1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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;
43 with Rident; use Rident;
45 with Sem_Cat; use Sem_Cat;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch7; use Sem_Ch7;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Ch13; use Sem_Ch13;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Mech; use Sem_Mech;
52 with Sem_Prag; use Sem_Prag;
53 with Sem_Res; use Sem_Res;
54 with Sem_Util; use Sem_Util;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Stand; use Stand;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Ttypes; use Ttypes;
61 with Uintp; use Uintp;
62 with Urealp; use Urealp;
64 package body Freeze is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
71 -- Typ is a type that is being frozen. If no size clause is given,
72 -- but a default Esize has been computed, then this default Esize is
73 -- adjusted up if necessary to be consistent with a given alignment,
74 -- but never to a value greater than Long_Long_Integer'Size. This
75 -- is used for all discrete types and for fixed-point types.
77 procedure Build_And_Analyze_Renamed_Body
80 After : in out Node_Id);
81 -- Build body for a renaming declaration, insert in tree and analyze.
83 procedure Check_Address_Clause (E : Entity_Id);
84 -- Apply legality checks to address clauses for object declarations,
85 -- at the point the object is frozen.
87 procedure Check_Strict_Alignment (E : Entity_Id);
88 -- E is a base type. If E is tagged or has a component that is aliased
89 -- or tagged or contains something this is aliased or tagged, set
92 procedure Check_Unsigned_Type (E : Entity_Id);
93 pragma Inline (Check_Unsigned_Type);
94 -- If E is a fixed-point or discrete type, then all the necessary work
95 -- to freeze it is completed except for possible setting of the flag
96 -- Is_Unsigned_Type, which is done by this procedure. The call has no
97 -- effect if the entity E is not a discrete or fixed-point type.
99 procedure Freeze_And_Append
102 Result : in out List_Id);
103 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
104 -- nodes to Result, modifying Result from No_List if necessary.
106 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
107 -- Freeze enumeration type. The Esize field is set as processing
108 -- proceeds (i.e. set by default when the type is declared and then
109 -- adjusted by rep clauses. What this procedure does is to make sure
110 -- that if a foreign convention is specified, and no specific size
111 -- is given, then the size must be at least Integer'Size.
113 procedure Freeze_Static_Object (E : Entity_Id);
114 -- If an object is frozen which has Is_Statically_Allocated set, then
115 -- all referenced types must also be marked with this flag. This routine
116 -- is in charge of meeting this requirement for the object entity E.
118 procedure Freeze_Subprogram (E : Entity_Id);
119 -- Perform freezing actions for a subprogram (create extra formals,
120 -- and set proper default mechanism values). Note that this routine
121 -- is not called for internal subprograms, for which neither of these
122 -- actions is needed (or desirable, we do not want for example to have
123 -- these extra formals present in initialization procedures, where they
124 -- would serve no purpose). In this call E is either a subprogram or
125 -- a subprogram type (i.e. an access to a subprogram).
127 function Is_Fully_Defined (T : Entity_Id) return Boolean;
128 -- True if T is not private and has no private components, or has a full
129 -- view. Used to determine whether the designated type of an access type
130 -- should be frozen when the access type is frozen. This is done when an
131 -- allocator is frozen, or an expression that may involve attributes of
132 -- the designated type. Otherwise freezing the access type does not freeze
133 -- the designated type.
135 procedure Process_Default_Expressions
137 After : in out Node_Id);
138 -- This procedure is called for each subprogram to complete processing
139 -- of default expressions at the point where all types are known to be
140 -- frozen. The expressions must be analyzed in full, to make sure that
141 -- all error processing is done (they have only been pre-analyzed). If
142 -- the expression is not an entity or literal, its analysis may generate
143 -- code which must not be executed. In that case we build a function
144 -- body to hold that code. This wrapper function serves no other purpose
145 -- (it used to be called to evaluate the default, but now the default is
146 -- inlined at each point of call).
148 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
149 -- Typ is a record or array type that is being frozen. This routine
150 -- sets the default component alignment from the scope stack values
151 -- if the alignment is otherwise not specified.
153 procedure Check_Debug_Info_Needed (T : Entity_Id);
154 -- As each entity is frozen, this routine is called to deal with the
155 -- setting of Debug_Info_Needed for the entity. This flag is set if
156 -- the entity comes from source, or if we are in Debug_Generated_Code
157 -- mode or if the -gnatdV debug flag is set. However, it never sets
158 -- the flag if Debug_Info_Off is set.
160 procedure Set_Debug_Info_Needed (T : Entity_Id);
161 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
162 -- also on any entities that are needed by T (for an object, the type
163 -- of the object is needed, and for a type, the subsidiary types are
164 -- needed -- see body for details). Never has any effect on T if the
165 -- Debug_Info_Off flag is set.
167 procedure Warn_Overlay
171 -- Expr is the expression for an address clause for entity Nam whose type
172 -- is Typ. If Typ has a default initialization, and there is no explicit
173 -- initialization in the source declaration, check whether the address
174 -- clause might cause overlaying of an entity, and emit a warning on the
175 -- side effect that the initialization will cause.
177 -------------------------------
178 -- Adjust_Esize_For_Alignment --
179 -------------------------------
181 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
185 if Known_Esize (Typ) and then Known_Alignment (Typ) then
186 Align := Alignment_In_Bits (Typ);
188 if Align > Esize (Typ)
189 and then Align <= Standard_Long_Long_Integer_Size
191 Set_Esize (Typ, Align);
194 end Adjust_Esize_For_Alignment;
196 ------------------------------------
197 -- Build_And_Analyze_Renamed_Body --
198 ------------------------------------
200 procedure Build_And_Analyze_Renamed_Body
203 After : in out Node_Id)
205 Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S);
208 Insert_After (After, Body_Node);
209 Mark_Rewrite_Insertion (Body_Node);
212 end Build_And_Analyze_Renamed_Body;
214 ------------------------
215 -- Build_Renamed_Body --
216 ------------------------
218 function Build_Renamed_Body
220 New_S : Entity_Id) return Node_Id
222 Loc : constant Source_Ptr := Sloc (New_S);
223 -- We use for the source location of the renamed body, the location
224 -- of the spec entity. It might seem more natural to use the location
225 -- of the renaming declaration itself, but that would be wrong, since
226 -- then the body we create would look as though it was created far
227 -- too late, and this could cause problems with elaboration order
228 -- analysis, particularly in connection with instantiations.
230 N : constant Node_Id := Unit_Declaration_Node (New_S);
231 Nam : constant Node_Id := Name (N);
233 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
234 Actuals : List_Id := No_List;
239 O_Formal : Entity_Id;
240 Param_Spec : Node_Id;
243 -- Determine the entity being renamed, which is the target of the
244 -- call statement. If the name is an explicit dereference, this is
245 -- a renaming of a subprogram type rather than a subprogram. The
246 -- name itself is fully analyzed.
248 if Nkind (Nam) = N_Selected_Component then
249 Old_S := Entity (Selector_Name (Nam));
251 elsif Nkind (Nam) = N_Explicit_Dereference then
252 Old_S := Etype (Nam);
254 elsif Nkind (Nam) = N_Indexed_Component then
255 if Is_Entity_Name (Prefix (Nam)) then
256 Old_S := Entity (Prefix (Nam));
258 Old_S := Entity (Selector_Name (Prefix (Nam)));
261 elsif Nkind (Nam) = N_Character_Literal then
262 Old_S := Etype (New_S);
265 Old_S := Entity (Nam);
268 if Is_Entity_Name (Nam) then
270 -- If the renamed entity is a predefined operator, retain full
271 -- name to ensure its visibility.
273 if Ekind (Old_S) = E_Operator
274 and then Nkind (Nam) = N_Expanded_Name
276 Call_Name := New_Copy (Name (N));
278 Call_Name := New_Reference_To (Old_S, Loc);
282 Call_Name := New_Copy (Name (N));
284 -- The original name may have been overloaded, but
285 -- is fully resolved now.
287 Set_Is_Overloaded (Call_Name, False);
290 -- For simple renamings, subsequent calls can be expanded directly
291 -- as called to the renamed entity. The body must be generated in
292 -- any case for calls they may appear elsewhere.
294 if (Ekind (Old_S) = E_Function
295 or else Ekind (Old_S) = E_Procedure)
296 and then Nkind (Decl) = N_Subprogram_Declaration
298 Set_Body_To_Inline (Decl, Old_S);
301 -- The body generated for this renaming is an internal artifact, and
302 -- does not constitute a freeze point for the called entity.
304 Set_Must_Not_Freeze (Call_Name);
306 Formal := First_Formal (Defining_Entity (Decl));
308 if Present (Formal) then
311 while Present (Formal) loop
312 Append (New_Reference_To (Formal, Loc), Actuals);
313 Next_Formal (Formal);
317 -- If the renamed entity is an entry, inherit its profile. For
318 -- other renamings as bodies, both profiles must be subtype
319 -- conformant, so it is not necessary to replace the profile given
320 -- in the declaration. However, default values that are aggregates
321 -- are rewritten when partially analyzed, so we recover the original
322 -- aggregate to insure that subsequent conformity checking works.
323 -- Similarly, if the default expression was constant-folded, recover
324 -- the original expression.
326 Formal := First_Formal (Defining_Entity (Decl));
328 if Present (Formal) then
329 O_Formal := First_Formal (Old_S);
330 Param_Spec := First (Parameter_Specifications (Spec));
332 while Present (Formal) loop
333 if Is_Entry (Old_S) then
335 if Nkind (Parameter_Type (Param_Spec)) /=
338 Set_Etype (Formal, Etype (O_Formal));
339 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
342 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
343 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
344 Nkind (Default_Value (O_Formal))
346 Set_Expression (Param_Spec,
347 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
350 Next_Formal (Formal);
351 Next_Formal (O_Formal);
356 -- If the renamed entity is a function, the generated body contains a
357 -- return statement. Otherwise, build a procedure call. If the entity is
358 -- an entry, subsequent analysis of the call will transform it into the
359 -- proper entry or protected operation call. If the renamed entity is
360 -- a character literal, return it directly.
362 if Ekind (Old_S) = E_Function
363 or else Ekind (Old_S) = E_Operator
364 or else (Ekind (Old_S) = E_Subprogram_Type
365 and then Etype (Old_S) /= Standard_Void_Type)
368 Make_Return_Statement (Loc,
370 Make_Function_Call (Loc,
372 Parameter_Associations => Actuals));
374 elsif Ekind (Old_S) = E_Enumeration_Literal then
376 Make_Return_Statement (Loc,
377 Expression => New_Occurrence_Of (Old_S, Loc));
379 elsif Nkind (Nam) = N_Character_Literal then
381 Make_Return_Statement (Loc,
382 Expression => Call_Name);
386 Make_Procedure_Call_Statement (Loc,
388 Parameter_Associations => Actuals);
391 -- Create entities for subprogram body and formals.
393 Set_Defining_Unit_Name (Spec,
394 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
396 Param_Spec := First (Parameter_Specifications (Spec));
398 while Present (Param_Spec) loop
399 Set_Defining_Identifier (Param_Spec,
400 Make_Defining_Identifier (Loc,
401 Chars => Chars (Defining_Identifier (Param_Spec))));
406 Make_Subprogram_Body (Loc,
407 Specification => Spec,
408 Declarations => New_List,
409 Handled_Statement_Sequence =>
410 Make_Handled_Sequence_Of_Statements (Loc,
411 Statements => New_List (Call_Node)));
413 if Nkind (Decl) /= N_Subprogram_Declaration then
415 Make_Subprogram_Declaration (Loc,
416 Specification => Specification (N)));
419 -- Link the body to the entity whose declaration it completes. If
420 -- the body is analyzed when the renamed entity is frozen, it may be
421 -- necessary to restore the proper scope (see package Exp_Ch13).
423 if Nkind (N) = N_Subprogram_Renaming_Declaration
424 and then Present (Corresponding_Spec (N))
426 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
428 Set_Corresponding_Spec (Body_Node, New_S);
432 end Build_Renamed_Body;
434 --------------------------
435 -- Check_Address_Clause --
436 --------------------------
438 procedure Check_Address_Clause (E : Entity_Id) is
439 Addr : constant Node_Id := Address_Clause (E);
441 Decl : constant Node_Id := Declaration_Node (E);
442 Typ : constant Entity_Id := Etype (E);
445 if Present (Addr) then
446 Expr := Expression (Addr);
448 -- If we have no initialization of any kind, then we don't
449 -- need to place any restrictions on the address clause, because
450 -- the object will be elaborated after the address clause is
451 -- evaluated. This happens if the declaration has no initial
452 -- expression, or the type has no implicit initialization, or
453 -- the object is imported.
455 -- The same holds for all initialized scalar types and all
456 -- access types. Packed bit arrays of size up to 64 are
457 -- represented using a modular type with an initialization
458 -- (to zero) and can be processed like other initialized
461 -- If the type is controlled, code to attach the object to a
462 -- finalization chain is generated at the point of declaration,
463 -- and therefore the elaboration of the object cannot be delayed:
464 -- the address expression must be a constant.
466 if (No (Expression (Decl))
467 and then not Controlled_Type (Typ)
469 (not Has_Non_Null_Base_Init_Proc (Typ)
470 or else Is_Imported (E)))
473 (Present (Expression (Decl))
474 and then Is_Scalar_Type (Typ))
480 (Is_Bit_Packed_Array (Typ)
482 Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
486 -- Otherwise, we require the address clause to be constant
487 -- because the call to the initialization procedure (or the
488 -- attach code) has to happen at the point of the declaration.
491 Check_Constant_Address_Clause (Expr, E);
492 Set_Has_Delayed_Freeze (E, False);
495 if not Error_Posted (Expr)
496 and then not Controlled_Type (Typ)
498 Warn_Overlay (Expr, Typ, Name (Addr));
501 end Check_Address_Clause;
503 -----------------------------
504 -- Check_Compile_Time_Size --
505 -----------------------------
507 procedure Check_Compile_Time_Size (T : Entity_Id) is
509 procedure Set_Small_Size (S : Uint);
510 -- Sets the compile time known size (32 bits or less) in the Esize
511 -- field, checking for a size clause that was given which attempts
512 -- to give a smaller size.
514 function Size_Known (T : Entity_Id) return Boolean;
515 -- Recursive function that does all the work
517 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
518 -- If T is a constrained subtype, its size is not known if any of its
519 -- discriminant constraints is not static and it is not a null record.
520 -- The test is conservative and doesn't check that the components are
521 -- in fact constrained by non-static discriminant values. Could be made
528 procedure Set_Small_Size (S : Uint) is
533 elsif Has_Size_Clause (T) then
534 if RM_Size (T) < S then
535 Error_Msg_Uint_1 := S;
537 ("size for & is too small, minimum is ^",
540 elsif Unknown_Esize (T) then
544 -- Set sizes if not set already
547 if Unknown_Esize (T) then
551 if Unknown_RM_Size (T) then
561 function Size_Known (T : Entity_Id) return Boolean is
569 if Size_Known_At_Compile_Time (T) then
572 elsif Is_Scalar_Type (T)
573 or else Is_Task_Type (T)
575 return not Is_Generic_Type (T);
577 elsif Is_Array_Type (T) then
578 if Ekind (T) = E_String_Literal_Subtype then
579 Set_Small_Size (Component_Size (T) * String_Literal_Length (T));
582 elsif not Is_Constrained (T) then
585 -- Don't do any recursion on type with error posted, since
586 -- we may have a malformed type that leads us into a loop
588 elsif Error_Posted (T) then
591 elsif not Size_Known (Component_Type (T)) then
595 -- Check for all indexes static, and also compute possible
596 -- size (in case it is less than 32 and may be packable).
599 Esiz : Uint := Component_Size (T);
603 Index := First_Index (T);
605 while Present (Index) loop
606 if Nkind (Index) = N_Range then
607 Get_Index_Bounds (Index, Low, High);
609 elsif Error_Posted (Scalar_Range (Etype (Index))) then
613 Low := Type_Low_Bound (Etype (Index));
614 High := Type_High_Bound (Etype (Index));
617 if not Compile_Time_Known_Value (Low)
618 or else not Compile_Time_Known_Value (High)
619 or else Etype (Index) = Any_Type
624 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
636 Set_Small_Size (Esiz);
640 elsif Is_Access_Type (T) then
643 elsif Is_Private_Type (T)
644 and then not Is_Generic_Type (T)
645 and then Present (Underlying_Type (T))
647 -- Don't do any recursion on type with error posted, since
648 -- we may have a malformed type that leads us into a loop
650 if Error_Posted (T) then
653 return Size_Known (Underlying_Type (T));
656 elsif Is_Record_Type (T) then
658 -- A class-wide type is never considered to have a known size
660 if Is_Class_Wide_Type (T) then
663 -- A subtype of a variant record must not have non-static
664 -- discriminanted components.
666 elsif T /= Base_Type (T)
667 and then not Static_Discriminated_Components (T)
671 -- Don't do any recursion on type with error posted, since
672 -- we may have a malformed type that leads us into a loop
674 elsif Error_Posted (T) then
678 -- Now look at the components of the record
681 -- The following two variables are used to keep track of
682 -- the size of packed records if we can tell the size of
683 -- the packed record in the front end. Packed_Size_Known
684 -- is True if so far we can figure out the size. It is
685 -- initialized to True for a packed record, unless the
686 -- record has discriminants. The reason we eliminate the
687 -- discriminated case is that we don't know the way the
688 -- back end lays out discriminated packed records. If
689 -- Packed_Size_Known is True, then Packed_Size is the
690 -- size in bits so far.
692 Packed_Size_Known : Boolean :=
694 and then not Has_Discriminants (T);
696 Packed_Size : Uint := Uint_0;
699 -- Test for variant part present
701 if Has_Discriminants (T)
702 and then Present (Parent (T))
703 and then Nkind (Parent (T)) = N_Full_Type_Declaration
704 and then Nkind (Type_Definition (Parent (T))) =
706 and then not Null_Present (Type_Definition (Parent (T)))
707 and then Present (Variant_Part
708 (Component_List (Type_Definition (Parent (T)))))
710 -- If variant part is present, and type is unconstrained,
711 -- then we must have defaulted discriminants, or a size
712 -- clause must be present for the type, or else the size
713 -- is definitely not known at compile time.
715 if not Is_Constrained (T)
717 No (Discriminant_Default_Value
718 (First_Discriminant (T)))
719 and then Unknown_Esize (T)
725 -- Loop through components
727 Comp := First_Entity (T);
728 while Present (Comp) loop
729 if Ekind (Comp) = E_Component
731 Ekind (Comp) = E_Discriminant
733 Ctyp := Etype (Comp);
735 -- We do not know the packed size if there is a
736 -- component clause present (we possibly could,
737 -- but this would only help in the case of a record
738 -- with partial rep clauses. That's because in the
739 -- case of full rep clauses, the size gets figured
740 -- out anyway by a different circuit).
742 if Present (Component_Clause (Comp)) then
743 Packed_Size_Known := False;
746 -- We need to identify a component that is an array
747 -- where the index type is an enumeration type with
748 -- non-standard representation, and some bound of the
749 -- type depends on a discriminant.
751 -- This is because gigi computes the size by doing a
752 -- substituation of the appropriate discriminant value
753 -- in the size expression for the base type, and gigi
754 -- is not clever enough to evaluate the resulting
755 -- expression (which involves a call to rep_to_pos)
758 -- It would be nice if gigi would either recognize that
759 -- this expression can be computed at compile time, or
760 -- alternatively figured out the size from the subtype
761 -- directly, where all the information is at hand ???
763 if Is_Array_Type (Etype (Comp))
764 and then Present (Packed_Array_Type (Etype (Comp)))
767 Ocomp : constant Entity_Id :=
768 Original_Record_Component (Comp);
769 OCtyp : constant Entity_Id := Etype (Ocomp);
775 Ind := First_Index (OCtyp);
776 while Present (Ind) loop
777 Indtyp := Etype (Ind);
779 if Is_Enumeration_Type (Indtyp)
780 and then Has_Non_Standard_Rep (Indtyp)
782 Lo := Type_Low_Bound (Indtyp);
783 Hi := Type_High_Bound (Indtyp);
785 if Is_Entity_Name (Lo)
787 Ekind (Entity (Lo)) = E_Discriminant
791 elsif Is_Entity_Name (Hi)
793 Ekind (Entity (Hi)) = E_Discriminant
804 -- Clearly size of record is not known if the size of
805 -- one of the components is not known.
807 if not Size_Known (Ctyp) then
811 -- Accumulate packed size if possible
813 if Packed_Size_Known then
815 -- We can only deal with elementary types, since for
816 -- non-elementary components, alignment enters into
817 -- the picture, and we don't know enough to handle
818 -- proper alignment in this context. Packed arrays
819 -- count as elementary if the representation is a
822 if Is_Elementary_Type (Ctyp)
823 or else (Is_Array_Type (Ctyp)
825 Present (Packed_Array_Type (Ctyp))
827 Is_Modular_Integer_Type
828 (Packed_Array_Type (Ctyp)))
830 -- If RM_Size is known and static, then we can
831 -- keep accumulating the packed size.
833 if Known_Static_RM_Size (Ctyp) then
835 -- A little glitch, to be removed sometime ???
836 -- gigi does not understand zero sizes yet.
838 if RM_Size (Ctyp) = Uint_0 then
839 Packed_Size_Known := False;
841 -- Normal case where we can keep accumulating
842 -- the packed array size.
845 Packed_Size := Packed_Size + RM_Size (Ctyp);
848 -- If we have a field whose RM_Size is not known
849 -- then we can't figure out the packed size here.
852 Packed_Size_Known := False;
855 -- If we have a non-elementary type we can't figure
856 -- out the packed array size (alignment issues).
859 Packed_Size_Known := False;
867 if Packed_Size_Known then
868 Set_Small_Size (Packed_Size);
879 -------------------------------------
880 -- Static_Discriminated_Components --
881 -------------------------------------
883 function Static_Discriminated_Components
887 Constraint : Elmt_Id;
890 if Has_Discriminants (T)
891 and then Present (Discriminant_Constraint (T))
892 and then Present (First_Component (T))
894 Constraint := First_Elmt (Discriminant_Constraint (T));
895 while Present (Constraint) loop
896 if not Compile_Time_Known_Value (Node (Constraint)) then
900 Next_Elmt (Constraint);
905 end Static_Discriminated_Components;
907 -- Start of processing for Check_Compile_Time_Size
910 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
911 end Check_Compile_Time_Size;
913 -----------------------------
914 -- Check_Debug_Info_Needed --
915 -----------------------------
917 procedure Check_Debug_Info_Needed (T : Entity_Id) is
919 if Needs_Debug_Info (T) or else Debug_Info_Off (T) then
922 elsif Comes_From_Source (T)
923 or else Debug_Generated_Code
924 or else Debug_Flag_VV
926 Set_Debug_Info_Needed (T);
928 end Check_Debug_Info_Needed;
930 ----------------------------
931 -- Check_Strict_Alignment --
932 ----------------------------
934 procedure Check_Strict_Alignment (E : Entity_Id) is
938 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
939 Set_Strict_Alignment (E);
941 elsif Is_Array_Type (E) then
942 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
944 elsif Is_Record_Type (E) then
945 if Is_Limited_Record (E) then
946 Set_Strict_Alignment (E);
950 Comp := First_Component (E);
952 while Present (Comp) loop
953 if not Is_Type (Comp)
954 and then (Strict_Alignment (Etype (Comp))
955 or else Is_Aliased (Comp))
957 Set_Strict_Alignment (E);
961 Next_Component (Comp);
964 end Check_Strict_Alignment;
966 -------------------------
967 -- Check_Unsigned_Type --
968 -------------------------
970 procedure Check_Unsigned_Type (E : Entity_Id) is
971 Ancestor : Entity_Id;
976 if not Is_Discrete_Or_Fixed_Point_Type (E) then
980 -- Do not attempt to analyze case where range was in error
982 if Error_Posted (Scalar_Range (E)) then
986 -- The situation that is non trivial is something like
988 -- subtype x1 is integer range -10 .. +10;
989 -- subtype x2 is x1 range 0 .. V1;
990 -- subtype x3 is x2 range V2 .. V3;
991 -- subtype x4 is x3 range V4 .. V5;
993 -- where Vn are variables. Here the base type is signed, but we still
994 -- know that x4 is unsigned because of the lower bound of x2.
996 -- The only way to deal with this is to look up the ancestor chain
1000 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1004 Lo_Bound := Type_Low_Bound (Ancestor);
1006 if Compile_Time_Known_Value (Lo_Bound) then
1008 if Expr_Rep_Value (Lo_Bound) >= 0 then
1009 Set_Is_Unsigned_Type (E, True);
1015 Ancestor := Ancestor_Subtype (Ancestor);
1017 -- If no ancestor had a static lower bound, go to base type
1019 if No (Ancestor) then
1021 -- Note: the reason we still check for a compile time known
1022 -- value for the base type is that at least in the case of
1023 -- generic formals, we can have bounds that fail this test,
1024 -- and there may be other cases in error situations.
1026 Btyp := Base_Type (E);
1028 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1032 Lo_Bound := Type_Low_Bound (Base_Type (E));
1034 if Compile_Time_Known_Value (Lo_Bound)
1035 and then Expr_Rep_Value (Lo_Bound) >= 0
1037 Set_Is_Unsigned_Type (E, True);
1044 end Check_Unsigned_Type;
1046 -----------------------------
1047 -- Expand_Atomic_Aggregate --
1048 -----------------------------
1050 procedure Expand_Atomic_Aggregate (E : Entity_Id; Typ : Entity_Id) is
1051 Loc : constant Source_Ptr := Sloc (E);
1056 if (Nkind (Parent (E)) = N_Object_Declaration
1057 or else Nkind (Parent (E)) = N_Assignment_Statement)
1058 and then Comes_From_Source (Parent (E))
1059 and then Nkind (E) = N_Aggregate
1062 Make_Defining_Identifier (Loc,
1063 New_Internal_Name ('T'));
1066 Make_Object_Declaration (Loc,
1067 Defining_Identifier => Temp,
1068 Object_definition => New_Occurrence_Of (Typ, Loc),
1069 Expression => Relocate_Node (E));
1070 Insert_Before (Parent (E), New_N);
1073 Set_Expression (Parent (E), New_Occurrence_Of (Temp, Loc));
1075 -- To prevent the temporary from being constant-folded (which
1076 -- would lead to the same piecemeal assignment on the original
1077 -- target) indicate to the back-end that the temporary is a
1078 -- variable with real storage. See description of this flag
1079 -- in Einfo, and the notes on N_Assignment_Statement and
1080 -- N_Object_Declaration in Sinfo.
1082 Set_Is_True_Constant (Temp, False);
1084 end Expand_Atomic_Aggregate;
1090 -- Note: the easy coding for this procedure would be to just build a
1091 -- single list of freeze nodes and then insert them and analyze them
1092 -- all at once. This won't work, because the analysis of earlier freeze
1093 -- nodes may recursively freeze types which would otherwise appear later
1094 -- on in the freeze list. So we must analyze and expand the freeze nodes
1095 -- as they are generated.
1097 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1098 Loc : constant Source_Ptr := Sloc (After);
1102 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1103 -- This is the internal recursive routine that does freezing of
1104 -- entities (but NOT the analysis of default expressions, which
1105 -- should not be recursive, we don't want to analyze those till
1106 -- we are sure that ALL the types are frozen).
1108 --------------------
1109 -- Freeze_All_Ent --
1110 --------------------
1112 procedure Freeze_All_Ent
1114 After : in out Node_Id)
1120 procedure Process_Flist;
1121 -- If freeze nodes are present, insert and analyze, and reset
1122 -- cursor for next insertion.
1128 procedure Process_Flist is
1130 if Is_Non_Empty_List (Flist) then
1131 Lastn := Next (After);
1132 Insert_List_After_And_Analyze (After, Flist);
1134 if Present (Lastn) then
1135 After := Prev (Lastn);
1137 After := Last (List_Containing (After));
1142 -- Start or processing for Freeze_All_Ent
1146 while Present (E) loop
1148 -- If the entity is an inner package which is not a package
1149 -- renaming, then its entities must be frozen at this point.
1150 -- Note that such entities do NOT get frozen at the end of
1151 -- the nested package itself (only library packages freeze).
1153 -- Same is true for task declarations, where anonymous records
1154 -- created for entry parameters must be frozen.
1156 if Ekind (E) = E_Package
1157 and then No (Renamed_Object (E))
1158 and then not Is_Child_Unit (E)
1159 and then not Is_Frozen (E)
1162 Install_Visible_Declarations (E);
1163 Install_Private_Declarations (E);
1165 Freeze_All (First_Entity (E), After);
1167 End_Package_Scope (E);
1169 elsif Ekind (E) in Task_Kind
1171 (Nkind (Parent (E)) = N_Task_Type_Declaration
1173 Nkind (Parent (E)) = N_Single_Task_Declaration)
1176 Freeze_All (First_Entity (E), After);
1179 -- For a derived tagged type, we must ensure that all the
1180 -- primitive operations of the parent have been frozen, so
1181 -- that their addresses will be in the parent's dispatch table
1182 -- at the point it is inherited.
1184 elsif Ekind (E) = E_Record_Type
1185 and then Is_Tagged_Type (E)
1186 and then Is_Tagged_Type (Etype (E))
1187 and then Is_Derived_Type (E)
1190 Prim_List : constant Elist_Id :=
1191 Primitive_Operations (Etype (E));
1197 Prim := First_Elmt (Prim_List);
1199 while Present (Prim) loop
1200 Subp := Node (Prim);
1202 if Comes_From_Source (Subp)
1203 and then not Is_Frozen (Subp)
1205 Flist := Freeze_Entity (Subp, Loc);
1214 if not Is_Frozen (E) then
1215 Flist := Freeze_Entity (E, Loc);
1219 -- If an incomplete type is still not frozen, this may be
1220 -- a premature freezing because of a body declaration that
1221 -- follows. Indicate where the freezing took place.
1223 -- If the freezing is caused by the end of the current
1224 -- declarative part, it is a Taft Amendment type, and there
1227 if not Is_Frozen (E)
1228 and then Ekind (E) = E_Incomplete_Type
1231 Bod : constant Node_Id := Next (After);
1234 if (Nkind (Bod) = N_Subprogram_Body
1235 or else Nkind (Bod) = N_Entry_Body
1236 or else Nkind (Bod) = N_Package_Body
1237 or else Nkind (Bod) = N_Protected_Body
1238 or else Nkind (Bod) = N_Task_Body
1239 or else Nkind (Bod) in N_Body_Stub)
1241 List_Containing (After) = List_Containing (Parent (E))
1243 Error_Msg_Sloc := Sloc (Next (After));
1245 ("type& is frozen# before its full declaration",
1255 -- Start of processing for Freeze_All
1258 Freeze_All_Ent (From, After);
1260 -- Now that all types are frozen, we can deal with default expressions
1261 -- that require us to build a default expression functions. This is the
1262 -- point at which such functions are constructed (after all types that
1263 -- might be used in such expressions have been frozen).
1265 -- We also add finalization chains to access types whose designated
1266 -- types are controlled. This is normally done when freezing the type,
1267 -- but this misses recursive type definitions where the later members
1268 -- of the recursion introduce controlled components (e.g. 5624-001).
1270 -- Loop through entities
1273 while Present (E) loop
1274 if Is_Subprogram (E) then
1276 if not Default_Expressions_Processed (E) then
1277 Process_Default_Expressions (E, After);
1280 if not Has_Completion (E) then
1281 Decl := Unit_Declaration_Node (E);
1283 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1284 Build_And_Analyze_Renamed_Body (Decl, E, After);
1286 elsif Nkind (Decl) = N_Subprogram_Declaration
1287 and then Present (Corresponding_Body (Decl))
1289 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1290 = N_Subprogram_Renaming_Declaration
1292 Build_And_Analyze_Renamed_Body
1293 (Decl, Corresponding_Body (Decl), After);
1297 elsif Ekind (E) in Task_Kind
1299 (Nkind (Parent (E)) = N_Task_Type_Declaration
1301 Nkind (Parent (E)) = N_Single_Task_Declaration)
1306 Ent := First_Entity (E);
1308 while Present (Ent) loop
1311 and then not Default_Expressions_Processed (Ent)
1313 Process_Default_Expressions (Ent, After);
1320 elsif Is_Access_Type (E)
1321 and then Comes_From_Source (E)
1322 and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
1323 and then Controlled_Type (Designated_Type (E))
1324 and then No (Associated_Final_Chain (E))
1326 Build_Final_List (Parent (E), E);
1333 -----------------------
1334 -- Freeze_And_Append --
1335 -----------------------
1337 procedure Freeze_And_Append
1340 Result : in out List_Id)
1342 L : constant List_Id := Freeze_Entity (Ent, Loc);
1345 if Is_Non_Empty_List (L) then
1346 if Result = No_List then
1349 Append_List (L, Result);
1352 end Freeze_And_Append;
1358 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1359 Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
1362 if Is_Non_Empty_List (Freeze_Nodes) then
1363 Insert_Actions (N, Freeze_Nodes);
1371 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
1379 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1380 -- Check that an Access or Unchecked_Access attribute with
1381 -- a prefix which is the current instance type can only be
1382 -- applied when the type is limited.
1384 function After_Last_Declaration return Boolean;
1385 -- If Loc is a freeze_entity that appears after the last declaration
1386 -- in the scope, inhibit error messages on late completion.
1388 procedure Freeze_Record_Type (Rec : Entity_Id);
1389 -- Freeze each component, handle some representation clauses, and
1390 -- freeze primitive operations if this is a tagged type.
1392 ----------------------------
1393 -- After_Last_Declaration --
1394 ----------------------------
1396 function After_Last_Declaration return Boolean is
1397 Spec : constant Node_Id := Parent (Current_Scope);
1400 if Nkind (Spec) = N_Package_Specification then
1401 if Present (Private_Declarations (Spec)) then
1402 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1404 elsif Present (Visible_Declarations (Spec)) then
1405 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1413 end After_Last_Declaration;
1415 ----------------------------
1416 -- Check_Current_Instance --
1417 ----------------------------
1419 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1421 function Process (N : Node_Id) return Traverse_Result;
1422 -- Process routine to apply check to given node.
1428 function Process (N : Node_Id) return Traverse_Result is
1431 when N_Attribute_Reference =>
1432 if (Attribute_Name (N) = Name_Access
1434 Attribute_Name (N) = Name_Unchecked_Access)
1435 and then Is_Entity_Name (Prefix (N))
1436 and then Is_Type (Entity (Prefix (N)))
1437 and then Entity (Prefix (N)) = E
1440 ("current instance must be a limited type", Prefix (N));
1446 when others => return OK;
1450 procedure Traverse is new Traverse_Proc (Process);
1452 -- Start of processing for Check_Current_Instance
1455 Traverse (Comp_Decl);
1456 end Check_Current_Instance;
1458 ------------------------
1459 -- Freeze_Record_Type --
1460 ------------------------
1462 procedure Freeze_Record_Type (Rec : Entity_Id) is
1468 Unplaced_Component : Boolean := False;
1469 -- Set True if we find at least one component with no component
1470 -- clause (used to warn about useless Pack pragmas).
1472 Placed_Component : Boolean := False;
1473 -- Set True if we find at least one component with a component
1474 -- clause (used to warn about useless Bit_Order pragmas).
1476 procedure Check_Itype (Desig : Entity_Id);
1477 -- If the component subtype is an access to a constrained subtype
1478 -- of an already frozen type, make the subtype frozen as well. It
1479 -- might otherwise be frozen in the wrong scope, and a freeze node
1480 -- on subtype has no effect.
1486 procedure Check_Itype (Desig : Entity_Id) is
1488 if not Is_Frozen (Desig)
1489 and then Is_Frozen (Base_Type (Desig))
1491 Set_Is_Frozen (Desig);
1493 -- In addition, add an Itype_Reference to ensure that the
1494 -- access subtype is elaborated early enough. This cannot
1495 -- be done if the subtype may depend on discriminants.
1497 if Ekind (Comp) = E_Component
1498 and then Is_Itype (Etype (Comp))
1499 and then not Has_Discriminants (Rec)
1501 IR := Make_Itype_Reference (Sloc (Comp));
1502 Set_Itype (IR, Desig);
1505 Result := New_List (IR);
1507 Append (IR, Result);
1513 -- Start of processing for Freeze_Record_Type
1516 -- If this is a subtype of a controlled type, declared without
1517 -- a constraint, the _controller may not appear in the component
1518 -- list if the parent was not frozen at the point of subtype
1519 -- declaration. Inherit the _controller component now.
1521 if Rec /= Base_Type (Rec)
1522 and then Has_Controlled_Component (Rec)
1524 if Nkind (Parent (Rec)) = N_Subtype_Declaration
1525 and then Is_Entity_Name (Subtype_Indication (Parent (Rec)))
1527 Set_First_Entity (Rec, First_Entity (Base_Type (Rec)));
1529 -- If this is an internal type without a declaration, as for a
1530 -- record component, the base type may not yet be frozen, and its
1531 -- controller has not been created. Add an explicit freeze node
1532 -- for the itype, so it will be frozen after the base type.
1534 elsif Is_Itype (Rec)
1535 and then Has_Delayed_Freeze (Base_Type (Rec))
1537 Nkind (Associated_Node_For_Itype (Rec)) =
1538 N_Component_Declaration
1540 Ensure_Freeze_Node (Rec);
1544 -- Freeze components and embedded subtypes
1546 Comp := First_Entity (Rec);
1547 while Present (Comp) loop
1548 if not Is_Type (Comp) then
1549 Freeze_And_Append (Etype (Comp), Loc, Result);
1552 -- If the component is an access type with an allocator
1553 -- as default value, the designated type will be frozen
1554 -- by the corresponding expression in init_proc. In order
1555 -- to place the freeze node for the designated type before
1556 -- that for the current record type, freeze it now.
1558 -- Same process if the component is an array of access types,
1559 -- initialized with an aggregate. If the designated type is
1560 -- private, it cannot contain allocators, and it is premature
1561 -- to freeze the type, so we check for this as well.
1563 if Is_Access_Type (Etype (Comp))
1564 and then Present (Parent (Comp))
1565 and then Present (Expression (Parent (Comp)))
1566 and then Nkind (Expression (Parent (Comp))) = N_Allocator
1569 Alloc : constant Node_Id := Expression (Parent (Comp));
1572 -- If component is pointer to a classwide type, freeze
1573 -- the specific type in the expression being allocated.
1574 -- The expression may be a subtype indication, in which
1575 -- case freeze the subtype mark.
1577 if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
1578 if Is_Entity_Name (Expression (Alloc)) then
1580 (Entity (Expression (Alloc)), Loc, Result);
1582 Nkind (Expression (Alloc)) = N_Subtype_Indication
1585 (Entity (Subtype_Mark (Expression (Alloc))),
1589 elsif Is_Itype (Designated_Type (Etype (Comp))) then
1590 Check_Itype (Designated_Type (Etype (Comp)));
1594 (Designated_Type (Etype (Comp)), Loc, Result);
1598 elsif Is_Access_Type (Etype (Comp))
1599 and then Is_Itype (Designated_Type (Etype (Comp)))
1601 Check_Itype (Designated_Type (Etype (Comp)));
1603 elsif Is_Array_Type (Etype (Comp))
1604 and then Is_Access_Type (Component_Type (Etype (Comp)))
1605 and then Present (Parent (Comp))
1606 and then Nkind (Parent (Comp)) = N_Component_Declaration
1607 and then Present (Expression (Parent (Comp)))
1608 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
1609 and then Is_Fully_Defined
1610 (Designated_Type (Component_Type (Etype (Comp))))
1614 (Component_Type (Etype (Comp))), Loc, Result);
1617 -- Processing for real components (exclude anonymous subtypes)
1619 if Ekind (Comp) = E_Component
1620 or else Ekind (Comp) = E_Discriminant
1622 -- Check for error of component clause given for variable
1623 -- sized type. We have to delay this test till this point,
1624 -- since the component type has to be frozen for us to know
1625 -- if it is variable length. We omit this test in a generic
1626 -- context, it will be applied at instantiation time.
1629 CC : constant Node_Id := Component_Clause (Comp);
1632 if Present (CC) then
1633 Placed_Component := True;
1635 if Inside_A_Generic then
1638 elsif not Size_Known_At_Compile_Time
1639 (Underlying_Type (Etype (Comp)))
1642 ("component clause not allowed for variable " &
1643 "length component", CC);
1647 Unplaced_Component := True;
1651 -- If component clause is present, then deal with the
1652 -- non-default bit order case. We cannot do this before
1653 -- the freeze point, because there is no required order
1654 -- for the component clause and the bit_order clause.
1656 -- We only do this processing for the base type, and in
1657 -- fact that's important, since otherwise if there are
1658 -- record subtypes, we could reverse the bits once for
1659 -- each subtype, which would be incorrect.
1661 if Present (Component_Clause (Comp))
1662 and then Reverse_Bit_Order (Rec)
1663 and then Ekind (E) = E_Record_Type
1666 CFB : constant Uint := Component_Bit_Offset (Comp);
1667 CSZ : constant Uint := Esize (Comp);
1668 CLC : constant Node_Id := Component_Clause (Comp);
1669 Pos : constant Node_Id := Position (CLC);
1670 FB : constant Node_Id := First_Bit (CLC);
1672 Storage_Unit_Offset : constant Uint :=
1673 CFB / System_Storage_Unit;
1675 Start_Bit : constant Uint :=
1676 CFB mod System_Storage_Unit;
1679 -- Cases where field goes over storage unit boundary
1681 if Start_Bit + CSZ > System_Storage_Unit then
1683 -- Allow multi-byte field but generate warning
1685 if Start_Bit mod System_Storage_Unit = 0
1686 and then CSZ mod System_Storage_Unit = 0
1689 ("multi-byte field specified with non-standard"
1690 & " Bit_Order?", CLC);
1692 if Bytes_Big_Endian then
1694 ("bytes are not reversed "
1695 & "(component is big-endian)?", CLC);
1698 ("bytes are not reversed "
1699 & "(component is little-endian)?", CLC);
1702 -- Do not allow non-contiguous field
1706 ("attempt to specify non-contiguous field"
1707 & " not permitted", CLC);
1709 ("\(caused by non-standard Bit_Order "
1710 & "specified)", CLC);
1713 -- Case where field fits in one storage unit
1716 -- Give warning if suspicious component clause
1718 if Intval (FB) >= System_Storage_Unit then
1720 ("?Bit_Order clause does not affect " &
1721 "byte ordering", Pos);
1723 Intval (Pos) + Intval (FB) / System_Storage_Unit;
1725 ("?position normalized to ^ before bit " &
1726 "order interpreted", Pos);
1729 -- Here is where we fix up the Component_Bit_Offset
1730 -- value to account for the reverse bit order.
1731 -- Some examples of what needs to be done are:
1733 -- First_Bit .. Last_Bit Component_Bit_Offset
1736 -- 0 .. 0 7 .. 7 0 7
1737 -- 0 .. 1 6 .. 7 0 6
1738 -- 0 .. 2 5 .. 7 0 5
1739 -- 0 .. 7 0 .. 7 0 4
1741 -- 1 .. 1 6 .. 6 1 6
1742 -- 1 .. 4 3 .. 6 1 3
1743 -- 4 .. 7 0 .. 3 4 0
1745 -- The general rule is that the first bit is
1746 -- is obtained by subtracting the old ending bit
1747 -- from storage_unit - 1.
1749 Set_Component_Bit_Offset (Comp,
1750 (Storage_Unit_Offset * System_Storage_Unit)
1751 + (System_Storage_Unit - 1)
1752 - (Start_Bit + CSZ - 1));
1754 Set_Normalized_First_Bit (Comp,
1755 Component_Bit_Offset (Comp) mod System_Storage_Unit);
1764 -- Check for useless pragma Bit_Order
1766 if not Placed_Component and then Reverse_Bit_Order (Rec) then
1767 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
1768 Error_Msg_N ("?Bit_Order specification has no effect", ADC);
1769 Error_Msg_N ("\?since no component clauses were specified", ADC);
1772 -- Check for useless pragma Pack when all components placed
1775 and then not Unplaced_Component
1776 and then Warn_On_Redundant_Constructs
1779 ("?pragma Pack has no effect, no unplaced components",
1780 Get_Rep_Pragma (Rec, Name_Pack));
1781 Set_Is_Packed (Rec, False);
1784 -- If this is the record corresponding to a remote type,
1785 -- freeze the remote type here since that is what we are
1786 -- semantically freezing. This prevents having the freeze
1787 -- node for that type in an inner scope.
1789 -- Also, Check for controlled components and unchecked unions.
1790 -- Finally, enforce the restriction that access attributes with
1791 -- a current instance prefix can only apply to limited types.
1793 if Ekind (Rec) = E_Record_Type then
1794 if Present (Corresponding_Remote_Type (Rec)) then
1796 (Corresponding_Remote_Type (Rec), Loc, Result);
1799 Comp := First_Component (Rec);
1800 while Present (Comp) loop
1801 if Has_Controlled_Component (Etype (Comp))
1802 or else (Chars (Comp) /= Name_uParent
1803 and then Is_Controlled (Etype (Comp)))
1804 or else (Is_Protected_Type (Etype (Comp))
1806 (Corresponding_Record_Type (Etype (Comp)))
1807 and then Has_Controlled_Component
1808 (Corresponding_Record_Type (Etype (Comp))))
1810 Set_Has_Controlled_Component (Rec);
1814 if Has_Unchecked_Union (Etype (Comp)) then
1815 Set_Has_Unchecked_Union (Rec);
1818 if Has_Per_Object_Constraint (Comp)
1819 and then not Is_Limited_Type (Rec)
1821 -- Scan component declaration for likely misuses of
1822 -- current instance, either in a constraint or in a
1823 -- default expression.
1825 Check_Current_Instance (Parent (Comp));
1828 Next_Component (Comp);
1832 Set_Component_Alignment_If_Not_Set (Rec);
1834 -- For first subtypes, check if there are any fixed-point
1835 -- fields with component clauses, where we must check the size.
1836 -- This is not done till the freeze point, since for fixed-point
1837 -- types, we do not know the size until the type is frozen.
1838 -- Similar processing applies to bit packed arrays.
1840 if Is_First_Subtype (Rec) then
1841 Comp := First_Component (Rec);
1843 while Present (Comp) loop
1844 if Present (Component_Clause (Comp))
1845 and then (Is_Fixed_Point_Type (Etype (Comp))
1847 Is_Bit_Packed_Array (Etype (Comp)))
1850 (Component_Name (Component_Clause (Comp)),
1856 Next_Component (Comp);
1859 end Freeze_Record_Type;
1861 -- Start of processing for Freeze_Entity
1864 -- Do not freeze if already frozen since we only need one freeze node
1866 if Is_Frozen (E) then
1869 -- It is improper to freeze an external entity within a generic
1870 -- because its freeze node will appear in a non-valid context.
1871 -- The entity will be frozen in the proper scope after the current
1872 -- generic is analyzed.
1874 elsif Inside_A_Generic and then External_Ref_In_Generic (E) then
1877 -- Do not freeze a global entity within an inner scope created during
1878 -- expansion. A call to subprogram E within some internal procedure
1879 -- (a stream attribute for example) might require freezing E, but the
1880 -- freeze node must appear in the same declarative part as E itself.
1881 -- The two-pass elaboration mechanism in gigi guarantees that E will
1882 -- be frozen before the inner call is elaborated. We exclude constants
1883 -- from this test, because deferred constants may be frozen early, and
1884 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
1885 -- comes from source, or is a generic instance, then the freeze point
1886 -- is the one mandated by the language. and we freze the entity.
1888 elsif In_Open_Scopes (Scope (E))
1889 and then Scope (E) /= Current_Scope
1890 and then Ekind (E) /= E_Constant
1893 S : Entity_Id := Current_Scope;
1896 while Present (S) loop
1897 if Is_Overloadable (S) then
1898 if Comes_From_Source (S)
1899 or else Is_Generic_Instance (S)
1911 -- Similarly, an inlined instance body may make reference to global
1912 -- entities, but these references cannot be the proper freezing point
1913 -- for them, and the the absence of inlining freezing will take place
1914 -- in their own scope. Normally instance bodies are analyzed after
1915 -- the enclosing compilation, and everything has been frozen at the
1916 -- proper place, but with front-end inlining an instance body is
1917 -- compiled before the end of the enclosing scope, and as a result
1918 -- out-of-order freezing must be prevented.
1920 elsif Front_End_Inlining
1921 and then In_Instance_Body
1922 and then Present (Scope (E))
1925 S : Entity_Id := Scope (E);
1927 while Present (S) loop
1928 if Is_Generic_Instance (S) then
1941 -- Here to freeze the entity
1946 -- Case of entity being frozen is other than a type
1948 if not Is_Type (E) then
1950 -- If entity is exported or imported and does not have an external
1951 -- name, now is the time to provide the appropriate default name.
1952 -- Skip this if the entity is stubbed, since we don't need a name
1953 -- for any stubbed routine.
1955 if (Is_Imported (E) or else Is_Exported (E))
1956 and then No (Interface_Name (E))
1957 and then Convention (E) /= Convention_Stubbed
1959 Set_Encoded_Interface_Name
1960 (E, Get_Default_External_Name (E));
1962 -- Special processing for atomic objects appearing in object decls
1965 and then Nkind (Parent (E)) = N_Object_Declaration
1966 and then Present (Expression (Parent (E)))
1969 Expr : constant Node_Id := Expression (Parent (E));
1972 -- If expression is an aggregate, assign to a temporary to
1973 -- ensure that the actual assignment is done atomically rather
1974 -- than component-wise (the assignment to the temp may be done
1975 -- component-wise, but that is harmless.
1977 if Nkind (Expr) = N_Aggregate then
1978 Expand_Atomic_Aggregate (Expr, Etype (E));
1980 -- If the expression is a reference to a record or array
1981 -- object entity, then reset Is_True_Constant to False so
1982 -- that the compiler will not optimize away the intermediate
1983 -- object, which we need in this case for the same reason
1984 -- (to ensure that the actual assignment is atomic, rather
1985 -- than component-wise).
1987 elsif Is_Entity_Name (Expr)
1988 and then (Is_Record_Type (Etype (Expr))
1990 Is_Array_Type (Etype (Expr)))
1992 Set_Is_True_Constant (Entity (Expr), False);
1997 -- For a subprogram, freeze all parameter types and also the return
1998 -- type (RM 13.14(14)). However skip this for internal subprograms.
1999 -- This is also the point where any extra formal parameters are
2000 -- created since we now know whether the subprogram will use
2001 -- a foreign convention.
2003 if Is_Subprogram (E) then
2004 if not Is_Internal (E) then
2007 Warn_Node : Node_Id;
2009 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean;
2010 -- Determines if given type entity is a fat pointer type
2011 -- used as an argument type or return type to a subprogram
2012 -- with C or C++ convention set.
2014 --------------------------
2015 -- Is_Fat_C_Access_Type --
2016 --------------------------
2018 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is
2020 return (Convention (E) = Convention_C
2022 Convention (E) = Convention_CPP)
2023 and then Is_Access_Type (T)
2024 and then Esize (T) > Ttypes.System_Address_Size;
2025 end Is_Fat_C_Ptr_Type;
2028 -- Loop through formals
2030 Formal := First_Formal (E);
2031 while Present (Formal) loop
2032 F_Type := Etype (Formal);
2033 Freeze_And_Append (F_Type, Loc, Result);
2035 if Is_Private_Type (F_Type)
2036 and then Is_Private_Type (Base_Type (F_Type))
2037 and then No (Full_View (Base_Type (F_Type)))
2038 and then not Is_Generic_Type (F_Type)
2039 and then not Is_Derived_Type (F_Type)
2041 -- If the type of a formal is incomplete, subprogram
2042 -- is being frozen prematurely. Within an instance
2043 -- (but not within a wrapper package) this is an
2044 -- an artifact of our need to regard the end of an
2045 -- instantiation as a freeze point. Otherwise it is
2046 -- a definite error.
2048 -- and then not Is_Wrapper_Package (Current_Scope) ???
2051 Set_Is_Frozen (E, False);
2054 elsif not After_Last_Declaration then
2055 Error_Msg_Node_1 := F_Type;
2057 ("type& must be fully defined before this point",
2062 -- Check bad use of fat C pointer
2064 if Warn_On_Export_Import and then
2065 Is_Fat_C_Ptr_Type (F_Type)
2067 Error_Msg_Qual_Level := 1;
2069 ("?type of & does not correspond to C pointer",
2071 Error_Msg_Qual_Level := 0;
2074 -- Check for unconstrained array in exported foreign
2077 if Convention (E) in Foreign_Convention
2078 and then not Is_Imported (E)
2079 and then Is_Array_Type (F_Type)
2080 and then not Is_Constrained (F_Type)
2081 and then Warn_On_Export_Import
2083 Error_Msg_Qual_Level := 1;
2085 -- If this is an inherited operation, place the
2086 -- warning on the derived type declaration, rather
2087 -- than on the original subprogram.
2089 if Nkind (Original_Node (Parent (E))) =
2090 N_Full_Type_Declaration
2092 Warn_Node := Parent (E);
2094 if Formal = First_Formal (E) then
2096 ("?in inherited operation&!", Warn_Node, E);
2099 Warn_Node := Formal;
2103 ("?type of argument& is unconstrained array",
2106 ("?foreign caller must pass bounds explicitly",
2108 Error_Msg_Qual_Level := 0;
2111 Next_Formal (Formal);
2114 -- Check return type
2116 if Ekind (E) = E_Function then
2117 Freeze_And_Append (Etype (E), Loc, Result);
2119 if Warn_On_Export_Import
2120 and then Is_Fat_C_Ptr_Type (Etype (E))
2123 ("?return type of& does not correspond to C pointer",
2126 elsif Is_Array_Type (Etype (E))
2127 and then not Is_Constrained (Etype (E))
2128 and then not Is_Imported (E)
2129 and then Convention (E) in Foreign_Convention
2130 and then Warn_On_Export_Import
2133 ("?foreign convention function& should not " &
2134 "return unconstrained array", E);
2140 -- Must freeze its parent first if it is a derived subprogram
2142 if Present (Alias (E)) then
2143 Freeze_And_Append (Alias (E), Loc, Result);
2146 -- If the return type requires a transient scope, and we are on
2147 -- a target allowing functions to return with a depressed stack
2148 -- pointer, then we mark the function as requiring this treatment.
2150 if Ekind (E) = E_Function
2151 and then Functions_Return_By_DSP_On_Target
2152 and then Requires_Transient_Scope (Etype (E))
2154 Set_Function_Returns_With_DSP (E);
2157 if not Is_Internal (E) then
2158 Freeze_Subprogram (E);
2161 -- Here for other than a subprogram or type
2164 -- If entity has a type, and it is not a generic unit, then
2165 -- freeze it first (RM 13.14(10))
2167 if Present (Etype (E))
2168 and then Ekind (E) /= E_Generic_Function
2170 Freeze_And_Append (Etype (E), Loc, Result);
2173 -- For object created by object declaration, perform required
2174 -- categorization (preelaborate and pure) checks. Defer these
2175 -- checks to freeze time since pragma Import inhibits default
2176 -- initialization and thus pragma Import affects these checks.
2178 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
2179 Validate_Object_Declaration (Declaration_Node (E));
2180 Check_Address_Clause (E);
2183 -- Check that a constant which has a pragma Volatile[_Components]
2184 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
2186 -- Note: Atomic[_Components] also sets Volatile[_Components]
2188 if Ekind (E) = E_Constant
2189 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
2190 and then not Is_Imported (E)
2192 -- Make sure we actually have a pragma, and have not merely
2193 -- inherited the indication from elsewhere (e.g. an address
2194 -- clause, which is not good enough in RM terms!)
2196 if Present (Get_Rep_Pragma (E, Name_Atomic))
2198 Present (Get_Rep_Pragma (E, Name_Atomic_Components))
2201 ("stand alone atomic constant must be " &
2202 "imported ('R'M 'C.6(13))", E);
2204 elsif Present (Get_Rep_Pragma (E, Name_Volatile))
2206 Present (Get_Rep_Pragma (E, Name_Volatile_Components))
2209 ("stand alone volatile constant must be " &
2210 "imported ('R'M 'C.6(13))", E);
2214 -- Static objects require special handling
2216 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
2217 and then Is_Statically_Allocated (E)
2219 Freeze_Static_Object (E);
2222 -- Remaining step is to layout objects
2224 if Ekind (E) = E_Variable
2226 Ekind (E) = E_Constant
2228 Ekind (E) = E_Loop_Parameter
2236 -- Case of a type or subtype being frozen
2239 -- The type may be defined in a generic unit. This can occur when
2240 -- freezing a generic function that returns the type (which is
2241 -- defined in a parent unit). It is clearly meaningless to freeze
2242 -- this type. However, if it is a subtype, its size may be determi-
2243 -- nable and used in subsequent checks, so might as well try to
2246 if Present (Scope (E))
2247 and then Is_Generic_Unit (Scope (E))
2249 Check_Compile_Time_Size (E);
2253 -- Deal with special cases of freezing for subtype
2255 if E /= Base_Type (E) then
2257 -- If ancestor subtype present, freeze that first.
2258 -- Note that this will also get the base type frozen.
2260 Atype := Ancestor_Subtype (E);
2262 if Present (Atype) then
2263 Freeze_And_Append (Atype, Loc, Result);
2265 -- Otherwise freeze the base type of the entity before
2266 -- freezing the entity itself, (RM 13.14(15)).
2268 elsif E /= Base_Type (E) then
2269 Freeze_And_Append (Base_Type (E), Loc, Result);
2272 -- For a derived type, freeze its parent type first (RM 13.14(15))
2274 elsif Is_Derived_Type (E) then
2275 Freeze_And_Append (Etype (E), Loc, Result);
2276 Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
2279 -- For array type, freeze index types and component type first
2280 -- before freezing the array (RM 13.14(15)).
2282 if Is_Array_Type (E) then
2284 Ctyp : constant Entity_Id := Component_Type (E);
2287 Non_Standard_Enum : Boolean := False;
2288 -- Set true if any of the index types is an enumeration
2289 -- type with a non-standard representation.
2292 Freeze_And_Append (Ctyp, Loc, Result);
2294 Indx := First_Index (E);
2295 while Present (Indx) loop
2296 Freeze_And_Append (Etype (Indx), Loc, Result);
2298 if Is_Enumeration_Type (Etype (Indx))
2299 and then Has_Non_Standard_Rep (Etype (Indx))
2301 Non_Standard_Enum := True;
2307 -- Processing that is done only for base types
2309 if Ekind (E) = E_Array_Type then
2311 -- Propagate flags for component type
2313 if Is_Controlled (Component_Type (E))
2314 or else Has_Controlled_Component (Ctyp)
2316 Set_Has_Controlled_Component (E);
2319 if Has_Unchecked_Union (Component_Type (E)) then
2320 Set_Has_Unchecked_Union (E);
2323 -- If packing was requested or if the component size was set
2324 -- explicitly, then see if bit packing is required. This
2325 -- processing is only done for base types, since all the
2326 -- representation aspects involved are type-related. This
2327 -- is not just an optimization, if we start processing the
2328 -- subtypes, they intefere with the settings on the base
2329 -- type (this is because Is_Packed has a slightly different
2330 -- meaning before and after freezing).
2337 if (Is_Packed (E) or else Has_Pragma_Pack (E))
2338 and then not Has_Atomic_Components (E)
2339 and then Known_Static_RM_Size (Ctyp)
2341 Csiz := UI_Max (RM_Size (Ctyp), 1);
2343 elsif Known_Component_Size (E) then
2344 Csiz := Component_Size (E);
2346 elsif not Known_Static_Esize (Ctyp) then
2350 Esiz := Esize (Ctyp);
2352 -- We can set the component size if it is less than
2353 -- 16, rounding it up to the next storage unit size.
2357 elsif Esiz <= 16 then
2363 -- Set component size up to match alignment if
2364 -- it would otherwise be less than the alignment.
2365 -- This deals with cases of types whose alignment
2366 -- exceeds their sizes (padded types).
2370 A : constant Uint := Alignment_In_Bits (Ctyp);
2381 if 1 <= Csiz and then Csiz <= 64 then
2383 -- We set the component size for all cases 1-64
2385 Set_Component_Size (Base_Type (E), Csiz);
2387 -- Check for base type of 8,16,32 bits, where the
2388 -- subtype has a length one less than the base type
2389 -- and is unsigned (e.g. Natural subtype of Integer)
2391 -- In such cases, if a component size was not set
2392 -- explicitly, then generate a warning.
2394 if Has_Pragma_Pack (E)
2395 and then not Has_Component_Size_Clause (E)
2397 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
2398 and then Esize (Base_Type (Ctyp)) = Csiz + 1
2400 Error_Msg_Uint_1 := Csiz;
2402 Get_Rep_Pragma (First_Subtype (E), Name_Pack);
2404 if Present (Pnod) then
2406 ("pragma Pack causes component size to be ^?",
2409 ("\use Component_Size to set desired value",
2414 -- Actual packing is not needed for 8,16,32,64
2415 -- Also not needed for 24 if alignment is 1
2421 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
2423 -- Here the array was requested to be packed, but
2424 -- the packing request had no effect, so Is_Packed
2427 -- Note: semantically this means that we lose
2428 -- track of the fact that a derived type inherited
2429 -- a pack pragma that was non-effective, but that
2432 -- We regard a Pack pragma as a request to set a
2433 -- representation characteristic, and this request
2436 Set_Is_Packed (Base_Type (E), False);
2438 -- In all other cases, packing is indeed needed
2441 Set_Has_Non_Standard_Rep (Base_Type (E));
2442 Set_Is_Bit_Packed_Array (Base_Type (E));
2443 Set_Is_Packed (Base_Type (E));
2448 -- Processing that is done only for subtypes
2451 -- Acquire alignment from base type
2453 if Unknown_Alignment (E) then
2454 Set_Alignment (E, Alignment (Base_Type (E)));
2458 -- For bit-packed arrays, check the size
2460 if Is_Bit_Packed_Array (E)
2461 and then Known_Esize (E)
2465 SizC : constant Node_Id := Size_Clause (E);
2468 -- It is not clear if it is possible to have no size
2469 -- clause at this stage, but this is not worth worrying
2470 -- about. Post the error on the entity name in the size
2471 -- clause if present, else on the type entity itself.
2473 if Present (SizC) then
2474 Check_Size (Name (SizC), E, Esize (E), Discard);
2476 Check_Size (E, E, Esize (E), Discard);
2481 -- Check one common case of a size given where the array
2482 -- needs to be packed, but was not so the size cannot be
2483 -- honored. This would of course be caught by the backend,
2484 -- and indeed we don't catch all cases. The point is that
2485 -- we can give a better error message in those cases that
2486 -- we do catch with the circuitry here.
2490 Ctyp : constant Entity_Id := Component_Type (E);
2493 if Present (Size_Clause (E))
2494 and then Known_Static_Esize (E)
2495 and then not Is_Bit_Packed_Array (E)
2496 and then not Has_Pragma_Pack (E)
2497 and then Number_Dimensions (E) = 1
2498 and then not Has_Component_Size_Clause (E)
2499 and then Known_Static_Esize (Ctyp)
2501 Get_Index_Bounds (First_Index (E), Lo, Hi);
2503 if Compile_Time_Known_Value (Lo)
2504 and then Compile_Time_Known_Value (Hi)
2505 and then Known_Static_RM_Size (Ctyp)
2506 and then RM_Size (Ctyp) < 64
2509 Lov : constant Uint := Expr_Value (Lo);
2510 Hiv : constant Uint := Expr_Value (Hi);
2511 Len : constant Uint :=
2512 UI_Max (Uint_0, Hiv - Lov + 1);
2513 Rsiz : constant Uint := RM_Size (Ctyp);
2515 -- What we are looking for here is the situation
2516 -- where the Esize given would be exactly right
2517 -- if there was a pragma Pack (resulting in the
2518 -- component size being the same as the RM_Size).
2519 -- Furthermore, the component type size must be
2520 -- an odd size (not a multiple of storage unit)
2523 if Esize (E) = Len * Rsiz
2524 and then Rsiz mod System_Storage_Unit /= 0
2527 ("size given for& too small",
2528 Size_Clause (E), E);
2530 ("\explicit pragma Pack is required",
2538 -- If any of the index types was an enumeration type with
2539 -- a non-standard rep clause, then we indicate that the
2540 -- array type is always packed (even if it is not bit packed).
2542 if Non_Standard_Enum then
2543 Set_Has_Non_Standard_Rep (Base_Type (E));
2544 Set_Is_Packed (Base_Type (E));
2548 Set_Component_Alignment_If_Not_Set (E);
2550 -- If the array is packed, we must create the packed array
2551 -- type to be used to actually implement the type. This is
2552 -- only needed for real array types (not for string literal
2553 -- types, since they are present only for the front end).
2556 and then Ekind (E) /= E_String_Literal_Subtype
2558 Create_Packed_Array_Type (E);
2559 Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
2561 -- Size information of packed array type is copied to the
2562 -- array type, since this is really the representation.
2564 Set_Size_Info (E, Packed_Array_Type (E));
2565 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
2568 -- For a class-wide type, the corresponding specific type is
2569 -- frozen as well (RM 13.14(15))
2571 elsif Is_Class_Wide_Type (E) then
2572 Freeze_And_Append (Root_Type (E), Loc, Result);
2574 -- If the Class_Wide_Type is an Itype (when type is the anonymous
2575 -- parent of a derived type) and it is a library-level entity,
2576 -- generate an itype reference for it. Otherwise, its first
2577 -- explicit reference may be in an inner scope, which will be
2578 -- rejected by the back-end.
2581 and then Is_Compilation_Unit (Scope (E))
2584 Ref : constant Node_Id := Make_Itype_Reference (Loc);
2589 Result := New_List (Ref);
2591 Append (Ref, Result);
2596 -- The equivalent type associated with a class-wide subtype
2597 -- needs to be frozen to ensure that its layout is done.
2598 -- Class-wide subtypes are currently only frozen on targets
2599 -- requiring front-end layout (see New_Class_Wide_Subtype
2600 -- and Make_CW_Equivalent_Type in exp_util.adb).
2602 if Ekind (E) = E_Class_Wide_Subtype
2603 and then Present (Equivalent_Type (E))
2605 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2608 -- For a record (sub)type, freeze all the component types (RM
2609 -- 13.14(15). We test for E_Record_(sub)Type here, rather than
2610 -- using Is_Record_Type, because we don't want to attempt the
2611 -- freeze for the case of a private type with record extension
2612 -- (we will do that later when the full type is frozen).
2614 elsif Ekind (E) = E_Record_Type
2615 or else Ekind (E) = E_Record_Subtype
2617 Freeze_Record_Type (E);
2619 -- For a concurrent type, freeze corresponding record type. This
2620 -- does not correpond to any specific rule in the RM, but the
2621 -- record type is essentially part of the concurrent type.
2622 -- Freeze as well all local entities. This includes record types
2623 -- created for entry parameter blocks, and whatever local entities
2624 -- may appear in the private part.
2626 elsif Is_Concurrent_Type (E) then
2627 if Present (Corresponding_Record_Type (E)) then
2629 (Corresponding_Record_Type (E), Loc, Result);
2632 Comp := First_Entity (E);
2634 while Present (Comp) loop
2635 if Is_Type (Comp) then
2636 Freeze_And_Append (Comp, Loc, Result);
2638 elsif (Ekind (Comp)) /= E_Function then
2639 Freeze_And_Append (Etype (Comp), Loc, Result);
2645 -- Private types are required to point to the same freeze node
2646 -- as their corresponding full views. The freeze node itself
2647 -- has to point to the partial view of the entity (because
2648 -- from the partial view, we can retrieve the full view, but
2649 -- not the reverse). However, in order to freeze correctly,
2650 -- we need to freeze the full view. If we are freezing at the
2651 -- end of a scope (or within the scope of the private type),
2652 -- the partial and full views will have been swapped, the
2653 -- full view appears first in the entity chain and the swapping
2654 -- mechanism ensures that the pointers are properly set (on
2657 -- If we encounter the partial view before the full view
2658 -- (e.g. when freezing from another scope), we freeze the
2659 -- full view, and then set the pointers appropriately since
2660 -- we cannot rely on swapping to fix things up (subtypes in an
2661 -- outer scope might not get swapped).
2663 elsif Is_Incomplete_Or_Private_Type (E)
2664 and then not Is_Generic_Type (E)
2666 -- Case of full view present
2668 if Present (Full_View (E)) then
2670 -- If full view has already been frozen, then no
2671 -- further processing is required
2673 if Is_Frozen (Full_View (E)) then
2675 Set_Has_Delayed_Freeze (E, False);
2676 Set_Freeze_Node (E, Empty);
2677 Check_Debug_Info_Needed (E);
2679 -- Otherwise freeze full view and patch the pointers
2680 -- so that the freeze node will elaborate both views
2685 Full : constant Entity_Id := Full_View (E);
2688 if Is_Private_Type (Full)
2689 and then Present (Underlying_Full_View (Full))
2692 (Underlying_Full_View (Full), Loc, Result);
2695 Freeze_And_Append (Full, Loc, Result);
2697 if Has_Delayed_Freeze (E) then
2698 F_Node := Freeze_Node (Full);
2700 if Present (F_Node) then
2701 Set_Freeze_Node (E, F_Node);
2702 Set_Entity (F_Node, E);
2705 -- {Incomplete,Private}_Subtypes
2706 -- with Full_Views constrained by discriminants
2708 Set_Has_Delayed_Freeze (E, False);
2709 Set_Freeze_Node (E, Empty);
2714 Check_Debug_Info_Needed (E);
2717 -- AI-117 requires that the convention of a partial view
2718 -- be the same as the convention of the full view. Note
2719 -- that this is a recognized breach of privacy, but it's
2720 -- essential for logical consistency of representation,
2721 -- and the lack of a rule in RM95 was an oversight.
2723 Set_Convention (E, Convention (Full_View (E)));
2725 Set_Size_Known_At_Compile_Time (E,
2726 Size_Known_At_Compile_Time (Full_View (E)));
2728 -- Size information is copied from the full view to the
2729 -- incomplete or private view for consistency
2731 -- We skip this is the full view is not a type. This is
2732 -- very strange of course, and can only happen as a result
2733 -- of certain illegalities, such as a premature attempt to
2734 -- derive from an incomplete type.
2736 if Is_Type (Full_View (E)) then
2737 Set_Size_Info (E, Full_View (E));
2738 Set_RM_Size (E, RM_Size (Full_View (E)));
2743 -- Case of no full view present. If entity is derived or subtype,
2744 -- it is safe to freeze, correctness depends on the frozen status
2745 -- of parent. Otherwise it is either premature usage, or a Taft
2746 -- amendment type, so diagnosis is at the point of use and the
2747 -- type might be frozen later.
2749 elsif E /= Base_Type (E)
2750 or else Is_Derived_Type (E)
2755 Set_Is_Frozen (E, False);
2759 -- For access subprogram, freeze types of all formals, the return
2760 -- type was already frozen, since it is the Etype of the function.
2762 elsif Ekind (E) = E_Subprogram_Type then
2763 Formal := First_Formal (E);
2764 while Present (Formal) loop
2765 Freeze_And_Append (Etype (Formal), Loc, Result);
2766 Next_Formal (Formal);
2769 -- If the return type requires a transient scope, and we are on
2770 -- a target allowing functions to return with a depressed stack
2771 -- pointer, then we mark the function as requiring this treatment.
2773 if Functions_Return_By_DSP_On_Target
2774 and then Requires_Transient_Scope (Etype (E))
2776 Set_Function_Returns_With_DSP (E);
2779 Freeze_Subprogram (E);
2781 -- For access to a protected subprogram, freeze the equivalent
2782 -- type (however this is not set if we are not generating code)
2783 -- or if this is an anonymous type used just for resolution).
2785 elsif Ekind (E) = E_Access_Protected_Subprogram_Type
2786 and then Operating_Mode = Generate_Code
2787 and then Present (Equivalent_Type (E))
2789 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2792 -- Generic types are never seen by the back-end, and are also not
2793 -- processed by the expander (since the expander is turned off for
2794 -- generic processing), so we never need freeze nodes for them.
2796 if Is_Generic_Type (E) then
2800 -- Some special processing for non-generic types to complete
2801 -- representation details not known till the freeze point.
2803 if Is_Fixed_Point_Type (E) then
2804 Freeze_Fixed_Point_Type (E);
2806 -- Some error checks required for ordinary fixed-point type.
2807 -- Defer these till the freeze-point since we need the small
2808 -- and range values. We only do these checks for base types
2810 if Is_Ordinary_Fixed_Point_Type (E)
2811 and then E = Base_Type (E)
2813 if Small_Value (E) < Ureal_2_M_80 then
2814 Error_Msg_Name_1 := Name_Small;
2816 ("`&''%` is too small, minimum is 2.0'*'*(-80)", E);
2818 elsif Small_Value (E) > Ureal_2_80 then
2819 Error_Msg_Name_1 := Name_Small;
2821 ("`&''%` is too large, maximum is 2.0'*'*80", E);
2824 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
2825 Error_Msg_Name_1 := Name_First;
2827 ("`&''%` is too small, minimum is -10.0'*'*36", E);
2830 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
2831 Error_Msg_Name_1 := Name_Last;
2833 ("`&''%` is too large, maximum is 10.0'*'*36", E);
2837 elsif Is_Enumeration_Type (E) then
2838 Freeze_Enumeration_Type (E);
2840 elsif Is_Integer_Type (E) then
2841 Adjust_Esize_For_Alignment (E);
2843 elsif Is_Access_Type (E)
2844 and then No (Associated_Storage_Pool (E))
2846 Check_Restriction (No_Standard_Storage_Pools, E);
2849 -- If the current entity is an array or record subtype and has
2850 -- discriminants used to constrain it, it must not freeze, because
2851 -- Freeze_Entity nodes force Gigi to process the frozen type.
2853 if Is_Composite_Type (E) then
2855 if Is_Array_Type (E) then
2857 Index : Node_Id := First_Index (E);
2862 while Present (Index) loop
2863 if Etype (Index) /= Any_Type then
2864 Get_Index_Bounds (Index, Expr1, Expr2);
2866 for J in 1 .. 2 loop
2867 if Nkind (Expr1) = N_Identifier
2868 and then Ekind (Entity (Expr1)) = E_Discriminant
2870 Set_Has_Delayed_Freeze (E, False);
2871 Set_Freeze_Node (E, Empty);
2872 Check_Debug_Info_Needed (E);
2884 elsif Has_Discriminants (E)
2885 and Is_Constrained (E)
2888 Constraint : Elmt_Id;
2892 Constraint := First_Elmt (Discriminant_Constraint (E));
2893 while Present (Constraint) loop
2894 Expr := Node (Constraint);
2895 if Nkind (Expr) = N_Identifier
2896 and then Ekind (Entity (Expr)) = E_Discriminant
2898 Set_Has_Delayed_Freeze (E, False);
2899 Set_Freeze_Node (E, Empty);
2900 Check_Debug_Info_Needed (E);
2904 Next_Elmt (Constraint);
2909 -- AI-117 requires that all new primitives of a tagged type
2910 -- must inherit the convention of the full view of the type.
2911 -- Inherited and overriding operations are defined to inherit
2912 -- the convention of their parent or overridden subprogram
2913 -- (also specified in AI-117), and that will have occurred
2914 -- earlier (in Derive_Subprogram and New_Overloaded_Entity).
2915 -- Here we set the convention of primitives that are still
2916 -- convention Ada, which will ensure that any new primitives
2917 -- inherit the type's convention. Class-wide types can have
2918 -- a foreign convention inherited from their specific type,
2919 -- but are excluded from this since they don't have any
2920 -- associated primitives.
2922 if Is_Tagged_Type (E)
2923 and then not Is_Class_Wide_Type (E)
2924 and then Convention (E) /= Convention_Ada
2927 Prim_List : constant Elist_Id := Primitive_Operations (E);
2930 Prim := First_Elmt (Prim_List);
2931 while Present (Prim) loop
2932 if Convention (Node (Prim)) = Convention_Ada then
2933 Set_Convention (Node (Prim), Convention (E));
2942 -- Generate primitive operation references for a tagged type
2944 if Is_Tagged_Type (E)
2945 and then not Is_Class_Wide_Type (E)
2948 Prim_List : constant Elist_Id := Primitive_Operations (E);
2953 Prim := First_Elmt (Prim_List);
2954 while Present (Prim) loop
2957 -- If the operation is derived, get the original for
2958 -- cross-reference purposes (it is the original for
2959 -- which we want the xref, and for which the comes
2960 -- from source test needs to be performed).
2962 while Present (Alias (Ent)) loop
2966 Generate_Reference (E, Ent, 'p', Set_Ref => False);
2970 -- If we get an exception, then something peculiar has happened
2971 -- probably as a result of a previous error. Since this is only
2972 -- for non-critical cross-references, ignore the error.
2975 when others => null;
2979 -- Now that all types from which E may depend are frozen, see
2980 -- if the size is known at compile time, if it must be unsigned,
2981 -- or if strict alignent is required
2983 Check_Compile_Time_Size (E);
2984 Check_Unsigned_Type (E);
2986 if Base_Type (E) = E then
2987 Check_Strict_Alignment (E);
2990 -- Do not allow a size clause for a type which does not have a size
2991 -- that is known at compile time
2993 if Has_Size_Clause (E)
2994 and then not Size_Known_At_Compile_Time (E)
2996 -- Supress this message if errors posted on E, even if we are
2997 -- in all errors mode, since this is often a junk message
2999 if not Error_Posted (E) then
3001 ("size clause not allowed for variable length type",
3006 -- Remaining process is to set/verify the representation information,
3007 -- in particular the size and alignment values. This processing is
3008 -- not required for generic types, since generic types do not play
3009 -- any part in code generation, and so the size and alignment values
3010 -- for suhc types are irrelevant.
3012 if Is_Generic_Type (E) then
3015 -- Otherwise we call the layout procedure
3021 -- End of freeze processing for type entities
3024 -- Here is where we logically freeze the current entity. If it has a
3025 -- freeze node, then this is the point at which the freeze node is
3026 -- linked into the result list.
3028 if Has_Delayed_Freeze (E) then
3030 -- If a freeze node is already allocated, use it, otherwise allocate
3031 -- a new one. The preallocation happens in the case of anonymous base
3032 -- types, where we preallocate so that we can set First_Subtype_Link.
3033 -- Note that we reset the Sloc to the current freeze location.
3035 if Present (Freeze_Node (E)) then
3036 F_Node := Freeze_Node (E);
3037 Set_Sloc (F_Node, Loc);
3040 F_Node := New_Node (N_Freeze_Entity, Loc);
3041 Set_Freeze_Node (E, F_Node);
3042 Set_Access_Types_To_Process (F_Node, No_Elist);
3043 Set_TSS_Elist (F_Node, No_Elist);
3044 Set_Actions (F_Node, No_List);
3047 Set_Entity (F_Node, E);
3049 if Result = No_List then
3050 Result := New_List (F_Node);
3052 Append (F_Node, Result);
3056 -- When a type is frozen, the first subtype of the type is frozen as
3057 -- well (RM 13.14(15)). This has to be done after freezing the type,
3058 -- since obviously the first subtype depends on its own base type.
3061 Freeze_And_Append (First_Subtype (E), Loc, Result);
3063 -- If we just froze a tagged non-class wide record, then freeze the
3064 -- corresponding class-wide type. This must be done after the tagged
3065 -- type itself is frozen, because the class-wide type refers to the
3066 -- tagged type which generates the class.
3068 if Is_Tagged_Type (E)
3069 and then not Is_Class_Wide_Type (E)
3070 and then Present (Class_Wide_Type (E))
3072 Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
3076 Check_Debug_Info_Needed (E);
3078 -- Special handling for subprograms
3080 if Is_Subprogram (E) then
3082 -- If subprogram has address clause then reset Is_Public flag, since
3083 -- we do not want the backend to generate external references.
3085 if Present (Address_Clause (E))
3086 and then not Is_Library_Level_Entity (E)
3088 Set_Is_Public (E, False);
3090 -- If no address clause and not intrinsic, then for imported
3091 -- subprogram in main unit, generate descriptor if we are in
3092 -- Propagate_Exceptions mode.
3094 elsif Propagate_Exceptions
3095 and then Is_Imported (E)
3096 and then not Is_Intrinsic_Subprogram (E)
3097 and then Convention (E) /= Convention_Stubbed
3099 if Result = No_List then
3100 Result := Empty_List;
3103 Generate_Subprogram_Descriptor_For_Imported_Subprogram
3111 -----------------------------
3112 -- Freeze_Enumeration_Type --
3113 -----------------------------
3115 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
3117 if Has_Foreign_Convention (Typ)
3118 and then not Has_Size_Clause (Typ)
3119 and then Esize (Typ) < Standard_Integer_Size
3121 Init_Esize (Typ, Standard_Integer_Size);
3123 Adjust_Esize_For_Alignment (Typ);
3125 end Freeze_Enumeration_Type;
3127 -----------------------
3128 -- Freeze_Expression --
3129 -----------------------
3131 procedure Freeze_Expression (N : Node_Id) is
3132 In_Def_Exp : constant Boolean := In_Default_Expression;
3135 Desig_Typ : Entity_Id;
3139 Freeze_Outside : Boolean := False;
3140 -- This flag is set true if the entity must be frozen outside the
3141 -- current subprogram. This happens in the case of expander generated
3142 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
3143 -- not freeze all entities like other bodies, but which nevertheless
3144 -- may reference entities that have to be frozen before the body and
3145 -- obviously cannot be frozen inside the body.
3147 function In_Exp_Body (N : Node_Id) return Boolean;
3148 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
3149 -- it is the handled statement sequence of an expander generated
3150 -- subprogram (init proc, or stream subprogram). If so, it returns
3151 -- True, otherwise False.
3157 function In_Exp_Body (N : Node_Id) return Boolean is
3161 if Nkind (N) = N_Subprogram_Body then
3167 if Nkind (P) /= N_Subprogram_Body then
3171 P := Defining_Unit_Name (Specification (P));
3173 if Nkind (P) = N_Defining_Identifier
3174 and then (Is_Init_Proc (P) or else
3175 Is_TSS (P, TSS_Stream_Input) or else
3176 Is_TSS (P, TSS_Stream_Output) or else
3177 Is_TSS (P, TSS_Stream_Read) or else
3178 Is_TSS (P, TSS_Stream_Write))
3187 -- Start of processing for Freeze_Expression
3190 -- Immediate return if freezing is inhibited. This flag is set by
3191 -- the analyzer to stop freezing on generated expressions that would
3192 -- cause freezing if they were in the source program, but which are
3193 -- not supposed to freeze, since they are created.
3195 if Must_Not_Freeze (N) then
3199 -- If expression is non-static, then it does not freeze in a default
3200 -- expression, see section "Handling of Default Expressions" in the
3201 -- spec of package Sem for further details. Note that we have to
3202 -- make sure that we actually have a real expression (if we have
3203 -- a subtype indication, we can't test Is_Static_Expression!)
3206 and then Nkind (N) in N_Subexpr
3207 and then not Is_Static_Expression (N)
3212 -- Freeze type of expression if not frozen already
3216 if Nkind (N) in N_Has_Etype then
3217 if not Is_Frozen (Etype (N)) then
3220 -- Base type may be an derived numeric type that is frozen at
3221 -- the point of declaration, but first_subtype is still unfrozen.
3223 elsif not Is_Frozen (First_Subtype (Etype (N))) then
3224 Typ := First_Subtype (Etype (N));
3228 -- For entity name, freeze entity if not frozen already. A special
3229 -- exception occurs for an identifier that did not come from source.
3230 -- We don't let such identifiers freeze a non-internal entity, i.e.
3231 -- an entity that did come from source, since such an identifier was
3232 -- generated by the expander, and cannot have any semantic effect on
3233 -- the freezing semantics. For example, this stops the parameter of
3234 -- an initialization procedure from freezing the variable.
3236 if Is_Entity_Name (N)
3237 and then not Is_Frozen (Entity (N))
3238 and then (Nkind (N) /= N_Identifier
3239 or else Comes_From_Source (N)
3240 or else not Comes_From_Source (Entity (N)))
3247 -- For an allocator freeze designated type if not frozen already.
3249 -- For an aggregate whose component type is an access type, freeze
3250 -- the designated type now, so that its freeze does not appear within
3251 -- the loop that might be created in the expansion of the aggregate.
3252 -- If the designated type is a private type without full view, the
3253 -- expression cannot contain an allocator, so the type is not frozen.
3259 Desig_Typ := Designated_Type (Etype (N));
3262 if Is_Array_Type (Etype (N))
3263 and then Is_Access_Type (Component_Type (Etype (N)))
3265 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
3268 when N_Selected_Component |
3269 N_Indexed_Component |
3272 if Is_Access_Type (Etype (Prefix (N))) then
3273 Desig_Typ := Designated_Type (Etype (Prefix (N)));
3280 if Desig_Typ /= Empty
3281 and then (Is_Frozen (Desig_Typ)
3282 or else (not Is_Fully_Defined (Desig_Typ)))
3287 -- All done if nothing needs freezing
3291 and then No (Desig_Typ)
3296 -- Loop for looking at the right place to insert the freeze nodes
3297 -- exiting from the loop when it is appropriate to insert the freeze
3298 -- node before the current node P.
3300 -- Also checks some special exceptions to the freezing rules. These
3301 -- cases result in a direct return, bypassing the freeze action.
3305 Parent_P := Parent (P);
3307 -- If we don't have a parent, then we are not in a well-formed
3308 -- tree. This is an unusual case, but there are some legitimate
3309 -- situations in which this occurs, notably when the expressions
3310 -- in the range of a type declaration are resolved. We simply
3311 -- ignore the freeze request in this case. Is this right ???
3313 if No (Parent_P) then
3317 -- See if we have got to an appropriate point in the tree
3319 case Nkind (Parent_P) is
3321 -- A special test for the exception of (RM 13.14(8)) for the
3322 -- case of per-object expressions (RM 3.8(18)) occurring in a
3323 -- component definition or a discrete subtype definition. Note
3324 -- that we test for a component declaration which includes both
3325 -- cases we are interested in, and furthermore the tree does not
3326 -- have explicit nodes for either of these two constructs.
3328 when N_Component_Declaration =>
3330 -- The case we want to test for here is an identifier that is
3331 -- a per-object expression, this is either a discriminant that
3332 -- appears in a context other than the component declaration
3333 -- or it is a reference to the type of the enclosing construct.
3335 -- For either of these cases, we skip the freezing
3337 if not In_Default_Expression
3338 and then Nkind (N) = N_Identifier
3339 and then (Present (Entity (N)))
3341 -- We recognize the discriminant case by just looking for
3342 -- a reference to a discriminant. It can only be one for
3343 -- the enclosing construct. Skip freezing in this case.
3345 if Ekind (Entity (N)) = E_Discriminant then
3348 -- For the case of a reference to the enclosing record,
3349 -- (or task or protected type), we look for a type that
3350 -- matches the current scope.
3352 elsif Entity (N) = Current_Scope then
3357 -- If we have an enumeration literal that appears as the
3358 -- choice in the aggregate of an enumeration representation
3359 -- clause, then freezing does not occur (RM 13.14(10)).
3361 when N_Enumeration_Representation_Clause =>
3363 -- The case we are looking for is an enumeration literal
3365 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
3366 and then Is_Enumeration_Type (Etype (N))
3368 -- If enumeration literal appears directly as the choice,
3369 -- do not freeze (this is the normal non-overloade case)
3371 if Nkind (Parent (N)) = N_Component_Association
3372 and then First (Choices (Parent (N))) = N
3376 -- If enumeration literal appears as the name of a
3377 -- function which is the choice, then also do not freeze.
3378 -- This happens in the overloaded literal case, where the
3379 -- enumeration literal is temporarily changed to a function
3380 -- call for overloading analysis purposes.
3382 elsif Nkind (Parent (N)) = N_Function_Call
3384 Nkind (Parent (Parent (N))) = N_Component_Association
3386 First (Choices (Parent (Parent (N)))) = Parent (N)
3392 -- Normally if the parent is a handled sequence of statements,
3393 -- then the current node must be a statement, and that is an
3394 -- appropriate place to insert a freeze node.
3396 when N_Handled_Sequence_Of_Statements =>
3398 -- An exception occurs when the sequence of statements is
3399 -- for an expander generated body that did not do the usual
3400 -- freeze all operation. In this case we usually want to
3401 -- freeze outside this body, not inside it, and we skip
3402 -- past the subprogram body that we are inside.
3404 if In_Exp_Body (Parent_P) then
3406 -- However, we *do* want to freeze at this point if we have
3407 -- an entity to freeze, and that entity is declared *inside*
3408 -- the body of the expander generated procedure. This case
3409 -- is recognized by the scope of the type, which is either
3410 -- the spec for some enclosing body, or (in the case of
3411 -- init_procs, for which there are no separate specs) the
3415 Subp : constant Node_Id := Parent (Parent_P);
3419 if Nkind (Subp) = N_Subprogram_Body then
3420 Cspc := Corresponding_Spec (Subp);
3422 if (Present (Typ) and then Scope (Typ) = Cspc)
3424 (Present (Nam) and then Scope (Nam) = Cspc)
3429 and then Scope (Typ) = Current_Scope
3430 and then Current_Scope = Defining_Entity (Subp)
3437 -- If not that exception to the exception, then this is
3438 -- where we delay the freeze till outside the body.
3440 Parent_P := Parent (Parent_P);
3441 Freeze_Outside := True;
3443 -- Here if normal case where we are in handled statement
3444 -- sequence and want to do the insertion right there.
3450 -- If parent is a body or a spec or a block, then the current
3451 -- node is a statement or declaration and we can insert the
3452 -- freeze node before it.
3454 when N_Package_Specification |
3460 N_Block_Statement => exit;
3462 -- The expander is allowed to define types in any statements list,
3463 -- so any of the following parent nodes also mark a freezing point
3464 -- if the actual node is in a list of statements or declarations.
3466 when N_Exception_Handler |
3469 N_Case_Statement_Alternative |
3470 N_Compilation_Unit_Aux |
3471 N_Selective_Accept |
3472 N_Accept_Alternative |
3473 N_Delay_Alternative |
3474 N_Conditional_Entry_Call |
3475 N_Entry_Call_Alternative |
3476 N_Triggering_Alternative |
3480 exit when Is_List_Member (P);
3482 -- Note: The N_Loop_Statement is a special case. A type that
3483 -- appears in the source can never be frozen in a loop (this
3484 -- occurs only because of a loop expanded by the expander),
3485 -- so we keep on going. Otherwise we terminate the search.
3486 -- Same is true of any entity which comes from source. (if they
3487 -- have a predefined type, that type does not appear to come
3488 -- from source, but the entity should not be frozen here).
3490 when N_Loop_Statement =>
3491 exit when not Comes_From_Source (Etype (N))
3492 and then (No (Nam) or else not Comes_From_Source (Nam));
3494 -- For all other cases, keep looking at parents
3500 -- We fall through the case if we did not yet find the proper
3501 -- place in the free for inserting the freeze node, so climb!
3506 -- If the expression appears in a record or an initialization
3507 -- procedure, the freeze nodes are collected and attached to
3508 -- the current scope, to be inserted and analyzed on exit from
3509 -- the scope, to insure that generated entities appear in the
3510 -- correct scope. If the expression is a default for a discriminant
3511 -- specification, the scope is still void. The expression can also
3512 -- appear in the discriminant part of a private or concurrent type.
3514 -- The other case requiring this special handling is if we are in
3515 -- a default expression, since in that case we are about to freeze
3516 -- a static type, and the freeze scope needs to be the outer scope,
3517 -- not the scope of the subprogram with the default parameter.
3519 -- For default expressions in generic units, the Move_Freeze_Nodes
3520 -- mechanism (see sem_ch12.adb) takes care of placing them at the
3521 -- proper place, after the generic unit.
3523 if (In_Def_Exp and not Inside_A_Generic)
3524 or else Freeze_Outside
3525 or else (Is_Type (Current_Scope)
3526 and then (not Is_Concurrent_Type (Current_Scope)
3527 or else not Has_Completion (Current_Scope)))
3528 or else Ekind (Current_Scope) = E_Void
3531 Loc : constant Source_Ptr := Sloc (Current_Scope);
3532 Freeze_Nodes : List_Id := No_List;
3535 if Present (Desig_Typ) then
3536 Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
3539 if Present (Typ) then
3540 Freeze_And_Append (Typ, Loc, Freeze_Nodes);
3543 if Present (Nam) then
3544 Freeze_And_Append (Nam, Loc, Freeze_Nodes);
3547 if Is_Non_Empty_List (Freeze_Nodes) then
3548 if No (Scope_Stack.Table
3549 (Scope_Stack.Last).Pending_Freeze_Actions)
3552 (Scope_Stack.Last).Pending_Freeze_Actions :=
3555 Append_List (Freeze_Nodes, Scope_Stack.Table
3556 (Scope_Stack.Last).Pending_Freeze_Actions);
3564 -- Now we have the right place to do the freezing. First, a special
3565 -- adjustment, if we are in default expression analysis mode, these
3566 -- freeze actions must not be thrown away (normally all inserted
3567 -- actions are thrown away in this mode. However, the freeze actions
3568 -- are from static expressions and one of the important reasons we
3569 -- are doing this special analysis is to get these freeze actions.
3570 -- Therefore we turn off the In_Default_Expression mode to propagate
3571 -- these freeze actions. This also means they get properly analyzed
3574 In_Default_Expression := False;
3576 -- Freeze the designated type of an allocator (RM 13.14(13))
3578 if Present (Desig_Typ) then
3579 Freeze_Before (P, Desig_Typ);
3582 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
3583 -- the enumeration representation clause exception in the loop above.
3585 if Present (Typ) then
3586 Freeze_Before (P, Typ);
3589 -- Freeze name if one is present (RM 13.14(11))
3591 if Present (Nam) then
3592 Freeze_Before (P, Nam);
3595 In_Default_Expression := In_Def_Exp;
3596 end Freeze_Expression;
3598 -----------------------------
3599 -- Freeze_Fixed_Point_Type --
3600 -----------------------------
3602 -- Certain fixed-point types and subtypes, including implicit base
3603 -- types and declared first subtypes, have not yet set up a range.
3604 -- This is because the range cannot be set until the Small and Size
3605 -- values are known, and these are not known till the type is frozen.
3607 -- To signal this case, Scalar_Range contains an unanalyzed syntactic
3608 -- range whose bounds are unanalyzed real literals. This routine will
3609 -- recognize this case, and transform this range node into a properly
3610 -- typed range with properly analyzed and resolved values.
3612 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
3613 Rng : constant Node_Id := Scalar_Range (Typ);
3614 Lo : constant Node_Id := Low_Bound (Rng);
3615 Hi : constant Node_Id := High_Bound (Rng);
3616 Btyp : constant Entity_Id := Base_Type (Typ);
3617 Brng : constant Node_Id := Scalar_Range (Btyp);
3618 BLo : constant Node_Id := Low_Bound (Brng);
3619 BHi : constant Node_Id := High_Bound (Brng);
3620 Small : constant Ureal := Small_Value (Typ);
3627 function Fsize (Lov, Hiv : Ureal) return Nat;
3628 -- Returns size of type with given bounds. Also leaves these
3629 -- bounds set as the current bounds of the Typ.
3631 function Fsize (Lov, Hiv : Ureal) return Nat is
3633 Set_Realval (Lo, Lov);
3634 Set_Realval (Hi, Hiv);
3635 return Minimum_Size (Typ);
3638 -- Start of processing for Freeze_Fixed_Point_Type;
3641 -- If Esize of a subtype has not previously been set, set it now
3643 if Unknown_Esize (Typ) then
3644 Atype := Ancestor_Subtype (Typ);
3646 if Present (Atype) then
3647 Set_Esize (Typ, Esize (Atype));
3649 Set_Esize (Typ, Esize (Base_Type (Typ)));
3653 -- Immediate return if the range is already analyzed. This means
3654 -- that the range is already set, and does not need to be computed
3657 if Analyzed (Rng) then
3661 -- Immediate return if either of the bounds raises Constraint_Error
3663 if Raises_Constraint_Error (Lo)
3664 or else Raises_Constraint_Error (Hi)
3669 Loval := Realval (Lo);
3670 Hival := Realval (Hi);
3672 -- Ordinary fixed-point case
3674 if Is_Ordinary_Fixed_Point_Type (Typ) then
3676 -- For the ordinary fixed-point case, we are allowed to fudge the
3677 -- end-points up or down by small. Generally we prefer to fudge
3678 -- up, i.e. widen the bounds for non-model numbers so that the
3679 -- end points are included. However there are cases in which this
3680 -- cannot be done, and indeed cases in which we may need to narrow
3681 -- the bounds. The following circuit makes the decision.
3683 -- Note: our terminology here is that Incl_EP means that the
3684 -- bounds are widened by Small if necessary to include the end
3685 -- points, and Excl_EP means that the bounds are narrowed by
3686 -- Small to exclude the end-points if this reduces the size.
3688 -- Note that in the Incl case, all we care about is including the
3689 -- end-points. In the Excl case, we want to narrow the bounds as
3690 -- much as permitted by the RM, to give the smallest possible size.
3693 Loval_Incl_EP : Ureal;
3694 Hival_Incl_EP : Ureal;
3696 Loval_Excl_EP : Ureal;
3697 Hival_Excl_EP : Ureal;
3703 First_Subt : Entity_Id;
3708 -- First step. Base types are required to be symmetrical. Right
3709 -- now, the base type range is a copy of the first subtype range.
3710 -- This will be corrected before we are done, but right away we
3711 -- need to deal with the case where both bounds are non-negative.
3712 -- In this case, we set the low bound to the negative of the high
3713 -- bound, to make sure that the size is computed to include the
3714 -- required sign. Note that we do not need to worry about the
3715 -- case of both bounds negative, because the sign will be dealt
3716 -- with anyway. Furthermore we can't just go making such a bound
3717 -- symmetrical, since in a twos-complement system, there is an
3718 -- extra negative value which could not be accomodated on the
3722 and then not UR_Is_Negative (Loval)
3723 and then Hival > Loval
3726 Set_Realval (Lo, Loval);
3729 -- Compute the fudged bounds. If the number is a model number,
3730 -- then we do nothing to include it, but we are allowed to
3731 -- backoff to the next adjacent model number when we exclude
3732 -- it. If it is not a model number then we straddle the two
3733 -- values with the model numbers on either side.
3735 Model_Num := UR_Trunc (Loval / Small) * Small;
3737 if Loval = Model_Num then
3738 Loval_Incl_EP := Model_Num;
3740 Loval_Incl_EP := Model_Num - Small;
3743 -- The low value excluding the end point is Small greater, but
3744 -- we do not do this exclusion if the low value is positive,
3745 -- since it can't help the size and could actually hurt by
3746 -- crossing the high bound.
3748 if UR_Is_Negative (Loval_Incl_EP) then
3749 Loval_Excl_EP := Loval_Incl_EP + Small;
3751 Loval_Excl_EP := Loval_Incl_EP;
3754 -- Similar processing for upper bound and high value
3756 Model_Num := UR_Trunc (Hival / Small) * Small;
3758 if Hival = Model_Num then
3759 Hival_Incl_EP := Model_Num;
3761 Hival_Incl_EP := Model_Num + Small;
3764 if UR_Is_Positive (Hival_Incl_EP) then
3765 Hival_Excl_EP := Hival_Incl_EP - Small;
3767 Hival_Excl_EP := Hival_Incl_EP;
3770 -- One further adjustment is needed. In the case of subtypes,
3771 -- we cannot go outside the range of the base type, or we get
3772 -- peculiarities, and the base type range is already set. This
3773 -- only applies to the Incl values, since clearly the Excl
3774 -- values are already as restricted as they are allowed to be.
3777 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
3778 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
3781 -- Get size including and excluding end points
3783 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
3784 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
3786 -- No need to exclude end-points if it does not reduce size
3788 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
3789 Loval_Excl_EP := Loval_Incl_EP;
3792 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
3793 Hival_Excl_EP := Hival_Incl_EP;
3796 -- Now we set the actual size to be used. We want to use the
3797 -- bounds fudged up to include the end-points but only if this
3798 -- can be done without violating a specifically given size
3799 -- size clause or causing an unacceptable increase in size.
3801 -- Case of size clause given
3803 if Has_Size_Clause (Typ) then
3805 -- Use the inclusive size only if it is consistent with
3806 -- the explicitly specified size.
3808 if Size_Incl_EP <= RM_Size (Typ) then
3809 Actual_Lo := Loval_Incl_EP;
3810 Actual_Hi := Hival_Incl_EP;
3811 Actual_Size := Size_Incl_EP;
3813 -- If the inclusive size is too large, we try excluding
3814 -- the end-points (will be caught later if does not work).
3817 Actual_Lo := Loval_Excl_EP;
3818 Actual_Hi := Hival_Excl_EP;
3819 Actual_Size := Size_Excl_EP;
3822 -- Case of size clause not given
3825 -- If we have a base type whose corresponding first subtype
3826 -- has an explicit size that is large enough to include our
3827 -- end-points, then do so. There is no point in working hard
3828 -- to get a base type whose size is smaller than the specified
3829 -- size of the first subtype.
3831 First_Subt := First_Subtype (Typ);
3833 if Has_Size_Clause (First_Subt)
3834 and then Size_Incl_EP <= Esize (First_Subt)
3836 Actual_Size := Size_Incl_EP;
3837 Actual_Lo := Loval_Incl_EP;
3838 Actual_Hi := Hival_Incl_EP;
3840 -- If excluding the end-points makes the size smaller and
3841 -- results in a size of 8,16,32,64, then we take the smaller
3842 -- size. For the 64 case, this is compulsory. For the other
3843 -- cases, it seems reasonable. We like to include end points
3844 -- if we can, but not at the expense of moving to the next
3845 -- natural boundary of size.
3847 elsif Size_Incl_EP /= Size_Excl_EP
3849 (Size_Excl_EP = 8 or else
3850 Size_Excl_EP = 16 or else
3851 Size_Excl_EP = 32 or else
3854 Actual_Size := Size_Excl_EP;
3855 Actual_Lo := Loval_Excl_EP;
3856 Actual_Hi := Hival_Excl_EP;
3858 -- Otherwise we can definitely include the end points
3861 Actual_Size := Size_Incl_EP;
3862 Actual_Lo := Loval_Incl_EP;
3863 Actual_Hi := Hival_Incl_EP;
3866 -- One pathological case: normally we never fudge a low
3867 -- bound down, since it would seem to increase the size
3868 -- (if it has any effect), but for ranges containing a
3869 -- single value, or no values, the high bound can be
3870 -- small too large. Consider:
3872 -- type t is delta 2.0**(-14)
3873 -- range 131072.0 .. 0;
3875 -- That lower bound is *just* outside the range of 32
3876 -- bits, and does need fudging down in this case. Note
3877 -- that the bounds will always have crossed here, since
3878 -- the high bound will be fudged down if necessary, as
3881 -- type t is delta 2.0**(-14)
3882 -- range 131072.0 .. 131072.0;
3884 -- So we can detect the situation by looking for crossed
3885 -- bounds, and if the bounds are crossed, and the low
3886 -- bound is greater than zero, we will always back it
3887 -- off by small, since this is completely harmless.
3889 if Actual_Lo > Actual_Hi then
3890 if UR_Is_Positive (Actual_Lo) then
3891 Actual_Lo := Loval_Incl_EP - Small;
3892 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3894 -- And of course, we need to do exactly the same parallel
3895 -- fudge for flat ranges in the negative region.
3897 elsif UR_Is_Negative (Actual_Hi) then
3898 Actual_Hi := Hival_Incl_EP + Small;
3899 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3904 Set_Realval (Lo, Actual_Lo);
3905 Set_Realval (Hi, Actual_Hi);
3908 -- For the decimal case, none of this fudging is required, since there
3909 -- are no end-point problems in the decimal case (the end-points are
3910 -- always included).
3913 Actual_Size := Fsize (Loval, Hival);
3916 -- At this stage, the actual size has been calculated and the proper
3917 -- required bounds are stored in the low and high bounds.
3919 if Actual_Size > 64 then
3920 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
3922 ("size required (^) for type& too large, maximum is 64", Typ);
3926 -- Check size against explicit given size
3928 if Has_Size_Clause (Typ) then
3929 if Actual_Size > RM_Size (Typ) then
3930 Error_Msg_Uint_1 := RM_Size (Typ);
3931 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
3933 ("size given (^) for type& too small, minimum is ^",
3934 Size_Clause (Typ), Typ);
3937 Actual_Size := UI_To_Int (Esize (Typ));
3940 -- Increase size to next natural boundary if no size clause given
3943 if Actual_Size <= 8 then
3945 elsif Actual_Size <= 16 then
3947 elsif Actual_Size <= 32 then
3953 Init_Esize (Typ, Actual_Size);
3954 Adjust_Esize_For_Alignment (Typ);
3957 -- If we have a base type, then expand the bounds so that they
3958 -- extend to the full width of the allocated size in bits, to
3959 -- avoid junk range checks on intermediate computations.
3961 if Base_Type (Typ) = Typ then
3962 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
3963 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
3966 -- Final step is to reanalyze the bounds using the proper type
3967 -- and set the Corresponding_Integer_Value fields of the literals.
3969 Set_Etype (Lo, Empty);
3970 Set_Analyzed (Lo, False);
3973 -- Resolve with universal fixed if the base type, and the base
3974 -- type if it is a subtype. Note we can't resolve the base type
3975 -- with itself, that would be a reference before definition.
3978 Resolve (Lo, Universal_Fixed);
3983 -- Set corresponding integer value for bound
3985 Set_Corresponding_Integer_Value
3986 (Lo, UR_To_Uint (Realval (Lo) / Small));
3988 -- Similar processing for high bound
3990 Set_Etype (Hi, Empty);
3991 Set_Analyzed (Hi, False);
3995 Resolve (Hi, Universal_Fixed);
4000 Set_Corresponding_Integer_Value
4001 (Hi, UR_To_Uint (Realval (Hi) / Small));
4003 -- Set type of range to correspond to bounds
4005 Set_Etype (Rng, Etype (Lo));
4007 -- Set Esize to calculated size if not set already
4009 if Unknown_Esize (Typ) then
4010 Init_Esize (Typ, Actual_Size);
4013 -- Set RM_Size if not already set. If already set, check value
4016 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
4019 if RM_Size (Typ) /= Uint_0 then
4020 if RM_Size (Typ) < Minsiz then
4021 Error_Msg_Uint_1 := RM_Size (Typ);
4022 Error_Msg_Uint_2 := Minsiz;
4024 ("size given (^) for type& too small, minimum is ^",
4025 Size_Clause (Typ), Typ);
4029 Set_RM_Size (Typ, Minsiz);
4032 end Freeze_Fixed_Point_Type;
4038 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
4042 Set_Has_Delayed_Freeze (T);
4043 L := Freeze_Entity (T, Sloc (N));
4045 if Is_Non_Empty_List (L) then
4046 Insert_Actions (N, L);
4050 --------------------------
4051 -- Freeze_Static_Object --
4052 --------------------------
4054 procedure Freeze_Static_Object (E : Entity_Id) is
4056 Cannot_Be_Static : exception;
4057 -- Exception raised if the type of a static object cannot be made
4058 -- static. This happens if the type depends on non-global objects.
4060 procedure Ensure_Expression_Is_SA (N : Node_Id);
4061 -- Called to ensure that an expression used as part of a type
4062 -- definition is statically allocatable, which means that the type
4063 -- of the expression is statically allocatable, and the expression
4064 -- is either static, or a reference to a library level constant.
4066 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
4067 -- Called to mark a type as static, checking that it is possible
4068 -- to set the type as static. If it is not possible, then the
4069 -- exception Cannot_Be_Static is raised.
4071 -----------------------------
4072 -- Ensure_Expression_Is_SA --
4073 -----------------------------
4075 procedure Ensure_Expression_Is_SA (N : Node_Id) is
4079 Ensure_Type_Is_SA (Etype (N));
4081 if Is_Static_Expression (N) then
4084 elsif Nkind (N) = N_Identifier then
4088 and then Ekind (Ent) = E_Constant
4089 and then Is_Library_Level_Entity (Ent)
4095 raise Cannot_Be_Static;
4096 end Ensure_Expression_Is_SA;
4098 -----------------------
4099 -- Ensure_Type_Is_SA --
4100 -----------------------
4102 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
4107 -- If type is library level, we are all set
4109 if Is_Library_Level_Entity (Typ) then
4113 -- We are also OK if the type is already marked as statically
4114 -- allocated, which means we processed it before.
4116 if Is_Statically_Allocated (Typ) then
4120 -- Mark type as statically allocated
4122 Set_Is_Statically_Allocated (Typ);
4124 -- Check that it is safe to statically allocate this type
4126 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
4127 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
4128 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
4130 elsif Is_Array_Type (Typ) then
4131 N := First_Index (Typ);
4132 while Present (N) loop
4133 Ensure_Type_Is_SA (Etype (N));
4137 Ensure_Type_Is_SA (Component_Type (Typ));
4139 elsif Is_Access_Type (Typ) then
4140 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
4144 T : constant Entity_Id := Etype (Designated_Type (Typ));
4147 if T /= Standard_Void_Type then
4148 Ensure_Type_Is_SA (T);
4151 F := First_Formal (Designated_Type (Typ));
4153 while Present (F) loop
4154 Ensure_Type_Is_SA (Etype (F));
4160 Ensure_Type_Is_SA (Designated_Type (Typ));
4163 elsif Is_Record_Type (Typ) then
4164 C := First_Entity (Typ);
4166 while Present (C) loop
4167 if Ekind (C) = E_Discriminant
4168 or else Ekind (C) = E_Component
4170 Ensure_Type_Is_SA (Etype (C));
4172 elsif Is_Type (C) then
4173 Ensure_Type_Is_SA (C);
4179 elsif Ekind (Typ) = E_Subprogram_Type then
4180 Ensure_Type_Is_SA (Etype (Typ));
4182 C := First_Formal (Typ);
4183 while Present (C) loop
4184 Ensure_Type_Is_SA (Etype (C));
4189 raise Cannot_Be_Static;
4191 end Ensure_Type_Is_SA;
4193 -- Start of processing for Freeze_Static_Object
4196 Ensure_Type_Is_SA (Etype (E));
4198 -- Reset True_Constant flag, since something strange is going on
4199 -- with the scoping here, and our simple value traceing may not
4200 -- be sufficient for this indication to be reliable. We kill the
4201 -- Constant_Value indication for the same reason.
4203 Set_Is_True_Constant (E, False);
4204 Set_Current_Value (E, Empty);
4207 when Cannot_Be_Static =>
4209 -- If the object that cannot be static is imported or exported,
4210 -- then we give an error message saying that this object cannot
4211 -- be imported or exported.
4213 if Is_Imported (E) then
4215 ("& cannot be imported (local type is not constant)", E);
4217 -- Otherwise must be exported, something is wrong if compiler
4218 -- is marking something as statically allocated which cannot be).
4220 else pragma Assert (Is_Exported (E));
4222 ("& cannot be exported (local type is not constant)", E);
4224 end Freeze_Static_Object;
4226 -----------------------
4227 -- Freeze_Subprogram --
4228 -----------------------
4230 procedure Freeze_Subprogram (E : Entity_Id) is
4235 -- Subprogram may not have an address clause unless it is imported
4237 if Present (Address_Clause (E)) then
4238 if not Is_Imported (E) then
4240 ("address clause can only be given " &
4241 "for imported subprogram",
4242 Name (Address_Clause (E)));
4246 -- Reset the Pure indication on an imported subprogram unless an
4247 -- explicit Pure_Function pragma was present. We do this because
4248 -- otherwise it is an insidious error to call a non-pure function
4249 -- from a pure unit and have calls mysteriously optimized away.
4250 -- What happens here is that the Import can bypass the normal
4251 -- check to ensure that pure units call only pure subprograms.
4254 and then Is_Pure (E)
4255 and then not Has_Pragma_Pure_Function (E)
4257 Set_Is_Pure (E, False);
4260 -- For non-foreign convention subprograms, this is where we create
4261 -- the extra formals (for accessibility level and constrained bit
4262 -- information). We delay this till the freeze point precisely so
4263 -- that we know the convention!
4265 if not Has_Foreign_Convention (E) then
4266 Create_Extra_Formals (E);
4269 -- If this is convention Ada and a Valued_Procedure, that's odd
4271 if Ekind (E) = E_Procedure
4272 and then Is_Valued_Procedure (E)
4273 and then Convention (E) = Convention_Ada
4274 and then Warn_On_Export_Import
4277 ("?Valued_Procedure has no effect for convention Ada", E);
4278 Set_Is_Valued_Procedure (E, False);
4281 -- Case of foreign convention
4286 -- For foreign conventions, warn about return of an
4287 -- unconstrained array.
4289 -- Note: we *do* allow a return by descriptor for the VMS case,
4290 -- though here there is probably more to be done ???
4292 if Ekind (E) = E_Function then
4293 Retype := Underlying_Type (Etype (E));
4295 -- If no return type, probably some other error, e.g. a
4296 -- missing full declaration, so ignore.
4301 -- If the return type is generic, we have emitted a warning
4302 -- earlier on, and there is nothing else to check here.
4303 -- Specific instantiations may lead to erroneous behavior.
4305 elsif Is_Generic_Type (Etype (E)) then
4308 elsif Is_Array_Type (Retype)
4309 and then not Is_Constrained (Retype)
4310 and then Mechanism (E) not in Descriptor_Codes
4311 and then Warn_On_Export_Import
4314 ("?foreign convention function& should not return " &
4315 "unconstrained array", E);
4320 -- If any of the formals for an exported foreign convention
4321 -- subprogram have defaults, then emit an appropriate warning
4322 -- since this is odd (default cannot be used from non-Ada code)
4324 if Is_Exported (E) then
4325 F := First_Formal (E);
4326 while Present (F) loop
4327 if Warn_On_Export_Import
4328 and then Present (Default_Value (F))
4331 ("?parameter cannot be defaulted in non-Ada call",
4340 -- For VMS, descriptor mechanisms for parameters are allowed only
4341 -- for imported subprograms.
4343 if OpenVMS_On_Target then
4344 if not Is_Imported (E) then
4345 F := First_Formal (E);
4346 while Present (F) loop
4347 if Mechanism (F) in Descriptor_Codes then
4349 ("descriptor mechanism for parameter not permitted", F);
4351 ("\can only be used for imported subprogram", F);
4358 end Freeze_Subprogram;
4360 -----------------------
4361 -- Is_Fully_Defined --
4362 -----------------------
4364 function Is_Fully_Defined (T : Entity_Id) return Boolean is
4366 if Ekind (T) = E_Class_Wide_Type then
4367 return Is_Fully_Defined (Etype (T));
4369 elsif Is_Array_Type (T) then
4370 return Is_Fully_Defined (Component_Type (T));
4372 elsif Is_Record_Type (T)
4373 and not Is_Private_Type (T)
4375 -- Verify that the record type has no components with
4376 -- private types without completion.
4382 Comp := First_Component (T);
4384 while Present (Comp) loop
4385 if not Is_Fully_Defined (Etype (Comp)) then
4389 Next_Component (Comp);
4394 else return not Is_Private_Type (T)
4395 or else Present (Full_View (Base_Type (T)));
4397 end Is_Fully_Defined;
4399 ---------------------------------
4400 -- Process_Default_Expressions --
4401 ---------------------------------
4403 procedure Process_Default_Expressions
4405 After : in out Node_Id)
4407 Loc : constant Source_Ptr := Sloc (E);
4414 Set_Default_Expressions_Processed (E);
4416 -- A subprogram instance and its associated anonymous subprogram
4417 -- share their signature. The default expression functions are defined
4418 -- in the wrapper packages for the anonymous subprogram, and should
4419 -- not be generated again for the instance.
4421 if Is_Generic_Instance (E)
4422 and then Present (Alias (E))
4423 and then Default_Expressions_Processed (Alias (E))
4428 Formal := First_Formal (E);
4430 while Present (Formal) loop
4431 if Present (Default_Value (Formal)) then
4433 -- We work with a copy of the default expression because we
4434 -- do not want to disturb the original, since this would mess
4435 -- up the conformance checking.
4437 Dcopy := New_Copy_Tree (Default_Value (Formal));
4439 -- The analysis of the expression may generate insert actions,
4440 -- which of course must not be executed. We wrap those actions
4441 -- in a procedure that is not called, and later on eliminated.
4442 -- The following cases have no side-effects, and are analyzed
4445 if Nkind (Dcopy) = N_Identifier
4446 or else Nkind (Dcopy) = N_Expanded_Name
4447 or else Nkind (Dcopy) = N_Integer_Literal
4448 or else (Nkind (Dcopy) = N_Real_Literal
4449 and then not Vax_Float (Etype (Dcopy)))
4450 or else Nkind (Dcopy) = N_Character_Literal
4451 or else Nkind (Dcopy) = N_String_Literal
4452 or else Nkind (Dcopy) = N_Null
4453 or else (Nkind (Dcopy) = N_Attribute_Reference
4455 Attribute_Name (Dcopy) = Name_Null_Parameter)
4458 -- If there is no default function, we must still do a full
4459 -- analyze call on the default value, to ensure that all
4460 -- error checks are performed, e.g. those associated with
4461 -- static evaluation. Note that this branch will always be
4462 -- taken if the analyzer is turned off (but we still need the
4465 -- Note: the setting of parent here is to meet the requirement
4466 -- that we can only analyze the expression while attached to
4467 -- the tree. Really the requirement is that the parent chain
4468 -- be set, we don't actually need to be in the tree.
4470 Set_Parent (Dcopy, Declaration_Node (Formal));
4473 -- Default expressions are resolved with their own type if the
4474 -- context is generic, to avoid anomalies with private types.
4476 if Ekind (Scope (E)) = E_Generic_Package then
4479 Resolve (Dcopy, Etype (Formal));
4482 -- If that resolved expression will raise constraint error,
4483 -- then flag the default value as raising constraint error.
4484 -- This allows a proper error message on the calls.
4486 if Raises_Constraint_Error (Dcopy) then
4487 Set_Raises_Constraint_Error (Default_Value (Formal));
4490 -- If the default is a parameterless call, we use the name of
4491 -- the called function directly, and there is no body to build.
4493 elsif Nkind (Dcopy) = N_Function_Call
4494 and then No (Parameter_Associations (Dcopy))
4498 -- Else construct and analyze the body of a wrapper procedure
4499 -- that contains an object declaration to hold the expression.
4500 -- Given that this is done only to complete the analysis, it
4501 -- simpler to build a procedure than a function which might
4502 -- involve secondary stack expansion.
4506 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
4509 Make_Subprogram_Body (Loc,
4511 Make_Procedure_Specification (Loc,
4512 Defining_Unit_Name => Dnam),
4514 Declarations => New_List (
4515 Make_Object_Declaration (Loc,
4516 Defining_Identifier =>
4517 Make_Defining_Identifier (Loc,
4518 New_Internal_Name ('T')),
4519 Object_Definition =>
4520 New_Occurrence_Of (Etype (Formal), Loc),
4521 Expression => New_Copy_Tree (Dcopy))),
4523 Handled_Statement_Sequence =>
4524 Make_Handled_Sequence_Of_Statements (Loc,
4525 Statements => New_List));
4527 Set_Scope (Dnam, Scope (E));
4528 Set_Assignment_OK (First (Declarations (Dbody)));
4529 Set_Is_Eliminated (Dnam);
4530 Insert_After (After, Dbody);
4536 Next_Formal (Formal);
4539 end Process_Default_Expressions;
4541 ----------------------------------------
4542 -- Set_Component_Alignment_If_Not_Set --
4543 ----------------------------------------
4545 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
4547 -- Ignore if not base type, subtypes don't need anything
4549 if Typ /= Base_Type (Typ) then
4553 -- Do not override existing representation
4555 if Is_Packed (Typ) then
4558 elsif Has_Specified_Layout (Typ) then
4561 elsif Component_Alignment (Typ) /= Calign_Default then
4565 Set_Component_Alignment
4566 (Typ, Scope_Stack.Table
4567 (Scope_Stack.Last).Component_Alignment_Default);
4569 end Set_Component_Alignment_If_Not_Set;
4571 ---------------------------
4572 -- Set_Debug_Info_Needed --
4573 ---------------------------
4575 procedure Set_Debug_Info_Needed (T : Entity_Id) is
4578 or else Needs_Debug_Info (T)
4579 or else Debug_Info_Off (T)
4583 Set_Needs_Debug_Info (T);
4586 if Is_Object (T) then
4587 Set_Debug_Info_Needed (Etype (T));
4589 elsif Is_Type (T) then
4590 Set_Debug_Info_Needed (Etype (T));
4592 if Is_Record_Type (T) then
4594 Ent : Entity_Id := First_Entity (T);
4596 while Present (Ent) loop
4597 Set_Debug_Info_Needed (Ent);
4602 elsif Is_Array_Type (T) then
4603 Set_Debug_Info_Needed (Component_Type (T));
4606 Indx : Node_Id := First_Index (T);
4608 while Present (Indx) loop
4609 Set_Debug_Info_Needed (Etype (Indx));
4610 Indx := Next_Index (Indx);
4614 if Is_Packed (T) then
4615 Set_Debug_Info_Needed (Packed_Array_Type (T));
4618 elsif Is_Access_Type (T) then
4619 Set_Debug_Info_Needed (Directly_Designated_Type (T));
4621 elsif Is_Private_Type (T) then
4622 Set_Debug_Info_Needed (Full_View (T));
4624 elsif Is_Protected_Type (T) then
4625 Set_Debug_Info_Needed (Corresponding_Record_Type (T));
4628 end Set_Debug_Info_Needed;
4634 procedure Warn_Overlay
4639 Ent : constant Entity_Id := Entity (Nam);
4640 -- The object to which the address clause applies.
4643 Old : Entity_Id := Empty;
4647 -- No warning if address clause overlay warnings are off
4649 if not Address_Clause_Overlay_Warnings then
4653 -- No warning if there is an explicit initialization
4655 Init := Original_Node (Expression (Declaration_Node (Ent)));
4657 if Present (Init) and then Comes_From_Source (Init) then
4661 -- We only give the warning for non-imported entities of a type
4662 -- for which a non-null base init proc is defined (or for access
4663 -- types which have implicit null initialization).
4666 and then (Has_Non_Null_Base_Init_Proc (Typ)
4667 or else Is_Access_Type (Typ))
4668 and then not Is_Imported (Ent)
4670 if Nkind (Expr) = N_Attribute_Reference
4671 and then Is_Entity_Name (Prefix (Expr))
4673 Old := Entity (Prefix (Expr));
4675 elsif Is_Entity_Name (Expr)
4676 and then Ekind (Entity (Expr)) = E_Constant
4678 Decl := Declaration_Node (Entity (Expr));
4680 if Nkind (Decl) = N_Object_Declaration
4681 and then Present (Expression (Decl))
4682 and then Nkind (Expression (Decl)) = N_Attribute_Reference
4683 and then Is_Entity_Name (Prefix (Expression (Decl)))
4685 Old := Entity (Prefix (Expression (Decl)));
4687 elsif Nkind (Expr) = N_Function_Call then
4691 -- A function call (most likely to To_Address) is probably not
4692 -- an overlay, so skip warning. Ditto if the function call was
4693 -- inlined and transformed into an entity.
4695 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
4699 Decl := Next (Parent (Expr));
4701 -- If a pragma Import follows, we assume that it is for the current
4702 -- target of the address clause, and skip the warning.
4705 and then Nkind (Decl) = N_Pragma
4706 and then Chars (Decl) = Name_Import
4711 if Present (Old) then
4712 Error_Msg_Node_2 := Old;
4714 ("default initialization of & may modify &?",
4718 ("default initialization of & may modify overlaid storage?",
4722 -- Add friendly warning if initialization comes from a packed array
4725 if Is_Record_Type (Typ) then
4730 Comp := First_Component (Typ);
4732 while Present (Comp) loop
4733 if Nkind (Parent (Comp)) = N_Component_Declaration
4734 and then Present (Expression (Parent (Comp)))
4737 elsif Is_Array_Type (Etype (Comp))
4738 and then Present (Packed_Array_Type (Etype (Comp)))
4741 ("packed array component& will be initialized to zero?",
4745 Next_Component (Comp);
4752 ("use pragma Import for & to " &
4753 "suppress initialization ('R'M B.1(24))?",