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 if Is_Entity_Name (Nod)
1260 and then Present (Entity (Nod))
1261 and then Ekind (Entity (Nod)) = E_Constant
1262 and then not Is_Imported (Entity (Nod))
1263 and then not Has_Completion (Entity (Nod))
1264 and then Scope (Entity (Nod)) = Current_Scope
1267 ("premature use of& in call or instance", N, Entity (Nod));
1273 procedure Check_Deferred is new Traverse_Proc (Find_Constant);
1275 -- Start of processing for Check_Expression_Function
1278 Decl := Original_Node (Unit_Declaration_Node (Nam));
1280 if Scope (Nam) = Current_Scope
1281 and then Nkind (Decl) = N_Expression_Function
1283 Check_Deferred (Expression (Decl));
1285 end Check_Expression_Function;
1287 ----------------------------
1288 -- Check_Strict_Alignment --
1289 ----------------------------
1291 procedure Check_Strict_Alignment (E : Entity_Id) is
1295 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
1296 Set_Strict_Alignment (E);
1298 elsif Is_Array_Type (E) then
1299 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
1301 elsif Is_Record_Type (E) then
1302 if Is_Limited_Record (E) then
1303 Set_Strict_Alignment (E);
1307 Comp := First_Component (E);
1308 while Present (Comp) loop
1309 if not Is_Type (Comp)
1310 and then (Strict_Alignment (Etype (Comp))
1311 or else Is_Aliased (Comp))
1313 Set_Strict_Alignment (E);
1317 Next_Component (Comp);
1320 end Check_Strict_Alignment;
1322 -------------------------
1323 -- Check_Unsigned_Type --
1324 -------------------------
1326 procedure Check_Unsigned_Type (E : Entity_Id) is
1327 Ancestor : Entity_Id;
1332 if not Is_Discrete_Or_Fixed_Point_Type (E) then
1336 -- Do not attempt to analyze case where range was in error
1338 if No (Scalar_Range (E)) or else Error_Posted (Scalar_Range (E)) then
1342 -- The situation that is non trivial is something like
1344 -- subtype x1 is integer range -10 .. +10;
1345 -- subtype x2 is x1 range 0 .. V1;
1346 -- subtype x3 is x2 range V2 .. V3;
1347 -- subtype x4 is x3 range V4 .. V5;
1349 -- where Vn are variables. Here the base type is signed, but we still
1350 -- know that x4 is unsigned because of the lower bound of x2.
1352 -- The only way to deal with this is to look up the ancestor chain
1356 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1360 Lo_Bound := Type_Low_Bound (Ancestor);
1362 if Compile_Time_Known_Value (Lo_Bound) then
1363 if Expr_Rep_Value (Lo_Bound) >= 0 then
1364 Set_Is_Unsigned_Type (E, True);
1370 Ancestor := Ancestor_Subtype (Ancestor);
1372 -- If no ancestor had a static lower bound, go to base type
1374 if No (Ancestor) then
1376 -- Note: the reason we still check for a compile time known
1377 -- value for the base type is that at least in the case of
1378 -- generic formals, we can have bounds that fail this test,
1379 -- and there may be other cases in error situations.
1381 Btyp := Base_Type (E);
1383 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1387 Lo_Bound := Type_Low_Bound (Base_Type (E));
1389 if Compile_Time_Known_Value (Lo_Bound)
1390 and then Expr_Rep_Value (Lo_Bound) >= 0
1392 Set_Is_Unsigned_Type (E, True);
1399 end Check_Unsigned_Type;
1401 -------------------------
1402 -- Is_Atomic_Aggregate --
1403 -------------------------
1405 function Is_Atomic_Aggregate
1407 Typ : Entity_Id) return Boolean
1409 Loc : constant Source_Ptr := Sloc (E);
1417 -- Array may be qualified, so find outer context
1419 if Nkind (Par) = N_Qualified_Expression then
1420 Par := Parent (Par);
1423 if Nkind_In (Par, N_Object_Declaration, N_Assignment_Statement)
1424 and then Comes_From_Source (Par)
1426 Temp := Make_Temporary (Loc, 'T', E);
1428 Make_Object_Declaration (Loc,
1429 Defining_Identifier => Temp,
1430 Object_Definition => New_Occurrence_Of (Typ, Loc),
1431 Expression => Relocate_Node (E));
1432 Insert_Before (Par, New_N);
1435 Set_Expression (Par, New_Occurrence_Of (Temp, Loc));
1441 end Is_Atomic_Aggregate;
1443 -----------------------------------------------
1444 -- Explode_Initialization_Compound_Statement --
1445 -----------------------------------------------
1447 procedure Explode_Initialization_Compound_Statement (E : Entity_Id) is
1448 Init_Stmts : constant Node_Id := Initialization_Statements (E);
1451 if Present (Init_Stmts)
1452 and then Nkind (Init_Stmts) = N_Compound_Statement
1454 Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
1456 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1457 -- just removing it, because Freeze_All may rely on this particular
1458 -- Node_Id still being present in the enclosing list to know where to
1461 Rewrite (Init_Stmts, Make_Null_Statement (Sloc (Init_Stmts)));
1463 Set_Initialization_Statements (E, Empty);
1465 end Explode_Initialization_Compound_Statement;
1471 -- Note: the easy coding for this procedure would be to just build a
1472 -- single list of freeze nodes and then insert them and analyze them
1473 -- all at once. This won't work, because the analysis of earlier freeze
1474 -- nodes may recursively freeze types which would otherwise appear later
1475 -- on in the freeze list. So we must analyze and expand the freeze nodes
1476 -- as they are generated.
1478 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1482 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1483 -- This is the internal recursive routine that does freezing of entities
1484 -- (but NOT the analysis of default expressions, which should not be
1485 -- recursive, we don't want to analyze those till we are sure that ALL
1486 -- the types are frozen).
1488 --------------------
1489 -- Freeze_All_Ent --
1490 --------------------
1492 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id) is
1497 procedure Process_Flist;
1498 -- If freeze nodes are present, insert and analyze, and reset cursor
1499 -- for next insertion.
1505 procedure Process_Flist is
1507 if Is_Non_Empty_List (Flist) then
1508 Lastn := Next (After);
1509 Insert_List_After_And_Analyze (After, Flist);
1511 if Present (Lastn) then
1512 After := Prev (Lastn);
1514 After := Last (List_Containing (After));
1519 -- Start or processing for Freeze_All_Ent
1523 while Present (E) loop
1525 -- If the entity is an inner package which is not a package
1526 -- renaming, then its entities must be frozen at this point. Note
1527 -- that such entities do NOT get frozen at the end of the nested
1528 -- package itself (only library packages freeze).
1530 -- Same is true for task declarations, where anonymous records
1531 -- created for entry parameters must be frozen.
1533 if Ekind (E) = E_Package
1534 and then No (Renamed_Object (E))
1535 and then not Is_Child_Unit (E)
1536 and then not Is_Frozen (E)
1539 Install_Visible_Declarations (E);
1540 Install_Private_Declarations (E);
1542 Freeze_All (First_Entity (E), After);
1544 End_Package_Scope (E);
1546 if Is_Generic_Instance (E)
1547 and then Has_Delayed_Freeze (E)
1549 Set_Has_Delayed_Freeze (E, False);
1550 Expand_N_Package_Declaration (Unit_Declaration_Node (E));
1553 elsif Ekind (E) in Task_Kind
1554 and then Nkind_In (Parent (E), N_Task_Type_Declaration,
1555 N_Single_Task_Declaration)
1558 Freeze_All (First_Entity (E), After);
1561 -- For a derived tagged type, we must ensure that all the
1562 -- primitive operations of the parent have been frozen, so that
1563 -- their addresses will be in the parent's dispatch table at the
1564 -- point it is inherited.
1566 elsif Ekind (E) = E_Record_Type
1567 and then Is_Tagged_Type (E)
1568 and then Is_Tagged_Type (Etype (E))
1569 and then Is_Derived_Type (E)
1572 Prim_List : constant Elist_Id :=
1573 Primitive_Operations (Etype (E));
1579 Prim := First_Elmt (Prim_List);
1580 while Present (Prim) loop
1581 Subp := Node (Prim);
1583 if Comes_From_Source (Subp)
1584 and then not Is_Frozen (Subp)
1586 Flist := Freeze_Entity (Subp, After);
1595 if not Is_Frozen (E) then
1596 Flist := Freeze_Entity (E, After);
1599 -- If already frozen, and there are delayed aspects, this is where
1600 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1601 -- for a description of how we handle aspect visibility).
1603 elsif Has_Delayed_Aspects (E) then
1605 -- Retrieve the visibility to the discriminants in order to
1606 -- analyze properly the aspects.
1608 Push_Scope_And_Install_Discriminants (E);
1614 Ritem := First_Rep_Item (E);
1615 while Present (Ritem) loop
1616 if Nkind (Ritem) = N_Aspect_Specification
1617 and then Entity (Ritem) = E
1618 and then Is_Delayed_Aspect (Ritem)
1620 Check_Aspect_At_End_Of_Declarations (Ritem);
1623 Ritem := Next_Rep_Item (Ritem);
1627 Uninstall_Discriminants_And_Pop_Scope (E);
1630 -- If an incomplete type is still not frozen, this may be a
1631 -- premature freezing because of a body declaration that follows.
1632 -- Indicate where the freezing took place. Freezing will happen
1633 -- if the body comes from source, but not if it is internally
1634 -- generated, for example as the body of a type invariant.
1636 -- If the freezing is caused by the end of the current declarative
1637 -- part, it is a Taft Amendment type, and there is no error.
1639 if not Is_Frozen (E)
1640 and then Ekind (E) = E_Incomplete_Type
1643 Bod : constant Node_Id := Next (After);
1646 -- The presence of a body freezes all entities previously
1647 -- declared in the current list of declarations, but this
1648 -- does not apply if the body does not come from source.
1649 -- A type invariant is transformed into a subprogram body
1650 -- which is placed at the end of the private part of the
1651 -- current package, but this body does not freeze incomplete
1652 -- types that may be declared in this private part.
1654 if (Nkind_In (Bod, N_Subprogram_Body,
1659 or else Nkind (Bod) in N_Body_Stub)
1661 List_Containing (After) = List_Containing (Parent (E))
1662 and then Comes_From_Source (Bod)
1664 Error_Msg_Sloc := Sloc (Next (After));
1666 ("type& is frozen# before its full declaration",
1676 -- Start of processing for Freeze_All
1679 Freeze_All_Ent (From, After);
1681 -- Now that all types are frozen, we can deal with default expressions
1682 -- that require us to build a default expression functions. This is the
1683 -- point at which such functions are constructed (after all types that
1684 -- might be used in such expressions have been frozen).
1686 -- For subprograms that are renaming_as_body, we create the wrapper
1687 -- bodies as needed.
1689 -- We also add finalization chains to access types whose designated
1690 -- types are controlled. This is normally done when freezing the type,
1691 -- but this misses recursive type definitions where the later members
1692 -- of the recursion introduce controlled components.
1694 -- Loop through entities
1697 while Present (E) loop
1698 if Is_Subprogram (E) then
1700 if not Default_Expressions_Processed (E) then
1701 Process_Default_Expressions (E, After);
1704 if not Has_Completion (E) then
1705 Decl := Unit_Declaration_Node (E);
1707 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1708 if Error_Posted (Decl) then
1709 Set_Has_Completion (E);
1711 Build_And_Analyze_Renamed_Body (Decl, E, After);
1714 elsif Nkind (Decl) = N_Subprogram_Declaration
1715 and then Present (Corresponding_Body (Decl))
1717 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1718 = N_Subprogram_Renaming_Declaration
1720 Build_And_Analyze_Renamed_Body
1721 (Decl, Corresponding_Body (Decl), After);
1725 elsif Ekind (E) in Task_Kind
1726 and then Nkind_In (Parent (E), N_Task_Type_Declaration,
1727 N_Single_Task_Declaration)
1733 Ent := First_Entity (E);
1734 while Present (Ent) loop
1736 and then not Default_Expressions_Processed (Ent)
1738 Process_Default_Expressions (Ent, After);
1745 -- We add finalization masters to access types whose designated types
1746 -- require finalization. This is normally done when freezing the
1747 -- type, but this misses recursive type definitions where the later
1748 -- members of the recursion introduce controlled components (such as
1749 -- can happen when incomplete types are involved), as well cases
1750 -- where a component type is private and the controlled full type
1751 -- occurs after the access type is frozen. Cases that don't need a
1752 -- finalization master are generic formal types (the actual type will
1753 -- have it) and types derived from them, and types with Java and CIL
1754 -- conventions, since those are used for API bindings.
1755 -- (Are there any other cases that should be excluded here???)
1757 elsif Is_Access_Type (E)
1758 and then Comes_From_Source (E)
1759 and then not Is_Generic_Type (Root_Type (E))
1760 and then Needs_Finalization (Designated_Type (E))
1762 Build_Finalization_Master (E);
1769 -----------------------
1770 -- Freeze_And_Append --
1771 -----------------------
1773 procedure Freeze_And_Append
1776 Result : in out List_Id)
1778 L : constant List_Id := Freeze_Entity (Ent, N);
1780 if Is_Non_Empty_List (L) then
1781 if Result = No_List then
1784 Append_List (L, Result);
1787 end Freeze_And_Append;
1793 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1794 Freeze_Nodes : constant List_Id := Freeze_Entity (T, N);
1797 if Ekind (T) = E_Function then
1798 Check_Expression_Function (N, T);
1801 if Is_Non_Empty_List (Freeze_Nodes) then
1802 Insert_Actions (N, Freeze_Nodes);
1810 function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is
1811 Loc : constant Source_Ptr := Sloc (N);
1812 Test_E : Entity_Id := E;
1819 Result : List_Id := No_List;
1820 -- List of freezing actions, left at No_List if none
1822 Has_Default_Initialization : Boolean := False;
1823 -- This flag gets set to true for a variable with default initialization
1825 procedure Add_To_Result (N : Node_Id);
1826 -- N is a freezing action to be appended to the Result
1828 function After_Last_Declaration return Boolean;
1829 -- If Loc is a freeze_entity that appears after the last declaration
1830 -- in the scope, inhibit error messages on late completion.
1832 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1833 -- Check that an Access or Unchecked_Access attribute with a prefix
1834 -- which is the current instance type can only be applied when the type
1837 procedure Check_Suspicious_Modulus (Utype : Entity_Id);
1838 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1839 -- integer literal without an explicit corresponding size clause. The
1840 -- caller has checked that Utype is a modular integer type.
1842 procedure Freeze_Array_Type (Arr : Entity_Id);
1843 -- Freeze array type, including freezing index and component types
1845 function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id;
1846 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1847 -- package. Recurse on inner generic packages.
1849 procedure Freeze_Record_Type (Rec : Entity_Id);
1850 -- Freeze record type, including freezing component types, and freezing
1851 -- primitive operations if this is a tagged type.
1853 function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean;
1854 -- Determine whether an arbitrary entity is subject to Boolean aspect
1855 -- Import and its value is specified as True.
1857 procedure Wrap_Imported_Subprogram (E : Entity_Id);
1858 -- If E is an entity for an imported subprogram with pre/post-conditions
1859 -- then this procedure will create a wrapper to ensure that proper run-
1860 -- time checking of the pre/postconditions. See body for details.
1866 procedure Add_To_Result (N : Node_Id) is
1869 Result := New_List (N);
1875 ----------------------------
1876 -- After_Last_Declaration --
1877 ----------------------------
1879 function After_Last_Declaration return Boolean is
1880 Spec : constant Node_Id := Parent (Current_Scope);
1882 if Nkind (Spec) = N_Package_Specification then
1883 if Present (Private_Declarations (Spec)) then
1884 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1885 elsif Present (Visible_Declarations (Spec)) then
1886 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1893 end After_Last_Declaration;
1895 ----------------------------
1896 -- Check_Current_Instance --
1897 ----------------------------
1899 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1901 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean;
1902 -- Determine whether Typ is compatible with the rules for aliased
1903 -- views of types as defined in RM 3.10 in the various dialects.
1905 function Process (N : Node_Id) return Traverse_Result;
1906 -- Process routine to apply check to given node
1908 -----------------------------
1909 -- Is_Aliased_View_Of_Type --
1910 -----------------------------
1912 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean is
1913 Typ_Decl : constant Node_Id := Parent (Typ);
1918 if Nkind (Typ_Decl) = N_Full_Type_Declaration
1919 and then Limited_Present (Type_Definition (Typ_Decl))
1923 -- The following paragraphs describe what a legal aliased view of
1924 -- a type is in the various dialects of Ada.
1928 -- The current instance of a limited type, and a formal parameter
1929 -- or generic formal object of a tagged type.
1931 -- Ada 95 limited type
1932 -- * Type with reserved word "limited"
1933 -- * A protected or task type
1934 -- * A composite type with limited component
1936 elsif Ada_Version <= Ada_95 then
1937 return Is_Limited_Type (Typ);
1941 -- The current instance of a limited tagged type, a protected
1942 -- type, a task type, or a type that has the reserved word
1943 -- "limited" in its full definition ... a formal parameter or
1944 -- generic formal object of a tagged type.
1946 -- Ada 2005 limited type
1947 -- * Type with reserved word "limited", "synchronized", "task"
1949 -- * A composite type with limited component
1950 -- * A derived type whose parent is a non-interface limited type
1952 elsif Ada_Version = Ada_2005 then
1954 (Is_Limited_Type (Typ) and then Is_Tagged_Type (Typ))
1956 (Is_Derived_Type (Typ)
1957 and then not Is_Interface (Etype (Typ))
1958 and then Is_Limited_Type (Etype (Typ)));
1960 -- Ada 2012 and beyond
1962 -- The current instance of an immutably limited type ... a formal
1963 -- parameter or generic formal object of a tagged type.
1965 -- Ada 2012 limited type
1966 -- * Type with reserved word "limited", "synchronized", "task"
1968 -- * A composite type with limited component
1969 -- * A derived type whose parent is a non-interface limited type
1970 -- * An incomplete view
1972 -- Ada 2012 immutably limited type
1973 -- * Explicitly limited record type
1974 -- * Record extension with "limited" present
1975 -- * Non-formal limited private type that is either tagged
1976 -- or has at least one access discriminant with a default
1978 -- * Task type, protected type or synchronized interface
1979 -- * Type derived from immutably limited type
1983 Is_Immutably_Limited_Type (Typ)
1984 or else Is_Incomplete_Type (Typ);
1986 end Is_Aliased_View_Of_Type;
1992 function Process (N : Node_Id) return Traverse_Result is
1995 when N_Attribute_Reference =>
1996 if Nam_In (Attribute_Name (N), Name_Access,
1997 Name_Unchecked_Access)
1998 and then Is_Entity_Name (Prefix (N))
1999 and then Is_Type (Entity (Prefix (N)))
2000 and then Entity (Prefix (N)) = E
2002 if Ada_Version < Ada_2012 then
2004 ("current instance must be a limited type",
2008 ("current instance must be an immutably limited "
2009 & "type (RM-2012, 7.5 (8.1/3))",
2019 when others => return OK;
2023 procedure Traverse is new Traverse_Proc (Process);
2027 Rec_Type : constant Entity_Id :=
2028 Scope (Defining_Identifier (Comp_Decl));
2030 -- Start of processing for Check_Current_Instance
2033 if not Is_Aliased_View_Of_Type (Rec_Type) then
2034 Traverse (Comp_Decl);
2036 end Check_Current_Instance;
2038 ------------------------------
2039 -- Check_Suspicious_Modulus --
2040 ------------------------------
2042 procedure Check_Suspicious_Modulus (Utype : Entity_Id) is
2043 Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype));
2046 if not Warn_On_Suspicious_Modulus_Value then
2050 if Nkind (Decl) = N_Full_Type_Declaration then
2052 Tdef : constant Node_Id := Type_Definition (Decl);
2055 if Nkind (Tdef) = N_Modular_Type_Definition then
2057 Modulus : constant Node_Id :=
2058 Original_Node (Expression (Tdef));
2061 if Nkind (Modulus) = N_Integer_Literal then
2063 Modv : constant Uint := Intval (Modulus);
2064 Sizv : constant Uint := RM_Size (Utype);
2067 -- First case, modulus and size are the same. This
2068 -- happens if you have something like mod 32, with
2069 -- an explicit size of 32, this is for sure a case
2070 -- where the warning is given, since it is seems
2071 -- very unlikely that someone would want e.g. a
2072 -- five bit type stored in 32 bits. It is much
2073 -- more likely they wanted a 32-bit type.
2078 -- Second case, the modulus is 32 or 64 and no
2079 -- size clause is present. This is a less clear
2080 -- case for giving the warning, but in the case
2081 -- of 32/64 (5-bit or 6-bit types) these seem rare
2082 -- enough that it is a likely error (and in any
2083 -- case using 2**5 or 2**6 in these cases seems
2084 -- clearer. We don't include 8 or 16 here, simply
2085 -- because in practice 3-bit and 4-bit types are
2086 -- more common and too many false positives if
2087 -- we warn in these cases.
2089 elsif not Has_Size_Clause (Utype)
2090 and then (Modv = Uint_32 or else Modv = Uint_64)
2094 -- No warning needed
2100 -- If we fall through, give warning
2102 Error_Msg_Uint_1 := Modv;
2104 ("?M?2 '*'*^' may have been intended here",
2112 end Check_Suspicious_Modulus;
2114 -----------------------
2115 -- Freeze_Array_Type --
2116 -----------------------
2118 procedure Freeze_Array_Type (Arr : Entity_Id) is
2119 FS : constant Entity_Id := First_Subtype (Arr);
2120 Ctyp : constant Entity_Id := Component_Type (Arr);
2123 Non_Standard_Enum : Boolean := False;
2124 -- Set true if any of the index types is an enumeration type with a
2125 -- non-standard representation.
2128 Freeze_And_Append (Ctyp, N, Result);
2130 Indx := First_Index (Arr);
2131 while Present (Indx) loop
2132 Freeze_And_Append (Etype (Indx), N, Result);
2134 if Is_Enumeration_Type (Etype (Indx))
2135 and then Has_Non_Standard_Rep (Etype (Indx))
2137 Non_Standard_Enum := True;
2143 -- Processing that is done only for base types
2145 if Ekind (Arr) = E_Array_Type then
2147 -- Deal with default setting of reverse storage order
2149 Set_SSO_From_Default (Arr);
2151 -- Propagate flags for component type
2153 if Is_Controlled (Component_Type (Arr))
2154 or else Has_Controlled_Component (Ctyp)
2156 Set_Has_Controlled_Component (Arr);
2159 if Has_Unchecked_Union (Component_Type (Arr)) then
2160 Set_Has_Unchecked_Union (Arr);
2163 -- Warn for pragma Pack overriding foreign convention
2165 if Has_Foreign_Convention (Ctyp)
2166 and then Has_Pragma_Pack (Arr)
2169 CN : constant Name_Id :=
2170 Get_Convention_Name (Convention (Ctyp));
2171 PP : constant Node_Id :=
2172 Get_Pragma (First_Subtype (Arr), Pragma_Pack);
2174 if Present (PP) then
2175 Error_Msg_Name_1 := CN;
2176 Error_Msg_Sloc := Sloc (Arr);
2178 ("pragma Pack affects convention % components #??",
2180 Error_Msg_Name_1 := CN;
2182 ("\array components may not have % compatible "
2183 & "representation??", PP);
2188 -- If packing was requested or if the component size was
2189 -- set explicitly, then see if bit packing is required. This
2190 -- processing is only done for base types, since all of the
2191 -- representation aspects involved are type-related.
2193 -- This is not just an optimization, if we start processing the
2194 -- subtypes, they interfere with the settings on the base type
2195 -- (this is because Is_Packed has a slightly different meaning
2196 -- before and after freezing).
2203 if (Is_Packed (Arr) or else Has_Pragma_Pack (Arr))
2204 and then Known_Static_RM_Size (Ctyp)
2205 and then not Has_Component_Size_Clause (Arr)
2207 Csiz := UI_Max (RM_Size (Ctyp), 1);
2209 elsif Known_Component_Size (Arr) then
2210 Csiz := Component_Size (Arr);
2212 elsif not Known_Static_Esize (Ctyp) then
2216 Esiz := Esize (Ctyp);
2218 -- We can set the component size if it is less than 16,
2219 -- rounding it up to the next storage unit size.
2223 elsif Esiz <= 16 then
2229 -- Set component size up to match alignment if it would
2230 -- otherwise be less than the alignment. This deals with
2231 -- cases of types whose alignment exceeds their size (the
2232 -- padded type cases).
2236 A : constant Uint := Alignment_In_Bits (Ctyp);
2245 -- Case of component size that may result in packing
2247 if 1 <= Csiz and then Csiz <= 64 then
2249 Ent : constant Entity_Id :=
2250 First_Subtype (Arr);
2251 Pack_Pragma : constant Node_Id :=
2252 Get_Rep_Pragma (Ent, Name_Pack);
2253 Comp_Size_C : constant Node_Id :=
2254 Get_Attribute_Definition_Clause
2255 (Ent, Attribute_Component_Size);
2257 -- Warn if we have pack and component size so that the
2260 -- Note: here we must check for the presence of a
2261 -- component size before checking for a Pack pragma to
2262 -- deal with the case where the array type is a derived
2263 -- type whose parent is currently private.
2265 if Present (Comp_Size_C)
2266 and then Has_Pragma_Pack (Ent)
2267 and then Warn_On_Redundant_Constructs
2269 Error_Msg_Sloc := Sloc (Comp_Size_C);
2271 ("?r?pragma Pack for& ignored!", Pack_Pragma, Ent);
2273 ("\?r?explicit component size given#!", Pack_Pragma);
2274 Set_Is_Packed (Base_Type (Ent), False);
2275 Set_Is_Bit_Packed_Array (Base_Type (Ent), False);
2278 -- Set component size if not already set by a component
2281 if not Present (Comp_Size_C) then
2282 Set_Component_Size (Arr, Csiz);
2285 -- Check for base type of 8, 16, 32 bits, where an
2286 -- unsigned subtype has a length one less than the
2287 -- base type (e.g. Natural subtype of Integer).
2289 -- In such cases, if a component size was not set
2290 -- explicitly, then generate a warning.
2292 if Has_Pragma_Pack (Arr)
2293 and then not Present (Comp_Size_C)
2294 and then (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
2295 and then Esize (Base_Type (Ctyp)) = Csiz + 1
2297 Error_Msg_Uint_1 := Csiz;
2299 if Present (Pack_Pragma) then
2301 ("??pragma Pack causes component size "
2302 & "to be ^!", Pack_Pragma);
2304 ("\??use Component_Size to set "
2305 & "desired value!", Pack_Pragma);
2309 -- Actual packing is not needed for 8, 16, 32, 64. Also
2310 -- not needed for 24 if alignment is 1.
2316 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
2318 -- Here the array was requested to be packed, but
2319 -- the packing request had no effect, so Is_Packed
2322 -- Note: semantically this means that we lose track
2323 -- of the fact that a derived type inherited a pragma
2324 -- Pack that was non- effective, but that seems fine.
2326 -- We regard a Pack pragma as a request to set a
2327 -- representation characteristic, and this request
2330 Set_Is_Packed (Base_Type (Arr), False);
2331 Set_Is_Bit_Packed_Array (Base_Type (Arr), False);
2333 if Known_Static_Esize (Component_Type (Arr))
2334 and then Esize (Component_Type (Arr)) = Csiz
2336 Set_Has_Non_Standard_Rep (Base_Type (Arr), False);
2339 -- In all other cases, packing is indeed needed
2342 Set_Has_Non_Standard_Rep (Base_Type (Arr), True);
2343 Set_Is_Bit_Packed_Array (Base_Type (Arr), True);
2344 Set_Is_Packed (Base_Type (Arr), True);
2350 -- Check for Atomic_Components or Aliased with unsuitable packing
2351 -- or explicit component size clause given.
2353 if (Has_Atomic_Components (Arr)
2355 Has_Aliased_Components (Arr))
2357 (Has_Component_Size_Clause (Arr) or else Is_Packed (Arr))
2359 Alias_Atomic_Check : declare
2361 procedure Complain_CS (T : String);
2362 -- Outputs error messages for incorrect CS clause or pragma
2363 -- Pack for aliased or atomic components (T is "aliased" or
2370 procedure Complain_CS (T : String) is
2372 if Has_Component_Size_Clause (Arr) then
2374 Get_Attribute_Definition_Clause
2375 (FS, Attribute_Component_Size);
2377 if Known_Static_Esize (Ctyp) then
2379 ("incorrect component size for "
2380 & T & " components", Clause);
2381 Error_Msg_Uint_1 := Esize (Ctyp);
2383 ("\only allowed value is^", Clause);
2387 ("component size cannot be given for "
2388 & T & " components", Clause);
2393 ("cannot pack " & T & " components",
2394 Get_Rep_Pragma (FS, Name_Pack));
2400 -- Start of processing for Alias_Atomic_Check
2403 -- If object size of component type isn't known, we cannot
2404 -- be sure so we defer to the back end.
2406 if not Known_Static_Esize (Ctyp) then
2409 -- Case where component size has no effect. First check for
2410 -- object size of component type multiple of the storage
2413 elsif Esize (Ctyp) mod System_Storage_Unit = 0
2415 -- OK in both packing case and component size case if RM
2416 -- size is known and static and same as the object size.
2419 ((Known_Static_RM_Size (Ctyp)
2420 and then Esize (Ctyp) = RM_Size (Ctyp))
2422 -- Or if we have an explicit component size clause and
2423 -- the component size and object size are equal.
2426 (Has_Component_Size_Clause (Arr)
2427 and then Component_Size (Arr) = Esize (Ctyp)))
2431 elsif Has_Aliased_Components (Arr)
2432 or else Is_Aliased (Ctyp)
2434 Complain_CS ("aliased");
2436 elsif Has_Atomic_Components (Arr)
2437 or else Is_Atomic (Ctyp)
2439 Complain_CS ("atomic");
2441 end Alias_Atomic_Check;
2444 -- Warn for case of atomic type
2446 Clause := Get_Rep_Pragma (FS, Name_Atomic);
2449 and then not Addressable (Component_Size (FS))
2452 ("non-atomic components of type& may not be "
2453 & "accessible by separate tasks??", Clause, Arr);
2455 if Has_Component_Size_Clause (Arr) then
2456 Error_Msg_Sloc := Sloc (Get_Attribute_Definition_Clause
2457 (FS, Attribute_Component_Size));
2458 Error_Msg_N ("\because of component size clause#??", Clause);
2460 elsif Has_Pragma_Pack (Arr) then
2461 Error_Msg_Sloc := Sloc (Get_Rep_Pragma (FS, Name_Pack));
2462 Error_Msg_N ("\because of pragma Pack#??", Clause);
2466 -- Check for scalar storage order
2471 Check_Component_Storage_Order
2474 ADC => Get_Attribute_Definition_Clause
2475 (First_Subtype (Arr),
2476 Attribute_Scalar_Storage_Order),
2477 Comp_ADC_Present => Dummy);
2480 -- Processing that is done only for subtypes
2483 -- Acquire alignment from base type
2485 if Unknown_Alignment (Arr) then
2486 Set_Alignment (Arr, Alignment (Base_Type (Arr)));
2487 Adjust_Esize_Alignment (Arr);
2491 -- Specific checks for bit-packed arrays
2493 if Is_Bit_Packed_Array (Arr) then
2495 -- Check number of elements for bit packed arrays that come from
2496 -- source and have compile time known ranges. The bit-packed
2497 -- arrays circuitry does not support arrays with more than
2498 -- Integer'Last + 1 elements, and when this restriction is
2499 -- violated, causes incorrect data access.
2501 -- For the case where this is not compile time known, a run-time
2502 -- check should be generated???
2504 if Comes_From_Source (Arr) and then Is_Constrained (Arr) then
2513 Index := First_Index (Arr);
2514 while Present (Index) loop
2515 Ityp := Etype (Index);
2517 -- Never generate an error if any index is of a generic
2518 -- type. We will check this in instances.
2520 if Is_Generic_Type (Ityp) then
2526 Make_Attribute_Reference (Loc,
2528 New_Occurrence_Of (Ityp, Loc),
2529 Attribute_Name => Name_Range_Length);
2530 Analyze_And_Resolve (Ilen);
2532 -- No attempt is made to check number of elements
2533 -- if not compile time known.
2535 if Nkind (Ilen) /= N_Integer_Literal then
2540 Elmts := Elmts * Intval (Ilen);
2544 if Elmts > Intval (High_Bound
2545 (Scalar_Range (Standard_Integer))) + 1
2548 ("bit packed array type may not have "
2549 & "more than Integer''Last+1 elements", Arr);
2556 if Known_RM_Size (Arr) then
2558 SizC : constant Node_Id := Size_Clause (Arr);
2561 pragma Warnings (Off, Discard);
2564 -- It is not clear if it is possible to have no size clause
2565 -- at this stage, but it is not worth worrying about. Post
2566 -- error on the entity name in the size clause if present,
2567 -- else on the type entity itself.
2569 if Present (SizC) then
2570 Check_Size (Name (SizC), Arr, RM_Size (Arr), Discard);
2572 Check_Size (Arr, Arr, RM_Size (Arr), Discard);
2578 -- If any of the index types was an enumeration type with a
2579 -- non-standard rep clause, then we indicate that the array type
2580 -- is always packed (even if it is not bit packed).
2582 if Non_Standard_Enum then
2583 Set_Has_Non_Standard_Rep (Base_Type (Arr));
2584 Set_Is_Packed (Base_Type (Arr));
2587 Set_Component_Alignment_If_Not_Set (Arr);
2589 -- If the array is packed, we must create the packed array type to be
2590 -- used to actually implement the type. This is only needed for real
2591 -- array types (not for string literal types, since they are present
2592 -- only for the front end).
2595 and then Ekind (Arr) /= E_String_Literal_Subtype
2597 Create_Packed_Array_Impl_Type (Arr);
2598 Freeze_And_Append (Packed_Array_Impl_Type (Arr), N, Result);
2600 -- Size information of packed array type is copied to the array
2601 -- type, since this is really the representation. But do not
2602 -- override explicit existing size values. If the ancestor subtype
2603 -- is constrained the Packed_Array_Impl_Type will be inherited
2604 -- from it, but the size may have been provided already, and
2605 -- must not be overridden either.
2607 if not Has_Size_Clause (Arr)
2609 (No (Ancestor_Subtype (Arr))
2610 or else not Has_Size_Clause (Ancestor_Subtype (Arr)))
2612 Set_Esize (Arr, Esize (Packed_Array_Impl_Type (Arr)));
2613 Set_RM_Size (Arr, RM_Size (Packed_Array_Impl_Type (Arr)));
2616 if not Has_Alignment_Clause (Arr) then
2617 Set_Alignment (Arr, Alignment (Packed_Array_Impl_Type (Arr)));
2621 -- For non-packed arrays set the alignment of the array to the
2622 -- alignment of the component type if it is unknown. Skip this
2623 -- in atomic case (atomic arrays may need larger alignments).
2625 if not Is_Packed (Arr)
2626 and then Unknown_Alignment (Arr)
2627 and then Known_Alignment (Ctyp)
2628 and then Known_Static_Component_Size (Arr)
2629 and then Known_Static_Esize (Ctyp)
2630 and then Esize (Ctyp) = Component_Size (Arr)
2631 and then not Is_Atomic (Arr)
2633 Set_Alignment (Arr, Alignment (Component_Type (Arr)));
2635 end Freeze_Array_Type;
2637 -----------------------------
2638 -- Freeze_Generic_Entities --
2639 -----------------------------
2641 function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id is
2648 E := First_Entity (Pack);
2649 while Present (E) loop
2650 if Is_Type (E) and then not Is_Generic_Type (E) then
2651 F := Make_Freeze_Generic_Entity (Sloc (Pack));
2653 Append_To (Flist, F);
2655 elsif Ekind (E) = E_Generic_Package then
2656 Append_List_To (Flist, Freeze_Generic_Entities (E));
2663 end Freeze_Generic_Entities;
2665 ------------------------
2666 -- Freeze_Record_Type --
2667 ------------------------
2669 procedure Freeze_Record_Type (Rec : Entity_Id) is
2676 pragma Warnings (Off, Junk);
2678 Rec_Pushed : Boolean := False;
2679 -- Set True if the record type scope Rec has been pushed on the scope
2680 -- stack. Needed for the analysis of delayed aspects specified to the
2681 -- components of Rec.
2684 -- Scalar_Storage_Order attribute definition clause for the record
2686 Unplaced_Component : Boolean := False;
2687 -- Set True if we find at least one component with no component
2688 -- clause (used to warn about useless Pack pragmas).
2690 Placed_Component : Boolean := False;
2691 -- Set True if we find at least one component with a component
2692 -- clause (used to warn about useless Bit_Order pragmas, and also
2693 -- to detect cases where Implicit_Packing may have an effect).
2695 Aliased_Component : Boolean := False;
2696 -- Set True if we find at least one component which is aliased. This
2697 -- is used to prevent Implicit_Packing of the record, since packing
2698 -- cannot modify the size of alignment of an aliased component.
2700 SSO_ADC_Component : Boolean := False;
2701 -- Set True if we find at least one component whose type has a
2702 -- Scalar_Storage_Order attribute definition clause.
2704 All_Scalar_Components : Boolean := True;
2705 -- Set False if we encounter a component of a non-scalar type
2707 Scalar_Component_Total_RM_Size : Uint := Uint_0;
2708 Scalar_Component_Total_Esize : Uint := Uint_0;
2709 -- Accumulates total RM_Size values and total Esize values of all
2710 -- scalar components. Used for processing of Implicit_Packing.
2712 function Check_Allocator (N : Node_Id) return Node_Id;
2713 -- If N is an allocator, possibly wrapped in one or more level of
2714 -- qualified expression(s), return the inner allocator node, else
2717 procedure Check_Itype (Typ : Entity_Id);
2718 -- If the component subtype is an access to a constrained subtype of
2719 -- an already frozen type, make the subtype frozen as well. It might
2720 -- otherwise be frozen in the wrong scope, and a freeze node on
2721 -- subtype has no effect. Similarly, if the component subtype is a
2722 -- regular (not protected) access to subprogram, set the anonymous
2723 -- subprogram type to frozen as well, to prevent an out-of-scope
2724 -- freeze node at some eventual point of call. Protected operations
2725 -- are handled elsewhere.
2727 procedure Freeze_Choices_In_Variant_Part (VP : Node_Id);
2728 -- Make sure that all types mentioned in Discrete_Choices of the
2729 -- variants referenceed by the Variant_Part VP are frozen. This is
2730 -- a recursive routine to deal with nested variants.
2732 ---------------------
2733 -- Check_Allocator --
2734 ---------------------
2736 function Check_Allocator (N : Node_Id) return Node_Id is
2741 if Nkind (Inner) = N_Allocator then
2743 elsif Nkind (Inner) = N_Qualified_Expression then
2744 Inner := Expression (Inner);
2749 end Check_Allocator;
2755 procedure Check_Itype (Typ : Entity_Id) is
2756 Desig : constant Entity_Id := Designated_Type (Typ);
2759 if not Is_Frozen (Desig)
2760 and then Is_Frozen (Base_Type (Desig))
2762 Set_Is_Frozen (Desig);
2764 -- In addition, add an Itype_Reference to ensure that the
2765 -- access subtype is elaborated early enough. This cannot be
2766 -- done if the subtype may depend on discriminants.
2768 if Ekind (Comp) = E_Component
2769 and then Is_Itype (Etype (Comp))
2770 and then not Has_Discriminants (Rec)
2772 IR := Make_Itype_Reference (Sloc (Comp));
2773 Set_Itype (IR, Desig);
2777 elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type
2778 and then Convention (Desig) /= Convention_Protected
2780 Set_Is_Frozen (Desig);
2784 ------------------------------------
2785 -- Freeze_Choices_In_Variant_Part --
2786 ------------------------------------
2788 procedure Freeze_Choices_In_Variant_Part (VP : Node_Id) is
2789 pragma Assert (Nkind (VP) = N_Variant_Part);
2796 -- Loop through variants
2798 Variant := First_Non_Pragma (Variants (VP));
2799 while Present (Variant) loop
2801 -- Loop through choices, checking that all types are frozen
2803 Choice := First_Non_Pragma (Discrete_Choices (Variant));
2804 while Present (Choice) loop
2805 if Nkind (Choice) in N_Has_Etype
2806 and then Present (Etype (Choice))
2808 Freeze_And_Append (Etype (Choice), N, Result);
2811 Next_Non_Pragma (Choice);
2814 -- Check for nested variant part to process
2816 CL := Component_List (Variant);
2818 if not Null_Present (CL) then
2819 if Present (Variant_Part (CL)) then
2820 Freeze_Choices_In_Variant_Part (Variant_Part (CL));
2824 Next_Non_Pragma (Variant);
2826 end Freeze_Choices_In_Variant_Part;
2828 -- Start of processing for Freeze_Record_Type
2831 -- Deal with delayed aspect specifications for components. The
2832 -- analysis of the aspect is required to be delayed to the freeze
2833 -- point, thus we analyze the pragma or attribute definition
2834 -- clause in the tree at this point. We also analyze the aspect
2835 -- specification node at the freeze point when the aspect doesn't
2836 -- correspond to pragma/attribute definition clause.
2838 Comp := First_Entity (Rec);
2839 while Present (Comp) loop
2840 if Ekind (Comp) = E_Component
2841 and then Has_Delayed_Aspects (Comp)
2843 if not Rec_Pushed then
2847 -- The visibility to the discriminants must be restored in
2848 -- order to properly analyze the aspects.
2850 if Has_Discriminants (Rec) then
2851 Install_Discriminants (Rec);
2855 Analyze_Aspects_At_Freeze_Point (Comp);
2861 -- Pop the scope if Rec scope has been pushed on the scope stack
2862 -- during the delayed aspect analysis process.
2865 if Has_Discriminants (Rec) then
2866 Uninstall_Discriminants (Rec);
2872 -- Freeze components and embedded subtypes
2874 Comp := First_Entity (Rec);
2876 while Present (Comp) loop
2877 if Is_Aliased (Comp) then
2878 Aliased_Component := True;
2881 -- Handle the component and discriminant case
2883 if Ekind_In (Comp, E_Component, E_Discriminant) then
2885 CC : constant Node_Id := Component_Clause (Comp);
2888 -- Freezing a record type freezes the type of each of its
2889 -- components. However, if the type of the component is
2890 -- part of this record, we do not want or need a separate
2891 -- Freeze_Node. Note that Is_Itype is wrong because that's
2892 -- also set in private type cases. We also can't check for
2893 -- the Scope being exactly Rec because of private types and
2894 -- record extensions.
2896 if Is_Itype (Etype (Comp))
2897 and then Is_Record_Type (Underlying_Type
2898 (Scope (Etype (Comp))))
2900 Undelay_Type (Etype (Comp));
2903 Freeze_And_Append (Etype (Comp), N, Result);
2905 -- Warn for pragma Pack overriding foreign convention
2907 if Has_Foreign_Convention (Etype (Comp))
2908 and then Has_Pragma_Pack (Rec)
2910 -- Don't warn for aliased components, since override
2911 -- cannot happen in that case.
2913 and then not Is_Aliased (Comp)
2916 CN : constant Name_Id :=
2917 Get_Convention_Name (Convention (Etype (Comp)));
2918 PP : constant Node_Id :=
2919 Get_Pragma (Rec, Pragma_Pack);
2921 if Present (PP) then
2922 Error_Msg_Name_1 := CN;
2923 Error_Msg_Sloc := Sloc (Comp);
2925 ("pragma Pack affects convention % component#??",
2927 Error_Msg_Name_1 := CN;
2929 ("\component & may not have % compatible "
2930 & "representation??", PP, Comp);
2935 -- Check for error of component clause given for variable
2936 -- sized type. We have to delay this test till this point,
2937 -- since the component type has to be frozen for us to know
2938 -- if it is variable length.
2940 if Present (CC) then
2941 Placed_Component := True;
2943 -- We omit this test in a generic context, it will be
2944 -- applied at instantiation time.
2946 if Inside_A_Generic then
2949 -- Also omit this test in CodePeer mode, since we do not
2950 -- have sufficient info on size and rep clauses.
2952 elsif CodePeer_Mode then
2958 Size_Known_At_Compile_Time
2959 (Underlying_Type (Etype (Comp)))
2962 ("component clause not allowed for variable " &
2963 "length component", CC);
2967 Unplaced_Component := True;
2970 -- Case of component requires byte alignment
2972 if Must_Be_On_Byte_Boundary (Etype (Comp)) then
2974 -- Set the enclosing record to also require byte align
2976 Set_Must_Be_On_Byte_Boundary (Rec);
2978 -- Check for component clause that is inconsistent with
2979 -- the required byte boundary alignment.
2982 and then Normalized_First_Bit (Comp) mod
2983 System_Storage_Unit /= 0
2986 ("component & must be byte aligned",
2987 Component_Name (Component_Clause (Comp)));
2993 -- Gather data for possible Implicit_Packing later. Note that at
2994 -- this stage we might be dealing with a real component, or with
2995 -- an implicit subtype declaration.
2997 if not Is_Scalar_Type (Etype (Comp)) then
2998 All_Scalar_Components := False;
3000 Scalar_Component_Total_RM_Size :=
3001 Scalar_Component_Total_RM_Size + RM_Size (Etype (Comp));
3002 Scalar_Component_Total_Esize :=
3003 Scalar_Component_Total_Esize + Esize (Etype (Comp));
3006 -- If the component is an Itype with Delayed_Freeze and is either
3007 -- a record or array subtype and its base type has not yet been
3008 -- frozen, we must remove this from the entity list of this record
3009 -- and put it on the entity list of the scope of its base type.
3010 -- Note that we know that this is not the type of a component
3011 -- since we cleared Has_Delayed_Freeze for it in the previous
3012 -- loop. Thus this must be the Designated_Type of an access type,
3013 -- which is the type of a component.
3016 and then Is_Type (Scope (Comp))
3017 and then Is_Composite_Type (Comp)
3018 and then Base_Type (Comp) /= Comp
3019 and then Has_Delayed_Freeze (Comp)
3020 and then not Is_Frozen (Base_Type (Comp))
3023 Will_Be_Frozen : Boolean := False;
3027 -- We have a difficult case to handle here. Suppose Rec is
3028 -- subtype being defined in a subprogram that's created as
3029 -- part of the freezing of Rec'Base. In that case, we know
3030 -- that Comp'Base must have already been frozen by the time
3031 -- we get to elaborate this because Gigi doesn't elaborate
3032 -- any bodies until it has elaborated all of the declarative
3033 -- part. But Is_Frozen will not be set at this point because
3034 -- we are processing code in lexical order.
3036 -- We detect this case by going up the Scope chain of Rec
3037 -- and seeing if we have a subprogram scope before reaching
3038 -- the top of the scope chain or that of Comp'Base. If we
3039 -- do, then mark that Comp'Base will actually be frozen. If
3040 -- so, we merely undelay it.
3043 while Present (S) loop
3044 if Is_Subprogram (S) then
3045 Will_Be_Frozen := True;
3047 elsif S = Scope (Base_Type (Comp)) then
3054 if Will_Be_Frozen then
3055 Undelay_Type (Comp);
3057 if Present (Prev) then
3058 Set_Next_Entity (Prev, Next_Entity (Comp));
3060 Set_First_Entity (Rec, Next_Entity (Comp));
3063 -- Insert in entity list of scope of base type (which
3064 -- must be an enclosing scope, because still unfrozen).
3066 Append_Entity (Comp, Scope (Base_Type (Comp)));
3070 -- If the component is an access type with an allocator as default
3071 -- value, the designated type will be frozen by the corresponding
3072 -- expression in init_proc. In order to place the freeze node for
3073 -- the designated type before that for the current record type,
3076 -- Same process if the component is an array of access types,
3077 -- initialized with an aggregate. If the designated type is
3078 -- private, it cannot contain allocators, and it is premature
3079 -- to freeze the type, so we check for this as well.
3081 elsif Is_Access_Type (Etype (Comp))
3082 and then Present (Parent (Comp))
3083 and then Present (Expression (Parent (Comp)))
3086 Alloc : constant Node_Id :=
3087 Check_Allocator (Expression (Parent (Comp)));
3090 if Present (Alloc) then
3092 -- If component is pointer to a class-wide type, freeze
3093 -- the specific type in the expression being allocated.
3094 -- The expression may be a subtype indication, in which
3095 -- case freeze the subtype mark.
3097 if Is_Class_Wide_Type
3098 (Designated_Type (Etype (Comp)))
3100 if Is_Entity_Name (Expression (Alloc)) then
3102 (Entity (Expression (Alloc)), N, Result);
3104 Nkind (Expression (Alloc)) = N_Subtype_Indication
3107 (Entity (Subtype_Mark (Expression (Alloc))),
3111 elsif Is_Itype (Designated_Type (Etype (Comp))) then
3112 Check_Itype (Etype (Comp));
3116 (Designated_Type (Etype (Comp)), N, Result);
3121 elsif Is_Access_Type (Etype (Comp))
3122 and then Is_Itype (Designated_Type (Etype (Comp)))
3124 Check_Itype (Etype (Comp));
3126 elsif Is_Array_Type (Etype (Comp))
3127 and then Is_Access_Type (Component_Type (Etype (Comp)))
3128 and then Present (Parent (Comp))
3129 and then Nkind (Parent (Comp)) = N_Component_Declaration
3130 and then Present (Expression (Parent (Comp)))
3131 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
3132 and then Is_Fully_Defined
3133 (Designated_Type (Component_Type (Etype (Comp))))
3137 (Component_Type (Etype (Comp))), N, Result);
3144 SSO_ADC := Get_Attribute_Definition_Clause
3145 (Rec, Attribute_Scalar_Storage_Order);
3147 -- Check consistent attribute setting on component types
3150 Comp_ADC_Present : Boolean;
3152 Comp := First_Component (Rec);
3153 while Present (Comp) loop
3154 Check_Component_Storage_Order
3158 Comp_ADC_Present => Comp_ADC_Present);
3159 SSO_ADC_Component := SSO_ADC_Component or Comp_ADC_Present;
3160 Next_Component (Comp);
3164 -- Deal with default setting of reverse storage order
3166 Set_SSO_From_Default (Rec);
3168 -- Now deal with reverse storage order/bit order issues
3170 if Present (SSO_ADC) then
3172 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3173 -- the former is specified.
3175 if Reverse_Bit_Order (Rec) /= Reverse_Storage_Order (Rec) then
3177 -- Note: report error on Rec, not on SSO_ADC, as ADC may apply
3178 -- to some ancestor type.
3180 Error_Msg_Sloc := Sloc (SSO_ADC);
3182 ("scalar storage order for& specified# inconsistent with "
3183 & "bit order", Rec);
3186 -- Warn if there is an Scalar_Storage_Order attribute definition
3187 -- clause but no component clause, no component that itself has
3188 -- such an attribute definition, and no pragma Pack.
3190 if not (Placed_Component
3197 ("??scalar storage order specified but no component clause",
3202 -- Deal with Bit_Order aspect
3204 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
3206 if Present (ADC) and then Base_Type (Rec) = Rec then
3207 if not (Placed_Component
3208 or else Present (SSO_ADC)
3209 or else Is_Packed (Rec))
3211 -- Warn if clause has no effect when no component clause is
3212 -- present, but suppress warning if the Bit_Order is required
3213 -- due to the presence of a Scalar_Storage_Order attribute.
3216 ("??bit order specification has no effect", ADC);
3218 ("\??since no component clauses were specified", ADC);
3220 -- Here is where we do the processing to adjust component clauses
3221 -- for reversed bit order.
3223 elsif Reverse_Bit_Order (Rec)
3224 and then not Reverse_Storage_Order (Rec)
3226 Adjust_Record_For_Reverse_Bit_Order (Rec);
3228 -- Case where we have both an explicit Bit_Order and the same
3229 -- Scalar_Storage_Order: leave record untouched, the back-end
3230 -- will take care of required layout conversions.
3238 -- Complete error checking on record representation clause (e.g.
3239 -- overlap of components). This is called after adjusting the
3240 -- record for reverse bit order.
3243 RRC : constant Node_Id := Get_Record_Representation_Clause (Rec);
3245 if Present (RRC) then
3246 Check_Record_Representation_Clause (RRC);
3250 -- Set OK_To_Reorder_Components depending on debug flags
3252 if Is_Base_Type (Rec) and then Convention (Rec) = Convention_Ada then
3253 if (Has_Discriminants (Rec) and then Debug_Flag_Dot_V)
3255 (not Has_Discriminants (Rec) and then Debug_Flag_Dot_R)
3257 Set_OK_To_Reorder_Components (Rec);
3261 -- Check for useless pragma Pack when all components placed. We only
3262 -- do this check for record types, not subtypes, since a subtype may
3263 -- have all its components placed, and it still makes perfectly good
3264 -- sense to pack other subtypes or the parent type. We do not give
3265 -- this warning if Optimize_Alignment is set to Space, since the
3266 -- pragma Pack does have an effect in this case (it always resets
3267 -- the alignment to one).
3269 if Ekind (Rec) = E_Record_Type
3270 and then Is_Packed (Rec)
3271 and then not Unplaced_Component
3272 and then Optimize_Alignment /= 'S'
3274 -- Reset packed status. Probably not necessary, but we do it so
3275 -- that there is no chance of the back end doing something strange
3276 -- with this redundant indication of packing.
3278 Set_Is_Packed (Rec, False);
3280 -- Give warning if redundant constructs warnings on
3282 if Warn_On_Redundant_Constructs then
3283 Error_Msg_N -- CODEFIX
3284 ("??pragma Pack has no effect, no unplaced components",
3285 Get_Rep_Pragma (Rec, Name_Pack));
3289 -- If this is the record corresponding to a remote type, freeze the
3290 -- remote type here since that is what we are semantically freezing.
3291 -- This prevents the freeze node for that type in an inner scope.
3293 if Ekind (Rec) = E_Record_Type then
3294 if Present (Corresponding_Remote_Type (Rec)) then
3295 Freeze_And_Append (Corresponding_Remote_Type (Rec), N, Result);
3298 -- Check for controlled components and unchecked unions.
3300 Comp := First_Component (Rec);
3301 while Present (Comp) loop
3303 -- Do not set Has_Controlled_Component on a class-wide
3304 -- equivalent type. See Make_CW_Equivalent_Type.
3306 if not Is_Class_Wide_Equivalent_Type (Rec)
3308 (Has_Controlled_Component (Etype (Comp))
3310 (Chars (Comp) /= Name_uParent
3311 and then Is_Controlled (Etype (Comp)))
3313 (Is_Protected_Type (Etype (Comp))
3315 Present (Corresponding_Record_Type (Etype (Comp)))
3317 Has_Controlled_Component
3318 (Corresponding_Record_Type (Etype (Comp)))))
3320 Set_Has_Controlled_Component (Rec);
3323 if Has_Unchecked_Union (Etype (Comp)) then
3324 Set_Has_Unchecked_Union (Rec);
3327 -- Scan component declaration for likely misuses of current
3328 -- instance, either in a constraint or a default expression.
3330 if Has_Per_Object_Constraint (Comp) then
3331 Check_Current_Instance (Parent (Comp));
3334 Next_Component (Comp);
3338 -- Enforce the restriction that access attributes with a current
3339 -- instance prefix can only apply to limited types. This comment
3340 -- is floating here, but does not seem to belong here???
3342 -- Set component alignment if not otherwise already set
3344 Set_Component_Alignment_If_Not_Set (Rec);
3346 -- For first subtypes, check if there are any fixed-point fields with
3347 -- component clauses, where we must check the size. This is not done
3348 -- till the freeze point since for fixed-point types, we do not know
3349 -- the size until the type is frozen. Similar processing applies to
3350 -- bit packed arrays.
3352 if Is_First_Subtype (Rec) then
3353 Comp := First_Component (Rec);
3354 while Present (Comp) loop
3355 if Present (Component_Clause (Comp))
3356 and then (Is_Fixed_Point_Type (Etype (Comp))
3357 or else Is_Bit_Packed_Array (Etype (Comp)))
3360 (Component_Name (Component_Clause (Comp)),
3366 Next_Component (Comp);
3370 -- Generate warning for applying C or C++ convention to a record
3371 -- with discriminants. This is suppressed for the unchecked union
3372 -- case, since the whole point in this case is interface C. We also
3373 -- do not generate this within instantiations, since we will have
3374 -- generated a message on the template.
3376 if Has_Discriminants (E)
3377 and then not Is_Unchecked_Union (E)
3378 and then (Convention (E) = Convention_C
3380 Convention (E) = Convention_CPP)
3381 and then Comes_From_Source (E)
3382 and then not In_Instance
3383 and then not Has_Warnings_Off (E)
3384 and then not Has_Warnings_Off (Base_Type (E))
3387 Cprag : constant Node_Id := Get_Rep_Pragma (E, Name_Convention);
3391 if Present (Cprag) then
3392 A2 := Next (First (Pragma_Argument_Associations (Cprag)));
3394 if Convention (E) = Convention_C then
3396 ("?x?variant record has no direct equivalent in C",
3400 ("?x?variant record has no direct equivalent in C++",
3405 ("\?x?use of convention for type& is dubious", A2, E);
3410 -- See if Size is too small as is (and implicit packing might help)
3412 if not Is_Packed (Rec)
3414 -- No implicit packing if even one component is explicitly placed
3416 and then not Placed_Component
3418 -- Or even one component is aliased
3420 and then not Aliased_Component
3422 -- Must have size clause and all scalar components
3424 and then Has_Size_Clause (Rec)
3425 and then All_Scalar_Components
3427 -- Do not try implicit packing on records with discriminants, too
3428 -- complicated, especially in the variant record case.
3430 and then not Has_Discriminants (Rec)
3432 -- We can implicitly pack if the specified size of the record is
3433 -- less than the sum of the object sizes (no point in packing if
3434 -- this is not the case).
3436 and then RM_Size (Rec) < Scalar_Component_Total_Esize
3438 -- And the total RM size cannot be greater than the specified size
3439 -- since otherwise packing will not get us where we have to be.
3441 and then RM_Size (Rec) >= Scalar_Component_Total_RM_Size
3443 -- Never do implicit packing in CodePeer or SPARK modes since
3444 -- we don't do any packing in these modes, since this generates
3445 -- over-complex code that confuses static analysis, and in
3446 -- general, neither CodePeer not GNATprove care about the
3447 -- internal representation of objects.
3449 and then not (CodePeer_Mode or GNATprove_Mode)
3451 -- If implicit packing enabled, do it
3453 if Implicit_Packing then
3454 Set_Is_Packed (Rec);
3456 -- Otherwise flag the size clause
3460 Sz : constant Node_Id := Size_Clause (Rec);
3462 Error_Msg_NE -- CODEFIX
3463 ("size given for& too small", Sz, Rec);
3464 Error_Msg_N -- CODEFIX
3465 ("\use explicit pragma Pack "
3466 & "or use pragma Implicit_Packing", Sz);
3471 -- The following checks are only relevant when SPARK_Mode is on as
3472 -- they are not standard Ada legality rules.
3474 if SPARK_Mode = On then
3475 if Is_SPARK_Volatile (Rec) then
3477 -- A discriminated type cannot be volatile (SPARK RM C.6(4))
3479 if Has_Discriminants (Rec) then
3480 Error_Msg_N ("discriminated type & cannot be volatile", Rec);
3482 -- A tagged type cannot be volatile (SPARK RM C.6(5))
3484 elsif Is_Tagged_Type (Rec) then
3485 Error_Msg_N ("tagged type & cannot be volatile", Rec);
3488 -- A non-volatile record type cannot contain volatile components
3489 -- (SPARK RM C.6(2))
3492 Comp := First_Component (Rec);
3493 while Present (Comp) loop
3494 if Comes_From_Source (Comp)
3495 and then Is_SPARK_Volatile (Etype (Comp))
3497 Error_Msg_Name_1 := Chars (Rec);
3499 ("component & of non-volatile type % cannot be "
3500 & "volatile", Comp);
3503 Next_Component (Comp);
3508 -- All done if not a full record definition
3510 if Ekind (Rec) /= E_Record_Type then
3514 -- Finally we need to check the variant part to make sure that
3515 -- all types within choices are properly frozen as part of the
3516 -- freezing of the record type.
3518 Check_Variant_Part : declare
3519 D : constant Node_Id := Declaration_Node (Rec);
3524 -- Find component list
3528 if Nkind (D) = N_Full_Type_Declaration then
3529 T := Type_Definition (D);
3531 if Nkind (T) = N_Record_Definition then
3532 C := Component_List (T);
3534 elsif Nkind (T) = N_Derived_Type_Definition
3535 and then Present (Record_Extension_Part (T))
3537 C := Component_List (Record_Extension_Part (T));
3541 -- Case of variant part present
3543 if Present (C) and then Present (Variant_Part (C)) then
3544 Freeze_Choices_In_Variant_Part (Variant_Part (C));
3547 -- Note: we used to call Check_Choices here, but it is too early,
3548 -- since predicated subtypes are frozen here, but their freezing
3549 -- actions are in Analyze_Freeze_Entity, which has not been called
3550 -- yet for entities frozen within this procedure, so we moved that
3551 -- call to the Analyze_Freeze_Entity for the record type.
3553 end Check_Variant_Part;
3554 end Freeze_Record_Type;
3556 -------------------------------
3557 -- Has_Boolean_Aspect_Import --
3558 -------------------------------
3560 function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean is
3561 Decl : constant Node_Id := Declaration_Node (E);
3566 if Has_Aspects (Decl) then
3567 Asp := First (Aspect_Specifications (Decl));
3568 while Present (Asp) loop
3569 Expr := Expression (Asp);
3571 -- The value of aspect Import is True when the expression is
3572 -- either missing or it is explicitly set to True.
3574 if Get_Aspect_Id (Asp) = Aspect_Import
3576 or else (Compile_Time_Known_Value (Expr)
3577 and then Is_True (Expr_Value (Expr))))
3587 end Has_Boolean_Aspect_Import;
3589 ------------------------------
3590 -- Wrap_Imported_Subprogram --
3591 ------------------------------
3593 -- The issue here is that our normal approach of checking preconditions
3594 -- and postconditions does not work for imported procedures, since we
3595 -- are not generating code for the body. To get around this we create
3596 -- a wrapper, as shown by the following example:
3598 -- procedure K (A : Integer);
3599 -- pragma Import (C, K);
3601 -- The spec is rewritten by removing the effects of pragma Import, but
3602 -- leaving the convention unchanged, as though the source had said:
3604 -- procedure K (A : Integer);
3605 -- pragma Convention (C, K);
3607 -- and we create a body, added to the entity K freeze actions, which
3610 -- procedure K (A : Integer) is
3611 -- procedure K (A : Integer);
3612 -- pragma Import (C, K);
3617 -- Now the contract applies in the normal way to the outer procedure,
3618 -- and the inner procedure has no contracts, so there is no problem
3619 -- in just calling it to get the original effect.
3621 -- In the case of a function, we create an appropriate return statement
3622 -- for the subprogram body that calls the inner procedure.
3624 procedure Wrap_Imported_Subprogram (E : Entity_Id) is
3625 Loc : constant Source_Ptr := Sloc (E);
3626 CE : constant Name_Id := Chars (E);
3635 -- Nothing to do if not imported
3637 if not Is_Imported (E) then
3640 -- Test enabling conditions for wrapping
3642 elsif Is_Subprogram (E)
3643 and then Present (Contract (E))
3644 and then Present (Pre_Post_Conditions (Contract (E)))
3645 and then not GNATprove_Mode
3647 -- Here we do the wrap
3649 -- Note on calls to Copy_Separate_Tree. The trees we are copying
3650 -- here are fully analyzed, but we definitely want fully syntactic
3651 -- unanalyzed trees in the body we construct, so that the analysis
3652 -- generates the right visibility, and that is exactly what the
3653 -- calls to Copy_Separate_Tree give us.
3655 -- Acquire copy of Inline pragma
3658 Copy_Separate_Tree (Import_Pragma (E));
3660 -- Fix up spec to be not imported any more
3662 Set_Is_Imported (E, False);
3663 Set_Interface_Name (E, Empty);
3664 Set_Has_Completion (E, False);
3665 Set_Import_Pragma (E, Empty);
3667 -- Grab the subprogram declaration and specification
3669 Spec := Declaration_Node (E);
3671 -- Build parameter list that we need
3674 Forml := First_Formal (E);
3675 while Present (Forml) loop
3676 Append_To (Parms, Make_Identifier (Loc, Chars (Forml)));
3677 Next_Formal (Forml);
3682 if Ekind_In (E, E_Function, E_Generic_Function) then
3684 Make_Simple_Return_Statement (Loc,
3686 Make_Function_Call (Loc,
3687 Name => Make_Identifier (Loc, CE),
3688 Parameter_Associations => Parms));
3692 Make_Procedure_Call_Statement (Loc,
3693 Name => Make_Identifier (Loc, CE),
3694 Parameter_Associations => Parms);
3697 -- Now build the body
3700 Make_Subprogram_Body (Loc,
3702 Copy_Separate_Tree (Spec),
3703 Declarations => New_List (
3704 Make_Subprogram_Declaration (Loc,
3706 Copy_Separate_Tree (Spec)),
3708 Handled_Statement_Sequence =>
3709 Make_Handled_Sequence_Of_Statements (Loc,
3710 Statements => New_List (Stmt),
3711 End_Label => Make_Identifier (Loc, CE)));
3713 -- Append the body to freeze result
3715 Add_To_Result (Bod);
3718 -- Case of imported subprogram that does not get wrapped
3721 -- Set Is_Public. All imported entities need an external symbol
3722 -- created for them since they are always referenced from another
3723 -- object file. Note this used to be set when we set Is_Imported
3724 -- back in Sem_Prag, but now we delay it to this point, since we
3725 -- don't want to set this flag if we wrap an imported subprogram.
3729 end Wrap_Imported_Subprogram;
3731 -- Start of processing for Freeze_Entity
3734 -- We are going to test for various reasons why this entity need not be
3735 -- frozen here, but in the case of an Itype that's defined within a
3736 -- record, that test actually applies to the record.
3738 if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
3739 Test_E := Scope (E);
3740 elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
3741 and then Is_Record_Type (Underlying_Type (Scope (E)))
3743 Test_E := Underlying_Type (Scope (E));
3746 -- Do not freeze if already frozen since we only need one freeze node
3748 if Is_Frozen (E) then
3751 -- It is improper to freeze an external entity within a generic because
3752 -- its freeze node will appear in a non-valid context. The entity will
3753 -- be frozen in the proper scope after the current generic is analyzed.
3754 -- However, aspects must be analyzed because they may be queried later
3755 -- within the generic itself, and the corresponding pragma or attribute
3756 -- definition has not been analyzed yet.
3758 elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then
3759 if Has_Delayed_Aspects (E) then
3760 Analyze_Aspects_At_Freeze_Point (E);
3765 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3766 -- the instance, the same applies to the subtype renaming the actual.
3768 elsif Is_Private_Type (E)
3769 and then Is_Generic_Actual_Type (E)
3770 and then No (Full_View (Base_Type (E)))
3771 and then Ada_Version >= Ada_2012
3775 -- Generic types need no freeze node and have no delayed semantic
3778 elsif Is_Generic_Type (E) then
3781 -- Do not freeze a global entity within an inner scope created during
3782 -- expansion. A call to subprogram E within some internal procedure
3783 -- (a stream attribute for example) might require freezing E, but the
3784 -- freeze node must appear in the same declarative part as E itself.
3785 -- The two-pass elaboration mechanism in gigi guarantees that E will
3786 -- be frozen before the inner call is elaborated. We exclude constants
3787 -- from this test, because deferred constants may be frozen early, and
3788 -- must be diagnosed (e.g. in the case of a deferred constant being used
3789 -- in a default expression). If the enclosing subprogram comes from
3790 -- source, or is a generic instance, then the freeze point is the one
3791 -- mandated by the language, and we freeze the entity. A subprogram that
3792 -- is a child unit body that acts as a spec does not have a spec that
3793 -- comes from source, but can only come from source.
3795 elsif In_Open_Scopes (Scope (Test_E))
3796 and then Scope (Test_E) /= Current_Scope
3797 and then Ekind (Test_E) /= E_Constant
3804 while Present (S) loop
3805 if Is_Overloadable (S) then
3806 if Comes_From_Source (S)
3807 or else Is_Generic_Instance (S)
3808 or else Is_Child_Unit (S)
3820 -- Similarly, an inlined instance body may make reference to global
3821 -- entities, but these references cannot be the proper freezing point
3822 -- for them, and in the absence of inlining freezing will take place in
3823 -- their own scope. Normally instance bodies are analyzed after the
3824 -- enclosing compilation, and everything has been frozen at the proper
3825 -- place, but with front-end inlining an instance body is compiled
3826 -- before the end of the enclosing scope, and as a result out-of-order
3827 -- freezing must be prevented.
3829 elsif Front_End_Inlining
3830 and then In_Instance_Body
3831 and then Present (Scope (Test_E))
3837 S := Scope (Test_E);
3838 while Present (S) loop
3839 if Is_Generic_Instance (S) then
3851 elsif Ekind (E) = E_Generic_Package then
3852 return Freeze_Generic_Entities (E);
3855 -- Add checks to detect proper initialization of scalars that may appear
3856 -- as subprogram parameters.
3858 if Is_Subprogram (E) and then Check_Validity_Of_Parameters then
3859 Apply_Parameter_Validity_Checks (E);
3862 -- Deal with delayed aspect specifications. The analysis of the aspect
3863 -- is required to be delayed to the freeze point, thus we analyze the
3864 -- pragma or attribute definition clause in the tree at this point. We
3865 -- also analyze the aspect specification node at the freeze point when
3866 -- the aspect doesn't correspond to pragma/attribute definition clause.
3868 if Has_Delayed_Aspects (E) then
3869 Analyze_Aspects_At_Freeze_Point (E);
3872 -- Here to freeze the entity
3876 -- Case of entity being frozen is other than a type
3878 if not Is_Type (E) then
3880 -- If entity is exported or imported and does not have an external
3881 -- name, now is the time to provide the appropriate default name.
3882 -- Skip this if the entity is stubbed, since we don't need a name
3883 -- for any stubbed routine. For the case on intrinsics, if no
3884 -- external name is specified, then calls will be handled in
3885 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3886 -- external name is provided, then Expand_Intrinsic_Call leaves
3887 -- calls in place for expansion by GIGI.
3889 if (Is_Imported (E) or else Is_Exported (E))
3890 and then No (Interface_Name (E))
3891 and then Convention (E) /= Convention_Stubbed
3892 and then Convention (E) /= Convention_Intrinsic
3894 Set_Encoded_Interface_Name
3895 (E, Get_Default_External_Name (E));
3897 -- If entity is an atomic object appearing in a declaration and
3898 -- the expression is an aggregate, assign it to a temporary to
3899 -- ensure that the actual assignment is done atomically rather
3900 -- than component-wise (the assignment to the temp may be done
3901 -- component-wise, but that is harmless).
3904 and then Nkind (Parent (E)) = N_Object_Declaration
3905 and then Present (Expression (Parent (E)))
3906 and then Nkind (Expression (Parent (E))) = N_Aggregate
3907 and then Is_Atomic_Aggregate (Expression (Parent (E)), Etype (E))
3914 if Is_Subprogram (E) then
3916 -- Check for needing to wrap imported subprogram
3918 Wrap_Imported_Subprogram (E);
3920 -- Freeze all parameter types and the return type (RM 13.14(14)).
3921 -- However skip this for internal subprograms. This is also where
3922 -- any extra formal parameters are created since we now know
3923 -- whether the subprogram will use a foreign convention.
3925 if not Is_Internal (E) then
3929 Warn_Node : Node_Id;
3932 -- Loop through formals
3934 Formal := First_Formal (E);
3935 while Present (Formal) loop
3936 F_Type := Etype (Formal);
3938 -- AI05-0151 : incomplete types can appear in a profile.
3939 -- By the time the entity is frozen, the full view must
3940 -- be available, unless it is a limited view.
3942 if Is_Incomplete_Type (F_Type)
3943 and then Present (Full_View (F_Type))
3944 and then not From_Limited_With (F_Type)
3946 F_Type := Full_View (F_Type);
3947 Set_Etype (Formal, F_Type);
3950 Freeze_And_Append (F_Type, N, Result);
3952 if Is_Private_Type (F_Type)
3953 and then Is_Private_Type (Base_Type (F_Type))
3954 and then No (Full_View (Base_Type (F_Type)))
3955 and then not Is_Generic_Type (F_Type)
3956 and then not Is_Derived_Type (F_Type)
3958 -- If the type of a formal is incomplete, subprogram
3959 -- is being frozen prematurely. Within an instance
3960 -- (but not within a wrapper package) this is an
3961 -- artifact of our need to regard the end of an
3962 -- instantiation as a freeze point. Otherwise it is
3963 -- a definite error.
3966 Set_Is_Frozen (E, False);
3969 elsif not After_Last_Declaration
3970 and then not Freezing_Library_Level_Tagged_Type
3972 Error_Msg_Node_1 := F_Type;
3974 ("type& must be fully defined before this point",
3979 -- Check suspicious parameter for C function. These tests
3980 -- apply only to exported/imported subprograms.
3982 if Warn_On_Export_Import
3983 and then Comes_From_Source (E)
3984 and then (Convention (E) = Convention_C
3986 Convention (E) = Convention_CPP)
3987 and then (Is_Imported (E) or else Is_Exported (E))
3988 and then Convention (E) /= Convention (Formal)
3989 and then not Has_Warnings_Off (E)
3990 and then not Has_Warnings_Off (F_Type)
3991 and then not Has_Warnings_Off (Formal)
3993 -- Qualify mention of formals with subprogram name
3995 Error_Msg_Qual_Level := 1;
3997 -- Check suspicious use of fat C pointer
3999 if Is_Access_Type (F_Type)
4000 and then Esize (F_Type) > Ttypes.System_Address_Size
4003 ("?x?type of & does not correspond to C pointer!",
4006 -- Check suspicious return of boolean
4008 elsif Root_Type (F_Type) = Standard_Boolean
4009 and then Convention (F_Type) = Convention_Ada
4010 and then not Has_Warnings_Off (F_Type)
4011 and then not Has_Size_Clause (F_Type)
4012 and then VM_Target = No_VM
4015 ("& is an 8-bit Ada Boolean?x?", Formal);
4017 ("\use appropriate corresponding type in C "
4018 & "(e.g. char)?x?", Formal);
4020 -- Check suspicious tagged type
4022 elsif (Is_Tagged_Type (F_Type)
4023 or else (Is_Access_Type (F_Type)
4026 (Designated_Type (F_Type))))
4027 and then Convention (E) = Convention_C
4030 ("?x?& involves a tagged type which does not "
4031 & "correspond to any C type!", Formal);
4033 -- Check wrong convention subprogram pointer
4035 elsif Ekind (F_Type) = E_Access_Subprogram_Type
4036 and then not Has_Foreign_Convention (F_Type)
4039 ("?x?subprogram pointer & should "
4040 & "have foreign convention!", Formal);
4041 Error_Msg_Sloc := Sloc (F_Type);
4043 ("\?x?add Convention pragma to declaration of &#",
4047 -- Turn off name qualification after message output
4049 Error_Msg_Qual_Level := 0;
4052 -- Check for unconstrained array in exported foreign
4055 if Has_Foreign_Convention (E)
4056 and then not Is_Imported (E)
4057 and then Is_Array_Type (F_Type)
4058 and then not Is_Constrained (F_Type)
4059 and then Warn_On_Export_Import
4061 -- Exclude VM case, since both .NET and JVM can handle
4062 -- unconstrained arrays without a problem.
4064 and then VM_Target = No_VM
4066 Error_Msg_Qual_Level := 1;
4068 -- If this is an inherited operation, place the
4069 -- warning on the derived type declaration, rather
4070 -- than on the original subprogram.
4072 if Nkind (Original_Node (Parent (E))) =
4073 N_Full_Type_Declaration
4075 Warn_Node := Parent (E);
4077 if Formal = First_Formal (E) then
4079 ("??in inherited operation&", Warn_Node, E);
4082 Warn_Node := Formal;
4086 ("?x?type of argument& is unconstrained array",
4089 ("?x?foreign caller must pass bounds explicitly",
4091 Error_Msg_Qual_Level := 0;
4094 if not From_Limited_With (F_Type) then
4095 if Is_Access_Type (F_Type) then
4096 F_Type := Designated_Type (F_Type);
4099 -- If the formal is an anonymous_access_to_subprogram
4100 -- freeze the subprogram type as well, to prevent
4101 -- scope anomalies in gigi, because there is no other
4102 -- clear point at which it could be frozen.
4104 if Is_Itype (Etype (Formal))
4105 and then Ekind (F_Type) = E_Subprogram_Type
4107 Freeze_And_Append (F_Type, N, Result);
4111 Next_Formal (Formal);
4114 -- Case of function: similar checks on return type
4116 if Ekind (E) = E_Function then
4118 -- Freeze return type
4120 R_Type := Etype (E);
4122 -- AI05-0151: the return type may have been incomplete
4123 -- at the point of declaration. Replace it with the full
4124 -- view, unless the current type is a limited view. In
4125 -- that case the full view is in a different unit, and
4126 -- gigi finds the non-limited view after the other unit
4129 if Ekind (R_Type) = E_Incomplete_Type
4130 and then Present (Full_View (R_Type))
4131 and then not From_Limited_With (R_Type)
4133 R_Type := Full_View (R_Type);
4134 Set_Etype (E, R_Type);
4136 -- If the return type is a limited view and the non-
4137 -- limited view is still incomplete, the function has
4138 -- to be frozen at a later time.
4140 elsif Ekind (R_Type) = E_Incomplete_Type
4141 and then From_Limited_With (R_Type)
4143 Ekind (Non_Limited_View (R_Type)) = E_Incomplete_Type
4145 Set_Is_Frozen (E, False);
4149 Freeze_And_Append (R_Type, N, Result);
4151 -- Check suspicious return type for C function
4153 if Warn_On_Export_Import
4154 and then (Convention (E) = Convention_C
4156 Convention (E) = Convention_CPP)
4157 and then (Is_Imported (E) or else Is_Exported (E))
4159 -- Check suspicious return of fat C pointer
4161 if Is_Access_Type (R_Type)
4162 and then Esize (R_Type) > Ttypes.System_Address_Size
4163 and then not Has_Warnings_Off (E)
4164 and then not Has_Warnings_Off (R_Type)
4167 ("?x?return type of& does not "
4168 & "correspond to C pointer!", E);
4170 -- Check suspicious return of boolean
4172 elsif Root_Type (R_Type) = Standard_Boolean
4173 and then Convention (R_Type) = Convention_Ada
4174 and then VM_Target = No_VM
4175 and then not Has_Warnings_Off (E)
4176 and then not Has_Warnings_Off (R_Type)
4177 and then not Has_Size_Clause (R_Type)
4180 N : constant Node_Id :=
4181 Result_Definition (Declaration_Node (E));
4184 ("return type of & is an 8-bit Ada Boolean?x?",
4187 ("\use appropriate corresponding type in C "
4188 & "(e.g. char)?x?", N, E);
4191 -- Check suspicious return tagged type
4193 elsif (Is_Tagged_Type (R_Type)
4194 or else (Is_Access_Type (R_Type)
4197 (Designated_Type (R_Type))))
4198 and then Convention (E) = Convention_C
4199 and then not Has_Warnings_Off (E)
4200 and then not Has_Warnings_Off (R_Type)
4203 ("?x?return type of & does not "
4204 & "correspond to C type!", E);
4206 -- Check return of wrong convention subprogram pointer
4208 elsif Ekind (R_Type) = E_Access_Subprogram_Type
4209 and then not Has_Foreign_Convention (R_Type)
4210 and then not Has_Warnings_Off (E)
4211 and then not Has_Warnings_Off (R_Type)
4214 ("?x?& should return a foreign "
4215 & "convention subprogram pointer", E);
4216 Error_Msg_Sloc := Sloc (R_Type);
4218 ("\?x?add Convention pragma to declaration of& #",
4223 -- Give warning for suspicious return of a result of an
4224 -- unconstrained array type in a foreign convention
4227 if Has_Foreign_Convention (E)
4229 -- We are looking for a return of unconstrained array
4231 and then Is_Array_Type (R_Type)
4232 and then not Is_Constrained (R_Type)
4234 -- Exclude imported routines, the warning does not
4235 -- belong on the import, but rather on the routine
4238 and then not Is_Imported (E)
4240 -- Exclude VM case, since both .NET and JVM can handle
4241 -- return of unconstrained arrays without a problem.
4243 and then VM_Target = No_VM
4245 -- Check that general warning is enabled, and that it
4246 -- is not suppressed for this particular case.
4248 and then Warn_On_Export_Import
4249 and then not Has_Warnings_Off (E)
4250 and then not Has_Warnings_Off (R_Type)
4253 ("?x?foreign convention function& should not " &
4254 "return unconstrained array!", E);
4260 -- Must freeze its parent first if it is a derived subprogram
4262 if Present (Alias (E)) then
4263 Freeze_And_Append (Alias (E), N, Result);
4266 -- We don't freeze internal subprograms, because we don't normally
4267 -- want addition of extra formals or mechanism setting to happen
4268 -- for those. However we do pass through predefined dispatching
4269 -- cases, since extra formals may be needed in some cases, such as
4270 -- for the stream 'Input function (build-in-place formals).
4272 if not Is_Internal (E)
4273 or else Is_Predefined_Dispatching_Operation (E)
4275 Freeze_Subprogram (E);
4278 -- If warning on suspicious contracts then check for the case of
4279 -- a postcondition other than False for a No_Return subprogram.
4282 and then Warn_On_Suspicious_Contract
4283 and then Present (Contract (E))
4286 Prag : Node_Id := Pre_Post_Conditions (Contract (E));
4290 while Present (Prag) loop
4291 if Nam_In (Pragma_Name (Prag), Name_Post,
4297 (First (Pragma_Argument_Associations (Prag)));
4299 if Nkind (Exp) /= N_Identifier
4300 or else Chars (Exp) /= Name_False
4303 ("useless postcondition, & is marked "
4304 & "No_Return?T?", Exp, E);
4308 Prag := Next_Pragma (Prag);
4313 -- Here for other than a subprogram or type
4316 -- If entity has a type, and it is not a generic unit, then
4317 -- freeze it first (RM 13.14(10)).
4319 if Present (Etype (E))
4320 and then Ekind (E) /= E_Generic_Function
4322 Freeze_And_Append (Etype (E), N, Result);
4325 -- Special processing for objects created by object declaration
4327 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
4329 -- Abstract type allowed only for C++ imported variables or
4332 -- Note: we inhibit this check for objects that do not come
4333 -- from source because there is at least one case (the
4334 -- expansion of x'Class'Input where x is abstract) where we
4335 -- legitimately generate an abstract object.
4337 if Is_Abstract_Type (Etype (E))
4338 and then Comes_From_Source (Parent (E))
4339 and then not (Is_Imported (E)
4340 and then Is_CPP_Class (Etype (E)))
4342 Error_Msg_N ("type of object cannot be abstract",
4343 Object_Definition (Parent (E)));
4345 if Is_CPP_Class (Etype (E)) then
4347 ("\} may need a cpp_constructor",
4348 Object_Definition (Parent (E)), Etype (E));
4352 -- For object created by object declaration, perform required
4353 -- categorization (preelaborate and pure) checks. Defer these
4354 -- checks to freeze time since pragma Import inhibits default
4355 -- initialization and thus pragma Import affects these checks.
4357 Validate_Object_Declaration (Declaration_Node (E));
4359 -- If there is an address clause, check that it is valid
4361 Check_Address_Clause (E);
4363 -- Reset Is_True_Constant for aliased object. We consider that
4364 -- the fact that something is aliased may indicate that some
4365 -- funny business is going on, e.g. an aliased object is passed
4366 -- by reference to a procedure which captures the address of
4367 -- the object, which is later used to assign a new value. Such
4368 -- code is highly dubious, but we choose to make it "work" for
4371 -- However, we don't do that for internal entities. We figure
4372 -- that if we deliberately set Is_True_Constant for an internal
4373 -- entity, e.g. a dispatch table entry, then we mean it.
4375 if (Is_Aliased (E) or else Is_Aliased (Etype (E)))
4376 and then not Is_Internal_Name (Chars (E))
4378 Set_Is_True_Constant (E, False);
4381 -- If the object needs any kind of default initialization, an
4382 -- error must be issued if No_Default_Initialization applies.
4383 -- The check doesn't apply to imported objects, which are not
4384 -- ever default initialized, and is why the check is deferred
4385 -- until freezing, at which point we know if Import applies.
4386 -- Deferred constants are also exempted from this test because
4387 -- their completion is explicit, or through an import pragma.
4389 if Ekind (E) = E_Constant
4390 and then Present (Full_View (E))
4394 elsif Comes_From_Source (E)
4395 and then not Is_Imported (E)
4396 and then not Has_Init_Expression (Declaration_Node (E))
4398 ((Has_Non_Null_Base_Init_Proc (Etype (E))
4399 and then not No_Initialization (Declaration_Node (E))
4400 and then not Is_Value_Type (Etype (E))
4401 and then not Initialization_Suppressed (Etype (E)))
4403 (Needs_Simple_Initialization (Etype (E))
4404 and then not Is_Internal (E)))
4406 Has_Default_Initialization := True;
4408 (No_Default_Initialization, Declaration_Node (E));
4411 -- Check that a Thread_Local_Storage variable does not have
4412 -- default initialization, and any explicit initialization must
4413 -- either be the null constant or a static constant.
4415 if Has_Pragma_Thread_Local_Storage (E) then
4417 Decl : constant Node_Id := Declaration_Node (E);
4419 if Has_Default_Initialization
4421 (Has_Init_Expression (Decl)
4423 (No (Expression (Decl))
4425 (Is_OK_Static_Expression (Expression (Decl))
4427 Nkind (Expression (Decl)) = N_Null)))
4430 ("Thread_Local_Storage variable& is "
4431 & "improperly initialized", Decl, E);
4433 ("\only allowed initialization is explicit "
4434 & "NULL or static expression", Decl, E);
4439 -- For imported objects, set Is_Public unless there is also an
4440 -- address clause, which means that there is no external symbol
4441 -- needed for the Import (Is_Public may still be set for other
4442 -- unrelated reasons). Note that we delayed this processing
4443 -- till freeze time so that we can be sure not to set the flag
4444 -- if there is an address clause. If there is such a clause,
4445 -- then the only purpose of the Import pragma is to suppress
4446 -- implicit initialization.
4448 if Is_Imported (E) and then No (Address_Clause (E)) then
4452 -- For source objects that are not Imported and are library
4453 -- level, if no linker section pragma was given inherit the
4454 -- appropriate linker section from the corresponding type.
4456 if Comes_From_Source (E)
4457 and then not Is_Imported (E)
4458 and then Is_Library_Level_Entity (E)
4459 and then No (Linker_Section_Pragma (E))
4461 Set_Linker_Section_Pragma
4462 (E, Linker_Section_Pragma (Etype (E)));
4465 -- For convention C objects of an enumeration type, warn if
4466 -- the size is not integer size and no explicit size given.
4467 -- Skip warning for Boolean, and Character, assume programmer
4468 -- expects 8-bit sizes for these cases.
4470 if (Convention (E) = Convention_C
4472 Convention (E) = Convention_CPP)
4473 and then Is_Enumeration_Type (Etype (E))
4474 and then not Is_Character_Type (Etype (E))
4475 and then not Is_Boolean_Type (Etype (E))
4476 and then Esize (Etype (E)) < Standard_Integer_Size
4477 and then not Has_Size_Clause (E)
4479 Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size);
4481 ("??convention C enumeration object has size less than ^",
4483 Error_Msg_N ("\??use explicit size clause to set size", E);
4487 -- Check that a constant which has a pragma Volatile[_Components]
4488 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4490 -- Note: Atomic[_Components] also sets Volatile[_Components]
4492 if Ekind (E) = E_Constant
4493 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
4494 and then not Is_Imported (E)
4495 and then not Has_Boolean_Aspect_Import (E)
4497 -- Make sure we actually have a pragma, and have not merely
4498 -- inherited the indication from elsewhere (e.g. an address
4499 -- clause, which is not good enough in RM terms).
4501 if Has_Rep_Pragma (E, Name_Atomic)
4503 Has_Rep_Pragma (E, Name_Atomic_Components)
4506 ("stand alone atomic constant must be " &
4507 "imported (RM C.6(13))", E);
4509 elsif Has_Rep_Pragma (E, Name_Volatile)
4511 Has_Rep_Pragma (E, Name_Volatile_Components)
4514 ("stand alone volatile constant must be " &
4515 "imported (RM C.6(13))", E);
4519 -- Static objects require special handling
4521 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4522 and then Is_Statically_Allocated (E)
4524 Freeze_Static_Object (E);
4527 -- Remaining step is to layout objects
4529 if Ekind_In (E, E_Variable, E_Constant, E_Loop_Parameter)
4530 or else Is_Formal (E)
4535 -- For an object that does not have delayed freezing, and whose
4536 -- initialization actions have been captured in a compound
4537 -- statement, move them back now directly within the enclosing
4538 -- statement sequence.
4540 if Ekind_In (E, E_Constant, E_Variable)
4541 and then not Has_Delayed_Freeze (E)
4543 Explode_Initialization_Compound_Statement (E);
4547 -- Case of a type or subtype being frozen
4550 -- We used to check here that a full type must have preelaborable
4551 -- initialization if it completes a private type specified with
4552 -- pragma Preelaborable_Initialization, but that missed cases where
4553 -- the types occur within a generic package, since the freezing
4554 -- that occurs within a containing scope generally skips traversal
4555 -- of a generic unit's declarations (those will be frozen within
4556 -- instances). This check was moved to Analyze_Package_Specification.
4558 -- The type may be defined in a generic unit. This can occur when
4559 -- freezing a generic function that returns the type (which is
4560 -- defined in a parent unit). It is clearly meaningless to freeze
4561 -- this type. However, if it is a subtype, its size may be determi-
4562 -- nable and used in subsequent checks, so might as well try to
4565 -- In Ada 2012, Freeze_Entities is also used in the front end to
4566 -- trigger the analysis of aspect expressions, so in this case we
4567 -- want to continue the freezing process.
4569 if Present (Scope (E))
4570 and then Is_Generic_Unit (Scope (E))
4572 (not Has_Predicates (E)
4573 and then not Has_Delayed_Freeze (E))
4575 Check_Compile_Time_Size (E);
4579 -- Check for error of Type_Invariant'Class applied to an untagged
4580 -- type (check delayed to freeze time when full type is available).
4583 Prag : constant Node_Id := Get_Pragma (E, Pragma_Invariant);
4586 and then Class_Present (Prag)
4587 and then not Is_Tagged_Type (E)
4590 ("Type_Invariant''Class cannot be specified for &",
4593 ("\can only be specified for a tagged type", Prag);
4597 -- Deal with special cases of freezing for subtype
4599 if E /= Base_Type (E) then
4601 -- Before we do anything else, a specialized test for the case of
4602 -- a size given for an array where the array needs to be packed,
4603 -- but was not so the size cannot be honored. This is the case
4604 -- where implicit packing may apply. The reason we do this so
4605 -- early is that if we have implicit packing, the layout of the
4606 -- base type is affected, so we must do this before we freeze
4609 -- We could do this processing only if implicit packing is enabled
4610 -- since in all other cases, the error would be caught by the back
4611 -- end. However, we choose to do the check even if we do not have
4612 -- implicit packing enabled, since this allows us to give a more
4613 -- useful error message (advising use of pragmas Implicit_Packing
4616 if Is_Array_Type (E) then
4618 Ctyp : constant Entity_Id := Component_Type (E);
4619 Rsiz : constant Uint := RM_Size (Ctyp);
4620 SZ : constant Node_Id := Size_Clause (E);
4621 Btyp : constant Entity_Id := Base_Type (E);
4628 -- Number of elements in array
4631 -- Check enabling conditions. These are straightforward
4632 -- except for the test for a limited composite type. This
4633 -- eliminates the rare case of a array of limited components
4634 -- where there are issues of whether or not we can go ahead
4635 -- and pack the array (since we can't freely pack and unpack
4636 -- arrays if they are limited).
4638 -- Note that we check the root type explicitly because the
4639 -- whole point is we are doing this test before we have had
4640 -- a chance to freeze the base type (and it is that freeze
4641 -- action that causes stuff to be inherited).
4643 if Has_Size_Clause (E)
4644 and then Known_Static_RM_Size (E)
4645 and then not Is_Packed (E)
4646 and then not Has_Pragma_Pack (E)
4647 and then not Has_Component_Size_Clause (E)
4648 and then Known_Static_RM_Size (Ctyp)
4649 and then RM_Size (Ctyp) < 64
4650 and then not Is_Limited_Composite (E)
4651 and then not Is_Packed (Root_Type (E))
4652 and then not Has_Component_Size_Clause (Root_Type (E))
4653 and then not (CodePeer_Mode or GNATprove_Mode)
4655 -- Compute number of elements in array
4657 Num_Elmts := Uint_1;
4658 Indx := First_Index (E);
4659 while Present (Indx) loop
4660 Get_Index_Bounds (Indx, Lo, Hi);
4662 if not (Compile_Time_Known_Value (Lo)
4664 Compile_Time_Known_Value (Hi))
4666 goto No_Implicit_Packing;
4672 Expr_Value (Hi) - Expr_Value (Lo) + 1);
4676 -- What we are looking for here is the situation where
4677 -- the RM_Size given would be exactly right if there was
4678 -- a pragma Pack (resulting in the component size being
4679 -- the same as the RM_Size). Furthermore, the component
4680 -- type size must be an odd size (not a multiple of
4681 -- storage unit). If the component RM size is an exact
4682 -- number of storage units that is a power of two, the
4683 -- array is not packed and has a standard representation.
4685 if RM_Size (E) = Num_Elmts * Rsiz
4686 and then Rsiz mod System_Storage_Unit /= 0
4688 -- For implicit packing mode, just set the component
4691 if Implicit_Packing then
4692 Set_Component_Size (Btyp, Rsiz);
4693 Set_Is_Bit_Packed_Array (Btyp);
4694 Set_Is_Packed (Btyp);
4695 Set_Has_Non_Standard_Rep (Btyp);
4697 -- Otherwise give an error message
4701 ("size given for& too small", SZ, E);
4702 Error_Msg_N -- CODEFIX
4703 ("\use explicit pragma Pack "
4704 & "or use pragma Implicit_Packing", SZ);
4707 elsif RM_Size (E) = Num_Elmts * Rsiz
4708 and then Implicit_Packing
4710 (Rsiz / System_Storage_Unit = 1
4712 Rsiz / System_Storage_Unit = 2
4714 Rsiz / System_Storage_Unit = 4)
4716 -- Not a packed array, but indicate the desired
4717 -- component size, for the back-end.
4719 Set_Component_Size (Btyp, Rsiz);
4725 <<No_Implicit_Packing>>
4727 -- If ancestor subtype present, freeze that first. Note that this
4728 -- will also get the base type frozen. Need RM reference ???
4730 Atype := Ancestor_Subtype (E);
4732 if Present (Atype) then
4733 Freeze_And_Append (Atype, N, Result);
4735 -- No ancestor subtype present
4738 -- See if we have a nearest ancestor that has a predicate.
4739 -- That catches the case of derived type with a predicate.
4740 -- Need RM reference here ???
4742 Atype := Nearest_Ancestor (E);
4744 if Present (Atype) and then Has_Predicates (Atype) then
4745 Freeze_And_Append (Atype, N, Result);
4748 -- Freeze base type before freezing the entity (RM 13.14(15))
4750 if E /= Base_Type (E) then
4751 Freeze_And_Append (Base_Type (E), N, Result);
4755 -- A subtype inherits all the type-related representation aspects
4756 -- from its parents (RM 13.1(8)).
4758 Inherit_Aspects_At_Freeze_Point (E);
4760 -- For a derived type, freeze its parent type first (RM 13.14(15))
4762 elsif Is_Derived_Type (E) then
4763 Freeze_And_Append (Etype (E), N, Result);
4764 Freeze_And_Append (First_Subtype (Etype (E)), N, Result);
4766 -- A derived type inherits each type-related representation aspect
4767 -- of its parent type that was directly specified before the
4768 -- declaration of the derived type (RM 13.1(15)).
4770 Inherit_Aspects_At_Freeze_Point (E);
4773 -- Check for incompatible size and alignment for record type
4775 if Warn_On_Size_Alignment
4776 and then Is_Record_Type (E)
4777 and then Has_Size_Clause (E) and then Has_Alignment_Clause (E)
4779 -- If explicit Object_Size clause given assume that the programmer
4780 -- knows what he is doing, and expects the compiler behavior.
4782 and then not Has_Object_Size_Clause (E)
4784 -- Check for size not a multiple of alignment
4786 and then RM_Size (E) mod (Alignment (E) * System_Storage_Unit) /= 0
4789 SC : constant Node_Id := Size_Clause (E);
4790 AC : constant Node_Id := Alignment_Clause (E);
4792 Abits : constant Uint := Alignment (E) * System_Storage_Unit;
4795 if Present (SC) and then Present (AC) then
4799 if Sloc (SC) > Sloc (AC) then
4802 ("??size is not a multiple of alignment for &", Loc, E);
4803 Error_Msg_Sloc := Sloc (AC);
4804 Error_Msg_Uint_1 := Alignment (E);
4805 Error_Msg_N ("\??alignment of ^ specified #", Loc);
4810 ("??size is not a multiple of alignment for &", Loc, E);
4811 Error_Msg_Sloc := Sloc (SC);
4812 Error_Msg_Uint_1 := RM_Size (E);
4813 Error_Msg_N ("\??size of ^ specified #", Loc);
4816 Error_Msg_Uint_1 := ((RM_Size (E) / Abits) + 1) * Abits;
4817 Error_Msg_N ("\??Object_Size will be increased to ^", Loc);
4824 if Is_Array_Type (E) then
4825 Freeze_Array_Type (E);
4827 -- For a class-wide type, the corresponding specific type is
4828 -- frozen as well (RM 13.14(15))
4830 elsif Is_Class_Wide_Type (E) then
4831 Freeze_And_Append (Root_Type (E), N, Result);
4833 -- If the base type of the class-wide type is still incomplete,
4834 -- the class-wide remains unfrozen as well. This is legal when
4835 -- E is the formal of a primitive operation of some other type
4836 -- which is being frozen.
4838 if not Is_Frozen (Root_Type (E)) then
4839 Set_Is_Frozen (E, False);
4843 -- The equivalent type associated with a class-wide subtype needs
4844 -- to be frozen to ensure that its layout is done.
4846 if Ekind (E) = E_Class_Wide_Subtype
4847 and then Present (Equivalent_Type (E))
4849 Freeze_And_Append (Equivalent_Type (E), N, Result);
4852 -- Generate an itype reference for a library-level class-wide type
4853 -- at the freeze point. Otherwise the first explicit reference to
4854 -- the type may appear in an inner scope which will be rejected by
4858 and then Is_Compilation_Unit (Scope (E))
4861 Ref : constant Node_Id := Make_Itype_Reference (Loc);
4866 -- From a gigi point of view, a class-wide subtype derives
4867 -- from its record equivalent type. As a result, the itype
4868 -- reference must appear after the freeze node of the
4869 -- equivalent type or gigi will reject the reference.
4871 if Ekind (E) = E_Class_Wide_Subtype
4872 and then Present (Equivalent_Type (E))
4874 Insert_After (Freeze_Node (Equivalent_Type (E)), Ref);
4876 Add_To_Result (Ref);
4881 -- For a record type or record subtype, freeze all component types
4882 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4883 -- using Is_Record_Type, because we don't want to attempt the freeze
4884 -- for the case of a private type with record extension (we will do
4885 -- that later when the full type is frozen).
4887 elsif Ekind_In (E, E_Record_Type, E_Record_Subtype)
4888 and then not Is_Generic_Unit (Scope (E))
4890 Freeze_Record_Type (E);
4892 -- For a concurrent type, freeze corresponding record type. This does
4893 -- not correspond to any specific rule in the RM, but the record type
4894 -- is essentially part of the concurrent type. Also freeze all local
4895 -- entities. This includes record types created for entry parameter
4896 -- blocks and whatever local entities may appear in the private part.
4898 elsif Is_Concurrent_Type (E) then
4899 if Present (Corresponding_Record_Type (E)) then
4900 Freeze_And_Append (Corresponding_Record_Type (E), N, Result);
4903 Comp := First_Entity (E);
4904 while Present (Comp) loop
4905 if Is_Type (Comp) then
4906 Freeze_And_Append (Comp, N, Result);
4908 elsif (Ekind (Comp)) /= E_Function then
4910 -- The guard on the presence of the Etype seems to be needed
4911 -- for some CodePeer (-gnatcC) cases, but not clear why???
4913 if Present (Etype (Comp)) then
4914 if Is_Itype (Etype (Comp))
4915 and then Underlying_Type (Scope (Etype (Comp))) = E
4917 Undelay_Type (Etype (Comp));
4920 Freeze_And_Append (Etype (Comp), N, Result);
4927 -- Private types are required to point to the same freeze node as
4928 -- their corresponding full views. The freeze node itself has to
4929 -- point to the partial view of the entity (because from the partial
4930 -- view, we can retrieve the full view, but not the reverse).
4931 -- However, in order to freeze correctly, we need to freeze the full
4932 -- view. If we are freezing at the end of a scope (or within the
4933 -- scope of the private type), the partial and full views will have
4934 -- been swapped, the full view appears first in the entity chain and
4935 -- the swapping mechanism ensures that the pointers are properly set
4938 -- If we encounter the partial view before the full view (e.g. when
4939 -- freezing from another scope), we freeze the full view, and then
4940 -- set the pointers appropriately since we cannot rely on swapping to
4941 -- fix things up (subtypes in an outer scope might not get swapped).
4943 elsif Is_Incomplete_Or_Private_Type (E)
4944 and then not Is_Generic_Type (E)
4946 -- The construction of the dispatch table associated with library
4947 -- level tagged types forces freezing of all the primitives of the
4948 -- type, which may cause premature freezing of the partial view.
4952 -- type T is tagged private;
4953 -- type DT is new T with private;
4954 -- procedure Prim (X : in out T; Y : in out DT'Class);
4956 -- type T is tagged null record;
4958 -- type DT is new T with null record;
4961 -- In this case the type will be frozen later by the usual
4962 -- mechanism: an object declaration, an instantiation, or the
4963 -- end of a declarative part.
4965 if Is_Library_Level_Tagged_Type (E)
4966 and then not Present (Full_View (E))
4968 Set_Is_Frozen (E, False);
4971 -- Case of full view present
4973 elsif Present (Full_View (E)) then
4975 -- If full view has already been frozen, then no further
4976 -- processing is required
4978 if Is_Frozen (Full_View (E)) then
4979 Set_Has_Delayed_Freeze (E, False);
4980 Set_Freeze_Node (E, Empty);
4981 Check_Debug_Info_Needed (E);
4983 -- Otherwise freeze full view and patch the pointers so that
4984 -- the freeze node will elaborate both views in the back-end.
4988 Full : constant Entity_Id := Full_View (E);
4991 if Is_Private_Type (Full)
4992 and then Present (Underlying_Full_View (Full))
4995 (Underlying_Full_View (Full), N, Result);
4998 Freeze_And_Append (Full, N, Result);
5000 if Has_Delayed_Freeze (E) then
5001 F_Node := Freeze_Node (Full);
5003 if Present (F_Node) then
5004 Set_Freeze_Node (E, F_Node);
5005 Set_Entity (F_Node, E);
5008 -- {Incomplete,Private}_Subtypes with Full_Views
5009 -- constrained by discriminants.
5011 Set_Has_Delayed_Freeze (E, False);
5012 Set_Freeze_Node (E, Empty);
5017 Check_Debug_Info_Needed (E);
5020 -- AI-117 requires that the convention of a partial view be the
5021 -- same as the convention of the full view. Note that this is a
5022 -- recognized breach of privacy, but it's essential for logical
5023 -- consistency of representation, and the lack of a rule in
5024 -- RM95 was an oversight.
5026 Set_Convention (E, Convention (Full_View (E)));
5028 Set_Size_Known_At_Compile_Time (E,
5029 Size_Known_At_Compile_Time (Full_View (E)));
5031 -- Size information is copied from the full view to the
5032 -- incomplete or private view for consistency.
5034 -- We skip this is the full view is not a type. This is very
5035 -- strange of course, and can only happen as a result of
5036 -- certain illegalities, such as a premature attempt to derive
5037 -- from an incomplete type.
5039 if Is_Type (Full_View (E)) then
5040 Set_Size_Info (E, Full_View (E));
5041 Set_RM_Size (E, RM_Size (Full_View (E)));
5046 -- Case of no full view present. If entity is derived or subtype,
5047 -- it is safe to freeze, correctness depends on the frozen status
5048 -- of parent. Otherwise it is either premature usage, or a Taft
5049 -- amendment type, so diagnosis is at the point of use and the
5050 -- type might be frozen later.
5052 elsif E /= Base_Type (E) or else Is_Derived_Type (E) then
5056 Set_Is_Frozen (E, False);
5060 -- For access subprogram, freeze types of all formals, the return
5061 -- type was already frozen, since it is the Etype of the function.
5062 -- Formal types can be tagged Taft amendment types, but otherwise
5063 -- they cannot be incomplete.
5065 elsif Ekind (E) = E_Subprogram_Type then
5066 Formal := First_Formal (E);
5067 while Present (Formal) loop
5068 if Ekind (Etype (Formal)) = E_Incomplete_Type
5069 and then No (Full_View (Etype (Formal)))
5070 and then not Is_Value_Type (Etype (Formal))
5072 if Is_Tagged_Type (Etype (Formal)) then
5075 -- AI05-151: Incomplete types are allowed in access to
5076 -- subprogram specifications.
5078 elsif Ada_Version < Ada_2012 then
5080 ("invalid use of incomplete type&", E, Etype (Formal));
5084 Freeze_And_Append (Etype (Formal), N, Result);
5085 Next_Formal (Formal);
5088 Freeze_Subprogram (E);
5090 -- For access to a protected subprogram, freeze the equivalent type
5091 -- (however this is not set if we are not generating code or if this
5092 -- is an anonymous type used just for resolution).
5094 elsif Is_Access_Protected_Subprogram_Type (E) then
5095 if Present (Equivalent_Type (E)) then
5096 Freeze_And_Append (Equivalent_Type (E), N, Result);
5100 -- Generic types are never seen by the back-end, and are also not
5101 -- processed by the expander (since the expander is turned off for
5102 -- generic processing), so we never need freeze nodes for them.
5104 if Is_Generic_Type (E) then
5108 -- Some special processing for non-generic types to complete
5109 -- representation details not known till the freeze point.
5111 if Is_Fixed_Point_Type (E) then
5112 Freeze_Fixed_Point_Type (E);
5114 -- Some error checks required for ordinary fixed-point type. Defer
5115 -- these till the freeze-point since we need the small and range
5116 -- values. We only do these checks for base types
5118 if Is_Ordinary_Fixed_Point_Type (E) and then Is_Base_Type (E) then
5119 if Small_Value (E) < Ureal_2_M_80 then
5120 Error_Msg_Name_1 := Name_Small;
5122 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E);
5124 elsif Small_Value (E) > Ureal_2_80 then
5125 Error_Msg_Name_1 := Name_Small;
5127 ("`&''%` too large, maximum allowed is 2.0'*'*80", E);
5130 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
5131 Error_Msg_Name_1 := Name_First;
5133 ("`&''%` too small, minimum allowed is -10.0'*'*36", E);
5136 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
5137 Error_Msg_Name_1 := Name_Last;
5139 ("`&''%` too large, maximum allowed is 10.0'*'*36", E);
5143 elsif Is_Enumeration_Type (E) then
5144 Freeze_Enumeration_Type (E);
5146 elsif Is_Integer_Type (E) then
5147 Adjust_Esize_For_Alignment (E);
5149 if Is_Modular_Integer_Type (E)
5150 and then Warn_On_Suspicious_Modulus_Value
5152 Check_Suspicious_Modulus (E);
5155 elsif Is_Access_Type (E)
5156 and then not Is_Access_Subprogram_Type (E)
5158 -- If a pragma Default_Storage_Pool applies, and this type has no
5159 -- Storage_Pool or Storage_Size clause (which must have occurred
5160 -- before the freezing point), then use the default. This applies
5161 -- only to base types.
5163 -- None of this applies to access to subprograms, for which there
5164 -- are clearly no pools.
5166 if Present (Default_Pool)
5167 and then Is_Base_Type (E)
5168 and then not Has_Storage_Size_Clause (E)
5169 and then No (Associated_Storage_Pool (E))
5171 -- Case of pragma Default_Storage_Pool (null)
5173 if Nkind (Default_Pool) = N_Null then
5174 Set_No_Pool_Assigned (E);
5176 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5179 Set_Associated_Storage_Pool (E, Entity (Default_Pool));
5183 -- Check restriction for standard storage pool
5185 if No (Associated_Storage_Pool (E)) then
5186 Check_Restriction (No_Standard_Storage_Pools, E);
5189 -- Deal with error message for pure access type. This is not an
5190 -- error in Ada 2005 if there is no pool (see AI-366).
5192 if Is_Pure_Unit_Access_Type (E)
5193 and then (Ada_Version < Ada_2005
5194 or else not No_Pool_Assigned (E))
5195 and then not Is_Generic_Unit (Scope (E))
5197 Error_Msg_N ("named access type not allowed in pure unit", E);
5199 if Ada_Version >= Ada_2005 then
5201 ("\would be legal if Storage_Size of 0 given??", E);
5203 elsif No_Pool_Assigned (E) then
5205 ("\would be legal in Ada 2005??", E);
5209 ("\would be legal in Ada 2005 if "
5210 & "Storage_Size of 0 given??", E);
5215 -- Case of composite types
5217 if Is_Composite_Type (E) then
5219 -- AI-117 requires that all new primitives of a tagged type must
5220 -- inherit the convention of the full view of the type. Inherited
5221 -- and overriding operations are defined to inherit the convention
5222 -- of their parent or overridden subprogram (also specified in
5223 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5224 -- and New_Overloaded_Entity). Here we set the convention of
5225 -- primitives that are still convention Ada, which will ensure
5226 -- that any new primitives inherit the type's convention. Class-
5227 -- wide types can have a foreign convention inherited from their
5228 -- specific type, but are excluded from this since they don't have
5229 -- any associated primitives.
5231 if Is_Tagged_Type (E)
5232 and then not Is_Class_Wide_Type (E)
5233 and then Convention (E) /= Convention_Ada
5236 Prim_List : constant Elist_Id := Primitive_Operations (E);
5240 Prim := First_Elmt (Prim_List);
5241 while Present (Prim) loop
5242 if Convention (Node (Prim)) = Convention_Ada then
5243 Set_Convention (Node (Prim), Convention (E));
5251 -- If the type is a simple storage pool type, then this is where
5252 -- we attempt to locate and validate its Allocate, Deallocate, and
5253 -- Storage_Size operations (the first is required, and the latter
5254 -- two are optional). We also verify that the full type for a
5255 -- private type is allowed to be a simple storage pool type.
5257 if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type))
5258 and then (Is_Base_Type (E) or else Has_Private_Declaration (E))
5260 -- If the type is marked Has_Private_Declaration, then this is
5261 -- a full type for a private type that was specified with the
5262 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5263 -- pragma is allowed for the full type (for example, it can't
5264 -- be an array type, or a nonlimited record type).
5266 if Has_Private_Declaration (E) then
5267 if (not Is_Record_Type (E) or else not Is_Limited_View (E))
5268 and then not Is_Private_Type (E)
5270 Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type;
5272 ("pragma% can only apply to full type that is an " &
5273 "explicitly limited type", E);
5277 Validate_Simple_Pool_Ops : declare
5278 Pool_Type : Entity_Id renames E;
5279 Address_Type : constant Entity_Id := RTE (RE_Address);
5280 Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count);
5282 procedure Validate_Simple_Pool_Op_Formal
5283 (Pool_Op : Entity_Id;
5284 Pool_Op_Formal : in out Entity_Id;
5285 Expected_Mode : Formal_Kind;
5286 Expected_Type : Entity_Id;
5287 Formal_Name : String;
5288 OK_Formal : in out Boolean);
5289 -- Validate one formal Pool_Op_Formal of the candidate pool
5290 -- operation Pool_Op. The formal must be of Expected_Type
5291 -- and have mode Expected_Mode. OK_Formal will be set to
5292 -- False if the formal doesn't match. If OK_Formal is False
5293 -- on entry, then the formal will effectively be ignored
5294 -- (because validation of the pool op has already failed).
5295 -- Upon return, Pool_Op_Formal will be updated to the next
5298 procedure Validate_Simple_Pool_Operation
5299 (Op_Name : Name_Id);
5300 -- Search for and validate a simple pool operation with the
5301 -- name Op_Name. If the name is Allocate, then there must be
5302 -- exactly one such primitive operation for the simple pool
5303 -- type. If the name is Deallocate or Storage_Size, then
5304 -- there can be at most one such primitive operation. The
5305 -- profile of the located primitive must conform to what
5306 -- is expected for each operation.
5308 ------------------------------------
5309 -- Validate_Simple_Pool_Op_Formal --
5310 ------------------------------------
5312 procedure Validate_Simple_Pool_Op_Formal
5313 (Pool_Op : Entity_Id;
5314 Pool_Op_Formal : in out Entity_Id;
5315 Expected_Mode : Formal_Kind;
5316 Expected_Type : Entity_Id;
5317 Formal_Name : String;
5318 OK_Formal : in out Boolean)
5321 -- If OK_Formal is False on entry, then simply ignore
5322 -- the formal, because an earlier formal has already
5325 if not OK_Formal then
5328 -- If no formal is passed in, then issue an error for a
5331 elsif not Present (Pool_Op_Formal) then
5333 ("simple storage pool op missing formal " &
5334 Formal_Name & " of type&", Pool_Op, Expected_Type);
5340 if Etype (Pool_Op_Formal) /= Expected_Type then
5342 -- If the pool type was expected for this formal, then
5343 -- this will not be considered a candidate operation
5344 -- for the simple pool, so we unset OK_Formal so that
5345 -- the op and any later formals will be ignored.
5347 if Expected_Type = Pool_Type then
5354 ("wrong type for formal " & Formal_Name &
5355 " of simple storage pool op; expected type&",
5356 Pool_Op_Formal, Expected_Type);
5360 -- Issue error if formal's mode is not the expected one
5362 if Ekind (Pool_Op_Formal) /= Expected_Mode then
5364 ("wrong mode for formal of simple storage pool op",
5368 -- Advance to the next formal
5370 Next_Formal (Pool_Op_Formal);
5371 end Validate_Simple_Pool_Op_Formal;
5373 ------------------------------------
5374 -- Validate_Simple_Pool_Operation --
5375 ------------------------------------
5377 procedure Validate_Simple_Pool_Operation
5381 Found_Op : Entity_Id := Empty;
5387 (Nam_In (Op_Name, Name_Allocate,
5389 Name_Storage_Size));
5391 Error_Msg_Name_1 := Op_Name;
5393 -- For each homonym declared immediately in the scope
5394 -- of the simple storage pool type, determine whether
5395 -- the homonym is an operation of the pool type, and,
5396 -- if so, check that its profile is as expected for
5397 -- a simple pool operation of that name.
5399 Op := Get_Name_Entity_Id (Op_Name);
5400 while Present (Op) loop
5401 if Ekind_In (Op, E_Function, E_Procedure)
5402 and then Scope (Op) = Current_Scope
5404 Formal := First_Entity (Op);
5408 -- The first parameter must be of the pool type
5409 -- in order for the operation to qualify.
5411 if Op_Name = Name_Storage_Size then
5412 Validate_Simple_Pool_Op_Formal
5413 (Op, Formal, E_In_Parameter, Pool_Type,
5416 Validate_Simple_Pool_Op_Formal
5417 (Op, Formal, E_In_Out_Parameter, Pool_Type,
5421 -- If another operation with this name has already
5422 -- been located for the type, then flag an error,
5423 -- since we only allow the type to have a single
5426 if Present (Found_Op) and then Is_OK then
5428 ("only one % operation allowed for " &
5429 "simple storage pool type&", Op, Pool_Type);
5432 -- In the case of Allocate and Deallocate, a formal
5433 -- of type System.Address is required.
5435 if Op_Name = Name_Allocate then
5436 Validate_Simple_Pool_Op_Formal
5437 (Op, Formal, E_Out_Parameter,
5438 Address_Type, "Storage_Address", Is_OK);
5440 elsif Op_Name = Name_Deallocate then
5441 Validate_Simple_Pool_Op_Formal
5442 (Op, Formal, E_In_Parameter,
5443 Address_Type, "Storage_Address", Is_OK);
5446 -- In the case of Allocate and Deallocate, formals
5447 -- of type Storage_Count are required as the third
5448 -- and fourth parameters.
5450 if Op_Name /= Name_Storage_Size then
5451 Validate_Simple_Pool_Op_Formal
5452 (Op, Formal, E_In_Parameter,
5453 Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK);
5454 Validate_Simple_Pool_Op_Formal
5455 (Op, Formal, E_In_Parameter,
5456 Stg_Cnt_Type, "Alignment", Is_OK);
5459 -- If no mismatched formals have been found (Is_OK)
5460 -- and no excess formals are present, then this
5461 -- operation has been validated, so record it.
5463 if not Present (Formal) and then Is_OK then
5471 -- There must be a valid Allocate operation for the type,
5472 -- so issue an error if none was found.
5474 if Op_Name = Name_Allocate
5475 and then not Present (Found_Op)
5477 Error_Msg_N ("missing % operation for simple " &
5478 "storage pool type", Pool_Type);
5480 elsif Present (Found_Op) then
5482 -- Simple pool operations can't be abstract
5484 if Is_Abstract_Subprogram (Found_Op) then
5486 ("simple storage pool operation must not be " &
5487 "abstract", Found_Op);
5490 -- The Storage_Size operation must be a function with
5491 -- Storage_Count as its result type.
5493 if Op_Name = Name_Storage_Size then
5494 if Ekind (Found_Op) = E_Procedure then
5496 ("% operation must be a function", Found_Op);
5498 elsif Etype (Found_Op) /= Stg_Cnt_Type then
5500 ("wrong result type for%, expected type&",
5501 Found_Op, Stg_Cnt_Type);
5504 -- Allocate and Deallocate must be procedures
5506 elsif Ekind (Found_Op) = E_Function then
5508 ("% operation must be a procedure", Found_Op);
5511 end Validate_Simple_Pool_Operation;
5513 -- Start of processing for Validate_Simple_Pool_Ops
5516 Validate_Simple_Pool_Operation (Name_Allocate);
5517 Validate_Simple_Pool_Operation (Name_Deallocate);
5518 Validate_Simple_Pool_Operation (Name_Storage_Size);
5519 end Validate_Simple_Pool_Ops;
5523 -- Now that all types from which E may depend are frozen, see if the
5524 -- size is known at compile time, if it must be unsigned, or if
5525 -- strict alignment is required
5527 Check_Compile_Time_Size (E);
5528 Check_Unsigned_Type (E);
5530 if Base_Type (E) = E then
5531 Check_Strict_Alignment (E);
5534 -- Do not allow a size clause for a type which does not have a size
5535 -- that is known at compile time
5537 if Has_Size_Clause (E)
5538 and then not Size_Known_At_Compile_Time (E)
5540 -- Suppress this message if errors posted on E, even if we are
5541 -- in all errors mode, since this is often a junk message
5543 if not Error_Posted (E) then
5545 ("size clause not allowed for variable length type",
5550 -- Now we set/verify the representation information, in particular
5551 -- the size and alignment values. This processing is not required for
5552 -- generic types, since generic types do not play any part in code
5553 -- generation, and so the size and alignment values for such types
5554 -- are irrelevant. Ditto for types declared within a generic unit,
5555 -- which may have components that depend on generic parameters, and
5556 -- that will be recreated in an instance.
5558 if Inside_A_Generic then
5561 -- Otherwise we call the layout procedure
5567 -- If this is an access to subprogram whose designated type is itself
5568 -- a subprogram type, the return type of this anonymous subprogram
5569 -- type must be decorated as well.
5571 if Ekind (E) = E_Anonymous_Access_Subprogram_Type
5572 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
5574 Layout_Type (Etype (Designated_Type (E)));
5577 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5578 -- this is where we analye the expression (after the type is frozen,
5579 -- since in the case of Default_Value, we are analyzing with the
5580 -- type itself, and we treat Default_Component_Value similarly for
5581 -- the sake of uniformity).
5583 if Is_First_Subtype (E) and then Has_Default_Aspect (E) then
5590 if Is_Scalar_Type (E) then
5591 Nam := Name_Default_Value;
5593 Exp := Default_Aspect_Value (Typ);
5595 Nam := Name_Default_Component_Value;
5596 Typ := Component_Type (E);
5597 Exp := Default_Aspect_Component_Value (E);
5600 Analyze_And_Resolve (Exp, Typ);
5602 if Etype (Exp) /= Any_Type then
5603 if not Is_OK_Static_Expression (Exp) then
5604 Error_Msg_Name_1 := Nam;
5605 Flag_Non_Static_Expr
5606 ("aspect% requires static expression", Exp);
5612 -- End of freeze processing for type entities
5615 -- Here is where we logically freeze the current entity. If it has a
5616 -- freeze node, then this is the point at which the freeze node is
5617 -- linked into the result list.
5619 if Has_Delayed_Freeze (E) then
5621 -- If a freeze node is already allocated, use it, otherwise allocate
5622 -- a new one. The preallocation happens in the case of anonymous base
5623 -- types, where we preallocate so that we can set First_Subtype_Link.
5624 -- Note that we reset the Sloc to the current freeze location.
5626 if Present (Freeze_Node (E)) then
5627 F_Node := Freeze_Node (E);
5628 Set_Sloc (F_Node, Loc);
5631 F_Node := New_Node (N_Freeze_Entity, Loc);
5632 Set_Freeze_Node (E, F_Node);
5633 Set_Access_Types_To_Process (F_Node, No_Elist);
5634 Set_TSS_Elist (F_Node, No_Elist);
5635 Set_Actions (F_Node, No_List);
5638 Set_Entity (F_Node, E);
5639 Add_To_Result (F_Node);
5641 -- A final pass over record types with discriminants. If the type
5642 -- has an incomplete declaration, there may be constrained access
5643 -- subtypes declared elsewhere, which do not depend on the discrimi-
5644 -- nants of the type, and which are used as component types (i.e.
5645 -- the full view is a recursive type). The designated types of these
5646 -- subtypes can only be elaborated after the type itself, and they
5647 -- need an itype reference.
5649 if Ekind (E) = E_Record_Type
5650 and then Has_Discriminants (E)
5658 Comp := First_Component (E);
5659 while Present (Comp) loop
5660 Typ := Etype (Comp);
5662 if Ekind (Comp) = E_Component
5663 and then Is_Access_Type (Typ)
5664 and then Scope (Typ) /= E
5665 and then Base_Type (Designated_Type (Typ)) = E
5666 and then Is_Itype (Designated_Type (Typ))
5668 IR := Make_Itype_Reference (Sloc (Comp));
5669 Set_Itype (IR, Designated_Type (Typ));
5670 Append (IR, Result);
5673 Next_Component (Comp);
5679 -- When a type is frozen, the first subtype of the type is frozen as
5680 -- well (RM 13.14(15)). This has to be done after freezing the type,
5681 -- since obviously the first subtype depends on its own base type.
5684 Freeze_And_Append (First_Subtype (E), N, Result);
5686 -- If we just froze a tagged non-class wide record, then freeze the
5687 -- corresponding class-wide type. This must be done after the tagged
5688 -- type itself is frozen, because the class-wide type refers to the
5689 -- tagged type which generates the class.
5691 if Is_Tagged_Type (E)
5692 and then not Is_Class_Wide_Type (E)
5693 and then Present (Class_Wide_Type (E))
5695 Freeze_And_Append (Class_Wide_Type (E), N, Result);
5699 Check_Debug_Info_Needed (E);
5701 -- Special handling for subprograms
5703 if Is_Subprogram (E) then
5705 -- If subprogram has address clause then reset Is_Public flag, since
5706 -- we do not want the backend to generate external references.
5708 if Present (Address_Clause (E))
5709 and then not Is_Library_Level_Entity (E)
5711 Set_Is_Public (E, False);
5718 -----------------------------
5719 -- Freeze_Enumeration_Type --
5720 -----------------------------
5722 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
5724 -- By default, if no size clause is present, an enumeration type with
5725 -- Convention C is assumed to interface to a C enum, and has integer
5726 -- size. This applies to types. For subtypes, verify that its base
5727 -- type has no size clause either. Treat other foreign conventions
5728 -- in the same way, and also make sure alignment is set right.
5730 if Has_Foreign_Convention (Typ)
5731 and then not Has_Size_Clause (Typ)
5732 and then not Has_Size_Clause (Base_Type (Typ))
5733 and then Esize (Typ) < Standard_Integer_Size
5735 -- Don't do this if Short_Enums on target
5737 and then not Target_Short_Enums
5739 Init_Esize (Typ, Standard_Integer_Size);
5740 Set_Alignment (Typ, Alignment (Standard_Integer));
5742 -- Normal Ada case or size clause present or not Long_C_Enums on target
5745 -- If the enumeration type interfaces to C, and it has a size clause
5746 -- that specifies less than int size, it warrants a warning. The
5747 -- user may intend the C type to be an enum or a char, so this is
5748 -- not by itself an error that the Ada compiler can detect, but it
5749 -- it is a worth a heads-up. For Boolean and Character types we
5750 -- assume that the programmer has the proper C type in mind.
5752 if Convention (Typ) = Convention_C
5753 and then Has_Size_Clause (Typ)
5754 and then Esize (Typ) /= Esize (Standard_Integer)
5755 and then not Is_Boolean_Type (Typ)
5756 and then not Is_Character_Type (Typ)
5758 -- Don't do this if Short_Enums on target
5760 and then not Target_Short_Enums
5763 ("C enum types have the size of a C int??", Size_Clause (Typ));
5766 Adjust_Esize_For_Alignment (Typ);
5768 end Freeze_Enumeration_Type;
5770 -----------------------
5771 -- Freeze_Expression --
5772 -----------------------
5774 procedure Freeze_Expression (N : Node_Id) is
5775 In_Spec_Exp : constant Boolean := In_Spec_Expression;
5778 Desig_Typ : Entity_Id;
5782 Freeze_Outside : Boolean := False;
5783 -- This flag is set true if the entity must be frozen outside the
5784 -- current subprogram. This happens in the case of expander generated
5785 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5786 -- not freeze all entities like other bodies, but which nevertheless
5787 -- may reference entities that have to be frozen before the body and
5788 -- obviously cannot be frozen inside the body.
5790 function In_Exp_Body (N : Node_Id) return Boolean;
5791 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5792 -- it is the handled statement sequence of an expander-generated
5793 -- subprogram (init proc, stream subprogram, or renaming as body).
5794 -- If so, this is not a freezing context.
5800 function In_Exp_Body (N : Node_Id) return Boolean is
5805 if Nkind (N) = N_Subprogram_Body then
5811 if Nkind (P) /= N_Subprogram_Body then
5815 Id := Defining_Unit_Name (Specification (P));
5817 -- Following complex conditional could use comments ???
5819 if Nkind (Id) = N_Defining_Identifier
5820 and then (Is_Init_Proc (Id)
5821 or else Is_TSS (Id, TSS_Stream_Input)
5822 or else Is_TSS (Id, TSS_Stream_Output)
5823 or else Is_TSS (Id, TSS_Stream_Read)
5824 or else Is_TSS (Id, TSS_Stream_Write)
5825 or else Nkind_In (Original_Node (P),
5826 N_Subprogram_Renaming_Declaration,
5827 N_Expression_Function))
5836 -- Start of processing for Freeze_Expression
5839 -- Immediate return if freezing is inhibited. This flag is set by the
5840 -- analyzer to stop freezing on generated expressions that would cause
5841 -- freezing if they were in the source program, but which are not
5842 -- supposed to freeze, since they are created.
5844 if Must_Not_Freeze (N) then
5848 -- If expression is non-static, then it does not freeze in a default
5849 -- expression, see section "Handling of Default Expressions" in the
5850 -- spec of package Sem for further details. Note that we have to make
5851 -- sure that we actually have a real expression (if we have a subtype
5852 -- indication, we can't test Is_OK_Static_Expression). However, we
5853 -- exclude the case of the prefix of an attribute of a static scalar
5854 -- subtype from this early return, because static subtype attributes
5855 -- should always cause freezing, even in default expressions, but
5856 -- the attribute may not have been marked as static yet (because in
5857 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
5858 -- Freeze_Expression on the prefix).
5861 and then Nkind (N) in N_Subexpr
5862 and then not Is_OK_Static_Expression (N)
5863 and then (Nkind (Parent (N)) /= N_Attribute_Reference
5864 or else not (Is_Entity_Name (N)
5865 and then Is_Type (Entity (N))
5866 and then Is_OK_Static_Subtype (Entity (N))))
5871 -- Freeze type of expression if not frozen already
5875 if Nkind (N) in N_Has_Etype then
5876 if not Is_Frozen (Etype (N)) then
5879 -- Base type may be an derived numeric type that is frozen at
5880 -- the point of declaration, but first_subtype is still unfrozen.
5882 elsif not Is_Frozen (First_Subtype (Etype (N))) then
5883 Typ := First_Subtype (Etype (N));
5887 -- For entity name, freeze entity if not frozen already. A special
5888 -- exception occurs for an identifier that did not come from source.
5889 -- We don't let such identifiers freeze a non-internal entity, i.e.
5890 -- an entity that did come from source, since such an identifier was
5891 -- generated by the expander, and cannot have any semantic effect on
5892 -- the freezing semantics. For example, this stops the parameter of
5893 -- an initialization procedure from freezing the variable.
5895 if Is_Entity_Name (N)
5896 and then not Is_Frozen (Entity (N))
5897 and then (Nkind (N) /= N_Identifier
5898 or else Comes_From_Source (N)
5899 or else not Comes_From_Source (Entity (N)))
5903 if Present (Nam) and then Ekind (Nam) = E_Function then
5904 Check_Expression_Function (N, Nam);
5911 -- For an allocator freeze designated type if not frozen already
5913 -- For an aggregate whose component type is an access type, freeze the
5914 -- designated type now, so that its freeze does not appear within the
5915 -- loop that might be created in the expansion of the aggregate. If the
5916 -- designated type is a private type without full view, the expression
5917 -- cannot contain an allocator, so the type is not frozen.
5919 -- For a function, we freeze the entity when the subprogram declaration
5920 -- is frozen, but a function call may appear in an initialization proc.
5921 -- before the declaration is frozen. We need to generate the extra
5922 -- formals, if any, to ensure that the expansion of the call includes
5923 -- the proper actuals. This only applies to Ada subprograms, not to
5930 Desig_Typ := Designated_Type (Etype (N));
5933 if Is_Array_Type (Etype (N))
5934 and then Is_Access_Type (Component_Type (Etype (N)))
5936 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
5939 when N_Selected_Component |
5940 N_Indexed_Component |
5943 if Is_Access_Type (Etype (Prefix (N))) then
5944 Desig_Typ := Designated_Type (Etype (Prefix (N)));
5947 when N_Identifier =>
5949 and then Ekind (Nam) = E_Function
5950 and then Nkind (Parent (N)) = N_Function_Call
5951 and then Convention (Nam) = Convention_Ada
5953 Create_Extra_Formals (Nam);
5960 if Desig_Typ /= Empty
5961 and then (Is_Frozen (Desig_Typ)
5962 or else (not Is_Fully_Defined (Desig_Typ)))
5967 -- All done if nothing needs freezing
5971 and then No (Desig_Typ)
5976 -- Loop for looking at the right place to insert the freeze nodes,
5977 -- exiting from the loop when it is appropriate to insert the freeze
5978 -- node before the current node P.
5980 -- Also checks some special exceptions to the freezing rules. These
5981 -- cases result in a direct return, bypassing the freeze action.
5985 Parent_P := Parent (P);
5987 -- If we don't have a parent, then we are not in a well-formed tree.
5988 -- This is an unusual case, but there are some legitimate situations
5989 -- in which this occurs, notably when the expressions in the range of
5990 -- a type declaration are resolved. We simply ignore the freeze
5991 -- request in this case. Is this right ???
5993 if No (Parent_P) then
5997 -- See if we have got to an appropriate point in the tree
5999 case Nkind (Parent_P) is
6001 -- A special test for the exception of (RM 13.14(8)) for the case
6002 -- of per-object expressions (RM 3.8(18)) occurring in component
6003 -- definition or a discrete subtype definition. Note that we test
6004 -- for a component declaration which includes both cases we are
6005 -- interested in, and furthermore the tree does not have explicit
6006 -- nodes for either of these two constructs.
6008 when N_Component_Declaration =>
6010 -- The case we want to test for here is an identifier that is
6011 -- a per-object expression, this is either a discriminant that
6012 -- appears in a context other than the component declaration
6013 -- or it is a reference to the type of the enclosing construct.
6015 -- For either of these cases, we skip the freezing
6017 if not In_Spec_Expression
6018 and then Nkind (N) = N_Identifier
6019 and then (Present (Entity (N)))
6021 -- We recognize the discriminant case by just looking for
6022 -- a reference to a discriminant. It can only be one for
6023 -- the enclosing construct. Skip freezing in this case.
6025 if Ekind (Entity (N)) = E_Discriminant then
6028 -- For the case of a reference to the enclosing record,
6029 -- (or task or protected type), we look for a type that
6030 -- matches the current scope.
6032 elsif Entity (N) = Current_Scope then
6037 -- If we have an enumeration literal that appears as the choice in
6038 -- the aggregate of an enumeration representation clause, then
6039 -- freezing does not occur (RM 13.14(10)).
6041 when N_Enumeration_Representation_Clause =>
6043 -- The case we are looking for is an enumeration literal
6045 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
6046 and then Is_Enumeration_Type (Etype (N))
6048 -- If enumeration literal appears directly as the choice,
6049 -- do not freeze (this is the normal non-overloaded case)
6051 if Nkind (Parent (N)) = N_Component_Association
6052 and then First (Choices (Parent (N))) = N
6056 -- If enumeration literal appears as the name of function
6057 -- which is the choice, then also do not freeze. This
6058 -- happens in the overloaded literal case, where the
6059 -- enumeration literal is temporarily changed to a function
6060 -- call for overloading analysis purposes.
6062 elsif Nkind (Parent (N)) = N_Function_Call
6064 Nkind (Parent (Parent (N))) = N_Component_Association
6066 First (Choices (Parent (Parent (N)))) = Parent (N)
6072 -- Normally if the parent is a handled sequence of statements,
6073 -- then the current node must be a statement, and that is an
6074 -- appropriate place to insert a freeze node.
6076 when N_Handled_Sequence_Of_Statements =>
6078 -- An exception occurs when the sequence of statements is for
6079 -- an expander generated body that did not do the usual freeze
6080 -- all operation. In this case we usually want to freeze
6081 -- outside this body, not inside it, and we skip past the
6082 -- subprogram body that we are inside.
6084 if In_Exp_Body (Parent_P) then
6086 Subp : constant Node_Id := Parent (Parent_P);
6090 -- Freeze the entity only when it is declared inside the
6091 -- body of the expander generated procedure. This case
6092 -- is recognized by the scope of the entity or its type,
6093 -- which is either the spec for some enclosing body, or
6094 -- (in the case of init_procs, for which there are no
6095 -- separate specs) the current scope.
6097 if Nkind (Subp) = N_Subprogram_Body then
6098 Spec := Corresponding_Spec (Subp);
6100 if (Present (Typ) and then Scope (Typ) = Spec)
6102 (Present (Nam) and then Scope (Nam) = Spec)
6107 and then Scope (Typ) = Current_Scope
6108 and then Defining_Entity (Subp) = Current_Scope
6114 -- An expression function may act as a completion of
6115 -- a function declaration. As such, it can reference
6116 -- entities declared between the two views:
6119 -- function F return ...;
6121 -- function Hidden return ...;
6122 -- function F return ... is (Hidden); -- 2
6124 -- Refering to the example above, freezing the expression
6125 -- of F (2) would place Hidden's freeze node (1) in the
6126 -- wrong place. Avoid explicit freezing and let the usual
6127 -- scenarios do the job - for example, reaching the end
6128 -- of the private declarations.
6130 if Nkind (Original_Node (Subp)) =
6131 N_Expression_Function
6135 -- Freeze outside the body
6138 Parent_P := Parent (Parent_P);
6139 Freeze_Outside := True;
6143 -- Here if normal case where we are in handled statement
6144 -- sequence and want to do the insertion right there.
6150 -- If parent is a body or a spec or a block, then the current node
6151 -- is a statement or declaration and we can insert the freeze node
6154 when N_Block_Statement |
6157 N_Package_Specification |
6160 N_Task_Body => exit;
6162 -- The expander is allowed to define types in any statements list,
6163 -- so any of the following parent nodes also mark a freezing point
6164 -- if the actual node is in a list of statements or declarations.
6166 when N_Abortable_Part |
6167 N_Accept_Alternative |
6169 N_Case_Statement_Alternative |
6170 N_Compilation_Unit_Aux |
6171 N_Conditional_Entry_Call |
6172 N_Delay_Alternative |
6174 N_Entry_Call_Alternative |
6175 N_Exception_Handler |
6176 N_Extended_Return_Statement |
6180 N_Selective_Accept |
6181 N_Triggering_Alternative =>
6183 exit when Is_List_Member (P);
6185 -- Freeze nodes produced by an expression coming from the Actions
6186 -- list of a N_Expression_With_Actions node must remain within the
6187 -- Actions list. Inserting the freeze nodes further up the tree
6188 -- may lead to use before declaration issues in the case of array
6191 when N_Expression_With_Actions =>
6192 if Is_List_Member (P)
6193 and then List_Containing (P) = Actions (Parent_P)
6198 -- Note: N_Loop_Statement is a special case. A type that appears
6199 -- in the source can never be frozen in a loop (this occurs only
6200 -- because of a loop expanded by the expander), so we keep on
6201 -- going. Otherwise we terminate the search. Same is true of any
6202 -- entity which comes from source. (if they have predefined type,
6203 -- that type does not appear to come from source, but the entity
6204 -- should not be frozen here).
6206 when N_Loop_Statement =>
6207 exit when not Comes_From_Source (Etype (N))
6208 and then (No (Nam) or else not Comes_From_Source (Nam));
6210 -- For all other cases, keep looking at parents
6216 -- We fall through the case if we did not yet find the proper
6217 -- place in the free for inserting the freeze node, so climb.
6222 -- If the expression appears in a record or an initialization procedure,
6223 -- the freeze nodes are collected and attached to the current scope, to
6224 -- be inserted and analyzed on exit from the scope, to insure that
6225 -- generated entities appear in the correct scope. If the expression is
6226 -- a default for a discriminant specification, the scope is still void.
6227 -- The expression can also appear in the discriminant part of a private
6228 -- or concurrent type.
6230 -- If the expression appears in a constrained subcomponent of an
6231 -- enclosing record declaration, the freeze nodes must be attached to
6232 -- the outer record type so they can eventually be placed in the
6233 -- enclosing declaration list.
6235 -- The other case requiring this special handling is if we are in a
6236 -- default expression, since in that case we are about to freeze a
6237 -- static type, and the freeze scope needs to be the outer scope, not
6238 -- the scope of the subprogram with the default parameter.
6240 -- For default expressions and other spec expressions in generic units,
6241 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6242 -- placing them at the proper place, after the generic unit.
6244 if (In_Spec_Exp and not Inside_A_Generic)
6245 or else Freeze_Outside
6246 or else (Is_Type (Current_Scope)
6247 and then (not Is_Concurrent_Type (Current_Scope)
6248 or else not Has_Completion (Current_Scope)))
6249 or else Ekind (Current_Scope) = E_Void
6252 N : constant Node_Id := Current_Scope;
6253 Freeze_Nodes : List_Id := No_List;
6254 Pos : Int := Scope_Stack.Last;
6257 if Present (Desig_Typ) then
6258 Freeze_And_Append (Desig_Typ, N, Freeze_Nodes);
6261 if Present (Typ) then
6262 Freeze_And_Append (Typ, N, Freeze_Nodes);
6265 if Present (Nam) then
6266 Freeze_And_Append (Nam, N, Freeze_Nodes);
6269 -- The current scope may be that of a constrained component of
6270 -- an enclosing record declaration, or of a loop of an enclosing
6271 -- quantified expression, which is above the current scope in the
6272 -- scope stack. Indeed in the context of a quantified expression,
6273 -- a scope is created and pushed above the current scope in order
6274 -- to emulate the loop-like behavior of the quantified expression.
6275 -- If the expression is within a top-level pragma, as for a pre-
6276 -- condition on a library-level subprogram, nothing to do.
6278 if not Is_Compilation_Unit (Current_Scope)
6279 and then (Is_Record_Type (Scope (Current_Scope))
6280 or else Nkind (Parent (Current_Scope)) =
6281 N_Quantified_Expression)
6286 if Is_Non_Empty_List (Freeze_Nodes) then
6287 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
6288 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
6291 Append_List (Freeze_Nodes,
6292 Scope_Stack.Table (Pos).Pending_Freeze_Actions);
6300 -- Now we have the right place to do the freezing. First, a special
6301 -- adjustment, if we are in spec-expression analysis mode, these freeze
6302 -- actions must not be thrown away (normally all inserted actions are
6303 -- thrown away in this mode. However, the freeze actions are from static
6304 -- expressions and one of the important reasons we are doing this
6305 -- special analysis is to get these freeze actions. Therefore we turn
6306 -- off the In_Spec_Expression mode to propagate these freeze actions.
6307 -- This also means they get properly analyzed and expanded.
6309 In_Spec_Expression := False;
6311 -- Freeze the designated type of an allocator (RM 13.14(13))
6313 if Present (Desig_Typ) then
6314 Freeze_Before (P, Desig_Typ);
6317 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
6318 -- the enumeration representation clause exception in the loop above.
6320 if Present (Typ) then
6321 Freeze_Before (P, Typ);
6324 -- Freeze name if one is present (RM 13.14(11))
6326 if Present (Nam) then
6327 Freeze_Before (P, Nam);
6330 -- Restore In_Spec_Expression flag
6332 In_Spec_Expression := In_Spec_Exp;
6333 end Freeze_Expression;
6335 -----------------------------
6336 -- Freeze_Fixed_Point_Type --
6337 -----------------------------
6339 -- Certain fixed-point types and subtypes, including implicit base types
6340 -- and declared first subtypes, have not yet set up a range. This is
6341 -- because the range cannot be set until the Small and Size values are
6342 -- known, and these are not known till the type is frozen.
6344 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
6345 -- whose bounds are unanalyzed real literals. This routine will recognize
6346 -- this case, and transform this range node into a properly typed range
6347 -- with properly analyzed and resolved values.
6349 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
6350 Rng : constant Node_Id := Scalar_Range (Typ);
6351 Lo : constant Node_Id := Low_Bound (Rng);
6352 Hi : constant Node_Id := High_Bound (Rng);
6353 Btyp : constant Entity_Id := Base_Type (Typ);
6354 Brng : constant Node_Id := Scalar_Range (Btyp);
6355 BLo : constant Node_Id := Low_Bound (Brng);
6356 BHi : constant Node_Id := High_Bound (Brng);
6357 Small : constant Ureal := Small_Value (Typ);
6364 function Fsize (Lov, Hiv : Ureal) return Nat;
6365 -- Returns size of type with given bounds. Also leaves these
6366 -- bounds set as the current bounds of the Typ.
6372 function Fsize (Lov, Hiv : Ureal) return Nat is
6374 Set_Realval (Lo, Lov);
6375 Set_Realval (Hi, Hiv);
6376 return Minimum_Size (Typ);
6379 -- Start of processing for Freeze_Fixed_Point_Type
6382 -- If Esize of a subtype has not previously been set, set it now
6384 if Unknown_Esize (Typ) then
6385 Atype := Ancestor_Subtype (Typ);
6387 if Present (Atype) then
6388 Set_Esize (Typ, Esize (Atype));
6390 Set_Esize (Typ, Esize (Base_Type (Typ)));
6394 -- Immediate return if the range is already analyzed. This means that
6395 -- the range is already set, and does not need to be computed by this
6398 if Analyzed (Rng) then
6402 -- Immediate return if either of the bounds raises Constraint_Error
6404 if Raises_Constraint_Error (Lo)
6405 or else Raises_Constraint_Error (Hi)
6410 Loval := Realval (Lo);
6411 Hival := Realval (Hi);
6413 -- Ordinary fixed-point case
6415 if Is_Ordinary_Fixed_Point_Type (Typ) then
6417 -- For the ordinary fixed-point case, we are allowed to fudge the
6418 -- end-points up or down by small. Generally we prefer to fudge up,
6419 -- i.e. widen the bounds for non-model numbers so that the end points
6420 -- are included. However there are cases in which this cannot be
6421 -- done, and indeed cases in which we may need to narrow the bounds.
6422 -- The following circuit makes the decision.
6424 -- Note: our terminology here is that Incl_EP means that the bounds
6425 -- are widened by Small if necessary to include the end points, and
6426 -- Excl_EP means that the bounds are narrowed by Small to exclude the
6427 -- end-points if this reduces the size.
6429 -- Note that in the Incl case, all we care about is including the
6430 -- end-points. In the Excl case, we want to narrow the bounds as
6431 -- much as permitted by the RM, to give the smallest possible size.
6434 Loval_Incl_EP : Ureal;
6435 Hival_Incl_EP : Ureal;
6437 Loval_Excl_EP : Ureal;
6438 Hival_Excl_EP : Ureal;
6444 First_Subt : Entity_Id;
6449 -- First step. Base types are required to be symmetrical. Right
6450 -- now, the base type range is a copy of the first subtype range.
6451 -- This will be corrected before we are done, but right away we
6452 -- need to deal with the case where both bounds are non-negative.
6453 -- In this case, we set the low bound to the negative of the high
6454 -- bound, to make sure that the size is computed to include the
6455 -- required sign. Note that we do not need to worry about the
6456 -- case of both bounds negative, because the sign will be dealt
6457 -- with anyway. Furthermore we can't just go making such a bound
6458 -- symmetrical, since in a twos-complement system, there is an
6459 -- extra negative value which could not be accommodated on the
6463 and then not UR_Is_Negative (Loval)
6464 and then Hival > Loval
6467 Set_Realval (Lo, Loval);
6470 -- Compute the fudged bounds. If the number is a model number,
6471 -- then we do nothing to include it, but we are allowed to backoff
6472 -- to the next adjacent model number when we exclude it. If it is
6473 -- not a model number then we straddle the two values with the
6474 -- model numbers on either side.
6476 Model_Num := UR_Trunc (Loval / Small) * Small;
6478 if Loval = Model_Num then
6479 Loval_Incl_EP := Model_Num;
6481 Loval_Incl_EP := Model_Num - Small;
6484 -- The low value excluding the end point is Small greater, but
6485 -- we do not do this exclusion if the low value is positive,
6486 -- since it can't help the size and could actually hurt by
6487 -- crossing the high bound.
6489 if UR_Is_Negative (Loval_Incl_EP) then
6490 Loval_Excl_EP := Loval_Incl_EP + Small;
6492 -- If the value went from negative to zero, then we have the
6493 -- case where Loval_Incl_EP is the model number just below
6494 -- zero, so we want to stick to the negative value for the
6495 -- base type to maintain the condition that the size will
6496 -- include signed values.
6499 and then UR_Is_Zero (Loval_Excl_EP)
6501 Loval_Excl_EP := Loval_Incl_EP;
6505 Loval_Excl_EP := Loval_Incl_EP;
6508 -- Similar processing for upper bound and high value
6510 Model_Num := UR_Trunc (Hival / Small) * Small;
6512 if Hival = Model_Num then
6513 Hival_Incl_EP := Model_Num;
6515 Hival_Incl_EP := Model_Num + Small;
6518 if UR_Is_Positive (Hival_Incl_EP) then
6519 Hival_Excl_EP := Hival_Incl_EP - Small;
6521 Hival_Excl_EP := Hival_Incl_EP;
6524 -- One further adjustment is needed. In the case of subtypes, we
6525 -- cannot go outside the range of the base type, or we get
6526 -- peculiarities, and the base type range is already set. This
6527 -- only applies to the Incl values, since clearly the Excl values
6528 -- are already as restricted as they are allowed to be.
6531 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
6532 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
6535 -- Get size including and excluding end points
6537 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
6538 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
6540 -- No need to exclude end-points if it does not reduce size
6542 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
6543 Loval_Excl_EP := Loval_Incl_EP;
6546 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
6547 Hival_Excl_EP := Hival_Incl_EP;
6550 -- Now we set the actual size to be used. We want to use the
6551 -- bounds fudged up to include the end-points but only if this
6552 -- can be done without violating a specifically given size
6553 -- size clause or causing an unacceptable increase in size.
6555 -- Case of size clause given
6557 if Has_Size_Clause (Typ) then
6559 -- Use the inclusive size only if it is consistent with
6560 -- the explicitly specified size.
6562 if Size_Incl_EP <= RM_Size (Typ) then
6563 Actual_Lo := Loval_Incl_EP;
6564 Actual_Hi := Hival_Incl_EP;
6565 Actual_Size := Size_Incl_EP;
6567 -- If the inclusive size is too large, we try excluding
6568 -- the end-points (will be caught later if does not work).
6571 Actual_Lo := Loval_Excl_EP;
6572 Actual_Hi := Hival_Excl_EP;
6573 Actual_Size := Size_Excl_EP;
6576 -- Case of size clause not given
6579 -- If we have a base type whose corresponding first subtype
6580 -- has an explicit size that is large enough to include our
6581 -- end-points, then do so. There is no point in working hard
6582 -- to get a base type whose size is smaller than the specified
6583 -- size of the first subtype.
6585 First_Subt := First_Subtype (Typ);
6587 if Has_Size_Clause (First_Subt)
6588 and then Size_Incl_EP <= Esize (First_Subt)
6590 Actual_Size := Size_Incl_EP;
6591 Actual_Lo := Loval_Incl_EP;
6592 Actual_Hi := Hival_Incl_EP;
6594 -- If excluding the end-points makes the size smaller and
6595 -- results in a size of 8,16,32,64, then we take the smaller
6596 -- size. For the 64 case, this is compulsory. For the other
6597 -- cases, it seems reasonable. We like to include end points
6598 -- if we can, but not at the expense of moving to the next
6599 -- natural boundary of size.
6601 elsif Size_Incl_EP /= Size_Excl_EP
6602 and then Addressable (Size_Excl_EP)
6604 Actual_Size := Size_Excl_EP;
6605 Actual_Lo := Loval_Excl_EP;
6606 Actual_Hi := Hival_Excl_EP;
6608 -- Otherwise we can definitely include the end points
6611 Actual_Size := Size_Incl_EP;
6612 Actual_Lo := Loval_Incl_EP;
6613 Actual_Hi := Hival_Incl_EP;
6616 -- One pathological case: normally we never fudge a low bound
6617 -- down, since it would seem to increase the size (if it has
6618 -- any effect), but for ranges containing single value, or no
6619 -- values, the high bound can be small too large. Consider:
6621 -- type t is delta 2.0**(-14)
6622 -- range 131072.0 .. 0;
6624 -- That lower bound is *just* outside the range of 32 bits, and
6625 -- does need fudging down in this case. Note that the bounds
6626 -- will always have crossed here, since the high bound will be
6627 -- fudged down if necessary, as in the case of:
6629 -- type t is delta 2.0**(-14)
6630 -- range 131072.0 .. 131072.0;
6632 -- So we detect the situation by looking for crossed bounds,
6633 -- and if the bounds are crossed, and the low bound is greater
6634 -- than zero, we will always back it off by small, since this
6635 -- is completely harmless.
6637 if Actual_Lo > Actual_Hi then
6638 if UR_Is_Positive (Actual_Lo) then
6639 Actual_Lo := Loval_Incl_EP - Small;
6640 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
6642 -- And of course, we need to do exactly the same parallel
6643 -- fudge for flat ranges in the negative region.
6645 elsif UR_Is_Negative (Actual_Hi) then
6646 Actual_Hi := Hival_Incl_EP + Small;
6647 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
6652 Set_Realval (Lo, Actual_Lo);
6653 Set_Realval (Hi, Actual_Hi);
6656 -- For the decimal case, none of this fudging is required, since there
6657 -- are no end-point problems in the decimal case (the end-points are
6658 -- always included).
6661 Actual_Size := Fsize (Loval, Hival);
6664 -- At this stage, the actual size has been calculated and the proper
6665 -- required bounds are stored in the low and high bounds.
6667 if Actual_Size > 64 then
6668 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
6670 ("size required (^) for type& too large, maximum allowed is 64",
6675 -- Check size against explicit given size
6677 if Has_Size_Clause (Typ) then
6678 if Actual_Size > RM_Size (Typ) then
6679 Error_Msg_Uint_1 := RM_Size (Typ);
6680 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
6682 ("size given (^) for type& too small, minimum allowed is ^",
6683 Size_Clause (Typ), Typ);
6686 Actual_Size := UI_To_Int (Esize (Typ));
6689 -- Increase size to next natural boundary if no size clause given
6692 if Actual_Size <= 8 then
6694 elsif Actual_Size <= 16 then
6696 elsif Actual_Size <= 32 then
6702 Init_Esize (Typ, Actual_Size);
6703 Adjust_Esize_For_Alignment (Typ);
6706 -- If we have a base type, then expand the bounds so that they extend to
6707 -- the full width of the allocated size in bits, to avoid junk range
6708 -- checks on intermediate computations.
6710 if Base_Type (Typ) = Typ then
6711 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
6712 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
6715 -- Final step is to reanalyze the bounds using the proper type
6716 -- and set the Corresponding_Integer_Value fields of the literals.
6718 Set_Etype (Lo, Empty);
6719 Set_Analyzed (Lo, False);
6722 -- Resolve with universal fixed if the base type, and the base type if
6723 -- it is a subtype. Note we can't resolve the base type with itself,
6724 -- that would be a reference before definition.
6727 Resolve (Lo, Universal_Fixed);
6732 -- Set corresponding integer value for bound
6734 Set_Corresponding_Integer_Value
6735 (Lo, UR_To_Uint (Realval (Lo) / Small));
6737 -- Similar processing for high bound
6739 Set_Etype (Hi, Empty);
6740 Set_Analyzed (Hi, False);
6744 Resolve (Hi, Universal_Fixed);
6749 Set_Corresponding_Integer_Value
6750 (Hi, UR_To_Uint (Realval (Hi) / Small));
6752 -- Set type of range to correspond to bounds
6754 Set_Etype (Rng, Etype (Lo));
6756 -- Set Esize to calculated size if not set already
6758 if Unknown_Esize (Typ) then
6759 Init_Esize (Typ, Actual_Size);
6762 -- Set RM_Size if not already set. If already set, check value
6765 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
6768 if RM_Size (Typ) /= Uint_0 then
6769 if RM_Size (Typ) < Minsiz then
6770 Error_Msg_Uint_1 := RM_Size (Typ);
6771 Error_Msg_Uint_2 := Minsiz;
6773 ("size given (^) for type& too small, minimum allowed is ^",
6774 Size_Clause (Typ), Typ);
6778 Set_RM_Size (Typ, Minsiz);
6781 end Freeze_Fixed_Point_Type;
6787 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
6791 Set_Has_Delayed_Freeze (T);
6792 L := Freeze_Entity (T, N);
6794 if Is_Non_Empty_List (L) then
6795 Insert_Actions (N, L);
6799 --------------------------
6800 -- Freeze_Static_Object --
6801 --------------------------
6803 procedure Freeze_Static_Object (E : Entity_Id) is
6805 Cannot_Be_Static : exception;
6806 -- Exception raised if the type of a static object cannot be made
6807 -- static. This happens if the type depends on non-global objects.
6809 procedure Ensure_Expression_Is_SA (N : Node_Id);
6810 -- Called to ensure that an expression used as part of a type definition
6811 -- is statically allocatable, which means that the expression type is
6812 -- statically allocatable, and the expression is either static, or a
6813 -- reference to a library level constant.
6815 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
6816 -- Called to mark a type as static, checking that it is possible
6817 -- to set the type as static. If it is not possible, then the
6818 -- exception Cannot_Be_Static is raised.
6820 -----------------------------
6821 -- Ensure_Expression_Is_SA --
6822 -----------------------------
6824 procedure Ensure_Expression_Is_SA (N : Node_Id) is
6828 Ensure_Type_Is_SA (Etype (N));
6830 if Is_OK_Static_Expression (N) then
6833 elsif Nkind (N) = N_Identifier then
6837 and then Ekind (Ent) = E_Constant
6838 and then Is_Library_Level_Entity (Ent)
6844 raise Cannot_Be_Static;
6845 end Ensure_Expression_Is_SA;
6847 -----------------------
6848 -- Ensure_Type_Is_SA --
6849 -----------------------
6851 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
6856 -- If type is library level, we are all set
6858 if Is_Library_Level_Entity (Typ) then
6862 -- We are also OK if the type already marked as statically allocated,
6863 -- which means we processed it before.
6865 if Is_Statically_Allocated (Typ) then
6869 -- Mark type as statically allocated
6871 Set_Is_Statically_Allocated (Typ);
6873 -- Check that it is safe to statically allocate this type
6875 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
6876 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
6877 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
6879 elsif Is_Array_Type (Typ) then
6880 N := First_Index (Typ);
6881 while Present (N) loop
6882 Ensure_Type_Is_SA (Etype (N));
6886 Ensure_Type_Is_SA (Component_Type (Typ));
6888 elsif Is_Access_Type (Typ) then
6889 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
6893 T : constant Entity_Id := Etype (Designated_Type (Typ));
6896 if T /= Standard_Void_Type then
6897 Ensure_Type_Is_SA (T);
6900 F := First_Formal (Designated_Type (Typ));
6901 while Present (F) loop
6902 Ensure_Type_Is_SA (Etype (F));
6908 Ensure_Type_Is_SA (Designated_Type (Typ));
6911 elsif Is_Record_Type (Typ) then
6912 C := First_Entity (Typ);
6913 while Present (C) loop
6914 if Ekind (C) = E_Discriminant
6915 or else Ekind (C) = E_Component
6917 Ensure_Type_Is_SA (Etype (C));
6919 elsif Is_Type (C) then
6920 Ensure_Type_Is_SA (C);
6926 elsif Ekind (Typ) = E_Subprogram_Type then
6927 Ensure_Type_Is_SA (Etype (Typ));
6929 C := First_Formal (Typ);
6930 while Present (C) loop
6931 Ensure_Type_Is_SA (Etype (C));
6936 raise Cannot_Be_Static;
6938 end Ensure_Type_Is_SA;
6940 -- Start of processing for Freeze_Static_Object
6943 Ensure_Type_Is_SA (Etype (E));
6946 when Cannot_Be_Static =>
6948 -- If the object that cannot be static is imported or exported, then
6949 -- issue an error message saying that this object cannot be imported
6950 -- or exported. If it has an address clause it is an overlay in the
6951 -- current partition and the static requirement is not relevant.
6952 -- Do not issue any error message when ignoring rep clauses.
6954 if Ignore_Rep_Clauses then
6957 elsif Is_Imported (E) then
6958 if No (Address_Clause (E)) then
6960 ("& cannot be imported (local type is not constant)", E);
6963 -- Otherwise must be exported, something is wrong if compiler
6964 -- is marking something as statically allocated which cannot be).
6966 else pragma Assert (Is_Exported (E));
6968 ("& cannot be exported (local type is not constant)", E);
6970 end Freeze_Static_Object;
6972 -----------------------
6973 -- Freeze_Subprogram --
6974 -----------------------
6976 procedure Freeze_Subprogram (E : Entity_Id) is
6981 -- Subprogram may not have an address clause unless it is imported
6983 if Present (Address_Clause (E)) then
6984 if not Is_Imported (E) then
6986 ("address clause can only be given " &
6987 "for imported subprogram",
6988 Name (Address_Clause (E)));
6992 -- Reset the Pure indication on an imported subprogram unless an
6993 -- explicit Pure_Function pragma was present or the subprogram is an
6994 -- intrinsic. We do this because otherwise it is an insidious error
6995 -- to call a non-pure function from pure unit and have calls
6996 -- mysteriously optimized away. What happens here is that the Import
6997 -- can bypass the normal check to ensure that pure units call only pure
7000 -- The reason for the intrinsic exception is that in general, intrinsic
7001 -- functions (such as shifts) are pure anyway. The only exceptions are
7002 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7003 -- in any case, so no problem arises.
7006 and then Is_Pure (E)
7007 and then not Has_Pragma_Pure_Function (E)
7008 and then not Is_Intrinsic_Subprogram (E)
7010 Set_Is_Pure (E, False);
7013 -- For non-foreign convention subprograms, this is where we create
7014 -- the extra formals (for accessibility level and constrained bit
7015 -- information). We delay this till the freeze point precisely so
7016 -- that we know the convention.
7018 if not Has_Foreign_Convention (E) then
7019 Create_Extra_Formals (E);
7022 -- If this is convention Ada and a Valued_Procedure, that's odd
7024 if Ekind (E) = E_Procedure
7025 and then Is_Valued_Procedure (E)
7026 and then Convention (E) = Convention_Ada
7027 and then Warn_On_Export_Import
7030 ("??Valued_Procedure has no effect for convention Ada", E);
7031 Set_Is_Valued_Procedure (E, False);
7034 -- Case of foreign convention
7039 -- For foreign conventions, warn about return of an
7040 -- unconstrained array.
7042 -- Note: we *do* allow a return by descriptor for the VMS case,
7043 -- though here there is probably more to be done ???
7045 if Ekind (E) = E_Function then
7046 Retype := Underlying_Type (Etype (E));
7048 -- If no return type, probably some other error, e.g. a
7049 -- missing full declaration, so ignore.
7054 -- If the return type is generic, we have emitted a warning
7055 -- earlier on, and there is nothing else to check here. Specific
7056 -- instantiations may lead to erroneous behavior.
7058 elsif Is_Generic_Type (Etype (E)) then
7061 -- Display warning if returning unconstrained array
7063 elsif Is_Array_Type (Retype)
7064 and then not Is_Constrained (Retype)
7066 -- Exclude cases where descriptor mechanism is set, since the
7067 -- VMS descriptor mechanisms allow such unconstrained returns.
7069 and then Mechanism (E) not in Descriptor_Codes
7071 -- Check appropriate warning is enabled (should we check for
7072 -- Warnings (Off) on specific entities here, probably so???)
7074 and then Warn_On_Export_Import
7076 -- Exclude the VM case, since return of unconstrained arrays
7077 -- is properly handled in both the JVM and .NET cases.
7079 and then VM_Target = No_VM
7082 ("?x?foreign convention function& should not return " &
7083 "unconstrained array", E);
7088 -- If any of the formals for an exported foreign convention
7089 -- subprogram have defaults, then emit an appropriate warning since
7090 -- this is odd (default cannot be used from non-Ada code)
7092 if Is_Exported (E) then
7093 F := First_Formal (E);
7094 while Present (F) loop
7095 if Warn_On_Export_Import
7096 and then Present (Default_Value (F))
7099 ("?x?parameter cannot be defaulted in non-Ada call",
7108 -- For VMS, descriptor mechanisms for parameters are allowed only for
7109 -- imported/exported subprograms. Moreover, the NCA descriptor is not
7110 -- allowed for parameters of exported subprograms.
7112 if OpenVMS_On_Target then
7113 if Is_Exported (E) then
7114 F := First_Formal (E);
7115 while Present (F) loop
7116 if Mechanism (F) = By_Descriptor_NCA then
7118 ("'N'C'A' descriptor for parameter not permitted", F);
7120 ("\can only be used for imported subprogram", F);
7126 elsif not Is_Imported (E) then
7127 F := First_Formal (E);
7128 while Present (F) loop
7129 if Mechanism (F) in Descriptor_Codes then
7131 ("descriptor mechanism for parameter not permitted", F);
7133 ("\can only be used for imported/exported subprogram", F);
7141 -- Pragma Inline_Always is disallowed for dispatching subprograms
7142 -- because the address of such subprograms is saved in the dispatch
7143 -- table to support dispatching calls, and dispatching calls cannot
7144 -- be inlined. This is consistent with the restriction against using
7145 -- 'Access or 'Address on an Inline_Always subprogram.
7147 if Is_Dispatching_Operation (E)
7148 and then Has_Pragma_Inline_Always (E)
7151 ("pragma Inline_Always not allowed for dispatching subprograms", E);
7154 -- Because of the implicit representation of inherited predefined
7155 -- operators in the front-end, the overriding status of the operation
7156 -- may be affected when a full view of a type is analyzed, and this is
7157 -- not captured by the analysis of the corresponding type declaration.
7158 -- Therefore the correctness of a not-overriding indicator must be
7159 -- rechecked when the subprogram is frozen.
7161 if Nkind (E) = N_Defining_Operator_Symbol
7162 and then not Error_Posted (Parent (E))
7164 Check_Overriding_Indicator (E, Empty, Is_Primitive (E));
7166 end Freeze_Subprogram;
7168 ----------------------
7169 -- Is_Fully_Defined --
7170 ----------------------
7172 function Is_Fully_Defined (T : Entity_Id) return Boolean is
7174 if Ekind (T) = E_Class_Wide_Type then
7175 return Is_Fully_Defined (Etype (T));
7177 elsif Is_Array_Type (T) then
7178 return Is_Fully_Defined (Component_Type (T));
7180 elsif Is_Record_Type (T)
7181 and not Is_Private_Type (T)
7183 -- Verify that the record type has no components with private types
7184 -- without completion.
7190 Comp := First_Component (T);
7191 while Present (Comp) loop
7192 if not Is_Fully_Defined (Etype (Comp)) then
7196 Next_Component (Comp);
7201 -- For the designated type of an access to subprogram, all types in
7202 -- the profile must be fully defined.
7204 elsif Ekind (T) = E_Subprogram_Type then
7209 F := First_Formal (T);
7210 while Present (F) loop
7211 if not Is_Fully_Defined (Etype (F)) then
7218 return Is_Fully_Defined (Etype (T));
7222 return not Is_Private_Type (T)
7223 or else Present (Full_View (Base_Type (T)));
7225 end Is_Fully_Defined;
7227 ---------------------------------
7228 -- Process_Default_Expressions --
7229 ---------------------------------
7231 procedure Process_Default_Expressions
7233 After : in out Node_Id)
7235 Loc : constant Source_Ptr := Sloc (E);
7242 Set_Default_Expressions_Processed (E);
7244 -- A subprogram instance and its associated anonymous subprogram share
7245 -- their signature. The default expression functions are defined in the
7246 -- wrapper packages for the anonymous subprogram, and should not be
7247 -- generated again for the instance.
7249 if Is_Generic_Instance (E)
7250 and then Present (Alias (E))
7251 and then Default_Expressions_Processed (Alias (E))
7256 Formal := First_Formal (E);
7257 while Present (Formal) loop
7258 if Present (Default_Value (Formal)) then
7260 -- We work with a copy of the default expression because we
7261 -- do not want to disturb the original, since this would mess
7262 -- up the conformance checking.
7264 Dcopy := New_Copy_Tree (Default_Value (Formal));
7266 -- The analysis of the expression may generate insert actions,
7267 -- which of course must not be executed. We wrap those actions
7268 -- in a procedure that is not called, and later on eliminated.
7269 -- The following cases have no side-effects, and are analyzed
7272 if Nkind (Dcopy) = N_Identifier
7273 or else Nkind_In (Dcopy, N_Expanded_Name,
7275 N_Character_Literal,
7277 or else (Nkind (Dcopy) = N_Real_Literal
7278 and then not Vax_Float (Etype (Dcopy)))
7279 or else (Nkind (Dcopy) = N_Attribute_Reference
7280 and then Attribute_Name (Dcopy) = Name_Null_Parameter)
7281 or else Known_Null (Dcopy)
7283 -- If there is no default function, we must still do a full
7284 -- analyze call on the default value, to ensure that all error
7285 -- checks are performed, e.g. those associated with static
7286 -- evaluation. Note: this branch will always be taken if the
7287 -- analyzer is turned off (but we still need the error checks).
7289 -- Note: the setting of parent here is to meet the requirement
7290 -- that we can only analyze the expression while attached to
7291 -- the tree. Really the requirement is that the parent chain
7292 -- be set, we don't actually need to be in the tree.
7294 Set_Parent (Dcopy, Declaration_Node (Formal));
7297 -- Default expressions are resolved with their own type if the
7298 -- context is generic, to avoid anomalies with private types.
7300 if Ekind (Scope (E)) = E_Generic_Package then
7303 Resolve (Dcopy, Etype (Formal));
7306 -- If that resolved expression will raise constraint error,
7307 -- then flag the default value as raising constraint error.
7308 -- This allows a proper error message on the calls.
7310 if Raises_Constraint_Error (Dcopy) then
7311 Set_Raises_Constraint_Error (Default_Value (Formal));
7314 -- If the default is a parameterless call, we use the name of
7315 -- the called function directly, and there is no body to build.
7317 elsif Nkind (Dcopy) = N_Function_Call
7318 and then No (Parameter_Associations (Dcopy))
7322 -- Else construct and analyze the body of a wrapper procedure
7323 -- that contains an object declaration to hold the expression.
7324 -- Given that this is done only to complete the analysis, it
7325 -- simpler to build a procedure than a function which might
7326 -- involve secondary stack expansion.
7329 Dnam := Make_Temporary (Loc, 'D');
7332 Make_Subprogram_Body (Loc,
7334 Make_Procedure_Specification (Loc,
7335 Defining_Unit_Name => Dnam),
7337 Declarations => New_List (
7338 Make_Object_Declaration (Loc,
7339 Defining_Identifier => Make_Temporary (Loc, 'T'),
7340 Object_Definition =>
7341 New_Occurrence_Of (Etype (Formal), Loc),
7342 Expression => New_Copy_Tree (Dcopy))),
7344 Handled_Statement_Sequence =>
7345 Make_Handled_Sequence_Of_Statements (Loc,
7346 Statements => Empty_List));
7348 Set_Scope (Dnam, Scope (E));
7349 Set_Assignment_OK (First (Declarations (Dbody)));
7350 Set_Is_Eliminated (Dnam);
7351 Insert_After (After, Dbody);
7357 Next_Formal (Formal);
7359 end Process_Default_Expressions;
7361 ----------------------------------------
7362 -- Set_Component_Alignment_If_Not_Set --
7363 ----------------------------------------
7365 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
7367 -- Ignore if not base type, subtypes don't need anything
7369 if Typ /= Base_Type (Typ) then
7373 -- Do not override existing representation
7375 if Is_Packed (Typ) then
7378 elsif Has_Specified_Layout (Typ) then
7381 elsif Component_Alignment (Typ) /= Calign_Default then
7385 Set_Component_Alignment
7386 (Typ, Scope_Stack.Table
7387 (Scope_Stack.Last).Component_Alignment_Default);
7389 end Set_Component_Alignment_If_Not_Set;
7391 --------------------------
7392 -- Set_SSO_From_Default --
7393 --------------------------
7395 procedure Set_SSO_From_Default (T : Entity_Id) is
7397 if (Is_Record_Type (T) or else Is_Array_Type (T))
7398 and then Is_Base_Type (T)
7400 if (Bytes_Big_Endian and then SSO_Set_Low_By_Default (T))
7402 ((not Bytes_Big_Endian) and then SSO_Set_High_By_Default (T))
7404 -- If flags cause reverse storage order, then set the result. Note
7405 -- that we would have ignored the pragma setting the non default
7406 -- storage order in any case, hence the assertion at this point.
7408 pragma Assert (Support_Nondefault_SSO_On_Target);
7409 Set_Reverse_Storage_Order (T);
7412 end Set_SSO_From_Default;
7418 procedure Undelay_Type (T : Entity_Id) is
7420 Set_Has_Delayed_Freeze (T, False);
7421 Set_Freeze_Node (T, Empty);
7423 -- Since we don't want T to have a Freeze_Node, we don't want its
7424 -- Full_View or Corresponding_Record_Type to have one either.
7426 -- ??? Fundamentally, this whole handling is unpleasant. What we really
7427 -- want is to be sure that for an Itype that's part of record R and is a
7428 -- subtype of type T, that it's frozen after the later of the freeze
7429 -- points of R and T. We have no way of doing that directly, so what we
7430 -- do is force most such Itypes to be frozen as part of freezing R via
7431 -- this procedure and only delay the ones that need to be delayed
7432 -- (mostly the designated types of access types that are defined as part
7435 if Is_Private_Type (T)
7436 and then Present (Full_View (T))
7437 and then Is_Itype (Full_View (T))
7438 and then Is_Record_Type (Scope (Full_View (T)))
7440 Undelay_Type (Full_View (T));
7443 if Is_Concurrent_Type (T)
7444 and then Present (Corresponding_Record_Type (T))
7445 and then Is_Itype (Corresponding_Record_Type (T))
7446 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
7448 Undelay_Type (Corresponding_Record_Type (T));
7456 procedure Warn_Overlay
7461 Ent : constant Entity_Id := Entity (Nam);
7462 -- The object to which the address clause applies
7465 Old : Entity_Id := Empty;
7469 -- No warning if address clause overlay warnings are off
7471 if not Address_Clause_Overlay_Warnings then
7475 -- No warning if there is an explicit initialization
7477 Init := Original_Node (Expression (Declaration_Node (Ent)));
7479 if Present (Init) and then Comes_From_Source (Init) then
7483 -- We only give the warning for non-imported entities of a type for
7484 -- which a non-null base init proc is defined, or for objects of access
7485 -- types with implicit null initialization, or when Normalize_Scalars
7486 -- applies and the type is scalar or a string type (the latter being
7487 -- tested for because predefined String types are initialized by inline
7488 -- code rather than by an init_proc). Note that we do not give the
7489 -- warning for Initialize_Scalars, since we suppressed initialization
7490 -- in this case. Also, do not warn if Suppress_Initialization is set.
7493 and then not Is_Imported (Ent)
7494 and then not Initialization_Suppressed (Typ)
7495 and then (Has_Non_Null_Base_Init_Proc (Typ)
7496 or else Is_Access_Type (Typ)
7497 or else (Normalize_Scalars
7498 and then (Is_Scalar_Type (Typ)
7499 or else Is_String_Type (Typ))))
7501 if Nkind (Expr) = N_Attribute_Reference
7502 and then Is_Entity_Name (Prefix (Expr))
7504 Old := Entity (Prefix (Expr));
7506 elsif Is_Entity_Name (Expr)
7507 and then Ekind (Entity (Expr)) = E_Constant
7509 Decl := Declaration_Node (Entity (Expr));
7511 if Nkind (Decl) = N_Object_Declaration
7512 and then Present (Expression (Decl))
7513 and then Nkind (Expression (Decl)) = N_Attribute_Reference
7514 and then Is_Entity_Name (Prefix (Expression (Decl)))
7516 Old := Entity (Prefix (Expression (Decl)));
7518 elsif Nkind (Expr) = N_Function_Call then
7522 -- A function call (most likely to To_Address) is probably not an
7523 -- overlay, so skip warning. Ditto if the function call was inlined
7524 -- and transformed into an entity.
7526 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
7530 Decl := Next (Parent (Expr));
7532 -- If a pragma Import follows, we assume that it is for the current
7533 -- target of the address clause, and skip the warning.
7536 and then Nkind (Decl) = N_Pragma
7537 and then Pragma_Name (Decl) = Name_Import
7542 if Present (Old) then
7543 Error_Msg_Node_2 := Old;
7545 ("default initialization of & may modify &??",
7549 ("default initialization of & may modify overlaid storage??",
7553 -- Add friendly warning if initialization comes from a packed array
7556 if Is_Record_Type (Typ) then
7561 Comp := First_Component (Typ);
7562 while Present (Comp) loop
7563 if Nkind (Parent (Comp)) = N_Component_Declaration
7564 and then Present (Expression (Parent (Comp)))
7567 elsif Is_Array_Type (Etype (Comp))
7568 and then Present (Packed_Array_Impl_Type (Etype (Comp)))
7571 ("\packed array component& " &
7572 "will be initialized to zero??",
7576 Next_Component (Comp);
7583 ("\use pragma Import for & to " &
7584 "suppress initialization (RM B.1(24))??",