1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- You should have received a copy of the GNU General Public License along --
19 -- with this program; see file COPYING3. If not see --
20 -- <http://www.gnu.org/licenses/>. --
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_Ch3; use Exp_Ch3;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Pakd; use Exp_Pakd;
36 with Exp_Util; use Exp_Util;
37 with Exp_Tss; use Exp_Tss;
38 with Layout; use Layout;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch6; use Sem_Ch6;
49 with Sem_Ch7; use Sem_Ch7;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Mech; use Sem_Mech;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Util; use Sem_Util;
57 with Sinfo; use Sinfo;
58 with Snames; use Snames;
59 with Stand; use Stand;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uintp; use Uintp;
64 with Urealp; use Urealp;
66 package body Freeze is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
73 -- Typ is a type that is being frozen. If no size clause is given,
74 -- but a default Esize has been computed, then this default Esize is
75 -- adjusted up if necessary to be consistent with a given alignment,
76 -- but never to a value greater than Long_Long_Integer'Size. This
77 -- is used for all discrete types and for fixed-point types.
79 procedure Build_And_Analyze_Renamed_Body
82 After : in out Node_Id);
83 -- Build body for a renaming declaration, insert in tree and analyze
85 procedure Check_Address_Clause (E : Entity_Id);
86 -- Apply legality checks to address clauses for object declarations,
87 -- at the point the object is frozen.
89 procedure Check_Strict_Alignment (E : Entity_Id);
90 -- E is a base type. If E is tagged or has a component that is aliased
91 -- or tagged or contains something this is aliased or tagged, set
94 procedure Check_Unsigned_Type (E : Entity_Id);
95 pragma Inline (Check_Unsigned_Type);
96 -- If E is a fixed-point or discrete type, then all the necessary work
97 -- to freeze it is completed except for possible setting of the flag
98 -- Is_Unsigned_Type, which is done by this procedure. The call has no
99 -- effect if the entity E is not a discrete or fixed-point type.
101 procedure Freeze_And_Append
104 Result : in out List_Id);
105 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
106 -- nodes to Result, modifying Result from No_List if necessary.
108 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
109 -- Freeze enumeration type. The Esize field is set as processing
110 -- proceeds (i.e. set by default when the type is declared and then
111 -- adjusted by rep clauses. What this procedure does is to make sure
112 -- that if a foreign convention is specified, and no specific size
113 -- is given, then the size must be at least Integer'Size.
115 procedure Freeze_Static_Object (E : Entity_Id);
116 -- If an object is frozen which has Is_Statically_Allocated set, then
117 -- all referenced types must also be marked with this flag. This routine
118 -- is in charge of meeting this requirement for the object entity E.
120 procedure Freeze_Subprogram (E : Entity_Id);
121 -- Perform freezing actions for a subprogram (create extra formals,
122 -- and set proper default mechanism values). Note that this routine
123 -- is not called for internal subprograms, for which neither of these
124 -- actions is needed (or desirable, we do not want for example to have
125 -- these extra formals present in initialization procedures, where they
126 -- would serve no purpose). In this call E is either a subprogram or
127 -- a subprogram type (i.e. an access to a subprogram).
129 function Is_Fully_Defined (T : Entity_Id) return Boolean;
130 -- True if T is not private and has no private components, or has a full
131 -- view. Used to determine whether the designated type of an access type
132 -- should be frozen when the access type is frozen. This is done when an
133 -- allocator is frozen, or an expression that may involve attributes of
134 -- the designated type. Otherwise freezing the access type does not freeze
135 -- the designated type.
137 procedure Process_Default_Expressions
139 After : in out Node_Id);
140 -- This procedure is called for each subprogram to complete processing
141 -- of default expressions at the point where all types are known to be
142 -- frozen. The expressions must be analyzed in full, to make sure that
143 -- all error processing is done (they have only been pre-analyzed). If
144 -- the expression is not an entity or literal, its analysis may generate
145 -- code which must not be executed. In that case we build a function
146 -- body to hold that code. This wrapper function serves no other purpose
147 -- (it used to be called to evaluate the default, but now the default is
148 -- inlined at each point of call).
150 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
151 -- Typ is a record or array type that is being frozen. This routine
152 -- sets the default component alignment from the scope stack values
153 -- if the alignment is otherwise not specified.
155 procedure Check_Debug_Info_Needed (T : Entity_Id);
156 -- As each entity is frozen, this routine is called to deal with the
157 -- setting of Debug_Info_Needed for the entity. This flag is set if
158 -- the entity comes from source, or if we are in Debug_Generated_Code
159 -- mode or if the -gnatdV debug flag is set. However, it never sets
160 -- the flag if Debug_Info_Off is set. This procedure also ensures that
161 -- subsidiary entities have the flag set as required.
163 procedure Undelay_Type (T : Entity_Id);
164 -- T is a type of a component that we know to be an Itype.
165 -- We don't want this to have a Freeze_Node, so ensure it doesn't.
166 -- Do the same for any Full_View or Corresponding_Record_Type.
168 procedure Warn_Overlay
172 -- Expr is the expression for an address clause for entity Nam whose type
173 -- is Typ. If Typ has a default initialization, and there is no explicit
174 -- initialization in the source declaration, check whether the address
175 -- clause might cause overlaying of an entity, and emit a warning on the
176 -- side effect that the initialization will cause.
178 -------------------------------
179 -- Adjust_Esize_For_Alignment --
180 -------------------------------
182 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
186 if Known_Esize (Typ) and then Known_Alignment (Typ) then
187 Align := Alignment_In_Bits (Typ);
189 if Align > Esize (Typ)
190 and then Align <= Standard_Long_Long_Integer_Size
192 Set_Esize (Typ, Align);
195 end Adjust_Esize_For_Alignment;
197 ------------------------------------
198 -- Build_And_Analyze_Renamed_Body --
199 ------------------------------------
201 procedure Build_And_Analyze_Renamed_Body
204 After : in out Node_Id)
206 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;
242 Pref : Node_Id := Empty;
243 -- If the renamed entity is a primitive operation given in prefix form,
244 -- the prefix is the target object and it has to be added as the first
245 -- actual in the generated call.
248 -- Determine the entity being renamed, which is the target of the call
249 -- statement. If the name is an explicit dereference, this is a renaming
250 -- of a subprogram type rather than a subprogram. The name itself is
253 if Nkind (Nam) = N_Selected_Component then
254 Old_S := Entity (Selector_Name (Nam));
256 elsif Nkind (Nam) = N_Explicit_Dereference then
257 Old_S := Etype (Nam);
259 elsif Nkind (Nam) = N_Indexed_Component then
260 if Is_Entity_Name (Prefix (Nam)) then
261 Old_S := Entity (Prefix (Nam));
263 Old_S := Entity (Selector_Name (Prefix (Nam)));
266 elsif Nkind (Nam) = N_Character_Literal then
267 Old_S := Etype (New_S);
270 Old_S := Entity (Nam);
273 if Is_Entity_Name (Nam) then
275 -- If the renamed entity is a predefined operator, retain full name
276 -- to ensure its visibility.
278 if Ekind (Old_S) = E_Operator
279 and then Nkind (Nam) = N_Expanded_Name
281 Call_Name := New_Copy (Name (N));
283 Call_Name := New_Reference_To (Old_S, Loc);
287 if Nkind (Nam) = N_Selected_Component
288 and then Present (First_Formal (Old_S))
290 (Is_Controlling_Formal (First_Formal (Old_S))
291 or else Is_Class_Wide_Type (Etype (First_Formal (Old_S))))
294 -- Retrieve the target object, to be added as a first actual
297 Call_Name := New_Occurrence_Of (Old_S, Loc);
298 Pref := Prefix (Nam);
301 Call_Name := New_Copy (Name (N));
304 -- The original name may have been overloaded, but
305 -- is fully resolved now.
307 Set_Is_Overloaded (Call_Name, False);
310 -- For simple renamings, subsequent calls can be expanded directly as
311 -- called to the renamed entity. The body must be generated in any case
312 -- for calls they may appear elsewhere.
314 if (Ekind (Old_S) = E_Function
315 or else Ekind (Old_S) = E_Procedure)
316 and then Nkind (Decl) = N_Subprogram_Declaration
318 Set_Body_To_Inline (Decl, Old_S);
321 -- The body generated for this renaming is an internal artifact, and
322 -- does not constitute a freeze point for the called entity.
324 Set_Must_Not_Freeze (Call_Name);
326 Formal := First_Formal (Defining_Entity (Decl));
328 if Present (Pref) then
330 Pref_Type : constant Entity_Id := Etype (Pref);
331 Form_Type : constant Entity_Id := Etype (First_Formal (Old_S));
335 -- The controlling formal may be an access parameter, or the
336 -- actual may be an access value, so adjust accordingly.
338 if Is_Access_Type (Pref_Type)
339 and then not Is_Access_Type (Form_Type)
342 (Make_Explicit_Dereference (Loc, Relocate_Node (Pref)));
344 elsif Is_Access_Type (Form_Type)
345 and then not Is_Access_Type (Pref)
348 (Make_Attribute_Reference (Loc,
349 Attribute_Name => Name_Access,
350 Prefix => Relocate_Node (Pref)));
352 Actuals := New_List (Pref);
356 elsif Present (Formal) then
363 if Present (Formal) then
364 while Present (Formal) loop
365 Append (New_Reference_To (Formal, Loc), Actuals);
366 Next_Formal (Formal);
370 -- If the renamed entity is an entry, inherit its profile. For other
371 -- renamings as bodies, both profiles must be subtype conformant, so it
372 -- is not necessary to replace the profile given in the declaration.
373 -- However, default values that are aggregates are rewritten when
374 -- partially analyzed, so we recover the original aggregate to insure
375 -- that subsequent conformity checking works. Similarly, if the default
376 -- expression was constant-folded, recover the original expression.
378 Formal := First_Formal (Defining_Entity (Decl));
380 if Present (Formal) then
381 O_Formal := First_Formal (Old_S);
382 Param_Spec := First (Parameter_Specifications (Spec));
384 while Present (Formal) loop
385 if Is_Entry (Old_S) then
387 if Nkind (Parameter_Type (Param_Spec)) /=
390 Set_Etype (Formal, Etype (O_Formal));
391 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
394 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
395 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
396 Nkind (Default_Value (O_Formal))
398 Set_Expression (Param_Spec,
399 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
402 Next_Formal (Formal);
403 Next_Formal (O_Formal);
408 -- If the renamed entity is a function, the generated body contains a
409 -- return statement. Otherwise, build a procedure call. If the entity is
410 -- an entry, subsequent analysis of the call will transform it into the
411 -- proper entry or protected operation call. If the renamed entity is
412 -- a character literal, return it directly.
414 if Ekind (Old_S) = E_Function
415 or else Ekind (Old_S) = E_Operator
416 or else (Ekind (Old_S) = E_Subprogram_Type
417 and then Etype (Old_S) /= Standard_Void_Type)
420 Make_Simple_Return_Statement (Loc,
422 Make_Function_Call (Loc,
424 Parameter_Associations => Actuals));
426 elsif Ekind (Old_S) = E_Enumeration_Literal then
428 Make_Simple_Return_Statement (Loc,
429 Expression => New_Occurrence_Of (Old_S, Loc));
431 elsif Nkind (Nam) = N_Character_Literal then
433 Make_Simple_Return_Statement (Loc,
434 Expression => Call_Name);
438 Make_Procedure_Call_Statement (Loc,
440 Parameter_Associations => Actuals);
443 -- Create entities for subprogram body and formals
445 Set_Defining_Unit_Name (Spec,
446 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
448 Param_Spec := First (Parameter_Specifications (Spec));
450 while Present (Param_Spec) loop
451 Set_Defining_Identifier (Param_Spec,
452 Make_Defining_Identifier (Loc,
453 Chars => Chars (Defining_Identifier (Param_Spec))));
458 Make_Subprogram_Body (Loc,
459 Specification => Spec,
460 Declarations => New_List,
461 Handled_Statement_Sequence =>
462 Make_Handled_Sequence_Of_Statements (Loc,
463 Statements => New_List (Call_Node)));
465 if Nkind (Decl) /= N_Subprogram_Declaration then
467 Make_Subprogram_Declaration (Loc,
468 Specification => Specification (N)));
471 -- Link the body to the entity whose declaration it completes. If
472 -- the body is analyzed when the renamed entity is frozen, it may
473 -- be necessary to restore the proper scope (see package Exp_Ch13).
475 if Nkind (N) = N_Subprogram_Renaming_Declaration
476 and then Present (Corresponding_Spec (N))
478 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
480 Set_Corresponding_Spec (Body_Node, New_S);
484 end Build_Renamed_Body;
486 --------------------------
487 -- Check_Address_Clause --
488 --------------------------
490 procedure Check_Address_Clause (E : Entity_Id) is
491 Addr : constant Node_Id := Address_Clause (E);
493 Decl : constant Node_Id := Declaration_Node (E);
494 Typ : constant Entity_Id := Etype (E);
497 if Present (Addr) then
498 Expr := Expression (Addr);
500 -- If we have no initialization of any kind, then we don't need to
501 -- place any restrictions on the address clause, because the object
502 -- will be elaborated after the address clause is evaluated. This
503 -- happens if the declaration has no initial expression, or the type
504 -- has no implicit initialization, or the object is imported.
506 -- The same holds for all initialized scalar types and all access
507 -- types. Packed bit arrays of size up to 64 are represented using a
508 -- modular type with an initialization (to zero) and can be processed
509 -- like other initialized scalar types.
511 -- If the type is controlled, code to attach the object to a
512 -- finalization chain is generated at the point of declaration,
513 -- and therefore the elaboration of the object cannot be delayed:
514 -- the address expression must be a constant.
516 if (No (Expression (Decl))
517 and then not Needs_Finalization (Typ)
519 (not Has_Non_Null_Base_Init_Proc (Typ)
520 or else Is_Imported (E)))
523 (Present (Expression (Decl))
524 and then Is_Scalar_Type (Typ))
530 (Is_Bit_Packed_Array (Typ)
532 Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
536 -- Otherwise, we require the address clause to be constant because
537 -- the call to the initialization procedure (or the attach code) has
538 -- to happen at the point of the declaration.
539 -- Actually the IP call has been moved to the freeze actions
540 -- anyway, so maybe we can relax this restriction???
543 Check_Constant_Address_Clause (Expr, E);
545 -- Has_Delayed_Freeze was set on E when the address clause was
546 -- analyzed. Reset the flag now unless freeze actions were
547 -- attached to it in the mean time.
549 if No (Freeze_Node (E)) then
550 Set_Has_Delayed_Freeze (E, False);
554 if not Error_Posted (Expr)
555 and then not Needs_Finalization (Typ)
557 Warn_Overlay (Expr, Typ, Name (Addr));
560 end Check_Address_Clause;
562 -----------------------------
563 -- Check_Compile_Time_Size --
564 -----------------------------
566 procedure Check_Compile_Time_Size (T : Entity_Id) is
568 procedure Set_Small_Size (T : Entity_Id; S : Uint);
569 -- Sets the compile time known size (32 bits or less) in the Esize
570 -- field, of T checking for a size clause that was given which attempts
571 -- to give a smaller size, and also checking for an alignment clause.
573 function Size_Known (T : Entity_Id) return Boolean;
574 -- Recursive function that does all the work
576 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
577 -- If T is a constrained subtype, its size is not known if any of its
578 -- discriminant constraints is not static and it is not a null record.
579 -- The test is conservative and doesn't check that the components are
580 -- in fact constrained by non-static discriminant values. Could be made
587 procedure Set_Small_Size (T : Entity_Id; S : Uint) is
592 -- Don't bother if alignment clause with a value other than 1 is
593 -- present, because size may be padded up to meet back end alignment
594 -- requirements, and only the back end knows the rules!
596 elsif Known_Alignment (T) and then Alignment (T) /= 1 then
599 -- Check for bad size clause given
601 elsif Has_Size_Clause (T) then
602 if RM_Size (T) < S then
603 Error_Msg_Uint_1 := S;
605 ("size for& too small, minimum allowed is ^",
608 elsif Unknown_Esize (T) then
612 -- Set sizes if not set already
615 if Unknown_Esize (T) then
619 if Unknown_RM_Size (T) then
629 function Size_Known (T : Entity_Id) return Boolean is
637 if Size_Known_At_Compile_Time (T) then
640 -- Always True for scalar types. This is true even for generic formal
641 -- scalar types. We used to return False in the latter case, but the
642 -- size is known at compile time, even in the template, we just do
643 -- not know the exact size but that's not the point of this routine.
645 elsif Is_Scalar_Type (T)
646 or else Is_Task_Type (T)
652 elsif Is_Array_Type (T) then
654 -- String literals always have known size, and we can set it
656 if Ekind (T) = E_String_Literal_Subtype then
657 Set_Small_Size (T, Component_Size (T)
658 * String_Literal_Length (T));
661 -- Unconstrained types never have known at compile time size
663 elsif not Is_Constrained (T) then
666 -- Don't do any recursion on type with error posted, since we may
667 -- have a malformed type that leads us into a loop.
669 elsif Error_Posted (T) then
672 -- Otherwise if component size unknown, then array size unknown
674 elsif not Size_Known (Component_Type (T)) then
678 -- Check for all indexes static, and also compute possible size
679 -- (in case it is less than 32 and may be packable).
682 Esiz : Uint := Component_Size (T);
686 Index := First_Index (T);
687 while Present (Index) loop
688 if Nkind (Index) = N_Range then
689 Get_Index_Bounds (Index, Low, High);
691 elsif Error_Posted (Scalar_Range (Etype (Index))) then
695 Low := Type_Low_Bound (Etype (Index));
696 High := Type_High_Bound (Etype (Index));
699 if not Compile_Time_Known_Value (Low)
700 or else not Compile_Time_Known_Value (High)
701 or else Etype (Index) = Any_Type
706 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
718 Set_Small_Size (T, Esiz);
722 -- Access types always have known at compile time sizes
724 elsif Is_Access_Type (T) then
727 -- For non-generic private types, go to underlying type if present
729 elsif Is_Private_Type (T)
730 and then not Is_Generic_Type (T)
731 and then Present (Underlying_Type (T))
733 -- Don't do any recursion on type with error posted, since we may
734 -- have a malformed type that leads us into a loop.
736 if Error_Posted (T) then
739 return Size_Known (Underlying_Type (T));
744 elsif Is_Record_Type (T) then
746 -- A class-wide type is never considered to have a known size
748 if Is_Class_Wide_Type (T) then
751 -- A subtype of a variant record must not have non-static
752 -- discriminanted components.
754 elsif T /= Base_Type (T)
755 and then not Static_Discriminated_Components (T)
759 -- Don't do any recursion on type with error posted, since we may
760 -- have a malformed type that leads us into a loop.
762 elsif Error_Posted (T) then
766 -- Now look at the components of the record
769 -- The following two variables are used to keep track of the
770 -- size of packed records if we can tell the size of the packed
771 -- record in the front end. Packed_Size_Known is True if so far
772 -- we can figure out the size. It is initialized to True for a
773 -- packed record, unless the record has discriminants. The
774 -- reason we eliminate the discriminated case is that we don't
775 -- know the way the back end lays out discriminated packed
776 -- records. If Packed_Size_Known is True, then Packed_Size is
777 -- the size in bits so far.
779 Packed_Size_Known : Boolean :=
781 and then not Has_Discriminants (T);
783 Packed_Size : Uint := Uint_0;
786 -- Test for variant part present
788 if Has_Discriminants (T)
789 and then Present (Parent (T))
790 and then Nkind (Parent (T)) = N_Full_Type_Declaration
791 and then Nkind (Type_Definition (Parent (T))) =
793 and then not Null_Present (Type_Definition (Parent (T)))
794 and then Present (Variant_Part
795 (Component_List (Type_Definition (Parent (T)))))
797 -- If variant part is present, and type is unconstrained,
798 -- then we must have defaulted discriminants, or a size
799 -- clause must be present for the type, or else the size
800 -- is definitely not known at compile time.
802 if not Is_Constrained (T)
804 No (Discriminant_Default_Value
805 (First_Discriminant (T)))
806 and then Unknown_Esize (T)
812 -- Loop through components
814 Comp := First_Component_Or_Discriminant (T);
815 while Present (Comp) loop
816 Ctyp := Etype (Comp);
818 -- We do not know the packed size if there is a component
819 -- clause present (we possibly could, but this would only
820 -- help in the case of a record with partial rep clauses.
821 -- That's because in the case of full rep clauses, the
822 -- size gets figured out anyway by a different circuit).
824 if Present (Component_Clause (Comp)) then
825 Packed_Size_Known := False;
828 -- We need to identify a component that is an array where
829 -- the index type is an enumeration type with non-standard
830 -- representation, and some bound of the type depends on a
833 -- This is because gigi computes the size by doing a
834 -- substitution of the appropriate discriminant value in
835 -- the size expression for the base type, and gigi is not
836 -- clever enough to evaluate the resulting expression (which
837 -- involves a call to rep_to_pos) at compile time.
839 -- It would be nice if gigi would either recognize that
840 -- this expression can be computed at compile time, or
841 -- alternatively figured out the size from the subtype
842 -- directly, where all the information is at hand ???
844 if Is_Array_Type (Etype (Comp))
845 and then Present (Packed_Array_Type (Etype (Comp)))
848 Ocomp : constant Entity_Id :=
849 Original_Record_Component (Comp);
850 OCtyp : constant Entity_Id := Etype (Ocomp);
856 Ind := First_Index (OCtyp);
857 while Present (Ind) loop
858 Indtyp := Etype (Ind);
860 if Is_Enumeration_Type (Indtyp)
861 and then Has_Non_Standard_Rep (Indtyp)
863 Lo := Type_Low_Bound (Indtyp);
864 Hi := Type_High_Bound (Indtyp);
866 if Is_Entity_Name (Lo)
867 and then Ekind (Entity (Lo)) = E_Discriminant
871 elsif Is_Entity_Name (Hi)
872 and then Ekind (Entity (Hi)) = E_Discriminant
883 -- Clearly size of record is not known if the size of one of
884 -- the components is not known.
886 if not Size_Known (Ctyp) then
890 -- Accumulate packed size if possible
892 if Packed_Size_Known then
894 -- We can only deal with elementary types, since for
895 -- non-elementary components, alignment enters into the
896 -- picture, and we don't know enough to handle proper
897 -- alignment in this context. Packed arrays count as
898 -- elementary if the representation is a modular type.
900 if Is_Elementary_Type (Ctyp)
901 or else (Is_Array_Type (Ctyp)
902 and then Present (Packed_Array_Type (Ctyp))
903 and then Is_Modular_Integer_Type
904 (Packed_Array_Type (Ctyp)))
906 -- If RM_Size is known and static, then we can keep
907 -- accumulating the packed size.
909 if Known_Static_RM_Size (Ctyp) then
911 -- A little glitch, to be removed sometime ???
912 -- gigi does not understand zero sizes yet.
914 if RM_Size (Ctyp) = Uint_0 then
915 Packed_Size_Known := False;
917 -- Normal case where we can keep accumulating the
918 -- packed array size.
921 Packed_Size := Packed_Size + RM_Size (Ctyp);
924 -- If we have a field whose RM_Size is not known then
925 -- we can't figure out the packed size here.
928 Packed_Size_Known := False;
931 -- If we have a non-elementary type we can't figure out
932 -- the packed array size (alignment issues).
935 Packed_Size_Known := False;
939 Next_Component_Or_Discriminant (Comp);
942 if Packed_Size_Known then
943 Set_Small_Size (T, Packed_Size);
949 -- All other cases, size not known at compile time
956 -------------------------------------
957 -- Static_Discriminated_Components --
958 -------------------------------------
960 function Static_Discriminated_Components
961 (T : Entity_Id) return Boolean
963 Constraint : Elmt_Id;
966 if Has_Discriminants (T)
967 and then Present (Discriminant_Constraint (T))
968 and then Present (First_Component (T))
970 Constraint := First_Elmt (Discriminant_Constraint (T));
971 while Present (Constraint) loop
972 if not Compile_Time_Known_Value (Node (Constraint)) then
976 Next_Elmt (Constraint);
981 end Static_Discriminated_Components;
983 -- Start of processing for Check_Compile_Time_Size
986 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
987 end Check_Compile_Time_Size;
989 -----------------------------
990 -- Check_Debug_Info_Needed --
991 -----------------------------
993 procedure Check_Debug_Info_Needed (T : Entity_Id) is
995 if Debug_Info_Off (T) then
998 elsif Comes_From_Source (T)
999 or else Debug_Generated_Code
1000 or else Debug_Flag_VV
1001 or else Needs_Debug_Info (T)
1003 Set_Debug_Info_Needed (T);
1005 end Check_Debug_Info_Needed;
1007 ----------------------------
1008 -- Check_Strict_Alignment --
1009 ----------------------------
1011 procedure Check_Strict_Alignment (E : Entity_Id) is
1015 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
1016 Set_Strict_Alignment (E);
1018 elsif Is_Array_Type (E) then
1019 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
1021 elsif Is_Record_Type (E) then
1022 if Is_Limited_Record (E) then
1023 Set_Strict_Alignment (E);
1027 Comp := First_Component (E);
1029 while Present (Comp) loop
1030 if not Is_Type (Comp)
1031 and then (Strict_Alignment (Etype (Comp))
1032 or else Is_Aliased (Comp))
1034 Set_Strict_Alignment (E);
1038 Next_Component (Comp);
1041 end Check_Strict_Alignment;
1043 -------------------------
1044 -- Check_Unsigned_Type --
1045 -------------------------
1047 procedure Check_Unsigned_Type (E : Entity_Id) is
1048 Ancestor : Entity_Id;
1053 if not Is_Discrete_Or_Fixed_Point_Type (E) then
1057 -- Do not attempt to analyze case where range was in error
1059 if Error_Posted (Scalar_Range (E)) then
1063 -- The situation that is non trivial is something like
1065 -- subtype x1 is integer range -10 .. +10;
1066 -- subtype x2 is x1 range 0 .. V1;
1067 -- subtype x3 is x2 range V2 .. V3;
1068 -- subtype x4 is x3 range V4 .. V5;
1070 -- where Vn are variables. Here the base type is signed, but we still
1071 -- know that x4 is unsigned because of the lower bound of x2.
1073 -- The only way to deal with this is to look up the ancestor chain
1077 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1081 Lo_Bound := Type_Low_Bound (Ancestor);
1083 if Compile_Time_Known_Value (Lo_Bound) then
1085 if Expr_Rep_Value (Lo_Bound) >= 0 then
1086 Set_Is_Unsigned_Type (E, True);
1092 Ancestor := Ancestor_Subtype (Ancestor);
1094 -- If no ancestor had a static lower bound, go to base type
1096 if No (Ancestor) then
1098 -- Note: the reason we still check for a compile time known
1099 -- value for the base type is that at least in the case of
1100 -- generic formals, we can have bounds that fail this test,
1101 -- and there may be other cases in error situations.
1103 Btyp := Base_Type (E);
1105 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1109 Lo_Bound := Type_Low_Bound (Base_Type (E));
1111 if Compile_Time_Known_Value (Lo_Bound)
1112 and then Expr_Rep_Value (Lo_Bound) >= 0
1114 Set_Is_Unsigned_Type (E, True);
1121 end Check_Unsigned_Type;
1123 -------------------------
1124 -- Is_Atomic_Aggregate --
1125 -------------------------
1127 function Is_Atomic_Aggregate
1129 Typ : Entity_Id) return Boolean
1131 Loc : constant Source_Ptr := Sloc (E);
1139 -- Array may be qualified, so find outer context
1141 if Nkind (Par) = N_Qualified_Expression then
1142 Par := Parent (Par);
1145 if Nkind_In (Par, N_Object_Declaration, N_Assignment_Statement)
1146 and then Comes_From_Source (Par)
1148 Temp := Make_Temporary (Loc, 'T', E);
1150 Make_Object_Declaration (Loc,
1151 Defining_Identifier => Temp,
1152 Object_Definition => New_Occurrence_Of (Typ, Loc),
1153 Expression => Relocate_Node (E));
1154 Insert_Before (Par, New_N);
1157 Set_Expression (Par, New_Occurrence_Of (Temp, Loc));
1163 end Is_Atomic_Aggregate;
1169 -- Note: the easy coding for this procedure would be to just build a
1170 -- single list of freeze nodes and then insert them and analyze them
1171 -- all at once. This won't work, because the analysis of earlier freeze
1172 -- nodes may recursively freeze types which would otherwise appear later
1173 -- on in the freeze list. So we must analyze and expand the freeze nodes
1174 -- as they are generated.
1176 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1177 Loc : constant Source_Ptr := Sloc (After);
1181 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1182 -- This is the internal recursive routine that does freezing of entities
1183 -- (but NOT the analysis of default expressions, which should not be
1184 -- recursive, we don't want to analyze those till we are sure that ALL
1185 -- the types are frozen).
1187 --------------------
1188 -- Freeze_All_Ent --
1189 --------------------
1191 procedure Freeze_All_Ent
1193 After : in out Node_Id)
1199 procedure Process_Flist;
1200 -- If freeze nodes are present, insert and analyze, and reset cursor
1201 -- for next insertion.
1207 procedure Process_Flist is
1209 if Is_Non_Empty_List (Flist) then
1210 Lastn := Next (After);
1211 Insert_List_After_And_Analyze (After, Flist);
1213 if Present (Lastn) then
1214 After := Prev (Lastn);
1216 After := Last (List_Containing (After));
1221 -- Start or processing for Freeze_All_Ent
1225 while Present (E) loop
1227 -- If the entity is an inner package which is not a package
1228 -- renaming, then its entities must be frozen at this point. Note
1229 -- that such entities do NOT get frozen at the end of the nested
1230 -- package itself (only library packages freeze).
1232 -- Same is true for task declarations, where anonymous records
1233 -- created for entry parameters must be frozen.
1235 if Ekind (E) = E_Package
1236 and then No (Renamed_Object (E))
1237 and then not Is_Child_Unit (E)
1238 and then not Is_Frozen (E)
1241 Install_Visible_Declarations (E);
1242 Install_Private_Declarations (E);
1244 Freeze_All (First_Entity (E), After);
1246 End_Package_Scope (E);
1248 elsif Ekind (E) in Task_Kind
1250 (Nkind (Parent (E)) = N_Task_Type_Declaration
1252 Nkind (Parent (E)) = N_Single_Task_Declaration)
1255 Freeze_All (First_Entity (E), After);
1258 -- For a derived tagged type, we must ensure that all the
1259 -- primitive operations of the parent have been frozen, so that
1260 -- their addresses will be in the parent's dispatch table at the
1261 -- point it is inherited.
1263 elsif Ekind (E) = E_Record_Type
1264 and then Is_Tagged_Type (E)
1265 and then Is_Tagged_Type (Etype (E))
1266 and then Is_Derived_Type (E)
1269 Prim_List : constant Elist_Id :=
1270 Primitive_Operations (Etype (E));
1276 Prim := First_Elmt (Prim_List);
1278 while Present (Prim) loop
1279 Subp := Node (Prim);
1281 if Comes_From_Source (Subp)
1282 and then not Is_Frozen (Subp)
1284 Flist := Freeze_Entity (Subp, Loc);
1293 if not Is_Frozen (E) then
1294 Flist := Freeze_Entity (E, Loc);
1298 -- If an incomplete type is still not frozen, this may be a
1299 -- premature freezing because of a body declaration that follows.
1300 -- Indicate where the freezing took place.
1302 -- If the freezing is caused by the end of the current declarative
1303 -- part, it is a Taft Amendment type, and there is no error.
1305 if not Is_Frozen (E)
1306 and then Ekind (E) = E_Incomplete_Type
1309 Bod : constant Node_Id := Next (After);
1312 if (Nkind (Bod) = N_Subprogram_Body
1313 or else Nkind (Bod) = N_Entry_Body
1314 or else Nkind (Bod) = N_Package_Body
1315 or else Nkind (Bod) = N_Protected_Body
1316 or else Nkind (Bod) = N_Task_Body
1317 or else Nkind (Bod) in N_Body_Stub)
1319 List_Containing (After) = List_Containing (Parent (E))
1321 Error_Msg_Sloc := Sloc (Next (After));
1323 ("type& is frozen# before its full declaration",
1333 -- Start of processing for Freeze_All
1336 Freeze_All_Ent (From, After);
1338 -- Now that all types are frozen, we can deal with default expressions
1339 -- that require us to build a default expression functions. This is the
1340 -- point at which such functions are constructed (after all types that
1341 -- might be used in such expressions have been frozen).
1343 -- We also add finalization chains to access types whose designated
1344 -- types are controlled. This is normally done when freezing the type,
1345 -- but this misses recursive type definitions where the later members
1346 -- of the recursion introduce controlled components.
1348 -- Loop through entities
1351 while Present (E) loop
1352 if Is_Subprogram (E) then
1354 if not Default_Expressions_Processed (E) then
1355 Process_Default_Expressions (E, After);
1358 if not Has_Completion (E) then
1359 Decl := Unit_Declaration_Node (E);
1361 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1362 Build_And_Analyze_Renamed_Body (Decl, E, After);
1364 elsif Nkind (Decl) = N_Subprogram_Declaration
1365 and then Present (Corresponding_Body (Decl))
1367 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1368 = N_Subprogram_Renaming_Declaration
1370 Build_And_Analyze_Renamed_Body
1371 (Decl, Corresponding_Body (Decl), After);
1375 elsif Ekind (E) in Task_Kind
1377 (Nkind (Parent (E)) = N_Task_Type_Declaration
1379 Nkind (Parent (E)) = N_Single_Task_Declaration)
1384 Ent := First_Entity (E);
1386 while Present (Ent) loop
1389 and then not Default_Expressions_Processed (Ent)
1391 Process_Default_Expressions (Ent, After);
1398 elsif Is_Access_Type (E)
1399 and then Comes_From_Source (E)
1400 and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
1401 and then Needs_Finalization (Designated_Type (E))
1402 and then No (Associated_Final_Chain (E))
1404 Build_Final_List (Parent (E), E);
1411 -----------------------
1412 -- Freeze_And_Append --
1413 -----------------------
1415 procedure Freeze_And_Append
1418 Result : in out List_Id)
1420 L : constant List_Id := Freeze_Entity (Ent, Loc);
1422 if Is_Non_Empty_List (L) then
1423 if Result = No_List then
1426 Append_List (L, Result);
1429 end Freeze_And_Append;
1435 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1436 Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
1438 if Is_Non_Empty_List (Freeze_Nodes) then
1439 Insert_Actions (N, Freeze_Nodes);
1447 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
1448 Test_E : Entity_Id := E;
1456 Has_Default_Initialization : Boolean := False;
1457 -- This flag gets set to true for a variable with default initialization
1459 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1460 -- Check that an Access or Unchecked_Access attribute with a prefix
1461 -- which is the current instance type can only be applied when the type
1464 procedure Check_Suspicious_Modulus (Utype : Entity_Id);
1465 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1466 -- integer literal without an explicit corresponding size clause. The
1467 -- caller has checked that Utype is a modular integer type.
1469 function After_Last_Declaration return Boolean;
1470 -- If Loc is a freeze_entity that appears after the last declaration
1471 -- in the scope, inhibit error messages on late completion.
1473 procedure Freeze_Record_Type (Rec : Entity_Id);
1474 -- Freeze each component, handle some representation clauses, and freeze
1475 -- primitive operations if this is a tagged type.
1477 ----------------------------
1478 -- After_Last_Declaration --
1479 ----------------------------
1481 function After_Last_Declaration return Boolean is
1482 Spec : constant Node_Id := Parent (Current_Scope);
1484 if Nkind (Spec) = N_Package_Specification then
1485 if Present (Private_Declarations (Spec)) then
1486 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1487 elsif Present (Visible_Declarations (Spec)) then
1488 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1495 end After_Last_Declaration;
1497 ----------------------------
1498 -- Check_Current_Instance --
1499 ----------------------------
1501 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1503 Rec_Type : constant Entity_Id :=
1504 Scope (Defining_Identifier (Comp_Decl));
1506 Decl : constant Node_Id := Parent (Rec_Type);
1508 function Process (N : Node_Id) return Traverse_Result;
1509 -- Process routine to apply check to given node
1515 function Process (N : Node_Id) return Traverse_Result is
1518 when N_Attribute_Reference =>
1519 if (Attribute_Name (N) = Name_Access
1521 Attribute_Name (N) = Name_Unchecked_Access)
1522 and then Is_Entity_Name (Prefix (N))
1523 and then Is_Type (Entity (Prefix (N)))
1524 and then Entity (Prefix (N)) = E
1527 ("current instance must be a limited type", Prefix (N));
1533 when others => return OK;
1537 procedure Traverse is new Traverse_Proc (Process);
1539 -- Start of processing for Check_Current_Instance
1542 -- In Ada95, the (imprecise) rule is that the current instance of a
1543 -- limited type is aliased. In Ada2005, limitedness must be explicit:
1544 -- either a tagged type, or a limited record.
1546 if Is_Limited_Type (Rec_Type)
1547 and then (Ada_Version < Ada_05 or else Is_Tagged_Type (Rec_Type))
1551 elsif Nkind (Decl) = N_Full_Type_Declaration
1552 and then Limited_Present (Type_Definition (Decl))
1557 Traverse (Comp_Decl);
1559 end Check_Current_Instance;
1561 ------------------------------
1562 -- Check_Suspicious_Modulus --
1563 ------------------------------
1565 procedure Check_Suspicious_Modulus (Utype : Entity_Id) is
1566 Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype));
1569 if Nkind (Decl) = N_Full_Type_Declaration then
1571 Tdef : constant Node_Id := Type_Definition (Decl);
1573 if Nkind (Tdef) = N_Modular_Type_Definition then
1575 Modulus : constant Node_Id :=
1576 Original_Node (Expression (Tdef));
1578 if Nkind (Modulus) = N_Integer_Literal then
1580 Modv : constant Uint := Intval (Modulus);
1581 Sizv : constant Uint := RM_Size (Utype);
1584 -- First case, modulus and size are the same. This
1585 -- happens if you have something like mod 32, with
1586 -- an explicit size of 32, this is for sure a case
1587 -- where the warning is given, since it is seems
1588 -- very unlikely that someone would want e.g. a
1589 -- five bit type stored in 32 bits. It is much
1590 -- more likely they wanted a 32-bit type.
1595 -- Second case, the modulus is 32 or 64 and no
1596 -- size clause is present. This is a less clear
1597 -- case for giving the warning, but in the case
1598 -- of 32/64 (5-bit or 6-bit types) these seem rare
1599 -- enough that it is a likely error (and in any
1600 -- case using 2**5 or 2**6 in these cases seems
1601 -- clearer. We don't include 8 or 16 here, simply
1602 -- because in practice 3-bit and 4-bit types are
1603 -- more common and too many false positives if
1604 -- we warn in these cases.
1606 elsif not Has_Size_Clause (Utype)
1607 and then (Modv = Uint_32 or else Modv = Uint_64)
1611 -- No warning needed
1617 -- If we fall through, give warning
1619 Error_Msg_Uint_1 := Modv;
1621 ("?2 '*'*^' may have been intended here",
1629 end Check_Suspicious_Modulus;
1631 ------------------------
1632 -- Freeze_Record_Type --
1633 ------------------------
1635 procedure Freeze_Record_Type (Rec : Entity_Id) is
1642 pragma Warnings (Off, Junk);
1644 Unplaced_Component : Boolean := False;
1645 -- Set True if we find at least one component with no component
1646 -- clause (used to warn about useless Pack pragmas).
1648 Placed_Component : Boolean := False;
1649 -- Set True if we find at least one component with a component
1650 -- clause (used to warn about useless Bit_Order pragmas, and also
1651 -- to detect cases where Implicit_Packing may have an effect).
1653 All_Scalar_Components : Boolean := True;
1654 -- Set False if we encounter a component of a non-scalar type
1656 Scalar_Component_Total_RM_Size : Uint := Uint_0;
1657 Scalar_Component_Total_Esize : Uint := Uint_0;
1658 -- Accumulates total RM_Size values and total Esize values of all
1659 -- scalar components. Used for processing of Implicit_Packing.
1661 function Check_Allocator (N : Node_Id) return Node_Id;
1662 -- If N is an allocator, possibly wrapped in one or more level of
1663 -- qualified expression(s), return the inner allocator node, else
1666 procedure Check_Itype (Typ : Entity_Id);
1667 -- If the component subtype is an access to a constrained subtype of
1668 -- an already frozen type, make the subtype frozen as well. It might
1669 -- otherwise be frozen in the wrong scope, and a freeze node on
1670 -- subtype has no effect. Similarly, if the component subtype is a
1671 -- regular (not protected) access to subprogram, set the anonymous
1672 -- subprogram type to frozen as well, to prevent an out-of-scope
1673 -- freeze node at some eventual point of call. Protected operations
1674 -- are handled elsewhere.
1676 ---------------------
1677 -- Check_Allocator --
1678 ---------------------
1680 function Check_Allocator (N : Node_Id) return Node_Id is
1685 if Nkind (Inner) = N_Allocator then
1687 elsif Nkind (Inner) = N_Qualified_Expression then
1688 Inner := Expression (Inner);
1693 end Check_Allocator;
1699 procedure Check_Itype (Typ : Entity_Id) is
1700 Desig : constant Entity_Id := Designated_Type (Typ);
1703 if not Is_Frozen (Desig)
1704 and then Is_Frozen (Base_Type (Desig))
1706 Set_Is_Frozen (Desig);
1708 -- In addition, add an Itype_Reference to ensure that the
1709 -- access subtype is elaborated early enough. This cannot be
1710 -- done if the subtype may depend on discriminants.
1712 if Ekind (Comp) = E_Component
1713 and then Is_Itype (Etype (Comp))
1714 and then not Has_Discriminants (Rec)
1716 IR := Make_Itype_Reference (Sloc (Comp));
1717 Set_Itype (IR, Desig);
1720 Result := New_List (IR);
1722 Append (IR, Result);
1726 elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type
1727 and then Convention (Desig) /= Convention_Protected
1729 Set_Is_Frozen (Desig);
1733 -- Start of processing for Freeze_Record_Type
1736 -- If this is a subtype of a controlled type, declared without a
1737 -- constraint, the _controller may not appear in the component list
1738 -- if the parent was not frozen at the point of subtype declaration.
1739 -- Inherit the _controller component now.
1741 if Rec /= Base_Type (Rec)
1742 and then Has_Controlled_Component (Rec)
1744 if Nkind (Parent (Rec)) = N_Subtype_Declaration
1745 and then Is_Entity_Name (Subtype_Indication (Parent (Rec)))
1747 Set_First_Entity (Rec, First_Entity (Base_Type (Rec)));
1749 -- If this is an internal type without a declaration, as for
1750 -- record component, the base type may not yet be frozen, and its
1751 -- controller has not been created. Add an explicit freeze node
1752 -- for the itype, so it will be frozen after the base type. This
1753 -- freeze node is used to communicate with the expander, in order
1754 -- to create the controller for the enclosing record, and it is
1755 -- deleted afterwards (see exp_ch3). It must not be created when
1756 -- expansion is off, because it might appear in the wrong context
1757 -- for the back end.
1759 elsif Is_Itype (Rec)
1760 and then Has_Delayed_Freeze (Base_Type (Rec))
1762 Nkind (Associated_Node_For_Itype (Rec)) =
1763 N_Component_Declaration
1764 and then Expander_Active
1766 Ensure_Freeze_Node (Rec);
1770 -- Freeze components and embedded subtypes
1772 Comp := First_Entity (Rec);
1774 while Present (Comp) loop
1776 -- First handle the component case
1778 if Ekind (Comp) = E_Component
1779 or else Ekind (Comp) = E_Discriminant
1782 CC : constant Node_Id := Component_Clause (Comp);
1785 -- Freezing a record type freezes the type of each of its
1786 -- components. However, if the type of the component is
1787 -- part of this record, we do not want or need a separate
1788 -- Freeze_Node. Note that Is_Itype is wrong because that's
1789 -- also set in private type cases. We also can't check for
1790 -- the Scope being exactly Rec because of private types and
1791 -- record extensions.
1793 if Is_Itype (Etype (Comp))
1794 and then Is_Record_Type (Underlying_Type
1795 (Scope (Etype (Comp))))
1797 Undelay_Type (Etype (Comp));
1800 Freeze_And_Append (Etype (Comp), Loc, Result);
1802 -- Check for error of component clause given for variable
1803 -- sized type. We have to delay this test till this point,
1804 -- since the component type has to be frozen for us to know
1805 -- if it is variable length. We omit this test in a generic
1806 -- context, it will be applied at instantiation time.
1808 if Present (CC) then
1809 Placed_Component := True;
1811 if Inside_A_Generic then
1815 Size_Known_At_Compile_Time
1816 (Underlying_Type (Etype (Comp)))
1819 ("component clause not allowed for variable " &
1820 "length component", CC);
1824 Unplaced_Component := True;
1827 -- Case of component requires byte alignment
1829 if Must_Be_On_Byte_Boundary (Etype (Comp)) then
1831 -- Set the enclosing record to also require byte align
1833 Set_Must_Be_On_Byte_Boundary (Rec);
1835 -- Check for component clause that is inconsistent with
1836 -- the required byte boundary alignment.
1839 and then Normalized_First_Bit (Comp) mod
1840 System_Storage_Unit /= 0
1843 ("component & must be byte aligned",
1844 Component_Name (Component_Clause (Comp)));
1850 -- Gather data for possible Implicit_Packing later. Note that at
1851 -- this stage we might be dealing with a real component, or with
1852 -- an implicit subtype declaration.
1854 if not Is_Scalar_Type (Etype (Comp)) then
1855 All_Scalar_Components := False;
1857 Scalar_Component_Total_RM_Size :=
1858 Scalar_Component_Total_RM_Size + RM_Size (Etype (Comp));
1859 Scalar_Component_Total_Esize :=
1860 Scalar_Component_Total_Esize + Esize (Etype (Comp));
1863 -- If the component is an Itype with Delayed_Freeze and is either
1864 -- a record or array subtype and its base type has not yet been
1865 -- frozen, we must remove this from the entity list of this
1866 -- record and put it on the entity list of the scope of its base
1867 -- type. Note that we know that this is not the type of a
1868 -- component since we cleared Has_Delayed_Freeze for it in the
1869 -- previous loop. Thus this must be the Designated_Type of an
1870 -- access type, which is the type of a component.
1873 and then Is_Type (Scope (Comp))
1874 and then Is_Composite_Type (Comp)
1875 and then Base_Type (Comp) /= Comp
1876 and then Has_Delayed_Freeze (Comp)
1877 and then not Is_Frozen (Base_Type (Comp))
1880 Will_Be_Frozen : Boolean := False;
1884 -- We have a pretty bad kludge here. Suppose Rec is subtype
1885 -- being defined in a subprogram that's created as part of
1886 -- the freezing of Rec'Base. In that case, we know that
1887 -- Comp'Base must have already been frozen by the time we
1888 -- get to elaborate this because Gigi doesn't elaborate any
1889 -- bodies until it has elaborated all of the declarative
1890 -- part. But Is_Frozen will not be set at this point because
1891 -- we are processing code in lexical order.
1893 -- We detect this case by going up the Scope chain of Rec
1894 -- and seeing if we have a subprogram scope before reaching
1895 -- the top of the scope chain or that of Comp'Base. If we
1896 -- do, then mark that Comp'Base will actually be frozen. If
1897 -- so, we merely undelay it.
1900 while Present (S) loop
1901 if Is_Subprogram (S) then
1902 Will_Be_Frozen := True;
1904 elsif S = Scope (Base_Type (Comp)) then
1911 if Will_Be_Frozen then
1912 Undelay_Type (Comp);
1914 if Present (Prev) then
1915 Set_Next_Entity (Prev, Next_Entity (Comp));
1917 Set_First_Entity (Rec, Next_Entity (Comp));
1920 -- Insert in entity list of scope of base type (which
1921 -- must be an enclosing scope, because still unfrozen).
1923 Append_Entity (Comp, Scope (Base_Type (Comp)));
1927 -- If the component is an access type with an allocator as default
1928 -- value, the designated type will be frozen by the corresponding
1929 -- expression in init_proc. In order to place the freeze node for
1930 -- the designated type before that for the current record type,
1933 -- Same process if the component is an array of access types,
1934 -- initialized with an aggregate. If the designated type is
1935 -- private, it cannot contain allocators, and it is premature
1936 -- to freeze the type, so we check for this as well.
1938 elsif Is_Access_Type (Etype (Comp))
1939 and then Present (Parent (Comp))
1940 and then Present (Expression (Parent (Comp)))
1943 Alloc : constant Node_Id :=
1944 Check_Allocator (Expression (Parent (Comp)));
1947 if Present (Alloc) then
1949 -- If component is pointer to a classwide type, freeze
1950 -- the specific type in the expression being allocated.
1951 -- The expression may be a subtype indication, in which
1952 -- case freeze the subtype mark.
1954 if Is_Class_Wide_Type
1955 (Designated_Type (Etype (Comp)))
1957 if Is_Entity_Name (Expression (Alloc)) then
1959 (Entity (Expression (Alloc)), Loc, Result);
1961 Nkind (Expression (Alloc)) = N_Subtype_Indication
1964 (Entity (Subtype_Mark (Expression (Alloc))),
1968 elsif Is_Itype (Designated_Type (Etype (Comp))) then
1969 Check_Itype (Etype (Comp));
1973 (Designated_Type (Etype (Comp)), Loc, Result);
1978 elsif Is_Access_Type (Etype (Comp))
1979 and then Is_Itype (Designated_Type (Etype (Comp)))
1981 Check_Itype (Etype (Comp));
1983 elsif Is_Array_Type (Etype (Comp))
1984 and then Is_Access_Type (Component_Type (Etype (Comp)))
1985 and then Present (Parent (Comp))
1986 and then Nkind (Parent (Comp)) = N_Component_Declaration
1987 and then Present (Expression (Parent (Comp)))
1988 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
1989 and then Is_Fully_Defined
1990 (Designated_Type (Component_Type (Etype (Comp))))
1994 (Component_Type (Etype (Comp))), Loc, Result);
2001 -- Deal with pragma Bit_Order setting non-standard bit order
2003 if Reverse_Bit_Order (Rec) and then Base_Type (Rec) = Rec then
2004 if not Placed_Component then
2006 Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
2008 ("?Bit_Order specification has no effect", ADC);
2010 ("\?since no component clauses were specified", ADC);
2012 -- Here is where we do the processing for reversed bit order
2015 Adjust_Record_For_Reverse_Bit_Order (Rec);
2019 -- Complete error checking on record representation clause (e.g.
2020 -- overlap of components). This is called after adjusting the
2021 -- record for reverse bit order.
2024 RRC : constant Node_Id := Get_Record_Representation_Clause (Rec);
2026 if Present (RRC) then
2027 Check_Record_Representation_Clause (RRC);
2031 -- Set OK_To_Reorder_Components depending on debug flags
2033 if Rec = Base_Type (Rec)
2034 and then Convention (Rec) = Convention_Ada
2036 if (Has_Discriminants (Rec) and then Debug_Flag_Dot_V)
2038 (not Has_Discriminants (Rec) and then Debug_Flag_Dot_R)
2040 Set_OK_To_Reorder_Components (Rec);
2044 -- Check for useless pragma Pack when all components placed. We only
2045 -- do this check for record types, not subtypes, since a subtype may
2046 -- have all its components placed, and it still makes perfectly good
2047 -- sense to pack other subtypes or the parent type. We do not give
2048 -- this warning if Optimize_Alignment is set to Space, since the
2049 -- pragma Pack does have an effect in this case (it always resets
2050 -- the alignment to one).
2052 if Ekind (Rec) = E_Record_Type
2053 and then Is_Packed (Rec)
2054 and then not Unplaced_Component
2055 and then Optimize_Alignment /= 'S'
2057 -- Reset packed status. Probably not necessary, but we do it so
2058 -- that there is no chance of the back end doing something strange
2059 -- with this redundant indication of packing.
2061 Set_Is_Packed (Rec, False);
2063 -- Give warning if redundant constructs warnings on
2065 if Warn_On_Redundant_Constructs then
2067 ("?pragma Pack has no effect, no unplaced components",
2068 Get_Rep_Pragma (Rec, Name_Pack));
2072 -- If this is the record corresponding to a remote type, freeze the
2073 -- remote type here since that is what we are semantically freezing.
2074 -- This prevents the freeze node for that type in an inner scope.
2076 -- Also, Check for controlled components and unchecked unions.
2077 -- Finally, enforce the restriction that access attributes with a
2078 -- current instance prefix can only apply to limited types.
2080 if Ekind (Rec) = E_Record_Type then
2081 if Present (Corresponding_Remote_Type (Rec)) then
2083 (Corresponding_Remote_Type (Rec), Loc, Result);
2086 Comp := First_Component (Rec);
2087 while Present (Comp) loop
2089 -- Do not set Has_Controlled_Component on a class-wide
2090 -- equivalent type. See Make_CW_Equivalent_Type.
2092 if not Is_Class_Wide_Equivalent_Type (Rec)
2093 and then (Has_Controlled_Component (Etype (Comp))
2094 or else (Chars (Comp) /= Name_uParent
2095 and then Is_Controlled (Etype (Comp)))
2096 or else (Is_Protected_Type (Etype (Comp))
2098 (Corresponding_Record_Type
2100 and then Has_Controlled_Component
2101 (Corresponding_Record_Type
2104 Set_Has_Controlled_Component (Rec);
2108 if Has_Unchecked_Union (Etype (Comp)) then
2109 Set_Has_Unchecked_Union (Rec);
2112 if Has_Per_Object_Constraint (Comp) then
2114 -- Scan component declaration for likely misuses of current
2115 -- instance, either in a constraint or a default expression.
2117 Check_Current_Instance (Parent (Comp));
2120 Next_Component (Comp);
2124 Set_Component_Alignment_If_Not_Set (Rec);
2126 -- For first subtypes, check if there are any fixed-point fields with
2127 -- component clauses, where we must check the size. This is not done
2128 -- till the freeze point, since for fixed-point types, we do not know
2129 -- the size until the type is frozen. Similar processing applies to
2130 -- bit packed arrays.
2132 if Is_First_Subtype (Rec) then
2133 Comp := First_Component (Rec);
2135 while Present (Comp) loop
2136 if Present (Component_Clause (Comp))
2137 and then (Is_Fixed_Point_Type (Etype (Comp))
2139 Is_Bit_Packed_Array (Etype (Comp)))
2142 (Component_Name (Component_Clause (Comp)),
2148 Next_Component (Comp);
2152 -- Generate warning for applying C or C++ convention to a record
2153 -- with discriminants. This is suppressed for the unchecked union
2154 -- case, since the whole point in this case is interface C. We also
2155 -- do not generate this within instantiations, since we will have
2156 -- generated a message on the template.
2158 if Has_Discriminants (E)
2159 and then not Is_Unchecked_Union (E)
2160 and then (Convention (E) = Convention_C
2162 Convention (E) = Convention_CPP)
2163 and then Comes_From_Source (E)
2164 and then not In_Instance
2165 and then not Has_Warnings_Off (E)
2166 and then not Has_Warnings_Off (Base_Type (E))
2169 Cprag : constant Node_Id := Get_Rep_Pragma (E, Name_Convention);
2173 if Present (Cprag) then
2174 A2 := Next (First (Pragma_Argument_Associations (Cprag)));
2176 if Convention (E) = Convention_C then
2178 ("?variant record has no direct equivalent in C", A2);
2181 ("?variant record has no direct equivalent in C++", A2);
2185 ("\?use of convention for type& is dubious", A2, E);
2190 -- See if Size is too small as is (and implicit packing might help)
2192 if not Is_Packed (Rec)
2194 -- No implicit packing if even one component is explicitly placed
2196 and then not Placed_Component
2198 -- Must have size clause and all scalar components
2200 and then Has_Size_Clause (Rec)
2201 and then All_Scalar_Components
2203 -- Do not try implicit packing on records with discriminants, too
2204 -- complicated, especially in the variant record case.
2206 and then not Has_Discriminants (Rec)
2208 -- We can implicitly pack if the specified size of the record is
2209 -- less than the sum of the object sizes (no point in packing if
2210 -- this is not the case).
2212 and then Esize (Rec) < Scalar_Component_Total_Esize
2214 -- And the total RM size cannot be greater than the specified size
2215 -- since otherwise packing will not get us where we have to be!
2217 and then Esize (Rec) >= Scalar_Component_Total_RM_Size
2219 -- Never do implicit packing in CodePeer mode since we don't do
2220 -- any packing ever in this mode (why not???)
2222 and then not CodePeer_Mode
2224 -- If implicit packing enabled, do it
2226 if Implicit_Packing then
2227 Set_Is_Packed (Rec);
2229 -- Otherwise flag the size clause
2233 Sz : constant Node_Id := Size_Clause (Rec);
2235 Error_Msg_NE -- CODEFIX
2236 ("size given for& too small", Sz, Rec);
2237 Error_Msg_N -- CODEFIX
2238 ("\use explicit pragma Pack "
2239 & "or use pragma Implicit_Packing", Sz);
2243 end Freeze_Record_Type;
2245 -- Start of processing for Freeze_Entity
2248 -- We are going to test for various reasons why this entity need not be
2249 -- frozen here, but in the case of an Itype that's defined within a
2250 -- record, that test actually applies to the record.
2252 if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
2253 Test_E := Scope (E);
2254 elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
2255 and then Is_Record_Type (Underlying_Type (Scope (E)))
2257 Test_E := Underlying_Type (Scope (E));
2260 -- Do not freeze if already frozen since we only need one freeze node
2262 if Is_Frozen (E) then
2265 -- It is improper to freeze an external entity within a generic because
2266 -- its freeze node will appear in a non-valid context. The entity will
2267 -- be frozen in the proper scope after the current generic is analyzed.
2269 elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then
2272 -- Do not freeze a global entity within an inner scope created during
2273 -- expansion. A call to subprogram E within some internal procedure
2274 -- (a stream attribute for example) might require freezing E, but the
2275 -- freeze node must appear in the same declarative part as E itself.
2276 -- The two-pass elaboration mechanism in gigi guarantees that E will
2277 -- be frozen before the inner call is elaborated. We exclude constants
2278 -- from this test, because deferred constants may be frozen early, and
2279 -- must be diagnosed (e.g. in the case of a deferred constant being used
2280 -- in a default expression). If the enclosing subprogram comes from
2281 -- source, or is a generic instance, then the freeze point is the one
2282 -- mandated by the language, and we freeze the entity. A subprogram that
2283 -- is a child unit body that acts as a spec does not have a spec that
2284 -- comes from source, but can only come from source.
2286 elsif In_Open_Scopes (Scope (Test_E))
2287 and then Scope (Test_E) /= Current_Scope
2288 and then Ekind (Test_E) /= E_Constant
2291 S : Entity_Id := Current_Scope;
2294 while Present (S) loop
2295 if Is_Overloadable (S) then
2296 if Comes_From_Source (S)
2297 or else Is_Generic_Instance (S)
2298 or else Is_Child_Unit (S)
2310 -- Similarly, an inlined instance body may make reference to global
2311 -- entities, but these references cannot be the proper freezing point
2312 -- for them, and in the absence of inlining freezing will take place in
2313 -- their own scope. Normally instance bodies are analyzed after the
2314 -- enclosing compilation, and everything has been frozen at the proper
2315 -- place, but with front-end inlining an instance body is compiled
2316 -- before the end of the enclosing scope, and as a result out-of-order
2317 -- freezing must be prevented.
2319 elsif Front_End_Inlining
2320 and then In_Instance_Body
2321 and then Present (Scope (Test_E))
2324 S : Entity_Id := Scope (Test_E);
2327 while Present (S) loop
2328 if Is_Generic_Instance (S) then
2341 -- Here to freeze the entity
2346 -- Case of entity being frozen is other than a type
2348 if not Is_Type (E) then
2350 -- If entity is exported or imported and does not have an external
2351 -- name, now is the time to provide the appropriate default name.
2352 -- Skip this if the entity is stubbed, since we don't need a name
2353 -- for any stubbed routine. For the case on intrinsics, if no
2354 -- external name is specified, then calls will be handled in
2355 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed; if
2356 -- an external name is provided, then Expand_Intrinsic_Call leaves
2357 -- calls in place for expansion by GIGI.
2359 if (Is_Imported (E) or else Is_Exported (E))
2360 and then No (Interface_Name (E))
2361 and then Convention (E) /= Convention_Stubbed
2362 and then Convention (E) /= Convention_Intrinsic
2364 Set_Encoded_Interface_Name
2365 (E, Get_Default_External_Name (E));
2367 -- If entity is an atomic object appearing in a declaration and
2368 -- the expression is an aggregate, assign it to a temporary to
2369 -- ensure that the actual assignment is done atomically rather
2370 -- than component-wise (the assignment to the temp may be done
2371 -- component-wise, but that is harmless).
2374 and then Nkind (Parent (E)) = N_Object_Declaration
2375 and then Present (Expression (Parent (E)))
2376 and then Nkind (Expression (Parent (E))) = N_Aggregate
2378 Is_Atomic_Aggregate (Expression (Parent (E)), Etype (E))
2383 -- For a subprogram, freeze all parameter types and also the return
2384 -- type (RM 13.14(14)). However skip this for internal subprograms.
2385 -- This is also the point where any extra formal parameters are
2386 -- created since we now know whether the subprogram will use a
2387 -- foreign convention.
2389 if Is_Subprogram (E) then
2390 if not Is_Internal (E) then
2394 Warn_Node : Node_Id;
2397 -- Loop through formals
2399 Formal := First_Formal (E);
2400 while Present (Formal) loop
2401 F_Type := Etype (Formal);
2402 Freeze_And_Append (F_Type, Loc, Result);
2404 if Is_Private_Type (F_Type)
2405 and then Is_Private_Type (Base_Type (F_Type))
2406 and then No (Full_View (Base_Type (F_Type)))
2407 and then not Is_Generic_Type (F_Type)
2408 and then not Is_Derived_Type (F_Type)
2410 -- If the type of a formal is incomplete, subprogram
2411 -- is being frozen prematurely. Within an instance
2412 -- (but not within a wrapper package) this is an
2413 -- artifact of our need to regard the end of an
2414 -- instantiation as a freeze point. Otherwise it is
2415 -- a definite error.
2418 Set_Is_Frozen (E, False);
2421 elsif not After_Last_Declaration
2422 and then not Freezing_Library_Level_Tagged_Type
2424 Error_Msg_Node_1 := F_Type;
2426 ("type& must be fully defined before this point",
2431 -- Check suspicious parameter for C function. These tests
2432 -- apply only to exported/imported subprograms.
2434 if Warn_On_Export_Import
2435 and then Comes_From_Source (E)
2436 and then (Convention (E) = Convention_C
2438 Convention (E) = Convention_CPP)
2439 and then (Is_Imported (E) or else Is_Exported (E))
2440 and then Convention (E) /= Convention (Formal)
2441 and then not Has_Warnings_Off (E)
2442 and then not Has_Warnings_Off (F_Type)
2443 and then not Has_Warnings_Off (Formal)
2445 -- Qualify mention of formals with subprogram name
2447 Error_Msg_Qual_Level := 1;
2449 -- Check suspicious use of fat C pointer
2451 if Is_Access_Type (F_Type)
2452 and then Esize (F_Type) > Ttypes.System_Address_Size
2455 ("?type of & does not correspond to C pointer!",
2458 -- Check suspicious return of boolean
2460 elsif Root_Type (F_Type) = Standard_Boolean
2461 and then Convention (F_Type) = Convention_Ada
2462 and then not Has_Warnings_Off (F_Type)
2463 and then not Has_Size_Clause (F_Type)
2464 and then VM_Target = No_VM
2467 ("& is an 8-bit Ada Boolean?", Formal);
2469 ("\use appropriate corresponding type in C "
2470 & "(e.g. char)?", Formal);
2472 -- Check suspicious tagged type
2474 elsif (Is_Tagged_Type (F_Type)
2475 or else (Is_Access_Type (F_Type)
2478 (Designated_Type (F_Type))))
2479 and then Convention (E) = Convention_C
2482 ("?& involves a tagged type which does not "
2483 & "correspond to any C type!", Formal);
2485 -- Check wrong convention subprogram pointer
2487 elsif Ekind (F_Type) = E_Access_Subprogram_Type
2488 and then not Has_Foreign_Convention (F_Type)
2491 ("?subprogram pointer & should "
2492 & "have foreign convention!", Formal);
2493 Error_Msg_Sloc := Sloc (F_Type);
2495 ("\?add Convention pragma to declaration of &#",
2499 -- Turn off name qualification after message output
2501 Error_Msg_Qual_Level := 0;
2504 -- Check for unconstrained array in exported foreign
2507 if Has_Foreign_Convention (E)
2508 and then not Is_Imported (E)
2509 and then Is_Array_Type (F_Type)
2510 and then not Is_Constrained (F_Type)
2511 and then Warn_On_Export_Import
2513 -- Exclude VM case, since both .NET and JVM can handle
2514 -- unconstrained arrays without a problem.
2516 and then VM_Target = No_VM
2518 Error_Msg_Qual_Level := 1;
2520 -- If this is an inherited operation, place the
2521 -- warning on the derived type declaration, rather
2522 -- than on the original subprogram.
2524 if Nkind (Original_Node (Parent (E))) =
2525 N_Full_Type_Declaration
2527 Warn_Node := Parent (E);
2529 if Formal = First_Formal (E) then
2531 ("?in inherited operation&", Warn_Node, E);
2534 Warn_Node := Formal;
2538 ("?type of argument& is unconstrained array",
2541 ("?foreign caller must pass bounds explicitly",
2543 Error_Msg_Qual_Level := 0;
2546 if not From_With_Type (F_Type) then
2547 if Is_Access_Type (F_Type) then
2548 F_Type := Designated_Type (F_Type);
2551 -- If the formal is an anonymous_access_to_subprogram
2552 -- freeze the subprogram type as well, to prevent
2553 -- scope anomalies in gigi, because there is no other
2554 -- clear point at which it could be frozen.
2556 if Is_Itype (Etype (Formal))
2557 and then Ekind (F_Type) = E_Subprogram_Type
2559 Freeze_And_Append (F_Type, Loc, Result);
2563 Next_Formal (Formal);
2566 -- Case of function: similar checks on return type
2568 if Ekind (E) = E_Function then
2570 -- Freeze return type
2572 R_Type := Etype (E);
2573 Freeze_And_Append (R_Type, Loc, Result);
2575 -- Check suspicious return type for C function
2577 if Warn_On_Export_Import
2578 and then (Convention (E) = Convention_C
2580 Convention (E) = Convention_CPP)
2581 and then (Is_Imported (E) or else Is_Exported (E))
2583 -- Check suspicious return of fat C pointer
2585 if Is_Access_Type (R_Type)
2586 and then Esize (R_Type) > Ttypes.System_Address_Size
2587 and then not Has_Warnings_Off (E)
2588 and then not Has_Warnings_Off (R_Type)
2591 ("?return type of& does not "
2592 & "correspond to C pointer!", E);
2594 -- Check suspicious return of boolean
2596 elsif Root_Type (R_Type) = Standard_Boolean
2597 and then Convention (R_Type) = Convention_Ada
2598 and then VM_Target = No_VM
2599 and then not Has_Warnings_Off (E)
2600 and then not Has_Warnings_Off (R_Type)
2601 and then not Has_Size_Clause (R_Type)
2604 N : constant Node_Id :=
2605 Result_Definition (Declaration_Node (E));
2608 ("return type of & is an 8-bit Ada Boolean?",
2611 ("\use appropriate corresponding type in C "
2612 & "(e.g. char)?", N, E);
2615 -- Check suspicious return tagged type
2617 elsif (Is_Tagged_Type (R_Type)
2618 or else (Is_Access_Type (R_Type)
2621 (Designated_Type (R_Type))))
2622 and then Convention (E) = Convention_C
2623 and then not Has_Warnings_Off (E)
2624 and then not Has_Warnings_Off (R_Type)
2627 ("?return type of & does not "
2628 & "correspond to C type!", E);
2630 -- Check return of wrong convention subprogram pointer
2632 elsif Ekind (R_Type) = E_Access_Subprogram_Type
2633 and then not Has_Foreign_Convention (R_Type)
2634 and then not Has_Warnings_Off (E)
2635 and then not Has_Warnings_Off (R_Type)
2638 ("?& should return a foreign "
2639 & "convention subprogram pointer", E);
2640 Error_Msg_Sloc := Sloc (R_Type);
2642 ("\?add Convention pragma to declaration of& #",
2647 -- Give warning for suspicous return of a result of an
2648 -- unconstrained array type in a foreign convention
2651 if Has_Foreign_Convention (E)
2653 -- We are looking for a return of unconstrained array
2655 and then Is_Array_Type (R_Type)
2656 and then not Is_Constrained (R_Type)
2658 -- Exclude imported routines, the warning does not
2659 -- belong on the import, but on the routine definition.
2661 and then not Is_Imported (E)
2663 -- Exclude VM case, since both .NET and JVM can handle
2664 -- return of unconstrained arrays without a problem.
2666 and then VM_Target = No_VM
2668 -- Check that general warning is enabled, and that it
2669 -- is not suppressed for this particular case.
2671 and then Warn_On_Export_Import
2672 and then not Has_Warnings_Off (E)
2673 and then not Has_Warnings_Off (R_Type)
2676 ("?foreign convention function& should not " &
2677 "return unconstrained array!", E);
2683 -- Must freeze its parent first if it is a derived subprogram
2685 if Present (Alias (E)) then
2686 Freeze_And_Append (Alias (E), Loc, Result);
2689 -- We don't freeze internal subprograms, because we don't normally
2690 -- want addition of extra formals or mechanism setting to happen
2691 -- for those. However we do pass through predefined dispatching
2692 -- cases, since extra formals may be needed in some cases, such as
2693 -- for the stream 'Input function (build-in-place formals).
2695 if not Is_Internal (E)
2696 or else Is_Predefined_Dispatching_Operation (E)
2698 Freeze_Subprogram (E);
2701 -- Here for other than a subprogram or type
2704 -- If entity has a type, and it is not a generic unit, then
2705 -- freeze it first (RM 13.14(10)).
2707 if Present (Etype (E))
2708 and then Ekind (E) /= E_Generic_Function
2710 Freeze_And_Append (Etype (E), Loc, Result);
2713 -- Special processing for objects created by object declaration
2715 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
2717 -- Abstract type allowed only for C++ imported variables or
2720 -- Note: we inhibit this check for objects that do not come
2721 -- from source because there is at least one case (the
2722 -- expansion of x'class'input where x is abstract) where we
2723 -- legitimately generate an abstract object.
2725 if Is_Abstract_Type (Etype (E))
2726 and then Comes_From_Source (Parent (E))
2727 and then not (Is_Imported (E)
2728 and then Is_CPP_Class (Etype (E)))
2730 Error_Msg_N ("type of object cannot be abstract",
2731 Object_Definition (Parent (E)));
2733 if Is_CPP_Class (Etype (E)) then
2734 Error_Msg_NE ("\} may need a cpp_constructor",
2735 Object_Definition (Parent (E)), Etype (E));
2739 -- For object created by object declaration, perform required
2740 -- categorization (preelaborate and pure) checks. Defer these
2741 -- checks to freeze time since pragma Import inhibits default
2742 -- initialization and thus pragma Import affects these checks.
2744 Validate_Object_Declaration (Declaration_Node (E));
2746 -- If there is an address clause, check that it is valid
2748 Check_Address_Clause (E);
2750 -- If the object needs any kind of default initialization, an
2751 -- error must be issued if No_Default_Initialization applies.
2752 -- The check doesn't apply to imported objects, which are not
2753 -- ever default initialized, and is why the check is deferred
2754 -- until freezing, at which point we know if Import applies.
2755 -- Deferred constants are also exempted from this test because
2756 -- their completion is explicit, or through an import pragma.
2758 if Ekind (E) = E_Constant
2759 and then Present (Full_View (E))
2763 elsif Comes_From_Source (E)
2764 and then not Is_Imported (E)
2765 and then not Has_Init_Expression (Declaration_Node (E))
2767 ((Has_Non_Null_Base_Init_Proc (Etype (E))
2768 and then not No_Initialization (Declaration_Node (E))
2769 and then not Is_Value_Type (Etype (E))
2770 and then not Suppress_Init_Proc (Etype (E)))
2772 (Needs_Simple_Initialization (Etype (E))
2773 and then not Is_Internal (E)))
2775 Has_Default_Initialization := True;
2777 (No_Default_Initialization, Declaration_Node (E));
2780 -- Check that a Thread_Local_Storage variable does not have
2781 -- default initialization, and any explicit initialization must
2782 -- either be the null constant or a static constant.
2784 if Has_Pragma_Thread_Local_Storage (E) then
2786 Decl : constant Node_Id := Declaration_Node (E);
2788 if Has_Default_Initialization
2790 (Has_Init_Expression (Decl)
2792 (No (Expression (Decl))
2794 (Is_Static_Expression (Expression (Decl))
2796 Nkind (Expression (Decl)) = N_Null)))
2799 ("Thread_Local_Storage variable& is "
2800 & "improperly initialized", Decl, E);
2802 ("\only allowed initialization is explicit "
2803 & "NULL or static expression", Decl, E);
2808 -- For imported objects, set Is_Public unless there is also an
2809 -- address clause, which means that there is no external symbol
2810 -- needed for the Import (Is_Public may still be set for other
2811 -- unrelated reasons). Note that we delayed this processing
2812 -- till freeze time so that we can be sure not to set the flag
2813 -- if there is an address clause. If there is such a clause,
2814 -- then the only purpose of the Import pragma is to suppress
2815 -- implicit initialization.
2818 and then No (Address_Clause (E))
2823 -- For convention C objects of an enumeration type, warn if
2824 -- the size is not integer size and no explicit size given.
2825 -- Skip warning for Boolean, and Character, assume programmer
2826 -- expects 8-bit sizes for these cases.
2828 if (Convention (E) = Convention_C
2830 Convention (E) = Convention_CPP)
2831 and then Is_Enumeration_Type (Etype (E))
2832 and then not Is_Character_Type (Etype (E))
2833 and then not Is_Boolean_Type (Etype (E))
2834 and then Esize (Etype (E)) < Standard_Integer_Size
2835 and then not Has_Size_Clause (E)
2837 Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size);
2839 ("?convention C enumeration object has size less than ^",
2841 Error_Msg_N ("\?use explicit size clause to set size", E);
2845 -- Check that a constant which has a pragma Volatile[_Components]
2846 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
2848 -- Note: Atomic[_Components] also sets Volatile[_Components]
2850 if Ekind (E) = E_Constant
2851 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
2852 and then not Is_Imported (E)
2854 -- Make sure we actually have a pragma, and have not merely
2855 -- inherited the indication from elsewhere (e.g. an address
2856 -- clause, which is not good enough in RM terms!)
2858 if Has_Rep_Pragma (E, Name_Atomic)
2860 Has_Rep_Pragma (E, Name_Atomic_Components)
2863 ("stand alone atomic constant must be " &
2864 "imported (RM C.6(13))", E);
2866 elsif Has_Rep_Pragma (E, Name_Volatile)
2868 Has_Rep_Pragma (E, Name_Volatile_Components)
2871 ("stand alone volatile constant must be " &
2872 "imported (RM C.6(13))", E);
2876 -- Static objects require special handling
2878 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
2879 and then Is_Statically_Allocated (E)
2881 Freeze_Static_Object (E);
2884 -- Remaining step is to layout objects
2886 if Ekind (E) = E_Variable
2888 Ekind (E) = E_Constant
2890 Ekind (E) = E_Loop_Parameter
2898 -- Case of a type or subtype being frozen
2901 -- We used to check here that a full type must have preelaborable
2902 -- initialization if it completes a private type specified with
2903 -- pragma Preelaborable_Intialization, but that missed cases where
2904 -- the types occur within a generic package, since the freezing
2905 -- that occurs within a containing scope generally skips traversal
2906 -- of a generic unit's declarations (those will be frozen within
2907 -- instances). This check was moved to Analyze_Package_Specification.
2909 -- The type may be defined in a generic unit. This can occur when
2910 -- freezing a generic function that returns the type (which is
2911 -- defined in a parent unit). It is clearly meaningless to freeze
2912 -- this type. However, if it is a subtype, its size may be determi-
2913 -- nable and used in subsequent checks, so might as well try to
2916 if Present (Scope (E))
2917 and then Is_Generic_Unit (Scope (E))
2919 Check_Compile_Time_Size (E);
2923 -- Deal with special cases of freezing for subtype
2925 if E /= Base_Type (E) then
2927 -- Before we do anything else, a specialized test for the case of
2928 -- a size given for an array where the array needs to be packed,
2929 -- but was not so the size cannot be honored. This would of course
2930 -- be caught by the backend, and indeed we don't catch all cases.
2931 -- The point is that we can give a better error message in those
2932 -- cases that we do catch with the circuitry here. Also if pragma
2933 -- Implicit_Packing is set, this is where the packing occurs.
2935 -- The reason we do this so early is that the processing in the
2936 -- automatic packing case affects the layout of the base type, so
2937 -- it must be done before we freeze the base type.
2939 if Is_Array_Type (E) then
2942 Ctyp : constant Entity_Id := Component_Type (E);
2945 -- Check enabling conditions. These are straightforward
2946 -- except for the test for a limited composite type. This
2947 -- eliminates the rare case of a array of limited components
2948 -- where there are issues of whether or not we can go ahead
2949 -- and pack the array (since we can't freely pack and unpack
2950 -- arrays if they are limited).
2952 -- Note that we check the root type explicitly because the
2953 -- whole point is we are doing this test before we have had
2954 -- a chance to freeze the base type (and it is that freeze
2955 -- action that causes stuff to be inherited).
2957 if Present (Size_Clause (E))
2958 and then Known_Static_Esize (E)
2959 and then not Is_Packed (E)
2960 and then not Has_Pragma_Pack (E)
2961 and then Number_Dimensions (E) = 1
2962 and then not Has_Component_Size_Clause (E)
2963 and then Known_Static_Esize (Ctyp)
2964 and then not Is_Limited_Composite (E)
2965 and then not Is_Packed (Root_Type (E))
2966 and then not Has_Component_Size_Clause (Root_Type (E))
2967 and then not CodePeer_Mode
2969 Get_Index_Bounds (First_Index (E), Lo, Hi);
2971 if Compile_Time_Known_Value (Lo)
2972 and then Compile_Time_Known_Value (Hi)
2973 and then Known_Static_RM_Size (Ctyp)
2974 and then RM_Size (Ctyp) < 64
2977 Lov : constant Uint := Expr_Value (Lo);
2978 Hiv : constant Uint := Expr_Value (Hi);
2979 Len : constant Uint := UI_Max
2982 Rsiz : constant Uint := RM_Size (Ctyp);
2983 SZ : constant Node_Id := Size_Clause (E);
2984 Btyp : constant Entity_Id := Base_Type (E);
2986 -- What we are looking for here is the situation where
2987 -- the RM_Size given would be exactly right if there
2988 -- was a pragma Pack (resulting in the component size
2989 -- being the same as the RM_Size). Furthermore, the
2990 -- component type size must be an odd size (not a
2991 -- multiple of storage unit). If the component RM size
2992 -- is an exact number of storage units that is a power
2993 -- of two, the array is not packed and has a standard
2997 if RM_Size (E) = Len * Rsiz
2998 and then Rsiz mod System_Storage_Unit /= 0
3000 -- For implicit packing mode, just set the
3001 -- component size silently.
3003 if Implicit_Packing then
3004 Set_Component_Size (Btyp, Rsiz);
3005 Set_Is_Bit_Packed_Array (Btyp);
3006 Set_Is_Packed (Btyp);
3007 Set_Has_Non_Standard_Rep (Btyp);
3009 -- Otherwise give an error message
3013 ("size given for& too small", SZ, E);
3015 ("\use explicit pragma Pack "
3016 & "or use pragma Implicit_Packing", SZ);
3019 elsif RM_Size (E) = Len * Rsiz
3020 and then Implicit_Packing
3022 (Rsiz / System_Storage_Unit = 1
3023 or else Rsiz / System_Storage_Unit = 2
3024 or else Rsiz / System_Storage_Unit = 4)
3027 -- Not a packed array, but indicate the desired
3028 -- component size, for the back-end.
3030 Set_Component_Size (Btyp, Rsiz);
3038 -- If ancestor subtype present, freeze that first. Note that this
3039 -- will also get the base type frozen.
3041 Atype := Ancestor_Subtype (E);
3043 if Present (Atype) then
3044 Freeze_And_Append (Atype, Loc, Result);
3046 -- Otherwise freeze the base type of the entity before freezing
3047 -- the entity itself (RM 13.14(15)).
3049 elsif E /= Base_Type (E) then
3050 Freeze_And_Append (Base_Type (E), Loc, Result);
3053 -- For a derived type, freeze its parent type first (RM 13.14(15))
3055 elsif Is_Derived_Type (E) then
3056 Freeze_And_Append (Etype (E), Loc, Result);
3057 Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
3060 -- For array type, freeze index types and component type first
3061 -- before freezing the array (RM 13.14(15)).
3063 if Is_Array_Type (E) then
3065 Ctyp : constant Entity_Id := Component_Type (E);
3067 Non_Standard_Enum : Boolean := False;
3068 -- Set true if any of the index types is an enumeration type
3069 -- with a non-standard representation.
3072 Freeze_And_Append (Ctyp, Loc, Result);
3074 Indx := First_Index (E);
3075 while Present (Indx) loop
3076 Freeze_And_Append (Etype (Indx), Loc, Result);
3078 if Is_Enumeration_Type (Etype (Indx))
3079 and then Has_Non_Standard_Rep (Etype (Indx))
3081 Non_Standard_Enum := True;
3087 -- Processing that is done only for base types
3089 if Ekind (E) = E_Array_Type then
3091 -- Propagate flags for component type
3093 if Is_Controlled (Component_Type (E))
3094 or else Has_Controlled_Component (Ctyp)
3096 Set_Has_Controlled_Component (E);
3099 if Has_Unchecked_Union (Component_Type (E)) then
3100 Set_Has_Unchecked_Union (E);
3103 -- If packing was requested or if the component size was set
3104 -- explicitly, then see if bit packing is required. This
3105 -- processing is only done for base types, since all the
3106 -- representation aspects involved are type-related. This
3107 -- is not just an optimization, if we start processing the
3108 -- subtypes, they interfere with the settings on the base
3109 -- type (this is because Is_Packed has a slightly different
3110 -- meaning before and after freezing).
3117 if (Is_Packed (E) or else Has_Pragma_Pack (E))
3118 and then not Has_Atomic_Components (E)
3119 and then Known_Static_RM_Size (Ctyp)
3121 Csiz := UI_Max (RM_Size (Ctyp), 1);
3123 elsif Known_Component_Size (E) then
3124 Csiz := Component_Size (E);
3126 elsif not Known_Static_Esize (Ctyp) then
3130 Esiz := Esize (Ctyp);
3132 -- We can set the component size if it is less than
3133 -- 16, rounding it up to the next storage unit size.
3137 elsif Esiz <= 16 then
3143 -- Set component size up to match alignment if it
3144 -- would otherwise be less than the alignment. This
3145 -- deals with cases of types whose alignment exceeds
3146 -- their size (padded types).
3150 A : constant Uint := Alignment_In_Bits (Ctyp);
3159 -- Case of component size that may result in packing
3161 if 1 <= Csiz and then Csiz <= 64 then
3163 Ent : constant Entity_Id :=
3165 Pack_Pragma : constant Node_Id :=
3166 Get_Rep_Pragma (Ent, Name_Pack);
3167 Comp_Size_C : constant Node_Id :=
3168 Get_Attribute_Definition_Clause
3169 (Ent, Attribute_Component_Size);
3171 -- Warn if we have pack and component size so that
3172 -- the pack is ignored.
3174 -- Note: here we must check for the presence of a
3175 -- component size before checking for a Pack pragma
3176 -- to deal with the case where the array type is a
3177 -- derived type whose parent is currently private.
3179 if Present (Comp_Size_C)
3180 and then Has_Pragma_Pack (Ent)
3182 Error_Msg_Sloc := Sloc (Comp_Size_C);
3184 ("?pragma Pack for& ignored!",
3187 ("\?explicit component size given#!",
3191 -- Set component size if not already set by a
3192 -- component size clause.
3194 if not Present (Comp_Size_C) then
3195 Set_Component_Size (E, Csiz);
3198 -- Check for base type of 8, 16, 32 bits, where an
3199 -- unsigned subtype has a length one less than the
3200 -- base type (e.g. Natural subtype of Integer).
3202 -- In such cases, if a component size was not set
3203 -- explicitly, then generate a warning.
3205 if Has_Pragma_Pack (E)
3206 and then not Present (Comp_Size_C)
3208 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
3209 and then Esize (Base_Type (Ctyp)) = Csiz + 1
3211 Error_Msg_Uint_1 := Csiz;
3213 if Present (Pack_Pragma) then
3215 ("?pragma Pack causes component size "
3216 & "to be ^!", Pack_Pragma);
3218 ("\?use Component_Size to set "
3219 & "desired value!", Pack_Pragma);
3223 -- Actual packing is not needed for 8, 16, 32, 64.
3224 -- Also not needed for 24 if alignment is 1.
3230 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
3232 -- Here the array was requested to be packed,
3233 -- but the packing request had no effect, so
3234 -- Is_Packed is reset.
3236 -- Note: semantically this means that we lose
3237 -- track of the fact that a derived type
3238 -- inherited a pragma Pack that was non-
3239 -- effective, but that seems fine.
3241 -- We regard a Pack pragma as a request to set
3242 -- a representation characteristic, and this
3243 -- request may be ignored.
3245 Set_Is_Packed (Base_Type (E), False);
3247 -- In all other cases, packing is indeed needed
3250 Set_Has_Non_Standard_Rep (Base_Type (E));
3251 Set_Is_Bit_Packed_Array (Base_Type (E));
3252 Set_Is_Packed (Base_Type (E));
3258 -- Processing that is done only for subtypes
3261 -- Acquire alignment from base type
3263 if Unknown_Alignment (E) then
3264 Set_Alignment (E, Alignment (Base_Type (E)));
3265 Adjust_Esize_Alignment (E);
3269 -- For bit-packed arrays, check the size
3271 if Is_Bit_Packed_Array (E) and then Known_RM_Size (E) then
3273 SizC : constant Node_Id := Size_Clause (E);
3276 pragma Warnings (Off, Discard);
3279 -- It is not clear if it is possible to have no size
3280 -- clause at this stage, but it is not worth worrying
3281 -- about. Post error on the entity name in the size
3282 -- clause if present, else on the type entity itself.
3284 if Present (SizC) then
3285 Check_Size (Name (SizC), E, RM_Size (E), Discard);
3287 Check_Size (E, E, RM_Size (E), Discard);
3292 -- If any of the index types was an enumeration type with
3293 -- a non-standard rep clause, then we indicate that the
3294 -- array type is always packed (even if it is not bit packed).
3296 if Non_Standard_Enum then
3297 Set_Has_Non_Standard_Rep (Base_Type (E));
3298 Set_Is_Packed (Base_Type (E));
3301 Set_Component_Alignment_If_Not_Set (E);
3303 -- If the array is packed, we must create the packed array
3304 -- type to be used to actually implement the type. This is
3305 -- only needed for real array types (not for string literal
3306 -- types, since they are present only for the front end).
3309 and then Ekind (E) /= E_String_Literal_Subtype
3311 Create_Packed_Array_Type (E);
3312 Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
3314 -- Size information of packed array type is copied to the
3315 -- array type, since this is really the representation. But
3316 -- do not override explicit existing size values. If the
3317 -- ancestor subtype is constrained the packed_array_type
3318 -- will be inherited from it, but the size may have been
3319 -- provided already, and must not be overridden either.
3321 if not Has_Size_Clause (E)
3323 (No (Ancestor_Subtype (E))
3324 or else not Has_Size_Clause (Ancestor_Subtype (E)))
3326 Set_Esize (E, Esize (Packed_Array_Type (E)));
3327 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
3330 if not Has_Alignment_Clause (E) then
3331 Set_Alignment (E, Alignment (Packed_Array_Type (E)));
3335 -- For non-packed arrays set the alignment of the array to the
3336 -- alignment of the component type if it is unknown. Skip this
3337 -- in atomic case (atomic arrays may need larger alignments).
3339 if not Is_Packed (E)
3340 and then Unknown_Alignment (E)
3341 and then Known_Alignment (Ctyp)
3342 and then Known_Static_Component_Size (E)
3343 and then Known_Static_Esize (Ctyp)
3344 and then Esize (Ctyp) = Component_Size (E)
3345 and then not Is_Atomic (E)
3347 Set_Alignment (E, Alignment (Component_Type (E)));
3351 -- For a class-wide type, the corresponding specific type is
3352 -- frozen as well (RM 13.14(15))
3354 elsif Is_Class_Wide_Type (E) then
3355 Freeze_And_Append (Root_Type (E), Loc, Result);
3357 -- If the base type of the class-wide type is still incomplete,
3358 -- the class-wide remains unfrozen as well. This is legal when
3359 -- E is the formal of a primitive operation of some other type
3360 -- which is being frozen.
3362 if not Is_Frozen (Root_Type (E)) then
3363 Set_Is_Frozen (E, False);
3367 -- If the Class_Wide_Type is an Itype (when type is the anonymous
3368 -- parent of a derived type) and it is a library-level entity,
3369 -- generate an itype reference for it. Otherwise, its first
3370 -- explicit reference may be in an inner scope, which will be
3371 -- rejected by the back-end.
3374 and then Is_Compilation_Unit (Scope (E))
3377 Ref : constant Node_Id := Make_Itype_Reference (Loc);
3382 Result := New_List (Ref);
3384 Append (Ref, Result);
3389 -- The equivalent type associated with a class-wide subtype needs
3390 -- to be frozen to ensure that its layout is done.
3392 if Ekind (E) = E_Class_Wide_Subtype
3393 and then Present (Equivalent_Type (E))
3395 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
3398 -- For a record (sub)type, freeze all the component types (RM
3399 -- 13.14(15). We test for E_Record_(sub)Type here, rather than using
3400 -- Is_Record_Type, because we don't want to attempt the freeze for
3401 -- the case of a private type with record extension (we will do that
3402 -- later when the full type is frozen).
3404 elsif Ekind (E) = E_Record_Type
3405 or else Ekind (E) = E_Record_Subtype
3407 Freeze_Record_Type (E);
3409 -- For a concurrent type, freeze corresponding record type. This
3410 -- does not correspond to any specific rule in the RM, but the
3411 -- record type is essentially part of the concurrent type.
3412 -- Freeze as well all local entities. This includes record types
3413 -- created for entry parameter blocks, and whatever local entities
3414 -- may appear in the private part.
3416 elsif Is_Concurrent_Type (E) then
3417 if Present (Corresponding_Record_Type (E)) then
3419 (Corresponding_Record_Type (E), Loc, Result);
3422 Comp := First_Entity (E);
3423 while Present (Comp) loop
3424 if Is_Type (Comp) then
3425 Freeze_And_Append (Comp, Loc, Result);
3427 elsif (Ekind (Comp)) /= E_Function then
3428 if Is_Itype (Etype (Comp))
3429 and then Underlying_Type (Scope (Etype (Comp))) = E
3431 Undelay_Type (Etype (Comp));
3434 Freeze_And_Append (Etype (Comp), Loc, Result);
3440 -- Private types are required to point to the same freeze node as
3441 -- their corresponding full views. The freeze node itself has to
3442 -- point to the partial view of the entity (because from the partial
3443 -- view, we can retrieve the full view, but not the reverse).
3444 -- However, in order to freeze correctly, we need to freeze the full
3445 -- view. If we are freezing at the end of a scope (or within the
3446 -- scope of the private type), the partial and full views will have
3447 -- been swapped, the full view appears first in the entity chain and
3448 -- the swapping mechanism ensures that the pointers are properly set
3451 -- If we encounter the partial view before the full view (e.g. when
3452 -- freezing from another scope), we freeze the full view, and then
3453 -- set the pointers appropriately since we cannot rely on swapping to
3454 -- fix things up (subtypes in an outer scope might not get swapped).
3456 elsif Is_Incomplete_Or_Private_Type (E)
3457 and then not Is_Generic_Type (E)
3459 -- The construction of the dispatch table associated with library
3460 -- level tagged types forces freezing of all the primitives of the
3461 -- type, which may cause premature freezing of the partial view.
3465 -- type T is tagged private;
3466 -- type DT is new T with private;
3467 -- procedure Prim (X : in out T; Y : in out DT'class);
3469 -- type T is tagged null record;
3471 -- type DT is new T with null record;
3474 -- In this case the type will be frozen later by the usual
3475 -- mechanism: an object declaration, an instantiation, or the
3476 -- end of a declarative part.
3478 if Is_Library_Level_Tagged_Type (E)
3479 and then not Present (Full_View (E))
3481 Set_Is_Frozen (E, False);
3484 -- Case of full view present
3486 elsif Present (Full_View (E)) then
3488 -- If full view has already been frozen, then no further
3489 -- processing is required
3491 if Is_Frozen (Full_View (E)) then
3493 Set_Has_Delayed_Freeze (E, False);
3494 Set_Freeze_Node (E, Empty);
3495 Check_Debug_Info_Needed (E);
3497 -- Otherwise freeze full view and patch the pointers so that
3498 -- the freeze node will elaborate both views in the back-end.
3502 Full : constant Entity_Id := Full_View (E);
3505 if Is_Private_Type (Full)
3506 and then Present (Underlying_Full_View (Full))
3509 (Underlying_Full_View (Full), Loc, Result);
3512 Freeze_And_Append (Full, Loc, Result);
3514 if Has_Delayed_Freeze (E) then
3515 F_Node := Freeze_Node (Full);
3517 if Present (F_Node) then
3518 Set_Freeze_Node (E, F_Node);
3519 Set_Entity (F_Node, E);
3522 -- {Incomplete,Private}_Subtypes with Full_Views
3523 -- constrained by discriminants.
3525 Set_Has_Delayed_Freeze (E, False);
3526 Set_Freeze_Node (E, Empty);
3531 Check_Debug_Info_Needed (E);
3534 -- AI-117 requires that the convention of a partial view be the
3535 -- same as the convention of the full view. Note that this is a
3536 -- recognized breach of privacy, but it's essential for logical
3537 -- consistency of representation, and the lack of a rule in
3538 -- RM95 was an oversight.
3540 Set_Convention (E, Convention (Full_View (E)));
3542 Set_Size_Known_At_Compile_Time (E,
3543 Size_Known_At_Compile_Time (Full_View (E)));
3545 -- Size information is copied from the full view to the
3546 -- incomplete or private view for consistency.
3548 -- We skip this is the full view is not a type. This is very
3549 -- strange of course, and can only happen as a result of
3550 -- certain illegalities, such as a premature attempt to derive
3551 -- from an incomplete type.
3553 if Is_Type (Full_View (E)) then
3554 Set_Size_Info (E, Full_View (E));
3555 Set_RM_Size (E, RM_Size (Full_View (E)));
3560 -- Case of no full view present. If entity is derived or subtype,
3561 -- it is safe to freeze, correctness depends on the frozen status
3562 -- of parent. Otherwise it is either premature usage, or a Taft
3563 -- amendment type, so diagnosis is at the point of use and the
3564 -- type might be frozen later.
3566 elsif E /= Base_Type (E)
3567 or else Is_Derived_Type (E)
3572 Set_Is_Frozen (E, False);
3576 -- For access subprogram, freeze types of all formals, the return
3577 -- type was already frozen, since it is the Etype of the function.
3578 -- Formal types can be tagged Taft amendment types, but otherwise
3579 -- they cannot be incomplete.
3581 elsif Ekind (E) = E_Subprogram_Type then
3582 Formal := First_Formal (E);
3584 while Present (Formal) loop
3585 if Ekind (Etype (Formal)) = E_Incomplete_Type
3586 and then No (Full_View (Etype (Formal)))
3587 and then not Is_Value_Type (Etype (Formal))
3589 if Is_Tagged_Type (Etype (Formal)) then
3593 ("invalid use of incomplete type&", E, Etype (Formal));
3597 Freeze_And_Append (Etype (Formal), Loc, Result);
3598 Next_Formal (Formal);
3601 Freeze_Subprogram (E);
3603 -- For access to a protected subprogram, freeze the equivalent type
3604 -- (however this is not set if we are not generating code or if this
3605 -- is an anonymous type used just for resolution).
3607 elsif Is_Access_Protected_Subprogram_Type (E) then
3608 if Present (Equivalent_Type (E)) then
3609 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
3613 -- Generic types are never seen by the back-end, and are also not
3614 -- processed by the expander (since the expander is turned off for
3615 -- generic processing), so we never need freeze nodes for them.
3617 if Is_Generic_Type (E) then
3621 -- Some special processing for non-generic types to complete
3622 -- representation details not known till the freeze point.
3624 if Is_Fixed_Point_Type (E) then
3625 Freeze_Fixed_Point_Type (E);
3627 -- Some error checks required for ordinary fixed-point type. Defer
3628 -- these till the freeze-point since we need the small and range
3629 -- values. We only do these checks for base types
3631 if Is_Ordinary_Fixed_Point_Type (E)
3632 and then E = Base_Type (E)
3634 if Small_Value (E) < Ureal_2_M_80 then
3635 Error_Msg_Name_1 := Name_Small;
3637 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E);
3639 elsif Small_Value (E) > Ureal_2_80 then
3640 Error_Msg_Name_1 := Name_Small;
3642 ("`&''%` too large, maximum allowed is 2.0'*'*80", E);
3645 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
3646 Error_Msg_Name_1 := Name_First;
3648 ("`&''%` too small, minimum allowed is -10.0'*'*36", E);
3651 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
3652 Error_Msg_Name_1 := Name_Last;
3654 ("`&''%` too large, maximum allowed is 10.0'*'*36", E);
3658 elsif Is_Enumeration_Type (E) then
3659 Freeze_Enumeration_Type (E);
3661 elsif Is_Integer_Type (E) then
3662 Adjust_Esize_For_Alignment (E);
3664 if Is_Modular_Integer_Type (E)
3665 and then Warn_On_Suspicious_Modulus_Value
3667 Check_Suspicious_Modulus (E);
3670 elsif Is_Access_Type (E) then
3672 -- Check restriction for standard storage pool
3674 if No (Associated_Storage_Pool (E)) then
3675 Check_Restriction (No_Standard_Storage_Pools, E);
3678 -- Deal with error message for pure access type. This is not an
3679 -- error in Ada 2005 if there is no pool (see AI-366).
3681 if Is_Pure_Unit_Access_Type (E)
3682 and then (Ada_Version < Ada_05
3683 or else not No_Pool_Assigned (E))
3685 Error_Msg_N ("named access type not allowed in pure unit", E);
3687 if Ada_Version >= Ada_05 then
3689 ("\would be legal if Storage_Size of 0 given?", E);
3691 elsif No_Pool_Assigned (E) then
3693 ("\would be legal in Ada 2005?", E);
3697 ("\would be legal in Ada 2005 if "
3698 & "Storage_Size of 0 given?", E);
3703 -- Case of composite types
3705 if Is_Composite_Type (E) then
3707 -- AI-117 requires that all new primitives of a tagged type must
3708 -- inherit the convention of the full view of the type. Inherited
3709 -- and overriding operations are defined to inherit the convention
3710 -- of their parent or overridden subprogram (also specified in
3711 -- AI-117), which will have occurred earlier (in Derive_Subprogram
3712 -- and New_Overloaded_Entity). Here we set the convention of
3713 -- primitives that are still convention Ada, which will ensure
3714 -- that any new primitives inherit the type's convention. Class-
3715 -- wide types can have a foreign convention inherited from their
3716 -- specific type, but are excluded from this since they don't have
3717 -- any associated primitives.
3719 if Is_Tagged_Type (E)
3720 and then not Is_Class_Wide_Type (E)
3721 and then Convention (E) /= Convention_Ada
3724 Prim_List : constant Elist_Id := Primitive_Operations (E);
3727 Prim := First_Elmt (Prim_List);
3728 while Present (Prim) loop
3729 if Convention (Node (Prim)) = Convention_Ada then
3730 Set_Convention (Node (Prim), Convention (E));
3739 -- Now that all types from which E may depend are frozen, see if the
3740 -- size is known at compile time, if it must be unsigned, or if
3741 -- strict alignment is required
3743 Check_Compile_Time_Size (E);
3744 Check_Unsigned_Type (E);
3746 if Base_Type (E) = E then
3747 Check_Strict_Alignment (E);
3750 -- Do not allow a size clause for a type which does not have a size
3751 -- that is known at compile time
3753 if Has_Size_Clause (E)
3754 and then not Size_Known_At_Compile_Time (E)
3756 -- Suppress this message if errors posted on E, even if we are
3757 -- in all errors mode, since this is often a junk message
3759 if not Error_Posted (E) then
3761 ("size clause not allowed for variable length type",
3766 -- Remaining process is to set/verify the representation information,
3767 -- in particular the size and alignment values. This processing is
3768 -- not required for generic types, since generic types do not play
3769 -- any part in code generation, and so the size and alignment values
3770 -- for such types are irrelevant.
3772 if Is_Generic_Type (E) then
3775 -- Otherwise we call the layout procedure
3781 -- End of freeze processing for type entities
3784 -- Here is where we logically freeze the current entity. If it has a
3785 -- freeze node, then this is the point at which the freeze node is
3786 -- linked into the result list.
3788 if Has_Delayed_Freeze (E) then
3790 -- If a freeze node is already allocated, use it, otherwise allocate
3791 -- a new one. The preallocation happens in the case of anonymous base
3792 -- types, where we preallocate so that we can set First_Subtype_Link.
3793 -- Note that we reset the Sloc to the current freeze location.
3795 if Present (Freeze_Node (E)) then
3796 F_Node := Freeze_Node (E);
3797 Set_Sloc (F_Node, Loc);
3800 F_Node := New_Node (N_Freeze_Entity, Loc);
3801 Set_Freeze_Node (E, F_Node);
3802 Set_Access_Types_To_Process (F_Node, No_Elist);
3803 Set_TSS_Elist (F_Node, No_Elist);
3804 Set_Actions (F_Node, No_List);
3807 Set_Entity (F_Node, E);
3809 if Result = No_List then
3810 Result := New_List (F_Node);
3812 Append (F_Node, Result);
3815 -- A final pass over record types with discriminants. If the type
3816 -- has an incomplete declaration, there may be constrained access
3817 -- subtypes declared elsewhere, which do not depend on the discrimi-
3818 -- nants of the type, and which are used as component types (i.e.
3819 -- the full view is a recursive type). The designated types of these
3820 -- subtypes can only be elaborated after the type itself, and they
3821 -- need an itype reference.
3823 if Ekind (E) = E_Record_Type
3824 and then Has_Discriminants (E)
3832 Comp := First_Component (E);
3834 while Present (Comp) loop
3835 Typ := Etype (Comp);
3837 if Ekind (Comp) = E_Component
3838 and then Is_Access_Type (Typ)
3839 and then Scope (Typ) /= E
3840 and then Base_Type (Designated_Type (Typ)) = E
3841 and then Is_Itype (Designated_Type (Typ))
3843 IR := Make_Itype_Reference (Sloc (Comp));
3844 Set_Itype (IR, Designated_Type (Typ));
3845 Append (IR, Result);
3848 Next_Component (Comp);
3854 -- When a type is frozen, the first subtype of the type is frozen as
3855 -- well (RM 13.14(15)). This has to be done after freezing the type,
3856 -- since obviously the first subtype depends on its own base type.
3859 Freeze_And_Append (First_Subtype (E), Loc, Result);
3861 -- If we just froze a tagged non-class wide record, then freeze the
3862 -- corresponding class-wide type. This must be done after the tagged
3863 -- type itself is frozen, because the class-wide type refers to the
3864 -- tagged type which generates the class.
3866 if Is_Tagged_Type (E)
3867 and then not Is_Class_Wide_Type (E)
3868 and then Present (Class_Wide_Type (E))
3870 Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
3874 Check_Debug_Info_Needed (E);
3876 -- Special handling for subprograms
3878 if Is_Subprogram (E) then
3880 -- If subprogram has address clause then reset Is_Public flag, since
3881 -- we do not want the backend to generate external references.
3883 if Present (Address_Clause (E))
3884 and then not Is_Library_Level_Entity (E)
3886 Set_Is_Public (E, False);
3888 -- If no address clause and not intrinsic, then for imported
3889 -- subprogram in main unit, generate descriptor if we are in
3890 -- Propagate_Exceptions mode.
3892 elsif Propagate_Exceptions
3893 and then Is_Imported (E)
3894 and then not Is_Intrinsic_Subprogram (E)
3895 and then Convention (E) /= Convention_Stubbed
3897 if Result = No_List then
3898 Result := Empty_List;
3906 -----------------------------
3907 -- Freeze_Enumeration_Type --
3908 -----------------------------
3910 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
3912 -- By default, if no size clause is present, an enumeration type with
3913 -- Convention C is assumed to interface to a C enum, and has integer
3914 -- size. This applies to types. For subtypes, verify that its base
3915 -- type has no size clause either.
3917 if Has_Foreign_Convention (Typ)
3918 and then not Has_Size_Clause (Typ)
3919 and then not Has_Size_Clause (Base_Type (Typ))
3920 and then Esize (Typ) < Standard_Integer_Size
3922 Init_Esize (Typ, Standard_Integer_Size);
3925 -- If the enumeration type interfaces to C, and it has a size clause
3926 -- that specifies less than int size, it warrants a warning. The
3927 -- user may intend the C type to be an enum or a char, so this is
3928 -- not by itself an error that the Ada compiler can detect, but it
3929 -- it is a worth a heads-up. For Boolean and Character types we
3930 -- assume that the programmer has the proper C type in mind.
3932 if Convention (Typ) = Convention_C
3933 and then Has_Size_Clause (Typ)
3934 and then Esize (Typ) /= Esize (Standard_Integer)
3935 and then not Is_Boolean_Type (Typ)
3936 and then not Is_Character_Type (Typ)
3939 ("C enum types have the size of a C int?", Size_Clause (Typ));
3942 Adjust_Esize_For_Alignment (Typ);
3944 end Freeze_Enumeration_Type;
3946 -----------------------
3947 -- Freeze_Expression --
3948 -----------------------
3950 procedure Freeze_Expression (N : Node_Id) is
3951 In_Spec_Exp : constant Boolean := In_Spec_Expression;
3954 Desig_Typ : Entity_Id;
3958 Freeze_Outside : Boolean := False;
3959 -- This flag is set true if the entity must be frozen outside the
3960 -- current subprogram. This happens in the case of expander generated
3961 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
3962 -- not freeze all entities like other bodies, but which nevertheless
3963 -- may reference entities that have to be frozen before the body and
3964 -- obviously cannot be frozen inside the body.
3966 function In_Exp_Body (N : Node_Id) return Boolean;
3967 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
3968 -- it is the handled statement sequence of an expander-generated
3969 -- subprogram (init proc, stream subprogram, or renaming as body).
3970 -- If so, this is not a freezing context.
3976 function In_Exp_Body (N : Node_Id) return Boolean is
3981 if Nkind (N) = N_Subprogram_Body then
3987 if Nkind (P) /= N_Subprogram_Body then
3991 Id := Defining_Unit_Name (Specification (P));
3993 if Nkind (Id) = N_Defining_Identifier
3994 and then (Is_Init_Proc (Id) or else
3995 Is_TSS (Id, TSS_Stream_Input) or else
3996 Is_TSS (Id, TSS_Stream_Output) or else
3997 Is_TSS (Id, TSS_Stream_Read) or else
3998 Is_TSS (Id, TSS_Stream_Write) or else
3999 Nkind (Original_Node (P)) =
4000 N_Subprogram_Renaming_Declaration)
4009 -- Start of processing for Freeze_Expression
4012 -- Immediate return if freezing is inhibited. This flag is set by the
4013 -- analyzer to stop freezing on generated expressions that would cause
4014 -- freezing if they were in the source program, but which are not
4015 -- supposed to freeze, since they are created.
4017 if Must_Not_Freeze (N) then
4021 -- If expression is non-static, then it does not freeze in a default
4022 -- expression, see section "Handling of Default Expressions" in the
4023 -- spec of package Sem for further details. Note that we have to
4024 -- make sure that we actually have a real expression (if we have
4025 -- a subtype indication, we can't test Is_Static_Expression!)
4028 and then Nkind (N) in N_Subexpr
4029 and then not Is_Static_Expression (N)
4034 -- Freeze type of expression if not frozen already
4038 if Nkind (N) in N_Has_Etype then
4039 if not Is_Frozen (Etype (N)) then
4042 -- Base type may be an derived numeric type that is frozen at
4043 -- the point of declaration, but first_subtype is still unfrozen.
4045 elsif not Is_Frozen (First_Subtype (Etype (N))) then
4046 Typ := First_Subtype (Etype (N));
4050 -- For entity name, freeze entity if not frozen already. A special
4051 -- exception occurs for an identifier that did not come from source.
4052 -- We don't let such identifiers freeze a non-internal entity, i.e.
4053 -- an entity that did come from source, since such an identifier was
4054 -- generated by the expander, and cannot have any semantic effect on
4055 -- the freezing semantics. For example, this stops the parameter of
4056 -- an initialization procedure from freezing the variable.
4058 if Is_Entity_Name (N)
4059 and then not Is_Frozen (Entity (N))
4060 and then (Nkind (N) /= N_Identifier
4061 or else Comes_From_Source (N)
4062 or else not Comes_From_Source (Entity (N)))
4069 -- For an allocator freeze designated type if not frozen already
4071 -- For an aggregate whose component type is an access type, freeze the
4072 -- designated type now, so that its freeze does not appear within the
4073 -- loop that might be created in the expansion of the aggregate. If the
4074 -- designated type is a private type without full view, the expression
4075 -- cannot contain an allocator, so the type is not frozen.
4077 -- For a function, we freeze the entity when the subprogram declaration
4078 -- is frozen, but a function call may appear in an initialization proc.
4079 -- before the declaration is frozen. We need to generate the extra
4080 -- formals, if any, to ensure that the expansion of the call includes
4081 -- the proper actuals. This only applies to Ada subprograms, not to
4088 Desig_Typ := Designated_Type (Etype (N));
4091 if Is_Array_Type (Etype (N))
4092 and then Is_Access_Type (Component_Type (Etype (N)))
4094 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
4097 when N_Selected_Component |
4098 N_Indexed_Component |
4101 if Is_Access_Type (Etype (Prefix (N))) then
4102 Desig_Typ := Designated_Type (Etype (Prefix (N)));
4105 when N_Identifier =>
4107 and then Ekind (Nam) = E_Function
4108 and then Nkind (Parent (N)) = N_Function_Call
4109 and then Convention (Nam) = Convention_Ada
4111 Create_Extra_Formals (Nam);
4118 if Desig_Typ /= Empty
4119 and then (Is_Frozen (Desig_Typ)
4120 or else (not Is_Fully_Defined (Desig_Typ)))
4125 -- All done if nothing needs freezing
4129 and then No (Desig_Typ)
4134 -- Loop for looking at the right place to insert the freeze nodes,
4135 -- exiting from the loop when it is appropriate to insert the freeze
4136 -- node before the current node P.
4138 -- Also checks some special exceptions to the freezing rules. These
4139 -- cases result in a direct return, bypassing the freeze action.
4143 Parent_P := Parent (P);
4145 -- If we don't have a parent, then we are not in a well-formed tree.
4146 -- This is an unusual case, but there are some legitimate situations
4147 -- in which this occurs, notably when the expressions in the range of
4148 -- a type declaration are resolved. We simply ignore the freeze
4149 -- request in this case. Is this right ???
4151 if No (Parent_P) then
4155 -- See if we have got to an appropriate point in the tree
4157 case Nkind (Parent_P) is
4159 -- A special test for the exception of (RM 13.14(8)) for the case
4160 -- of per-object expressions (RM 3.8(18)) occurring in component
4161 -- definition or a discrete subtype definition. Note that we test
4162 -- for a component declaration which includes both cases we are
4163 -- interested in, and furthermore the tree does not have explicit
4164 -- nodes for either of these two constructs.
4166 when N_Component_Declaration =>
4168 -- The case we want to test for here is an identifier that is
4169 -- a per-object expression, this is either a discriminant that
4170 -- appears in a context other than the component declaration
4171 -- or it is a reference to the type of the enclosing construct.
4173 -- For either of these cases, we skip the freezing
4175 if not In_Spec_Expression
4176 and then Nkind (N) = N_Identifier
4177 and then (Present (Entity (N)))
4179 -- We recognize the discriminant case by just looking for
4180 -- a reference to a discriminant. It can only be one for
4181 -- the enclosing construct. Skip freezing in this case.
4183 if Ekind (Entity (N)) = E_Discriminant then
4186 -- For the case of a reference to the enclosing record,
4187 -- (or task or protected type), we look for a type that
4188 -- matches the current scope.
4190 elsif Entity (N) = Current_Scope then
4195 -- If we have an enumeration literal that appears as the choice in
4196 -- the aggregate of an enumeration representation clause, then
4197 -- freezing does not occur (RM 13.14(10)).
4199 when N_Enumeration_Representation_Clause =>
4201 -- The case we are looking for is an enumeration literal
4203 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
4204 and then Is_Enumeration_Type (Etype (N))
4206 -- If enumeration literal appears directly as the choice,
4207 -- do not freeze (this is the normal non-overloaded case)
4209 if Nkind (Parent (N)) = N_Component_Association
4210 and then First (Choices (Parent (N))) = N
4214 -- If enumeration literal appears as the name of function
4215 -- which is the choice, then also do not freeze. This
4216 -- happens in the overloaded literal case, where the
4217 -- enumeration literal is temporarily changed to a function
4218 -- call for overloading analysis purposes.
4220 elsif Nkind (Parent (N)) = N_Function_Call
4222 Nkind (Parent (Parent (N))) = N_Component_Association
4224 First (Choices (Parent (Parent (N)))) = Parent (N)
4230 -- Normally if the parent is a handled sequence of statements,
4231 -- then the current node must be a statement, and that is an
4232 -- appropriate place to insert a freeze node.
4234 when N_Handled_Sequence_Of_Statements =>
4236 -- An exception occurs when the sequence of statements is for
4237 -- an expander generated body that did not do the usual freeze
4238 -- all operation. In this case we usually want to freeze
4239 -- outside this body, not inside it, and we skip past the
4240 -- subprogram body that we are inside.
4242 if In_Exp_Body (Parent_P) then
4244 -- However, we *do* want to freeze at this point if we have
4245 -- an entity to freeze, and that entity is declared *inside*
4246 -- the body of the expander generated procedure. This case
4247 -- is recognized by the scope of the type, which is either
4248 -- the spec for some enclosing body, or (in the case of
4249 -- init_procs, for which there are no separate specs) the
4253 Subp : constant Node_Id := Parent (Parent_P);
4257 if Nkind (Subp) = N_Subprogram_Body then
4258 Cspc := Corresponding_Spec (Subp);
4260 if (Present (Typ) and then Scope (Typ) = Cspc)
4262 (Present (Nam) and then Scope (Nam) = Cspc)
4267 and then Scope (Typ) = Current_Scope
4268 and then Current_Scope = Defining_Entity (Subp)
4275 -- If not that exception to the exception, then this is
4276 -- where we delay the freeze till outside the body.
4278 Parent_P := Parent (Parent_P);
4279 Freeze_Outside := True;
4281 -- Here if normal case where we are in handled statement
4282 -- sequence and want to do the insertion right there.
4288 -- If parent is a body or a spec or a block, then the current node
4289 -- is a statement or declaration and we can insert the freeze node
4292 when N_Package_Specification |
4298 N_Block_Statement => exit;
4300 -- The expander is allowed to define types in any statements list,
4301 -- so any of the following parent nodes also mark a freezing point
4302 -- if the actual node is in a list of statements or declarations.
4304 when N_Exception_Handler |
4307 N_Case_Statement_Alternative |
4308 N_Compilation_Unit_Aux |
4309 N_Selective_Accept |
4310 N_Accept_Alternative |
4311 N_Delay_Alternative |
4312 N_Conditional_Entry_Call |
4313 N_Entry_Call_Alternative |
4314 N_Triggering_Alternative |
4320 exit when Is_List_Member (P);
4322 -- Note: The N_Loop_Statement is a special case. A type that
4323 -- appears in the source can never be frozen in a loop (this
4324 -- occurs only because of a loop expanded by the expander), so we
4325 -- keep on going. Otherwise we terminate the search. Same is true
4326 -- of any entity which comes from source. (if they have predefined
4327 -- type, that type does not appear to come from source, but the
4328 -- entity should not be frozen here).
4330 when N_Loop_Statement =>
4331 exit when not Comes_From_Source (Etype (N))
4332 and then (No (Nam) or else not Comes_From_Source (Nam));
4334 -- For all other cases, keep looking at parents
4340 -- We fall through the case if we did not yet find the proper
4341 -- place in the free for inserting the freeze node, so climb!
4346 -- If the expression appears in a record or an initialization procedure,
4347 -- the freeze nodes are collected and attached to the current scope, to
4348 -- be inserted and analyzed on exit from the scope, to insure that
4349 -- generated entities appear in the correct scope. If the expression is
4350 -- a default for a discriminant specification, the scope is still void.
4351 -- The expression can also appear in the discriminant part of a private
4352 -- or concurrent type.
4354 -- If the expression appears in a constrained subcomponent of an
4355 -- enclosing record declaration, the freeze nodes must be attached to
4356 -- the outer record type so they can eventually be placed in the
4357 -- enclosing declaration list.
4359 -- The other case requiring this special handling is if we are in a
4360 -- default expression, since in that case we are about to freeze a
4361 -- static type, and the freeze scope needs to be the outer scope, not
4362 -- the scope of the subprogram with the default parameter.
4364 -- For default expressions and other spec expressions in generic units,
4365 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
4366 -- placing them at the proper place, after the generic unit.
4368 if (In_Spec_Exp and not Inside_A_Generic)
4369 or else Freeze_Outside
4370 or else (Is_Type (Current_Scope)
4371 and then (not Is_Concurrent_Type (Current_Scope)
4372 or else not Has_Completion (Current_Scope)))
4373 or else Ekind (Current_Scope) = E_Void
4376 Loc : constant Source_Ptr := Sloc (Current_Scope);
4377 Freeze_Nodes : List_Id := No_List;
4378 Pos : Int := Scope_Stack.Last;
4381 if Present (Desig_Typ) then
4382 Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
4385 if Present (Typ) then
4386 Freeze_And_Append (Typ, Loc, Freeze_Nodes);
4389 if Present (Nam) then
4390 Freeze_And_Append (Nam, Loc, Freeze_Nodes);
4393 -- The current scope may be that of a constrained component of
4394 -- an enclosing record declaration, which is above the current
4395 -- scope in the scope stack.
4397 if Is_Record_Type (Scope (Current_Scope)) then
4401 if Is_Non_Empty_List (Freeze_Nodes) then
4402 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
4403 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
4406 Append_List (Freeze_Nodes, Scope_Stack.Table
4407 (Pos).Pending_Freeze_Actions);
4415 -- Now we have the right place to do the freezing. First, a special
4416 -- adjustment, if we are in spec-expression analysis mode, these freeze
4417 -- actions must not be thrown away (normally all inserted actions are
4418 -- thrown away in this mode. However, the freeze actions are from static
4419 -- expressions and one of the important reasons we are doing this
4420 -- special analysis is to get these freeze actions. Therefore we turn
4421 -- off the In_Spec_Expression mode to propagate these freeze actions.
4422 -- This also means they get properly analyzed and expanded.
4424 In_Spec_Expression := False;
4426 -- Freeze the designated type of an allocator (RM 13.14(13))
4428 if Present (Desig_Typ) then
4429 Freeze_Before (P, Desig_Typ);
4432 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
4433 -- the enumeration representation clause exception in the loop above.
4435 if Present (Typ) then
4436 Freeze_Before (P, Typ);
4439 -- Freeze name if one is present (RM 13.14(11))
4441 if Present (Nam) then
4442 Freeze_Before (P, Nam);
4445 -- Restore In_Spec_Expression flag
4447 In_Spec_Expression := In_Spec_Exp;
4448 end Freeze_Expression;
4450 -----------------------------
4451 -- Freeze_Fixed_Point_Type --
4452 -----------------------------
4454 -- Certain fixed-point types and subtypes, including implicit base types
4455 -- and declared first subtypes, have not yet set up a range. This is
4456 -- because the range cannot be set until the Small and Size values are
4457 -- known, and these are not known till the type is frozen.
4459 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
4460 -- whose bounds are unanalyzed real literals. This routine will recognize
4461 -- this case, and transform this range node into a properly typed range
4462 -- with properly analyzed and resolved values.
4464 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
4465 Rng : constant Node_Id := Scalar_Range (Typ);
4466 Lo : constant Node_Id := Low_Bound (Rng);
4467 Hi : constant Node_Id := High_Bound (Rng);
4468 Btyp : constant Entity_Id := Base_Type (Typ);
4469 Brng : constant Node_Id := Scalar_Range (Btyp);
4470 BLo : constant Node_Id := Low_Bound (Brng);
4471 BHi : constant Node_Id := High_Bound (Brng);
4472 Small : constant Ureal := Small_Value (Typ);
4479 function Fsize (Lov, Hiv : Ureal) return Nat;
4480 -- Returns size of type with given bounds. Also leaves these
4481 -- bounds set as the current bounds of the Typ.
4487 function Fsize (Lov, Hiv : Ureal) return Nat is
4489 Set_Realval (Lo, Lov);
4490 Set_Realval (Hi, Hiv);
4491 return Minimum_Size (Typ);
4494 -- Start of processing for Freeze_Fixed_Point_Type
4497 -- If Esize of a subtype has not previously been set, set it now
4499 if Unknown_Esize (Typ) then
4500 Atype := Ancestor_Subtype (Typ);
4502 if Present (Atype) then
4503 Set_Esize (Typ, Esize (Atype));
4505 Set_Esize (Typ, Esize (Base_Type (Typ)));
4509 -- Immediate return if the range is already analyzed. This means that
4510 -- the range is already set, and does not need to be computed by this
4513 if Analyzed (Rng) then
4517 -- Immediate return if either of the bounds raises Constraint_Error
4519 if Raises_Constraint_Error (Lo)
4520 or else Raises_Constraint_Error (Hi)
4525 Loval := Realval (Lo);
4526 Hival := Realval (Hi);
4528 -- Ordinary fixed-point case
4530 if Is_Ordinary_Fixed_Point_Type (Typ) then
4532 -- For the ordinary fixed-point case, we are allowed to fudge the
4533 -- end-points up or down by small. Generally we prefer to fudge up,
4534 -- i.e. widen the bounds for non-model numbers so that the end points
4535 -- are included. However there are cases in which this cannot be
4536 -- done, and indeed cases in which we may need to narrow the bounds.
4537 -- The following circuit makes the decision.
4539 -- Note: our terminology here is that Incl_EP means that the bounds
4540 -- are widened by Small if necessary to include the end points, and
4541 -- Excl_EP means that the bounds are narrowed by Small to exclude the
4542 -- end-points if this reduces the size.
4544 -- Note that in the Incl case, all we care about is including the
4545 -- end-points. In the Excl case, we want to narrow the bounds as
4546 -- much as permitted by the RM, to give the smallest possible size.
4549 Loval_Incl_EP : Ureal;
4550 Hival_Incl_EP : Ureal;
4552 Loval_Excl_EP : Ureal;
4553 Hival_Excl_EP : Ureal;
4559 First_Subt : Entity_Id;
4564 -- First step. Base types are required to be symmetrical. Right
4565 -- now, the base type range is a copy of the first subtype range.
4566 -- This will be corrected before we are done, but right away we
4567 -- need to deal with the case where both bounds are non-negative.
4568 -- In this case, we set the low bound to the negative of the high
4569 -- bound, to make sure that the size is computed to include the
4570 -- required sign. Note that we do not need to worry about the
4571 -- case of both bounds negative, because the sign will be dealt
4572 -- with anyway. Furthermore we can't just go making such a bound
4573 -- symmetrical, since in a twos-complement system, there is an
4574 -- extra negative value which could not be accommodated on the
4578 and then not UR_Is_Negative (Loval)
4579 and then Hival > Loval
4582 Set_Realval (Lo, Loval);
4585 -- Compute the fudged bounds. If the number is a model number,
4586 -- then we do nothing to include it, but we are allowed to backoff
4587 -- to the next adjacent model number when we exclude it. If it is
4588 -- not a model number then we straddle the two values with the
4589 -- model numbers on either side.
4591 Model_Num := UR_Trunc (Loval / Small) * Small;
4593 if Loval = Model_Num then
4594 Loval_Incl_EP := Model_Num;
4596 Loval_Incl_EP := Model_Num - Small;
4599 -- The low value excluding the end point is Small greater, but
4600 -- we do not do this exclusion if the low value is positive,
4601 -- since it can't help the size and could actually hurt by
4602 -- crossing the high bound.
4604 if UR_Is_Negative (Loval_Incl_EP) then
4605 Loval_Excl_EP := Loval_Incl_EP + Small;
4607 -- If the value went from negative to zero, then we have the
4608 -- case where Loval_Incl_EP is the model number just below
4609 -- zero, so we want to stick to the negative value for the
4610 -- base type to maintain the condition that the size will
4611 -- include signed values.
4614 and then UR_Is_Zero (Loval_Excl_EP)
4616 Loval_Excl_EP := Loval_Incl_EP;
4620 Loval_Excl_EP := Loval_Incl_EP;
4623 -- Similar processing for upper bound and high value
4625 Model_Num := UR_Trunc (Hival / Small) * Small;
4627 if Hival = Model_Num then
4628 Hival_Incl_EP := Model_Num;
4630 Hival_Incl_EP := Model_Num + Small;
4633 if UR_Is_Positive (Hival_Incl_EP) then
4634 Hival_Excl_EP := Hival_Incl_EP - Small;
4636 Hival_Excl_EP := Hival_Incl_EP;
4639 -- One further adjustment is needed. In the case of subtypes, we
4640 -- cannot go outside the range of the base type, or we get
4641 -- peculiarities, and the base type range is already set. This
4642 -- only applies to the Incl values, since clearly the Excl values
4643 -- are already as restricted as they are allowed to be.
4646 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
4647 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
4650 -- Get size including and excluding end points
4652 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
4653 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
4655 -- No need to exclude end-points if it does not reduce size
4657 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
4658 Loval_Excl_EP := Loval_Incl_EP;
4661 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
4662 Hival_Excl_EP := Hival_Incl_EP;
4665 -- Now we set the actual size to be used. We want to use the
4666 -- bounds fudged up to include the end-points but only if this
4667 -- can be done without violating a specifically given size
4668 -- size clause or causing an unacceptable increase in size.
4670 -- Case of size clause given
4672 if Has_Size_Clause (Typ) then
4674 -- Use the inclusive size only if it is consistent with
4675 -- the explicitly specified size.
4677 if Size_Incl_EP <= RM_Size (Typ) then
4678 Actual_Lo := Loval_Incl_EP;
4679 Actual_Hi := Hival_Incl_EP;
4680 Actual_Size := Size_Incl_EP;
4682 -- If the inclusive size is too large, we try excluding
4683 -- the end-points (will be caught later if does not work).
4686 Actual_Lo := Loval_Excl_EP;
4687 Actual_Hi := Hival_Excl_EP;
4688 Actual_Size := Size_Excl_EP;
4691 -- Case of size clause not given
4694 -- If we have a base type whose corresponding first subtype
4695 -- has an explicit size that is large enough to include our
4696 -- end-points, then do so. There is no point in working hard
4697 -- to get a base type whose size is smaller than the specified
4698 -- size of the first subtype.
4700 First_Subt := First_Subtype (Typ);
4702 if Has_Size_Clause (First_Subt)
4703 and then Size_Incl_EP <= Esize (First_Subt)
4705 Actual_Size := Size_Incl_EP;
4706 Actual_Lo := Loval_Incl_EP;
4707 Actual_Hi := Hival_Incl_EP;
4709 -- If excluding the end-points makes the size smaller and
4710 -- results in a size of 8,16,32,64, then we take the smaller
4711 -- size. For the 64 case, this is compulsory. For the other
4712 -- cases, it seems reasonable. We like to include end points
4713 -- if we can, but not at the expense of moving to the next
4714 -- natural boundary of size.
4716 elsif Size_Incl_EP /= Size_Excl_EP
4718 (Size_Excl_EP = 8 or else
4719 Size_Excl_EP = 16 or else
4720 Size_Excl_EP = 32 or else
4723 Actual_Size := Size_Excl_EP;
4724 Actual_Lo := Loval_Excl_EP;
4725 Actual_Hi := Hival_Excl_EP;
4727 -- Otherwise we can definitely include the end points
4730 Actual_Size := Size_Incl_EP;
4731 Actual_Lo := Loval_Incl_EP;
4732 Actual_Hi := Hival_Incl_EP;
4735 -- One pathological case: normally we never fudge a low bound
4736 -- down, since it would seem to increase the size (if it has
4737 -- any effect), but for ranges containing single value, or no
4738 -- values, the high bound can be small too large. Consider:
4740 -- type t is delta 2.0**(-14)
4741 -- range 131072.0 .. 0;
4743 -- That lower bound is *just* outside the range of 32 bits, and
4744 -- does need fudging down in this case. Note that the bounds
4745 -- will always have crossed here, since the high bound will be
4746 -- fudged down if necessary, as in the case of:
4748 -- type t is delta 2.0**(-14)
4749 -- range 131072.0 .. 131072.0;
4751 -- So we detect the situation by looking for crossed bounds,
4752 -- and if the bounds are crossed, and the low bound is greater
4753 -- than zero, we will always back it off by small, since this
4754 -- is completely harmless.
4756 if Actual_Lo > Actual_Hi then
4757 if UR_Is_Positive (Actual_Lo) then
4758 Actual_Lo := Loval_Incl_EP - Small;
4759 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
4761 -- And of course, we need to do exactly the same parallel
4762 -- fudge for flat ranges in the negative region.
4764 elsif UR_Is_Negative (Actual_Hi) then
4765 Actual_Hi := Hival_Incl_EP + Small;
4766 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
4771 Set_Realval (Lo, Actual_Lo);
4772 Set_Realval (Hi, Actual_Hi);
4775 -- For the decimal case, none of this fudging is required, since there
4776 -- are no end-point problems in the decimal case (the end-points are
4777 -- always included).
4780 Actual_Size := Fsize (Loval, Hival);
4783 -- At this stage, the actual size has been calculated and the proper
4784 -- required bounds are stored in the low and high bounds.
4786 if Actual_Size > 64 then
4787 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
4789 ("size required (^) for type& too large, maximum allowed is 64",
4794 -- Check size against explicit given size
4796 if Has_Size_Clause (Typ) then
4797 if Actual_Size > RM_Size (Typ) then
4798 Error_Msg_Uint_1 := RM_Size (Typ);
4799 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
4801 ("size given (^) for type& too small, minimum allowed is ^",
4802 Size_Clause (Typ), Typ);
4805 Actual_Size := UI_To_Int (Esize (Typ));
4808 -- Increase size to next natural boundary if no size clause given
4811 if Actual_Size <= 8 then
4813 elsif Actual_Size <= 16 then
4815 elsif Actual_Size <= 32 then
4821 Init_Esize (Typ, Actual_Size);
4822 Adjust_Esize_For_Alignment (Typ);
4825 -- If we have a base type, then expand the bounds so that they extend to
4826 -- the full width of the allocated size in bits, to avoid junk range
4827 -- checks on intermediate computations.
4829 if Base_Type (Typ) = Typ then
4830 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
4831 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
4834 -- Final step is to reanalyze the bounds using the proper type
4835 -- and set the Corresponding_Integer_Value fields of the literals.
4837 Set_Etype (Lo, Empty);
4838 Set_Analyzed (Lo, False);
4841 -- Resolve with universal fixed if the base type, and the base type if
4842 -- it is a subtype. Note we can't resolve the base type with itself,
4843 -- that would be a reference before definition.
4846 Resolve (Lo, Universal_Fixed);
4851 -- Set corresponding integer value for bound
4853 Set_Corresponding_Integer_Value
4854 (Lo, UR_To_Uint (Realval (Lo) / Small));
4856 -- Similar processing for high bound
4858 Set_Etype (Hi, Empty);
4859 Set_Analyzed (Hi, False);
4863 Resolve (Hi, Universal_Fixed);
4868 Set_Corresponding_Integer_Value
4869 (Hi, UR_To_Uint (Realval (Hi) / Small));
4871 -- Set type of range to correspond to bounds
4873 Set_Etype (Rng, Etype (Lo));
4875 -- Set Esize to calculated size if not set already
4877 if Unknown_Esize (Typ) then
4878 Init_Esize (Typ, Actual_Size);
4881 -- Set RM_Size if not already set. If already set, check value
4884 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
4887 if RM_Size (Typ) /= Uint_0 then
4888 if RM_Size (Typ) < Minsiz then
4889 Error_Msg_Uint_1 := RM_Size (Typ);
4890 Error_Msg_Uint_2 := Minsiz;
4892 ("size given (^) for type& too small, minimum allowed is ^",
4893 Size_Clause (Typ), Typ);
4897 Set_RM_Size (Typ, Minsiz);
4900 end Freeze_Fixed_Point_Type;
4906 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
4910 Set_Has_Delayed_Freeze (T);
4911 L := Freeze_Entity (T, Sloc (N));
4913 if Is_Non_Empty_List (L) then
4914 Insert_Actions (N, L);
4918 --------------------------
4919 -- Freeze_Static_Object --
4920 --------------------------
4922 procedure Freeze_Static_Object (E : Entity_Id) is
4924 Cannot_Be_Static : exception;
4925 -- Exception raised if the type of a static object cannot be made
4926 -- static. This happens if the type depends on non-global objects.
4928 procedure Ensure_Expression_Is_SA (N : Node_Id);
4929 -- Called to ensure that an expression used as part of a type definition
4930 -- is statically allocatable, which means that the expression type is
4931 -- statically allocatable, and the expression is either static, or a
4932 -- reference to a library level constant.
4934 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
4935 -- Called to mark a type as static, checking that it is possible
4936 -- to set the type as static. If it is not possible, then the
4937 -- exception Cannot_Be_Static is raised.
4939 -----------------------------
4940 -- Ensure_Expression_Is_SA --
4941 -----------------------------
4943 procedure Ensure_Expression_Is_SA (N : Node_Id) is
4947 Ensure_Type_Is_SA (Etype (N));
4949 if Is_Static_Expression (N) then
4952 elsif Nkind (N) = N_Identifier then
4956 and then Ekind (Ent) = E_Constant
4957 and then Is_Library_Level_Entity (Ent)
4963 raise Cannot_Be_Static;
4964 end Ensure_Expression_Is_SA;
4966 -----------------------
4967 -- Ensure_Type_Is_SA --
4968 -----------------------
4970 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
4975 -- If type is library level, we are all set
4977 if Is_Library_Level_Entity (Typ) then
4981 -- We are also OK if the type already marked as statically allocated,
4982 -- which means we processed it before.
4984 if Is_Statically_Allocated (Typ) then
4988 -- Mark type as statically allocated
4990 Set_Is_Statically_Allocated (Typ);
4992 -- Check that it is safe to statically allocate this type
4994 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
4995 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
4996 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
4998 elsif Is_Array_Type (Typ) then
4999 N := First_Index (Typ);
5000 while Present (N) loop
5001 Ensure_Type_Is_SA (Etype (N));
5005 Ensure_Type_Is_SA (Component_Type (Typ));
5007 elsif Is_Access_Type (Typ) then
5008 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
5012 T : constant Entity_Id := Etype (Designated_Type (Typ));
5015 if T /= Standard_Void_Type then
5016 Ensure_Type_Is_SA (T);
5019 F := First_Formal (Designated_Type (Typ));
5021 while Present (F) loop
5022 Ensure_Type_Is_SA (Etype (F));
5028 Ensure_Type_Is_SA (Designated_Type (Typ));
5031 elsif Is_Record_Type (Typ) then
5032 C := First_Entity (Typ);
5033 while Present (C) loop
5034 if Ekind (C) = E_Discriminant
5035 or else Ekind (C) = E_Component
5037 Ensure_Type_Is_SA (Etype (C));
5039 elsif Is_Type (C) then
5040 Ensure_Type_Is_SA (C);
5046 elsif Ekind (Typ) = E_Subprogram_Type then
5047 Ensure_Type_Is_SA (Etype (Typ));
5049 C := First_Formal (Typ);
5050 while Present (C) loop
5051 Ensure_Type_Is_SA (Etype (C));
5056 raise Cannot_Be_Static;
5058 end Ensure_Type_Is_SA;
5060 -- Start of processing for Freeze_Static_Object
5063 Ensure_Type_Is_SA (Etype (E));
5066 when Cannot_Be_Static =>
5068 -- If the object that cannot be static is imported or exported, then
5069 -- issue an error message saying that this object cannot be imported
5070 -- or exported. If it has an address clause it is an overlay in the
5071 -- current partition and the static requirement is not relevant.
5073 if Is_Imported (E) and then No (Address_Clause (E)) then
5075 ("& cannot be imported (local type is not constant)", E);
5077 -- Otherwise must be exported, something is wrong if compiler
5078 -- is marking something as statically allocated which cannot be).
5080 else pragma Assert (Is_Exported (E));
5082 ("& cannot be exported (local type is not constant)", E);
5084 end Freeze_Static_Object;
5086 -----------------------
5087 -- Freeze_Subprogram --
5088 -----------------------
5090 procedure Freeze_Subprogram (E : Entity_Id) is
5095 -- Subprogram may not have an address clause unless it is imported
5097 if Present (Address_Clause (E)) then
5098 if not Is_Imported (E) then
5100 ("address clause can only be given " &
5101 "for imported subprogram",
5102 Name (Address_Clause (E)));
5106 -- Reset the Pure indication on an imported subprogram unless an
5107 -- explicit Pure_Function pragma was present. We do this because
5108 -- otherwise it is an insidious error to call a non-pure function from
5109 -- pure unit and have calls mysteriously optimized away. What happens
5110 -- here is that the Import can bypass the normal check to ensure that
5111 -- pure units call only pure subprograms.
5114 and then Is_Pure (E)
5115 and then not Has_Pragma_Pure_Function (E)
5117 Set_Is_Pure (E, False);
5120 -- For non-foreign convention subprograms, this is where we create
5121 -- the extra formals (for accessibility level and constrained bit
5122 -- information). We delay this till the freeze point precisely so
5123 -- that we know the convention!
5125 if not Has_Foreign_Convention (E) then
5126 Create_Extra_Formals (E);
5129 -- If this is convention Ada and a Valued_Procedure, that's odd
5131 if Ekind (E) = E_Procedure
5132 and then Is_Valued_Procedure (E)
5133 and then Convention (E) = Convention_Ada
5134 and then Warn_On_Export_Import
5137 ("?Valued_Procedure has no effect for convention Ada", E);
5138 Set_Is_Valued_Procedure (E, False);
5141 -- Case of foreign convention
5146 -- For foreign conventions, warn about return of an
5147 -- unconstrained array.
5149 -- Note: we *do* allow a return by descriptor for the VMS case,
5150 -- though here there is probably more to be done ???
5152 if Ekind (E) = E_Function then
5153 Retype := Underlying_Type (Etype (E));
5155 -- If no return type, probably some other error, e.g. a
5156 -- missing full declaration, so ignore.
5161 -- If the return type is generic, we have emitted a warning
5162 -- earlier on, and there is nothing else to check here. Specific
5163 -- instantiations may lead to erroneous behavior.
5165 elsif Is_Generic_Type (Etype (E)) then
5168 -- Display warning if returning unconstrained array
5170 elsif Is_Array_Type (Retype)
5171 and then not Is_Constrained (Retype)
5173 -- Exclude cases where descriptor mechanism is set, since the
5174 -- VMS descriptor mechanisms allow such unconstrained returns.
5176 and then Mechanism (E) not in Descriptor_Codes
5178 -- Check appropriate warning is enabled (should we check for
5179 -- Warnings (Off) on specific entities here, probably so???)
5181 and then Warn_On_Export_Import
5183 -- Exclude the VM case, since return of unconstrained arrays
5184 -- is properly handled in both the JVM and .NET cases.
5186 and then VM_Target = No_VM
5189 ("?foreign convention function& should not return " &
5190 "unconstrained array", E);
5195 -- If any of the formals for an exported foreign convention
5196 -- subprogram have defaults, then emit an appropriate warning since
5197 -- this is odd (default cannot be used from non-Ada code)
5199 if Is_Exported (E) then
5200 F := First_Formal (E);
5201 while Present (F) loop
5202 if Warn_On_Export_Import
5203 and then Present (Default_Value (F))
5206 ("?parameter cannot be defaulted in non-Ada call",
5215 -- For VMS, descriptor mechanisms for parameters are allowed only for
5216 -- imported/exported subprograms. Moreover, the NCA descriptor is not
5217 -- allowed for parameters of exported subprograms.
5219 if OpenVMS_On_Target then
5220 if Is_Exported (E) then
5221 F := First_Formal (E);
5222 while Present (F) loop
5223 if Mechanism (F) = By_Descriptor_NCA then
5225 ("'N'C'A' descriptor for parameter not permitted", F);
5227 ("\can only be used for imported subprogram", F);
5233 elsif not Is_Imported (E) then
5234 F := First_Formal (E);
5235 while Present (F) loop
5236 if Mechanism (F) in Descriptor_Codes then
5238 ("descriptor mechanism for parameter not permitted", F);
5240 ("\can only be used for imported/exported subprogram", F);
5248 -- Pragma Inline_Always is disallowed for dispatching subprograms
5249 -- because the address of such subprograms is saved in the dispatch
5250 -- table to support dispatching calls, and dispatching calls cannot
5251 -- be inlined. This is consistent with the restriction against using
5252 -- 'Access or 'Address on an Inline_Always subprogram.
5254 if Is_Dispatching_Operation (E)
5255 and then Has_Pragma_Inline_Always (E)
5258 ("pragma Inline_Always not allowed for dispatching subprograms", E);
5261 -- Because of the implicit representation of inherited predefined
5262 -- operators in the front-end, the overriding status of the operation
5263 -- may be affected when a full view of a type is analyzed, and this is
5264 -- not captured by the analysis of the corresponding type declaration.
5265 -- Therefore the correctness of a not-overriding indicator must be
5266 -- rechecked when the subprogram is frozen.
5268 if Nkind (E) = N_Defining_Operator_Symbol
5269 and then not Error_Posted (Parent (E))
5271 Check_Overriding_Indicator (E, Empty, Is_Primitive (E));
5273 end Freeze_Subprogram;
5275 ----------------------
5276 -- Is_Fully_Defined --
5277 ----------------------
5279 function Is_Fully_Defined (T : Entity_Id) return Boolean is
5281 if Ekind (T) = E_Class_Wide_Type then
5282 return Is_Fully_Defined (Etype (T));
5284 elsif Is_Array_Type (T) then
5285 return Is_Fully_Defined (Component_Type (T));
5287 elsif Is_Record_Type (T)
5288 and not Is_Private_Type (T)
5290 -- Verify that the record type has no components with private types
5291 -- without completion.
5297 Comp := First_Component (T);
5299 while Present (Comp) loop
5300 if not Is_Fully_Defined (Etype (Comp)) then
5304 Next_Component (Comp);
5310 return not Is_Private_Type (T)
5311 or else Present (Full_View (Base_Type (T)));
5313 end Is_Fully_Defined;
5315 ---------------------------------
5316 -- Process_Default_Expressions --
5317 ---------------------------------
5319 procedure Process_Default_Expressions
5321 After : in out Node_Id)
5323 Loc : constant Source_Ptr := Sloc (E);
5330 Set_Default_Expressions_Processed (E);
5332 -- A subprogram instance and its associated anonymous subprogram share
5333 -- their signature. The default expression functions are defined in the
5334 -- wrapper packages for the anonymous subprogram, and should not be
5335 -- generated again for the instance.
5337 if Is_Generic_Instance (E)
5338 and then Present (Alias (E))
5339 and then Default_Expressions_Processed (Alias (E))
5344 Formal := First_Formal (E);
5345 while Present (Formal) loop
5346 if Present (Default_Value (Formal)) then
5348 -- We work with a copy of the default expression because we
5349 -- do not want to disturb the original, since this would mess
5350 -- up the conformance checking.
5352 Dcopy := New_Copy_Tree (Default_Value (Formal));
5354 -- The analysis of the expression may generate insert actions,
5355 -- which of course must not be executed. We wrap those actions
5356 -- in a procedure that is not called, and later on eliminated.
5357 -- The following cases have no side-effects, and are analyzed
5360 if Nkind (Dcopy) = N_Identifier
5361 or else Nkind (Dcopy) = N_Expanded_Name
5362 or else Nkind (Dcopy) = N_Integer_Literal
5363 or else (Nkind (Dcopy) = N_Real_Literal
5364 and then not Vax_Float (Etype (Dcopy)))
5365 or else Nkind (Dcopy) = N_Character_Literal
5366 or else Nkind (Dcopy) = N_String_Literal
5367 or else Known_Null (Dcopy)
5368 or else (Nkind (Dcopy) = N_Attribute_Reference
5370 Attribute_Name (Dcopy) = Name_Null_Parameter)
5373 -- If there is no default function, we must still do a full
5374 -- analyze call on the default value, to ensure that all error
5375 -- checks are performed, e.g. those associated with static
5376 -- evaluation. Note: this branch will always be taken if the
5377 -- analyzer is turned off (but we still need the error checks).
5379 -- Note: the setting of parent here is to meet the requirement
5380 -- that we can only analyze the expression while attached to
5381 -- the tree. Really the requirement is that the parent chain
5382 -- be set, we don't actually need to be in the tree.
5384 Set_Parent (Dcopy, Declaration_Node (Formal));
5387 -- Default expressions are resolved with their own type if the
5388 -- context is generic, to avoid anomalies with private types.
5390 if Ekind (Scope (E)) = E_Generic_Package then
5393 Resolve (Dcopy, Etype (Formal));
5396 -- If that resolved expression will raise constraint error,
5397 -- then flag the default value as raising constraint error.
5398 -- This allows a proper error message on the calls.
5400 if Raises_Constraint_Error (Dcopy) then
5401 Set_Raises_Constraint_Error (Default_Value (Formal));
5404 -- If the default is a parameterless call, we use the name of
5405 -- the called function directly, and there is no body to build.
5407 elsif Nkind (Dcopy) = N_Function_Call
5408 and then No (Parameter_Associations (Dcopy))
5412 -- Else construct and analyze the body of a wrapper procedure
5413 -- that contains an object declaration to hold the expression.
5414 -- Given that this is done only to complete the analysis, it
5415 -- simpler to build a procedure than a function which might
5416 -- involve secondary stack expansion.
5419 Dnam := Make_Temporary (Loc, 'D');
5422 Make_Subprogram_Body (Loc,
5424 Make_Procedure_Specification (Loc,
5425 Defining_Unit_Name => Dnam),
5427 Declarations => New_List (
5428 Make_Object_Declaration (Loc,
5429 Defining_Identifier =>
5430 Make_Defining_Identifier (Loc,
5431 New_Internal_Name ('T')),
5432 Object_Definition =>
5433 New_Occurrence_Of (Etype (Formal), Loc),
5434 Expression => New_Copy_Tree (Dcopy))),
5436 Handled_Statement_Sequence =>
5437 Make_Handled_Sequence_Of_Statements (Loc,
5438 Statements => New_List));
5440 Set_Scope (Dnam, Scope (E));
5441 Set_Assignment_OK (First (Declarations (Dbody)));
5442 Set_Is_Eliminated (Dnam);
5443 Insert_After (After, Dbody);
5449 Next_Formal (Formal);
5451 end Process_Default_Expressions;
5453 ----------------------------------------
5454 -- Set_Component_Alignment_If_Not_Set --
5455 ----------------------------------------
5457 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
5459 -- Ignore if not base type, subtypes don't need anything
5461 if Typ /= Base_Type (Typ) then
5465 -- Do not override existing representation
5467 if Is_Packed (Typ) then
5470 elsif Has_Specified_Layout (Typ) then
5473 elsif Component_Alignment (Typ) /= Calign_Default then
5477 Set_Component_Alignment
5478 (Typ, Scope_Stack.Table
5479 (Scope_Stack.Last).Component_Alignment_Default);
5481 end Set_Component_Alignment_If_Not_Set;
5487 procedure Undelay_Type (T : Entity_Id) is
5489 Set_Has_Delayed_Freeze (T, False);
5490 Set_Freeze_Node (T, Empty);
5492 -- Since we don't want T to have a Freeze_Node, we don't want its
5493 -- Full_View or Corresponding_Record_Type to have one either.
5495 -- ??? Fundamentally, this whole handling is a kludge. What we really
5496 -- want is to be sure that for an Itype that's part of record R and is a
5497 -- subtype of type T, that it's frozen after the later of the freeze
5498 -- points of R and T. We have no way of doing that directly, so what we
5499 -- do is force most such Itypes to be frozen as part of freezing R via
5500 -- this procedure and only delay the ones that need to be delayed
5501 -- (mostly the designated types of access types that are defined as part
5504 if Is_Private_Type (T)
5505 and then Present (Full_View (T))
5506 and then Is_Itype (Full_View (T))
5507 and then Is_Record_Type (Scope (Full_View (T)))
5509 Undelay_Type (Full_View (T));
5512 if Is_Concurrent_Type (T)
5513 and then Present (Corresponding_Record_Type (T))
5514 and then Is_Itype (Corresponding_Record_Type (T))
5515 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
5517 Undelay_Type (Corresponding_Record_Type (T));
5525 procedure Warn_Overlay
5530 Ent : constant Entity_Id := Entity (Nam);
5531 -- The object to which the address clause applies
5534 Old : Entity_Id := Empty;
5538 -- No warning if address clause overlay warnings are off
5540 if not Address_Clause_Overlay_Warnings then
5544 -- No warning if there is an explicit initialization
5546 Init := Original_Node (Expression (Declaration_Node (Ent)));
5548 if Present (Init) and then Comes_From_Source (Init) then
5552 -- We only give the warning for non-imported entities of a type for
5553 -- which a non-null base init proc is defined, or for objects of access
5554 -- types with implicit null initialization, or when Normalize_Scalars
5555 -- applies and the type is scalar or a string type (the latter being
5556 -- tested for because predefined String types are initialized by inline
5557 -- code rather than by an init_proc). Note that we do not give the
5558 -- warning for Initialize_Scalars, since we suppressed initialization
5562 and then not Is_Imported (Ent)
5563 and then (Has_Non_Null_Base_Init_Proc (Typ)
5564 or else Is_Access_Type (Typ)
5565 or else (Normalize_Scalars
5566 and then (Is_Scalar_Type (Typ)
5567 or else Is_String_Type (Typ))))
5569 if Nkind (Expr) = N_Attribute_Reference
5570 and then Is_Entity_Name (Prefix (Expr))
5572 Old := Entity (Prefix (Expr));
5574 elsif Is_Entity_Name (Expr)
5575 and then Ekind (Entity (Expr)) = E_Constant
5577 Decl := Declaration_Node (Entity (Expr));
5579 if Nkind (Decl) = N_Object_Declaration
5580 and then Present (Expression (Decl))
5581 and then Nkind (Expression (Decl)) = N_Attribute_Reference
5582 and then Is_Entity_Name (Prefix (Expression (Decl)))
5584 Old := Entity (Prefix (Expression (Decl)));
5586 elsif Nkind (Expr) = N_Function_Call then
5590 -- A function call (most likely to To_Address) is probably not an
5591 -- overlay, so skip warning. Ditto if the function call was inlined
5592 -- and transformed into an entity.
5594 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
5598 Decl := Next (Parent (Expr));
5600 -- If a pragma Import follows, we assume that it is for the current
5601 -- target of the address clause, and skip the warning.
5604 and then Nkind (Decl) = N_Pragma
5605 and then Pragma_Name (Decl) = Name_Import
5610 if Present (Old) then
5611 Error_Msg_Node_2 := Old;
5613 ("default initialization of & may modify &?",
5617 ("default initialization of & may modify overlaid storage?",
5621 -- Add friendly warning if initialization comes from a packed array
5624 if Is_Record_Type (Typ) then
5629 Comp := First_Component (Typ);
5631 while Present (Comp) loop
5632 if Nkind (Parent (Comp)) = N_Component_Declaration
5633 and then Present (Expression (Parent (Comp)))
5636 elsif Is_Array_Type (Etype (Comp))
5637 and then Present (Packed_Array_Type (Etype (Comp)))
5640 ("\packed array component& " &
5641 "will be initialized to zero?",
5645 Next_Component (Comp);
5652 ("\use pragma Import for & to " &
5653 "suppress initialization (RM B.1(24))?",