Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / freeze.adb
blob8a5b927c570c3024d254d2852b427e5b0a95016c
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));
3364 -- Note that we rewrite Init_Stmts into a NULL statement,
3365 -- rather than just removing it, because Freeze_All may
3366 -- depend on this particular Node_Id still being present
3367 -- in the enclosing list to signal where to stop
3368 -- freezing.
3370 Rewrite (Init_Stmts,
3371 Make_Null_Statement (Sloc (Init_Stmts)));
3373 Set_Initialization_Statements (E, Empty);
3374 end if;
3375 end;
3376 end if;
3378 end if;
3380 -- Case of a type or subtype being frozen
3382 else
3383 -- We used to check here that a full type must have preelaborable
3384 -- initialization if it completes a private type specified with
3385 -- pragma Preelaborable_Initialization, but that missed cases where
3386 -- the types occur within a generic package, since the freezing
3387 -- that occurs within a containing scope generally skips traversal
3388 -- of a generic unit's declarations (those will be frozen within
3389 -- instances). This check was moved to Analyze_Package_Specification.
3391 -- The type may be defined in a generic unit. This can occur when
3392 -- freezing a generic function that returns the type (which is
3393 -- defined in a parent unit). It is clearly meaningless to freeze
3394 -- this type. However, if it is a subtype, its size may be determi-
3395 -- nable and used in subsequent checks, so might as well try to
3396 -- compute it.
3398 -- In Ada 2012, Freeze_Entities is also used in the front end to
3399 -- trigger the analysis of aspect expressions, so in this case we
3400 -- want to continue the freezing process.
3402 if Present (Scope (E))
3403 and then Is_Generic_Unit (Scope (E))
3404 and then not Has_Predicates (E)
3405 then
3406 Check_Compile_Time_Size (E);
3407 return No_List;
3408 end if;
3410 -- Deal with special cases of freezing for subtype
3412 if E /= Base_Type (E) then
3414 -- Before we do anything else, a specialized test for the case of
3415 -- a size given for an array where the array needs to be packed,
3416 -- but was not so the size cannot be honored. This is the case
3417 -- where implicit packing may apply. The reason we do this so
3418 -- early is that if we have implicit packing, the layout of the
3419 -- base type is affected, so we must do this before we freeze
3420 -- the base type.
3422 -- We could do this processing only if implicit packing is enabled
3423 -- since in all other cases, the error would be caught by the back
3424 -- end. However, we choose to do the check even if we do not have
3425 -- implicit packing enabled, since this allows us to give a more
3426 -- useful error message (advising use of pragmas Implicit_Packing
3427 -- or Pack).
3429 if Is_Array_Type (E) then
3430 declare
3431 Ctyp : constant Entity_Id := Component_Type (E);
3432 Rsiz : constant Uint := RM_Size (Ctyp);
3433 SZ : constant Node_Id := Size_Clause (E);
3434 Btyp : constant Entity_Id := Base_Type (E);
3436 Lo : Node_Id;
3437 Hi : Node_Id;
3438 Indx : Node_Id;
3440 Num_Elmts : Uint;
3441 -- Number of elements in array
3443 begin
3444 -- Check enabling conditions. These are straightforward
3445 -- except for the test for a limited composite type. This
3446 -- eliminates the rare case of a array of limited components
3447 -- where there are issues of whether or not we can go ahead
3448 -- and pack the array (since we can't freely pack and unpack
3449 -- arrays if they are limited).
3451 -- Note that we check the root type explicitly because the
3452 -- whole point is we are doing this test before we have had
3453 -- a chance to freeze the base type (and it is that freeze
3454 -- action that causes stuff to be inherited).
3456 if Has_Size_Clause (E)
3457 and then Known_Static_RM_Size (E)
3458 and then not Is_Packed (E)
3459 and then not Has_Pragma_Pack (E)
3460 and then not Has_Component_Size_Clause (E)
3461 and then Known_Static_RM_Size (Ctyp)
3462 and then RM_Size (Ctyp) < 64
3463 and then not Is_Limited_Composite (E)
3464 and then not Is_Packed (Root_Type (E))
3465 and then not Has_Component_Size_Clause (Root_Type (E))
3466 and then not (CodePeer_Mode or SPARK_Mode)
3467 then
3468 -- Compute number of elements in array
3470 Num_Elmts := Uint_1;
3471 Indx := First_Index (E);
3472 while Present (Indx) loop
3473 Get_Index_Bounds (Indx, Lo, Hi);
3475 if not (Compile_Time_Known_Value (Lo)
3476 and then
3477 Compile_Time_Known_Value (Hi))
3478 then
3479 goto No_Implicit_Packing;
3480 end if;
3482 Num_Elmts :=
3483 Num_Elmts *
3484 UI_Max (Uint_0,
3485 Expr_Value (Hi) - Expr_Value (Lo) + 1);
3486 Next_Index (Indx);
3487 end loop;
3489 -- What we are looking for here is the situation where
3490 -- the RM_Size given would be exactly right if there was
3491 -- a pragma Pack (resulting in the component size being
3492 -- the same as the RM_Size). Furthermore, the component
3493 -- type size must be an odd size (not a multiple of
3494 -- storage unit). If the component RM size is an exact
3495 -- number of storage units that is a power of two, the
3496 -- array is not packed and has a standard representation.
3498 if RM_Size (E) = Num_Elmts * Rsiz
3499 and then Rsiz mod System_Storage_Unit /= 0
3500 then
3501 -- For implicit packing mode, just set the component
3502 -- size silently.
3504 if Implicit_Packing then
3505 Set_Component_Size (Btyp, Rsiz);
3506 Set_Is_Bit_Packed_Array (Btyp);
3507 Set_Is_Packed (Btyp);
3508 Set_Has_Non_Standard_Rep (Btyp);
3510 -- Otherwise give an error message
3512 else
3513 Error_Msg_NE
3514 ("size given for& too small", SZ, E);
3515 Error_Msg_N -- CODEFIX
3516 ("\use explicit pragma Pack "
3517 & "or use pragma Implicit_Packing", SZ);
3518 end if;
3520 elsif RM_Size (E) = Num_Elmts * Rsiz
3521 and then Implicit_Packing
3522 and then
3523 (Rsiz / System_Storage_Unit = 1
3524 or else
3525 Rsiz / System_Storage_Unit = 2
3526 or else
3527 Rsiz / System_Storage_Unit = 4)
3528 then
3529 -- Not a packed array, but indicate the desired
3530 -- component size, for the back-end.
3532 Set_Component_Size (Btyp, Rsiz);
3533 end if;
3534 end if;
3535 end;
3536 end if;
3538 <<No_Implicit_Packing>>
3540 -- If ancestor subtype present, freeze that first. Note that this
3541 -- will also get the base type frozen. Need RM reference ???
3543 Atype := Ancestor_Subtype (E);
3545 if Present (Atype) then
3546 Freeze_And_Append (Atype, N, Result);
3548 -- No ancestor subtype present
3550 else
3551 -- See if we have a nearest ancestor that has a predicate.
3552 -- That catches the case of derived type with a predicate.
3553 -- Need RM reference here ???
3555 Atype := Nearest_Ancestor (E);
3557 if Present (Atype) and then Has_Predicates (Atype) then
3558 Freeze_And_Append (Atype, N, Result);
3559 end if;
3561 -- Freeze base type before freezing the entity (RM 13.14(15))
3563 if E /= Base_Type (E) then
3564 Freeze_And_Append (Base_Type (E), N, Result);
3565 end if;
3566 end if;
3568 -- A subtype inherits all the type-related representation aspects
3569 -- from its parents (RM 13.1(8)).
3571 Inherit_Aspects_At_Freeze_Point (E);
3573 -- For a derived type, freeze its parent type first (RM 13.14(15))
3575 elsif Is_Derived_Type (E) then
3576 Freeze_And_Append (Etype (E), N, Result);
3577 Freeze_And_Append (First_Subtype (Etype (E)), N, Result);
3579 -- A derived type inherits each type-related representation aspect
3580 -- of its parent type that was directly specified before the
3581 -- declaration of the derived type (RM 13.1(15)).
3583 Inherit_Aspects_At_Freeze_Point (E);
3584 end if;
3586 -- For array type, freeze index types and component type first
3587 -- before freezing the array (RM 13.14(15)).
3589 if Is_Array_Type (E) then
3590 declare
3591 FS : constant Entity_Id := First_Subtype (E);
3592 Ctyp : constant Entity_Id := Component_Type (E);
3593 Clause : Entity_Id;
3595 Non_Standard_Enum : Boolean := False;
3596 -- Set true if any of the index types is an enumeration type
3597 -- with a non-standard representation.
3599 begin
3600 Freeze_And_Append (Ctyp, N, Result);
3602 Indx := First_Index (E);
3603 while Present (Indx) loop
3604 Freeze_And_Append (Etype (Indx), N, Result);
3606 if Is_Enumeration_Type (Etype (Indx))
3607 and then Has_Non_Standard_Rep (Etype (Indx))
3608 then
3609 Non_Standard_Enum := True;
3610 end if;
3612 Next_Index (Indx);
3613 end loop;
3615 -- Processing that is done only for base types
3617 if Ekind (E) = E_Array_Type then
3619 -- Propagate flags for component type
3621 if Is_Controlled (Component_Type (E))
3622 or else Has_Controlled_Component (Ctyp)
3623 then
3624 Set_Has_Controlled_Component (E);
3625 end if;
3627 if Has_Unchecked_Union (Component_Type (E)) then
3628 Set_Has_Unchecked_Union (E);
3629 end if;
3631 -- If packing was requested or if the component size was set
3632 -- explicitly, then see if bit packing is required. This
3633 -- processing is only done for base types, since all the
3634 -- representation aspects involved are type-related. This
3635 -- is not just an optimization, if we start processing the
3636 -- subtypes, they interfere with the settings on the base
3637 -- type (this is because Is_Packed has a slightly different
3638 -- meaning before and after freezing).
3640 declare
3641 Csiz : Uint;
3642 Esiz : Uint;
3644 begin
3645 if (Is_Packed (E) or else Has_Pragma_Pack (E))
3646 and then Known_Static_RM_Size (Ctyp)
3647 and then not Has_Component_Size_Clause (E)
3648 then
3649 Csiz := UI_Max (RM_Size (Ctyp), 1);
3651 elsif Known_Component_Size (E) then
3652 Csiz := Component_Size (E);
3654 elsif not Known_Static_Esize (Ctyp) then
3655 Csiz := Uint_0;
3657 else
3658 Esiz := Esize (Ctyp);
3660 -- We can set the component size if it is less than
3661 -- 16, rounding it up to the next storage unit size.
3663 if Esiz <= 8 then
3664 Csiz := Uint_8;
3665 elsif Esiz <= 16 then
3666 Csiz := Uint_16;
3667 else
3668 Csiz := Uint_0;
3669 end if;
3671 -- Set component size up to match alignment if it
3672 -- would otherwise be less than the alignment. This
3673 -- deals with cases of types whose alignment exceeds
3674 -- their size (padded types).
3676 if Csiz /= 0 then
3677 declare
3678 A : constant Uint := Alignment_In_Bits (Ctyp);
3679 begin
3680 if Csiz < A then
3681 Csiz := A;
3682 end if;
3683 end;
3684 end if;
3685 end if;
3687 -- Case of component size that may result in packing
3689 if 1 <= Csiz and then Csiz <= 64 then
3690 declare
3691 Ent : constant Entity_Id :=
3692 First_Subtype (E);
3693 Pack_Pragma : constant Node_Id :=
3694 Get_Rep_Pragma (Ent, Name_Pack);
3695 Comp_Size_C : constant Node_Id :=
3696 Get_Attribute_Definition_Clause
3697 (Ent, Attribute_Component_Size);
3698 begin
3699 -- Warn if we have pack and component size so that
3700 -- the pack is ignored.
3702 -- Note: here we must check for the presence of a
3703 -- component size before checking for a Pack pragma
3704 -- to deal with the case where the array type is a
3705 -- derived type whose parent is currently private.
3707 if Present (Comp_Size_C)
3708 and then Has_Pragma_Pack (Ent)
3709 and then Warn_On_Redundant_Constructs
3710 then
3711 Error_Msg_Sloc := Sloc (Comp_Size_C);
3712 Error_Msg_NE
3713 ("?r?pragma Pack for& ignored!",
3714 Pack_Pragma, Ent);
3715 Error_Msg_N
3716 ("\?r?explicit component size given#!",
3717 Pack_Pragma);
3718 Set_Is_Packed (Base_Type (Ent), False);
3719 Set_Is_Bit_Packed_Array (Base_Type (Ent), False);
3720 end if;
3722 -- Set component size if not already set by a
3723 -- component size clause.
3725 if not Present (Comp_Size_C) then
3726 Set_Component_Size (E, Csiz);
3727 end if;
3729 -- Check for base type of 8, 16, 32 bits, where an
3730 -- unsigned subtype has a length one less than the
3731 -- base type (e.g. Natural subtype of Integer).
3733 -- In such cases, if a component size was not set
3734 -- explicitly, then generate a warning.
3736 if Has_Pragma_Pack (E)
3737 and then not Present (Comp_Size_C)
3738 and then
3739 (Csiz = 7 or else Csiz = 15 or else Csiz = 31)
3740 and then Esize (Base_Type (Ctyp)) = Csiz + 1
3741 then
3742 Error_Msg_Uint_1 := Csiz;
3744 if Present (Pack_Pragma) then
3745 Error_Msg_N
3746 ("??pragma Pack causes component size "
3747 & "to be ^!", Pack_Pragma);
3748 Error_Msg_N
3749 ("\??use Component_Size to set "
3750 & "desired value!", Pack_Pragma);
3751 end if;
3752 end if;
3754 -- Actual packing is not needed for 8, 16, 32, 64.
3755 -- Also not needed for 24 if alignment is 1.
3757 if Csiz = 8
3758 or else Csiz = 16
3759 or else Csiz = 32
3760 or else Csiz = 64
3761 or else (Csiz = 24 and then Alignment (Ctyp) = 1)
3762 then
3763 -- Here the array was requested to be packed,
3764 -- but the packing request had no effect, so
3765 -- Is_Packed is reset.
3767 -- Note: semantically this means that we lose
3768 -- track of the fact that a derived type
3769 -- inherited a pragma Pack that was non-
3770 -- effective, but that seems fine.
3772 -- We regard a Pack pragma as a request to set
3773 -- a representation characteristic, and this
3774 -- request may be ignored.
3776 Set_Is_Packed (Base_Type (E), False);
3777 Set_Is_Bit_Packed_Array (Base_Type (E), False);
3779 if Known_Static_Esize (Component_Type (E))
3780 and then Esize (Component_Type (E)) = Csiz
3781 then
3782 Set_Has_Non_Standard_Rep
3783 (Base_Type (E), False);
3784 end if;
3786 -- In all other cases, packing is indeed needed
3788 else
3789 Set_Has_Non_Standard_Rep (Base_Type (E), True);
3790 Set_Is_Bit_Packed_Array (Base_Type (E), True);
3791 Set_Is_Packed (Base_Type (E), True);
3792 end if;
3793 end;
3794 end if;
3795 end;
3797 -- Check for Atomic_Components or Aliased with unsuitable
3798 -- packing or explicit component size clause given.
3800 if (Has_Atomic_Components (E)
3801 or else Has_Aliased_Components (E))
3802 and then (Has_Component_Size_Clause (E)
3803 or else Is_Packed (E))
3804 then
3805 Alias_Atomic_Check : declare
3807 procedure Complain_CS (T : String);
3808 -- Outputs error messages for incorrect CS clause or
3809 -- pragma Pack for aliased or atomic components (T is
3810 -- "aliased" or "atomic");
3812 -----------------
3813 -- Complain_CS --
3814 -----------------
3816 procedure Complain_CS (T : String) is
3817 begin
3818 if Has_Component_Size_Clause (E) then
3819 Clause :=
3820 Get_Attribute_Definition_Clause
3821 (FS, Attribute_Component_Size);
3823 if Known_Static_Esize (Ctyp) then
3824 Error_Msg_N
3825 ("incorrect component size for "
3826 & T & " components", Clause);
3827 Error_Msg_Uint_1 := Esize (Ctyp);
3828 Error_Msg_N
3829 ("\only allowed value is^", Clause);
3831 else
3832 Error_Msg_N
3833 ("component size cannot be given for "
3834 & T & " components", Clause);
3835 end if;
3837 else
3838 Error_Msg_N
3839 ("cannot pack " & T & " components",
3840 Get_Rep_Pragma (FS, Name_Pack));
3841 end if;
3843 return;
3844 end Complain_CS;
3846 -- Start of processing for Alias_Atomic_Check
3848 begin
3850 -- If object size of component type isn't known, we
3851 -- cannot be sure so we defer to the back end.
3853 if not Known_Static_Esize (Ctyp) then
3854 null;
3856 -- Case where component size has no effect. First
3857 -- check for object size of component type multiple
3858 -- of the storage unit size.
3860 elsif Esize (Ctyp) mod System_Storage_Unit = 0
3862 -- OK in both packing case and component size case
3863 -- if RM size is known and static and the same as
3864 -- the object size.
3866 and then
3867 ((Known_Static_RM_Size (Ctyp)
3868 and then Esize (Ctyp) = RM_Size (Ctyp))
3870 -- Or if we have an explicit component size
3871 -- clause and the component size and object size
3872 -- are equal.
3874 or else
3875 (Has_Component_Size_Clause (E)
3876 and then Component_Size (E) = Esize (Ctyp)))
3877 then
3878 null;
3880 elsif Has_Aliased_Components (E)
3881 or else Is_Aliased (Ctyp)
3882 then
3883 Complain_CS ("aliased");
3885 elsif Has_Atomic_Components (E)
3886 or else Is_Atomic (Ctyp)
3887 then
3888 Complain_CS ("atomic");
3889 end if;
3890 end Alias_Atomic_Check;
3891 end if;
3893 -- Warn for case of atomic type
3895 Clause := Get_Rep_Pragma (FS, Name_Atomic);
3897 if Present (Clause)
3898 and then not Addressable (Component_Size (FS))
3899 then
3900 Error_Msg_NE
3901 ("non-atomic components of type& may not be "
3902 & "accessible by separate tasks??", Clause, E);
3904 if Has_Component_Size_Clause (E) then
3905 Error_Msg_Sloc :=
3906 Sloc
3907 (Get_Attribute_Definition_Clause
3908 (FS, Attribute_Component_Size));
3909 Error_Msg_N
3910 ("\because of component size clause#??",
3911 Clause);
3913 elsif Has_Pragma_Pack (E) then
3914 Error_Msg_Sloc :=
3915 Sloc (Get_Rep_Pragma (FS, Name_Pack));
3916 Error_Msg_N
3917 ("\because of pragma Pack#??", Clause);
3918 end if;
3919 end if;
3921 -- Check for scalar storage order
3923 if Present (Get_Attribute_Definition_Clause
3924 (E, Attribute_Scalar_Storage_Order))
3925 then
3926 Check_Component_Storage_Order (E, Empty);
3927 end if;
3929 -- Processing that is done only for subtypes
3931 else
3932 -- Acquire alignment from base type
3934 if Unknown_Alignment (E) then
3935 Set_Alignment (E, Alignment (Base_Type (E)));
3936 Adjust_Esize_Alignment (E);
3937 end if;
3938 end if;
3940 -- Specific checks for bit-packed arrays
3942 if Is_Bit_Packed_Array (E) then
3944 -- Check number of elements for bit packed arrays that come
3945 -- from source and have compile time known ranges. The
3946 -- bit-packed arrays circuitry does not support arrays
3947 -- with more than Integer'Last + 1 elements, and when this
3948 -- restriction is violated, causes incorrect data access.
3950 -- For the case where this is not compile time known, a
3951 -- run-time check should be generated???
3953 if Comes_From_Source (E) and then Is_Constrained (E) then
3954 declare
3955 Elmts : Uint;
3956 Index : Node_Id;
3957 Ilen : Node_Id;
3958 Ityp : Entity_Id;
3960 begin
3961 Elmts := Uint_1;
3962 Index := First_Index (E);
3963 while Present (Index) loop
3964 Ityp := Etype (Index);
3966 -- Never generate an error if any index is of a
3967 -- generic type. We will check this in instances.
3969 if Is_Generic_Type (Ityp) then
3970 Elmts := Uint_0;
3971 exit;
3972 end if;
3974 Ilen :=
3975 Make_Attribute_Reference (Loc,
3976 Prefix =>
3977 New_Occurrence_Of (Ityp, Loc),
3978 Attribute_Name => Name_Range_Length);
3979 Analyze_And_Resolve (Ilen);
3981 -- No attempt is made to check number of elements
3982 -- if not compile time known.
3984 if Nkind (Ilen) /= N_Integer_Literal then
3985 Elmts := Uint_0;
3986 exit;
3987 end if;
3989 Elmts := Elmts * Intval (Ilen);
3990 Next_Index (Index);
3991 end loop;
3993 if Elmts > Intval (High_Bound
3994 (Scalar_Range
3995 (Standard_Integer))) + 1
3996 then
3997 Error_Msg_N
3998 ("bit packed array type may not have "
3999 & "more than Integer''Last+1 elements", E);
4000 end if;
4001 end;
4002 end if;
4004 -- Check size
4006 if Known_RM_Size (E) then
4007 declare
4008 SizC : constant Node_Id := Size_Clause (E);
4010 Discard : Boolean;
4011 pragma Warnings (Off, Discard);
4013 begin
4014 -- It is not clear if it is possible to have no size
4015 -- clause at this stage, but it is not worth worrying
4016 -- about. Post error on the entity name in the size
4017 -- clause if present, else on the type entity itself.
4019 if Present (SizC) then
4020 Check_Size (Name (SizC), E, RM_Size (E), Discard);
4021 else
4022 Check_Size (E, E, RM_Size (E), Discard);
4023 end if;
4024 end;
4025 end if;
4026 end if;
4028 -- If any of the index types was an enumeration type with a
4029 -- non-standard rep clause, then we indicate that the array
4030 -- type is always packed (even if it is not bit packed).
4032 if Non_Standard_Enum then
4033 Set_Has_Non_Standard_Rep (Base_Type (E));
4034 Set_Is_Packed (Base_Type (E));
4035 end if;
4037 Set_Component_Alignment_If_Not_Set (E);
4039 -- If the array is packed, we must create the packed array
4040 -- type to be used to actually implement the type. This is
4041 -- only needed for real array types (not for string literal
4042 -- types, since they are present only for the front end).
4044 if Is_Packed (E)
4045 and then Ekind (E) /= E_String_Literal_Subtype
4046 then
4047 Create_Packed_Array_Type (E);
4048 Freeze_And_Append (Packed_Array_Type (E), N, Result);
4050 -- Size information of packed array type is copied to the
4051 -- array type, since this is really the representation. But
4052 -- do not override explicit existing size values. If the
4053 -- ancestor subtype is constrained the packed_array_type
4054 -- will be inherited from it, but the size may have been
4055 -- provided already, and must not be overridden either.
4057 if not Has_Size_Clause (E)
4058 and then
4059 (No (Ancestor_Subtype (E))
4060 or else not Has_Size_Clause (Ancestor_Subtype (E)))
4061 then
4062 Set_Esize (E, Esize (Packed_Array_Type (E)));
4063 Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
4064 end if;
4066 if not Has_Alignment_Clause (E) then
4067 Set_Alignment (E, Alignment (Packed_Array_Type (E)));
4068 end if;
4069 end if;
4071 -- For non-packed arrays set the alignment of the array to the
4072 -- alignment of the component type if it is unknown. Skip this
4073 -- in atomic case (atomic arrays may need larger alignments).
4075 if not Is_Packed (E)
4076 and then Unknown_Alignment (E)
4077 and then Known_Alignment (Ctyp)
4078 and then Known_Static_Component_Size (E)
4079 and then Known_Static_Esize (Ctyp)
4080 and then Esize (Ctyp) = Component_Size (E)
4081 and then not Is_Atomic (E)
4082 then
4083 Set_Alignment (E, Alignment (Component_Type (E)));
4084 end if;
4085 end;
4087 -- For a class-wide type, the corresponding specific type is
4088 -- frozen as well (RM 13.14(15))
4090 elsif Is_Class_Wide_Type (E) then
4091 Freeze_And_Append (Root_Type (E), N, Result);
4093 -- If the base type of the class-wide type is still incomplete,
4094 -- the class-wide remains unfrozen as well. This is legal when
4095 -- E is the formal of a primitive operation of some other type
4096 -- which is being frozen.
4098 if not Is_Frozen (Root_Type (E)) then
4099 Set_Is_Frozen (E, False);
4100 return Result;
4101 end if;
4103 -- The equivalent type associated with a class-wide subtype needs
4104 -- to be frozen to ensure that its layout is done.
4106 if Ekind (E) = E_Class_Wide_Subtype
4107 and then Present (Equivalent_Type (E))
4108 then
4109 Freeze_And_Append (Equivalent_Type (E), N, Result);
4110 end if;
4112 -- Generate an itype reference for a library-level class-wide type
4113 -- at the freeze point. Otherwise the first explicit reference to
4114 -- the type may appear in an inner scope which will be rejected by
4115 -- the back-end.
4117 if Is_Itype (E)
4118 and then Is_Compilation_Unit (Scope (E))
4119 then
4120 declare
4121 Ref : constant Node_Id := Make_Itype_Reference (Loc);
4123 begin
4124 Set_Itype (Ref, E);
4126 -- From a gigi point of view, a class-wide subtype derives
4127 -- from its record equivalent type. As a result, the itype
4128 -- reference must appear after the freeze node of the
4129 -- equivalent type or gigi will reject the reference.
4131 if Ekind (E) = E_Class_Wide_Subtype
4132 and then Present (Equivalent_Type (E))
4133 then
4134 Insert_After (Freeze_Node (Equivalent_Type (E)), Ref);
4135 else
4136 Add_To_Result (Ref);
4137 end if;
4138 end;
4139 end if;
4141 -- For a record type or record subtype, freeze all component types
4142 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4143 -- using Is_Record_Type, because we don't want to attempt the freeze
4144 -- for the case of a private type with record extension (we will do
4145 -- that later when the full type is frozen).
4147 elsif Ekind_In (E, E_Record_Type, E_Record_Subtype) then
4148 Freeze_Record_Type (E);
4150 -- For a concurrent type, freeze corresponding record type. This
4151 -- does not correspond to any specific rule in the RM, but the
4152 -- record type is essentially part of the concurrent type.
4153 -- Freeze as well all local entities. This includes record types
4154 -- created for entry parameter blocks, and whatever local entities
4155 -- may appear in the private part.
4157 elsif Is_Concurrent_Type (E) then
4158 if Present (Corresponding_Record_Type (E)) then
4159 Freeze_And_Append
4160 (Corresponding_Record_Type (E), N, Result);
4161 end if;
4163 Comp := First_Entity (E);
4164 while Present (Comp) loop
4165 if Is_Type (Comp) then
4166 Freeze_And_Append (Comp, N, Result);
4168 elsif (Ekind (Comp)) /= E_Function then
4169 if Is_Itype (Etype (Comp))
4170 and then Underlying_Type (Scope (Etype (Comp))) = E
4171 then
4172 Undelay_Type (Etype (Comp));
4173 end if;
4175 Freeze_And_Append (Etype (Comp), N, Result);
4176 end if;
4178 Next_Entity (Comp);
4179 end loop;
4181 -- Private types are required to point to the same freeze node as
4182 -- their corresponding full views. The freeze node itself has to
4183 -- point to the partial view of the entity (because from the partial
4184 -- view, we can retrieve the full view, but not the reverse).
4185 -- However, in order to freeze correctly, we need to freeze the full
4186 -- view. If we are freezing at the end of a scope (or within the
4187 -- scope of the private type), the partial and full views will have
4188 -- been swapped, the full view appears first in the entity chain and
4189 -- the swapping mechanism ensures that the pointers are properly set
4190 -- (on scope exit).
4192 -- If we encounter the partial view before the full view (e.g. when
4193 -- freezing from another scope), we freeze the full view, and then
4194 -- set the pointers appropriately since we cannot rely on swapping to
4195 -- fix things up (subtypes in an outer scope might not get swapped).
4197 elsif Is_Incomplete_Or_Private_Type (E)
4198 and then not Is_Generic_Type (E)
4199 then
4200 -- The construction of the dispatch table associated with library
4201 -- level tagged types forces freezing of all the primitives of the
4202 -- type, which may cause premature freezing of the partial view.
4203 -- For example:
4205 -- package Pkg is
4206 -- type T is tagged private;
4207 -- type DT is new T with private;
4208 -- procedure Prim (X : in out T; Y : in out DT'Class);
4209 -- private
4210 -- type T is tagged null record;
4211 -- Obj : T;
4212 -- type DT is new T with null record;
4213 -- end;
4215 -- In this case the type will be frozen later by the usual
4216 -- mechanism: an object declaration, an instantiation, or the
4217 -- end of a declarative part.
4219 if Is_Library_Level_Tagged_Type (E)
4220 and then not Present (Full_View (E))
4221 then
4222 Set_Is_Frozen (E, False);
4223 return Result;
4225 -- Case of full view present
4227 elsif Present (Full_View (E)) then
4229 -- If full view has already been frozen, then no further
4230 -- processing is required
4232 if Is_Frozen (Full_View (E)) then
4233 Set_Has_Delayed_Freeze (E, False);
4234 Set_Freeze_Node (E, Empty);
4235 Check_Debug_Info_Needed (E);
4237 -- Otherwise freeze full view and patch the pointers so that
4238 -- the freeze node will elaborate both views in the back-end.
4240 else
4241 declare
4242 Full : constant Entity_Id := Full_View (E);
4244 begin
4245 if Is_Private_Type (Full)
4246 and then Present (Underlying_Full_View (Full))
4247 then
4248 Freeze_And_Append
4249 (Underlying_Full_View (Full), N, Result);
4250 end if;
4252 Freeze_And_Append (Full, N, Result);
4254 if Has_Delayed_Freeze (E) then
4255 F_Node := Freeze_Node (Full);
4257 if Present (F_Node) then
4258 Set_Freeze_Node (E, F_Node);
4259 Set_Entity (F_Node, E);
4261 else
4262 -- {Incomplete,Private}_Subtypes with Full_Views
4263 -- constrained by discriminants.
4265 Set_Has_Delayed_Freeze (E, False);
4266 Set_Freeze_Node (E, Empty);
4267 end if;
4268 end if;
4269 end;
4271 Check_Debug_Info_Needed (E);
4272 end if;
4274 -- AI-117 requires that the convention of a partial view be the
4275 -- same as the convention of the full view. Note that this is a
4276 -- recognized breach of privacy, but it's essential for logical
4277 -- consistency of representation, and the lack of a rule in
4278 -- RM95 was an oversight.
4280 Set_Convention (E, Convention (Full_View (E)));
4282 Set_Size_Known_At_Compile_Time (E,
4283 Size_Known_At_Compile_Time (Full_View (E)));
4285 -- Size information is copied from the full view to the
4286 -- incomplete or private view for consistency.
4288 -- We skip this is the full view is not a type. This is very
4289 -- strange of course, and can only happen as a result of
4290 -- certain illegalities, such as a premature attempt to derive
4291 -- from an incomplete type.
4293 if Is_Type (Full_View (E)) then
4294 Set_Size_Info (E, Full_View (E));
4295 Set_RM_Size (E, RM_Size (Full_View (E)));
4296 end if;
4298 return Result;
4300 -- Case of no full view present. If entity is derived or subtype,
4301 -- it is safe to freeze, correctness depends on the frozen status
4302 -- of parent. Otherwise it is either premature usage, or a Taft
4303 -- amendment type, so diagnosis is at the point of use and the
4304 -- type might be frozen later.
4306 elsif E /= Base_Type (E)
4307 or else Is_Derived_Type (E)
4308 then
4309 null;
4311 else
4312 Set_Is_Frozen (E, False);
4313 return No_List;
4314 end if;
4316 -- For access subprogram, freeze types of all formals, the return
4317 -- type was already frozen, since it is the Etype of the function.
4318 -- Formal types can be tagged Taft amendment types, but otherwise
4319 -- they cannot be incomplete.
4321 elsif Ekind (E) = E_Subprogram_Type then
4322 Formal := First_Formal (E);
4323 while Present (Formal) loop
4324 if Ekind (Etype (Formal)) = E_Incomplete_Type
4325 and then No (Full_View (Etype (Formal)))
4326 and then not Is_Value_Type (Etype (Formal))
4327 then
4328 if Is_Tagged_Type (Etype (Formal)) then
4329 null;
4331 -- AI05-151: Incomplete types are allowed in access to
4332 -- subprogram specifications.
4334 elsif Ada_Version < Ada_2012 then
4335 Error_Msg_NE
4336 ("invalid use of incomplete type&", E, Etype (Formal));
4337 end if;
4338 end if;
4340 Freeze_And_Append (Etype (Formal), N, Result);
4341 Next_Formal (Formal);
4342 end loop;
4344 Freeze_Subprogram (E);
4346 -- For access to a protected subprogram, freeze the equivalent type
4347 -- (however this is not set if we are not generating code or if this
4348 -- is an anonymous type used just for resolution).
4350 elsif Is_Access_Protected_Subprogram_Type (E) then
4351 if Present (Equivalent_Type (E)) then
4352 Freeze_And_Append (Equivalent_Type (E), N, Result);
4353 end if;
4354 end if;
4356 -- Generic types are never seen by the back-end, and are also not
4357 -- processed by the expander (since the expander is turned off for
4358 -- generic processing), so we never need freeze nodes for them.
4360 if Is_Generic_Type (E) then
4361 return Result;
4362 end if;
4364 -- Some special processing for non-generic types to complete
4365 -- representation details not known till the freeze point.
4367 if Is_Fixed_Point_Type (E) then
4368 Freeze_Fixed_Point_Type (E);
4370 -- Some error checks required for ordinary fixed-point type. Defer
4371 -- these till the freeze-point since we need the small and range
4372 -- values. We only do these checks for base types
4374 if Is_Ordinary_Fixed_Point_Type (E) and then Is_Base_Type (E) then
4375 if Small_Value (E) < Ureal_2_M_80 then
4376 Error_Msg_Name_1 := Name_Small;
4377 Error_Msg_N
4378 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E);
4380 elsif Small_Value (E) > Ureal_2_80 then
4381 Error_Msg_Name_1 := Name_Small;
4382 Error_Msg_N
4383 ("`&''%` too large, maximum allowed is 2.0'*'*80", E);
4384 end if;
4386 if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
4387 Error_Msg_Name_1 := Name_First;
4388 Error_Msg_N
4389 ("`&''%` too small, minimum allowed is -10.0'*'*36", E);
4390 end if;
4392 if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
4393 Error_Msg_Name_1 := Name_Last;
4394 Error_Msg_N
4395 ("`&''%` too large, maximum allowed is 10.0'*'*36", E);
4396 end if;
4397 end if;
4399 elsif Is_Enumeration_Type (E) then
4400 Freeze_Enumeration_Type (E);
4402 elsif Is_Integer_Type (E) then
4403 Adjust_Esize_For_Alignment (E);
4405 if Is_Modular_Integer_Type (E)
4406 and then Warn_On_Suspicious_Modulus_Value
4407 then
4408 Check_Suspicious_Modulus (E);
4409 end if;
4411 elsif Is_Access_Type (E)
4412 and then not Is_Access_Subprogram_Type (E)
4413 then
4414 -- If a pragma Default_Storage_Pool applies, and this type has no
4415 -- Storage_Pool or Storage_Size clause (which must have occurred
4416 -- before the freezing point), then use the default. This applies
4417 -- only to base types.
4419 -- None of this applies to access to subprograms, for which there
4420 -- are clearly no pools.
4422 if Present (Default_Pool)
4423 and then Is_Base_Type (E)
4424 and then not Has_Storage_Size_Clause (E)
4425 and then No (Associated_Storage_Pool (E))
4426 then
4427 -- Case of pragma Default_Storage_Pool (null)
4429 if Nkind (Default_Pool) = N_Null then
4430 Set_No_Pool_Assigned (E);
4432 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4434 else
4435 Set_Associated_Storage_Pool (E, Entity (Default_Pool));
4436 end if;
4437 end if;
4439 -- Check restriction for standard storage pool
4441 if No (Associated_Storage_Pool (E)) then
4442 Check_Restriction (No_Standard_Storage_Pools, E);
4443 end if;
4445 -- Deal with error message for pure access type. This is not an
4446 -- error in Ada 2005 if there is no pool (see AI-366).
4448 if Is_Pure_Unit_Access_Type (E)
4449 and then (Ada_Version < Ada_2005
4450 or else not No_Pool_Assigned (E))
4451 then
4452 Error_Msg_N ("named access type not allowed in pure unit", E);
4454 if Ada_Version >= Ada_2005 then
4455 Error_Msg_N
4456 ("\would be legal if Storage_Size of 0 given??", E);
4458 elsif No_Pool_Assigned (E) then
4459 Error_Msg_N
4460 ("\would be legal in Ada 2005??", E);
4462 else
4463 Error_Msg_N
4464 ("\would be legal in Ada 2005 if "
4465 & "Storage_Size of 0 given??", E);
4466 end if;
4467 end if;
4468 end if;
4470 -- Case of composite types
4472 if Is_Composite_Type (E) then
4474 -- AI-117 requires that all new primitives of a tagged type must
4475 -- inherit the convention of the full view of the type. Inherited
4476 -- and overriding operations are defined to inherit the convention
4477 -- of their parent or overridden subprogram (also specified in
4478 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4479 -- and New_Overloaded_Entity). Here we set the convention of
4480 -- primitives that are still convention Ada, which will ensure
4481 -- that any new primitives inherit the type's convention. Class-
4482 -- wide types can have a foreign convention inherited from their
4483 -- specific type, but are excluded from this since they don't have
4484 -- any associated primitives.
4486 if Is_Tagged_Type (E)
4487 and then not Is_Class_Wide_Type (E)
4488 and then Convention (E) /= Convention_Ada
4489 then
4490 declare
4491 Prim_List : constant Elist_Id := Primitive_Operations (E);
4492 Prim : Elmt_Id;
4494 begin
4495 Prim := First_Elmt (Prim_List);
4496 while Present (Prim) loop
4497 if Convention (Node (Prim)) = Convention_Ada then
4498 Set_Convention (Node (Prim), Convention (E));
4499 end if;
4501 Next_Elmt (Prim);
4502 end loop;
4503 end;
4504 end if;
4506 -- If the type is a simple storage pool type, then this is where
4507 -- we attempt to locate and validate its Allocate, Deallocate, and
4508 -- Storage_Size operations (the first is required, and the latter
4509 -- two are optional). We also verify that the full type for a
4510 -- private type is allowed to be a simple storage pool type.
4512 if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type))
4513 and then (Is_Base_Type (E) or else Has_Private_Declaration (E))
4514 then
4515 -- If the type is marked Has_Private_Declaration, then this is
4516 -- a full type for a private type that was specified with the
4517 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4518 -- pragma is allowed for the full type (for example, it can't
4519 -- be an array type, or a nonlimited record type).
4521 if Has_Private_Declaration (E) then
4522 if (not Is_Record_Type (E)
4523 or else not Is_Immutably_Limited_Type (E))
4524 and then not Is_Private_Type (E)
4525 then
4526 Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type;
4527 Error_Msg_N
4528 ("pragma% can only apply to full type that is an " &
4529 "explicitly limited type", E);
4530 end if;
4531 end if;
4533 Validate_Simple_Pool_Ops : declare
4534 Pool_Type : Entity_Id renames E;
4535 Address_Type : constant Entity_Id := RTE (RE_Address);
4536 Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count);
4538 procedure Validate_Simple_Pool_Op_Formal
4539 (Pool_Op : Entity_Id;
4540 Pool_Op_Formal : in out Entity_Id;
4541 Expected_Mode : Formal_Kind;
4542 Expected_Type : Entity_Id;
4543 Formal_Name : String;
4544 OK_Formal : in out Boolean);
4545 -- Validate one formal Pool_Op_Formal of the candidate pool
4546 -- operation Pool_Op. The formal must be of Expected_Type
4547 -- and have mode Expected_Mode. OK_Formal will be set to
4548 -- False if the formal doesn't match. If OK_Formal is False
4549 -- on entry, then the formal will effectively be ignored
4550 -- (because validation of the pool op has already failed).
4551 -- Upon return, Pool_Op_Formal will be updated to the next
4552 -- formal, if any.
4554 procedure Validate_Simple_Pool_Operation (Op_Name : Name_Id);
4555 -- Search for and validate a simple pool operation with the
4556 -- name Op_Name. If the name is Allocate, then there must be
4557 -- exactly one such primitive operation for the simple pool
4558 -- type. If the name is Deallocate or Storage_Size, then
4559 -- there can be at most one such primitive operation. The
4560 -- profile of the located primitive must conform to what
4561 -- is expected for each operation.
4563 ------------------------------------
4564 -- Validate_Simple_Pool_Op_Formal --
4565 ------------------------------------
4567 procedure Validate_Simple_Pool_Op_Formal
4568 (Pool_Op : Entity_Id;
4569 Pool_Op_Formal : in out Entity_Id;
4570 Expected_Mode : Formal_Kind;
4571 Expected_Type : Entity_Id;
4572 Formal_Name : String;
4573 OK_Formal : in out Boolean)
4575 begin
4576 -- If OK_Formal is False on entry, then simply ignore
4577 -- the formal, because an earlier formal has already
4578 -- been flagged.
4580 if not OK_Formal then
4581 return;
4583 -- If no formal is passed in, then issue an error for a
4584 -- missing formal.
4586 elsif not Present (Pool_Op_Formal) then
4587 Error_Msg_NE
4588 ("simple storage pool op missing formal " &
4589 Formal_Name & " of type&", Pool_Op, Expected_Type);
4590 OK_Formal := False;
4592 return;
4593 end if;
4595 if Etype (Pool_Op_Formal) /= Expected_Type then
4597 -- If the pool type was expected for this formal, then
4598 -- this will not be considered a candidate operation
4599 -- for the simple pool, so we unset OK_Formal so that
4600 -- the op and any later formals will be ignored.
4602 if Expected_Type = Pool_Type then
4603 OK_Formal := False;
4605 return;
4607 else
4608 Error_Msg_NE
4609 ("wrong type for formal " & Formal_Name &
4610 " of simple storage pool op; expected type&",
4611 Pool_Op_Formal, Expected_Type);
4612 end if;
4613 end if;
4615 -- Issue error if formal's mode is not the expected one
4617 if Ekind (Pool_Op_Formal) /= Expected_Mode then
4618 Error_Msg_N
4619 ("wrong mode for formal of simple storage pool op",
4620 Pool_Op_Formal);
4621 end if;
4623 -- Advance to the next formal
4625 Next_Formal (Pool_Op_Formal);
4626 end Validate_Simple_Pool_Op_Formal;
4628 ------------------------------------
4629 -- Validate_Simple_Pool_Operation --
4630 ------------------------------------
4632 procedure Validate_Simple_Pool_Operation
4633 (Op_Name : Name_Id)
4635 Op : Entity_Id;
4636 Found_Op : Entity_Id := Empty;
4637 Formal : Entity_Id;
4638 Is_OK : Boolean;
4640 begin
4641 pragma Assert
4642 (Nam_In (Op_Name, Name_Allocate,
4643 Name_Deallocate,
4644 Name_Storage_Size));
4646 Error_Msg_Name_1 := Op_Name;
4648 -- For each homonym declared immediately in the scope
4649 -- of the simple storage pool type, determine whether
4650 -- the homonym is an operation of the pool type, and,
4651 -- if so, check that its profile is as expected for
4652 -- a simple pool operation of that name.
4654 Op := Get_Name_Entity_Id (Op_Name);
4655 while Present (Op) loop
4656 if Ekind_In (Op, E_Function, E_Procedure)
4657 and then Scope (Op) = Current_Scope
4658 then
4659 Formal := First_Entity (Op);
4661 Is_OK := True;
4663 -- The first parameter must be of the pool type
4664 -- in order for the operation to qualify.
4666 if Op_Name = Name_Storage_Size then
4667 Validate_Simple_Pool_Op_Formal
4668 (Op, Formal, E_In_Parameter, Pool_Type,
4669 "Pool", Is_OK);
4670 else
4671 Validate_Simple_Pool_Op_Formal
4672 (Op, Formal, E_In_Out_Parameter, Pool_Type,
4673 "Pool", Is_OK);
4674 end if;
4676 -- If another operation with this name has already
4677 -- been located for the type, then flag an error,
4678 -- since we only allow the type to have a single
4679 -- such primitive.
4681 if Present (Found_Op) and then Is_OK then
4682 Error_Msg_NE
4683 ("only one % operation allowed for " &
4684 "simple storage pool type&", Op, Pool_Type);
4685 end if;
4687 -- In the case of Allocate and Deallocate, a formal
4688 -- of type System.Address is required.
4690 if Op_Name = Name_Allocate then
4691 Validate_Simple_Pool_Op_Formal
4692 (Op, Formal, E_Out_Parameter,
4693 Address_Type, "Storage_Address", Is_OK);
4695 elsif Op_Name = Name_Deallocate then
4696 Validate_Simple_Pool_Op_Formal
4697 (Op, Formal, E_In_Parameter,
4698 Address_Type, "Storage_Address", Is_OK);
4699 end if;
4701 -- In the case of Allocate and Deallocate, formals
4702 -- of type Storage_Count are required as the third
4703 -- and fourth parameters.
4705 if Op_Name /= Name_Storage_Size then
4706 Validate_Simple_Pool_Op_Formal
4707 (Op, Formal, E_In_Parameter,
4708 Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK);
4709 Validate_Simple_Pool_Op_Formal
4710 (Op, Formal, E_In_Parameter,
4711 Stg_Cnt_Type, "Alignment", Is_OK);
4712 end if;
4714 -- If no mismatched formals have been found (Is_OK)
4715 -- and no excess formals are present, then this
4716 -- operation has been validated, so record it.
4718 if not Present (Formal) and then Is_OK then
4719 Found_Op := Op;
4720 end if;
4721 end if;
4723 Op := Homonym (Op);
4724 end loop;
4726 -- There must be a valid Allocate operation for the type,
4727 -- so issue an error if none was found.
4729 if Op_Name = Name_Allocate
4730 and then not Present (Found_Op)
4731 then
4732 Error_Msg_N ("missing % operation for simple " &
4733 "storage pool type", Pool_Type);
4735 elsif Present (Found_Op) then
4737 -- Simple pool operations can't be abstract
4739 if Is_Abstract_Subprogram (Found_Op) then
4740 Error_Msg_N
4741 ("simple storage pool operation must not be " &
4742 "abstract", Found_Op);
4743 end if;
4745 -- The Storage_Size operation must be a function with
4746 -- Storage_Count as its result type.
4748 if Op_Name = Name_Storage_Size then
4749 if Ekind (Found_Op) = E_Procedure then
4750 Error_Msg_N
4751 ("% operation must be a function", Found_Op);
4753 elsif Etype (Found_Op) /= Stg_Cnt_Type then
4754 Error_Msg_NE
4755 ("wrong result type for%, expected type&",
4756 Found_Op, Stg_Cnt_Type);
4757 end if;
4759 -- Allocate and Deallocate must be procedures
4761 elsif Ekind (Found_Op) = E_Function then
4762 Error_Msg_N
4763 ("% operation must be a procedure", Found_Op);
4764 end if;
4765 end if;
4766 end Validate_Simple_Pool_Operation;
4768 -- Start of processing for Validate_Simple_Pool_Ops
4770 begin
4771 Validate_Simple_Pool_Operation (Name_Allocate);
4772 Validate_Simple_Pool_Operation (Name_Deallocate);
4773 Validate_Simple_Pool_Operation (Name_Storage_Size);
4774 end Validate_Simple_Pool_Ops;
4775 end if;
4776 end if;
4778 -- Now that all types from which E may depend are frozen, see if the
4779 -- size is known at compile time, if it must be unsigned, or if
4780 -- strict alignment is required
4782 Check_Compile_Time_Size (E);
4783 Check_Unsigned_Type (E);
4785 if Base_Type (E) = E then
4786 Check_Strict_Alignment (E);
4787 end if;
4789 -- Do not allow a size clause for a type which does not have a size
4790 -- that is known at compile time
4792 if Has_Size_Clause (E)
4793 and then not Size_Known_At_Compile_Time (E)
4794 then
4795 -- Suppress this message if errors posted on E, even if we are
4796 -- in all errors mode, since this is often a junk message
4798 if not Error_Posted (E) then
4799 Error_Msg_N
4800 ("size clause not allowed for variable length type",
4801 Size_Clause (E));
4802 end if;
4803 end if;
4805 -- Now we set/verify the representation information, in particular
4806 -- the size and alignment values. This processing is not required for
4807 -- generic types, since generic types do not play any part in code
4808 -- generation, and so the size and alignment values for such types
4809 -- are irrelevant. Ditto for types declared within a generic unit,
4810 -- which may have components that depend on generic parameters, and
4811 -- that will be recreated in an instance.
4813 if Inside_A_Generic then
4814 null;
4816 -- Otherwise we call the layout procedure
4818 else
4819 Layout_Type (E);
4820 end if;
4822 -- If this is an access to subprogram whose designated type is itself
4823 -- a subprogram type, the return type of this anonymous subprogram
4824 -- type must be decorated as well.
4826 if Ekind (E) = E_Anonymous_Access_Subprogram_Type
4827 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
4828 then
4829 Layout_Type (Etype (Designated_Type (E)));
4830 end if;
4832 -- If the type has a Defaut_Value/Default_Component_Value aspect,
4833 -- this is where we analye the expression (after the type is frozen,
4834 -- since in the case of Default_Value, we are analyzing with the
4835 -- type itself, and we treat Default_Component_Value similarly for
4836 -- the sake of uniformity).
4838 if Is_First_Subtype (E) and then Has_Default_Aspect (E) then
4839 declare
4840 Nam : Name_Id;
4841 Exp : Node_Id;
4842 Typ : Entity_Id;
4844 begin
4845 if Is_Scalar_Type (E) then
4846 Nam := Name_Default_Value;
4847 Typ := E;
4848 Exp := Default_Aspect_Value (Typ);
4849 else
4850 Nam := Name_Default_Component_Value;
4851 Typ := Component_Type (E);
4852 Exp := Default_Aspect_Component_Value (E);
4853 end if;
4855 Analyze_And_Resolve (Exp, Typ);
4857 if Etype (Exp) /= Any_Type then
4858 if not Is_Static_Expression (Exp) then
4859 Error_Msg_Name_1 := Nam;
4860 Flag_Non_Static_Expr
4861 ("aspect% requires static expression", Exp);
4862 end if;
4863 end if;
4864 end;
4865 end if;
4867 -- End of freeze processing for type entities
4868 end if;
4870 -- Here is where we logically freeze the current entity. If it has a
4871 -- freeze node, then this is the point at which the freeze node is
4872 -- linked into the result list.
4874 if Has_Delayed_Freeze (E) then
4876 -- If a freeze node is already allocated, use it, otherwise allocate
4877 -- a new one. The preallocation happens in the case of anonymous base
4878 -- types, where we preallocate so that we can set First_Subtype_Link.
4879 -- Note that we reset the Sloc to the current freeze location.
4881 if Present (Freeze_Node (E)) then
4882 F_Node := Freeze_Node (E);
4883 Set_Sloc (F_Node, Loc);
4885 else
4886 F_Node := New_Node (N_Freeze_Entity, Loc);
4887 Set_Freeze_Node (E, F_Node);
4888 Set_Access_Types_To_Process (F_Node, No_Elist);
4889 Set_TSS_Elist (F_Node, No_Elist);
4890 Set_Actions (F_Node, No_List);
4891 end if;
4893 Set_Entity (F_Node, E);
4894 Add_To_Result (F_Node);
4896 -- A final pass over record types with discriminants. If the type
4897 -- has an incomplete declaration, there may be constrained access
4898 -- subtypes declared elsewhere, which do not depend on the discrimi-
4899 -- nants of the type, and which are used as component types (i.e.
4900 -- the full view is a recursive type). The designated types of these
4901 -- subtypes can only be elaborated after the type itself, and they
4902 -- need an itype reference.
4904 if Ekind (E) = E_Record_Type
4905 and then Has_Discriminants (E)
4906 then
4907 declare
4908 Comp : Entity_Id;
4909 IR : Node_Id;
4910 Typ : Entity_Id;
4912 begin
4913 Comp := First_Component (E);
4914 while Present (Comp) loop
4915 Typ := Etype (Comp);
4917 if Ekind (Comp) = E_Component
4918 and then Is_Access_Type (Typ)
4919 and then Scope (Typ) /= E
4920 and then Base_Type (Designated_Type (Typ)) = E
4921 and then Is_Itype (Designated_Type (Typ))
4922 then
4923 IR := Make_Itype_Reference (Sloc (Comp));
4924 Set_Itype (IR, Designated_Type (Typ));
4925 Append (IR, Result);
4926 end if;
4928 Next_Component (Comp);
4929 end loop;
4930 end;
4931 end if;
4932 end if;
4934 -- When a type is frozen, the first subtype of the type is frozen as
4935 -- well (RM 13.14(15)). This has to be done after freezing the type,
4936 -- since obviously the first subtype depends on its own base type.
4938 if Is_Type (E) then
4939 Freeze_And_Append (First_Subtype (E), N, Result);
4941 -- If we just froze a tagged non-class wide record, then freeze the
4942 -- corresponding class-wide type. This must be done after the tagged
4943 -- type itself is frozen, because the class-wide type refers to the
4944 -- tagged type which generates the class.
4946 if Is_Tagged_Type (E)
4947 and then not Is_Class_Wide_Type (E)
4948 and then Present (Class_Wide_Type (E))
4949 then
4950 Freeze_And_Append (Class_Wide_Type (E), N, Result);
4951 end if;
4952 end if;
4954 Check_Debug_Info_Needed (E);
4956 -- Special handling for subprograms
4958 if Is_Subprogram (E) then
4960 -- If subprogram has address clause then reset Is_Public flag, since
4961 -- we do not want the backend to generate external references.
4963 if Present (Address_Clause (E))
4964 and then not Is_Library_Level_Entity (E)
4965 then
4966 Set_Is_Public (E, False);
4967 end if;
4968 end if;
4970 return Result;
4971 end Freeze_Entity;
4973 -----------------------------
4974 -- Freeze_Enumeration_Type --
4975 -----------------------------
4977 procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
4978 begin
4979 -- By default, if no size clause is present, an enumeration type with
4980 -- Convention C is assumed to interface to a C enum, and has integer
4981 -- size. This applies to types. For subtypes, verify that its base
4982 -- type has no size clause either. Treat other foreign conventions
4983 -- in the same way, and also make sure alignment is set right.
4985 if Has_Foreign_Convention (Typ)
4986 and then not Has_Size_Clause (Typ)
4987 and then not Has_Size_Clause (Base_Type (Typ))
4988 and then Esize (Typ) < Standard_Integer_Size
4989 then
4990 Init_Esize (Typ, Standard_Integer_Size);
4991 Set_Alignment (Typ, Alignment (Standard_Integer));
4993 else
4994 -- If the enumeration type interfaces to C, and it has a size clause
4995 -- that specifies less than int size, it warrants a warning. The
4996 -- user may intend the C type to be an enum or a char, so this is
4997 -- not by itself an error that the Ada compiler can detect, but it
4998 -- it is a worth a heads-up. For Boolean and Character types we
4999 -- assume that the programmer has the proper C type in mind.
5001 if Convention (Typ) = Convention_C
5002 and then Has_Size_Clause (Typ)
5003 and then Esize (Typ) /= Esize (Standard_Integer)
5004 and then not Is_Boolean_Type (Typ)
5005 and then not Is_Character_Type (Typ)
5006 then
5007 Error_Msg_N
5008 ("C enum types have the size of a C int??", Size_Clause (Typ));
5009 end if;
5011 Adjust_Esize_For_Alignment (Typ);
5012 end if;
5013 end Freeze_Enumeration_Type;
5015 -----------------------
5016 -- Freeze_Expression --
5017 -----------------------
5019 procedure Freeze_Expression (N : Node_Id) is
5020 In_Spec_Exp : constant Boolean := In_Spec_Expression;
5021 Typ : Entity_Id;
5022 Nam : Entity_Id;
5023 Desig_Typ : Entity_Id;
5024 P : Node_Id;
5025 Parent_P : Node_Id;
5027 Freeze_Outside : Boolean := False;
5028 -- This flag is set true if the entity must be frozen outside the
5029 -- current subprogram. This happens in the case of expander generated
5030 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5031 -- not freeze all entities like other bodies, but which nevertheless
5032 -- may reference entities that have to be frozen before the body and
5033 -- obviously cannot be frozen inside the body.
5035 function In_Exp_Body (N : Node_Id) return Boolean;
5036 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5037 -- it is the handled statement sequence of an expander-generated
5038 -- subprogram (init proc, stream subprogram, or renaming as body).
5039 -- If so, this is not a freezing context.
5041 -----------------
5042 -- In_Exp_Body --
5043 -----------------
5045 function In_Exp_Body (N : Node_Id) return Boolean is
5046 P : Node_Id;
5047 Id : Entity_Id;
5049 begin
5050 if Nkind (N) = N_Subprogram_Body then
5051 P := N;
5052 else
5053 P := Parent (N);
5054 end if;
5056 if Nkind (P) /= N_Subprogram_Body then
5057 return False;
5059 else
5060 Id := Defining_Unit_Name (Specification (P));
5062 -- Following complex conditional could use comments ???
5064 if Nkind (Id) = N_Defining_Identifier
5065 and then (Is_Init_Proc (Id)
5066 or else Is_TSS (Id, TSS_Stream_Input)
5067 or else Is_TSS (Id, TSS_Stream_Output)
5068 or else Is_TSS (Id, TSS_Stream_Read)
5069 or else Is_TSS (Id, TSS_Stream_Write)
5070 or else Nkind_In (Original_Node (P),
5071 N_Subprogram_Renaming_Declaration,
5072 N_Expression_Function))
5073 then
5074 return True;
5075 else
5076 return False;
5077 end if;
5078 end if;
5079 end In_Exp_Body;
5081 -- Start of processing for Freeze_Expression
5083 begin
5084 -- Immediate return if freezing is inhibited. This flag is set by the
5085 -- analyzer to stop freezing on generated expressions that would cause
5086 -- freezing if they were in the source program, but which are not
5087 -- supposed to freeze, since they are created.
5089 if Must_Not_Freeze (N) then
5090 return;
5091 end if;
5093 -- If expression is non-static, then it does not freeze in a default
5094 -- expression, see section "Handling of Default Expressions" in the
5095 -- spec of package Sem for further details. Note that we have to make
5096 -- sure that we actually have a real expression (if we have a subtype
5097 -- indication, we can't test Is_Static_Expression!) However, we exclude
5098 -- the case of the prefix of an attribute of a static scalar subtype
5099 -- from this early return, because static subtype attributes should
5100 -- always cause freezing, even in default expressions, but the attribute
5101 -- may not have been marked as static yet (because in Resolve_Attribute,
5102 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5103 -- the prefix).
5105 if In_Spec_Exp
5106 and then Nkind (N) in N_Subexpr
5107 and then not Is_Static_Expression (N)
5108 and then (Nkind (Parent (N)) /= N_Attribute_Reference
5109 or else not (Is_Entity_Name (N)
5110 and then Is_Type (Entity (N))
5111 and then Is_Static_Subtype (Entity (N))))
5112 then
5113 return;
5114 end if;
5116 -- Freeze type of expression if not frozen already
5118 Typ := Empty;
5120 if Nkind (N) in N_Has_Etype then
5121 if not Is_Frozen (Etype (N)) then
5122 Typ := Etype (N);
5124 -- Base type may be an derived numeric type that is frozen at
5125 -- the point of declaration, but first_subtype is still unfrozen.
5127 elsif not Is_Frozen (First_Subtype (Etype (N))) then
5128 Typ := First_Subtype (Etype (N));
5129 end if;
5130 end if;
5132 -- For entity name, freeze entity if not frozen already. A special
5133 -- exception occurs for an identifier that did not come from source.
5134 -- We don't let such identifiers freeze a non-internal entity, i.e.
5135 -- an entity that did come from source, since such an identifier was
5136 -- generated by the expander, and cannot have any semantic effect on
5137 -- the freezing semantics. For example, this stops the parameter of
5138 -- an initialization procedure from freezing the variable.
5140 if Is_Entity_Name (N)
5141 and then not Is_Frozen (Entity (N))
5142 and then (Nkind (N) /= N_Identifier
5143 or else Comes_From_Source (N)
5144 or else not Comes_From_Source (Entity (N)))
5145 then
5146 Nam := Entity (N);
5147 else
5148 Nam := Empty;
5149 end if;
5151 -- For an allocator freeze designated type if not frozen already
5153 -- For an aggregate whose component type is an access type, freeze the
5154 -- designated type now, so that its freeze does not appear within the
5155 -- loop that might be created in the expansion of the aggregate. If the
5156 -- designated type is a private type without full view, the expression
5157 -- cannot contain an allocator, so the type is not frozen.
5159 -- For a function, we freeze the entity when the subprogram declaration
5160 -- is frozen, but a function call may appear in an initialization proc.
5161 -- before the declaration is frozen. We need to generate the extra
5162 -- formals, if any, to ensure that the expansion of the call includes
5163 -- the proper actuals. This only applies to Ada subprograms, not to
5164 -- imported ones.
5166 Desig_Typ := Empty;
5168 case Nkind (N) is
5169 when N_Allocator =>
5170 Desig_Typ := Designated_Type (Etype (N));
5172 when N_Aggregate =>
5173 if Is_Array_Type (Etype (N))
5174 and then Is_Access_Type (Component_Type (Etype (N)))
5175 then
5176 Desig_Typ := Designated_Type (Component_Type (Etype (N)));
5177 end if;
5179 when N_Selected_Component |
5180 N_Indexed_Component |
5181 N_Slice =>
5183 if Is_Access_Type (Etype (Prefix (N))) then
5184 Desig_Typ := Designated_Type (Etype (Prefix (N)));
5185 end if;
5187 when N_Identifier =>
5188 if Present (Nam)
5189 and then Ekind (Nam) = E_Function
5190 and then Nkind (Parent (N)) = N_Function_Call
5191 and then Convention (Nam) = Convention_Ada
5192 then
5193 Create_Extra_Formals (Nam);
5194 end if;
5196 when others =>
5197 null;
5198 end case;
5200 if Desig_Typ /= Empty
5201 and then (Is_Frozen (Desig_Typ)
5202 or else (not Is_Fully_Defined (Desig_Typ)))
5203 then
5204 Desig_Typ := Empty;
5205 end if;
5207 -- All done if nothing needs freezing
5209 if No (Typ)
5210 and then No (Nam)
5211 and then No (Desig_Typ)
5212 then
5213 return;
5214 end if;
5216 -- Loop for looking at the right place to insert the freeze nodes,
5217 -- exiting from the loop when it is appropriate to insert the freeze
5218 -- node before the current node P.
5220 -- Also checks some special exceptions to the freezing rules. These
5221 -- cases result in a direct return, bypassing the freeze action.
5223 P := N;
5224 loop
5225 Parent_P := Parent (P);
5227 -- If we don't have a parent, then we are not in a well-formed tree.
5228 -- This is an unusual case, but there are some legitimate situations
5229 -- in which this occurs, notably when the expressions in the range of
5230 -- a type declaration are resolved. We simply ignore the freeze
5231 -- request in this case. Is this right ???
5233 if No (Parent_P) then
5234 return;
5235 end if;
5237 -- See if we have got to an appropriate point in the tree
5239 case Nkind (Parent_P) is
5241 -- A special test for the exception of (RM 13.14(8)) for the case
5242 -- of per-object expressions (RM 3.8(18)) occurring in component
5243 -- definition or a discrete subtype definition. Note that we test
5244 -- for a component declaration which includes both cases we are
5245 -- interested in, and furthermore the tree does not have explicit
5246 -- nodes for either of these two constructs.
5248 when N_Component_Declaration =>
5250 -- The case we want to test for here is an identifier that is
5251 -- a per-object expression, this is either a discriminant that
5252 -- appears in a context other than the component declaration
5253 -- or it is a reference to the type of the enclosing construct.
5255 -- For either of these cases, we skip the freezing
5257 if not In_Spec_Expression
5258 and then Nkind (N) = N_Identifier
5259 and then (Present (Entity (N)))
5260 then
5261 -- We recognize the discriminant case by just looking for
5262 -- a reference to a discriminant. It can only be one for
5263 -- the enclosing construct. Skip freezing in this case.
5265 if Ekind (Entity (N)) = E_Discriminant then
5266 return;
5268 -- For the case of a reference to the enclosing record,
5269 -- (or task or protected type), we look for a type that
5270 -- matches the current scope.
5272 elsif Entity (N) = Current_Scope then
5273 return;
5274 end if;
5275 end if;
5277 -- If we have an enumeration literal that appears as the choice in
5278 -- the aggregate of an enumeration representation clause, then
5279 -- freezing does not occur (RM 13.14(10)).
5281 when N_Enumeration_Representation_Clause =>
5283 -- The case we are looking for is an enumeration literal
5285 if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
5286 and then Is_Enumeration_Type (Etype (N))
5287 then
5288 -- If enumeration literal appears directly as the choice,
5289 -- do not freeze (this is the normal non-overloaded case)
5291 if Nkind (Parent (N)) = N_Component_Association
5292 and then First (Choices (Parent (N))) = N
5293 then
5294 return;
5296 -- If enumeration literal appears as the name of function
5297 -- which is the choice, then also do not freeze. This
5298 -- happens in the overloaded literal case, where the
5299 -- enumeration literal is temporarily changed to a function
5300 -- call for overloading analysis purposes.
5302 elsif Nkind (Parent (N)) = N_Function_Call
5303 and then
5304 Nkind (Parent (Parent (N))) = N_Component_Association
5305 and then
5306 First (Choices (Parent (Parent (N)))) = Parent (N)
5307 then
5308 return;
5309 end if;
5310 end if;
5312 -- Normally if the parent is a handled sequence of statements,
5313 -- then the current node must be a statement, and that is an
5314 -- appropriate place to insert a freeze node.
5316 when N_Handled_Sequence_Of_Statements =>
5318 -- An exception occurs when the sequence of statements is for
5319 -- an expander generated body that did not do the usual freeze
5320 -- all operation. In this case we usually want to freeze
5321 -- outside this body, not inside it, and we skip past the
5322 -- subprogram body that we are inside.
5324 if In_Exp_Body (Parent_P) then
5325 declare
5326 Subp : constant Node_Id := Parent (Parent_P);
5327 Spec : Entity_Id;
5329 begin
5330 -- Freeze the entity only when it is declared inside the
5331 -- body of the expander generated procedure. This case
5332 -- is recognized by the scope of the entity or its type,
5333 -- which is either the spec for some enclosing body, or
5334 -- (in the case of init_procs, for which there are no
5335 -- separate specs) the current scope.
5337 if Nkind (Subp) = N_Subprogram_Body then
5338 Spec := Corresponding_Spec (Subp);
5340 if (Present (Typ) and then Scope (Typ) = Spec)
5341 or else
5342 (Present (Nam) and then Scope (Nam) = Spec)
5343 then
5344 exit;
5346 elsif Present (Typ)
5347 and then Scope (Typ) = Current_Scope
5348 and then Defining_Entity (Subp) = Current_Scope
5349 then
5350 exit;
5351 end if;
5352 end if;
5354 -- An expression function may act as a completion of
5355 -- a function declaration. As such, it can reference
5356 -- entities declared between the two views:
5358 -- Hidden []; -- 1
5359 -- function F return ...;
5360 -- private
5361 -- function Hidden return ...;
5362 -- function F return ... is (Hidden); -- 2
5364 -- Refering to the example above, freezing the expression
5365 -- of F (2) would place Hidden's freeze node (1) in the
5366 -- wrong place. Avoid explicit freezing and let the usual
5367 -- scenarios do the job - for example, reaching the end
5368 -- of the private declarations.
5370 if Nkind (Original_Node (Subp)) =
5371 N_Expression_Function
5372 then
5373 null;
5375 -- Freeze outside the body
5377 else
5378 Parent_P := Parent (Parent_P);
5379 Freeze_Outside := True;
5380 end if;
5381 end;
5383 -- Here if normal case where we are in handled statement
5384 -- sequence and want to do the insertion right there.
5386 else
5387 exit;
5388 end if;
5390 -- If parent is a body or a spec or a block, then the current node
5391 -- is a statement or declaration and we can insert the freeze node
5392 -- before it.
5394 when N_Block_Statement |
5395 N_Entry_Body |
5396 N_Package_Body |
5397 N_Package_Specification |
5398 N_Protected_Body |
5399 N_Subprogram_Body |
5400 N_Task_Body => exit;
5402 -- The expander is allowed to define types in any statements list,
5403 -- so any of the following parent nodes also mark a freezing point
5404 -- if the actual node is in a list of statements or declarations.
5406 when N_Abortable_Part |
5407 N_Accept_Alternative |
5408 N_And_Then |
5409 N_Case_Statement_Alternative |
5410 N_Compilation_Unit_Aux |
5411 N_Conditional_Entry_Call |
5412 N_Delay_Alternative |
5413 N_Elsif_Part |
5414 N_Entry_Call_Alternative |
5415 N_Exception_Handler |
5416 N_Extended_Return_Statement |
5417 N_Freeze_Entity |
5418 N_If_Statement |
5419 N_Or_Else |
5420 N_Selective_Accept |
5421 N_Triggering_Alternative =>
5423 exit when Is_List_Member (P);
5425 -- Note: The N_Loop_Statement is a special case. A type that
5426 -- appears in the source can never be frozen in a loop (this
5427 -- occurs only because of a loop expanded by the expander), so we
5428 -- keep on going. Otherwise we terminate the search. Same is true
5429 -- of any entity which comes from source. (if they have predefined
5430 -- type, that type does not appear to come from source, but the
5431 -- entity should not be frozen here).
5433 when N_Loop_Statement =>
5434 exit when not Comes_From_Source (Etype (N))
5435 and then (No (Nam) or else not Comes_From_Source (Nam));
5437 -- For all other cases, keep looking at parents
5439 when others =>
5440 null;
5441 end case;
5443 -- We fall through the case if we did not yet find the proper
5444 -- place in the free for inserting the freeze node, so climb!
5446 P := Parent_P;
5447 end loop;
5449 -- If the expression appears in a record or an initialization procedure,
5450 -- the freeze nodes are collected and attached to the current scope, to
5451 -- be inserted and analyzed on exit from the scope, to insure that
5452 -- generated entities appear in the correct scope. If the expression is
5453 -- a default for a discriminant specification, the scope is still void.
5454 -- The expression can also appear in the discriminant part of a private
5455 -- or concurrent type.
5457 -- If the expression appears in a constrained subcomponent of an
5458 -- enclosing record declaration, the freeze nodes must be attached to
5459 -- the outer record type so they can eventually be placed in the
5460 -- enclosing declaration list.
5462 -- The other case requiring this special handling is if we are in a
5463 -- default expression, since in that case we are about to freeze a
5464 -- static type, and the freeze scope needs to be the outer scope, not
5465 -- the scope of the subprogram with the default parameter.
5467 -- For default expressions and other spec expressions in generic units,
5468 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5469 -- placing them at the proper place, after the generic unit.
5471 if (In_Spec_Exp and not Inside_A_Generic)
5472 or else Freeze_Outside
5473 or else (Is_Type (Current_Scope)
5474 and then (not Is_Concurrent_Type (Current_Scope)
5475 or else not Has_Completion (Current_Scope)))
5476 or else Ekind (Current_Scope) = E_Void
5477 then
5478 declare
5479 N : constant Node_Id := Current_Scope;
5480 Freeze_Nodes : List_Id := No_List;
5481 Pos : Int := Scope_Stack.Last;
5483 begin
5484 if Present (Desig_Typ) then
5485 Freeze_And_Append (Desig_Typ, N, Freeze_Nodes);
5486 end if;
5488 if Present (Typ) then
5489 Freeze_And_Append (Typ, N, Freeze_Nodes);
5490 end if;
5492 if Present (Nam) then
5493 Freeze_And_Append (Nam, N, Freeze_Nodes);
5494 end if;
5496 -- The current scope may be that of a constrained component of
5497 -- an enclosing record declaration, or of a loop of an enclosing
5498 -- quantified expression, which is above the current scope in the
5499 -- scope stack. Indeed in the context of a quantified expression,
5500 -- a scope is created and pushed above the current scope in order
5501 -- to emulate the loop-like behavior of the quantified expression.
5502 -- If the expression is within a top-level pragma, as for a pre-
5503 -- condition on a library-level subprogram, nothing to do.
5505 if not Is_Compilation_Unit (Current_Scope)
5506 and then (Is_Record_Type (Scope (Current_Scope))
5507 or else Nkind (Parent (Current_Scope)) =
5508 N_Quantified_Expression)
5509 then
5510 Pos := Pos - 1;
5511 end if;
5513 if Is_Non_Empty_List (Freeze_Nodes) then
5514 if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then
5515 Scope_Stack.Table (Pos).Pending_Freeze_Actions :=
5516 Freeze_Nodes;
5517 else
5518 Append_List (Freeze_Nodes,
5519 Scope_Stack.Table (Pos).Pending_Freeze_Actions);
5520 end if;
5521 end if;
5522 end;
5524 return;
5525 end if;
5527 -- Now we have the right place to do the freezing. First, a special
5528 -- adjustment, if we are in spec-expression analysis mode, these freeze
5529 -- actions must not be thrown away (normally all inserted actions are
5530 -- thrown away in this mode. However, the freeze actions are from static
5531 -- expressions and one of the important reasons we are doing this
5532 -- special analysis is to get these freeze actions. Therefore we turn
5533 -- off the In_Spec_Expression mode to propagate these freeze actions.
5534 -- This also means they get properly analyzed and expanded.
5536 In_Spec_Expression := False;
5538 -- Freeze the designated type of an allocator (RM 13.14(13))
5540 if Present (Desig_Typ) then
5541 Freeze_Before (P, Desig_Typ);
5542 end if;
5544 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5545 -- the enumeration representation clause exception in the loop above.
5547 if Present (Typ) then
5548 Freeze_Before (P, Typ);
5549 end if;
5551 -- Freeze name if one is present (RM 13.14(11))
5553 if Present (Nam) then
5554 Freeze_Before (P, Nam);
5555 end if;
5557 -- Restore In_Spec_Expression flag
5559 In_Spec_Expression := In_Spec_Exp;
5560 end Freeze_Expression;
5562 -----------------------------
5563 -- Freeze_Fixed_Point_Type --
5564 -----------------------------
5566 -- Certain fixed-point types and subtypes, including implicit base types
5567 -- and declared first subtypes, have not yet set up a range. This is
5568 -- because the range cannot be set until the Small and Size values are
5569 -- known, and these are not known till the type is frozen.
5571 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5572 -- whose bounds are unanalyzed real literals. This routine will recognize
5573 -- this case, and transform this range node into a properly typed range
5574 -- with properly analyzed and resolved values.
5576 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
5577 Rng : constant Node_Id := Scalar_Range (Typ);
5578 Lo : constant Node_Id := Low_Bound (Rng);
5579 Hi : constant Node_Id := High_Bound (Rng);
5580 Btyp : constant Entity_Id := Base_Type (Typ);
5581 Brng : constant Node_Id := Scalar_Range (Btyp);
5582 BLo : constant Node_Id := Low_Bound (Brng);
5583 BHi : constant Node_Id := High_Bound (Brng);
5584 Small : constant Ureal := Small_Value (Typ);
5585 Loval : Ureal;
5586 Hival : Ureal;
5587 Atype : Entity_Id;
5589 Actual_Size : Nat;
5591 function Fsize (Lov, Hiv : Ureal) return Nat;
5592 -- Returns size of type with given bounds. Also leaves these
5593 -- bounds set as the current bounds of the Typ.
5595 -----------
5596 -- Fsize --
5597 -----------
5599 function Fsize (Lov, Hiv : Ureal) return Nat is
5600 begin
5601 Set_Realval (Lo, Lov);
5602 Set_Realval (Hi, Hiv);
5603 return Minimum_Size (Typ);
5604 end Fsize;
5606 -- Start of processing for Freeze_Fixed_Point_Type
5608 begin
5609 -- If Esize of a subtype has not previously been set, set it now
5611 if Unknown_Esize (Typ) then
5612 Atype := Ancestor_Subtype (Typ);
5614 if Present (Atype) then
5615 Set_Esize (Typ, Esize (Atype));
5616 else
5617 Set_Esize (Typ, Esize (Base_Type (Typ)));
5618 end if;
5619 end if;
5621 -- Immediate return if the range is already analyzed. This means that
5622 -- the range is already set, and does not need to be computed by this
5623 -- routine.
5625 if Analyzed (Rng) then
5626 return;
5627 end if;
5629 -- Immediate return if either of the bounds raises Constraint_Error
5631 if Raises_Constraint_Error (Lo)
5632 or else Raises_Constraint_Error (Hi)
5633 then
5634 return;
5635 end if;
5637 Loval := Realval (Lo);
5638 Hival := Realval (Hi);
5640 -- Ordinary fixed-point case
5642 if Is_Ordinary_Fixed_Point_Type (Typ) then
5644 -- For the ordinary fixed-point case, we are allowed to fudge the
5645 -- end-points up or down by small. Generally we prefer to fudge up,
5646 -- i.e. widen the bounds for non-model numbers so that the end points
5647 -- are included. However there are cases in which this cannot be
5648 -- done, and indeed cases in which we may need to narrow the bounds.
5649 -- The following circuit makes the decision.
5651 -- Note: our terminology here is that Incl_EP means that the bounds
5652 -- are widened by Small if necessary to include the end points, and
5653 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5654 -- end-points if this reduces the size.
5656 -- Note that in the Incl case, all we care about is including the
5657 -- end-points. In the Excl case, we want to narrow the bounds as
5658 -- much as permitted by the RM, to give the smallest possible size.
5660 Fudge : declare
5661 Loval_Incl_EP : Ureal;
5662 Hival_Incl_EP : Ureal;
5664 Loval_Excl_EP : Ureal;
5665 Hival_Excl_EP : Ureal;
5667 Size_Incl_EP : Nat;
5668 Size_Excl_EP : Nat;
5670 Model_Num : Ureal;
5671 First_Subt : Entity_Id;
5672 Actual_Lo : Ureal;
5673 Actual_Hi : Ureal;
5675 begin
5676 -- First step. Base types are required to be symmetrical. Right
5677 -- now, the base type range is a copy of the first subtype range.
5678 -- This will be corrected before we are done, but right away we
5679 -- need to deal with the case where both bounds are non-negative.
5680 -- In this case, we set the low bound to the negative of the high
5681 -- bound, to make sure that the size is computed to include the
5682 -- required sign. Note that we do not need to worry about the
5683 -- case of both bounds negative, because the sign will be dealt
5684 -- with anyway. Furthermore we can't just go making such a bound
5685 -- symmetrical, since in a twos-complement system, there is an
5686 -- extra negative value which could not be accommodated on the
5687 -- positive side.
5689 if Typ = Btyp
5690 and then not UR_Is_Negative (Loval)
5691 and then Hival > Loval
5692 then
5693 Loval := -Hival;
5694 Set_Realval (Lo, Loval);
5695 end if;
5697 -- Compute the fudged bounds. If the number is a model number,
5698 -- then we do nothing to include it, but we are allowed to backoff
5699 -- to the next adjacent model number when we exclude it. If it is
5700 -- not a model number then we straddle the two values with the
5701 -- model numbers on either side.
5703 Model_Num := UR_Trunc (Loval / Small) * Small;
5705 if Loval = Model_Num then
5706 Loval_Incl_EP := Model_Num;
5707 else
5708 Loval_Incl_EP := Model_Num - Small;
5709 end if;
5711 -- The low value excluding the end point is Small greater, but
5712 -- we do not do this exclusion if the low value is positive,
5713 -- since it can't help the size and could actually hurt by
5714 -- crossing the high bound.
5716 if UR_Is_Negative (Loval_Incl_EP) then
5717 Loval_Excl_EP := Loval_Incl_EP + Small;
5719 -- If the value went from negative to zero, then we have the
5720 -- case where Loval_Incl_EP is the model number just below
5721 -- zero, so we want to stick to the negative value for the
5722 -- base type to maintain the condition that the size will
5723 -- include signed values.
5725 if Typ = Btyp
5726 and then UR_Is_Zero (Loval_Excl_EP)
5727 then
5728 Loval_Excl_EP := Loval_Incl_EP;
5729 end if;
5731 else
5732 Loval_Excl_EP := Loval_Incl_EP;
5733 end if;
5735 -- Similar processing for upper bound and high value
5737 Model_Num := UR_Trunc (Hival / Small) * Small;
5739 if Hival = Model_Num then
5740 Hival_Incl_EP := Model_Num;
5741 else
5742 Hival_Incl_EP := Model_Num + Small;
5743 end if;
5745 if UR_Is_Positive (Hival_Incl_EP) then
5746 Hival_Excl_EP := Hival_Incl_EP - Small;
5747 else
5748 Hival_Excl_EP := Hival_Incl_EP;
5749 end if;
5751 -- One further adjustment is needed. In the case of subtypes, we
5752 -- cannot go outside the range of the base type, or we get
5753 -- peculiarities, and the base type range is already set. This
5754 -- only applies to the Incl values, since clearly the Excl values
5755 -- are already as restricted as they are allowed to be.
5757 if Typ /= Btyp then
5758 Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
5759 Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
5760 end if;
5762 -- Get size including and excluding end points
5764 Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
5765 Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
5767 -- No need to exclude end-points if it does not reduce size
5769 if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
5770 Loval_Excl_EP := Loval_Incl_EP;
5771 end if;
5773 if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
5774 Hival_Excl_EP := Hival_Incl_EP;
5775 end if;
5777 -- Now we set the actual size to be used. We want to use the
5778 -- bounds fudged up to include the end-points but only if this
5779 -- can be done without violating a specifically given size
5780 -- size clause or causing an unacceptable increase in size.
5782 -- Case of size clause given
5784 if Has_Size_Clause (Typ) then
5786 -- Use the inclusive size only if it is consistent with
5787 -- the explicitly specified size.
5789 if Size_Incl_EP <= RM_Size (Typ) then
5790 Actual_Lo := Loval_Incl_EP;
5791 Actual_Hi := Hival_Incl_EP;
5792 Actual_Size := Size_Incl_EP;
5794 -- If the inclusive size is too large, we try excluding
5795 -- the end-points (will be caught later if does not work).
5797 else
5798 Actual_Lo := Loval_Excl_EP;
5799 Actual_Hi := Hival_Excl_EP;
5800 Actual_Size := Size_Excl_EP;
5801 end if;
5803 -- Case of size clause not given
5805 else
5806 -- If we have a base type whose corresponding first subtype
5807 -- has an explicit size that is large enough to include our
5808 -- end-points, then do so. There is no point in working hard
5809 -- to get a base type whose size is smaller than the specified
5810 -- size of the first subtype.
5812 First_Subt := First_Subtype (Typ);
5814 if Has_Size_Clause (First_Subt)
5815 and then Size_Incl_EP <= Esize (First_Subt)
5816 then
5817 Actual_Size := Size_Incl_EP;
5818 Actual_Lo := Loval_Incl_EP;
5819 Actual_Hi := Hival_Incl_EP;
5821 -- If excluding the end-points makes the size smaller and
5822 -- results in a size of 8,16,32,64, then we take the smaller
5823 -- size. For the 64 case, this is compulsory. For the other
5824 -- cases, it seems reasonable. We like to include end points
5825 -- if we can, but not at the expense of moving to the next
5826 -- natural boundary of size.
5828 elsif Size_Incl_EP /= Size_Excl_EP
5829 and then Addressable (Size_Excl_EP)
5830 then
5831 Actual_Size := Size_Excl_EP;
5832 Actual_Lo := Loval_Excl_EP;
5833 Actual_Hi := Hival_Excl_EP;
5835 -- Otherwise we can definitely include the end points
5837 else
5838 Actual_Size := Size_Incl_EP;
5839 Actual_Lo := Loval_Incl_EP;
5840 Actual_Hi := Hival_Incl_EP;
5841 end if;
5843 -- One pathological case: normally we never fudge a low bound
5844 -- down, since it would seem to increase the size (if it has
5845 -- any effect), but for ranges containing single value, or no
5846 -- values, the high bound can be small too large. Consider:
5848 -- type t is delta 2.0**(-14)
5849 -- range 131072.0 .. 0;
5851 -- That lower bound is *just* outside the range of 32 bits, and
5852 -- does need fudging down in this case. Note that the bounds
5853 -- will always have crossed here, since the high bound will be
5854 -- fudged down if necessary, as in the case of:
5856 -- type t is delta 2.0**(-14)
5857 -- range 131072.0 .. 131072.0;
5859 -- So we detect the situation by looking for crossed bounds,
5860 -- and if the bounds are crossed, and the low bound is greater
5861 -- than zero, we will always back it off by small, since this
5862 -- is completely harmless.
5864 if Actual_Lo > Actual_Hi then
5865 if UR_Is_Positive (Actual_Lo) then
5866 Actual_Lo := Loval_Incl_EP - Small;
5867 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
5869 -- And of course, we need to do exactly the same parallel
5870 -- fudge for flat ranges in the negative region.
5872 elsif UR_Is_Negative (Actual_Hi) then
5873 Actual_Hi := Hival_Incl_EP + Small;
5874 Actual_Size := Fsize (Actual_Lo, Actual_Hi);
5875 end if;
5876 end if;
5877 end if;
5879 Set_Realval (Lo, Actual_Lo);
5880 Set_Realval (Hi, Actual_Hi);
5881 end Fudge;
5883 -- For the decimal case, none of this fudging is required, since there
5884 -- are no end-point problems in the decimal case (the end-points are
5885 -- always included).
5887 else
5888 Actual_Size := Fsize (Loval, Hival);
5889 end if;
5891 -- At this stage, the actual size has been calculated and the proper
5892 -- required bounds are stored in the low and high bounds.
5894 if Actual_Size > 64 then
5895 Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
5896 Error_Msg_N
5897 ("size required (^) for type& too large, maximum allowed is 64",
5898 Typ);
5899 Actual_Size := 64;
5900 end if;
5902 -- Check size against explicit given size
5904 if Has_Size_Clause (Typ) then
5905 if Actual_Size > RM_Size (Typ) then
5906 Error_Msg_Uint_1 := RM_Size (Typ);
5907 Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
5908 Error_Msg_NE
5909 ("size given (^) for type& too small, minimum allowed is ^",
5910 Size_Clause (Typ), Typ);
5912 else
5913 Actual_Size := UI_To_Int (Esize (Typ));
5914 end if;
5916 -- Increase size to next natural boundary if no size clause given
5918 else
5919 if Actual_Size <= 8 then
5920 Actual_Size := 8;
5921 elsif Actual_Size <= 16 then
5922 Actual_Size := 16;
5923 elsif Actual_Size <= 32 then
5924 Actual_Size := 32;
5925 else
5926 Actual_Size := 64;
5927 end if;
5929 Init_Esize (Typ, Actual_Size);
5930 Adjust_Esize_For_Alignment (Typ);
5931 end if;
5933 -- If we have a base type, then expand the bounds so that they extend to
5934 -- the full width of the allocated size in bits, to avoid junk range
5935 -- checks on intermediate computations.
5937 if Base_Type (Typ) = Typ then
5938 Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
5939 Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
5940 end if;
5942 -- Final step is to reanalyze the bounds using the proper type
5943 -- and set the Corresponding_Integer_Value fields of the literals.
5945 Set_Etype (Lo, Empty);
5946 Set_Analyzed (Lo, False);
5947 Analyze (Lo);
5949 -- Resolve with universal fixed if the base type, and the base type if
5950 -- it is a subtype. Note we can't resolve the base type with itself,
5951 -- that would be a reference before definition.
5953 if Typ = Btyp then
5954 Resolve (Lo, Universal_Fixed);
5955 else
5956 Resolve (Lo, Btyp);
5957 end if;
5959 -- Set corresponding integer value for bound
5961 Set_Corresponding_Integer_Value
5962 (Lo, UR_To_Uint (Realval (Lo) / Small));
5964 -- Similar processing for high bound
5966 Set_Etype (Hi, Empty);
5967 Set_Analyzed (Hi, False);
5968 Analyze (Hi);
5970 if Typ = Btyp then
5971 Resolve (Hi, Universal_Fixed);
5972 else
5973 Resolve (Hi, Btyp);
5974 end if;
5976 Set_Corresponding_Integer_Value
5977 (Hi, UR_To_Uint (Realval (Hi) / Small));
5979 -- Set type of range to correspond to bounds
5981 Set_Etype (Rng, Etype (Lo));
5983 -- Set Esize to calculated size if not set already
5985 if Unknown_Esize (Typ) then
5986 Init_Esize (Typ, Actual_Size);
5987 end if;
5989 -- Set RM_Size if not already set. If already set, check value
5991 declare
5992 Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
5994 begin
5995 if RM_Size (Typ) /= Uint_0 then
5996 if RM_Size (Typ) < Minsiz then
5997 Error_Msg_Uint_1 := RM_Size (Typ);
5998 Error_Msg_Uint_2 := Minsiz;
5999 Error_Msg_NE
6000 ("size given (^) for type& too small, minimum allowed is ^",
6001 Size_Clause (Typ), Typ);
6002 end if;
6004 else
6005 Set_RM_Size (Typ, Minsiz);
6006 end if;
6007 end;
6008 end Freeze_Fixed_Point_Type;
6010 ------------------
6011 -- Freeze_Itype --
6012 ------------------
6014 procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
6015 L : List_Id;
6017 begin
6018 Set_Has_Delayed_Freeze (T);
6019 L := Freeze_Entity (T, N);
6021 if Is_Non_Empty_List (L) then
6022 Insert_Actions (N, L);
6023 end if;
6024 end Freeze_Itype;
6026 --------------------------
6027 -- Freeze_Static_Object --
6028 --------------------------
6030 procedure Freeze_Static_Object (E : Entity_Id) is
6032 Cannot_Be_Static : exception;
6033 -- Exception raised if the type of a static object cannot be made
6034 -- static. This happens if the type depends on non-global objects.
6036 procedure Ensure_Expression_Is_SA (N : Node_Id);
6037 -- Called to ensure that an expression used as part of a type definition
6038 -- is statically allocatable, which means that the expression type is
6039 -- statically allocatable, and the expression is either static, or a
6040 -- reference to a library level constant.
6042 procedure Ensure_Type_Is_SA (Typ : Entity_Id);
6043 -- Called to mark a type as static, checking that it is possible
6044 -- to set the type as static. If it is not possible, then the
6045 -- exception Cannot_Be_Static is raised.
6047 -----------------------------
6048 -- Ensure_Expression_Is_SA --
6049 -----------------------------
6051 procedure Ensure_Expression_Is_SA (N : Node_Id) is
6052 Ent : Entity_Id;
6054 begin
6055 Ensure_Type_Is_SA (Etype (N));
6057 if Is_Static_Expression (N) then
6058 return;
6060 elsif Nkind (N) = N_Identifier then
6061 Ent := Entity (N);
6063 if Present (Ent)
6064 and then Ekind (Ent) = E_Constant
6065 and then Is_Library_Level_Entity (Ent)
6066 then
6067 return;
6068 end if;
6069 end if;
6071 raise Cannot_Be_Static;
6072 end Ensure_Expression_Is_SA;
6074 -----------------------
6075 -- Ensure_Type_Is_SA --
6076 -----------------------
6078 procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
6079 N : Node_Id;
6080 C : Entity_Id;
6082 begin
6083 -- If type is library level, we are all set
6085 if Is_Library_Level_Entity (Typ) then
6086 return;
6087 end if;
6089 -- We are also OK if the type already marked as statically allocated,
6090 -- which means we processed it before.
6092 if Is_Statically_Allocated (Typ) then
6093 return;
6094 end if;
6096 -- Mark type as statically allocated
6098 Set_Is_Statically_Allocated (Typ);
6100 -- Check that it is safe to statically allocate this type
6102 if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
6103 Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
6104 Ensure_Expression_Is_SA (Type_High_Bound (Typ));
6106 elsif Is_Array_Type (Typ) then
6107 N := First_Index (Typ);
6108 while Present (N) loop
6109 Ensure_Type_Is_SA (Etype (N));
6110 Next_Index (N);
6111 end loop;
6113 Ensure_Type_Is_SA (Component_Type (Typ));
6115 elsif Is_Access_Type (Typ) then
6116 if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
6118 declare
6119 F : Entity_Id;
6120 T : constant Entity_Id := Etype (Designated_Type (Typ));
6122 begin
6123 if T /= Standard_Void_Type then
6124 Ensure_Type_Is_SA (T);
6125 end if;
6127 F := First_Formal (Designated_Type (Typ));
6128 while Present (F) loop
6129 Ensure_Type_Is_SA (Etype (F));
6130 Next_Formal (F);
6131 end loop;
6132 end;
6134 else
6135 Ensure_Type_Is_SA (Designated_Type (Typ));
6136 end if;
6138 elsif Is_Record_Type (Typ) then
6139 C := First_Entity (Typ);
6140 while Present (C) loop
6141 if Ekind (C) = E_Discriminant
6142 or else Ekind (C) = E_Component
6143 then
6144 Ensure_Type_Is_SA (Etype (C));
6146 elsif Is_Type (C) then
6147 Ensure_Type_Is_SA (C);
6148 end if;
6150 Next_Entity (C);
6151 end loop;
6153 elsif Ekind (Typ) = E_Subprogram_Type then
6154 Ensure_Type_Is_SA (Etype (Typ));
6156 C := First_Formal (Typ);
6157 while Present (C) loop
6158 Ensure_Type_Is_SA (Etype (C));
6159 Next_Formal (C);
6160 end loop;
6162 else
6163 raise Cannot_Be_Static;
6164 end if;
6165 end Ensure_Type_Is_SA;
6167 -- Start of processing for Freeze_Static_Object
6169 begin
6170 Ensure_Type_Is_SA (Etype (E));
6172 exception
6173 when Cannot_Be_Static =>
6175 -- If the object that cannot be static is imported or exported, then
6176 -- issue an error message saying that this object cannot be imported
6177 -- or exported. If it has an address clause it is an overlay in the
6178 -- current partition and the static requirement is not relevant.
6179 -- Do not issue any error message when ignoring rep clauses.
6181 if Ignore_Rep_Clauses then
6182 null;
6184 elsif Is_Imported (E) then
6185 if No (Address_Clause (E)) then
6186 Error_Msg_N
6187 ("& cannot be imported (local type is not constant)", E);
6188 end if;
6190 -- Otherwise must be exported, something is wrong if compiler
6191 -- is marking something as statically allocated which cannot be).
6193 else pragma Assert (Is_Exported (E));
6194 Error_Msg_N
6195 ("& cannot be exported (local type is not constant)", E);
6196 end if;
6197 end Freeze_Static_Object;
6199 -----------------------
6200 -- Freeze_Subprogram --
6201 -----------------------
6203 procedure Freeze_Subprogram (E : Entity_Id) is
6204 Retype : Entity_Id;
6205 F : Entity_Id;
6207 begin
6208 -- Subprogram may not have an address clause unless it is imported
6210 if Present (Address_Clause (E)) then
6211 if not Is_Imported (E) then
6212 Error_Msg_N
6213 ("address clause can only be given " &
6214 "for imported subprogram",
6215 Name (Address_Clause (E)));
6216 end if;
6217 end if;
6219 -- Reset the Pure indication on an imported subprogram unless an
6220 -- explicit Pure_Function pragma was present. We do this because
6221 -- otherwise it is an insidious error to call a non-pure function from
6222 -- pure unit and have calls mysteriously optimized away. What happens
6223 -- here is that the Import can bypass the normal check to ensure that
6224 -- pure units call only pure subprograms.
6226 if Is_Imported (E)
6227 and then Is_Pure (E)
6228 and then not Has_Pragma_Pure_Function (E)
6229 then
6230 Set_Is_Pure (E, False);
6231 end if;
6233 -- For non-foreign convention subprograms, this is where we create
6234 -- the extra formals (for accessibility level and constrained bit
6235 -- information). We delay this till the freeze point precisely so
6236 -- that we know the convention!
6238 if not Has_Foreign_Convention (E) then
6239 Create_Extra_Formals (E);
6240 Set_Mechanisms (E);
6242 -- If this is convention Ada and a Valued_Procedure, that's odd
6244 if Ekind (E) = E_Procedure
6245 and then Is_Valued_Procedure (E)
6246 and then Convention (E) = Convention_Ada
6247 and then Warn_On_Export_Import
6248 then
6249 Error_Msg_N
6250 ("??Valued_Procedure has no effect for convention Ada", E);
6251 Set_Is_Valued_Procedure (E, False);
6252 end if;
6254 -- Case of foreign convention
6256 else
6257 Set_Mechanisms (E);
6259 -- For foreign conventions, warn about return of an
6260 -- unconstrained array.
6262 -- Note: we *do* allow a return by descriptor for the VMS case,
6263 -- though here there is probably more to be done ???
6265 if Ekind (E) = E_Function then
6266 Retype := Underlying_Type (Etype (E));
6268 -- If no return type, probably some other error, e.g. a
6269 -- missing full declaration, so ignore.
6271 if No (Retype) then
6272 null;
6274 -- If the return type is generic, we have emitted a warning
6275 -- earlier on, and there is nothing else to check here. Specific
6276 -- instantiations may lead to erroneous behavior.
6278 elsif Is_Generic_Type (Etype (E)) then
6279 null;
6281 -- Display warning if returning unconstrained array
6283 elsif Is_Array_Type (Retype)
6284 and then not Is_Constrained (Retype)
6286 -- Exclude cases where descriptor mechanism is set, since the
6287 -- VMS descriptor mechanisms allow such unconstrained returns.
6289 and then Mechanism (E) not in Descriptor_Codes
6291 -- Check appropriate warning is enabled (should we check for
6292 -- Warnings (Off) on specific entities here, probably so???)
6294 and then Warn_On_Export_Import
6296 -- Exclude the VM case, since return of unconstrained arrays
6297 -- is properly handled in both the JVM and .NET cases.
6299 and then VM_Target = No_VM
6300 then
6301 Error_Msg_N
6302 ("?x?foreign convention function& should not return " &
6303 "unconstrained array", E);
6304 return;
6305 end if;
6306 end if;
6308 -- If any of the formals for an exported foreign convention
6309 -- subprogram have defaults, then emit an appropriate warning since
6310 -- this is odd (default cannot be used from non-Ada code)
6312 if Is_Exported (E) then
6313 F := First_Formal (E);
6314 while Present (F) loop
6315 if Warn_On_Export_Import
6316 and then Present (Default_Value (F))
6317 then
6318 Error_Msg_N
6319 ("?x?parameter cannot be defaulted in non-Ada call",
6320 Default_Value (F));
6321 end if;
6323 Next_Formal (F);
6324 end loop;
6325 end if;
6326 end if;
6328 -- For VMS, descriptor mechanisms for parameters are allowed only for
6329 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6330 -- allowed for parameters of exported subprograms.
6332 if OpenVMS_On_Target then
6333 if Is_Exported (E) then
6334 F := First_Formal (E);
6335 while Present (F) loop
6336 if Mechanism (F) = By_Descriptor_NCA then
6337 Error_Msg_N
6338 ("'N'C'A' descriptor for parameter not permitted", F);
6339 Error_Msg_N
6340 ("\can only be used for imported subprogram", F);
6341 end if;
6343 Next_Formal (F);
6344 end loop;
6346 elsif not Is_Imported (E) then
6347 F := First_Formal (E);
6348 while Present (F) loop
6349 if Mechanism (F) in Descriptor_Codes then
6350 Error_Msg_N
6351 ("descriptor mechanism for parameter not permitted", F);
6352 Error_Msg_N
6353 ("\can only be used for imported/exported subprogram", F);
6354 end if;
6356 Next_Formal (F);
6357 end loop;
6358 end if;
6359 end if;
6361 -- Pragma Inline_Always is disallowed for dispatching subprograms
6362 -- because the address of such subprograms is saved in the dispatch
6363 -- table to support dispatching calls, and dispatching calls cannot
6364 -- be inlined. This is consistent with the restriction against using
6365 -- 'Access or 'Address on an Inline_Always subprogram.
6367 if Is_Dispatching_Operation (E)
6368 and then Has_Pragma_Inline_Always (E)
6369 then
6370 Error_Msg_N
6371 ("pragma Inline_Always not allowed for dispatching subprograms", E);
6372 end if;
6374 -- Because of the implicit representation of inherited predefined
6375 -- operators in the front-end, the overriding status of the operation
6376 -- may be affected when a full view of a type is analyzed, and this is
6377 -- not captured by the analysis of the corresponding type declaration.
6378 -- Therefore the correctness of a not-overriding indicator must be
6379 -- rechecked when the subprogram is frozen.
6381 if Nkind (E) = N_Defining_Operator_Symbol
6382 and then not Error_Posted (Parent (E))
6383 then
6384 Check_Overriding_Indicator (E, Empty, Is_Primitive (E));
6385 end if;
6386 end Freeze_Subprogram;
6388 ----------------------
6389 -- Is_Fully_Defined --
6390 ----------------------
6392 function Is_Fully_Defined (T : Entity_Id) return Boolean is
6393 begin
6394 if Ekind (T) = E_Class_Wide_Type then
6395 return Is_Fully_Defined (Etype (T));
6397 elsif Is_Array_Type (T) then
6398 return Is_Fully_Defined (Component_Type (T));
6400 elsif Is_Record_Type (T)
6401 and not Is_Private_Type (T)
6402 then
6403 -- Verify that the record type has no components with private types
6404 -- without completion.
6406 declare
6407 Comp : Entity_Id;
6409 begin
6410 Comp := First_Component (T);
6411 while Present (Comp) loop
6412 if not Is_Fully_Defined (Etype (Comp)) then
6413 return False;
6414 end if;
6416 Next_Component (Comp);
6417 end loop;
6418 return True;
6419 end;
6421 -- For the designated type of an access to subprogram, all types in
6422 -- the profile must be fully defined.
6424 elsif Ekind (T) = E_Subprogram_Type then
6425 declare
6426 F : Entity_Id;
6428 begin
6429 F := First_Formal (T);
6430 while Present (F) loop
6431 if not Is_Fully_Defined (Etype (F)) then
6432 return False;
6433 end if;
6435 Next_Formal (F);
6436 end loop;
6438 return Is_Fully_Defined (Etype (T));
6439 end;
6441 else
6442 return not Is_Private_Type (T)
6443 or else Present (Full_View (Base_Type (T)));
6444 end if;
6445 end Is_Fully_Defined;
6447 ---------------------------------
6448 -- Process_Default_Expressions --
6449 ---------------------------------
6451 procedure Process_Default_Expressions
6452 (E : Entity_Id;
6453 After : in out Node_Id)
6455 Loc : constant Source_Ptr := Sloc (E);
6456 Dbody : Node_Id;
6457 Formal : Node_Id;
6458 Dcopy : Node_Id;
6459 Dnam : Entity_Id;
6461 begin
6462 Set_Default_Expressions_Processed (E);
6464 -- A subprogram instance and its associated anonymous subprogram share
6465 -- their signature. The default expression functions are defined in the
6466 -- wrapper packages for the anonymous subprogram, and should not be
6467 -- generated again for the instance.
6469 if Is_Generic_Instance (E)
6470 and then Present (Alias (E))
6471 and then Default_Expressions_Processed (Alias (E))
6472 then
6473 return;
6474 end if;
6476 Formal := First_Formal (E);
6477 while Present (Formal) loop
6478 if Present (Default_Value (Formal)) then
6480 -- We work with a copy of the default expression because we
6481 -- do not want to disturb the original, since this would mess
6482 -- up the conformance checking.
6484 Dcopy := New_Copy_Tree (Default_Value (Formal));
6486 -- The analysis of the expression may generate insert actions,
6487 -- which of course must not be executed. We wrap those actions
6488 -- in a procedure that is not called, and later on eliminated.
6489 -- The following cases have no side-effects, and are analyzed
6490 -- directly.
6492 if Nkind (Dcopy) = N_Identifier
6493 or else Nkind (Dcopy) = N_Expanded_Name
6494 or else Nkind (Dcopy) = N_Integer_Literal
6495 or else (Nkind (Dcopy) = N_Real_Literal
6496 and then not Vax_Float (Etype (Dcopy)))
6497 or else Nkind (Dcopy) = N_Character_Literal
6498 or else Nkind (Dcopy) = N_String_Literal
6499 or else Known_Null (Dcopy)
6500 or else (Nkind (Dcopy) = N_Attribute_Reference
6501 and then
6502 Attribute_Name (Dcopy) = Name_Null_Parameter)
6503 then
6505 -- If there is no default function, we must still do a full
6506 -- analyze call on the default value, to ensure that all error
6507 -- checks are performed, e.g. those associated with static
6508 -- evaluation. Note: this branch will always be taken if the
6509 -- analyzer is turned off (but we still need the error checks).
6511 -- Note: the setting of parent here is to meet the requirement
6512 -- that we can only analyze the expression while attached to
6513 -- the tree. Really the requirement is that the parent chain
6514 -- be set, we don't actually need to be in the tree.
6516 Set_Parent (Dcopy, Declaration_Node (Formal));
6517 Analyze (Dcopy);
6519 -- Default expressions are resolved with their own type if the
6520 -- context is generic, to avoid anomalies with private types.
6522 if Ekind (Scope (E)) = E_Generic_Package then
6523 Resolve (Dcopy);
6524 else
6525 Resolve (Dcopy, Etype (Formal));
6526 end if;
6528 -- If that resolved expression will raise constraint error,
6529 -- then flag the default value as raising constraint error.
6530 -- This allows a proper error message on the calls.
6532 if Raises_Constraint_Error (Dcopy) then
6533 Set_Raises_Constraint_Error (Default_Value (Formal));
6534 end if;
6536 -- If the default is a parameterless call, we use the name of
6537 -- the called function directly, and there is no body to build.
6539 elsif Nkind (Dcopy) = N_Function_Call
6540 and then No (Parameter_Associations (Dcopy))
6541 then
6542 null;
6544 -- Else construct and analyze the body of a wrapper procedure
6545 -- that contains an object declaration to hold the expression.
6546 -- Given that this is done only to complete the analysis, it
6547 -- simpler to build a procedure than a function which might
6548 -- involve secondary stack expansion.
6550 else
6551 Dnam := Make_Temporary (Loc, 'D');
6553 Dbody :=
6554 Make_Subprogram_Body (Loc,
6555 Specification =>
6556 Make_Procedure_Specification (Loc,
6557 Defining_Unit_Name => Dnam),
6559 Declarations => New_List (
6560 Make_Object_Declaration (Loc,
6561 Defining_Identifier => Make_Temporary (Loc, 'T'),
6562 Object_Definition =>
6563 New_Occurrence_Of (Etype (Formal), Loc),
6564 Expression => New_Copy_Tree (Dcopy))),
6566 Handled_Statement_Sequence =>
6567 Make_Handled_Sequence_Of_Statements (Loc,
6568 Statements => Empty_List));
6570 Set_Scope (Dnam, Scope (E));
6571 Set_Assignment_OK (First (Declarations (Dbody)));
6572 Set_Is_Eliminated (Dnam);
6573 Insert_After (After, Dbody);
6574 Analyze (Dbody);
6575 After := Dbody;
6576 end if;
6577 end if;
6579 Next_Formal (Formal);
6580 end loop;
6581 end Process_Default_Expressions;
6583 ----------------------------------------
6584 -- Set_Component_Alignment_If_Not_Set --
6585 ----------------------------------------
6587 procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
6588 begin
6589 -- Ignore if not base type, subtypes don't need anything
6591 if Typ /= Base_Type (Typ) then
6592 return;
6593 end if;
6595 -- Do not override existing representation
6597 if Is_Packed (Typ) then
6598 return;
6600 elsif Has_Specified_Layout (Typ) then
6601 return;
6603 elsif Component_Alignment (Typ) /= Calign_Default then
6604 return;
6606 else
6607 Set_Component_Alignment
6608 (Typ, Scope_Stack.Table
6609 (Scope_Stack.Last).Component_Alignment_Default);
6610 end if;
6611 end Set_Component_Alignment_If_Not_Set;
6613 ------------------
6614 -- Undelay_Type --
6615 ------------------
6617 procedure Undelay_Type (T : Entity_Id) is
6618 begin
6619 Set_Has_Delayed_Freeze (T, False);
6620 Set_Freeze_Node (T, Empty);
6622 -- Since we don't want T to have a Freeze_Node, we don't want its
6623 -- Full_View or Corresponding_Record_Type to have one either.
6625 -- ??? Fundamentally, this whole handling is a kludge. What we really
6626 -- want is to be sure that for an Itype that's part of record R and is a
6627 -- subtype of type T, that it's frozen after the later of the freeze
6628 -- points of R and T. We have no way of doing that directly, so what we
6629 -- do is force most such Itypes to be frozen as part of freezing R via
6630 -- this procedure and only delay the ones that need to be delayed
6631 -- (mostly the designated types of access types that are defined as part
6632 -- of the record).
6634 if Is_Private_Type (T)
6635 and then Present (Full_View (T))
6636 and then Is_Itype (Full_View (T))
6637 and then Is_Record_Type (Scope (Full_View (T)))
6638 then
6639 Undelay_Type (Full_View (T));
6640 end if;
6642 if Is_Concurrent_Type (T)
6643 and then Present (Corresponding_Record_Type (T))
6644 and then Is_Itype (Corresponding_Record_Type (T))
6645 and then Is_Record_Type (Scope (Corresponding_Record_Type (T)))
6646 then
6647 Undelay_Type (Corresponding_Record_Type (T));
6648 end if;
6649 end Undelay_Type;
6651 ------------------
6652 -- Warn_Overlay --
6653 ------------------
6655 procedure Warn_Overlay
6656 (Expr : Node_Id;
6657 Typ : Entity_Id;
6658 Nam : Entity_Id)
6660 Ent : constant Entity_Id := Entity (Nam);
6661 -- The object to which the address clause applies
6663 Init : Node_Id;
6664 Old : Entity_Id := Empty;
6665 Decl : Node_Id;
6667 begin
6668 -- No warning if address clause overlay warnings are off
6670 if not Address_Clause_Overlay_Warnings then
6671 return;
6672 end if;
6674 -- No warning if there is an explicit initialization
6676 Init := Original_Node (Expression (Declaration_Node (Ent)));
6678 if Present (Init) and then Comes_From_Source (Init) then
6679 return;
6680 end if;
6682 -- We only give the warning for non-imported entities of a type for
6683 -- which a non-null base init proc is defined, or for objects of access
6684 -- types with implicit null initialization, or when Normalize_Scalars
6685 -- applies and the type is scalar or a string type (the latter being
6686 -- tested for because predefined String types are initialized by inline
6687 -- code rather than by an init_proc). Note that we do not give the
6688 -- warning for Initialize_Scalars, since we suppressed initialization
6689 -- in this case. Also, do not warn if Suppress_Initialization is set.
6691 if Present (Expr)
6692 and then not Is_Imported (Ent)
6693 and then not Initialization_Suppressed (Typ)
6694 and then (Has_Non_Null_Base_Init_Proc (Typ)
6695 or else Is_Access_Type (Typ)
6696 or else (Normalize_Scalars
6697 and then (Is_Scalar_Type (Typ)
6698 or else Is_String_Type (Typ))))
6699 then
6700 if Nkind (Expr) = N_Attribute_Reference
6701 and then Is_Entity_Name (Prefix (Expr))
6702 then
6703 Old := Entity (Prefix (Expr));
6705 elsif Is_Entity_Name (Expr)
6706 and then Ekind (Entity (Expr)) = E_Constant
6707 then
6708 Decl := Declaration_Node (Entity (Expr));
6710 if Nkind (Decl) = N_Object_Declaration
6711 and then Present (Expression (Decl))
6712 and then Nkind (Expression (Decl)) = N_Attribute_Reference
6713 and then Is_Entity_Name (Prefix (Expression (Decl)))
6714 then
6715 Old := Entity (Prefix (Expression (Decl)));
6717 elsif Nkind (Expr) = N_Function_Call then
6718 return;
6719 end if;
6721 -- A function call (most likely to To_Address) is probably not an
6722 -- overlay, so skip warning. Ditto if the function call was inlined
6723 -- and transformed into an entity.
6725 elsif Nkind (Original_Node (Expr)) = N_Function_Call then
6726 return;
6727 end if;
6729 Decl := Next (Parent (Expr));
6731 -- If a pragma Import follows, we assume that it is for the current
6732 -- target of the address clause, and skip the warning.
6734 if Present (Decl)
6735 and then Nkind (Decl) = N_Pragma
6736 and then Pragma_Name (Decl) = Name_Import
6737 then
6738 return;
6739 end if;
6741 if Present (Old) then
6742 Error_Msg_Node_2 := Old;
6743 Error_Msg_N
6744 ("default initialization of & may modify &??",
6745 Nam);
6746 else
6747 Error_Msg_N
6748 ("default initialization of & may modify overlaid storage??",
6749 Nam);
6750 end if;
6752 -- Add friendly warning if initialization comes from a packed array
6753 -- component.
6755 if Is_Record_Type (Typ) then
6756 declare
6757 Comp : Entity_Id;
6759 begin
6760 Comp := First_Component (Typ);
6761 while Present (Comp) loop
6762 if Nkind (Parent (Comp)) = N_Component_Declaration
6763 and then Present (Expression (Parent (Comp)))
6764 then
6765 exit;
6766 elsif Is_Array_Type (Etype (Comp))
6767 and then Present (Packed_Array_Type (Etype (Comp)))
6768 then
6769 Error_Msg_NE
6770 ("\packed array component& " &
6771 "will be initialized to zero??",
6772 Nam, Comp);
6773 exit;
6774 else
6775 Next_Component (Comp);
6776 end if;
6777 end loop;
6778 end;
6779 end if;
6781 Error_Msg_N
6782 ("\use pragma Import for & to " &
6783 "suppress initialization (RM B.1(24))??",
6784 Nam);
6785 end if;
6786 end Warn_Overlay;
6788 end Freeze;