1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Ch7; use Exp_Ch7;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Pakd; use Exp_Pakd;
35 with Exp_Util; use Exp_Util;
36 with Exp_Tss; use Exp_Tss;
37 with Layout; use Layout;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
45 with Sem_Cat; use Sem_Cat;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch7; use Sem_Ch7;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Ch13; use Sem_Ch13;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Mech; use Sem_Mech;
52 with Sem_Prag; use Sem_Prag;
53 with Sem_Res; use Sem_Res;
54 with Sem_Util; use Sem_Util;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Stand; use Stand;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uintp; use Uintp;
62 with Urealp; use Urealp;
64 package body Freeze is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
71 -- Typ is a type that is being frozen. If no size clause is given,
72 -- but a default Esize has been computed, then this default Esize is
73 -- adjusted up if necessary to be consistent with a given alignment,
74 -- but never to a value greater than Long_Long_Integer'Size. This
75 -- is used for all discrete types and for fixed-point types.
77 procedure Build_And_Analyze_Renamed_Body
80 After : in out Node_Id);
81 -- Build body for a renaming declaration, insert in tree and analyze
83 procedure Check_Address_Clause (E : Entity_Id);
84 -- Apply legality checks to address clauses for object declarations,
85 -- at the point the object is frozen.
87 procedure Check_Strict_Alignment (E : Entity_Id);
88 -- E is a base type. If E is tagged or has a component that is aliased
89 -- or tagged or contains something this is aliased or tagged, set
92 procedure Check_Unsigned_Type (E : Entity_Id);
93 pragma Inline (Check_Unsigned_Type);
94 -- If E is a fixed-point or discrete type, then all the necessary work
95 -- to freeze it is completed except for possible setting of the flag
96 -- Is_Unsigned_Type, which is done by this procedure. The call has no
97 -- effect if the entity E is not a discrete or fixed-point type.
99 procedure Freeze_And_Append
102 Result : in out List_Id);
103 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
104 -- nodes to Result, modifying Result from No_List if necessary.
106 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
107 -- Freeze enumeration type. The Esize field is set as processing
108 -- proceeds (i.e. set by default when the type is declared and then
109 -- adjusted by rep clauses. What this procedure does is to make sure
110 -- that if a foreign convention is specified, and no specific size
111 -- is given, then the size must be at least Integer'Size.
113 procedure Freeze_Static_Object (E : Entity_Id);
114 -- If an object is frozen which has Is_Statically_Allocated set, then
115 -- all referenced types must also be marked with this flag. This routine
116 -- is in charge of meeting this requirement for the object entity E.
118 procedure Freeze_Subprogram (E : Entity_Id);
119 -- Perform freezing actions for a subprogram (create extra formals,
120 -- and set proper default mechanism values). Note that this routine
121 -- is not called for internal subprograms, for which neither of these
122 -- actions is needed (or desirable, we do not want for example to have
123 -- these extra formals present in initialization procedures, where they
124 -- would serve no purpose). In this call E is either a subprogram or
125 -- a subprogram type (i.e. an access to a subprogram).
127 function Is_Fully_Defined (T : Entity_Id) return Boolean;
128 -- True if T is not private and has no private components, or has a full
129 -- view. Used to determine whether the designated type of an access type
130 -- should be frozen when the access type is frozen. This is done when an
131 -- allocator is frozen, or an expression that may involve attributes of
132 -- the designated type. Otherwise freezing the access type does not freeze
133 -- the designated type.
135 procedure Process_Default_Expressions
137 After : in out Node_Id);
138 -- This procedure is called for each subprogram to complete processing
139 -- of default expressions at the point where all types are known to be
140 -- frozen. The expressions must be analyzed in full, to make sure that
141 -- all error processing is done (they have only been pre-analyzed). If
142 -- the expression is not an entity or literal, its analysis may generate
143 -- code which must not be executed. In that case we build a function
144 -- body to hold that code. This wrapper function serves no other purpose
145 -- (it used to be called to evaluate the default, but now the default is
146 -- inlined at each point of call).
148 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
149 -- Typ is a record or array type that is being frozen. This routine
150 -- sets the default component alignment from the scope stack values
151 -- if the alignment is otherwise not specified.
153 procedure Check_Debug_Info_Needed (T : Entity_Id);
154 -- As each entity is frozen, this routine is called to deal with the
155 -- setting of Debug_Info_Needed for the entity. This flag is set if
156 -- the entity comes from source, or if we are in Debug_Generated_Code
157 -- mode or if the -gnatdV debug flag is set. However, it never sets
158 -- the flag if Debug_Info_Off is set.
160 procedure Set_Debug_Info_Needed (T : Entity_Id);
161 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
162 -- also on any entities that are needed by T (for an object, the type
163 -- of the object is needed, and for a type, the subsidiary types are
164 -- needed -- see body for details). Never has any effect on T if the
165 -- Debug_Info_Off flag is set.
167 procedure Undelay_Type (T : Entity_Id);
168 -- T is a type of a component that we know to be an Itype.
169 -- We don't want this to have a Freeze_Node, so ensure it doesn't.
170 -- Do the same for any Full_View or Corresponding_Record_Type.
172 procedure Warn_Overlay
176 -- Expr is the expression for an address clause for entity Nam whose type
177 -- is Typ. If Typ has a default initialization, and there is no explicit
178 -- initialization in the source declaration, check whether the address
179 -- clause might cause overlaying of an entity, and emit a warning on the
180 -- side effect that the initialization will cause.
182 -------------------------------
183 -- Adjust_Esize_For_Alignment --
184 -------------------------------
186 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
190 if Known_Esize (Typ) and then Known_Alignment (Typ) then
191 Align := Alignment_In_Bits (Typ);
193 if Align > Esize (Typ)
194 and then Align <= Standard_Long_Long_Integer_Size
196 Set_Esize (Typ, Align);
199 end Adjust_Esize_For_Alignment;
201 ------------------------------------
202 -- Build_And_Analyze_Renamed_Body --
203 ------------------------------------
205 procedure Build_And_Analyze_Renamed_Body
208 After : in out Node_Id)
210 Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S);
213 Insert_After (After, Body_Node);
214 Mark_Rewrite_Insertion (Body_Node);
217 end Build_And_Analyze_Renamed_Body;
219 ------------------------
220 -- Build_Renamed_Body --
221 ------------------------
223 function Build_Renamed_Body
225 New_S : Entity_Id) return Node_Id
227 Loc : constant Source_Ptr := Sloc (New_S);
228 -- We use for the source location of the renamed body, the location
229 -- of the spec entity. It might seem more natural to use the location
230 -- of the renaming declaration itself, but that would be wrong, since
231 -- then the body we create would look as though it was created far
232 -- too late, and this could cause problems with elaboration order
233 -- analysis, particularly in connection with instantiations.
235 N : constant Node_Id := Unit_Declaration_Node (New_S);
236 Nam : constant Node_Id := Name (N);
238 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
239 Actuals : List_Id := No_List;
244 O_Formal : Entity_Id;
245 Param_Spec : Node_Id;
248 -- Determine the entity being renamed, which is the target of the
249 -- call statement. If the name is an explicit dereference, this is
250 -- a renaming of a subprogram type rather than a subprogram. The
251 -- name itself is fully analyzed.
253 if Nkind (Nam) = N_Selected_Component then
254 Old_S := Entity (Selector_Name (Nam));
256 elsif Nkind (Nam) = N_Explicit_Dereference then
257 Old_S := Etype (Nam);
259 elsif Nkind (Nam) = N_Indexed_Component then
260 if Is_Entity_Name (Prefix (Nam)) then
261 Old_S := Entity (Prefix (Nam));
263 Old_S := Entity (Selector_Name (Prefix (Nam)));
266 elsif Nkind (Nam) = N_Character_Literal then
267 Old_S := Etype (New_S);
270 Old_S := Entity (Nam);
273 if Is_Entity_Name (Nam) then
275 -- If the renamed entity is a predefined operator, retain full
276 -- name to ensure its visibility.
278 if Ekind (Old_S) = E_Operator
279 and then Nkind (Nam) = N_Expanded_Name
281 Call_Name := New_Copy (Name (N));
283 Call_Name := New_Reference_To (Old_S, Loc);
287 Call_Name := New_Copy (Name (N));
289 -- The original name may have been overloaded, but
290 -- is fully resolved now.
292 Set_Is_Overloaded (Call_Name, False);
295 -- For simple renamings, subsequent calls can be expanded directly
296 -- as called to the renamed entity. The body must be generated in
297 -- any case for calls they may appear elsewhere.
299 if (Ekind (Old_S) = E_Function
300 or else Ekind (Old_S) = E_Procedure)
301 and then Nkind (Decl) = N_Subprogram_Declaration
303 Set_Body_To_Inline (Decl, Old_S);
306 -- The body generated for this renaming is an internal artifact, and
307 -- does not constitute a freeze point for the called entity.
309 Set_Must_Not_Freeze (Call_Name);
311 Formal := First_Formal (Defining_Entity (Decl));
313 if Present (Formal) then
316 while Present (Formal) loop
317 Append (New_Reference_To (Formal, Loc), Actuals);
318 Next_Formal (Formal);
322 -- If the renamed entity is an entry, inherit its profile. For
323 -- other renamings as bodies, both profiles must be subtype
324 -- conformant, so it is not necessary to replace the profile given
325 -- in the declaration. However, default values that are aggregates
326 -- are rewritten when partially analyzed, so we recover the original
327 -- aggregate to insure that subsequent conformity checking works.
328 -- Similarly, if the default expression was constant-folded, recover
329 -- the original expression.
331 Formal := First_Formal (Defining_Entity (Decl));
333 if Present (Formal) then
334 O_Formal := First_Formal (Old_S);
335 Param_Spec := First (Parameter_Specifications (Spec));
337 while Present (Formal) loop
338 if Is_Entry (Old_S) then
340 if Nkind (Parameter_Type (Param_Spec)) /=
343 Set_Etype (Formal, Etype (O_Formal));
344 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
347 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
348 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
349 Nkind (Default_Value (O_Formal))
351 Set_Expression (Param_Spec,
352 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
355 Next_Formal (Formal);
356 Next_Formal (O_Formal);
361 -- If the renamed entity is a function, the generated body contains a
362 -- return statement. Otherwise, build a procedure call. If the entity is
363 -- an entry, subsequent analysis of the call will transform it into the
364 -- proper entry or protected operation call. If the renamed entity is
365 -- a character literal, return it directly.
367 if Ekind (Old_S) = E_Function
368 or else Ekind (Old_S) = E_Operator
369 or else (Ekind (Old_S) = E_Subprogram_Type
370 and then Etype (Old_S) /= Standard_Void_Type)
373 Make_Return_Statement (Loc,
375 Make_Function_Call (Loc,
377 Parameter_Associations => Actuals));
379 elsif Ekind (Old_S) = E_Enumeration_Literal then
381 Make_Return_Statement (Loc,
382 Expression => New_Occurrence_Of (Old_S, Loc));
384 elsif Nkind (Nam) = N_Character_Literal then
386 Make_Return_Statement (Loc,
387 Expression => Call_Name);
391 Make_Procedure_Call_Statement (Loc,
393 Parameter_Associations => Actuals);
396 -- Create entities for subprogram body and formals
398 Set_Defining_Unit_Name (Spec,
399 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
401 Param_Spec := First (Parameter_Specifications (Spec));
403 while Present (Param_Spec) loop
404 Set_Defining_Identifier (Param_Spec,
405 Make_Defining_Identifier (Loc,
406 Chars => Chars (Defining_Identifier (Param_Spec))));
411 Make_Subprogram_Body (Loc,
412 Specification => Spec,
413 Declarations => New_List,
414 Handled_Statement_Sequence =>
415 Make_Handled_Sequence_Of_Statements (Loc,
416 Statements => New_List (Call_Node)));
418 if Nkind (Decl) /= N_Subprogram_Declaration then
420 Make_Subprogram_Declaration (Loc,
421 Specification => Specification (N)));
424 -- Link the body to the entity whose declaration it completes. If
425 -- the body is analyzed when the renamed entity is frozen, it may be
426 -- necessary to restore the proper scope (see package Exp_Ch13).
428 if Nkind (N) = N_Subprogram_Renaming_Declaration
429 and then Present (Corresponding_Spec (N))
431 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
433 Set_Corresponding_Spec (Body_Node, New_S);
437 end Build_Renamed_Body;
439 --------------------------
440 -- Check_Address_Clause --
441 --------------------------
443 procedure Check_Address_Clause (E : Entity_Id) is
444 Addr : constant Node_Id := Address_Clause (E);
446 Decl : constant Node_Id := Declaration_Node (E);
447 Typ : constant Entity_Id := Etype (E);
450 if Present (Addr) then
451 Expr := Expression (Addr);
453 -- If we have no initialization of any kind, then we don't
454 -- need to place any restrictions on the address clause, because
455 -- the object will be elaborated after the address clause is
456 -- evaluated. This happens if the declaration has no initial
457 -- expression, or the type has no implicit initialization, or
458 -- the object is imported.
460 -- The same holds for all initialized scalar types and all
461 -- access types. Packed bit arrays of size up to 64 are
462 -- represented using a modular type with an initialization
463 -- (to zero) and can be processed like other initialized
466 -- If the type is controlled, code to attach the object to a
467 -- finalization chain is generated at the point of declaration,
468 -- and therefore the elaboration of the object cannot be delayed:
469 -- the address expression must be a constant.
471 if (No (Expression (Decl))
472 and then not Controlled_Type (Typ)
474 (not Has_Non_Null_Base_Init_Proc (Typ)
475 or else Is_Imported (E)))
478 (Present (Expression (Decl))
479 and then Is_Scalar_Type (Typ))
485 (Is_Bit_Packed_Array (Typ)
487 Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
491 -- Otherwise, we require the address clause to be constant
492 -- because the call to the initialization procedure (or the
493 -- attach code) has to happen at the point of the declaration.
496 Check_Constant_Address_Clause (Expr, E);
497 Set_Has_Delayed_Freeze (E, False);
500 if not Error_Posted (Expr)
501 and then not Controlled_Type (Typ)
503 Warn_Overlay (Expr, Typ, Name (Addr));
506 end Check_Address_Clause;
508 -----------------------------
509 -- Check_Compile_Time_Size --
510 -----------------------------
512 procedure Check_Compile_Time_Size (T : Entity_Id) is
514 procedure Set_Small_Size (T : Entity_Id; S : Uint);
515 -- Sets the compile time known size (32 bits or less) in the Esize
516 -- field, of T checking for a size clause that was given which attempts
517 -- to give a smaller size.
519 function Size_Known (T : Entity_Id) return Boolean;
520 -- Recursive function that does all the work
522 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
523 -- If T is a constrained subtype, its size is not known if any of its
524 -- discriminant constraints is not static and it is not a null record.
525 -- The test is conservative and doesn't check that the components are
526 -- in fact constrained by non-static discriminant values. Could be made
533 procedure Set_Small_Size (T : Entity_Id; S : Uint) is
538 elsif Has_Size_Clause (T) then
539 if RM_Size (T) < S then
540 Error_Msg_Uint_1 := S;
542 ("size for & is too small, minimum is ^",
545 elsif Unknown_Esize (T) then
549 -- Set sizes if not set already
552 if Unknown_Esize (T) then
556 if Unknown_RM_Size (T) then
566 function Size_Known (T : Entity_Id) return Boolean is
574 if Size_Known_At_Compile_Time (T) then
577 elsif Is_Scalar_Type (T)
578 or else Is_Task_Type (T)
580 return not Is_Generic_Type (T);
582 elsif Is_Array_Type (T) then
583 if Ekind (T) = E_String_Literal_Subtype then
584 Set_Small_Size (T, Component_Size (T)
585 * String_Literal_Length (T));
588 elsif not Is_Constrained (T) then
591 -- Don't do any recursion on type with error posted, since
592 -- we may have a malformed type that leads us into a loop
594 elsif Error_Posted (T) then
597 elsif not Size_Known (Component_Type (T)) then
601 -- Check for all indexes static, and also compute possible
602 -- size (in case it is less than 32 and may be packable).
605 Esiz : Uint := Component_Size (T);
609 Index := First_Index (T);
610 while Present (Index) loop
611 if Nkind (Index) = N_Range then
612 Get_Index_Bounds (Index, Low, High);
614 elsif Error_Posted (Scalar_Range (Etype (Index))) then
618 Low := Type_Low_Bound (Etype (Index));
619 High := Type_High_Bound (Etype (Index));
622 if not Compile_Time_Known_Value (Low)
623 or else not Compile_Time_Known_Value (High)
624 or else Etype (Index) = Any_Type
629 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
641 Set_Small_Size (T, Esiz);
645 elsif Is_Access_Type (T) then
648 elsif Is_Private_Type (T)
649 and then not Is_Generic_Type (T)
650 and then Present (Underlying_Type (T))
652 -- Don't do any recursion on type with error posted, since
653 -- we may have a malformed type that leads us into a loop
655 if Error_Posted (T) then
658 return Size_Known (Underlying_Type (T));
661 elsif Is_Record_Type (T) then
663 -- A class-wide type is never considered to have a known size
665 if Is_Class_Wide_Type (T) then
668 -- A subtype of a variant record must not have non-static
669 -- discriminanted components.
671 elsif T /= Base_Type (T)
672 and then not Static_Discriminated_Components (T)
676 -- Don't do any recursion on type with error posted, since
677 -- we may have a malformed type that leads us into a loop
679 elsif Error_Posted (T) then
683 -- Now look at the components of the record
686 -- The following two variables are used to keep track of
687 -- the size of packed records if we can tell the size of
688 -- the packed record in the front end. Packed_Size_Known
689 -- is True if so far we can figure out the size. It is
690 -- initialized to True for a packed record, unless the
691 -- record has discriminants. The reason we eliminate the
692 -- discriminated case is that we don't know the way the
693 -- back end lays out discriminated packed records. If
694 -- Packed_Size_Known is True, then Packed_Size is the
695 -- size in bits so far.
697 Packed_Size_Known : Boolean :=
699 and then not Has_Discriminants (T);
701 Packed_Size : Uint := Uint_0;
704 -- Test for variant part present
706 if Has_Discriminants (T)
707 and then Present (Parent (T))
708 and then Nkind (Parent (T)) = N_Full_Type_Declaration
709 and then Nkind (Type_Definition (Parent (T))) =
711 and then not Null_Present (Type_Definition (Parent (T)))
712 and then Present (Variant_Part
713 (Component_List (Type_Definition (Parent (T)))))
715 -- If variant part is present, and type is unconstrained,
716 -- then we must have defaulted discriminants, or a size
717 -- clause must be present for the type, or else the size
718 -- is definitely not known at compile time.
720 if not Is_Constrained (T)
722 No (Discriminant_Default_Value
723 (First_Discriminant (T)))
724 and then Unknown_Esize (T)
730 -- Loop through components
732 Comp := First_Entity (T);
733 while Present (Comp) loop
734 if Ekind (Comp) = E_Component
736 Ekind (Comp) = E_Discriminant
738 Ctyp := Etype (Comp);
740 -- We do not know the packed size if there is a
741 -- component clause present (we possibly could,
742 -- but this would only help in the case of a record
743 -- with partial rep clauses. That's because in the
744 -- case of full rep clauses, the size gets figured
745 -- out anyway by a different circuit).
747 if Present (Component_Clause (Comp)) then
748 Packed_Size_Known := False;
751 -- We need to identify a component that is an array
752 -- where the index type is an enumeration type with
753 -- non-standard representation, and some bound of the
754 -- type depends on a discriminant.
756 -- This is because gigi computes the size by doing a
757 -- substituation of the appropriate discriminant value
758 -- in the size expression for the base type, and gigi
759 -- is not clever enough to evaluate the resulting
760 -- expression (which involves a call to rep_to_pos)
763 -- It would be nice if gigi would either recognize that
764 -- this expression can be computed at compile time, or
765 -- alternatively figured out the size from the subtype
766 -- directly, where all the information is at hand ???
768 if Is_Array_Type (Etype (Comp))
769 and then Present (Packed_Array_Type (Etype (Comp)))
772 Ocomp : constant Entity_Id :=
773 Original_Record_Component (Comp);
774 OCtyp : constant Entity_Id := Etype (Ocomp);
780 Ind := First_Index (OCtyp);
781 while Present (Ind) loop
782 Indtyp := Etype (Ind);
784 if Is_Enumeration_Type (Indtyp)
785 and then Has_Non_Standard_Rep (Indtyp)
787 Lo := Type_Low_Bound (Indtyp);
788 Hi := Type_High_Bound (Indtyp);
790 if Is_Entity_Name (Lo)
792 Ekind (Entity (Lo)) = E_Discriminant
796 elsif Is_Entity_Name (Hi)
798 Ekind (Entity (Hi)) = E_Discriminant
809 -- Clearly size of record is not known if the size of
810 -- one of the components is not known.
812 if not Size_Known (Ctyp) then
816 -- Accumulate packed size if possible
818 if Packed_Size_Known then
820 -- We can only deal with elementary types, since for
821 -- non-elementary components, alignment enters into
822 -- the picture, and we don't know enough to handle
823 -- proper alignment in this context. Packed arrays
824 -- count as elementary if the representation is a
827 if Is_Elementary_Type (Ctyp)
828 or else (Is_Array_Type (Ctyp)
830 Present (Packed_Array_Type (Ctyp))
832 Is_Modular_Integer_Type
833 (Packed_Array_Type (Ctyp)))
835 -- If RM_Size is known and static, then we can
836 -- keep accumulating the packed size.
838 if Known_Static_RM_Size (Ctyp) then
840 -- A little glitch, to be removed sometime ???
841 -- gigi does not understand zero sizes yet.
843 if RM_Size (Ctyp) = Uint_0 then
844 Packed_Size_Known := False;
846 -- Normal case where we can keep accumulating
847 -- the packed array size.
850 Packed_Size := Packed_Size + RM_Size (Ctyp);
853 -- If we have a field whose RM_Size is not known
854 -- then we can't figure out the packed size here.
857 Packed_Size_Known := False;
860 -- If we have a non-elementary type we can't figure
861 -- out the packed array size (alignment issues).
864 Packed_Size_Known := False;
872 if Packed_Size_Known then
873 Set_Small_Size (T, Packed_Size);
884 -------------------------------------
885 -- Static_Discriminated_Components --
886 -------------------------------------
888 function Static_Discriminated_Components
889 (T : Entity_Id) return Boolean
891 Constraint : Elmt_Id;
894 if Has_Discriminants (T)
895 and then Present (Discriminant_Constraint (T))
896 and then Present (First_Component (T))
898 Constraint := First_Elmt (Discriminant_Constraint (T));
899 while Present (Constraint) loop
900 if not Compile_Time_Known_Value (Node (Constraint)) then
904 Next_Elmt (Constraint);
909 end Static_Discriminated_Components;
911 -- Start of processing for Check_Compile_Time_Size
914 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
915 end Check_Compile_Time_Size;
917 -----------------------------
918 -- Check_Debug_Info_Needed --
919 -----------------------------
921 procedure Check_Debug_Info_Needed (T : Entity_Id) is
923 if Needs_Debug_Info (T) or else Debug_Info_Off (T) then
926 elsif Comes_From_Source (T)
927 or else Debug_Generated_Code
928 or else Debug_Flag_VV
930 Set_Debug_Info_Needed (T);
932 end Check_Debug_Info_Needed;
934 ----------------------------
935 -- Check_Strict_Alignment --
936 ----------------------------
938 procedure Check_Strict_Alignment (E : Entity_Id) is
942 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
943 Set_Strict_Alignment (E);
945 elsif Is_Array_Type (E) then
946 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
948 elsif Is_Record_Type (E) then
949 if Is_Limited_Record (E) then
950 Set_Strict_Alignment (E);
954 Comp := First_Component (E);
956 while Present (Comp) loop
957 if not Is_Type (Comp)
958 and then (Strict_Alignment (Etype (Comp))
959 or else Is_Aliased (Comp))
961 Set_Strict_Alignment (E);
965 Next_Component (Comp);
968 end Check_Strict_Alignment;
970 -------------------------
971 -- Check_Unsigned_Type --
972 -------------------------
974 procedure Check_Unsigned_Type (E : Entity_Id) is
975 Ancestor : Entity_Id;
980 if not Is_Discrete_Or_Fixed_Point_Type (E) then
984 -- Do not attempt to analyze case where range was in error
986 if Error_Posted (Scalar_Range (E)) then
990 -- The situation that is non trivial is something like
992 -- subtype x1 is integer range -10 .. +10;
993 -- subtype x2 is x1 range 0 .. V1;
994 -- subtype x3 is x2 range V2 .. V3;
995 -- subtype x4 is x3 range V4 .. V5;
997 -- where Vn are variables. Here the base type is signed, but we still
998 -- know that x4 is unsigned because of the lower bound of x2.
1000 -- The only way to deal with this is to look up the ancestor chain
1004 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1008 Lo_Bound := Type_Low_Bound (Ancestor);
1010 if Compile_Time_Known_Value (Lo_Bound) then
1012 if Expr_Rep_Value (Lo_Bound) >= 0 then
1013 Set_Is_Unsigned_Type (E, True);
1019 Ancestor := Ancestor_Subtype (Ancestor);
1021 -- If no ancestor had a static lower bound, go to base type
1023 if No (Ancestor) then
1025 -- Note: the reason we still check for a compile time known
1026 -- value for the base type is that at least in the case of
1027 -- generic formals, we can have bounds that fail this test,
1028 -- and there may be other cases in error situations.
1030 Btyp := Base_Type (E);
1032 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1036 Lo_Bound := Type_Low_Bound (Base_Type (E));
1038 if Compile_Time_Known_Value (Lo_Bound)
1039 and then Expr_Rep_Value (Lo_Bound) >= 0
1041 Set_Is_Unsigned_Type (E, True);
1048 end Check_Unsigned_Type;
1050 -----------------------------
1051 -- Expand_Atomic_Aggregate --
1052 -----------------------------
1054 procedure Expand_Atomic_Aggregate (E : Entity_Id; Typ : Entity_Id) is
1055 Loc : constant Source_Ptr := Sloc (E);
1060 if (Nkind (Parent (E)) = N_Object_Declaration
1061 or else Nkind (Parent (E)) = N_Assignment_Statement)
1062 and then Comes_From_Source (Parent (E))
1063 and then Nkind (E) = N_Aggregate
1066 Make_Defining_Identifier (Loc,
1067 New_Internal_Name ('T'));
1070 Make_Object_Declaration (Loc,
1071 Defining_Identifier => Temp,
1072 Object_definition => New_Occurrence_Of (Typ, Loc),
1073 Expression => Relocate_Node (E));
1074 Insert_Before (Parent (E), New_N);
1077 Set_Expression (Parent (E), New_Occurrence_Of (Temp, Loc));
1079 -- To prevent the temporary from being constant-folded (which
1080 -- would lead to the same piecemeal assignment on the original
1081 -- target) indicate to the back-end that the temporary is a
1082 -- variable with real storage. See description of this flag
1083 -- in Einfo, and the notes on N_Assignment_Statement and
1084 -- N_Object_Declaration in Sinfo.
1086 Set_Is_True_Constant (Temp, False);
1088 end Expand_Atomic_Aggregate;
1094 -- Note: the easy coding for this procedure would be to just build a
1095 -- single list of freeze nodes and then insert them and analyze them
1096 -- all at once. This won't work, because the analysis of earlier freeze
1097 -- nodes may recursively freeze types which would otherwise appear later
1098 -- on in the freeze list. So we must analyze and expand the freeze nodes
1099 -- as they are generated.
1101 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1102 Loc : constant Source_Ptr := Sloc (After);
1106 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1107 -- This is the internal recursive routine that does freezing of
1108 -- entities (but NOT the analysis of default expressions, which
1109 -- should not be recursive, we don't want to analyze those till
1110 -- we are sure that ALL the types are frozen).
1112 --------------------
1113 -- Freeze_All_Ent --
1114 --------------------
1116 procedure Freeze_All_Ent
1118 After : in out Node_Id)
1124 procedure Process_Flist;
1125 -- If freeze nodes are present, insert and analyze, and reset
1126 -- cursor for next insertion.
1132 procedure Process_Flist is
1134 if Is_Non_Empty_List (Flist) then
1135 Lastn := Next (After);
1136 Insert_List_After_And_Analyze (After, Flist);
1138 if Present (Lastn) then
1139 After := Prev (Lastn);
1141 After := Last (List_Containing (After));
1146 -- Start or processing for Freeze_All_Ent
1150 while Present (E) loop
1152 -- If the entity is an inner package which is not a package
1153 -- renaming, then its entities must be frozen at this point.
1154 -- Note that such entities do NOT get frozen at the end of
1155 -- the nested package itself (only library packages freeze).
1157 -- Same is true for task declarations, where anonymous records
1158 -- created for entry parameters must be frozen.
1160 if Ekind (E) = E_Package
1161 and then No (Renamed_Object (E))
1162 and then not Is_Child_Unit (E)
1163 and then not Is_Frozen (E)
1166 Install_Visible_Declarations (E);
1167 Install_Private_Declarations (E);
1169 Freeze_All (First_Entity (E), After);
1171 End_Package_Scope (E);
1173 elsif Ekind (E) in Task_Kind
1175 (Nkind (Parent (E)) = N_Task_Type_Declaration
1177 Nkind (Parent (E)) = N_Single_Task_Declaration)
1180 Freeze_All (First_Entity (E), After);
1183 -- For a derived tagged type, we must ensure that all the
1184 -- primitive operations of the parent have been frozen, so
1185 -- that their addresses will be in the parent's dispatch table
1186 -- at the point it is inherited.
1188 elsif Ekind (E) = E_Record_Type
1189 and then Is_Tagged_Type (E)
1190 and then Is_Tagged_Type (Etype (E))
1191 and then Is_Derived_Type (E)
1194 Prim_List : constant Elist_Id :=
1195 Primitive_Operations (Etype (E));
1201 Prim := First_Elmt (Prim_List);
1203 while Present (Prim) loop
1204 Subp := Node (Prim);
1206 if Comes_From_Source (Subp)
1207 and then not Is_Frozen (Subp)
1209 Flist := Freeze_Entity (Subp, Loc);
1218 if not Is_Frozen (E) then
1219 Flist := Freeze_Entity (E, Loc);
1223 -- If an incomplete type is still not frozen, this may be
1224 -- a premature freezing because of a body declaration that
1225 -- follows. Indicate where the freezing took place.
1227 -- If the freezing is caused by the end of the current
1228 -- declarative part, it is a Taft Amendment type, and there
1231 if not Is_Frozen (E)
1232 and then Ekind (E) = E_Incomplete_Type
1235 Bod : constant Node_Id := Next (After);
1238 if (Nkind (Bod) = N_Subprogram_Body
1239 or else Nkind (Bod) = N_Entry_Body
1240 or else Nkind (Bod) = N_Package_Body
1241 or else Nkind (Bod) = N_Protected_Body
1242 or else Nkind (Bod) = N_Task_Body
1243 or else Nkind (Bod) in N_Body_Stub)
1245 List_Containing (After) = List_Containing (Parent (E))
1247 Error_Msg_Sloc := Sloc (Next (After));
1249 ("type& is frozen# before its full declaration",
1259 -- Start of processing for Freeze_All
1262 Freeze_All_Ent (From, After);
1264 -- Now that all types are frozen, we can deal with default expressions
1265 -- that require us to build a default expression functions. This is the
1266 -- point at which such functions are constructed (after all types that
1267 -- might be used in such expressions have been frozen).
1269 -- We also add finalization chains to access types whose designated
1270 -- types are controlled. This is normally done when freezing the type,
1271 -- but this misses recursive type definitions where the later members
1272 -- of the recursion introduce controlled components (e.g. 5624-001).
1274 -- Loop through entities
1277 while Present (E) loop
1278 if Is_Subprogram (E) then
1280 if not Default_Expressions_Processed (E) then
1281 Process_Default_Expressions (E, After);
1284 if not Has_Completion (E) then
1285 Decl := Unit_Declaration_Node (E);
1287 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1288 Build_And_Analyze_Renamed_Body (Decl, E, After);
1290 elsif Nkind (Decl) = N_Subprogram_Declaration
1291 and then Present (Corresponding_Body (Decl))
1293 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1294 = N_Subprogram_Renaming_Declaration
1296 Build_And_Analyze_Renamed_Body
1297 (Decl, Corresponding_Body (Decl), After);
1301 elsif Ekind (E) in Task_Kind
1303 (Nkind (Parent (E)) = N_Task_Type_Declaration
1305 Nkind (Parent (E)) = N_Single_Task_Declaration)
1310 Ent := First_Entity (E);
1312 while Present (Ent) loop
1315 and then not Default_Expressions_Processed (Ent)
1317 Process_Default_Expressions (Ent, After);
1324 elsif Is_Access_Type (E)
1325 and then Comes_From_Source (E)
1326 and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
1327 and then Controlled_Type (Designated_Type (E))
1328 and then No (Associated_Final_Chain (E))
1330 Build_Final_List (Parent (E), E);
1337 -----------------------
1338 -- Freeze_And_Append --
1339 -----------------------
1341 procedure Freeze_And_Append
1344 Result : in out List_Id)
1346 L : constant List_Id := Freeze_Entity (Ent, Loc);
1348 if Is_Non_Empty_List (L) then
1349 if Result = No_List then
1352 Append_List (L, Result);
1355 end Freeze_And_Append;
1361 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1362 Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
1364 if Is_Non_Empty_List (Freeze_Nodes) then
1365 Insert_Actions (N, Freeze_Nodes);
1373 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
1374 Test_E : Entity_Id := E;
1382 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1383 -- Check that an Access or Unchecked_Access attribute with a prefix
1384 -- which is the current instance type can only be applied when the type
1387 function After_Last_Declaration return Boolean;
1388 -- If Loc is a freeze_entity that appears after the last declaration
1389 -- in the scope, inhibit error messages on late completion.
1391 procedure Freeze_Record_Type (Rec : Entity_Id);
1392 -- Freeze each component, handle some representation clauses, and freeze
1393 -- primitive operations if this is a tagged type.
1395 ----------------------------
1396 -- After_Last_Declaration --
1397 ----------------------------
1399 function After_Last_Declaration return Boolean is
1400 Spec : constant Node_Id := Parent (Current_Scope);
1403 if Nkind (Spec) = N_Package_Specification then
1404 if Present (Private_Declarations (Spec)) then
1405 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1407 elsif Present (Visible_Declarations (Spec)) then
1408 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1416 end After_Last_Declaration;
1418 ----------------------------
1419 -- Check_Current_Instance --
1420 ----------------------------
1422 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1424 function Process (N : Node_Id) return Traverse_Result;
1425 -- Process routine to apply check to given node
1431 function Process (N : Node_Id) return Traverse_Result is
1434 when N_Attribute_Reference =>
1435 if (Attribute_Name (N) = Name_Access
1437 Attribute_Name (N) = Name_Unchecked_Access)
1438 and then Is_Entity_Name (Prefix (N))
1439 and then Is_Type (Entity (Prefix (N)))
1440 and then Entity (Prefix (N)) = E
1443 ("current instance must be a limited type", Prefix (N));
1449 when others => return OK;
1453 procedure Traverse is new Traverse_Proc (Process);
1455 -- Start of processing for Check_Current_Instance
1458 Traverse (Comp_Decl);
1459 end Check_Current_Instance;
1461 ------------------------
1462 -- Freeze_Record_Type --
1463 ------------------------
1465 procedure Freeze_Record_Type (Rec : Entity_Id) is
1472 Unplaced_Component : Boolean := False;
1473 -- Set True if we find at least one component with no component
1474 -- clause (used to warn about useless Pack pragmas).
1476 Placed_Component : Boolean := False;
1477 -- Set True if we find at least one component with a component
1478 -- clause (used to warn about useless Bit_Order pragmas).
1480 procedure Check_Itype (Desig : Entity_Id);
1481 -- If the component subtype is an access to a constrained subtype
1482 -- of an already frozen type, make the subtype frozen as well. It
1483 -- might otherwise be frozen in the wrong scope, and a freeze node
1484 -- on subtype has no effect.
1490 procedure Check_Itype (Desig : Entity_Id) is
1492 if not Is_Frozen (Desig)
1493 and then Is_Frozen (Base_Type (Desig))
1495 Set_Is_Frozen (Desig);
1497 -- In addition, add an Itype_Reference to ensure that the
1498 -- access subtype is elaborated early enough. This cannot
1499 -- be done if the subtype may depend on discriminants.
1501 if Ekind (Comp) = E_Component
1502 and then Is_Itype (Etype (Comp))
1503 and then not Has_Discriminants (Rec)
1505 IR := Make_Itype_Reference (Sloc (Comp));
1506 Set_Itype (IR, Desig);
1509 Result := New_List (IR);
1511 Append (IR, Result);
1517 -- Start of processing for Freeze_Record_Type
1520 -- If this is a subtype of a controlled type, declared without
1521 -- a constraint, the _controller may not appear in the component
1522 -- list if the parent was not frozen at the point of subtype
1523 -- declaration. Inherit the _controller component now.
1525 if Rec /= Base_Type (Rec)
1526 and then Has_Controlled_Component (Rec)
1528 if Nkind (Parent (Rec)) = N_Subtype_Declaration
1529 and then Is_Entity_Name (Subtype_Indication (Parent (Rec)))
1531 Set_First_Entity (Rec, First_Entity (Base_Type (Rec)));
1533 -- If this is an internal type without a declaration, as for
1534 -- record component, the base type may not yet be frozen, and its
1535 -- controller has not been created. Add an explicit freeze node
1536 -- for the itype, so it will be frozen after the base type. This
1537 -- freeze node is used to communicate with the expander, in order
1538 -- to create the controller for the enclosing record, and it is
1539 -- deleted afterwards (see exp_ch3). It must not be created when
1540 -- expansion is off, because it might appear in the wrong context
1541 -- for the back end.
1543 elsif Is_Itype (Rec)
1544 and then Has_Delayed_Freeze (Base_Type (Rec))
1546 Nkind (Associated_Node_For_Itype (Rec)) =
1547 N_Component_Declaration
1548 and then Expander_Active
1550 Ensure_Freeze_Node (Rec);
1554 -- Freeze components and embedded subtypes
1556 Comp := First_Entity (Rec);
1559 while Present (Comp) loop
1561 -- First handle the (real) component case
1563 if Ekind (Comp) = E_Component
1564 or else Ekind (Comp) = E_Discriminant
1567 CC : constant Node_Id := Component_Clause (Comp);
1570 -- Freezing a record type freezes the type of each of its
1571 -- components. However, if the type of the component is
1572 -- part of this record, we do not want or need a separate
1573 -- Freeze_Node. Note that Is_Itype is wrong because that's
1574 -- also set in private type cases. We also can't check for
1575 -- the Scope being exactly Rec because of private types and
1576 -- record extensions.
1578 if Is_Itype (Etype (Comp))
1579 and then Is_Record_Type (Underlying_Type
1580 (Scope (Etype (Comp))))
1582 Undelay_Type (Etype (Comp));
1585 Freeze_And_Append (Etype (Comp), Loc, Result);
1587 -- Check for error of component clause given for variable
1588 -- sized type. We have to delay this test till this point,
1589 -- since the component type has to be frozen for us to know
1590 -- if it is variable length. We omit this test in a generic
1591 -- context, it will be applied at instantiation time.
1593 if Present (CC) then
1594 Placed_Component := True;
1596 if Inside_A_Generic then
1599 elsif not Size_Known_At_Compile_Time
1600 (Underlying_Type (Etype (Comp)))
1603 ("component clause not allowed for variable " &
1604 "length component", CC);
1608 Unplaced_Component := True;
1611 -- Case of component requires byte alignment
1613 if Must_Be_On_Byte_Boundary (Etype (Comp)) then
1615 -- Set the enclosing record to also require byte align
1617 Set_Must_Be_On_Byte_Boundary (Rec);
1619 -- Check for component clause that is inconsistent
1620 -- with the required byte boundary alignment.
1623 and then Normalized_First_Bit (Comp) mod
1624 System_Storage_Unit /= 0
1627 ("component & must be byte aligned",
1628 Component_Name (Component_Clause (Comp)));
1632 -- If component clause is present, then deal with the
1633 -- non-default bit order case. We cannot do this before
1634 -- the freeze point, because there is no required order
1635 -- for the component clause and the bit_order clause.
1637 -- We only do this processing for the base type, and in
1638 -- fact that's important, since otherwise if there are
1639 -- record subtypes, we could reverse the bits once for
1640 -- each subtype, which would be incorrect.
1643 and then Reverse_Bit_Order (Rec)
1644 and then Ekind (E) = E_Record_Type
1647 CFB : constant Uint := Component_Bit_Offset (Comp);
1648 CSZ : constant Uint := Esize (Comp);
1649 CLC : constant Node_Id := Component_Clause (Comp);
1650 Pos : constant Node_Id := Position (CLC);
1651 FB : constant Node_Id := First_Bit (CLC);
1653 Storage_Unit_Offset : constant Uint :=
1654 CFB / System_Storage_Unit;
1656 Start_Bit : constant Uint :=
1657 CFB mod System_Storage_Unit;
1660 -- Cases where field goes over storage unit boundary
1662 if Start_Bit + CSZ > System_Storage_Unit then
1664 -- Allow multi-byte field but generate warning
1666 if Start_Bit mod System_Storage_Unit = 0
1667 and then CSZ mod System_Storage_Unit = 0
1670 ("multi-byte field specified with non-standard"
1671 & " Bit_Order?", CLC);
1673 if Bytes_Big_Endian then
1675 ("bytes are not reversed "
1676 & "(component is big-endian)?", CLC);
1679 ("bytes are not reversed "
1680 & "(component is little-endian)?", CLC);
1683 -- Do not allow non-contiguous field
1687 ("attempt to specify non-contiguous field"
1688 & " not permitted", CLC);
1690 ("\(caused by non-standard Bit_Order "
1691 & "specified)", CLC);
1694 -- Case where field fits in one storage unit
1697 -- Give warning if suspicious component clause
1699 if Intval (FB) >= System_Storage_Unit then
1701 ("?Bit_Order clause does not affect " &
1702 "byte ordering", Pos);
1704 Intval (Pos) + Intval (FB) /
1705 System_Storage_Unit;
1707 ("?position normalized to ^ before bit " &
1708 "order interpreted", Pos);
1711 -- Here is where we fix up the Component_Bit_Offset
1712 -- value to account for the reverse bit order.
1713 -- Some examples of what needs to be done are:
1715 -- First_Bit .. Last_Bit Component_Bit_Offset
1718 -- 0 .. 0 7 .. 7 0 7
1719 -- 0 .. 1 6 .. 7 0 6
1720 -- 0 .. 2 5 .. 7 0 5
1721 -- 0 .. 7 0 .. 7 0 4
1723 -- 1 .. 1 6 .. 6 1 6
1724 -- 1 .. 4 3 .. 6 1 3
1725 -- 4 .. 7 0 .. 3 4 0
1727 -- The general rule is that the first bit is
1728 -- is obtained by subtracting the old ending bit
1729 -- from storage_unit - 1.
1731 Set_Component_Bit_Offset
1733 (Storage_Unit_Offset * System_Storage_Unit) +
1734 (System_Storage_Unit - 1) -
1735 (Start_Bit + CSZ - 1));
1737 Set_Normalized_First_Bit
1739 Component_Bit_Offset (Comp) mod
1740 System_Storage_Unit);
1747 -- If the component is an Itype with Delayed_Freeze and is either
1748 -- a record or array subtype and its base type has not yet been
1749 -- frozen, we must remove this from the entity list of this
1750 -- record and put it on the entity list of the scope of its base
1751 -- type. Note that we know that this is not the type of a
1752 -- component since we cleared Has_Delayed_Freeze for it in the
1753 -- previous loop. Thus this must be the Designated_Type of an
1754 -- access type, which is the type of a component.
1757 and then Is_Type (Scope (Comp))
1758 and then Is_Composite_Type (Comp)
1759 and then Base_Type (Comp) /= Comp
1760 and then Has_Delayed_Freeze (Comp)
1761 and then not Is_Frozen (Base_Type (Comp))
1764 Will_Be_Frozen : Boolean := False;
1765 S : Entity_Id := Scope (Rec);
1768 -- We have a pretty bad kludge here. Suppose Rec is a
1769 -- subtype being defined in a subprogram that's created
1770 -- as part of the freezing of Rec'Base. In that case,
1771 -- we know that Comp'Base must have already been frozen by
1772 -- the time we get to elaborate this because Gigi doesn't
1773 -- elaborate any bodies until it has elaborated all of the
1774 -- declarative part. But Is_Frozen will not be set at this
1775 -- point because we are processing code in lexical order.
1777 -- We detect this case by going up the Scope chain of
1778 -- Rec and seeing if we have a subprogram scope before
1779 -- reaching the top of the scope chain or that of Comp'Base.
1780 -- If we do, then mark that Comp'Base will actually be
1781 -- frozen. If so, we merely undelay it.
1783 while Present (S) loop
1784 if Is_Subprogram (S) then
1785 Will_Be_Frozen := True;
1787 elsif S = Scope (Base_Type (Comp)) then
1794 if Will_Be_Frozen then
1795 Undelay_Type (Comp);
1797 if Present (Prev) then
1798 Set_Next_Entity (Prev, Next_Entity (Comp));
1800 Set_First_Entity (Rec, Next_Entity (Comp));
1803 -- Insert in entity list of scope of base type (which
1804 -- must be an enclosing scope, because still unfrozen).
1806 Append_Entity (Comp, Scope (Base_Type (Comp)));
1810 -- If the component is an access type with an allocator as
1811 -- default value, the designated type will be frozen by the
1812 -- corresponding expression in init_proc. In order to place the
1813 -- freeze node for the designated type before that for the
1814 -- current record type, freeze it now.
1816 -- Same process if the component is an array of access types,
1817 -- initialized with an aggregate. If the designated type is
1818 -- private, it cannot contain allocators, and it is premature to
1819 -- freeze the type, so we check for this as well.
1821 elsif Is_Access_Type (Etype (Comp))
1822 and then Present (Parent (Comp))
1823 and then Present (Expression (Parent (Comp)))
1824 and then Nkind (Expression (Parent (Comp))) = N_Allocator
1827 Alloc : constant Node_Id := Expression (Parent (Comp));
1830 -- If component is pointer to a classwide type, freeze
1831 -- the specific type in the expression being allocated.
1832 -- The expression may be a subtype indication, in which
1833 -- case freeze the subtype mark.
1835 if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
1836 if Is_Entity_Name (Expression (Alloc)) then
1838 (Entity (Expression (Alloc)), Loc, Result);
1840 Nkind (Expression (Alloc)) = N_Subtype_Indication
1843 (Entity (Subtype_Mark (Expression (Alloc))),
1847 elsif Is_Itype (Designated_Type (Etype (Comp))) then
1848 Check_Itype (Designated_Type (Etype (Comp)));
1852 (Designated_Type (Etype (Comp)), Loc, Result);
1856 elsif Is_Access_Type (Etype (Comp))
1857 and then Is_Itype (Designated_Type (Etype (Comp)))
1859 Check_Itype (Designated_Type (Etype (Comp)));
1861 elsif Is_Array_Type (Etype (Comp))
1862 and then Is_Access_Type (Component_Type (Etype (Comp)))
1863 and then Present (Parent (Comp))
1864 and then Nkind (Parent (Comp)) = N_Component_Declaration
1865 and then Present (Expression (Parent (Comp)))
1866 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
1867 and then Is_Fully_Defined
1868 (Designated_Type (Component_Type (Etype (Comp))))
1872 (Component_Type (Etype (Comp))), Loc, Result);
1879 -- Check for useless pragma Bit_Order
1881 if not Placed_Component and then Reverse_Bit_Order (Rec) then
1882 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
1883 Error_Msg_N ("?Bit_Order specification has no effect", ADC);
1884 Error_Msg_N ("\?since no component clauses were specified", ADC);
1887 -- Check for useless pragma Pack when all components placed
1890 and then not Unplaced_Component
1891 and then Warn_On_Redundant_Constructs
1894 ("?pragma Pack has no effect, no unplaced components",
1895 Get_Rep_Pragma (Rec, Name_Pack));
1896 Set_Is_Packed (Rec, False);
1899 -- If this is the record corresponding to a remote type,
1900 -- freeze the remote type here since that is what we are
1901 -- semantically freezing. This prevents having the freeze
1902 -- node for that type in an inner scope.
1904 -- Also, Check for controlled components and unchecked unions.
1905 -- Finally, enforce the restriction that access attributes with
1906 -- a current instance prefix can only apply to limited types.
1908 if Ekind (Rec) = E_Record_Type then
1909 if Present (Corresponding_Remote_Type (Rec)) then
1911 (Corresponding_Remote_Type (Rec), Loc, Result);
1914 Comp := First_Component (Rec);
1915 while Present (Comp) loop
1916 if Has_Controlled_Component (Etype (Comp))
1917 or else (Chars (Comp) /= Name_uParent
1918 and then Is_Controlled (Etype (Comp)))
1919 or else (Is_Protected_Type (Etype (Comp))
1921 (Corresponding_Record_Type (Etype (Comp)))
1922 and then Has_Controlled_Component
1923 (Corresponding_Record_Type (Etype (Comp))))
1925 Set_Has_Controlled_Component (Rec);
1929 if Has_Unchecked_Union (Etype (Comp)) then
1930 Set_Has_Unchecked_Union (Rec);
1933 if Has_Per_Object_Constraint (Comp)
1934 and then not Is_Limited_Type (Rec)
1936 -- Scan component declaration for likely misuses of
1937 -- current instance, either in a constraint or in a
1938 -- default expression.
1940 Check_Current_Instance (Parent (Comp));
1943 Next_Component (Comp);
1947 Set_Component_Alignment_If_Not_Set (Rec);
1949 -- For first subtypes, check if there are any fixed-point
1950 -- fields with component clauses, where we must check the size.
1951 -- This is not done till the freeze point, since for fixed-point
1952 -- types, we do not know the size until the type is frozen.
1953 -- Similar processing applies to bit packed arrays.
1955 if Is_First_Subtype (Rec) then
1956 Comp := First_Component (Rec);
1958 while Present (Comp) loop
1959 if Present (Component_Clause (Comp))
1960 and then (Is_Fixed_Point_Type (Etype (Comp))
1962 Is_Bit_Packed_Array (Etype (Comp)))
1965 (Component_Name (Component_Clause (Comp)),
1971 Next_Component (Comp);
1974 end Freeze_Record_Type;
1976 -- Start of processing for Freeze_Entity
1979 -- We are going to test for various reasons why this entity need not be
1980 -- frozen here, but in the case of an Itype that's defined within a
1981 -- record, that test actually applies to the record.
1983 if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
1984 Test_E := Scope (E);
1985 elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
1986 and then Is_Record_Type (Underlying_Type (Scope (E)))
1988 Test_E := Underlying_Type (Scope (E));
1991 -- Do not freeze if already frozen since we only need one freeze node
1993 if Is_Frozen (E) then
1996 -- It is improper to freeze an external entity within a generic because
1997 -- its freeze node will appear in a non-valid context. The entity will
1998 -- be frozen in the proper scope after the current generic is analyzed.
2000 elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then
2003 -- Do not freeze a global entity within an inner scope created during
2004 -- expansion. A call to subprogram E within some internal procedure
2005 -- (a stream attribute for example) might require freezing E, but the
2006 -- freeze node must appear in the same declarative part as E itself.
2007 -- The two-pass elaboration mechanism in gigi guarantees that E will
2008 -- be frozen before the inner call is elaborated. We exclude constants
2009 -- from this test, because deferred constants may be frozen early, and
2010 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
2011 -- comes from source, or is a generic instance, then the freeze point
2012 -- is the one mandated by the language. and we freze the entity.
2014 elsif In_Open_Scopes (Scope (Test_E))
2015 and then Scope (Test_E) /= Current_Scope
2016 and then Ekind (Test_E) /= E_Constant
2019 S : Entity_Id := Current_Scope;
2022 while Present (S) loop
2023 if Is_Overloadable (S) then
2024 if Comes_From_Source (S)
2025 or else Is_Generic_Instance (S)
2037 -- Similarly, an inlined instance body may make reference to global
2038 -- entities, but these references cannot be the proper freezing point
2039 -- for them, and the the absence of inlining freezing will take place
2040 -- in their own scope. Normally instance bodies are analyzed after
2041 -- the enclosing compilation, and everything has been frozen at the
2042 -- proper place, but with front-end inlining an instance body is
2043 -- compiled before the end of the enclosing scope, and as a result
2044 -- out-of-order freezing must be prevented.
2046 elsif Front_End_Inlining
2047 and then In_Instance_Body
2048 and then Present (Scope (Test_E))
2051 S : Entity_Id := Scope (Test_E);
2054 while Present (S) loop
2055 if Is_Generic_Instance (S) then
2068 -- Here to freeze the entity
2073 -- Case of entity being frozen is other than a type
2075 if not Is_Type (E) then
2077 -- If entity is exported or imported and does not have an external
2078 -- name, now is the time to provide the appropriate default name.
2079 -- Skip this if the entity is stubbed, since we don't need a name
2080 -- for any stubbed routine.
2082 if (Is_Imported (E) or else Is_Exported (E))
2083 and then No (Interface_Name (E))
2084 and then Convention (E) /= Convention_Stubbed
2086 Set_Encoded_Interface_Name
2087 (E, Get_Default_External_Name (E));
2089 -- Special processing for atomic objects appearing in object decls
2092 and then Nkind (Parent (E)) = N_Object_Declaration
2093 and then Present (Expression (Parent (E)))
2096 Expr : constant Node_Id := Expression (Parent (E));
2099 -- If expression is an aggregate, assign to a temporary to
2100 -- ensure that the actual assignment is done atomically rather
2101 -- than component-wise (the assignment to the temp may be done
2102 -- component-wise, but that is harmless.
2104 if Nkind (Expr) = N_Aggregate then
2105 Expand_Atomic_Aggregate (Expr, Etype (E));
2107 -- If the expression is a reference to a record or array
2108 -- object entity, then reset Is_True_Constant to False so
2109 -- that the compiler will not optimize away the intermediate
2110 -- object, which we need in this case for the same reason
2111 -- (to ensure that the actual assignment is atomic, rather
2112 -- than component-wise).
2114 elsif Is_Entity_Name (Expr)
2115 and then (Is_Record_Type (Etype (Expr))
2117 Is_Array_Type (Etype (Expr)))
2119 Set_Is_True_Constant (Entity (Expr), False);
2124 -- For a subprogram, freeze all parameter types and also the return
2125 -- type (RM 13.14(14)). However skip this for internal subprograms.
2126 -- This is also the point where any extra formal parameters are
2127 -- created since we now know whether the subprogram will use
2128 -- a foreign convention.
2130 if Is_Subprogram (E) then
2131 if not Is_Internal (E) then
2134 Warn_Node : Node_Id;
2136 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean;
2137 -- Determines if given type entity is a fat pointer type
2138 -- used as an argument type or return type to a subprogram
2139 -- with C or C++ convention set.
2141 --------------------------
2142 -- Is_Fat_C_Access_Type --
2143 --------------------------
2145 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is
2147 return (Convention (E) = Convention_C
2149 Convention (E) = Convention_CPP)
2150 and then Is_Access_Type (T)
2151 and then Esize (T) > Ttypes.System_Address_Size;
2152 end Is_Fat_C_Ptr_Type;
2155 -- Loop through formals
2157 Formal := First_Formal (E);
2158 while Present (Formal) loop
2159 F_Type := Etype (Formal);
2160 Freeze_And_Append (F_Type, Loc, Result);
2162 if Is_Private_Type (F_Type)
2163 and then Is_Private_Type (Base_Type (F_Type))
2164 and then No (Full_View (Base_Type (F_Type)))
2165 and then not Is_Generic_Type (F_Type)
2166 and then not Is_Derived_Type (F_Type)
2168 -- If the type of a formal is incomplete, subprogram
2169 -- is being frozen prematurely. Within an instance
2170 -- (but not within a wrapper package) this is an
2171 -- an artifact of our need to regard the end of an
2172 -- instantiation as a freeze point. Otherwise it is
2173 -- a definite error.
2175 -- and then not Is_Wrapper_Package (Current_Scope) ???
2178 Set_Is_Frozen (E, False);
2181 elsif not After_Last_Declaration then
2182 Error_Msg_Node_1 := F_Type;
2184 ("type& must be fully defined before this point",
2189 -- Check bad use of fat C pointer
2191 if Warn_On_Export_Import and then
2192 Is_Fat_C_Ptr_Type (F_Type)
2194 Error_Msg_Qual_Level := 1;
2196 ("?type of & does not correspond to C pointer",
2198 Error_Msg_Qual_Level := 0;
2201 -- Check for unconstrained array in exported foreign
2204 if Convention (E) in Foreign_Convention
2205 and then not Is_Imported (E)
2206 and then Is_Array_Type (F_Type)
2207 and then not Is_Constrained (F_Type)
2208 and then Warn_On_Export_Import
2210 Error_Msg_Qual_Level := 1;
2212 -- If this is an inherited operation, place the
2213 -- warning on the derived type declaration, rather
2214 -- than on the original subprogram.
2216 if Nkind (Original_Node (Parent (E))) =
2217 N_Full_Type_Declaration
2219 Warn_Node := Parent (E);
2221 if Formal = First_Formal (E) then
2223 ("?in inherited operation&!", Warn_Node, E);
2226 Warn_Node := Formal;
2230 ("?type of argument& is unconstrained array",
2233 ("?foreign caller must pass bounds explicitly",
2235 Error_Msg_Qual_Level := 0;
2238 -- Ada 2005 (AI-326): Check wrong use of tag incomplete
2239 -- types with unknown discriminants. For example:
2241 -- type T (<>) is tagged;
2242 -- procedure P (X : access T); -- ERROR
2243 -- procedure P (X : T); -- ERROR
2245 if not From_With_Type (F_Type) then
2246 if Is_Access_Type (F_Type) then
2247 F_Type := Designated_Type (F_Type);
2250 if Ekind (F_Type) = E_Incomplete_Type
2251 and then Is_Tagged_Type (F_Type)
2252 and then not Is_Class_Wide_Type (F_Type)
2253 and then No (Full_View (F_Type))
2254 and then Unknown_Discriminants_Present
2256 and then No (Stored_Constraint (F_Type))
2259 ("(Ada 2005): invalid use of unconstrained tagged"
2260 & " incomplete type", E);
2264 Next_Formal (Formal);
2267 -- Check return type
2269 if Ekind (E) = E_Function then
2270 Freeze_And_Append (Etype (E), Loc, Result);
2272 if Warn_On_Export_Import
2273 and then Is_Fat_C_Ptr_Type (Etype (E))
2276 ("?return type of& does not correspond to C pointer",
2279 elsif Is_Array_Type (Etype (E))
2280 and then not Is_Constrained (Etype (E))
2281 and then not Is_Imported (E)
2282 and then Convention (E) in Foreign_Convention
2283 and then Warn_On_Export_Import
2286 ("?foreign convention function& should not " &
2287 "return unconstrained array", E);
2289 -- Ada 2005 (AI-326): Check wrong use of tagged
2292 -- type T is tagged;
2293 -- function F (X : Boolean) return T; -- ERROR
2295 elsif Ekind (Etype (E)) = E_Incomplete_Type
2296 and then Is_Tagged_Type (Etype (E))
2297 and then No (Full_View (Etype (E)))
2300 ("(Ada 2005): invalid use of tagged incomplete type",
2307 -- Must freeze its parent first if it is a derived subprogram
2309 if Present (Alias (E)) then
2310 Freeze_And_Append (Alias (E), Loc, Result);
2313 -- If the return type requires a transient scope, and we are on
2314 -- a target allowing functions to return with a depressed stack
2315 -- pointer, then we mark the function as requiring this treatment.
2317 if Ekind (E) = E_Function
2318 and then Functions_Return_By_DSP_On_Target
2319 and then Requires_Transient_Scope (Etype (E))
2321 Set_Function_Returns_With_DSP (E);
2324 if not Is_Internal (E) then
2325 Freeze_Subprogram (E);
2328 -- Here for other than a subprogram or type
2331 -- If entity has a type, and it is not a generic unit, then
2332 -- freeze it first (RM 13.14(10))
2334 if Present (Etype (E))
2335 and then Ekind (E) /= E_Generic_Function
2337 Freeze_And_Append (Etype (E), Loc, Result);
2340 -- Special processing for objects created by object declaration
2342 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
2344 -- For object created by object declaration, perform required
2345 -- categorization (preelaborate and pure) checks. Defer these
2346 -- checks to freeze time since pragma Import inhibits default
2347 -- initialization and thus pragma Import affects these checks.
2349 Validate_Object_Declaration (Declaration_Node (E));
2351 -- If there is an address clause, check it is valid
2353 Check_Address_Clause (E);
2355 -- For imported objects, set Is_Public unless there is also
2356 -- an address clause, which means that there is no external
2357 -- symbol needed for the Import (Is_Public may still be set
2358 -- for other unrelated reasons). Note that we delayed this
2359 -- processing till freeze time so that we can be sure not
2360 -- to set the flag if there is an address clause. If there
2361 -- is such a clause, then the only purpose of the import
2362 -- pragma is to suppress implicit initialization.
2365 and then not Present (Address_Clause (E))
2371 -- Check that a constant which has a pragma Volatile[_Components]
2372 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
2374 -- Note: Atomic[_Components] also sets Volatile[_Components]
2376 if Ekind (E) = E_Constant
2377 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
2378 and then not Is_Imported (E)
2380 -- Make sure we actually have a pragma, and have not merely
2381 -- inherited the indication from elsewhere (e.g. an address
2382 -- clause, which is not good enough in RM terms!)
2384 if Has_Rep_Pragma (E, Name_Atomic)
2386 Has_Rep_Pragma (E, Name_Atomic_Components)
2389 ("stand alone atomic constant must be " &
2390 "imported ('R'M 'C.6(13))", E);
2392 elsif Has_Rep_Pragma (E, Name_Volatile)
2394 Has_Rep_Pragma (E, Name_Volatile_Components)
2397 ("stand alone volatile constant must be " &
2398 "imported ('R'M 'C.6(13))", E);
2402 -- Static objects require special handling
2404 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
2405 and then Is_Statically_Allocated (E)
2407 Freeze_Static_Object (E);
2410 -- Remaining step is to layout objects
2412 if Ekind (E) = E_Variable
2414 Ekind (E) = E_Constant
2416 Ekind (E) = E_Loop_Parameter
2424 -- Case of a type or subtype being frozen
2427 -- The type may be defined in a generic unit. This can occur when
2428 -- freezing a generic function that returns the type (which is
2429 -- defined in a parent unit). It is clearly meaningless to freeze
2430 -- this type. However, if it is a subtype, its size may be determi-
2431 -- nable and used in subsequent checks, so might as well try to
2434 if Present (Scope (E))
2435 and then Is_Generic_Unit (Scope (E))
2437 Check_Compile_Time_Size (E);
2441 -- Deal with special cases of freezing for subtype
2443 if E /= Base_Type (E) then
2445 -- If ancestor subtype present, freeze that first.
2446 -- Note that this will also get the base type frozen.
2448 Atype := Ancestor_Subtype (E);
2450 if Present (Atype) then
2451 Freeze_And_Append (Atype, Loc, Result);
2453 -- Otherwise freeze the base type of the entity before
2454 -- freezing the entity itself, (RM 13.14(15)).
2456 elsif E /= Base_Type (E) then
2457 Freeze_And_Append (Base_Type (E), Loc, Result);
2460 -- For a derived type, freeze its parent type first (RM 13.14(15))
2462 elsif Is_Derived_Type (E) then
2463 Freeze_And_Append (Etype (E), Loc, Result);
2464 Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
2467 -- For array type, freeze index types and component type first
2468 -- before freezing the array (RM 13.14(15)).
2470 if Is_Array_Type (E) then
2472 Ctyp : constant Entity_Id := Component_Type (E);
2475 Non_Standard_Enum : Boolean := False;
2476 -- Set true if any of the index types is an enumeration
2477 -- type with a non-standard representation.
2480 Freeze_And_Append (Ctyp, Loc, Result);
2482 Indx := First_Index (E);
2483 while Present (Indx) loop
2484 Freeze_And_Append (Etype (Indx), Loc, Result);
2486 if Is_Enumeration_Type (Etype (Indx))
2487 and then Has_Non_Standard_Rep (Etype (Indx))
2489 Non_Standard_Enum := True;
2495 -- Processing that is done only for base types
2497 if Ekind (E) = E_Array_Type then
2499 -- Propagate flags for component type
2501 if Is_Controlled (Component_Type (E))
2502 or else Has_Controlled_Component (Ctyp)
2504 Set_Has_Controlled_Component (E);
2507 if Has_Unchecked_Union (Component_Type (E)) then
2508 Set_Has_Unchecked_Union (E);
2511 -- If packing was requested or if the component size was set
2512 -- explicitly, then see if bit packing is required. This
2513 -- processing is only done for base types, since all the
2514 -- representation aspects involved are type-related. This
2515 -- is not just an optimization, if we start processing the
2516 -- subtypes, they intefere with the settings on the base
2517 -- type (this is because Is_Packed has a slightly different
2518 -- meaning before and after freezing).
2525 if (Is_Packed (E) or else Has_Pragma_Pack (E))
2526 and then not Has_Atomic_Components (E)
2527 and then Known_Static_RM_Size (Ctyp)
2529 Csiz := UI_Max (RM_Size (Ctyp), 1);
2531 elsif Known_Component_Size (E) then
2532 Csiz := Component_Size (E);
2534 elsif not Known_Static_Esize (Ctyp) then
2538 Esiz := Esize (Ctyp);
2540 -- We can set the component size if it is less than
2541 -- 16, rounding it up to the next storage unit size.
2545 elsif Esiz <= 16 then
2551 -- Set component size up to match alignment if
2552 -- it would otherwise be less than the alignment.
2553 -- This deals with cases of types whose alignment
2554 -- exceeds their sizes (padded types).
2558 A : constant Uint := Alignment_In_Bits (Ctyp);
2569 if 1 <= Csiz and then Csiz <= 64 then
2571 -- We set the component size for all cases 1-64
2573 Set_Component_Size (Base_Type (E), Csiz);
2575 -- Check for base type of 8,16,32 bits, where the
2576 -- subtype has a length one less than the base type
2577 -- and is unsigned (e.g. Natural subtype of Integer)
2579 -- In such cases, if a component size was not set
2580 -- explicitly, then generate a warning.
2582 if Has_Pragma_Pack (E)
2583 and then not Has_Component_Size_Clause (E)
2585 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
2586 and then Esize (Base_Type (Ctyp)) = Csiz + 1
2588 Error_Msg_Uint_1 := Csiz;
2590 Get_Rep_Pragma (First_Subtype (E), Name_Pack);
2592 if Present (Pnod) then
2594 ("pragma Pack causes component size to be ^?",
2597 ("\use Component_Size to set desired value",
2602 -- Actual packing is not needed for 8,16,32,64
2603 -- Also not needed for 24 if alignment is 1
2609 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
2611 -- Here the array was requested to be packed, but
2612 -- the packing request had no effect, so Is_Packed
2615 -- Note: semantically this means that we lose
2616 -- track of the fact that a derived type inherited
2617 -- a pack pragma that was non-effective, but that
2620 -- We regard a Pack pragma as a request to set a
2621 -- representation characteristic, and this request
2624 Set_Is_Packed (Base_Type (E), False);
2626 -- In all other cases, packing is indeed needed
2629 Set_Has_Non_Standard_Rep (Base_Type (E));
2630 Set_Is_Bit_Packed_Array (Base_Type (E));
2631 Set_Is_Packed (Base_Type (E));
2636 -- Processing that is done only for subtypes
2639 -- Acquire alignment from base type
2641 if Unknown_Alignment (E) then
2642 Set_Alignment (E, Alignment (Base_Type (E)));
2646 -- For bit-packed arrays, check the size
2648 if Is_Bit_Packed_Array (E)
2649 and then Known_Esize (E)
2653 SizC : constant Node_Id := Size_Clause (E);
2656 -- It is not clear if it is possible to have no size
2657 -- clause at this stage, but this is not worth worrying
2658 -- about. Post the error on the entity name in the size
2659 -- clause if present, else on the type entity itself.
2661 if Present (SizC) then
2662 Check_Size (Name (SizC), E, Esize (E), Discard);
2664 Check_Size (E, E, Esize (E), Discard);
2669 -- Check one common case of a size given where the array
2670 -- needs to be packed, but was not so the size cannot be
2671 -- honored. This would of course be caught by the backend,
2672 -- and indeed we don't catch all cases. The point is that
2673 -- we can give a better error message in those cases that
2674 -- we do catch with the circuitry here.
2678 Ctyp : constant Entity_Id := Component_Type (E);
2681 if Present (Size_Clause (E))
2682 and then Known_Static_Esize (E)
2683 and then not Is_Bit_Packed_Array (E)
2684 and then not Has_Pragma_Pack (E)
2685 and then Number_Dimensions (E) = 1
2686 and then not Has_Component_Size_Clause (E)
2687 and then Known_Static_Esize (Ctyp)
2689 Get_Index_Bounds (First_Index (E), Lo, Hi);
2691 if Compile_Time_Known_Value (Lo)
2692 and then Compile_Time_Known_Value (Hi)
2693 and then Known_Static_RM_Size (Ctyp)
2694 and then RM_Size (Ctyp) < 64
2697 Lov : constant Uint := Expr_Value (Lo);
2698 Hiv : constant Uint := Expr_Value (Hi);
2699 Len : constant Uint :=
2700 UI_Max (Uint_0, Hiv - Lov + 1);
2701 Rsiz : constant Uint := RM_Size (Ctyp);
2703 -- What we are looking for here is the situation
2704 -- where the Esize given would be exactly right
2705 -- if there was a pragma Pack (resulting in the
2706 -- component size being the same as the RM_Size).
2707 -- Furthermore, the component type size must be
2708 -- an odd size (not a multiple of storage unit)
2711 if Esize (E) = Len * Rsiz
2712 and then Rsiz mod System_Storage_Unit /= 0
2715 ("size given for& too small",
2716 Size_Clause (E), E);
2718 ("\explicit pragma Pack is required",
2726 -- If any of the index types was an enumeration type with
2727 -- a non-standard rep clause, then we indicate that the
2728 -- array type is always packed (even if it is not bit packed).
2730 if Non_Standard_Enum then
2731 Set_Has_Non_Standard_Rep (Base_Type (E));
2732 Set_Is_Packed (Base_Type (E));
2735 Set_Component_Alignment_If_Not_Set (E);
2737 -- If the array is packed, we must create the packed array
2738 -- type to be used to actually implement the type. This is
2739 -- only needed for real array types (not for string literal
2740 -- types, since they are present only for the front end).
2743 and then Ekind (E) /= E_String_Literal_Subtype
2745 Create_Packed_Array_Type (E);
2746 Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
2748 -- Size information of packed array type is copied to the
2749 -- array type, since this is really the representation.
2751 Set_Size_Info (E, Packed_Array_Type (E));
2752 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
2755 -- For non-packed arrays set the alignment of the array
2756 -- to the alignment of the component type if it is unknown.
2757 -- Skip this in the atomic case, since atomic arrays may
2758 -- need larger alignments.
2760 if not Is_Packed (E)
2761 and then Unknown_Alignment (E)
2762 and then Known_Alignment (Ctyp)
2763 and then Known_Static_Component_Size (E)
2764 and then Known_Static_Esize (Ctyp)
2765 and then Esize (Ctyp) = Component_Size (E)
2766 and then not Is_Atomic (E)
2768 Set_Alignment (E, Alignment (Component_Type (E)));
2772 -- For a class-wide type, the corresponding specific type is
2773 -- frozen as well (RM 13.14(15))
2775 elsif Is_Class_Wide_Type (E) then
2776 Freeze_And_Append (Root_Type (E), Loc, Result);
2778 -- If the Class_Wide_Type is an Itype (when type is the anonymous
2779 -- parent of a derived type) and it is a library-level entity,
2780 -- generate an itype reference for it. Otherwise, its first
2781 -- explicit reference may be in an inner scope, which will be
2782 -- rejected by the back-end.
2785 and then Is_Compilation_Unit (Scope (E))
2788 Ref : constant Node_Id := Make_Itype_Reference (Loc);
2793 Result := New_List (Ref);
2795 Append (Ref, Result);
2800 -- The equivalent type associated with a class-wide subtype
2801 -- needs to be frozen to ensure that its layout is done.
2802 -- Class-wide subtypes are currently only frozen on targets
2803 -- requiring front-end layout (see New_Class_Wide_Subtype
2804 -- and Make_CW_Equivalent_Type in exp_util.adb).
2806 if Ekind (E) = E_Class_Wide_Subtype
2807 and then Present (Equivalent_Type (E))
2809 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2812 -- For a record (sub)type, freeze all the component types (RM
2813 -- 13.14(15). We test for E_Record_(sub)Type here, rather than
2814 -- using Is_Record_Type, because we don't want to attempt the
2815 -- freeze for the case of a private type with record extension
2816 -- (we will do that later when the full type is frozen).
2818 elsif Ekind (E) = E_Record_Type
2819 or else Ekind (E) = E_Record_Subtype
2821 Freeze_Record_Type (E);
2823 -- For a concurrent type, freeze corresponding record type. This
2824 -- does not correpond to any specific rule in the RM, but the
2825 -- record type is essentially part of the concurrent type.
2826 -- Freeze as well all local entities. This includes record types
2827 -- created for entry parameter blocks, and whatever local entities
2828 -- may appear in the private part.
2830 elsif Is_Concurrent_Type (E) then
2831 if Present (Corresponding_Record_Type (E)) then
2833 (Corresponding_Record_Type (E), Loc, Result);
2836 Comp := First_Entity (E);
2838 while Present (Comp) loop
2839 if Is_Type (Comp) then
2840 Freeze_And_Append (Comp, Loc, Result);
2842 elsif (Ekind (Comp)) /= E_Function then
2843 if Is_Itype (Etype (Comp))
2844 and then Underlying_Type (Scope (Etype (Comp))) = E
2846 Undelay_Type (Etype (Comp));
2849 Freeze_And_Append (Etype (Comp), Loc, Result);
2855 -- Private types are required to point to the same freeze node
2856 -- as their corresponding full views. The freeze node itself
2857 -- has to point to the partial view of the entity (because
2858 -- from the partial view, we can retrieve the full view, but
2859 -- not the reverse). However, in order to freeze correctly,
2860 -- we need to freeze the full view. If we are freezing at the
2861 -- end of a scope (or within the scope of the private type),
2862 -- the partial and full views will have been swapped, the
2863 -- full view appears first in the entity chain and the swapping
2864 -- mechanism ensures that the pointers are properly set (on
2867 -- If we encounter the partial view before the full view
2868 -- (e.g. when freezing from another scope), we freeze the
2869 -- full view, and then set the pointers appropriately since
2870 -- we cannot rely on swapping to fix things up (subtypes in an
2871 -- outer scope might not get swapped).
2873 elsif Is_Incomplete_Or_Private_Type (E)
2874 and then not Is_Generic_Type (E)
2876 -- Case of full view present
2878 if Present (Full_View (E)) then
2880 -- If full view has already been frozen, then no
2881 -- further processing is required
2883 if Is_Frozen (Full_View (E)) then
2885 Set_Has_Delayed_Freeze (E, False);
2886 Set_Freeze_Node (E, Empty);
2887 Check_Debug_Info_Needed (E);
2889 -- Otherwise freeze full view and patch the pointers
2890 -- so that the freeze node will elaborate both views
2895 Full : constant Entity_Id := Full_View (E);
2898 if Is_Private_Type (Full)
2899 and then Present (Underlying_Full_View (Full))
2902 (Underlying_Full_View (Full), Loc, Result);
2905 Freeze_And_Append (Full, Loc, Result);
2907 if Has_Delayed_Freeze (E) then
2908 F_Node := Freeze_Node (Full);
2910 if Present (F_Node) then
2911 Set_Freeze_Node (E, F_Node);
2912 Set_Entity (F_Node, E);
2915 -- {Incomplete,Private}_Subtypes
2916 -- with Full_Views constrained by discriminants
2918 Set_Has_Delayed_Freeze (E, False);
2919 Set_Freeze_Node (E, Empty);
2924 Check_Debug_Info_Needed (E);
2927 -- AI-117 requires that the convention of a partial view
2928 -- be the same as the convention of the full view. Note
2929 -- that this is a recognized breach of privacy, but it's
2930 -- essential for logical consistency of representation,
2931 -- and the lack of a rule in RM95 was an oversight.
2933 Set_Convention (E, Convention (Full_View (E)));
2935 Set_Size_Known_At_Compile_Time (E,
2936 Size_Known_At_Compile_Time (Full_View (E)));
2938 -- Size information is copied from the full view to the
2939 -- incomplete or private view for consistency
2941 -- We skip this is the full view is not a type. This is
2942 -- very strange of course, and can only happen as a result
2943 -- of certain illegalities, such as a premature attempt to
2944 -- derive from an incomplete type.
2946 if Is_Type (Full_View (E)) then
2947 Set_Size_Info (E, Full_View (E));
2948 Set_RM_Size (E, RM_Size (Full_View (E)));
2953 -- Case of no full view present. If entity is derived or subtype,
2954 -- it is safe to freeze, correctness depends on the frozen status
2955 -- of parent. Otherwise it is either premature usage, or a Taft
2956 -- amendment type, so diagnosis is at the point of use and the
2957 -- type might be frozen later.
2959 elsif E /= Base_Type (E)
2960 or else Is_Derived_Type (E)
2965 Set_Is_Frozen (E, False);
2969 -- For access subprogram, freeze types of all formals, the return
2970 -- type was already frozen, since it is the Etype of the function.
2972 elsif Ekind (E) = E_Subprogram_Type then
2973 Formal := First_Formal (E);
2974 while Present (Formal) loop
2975 Freeze_And_Append (Etype (Formal), Loc, Result);
2976 Next_Formal (Formal);
2979 -- If the return type requires a transient scope, and we are on
2980 -- a target allowing functions to return with a depressed stack
2981 -- pointer, then we mark the function as requiring this treatment.
2983 if Functions_Return_By_DSP_On_Target
2984 and then Requires_Transient_Scope (Etype (E))
2986 Set_Function_Returns_With_DSP (E);
2989 Freeze_Subprogram (E);
2991 -- AI-326: Check wrong use of tag incomplete type
2993 -- type T is tagged;
2994 -- type Acc is access function (X : T) return T; -- ERROR
2996 if Ekind (Etype (E)) = E_Incomplete_Type
2997 and then Is_Tagged_Type (Etype (E))
2998 and then No (Full_View (Etype (E)))
3001 ("(Ada 2005): invalid use of tagged incomplete type", E);
3004 -- For access to a protected subprogram, freeze the equivalent
3005 -- type (however this is not set if we are not generating code)
3006 -- or if this is an anonymous type used just for resolution).
3008 elsif Ekind (E) = E_Access_Protected_Subprogram_Type then
3010 -- AI-326: Check wrong use of tagged incomplete types
3012 -- type T is tagged;
3013 -- type As3D is access protected
3014 -- function (X : Float) return T; -- ERROR
3020 Etyp := Etype (Directly_Designated_Type (E));
3022 if Is_Class_Wide_Type (Etyp) then
3023 Etyp := Etype (Etyp);
3026 if Ekind (Etyp) = E_Incomplete_Type
3027 and then Is_Tagged_Type (Etyp)
3028 and then No (Full_View (Etyp))
3031 ("(Ada 2005): invalid use of tagged incomplete type", E);
3035 if Operating_Mode = Generate_Code
3036 and then Present (Equivalent_Type (E))
3038 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
3042 -- Generic types are never seen by the back-end, and are also not
3043 -- processed by the expander (since the expander is turned off for
3044 -- generic processing), so we never need freeze nodes for them.
3046 if Is_Generic_Type (E) then
3050 -- Some special processing for non-generic types to complete
3051 -- representation details not known till the freeze point.
3053 if Is_Fixed_Point_Type (E) then
3054 Freeze_Fixed_Point_Type (E);
3056 -- Some error checks required for ordinary fixed-point type.
3057 -- Defer these till the freeze-point since we need the small
3058 -- and range values. We only do these checks for base types
3060 if Is_Ordinary_Fixed_Point_Type (E)
3061 and then E = Base_Type (E)
3063 if Small_Value (E) < Ureal_2_M_80 then
3064 Error_Msg_Name_1 := Name_Small;
3066 ("`&''%` is too small, minimum is 2.0'*'*(-80)", E);
3068 elsif Small_Value (E) > Ureal_2_80 then
3069 Error_Msg_Name_1 := Name_Small;
3071 ("`&''%` is too large, maximum is 2.0'*'*80", E);
3074 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
3075 Error_Msg_Name_1 := Name_First;
3077 ("`&''%` is too small, minimum is -10.0'*'*36", E);
3080 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
3081 Error_Msg_Name_1 := Name_Last;
3083 ("`&''%` is too large, maximum is 10.0'*'*36", E);
3087 elsif Is_Enumeration_Type (E) then
3088 Freeze_Enumeration_Type (E);
3090 elsif Is_Integer_Type (E) then
3091 Adjust_Esize_For_Alignment (E);
3093 elsif Is_Access_Type (E) then
3095 -- Check restriction for standard storage pool
3097 if No (Associated_Storage_Pool (E)) then
3098 Check_Restriction (No_Standard_Storage_Pools, E);
3101 -- Deal with error message for pure access type. This is not an
3102 -- error in Ada 2005 if there is no pool (see AI-366).
3104 if Is_Pure_Unit_Access_Type (E)
3105 and then (Ada_Version < Ada_05
3106 or else not No_Pool_Assigned (E))
3108 Error_Msg_N ("named access type not allowed in pure unit", E);
3112 -- Case of composite types
3114 if Is_Composite_Type (E) then
3116 -- AI-117 requires that all new primitives of a tagged type must
3117 -- inherit the convention of the full view of the type. Inherited
3118 -- and overriding operations are defined to inherit the convention
3119 -- of their parent or overridden subprogram (also specified in
3120 -- AI-117), and that will have occurred earlier (in
3121 -- Derive_Subprogram and New_Overloaded_Entity). Here we set the
3122 -- convention of primitives that are still convention Ada, which
3123 -- will ensure that any new primitives inherit the type's
3124 -- convention. Class-wide types can have a foreign convention
3125 -- inherited from their specific type, but are excluded from this
3126 -- since they don't have any associated primitives.
3128 if Is_Tagged_Type (E)
3129 and then not Is_Class_Wide_Type (E)
3130 and then Convention (E) /= Convention_Ada
3133 Prim_List : constant Elist_Id := Primitive_Operations (E);
3136 Prim := First_Elmt (Prim_List);
3137 while Present (Prim) loop
3138 if Convention (Node (Prim)) = Convention_Ada then
3139 Set_Convention (Node (Prim), Convention (E));
3148 -- Generate primitive operation references for a tagged type
3150 if Is_Tagged_Type (E)
3151 and then not Is_Class_Wide_Type (E)
3154 Prim_List : Elist_Id;
3159 -- Ada 2005 (AI-345): In case of concurrent type generate
3160 -- reference to the wrapper that allow us to dispatch calls
3161 -- through their implemented abstract interface types.
3163 -- The check for Present here is to protect against previously
3164 -- reported critical errors.
3166 if Is_Concurrent_Type (E)
3167 and then Present (Corresponding_Record_Type (E))
3169 pragma Assert (not Is_Empty_Elmt_List
3170 (Abstract_Interfaces
3171 (Corresponding_Record_Type (E))));
3173 Prim_List := Primitive_Operations
3174 (Corresponding_Record_Type (E));
3176 Prim_List := Primitive_Operations (E);
3179 -- Loop to generate references for primitive operations
3181 Prim := First_Elmt (Prim_List);
3182 while Present (Prim) loop
3185 -- If the operation is derived, get the original for cross-
3186 -- reference purposes (it is the original for which we want
3187 -- the xref, and for which the comes from source test needs
3188 -- to be performed).
3190 while Present (Alias (Ent)) loop
3194 Generate_Reference (E, Ent, 'p', Set_Ref => False);
3198 -- If we get an exception, then something peculiar has happened
3199 -- probably as a result of a previous error. Since this is only
3200 -- for non-critical cross-references, ignore the error.
3203 when others => null;
3207 -- Now that all types from which E may depend are frozen, see
3208 -- if the size is known at compile time, if it must be unsigned,
3209 -- or if strict alignent is required
3211 Check_Compile_Time_Size (E);
3212 Check_Unsigned_Type (E);
3214 if Base_Type (E) = E then
3215 Check_Strict_Alignment (E);
3218 -- Do not allow a size clause for a type which does not have a size
3219 -- that is known at compile time
3221 if Has_Size_Clause (E)
3222 and then not Size_Known_At_Compile_Time (E)
3224 -- Supress this message if errors posted on E, even if we are
3225 -- in all errors mode, since this is often a junk message
3227 if not Error_Posted (E) then
3229 ("size clause not allowed for variable length type",
3234 -- Remaining process is to set/verify the representation information,
3235 -- in particular the size and alignment values. This processing is
3236 -- not required for generic types, since generic types do not play
3237 -- any part in code generation, and so the size and alignment values
3238 -- for such types are irrelevant.
3240 if Is_Generic_Type (E) then
3243 -- Otherwise we call the layout procedure
3249 -- End of freeze processing for type entities
3252 -- Here is where we logically freeze the current entity. If it has a
3253 -- freeze node, then this is the point at which the freeze node is
3254 -- linked into the result list.
3256 if Has_Delayed_Freeze (E) then
3258 -- If a freeze node is already allocated, use it, otherwise allocate
3259 -- a new one. The preallocation happens in the case of anonymous base
3260 -- types, where we preallocate so that we can set First_Subtype_Link.
3261 -- Note that we reset the Sloc to the current freeze location.
3263 if Present (Freeze_Node (E)) then
3264 F_Node := Freeze_Node (E);
3265 Set_Sloc (F_Node, Loc);
3268 F_Node := New_Node (N_Freeze_Entity, Loc);
3269 Set_Freeze_Node (E, F_Node);
3270 Set_Access_Types_To_Process (F_Node, No_Elist);
3271 Set_TSS_Elist (F_Node, No_Elist);
3272 Set_Actions (F_Node, No_List);
3275 Set_Entity (F_Node, E);
3277 if Result = No_List then
3278 Result := New_List (F_Node);
3280 Append (F_Node, Result);
3283 -- A final pass over record types with discriminants. If the type
3284 -- has an incomplete declaration, there may be constrained access
3285 -- subtypes declared elsewhere, which do not depend on the discrimi-
3286 -- nants of the type, and which are used as component types (i.e.
3287 -- the full view is a recursive type). The designated types of these
3288 -- subtypes can only be elaborated after the type itself, and they
3289 -- need an itype reference.
3291 if Ekind (E) = E_Record_Type
3292 and then Has_Discriminants (E)
3300 Comp := First_Component (E);
3302 while Present (Comp) loop
3303 Typ := Etype (Comp);
3305 if Ekind (Comp) = E_Component
3306 and then Is_Access_Type (Typ)
3307 and then Scope (Typ) /= E
3308 and then Base_Type (Designated_Type (Typ)) = E
3309 and then Is_Itype (Designated_Type (Typ))
3311 IR := Make_Itype_Reference (Sloc (Comp));
3312 Set_Itype (IR, Designated_Type (Typ));
3313 Append (IR, Result);
3316 Next_Component (Comp);
3322 -- When a type is frozen, the first subtype of the type is frozen as
3323 -- well (RM 13.14(15)). This has to be done after freezing the type,
3324 -- since obviously the first subtype depends on its own base type.
3327 Freeze_And_Append (First_Subtype (E), Loc, Result);
3329 -- If we just froze a tagged non-class wide record, then freeze the
3330 -- corresponding class-wide type. This must be done after the tagged
3331 -- type itself is frozen, because the class-wide type refers to the
3332 -- tagged type which generates the class.
3334 if Is_Tagged_Type (E)
3335 and then not Is_Class_Wide_Type (E)
3336 and then Present (Class_Wide_Type (E))
3338 Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
3342 Check_Debug_Info_Needed (E);
3344 -- Special handling for subprograms
3346 if Is_Subprogram (E) then
3348 -- If subprogram has address clause then reset Is_Public flag, since
3349 -- we do not want the backend to generate external references.
3351 if Present (Address_Clause (E))
3352 and then not Is_Library_Level_Entity (E)
3354 Set_Is_Public (E, False);
3356 -- If no address clause and not intrinsic, then for imported
3357 -- subprogram in main unit, generate descriptor if we are in
3358 -- Propagate_Exceptions mode.
3360 elsif Propagate_Exceptions
3361 and then Is_Imported (E)
3362 and then not Is_Intrinsic_Subprogram (E)
3363 and then Convention (E) /= Convention_Stubbed
3365 if Result = No_List then
3366 Result := Empty_List;
3369 Generate_Subprogram_Descriptor_For_Imported_Subprogram
3377 -----------------------------
3378 -- Freeze_Enumeration_Type --
3379 -----------------------------
3381 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
3383 if Has_Foreign_Convention (Typ)
3384 and then not Has_Size_Clause (Typ)
3385 and then Esize (Typ) < Standard_Integer_Size
3387 Init_Esize (Typ, Standard_Integer_Size);
3389 Adjust_Esize_For_Alignment (Typ);
3391 end Freeze_Enumeration_Type;
3393 -----------------------
3394 -- Freeze_Expression --
3395 -----------------------
3397 procedure Freeze_Expression (N : Node_Id) is
3398 In_Def_Exp : constant Boolean := In_Default_Expression;
3401 Desig_Typ : Entity_Id;
3405 Freeze_Outside : Boolean := False;
3406 -- This flag is set true if the entity must be frozen outside the
3407 -- current subprogram. This happens in the case of expander generated
3408 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
3409 -- not freeze all entities like other bodies, but which nevertheless
3410 -- may reference entities that have to be frozen before the body and
3411 -- obviously cannot be frozen inside the body.
3413 function In_Exp_Body (N : Node_Id) return Boolean;
3414 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
3415 -- it is the handled statement sequence of an expander-generated
3416 -- subprogram (init proc, or stream subprogram). If so, it returns
3417 -- True, otherwise False.
3423 function In_Exp_Body (N : Node_Id) return Boolean is
3427 if Nkind (N) = N_Subprogram_Body then
3433 if Nkind (P) /= N_Subprogram_Body then
3437 P := Defining_Unit_Name (Specification (P));
3439 if Nkind (P) = N_Defining_Identifier
3440 and then (Is_Init_Proc (P) or else
3441 Is_TSS (P, TSS_Stream_Input) or else
3442 Is_TSS (P, TSS_Stream_Output) or else
3443 Is_TSS (P, TSS_Stream_Read) or else
3444 Is_TSS (P, TSS_Stream_Write))
3453 -- Start of processing for Freeze_Expression
3456 -- Immediate return if freezing is inhibited. This flag is set by the
3457 -- analyzer to stop freezing on generated expressions that would cause
3458 -- freezing if they were in the source program, but which are not
3459 -- supposed to freeze, since they are created.
3461 if Must_Not_Freeze (N) then
3465 -- If expression is non-static, then it does not freeze in a default
3466 -- expression, see section "Handling of Default Expressions" in the
3467 -- spec of package Sem for further details. Note that we have to
3468 -- make sure that we actually have a real expression (if we have
3469 -- a subtype indication, we can't test Is_Static_Expression!)
3472 and then Nkind (N) in N_Subexpr
3473 and then not Is_Static_Expression (N)
3478 -- Freeze type of expression if not frozen already
3482 if Nkind (N) in N_Has_Etype then
3483 if not Is_Frozen (Etype (N)) then
3486 -- Base type may be an derived numeric type that is frozen at
3487 -- the point of declaration, but first_subtype is still unfrozen.
3489 elsif not Is_Frozen (First_Subtype (Etype (N))) then
3490 Typ := First_Subtype (Etype (N));
3494 -- For entity name, freeze entity if not frozen already. A special
3495 -- exception occurs for an identifier that did not come from source.
3496 -- We don't let such identifiers freeze a non-internal entity, i.e.
3497 -- an entity that did come from source, since such an identifier was
3498 -- generated by the expander, and cannot have any semantic effect on
3499 -- the freezing semantics. For example, this stops the parameter of
3500 -- an initialization procedure from freezing the variable.
3502 if Is_Entity_Name (N)
3503 and then not Is_Frozen (Entity (N))
3504 and then (Nkind (N) /= N_Identifier
3505 or else Comes_From_Source (N)
3506 or else not Comes_From_Source (Entity (N)))
3513 -- For an allocator freeze designated type if not frozen already
3515 -- For an aggregate whose component type is an access type, freeze
3516 -- the designated type now, so that its freeze does not appear within
3517 -- the loop that might be created in the expansion of the aggregate.
3518 -- If the designated type is a private type without full view, the
3519 -- expression cannot contain an allocator, so the type is not frozen.
3525 Desig_Typ := Designated_Type (Etype (N));
3528 if Is_Array_Type (Etype (N))
3529 and then Is_Access_Type (Component_Type (Etype (N)))
3531 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
3534 when N_Selected_Component |
3535 N_Indexed_Component |
3538 if Is_Access_Type (Etype (Prefix (N))) then
3539 Desig_Typ := Designated_Type (Etype (Prefix (N)));
3546 if Desig_Typ /= Empty
3547 and then (Is_Frozen (Desig_Typ)
3548 or else (not Is_Fully_Defined (Desig_Typ)))
3553 -- All done if nothing needs freezing
3557 and then No (Desig_Typ)
3562 -- Loop for looking at the right place to insert the freeze nodes
3563 -- exiting from the loop when it is appropriate to insert the freeze
3564 -- node before the current node P.
3566 -- Also checks some special exceptions to the freezing rules. These
3567 -- cases result in a direct return, bypassing the freeze action.
3571 Parent_P := Parent (P);
3573 -- If we don't have a parent, then we are not in a well-formed
3574 -- tree. This is an unusual case, but there are some legitimate
3575 -- situations in which this occurs, notably when the expressions
3576 -- in the range of a type declaration are resolved. We simply
3577 -- ignore the freeze request in this case. Is this right ???
3579 if No (Parent_P) then
3583 -- See if we have got to an appropriate point in the tree
3585 case Nkind (Parent_P) is
3587 -- A special test for the exception of (RM 13.14(8)) for the case
3588 -- of per-object expressions (RM 3.8(18)) occurring in component
3589 -- definition or a discrete subtype definition. Note that we test
3590 -- for a component declaration which includes both cases we are
3591 -- interested in, and furthermore the tree does not have explicit
3592 -- nodes for either of these two constructs.
3594 when N_Component_Declaration =>
3596 -- The case we want to test for here is an identifier that is
3597 -- a per-object expression, this is either a discriminant that
3598 -- appears in a context other than the component declaration
3599 -- or it is a reference to the type of the enclosing construct.
3601 -- For either of these cases, we skip the freezing
3603 if not In_Default_Expression
3604 and then Nkind (N) = N_Identifier
3605 and then (Present (Entity (N)))
3607 -- We recognize the discriminant case by just looking for
3608 -- a reference to a discriminant. It can only be one for
3609 -- the enclosing construct. Skip freezing in this case.
3611 if Ekind (Entity (N)) = E_Discriminant then
3614 -- For the case of a reference to the enclosing record,
3615 -- (or task or protected type), we look for a type that
3616 -- matches the current scope.
3618 elsif Entity (N) = Current_Scope then
3623 -- If we have an enumeration literal that appears as the choice in
3624 -- the aggregate of an enumeration representation clause, then
3625 -- freezing does not occur (RM 13.14(10)).
3627 when N_Enumeration_Representation_Clause =>
3629 -- The case we are looking for is an enumeration literal
3631 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
3632 and then Is_Enumeration_Type (Etype (N))
3634 -- If enumeration literal appears directly as the choice,
3635 -- do not freeze (this is the normal non-overloade case)
3637 if Nkind (Parent (N)) = N_Component_Association
3638 and then First (Choices (Parent (N))) = N
3642 -- If enumeration literal appears as the name of a
3643 -- function which is the choice, then also do not freeze.
3644 -- This happens in the overloaded literal case, where the
3645 -- enumeration literal is temporarily changed to a function
3646 -- call for overloading analysis purposes.
3648 elsif Nkind (Parent (N)) = N_Function_Call
3650 Nkind (Parent (Parent (N))) = N_Component_Association
3652 First (Choices (Parent (Parent (N)))) = Parent (N)
3658 -- Normally if the parent is a handled sequence of statements,
3659 -- then the current node must be a statement, and that is an
3660 -- appropriate place to insert a freeze node.
3662 when N_Handled_Sequence_Of_Statements =>
3664 -- An exception occurs when the sequence of statements is for
3665 -- an expander generated body that did not do the usual freeze
3666 -- all operation. In this case we usually want to freeze
3667 -- outside this body, not inside it, and we skip past the
3668 -- subprogram body that we are inside.
3670 if In_Exp_Body (Parent_P) then
3672 -- However, we *do* want to freeze at this point if we have
3673 -- an entity to freeze, and that entity is declared *inside*
3674 -- the body of the expander generated procedure. This case
3675 -- is recognized by the scope of the type, which is either
3676 -- the spec for some enclosing body, or (in the case of
3677 -- init_procs, for which there are no separate specs) the
3681 Subp : constant Node_Id := Parent (Parent_P);
3685 if Nkind (Subp) = N_Subprogram_Body then
3686 Cspc := Corresponding_Spec (Subp);
3688 if (Present (Typ) and then Scope (Typ) = Cspc)
3690 (Present (Nam) and then Scope (Nam) = Cspc)
3695 and then Scope (Typ) = Current_Scope
3696 and then Current_Scope = Defining_Entity (Subp)
3703 -- If not that exception to the exception, then this is
3704 -- where we delay the freeze till outside the body.
3706 Parent_P := Parent (Parent_P);
3707 Freeze_Outside := True;
3709 -- Here if normal case where we are in handled statement
3710 -- sequence and want to do the insertion right there.
3716 -- If parent is a body or a spec or a block, then the current
3717 -- node is a statement or declaration and we can insert the
3718 -- freeze node before it.
3720 when N_Package_Specification |
3726 N_Block_Statement => exit;
3728 -- The expander is allowed to define types in any statements list,
3729 -- so any of the following parent nodes also mark a freezing point
3730 -- if the actual node is in a list of statements or declarations.
3732 when N_Exception_Handler |
3735 N_Case_Statement_Alternative |
3736 N_Compilation_Unit_Aux |
3737 N_Selective_Accept |
3738 N_Accept_Alternative |
3739 N_Delay_Alternative |
3740 N_Conditional_Entry_Call |
3741 N_Entry_Call_Alternative |
3742 N_Triggering_Alternative |
3746 exit when Is_List_Member (P);
3748 -- Note: The N_Loop_Statement is a special case. A type that
3749 -- appears in the source can never be frozen in a loop (this
3750 -- occurs only because of a loop expanded by the expander), so we
3751 -- keep on going. Otherwise we terminate the search. Same is true
3752 -- of any entity which comes from source. (if they have a
3753 -- predefined type, that type does not appear to come from source,
3754 -- but the entity should not be frozen here).
3756 when N_Loop_Statement =>
3757 exit when not Comes_From_Source (Etype (N))
3758 and then (No (Nam) or else not Comes_From_Source (Nam));
3760 -- For all other cases, keep looking at parents
3766 -- We fall through the case if we did not yet find the proper
3767 -- place in the free for inserting the freeze node, so climb!
3772 -- If the expression appears in a record or an initialization procedure,
3773 -- the freeze nodes are collected and attached to the current scope, to
3774 -- be inserted and analyzed on exit from the scope, to insure that
3775 -- generated entities appear in the correct scope. If the expression is
3776 -- a default for a discriminant specification, the scope is still void.
3777 -- The expression can also appear in the discriminant part of a private
3778 -- or concurrent type.
3780 -- If the expression appears in a constrained subcomponent of an
3781 -- enclosing record declaration, the freeze nodes must be attached to
3782 -- the outer record type so they can eventually be placed in the
3783 -- enclosing declaration list.
3785 -- The other case requiring this special handling is if we are in
3786 -- a default expression, since in that case we are about to freeze
3787 -- a static type, and the freeze scope needs to be the outer scope,
3788 -- not the scope of the subprogram with the default parameter.
3790 -- For default expressions in generic units, the Move_Freeze_Nodes
3791 -- mechanism (see sem_ch12.adb) takes care of placing them at the
3792 -- proper place, after the generic unit.
3794 if (In_Def_Exp and not Inside_A_Generic)
3795 or else Freeze_Outside
3796 or else (Is_Type (Current_Scope)
3797 and then (not Is_Concurrent_Type (Current_Scope)
3798 or else not Has_Completion (Current_Scope)))
3799 or else Ekind (Current_Scope) = E_Void
3802 Loc : constant Source_Ptr := Sloc (Current_Scope);
3803 Freeze_Nodes : List_Id := No_List;
3804 Pos : Int := Scope_Stack.Last;
3807 if Present (Desig_Typ) then
3808 Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
3811 if Present (Typ) then
3812 Freeze_And_Append (Typ, Loc, Freeze_Nodes);
3815 if Present (Nam) then
3816 Freeze_And_Append (Nam, Loc, Freeze_Nodes);
3819 -- The current scope may be that of a constrained component of
3820 -- an enclosing record declaration, which is above the current
3821 -- scope in the scope stack.
3823 if Is_Record_Type (Scope (Current_Scope)) then
3827 if Is_Non_Empty_List (Freeze_Nodes) then
3828 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
3829 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
3832 Append_List (Freeze_Nodes, Scope_Stack.Table
3833 (Pos).Pending_Freeze_Actions);
3841 -- Now we have the right place to do the freezing. First, a special
3842 -- adjustment, if we are in default expression analysis mode, these
3843 -- freeze actions must not be thrown away (normally all inserted
3844 -- actions are thrown away in this mode. However, the freeze actions
3845 -- are from static expressions and one of the important reasons we
3846 -- are doing this special analysis is to get these freeze actions.
3847 -- Therefore we turn off the In_Default_Expression mode to propagate
3848 -- these freeze actions. This also means they get properly analyzed
3851 In_Default_Expression := False;
3853 -- Freeze the designated type of an allocator (RM 13.14(13))
3855 if Present (Desig_Typ) then
3856 Freeze_Before (P, Desig_Typ);
3859 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
3860 -- the enumeration representation clause exception in the loop above.
3862 if Present (Typ) then
3863 Freeze_Before (P, Typ);
3866 -- Freeze name if one is present (RM 13.14(11))
3868 if Present (Nam) then
3869 Freeze_Before (P, Nam);
3872 In_Default_Expression := In_Def_Exp;
3873 end Freeze_Expression;
3875 -----------------------------
3876 -- Freeze_Fixed_Point_Type --
3877 -----------------------------
3879 -- Certain fixed-point types and subtypes, including implicit base types
3880 -- and declared first subtypes, have not yet set up a range. This is
3881 -- because the range cannot be set until the Small and Size values are
3882 -- known, and these are not known till the type is frozen.
3884 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
3885 -- whose bounds are unanalyzed real literals. This routine will recognize
3886 -- this case, and transform this range node into a properly typed range
3887 -- with properly analyzed and resolved values.
3889 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
3890 Rng : constant Node_Id := Scalar_Range (Typ);
3891 Lo : constant Node_Id := Low_Bound (Rng);
3892 Hi : constant Node_Id := High_Bound (Rng);
3893 Btyp : constant Entity_Id := Base_Type (Typ);
3894 Brng : constant Node_Id := Scalar_Range (Btyp);
3895 BLo : constant Node_Id := Low_Bound (Brng);
3896 BHi : constant Node_Id := High_Bound (Brng);
3897 Small : constant Ureal := Small_Value (Typ);
3904 function Fsize (Lov, Hiv : Ureal) return Nat;
3905 -- Returns size of type with given bounds. Also leaves these
3906 -- bounds set as the current bounds of the Typ.
3912 function Fsize (Lov, Hiv : Ureal) return Nat is
3914 Set_Realval (Lo, Lov);
3915 Set_Realval (Hi, Hiv);
3916 return Minimum_Size (Typ);
3919 -- Start of processing for Freeze_Fixed_Point_Type
3922 -- If Esize of a subtype has not previously been set, set it now
3924 if Unknown_Esize (Typ) then
3925 Atype := Ancestor_Subtype (Typ);
3927 if Present (Atype) then
3928 Set_Esize (Typ, Esize (Atype));
3930 Set_Esize (Typ, Esize (Base_Type (Typ)));
3934 -- Immediate return if the range is already analyzed. This means
3935 -- that the range is already set, and does not need to be computed
3938 if Analyzed (Rng) then
3942 -- Immediate return if either of the bounds raises Constraint_Error
3944 if Raises_Constraint_Error (Lo)
3945 or else Raises_Constraint_Error (Hi)
3950 Loval := Realval (Lo);
3951 Hival := Realval (Hi);
3953 -- Ordinary fixed-point case
3955 if Is_Ordinary_Fixed_Point_Type (Typ) then
3957 -- For the ordinary fixed-point case, we are allowed to fudge the
3958 -- end-points up or down by small. Generally we prefer to fudge
3959 -- up, i.e. widen the bounds for non-model numbers so that the
3960 -- end points are included. However there are cases in which this
3961 -- cannot be done, and indeed cases in which we may need to narrow
3962 -- the bounds. The following circuit makes the decision.
3964 -- Note: our terminology here is that Incl_EP means that the
3965 -- bounds are widened by Small if necessary to include the end
3966 -- points, and Excl_EP means that the bounds are narrowed by
3967 -- Small to exclude the end-points if this reduces the size.
3969 -- Note that in the Incl case, all we care about is including the
3970 -- end-points. In the Excl case, we want to narrow the bounds as
3971 -- much as permitted by the RM, to give the smallest possible size.
3974 Loval_Incl_EP : Ureal;
3975 Hival_Incl_EP : Ureal;
3977 Loval_Excl_EP : Ureal;
3978 Hival_Excl_EP : Ureal;
3984 First_Subt : Entity_Id;
3989 -- First step. Base types are required to be symmetrical. Right
3990 -- now, the base type range is a copy of the first subtype range.
3991 -- This will be corrected before we are done, but right away we
3992 -- need to deal with the case where both bounds are non-negative.
3993 -- In this case, we set the low bound to the negative of the high
3994 -- bound, to make sure that the size is computed to include the
3995 -- required sign. Note that we do not need to worry about the
3996 -- case of both bounds negative, because the sign will be dealt
3997 -- with anyway. Furthermore we can't just go making such a bound
3998 -- symmetrical, since in a twos-complement system, there is an
3999 -- extra negative value which could not be accomodated on the
4003 and then not UR_Is_Negative (Loval)
4004 and then Hival > Loval
4007 Set_Realval (Lo, Loval);
4010 -- Compute the fudged bounds. If the number is a model number,
4011 -- then we do nothing to include it, but we are allowed to backoff
4012 -- to the next adjacent model number when we exclude it. If it is
4013 -- not a model number then we straddle the two values with the
4014 -- model numbers on either side.
4016 Model_Num := UR_Trunc (Loval / Small) * Small;
4018 if Loval = Model_Num then
4019 Loval_Incl_EP := Model_Num;
4021 Loval_Incl_EP := Model_Num - Small;
4024 -- The low value excluding the end point is Small greater, but
4025 -- we do not do this exclusion if the low value is positive,
4026 -- since it can't help the size and could actually hurt by
4027 -- crossing the high bound.
4029 if UR_Is_Negative (Loval_Incl_EP) then
4030 Loval_Excl_EP := Loval_Incl_EP + Small;
4032 Loval_Excl_EP := Loval_Incl_EP;
4035 -- Similar processing for upper bound and high value
4037 Model_Num := UR_Trunc (Hival / Small) * Small;
4039 if Hival = Model_Num then
4040 Hival_Incl_EP := Model_Num;
4042 Hival_Incl_EP := Model_Num + Small;
4045 if UR_Is_Positive (Hival_Incl_EP) then
4046 Hival_Excl_EP := Hival_Incl_EP - Small;
4048 Hival_Excl_EP := Hival_Incl_EP;
4051 -- One further adjustment is needed. In the case of subtypes,
4052 -- we cannot go outside the range of the base type, or we get
4053 -- peculiarities, and the base type range is already set. This
4054 -- only applies to the Incl values, since clearly the Excl
4055 -- values are already as restricted as they are allowed to be.
4058 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
4059 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
4062 -- Get size including and excluding end points
4064 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
4065 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
4067 -- No need to exclude end-points if it does not reduce size
4069 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
4070 Loval_Excl_EP := Loval_Incl_EP;
4073 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
4074 Hival_Excl_EP := Hival_Incl_EP;
4077 -- Now we set the actual size to be used. We want to use the
4078 -- bounds fudged up to include the end-points but only if this
4079 -- can be done without violating a specifically given size
4080 -- size clause or causing an unacceptable increase in size.
4082 -- Case of size clause given
4084 if Has_Size_Clause (Typ) then
4086 -- Use the inclusive size only if it is consistent with
4087 -- the explicitly specified size.
4089 if Size_Incl_EP <= RM_Size (Typ) then
4090 Actual_Lo := Loval_Incl_EP;
4091 Actual_Hi := Hival_Incl_EP;
4092 Actual_Size := Size_Incl_EP;
4094 -- If the inclusive size is too large, we try excluding
4095 -- the end-points (will be caught later if does not work).
4098 Actual_Lo := Loval_Excl_EP;
4099 Actual_Hi := Hival_Excl_EP;
4100 Actual_Size := Size_Excl_EP;
4103 -- Case of size clause not given
4106 -- If we have a base type whose corresponding first subtype
4107 -- has an explicit size that is large enough to include our
4108 -- end-points, then do so. There is no point in working hard
4109 -- to get a base type whose size is smaller than the specified
4110 -- size of the first subtype.
4112 First_Subt := First_Subtype (Typ);
4114 if Has_Size_Clause (First_Subt)
4115 and then Size_Incl_EP <= Esize (First_Subt)
4117 Actual_Size := Size_Incl_EP;
4118 Actual_Lo := Loval_Incl_EP;
4119 Actual_Hi := Hival_Incl_EP;
4121 -- If excluding the end-points makes the size smaller and
4122 -- results in a size of 8,16,32,64, then we take the smaller
4123 -- size. For the 64 case, this is compulsory. For the other
4124 -- cases, it seems reasonable. We like to include end points
4125 -- if we can, but not at the expense of moving to the next
4126 -- natural boundary of size.
4128 elsif Size_Incl_EP /= Size_Excl_EP
4130 (Size_Excl_EP = 8 or else
4131 Size_Excl_EP = 16 or else
4132 Size_Excl_EP = 32 or else
4135 Actual_Size := Size_Excl_EP;
4136 Actual_Lo := Loval_Excl_EP;
4137 Actual_Hi := Hival_Excl_EP;
4139 -- Otherwise we can definitely include the end points
4142 Actual_Size := Size_Incl_EP;
4143 Actual_Lo := Loval_Incl_EP;
4144 Actual_Hi := Hival_Incl_EP;
4147 -- One pathological case: normally we never fudge a low bound
4148 -- down, since it would seem to increase the size (if it has
4149 -- any effect), but for ranges containing single value, or no
4150 -- values, the high bound can be small too large. Consider:
4152 -- type t is delta 2.0**(-14)
4153 -- range 131072.0 .. 0;
4155 -- That lower bound is *just* outside the range of 32 bits, and
4156 -- does need fudging down in this case. Note that the bounds
4157 -- will always have crossed here, since the high bound will be
4158 -- fudged down if necessary, as in the case of:
4160 -- type t is delta 2.0**(-14)
4161 -- range 131072.0 .. 131072.0;
4163 -- So we detect the situation by looking for crossed bounds,
4164 -- and if the bounds are crossed, and the low bound is greater
4165 -- than zero, we will always back it off by small, since this
4166 -- is completely harmless.
4168 if Actual_Lo > Actual_Hi then
4169 if UR_Is_Positive (Actual_Lo) then
4170 Actual_Lo := Loval_Incl_EP - Small;
4171 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
4173 -- And of course, we need to do exactly the same parallel
4174 -- fudge for flat ranges in the negative region.
4176 elsif UR_Is_Negative (Actual_Hi) then
4177 Actual_Hi := Hival_Incl_EP + Small;
4178 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
4183 Set_Realval (Lo, Actual_Lo);
4184 Set_Realval (Hi, Actual_Hi);
4187 -- For the decimal case, none of this fudging is required, since there
4188 -- are no end-point problems in the decimal case (the end-points are
4189 -- always included).
4192 Actual_Size := Fsize (Loval, Hival);
4195 -- At this stage, the actual size has been calculated and the proper
4196 -- required bounds are stored in the low and high bounds.
4198 if Actual_Size > 64 then
4199 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
4201 ("size required (^) for type& too large, maximum is 64", Typ);
4205 -- Check size against explicit given size
4207 if Has_Size_Clause (Typ) then
4208 if Actual_Size > RM_Size (Typ) then
4209 Error_Msg_Uint_1 := RM_Size (Typ);
4210 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
4212 ("size given (^) for type& too small, minimum is ^",
4213 Size_Clause (Typ), Typ);
4216 Actual_Size := UI_To_Int (Esize (Typ));
4219 -- Increase size to next natural boundary if no size clause given
4222 if Actual_Size <= 8 then
4224 elsif Actual_Size <= 16 then
4226 elsif Actual_Size <= 32 then
4232 Init_Esize (Typ, Actual_Size);
4233 Adjust_Esize_For_Alignment (Typ);
4236 -- If we have a base type, then expand the bounds so that they extend to
4237 -- the full width of the allocated size in bits, to avoid junk range
4238 -- checks on intermediate computations.
4240 if Base_Type (Typ) = Typ then
4241 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
4242 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
4245 -- Final step is to reanalyze the bounds using the proper type
4246 -- and set the Corresponding_Integer_Value fields of the literals.
4248 Set_Etype (Lo, Empty);
4249 Set_Analyzed (Lo, False);
4252 -- Resolve with universal fixed if the base type, and the base type if
4253 -- it is a subtype. Note we can't resolve the base type with itself,
4254 -- that would be a reference before definition.
4257 Resolve (Lo, Universal_Fixed);
4262 -- Set corresponding integer value for bound
4264 Set_Corresponding_Integer_Value
4265 (Lo, UR_To_Uint (Realval (Lo) / Small));
4267 -- Similar processing for high bound
4269 Set_Etype (Hi, Empty);
4270 Set_Analyzed (Hi, False);
4274 Resolve (Hi, Universal_Fixed);
4279 Set_Corresponding_Integer_Value
4280 (Hi, UR_To_Uint (Realval (Hi) / Small));
4282 -- Set type of range to correspond to bounds
4284 Set_Etype (Rng, Etype (Lo));
4286 -- Set Esize to calculated size if not set already
4288 if Unknown_Esize (Typ) then
4289 Init_Esize (Typ, Actual_Size);
4292 -- Set RM_Size if not already set. If already set, check value
4295 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
4298 if RM_Size (Typ) /= Uint_0 then
4299 if RM_Size (Typ) < Minsiz then
4300 Error_Msg_Uint_1 := RM_Size (Typ);
4301 Error_Msg_Uint_2 := Minsiz;
4303 ("size given (^) for type& too small, minimum is ^",
4304 Size_Clause (Typ), Typ);
4308 Set_RM_Size (Typ, Minsiz);
4311 end Freeze_Fixed_Point_Type;
4317 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
4321 Set_Has_Delayed_Freeze (T);
4322 L := Freeze_Entity (T, Sloc (N));
4324 if Is_Non_Empty_List (L) then
4325 Insert_Actions (N, L);
4329 --------------------------
4330 -- Freeze_Static_Object --
4331 --------------------------
4333 procedure Freeze_Static_Object (E : Entity_Id) is
4335 Cannot_Be_Static : exception;
4336 -- Exception raised if the type of a static object cannot be made
4337 -- static. This happens if the type depends on non-global objects.
4339 procedure Ensure_Expression_Is_SA (N : Node_Id);
4340 -- Called to ensure that an expression used as part of a type
4341 -- definition is statically allocatable, which means that the type
4342 -- of the expression is statically allocatable, and the expression
4343 -- is either static, or a reference to a library level constant.
4345 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
4346 -- Called to mark a type as static, checking that it is possible
4347 -- to set the type as static. If it is not possible, then the
4348 -- exception Cannot_Be_Static is raised.
4350 -----------------------------
4351 -- Ensure_Expression_Is_SA --
4352 -----------------------------
4354 procedure Ensure_Expression_Is_SA (N : Node_Id) is
4358 Ensure_Type_Is_SA (Etype (N));
4360 if Is_Static_Expression (N) then
4363 elsif Nkind (N) = N_Identifier then
4367 and then Ekind (Ent) = E_Constant
4368 and then Is_Library_Level_Entity (Ent)
4374 raise Cannot_Be_Static;
4375 end Ensure_Expression_Is_SA;
4377 -----------------------
4378 -- Ensure_Type_Is_SA --
4379 -----------------------
4381 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
4386 -- If type is library level, we are all set
4388 if Is_Library_Level_Entity (Typ) then
4392 -- We are also OK if the type is already marked as statically
4393 -- allocated, which means we processed it before.
4395 if Is_Statically_Allocated (Typ) then
4399 -- Mark type as statically allocated
4401 Set_Is_Statically_Allocated (Typ);
4403 -- Check that it is safe to statically allocate this type
4405 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
4406 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
4407 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
4409 elsif Is_Array_Type (Typ) then
4410 N := First_Index (Typ);
4411 while Present (N) loop
4412 Ensure_Type_Is_SA (Etype (N));
4416 Ensure_Type_Is_SA (Component_Type (Typ));
4418 elsif Is_Access_Type (Typ) then
4419 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
4423 T : constant Entity_Id := Etype (Designated_Type (Typ));
4426 if T /= Standard_Void_Type then
4427 Ensure_Type_Is_SA (T);
4430 F := First_Formal (Designated_Type (Typ));
4432 while Present (F) loop
4433 Ensure_Type_Is_SA (Etype (F));
4439 Ensure_Type_Is_SA (Designated_Type (Typ));
4442 elsif Is_Record_Type (Typ) then
4443 C := First_Entity (Typ);
4445 while Present (C) loop
4446 if Ekind (C) = E_Discriminant
4447 or else Ekind (C) = E_Component
4449 Ensure_Type_Is_SA (Etype (C));
4451 elsif Is_Type (C) then
4452 Ensure_Type_Is_SA (C);
4458 elsif Ekind (Typ) = E_Subprogram_Type then
4459 Ensure_Type_Is_SA (Etype (Typ));
4461 C := First_Formal (Typ);
4462 while Present (C) loop
4463 Ensure_Type_Is_SA (Etype (C));
4468 raise Cannot_Be_Static;
4470 end Ensure_Type_Is_SA;
4472 -- Start of processing for Freeze_Static_Object
4475 Ensure_Type_Is_SA (Etype (E));
4477 -- Reset True_Constant flag, since something strange is going on with
4478 -- the scoping here, and our simple value tracing may not be sufficient
4479 -- for this indication to be reliable. We kill the Constant_Value
4480 -- indication for the same reason.
4482 Set_Is_True_Constant (E, False);
4483 Set_Current_Value (E, Empty);
4486 when Cannot_Be_Static =>
4488 -- If the object that cannot be static is imported or exported,
4489 -- then we give an error message saying that this object cannot
4490 -- be imported or exported.
4492 if Is_Imported (E) then
4494 ("& cannot be imported (local type is not constant)", E);
4496 -- Otherwise must be exported, something is wrong if compiler
4497 -- is marking something as statically allocated which cannot be).
4499 else pragma Assert (Is_Exported (E));
4501 ("& cannot be exported (local type is not constant)", E);
4503 end Freeze_Static_Object;
4505 -----------------------
4506 -- Freeze_Subprogram --
4507 -----------------------
4509 procedure Freeze_Subprogram (E : Entity_Id) is
4514 -- Subprogram may not have an address clause unless it is imported
4516 if Present (Address_Clause (E)) then
4517 if not Is_Imported (E) then
4519 ("address clause can only be given " &
4520 "for imported subprogram",
4521 Name (Address_Clause (E)));
4525 -- Reset the Pure indication on an imported subprogram unless an
4526 -- explicit Pure_Function pragma was present. We do this because
4527 -- otherwise it is an insidious error to call a non-pure function
4528 -- from pure unit and have calls mysteriously optimized away. What
4529 -- happens here is that the Import can bypass the normal check to
4530 -- ensure that pure units call only pure subprograms.
4533 and then Is_Pure (E)
4534 and then not Has_Pragma_Pure_Function (E)
4536 Set_Is_Pure (E, False);
4539 -- For non-foreign convention subprograms, this is where we create
4540 -- the extra formals (for accessibility level and constrained bit
4541 -- information). We delay this till the freeze point precisely so
4542 -- that we know the convention!
4544 if not Has_Foreign_Convention (E) then
4545 Create_Extra_Formals (E);
4548 -- If this is convention Ada and a Valued_Procedure, that's odd
4550 if Ekind (E) = E_Procedure
4551 and then Is_Valued_Procedure (E)
4552 and then Convention (E) = Convention_Ada
4553 and then Warn_On_Export_Import
4556 ("?Valued_Procedure has no effect for convention Ada", E);
4557 Set_Is_Valued_Procedure (E, False);
4560 -- Case of foreign convention
4565 -- For foreign conventions, warn about return of an
4566 -- unconstrained array.
4568 -- Note: we *do* allow a return by descriptor for the VMS case,
4569 -- though here there is probably more to be done ???
4571 if Ekind (E) = E_Function then
4572 Retype := Underlying_Type (Etype (E));
4574 -- If no return type, probably some other error, e.g. a
4575 -- missing full declaration, so ignore.
4580 -- If the return type is generic, we have emitted a warning
4581 -- earlier on, and there is nothing else to check here. Specific
4582 -- instantiations may lead to erroneous behavior.
4584 elsif Is_Generic_Type (Etype (E)) then
4587 elsif Is_Array_Type (Retype)
4588 and then not Is_Constrained (Retype)
4589 and then Mechanism (E) not in Descriptor_Codes
4590 and then Warn_On_Export_Import
4593 ("?foreign convention function& should not return " &
4594 "unconstrained array", E);
4599 -- If any of the formals for an exported foreign convention
4600 -- subprogram have defaults, then emit an appropriate warning since
4601 -- this is odd (default cannot be used from non-Ada code)
4603 if Is_Exported (E) then
4604 F := First_Formal (E);
4605 while Present (F) loop
4606 if Warn_On_Export_Import
4607 and then Present (Default_Value (F))
4610 ("?parameter cannot be defaulted in non-Ada call",
4619 -- For VMS, descriptor mechanisms for parameters are allowed only
4620 -- for imported subprograms.
4622 if OpenVMS_On_Target then
4623 if not Is_Imported (E) then
4624 F := First_Formal (E);
4625 while Present (F) loop
4626 if Mechanism (F) in Descriptor_Codes then
4628 ("descriptor mechanism for parameter not permitted", F);
4630 ("\can only be used for imported subprogram", F);
4638 -- Pragma Inline_Always is disallowed for dispatching subprograms
4639 -- because the address of such subprograms is saved in the dispatch
4640 -- table to support dispatching calls, and dispatching calls cannot
4641 -- be inlined. This is consistent with the restriction against using
4642 -- 'Access or 'Address on an Inline_Always subprogram.
4644 if Is_Dispatching_Operation (E) and then Is_Always_Inlined (E) then
4646 ("pragma Inline_Always not allowed for dispatching subprograms", E);
4648 end Freeze_Subprogram;
4650 ----------------------
4651 -- Is_Fully_Defined --
4652 ----------------------
4654 function Is_Fully_Defined (T : Entity_Id) return Boolean is
4656 if Ekind (T) = E_Class_Wide_Type then
4657 return Is_Fully_Defined (Etype (T));
4659 elsif Is_Array_Type (T) then
4660 return Is_Fully_Defined (Component_Type (T));
4662 elsif Is_Record_Type (T)
4663 and not Is_Private_Type (T)
4665 -- Verify that the record type has no components with
4666 -- private types without completion.
4672 Comp := First_Component (T);
4674 while Present (Comp) loop
4675 if not Is_Fully_Defined (Etype (Comp)) then
4679 Next_Component (Comp);
4684 else return not Is_Private_Type (T)
4685 or else Present (Full_View (Base_Type (T)));
4687 end Is_Fully_Defined;
4689 ---------------------------------
4690 -- Process_Default_Expressions --
4691 ---------------------------------
4693 procedure Process_Default_Expressions
4695 After : in out Node_Id)
4697 Loc : constant Source_Ptr := Sloc (E);
4704 Set_Default_Expressions_Processed (E);
4706 -- A subprogram instance and its associated anonymous subprogram
4707 -- share their signature. The default expression functions are defined
4708 -- in the wrapper packages for the anonymous subprogram, and should
4709 -- not be generated again for the instance.
4711 if Is_Generic_Instance (E)
4712 and then Present (Alias (E))
4713 and then Default_Expressions_Processed (Alias (E))
4718 Formal := First_Formal (E);
4720 while Present (Formal) loop
4721 if Present (Default_Value (Formal)) then
4723 -- We work with a copy of the default expression because we
4724 -- do not want to disturb the original, since this would mess
4725 -- up the conformance checking.
4727 Dcopy := New_Copy_Tree (Default_Value (Formal));
4729 -- The analysis of the expression may generate insert actions,
4730 -- which of course must not be executed. We wrap those actions
4731 -- in a procedure that is not called, and later on eliminated.
4732 -- The following cases have no side-effects, and are analyzed
4735 if Nkind (Dcopy) = N_Identifier
4736 or else Nkind (Dcopy) = N_Expanded_Name
4737 or else Nkind (Dcopy) = N_Integer_Literal
4738 or else (Nkind (Dcopy) = N_Real_Literal
4739 and then not Vax_Float (Etype (Dcopy)))
4740 or else Nkind (Dcopy) = N_Character_Literal
4741 or else Nkind (Dcopy) = N_String_Literal
4742 or else Nkind (Dcopy) = N_Null
4743 or else (Nkind (Dcopy) = N_Attribute_Reference
4745 Attribute_Name (Dcopy) = Name_Null_Parameter)
4748 -- If there is no default function, we must still do a full
4749 -- analyze call on the default value, to ensure that all
4750 -- error checks are performed, e.g. those associated with
4751 -- static evaluation. Note that this branch will always be
4752 -- taken if the analyzer is turned off (but we still need the
4755 -- Note: the setting of parent here is to meet the requirement
4756 -- that we can only analyze the expression while attached to
4757 -- the tree. Really the requirement is that the parent chain
4758 -- be set, we don't actually need to be in the tree.
4760 Set_Parent (Dcopy, Declaration_Node (Formal));
4763 -- Default expressions are resolved with their own type if the
4764 -- context is generic, to avoid anomalies with private types.
4766 if Ekind (Scope (E)) = E_Generic_Package then
4769 Resolve (Dcopy, Etype (Formal));
4772 -- If that resolved expression will raise constraint error,
4773 -- then flag the default value as raising constraint error.
4774 -- This allows a proper error message on the calls.
4776 if Raises_Constraint_Error (Dcopy) then
4777 Set_Raises_Constraint_Error (Default_Value (Formal));
4780 -- If the default is a parameterless call, we use the name of
4781 -- the called function directly, and there is no body to build.
4783 elsif Nkind (Dcopy) = N_Function_Call
4784 and then No (Parameter_Associations (Dcopy))
4788 -- Else construct and analyze the body of a wrapper procedure
4789 -- that contains an object declaration to hold the expression.
4790 -- Given that this is done only to complete the analysis, it
4791 -- simpler to build a procedure than a function which might
4792 -- involve secondary stack expansion.
4796 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
4799 Make_Subprogram_Body (Loc,
4801 Make_Procedure_Specification (Loc,
4802 Defining_Unit_Name => Dnam),
4804 Declarations => New_List (
4805 Make_Object_Declaration (Loc,
4806 Defining_Identifier =>
4807 Make_Defining_Identifier (Loc,
4808 New_Internal_Name ('T')),
4809 Object_Definition =>
4810 New_Occurrence_Of (Etype (Formal), Loc),
4811 Expression => New_Copy_Tree (Dcopy))),
4813 Handled_Statement_Sequence =>
4814 Make_Handled_Sequence_Of_Statements (Loc,
4815 Statements => New_List));
4817 Set_Scope (Dnam, Scope (E));
4818 Set_Assignment_OK (First (Declarations (Dbody)));
4819 Set_Is_Eliminated (Dnam);
4820 Insert_After (After, Dbody);
4826 Next_Formal (Formal);
4829 end Process_Default_Expressions;
4831 ----------------------------------------
4832 -- Set_Component_Alignment_If_Not_Set --
4833 ----------------------------------------
4835 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
4837 -- Ignore if not base type, subtypes don't need anything
4839 if Typ /= Base_Type (Typ) then
4843 -- Do not override existing representation
4845 if Is_Packed (Typ) then
4848 elsif Has_Specified_Layout (Typ) then
4851 elsif Component_Alignment (Typ) /= Calign_Default then
4855 Set_Component_Alignment
4856 (Typ, Scope_Stack.Table
4857 (Scope_Stack.Last).Component_Alignment_Default);
4859 end Set_Component_Alignment_If_Not_Set;
4861 ---------------------------
4862 -- Set_Debug_Info_Needed --
4863 ---------------------------
4865 procedure Set_Debug_Info_Needed (T : Entity_Id) is
4868 or else Needs_Debug_Info (T)
4869 or else Debug_Info_Off (T)
4873 Set_Needs_Debug_Info (T);
4876 if Is_Object (T) then
4877 Set_Debug_Info_Needed (Etype (T));
4879 elsif Is_Type (T) then
4880 Set_Debug_Info_Needed (Etype (T));
4882 if Is_Record_Type (T) then
4884 Ent : Entity_Id := First_Entity (T);
4886 while Present (Ent) loop
4887 Set_Debug_Info_Needed (Ent);
4892 elsif Is_Array_Type (T) then
4893 Set_Debug_Info_Needed (Component_Type (T));
4896 Indx : Node_Id := First_Index (T);
4898 while Present (Indx) loop
4899 Set_Debug_Info_Needed (Etype (Indx));
4900 Indx := Next_Index (Indx);
4904 if Is_Packed (T) then
4905 Set_Debug_Info_Needed (Packed_Array_Type (T));
4908 elsif Is_Access_Type (T) then
4909 Set_Debug_Info_Needed (Directly_Designated_Type (T));
4911 elsif Is_Private_Type (T) then
4912 Set_Debug_Info_Needed (Full_View (T));
4914 elsif Is_Protected_Type (T) then
4915 Set_Debug_Info_Needed (Corresponding_Record_Type (T));
4918 end Set_Debug_Info_Needed;
4924 procedure Undelay_Type (T : Entity_Id) is
4926 Set_Has_Delayed_Freeze (T, False);
4927 Set_Freeze_Node (T, Empty);
4929 -- Since we don't want T to have a Freeze_Node, we don't want its
4930 -- Full_View or Corresponding_Record_Type to have one either.
4932 -- ??? Fundamentally, this whole handling is a kludge. What we really
4933 -- want is to be sure that for an Itype that's part of record R and is
4934 -- a subtype of type T, that it's frozen after the later of the freeze
4935 -- points of R and T. We have no way of doing that directly, so what we
4936 -- do is force most such Itypes to be frozen as part of freezing R via
4937 -- this procedure and only delay the ones that need to be delayed
4938 -- (mostly the designated types of access types that are defined as
4939 -- part of the record).
4941 if Is_Private_Type (T)
4942 and then Present (Full_View (T))
4943 and then Is_Itype (Full_View (T))
4944 and then Is_Record_Type (Scope (Full_View (T)))
4946 Undelay_Type (Full_View (T));
4949 if Is_Concurrent_Type (T)
4950 and then Present (Corresponding_Record_Type (T))
4951 and then Is_Itype (Corresponding_Record_Type (T))
4952 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
4954 Undelay_Type (Corresponding_Record_Type (T));
4962 procedure Warn_Overlay
4967 Ent : constant Entity_Id := Entity (Nam);
4968 -- The object to which the address clause applies
4971 Old : Entity_Id := Empty;
4975 -- No warning if address clause overlay warnings are off
4977 if not Address_Clause_Overlay_Warnings then
4981 -- No warning if there is an explicit initialization
4983 Init := Original_Node (Expression (Declaration_Node (Ent)));
4985 if Present (Init) and then Comes_From_Source (Init) then
4989 -- We only give the warning for non-imported entities of a type for
4990 -- which a non-null base init proc is defined (or for access types which
4991 -- have implicit null initialization).
4994 and then (Has_Non_Null_Base_Init_Proc (Typ)
4995 or else Is_Access_Type (Typ))
4996 and then not Is_Imported (Ent)
4998 if Nkind (Expr) = N_Attribute_Reference
4999 and then Is_Entity_Name (Prefix (Expr))
5001 Old := Entity (Prefix (Expr));
5003 elsif Is_Entity_Name (Expr)
5004 and then Ekind (Entity (Expr)) = E_Constant
5006 Decl := Declaration_Node (Entity (Expr));
5008 if Nkind (Decl) = N_Object_Declaration
5009 and then Present (Expression (Decl))
5010 and then Nkind (Expression (Decl)) = N_Attribute_Reference
5011 and then Is_Entity_Name (Prefix (Expression (Decl)))
5013 Old := Entity (Prefix (Expression (Decl)));
5015 elsif Nkind (Expr) = N_Function_Call then
5019 -- A function call (most likely to To_Address) is probably not
5020 -- an overlay, so skip warning. Ditto if the function call was
5021 -- inlined and transformed into an entity.
5023 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
5027 Decl := Next (Parent (Expr));
5029 -- If a pragma Import follows, we assume that it is for the current
5030 -- target of the address clause, and skip the warning.
5033 and then Nkind (Decl) = N_Pragma
5034 and then Chars (Decl) = Name_Import
5039 if Present (Old) then
5040 Error_Msg_Node_2 := Old;
5042 ("default initialization of & may modify &?",
5046 ("default initialization of & may modify overlaid storage?",
5050 -- Add friendly warning if initialization comes from a packed array
5053 if Is_Record_Type (Typ) then
5058 Comp := First_Component (Typ);
5060 while Present (Comp) loop
5061 if Nkind (Parent (Comp)) = N_Component_Declaration
5062 and then Present (Expression (Parent (Comp)))
5065 elsif Is_Array_Type (Etype (Comp))
5066 and then Present (Packed_Array_Type (Etype (Comp)))
5069 ("packed array component& will be initialized to zero?",
5073 Next_Component (Comp);
5080 ("use pragma Import for & to " &
5081 "suppress initialization ('R'M B.1(24))?",