Daily bump.
[official-gcc.git] / gcc / ada / freeze.adb
blobe1855b73e9baba62ed979ed09e1ca3e0046e07a6
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R E E Z E --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.2 $
10 -- --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 -- --
27 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Elists; use Elists;
33 with Errout; use Errout;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Pakd; use Exp_Pakd;
37 with Exp_Util; use Exp_Util;
38 with Layout; use Layout;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Opt; use Opt;
42 with Restrict; use Restrict;
43 with Sem; use Sem;
44 with Sem_Cat; use Sem_Cat;
45 with Sem_Ch6; use Sem_Ch6;
46 with Sem_Ch7; use Sem_Ch7;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Ch13; use Sem_Ch13;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Mech; use Sem_Mech;
51 with Sem_Prag; use Sem_Prag;
52 with Sem_Res; use Sem_Res;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Snames; use Snames;
56 with Stand; use Stand;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Ttypes; use Ttypes;
60 with Uintp; use Uintp;
61 with Urealp; use Urealp;
63 package body Freeze is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
70 -- Typ is a type that is being frozen. If no size clause is given,
71 -- but a default Esize has been computed, then this default Esize is
72 -- adjusted up if necessary to be consistent with a given alignment,
73 -- but never to a value greater than Long_Long_Integer'Size. This
74 -- is used for all discrete types and for fixed-point types.
76 procedure Build_And_Analyze_Renamed_Body
77 (Decl : Node_Id;
78 New_S : Entity_Id;
79 After : in out Node_Id);
80 -- Build body for a renaming declaration, insert in tree and analyze.
82 procedure Check_Strict_Alignment (E : Entity_Id);
83 -- E is a base type. If E is tagged or has a component that is aliased
84 -- or tagged or contains something this is aliased or tagged, set
85 -- Strict_Alignment.
87 procedure Check_Unsigned_Type (E : Entity_Id);
88 pragma Inline (Check_Unsigned_Type);
89 -- If E is a fixed-point or discrete type, then all the necessary work
90 -- to freeze it is completed except for possible setting of the flag
91 -- Is_Unsigned_Type, which is done by this procedure. The call has no
92 -- effect if the entity E is not a discrete or fixed-point type.
94 procedure Freeze_And_Append
95 (Ent : Entity_Id;
96 Loc : Source_Ptr;
97 Result : in out List_Id);
98 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
99 -- nodes to Result, modifying Result from No_List if necessary.
101 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
102 -- Freeze enumeration type. The Esize field is set as processing
103 -- proceeds (i.e. set by default when the type is declared and then
104 -- adjusted by rep clauses. What this procedure does is to make sure
105 -- that if a foreign convention is specified, and no specific size
106 -- is given, then the size must be at least Integer'Size.
108 procedure Freeze_Static_Object (E : Entity_Id);
109 -- If an object is frozen which has Is_Statically_Allocated set, then
110 -- all referenced types must also be marked with this flag. This routine
111 -- is in charge of meeting this requirement for the object entity E.
113 procedure Freeze_Subprogram (E : Entity_Id);
114 -- Perform freezing actions for a subprogram (create extra formals,
115 -- and set proper default mechanism values). Note that this routine
116 -- is not called for internal subprograms, for which neither of these
117 -- actions is needed (or desirable, we do not want for example to have
118 -- these extra formals present in initialization procedures, where they
119 -- would serve no purpose). In this call E is either a subprogram or
120 -- a subprogram type (i.e. an access to a subprogram).
122 function Is_Fully_Defined (T : Entity_Id) return Boolean;
123 -- true if T is not private, or has a full view.
125 procedure Process_Default_Expressions
126 (E : Entity_Id;
127 After : in out Node_Id);
128 -- This procedure is called for each subprogram to complete processing
129 -- of default expressions at the point where all types are known to be
130 -- frozen. The expressions must be analyzed in full, to make sure that
131 -- all error processing is done (they have only been pre-analyzed). If
132 -- the expression is not an entity or literal, its analysis may generate
133 -- code which must not be executed. In that case we build a function
134 -- body to hold that code. This wrapper function serves no other purpose
135 -- (it used to be called to evaluate the default, but now the default is
136 -- inlined at each point of call).
138 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
139 -- Typ is a record or array type that is being frozen. This routine
140 -- sets the default component alignment from the scope stack values
141 -- if the alignment is otherwise not specified.
143 procedure Check_Debug_Info_Needed (T : Entity_Id);
144 -- As each entity is frozen, this routine is called to deal with the
145 -- setting of Debug_Info_Needed for the entity. This flag is set if
146 -- the entity comes from source, or if we are in Debug_Generated_Code
147 -- mode or if the -gnatdV debug flag is set. However, it never sets
148 -- the flag if Debug_Info_Off is set.
150 procedure Set_Debug_Info_Needed (T : Entity_Id);
151 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
152 -- also on any entities that are needed by T (for an object, the type
153 -- of the object is needed, and for a type, the subsidiary types are
154 -- needed -- see body for details). Never has any effect on T if the
155 -- Debug_Info_Off flag is set.
157 -------------------------------
158 -- Adjust_Esize_For_Alignment --
159 -------------------------------
161 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
162 Align : Uint;
164 begin
165 if Known_Esize (Typ) and then Known_Alignment (Typ) then
166 Align := Alignment_In_Bits (Typ);
168 if Align > Esize (Typ)
169 and then Align <= Standard_Long_Long_Integer_Size
170 then
171 Set_Esize (Typ, Align);
172 end if;
173 end if;
174 end Adjust_Esize_For_Alignment;
176 ------------------------------------
177 -- Build_And_Analyze_Renamed_Body --
178 ------------------------------------
180 procedure Build_And_Analyze_Renamed_Body
181 (Decl : Node_Id;
182 New_S : Entity_Id;
183 After : in out Node_Id)
185 Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S);
187 begin
188 Insert_After (After, Body_Node);
189 Mark_Rewrite_Insertion (Body_Node);
190 Analyze (Body_Node);
191 After := Body_Node;
192 end Build_And_Analyze_Renamed_Body;
194 ------------------------
195 -- Build_Renamed_Body --
196 ------------------------
198 function Build_Renamed_Body
199 (Decl : Node_Id;
200 New_S : Entity_Id)
201 return Node_Id
203 Loc : constant Source_Ptr := Sloc (New_S);
204 -- We use for the source location of the renamed body, the location
205 -- of the spec entity. It might seem more natural to use the location
206 -- of the renaming declaration itself, but that would be wrong, since
207 -- then the body we create would look as though it was created far
208 -- too late, and this could cause problems with elaboration order
209 -- analysis, particularly in connection with instantiations.
211 N : constant Node_Id := Unit_Declaration_Node (New_S);
212 Nam : constant Node_Id := Name (N);
213 Old_S : Entity_Id;
214 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
215 Actuals : List_Id := No_List;
216 Call_Node : Node_Id;
217 Call_Name : Node_Id;
218 Body_Node : Node_Id;
219 Formal : Entity_Id;
220 O_Formal : Entity_Id;
221 Param_Spec : Node_Id;
223 begin
224 -- Determine the entity being renamed, which is the target of the
225 -- call statement. If the name is an explicit dereference, this is
226 -- a renaming of a subprogram type rather than a subprogram. The
227 -- name itself is fully analyzed.
229 if Nkind (Nam) = N_Selected_Component then
230 Old_S := Entity (Selector_Name (Nam));
232 elsif Nkind (Nam) = N_Explicit_Dereference then
233 Old_S := Etype (Nam);
235 elsif Nkind (Nam) = N_Indexed_Component then
237 if Is_Entity_Name (Prefix (Nam)) then
238 Old_S := Entity (Prefix (Nam));
239 else
240 Old_S := Entity (Selector_Name (Prefix (Nam)));
241 end if;
243 elsif Nkind (Nam) = N_Character_Literal then
244 Old_S := Etype (New_S);
246 else
247 Old_S := Entity (Nam);
248 end if;
250 if Is_Entity_Name (Nam) then
251 Call_Name := New_Reference_To (Old_S, Loc);
252 else
253 Call_Name := New_Copy (Name (N));
255 -- The original name may have been overloaded, but
256 -- is fully resolved now.
258 Set_Is_Overloaded (Call_Name, False);
259 end if;
261 -- For simple renamings, subsequent calls can be expanded directly
262 -- as called to the renamed entity. The body must be generated in
263 -- any case for calls they may appear elsewhere.
265 if (Ekind (Old_S) = E_Function
266 or else Ekind (Old_S) = E_Procedure)
267 and then Nkind (Decl) = N_Subprogram_Declaration
268 then
269 Set_Body_To_Inline (Decl, Old_S);
270 end if;
272 -- The body generated for this renaming is an internal artifact, and
273 -- does not constitute a freeze point for the called entity.
275 Set_Must_Not_Freeze (Call_Name);
277 Formal := First_Formal (Defining_Entity (Decl));
279 if Present (Formal) then
280 Actuals := New_List;
282 while Present (Formal) loop
283 Append (New_Reference_To (Formal, Loc), Actuals);
284 Next_Formal (Formal);
285 end loop;
286 end if;
288 -- If the renamed entity is an entry, inherit its profile. For
289 -- other renamings as bodies, both profiles must be subtype
290 -- conformant, so it is not necessary to replace the profile given
291 -- in the declaration. However, default values that are aggregates
292 -- are rewritten when partially analyzed, so we recover the original
293 -- aggregate to insure that subsequent conformity checking works.
295 Formal := First_Formal (Defining_Entity (Decl));
297 if Present (Formal) then
298 O_Formal := First_Formal (Old_S);
299 Param_Spec := First (Parameter_Specifications (Spec));
301 while Present (Formal) loop
302 if Is_Entry (Old_S) then
304 if Nkind (Parameter_Type (Param_Spec)) /=
305 N_Access_Definition
306 then
307 Set_Etype (Formal, Etype (O_Formal));
308 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
309 end if;
311 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate then
312 Set_Expression (Param_Spec,
313 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
314 end if;
316 Next_Formal (Formal);
317 Next_Formal (O_Formal);
318 Next (Param_Spec);
319 end loop;
320 end if;
322 -- If the renamed entity is a function, the generated body contains a
323 -- return statement. Otherwise, build a procedure call. If the entity is
324 -- an entry, subsequent analysis of the call will transform it into the
325 -- proper entry or protected operation call. If the renamed entity is
326 -- a character literal, return it directly.
328 if Ekind (Old_S) = E_Function
329 or else Ekind (Old_S) = E_Operator
330 or else (Ekind (Old_S) = E_Subprogram_Type
331 and then Etype (Old_S) /= Standard_Void_Type)
332 then
333 Call_Node :=
334 Make_Return_Statement (Loc,
335 Expression =>
336 Make_Function_Call (Loc,
337 Name => Call_Name,
338 Parameter_Associations => Actuals));
340 elsif Ekind (Old_S) = E_Enumeration_Literal then
341 Call_Node :=
342 Make_Return_Statement (Loc,
343 Expression => New_Occurrence_Of (Old_S, Loc));
345 elsif Nkind (Nam) = N_Character_Literal then
346 Call_Node :=
347 Make_Return_Statement (Loc,
348 Expression => Call_Name);
350 else
351 Call_Node :=
352 Make_Procedure_Call_Statement (Loc,
353 Name => Call_Name,
354 Parameter_Associations => Actuals);
355 end if;
357 -- Create entities for subprogram body and formals.
359 Set_Defining_Unit_Name (Spec,
360 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
362 Param_Spec := First (Parameter_Specifications (Spec));
364 while Present (Param_Spec) loop
365 Set_Defining_Identifier (Param_Spec,
366 Make_Defining_Identifier (Loc,
367 Chars => Chars (Defining_Identifier (Param_Spec))));
368 Next (Param_Spec);
369 end loop;
371 Body_Node :=
372 Make_Subprogram_Body (Loc,
373 Specification => Spec,
374 Declarations => New_List,
375 Handled_Statement_Sequence =>
376 Make_Handled_Sequence_Of_Statements (Loc,
377 Statements => New_List (Call_Node)));
379 if Nkind (Decl) /= N_Subprogram_Declaration then
380 Rewrite (N,
381 Make_Subprogram_Declaration (Loc,
382 Specification => Specification (N)));
383 end if;
385 -- Link the body to the entity whose declaration it completes. If
386 -- the body is analyzed when the renamed entity is frozen, it may be
387 -- necessary to restore the proper scope (see package Exp_Ch13).
389 if Nkind (N) = N_Subprogram_Renaming_Declaration
390 and then Present (Corresponding_Spec (N))
391 then
392 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
393 else
394 Set_Corresponding_Spec (Body_Node, New_S);
395 end if;
397 return Body_Node;
398 end Build_Renamed_Body;
400 -----------------------------
401 -- Check_Compile_Time_Size --
402 -----------------------------
404 procedure Check_Compile_Time_Size (T : Entity_Id) is
406 procedure Set_Small_Size (S : Uint);
407 -- Sets the compile time known size (32 bits or less) in the Esize
408 -- field, checking for a size clause that was given which attempts
409 -- to give a smaller size.
411 function Size_Known (T : Entity_Id) return Boolean;
412 -- Recursive function that does all the work.
413 -- Is this right??? isn't recursive case already handled???
414 -- certainly yes for normal call, but what about bogus sem_res call???
416 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
417 -- If T is a constrained subtype, its size is not known if any of its
418 -- discriminant constraints is not static and it is not a null record.
419 -- The test is conservative and doesn't check that the components are
420 -- in fact constrained by non-static discriminant values. Could be made
421 -- more precise ???
423 --------------------
424 -- Set_Small_Size --
425 --------------------
427 procedure Set_Small_Size (S : Uint) is
428 begin
429 if S > 32 then
430 return;
432 elsif Has_Size_Clause (T) then
433 if RM_Size (T) < S then
434 Error_Msg_Uint_1 := S;
435 Error_Msg_NE
436 ("size for & is too small, minimum is ^",
437 Size_Clause (T), T);
439 elsif Unknown_Esize (T) then
440 Set_Esize (T, S);
441 end if;
443 -- Set sizes if not set already
445 else
446 if Unknown_Esize (T) then
447 Set_Esize (T, S);
448 end if;
450 if Unknown_RM_Size (T) then
451 Set_RM_Size (T, S);
452 end if;
453 end if;
454 end Set_Small_Size;
456 ----------------
457 -- Size_Known --
458 ----------------
460 function Size_Known (T : Entity_Id) return Boolean is
461 Index : Entity_Id;
462 Comp : Entity_Id;
463 Ctyp : Entity_Id;
464 Low : Node_Id;
465 High : Node_Id;
467 begin
468 if Size_Known_At_Compile_Time (T) then
469 return True;
471 elsif Error_Posted (T) then
472 return False;
474 elsif Is_Scalar_Type (T)
475 or else Is_Task_Type (T)
476 then
477 return not Is_Generic_Type (T);
479 elsif Is_Array_Type (T) then
481 if Ekind (T) = E_String_Literal_Subtype then
482 Set_Small_Size (Component_Size (T) * String_Literal_Length (T));
483 return True;
485 elsif not Is_Constrained (T) then
486 return False;
488 elsif not Size_Known (Component_Type (T)) then
489 return False;
490 end if;
492 -- Check for all indexes static, and also compute possible
493 -- size (in case it is less than 32 and may be packable).
495 declare
496 Esiz : Uint := Component_Size (T);
497 Dim : Uint;
499 begin
500 Index := First_Index (T);
502 while Present (Index) loop
503 if Nkind (Index) = N_Range then
504 Get_Index_Bounds (Index, Low, High);
506 elsif Error_Posted (Scalar_Range (Etype (Index))) then
507 return False;
509 else
510 Low := Type_Low_Bound (Etype (Index));
511 High := Type_High_Bound (Etype (Index));
512 end if;
514 if not Compile_Time_Known_Value (Low)
515 or else not Compile_Time_Known_Value (High)
516 or else Etype (Index) = Any_Type
517 then
518 return False;
520 else
521 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
523 if Dim >= 0 then
524 Esiz := Esiz * Dim;
525 else
526 Esiz := Uint_0;
527 end if;
528 end if;
530 Next_Index (Index);
531 end loop;
533 Set_Small_Size (Esiz);
534 return True;
535 end;
537 elsif Is_Access_Type (T) then
538 return True;
540 elsif Is_Private_Type (T)
541 and then not Is_Generic_Type (T)
542 and then Present (Underlying_Type (T))
543 then
544 return Size_Known (Underlying_Type (T));
546 elsif Is_Record_Type (T) then
547 if Is_Class_Wide_Type (T) then
548 return False;
550 elsif T /= Base_Type (T) then
551 return Size_Known_At_Compile_Time (Base_Type (T))
552 and then Static_Discriminated_Components (T);
554 else
555 declare
556 Packed_Size_Known : Boolean := Is_Packed (T);
557 Packed_Size : Uint := Uint_0;
559 begin
560 -- Test for variant part present
562 if Has_Discriminants (T)
563 and then Present (Parent (T))
564 and then Nkind (Parent (T)) = N_Full_Type_Declaration
565 and then Nkind (Type_Definition (Parent (T))) =
566 N_Record_Definition
567 and then not Null_Present (Type_Definition (Parent (T)))
568 and then Present (Variant_Part
569 (Component_List (Type_Definition (Parent (T)))))
570 then
571 -- If variant part is present, and type is unconstrained,
572 -- then we must have defaulted discriminants, or a size
573 -- clause must be present for the type, or else the size
574 -- is definitely not known at compile time.
576 if not Is_Constrained (T)
577 and then
578 No (Discriminant_Default_Value
579 (First_Discriminant (T)))
580 and then Unknown_Esize (T)
581 then
582 return False;
583 else
584 -- We do not know the packed size, it is too much
585 -- trouble to figure it out.
587 Packed_Size_Known := False;
588 end if;
589 end if;
591 Comp := First_Entity (T);
593 while Present (Comp) loop
594 if Ekind (Comp) = E_Component
595 or else
596 Ekind (Comp) = E_Discriminant
597 then
598 Ctyp := Etype (Comp);
600 if Present (Component_Clause (Comp)) then
601 Packed_Size_Known := False;
602 end if;
604 if not Size_Known (Ctyp) then
605 return False;
607 elsif Packed_Size_Known then
609 -- If RM_Size is known and static, then we can
610 -- keep accumulating the packed size.
612 if Known_Static_RM_Size (Ctyp) then
614 -- A little glitch, to be removed sometime ???
615 -- gigi does not understand zero sizes yet.
617 if RM_Size (Ctyp) = Uint_0 then
618 Packed_Size_Known := False;
619 end if;
621 Packed_Size :=
622 Packed_Size + RM_Size (Ctyp);
624 -- If we have a field whose RM_Size is not known
625 -- then we can't figure out the packed size here.
627 else
628 Packed_Size_Known := False;
629 end if;
630 end if;
631 end if;
633 Next_Entity (Comp);
634 end loop;
636 if Packed_Size_Known then
637 Set_Small_Size (Packed_Size);
638 end if;
640 return True;
641 end;
642 end if;
644 else
645 return False;
646 end if;
647 end Size_Known;
649 -------------------------------------
650 -- Static_Discriminated_Components --
651 -------------------------------------
653 function Static_Discriminated_Components
654 (T : Entity_Id)
655 return Boolean
657 Constraint : Elmt_Id;
659 begin
660 if Has_Discriminants (T)
661 and then Present (Discriminant_Constraint (T))
662 and then Present (First_Component (T))
663 then
664 Constraint := First_Elmt (Discriminant_Constraint (T));
666 while Present (Constraint) loop
667 if not Compile_Time_Known_Value (Node (Constraint)) then
668 return False;
669 end if;
671 Next_Elmt (Constraint);
672 end loop;
673 end if;
675 return True;
676 end Static_Discriminated_Components;
678 -- Start of processing for Check_Compile_Time_Size
680 begin
681 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
682 end Check_Compile_Time_Size;
684 -----------------------------
685 -- Check_Debug_Info_Needed --
686 -----------------------------
688 procedure Check_Debug_Info_Needed (T : Entity_Id) is
689 begin
690 if Needs_Debug_Info (T) or else Debug_Info_Off (T) then
691 return;
693 elsif Comes_From_Source (T)
694 or else Debug_Generated_Code
695 or else Debug_Flag_VV
696 then
697 Set_Debug_Info_Needed (T);
698 end if;
699 end Check_Debug_Info_Needed;
701 ----------------------------
702 -- Check_Strict_Alignment --
703 ----------------------------
705 procedure Check_Strict_Alignment (E : Entity_Id) is
706 Comp : Entity_Id;
708 begin
709 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
710 Set_Strict_Alignment (E);
712 elsif Is_Array_Type (E) then
713 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
715 elsif Is_Record_Type (E) then
716 if Is_Limited_Record (E) then
717 Set_Strict_Alignment (E);
718 return;
719 end if;
721 Comp := First_Component (E);
723 while Present (Comp) loop
724 if not Is_Type (Comp)
725 and then (Strict_Alignment (Etype (Comp))
726 or else Is_Aliased (Comp))
727 then
728 Set_Strict_Alignment (E);
729 return;
730 end if;
732 Next_Component (Comp);
733 end loop;
734 end if;
735 end Check_Strict_Alignment;
737 -------------------------
738 -- Check_Unsigned_Type --
739 -------------------------
741 procedure Check_Unsigned_Type (E : Entity_Id) is
742 Ancestor : Entity_Id;
743 Lo_Bound : Node_Id;
744 Btyp : Entity_Id;
746 begin
747 if not Is_Discrete_Or_Fixed_Point_Type (E) then
748 return;
749 end if;
751 -- Do not attempt to analyze case where range was in error
753 if Error_Posted (Scalar_Range (E)) then
754 return;
755 end if;
757 -- The situation that is non trivial is something like
759 -- subtype x1 is integer range -10 .. +10;
760 -- subtype x2 is x1 range 0 .. V1;
761 -- subtype x3 is x2 range V2 .. V3;
762 -- subtype x4 is x3 range V4 .. V5;
764 -- where Vn are variables. Here the base type is signed, but we still
765 -- know that x4 is unsigned because of the lower bound of x2.
767 -- The only way to deal with this is to look up the ancestor chain
769 Ancestor := E;
770 loop
771 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
772 return;
773 end if;
775 Lo_Bound := Type_Low_Bound (Ancestor);
777 if Compile_Time_Known_Value (Lo_Bound) then
779 if Expr_Rep_Value (Lo_Bound) >= 0 then
780 Set_Is_Unsigned_Type (E, True);
781 end if;
783 return;
785 else
786 Ancestor := Ancestor_Subtype (Ancestor);
788 -- If no ancestor had a static lower bound, go to base type
790 if No (Ancestor) then
792 -- Note: the reason we still check for a compile time known
793 -- value for the base type is that at least in the case of
794 -- generic formals, we can have bounds that fail this test,
795 -- and there may be other cases in error situations.
797 Btyp := Base_Type (E);
799 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
800 return;
801 end if;
803 Lo_Bound := Type_Low_Bound (Base_Type (E));
805 if Compile_Time_Known_Value (Lo_Bound)
806 and then Expr_Rep_Value (Lo_Bound) >= 0
807 then
808 Set_Is_Unsigned_Type (E, True);
809 end if;
811 return;
813 end if;
814 end if;
815 end loop;
816 end Check_Unsigned_Type;
818 ----------------
819 -- Freeze_All --
820 ----------------
822 -- Note: the easy coding for this procedure would be to just build a
823 -- single list of freeze nodes and then insert them and analyze them
824 -- all at once. This won't work, because the analysis of earlier freeze
825 -- nodes may recursively freeze types which would otherwise appear later
826 -- on in the freeze list. So we must analyze and expand the freeze nodes
827 -- as they are generated.
829 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
830 Loc : constant Source_Ptr := Sloc (After);
831 E : Entity_Id;
832 Decl : Node_Id;
834 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
835 -- This is the internal recursive routine that does freezing of
836 -- entities (but NOT the analysis of default expressions, which
837 -- should not be recursive, we don't want to analyze those till
838 -- we are sure that ALL the types are frozen).
840 procedure Freeze_All_Ent
841 (From : Entity_Id;
842 After : in out Node_Id)
844 E : Entity_Id;
845 Flist : List_Id;
846 Lastn : Node_Id;
848 procedure Process_Flist;
849 -- If freeze nodes are present, insert and analyze, and reset
850 -- cursor for next insertion.
852 procedure Process_Flist is
853 begin
854 if Is_Non_Empty_List (Flist) then
855 Lastn := Next (After);
856 Insert_List_After_And_Analyze (After, Flist);
858 if Present (Lastn) then
859 After := Prev (Lastn);
860 else
861 After := Last (List_Containing (After));
862 end if;
863 end if;
864 end Process_Flist;
866 begin
867 E := From;
868 while Present (E) loop
870 -- If the entity is an inner package which is not a package
871 -- renaming, then its entities must be frozen at this point.
872 -- Note that such entities do NOT get frozen at the end of
873 -- the nested package itself (only library packages freeze).
875 -- Same is true for task declarations, where anonymous records
876 -- created for entry parameters must be frozen.
878 if Ekind (E) = E_Package
879 and then No (Renamed_Object (E))
880 and then not Is_Child_Unit (E)
881 and then not Is_Frozen (E)
882 then
883 New_Scope (E);
884 Install_Visible_Declarations (E);
885 Install_Private_Declarations (E);
887 Freeze_All (First_Entity (E), After);
889 End_Package_Scope (E);
891 elsif Ekind (E) in Task_Kind
892 and then
893 (Nkind (Parent (E)) = N_Task_Type_Declaration
894 or else
895 Nkind (Parent (E)) = N_Single_Task_Declaration)
896 then
897 New_Scope (E);
898 Freeze_All (First_Entity (E), After);
899 End_Scope;
901 -- For a derived tagged type, we must ensure that all the
902 -- primitive operations of the parent have been frozen, so
903 -- that their addresses will be in the parent's dispatch table
904 -- at the point it is inherited.
906 elsif Ekind (E) = E_Record_Type
907 and then Is_Tagged_Type (E)
908 and then Is_Tagged_Type (Etype (E))
909 and then Is_Derived_Type (E)
910 then
911 declare
912 Prim_List : constant Elist_Id :=
913 Primitive_Operations (Etype (E));
914 Prim : Elmt_Id;
915 Subp : Entity_Id;
917 begin
918 Prim := First_Elmt (Prim_List);
920 while Present (Prim) loop
921 Subp := Node (Prim);
923 if Comes_From_Source (Subp)
924 and then not Is_Frozen (Subp)
925 then
926 Flist := Freeze_Entity (Subp, Loc);
927 Process_Flist;
928 end if;
930 Next_Elmt (Prim);
931 end loop;
932 end;
933 end if;
935 if not Is_Frozen (E) then
936 Flist := Freeze_Entity (E, Loc);
937 Process_Flist;
938 end if;
940 Next_Entity (E);
941 end loop;
942 end Freeze_All_Ent;
944 -- Start of processing for Freeze_All
946 begin
947 Freeze_All_Ent (From, After);
949 -- Now that all types are frozen, we can deal with default expressions
950 -- that require us to build a default expression functions. This is the
951 -- point at which such functions are constructed (after all types that
952 -- might be used in such expressions have been frozen).
953 -- We also add finalization chains to access types whose designated
954 -- types are controlled. This is normally done when freezing the type,
955 -- but this misses recursive type definitions where the later members
956 -- of the recursion introduce controlled components (e.g. 5624-001).
958 -- Loop through entities
960 E := From;
961 while Present (E) loop
963 if Is_Subprogram (E) then
965 if not Default_Expressions_Processed (E) then
966 Process_Default_Expressions (E, After);
967 end if;
969 if not Has_Completion (E) then
970 Decl := Unit_Declaration_Node (E);
972 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
973 Build_And_Analyze_Renamed_Body (Decl, E, After);
975 elsif Nkind (Decl) = N_Subprogram_Declaration
976 and then Present (Corresponding_Body (Decl))
977 and then
978 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
979 = N_Subprogram_Renaming_Declaration
980 then
981 Build_And_Analyze_Renamed_Body
982 (Decl, Corresponding_Body (Decl), After);
983 end if;
984 end if;
986 elsif Ekind (E) in Task_Kind
987 and then
988 (Nkind (Parent (E)) = N_Task_Type_Declaration
989 or else
990 Nkind (Parent (E)) = N_Single_Task_Declaration)
991 then
992 declare
993 Ent : Entity_Id;
995 begin
996 Ent := First_Entity (E);
998 while Present (Ent) loop
1000 if Is_Entry (Ent)
1001 and then not Default_Expressions_Processed (Ent)
1002 then
1003 Process_Default_Expressions (Ent, After);
1004 end if;
1006 Next_Entity (Ent);
1007 end loop;
1008 end;
1010 elsif Is_Access_Type (E)
1011 and then Comes_From_Source (E)
1012 and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
1013 and then Controlled_Type (Designated_Type (E))
1014 and then No (Associated_Final_Chain (E))
1015 then
1016 Build_Final_List (Parent (E), E);
1017 end if;
1019 Next_Entity (E);
1020 end loop;
1022 end Freeze_All;
1024 -----------------------
1025 -- Freeze_And_Append --
1026 -----------------------
1028 procedure Freeze_And_Append
1029 (Ent : Entity_Id;
1030 Loc : Source_Ptr;
1031 Result : in out List_Id)
1033 L : constant List_Id := Freeze_Entity (Ent, Loc);
1035 begin
1036 if Is_Non_Empty_List (L) then
1037 if Result = No_List then
1038 Result := L;
1039 else
1040 Append_List (L, Result);
1041 end if;
1042 end if;
1043 end Freeze_And_Append;
1045 -------------------
1046 -- Freeze_Before --
1047 -------------------
1049 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1050 Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
1051 F : Node_Id;
1053 begin
1054 if Is_Non_Empty_List (Freeze_Nodes) then
1055 F := First (Freeze_Nodes);
1057 if Present (F) then
1058 Insert_Actions (N, Freeze_Nodes);
1059 end if;
1060 end if;
1061 end Freeze_Before;
1063 -------------------
1064 -- Freeze_Entity --
1065 -------------------
1067 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
1068 Comp : Entity_Id;
1069 F_Node : Node_Id;
1070 Result : List_Id;
1071 Indx : Node_Id;
1072 Formal : Entity_Id;
1073 Atype : Entity_Id;
1075 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1076 -- Check that an Access or Unchecked_Access attribute with
1077 -- a prefix which is the current instance type can only be
1078 -- applied when the type is limited.
1080 function After_Last_Declaration return Boolean;
1081 -- If Loc is a freeze_entity that appears after the last declaration
1082 -- in the scope, inhibit error messages on late completion.
1084 procedure Freeze_Record_Type (Rec : Entity_Id);
1085 -- Freeze each component, handle some representation clauses, and
1086 -- freeze primitive operations if this is a tagged type.
1088 ----------------------------
1089 -- After_Last_Declaration --
1090 ----------------------------
1092 function After_Last_Declaration return Boolean is
1093 Spec : Node_Id := Parent (Current_Scope);
1095 begin
1096 if Nkind (Spec) = N_Package_Specification then
1097 if Present (Private_Declarations (Spec)) then
1098 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1100 elsif Present (Visible_Declarations (Spec)) then
1101 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1102 else
1103 return False;
1104 end if;
1106 else
1107 return False;
1108 end if;
1109 end After_Last_Declaration;
1111 ----------------------------
1112 -- Check_Current_Instance --
1113 ----------------------------
1115 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1117 function Process (N : Node_Id) return Traverse_Result;
1118 -- Process routine to apply check to given node.
1120 function Process (N : Node_Id) return Traverse_Result is
1121 begin
1122 case Nkind (N) is
1123 when N_Attribute_Reference =>
1124 if (Attribute_Name (N) = Name_Access
1125 or else
1126 Attribute_Name (N) = Name_Unchecked_Access)
1127 and then Is_Entity_Name (Prefix (N))
1128 and then Is_Type (Entity (Prefix (N)))
1129 and then Entity (Prefix (N)) = E
1130 then
1131 Error_Msg_N
1132 ("current instance must be a limited type", Prefix (N));
1133 return Abandon;
1134 else
1135 return OK;
1136 end if;
1138 when others => return OK;
1139 end case;
1140 end Process;
1142 procedure Traverse is new Traverse_Proc (Process);
1144 -- Start of processing for Check_Current_Instance
1146 begin
1147 Traverse (Comp_Decl);
1148 end Check_Current_Instance;
1150 ------------------------
1151 -- Freeze_Record_Type --
1152 ------------------------
1154 procedure Freeze_Record_Type (Rec : Entity_Id) is
1155 Comp : Entity_Id;
1156 Junk : Boolean;
1157 ADC : Node_Id;
1159 Unplaced_Component : Boolean := False;
1160 -- Set True if we find at least one component with no component
1161 -- clause (used to warn about useless Pack pragmas).
1163 Placed_Component : Boolean := False;
1164 -- Set True if we find at least one component with a component
1165 -- clause (used to warn about useless Bit_Order pragmas).
1167 begin
1168 -- Freeze components and embedded subtypes
1170 Comp := First_Entity (Rec);
1172 while Present (Comp) loop
1174 if not Is_Type (Comp) then
1175 Freeze_And_Append (Etype (Comp), Loc, Result);
1176 end if;
1178 -- If the component is an access type with an allocator
1179 -- as default value, the designated type will be frozen
1180 -- by the corresponding expression in init_proc. In order
1181 -- to place the freeze node for the designated type before
1182 -- that for the current record type, freeze it now.
1184 -- Same process if the component is an array of access types,
1185 -- initialized with an aggregate. If the designated type is
1186 -- private, it cannot contain allocators, and it is premature
1187 -- to freeze the type, so we check for this as well.
1189 if Is_Access_Type (Etype (Comp))
1190 and then Present (Parent (Comp))
1191 and then Present (Expression (Parent (Comp)))
1192 and then Nkind (Expression (Parent (Comp))) = N_Allocator
1193 then
1194 declare
1195 Alloc : constant Node_Id := Expression (Parent (Comp));
1197 begin
1198 -- If component is pointer to a classwide type, freeze
1199 -- the specific type in the expression being allocated.
1200 -- The expression may be a subtype indication, in which
1201 -- case freeze the subtype mark.
1203 if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
1205 if Is_Entity_Name (Expression (Alloc)) then
1206 Freeze_And_Append
1207 (Entity (Expression (Alloc)), Loc, Result);
1208 elsif
1209 Nkind (Expression (Alloc)) = N_Subtype_Indication
1210 then
1211 Freeze_And_Append
1212 (Entity (Subtype_Mark (Expression (Alloc))),
1213 Loc, Result);
1214 end if;
1215 else
1216 Freeze_And_Append
1217 (Designated_Type (Etype (Comp)), Loc, Result);
1218 end if;
1219 end;
1221 elsif Is_Array_Type (Etype (Comp))
1222 and then Is_Access_Type (Component_Type (Etype (Comp)))
1223 and then Present (Parent (Comp))
1224 and then Nkind (Parent (Comp)) = N_Component_Declaration
1225 and then Present (Expression (Parent (Comp)))
1226 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
1227 and then Is_Fully_Defined
1228 (Designated_Type (Component_Type (Etype (Comp))))
1229 then
1230 Freeze_And_Append
1231 (Designated_Type
1232 (Component_Type (Etype (Comp))), Loc, Result);
1233 end if;
1235 -- Processing for real components (exclude anonymous subtypes)
1237 if Ekind (Comp) = E_Component
1238 or else Ekind (Comp) = E_Discriminant
1239 then
1240 -- Check for error of component clause given for variable
1241 -- sized type. We have to delay this test till this point,
1242 -- since the component type has to be frozen for us to know
1243 -- if it is variable length. We omit this test in a generic
1244 -- context, it will be applied at instantiation time.
1246 declare
1247 CC : constant Node_Id := Component_Clause (Comp);
1249 begin
1250 if Present (CC) then
1251 Placed_Component := True;
1253 if not Size_Known_At_Compile_Time
1254 (Underlying_Type (Etype (Comp)))
1255 and then not Inside_A_Generic
1256 then
1257 Error_Msg_N
1258 ("component clause not allowed for variable " &
1259 "length component", CC);
1260 end if;
1262 else
1263 Unplaced_Component := True;
1264 end if;
1265 end;
1267 -- If component clause is present, then deal with the
1268 -- non-default bit order case. We cannot do this before
1269 -- the freeze point, because there is no required order
1270 -- for the component clause and the bit_order clause.
1272 -- We only do this processing for the base type, and in
1273 -- fact that's important, since otherwise if there are
1274 -- record subtypes, we could reverse the bits once for
1275 -- each subtype, which would be incorrect.
1277 if Present (Component_Clause (Comp))
1278 and then Reverse_Bit_Order (Rec)
1279 and then Ekind (E) = E_Record_Type
1280 then
1281 declare
1282 CFB : constant Uint := Component_Bit_Offset (Comp);
1283 CSZ : constant Uint := Esize (Comp);
1284 CLC : constant Node_Id := Component_Clause (Comp);
1285 Pos : constant Node_Id := Position (CLC);
1286 FB : constant Node_Id := First_Bit (CLC);
1288 Storage_Unit_Offset : constant Uint :=
1289 CFB / System_Storage_Unit;
1291 Start_Bit : constant Uint :=
1292 CFB mod System_Storage_Unit;
1294 begin
1295 -- Cases where field goes over storage unit boundary
1297 if Start_Bit + CSZ > System_Storage_Unit then
1299 -- Allow multi-byte field but generate warning
1301 if Start_Bit mod System_Storage_Unit = 0
1302 and then CSZ mod System_Storage_Unit = 0
1303 then
1304 Error_Msg_N
1305 ("multi-byte field specified with non-standard"
1306 & " Bit_Order?", CLC);
1308 if Bytes_Big_Endian then
1309 Error_Msg_N
1310 ("bytes are not reversed "
1311 & "(component is big-endian)?", CLC);
1312 else
1313 Error_Msg_N
1314 ("bytes are not reversed "
1315 & "(component is little-endian)?", CLC);
1316 end if;
1318 -- Do not allow non-contiguous field
1320 else
1321 Error_Msg_N
1322 ("attempt to specify non-contiguous field"
1323 & " not permitted", CLC);
1324 Error_Msg_N
1325 ("\(caused by non-standard Bit_Order "
1326 & "specified)", CLC);
1327 end if;
1329 -- Case where field fits in one storage unit
1331 else
1332 -- Give warning if suspicious component clause
1334 if Intval (FB) >= System_Storage_Unit then
1335 Error_Msg_N
1336 ("?Bit_Order clause does not affect " &
1337 "byte ordering", Pos);
1338 Error_Msg_Uint_1 :=
1339 Intval (Pos) + Intval (FB) / System_Storage_Unit;
1340 Error_Msg_N
1341 ("?position normalized to ^ before bit " &
1342 "order interpreted", Pos);
1343 end if;
1345 -- Here is where we fix up the Component_Bit_Offset
1346 -- value to account for the reverse bit order.
1347 -- Some examples of what needs to be done are:
1349 -- First_Bit .. Last_Bit Component_Bit_Offset
1350 -- old new old new
1352 -- 0 .. 0 7 .. 7 0 7
1353 -- 0 .. 1 6 .. 7 0 6
1354 -- 0 .. 2 5 .. 7 0 5
1355 -- 0 .. 7 0 .. 7 0 4
1357 -- 1 .. 1 6 .. 6 1 6
1358 -- 1 .. 4 3 .. 6 1 3
1359 -- 4 .. 7 0 .. 3 4 0
1361 -- The general rule is that the first bit is
1362 -- is obtained by subtracting the old ending bit
1363 -- from storage_unit - 1.
1365 Set_Component_Bit_Offset (Comp,
1366 (Storage_Unit_Offset * System_Storage_Unit)
1367 + (System_Storage_Unit - 1)
1368 - (Start_Bit + CSZ - 1));
1370 Set_Normalized_First_Bit (Comp,
1371 Component_Bit_Offset (Comp) mod System_Storage_Unit);
1372 end if;
1373 end;
1374 end if;
1375 end if;
1377 Next_Entity (Comp);
1378 end loop;
1380 -- Check for useless pragma Bit_Order
1382 if not Placed_Component and then Reverse_Bit_Order (Rec) then
1383 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
1384 Error_Msg_N ("?Bit_Order specification has no effect", ADC);
1385 Error_Msg_N ("\?since no component clauses were specified", ADC);
1386 end if;
1388 -- Check for useless pragma Pack when all components placed
1390 if Is_Packed (Rec)
1391 and then not Unplaced_Component
1392 and then Warn_On_Redundant_Constructs
1393 then
1394 Error_Msg_N
1395 ("?pragma Pack has no effect, no unplaced components",
1396 Get_Rep_Pragma (Rec, Name_Pack));
1397 Set_Is_Packed (Rec, False);
1398 end if;
1400 -- If this is the record corresponding to a remote type,
1401 -- freeze the remote type here since that is what we are
1402 -- semantically freeing. This prevents having the freeze node
1403 -- for that type in an inner scope.
1405 -- Also, Check for controlled components and unchecked unions.
1406 -- Finally, enforce the restriction that access attributes with
1407 -- a current instance prefix can only apply to limited types.
1409 if Ekind (Rec) = E_Record_Type then
1411 if Present (Corresponding_Remote_Type (Rec)) then
1412 Freeze_And_Append
1413 (Corresponding_Remote_Type (Rec), Loc, Result);
1414 end if;
1416 Comp := First_Component (Rec);
1418 while Present (Comp) loop
1419 if Has_Controlled_Component (Etype (Comp))
1420 or else (Chars (Comp) /= Name_uParent
1421 and then Is_Controlled (Etype (Comp)))
1422 or else (Is_Protected_Type (Etype (Comp))
1423 and then Present
1424 (Corresponding_Record_Type (Etype (Comp)))
1425 and then Has_Controlled_Component
1426 (Corresponding_Record_Type (Etype (Comp))))
1427 then
1428 Set_Has_Controlled_Component (Rec);
1429 exit;
1430 end if;
1432 if Has_Unchecked_Union (Etype (Comp)) then
1433 Set_Has_Unchecked_Union (Rec);
1434 end if;
1436 if Has_Per_Object_Constraint (Comp)
1437 and then not Is_Limited_Type (Rec)
1438 then
1439 -- Scan component declaration for likely misuses of
1440 -- current instance, either in a constraint or in a
1441 -- default expression.
1443 Check_Current_Instance (Parent (Comp));
1444 end if;
1446 Next_Component (Comp);
1447 end loop;
1448 end if;
1450 Set_Component_Alignment_If_Not_Set (Rec);
1452 -- For first subtypes, check if there are any fixed-point
1453 -- fields with component clauses, where we must check the size.
1454 -- This is not done till the freeze point, since for fixed-point
1455 -- types, we do not know the size until the type is frozen.
1457 if Is_First_Subtype (Rec) then
1458 Comp := First_Component (Rec);
1460 while Present (Comp) loop
1461 if Present (Component_Clause (Comp))
1462 and then Is_Fixed_Point_Type (Etype (Comp))
1463 then
1464 Check_Size
1465 (Component_Clause (Comp),
1466 Etype (Comp),
1467 Esize (Comp),
1468 Junk);
1469 end if;
1471 Next_Component (Comp);
1472 end loop;
1473 end if;
1474 end Freeze_Record_Type;
1476 -- Start of processing for Freeze_Entity
1478 begin
1479 -- Do not freeze if already frozen since we only need one freeze node.
1481 if Is_Frozen (E) then
1482 return No_List;
1484 -- It is improper to freeze an external entity within a generic
1485 -- because its freeze node will appear in a non-valid context.
1486 -- ??? We should probably freeze the entity at that point and insert
1487 -- the freeze node in a proper place but this proper place is not
1488 -- easy to find, and the proper scope is not easy to restore. For
1489 -- now, just wait to get out of the generic to freeze ???
1491 elsif Inside_A_Generic and then External_Ref_In_Generic (E) then
1492 return No_List;
1494 -- Do not freeze a global entity within an inner scope created during
1495 -- expansion. A call to subprogram E within some internal procedure
1496 -- (a stream attribute for example) might require freezing E, but the
1497 -- freeze node must appear in the same declarative part as E itself.
1498 -- The two-pass elaboration mechanism in gigi guarantees that E will
1499 -- be frozen before the inner call is elaborated. We exclude constants
1500 -- from this test, because deferred constants may be frozen early, and
1501 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
1502 -- comes from source, or is a generic instance, then the freeze point
1503 -- is the one mandated by the language. and we freze the entity.
1505 elsif In_Open_Scopes (Scope (E))
1506 and then Scope (E) /= Current_Scope
1507 and then Ekind (E) /= E_Constant
1508 then
1509 declare
1510 S : Entity_Id := Current_Scope;
1512 begin
1513 while Present (S) loop
1514 if Is_Overloadable (S) then
1515 if Comes_From_Source (S)
1516 or else Is_Generic_Instance (S)
1517 then
1518 exit;
1519 else
1520 return No_List;
1521 end if;
1522 end if;
1524 S := Scope (S);
1525 end loop;
1526 end;
1527 end if;
1529 -- Here to freeze the entity
1531 Result := No_List;
1532 Set_Is_Frozen (E);
1534 -- Case of entity being frozen is other than a type
1536 if not Is_Type (E) then
1538 -- If entity is exported or imported and does not have an external
1539 -- name, now is the time to provide the appropriate default name.
1540 -- Skip this if the entity is stubbed, since we don't need a name
1541 -- for any stubbed routine.
1543 if (Is_Imported (E) or else Is_Exported (E))
1544 and then No (Interface_Name (E))
1545 and then Convention (E) /= Convention_Stubbed
1546 then
1547 Set_Encoded_Interface_Name
1548 (E, Get_Default_External_Name (E));
1549 end if;
1551 -- For a subprogram, freeze all parameter types and also the return
1552 -- type (RM 13.14(13)). However skip this for internal subprograms.
1553 -- This is also the point where any extra formal parameters are
1554 -- created since we now know whether the subprogram will use
1555 -- a foreign convention.
1557 if Is_Subprogram (E) then
1559 if not Is_Internal (E) then
1561 declare
1562 F_Type : Entity_Id;
1564 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean;
1565 -- Determines if given type entity is a fat pointer type
1566 -- used as an argument type or return type to a subprogram
1567 -- with C or C++ convention set.
1569 --------------------------
1570 -- Is_Fat_C_Access_Type --
1571 --------------------------
1573 function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is
1574 begin
1575 return (Convention (E) = Convention_C
1576 or else
1577 Convention (E) = Convention_CPP)
1578 and then Is_Access_Type (T)
1579 and then Esize (T) > Ttypes.System_Address_Size;
1580 end Is_Fat_C_Ptr_Type;
1582 begin
1583 -- Loop through formals
1585 Formal := First_Formal (E);
1587 while Present (Formal) loop
1589 F_Type := Etype (Formal);
1590 Freeze_And_Append (F_Type, Loc, Result);
1592 if Is_Private_Type (F_Type)
1593 and then Is_Private_Type (Base_Type (F_Type))
1594 and then No (Full_View (Base_Type (F_Type)))
1595 and then not Is_Generic_Type (F_Type)
1596 and then not Is_Derived_Type (F_Type)
1597 then
1598 -- If the type of a formal is incomplete, subprogram
1599 -- is being frozen prematurely. Within an instance
1600 -- (but not within a wrapper package) this is an
1601 -- an artifact of our need to regard the end of an
1602 -- instantiation as a freeze point. Otherwise it is
1603 -- a definite error.
1604 -- and then not Is_Wrapper_Package (Current_Scope) ???
1606 if In_Instance then
1607 Set_Is_Frozen (E, False);
1608 return No_List;
1610 elsif not After_Last_Declaration then
1611 Error_Msg_Node_1 := F_Type;
1612 Error_Msg
1613 ("type& must be fully defined before this point",
1614 Loc);
1615 end if;
1616 end if;
1618 -- Check bad use of fat C pointer
1620 if Is_Fat_C_Ptr_Type (F_Type) then
1621 Error_Msg_Qual_Level := 1;
1622 Error_Msg_N
1623 ("?type of & does not correspond to C pointer",
1624 Formal);
1625 Error_Msg_Qual_Level := 0;
1626 end if;
1628 -- Check for unconstrained array in exported foreign
1629 -- convention case.
1631 if Convention (E) in Foreign_Convention
1632 and then not Is_Imported (E)
1633 and then Is_Array_Type (F_Type)
1634 and then not Is_Constrained (F_Type)
1635 then
1636 Error_Msg_Qual_Level := 1;
1637 Error_Msg_N
1638 ("?type of argument& is unconstrained array",
1639 Formal);
1640 Error_Msg_N
1641 ("?foreign caller must pass bounds explicitly",
1642 Formal);
1643 Error_Msg_Qual_Level := 0;
1644 end if;
1646 Next_Formal (Formal);
1647 end loop;
1649 -- Check return type
1651 if Ekind (E) = E_Function then
1652 Freeze_And_Append (Etype (E), Loc, Result);
1654 if Is_Fat_C_Ptr_Type (Etype (E)) then
1655 Error_Msg_N
1656 ("?return type of& does not correspond to C pointer",
1659 elsif Is_Array_Type (Etype (E))
1660 and then not Is_Constrained (Etype (E))
1661 and then not Is_Imported (E)
1662 and then Convention (E) in Foreign_Convention
1663 then
1664 Error_Msg_N
1665 ("foreign convention function may not " &
1666 "return unconstrained array", E);
1667 end if;
1668 end if;
1669 end;
1670 end if;
1672 -- Must freeze its parent first if it is a derived subprogram
1674 if Present (Alias (E)) then
1675 Freeze_And_Append (Alias (E), Loc, Result);
1676 end if;
1678 -- If the return type requires a transient scope, and we are on
1679 -- a target allowing functions to return with a depressed stack
1680 -- pointer, then we mark the function as requiring this treatment.
1682 if Ekind (E) = E_Function
1683 and then Functions_Return_By_DSP_On_Target
1684 and then Requires_Transient_Scope (Etype (E))
1685 then
1686 Set_Function_Returns_With_DSP (E);
1687 end if;
1689 if not Is_Internal (E) then
1690 Freeze_Subprogram (E);
1691 end if;
1693 -- Here for other than a subprogram or type
1695 else
1696 -- If entity has a type, and it is not a generic unit, then
1697 -- freeze it first (RM 13.14(10))
1699 if Present (Etype (E))
1700 and then Ekind (E) /= E_Generic_Function
1701 then
1702 Freeze_And_Append (Etype (E), Loc, Result);
1703 end if;
1705 -- For object created by object declaration, perform required
1706 -- categorization (preelaborate and pure) checks. Defer these
1707 -- checks to freeze time since pragma Import inhibits default
1708 -- initialization and thus pragma Import affects these checks.
1710 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
1711 Validate_Object_Declaration (Declaration_Node (E));
1712 end if;
1714 -- Check that a constant which has a pragma Volatile[_Components]
1715 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
1717 -- Note: Atomic[_Components] also sets Volatile[_Components]
1719 if Ekind (E) = E_Constant
1720 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
1721 and then not Is_Imported (E)
1722 then
1723 -- Make sure we actually have a pragma, and have not merely
1724 -- inherited the indication from elsewhere (e.g. an address
1725 -- clause, which is not good enough in RM terms!)
1727 if Present (Get_Rep_Pragma (E, Name_Atomic)) or else
1728 Present (Get_Rep_Pragma (E, Name_Atomic_Components)) or else
1729 Present (Get_Rep_Pragma (E, Name_Volatile)) or else
1730 Present (Get_Rep_Pragma (E, Name_Volatile_Components))
1731 then
1732 Error_Msg_N
1733 ("stand alone atomic/volatile constant must be imported",
1735 end if;
1736 end if;
1738 -- Static objects require special handling
1740 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
1741 and then Is_Statically_Allocated (E)
1742 then
1743 Freeze_Static_Object (E);
1744 end if;
1746 -- Remaining step is to layout objects
1748 if Ekind (E) = E_Variable
1749 or else
1750 Ekind (E) = E_Constant
1751 or else
1752 Ekind (E) = E_Loop_Parameter
1753 or else
1754 Is_Formal (E)
1755 then
1756 Layout_Object (E);
1757 end if;
1758 end if;
1760 -- Case of a type or subtype being frozen
1762 else
1763 -- The type may be defined in a generic unit. This can occur when
1764 -- freezing a generic function that returns the type (which is
1765 -- defined in a parent unit). It is clearly meaningless to freeze
1766 -- this type. However, if it is a subtype, its size may be determi-
1767 -- nable and used in subsequent checks, so might as well try to
1768 -- compute it.
1770 if Present (Scope (E))
1771 and then Is_Generic_Unit (Scope (E))
1772 then
1773 Check_Compile_Time_Size (E);
1774 return No_List;
1775 end if;
1777 -- Deal with special cases of freezing for subtype
1779 if E /= Base_Type (E) then
1781 -- If ancestor subtype present, freeze that first.
1782 -- Note that this will also get the base type frozen.
1784 Atype := Ancestor_Subtype (E);
1786 if Present (Atype) then
1787 Freeze_And_Append (Atype, Loc, Result);
1789 -- Otherwise freeze the base type of the entity before
1790 -- freezing the entity itself, (RM 13.14(14)).
1792 elsif E /= Base_Type (E) then
1793 Freeze_And_Append (Base_Type (E), Loc, Result);
1794 end if;
1796 -- For a derived type, freeze its parent type first (RM 13.14(14))
1798 elsif Is_Derived_Type (E) then
1799 Freeze_And_Append (Etype (E), Loc, Result);
1800 Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
1801 end if;
1803 -- For array type, freeze index types and component type first
1804 -- before freezing the array (RM 13.14(14)).
1806 if Is_Array_Type (E) then
1807 declare
1808 Ctyp : constant Entity_Id := Component_Type (E);
1810 Non_Standard_Enum : Boolean := False;
1811 -- Set true if any of the index types is an enumeration
1812 -- type with a non-standard representation.
1814 begin
1815 Freeze_And_Append (Ctyp, Loc, Result);
1817 Indx := First_Index (E);
1818 while Present (Indx) loop
1819 Freeze_And_Append (Etype (Indx), Loc, Result);
1821 if Is_Enumeration_Type (Etype (Indx))
1822 and then Has_Non_Standard_Rep (Etype (Indx))
1823 then
1824 Non_Standard_Enum := True;
1825 end if;
1827 Next_Index (Indx);
1828 end loop;
1830 -- For base type, propagate flags for component type
1832 if Ekind (E) = E_Array_Type then
1833 if Is_Controlled (Component_Type (E))
1834 or else Has_Controlled_Component (Ctyp)
1835 then
1836 Set_Has_Controlled_Component (E);
1837 end if;
1839 if Has_Unchecked_Union (Component_Type (E)) then
1840 Set_Has_Unchecked_Union (E);
1841 end if;
1842 end if;
1844 -- If packing was requested or if the component size was set
1845 -- explicitly, then see if bit packing is required. This
1846 -- processing is only done for base types, since all the
1847 -- representation aspects involved are type-related. This
1848 -- is not just an optimization, if we start processing the
1849 -- subtypes, they intefere with the settings on the base
1850 -- type (this is because Is_Packed has a slightly different
1851 -- meaning before and after freezing).
1853 if E = Base_Type (E) then
1854 declare
1855 Csiz : Uint;
1856 Esiz : Uint;
1858 begin
1859 if (Is_Packed (E) or else Has_Pragma_Pack (E))
1860 and then not Has_Atomic_Components (E)
1861 and then Known_Static_RM_Size (Ctyp)
1862 then
1863 Csiz := UI_Max (RM_Size (Ctyp), 1);
1865 elsif Known_Component_Size (E) then
1866 Csiz := Component_Size (E);
1868 elsif not Known_Static_Esize (Ctyp) then
1869 Csiz := Uint_0;
1871 else
1872 Esiz := Esize (Ctyp);
1874 -- We can set the component size if it is less than
1875 -- 16, rounding it up to the next storage unit size.
1877 if Esiz <= 8 then
1878 Csiz := Uint_8;
1879 elsif Esiz <= 16 then
1880 Csiz := Uint_16;
1881 else
1882 Csiz := Uint_0;
1883 end if;
1885 -- Set component size up to match alignment if
1886 -- it would otherwise be less than the alignment.
1887 -- This deals with cases of types whose alignment
1888 -- exceeds their sizes (padded types).
1890 if Csiz /= 0 then
1891 declare
1892 A : constant Uint := Alignment_In_Bits (Ctyp);
1894 begin
1895 if Csiz < A then
1896 Csiz := A;
1897 end if;
1898 end;
1899 end if;
1901 end if;
1903 if 1 <= Csiz and then Csiz <= 64 then
1905 -- We set the component size for all cases 1-64
1907 Set_Component_Size (Base_Type (E), Csiz);
1909 -- Actual packing is not needed for 8,16,32,64
1910 -- Also not needed for 24 if alignment is 1
1912 if Csiz = 8
1913 or else Csiz = 16
1914 or else Csiz = 32
1915 or else Csiz = 64
1916 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
1917 then
1918 -- Here the array was requested to be packed, but
1919 -- the packing request had no effect, so Is_Packed
1920 -- is reset.
1922 -- Note: semantically this means that we lose
1923 -- track of the fact that a derived type inherited
1924 -- a pack pragma that was non-effective, but that
1925 -- seems fine.
1927 -- We regard a Pack pragma as a request to set a
1928 -- representation characteristic, and this request
1929 -- may be ignored.
1931 Set_Is_Packed (Base_Type (E), False);
1933 -- In all other cases, packing is indeed needed
1935 else
1936 Set_Has_Non_Standard_Rep (Base_Type (E));
1937 Set_Is_Bit_Packed_Array (Base_Type (E));
1938 Set_Is_Packed (Base_Type (E));
1939 end if;
1940 end if;
1941 end;
1942 end if;
1944 -- If any of the index types was an enumeration type with
1945 -- a non-standard rep clause, then we indicate that the
1946 -- array type is always packed (even if it is not bit packed).
1948 if Non_Standard_Enum then
1949 Set_Has_Non_Standard_Rep (Base_Type (E));
1950 Set_Is_Packed (Base_Type (E));
1951 end if;
1952 end;
1954 Set_Component_Alignment_If_Not_Set (E);
1956 -- If the array is packed, we must create the packed array
1957 -- type to be used to actually implement the type. This is
1958 -- only needed for real array types (not for string literal
1959 -- types, since they are present only for the front end).
1961 if Is_Packed (E)
1962 and then Ekind (E) /= E_String_Literal_Subtype
1963 then
1964 Create_Packed_Array_Type (E);
1965 Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
1967 -- Size information of packed array type is copied to the
1968 -- array type, since this is really the representation.
1970 Set_Size_Info (E, Packed_Array_Type (E));
1971 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
1972 end if;
1974 -- For a class wide type, the corresponding specific type is
1975 -- frozen as well (RM 13.14(14))
1977 elsif Is_Class_Wide_Type (E) then
1978 Freeze_And_Append (Root_Type (E), Loc, Result);
1980 -- If the Class_Wide_Type is an Itype (when type is the anonymous
1981 -- parent of a derived type) and it is a library-level entity,
1982 -- generate an itype reference for it. Otherwise, its first
1983 -- explicit reference may be in an inner scope, which will be
1984 -- rejected by the back-end.
1986 if Is_Itype (E)
1987 and then Is_Compilation_Unit (Scope (E))
1988 then
1990 declare
1991 Ref : Node_Id := Make_Itype_Reference (Loc);
1993 begin
1994 Set_Itype (Ref, E);
1995 if No (Result) then
1996 Result := New_List (Ref);
1997 else
1998 Append (Ref, Result);
1999 end if;
2000 end;
2001 end if;
2003 -- For record (sub)type, freeze all the component types (RM
2004 -- 13.14(14). We test for E_Record_(sub)Type here, rather than
2005 -- using Is_Record_Type, because we don't want to attempt the
2006 -- freeze for the case of a private type with record extension
2007 -- (we will do that later when the full type is frozen).
2009 elsif Ekind (E) = E_Record_Type
2010 or else Ekind (E) = E_Record_Subtype
2011 then
2012 Freeze_Record_Type (E);
2014 -- For a concurrent type, freeze corresponding record type. This
2015 -- does not correpond to any specific rule in the RM, but the
2016 -- record type is essentially part of the concurrent type.
2017 -- Freeze as well all local entities. This includes record types
2018 -- created for entry parameter blocks, and whatever local entities
2019 -- may appear in the private part.
2021 elsif Is_Concurrent_Type (E) then
2022 if Present (Corresponding_Record_Type (E)) then
2023 Freeze_And_Append
2024 (Corresponding_Record_Type (E), Loc, Result);
2025 end if;
2027 Comp := First_Entity (E);
2029 while Present (Comp) loop
2030 if Is_Type (Comp) then
2031 Freeze_And_Append (Comp, Loc, Result);
2033 elsif (Ekind (Comp)) /= E_Function then
2034 Freeze_And_Append (Etype (Comp), Loc, Result);
2035 end if;
2037 Next_Entity (Comp);
2038 end loop;
2040 -- Private types are required to point to the same freeze node
2041 -- as their corresponding full views. The freeze node itself
2042 -- has to point to the partial view of the entity (because
2043 -- from the partial view, we can retrieve the full view, but
2044 -- not the reverse). However, in order to freeze correctly,
2045 -- we need to freeze the full view. If we are freezing at the
2046 -- end of a scope (or within the scope of the private type),
2047 -- the partial and full views will have been swapped, the
2048 -- full view appears first in the entity chain and the swapping
2049 -- mechanism enusres that the pointers are properly set (on
2050 -- scope exit).
2052 -- If we encounter the partial view before the full view
2053 -- (e.g. when freezing from another scope), we freeze the
2054 -- full view, and then set the pointers appropriately since
2055 -- we cannot rely on swapping to fix things up (subtypes in an
2056 -- outer scope might not get swapped).
2058 elsif Is_Incomplete_Or_Private_Type (E)
2059 and then not Is_Generic_Type (E)
2060 then
2061 -- Case of full view present
2063 if Present (Full_View (E)) then
2065 -- If full view has already been frozen, then no
2066 -- further processing is required
2068 if Is_Frozen (Full_View (E)) then
2070 Set_Has_Delayed_Freeze (E, False);
2071 Set_Freeze_Node (E, Empty);
2072 Check_Debug_Info_Needed (E);
2074 -- Otherwise freeze full view and patch the pointers
2076 else
2077 if Is_Private_Type (Full_View (E))
2078 and then Present (Underlying_Full_View (Full_View (E)))
2079 then
2080 Freeze_And_Append
2081 (Underlying_Full_View (Full_View (E)), Loc, Result);
2082 end if;
2084 Freeze_And_Append (Full_View (E), Loc, Result);
2086 if Has_Delayed_Freeze (E) then
2087 F_Node := Freeze_Node (Full_View (E));
2089 if Present (F_Node) then
2090 Set_Freeze_Node (E, F_Node);
2091 Set_Entity (F_Node, E);
2092 else
2093 -- {Incomplete,Private}_Subtypes
2094 -- with Full_Views constrained by discriminants
2096 Set_Has_Delayed_Freeze (E, False);
2097 Set_Freeze_Node (E, Empty);
2098 end if;
2099 end if;
2101 Check_Debug_Info_Needed (E);
2102 end if;
2104 -- AI-117 requires that the convention of a partial view
2105 -- be the same as the convention of the full view. Note
2106 -- that this is a recognized breach of privacy, but it's
2107 -- essential for logical consistency of representation,
2108 -- and the lack of a rule in RM95 was an oversight.
2110 Set_Convention (E, Convention (Full_View (E)));
2112 Set_Size_Known_At_Compile_Time (E,
2113 Size_Known_At_Compile_Time (Full_View (E)));
2115 -- Size information is copied from the full view to the
2116 -- incomplete or private view for consistency
2118 -- We skip this is the full view is not a type. This is
2119 -- very strange of course, and can only happen as a result
2120 -- of certain illegalities, such as a premature attempt to
2121 -- derive from an incomplete type.
2123 if Is_Type (Full_View (E)) then
2124 Set_Size_Info (E, Full_View (E));
2125 Set_RM_Size (E, RM_Size (Full_View (E)));
2126 end if;
2128 return Result;
2130 -- Case of no full view present. If entity is derived or subtype,
2131 -- it is safe to freeze, correctness depends on the frozen status
2132 -- of parent. Otherwise it is either premature usage, or a Taft
2133 -- amendment type, so diagnosis is at the point of use and the
2134 -- type might be frozen later.
2136 elsif E /= Base_Type (E)
2137 or else Is_Derived_Type (E)
2138 then
2139 null;
2141 else
2142 Set_Is_Frozen (E, False);
2143 return No_List;
2144 end if;
2146 -- For access subprogram, freeze types of all formals, the return
2147 -- type was already frozen, since it is the Etype of the function.
2149 elsif Ekind (E) = E_Subprogram_Type then
2150 Formal := First_Formal (E);
2151 while Present (Formal) loop
2152 Freeze_And_Append (Etype (Formal), Loc, Result);
2153 Next_Formal (Formal);
2154 end loop;
2156 -- If the return type requires a transient scope, and we are on
2157 -- a target allowing functions to return with a depressed stack
2158 -- pointer, then we mark the function as requiring this treatment.
2160 if Functions_Return_By_DSP_On_Target
2161 and then Requires_Transient_Scope (Etype (E))
2162 then
2163 Set_Function_Returns_With_DSP (E);
2164 end if;
2166 Freeze_Subprogram (E);
2168 -- For access to a protected subprogram, freeze the equivalent
2169 -- type (however this is not set if we are not generating code)
2170 -- or if this is an anonymous type used just for resolution).
2172 elsif Ekind (E) = E_Access_Protected_Subprogram_Type
2173 and then Operating_Mode = Generate_Code
2174 and then Present (Equivalent_Type (E))
2175 then
2176 Freeze_And_Append (Equivalent_Type (E), Loc, Result);
2177 end if;
2179 -- Generic types are never seen by the back-end, and are also not
2180 -- processed by the expander (since the expander is turned off for
2181 -- generic processing), so we never need freeze nodes for them.
2183 if Is_Generic_Type (E) then
2184 return Result;
2185 end if;
2187 -- Some special processing for non-generic types to complete
2188 -- representation details not known till the freeze point.
2190 if Is_Fixed_Point_Type (E) then
2191 Freeze_Fixed_Point_Type (E);
2193 elsif Is_Enumeration_Type (E) then
2194 Freeze_Enumeration_Type (E);
2196 elsif Is_Integer_Type (E) then
2197 Adjust_Esize_For_Alignment (E);
2199 elsif Is_Access_Type (E)
2200 and then No (Associated_Storage_Pool (E))
2201 then
2202 Check_Restriction (No_Standard_Storage_Pools, E);
2203 end if;
2205 -- If the current entity is an array or record subtype and has
2206 -- discriminants used to constrain it, it must not freeze, because
2207 -- Freeze_Entity nodes force Gigi to process the frozen type.
2209 if Is_Composite_Type (E) then
2211 if Is_Array_Type (E) then
2213 declare
2214 Index : Node_Id := First_Index (E);
2215 Expr1 : Node_Id;
2216 Expr2 : Node_Id;
2218 begin
2219 while Present (Index) loop
2220 if Etype (Index) /= Any_Type then
2221 Get_Index_Bounds (Index, Expr1, Expr2);
2223 for J in 1 .. 2 loop
2224 if Nkind (Expr1) = N_Identifier
2225 and then Ekind (Entity (Expr1)) = E_Discriminant
2226 then
2227 Set_Has_Delayed_Freeze (E, False);
2228 Set_Freeze_Node (E, Empty);
2229 Check_Debug_Info_Needed (E);
2230 return Result;
2231 end if;
2233 Expr1 := Expr2;
2234 end loop;
2235 end if;
2237 Next_Index (Index);
2238 end loop;
2239 end;
2241 elsif Has_Discriminants (E)
2242 and Is_Constrained (E)
2243 then
2245 declare
2246 Constraint : Elmt_Id;
2247 Expr : Node_Id;
2248 begin
2249 Constraint := First_Elmt (Discriminant_Constraint (E));
2251 while Present (Constraint) loop
2253 Expr := Node (Constraint);
2254 if Nkind (Expr) = N_Identifier
2255 and then Ekind (Entity (Expr)) = E_Discriminant
2256 then
2257 Set_Has_Delayed_Freeze (E, False);
2258 Set_Freeze_Node (E, Empty);
2259 Check_Debug_Info_Needed (E);
2260 return Result;
2261 end if;
2263 Next_Elmt (Constraint);
2264 end loop;
2265 end;
2267 end if;
2269 -- AI-117 requires that all new primitives of a tagged type
2270 -- must inherit the convention of the full view of the type.
2271 -- Inherited and overriding operations are defined to inherit
2272 -- the convention of their parent or overridden subprogram
2273 -- (also specified in AI-117), and that will have occurred
2274 -- earlier (in Derive_Subprogram and New_Overloaded_Entity).
2275 -- Here we set the convention of primitives that are still
2276 -- convention Ada, which will ensure that any new primitives
2277 -- inherit the type's convention. Class-wide types can have
2278 -- a foreign convention inherited from their specific type,
2279 -- but are excluded from this since they don't have any
2280 -- associated primitives.
2282 if Is_Tagged_Type (E)
2283 and then not Is_Class_Wide_Type (E)
2284 and then Convention (E) /= Convention_Ada
2285 then
2286 declare
2287 Prim_List : constant Elist_Id := Primitive_Operations (E);
2288 Prim : Elmt_Id := First_Elmt (Prim_List);
2290 begin
2291 while Present (Prim) loop
2292 if Convention (Node (Prim)) = Convention_Ada then
2293 Set_Convention (Node (Prim), Convention (E));
2294 end if;
2296 Next_Elmt (Prim);
2297 end loop;
2298 end;
2299 end if;
2300 end if;
2302 -- Now that all types from which E may depend are frozen, see
2303 -- if the size is known at compile time, if it must be unsigned,
2304 -- or if strict alignent is required
2306 Check_Compile_Time_Size (E);
2307 Check_Unsigned_Type (E);
2309 if Base_Type (E) = E then
2310 Check_Strict_Alignment (E);
2311 end if;
2313 -- Do not allow a size clause for a type which does not have a size
2314 -- that is known at compile time
2316 if Has_Size_Clause (E)
2317 and then not Size_Known_At_Compile_Time (E)
2318 then
2319 Error_Msg_N
2320 ("size clause not allowed for variable length type",
2321 Size_Clause (E));
2322 end if;
2324 -- Remaining process is to set/verify the representation information,
2325 -- in particular the size and alignment values. This processing is
2326 -- not required for generic types, since generic types do not play
2327 -- any part in code generation, and so the size and alignment values
2328 -- for suhc types are irrelevant.
2330 if Is_Generic_Type (E) then
2331 return Result;
2333 -- Otherwise we call the layout procedure
2335 else
2336 Layout_Type (E);
2337 end if;
2339 -- End of freeze processing for type entities
2340 end if;
2342 -- Here is where we logically freeze the current entity. If it has a
2343 -- freeze node, then this is the point at which the freeze node is
2344 -- linked into the result list.
2346 if Has_Delayed_Freeze (E) then
2348 -- If a freeze node is already allocated, use it, otherwise allocate
2349 -- a new one. The preallocation happens in the case of anonymous base
2350 -- types, where we preallocate so that we can set First_Subtype_Link.
2351 -- Note that we reset the Sloc to the current freeze location.
2353 if Present (Freeze_Node (E)) then
2354 F_Node := Freeze_Node (E);
2355 Set_Sloc (F_Node, Loc);
2357 else
2358 F_Node := New_Node (N_Freeze_Entity, Loc);
2359 Set_Freeze_Node (E, F_Node);
2360 Set_Access_Types_To_Process (F_Node, No_Elist);
2361 Set_TSS_Elist (F_Node, No_Elist);
2362 Set_Actions (F_Node, No_List);
2363 end if;
2365 Set_Entity (F_Node, E);
2367 if Result = No_List then
2368 Result := New_List (F_Node);
2369 else
2370 Append (F_Node, Result);
2371 end if;
2373 end if;
2375 -- When a type is frozen, the first subtype of the type is frozen as
2376 -- well (RM 13.14(15)). This has to be done after freezing the type,
2377 -- since obviously the first subtype depends on its own base type.
2379 if Is_Type (E) then
2380 Freeze_And_Append (First_Subtype (E), Loc, Result);
2382 -- If we just froze a tagged non-class wide record, then freeze the
2383 -- corresponding class-wide type. This must be done after the tagged
2384 -- type itself is frozen, because the class-wide type refers to the
2385 -- tagged type which generates the class.
2387 if Is_Tagged_Type (E)
2388 and then not Is_Class_Wide_Type (E)
2389 and then Present (Class_Wide_Type (E))
2390 then
2391 Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
2392 end if;
2393 end if;
2395 Check_Debug_Info_Needed (E);
2397 -- Special handling for subprograms
2399 if Is_Subprogram (E) then
2401 -- If subprogram has address clause then reset Is_Public flag, since
2402 -- we do not want the backend to generate external references.
2404 if Present (Address_Clause (E))
2405 and then not Is_Library_Level_Entity (E)
2406 then
2407 Set_Is_Public (E, False);
2409 -- If no address clause and not intrinsic, then for imported
2410 -- subprogram in main unit, generate descriptor if we are in
2411 -- Propagate_Exceptions mode.
2413 elsif Propagate_Exceptions
2414 and then Is_Imported (E)
2415 and then not Is_Intrinsic_Subprogram (E)
2416 and then Convention (E) /= Convention_Stubbed
2417 then
2418 if Result = No_List then
2419 Result := Empty_List;
2420 end if;
2422 Generate_Subprogram_Descriptor_For_Imported_Subprogram
2423 (E, Result);
2424 end if;
2426 end if;
2428 return Result;
2429 end Freeze_Entity;
2431 -----------------------------
2432 -- Freeze_Enumeration_Type --
2433 -----------------------------
2435 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
2436 begin
2437 if Has_Foreign_Convention (Typ)
2438 and then not Has_Size_Clause (Typ)
2439 and then Esize (Typ) < Standard_Integer_Size
2440 then
2441 Init_Esize (Typ, Standard_Integer_Size);
2443 else
2444 Adjust_Esize_For_Alignment (Typ);
2445 end if;
2446 end Freeze_Enumeration_Type;
2448 -----------------------
2449 -- Freeze_Expression --
2450 -----------------------
2452 procedure Freeze_Expression (N : Node_Id) is
2453 In_Def_Exp : constant Boolean := In_Default_Expression;
2454 Typ : Entity_Id;
2455 Nam : Entity_Id;
2456 Desig_Typ : Entity_Id;
2457 P : Node_Id;
2458 Parent_P : Node_Id;
2460 Freeze_Outside : Boolean := False;
2461 -- This flag is set true if the entity must be frozen outside the
2462 -- current subprogram. This happens in the case of expander generated
2463 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
2464 -- not freeze all entities like other bodies, but which nevertheless
2465 -- may reference entities that have to be frozen before the body and
2466 -- obviously cannot be frozen inside the body.
2468 function In_Exp_Body (N : Node_Id) return Boolean;
2469 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
2470 -- it is the handled statement sequence of an expander generated
2471 -- subprogram (init proc, or stream subprogram). If so, it returns
2472 -- True, otherwise False.
2474 function In_Exp_Body (N : Node_Id) return Boolean is
2475 P : Node_Id;
2477 begin
2478 if Nkind (N) = N_Subprogram_Body then
2479 P := N;
2480 else
2481 P := Parent (N);
2482 end if;
2484 if Nkind (P) /= N_Subprogram_Body then
2485 return False;
2487 else
2488 P := Defining_Unit_Name (Specification (P));
2490 if Nkind (P) = N_Defining_Identifier
2491 and then (Chars (P) = Name_uInit_Proc or else
2492 Chars (P) = Name_uInput or else
2493 Chars (P) = Name_uOutput or else
2494 Chars (P) = Name_uRead or else
2495 Chars (P) = Name_uWrite)
2496 then
2497 return True;
2498 else
2499 return False;
2500 end if;
2501 end if;
2503 end In_Exp_Body;
2505 -- Start of processing for Freeze_Expression
2507 begin
2508 -- Immediate return if freezing is inhibited. This flag is set by
2509 -- the analyzer to stop freezing on generated expressions that would
2510 -- cause freezing if they were in the source program, but which are
2511 -- not supposed to freeze, since they are created.
2513 if Must_Not_Freeze (N) then
2514 return;
2515 end if;
2517 -- If expression is non-static, then it does not freeze in a default
2518 -- expression, see section "Handling of Default Expressions" in the
2519 -- spec of package Sem for further details. Note that we have to
2520 -- make sure that we actually have a real expression (if we have
2521 -- a subtype indication, we can't test Is_Static_Expression!)
2523 if In_Def_Exp
2524 and then Nkind (N) in N_Subexpr
2525 and then not Is_Static_Expression (N)
2526 then
2527 return;
2528 end if;
2530 -- Freeze type of expression if not frozen already
2532 if Nkind (N) in N_Has_Etype
2533 and then not Is_Frozen (Etype (N))
2534 then
2535 Typ := Etype (N);
2536 else
2537 Typ := Empty;
2538 end if;
2540 -- For entity name, freeze entity if not frozen already. A special
2541 -- exception occurs for an identifier that did not come from source.
2542 -- We don't let such identifiers freeze a non-internal entity, i.e.
2543 -- an entity that did come from source, since such an identifier was
2544 -- generated by the expander, and cannot have any semantic effect on
2545 -- the freezing semantics. For example, this stops the parameter of
2546 -- an initialization procedure from freezing the variable.
2548 if Is_Entity_Name (N)
2549 and then not Is_Frozen (Entity (N))
2550 and then (Nkind (N) /= N_Identifier
2551 or else Comes_From_Source (N)
2552 or else not Comes_From_Source (Entity (N)))
2553 then
2554 Nam := Entity (N);
2556 else
2557 Nam := Empty;
2558 end if;
2560 -- For an allocator freeze designated type if not frozen already.
2562 -- For an aggregate whose component type is an access type, freeze
2563 -- the designated type now, so that its freeze does not appear within
2564 -- the loop that might be created in the expansion of the aggregate.
2565 -- If the designated type is a private type without full view, the
2566 -- expression cannot contain an allocator, so the type is not frozen.
2568 Desig_Typ := Empty;
2569 case Nkind (N) is
2571 when N_Allocator =>
2572 Desig_Typ := Designated_Type (Etype (N));
2574 when N_Aggregate =>
2575 if Is_Array_Type (Etype (N))
2576 and then Is_Access_Type (Component_Type (Etype (N)))
2577 then
2578 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
2579 end if;
2581 when N_Selected_Component |
2582 N_Indexed_Component |
2583 N_Slice =>
2585 if Is_Access_Type (Etype (Prefix (N))) then
2586 Desig_Typ := Designated_Type (Etype (Prefix (N)));
2587 end if;
2589 when others =>
2590 null;
2592 end case;
2594 if Desig_Typ /= Empty
2595 and then (Is_Frozen (Desig_Typ)
2596 or else (not Is_Fully_Defined (Desig_Typ)))
2597 then
2598 Desig_Typ := Empty;
2599 end if;
2601 -- All done if nothing needs freezing
2603 if No (Typ)
2604 and then No (Nam)
2605 and then No (Desig_Typ)
2606 then
2607 return;
2608 end if;
2610 -- Loop for looking at the right place to insert the freeze nodes
2611 -- exiting from the loop when it is appropriate to insert the freeze
2612 -- node before the current node P.
2614 -- Also checks some special exceptions to the freezing rules. These
2615 -- cases result in a direct return, bypassing the freeze action.
2617 P := N;
2618 loop
2619 Parent_P := Parent (P);
2621 -- If we don't have a parent, then we are not in a well-formed
2622 -- tree. This is an unusual case, but there are some legitimate
2623 -- situations in which this occurs, notably when the expressions
2624 -- in the range of a type declaration are resolved. We simply
2625 -- ignore the freeze request in this case. Is this right ???
2627 if No (Parent_P) then
2628 return;
2629 end if;
2631 -- See if we have got to an appropriate point in the tree
2633 case Nkind (Parent_P) is
2635 -- A special test for the exception of (RM 13.14(8)) for the
2636 -- case of per-object expressions (RM 3.8(18)) occurring in a
2637 -- component definition or a discrete subtype definition. Note
2638 -- that we test for a component declaration which includes both
2639 -- cases we are interested in, and furthermore the tree does not
2640 -- have explicit nodes for either of these two constructs.
2642 when N_Component_Declaration =>
2644 -- The case we want to test for here is an identifier that is
2645 -- a per-object expression, this is either a discriminant that
2646 -- appears in a context other than the component declaration
2647 -- or it is a reference to the type of the enclosing construct.
2649 -- For either of these cases, we skip the freezing
2651 if not In_Default_Expression
2652 and then Nkind (N) = N_Identifier
2653 and then (Present (Entity (N)))
2654 then
2655 -- We recognize the discriminant case by just looking for
2656 -- a reference to a discriminant. It can only be one for
2657 -- the enclosing construct. Skip freezing in this case.
2659 if Ekind (Entity (N)) = E_Discriminant then
2660 return;
2662 -- For the case of a reference to the enclosing record,
2663 -- (or task or protected type), we look for a type that
2664 -- matches the current scope.
2666 elsif Entity (N) = Current_Scope then
2667 return;
2668 end if;
2669 end if;
2671 -- If we have an enumeration literal that appears as the
2672 -- choice in the aggregate of an enumeration representation
2673 -- clause, then freezing does not occur (RM 13.14(9)).
2675 when N_Enumeration_Representation_Clause =>
2677 -- The case we are looking for is an enumeration literal
2679 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
2680 and then Is_Enumeration_Type (Etype (N))
2681 then
2682 -- If enumeration literal appears directly as the choice,
2683 -- do not freeze (this is the normal non-overloade case)
2685 if Nkind (Parent (N)) = N_Component_Association
2686 and then First (Choices (Parent (N))) = N
2687 then
2688 return;
2690 -- If enumeration literal appears as the name of a
2691 -- function which is the choice, then also do not freeze.
2692 -- This happens in the overloaded literal case, where the
2693 -- enumeration literal is temporarily changed to a function
2694 -- call for overloading analysis purposes.
2696 elsif Nkind (Parent (N)) = N_Function_Call
2697 and then
2698 Nkind (Parent (Parent (N))) = N_Component_Association
2699 and then
2700 First (Choices (Parent (Parent (N)))) = Parent (N)
2701 then
2702 return;
2703 end if;
2704 end if;
2706 -- Normally if the parent is a handled sequence of statements,
2707 -- then the current node must be a statement, and that is an
2708 -- appropriate place to insert a freeze node.
2710 when N_Handled_Sequence_Of_Statements =>
2712 -- An exception occurs when the sequence of statements is
2713 -- for an expander generated body that did not do the usual
2714 -- freeze all operation. In this case we usually want to
2715 -- freeze outside this body, not inside it, and we skip
2716 -- past the subprogram body that we are inside.
2718 if In_Exp_Body (Parent_P) then
2720 -- However, we *do* want to freeze at this point if we have
2721 -- an entity to freeze, and that entity is declared *inside*
2722 -- the body of the expander generated procedure. This case
2723 -- is recognized by the scope of the type, which is either
2724 -- the spec for some enclosing body, or (in the case of
2725 -- init_procs, for which there are no separate specs) the
2726 -- current scope.
2728 declare
2729 Subp : constant Node_Id := Parent (Parent_P);
2730 Cspc : Entity_Id;
2732 begin
2733 if Nkind (Subp) = N_Subprogram_Body then
2734 Cspc := Corresponding_Spec (Subp);
2736 if (Present (Typ) and then Scope (Typ) = Cspc)
2737 or else
2738 (Present (Nam) and then Scope (Nam) = Cspc)
2739 then
2740 exit;
2742 elsif Present (Typ)
2743 and then Scope (Typ) = Current_Scope
2744 and then Current_Scope = Defining_Entity (Subp)
2745 then
2746 exit;
2747 end if;
2748 end if;
2749 end;
2751 -- If not that exception to the exception, then this is
2752 -- where we delay the freeze till outside the body.
2754 Parent_P := Parent (Parent_P);
2755 Freeze_Outside := True;
2757 -- Here if normal case where we are in handled statement
2758 -- sequence and want to do the insertion right there.
2760 else
2761 exit;
2762 end if;
2764 -- If parent is a body or a spec or a block, then the current
2765 -- node is a statement or declaration and we can insert the
2766 -- freeze node before it.
2768 when N_Package_Specification |
2769 N_Package_Body |
2770 N_Subprogram_Body |
2771 N_Task_Body |
2772 N_Protected_Body |
2773 N_Entry_Body |
2774 N_Block_Statement => exit;
2776 -- The expander is allowed to define types in any statements list,
2777 -- so any of the following parent nodes also mark a freezing point
2778 -- if the actual node is in a list of statements or declarations.
2780 when N_Exception_Handler |
2781 N_If_Statement |
2782 N_Elsif_Part |
2783 N_Case_Statement_Alternative |
2784 N_Compilation_Unit_Aux |
2785 N_Selective_Accept |
2786 N_Accept_Alternative |
2787 N_Delay_Alternative |
2788 N_Conditional_Entry_Call |
2789 N_Entry_Call_Alternative |
2790 N_Triggering_Alternative |
2791 N_Abortable_Part |
2792 N_Freeze_Entity =>
2794 exit when Is_List_Member (P);
2796 -- Note: The N_Loop_Statement is a special case. A type that
2797 -- appears in the source can never be frozen in a loop (this
2798 -- occurs only because of a loop expanded by the expander),
2799 -- so we keep on going. Otherwise we terminate the search.
2800 -- Same is true of any entity which comes from source. (if they
2801 -- have a predefined type, that type does not appear to come
2802 -- from source, but the entity should not be frozen here).
2804 when N_Loop_Statement =>
2805 exit when not Comes_From_Source (Etype (N))
2806 and then (No (Nam) or else not Comes_From_Source (Nam));
2808 -- For all other cases, keep looking at parents
2810 when others =>
2811 null;
2812 end case;
2814 -- We fall through the case if we did not yet find the proper
2815 -- place in the free for inserting the freeze node, so climb!
2817 P := Parent_P;
2818 end loop;
2820 -- If the expression appears in a record or an initialization
2821 -- procedure, the freeze nodes are collected and attached to
2822 -- the current scope, to be inserted and analyzed on exit from
2823 -- the scope, to insure that generated entities appear in the
2824 -- correct scope. If the expression is a default for a discriminant
2825 -- specification, the scope is still void. The expression can also
2826 -- appear in the discriminant part of a private or concurrent type.
2828 -- The other case requiring this special handling is if we are in
2829 -- a default expression, since in that case we are about to freeze
2830 -- a static type, and the freeze scope needs to be the outer scope,
2831 -- not the scope of the subprogram with the default parameter.
2833 -- For default expressions in generic units, the Move_Freeze_Nodes
2834 -- mechanism (see sem_ch12.adb) takes care of placing them at the
2835 -- proper place, after the generic unit.
2837 if (In_Def_Exp and not Inside_A_Generic)
2838 or else Freeze_Outside
2839 or else (Is_Type (Current_Scope)
2840 and then (not Is_Concurrent_Type (Current_Scope)
2841 or else not Has_Completion (Current_Scope)))
2842 or else Ekind (Current_Scope) = E_Void
2843 then
2844 declare
2845 Loc : constant Source_Ptr := Sloc (Current_Scope);
2846 Freeze_Nodes : List_Id := No_List;
2848 begin
2849 if Present (Desig_Typ) then
2850 Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
2851 end if;
2853 if Present (Typ) then
2854 Freeze_And_Append (Typ, Loc, Freeze_Nodes);
2855 end if;
2857 if Present (Nam) then
2858 Freeze_And_Append (Nam, Loc, Freeze_Nodes);
2859 end if;
2861 if Is_Non_Empty_List (Freeze_Nodes) then
2863 if No (Scope_Stack.Table
2864 (Scope_Stack.Last).Pending_Freeze_Actions)
2865 then
2866 Scope_Stack.Table
2867 (Scope_Stack.Last).Pending_Freeze_Actions :=
2868 Freeze_Nodes;
2869 else
2870 Append_List (Freeze_Nodes, Scope_Stack.Table
2871 (Scope_Stack.Last).Pending_Freeze_Actions);
2872 end if;
2873 end if;
2874 end;
2876 return;
2877 end if;
2879 -- Now we have the right place to do the freezing. First, a special
2880 -- adjustment, if we are in default expression analysis mode, these
2881 -- freeze actions must not be thrown away (normally all inserted
2882 -- actions are thrown away in this mode. However, the freeze actions
2883 -- are from static expressions and one of the important reasons we
2884 -- are doing this special analysis is to get these freeze actions.
2885 -- Therefore we turn off the In_Default_Expression mode to propagate
2886 -- these freeze actions. This also means they get properly analyzed
2887 -- and expanded.
2889 In_Default_Expression := False;
2891 -- Freeze the designated type of an allocator (RM 13.14(12))
2893 if Present (Desig_Typ) then
2894 Freeze_Before (P, Desig_Typ);
2895 end if;
2897 -- Freeze type of expression (RM 13.14(9)). Note that we took care of
2898 -- the enumeration representation clause exception in the loop above.
2900 if Present (Typ) then
2901 Freeze_Before (P, Typ);
2902 end if;
2904 -- Freeze name if one is present (RM 13.14(10))
2906 if Present (Nam) then
2907 Freeze_Before (P, Nam);
2908 end if;
2910 In_Default_Expression := In_Def_Exp;
2911 end Freeze_Expression;
2913 -----------------------------
2914 -- Freeze_Fixed_Point_Type --
2915 -----------------------------
2917 -- Certain fixed-point types and subtypes, including implicit base
2918 -- types and declared first subtypes, have not yet set up a range.
2919 -- This is because the range cannot be set until the Small and Size
2920 -- values are known, and these are not known till the type is frozen.
2922 -- To signal this case, Scalar_Range contains an unanalyzed syntactic
2923 -- range whose bounds are unanalyzed real literals. This routine will
2924 -- recognize this case, and transform this range node into a properly
2925 -- typed range with properly analyzed and resolved values.
2927 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
2928 Rng : constant Node_Id := Scalar_Range (Typ);
2929 Lo : constant Node_Id := Low_Bound (Rng);
2930 Hi : constant Node_Id := High_Bound (Rng);
2931 Btyp : constant Entity_Id := Base_Type (Typ);
2932 Brng : constant Node_Id := Scalar_Range (Btyp);
2933 BLo : constant Node_Id := Low_Bound (Brng);
2934 BHi : constant Node_Id := High_Bound (Brng);
2935 Small : constant Ureal := Small_Value (Typ);
2936 Loval : Ureal;
2937 Hival : Ureal;
2938 Atype : Entity_Id;
2940 Actual_Size : Nat;
2942 function Fsize (Lov, Hiv : Ureal) return Nat;
2943 -- Returns size of type with given bounds. Also leaves these
2944 -- bounds set as the current bounds of the Typ.
2946 function Fsize (Lov, Hiv : Ureal) return Nat is
2947 begin
2948 Set_Realval (Lo, Lov);
2949 Set_Realval (Hi, Hiv);
2950 return Minimum_Size (Typ);
2951 end Fsize;
2953 -- Start of processing for Freeze_Fixed_Point_Type;
2955 begin
2956 -- If Esize of a subtype has not previously been set, set it now
2958 if Unknown_Esize (Typ) then
2959 Atype := Ancestor_Subtype (Typ);
2961 if Present (Atype) then
2962 Set_Size_Info (Typ, Atype);
2963 else
2964 Set_Size_Info (Typ, Base_Type (Typ));
2965 end if;
2966 end if;
2968 -- Immediate return if the range is already analyzed. This means
2969 -- that the range is already set, and does not need to be computed
2970 -- by this routine.
2972 if Analyzed (Rng) then
2973 return;
2974 end if;
2976 -- Immediate return if either of the bounds raises Constraint_Error
2978 if Raises_Constraint_Error (Lo)
2979 or else Raises_Constraint_Error (Hi)
2980 then
2981 return;
2982 end if;
2984 Loval := Realval (Lo);
2985 Hival := Realval (Hi);
2987 -- Ordinary fixed-point case
2989 if Is_Ordinary_Fixed_Point_Type (Typ) then
2991 -- For the ordinary fixed-point case, we are allowed to fudge the
2992 -- end-points up or down by small. Generally we prefer to fudge
2993 -- up, i.e. widen the bounds for non-model numbers so that the
2994 -- end points are included. However there are cases in which this
2995 -- cannot be done, and indeed cases in which we may need to narrow
2996 -- the bounds. The following circuit makes the decision.
2998 -- Note: our terminology here is that Incl_EP means that the
2999 -- bounds are widened by Small if necessary to include the end
3000 -- points, and Excl_EP means that the bounds are narrowed by
3001 -- Small to exclude the end-points if this reduces the size.
3003 -- Note that in the Incl case, all we care about is including the
3004 -- end-points. In the Excl case, we want to narrow the bounds as
3005 -- much as permitted by the RM, to give the smallest possible size.
3007 Fudge : declare
3008 Loval_Incl_EP : Ureal;
3009 Hival_Incl_EP : Ureal;
3011 Loval_Excl_EP : Ureal;
3012 Hival_Excl_EP : Ureal;
3014 Size_Incl_EP : Nat;
3015 Size_Excl_EP : Nat;
3017 Model_Num : Ureal;
3018 First_Subt : Entity_Id;
3019 Actual_Lo : Ureal;
3020 Actual_Hi : Ureal;
3022 begin
3023 -- First step. Base types are required to be symmetrical. Right
3024 -- now, the base type range is a copy of the first subtype range.
3025 -- This will be corrected before we are done, but right away we
3026 -- need to deal with the case where both bounds are non-negative.
3027 -- In this case, we set the low bound to the negative of the high
3028 -- bound, to make sure that the size is computed to include the
3029 -- required sign. Note that we do not need to worry about the
3030 -- case of both bounds negative, because the sign will be dealt
3031 -- with anyway. Furthermore we can't just go making such a bound
3032 -- symmetrical, since in a twos-complement system, there is an
3033 -- extra negative value which could not be accomodated on the
3034 -- positive side.
3036 if Typ = Btyp
3037 and then not UR_Is_Negative (Loval)
3038 and then Hival > Loval
3039 then
3040 Loval := -Hival;
3041 Set_Realval (Lo, Loval);
3042 end if;
3044 -- Compute the fudged bounds. If the number is a model number,
3045 -- then we do nothing to include it, but we are allowed to
3046 -- backoff to the next adjacent model number when we exclude
3047 -- it. If it is not a model number then we straddle the two
3048 -- values with the model numbers on either side.
3050 Model_Num := UR_Trunc (Loval / Small) * Small;
3052 if Loval = Model_Num then
3053 Loval_Incl_EP := Model_Num;
3054 else
3055 Loval_Incl_EP := Model_Num - Small;
3056 end if;
3058 -- The low value excluding the end point is Small greater, but
3059 -- we do not do this exclusion if the low value is positive,
3060 -- since it can't help the size and could actually hurt by
3061 -- crossing the high bound.
3063 if UR_Is_Negative (Loval_Incl_EP) then
3064 Loval_Excl_EP := Loval_Incl_EP + Small;
3065 else
3066 Loval_Excl_EP := Loval_Incl_EP;
3067 end if;
3069 -- Similar processing for upper bound and high value
3071 Model_Num := UR_Trunc (Hival / Small) * Small;
3073 if Hival = Model_Num then
3074 Hival_Incl_EP := Model_Num;
3075 else
3076 Hival_Incl_EP := Model_Num + Small;
3077 end if;
3079 if UR_Is_Positive (Hival_Incl_EP) then
3080 Hival_Excl_EP := Hival_Incl_EP - Small;
3081 else
3082 Hival_Excl_EP := Hival_Incl_EP;
3083 end if;
3085 -- One further adjustment is needed. In the case of subtypes,
3086 -- we cannot go outside the range of the base type, or we get
3087 -- peculiarities, and the base type range is already set. This
3088 -- only applies to the Incl values, since clearly the Excl
3089 -- values are already as restricted as they are allowed to be.
3091 if Typ /= Btyp then
3092 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
3093 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
3094 end if;
3096 -- Get size including and excluding end points
3098 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
3099 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
3101 -- No need to exclude end-points if it does not reduce size
3103 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
3104 Loval_Excl_EP := Loval_Incl_EP;
3105 end if;
3107 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
3108 Hival_Excl_EP := Hival_Incl_EP;
3109 end if;
3111 -- Now we set the actual size to be used. We want to use the
3112 -- bounds fudged up to include the end-points but only if this
3113 -- can be done without violating a specifically given size
3114 -- size clause or causing an unacceptable increase in size.
3116 -- Case of size clause given
3118 if Has_Size_Clause (Typ) then
3120 -- Use the inclusive size only if it is consistent with
3121 -- the explicitly specified size.
3123 if Size_Incl_EP <= RM_Size (Typ) then
3124 Actual_Lo := Loval_Incl_EP;
3125 Actual_Hi := Hival_Incl_EP;
3126 Actual_Size := Size_Incl_EP;
3128 -- If the inclusive size is too large, we try excluding
3129 -- the end-points (will be caught later if does not work).
3131 else
3132 Actual_Lo := Loval_Excl_EP;
3133 Actual_Hi := Hival_Excl_EP;
3134 Actual_Size := Size_Excl_EP;
3135 end if;
3137 -- Case of size clause not given
3139 else
3140 -- If we have a base type whose corresponding first subtype
3141 -- has an explicit size that is large enough to include our
3142 -- end-points, then do so. There is no point in working hard
3143 -- to get a base type whose size is smaller than the specified
3144 -- size of the first subtype.
3146 First_Subt := First_Subtype (Typ);
3148 if Has_Size_Clause (First_Subt)
3149 and then Size_Incl_EP <= Esize (First_Subt)
3150 then
3151 Actual_Size := Size_Incl_EP;
3152 Actual_Lo := Loval_Incl_EP;
3153 Actual_Hi := Hival_Incl_EP;
3155 -- If excluding the end-points makes the size smaller and
3156 -- results in a size of 8,16,32,64, then we take the smaller
3157 -- size. For the 64 case, this is compulsory. For the other
3158 -- cases, it seems reasonable. We like to include end points
3159 -- if we can, but not at the expense of moving to the next
3160 -- natural boundary of size.
3162 elsif Size_Incl_EP /= Size_Excl_EP
3163 and then
3164 (Size_Excl_EP = 8 or else
3165 Size_Excl_EP = 16 or else
3166 Size_Excl_EP = 32 or else
3167 Size_Excl_EP = 64)
3168 then
3169 Actual_Size := Size_Excl_EP;
3170 Actual_Lo := Loval_Excl_EP;
3171 Actual_Hi := Hival_Excl_EP;
3173 -- Otherwise we can definitely include the end points
3175 else
3176 Actual_Size := Size_Incl_EP;
3177 Actual_Lo := Loval_Incl_EP;
3178 Actual_Hi := Hival_Incl_EP;
3179 end if;
3181 -- One pathological case: normally we never fudge a low
3182 -- bound down, since it would seem to increase the size
3183 -- (if it has any effect), but for ranges containing a
3184 -- single value, or no values, the high bound can be
3185 -- small too large. Consider:
3187 -- type t is delta 2.0**(-14)
3188 -- range 131072.0 .. 0;
3190 -- That lower bound is *just* outside the range of 32
3191 -- bits, and does need fudging down in this case. Note
3192 -- that the bounds will always have crossed here, since
3193 -- the high bound will be fudged down if necessary, as
3194 -- in the case of:
3196 -- type t is delta 2.0**(-14)
3197 -- range 131072.0 .. 131072.0;
3199 -- So we can detect the situation by looking for crossed
3200 -- bounds, and if the bounds are crossed, and the low
3201 -- bound is greater than zero, we will always back it
3202 -- off by small, since this is completely harmless.
3204 if Actual_Lo > Actual_Hi then
3205 if UR_Is_Positive (Actual_Lo) then
3206 Actual_Lo := Loval_Incl_EP - Small;
3207 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3209 -- And of course, we need to do exactly the same parallel
3210 -- fudge for flat ranges in the negative region.
3212 elsif UR_Is_Negative (Actual_Hi) then
3213 Actual_Hi := Hival_Incl_EP + Small;
3214 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
3215 end if;
3216 end if;
3217 end if;
3219 Set_Realval (Lo, Actual_Lo);
3220 Set_Realval (Hi, Actual_Hi);
3221 end Fudge;
3223 -- For the decimal case, none of this fudging is required, since there
3224 -- are no end-point problems in the decimal case (the end-points are
3225 -- always included).
3227 else
3228 Actual_Size := Fsize (Loval, Hival);
3229 end if;
3231 -- At this stage, the actual size has been calculated and the proper
3232 -- required bounds are stored in the low and high bounds.
3234 if Actual_Size > 64 then
3235 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
3236 Error_Msg_N
3237 ("size required (^) for type& too large, maximum is 64", Typ);
3238 Actual_Size := 64;
3239 end if;
3241 -- Check size against explicit given size
3243 if Has_Size_Clause (Typ) then
3244 if Actual_Size > RM_Size (Typ) then
3245 Error_Msg_Uint_1 := RM_Size (Typ);
3246 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
3247 Error_Msg_NE
3248 ("size given (^) for type& too small, minimum is ^",
3249 Size_Clause (Typ), Typ);
3251 else
3252 Actual_Size := UI_To_Int (Esize (Typ));
3253 end if;
3255 -- Increase size to next natural boundary if no size clause given
3257 else
3258 if Actual_Size <= 8 then
3259 Actual_Size := 8;
3260 elsif Actual_Size <= 16 then
3261 Actual_Size := 16;
3262 elsif Actual_Size <= 32 then
3263 Actual_Size := 32;
3264 else
3265 Actual_Size := 64;
3266 end if;
3268 Init_Esize (Typ, Actual_Size);
3269 Adjust_Esize_For_Alignment (Typ);
3270 end if;
3272 -- If we have a base type, then expand the bounds so that they
3273 -- extend to the full width of the allocated size in bits, to
3274 -- avoid junk range checks on intermediate computations.
3276 if Base_Type (Typ) = Typ then
3277 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
3278 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
3279 end if;
3281 -- Final step is to reanalyze the bounds using the proper type
3282 -- and set the Corresponding_Integer_Value fields of the literals.
3284 Set_Etype (Lo, Empty);
3285 Set_Analyzed (Lo, False);
3286 Analyze (Lo);
3288 -- Resolve with universal fixed if the base type, and the base
3289 -- type if it is a subtype. Note we can't resolve the base type
3290 -- with itself, that would be a reference before definition.
3292 if Typ = Btyp then
3293 Resolve (Lo, Universal_Fixed);
3294 else
3295 Resolve (Lo, Btyp);
3296 end if;
3298 -- Set corresponding integer value for bound
3300 Set_Corresponding_Integer_Value
3301 (Lo, UR_To_Uint (Realval (Lo) / Small));
3303 -- Similar processing for high bound
3305 Set_Etype (Hi, Empty);
3306 Set_Analyzed (Hi, False);
3307 Analyze (Hi);
3309 if Typ = Btyp then
3310 Resolve (Hi, Universal_Fixed);
3311 else
3312 Resolve (Hi, Btyp);
3313 end if;
3315 Set_Corresponding_Integer_Value
3316 (Hi, UR_To_Uint (Realval (Hi) / Small));
3318 -- Set type of range to correspond to bounds
3320 Set_Etype (Rng, Etype (Lo));
3322 -- Set Esize to calculated size and also set RM_Size
3324 Init_Esize (Typ, Actual_Size);
3326 -- Set RM_Size if not already set. If already set, check value
3328 declare
3329 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
3331 begin
3332 if RM_Size (Typ) /= Uint_0 then
3333 if RM_Size (Typ) < Minsiz then
3334 Error_Msg_Uint_1 := RM_Size (Typ);
3335 Error_Msg_Uint_2 := Minsiz;
3336 Error_Msg_NE
3337 ("size given (^) for type& too small, minimum is ^",
3338 Size_Clause (Typ), Typ);
3339 end if;
3341 else
3342 Set_RM_Size (Typ, Minsiz);
3343 end if;
3344 end;
3346 end Freeze_Fixed_Point_Type;
3348 ------------------
3349 -- Freeze_Itype --
3350 ------------------
3352 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
3353 L : List_Id;
3355 begin
3356 Set_Has_Delayed_Freeze (T);
3357 L := Freeze_Entity (T, Sloc (N));
3359 if Is_Non_Empty_List (L) then
3360 Insert_Actions (N, L);
3361 end if;
3362 end Freeze_Itype;
3364 --------------------------
3365 -- Freeze_Static_Object --
3366 --------------------------
3368 procedure Freeze_Static_Object (E : Entity_Id) is
3370 Cannot_Be_Static : exception;
3371 -- Exception raised if the type of a static object cannot be made
3372 -- static. This happens if the type depends on non-global objects.
3374 procedure Ensure_Expression_Is_SA (N : Node_Id);
3375 -- Called to ensure that an expression used as part of a type
3376 -- definition is statically allocatable, which means that the type
3377 -- of the expression is statically allocatable, and the expression
3378 -- is either static, or a reference to a library level constant.
3380 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
3381 -- Called to mark a type as static, checking that it is possible
3382 -- to set the type as static. If it is not possible, then the
3383 -- exception Cannot_Be_Static is raised.
3385 -----------------------------
3386 -- Ensure_Expression_Is_SA --
3387 -----------------------------
3389 procedure Ensure_Expression_Is_SA (N : Node_Id) is
3390 Ent : Entity_Id;
3392 begin
3393 Ensure_Type_Is_SA (Etype (N));
3395 if Is_Static_Expression (N) then
3396 return;
3398 elsif Nkind (N) = N_Identifier then
3399 Ent := Entity (N);
3401 if Present (Ent)
3402 and then Ekind (Ent) = E_Constant
3403 and then Is_Library_Level_Entity (Ent)
3404 then
3405 return;
3406 end if;
3407 end if;
3409 raise Cannot_Be_Static;
3410 end Ensure_Expression_Is_SA;
3412 -----------------------
3413 -- Ensure_Type_Is_SA --
3414 -----------------------
3416 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
3417 N : Node_Id;
3418 C : Entity_Id;
3420 begin
3421 -- If type is library level, we are all set
3423 if Is_Library_Level_Entity (Typ) then
3424 return;
3425 end if;
3427 -- We are also OK if the type is already marked as statically
3428 -- allocated, which means we processed it before.
3430 if Is_Statically_Allocated (Typ) then
3431 return;
3432 end if;
3434 -- Mark type as statically allocated
3436 Set_Is_Statically_Allocated (Typ);
3438 -- Check that it is safe to statically allocate this type
3440 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
3441 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
3442 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
3444 elsif Is_Array_Type (Typ) then
3445 N := First_Index (Typ);
3446 while Present (N) loop
3447 Ensure_Type_Is_SA (Etype (N));
3448 Next_Index (N);
3449 end loop;
3451 Ensure_Type_Is_SA (Component_Type (Typ));
3453 elsif Is_Access_Type (Typ) then
3454 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
3456 declare
3457 F : Entity_Id;
3458 T : constant Entity_Id := Etype (Designated_Type (Typ));
3460 begin
3461 if T /= Standard_Void_Type then
3462 Ensure_Type_Is_SA (T);
3463 end if;
3465 F := First_Formal (Designated_Type (Typ));
3467 while Present (F) loop
3468 Ensure_Type_Is_SA (Etype (F));
3469 Next_Formal (F);
3470 end loop;
3471 end;
3473 else
3474 Ensure_Type_Is_SA (Designated_Type (Typ));
3475 end if;
3477 elsif Is_Record_Type (Typ) then
3478 C := First_Entity (Typ);
3480 while Present (C) loop
3481 if Ekind (C) = E_Discriminant
3482 or else Ekind (C) = E_Component
3483 then
3484 Ensure_Type_Is_SA (Etype (C));
3486 elsif Is_Type (C) then
3487 Ensure_Type_Is_SA (C);
3488 end if;
3490 Next_Entity (C);
3491 end loop;
3493 elsif Ekind (Typ) = E_Subprogram_Type then
3494 Ensure_Type_Is_SA (Etype (Typ));
3496 C := First_Formal (Typ);
3497 while Present (C) loop
3498 Ensure_Type_Is_SA (Etype (C));
3499 Next_Formal (C);
3500 end loop;
3502 else
3503 raise Cannot_Be_Static;
3504 end if;
3505 end Ensure_Type_Is_SA;
3507 -- Start of processing for Freeze_Static_Object
3509 begin
3510 Ensure_Type_Is_SA (Etype (E));
3512 exception
3513 when Cannot_Be_Static =>
3515 -- If the object that cannot be static is imported or exported,
3516 -- then we give an error message saying that this object cannot
3517 -- be imported or exported.
3519 if Is_Imported (E) then
3520 Error_Msg_N
3521 ("& cannot be imported (local type is not constant)", E);
3523 -- Otherwise must be exported, something is wrong if compiler
3524 -- is marking something as statically allocated which cannot be).
3526 else pragma Assert (Is_Exported (E));
3527 Error_Msg_N
3528 ("& cannot be exported (local type is not constant)", E);
3529 end if;
3530 end Freeze_Static_Object;
3532 -----------------------
3533 -- Freeze_Subprogram --
3534 -----------------------
3536 procedure Freeze_Subprogram (E : Entity_Id) is
3537 Retype : Entity_Id;
3538 F : Entity_Id;
3540 begin
3541 -- Subprogram may not have an address clause unless it is imported
3543 if Present (Address_Clause (E)) then
3544 if not Is_Imported (E) then
3545 Error_Msg_N
3546 ("address clause can only be given " &
3547 "for imported subprogram",
3548 Name (Address_Clause (E)));
3549 end if;
3550 end if;
3552 -- For non-foreign convention subprograms, this is where we create
3553 -- the extra formals (for accessibility level and constrained bit
3554 -- information). We delay this till the freeze point precisely so
3555 -- that we know the convention!
3557 if not Has_Foreign_Convention (E) then
3558 Create_Extra_Formals (E);
3559 Set_Mechanisms (E);
3561 -- If this is convention Ada and a Valued_Procedure, that's odd
3563 if Ekind (E) = E_Procedure
3564 and then Is_Valued_Procedure (E)
3565 and then Convention (E) = Convention_Ada
3566 then
3567 Error_Msg_N
3568 ("?Valued_Procedure has no effect for convention Ada", E);
3569 Set_Is_Valued_Procedure (E, False);
3570 end if;
3572 -- Case of foreign convention
3574 else
3575 Set_Mechanisms (E);
3577 -- For foreign conventions, do not permit return of an
3578 -- unconstrained array.
3580 -- Note: we *do* allow a return by descriptor for the VMS case,
3581 -- though here there is probably more to be done ???
3583 if Ekind (E) = E_Function then
3584 Retype := Underlying_Type (Etype (E));
3586 -- If no return type, probably some other error, e.g. a
3587 -- missing full declaration, so ignore.
3589 if No (Retype) then
3590 null;
3592 -- If the return type is generic, we have emitted a warning
3593 -- earlier on, and there is nothing else to check here.
3594 -- Specific instantiations may lead to erroneous behavior.
3596 elsif Is_Generic_Type (Etype (E)) then
3597 null;
3599 elsif Is_Array_Type (Retype)
3600 and then not Is_Constrained (Retype)
3601 and then Mechanism (E) not in Descriptor_Codes
3602 then
3603 Error_Msg_NE
3604 ("convention for& does not permit returning " &
3605 "unconstrained array type", E, E);
3606 return;
3607 end if;
3608 end if;
3610 -- If any of the formals for an exported foreign convention
3611 -- subprogram have defaults, then emit an appropriate warning
3612 -- since this is odd (default cannot be used from non-Ada code)
3614 if Is_Exported (E) then
3615 F := First_Formal (E);
3616 while Present (F) loop
3617 if Present (Default_Value (F)) then
3618 Error_Msg_N
3619 ("?parameter cannot be defaulted in non-Ada call",
3620 Default_Value (F));
3621 end if;
3623 Next_Formal (F);
3624 end loop;
3625 end if;
3626 end if;
3628 -- For VMS, descriptor mechanisms for parameters are allowed only
3629 -- for imported subprograms.
3631 if OpenVMS_On_Target then
3632 if not Is_Imported (E) then
3633 F := First_Formal (E);
3634 while Present (F) loop
3635 if Mechanism (F) in Descriptor_Codes then
3636 Error_Msg_N
3637 ("descriptor mechanism for parameter not permitted", F);
3638 Error_Msg_N
3639 ("\can only be used for imported subprogram", F);
3640 end if;
3642 Next_Formal (F);
3643 end loop;
3644 end if;
3645 end if;
3647 end Freeze_Subprogram;
3649 -----------------------
3650 -- Is_Fully_Defined --
3651 -----------------------
3653 -- Should this be in Sem_Util ???
3655 function Is_Fully_Defined (T : Entity_Id) return Boolean is
3656 begin
3657 if Ekind (T) = E_Class_Wide_Type then
3658 return Is_Fully_Defined (Etype (T));
3659 else
3660 return not Is_Private_Type (T)
3661 or else Present (Full_View (Base_Type (T)));
3662 end if;
3663 end Is_Fully_Defined;
3665 ---------------------------------
3666 -- Process_Default_Expressions --
3667 ---------------------------------
3669 procedure Process_Default_Expressions
3670 (E : Entity_Id;
3671 After : in out Node_Id)
3673 Loc : constant Source_Ptr := Sloc (E);
3674 Dbody : Node_Id;
3675 Formal : Node_Id;
3676 Dcopy : Node_Id;
3677 Dnam : Entity_Id;
3679 begin
3680 Set_Default_Expressions_Processed (E);
3682 -- A subprogram instance and its associated anonymous subprogram
3683 -- share their signature. The default expression functions are defined
3684 -- in the wrapper packages for the anonymous subprogram, and should
3685 -- not be generated again for the instance.
3687 if Is_Generic_Instance (E)
3688 and then Present (Alias (E))
3689 and then Default_Expressions_Processed (Alias (E))
3690 then
3691 return;
3692 end if;
3694 Formal := First_Formal (E);
3696 while Present (Formal) loop
3697 if Present (Default_Value (Formal)) then
3699 -- We work with a copy of the default expression because we
3700 -- do not want to disturb the original, since this would mess
3701 -- up the conformance checking.
3703 Dcopy := New_Copy_Tree (Default_Value (Formal));
3705 -- The analysis of the expression may generate insert actions,
3706 -- which of course must not be executed. We wrap those actions
3707 -- in a procedure that is not called, and later on eliminated.
3708 -- The following cases have no side-effects, and are analyzed
3709 -- directly.
3711 if Nkind (Dcopy) = N_Identifier
3712 or else Nkind (Dcopy) = N_Expanded_Name
3713 or else Nkind (Dcopy) = N_Integer_Literal
3714 or else (Nkind (Dcopy) = N_Real_Literal
3715 and then not Vax_Float (Etype (Dcopy)))
3716 or else Nkind (Dcopy) = N_Character_Literal
3717 or else Nkind (Dcopy) = N_String_Literal
3718 or else Nkind (Dcopy) = N_Null
3719 or else (Nkind (Dcopy) = N_Attribute_Reference
3720 and then
3721 Attribute_Name (Dcopy) = Name_Null_Parameter)
3723 then
3725 -- If there is no default function, we must still do a full
3726 -- analyze call on the default value, to ensure that all
3727 -- error checks are performed, e.g. those associated with
3728 -- static evaluation. Note that this branch will always be
3729 -- taken if the analyzer is turned off (but we still need the
3730 -- error checks).
3732 -- Note: the setting of parent here is to meet the requirement
3733 -- that we can only analyze the expression while attached to
3734 -- the tree. Really the requirement is that the parent chain
3735 -- be set, we don't actually need to be in the tree.
3737 Set_Parent (Dcopy, Declaration_Node (Formal));
3738 Analyze (Dcopy);
3740 -- Default expressions are resolved with their own type if the
3741 -- context is generic, to avoid anomalies with private types.
3743 if Ekind (Scope (E)) = E_Generic_Package then
3744 Resolve (Dcopy, Etype (Dcopy));
3745 else
3746 Resolve (Dcopy, Etype (Formal));
3747 end if;
3749 -- If that resolved expression will raise constraint error,
3750 -- then flag the default value as raising constraint error.
3751 -- This allows a proper error message on the calls.
3753 if Raises_Constraint_Error (Dcopy) then
3754 Set_Raises_Constraint_Error (Default_Value (Formal));
3755 end if;
3757 -- If the default is a parameterless call, we use the name of
3758 -- the called function directly, and there is no body to build.
3760 elsif Nkind (Dcopy) = N_Function_Call
3761 and then No (Parameter_Associations (Dcopy))
3762 then
3763 null;
3765 -- Else construct and analyze the body of a wrapper procedure
3766 -- that contains an object declaration to hold the expression.
3767 -- Given that this is done only to complete the analysis, it
3768 -- simpler to build a procedure than a function which might
3769 -- involve secondary stack expansion.
3771 else
3772 Dnam :=
3773 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
3775 Dbody :=
3776 Make_Subprogram_Body (Loc,
3777 Specification =>
3778 Make_Procedure_Specification (Loc,
3779 Defining_Unit_Name => Dnam),
3781 Declarations => New_List (
3782 Make_Object_Declaration (Loc,
3783 Defining_Identifier =>
3784 Make_Defining_Identifier (Loc,
3785 New_Internal_Name ('T')),
3786 Object_Definition =>
3787 New_Occurrence_Of (Etype (Formal), Loc),
3788 Expression => New_Copy_Tree (Dcopy))),
3790 Handled_Statement_Sequence =>
3791 Make_Handled_Sequence_Of_Statements (Loc,
3792 Statements => New_List));
3794 Set_Scope (Dnam, Scope (E));
3795 Set_Assignment_OK (First (Declarations (Dbody)));
3796 Set_Is_Eliminated (Dnam);
3797 Insert_After (After, Dbody);
3798 Analyze (Dbody);
3799 After := Dbody;
3800 end if;
3801 end if;
3803 Next_Formal (Formal);
3804 end loop;
3806 end Process_Default_Expressions;
3808 ----------------------------------------
3809 -- Set_Component_Alignment_If_Not_Set --
3810 ----------------------------------------
3812 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
3813 begin
3814 -- Ignore if not base type, subtypes don't need anything
3816 if Typ /= Base_Type (Typ) then
3817 return;
3818 end if;
3820 -- Do not override existing representation
3822 if Is_Packed (Typ) then
3823 return;
3825 elsif Has_Specified_Layout (Typ) then
3826 return;
3828 elsif Component_Alignment (Typ) /= Calign_Default then
3829 return;
3831 else
3832 Set_Component_Alignment
3833 (Typ, Scope_Stack.Table
3834 (Scope_Stack.Last).Component_Alignment_Default);
3835 end if;
3836 end Set_Component_Alignment_If_Not_Set;
3838 ---------------------------
3839 -- Set_Debug_Info_Needed --
3840 ---------------------------
3842 procedure Set_Debug_Info_Needed (T : Entity_Id) is
3843 begin
3844 if No (T)
3845 or else Needs_Debug_Info (T)
3846 or else Debug_Info_Off (T)
3847 then
3848 return;
3849 else
3850 Set_Needs_Debug_Info (T);
3851 end if;
3853 if Is_Object (T) then
3854 Set_Debug_Info_Needed (Etype (T));
3856 elsif Is_Type (T) then
3857 Set_Debug_Info_Needed (Etype (T));
3859 if Is_Record_Type (T) then
3860 declare
3861 Ent : Entity_Id := First_Entity (T);
3862 begin
3863 while Present (Ent) loop
3864 Set_Debug_Info_Needed (Ent);
3865 Next_Entity (Ent);
3866 end loop;
3867 end;
3869 elsif Is_Array_Type (T) then
3870 Set_Debug_Info_Needed (Component_Type (T));
3872 declare
3873 Indx : Node_Id := First_Index (T);
3874 begin
3875 while Present (Indx) loop
3876 Set_Debug_Info_Needed (Etype (Indx));
3877 Indx := Next_Index (Indx);
3878 end loop;
3879 end;
3881 if Is_Packed (T) then
3882 Set_Debug_Info_Needed (Packed_Array_Type (T));
3883 end if;
3885 elsif Is_Access_Type (T) then
3886 Set_Debug_Info_Needed (Directly_Designated_Type (T));
3888 elsif Is_Private_Type (T) then
3889 Set_Debug_Info_Needed (Full_View (T));
3891 elsif Is_Protected_Type (T) then
3892 Set_Debug_Info_Needed (Corresponding_Record_Type (T));
3893 end if;
3894 end if;
3896 end Set_Debug_Info_Needed;
3898 end Freeze;