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