1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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;
44 with Sem_Cat; use Sem_Cat;
45 with Sem_Ch6; use Sem_Ch6;
46 with Sem_Ch7; use Sem_Ch7;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Ch13; use Sem_Ch13;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Mech; use Sem_Mech;
51 with Sem_Prag; use Sem_Prag;
52 with Sem_Res; use Sem_Res;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Snames; use Snames;
56 with Stand; use Stand;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
60 with Uintp; use Uintp;
61 with Urealp; use Urealp;
63 package body Freeze is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
70 -- Typ is a type that is being frozen. If no size clause is given,
71 -- but a default Esize has been computed, then this default Esize is
72 -- adjusted up if necessary to be consistent with a given alignment,
73 -- but never to a value greater than Long_Long_Integer'Size. This
74 -- is used for all discrete types and for fixed-point types.
76 procedure Build_And_Analyze_Renamed_Body
79 After : in out Node_Id);
80 -- Build body for a renaming declaration, insert in tree and analyze.
82 procedure Check_Address_Clause (E : Entity_Id);
83 -- Apply legality checks to address clauses for object declarations,
84 -- at the point the object is frozen.
86 procedure Check_Strict_Alignment (E : Entity_Id);
87 -- E is a base type. If E is tagged or has a component that is aliased
88 -- or tagged or contains something this is aliased or tagged, set
91 procedure Check_Unsigned_Type (E : Entity_Id);
92 pragma Inline (Check_Unsigned_Type);
93 -- If E is a fixed-point or discrete type, then all the necessary work
94 -- to freeze it is completed except for possible setting of the flag
95 -- Is_Unsigned_Type, which is done by this procedure. The call has no
96 -- effect if the entity E is not a discrete or fixed-point type.
98 procedure Freeze_And_Append
101 Result : in out List_Id);
102 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
103 -- nodes to Result, modifying Result from No_List if necessary.
105 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
106 -- Freeze enumeration type. The Esize field is set as processing
107 -- proceeds (i.e. set by default when the type is declared and then
108 -- adjusted by rep clauses. What this procedure does is to make sure
109 -- that if a foreign convention is specified, and no specific size
110 -- is given, then the size must be at least Integer'Size.
112 procedure Freeze_Static_Object (E : Entity_Id);
113 -- If an object is frozen which has Is_Statically_Allocated set, then
114 -- all referenced types must also be marked with this flag. This routine
115 -- is in charge of meeting this requirement for the object entity E.
117 procedure Freeze_Subprogram (E : Entity_Id);
118 -- Perform freezing actions for a subprogram (create extra formals,
119 -- and set proper default mechanism values). Note that this routine
120 -- is not called for internal subprograms, for which neither of these
121 -- actions is needed (or desirable, we do not want for example to have
122 -- these extra formals present in initialization procedures, where they
123 -- would serve no purpose). In this call E is either a subprogram or
124 -- a subprogram type (i.e. an access to a subprogram).
126 function Is_Fully_Defined (T : Entity_Id) return Boolean;
127 -- True if T is not private and has no private components, or has a full
128 -- view. Used to determine whether the designated type of an access type
129 -- should be frozen when the access type is frozen. This is done when an
130 -- allocator is frozen, or an expression that may involve attributes of
131 -- the designated type. Otherwise freezing the access type does not freeze
132 -- the designated type.
134 procedure Process_Default_Expressions
136 After : in out Node_Id);
137 -- This procedure is called for each subprogram to complete processing
138 -- of default expressions at the point where all types are known to be
139 -- frozen. The expressions must be analyzed in full, to make sure that
140 -- all error processing is done (they have only been pre-analyzed). If
141 -- the expression is not an entity or literal, its analysis may generate
142 -- code which must not be executed. In that case we build a function
143 -- body to hold that code. This wrapper function serves no other purpose
144 -- (it used to be called to evaluate the default, but now the default is
145 -- inlined at each point of call).
147 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
148 -- Typ is a record or array type that is being frozen. This routine
149 -- sets the default component alignment from the scope stack values
150 -- if the alignment is otherwise not specified.
152 procedure Check_Debug_Info_Needed (T : Entity_Id);
153 -- As each entity is frozen, this routine is called to deal with the
154 -- setting of Debug_Info_Needed for the entity. This flag is set if
155 -- the entity comes from source, or if we are in Debug_Generated_Code
156 -- mode or if the -gnatdV debug flag is set. However, it never sets
157 -- the flag if Debug_Info_Off is set.
159 procedure Set_Debug_Info_Needed (T : Entity_Id);
160 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
161 -- also on any entities that are needed by T (for an object, the type
162 -- of the object is needed, and for a type, the subsidiary types are
163 -- needed -- see body for details). Never has any effect on T if the
164 -- Debug_Info_Off flag is set.
166 procedure Warn_Overlay
170 -- Expr is the expression for an address clause for entity Nam whose type
171 -- is Typ. If Typ has a default initialization, and there is no explicit
172 -- initialization in the source declaration, check whether the address
173 -- clause might cause overlaying of an entity, and emit a warning on the
174 -- side effect that the initialization will cause.
176 -------------------------------
177 -- Adjust_Esize_For_Alignment --
178 -------------------------------
180 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
184 if Known_Esize (Typ) and then Known_Alignment (Typ) then
185 Align := Alignment_In_Bits (Typ);
187 if Align > Esize (Typ)
188 and then Align <= Standard_Long_Long_Integer_Size
190 Set_Esize (Typ, Align);
193 end Adjust_Esize_For_Alignment;
195 ------------------------------------
196 -- Build_And_Analyze_Renamed_Body --
197 ------------------------------------
199 procedure Build_And_Analyze_Renamed_Body
202 After : in out Node_Id)
204 Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S);
207 Insert_After (After, Body_Node);
208 Mark_Rewrite_Insertion (Body_Node);
211 end Build_And_Analyze_Renamed_Body;
213 ------------------------
214 -- Build_Renamed_Body --
215 ------------------------
217 function Build_Renamed_Body
219 New_S : Entity_Id) return Node_Id
221 Loc : constant Source_Ptr := Sloc (New_S);
222 -- We use for the source location of the renamed body, the location
223 -- of the spec entity. It might seem more natural to use the location
224 -- of the renaming declaration itself, but that would be wrong, since
225 -- then the body we create would look as though it was created far
226 -- too late, and this could cause problems with elaboration order
227 -- analysis, particularly in connection with instantiations.
229 N : constant Node_Id := Unit_Declaration_Node (New_S);
230 Nam : constant Node_Id := Name (N);
232 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
233 Actuals : List_Id := No_List;
238 O_Formal : Entity_Id;
239 Param_Spec : Node_Id;
242 -- Determine the entity being renamed, which is the target of the
243 -- call statement. If the name is an explicit dereference, this is
244 -- a renaming of a subprogram type rather than a subprogram. The
245 -- name itself is fully analyzed.
247 if Nkind (Nam) = N_Selected_Component then
248 Old_S := Entity (Selector_Name (Nam));
250 elsif Nkind (Nam) = N_Explicit_Dereference then
251 Old_S := Etype (Nam);
253 elsif Nkind (Nam) = N_Indexed_Component then
254 if Is_Entity_Name (Prefix (Nam)) then
255 Old_S := Entity (Prefix (Nam));
257 Old_S := Entity (Selector_Name (Prefix (Nam)));
260 elsif Nkind (Nam) = N_Character_Literal then
261 Old_S := Etype (New_S);
264 Old_S := Entity (Nam);
267 if Is_Entity_Name (Nam) then
269 -- If the renamed entity is a predefined operator, retain full
270 -- name to ensure its visibility.
272 if Ekind (Old_S) = E_Operator
273 and then Nkind (Nam) = N_Expanded_Name
275 Call_Name := New_Copy (Name (N));
277 Call_Name := New_Reference_To (Old_S, Loc);
281 Call_Name := New_Copy (Name (N));
283 -- The original name may have been overloaded, but
284 -- is fully resolved now.
286 Set_Is_Overloaded (Call_Name, False);
289 -- For simple renamings, subsequent calls can be expanded directly
290 -- as called to the renamed entity. The body must be generated in
291 -- any case for calls they may appear elsewhere.
293 if (Ekind (Old_S) = E_Function
294 or else Ekind (Old_S) = E_Procedure)
295 and then Nkind (Decl) = N_Subprogram_Declaration
297 Set_Body_To_Inline (Decl, Old_S);
300 -- The body generated for this renaming is an internal artifact, and
301 -- does not constitute a freeze point for the called entity.
303 Set_Must_Not_Freeze (Call_Name);
305 Formal := First_Formal (Defining_Entity (Decl));
307 if Present (Formal) then
310 while Present (Formal) loop
311 Append (New_Reference_To (Formal, Loc), Actuals);
312 Next_Formal (Formal);
316 -- If the renamed entity is an entry, inherit its profile. For
317 -- other renamings as bodies, both profiles must be subtype
318 -- conformant, so it is not necessary to replace the profile given
319 -- in the declaration. However, default values that are aggregates
320 -- are rewritten when partially analyzed, so we recover the original
321 -- aggregate to insure that subsequent conformity checking works.
322 -- Similarly, if the default expression was constant-folded, recover
323 -- the original expression.
325 Formal := First_Formal (Defining_Entity (Decl));
327 if Present (Formal) then
328 O_Formal := First_Formal (Old_S);
329 Param_Spec := First (Parameter_Specifications (Spec));
331 while Present (Formal) loop
332 if Is_Entry (Old_S) then
334 if Nkind (Parameter_Type (Param_Spec)) /=
337 Set_Etype (Formal, Etype (O_Formal));
338 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
341 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
342 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
343 Nkind (Default_Value (O_Formal))
345 Set_Expression (Param_Spec,
346 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
349 Next_Formal (Formal);
350 Next_Formal (O_Formal);
355 -- If the renamed entity is a function, the generated body contains a
356 -- return statement. Otherwise, build a procedure call. If the entity is
357 -- an entry, subsequent analysis of the call will transform it into the
358 -- proper entry or protected operation call. If the renamed entity is
359 -- a character literal, return it directly.
361 if Ekind (Old_S) = E_Function
362 or else Ekind (Old_S) = E_Operator
363 or else (Ekind (Old_S) = E_Subprogram_Type
364 and then Etype (Old_S) /= Standard_Void_Type)
367 Make_Return_Statement (Loc,
369 Make_Function_Call (Loc,
371 Parameter_Associations => Actuals));
373 elsif Ekind (Old_S) = E_Enumeration_Literal then
375 Make_Return_Statement (Loc,
376 Expression => New_Occurrence_Of (Old_S, Loc));
378 elsif Nkind (Nam) = N_Character_Literal then
380 Make_Return_Statement (Loc,
381 Expression => Call_Name);
385 Make_Procedure_Call_Statement (Loc,
387 Parameter_Associations => Actuals);
390 -- Create entities for subprogram body and formals.
392 Set_Defining_Unit_Name (Spec,
393 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
395 Param_Spec := First (Parameter_Specifications (Spec));
397 while Present (Param_Spec) loop
398 Set_Defining_Identifier (Param_Spec,
399 Make_Defining_Identifier (Loc,
400 Chars => Chars (Defining_Identifier (Param_Spec))));
405 Make_Subprogram_Body (Loc,
406 Specification => Spec,
407 Declarations => New_List,
408 Handled_Statement_Sequence =>
409 Make_Handled_Sequence_Of_Statements (Loc,
410 Statements => New_List (Call_Node)));
412 if Nkind (Decl) /= N_Subprogram_Declaration then
414 Make_Subprogram_Declaration (Loc,
415 Specification => Specification (N)));
418 -- Link the body to the entity whose declaration it completes. If
419 -- the body is analyzed when the renamed entity is frozen, it may be
420 -- necessary to restore the proper scope (see package Exp_Ch13).
422 if Nkind (N) = N_Subprogram_Renaming_Declaration
423 and then Present (Corresponding_Spec (N))
425 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
427 Set_Corresponding_Spec (Body_Node, New_S);
431 end Build_Renamed_Body;
433 --------------------------
434 -- Check_Address_Clause --
435 --------------------------
437 procedure Check_Address_Clause (E : Entity_Id) is
438 Addr : constant Node_Id := Address_Clause (E);
440 Decl : constant Node_Id := Declaration_Node (E);
441 Typ : constant Entity_Id := Etype (E);
444 if Present (Addr) then
445 Expr := Expression (Addr);
447 -- If we have no initialization of any kind, then we don't
448 -- need to place any restrictions on the address clause, because
449 -- the object will be elaborated after the address clause is
450 -- evaluated. This happens if the declaration has no initial
451 -- expression, or the type has no implicit initialization, or
452 -- the object is imported.
454 -- The same holds for all initialized scalar types and all
455 -- access types. Packed bit arrays of size up to 64 are
456 -- represented using a modular type with an initialization
457 -- (to zero) and can be processed like other initialized
460 -- If the type is controlled, code to attach the object to a
461 -- finalization chain is generated at the point of declaration,
462 -- and therefore the elaboration of the object cannot be delayed:
463 -- the address expression must be a constant.
465 if (No (Expression (Decl))
466 and then not Controlled_Type (Typ)
468 (not Has_Non_Null_Base_Init_Proc (Typ)
469 or else Is_Imported (E)))
472 (Present (Expression (Decl))
473 and then Is_Scalar_Type (Typ))
479 (Is_Bit_Packed_Array (Typ)
481 Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
485 -- Otherwise, we require the address clause to be constant
486 -- because the call to the initialization procedure (or the
487 -- attach code) has to happen at the point of the declaration.
490 Check_Constant_Address_Clause (Expr, E);
491 Set_Has_Delayed_Freeze (E, False);
494 if not Error_Posted (Expr)
495 and then not Controlled_Type (Typ)
497 Warn_Overlay (Expr, Typ, Name (Addr));
500 end Check_Address_Clause;
502 -----------------------------
503 -- Check_Compile_Time_Size --
504 -----------------------------
506 procedure Check_Compile_Time_Size (T : Entity_Id) is
508 procedure Set_Small_Size (S : Uint);
509 -- Sets the compile time known size (32 bits or less) in the Esize
510 -- field, checking for a size clause that was given which attempts
511 -- to give a smaller size.
513 function Size_Known (T : Entity_Id) return Boolean;
514 -- Recursive function that does all the work
516 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
517 -- If T is a constrained subtype, its size is not known if any of its
518 -- discriminant constraints is not static and it is not a null record.
519 -- The test is conservative and doesn't check that the components are
520 -- in fact constrained by non-static discriminant values. Could be made
527 procedure Set_Small_Size (S : Uint) is
532 elsif Has_Size_Clause (T) then
533 if RM_Size (T) < S then
534 Error_Msg_Uint_1 := S;
536 ("size for & is too small, minimum is ^",
539 elsif Unknown_Esize (T) then
543 -- Set sizes if not set already
546 if Unknown_Esize (T) then
550 if Unknown_RM_Size (T) then
560 function Size_Known (T : Entity_Id) return Boolean is
568 if Size_Known_At_Compile_Time (T) then
571 elsif Is_Scalar_Type (T)
572 or else Is_Task_Type (T)
574 return not Is_Generic_Type (T);
576 elsif Is_Array_Type (T) then
577 if Ekind (T) = E_String_Literal_Subtype then
578 Set_Small_Size (Component_Size (T) * String_Literal_Length (T));
581 elsif not Is_Constrained (T) then
584 -- Don't do any recursion on type with error posted, since
585 -- we may have a malformed type that leads us into a loop
587 elsif Error_Posted (T) then
590 elsif not Size_Known (Component_Type (T)) then
594 -- Check for all indexes static, and also compute possible
595 -- size (in case it is less than 32 and may be packable).
598 Esiz : Uint := Component_Size (T);
602 Index := First_Index (T);
604 while Present (Index) loop
605 if Nkind (Index) = N_Range then
606 Get_Index_Bounds (Index, Low, High);
608 elsif Error_Posted (Scalar_Range (Etype (Index))) then
612 Low := Type_Low_Bound (Etype (Index));
613 High := Type_High_Bound (Etype (Index));
616 if not Compile_Time_Known_Value (Low)
617 or else not Compile_Time_Known_Value (High)
618 or else Etype (Index) = Any_Type
623 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
635 Set_Small_Size (Esiz);
639 elsif Is_Access_Type (T) then
642 elsif Is_Private_Type (T)
643 and then not Is_Generic_Type (T)
644 and then Present (Underlying_Type (T))
646 -- Don't do any recursion on type with error posted, since
647 -- we may have a malformed type that leads us into a loop
649 if Error_Posted (T) then
652 return Size_Known (Underlying_Type (T));
655 elsif Is_Record_Type (T) then
657 -- A class-wide type is never considered to have a known size
659 if Is_Class_Wide_Type (T) then
662 -- A subtype of a variant record must not have non-static
663 -- discriminanted components.
665 elsif T /= Base_Type (T)
666 and then not Static_Discriminated_Components (T)
670 -- Don't do any recursion on type with error posted, since
671 -- we may have a malformed type that leads us into a loop
673 elsif Error_Posted (T) then
677 -- Now look at the components of the record
680 -- The following two variables are used to keep track of
681 -- the size of packed records if we can tell the size of
682 -- the packed record in the front end. Packed_Size_Known
683 -- is True if so far we can figure out the size. It is
684 -- initialized to True for a packed record, unless the
685 -- record has discriminants. The reason we eliminate the
686 -- discriminated case is that we don't know the way the
687 -- back end lays out discriminated packed records. If
688 -- Packed_Size_Known is True, then Packed_Size is the
689 -- size in bits so far.
691 Packed_Size_Known : Boolean :=
693 and then not Has_Discriminants (T);
695 Packed_Size : Uint := Uint_0;
698 -- Test for variant part present
700 if Has_Discriminants (T)
701 and then Present (Parent (T))
702 and then Nkind (Parent (T)) = N_Full_Type_Declaration
703 and then Nkind (Type_Definition (Parent (T))) =
705 and then not Null_Present (Type_Definition (Parent (T)))
706 and then Present (Variant_Part
707 (Component_List (Type_Definition (Parent (T)))))
709 -- If variant part is present, and type is unconstrained,
710 -- then we must have defaulted discriminants, or a size
711 -- clause must be present for the type, or else the size
712 -- is definitely not known at compile time.
714 if not Is_Constrained (T)
716 No (Discriminant_Default_Value
717 (First_Discriminant (T)))
718 and then Unknown_Esize (T)
724 -- Loop through components
726 Comp := First_Entity (T);
727 while Present (Comp) loop
728 if Ekind (Comp) = E_Component
730 Ekind (Comp) = E_Discriminant
732 Ctyp := Etype (Comp);
734 -- We do not know the packed size if there is a
735 -- component clause present (we possibly could,
736 -- but this would only help in the case of a record
737 -- with partial rep clauses. That's because in the
738 -- case of full rep clauses, the size gets figured
739 -- out anyway by a different circuit).
741 if Present (Component_Clause (Comp)) then
742 Packed_Size_Known := False;
745 -- We need to identify a component that is an array
746 -- where the index type is an enumeration type with
747 -- non-standard representation, and some bound of the
748 -- type depends on a discriminant.
750 -- This is because gigi computes the size by doing a
751 -- substituation of the appropriate discriminant value
752 -- in the size expression for the base type, and gigi
753 -- is not clever enough to evaluate the resulting
754 -- expression (which involves a call to rep_to_pos)
757 -- It would be nice if gigi would either recognize that
758 -- this expression can be computed at compile time, or
759 -- alternatively figured out the size from the subtype
760 -- directly, where all the information is at hand ???
762 if Is_Array_Type (Etype (Comp))
763 and then Present (Packed_Array_Type (Etype (Comp)))
766 Ocomp : constant Entity_Id :=
767 Original_Record_Component (Comp);
768 OCtyp : constant Entity_Id := Etype (Ocomp);
774 Ind := First_Index (OCtyp);
775 while Present (Ind) loop
776 Indtyp := Etype (Ind);
778 if Is_Enumeration_Type (Indtyp)
779 and then Has_Non_Standard_Rep (Indtyp)
781 Lo := Type_Low_Bound (Indtyp);
782 Hi := Type_High_Bound (Indtyp);
784 if Is_Entity_Name (Lo)
786 Ekind (Entity (Lo)) = E_Discriminant
790 elsif Is_Entity_Name (Hi)
792 Ekind (Entity (Hi)) = E_Discriminant
803 -- Clearly size of record is not known if the size of
804 -- one of the components is not known.
806 if not Size_Known (Ctyp) then
810 -- Accumulate packed size if possible
812 if Packed_Size_Known then
814 -- We can only deal with elementary types, since for
815 -- non-elementary components, alignment enters into
816 -- the picture, and we don't know enough to handle
817 -- proper alignment in this context. Packed arrays
818 -- count as elementary if the representation is a
821 if Is_Elementary_Type (Ctyp)
822 or else (Is_Array_Type (Ctyp)
824 Present (Packed_Array_Type (Ctyp))
826 Is_Modular_Integer_Type
827 (Packed_Array_Type (Ctyp)))
829 -- If RM_Size is known and static, then we can
830 -- keep accumulating the packed size.
832 if Known_Static_RM_Size (Ctyp) then
834 -- A little glitch, to be removed sometime ???
835 -- gigi does not understand zero sizes yet.
837 if RM_Size (Ctyp) = Uint_0 then
838 Packed_Size_Known := False;
840 -- Normal case where we can keep accumulating
841 -- the packed array size.
844 Packed_Size := Packed_Size + RM_Size (Ctyp);
847 -- If we have a field whose RM_Size is not known
848 -- then we can't figure out the packed size here.
851 Packed_Size_Known := False;
854 -- If we have a non-elementary type we can't figure
855 -- out the packed array size (alignment issues).
858 Packed_Size_Known := False;
866 if Packed_Size_Known then
867 Set_Small_Size (Packed_Size);
878 -------------------------------------
879 -- Static_Discriminated_Components --
880 -------------------------------------
882 function Static_Discriminated_Components
886 Constraint : Elmt_Id;
889 if Has_Discriminants (T)
890 and then Present (Discriminant_Constraint (T))
891 and then Present (First_Component (T))
893 Constraint := First_Elmt (Discriminant_Constraint (T));
894 while Present (Constraint) loop
895 if not Compile_Time_Known_Value (Node (Constraint)) then
899 Next_Elmt (Constraint);
904 end Static_Discriminated_Components;
906 -- Start of processing for Check_Compile_Time_Size
909 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
910 end Check_Compile_Time_Size;
912 -----------------------------
913 -- Check_Debug_Info_Needed --
914 -----------------------------
916 procedure Check_Debug_Info_Needed (T : Entity_Id) is
918 if Needs_Debug_Info (T) or else Debug_Info_Off (T) then
921 elsif Comes_From_Source (T)
922 or else Debug_Generated_Code
923 or else Debug_Flag_VV
925 Set_Debug_Info_Needed (T);
927 end Check_Debug_Info_Needed;
929 ----------------------------
930 -- Check_Strict_Alignment --
931 ----------------------------
933 procedure Check_Strict_Alignment (E : Entity_Id) is
937 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
938 Set_Strict_Alignment (E);
940 elsif Is_Array_Type (E) then
941 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
943 elsif Is_Record_Type (E) then
944 if Is_Limited_Record (E) then
945 Set_Strict_Alignment (E);
949 Comp := First_Component (E);
951 while Present (Comp) loop
952 if not Is_Type (Comp)
953 and then (Strict_Alignment (Etype (Comp))
954 or else Is_Aliased (Comp))
956 Set_Strict_Alignment (E);
960 Next_Component (Comp);
963 end Check_Strict_Alignment;
965 -------------------------
966 -- Check_Unsigned_Type --
967 -------------------------
969 procedure Check_Unsigned_Type (E : Entity_Id) is
970 Ancestor : Entity_Id;
975 if not Is_Discrete_Or_Fixed_Point_Type (E) then
979 -- Do not attempt to analyze case where range was in error
981 if Error_Posted (Scalar_Range (E)) then
985 -- The situation that is non trivial is something like
987 -- subtype x1 is integer range -10 .. +10;
988 -- subtype x2 is x1 range 0 .. V1;
989 -- subtype x3 is x2 range V2 .. V3;
990 -- subtype x4 is x3 range V4 .. V5;
992 -- where Vn are variables. Here the base type is signed, but we still
993 -- know that x4 is unsigned because of the lower bound of x2.
995 -- The only way to deal with this is to look up the ancestor chain
999 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1003 Lo_Bound := Type_Low_Bound (Ancestor);
1005 if Compile_Time_Known_Value (Lo_Bound) then
1007 if Expr_Rep_Value (Lo_Bound) >= 0 then
1008 Set_Is_Unsigned_Type (E, True);
1014 Ancestor := Ancestor_Subtype (Ancestor);
1016 -- If no ancestor had a static lower bound, go to base type
1018 if No (Ancestor) then
1020 -- Note: the reason we still check for a compile time known
1021 -- value for the base type is that at least in the case of
1022 -- generic formals, we can have bounds that fail this test,
1023 -- and there may be other cases in error situations.
1025 Btyp := Base_Type (E);
1027 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1031 Lo_Bound := Type_Low_Bound (Base_Type (E));
1033 if Compile_Time_Known_Value (Lo_Bound)
1034 and then Expr_Rep_Value (Lo_Bound) >= 0
1036 Set_Is_Unsigned_Type (E, True);
1043 end Check_Unsigned_Type;
1045 -----------------------------
1046 -- Expand_Atomic_Aggregate --
1047 -----------------------------
1049 procedure Expand_Atomic_Aggregate (E : Entity_Id; Typ : Entity_Id) is
1050 Loc : constant Source_Ptr := Sloc (E);
1055 if (Nkind (Parent (E)) = N_Object_Declaration
1056 or else Nkind (Parent (E)) = N_Assignment_Statement)
1057 and then Comes_From_Source (Parent (E))
1058 and then Nkind (E) = N_Aggregate
1061 Make_Defining_Identifier (Loc,
1062 New_Internal_Name ('T'));
1065 Make_Object_Declaration (Loc,
1066 Defining_Identifier => Temp,
1067 Object_definition => New_Occurrence_Of (Typ, Loc),
1068 Expression => Relocate_Node (E));
1069 Insert_Before (Parent (E), New_N);
1072 Set_Expression (Parent (E), New_Occurrence_Of (Temp, Loc));
1074 -- To prevent the temporary from being constant-folded (which
1075 -- would lead to the same piecemeal assignment on the original
1076 -- target) indicate to the back-end that the temporary is a
1077 -- variable with real storage. See description of this flag
1078 -- in Einfo, and the notes on N_Assignment_Statement and
1079 -- N_Object_Declaration in Sinfo.
1081 Set_Is_True_Constant (Temp, False);
1083 end Expand_Atomic_Aggregate;
1089 -- Note: the easy coding for this procedure would be to just build a
1090 -- single list of freeze nodes and then insert them and analyze them
1091 -- all at once. This won't work, because the analysis of earlier freeze
1092 -- nodes may recursively freeze types which would otherwise appear later
1093 -- on in the freeze list. So we must analyze and expand the freeze nodes
1094 -- as they are generated.
1096 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1097 Loc : constant Source_Ptr := Sloc (After);
1101 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1102 -- This is the internal recursive routine that does freezing of
1103 -- entities (but NOT the analysis of default expressions, which
1104 -- should not be recursive, we don't want to analyze those till
1105 -- we are sure that ALL the types are frozen).
1107 --------------------
1108 -- Freeze_All_Ent --
1109 --------------------
1111 procedure Freeze_All_Ent
1113 After : in out Node_Id)
1119 procedure Process_Flist;
1120 -- If freeze nodes are present, insert and analyze, and reset
1121 -- cursor for next insertion.
1127 procedure Process_Flist is
1129 if Is_Non_Empty_List (Flist) then
1130 Lastn := Next (After);
1131 Insert_List_After_And_Analyze (After, Flist);
1133 if Present (Lastn) then
1134 After := Prev (Lastn);
1136 After := Last (List_Containing (After));
1141 -- Start or processing for Freeze_All_Ent
1145 while Present (E) loop
1147 -- If the entity is an inner package which is not a package
1148 -- renaming, then its entities must be frozen at this point.
1149 -- Note that such entities do NOT get frozen at the end of
1150 -- the nested package itself (only library packages freeze).
1152 -- Same is true for task declarations, where anonymous records
1153 -- created for entry parameters must be frozen.
1155 if Ekind (E) = E_Package
1156 and then No (Renamed_Object (E))
1157 and then not Is_Child_Unit (E)
1158 and then not Is_Frozen (E)
1161 Install_Visible_Declarations (E);
1162 Install_Private_Declarations (E);
1164 Freeze_All (First_Entity (E), After);
1166 End_Package_Scope (E);
1168 elsif Ekind (E) in Task_Kind
1170 (Nkind (Parent (E)) = N_Task_Type_Declaration
1172 Nkind (Parent (E)) = N_Single_Task_Declaration)
1175 Freeze_All (First_Entity (E), After);
1178 -- For a derived tagged type, we must ensure that all the
1179 -- primitive operations of the parent have been frozen, so
1180 -- that their addresses will be in the parent's dispatch table
1181 -- at the point it is inherited.
1183 elsif Ekind (E) = E_Record_Type
1184 and then Is_Tagged_Type (E)
1185 and then Is_Tagged_Type (Etype (E))
1186 and then Is_Derived_Type (E)
1189 Prim_List : constant Elist_Id :=
1190 Primitive_Operations (Etype (E));
1196 Prim := First_Elmt (Prim_List);
1198 while Present (Prim) loop
1199 Subp := Node (Prim);
1201 if Comes_From_Source (Subp)
1202 and then not Is_Frozen (Subp)
1204 Flist := Freeze_Entity (Subp, Loc);
1213 if not Is_Frozen (E) then
1214 Flist := Freeze_Entity (E, Loc);
1218 -- If an incomplete type is still not frozen, this may be
1219 -- a premature freezing because of a body declaration that
1220 -- follows. Indicate where the freezing took place.
1222 -- If the freezing is caused by the end of the current
1223 -- declarative part, it is a Taft Amendment type, and there
1226 if not Is_Frozen (E)
1227 and then Ekind (E) = E_Incomplete_Type
1230 Bod : constant Node_Id := Next (After);
1233 if (Nkind (Bod) = N_Subprogram_Body
1234 or else Nkind (Bod) = N_Entry_Body
1235 or else Nkind (Bod) = N_Package_Body
1236 or else Nkind (Bod) = N_Protected_Body
1237 or else Nkind (Bod) = N_Task_Body
1238 or else Nkind (Bod) in N_Body_Stub)
1240 List_Containing (After) = List_Containing (Parent (E))
1242 Error_Msg_Sloc := Sloc (Next (After));
1244 ("type& is frozen# before its full declaration",
1254 -- Start of processing for Freeze_All
1257 Freeze_All_Ent (From, After);
1259 -- Now that all types are frozen, we can deal with default expressions
1260 -- that require us to build a default expression functions. This is the
1261 -- point at which such functions are constructed (after all types that
1262 -- might be used in such expressions have been frozen).
1264 -- We also add finalization chains to access types whose designated
1265 -- types are controlled. This is normally done when freezing the type,
1266 -- but this misses recursive type definitions where the later members
1267 -- of the recursion introduce controlled components (e.g. 5624-001).
1269 -- Loop through entities
1272 while Present (E) loop
1273 if Is_Subprogram (E) then
1275 if not Default_Expressions_Processed (E) then
1276 Process_Default_Expressions (E, After);
1279 if not Has_Completion (E) then
1280 Decl := Unit_Declaration_Node (E);
1282 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1283 Build_And_Analyze_Renamed_Body (Decl, E, After);
1285 elsif Nkind (Decl) = N_Subprogram_Declaration
1286 and then Present (Corresponding_Body (Decl))
1288 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1289 = N_Subprogram_Renaming_Declaration
1291 Build_And_Analyze_Renamed_Body
1292 (Decl, Corresponding_Body (Decl), After);
1296 elsif Ekind (E) in Task_Kind
1298 (Nkind (Parent (E)) = N_Task_Type_Declaration
1300 Nkind (Parent (E)) = N_Single_Task_Declaration)
1305 Ent := First_Entity (E);
1307 while Present (Ent) loop
1310 and then not Default_Expressions_Processed (Ent)
1312 Process_Default_Expressions (Ent, After);
1319 elsif Is_Access_Type (E)
1320 and then Comes_From_Source (E)
1321 and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
1322 and then Controlled_Type (Designated_Type (E))
1323 and then No (Associated_Final_Chain (E))
1325 Build_Final_List (Parent (E), E);
1332 -----------------------
1333 -- Freeze_And_Append --
1334 -----------------------
1336 procedure Freeze_And_Append
1339 Result : in out List_Id)
1341 L : constant List_Id := Freeze_Entity (Ent, Loc);
1344 if Is_Non_Empty_List (L) then
1345 if Result = No_List then
1348 Append_List (L, Result);
1351 end Freeze_And_Append;
1357 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1358 Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
1361 if Is_Non_Empty_List (Freeze_Nodes) then
1362 Insert_Actions (N, Freeze_Nodes);
1370 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
1378 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1379 -- Check that an Access or Unchecked_Access attribute with
1380 -- a prefix which is the current instance type can only be
1381 -- applied when the type is limited.
1383 function After_Last_Declaration return Boolean;
1384 -- If Loc is a freeze_entity that appears after the last declaration
1385 -- in the scope, inhibit error messages on late completion.
1387 procedure Freeze_Record_Type (Rec : Entity_Id);
1388 -- Freeze each component, handle some representation clauses, and
1389 -- freeze primitive operations if this is a tagged type.
1391 ----------------------------
1392 -- After_Last_Declaration --
1393 ----------------------------
1395 function After_Last_Declaration return Boolean is
1396 Spec : constant Node_Id := Parent (Current_Scope);
1399 if Nkind (Spec) = N_Package_Specification then
1400 if Present (Private_Declarations (Spec)) then
1401 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1403 elsif Present (Visible_Declarations (Spec)) then
1404 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1412 end After_Last_Declaration;
1414 ----------------------------
1415 -- Check_Current_Instance --
1416 ----------------------------
1418 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1420 function Process (N : Node_Id) return Traverse_Result;
1421 -- Process routine to apply check to given node.
1427 function Process (N : Node_Id) return Traverse_Result is
1430 when N_Attribute_Reference =>
1431 if (Attribute_Name (N) = Name_Access
1433 Attribute_Name (N) = Name_Unchecked_Access)
1434 and then Is_Entity_Name (Prefix (N))
1435 and then Is_Type (Entity (Prefix (N)))
1436 and then Entity (Prefix (N)) = E
1439 ("current instance must be a limited type", Prefix (N));
1445 when others => return OK;
1449 procedure Traverse is new Traverse_Proc (Process);
1451 -- Start of processing for Check_Current_Instance
1454 Traverse (Comp_Decl);
1455 end Check_Current_Instance;
1457 ------------------------
1458 -- Freeze_Record_Type --
1459 ------------------------
1461 procedure Freeze_Record_Type (Rec : Entity_Id) is
1467 Unplaced_Component : Boolean := False;
1468 -- Set True if we find at least one component with no component
1469 -- clause (used to warn about useless Pack pragmas).
1471 Placed_Component : Boolean := False;
1472 -- Set True if we find at least one component with a component
1473 -- clause (used to warn about useless Bit_Order pragmas).
1476 -- If this is a subtype of a controlled type, declared without
1477 -- a constraint, the _controller may not appear in the component
1478 -- list if the parent was not frozen at the point of subtype
1479 -- declaration. Inherit the _controller component now.
1481 if Rec /= Base_Type (Rec)
1482 and then Has_Controlled_Component (Rec)
1484 if Nkind (Parent (Rec)) = N_Subtype_Declaration
1485 and then Is_Entity_Name (Subtype_Indication (Parent (Rec)))
1487 Set_First_Entity (Rec, First_Entity (Base_Type (Rec)));
1489 -- If this is an internal type without a declaration, as for
1490 -- a record component, the base type may not yet be frozen,
1491 -- and its controller has not been created. Add an explicit
1492 -- freeze node for the itype, so it will be frozen after the
1495 elsif Is_Itype (Rec)
1496 and then Has_Delayed_Freeze (Base_Type (Rec))
1498 Nkind (Associated_Node_For_Itype (Rec)) =
1499 N_Component_Declaration
1501 Ensure_Freeze_Node (Rec);
1505 -- Freeze components and embedded subtypes
1507 Comp := First_Entity (Rec);
1508 while Present (Comp) loop
1509 if not Is_Type (Comp) then
1510 Freeze_And_Append (Etype (Comp), Loc, Result);
1513 -- If the component is an access type with an allocator
1514 -- as default value, the designated type will be frozen
1515 -- by the corresponding expression in init_proc. In order
1516 -- to place the freeze node for the designated type before
1517 -- that for the current record type, freeze it now.
1519 -- Same process if the component is an array of access types,
1520 -- initialized with an aggregate. If the designated type is
1521 -- private, it cannot contain allocators, and it is premature
1522 -- to freeze the type, so we check for this as well.
1524 if Is_Access_Type (Etype (Comp))
1525 and then Present (Parent (Comp))
1526 and then Present (Expression (Parent (Comp)))
1527 and then Nkind (Expression (Parent (Comp))) = N_Allocator
1530 Alloc : constant Node_Id := Expression (Parent (Comp));
1533 -- If component is pointer to a classwide type, freeze
1534 -- the specific type in the expression being allocated.
1535 -- The expression may be a subtype indication, in which
1536 -- case freeze the subtype mark.
1538 if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
1539 if Is_Entity_Name (Expression (Alloc)) then
1541 (Entity (Expression (Alloc)), Loc, Result);
1543 Nkind (Expression (Alloc)) = N_Subtype_Indication
1546 (Entity (Subtype_Mark (Expression (Alloc))),
1552 (Designated_Type (Etype (Comp)), Loc, Result);
1556 -- If this is a constrained subtype of an already frozen type,
1557 -- make the subtype frozen as well. It might otherwise be frozen
1558 -- in the wrong scope, and a freeze node on subtype has no effect.
1560 elsif Is_Access_Type (Etype (Comp))
1561 and then not Is_Frozen (Designated_Type (Etype (Comp)))
1562 and then Is_Itype (Designated_Type (Etype (Comp)))
1563 and then Is_Frozen (Base_Type (Designated_Type (Etype (Comp))))
1565 Set_Is_Frozen (Designated_Type (Etype (Comp)));
1567 -- In addition, add an Itype_Reference to ensure that the
1568 -- access subtype is elaborated early enough. This cannot
1569 -- be done if the subtype may depend on discriminants.
1571 if Ekind (Comp) = E_Component
1572 and then Is_Itype (Etype (Comp))
1573 and then not Has_Discriminants (Rec)
1575 IR := Make_Itype_Reference (Sloc (Comp));
1576 Set_Itype (IR, Designated_Type (Etype (Comp)));
1579 Result := New_List (IR);
1581 Append (IR, Result);
1585 elsif Is_Array_Type (Etype (Comp))
1586 and then Is_Access_Type (Component_Type (Etype (Comp)))
1587 and then Present (Parent (Comp))
1588 and then Nkind (Parent (Comp)) = N_Component_Declaration
1589 and then Present (Expression (Parent (Comp)))
1590 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
1591 and then Is_Fully_Defined
1592 (Designated_Type (Component_Type (Etype (Comp))))
1596 (Component_Type (Etype (Comp))), Loc, Result);
1599 -- Processing for real components (exclude anonymous subtypes)
1601 if Ekind (Comp) = E_Component
1602 or else Ekind (Comp) = E_Discriminant
1604 -- Check for error of component clause given for variable
1605 -- sized type. We have to delay this test till this point,
1606 -- since the component type has to be frozen for us to know
1607 -- if it is variable length. We omit this test in a generic
1608 -- context, it will be applied at instantiation time.
1611 CC : constant Node_Id := Component_Clause (Comp);
1614 if Present (CC) then
1615 Placed_Component := True;
1617 if Inside_A_Generic then
1620 elsif not Size_Known_At_Compile_Time
1621 (Underlying_Type (Etype (Comp)))
1624 ("component clause not allowed for variable " &
1625 "length component", CC);
1629 Unplaced_Component := True;
1633 -- If component clause is present, then deal with the
1634 -- non-default bit order case. We cannot do this before
1635 -- the freeze point, because there is no required order
1636 -- for the component clause and the bit_order clause.
1638 -- We only do this processing for the base type, and in
1639 -- fact that's important, since otherwise if there are
1640 -- record subtypes, we could reverse the bits once for
1641 -- each subtype, which would be incorrect.
1643 if Present (Component_Clause (Comp))
1644 and then Reverse_Bit_Order (Rec)
1645 and then Ekind (E) = E_Record_Type
1648 CFB : constant Uint := Component_Bit_Offset (Comp);
1649 CSZ : constant Uint := Esize (Comp);
1650 CLC : constant Node_Id := Component_Clause (Comp);
1651 Pos : constant Node_Id := Position (CLC);
1652 FB : constant Node_Id := First_Bit (CLC);
1654 Storage_Unit_Offset : constant Uint :=
1655 CFB / System_Storage_Unit;
1657 Start_Bit : constant Uint :=
1658 CFB mod System_Storage_Unit;
1661 -- Cases where field goes over storage unit boundary
1663 if Start_Bit + CSZ > System_Storage_Unit then
1665 -- Allow multi-byte field but generate warning
1667 if Start_Bit mod System_Storage_Unit = 0
1668 and then CSZ mod System_Storage_Unit = 0
1671 ("multi-byte field specified with non-standard"
1672 & " Bit_Order?", CLC);
1674 if Bytes_Big_Endian then
1676 ("bytes are not reversed "
1677 & "(component is big-endian)?", CLC);
1680 ("bytes are not reversed "
1681 & "(component is little-endian)?", CLC);
1684 -- Do not allow non-contiguous field
1688 ("attempt to specify non-contiguous field"
1689 & " not permitted", CLC);
1691 ("\(caused by non-standard Bit_Order "
1692 & "specified)", CLC);
1695 -- Case where field fits in one storage unit
1698 -- Give warning if suspicious component clause
1700 if Intval (FB) >= System_Storage_Unit then
1702 ("?Bit_Order clause does not affect " &
1703 "byte ordering", Pos);
1705 Intval (Pos) + Intval (FB) / 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 (Comp,
1732 (Storage_Unit_Offset * System_Storage_Unit)
1733 + (System_Storage_Unit - 1)
1734 - (Start_Bit + CSZ - 1));
1736 Set_Normalized_First_Bit (Comp,
1737 Component_Bit_Offset (Comp) mod System_Storage_Unit);
1746 -- Check for useless pragma Bit_Order
1748 if not Placed_Component and then Reverse_Bit_Order (Rec) then
1749 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
1750 Error_Msg_N ("?Bit_Order specification has no effect", ADC);
1751 Error_Msg_N ("\?since no component clauses were specified", ADC);
1754 -- Check for useless pragma Pack when all components placed
1757 and then not Unplaced_Component
1758 and then Warn_On_Redundant_Constructs
1761 ("?pragma Pack has no effect, no unplaced components",
1762 Get_Rep_Pragma (Rec, Name_Pack));
1763 Set_Is_Packed (Rec, False);
1766 -- If this is the record corresponding to a remote type,
1767 -- freeze the remote type here since that is what we are
1768 -- semantically freezing. This prevents having the freeze
1769 -- node for that type in an inner scope.
1771 -- Also, Check for controlled components and unchecked unions.
1772 -- Finally, enforce the restriction that access attributes with
1773 -- a current instance prefix can only apply to limited types.
1775 if Ekind (Rec) = E_Record_Type then
1776 if Present (Corresponding_Remote_Type (Rec)) then
1778 (Corresponding_Remote_Type (Rec), Loc, Result);
1781 Comp := First_Component (Rec);
1782 while Present (Comp) loop
1783 if Has_Controlled_Component (Etype (Comp))
1784 or else (Chars (Comp) /= Name_uParent
1785 and then Is_Controlled (Etype (Comp)))
1786 or else (Is_Protected_Type (Etype (Comp))
1788 (Corresponding_Record_Type (Etype (Comp)))
1789 and then Has_Controlled_Component
1790 (Corresponding_Record_Type (Etype (Comp))))
1792 Set_Has_Controlled_Component (Rec);
1796 if Has_Unchecked_Union (Etype (Comp)) then
1797 Set_Has_Unchecked_Union (Rec);
1800 if Has_Per_Object_Constraint (Comp)
1801 and then not Is_Limited_Type (Rec)
1803 -- Scan component declaration for likely misuses of
1804 -- current instance, either in a constraint or in a
1805 -- default expression.
1807 Check_Current_Instance (Parent (Comp));
1810 Next_Component (Comp);
1814 Set_Component_Alignment_If_Not_Set (Rec);
1816 -- For first subtypes, check if there are any fixed-point
1817 -- fields with component clauses, where we must check the size.
1818 -- This is not done till the freeze point, since for fixed-point
1819 -- types, we do not know the size until the type is frozen.
1821 if Is_First_Subtype (Rec) then
1822 Comp := First_Component (Rec);
1824 while Present (Comp) loop
1825 if Present (Component_Clause (Comp))
1826 and then Is_Fixed_Point_Type (Etype (Comp))
1829 (Component_Clause (Comp),
1835 Next_Component (Comp);
1838 end Freeze_Record_Type;
1840 -- Start of processing for Freeze_Entity
1843 -- Do not freeze if already frozen since we only need one freeze node
1845 if Is_Frozen (E) then
1848 -- It is improper to freeze an external entity within a generic
1849 -- because its freeze node will appear in a non-valid context.
1850 -- ??? We should probably freeze the entity at that point and insert
1851 -- the freeze node in a proper place but this proper place is not
1852 -- easy to find, and the proper scope is not easy to restore. For
1853 -- now, just wait to get out of the generic to freeze ???
1855 elsif Inside_A_Generic and then External_Ref_In_Generic (E) then
1858 -- Do not freeze a global entity within an inner scope created during
1859 -- expansion. A call to subprogram E within some internal procedure
1860 -- (a stream attribute for example) might require freezing E, but the
1861 -- freeze node must appear in the same declarative part as E itself.
1862 -- The two-pass elaboration mechanism in gigi guarantees that E will
1863 -- be frozen before the inner call is elaborated. We exclude constants
1864 -- from this test, because deferred constants may be frozen early, and
1865 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
1866 -- comes from source, or is a generic instance, then the freeze point
1867 -- is the one mandated by the language. and we freze the entity.
1869 elsif In_Open_Scopes (Scope (E))
1870 and then Scope (E) /= Current_Scope
1871 and then Ekind (E) /= E_Constant
1874 S : Entity_Id := Current_Scope;
1877 while Present (S) loop
1878 if Is_Overloadable (S) then
1879 if Comes_From_Source (S)
1880 or else Is_Generic_Instance (S)
1893 -- Here to freeze the entity
1898 -- Case of entity being frozen is other than a type
1900 if not Is_Type (E) then
1902 -- If entity is exported or imported and does not have an external
1903 -- name, now is the time to provide the appropriate default name.
1904 -- Skip this if the entity is stubbed, since we don't need a name
1905 -- for any stubbed routine.
1907 if (Is_Imported (E) or else Is_Exported (E))
1908 and then No (Interface_Name (E))
1909 and then Convention (E) /= Convention_Stubbed
1911 Set_Encoded_Interface_Name
1912 (E, Get_Default_External_Name (E));
1914 -- Special processing for atomic objects appearing in object decls
1917 and then Nkind (Parent (E)) = N_Object_Declaration
1918 and then Present (Expression (Parent (E)))
1921 Expr : constant Node_Id := Expression (Parent (E));
1924 -- If expression is an aggregate, assign to a temporary to
1925 -- ensure that the actual assignment is done atomically rather
1926 -- than component-wise (the assignment to the temp may be done
1927 -- component-wise, but that is harmless.
1929 if Nkind (Expr) = N_Aggregate then
1930 Expand_Atomic_Aggregate (Expr, Etype (E));
1932 -- If the expression is a reference to a record or array
1933 -- object entity, then reset Is_True_Constant to False so
1934 -- that the compiler will not optimize away the intermediate
1935 -- object, which we need in this case for the same reason
1936 -- (to ensure that the actual assignment is atomic, rather
1937 -- than component-wise).
1939 elsif Is_Entity_Name (Expr)
1940 and then (Is_Record_Type (Etype (Expr))
1942 Is_Array_Type (Etype (Expr)))
1944 Set_Is_True_Constant (Entity (Expr), False);
1949 -- For a subprogram, freeze all parameter types and also the return
1950 -- type (RM 13.14(14)). However skip this for internal subprograms.
1951 -- This is also the point where any extra formal parameters are
1952 -- created since we now know whether the subprogram will use
1953 -- a foreign convention.
1955 if Is_Subprogram (E) then
1956 if not Is_Internal (E) then
1960 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean;
1961 -- Determines if given type entity is a fat pointer type
1962 -- used as an argument type or return type to a subprogram
1963 -- with C or C++ convention set.
1965 --------------------------
1966 -- Is_Fat_C_Access_Type --
1967 --------------------------
1969 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is
1971 return (Convention (E) = Convention_C
1973 Convention (E) = Convention_CPP)
1974 and then Is_Access_Type (T)
1975 and then Esize (T) > Ttypes.System_Address_Size;
1976 end Is_Fat_C_Ptr_Type;
1979 -- Loop through formals
1981 Formal := First_Formal (E);
1983 while Present (Formal) loop
1984 F_Type := Etype (Formal);
1985 Freeze_And_Append (F_Type, Loc, Result);
1987 if Is_Private_Type (F_Type)
1988 and then Is_Private_Type (Base_Type (F_Type))
1989 and then No (Full_View (Base_Type (F_Type)))
1990 and then not Is_Generic_Type (F_Type)
1991 and then not Is_Derived_Type (F_Type)
1993 -- If the type of a formal is incomplete, subprogram
1994 -- is being frozen prematurely. Within an instance
1995 -- (but not within a wrapper package) this is an
1996 -- an artifact of our need to regard the end of an
1997 -- instantiation as a freeze point. Otherwise it is
1998 -- a definite error.
2000 -- and then not Is_Wrapper_Package (Current_Scope) ???
2003 Set_Is_Frozen (E, False);
2006 elsif not After_Last_Declaration then
2007 Error_Msg_Node_1 := F_Type;
2009 ("type& must be fully defined before this point",
2014 -- Check bad use of fat C pointer
2016 if Warn_On_Export_Import and then
2017 Is_Fat_C_Ptr_Type (F_Type)
2019 Error_Msg_Qual_Level := 1;
2021 ("?type of & does not correspond to C pointer",
2023 Error_Msg_Qual_Level := 0;
2026 -- Check for unconstrained array in exported foreign
2029 if Convention (E) in Foreign_Convention
2030 and then not Is_Imported (E)
2031 and then Is_Array_Type (F_Type)
2032 and then not Is_Constrained (F_Type)
2033 and then Warn_On_Export_Import
2035 Error_Msg_Qual_Level := 1;
2037 ("?type of argument& is unconstrained array",
2040 ("?foreign caller must pass bounds explicitly",
2042 Error_Msg_Qual_Level := 0;
2045 Next_Formal (Formal);
2048 -- Check return type
2050 if Ekind (E) = E_Function then
2051 Freeze_And_Append (Etype (E), Loc, Result);
2053 if Warn_On_Export_Import
2054 and then Is_Fat_C_Ptr_Type (Etype (E))
2057 ("?return type of& does not correspond to C pointer",
2060 elsif Is_Array_Type (Etype (E))
2061 and then not Is_Constrained (Etype (E))
2062 and then not Is_Imported (E)
2063 and then Convention (E) in Foreign_Convention
2064 and then Warn_On_Export_Import
2067 ("?foreign convention function& should not " &
2068 "return unconstrained array", E);
2074 -- Must freeze its parent first if it is a derived subprogram
2076 if Present (Alias (E)) then
2077 Freeze_And_Append (Alias (E), Loc, Result);
2080 -- If the return type requires a transient scope, and we are on
2081 -- a target allowing functions to return with a depressed stack
2082 -- pointer, then we mark the function as requiring this treatment.
2084 if Ekind (E) = E_Function
2085 and then Functions_Return_By_DSP_On_Target
2086 and then Requires_Transient_Scope (Etype (E))
2088 Set_Function_Returns_With_DSP (E);
2091 if not Is_Internal (E) then
2092 Freeze_Subprogram (E);
2095 -- Here for other than a subprogram or type
2098 -- If entity has a type, and it is not a generic unit, then
2099 -- freeze it first (RM 13.14(10))
2101 if Present (Etype (E))
2102 and then Ekind (E) /= E_Generic_Function
2104 Freeze_And_Append (Etype (E), Loc, Result);
2107 -- For object created by object declaration, perform required
2108 -- categorization (preelaborate and pure) checks. Defer these
2109 -- checks to freeze time since pragma Import inhibits default
2110 -- initialization and thus pragma Import affects these checks.
2112 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
2113 Validate_Object_Declaration (Declaration_Node (E));
2114 Check_Address_Clause (E);
2117 -- Check that a constant which has a pragma Volatile[_Components]
2118 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
2120 -- Note: Atomic[_Components] also sets Volatile[_Components]
2122 if Ekind (E) = E_Constant
2123 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
2124 and then not Is_Imported (E)
2126 -- Make sure we actually have a pragma, and have not merely
2127 -- inherited the indication from elsewhere (e.g. an address
2128 -- clause, which is not good enough in RM terms!)
2130 if Present (Get_Rep_Pragma (E, Name_Atomic)) or else
2131 Present (Get_Rep_Pragma (E, Name_Atomic_Components)) or else
2132 Present (Get_Rep_Pragma (E, Name_Volatile)) or else
2133 Present (Get_Rep_Pragma (E, Name_Volatile_Components))
2136 ("stand alone atomic/volatile constant must be imported",
2141 -- Static objects require special handling
2143 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
2144 and then Is_Statically_Allocated (E)
2146 Freeze_Static_Object (E);
2149 -- Remaining step is to layout objects
2151 if Ekind (E) = E_Variable
2153 Ekind (E) = E_Constant
2155 Ekind (E) = E_Loop_Parameter
2163 -- Case of a type or subtype being frozen
2166 -- The type may be defined in a generic unit. This can occur when
2167 -- freezing a generic function that returns the type (which is
2168 -- defined in a parent unit). It is clearly meaningless to freeze
2169 -- this type. However, if it is a subtype, its size may be determi-
2170 -- nable and used in subsequent checks, so might as well try to
2173 if Present (Scope (E))
2174 and then Is_Generic_Unit (Scope (E))
2176 Check_Compile_Time_Size (E);
2180 -- Deal with special cases of freezing for subtype
2182 if E /= Base_Type (E) then
2184 -- If ancestor subtype present, freeze that first.
2185 -- Note that this will also get the base type frozen.
2187 Atype := Ancestor_Subtype (E);
2189 if Present (Atype) then
2190 Freeze_And_Append (Atype, Loc, Result);
2192 -- Otherwise freeze the base type of the entity before
2193 -- freezing the entity itself, (RM 13.14(15)).
2195 elsif E /= Base_Type (E) then
2196 Freeze_And_Append (Base_Type (E), Loc, Result);
2199 -- For a derived type, freeze its parent type first (RM 13.14(15))
2201 elsif Is_Derived_Type (E) then
2202 Freeze_And_Append (Etype (E), Loc, Result);
2203 Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
2206 -- For array type, freeze index types and component type first
2207 -- before freezing the array (RM 13.14(15)).
2209 if Is_Array_Type (E) then
2211 Ctyp : constant Entity_Id := Component_Type (E);
2214 Non_Standard_Enum : Boolean := False;
2215 -- Set true if any of the index types is an enumeration
2216 -- type with a non-standard representation.
2219 Freeze_And_Append (Ctyp, Loc, Result);
2221 Indx := First_Index (E);
2222 while Present (Indx) loop
2223 Freeze_And_Append (Etype (Indx), Loc, Result);
2225 if Is_Enumeration_Type (Etype (Indx))
2226 and then Has_Non_Standard_Rep (Etype (Indx))
2228 Non_Standard_Enum := True;
2234 -- Processing that is done only for base types
2236 if Ekind (E) = E_Array_Type then
2238 -- Propagate flags for component type
2240 if Is_Controlled (Component_Type (E))
2241 or else Has_Controlled_Component (Ctyp)
2243 Set_Has_Controlled_Component (E);
2246 if Has_Unchecked_Union (Component_Type (E)) then
2247 Set_Has_Unchecked_Union (E);
2250 -- If packing was requested or if the component size was set
2251 -- explicitly, then see if bit packing is required. This
2252 -- processing is only done for base types, since all the
2253 -- representation aspects involved are type-related. This
2254 -- is not just an optimization, if we start processing the
2255 -- subtypes, they intefere with the settings on the base
2256 -- type (this is because Is_Packed has a slightly different
2257 -- meaning before and after freezing).
2264 if (Is_Packed (E) or else Has_Pragma_Pack (E))
2265 and then not Has_Atomic_Components (E)
2266 and then Known_Static_RM_Size (Ctyp)
2268 Csiz := UI_Max (RM_Size (Ctyp), 1);
2270 elsif Known_Component_Size (E) then
2271 Csiz := Component_Size (E);
2273 elsif not Known_Static_Esize (Ctyp) then
2277 Esiz := Esize (Ctyp);
2279 -- We can set the component size if it is less than
2280 -- 16, rounding it up to the next storage unit size.
2284 elsif Esiz <= 16 then
2290 -- Set component size up to match alignment if
2291 -- it would otherwise be less than the alignment.
2292 -- This deals with cases of types whose alignment
2293 -- exceeds their sizes (padded types).
2297 A : constant Uint := Alignment_In_Bits (Ctyp);
2308 if 1 <= Csiz and then Csiz <= 64 then
2310 -- We set the component size for all cases 1-64
2312 Set_Component_Size (Base_Type (E), Csiz);
2314 -- Check for base type of 8,16,32 bits, where the
2315 -- subtype has a length one less than the base type
2316 -- and is unsigned (e.g. Natural subtype of Integer)
2318 -- In such cases, if a component size was not set
2319 -- explicitly, then generate a warning.
2321 if Has_Pragma_Pack (E)
2322 and then not Has_Component_Size_Clause (E)
2324 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
2325 and then Esize (Base_Type (Ctyp)) = Csiz + 1
2327 Error_Msg_Uint_1 := Csiz;
2329 Get_Rep_Pragma (First_Subtype (E), Name_Pack);
2331 if Present (Pnod) then
2333 ("pragma Pack causes component size to be ^?",
2336 ("\use Component_Size to set desired value",
2341 -- Actual packing is not needed for 8,16,32,64
2342 -- Also not needed for 24 if alignment is 1
2348 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
2350 -- Here the array was requested to be packed, but
2351 -- the packing request had no effect, so Is_Packed
2354 -- Note: semantically this means that we lose
2355 -- track of the fact that a derived type inherited
2356 -- a pack pragma that was non-effective, but that
2359 -- We regard a Pack pragma as a request to set a
2360 -- representation characteristic, and this request
2363 Set_Is_Packed (Base_Type (E), False);
2365 -- In all other cases, packing is indeed needed
2368 Set_Has_Non_Standard_Rep (Base_Type (E));
2369 Set_Is_Bit_Packed_Array (Base_Type (E));
2370 Set_Is_Packed (Base_Type (E));
2375 -- Processing that is done only for subtypes
2378 -- Acquire alignment from base type
2380 if Unknown_Alignment (E) then
2381 Set_Alignment (E, Alignment (Base_Type (E)));
2385 -- Check one common case of a size given where the array
2386 -- needs to be packed, but was not so the size cannot be
2387 -- honored. This would of course be caught by the backend,
2388 -- and indeed we don't catch all cases. The point is that
2389 -- we can give a better error message in those cases that
2390 -- we do catch with the circuitry here.
2394 Ctyp : constant Entity_Id := Component_Type (E);
2397 if Present (Size_Clause (E))
2398 and then Known_Static_Esize (E)
2399 and then not Is_Bit_Packed_Array (E)
2400 and then not Has_Pragma_Pack (E)
2401 and then Number_Dimensions (E) = 1
2402 and then not Has_Component_Size_Clause (E)
2403 and then Known_Static_Esize (Ctyp)
2405 Get_Index_Bounds (First_Index (E), Lo, Hi);
2407 if Compile_Time_Known_Value (Lo)
2408 and then Compile_Time_Known_Value (Hi)
2409 and then Known_Static_RM_Size (Ctyp)
2410 and then RM_Size (Ctyp) < 64
2413 Lov : constant Uint := Expr_Value (Lo);
2414 Hiv : constant Uint := Expr_Value (Hi);
2415 Len : constant Uint :=
2416 UI_Max (Uint_0, Hiv - Lov + 1);
2417 Rsiz : constant Uint := RM_Size (Ctyp);
2419 -- What we are looking for here is the situation
2420 -- where the Esize given would be exactly right
2421 -- if there was a pragma Pack (resulting in the
2422 -- component size being the same as the RM_Size).
2423 -- Furthermore, the component type size must be
2424 -- an odd size (not a multiple of storage unit)
2427 if Esize (E) = Len * Rsiz
2428 and then Rsiz mod System_Storage_Unit /= 0
2431 ("size given for& too small",
2432 Size_Clause (E), E);
2434 ("\explicit pragma Pack is required",
2442 -- If any of the index types was an enumeration type with
2443 -- a non-standard rep clause, then we indicate that the
2444 -- array type is always packed (even if it is not bit packed).
2446 if Non_Standard_Enum then
2447 Set_Has_Non_Standard_Rep (Base_Type (E));
2448 Set_Is_Packed (Base_Type (E));
2452 Set_Component_Alignment_If_Not_Set (E);
2454 -- If the array is packed, we must create the packed array
2455 -- type to be used to actually implement the type. This is
2456 -- only needed for real array types (not for string literal
2457 -- types, since they are present only for the front end).
2460 and then Ekind (E) /= E_String_Literal_Subtype
2462 Create_Packed_Array_Type (E);
2463 Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
2465 -- Size information of packed array type is copied to the
2466 -- array type, since this is really the representation.
2468 Set_Size_Info (E, Packed_Array_Type (E));
2469 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
2472 -- For a class-wide type, the corresponding specific type is
2473 -- frozen as well (RM 13.14(15))
2475 elsif Is_Class_Wide_Type (E) then
2476 Freeze_And_Append (Root_Type (E), Loc, Result);
2478 -- If the Class_Wide_Type is an Itype (when type is the anonymous
2479 -- parent of a derived type) and it is a library-level entity,
2480 -- generate an itype reference for it. Otherwise, its first
2481 -- explicit reference may be in an inner scope, which will be
2482 -- rejected by the back-end.
2485 and then Is_Compilation_Unit (Scope (E))
2488 Ref : constant Node_Id := Make_Itype_Reference (Loc);
2493 Result := New_List (Ref);
2495 Append (Ref, Result);
2500 -- The equivalent type associated with a class-wide subtype
2501 -- needs to be frozen to ensure that its layout is done.
2502 -- Class-wide subtypes are currently only frozen on targets
2503 -- requiring front-end layout (see New_Class_Wide_Subtype
2504 -- and Make_CW_Equivalent_Type in exp_util.adb).
2506 if Ekind (E) = E_Class_Wide_Subtype
2507 and then Present (Equivalent_Type (E))
2509 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2512 -- For a record (sub)type, freeze all the component types (RM
2513 -- 13.14(15). We test for E_Record_(sub)Type here, rather than
2514 -- using Is_Record_Type, because we don't want to attempt the
2515 -- freeze for the case of a private type with record extension
2516 -- (we will do that later when the full type is frozen).
2518 elsif Ekind (E) = E_Record_Type
2519 or else Ekind (E) = E_Record_Subtype
2521 Freeze_Record_Type (E);
2523 -- For a concurrent type, freeze corresponding record type. This
2524 -- does not correpond to any specific rule in the RM, but the
2525 -- record type is essentially part of the concurrent type.
2526 -- Freeze as well all local entities. This includes record types
2527 -- created for entry parameter blocks, and whatever local entities
2528 -- may appear in the private part.
2530 elsif Is_Concurrent_Type (E) then
2531 if Present (Corresponding_Record_Type (E)) then
2533 (Corresponding_Record_Type (E), Loc, Result);
2536 Comp := First_Entity (E);
2538 while Present (Comp) loop
2539 if Is_Type (Comp) then
2540 Freeze_And_Append (Comp, Loc, Result);
2542 elsif (Ekind (Comp)) /= E_Function then
2543 Freeze_And_Append (Etype (Comp), Loc, Result);
2549 -- Private types are required to point to the same freeze node
2550 -- as their corresponding full views. The freeze node itself
2551 -- has to point to the partial view of the entity (because
2552 -- from the partial view, we can retrieve the full view, but
2553 -- not the reverse). However, in order to freeze correctly,
2554 -- we need to freeze the full view. If we are freezing at the
2555 -- end of a scope (or within the scope of the private type),
2556 -- the partial and full views will have been swapped, the
2557 -- full view appears first in the entity chain and the swapping
2558 -- mechanism ensures that the pointers are properly set (on
2561 -- If we encounter the partial view before the full view
2562 -- (e.g. when freezing from another scope), we freeze the
2563 -- full view, and then set the pointers appropriately since
2564 -- we cannot rely on swapping to fix things up (subtypes in an
2565 -- outer scope might not get swapped).
2567 elsif Is_Incomplete_Or_Private_Type (E)
2568 and then not Is_Generic_Type (E)
2570 -- Case of full view present
2572 if Present (Full_View (E)) then
2574 -- If full view has already been frozen, then no
2575 -- further processing is required
2577 if Is_Frozen (Full_View (E)) then
2579 Set_Has_Delayed_Freeze (E, False);
2580 Set_Freeze_Node (E, Empty);
2581 Check_Debug_Info_Needed (E);
2583 -- Otherwise freeze full view and patch the pointers
2584 -- so that the freeze node will elaborate both views
2589 Full : constant Entity_Id := Full_View (E);
2592 if Is_Private_Type (Full)
2593 and then Present (Underlying_Full_View (Full))
2596 (Underlying_Full_View (Full), Loc, Result);
2599 Freeze_And_Append (Full, Loc, Result);
2601 if Has_Delayed_Freeze (E) then
2602 F_Node := Freeze_Node (Full);
2604 if Present (F_Node) then
2605 Set_Freeze_Node (E, F_Node);
2606 Set_Entity (F_Node, E);
2609 -- {Incomplete,Private}_Subtypes
2610 -- with Full_Views constrained by discriminants
2612 Set_Has_Delayed_Freeze (E, False);
2613 Set_Freeze_Node (E, Empty);
2618 Check_Debug_Info_Needed (E);
2621 -- AI-117 requires that the convention of a partial view
2622 -- be the same as the convention of the full view. Note
2623 -- that this is a recognized breach of privacy, but it's
2624 -- essential for logical consistency of representation,
2625 -- and the lack of a rule in RM95 was an oversight.
2627 Set_Convention (E, Convention (Full_View (E)));
2629 Set_Size_Known_At_Compile_Time (E,
2630 Size_Known_At_Compile_Time (Full_View (E)));
2632 -- Size information is copied from the full view to the
2633 -- incomplete or private view for consistency
2635 -- We skip this is the full view is not a type. This is
2636 -- very strange of course, and can only happen as a result
2637 -- of certain illegalities, such as a premature attempt to
2638 -- derive from an incomplete type.
2640 if Is_Type (Full_View (E)) then
2641 Set_Size_Info (E, Full_View (E));
2642 Set_RM_Size (E, RM_Size (Full_View (E)));
2647 -- Case of no full view present. If entity is derived or subtype,
2648 -- it is safe to freeze, correctness depends on the frozen status
2649 -- of parent. Otherwise it is either premature usage, or a Taft
2650 -- amendment type, so diagnosis is at the point of use and the
2651 -- type might be frozen later.
2653 elsif E /= Base_Type (E)
2654 or else Is_Derived_Type (E)
2659 Set_Is_Frozen (E, False);
2663 -- For access subprogram, freeze types of all formals, the return
2664 -- type was already frozen, since it is the Etype of the function.
2666 elsif Ekind (E) = E_Subprogram_Type then
2667 Formal := First_Formal (E);
2668 while Present (Formal) loop
2669 Freeze_And_Append (Etype (Formal), Loc, Result);
2670 Next_Formal (Formal);
2673 -- If the return type requires a transient scope, and we are on
2674 -- a target allowing functions to return with a depressed stack
2675 -- pointer, then we mark the function as requiring this treatment.
2677 if Functions_Return_By_DSP_On_Target
2678 and then Requires_Transient_Scope (Etype (E))
2680 Set_Function_Returns_With_DSP (E);
2683 Freeze_Subprogram (E);
2685 -- For access to a protected subprogram, freeze the equivalent
2686 -- type (however this is not set if we are not generating code)
2687 -- or if this is an anonymous type used just for resolution).
2689 elsif Ekind (E) = E_Access_Protected_Subprogram_Type
2690 and then Operating_Mode = Generate_Code
2691 and then Present (Equivalent_Type (E))
2693 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2696 -- Generic types are never seen by the back-end, and are also not
2697 -- processed by the expander (since the expander is turned off for
2698 -- generic processing), so we never need freeze nodes for them.
2700 if Is_Generic_Type (E) then
2704 -- Some special processing for non-generic types to complete
2705 -- representation details not known till the freeze point.
2707 if Is_Fixed_Point_Type (E) then
2708 Freeze_Fixed_Point_Type (E);
2710 -- Some error checks required for ordinary fixed-point type.
2711 -- Defer these till the freeze-point since we need the small
2712 -- and range values. We only do these checks for base types
2714 if Is_Ordinary_Fixed_Point_Type (E)
2715 and then E = Base_Type (E)
2717 if Small_Value (E) < Ureal_2_M_80 then
2718 Error_Msg_Name_1 := Name_Small;
2720 ("`&''%` is too small, minimum is 2.0'*'*(-80)", E);
2722 elsif Small_Value (E) > Ureal_2_80 then
2723 Error_Msg_Name_1 := Name_Small;
2725 ("`&''%` is too large, maximum is 2.0'*'*80", E);
2728 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
2729 Error_Msg_Name_1 := Name_First;
2731 ("`&''%` is too small, minimum is -10.0'*'*36", E);
2734 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
2735 Error_Msg_Name_1 := Name_Last;
2737 ("`&''%` is too large, maximum is 10.0'*'*36", E);
2741 elsif Is_Enumeration_Type (E) then
2742 Freeze_Enumeration_Type (E);
2744 elsif Is_Integer_Type (E) then
2745 Adjust_Esize_For_Alignment (E);
2747 elsif Is_Access_Type (E)
2748 and then No (Associated_Storage_Pool (E))
2750 Check_Restriction (No_Standard_Storage_Pools, E);
2753 -- If the current entity is an array or record subtype and has
2754 -- discriminants used to constrain it, it must not freeze, because
2755 -- Freeze_Entity nodes force Gigi to process the frozen type.
2757 if Is_Composite_Type (E) then
2759 if Is_Array_Type (E) then
2761 Index : Node_Id := First_Index (E);
2766 while Present (Index) loop
2767 if Etype (Index) /= Any_Type then
2768 Get_Index_Bounds (Index, Expr1, Expr2);
2770 for J in 1 .. 2 loop
2771 if Nkind (Expr1) = N_Identifier
2772 and then Ekind (Entity (Expr1)) = E_Discriminant
2774 Set_Has_Delayed_Freeze (E, False);
2775 Set_Freeze_Node (E, Empty);
2776 Check_Debug_Info_Needed (E);
2788 elsif Has_Discriminants (E)
2789 and Is_Constrained (E)
2792 Constraint : Elmt_Id;
2796 Constraint := First_Elmt (Discriminant_Constraint (E));
2797 while Present (Constraint) loop
2798 Expr := Node (Constraint);
2799 if Nkind (Expr) = N_Identifier
2800 and then Ekind (Entity (Expr)) = E_Discriminant
2802 Set_Has_Delayed_Freeze (E, False);
2803 Set_Freeze_Node (E, Empty);
2804 Check_Debug_Info_Needed (E);
2808 Next_Elmt (Constraint);
2813 -- AI-117 requires that all new primitives of a tagged type
2814 -- must inherit the convention of the full view of the type.
2815 -- Inherited and overriding operations are defined to inherit
2816 -- the convention of their parent or overridden subprogram
2817 -- (also specified in AI-117), and that will have occurred
2818 -- earlier (in Derive_Subprogram and New_Overloaded_Entity).
2819 -- Here we set the convention of primitives that are still
2820 -- convention Ada, which will ensure that any new primitives
2821 -- inherit the type's convention. Class-wide types can have
2822 -- a foreign convention inherited from their specific type,
2823 -- but are excluded from this since they don't have any
2824 -- associated primitives.
2826 if Is_Tagged_Type (E)
2827 and then not Is_Class_Wide_Type (E)
2828 and then Convention (E) /= Convention_Ada
2831 Prim_List : constant Elist_Id := Primitive_Operations (E);
2834 Prim := First_Elmt (Prim_List);
2835 while Present (Prim) loop
2836 if Convention (Node (Prim)) = Convention_Ada then
2837 Set_Convention (Node (Prim), Convention (E));
2846 -- Generate primitive operation references for a tagged type
2848 if Is_Tagged_Type (E)
2849 and then not Is_Class_Wide_Type (E)
2852 Prim_List : constant Elist_Id := Primitive_Operations (E);
2857 Prim := First_Elmt (Prim_List);
2858 while Present (Prim) loop
2861 -- If the operation is derived, get the original for
2862 -- cross-reference purposes (it is the original for
2863 -- which we want the xref, and for which the comes
2864 -- from source test needs to be performed).
2866 while Present (Alias (Ent)) loop
2870 Generate_Reference (E, Ent, 'p', Set_Ref => False);
2874 -- If we get an exception, then something peculiar has happened
2875 -- probably as a result of a previous error. Since this is only
2876 -- for non-critical cross-references, ignore the error.
2879 when others => null;
2883 -- Now that all types from which E may depend are frozen, see
2884 -- if the size is known at compile time, if it must be unsigned,
2885 -- or if strict alignent is required
2887 Check_Compile_Time_Size (E);
2888 Check_Unsigned_Type (E);
2890 if Base_Type (E) = E then
2891 Check_Strict_Alignment (E);
2894 -- Do not allow a size clause for a type which does not have a size
2895 -- that is known at compile time
2897 if Has_Size_Clause (E)
2898 and then not Size_Known_At_Compile_Time (E)
2900 -- Supress this message if errors posted on E, even if we are
2901 -- in all errors mode, since this is often a junk message
2903 if not Error_Posted (E) then
2905 ("size clause not allowed for variable length type",
2910 -- Remaining process is to set/verify the representation information,
2911 -- in particular the size and alignment values. This processing is
2912 -- not required for generic types, since generic types do not play
2913 -- any part in code generation, and so the size and alignment values
2914 -- for suhc types are irrelevant.
2916 if Is_Generic_Type (E) then
2919 -- Otherwise we call the layout procedure
2925 -- End of freeze processing for type entities
2928 -- Here is where we logically freeze the current entity. If it has a
2929 -- freeze node, then this is the point at which the freeze node is
2930 -- linked into the result list.
2932 if Has_Delayed_Freeze (E) then
2934 -- If a freeze node is already allocated, use it, otherwise allocate
2935 -- a new one. The preallocation happens in the case of anonymous base
2936 -- types, where we preallocate so that we can set First_Subtype_Link.
2937 -- Note that we reset the Sloc to the current freeze location.
2939 if Present (Freeze_Node (E)) then
2940 F_Node := Freeze_Node (E);
2941 Set_Sloc (F_Node, Loc);
2944 F_Node := New_Node (N_Freeze_Entity, Loc);
2945 Set_Freeze_Node (E, F_Node);
2946 Set_Access_Types_To_Process (F_Node, No_Elist);
2947 Set_TSS_Elist (F_Node, No_Elist);
2948 Set_Actions (F_Node, No_List);
2951 Set_Entity (F_Node, E);
2953 if Result = No_List then
2954 Result := New_List (F_Node);
2956 Append (F_Node, Result);
2960 -- When a type is frozen, the first subtype of the type is frozen as
2961 -- well (RM 13.14(15)). This has to be done after freezing the type,
2962 -- since obviously the first subtype depends on its own base type.
2965 Freeze_And_Append (First_Subtype (E), Loc, Result);
2967 -- If we just froze a tagged non-class wide record, then freeze the
2968 -- corresponding class-wide type. This must be done after the tagged
2969 -- type itself is frozen, because the class-wide type refers to the
2970 -- tagged type which generates the class.
2972 if Is_Tagged_Type (E)
2973 and then not Is_Class_Wide_Type (E)
2974 and then Present (Class_Wide_Type (E))
2976 Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
2980 Check_Debug_Info_Needed (E);
2982 -- Special handling for subprograms
2984 if Is_Subprogram (E) then
2986 -- If subprogram has address clause then reset Is_Public flag, since
2987 -- we do not want the backend to generate external references.
2989 if Present (Address_Clause (E))
2990 and then not Is_Library_Level_Entity (E)
2992 Set_Is_Public (E, False);
2994 -- If no address clause and not intrinsic, then for imported
2995 -- subprogram in main unit, generate descriptor if we are in
2996 -- Propagate_Exceptions mode.
2998 elsif Propagate_Exceptions
2999 and then Is_Imported (E)
3000 and then not Is_Intrinsic_Subprogram (E)
3001 and then Convention (E) /= Convention_Stubbed
3003 if Result = No_List then
3004 Result := Empty_List;
3007 Generate_Subprogram_Descriptor_For_Imported_Subprogram
3015 -----------------------------
3016 -- Freeze_Enumeration_Type --
3017 -----------------------------
3019 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
3021 if Has_Foreign_Convention (Typ)
3022 and then not Has_Size_Clause (Typ)
3023 and then Esize (Typ) < Standard_Integer_Size
3025 Init_Esize (Typ, Standard_Integer_Size);
3027 Adjust_Esize_For_Alignment (Typ);
3029 end Freeze_Enumeration_Type;
3031 -----------------------
3032 -- Freeze_Expression --
3033 -----------------------
3035 procedure Freeze_Expression (N : Node_Id) is
3036 In_Def_Exp : constant Boolean := In_Default_Expression;
3039 Desig_Typ : Entity_Id;
3043 Freeze_Outside : Boolean := False;
3044 -- This flag is set true if the entity must be frozen outside the
3045 -- current subprogram. This happens in the case of expander generated
3046 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
3047 -- not freeze all entities like other bodies, but which nevertheless
3048 -- may reference entities that have to be frozen before the body and
3049 -- obviously cannot be frozen inside the body.
3051 function In_Exp_Body (N : Node_Id) return Boolean;
3052 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
3053 -- it is the handled statement sequence of an expander generated
3054 -- subprogram (init proc, or stream subprogram). If so, it returns
3055 -- True, otherwise False.
3061 function In_Exp_Body (N : Node_Id) return Boolean is
3065 if Nkind (N) = N_Subprogram_Body then
3071 if Nkind (P) /= N_Subprogram_Body then
3075 P := Defining_Unit_Name (Specification (P));
3077 if Nkind (P) = N_Defining_Identifier
3078 and then (Is_Init_Proc (P) or else
3079 Is_TSS (P, TSS_Stream_Input) or else
3080 Is_TSS (P, TSS_Stream_Output) or else
3081 Is_TSS (P, TSS_Stream_Read) or else
3082 Is_TSS (P, TSS_Stream_Write))
3091 -- Start of processing for Freeze_Expression
3094 -- Immediate return if freezing is inhibited. This flag is set by
3095 -- the analyzer to stop freezing on generated expressions that would
3096 -- cause freezing if they were in the source program, but which are
3097 -- not supposed to freeze, since they are created.
3099 if Must_Not_Freeze (N) then
3103 -- If expression is non-static, then it does not freeze in a default
3104 -- expression, see section "Handling of Default Expressions" in the
3105 -- spec of package Sem for further details. Note that we have to
3106 -- make sure that we actually have a real expression (if we have
3107 -- a subtype indication, we can't test Is_Static_Expression!)
3110 and then Nkind (N) in N_Subexpr
3111 and then not Is_Static_Expression (N)
3116 -- Freeze type of expression if not frozen already
3120 if Nkind (N) in N_Has_Etype then
3121 if not Is_Frozen (Etype (N)) then
3124 -- Base type may be an derived numeric type that is frozen at
3125 -- the point of declaration, but first_subtype is still unfrozen.
3127 elsif not Is_Frozen (First_Subtype (Etype (N))) then
3128 Typ := First_Subtype (Etype (N));
3132 -- For entity name, freeze entity if not frozen already. A special
3133 -- exception occurs for an identifier that did not come from source.
3134 -- We don't let such identifiers freeze a non-internal entity, i.e.
3135 -- an entity that did come from source, since such an identifier was
3136 -- generated by the expander, and cannot have any semantic effect on
3137 -- the freezing semantics. For example, this stops the parameter of
3138 -- an initialization procedure from freezing the variable.
3140 if Is_Entity_Name (N)
3141 and then not Is_Frozen (Entity (N))
3142 and then (Nkind (N) /= N_Identifier
3143 or else Comes_From_Source (N)
3144 or else not Comes_From_Source (Entity (N)))
3151 -- For an allocator freeze designated type if not frozen already.
3153 -- For an aggregate whose component type is an access type, freeze
3154 -- the designated type now, so that its freeze does not appear within
3155 -- the loop that might be created in the expansion of the aggregate.
3156 -- If the designated type is a private type without full view, the
3157 -- expression cannot contain an allocator, so the type is not frozen.
3163 Desig_Typ := Designated_Type (Etype (N));
3166 if Is_Array_Type (Etype (N))
3167 and then Is_Access_Type (Component_Type (Etype (N)))
3169 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
3172 when N_Selected_Component |
3173 N_Indexed_Component |
3176 if Is_Access_Type (Etype (Prefix (N))) then
3177 Desig_Typ := Designated_Type (Etype (Prefix (N)));
3184 if Desig_Typ /= Empty
3185 and then (Is_Frozen (Desig_Typ)
3186 or else (not Is_Fully_Defined (Desig_Typ)))
3191 -- All done if nothing needs freezing
3195 and then No (Desig_Typ)
3200 -- Loop for looking at the right place to insert the freeze nodes
3201 -- exiting from the loop when it is appropriate to insert the freeze
3202 -- node before the current node P.
3204 -- Also checks some special exceptions to the freezing rules. These
3205 -- cases result in a direct return, bypassing the freeze action.
3209 Parent_P := Parent (P);
3211 -- If we don't have a parent, then we are not in a well-formed
3212 -- tree. This is an unusual case, but there are some legitimate
3213 -- situations in which this occurs, notably when the expressions
3214 -- in the range of a type declaration are resolved. We simply
3215 -- ignore the freeze request in this case. Is this right ???
3217 if No (Parent_P) then
3221 -- See if we have got to an appropriate point in the tree
3223 case Nkind (Parent_P) is
3225 -- A special test for the exception of (RM 13.14(8)) for the
3226 -- case of per-object expressions (RM 3.8(18)) occurring in a
3227 -- component definition or a discrete subtype definition. Note
3228 -- that we test for a component declaration which includes both
3229 -- cases we are interested in, and furthermore the tree does not
3230 -- have explicit nodes for either of these two constructs.
3232 when N_Component_Declaration =>
3234 -- The case we want to test for here is an identifier that is
3235 -- a per-object expression, this is either a discriminant that
3236 -- appears in a context other than the component declaration
3237 -- or it is a reference to the type of the enclosing construct.
3239 -- For either of these cases, we skip the freezing
3241 if not In_Default_Expression
3242 and then Nkind (N) = N_Identifier
3243 and then (Present (Entity (N)))
3245 -- We recognize the discriminant case by just looking for
3246 -- a reference to a discriminant. It can only be one for
3247 -- the enclosing construct. Skip freezing in this case.
3249 if Ekind (Entity (N)) = E_Discriminant then
3252 -- For the case of a reference to the enclosing record,
3253 -- (or task or protected type), we look for a type that
3254 -- matches the current scope.
3256 elsif Entity (N) = Current_Scope then
3261 -- If we have an enumeration literal that appears as the
3262 -- choice in the aggregate of an enumeration representation
3263 -- clause, then freezing does not occur (RM 13.14(10)).
3265 when N_Enumeration_Representation_Clause =>
3267 -- The case we are looking for is an enumeration literal
3269 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
3270 and then Is_Enumeration_Type (Etype (N))
3272 -- If enumeration literal appears directly as the choice,
3273 -- do not freeze (this is the normal non-overloade case)
3275 if Nkind (Parent (N)) = N_Component_Association
3276 and then First (Choices (Parent (N))) = N
3280 -- If enumeration literal appears as the name of a
3281 -- function which is the choice, then also do not freeze.
3282 -- This happens in the overloaded literal case, where the
3283 -- enumeration literal is temporarily changed to a function
3284 -- call for overloading analysis purposes.
3286 elsif Nkind (Parent (N)) = N_Function_Call
3288 Nkind (Parent (Parent (N))) = N_Component_Association
3290 First (Choices (Parent (Parent (N)))) = Parent (N)
3296 -- Normally if the parent is a handled sequence of statements,
3297 -- then the current node must be a statement, and that is an
3298 -- appropriate place to insert a freeze node.
3300 when N_Handled_Sequence_Of_Statements =>
3302 -- An exception occurs when the sequence of statements is
3303 -- for an expander generated body that did not do the usual
3304 -- freeze all operation. In this case we usually want to
3305 -- freeze outside this body, not inside it, and we skip
3306 -- past the subprogram body that we are inside.
3308 if In_Exp_Body (Parent_P) then
3310 -- However, we *do* want to freeze at this point if we have
3311 -- an entity to freeze, and that entity is declared *inside*
3312 -- the body of the expander generated procedure. This case
3313 -- is recognized by the scope of the type, which is either
3314 -- the spec for some enclosing body, or (in the case of
3315 -- init_procs, for which there are no separate specs) the
3319 Subp : constant Node_Id := Parent (Parent_P);
3323 if Nkind (Subp) = N_Subprogram_Body then
3324 Cspc := Corresponding_Spec (Subp);
3326 if (Present (Typ) and then Scope (Typ) = Cspc)
3328 (Present (Nam) and then Scope (Nam) = Cspc)
3333 and then Scope (Typ) = Current_Scope
3334 and then Current_Scope = Defining_Entity (Subp)
3341 -- If not that exception to the exception, then this is
3342 -- where we delay the freeze till outside the body.
3344 Parent_P := Parent (Parent_P);
3345 Freeze_Outside := True;
3347 -- Here if normal case where we are in handled statement
3348 -- sequence and want to do the insertion right there.
3354 -- If parent is a body or a spec or a block, then the current
3355 -- node is a statement or declaration and we can insert the
3356 -- freeze node before it.
3358 when N_Package_Specification |
3364 N_Block_Statement => exit;
3366 -- The expander is allowed to define types in any statements list,
3367 -- so any of the following parent nodes also mark a freezing point
3368 -- if the actual node is in a list of statements or declarations.
3370 when N_Exception_Handler |
3373 N_Case_Statement_Alternative |
3374 N_Compilation_Unit_Aux |
3375 N_Selective_Accept |
3376 N_Accept_Alternative |
3377 N_Delay_Alternative |
3378 N_Conditional_Entry_Call |
3379 N_Entry_Call_Alternative |
3380 N_Triggering_Alternative |
3384 exit when Is_List_Member (P);
3386 -- Note: The N_Loop_Statement is a special case. A type that
3387 -- appears in the source can never be frozen in a loop (this
3388 -- occurs only because of a loop expanded by the expander),
3389 -- so we keep on going. Otherwise we terminate the search.
3390 -- Same is true of any entity which comes from source. (if they
3391 -- have a predefined type, that type does not appear to come
3392 -- from source, but the entity should not be frozen here).
3394 when N_Loop_Statement =>
3395 exit when not Comes_From_Source (Etype (N))
3396 and then (No (Nam) or else not Comes_From_Source (Nam));
3398 -- For all other cases, keep looking at parents
3404 -- We fall through the case if we did not yet find the proper
3405 -- place in the free for inserting the freeze node, so climb!
3410 -- If the expression appears in a record or an initialization
3411 -- procedure, the freeze nodes are collected and attached to
3412 -- the current scope, to be inserted and analyzed on exit from
3413 -- the scope, to insure that generated entities appear in the
3414 -- correct scope. If the expression is a default for a discriminant
3415 -- specification, the scope is still void. The expression can also
3416 -- appear in the discriminant part of a private or concurrent type.
3418 -- The other case requiring this special handling is if we are in
3419 -- a default expression, since in that case we are about to freeze
3420 -- a static type, and the freeze scope needs to be the outer scope,
3421 -- not the scope of the subprogram with the default parameter.
3423 -- For default expressions in generic units, the Move_Freeze_Nodes
3424 -- mechanism (see sem_ch12.adb) takes care of placing them at the
3425 -- proper place, after the generic unit.
3427 if (In_Def_Exp and not Inside_A_Generic)
3428 or else Freeze_Outside
3429 or else (Is_Type (Current_Scope)
3430 and then (not Is_Concurrent_Type (Current_Scope)
3431 or else not Has_Completion (Current_Scope)))
3432 or else Ekind (Current_Scope) = E_Void
3435 Loc : constant Source_Ptr := Sloc (Current_Scope);
3436 Freeze_Nodes : List_Id := No_List;
3439 if Present (Desig_Typ) then
3440 Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
3443 if Present (Typ) then
3444 Freeze_And_Append (Typ, Loc, Freeze_Nodes);
3447 if Present (Nam) then
3448 Freeze_And_Append (Nam, Loc, Freeze_Nodes);
3451 if Is_Non_Empty_List (Freeze_Nodes) then
3452 if No (Scope_Stack.Table
3453 (Scope_Stack.Last).Pending_Freeze_Actions)
3456 (Scope_Stack.Last).Pending_Freeze_Actions :=
3459 Append_List (Freeze_Nodes, Scope_Stack.Table
3460 (Scope_Stack.Last).Pending_Freeze_Actions);
3468 -- Now we have the right place to do the freezing. First, a special
3469 -- adjustment, if we are in default expression analysis mode, these
3470 -- freeze actions must not be thrown away (normally all inserted
3471 -- actions are thrown away in this mode. However, the freeze actions
3472 -- are from static expressions and one of the important reasons we
3473 -- are doing this special analysis is to get these freeze actions.
3474 -- Therefore we turn off the In_Default_Expression mode to propagate
3475 -- these freeze actions. This also means they get properly analyzed
3478 In_Default_Expression := False;
3480 -- Freeze the designated type of an allocator (RM 13.14(13))
3482 if Present (Desig_Typ) then
3483 Freeze_Before (P, Desig_Typ);
3486 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
3487 -- the enumeration representation clause exception in the loop above.
3489 if Present (Typ) then
3490 Freeze_Before (P, Typ);
3493 -- Freeze name if one is present (RM 13.14(11))
3495 if Present (Nam) then
3496 Freeze_Before (P, Nam);
3499 In_Default_Expression := In_Def_Exp;
3500 end Freeze_Expression;
3502 -----------------------------
3503 -- Freeze_Fixed_Point_Type --
3504 -----------------------------
3506 -- Certain fixed-point types and subtypes, including implicit base
3507 -- types and declared first subtypes, have not yet set up a range.
3508 -- This is because the range cannot be set until the Small and Size
3509 -- values are known, and these are not known till the type is frozen.
3511 -- To signal this case, Scalar_Range contains an unanalyzed syntactic
3512 -- range whose bounds are unanalyzed real literals. This routine will
3513 -- recognize this case, and transform this range node into a properly
3514 -- typed range with properly analyzed and resolved values.
3516 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
3517 Rng : constant Node_Id := Scalar_Range (Typ);
3518 Lo : constant Node_Id := Low_Bound (Rng);
3519 Hi : constant Node_Id := High_Bound (Rng);
3520 Btyp : constant Entity_Id := Base_Type (Typ);
3521 Brng : constant Node_Id := Scalar_Range (Btyp);
3522 BLo : constant Node_Id := Low_Bound (Brng);
3523 BHi : constant Node_Id := High_Bound (Brng);
3524 Small : constant Ureal := Small_Value (Typ);
3531 function Fsize (Lov, Hiv : Ureal) return Nat;
3532 -- Returns size of type with given bounds. Also leaves these
3533 -- bounds set as the current bounds of the Typ.
3535 function Fsize (Lov, Hiv : Ureal) return Nat is
3537 Set_Realval (Lo, Lov);
3538 Set_Realval (Hi, Hiv);
3539 return Minimum_Size (Typ);
3542 -- Start of processing for Freeze_Fixed_Point_Type;
3545 -- If Esize of a subtype has not previously been set, set it now
3547 if Unknown_Esize (Typ) then
3548 Atype := Ancestor_Subtype (Typ);
3550 if Present (Atype) then
3551 Set_Esize (Typ, Esize (Atype));
3553 Set_Esize (Typ, Esize (Base_Type (Typ)));
3557 -- Immediate return if the range is already analyzed. This means
3558 -- that the range is already set, and does not need to be computed
3561 if Analyzed (Rng) then
3565 -- Immediate return if either of the bounds raises Constraint_Error
3567 if Raises_Constraint_Error (Lo)
3568 or else Raises_Constraint_Error (Hi)
3573 Loval := Realval (Lo);
3574 Hival := Realval (Hi);
3576 -- Ordinary fixed-point case
3578 if Is_Ordinary_Fixed_Point_Type (Typ) then
3580 -- For the ordinary fixed-point case, we are allowed to fudge the
3581 -- end-points up or down by small. Generally we prefer to fudge
3582 -- up, i.e. widen the bounds for non-model numbers so that the
3583 -- end points are included. However there are cases in which this
3584 -- cannot be done, and indeed cases in which we may need to narrow
3585 -- the bounds. The following circuit makes the decision.
3587 -- Note: our terminology here is that Incl_EP means that the
3588 -- bounds are widened by Small if necessary to include the end
3589 -- points, and Excl_EP means that the bounds are narrowed by
3590 -- Small to exclude the end-points if this reduces the size.
3592 -- Note that in the Incl case, all we care about is including the
3593 -- end-points. In the Excl case, we want to narrow the bounds as
3594 -- much as permitted by the RM, to give the smallest possible size.
3597 Loval_Incl_EP : Ureal;
3598 Hival_Incl_EP : Ureal;
3600 Loval_Excl_EP : Ureal;
3601 Hival_Excl_EP : Ureal;
3607 First_Subt : Entity_Id;
3612 -- First step. Base types are required to be symmetrical. Right
3613 -- now, the base type range is a copy of the first subtype range.
3614 -- This will be corrected before we are done, but right away we
3615 -- need to deal with the case where both bounds are non-negative.
3616 -- In this case, we set the low bound to the negative of the high
3617 -- bound, to make sure that the size is computed to include the
3618 -- required sign. Note that we do not need to worry about the
3619 -- case of both bounds negative, because the sign will be dealt
3620 -- with anyway. Furthermore we can't just go making such a bound
3621 -- symmetrical, since in a twos-complement system, there is an
3622 -- extra negative value which could not be accomodated on the
3626 and then not UR_Is_Negative (Loval)
3627 and then Hival > Loval
3630 Set_Realval (Lo, Loval);
3633 -- Compute the fudged bounds. If the number is a model number,
3634 -- then we do nothing to include it, but we are allowed to
3635 -- backoff to the next adjacent model number when we exclude
3636 -- it. If it is not a model number then we straddle the two
3637 -- values with the model numbers on either side.
3639 Model_Num := UR_Trunc (Loval / Small) * Small;
3641 if Loval = Model_Num then
3642 Loval_Incl_EP := Model_Num;
3644 Loval_Incl_EP := Model_Num - Small;
3647 -- The low value excluding the end point is Small greater, but
3648 -- we do not do this exclusion if the low value is positive,
3649 -- since it can't help the size and could actually hurt by
3650 -- crossing the high bound.
3652 if UR_Is_Negative (Loval_Incl_EP) then
3653 Loval_Excl_EP := Loval_Incl_EP + Small;
3655 Loval_Excl_EP := Loval_Incl_EP;
3658 -- Similar processing for upper bound and high value
3660 Model_Num := UR_Trunc (Hival / Small) * Small;
3662 if Hival = Model_Num then
3663 Hival_Incl_EP := Model_Num;
3665 Hival_Incl_EP := Model_Num + Small;
3668 if UR_Is_Positive (Hival_Incl_EP) then
3669 Hival_Excl_EP := Hival_Incl_EP - Small;
3671 Hival_Excl_EP := Hival_Incl_EP;
3674 -- One further adjustment is needed. In the case of subtypes,
3675 -- we cannot go outside the range of the base type, or we get
3676 -- peculiarities, and the base type range is already set. This
3677 -- only applies to the Incl values, since clearly the Excl
3678 -- values are already as restricted as they are allowed to be.
3681 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
3682 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
3685 -- Get size including and excluding end points
3687 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
3688 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
3690 -- No need to exclude end-points if it does not reduce size
3692 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
3693 Loval_Excl_EP := Loval_Incl_EP;
3696 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
3697 Hival_Excl_EP := Hival_Incl_EP;
3700 -- Now we set the actual size to be used. We want to use the
3701 -- bounds fudged up to include the end-points but only if this
3702 -- can be done without violating a specifically given size
3703 -- size clause or causing an unacceptable increase in size.
3705 -- Case of size clause given
3707 if Has_Size_Clause (Typ) then
3709 -- Use the inclusive size only if it is consistent with
3710 -- the explicitly specified size.
3712 if Size_Incl_EP <= RM_Size (Typ) then
3713 Actual_Lo := Loval_Incl_EP;
3714 Actual_Hi := Hival_Incl_EP;
3715 Actual_Size := Size_Incl_EP;
3717 -- If the inclusive size is too large, we try excluding
3718 -- the end-points (will be caught later if does not work).
3721 Actual_Lo := Loval_Excl_EP;
3722 Actual_Hi := Hival_Excl_EP;
3723 Actual_Size := Size_Excl_EP;
3726 -- Case of size clause not given
3729 -- If we have a base type whose corresponding first subtype
3730 -- has an explicit size that is large enough to include our
3731 -- end-points, then do so. There is no point in working hard
3732 -- to get a base type whose size is smaller than the specified
3733 -- size of the first subtype.
3735 First_Subt := First_Subtype (Typ);
3737 if Has_Size_Clause (First_Subt)
3738 and then Size_Incl_EP <= Esize (First_Subt)
3740 Actual_Size := Size_Incl_EP;
3741 Actual_Lo := Loval_Incl_EP;
3742 Actual_Hi := Hival_Incl_EP;
3744 -- If excluding the end-points makes the size smaller and
3745 -- results in a size of 8,16,32,64, then we take the smaller
3746 -- size. For the 64 case, this is compulsory. For the other
3747 -- cases, it seems reasonable. We like to include end points
3748 -- if we can, but not at the expense of moving to the next
3749 -- natural boundary of size.
3751 elsif Size_Incl_EP /= Size_Excl_EP
3753 (Size_Excl_EP = 8 or else
3754 Size_Excl_EP = 16 or else
3755 Size_Excl_EP = 32 or else
3758 Actual_Size := Size_Excl_EP;
3759 Actual_Lo := Loval_Excl_EP;
3760 Actual_Hi := Hival_Excl_EP;
3762 -- Otherwise we can definitely include the end points
3765 Actual_Size := Size_Incl_EP;
3766 Actual_Lo := Loval_Incl_EP;
3767 Actual_Hi := Hival_Incl_EP;
3770 -- One pathological case: normally we never fudge a low
3771 -- bound down, since it would seem to increase the size
3772 -- (if it has any effect), but for ranges containing a
3773 -- single value, or no values, the high bound can be
3774 -- small too large. Consider:
3776 -- type t is delta 2.0**(-14)
3777 -- range 131072.0 .. 0;
3779 -- That lower bound is *just* outside the range of 32
3780 -- bits, and does need fudging down in this case. Note
3781 -- that the bounds will always have crossed here, since
3782 -- the high bound will be fudged down if necessary, as
3785 -- type t is delta 2.0**(-14)
3786 -- range 131072.0 .. 131072.0;
3788 -- So we can detect the situation by looking for crossed
3789 -- bounds, and if the bounds are crossed, and the low
3790 -- bound is greater than zero, we will always back it
3791 -- off by small, since this is completely harmless.
3793 if Actual_Lo > Actual_Hi then
3794 if UR_Is_Positive (Actual_Lo) then
3795 Actual_Lo := Loval_Incl_EP - Small;
3796 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3798 -- And of course, we need to do exactly the same parallel
3799 -- fudge for flat ranges in the negative region.
3801 elsif UR_Is_Negative (Actual_Hi) then
3802 Actual_Hi := Hival_Incl_EP + Small;
3803 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3808 Set_Realval (Lo, Actual_Lo);
3809 Set_Realval (Hi, Actual_Hi);
3812 -- For the decimal case, none of this fudging is required, since there
3813 -- are no end-point problems in the decimal case (the end-points are
3814 -- always included).
3817 Actual_Size := Fsize (Loval, Hival);
3820 -- At this stage, the actual size has been calculated and the proper
3821 -- required bounds are stored in the low and high bounds.
3823 if Actual_Size > 64 then
3824 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
3826 ("size required (^) for type& too large, maximum is 64", Typ);
3830 -- Check size against explicit given size
3832 if Has_Size_Clause (Typ) then
3833 if Actual_Size > RM_Size (Typ) then
3834 Error_Msg_Uint_1 := RM_Size (Typ);
3835 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
3837 ("size given (^) for type& too small, minimum is ^",
3838 Size_Clause (Typ), Typ);
3841 Actual_Size := UI_To_Int (Esize (Typ));
3844 -- Increase size to next natural boundary if no size clause given
3847 if Actual_Size <= 8 then
3849 elsif Actual_Size <= 16 then
3851 elsif Actual_Size <= 32 then
3857 Init_Esize (Typ, Actual_Size);
3858 Adjust_Esize_For_Alignment (Typ);
3861 -- If we have a base type, then expand the bounds so that they
3862 -- extend to the full width of the allocated size in bits, to
3863 -- avoid junk range checks on intermediate computations.
3865 if Base_Type (Typ) = Typ then
3866 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
3867 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
3870 -- Final step is to reanalyze the bounds using the proper type
3871 -- and set the Corresponding_Integer_Value fields of the literals.
3873 Set_Etype (Lo, Empty);
3874 Set_Analyzed (Lo, False);
3877 -- Resolve with universal fixed if the base type, and the base
3878 -- type if it is a subtype. Note we can't resolve the base type
3879 -- with itself, that would be a reference before definition.
3882 Resolve (Lo, Universal_Fixed);
3887 -- Set corresponding integer value for bound
3889 Set_Corresponding_Integer_Value
3890 (Lo, UR_To_Uint (Realval (Lo) / Small));
3892 -- Similar processing for high bound
3894 Set_Etype (Hi, Empty);
3895 Set_Analyzed (Hi, False);
3899 Resolve (Hi, Universal_Fixed);
3904 Set_Corresponding_Integer_Value
3905 (Hi, UR_To_Uint (Realval (Hi) / Small));
3907 -- Set type of range to correspond to bounds
3909 Set_Etype (Rng, Etype (Lo));
3911 -- Set Esize to calculated size if not set already
3913 if Unknown_Esize (Typ) then
3914 Init_Esize (Typ, Actual_Size);
3917 -- Set RM_Size if not already set. If already set, check value
3920 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
3923 if RM_Size (Typ) /= Uint_0 then
3924 if RM_Size (Typ) < Minsiz then
3925 Error_Msg_Uint_1 := RM_Size (Typ);
3926 Error_Msg_Uint_2 := Minsiz;
3928 ("size given (^) for type& too small, minimum is ^",
3929 Size_Clause (Typ), Typ);
3933 Set_RM_Size (Typ, Minsiz);
3936 end Freeze_Fixed_Point_Type;
3942 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
3946 Set_Has_Delayed_Freeze (T);
3947 L := Freeze_Entity (T, Sloc (N));
3949 if Is_Non_Empty_List (L) then
3950 Insert_Actions (N, L);
3954 --------------------------
3955 -- Freeze_Static_Object --
3956 --------------------------
3958 procedure Freeze_Static_Object (E : Entity_Id) is
3960 Cannot_Be_Static : exception;
3961 -- Exception raised if the type of a static object cannot be made
3962 -- static. This happens if the type depends on non-global objects.
3964 procedure Ensure_Expression_Is_SA (N : Node_Id);
3965 -- Called to ensure that an expression used as part of a type
3966 -- definition is statically allocatable, which means that the type
3967 -- of the expression is statically allocatable, and the expression
3968 -- is either static, or a reference to a library level constant.
3970 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
3971 -- Called to mark a type as static, checking that it is possible
3972 -- to set the type as static. If it is not possible, then the
3973 -- exception Cannot_Be_Static is raised.
3975 -----------------------------
3976 -- Ensure_Expression_Is_SA --
3977 -----------------------------
3979 procedure Ensure_Expression_Is_SA (N : Node_Id) is
3983 Ensure_Type_Is_SA (Etype (N));
3985 if Is_Static_Expression (N) then
3988 elsif Nkind (N) = N_Identifier then
3992 and then Ekind (Ent) = E_Constant
3993 and then Is_Library_Level_Entity (Ent)
3999 raise Cannot_Be_Static;
4000 end Ensure_Expression_Is_SA;
4002 -----------------------
4003 -- Ensure_Type_Is_SA --
4004 -----------------------
4006 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
4011 -- If type is library level, we are all set
4013 if Is_Library_Level_Entity (Typ) then
4017 -- We are also OK if the type is already marked as statically
4018 -- allocated, which means we processed it before.
4020 if Is_Statically_Allocated (Typ) then
4024 -- Mark type as statically allocated
4026 Set_Is_Statically_Allocated (Typ);
4028 -- Check that it is safe to statically allocate this type
4030 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
4031 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
4032 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
4034 elsif Is_Array_Type (Typ) then
4035 N := First_Index (Typ);
4036 while Present (N) loop
4037 Ensure_Type_Is_SA (Etype (N));
4041 Ensure_Type_Is_SA (Component_Type (Typ));
4043 elsif Is_Access_Type (Typ) then
4044 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
4048 T : constant Entity_Id := Etype (Designated_Type (Typ));
4051 if T /= Standard_Void_Type then
4052 Ensure_Type_Is_SA (T);
4055 F := First_Formal (Designated_Type (Typ));
4057 while Present (F) loop
4058 Ensure_Type_Is_SA (Etype (F));
4064 Ensure_Type_Is_SA (Designated_Type (Typ));
4067 elsif Is_Record_Type (Typ) then
4068 C := First_Entity (Typ);
4070 while Present (C) loop
4071 if Ekind (C) = E_Discriminant
4072 or else Ekind (C) = E_Component
4074 Ensure_Type_Is_SA (Etype (C));
4076 elsif Is_Type (C) then
4077 Ensure_Type_Is_SA (C);
4083 elsif Ekind (Typ) = E_Subprogram_Type then
4084 Ensure_Type_Is_SA (Etype (Typ));
4086 C := First_Formal (Typ);
4087 while Present (C) loop
4088 Ensure_Type_Is_SA (Etype (C));
4093 raise Cannot_Be_Static;
4095 end Ensure_Type_Is_SA;
4097 -- Start of processing for Freeze_Static_Object
4100 Ensure_Type_Is_SA (Etype (E));
4102 -- Reset True_Constant flag, since something strange is going on
4103 -- with the scoping here, and our simple value traceing may not
4104 -- be sufficient for this indication to be reliable. We kill the
4105 -- Constant_Value indication for the same reason.
4107 Set_Is_True_Constant (E, False);
4108 Set_Current_Value (E, Empty);
4111 when Cannot_Be_Static =>
4113 -- If the object that cannot be static is imported or exported,
4114 -- then we give an error message saying that this object cannot
4115 -- be imported or exported.
4117 if Is_Imported (E) then
4119 ("& cannot be imported (local type is not constant)", E);
4121 -- Otherwise must be exported, something is wrong if compiler
4122 -- is marking something as statically allocated which cannot be).
4124 else pragma Assert (Is_Exported (E));
4126 ("& cannot be exported (local type is not constant)", E);
4128 end Freeze_Static_Object;
4130 -----------------------
4131 -- Freeze_Subprogram --
4132 -----------------------
4134 procedure Freeze_Subprogram (E : Entity_Id) is
4139 -- Subprogram may not have an address clause unless it is imported
4141 if Present (Address_Clause (E)) then
4142 if not Is_Imported (E) then
4144 ("address clause can only be given " &
4145 "for imported subprogram",
4146 Name (Address_Clause (E)));
4150 -- For non-foreign convention subprograms, this is where we create
4151 -- the extra formals (for accessibility level and constrained bit
4152 -- information). We delay this till the freeze point precisely so
4153 -- that we know the convention!
4155 if not Has_Foreign_Convention (E) then
4156 Create_Extra_Formals (E);
4159 -- If this is convention Ada and a Valued_Procedure, that's odd
4161 if Ekind (E) = E_Procedure
4162 and then Is_Valued_Procedure (E)
4163 and then Convention (E) = Convention_Ada
4164 and then Warn_On_Export_Import
4167 ("?Valued_Procedure has no effect for convention Ada", E);
4168 Set_Is_Valued_Procedure (E, False);
4171 -- Case of foreign convention
4176 -- For foreign conventions, warn about return of an
4177 -- unconstrained array.
4179 -- Note: we *do* allow a return by descriptor for the VMS case,
4180 -- though here there is probably more to be done ???
4182 if Ekind (E) = E_Function then
4183 Retype := Underlying_Type (Etype (E));
4185 -- If no return type, probably some other error, e.g. a
4186 -- missing full declaration, so ignore.
4191 -- If the return type is generic, we have emitted a warning
4192 -- earlier on, and there is nothing else to check here.
4193 -- Specific instantiations may lead to erroneous behavior.
4195 elsif Is_Generic_Type (Etype (E)) then
4198 elsif Is_Array_Type (Retype)
4199 and then not Is_Constrained (Retype)
4200 and then Mechanism (E) not in Descriptor_Codes
4201 and then Warn_On_Export_Import
4204 ("?foreign convention function& should not return " &
4205 "unconstrained array", E);
4210 -- If any of the formals for an exported foreign convention
4211 -- subprogram have defaults, then emit an appropriate warning
4212 -- since this is odd (default cannot be used from non-Ada code)
4214 if Is_Exported (E) then
4215 F := First_Formal (E);
4216 while Present (F) loop
4217 if Warn_On_Export_Import
4218 and then Present (Default_Value (F))
4221 ("?parameter cannot be defaulted in non-Ada call",
4230 -- For VMS, descriptor mechanisms for parameters are allowed only
4231 -- for imported subprograms.
4233 if OpenVMS_On_Target then
4234 if not Is_Imported (E) then
4235 F := First_Formal (E);
4236 while Present (F) loop
4237 if Mechanism (F) in Descriptor_Codes then
4239 ("descriptor mechanism for parameter not permitted", F);
4241 ("\can only be used for imported subprogram", F);
4248 end Freeze_Subprogram;
4250 -----------------------
4251 -- Is_Fully_Defined --
4252 -----------------------
4254 function Is_Fully_Defined (T : Entity_Id) return Boolean is
4256 if Ekind (T) = E_Class_Wide_Type then
4257 return Is_Fully_Defined (Etype (T));
4259 elsif Is_Array_Type (T) then
4260 return Is_Fully_Defined (Component_Type (T));
4262 elsif Is_Record_Type (T)
4263 and not Is_Private_Type (T)
4265 -- Verify that the record type has no components with
4266 -- private types without completion.
4272 Comp := First_Component (T);
4274 while Present (Comp) loop
4275 if not Is_Fully_Defined (Etype (Comp)) then
4279 Next_Component (Comp);
4284 else return not Is_Private_Type (T)
4285 or else Present (Full_View (Base_Type (T)));
4287 end Is_Fully_Defined;
4289 ---------------------------------
4290 -- Process_Default_Expressions --
4291 ---------------------------------
4293 procedure Process_Default_Expressions
4295 After : in out Node_Id)
4297 Loc : constant Source_Ptr := Sloc (E);
4304 Set_Default_Expressions_Processed (E);
4306 -- A subprogram instance and its associated anonymous subprogram
4307 -- share their signature. The default expression functions are defined
4308 -- in the wrapper packages for the anonymous subprogram, and should
4309 -- not be generated again for the instance.
4311 if Is_Generic_Instance (E)
4312 and then Present (Alias (E))
4313 and then Default_Expressions_Processed (Alias (E))
4318 Formal := First_Formal (E);
4320 while Present (Formal) loop
4321 if Present (Default_Value (Formal)) then
4323 -- We work with a copy of the default expression because we
4324 -- do not want to disturb the original, since this would mess
4325 -- up the conformance checking.
4327 Dcopy := New_Copy_Tree (Default_Value (Formal));
4329 -- The analysis of the expression may generate insert actions,
4330 -- which of course must not be executed. We wrap those actions
4331 -- in a procedure that is not called, and later on eliminated.
4332 -- The following cases have no side-effects, and are analyzed
4335 if Nkind (Dcopy) = N_Identifier
4336 or else Nkind (Dcopy) = N_Expanded_Name
4337 or else Nkind (Dcopy) = N_Integer_Literal
4338 or else (Nkind (Dcopy) = N_Real_Literal
4339 and then not Vax_Float (Etype (Dcopy)))
4340 or else Nkind (Dcopy) = N_Character_Literal
4341 or else Nkind (Dcopy) = N_String_Literal
4342 or else Nkind (Dcopy) = N_Null
4343 or else (Nkind (Dcopy) = N_Attribute_Reference
4345 Attribute_Name (Dcopy) = Name_Null_Parameter)
4348 -- If there is no default function, we must still do a full
4349 -- analyze call on the default value, to ensure that all
4350 -- error checks are performed, e.g. those associated with
4351 -- static evaluation. Note that this branch will always be
4352 -- taken if the analyzer is turned off (but we still need the
4355 -- Note: the setting of parent here is to meet the requirement
4356 -- that we can only analyze the expression while attached to
4357 -- the tree. Really the requirement is that the parent chain
4358 -- be set, we don't actually need to be in the tree.
4360 Set_Parent (Dcopy, Declaration_Node (Formal));
4363 -- Default expressions are resolved with their own type if the
4364 -- context is generic, to avoid anomalies with private types.
4366 if Ekind (Scope (E)) = E_Generic_Package then
4369 Resolve (Dcopy, Etype (Formal));
4372 -- If that resolved expression will raise constraint error,
4373 -- then flag the default value as raising constraint error.
4374 -- This allows a proper error message on the calls.
4376 if Raises_Constraint_Error (Dcopy) then
4377 Set_Raises_Constraint_Error (Default_Value (Formal));
4380 -- If the default is a parameterless call, we use the name of
4381 -- the called function directly, and there is no body to build.
4383 elsif Nkind (Dcopy) = N_Function_Call
4384 and then No (Parameter_Associations (Dcopy))
4388 -- Else construct and analyze the body of a wrapper procedure
4389 -- that contains an object declaration to hold the expression.
4390 -- Given that this is done only to complete the analysis, it
4391 -- simpler to build a procedure than a function which might
4392 -- involve secondary stack expansion.
4396 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
4399 Make_Subprogram_Body (Loc,
4401 Make_Procedure_Specification (Loc,
4402 Defining_Unit_Name => Dnam),
4404 Declarations => New_List (
4405 Make_Object_Declaration (Loc,
4406 Defining_Identifier =>
4407 Make_Defining_Identifier (Loc,
4408 New_Internal_Name ('T')),
4409 Object_Definition =>
4410 New_Occurrence_Of (Etype (Formal), Loc),
4411 Expression => New_Copy_Tree (Dcopy))),
4413 Handled_Statement_Sequence =>
4414 Make_Handled_Sequence_Of_Statements (Loc,
4415 Statements => New_List));
4417 Set_Scope (Dnam, Scope (E));
4418 Set_Assignment_OK (First (Declarations (Dbody)));
4419 Set_Is_Eliminated (Dnam);
4420 Insert_After (After, Dbody);
4426 Next_Formal (Formal);
4429 end Process_Default_Expressions;
4431 ----------------------------------------
4432 -- Set_Component_Alignment_If_Not_Set --
4433 ----------------------------------------
4435 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
4437 -- Ignore if not base type, subtypes don't need anything
4439 if Typ /= Base_Type (Typ) then
4443 -- Do not override existing representation
4445 if Is_Packed (Typ) then
4448 elsif Has_Specified_Layout (Typ) then
4451 elsif Component_Alignment (Typ) /= Calign_Default then
4455 Set_Component_Alignment
4456 (Typ, Scope_Stack.Table
4457 (Scope_Stack.Last).Component_Alignment_Default);
4459 end Set_Component_Alignment_If_Not_Set;
4461 ---------------------------
4462 -- Set_Debug_Info_Needed --
4463 ---------------------------
4465 procedure Set_Debug_Info_Needed (T : Entity_Id) is
4468 or else Needs_Debug_Info (T)
4469 or else Debug_Info_Off (T)
4473 Set_Needs_Debug_Info (T);
4476 if Is_Object (T) then
4477 Set_Debug_Info_Needed (Etype (T));
4479 elsif Is_Type (T) then
4480 Set_Debug_Info_Needed (Etype (T));
4482 if Is_Record_Type (T) then
4484 Ent : Entity_Id := First_Entity (T);
4486 while Present (Ent) loop
4487 Set_Debug_Info_Needed (Ent);
4492 elsif Is_Array_Type (T) then
4493 Set_Debug_Info_Needed (Component_Type (T));
4496 Indx : Node_Id := First_Index (T);
4498 while Present (Indx) loop
4499 Set_Debug_Info_Needed (Etype (Indx));
4500 Indx := Next_Index (Indx);
4504 if Is_Packed (T) then
4505 Set_Debug_Info_Needed (Packed_Array_Type (T));
4508 elsif Is_Access_Type (T) then
4509 Set_Debug_Info_Needed (Directly_Designated_Type (T));
4511 elsif Is_Private_Type (T) then
4512 Set_Debug_Info_Needed (Full_View (T));
4514 elsif Is_Protected_Type (T) then
4515 Set_Debug_Info_Needed (Corresponding_Record_Type (T));
4518 end Set_Debug_Info_Needed;
4524 procedure Warn_Overlay
4529 Ent : constant Entity_Id := Entity (Nam);
4530 -- The object to which the address clause applies.
4533 Old : Entity_Id := Empty;
4537 -- No warning if address clause overlay warnings are off
4539 if not Address_Clause_Overlay_Warnings then
4543 -- No warning if there is an explicit initialization
4545 Init := Original_Node (Expression (Declaration_Node (Ent)));
4547 if Present (Init) and then Comes_From_Source (Init) then
4551 -- We only give the warning for non-imported entities of a type
4552 -- for which a non-null base init proc is defined (or for access
4553 -- types which have implicit null initialization).
4556 and then (Has_Non_Null_Base_Init_Proc (Typ)
4557 or else Is_Access_Type (Typ))
4558 and then not Is_Imported (Ent)
4560 if Nkind (Expr) = N_Attribute_Reference
4561 and then Is_Entity_Name (Prefix (Expr))
4563 Old := Entity (Prefix (Expr));
4565 elsif Is_Entity_Name (Expr)
4566 and then Ekind (Entity (Expr)) = E_Constant
4568 Decl := Declaration_Node (Entity (Expr));
4570 if Nkind (Decl) = N_Object_Declaration
4571 and then Present (Expression (Decl))
4572 and then Nkind (Expression (Decl)) = N_Attribute_Reference
4573 and then Is_Entity_Name (Prefix (Expression (Decl)))
4575 Old := Entity (Prefix (Expression (Decl)));
4577 elsif Nkind (Expr) = N_Function_Call then
4581 -- A function call (most likely to To_Address) is probably not
4582 -- an overlay, so skip warning. Ditto if the function call was
4583 -- inlined and transformed into an entity.
4585 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
4589 Decl := Next (Parent (Expr));
4591 -- If a pragma Import follows, we assume that it is for the current
4592 -- target of the address clause, and skip the warning.
4595 and then Nkind (Decl) = N_Pragma
4596 and then Chars (Decl) = Name_Import
4601 if Present (Old) then
4602 Error_Msg_Node_2 := Old;
4604 ("default initialization of & may modify &?",
4608 ("default initialization of & may modify overlaid storage?",
4612 -- Add friendly warning if initialization comes from a packed array
4615 if Is_Record_Type (Typ) then
4620 Comp := First_Component (Typ);
4622 while Present (Comp) loop
4623 if Nkind (Parent (Comp)) = N_Component_Declaration
4624 and then Present (Expression (Parent (Comp)))
4627 elsif Is_Array_Type (Etype (Comp))
4628 and then Present (Packed_Array_Type (Etype (Comp)))
4631 ("packed array component& will be initialized to zero?",
4635 Next_Component (Comp);
4642 ("use pragma Import for & to " &
4643 "suppress initialization ('R'M B.1(24))?",