1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Ch3; use Exp_Ch3;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Pakd; use Exp_Pakd;
36 with Exp_Util; use Exp_Util;
37 with Exp_Tss; use Exp_Tss;
38 with Layout; use Layout;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Cat; use Sem_Cat;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch7; use Sem_Ch7;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Ch9; use Sem_Ch9;
54 with Sem_Ch13; use Sem_Ch13;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Mech; use Sem_Mech;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Util; use Sem_Util;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Ttypes; use Ttypes;
66 with Uintp; use Uintp;
67 with Urealp; use Urealp;
69 package body Freeze is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
76 -- Typ is a type that is being frozen. If no size clause is given,
77 -- but a default Esize has been computed, then this default Esize is
78 -- adjusted up if necessary to be consistent with a given alignment,
79 -- but never to a value greater than Long_Long_Integer'Size. This
80 -- is used for all discrete types and for fixed-point types.
82 procedure Build_And_Analyze_Renamed_Body
85 After : in out Node_Id);
86 -- Build body for a renaming declaration, insert in tree and analyze
88 procedure Check_Address_Clause (E : Entity_Id);
89 -- Apply legality checks to address clauses for object declarations,
90 -- at the point the object is frozen. Also ensure any initialization is
91 -- performed only after the object has been frozen.
93 procedure Check_Component_Storage_Order
94 (Encl_Type : Entity_Id;
97 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
98 -- clause, verify that the component type has an explicit and compatible
99 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
100 -- entity of the component under consideration. For an Encl_Type that
101 -- does not have a Scalar_Storage_Order attribute definition clause,
102 -- verify that the component also does not have such a clause.
103 -- ADC is the attribute definition clause if present (or Empty).
105 procedure Check_Strict_Alignment (E : Entity_Id);
106 -- E is a base type. If E is tagged or has a component that is aliased
107 -- or tagged or contains something this is aliased or tagged, set
110 procedure Check_Unsigned_Type (E : Entity_Id);
111 pragma Inline (Check_Unsigned_Type);
112 -- If E is a fixed-point or discrete type, then all the necessary work
113 -- to freeze it is completed except for possible setting of the flag
114 -- Is_Unsigned_Type, which is done by this procedure. The call has no
115 -- effect if the entity E is not a discrete or fixed-point type.
117 procedure Freeze_And_Append
120 Result : in out List_Id);
121 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
122 -- nodes to Result, modifying Result from No_List if necessary. N has
123 -- the same usage as in Freeze_Entity.
125 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
126 -- Freeze enumeration type. The Esize field is set as processing
127 -- proceeds (i.e. set by default when the type is declared and then
128 -- adjusted by rep clauses. What this procedure does is to make sure
129 -- that if a foreign convention is specified, and no specific size
130 -- is given, then the size must be at least Integer'Size.
132 procedure Freeze_Static_Object (E : Entity_Id);
133 -- If an object is frozen which has Is_Statically_Allocated set, then
134 -- all referenced types must also be marked with this flag. This routine
135 -- is in charge of meeting this requirement for the object entity E.
137 procedure Freeze_Subprogram (E : Entity_Id);
138 -- Perform freezing actions for a subprogram (create extra formals,
139 -- and set proper default mechanism values). Note that this routine
140 -- is not called for internal subprograms, for which neither of these
141 -- actions is needed (or desirable, we do not want for example to have
142 -- these extra formals present in initialization procedures, where they
143 -- would serve no purpose). In this call E is either a subprogram or
144 -- a subprogram type (i.e. an access to a subprogram).
146 function Is_Fully_Defined (T : Entity_Id) return Boolean;
147 -- True if T is not private and has no private components, or has a full
148 -- view. Used to determine whether the designated type of an access type
149 -- should be frozen when the access type is frozen. This is done when an
150 -- allocator is frozen, or an expression that may involve attributes of
151 -- the designated type. Otherwise freezing the access type does not freeze
152 -- the designated type.
154 procedure Process_Default_Expressions
156 After : in out Node_Id);
157 -- This procedure is called for each subprogram to complete processing of
158 -- default expressions at the point where all types are known to be frozen.
159 -- The expressions must be analyzed in full, to make sure that all error
160 -- processing is done (they have only been pre-analyzed). If the expression
161 -- is not an entity or literal, its analysis may generate code which must
162 -- not be executed. In that case we build a function body to hold that
163 -- code. This wrapper function serves no other purpose (it used to be
164 -- called to evaluate the default, but now the default is inlined at each
167 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
168 -- Typ is a record or array type that is being frozen. This routine sets
169 -- the default component alignment from the scope stack values if the
170 -- alignment is otherwise not specified.
172 procedure Check_Debug_Info_Needed (T : Entity_Id);
173 -- As each entity is frozen, this routine is called to deal with the
174 -- setting of Debug_Info_Needed for the entity. This flag is set if
175 -- the entity comes from source, or if we are in Debug_Generated_Code
176 -- mode or if the -gnatdV debug flag is set. However, it never sets
177 -- the flag if Debug_Info_Off is set. This procedure also ensures that
178 -- subsidiary entities have the flag set as required.
180 procedure Undelay_Type (T : Entity_Id);
181 -- T is a type of a component that we know to be an Itype. We don't want
182 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
183 -- Full_View or Corresponding_Record_Type.
185 procedure Warn_Overlay
189 -- Expr is the expression for an address clause for entity Nam whose type
190 -- is Typ. If Typ has a default initialization, and there is no explicit
191 -- initialization in the source declaration, check whether the address
192 -- clause might cause overlaying of an entity, and emit a warning on the
193 -- side effect that the initialization will cause.
195 -------------------------------
196 -- Adjust_Esize_For_Alignment --
197 -------------------------------
199 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
203 if Known_Esize (Typ) and then Known_Alignment (Typ) then
204 Align := Alignment_In_Bits (Typ);
206 if Align > Esize (Typ)
207 and then Align <= Standard_Long_Long_Integer_Size
209 Set_Esize (Typ, Align);
212 end Adjust_Esize_For_Alignment;
214 ------------------------------------
215 -- Build_And_Analyze_Renamed_Body --
216 ------------------------------------
218 procedure Build_And_Analyze_Renamed_Body
221 After : in out Node_Id)
223 Body_Decl : constant Node_Id := Unit_Declaration_Node (New_S);
224 Ent : constant Entity_Id := Defining_Entity (Decl);
226 Renamed_Subp : Entity_Id;
229 -- If the renamed subprogram is intrinsic, there is no need for a
230 -- wrapper body: we set the alias that will be called and expanded which
231 -- completes the declaration. This transformation is only legal if the
232 -- renamed entity has already been elaborated.
234 -- Note that it is legal for a renaming_as_body to rename an intrinsic
235 -- subprogram, as long as the renaming occurs before the new entity
236 -- is frozen. See RM 8.5.4 (5).
238 if Nkind (Body_Decl) = N_Subprogram_Renaming_Declaration
239 and then Is_Entity_Name (Name (Body_Decl))
241 Renamed_Subp := Entity (Name (Body_Decl));
243 Renamed_Subp := Empty;
246 if Present (Renamed_Subp)
247 and then Is_Intrinsic_Subprogram (Renamed_Subp)
249 (not In_Same_Source_Unit (Renamed_Subp, Ent)
250 or else Sloc (Renamed_Subp) < Sloc (Ent))
252 -- We can make the renaming entity intrinsic if the renamed function
253 -- has an interface name, or if it is one of the shift/rotate
254 -- operations known to the compiler.
257 (Present (Interface_Name (Renamed_Subp))
258 or else Nam_In (Chars (Renamed_Subp), Name_Rotate_Left,
262 Name_Shift_Right_Arithmetic))
264 Set_Interface_Name (Ent, Interface_Name (Renamed_Subp));
266 if Present (Alias (Renamed_Subp)) then
267 Set_Alias (Ent, Alias (Renamed_Subp));
269 Set_Alias (Ent, Renamed_Subp);
272 Set_Is_Intrinsic_Subprogram (Ent);
273 Set_Has_Completion (Ent);
276 Body_Node := Build_Renamed_Body (Decl, New_S);
277 Insert_After (After, Body_Node);
278 Mark_Rewrite_Insertion (Body_Node);
282 end Build_And_Analyze_Renamed_Body;
284 ------------------------
285 -- Build_Renamed_Body --
286 ------------------------
288 function Build_Renamed_Body
290 New_S : Entity_Id) return Node_Id
292 Loc : constant Source_Ptr := Sloc (New_S);
293 -- We use for the source location of the renamed body, the location of
294 -- the spec entity. It might seem more natural to use the location of
295 -- the renaming declaration itself, but that would be wrong, since then
296 -- the body we create would look as though it was created far too late,
297 -- and this could cause problems with elaboration order analysis,
298 -- particularly in connection with instantiations.
300 N : constant Node_Id := Unit_Declaration_Node (New_S);
301 Nam : constant Node_Id := Name (N);
303 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
304 Actuals : List_Id := No_List;
309 O_Formal : Entity_Id;
310 Param_Spec : Node_Id;
312 Pref : Node_Id := Empty;
313 -- If the renamed entity is a primitive operation given in prefix form,
314 -- the prefix is the target object and it has to be added as the first
315 -- actual in the generated call.
318 -- Determine the entity being renamed, which is the target of the call
319 -- statement. If the name is an explicit dereference, this is a renaming
320 -- of a subprogram type rather than a subprogram. The name itself is
323 if Nkind (Nam) = N_Selected_Component then
324 Old_S := Entity (Selector_Name (Nam));
326 elsif Nkind (Nam) = N_Explicit_Dereference then
327 Old_S := Etype (Nam);
329 elsif Nkind (Nam) = N_Indexed_Component then
330 if Is_Entity_Name (Prefix (Nam)) then
331 Old_S := Entity (Prefix (Nam));
333 Old_S := Entity (Selector_Name (Prefix (Nam)));
336 elsif Nkind (Nam) = N_Character_Literal then
337 Old_S := Etype (New_S);
340 Old_S := Entity (Nam);
343 if Is_Entity_Name (Nam) then
345 -- If the renamed entity is a predefined operator, retain full name
346 -- to ensure its visibility.
348 if Ekind (Old_S) = E_Operator
349 and then Nkind (Nam) = N_Expanded_Name
351 Call_Name := New_Copy (Name (N));
353 Call_Name := New_Reference_To (Old_S, Loc);
357 if Nkind (Nam) = N_Selected_Component
358 and then Present (First_Formal (Old_S))
360 (Is_Controlling_Formal (First_Formal (Old_S))
361 or else Is_Class_Wide_Type (Etype (First_Formal (Old_S))))
364 -- Retrieve the target object, to be added as a first actual
367 Call_Name := New_Occurrence_Of (Old_S, Loc);
368 Pref := Prefix (Nam);
371 Call_Name := New_Copy (Name (N));
374 -- Original name may have been overloaded, but is fully resolved now
376 Set_Is_Overloaded (Call_Name, False);
379 -- For simple renamings, subsequent calls can be expanded directly as
380 -- calls to the renamed entity. The body must be generated in any case
381 -- for calls that may appear elsewhere. This is not done in the case
382 -- where the subprogram is an instantiation because the actual proper
383 -- body has not been built yet.
385 if Ekind_In (Old_S, E_Function, E_Procedure)
386 and then Nkind (Decl) = N_Subprogram_Declaration
387 and then not Is_Generic_Instance (Old_S)
389 Set_Body_To_Inline (Decl, Old_S);
392 -- The body generated for this renaming is an internal artifact, and
393 -- does not constitute a freeze point for the called entity.
395 Set_Must_Not_Freeze (Call_Name);
397 Formal := First_Formal (Defining_Entity (Decl));
399 if Present (Pref) then
401 Pref_Type : constant Entity_Id := Etype (Pref);
402 Form_Type : constant Entity_Id := Etype (First_Formal (Old_S));
405 -- The controlling formal may be an access parameter, or the
406 -- actual may be an access value, so adjust accordingly.
408 if Is_Access_Type (Pref_Type)
409 and then not Is_Access_Type (Form_Type)
412 (Make_Explicit_Dereference (Loc, Relocate_Node (Pref)));
414 elsif Is_Access_Type (Form_Type)
415 and then not Is_Access_Type (Pref)
418 (Make_Attribute_Reference (Loc,
419 Attribute_Name => Name_Access,
420 Prefix => Relocate_Node (Pref)));
422 Actuals := New_List (Pref);
426 elsif Present (Formal) then
433 if Present (Formal) then
434 while Present (Formal) loop
435 Append (New_Reference_To (Formal, Loc), Actuals);
436 Next_Formal (Formal);
440 -- If the renamed entity is an entry, inherit its profile. For other
441 -- renamings as bodies, both profiles must be subtype conformant, so it
442 -- is not necessary to replace the profile given in the declaration.
443 -- However, default values that are aggregates are rewritten when
444 -- partially analyzed, so we recover the original aggregate to insure
445 -- that subsequent conformity checking works. Similarly, if the default
446 -- expression was constant-folded, recover the original expression.
448 Formal := First_Formal (Defining_Entity (Decl));
450 if Present (Formal) then
451 O_Formal := First_Formal (Old_S);
452 Param_Spec := First (Parameter_Specifications (Spec));
453 while Present (Formal) loop
454 if Is_Entry (Old_S) then
455 if Nkind (Parameter_Type (Param_Spec)) /=
458 Set_Etype (Formal, Etype (O_Formal));
459 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
462 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
463 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
464 Nkind (Default_Value (O_Formal))
466 Set_Expression (Param_Spec,
467 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
470 Next_Formal (Formal);
471 Next_Formal (O_Formal);
476 -- If the renamed entity is a function, the generated body contains a
477 -- return statement. Otherwise, build a procedure call. If the entity is
478 -- an entry, subsequent analysis of the call will transform it into the
479 -- proper entry or protected operation call. If the renamed entity is
480 -- a character literal, return it directly.
482 if Ekind (Old_S) = E_Function
483 or else Ekind (Old_S) = E_Operator
484 or else (Ekind (Old_S) = E_Subprogram_Type
485 and then Etype (Old_S) /= Standard_Void_Type)
488 Make_Simple_Return_Statement (Loc,
490 Make_Function_Call (Loc,
492 Parameter_Associations => Actuals));
494 elsif Ekind (Old_S) = E_Enumeration_Literal then
496 Make_Simple_Return_Statement (Loc,
497 Expression => New_Occurrence_Of (Old_S, Loc));
499 elsif Nkind (Nam) = N_Character_Literal then
501 Make_Simple_Return_Statement (Loc,
502 Expression => Call_Name);
506 Make_Procedure_Call_Statement (Loc,
508 Parameter_Associations => Actuals);
511 -- Create entities for subprogram body and formals
513 Set_Defining_Unit_Name (Spec,
514 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
516 Param_Spec := First (Parameter_Specifications (Spec));
517 while Present (Param_Spec) loop
518 Set_Defining_Identifier (Param_Spec,
519 Make_Defining_Identifier (Loc,
520 Chars => Chars (Defining_Identifier (Param_Spec))));
525 Make_Subprogram_Body (Loc,
526 Specification => Spec,
527 Declarations => New_List,
528 Handled_Statement_Sequence =>
529 Make_Handled_Sequence_Of_Statements (Loc,
530 Statements => New_List (Call_Node)));
532 if Nkind (Decl) /= N_Subprogram_Declaration then
534 Make_Subprogram_Declaration (Loc,
535 Specification => Specification (N)));
538 -- Link the body to the entity whose declaration it completes. If
539 -- the body is analyzed when the renamed entity is frozen, it may
540 -- be necessary to restore the proper scope (see package Exp_Ch13).
542 if Nkind (N) = N_Subprogram_Renaming_Declaration
543 and then Present (Corresponding_Spec (N))
545 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
547 Set_Corresponding_Spec (Body_Node, New_S);
551 end Build_Renamed_Body;
553 --------------------------
554 -- Check_Address_Clause --
555 --------------------------
557 procedure Check_Address_Clause (E : Entity_Id) is
558 Addr : constant Node_Id := Address_Clause (E);
560 Decl : constant Node_Id := Declaration_Node (E);
561 Loc : constant Source_Ptr := Sloc (Decl);
562 Typ : constant Entity_Id := Etype (E);
565 if Present (Addr) then
566 Expr := Expression (Addr);
568 if Needs_Constant_Address (Decl, Typ) then
569 Check_Constant_Address_Clause (Expr, E);
571 -- Has_Delayed_Freeze was set on E when the address clause was
572 -- analyzed, and must remain set because we want the address
573 -- clause to be elaborated only after any entity it references
574 -- has been elaborated.
577 -- If Rep_Clauses are to be ignored, remove address clause from
578 -- list attached to entity, because it may be illegal for gigi,
579 -- for example by breaking order of elaboration..
581 if Ignore_Rep_Clauses then
586 Rep := First_Rep_Item (E);
589 Set_First_Rep_Item (E, Next_Rep_Item (Addr));
593 and then Next_Rep_Item (Rep) /= Addr
595 Rep := Next_Rep_Item (Rep);
599 if Present (Rep) then
600 Set_Next_Rep_Item (Rep, Next_Rep_Item (Addr));
604 Rewrite (Addr, Make_Null_Statement (Sloc (E)));
606 elsif not Error_Posted (Expr)
607 and then not Needs_Finalization (Typ)
609 Warn_Overlay (Expr, Typ, Name (Addr));
612 if Present (Expression (Decl)) then
614 -- Capture initialization value at point of declaration
616 Remove_Side_Effects (Expression (Decl));
618 -- Move initialization to freeze actions (once the object has
619 -- been frozen, and the address clause alignment check has been
622 Append_Freeze_Action (E,
623 Make_Assignment_Statement (Loc,
624 Name => New_Occurrence_Of (E, Loc),
625 Expression => Expression (Decl)));
627 Set_No_Initialization (Decl);
630 end Check_Address_Clause;
632 -----------------------------
633 -- Check_Compile_Time_Size --
634 -----------------------------
636 procedure Check_Compile_Time_Size (T : Entity_Id) is
638 procedure Set_Small_Size (T : Entity_Id; S : Uint);
639 -- Sets the compile time known size (32 bits or less) in the Esize
640 -- field, of T checking for a size clause that was given which attempts
641 -- to give a smaller size, and also checking for an alignment clause.
643 function Size_Known (T : Entity_Id) return Boolean;
644 -- Recursive function that does all the work
646 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
647 -- If T is a constrained subtype, its size is not known if any of its
648 -- discriminant constraints is not static and it is not a null record.
649 -- The test is conservative and doesn't check that the components are
650 -- in fact constrained by non-static discriminant values. Could be made
657 procedure Set_Small_Size (T : Entity_Id; S : Uint) is
662 -- Check for bad size clause given
664 elsif Has_Size_Clause (T) then
665 if RM_Size (T) < S then
666 Error_Msg_Uint_1 := S;
668 ("size for& too small, minimum allowed is ^",
672 -- Set size if not set already
674 elsif Unknown_RM_Size (T) then
683 function Size_Known (T : Entity_Id) return Boolean is
691 if Size_Known_At_Compile_Time (T) then
694 -- Always True for scalar types. This is true even for generic formal
695 -- scalar types. We used to return False in the latter case, but the
696 -- size is known at compile time, even in the template, we just do
697 -- not know the exact size but that's not the point of this routine.
699 elsif Is_Scalar_Type (T)
700 or else Is_Task_Type (T)
706 elsif Is_Array_Type (T) then
708 -- String literals always have known size, and we can set it
710 if Ekind (T) = E_String_Literal_Subtype then
711 Set_Small_Size (T, Component_Size (T)
712 * String_Literal_Length (T));
715 -- Unconstrained types never have known at compile time size
717 elsif not Is_Constrained (T) then
720 -- Don't do any recursion on type with error posted, since we may
721 -- have a malformed type that leads us into a loop.
723 elsif Error_Posted (T) then
726 -- Otherwise if component size unknown, then array size unknown
728 elsif not Size_Known (Component_Type (T)) then
732 -- Check for all indexes static, and also compute possible size
733 -- (in case it is less than 32 and may be packable).
736 Esiz : Uint := Component_Size (T);
740 Index := First_Index (T);
741 while Present (Index) loop
742 if Nkind (Index) = N_Range then
743 Get_Index_Bounds (Index, Low, High);
745 elsif Error_Posted (Scalar_Range (Etype (Index))) then
749 Low := Type_Low_Bound (Etype (Index));
750 High := Type_High_Bound (Etype (Index));
753 if not Compile_Time_Known_Value (Low)
754 or else not Compile_Time_Known_Value (High)
755 or else Etype (Index) = Any_Type
760 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
772 Set_Small_Size (T, Esiz);
776 -- Access types always have known at compile time sizes
778 elsif Is_Access_Type (T) then
781 -- For non-generic private types, go to underlying type if present
783 elsif Is_Private_Type (T)
784 and then not Is_Generic_Type (T)
785 and then Present (Underlying_Type (T))
787 -- Don't do any recursion on type with error posted, since we may
788 -- have a malformed type that leads us into a loop.
790 if Error_Posted (T) then
793 return Size_Known (Underlying_Type (T));
798 elsif Is_Record_Type (T) then
800 -- A class-wide type is never considered to have a known size
802 if Is_Class_Wide_Type (T) then
805 -- A subtype of a variant record must not have non-static
806 -- discriminated components.
808 elsif T /= Base_Type (T)
809 and then not Static_Discriminated_Components (T)
813 -- Don't do any recursion on type with error posted, since we may
814 -- have a malformed type that leads us into a loop.
816 elsif Error_Posted (T) then
820 -- Now look at the components of the record
823 -- The following two variables are used to keep track of the
824 -- size of packed records if we can tell the size of the packed
825 -- record in the front end. Packed_Size_Known is True if so far
826 -- we can figure out the size. It is initialized to True for a
827 -- packed record, unless the record has discriminants or atomic
828 -- components or independent components.
830 -- The reason we eliminate the discriminated case is that
831 -- we don't know the way the back end lays out discriminated
832 -- packed records. If Packed_Size_Known is True, then
833 -- Packed_Size is the size in bits so far.
835 Packed_Size_Known : Boolean :=
837 and then not Has_Discriminants (T)
838 and then not Has_Atomic_Components (T)
839 and then not Has_Independent_Components (T);
841 Packed_Size : Uint := Uint_0;
842 -- Size in bits so far
845 -- Test for variant part present
847 if Has_Discriminants (T)
848 and then Present (Parent (T))
849 and then Nkind (Parent (T)) = N_Full_Type_Declaration
850 and then Nkind (Type_Definition (Parent (T))) =
852 and then not Null_Present (Type_Definition (Parent (T)))
854 Present (Variant_Part
855 (Component_List (Type_Definition (Parent (T)))))
857 -- If variant part is present, and type is unconstrained,
858 -- then we must have defaulted discriminants, or a size
859 -- clause must be present for the type, or else the size
860 -- is definitely not known at compile time.
862 if not Is_Constrained (T)
864 No (Discriminant_Default_Value (First_Discriminant (T)))
865 and then Unknown_RM_Size (T)
871 -- Loop through components
873 Comp := First_Component_Or_Discriminant (T);
874 while Present (Comp) loop
875 Ctyp := Etype (Comp);
877 -- We do not know the packed size if there is a component
878 -- clause present (we possibly could, but this would only
879 -- help in the case of a record with partial rep clauses.
880 -- That's because in the case of full rep clauses, the
881 -- size gets figured out anyway by a different circuit).
883 if Present (Component_Clause (Comp)) then
884 Packed_Size_Known := False;
887 -- We do not know the packed size if we have a by reference
888 -- type, or an atomic type or an atomic component, or an
889 -- aliased component (because packing does not touch these).
892 or else Is_Atomic (Comp)
893 or else Is_By_Reference_Type (Ctyp)
894 or else Is_Aliased (Comp)
896 Packed_Size_Known := False;
899 -- We need to identify a component that is an array where
900 -- the index type is an enumeration type with non-standard
901 -- representation, and some bound of the type depends on a
904 -- This is because gigi computes the size by doing a
905 -- substitution of the appropriate discriminant value in
906 -- the size expression for the base type, and gigi is not
907 -- clever enough to evaluate the resulting expression (which
908 -- involves a call to rep_to_pos) at compile time.
910 -- It would be nice if gigi would either recognize that
911 -- this expression can be computed at compile time, or
912 -- alternatively figured out the size from the subtype
913 -- directly, where all the information is at hand ???
915 if Is_Array_Type (Etype (Comp))
916 and then Present (Packed_Array_Type (Etype (Comp)))
919 Ocomp : constant Entity_Id :=
920 Original_Record_Component (Comp);
921 OCtyp : constant Entity_Id := Etype (Ocomp);
927 Ind := First_Index (OCtyp);
928 while Present (Ind) loop
929 Indtyp := Etype (Ind);
931 if Is_Enumeration_Type (Indtyp)
932 and then Has_Non_Standard_Rep (Indtyp)
934 Lo := Type_Low_Bound (Indtyp);
935 Hi := Type_High_Bound (Indtyp);
937 if Is_Entity_Name (Lo)
938 and then Ekind (Entity (Lo)) = E_Discriminant
942 elsif Is_Entity_Name (Hi)
943 and then Ekind (Entity (Hi)) = E_Discriminant
954 -- Clearly size of record is not known if the size of one of
955 -- the components is not known.
957 if not Size_Known (Ctyp) then
961 -- Accumulate packed size if possible
963 if Packed_Size_Known then
965 -- We can only deal with elementary types, since for
966 -- non-elementary components, alignment enters into the
967 -- picture, and we don't know enough to handle proper
968 -- alignment in this context. Packed arrays count as
969 -- elementary if the representation is a modular type.
971 if Is_Elementary_Type (Ctyp)
972 or else (Is_Array_Type (Ctyp)
973 and then Present (Packed_Array_Type (Ctyp))
974 and then Is_Modular_Integer_Type
975 (Packed_Array_Type (Ctyp)))
977 -- Packed size unknown if we have an atomic type
978 -- or a by reference type, since the back end
979 -- knows how these are layed out.
982 or else Is_By_Reference_Type (Ctyp)
984 Packed_Size_Known := False;
986 -- If RM_Size is known and static, then we can keep
987 -- accumulating the packed size
989 elsif Known_Static_RM_Size (Ctyp) then
991 -- A little glitch, to be removed sometime ???
992 -- gigi does not understand zero sizes yet.
994 if RM_Size (Ctyp) = Uint_0 then
995 Packed_Size_Known := False;
997 -- Normal case where we can keep accumulating the
998 -- packed array size.
1001 Packed_Size := Packed_Size + RM_Size (Ctyp);
1004 -- If we have a field whose RM_Size is not known then
1005 -- we can't figure out the packed size here.
1008 Packed_Size_Known := False;
1011 -- If we have a non-elementary type we can't figure out
1012 -- the packed array size (alignment issues).
1015 Packed_Size_Known := False;
1019 Next_Component_Or_Discriminant (Comp);
1022 if Packed_Size_Known then
1023 Set_Small_Size (T, Packed_Size);
1029 -- All other cases, size not known at compile time
1036 -------------------------------------
1037 -- Static_Discriminated_Components --
1038 -------------------------------------
1040 function Static_Discriminated_Components
1041 (T : Entity_Id) return Boolean
1043 Constraint : Elmt_Id;
1046 if Has_Discriminants (T)
1047 and then Present (Discriminant_Constraint (T))
1048 and then Present (First_Component (T))
1050 Constraint := First_Elmt (Discriminant_Constraint (T));
1051 while Present (Constraint) loop
1052 if not Compile_Time_Known_Value (Node (Constraint)) then
1056 Next_Elmt (Constraint);
1061 end Static_Discriminated_Components;
1063 -- Start of processing for Check_Compile_Time_Size
1066 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
1067 end Check_Compile_Time_Size;
1069 -----------------------------------
1070 -- Check_Component_Storage_Order --
1071 -----------------------------------
1073 procedure Check_Component_Storage_Order
1074 (Encl_Type : Entity_Id;
1078 Comp_Type : Entity_Id;
1082 Comp_Byte_Aligned : Boolean;
1083 -- Set True for the record case, when Comp starts on a byte boundary
1084 -- (in which case it is allowed to have different storage order).
1086 Component_Aliased : Boolean;
1091 if Present (Comp) then
1093 Comp_Type := Etype (Comp);
1095 if Is_Tag (Comp) then
1096 Comp_Byte_Aligned := True;
1097 Component_Aliased := False;
1100 Comp_Byte_Aligned :=
1101 Present (Component_Clause (Comp))
1103 Normalized_First_Bit (Comp) mod System_Storage_Unit = 0;
1104 Component_Aliased := Is_Aliased (Comp);
1110 Err_Node := Encl_Type;
1111 Comp_Type := Component_Type (Encl_Type);
1113 Comp_Byte_Aligned := False;
1114 Component_Aliased := Has_Aliased_Components (Encl_Type);
1117 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1118 -- the attribute definition clause is attached to the first subtype.
1120 Comp_Type := Base_Type (Comp_Type);
1121 Comp_ADC := Get_Attribute_Definition_Clause
1122 (First_Subtype (Comp_Type),
1123 Attribute_Scalar_Storage_Order);
1125 -- Case of enclosing type not having explicit SSO: component cannot
1129 if Present (Comp_ADC) then
1131 ("composite type must have explicit scalar storage order",
1135 -- Case of enclosing type having explicit SSO: check compatible
1136 -- attribute on Comp_Type if composite.
1138 elsif Is_Record_Type (Comp_Type) or else Is_Array_Type (Comp_Type) then
1139 if Present (Comp) and then Chars (Comp) = Name_uParent then
1140 if Reverse_Storage_Order (Encl_Type)
1142 Reverse_Storage_Order (Comp_Type)
1145 ("record extension must have same scalar storage order as "
1146 & "parent", Err_Node);
1150 Error_Msg_N ("nested composite must have explicit scalar "
1151 & "storage order", Err_Node);
1153 elsif (Reverse_Storage_Order (Encl_Type)
1155 Reverse_Storage_Order (Comp_Type))
1156 and then not Comp_Byte_Aligned
1159 ("type of non-byte-aligned component must have same scalar "
1160 & "storage order as enclosing composite", Err_Node);
1163 -- Enclosing type has explicit SSO, non-composite component must not
1166 elsif Component_Aliased then
1168 ("aliased component not permitted for type with "
1169 & "explicit Scalar_Storage_Order", Err_Node);
1171 end Check_Component_Storage_Order;
1173 -----------------------------
1174 -- Check_Debug_Info_Needed --
1175 -----------------------------
1177 procedure Check_Debug_Info_Needed (T : Entity_Id) is
1179 if Debug_Info_Off (T) then
1182 elsif Comes_From_Source (T)
1183 or else Debug_Generated_Code
1184 or else Debug_Flag_VV
1185 or else Needs_Debug_Info (T)
1187 Set_Debug_Info_Needed (T);
1189 end Check_Debug_Info_Needed;
1191 ----------------------------
1192 -- Check_Strict_Alignment --
1193 ----------------------------
1195 procedure Check_Strict_Alignment (E : Entity_Id) is
1199 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
1200 Set_Strict_Alignment (E);
1202 elsif Is_Array_Type (E) then
1203 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
1205 elsif Is_Record_Type (E) then
1206 if Is_Limited_Record (E) then
1207 Set_Strict_Alignment (E);
1211 Comp := First_Component (E);
1212 while Present (Comp) loop
1213 if not Is_Type (Comp)
1214 and then (Strict_Alignment (Etype (Comp))
1215 or else Is_Aliased (Comp))
1217 Set_Strict_Alignment (E);
1221 Next_Component (Comp);
1224 end Check_Strict_Alignment;
1226 -------------------------
1227 -- Check_Unsigned_Type --
1228 -------------------------
1230 procedure Check_Unsigned_Type (E : Entity_Id) is
1231 Ancestor : Entity_Id;
1236 if not Is_Discrete_Or_Fixed_Point_Type (E) then
1240 -- Do not attempt to analyze case where range was in error
1242 if No (Scalar_Range (E))
1243 or else Error_Posted (Scalar_Range (E))
1248 -- The situation that is non trivial is something like
1250 -- subtype x1 is integer range -10 .. +10;
1251 -- subtype x2 is x1 range 0 .. V1;
1252 -- subtype x3 is x2 range V2 .. V3;
1253 -- subtype x4 is x3 range V4 .. V5;
1255 -- where Vn are variables. Here the base type is signed, but we still
1256 -- know that x4 is unsigned because of the lower bound of x2.
1258 -- The only way to deal with this is to look up the ancestor chain
1262 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1266 Lo_Bound := Type_Low_Bound (Ancestor);
1268 if Compile_Time_Known_Value (Lo_Bound) then
1270 if Expr_Rep_Value (Lo_Bound) >= 0 then
1271 Set_Is_Unsigned_Type (E, True);
1277 Ancestor := Ancestor_Subtype (Ancestor);
1279 -- If no ancestor had a static lower bound, go to base type
1281 if No (Ancestor) then
1283 -- Note: the reason we still check for a compile time known
1284 -- value for the base type is that at least in the case of
1285 -- generic formals, we can have bounds that fail this test,
1286 -- and there may be other cases in error situations.
1288 Btyp := Base_Type (E);
1290 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1294 Lo_Bound := Type_Low_Bound (Base_Type (E));
1296 if Compile_Time_Known_Value (Lo_Bound)
1297 and then Expr_Rep_Value (Lo_Bound) >= 0
1299 Set_Is_Unsigned_Type (E, True);
1306 end Check_Unsigned_Type;
1308 -------------------------
1309 -- Is_Atomic_Aggregate --
1310 -------------------------
1312 function Is_Atomic_Aggregate
1314 Typ : Entity_Id) return Boolean
1316 Loc : constant Source_Ptr := Sloc (E);
1324 -- Array may be qualified, so find outer context
1326 if Nkind (Par) = N_Qualified_Expression then
1327 Par := Parent (Par);
1330 if Nkind_In (Par, N_Object_Declaration, N_Assignment_Statement)
1331 and then Comes_From_Source (Par)
1333 Temp := Make_Temporary (Loc, 'T', E);
1335 Make_Object_Declaration (Loc,
1336 Defining_Identifier => Temp,
1337 Object_Definition => New_Occurrence_Of (Typ, Loc),
1338 Expression => Relocate_Node (E));
1339 Insert_Before (Par, New_N);
1342 Set_Expression (Par, New_Occurrence_Of (Temp, Loc));
1348 end Is_Atomic_Aggregate;
1354 -- Note: the easy coding for this procedure would be to just build a
1355 -- single list of freeze nodes and then insert them and analyze them
1356 -- all at once. This won't work, because the analysis of earlier freeze
1357 -- nodes may recursively freeze types which would otherwise appear later
1358 -- on in the freeze list. So we must analyze and expand the freeze nodes
1359 -- as they are generated.
1361 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1365 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1366 -- This is the internal recursive routine that does freezing of entities
1367 -- (but NOT the analysis of default expressions, which should not be
1368 -- recursive, we don't want to analyze those till we are sure that ALL
1369 -- the types are frozen).
1371 --------------------
1372 -- Freeze_All_Ent --
1373 --------------------
1375 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id) is
1380 procedure Process_Flist;
1381 -- If freeze nodes are present, insert and analyze, and reset cursor
1382 -- for next insertion.
1388 procedure Process_Flist is
1390 if Is_Non_Empty_List (Flist) then
1391 Lastn := Next (After);
1392 Insert_List_After_And_Analyze (After, Flist);
1394 if Present (Lastn) then
1395 After := Prev (Lastn);
1397 After := Last (List_Containing (After));
1402 -- Start or processing for Freeze_All_Ent
1406 while Present (E) loop
1408 -- If the entity is an inner package which is not a package
1409 -- renaming, then its entities must be frozen at this point. Note
1410 -- that such entities do NOT get frozen at the end of the nested
1411 -- package itself (only library packages freeze).
1413 -- Same is true for task declarations, where anonymous records
1414 -- created for entry parameters must be frozen.
1416 if Ekind (E) = E_Package
1417 and then No (Renamed_Object (E))
1418 and then not Is_Child_Unit (E)
1419 and then not Is_Frozen (E)
1422 Install_Visible_Declarations (E);
1423 Install_Private_Declarations (E);
1425 Freeze_All (First_Entity (E), After);
1427 End_Package_Scope (E);
1429 if Is_Generic_Instance (E)
1430 and then Has_Delayed_Freeze (E)
1432 Set_Has_Delayed_Freeze (E, False);
1433 Expand_N_Package_Declaration (Unit_Declaration_Node (E));
1436 elsif Ekind (E) in Task_Kind
1438 (Nkind (Parent (E)) = N_Task_Type_Declaration
1440 Nkind (Parent (E)) = N_Single_Task_Declaration)
1443 Freeze_All (First_Entity (E), After);
1446 -- For a derived tagged type, we must ensure that all the
1447 -- primitive operations of the parent have been frozen, so that
1448 -- their addresses will be in the parent's dispatch table at the
1449 -- point it is inherited.
1451 elsif Ekind (E) = E_Record_Type
1452 and then Is_Tagged_Type (E)
1453 and then Is_Tagged_Type (Etype (E))
1454 and then Is_Derived_Type (E)
1457 Prim_List : constant Elist_Id :=
1458 Primitive_Operations (Etype (E));
1464 Prim := First_Elmt (Prim_List);
1465 while Present (Prim) loop
1466 Subp := Node (Prim);
1468 if Comes_From_Source (Subp)
1469 and then not Is_Frozen (Subp)
1471 Flist := Freeze_Entity (Subp, After);
1480 if not Is_Frozen (E) then
1481 Flist := Freeze_Entity (E, After);
1484 -- If already frozen, and there are delayed aspects, this is where
1485 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1486 -- for a description of how we handle aspect visibility).
1488 elsif Has_Delayed_Aspects (E) then
1490 -- Retrieve the visibility to the discriminants in order to
1491 -- analyze properly the aspects.
1493 Push_Scope_And_Install_Discriminants (E);
1499 Ritem := First_Rep_Item (E);
1500 while Present (Ritem) loop
1501 if Nkind (Ritem) = N_Aspect_Specification
1502 and then Entity (Ritem) = E
1503 and then Is_Delayed_Aspect (Ritem)
1505 Check_Aspect_At_End_Of_Declarations (Ritem);
1508 Ritem := Next_Rep_Item (Ritem);
1512 Uninstall_Discriminants_And_Pop_Scope (E);
1515 -- If an incomplete type is still not frozen, this may be a
1516 -- premature freezing because of a body declaration that follows.
1517 -- Indicate where the freezing took place. Freezing will happen
1518 -- if the body comes from source, but not if it is internally
1519 -- generated, for example as the body of a type invariant.
1521 -- If the freezing is caused by the end of the current declarative
1522 -- part, it is a Taft Amendment type, and there is no error.
1524 if not Is_Frozen (E)
1525 and then Ekind (E) = E_Incomplete_Type
1528 Bod : constant Node_Id := Next (After);
1531 -- The presence of a body freezes all entities previously
1532 -- declared in the current list of declarations, but this
1533 -- does not apply if the body does not come from source.
1534 -- A type invariant is transformed into a subprogram body
1535 -- which is placed at the end of the private part of the
1536 -- current package, but this body does not freeze incomplete
1537 -- types that may be declared in this private part.
1539 if (Nkind_In (Bod, N_Subprogram_Body,
1544 or else Nkind (Bod) in N_Body_Stub)
1546 List_Containing (After) = List_Containing (Parent (E))
1547 and then Comes_From_Source (Bod)
1549 Error_Msg_Sloc := Sloc (Next (After));
1551 ("type& is frozen# before its full declaration",
1561 -- Start of processing for Freeze_All
1564 Freeze_All_Ent (From, After);
1566 -- Now that all types are frozen, we can deal with default expressions
1567 -- that require us to build a default expression functions. This is the
1568 -- point at which such functions are constructed (after all types that
1569 -- might be used in such expressions have been frozen).
1571 -- For subprograms that are renaming_as_body, we create the wrapper
1572 -- bodies as needed.
1574 -- We also add finalization chains to access types whose designated
1575 -- types are controlled. This is normally done when freezing the type,
1576 -- but this misses recursive type definitions where the later members
1577 -- of the recursion introduce controlled components.
1579 -- Loop through entities
1582 while Present (E) loop
1583 if Is_Subprogram (E) then
1585 if not Default_Expressions_Processed (E) then
1586 Process_Default_Expressions (E, After);
1589 if not Has_Completion (E) then
1590 Decl := Unit_Declaration_Node (E);
1592 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1593 if Error_Posted (Decl) then
1594 Set_Has_Completion (E);
1596 Build_And_Analyze_Renamed_Body (Decl, E, After);
1599 elsif Nkind (Decl) = N_Subprogram_Declaration
1600 and then Present (Corresponding_Body (Decl))
1602 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1603 = N_Subprogram_Renaming_Declaration
1605 Build_And_Analyze_Renamed_Body
1606 (Decl, Corresponding_Body (Decl), After);
1610 elsif Ekind (E) in Task_Kind
1612 (Nkind (Parent (E)) = N_Task_Type_Declaration
1614 Nkind (Parent (E)) = N_Single_Task_Declaration)
1620 Ent := First_Entity (E);
1621 while Present (Ent) loop
1623 and then not Default_Expressions_Processed (Ent)
1625 Process_Default_Expressions (Ent, After);
1632 -- We add finalization masters to access types whose designated types
1633 -- require finalization. This is normally done when freezing the
1634 -- type, but this misses recursive type definitions where the later
1635 -- members of the recursion introduce controlled components (such as
1636 -- can happen when incomplete types are involved), as well cases
1637 -- where a component type is private and the controlled full type
1638 -- occurs after the access type is frozen. Cases that don't need a
1639 -- finalization master are generic formal types (the actual type will
1640 -- have it) and types with Java and CIL conventions, since those are
1641 -- used for API bindings. (Are there any other cases that should be
1642 -- excluded here???)
1644 elsif Is_Access_Type (E)
1645 and then Comes_From_Source (E)
1646 and then not Is_Generic_Type (E)
1647 and then Needs_Finalization (Designated_Type (E))
1649 Build_Finalization_Master (E);
1656 -----------------------
1657 -- Freeze_And_Append --
1658 -----------------------
1660 procedure Freeze_And_Append
1663 Result : in out List_Id)
1665 L : constant List_Id := Freeze_Entity (Ent, N);
1667 if Is_Non_Empty_List (L) then
1668 if Result = No_List then
1671 Append_List (L, Result);
1674 end Freeze_And_Append;
1680 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1681 Freeze_Nodes : constant List_Id := Freeze_Entity (T, N);
1683 if Is_Non_Empty_List (Freeze_Nodes) then
1684 Insert_Actions (N, Freeze_Nodes);
1692 function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is
1693 Loc : constant Source_Ptr := Sloc (N);
1694 Test_E : Entity_Id := E;
1701 Result : List_Id := No_List;
1702 -- List of freezing actions, left at No_List if none
1704 Has_Default_Initialization : Boolean := False;
1705 -- This flag gets set to true for a variable with default initialization
1707 procedure Add_To_Result (N : Node_Id);
1708 -- N is a freezing action to be appended to the Result
1710 function After_Last_Declaration return Boolean;
1711 -- If Loc is a freeze_entity that appears after the last declaration
1712 -- in the scope, inhibit error messages on late completion.
1714 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1715 -- Check that an Access or Unchecked_Access attribute with a prefix
1716 -- which is the current instance type can only be applied when the type
1719 procedure Check_Suspicious_Modulus (Utype : Entity_Id);
1720 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1721 -- integer literal without an explicit corresponding size clause. The
1722 -- caller has checked that Utype is a modular integer type.
1724 procedure Freeze_Array_Type (Arr : Entity_Id);
1725 -- Freeze array type, including freezing index and component types
1727 function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id;
1728 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1729 -- package. Recurse on inner generic packages.
1731 procedure Freeze_Record_Type (Rec : Entity_Id);
1732 -- Freeze record type, including freezing component types, and freezing
1733 -- primitive operations if this is a tagged type.
1739 procedure Add_To_Result (N : Node_Id) is
1742 Result := New_List (N);
1748 ----------------------------
1749 -- After_Last_Declaration --
1750 ----------------------------
1752 function After_Last_Declaration return Boolean is
1753 Spec : constant Node_Id := Parent (Current_Scope);
1755 if Nkind (Spec) = N_Package_Specification then
1756 if Present (Private_Declarations (Spec)) then
1757 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1758 elsif Present (Visible_Declarations (Spec)) then
1759 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1766 end After_Last_Declaration;
1768 ----------------------------
1769 -- Check_Current_Instance --
1770 ----------------------------
1772 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1774 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean;
1775 -- Determine whether Typ is compatible with the rules for aliased
1776 -- views of types as defined in RM 3.10 in the various dialects.
1778 function Process (N : Node_Id) return Traverse_Result;
1779 -- Process routine to apply check to given node
1781 -----------------------------
1782 -- Is_Aliased_View_Of_Type --
1783 -----------------------------
1785 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean is
1786 Typ_Decl : constant Node_Id := Parent (Typ);
1791 if Nkind (Typ_Decl) = N_Full_Type_Declaration
1792 and then Limited_Present (Type_Definition (Typ_Decl))
1796 -- The following paragraphs describe what a legal aliased view of
1797 -- a type is in the various dialects of Ada.
1801 -- The current instance of a limited type, and a formal parameter
1802 -- or generic formal object of a tagged type.
1804 -- Ada 95 limited type
1805 -- * Type with reserved word "limited"
1806 -- * A protected or task type
1807 -- * A composite type with limited component
1809 elsif Ada_Version <= Ada_95 then
1810 return Is_Limited_Type (Typ);
1814 -- The current instance of a limited tagged type, a protected
1815 -- type, a task type, or a type that has the reserved word
1816 -- "limited" in its full definition ... a formal parameter or
1817 -- generic formal object of a tagged type.
1819 -- Ada 2005 limited type
1820 -- * Type with reserved word "limited", "synchronized", "task"
1822 -- * A composite type with limited component
1823 -- * A derived type whose parent is a non-interface limited type
1825 elsif Ada_Version = Ada_2005 then
1827 (Is_Limited_Type (Typ) and then Is_Tagged_Type (Typ))
1829 (Is_Derived_Type (Typ)
1830 and then not Is_Interface (Etype (Typ))
1831 and then Is_Limited_Type (Etype (Typ)));
1833 -- Ada 2012 and beyond
1835 -- The current instance of an immutably limited type ... a formal
1836 -- parameter or generic formal object of a tagged type.
1838 -- Ada 2012 limited type
1839 -- * Type with reserved word "limited", "synchronized", "task"
1841 -- * A composite type with limited component
1842 -- * A derived type whose parent is a non-interface limited type
1843 -- * An incomplete view
1845 -- Ada 2012 immutably limited type
1846 -- * Explicitly limited record type
1847 -- * Record extension with "limited" present
1848 -- * Non-formal limited private type that is either tagged
1849 -- or has at least one access discriminant with a default
1851 -- * Task type, protected type or synchronized interface
1852 -- * Type derived from immutably limited type
1856 Is_Immutably_Limited_Type (Typ)
1857 or else Is_Incomplete_Type (Typ);
1859 end Is_Aliased_View_Of_Type;
1865 function Process (N : Node_Id) return Traverse_Result is
1868 when N_Attribute_Reference =>
1869 if Nam_In (Attribute_Name (N), Name_Access,
1870 Name_Unchecked_Access)
1871 and then Is_Entity_Name (Prefix (N))
1872 and then Is_Type (Entity (Prefix (N)))
1873 and then Entity (Prefix (N)) = E
1876 ("current instance must be a limited type", Prefix (N));
1882 when others => return OK;
1886 procedure Traverse is new Traverse_Proc (Process);
1890 Rec_Type : constant Entity_Id :=
1891 Scope (Defining_Identifier (Comp_Decl));
1893 -- Start of processing for Check_Current_Instance
1896 if not Is_Aliased_View_Of_Type (Rec_Type) then
1897 Traverse (Comp_Decl);
1899 end Check_Current_Instance;
1901 ------------------------------
1902 -- Check_Suspicious_Modulus --
1903 ------------------------------
1905 procedure Check_Suspicious_Modulus (Utype : Entity_Id) is
1906 Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype));
1909 if not Warn_On_Suspicious_Modulus_Value then
1913 if Nkind (Decl) = N_Full_Type_Declaration then
1915 Tdef : constant Node_Id := Type_Definition (Decl);
1918 if Nkind (Tdef) = N_Modular_Type_Definition then
1920 Modulus : constant Node_Id :=
1921 Original_Node (Expression (Tdef));
1924 if Nkind (Modulus) = N_Integer_Literal then
1926 Modv : constant Uint := Intval (Modulus);
1927 Sizv : constant Uint := RM_Size (Utype);
1930 -- First case, modulus and size are the same. This
1931 -- happens if you have something like mod 32, with
1932 -- an explicit size of 32, this is for sure a case
1933 -- where the warning is given, since it is seems
1934 -- very unlikely that someone would want e.g. a
1935 -- five bit type stored in 32 bits. It is much
1936 -- more likely they wanted a 32-bit type.
1941 -- Second case, the modulus is 32 or 64 and no
1942 -- size clause is present. This is a less clear
1943 -- case for giving the warning, but in the case
1944 -- of 32/64 (5-bit or 6-bit types) these seem rare
1945 -- enough that it is a likely error (and in any
1946 -- case using 2**5 or 2**6 in these cases seems
1947 -- clearer. We don't include 8 or 16 here, simply
1948 -- because in practice 3-bit and 4-bit types are
1949 -- more common and too many false positives if
1950 -- we warn in these cases.
1952 elsif not Has_Size_Clause (Utype)
1953 and then (Modv = Uint_32 or else Modv = Uint_64)
1957 -- No warning needed
1963 -- If we fall through, give warning
1965 Error_Msg_Uint_1 := Modv;
1967 ("?M?2 '*'*^' may have been intended here",
1975 end Check_Suspicious_Modulus;
1977 -----------------------
1978 -- Freeze_Array_Type --
1979 -----------------------
1981 procedure Freeze_Array_Type (Arr : Entity_Id) is
1982 FS : constant Entity_Id := First_Subtype (Arr);
1983 Ctyp : constant Entity_Id := Component_Type (Arr);
1986 Non_Standard_Enum : Boolean := False;
1987 -- Set true if any of the index types is an enumeration type with a
1988 -- non-standard representation.
1991 Freeze_And_Append (Ctyp, N, Result);
1993 Indx := First_Index (Arr);
1994 while Present (Indx) loop
1995 Freeze_And_Append (Etype (Indx), N, Result);
1997 if Is_Enumeration_Type (Etype (Indx))
1998 and then Has_Non_Standard_Rep (Etype (Indx))
2000 Non_Standard_Enum := True;
2006 -- Processing that is done only for base types
2008 if Ekind (Arr) = E_Array_Type then
2010 -- Propagate flags for component type
2012 if Is_Controlled (Component_Type (Arr))
2013 or else Has_Controlled_Component (Ctyp)
2015 Set_Has_Controlled_Component (Arr);
2018 if Has_Unchecked_Union (Component_Type (Arr)) then
2019 Set_Has_Unchecked_Union (Arr);
2022 -- Warn for pragma Pack overriding foreign convention
2024 if Has_Foreign_Convention (Ctyp)
2025 and then Has_Pragma_Pack (Arr)
2028 CN : constant Name_Id :=
2029 Get_Convention_Name (Convention (Ctyp));
2030 PP : constant Node_Id :=
2031 Get_Pragma (First_Subtype (Arr), Pragma_Pack);
2033 if Present (PP) then
2034 Error_Msg_Name_1 := CN;
2035 Error_Msg_Sloc := Sloc (Arr);
2037 ("pragma Pack affects convention % components #??",
2039 Error_Msg_Name_1 := CN;
2041 ("\array components may not have % compatible "
2042 & "representation??", PP);
2047 -- If packing was requested or if the component size was
2048 -- set explicitly, then see if bit packing is required. This
2049 -- processing is only done for base types, since all of the
2050 -- representation aspects involved are type-related. This is not
2051 -- just an optimization, if we start processing the subtypes, they
2052 -- interfere with the settings on the base type (this is because
2053 -- Is_Packed has a slightly different meaning before and after
2061 if (Is_Packed (Arr) or else Has_Pragma_Pack (Arr))
2062 and then Known_Static_RM_Size (Ctyp)
2063 and then not Has_Component_Size_Clause (Arr)
2065 Csiz := UI_Max (RM_Size (Ctyp), 1);
2067 elsif Known_Component_Size (Arr) then
2068 Csiz := Component_Size (Arr);
2070 elsif not Known_Static_Esize (Ctyp) then
2074 Esiz := Esize (Ctyp);
2076 -- We can set the component size if it is less than 16,
2077 -- rounding it up to the next storage unit size.
2081 elsif Esiz <= 16 then
2087 -- Set component size up to match alignment if it would
2088 -- otherwise be less than the alignment. This deals with
2089 -- cases of types whose alignment exceeds their size (the
2090 -- padded type cases).
2094 A : constant Uint := Alignment_In_Bits (Ctyp);
2103 -- Case of component size that may result in packing
2105 if 1 <= Csiz and then Csiz <= 64 then
2107 Ent : constant Entity_Id :=
2108 First_Subtype (Arr);
2109 Pack_Pragma : constant Node_Id :=
2110 Get_Rep_Pragma (Ent, Name_Pack);
2111 Comp_Size_C : constant Node_Id :=
2112 Get_Attribute_Definition_Clause
2113 (Ent, Attribute_Component_Size);
2115 -- Warn if we have pack and component size so that the
2118 -- Note: here we must check for the presence of a
2119 -- component size before checking for a Pack pragma to
2120 -- deal with the case where the array type is a derived
2121 -- type whose parent is currently private.
2123 if Present (Comp_Size_C)
2124 and then Has_Pragma_Pack (Ent)
2125 and then Warn_On_Redundant_Constructs
2127 Error_Msg_Sloc := Sloc (Comp_Size_C);
2129 ("?r?pragma Pack for& ignored!",
2132 ("\?r?explicit component size given#!",
2134 Set_Is_Packed (Base_Type (Ent), False);
2135 Set_Is_Bit_Packed_Array (Base_Type (Ent), False);
2138 -- Set component size if not already set by a component
2141 if not Present (Comp_Size_C) then
2142 Set_Component_Size (Arr, Csiz);
2145 -- Check for base type of 8, 16, 32 bits, where an
2146 -- unsigned subtype has a length one less than the
2147 -- base type (e.g. Natural subtype of Integer).
2149 -- In such cases, if a component size was not set
2150 -- explicitly, then generate a warning.
2152 if Has_Pragma_Pack (Arr)
2153 and then not Present (Comp_Size_C)
2155 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
2156 and then Esize (Base_Type (Ctyp)) = Csiz + 1
2158 Error_Msg_Uint_1 := Csiz;
2160 if Present (Pack_Pragma) then
2162 ("??pragma Pack causes component size "
2163 & "to be ^!", Pack_Pragma);
2165 ("\??use Component_Size to set "
2166 & "desired value!", Pack_Pragma);
2170 -- Actual packing is not needed for 8, 16, 32, 64. Also
2171 -- not needed for 24 if alignment is 1.
2177 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
2179 -- Here the array was requested to be packed, but
2180 -- the packing request had no effect, so Is_Packed
2183 -- Note: semantically this means that we lose track
2184 -- of the fact that a derived type inherited a pragma
2185 -- Pack that was non- effective, but that seems fine.
2187 -- We regard a Pack pragma as a request to set a
2188 -- representation characteristic, and this request
2191 Set_Is_Packed (Base_Type (Arr), False);
2192 Set_Is_Bit_Packed_Array (Base_Type (Arr), False);
2194 if Known_Static_Esize (Component_Type (Arr))
2195 and then Esize (Component_Type (Arr)) = Csiz
2197 Set_Has_Non_Standard_Rep
2198 (Base_Type (Arr), False);
2201 -- In all other cases, packing is indeed needed
2204 Set_Has_Non_Standard_Rep (Base_Type (Arr), True);
2205 Set_Is_Bit_Packed_Array (Base_Type (Arr), True);
2206 Set_Is_Packed (Base_Type (Arr), True);
2212 -- Check for Atomic_Components or Aliased with unsuitable packing
2213 -- or explicit component size clause given.
2215 if (Has_Atomic_Components (Arr)
2216 or else Has_Aliased_Components (Arr))
2217 and then (Has_Component_Size_Clause (Arr)
2218 or else Is_Packed (Arr))
2220 Alias_Atomic_Check : declare
2222 procedure Complain_CS (T : String);
2223 -- Outputs error messages for incorrect CS clause or pragma
2224 -- Pack for aliased or atomic components (T is "aliased" or
2231 procedure Complain_CS (T : String) is
2233 if Has_Component_Size_Clause (Arr) then
2235 Get_Attribute_Definition_Clause
2236 (FS, Attribute_Component_Size);
2238 if Known_Static_Esize (Ctyp) then
2240 ("incorrect component size for "
2241 & T & " components", Clause);
2242 Error_Msg_Uint_1 := Esize (Ctyp);
2244 ("\only allowed value is^", Clause);
2248 ("component size cannot be given for "
2249 & T & " components", Clause);
2254 ("cannot pack " & T & " components",
2255 Get_Rep_Pragma (FS, Name_Pack));
2261 -- Start of processing for Alias_Atomic_Check
2265 -- If object size of component type isn't known, we cannot
2266 -- be sure so we defer to the back end.
2268 if not Known_Static_Esize (Ctyp) then
2271 -- Case where component size has no effect. First check for
2272 -- object size of component type multiple of the storage
2275 elsif Esize (Ctyp) mod System_Storage_Unit = 0
2277 -- OK in both packing case and component size case if RM
2278 -- size is known and static and same as the object size.
2281 ((Known_Static_RM_Size (Ctyp)
2282 and then Esize (Ctyp) = RM_Size (Ctyp))
2284 -- Or if we have an explicit component size clause and
2285 -- the component size and object size are equal.
2288 (Has_Component_Size_Clause (Arr)
2289 and then Component_Size (Arr) = Esize (Ctyp)))
2293 elsif Has_Aliased_Components (Arr)
2294 or else Is_Aliased (Ctyp)
2296 Complain_CS ("aliased");
2298 elsif Has_Atomic_Components (Arr)
2299 or else Is_Atomic (Ctyp)
2301 Complain_CS ("atomic");
2303 end Alias_Atomic_Check;
2306 -- Warn for case of atomic type
2308 Clause := Get_Rep_Pragma (FS, Name_Atomic);
2311 and then not Addressable (Component_Size (FS))
2314 ("non-atomic components of type& may not be "
2315 & "accessible by separate tasks??", Clause, Arr);
2317 if Has_Component_Size_Clause (Arr) then
2320 (Get_Attribute_Definition_Clause
2321 (FS, Attribute_Component_Size));
2323 ("\because of component size clause#??",
2326 elsif Has_Pragma_Pack (Arr) then
2328 Sloc (Get_Rep_Pragma (FS, Name_Pack));
2330 ("\because of pragma Pack#??", Clause);
2334 -- Check for scalar storage order
2336 Check_Component_Storage_Order
2339 ADC => Get_Attribute_Definition_Clause
2340 (First_Subtype (Arr),
2341 Attribute_Scalar_Storage_Order));
2343 -- Processing that is done only for subtypes
2346 -- Acquire alignment from base type
2348 if Unknown_Alignment (Arr) then
2349 Set_Alignment (Arr, Alignment (Base_Type (Arr)));
2350 Adjust_Esize_Alignment (Arr);
2354 -- Specific checks for bit-packed arrays
2356 if Is_Bit_Packed_Array (Arr) then
2358 -- Check number of elements for bit packed arrays that come from
2359 -- source and have compile time known ranges. The bit-packed
2360 -- arrays circuitry does not support arrays with more than
2361 -- Integer'Last + 1 elements, and when this restriction is
2362 -- violated, causes incorrect data access.
2364 -- For the case where this is not compile time known, a run-time
2365 -- check should be generated???
2367 if Comes_From_Source (Arr) and then Is_Constrained (Arr) then
2376 Index := First_Index (Arr);
2377 while Present (Index) loop
2378 Ityp := Etype (Index);
2380 -- Never generate an error if any index is of a generic
2381 -- type. We will check this in instances.
2383 if Is_Generic_Type (Ityp) then
2389 Make_Attribute_Reference (Loc,
2391 New_Occurrence_Of (Ityp, Loc),
2392 Attribute_Name => Name_Range_Length);
2393 Analyze_And_Resolve (Ilen);
2395 -- No attempt is made to check number of elements
2396 -- if not compile time known.
2398 if Nkind (Ilen) /= N_Integer_Literal then
2403 Elmts := Elmts * Intval (Ilen);
2407 if Elmts > Intval (High_Bound
2409 (Standard_Integer))) + 1
2412 ("bit packed array type may not have "
2413 & "more than Integer''Last+1 elements", Arr);
2420 if Known_RM_Size (Arr) then
2422 SizC : constant Node_Id := Size_Clause (Arr);
2425 pragma Warnings (Off, Discard);
2428 -- It is not clear if it is possible to have no size clause
2429 -- at this stage, but it is not worth worrying about. Post
2430 -- error on the entity name in the size clause if present,
2431 -- else on the type entity itself.
2433 if Present (SizC) then
2434 Check_Size (Name (SizC), Arr, RM_Size (Arr), Discard);
2436 Check_Size (Arr, Arr, RM_Size (Arr), Discard);
2442 -- If any of the index types was an enumeration type with a
2443 -- non-standard rep clause, then we indicate that the array type
2444 -- is always packed (even if it is not bit packed).
2446 if Non_Standard_Enum then
2447 Set_Has_Non_Standard_Rep (Base_Type (Arr));
2448 Set_Is_Packed (Base_Type (Arr));
2451 Set_Component_Alignment_If_Not_Set (Arr);
2453 -- If the array is packed, we must create the packed array type to be
2454 -- used to actually implement the type. This is only needed for real
2455 -- array types (not for string literal types, since they are present
2456 -- only for the front end).
2459 and then Ekind (Arr) /= E_String_Literal_Subtype
2461 Create_Packed_Array_Type (Arr);
2462 Freeze_And_Append (Packed_Array_Type (Arr), N, Result);
2464 -- Size information of packed array type is copied to the array
2465 -- type, since this is really the representation. But do not
2466 -- override explicit existing size values. If the ancestor subtype
2467 -- is constrained the packed_array_type will be inherited from it,
2468 -- but the size may have been provided already, and must not be
2469 -- overridden either.
2471 if not Has_Size_Clause (Arr)
2473 (No (Ancestor_Subtype (Arr))
2474 or else not Has_Size_Clause (Ancestor_Subtype (Arr)))
2476 Set_Esize (Arr, Esize (Packed_Array_Type (Arr)));
2477 Set_RM_Size (Arr, RM_Size (Packed_Array_Type (Arr)));
2480 if not Has_Alignment_Clause (Arr) then
2481 Set_Alignment (Arr, Alignment (Packed_Array_Type (Arr)));
2485 -- For non-packed arrays set the alignment of the array to the
2486 -- alignment of the component type if it is unknown. Skip this
2487 -- in atomic case (atomic arrays may need larger alignments).
2489 if not Is_Packed (Arr)
2490 and then Unknown_Alignment (Arr)
2491 and then Known_Alignment (Ctyp)
2492 and then Known_Static_Component_Size (Arr)
2493 and then Known_Static_Esize (Ctyp)
2494 and then Esize (Ctyp) = Component_Size (Arr)
2495 and then not Is_Atomic (Arr)
2497 Set_Alignment (Arr, Alignment (Component_Type (Arr)));
2499 end Freeze_Array_Type;
2501 -----------------------------
2502 -- Freeze_Generic_Entities --
2503 -----------------------------
2505 function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id is
2512 E := First_Entity (Pack);
2513 while Present (E) loop
2514 if Is_Type (E) and then not Is_Generic_Type (E) then
2515 F := Make_Freeze_Generic_Entity (Sloc (Pack));
2517 Append_To (Flist, F);
2519 elsif Ekind (E) = E_Generic_Package then
2520 Append_List_To (Flist, Freeze_Generic_Entities (E));
2527 end Freeze_Generic_Entities;
2529 ------------------------
2530 -- Freeze_Record_Type --
2531 ------------------------
2533 procedure Freeze_Record_Type (Rec : Entity_Id) is
2540 pragma Warnings (Off, Junk);
2542 Rec_Pushed : Boolean := False;
2543 -- Set True if the record type scope Rec has been pushed on the scope
2544 -- stack. Needed for the analysis of delayed aspects specified to the
2545 -- components of Rec.
2547 Unplaced_Component : Boolean := False;
2548 -- Set True if we find at least one component with no component
2549 -- clause (used to warn about useless Pack pragmas).
2551 Placed_Component : Boolean := False;
2552 -- Set True if we find at least one component with a component
2553 -- clause (used to warn about useless Bit_Order pragmas, and also
2554 -- to detect cases where Implicit_Packing may have an effect).
2556 Aliased_Component : Boolean := False;
2557 -- Set True if we find at least one component which is aliased. This
2558 -- is used to prevent Implicit_Packing of the record, since packing
2559 -- cannot modify the size of alignment of an aliased component.
2561 All_Scalar_Components : Boolean := True;
2562 -- Set False if we encounter a component of a non-scalar type
2564 Scalar_Component_Total_RM_Size : Uint := Uint_0;
2565 Scalar_Component_Total_Esize : Uint := Uint_0;
2566 -- Accumulates total RM_Size values and total Esize values of all
2567 -- scalar components. Used for processing of Implicit_Packing.
2569 function Check_Allocator (N : Node_Id) return Node_Id;
2570 -- If N is an allocator, possibly wrapped in one or more level of
2571 -- qualified expression(s), return the inner allocator node, else
2574 procedure Check_Itype (Typ : Entity_Id);
2575 -- If the component subtype is an access to a constrained subtype of
2576 -- an already frozen type, make the subtype frozen as well. It might
2577 -- otherwise be frozen in the wrong scope, and a freeze node on
2578 -- subtype has no effect. Similarly, if the component subtype is a
2579 -- regular (not protected) access to subprogram, set the anonymous
2580 -- subprogram type to frozen as well, to prevent an out-of-scope
2581 -- freeze node at some eventual point of call. Protected operations
2582 -- are handled elsewhere.
2584 procedure Freeze_Choices_In_Variant_Part (VP : Node_Id);
2585 -- Make sure that all types mentioned in Discrete_Choices of the
2586 -- variants referenceed by the Variant_Part VP are frozen. This is
2587 -- a recursive routine to deal with nested variants.
2589 ---------------------
2590 -- Check_Allocator --
2591 ---------------------
2593 function Check_Allocator (N : Node_Id) return Node_Id is
2598 if Nkind (Inner) = N_Allocator then
2600 elsif Nkind (Inner) = N_Qualified_Expression then
2601 Inner := Expression (Inner);
2606 end Check_Allocator;
2612 procedure Check_Itype (Typ : Entity_Id) is
2613 Desig : constant Entity_Id := Designated_Type (Typ);
2616 if not Is_Frozen (Desig)
2617 and then Is_Frozen (Base_Type (Desig))
2619 Set_Is_Frozen (Desig);
2621 -- In addition, add an Itype_Reference to ensure that the
2622 -- access subtype is elaborated early enough. This cannot be
2623 -- done if the subtype may depend on discriminants.
2625 if Ekind (Comp) = E_Component
2626 and then Is_Itype (Etype (Comp))
2627 and then not Has_Discriminants (Rec)
2629 IR := Make_Itype_Reference (Sloc (Comp));
2630 Set_Itype (IR, Desig);
2634 elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type
2635 and then Convention (Desig) /= Convention_Protected
2637 Set_Is_Frozen (Desig);
2641 ------------------------------------
2642 -- Freeze_Choices_In_Variant_Part --
2643 ------------------------------------
2645 procedure Freeze_Choices_In_Variant_Part (VP : Node_Id) is
2646 pragma Assert (Nkind (VP) = N_Variant_Part);
2653 -- Loop through variants
2655 Variant := First_Non_Pragma (Variants (VP));
2656 while Present (Variant) loop
2658 -- Loop through choices, checking that all types are frozen
2660 Choice := First_Non_Pragma (Discrete_Choices (Variant));
2661 while Present (Choice) loop
2662 if Nkind (Choice) in N_Has_Etype
2663 and then Present (Etype (Choice))
2665 Freeze_And_Append (Etype (Choice), N, Result);
2668 Next_Non_Pragma (Choice);
2671 -- Check for nested variant part to process
2673 CL := Component_List (Variant);
2675 if not Null_Present (CL) then
2676 if Present (Variant_Part (CL)) then
2677 Freeze_Choices_In_Variant_Part (Variant_Part (CL));
2681 Next_Non_Pragma (Variant);
2683 end Freeze_Choices_In_Variant_Part;
2685 -- Start of processing for Freeze_Record_Type
2688 -- Deal with delayed aspect specifications for components. The
2689 -- analysis of the aspect is required to be delayed to the freeze
2690 -- point, thus we analyze the pragma or attribute definition
2691 -- clause in the tree at this point. We also analyze the aspect
2692 -- specification node at the freeze point when the aspect doesn't
2693 -- correspond to pragma/attribute definition clause.
2695 Comp := First_Entity (Rec);
2696 while Present (Comp) loop
2697 if Ekind (Comp) = E_Component
2698 and then Has_Delayed_Aspects (Comp)
2700 if not Rec_Pushed then
2704 -- The visibility to the discriminants must be restored in
2705 -- order to properly analyze the aspects.
2707 if Has_Discriminants (Rec) then
2708 Install_Discriminants (Rec);
2712 Analyze_Aspects_At_Freeze_Point (Comp);
2718 -- Pop the scope if Rec scope has been pushed on the scope stack
2719 -- during the delayed aspect analysis process.
2722 if Has_Discriminants (Rec) then
2723 Uninstall_Discriminants (Rec);
2729 -- Freeze components and embedded subtypes
2731 Comp := First_Entity (Rec);
2733 while Present (Comp) loop
2734 if Is_Aliased (Comp) then
2735 Aliased_Component := True;
2738 -- Handle the component and discriminant case
2740 if Ekind_In (Comp, E_Component, E_Discriminant) then
2742 CC : constant Node_Id := Component_Clause (Comp);
2745 -- Freezing a record type freezes the type of each of its
2746 -- components. However, if the type of the component is
2747 -- part of this record, we do not want or need a separate
2748 -- Freeze_Node. Note that Is_Itype is wrong because that's
2749 -- also set in private type cases. We also can't check for
2750 -- the Scope being exactly Rec because of private types and
2751 -- record extensions.
2753 if Is_Itype (Etype (Comp))
2754 and then Is_Record_Type (Underlying_Type
2755 (Scope (Etype (Comp))))
2757 Undelay_Type (Etype (Comp));
2760 Freeze_And_Append (Etype (Comp), N, Result);
2762 -- Warn for pragma Pack overriding foreign convention
2764 if Has_Foreign_Convention (Etype (Comp))
2765 and then Has_Pragma_Pack (Rec)
2767 -- Don't warn for aliased components, since override
2768 -- cannot happen in that case.
2770 and then not Is_Aliased (Comp)
2773 CN : constant Name_Id :=
2774 Get_Convention_Name (Convention (Etype (Comp)));
2775 PP : constant Node_Id :=
2776 Get_Pragma (Rec, Pragma_Pack);
2778 if Present (PP) then
2779 Error_Msg_Name_1 := CN;
2780 Error_Msg_Sloc := Sloc (Comp);
2782 ("pragma Pack affects convention % component#??",
2784 Error_Msg_Name_1 := CN;
2786 ("\component & may not have % compatible "
2787 & "representation??", PP, Comp);
2792 -- Check for error of component clause given for variable
2793 -- sized type. We have to delay this test till this point,
2794 -- since the component type has to be frozen for us to know
2795 -- if it is variable length. We omit this test in a generic
2796 -- context, it will be applied at instantiation time.
2798 -- We also omit this test in CodePeer mode, since we do not
2799 -- have sufficient info on size and representation clauses.
2801 if Present (CC) then
2802 Placed_Component := True;
2804 if Inside_A_Generic then
2807 elsif CodePeer_Mode then
2811 Size_Known_At_Compile_Time
2812 (Underlying_Type (Etype (Comp)))
2815 ("component clause not allowed for variable " &
2816 "length component", CC);
2820 Unplaced_Component := True;
2823 -- Case of component requires byte alignment
2825 if Must_Be_On_Byte_Boundary (Etype (Comp)) then
2827 -- Set the enclosing record to also require byte align
2829 Set_Must_Be_On_Byte_Boundary (Rec);
2831 -- Check for component clause that is inconsistent with
2832 -- the required byte boundary alignment.
2835 and then Normalized_First_Bit (Comp) mod
2836 System_Storage_Unit /= 0
2839 ("component & must be byte aligned",
2840 Component_Name (Component_Clause (Comp)));
2846 -- Gather data for possible Implicit_Packing later. Note that at
2847 -- this stage we might be dealing with a real component, or with
2848 -- an implicit subtype declaration.
2850 if not Is_Scalar_Type (Etype (Comp)) then
2851 All_Scalar_Components := False;
2853 Scalar_Component_Total_RM_Size :=
2854 Scalar_Component_Total_RM_Size + RM_Size (Etype (Comp));
2855 Scalar_Component_Total_Esize :=
2856 Scalar_Component_Total_Esize + Esize (Etype (Comp));
2859 -- If the component is an Itype with Delayed_Freeze and is either
2860 -- a record or array subtype and its base type has not yet been
2861 -- frozen, we must remove this from the entity list of this record
2862 -- and put it on the entity list of the scope of its base type.
2863 -- Note that we know that this is not the type of a component
2864 -- since we cleared Has_Delayed_Freeze for it in the previous
2865 -- loop. Thus this must be the Designated_Type of an access type,
2866 -- which is the type of a component.
2869 and then Is_Type (Scope (Comp))
2870 and then Is_Composite_Type (Comp)
2871 and then Base_Type (Comp) /= Comp
2872 and then Has_Delayed_Freeze (Comp)
2873 and then not Is_Frozen (Base_Type (Comp))
2876 Will_Be_Frozen : Boolean := False;
2880 -- We have a pretty bad kludge here. Suppose Rec is subtype
2881 -- being defined in a subprogram that's created as part of
2882 -- the freezing of Rec'Base. In that case, we know that
2883 -- Comp'Base must have already been frozen by the time we
2884 -- get to elaborate this because Gigi doesn't elaborate any
2885 -- bodies until it has elaborated all of the declarative
2886 -- part. But Is_Frozen will not be set at this point because
2887 -- we are processing code in lexical order.
2889 -- We detect this case by going up the Scope chain of Rec
2890 -- and seeing if we have a subprogram scope before reaching
2891 -- the top of the scope chain or that of Comp'Base. If we
2892 -- do, then mark that Comp'Base will actually be frozen. If
2893 -- so, we merely undelay it.
2896 while Present (S) loop
2897 if Is_Subprogram (S) then
2898 Will_Be_Frozen := True;
2900 elsif S = Scope (Base_Type (Comp)) then
2907 if Will_Be_Frozen then
2908 Undelay_Type (Comp);
2910 if Present (Prev) then
2911 Set_Next_Entity (Prev, Next_Entity (Comp));
2913 Set_First_Entity (Rec, Next_Entity (Comp));
2916 -- Insert in entity list of scope of base type (which
2917 -- must be an enclosing scope, because still unfrozen).
2919 Append_Entity (Comp, Scope (Base_Type (Comp)));
2923 -- If the component is an access type with an allocator as default
2924 -- value, the designated type will be frozen by the corresponding
2925 -- expression in init_proc. In order to place the freeze node for
2926 -- the designated type before that for the current record type,
2929 -- Same process if the component is an array of access types,
2930 -- initialized with an aggregate. If the designated type is
2931 -- private, it cannot contain allocators, and it is premature
2932 -- to freeze the type, so we check for this as well.
2934 elsif Is_Access_Type (Etype (Comp))
2935 and then Present (Parent (Comp))
2936 and then Present (Expression (Parent (Comp)))
2939 Alloc : constant Node_Id :=
2940 Check_Allocator (Expression (Parent (Comp)));
2943 if Present (Alloc) then
2945 -- If component is pointer to a class-wide type, freeze
2946 -- the specific type in the expression being allocated.
2947 -- The expression may be a subtype indication, in which
2948 -- case freeze the subtype mark.
2950 if Is_Class_Wide_Type
2951 (Designated_Type (Etype (Comp)))
2953 if Is_Entity_Name (Expression (Alloc)) then
2955 (Entity (Expression (Alloc)), N, Result);
2957 Nkind (Expression (Alloc)) = N_Subtype_Indication
2960 (Entity (Subtype_Mark (Expression (Alloc))),
2964 elsif Is_Itype (Designated_Type (Etype (Comp))) then
2965 Check_Itype (Etype (Comp));
2969 (Designated_Type (Etype (Comp)), N, Result);
2974 elsif Is_Access_Type (Etype (Comp))
2975 and then Is_Itype (Designated_Type (Etype (Comp)))
2977 Check_Itype (Etype (Comp));
2979 elsif Is_Array_Type (Etype (Comp))
2980 and then Is_Access_Type (Component_Type (Etype (Comp)))
2981 and then Present (Parent (Comp))
2982 and then Nkind (Parent (Comp)) = N_Component_Declaration
2983 and then Present (Expression (Parent (Comp)))
2984 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
2985 and then Is_Fully_Defined
2986 (Designated_Type (Component_Type (Etype (Comp))))
2990 (Component_Type (Etype (Comp))), N, Result);
2997 ADC := Get_Attribute_Definition_Clause
2998 (Rec, Attribute_Scalar_Storage_Order);
3000 if Present (ADC) then
3002 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3003 -- the former is specified.
3005 if Reverse_Bit_Order (Rec) /= Reverse_Storage_Order (Rec) then
3007 -- Note: report error on Rec, not on ADC, as ADC may apply to
3008 -- an ancestor type.
3010 Error_Msg_Sloc := Sloc (ADC);
3012 ("scalar storage order for& specified# inconsistent with "
3013 & "bit order", Rec);
3016 -- Warn if there is a Scalar_Storage_Order but no component clause
3017 -- (or pragma Pack).
3019 if not (Placed_Component or else Is_Packed (Rec)) then
3021 ("??scalar storage order specified but no component clause",
3026 -- Check consistent attribute setting on component types
3028 Comp := First_Component (Rec);
3029 while Present (Comp) loop
3030 Check_Component_Storage_Order
3031 (Encl_Type => Rec, Comp => Comp, ADC => ADC);
3032 Next_Component (Comp);
3035 -- Deal with Bit_Order aspect specifying a non-default bit order
3037 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
3039 if Present (ADC) and then Base_Type (Rec) = Rec then
3040 if not (Placed_Component or else Is_Packed (Rec)) then
3042 ("??bit order specification has no effect", ADC);
3044 ("\??since no component clauses were specified", ADC);
3046 -- Here is where we do the processing for reversed bit order
3048 elsif Reverse_Bit_Order (Rec)
3049 and then not Reverse_Storage_Order (Rec)
3051 Adjust_Record_For_Reverse_Bit_Order (Rec);
3053 -- Case where we have both an explicit Bit_Order and the same
3054 -- Scalar_Storage_Order: leave record untouched, the back-end
3055 -- will take care of required layout conversions.
3063 -- Complete error checking on record representation clause (e.g.
3064 -- overlap of components). This is called after adjusting the
3065 -- record for reverse bit order.
3068 RRC : constant Node_Id := Get_Record_Representation_Clause (Rec);
3070 if Present (RRC) then
3071 Check_Record_Representation_Clause (RRC);
3075 -- Set OK_To_Reorder_Components depending on debug flags
3077 if Is_Base_Type (Rec) and then Convention (Rec) = Convention_Ada then
3078 if (Has_Discriminants (Rec) and then Debug_Flag_Dot_V)
3080 (not Has_Discriminants (Rec) and then Debug_Flag_Dot_R)
3082 Set_OK_To_Reorder_Components (Rec);
3086 -- Check for useless pragma Pack when all components placed. We only
3087 -- do this check for record types, not subtypes, since a subtype may
3088 -- have all its components placed, and it still makes perfectly good
3089 -- sense to pack other subtypes or the parent type. We do not give
3090 -- this warning if Optimize_Alignment is set to Space, since the
3091 -- pragma Pack does have an effect in this case (it always resets
3092 -- the alignment to one).
3094 if Ekind (Rec) = E_Record_Type
3095 and then Is_Packed (Rec)
3096 and then not Unplaced_Component
3097 and then Optimize_Alignment /= 'S'
3099 -- Reset packed status. Probably not necessary, but we do it so
3100 -- that there is no chance of the back end doing something strange
3101 -- with this redundant indication of packing.
3103 Set_Is_Packed (Rec, False);
3105 -- Give warning if redundant constructs warnings on
3107 if Warn_On_Redundant_Constructs then
3108 Error_Msg_N -- CODEFIX
3109 ("??pragma Pack has no effect, no unplaced components",
3110 Get_Rep_Pragma (Rec, Name_Pack));
3114 -- If this is the record corresponding to a remote type, freeze the
3115 -- remote type here since that is what we are semantically freezing.
3116 -- This prevents the freeze node for that type in an inner scope.
3118 if Ekind (Rec) = E_Record_Type then
3119 if Present (Corresponding_Remote_Type (Rec)) then
3120 Freeze_And_Append (Corresponding_Remote_Type (Rec), N, Result);
3123 -- Check for controlled components and unchecked unions.
3125 Comp := First_Component (Rec);
3126 while Present (Comp) loop
3128 -- Do not set Has_Controlled_Component on a class-wide
3129 -- equivalent type. See Make_CW_Equivalent_Type.
3131 if not Is_Class_Wide_Equivalent_Type (Rec)
3133 (Has_Controlled_Component (Etype (Comp))
3135 (Chars (Comp) /= Name_uParent
3136 and then Is_Controlled (Etype (Comp)))
3138 (Is_Protected_Type (Etype (Comp))
3140 Present (Corresponding_Record_Type (Etype (Comp)))
3142 Has_Controlled_Component
3143 (Corresponding_Record_Type (Etype (Comp)))))
3145 Set_Has_Controlled_Component (Rec);
3148 if Has_Unchecked_Union (Etype (Comp)) then
3149 Set_Has_Unchecked_Union (Rec);
3152 -- Scan component declaration for likely misuses of current
3153 -- instance, either in a constraint or a default expression.
3155 if Has_Per_Object_Constraint (Comp) then
3156 Check_Current_Instance (Parent (Comp));
3159 Next_Component (Comp);
3163 -- Enforce the restriction that access attributes with a current
3164 -- instance prefix can only apply to limited types. This comment
3165 -- is floating here, but does not seem to belong here???
3167 -- Set component alignment if not otherwise already set
3169 Set_Component_Alignment_If_Not_Set (Rec);
3171 -- For first subtypes, check if there are any fixed-point fields with
3172 -- component clauses, where we must check the size. This is not done
3173 -- till the freeze point since for fixed-point types, we do not know
3174 -- the size until the type is frozen. Similar processing applies to
3175 -- bit packed arrays.
3177 if Is_First_Subtype (Rec) then
3178 Comp := First_Component (Rec);
3179 while Present (Comp) loop
3180 if Present (Component_Clause (Comp))
3181 and then (Is_Fixed_Point_Type (Etype (Comp))
3183 Is_Bit_Packed_Array (Etype (Comp)))
3186 (Component_Name (Component_Clause (Comp)),
3192 Next_Component (Comp);
3196 -- Generate warning for applying C or C++ convention to a record
3197 -- with discriminants. This is suppressed for the unchecked union
3198 -- case, since the whole point in this case is interface C. We also
3199 -- do not generate this within instantiations, since we will have
3200 -- generated a message on the template.
3202 if Has_Discriminants (E)
3203 and then not Is_Unchecked_Union (E)
3204 and then (Convention (E) = Convention_C
3206 Convention (E) = Convention_CPP)
3207 and then Comes_From_Source (E)
3208 and then not In_Instance
3209 and then not Has_Warnings_Off (E)
3210 and then not Has_Warnings_Off (Base_Type (E))
3213 Cprag : constant Node_Id := Get_Rep_Pragma (E, Name_Convention);
3217 if Present (Cprag) then
3218 A2 := Next (First (Pragma_Argument_Associations (Cprag)));
3220 if Convention (E) = Convention_C then
3222 ("?x?variant record has no direct equivalent in C",
3226 ("?x?variant record has no direct equivalent in C++",
3231 ("\?x?use of convention for type& is dubious", A2, E);
3236 -- See if Size is too small as is (and implicit packing might help)
3238 if not Is_Packed (Rec)
3240 -- No implicit packing if even one component is explicitly placed
3242 and then not Placed_Component
3244 -- Or even one component is aliased
3246 and then not Aliased_Component
3248 -- Must have size clause and all scalar components
3250 and then Has_Size_Clause (Rec)
3251 and then All_Scalar_Components
3253 -- Do not try implicit packing on records with discriminants, too
3254 -- complicated, especially in the variant record case.
3256 and then not Has_Discriminants (Rec)
3258 -- We can implicitly pack if the specified size of the record is
3259 -- less than the sum of the object sizes (no point in packing if
3260 -- this is not the case).
3262 and then RM_Size (Rec) < Scalar_Component_Total_Esize
3264 -- And the total RM size cannot be greater than the specified size
3265 -- since otherwise packing will not get us where we have to be!
3267 and then RM_Size (Rec) >= Scalar_Component_Total_RM_Size
3269 -- Never do implicit packing in CodePeer or SPARK modes since
3270 -- we don't do any packing in these modes, since this generates
3271 -- over-complex code that confuses static analysis, and in
3272 -- general, neither CodePeer not GNATprove care about the
3273 -- internal representation of objects.
3275 and then not (CodePeer_Mode or SPARK_Mode)
3277 -- If implicit packing enabled, do it
3279 if Implicit_Packing then
3280 Set_Is_Packed (Rec);
3282 -- Otherwise flag the size clause
3286 Sz : constant Node_Id := Size_Clause (Rec);
3288 Error_Msg_NE -- CODEFIX
3289 ("size given for& too small", Sz, Rec);
3290 Error_Msg_N -- CODEFIX
3291 ("\use explicit pragma Pack "
3292 & "or use pragma Implicit_Packing", Sz);
3297 -- All done if not a full record definition
3299 if Ekind (Rec) /= E_Record_Type then
3303 -- Finally we need to check the variant part to make sure that
3304 -- all types within choices are properly frozen as part of the
3305 -- freezing of the record type.
3307 Check_Variant_Part : declare
3308 D : constant Node_Id := Declaration_Node (Rec);
3313 -- Find component list
3317 if Nkind (D) = N_Full_Type_Declaration then
3318 T := Type_Definition (D);
3320 if Nkind (T) = N_Record_Definition then
3321 C := Component_List (T);
3323 elsif Nkind (T) = N_Derived_Type_Definition
3324 and then Present (Record_Extension_Part (T))
3326 C := Component_List (Record_Extension_Part (T));
3330 -- Case of variant part present
3332 if Present (C) and then Present (Variant_Part (C)) then
3333 Freeze_Choices_In_Variant_Part (Variant_Part (C));
3336 -- Note: we used to call Check_Choices here, but it is too early,
3337 -- since predicated subtypes are frozen here, but their freezing
3338 -- actions are in Analyze_Freeze_Entity, which has not been called
3339 -- yet for entities frozen within this procedure, so we moved that
3340 -- call to the Analyze_Freeze_Entity for the record type.
3342 end Check_Variant_Part;
3343 end Freeze_Record_Type;
3345 -- Start of processing for Freeze_Entity
3348 -- We are going to test for various reasons why this entity need not be
3349 -- frozen here, but in the case of an Itype that's defined within a
3350 -- record, that test actually applies to the record.
3352 if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
3353 Test_E := Scope (E);
3354 elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
3355 and then Is_Record_Type (Underlying_Type (Scope (E)))
3357 Test_E := Underlying_Type (Scope (E));
3360 -- Do not freeze if already frozen since we only need one freeze node
3362 if Is_Frozen (E) then
3365 -- It is improper to freeze an external entity within a generic because
3366 -- its freeze node will appear in a non-valid context. The entity will
3367 -- be frozen in the proper scope after the current generic is analyzed.
3368 -- However, aspects must be analyzed because they may be queried later
3369 -- within the generic itself, and the corresponding pragma or attribute
3370 -- definition has not been analyzed yet.
3372 elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then
3373 if Has_Delayed_Aspects (E) then
3374 Analyze_Aspects_At_Freeze_Point (E);
3379 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3380 -- the instance, the same applies to the subtype renaming the actual.
3382 elsif Is_Private_Type (E)
3383 and then Is_Generic_Actual_Type (E)
3384 and then No (Full_View (Base_Type (E)))
3385 and then Ada_Version >= Ada_2012
3389 -- Generic types need no freeze node and have no delayed semantic
3392 elsif Is_Generic_Type (E) then
3395 -- Do not freeze a global entity within an inner scope created during
3396 -- expansion. A call to subprogram E within some internal procedure
3397 -- (a stream attribute for example) might require freezing E, but the
3398 -- freeze node must appear in the same declarative part as E itself.
3399 -- The two-pass elaboration mechanism in gigi guarantees that E will
3400 -- be frozen before the inner call is elaborated. We exclude constants
3401 -- from this test, because deferred constants may be frozen early, and
3402 -- must be diagnosed (e.g. in the case of a deferred constant being used
3403 -- in a default expression). If the enclosing subprogram comes from
3404 -- source, or is a generic instance, then the freeze point is the one
3405 -- mandated by the language, and we freeze the entity. A subprogram that
3406 -- is a child unit body that acts as a spec does not have a spec that
3407 -- comes from source, but can only come from source.
3409 elsif In_Open_Scopes (Scope (Test_E))
3410 and then Scope (Test_E) /= Current_Scope
3411 and then Ekind (Test_E) /= E_Constant
3418 while Present (S) loop
3419 if Is_Overloadable (S) then
3420 if Comes_From_Source (S)
3421 or else Is_Generic_Instance (S)
3422 or else Is_Child_Unit (S)
3434 -- Similarly, an inlined instance body may make reference to global
3435 -- entities, but these references cannot be the proper freezing point
3436 -- for them, and in the absence of inlining freezing will take place in
3437 -- their own scope. Normally instance bodies are analyzed after the
3438 -- enclosing compilation, and everything has been frozen at the proper
3439 -- place, but with front-end inlining an instance body is compiled
3440 -- before the end of the enclosing scope, and as a result out-of-order
3441 -- freezing must be prevented.
3443 elsif Front_End_Inlining
3444 and then In_Instance_Body
3445 and then Present (Scope (Test_E))
3451 S := Scope (Test_E);
3452 while Present (S) loop
3453 if Is_Generic_Instance (S) then
3465 elsif Ekind (E) = E_Generic_Package then
3466 return Freeze_Generic_Entities (E);
3469 -- Add checks to detect proper initialization of scalars that may appear
3470 -- as subprogram parameters.
3472 if Is_Subprogram (E) and then Check_Validity_Of_Parameters then
3473 Apply_Parameter_Validity_Checks (E);
3476 -- Deal with delayed aspect specifications. The analysis of the aspect
3477 -- is required to be delayed to the freeze point, thus we analyze the
3478 -- pragma or attribute definition clause in the tree at this point. We
3479 -- also analyze the aspect specification node at the freeze point when
3480 -- the aspect doesn't correspond to pragma/attribute definition clause.
3482 if Has_Delayed_Aspects (E) then
3483 Analyze_Aspects_At_Freeze_Point (E);
3486 -- Here to freeze the entity
3490 -- Case of entity being frozen is other than a type
3492 if not Is_Type (E) then
3494 -- If entity is exported or imported and does not have an external
3495 -- name, now is the time to provide the appropriate default name.
3496 -- Skip this if the entity is stubbed, since we don't need a name
3497 -- for any stubbed routine. For the case on intrinsics, if no
3498 -- external name is specified, then calls will be handled in
3499 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3500 -- external name is provided, then Expand_Intrinsic_Call leaves
3501 -- calls in place for expansion by GIGI.
3503 if (Is_Imported (E) or else Is_Exported (E))
3504 and then No (Interface_Name (E))
3505 and then Convention (E) /= Convention_Stubbed
3506 and then Convention (E) /= Convention_Intrinsic
3508 Set_Encoded_Interface_Name
3509 (E, Get_Default_External_Name (E));
3511 -- If entity is an atomic object appearing in a declaration and
3512 -- the expression is an aggregate, assign it to a temporary to
3513 -- ensure that the actual assignment is done atomically rather
3514 -- than component-wise (the assignment to the temp may be done
3515 -- component-wise, but that is harmless).
3518 and then Nkind (Parent (E)) = N_Object_Declaration
3519 and then Present (Expression (Parent (E)))
3520 and then Nkind (Expression (Parent (E))) = N_Aggregate
3521 and then Is_Atomic_Aggregate (Expression (Parent (E)), Etype (E))
3526 -- For a subprogram, freeze all parameter types and also the return
3527 -- type (RM 13.14(14)). However skip this for internal subprograms.
3528 -- This is also the point where any extra formal parameters are
3529 -- created since we now know whether the subprogram will use a
3530 -- foreign convention.
3532 if Is_Subprogram (E) then
3533 if not Is_Internal (E) then
3537 Warn_Node : Node_Id;
3540 -- Loop through formals
3542 Formal := First_Formal (E);
3543 while Present (Formal) loop
3544 F_Type := Etype (Formal);
3546 -- AI05-0151 : incomplete types can appear in a profile.
3547 -- By the time the entity is frozen, the full view must
3548 -- be available, unless it is a limited view.
3550 if Is_Incomplete_Type (F_Type)
3551 and then Present (Full_View (F_Type))
3552 and then not From_Limited_With (F_Type)
3554 F_Type := Full_View (F_Type);
3555 Set_Etype (Formal, F_Type);
3558 Freeze_And_Append (F_Type, N, Result);
3560 if Is_Private_Type (F_Type)
3561 and then Is_Private_Type (Base_Type (F_Type))
3562 and then No (Full_View (Base_Type (F_Type)))
3563 and then not Is_Generic_Type (F_Type)
3564 and then not Is_Derived_Type (F_Type)
3566 -- If the type of a formal is incomplete, subprogram
3567 -- is being frozen prematurely. Within an instance
3568 -- (but not within a wrapper package) this is an
3569 -- artifact of our need to regard the end of an
3570 -- instantiation as a freeze point. Otherwise it is
3571 -- a definite error.
3574 Set_Is_Frozen (E, False);
3577 elsif not After_Last_Declaration
3578 and then not Freezing_Library_Level_Tagged_Type
3580 Error_Msg_Node_1 := F_Type;
3582 ("type& must be fully defined before this point",
3587 -- Check suspicious parameter for C function. These tests
3588 -- apply only to exported/imported subprograms.
3590 if Warn_On_Export_Import
3591 and then Comes_From_Source (E)
3592 and then (Convention (E) = Convention_C
3594 Convention (E) = Convention_CPP)
3595 and then (Is_Imported (E) or else Is_Exported (E))
3596 and then Convention (E) /= Convention (Formal)
3597 and then not Has_Warnings_Off (E)
3598 and then not Has_Warnings_Off (F_Type)
3599 and then not Has_Warnings_Off (Formal)
3601 -- Qualify mention of formals with subprogram name
3603 Error_Msg_Qual_Level := 1;
3605 -- Check suspicious use of fat C pointer
3607 if Is_Access_Type (F_Type)
3608 and then Esize (F_Type) > Ttypes.System_Address_Size
3611 ("?x?type of & does not correspond to C pointer!",
3614 -- Check suspicious return of boolean
3616 elsif Root_Type (F_Type) = Standard_Boolean
3617 and then Convention (F_Type) = Convention_Ada
3618 and then not Has_Warnings_Off (F_Type)
3619 and then not Has_Size_Clause (F_Type)
3620 and then VM_Target = No_VM
3623 ("& is an 8-bit Ada Boolean?x?", Formal);
3625 ("\use appropriate corresponding type in C "
3626 & "(e.g. char)?x?", Formal);
3628 -- Check suspicious tagged type
3630 elsif (Is_Tagged_Type (F_Type)
3631 or else (Is_Access_Type (F_Type)
3634 (Designated_Type (F_Type))))
3635 and then Convention (E) = Convention_C
3638 ("?x?& involves a tagged type which does not "
3639 & "correspond to any C type!", Formal);
3641 -- Check wrong convention subprogram pointer
3643 elsif Ekind (F_Type) = E_Access_Subprogram_Type
3644 and then not Has_Foreign_Convention (F_Type)
3647 ("?x?subprogram pointer & should "
3648 & "have foreign convention!", Formal);
3649 Error_Msg_Sloc := Sloc (F_Type);
3651 ("\?x?add Convention pragma to declaration of &#",
3655 -- Turn off name qualification after message output
3657 Error_Msg_Qual_Level := 0;
3660 -- Check for unconstrained array in exported foreign
3663 if Has_Foreign_Convention (E)
3664 and then not Is_Imported (E)
3665 and then Is_Array_Type (F_Type)
3666 and then not Is_Constrained (F_Type)
3667 and then Warn_On_Export_Import
3669 -- Exclude VM case, since both .NET and JVM can handle
3670 -- unconstrained arrays without a problem.
3672 and then VM_Target = No_VM
3674 Error_Msg_Qual_Level := 1;
3676 -- If this is an inherited operation, place the
3677 -- warning on the derived type declaration, rather
3678 -- than on the original subprogram.
3680 if Nkind (Original_Node (Parent (E))) =
3681 N_Full_Type_Declaration
3683 Warn_Node := Parent (E);
3685 if Formal = First_Formal (E) then
3687 ("??in inherited operation&", Warn_Node, E);
3690 Warn_Node := Formal;
3694 ("?x?type of argument& is unconstrained array",
3697 ("?x?foreign caller must pass bounds explicitly",
3699 Error_Msg_Qual_Level := 0;
3702 if not From_Limited_With (F_Type) then
3703 if Is_Access_Type (F_Type) then
3704 F_Type := Designated_Type (F_Type);
3707 -- If the formal is an anonymous_access_to_subprogram
3708 -- freeze the subprogram type as well, to prevent
3709 -- scope anomalies in gigi, because there is no other
3710 -- clear point at which it could be frozen.
3712 if Is_Itype (Etype (Formal))
3713 and then Ekind (F_Type) = E_Subprogram_Type
3715 Freeze_And_Append (F_Type, N, Result);
3719 Next_Formal (Formal);
3722 -- Case of function: similar checks on return type
3724 if Ekind (E) = E_Function then
3726 -- Freeze return type
3728 R_Type := Etype (E);
3730 -- AI05-0151: the return type may have been incomplete
3731 -- at the point of declaration. Replace it with the full
3732 -- view, unless the current type is a limited view. In
3733 -- that case the full view is in a different unit, and
3734 -- gigi finds the non-limited view after the other unit
3737 if Ekind (R_Type) = E_Incomplete_Type
3738 and then Present (Full_View (R_Type))
3739 and then not From_Limited_With (R_Type)
3741 R_Type := Full_View (R_Type);
3742 Set_Etype (E, R_Type);
3745 Freeze_And_Append (R_Type, N, Result);
3747 -- Check suspicious return type for C function
3749 if Warn_On_Export_Import
3750 and then (Convention (E) = Convention_C
3752 Convention (E) = Convention_CPP)
3753 and then (Is_Imported (E) or else Is_Exported (E))
3755 -- Check suspicious return of fat C pointer
3757 if Is_Access_Type (R_Type)
3758 and then Esize (R_Type) > Ttypes.System_Address_Size
3759 and then not Has_Warnings_Off (E)
3760 and then not Has_Warnings_Off (R_Type)
3763 ("?x?return type of& does not "
3764 & "correspond to C pointer!", E);
3766 -- Check suspicious return of boolean
3768 elsif Root_Type (R_Type) = Standard_Boolean
3769 and then Convention (R_Type) = Convention_Ada
3770 and then VM_Target = No_VM
3771 and then not Has_Warnings_Off (E)
3772 and then not Has_Warnings_Off (R_Type)
3773 and then not Has_Size_Clause (R_Type)
3776 N : constant Node_Id :=
3777 Result_Definition (Declaration_Node (E));
3780 ("return type of & is an 8-bit Ada Boolean?x?",
3783 ("\use appropriate corresponding type in C "
3784 & "(e.g. char)?x?", N, E);
3787 -- Check suspicious return tagged type
3789 elsif (Is_Tagged_Type (R_Type)
3790 or else (Is_Access_Type (R_Type)
3793 (Designated_Type (R_Type))))
3794 and then Convention (E) = Convention_C
3795 and then not Has_Warnings_Off (E)
3796 and then not Has_Warnings_Off (R_Type)
3799 ("?x?return type of & does not "
3800 & "correspond to C type!", E);
3802 -- Check return of wrong convention subprogram pointer
3804 elsif Ekind (R_Type) = E_Access_Subprogram_Type
3805 and then not Has_Foreign_Convention (R_Type)
3806 and then not Has_Warnings_Off (E)
3807 and then not Has_Warnings_Off (R_Type)
3810 ("?x?& should return a foreign "
3811 & "convention subprogram pointer", E);
3812 Error_Msg_Sloc := Sloc (R_Type);
3814 ("\?x?add Convention pragma to declaration of& #",
3819 -- Give warning for suspicious return of a result of an
3820 -- unconstrained array type in a foreign convention
3823 if Has_Foreign_Convention (E)
3825 -- We are looking for a return of unconstrained array
3827 and then Is_Array_Type (R_Type)
3828 and then not Is_Constrained (R_Type)
3830 -- Exclude imported routines, the warning does not
3831 -- belong on the import, but rather on the routine
3834 and then not Is_Imported (E)
3836 -- Exclude VM case, since both .NET and JVM can handle
3837 -- return of unconstrained arrays without a problem.
3839 and then VM_Target = No_VM
3841 -- Check that general warning is enabled, and that it
3842 -- is not suppressed for this particular case.
3844 and then Warn_On_Export_Import
3845 and then not Has_Warnings_Off (E)
3846 and then not Has_Warnings_Off (R_Type)
3849 ("?x?foreign convention function& should not " &
3850 "return unconstrained array!", E);
3855 -- Pre/post conditions are implemented through a subprogram in
3856 -- the corresponding body, and therefore are not checked on an
3857 -- imported subprogram for which the body is not available.
3859 -- Could consider generating a wrapper to take care of this???
3861 if Is_Subprogram (E)
3862 and then Is_Imported (E)
3863 and then Present (Contract (E))
3864 and then Present (Pre_Post_Conditions (Contract (E)))
3867 ("pre/post conditions on imported subprogram are not "
3868 & "enforced??", E, Pre_Post_Conditions (Contract (E)));
3873 -- Must freeze its parent first if it is a derived subprogram
3875 if Present (Alias (E)) then
3876 Freeze_And_Append (Alias (E), N, Result);
3879 -- We don't freeze internal subprograms, because we don't normally
3880 -- want addition of extra formals or mechanism setting to happen
3881 -- for those. However we do pass through predefined dispatching
3882 -- cases, since extra formals may be needed in some cases, such as
3883 -- for the stream 'Input function (build-in-place formals).
3885 if not Is_Internal (E)
3886 or else Is_Predefined_Dispatching_Operation (E)
3888 Freeze_Subprogram (E);
3891 -- Here for other than a subprogram or type
3894 -- If entity has a type, and it is not a generic unit, then
3895 -- freeze it first (RM 13.14(10)).
3897 if Present (Etype (E))
3898 and then Ekind (E) /= E_Generic_Function
3900 Freeze_And_Append (Etype (E), N, Result);
3903 -- Special processing for objects created by object declaration
3905 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
3907 -- Abstract type allowed only for C++ imported variables or
3910 -- Note: we inhibit this check for objects that do not come
3911 -- from source because there is at least one case (the
3912 -- expansion of x'Class'Input where x is abstract) where we
3913 -- legitimately generate an abstract object.
3915 if Is_Abstract_Type (Etype (E))
3916 and then Comes_From_Source (Parent (E))
3917 and then not (Is_Imported (E)
3918 and then Is_CPP_Class (Etype (E)))
3920 Error_Msg_N ("type of object cannot be abstract",
3921 Object_Definition (Parent (E)));
3923 if Is_CPP_Class (Etype (E)) then
3925 ("\} may need a cpp_constructor",
3926 Object_Definition (Parent (E)), Etype (E));
3930 -- For object created by object declaration, perform required
3931 -- categorization (preelaborate and pure) checks. Defer these
3932 -- checks to freeze time since pragma Import inhibits default
3933 -- initialization and thus pragma Import affects these checks.
3935 Validate_Object_Declaration (Declaration_Node (E));
3937 -- If there is an address clause, check that it is valid
3939 Check_Address_Clause (E);
3941 -- Reset Is_True_Constant for aliased object. We consider that
3942 -- the fact that something is aliased may indicate that some
3943 -- funny business is going on, e.g. an aliased object is passed
3944 -- by reference to a procedure which captures the address of
3945 -- the object, which is later used to assign a new value. Such
3946 -- code is highly dubious, but we choose to make it "work" for
3949 -- However, we don't do that for internal entities. We figure
3950 -- that if we deliberately set Is_True_Constant for an internal
3951 -- entity, e.g. a dispatch table entry, then we mean it!
3953 if (Is_Aliased (E) or else Is_Aliased (Etype (E)))
3954 and then not Is_Internal_Name (Chars (E))
3956 Set_Is_True_Constant (E, False);
3959 -- If the object needs any kind of default initialization, an
3960 -- error must be issued if No_Default_Initialization applies.
3961 -- The check doesn't apply to imported objects, which are not
3962 -- ever default initialized, and is why the check is deferred
3963 -- until freezing, at which point we know if Import applies.
3964 -- Deferred constants are also exempted from this test because
3965 -- their completion is explicit, or through an import pragma.
3967 if Ekind (E) = E_Constant
3968 and then Present (Full_View (E))
3972 elsif Comes_From_Source (E)
3973 and then not Is_Imported (E)
3974 and then not Has_Init_Expression (Declaration_Node (E))
3976 ((Has_Non_Null_Base_Init_Proc (Etype (E))
3977 and then not No_Initialization (Declaration_Node (E))
3978 and then not Is_Value_Type (Etype (E))
3979 and then not Initialization_Suppressed (Etype (E)))
3981 (Needs_Simple_Initialization (Etype (E))
3982 and then not Is_Internal (E)))
3984 Has_Default_Initialization := True;
3986 (No_Default_Initialization, Declaration_Node (E));
3989 -- Check that a Thread_Local_Storage variable does not have
3990 -- default initialization, and any explicit initialization must
3991 -- either be the null constant or a static constant.
3993 if Has_Pragma_Thread_Local_Storage (E) then
3995 Decl : constant Node_Id := Declaration_Node (E);
3997 if Has_Default_Initialization
3999 (Has_Init_Expression (Decl)
4001 (No (Expression (Decl))
4003 (Is_Static_Expression (Expression (Decl))
4005 Nkind (Expression (Decl)) = N_Null)))
4008 ("Thread_Local_Storage variable& is "
4009 & "improperly initialized", Decl, E);
4011 ("\only allowed initialization is explicit "
4012 & "NULL or static expression", Decl, E);
4017 -- For imported objects, set Is_Public unless there is also an
4018 -- address clause, which means that there is no external symbol
4019 -- needed for the Import (Is_Public may still be set for other
4020 -- unrelated reasons). Note that we delayed this processing
4021 -- till freeze time so that we can be sure not to set the flag
4022 -- if there is an address clause. If there is such a clause,
4023 -- then the only purpose of the Import pragma is to suppress
4024 -- implicit initialization.
4026 if Is_Imported (E) and then No (Address_Clause (E)) then
4030 -- For convention C objects of an enumeration type, warn if
4031 -- the size is not integer size and no explicit size given.
4032 -- Skip warning for Boolean, and Character, assume programmer
4033 -- expects 8-bit sizes for these cases.
4035 if (Convention (E) = Convention_C
4037 Convention (E) = Convention_CPP)
4038 and then Is_Enumeration_Type (Etype (E))
4039 and then not Is_Character_Type (Etype (E))
4040 and then not Is_Boolean_Type (Etype (E))
4041 and then Esize (Etype (E)) < Standard_Integer_Size
4042 and then not Has_Size_Clause (E)
4044 Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size);
4046 ("??convention C enumeration object has size less than ^",
4048 Error_Msg_N ("\?use explicit size clause to set size", E);
4052 -- Check that a constant which has a pragma Volatile[_Components]
4053 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4055 -- Note: Atomic[_Components] also sets Volatile[_Components]
4057 if Ekind (E) = E_Constant
4058 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
4059 and then not Is_Imported (E)
4061 -- Make sure we actually have a pragma, and have not merely
4062 -- inherited the indication from elsewhere (e.g. an address
4063 -- clause, which is not good enough in RM terms!)
4065 if Has_Rep_Pragma (E, Name_Atomic)
4067 Has_Rep_Pragma (E, Name_Atomic_Components)
4070 ("stand alone atomic constant must be " &
4071 "imported (RM C.6(13))", E);
4073 elsif Has_Rep_Pragma (E, Name_Volatile)
4075 Has_Rep_Pragma (E, Name_Volatile_Components)
4078 ("stand alone volatile constant must be " &
4079 "imported (RM C.6(13))", E);
4083 -- Static objects require special handling
4085 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4086 and then Is_Statically_Allocated (E)
4088 Freeze_Static_Object (E);
4091 -- Remaining step is to layout objects
4093 if Ekind (E) = E_Variable
4095 Ekind (E) = E_Constant
4097 Ekind (E) = E_Loop_Parameter
4104 -- If initialization statements were captured in an expression
4105 -- with actions with null expression, and the object does not
4106 -- have delayed freezing, move them back now directly within the
4107 -- enclosing statement sequence.
4109 if Ekind_In (E, E_Constant, E_Variable)
4110 and then not Has_Delayed_Freeze (E)
4113 Init_Stmts : constant Node_Id :=
4114 Initialization_Statements (E);
4116 if Present (Init_Stmts)
4117 and then Nkind (Init_Stmts) = N_Expression_With_Actions
4118 and then Nkind (Expression (Init_Stmts)) = N_Null_Statement
4120 Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
4122 -- Note that we rewrite Init_Stmts into a NULL statement,
4123 -- rather than just removing it, because Freeze_All may
4124 -- depend on this particular Node_Id still being present
4125 -- in the enclosing list to signal where to stop
4128 Rewrite (Init_Stmts,
4129 Make_Null_Statement (Sloc (Init_Stmts)));
4131 Set_Initialization_Statements (E, Empty);
4137 -- Case of a type or subtype being frozen
4140 -- We used to check here that a full type must have preelaborable
4141 -- initialization if it completes a private type specified with
4142 -- pragma Preelaborable_Initialization, but that missed cases where
4143 -- the types occur within a generic package, since the freezing
4144 -- that occurs within a containing scope generally skips traversal
4145 -- of a generic unit's declarations (those will be frozen within
4146 -- instances). This check was moved to Analyze_Package_Specification.
4148 -- The type may be defined in a generic unit. This can occur when
4149 -- freezing a generic function that returns the type (which is
4150 -- defined in a parent unit). It is clearly meaningless to freeze
4151 -- this type. However, if it is a subtype, its size may be determi-
4152 -- nable and used in subsequent checks, so might as well try to
4155 -- In Ada 2012, Freeze_Entities is also used in the front end to
4156 -- trigger the analysis of aspect expressions, so in this case we
4157 -- want to continue the freezing process.
4159 if Present (Scope (E))
4160 and then Is_Generic_Unit (Scope (E))
4162 (not Has_Predicates (E)
4163 and then not Has_Delayed_Freeze (E))
4165 Check_Compile_Time_Size (E);
4169 -- Deal with special cases of freezing for subtype
4171 if E /= Base_Type (E) then
4173 -- Before we do anything else, a specialized test for the case of
4174 -- a size given for an array where the array needs to be packed,
4175 -- but was not so the size cannot be honored. This is the case
4176 -- where implicit packing may apply. The reason we do this so
4177 -- early is that if we have implicit packing, the layout of the
4178 -- base type is affected, so we must do this before we freeze
4181 -- We could do this processing only if implicit packing is enabled
4182 -- since in all other cases, the error would be caught by the back
4183 -- end. However, we choose to do the check even if we do not have
4184 -- implicit packing enabled, since this allows us to give a more
4185 -- useful error message (advising use of pragmas Implicit_Packing
4188 if Is_Array_Type (E) then
4190 Ctyp : constant Entity_Id := Component_Type (E);
4191 Rsiz : constant Uint := RM_Size (Ctyp);
4192 SZ : constant Node_Id := Size_Clause (E);
4193 Btyp : constant Entity_Id := Base_Type (E);
4200 -- Number of elements in array
4203 -- Check enabling conditions. These are straightforward
4204 -- except for the test for a limited composite type. This
4205 -- eliminates the rare case of a array of limited components
4206 -- where there are issues of whether or not we can go ahead
4207 -- and pack the array (since we can't freely pack and unpack
4208 -- arrays if they are limited).
4210 -- Note that we check the root type explicitly because the
4211 -- whole point is we are doing this test before we have had
4212 -- a chance to freeze the base type (and it is that freeze
4213 -- action that causes stuff to be inherited).
4215 if Has_Size_Clause (E)
4216 and then Known_Static_RM_Size (E)
4217 and then not Is_Packed (E)
4218 and then not Has_Pragma_Pack (E)
4219 and then not Has_Component_Size_Clause (E)
4220 and then Known_Static_RM_Size (Ctyp)
4221 and then RM_Size (Ctyp) < 64
4222 and then not Is_Limited_Composite (E)
4223 and then not Is_Packed (Root_Type (E))
4224 and then not Has_Component_Size_Clause (Root_Type (E))
4225 and then not (CodePeer_Mode or SPARK_Mode)
4227 -- Compute number of elements in array
4229 Num_Elmts := Uint_1;
4230 Indx := First_Index (E);
4231 while Present (Indx) loop
4232 Get_Index_Bounds (Indx, Lo, Hi);
4234 if not (Compile_Time_Known_Value (Lo)
4236 Compile_Time_Known_Value (Hi))
4238 goto No_Implicit_Packing;
4244 Expr_Value (Hi) - Expr_Value (Lo) + 1);
4248 -- What we are looking for here is the situation where
4249 -- the RM_Size given would be exactly right if there was
4250 -- a pragma Pack (resulting in the component size being
4251 -- the same as the RM_Size). Furthermore, the component
4252 -- type size must be an odd size (not a multiple of
4253 -- storage unit). If the component RM size is an exact
4254 -- number of storage units that is a power of two, the
4255 -- array is not packed and has a standard representation.
4257 if RM_Size (E) = Num_Elmts * Rsiz
4258 and then Rsiz mod System_Storage_Unit /= 0
4260 -- For implicit packing mode, just set the component
4263 if Implicit_Packing then
4264 Set_Component_Size (Btyp, Rsiz);
4265 Set_Is_Bit_Packed_Array (Btyp);
4266 Set_Is_Packed (Btyp);
4267 Set_Has_Non_Standard_Rep (Btyp);
4269 -- Otherwise give an error message
4273 ("size given for& too small", SZ, E);
4274 Error_Msg_N -- CODEFIX
4275 ("\use explicit pragma Pack "
4276 & "or use pragma Implicit_Packing", SZ);
4279 elsif RM_Size (E) = Num_Elmts * Rsiz
4280 and then Implicit_Packing
4282 (Rsiz / System_Storage_Unit = 1
4284 Rsiz / System_Storage_Unit = 2
4286 Rsiz / System_Storage_Unit = 4)
4288 -- Not a packed array, but indicate the desired
4289 -- component size, for the back-end.
4291 Set_Component_Size (Btyp, Rsiz);
4297 <<No_Implicit_Packing>>
4299 -- If ancestor subtype present, freeze that first. Note that this
4300 -- will also get the base type frozen. Need RM reference ???
4302 Atype := Ancestor_Subtype (E);
4304 if Present (Atype) then
4305 Freeze_And_Append (Atype, N, Result);
4307 -- No ancestor subtype present
4310 -- See if we have a nearest ancestor that has a predicate.
4311 -- That catches the case of derived type with a predicate.
4312 -- Need RM reference here ???
4314 Atype := Nearest_Ancestor (E);
4316 if Present (Atype) and then Has_Predicates (Atype) then
4317 Freeze_And_Append (Atype, N, Result);
4320 -- Freeze base type before freezing the entity (RM 13.14(15))
4322 if E /= Base_Type (E) then
4323 Freeze_And_Append (Base_Type (E), N, Result);
4327 -- A subtype inherits all the type-related representation aspects
4328 -- from its parents (RM 13.1(8)).
4330 Inherit_Aspects_At_Freeze_Point (E);
4332 -- For a derived type, freeze its parent type first (RM 13.14(15))
4334 elsif Is_Derived_Type (E) then
4335 Freeze_And_Append (Etype (E), N, Result);
4336 Freeze_And_Append (First_Subtype (Etype (E)), N, Result);
4338 -- A derived type inherits each type-related representation aspect
4339 -- of its parent type that was directly specified before the
4340 -- declaration of the derived type (RM 13.1(15)).
4342 Inherit_Aspects_At_Freeze_Point (E);
4347 if Is_Array_Type (E) then
4348 Freeze_Array_Type (E);
4350 -- For a class-wide type, the corresponding specific type is
4351 -- frozen as well (RM 13.14(15))
4353 elsif Is_Class_Wide_Type (E) then
4354 Freeze_And_Append (Root_Type (E), N, Result);
4356 -- If the base type of the class-wide type is still incomplete,
4357 -- the class-wide remains unfrozen as well. This is legal when
4358 -- E is the formal of a primitive operation of some other type
4359 -- which is being frozen.
4361 if not Is_Frozen (Root_Type (E)) then
4362 Set_Is_Frozen (E, False);
4366 -- The equivalent type associated with a class-wide subtype needs
4367 -- to be frozen to ensure that its layout is done.
4369 if Ekind (E) = E_Class_Wide_Subtype
4370 and then Present (Equivalent_Type (E))
4372 Freeze_And_Append (Equivalent_Type (E), N, Result);
4375 -- Generate an itype reference for a library-level class-wide type
4376 -- at the freeze point. Otherwise the first explicit reference to
4377 -- the type may appear in an inner scope which will be rejected by
4381 and then Is_Compilation_Unit (Scope (E))
4384 Ref : constant Node_Id := Make_Itype_Reference (Loc);
4389 -- From a gigi point of view, a class-wide subtype derives
4390 -- from its record equivalent type. As a result, the itype
4391 -- reference must appear after the freeze node of the
4392 -- equivalent type or gigi will reject the reference.
4394 if Ekind (E) = E_Class_Wide_Subtype
4395 and then Present (Equivalent_Type (E))
4397 Insert_After (Freeze_Node (Equivalent_Type (E)), Ref);
4399 Add_To_Result (Ref);
4404 -- For a record type or record subtype, freeze all component types
4405 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4406 -- using Is_Record_Type, because we don't want to attempt the freeze
4407 -- for the case of a private type with record extension (we will do
4408 -- that later when the full type is frozen).
4410 elsif Ekind_In (E, E_Record_Type, E_Record_Subtype)
4411 and then not Is_Generic_Unit (Scope (E))
4413 Freeze_Record_Type (E);
4415 -- For a concurrent type, freeze corresponding record type. This
4416 -- does not correspond to any specific rule in the RM, but the
4417 -- record type is essentially part of the concurrent type.
4418 -- Freeze as well all local entities. This includes record types
4419 -- created for entry parameter blocks, and whatever local entities
4420 -- may appear in the private part.
4422 elsif Is_Concurrent_Type (E) then
4423 if Present (Corresponding_Record_Type (E)) then
4425 (Corresponding_Record_Type (E), N, Result);
4428 Comp := First_Entity (E);
4429 while Present (Comp) loop
4430 if Is_Type (Comp) then
4431 Freeze_And_Append (Comp, N, Result);
4433 elsif (Ekind (Comp)) /= E_Function then
4434 if Is_Itype (Etype (Comp))
4435 and then Underlying_Type (Scope (Etype (Comp))) = E
4437 Undelay_Type (Etype (Comp));
4440 Freeze_And_Append (Etype (Comp), N, Result);
4446 -- Private types are required to point to the same freeze node as
4447 -- their corresponding full views. The freeze node itself has to
4448 -- point to the partial view of the entity (because from the partial
4449 -- view, we can retrieve the full view, but not the reverse).
4450 -- However, in order to freeze correctly, we need to freeze the full
4451 -- view. If we are freezing at the end of a scope (or within the
4452 -- scope of the private type), the partial and full views will have
4453 -- been swapped, the full view appears first in the entity chain and
4454 -- the swapping mechanism ensures that the pointers are properly set
4457 -- If we encounter the partial view before the full view (e.g. when
4458 -- freezing from another scope), we freeze the full view, and then
4459 -- set the pointers appropriately since we cannot rely on swapping to
4460 -- fix things up (subtypes in an outer scope might not get swapped).
4462 elsif Is_Incomplete_Or_Private_Type (E)
4463 and then not Is_Generic_Type (E)
4465 -- The construction of the dispatch table associated with library
4466 -- level tagged types forces freezing of all the primitives of the
4467 -- type, which may cause premature freezing of the partial view.
4471 -- type T is tagged private;
4472 -- type DT is new T with private;
4473 -- procedure Prim (X : in out T; Y : in out DT'Class);
4475 -- type T is tagged null record;
4477 -- type DT is new T with null record;
4480 -- In this case the type will be frozen later by the usual
4481 -- mechanism: an object declaration, an instantiation, or the
4482 -- end of a declarative part.
4484 if Is_Library_Level_Tagged_Type (E)
4485 and then not Present (Full_View (E))
4487 Set_Is_Frozen (E, False);
4490 -- Case of full view present
4492 elsif Present (Full_View (E)) then
4494 -- If full view has already been frozen, then no further
4495 -- processing is required
4497 if Is_Frozen (Full_View (E)) then
4498 Set_Has_Delayed_Freeze (E, False);
4499 Set_Freeze_Node (E, Empty);
4500 Check_Debug_Info_Needed (E);
4502 -- Otherwise freeze full view and patch the pointers so that
4503 -- the freeze node will elaborate both views in the back-end.
4507 Full : constant Entity_Id := Full_View (E);
4510 if Is_Private_Type (Full)
4511 and then Present (Underlying_Full_View (Full))
4514 (Underlying_Full_View (Full), N, Result);
4517 Freeze_And_Append (Full, N, Result);
4519 if Has_Delayed_Freeze (E) then
4520 F_Node := Freeze_Node (Full);
4522 if Present (F_Node) then
4523 Set_Freeze_Node (E, F_Node);
4524 Set_Entity (F_Node, E);
4527 -- {Incomplete,Private}_Subtypes with Full_Views
4528 -- constrained by discriminants.
4530 Set_Has_Delayed_Freeze (E, False);
4531 Set_Freeze_Node (E, Empty);
4536 Check_Debug_Info_Needed (E);
4539 -- AI-117 requires that the convention of a partial view be the
4540 -- same as the convention of the full view. Note that this is a
4541 -- recognized breach of privacy, but it's essential for logical
4542 -- consistency of representation, and the lack of a rule in
4543 -- RM95 was an oversight.
4545 Set_Convention (E, Convention (Full_View (E)));
4547 Set_Size_Known_At_Compile_Time (E,
4548 Size_Known_At_Compile_Time (Full_View (E)));
4550 -- Size information is copied from the full view to the
4551 -- incomplete or private view for consistency.
4553 -- We skip this is the full view is not a type. This is very
4554 -- strange of course, and can only happen as a result of
4555 -- certain illegalities, such as a premature attempt to derive
4556 -- from an incomplete type.
4558 if Is_Type (Full_View (E)) then
4559 Set_Size_Info (E, Full_View (E));
4560 Set_RM_Size (E, RM_Size (Full_View (E)));
4565 -- Case of no full view present. If entity is derived or subtype,
4566 -- it is safe to freeze, correctness depends on the frozen status
4567 -- of parent. Otherwise it is either premature usage, or a Taft
4568 -- amendment type, so diagnosis is at the point of use and the
4569 -- type might be frozen later.
4571 elsif E /= Base_Type (E)
4572 or else Is_Derived_Type (E)
4577 Set_Is_Frozen (E, False);
4581 -- For access subprogram, freeze types of all formals, the return
4582 -- type was already frozen, since it is the Etype of the function.
4583 -- Formal types can be tagged Taft amendment types, but otherwise
4584 -- they cannot be incomplete.
4586 elsif Ekind (E) = E_Subprogram_Type then
4587 Formal := First_Formal (E);
4588 while Present (Formal) loop
4589 if Ekind (Etype (Formal)) = E_Incomplete_Type
4590 and then No (Full_View (Etype (Formal)))
4591 and then not Is_Value_Type (Etype (Formal))
4593 if Is_Tagged_Type (Etype (Formal)) then
4596 -- AI05-151: Incomplete types are allowed in access to
4597 -- subprogram specifications.
4599 elsif Ada_Version < Ada_2012 then
4601 ("invalid use of incomplete type&", E, Etype (Formal));
4605 Freeze_And_Append (Etype (Formal), N, Result);
4606 Next_Formal (Formal);
4609 Freeze_Subprogram (E);
4611 -- For access to a protected subprogram, freeze the equivalent type
4612 -- (however this is not set if we are not generating code or if this
4613 -- is an anonymous type used just for resolution).
4615 elsif Is_Access_Protected_Subprogram_Type (E) then
4616 if Present (Equivalent_Type (E)) then
4617 Freeze_And_Append (Equivalent_Type (E), N, Result);
4621 -- Generic types are never seen by the back-end, and are also not
4622 -- processed by the expander (since the expander is turned off for
4623 -- generic processing), so we never need freeze nodes for them.
4625 if Is_Generic_Type (E) then
4629 -- Some special processing for non-generic types to complete
4630 -- representation details not known till the freeze point.
4632 if Is_Fixed_Point_Type (E) then
4633 Freeze_Fixed_Point_Type (E);
4635 -- Some error checks required for ordinary fixed-point type. Defer
4636 -- these till the freeze-point since we need the small and range
4637 -- values. We only do these checks for base types
4639 if Is_Ordinary_Fixed_Point_Type (E) and then Is_Base_Type (E) then
4640 if Small_Value (E) < Ureal_2_M_80 then
4641 Error_Msg_Name_1 := Name_Small;
4643 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E);
4645 elsif Small_Value (E) > Ureal_2_80 then
4646 Error_Msg_Name_1 := Name_Small;
4648 ("`&''%` too large, maximum allowed is 2.0'*'*80", E);
4651 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
4652 Error_Msg_Name_1 := Name_First;
4654 ("`&''%` too small, minimum allowed is -10.0'*'*36", E);
4657 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
4658 Error_Msg_Name_1 := Name_Last;
4660 ("`&''%` too large, maximum allowed is 10.0'*'*36", E);
4664 elsif Is_Enumeration_Type (E) then
4665 Freeze_Enumeration_Type (E);
4667 elsif Is_Integer_Type (E) then
4668 Adjust_Esize_For_Alignment (E);
4670 if Is_Modular_Integer_Type (E)
4671 and then Warn_On_Suspicious_Modulus_Value
4673 Check_Suspicious_Modulus (E);
4676 elsif Is_Access_Type (E)
4677 and then not Is_Access_Subprogram_Type (E)
4679 -- If a pragma Default_Storage_Pool applies, and this type has no
4680 -- Storage_Pool or Storage_Size clause (which must have occurred
4681 -- before the freezing point), then use the default. This applies
4682 -- only to base types.
4684 -- None of this applies to access to subprograms, for which there
4685 -- are clearly no pools.
4687 if Present (Default_Pool)
4688 and then Is_Base_Type (E)
4689 and then not Has_Storage_Size_Clause (E)
4690 and then No (Associated_Storage_Pool (E))
4692 -- Case of pragma Default_Storage_Pool (null)
4694 if Nkind (Default_Pool) = N_Null then
4695 Set_No_Pool_Assigned (E);
4697 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4700 Set_Associated_Storage_Pool (E, Entity (Default_Pool));
4704 -- Check restriction for standard storage pool
4706 if No (Associated_Storage_Pool (E)) then
4707 Check_Restriction (No_Standard_Storage_Pools, E);
4710 -- Deal with error message for pure access type. This is not an
4711 -- error in Ada 2005 if there is no pool (see AI-366).
4713 if Is_Pure_Unit_Access_Type (E)
4714 and then (Ada_Version < Ada_2005
4715 or else not No_Pool_Assigned (E))
4716 and then not Is_Generic_Unit (Scope (E))
4718 Error_Msg_N ("named access type not allowed in pure unit", E);
4720 if Ada_Version >= Ada_2005 then
4722 ("\would be legal if Storage_Size of 0 given??", E);
4724 elsif No_Pool_Assigned (E) then
4726 ("\would be legal in Ada 2005??", E);
4730 ("\would be legal in Ada 2005 if "
4731 & "Storage_Size of 0 given??", E);
4736 -- Case of composite types
4738 if Is_Composite_Type (E) then
4740 -- AI-117 requires that all new primitives of a tagged type must
4741 -- inherit the convention of the full view of the type. Inherited
4742 -- and overriding operations are defined to inherit the convention
4743 -- of their parent or overridden subprogram (also specified in
4744 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4745 -- and New_Overloaded_Entity). Here we set the convention of
4746 -- primitives that are still convention Ada, which will ensure
4747 -- that any new primitives inherit the type's convention. Class-
4748 -- wide types can have a foreign convention inherited from their
4749 -- specific type, but are excluded from this since they don't have
4750 -- any associated primitives.
4752 if Is_Tagged_Type (E)
4753 and then not Is_Class_Wide_Type (E)
4754 and then Convention (E) /= Convention_Ada
4757 Prim_List : constant Elist_Id := Primitive_Operations (E);
4761 Prim := First_Elmt (Prim_List);
4762 while Present (Prim) loop
4763 if Convention (Node (Prim)) = Convention_Ada then
4764 Set_Convention (Node (Prim), Convention (E));
4772 -- If the type is a simple storage pool type, then this is where
4773 -- we attempt to locate and validate its Allocate, Deallocate, and
4774 -- Storage_Size operations (the first is required, and the latter
4775 -- two are optional). We also verify that the full type for a
4776 -- private type is allowed to be a simple storage pool type.
4778 if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type))
4779 and then (Is_Base_Type (E) or else Has_Private_Declaration (E))
4781 -- If the type is marked Has_Private_Declaration, then this is
4782 -- a full type for a private type that was specified with the
4783 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4784 -- pragma is allowed for the full type (for example, it can't
4785 -- be an array type, or a nonlimited record type).
4787 if Has_Private_Declaration (E) then
4788 if (not Is_Record_Type (E)
4789 or else not Is_Limited_View (E))
4790 and then not Is_Private_Type (E)
4792 Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type;
4794 ("pragma% can only apply to full type that is an " &
4795 "explicitly limited type", E);
4799 Validate_Simple_Pool_Ops : declare
4800 Pool_Type : Entity_Id renames E;
4801 Address_Type : constant Entity_Id := RTE (RE_Address);
4802 Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count);
4804 procedure Validate_Simple_Pool_Op_Formal
4805 (Pool_Op : Entity_Id;
4806 Pool_Op_Formal : in out Entity_Id;
4807 Expected_Mode : Formal_Kind;
4808 Expected_Type : Entity_Id;
4809 Formal_Name : String;
4810 OK_Formal : in out Boolean);
4811 -- Validate one formal Pool_Op_Formal of the candidate pool
4812 -- operation Pool_Op. The formal must be of Expected_Type
4813 -- and have mode Expected_Mode. OK_Formal will be set to
4814 -- False if the formal doesn't match. If OK_Formal is False
4815 -- on entry, then the formal will effectively be ignored
4816 -- (because validation of the pool op has already failed).
4817 -- Upon return, Pool_Op_Formal will be updated to the next
4820 procedure Validate_Simple_Pool_Operation (Op_Name : Name_Id);
4821 -- Search for and validate a simple pool operation with the
4822 -- name Op_Name. If the name is Allocate, then there must be
4823 -- exactly one such primitive operation for the simple pool
4824 -- type. If the name is Deallocate or Storage_Size, then
4825 -- there can be at most one such primitive operation. The
4826 -- profile of the located primitive must conform to what
4827 -- is expected for each operation.
4829 ------------------------------------
4830 -- Validate_Simple_Pool_Op_Formal --
4831 ------------------------------------
4833 procedure Validate_Simple_Pool_Op_Formal
4834 (Pool_Op : Entity_Id;
4835 Pool_Op_Formal : in out Entity_Id;
4836 Expected_Mode : Formal_Kind;
4837 Expected_Type : Entity_Id;
4838 Formal_Name : String;
4839 OK_Formal : in out Boolean)
4842 -- If OK_Formal is False on entry, then simply ignore
4843 -- the formal, because an earlier formal has already
4846 if not OK_Formal then
4849 -- If no formal is passed in, then issue an error for a
4852 elsif not Present (Pool_Op_Formal) then
4854 ("simple storage pool op missing formal " &
4855 Formal_Name & " of type&", Pool_Op, Expected_Type);
4861 if Etype (Pool_Op_Formal) /= Expected_Type then
4863 -- If the pool type was expected for this formal, then
4864 -- this will not be considered a candidate operation
4865 -- for the simple pool, so we unset OK_Formal so that
4866 -- the op and any later formals will be ignored.
4868 if Expected_Type = Pool_Type then
4875 ("wrong type for formal " & Formal_Name &
4876 " of simple storage pool op; expected type&",
4877 Pool_Op_Formal, Expected_Type);
4881 -- Issue error if formal's mode is not the expected one
4883 if Ekind (Pool_Op_Formal) /= Expected_Mode then
4885 ("wrong mode for formal of simple storage pool op",
4889 -- Advance to the next formal
4891 Next_Formal (Pool_Op_Formal);
4892 end Validate_Simple_Pool_Op_Formal;
4894 ------------------------------------
4895 -- Validate_Simple_Pool_Operation --
4896 ------------------------------------
4898 procedure Validate_Simple_Pool_Operation
4902 Found_Op : Entity_Id := Empty;
4908 (Nam_In (Op_Name, Name_Allocate,
4910 Name_Storage_Size));
4912 Error_Msg_Name_1 := Op_Name;
4914 -- For each homonym declared immediately in the scope
4915 -- of the simple storage pool type, determine whether
4916 -- the homonym is an operation of the pool type, and,
4917 -- if so, check that its profile is as expected for
4918 -- a simple pool operation of that name.
4920 Op := Get_Name_Entity_Id (Op_Name);
4921 while Present (Op) loop
4922 if Ekind_In (Op, E_Function, E_Procedure)
4923 and then Scope (Op) = Current_Scope
4925 Formal := First_Entity (Op);
4929 -- The first parameter must be of the pool type
4930 -- in order for the operation to qualify.
4932 if Op_Name = Name_Storage_Size then
4933 Validate_Simple_Pool_Op_Formal
4934 (Op, Formal, E_In_Parameter, Pool_Type,
4937 Validate_Simple_Pool_Op_Formal
4938 (Op, Formal, E_In_Out_Parameter, Pool_Type,
4942 -- If another operation with this name has already
4943 -- been located for the type, then flag an error,
4944 -- since we only allow the type to have a single
4947 if Present (Found_Op) and then Is_OK then
4949 ("only one % operation allowed for " &
4950 "simple storage pool type&", Op, Pool_Type);
4953 -- In the case of Allocate and Deallocate, a formal
4954 -- of type System.Address is required.
4956 if Op_Name = Name_Allocate then
4957 Validate_Simple_Pool_Op_Formal
4958 (Op, Formal, E_Out_Parameter,
4959 Address_Type, "Storage_Address", Is_OK);
4961 elsif Op_Name = Name_Deallocate then
4962 Validate_Simple_Pool_Op_Formal
4963 (Op, Formal, E_In_Parameter,
4964 Address_Type, "Storage_Address", Is_OK);
4967 -- In the case of Allocate and Deallocate, formals
4968 -- of type Storage_Count are required as the third
4969 -- and fourth parameters.
4971 if Op_Name /= Name_Storage_Size then
4972 Validate_Simple_Pool_Op_Formal
4973 (Op, Formal, E_In_Parameter,
4974 Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK);
4975 Validate_Simple_Pool_Op_Formal
4976 (Op, Formal, E_In_Parameter,
4977 Stg_Cnt_Type, "Alignment", Is_OK);
4980 -- If no mismatched formals have been found (Is_OK)
4981 -- and no excess formals are present, then this
4982 -- operation has been validated, so record it.
4984 if not Present (Formal) and then Is_OK then
4992 -- There must be a valid Allocate operation for the type,
4993 -- so issue an error if none was found.
4995 if Op_Name = Name_Allocate
4996 and then not Present (Found_Op)
4998 Error_Msg_N ("missing % operation for simple " &
4999 "storage pool type", Pool_Type);
5001 elsif Present (Found_Op) then
5003 -- Simple pool operations can't be abstract
5005 if Is_Abstract_Subprogram (Found_Op) then
5007 ("simple storage pool operation must not be " &
5008 "abstract", Found_Op);
5011 -- The Storage_Size operation must be a function with
5012 -- Storage_Count as its result type.
5014 if Op_Name = Name_Storage_Size then
5015 if Ekind (Found_Op) = E_Procedure then
5017 ("% operation must be a function", Found_Op);
5019 elsif Etype (Found_Op) /= Stg_Cnt_Type then
5021 ("wrong result type for%, expected type&",
5022 Found_Op, Stg_Cnt_Type);
5025 -- Allocate and Deallocate must be procedures
5027 elsif Ekind (Found_Op) = E_Function then
5029 ("% operation must be a procedure", Found_Op);
5032 end Validate_Simple_Pool_Operation;
5034 -- Start of processing for Validate_Simple_Pool_Ops
5037 Validate_Simple_Pool_Operation (Name_Allocate);
5038 Validate_Simple_Pool_Operation (Name_Deallocate);
5039 Validate_Simple_Pool_Operation (Name_Storage_Size);
5040 end Validate_Simple_Pool_Ops;
5044 -- Now that all types from which E may depend are frozen, see if the
5045 -- size is known at compile time, if it must be unsigned, or if
5046 -- strict alignment is required
5048 Check_Compile_Time_Size (E);
5049 Check_Unsigned_Type (E);
5051 if Base_Type (E) = E then
5052 Check_Strict_Alignment (E);
5055 -- Do not allow a size clause for a type which does not have a size
5056 -- that is known at compile time
5058 if Has_Size_Clause (E)
5059 and then not Size_Known_At_Compile_Time (E)
5061 -- Suppress this message if errors posted on E, even if we are
5062 -- in all errors mode, since this is often a junk message
5064 if not Error_Posted (E) then
5066 ("size clause not allowed for variable length type",
5071 -- Now we set/verify the representation information, in particular
5072 -- the size and alignment values. This processing is not required for
5073 -- generic types, since generic types do not play any part in code
5074 -- generation, and so the size and alignment values for such types
5075 -- are irrelevant. Ditto for types declared within a generic unit,
5076 -- which may have components that depend on generic parameters, and
5077 -- that will be recreated in an instance.
5079 if Inside_A_Generic then
5082 -- Otherwise we call the layout procedure
5088 -- If this is an access to subprogram whose designated type is itself
5089 -- a subprogram type, the return type of this anonymous subprogram
5090 -- type must be decorated as well.
5092 if Ekind (E) = E_Anonymous_Access_Subprogram_Type
5093 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
5095 Layout_Type (Etype (Designated_Type (E)));
5098 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5099 -- this is where we analye the expression (after the type is frozen,
5100 -- since in the case of Default_Value, we are analyzing with the
5101 -- type itself, and we treat Default_Component_Value similarly for
5102 -- the sake of uniformity).
5104 if Is_First_Subtype (E) and then Has_Default_Aspect (E) then
5111 if Is_Scalar_Type (E) then
5112 Nam := Name_Default_Value;
5114 Exp := Default_Aspect_Value (Typ);
5116 Nam := Name_Default_Component_Value;
5117 Typ := Component_Type (E);
5118 Exp := Default_Aspect_Component_Value (E);
5121 Analyze_And_Resolve (Exp, Typ);
5123 if Etype (Exp) /= Any_Type then
5124 if not Is_Static_Expression (Exp) then
5125 Error_Msg_Name_1 := Nam;
5126 Flag_Non_Static_Expr
5127 ("aspect% requires static expression", Exp);
5133 -- End of freeze processing for type entities
5136 -- Here is where we logically freeze the current entity. If it has a
5137 -- freeze node, then this is the point at which the freeze node is
5138 -- linked into the result list.
5140 if Has_Delayed_Freeze (E) then
5142 -- If a freeze node is already allocated, use it, otherwise allocate
5143 -- a new one. The preallocation happens in the case of anonymous base
5144 -- types, where we preallocate so that we can set First_Subtype_Link.
5145 -- Note that we reset the Sloc to the current freeze location.
5147 if Present (Freeze_Node (E)) then
5148 F_Node := Freeze_Node (E);
5149 Set_Sloc (F_Node, Loc);
5152 F_Node := New_Node (N_Freeze_Entity, Loc);
5153 Set_Freeze_Node (E, F_Node);
5154 Set_Access_Types_To_Process (F_Node, No_Elist);
5155 Set_TSS_Elist (F_Node, No_Elist);
5156 Set_Actions (F_Node, No_List);
5159 Set_Entity (F_Node, E);
5160 Add_To_Result (F_Node);
5162 -- A final pass over record types with discriminants. If the type
5163 -- has an incomplete declaration, there may be constrained access
5164 -- subtypes declared elsewhere, which do not depend on the discrimi-
5165 -- nants of the type, and which are used as component types (i.e.
5166 -- the full view is a recursive type). The designated types of these
5167 -- subtypes can only be elaborated after the type itself, and they
5168 -- need an itype reference.
5170 if Ekind (E) = E_Record_Type
5171 and then Has_Discriminants (E)
5179 Comp := First_Component (E);
5180 while Present (Comp) loop
5181 Typ := Etype (Comp);
5183 if Ekind (Comp) = E_Component
5184 and then Is_Access_Type (Typ)
5185 and then Scope (Typ) /= E
5186 and then Base_Type (Designated_Type (Typ)) = E
5187 and then Is_Itype (Designated_Type (Typ))
5189 IR := Make_Itype_Reference (Sloc (Comp));
5190 Set_Itype (IR, Designated_Type (Typ));
5191 Append (IR, Result);
5194 Next_Component (Comp);
5200 -- When a type is frozen, the first subtype of the type is frozen as
5201 -- well (RM 13.14(15)). This has to be done after freezing the type,
5202 -- since obviously the first subtype depends on its own base type.
5205 Freeze_And_Append (First_Subtype (E), N, Result);
5207 -- If we just froze a tagged non-class wide record, then freeze the
5208 -- corresponding class-wide type. This must be done after the tagged
5209 -- type itself is frozen, because the class-wide type refers to the
5210 -- tagged type which generates the class.
5212 if Is_Tagged_Type (E)
5213 and then not Is_Class_Wide_Type (E)
5214 and then Present (Class_Wide_Type (E))
5216 Freeze_And_Append (Class_Wide_Type (E), N, Result);
5220 Check_Debug_Info_Needed (E);
5222 -- Special handling for subprograms
5224 if Is_Subprogram (E) then
5226 -- If subprogram has address clause then reset Is_Public flag, since
5227 -- we do not want the backend to generate external references.
5229 if Present (Address_Clause (E))
5230 and then not Is_Library_Level_Entity (E)
5232 Set_Is_Public (E, False);
5239 -----------------------------
5240 -- Freeze_Enumeration_Type --
5241 -----------------------------
5243 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
5245 -- By default, if no size clause is present, an enumeration type with
5246 -- Convention C is assumed to interface to a C enum, and has integer
5247 -- size. This applies to types. For subtypes, verify that its base
5248 -- type has no size clause either. Treat other foreign conventions
5249 -- in the same way, and also make sure alignment is set right.
5251 if Has_Foreign_Convention (Typ)
5252 and then not Has_Size_Clause (Typ)
5253 and then not Has_Size_Clause (Base_Type (Typ))
5254 and then Esize (Typ) < Standard_Integer_Size
5256 Init_Esize (Typ, Standard_Integer_Size);
5257 Set_Alignment (Typ, Alignment (Standard_Integer));
5260 -- If the enumeration type interfaces to C, and it has a size clause
5261 -- that specifies less than int size, it warrants a warning. The
5262 -- user may intend the C type to be an enum or a char, so this is
5263 -- not by itself an error that the Ada compiler can detect, but it
5264 -- it is a worth a heads-up. For Boolean and Character types we
5265 -- assume that the programmer has the proper C type in mind.
5267 if Convention (Typ) = Convention_C
5268 and then Has_Size_Clause (Typ)
5269 and then Esize (Typ) /= Esize (Standard_Integer)
5270 and then not Is_Boolean_Type (Typ)
5271 and then not Is_Character_Type (Typ)
5274 ("C enum types have the size of a C int??", Size_Clause (Typ));
5277 Adjust_Esize_For_Alignment (Typ);
5279 end Freeze_Enumeration_Type;
5281 -----------------------
5282 -- Freeze_Expression --
5283 -----------------------
5285 procedure Freeze_Expression (N : Node_Id) is
5286 In_Spec_Exp : constant Boolean := In_Spec_Expression;
5289 Desig_Typ : Entity_Id;
5293 Freeze_Outside : Boolean := False;
5294 -- This flag is set true if the entity must be frozen outside the
5295 -- current subprogram. This happens in the case of expander generated
5296 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5297 -- not freeze all entities like other bodies, but which nevertheless
5298 -- may reference entities that have to be frozen before the body and
5299 -- obviously cannot be frozen inside the body.
5301 function In_Exp_Body (N : Node_Id) return Boolean;
5302 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5303 -- it is the handled statement sequence of an expander-generated
5304 -- subprogram (init proc, stream subprogram, or renaming as body).
5305 -- If so, this is not a freezing context.
5311 function In_Exp_Body (N : Node_Id) return Boolean is
5316 if Nkind (N) = N_Subprogram_Body then
5322 if Nkind (P) /= N_Subprogram_Body then
5326 Id := Defining_Unit_Name (Specification (P));
5328 -- Following complex conditional could use comments ???
5330 if Nkind (Id) = N_Defining_Identifier
5331 and then (Is_Init_Proc (Id)
5332 or else Is_TSS (Id, TSS_Stream_Input)
5333 or else Is_TSS (Id, TSS_Stream_Output)
5334 or else Is_TSS (Id, TSS_Stream_Read)
5335 or else Is_TSS (Id, TSS_Stream_Write)
5336 or else Nkind_In (Original_Node (P),
5337 N_Subprogram_Renaming_Declaration,
5338 N_Expression_Function))
5347 -- Start of processing for Freeze_Expression
5350 -- Immediate return if freezing is inhibited. This flag is set by the
5351 -- analyzer to stop freezing on generated expressions that would cause
5352 -- freezing if they were in the source program, but which are not
5353 -- supposed to freeze, since they are created.
5355 if Must_Not_Freeze (N) then
5359 -- If expression is non-static, then it does not freeze in a default
5360 -- expression, see section "Handling of Default Expressions" in the
5361 -- spec of package Sem for further details. Note that we have to make
5362 -- sure that we actually have a real expression (if we have a subtype
5363 -- indication, we can't test Is_Static_Expression!) However, we exclude
5364 -- the case of the prefix of an attribute of a static scalar subtype
5365 -- from this early return, because static subtype attributes should
5366 -- always cause freezing, even in default expressions, but the attribute
5367 -- may not have been marked as static yet (because in Resolve_Attribute,
5368 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5372 and then Nkind (N) in N_Subexpr
5373 and then not Is_Static_Expression (N)
5374 and then (Nkind (Parent (N)) /= N_Attribute_Reference
5375 or else not (Is_Entity_Name (N)
5376 and then Is_Type (Entity (N))
5377 and then Is_Static_Subtype (Entity (N))))
5382 -- Freeze type of expression if not frozen already
5386 if Nkind (N) in N_Has_Etype then
5387 if not Is_Frozen (Etype (N)) then
5390 -- Base type may be an derived numeric type that is frozen at
5391 -- the point of declaration, but first_subtype is still unfrozen.
5393 elsif not Is_Frozen (First_Subtype (Etype (N))) then
5394 Typ := First_Subtype (Etype (N));
5398 -- For entity name, freeze entity if not frozen already. A special
5399 -- exception occurs for an identifier that did not come from source.
5400 -- We don't let such identifiers freeze a non-internal entity, i.e.
5401 -- an entity that did come from source, since such an identifier was
5402 -- generated by the expander, and cannot have any semantic effect on
5403 -- the freezing semantics. For example, this stops the parameter of
5404 -- an initialization procedure from freezing the variable.
5406 if Is_Entity_Name (N)
5407 and then not Is_Frozen (Entity (N))
5408 and then (Nkind (N) /= N_Identifier
5409 or else Comes_From_Source (N)
5410 or else not Comes_From_Source (Entity (N)))
5417 -- For an allocator freeze designated type if not frozen already
5419 -- For an aggregate whose component type is an access type, freeze the
5420 -- designated type now, so that its freeze does not appear within the
5421 -- loop that might be created in the expansion of the aggregate. If the
5422 -- designated type is a private type without full view, the expression
5423 -- cannot contain an allocator, so the type is not frozen.
5425 -- For a function, we freeze the entity when the subprogram declaration
5426 -- is frozen, but a function call may appear in an initialization proc.
5427 -- before the declaration is frozen. We need to generate the extra
5428 -- formals, if any, to ensure that the expansion of the call includes
5429 -- the proper actuals. This only applies to Ada subprograms, not to
5436 Desig_Typ := Designated_Type (Etype (N));
5439 if Is_Array_Type (Etype (N))
5440 and then Is_Access_Type (Component_Type (Etype (N)))
5442 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
5445 when N_Selected_Component |
5446 N_Indexed_Component |
5449 if Is_Access_Type (Etype (Prefix (N))) then
5450 Desig_Typ := Designated_Type (Etype (Prefix (N)));
5453 when N_Identifier =>
5455 and then Ekind (Nam) = E_Function
5456 and then Nkind (Parent (N)) = N_Function_Call
5457 and then Convention (Nam) = Convention_Ada
5459 Create_Extra_Formals (Nam);
5466 if Desig_Typ /= Empty
5467 and then (Is_Frozen (Desig_Typ)
5468 or else (not Is_Fully_Defined (Desig_Typ)))
5473 -- All done if nothing needs freezing
5477 and then No (Desig_Typ)
5482 -- Loop for looking at the right place to insert the freeze nodes,
5483 -- exiting from the loop when it is appropriate to insert the freeze
5484 -- node before the current node P.
5486 -- Also checks some special exceptions to the freezing rules. These
5487 -- cases result in a direct return, bypassing the freeze action.
5491 Parent_P := Parent (P);
5493 -- If we don't have a parent, then we are not in a well-formed tree.
5494 -- This is an unusual case, but there are some legitimate situations
5495 -- in which this occurs, notably when the expressions in the range of
5496 -- a type declaration are resolved. We simply ignore the freeze
5497 -- request in this case. Is this right ???
5499 if No (Parent_P) then
5503 -- See if we have got to an appropriate point in the tree
5505 case Nkind (Parent_P) is
5507 -- A special test for the exception of (RM 13.14(8)) for the case
5508 -- of per-object expressions (RM 3.8(18)) occurring in component
5509 -- definition or a discrete subtype definition. Note that we test
5510 -- for a component declaration which includes both cases we are
5511 -- interested in, and furthermore the tree does not have explicit
5512 -- nodes for either of these two constructs.
5514 when N_Component_Declaration =>
5516 -- The case we want to test for here is an identifier that is
5517 -- a per-object expression, this is either a discriminant that
5518 -- appears in a context other than the component declaration
5519 -- or it is a reference to the type of the enclosing construct.
5521 -- For either of these cases, we skip the freezing
5523 if not In_Spec_Expression
5524 and then Nkind (N) = N_Identifier
5525 and then (Present (Entity (N)))
5527 -- We recognize the discriminant case by just looking for
5528 -- a reference to a discriminant. It can only be one for
5529 -- the enclosing construct. Skip freezing in this case.
5531 if Ekind (Entity (N)) = E_Discriminant then
5534 -- For the case of a reference to the enclosing record,
5535 -- (or task or protected type), we look for a type that
5536 -- matches the current scope.
5538 elsif Entity (N) = Current_Scope then
5543 -- If we have an enumeration literal that appears as the choice in
5544 -- the aggregate of an enumeration representation clause, then
5545 -- freezing does not occur (RM 13.14(10)).
5547 when N_Enumeration_Representation_Clause =>
5549 -- The case we are looking for is an enumeration literal
5551 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
5552 and then Is_Enumeration_Type (Etype (N))
5554 -- If enumeration literal appears directly as the choice,
5555 -- do not freeze (this is the normal non-overloaded case)
5557 if Nkind (Parent (N)) = N_Component_Association
5558 and then First (Choices (Parent (N))) = N
5562 -- If enumeration literal appears as the name of function
5563 -- which is the choice, then also do not freeze. This
5564 -- happens in the overloaded literal case, where the
5565 -- enumeration literal is temporarily changed to a function
5566 -- call for overloading analysis purposes.
5568 elsif Nkind (Parent (N)) = N_Function_Call
5570 Nkind (Parent (Parent (N))) = N_Component_Association
5572 First (Choices (Parent (Parent (N)))) = Parent (N)
5578 -- Normally if the parent is a handled sequence of statements,
5579 -- then the current node must be a statement, and that is an
5580 -- appropriate place to insert a freeze node.
5582 when N_Handled_Sequence_Of_Statements =>
5584 -- An exception occurs when the sequence of statements is for
5585 -- an expander generated body that did not do the usual freeze
5586 -- all operation. In this case we usually want to freeze
5587 -- outside this body, not inside it, and we skip past the
5588 -- subprogram body that we are inside.
5590 if In_Exp_Body (Parent_P) then
5592 Subp : constant Node_Id := Parent (Parent_P);
5596 -- Freeze the entity only when it is declared inside the
5597 -- body of the expander generated procedure. This case
5598 -- is recognized by the scope of the entity or its type,
5599 -- which is either the spec for some enclosing body, or
5600 -- (in the case of init_procs, for which there are no
5601 -- separate specs) the current scope.
5603 if Nkind (Subp) = N_Subprogram_Body then
5604 Spec := Corresponding_Spec (Subp);
5606 if (Present (Typ) and then Scope (Typ) = Spec)
5608 (Present (Nam) and then Scope (Nam) = Spec)
5613 and then Scope (Typ) = Current_Scope
5614 and then Defining_Entity (Subp) = Current_Scope
5620 -- An expression function may act as a completion of
5621 -- a function declaration. As such, it can reference
5622 -- entities declared between the two views:
5625 -- function F return ...;
5627 -- function Hidden return ...;
5628 -- function F return ... is (Hidden); -- 2
5630 -- Refering to the example above, freezing the expression
5631 -- of F (2) would place Hidden's freeze node (1) in the
5632 -- wrong place. Avoid explicit freezing and let the usual
5633 -- scenarios do the job - for example, reaching the end
5634 -- of the private declarations.
5636 if Nkind (Original_Node (Subp)) =
5637 N_Expression_Function
5641 -- Freeze outside the body
5644 Parent_P := Parent (Parent_P);
5645 Freeze_Outside := True;
5649 -- Here if normal case where we are in handled statement
5650 -- sequence and want to do the insertion right there.
5656 -- If parent is a body or a spec or a block, then the current node
5657 -- is a statement or declaration and we can insert the freeze node
5660 when N_Block_Statement |
5663 N_Package_Specification |
5666 N_Task_Body => exit;
5668 -- The expander is allowed to define types in any statements list,
5669 -- so any of the following parent nodes also mark a freezing point
5670 -- if the actual node is in a list of statements or declarations.
5672 when N_Abortable_Part |
5673 N_Accept_Alternative |
5675 N_Case_Statement_Alternative |
5676 N_Compilation_Unit_Aux |
5677 N_Conditional_Entry_Call |
5678 N_Delay_Alternative |
5680 N_Entry_Call_Alternative |
5681 N_Exception_Handler |
5682 N_Extended_Return_Statement |
5686 N_Selective_Accept |
5687 N_Triggering_Alternative =>
5689 exit when Is_List_Member (P);
5691 -- Note: The N_Loop_Statement is a special case. A type that
5692 -- appears in the source can never be frozen in a loop (this
5693 -- occurs only because of a loop expanded by the expander), so we
5694 -- keep on going. Otherwise we terminate the search. Same is true
5695 -- of any entity which comes from source. (if they have predefined
5696 -- type, that type does not appear to come from source, but the
5697 -- entity should not be frozen here).
5699 when N_Loop_Statement =>
5700 exit when not Comes_From_Source (Etype (N))
5701 and then (No (Nam) or else not Comes_From_Source (Nam));
5703 -- For all other cases, keep looking at parents
5709 -- We fall through the case if we did not yet find the proper
5710 -- place in the free for inserting the freeze node, so climb!
5715 -- If the expression appears in a record or an initialization procedure,
5716 -- the freeze nodes are collected and attached to the current scope, to
5717 -- be inserted and analyzed on exit from the scope, to insure that
5718 -- generated entities appear in the correct scope. If the expression is
5719 -- a default for a discriminant specification, the scope is still void.
5720 -- The expression can also appear in the discriminant part of a private
5721 -- or concurrent type.
5723 -- If the expression appears in a constrained subcomponent of an
5724 -- enclosing record declaration, the freeze nodes must be attached to
5725 -- the outer record type so they can eventually be placed in the
5726 -- enclosing declaration list.
5728 -- The other case requiring this special handling is if we are in a
5729 -- default expression, since in that case we are about to freeze a
5730 -- static type, and the freeze scope needs to be the outer scope, not
5731 -- the scope of the subprogram with the default parameter.
5733 -- For default expressions and other spec expressions in generic units,
5734 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5735 -- placing them at the proper place, after the generic unit.
5737 if (In_Spec_Exp and not Inside_A_Generic)
5738 or else Freeze_Outside
5739 or else (Is_Type (Current_Scope)
5740 and then (not Is_Concurrent_Type (Current_Scope)
5741 or else not Has_Completion (Current_Scope)))
5742 or else Ekind (Current_Scope) = E_Void
5745 N : constant Node_Id := Current_Scope;
5746 Freeze_Nodes : List_Id := No_List;
5747 Pos : Int := Scope_Stack.Last;
5750 if Present (Desig_Typ) then
5751 Freeze_And_Append (Desig_Typ, N, Freeze_Nodes);
5754 if Present (Typ) then
5755 Freeze_And_Append (Typ, N, Freeze_Nodes);
5758 if Present (Nam) then
5759 Freeze_And_Append (Nam, N, Freeze_Nodes);
5762 -- The current scope may be that of a constrained component of
5763 -- an enclosing record declaration, or of a loop of an enclosing
5764 -- quantified expression, which is above the current scope in the
5765 -- scope stack. Indeed in the context of a quantified expression,
5766 -- a scope is created and pushed above the current scope in order
5767 -- to emulate the loop-like behavior of the quantified expression.
5768 -- If the expression is within a top-level pragma, as for a pre-
5769 -- condition on a library-level subprogram, nothing to do.
5771 if not Is_Compilation_Unit (Current_Scope)
5772 and then (Is_Record_Type (Scope (Current_Scope))
5773 or else Nkind (Parent (Current_Scope)) =
5774 N_Quantified_Expression)
5779 if Is_Non_Empty_List (Freeze_Nodes) then
5780 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
5781 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
5784 Append_List (Freeze_Nodes,
5785 Scope_Stack.Table (Pos).Pending_Freeze_Actions);
5793 -- Now we have the right place to do the freezing. First, a special
5794 -- adjustment, if we are in spec-expression analysis mode, these freeze
5795 -- actions must not be thrown away (normally all inserted actions are
5796 -- thrown away in this mode. However, the freeze actions are from static
5797 -- expressions and one of the important reasons we are doing this
5798 -- special analysis is to get these freeze actions. Therefore we turn
5799 -- off the In_Spec_Expression mode to propagate these freeze actions.
5800 -- This also means they get properly analyzed and expanded.
5802 In_Spec_Expression := False;
5804 -- Freeze the designated type of an allocator (RM 13.14(13))
5806 if Present (Desig_Typ) then
5807 Freeze_Before (P, Desig_Typ);
5810 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5811 -- the enumeration representation clause exception in the loop above.
5813 if Present (Typ) then
5814 Freeze_Before (P, Typ);
5817 -- Freeze name if one is present (RM 13.14(11))
5819 if Present (Nam) then
5820 Freeze_Before (P, Nam);
5823 -- Restore In_Spec_Expression flag
5825 In_Spec_Expression := In_Spec_Exp;
5826 end Freeze_Expression;
5828 -----------------------------
5829 -- Freeze_Fixed_Point_Type --
5830 -----------------------------
5832 -- Certain fixed-point types and subtypes, including implicit base types
5833 -- and declared first subtypes, have not yet set up a range. This is
5834 -- because the range cannot be set until the Small and Size values are
5835 -- known, and these are not known till the type is frozen.
5837 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5838 -- whose bounds are unanalyzed real literals. This routine will recognize
5839 -- this case, and transform this range node into a properly typed range
5840 -- with properly analyzed and resolved values.
5842 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
5843 Rng : constant Node_Id := Scalar_Range (Typ);
5844 Lo : constant Node_Id := Low_Bound (Rng);
5845 Hi : constant Node_Id := High_Bound (Rng);
5846 Btyp : constant Entity_Id := Base_Type (Typ);
5847 Brng : constant Node_Id := Scalar_Range (Btyp);
5848 BLo : constant Node_Id := Low_Bound (Brng);
5849 BHi : constant Node_Id := High_Bound (Brng);
5850 Small : constant Ureal := Small_Value (Typ);
5857 function Fsize (Lov, Hiv : Ureal) return Nat;
5858 -- Returns size of type with given bounds. Also leaves these
5859 -- bounds set as the current bounds of the Typ.
5865 function Fsize (Lov, Hiv : Ureal) return Nat is
5867 Set_Realval (Lo, Lov);
5868 Set_Realval (Hi, Hiv);
5869 return Minimum_Size (Typ);
5872 -- Start of processing for Freeze_Fixed_Point_Type
5875 -- If Esize of a subtype has not previously been set, set it now
5877 if Unknown_Esize (Typ) then
5878 Atype := Ancestor_Subtype (Typ);
5880 if Present (Atype) then
5881 Set_Esize (Typ, Esize (Atype));
5883 Set_Esize (Typ, Esize (Base_Type (Typ)));
5887 -- Immediate return if the range is already analyzed. This means that
5888 -- the range is already set, and does not need to be computed by this
5891 if Analyzed (Rng) then
5895 -- Immediate return if either of the bounds raises Constraint_Error
5897 if Raises_Constraint_Error (Lo)
5898 or else Raises_Constraint_Error (Hi)
5903 Loval := Realval (Lo);
5904 Hival := Realval (Hi);
5906 -- Ordinary fixed-point case
5908 if Is_Ordinary_Fixed_Point_Type (Typ) then
5910 -- For the ordinary fixed-point case, we are allowed to fudge the
5911 -- end-points up or down by small. Generally we prefer to fudge up,
5912 -- i.e. widen the bounds for non-model numbers so that the end points
5913 -- are included. However there are cases in which this cannot be
5914 -- done, and indeed cases in which we may need to narrow the bounds.
5915 -- The following circuit makes the decision.
5917 -- Note: our terminology here is that Incl_EP means that the bounds
5918 -- are widened by Small if necessary to include the end points, and
5919 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5920 -- end-points if this reduces the size.
5922 -- Note that in the Incl case, all we care about is including the
5923 -- end-points. In the Excl case, we want to narrow the bounds as
5924 -- much as permitted by the RM, to give the smallest possible size.
5927 Loval_Incl_EP : Ureal;
5928 Hival_Incl_EP : Ureal;
5930 Loval_Excl_EP : Ureal;
5931 Hival_Excl_EP : Ureal;
5937 First_Subt : Entity_Id;
5942 -- First step. Base types are required to be symmetrical. Right
5943 -- now, the base type range is a copy of the first subtype range.
5944 -- This will be corrected before we are done, but right away we
5945 -- need to deal with the case where both bounds are non-negative.
5946 -- In this case, we set the low bound to the negative of the high
5947 -- bound, to make sure that the size is computed to include the
5948 -- required sign. Note that we do not need to worry about the
5949 -- case of both bounds negative, because the sign will be dealt
5950 -- with anyway. Furthermore we can't just go making such a bound
5951 -- symmetrical, since in a twos-complement system, there is an
5952 -- extra negative value which could not be accommodated on the
5956 and then not UR_Is_Negative (Loval)
5957 and then Hival > Loval
5960 Set_Realval (Lo, Loval);
5963 -- Compute the fudged bounds. If the number is a model number,
5964 -- then we do nothing to include it, but we are allowed to backoff
5965 -- to the next adjacent model number when we exclude it. If it is
5966 -- not a model number then we straddle the two values with the
5967 -- model numbers on either side.
5969 Model_Num := UR_Trunc (Loval / Small) * Small;
5971 if Loval = Model_Num then
5972 Loval_Incl_EP := Model_Num;
5974 Loval_Incl_EP := Model_Num - Small;
5977 -- The low value excluding the end point is Small greater, but
5978 -- we do not do this exclusion if the low value is positive,
5979 -- since it can't help the size and could actually hurt by
5980 -- crossing the high bound.
5982 if UR_Is_Negative (Loval_Incl_EP) then
5983 Loval_Excl_EP := Loval_Incl_EP + Small;
5985 -- If the value went from negative to zero, then we have the
5986 -- case where Loval_Incl_EP is the model number just below
5987 -- zero, so we want to stick to the negative value for the
5988 -- base type to maintain the condition that the size will
5989 -- include signed values.
5992 and then UR_Is_Zero (Loval_Excl_EP)
5994 Loval_Excl_EP := Loval_Incl_EP;
5998 Loval_Excl_EP := Loval_Incl_EP;
6001 -- Similar processing for upper bound and high value
6003 Model_Num := UR_Trunc (Hival / Small) * Small;
6005 if Hival = Model_Num then
6006 Hival_Incl_EP := Model_Num;
6008 Hival_Incl_EP := Model_Num + Small;
6011 if UR_Is_Positive (Hival_Incl_EP) then
6012 Hival_Excl_EP := Hival_Incl_EP - Small;
6014 Hival_Excl_EP := Hival_Incl_EP;
6017 -- One further adjustment is needed. In the case of subtypes, we
6018 -- cannot go outside the range of the base type, or we get
6019 -- peculiarities, and the base type range is already set. This
6020 -- only applies to the Incl values, since clearly the Excl values
6021 -- are already as restricted as they are allowed to be.
6024 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
6025 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
6028 -- Get size including and excluding end points
6030 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
6031 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
6033 -- No need to exclude end-points if it does not reduce size
6035 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
6036 Loval_Excl_EP := Loval_Incl_EP;
6039 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
6040 Hival_Excl_EP := Hival_Incl_EP;
6043 -- Now we set the actual size to be used. We want to use the
6044 -- bounds fudged up to include the end-points but only if this
6045 -- can be done without violating a specifically given size
6046 -- size clause or causing an unacceptable increase in size.
6048 -- Case of size clause given
6050 if Has_Size_Clause (Typ) then
6052 -- Use the inclusive size only if it is consistent with
6053 -- the explicitly specified size.
6055 if Size_Incl_EP <= RM_Size (Typ) then
6056 Actual_Lo := Loval_Incl_EP;
6057 Actual_Hi := Hival_Incl_EP;
6058 Actual_Size := Size_Incl_EP;
6060 -- If the inclusive size is too large, we try excluding
6061 -- the end-points (will be caught later if does not work).
6064 Actual_Lo := Loval_Excl_EP;
6065 Actual_Hi := Hival_Excl_EP;
6066 Actual_Size := Size_Excl_EP;
6069 -- Case of size clause not given
6072 -- If we have a base type whose corresponding first subtype
6073 -- has an explicit size that is large enough to include our
6074 -- end-points, then do so. There is no point in working hard
6075 -- to get a base type whose size is smaller than the specified
6076 -- size of the first subtype.
6078 First_Subt := First_Subtype (Typ);
6080 if Has_Size_Clause (First_Subt)
6081 and then Size_Incl_EP <= Esize (First_Subt)
6083 Actual_Size := Size_Incl_EP;
6084 Actual_Lo := Loval_Incl_EP;
6085 Actual_Hi := Hival_Incl_EP;
6087 -- If excluding the end-points makes the size smaller and
6088 -- results in a size of 8,16,32,64, then we take the smaller
6089 -- size. For the 64 case, this is compulsory. For the other
6090 -- cases, it seems reasonable. We like to include end points
6091 -- if we can, but not at the expense of moving to the next
6092 -- natural boundary of size.
6094 elsif Size_Incl_EP /= Size_Excl_EP
6095 and then Addressable (Size_Excl_EP)
6097 Actual_Size := Size_Excl_EP;
6098 Actual_Lo := Loval_Excl_EP;
6099 Actual_Hi := Hival_Excl_EP;
6101 -- Otherwise we can definitely include the end points
6104 Actual_Size := Size_Incl_EP;
6105 Actual_Lo := Loval_Incl_EP;
6106 Actual_Hi := Hival_Incl_EP;
6109 -- One pathological case: normally we never fudge a low bound
6110 -- down, since it would seem to increase the size (if it has
6111 -- any effect), but for ranges containing single value, or no
6112 -- values, the high bound can be small too large. Consider:
6114 -- type t is delta 2.0**(-14)
6115 -- range 131072.0 .. 0;
6117 -- That lower bound is *just* outside the range of 32 bits, and
6118 -- does need fudging down in this case. Note that the bounds
6119 -- will always have crossed here, since the high bound will be
6120 -- fudged down if necessary, as in the case of:
6122 -- type t is delta 2.0**(-14)
6123 -- range 131072.0 .. 131072.0;
6125 -- So we detect the situation by looking for crossed bounds,
6126 -- and if the bounds are crossed, and the low bound is greater
6127 -- than zero, we will always back it off by small, since this
6128 -- is completely harmless.
6130 if Actual_Lo > Actual_Hi then
6131 if UR_Is_Positive (Actual_Lo) then
6132 Actual_Lo := Loval_Incl_EP - Small;
6133 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
6135 -- And of course, we need to do exactly the same parallel
6136 -- fudge for flat ranges in the negative region.
6138 elsif UR_Is_Negative (Actual_Hi) then
6139 Actual_Hi := Hival_Incl_EP + Small;
6140 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
6145 Set_Realval (Lo, Actual_Lo);
6146 Set_Realval (Hi, Actual_Hi);
6149 -- For the decimal case, none of this fudging is required, since there
6150 -- are no end-point problems in the decimal case (the end-points are
6151 -- always included).
6154 Actual_Size := Fsize (Loval, Hival);
6157 -- At this stage, the actual size has been calculated and the proper
6158 -- required bounds are stored in the low and high bounds.
6160 if Actual_Size > 64 then
6161 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
6163 ("size required (^) for type& too large, maximum allowed is 64",
6168 -- Check size against explicit given size
6170 if Has_Size_Clause (Typ) then
6171 if Actual_Size > RM_Size (Typ) then
6172 Error_Msg_Uint_1 := RM_Size (Typ);
6173 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
6175 ("size given (^) for type& too small, minimum allowed is ^",
6176 Size_Clause (Typ), Typ);
6179 Actual_Size := UI_To_Int (Esize (Typ));
6182 -- Increase size to next natural boundary if no size clause given
6185 if Actual_Size <= 8 then
6187 elsif Actual_Size <= 16 then
6189 elsif Actual_Size <= 32 then
6195 Init_Esize (Typ, Actual_Size);
6196 Adjust_Esize_For_Alignment (Typ);
6199 -- If we have a base type, then expand the bounds so that they extend to
6200 -- the full width of the allocated size in bits, to avoid junk range
6201 -- checks on intermediate computations.
6203 if Base_Type (Typ) = Typ then
6204 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
6205 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
6208 -- Final step is to reanalyze the bounds using the proper type
6209 -- and set the Corresponding_Integer_Value fields of the literals.
6211 Set_Etype (Lo, Empty);
6212 Set_Analyzed (Lo, False);
6215 -- Resolve with universal fixed if the base type, and the base type if
6216 -- it is a subtype. Note we can't resolve the base type with itself,
6217 -- that would be a reference before definition.
6220 Resolve (Lo, Universal_Fixed);
6225 -- Set corresponding integer value for bound
6227 Set_Corresponding_Integer_Value
6228 (Lo, UR_To_Uint (Realval (Lo) / Small));
6230 -- Similar processing for high bound
6232 Set_Etype (Hi, Empty);
6233 Set_Analyzed (Hi, False);
6237 Resolve (Hi, Universal_Fixed);
6242 Set_Corresponding_Integer_Value
6243 (Hi, UR_To_Uint (Realval (Hi) / Small));
6245 -- Set type of range to correspond to bounds
6247 Set_Etype (Rng, Etype (Lo));
6249 -- Set Esize to calculated size if not set already
6251 if Unknown_Esize (Typ) then
6252 Init_Esize (Typ, Actual_Size);
6255 -- Set RM_Size if not already set. If already set, check value
6258 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
6261 if RM_Size (Typ) /= Uint_0 then
6262 if RM_Size (Typ) < Minsiz then
6263 Error_Msg_Uint_1 := RM_Size (Typ);
6264 Error_Msg_Uint_2 := Minsiz;
6266 ("size given (^) for type& too small, minimum allowed is ^",
6267 Size_Clause (Typ), Typ);
6271 Set_RM_Size (Typ, Minsiz);
6274 end Freeze_Fixed_Point_Type;
6280 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
6284 Set_Has_Delayed_Freeze (T);
6285 L := Freeze_Entity (T, N);
6287 if Is_Non_Empty_List (L) then
6288 Insert_Actions (N, L);
6292 --------------------------
6293 -- Freeze_Static_Object --
6294 --------------------------
6296 procedure Freeze_Static_Object (E : Entity_Id) is
6298 Cannot_Be_Static : exception;
6299 -- Exception raised if the type of a static object cannot be made
6300 -- static. This happens if the type depends on non-global objects.
6302 procedure Ensure_Expression_Is_SA (N : Node_Id);
6303 -- Called to ensure that an expression used as part of a type definition
6304 -- is statically allocatable, which means that the expression type is
6305 -- statically allocatable, and the expression is either static, or a
6306 -- reference to a library level constant.
6308 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
6309 -- Called to mark a type as static, checking that it is possible
6310 -- to set the type as static. If it is not possible, then the
6311 -- exception Cannot_Be_Static is raised.
6313 -----------------------------
6314 -- Ensure_Expression_Is_SA --
6315 -----------------------------
6317 procedure Ensure_Expression_Is_SA (N : Node_Id) is
6321 Ensure_Type_Is_SA (Etype (N));
6323 if Is_Static_Expression (N) then
6326 elsif Nkind (N) = N_Identifier then
6330 and then Ekind (Ent) = E_Constant
6331 and then Is_Library_Level_Entity (Ent)
6337 raise Cannot_Be_Static;
6338 end Ensure_Expression_Is_SA;
6340 -----------------------
6341 -- Ensure_Type_Is_SA --
6342 -----------------------
6344 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
6349 -- If type is library level, we are all set
6351 if Is_Library_Level_Entity (Typ) then
6355 -- We are also OK if the type already marked as statically allocated,
6356 -- which means we processed it before.
6358 if Is_Statically_Allocated (Typ) then
6362 -- Mark type as statically allocated
6364 Set_Is_Statically_Allocated (Typ);
6366 -- Check that it is safe to statically allocate this type
6368 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
6369 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
6370 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
6372 elsif Is_Array_Type (Typ) then
6373 N := First_Index (Typ);
6374 while Present (N) loop
6375 Ensure_Type_Is_SA (Etype (N));
6379 Ensure_Type_Is_SA (Component_Type (Typ));
6381 elsif Is_Access_Type (Typ) then
6382 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
6386 T : constant Entity_Id := Etype (Designated_Type (Typ));
6389 if T /= Standard_Void_Type then
6390 Ensure_Type_Is_SA (T);
6393 F := First_Formal (Designated_Type (Typ));
6394 while Present (F) loop
6395 Ensure_Type_Is_SA (Etype (F));
6401 Ensure_Type_Is_SA (Designated_Type (Typ));
6404 elsif Is_Record_Type (Typ) then
6405 C := First_Entity (Typ);
6406 while Present (C) loop
6407 if Ekind (C) = E_Discriminant
6408 or else Ekind (C) = E_Component
6410 Ensure_Type_Is_SA (Etype (C));
6412 elsif Is_Type (C) then
6413 Ensure_Type_Is_SA (C);
6419 elsif Ekind (Typ) = E_Subprogram_Type then
6420 Ensure_Type_Is_SA (Etype (Typ));
6422 C := First_Formal (Typ);
6423 while Present (C) loop
6424 Ensure_Type_Is_SA (Etype (C));
6429 raise Cannot_Be_Static;
6431 end Ensure_Type_Is_SA;
6433 -- Start of processing for Freeze_Static_Object
6436 Ensure_Type_Is_SA (Etype (E));
6439 when Cannot_Be_Static =>
6441 -- If the object that cannot be static is imported or exported, then
6442 -- issue an error message saying that this object cannot be imported
6443 -- or exported. If it has an address clause it is an overlay in the
6444 -- current partition and the static requirement is not relevant.
6445 -- Do not issue any error message when ignoring rep clauses.
6447 if Ignore_Rep_Clauses then
6450 elsif Is_Imported (E) then
6451 if No (Address_Clause (E)) then
6453 ("& cannot be imported (local type is not constant)", E);
6456 -- Otherwise must be exported, something is wrong if compiler
6457 -- is marking something as statically allocated which cannot be).
6459 else pragma Assert (Is_Exported (E));
6461 ("& cannot be exported (local type is not constant)", E);
6463 end Freeze_Static_Object;
6465 -----------------------
6466 -- Freeze_Subprogram --
6467 -----------------------
6469 procedure Freeze_Subprogram (E : Entity_Id) is
6474 -- Subprogram may not have an address clause unless it is imported
6476 if Present (Address_Clause (E)) then
6477 if not Is_Imported (E) then
6479 ("address clause can only be given " &
6480 "for imported subprogram",
6481 Name (Address_Clause (E)));
6485 -- Reset the Pure indication on an imported subprogram unless an
6486 -- explicit Pure_Function pragma was present. We do this because
6487 -- otherwise it is an insidious error to call a non-pure function from
6488 -- pure unit and have calls mysteriously optimized away. What happens
6489 -- here is that the Import can bypass the normal check to ensure that
6490 -- pure units call only pure subprograms.
6493 and then Is_Pure (E)
6494 and then not Has_Pragma_Pure_Function (E)
6496 Set_Is_Pure (E, False);
6499 -- For non-foreign convention subprograms, this is where we create
6500 -- the extra formals (for accessibility level and constrained bit
6501 -- information). We delay this till the freeze point precisely so
6502 -- that we know the convention!
6504 if not Has_Foreign_Convention (E) then
6505 Create_Extra_Formals (E);
6508 -- If this is convention Ada and a Valued_Procedure, that's odd
6510 if Ekind (E) = E_Procedure
6511 and then Is_Valued_Procedure (E)
6512 and then Convention (E) = Convention_Ada
6513 and then Warn_On_Export_Import
6516 ("??Valued_Procedure has no effect for convention Ada", E);
6517 Set_Is_Valued_Procedure (E, False);
6520 -- Case of foreign convention
6525 -- For foreign conventions, warn about return of an
6526 -- unconstrained array.
6528 -- Note: we *do* allow a return by descriptor for the VMS case,
6529 -- though here there is probably more to be done ???
6531 if Ekind (E) = E_Function then
6532 Retype := Underlying_Type (Etype (E));
6534 -- If no return type, probably some other error, e.g. a
6535 -- missing full declaration, so ignore.
6540 -- If the return type is generic, we have emitted a warning
6541 -- earlier on, and there is nothing else to check here. Specific
6542 -- instantiations may lead to erroneous behavior.
6544 elsif Is_Generic_Type (Etype (E)) then
6547 -- Display warning if returning unconstrained array
6549 elsif Is_Array_Type (Retype)
6550 and then not Is_Constrained (Retype)
6552 -- Exclude cases where descriptor mechanism is set, since the
6553 -- VMS descriptor mechanisms allow such unconstrained returns.
6555 and then Mechanism (E) not in Descriptor_Codes
6557 -- Check appropriate warning is enabled (should we check for
6558 -- Warnings (Off) on specific entities here, probably so???)
6560 and then Warn_On_Export_Import
6562 -- Exclude the VM case, since return of unconstrained arrays
6563 -- is properly handled in both the JVM and .NET cases.
6565 and then VM_Target = No_VM
6568 ("?x?foreign convention function& should not return " &
6569 "unconstrained array", E);
6574 -- If any of the formals for an exported foreign convention
6575 -- subprogram have defaults, then emit an appropriate warning since
6576 -- this is odd (default cannot be used from non-Ada code)
6578 if Is_Exported (E) then
6579 F := First_Formal (E);
6580 while Present (F) loop
6581 if Warn_On_Export_Import
6582 and then Present (Default_Value (F))
6585 ("?x?parameter cannot be defaulted in non-Ada call",
6594 -- For VMS, descriptor mechanisms for parameters are allowed only for
6595 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6596 -- allowed for parameters of exported subprograms.
6598 if OpenVMS_On_Target then
6599 if Is_Exported (E) then
6600 F := First_Formal (E);
6601 while Present (F) loop
6602 if Mechanism (F) = By_Descriptor_NCA then
6604 ("'N'C'A' descriptor for parameter not permitted", F);
6606 ("\can only be used for imported subprogram", F);
6612 elsif not Is_Imported (E) then
6613 F := First_Formal (E);
6614 while Present (F) loop
6615 if Mechanism (F) in Descriptor_Codes then
6617 ("descriptor mechanism for parameter not permitted", F);
6619 ("\can only be used for imported/exported subprogram", F);
6627 -- Pragma Inline_Always is disallowed for dispatching subprograms
6628 -- because the address of such subprograms is saved in the dispatch
6629 -- table to support dispatching calls, and dispatching calls cannot
6630 -- be inlined. This is consistent with the restriction against using
6631 -- 'Access or 'Address on an Inline_Always subprogram.
6633 if Is_Dispatching_Operation (E)
6634 and then Has_Pragma_Inline_Always (E)
6637 ("pragma Inline_Always not allowed for dispatching subprograms", E);
6640 -- Because of the implicit representation of inherited predefined
6641 -- operators in the front-end, the overriding status of the operation
6642 -- may be affected when a full view of a type is analyzed, and this is
6643 -- not captured by the analysis of the corresponding type declaration.
6644 -- Therefore the correctness of a not-overriding indicator must be
6645 -- rechecked when the subprogram is frozen.
6647 if Nkind (E) = N_Defining_Operator_Symbol
6648 and then not Error_Posted (Parent (E))
6650 Check_Overriding_Indicator (E, Empty, Is_Primitive (E));
6652 end Freeze_Subprogram;
6654 ----------------------
6655 -- Is_Fully_Defined --
6656 ----------------------
6658 function Is_Fully_Defined (T : Entity_Id) return Boolean is
6660 if Ekind (T) = E_Class_Wide_Type then
6661 return Is_Fully_Defined (Etype (T));
6663 elsif Is_Array_Type (T) then
6664 return Is_Fully_Defined (Component_Type (T));
6666 elsif Is_Record_Type (T)
6667 and not Is_Private_Type (T)
6669 -- Verify that the record type has no components with private types
6670 -- without completion.
6676 Comp := First_Component (T);
6677 while Present (Comp) loop
6678 if not Is_Fully_Defined (Etype (Comp)) then
6682 Next_Component (Comp);
6687 -- For the designated type of an access to subprogram, all types in
6688 -- the profile must be fully defined.
6690 elsif Ekind (T) = E_Subprogram_Type then
6695 F := First_Formal (T);
6696 while Present (F) loop
6697 if not Is_Fully_Defined (Etype (F)) then
6704 return Is_Fully_Defined (Etype (T));
6708 return not Is_Private_Type (T)
6709 or else Present (Full_View (Base_Type (T)));
6711 end Is_Fully_Defined;
6713 ---------------------------------
6714 -- Process_Default_Expressions --
6715 ---------------------------------
6717 procedure Process_Default_Expressions
6719 After : in out Node_Id)
6721 Loc : constant Source_Ptr := Sloc (E);
6728 Set_Default_Expressions_Processed (E);
6730 -- A subprogram instance and its associated anonymous subprogram share
6731 -- their signature. The default expression functions are defined in the
6732 -- wrapper packages for the anonymous subprogram, and should not be
6733 -- generated again for the instance.
6735 if Is_Generic_Instance (E)
6736 and then Present (Alias (E))
6737 and then Default_Expressions_Processed (Alias (E))
6742 Formal := First_Formal (E);
6743 while Present (Formal) loop
6744 if Present (Default_Value (Formal)) then
6746 -- We work with a copy of the default expression because we
6747 -- do not want to disturb the original, since this would mess
6748 -- up the conformance checking.
6750 Dcopy := New_Copy_Tree (Default_Value (Formal));
6752 -- The analysis of the expression may generate insert actions,
6753 -- which of course must not be executed. We wrap those actions
6754 -- in a procedure that is not called, and later on eliminated.
6755 -- The following cases have no side-effects, and are analyzed
6758 if Nkind (Dcopy) = N_Identifier
6759 or else Nkind (Dcopy) = N_Expanded_Name
6760 or else Nkind (Dcopy) = N_Integer_Literal
6761 or else (Nkind (Dcopy) = N_Real_Literal
6762 and then not Vax_Float (Etype (Dcopy)))
6763 or else Nkind (Dcopy) = N_Character_Literal
6764 or else Nkind (Dcopy) = N_String_Literal
6765 or else Known_Null (Dcopy)
6766 or else (Nkind (Dcopy) = N_Attribute_Reference
6768 Attribute_Name (Dcopy) = Name_Null_Parameter)
6771 -- If there is no default function, we must still do a full
6772 -- analyze call on the default value, to ensure that all error
6773 -- checks are performed, e.g. those associated with static
6774 -- evaluation. Note: this branch will always be taken if the
6775 -- analyzer is turned off (but we still need the error checks).
6777 -- Note: the setting of parent here is to meet the requirement
6778 -- that we can only analyze the expression while attached to
6779 -- the tree. Really the requirement is that the parent chain
6780 -- be set, we don't actually need to be in the tree.
6782 Set_Parent (Dcopy, Declaration_Node (Formal));
6785 -- Default expressions are resolved with their own type if the
6786 -- context is generic, to avoid anomalies with private types.
6788 if Ekind (Scope (E)) = E_Generic_Package then
6791 Resolve (Dcopy, Etype (Formal));
6794 -- If that resolved expression will raise constraint error,
6795 -- then flag the default value as raising constraint error.
6796 -- This allows a proper error message on the calls.
6798 if Raises_Constraint_Error (Dcopy) then
6799 Set_Raises_Constraint_Error (Default_Value (Formal));
6802 -- If the default is a parameterless call, we use the name of
6803 -- the called function directly, and there is no body to build.
6805 elsif Nkind (Dcopy) = N_Function_Call
6806 and then No (Parameter_Associations (Dcopy))
6810 -- Else construct and analyze the body of a wrapper procedure
6811 -- that contains an object declaration to hold the expression.
6812 -- Given that this is done only to complete the analysis, it
6813 -- simpler to build a procedure than a function which might
6814 -- involve secondary stack expansion.
6817 Dnam := Make_Temporary (Loc, 'D');
6820 Make_Subprogram_Body (Loc,
6822 Make_Procedure_Specification (Loc,
6823 Defining_Unit_Name => Dnam),
6825 Declarations => New_List (
6826 Make_Object_Declaration (Loc,
6827 Defining_Identifier => Make_Temporary (Loc, 'T'),
6828 Object_Definition =>
6829 New_Occurrence_Of (Etype (Formal), Loc),
6830 Expression => New_Copy_Tree (Dcopy))),
6832 Handled_Statement_Sequence =>
6833 Make_Handled_Sequence_Of_Statements (Loc,
6834 Statements => Empty_List));
6836 Set_Scope (Dnam, Scope (E));
6837 Set_Assignment_OK (First (Declarations (Dbody)));
6838 Set_Is_Eliminated (Dnam);
6839 Insert_After (After, Dbody);
6845 Next_Formal (Formal);
6847 end Process_Default_Expressions;
6849 ----------------------------------------
6850 -- Set_Component_Alignment_If_Not_Set --
6851 ----------------------------------------
6853 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
6855 -- Ignore if not base type, subtypes don't need anything
6857 if Typ /= Base_Type (Typ) then
6861 -- Do not override existing representation
6863 if Is_Packed (Typ) then
6866 elsif Has_Specified_Layout (Typ) then
6869 elsif Component_Alignment (Typ) /= Calign_Default then
6873 Set_Component_Alignment
6874 (Typ, Scope_Stack.Table
6875 (Scope_Stack.Last).Component_Alignment_Default);
6877 end Set_Component_Alignment_If_Not_Set;
6883 procedure Undelay_Type (T : Entity_Id) is
6885 Set_Has_Delayed_Freeze (T, False);
6886 Set_Freeze_Node (T, Empty);
6888 -- Since we don't want T to have a Freeze_Node, we don't want its
6889 -- Full_View or Corresponding_Record_Type to have one either.
6891 -- ??? Fundamentally, this whole handling is a kludge. What we really
6892 -- want is to be sure that for an Itype that's part of record R and is a
6893 -- subtype of type T, that it's frozen after the later of the freeze
6894 -- points of R and T. We have no way of doing that directly, so what we
6895 -- do is force most such Itypes to be frozen as part of freezing R via
6896 -- this procedure and only delay the ones that need to be delayed
6897 -- (mostly the designated types of access types that are defined as part
6900 if Is_Private_Type (T)
6901 and then Present (Full_View (T))
6902 and then Is_Itype (Full_View (T))
6903 and then Is_Record_Type (Scope (Full_View (T)))
6905 Undelay_Type (Full_View (T));
6908 if Is_Concurrent_Type (T)
6909 and then Present (Corresponding_Record_Type (T))
6910 and then Is_Itype (Corresponding_Record_Type (T))
6911 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
6913 Undelay_Type (Corresponding_Record_Type (T));
6921 procedure Warn_Overlay
6926 Ent : constant Entity_Id := Entity (Nam);
6927 -- The object to which the address clause applies
6930 Old : Entity_Id := Empty;
6934 -- No warning if address clause overlay warnings are off
6936 if not Address_Clause_Overlay_Warnings then
6940 -- No warning if there is an explicit initialization
6942 Init := Original_Node (Expression (Declaration_Node (Ent)));
6944 if Present (Init) and then Comes_From_Source (Init) then
6948 -- We only give the warning for non-imported entities of a type for
6949 -- which a non-null base init proc is defined, or for objects of access
6950 -- types with implicit null initialization, or when Normalize_Scalars
6951 -- applies and the type is scalar or a string type (the latter being
6952 -- tested for because predefined String types are initialized by inline
6953 -- code rather than by an init_proc). Note that we do not give the
6954 -- warning for Initialize_Scalars, since we suppressed initialization
6955 -- in this case. Also, do not warn if Suppress_Initialization is set.
6958 and then not Is_Imported (Ent)
6959 and then not Initialization_Suppressed (Typ)
6960 and then (Has_Non_Null_Base_Init_Proc (Typ)
6961 or else Is_Access_Type (Typ)
6962 or else (Normalize_Scalars
6963 and then (Is_Scalar_Type (Typ)
6964 or else Is_String_Type (Typ))))
6966 if Nkind (Expr) = N_Attribute_Reference
6967 and then Is_Entity_Name (Prefix (Expr))
6969 Old := Entity (Prefix (Expr));
6971 elsif Is_Entity_Name (Expr)
6972 and then Ekind (Entity (Expr)) = E_Constant
6974 Decl := Declaration_Node (Entity (Expr));
6976 if Nkind (Decl) = N_Object_Declaration
6977 and then Present (Expression (Decl))
6978 and then Nkind (Expression (Decl)) = N_Attribute_Reference
6979 and then Is_Entity_Name (Prefix (Expression (Decl)))
6981 Old := Entity (Prefix (Expression (Decl)));
6983 elsif Nkind (Expr) = N_Function_Call then
6987 -- A function call (most likely to To_Address) is probably not an
6988 -- overlay, so skip warning. Ditto if the function call was inlined
6989 -- and transformed into an entity.
6991 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
6995 Decl := Next (Parent (Expr));
6997 -- If a pragma Import follows, we assume that it is for the current
6998 -- target of the address clause, and skip the warning.
7001 and then Nkind (Decl) = N_Pragma
7002 and then Pragma_Name (Decl) = Name_Import
7007 if Present (Old) then
7008 Error_Msg_Node_2 := Old;
7010 ("default initialization of & may modify &??",
7014 ("default initialization of & may modify overlaid storage??",
7018 -- Add friendly warning if initialization comes from a packed array
7021 if Is_Record_Type (Typ) then
7026 Comp := First_Component (Typ);
7027 while Present (Comp) loop
7028 if Nkind (Parent (Comp)) = N_Component_Declaration
7029 and then Present (Expression (Parent (Comp)))
7032 elsif Is_Array_Type (Etype (Comp))
7033 and then Present (Packed_Array_Type (Etype (Comp)))
7036 ("\packed array component& " &
7037 "will be initialized to zero??",
7041 Next_Component (Comp);
7048 ("\use pragma Import for & to " &
7049 "suppress initialization (RM B.1(24))??",