2013-05-03 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / freeze.adb
blob88a8f6df656045e9d62872080bf1d0b535ef237d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R E E Z E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Ch3; use Exp_Ch3;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Pakd; use Exp_Pakd;
36 with Exp_Util; use Exp_Util;
37 with Exp_Tss; use Exp_Tss;
38 with Layout; use Layout;
39 with Lib; use Lib;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Opt; use Opt;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Cat; use Sem_Cat;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch7; use Sem_Ch7;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Ch9; use Sem_Ch9;
54 with Sem_Ch13; use Sem_Ch13;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Mech; use Sem_Mech;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Util; use Sem_Util;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Ttypes; use Ttypes;
66 with Uintp; use Uintp;
67 with Urealp; use Urealp;
69 package body Freeze is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
76 -- Typ is a type that is being frozen. If no size clause is given,
77 -- but a default Esize has been computed, then this default Esize is
78 -- adjusted up if necessary to be consistent with a given alignment,
79 -- but never to a value greater than Long_Long_Integer'Size. This
80 -- is used for all discrete types and for fixed-point types.
82 procedure Build_And_Analyze_Renamed_Body
83 (Decl : Node_Id;
84 New_S : Entity_Id;
85 After : in out Node_Id);
86 -- Build body for a renaming declaration, insert in tree and analyze
88 procedure Check_Address_Clause (E : Entity_Id);
89 -- Apply legality checks to address clauses for object declarations,
90 -- at the point the object is frozen. Also ensure any initialization is
91 -- performed only after the object has been frozen.
93 procedure Check_Component_Storage_Order
94 (Encl_Type : Entity_Id;
95 Comp : Entity_Id);
96 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
97 -- clause, verify that the component type is compatible. For arrays,
98 -- Comp is Empty; for records, it is the entity of the component under
99 -- consideration.
101 procedure Check_Strict_Alignment (E : Entity_Id);
102 -- E is a base type. If E is tagged or has a component that is aliased
103 -- or tagged or contains something this is aliased or tagged, set
104 -- Strict_Alignment.
106 procedure Check_Unsigned_Type (E : Entity_Id);
107 pragma Inline (Check_Unsigned_Type);
108 -- If E is a fixed-point or discrete type, then all the necessary work
109 -- to freeze it is completed except for possible setting of the flag
110 -- Is_Unsigned_Type, which is done by this procedure. The call has no
111 -- effect if the entity E is not a discrete or fixed-point type.
113 procedure Freeze_And_Append
114 (Ent : Entity_Id;
115 N : Node_Id;
116 Result : in out List_Id);
117 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
118 -- nodes to Result, modifying Result from No_List if necessary. N has
119 -- the same usage as in Freeze_Entity.
121 procedure Freeze_Enumeration_Type (Typ : Entity_Id);
122 -- Freeze enumeration type. The Esize field is set as processing
123 -- proceeds (i.e. set by default when the type is declared and then
124 -- adjusted by rep clauses. What this procedure does is to make sure
125 -- that if a foreign convention is specified, and no specific size
126 -- is given, then the size must be at least Integer'Size.
128 procedure Freeze_Static_Object (E : Entity_Id);
129 -- If an object is frozen which has Is_Statically_Allocated set, then
130 -- all referenced types must also be marked with this flag. This routine
131 -- is in charge of meeting this requirement for the object entity E.
133 procedure Freeze_Subprogram (E : Entity_Id);
134 -- Perform freezing actions for a subprogram (create extra formals,
135 -- and set proper default mechanism values). Note that this routine
136 -- is not called for internal subprograms, for which neither of these
137 -- actions is needed (or desirable, we do not want for example to have
138 -- these extra formals present in initialization procedures, where they
139 -- would serve no purpose). In this call E is either a subprogram or
140 -- a subprogram type (i.e. an access to a subprogram).
142 function Is_Fully_Defined (T : Entity_Id) return Boolean;
143 -- True if T is not private and has no private components, or has a full
144 -- view. Used to determine whether the designated type of an access type
145 -- should be frozen when the access type is frozen. This is done when an
146 -- allocator is frozen, or an expression that may involve attributes of
147 -- the designated type. Otherwise freezing the access type does not freeze
148 -- the designated type.
150 procedure Process_Default_Expressions
151 (E : Entity_Id;
152 After : in out Node_Id);
153 -- This procedure is called for each subprogram to complete processing of
154 -- default expressions at the point where all types are known to be frozen.
155 -- The expressions must be analyzed in full, to make sure that all error
156 -- processing is done (they have only been pre-analyzed). If the expression
157 -- is not an entity or literal, its analysis may generate code which must
158 -- not be executed. In that case we build a function body to hold that
159 -- code. This wrapper function serves no other purpose (it used to be
160 -- called to evaluate the default, but now the default is inlined at each
161 -- point of call).
163 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
164 -- Typ is a record or array type that is being frozen. This routine sets
165 -- the default component alignment from the scope stack values if the
166 -- alignment is otherwise not specified.
168 procedure Check_Debug_Info_Needed (T : Entity_Id);
169 -- As each entity is frozen, this routine is called to deal with the
170 -- setting of Debug_Info_Needed for the entity. This flag is set if
171 -- the entity comes from source, or if we are in Debug_Generated_Code
172 -- mode or if the -gnatdV debug flag is set. However, it never sets
173 -- the flag if Debug_Info_Off is set. This procedure also ensures that
174 -- subsidiary entities have the flag set as required.
176 procedure Undelay_Type (T : Entity_Id);
177 -- T is a type of a component that we know to be an Itype. We don't want
178 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
179 -- Full_View or Corresponding_Record_Type.
181 procedure Warn_Overlay
182 (Expr : Node_Id;
183 Typ : Entity_Id;
184 Nam : Node_Id);
185 -- Expr is the expression for an address clause for entity Nam whose type
186 -- is Typ. If Typ has a default initialization, and there is no explicit
187 -- initialization in the source declaration, check whether the address
188 -- clause might cause overlaying of an entity, and emit a warning on the
189 -- side effect that the initialization will cause.
191 -------------------------------
192 -- Adjust_Esize_For_Alignment --
193 -------------------------------
195 procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
196 Align : Uint;
198 begin
199 if Known_Esize (Typ) and then Known_Alignment (Typ) then
200 Align := Alignment_In_Bits (Typ);
202 if Align > Esize (Typ)
203 and then Align <= Standard_Long_Long_Integer_Size
204 then
205 Set_Esize (Typ, Align);
206 end if;
207 end if;
208 end Adjust_Esize_For_Alignment;
210 ------------------------------------
211 -- Build_And_Analyze_Renamed_Body --
212 ------------------------------------
214 procedure Build_And_Analyze_Renamed_Body
215 (Decl : Node_Id;
216 New_S : Entity_Id;
217 After : in out Node_Id)
219 Body_Decl : constant Node_Id := Unit_Declaration_Node (New_S);
220 Ent : constant Entity_Id := Defining_Entity (Decl);
221 Body_Node : Node_Id;
222 Renamed_Subp : Entity_Id;
224 begin
225 -- If the renamed subprogram is intrinsic, there is no need for a
226 -- wrapper body: we set the alias that will be called and expanded which
227 -- completes the declaration. This transformation is only legal if the
228 -- renamed entity has already been elaborated.
230 -- Note that it is legal for a renaming_as_body to rename an intrinsic
231 -- subprogram, as long as the renaming occurs before the new entity
232 -- is frozen. See RM 8.5.4 (5).
234 if Nkind (Body_Decl) = N_Subprogram_Renaming_Declaration
235 and then Is_Entity_Name (Name (Body_Decl))
236 then
237 Renamed_Subp := Entity (Name (Body_Decl));
238 else
239 Renamed_Subp := Empty;
240 end if;
242 if Present (Renamed_Subp)
243 and then Is_Intrinsic_Subprogram (Renamed_Subp)
244 and then
245 (not In_Same_Source_Unit (Renamed_Subp, Ent)
246 or else Sloc (Renamed_Subp) < Sloc (Ent))
248 -- We can make the renaming entity intrinsic if the renamed function
249 -- has an interface name, or if it is one of the shift/rotate
250 -- operations known to the compiler.
252 and then
253 (Present (Interface_Name (Renamed_Subp))
254 or else Nam_In (Chars (Renamed_Subp), Name_Rotate_Left,
255 Name_Rotate_Right,
256 Name_Shift_Left,
257 Name_Shift_Right,
258 Name_Shift_Right_Arithmetic))
259 then
260 Set_Interface_Name (Ent, Interface_Name (Renamed_Subp));
262 if Present (Alias (Renamed_Subp)) then
263 Set_Alias (Ent, Alias (Renamed_Subp));
264 else
265 Set_Alias (Ent, Renamed_Subp);
266 end if;
268 Set_Is_Intrinsic_Subprogram (Ent);
269 Set_Has_Completion (Ent);
271 else
272 Body_Node := Build_Renamed_Body (Decl, New_S);
273 Insert_After (After, Body_Node);
274 Mark_Rewrite_Insertion (Body_Node);
275 Analyze (Body_Node);
276 After := Body_Node;
277 end if;
278 end Build_And_Analyze_Renamed_Body;
280 ------------------------
281 -- Build_Renamed_Body --
282 ------------------------
284 function Build_Renamed_Body
285 (Decl : Node_Id;
286 New_S : Entity_Id) return Node_Id
288 Loc : constant Source_Ptr := Sloc (New_S);
289 -- We use for the source location of the renamed body, the location of
290 -- the spec entity. It might seem more natural to use the location of
291 -- the renaming declaration itself, but that would be wrong, since then
292 -- the body we create would look as though it was created far too late,
293 -- and this could cause problems with elaboration order analysis,
294 -- particularly in connection with instantiations.
296 N : constant Node_Id := Unit_Declaration_Node (New_S);
297 Nam : constant Node_Id := Name (N);
298 Old_S : Entity_Id;
299 Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
300 Actuals : List_Id := No_List;
301 Call_Node : Node_Id;
302 Call_Name : Node_Id;
303 Body_Node : Node_Id;
304 Formal : Entity_Id;
305 O_Formal : Entity_Id;
306 Param_Spec : Node_Id;
308 Pref : Node_Id := Empty;
309 -- If the renamed entity is a primitive operation given in prefix form,
310 -- the prefix is the target object and it has to be added as the first
311 -- actual in the generated call.
313 begin
314 -- Determine the entity being renamed, which is the target of the call
315 -- statement. If the name is an explicit dereference, this is a renaming
316 -- of a subprogram type rather than a subprogram. The name itself is
317 -- fully analyzed.
319 if Nkind (Nam) = N_Selected_Component then
320 Old_S := Entity (Selector_Name (Nam));
322 elsif Nkind (Nam) = N_Explicit_Dereference then
323 Old_S := Etype (Nam);
325 elsif Nkind (Nam) = N_Indexed_Component then
326 if Is_Entity_Name (Prefix (Nam)) then
327 Old_S := Entity (Prefix (Nam));
328 else
329 Old_S := Entity (Selector_Name (Prefix (Nam)));
330 end if;
332 elsif Nkind (Nam) = N_Character_Literal then
333 Old_S := Etype (New_S);
335 else
336 Old_S := Entity (Nam);
337 end if;
339 if Is_Entity_Name (Nam) then
341 -- If the renamed entity is a predefined operator, retain full name
342 -- to ensure its visibility.
344 if Ekind (Old_S) = E_Operator
345 and then Nkind (Nam) = N_Expanded_Name
346 then
347 Call_Name := New_Copy (Name (N));
348 else
349 Call_Name := New_Reference_To (Old_S, Loc);
350 end if;
352 else
353 if Nkind (Nam) = N_Selected_Component
354 and then Present (First_Formal (Old_S))
355 and then
356 (Is_Controlling_Formal (First_Formal (Old_S))
357 or else Is_Class_Wide_Type (Etype (First_Formal (Old_S))))
358 then
360 -- Retrieve the target object, to be added as a first actual
361 -- in the call.
363 Call_Name := New_Occurrence_Of (Old_S, Loc);
364 Pref := Prefix (Nam);
366 else
367 Call_Name := New_Copy (Name (N));
368 end if;
370 -- Original name may have been overloaded, but is fully resolved now
372 Set_Is_Overloaded (Call_Name, False);
373 end if;
375 -- For simple renamings, subsequent calls can be expanded directly as
376 -- calls to the renamed entity. The body must be generated in any case
377 -- for calls that may appear elsewhere. This is not done in the case
378 -- where the subprogram is an instantiation because the actual proper
379 -- body has not been built yet.
381 if Ekind_In (Old_S, E_Function, E_Procedure)
382 and then Nkind (Decl) = N_Subprogram_Declaration
383 and then not Is_Generic_Instance (Old_S)
384 then
385 Set_Body_To_Inline (Decl, Old_S);
386 end if;
388 -- The body generated for this renaming is an internal artifact, and
389 -- does not constitute a freeze point for the called entity.
391 Set_Must_Not_Freeze (Call_Name);
393 Formal := First_Formal (Defining_Entity (Decl));
395 if Present (Pref) then
396 declare
397 Pref_Type : constant Entity_Id := Etype (Pref);
398 Form_Type : constant Entity_Id := Etype (First_Formal (Old_S));
400 begin
401 -- The controlling formal may be an access parameter, or the
402 -- actual may be an access value, so adjust accordingly.
404 if Is_Access_Type (Pref_Type)
405 and then not Is_Access_Type (Form_Type)
406 then
407 Actuals := New_List
408 (Make_Explicit_Dereference (Loc, Relocate_Node (Pref)));
410 elsif Is_Access_Type (Form_Type)
411 and then not Is_Access_Type (Pref)
412 then
413 Actuals := New_List
414 (Make_Attribute_Reference (Loc,
415 Attribute_Name => Name_Access,
416 Prefix => Relocate_Node (Pref)));
417 else
418 Actuals := New_List (Pref);
419 end if;
420 end;
422 elsif Present (Formal) then
423 Actuals := New_List;
425 else
426 Actuals := No_List;
427 end if;
429 if Present (Formal) then
430 while Present (Formal) loop
431 Append (New_Reference_To (Formal, Loc), Actuals);
432 Next_Formal (Formal);
433 end loop;
434 end if;
436 -- If the renamed entity is an entry, inherit its profile. For other
437 -- renamings as bodies, both profiles must be subtype conformant, so it
438 -- is not necessary to replace the profile given in the declaration.
439 -- However, default values that are aggregates are rewritten when
440 -- partially analyzed, so we recover the original aggregate to insure
441 -- that subsequent conformity checking works. Similarly, if the default
442 -- expression was constant-folded, recover the original expression.
444 Formal := First_Formal (Defining_Entity (Decl));
446 if Present (Formal) then
447 O_Formal := First_Formal (Old_S);
448 Param_Spec := First (Parameter_Specifications (Spec));
449 while Present (Formal) loop
450 if Is_Entry (Old_S) then
451 if Nkind (Parameter_Type (Param_Spec)) /=
452 N_Access_Definition
453 then
454 Set_Etype (Formal, Etype (O_Formal));
455 Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
456 end if;
458 elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
459 or else Nkind (Original_Node (Default_Value (O_Formal))) /=
460 Nkind (Default_Value (O_Formal))
461 then
462 Set_Expression (Param_Spec,
463 New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
464 end if;
466 Next_Formal (Formal);
467 Next_Formal (O_Formal);
468 Next (Param_Spec);
469 end loop;
470 end if;
472 -- If the renamed entity is a function, the generated body contains a
473 -- return statement. Otherwise, build a procedure call. If the entity is
474 -- an entry, subsequent analysis of the call will transform it into the
475 -- proper entry or protected operation call. If the renamed entity is
476 -- a character literal, return it directly.
478 if Ekind (Old_S) = E_Function
479 or else Ekind (Old_S) = E_Operator
480 or else (Ekind (Old_S) = E_Subprogram_Type
481 and then Etype (Old_S) /= Standard_Void_Type)
482 then
483 Call_Node :=
484 Make_Simple_Return_Statement (Loc,
485 Expression =>
486 Make_Function_Call (Loc,
487 Name => Call_Name,
488 Parameter_Associations => Actuals));
490 elsif Ekind (Old_S) = E_Enumeration_Literal then
491 Call_Node :=
492 Make_Simple_Return_Statement (Loc,
493 Expression => New_Occurrence_Of (Old_S, Loc));
495 elsif Nkind (Nam) = N_Character_Literal then
496 Call_Node :=
497 Make_Simple_Return_Statement (Loc,
498 Expression => Call_Name);
500 else
501 Call_Node :=
502 Make_Procedure_Call_Statement (Loc,
503 Name => Call_Name,
504 Parameter_Associations => Actuals);
505 end if;
507 -- Create entities for subprogram body and formals
509 Set_Defining_Unit_Name (Spec,
510 Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
512 Param_Spec := First (Parameter_Specifications (Spec));
513 while Present (Param_Spec) loop
514 Set_Defining_Identifier (Param_Spec,
515 Make_Defining_Identifier (Loc,
516 Chars => Chars (Defining_Identifier (Param_Spec))));
517 Next (Param_Spec);
518 end loop;
520 Body_Node :=
521 Make_Subprogram_Body (Loc,
522 Specification => Spec,
523 Declarations => New_List,
524 Handled_Statement_Sequence =>
525 Make_Handled_Sequence_Of_Statements (Loc,
526 Statements => New_List (Call_Node)));
528 if Nkind (Decl) /= N_Subprogram_Declaration then
529 Rewrite (N,
530 Make_Subprogram_Declaration (Loc,
531 Specification => Specification (N)));
532 end if;
534 -- Link the body to the entity whose declaration it completes. If
535 -- the body is analyzed when the renamed entity is frozen, it may
536 -- be necessary to restore the proper scope (see package Exp_Ch13).
538 if Nkind (N) = N_Subprogram_Renaming_Declaration
539 and then Present (Corresponding_Spec (N))
540 then
541 Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
542 else
543 Set_Corresponding_Spec (Body_Node, New_S);
544 end if;
546 return Body_Node;
547 end Build_Renamed_Body;
549 --------------------------
550 -- Check_Address_Clause --
551 --------------------------
553 procedure Check_Address_Clause (E : Entity_Id) is
554 Addr : constant Node_Id := Address_Clause (E);
555 Expr : Node_Id;
556 Decl : constant Node_Id := Declaration_Node (E);
557 Loc : constant Source_Ptr := Sloc (Decl);
558 Typ : constant Entity_Id := Etype (E);
560 begin
561 if Present (Addr) then
562 Expr := Expression (Addr);
564 if Needs_Constant_Address (Decl, Typ) then
565 Check_Constant_Address_Clause (Expr, E);
567 -- Has_Delayed_Freeze was set on E when the address clause was
568 -- analyzed, and must remain set because we want the address
569 -- clause to be elaborated only after any entity it references
570 -- has been elaborated.
571 end if;
573 -- If Rep_Clauses are to be ignored, remove address clause from
574 -- list attached to entity, because it may be illegal for gigi,
575 -- for example by breaking order of elaboration..
577 if Ignore_Rep_Clauses then
578 declare
579 Rep : Node_Id;
581 begin
582 Rep := First_Rep_Item (E);
584 if Rep = Addr then
585 Set_First_Rep_Item (E, Next_Rep_Item (Addr));
587 else
588 while Present (Rep)
589 and then Next_Rep_Item (Rep) /= Addr
590 loop
591 Rep := Next_Rep_Item (Rep);
592 end loop;
593 end if;
595 if Present (Rep) then
596 Set_Next_Rep_Item (Rep, Next_Rep_Item (Addr));
597 end if;
598 end;
600 Rewrite (Addr, Make_Null_Statement (Sloc (E)));
602 elsif not Error_Posted (Expr)
603 and then not Needs_Finalization (Typ)
604 then
605 Warn_Overlay (Expr, Typ, Name (Addr));
606 end if;
608 if Present (Expression (Decl)) then
610 -- Capture initialization value at point of declaration
612 Remove_Side_Effects (Expression (Decl));
614 -- Move initialization to freeze actions (once the object has
615 -- been frozen, and the address clause alignment check has been
616 -- performed.
618 Append_Freeze_Action (E,
619 Make_Assignment_Statement (Loc,
620 Name => New_Occurrence_Of (E, Loc),
621 Expression => Expression (Decl)));
623 Set_No_Initialization (Decl);
624 end if;
625 end if;
626 end Check_Address_Clause;
628 -----------------------------
629 -- Check_Compile_Time_Size --
630 -----------------------------
632 procedure Check_Compile_Time_Size (T : Entity_Id) is
634 procedure Set_Small_Size (T : Entity_Id; S : Uint);
635 -- Sets the compile time known size (32 bits or less) in the Esize
636 -- field, of T checking for a size clause that was given which attempts
637 -- to give a smaller size, and also checking for an alignment clause.
639 function Size_Known (T : Entity_Id) return Boolean;
640 -- Recursive function that does all the work
642 function Static_Discriminated_Components (T : Entity_Id) return Boolean;
643 -- If T is a constrained subtype, its size is not known if any of its
644 -- discriminant constraints is not static and it is not a null record.
645 -- The test is conservative and doesn't check that the components are
646 -- in fact constrained by non-static discriminant values. Could be made
647 -- more precise ???
649 --------------------
650 -- Set_Small_Size --
651 --------------------
653 procedure Set_Small_Size (T : Entity_Id; S : Uint) is
654 begin
655 if S > 32 then
656 return;
658 -- Check for bad size clause given
660 elsif Has_Size_Clause (T) then
661 if RM_Size (T) < S then
662 Error_Msg_Uint_1 := S;
663 Error_Msg_NE
664 ("size for& too small, minimum allowed is ^",
665 Size_Clause (T), T);
666 end if;
668 -- Set size if not set already
670 elsif Unknown_RM_Size (T) then
671 Set_RM_Size (T, S);
672 end if;
673 end Set_Small_Size;
675 ----------------
676 -- Size_Known --
677 ----------------
679 function Size_Known (T : Entity_Id) return Boolean is
680 Index : Entity_Id;
681 Comp : Entity_Id;
682 Ctyp : Entity_Id;
683 Low : Node_Id;
684 High : Node_Id;
686 begin
687 if Size_Known_At_Compile_Time (T) then
688 return True;
690 -- Always True for scalar types. This is true even for generic formal
691 -- scalar types. We used to return False in the latter case, but the
692 -- size is known at compile time, even in the template, we just do
693 -- not know the exact size but that's not the point of this routine.
695 elsif Is_Scalar_Type (T)
696 or else Is_Task_Type (T)
697 then
698 return True;
700 -- Array types
702 elsif Is_Array_Type (T) then
704 -- String literals always have known size, and we can set it
706 if Ekind (T) = E_String_Literal_Subtype then
707 Set_Small_Size (T, Component_Size (T)
708 * String_Literal_Length (T));
709 return True;
711 -- Unconstrained types never have known at compile time size
713 elsif not Is_Constrained (T) then
714 return False;
716 -- Don't do any recursion on type with error posted, since we may
717 -- have a malformed type that leads us into a loop.
719 elsif Error_Posted (T) then
720 return False;
722 -- Otherwise if component size unknown, then array size unknown
724 elsif not Size_Known (Component_Type (T)) then
725 return False;
726 end if;
728 -- Check for all indexes static, and also compute possible size
729 -- (in case it is less than 32 and may be packable).
731 declare
732 Esiz : Uint := Component_Size (T);
733 Dim : Uint;
735 begin
736 Index := First_Index (T);
737 while Present (Index) loop
738 if Nkind (Index) = N_Range then
739 Get_Index_Bounds (Index, Low, High);
741 elsif Error_Posted (Scalar_Range (Etype (Index))) then
742 return False;
744 else
745 Low := Type_Low_Bound (Etype (Index));
746 High := Type_High_Bound (Etype (Index));
747 end if;
749 if not Compile_Time_Known_Value (Low)
750 or else not Compile_Time_Known_Value (High)
751 or else Etype (Index) = Any_Type
752 then
753 return False;
755 else
756 Dim := Expr_Value (High) - Expr_Value (Low) + 1;
758 if Dim >= 0 then
759 Esiz := Esiz * Dim;
760 else
761 Esiz := Uint_0;
762 end if;
763 end if;
765 Next_Index (Index);
766 end loop;
768 Set_Small_Size (T, Esiz);
769 return True;
770 end;
772 -- Access types always have known at compile time sizes
774 elsif Is_Access_Type (T) then
775 return True;
777 -- For non-generic private types, go to underlying type if present
779 elsif Is_Private_Type (T)
780 and then not Is_Generic_Type (T)
781 and then Present (Underlying_Type (T))
782 then
783 -- Don't do any recursion on type with error posted, since we may
784 -- have a malformed type that leads us into a loop.
786 if Error_Posted (T) then
787 return False;
788 else
789 return Size_Known (Underlying_Type (T));
790 end if;
792 -- Record types
794 elsif Is_Record_Type (T) then
796 -- A class-wide type is never considered to have a known size
798 if Is_Class_Wide_Type (T) then
799 return False;
801 -- A subtype of a variant record must not have non-static
802 -- discriminated components.
804 elsif T /= Base_Type (T)
805 and then not Static_Discriminated_Components (T)
806 then
807 return False;
809 -- Don't do any recursion on type with error posted, since we may
810 -- have a malformed type that leads us into a loop.
812 elsif Error_Posted (T) then
813 return False;
814 end if;
816 -- Now look at the components of the record
818 declare
819 -- The following two variables are used to keep track of the
820 -- size of packed records if we can tell the size of the packed
821 -- record in the front end. Packed_Size_Known is True if so far
822 -- we can figure out the size. It is initialized to True for a
823 -- packed record, unless the record has discriminants or atomic
824 -- components or independent components.
826 -- The reason we eliminate the discriminated case is that
827 -- we don't know the way the back end lays out discriminated
828 -- packed records. If Packed_Size_Known is True, then
829 -- Packed_Size is the size in bits so far.
831 Packed_Size_Known : Boolean :=
832 Is_Packed (T)
833 and then not Has_Discriminants (T)
834 and then not Has_Atomic_Components (T)
835 and then not Has_Independent_Components (T);
837 Packed_Size : Uint := Uint_0;
838 -- SIze in bis so far
840 begin
841 -- Test for variant part present
843 if Has_Discriminants (T)
844 and then Present (Parent (T))
845 and then Nkind (Parent (T)) = N_Full_Type_Declaration
846 and then Nkind (Type_Definition (Parent (T))) =
847 N_Record_Definition
848 and then not Null_Present (Type_Definition (Parent (T)))
849 and then Present (Variant_Part
850 (Component_List (Type_Definition (Parent (T)))))
851 then
852 -- If variant part is present, and type is unconstrained,
853 -- then we must have defaulted discriminants, or a size
854 -- clause must be present for the type, or else the size
855 -- is definitely not known at compile time.
857 if not Is_Constrained (T)
858 and then
859 No (Discriminant_Default_Value (First_Discriminant (T)))
860 and then Unknown_RM_Size (T)
861 then
862 return False;
863 end if;
864 end if;
866 -- Loop through components
868 Comp := First_Component_Or_Discriminant (T);
869 while Present (Comp) loop
870 Ctyp := Etype (Comp);
872 -- We do not know the packed size if there is a component
873 -- clause present (we possibly could, but this would only
874 -- help in the case of a record with partial rep clauses.
875 -- That's because in the case of full rep clauses, the
876 -- size gets figured out anyway by a different circuit).
878 if Present (Component_Clause (Comp)) then
879 Packed_Size_Known := False;
880 end if;
882 -- We do not know the packed size if we have a by reference
883 -- type, or an atomic type or an atomic component.
885 if Is_Atomic (Ctyp)
886 or else Is_Atomic (Comp)
887 or else Is_By_Reference_Type (Ctyp)
888 then
889 Packed_Size_Known := False;
890 end if;
892 -- We need to identify a component that is an array where
893 -- the index type is an enumeration type with non-standard
894 -- representation, and some bound of the type depends on a
895 -- discriminant.
897 -- This is because gigi computes the size by doing a
898 -- substitution of the appropriate discriminant value in
899 -- the size expression for the base type, and gigi is not
900 -- clever enough to evaluate the resulting expression (which
901 -- involves a call to rep_to_pos) at compile time.
903 -- It would be nice if gigi would either recognize that
904 -- this expression can be computed at compile time, or
905 -- alternatively figured out the size from the subtype
906 -- directly, where all the information is at hand ???
908 if Is_Array_Type (Etype (Comp))
909 and then Present (Packed_Array_Type (Etype (Comp)))
910 then
911 declare
912 Ocomp : constant Entity_Id :=
913 Original_Record_Component (Comp);
914 OCtyp : constant Entity_Id := Etype (Ocomp);
915 Ind : Node_Id;
916 Indtyp : Entity_Id;
917 Lo, Hi : Node_Id;
919 begin
920 Ind := First_Index (OCtyp);
921 while Present (Ind) loop
922 Indtyp := Etype (Ind);
924 if Is_Enumeration_Type (Indtyp)
925 and then Has_Non_Standard_Rep (Indtyp)
926 then
927 Lo := Type_Low_Bound (Indtyp);
928 Hi := Type_High_Bound (Indtyp);
930 if Is_Entity_Name (Lo)
931 and then Ekind (Entity (Lo)) = E_Discriminant
932 then
933 return False;
935 elsif Is_Entity_Name (Hi)
936 and then Ekind (Entity (Hi)) = E_Discriminant
937 then
938 return False;
939 end if;
940 end if;
942 Next_Index (Ind);
943 end loop;
944 end;
945 end if;
947 -- Clearly size of record is not known if the size of one of
948 -- the components is not known.
950 if not Size_Known (Ctyp) then
951 return False;
952 end if;
954 -- Accumulate packed size if possible
956 if Packed_Size_Known then
958 -- We can only deal with elementary types, since for
959 -- non-elementary components, alignment enters into the
960 -- picture, and we don't know enough to handle proper
961 -- alignment in this context. Packed arrays count as
962 -- elementary if the representation is a modular type.
964 if Is_Elementary_Type (Ctyp)
965 or else (Is_Array_Type (Ctyp)
966 and then Present (Packed_Array_Type (Ctyp))
967 and then Is_Modular_Integer_Type
968 (Packed_Array_Type (Ctyp)))
969 then
970 -- Packed size unknown if we have an atomic type
971 -- or a by reference type, since the back end
972 -- knows how these are layed out.
974 if Is_Atomic (Ctyp)
975 or else Is_By_Reference_Type (Ctyp)
976 then
977 Packed_Size_Known := False;
979 -- If RM_Size is known and static, then we can keep
980 -- accumulating the packed size
982 elsif Known_Static_RM_Size (Ctyp) then
984 -- A little glitch, to be removed sometime ???
985 -- gigi does not understand zero sizes yet.
987 if RM_Size (Ctyp) = Uint_0 then
988 Packed_Size_Known := False;
990 -- Normal case where we can keep accumulating the
991 -- packed array size.
993 else
994 Packed_Size := Packed_Size + RM_Size (Ctyp);
995 end if;
997 -- If we have a field whose RM_Size is not known then
998 -- we can't figure out the packed size here.
1000 else
1001 Packed_Size_Known := False;
1002 end if;
1004 -- If we have a non-elementary type we can't figure out
1005 -- the packed array size (alignment issues).
1007 else
1008 Packed_Size_Known := False;
1009 end if;
1010 end if;
1012 Next_Component_Or_Discriminant (Comp);
1013 end loop;
1015 if Packed_Size_Known then
1016 Set_Small_Size (T, Packed_Size);
1017 end if;
1019 return True;
1020 end;
1022 -- All other cases, size not known at compile time
1024 else
1025 return False;
1026 end if;
1027 end Size_Known;
1029 -------------------------------------
1030 -- Static_Discriminated_Components --
1031 -------------------------------------
1033 function Static_Discriminated_Components
1034 (T : Entity_Id) return Boolean
1036 Constraint : Elmt_Id;
1038 begin
1039 if Has_Discriminants (T)
1040 and then Present (Discriminant_Constraint (T))
1041 and then Present (First_Component (T))
1042 then
1043 Constraint := First_Elmt (Discriminant_Constraint (T));
1044 while Present (Constraint) loop
1045 if not Compile_Time_Known_Value (Node (Constraint)) then
1046 return False;
1047 end if;
1049 Next_Elmt (Constraint);
1050 end loop;
1051 end if;
1053 return True;
1054 end Static_Discriminated_Components;
1056 -- Start of processing for Check_Compile_Time_Size
1058 begin
1059 Set_Size_Known_At_Compile_Time (T, Size_Known (T));
1060 end Check_Compile_Time_Size;
1062 -----------------------------------
1063 -- Check_Component_Storage_Order --
1064 -----------------------------------
1066 procedure Check_Component_Storage_Order
1067 (Encl_Type : Entity_Id;
1068 Comp : Entity_Id)
1070 Comp_Type : Entity_Id;
1071 Comp_Def : Node_Id;
1072 Err_Node : Node_Id;
1073 ADC : Node_Id;
1075 Comp_Byte_Aligned : Boolean;
1076 -- Set True for the record case, when Comp starts on a byte boundary
1077 -- (in which case it is allowed to have different storage order).
1079 begin
1080 -- Record case
1082 if Present (Comp) then
1083 Err_Node := Comp;
1084 Comp_Type := Etype (Comp);
1086 if Is_Tag (Comp) then
1087 Comp_Def := Empty;
1088 Comp_Byte_Aligned := True;
1090 else
1091 Comp_Def := Component_Definition (Parent (Comp));
1092 Comp_Byte_Aligned :=
1093 Present (Component_Clause (Comp))
1094 and then
1095 Normalized_First_Bit (Comp) mod System_Storage_Unit = 0;
1096 end if;
1098 -- Array case
1100 else
1101 Err_Node := Encl_Type;
1102 Comp_Type := Component_Type (Encl_Type);
1103 Comp_Def := Component_Definition
1104 (Type_Definition (Declaration_Node (Encl_Type)));
1106 Comp_Byte_Aligned := False;
1107 end if;
1109 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1110 -- the attribute definition clause is attached to the first subtype.
1112 Comp_Type := Base_Type (Comp_Type);
1113 ADC := Get_Attribute_Definition_Clause
1114 (First_Subtype (Comp_Type),
1115 Attribute_Scalar_Storage_Order);
1117 if Is_Record_Type (Comp_Type) or else Is_Array_Type (Comp_Type) then
1118 if Present (Comp) and then Chars (Comp) = Name_uParent then
1119 if Reverse_Storage_Order (Encl_Type)
1121 Reverse_Storage_Order (Comp_Type)
1122 then
1123 Error_Msg_N
1124 ("record extension must have same scalar storage order as "
1125 & "parent", Err_Node);
1126 end if;
1128 elsif No (ADC) then
1129 Error_Msg_N ("nested composite must have explicit scalar "
1130 & "storage order", Err_Node);
1132 elsif (Reverse_Storage_Order (Encl_Type)
1134 Reverse_Storage_Order (Comp_Type))
1135 and then not Comp_Byte_Aligned
1136 then
1137 Error_Msg_N
1138 ("type of non-byte-aligned component must have same scalar "
1139 & "storage order as enclosing composite", Err_Node);
1140 end if;
1142 elsif Present (Comp_Def) and then Aliased_Present (Comp_Def) then
1143 Error_Msg_N
1144 ("aliased component not permitted for type with "
1145 & "explicit Scalar_Storage_Order", Err_Node);
1146 end if;
1147 end Check_Component_Storage_Order;
1149 -----------------------------
1150 -- Check_Debug_Info_Needed --
1151 -----------------------------
1153 procedure Check_Debug_Info_Needed (T : Entity_Id) is
1154 begin
1155 if Debug_Info_Off (T) then
1156 return;
1158 elsif Comes_From_Source (T)
1159 or else Debug_Generated_Code
1160 or else Debug_Flag_VV
1161 or else Needs_Debug_Info (T)
1162 then
1163 Set_Debug_Info_Needed (T);
1164 end if;
1165 end Check_Debug_Info_Needed;
1167 ----------------------------
1168 -- Check_Strict_Alignment --
1169 ----------------------------
1171 procedure Check_Strict_Alignment (E : Entity_Id) is
1172 Comp : Entity_Id;
1174 begin
1175 if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
1176 Set_Strict_Alignment (E);
1178 elsif Is_Array_Type (E) then
1179 Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
1181 elsif Is_Record_Type (E) then
1182 if Is_Limited_Record (E) then
1183 Set_Strict_Alignment (E);
1184 return;
1185 end if;
1187 Comp := First_Component (E);
1188 while Present (Comp) loop
1189 if not Is_Type (Comp)
1190 and then (Strict_Alignment (Etype (Comp))
1191 or else Is_Aliased (Comp))
1192 then
1193 Set_Strict_Alignment (E);
1194 return;
1195 end if;
1197 Next_Component (Comp);
1198 end loop;
1199 end if;
1200 end Check_Strict_Alignment;
1202 -------------------------
1203 -- Check_Unsigned_Type --
1204 -------------------------
1206 procedure Check_Unsigned_Type (E : Entity_Id) is
1207 Ancestor : Entity_Id;
1208 Lo_Bound : Node_Id;
1209 Btyp : Entity_Id;
1211 begin
1212 if not Is_Discrete_Or_Fixed_Point_Type (E) then
1213 return;
1214 end if;
1216 -- Do not attempt to analyze case where range was in error
1218 if No (Scalar_Range (E))
1219 or else Error_Posted (Scalar_Range (E))
1220 then
1221 return;
1222 end if;
1224 -- The situation that is non trivial is something like
1226 -- subtype x1 is integer range -10 .. +10;
1227 -- subtype x2 is x1 range 0 .. V1;
1228 -- subtype x3 is x2 range V2 .. V3;
1229 -- subtype x4 is x3 range V4 .. V5;
1231 -- where Vn are variables. Here the base type is signed, but we still
1232 -- know that x4 is unsigned because of the lower bound of x2.
1234 -- The only way to deal with this is to look up the ancestor chain
1236 Ancestor := E;
1237 loop
1238 if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
1239 return;
1240 end if;
1242 Lo_Bound := Type_Low_Bound (Ancestor);
1244 if Compile_Time_Known_Value (Lo_Bound) then
1246 if Expr_Rep_Value (Lo_Bound) >= 0 then
1247 Set_Is_Unsigned_Type (E, True);
1248 end if;
1250 return;
1252 else
1253 Ancestor := Ancestor_Subtype (Ancestor);
1255 -- If no ancestor had a static lower bound, go to base type
1257 if No (Ancestor) then
1259 -- Note: the reason we still check for a compile time known
1260 -- value for the base type is that at least in the case of
1261 -- generic formals, we can have bounds that fail this test,
1262 -- and there may be other cases in error situations.
1264 Btyp := Base_Type (E);
1266 if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
1267 return;
1268 end if;
1270 Lo_Bound := Type_Low_Bound (Base_Type (E));
1272 if Compile_Time_Known_Value (Lo_Bound)
1273 and then Expr_Rep_Value (Lo_Bound) >= 0
1274 then
1275 Set_Is_Unsigned_Type (E, True);
1276 end if;
1278 return;
1279 end if;
1280 end if;
1281 end loop;
1282 end Check_Unsigned_Type;
1284 -------------------------
1285 -- Is_Atomic_Aggregate --
1286 -------------------------
1288 function Is_Atomic_Aggregate
1289 (E : Entity_Id;
1290 Typ : Entity_Id) return Boolean
1292 Loc : constant Source_Ptr := Sloc (E);
1293 New_N : Node_Id;
1294 Par : Node_Id;
1295 Temp : Entity_Id;
1297 begin
1298 Par := Parent (E);
1300 -- Array may be qualified, so find outer context
1302 if Nkind (Par) = N_Qualified_Expression then
1303 Par := Parent (Par);
1304 end if;
1306 if Nkind_In (Par, N_Object_Declaration, N_Assignment_Statement)
1307 and then Comes_From_Source (Par)
1308 then
1309 Temp := Make_Temporary (Loc, 'T', E);
1310 New_N :=
1311 Make_Object_Declaration (Loc,
1312 Defining_Identifier => Temp,
1313 Object_Definition => New_Occurrence_Of (Typ, Loc),
1314 Expression => Relocate_Node (E));
1315 Insert_Before (Par, New_N);
1316 Analyze (New_N);
1318 Set_Expression (Par, New_Occurrence_Of (Temp, Loc));
1319 return True;
1321 else
1322 return False;
1323 end if;
1324 end Is_Atomic_Aggregate;
1326 ----------------
1327 -- Freeze_All --
1328 ----------------
1330 -- Note: the easy coding for this procedure would be to just build a
1331 -- single list of freeze nodes and then insert them and analyze them
1332 -- all at once. This won't work, because the analysis of earlier freeze
1333 -- nodes may recursively freeze types which would otherwise appear later
1334 -- on in the freeze list. So we must analyze and expand the freeze nodes
1335 -- as they are generated.
1337 procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
1338 E : Entity_Id;
1339 Decl : Node_Id;
1341 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
1342 -- This is the internal recursive routine that does freezing of entities
1343 -- (but NOT the analysis of default expressions, which should not be
1344 -- recursive, we don't want to analyze those till we are sure that ALL
1345 -- the types are frozen).
1347 --------------------
1348 -- Freeze_All_Ent --
1349 --------------------
1351 procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id) is
1352 E : Entity_Id;
1353 Flist : List_Id;
1354 Lastn : Node_Id;
1356 procedure Process_Flist;
1357 -- If freeze nodes are present, insert and analyze, and reset cursor
1358 -- for next insertion.
1360 -------------------
1361 -- Process_Flist --
1362 -------------------
1364 procedure Process_Flist is
1365 begin
1366 if Is_Non_Empty_List (Flist) then
1367 Lastn := Next (After);
1368 Insert_List_After_And_Analyze (After, Flist);
1370 if Present (Lastn) then
1371 After := Prev (Lastn);
1372 else
1373 After := Last (List_Containing (After));
1374 end if;
1375 end if;
1376 end Process_Flist;
1378 -- Start or processing for Freeze_All_Ent
1380 begin
1381 E := From;
1382 while Present (E) loop
1384 -- If the entity is an inner package which is not a package
1385 -- renaming, then its entities must be frozen at this point. Note
1386 -- that such entities do NOT get frozen at the end of the nested
1387 -- package itself (only library packages freeze).
1389 -- Same is true for task declarations, where anonymous records
1390 -- created for entry parameters must be frozen.
1392 if Ekind (E) = E_Package
1393 and then No (Renamed_Object (E))
1394 and then not Is_Child_Unit (E)
1395 and then not Is_Frozen (E)
1396 then
1397 Push_Scope (E);
1398 Install_Visible_Declarations (E);
1399 Install_Private_Declarations (E);
1401 Freeze_All (First_Entity (E), After);
1403 End_Package_Scope (E);
1405 if Is_Generic_Instance (E)
1406 and then Has_Delayed_Freeze (E)
1407 then
1408 Set_Has_Delayed_Freeze (E, False);
1409 Expand_N_Package_Declaration (Unit_Declaration_Node (E));
1410 end if;
1412 elsif Ekind (E) in Task_Kind
1413 and then
1414 (Nkind (Parent (E)) = N_Task_Type_Declaration
1415 or else
1416 Nkind (Parent (E)) = N_Single_Task_Declaration)
1417 then
1418 Push_Scope (E);
1419 Freeze_All (First_Entity (E), After);
1420 End_Scope;
1422 -- For a derived tagged type, we must ensure that all the
1423 -- primitive operations of the parent have been frozen, so that
1424 -- their addresses will be in the parent's dispatch table at the
1425 -- point it is inherited.
1427 elsif Ekind (E) = E_Record_Type
1428 and then Is_Tagged_Type (E)
1429 and then Is_Tagged_Type (Etype (E))
1430 and then Is_Derived_Type (E)
1431 then
1432 declare
1433 Prim_List : constant Elist_Id :=
1434 Primitive_Operations (Etype (E));
1436 Prim : Elmt_Id;
1437 Subp : Entity_Id;
1439 begin
1440 Prim := First_Elmt (Prim_List);
1441 while Present (Prim) loop
1442 Subp := Node (Prim);
1444 if Comes_From_Source (Subp)
1445 and then not Is_Frozen (Subp)
1446 then
1447 Flist := Freeze_Entity (Subp, After);
1448 Process_Flist;
1449 end if;
1451 Next_Elmt (Prim);
1452 end loop;
1453 end;
1454 end if;
1456 if not Is_Frozen (E) then
1457 Flist := Freeze_Entity (E, After);
1458 Process_Flist;
1460 -- If already frozen, and there are delayed aspects, this is where
1461 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1462 -- for a description of how we handle aspect visibility).
1464 elsif Has_Delayed_Aspects (E) then
1466 -- Retrieve the visibility to the discriminants in order to
1467 -- analyze properly the aspects.
1469 Push_Scope_And_Install_Discriminants (E);
1471 declare
1472 Ritem : Node_Id;
1474 begin
1475 Ritem := First_Rep_Item (E);
1476 while Present (Ritem) loop
1477 if Nkind (Ritem) = N_Aspect_Specification
1478 and then Entity (Ritem) = E
1479 and then Is_Delayed_Aspect (Ritem)
1480 then
1481 Check_Aspect_At_End_Of_Declarations (Ritem);
1482 end if;
1484 Ritem := Next_Rep_Item (Ritem);
1485 end loop;
1486 end;
1488 Uninstall_Discriminants_And_Pop_Scope (E);
1489 end if;
1491 -- If an incomplete type is still not frozen, this may be a
1492 -- premature freezing because of a body declaration that follows.
1493 -- Indicate where the freezing took place. Freezing will happen
1494 -- if the body comes from source, but not if it is internally
1495 -- generated, for example as the body of a type invariant.
1497 -- If the freezing is caused by the end of the current declarative
1498 -- part, it is a Taft Amendment type, and there is no error.
1500 if not Is_Frozen (E)
1501 and then Ekind (E) = E_Incomplete_Type
1502 then
1503 declare
1504 Bod : constant Node_Id := Next (After);
1506 begin
1507 -- The presence of a body freezes all entities previously
1508 -- declared in the current list of declarations, but this
1509 -- does not apply if the body does not come from source.
1510 -- A type invariant is transformed into a subprogram body
1511 -- which is placed at the end of the private part of the
1512 -- current package, but this body does not freeze incomplete
1513 -- types that may be declared in this private part.
1515 if (Nkind_In (Bod, N_Subprogram_Body,
1516 N_Entry_Body,
1517 N_Package_Body,
1518 N_Protected_Body,
1519 N_Task_Body)
1520 or else Nkind (Bod) in N_Body_Stub)
1521 and then
1522 List_Containing (After) = List_Containing (Parent (E))
1523 and then Comes_From_Source (Bod)
1524 then
1525 Error_Msg_Sloc := Sloc (Next (After));
1526 Error_Msg_NE
1527 ("type& is frozen# before its full declaration",
1528 Parent (E), E);
1529 end if;
1530 end;
1531 end if;
1533 Next_Entity (E);
1534 end loop;
1535 end Freeze_All_Ent;
1537 -- Start of processing for Freeze_All
1539 begin
1540 Freeze_All_Ent (From, After);
1542 -- Now that all types are frozen, we can deal with default expressions
1543 -- that require us to build a default expression functions. This is the
1544 -- point at which such functions are constructed (after all types that
1545 -- might be used in such expressions have been frozen).
1547 -- For subprograms that are renaming_as_body, we create the wrapper
1548 -- bodies as needed.
1550 -- We also add finalization chains to access types whose designated
1551 -- types are controlled. This is normally done when freezing the type,
1552 -- but this misses recursive type definitions where the later members
1553 -- of the recursion introduce controlled components.
1555 -- Loop through entities
1557 E := From;
1558 while Present (E) loop
1559 if Is_Subprogram (E) then
1561 if not Default_Expressions_Processed (E) then
1562 Process_Default_Expressions (E, After);
1563 end if;
1565 if not Has_Completion (E) then
1566 Decl := Unit_Declaration_Node (E);
1568 if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
1569 if Error_Posted (Decl) then
1570 Set_Has_Completion (E);
1571 else
1572 Build_And_Analyze_Renamed_Body (Decl, E, After);
1573 end if;
1575 elsif Nkind (Decl) = N_Subprogram_Declaration
1576 and then Present (Corresponding_Body (Decl))
1577 and then
1578 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
1579 = N_Subprogram_Renaming_Declaration
1580 then
1581 Build_And_Analyze_Renamed_Body
1582 (Decl, Corresponding_Body (Decl), After);
1583 end if;
1584 end if;
1586 elsif Ekind (E) in Task_Kind
1587 and then
1588 (Nkind (Parent (E)) = N_Task_Type_Declaration
1589 or else
1590 Nkind (Parent (E)) = N_Single_Task_Declaration)
1591 then
1592 declare
1593 Ent : Entity_Id;
1595 begin
1596 Ent := First_Entity (E);
1597 while Present (Ent) loop
1598 if Is_Entry (Ent)
1599 and then not Default_Expressions_Processed (Ent)
1600 then
1601 Process_Default_Expressions (Ent, After);
1602 end if;
1604 Next_Entity (Ent);
1605 end loop;
1606 end;
1608 -- We add finalization masters to access types whose designated types
1609 -- require finalization. This is normally done when freezing the
1610 -- type, but this misses recursive type definitions where the later
1611 -- members of the recursion introduce controlled components (such as
1612 -- can happen when incomplete types are involved), as well cases
1613 -- where a component type is private and the controlled full type
1614 -- occurs after the access type is frozen. Cases that don't need a
1615 -- finalization master are generic formal types (the actual type will
1616 -- have it) and types with Java and CIL conventions, since those are
1617 -- used for API bindings. (Are there any other cases that should be
1618 -- excluded here???)
1620 elsif Is_Access_Type (E)
1621 and then Comes_From_Source (E)
1622 and then not Is_Generic_Type (E)
1623 and then Needs_Finalization (Designated_Type (E))
1624 then
1625 Build_Finalization_Master (E);
1626 end if;
1628 Next_Entity (E);
1629 end loop;
1630 end Freeze_All;
1632 -----------------------
1633 -- Freeze_And_Append --
1634 -----------------------
1636 procedure Freeze_And_Append
1637 (Ent : Entity_Id;
1638 N : Node_Id;
1639 Result : in out List_Id)
1641 L : constant List_Id := Freeze_Entity (Ent, N);
1642 begin
1643 if Is_Non_Empty_List (L) then
1644 if Result = No_List then
1645 Result := L;
1646 else
1647 Append_List (L, Result);
1648 end if;
1649 end if;
1650 end Freeze_And_Append;
1652 -------------------
1653 -- Freeze_Before --
1654 -------------------
1656 procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
1657 Freeze_Nodes : constant List_Id := Freeze_Entity (T, N);
1658 begin
1659 if Is_Non_Empty_List (Freeze_Nodes) then
1660 Insert_Actions (N, Freeze_Nodes);
1661 end if;
1662 end Freeze_Before;
1664 -------------------
1665 -- Freeze_Entity --
1666 -------------------
1668 function Freeze_Entity (E : Entity_Id; N : Node_Id) return List_Id is
1669 Loc : constant Source_Ptr := Sloc (N);
1670 Test_E : Entity_Id := E;
1671 Comp : Entity_Id;
1672 F_Node : Node_Id;
1673 Indx : Node_Id;
1674 Formal : Entity_Id;
1675 Atype : Entity_Id;
1677 Result : List_Id := No_List;
1678 -- List of freezing actions, left at No_List if none
1680 Has_Default_Initialization : Boolean := False;
1681 -- This flag gets set to true for a variable with default initialization
1683 procedure Add_To_Result (N : Node_Id);
1684 -- N is a freezing action to be appended to the Result
1686 function After_Last_Declaration return Boolean;
1687 -- If Loc is a freeze_entity that appears after the last declaration
1688 -- in the scope, inhibit error messages on late completion.
1690 procedure Check_Current_Instance (Comp_Decl : Node_Id);
1691 -- Check that an Access or Unchecked_Access attribute with a prefix
1692 -- which is the current instance type can only be applied when the type
1693 -- is limited.
1695 procedure Check_Suspicious_Modulus (Utype : Entity_Id);
1696 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1697 -- integer literal without an explicit corresponding size clause. The
1698 -- caller has checked that Utype is a modular integer type.
1700 procedure Freeze_Record_Type (Rec : Entity_Id);
1701 -- Freeze each component, handle some representation clauses, and freeze
1702 -- primitive operations if this is a tagged type.
1704 -------------------
1705 -- Add_To_Result --
1706 -------------------
1708 procedure Add_To_Result (N : Node_Id) is
1709 begin
1710 if No (Result) then
1711 Result := New_List (N);
1712 else
1713 Append (N, Result);
1714 end if;
1715 end Add_To_Result;
1717 ----------------------------
1718 -- After_Last_Declaration --
1719 ----------------------------
1721 function After_Last_Declaration return Boolean is
1722 Spec : constant Node_Id := Parent (Current_Scope);
1723 begin
1724 if Nkind (Spec) = N_Package_Specification then
1725 if Present (Private_Declarations (Spec)) then
1726 return Loc >= Sloc (Last (Private_Declarations (Spec)));
1727 elsif Present (Visible_Declarations (Spec)) then
1728 return Loc >= Sloc (Last (Visible_Declarations (Spec)));
1729 else
1730 return False;
1731 end if;
1732 else
1733 return False;
1734 end if;
1735 end After_Last_Declaration;
1737 ----------------------------
1738 -- Check_Current_Instance --
1739 ----------------------------
1741 procedure Check_Current_Instance (Comp_Decl : Node_Id) is
1743 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean;
1744 -- Determine whether Typ is compatible with the rules for aliased
1745 -- views of types as defined in RM 3.10 in the various dialects.
1747 function Process (N : Node_Id) return Traverse_Result;
1748 -- Process routine to apply check to given node
1750 -----------------------------
1751 -- Is_Aliased_View_Of_Type --
1752 -----------------------------
1754 function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean is
1755 Typ_Decl : constant Node_Id := Parent (Typ);
1757 begin
1758 -- Common case
1760 if Nkind (Typ_Decl) = N_Full_Type_Declaration
1761 and then Limited_Present (Type_Definition (Typ_Decl))
1762 then
1763 return True;
1765 -- The following paragraphs describe what a legal aliased view of
1766 -- a type is in the various dialects of Ada.
1768 -- Ada 95
1770 -- The current instance of a limited type, and a formal parameter
1771 -- or generic formal object of a tagged type.
1773 -- Ada 95 limited type
1774 -- * Type with reserved word "limited"
1775 -- * A protected or task type
1776 -- * A composite type with limited component
1778 elsif Ada_Version <= Ada_95 then
1779 return Is_Limited_Type (Typ);
1781 -- Ada 2005
1783 -- The current instance of a limited tagged type, a protected
1784 -- type, a task type, or a type that has the reserved word
1785 -- "limited" in its full definition ... a formal parameter or
1786 -- generic formal object of a tagged type.
1788 -- Ada 2005 limited type
1789 -- * Type with reserved word "limited", "synchronized", "task"
1790 -- or "protected"
1791 -- * A composite type with limited component
1792 -- * A derived type whose parent is a non-interface limited type
1794 elsif Ada_Version = Ada_2005 then
1795 return
1796 (Is_Limited_Type (Typ) and then Is_Tagged_Type (Typ))
1797 or else
1798 (Is_Derived_Type (Typ)
1799 and then not Is_Interface (Etype (Typ))
1800 and then Is_Limited_Type (Etype (Typ)));
1802 -- Ada 2012 and beyond
1804 -- The current instance of an immutably limited type ... a formal
1805 -- parameter or generic formal object of a tagged type.
1807 -- Ada 2012 limited type
1808 -- * Type with reserved word "limited", "synchronized", "task"
1809 -- or "protected"
1810 -- * A composite type with limited component
1811 -- * A derived type whose parent is a non-interface limited type
1812 -- * An incomplete view
1814 -- Ada 2012 immutably limited type
1815 -- * Explicitly limited record type
1816 -- * Record extension with "limited" present
1817 -- * Non-formal limited private type that is either tagged
1818 -- or has at least one access discriminant with a default
1819 -- expression
1820 -- * Task type, protected type or synchronized interface
1821 -- * Type derived from immutably limited type
1823 else
1824 return
1825 Is_Immutably_Limited_Type (Typ)
1826 or else Is_Incomplete_Type (Typ);
1827 end if;
1828 end Is_Aliased_View_Of_Type;
1830 -------------
1831 -- Process --
1832 -------------
1834 function Process (N : Node_Id) return Traverse_Result is
1835 begin
1836 case Nkind (N) is
1837 when N_Attribute_Reference =>
1838 if Nam_In (Attribute_Name (N), Name_Access,
1839 Name_Unchecked_Access)
1840 and then Is_Entity_Name (Prefix (N))
1841 and then Is_Type (Entity (Prefix (N)))
1842 and then Entity (Prefix (N)) = E
1843 then
1844 Error_Msg_N
1845 ("current instance must be a limited type", Prefix (N));
1846 return Abandon;
1847 else
1848 return OK;
1849 end if;
1851 when others => return OK;
1852 end case;
1853 end Process;
1855 procedure Traverse is new Traverse_Proc (Process);
1857 -- Local variables
1859 Rec_Type : constant Entity_Id :=
1860 Scope (Defining_Identifier (Comp_Decl));
1862 -- Start of processing for Check_Current_Instance
1864 begin
1865 if not Is_Aliased_View_Of_Type (Rec_Type) then
1866 Traverse (Comp_Decl);
1867 end if;
1868 end Check_Current_Instance;
1870 ------------------------------
1871 -- Check_Suspicious_Modulus --
1872 ------------------------------
1874 procedure Check_Suspicious_Modulus (Utype : Entity_Id) is
1875 Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype));
1877 begin
1878 if not Warn_On_Suspicious_Modulus_Value then
1879 return;
1880 end if;
1882 if Nkind (Decl) = N_Full_Type_Declaration then
1883 declare
1884 Tdef : constant Node_Id := Type_Definition (Decl);
1886 begin
1887 if Nkind (Tdef) = N_Modular_Type_Definition then
1888 declare
1889 Modulus : constant Node_Id :=
1890 Original_Node (Expression (Tdef));
1892 begin
1893 if Nkind (Modulus) = N_Integer_Literal then
1894 declare
1895 Modv : constant Uint := Intval (Modulus);
1896 Sizv : constant Uint := RM_Size (Utype);
1898 begin
1899 -- First case, modulus and size are the same. This
1900 -- happens if you have something like mod 32, with
1901 -- an explicit size of 32, this is for sure a case
1902 -- where the warning is given, since it is seems
1903 -- very unlikely that someone would want e.g. a
1904 -- five bit type stored in 32 bits. It is much
1905 -- more likely they wanted a 32-bit type.
1907 if Modv = Sizv then
1908 null;
1910 -- Second case, the modulus is 32 or 64 and no
1911 -- size clause is present. This is a less clear
1912 -- case for giving the warning, but in the case
1913 -- of 32/64 (5-bit or 6-bit types) these seem rare
1914 -- enough that it is a likely error (and in any
1915 -- case using 2**5 or 2**6 in these cases seems
1916 -- clearer. We don't include 8 or 16 here, simply
1917 -- because in practice 3-bit and 4-bit types are
1918 -- more common and too many false positives if
1919 -- we warn in these cases.
1921 elsif not Has_Size_Clause (Utype)
1922 and then (Modv = Uint_32 or else Modv = Uint_64)
1923 then
1924 null;
1926 -- No warning needed
1928 else
1929 return;
1930 end if;
1932 -- If we fall through, give warning
1934 Error_Msg_Uint_1 := Modv;
1935 Error_Msg_N
1936 ("?M?2 '*'*^' may have been intended here",
1937 Modulus);
1938 end;
1939 end if;
1940 end;
1941 end if;
1942 end;
1943 end if;
1944 end Check_Suspicious_Modulus;
1946 ------------------------
1947 -- Freeze_Record_Type --
1948 ------------------------
1950 procedure Freeze_Record_Type (Rec : Entity_Id) is
1951 Comp : Entity_Id;
1952 IR : Node_Id;
1953 ADC : Node_Id;
1954 Prev : Entity_Id;
1956 Junk : Boolean;
1957 pragma Warnings (Off, Junk);
1959 Rec_Pushed : Boolean := False;
1960 -- Set True if the record type scope Rec has been pushed on the scope
1961 -- stack. Needed for the analysis of delayed aspects specified to the
1962 -- components of Rec.
1964 Unplaced_Component : Boolean := False;
1965 -- Set True if we find at least one component with no component
1966 -- clause (used to warn about useless Pack pragmas).
1968 Placed_Component : Boolean := False;
1969 -- Set True if we find at least one component with a component
1970 -- clause (used to warn about useless Bit_Order pragmas, and also
1971 -- to detect cases where Implicit_Packing may have an effect).
1973 All_Scalar_Components : Boolean := True;
1974 -- Set False if we encounter a component of a non-scalar type
1976 Scalar_Component_Total_RM_Size : Uint := Uint_0;
1977 Scalar_Component_Total_Esize : Uint := Uint_0;
1978 -- Accumulates total RM_Size values and total Esize values of all
1979 -- scalar components. Used for processing of Implicit_Packing.
1981 function Check_Allocator (N : Node_Id) return Node_Id;
1982 -- If N is an allocator, possibly wrapped in one or more level of
1983 -- qualified expression(s), return the inner allocator node, else
1984 -- return Empty.
1986 procedure Check_Itype (Typ : Entity_Id);
1987 -- If the component subtype is an access to a constrained subtype of
1988 -- an already frozen type, make the subtype frozen as well. It might
1989 -- otherwise be frozen in the wrong scope, and a freeze node on
1990 -- subtype has no effect. Similarly, if the component subtype is a
1991 -- regular (not protected) access to subprogram, set the anonymous
1992 -- subprogram type to frozen as well, to prevent an out-of-scope
1993 -- freeze node at some eventual point of call. Protected operations
1994 -- are handled elsewhere.
1996 ---------------------
1997 -- Check_Allocator --
1998 ---------------------
2000 function Check_Allocator (N : Node_Id) return Node_Id is
2001 Inner : Node_Id;
2002 begin
2003 Inner := N;
2004 loop
2005 if Nkind (Inner) = N_Allocator then
2006 return Inner;
2007 elsif Nkind (Inner) = N_Qualified_Expression then
2008 Inner := Expression (Inner);
2009 else
2010 return Empty;
2011 end if;
2012 end loop;
2013 end Check_Allocator;
2015 -----------------
2016 -- Check_Itype --
2017 -----------------
2019 procedure Check_Itype (Typ : Entity_Id) is
2020 Desig : constant Entity_Id := Designated_Type (Typ);
2022 begin
2023 if not Is_Frozen (Desig)
2024 and then Is_Frozen (Base_Type (Desig))
2025 then
2026 Set_Is_Frozen (Desig);
2028 -- In addition, add an Itype_Reference to ensure that the
2029 -- access subtype is elaborated early enough. This cannot be
2030 -- done if the subtype may depend on discriminants.
2032 if Ekind (Comp) = E_Component
2033 and then Is_Itype (Etype (Comp))
2034 and then not Has_Discriminants (Rec)
2035 then
2036 IR := Make_Itype_Reference (Sloc (Comp));
2037 Set_Itype (IR, Desig);
2038 Add_To_Result (IR);
2039 end if;
2041 elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type
2042 and then Convention (Desig) /= Convention_Protected
2043 then
2044 Set_Is_Frozen (Desig);
2045 end if;
2046 end Check_Itype;
2048 -- Start of processing for Freeze_Record_Type
2050 begin
2051 -- Deal with delayed aspect specifications for components. The
2052 -- analysis of the aspect is required to be delayed to the freeze
2053 -- point, thus we analyze the pragma or attribute definition
2054 -- clause in the tree at this point. We also analyze the aspect
2055 -- specification node at the freeze point when the aspect doesn't
2056 -- correspond to pragma/attribute definition clause.
2058 Comp := First_Entity (Rec);
2059 while Present (Comp) loop
2060 if Ekind (Comp) = E_Component
2061 and then Has_Delayed_Aspects (Comp)
2062 then
2063 if not Rec_Pushed then
2064 Push_Scope (Rec);
2065 Rec_Pushed := True;
2067 -- The visibility to the discriminants must be restored in
2068 -- order to properly analyze the aspects.
2070 if Has_Discriminants (Rec) then
2071 Install_Discriminants (Rec);
2072 end if;
2073 end if;
2075 Analyze_Aspects_At_Freeze_Point (Comp);
2076 end if;
2078 Next_Entity (Comp);
2079 end loop;
2081 -- Pop the scope if Rec scope has been pushed on the scope stack
2082 -- during the delayed aspect analysis process.
2084 if Rec_Pushed then
2085 if Has_Discriminants (Rec) then
2086 Uninstall_Discriminants (Rec);
2087 end if;
2089 Pop_Scope;
2090 end if;
2092 -- Freeze components and embedded subtypes
2094 Comp := First_Entity (Rec);
2095 Prev := Empty;
2096 while Present (Comp) loop
2098 -- Handle the component and discriminant case
2100 if Ekind_In (Comp, E_Component, E_Discriminant) then
2101 declare
2102 CC : constant Node_Id := Component_Clause (Comp);
2104 begin
2105 -- Freezing a record type freezes the type of each of its
2106 -- components. However, if the type of the component is
2107 -- part of this record, we do not want or need a separate
2108 -- Freeze_Node. Note that Is_Itype is wrong because that's
2109 -- also set in private type cases. We also can't check for
2110 -- the Scope being exactly Rec because of private types and
2111 -- record extensions.
2113 if Is_Itype (Etype (Comp))
2114 and then Is_Record_Type (Underlying_Type
2115 (Scope (Etype (Comp))))
2116 then
2117 Undelay_Type (Etype (Comp));
2118 end if;
2120 Freeze_And_Append (Etype (Comp), N, Result);
2122 -- Check for error of component clause given for variable
2123 -- sized type. We have to delay this test till this point,
2124 -- since the component type has to be frozen for us to know
2125 -- if it is variable length. We omit this test in a generic
2126 -- context, it will be applied at instantiation time.
2128 -- We also omit this test in CodePeer mode, since we do not
2129 -- have sufficient info on size and representation clauses.
2131 if Present (CC) then
2132 Placed_Component := True;
2134 if Inside_A_Generic then
2135 null;
2137 elsif CodePeer_Mode then
2138 null;
2140 elsif not
2141 Size_Known_At_Compile_Time
2142 (Underlying_Type (Etype (Comp)))
2143 then
2144 Error_Msg_N
2145 ("component clause not allowed for variable " &
2146 "length component", CC);
2147 end if;
2149 else
2150 Unplaced_Component := True;
2151 end if;
2153 -- Case of component requires byte alignment
2155 if Must_Be_On_Byte_Boundary (Etype (Comp)) then
2157 -- Set the enclosing record to also require byte align
2159 Set_Must_Be_On_Byte_Boundary (Rec);
2161 -- Check for component clause that is inconsistent with
2162 -- the required byte boundary alignment.
2164 if Present (CC)
2165 and then Normalized_First_Bit (Comp) mod
2166 System_Storage_Unit /= 0
2167 then
2168 Error_Msg_N
2169 ("component & must be byte aligned",
2170 Component_Name (Component_Clause (Comp)));
2171 end if;
2172 end if;
2173 end;
2174 end if;
2176 -- Gather data for possible Implicit_Packing later. Note that at
2177 -- this stage we might be dealing with a real component, or with
2178 -- an implicit subtype declaration.
2180 if not Is_Scalar_Type (Etype (Comp)) then
2181 All_Scalar_Components := False;
2182 else
2183 Scalar_Component_Total_RM_Size :=
2184 Scalar_Component_Total_RM_Size + RM_Size (Etype (Comp));
2185 Scalar_Component_Total_Esize :=
2186 Scalar_Component_Total_Esize + Esize (Etype (Comp));
2187 end if;
2189 -- If the component is an Itype with Delayed_Freeze and is either
2190 -- a record or array subtype and its base type has not yet been
2191 -- frozen, we must remove this from the entity list of this record
2192 -- and put it on the entity list of the scope of its base type.
2193 -- Note that we know that this is not the type of a component
2194 -- since we cleared Has_Delayed_Freeze for it in the previous
2195 -- loop. Thus this must be the Designated_Type of an access type,
2196 -- which is the type of a component.
2198 if Is_Itype (Comp)
2199 and then Is_Type (Scope (Comp))
2200 and then Is_Composite_Type (Comp)
2201 and then Base_Type (Comp) /= Comp
2202 and then Has_Delayed_Freeze (Comp)
2203 and then not Is_Frozen (Base_Type (Comp))
2204 then
2205 declare
2206 Will_Be_Frozen : Boolean := False;
2207 S : Entity_Id;
2209 begin
2210 -- We have a pretty bad kludge here. Suppose Rec is subtype
2211 -- being defined in a subprogram that's created as part of
2212 -- the freezing of Rec'Base. In that case, we know that
2213 -- Comp'Base must have already been frozen by the time we
2214 -- get to elaborate this because Gigi doesn't elaborate any
2215 -- bodies until it has elaborated all of the declarative
2216 -- part. But Is_Frozen will not be set at this point because
2217 -- we are processing code in lexical order.
2219 -- We detect this case by going up the Scope chain of Rec
2220 -- and seeing if we have a subprogram scope before reaching
2221 -- the top of the scope chain or that of Comp'Base. If we
2222 -- do, then mark that Comp'Base will actually be frozen. If
2223 -- so, we merely undelay it.
2225 S := Scope (Rec);
2226 while Present (S) loop
2227 if Is_Subprogram (S) then
2228 Will_Be_Frozen := True;
2229 exit;
2230 elsif S = Scope (Base_Type (Comp)) then
2231 exit;
2232 end if;
2234 S := Scope (S);
2235 end loop;
2237 if Will_Be_Frozen then
2238 Undelay_Type (Comp);
2239 else
2240 if Present (Prev) then
2241 Set_Next_Entity (Prev, Next_Entity (Comp));
2242 else
2243 Set_First_Entity (Rec, Next_Entity (Comp));
2244 end if;
2246 -- Insert in entity list of scope of base type (which
2247 -- must be an enclosing scope, because still unfrozen).
2249 Append_Entity (Comp, Scope (Base_Type (Comp)));
2250 end if;
2251 end;
2253 -- If the component is an access type with an allocator as default
2254 -- value, the designated type will be frozen by the corresponding
2255 -- expression in init_proc. In order to place the freeze node for
2256 -- the designated type before that for the current record type,
2257 -- freeze it now.
2259 -- Same process if the component is an array of access types,
2260 -- initialized with an aggregate. If the designated type is
2261 -- private, it cannot contain allocators, and it is premature
2262 -- to freeze the type, so we check for this as well.
2264 elsif Is_Access_Type (Etype (Comp))
2265 and then Present (Parent (Comp))
2266 and then Present (Expression (Parent (Comp)))
2267 then
2268 declare
2269 Alloc : constant Node_Id :=
2270 Check_Allocator (Expression (Parent (Comp)));
2272 begin
2273 if Present (Alloc) then
2275 -- If component is pointer to a classwide type, freeze
2276 -- the specific type in the expression being allocated.
2277 -- The expression may be a subtype indication, in which
2278 -- case freeze the subtype mark.
2280 if Is_Class_Wide_Type
2281 (Designated_Type (Etype (Comp)))
2282 then
2283 if Is_Entity_Name (Expression (Alloc)) then
2284 Freeze_And_Append
2285 (Entity (Expression (Alloc)), N, Result);
2286 elsif
2287 Nkind (Expression (Alloc)) = N_Subtype_Indication
2288 then
2289 Freeze_And_Append
2290 (Entity (Subtype_Mark (Expression (Alloc))),
2291 N, Result);
2292 end if;
2294 elsif Is_Itype (Designated_Type (Etype (Comp))) then
2295 Check_Itype (Etype (Comp));
2297 else
2298 Freeze_And_Append
2299 (Designated_Type (Etype (Comp)), N, Result);
2300 end if;
2301 end if;
2302 end;
2304 elsif Is_Access_Type (Etype (Comp))
2305 and then Is_Itype (Designated_Type (Etype (Comp)))
2306 then
2307 Check_Itype (Etype (Comp));
2309 elsif Is_Array_Type (Etype (Comp))
2310 and then Is_Access_Type (Component_Type (Etype (Comp)))
2311 and then Present (Parent (Comp))
2312 and then Nkind (Parent (Comp)) = N_Component_Declaration
2313 and then Present (Expression (Parent (Comp)))
2314 and then Nkind (Expression (Parent (Comp))) = N_Aggregate
2315 and then Is_Fully_Defined
2316 (Designated_Type (Component_Type (Etype (Comp))))
2317 then
2318 Freeze_And_Append
2319 (Designated_Type
2320 (Component_Type (Etype (Comp))), N, Result);
2321 end if;
2323 Prev := Comp;
2324 Next_Entity (Comp);
2325 end loop;
2327 ADC := Get_Attribute_Definition_Clause
2328 (Rec, Attribute_Scalar_Storage_Order);
2330 if Present (ADC) then
2332 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
2333 -- the former is specified.
2335 if Reverse_Bit_Order (Rec) /= Reverse_Storage_Order (Rec) then
2337 -- Note: report error on Rec, not on ADC, as ADC may apply to
2338 -- an ancestor type.
2340 Error_Msg_Sloc := Sloc (ADC);
2341 Error_Msg_N
2342 ("scalar storage order for& specified# inconsistent with "
2343 & "bit order", Rec);
2344 end if;
2346 -- Warn if there is a Scalar_Storage_Order but no component clause
2347 -- (or pragma Pack).
2349 if not (Placed_Component or else Is_Packed (Rec)) then
2350 Error_Msg_N
2351 ("??scalar storage order specified but no component clause",
2352 ADC);
2353 end if;
2355 -- Check attribute on component types
2357 Comp := First_Component (Rec);
2358 while Present (Comp) loop
2359 Check_Component_Storage_Order (Rec, Comp);
2360 Next_Component (Comp);
2361 end loop;
2362 end if;
2364 -- Deal with Bit_Order aspect specifying a non-default bit order
2366 ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
2368 if Present (ADC) and then Base_Type (Rec) = Rec then
2369 if not (Placed_Component or else Is_Packed (Rec)) then
2370 Error_Msg_N ("??bit order specification has no effect", ADC);
2371 Error_Msg_N
2372 ("\??since no component clauses were specified", ADC);
2374 -- Here is where we do the processing for reversed bit order
2376 elsif Reverse_Bit_Order (Rec)
2377 and then not Reverse_Storage_Order (Rec)
2378 then
2379 Adjust_Record_For_Reverse_Bit_Order (Rec);
2381 -- Case where we have both an explicit Bit_Order and the same
2382 -- Scalar_Storage_Order: leave record untouched, the back-end
2383 -- will take care of required layout conversions.
2385 else
2386 null;
2388 end if;
2389 end if;
2391 -- Complete error checking on record representation clause (e.g.
2392 -- overlap of components). This is called after adjusting the
2393 -- record for reverse bit order.
2395 declare
2396 RRC : constant Node_Id := Get_Record_Representation_Clause (Rec);
2397 begin
2398 if Present (RRC) then
2399 Check_Record_Representation_Clause (RRC);
2400 end if;
2401 end;
2403 -- Set OK_To_Reorder_Components depending on debug flags
2405 if Is_Base_Type (Rec) and then Convention (Rec) = Convention_Ada then
2406 if (Has_Discriminants (Rec) and then Debug_Flag_Dot_V)
2407 or else
2408 (not Has_Discriminants (Rec) and then Debug_Flag_Dot_R)
2409 then
2410 Set_OK_To_Reorder_Components (Rec);
2411 end if;
2412 end if;
2414 -- Check for useless pragma Pack when all components placed. We only
2415 -- do this check for record types, not subtypes, since a subtype may
2416 -- have all its components placed, and it still makes perfectly good
2417 -- sense to pack other subtypes or the parent type. We do not give
2418 -- this warning if Optimize_Alignment is set to Space, since the
2419 -- pragma Pack does have an effect in this case (it always resets
2420 -- the alignment to one).
2422 if Ekind (Rec) = E_Record_Type
2423 and then Is_Packed (Rec)
2424 and then not Unplaced_Component
2425 and then Optimize_Alignment /= 'S'
2426 then
2427 -- Reset packed status. Probably not necessary, but we do it so
2428 -- that there is no chance of the back end doing something strange
2429 -- with this redundant indication of packing.
2431 Set_Is_Packed (Rec, False);
2433 -- Give warning if redundant constructs warnings on
2435 if Warn_On_Redundant_Constructs then
2436 Error_Msg_N -- CODEFIX
2437 ("??pragma Pack has no effect, no unplaced components",
2438 Get_Rep_Pragma (Rec, Name_Pack));
2439 end if;
2440 end if;
2442 -- If this is the record corresponding to a remote type, freeze the
2443 -- remote type here since that is what we are semantically freezing.
2444 -- This prevents the freeze node for that type in an inner scope.
2446 -- Also, Check for controlled components and unchecked unions.
2447 -- Finally, enforce the restriction that access attributes with a
2448 -- current instance prefix can only apply to limited types.
2450 if Ekind (Rec) = E_Record_Type then
2451 if Present (Corresponding_Remote_Type (Rec)) then
2452 Freeze_And_Append (Corresponding_Remote_Type (Rec), N, Result);
2453 end if;
2455 Comp := First_Component (Rec);
2456 while Present (Comp) loop
2458 -- Do not set Has_Controlled_Component on a class-wide
2459 -- equivalent type. See Make_CW_Equivalent_Type.
2461 if not Is_Class_Wide_Equivalent_Type (Rec)
2462 and then (Has_Controlled_Component (Etype (Comp))
2463 or else (Chars (Comp) /= Name_uParent
2464 and then Is_Controlled (Etype (Comp)))
2465 or else (Is_Protected_Type (Etype (Comp))
2466 and then Present
2467 (Corresponding_Record_Type
2468 (Etype (Comp)))
2469 and then Has_Controlled_Component
2470 (Corresponding_Record_Type
2471 (Etype (Comp)))))
2472 then
2473 Set_Has_Controlled_Component (Rec);
2474 end if;
2476 if Has_Unchecked_Union (Etype (Comp)) then
2477 Set_Has_Unchecked_Union (Rec);
2478 end if;
2480 -- Scan component declaration for likely misuses of current
2481 -- instance, either in a constraint or a default expression.
2483 if Has_Per_Object_Constraint (Comp) then
2484 Check_Current_Instance (Parent (Comp));
2485 end if;
2487 Next_Component (Comp);
2488 end loop;
2489 end if;
2491 Set_Component_Alignment_If_Not_Set (Rec);
2493 -- For first subtypes, check if there are any fixed-point fields with
2494 -- component clauses, where we must check the size. This is not done
2495 -- till the freeze point, since for fixed-point types, we do not know
2496 -- the size until the type is frozen. Similar processing applies to
2497 -- bit packed arrays.
2499 if Is_First_Subtype (Rec) then
2500 Comp := First_Component (Rec);
2501 while Present (Comp) loop
2502 if Present (Component_Clause (Comp))
2503 and then (Is_Fixed_Point_Type (Etype (Comp))
2504 or else
2505 Is_Bit_Packed_Array (Etype (Comp)))
2506 then
2507 Check_Size
2508 (Component_Name (Component_Clause (Comp)),
2509 Etype (Comp),
2510 Esize (Comp),
2511 Junk);
2512 end if;
2514 Next_Component (Comp);
2515 end loop;
2516 end if;
2518 -- Generate warning for applying C or C++ convention to a record
2519 -- with discriminants. This is suppressed for the unchecked union
2520 -- case, since the whole point in this case is interface C. We also
2521 -- do not generate this within instantiations, since we will have
2522 -- generated a message on the template.
2524 if Has_Discriminants (E)
2525 and then not Is_Unchecked_Union (E)
2526 and then (Convention (E) = Convention_C
2527 or else
2528 Convention (E) = Convention_CPP)
2529 and then Comes_From_Source (E)
2530 and then not In_Instance
2531 and then not Has_Warnings_Off (E)
2532 and then not Has_Warnings_Off (Base_Type (E))
2533 then
2534 declare
2535 Cprag : constant Node_Id := Get_Rep_Pragma (E, Name_Convention);
2536 A2 : Node_Id;
2538 begin
2539 if Present (Cprag) then
2540 A2 := Next (First (Pragma_Argument_Associations (Cprag)));
2542 if Convention (E) = Convention_C then
2543 Error_Msg_N
2544 ("?x?variant record has no direct equivalent in C",
2545 A2);
2546 else
2547 Error_Msg_N
2548 ("?x?variant record has no direct equivalent in C++",
2549 A2);
2550 end if;
2552 Error_Msg_NE
2553 ("\?x?use of convention for type& is dubious", A2, E);
2554 end if;
2555 end;
2556 end if;
2558 -- See if Size is too small as is (and implicit packing might help)
2560 if not Is_Packed (Rec)
2562 -- No implicit packing if even one component is explicitly placed
2564 and then not Placed_Component
2566 -- Must have size clause and all scalar components
2568 and then Has_Size_Clause (Rec)
2569 and then All_Scalar_Components
2571 -- Do not try implicit packing on records with discriminants, too
2572 -- complicated, especially in the variant record case.
2574 and then not Has_Discriminants (Rec)
2576 -- We can implicitly pack if the specified size of the record is
2577 -- less than the sum of the object sizes (no point in packing if
2578 -- this is not the case).
2580 and then RM_Size (Rec) < Scalar_Component_Total_Esize
2582 -- And the total RM size cannot be greater than the specified size
2583 -- since otherwise packing will not get us where we have to be!
2585 and then RM_Size (Rec) >= Scalar_Component_Total_RM_Size
2587 -- Never do implicit packing in CodePeer or SPARK modes since
2588 -- we don't do any packing in these modes, since this generates
2589 -- over-complex code that confuses static analysis, and in
2590 -- general, neither CodePeer not GNATprove care about the
2591 -- internal representation of objects.
2593 and then not (CodePeer_Mode or SPARK_Mode)
2594 then
2595 -- If implicit packing enabled, do it
2597 if Implicit_Packing then
2598 Set_Is_Packed (Rec);
2600 -- Otherwise flag the size clause
2602 else
2603 declare
2604 Sz : constant Node_Id := Size_Clause (Rec);
2605 begin
2606 Error_Msg_NE -- CODEFIX
2607 ("size given for& too small", Sz, Rec);
2608 Error_Msg_N -- CODEFIX
2609 ("\use explicit pragma Pack "
2610 & "or use pragma Implicit_Packing", Sz);
2611 end;
2612 end if;
2613 end if;
2614 end Freeze_Record_Type;
2616 -- Start of processing for Freeze_Entity
2618 begin
2619 -- We are going to test for various reasons why this entity need not be
2620 -- frozen here, but in the case of an Itype that's defined within a
2621 -- record, that test actually applies to the record.
2623 if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
2624 Test_E := Scope (E);
2625 elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
2626 and then Is_Record_Type (Underlying_Type (Scope (E)))
2627 then
2628 Test_E := Underlying_Type (Scope (E));
2629 end if;
2631 -- Do not freeze if already frozen since we only need one freeze node
2633 if Is_Frozen (E) then
2634 return No_List;
2636 -- It is improper to freeze an external entity within a generic because
2637 -- its freeze node will appear in a non-valid context. The entity will
2638 -- be frozen in the proper scope after the current generic is analyzed.
2639 -- However, aspects must be analyzed because they may be queried later
2640 -- within the generic itself, and the corresponding pragma or attribute
2641 -- definition has not been analyzed yet.
2643 elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then
2644 if Has_Delayed_Aspects (E) then
2645 Analyze_Aspects_At_Freeze_Point (E);
2646 end if;
2648 return No_List;
2650 -- AI05-0213: A formal incomplete type does not freeze the actual. In
2651 -- the instance, the same applies to the subtype renaming the actual.
2653 elsif Is_Private_Type (E)
2654 and then Is_Generic_Actual_Type (E)
2655 and then No (Full_View (Base_Type (E)))
2656 and then Ada_Version >= Ada_2012
2657 then
2658 return No_List;
2660 -- Do not freeze a global entity within an inner scope created during
2661 -- expansion. A call to subprogram E within some internal procedure
2662 -- (a stream attribute for example) might require freezing E, but the
2663 -- freeze node must appear in the same declarative part as E itself.
2664 -- The two-pass elaboration mechanism in gigi guarantees that E will
2665 -- be frozen before the inner call is elaborated. We exclude constants
2666 -- from this test, because deferred constants may be frozen early, and
2667 -- must be diagnosed (e.g. in the case of a deferred constant being used
2668 -- in a default expression). If the enclosing subprogram comes from
2669 -- source, or is a generic instance, then the freeze point is the one
2670 -- mandated by the language, and we freeze the entity. A subprogram that
2671 -- is a child unit body that acts as a spec does not have a spec that
2672 -- comes from source, but can only come from source.
2674 elsif In_Open_Scopes (Scope (Test_E))
2675 and then Scope (Test_E) /= Current_Scope
2676 and then Ekind (Test_E) /= E_Constant
2677 then
2678 declare
2679 S : Entity_Id;
2681 begin
2682 S := Current_Scope;
2683 while Present (S) loop
2684 if Is_Overloadable (S) then
2685 if Comes_From_Source (S)
2686 or else Is_Generic_Instance (S)
2687 or else Is_Child_Unit (S)
2688 then
2689 exit;
2690 else
2691 return No_List;
2692 end if;
2693 end if;
2695 S := Scope (S);
2696 end loop;
2697 end;
2699 -- Similarly, an inlined instance body may make reference to global
2700 -- entities, but these references cannot be the proper freezing point
2701 -- for them, and in the absence of inlining freezing will take place in
2702 -- their own scope. Normally instance bodies are analyzed after the
2703 -- enclosing compilation, and everything has been frozen at the proper
2704 -- place, but with front-end inlining an instance body is compiled
2705 -- before the end of the enclosing scope, and as a result out-of-order
2706 -- freezing must be prevented.
2708 elsif Front_End_Inlining
2709 and then In_Instance_Body
2710 and then Present (Scope (Test_E))
2711 then
2712 declare
2713 S : Entity_Id;
2715 begin
2716 S := Scope (Test_E);
2717 while Present (S) loop
2718 if Is_Generic_Instance (S) then
2719 exit;
2720 else
2721 S := Scope (S);
2722 end if;
2723 end loop;
2725 if No (S) then
2726 return No_List;
2727 end if;
2728 end;
2729 end if;
2731 -- Add checks to detect proper initialization of scalars that may appear
2732 -- as subprogram parameters.
2734 if Is_Subprogram (E)
2735 and then Check_Validity_Of_Parameters
2736 then
2737 Apply_Parameter_Validity_Checks (E);
2738 end if;
2740 -- Deal with delayed aspect specifications. The analysis of the aspect
2741 -- is required to be delayed to the freeze point, thus we analyze the
2742 -- pragma or attribute definition clause in the tree at this point. We
2743 -- also analyze the aspect specification node at the freeze point when
2744 -- the aspect doesn't correspond to pragma/attribute definition clause.
2746 if Has_Delayed_Aspects (E) then
2747 Analyze_Aspects_At_Freeze_Point (E);
2748 end if;
2750 -- Here to freeze the entity
2752 Set_Is_Frozen (E);
2754 -- Case of entity being frozen is other than a type
2756 if not Is_Type (E) then
2758 -- If entity is exported or imported and does not have an external
2759 -- name, now is the time to provide the appropriate default name.
2760 -- Skip this if the entity is stubbed, since we don't need a name
2761 -- for any stubbed routine. For the case on intrinsics, if no
2762 -- external name is specified, then calls will be handled in
2763 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
2764 -- external name is provided, then Expand_Intrinsic_Call leaves
2765 -- calls in place for expansion by GIGI.
2767 if (Is_Imported (E) or else Is_Exported (E))
2768 and then No (Interface_Name (E))
2769 and then Convention (E) /= Convention_Stubbed
2770 and then Convention (E) /= Convention_Intrinsic
2771 then
2772 Set_Encoded_Interface_Name
2773 (E, Get_Default_External_Name (E));
2775 -- If entity is an atomic object appearing in a declaration and
2776 -- the expression is an aggregate, assign it to a temporary to
2777 -- ensure that the actual assignment is done atomically rather
2778 -- than component-wise (the assignment to the temp may be done
2779 -- component-wise, but that is harmless).
2781 elsif Is_Atomic (E)
2782 and then Nkind (Parent (E)) = N_Object_Declaration
2783 and then Present (Expression (Parent (E)))
2784 and then Nkind (Expression (Parent (E))) = N_Aggregate
2785 and then Is_Atomic_Aggregate (Expression (Parent (E)), Etype (E))
2786 then
2787 null;
2788 end if;
2790 -- For a subprogram, freeze all parameter types and also the return
2791 -- type (RM 13.14(14)). However skip this for internal subprograms.
2792 -- This is also the point where any extra formal parameters are
2793 -- created since we now know whether the subprogram will use a
2794 -- foreign convention.
2796 if Is_Subprogram (E) then
2797 if not Is_Internal (E) then
2798 declare
2799 F_Type : Entity_Id;
2800 R_Type : Entity_Id;
2801 Warn_Node : Node_Id;
2803 begin
2804 -- Loop through formals
2806 Formal := First_Formal (E);
2807 while Present (Formal) loop
2808 F_Type := Etype (Formal);
2810 -- AI05-0151 : incomplete types can appear in a profile.
2811 -- By the time the entity is frozen, the full view must
2812 -- be available, unless it is a limited view.
2814 if Is_Incomplete_Type (F_Type)
2815 and then Present (Full_View (F_Type))
2816 then
2817 F_Type := Full_View (F_Type);
2818 Set_Etype (Formal, F_Type);
2819 end if;
2821 Freeze_And_Append (F_Type, N, Result);
2823 if Is_Private_Type (F_Type)
2824 and then Is_Private_Type (Base_Type (F_Type))
2825 and then No (Full_View (Base_Type (F_Type)))
2826 and then not Is_Generic_Type (F_Type)
2827 and then not Is_Derived_Type (F_Type)
2828 then
2829 -- If the type of a formal is incomplete, subprogram
2830 -- is being frozen prematurely. Within an instance
2831 -- (but not within a wrapper package) this is an
2832 -- artifact of our need to regard the end of an
2833 -- instantiation as a freeze point. Otherwise it is
2834 -- a definite error.
2836 if In_Instance then
2837 Set_Is_Frozen (E, False);
2838 return No_List;
2840 elsif not After_Last_Declaration
2841 and then not Freezing_Library_Level_Tagged_Type
2842 then
2843 Error_Msg_Node_1 := F_Type;
2844 Error_Msg
2845 ("type& must be fully defined before this point",
2846 Loc);
2847 end if;
2848 end if;
2850 -- Check suspicious parameter for C function. These tests
2851 -- apply only to exported/imported subprograms.
2853 if Warn_On_Export_Import
2854 and then Comes_From_Source (E)
2855 and then (Convention (E) = Convention_C
2856 or else
2857 Convention (E) = Convention_CPP)
2858 and then (Is_Imported (E) or else Is_Exported (E))
2859 and then Convention (E) /= Convention (Formal)
2860 and then not Has_Warnings_Off (E)
2861 and then not Has_Warnings_Off (F_Type)
2862 and then not Has_Warnings_Off (Formal)
2863 then
2864 -- Qualify mention of formals with subprogram name
2866 Error_Msg_Qual_Level := 1;
2868 -- Check suspicious use of fat C pointer
2870 if Is_Access_Type (F_Type)
2871 and then Esize (F_Type) > Ttypes.System_Address_Size
2872 then
2873 Error_Msg_N
2874 ("?x?type of & does not correspond to C pointer!",
2875 Formal);
2877 -- Check suspicious return of boolean
2879 elsif Root_Type (F_Type) = Standard_Boolean
2880 and then Convention (F_Type) = Convention_Ada
2881 and then not Has_Warnings_Off (F_Type)
2882 and then not Has_Size_Clause (F_Type)
2883 and then VM_Target = No_VM
2884 then
2885 Error_Msg_N
2886 ("& is an 8-bit Ada Boolean?x?", Formal);
2887 Error_Msg_N
2888 ("\use appropriate corresponding type in C "
2889 & "(e.g. char)?x?", Formal);
2891 -- Check suspicious tagged type
2893 elsif (Is_Tagged_Type (F_Type)
2894 or else (Is_Access_Type (F_Type)
2895 and then
2896 Is_Tagged_Type
2897 (Designated_Type (F_Type))))
2898 and then Convention (E) = Convention_C
2899 then
2900 Error_Msg_N
2901 ("?x?& involves a tagged type which does not "
2902 & "correspond to any C type!", Formal);
2904 -- Check wrong convention subprogram pointer
2906 elsif Ekind (F_Type) = E_Access_Subprogram_Type
2907 and then not Has_Foreign_Convention (F_Type)
2908 then
2909 Error_Msg_N
2910 ("?x?subprogram pointer & should "
2911 & "have foreign convention!", Formal);
2912 Error_Msg_Sloc := Sloc (F_Type);
2913 Error_Msg_NE
2914 ("\?x?add Convention pragma to declaration of &#",
2915 Formal, F_Type);
2916 end if;
2918 -- Turn off name qualification after message output
2920 Error_Msg_Qual_Level := 0;
2921 end if;
2923 -- Check for unconstrained array in exported foreign
2924 -- convention case.
2926 if Has_Foreign_Convention (E)
2927 and then not Is_Imported (E)
2928 and then Is_Array_Type (F_Type)
2929 and then not Is_Constrained (F_Type)
2930 and then Warn_On_Export_Import
2932 -- Exclude VM case, since both .NET and JVM can handle
2933 -- unconstrained arrays without a problem.
2935 and then VM_Target = No_VM
2936 then
2937 Error_Msg_Qual_Level := 1;
2939 -- If this is an inherited operation, place the
2940 -- warning on the derived type declaration, rather
2941 -- than on the original subprogram.
2943 if Nkind (Original_Node (Parent (E))) =
2944 N_Full_Type_Declaration
2945 then
2946 Warn_Node := Parent (E);
2948 if Formal = First_Formal (E) then
2949 Error_Msg_NE
2950 ("??in inherited operation&", Warn_Node, E);
2951 end if;
2952 else
2953 Warn_Node := Formal;
2954 end if;
2956 Error_Msg_NE
2957 ("?x?type of argument& is unconstrained array",
2958 Warn_Node, Formal);
2959 Error_Msg_NE
2960 ("?x?foreign caller must pass bounds explicitly",
2961 Warn_Node, Formal);
2962 Error_Msg_Qual_Level := 0;
2963 end if;
2965 if not From_With_Type (F_Type) then
2966 if Is_Access_Type (F_Type) then
2967 F_Type := Designated_Type (F_Type);
2968 end if;
2970 -- If the formal is an anonymous_access_to_subprogram
2971 -- freeze the subprogram type as well, to prevent
2972 -- scope anomalies in gigi, because there is no other
2973 -- clear point at which it could be frozen.
2975 if Is_Itype (Etype (Formal))
2976 and then Ekind (F_Type) = E_Subprogram_Type
2977 then
2978 Freeze_And_Append (F_Type, N, Result);
2979 end if;
2980 end if;
2982 Next_Formal (Formal);
2983 end loop;
2985 -- Case of function: similar checks on return type
2987 if Ekind (E) = E_Function then
2989 -- Freeze return type
2991 R_Type := Etype (E);
2993 -- AI05-0151: the return type may have been incomplete
2994 -- at the point of declaration.
2996 if Ekind (R_Type) = E_Incomplete_Type
2997 and then Present (Full_View (R_Type))
2998 then
2999 R_Type := Full_View (R_Type);
3000 Set_Etype (E, R_Type);
3001 end if;
3003 Freeze_And_Append (R_Type, N, Result);
3005 -- Check suspicious return type for C function
3007 if Warn_On_Export_Import
3008 and then (Convention (E) = Convention_C
3009 or else
3010 Convention (E) = Convention_CPP)
3011 and then (Is_Imported (E) or else Is_Exported (E))
3012 then
3013 -- Check suspicious return of fat C pointer
3015 if Is_Access_Type (R_Type)
3016 and then Esize (R_Type) > Ttypes.System_Address_Size
3017 and then not Has_Warnings_Off (E)
3018 and then not Has_Warnings_Off (R_Type)
3019 then
3020 Error_Msg_N
3021 ("?x?return type of& does not "
3022 & "correspond to C pointer!", E);
3024 -- Check suspicious return of boolean
3026 elsif Root_Type (R_Type) = Standard_Boolean
3027 and then Convention (R_Type) = Convention_Ada
3028 and then VM_Target = No_VM
3029 and then not Has_Warnings_Off (E)
3030 and then not Has_Warnings_Off (R_Type)
3031 and then not Has_Size_Clause (R_Type)
3032 then
3033 declare
3034 N : constant Node_Id :=
3035 Result_Definition (Declaration_Node (E));
3036 begin
3037 Error_Msg_NE
3038 ("return type of & is an 8-bit Ada Boolean?x?",
3039 N, E);
3040 Error_Msg_NE
3041 ("\use appropriate corresponding type in C "
3042 & "(e.g. char)?x?", N, E);
3043 end;
3045 -- Check suspicious return tagged type
3047 elsif (Is_Tagged_Type (R_Type)
3048 or else (Is_Access_Type (R_Type)
3049 and then
3050 Is_Tagged_Type
3051 (Designated_Type (R_Type))))
3052 and then Convention (E) = Convention_C
3053 and then not Has_Warnings_Off (E)
3054 and then not Has_Warnings_Off (R_Type)
3055 then
3056 Error_Msg_N
3057 ("?x?return type of & does not "
3058 & "correspond to C type!", E);
3060 -- Check return of wrong convention subprogram pointer
3062 elsif Ekind (R_Type) = E_Access_Subprogram_Type
3063 and then not Has_Foreign_Convention (R_Type)
3064 and then not Has_Warnings_Off (E)
3065 and then not Has_Warnings_Off (R_Type)
3066 then
3067 Error_Msg_N
3068 ("?x?& should return a foreign "
3069 & "convention subprogram pointer", E);
3070 Error_Msg_Sloc := Sloc (R_Type);
3071 Error_Msg_NE
3072 ("\?x?add Convention pragma to declaration of& #",
3073 E, R_Type);
3074 end if;
3075 end if;
3077 -- Give warning for suspicious return of a result of an
3078 -- unconstrained array type in a foreign convention
3079 -- function.
3081 if Has_Foreign_Convention (E)
3083 -- We are looking for a return of unconstrained array
3085 and then Is_Array_Type (R_Type)
3086 and then not Is_Constrained (R_Type)
3088 -- Exclude imported routines, the warning does not
3089 -- belong on the import, but rather on the routine
3090 -- definition.
3092 and then not Is_Imported (E)
3094 -- Exclude VM case, since both .NET and JVM can handle
3095 -- return of unconstrained arrays without a problem.
3097 and then VM_Target = No_VM
3099 -- Check that general warning is enabled, and that it
3100 -- is not suppressed for this particular case.
3102 and then Warn_On_Export_Import
3103 and then not Has_Warnings_Off (E)
3104 and then not Has_Warnings_Off (R_Type)
3105 then
3106 Error_Msg_N
3107 ("?x?foreign convention function& should not " &
3108 "return unconstrained array!", E);
3109 end if;
3110 end if;
3111 end;
3113 -- Pre/post conditions are implemented through a subprogram in
3114 -- the corresponding body, and therefore are not checked on an
3115 -- imported subprogram for which the body is not available.
3117 -- Could consider generating a wrapper to take care of this???
3119 if Is_Subprogram (E)
3120 and then Is_Imported (E)
3121 and then Present (Contract (E))
3122 and then Present (Pre_Post_Conditions (Contract (E)))
3123 then
3124 Error_Msg_NE
3125 ("pre/post conditions on imported subprogram are not "
3126 & "enforced??", E, Pre_Post_Conditions (Contract (E)));
3127 end if;
3129 end if;
3131 -- Must freeze its parent first if it is a derived subprogram
3133 if Present (Alias (E)) then
3134 Freeze_And_Append (Alias (E), N, Result);
3135 end if;
3137 -- We don't freeze internal subprograms, because we don't normally
3138 -- want addition of extra formals or mechanism setting to happen
3139 -- for those. However we do pass through predefined dispatching
3140 -- cases, since extra formals may be needed in some cases, such as
3141 -- for the stream 'Input function (build-in-place formals).
3143 if not Is_Internal (E)
3144 or else Is_Predefined_Dispatching_Operation (E)
3145 then
3146 Freeze_Subprogram (E);
3147 end if;
3149 -- Here for other than a subprogram or type
3151 else
3152 -- If entity has a type, and it is not a generic unit, then
3153 -- freeze it first (RM 13.14(10)).
3155 if Present (Etype (E))
3156 and then Ekind (E) /= E_Generic_Function
3157 then
3158 Freeze_And_Append (Etype (E), N, Result);
3159 end if;
3161 -- Special processing for objects created by object declaration
3163 if Nkind (Declaration_Node (E)) = N_Object_Declaration then
3165 -- Abstract type allowed only for C++ imported variables or
3166 -- constants.
3168 -- Note: we inhibit this check for objects that do not come
3169 -- from source because there is at least one case (the
3170 -- expansion of x'Class'Input where x is abstract) where we
3171 -- legitimately generate an abstract object.
3173 if Is_Abstract_Type (Etype (E))
3174 and then Comes_From_Source (Parent (E))
3175 and then not (Is_Imported (E)
3176 and then Is_CPP_Class (Etype (E)))
3177 then
3178 Error_Msg_N ("type of object cannot be abstract",
3179 Object_Definition (Parent (E)));
3181 if Is_CPP_Class (Etype (E)) then
3182 Error_Msg_NE
3183 ("\} may need a cpp_constructor",
3184 Object_Definition (Parent (E)), Etype (E));
3185 end if;
3186 end if;
3188 -- For object created by object declaration, perform required
3189 -- categorization (preelaborate and pure) checks. Defer these
3190 -- checks to freeze time since pragma Import inhibits default
3191 -- initialization and thus pragma Import affects these checks.
3193 Validate_Object_Declaration (Declaration_Node (E));
3195 -- If there is an address clause, check that it is valid
3197 Check_Address_Clause (E);
3199 -- If the object needs any kind of default initialization, an
3200 -- error must be issued if No_Default_Initialization applies.
3201 -- The check doesn't apply to imported objects, which are not
3202 -- ever default initialized, and is why the check is deferred
3203 -- until freezing, at which point we know if Import applies.
3204 -- Deferred constants are also exempted from this test because
3205 -- their completion is explicit, or through an import pragma.
3207 if Ekind (E) = E_Constant
3208 and then Present (Full_View (E))
3209 then
3210 null;
3212 elsif Comes_From_Source (E)
3213 and then not Is_Imported (E)
3214 and then not Has_Init_Expression (Declaration_Node (E))
3215 and then
3216 ((Has_Non_Null_Base_Init_Proc (Etype (E))
3217 and then not No_Initialization (Declaration_Node (E))
3218 and then not Is_Value_Type (Etype (E))
3219 and then not Initialization_Suppressed (Etype (E)))
3220 or else
3221 (Needs_Simple_Initialization (Etype (E))
3222 and then not Is_Internal (E)))
3223 then
3224 Has_Default_Initialization := True;
3225 Check_Restriction
3226 (No_Default_Initialization, Declaration_Node (E));
3227 end if;
3229 -- Check that a Thread_Local_Storage variable does not have
3230 -- default initialization, and any explicit initialization must
3231 -- either be the null constant or a static constant.
3233 if Has_Pragma_Thread_Local_Storage (E) then
3234 declare
3235 Decl : constant Node_Id := Declaration_Node (E);
3236 begin
3237 if Has_Default_Initialization
3238 or else
3239 (Has_Init_Expression (Decl)
3240 and then
3241 (No (Expression (Decl))
3242 or else not
3243 (Is_Static_Expression (Expression (Decl))
3244 or else
3245 Nkind (Expression (Decl)) = N_Null)))
3246 then
3247 Error_Msg_NE
3248 ("Thread_Local_Storage variable& is "
3249 & "improperly initialized", Decl, E);
3250 Error_Msg_NE
3251 ("\only allowed initialization is explicit "
3252 & "NULL or static expression", Decl, E);
3253 end if;
3254 end;
3255 end if;
3257 -- For imported objects, set Is_Public unless there is also an
3258 -- address clause, which means that there is no external symbol
3259 -- needed for the Import (Is_Public may still be set for other
3260 -- unrelated reasons). Note that we delayed this processing
3261 -- till freeze time so that we can be sure not to set the flag
3262 -- if there is an address clause. If there is such a clause,
3263 -- then the only purpose of the Import pragma is to suppress
3264 -- implicit initialization.
3266 if Is_Imported (E)
3267 and then No (Address_Clause (E))
3268 then
3269 Set_Is_Public (E);
3270 end if;
3272 -- For convention C objects of an enumeration type, warn if
3273 -- the size is not integer size and no explicit size given.
3274 -- Skip warning for Boolean, and Character, assume programmer
3275 -- expects 8-bit sizes for these cases.
3277 if (Convention (E) = Convention_C
3278 or else
3279 Convention (E) = Convention_CPP)
3280 and then Is_Enumeration_Type (Etype (E))
3281 and then not Is_Character_Type (Etype (E))
3282 and then not Is_Boolean_Type (Etype (E))
3283 and then Esize (Etype (E)) < Standard_Integer_Size
3284 and then not Has_Size_Clause (E)
3285 then
3286 Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size);
3287 Error_Msg_N
3288 ("??convention C enumeration object has size less than ^",
3290 Error_Msg_N ("\?use explicit size clause to set size", E);
3291 end if;
3292 end if;
3294 -- Check that a constant which has a pragma Volatile[_Components]
3295 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
3297 -- Note: Atomic[_Components] also sets Volatile[_Components]
3299 if Ekind (E) = E_Constant
3300 and then (Has_Volatile_Components (E) or else Is_Volatile (E))
3301 and then not Is_Imported (E)
3302 then
3303 -- Make sure we actually have a pragma, and have not merely
3304 -- inherited the indication from elsewhere (e.g. an address
3305 -- clause, which is not good enough in RM terms!)
3307 if Has_Rep_Pragma (E, Name_Atomic)
3308 or else
3309 Has_Rep_Pragma (E, Name_Atomic_Components)
3310 then
3311 Error_Msg_N
3312 ("stand alone atomic constant must be " &
3313 "imported (RM C.6(13))", E);
3315 elsif Has_Rep_Pragma (E, Name_Volatile)
3316 or else
3317 Has_Rep_Pragma (E, Name_Volatile_Components)
3318 then
3319 Error_Msg_N
3320 ("stand alone volatile constant must be " &
3321 "imported (RM C.6(13))", E);
3322 end if;
3323 end if;
3325 -- Static objects require special handling
3327 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
3328 and then Is_Statically_Allocated (E)
3329 then
3330 Freeze_Static_Object (E);
3331 end if;
3333 -- Remaining step is to layout objects
3335 if Ekind (E) = E_Variable
3336 or else
3337 Ekind (E) = E_Constant
3338 or else
3339 Ekind (E) = E_Loop_Parameter
3340 or else
3341 Is_Formal (E)
3342 then
3343 Layout_Object (E);
3344 end if;
3346 -- If initialization statements were captured in an expression
3347 -- with actions with null expression, and the object does not
3348 -- have delayed freezing, move them back now directly within the
3349 -- enclosing statement sequence.
3351 if Ekind_In (E, E_Constant, E_Variable)
3352 and then not Has_Delayed_Freeze (E)
3353 then
3354 declare
3355 Init_Stmts : constant Node_Id :=
3356 Initialization_Statements (E);
3357 begin
3358 if Present (Init_Stmts)
3359 and then Nkind (Init_Stmts) = N_Expression_With_Actions
3360 and then Nkind (Expression (Init_Stmts)) = N_Null_Statement
3361 then
3362 Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
3363 Remove (Init_Stmts);
3364 Set_Initialization_Statements (E, Empty);
3365 end if;
3366 end;
3367 end if;
3369 end if;
3371 -- Case of a type or subtype being frozen
3373 else
3374 -- We used to check here that a full type must have preelaborable
3375 -- initialization if it completes a private type specified with
3376 -- pragma Preelaborable_Initialization, but that missed cases where
3377 -- the types occur within a generic package, since the freezing
3378 -- that occurs within a containing scope generally skips traversal
3379 -- of a generic unit's declarations (those will be frozen within
3380 -- instances). This check was moved to Analyze_Package_Specification.
3382 -- The type may be defined in a generic unit. This can occur when
3383 -- freezing a generic function that returns the type (which is
3384 -- defined in a parent unit). It is clearly meaningless to freeze
3385 -- this type. However, if it is a subtype, its size may be determi-
3386 -- nable and used in subsequent checks, so might as well try to
3387 -- compute it.
3389 -- In Ada 2012, Freeze_Entities is also used in the front end to
3390 -- trigger the analysis of aspect expressions, so in this case we
3391 -- want to continue the freezing process.
3393 if Present (Scope (E))
3394 and then Is_Generic_Unit (Scope (E))
3395 and then not Has_Predicates (E)
3396 then
3397 Check_Compile_Time_Size (E);
3398 return No_List;
3399 end if;
3401 -- Deal with special cases of freezing for subtype
3403 if E /= Base_Type (E) then
3405 -- Before we do anything else, a specialized test for the case of
3406 -- a size given for an array where the array needs to be packed,
3407 -- but was not so the size cannot be honored. This would of course
3408 -- be caught by the backend, and indeed we don't catch all cases.
3409 -- The point is that we can give a better error message in those
3410 -- cases that we do catch with the circuitry here. Also if pragma
3411 -- Implicit_Packing is set, this is where the packing occurs.
3413 -- The reason we do this so early is that the processing in the
3414 -- automatic packing case affects the layout of the base type, so
3415 -- it must be done before we freeze the base type.
3417 if Is_Array_Type (E) then
3418 declare
3419 Lo, Hi : Node_Id;
3420 Ctyp : constant Entity_Id := Component_Type (E);
3422 begin
3423 -- Check enabling conditions. These are straightforward
3424 -- except for the test for a limited composite type. This
3425 -- eliminates the rare case of a array of limited components
3426 -- where there are issues of whether or not we can go ahead
3427 -- and pack the array (since we can't freely pack and unpack
3428 -- arrays if they are limited).
3430 -- Note that we check the root type explicitly because the
3431 -- whole point is we are doing this test before we have had
3432 -- a chance to freeze the base type (and it is that freeze
3433 -- action that causes stuff to be inherited).
3435 if Present (Size_Clause (E))
3436 and then Known_Static_RM_Size (E)
3437 and then not Is_Packed (E)
3438 and then not Has_Pragma_Pack (E)
3439 and then Number_Dimensions (E) = 1
3440 and then not Has_Component_Size_Clause (E)
3441 and then Known_Static_RM_Size (Ctyp)
3442 and then not Is_Limited_Composite (E)
3443 and then not Is_Packed (Root_Type (E))
3444 and then not Has_Component_Size_Clause (Root_Type (E))
3445 and then not (CodePeer_Mode or SPARK_Mode)
3446 then
3447 Get_Index_Bounds (First_Index (E), Lo, Hi);
3449 if Compile_Time_Known_Value (Lo)
3450 and then Compile_Time_Known_Value (Hi)
3451 and then Known_Static_RM_Size (Ctyp)
3452 and then RM_Size (Ctyp) < 64
3453 then
3454 declare
3455 Lov : constant Uint := Expr_Value (Lo);
3456 Hiv : constant Uint := Expr_Value (Hi);
3457 Len : constant Uint := UI_Max
3458 (Uint_0,
3459 Hiv - Lov + 1);
3460 Rsiz : constant Uint := RM_Size (Ctyp);
3461 SZ : constant Node_Id := Size_Clause (E);
3462 Btyp : constant Entity_Id := Base_Type (E);
3464 -- What we are looking for here is the situation where
3465 -- the RM_Size given would be exactly right if there
3466 -- was a pragma Pack (resulting in the component size
3467 -- being the same as the RM_Size). Furthermore, the
3468 -- component type size must be an odd size (not a
3469 -- multiple of storage unit). If the component RM size
3470 -- is an exact number of storage units that is a power
3471 -- of two, the array is not packed and has a standard
3472 -- representation.
3474 begin
3475 if RM_Size (E) = Len * Rsiz
3476 and then Rsiz mod System_Storage_Unit /= 0
3477 then
3478 -- For implicit packing mode, just set the
3479 -- component size silently.
3481 if Implicit_Packing then
3482 Set_Component_Size (Btyp, Rsiz);
3483 Set_Is_Bit_Packed_Array (Btyp);
3484 Set_Is_Packed (Btyp);
3485 Set_Has_Non_Standard_Rep (Btyp);
3487 -- Otherwise give an error message
3489 else
3490 Error_Msg_NE
3491 ("size given for& too small", SZ, E);
3492 Error_Msg_N -- CODEFIX
3493 ("\use explicit pragma Pack "
3494 & "or use pragma Implicit_Packing", SZ);
3495 end if;
3497 elsif RM_Size (E) = Len * Rsiz
3498 and then Implicit_Packing
3499 and then
3500 (Rsiz / System_Storage_Unit = 1
3501 or else Rsiz / System_Storage_Unit = 2
3502 or else Rsiz / System_Storage_Unit = 4)
3503 then
3505 -- Not a packed array, but indicate the desired
3506 -- component size, for the back-end.
3508 Set_Component_Size (Btyp, Rsiz);
3509 end if;
3510 end;
3511 end if;
3512 end if;
3513 end;
3514 end if;
3516 -- If ancestor subtype present, freeze that first. Note that this
3517 -- will also get the base type frozen. Need RM reference ???
3519 Atype := Ancestor_Subtype (E);
3521 if Present (Atype) then
3522 Freeze_And_Append (Atype, N, Result);
3524 -- No ancestor subtype present
3526 else
3527 -- See if we have a nearest ancestor that has a predicate.
3528 -- That catches the case of derived type with a predicate.
3529 -- Need RM reference here ???
3531 Atype := Nearest_Ancestor (E);
3533 if Present (Atype) and then Has_Predicates (Atype) then
3534 Freeze_And_Append (Atype, N, Result);
3535 end if;
3537 -- Freeze base type before freezing the entity (RM 13.14(15))
3539 if E /= Base_Type (E) then
3540 Freeze_And_Append (Base_Type (E), N, Result);
3541 end if;
3542 end if;
3544 -- A subtype inherits all the type-related representation aspects
3545 -- from its parents (RM 13.1(8)).
3547 Inherit_Aspects_At_Freeze_Point (E);
3549 -- For a derived type, freeze its parent type first (RM 13.14(15))
3551 elsif Is_Derived_Type (E) then
3552 Freeze_And_Append (Etype (E), N, Result);
3553 Freeze_And_Append (First_Subtype (Etype (E)), N, Result);
3555 -- A derived type inherits each type-related representation aspect
3556 -- of its parent type that was directly specified before the
3557 -- declaration of the derived type (RM 13.1(15)).
3559 Inherit_Aspects_At_Freeze_Point (E);
3560 end if;
3562 -- For array type, freeze index types and component type first
3563 -- before freezing the array (RM 13.14(15)).
3565 if Is_Array_Type (E) then
3566 declare
3567 FS : constant Entity_Id := First_Subtype (E);
3568 Ctyp : constant Entity_Id := Component_Type (E);
3569 Clause : Entity_Id;
3571 Non_Standard_Enum : Boolean := False;
3572 -- Set true if any of the index types is an enumeration type
3573 -- with a non-standard representation.
3575 begin
3576 Freeze_And_Append (Ctyp, N, Result);
3578 Indx := First_Index (E);
3579 while Present (Indx) loop
3580 Freeze_And_Append (Etype (Indx), N, Result);
3582 if Is_Enumeration_Type (Etype (Indx))
3583 and then Has_Non_Standard_Rep (Etype (Indx))
3584 then
3585 Non_Standard_Enum := True;
3586 end if;
3588 Next_Index (Indx);
3589 end loop;
3591 -- Processing that is done only for base types
3593 if Ekind (E) = E_Array_Type then
3595 -- Propagate flags for component type
3597 if Is_Controlled (Component_Type (E))
3598 or else Has_Controlled_Component (Ctyp)
3599 then
3600 Set_Has_Controlled_Component (E);
3601 end if;
3603 if Has_Unchecked_Union (Component_Type (E)) then
3604 Set_Has_Unchecked_Union (E);
3605 end if;
3607 -- If packing was requested or if the component size was set
3608 -- explicitly, then see if bit packing is required. This
3609 -- processing is only done for base types, since all the
3610 -- representation aspects involved are type-related. This
3611 -- is not just an optimization, if we start processing the
3612 -- subtypes, they interfere with the settings on the base
3613 -- type (this is because Is_Packed has a slightly different
3614 -- meaning before and after freezing).
3616 declare
3617 Csiz : Uint;
3618 Esiz : Uint;
3620 begin
3621 if (Is_Packed (E) or else Has_Pragma_Pack (E))
3622 and then Known_Static_RM_Size (Ctyp)
3623 and then not Has_Component_Size_Clause (E)
3624 then
3625 Csiz := UI_Max (RM_Size (Ctyp), 1);
3627 elsif Known_Component_Size (E) then
3628 Csiz := Component_Size (E);
3630 elsif not Known_Static_Esize (Ctyp) then
3631 Csiz := Uint_0;
3633 else
3634 Esiz := Esize (Ctyp);
3636 -- We can set the component size if it is less than
3637 -- 16, rounding it up to the next storage unit size.
3639 if Esiz <= 8 then
3640 Csiz := Uint_8;
3641 elsif Esiz <= 16 then
3642 Csiz := Uint_16;
3643 else
3644 Csiz := Uint_0;
3645 end if;
3647 -- Set component size up to match alignment if it
3648 -- would otherwise be less than the alignment. This
3649 -- deals with cases of types whose alignment exceeds
3650 -- their size (padded types).
3652 if Csiz /= 0 then
3653 declare
3654 A : constant Uint := Alignment_In_Bits (Ctyp);
3655 begin
3656 if Csiz < A then
3657 Csiz := A;
3658 end if;
3659 end;
3660 end if;
3661 end if;
3663 -- Case of component size that may result in packing
3665 if 1 <= Csiz and then Csiz <= 64 then
3666 declare
3667 Ent : constant Entity_Id :=
3668 First_Subtype (E);
3669 Pack_Pragma : constant Node_Id :=
3670 Get_Rep_Pragma (Ent, Name_Pack);
3671 Comp_Size_C : constant Node_Id :=
3672 Get_Attribute_Definition_Clause
3673 (Ent, Attribute_Component_Size);
3674 begin
3675 -- Warn if we have pack and component size so that
3676 -- the pack is ignored.
3678 -- Note: here we must check for the presence of a
3679 -- component size before checking for a Pack pragma
3680 -- to deal with the case where the array type is a
3681 -- derived type whose parent is currently private.
3683 if Present (Comp_Size_C)
3684 and then Has_Pragma_Pack (Ent)
3685 and then Warn_On_Redundant_Constructs
3686 then
3687 Error_Msg_Sloc := Sloc (Comp_Size_C);
3688 Error_Msg_NE
3689 ("?r?pragma Pack for& ignored!",
3690 Pack_Pragma, Ent);
3691 Error_Msg_N
3692 ("\?r?explicit component size given#!",
3693 Pack_Pragma);
3694 Set_Is_Packed (Base_Type (Ent), False);
3695 Set_Is_Bit_Packed_Array (Base_Type (Ent), False);
3696 end if;
3698 -- Set component size if not already set by a
3699 -- component size clause.
3701 if not Present (Comp_Size_C) then
3702 Set_Component_Size (E, Csiz);
3703 end if;
3705 -- Check for base type of 8, 16, 32 bits, where an
3706 -- unsigned subtype has a length one less than the
3707 -- base type (e.g. Natural subtype of Integer).
3709 -- In such cases, if a component size was not set
3710 -- explicitly, then generate a warning.
3712 if Has_Pragma_Pack (E)
3713 and then not Present (Comp_Size_C)
3714 and then
3715 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
3716 and then Esize (Base_Type (Ctyp)) = Csiz + 1
3717 then
3718 Error_Msg_Uint_1 := Csiz;
3720 if Present (Pack_Pragma) then
3721 Error_Msg_N
3722 ("??pragma Pack causes component size "
3723 & "to be ^!", Pack_Pragma);
3724 Error_Msg_N
3725 ("\??use Component_Size to set "
3726 & "desired value!", Pack_Pragma);
3727 end if;
3728 end if;
3730 -- Actual packing is not needed for 8, 16, 32, 64.
3731 -- Also not needed for 24 if alignment is 1.
3733 if Csiz = 8
3734 or else Csiz = 16
3735 or else Csiz = 32
3736 or else Csiz = 64
3737 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
3738 then
3739 -- Here the array was requested to be packed,
3740 -- but the packing request had no effect, so
3741 -- Is_Packed is reset.
3743 -- Note: semantically this means that we lose
3744 -- track of the fact that a derived type
3745 -- inherited a pragma Pack that was non-
3746 -- effective, but that seems fine.
3748 -- We regard a Pack pragma as a request to set
3749 -- a representation characteristic, and this
3750 -- request may be ignored.
3752 Set_Is_Packed (Base_Type (E), False);
3753 Set_Is_Bit_Packed_Array (Base_Type (E), False);
3755 if Known_Static_Esize (Component_Type (E))
3756 and then Esize (Component_Type (E)) = Csiz
3757 then
3758 Set_Has_Non_Standard_Rep
3759 (Base_Type (E), False);
3760 end if;
3762 -- In all other cases, packing is indeed needed
3764 else
3765 Set_Has_Non_Standard_Rep (Base_Type (E), True);
3766 Set_Is_Bit_Packed_Array (Base_Type (E), True);
3767 Set_Is_Packed (Base_Type (E), True);
3768 end if;
3769 end;
3770 end if;
3771 end;
3773 -- Check for Atomic_Components or Aliased with unsuitable
3774 -- packing or explicit component size clause given.
3776 if (Has_Atomic_Components (E)
3777 or else Has_Aliased_Components (E))
3778 and then (Has_Component_Size_Clause (E)
3779 or else Is_Packed (E))
3780 then
3781 Alias_Atomic_Check : declare
3783 procedure Complain_CS (T : String);
3784 -- Outputs error messages for incorrect CS clause or
3785 -- pragma Pack for aliased or atomic components (T is
3786 -- "aliased" or "atomic");
3788 -----------------
3789 -- Complain_CS --
3790 -----------------
3792 procedure Complain_CS (T : String) is
3793 begin
3794 if Has_Component_Size_Clause (E) then
3795 Clause :=
3796 Get_Attribute_Definition_Clause
3797 (FS, Attribute_Component_Size);
3799 if Known_Static_Esize (Ctyp) then
3800 Error_Msg_N
3801 ("incorrect component size for "
3802 & T & " components", Clause);
3803 Error_Msg_Uint_1 := Esize (Ctyp);
3804 Error_Msg_N
3805 ("\only allowed value is^", Clause);
3807 else
3808 Error_Msg_N
3809 ("component size cannot be given for "
3810 & T & " components", Clause);
3811 end if;
3813 else
3814 Error_Msg_N
3815 ("cannot pack " & T & " components",
3816 Get_Rep_Pragma (FS, Name_Pack));
3817 end if;
3819 return;
3820 end Complain_CS;
3822 -- Start of processing for Alias_Atomic_Check
3824 begin
3826 -- If object size of component type isn't known, we
3827 -- cannot be sure so we defer to the back end.
3829 if not Known_Static_Esize (Ctyp) then
3830 null;
3832 -- Case where component size has no effect. First
3833 -- check for object size of component type multiple
3834 -- of the storage unit size.
3836 elsif Esize (Ctyp) mod System_Storage_Unit = 0
3838 -- OK in both packing case and component size case
3839 -- if RM size is known and static and the same as
3840 -- the object size.
3842 and then
3843 ((Known_Static_RM_Size (Ctyp)
3844 and then Esize (Ctyp) = RM_Size (Ctyp))
3846 -- Or if we have an explicit component size
3847 -- clause and the component size and object size
3848 -- are equal.
3850 or else
3851 (Has_Component_Size_Clause (E)
3852 and then Component_Size (E) = Esize (Ctyp)))
3853 then
3854 null;
3856 elsif Has_Aliased_Components (E)
3857 or else Is_Aliased (Ctyp)
3858 then
3859 Complain_CS ("aliased");
3861 elsif Has_Atomic_Components (E)
3862 or else Is_Atomic (Ctyp)
3863 then
3864 Complain_CS ("atomic");
3865 end if;
3866 end Alias_Atomic_Check;
3867 end if;
3869 -- Warn for case of atomic type
3871 Clause := Get_Rep_Pragma (FS, Name_Atomic);
3873 if Present (Clause)
3874 and then not Addressable (Component_Size (FS))
3875 then
3876 Error_Msg_NE
3877 ("non-atomic components of type& may not be "
3878 & "accessible by separate tasks??", Clause, E);
3880 if Has_Component_Size_Clause (E) then
3881 Error_Msg_Sloc :=
3882 Sloc
3883 (Get_Attribute_Definition_Clause
3884 (FS, Attribute_Component_Size));
3885 Error_Msg_N
3886 ("\because of component size clause#??",
3887 Clause);
3889 elsif Has_Pragma_Pack (E) then
3890 Error_Msg_Sloc :=
3891 Sloc (Get_Rep_Pragma (FS, Name_Pack));
3892 Error_Msg_N
3893 ("\because of pragma Pack#??", Clause);
3894 end if;
3895 end if;
3897 -- Check for scalar storage order
3899 if Present (Get_Attribute_Definition_Clause
3900 (E, Attribute_Scalar_Storage_Order))
3901 then
3902 Check_Component_Storage_Order (E, Empty);
3903 end if;
3905 -- Processing that is done only for subtypes
3907 else
3908 -- Acquire alignment from base type
3910 if Unknown_Alignment (E) then
3911 Set_Alignment (E, Alignment (Base_Type (E)));
3912 Adjust_Esize_Alignment (E);
3913 end if;
3914 end if;
3916 -- Specific checks for bit-packed arrays
3918 if Is_Bit_Packed_Array (E) then
3920 -- Check number of elements for bit packed arrays that come
3921 -- from source and have compile time known ranges. The
3922 -- bit-packed arrays circuitry does not support arrays
3923 -- with more than Integer'Last + 1 elements, and when this
3924 -- restriction is violated, causes incorrect data access.
3926 -- For the case where this is not compile time known, a
3927 -- run-time check should be generated???
3929 if Comes_From_Source (E) and then Is_Constrained (E) then
3930 declare
3931 Elmts : Uint;
3932 Index : Node_Id;
3933 Ilen : Node_Id;
3934 Ityp : Entity_Id;
3936 begin
3937 Elmts := Uint_1;
3938 Index := First_Index (E);
3939 while Present (Index) loop
3940 Ityp := Etype (Index);
3942 -- Never generate an error if any index is of a
3943 -- generic type. We will check this in instances.
3945 if Is_Generic_Type (Ityp) then
3946 Elmts := Uint_0;
3947 exit;
3948 end if;
3950 Ilen :=
3951 Make_Attribute_Reference (Loc,
3952 Prefix =>
3953 New_Occurrence_Of (Ityp, Loc),
3954 Attribute_Name => Name_Range_Length);
3955 Analyze_And_Resolve (Ilen);
3957 -- No attempt is made to check number of elements
3958 -- if not compile time known.
3960 if Nkind (Ilen) /= N_Integer_Literal then
3961 Elmts := Uint_0;
3962 exit;
3963 end if;
3965 Elmts := Elmts * Intval (Ilen);
3966 Next_Index (Index);
3967 end loop;
3969 if Elmts > Intval (High_Bound
3970 (Scalar_Range
3971 (Standard_Integer))) + 1
3972 then
3973 Error_Msg_N
3974 ("bit packed array type may not have "
3975 & "more than Integer''Last+1 elements", E);
3976 end if;
3977 end;
3978 end if;
3980 -- Check size
3982 if Known_RM_Size (E) then
3983 declare
3984 SizC : constant Node_Id := Size_Clause (E);
3986 Discard : Boolean;
3987 pragma Warnings (Off, Discard);
3989 begin
3990 -- It is not clear if it is possible to have no size
3991 -- clause at this stage, but it is not worth worrying
3992 -- about. Post error on the entity name in the size
3993 -- clause if present, else on the type entity itself.
3995 if Present (SizC) then
3996 Check_Size (Name (SizC), E, RM_Size (E), Discard);
3997 else
3998 Check_Size (E, E, RM_Size (E), Discard);
3999 end if;
4000 end;
4001 end if;
4002 end if;
4004 -- If any of the index types was an enumeration type with a
4005 -- non-standard rep clause, then we indicate that the array
4006 -- type is always packed (even if it is not bit packed).
4008 if Non_Standard_Enum then
4009 Set_Has_Non_Standard_Rep (Base_Type (E));
4010 Set_Is_Packed (Base_Type (E));
4011 end if;
4013 Set_Component_Alignment_If_Not_Set (E);
4015 -- If the array is packed, we must create the packed array
4016 -- type to be used to actually implement the type. This is
4017 -- only needed for real array types (not for string literal
4018 -- types, since they are present only for the front end).
4020 if Is_Packed (E)
4021 and then Ekind (E) /= E_String_Literal_Subtype
4022 then
4023 Create_Packed_Array_Type (E);
4024 Freeze_And_Append (Packed_Array_Type (E), N, Result);
4026 -- Size information of packed array type is copied to the
4027 -- array type, since this is really the representation. But
4028 -- do not override explicit existing size values. If the
4029 -- ancestor subtype is constrained the packed_array_type
4030 -- will be inherited from it, but the size may have been
4031 -- provided already, and must not be overridden either.
4033 if not Has_Size_Clause (E)
4034 and then
4035 (No (Ancestor_Subtype (E))
4036 or else not Has_Size_Clause (Ancestor_Subtype (E)))
4037 then
4038 Set_Esize (E, Esize (Packed_Array_Type (E)));
4039 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
4040 end if;
4042 if not Has_Alignment_Clause (E) then
4043 Set_Alignment (E, Alignment (Packed_Array_Type (E)));
4044 end if;
4045 end if;
4047 -- For non-packed arrays set the alignment of the array to the
4048 -- alignment of the component type if it is unknown. Skip this
4049 -- in atomic case (atomic arrays may need larger alignments).
4051 if not Is_Packed (E)
4052 and then Unknown_Alignment (E)
4053 and then Known_Alignment (Ctyp)
4054 and then Known_Static_Component_Size (E)
4055 and then Known_Static_Esize (Ctyp)
4056 and then Esize (Ctyp) = Component_Size (E)
4057 and then not Is_Atomic (E)
4058 then
4059 Set_Alignment (E, Alignment (Component_Type (E)));
4060 end if;
4061 end;
4063 -- For a class-wide type, the corresponding specific type is
4064 -- frozen as well (RM 13.14(15))
4066 elsif Is_Class_Wide_Type (E) then
4067 Freeze_And_Append (Root_Type (E), N, Result);
4069 -- If the base type of the class-wide type is still incomplete,
4070 -- the class-wide remains unfrozen as well. This is legal when
4071 -- E is the formal of a primitive operation of some other type
4072 -- which is being frozen.
4074 if not Is_Frozen (Root_Type (E)) then
4075 Set_Is_Frozen (E, False);
4076 return Result;
4077 end if;
4079 -- The equivalent type associated with a class-wide subtype needs
4080 -- to be frozen to ensure that its layout is done.
4082 if Ekind (E) = E_Class_Wide_Subtype
4083 and then Present (Equivalent_Type (E))
4084 then
4085 Freeze_And_Append (Equivalent_Type (E), N, Result);
4086 end if;
4088 -- Generate an itype reference for a library-level class-wide type
4089 -- at the freeze point. Otherwise the first explicit reference to
4090 -- the type may appear in an inner scope which will be rejected by
4091 -- the back-end.
4093 if Is_Itype (E)
4094 and then Is_Compilation_Unit (Scope (E))
4095 then
4096 declare
4097 Ref : constant Node_Id := Make_Itype_Reference (Loc);
4099 begin
4100 Set_Itype (Ref, E);
4102 -- From a gigi point of view, a class-wide subtype derives
4103 -- from its record equivalent type. As a result, the itype
4104 -- reference must appear after the freeze node of the
4105 -- equivalent type or gigi will reject the reference.
4107 if Ekind (E) = E_Class_Wide_Subtype
4108 and then Present (Equivalent_Type (E))
4109 then
4110 Insert_After (Freeze_Node (Equivalent_Type (E)), Ref);
4111 else
4112 Add_To_Result (Ref);
4113 end if;
4114 end;
4115 end if;
4117 -- For a record type or record subtype, freeze all component types
4118 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4119 -- using Is_Record_Type, because we don't want to attempt the freeze
4120 -- for the case of a private type with record extension (we will do
4121 -- that later when the full type is frozen).
4123 elsif Ekind_In (E, E_Record_Type, E_Record_Subtype) then
4124 Freeze_Record_Type (E);
4126 -- For a concurrent type, freeze corresponding record type. This
4127 -- does not correspond to any specific rule in the RM, but the
4128 -- record type is essentially part of the concurrent type.
4129 -- Freeze as well all local entities. This includes record types
4130 -- created for entry parameter blocks, and whatever local entities
4131 -- may appear in the private part.
4133 elsif Is_Concurrent_Type (E) then
4134 if Present (Corresponding_Record_Type (E)) then
4135 Freeze_And_Append
4136 (Corresponding_Record_Type (E), N, Result);
4137 end if;
4139 Comp := First_Entity (E);
4140 while Present (Comp) loop
4141 if Is_Type (Comp) then
4142 Freeze_And_Append (Comp, N, Result);
4144 elsif (Ekind (Comp)) /= E_Function then
4145 if Is_Itype (Etype (Comp))
4146 and then Underlying_Type (Scope (Etype (Comp))) = E
4147 then
4148 Undelay_Type (Etype (Comp));
4149 end if;
4151 Freeze_And_Append (Etype (Comp), N, Result);
4152 end if;
4154 Next_Entity (Comp);
4155 end loop;
4157 -- Private types are required to point to the same freeze node as
4158 -- their corresponding full views. The freeze node itself has to
4159 -- point to the partial view of the entity (because from the partial
4160 -- view, we can retrieve the full view, but not the reverse).
4161 -- However, in order to freeze correctly, we need to freeze the full
4162 -- view. If we are freezing at the end of a scope (or within the
4163 -- scope of the private type), the partial and full views will have
4164 -- been swapped, the full view appears first in the entity chain and
4165 -- the swapping mechanism ensures that the pointers are properly set
4166 -- (on scope exit).
4168 -- If we encounter the partial view before the full view (e.g. when
4169 -- freezing from another scope), we freeze the full view, and then
4170 -- set the pointers appropriately since we cannot rely on swapping to
4171 -- fix things up (subtypes in an outer scope might not get swapped).
4173 elsif Is_Incomplete_Or_Private_Type (E)
4174 and then not Is_Generic_Type (E)
4175 then
4176 -- The construction of the dispatch table associated with library
4177 -- level tagged types forces freezing of all the primitives of the
4178 -- type, which may cause premature freezing of the partial view.
4179 -- For example:
4181 -- package Pkg is
4182 -- type T is tagged private;
4183 -- type DT is new T with private;
4184 -- procedure Prim (X : in out T; Y : in out DT'Class);
4185 -- private
4186 -- type T is tagged null record;
4187 -- Obj : T;
4188 -- type DT is new T with null record;
4189 -- end;
4191 -- In this case the type will be frozen later by the usual
4192 -- mechanism: an object declaration, an instantiation, or the
4193 -- end of a declarative part.
4195 if Is_Library_Level_Tagged_Type (E)
4196 and then not Present (Full_View (E))
4197 then
4198 Set_Is_Frozen (E, False);
4199 return Result;
4201 -- Case of full view present
4203 elsif Present (Full_View (E)) then
4205 -- If full view has already been frozen, then no further
4206 -- processing is required
4208 if Is_Frozen (Full_View (E)) then
4209 Set_Has_Delayed_Freeze (E, False);
4210 Set_Freeze_Node (E, Empty);
4211 Check_Debug_Info_Needed (E);
4213 -- Otherwise freeze full view and patch the pointers so that
4214 -- the freeze node will elaborate both views in the back-end.
4216 else
4217 declare
4218 Full : constant Entity_Id := Full_View (E);
4220 begin
4221 if Is_Private_Type (Full)
4222 and then Present (Underlying_Full_View (Full))
4223 then
4224 Freeze_And_Append
4225 (Underlying_Full_View (Full), N, Result);
4226 end if;
4228 Freeze_And_Append (Full, N, Result);
4230 if Has_Delayed_Freeze (E) then
4231 F_Node := Freeze_Node (Full);
4233 if Present (F_Node) then
4234 Set_Freeze_Node (E, F_Node);
4235 Set_Entity (F_Node, E);
4237 else
4238 -- {Incomplete,Private}_Subtypes with Full_Views
4239 -- constrained by discriminants.
4241 Set_Has_Delayed_Freeze (E, False);
4242 Set_Freeze_Node (E, Empty);
4243 end if;
4244 end if;
4245 end;
4247 Check_Debug_Info_Needed (E);
4248 end if;
4250 -- AI-117 requires that the convention of a partial view be the
4251 -- same as the convention of the full view. Note that this is a
4252 -- recognized breach of privacy, but it's essential for logical
4253 -- consistency of representation, and the lack of a rule in
4254 -- RM95 was an oversight.
4256 Set_Convention (E, Convention (Full_View (E)));
4258 Set_Size_Known_At_Compile_Time (E,
4259 Size_Known_At_Compile_Time (Full_View (E)));
4261 -- Size information is copied from the full view to the
4262 -- incomplete or private view for consistency.
4264 -- We skip this is the full view is not a type. This is very
4265 -- strange of course, and can only happen as a result of
4266 -- certain illegalities, such as a premature attempt to derive
4267 -- from an incomplete type.
4269 if Is_Type (Full_View (E)) then
4270 Set_Size_Info (E, Full_View (E));
4271 Set_RM_Size (E, RM_Size (Full_View (E)));
4272 end if;
4274 return Result;
4276 -- Case of no full view present. If entity is derived or subtype,
4277 -- it is safe to freeze, correctness depends on the frozen status
4278 -- of parent. Otherwise it is either premature usage, or a Taft
4279 -- amendment type, so diagnosis is at the point of use and the
4280 -- type might be frozen later.
4282 elsif E /= Base_Type (E)
4283 or else Is_Derived_Type (E)
4284 then
4285 null;
4287 else
4288 Set_Is_Frozen (E, False);
4289 return No_List;
4290 end if;
4292 -- For access subprogram, freeze types of all formals, the return
4293 -- type was already frozen, since it is the Etype of the function.
4294 -- Formal types can be tagged Taft amendment types, but otherwise
4295 -- they cannot be incomplete.
4297 elsif Ekind (E) = E_Subprogram_Type then
4298 Formal := First_Formal (E);
4299 while Present (Formal) loop
4300 if Ekind (Etype (Formal)) = E_Incomplete_Type
4301 and then No (Full_View (Etype (Formal)))
4302 and then not Is_Value_Type (Etype (Formal))
4303 then
4304 if Is_Tagged_Type (Etype (Formal)) then
4305 null;
4307 -- AI05-151: Incomplete types are allowed in access to
4308 -- subprogram specifications.
4310 elsif Ada_Version < Ada_2012 then
4311 Error_Msg_NE
4312 ("invalid use of incomplete type&", E, Etype (Formal));
4313 end if;
4314 end if;
4316 Freeze_And_Append (Etype (Formal), N, Result);
4317 Next_Formal (Formal);
4318 end loop;
4320 Freeze_Subprogram (E);
4322 -- For access to a protected subprogram, freeze the equivalent type
4323 -- (however this is not set if we are not generating code or if this
4324 -- is an anonymous type used just for resolution).
4326 elsif Is_Access_Protected_Subprogram_Type (E) then
4327 if Present (Equivalent_Type (E)) then
4328 Freeze_And_Append (Equivalent_Type (E), N, Result);
4329 end if;
4330 end if;
4332 -- Generic types are never seen by the back-end, and are also not
4333 -- processed by the expander (since the expander is turned off for
4334 -- generic processing), so we never need freeze nodes for them.
4336 if Is_Generic_Type (E) then
4337 return Result;
4338 end if;
4340 -- Some special processing for non-generic types to complete
4341 -- representation details not known till the freeze point.
4343 if Is_Fixed_Point_Type (E) then
4344 Freeze_Fixed_Point_Type (E);
4346 -- Some error checks required for ordinary fixed-point type. Defer
4347 -- these till the freeze-point since we need the small and range
4348 -- values. We only do these checks for base types
4350 if Is_Ordinary_Fixed_Point_Type (E) and then Is_Base_Type (E) then
4351 if Small_Value (E) < Ureal_2_M_80 then
4352 Error_Msg_Name_1 := Name_Small;
4353 Error_Msg_N
4354 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E);
4356 elsif Small_Value (E) > Ureal_2_80 then
4357 Error_Msg_Name_1 := Name_Small;
4358 Error_Msg_N
4359 ("`&''%` too large, maximum allowed is 2.0'*'*80", E);
4360 end if;
4362 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
4363 Error_Msg_Name_1 := Name_First;
4364 Error_Msg_N
4365 ("`&''%` too small, minimum allowed is -10.0'*'*36", E);
4366 end if;
4368 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
4369 Error_Msg_Name_1 := Name_Last;
4370 Error_Msg_N
4371 ("`&''%` too large, maximum allowed is 10.0'*'*36", E);
4372 end if;
4373 end if;
4375 elsif Is_Enumeration_Type (E) then
4376 Freeze_Enumeration_Type (E);
4378 elsif Is_Integer_Type (E) then
4379 Adjust_Esize_For_Alignment (E);
4381 if Is_Modular_Integer_Type (E)
4382 and then Warn_On_Suspicious_Modulus_Value
4383 then
4384 Check_Suspicious_Modulus (E);
4385 end if;
4387 elsif Is_Access_Type (E)
4388 and then not Is_Access_Subprogram_Type (E)
4389 then
4390 -- If a pragma Default_Storage_Pool applies, and this type has no
4391 -- Storage_Pool or Storage_Size clause (which must have occurred
4392 -- before the freezing point), then use the default. This applies
4393 -- only to base types.
4395 -- None of this applies to access to subprograms, for which there
4396 -- are clearly no pools.
4398 if Present (Default_Pool)
4399 and then Is_Base_Type (E)
4400 and then not Has_Storage_Size_Clause (E)
4401 and then No (Associated_Storage_Pool (E))
4402 then
4403 -- Case of pragma Default_Storage_Pool (null)
4405 if Nkind (Default_Pool) = N_Null then
4406 Set_No_Pool_Assigned (E);
4408 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4410 else
4411 Set_Associated_Storage_Pool (E, Entity (Default_Pool));
4412 end if;
4413 end if;
4415 -- Check restriction for standard storage pool
4417 if No (Associated_Storage_Pool (E)) then
4418 Check_Restriction (No_Standard_Storage_Pools, E);
4419 end if;
4421 -- Deal with error message for pure access type. This is not an
4422 -- error in Ada 2005 if there is no pool (see AI-366).
4424 if Is_Pure_Unit_Access_Type (E)
4425 and then (Ada_Version < Ada_2005
4426 or else not No_Pool_Assigned (E))
4427 then
4428 Error_Msg_N ("named access type not allowed in pure unit", E);
4430 if Ada_Version >= Ada_2005 then
4431 Error_Msg_N
4432 ("\would be legal if Storage_Size of 0 given??", E);
4434 elsif No_Pool_Assigned (E) then
4435 Error_Msg_N
4436 ("\would be legal in Ada 2005??", E);
4438 else
4439 Error_Msg_N
4440 ("\would be legal in Ada 2005 if "
4441 & "Storage_Size of 0 given??", E);
4442 end if;
4443 end if;
4444 end if;
4446 -- Case of composite types
4448 if Is_Composite_Type (E) then
4450 -- AI-117 requires that all new primitives of a tagged type must
4451 -- inherit the convention of the full view of the type. Inherited
4452 -- and overriding operations are defined to inherit the convention
4453 -- of their parent or overridden subprogram (also specified in
4454 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4455 -- and New_Overloaded_Entity). Here we set the convention of
4456 -- primitives that are still convention Ada, which will ensure
4457 -- that any new primitives inherit the type's convention. Class-
4458 -- wide types can have a foreign convention inherited from their
4459 -- specific type, but are excluded from this since they don't have
4460 -- any associated primitives.
4462 if Is_Tagged_Type (E)
4463 and then not Is_Class_Wide_Type (E)
4464 and then Convention (E) /= Convention_Ada
4465 then
4466 declare
4467 Prim_List : constant Elist_Id := Primitive_Operations (E);
4468 Prim : Elmt_Id;
4470 begin
4471 Prim := First_Elmt (Prim_List);
4472 while Present (Prim) loop
4473 if Convention (Node (Prim)) = Convention_Ada then
4474 Set_Convention (Node (Prim), Convention (E));
4475 end if;
4477 Next_Elmt (Prim);
4478 end loop;
4479 end;
4480 end if;
4482 -- If the type is a simple storage pool type, then this is where
4483 -- we attempt to locate and validate its Allocate, Deallocate, and
4484 -- Storage_Size operations (the first is required, and the latter
4485 -- two are optional). We also verify that the full type for a
4486 -- private type is allowed to be a simple storage pool type.
4488 if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type))
4489 and then (Is_Base_Type (E) or else Has_Private_Declaration (E))
4490 then
4491 -- If the type is marked Has_Private_Declaration, then this is
4492 -- a full type for a private type that was specified with the
4493 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4494 -- pragma is allowed for the full type (for example, it can't
4495 -- be an array type, or a nonlimited record type).
4497 if Has_Private_Declaration (E) then
4498 if (not Is_Record_Type (E)
4499 or else not Is_Immutably_Limited_Type (E))
4500 and then not Is_Private_Type (E)
4501 then
4502 Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type;
4503 Error_Msg_N
4504 ("pragma% can only apply to full type that is an " &
4505 "explicitly limited type", E);
4506 end if;
4507 end if;
4509 Validate_Simple_Pool_Ops : declare
4510 Pool_Type : Entity_Id renames E;
4511 Address_Type : constant Entity_Id := RTE (RE_Address);
4512 Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count);
4514 procedure Validate_Simple_Pool_Op_Formal
4515 (Pool_Op : Entity_Id;
4516 Pool_Op_Formal : in out Entity_Id;
4517 Expected_Mode : Formal_Kind;
4518 Expected_Type : Entity_Id;
4519 Formal_Name : String;
4520 OK_Formal : in out Boolean);
4521 -- Validate one formal Pool_Op_Formal of the candidate pool
4522 -- operation Pool_Op. The formal must be of Expected_Type
4523 -- and have mode Expected_Mode. OK_Formal will be set to
4524 -- False if the formal doesn't match. If OK_Formal is False
4525 -- on entry, then the formal will effectively be ignored
4526 -- (because validation of the pool op has already failed).
4527 -- Upon return, Pool_Op_Formal will be updated to the next
4528 -- formal, if any.
4530 procedure Validate_Simple_Pool_Operation (Op_Name : Name_Id);
4531 -- Search for and validate a simple pool operation with the
4532 -- name Op_Name. If the name is Allocate, then there must be
4533 -- exactly one such primitive operation for the simple pool
4534 -- type. If the name is Deallocate or Storage_Size, then
4535 -- there can be at most one such primitive operation. The
4536 -- profile of the located primitive must conform to what
4537 -- is expected for each operation.
4539 ------------------------------------
4540 -- Validate_Simple_Pool_Op_Formal --
4541 ------------------------------------
4543 procedure Validate_Simple_Pool_Op_Formal
4544 (Pool_Op : Entity_Id;
4545 Pool_Op_Formal : in out Entity_Id;
4546 Expected_Mode : Formal_Kind;
4547 Expected_Type : Entity_Id;
4548 Formal_Name : String;
4549 OK_Formal : in out Boolean)
4551 begin
4552 -- If OK_Formal is False on entry, then simply ignore
4553 -- the formal, because an earlier formal has already
4554 -- been flagged.
4556 if not OK_Formal then
4557 return;
4559 -- If no formal is passed in, then issue an error for a
4560 -- missing formal.
4562 elsif not Present (Pool_Op_Formal) then
4563 Error_Msg_NE
4564 ("simple storage pool op missing formal " &
4565 Formal_Name & " of type&", Pool_Op, Expected_Type);
4566 OK_Formal := False;
4568 return;
4569 end if;
4571 if Etype (Pool_Op_Formal) /= Expected_Type then
4573 -- If the pool type was expected for this formal, then
4574 -- this will not be considered a candidate operation
4575 -- for the simple pool, so we unset OK_Formal so that
4576 -- the op and any later formals will be ignored.
4578 if Expected_Type = Pool_Type then
4579 OK_Formal := False;
4581 return;
4583 else
4584 Error_Msg_NE
4585 ("wrong type for formal " & Formal_Name &
4586 " of simple storage pool op; expected type&",
4587 Pool_Op_Formal, Expected_Type);
4588 end if;
4589 end if;
4591 -- Issue error if formal's mode is not the expected one
4593 if Ekind (Pool_Op_Formal) /= Expected_Mode then
4594 Error_Msg_N
4595 ("wrong mode for formal of simple storage pool op",
4596 Pool_Op_Formal);
4597 end if;
4599 -- Advance to the next formal
4601 Next_Formal (Pool_Op_Formal);
4602 end Validate_Simple_Pool_Op_Formal;
4604 ------------------------------------
4605 -- Validate_Simple_Pool_Operation --
4606 ------------------------------------
4608 procedure Validate_Simple_Pool_Operation
4609 (Op_Name : Name_Id)
4611 Op : Entity_Id;
4612 Found_Op : Entity_Id := Empty;
4613 Formal : Entity_Id;
4614 Is_OK : Boolean;
4616 begin
4617 pragma Assert
4618 (Nam_In (Op_Name, Name_Allocate,
4619 Name_Deallocate,
4620 Name_Storage_Size));
4622 Error_Msg_Name_1 := Op_Name;
4624 -- For each homonym declared immediately in the scope
4625 -- of the simple storage pool type, determine whether
4626 -- the homonym is an operation of the pool type, and,
4627 -- if so, check that its profile is as expected for
4628 -- a simple pool operation of that name.
4630 Op := Get_Name_Entity_Id (Op_Name);
4631 while Present (Op) loop
4632 if Ekind_In (Op, E_Function, E_Procedure)
4633 and then Scope (Op) = Current_Scope
4634 then
4635 Formal := First_Entity (Op);
4637 Is_OK := True;
4639 -- The first parameter must be of the pool type
4640 -- in order for the operation to qualify.
4642 if Op_Name = Name_Storage_Size then
4643 Validate_Simple_Pool_Op_Formal
4644 (Op, Formal, E_In_Parameter, Pool_Type,
4645 "Pool", Is_OK);
4646 else
4647 Validate_Simple_Pool_Op_Formal
4648 (Op, Formal, E_In_Out_Parameter, Pool_Type,
4649 "Pool", Is_OK);
4650 end if;
4652 -- If another operation with this name has already
4653 -- been located for the type, then flag an error,
4654 -- since we only allow the type to have a single
4655 -- such primitive.
4657 if Present (Found_Op) and then Is_OK then
4658 Error_Msg_NE
4659 ("only one % operation allowed for " &
4660 "simple storage pool type&", Op, Pool_Type);
4661 end if;
4663 -- In the case of Allocate and Deallocate, a formal
4664 -- of type System.Address is required.
4666 if Op_Name = Name_Allocate then
4667 Validate_Simple_Pool_Op_Formal
4668 (Op, Formal, E_Out_Parameter,
4669 Address_Type, "Storage_Address", Is_OK);
4671 elsif Op_Name = Name_Deallocate then
4672 Validate_Simple_Pool_Op_Formal
4673 (Op, Formal, E_In_Parameter,
4674 Address_Type, "Storage_Address", Is_OK);
4675 end if;
4677 -- In the case of Allocate and Deallocate, formals
4678 -- of type Storage_Count are required as the third
4679 -- and fourth parameters.
4681 if Op_Name /= Name_Storage_Size then
4682 Validate_Simple_Pool_Op_Formal
4683 (Op, Formal, E_In_Parameter,
4684 Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK);
4685 Validate_Simple_Pool_Op_Formal
4686 (Op, Formal, E_In_Parameter,
4687 Stg_Cnt_Type, "Alignment", Is_OK);
4688 end if;
4690 -- If no mismatched formals have been found (Is_OK)
4691 -- and no excess formals are present, then this
4692 -- operation has been validated, so record it.
4694 if not Present (Formal) and then Is_OK then
4695 Found_Op := Op;
4696 end if;
4697 end if;
4699 Op := Homonym (Op);
4700 end loop;
4702 -- There must be a valid Allocate operation for the type,
4703 -- so issue an error if none was found.
4705 if Op_Name = Name_Allocate
4706 and then not Present (Found_Op)
4707 then
4708 Error_Msg_N ("missing % operation for simple " &
4709 "storage pool type", Pool_Type);
4711 elsif Present (Found_Op) then
4713 -- Simple pool operations can't be abstract
4715 if Is_Abstract_Subprogram (Found_Op) then
4716 Error_Msg_N
4717 ("simple storage pool operation must not be " &
4718 "abstract", Found_Op);
4719 end if;
4721 -- The Storage_Size operation must be a function with
4722 -- Storage_Count as its result type.
4724 if Op_Name = Name_Storage_Size then
4725 if Ekind (Found_Op) = E_Procedure then
4726 Error_Msg_N
4727 ("% operation must be a function", Found_Op);
4729 elsif Etype (Found_Op) /= Stg_Cnt_Type then
4730 Error_Msg_NE
4731 ("wrong result type for%, expected type&",
4732 Found_Op, Stg_Cnt_Type);
4733 end if;
4735 -- Allocate and Deallocate must be procedures
4737 elsif Ekind (Found_Op) = E_Function then
4738 Error_Msg_N
4739 ("% operation must be a procedure", Found_Op);
4740 end if;
4741 end if;
4742 end Validate_Simple_Pool_Operation;
4744 -- Start of processing for Validate_Simple_Pool_Ops
4746 begin
4747 Validate_Simple_Pool_Operation (Name_Allocate);
4748 Validate_Simple_Pool_Operation (Name_Deallocate);
4749 Validate_Simple_Pool_Operation (Name_Storage_Size);
4750 end Validate_Simple_Pool_Ops;
4751 end if;
4752 end if;
4754 -- Now that all types from which E may depend are frozen, see if the
4755 -- size is known at compile time, if it must be unsigned, or if
4756 -- strict alignment is required
4758 Check_Compile_Time_Size (E);
4759 Check_Unsigned_Type (E);
4761 if Base_Type (E) = E then
4762 Check_Strict_Alignment (E);
4763 end if;
4765 -- Do not allow a size clause for a type which does not have a size
4766 -- that is known at compile time
4768 if Has_Size_Clause (E)
4769 and then not Size_Known_At_Compile_Time (E)
4770 then
4771 -- Suppress this message if errors posted on E, even if we are
4772 -- in all errors mode, since this is often a junk message
4774 if not Error_Posted (E) then
4775 Error_Msg_N
4776 ("size clause not allowed for variable length type",
4777 Size_Clause (E));
4778 end if;
4779 end if;
4781 -- Now we set/verify the representation information, in particular
4782 -- the size and alignment values. This processing is not required for
4783 -- generic types, since generic types do not play any part in code
4784 -- generation, and so the size and alignment values for such types
4785 -- are irrelevant. Ditto for types declared within a generic unit,
4786 -- which may have components that depend on generic parameters, and
4787 -- that will be recreated in an instance.
4789 if Inside_A_Generic then
4790 null;
4792 -- Otherwise we call the layout procedure
4794 else
4795 Layout_Type (E);
4796 end if;
4798 -- If this is an access to subprogram whose designated type is itself
4799 -- a subprogram type, the return type of this anonymous subprogram
4800 -- type must be decorated as well.
4802 if Ekind (E) = E_Anonymous_Access_Subprogram_Type
4803 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
4804 then
4805 Layout_Type (Etype (Designated_Type (E)));
4806 end if;
4808 -- If the type has a Defaut_Value/Default_Component_Value aspect,
4809 -- this is where we analye the expression (after the type is frozen,
4810 -- since in the case of Default_Value, we are analyzing with the
4811 -- type itself, and we treat Default_Component_Value similarly for
4812 -- the sake of uniformity).
4814 if Is_First_Subtype (E) and then Has_Default_Aspect (E) then
4815 declare
4816 Nam : Name_Id;
4817 Exp : Node_Id;
4818 Typ : Entity_Id;
4820 begin
4821 if Is_Scalar_Type (E) then
4822 Nam := Name_Default_Value;
4823 Typ := E;
4824 Exp := Default_Aspect_Value (Typ);
4825 else
4826 Nam := Name_Default_Component_Value;
4827 Typ := Component_Type (E);
4828 Exp := Default_Aspect_Component_Value (E);
4829 end if;
4831 Analyze_And_Resolve (Exp, Typ);
4833 if Etype (Exp) /= Any_Type then
4834 if not Is_Static_Expression (Exp) then
4835 Error_Msg_Name_1 := Nam;
4836 Flag_Non_Static_Expr
4837 ("aspect% requires static expression", Exp);
4838 end if;
4839 end if;
4840 end;
4841 end if;
4843 -- End of freeze processing for type entities
4844 end if;
4846 -- Here is where we logically freeze the current entity. If it has a
4847 -- freeze node, then this is the point at which the freeze node is
4848 -- linked into the result list.
4850 if Has_Delayed_Freeze (E) then
4852 -- If a freeze node is already allocated, use it, otherwise allocate
4853 -- a new one. The preallocation happens in the case of anonymous base
4854 -- types, where we preallocate so that we can set First_Subtype_Link.
4855 -- Note that we reset the Sloc to the current freeze location.
4857 if Present (Freeze_Node (E)) then
4858 F_Node := Freeze_Node (E);
4859 Set_Sloc (F_Node, Loc);
4861 else
4862 F_Node := New_Node (N_Freeze_Entity, Loc);
4863 Set_Freeze_Node (E, F_Node);
4864 Set_Access_Types_To_Process (F_Node, No_Elist);
4865 Set_TSS_Elist (F_Node, No_Elist);
4866 Set_Actions (F_Node, No_List);
4867 end if;
4869 Set_Entity (F_Node, E);
4870 Add_To_Result (F_Node);
4872 -- A final pass over record types with discriminants. If the type
4873 -- has an incomplete declaration, there may be constrained access
4874 -- subtypes declared elsewhere, which do not depend on the discrimi-
4875 -- nants of the type, and which are used as component types (i.e.
4876 -- the full view is a recursive type). The designated types of these
4877 -- subtypes can only be elaborated after the type itself, and they
4878 -- need an itype reference.
4880 if Ekind (E) = E_Record_Type
4881 and then Has_Discriminants (E)
4882 then
4883 declare
4884 Comp : Entity_Id;
4885 IR : Node_Id;
4886 Typ : Entity_Id;
4888 begin
4889 Comp := First_Component (E);
4890 while Present (Comp) loop
4891 Typ := Etype (Comp);
4893 if Ekind (Comp) = E_Component
4894 and then Is_Access_Type (Typ)
4895 and then Scope (Typ) /= E
4896 and then Base_Type (Designated_Type (Typ)) = E
4897 and then Is_Itype (Designated_Type (Typ))
4898 then
4899 IR := Make_Itype_Reference (Sloc (Comp));
4900 Set_Itype (IR, Designated_Type (Typ));
4901 Append (IR, Result);
4902 end if;
4904 Next_Component (Comp);
4905 end loop;
4906 end;
4907 end if;
4908 end if;
4910 -- When a type is frozen, the first subtype of the type is frozen as
4911 -- well (RM 13.14(15)). This has to be done after freezing the type,
4912 -- since obviously the first subtype depends on its own base type.
4914 if Is_Type (E) then
4915 Freeze_And_Append (First_Subtype (E), N, Result);
4917 -- If we just froze a tagged non-class wide record, then freeze the
4918 -- corresponding class-wide type. This must be done after the tagged
4919 -- type itself is frozen, because the class-wide type refers to the
4920 -- tagged type which generates the class.
4922 if Is_Tagged_Type (E)
4923 and then not Is_Class_Wide_Type (E)
4924 and then Present (Class_Wide_Type (E))
4925 then
4926 Freeze_And_Append (Class_Wide_Type (E), N, Result);
4927 end if;
4928 end if;
4930 Check_Debug_Info_Needed (E);
4932 -- Special handling for subprograms
4934 if Is_Subprogram (E) then
4936 -- If subprogram has address clause then reset Is_Public flag, since
4937 -- we do not want the backend to generate external references.
4939 if Present (Address_Clause (E))
4940 and then not Is_Library_Level_Entity (E)
4941 then
4942 Set_Is_Public (E, False);
4944 -- If no address clause and not intrinsic, then for imported
4945 -- subprogram in main unit, generate descriptor if we are in
4946 -- Propagate_Exceptions mode.
4948 -- This is very odd code, it makes a null result, why ???
4950 elsif Propagate_Exceptions
4951 and then Is_Imported (E)
4952 and then not Is_Intrinsic_Subprogram (E)
4953 and then Convention (E) /= Convention_Stubbed
4954 then
4955 if Result = No_List then
4956 Result := Empty_List;
4957 end if;
4958 end if;
4959 end if;
4961 return Result;
4962 end Freeze_Entity;
4964 -----------------------------
4965 -- Freeze_Enumeration_Type --
4966 -----------------------------
4968 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
4969 begin
4970 -- By default, if no size clause is present, an enumeration type with
4971 -- Convention C is assumed to interface to a C enum, and has integer
4972 -- size. This applies to types. For subtypes, verify that its base
4973 -- type has no size clause either. Treat other foreign conventions
4974 -- in the same way, and also make sure alignment is set right.
4976 if Has_Foreign_Convention (Typ)
4977 and then not Has_Size_Clause (Typ)
4978 and then not Has_Size_Clause (Base_Type (Typ))
4979 and then Esize (Typ) < Standard_Integer_Size
4980 then
4981 Init_Esize (Typ, Standard_Integer_Size);
4982 Set_Alignment (Typ, Alignment (Standard_Integer));
4984 else
4985 -- If the enumeration type interfaces to C, and it has a size clause
4986 -- that specifies less than int size, it warrants a warning. The
4987 -- user may intend the C type to be an enum or a char, so this is
4988 -- not by itself an error that the Ada compiler can detect, but it
4989 -- it is a worth a heads-up. For Boolean and Character types we
4990 -- assume that the programmer has the proper C type in mind.
4992 if Convention (Typ) = Convention_C
4993 and then Has_Size_Clause (Typ)
4994 and then Esize (Typ) /= Esize (Standard_Integer)
4995 and then not Is_Boolean_Type (Typ)
4996 and then not Is_Character_Type (Typ)
4997 then
4998 Error_Msg_N
4999 ("C enum types have the size of a C int??", Size_Clause (Typ));
5000 end if;
5002 Adjust_Esize_For_Alignment (Typ);
5003 end if;
5004 end Freeze_Enumeration_Type;
5006 -----------------------
5007 -- Freeze_Expression --
5008 -----------------------
5010 procedure Freeze_Expression (N : Node_Id) is
5011 In_Spec_Exp : constant Boolean := In_Spec_Expression;
5012 Typ : Entity_Id;
5013 Nam : Entity_Id;
5014 Desig_Typ : Entity_Id;
5015 P : Node_Id;
5016 Parent_P : Node_Id;
5018 Freeze_Outside : Boolean := False;
5019 -- This flag is set true if the entity must be frozen outside the
5020 -- current subprogram. This happens in the case of expander generated
5021 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5022 -- not freeze all entities like other bodies, but which nevertheless
5023 -- may reference entities that have to be frozen before the body and
5024 -- obviously cannot be frozen inside the body.
5026 function In_Exp_Body (N : Node_Id) return Boolean;
5027 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5028 -- it is the handled statement sequence of an expander-generated
5029 -- subprogram (init proc, stream subprogram, or renaming as body).
5030 -- If so, this is not a freezing context.
5032 -----------------
5033 -- In_Exp_Body --
5034 -----------------
5036 function In_Exp_Body (N : Node_Id) return Boolean is
5037 P : Node_Id;
5038 Id : Entity_Id;
5040 begin
5041 if Nkind (N) = N_Subprogram_Body then
5042 P := N;
5043 else
5044 P := Parent (N);
5045 end if;
5047 if Nkind (P) /= N_Subprogram_Body then
5048 return False;
5050 else
5051 Id := Defining_Unit_Name (Specification (P));
5053 -- Following complex conditional could use comments ???
5055 if Nkind (Id) = N_Defining_Identifier
5056 and then (Is_Init_Proc (Id)
5057 or else Is_TSS (Id, TSS_Stream_Input)
5058 or else Is_TSS (Id, TSS_Stream_Output)
5059 or else Is_TSS (Id, TSS_Stream_Read)
5060 or else Is_TSS (Id, TSS_Stream_Write)
5061 or else Nkind_In (Original_Node (P),
5062 N_Subprogram_Renaming_Declaration,
5063 N_Expression_Function))
5064 then
5065 return True;
5066 else
5067 return False;
5068 end if;
5069 end if;
5070 end In_Exp_Body;
5072 -- Start of processing for Freeze_Expression
5074 begin
5075 -- Immediate return if freezing is inhibited. This flag is set by the
5076 -- analyzer to stop freezing on generated expressions that would cause
5077 -- freezing if they were in the source program, but which are not
5078 -- supposed to freeze, since they are created.
5080 if Must_Not_Freeze (N) then
5081 return;
5082 end if;
5084 -- If expression is non-static, then it does not freeze in a default
5085 -- expression, see section "Handling of Default Expressions" in the
5086 -- spec of package Sem for further details. Note that we have to make
5087 -- sure that we actually have a real expression (if we have a subtype
5088 -- indication, we can't test Is_Static_Expression!) However, we exclude
5089 -- the case of the prefix of an attribute of a static scalar subtype
5090 -- from this early return, because static subtype attributes should
5091 -- always cause freezing, even in default expressions, but the attribute
5092 -- may not have been marked as static yet (because in Resolve_Attribute,
5093 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5094 -- the prefix).
5096 if In_Spec_Exp
5097 and then Nkind (N) in N_Subexpr
5098 and then not Is_Static_Expression (N)
5099 and then (Nkind (Parent (N)) /= N_Attribute_Reference
5100 or else not (Is_Entity_Name (N)
5101 and then Is_Type (Entity (N))
5102 and then Is_Static_Subtype (Entity (N))))
5103 then
5104 return;
5105 end if;
5107 -- Freeze type of expression if not frozen already
5109 Typ := Empty;
5111 if Nkind (N) in N_Has_Etype then
5112 if not Is_Frozen (Etype (N)) then
5113 Typ := Etype (N);
5115 -- Base type may be an derived numeric type that is frozen at
5116 -- the point of declaration, but first_subtype is still unfrozen.
5118 elsif not Is_Frozen (First_Subtype (Etype (N))) then
5119 Typ := First_Subtype (Etype (N));
5120 end if;
5121 end if;
5123 -- For entity name, freeze entity if not frozen already. A special
5124 -- exception occurs for an identifier that did not come from source.
5125 -- We don't let such identifiers freeze a non-internal entity, i.e.
5126 -- an entity that did come from source, since such an identifier was
5127 -- generated by the expander, and cannot have any semantic effect on
5128 -- the freezing semantics. For example, this stops the parameter of
5129 -- an initialization procedure from freezing the variable.
5131 if Is_Entity_Name (N)
5132 and then not Is_Frozen (Entity (N))
5133 and then (Nkind (N) /= N_Identifier
5134 or else Comes_From_Source (N)
5135 or else not Comes_From_Source (Entity (N)))
5136 then
5137 Nam := Entity (N);
5138 else
5139 Nam := Empty;
5140 end if;
5142 -- For an allocator freeze designated type if not frozen already
5144 -- For an aggregate whose component type is an access type, freeze the
5145 -- designated type now, so that its freeze does not appear within the
5146 -- loop that might be created in the expansion of the aggregate. If the
5147 -- designated type is a private type without full view, the expression
5148 -- cannot contain an allocator, so the type is not frozen.
5150 -- For a function, we freeze the entity when the subprogram declaration
5151 -- is frozen, but a function call may appear in an initialization proc.
5152 -- before the declaration is frozen. We need to generate the extra
5153 -- formals, if any, to ensure that the expansion of the call includes
5154 -- the proper actuals. This only applies to Ada subprograms, not to
5155 -- imported ones.
5157 Desig_Typ := Empty;
5159 case Nkind (N) is
5160 when N_Allocator =>
5161 Desig_Typ := Designated_Type (Etype (N));
5163 when N_Aggregate =>
5164 if Is_Array_Type (Etype (N))
5165 and then Is_Access_Type (Component_Type (Etype (N)))
5166 then
5167 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
5168 end if;
5170 when N_Selected_Component |
5171 N_Indexed_Component |
5172 N_Slice =>
5174 if Is_Access_Type (Etype (Prefix (N))) then
5175 Desig_Typ := Designated_Type (Etype (Prefix (N)));
5176 end if;
5178 when N_Identifier =>
5179 if Present (Nam)
5180 and then Ekind (Nam) = E_Function
5181 and then Nkind (Parent (N)) = N_Function_Call
5182 and then Convention (Nam) = Convention_Ada
5183 then
5184 Create_Extra_Formals (Nam);
5185 end if;
5187 when others =>
5188 null;
5189 end case;
5191 if Desig_Typ /= Empty
5192 and then (Is_Frozen (Desig_Typ)
5193 or else (not Is_Fully_Defined (Desig_Typ)))
5194 then
5195 Desig_Typ := Empty;
5196 end if;
5198 -- All done if nothing needs freezing
5200 if No (Typ)
5201 and then No (Nam)
5202 and then No (Desig_Typ)
5203 then
5204 return;
5205 end if;
5207 -- Loop for looking at the right place to insert the freeze nodes,
5208 -- exiting from the loop when it is appropriate to insert the freeze
5209 -- node before the current node P.
5211 -- Also checks some special exceptions to the freezing rules. These
5212 -- cases result in a direct return, bypassing the freeze action.
5214 P := N;
5215 loop
5216 Parent_P := Parent (P);
5218 -- If we don't have a parent, then we are not in a well-formed tree.
5219 -- This is an unusual case, but there are some legitimate situations
5220 -- in which this occurs, notably when the expressions in the range of
5221 -- a type declaration are resolved. We simply ignore the freeze
5222 -- request in this case. Is this right ???
5224 if No (Parent_P) then
5225 return;
5226 end if;
5228 -- See if we have got to an appropriate point in the tree
5230 case Nkind (Parent_P) is
5232 -- A special test for the exception of (RM 13.14(8)) for the case
5233 -- of per-object expressions (RM 3.8(18)) occurring in component
5234 -- definition or a discrete subtype definition. Note that we test
5235 -- for a component declaration which includes both cases we are
5236 -- interested in, and furthermore the tree does not have explicit
5237 -- nodes for either of these two constructs.
5239 when N_Component_Declaration =>
5241 -- The case we want to test for here is an identifier that is
5242 -- a per-object expression, this is either a discriminant that
5243 -- appears in a context other than the component declaration
5244 -- or it is a reference to the type of the enclosing construct.
5246 -- For either of these cases, we skip the freezing
5248 if not In_Spec_Expression
5249 and then Nkind (N) = N_Identifier
5250 and then (Present (Entity (N)))
5251 then
5252 -- We recognize the discriminant case by just looking for
5253 -- a reference to a discriminant. It can only be one for
5254 -- the enclosing construct. Skip freezing in this case.
5256 if Ekind (Entity (N)) = E_Discriminant then
5257 return;
5259 -- For the case of a reference to the enclosing record,
5260 -- (or task or protected type), we look for a type that
5261 -- matches the current scope.
5263 elsif Entity (N) = Current_Scope then
5264 return;
5265 end if;
5266 end if;
5268 -- If we have an enumeration literal that appears as the choice in
5269 -- the aggregate of an enumeration representation clause, then
5270 -- freezing does not occur (RM 13.14(10)).
5272 when N_Enumeration_Representation_Clause =>
5274 -- The case we are looking for is an enumeration literal
5276 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
5277 and then Is_Enumeration_Type (Etype (N))
5278 then
5279 -- If enumeration literal appears directly as the choice,
5280 -- do not freeze (this is the normal non-overloaded case)
5282 if Nkind (Parent (N)) = N_Component_Association
5283 and then First (Choices (Parent (N))) = N
5284 then
5285 return;
5287 -- If enumeration literal appears as the name of function
5288 -- which is the choice, then also do not freeze. This
5289 -- happens in the overloaded literal case, where the
5290 -- enumeration literal is temporarily changed to a function
5291 -- call for overloading analysis purposes.
5293 elsif Nkind (Parent (N)) = N_Function_Call
5294 and then
5295 Nkind (Parent (Parent (N))) = N_Component_Association
5296 and then
5297 First (Choices (Parent (Parent (N)))) = Parent (N)
5298 then
5299 return;
5300 end if;
5301 end if;
5303 -- Normally if the parent is a handled sequence of statements,
5304 -- then the current node must be a statement, and that is an
5305 -- appropriate place to insert a freeze node.
5307 when N_Handled_Sequence_Of_Statements =>
5309 -- An exception occurs when the sequence of statements is for
5310 -- an expander generated body that did not do the usual freeze
5311 -- all operation. In this case we usually want to freeze
5312 -- outside this body, not inside it, and we skip past the
5313 -- subprogram body that we are inside.
5315 if In_Exp_Body (Parent_P) then
5316 declare
5317 Subp : constant Node_Id := Parent (Parent_P);
5318 Spec : Entity_Id;
5320 begin
5321 -- Freeze the entity only when it is declared inside the
5322 -- body of the expander generated procedure. This case
5323 -- is recognized by the scope of the entity or its type,
5324 -- which is either the spec for some enclosing body, or
5325 -- (in the case of init_procs, for which there are no
5326 -- separate specs) the current scope.
5328 if Nkind (Subp) = N_Subprogram_Body then
5329 Spec := Corresponding_Spec (Subp);
5331 if (Present (Typ) and then Scope (Typ) = Spec)
5332 or else
5333 (Present (Nam) and then Scope (Nam) = Spec)
5334 then
5335 exit;
5337 elsif Present (Typ)
5338 and then Scope (Typ) = Current_Scope
5339 and then Defining_Entity (Subp) = Current_Scope
5340 then
5341 exit;
5342 end if;
5343 end if;
5345 -- An expression function may act as a completion of
5346 -- a function declaration. As such, it can reference
5347 -- entities declared between the two views:
5349 -- Hidden []; -- 1
5350 -- function F return ...;
5351 -- private
5352 -- function Hidden return ...;
5353 -- function F return ... is (Hidden); -- 2
5355 -- Refering to the example above, freezing the expression
5356 -- of F (2) would place Hidden's freeze node (1) in the
5357 -- wrong place. Avoid explicit freezing and let the usual
5358 -- scenarios do the job - for example, reaching the end
5359 -- of the private declarations.
5361 if Nkind (Original_Node (Subp)) =
5362 N_Expression_Function
5363 then
5364 null;
5366 -- Freeze outside the body
5368 else
5369 Parent_P := Parent (Parent_P);
5370 Freeze_Outside := True;
5371 end if;
5372 end;
5374 -- Here if normal case where we are in handled statement
5375 -- sequence and want to do the insertion right there.
5377 else
5378 exit;
5379 end if;
5381 -- If parent is a body or a spec or a block, then the current node
5382 -- is a statement or declaration and we can insert the freeze node
5383 -- before it.
5385 when N_Block_Statement |
5386 N_Entry_Body |
5387 N_Package_Body |
5388 N_Package_Specification |
5389 N_Protected_Body |
5390 N_Subprogram_Body |
5391 N_Task_Body => exit;
5393 -- The expander is allowed to define types in any statements list,
5394 -- so any of the following parent nodes also mark a freezing point
5395 -- if the actual node is in a list of statements or declarations.
5397 when N_Abortable_Part |
5398 N_Accept_Alternative |
5399 N_And_Then |
5400 N_Case_Statement_Alternative |
5401 N_Compilation_Unit_Aux |
5402 N_Conditional_Entry_Call |
5403 N_Delay_Alternative |
5404 N_Elsif_Part |
5405 N_Entry_Call_Alternative |
5406 N_Exception_Handler |
5407 N_Extended_Return_Statement |
5408 N_Freeze_Entity |
5409 N_If_Statement |
5410 N_Or_Else |
5411 N_Selective_Accept |
5412 N_Triggering_Alternative =>
5414 exit when Is_List_Member (P);
5416 -- Note: The N_Loop_Statement is a special case. A type that
5417 -- appears in the source can never be frozen in a loop (this
5418 -- occurs only because of a loop expanded by the expander), so we
5419 -- keep on going. Otherwise we terminate the search. Same is true
5420 -- of any entity which comes from source. (if they have predefined
5421 -- type, that type does not appear to come from source, but the
5422 -- entity should not be frozen here).
5424 when N_Loop_Statement =>
5425 exit when not Comes_From_Source (Etype (N))
5426 and then (No (Nam) or else not Comes_From_Source (Nam));
5428 -- For all other cases, keep looking at parents
5430 when others =>
5431 null;
5432 end case;
5434 -- We fall through the case if we did not yet find the proper
5435 -- place in the free for inserting the freeze node, so climb!
5437 P := Parent_P;
5438 end loop;
5440 -- If the expression appears in a record or an initialization procedure,
5441 -- the freeze nodes are collected and attached to the current scope, to
5442 -- be inserted and analyzed on exit from the scope, to insure that
5443 -- generated entities appear in the correct scope. If the expression is
5444 -- a default for a discriminant specification, the scope is still void.
5445 -- The expression can also appear in the discriminant part of a private
5446 -- or concurrent type.
5448 -- If the expression appears in a constrained subcomponent of an
5449 -- enclosing record declaration, the freeze nodes must be attached to
5450 -- the outer record type so they can eventually be placed in the
5451 -- enclosing declaration list.
5453 -- The other case requiring this special handling is if we are in a
5454 -- default expression, since in that case we are about to freeze a
5455 -- static type, and the freeze scope needs to be the outer scope, not
5456 -- the scope of the subprogram with the default parameter.
5458 -- For default expressions and other spec expressions in generic units,
5459 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5460 -- placing them at the proper place, after the generic unit.
5462 if (In_Spec_Exp and not Inside_A_Generic)
5463 or else Freeze_Outside
5464 or else (Is_Type (Current_Scope)
5465 and then (not Is_Concurrent_Type (Current_Scope)
5466 or else not Has_Completion (Current_Scope)))
5467 or else Ekind (Current_Scope) = E_Void
5468 then
5469 declare
5470 N : constant Node_Id := Current_Scope;
5471 Freeze_Nodes : List_Id := No_List;
5472 Pos : Int := Scope_Stack.Last;
5474 begin
5475 if Present (Desig_Typ) then
5476 Freeze_And_Append (Desig_Typ, N, Freeze_Nodes);
5477 end if;
5479 if Present (Typ) then
5480 Freeze_And_Append (Typ, N, Freeze_Nodes);
5481 end if;
5483 if Present (Nam) then
5484 Freeze_And_Append (Nam, N, Freeze_Nodes);
5485 end if;
5487 -- The current scope may be that of a constrained component of
5488 -- an enclosing record declaration, or of a loop of an enclosing
5489 -- quantified expression, which is above the current scope in the
5490 -- scope stack. Indeed in the context of a quantified expression,
5491 -- a scope is created and pushed above the current scope in order
5492 -- to emulate the loop-like behavior of the quantified expression.
5493 -- If the expression is within a top-level pragma, as for a pre-
5494 -- condition on a library-level subprogram, nothing to do.
5496 if not Is_Compilation_Unit (Current_Scope)
5497 and then (Is_Record_Type (Scope (Current_Scope))
5498 or else Nkind (Parent (Current_Scope)) =
5499 N_Quantified_Expression)
5500 then
5501 Pos := Pos - 1;
5502 end if;
5504 if Is_Non_Empty_List (Freeze_Nodes) then
5505 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
5506 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
5507 Freeze_Nodes;
5508 else
5509 Append_List (Freeze_Nodes,
5510 Scope_Stack.Table (Pos).Pending_Freeze_Actions);
5511 end if;
5512 end if;
5513 end;
5515 return;
5516 end if;
5518 -- Now we have the right place to do the freezing. First, a special
5519 -- adjustment, if we are in spec-expression analysis mode, these freeze
5520 -- actions must not be thrown away (normally all inserted actions are
5521 -- thrown away in this mode. However, the freeze actions are from static
5522 -- expressions and one of the important reasons we are doing this
5523 -- special analysis is to get these freeze actions. Therefore we turn
5524 -- off the In_Spec_Expression mode to propagate these freeze actions.
5525 -- This also means they get properly analyzed and expanded.
5527 In_Spec_Expression := False;
5529 -- Freeze the designated type of an allocator (RM 13.14(13))
5531 if Present (Desig_Typ) then
5532 Freeze_Before (P, Desig_Typ);
5533 end if;
5535 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5536 -- the enumeration representation clause exception in the loop above.
5538 if Present (Typ) then
5539 Freeze_Before (P, Typ);
5540 end if;
5542 -- Freeze name if one is present (RM 13.14(11))
5544 if Present (Nam) then
5545 Freeze_Before (P, Nam);
5546 end if;
5548 -- Restore In_Spec_Expression flag
5550 In_Spec_Expression := In_Spec_Exp;
5551 end Freeze_Expression;
5553 -----------------------------
5554 -- Freeze_Fixed_Point_Type --
5555 -----------------------------
5557 -- Certain fixed-point types and subtypes, including implicit base types
5558 -- and declared first subtypes, have not yet set up a range. This is
5559 -- because the range cannot be set until the Small and Size values are
5560 -- known, and these are not known till the type is frozen.
5562 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5563 -- whose bounds are unanalyzed real literals. This routine will recognize
5564 -- this case, and transform this range node into a properly typed range
5565 -- with properly analyzed and resolved values.
5567 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
5568 Rng : constant Node_Id := Scalar_Range (Typ);
5569 Lo : constant Node_Id := Low_Bound (Rng);
5570 Hi : constant Node_Id := High_Bound (Rng);
5571 Btyp : constant Entity_Id := Base_Type (Typ);
5572 Brng : constant Node_Id := Scalar_Range (Btyp);
5573 BLo : constant Node_Id := Low_Bound (Brng);
5574 BHi : constant Node_Id := High_Bound (Brng);
5575 Small : constant Ureal := Small_Value (Typ);
5576 Loval : Ureal;
5577 Hival : Ureal;
5578 Atype : Entity_Id;
5580 Actual_Size : Nat;
5582 function Fsize (Lov, Hiv : Ureal) return Nat;
5583 -- Returns size of type with given bounds. Also leaves these
5584 -- bounds set as the current bounds of the Typ.
5586 -----------
5587 -- Fsize --
5588 -----------
5590 function Fsize (Lov, Hiv : Ureal) return Nat is
5591 begin
5592 Set_Realval (Lo, Lov);
5593 Set_Realval (Hi, Hiv);
5594 return Minimum_Size (Typ);
5595 end Fsize;
5597 -- Start of processing for Freeze_Fixed_Point_Type
5599 begin
5600 -- If Esize of a subtype has not previously been set, set it now
5602 if Unknown_Esize (Typ) then
5603 Atype := Ancestor_Subtype (Typ);
5605 if Present (Atype) then
5606 Set_Esize (Typ, Esize (Atype));
5607 else
5608 Set_Esize (Typ, Esize (Base_Type (Typ)));
5609 end if;
5610 end if;
5612 -- Immediate return if the range is already analyzed. This means that
5613 -- the range is already set, and does not need to be computed by this
5614 -- routine.
5616 if Analyzed (Rng) then
5617 return;
5618 end if;
5620 -- Immediate return if either of the bounds raises Constraint_Error
5622 if Raises_Constraint_Error (Lo)
5623 or else Raises_Constraint_Error (Hi)
5624 then
5625 return;
5626 end if;
5628 Loval := Realval (Lo);
5629 Hival := Realval (Hi);
5631 -- Ordinary fixed-point case
5633 if Is_Ordinary_Fixed_Point_Type (Typ) then
5635 -- For the ordinary fixed-point case, we are allowed to fudge the
5636 -- end-points up or down by small. Generally we prefer to fudge up,
5637 -- i.e. widen the bounds for non-model numbers so that the end points
5638 -- are included. However there are cases in which this cannot be
5639 -- done, and indeed cases in which we may need to narrow the bounds.
5640 -- The following circuit makes the decision.
5642 -- Note: our terminology here is that Incl_EP means that the bounds
5643 -- are widened by Small if necessary to include the end points, and
5644 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5645 -- end-points if this reduces the size.
5647 -- Note that in the Incl case, all we care about is including the
5648 -- end-points. In the Excl case, we want to narrow the bounds as
5649 -- much as permitted by the RM, to give the smallest possible size.
5651 Fudge : declare
5652 Loval_Incl_EP : Ureal;
5653 Hival_Incl_EP : Ureal;
5655 Loval_Excl_EP : Ureal;
5656 Hival_Excl_EP : Ureal;
5658 Size_Incl_EP : Nat;
5659 Size_Excl_EP : Nat;
5661 Model_Num : Ureal;
5662 First_Subt : Entity_Id;
5663 Actual_Lo : Ureal;
5664 Actual_Hi : Ureal;
5666 begin
5667 -- First step. Base types are required to be symmetrical. Right
5668 -- now, the base type range is a copy of the first subtype range.
5669 -- This will be corrected before we are done, but right away we
5670 -- need to deal with the case where both bounds are non-negative.
5671 -- In this case, we set the low bound to the negative of the high
5672 -- bound, to make sure that the size is computed to include the
5673 -- required sign. Note that we do not need to worry about the
5674 -- case of both bounds negative, because the sign will be dealt
5675 -- with anyway. Furthermore we can't just go making such a bound
5676 -- symmetrical, since in a twos-complement system, there is an
5677 -- extra negative value which could not be accommodated on the
5678 -- positive side.
5680 if Typ = Btyp
5681 and then not UR_Is_Negative (Loval)
5682 and then Hival > Loval
5683 then
5684 Loval := -Hival;
5685 Set_Realval (Lo, Loval);
5686 end if;
5688 -- Compute the fudged bounds. If the number is a model number,
5689 -- then we do nothing to include it, but we are allowed to backoff
5690 -- to the next adjacent model number when we exclude it. If it is
5691 -- not a model number then we straddle the two values with the
5692 -- model numbers on either side.
5694 Model_Num := UR_Trunc (Loval / Small) * Small;
5696 if Loval = Model_Num then
5697 Loval_Incl_EP := Model_Num;
5698 else
5699 Loval_Incl_EP := Model_Num - Small;
5700 end if;
5702 -- The low value excluding the end point is Small greater, but
5703 -- we do not do this exclusion if the low value is positive,
5704 -- since it can't help the size and could actually hurt by
5705 -- crossing the high bound.
5707 if UR_Is_Negative (Loval_Incl_EP) then
5708 Loval_Excl_EP := Loval_Incl_EP + Small;
5710 -- If the value went from negative to zero, then we have the
5711 -- case where Loval_Incl_EP is the model number just below
5712 -- zero, so we want to stick to the negative value for the
5713 -- base type to maintain the condition that the size will
5714 -- include signed values.
5716 if Typ = Btyp
5717 and then UR_Is_Zero (Loval_Excl_EP)
5718 then
5719 Loval_Excl_EP := Loval_Incl_EP;
5720 end if;
5722 else
5723 Loval_Excl_EP := Loval_Incl_EP;
5724 end if;
5726 -- Similar processing for upper bound and high value
5728 Model_Num := UR_Trunc (Hival / Small) * Small;
5730 if Hival = Model_Num then
5731 Hival_Incl_EP := Model_Num;
5732 else
5733 Hival_Incl_EP := Model_Num + Small;
5734 end if;
5736 if UR_Is_Positive (Hival_Incl_EP) then
5737 Hival_Excl_EP := Hival_Incl_EP - Small;
5738 else
5739 Hival_Excl_EP := Hival_Incl_EP;
5740 end if;
5742 -- One further adjustment is needed. In the case of subtypes, we
5743 -- cannot go outside the range of the base type, or we get
5744 -- peculiarities, and the base type range is already set. This
5745 -- only applies to the Incl values, since clearly the Excl values
5746 -- are already as restricted as they are allowed to be.
5748 if Typ /= Btyp then
5749 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
5750 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
5751 end if;
5753 -- Get size including and excluding end points
5755 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
5756 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
5758 -- No need to exclude end-points if it does not reduce size
5760 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
5761 Loval_Excl_EP := Loval_Incl_EP;
5762 end if;
5764 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
5765 Hival_Excl_EP := Hival_Incl_EP;
5766 end if;
5768 -- Now we set the actual size to be used. We want to use the
5769 -- bounds fudged up to include the end-points but only if this
5770 -- can be done without violating a specifically given size
5771 -- size clause or causing an unacceptable increase in size.
5773 -- Case of size clause given
5775 if Has_Size_Clause (Typ) then
5777 -- Use the inclusive size only if it is consistent with
5778 -- the explicitly specified size.
5780 if Size_Incl_EP <= RM_Size (Typ) then
5781 Actual_Lo := Loval_Incl_EP;
5782 Actual_Hi := Hival_Incl_EP;
5783 Actual_Size := Size_Incl_EP;
5785 -- If the inclusive size is too large, we try excluding
5786 -- the end-points (will be caught later if does not work).
5788 else
5789 Actual_Lo := Loval_Excl_EP;
5790 Actual_Hi := Hival_Excl_EP;
5791 Actual_Size := Size_Excl_EP;
5792 end if;
5794 -- Case of size clause not given
5796 else
5797 -- If we have a base type whose corresponding first subtype
5798 -- has an explicit size that is large enough to include our
5799 -- end-points, then do so. There is no point in working hard
5800 -- to get a base type whose size is smaller than the specified
5801 -- size of the first subtype.
5803 First_Subt := First_Subtype (Typ);
5805 if Has_Size_Clause (First_Subt)
5806 and then Size_Incl_EP <= Esize (First_Subt)
5807 then
5808 Actual_Size := Size_Incl_EP;
5809 Actual_Lo := Loval_Incl_EP;
5810 Actual_Hi := Hival_Incl_EP;
5812 -- If excluding the end-points makes the size smaller and
5813 -- results in a size of 8,16,32,64, then we take the smaller
5814 -- size. For the 64 case, this is compulsory. For the other
5815 -- cases, it seems reasonable. We like to include end points
5816 -- if we can, but not at the expense of moving to the next
5817 -- natural boundary of size.
5819 elsif Size_Incl_EP /= Size_Excl_EP
5820 and then Addressable (Size_Excl_EP)
5821 then
5822 Actual_Size := Size_Excl_EP;
5823 Actual_Lo := Loval_Excl_EP;
5824 Actual_Hi := Hival_Excl_EP;
5826 -- Otherwise we can definitely include the end points
5828 else
5829 Actual_Size := Size_Incl_EP;
5830 Actual_Lo := Loval_Incl_EP;
5831 Actual_Hi := Hival_Incl_EP;
5832 end if;
5834 -- One pathological case: normally we never fudge a low bound
5835 -- down, since it would seem to increase the size (if it has
5836 -- any effect), but for ranges containing single value, or no
5837 -- values, the high bound can be small too large. Consider:
5839 -- type t is delta 2.0**(-14)
5840 -- range 131072.0 .. 0;
5842 -- That lower bound is *just* outside the range of 32 bits, and
5843 -- does need fudging down in this case. Note that the bounds
5844 -- will always have crossed here, since the high bound will be
5845 -- fudged down if necessary, as in the case of:
5847 -- type t is delta 2.0**(-14)
5848 -- range 131072.0 .. 131072.0;
5850 -- So we detect the situation by looking for crossed bounds,
5851 -- and if the bounds are crossed, and the low bound is greater
5852 -- than zero, we will always back it off by small, since this
5853 -- is completely harmless.
5855 if Actual_Lo > Actual_Hi then
5856 if UR_Is_Positive (Actual_Lo) then
5857 Actual_Lo := Loval_Incl_EP - Small;
5858 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
5860 -- And of course, we need to do exactly the same parallel
5861 -- fudge for flat ranges in the negative region.
5863 elsif UR_Is_Negative (Actual_Hi) then
5864 Actual_Hi := Hival_Incl_EP + Small;
5865 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
5866 end if;
5867 end if;
5868 end if;
5870 Set_Realval (Lo, Actual_Lo);
5871 Set_Realval (Hi, Actual_Hi);
5872 end Fudge;
5874 -- For the decimal case, none of this fudging is required, since there
5875 -- are no end-point problems in the decimal case (the end-points are
5876 -- always included).
5878 else
5879 Actual_Size := Fsize (Loval, Hival);
5880 end if;
5882 -- At this stage, the actual size has been calculated and the proper
5883 -- required bounds are stored in the low and high bounds.
5885 if Actual_Size > 64 then
5886 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
5887 Error_Msg_N
5888 ("size required (^) for type& too large, maximum allowed is 64",
5889 Typ);
5890 Actual_Size := 64;
5891 end if;
5893 -- Check size against explicit given size
5895 if Has_Size_Clause (Typ) then
5896 if Actual_Size > RM_Size (Typ) then
5897 Error_Msg_Uint_1 := RM_Size (Typ);
5898 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
5899 Error_Msg_NE
5900 ("size given (^) for type& too small, minimum allowed is ^",
5901 Size_Clause (Typ), Typ);
5903 else
5904 Actual_Size := UI_To_Int (Esize (Typ));
5905 end if;
5907 -- Increase size to next natural boundary if no size clause given
5909 else
5910 if Actual_Size <= 8 then
5911 Actual_Size := 8;
5912 elsif Actual_Size <= 16 then
5913 Actual_Size := 16;
5914 elsif Actual_Size <= 32 then
5915 Actual_Size := 32;
5916 else
5917 Actual_Size := 64;
5918 end if;
5920 Init_Esize (Typ, Actual_Size);
5921 Adjust_Esize_For_Alignment (Typ);
5922 end if;
5924 -- If we have a base type, then expand the bounds so that they extend to
5925 -- the full width of the allocated size in bits, to avoid junk range
5926 -- checks on intermediate computations.
5928 if Base_Type (Typ) = Typ then
5929 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
5930 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
5931 end if;
5933 -- Final step is to reanalyze the bounds using the proper type
5934 -- and set the Corresponding_Integer_Value fields of the literals.
5936 Set_Etype (Lo, Empty);
5937 Set_Analyzed (Lo, False);
5938 Analyze (Lo);
5940 -- Resolve with universal fixed if the base type, and the base type if
5941 -- it is a subtype. Note we can't resolve the base type with itself,
5942 -- that would be a reference before definition.
5944 if Typ = Btyp then
5945 Resolve (Lo, Universal_Fixed);
5946 else
5947 Resolve (Lo, Btyp);
5948 end if;
5950 -- Set corresponding integer value for bound
5952 Set_Corresponding_Integer_Value
5953 (Lo, UR_To_Uint (Realval (Lo) / Small));
5955 -- Similar processing for high bound
5957 Set_Etype (Hi, Empty);
5958 Set_Analyzed (Hi, False);
5959 Analyze (Hi);
5961 if Typ = Btyp then
5962 Resolve (Hi, Universal_Fixed);
5963 else
5964 Resolve (Hi, Btyp);
5965 end if;
5967 Set_Corresponding_Integer_Value
5968 (Hi, UR_To_Uint (Realval (Hi) / Small));
5970 -- Set type of range to correspond to bounds
5972 Set_Etype (Rng, Etype (Lo));
5974 -- Set Esize to calculated size if not set already
5976 if Unknown_Esize (Typ) then
5977 Init_Esize (Typ, Actual_Size);
5978 end if;
5980 -- Set RM_Size if not already set. If already set, check value
5982 declare
5983 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
5985 begin
5986 if RM_Size (Typ) /= Uint_0 then
5987 if RM_Size (Typ) < Minsiz then
5988 Error_Msg_Uint_1 := RM_Size (Typ);
5989 Error_Msg_Uint_2 := Minsiz;
5990 Error_Msg_NE
5991 ("size given (^) for type& too small, minimum allowed is ^",
5992 Size_Clause (Typ), Typ);
5993 end if;
5995 else
5996 Set_RM_Size (Typ, Minsiz);
5997 end if;
5998 end;
5999 end Freeze_Fixed_Point_Type;
6001 ------------------
6002 -- Freeze_Itype --
6003 ------------------
6005 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
6006 L : List_Id;
6008 begin
6009 Set_Has_Delayed_Freeze (T);
6010 L := Freeze_Entity (T, N);
6012 if Is_Non_Empty_List (L) then
6013 Insert_Actions (N, L);
6014 end if;
6015 end Freeze_Itype;
6017 --------------------------
6018 -- Freeze_Static_Object --
6019 --------------------------
6021 procedure Freeze_Static_Object (E : Entity_Id) is
6023 Cannot_Be_Static : exception;
6024 -- Exception raised if the type of a static object cannot be made
6025 -- static. This happens if the type depends on non-global objects.
6027 procedure Ensure_Expression_Is_SA (N : Node_Id);
6028 -- Called to ensure that an expression used as part of a type definition
6029 -- is statically allocatable, which means that the expression type is
6030 -- statically allocatable, and the expression is either static, or a
6031 -- reference to a library level constant.
6033 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
6034 -- Called to mark a type as static, checking that it is possible
6035 -- to set the type as static. If it is not possible, then the
6036 -- exception Cannot_Be_Static is raised.
6038 -----------------------------
6039 -- Ensure_Expression_Is_SA --
6040 -----------------------------
6042 procedure Ensure_Expression_Is_SA (N : Node_Id) is
6043 Ent : Entity_Id;
6045 begin
6046 Ensure_Type_Is_SA (Etype (N));
6048 if Is_Static_Expression (N) then
6049 return;
6051 elsif Nkind (N) = N_Identifier then
6052 Ent := Entity (N);
6054 if Present (Ent)
6055 and then Ekind (Ent) = E_Constant
6056 and then Is_Library_Level_Entity (Ent)
6057 then
6058 return;
6059 end if;
6060 end if;
6062 raise Cannot_Be_Static;
6063 end Ensure_Expression_Is_SA;
6065 -----------------------
6066 -- Ensure_Type_Is_SA --
6067 -----------------------
6069 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
6070 N : Node_Id;
6071 C : Entity_Id;
6073 begin
6074 -- If type is library level, we are all set
6076 if Is_Library_Level_Entity (Typ) then
6077 return;
6078 end if;
6080 -- We are also OK if the type already marked as statically allocated,
6081 -- which means we processed it before.
6083 if Is_Statically_Allocated (Typ) then
6084 return;
6085 end if;
6087 -- Mark type as statically allocated
6089 Set_Is_Statically_Allocated (Typ);
6091 -- Check that it is safe to statically allocate this type
6093 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
6094 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
6095 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
6097 elsif Is_Array_Type (Typ) then
6098 N := First_Index (Typ);
6099 while Present (N) loop
6100 Ensure_Type_Is_SA (Etype (N));
6101 Next_Index (N);
6102 end loop;
6104 Ensure_Type_Is_SA (Component_Type (Typ));
6106 elsif Is_Access_Type (Typ) then
6107 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
6109 declare
6110 F : Entity_Id;
6111 T : constant Entity_Id := Etype (Designated_Type (Typ));
6113 begin
6114 if T /= Standard_Void_Type then
6115 Ensure_Type_Is_SA (T);
6116 end if;
6118 F := First_Formal (Designated_Type (Typ));
6119 while Present (F) loop
6120 Ensure_Type_Is_SA (Etype (F));
6121 Next_Formal (F);
6122 end loop;
6123 end;
6125 else
6126 Ensure_Type_Is_SA (Designated_Type (Typ));
6127 end if;
6129 elsif Is_Record_Type (Typ) then
6130 C := First_Entity (Typ);
6131 while Present (C) loop
6132 if Ekind (C) = E_Discriminant
6133 or else Ekind (C) = E_Component
6134 then
6135 Ensure_Type_Is_SA (Etype (C));
6137 elsif Is_Type (C) then
6138 Ensure_Type_Is_SA (C);
6139 end if;
6141 Next_Entity (C);
6142 end loop;
6144 elsif Ekind (Typ) = E_Subprogram_Type then
6145 Ensure_Type_Is_SA (Etype (Typ));
6147 C := First_Formal (Typ);
6148 while Present (C) loop
6149 Ensure_Type_Is_SA (Etype (C));
6150 Next_Formal (C);
6151 end loop;
6153 else
6154 raise Cannot_Be_Static;
6155 end if;
6156 end Ensure_Type_Is_SA;
6158 -- Start of processing for Freeze_Static_Object
6160 begin
6161 Ensure_Type_Is_SA (Etype (E));
6163 exception
6164 when Cannot_Be_Static =>
6166 -- If the object that cannot be static is imported or exported, then
6167 -- issue an error message saying that this object cannot be imported
6168 -- or exported. If it has an address clause it is an overlay in the
6169 -- current partition and the static requirement is not relevant.
6170 -- Do not issue any error message when ignoring rep clauses.
6172 if Ignore_Rep_Clauses then
6173 null;
6175 elsif Is_Imported (E) then
6176 if No (Address_Clause (E)) then
6177 Error_Msg_N
6178 ("& cannot be imported (local type is not constant)", E);
6179 end if;
6181 -- Otherwise must be exported, something is wrong if compiler
6182 -- is marking something as statically allocated which cannot be).
6184 else pragma Assert (Is_Exported (E));
6185 Error_Msg_N
6186 ("& cannot be exported (local type is not constant)", E);
6187 end if;
6188 end Freeze_Static_Object;
6190 -----------------------
6191 -- Freeze_Subprogram --
6192 -----------------------
6194 procedure Freeze_Subprogram (E : Entity_Id) is
6195 Retype : Entity_Id;
6196 F : Entity_Id;
6198 begin
6199 -- Subprogram may not have an address clause unless it is imported
6201 if Present (Address_Clause (E)) then
6202 if not Is_Imported (E) then
6203 Error_Msg_N
6204 ("address clause can only be given " &
6205 "for imported subprogram",
6206 Name (Address_Clause (E)));
6207 end if;
6208 end if;
6210 -- Reset the Pure indication on an imported subprogram unless an
6211 -- explicit Pure_Function pragma was present. We do this because
6212 -- otherwise it is an insidious error to call a non-pure function from
6213 -- pure unit and have calls mysteriously optimized away. What happens
6214 -- here is that the Import can bypass the normal check to ensure that
6215 -- pure units call only pure subprograms.
6217 if Is_Imported (E)
6218 and then Is_Pure (E)
6219 and then not Has_Pragma_Pure_Function (E)
6220 then
6221 Set_Is_Pure (E, False);
6222 end if;
6224 -- For non-foreign convention subprograms, this is where we create
6225 -- the extra formals (for accessibility level and constrained bit
6226 -- information). We delay this till the freeze point precisely so
6227 -- that we know the convention!
6229 if not Has_Foreign_Convention (E) then
6230 Create_Extra_Formals (E);
6231 Set_Mechanisms (E);
6233 -- If this is convention Ada and a Valued_Procedure, that's odd
6235 if Ekind (E) = E_Procedure
6236 and then Is_Valued_Procedure (E)
6237 and then Convention (E) = Convention_Ada
6238 and then Warn_On_Export_Import
6239 then
6240 Error_Msg_N
6241 ("??Valued_Procedure has no effect for convention Ada", E);
6242 Set_Is_Valued_Procedure (E, False);
6243 end if;
6245 -- Case of foreign convention
6247 else
6248 Set_Mechanisms (E);
6250 -- For foreign conventions, warn about return of an
6251 -- unconstrained array.
6253 -- Note: we *do* allow a return by descriptor for the VMS case,
6254 -- though here there is probably more to be done ???
6256 if Ekind (E) = E_Function then
6257 Retype := Underlying_Type (Etype (E));
6259 -- If no return type, probably some other error, e.g. a
6260 -- missing full declaration, so ignore.
6262 if No (Retype) then
6263 null;
6265 -- If the return type is generic, we have emitted a warning
6266 -- earlier on, and there is nothing else to check here. Specific
6267 -- instantiations may lead to erroneous behavior.
6269 elsif Is_Generic_Type (Etype (E)) then
6270 null;
6272 -- Display warning if returning unconstrained array
6274 elsif Is_Array_Type (Retype)
6275 and then not Is_Constrained (Retype)
6277 -- Exclude cases where descriptor mechanism is set, since the
6278 -- VMS descriptor mechanisms allow such unconstrained returns.
6280 and then Mechanism (E) not in Descriptor_Codes
6282 -- Check appropriate warning is enabled (should we check for
6283 -- Warnings (Off) on specific entities here, probably so???)
6285 and then Warn_On_Export_Import
6287 -- Exclude the VM case, since return of unconstrained arrays
6288 -- is properly handled in both the JVM and .NET cases.
6290 and then VM_Target = No_VM
6291 then
6292 Error_Msg_N
6293 ("?x?foreign convention function& should not return " &
6294 "unconstrained array", E);
6295 return;
6296 end if;
6297 end if;
6299 -- If any of the formals for an exported foreign convention
6300 -- subprogram have defaults, then emit an appropriate warning since
6301 -- this is odd (default cannot be used from non-Ada code)
6303 if Is_Exported (E) then
6304 F := First_Formal (E);
6305 while Present (F) loop
6306 if Warn_On_Export_Import
6307 and then Present (Default_Value (F))
6308 then
6309 Error_Msg_N
6310 ("?x?parameter cannot be defaulted in non-Ada call",
6311 Default_Value (F));
6312 end if;
6314 Next_Formal (F);
6315 end loop;
6316 end if;
6317 end if;
6319 -- For VMS, descriptor mechanisms for parameters are allowed only for
6320 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6321 -- allowed for parameters of exported subprograms.
6323 if OpenVMS_On_Target then
6324 if Is_Exported (E) then
6325 F := First_Formal (E);
6326 while Present (F) loop
6327 if Mechanism (F) = By_Descriptor_NCA then
6328 Error_Msg_N
6329 ("'N'C'A' descriptor for parameter not permitted", F);
6330 Error_Msg_N
6331 ("\can only be used for imported subprogram", F);
6332 end if;
6334 Next_Formal (F);
6335 end loop;
6337 elsif not Is_Imported (E) then
6338 F := First_Formal (E);
6339 while Present (F) loop
6340 if Mechanism (F) in Descriptor_Codes then
6341 Error_Msg_N
6342 ("descriptor mechanism for parameter not permitted", F);
6343 Error_Msg_N
6344 ("\can only be used for imported/exported subprogram", F);
6345 end if;
6347 Next_Formal (F);
6348 end loop;
6349 end if;
6350 end if;
6352 -- Pragma Inline_Always is disallowed for dispatching subprograms
6353 -- because the address of such subprograms is saved in the dispatch
6354 -- table to support dispatching calls, and dispatching calls cannot
6355 -- be inlined. This is consistent with the restriction against using
6356 -- 'Access or 'Address on an Inline_Always subprogram.
6358 if Is_Dispatching_Operation (E)
6359 and then Has_Pragma_Inline_Always (E)
6360 then
6361 Error_Msg_N
6362 ("pragma Inline_Always not allowed for dispatching subprograms", E);
6363 end if;
6365 -- Because of the implicit representation of inherited predefined
6366 -- operators in the front-end, the overriding status of the operation
6367 -- may be affected when a full view of a type is analyzed, and this is
6368 -- not captured by the analysis of the corresponding type declaration.
6369 -- Therefore the correctness of a not-overriding indicator must be
6370 -- rechecked when the subprogram is frozen.
6372 if Nkind (E) = N_Defining_Operator_Symbol
6373 and then not Error_Posted (Parent (E))
6374 then
6375 Check_Overriding_Indicator (E, Empty, Is_Primitive (E));
6376 end if;
6377 end Freeze_Subprogram;
6379 ----------------------
6380 -- Is_Fully_Defined --
6381 ----------------------
6383 function Is_Fully_Defined (T : Entity_Id) return Boolean is
6384 begin
6385 if Ekind (T) = E_Class_Wide_Type then
6386 return Is_Fully_Defined (Etype (T));
6388 elsif Is_Array_Type (T) then
6389 return Is_Fully_Defined (Component_Type (T));
6391 elsif Is_Record_Type (T)
6392 and not Is_Private_Type (T)
6393 then
6394 -- Verify that the record type has no components with private types
6395 -- without completion.
6397 declare
6398 Comp : Entity_Id;
6400 begin
6401 Comp := First_Component (T);
6402 while Present (Comp) loop
6403 if not Is_Fully_Defined (Etype (Comp)) then
6404 return False;
6405 end if;
6407 Next_Component (Comp);
6408 end loop;
6409 return True;
6410 end;
6412 -- For the designated type of an access to subprogram, all types in
6413 -- the profile must be fully defined.
6415 elsif Ekind (T) = E_Subprogram_Type then
6416 declare
6417 F : Entity_Id;
6419 begin
6420 F := First_Formal (T);
6421 while Present (F) loop
6422 if not Is_Fully_Defined (Etype (F)) then
6423 return False;
6424 end if;
6426 Next_Formal (F);
6427 end loop;
6429 return Is_Fully_Defined (Etype (T));
6430 end;
6432 else
6433 return not Is_Private_Type (T)
6434 or else Present (Full_View (Base_Type (T)));
6435 end if;
6436 end Is_Fully_Defined;
6438 ---------------------------------
6439 -- Process_Default_Expressions --
6440 ---------------------------------
6442 procedure Process_Default_Expressions
6443 (E : Entity_Id;
6444 After : in out Node_Id)
6446 Loc : constant Source_Ptr := Sloc (E);
6447 Dbody : Node_Id;
6448 Formal : Node_Id;
6449 Dcopy : Node_Id;
6450 Dnam : Entity_Id;
6452 begin
6453 Set_Default_Expressions_Processed (E);
6455 -- A subprogram instance and its associated anonymous subprogram share
6456 -- their signature. The default expression functions are defined in the
6457 -- wrapper packages for the anonymous subprogram, and should not be
6458 -- generated again for the instance.
6460 if Is_Generic_Instance (E)
6461 and then Present (Alias (E))
6462 and then Default_Expressions_Processed (Alias (E))
6463 then
6464 return;
6465 end if;
6467 Formal := First_Formal (E);
6468 while Present (Formal) loop
6469 if Present (Default_Value (Formal)) then
6471 -- We work with a copy of the default expression because we
6472 -- do not want to disturb the original, since this would mess
6473 -- up the conformance checking.
6475 Dcopy := New_Copy_Tree (Default_Value (Formal));
6477 -- The analysis of the expression may generate insert actions,
6478 -- which of course must not be executed. We wrap those actions
6479 -- in a procedure that is not called, and later on eliminated.
6480 -- The following cases have no side-effects, and are analyzed
6481 -- directly.
6483 if Nkind (Dcopy) = N_Identifier
6484 or else Nkind (Dcopy) = N_Expanded_Name
6485 or else Nkind (Dcopy) = N_Integer_Literal
6486 or else (Nkind (Dcopy) = N_Real_Literal
6487 and then not Vax_Float (Etype (Dcopy)))
6488 or else Nkind (Dcopy) = N_Character_Literal
6489 or else Nkind (Dcopy) = N_String_Literal
6490 or else Known_Null (Dcopy)
6491 or else (Nkind (Dcopy) = N_Attribute_Reference
6492 and then
6493 Attribute_Name (Dcopy) = Name_Null_Parameter)
6494 then
6496 -- If there is no default function, we must still do a full
6497 -- analyze call on the default value, to ensure that all error
6498 -- checks are performed, e.g. those associated with static
6499 -- evaluation. Note: this branch will always be taken if the
6500 -- analyzer is turned off (but we still need the error checks).
6502 -- Note: the setting of parent here is to meet the requirement
6503 -- that we can only analyze the expression while attached to
6504 -- the tree. Really the requirement is that the parent chain
6505 -- be set, we don't actually need to be in the tree.
6507 Set_Parent (Dcopy, Declaration_Node (Formal));
6508 Analyze (Dcopy);
6510 -- Default expressions are resolved with their own type if the
6511 -- context is generic, to avoid anomalies with private types.
6513 if Ekind (Scope (E)) = E_Generic_Package then
6514 Resolve (Dcopy);
6515 else
6516 Resolve (Dcopy, Etype (Formal));
6517 end if;
6519 -- If that resolved expression will raise constraint error,
6520 -- then flag the default value as raising constraint error.
6521 -- This allows a proper error message on the calls.
6523 if Raises_Constraint_Error (Dcopy) then
6524 Set_Raises_Constraint_Error (Default_Value (Formal));
6525 end if;
6527 -- If the default is a parameterless call, we use the name of
6528 -- the called function directly, and there is no body to build.
6530 elsif Nkind (Dcopy) = N_Function_Call
6531 and then No (Parameter_Associations (Dcopy))
6532 then
6533 null;
6535 -- Else construct and analyze the body of a wrapper procedure
6536 -- that contains an object declaration to hold the expression.
6537 -- Given that this is done only to complete the analysis, it
6538 -- simpler to build a procedure than a function which might
6539 -- involve secondary stack expansion.
6541 else
6542 Dnam := Make_Temporary (Loc, 'D');
6544 Dbody :=
6545 Make_Subprogram_Body (Loc,
6546 Specification =>
6547 Make_Procedure_Specification (Loc,
6548 Defining_Unit_Name => Dnam),
6550 Declarations => New_List (
6551 Make_Object_Declaration (Loc,
6552 Defining_Identifier => Make_Temporary (Loc, 'T'),
6553 Object_Definition =>
6554 New_Occurrence_Of (Etype (Formal), Loc),
6555 Expression => New_Copy_Tree (Dcopy))),
6557 Handled_Statement_Sequence =>
6558 Make_Handled_Sequence_Of_Statements (Loc,
6559 Statements => Empty_List));
6561 Set_Scope (Dnam, Scope (E));
6562 Set_Assignment_OK (First (Declarations (Dbody)));
6563 Set_Is_Eliminated (Dnam);
6564 Insert_After (After, Dbody);
6565 Analyze (Dbody);
6566 After := Dbody;
6567 end if;
6568 end if;
6570 Next_Formal (Formal);
6571 end loop;
6572 end Process_Default_Expressions;
6574 ----------------------------------------
6575 -- Set_Component_Alignment_If_Not_Set --
6576 ----------------------------------------
6578 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
6579 begin
6580 -- Ignore if not base type, subtypes don't need anything
6582 if Typ /= Base_Type (Typ) then
6583 return;
6584 end if;
6586 -- Do not override existing representation
6588 if Is_Packed (Typ) then
6589 return;
6591 elsif Has_Specified_Layout (Typ) then
6592 return;
6594 elsif Component_Alignment (Typ) /= Calign_Default then
6595 return;
6597 else
6598 Set_Component_Alignment
6599 (Typ, Scope_Stack.Table
6600 (Scope_Stack.Last).Component_Alignment_Default);
6601 end if;
6602 end Set_Component_Alignment_If_Not_Set;
6604 ------------------
6605 -- Undelay_Type --
6606 ------------------
6608 procedure Undelay_Type (T : Entity_Id) is
6609 begin
6610 Set_Has_Delayed_Freeze (T, False);
6611 Set_Freeze_Node (T, Empty);
6613 -- Since we don't want T to have a Freeze_Node, we don't want its
6614 -- Full_View or Corresponding_Record_Type to have one either.
6616 -- ??? Fundamentally, this whole handling is a kludge. What we really
6617 -- want is to be sure that for an Itype that's part of record R and is a
6618 -- subtype of type T, that it's frozen after the later of the freeze
6619 -- points of R and T. We have no way of doing that directly, so what we
6620 -- do is force most such Itypes to be frozen as part of freezing R via
6621 -- this procedure and only delay the ones that need to be delayed
6622 -- (mostly the designated types of access types that are defined as part
6623 -- of the record).
6625 if Is_Private_Type (T)
6626 and then Present (Full_View (T))
6627 and then Is_Itype (Full_View (T))
6628 and then Is_Record_Type (Scope (Full_View (T)))
6629 then
6630 Undelay_Type (Full_View (T));
6631 end if;
6633 if Is_Concurrent_Type (T)
6634 and then Present (Corresponding_Record_Type (T))
6635 and then Is_Itype (Corresponding_Record_Type (T))
6636 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
6637 then
6638 Undelay_Type (Corresponding_Record_Type (T));
6639 end if;
6640 end Undelay_Type;
6642 ------------------
6643 -- Warn_Overlay --
6644 ------------------
6646 procedure Warn_Overlay
6647 (Expr : Node_Id;
6648 Typ : Entity_Id;
6649 Nam : Entity_Id)
6651 Ent : constant Entity_Id := Entity (Nam);
6652 -- The object to which the address clause applies
6654 Init : Node_Id;
6655 Old : Entity_Id := Empty;
6656 Decl : Node_Id;
6658 begin
6659 -- No warning if address clause overlay warnings are off
6661 if not Address_Clause_Overlay_Warnings then
6662 return;
6663 end if;
6665 -- No warning if there is an explicit initialization
6667 Init := Original_Node (Expression (Declaration_Node (Ent)));
6669 if Present (Init) and then Comes_From_Source (Init) then
6670 return;
6671 end if;
6673 -- We only give the warning for non-imported entities of a type for
6674 -- which a non-null base init proc is defined, or for objects of access
6675 -- types with implicit null initialization, or when Normalize_Scalars
6676 -- applies and the type is scalar or a string type (the latter being
6677 -- tested for because predefined String types are initialized by inline
6678 -- code rather than by an init_proc). Note that we do not give the
6679 -- warning for Initialize_Scalars, since we suppressed initialization
6680 -- in this case. Also, do not warn if Suppress_Initialization is set.
6682 if Present (Expr)
6683 and then not Is_Imported (Ent)
6684 and then not Initialization_Suppressed (Typ)
6685 and then (Has_Non_Null_Base_Init_Proc (Typ)
6686 or else Is_Access_Type (Typ)
6687 or else (Normalize_Scalars
6688 and then (Is_Scalar_Type (Typ)
6689 or else Is_String_Type (Typ))))
6690 then
6691 if Nkind (Expr) = N_Attribute_Reference
6692 and then Is_Entity_Name (Prefix (Expr))
6693 then
6694 Old := Entity (Prefix (Expr));
6696 elsif Is_Entity_Name (Expr)
6697 and then Ekind (Entity (Expr)) = E_Constant
6698 then
6699 Decl := Declaration_Node (Entity (Expr));
6701 if Nkind (Decl) = N_Object_Declaration
6702 and then Present (Expression (Decl))
6703 and then Nkind (Expression (Decl)) = N_Attribute_Reference
6704 and then Is_Entity_Name (Prefix (Expression (Decl)))
6705 then
6706 Old := Entity (Prefix (Expression (Decl)));
6708 elsif Nkind (Expr) = N_Function_Call then
6709 return;
6710 end if;
6712 -- A function call (most likely to To_Address) is probably not an
6713 -- overlay, so skip warning. Ditto if the function call was inlined
6714 -- and transformed into an entity.
6716 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
6717 return;
6718 end if;
6720 Decl := Next (Parent (Expr));
6722 -- If a pragma Import follows, we assume that it is for the current
6723 -- target of the address clause, and skip the warning.
6725 if Present (Decl)
6726 and then Nkind (Decl) = N_Pragma
6727 and then Pragma_Name (Decl) = Name_Import
6728 then
6729 return;
6730 end if;
6732 if Present (Old) then
6733 Error_Msg_Node_2 := Old;
6734 Error_Msg_N
6735 ("default initialization of & may modify &??",
6736 Nam);
6737 else
6738 Error_Msg_N
6739 ("default initialization of & may modify overlaid storage??",
6740 Nam);
6741 end if;
6743 -- Add friendly warning if initialization comes from a packed array
6744 -- component.
6746 if Is_Record_Type (Typ) then
6747 declare
6748 Comp : Entity_Id;
6750 begin
6751 Comp := First_Component (Typ);
6752 while Present (Comp) loop
6753 if Nkind (Parent (Comp)) = N_Component_Declaration
6754 and then Present (Expression (Parent (Comp)))
6755 then
6756 exit;
6757 elsif Is_Array_Type (Etype (Comp))
6758 and then Present (Packed_Array_Type (Etype (Comp)))
6759 then
6760 Error_Msg_NE
6761 ("\packed array component& " &
6762 "will be initialized to zero??",
6763 Nam, Comp);
6764 exit;
6765 else
6766 Next_Component (Comp);
6767 end if;
6768 end loop;
6769 end;
6770 end if;
6772 Error_Msg_N
6773 ("\use pragma Import for & to " &
6774 "suppress initialization (RM B.1(24))??",
6775 Nam);
6776 end if;
6777 end Warn_Overlay;
6779 end Freeze;