]>
Commit | Line | Data |
---|---|---|
70482933 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- F R E E Z E -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
57747aec | 9 | -- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- |
70482933 RK |
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 2, 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 COPYING. If not, write -- | |
cb5fee25 KC |
19 | -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- |
20 | -- Boston, MA 02110-1301, USA. -- | |
70482933 RK |
21 | -- -- |
22 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 23 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
70482933 RK |
24 | -- -- |
25 | ------------------------------------------------------------------------------ | |
26 | ||
27 | with Atree; use Atree; | |
28 | with Debug; use Debug; | |
29 | with Einfo; use Einfo; | |
30 | with Elists; use Elists; | |
31 | with Errout; use Errout; | |
32 | with Exp_Ch7; use Exp_Ch7; | |
70482933 RK |
33 | with Exp_Pakd; use Exp_Pakd; |
34 | with Exp_Util; use Exp_Util; | |
fbf5a39b | 35 | with Exp_Tss; use Exp_Tss; |
70482933 | 36 | with Layout; use Layout; |
07fc65c4 | 37 | with Lib.Xref; use Lib.Xref; |
70482933 RK |
38 | with Nlists; use Nlists; |
39 | with Nmake; use Nmake; | |
40 | with Opt; use Opt; | |
41 | with Restrict; use Restrict; | |
6e937c1c | 42 | with Rident; use Rident; |
70482933 RK |
43 | with Sem; use Sem; |
44 | with Sem_Cat; use Sem_Cat; | |
45 | with Sem_Ch6; use Sem_Ch6; | |
46 | with Sem_Ch7; use Sem_Ch7; | |
47 | with Sem_Ch8; use Sem_Ch8; | |
48 | with Sem_Ch13; use Sem_Ch13; | |
49 | with Sem_Eval; use Sem_Eval; | |
50 | with Sem_Mech; use Sem_Mech; | |
51 | with Sem_Prag; use Sem_Prag; | |
52 | with Sem_Res; use Sem_Res; | |
53 | with Sem_Util; use Sem_Util; | |
54 | with Sinfo; use Sinfo; | |
55 | with Snames; use Snames; | |
56 | with Stand; use Stand; | |
57 | with Targparm; use Targparm; | |
58 | with Tbuild; use Tbuild; | |
59 | with Ttypes; use Ttypes; | |
60 | with Uintp; use Uintp; | |
61 | with Urealp; use Urealp; | |
62 | ||
63 | package body Freeze is | |
64 | ||
65 | ----------------------- | |
66 | -- Local Subprograms -- | |
67 | ----------------------- | |
68 | ||
69 | procedure Adjust_Esize_For_Alignment (Typ : Entity_Id); | |
70 | -- Typ is a type that is being frozen. If no size clause is given, | |
71 | -- but a default Esize has been computed, then this default Esize is | |
72 | -- adjusted up if necessary to be consistent with a given alignment, | |
73 | -- but never to a value greater than Long_Long_Integer'Size. This | |
74 | -- is used for all discrete types and for fixed-point types. | |
75 | ||
76 | procedure Build_And_Analyze_Renamed_Body | |
77 | (Decl : Node_Id; | |
78 | New_S : Entity_Id; | |
79 | After : in out Node_Id); | |
49e90211 | 80 | -- Build body for a renaming declaration, insert in tree and analyze |
70482933 | 81 | |
fbf5a39b AC |
82 | procedure Check_Address_Clause (E : Entity_Id); |
83 | -- Apply legality checks to address clauses for object declarations, | |
2c9beb8a | 84 | -- at the point the object is frozen. |
fbf5a39b | 85 | |
70482933 RK |
86 | procedure Check_Strict_Alignment (E : Entity_Id); |
87 | -- E is a base type. If E is tagged or has a component that is aliased | |
88 | -- or tagged or contains something this is aliased or tagged, set | |
89 | -- Strict_Alignment. | |
90 | ||
91 | procedure Check_Unsigned_Type (E : Entity_Id); | |
92 | pragma Inline (Check_Unsigned_Type); | |
93 | -- If E is a fixed-point or discrete type, then all the necessary work | |
94 | -- to freeze it is completed except for possible setting of the flag | |
95 | -- Is_Unsigned_Type, which is done by this procedure. The call has no | |
96 | -- effect if the entity E is not a discrete or fixed-point type. | |
97 | ||
98 | procedure Freeze_And_Append | |
99 | (Ent : Entity_Id; | |
100 | Loc : Source_Ptr; | |
101 | Result : in out List_Id); | |
102 | -- Freezes Ent using Freeze_Entity, and appends the resulting list of | |
103 | -- nodes to Result, modifying Result from No_List if necessary. | |
104 | ||
105 | procedure Freeze_Enumeration_Type (Typ : Entity_Id); | |
106 | -- Freeze enumeration type. The Esize field is set as processing | |
107 | -- proceeds (i.e. set by default when the type is declared and then | |
108 | -- adjusted by rep clauses. What this procedure does is to make sure | |
109 | -- that if a foreign convention is specified, and no specific size | |
110 | -- is given, then the size must be at least Integer'Size. | |
111 | ||
70482933 RK |
112 | procedure Freeze_Static_Object (E : Entity_Id); |
113 | -- If an object is frozen which has Is_Statically_Allocated set, then | |
114 | -- all referenced types must also be marked with this flag. This routine | |
115 | -- is in charge of meeting this requirement for the object entity E. | |
116 | ||
117 | procedure Freeze_Subprogram (E : Entity_Id); | |
118 | -- Perform freezing actions for a subprogram (create extra formals, | |
119 | -- and set proper default mechanism values). Note that this routine | |
120 | -- is not called for internal subprograms, for which neither of these | |
121 | -- actions is needed (or desirable, we do not want for example to have | |
122 | -- these extra formals present in initialization procedures, where they | |
123 | -- would serve no purpose). In this call E is either a subprogram or | |
124 | -- a subprogram type (i.e. an access to a subprogram). | |
125 | ||
126 | function Is_Fully_Defined (T : Entity_Id) return Boolean; | |
bde58e32 | 127 | -- True if T is not private and has no private components, or has a full |
657a9dd9 AC |
128 | -- view. Used to determine whether the designated type of an access type |
129 | -- should be frozen when the access type is frozen. This is done when an | |
130 | -- allocator is frozen, or an expression that may involve attributes of | |
131 | -- the designated type. Otherwise freezing the access type does not freeze | |
132 | -- the designated type. | |
70482933 RK |
133 | |
134 | procedure Process_Default_Expressions | |
135 | (E : Entity_Id; | |
136 | After : in out Node_Id); | |
137 | -- This procedure is called for each subprogram to complete processing | |
138 | -- of default expressions at the point where all types are known to be | |
139 | -- frozen. The expressions must be analyzed in full, to make sure that | |
140 | -- all error processing is done (they have only been pre-analyzed). If | |
141 | -- the expression is not an entity or literal, its analysis may generate | |
142 | -- code which must not be executed. In that case we build a function | |
143 | -- body to hold that code. This wrapper function serves no other purpose | |
144 | -- (it used to be called to evaluate the default, but now the default is | |
145 | -- inlined at each point of call). | |
146 | ||
147 | procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id); | |
148 | -- Typ is a record or array type that is being frozen. This routine | |
149 | -- sets the default component alignment from the scope stack values | |
150 | -- if the alignment is otherwise not specified. | |
151 | ||
152 | procedure Check_Debug_Info_Needed (T : Entity_Id); | |
153 | -- As each entity is frozen, this routine is called to deal with the | |
154 | -- setting of Debug_Info_Needed for the entity. This flag is set if | |
155 | -- the entity comes from source, or if we are in Debug_Generated_Code | |
156 | -- mode or if the -gnatdV debug flag is set. However, it never sets | |
157 | -- the flag if Debug_Info_Off is set. | |
158 | ||
159 | procedure Set_Debug_Info_Needed (T : Entity_Id); | |
160 | -- Sets the Debug_Info_Needed flag on entity T if not already set, and | |
161 | -- also on any entities that are needed by T (for an object, the type | |
162 | -- of the object is needed, and for a type, the subsidiary types are | |
163 | -- needed -- see body for details). Never has any effect on T if the | |
164 | -- Debug_Info_Off flag is set. | |
165 | ||
c6823a20 EB |
166 | procedure Undelay_Type (T : Entity_Id); |
167 | -- T is a type of a component that we know to be an Itype. | |
168 | -- We don't want this to have a Freeze_Node, so ensure it doesn't. | |
169 | -- Do the same for any Full_View or Corresponding_Record_Type. | |
170 | ||
fbf5a39b AC |
171 | procedure Warn_Overlay |
172 | (Expr : Node_Id; | |
173 | Typ : Entity_Id; | |
174 | Nam : Node_Id); | |
175 | -- Expr is the expression for an address clause for entity Nam whose type | |
176 | -- is Typ. If Typ has a default initialization, and there is no explicit | |
177 | -- initialization in the source declaration, check whether the address | |
178 | -- clause might cause overlaying of an entity, and emit a warning on the | |
179 | -- side effect that the initialization will cause. | |
180 | ||
70482933 RK |
181 | ------------------------------- |
182 | -- Adjust_Esize_For_Alignment -- | |
183 | ------------------------------- | |
184 | ||
185 | procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is | |
186 | Align : Uint; | |
187 | ||
188 | begin | |
189 | if Known_Esize (Typ) and then Known_Alignment (Typ) then | |
190 | Align := Alignment_In_Bits (Typ); | |
191 | ||
192 | if Align > Esize (Typ) | |
193 | and then Align <= Standard_Long_Long_Integer_Size | |
194 | then | |
195 | Set_Esize (Typ, Align); | |
196 | end if; | |
197 | end if; | |
198 | end Adjust_Esize_For_Alignment; | |
199 | ||
200 | ------------------------------------ | |
201 | -- Build_And_Analyze_Renamed_Body -- | |
202 | ------------------------------------ | |
203 | ||
204 | procedure Build_And_Analyze_Renamed_Body | |
205 | (Decl : Node_Id; | |
206 | New_S : Entity_Id; | |
207 | After : in out Node_Id) | |
208 | is | |
209 | Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S); | |
210 | ||
211 | begin | |
212 | Insert_After (After, Body_Node); | |
213 | Mark_Rewrite_Insertion (Body_Node); | |
214 | Analyze (Body_Node); | |
215 | After := Body_Node; | |
216 | end Build_And_Analyze_Renamed_Body; | |
217 | ||
218 | ------------------------ | |
219 | -- Build_Renamed_Body -- | |
220 | ------------------------ | |
221 | ||
222 | function Build_Renamed_Body | |
223 | (Decl : Node_Id; | |
fbf5a39b | 224 | New_S : Entity_Id) return Node_Id |
70482933 RK |
225 | is |
226 | Loc : constant Source_Ptr := Sloc (New_S); | |
227 | -- We use for the source location of the renamed body, the location | |
228 | -- of the spec entity. It might seem more natural to use the location | |
229 | -- of the renaming declaration itself, but that would be wrong, since | |
230 | -- then the body we create would look as though it was created far | |
231 | -- too late, and this could cause problems with elaboration order | |
232 | -- analysis, particularly in connection with instantiations. | |
233 | ||
234 | N : constant Node_Id := Unit_Declaration_Node (New_S); | |
235 | Nam : constant Node_Id := Name (N); | |
236 | Old_S : Entity_Id; | |
237 | Spec : constant Node_Id := New_Copy_Tree (Specification (Decl)); | |
238 | Actuals : List_Id := No_List; | |
239 | Call_Node : Node_Id; | |
240 | Call_Name : Node_Id; | |
241 | Body_Node : Node_Id; | |
242 | Formal : Entity_Id; | |
243 | O_Formal : Entity_Id; | |
244 | Param_Spec : Node_Id; | |
245 | ||
246 | begin | |
247 | -- Determine the entity being renamed, which is the target of the | |
248 | -- call statement. If the name is an explicit dereference, this is | |
249 | -- a renaming of a subprogram type rather than a subprogram. The | |
250 | -- name itself is fully analyzed. | |
251 | ||
252 | if Nkind (Nam) = N_Selected_Component then | |
253 | Old_S := Entity (Selector_Name (Nam)); | |
254 | ||
255 | elsif Nkind (Nam) = N_Explicit_Dereference then | |
256 | Old_S := Etype (Nam); | |
257 | ||
258 | elsif Nkind (Nam) = N_Indexed_Component then | |
70482933 RK |
259 | if Is_Entity_Name (Prefix (Nam)) then |
260 | Old_S := Entity (Prefix (Nam)); | |
261 | else | |
262 | Old_S := Entity (Selector_Name (Prefix (Nam))); | |
263 | end if; | |
264 | ||
265 | elsif Nkind (Nam) = N_Character_Literal then | |
266 | Old_S := Etype (New_S); | |
267 | ||
268 | else | |
269 | Old_S := Entity (Nam); | |
270 | end if; | |
271 | ||
272 | if Is_Entity_Name (Nam) then | |
07fc65c4 GB |
273 | |
274 | -- If the renamed entity is a predefined operator, retain full | |
275 | -- name to ensure its visibility. | |
276 | ||
277 | if Ekind (Old_S) = E_Operator | |
278 | and then Nkind (Nam) = N_Expanded_Name | |
279 | then | |
280 | Call_Name := New_Copy (Name (N)); | |
281 | else | |
282 | Call_Name := New_Reference_To (Old_S, Loc); | |
283 | end if; | |
284 | ||
70482933 RK |
285 | else |
286 | Call_Name := New_Copy (Name (N)); | |
287 | ||
288 | -- The original name may have been overloaded, but | |
289 | -- is fully resolved now. | |
290 | ||
291 | Set_Is_Overloaded (Call_Name, False); | |
292 | end if; | |
293 | ||
294 | -- For simple renamings, subsequent calls can be expanded directly | |
295 | -- as called to the renamed entity. The body must be generated in | |
296 | -- any case for calls they may appear elsewhere. | |
297 | ||
298 | if (Ekind (Old_S) = E_Function | |
299 | or else Ekind (Old_S) = E_Procedure) | |
300 | and then Nkind (Decl) = N_Subprogram_Declaration | |
301 | then | |
302 | Set_Body_To_Inline (Decl, Old_S); | |
303 | end if; | |
304 | ||
305 | -- The body generated for this renaming is an internal artifact, and | |
306 | -- does not constitute a freeze point for the called entity. | |
307 | ||
308 | Set_Must_Not_Freeze (Call_Name); | |
309 | ||
310 | Formal := First_Formal (Defining_Entity (Decl)); | |
311 | ||
312 | if Present (Formal) then | |
313 | Actuals := New_List; | |
314 | ||
315 | while Present (Formal) loop | |
316 | Append (New_Reference_To (Formal, Loc), Actuals); | |
317 | Next_Formal (Formal); | |
318 | end loop; | |
319 | end if; | |
320 | ||
321 | -- If the renamed entity is an entry, inherit its profile. For | |
322 | -- other renamings as bodies, both profiles must be subtype | |
323 | -- conformant, so it is not necessary to replace the profile given | |
324 | -- in the declaration. However, default values that are aggregates | |
325 | -- are rewritten when partially analyzed, so we recover the original | |
326 | -- aggregate to insure that subsequent conformity checking works. | |
07fc65c4 GB |
327 | -- Similarly, if the default expression was constant-folded, recover |
328 | -- the original expression. | |
70482933 RK |
329 | |
330 | Formal := First_Formal (Defining_Entity (Decl)); | |
331 | ||
332 | if Present (Formal) then | |
333 | O_Formal := First_Formal (Old_S); | |
334 | Param_Spec := First (Parameter_Specifications (Spec)); | |
335 | ||
336 | while Present (Formal) loop | |
337 | if Is_Entry (Old_S) then | |
338 | ||
339 | if Nkind (Parameter_Type (Param_Spec)) /= | |
340 | N_Access_Definition | |
341 | then | |
342 | Set_Etype (Formal, Etype (O_Formal)); | |
343 | Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal)); | |
344 | end if; | |
345 | ||
07fc65c4 GB |
346 | elsif Nkind (Default_Value (O_Formal)) = N_Aggregate |
347 | or else Nkind (Original_Node (Default_Value (O_Formal))) /= | |
348 | Nkind (Default_Value (O_Formal)) | |
349 | then | |
70482933 RK |
350 | Set_Expression (Param_Spec, |
351 | New_Copy_Tree (Original_Node (Default_Value (O_Formal)))); | |
352 | end if; | |
353 | ||
354 | Next_Formal (Formal); | |
355 | Next_Formal (O_Formal); | |
356 | Next (Param_Spec); | |
357 | end loop; | |
358 | end if; | |
359 | ||
360 | -- If the renamed entity is a function, the generated body contains a | |
361 | -- return statement. Otherwise, build a procedure call. If the entity is | |
362 | -- an entry, subsequent analysis of the call will transform it into the | |
363 | -- proper entry or protected operation call. If the renamed entity is | |
364 | -- a character literal, return it directly. | |
365 | ||
366 | if Ekind (Old_S) = E_Function | |
367 | or else Ekind (Old_S) = E_Operator | |
368 | or else (Ekind (Old_S) = E_Subprogram_Type | |
369 | and then Etype (Old_S) /= Standard_Void_Type) | |
370 | then | |
371 | Call_Node := | |
372 | Make_Return_Statement (Loc, | |
373 | Expression => | |
374 | Make_Function_Call (Loc, | |
375 | Name => Call_Name, | |
376 | Parameter_Associations => Actuals)); | |
377 | ||
378 | elsif Ekind (Old_S) = E_Enumeration_Literal then | |
379 | Call_Node := | |
380 | Make_Return_Statement (Loc, | |
381 | Expression => New_Occurrence_Of (Old_S, Loc)); | |
382 | ||
383 | elsif Nkind (Nam) = N_Character_Literal then | |
384 | Call_Node := | |
385 | Make_Return_Statement (Loc, | |
386 | Expression => Call_Name); | |
387 | ||
388 | else | |
389 | Call_Node := | |
390 | Make_Procedure_Call_Statement (Loc, | |
391 | Name => Call_Name, | |
392 | Parameter_Associations => Actuals); | |
393 | end if; | |
394 | ||
49e90211 | 395 | -- Create entities for subprogram body and formals |
70482933 RK |
396 | |
397 | Set_Defining_Unit_Name (Spec, | |
398 | Make_Defining_Identifier (Loc, Chars => Chars (New_S))); | |
399 | ||
400 | Param_Spec := First (Parameter_Specifications (Spec)); | |
401 | ||
402 | while Present (Param_Spec) loop | |
403 | Set_Defining_Identifier (Param_Spec, | |
404 | Make_Defining_Identifier (Loc, | |
405 | Chars => Chars (Defining_Identifier (Param_Spec)))); | |
406 | Next (Param_Spec); | |
407 | end loop; | |
408 | ||
409 | Body_Node := | |
410 | Make_Subprogram_Body (Loc, | |
411 | Specification => Spec, | |
412 | Declarations => New_List, | |
413 | Handled_Statement_Sequence => | |
414 | Make_Handled_Sequence_Of_Statements (Loc, | |
415 | Statements => New_List (Call_Node))); | |
416 | ||
417 | if Nkind (Decl) /= N_Subprogram_Declaration then | |
418 | Rewrite (N, | |
419 | Make_Subprogram_Declaration (Loc, | |
420 | Specification => Specification (N))); | |
421 | end if; | |
422 | ||
423 | -- Link the body to the entity whose declaration it completes. If | |
424 | -- the body is analyzed when the renamed entity is frozen, it may be | |
425 | -- necessary to restore the proper scope (see package Exp_Ch13). | |
426 | ||
427 | if Nkind (N) = N_Subprogram_Renaming_Declaration | |
428 | and then Present (Corresponding_Spec (N)) | |
429 | then | |
430 | Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N)); | |
431 | else | |
432 | Set_Corresponding_Spec (Body_Node, New_S); | |
433 | end if; | |
434 | ||
435 | return Body_Node; | |
436 | end Build_Renamed_Body; | |
437 | ||
fbf5a39b AC |
438 | -------------------------- |
439 | -- Check_Address_Clause -- | |
440 | -------------------------- | |
441 | ||
442 | procedure Check_Address_Clause (E : Entity_Id) is | |
443 | Addr : constant Node_Id := Address_Clause (E); | |
444 | Expr : Node_Id; | |
445 | Decl : constant Node_Id := Declaration_Node (E); | |
446 | Typ : constant Entity_Id := Etype (E); | |
447 | ||
448 | begin | |
449 | if Present (Addr) then | |
450 | Expr := Expression (Addr); | |
451 | ||
452 | -- If we have no initialization of any kind, then we don't | |
453 | -- need to place any restrictions on the address clause, because | |
454 | -- the object will be elaborated after the address clause is | |
455 | -- evaluated. This happens if the declaration has no initial | |
456 | -- expression, or the type has no implicit initialization, or | |
457 | -- the object is imported. | |
458 | ||
459 | -- The same holds for all initialized scalar types and all | |
460 | -- access types. Packed bit arrays of size up to 64 are | |
461 | -- represented using a modular type with an initialization | |
462 | -- (to zero) and can be processed like other initialized | |
463 | -- scalar types. | |
464 | ||
465 | -- If the type is controlled, code to attach the object to a | |
466 | -- finalization chain is generated at the point of declaration, | |
467 | -- and therefore the elaboration of the object cannot be delayed: | |
468 | -- the address expression must be a constant. | |
469 | ||
470 | if (No (Expression (Decl)) | |
471 | and then not Controlled_Type (Typ) | |
472 | and then | |
473 | (not Has_Non_Null_Base_Init_Proc (Typ) | |
474 | or else Is_Imported (E))) | |
475 | ||
476 | or else | |
477 | (Present (Expression (Decl)) | |
478 | and then Is_Scalar_Type (Typ)) | |
479 | ||
480 | or else | |
481 | Is_Access_Type (Typ) | |
482 | ||
483 | or else | |
484 | (Is_Bit_Packed_Array (Typ) | |
485 | and then | |
486 | Is_Modular_Integer_Type (Packed_Array_Type (Typ))) | |
487 | then | |
488 | null; | |
489 | ||
490 | -- Otherwise, we require the address clause to be constant | |
491 | -- because the call to the initialization procedure (or the | |
492 | -- attach code) has to happen at the point of the declaration. | |
493 | ||
494 | else | |
495 | Check_Constant_Address_Clause (Expr, E); | |
496 | Set_Has_Delayed_Freeze (E, False); | |
497 | end if; | |
498 | ||
499 | if not Error_Posted (Expr) | |
500 | and then not Controlled_Type (Typ) | |
501 | then | |
502 | Warn_Overlay (Expr, Typ, Name (Addr)); | |
503 | end if; | |
504 | end if; | |
505 | end Check_Address_Clause; | |
506 | ||
70482933 RK |
507 | ----------------------------- |
508 | -- Check_Compile_Time_Size -- | |
509 | ----------------------------- | |
510 | ||
511 | procedure Check_Compile_Time_Size (T : Entity_Id) is | |
512 | ||
c6823a20 | 513 | procedure Set_Small_Size (T : Entity_Id; S : Uint); |
70482933 | 514 | -- Sets the compile time known size (32 bits or less) in the Esize |
c6823a20 | 515 | -- field, of T checking for a size clause that was given which attempts |
70482933 RK |
516 | -- to give a smaller size. |
517 | ||
518 | function Size_Known (T : Entity_Id) return Boolean; | |
07fc65c4 | 519 | -- Recursive function that does all the work |
70482933 RK |
520 | |
521 | function Static_Discriminated_Components (T : Entity_Id) return Boolean; | |
522 | -- If T is a constrained subtype, its size is not known if any of its | |
523 | -- discriminant constraints is not static and it is not a null record. | |
fbf5a39b | 524 | -- The test is conservative and doesn't check that the components are |
70482933 RK |
525 | -- in fact constrained by non-static discriminant values. Could be made |
526 | -- more precise ??? | |
527 | ||
528 | -------------------- | |
529 | -- Set_Small_Size -- | |
530 | -------------------- | |
531 | ||
c6823a20 | 532 | procedure Set_Small_Size (T : Entity_Id; S : Uint) is |
70482933 RK |
533 | begin |
534 | if S > 32 then | |
535 | return; | |
536 | ||
537 | elsif Has_Size_Clause (T) then | |
538 | if RM_Size (T) < S then | |
539 | Error_Msg_Uint_1 := S; | |
540 | Error_Msg_NE | |
541 | ("size for & is too small, minimum is ^", | |
542 | Size_Clause (T), T); | |
543 | ||
544 | elsif Unknown_Esize (T) then | |
545 | Set_Esize (T, S); | |
546 | end if; | |
547 | ||
548 | -- Set sizes if not set already | |
549 | ||
550 | else | |
551 | if Unknown_Esize (T) then | |
552 | Set_Esize (T, S); | |
553 | end if; | |
554 | ||
555 | if Unknown_RM_Size (T) then | |
556 | Set_RM_Size (T, S); | |
557 | end if; | |
558 | end if; | |
559 | end Set_Small_Size; | |
560 | ||
561 | ---------------- | |
562 | -- Size_Known -- | |
563 | ---------------- | |
564 | ||
565 | function Size_Known (T : Entity_Id) return Boolean is | |
566 | Index : Entity_Id; | |
567 | Comp : Entity_Id; | |
568 | Ctyp : Entity_Id; | |
569 | Low : Node_Id; | |
570 | High : Node_Id; | |
571 | ||
572 | begin | |
573 | if Size_Known_At_Compile_Time (T) then | |
574 | return True; | |
575 | ||
70482933 RK |
576 | elsif Is_Scalar_Type (T) |
577 | or else Is_Task_Type (T) | |
578 | then | |
579 | return not Is_Generic_Type (T); | |
580 | ||
581 | elsif Is_Array_Type (T) then | |
70482933 | 582 | if Ekind (T) = E_String_Literal_Subtype then |
c6823a20 EB |
583 | Set_Small_Size (T, Component_Size (T) |
584 | * String_Literal_Length (T)); | |
70482933 RK |
585 | return True; |
586 | ||
587 | elsif not Is_Constrained (T) then | |
588 | return False; | |
589 | ||
07fc65c4 GB |
590 | -- Don't do any recursion on type with error posted, since |
591 | -- we may have a malformed type that leads us into a loop | |
592 | ||
593 | elsif Error_Posted (T) then | |
594 | return False; | |
595 | ||
70482933 RK |
596 | elsif not Size_Known (Component_Type (T)) then |
597 | return False; | |
598 | end if; | |
599 | ||
600 | -- Check for all indexes static, and also compute possible | |
601 | -- size (in case it is less than 32 and may be packable). | |
602 | ||
603 | declare | |
604 | Esiz : Uint := Component_Size (T); | |
605 | Dim : Uint; | |
606 | ||
607 | begin | |
608 | Index := First_Index (T); | |
70482933 RK |
609 | while Present (Index) loop |
610 | if Nkind (Index) = N_Range then | |
611 | Get_Index_Bounds (Index, Low, High); | |
612 | ||
613 | elsif Error_Posted (Scalar_Range (Etype (Index))) then | |
614 | return False; | |
615 | ||
616 | else | |
617 | Low := Type_Low_Bound (Etype (Index)); | |
618 | High := Type_High_Bound (Etype (Index)); | |
619 | end if; | |
620 | ||
621 | if not Compile_Time_Known_Value (Low) | |
622 | or else not Compile_Time_Known_Value (High) | |
623 | or else Etype (Index) = Any_Type | |
624 | then | |
625 | return False; | |
626 | ||
627 | else | |
628 | Dim := Expr_Value (High) - Expr_Value (Low) + 1; | |
629 | ||
630 | if Dim >= 0 then | |
631 | Esiz := Esiz * Dim; | |
632 | else | |
633 | Esiz := Uint_0; | |
634 | end if; | |
635 | end if; | |
636 | ||
637 | Next_Index (Index); | |
638 | end loop; | |
639 | ||
c6823a20 | 640 | Set_Small_Size (T, Esiz); |
70482933 RK |
641 | return True; |
642 | end; | |
643 | ||
644 | elsif Is_Access_Type (T) then | |
645 | return True; | |
646 | ||
647 | elsif Is_Private_Type (T) | |
648 | and then not Is_Generic_Type (T) | |
649 | and then Present (Underlying_Type (T)) | |
650 | then | |
07fc65c4 GB |
651 | -- Don't do any recursion on type with error posted, since |
652 | -- we may have a malformed type that leads us into a loop | |
653 | ||
654 | if Error_Posted (T) then | |
655 | return False; | |
656 | else | |
657 | return Size_Known (Underlying_Type (T)); | |
658 | end if; | |
70482933 RK |
659 | |
660 | elsif Is_Record_Type (T) then | |
fbf5a39b AC |
661 | |
662 | -- A class-wide type is never considered to have a known size | |
663 | ||
70482933 RK |
664 | if Is_Class_Wide_Type (T) then |
665 | return False; | |
666 | ||
fbf5a39b AC |
667 | -- A subtype of a variant record must not have non-static |
668 | -- discriminanted components. | |
669 | ||
670 | elsif T /= Base_Type (T) | |
671 | and then not Static_Discriminated_Components (T) | |
672 | then | |
673 | return False; | |
70482933 | 674 | |
07fc65c4 GB |
675 | -- Don't do any recursion on type with error posted, since |
676 | -- we may have a malformed type that leads us into a loop | |
677 | ||
678 | elsif Error_Posted (T) then | |
679 | return False; | |
fbf5a39b | 680 | end if; |
07fc65c4 | 681 | |
fbf5a39b | 682 | -- Now look at the components of the record |
70482933 | 683 | |
fbf5a39b AC |
684 | declare |
685 | -- The following two variables are used to keep track of | |
686 | -- the size of packed records if we can tell the size of | |
687 | -- the packed record in the front end. Packed_Size_Known | |
688 | -- is True if so far we can figure out the size. It is | |
689 | -- initialized to True for a packed record, unless the | |
690 | -- record has discriminants. The reason we eliminate the | |
691 | -- discriminated case is that we don't know the way the | |
692 | -- back end lays out discriminated packed records. If | |
693 | -- Packed_Size_Known is True, then Packed_Size is the | |
694 | -- size in bits so far. | |
695 | ||
696 | Packed_Size_Known : Boolean := | |
697 | Is_Packed (T) | |
698 | and then not Has_Discriminants (T); | |
699 | ||
700 | Packed_Size : Uint := Uint_0; | |
701 | ||
702 | begin | |
703 | -- Test for variant part present | |
704 | ||
705 | if Has_Discriminants (T) | |
706 | and then Present (Parent (T)) | |
707 | and then Nkind (Parent (T)) = N_Full_Type_Declaration | |
708 | and then Nkind (Type_Definition (Parent (T))) = | |
709 | N_Record_Definition | |
710 | and then not Null_Present (Type_Definition (Parent (T))) | |
711 | and then Present (Variant_Part | |
712 | (Component_List (Type_Definition (Parent (T))))) | |
713 | then | |
714 | -- If variant part is present, and type is unconstrained, | |
715 | -- then we must have defaulted discriminants, or a size | |
716 | -- clause must be present for the type, or else the size | |
717 | -- is definitely not known at compile time. | |
718 | ||
719 | if not Is_Constrained (T) | |
720 | and then | |
721 | No (Discriminant_Default_Value | |
722 | (First_Discriminant (T))) | |
723 | and then Unknown_Esize (T) | |
70482933 | 724 | then |
fbf5a39b AC |
725 | return False; |
726 | end if; | |
727 | end if; | |
70482933 | 728 | |
fbf5a39b AC |
729 | -- Loop through components |
730 | ||
731 | Comp := First_Entity (T); | |
732 | while Present (Comp) loop | |
733 | if Ekind (Comp) = E_Component | |
734 | or else | |
735 | Ekind (Comp) = E_Discriminant | |
736 | then | |
737 | Ctyp := Etype (Comp); | |
738 | ||
739 | -- We do not know the packed size if there is a | |
740 | -- component clause present (we possibly could, | |
741 | -- but this would only help in the case of a record | |
742 | -- with partial rep clauses. That's because in the | |
743 | -- case of full rep clauses, the size gets figured | |
744 | -- out anyway by a different circuit). | |
745 | ||
746 | if Present (Component_Clause (Comp)) then | |
70482933 RK |
747 | Packed_Size_Known := False; |
748 | end if; | |
70482933 | 749 | |
fbf5a39b AC |
750 | -- We need to identify a component that is an array |
751 | -- where the index type is an enumeration type with | |
752 | -- non-standard representation, and some bound of the | |
753 | -- type depends on a discriminant. | |
754 | ||
755 | -- This is because gigi computes the size by doing a | |
756 | -- substituation of the appropriate discriminant value | |
757 | -- in the size expression for the base type, and gigi | |
758 | -- is not clever enough to evaluate the resulting | |
759 | -- expression (which involves a call to rep_to_pos) | |
760 | -- at compile time. | |
761 | ||
762 | -- It would be nice if gigi would either recognize that | |
763 | -- this expression can be computed at compile time, or | |
764 | -- alternatively figured out the size from the subtype | |
765 | -- directly, where all the information is at hand ??? | |
766 | ||
767 | if Is_Array_Type (Etype (Comp)) | |
768 | and then Present (Packed_Array_Type (Etype (Comp))) | |
70482933 | 769 | then |
fbf5a39b AC |
770 | declare |
771 | Ocomp : constant Entity_Id := | |
772 | Original_Record_Component (Comp); | |
773 | OCtyp : constant Entity_Id := Etype (Ocomp); | |
774 | Ind : Node_Id; | |
775 | Indtyp : Entity_Id; | |
776 | Lo, Hi : Node_Id; | |
70482933 | 777 | |
fbf5a39b AC |
778 | begin |
779 | Ind := First_Index (OCtyp); | |
780 | while Present (Ind) loop | |
781 | Indtyp := Etype (Ind); | |
782 | ||
783 | if Is_Enumeration_Type (Indtyp) | |
784 | and then Has_Non_Standard_Rep (Indtyp) | |
785 | then | |
786 | Lo := Type_Low_Bound (Indtyp); | |
787 | Hi := Type_High_Bound (Indtyp); | |
788 | ||
789 | if Is_Entity_Name (Lo) | |
790 | and then | |
791 | Ekind (Entity (Lo)) = E_Discriminant | |
792 | then | |
793 | return False; | |
794 | ||
795 | elsif Is_Entity_Name (Hi) | |
796 | and then | |
797 | Ekind (Entity (Hi)) = E_Discriminant | |
798 | then | |
799 | return False; | |
800 | end if; | |
801 | end if; | |
802 | ||
803 | Next_Index (Ind); | |
804 | end loop; | |
805 | end; | |
806 | end if; | |
70482933 | 807 | |
fbf5a39b AC |
808 | -- Clearly size of record is not known if the size of |
809 | -- one of the components is not known. | |
70482933 | 810 | |
fbf5a39b AC |
811 | if not Size_Known (Ctyp) then |
812 | return False; | |
813 | end if; | |
814 | ||
815 | -- Accumulate packed size if possible | |
816 | ||
817 | if Packed_Size_Known then | |
818 | ||
819 | -- We can only deal with elementary types, since for | |
820 | -- non-elementary components, alignment enters into | |
821 | -- the picture, and we don't know enough to handle | |
822 | -- proper alignment in this context. Packed arrays | |
823 | -- count as elementary if the representation is a | |
824 | -- modular type. | |
70482933 | 825 | |
fbf5a39b AC |
826 | if Is_Elementary_Type (Ctyp) |
827 | or else (Is_Array_Type (Ctyp) | |
828 | and then | |
829 | Present (Packed_Array_Type (Ctyp)) | |
830 | and then | |
831 | Is_Modular_Integer_Type | |
832 | (Packed_Array_Type (Ctyp))) | |
833 | then | |
70482933 RK |
834 | -- If RM_Size is known and static, then we can |
835 | -- keep accumulating the packed size. | |
836 | ||
837 | if Known_Static_RM_Size (Ctyp) then | |
838 | ||
839 | -- A little glitch, to be removed sometime ??? | |
840 | -- gigi does not understand zero sizes yet. | |
841 | ||
842 | if RM_Size (Ctyp) = Uint_0 then | |
843 | Packed_Size_Known := False; | |
70482933 | 844 | |
fbf5a39b AC |
845 | -- Normal case where we can keep accumulating |
846 | -- the packed array size. | |
847 | ||
848 | else | |
849 | Packed_Size := Packed_Size + RM_Size (Ctyp); | |
850 | end if; | |
70482933 RK |
851 | |
852 | -- If we have a field whose RM_Size is not known | |
853 | -- then we can't figure out the packed size here. | |
854 | ||
855 | else | |
856 | Packed_Size_Known := False; | |
857 | end if; | |
fbf5a39b AC |
858 | |
859 | -- If we have a non-elementary type we can't figure | |
860 | -- out the packed array size (alignment issues). | |
861 | ||
862 | else | |
863 | Packed_Size_Known := False; | |
70482933 RK |
864 | end if; |
865 | end if; | |
fbf5a39b | 866 | end if; |
70482933 | 867 | |
fbf5a39b AC |
868 | Next_Entity (Comp); |
869 | end loop; | |
70482933 | 870 | |
fbf5a39b | 871 | if Packed_Size_Known then |
c6823a20 | 872 | Set_Small_Size (T, Packed_Size); |
fbf5a39b | 873 | end if; |
70482933 | 874 | |
fbf5a39b AC |
875 | return True; |
876 | end; | |
70482933 RK |
877 | |
878 | else | |
879 | return False; | |
880 | end if; | |
881 | end Size_Known; | |
882 | ||
883 | ------------------------------------- | |
884 | -- Static_Discriminated_Components -- | |
885 | ------------------------------------- | |
886 | ||
887 | function Static_Discriminated_Components | |
0da2c8ac | 888 | (T : Entity_Id) return Boolean |
70482933 RK |
889 | is |
890 | Constraint : Elmt_Id; | |
891 | ||
892 | begin | |
893 | if Has_Discriminants (T) | |
894 | and then Present (Discriminant_Constraint (T)) | |
895 | and then Present (First_Component (T)) | |
896 | then | |
897 | Constraint := First_Elmt (Discriminant_Constraint (T)); | |
70482933 RK |
898 | while Present (Constraint) loop |
899 | if not Compile_Time_Known_Value (Node (Constraint)) then | |
900 | return False; | |
901 | end if; | |
902 | ||
903 | Next_Elmt (Constraint); | |
904 | end loop; | |
905 | end if; | |
906 | ||
907 | return True; | |
908 | end Static_Discriminated_Components; | |
909 | ||
910 | -- Start of processing for Check_Compile_Time_Size | |
911 | ||
912 | begin | |
913 | Set_Size_Known_At_Compile_Time (T, Size_Known (T)); | |
914 | end Check_Compile_Time_Size; | |
915 | ||
916 | ----------------------------- | |
917 | -- Check_Debug_Info_Needed -- | |
918 | ----------------------------- | |
919 | ||
920 | procedure Check_Debug_Info_Needed (T : Entity_Id) is | |
921 | begin | |
922 | if Needs_Debug_Info (T) or else Debug_Info_Off (T) then | |
923 | return; | |
924 | ||
925 | elsif Comes_From_Source (T) | |
926 | or else Debug_Generated_Code | |
927 | or else Debug_Flag_VV | |
928 | then | |
929 | Set_Debug_Info_Needed (T); | |
930 | end if; | |
931 | end Check_Debug_Info_Needed; | |
932 | ||
933 | ---------------------------- | |
934 | -- Check_Strict_Alignment -- | |
935 | ---------------------------- | |
936 | ||
937 | procedure Check_Strict_Alignment (E : Entity_Id) is | |
938 | Comp : Entity_Id; | |
939 | ||
940 | begin | |
941 | if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then | |
942 | Set_Strict_Alignment (E); | |
943 | ||
944 | elsif Is_Array_Type (E) then | |
945 | Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E))); | |
946 | ||
947 | elsif Is_Record_Type (E) then | |
948 | if Is_Limited_Record (E) then | |
949 | Set_Strict_Alignment (E); | |
950 | return; | |
951 | end if; | |
952 | ||
953 | Comp := First_Component (E); | |
954 | ||
955 | while Present (Comp) loop | |
956 | if not Is_Type (Comp) | |
957 | and then (Strict_Alignment (Etype (Comp)) | |
fbf5a39b | 958 | or else Is_Aliased (Comp)) |
70482933 RK |
959 | then |
960 | Set_Strict_Alignment (E); | |
961 | return; | |
962 | end if; | |
963 | ||
964 | Next_Component (Comp); | |
965 | end loop; | |
966 | end if; | |
967 | end Check_Strict_Alignment; | |
968 | ||
969 | ------------------------- | |
970 | -- Check_Unsigned_Type -- | |
971 | ------------------------- | |
972 | ||
973 | procedure Check_Unsigned_Type (E : Entity_Id) is | |
974 | Ancestor : Entity_Id; | |
975 | Lo_Bound : Node_Id; | |
976 | Btyp : Entity_Id; | |
977 | ||
978 | begin | |
979 | if not Is_Discrete_Or_Fixed_Point_Type (E) then | |
980 | return; | |
981 | end if; | |
982 | ||
983 | -- Do not attempt to analyze case where range was in error | |
984 | ||
985 | if Error_Posted (Scalar_Range (E)) then | |
986 | return; | |
987 | end if; | |
988 | ||
989 | -- The situation that is non trivial is something like | |
990 | ||
991 | -- subtype x1 is integer range -10 .. +10; | |
992 | -- subtype x2 is x1 range 0 .. V1; | |
993 | -- subtype x3 is x2 range V2 .. V3; | |
994 | -- subtype x4 is x3 range V4 .. V5; | |
995 | ||
996 | -- where Vn are variables. Here the base type is signed, but we still | |
997 | -- know that x4 is unsigned because of the lower bound of x2. | |
998 | ||
999 | -- The only way to deal with this is to look up the ancestor chain | |
1000 | ||
1001 | Ancestor := E; | |
1002 | loop | |
1003 | if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then | |
1004 | return; | |
1005 | end if; | |
1006 | ||
1007 | Lo_Bound := Type_Low_Bound (Ancestor); | |
1008 | ||
1009 | if Compile_Time_Known_Value (Lo_Bound) then | |
1010 | ||
1011 | if Expr_Rep_Value (Lo_Bound) >= 0 then | |
1012 | Set_Is_Unsigned_Type (E, True); | |
1013 | end if; | |
1014 | ||
1015 | return; | |
1016 | ||
1017 | else | |
1018 | Ancestor := Ancestor_Subtype (Ancestor); | |
1019 | ||
1020 | -- If no ancestor had a static lower bound, go to base type | |
1021 | ||
1022 | if No (Ancestor) then | |
1023 | ||
1024 | -- Note: the reason we still check for a compile time known | |
1025 | -- value for the base type is that at least in the case of | |
1026 | -- generic formals, we can have bounds that fail this test, | |
1027 | -- and there may be other cases in error situations. | |
1028 | ||
1029 | Btyp := Base_Type (E); | |
1030 | ||
1031 | if Btyp = Any_Type or else Etype (Btyp) = Any_Type then | |
1032 | return; | |
1033 | end if; | |
1034 | ||
1035 | Lo_Bound := Type_Low_Bound (Base_Type (E)); | |
1036 | ||
1037 | if Compile_Time_Known_Value (Lo_Bound) | |
1038 | and then Expr_Rep_Value (Lo_Bound) >= 0 | |
1039 | then | |
1040 | Set_Is_Unsigned_Type (E, True); | |
1041 | end if; | |
1042 | ||
1043 | return; | |
70482933 RK |
1044 | end if; |
1045 | end if; | |
1046 | end loop; | |
1047 | end Check_Unsigned_Type; | |
1048 | ||
fbf5a39b AC |
1049 | ----------------------------- |
1050 | -- Expand_Atomic_Aggregate -- | |
1051 | ----------------------------- | |
1052 | ||
1053 | procedure Expand_Atomic_Aggregate (E : Entity_Id; Typ : Entity_Id) is | |
1054 | Loc : constant Source_Ptr := Sloc (E); | |
1055 | New_N : Node_Id; | |
1056 | Temp : Entity_Id; | |
1057 | ||
1058 | begin | |
1059 | if (Nkind (Parent (E)) = N_Object_Declaration | |
1060 | or else Nkind (Parent (E)) = N_Assignment_Statement) | |
1061 | and then Comes_From_Source (Parent (E)) | |
1062 | and then Nkind (E) = N_Aggregate | |
1063 | then | |
1064 | Temp := | |
1065 | Make_Defining_Identifier (Loc, | |
1066 | New_Internal_Name ('T')); | |
1067 | ||
1068 | New_N := | |
1069 | Make_Object_Declaration (Loc, | |
1070 | Defining_Identifier => Temp, | |
1071 | Object_definition => New_Occurrence_Of (Typ, Loc), | |
1072 | Expression => Relocate_Node (E)); | |
1073 | Insert_Before (Parent (E), New_N); | |
1074 | Analyze (New_N); | |
1075 | ||
1076 | Set_Expression (Parent (E), New_Occurrence_Of (Temp, Loc)); | |
1077 | ||
1078 | -- To prevent the temporary from being constant-folded (which | |
1079 | -- would lead to the same piecemeal assignment on the original | |
1080 | -- target) indicate to the back-end that the temporary is a | |
1081 | -- variable with real storage. See description of this flag | |
1082 | -- in Einfo, and the notes on N_Assignment_Statement and | |
1083 | -- N_Object_Declaration in Sinfo. | |
1084 | ||
1085 | Set_Is_True_Constant (Temp, False); | |
1086 | end if; | |
1087 | end Expand_Atomic_Aggregate; | |
1088 | ||
70482933 RK |
1089 | ---------------- |
1090 | -- Freeze_All -- | |
1091 | ---------------- | |
1092 | ||
1093 | -- Note: the easy coding for this procedure would be to just build a | |
1094 | -- single list of freeze nodes and then insert them and analyze them | |
1095 | -- all at once. This won't work, because the analysis of earlier freeze | |
1096 | -- nodes may recursively freeze types which would otherwise appear later | |
1097 | -- on in the freeze list. So we must analyze and expand the freeze nodes | |
1098 | -- as they are generated. | |
1099 | ||
1100 | procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is | |
1101 | Loc : constant Source_Ptr := Sloc (After); | |
1102 | E : Entity_Id; | |
1103 | Decl : Node_Id; | |
1104 | ||
1105 | procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id); | |
1106 | -- This is the internal recursive routine that does freezing of | |
1107 | -- entities (but NOT the analysis of default expressions, which | |
1108 | -- should not be recursive, we don't want to analyze those till | |
1109 | -- we are sure that ALL the types are frozen). | |
1110 | ||
fbf5a39b AC |
1111 | -------------------- |
1112 | -- Freeze_All_Ent -- | |
1113 | -------------------- | |
1114 | ||
70482933 RK |
1115 | procedure Freeze_All_Ent |
1116 | (From : Entity_Id; | |
1117 | After : in out Node_Id) | |
1118 | is | |
1119 | E : Entity_Id; | |
1120 | Flist : List_Id; | |
1121 | Lastn : Node_Id; | |
1122 | ||
1123 | procedure Process_Flist; | |
1124 | -- If freeze nodes are present, insert and analyze, and reset | |
1125 | -- cursor for next insertion. | |
1126 | ||
fbf5a39b AC |
1127 | ------------------- |
1128 | -- Process_Flist -- | |
1129 | ------------------- | |
1130 | ||
70482933 RK |
1131 | procedure Process_Flist is |
1132 | begin | |
1133 | if Is_Non_Empty_List (Flist) then | |
1134 | Lastn := Next (After); | |
1135 | Insert_List_After_And_Analyze (After, Flist); | |
1136 | ||
1137 | if Present (Lastn) then | |
1138 | After := Prev (Lastn); | |
1139 | else | |
1140 | After := Last (List_Containing (After)); | |
1141 | end if; | |
1142 | end if; | |
1143 | end Process_Flist; | |
1144 | ||
fbf5a39b AC |
1145 | -- Start or processing for Freeze_All_Ent |
1146 | ||
70482933 RK |
1147 | begin |
1148 | E := From; | |
1149 | while Present (E) loop | |
1150 | ||
1151 | -- If the entity is an inner package which is not a package | |
1152 | -- renaming, then its entities must be frozen at this point. | |
1153 | -- Note that such entities do NOT get frozen at the end of | |
1154 | -- the nested package itself (only library packages freeze). | |
1155 | ||
1156 | -- Same is true for task declarations, where anonymous records | |
1157 | -- created for entry parameters must be frozen. | |
1158 | ||
1159 | if Ekind (E) = E_Package | |
1160 | and then No (Renamed_Object (E)) | |
1161 | and then not Is_Child_Unit (E) | |
1162 | and then not Is_Frozen (E) | |
1163 | then | |
1164 | New_Scope (E); | |
1165 | Install_Visible_Declarations (E); | |
1166 | Install_Private_Declarations (E); | |
1167 | ||
1168 | Freeze_All (First_Entity (E), After); | |
1169 | ||
1170 | End_Package_Scope (E); | |
1171 | ||
1172 | elsif Ekind (E) in Task_Kind | |
1173 | and then | |
1174 | (Nkind (Parent (E)) = N_Task_Type_Declaration | |
fbf5a39b | 1175 | or else |
70482933 RK |
1176 | Nkind (Parent (E)) = N_Single_Task_Declaration) |
1177 | then | |
1178 | New_Scope (E); | |
1179 | Freeze_All (First_Entity (E), After); | |
1180 | End_Scope; | |
1181 | ||
1182 | -- For a derived tagged type, we must ensure that all the | |
1183 | -- primitive operations of the parent have been frozen, so | |
1184 | -- that their addresses will be in the parent's dispatch table | |
1185 | -- at the point it is inherited. | |
1186 | ||
1187 | elsif Ekind (E) = E_Record_Type | |
1188 | and then Is_Tagged_Type (E) | |
1189 | and then Is_Tagged_Type (Etype (E)) | |
1190 | and then Is_Derived_Type (E) | |
1191 | then | |
1192 | declare | |
1193 | Prim_List : constant Elist_Id := | |
1194 | Primitive_Operations (Etype (E)); | |
fbf5a39b AC |
1195 | |
1196 | Prim : Elmt_Id; | |
1197 | Subp : Entity_Id; | |
70482933 RK |
1198 | |
1199 | begin | |
1200 | Prim := First_Elmt (Prim_List); | |
1201 | ||
1202 | while Present (Prim) loop | |
1203 | Subp := Node (Prim); | |
1204 | ||
1205 | if Comes_From_Source (Subp) | |
1206 | and then not Is_Frozen (Subp) | |
1207 | then | |
1208 | Flist := Freeze_Entity (Subp, Loc); | |
1209 | Process_Flist; | |
1210 | end if; | |
1211 | ||
1212 | Next_Elmt (Prim); | |
1213 | end loop; | |
1214 | end; | |
1215 | end if; | |
1216 | ||
1217 | if not Is_Frozen (E) then | |
1218 | Flist := Freeze_Entity (E, Loc); | |
1219 | Process_Flist; | |
1220 | end if; | |
1221 | ||
fbf5a39b AC |
1222 | -- If an incomplete type is still not frozen, this may be |
1223 | -- a premature freezing because of a body declaration that | |
1224 | -- follows. Indicate where the freezing took place. | |
1225 | ||
1226 | -- If the freezing is caused by the end of the current | |
1227 | -- declarative part, it is a Taft Amendment type, and there | |
1228 | -- is no error. | |
1229 | ||
1230 | if not Is_Frozen (E) | |
1231 | and then Ekind (E) = E_Incomplete_Type | |
1232 | then | |
1233 | declare | |
1234 | Bod : constant Node_Id := Next (After); | |
1235 | ||
1236 | begin | |
1237 | if (Nkind (Bod) = N_Subprogram_Body | |
1238 | or else Nkind (Bod) = N_Entry_Body | |
1239 | or else Nkind (Bod) = N_Package_Body | |
1240 | or else Nkind (Bod) = N_Protected_Body | |
1241 | or else Nkind (Bod) = N_Task_Body | |
1242 | or else Nkind (Bod) in N_Body_Stub) | |
1243 | and then | |
1244 | List_Containing (After) = List_Containing (Parent (E)) | |
1245 | then | |
1246 | Error_Msg_Sloc := Sloc (Next (After)); | |
1247 | Error_Msg_NE | |
1248 | ("type& is frozen# before its full declaration", | |
1249 | Parent (E), E); | |
1250 | end if; | |
1251 | end; | |
1252 | end if; | |
1253 | ||
70482933 RK |
1254 | Next_Entity (E); |
1255 | end loop; | |
1256 | end Freeze_All_Ent; | |
1257 | ||
1258 | -- Start of processing for Freeze_All | |
1259 | ||
1260 | begin | |
1261 | Freeze_All_Ent (From, After); | |
1262 | ||
1263 | -- Now that all types are frozen, we can deal with default expressions | |
1264 | -- that require us to build a default expression functions. This is the | |
1265 | -- point at which such functions are constructed (after all types that | |
1266 | -- might be used in such expressions have been frozen). | |
fbf5a39b | 1267 | |
70482933 RK |
1268 | -- We also add finalization chains to access types whose designated |
1269 | -- types are controlled. This is normally done when freezing the type, | |
1270 | -- but this misses recursive type definitions where the later members | |
1271 | -- of the recursion introduce controlled components (e.g. 5624-001). | |
1272 | ||
1273 | -- Loop through entities | |
1274 | ||
1275 | E := From; | |
1276 | while Present (E) loop | |
70482933 RK |
1277 | if Is_Subprogram (E) then |
1278 | ||
1279 | if not Default_Expressions_Processed (E) then | |
1280 | Process_Default_Expressions (E, After); | |
1281 | end if; | |
1282 | ||
1283 | if not Has_Completion (E) then | |
1284 | Decl := Unit_Declaration_Node (E); | |
1285 | ||
1286 | if Nkind (Decl) = N_Subprogram_Renaming_Declaration then | |
1287 | Build_And_Analyze_Renamed_Body (Decl, E, After); | |
1288 | ||
1289 | elsif Nkind (Decl) = N_Subprogram_Declaration | |
1290 | and then Present (Corresponding_Body (Decl)) | |
1291 | and then | |
1292 | Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) | |
fbf5a39b | 1293 | = N_Subprogram_Renaming_Declaration |
70482933 RK |
1294 | then |
1295 | Build_And_Analyze_Renamed_Body | |
1296 | (Decl, Corresponding_Body (Decl), After); | |
1297 | end if; | |
1298 | end if; | |
1299 | ||
1300 | elsif Ekind (E) in Task_Kind | |
1301 | and then | |
1302 | (Nkind (Parent (E)) = N_Task_Type_Declaration | |
fbf5a39b | 1303 | or else |
70482933 RK |
1304 | Nkind (Parent (E)) = N_Single_Task_Declaration) |
1305 | then | |
1306 | declare | |
1307 | Ent : Entity_Id; | |
70482933 RK |
1308 | begin |
1309 | Ent := First_Entity (E); | |
1310 | ||
1311 | while Present (Ent) loop | |
1312 | ||
1313 | if Is_Entry (Ent) | |
1314 | and then not Default_Expressions_Processed (Ent) | |
1315 | then | |
1316 | Process_Default_Expressions (Ent, After); | |
1317 | end if; | |
1318 | ||
1319 | Next_Entity (Ent); | |
1320 | end loop; | |
1321 | end; | |
1322 | ||
1323 | elsif Is_Access_Type (E) | |
1324 | and then Comes_From_Source (E) | |
1325 | and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type | |
1326 | and then Controlled_Type (Designated_Type (E)) | |
1327 | and then No (Associated_Final_Chain (E)) | |
1328 | then | |
1329 | Build_Final_List (Parent (E), E); | |
1330 | end if; | |
1331 | ||
1332 | Next_Entity (E); | |
1333 | end loop; | |
70482933 RK |
1334 | end Freeze_All; |
1335 | ||
1336 | ----------------------- | |
1337 | -- Freeze_And_Append -- | |
1338 | ----------------------- | |
1339 | ||
1340 | procedure Freeze_And_Append | |
1341 | (Ent : Entity_Id; | |
1342 | Loc : Source_Ptr; | |
1343 | Result : in out List_Id) | |
1344 | is | |
1345 | L : constant List_Id := Freeze_Entity (Ent, Loc); | |
70482933 RK |
1346 | begin |
1347 | if Is_Non_Empty_List (L) then | |
1348 | if Result = No_List then | |
1349 | Result := L; | |
1350 | else | |
1351 | Append_List (L, Result); | |
1352 | end if; | |
1353 | end if; | |
1354 | end Freeze_And_Append; | |
1355 | ||
1356 | ------------------- | |
1357 | -- Freeze_Before -- | |
1358 | ------------------- | |
1359 | ||
1360 | procedure Freeze_Before (N : Node_Id; T : Entity_Id) is | |
1361 | Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N)); | |
70482933 RK |
1362 | begin |
1363 | if Is_Non_Empty_List (Freeze_Nodes) then | |
fbf5a39b | 1364 | Insert_Actions (N, Freeze_Nodes); |
70482933 RK |
1365 | end if; |
1366 | end Freeze_Before; | |
1367 | ||
1368 | ------------------- | |
1369 | -- Freeze_Entity -- | |
1370 | ------------------- | |
1371 | ||
1372 | function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is | |
c6823a20 | 1373 | Test_E : Entity_Id := E; |
70482933 RK |
1374 | Comp : Entity_Id; |
1375 | F_Node : Node_Id; | |
1376 | Result : List_Id; | |
1377 | Indx : Node_Id; | |
1378 | Formal : Entity_Id; | |
1379 | Atype : Entity_Id; | |
1380 | ||
1381 | procedure Check_Current_Instance (Comp_Decl : Node_Id); | |
edd63e9b ES |
1382 | -- Check that an Access or Unchecked_Access attribute with a prefix |
1383 | -- which is the current instance type can only be applied when the type | |
1384 | -- is limited. | |
70482933 RK |
1385 | |
1386 | function After_Last_Declaration return Boolean; | |
1387 | -- If Loc is a freeze_entity that appears after the last declaration | |
1388 | -- in the scope, inhibit error messages on late completion. | |
1389 | ||
1390 | procedure Freeze_Record_Type (Rec : Entity_Id); | |
edd63e9b ES |
1391 | -- Freeze each component, handle some representation clauses, and freeze |
1392 | -- primitive operations if this is a tagged type. | |
70482933 RK |
1393 | |
1394 | ---------------------------- | |
1395 | -- After_Last_Declaration -- | |
1396 | ---------------------------- | |
1397 | ||
1398 | function After_Last_Declaration return Boolean is | |
fbf5a39b | 1399 | Spec : constant Node_Id := Parent (Current_Scope); |
70482933 RK |
1400 | |
1401 | begin | |
1402 | if Nkind (Spec) = N_Package_Specification then | |
1403 | if Present (Private_Declarations (Spec)) then | |
1404 | return Loc >= Sloc (Last (Private_Declarations (Spec))); | |
1405 | ||
1406 | elsif Present (Visible_Declarations (Spec)) then | |
1407 | return Loc >= Sloc (Last (Visible_Declarations (Spec))); | |
1408 | else | |
1409 | return False; | |
1410 | end if; | |
1411 | ||
1412 | else | |
1413 | return False; | |
1414 | end if; | |
1415 | end After_Last_Declaration; | |
1416 | ||
1417 | ---------------------------- | |
1418 | -- Check_Current_Instance -- | |
1419 | ---------------------------- | |
1420 | ||
1421 | procedure Check_Current_Instance (Comp_Decl : Node_Id) is | |
1422 | ||
1423 | function Process (N : Node_Id) return Traverse_Result; | |
49e90211 | 1424 | -- Process routine to apply check to given node |
70482933 | 1425 | |
fbf5a39b AC |
1426 | ------------- |
1427 | -- Process -- | |
1428 | ------------- | |
1429 | ||
70482933 RK |
1430 | function Process (N : Node_Id) return Traverse_Result is |
1431 | begin | |
1432 | case Nkind (N) is | |
1433 | when N_Attribute_Reference => | |
1434 | if (Attribute_Name (N) = Name_Access | |
1435 | or else | |
1436 | Attribute_Name (N) = Name_Unchecked_Access) | |
1437 | and then Is_Entity_Name (Prefix (N)) | |
1438 | and then Is_Type (Entity (Prefix (N))) | |
1439 | and then Entity (Prefix (N)) = E | |
1440 | then | |
1441 | Error_Msg_N | |
1442 | ("current instance must be a limited type", Prefix (N)); | |
1443 | return Abandon; | |
1444 | else | |
1445 | return OK; | |
1446 | end if; | |
1447 | ||
1448 | when others => return OK; | |
1449 | end case; | |
1450 | end Process; | |
1451 | ||
1452 | procedure Traverse is new Traverse_Proc (Process); | |
1453 | ||
1454 | -- Start of processing for Check_Current_Instance | |
1455 | ||
1456 | begin | |
1457 | Traverse (Comp_Decl); | |
1458 | end Check_Current_Instance; | |
1459 | ||
1460 | ------------------------ | |
1461 | -- Freeze_Record_Type -- | |
1462 | ------------------------ | |
1463 | ||
1464 | procedure Freeze_Record_Type (Rec : Entity_Id) is | |
1465 | Comp : Entity_Id; | |
fbf5a39b | 1466 | IR : Node_Id; |
70482933 RK |
1467 | Junk : Boolean; |
1468 | ADC : Node_Id; | |
c6823a20 | 1469 | Prev : Entity_Id; |
70482933 RK |
1470 | |
1471 | Unplaced_Component : Boolean := False; | |
1472 | -- Set True if we find at least one component with no component | |
1473 | -- clause (used to warn about useless Pack pragmas). | |
1474 | ||
1475 | Placed_Component : Boolean := False; | |
1476 | -- Set True if we find at least one component with a component | |
1477 | -- clause (used to warn about useless Bit_Order pragmas). | |
1478 | ||
6e059adb AC |
1479 | procedure Check_Itype (Desig : Entity_Id); |
1480 | -- If the component subtype is an access to a constrained subtype | |
1481 | -- of an already frozen type, make the subtype frozen as well. It | |
1482 | -- might otherwise be frozen in the wrong scope, and a freeze node | |
1483 | -- on subtype has no effect. | |
1484 | ||
6871ba5f AC |
1485 | ----------------- |
1486 | -- Check_Itype -- | |
1487 | ----------------- | |
1488 | ||
6e059adb AC |
1489 | procedure Check_Itype (Desig : Entity_Id) is |
1490 | begin | |
1491 | if not Is_Frozen (Desig) | |
1492 | and then Is_Frozen (Base_Type (Desig)) | |
1493 | then | |
1494 | Set_Is_Frozen (Desig); | |
1495 | ||
1496 | -- In addition, add an Itype_Reference to ensure that the | |
1497 | -- access subtype is elaborated early enough. This cannot | |
1498 | -- be done if the subtype may depend on discriminants. | |
1499 | ||
1500 | if Ekind (Comp) = E_Component | |
1501 | and then Is_Itype (Etype (Comp)) | |
1502 | and then not Has_Discriminants (Rec) | |
1503 | then | |
1504 | IR := Make_Itype_Reference (Sloc (Comp)); | |
1505 | Set_Itype (IR, Desig); | |
1506 | ||
1507 | if No (Result) then | |
1508 | Result := New_List (IR); | |
1509 | else | |
1510 | Append (IR, Result); | |
1511 | end if; | |
1512 | end if; | |
1513 | end if; | |
1514 | end Check_Itype; | |
1515 | ||
1516 | -- Start of processing for Freeze_Record_Type | |
1517 | ||
70482933 | 1518 | begin |
fbf5a39b AC |
1519 | -- If this is a subtype of a controlled type, declared without |
1520 | -- a constraint, the _controller may not appear in the component | |
1521 | -- list if the parent was not frozen at the point of subtype | |
1522 | -- declaration. Inherit the _controller component now. | |
1523 | ||
1524 | if Rec /= Base_Type (Rec) | |
1525 | and then Has_Controlled_Component (Rec) | |
1526 | then | |
1527 | if Nkind (Parent (Rec)) = N_Subtype_Declaration | |
1528 | and then Is_Entity_Name (Subtype_Indication (Parent (Rec))) | |
1529 | then | |
1530 | Set_First_Entity (Rec, First_Entity (Base_Type (Rec))); | |
1531 | ||
49e90211 | 1532 | -- If this is an internal type without a declaration, as for |
6871ba5f AC |
1533 | -- record component, the base type may not yet be frozen, and its |
1534 | -- controller has not been created. Add an explicit freeze node | |
49e90211 ES |
1535 | -- for the itype, so it will be frozen after the base type. This |
1536 | -- freeze node is used to communicate with the expander, in order | |
1537 | -- to create the controller for the enclosing record, and it is | |
1538 | -- deleted afterwards (see exp_ch3). It must not be created when | |
1539 | -- expansion is off, because it might appear in the wrong context | |
1540 | -- for the back end. | |
fbf5a39b AC |
1541 | |
1542 | elsif Is_Itype (Rec) | |
1543 | and then Has_Delayed_Freeze (Base_Type (Rec)) | |
1544 | and then | |
1545 | Nkind (Associated_Node_For_Itype (Rec)) = | |
49e90211 ES |
1546 | N_Component_Declaration |
1547 | and then Expander_Active | |
fbf5a39b AC |
1548 | then |
1549 | Ensure_Freeze_Node (Rec); | |
1550 | end if; | |
1551 | end if; | |
1552 | ||
49e90211 | 1553 | -- Freeze components and embedded subtypes |
70482933 RK |
1554 | |
1555 | Comp := First_Entity (Rec); | |
c6823a20 | 1556 | Prev := Empty; |
70482933 | 1557 | |
c6823a20 | 1558 | while Present (Comp) loop |
70482933 | 1559 | |
49e90211 | 1560 | -- First handle the (real) component case |
70482933 RK |
1561 | |
1562 | if Ekind (Comp) = E_Component | |
1563 | or else Ekind (Comp) = E_Discriminant | |
1564 | then | |
70482933 RK |
1565 | declare |
1566 | CC : constant Node_Id := Component_Clause (Comp); | |
1567 | ||
1568 | begin | |
c6823a20 EB |
1569 | -- Freezing a record type freezes the type of each of its |
1570 | -- components. However, if the type of the component is | |
1571 | -- part of this record, we do not want or need a separate | |
1572 | -- Freeze_Node. Note that Is_Itype is wrong because that's | |
1573 | -- also set in private type cases. We also can't check for | |
1574 | -- the Scope being exactly Rec because of private types and | |
1575 | -- record extensions. | |
1576 | ||
1577 | if Is_Itype (Etype (Comp)) | |
1578 | and then Is_Record_Type (Underlying_Type | |
1579 | (Scope (Etype (Comp)))) | |
1580 | then | |
1581 | Undelay_Type (Etype (Comp)); | |
1582 | end if; | |
1583 | ||
1584 | Freeze_And_Append (Etype (Comp), Loc, Result); | |
1585 | ||
0da2c8ac AC |
1586 | -- Check for error of component clause given for variable |
1587 | -- sized type. We have to delay this test till this point, | |
1588 | -- since the component type has to be frozen for us to know | |
1589 | -- if it is variable length. We omit this test in a generic | |
1590 | -- context, it will be applied at instantiation time. | |
1591 | ||
70482933 RK |
1592 | if Present (CC) then |
1593 | Placed_Component := True; | |
1594 | ||
07fc65c4 GB |
1595 | if Inside_A_Generic then |
1596 | null; | |
1597 | ||
1598 | elsif not Size_Known_At_Compile_Time | |
70482933 | 1599 | (Underlying_Type (Etype (Comp))) |
70482933 RK |
1600 | then |
1601 | Error_Msg_N | |
1602 | ("component clause not allowed for variable " & | |
1603 | "length component", CC); | |
1604 | end if; | |
1605 | ||
1606 | else | |
1607 | Unplaced_Component := True; | |
1608 | end if; | |
70482933 | 1609 | |
0da2c8ac | 1610 | -- Case of component requires byte alignment |
70482933 | 1611 | |
0da2c8ac | 1612 | if Must_Be_On_Byte_Boundary (Etype (Comp)) then |
70482933 | 1613 | |
0da2c8ac | 1614 | -- Set the enclosing record to also require byte align |
70482933 | 1615 | |
0da2c8ac | 1616 | Set_Must_Be_On_Byte_Boundary (Rec); |
70482933 | 1617 | |
0da2c8ac AC |
1618 | -- Check for component clause that is inconsistent |
1619 | -- with the required byte boundary alignment. | |
70482933 | 1620 | |
0da2c8ac AC |
1621 | if Present (CC) |
1622 | and then Normalized_First_Bit (Comp) mod | |
1623 | System_Storage_Unit /= 0 | |
1624 | then | |
1625 | Error_Msg_N | |
1626 | ("component & must be byte aligned", | |
1627 | Component_Name (Component_Clause (Comp))); | |
1628 | end if; | |
1629 | end if; | |
70482933 | 1630 | |
0da2c8ac AC |
1631 | -- If component clause is present, then deal with the |
1632 | -- non-default bit order case. We cannot do this before | |
1633 | -- the freeze point, because there is no required order | |
1634 | -- for the component clause and the bit_order clause. | |
70482933 | 1635 | |
0da2c8ac AC |
1636 | -- We only do this processing for the base type, and in |
1637 | -- fact that's important, since otherwise if there are | |
1638 | -- record subtypes, we could reverse the bits once for | |
1639 | -- each subtype, which would be incorrect. | |
70482933 | 1640 | |
0da2c8ac AC |
1641 | if Present (CC) |
1642 | and then Reverse_Bit_Order (Rec) | |
1643 | and then Ekind (E) = E_Record_Type | |
1644 | then | |
1645 | declare | |
1646 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
1647 | CSZ : constant Uint := Esize (Comp); | |
1648 | CLC : constant Node_Id := Component_Clause (Comp); | |
1649 | Pos : constant Node_Id := Position (CLC); | |
1650 | FB : constant Node_Id := First_Bit (CLC); | |
1651 | ||
1652 | Storage_Unit_Offset : constant Uint := | |
1653 | CFB / System_Storage_Unit; | |
1654 | ||
1655 | Start_Bit : constant Uint := | |
1656 | CFB mod System_Storage_Unit; | |
1657 | ||
1658 | begin | |
1659 | -- Cases where field goes over storage unit boundary | |
1660 | ||
1661 | if Start_Bit + CSZ > System_Storage_Unit then | |
70482933 | 1662 | |
0da2c8ac AC |
1663 | -- Allow multi-byte field but generate warning |
1664 | ||
1665 | if Start_Bit mod System_Storage_Unit = 0 | |
1666 | and then CSZ mod System_Storage_Unit = 0 | |
1667 | then | |
70482933 | 1668 | Error_Msg_N |
0da2c8ac AC |
1669 | ("multi-byte field specified with non-standard" |
1670 | & " Bit_Order?", CLC); | |
1671 | ||
1672 | if Bytes_Big_Endian then | |
1673 | Error_Msg_N | |
1674 | ("bytes are not reversed " | |
1675 | & "(component is big-endian)?", CLC); | |
1676 | else | |
1677 | Error_Msg_N | |
1678 | ("bytes are not reversed " | |
1679 | & "(component is little-endian)?", CLC); | |
1680 | end if; | |
1681 | ||
1682 | -- Do not allow non-contiguous field | |
1683 | ||
70482933 RK |
1684 | else |
1685 | Error_Msg_N | |
0da2c8ac AC |
1686 | ("attempt to specify non-contiguous field" |
1687 | & " not permitted", CLC); | |
1688 | Error_Msg_N | |
1689 | ("\(caused by non-standard Bit_Order " | |
1690 | & "specified)", CLC); | |
70482933 RK |
1691 | end if; |
1692 | ||
0da2c8ac | 1693 | -- Case where field fits in one storage unit |
70482933 RK |
1694 | |
1695 | else | |
0da2c8ac | 1696 | -- Give warning if suspicious component clause |
70482933 | 1697 | |
0da2c8ac AC |
1698 | if Intval (FB) >= System_Storage_Unit then |
1699 | Error_Msg_N | |
1700 | ("?Bit_Order clause does not affect " & | |
1701 | "byte ordering", Pos); | |
1702 | Error_Msg_Uint_1 := | |
1703 | Intval (Pos) + Intval (FB) / | |
1704 | System_Storage_Unit; | |
1705 | Error_Msg_N | |
1706 | ("?position normalized to ^ before bit " & | |
1707 | "order interpreted", Pos); | |
1708 | end if; | |
70482933 | 1709 | |
0da2c8ac AC |
1710 | -- Here is where we fix up the Component_Bit_Offset |
1711 | -- value to account for the reverse bit order. | |
1712 | -- Some examples of what needs to be done are: | |
70482933 | 1713 | |
0da2c8ac AC |
1714 | -- First_Bit .. Last_Bit Component_Bit_Offset |
1715 | -- old new old new | |
70482933 | 1716 | |
0da2c8ac AC |
1717 | -- 0 .. 0 7 .. 7 0 7 |
1718 | -- 0 .. 1 6 .. 7 0 6 | |
1719 | -- 0 .. 2 5 .. 7 0 5 | |
1720 | -- 0 .. 7 0 .. 7 0 4 | |
70482933 | 1721 | |
0da2c8ac AC |
1722 | -- 1 .. 1 6 .. 6 1 6 |
1723 | -- 1 .. 4 3 .. 6 1 3 | |
1724 | -- 4 .. 7 0 .. 3 4 0 | |
70482933 | 1725 | |
0da2c8ac AC |
1726 | -- The general rule is that the first bit is |
1727 | -- is obtained by subtracting the old ending bit | |
1728 | -- from storage_unit - 1. | |
70482933 | 1729 | |
0da2c8ac AC |
1730 | Set_Component_Bit_Offset |
1731 | (Comp, | |
1732 | (Storage_Unit_Offset * System_Storage_Unit) + | |
1733 | (System_Storage_Unit - 1) - | |
1734 | (Start_Bit + CSZ - 1)); | |
70482933 | 1735 | |
0da2c8ac AC |
1736 | Set_Normalized_First_Bit |
1737 | (Comp, | |
1738 | Component_Bit_Offset (Comp) mod | |
1739 | System_Storage_Unit); | |
1740 | end if; | |
1741 | end; | |
1742 | end if; | |
1743 | end; | |
70482933 RK |
1744 | end if; |
1745 | ||
c6823a20 EB |
1746 | -- If the component is an Itype with Delayed_Freeze and is either |
1747 | -- a record or array subtype and its base type has not yet been | |
1748 | -- frozen, we must remove this from the entity list of this | |
1749 | -- record and put it on the entity list of the scope of its base | |
1750 | -- type. Note that we know that this is not the type of a | |
1751 | -- component since we cleared Has_Delayed_Freeze for it in the | |
1752 | -- previous loop. Thus this must be the Designated_Type of an | |
1753 | -- access type, which is the type of a component. | |
1754 | ||
1755 | if Is_Itype (Comp) | |
1756 | and then Is_Type (Scope (Comp)) | |
1757 | and then Is_Composite_Type (Comp) | |
1758 | and then Base_Type (Comp) /= Comp | |
1759 | and then Has_Delayed_Freeze (Comp) | |
1760 | and then not Is_Frozen (Base_Type (Comp)) | |
1761 | then | |
1762 | declare | |
1763 | Will_Be_Frozen : Boolean := False; | |
1764 | S : Entity_Id := Scope (Rec); | |
1765 | ||
1766 | begin | |
1767 | -- We have a pretty bad kludge here. Suppose Rec is a | |
1768 | -- subtype being defined in a subprogram that's created | |
1769 | -- as part of the freezing of Rec'Base. In that case, | |
1770 | -- we know that Comp'Base must have already been frozen by | |
1771 | -- the time we get to elaborate this because Gigi doesn't | |
1772 | -- elaborate any bodies until it has elaborated all of the | |
1773 | -- declarative part. But Is_Frozen will not be set at this | |
1774 | -- point because we are processing code in lexical order. | |
1775 | ||
1776 | -- We detect this case by going up the Scope chain of | |
1777 | -- Rec and seeing if we have a subprogram scope before | |
1778 | -- reaching the top of the scope chain or that of Comp'Base. | |
1779 | -- If we do, then mark that Comp'Base will actually be | |
1780 | -- frozen. If so, we merely undelay it. | |
1781 | ||
1782 | while Present (S) loop | |
1783 | if Is_Subprogram (S) then | |
1784 | Will_Be_Frozen := True; | |
1785 | exit; | |
1786 | elsif S = Scope (Base_Type (Comp)) then | |
1787 | exit; | |
1788 | end if; | |
1789 | ||
1790 | S := Scope (S); | |
1791 | end loop; | |
1792 | ||
1793 | if Will_Be_Frozen then | |
1794 | Undelay_Type (Comp); | |
1795 | else | |
1796 | if Present (Prev) then | |
1797 | Set_Next_Entity (Prev, Next_Entity (Comp)); | |
1798 | else | |
1799 | Set_First_Entity (Rec, Next_Entity (Comp)); | |
1800 | end if; | |
1801 | ||
1802 | -- Insert in entity list of scope of base type (which | |
1803 | -- must be an enclosing scope, because still unfrozen). | |
1804 | ||
1805 | Append_Entity (Comp, Scope (Base_Type (Comp))); | |
1806 | end if; | |
1807 | end; | |
1808 | ||
1809 | -- If the component is an access type with an allocator as | |
1810 | -- default value, the designated type will be frozen by the | |
1811 | -- corresponding expression in init_proc. In order to place the | |
1812 | -- freeze node for the designated type before that for the | |
1813 | -- current record type, freeze it now. | |
1814 | ||
1815 | -- Same process if the component is an array of access types, | |
1816 | -- initialized with an aggregate. If the designated type is | |
1817 | -- private, it cannot contain allocators, and it is premature to | |
1818 | -- freeze the type, so we check for this as well. | |
1819 | ||
1820 | elsif Is_Access_Type (Etype (Comp)) | |
1821 | and then Present (Parent (Comp)) | |
1822 | and then Present (Expression (Parent (Comp))) | |
1823 | and then Nkind (Expression (Parent (Comp))) = N_Allocator | |
1824 | then | |
1825 | declare | |
1826 | Alloc : constant Node_Id := Expression (Parent (Comp)); | |
1827 | ||
1828 | begin | |
1829 | -- If component is pointer to a classwide type, freeze | |
1830 | -- the specific type in the expression being allocated. | |
1831 | -- The expression may be a subtype indication, in which | |
1832 | -- case freeze the subtype mark. | |
1833 | ||
1834 | if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then | |
1835 | if Is_Entity_Name (Expression (Alloc)) then | |
1836 | Freeze_And_Append | |
1837 | (Entity (Expression (Alloc)), Loc, Result); | |
1838 | elsif | |
1839 | Nkind (Expression (Alloc)) = N_Subtype_Indication | |
1840 | then | |
1841 | Freeze_And_Append | |
1842 | (Entity (Subtype_Mark (Expression (Alloc))), | |
1843 | Loc, Result); | |
1844 | end if; | |
1845 | ||
1846 | elsif Is_Itype (Designated_Type (Etype (Comp))) then | |
1847 | Check_Itype (Designated_Type (Etype (Comp))); | |
1848 | ||
1849 | else | |
1850 | Freeze_And_Append | |
1851 | (Designated_Type (Etype (Comp)), Loc, Result); | |
1852 | end if; | |
1853 | end; | |
1854 | ||
1855 | elsif Is_Access_Type (Etype (Comp)) | |
1856 | and then Is_Itype (Designated_Type (Etype (Comp))) | |
1857 | then | |
1858 | Check_Itype (Designated_Type (Etype (Comp))); | |
1859 | ||
1860 | elsif Is_Array_Type (Etype (Comp)) | |
1861 | and then Is_Access_Type (Component_Type (Etype (Comp))) | |
1862 | and then Present (Parent (Comp)) | |
1863 | and then Nkind (Parent (Comp)) = N_Component_Declaration | |
1864 | and then Present (Expression (Parent (Comp))) | |
1865 | and then Nkind (Expression (Parent (Comp))) = N_Aggregate | |
1866 | and then Is_Fully_Defined | |
1867 | (Designated_Type (Component_Type (Etype (Comp)))) | |
1868 | then | |
1869 | Freeze_And_Append | |
1870 | (Designated_Type | |
1871 | (Component_Type (Etype (Comp))), Loc, Result); | |
1872 | end if; | |
1873 | ||
1874 | Prev := Comp; | |
70482933 RK |
1875 | Next_Entity (Comp); |
1876 | end loop; | |
1877 | ||
1878 | -- Check for useless pragma Bit_Order | |
1879 | ||
1880 | if not Placed_Component and then Reverse_Bit_Order (Rec) then | |
1881 | ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order); | |
1882 | Error_Msg_N ("?Bit_Order specification has no effect", ADC); | |
1883 | Error_Msg_N ("\?since no component clauses were specified", ADC); | |
1884 | end if; | |
1885 | ||
1886 | -- Check for useless pragma Pack when all components placed | |
1887 | ||
1888 | if Is_Packed (Rec) | |
1889 | and then not Unplaced_Component | |
1890 | and then Warn_On_Redundant_Constructs | |
1891 | then | |
1892 | Error_Msg_N | |
1893 | ("?pragma Pack has no effect, no unplaced components", | |
1894 | Get_Rep_Pragma (Rec, Name_Pack)); | |
1895 | Set_Is_Packed (Rec, False); | |
1896 | end if; | |
1897 | ||
1898 | -- If this is the record corresponding to a remote type, | |
1899 | -- freeze the remote type here since that is what we are | |
fbf5a39b AC |
1900 | -- semantically freezing. This prevents having the freeze |
1901 | -- node for that type in an inner scope. | |
70482933 RK |
1902 | |
1903 | -- Also, Check for controlled components and unchecked unions. | |
1904 | -- Finally, enforce the restriction that access attributes with | |
1905 | -- a current instance prefix can only apply to limited types. | |
1906 | ||
1907 | if Ekind (Rec) = E_Record_Type then | |
70482933 RK |
1908 | if Present (Corresponding_Remote_Type (Rec)) then |
1909 | Freeze_And_Append | |
1910 | (Corresponding_Remote_Type (Rec), Loc, Result); | |
1911 | end if; | |
1912 | ||
1913 | Comp := First_Component (Rec); | |
70482933 RK |
1914 | while Present (Comp) loop |
1915 | if Has_Controlled_Component (Etype (Comp)) | |
1916 | or else (Chars (Comp) /= Name_uParent | |
1917 | and then Is_Controlled (Etype (Comp))) | |
1918 | or else (Is_Protected_Type (Etype (Comp)) | |
1919 | and then Present | |
1920 | (Corresponding_Record_Type (Etype (Comp))) | |
1921 | and then Has_Controlled_Component | |
1922 | (Corresponding_Record_Type (Etype (Comp)))) | |
1923 | then | |
1924 | Set_Has_Controlled_Component (Rec); | |
1925 | exit; | |
1926 | end if; | |
1927 | ||
1928 | if Has_Unchecked_Union (Etype (Comp)) then | |
1929 | Set_Has_Unchecked_Union (Rec); | |
1930 | end if; | |
1931 | ||
1932 | if Has_Per_Object_Constraint (Comp) | |
1933 | and then not Is_Limited_Type (Rec) | |
1934 | then | |
1935 | -- Scan component declaration for likely misuses of | |
1936 | -- current instance, either in a constraint or in a | |
1937 | -- default expression. | |
1938 | ||
1939 | Check_Current_Instance (Parent (Comp)); | |
1940 | end if; | |
1941 | ||
1942 | Next_Component (Comp); | |
1943 | end loop; | |
1944 | end if; | |
1945 | ||
1946 | Set_Component_Alignment_If_Not_Set (Rec); | |
1947 | ||
1948 | -- For first subtypes, check if there are any fixed-point | |
1949 | -- fields with component clauses, where we must check the size. | |
1950 | -- This is not done till the freeze point, since for fixed-point | |
1951 | -- types, we do not know the size until the type is frozen. | |
d05ef0ab | 1952 | -- Similar processing applies to bit packed arrays. |
70482933 RK |
1953 | |
1954 | if Is_First_Subtype (Rec) then | |
1955 | Comp := First_Component (Rec); | |
1956 | ||
1957 | while Present (Comp) loop | |
1958 | if Present (Component_Clause (Comp)) | |
d05ef0ab AC |
1959 | and then (Is_Fixed_Point_Type (Etype (Comp)) |
1960 | or else | |
1961 | Is_Bit_Packed_Array (Etype (Comp))) | |
70482933 RK |
1962 | then |
1963 | Check_Size | |
d05ef0ab | 1964 | (Component_Name (Component_Clause (Comp)), |
70482933 RK |
1965 | Etype (Comp), |
1966 | Esize (Comp), | |
1967 | Junk); | |
1968 | end if; | |
1969 | ||
1970 | Next_Component (Comp); | |
1971 | end loop; | |
1972 | end if; | |
1973 | end Freeze_Record_Type; | |
1974 | ||
1975 | -- Start of processing for Freeze_Entity | |
1976 | ||
1977 | begin | |
c6823a20 EB |
1978 | -- We are going to test for various reasons why this entity need not be |
1979 | -- frozen here, but in the case of an Itype that's defined within a | |
1980 | -- record, that test actually applies to the record. | |
1981 | ||
1982 | if Is_Itype (E) and then Is_Record_Type (Scope (E)) then | |
1983 | Test_E := Scope (E); | |
1984 | elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E))) | |
1985 | and then Is_Record_Type (Underlying_Type (Scope (E))) | |
1986 | then | |
1987 | Test_E := Underlying_Type (Scope (E)); | |
1988 | end if; | |
1989 | ||
fbf5a39b | 1990 | -- Do not freeze if already frozen since we only need one freeze node |
70482933 RK |
1991 | |
1992 | if Is_Frozen (E) then | |
1993 | return No_List; | |
1994 | ||
c6823a20 EB |
1995 | -- It is improper to freeze an external entity within a generic because |
1996 | -- its freeze node will appear in a non-valid context. The entity will | |
1997 | -- be frozen in the proper scope after the current generic is analyzed. | |
70482933 | 1998 | |
c6823a20 | 1999 | elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then |
70482933 RK |
2000 | return No_List; |
2001 | ||
2002 | -- Do not freeze a global entity within an inner scope created during | |
2003 | -- expansion. A call to subprogram E within some internal procedure | |
2004 | -- (a stream attribute for example) might require freezing E, but the | |
2005 | -- freeze node must appear in the same declarative part as E itself. | |
2006 | -- The two-pass elaboration mechanism in gigi guarantees that E will | |
2007 | -- be frozen before the inner call is elaborated. We exclude constants | |
2008 | -- from this test, because deferred constants may be frozen early, and | |
2009 | -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram | |
2010 | -- comes from source, or is a generic instance, then the freeze point | |
2011 | -- is the one mandated by the language. and we freze the entity. | |
2012 | ||
c6823a20 EB |
2013 | elsif In_Open_Scopes (Scope (Test_E)) |
2014 | and then Scope (Test_E) /= Current_Scope | |
2015 | and then Ekind (Test_E) /= E_Constant | |
70482933 RK |
2016 | then |
2017 | declare | |
2018 | S : Entity_Id := Current_Scope; | |
2019 | ||
2020 | begin | |
2021 | while Present (S) loop | |
2022 | if Is_Overloadable (S) then | |
2023 | if Comes_From_Source (S) | |
2024 | or else Is_Generic_Instance (S) | |
2025 | then | |
2026 | exit; | |
2027 | else | |
2028 | return No_List; | |
2029 | end if; | |
2030 | end if; | |
2031 | ||
2032 | S := Scope (S); | |
2033 | end loop; | |
2034 | end; | |
555360a5 AC |
2035 | |
2036 | -- Similarly, an inlined instance body may make reference to global | |
2037 | -- entities, but these references cannot be the proper freezing point | |
2038 | -- for them, and the the absence of inlining freezing will take place | |
2039 | -- in their own scope. Normally instance bodies are analyzed after | |
2040 | -- the enclosing compilation, and everything has been frozen at the | |
2041 | -- proper place, but with front-end inlining an instance body is | |
2042 | -- compiled before the end of the enclosing scope, and as a result | |
2043 | -- out-of-order freezing must be prevented. | |
2044 | ||
2045 | elsif Front_End_Inlining | |
2046 | and then In_Instance_Body | |
c6823a20 | 2047 | and then Present (Scope (Test_E)) |
555360a5 AC |
2048 | then |
2049 | declare | |
c6823a20 EB |
2050 | S : Entity_Id := Scope (Test_E); |
2051 | ||
555360a5 AC |
2052 | begin |
2053 | while Present (S) loop | |
2054 | if Is_Generic_Instance (S) then | |
2055 | exit; | |
2056 | else | |
2057 | S := Scope (S); | |
2058 | end if; | |
2059 | end loop; | |
2060 | ||
2061 | if No (S) then | |
2062 | return No_List; | |
2063 | end if; | |
2064 | end; | |
70482933 RK |
2065 | end if; |
2066 | ||
2067 | -- Here to freeze the entity | |
2068 | ||
2069 | Result := No_List; | |
2070 | Set_Is_Frozen (E); | |
2071 | ||
2072 | -- Case of entity being frozen is other than a type | |
2073 | ||
2074 | if not Is_Type (E) then | |
2075 | ||
2076 | -- If entity is exported or imported and does not have an external | |
2077 | -- name, now is the time to provide the appropriate default name. | |
2078 | -- Skip this if the entity is stubbed, since we don't need a name | |
2079 | -- for any stubbed routine. | |
2080 | ||
2081 | if (Is_Imported (E) or else Is_Exported (E)) | |
2082 | and then No (Interface_Name (E)) | |
2083 | and then Convention (E) /= Convention_Stubbed | |
2084 | then | |
2085 | Set_Encoded_Interface_Name | |
2086 | (E, Get_Default_External_Name (E)); | |
fbf5a39b AC |
2087 | |
2088 | -- Special processing for atomic objects appearing in object decls | |
2089 | ||
2090 | elsif Is_Atomic (E) | |
2091 | and then Nkind (Parent (E)) = N_Object_Declaration | |
2092 | and then Present (Expression (Parent (E))) | |
2093 | then | |
2094 | declare | |
2095 | Expr : constant Node_Id := Expression (Parent (E)); | |
2096 | ||
2097 | begin | |
2098 | -- If expression is an aggregate, assign to a temporary to | |
2099 | -- ensure that the actual assignment is done atomically rather | |
2100 | -- than component-wise (the assignment to the temp may be done | |
2101 | -- component-wise, but that is harmless. | |
2102 | ||
2103 | if Nkind (Expr) = N_Aggregate then | |
2104 | Expand_Atomic_Aggregate (Expr, Etype (E)); | |
2105 | ||
2106 | -- If the expression is a reference to a record or array | |
2107 | -- object entity, then reset Is_True_Constant to False so | |
2108 | -- that the compiler will not optimize away the intermediate | |
2109 | -- object, which we need in this case for the same reason | |
2110 | -- (to ensure that the actual assignment is atomic, rather | |
2111 | -- than component-wise). | |
2112 | ||
2113 | elsif Is_Entity_Name (Expr) | |
2114 | and then (Is_Record_Type (Etype (Expr)) | |
2115 | or else | |
2116 | Is_Array_Type (Etype (Expr))) | |
2117 | then | |
2118 | Set_Is_True_Constant (Entity (Expr), False); | |
2119 | end if; | |
2120 | end; | |
70482933 RK |
2121 | end if; |
2122 | ||
2123 | -- For a subprogram, freeze all parameter types and also the return | |
fbf5a39b | 2124 | -- type (RM 13.14(14)). However skip this for internal subprograms. |
70482933 RK |
2125 | -- This is also the point where any extra formal parameters are |
2126 | -- created since we now know whether the subprogram will use | |
2127 | -- a foreign convention. | |
2128 | ||
2129 | if Is_Subprogram (E) then | |
70482933 | 2130 | if not Is_Internal (E) then |
70482933 | 2131 | declare |
6d11af89 AC |
2132 | F_Type : Entity_Id; |
2133 | Warn_Node : Node_Id; | |
70482933 RK |
2134 | |
2135 | function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean; | |
2136 | -- Determines if given type entity is a fat pointer type | |
2137 | -- used as an argument type or return type to a subprogram | |
2138 | -- with C or C++ convention set. | |
2139 | ||
2140 | -------------------------- | |
2141 | -- Is_Fat_C_Access_Type -- | |
2142 | -------------------------- | |
2143 | ||
2144 | function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is | |
2145 | begin | |
2146 | return (Convention (E) = Convention_C | |
2147 | or else | |
2148 | Convention (E) = Convention_CPP) | |
2149 | and then Is_Access_Type (T) | |
2150 | and then Esize (T) > Ttypes.System_Address_Size; | |
2151 | end Is_Fat_C_Ptr_Type; | |
2152 | ||
2153 | begin | |
2154 | -- Loop through formals | |
2155 | ||
2156 | Formal := First_Formal (E); | |
70482933 | 2157 | while Present (Formal) loop |
70482933 RK |
2158 | F_Type := Etype (Formal); |
2159 | Freeze_And_Append (F_Type, Loc, Result); | |
2160 | ||
2161 | if Is_Private_Type (F_Type) | |
2162 | and then Is_Private_Type (Base_Type (F_Type)) | |
2163 | and then No (Full_View (Base_Type (F_Type))) | |
2164 | and then not Is_Generic_Type (F_Type) | |
2165 | and then not Is_Derived_Type (F_Type) | |
2166 | then | |
2167 | -- If the type of a formal is incomplete, subprogram | |
2168 | -- is being frozen prematurely. Within an instance | |
2169 | -- (but not within a wrapper package) this is an | |
2170 | -- an artifact of our need to regard the end of an | |
2171 | -- instantiation as a freeze point. Otherwise it is | |
2172 | -- a definite error. | |
fbf5a39b | 2173 | |
70482933 RK |
2174 | -- and then not Is_Wrapper_Package (Current_Scope) ??? |
2175 | ||
2176 | if In_Instance then | |
2177 | Set_Is_Frozen (E, False); | |
2178 | return No_List; | |
2179 | ||
2180 | elsif not After_Last_Declaration then | |
2181 | Error_Msg_Node_1 := F_Type; | |
2182 | Error_Msg | |
2183 | ("type& must be fully defined before this point", | |
2184 | Loc); | |
2185 | end if; | |
2186 | end if; | |
2187 | ||
2188 | -- Check bad use of fat C pointer | |
2189 | ||
fbf5a39b AC |
2190 | if Warn_On_Export_Import and then |
2191 | Is_Fat_C_Ptr_Type (F_Type) | |
2192 | then | |
70482933 RK |
2193 | Error_Msg_Qual_Level := 1; |
2194 | Error_Msg_N | |
2195 | ("?type of & does not correspond to C pointer", | |
2196 | Formal); | |
2197 | Error_Msg_Qual_Level := 0; | |
2198 | end if; | |
2199 | ||
2200 | -- Check for unconstrained array in exported foreign | |
2201 | -- convention case. | |
2202 | ||
2203 | if Convention (E) in Foreign_Convention | |
2204 | and then not Is_Imported (E) | |
2205 | and then Is_Array_Type (F_Type) | |
2206 | and then not Is_Constrained (F_Type) | |
fbf5a39b | 2207 | and then Warn_On_Export_Import |
70482933 RK |
2208 | then |
2209 | Error_Msg_Qual_Level := 1; | |
6d11af89 AC |
2210 | |
2211 | -- If this is an inherited operation, place the | |
2212 | -- warning on the derived type declaration, rather | |
2213 | -- than on the original subprogram. | |
2214 | ||
2215 | if Nkind (Original_Node (Parent (E))) = | |
2216 | N_Full_Type_Declaration | |
2217 | then | |
2218 | Warn_Node := Parent (E); | |
2219 | ||
2220 | if Formal = First_Formal (E) then | |
2221 | Error_Msg_NE | |
2222 | ("?in inherited operation&!", Warn_Node, E); | |
2223 | end if; | |
2224 | else | |
2225 | Warn_Node := Formal; | |
2226 | end if; | |
2227 | ||
2228 | Error_Msg_NE | |
70482933 | 2229 | ("?type of argument& is unconstrained array", |
6d11af89 AC |
2230 | Warn_Node, Formal); |
2231 | Error_Msg_NE | |
70482933 | 2232 | ("?foreign caller must pass bounds explicitly", |
6d11af89 | 2233 | Warn_Node, Formal); |
70482933 RK |
2234 | Error_Msg_Qual_Level := 0; |
2235 | end if; | |
2236 | ||
d8db0bca JM |
2237 | -- Ada 2005 (AI-326): Check wrong use of tag incomplete |
2238 | -- types with unknown discriminants. For example: | |
2239 | ||
2240 | -- type T (<>) is tagged; | |
2241 | -- procedure P (X : access T); -- ERROR | |
2242 | -- procedure P (X : T); -- ERROR | |
2243 | ||
2244 | if not From_With_Type (F_Type) then | |
2245 | if Is_Access_Type (F_Type) then | |
2246 | F_Type := Designated_Type (F_Type); | |
2247 | end if; | |
2248 | ||
2249 | if Ekind (F_Type) = E_Incomplete_Type | |
2250 | and then Is_Tagged_Type (F_Type) | |
2251 | and then not Is_Class_Wide_Type (F_Type) | |
2252 | and then No (Full_View (F_Type)) | |
2253 | and then Unknown_Discriminants_Present | |
2254 | (Parent (F_Type)) | |
2255 | and then No (Stored_Constraint (F_Type)) | |
2256 | then | |
2257 | Error_Msg_N | |
2258 | ("(Ada 2005): invalid use of unconstrained tagged" | |
2259 | & " incomplete type", E); | |
57747aec ES |
2260 | |
2261 | elsif Ekind (F_Type) = E_Subprogram_Type then | |
2262 | Freeze_And_Append (F_Type, Loc, Result); | |
d8db0bca JM |
2263 | end if; |
2264 | end if; | |
2265 | ||
70482933 RK |
2266 | Next_Formal (Formal); |
2267 | end loop; | |
2268 | ||
2269 | -- Check return type | |
2270 | ||
2271 | if Ekind (E) = E_Function then | |
2272 | Freeze_And_Append (Etype (E), Loc, Result); | |
2273 | ||
fbf5a39b AC |
2274 | if Warn_On_Export_Import |
2275 | and then Is_Fat_C_Ptr_Type (Etype (E)) | |
2276 | then | |
70482933 RK |
2277 | Error_Msg_N |
2278 | ("?return type of& does not correspond to C pointer", | |
2279 | E); | |
2280 | ||
2281 | elsif Is_Array_Type (Etype (E)) | |
2282 | and then not Is_Constrained (Etype (E)) | |
2283 | and then not Is_Imported (E) | |
2284 | and then Convention (E) in Foreign_Convention | |
fbf5a39b | 2285 | and then Warn_On_Export_Import |
70482933 RK |
2286 | then |
2287 | Error_Msg_N | |
fbf5a39b | 2288 | ("?foreign convention function& should not " & |
70482933 | 2289 | "return unconstrained array", E); |
d8db0bca JM |
2290 | |
2291 | -- Ada 2005 (AI-326): Check wrong use of tagged | |
2292 | -- incomplete type | |
2293 | -- | |
2294 | -- type T is tagged; | |
2295 | -- function F (X : Boolean) return T; -- ERROR | |
2296 | ||
2297 | elsif Ekind (Etype (E)) = E_Incomplete_Type | |
2298 | and then Is_Tagged_Type (Etype (E)) | |
2299 | and then No (Full_View (Etype (E))) | |
2300 | then | |
2301 | Error_Msg_N | |
2302 | ("(Ada 2005): invalid use of tagged incomplete type", | |
2303 | E); | |
70482933 RK |
2304 | end if; |
2305 | end if; | |
2306 | end; | |
2307 | end if; | |
2308 | ||
2309 | -- Must freeze its parent first if it is a derived subprogram | |
2310 | ||
2311 | if Present (Alias (E)) then | |
2312 | Freeze_And_Append (Alias (E), Loc, Result); | |
2313 | end if; | |
2314 | ||
2315 | -- If the return type requires a transient scope, and we are on | |
2316 | -- a target allowing functions to return with a depressed stack | |
2317 | -- pointer, then we mark the function as requiring this treatment. | |
2318 | ||
2319 | if Ekind (E) = E_Function | |
2320 | and then Functions_Return_By_DSP_On_Target | |
2321 | and then Requires_Transient_Scope (Etype (E)) | |
2322 | then | |
2323 | Set_Function_Returns_With_DSP (E); | |
2324 | end if; | |
2325 | ||
2326 | if not Is_Internal (E) then | |
2327 | Freeze_Subprogram (E); | |
2328 | end if; | |
2329 | ||
2330 | -- Here for other than a subprogram or type | |
2331 | ||
2332 | else | |
2333 | -- If entity has a type, and it is not a generic unit, then | |
2334 | -- freeze it first (RM 13.14(10)) | |
2335 | ||
2336 | if Present (Etype (E)) | |
2337 | and then Ekind (E) /= E_Generic_Function | |
2338 | then | |
2339 | Freeze_And_Append (Etype (E), Loc, Result); | |
2340 | end if; | |
2341 | ||
2c9beb8a | 2342 | -- Special processing for objects created by object declaration |
70482933 RK |
2343 | |
2344 | if Nkind (Declaration_Node (E)) = N_Object_Declaration then | |
2c9beb8a RD |
2345 | |
2346 | -- For object created by object declaration, perform required | |
2347 | -- categorization (preelaborate and pure) checks. Defer these | |
2348 | -- checks to freeze time since pragma Import inhibits default | |
2349 | -- initialization and thus pragma Import affects these checks. | |
2350 | ||
70482933 | 2351 | Validate_Object_Declaration (Declaration_Node (E)); |
2c9beb8a RD |
2352 | |
2353 | -- If there is an address clause, check it is valid | |
2354 | ||
fbf5a39b | 2355 | Check_Address_Clause (E); |
2c9beb8a RD |
2356 | |
2357 | -- For imported objects, set Is_Public unless there is also | |
2358 | -- an address clause, which means that there is no external | |
2359 | -- symbol needed for the Import (Is_Public may still be set | |
2360 | -- for other unrelated reasons). Note that we delayed this | |
2361 | -- processing till freeze time so that we can be sure not | |
2362 | -- to set the flag if there is an address clause. If there | |
2363 | -- is such a clause, then the only purpose of the import | |
2364 | -- pragma is to suppress implicit initialization. | |
2365 | ||
2366 | if Is_Imported (E) | |
2367 | and then not Present (Address_Clause (E)) | |
2368 | then | |
2369 | Set_Is_Public (E); | |
2370 | end if; | |
70482933 RK |
2371 | end if; |
2372 | ||
2373 | -- Check that a constant which has a pragma Volatile[_Components] | |
2374 | -- or Atomic[_Components] also has a pragma Import (RM C.6(13)) | |
2375 | ||
2376 | -- Note: Atomic[_Components] also sets Volatile[_Components] | |
2377 | ||
2378 | if Ekind (E) = E_Constant | |
2379 | and then (Has_Volatile_Components (E) or else Is_Volatile (E)) | |
2380 | and then not Is_Imported (E) | |
2381 | then | |
2382 | -- Make sure we actually have a pragma, and have not merely | |
2383 | -- inherited the indication from elsewhere (e.g. an address | |
2384 | -- clause, which is not good enough in RM terms!) | |
2385 | ||
1d571f3b | 2386 | if Has_Rep_Pragma (E, Name_Atomic) |
91b1417d | 2387 | or else |
1d571f3b | 2388 | Has_Rep_Pragma (E, Name_Atomic_Components) |
70482933 RK |
2389 | then |
2390 | Error_Msg_N | |
91b1417d AC |
2391 | ("stand alone atomic constant must be " & |
2392 | "imported ('R'M 'C.6(13))", E); | |
2393 | ||
1d571f3b | 2394 | elsif Has_Rep_Pragma (E, Name_Volatile) |
91b1417d | 2395 | or else |
1d571f3b | 2396 | Has_Rep_Pragma (E, Name_Volatile_Components) |
91b1417d AC |
2397 | then |
2398 | Error_Msg_N | |
2399 | ("stand alone volatile constant must be " & | |
2400 | "imported ('R'M 'C.6(13))", E); | |
70482933 RK |
2401 | end if; |
2402 | end if; | |
2403 | ||
2404 | -- Static objects require special handling | |
2405 | ||
2406 | if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) | |
2407 | and then Is_Statically_Allocated (E) | |
2408 | then | |
2409 | Freeze_Static_Object (E); | |
2410 | end if; | |
2411 | ||
2412 | -- Remaining step is to layout objects | |
2413 | ||
2414 | if Ekind (E) = E_Variable | |
2415 | or else | |
2416 | Ekind (E) = E_Constant | |
2417 | or else | |
2418 | Ekind (E) = E_Loop_Parameter | |
2419 | or else | |
2420 | Is_Formal (E) | |
2421 | then | |
2422 | Layout_Object (E); | |
2423 | end if; | |
2424 | end if; | |
2425 | ||
2426 | -- Case of a type or subtype being frozen | |
2427 | ||
2428 | else | |
2429 | -- The type may be defined in a generic unit. This can occur when | |
2430 | -- freezing a generic function that returns the type (which is | |
2431 | -- defined in a parent unit). It is clearly meaningless to freeze | |
2432 | -- this type. However, if it is a subtype, its size may be determi- | |
2433 | -- nable and used in subsequent checks, so might as well try to | |
2434 | -- compute it. | |
2435 | ||
2436 | if Present (Scope (E)) | |
2437 | and then Is_Generic_Unit (Scope (E)) | |
2438 | then | |
2439 | Check_Compile_Time_Size (E); | |
2440 | return No_List; | |
2441 | end if; | |
2442 | ||
2443 | -- Deal with special cases of freezing for subtype | |
2444 | ||
2445 | if E /= Base_Type (E) then | |
2446 | ||
2447 | -- If ancestor subtype present, freeze that first. | |
2448 | -- Note that this will also get the base type frozen. | |
2449 | ||
2450 | Atype := Ancestor_Subtype (E); | |
2451 | ||
2452 | if Present (Atype) then | |
2453 | Freeze_And_Append (Atype, Loc, Result); | |
2454 | ||
2455 | -- Otherwise freeze the base type of the entity before | |
fbf5a39b | 2456 | -- freezing the entity itself, (RM 13.14(15)). |
70482933 RK |
2457 | |
2458 | elsif E /= Base_Type (E) then | |
2459 | Freeze_And_Append (Base_Type (E), Loc, Result); | |
2460 | end if; | |
2461 | ||
fbf5a39b | 2462 | -- For a derived type, freeze its parent type first (RM 13.14(15)) |
70482933 RK |
2463 | |
2464 | elsif Is_Derived_Type (E) then | |
2465 | Freeze_And_Append (Etype (E), Loc, Result); | |
2466 | Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result); | |
2467 | end if; | |
2468 | ||
2469 | -- For array type, freeze index types and component type first | |
fbf5a39b | 2470 | -- before freezing the array (RM 13.14(15)). |
70482933 RK |
2471 | |
2472 | if Is_Array_Type (E) then | |
2473 | declare | |
fbf5a39b AC |
2474 | Ctyp : constant Entity_Id := Component_Type (E); |
2475 | Pnod : Node_Id; | |
70482933 RK |
2476 | |
2477 | Non_Standard_Enum : Boolean := False; | |
2478 | -- Set true if any of the index types is an enumeration | |
2479 | -- type with a non-standard representation. | |
2480 | ||
2481 | begin | |
2482 | Freeze_And_Append (Ctyp, Loc, Result); | |
2483 | ||
2484 | Indx := First_Index (E); | |
2485 | while Present (Indx) loop | |
2486 | Freeze_And_Append (Etype (Indx), Loc, Result); | |
2487 | ||
2488 | if Is_Enumeration_Type (Etype (Indx)) | |
2489 | and then Has_Non_Standard_Rep (Etype (Indx)) | |
2490 | then | |
2491 | Non_Standard_Enum := True; | |
2492 | end if; | |
2493 | ||
2494 | Next_Index (Indx); | |
2495 | end loop; | |
2496 | ||
07fc65c4 | 2497 | -- Processing that is done only for base types |
70482933 RK |
2498 | |
2499 | if Ekind (E) = E_Array_Type then | |
07fc65c4 GB |
2500 | |
2501 | -- Propagate flags for component type | |
2502 | ||
70482933 RK |
2503 | if Is_Controlled (Component_Type (E)) |
2504 | or else Has_Controlled_Component (Ctyp) | |
2505 | then | |
2506 | Set_Has_Controlled_Component (E); | |
2507 | end if; | |
2508 | ||
2509 | if Has_Unchecked_Union (Component_Type (E)) then | |
2510 | Set_Has_Unchecked_Union (E); | |
2511 | end if; | |
70482933 | 2512 | |
07fc65c4 GB |
2513 | -- If packing was requested or if the component size was set |
2514 | -- explicitly, then see if bit packing is required. This | |
2515 | -- processing is only done for base types, since all the | |
2516 | -- representation aspects involved are type-related. This | |
2517 | -- is not just an optimization, if we start processing the | |
2518 | -- subtypes, they intefere with the settings on the base | |
2519 | -- type (this is because Is_Packed has a slightly different | |
2520 | -- meaning before and after freezing). | |
70482933 | 2521 | |
70482933 RK |
2522 | declare |
2523 | Csiz : Uint; | |
2524 | Esiz : Uint; | |
2525 | ||
2526 | begin | |
2527 | if (Is_Packed (E) or else Has_Pragma_Pack (E)) | |
2528 | and then not Has_Atomic_Components (E) | |
2529 | and then Known_Static_RM_Size (Ctyp) | |
2530 | then | |
2531 | Csiz := UI_Max (RM_Size (Ctyp), 1); | |
2532 | ||
2533 | elsif Known_Component_Size (E) then | |
2534 | Csiz := Component_Size (E); | |
2535 | ||
2536 | elsif not Known_Static_Esize (Ctyp) then | |
2537 | Csiz := Uint_0; | |
2538 | ||
2539 | else | |
2540 | Esiz := Esize (Ctyp); | |
2541 | ||
2542 | -- We can set the component size if it is less than | |
2543 | -- 16, rounding it up to the next storage unit size. | |
2544 | ||
2545 | if Esiz <= 8 then | |
2546 | Csiz := Uint_8; | |
2547 | elsif Esiz <= 16 then | |
2548 | Csiz := Uint_16; | |
2549 | else | |
2550 | Csiz := Uint_0; | |
2551 | end if; | |
2552 | ||
2553 | -- Set component size up to match alignment if | |
2554 | -- it would otherwise be less than the alignment. | |
2555 | -- This deals with cases of types whose alignment | |
2556 | -- exceeds their sizes (padded types). | |
2557 | ||
2558 | if Csiz /= 0 then | |
2559 | declare | |
2560 | A : constant Uint := Alignment_In_Bits (Ctyp); | |
2561 | ||
2562 | begin | |
2563 | if Csiz < A then | |
2564 | Csiz := A; | |
2565 | end if; | |
2566 | end; | |
2567 | end if; | |
2568 | ||
2569 | end if; | |
2570 | ||
2571 | if 1 <= Csiz and then Csiz <= 64 then | |
2572 | ||
2573 | -- We set the component size for all cases 1-64 | |
2574 | ||
2575 | Set_Component_Size (Base_Type (E), Csiz); | |
2576 | ||
fbf5a39b AC |
2577 | -- Check for base type of 8,16,32 bits, where the |
2578 | -- subtype has a length one less than the base type | |
2579 | -- and is unsigned (e.g. Natural subtype of Integer) | |
2580 | ||
2581 | -- In such cases, if a component size was not set | |
2582 | -- explicitly, then generate a warning. | |
2583 | ||
2584 | if Has_Pragma_Pack (E) | |
2585 | and then not Has_Component_Size_Clause (E) | |
2586 | and then | |
2587 | (Csiz = 7 or else Csiz = 15 or else Csiz = 31) | |
2588 | and then Esize (Base_Type (Ctyp)) = Csiz + 1 | |
2589 | then | |
2590 | Error_Msg_Uint_1 := Csiz; | |
2591 | Pnod := | |
2592 | Get_Rep_Pragma (First_Subtype (E), Name_Pack); | |
2593 | ||
2594 | if Present (Pnod) then | |
2595 | Error_Msg_N | |
2596 | ("pragma Pack causes component size to be ^?", | |
2597 | Pnod); | |
2598 | Error_Msg_N | |
2599 | ("\use Component_Size to set desired value", | |
2600 | Pnod); | |
2601 | end if; | |
2602 | end if; | |
2603 | ||
70482933 RK |
2604 | -- Actual packing is not needed for 8,16,32,64 |
2605 | -- Also not needed for 24 if alignment is 1 | |
2606 | ||
2607 | if Csiz = 8 | |
2608 | or else Csiz = 16 | |
2609 | or else Csiz = 32 | |
2610 | or else Csiz = 64 | |
2611 | or else (Csiz = 24 and then Alignment (Ctyp) = 1) | |
2612 | then | |
2613 | -- Here the array was requested to be packed, but | |
2614 | -- the packing request had no effect, so Is_Packed | |
2615 | -- is reset. | |
2616 | ||
2617 | -- Note: semantically this means that we lose | |
2618 | -- track of the fact that a derived type inherited | |
2619 | -- a pack pragma that was non-effective, but that | |
2620 | -- seems fine. | |
2621 | ||
2622 | -- We regard a Pack pragma as a request to set a | |
2623 | -- representation characteristic, and this request | |
2624 | -- may be ignored. | |
2625 | ||
2626 | Set_Is_Packed (Base_Type (E), False); | |
2627 | ||
2628 | -- In all other cases, packing is indeed needed | |
2629 | ||
2630 | else | |
2631 | Set_Has_Non_Standard_Rep (Base_Type (E)); | |
2632 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
2633 | Set_Is_Packed (Base_Type (E)); | |
2634 | end if; | |
2635 | end if; | |
2636 | end; | |
07fc65c4 GB |
2637 | |
2638 | -- Processing that is done only for subtypes | |
2639 | ||
2640 | else | |
2641 | -- Acquire alignment from base type | |
2642 | ||
2643 | if Unknown_Alignment (E) then | |
2644 | Set_Alignment (E, Alignment (Base_Type (E))); | |
2645 | end if; | |
2646 | end if; | |
2647 | ||
d05ef0ab AC |
2648 | -- For bit-packed arrays, check the size |
2649 | ||
2650 | if Is_Bit_Packed_Array (E) | |
2651 | and then Known_Esize (E) | |
2652 | then | |
2653 | declare | |
2654 | Discard : Boolean; | |
2655 | SizC : constant Node_Id := Size_Clause (E); | |
2656 | ||
2657 | begin | |
2658 | -- It is not clear if it is possible to have no size | |
2659 | -- clause at this stage, but this is not worth worrying | |
2660 | -- about. Post the error on the entity name in the size | |
2661 | -- clause if present, else on the type entity itself. | |
2662 | ||
2663 | if Present (SizC) then | |
2664 | Check_Size (Name (SizC), E, Esize (E), Discard); | |
2665 | else | |
2666 | Check_Size (E, E, Esize (E), Discard); | |
2667 | end if; | |
2668 | end; | |
2669 | end if; | |
2670 | ||
07fc65c4 GB |
2671 | -- Check one common case of a size given where the array |
2672 | -- needs to be packed, but was not so the size cannot be | |
2673 | -- honored. This would of course be caught by the backend, | |
2674 | -- and indeed we don't catch all cases. The point is that | |
2675 | -- we can give a better error message in those cases that | |
2676 | -- we do catch with the circuitry here. | |
2677 | ||
fbf5a39b AC |
2678 | declare |
2679 | Lo, Hi : Node_Id; | |
2680 | Ctyp : constant Entity_Id := Component_Type (E); | |
07fc65c4 | 2681 | |
fbf5a39b AC |
2682 | begin |
2683 | if Present (Size_Clause (E)) | |
2684 | and then Known_Static_Esize (E) | |
2685 | and then not Is_Bit_Packed_Array (E) | |
2686 | and then not Has_Pragma_Pack (E) | |
2687 | and then Number_Dimensions (E) = 1 | |
2688 | and then not Has_Component_Size_Clause (E) | |
2689 | and then Known_Static_Esize (Ctyp) | |
2690 | then | |
07fc65c4 GB |
2691 | Get_Index_Bounds (First_Index (E), Lo, Hi); |
2692 | ||
2693 | if Compile_Time_Known_Value (Lo) | |
2694 | and then Compile_Time_Known_Value (Hi) | |
2695 | and then Known_Static_RM_Size (Ctyp) | |
2696 | and then RM_Size (Ctyp) < 64 | |
2697 | then | |
2698 | declare | |
fbf5a39b AC |
2699 | Lov : constant Uint := Expr_Value (Lo); |
2700 | Hiv : constant Uint := Expr_Value (Hi); | |
2701 | Len : constant Uint := | |
2702 | UI_Max (Uint_0, Hiv - Lov + 1); | |
2703 | Rsiz : constant Uint := RM_Size (Ctyp); | |
2704 | ||
2705 | -- What we are looking for here is the situation | |
2706 | -- where the Esize given would be exactly right | |
2707 | -- if there was a pragma Pack (resulting in the | |
2708 | -- component size being the same as the RM_Size). | |
2709 | -- Furthermore, the component type size must be | |
2710 | -- an odd size (not a multiple of storage unit) | |
07fc65c4 GB |
2711 | |
2712 | begin | |
fbf5a39b AC |
2713 | if Esize (E) = Len * Rsiz |
2714 | and then Rsiz mod System_Storage_Unit /= 0 | |
07fc65c4 GB |
2715 | then |
2716 | Error_Msg_NE | |
2717 | ("size given for& too small", | |
2718 | Size_Clause (E), E); | |
2719 | Error_Msg_N | |
2720 | ("\explicit pragma Pack is required", | |
2721 | Size_Clause (E)); | |
2722 | end if; | |
2723 | end; | |
2724 | end if; | |
fbf5a39b AC |
2725 | end if; |
2726 | end; | |
70482933 RK |
2727 | |
2728 | -- If any of the index types was an enumeration type with | |
2729 | -- a non-standard rep clause, then we indicate that the | |
2730 | -- array type is always packed (even if it is not bit packed). | |
2731 | ||
2732 | if Non_Standard_Enum then | |
2733 | Set_Has_Non_Standard_Rep (Base_Type (E)); | |
2734 | Set_Is_Packed (Base_Type (E)); | |
2735 | end if; | |
70482933 | 2736 | |
0da2c8ac | 2737 | Set_Component_Alignment_If_Not_Set (E); |
70482933 | 2738 | |
0da2c8ac AC |
2739 | -- If the array is packed, we must create the packed array |
2740 | -- type to be used to actually implement the type. This is | |
2741 | -- only needed for real array types (not for string literal | |
2742 | -- types, since they are present only for the front end). | |
70482933 | 2743 | |
0da2c8ac AC |
2744 | if Is_Packed (E) |
2745 | and then Ekind (E) /= E_String_Literal_Subtype | |
2746 | then | |
2747 | Create_Packed_Array_Type (E); | |
2748 | Freeze_And_Append (Packed_Array_Type (E), Loc, Result); | |
70482933 | 2749 | |
0da2c8ac AC |
2750 | -- Size information of packed array type is copied to the |
2751 | -- array type, since this is really the representation. | |
70482933 | 2752 | |
0da2c8ac AC |
2753 | Set_Size_Info (E, Packed_Array_Type (E)); |
2754 | Set_RM_Size (E, RM_Size (Packed_Array_Type (E))); | |
2755 | end if; | |
2756 | ||
2757 | -- For non-packed arrays set the alignment of the array | |
2758 | -- to the alignment of the component type if it is unknown. | |
2759 | -- Skip this in the atomic case, since atomic arrays may | |
2760 | -- need larger alignments. | |
2761 | ||
2762 | if not Is_Packed (E) | |
2763 | and then Unknown_Alignment (E) | |
2764 | and then Known_Alignment (Ctyp) | |
2765 | and then Known_Static_Component_Size (E) | |
2766 | and then Known_Static_Esize (Ctyp) | |
2767 | and then Esize (Ctyp) = Component_Size (E) | |
2768 | and then not Is_Atomic (E) | |
2769 | then | |
2770 | Set_Alignment (E, Alignment (Component_Type (E))); | |
2771 | end if; | |
2772 | end; | |
70482933 | 2773 | |
fbf5a39b AC |
2774 | -- For a class-wide type, the corresponding specific type is |
2775 | -- frozen as well (RM 13.14(15)) | |
70482933 RK |
2776 | |
2777 | elsif Is_Class_Wide_Type (E) then | |
2778 | Freeze_And_Append (Root_Type (E), Loc, Result); | |
2779 | ||
2780 | -- If the Class_Wide_Type is an Itype (when type is the anonymous | |
2781 | -- parent of a derived type) and it is a library-level entity, | |
2782 | -- generate an itype reference for it. Otherwise, its first | |
2783 | -- explicit reference may be in an inner scope, which will be | |
2784 | -- rejected by the back-end. | |
2785 | ||
2786 | if Is_Itype (E) | |
2787 | and then Is_Compilation_Unit (Scope (E)) | |
2788 | then | |
70482933 | 2789 | declare |
fbf5a39b | 2790 | Ref : constant Node_Id := Make_Itype_Reference (Loc); |
70482933 RK |
2791 | |
2792 | begin | |
2793 | Set_Itype (Ref, E); | |
2794 | if No (Result) then | |
2795 | Result := New_List (Ref); | |
2796 | else | |
2797 | Append (Ref, Result); | |
2798 | end if; | |
2799 | end; | |
2800 | end if; | |
2801 | ||
fbf5a39b AC |
2802 | -- The equivalent type associated with a class-wide subtype |
2803 | -- needs to be frozen to ensure that its layout is done. | |
2804 | -- Class-wide subtypes are currently only frozen on targets | |
2805 | -- requiring front-end layout (see New_Class_Wide_Subtype | |
2806 | -- and Make_CW_Equivalent_Type in exp_util.adb). | |
2807 | ||
2808 | if Ekind (E) = E_Class_Wide_Subtype | |
2809 | and then Present (Equivalent_Type (E)) | |
2810 | then | |
2811 | Freeze_And_Append (Equivalent_Type (E), Loc, Result); | |
2812 | end if; | |
2813 | ||
2814 | -- For a record (sub)type, freeze all the component types (RM | |
2815 | -- 13.14(15). We test for E_Record_(sub)Type here, rather than | |
70482933 RK |
2816 | -- using Is_Record_Type, because we don't want to attempt the |
2817 | -- freeze for the case of a private type with record extension | |
2818 | -- (we will do that later when the full type is frozen). | |
2819 | ||
2820 | elsif Ekind (E) = E_Record_Type | |
2821 | or else Ekind (E) = E_Record_Subtype | |
2822 | then | |
2823 | Freeze_Record_Type (E); | |
2824 | ||
2825 | -- For a concurrent type, freeze corresponding record type. This | |
2826 | -- does not correpond to any specific rule in the RM, but the | |
2827 | -- record type is essentially part of the concurrent type. | |
2828 | -- Freeze as well all local entities. This includes record types | |
2829 | -- created for entry parameter blocks, and whatever local entities | |
2830 | -- may appear in the private part. | |
2831 | ||
2832 | elsif Is_Concurrent_Type (E) then | |
2833 | if Present (Corresponding_Record_Type (E)) then | |
2834 | Freeze_And_Append | |
2835 | (Corresponding_Record_Type (E), Loc, Result); | |
2836 | end if; | |
2837 | ||
2838 | Comp := First_Entity (E); | |
2839 | ||
2840 | while Present (Comp) loop | |
2841 | if Is_Type (Comp) then | |
2842 | Freeze_And_Append (Comp, Loc, Result); | |
2843 | ||
2844 | elsif (Ekind (Comp)) /= E_Function then | |
c6823a20 EB |
2845 | if Is_Itype (Etype (Comp)) |
2846 | and then Underlying_Type (Scope (Etype (Comp))) = E | |
2847 | then | |
2848 | Undelay_Type (Etype (Comp)); | |
2849 | end if; | |
2850 | ||
70482933 RK |
2851 | Freeze_And_Append (Etype (Comp), Loc, Result); |
2852 | end if; | |
2853 | ||
2854 | Next_Entity (Comp); | |
2855 | end loop; | |
2856 | ||
2857 | -- Private types are required to point to the same freeze node | |
2858 | -- as their corresponding full views. The freeze node itself | |
2859 | -- has to point to the partial view of the entity (because | |
2860 | -- from the partial view, we can retrieve the full view, but | |
2861 | -- not the reverse). However, in order to freeze correctly, | |
2862 | -- we need to freeze the full view. If we are freezing at the | |
2863 | -- end of a scope (or within the scope of the private type), | |
2864 | -- the partial and full views will have been swapped, the | |
2865 | -- full view appears first in the entity chain and the swapping | |
fbf5a39b | 2866 | -- mechanism ensures that the pointers are properly set (on |
70482933 RK |
2867 | -- scope exit). |
2868 | ||
2869 | -- If we encounter the partial view before the full view | |
2870 | -- (e.g. when freezing from another scope), we freeze the | |
2871 | -- full view, and then set the pointers appropriately since | |
2872 | -- we cannot rely on swapping to fix things up (subtypes in an | |
2873 | -- outer scope might not get swapped). | |
2874 | ||
2875 | elsif Is_Incomplete_Or_Private_Type (E) | |
2876 | and then not Is_Generic_Type (E) | |
2877 | then | |
2878 | -- Case of full view present | |
2879 | ||
2880 | if Present (Full_View (E)) then | |
2881 | ||
2882 | -- If full view has already been frozen, then no | |
2883 | -- further processing is required | |
2884 | ||
2885 | if Is_Frozen (Full_View (E)) then | |
2886 | ||
2887 | Set_Has_Delayed_Freeze (E, False); | |
2888 | Set_Freeze_Node (E, Empty); | |
2889 | Check_Debug_Info_Needed (E); | |
2890 | ||
2891 | -- Otherwise freeze full view and patch the pointers | |
fbf5a39b AC |
2892 | -- so that the freeze node will elaborate both views |
2893 | -- in the back-end. | |
70482933 RK |
2894 | |
2895 | else | |
fbf5a39b AC |
2896 | declare |
2897 | Full : constant Entity_Id := Full_View (E); | |
70482933 | 2898 | |
fbf5a39b AC |
2899 | begin |
2900 | if Is_Private_Type (Full) | |
2901 | and then Present (Underlying_Full_View (Full)) | |
2902 | then | |
2903 | Freeze_And_Append | |
2904 | (Underlying_Full_View (Full), Loc, Result); | |
2905 | end if; | |
70482933 | 2906 | |
fbf5a39b | 2907 | Freeze_And_Append (Full, Loc, Result); |
70482933 | 2908 | |
fbf5a39b AC |
2909 | if Has_Delayed_Freeze (E) then |
2910 | F_Node := Freeze_Node (Full); | |
70482933 | 2911 | |
fbf5a39b AC |
2912 | if Present (F_Node) then |
2913 | Set_Freeze_Node (E, F_Node); | |
2914 | Set_Entity (F_Node, E); | |
2915 | ||
2916 | else | |
2917 | -- {Incomplete,Private}_Subtypes | |
2918 | -- with Full_Views constrained by discriminants | |
2919 | ||
2920 | Set_Has_Delayed_Freeze (E, False); | |
2921 | Set_Freeze_Node (E, Empty); | |
2922 | end if; | |
70482933 | 2923 | end if; |
fbf5a39b | 2924 | end; |
70482933 RK |
2925 | |
2926 | Check_Debug_Info_Needed (E); | |
2927 | end if; | |
2928 | ||
2929 | -- AI-117 requires that the convention of a partial view | |
2930 | -- be the same as the convention of the full view. Note | |
2931 | -- that this is a recognized breach of privacy, but it's | |
2932 | -- essential for logical consistency of representation, | |
2933 | -- and the lack of a rule in RM95 was an oversight. | |
2934 | ||
2935 | Set_Convention (E, Convention (Full_View (E))); | |
2936 | ||
2937 | Set_Size_Known_At_Compile_Time (E, | |
2938 | Size_Known_At_Compile_Time (Full_View (E))); | |
2939 | ||
2940 | -- Size information is copied from the full view to the | |
2941 | -- incomplete or private view for consistency | |
2942 | ||
2943 | -- We skip this is the full view is not a type. This is | |
2944 | -- very strange of course, and can only happen as a result | |
2945 | -- of certain illegalities, such as a premature attempt to | |
2946 | -- derive from an incomplete type. | |
2947 | ||
2948 | if Is_Type (Full_View (E)) then | |
2949 | Set_Size_Info (E, Full_View (E)); | |
2950 | Set_RM_Size (E, RM_Size (Full_View (E))); | |
2951 | end if; | |
2952 | ||
2953 | return Result; | |
2954 | ||
2955 | -- Case of no full view present. If entity is derived or subtype, | |
2956 | -- it is safe to freeze, correctness depends on the frozen status | |
2957 | -- of parent. Otherwise it is either premature usage, or a Taft | |
2958 | -- amendment type, so diagnosis is at the point of use and the | |
2959 | -- type might be frozen later. | |
2960 | ||
2961 | elsif E /= Base_Type (E) | |
2962 | or else Is_Derived_Type (E) | |
2963 | then | |
2964 | null; | |
2965 | ||
2966 | else | |
2967 | Set_Is_Frozen (E, False); | |
2968 | return No_List; | |
2969 | end if; | |
2970 | ||
2971 | -- For access subprogram, freeze types of all formals, the return | |
2972 | -- type was already frozen, since it is the Etype of the function. | |
2973 | ||
2974 | elsif Ekind (E) = E_Subprogram_Type then | |
2975 | Formal := First_Formal (E); | |
2976 | while Present (Formal) loop | |
2977 | Freeze_And_Append (Etype (Formal), Loc, Result); | |
2978 | Next_Formal (Formal); | |
2979 | end loop; | |
2980 | ||
2981 | -- If the return type requires a transient scope, and we are on | |
2982 | -- a target allowing functions to return with a depressed stack | |
2983 | -- pointer, then we mark the function as requiring this treatment. | |
2984 | ||
2985 | if Functions_Return_By_DSP_On_Target | |
2986 | and then Requires_Transient_Scope (Etype (E)) | |
2987 | then | |
2988 | Set_Function_Returns_With_DSP (E); | |
2989 | end if; | |
2990 | ||
2991 | Freeze_Subprogram (E); | |
2992 | ||
d8db0bca JM |
2993 | -- AI-326: Check wrong use of tag incomplete type |
2994 | -- | |
2995 | -- type T is tagged; | |
2996 | -- type Acc is access function (X : T) return T; -- ERROR | |
2997 | ||
2998 | if Ekind (Etype (E)) = E_Incomplete_Type | |
2999 | and then Is_Tagged_Type (Etype (E)) | |
3000 | and then No (Full_View (Etype (E))) | |
3001 | then | |
3002 | Error_Msg_N | |
3003 | ("(Ada 2005): invalid use of tagged incomplete type", E); | |
3004 | end if; | |
3005 | ||
70482933 | 3006 | -- For access to a protected subprogram, freeze the equivalent |
57747aec | 3007 | -- type (however this is not set if we are not generating code |
70482933 RK |
3008 | -- or if this is an anonymous type used just for resolution). |
3009 | ||
d8db0bca JM |
3010 | elsif Ekind (E) = E_Access_Protected_Subprogram_Type then |
3011 | ||
3012 | -- AI-326: Check wrong use of tagged incomplete types | |
3013 | ||
3014 | -- type T is tagged; | |
3015 | -- type As3D is access protected | |
3016 | -- function (X : Float) return T; -- ERROR | |
3017 | ||
3018 | declare | |
3019 | Etyp : Entity_Id; | |
3020 | ||
3021 | begin | |
3022 | Etyp := Etype (Directly_Designated_Type (E)); | |
3023 | ||
3024 | if Is_Class_Wide_Type (Etyp) then | |
3025 | Etyp := Etype (Etyp); | |
3026 | end if; | |
3027 | ||
3028 | if Ekind (Etyp) = E_Incomplete_Type | |
3029 | and then Is_Tagged_Type (Etyp) | |
3030 | and then No (Full_View (Etyp)) | |
3031 | then | |
3032 | Error_Msg_N | |
3033 | ("(Ada 2005): invalid use of tagged incomplete type", E); | |
3034 | end if; | |
3035 | end; | |
3036 | ||
57747aec | 3037 | if Present (Equivalent_Type (E)) then |
d8db0bca JM |
3038 | Freeze_And_Append (Equivalent_Type (E), Loc, Result); |
3039 | end if; | |
70482933 RK |
3040 | end if; |
3041 | ||
3042 | -- Generic types are never seen by the back-end, and are also not | |
3043 | -- processed by the expander (since the expander is turned off for | |
3044 | -- generic processing), so we never need freeze nodes for them. | |
3045 | ||
3046 | if Is_Generic_Type (E) then | |
3047 | return Result; | |
3048 | end if; | |
3049 | ||
3050 | -- Some special processing for non-generic types to complete | |
3051 | -- representation details not known till the freeze point. | |
3052 | ||
3053 | if Is_Fixed_Point_Type (E) then | |
3054 | Freeze_Fixed_Point_Type (E); | |
3055 | ||
fbf5a39b AC |
3056 | -- Some error checks required for ordinary fixed-point type. |
3057 | -- Defer these till the freeze-point since we need the small | |
3058 | -- and range values. We only do these checks for base types | |
3059 | ||
3060 | if Is_Ordinary_Fixed_Point_Type (E) | |
3061 | and then E = Base_Type (E) | |
3062 | then | |
3063 | if Small_Value (E) < Ureal_2_M_80 then | |
3064 | Error_Msg_Name_1 := Name_Small; | |
3065 | Error_Msg_N | |
3066 | ("`&''%` is too small, minimum is 2.0'*'*(-80)", E); | |
3067 | ||
3068 | elsif Small_Value (E) > Ureal_2_80 then | |
3069 | Error_Msg_Name_1 := Name_Small; | |
3070 | Error_Msg_N | |
3071 | ("`&''%` is too large, maximum is 2.0'*'*80", E); | |
3072 | end if; | |
3073 | ||
3074 | if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then | |
3075 | Error_Msg_Name_1 := Name_First; | |
3076 | Error_Msg_N | |
3077 | ("`&''%` is too small, minimum is -10.0'*'*36", E); | |
3078 | end if; | |
3079 | ||
3080 | if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then | |
3081 | Error_Msg_Name_1 := Name_Last; | |
3082 | Error_Msg_N | |
3083 | ("`&''%` is too large, maximum is 10.0'*'*36", E); | |
3084 | end if; | |
3085 | end if; | |
3086 | ||
70482933 RK |
3087 | elsif Is_Enumeration_Type (E) then |
3088 | Freeze_Enumeration_Type (E); | |
3089 | ||
3090 | elsif Is_Integer_Type (E) then | |
3091 | Adjust_Esize_For_Alignment (E); | |
3092 | ||
edd63e9b ES |
3093 | elsif Is_Access_Type (E) then |
3094 | ||
3095 | -- Check restriction for standard storage pool | |
3096 | ||
3097 | if No (Associated_Storage_Pool (E)) then | |
3098 | Check_Restriction (No_Standard_Storage_Pools, E); | |
3099 | end if; | |
3100 | ||
3101 | -- Deal with error message for pure access type. This is not an | |
3102 | -- error in Ada 2005 if there is no pool (see AI-366). | |
3103 | ||
3104 | if Is_Pure_Unit_Access_Type (E) | |
3105 | and then (Ada_Version < Ada_05 | |
3106 | or else not No_Pool_Assigned (E)) | |
3107 | then | |
3108 | Error_Msg_N ("named access type not allowed in pure unit", E); | |
3109 | end if; | |
70482933 RK |
3110 | end if; |
3111 | ||
edd63e9b ES |
3112 | -- Case of composite types |
3113 | ||
70482933 RK |
3114 | if Is_Composite_Type (E) then |
3115 | ||
edd63e9b ES |
3116 | -- AI-117 requires that all new primitives of a tagged type must |
3117 | -- inherit the convention of the full view of the type. Inherited | |
3118 | -- and overriding operations are defined to inherit the convention | |
3119 | -- of their parent or overridden subprogram (also specified in | |
3120 | -- AI-117), and that will have occurred earlier (in | |
3121 | -- Derive_Subprogram and New_Overloaded_Entity). Here we set the | |
3122 | -- convention of primitives that are still convention Ada, which | |
3123 | -- will ensure that any new primitives inherit the type's | |
3124 | -- convention. Class-wide types can have a foreign convention | |
3125 | -- inherited from their specific type, but are excluded from this | |
3126 | -- since they don't have any associated primitives. | |
70482933 RK |
3127 | |
3128 | if Is_Tagged_Type (E) | |
3129 | and then not Is_Class_Wide_Type (E) | |
3130 | and then Convention (E) /= Convention_Ada | |
3131 | then | |
3132 | declare | |
3133 | Prim_List : constant Elist_Id := Primitive_Operations (E); | |
07fc65c4 | 3134 | Prim : Elmt_Id; |
70482933 | 3135 | begin |
07fc65c4 | 3136 | Prim := First_Elmt (Prim_List); |
70482933 RK |
3137 | while Present (Prim) loop |
3138 | if Convention (Node (Prim)) = Convention_Ada then | |
3139 | Set_Convention (Node (Prim), Convention (E)); | |
3140 | end if; | |
3141 | ||
3142 | Next_Elmt (Prim); | |
3143 | end loop; | |
3144 | end; | |
3145 | end if; | |
3146 | end if; | |
3147 | ||
07fc65c4 GB |
3148 | -- Generate primitive operation references for a tagged type |
3149 | ||
3150 | if Is_Tagged_Type (E) | |
3151 | and then not Is_Class_Wide_Type (E) | |
3152 | then | |
3153 | declare | |
edd63e9b | 3154 | Prim_List : Elist_Id; |
07fc65c4 GB |
3155 | Prim : Elmt_Id; |
3156 | Ent : Entity_Id; | |
3157 | ||
3158 | begin | |
edd63e9b ES |
3159 | -- Ada 2005 (AI-345): In case of concurrent type generate |
3160 | -- reference to the wrapper that allow us to dispatch calls | |
3161 | -- through their implemented abstract interface types. | |
3162 | ||
3163 | -- The check for Present here is to protect against previously | |
3164 | -- reported critical errors. | |
3165 | ||
3166 | if Is_Concurrent_Type (E) | |
3167 | and then Present (Corresponding_Record_Type (E)) | |
3168 | then | |
3169 | pragma Assert (not Is_Empty_Elmt_List | |
3170 | (Abstract_Interfaces | |
3171 | (Corresponding_Record_Type (E)))); | |
3172 | ||
3173 | Prim_List := Primitive_Operations | |
3174 | (Corresponding_Record_Type (E)); | |
3175 | else | |
3176 | Prim_List := Primitive_Operations (E); | |
3177 | end if; | |
3178 | ||
3179 | -- Loop to generate references for primitive operations | |
3180 | ||
07fc65c4 GB |
3181 | Prim := First_Elmt (Prim_List); |
3182 | while Present (Prim) loop | |
3183 | Ent := Node (Prim); | |
3184 | ||
edd63e9b ES |
3185 | -- If the operation is derived, get the original for cross- |
3186 | -- reference purposes (it is the original for which we want | |
3187 | -- the xref, and for which the comes from source test needs | |
3188 | -- to be performed). | |
07fc65c4 GB |
3189 | |
3190 | while Present (Alias (Ent)) loop | |
3191 | Ent := Alias (Ent); | |
3192 | end loop; | |
3193 | ||
3194 | Generate_Reference (E, Ent, 'p', Set_Ref => False); | |
3195 | Next_Elmt (Prim); | |
3196 | end loop; | |
3197 | ||
3198 | -- If we get an exception, then something peculiar has happened | |
3199 | -- probably as a result of a previous error. Since this is only | |
3200 | -- for non-critical cross-references, ignore the error. | |
3201 | ||
3202 | exception | |
3203 | when others => null; | |
3204 | end; | |
3205 | end if; | |
3206 | ||
70482933 RK |
3207 | -- Now that all types from which E may depend are frozen, see |
3208 | -- if the size is known at compile time, if it must be unsigned, | |
3209 | -- or if strict alignent is required | |
3210 | ||
3211 | Check_Compile_Time_Size (E); | |
3212 | Check_Unsigned_Type (E); | |
3213 | ||
3214 | if Base_Type (E) = E then | |
3215 | Check_Strict_Alignment (E); | |
3216 | end if; | |
3217 | ||
3218 | -- Do not allow a size clause for a type which does not have a size | |
3219 | -- that is known at compile time | |
3220 | ||
3221 | if Has_Size_Clause (E) | |
3222 | and then not Size_Known_At_Compile_Time (E) | |
3223 | then | |
07fc65c4 GB |
3224 | -- Supress this message if errors posted on E, even if we are |
3225 | -- in all errors mode, since this is often a junk message | |
3226 | ||
3227 | if not Error_Posted (E) then | |
3228 | Error_Msg_N | |
3229 | ("size clause not allowed for variable length type", | |
3230 | Size_Clause (E)); | |
3231 | end if; | |
70482933 RK |
3232 | end if; |
3233 | ||
3234 | -- Remaining process is to set/verify the representation information, | |
3235 | -- in particular the size and alignment values. This processing is | |
3236 | -- not required for generic types, since generic types do not play | |
3237 | -- any part in code generation, and so the size and alignment values | |
c6823a20 | 3238 | -- for such types are irrelevant. |
70482933 RK |
3239 | |
3240 | if Is_Generic_Type (E) then | |
3241 | return Result; | |
3242 | ||
3243 | -- Otherwise we call the layout procedure | |
3244 | ||
3245 | else | |
3246 | Layout_Type (E); | |
3247 | end if; | |
3248 | ||
3249 | -- End of freeze processing for type entities | |
3250 | end if; | |
3251 | ||
3252 | -- Here is where we logically freeze the current entity. If it has a | |
3253 | -- freeze node, then this is the point at which the freeze node is | |
3254 | -- linked into the result list. | |
3255 | ||
3256 | if Has_Delayed_Freeze (E) then | |
3257 | ||
3258 | -- If a freeze node is already allocated, use it, otherwise allocate | |
3259 | -- a new one. The preallocation happens in the case of anonymous base | |
3260 | -- types, where we preallocate so that we can set First_Subtype_Link. | |
3261 | -- Note that we reset the Sloc to the current freeze location. | |
3262 | ||
3263 | if Present (Freeze_Node (E)) then | |
3264 | F_Node := Freeze_Node (E); | |
3265 | Set_Sloc (F_Node, Loc); | |
3266 | ||
3267 | else | |
3268 | F_Node := New_Node (N_Freeze_Entity, Loc); | |
3269 | Set_Freeze_Node (E, F_Node); | |
3270 | Set_Access_Types_To_Process (F_Node, No_Elist); | |
3271 | Set_TSS_Elist (F_Node, No_Elist); | |
3272 | Set_Actions (F_Node, No_List); | |
3273 | end if; | |
3274 | ||
3275 | Set_Entity (F_Node, E); | |
3276 | ||
3277 | if Result = No_List then | |
3278 | Result := New_List (F_Node); | |
3279 | else | |
3280 | Append (F_Node, Result); | |
3281 | end if; | |
35ae2ed8 AC |
3282 | |
3283 | -- A final pass over record types with discriminants. If the type | |
3284 | -- has an incomplete declaration, there may be constrained access | |
3285 | -- subtypes declared elsewhere, which do not depend on the discrimi- | |
3286 | -- nants of the type, and which are used as component types (i.e. | |
3287 | -- the full view is a recursive type). The designated types of these | |
3288 | -- subtypes can only be elaborated after the type itself, and they | |
3289 | -- need an itype reference. | |
3290 | ||
3291 | if Ekind (E) = E_Record_Type | |
3292 | and then Has_Discriminants (E) | |
3293 | then | |
3294 | declare | |
3295 | Comp : Entity_Id; | |
3296 | IR : Node_Id; | |
3297 | Typ : Entity_Id; | |
3298 | ||
3299 | begin | |
3300 | Comp := First_Component (E); | |
3301 | ||
3302 | while Present (Comp) loop | |
3303 | Typ := Etype (Comp); | |
3304 | ||
3305 | if Ekind (Comp) = E_Component | |
3306 | and then Is_Access_Type (Typ) | |
3307 | and then Scope (Typ) /= E | |
3308 | and then Base_Type (Designated_Type (Typ)) = E | |
3309 | and then Is_Itype (Designated_Type (Typ)) | |
3310 | then | |
3311 | IR := Make_Itype_Reference (Sloc (Comp)); | |
3312 | Set_Itype (IR, Designated_Type (Typ)); | |
3313 | Append (IR, Result); | |
3314 | end if; | |
3315 | ||
3316 | Next_Component (Comp); | |
3317 | end loop; | |
3318 | end; | |
3319 | end if; | |
70482933 RK |
3320 | end if; |
3321 | ||
3322 | -- When a type is frozen, the first subtype of the type is frozen as | |
3323 | -- well (RM 13.14(15)). This has to be done after freezing the type, | |
3324 | -- since obviously the first subtype depends on its own base type. | |
3325 | ||
3326 | if Is_Type (E) then | |
3327 | Freeze_And_Append (First_Subtype (E), Loc, Result); | |
3328 | ||
3329 | -- If we just froze a tagged non-class wide record, then freeze the | |
3330 | -- corresponding class-wide type. This must be done after the tagged | |
3331 | -- type itself is frozen, because the class-wide type refers to the | |
3332 | -- tagged type which generates the class. | |
3333 | ||
3334 | if Is_Tagged_Type (E) | |
3335 | and then not Is_Class_Wide_Type (E) | |
3336 | and then Present (Class_Wide_Type (E)) | |
3337 | then | |
3338 | Freeze_And_Append (Class_Wide_Type (E), Loc, Result); | |
3339 | end if; | |
3340 | end if; | |
3341 | ||
3342 | Check_Debug_Info_Needed (E); | |
3343 | ||
3344 | -- Special handling for subprograms | |
3345 | ||
3346 | if Is_Subprogram (E) then | |
3347 | ||
3348 | -- If subprogram has address clause then reset Is_Public flag, since | |
3349 | -- we do not want the backend to generate external references. | |
3350 | ||
3351 | if Present (Address_Clause (E)) | |
3352 | and then not Is_Library_Level_Entity (E) | |
3353 | then | |
3354 | Set_Is_Public (E, False); | |
3355 | ||
3356 | -- If no address clause and not intrinsic, then for imported | |
3357 | -- subprogram in main unit, generate descriptor if we are in | |
3358 | -- Propagate_Exceptions mode. | |
3359 | ||
3360 | elsif Propagate_Exceptions | |
3361 | and then Is_Imported (E) | |
3362 | and then not Is_Intrinsic_Subprogram (E) | |
3363 | and then Convention (E) /= Convention_Stubbed | |
3364 | then | |
3365 | if Result = No_List then | |
3366 | Result := Empty_List; | |
3367 | end if; | |
70482933 | 3368 | end if; |
70482933 RK |
3369 | end if; |
3370 | ||
3371 | return Result; | |
3372 | end Freeze_Entity; | |
3373 | ||
3374 | ----------------------------- | |
3375 | -- Freeze_Enumeration_Type -- | |
3376 | ----------------------------- | |
3377 | ||
3378 | procedure Freeze_Enumeration_Type (Typ : Entity_Id) is | |
3379 | begin | |
3380 | if Has_Foreign_Convention (Typ) | |
3381 | and then not Has_Size_Clause (Typ) | |
3382 | and then Esize (Typ) < Standard_Integer_Size | |
3383 | then | |
3384 | Init_Esize (Typ, Standard_Integer_Size); | |
70482933 RK |
3385 | else |
3386 | Adjust_Esize_For_Alignment (Typ); | |
3387 | end if; | |
3388 | end Freeze_Enumeration_Type; | |
3389 | ||
3390 | ----------------------- | |
3391 | -- Freeze_Expression -- | |
3392 | ----------------------- | |
3393 | ||
3394 | procedure Freeze_Expression (N : Node_Id) is | |
3395 | In_Def_Exp : constant Boolean := In_Default_Expression; | |
3396 | Typ : Entity_Id; | |
3397 | Nam : Entity_Id; | |
3398 | Desig_Typ : Entity_Id; | |
3399 | P : Node_Id; | |
3400 | Parent_P : Node_Id; | |
3401 | ||
3402 | Freeze_Outside : Boolean := False; | |
3403 | -- This flag is set true if the entity must be frozen outside the | |
3404 | -- current subprogram. This happens in the case of expander generated | |
3405 | -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do | |
3406 | -- not freeze all entities like other bodies, but which nevertheless | |
3407 | -- may reference entities that have to be frozen before the body and | |
3408 | -- obviously cannot be frozen inside the body. | |
3409 | ||
3410 | function In_Exp_Body (N : Node_Id) return Boolean; | |
3411 | -- Given an N_Handled_Sequence_Of_Statements node N, determines whether | |
c6823a20 | 3412 | -- it is the handled statement sequence of an expander-generated |
70482933 RK |
3413 | -- subprogram (init proc, or stream subprogram). If so, it returns |
3414 | -- True, otherwise False. | |
3415 | ||
fbf5a39b AC |
3416 | ----------------- |
3417 | -- In_Exp_Body -- | |
3418 | ----------------- | |
3419 | ||
70482933 RK |
3420 | function In_Exp_Body (N : Node_Id) return Boolean is |
3421 | P : Node_Id; | |
3422 | ||
3423 | begin | |
3424 | if Nkind (N) = N_Subprogram_Body then | |
3425 | P := N; | |
3426 | else | |
3427 | P := Parent (N); | |
3428 | end if; | |
3429 | ||
3430 | if Nkind (P) /= N_Subprogram_Body then | |
3431 | return False; | |
3432 | ||
3433 | else | |
3434 | P := Defining_Unit_Name (Specification (P)); | |
3435 | ||
3436 | if Nkind (P) = N_Defining_Identifier | |
fbf5a39b AC |
3437 | and then (Is_Init_Proc (P) or else |
3438 | Is_TSS (P, TSS_Stream_Input) or else | |
3439 | Is_TSS (P, TSS_Stream_Output) or else | |
3440 | Is_TSS (P, TSS_Stream_Read) or else | |
3441 | Is_TSS (P, TSS_Stream_Write)) | |
70482933 RK |
3442 | then |
3443 | return True; | |
3444 | else | |
3445 | return False; | |
3446 | end if; | |
3447 | end if; | |
70482933 RK |
3448 | end In_Exp_Body; |
3449 | ||
3450 | -- Start of processing for Freeze_Expression | |
3451 | ||
3452 | begin | |
edd63e9b ES |
3453 | -- Immediate return if freezing is inhibited. This flag is set by the |
3454 | -- analyzer to stop freezing on generated expressions that would cause | |
3455 | -- freezing if they were in the source program, but which are not | |
3456 | -- supposed to freeze, since they are created. | |
70482933 RK |
3457 | |
3458 | if Must_Not_Freeze (N) then | |
3459 | return; | |
3460 | end if; | |
3461 | ||
3462 | -- If expression is non-static, then it does not freeze in a default | |
3463 | -- expression, see section "Handling of Default Expressions" in the | |
3464 | -- spec of package Sem for further details. Note that we have to | |
3465 | -- make sure that we actually have a real expression (if we have | |
3466 | -- a subtype indication, we can't test Is_Static_Expression!) | |
3467 | ||
3468 | if In_Def_Exp | |
3469 | and then Nkind (N) in N_Subexpr | |
3470 | and then not Is_Static_Expression (N) | |
3471 | then | |
3472 | return; | |
3473 | end if; | |
3474 | ||
3475 | -- Freeze type of expression if not frozen already | |
3476 | ||
fbf5a39b AC |
3477 | Typ := Empty; |
3478 | ||
3479 | if Nkind (N) in N_Has_Etype then | |
3480 | if not Is_Frozen (Etype (N)) then | |
3481 | Typ := Etype (N); | |
3482 | ||
3483 | -- Base type may be an derived numeric type that is frozen at | |
3484 | -- the point of declaration, but first_subtype is still unfrozen. | |
3485 | ||
3486 | elsif not Is_Frozen (First_Subtype (Etype (N))) then | |
3487 | Typ := First_Subtype (Etype (N)); | |
3488 | end if; | |
70482933 RK |
3489 | end if; |
3490 | ||
3491 | -- For entity name, freeze entity if not frozen already. A special | |
3492 | -- exception occurs for an identifier that did not come from source. | |
3493 | -- We don't let such identifiers freeze a non-internal entity, i.e. | |
3494 | -- an entity that did come from source, since such an identifier was | |
3495 | -- generated by the expander, and cannot have any semantic effect on | |
3496 | -- the freezing semantics. For example, this stops the parameter of | |
3497 | -- an initialization procedure from freezing the variable. | |
3498 | ||
3499 | if Is_Entity_Name (N) | |
3500 | and then not Is_Frozen (Entity (N)) | |
3501 | and then (Nkind (N) /= N_Identifier | |
3502 | or else Comes_From_Source (N) | |
3503 | or else not Comes_From_Source (Entity (N))) | |
3504 | then | |
3505 | Nam := Entity (N); | |
70482933 RK |
3506 | else |
3507 | Nam := Empty; | |
3508 | end if; | |
3509 | ||
49e90211 | 3510 | -- For an allocator freeze designated type if not frozen already |
70482933 RK |
3511 | |
3512 | -- For an aggregate whose component type is an access type, freeze | |
3513 | -- the designated type now, so that its freeze does not appear within | |
3514 | -- the loop that might be created in the expansion of the aggregate. | |
3515 | -- If the designated type is a private type without full view, the | |
3516 | -- expression cannot contain an allocator, so the type is not frozen. | |
3517 | ||
3518 | Desig_Typ := Empty; | |
70482933 | 3519 | |
fbf5a39b | 3520 | case Nkind (N) is |
70482933 RK |
3521 | when N_Allocator => |
3522 | Desig_Typ := Designated_Type (Etype (N)); | |
3523 | ||
3524 | when N_Aggregate => | |
3525 | if Is_Array_Type (Etype (N)) | |
3526 | and then Is_Access_Type (Component_Type (Etype (N))) | |
3527 | then | |
3528 | Desig_Typ := Designated_Type (Component_Type (Etype (N))); | |
3529 | end if; | |
3530 | ||
3531 | when N_Selected_Component | | |
3532 | N_Indexed_Component | | |
3533 | N_Slice => | |
3534 | ||
3535 | if Is_Access_Type (Etype (Prefix (N))) then | |
3536 | Desig_Typ := Designated_Type (Etype (Prefix (N))); | |
3537 | end if; | |
3538 | ||
3539 | when others => | |
3540 | null; | |
70482933 RK |
3541 | end case; |
3542 | ||
3543 | if Desig_Typ /= Empty | |
3544 | and then (Is_Frozen (Desig_Typ) | |
3545 | or else (not Is_Fully_Defined (Desig_Typ))) | |
3546 | then | |
3547 | Desig_Typ := Empty; | |
3548 | end if; | |
3549 | ||
3550 | -- All done if nothing needs freezing | |
3551 | ||
3552 | if No (Typ) | |
3553 | and then No (Nam) | |
3554 | and then No (Desig_Typ) | |
3555 | then | |
3556 | return; | |
3557 | end if; | |
3558 | ||
3559 | -- Loop for looking at the right place to insert the freeze nodes | |
3560 | -- exiting from the loop when it is appropriate to insert the freeze | |
3561 | -- node before the current node P. | |
3562 | ||
3563 | -- Also checks some special exceptions to the freezing rules. These | |
3564 | -- cases result in a direct return, bypassing the freeze action. | |
3565 | ||
3566 | P := N; | |
3567 | loop | |
3568 | Parent_P := Parent (P); | |
3569 | ||
3570 | -- If we don't have a parent, then we are not in a well-formed | |
3571 | -- tree. This is an unusual case, but there are some legitimate | |
3572 | -- situations in which this occurs, notably when the expressions | |
3573 | -- in the range of a type declaration are resolved. We simply | |
3574 | -- ignore the freeze request in this case. Is this right ??? | |
3575 | ||
3576 | if No (Parent_P) then | |
3577 | return; | |
3578 | end if; | |
3579 | ||
3580 | -- See if we have got to an appropriate point in the tree | |
3581 | ||
3582 | case Nkind (Parent_P) is | |
3583 | ||
edd63e9b ES |
3584 | -- A special test for the exception of (RM 13.14(8)) for the case |
3585 | -- of per-object expressions (RM 3.8(18)) occurring in component | |
3586 | -- definition or a discrete subtype definition. Note that we test | |
3587 | -- for a component declaration which includes both cases we are | |
3588 | -- interested in, and furthermore the tree does not have explicit | |
3589 | -- nodes for either of these two constructs. | |
70482933 RK |
3590 | |
3591 | when N_Component_Declaration => | |
3592 | ||
3593 | -- The case we want to test for here is an identifier that is | |
3594 | -- a per-object expression, this is either a discriminant that | |
3595 | -- appears in a context other than the component declaration | |
3596 | -- or it is a reference to the type of the enclosing construct. | |
3597 | ||
3598 | -- For either of these cases, we skip the freezing | |
3599 | ||
3600 | if not In_Default_Expression | |
3601 | and then Nkind (N) = N_Identifier | |
3602 | and then (Present (Entity (N))) | |
3603 | then | |
3604 | -- We recognize the discriminant case by just looking for | |
3605 | -- a reference to a discriminant. It can only be one for | |
3606 | -- the enclosing construct. Skip freezing in this case. | |
3607 | ||
3608 | if Ekind (Entity (N)) = E_Discriminant then | |
3609 | return; | |
3610 | ||
3611 | -- For the case of a reference to the enclosing record, | |
3612 | -- (or task or protected type), we look for a type that | |
3613 | -- matches the current scope. | |
3614 | ||
3615 | elsif Entity (N) = Current_Scope then | |
3616 | return; | |
3617 | end if; | |
3618 | end if; | |
3619 | ||
edd63e9b ES |
3620 | -- If we have an enumeration literal that appears as the choice in |
3621 | -- the aggregate of an enumeration representation clause, then | |
3622 | -- freezing does not occur (RM 13.14(10)). | |
70482933 RK |
3623 | |
3624 | when N_Enumeration_Representation_Clause => | |
3625 | ||
3626 | -- The case we are looking for is an enumeration literal | |
3627 | ||
3628 | if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal) | |
3629 | and then Is_Enumeration_Type (Etype (N)) | |
3630 | then | |
3631 | -- If enumeration literal appears directly as the choice, | |
3632 | -- do not freeze (this is the normal non-overloade case) | |
3633 | ||
3634 | if Nkind (Parent (N)) = N_Component_Association | |
3635 | and then First (Choices (Parent (N))) = N | |
3636 | then | |
3637 | return; | |
3638 | ||
3639 | -- If enumeration literal appears as the name of a | |
3640 | -- function which is the choice, then also do not freeze. | |
3641 | -- This happens in the overloaded literal case, where the | |
3642 | -- enumeration literal is temporarily changed to a function | |
3643 | -- call for overloading analysis purposes. | |
3644 | ||
3645 | elsif Nkind (Parent (N)) = N_Function_Call | |
3646 | and then | |
3647 | Nkind (Parent (Parent (N))) = N_Component_Association | |
3648 | and then | |
3649 | First (Choices (Parent (Parent (N)))) = Parent (N) | |
3650 | then | |
3651 | return; | |
3652 | end if; | |
3653 | end if; | |
3654 | ||
3655 | -- Normally if the parent is a handled sequence of statements, | |
3656 | -- then the current node must be a statement, and that is an | |
3657 | -- appropriate place to insert a freeze node. | |
3658 | ||
3659 | when N_Handled_Sequence_Of_Statements => | |
3660 | ||
edd63e9b ES |
3661 | -- An exception occurs when the sequence of statements is for |
3662 | -- an expander generated body that did not do the usual freeze | |
3663 | -- all operation. In this case we usually want to freeze | |
3664 | -- outside this body, not inside it, and we skip past the | |
3665 | -- subprogram body that we are inside. | |
70482933 RK |
3666 | |
3667 | if In_Exp_Body (Parent_P) then | |
3668 | ||
3669 | -- However, we *do* want to freeze at this point if we have | |
3670 | -- an entity to freeze, and that entity is declared *inside* | |
3671 | -- the body of the expander generated procedure. This case | |
3672 | -- is recognized by the scope of the type, which is either | |
3673 | -- the spec for some enclosing body, or (in the case of | |
3674 | -- init_procs, for which there are no separate specs) the | |
3675 | -- current scope. | |
3676 | ||
3677 | declare | |
3678 | Subp : constant Node_Id := Parent (Parent_P); | |
3679 | Cspc : Entity_Id; | |
3680 | ||
3681 | begin | |
3682 | if Nkind (Subp) = N_Subprogram_Body then | |
3683 | Cspc := Corresponding_Spec (Subp); | |
3684 | ||
3685 | if (Present (Typ) and then Scope (Typ) = Cspc) | |
3686 | or else | |
3687 | (Present (Nam) and then Scope (Nam) = Cspc) | |
3688 | then | |
3689 | exit; | |
3690 | ||
3691 | elsif Present (Typ) | |
3692 | and then Scope (Typ) = Current_Scope | |
3693 | and then Current_Scope = Defining_Entity (Subp) | |
3694 | then | |
3695 | exit; | |
3696 | end if; | |
3697 | end if; | |
3698 | end; | |
3699 | ||
3700 | -- If not that exception to the exception, then this is | |
3701 | -- where we delay the freeze till outside the body. | |
3702 | ||
3703 | Parent_P := Parent (Parent_P); | |
3704 | Freeze_Outside := True; | |
3705 | ||
3706 | -- Here if normal case where we are in handled statement | |
3707 | -- sequence and want to do the insertion right there. | |
3708 | ||
3709 | else | |
3710 | exit; | |
3711 | end if; | |
3712 | ||
3713 | -- If parent is a body or a spec or a block, then the current | |
3714 | -- node is a statement or declaration and we can insert the | |
3715 | -- freeze node before it. | |
3716 | ||
3717 | when N_Package_Specification | | |
3718 | N_Package_Body | | |
3719 | N_Subprogram_Body | | |
3720 | N_Task_Body | | |
3721 | N_Protected_Body | | |
3722 | N_Entry_Body | | |
3723 | N_Block_Statement => exit; | |
3724 | ||
3725 | -- The expander is allowed to define types in any statements list, | |
3726 | -- so any of the following parent nodes also mark a freezing point | |
3727 | -- if the actual node is in a list of statements or declarations. | |
3728 | ||
3729 | when N_Exception_Handler | | |
3730 | N_If_Statement | | |
3731 | N_Elsif_Part | | |
3732 | N_Case_Statement_Alternative | | |
3733 | N_Compilation_Unit_Aux | | |
3734 | N_Selective_Accept | | |
3735 | N_Accept_Alternative | | |
3736 | N_Delay_Alternative | | |
3737 | N_Conditional_Entry_Call | | |
3738 | N_Entry_Call_Alternative | | |
3739 | N_Triggering_Alternative | | |
3740 | N_Abortable_Part | | |
3741 | N_Freeze_Entity => | |
3742 | ||
3743 | exit when Is_List_Member (P); | |
3744 | ||
3745 | -- Note: The N_Loop_Statement is a special case. A type that | |
3746 | -- appears in the source can never be frozen in a loop (this | |
edd63e9b ES |
3747 | -- occurs only because of a loop expanded by the expander), so we |
3748 | -- keep on going. Otherwise we terminate the search. Same is true | |
3749 | -- of any entity which comes from source. (if they have a | |
3750 | -- predefined type, that type does not appear to come from source, | |
3751 | -- but the entity should not be frozen here). | |
70482933 RK |
3752 | |
3753 | when N_Loop_Statement => | |
3754 | exit when not Comes_From_Source (Etype (N)) | |
3755 | and then (No (Nam) or else not Comes_From_Source (Nam)); | |
3756 | ||
3757 | -- For all other cases, keep looking at parents | |
3758 | ||
3759 | when others => | |
3760 | null; | |
3761 | end case; | |
3762 | ||
3763 | -- We fall through the case if we did not yet find the proper | |
3764 | -- place in the free for inserting the freeze node, so climb! | |
3765 | ||
3766 | P := Parent_P; | |
3767 | end loop; | |
3768 | ||
edd63e9b ES |
3769 | -- If the expression appears in a record or an initialization procedure, |
3770 | -- the freeze nodes are collected and attached to the current scope, to | |
3771 | -- be inserted and analyzed on exit from the scope, to insure that | |
3772 | -- generated entities appear in the correct scope. If the expression is | |
3773 | -- a default for a discriminant specification, the scope is still void. | |
3774 | -- The expression can also appear in the discriminant part of a private | |
3775 | -- or concurrent type. | |
70482933 | 3776 | |
c6823a20 | 3777 | -- If the expression appears in a constrained subcomponent of an |
edd63e9b ES |
3778 | -- enclosing record declaration, the freeze nodes must be attached to |
3779 | -- the outer record type so they can eventually be placed in the | |
c6823a20 EB |
3780 | -- enclosing declaration list. |
3781 | ||
70482933 RK |
3782 | -- The other case requiring this special handling is if we are in |
3783 | -- a default expression, since in that case we are about to freeze | |
3784 | -- a static type, and the freeze scope needs to be the outer scope, | |
3785 | -- not the scope of the subprogram with the default parameter. | |
3786 | ||
3787 | -- For default expressions in generic units, the Move_Freeze_Nodes | |
3788 | -- mechanism (see sem_ch12.adb) takes care of placing them at the | |
3789 | -- proper place, after the generic unit. | |
3790 | ||
3791 | if (In_Def_Exp and not Inside_A_Generic) | |
3792 | or else Freeze_Outside | |
3793 | or else (Is_Type (Current_Scope) | |
3794 | and then (not Is_Concurrent_Type (Current_Scope) | |
3795 | or else not Has_Completion (Current_Scope))) | |
3796 | or else Ekind (Current_Scope) = E_Void | |
3797 | then | |
3798 | declare | |
3799 | Loc : constant Source_Ptr := Sloc (Current_Scope); | |
3800 | Freeze_Nodes : List_Id := No_List; | |
c6823a20 | 3801 | Pos : Int := Scope_Stack.Last; |
70482933 RK |
3802 | |
3803 | begin | |
3804 | if Present (Desig_Typ) then | |
3805 | Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes); | |
3806 | end if; | |
3807 | ||
3808 | if Present (Typ) then | |
3809 | Freeze_And_Append (Typ, Loc, Freeze_Nodes); | |
3810 | end if; | |
3811 | ||
3812 | if Present (Nam) then | |
3813 | Freeze_And_Append (Nam, Loc, Freeze_Nodes); | |
3814 | end if; | |
3815 | ||
c6823a20 EB |
3816 | -- The current scope may be that of a constrained component of |
3817 | -- an enclosing record declaration, which is above the current | |
3818 | -- scope in the scope stack. | |
3819 | ||
3820 | if Is_Record_Type (Scope (Current_Scope)) then | |
3821 | Pos := Pos - 1; | |
3822 | end if; | |
3823 | ||
70482933 | 3824 | if Is_Non_Empty_List (Freeze_Nodes) then |
c6823a20 EB |
3825 | if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then |
3826 | Scope_Stack.Table (Pos).Pending_Freeze_Actions := | |
70482933 RK |
3827 | Freeze_Nodes; |
3828 | else | |
3829 | Append_List (Freeze_Nodes, Scope_Stack.Table | |
c6823a20 | 3830 | (Pos).Pending_Freeze_Actions); |
70482933 RK |
3831 | end if; |
3832 | end if; | |
3833 | end; | |
3834 | ||
3835 | return; | |
3836 | end if; | |
3837 | ||
3838 | -- Now we have the right place to do the freezing. First, a special | |
3839 | -- adjustment, if we are in default expression analysis mode, these | |
3840 | -- freeze actions must not be thrown away (normally all inserted | |
3841 | -- actions are thrown away in this mode. However, the freeze actions | |
3842 | -- are from static expressions and one of the important reasons we | |
3843 | -- are doing this special analysis is to get these freeze actions. | |
3844 | -- Therefore we turn off the In_Default_Expression mode to propagate | |
3845 | -- these freeze actions. This also means they get properly analyzed | |
3846 | -- and expanded. | |
3847 | ||
3848 | In_Default_Expression := False; | |
3849 | ||
fbf5a39b | 3850 | -- Freeze the designated type of an allocator (RM 13.14(13)) |
70482933 RK |
3851 | |
3852 | if Present (Desig_Typ) then | |
3853 | Freeze_Before (P, Desig_Typ); | |
3854 | end if; | |
3855 | ||
fbf5a39b | 3856 | -- Freeze type of expression (RM 13.14(10)). Note that we took care of |
70482933 RK |
3857 | -- the enumeration representation clause exception in the loop above. |
3858 | ||
3859 | if Present (Typ) then | |
3860 | Freeze_Before (P, Typ); | |
3861 | end if; | |
3862 | ||
fbf5a39b | 3863 | -- Freeze name if one is present (RM 13.14(11)) |
70482933 RK |
3864 | |
3865 | if Present (Nam) then | |
3866 | Freeze_Before (P, Nam); | |
3867 | end if; | |
3868 | ||
3869 | In_Default_Expression := In_Def_Exp; | |
3870 | end Freeze_Expression; | |
3871 | ||
3872 | ----------------------------- | |
3873 | -- Freeze_Fixed_Point_Type -- | |
3874 | ----------------------------- | |
3875 | ||
edd63e9b ES |
3876 | -- Certain fixed-point types and subtypes, including implicit base types |
3877 | -- and declared first subtypes, have not yet set up a range. This is | |
3878 | -- because the range cannot be set until the Small and Size values are | |
3879 | -- known, and these are not known till the type is frozen. | |
70482933 | 3880 | |
edd63e9b ES |
3881 | -- To signal this case, Scalar_Range contains an unanalyzed syntactic range |
3882 | -- whose bounds are unanalyzed real literals. This routine will recognize | |
3883 | -- this case, and transform this range node into a properly typed range | |
3884 | -- with properly analyzed and resolved values. | |
70482933 RK |
3885 | |
3886 | procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is | |
3887 | Rng : constant Node_Id := Scalar_Range (Typ); | |
3888 | Lo : constant Node_Id := Low_Bound (Rng); | |
3889 | Hi : constant Node_Id := High_Bound (Rng); | |
3890 | Btyp : constant Entity_Id := Base_Type (Typ); | |
3891 | Brng : constant Node_Id := Scalar_Range (Btyp); | |
3892 | BLo : constant Node_Id := Low_Bound (Brng); | |
3893 | BHi : constant Node_Id := High_Bound (Brng); | |
3894 | Small : constant Ureal := Small_Value (Typ); | |
3895 | Loval : Ureal; | |
3896 | Hival : Ureal; | |
3897 | Atype : Entity_Id; | |
3898 | ||
3899 | Actual_Size : Nat; | |
3900 | ||
3901 | function Fsize (Lov, Hiv : Ureal) return Nat; | |
3902 | -- Returns size of type with given bounds. Also leaves these | |
3903 | -- bounds set as the current bounds of the Typ. | |
3904 | ||
0da2c8ac AC |
3905 | ----------- |
3906 | -- Fsize -- | |
3907 | ----------- | |
3908 | ||
70482933 RK |
3909 | function Fsize (Lov, Hiv : Ureal) return Nat is |
3910 | begin | |
3911 | Set_Realval (Lo, Lov); | |
3912 | Set_Realval (Hi, Hiv); | |
3913 | return Minimum_Size (Typ); | |
3914 | end Fsize; | |
3915 | ||
0da2c8ac | 3916 | -- Start of processing for Freeze_Fixed_Point_Type |
70482933 RK |
3917 | |
3918 | begin | |
3919 | -- If Esize of a subtype has not previously been set, set it now | |
3920 | ||
3921 | if Unknown_Esize (Typ) then | |
3922 | Atype := Ancestor_Subtype (Typ); | |
3923 | ||
3924 | if Present (Atype) then | |
fbf5a39b | 3925 | Set_Esize (Typ, Esize (Atype)); |
70482933 | 3926 | else |
fbf5a39b | 3927 | Set_Esize (Typ, Esize (Base_Type (Typ))); |
70482933 RK |
3928 | end if; |
3929 | end if; | |
3930 | ||
3931 | -- Immediate return if the range is already analyzed. This means | |
3932 | -- that the range is already set, and does not need to be computed | |
3933 | -- by this routine. | |
3934 | ||
3935 | if Analyzed (Rng) then | |
3936 | return; | |
3937 | end if; | |
3938 | ||
3939 | -- Immediate return if either of the bounds raises Constraint_Error | |
3940 | ||
3941 | if Raises_Constraint_Error (Lo) | |
3942 | or else Raises_Constraint_Error (Hi) | |
3943 | then | |
3944 | return; | |
3945 | end if; | |
3946 | ||
3947 | Loval := Realval (Lo); | |
3948 | Hival := Realval (Hi); | |
3949 | ||
3950 | -- Ordinary fixed-point case | |
3951 | ||
3952 | if Is_Ordinary_Fixed_Point_Type (Typ) then | |
3953 | ||
3954 | -- For the ordinary fixed-point case, we are allowed to fudge the | |
3955 | -- end-points up or down by small. Generally we prefer to fudge | |
3956 | -- up, i.e. widen the bounds for non-model numbers so that the | |
3957 | -- end points are included. However there are cases in which this | |
3958 | -- cannot be done, and indeed cases in which we may need to narrow | |
3959 | -- the bounds. The following circuit makes the decision. | |
3960 | ||
3961 | -- Note: our terminology here is that Incl_EP means that the | |
3962 | -- bounds are widened by Small if necessary to include the end | |
3963 | -- points, and Excl_EP means that the bounds are narrowed by | |
3964 | -- Small to exclude the end-points if this reduces the size. | |
3965 | ||
3966 | -- Note that in the Incl case, all we care about is including the | |
3967 | -- end-points. In the Excl case, we want to narrow the bounds as | |
3968 | -- much as permitted by the RM, to give the smallest possible size. | |
3969 | ||
3970 | Fudge : declare | |
3971 | Loval_Incl_EP : Ureal; | |
3972 | Hival_Incl_EP : Ureal; | |
3973 | ||
3974 | Loval_Excl_EP : Ureal; | |
3975 | Hival_Excl_EP : Ureal; | |
3976 | ||
3977 | Size_Incl_EP : Nat; | |
3978 | Size_Excl_EP : Nat; | |
3979 | ||
3980 | Model_Num : Ureal; | |
3981 | First_Subt : Entity_Id; | |
3982 | Actual_Lo : Ureal; | |
3983 | Actual_Hi : Ureal; | |
3984 | ||
3985 | begin | |
3986 | -- First step. Base types are required to be symmetrical. Right | |
3987 | -- now, the base type range is a copy of the first subtype range. | |
3988 | -- This will be corrected before we are done, but right away we | |
3989 | -- need to deal with the case where both bounds are non-negative. | |
3990 | -- In this case, we set the low bound to the negative of the high | |
3991 | -- bound, to make sure that the size is computed to include the | |
3992 | -- required sign. Note that we do not need to worry about the | |
3993 | -- case of both bounds negative, because the sign will be dealt | |
3994 | -- with anyway. Furthermore we can't just go making such a bound | |
3995 | -- symmetrical, since in a twos-complement system, there is an | |
3996 | -- extra negative value which could not be accomodated on the | |
3997 | -- positive side. | |
3998 | ||
3999 | if Typ = Btyp | |
4000 | and then not UR_Is_Negative (Loval) | |
4001 | and then Hival > Loval | |
4002 | then | |
4003 | Loval := -Hival; | |
4004 | Set_Realval (Lo, Loval); | |
4005 | end if; | |
4006 | ||
4007 | -- Compute the fudged bounds. If the number is a model number, | |
edd63e9b ES |
4008 | -- then we do nothing to include it, but we are allowed to backoff |
4009 | -- to the next adjacent model number when we exclude it. If it is | |
4010 | -- not a model number then we straddle the two values with the | |
4011 | -- model numbers on either side. | |
70482933 RK |
4012 | |
4013 | Model_Num := UR_Trunc (Loval / Small) * Small; | |
4014 | ||
4015 | if Loval = Model_Num then | |
4016 | Loval_Incl_EP := Model_Num; | |
4017 | else | |
4018 | Loval_Incl_EP := Model_Num - Small; | |
4019 | end if; | |
4020 | ||
4021 | -- The low value excluding the end point is Small greater, but | |
4022 | -- we do not do this exclusion if the low value is positive, | |
4023 | -- since it can't help the size and could actually hurt by | |
4024 | -- crossing the high bound. | |
4025 | ||
4026 | if UR_Is_Negative (Loval_Incl_EP) then | |
4027 | Loval_Excl_EP := Loval_Incl_EP + Small; | |
4028 | else | |
4029 | Loval_Excl_EP := Loval_Incl_EP; | |
4030 | end if; | |
4031 | ||
4032 | -- Similar processing for upper bound and high value | |
4033 | ||
4034 | Model_Num := UR_Trunc (Hival / Small) * Small; | |
4035 | ||
4036 | if Hival = Model_Num then | |
4037 | Hival_Incl_EP := Model_Num; | |
4038 | else | |
4039 | Hival_Incl_EP := Model_Num + Small; | |
4040 | end if; | |
4041 | ||
4042 | if UR_Is_Positive (Hival_Incl_EP) then | |
4043 | Hival_Excl_EP := Hival_Incl_EP - Small; | |
4044 | else | |
4045 | Hival_Excl_EP := Hival_Incl_EP; | |
4046 | end if; | |
4047 | ||
4048 | -- One further adjustment is needed. In the case of subtypes, | |
4049 | -- we cannot go outside the range of the base type, or we get | |
4050 | -- peculiarities, and the base type range is already set. This | |
4051 | -- only applies to the Incl values, since clearly the Excl | |
4052 | -- values are already as restricted as they are allowed to be. | |
4053 | ||
4054 | if Typ /= Btyp then | |
4055 | Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo)); | |
4056 | Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi)); | |
4057 | end if; | |
4058 | ||
4059 | -- Get size including and excluding end points | |
4060 | ||
4061 | Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP); | |
4062 | Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP); | |
4063 | ||
4064 | -- No need to exclude end-points if it does not reduce size | |
4065 | ||
4066 | if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then | |
4067 | Loval_Excl_EP := Loval_Incl_EP; | |
4068 | end if; | |
4069 | ||
4070 | if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then | |
4071 | Hival_Excl_EP := Hival_Incl_EP; | |
4072 | end if; | |
4073 | ||
4074 | -- Now we set the actual size to be used. We want to use the | |
4075 | -- bounds fudged up to include the end-points but only if this | |
4076 | -- can be done without violating a specifically given size | |
4077 | -- size clause or causing an unacceptable increase in size. | |
4078 | ||
4079 | -- Case of size clause given | |
4080 | ||
4081 | if Has_Size_Clause (Typ) then | |
4082 | ||
4083 | -- Use the inclusive size only if it is consistent with | |
4084 | -- the explicitly specified size. | |
4085 | ||
4086 | if Size_Incl_EP <= RM_Size (Typ) then | |
4087 | Actual_Lo := Loval_Incl_EP; | |
4088 | Actual_Hi := Hival_Incl_EP; | |
4089 | Actual_Size := Size_Incl_EP; | |
4090 | ||
4091 | -- If the inclusive size is too large, we try excluding | |
4092 | -- the end-points (will be caught later if does not work). | |
4093 | ||
4094 | else | |
4095 | Actual_Lo := Loval_Excl_EP; | |
4096 | Actual_Hi := Hival_Excl_EP; | |
4097 | Actual_Size := Size_Excl_EP; | |
4098 | end if; | |
4099 | ||
4100 | -- Case of size clause not given | |
4101 | ||
4102 | else | |
4103 | -- If we have a base type whose corresponding first subtype | |
4104 | -- has an explicit size that is large enough to include our | |
4105 | -- end-points, then do so. There is no point in working hard | |
4106 | -- to get a base type whose size is smaller than the specified | |
4107 | -- size of the first subtype. | |
4108 | ||
4109 | First_Subt := First_Subtype (Typ); | |
4110 | ||
4111 | if Has_Size_Clause (First_Subt) | |
4112 | and then Size_Incl_EP <= Esize (First_Subt) | |
4113 | then | |
4114 | Actual_Size := Size_Incl_EP; | |
4115 | Actual_Lo := Loval_Incl_EP; | |
4116 | Actual_Hi := Hival_Incl_EP; | |
4117 | ||
4118 | -- If excluding the end-points makes the size smaller and | |
4119 | -- results in a size of 8,16,32,64, then we take the smaller | |
4120 | -- size. For the 64 case, this is compulsory. For the other | |
4121 | -- cases, it seems reasonable. We like to include end points | |
4122 | -- if we can, but not at the expense of moving to the next | |
4123 | -- natural boundary of size. | |
4124 | ||
4125 | elsif Size_Incl_EP /= Size_Excl_EP | |
4126 | and then | |
4127 | (Size_Excl_EP = 8 or else | |
4128 | Size_Excl_EP = 16 or else | |
4129 | Size_Excl_EP = 32 or else | |
4130 | Size_Excl_EP = 64) | |
4131 | then | |
4132 | Actual_Size := Size_Excl_EP; | |
4133 | Actual_Lo := Loval_Excl_EP; | |
4134 | Actual_Hi := Hival_Excl_EP; | |
4135 | ||
4136 | -- Otherwise we can definitely include the end points | |
4137 | ||
4138 | else | |
4139 | Actual_Size := Size_Incl_EP; | |
4140 | Actual_Lo := Loval_Incl_EP; | |
4141 | Actual_Hi := Hival_Incl_EP; | |
4142 | end if; | |
4143 | ||
edd63e9b ES |
4144 | -- One pathological case: normally we never fudge a low bound |
4145 | -- down, since it would seem to increase the size (if it has | |
4146 | -- any effect), but for ranges containing single value, or no | |
4147 | -- values, the high bound can be small too large. Consider: | |
70482933 RK |
4148 | |
4149 | -- type t is delta 2.0**(-14) | |
4150 | -- range 131072.0 .. 0; | |
4151 | ||
edd63e9b ES |
4152 | -- That lower bound is *just* outside the range of 32 bits, and |
4153 | -- does need fudging down in this case. Note that the bounds | |
4154 | -- will always have crossed here, since the high bound will be | |
4155 | -- fudged down if necessary, as in the case of: | |
70482933 RK |
4156 | |
4157 | -- type t is delta 2.0**(-14) | |
4158 | -- range 131072.0 .. 131072.0; | |
4159 | ||
edd63e9b ES |
4160 | -- So we detect the situation by looking for crossed bounds, |
4161 | -- and if the bounds are crossed, and the low bound is greater | |
4162 | -- than zero, we will always back it off by small, since this | |
4163 | -- is completely harmless. | |
70482933 RK |
4164 | |
4165 | if Actual_Lo > Actual_Hi then | |
4166 | if UR_Is_Positive (Actual_Lo) then | |
4167 | Actual_Lo := Loval_Incl_EP - Small; | |
4168 | Actual_Size := Fsize (Actual_Lo, Actual_Hi); | |
4169 | ||
4170 | -- And of course, we need to do exactly the same parallel | |
4171 | -- fudge for flat ranges in the negative region. | |
4172 | ||
4173 | elsif UR_Is_Negative (Actual_Hi) then | |
4174 | Actual_Hi := Hival_Incl_EP + Small; | |
4175 | Actual_Size := Fsize (Actual_Lo, Actual_Hi); | |
4176 | end if; | |
4177 | end if; | |
4178 | end if; | |
4179 | ||
4180 | Set_Realval (Lo, Actual_Lo); | |
4181 | Set_Realval (Hi, Actual_Hi); | |
4182 | end Fudge; | |
4183 | ||
4184 | -- For the decimal case, none of this fudging is required, since there | |
4185 | -- are no end-point problems in the decimal case (the end-points are | |
4186 | -- always included). | |
4187 | ||
4188 | else | |
4189 | Actual_Size := Fsize (Loval, Hival); | |
4190 | end if; | |
4191 | ||
4192 | -- At this stage, the actual size has been calculated and the proper | |
4193 | -- required bounds are stored in the low and high bounds. | |
4194 | ||
4195 | if Actual_Size > 64 then | |
4196 | Error_Msg_Uint_1 := UI_From_Int (Actual_Size); | |
4197 | Error_Msg_N | |
4198 | ("size required (^) for type& too large, maximum is 64", Typ); | |
4199 | Actual_Size := 64; | |
4200 | end if; | |
4201 | ||
4202 | -- Check size against explicit given size | |
4203 | ||
4204 | if Has_Size_Clause (Typ) then | |
4205 | if Actual_Size > RM_Size (Typ) then | |
4206 | Error_Msg_Uint_1 := RM_Size (Typ); | |
4207 | Error_Msg_Uint_2 := UI_From_Int (Actual_Size); | |
4208 | Error_Msg_NE | |
4209 | ("size given (^) for type& too small, minimum is ^", | |
4210 | Size_Clause (Typ), Typ); | |
4211 | ||
4212 | else | |
4213 | Actual_Size := UI_To_Int (Esize (Typ)); | |
4214 | end if; | |
4215 | ||
4216 | -- Increase size to next natural boundary if no size clause given | |
4217 | ||
4218 | else | |
4219 | if Actual_Size <= 8 then | |
4220 | Actual_Size := 8; | |
4221 | elsif Actual_Size <= 16 then | |
4222 | Actual_Size := 16; | |
4223 | elsif Actual_Size <= 32 then | |
4224 | Actual_Size := 32; | |
4225 | else | |
4226 | Actual_Size := 64; | |
4227 | end if; | |
4228 | ||
4229 | Init_Esize (Typ, Actual_Size); | |
4230 | Adjust_Esize_For_Alignment (Typ); | |
4231 | end if; | |
4232 | ||
edd63e9b ES |
4233 | -- If we have a base type, then expand the bounds so that they extend to |
4234 | -- the full width of the allocated size in bits, to avoid junk range | |
4235 | -- checks on intermediate computations. | |
70482933 RK |
4236 | |
4237 | if Base_Type (Typ) = Typ then | |
4238 | Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1)))); | |
4239 | Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1))); | |
4240 | end if; | |
4241 | ||
4242 | -- Final step is to reanalyze the bounds using the proper type | |
4243 | -- and set the Corresponding_Integer_Value fields of the literals. | |
4244 | ||
4245 | Set_Etype (Lo, Empty); | |
4246 | Set_Analyzed (Lo, False); | |
4247 | Analyze (Lo); | |
4248 | ||
edd63e9b ES |
4249 | -- Resolve with universal fixed if the base type, and the base type if |
4250 | -- it is a subtype. Note we can't resolve the base type with itself, | |
4251 | -- that would be a reference before definition. | |
70482933 RK |
4252 | |
4253 | if Typ = Btyp then | |
4254 | Resolve (Lo, Universal_Fixed); | |
4255 | else | |
4256 | Resolve (Lo, Btyp); | |
4257 | end if; | |
4258 | ||
4259 | -- Set corresponding integer value for bound | |
4260 | ||
4261 | Set_Corresponding_Integer_Value | |
4262 | (Lo, UR_To_Uint (Realval (Lo) / Small)); | |
4263 | ||
4264 | -- Similar processing for high bound | |
4265 | ||
4266 | Set_Etype (Hi, Empty); | |
4267 | Set_Analyzed (Hi, False); | |
4268 | Analyze (Hi); | |
4269 | ||
4270 | if Typ = Btyp then | |
4271 | Resolve (Hi, Universal_Fixed); | |
4272 | else | |
4273 | Resolve (Hi, Btyp); | |
4274 | end if; | |
4275 | ||
4276 | Set_Corresponding_Integer_Value | |
4277 | (Hi, UR_To_Uint (Realval (Hi) / Small)); | |
4278 | ||
4279 | -- Set type of range to correspond to bounds | |
4280 | ||
4281 | Set_Etype (Rng, Etype (Lo)); | |
4282 | ||
fbf5a39b | 4283 | -- Set Esize to calculated size if not set already |
70482933 | 4284 | |
fbf5a39b AC |
4285 | if Unknown_Esize (Typ) then |
4286 | Init_Esize (Typ, Actual_Size); | |
4287 | end if; | |
70482933 RK |
4288 | |
4289 | -- Set RM_Size if not already set. If already set, check value | |
4290 | ||
4291 | declare | |
4292 | Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ)); | |
4293 | ||
4294 | begin | |
4295 | if RM_Size (Typ) /= Uint_0 then | |
4296 | if RM_Size (Typ) < Minsiz then | |
4297 | Error_Msg_Uint_1 := RM_Size (Typ); | |
4298 | Error_Msg_Uint_2 := Minsiz; | |
4299 | Error_Msg_NE | |
4300 | ("size given (^) for type& too small, minimum is ^", | |
4301 | Size_Clause (Typ), Typ); | |
4302 | end if; | |
4303 | ||
4304 | else | |
4305 | Set_RM_Size (Typ, Minsiz); | |
4306 | end if; | |
4307 | end; | |
70482933 RK |
4308 | end Freeze_Fixed_Point_Type; |
4309 | ||
4310 | ------------------ | |
4311 | -- Freeze_Itype -- | |
4312 | ------------------ | |
4313 | ||
4314 | procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is | |
4315 | L : List_Id; | |
4316 | ||
4317 | begin | |
4318 | Set_Has_Delayed_Freeze (T); | |
4319 | L := Freeze_Entity (T, Sloc (N)); | |
4320 | ||
4321 | if Is_Non_Empty_List (L) then | |
4322 | Insert_Actions (N, L); | |
4323 | end if; | |
4324 | end Freeze_Itype; | |
4325 | ||
4326 | -------------------------- | |
4327 | -- Freeze_Static_Object -- | |
4328 | -------------------------- | |
4329 | ||
4330 | procedure Freeze_Static_Object (E : Entity_Id) is | |
4331 | ||
4332 | Cannot_Be_Static : exception; | |
4333 | -- Exception raised if the type of a static object cannot be made | |
4334 | -- static. This happens if the type depends on non-global objects. | |
4335 | ||
4336 | procedure Ensure_Expression_Is_SA (N : Node_Id); | |
4337 | -- Called to ensure that an expression used as part of a type | |
4338 | -- definition is statically allocatable, which means that the type | |
4339 | -- of the expression is statically allocatable, and the expression | |
4340 | -- is either static, or a reference to a library level constant. | |
4341 | ||
4342 | procedure Ensure_Type_Is_SA (Typ : Entity_Id); | |
4343 | -- Called to mark a type as static, checking that it is possible | |
4344 | -- to set the type as static. If it is not possible, then the | |
4345 | -- exception Cannot_Be_Static is raised. | |
4346 | ||
4347 | ----------------------------- | |
4348 | -- Ensure_Expression_Is_SA -- | |
4349 | ----------------------------- | |
4350 | ||
4351 | procedure Ensure_Expression_Is_SA (N : Node_Id) is | |
4352 | Ent : Entity_Id; | |
4353 | ||
4354 | begin | |
4355 | Ensure_Type_Is_SA (Etype (N)); | |
4356 | ||
4357 | if Is_Static_Expression (N) then | |
4358 | return; | |
4359 | ||
4360 | elsif Nkind (N) = N_Identifier then | |
4361 | Ent := Entity (N); | |
4362 | ||
4363 | if Present (Ent) | |
4364 | and then Ekind (Ent) = E_Constant | |
4365 | and then Is_Library_Level_Entity (Ent) | |
4366 | then | |
4367 | return; | |
4368 | end if; | |
4369 | end if; | |
4370 | ||
4371 | raise Cannot_Be_Static; | |
4372 | end Ensure_Expression_Is_SA; | |
4373 | ||
4374 | ----------------------- | |
4375 | -- Ensure_Type_Is_SA -- | |
4376 | ----------------------- | |
4377 | ||
4378 | procedure Ensure_Type_Is_SA (Typ : Entity_Id) is | |
4379 | N : Node_Id; | |
4380 | C : Entity_Id; | |
4381 | ||
4382 | begin | |
4383 | -- If type is library level, we are all set | |
4384 | ||
4385 | if Is_Library_Level_Entity (Typ) then | |
4386 | return; | |
4387 | end if; | |
4388 | ||
4389 | -- We are also OK if the type is already marked as statically | |
4390 | -- allocated, which means we processed it before. | |
4391 | ||
4392 | if Is_Statically_Allocated (Typ) then | |
4393 | return; | |
4394 | end if; | |
4395 | ||
4396 | -- Mark type as statically allocated | |
4397 | ||
4398 | Set_Is_Statically_Allocated (Typ); | |
4399 | ||
4400 | -- Check that it is safe to statically allocate this type | |
4401 | ||
4402 | if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then | |
4403 | Ensure_Expression_Is_SA (Type_Low_Bound (Typ)); | |
4404 | Ensure_Expression_Is_SA (Type_High_Bound (Typ)); | |
4405 | ||
4406 | elsif Is_Array_Type (Typ) then | |
4407 | N := First_Index (Typ); | |
4408 | while Present (N) loop | |
4409 | Ensure_Type_Is_SA (Etype (N)); | |
4410 | Next_Index (N); | |
4411 | end loop; | |
4412 | ||
4413 | Ensure_Type_Is_SA (Component_Type (Typ)); | |
4414 | ||
4415 | elsif Is_Access_Type (Typ) then | |
4416 | if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then | |
4417 | ||
4418 | declare | |
4419 | F : Entity_Id; | |
4420 | T : constant Entity_Id := Etype (Designated_Type (Typ)); | |
4421 | ||
4422 | begin | |
4423 | if T /= Standard_Void_Type then | |
4424 | Ensure_Type_Is_SA (T); | |
4425 | end if; | |
4426 | ||
4427 | F := First_Formal (Designated_Type (Typ)); | |
4428 | ||
4429 | while Present (F) loop | |
4430 | Ensure_Type_Is_SA (Etype (F)); | |
4431 | Next_Formal (F); | |
4432 | end loop; | |
4433 | end; | |
4434 | ||
4435 | else | |
4436 | Ensure_Type_Is_SA (Designated_Type (Typ)); | |
4437 | end if; | |
4438 | ||
4439 | elsif Is_Record_Type (Typ) then | |
4440 | C := First_Entity (Typ); | |
4441 | ||
4442 | while Present (C) loop | |
4443 | if Ekind (C) = E_Discriminant | |
4444 | or else Ekind (C) = E_Component | |
4445 | then | |
4446 | Ensure_Type_Is_SA (Etype (C)); | |
4447 | ||
4448 | elsif Is_Type (C) then | |
4449 | Ensure_Type_Is_SA (C); | |
4450 | end if; | |
4451 | ||
4452 | Next_Entity (C); | |
4453 | end loop; | |
4454 | ||
4455 | elsif Ekind (Typ) = E_Subprogram_Type then | |
4456 | Ensure_Type_Is_SA (Etype (Typ)); | |
4457 | ||
4458 | C := First_Formal (Typ); | |
4459 | while Present (C) loop | |
4460 | Ensure_Type_Is_SA (Etype (C)); | |
4461 | Next_Formal (C); | |
4462 | end loop; | |
4463 | ||
4464 | else | |
4465 | raise Cannot_Be_Static; | |
4466 | end if; | |
4467 | end Ensure_Type_Is_SA; | |
4468 | ||
4469 | -- Start of processing for Freeze_Static_Object | |
4470 | ||
4471 | begin | |
4472 | Ensure_Type_Is_SA (Etype (E)); | |
4473 | ||
edd63e9b ES |
4474 | -- Reset True_Constant flag, since something strange is going on with |
4475 | -- the scoping here, and our simple value tracing may not be sufficient | |
4476 | -- for this indication to be reliable. We kill the Constant_Value | |
4477 | -- indication for the same reason. | |
fbf5a39b AC |
4478 | |
4479 | Set_Is_True_Constant (E, False); | |
4480 | Set_Current_Value (E, Empty); | |
4481 | ||
70482933 RK |
4482 | exception |
4483 | when Cannot_Be_Static => | |
4484 | ||
4485 | -- If the object that cannot be static is imported or exported, | |
4486 | -- then we give an error message saying that this object cannot | |
4487 | -- be imported or exported. | |
4488 | ||
4489 | if Is_Imported (E) then | |
4490 | Error_Msg_N | |
4491 | ("& cannot be imported (local type is not constant)", E); | |
4492 | ||
4493 | -- Otherwise must be exported, something is wrong if compiler | |
4494 | -- is marking something as statically allocated which cannot be). | |
4495 | ||
4496 | else pragma Assert (Is_Exported (E)); | |
4497 | Error_Msg_N | |
4498 | ("& cannot be exported (local type is not constant)", E); | |
4499 | end if; | |
4500 | end Freeze_Static_Object; | |
4501 | ||
4502 | ----------------------- | |
4503 | -- Freeze_Subprogram -- | |
4504 | ----------------------- | |
4505 | ||
4506 | procedure Freeze_Subprogram (E : Entity_Id) is | |
4507 | Retype : Entity_Id; | |
4508 | F : Entity_Id; | |
4509 | ||
4510 | begin | |
4511 | -- Subprogram may not have an address clause unless it is imported | |
4512 | ||
4513 | if Present (Address_Clause (E)) then | |
4514 | if not Is_Imported (E) then | |
4515 | Error_Msg_N | |
4516 | ("address clause can only be given " & | |
4517 | "for imported subprogram", | |
4518 | Name (Address_Clause (E))); | |
4519 | end if; | |
4520 | end if; | |
4521 | ||
91b1417d AC |
4522 | -- Reset the Pure indication on an imported subprogram unless an |
4523 | -- explicit Pure_Function pragma was present. We do this because | |
4524 | -- otherwise it is an insidious error to call a non-pure function | |
edd63e9b ES |
4525 | -- from pure unit and have calls mysteriously optimized away. What |
4526 | -- happens here is that the Import can bypass the normal check to | |
4527 | -- ensure that pure units call only pure subprograms. | |
91b1417d AC |
4528 | |
4529 | if Is_Imported (E) | |
4530 | and then Is_Pure (E) | |
4531 | and then not Has_Pragma_Pure_Function (E) | |
4532 | then | |
4533 | Set_Is_Pure (E, False); | |
4534 | end if; | |
4535 | ||
70482933 RK |
4536 | -- For non-foreign convention subprograms, this is where we create |
4537 | -- the extra formals (for accessibility level and constrained bit | |
4538 | -- information). We delay this till the freeze point precisely so | |
4539 | -- that we know the convention! | |
4540 | ||
4541 | if not Has_Foreign_Convention (E) then | |
4542 | Create_Extra_Formals (E); | |
4543 | Set_Mechanisms (E); | |
4544 | ||
4545 | -- If this is convention Ada and a Valued_Procedure, that's odd | |
4546 | ||
4547 | if Ekind (E) = E_Procedure | |
4548 | and then Is_Valued_Procedure (E) | |
4549 | and then Convention (E) = Convention_Ada | |
fbf5a39b | 4550 | and then Warn_On_Export_Import |
70482933 RK |
4551 | then |
4552 | Error_Msg_N | |
4553 | ("?Valued_Procedure has no effect for convention Ada", E); | |
4554 | Set_Is_Valued_Procedure (E, False); | |
4555 | end if; | |
4556 | ||
4557 | -- Case of foreign convention | |
4558 | ||
4559 | else | |
4560 | Set_Mechanisms (E); | |
4561 | ||
fbf5a39b | 4562 | -- For foreign conventions, warn about return of an |
70482933 RK |
4563 | -- unconstrained array. |
4564 | ||
4565 | -- Note: we *do* allow a return by descriptor for the VMS case, | |
4566 | -- though here there is probably more to be done ??? | |
4567 | ||
4568 | if Ekind (E) = E_Function then | |
4569 | Retype := Underlying_Type (Etype (E)); | |
4570 | ||
4571 | -- If no return type, probably some other error, e.g. a | |
4572 | -- missing full declaration, so ignore. | |
4573 | ||
4574 | if No (Retype) then | |
4575 | null; | |
4576 | ||
4577 | -- If the return type is generic, we have emitted a warning | |
edd63e9b ES |
4578 | -- earlier on, and there is nothing else to check here. Specific |
4579 | -- instantiations may lead to erroneous behavior. | |
70482933 RK |
4580 | |
4581 | elsif Is_Generic_Type (Etype (E)) then | |
4582 | null; | |
4583 | ||
4584 | elsif Is_Array_Type (Retype) | |
4585 | and then not Is_Constrained (Retype) | |
4586 | and then Mechanism (E) not in Descriptor_Codes | |
fbf5a39b | 4587 | and then Warn_On_Export_Import |
70482933 | 4588 | then |
fbf5a39b AC |
4589 | Error_Msg_N |
4590 | ("?foreign convention function& should not return " & | |
4591 | "unconstrained array", E); | |
70482933 RK |
4592 | return; |
4593 | end if; | |
4594 | end if; | |
4595 | ||
4596 | -- If any of the formals for an exported foreign convention | |
edd63e9b ES |
4597 | -- subprogram have defaults, then emit an appropriate warning since |
4598 | -- this is odd (default cannot be used from non-Ada code) | |
70482933 RK |
4599 | |
4600 | if Is_Exported (E) then | |
4601 | F := First_Formal (E); | |
4602 | while Present (F) loop | |
fbf5a39b AC |
4603 | if Warn_On_Export_Import |
4604 | and then Present (Default_Value (F)) | |
4605 | then | |
70482933 RK |
4606 | Error_Msg_N |
4607 | ("?parameter cannot be defaulted in non-Ada call", | |
4608 | Default_Value (F)); | |
4609 | end if; | |
4610 | ||
4611 | Next_Formal (F); | |
4612 | end loop; | |
4613 | end if; | |
4614 | end if; | |
4615 | ||
4616 | -- For VMS, descriptor mechanisms for parameters are allowed only | |
4617 | -- for imported subprograms. | |
4618 | ||
4619 | if OpenVMS_On_Target then | |
4620 | if not Is_Imported (E) then | |
4621 | F := First_Formal (E); | |
4622 | while Present (F) loop | |
4623 | if Mechanism (F) in Descriptor_Codes then | |
4624 | Error_Msg_N | |
4625 | ("descriptor mechanism for parameter not permitted", F); | |
4626 | Error_Msg_N | |
4627 | ("\can only be used for imported subprogram", F); | |
4628 | end if; | |
4629 | ||
4630 | Next_Formal (F); | |
4631 | end loop; | |
4632 | end if; | |
4633 | end if; | |
edd63e9b ES |
4634 | |
4635 | -- Pragma Inline_Always is disallowed for dispatching subprograms | |
4636 | -- because the address of such subprograms is saved in the dispatch | |
4637 | -- table to support dispatching calls, and dispatching calls cannot | |
4638 | -- be inlined. This is consistent with the restriction against using | |
4639 | -- 'Access or 'Address on an Inline_Always subprogram. | |
4640 | ||
4641 | if Is_Dispatching_Operation (E) and then Is_Always_Inlined (E) then | |
4642 | Error_Msg_N | |
4643 | ("pragma Inline_Always not allowed for dispatching subprograms", E); | |
4644 | end if; | |
70482933 RK |
4645 | end Freeze_Subprogram; |
4646 | ||
15ce9ca2 AC |
4647 | ---------------------- |
4648 | -- Is_Fully_Defined -- | |
4649 | ---------------------- | |
70482933 | 4650 | |
70482933 RK |
4651 | function Is_Fully_Defined (T : Entity_Id) return Boolean is |
4652 | begin | |
4653 | if Ekind (T) = E_Class_Wide_Type then | |
4654 | return Is_Fully_Defined (Etype (T)); | |
657a9dd9 AC |
4655 | |
4656 | elsif Is_Array_Type (T) then | |
4657 | return Is_Fully_Defined (Component_Type (T)); | |
4658 | ||
4659 | elsif Is_Record_Type (T) | |
4660 | and not Is_Private_Type (T) | |
4661 | then | |
657a9dd9 AC |
4662 | -- Verify that the record type has no components with |
4663 | -- private types without completion. | |
4664 | ||
4665 | declare | |
4666 | Comp : Entity_Id; | |
bde58e32 | 4667 | |
657a9dd9 AC |
4668 | begin |
4669 | Comp := First_Component (T); | |
4670 | ||
4671 | while Present (Comp) loop | |
4672 | if not Is_Fully_Defined (Etype (Comp)) then | |
4673 | return False; | |
4674 | end if; | |
4675 | ||
4676 | Next_Component (Comp); | |
4677 | end loop; | |
4678 | return True; | |
4679 | end; | |
4680 | ||
4681 | else return not Is_Private_Type (T) | |
4682 | or else Present (Full_View (Base_Type (T))); | |
70482933 RK |
4683 | end if; |
4684 | end Is_Fully_Defined; | |
4685 | ||
4686 | --------------------------------- | |
4687 | -- Process_Default_Expressions -- | |
4688 | --------------------------------- | |
4689 | ||
4690 | procedure Process_Default_Expressions | |
4691 | (E : Entity_Id; | |
4692 | After : in out Node_Id) | |
4693 | is | |
4694 | Loc : constant Source_Ptr := Sloc (E); | |
4695 | Dbody : Node_Id; | |
4696 | Formal : Node_Id; | |
4697 | Dcopy : Node_Id; | |
4698 | Dnam : Entity_Id; | |
4699 | ||
4700 | begin | |
4701 | Set_Default_Expressions_Processed (E); | |
4702 | ||
4703 | -- A subprogram instance and its associated anonymous subprogram | |
4704 | -- share their signature. The default expression functions are defined | |
4705 | -- in the wrapper packages for the anonymous subprogram, and should | |
4706 | -- not be generated again for the instance. | |
4707 | ||
4708 | if Is_Generic_Instance (E) | |
4709 | and then Present (Alias (E)) | |
4710 | and then Default_Expressions_Processed (Alias (E)) | |
4711 | then | |
4712 | return; | |
4713 | end if; | |
4714 | ||
4715 | Formal := First_Formal (E); | |
4716 | ||
4717 | while Present (Formal) loop | |
4718 | if Present (Default_Value (Formal)) then | |
4719 | ||
4720 | -- We work with a copy of the default expression because we | |
4721 | -- do not want to disturb the original, since this would mess | |
4722 | -- up the conformance checking. | |
4723 | ||
4724 | Dcopy := New_Copy_Tree (Default_Value (Formal)); | |
4725 | ||
4726 | -- The analysis of the expression may generate insert actions, | |
4727 | -- which of course must not be executed. We wrap those actions | |
4728 | -- in a procedure that is not called, and later on eliminated. | |
4729 | -- The following cases have no side-effects, and are analyzed | |
4730 | -- directly. | |
4731 | ||
4732 | if Nkind (Dcopy) = N_Identifier | |
4733 | or else Nkind (Dcopy) = N_Expanded_Name | |
4734 | or else Nkind (Dcopy) = N_Integer_Literal | |
4735 | or else (Nkind (Dcopy) = N_Real_Literal | |
4736 | and then not Vax_Float (Etype (Dcopy))) | |
4737 | or else Nkind (Dcopy) = N_Character_Literal | |
4738 | or else Nkind (Dcopy) = N_String_Literal | |
4739 | or else Nkind (Dcopy) = N_Null | |
4740 | or else (Nkind (Dcopy) = N_Attribute_Reference | |
4741 | and then | |
4742 | Attribute_Name (Dcopy) = Name_Null_Parameter) | |
70482933 RK |
4743 | then |
4744 | ||
4745 | -- If there is no default function, we must still do a full | |
4746 | -- analyze call on the default value, to ensure that all | |
4747 | -- error checks are performed, e.g. those associated with | |
4748 | -- static evaluation. Note that this branch will always be | |
4749 | -- taken if the analyzer is turned off (but we still need the | |
4750 | -- error checks). | |
4751 | ||
4752 | -- Note: the setting of parent here is to meet the requirement | |
4753 | -- that we can only analyze the expression while attached to | |
4754 | -- the tree. Really the requirement is that the parent chain | |
4755 | -- be set, we don't actually need to be in the tree. | |
4756 | ||
4757 | Set_Parent (Dcopy, Declaration_Node (Formal)); | |
4758 | Analyze (Dcopy); | |
4759 | ||
4760 | -- Default expressions are resolved with their own type if the | |
4761 | -- context is generic, to avoid anomalies with private types. | |
4762 | ||
4763 | if Ekind (Scope (E)) = E_Generic_Package then | |
fbf5a39b | 4764 | Resolve (Dcopy); |
70482933 RK |
4765 | else |
4766 | Resolve (Dcopy, Etype (Formal)); | |
4767 | end if; | |
4768 | ||
4769 | -- If that resolved expression will raise constraint error, | |
4770 | -- then flag the default value as raising constraint error. | |
4771 | -- This allows a proper error message on the calls. | |
4772 | ||
4773 | if Raises_Constraint_Error (Dcopy) then | |
4774 | Set_Raises_Constraint_Error (Default_Value (Formal)); | |
4775 | end if; | |
4776 | ||
4777 | -- If the default is a parameterless call, we use the name of | |
4778 | -- the called function directly, and there is no body to build. | |
4779 | ||
4780 | elsif Nkind (Dcopy) = N_Function_Call | |
4781 | and then No (Parameter_Associations (Dcopy)) | |
4782 | then | |
4783 | null; | |
4784 | ||
4785 | -- Else construct and analyze the body of a wrapper procedure | |
4786 | -- that contains an object declaration to hold the expression. | |
4787 | -- Given that this is done only to complete the analysis, it | |
4788 | -- simpler to build a procedure than a function which might | |
4789 | -- involve secondary stack expansion. | |
4790 | ||
4791 | else | |
4792 | Dnam := | |
4793 | Make_Defining_Identifier (Loc, New_Internal_Name ('D')); | |
4794 | ||
4795 | Dbody := | |
4796 | Make_Subprogram_Body (Loc, | |
4797 | Specification => | |
4798 | Make_Procedure_Specification (Loc, | |
4799 | Defining_Unit_Name => Dnam), | |
4800 | ||
4801 | Declarations => New_List ( | |
4802 | Make_Object_Declaration (Loc, | |
4803 | Defining_Identifier => | |
4804 | Make_Defining_Identifier (Loc, | |
4805 | New_Internal_Name ('T')), | |
4806 | Object_Definition => | |
4807 | New_Occurrence_Of (Etype (Formal), Loc), | |
4808 | Expression => New_Copy_Tree (Dcopy))), | |
4809 | ||
4810 | Handled_Statement_Sequence => | |
4811 | Make_Handled_Sequence_Of_Statements (Loc, | |
4812 | Statements => New_List)); | |
4813 | ||
4814 | Set_Scope (Dnam, Scope (E)); | |
4815 | Set_Assignment_OK (First (Declarations (Dbody))); | |
4816 | Set_Is_Eliminated (Dnam); | |
4817 | Insert_After (After, Dbody); | |
4818 | Analyze (Dbody); | |
4819 | After := Dbody; | |
4820 | end if; | |
4821 | end if; | |
4822 | ||
4823 | Next_Formal (Formal); | |
4824 | end loop; | |
4825 | ||
4826 | end Process_Default_Expressions; | |
4827 | ||
4828 | ---------------------------------------- | |
4829 | -- Set_Component_Alignment_If_Not_Set -- | |
4830 | ---------------------------------------- | |
4831 | ||
4832 | procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is | |
4833 | begin | |
4834 | -- Ignore if not base type, subtypes don't need anything | |
4835 | ||
4836 | if Typ /= Base_Type (Typ) then | |
4837 | return; | |
4838 | end if; | |
4839 | ||
4840 | -- Do not override existing representation | |
4841 | ||
4842 | if Is_Packed (Typ) then | |
4843 | return; | |
4844 | ||
4845 | elsif Has_Specified_Layout (Typ) then | |
4846 | return; | |
4847 | ||
4848 | elsif Component_Alignment (Typ) /= Calign_Default then | |
4849 | return; | |
4850 | ||
4851 | else | |
4852 | Set_Component_Alignment | |
4853 | (Typ, Scope_Stack.Table | |
4854 | (Scope_Stack.Last).Component_Alignment_Default); | |
4855 | end if; | |
4856 | end Set_Component_Alignment_If_Not_Set; | |
4857 | ||
4858 | --------------------------- | |
4859 | -- Set_Debug_Info_Needed -- | |
4860 | --------------------------- | |
4861 | ||
4862 | procedure Set_Debug_Info_Needed (T : Entity_Id) is | |
4863 | begin | |
4864 | if No (T) | |
4865 | or else Needs_Debug_Info (T) | |
4866 | or else Debug_Info_Off (T) | |
4867 | then | |
4868 | return; | |
4869 | else | |
4870 | Set_Needs_Debug_Info (T); | |
4871 | end if; | |
4872 | ||
4873 | if Is_Object (T) then | |
4874 | Set_Debug_Info_Needed (Etype (T)); | |
4875 | ||
4876 | elsif Is_Type (T) then | |
4877 | Set_Debug_Info_Needed (Etype (T)); | |
4878 | ||
4879 | if Is_Record_Type (T) then | |
4880 | declare | |
4881 | Ent : Entity_Id := First_Entity (T); | |
4882 | begin | |
4883 | while Present (Ent) loop | |
4884 | Set_Debug_Info_Needed (Ent); | |
4885 | Next_Entity (Ent); | |
4886 | end loop; | |
4887 | end; | |
4888 | ||
4889 | elsif Is_Array_Type (T) then | |
4890 | Set_Debug_Info_Needed (Component_Type (T)); | |
4891 | ||
4892 | declare | |
4893 | Indx : Node_Id := First_Index (T); | |
4894 | begin | |
4895 | while Present (Indx) loop | |
4896 | Set_Debug_Info_Needed (Etype (Indx)); | |
4897 | Indx := Next_Index (Indx); | |
4898 | end loop; | |
4899 | end; | |
4900 | ||
4901 | if Is_Packed (T) then | |
4902 | Set_Debug_Info_Needed (Packed_Array_Type (T)); | |
4903 | end if; | |
4904 | ||
4905 | elsif Is_Access_Type (T) then | |
4906 | Set_Debug_Info_Needed (Directly_Designated_Type (T)); | |
4907 | ||
4908 | elsif Is_Private_Type (T) then | |
4909 | Set_Debug_Info_Needed (Full_View (T)); | |
4910 | ||
4911 | elsif Is_Protected_Type (T) then | |
4912 | Set_Debug_Info_Needed (Corresponding_Record_Type (T)); | |
4913 | end if; | |
4914 | end if; | |
70482933 RK |
4915 | end Set_Debug_Info_Needed; |
4916 | ||
c6823a20 EB |
4917 | ------------------ |
4918 | -- Undelay_Type -- | |
4919 | ------------------ | |
4920 | ||
4921 | procedure Undelay_Type (T : Entity_Id) is | |
4922 | begin | |
4923 | Set_Has_Delayed_Freeze (T, False); | |
4924 | Set_Freeze_Node (T, Empty); | |
4925 | ||
4926 | -- Since we don't want T to have a Freeze_Node, we don't want its | |
4927 | -- Full_View or Corresponding_Record_Type to have one either. | |
4928 | ||
4929 | -- ??? Fundamentally, this whole handling is a kludge. What we really | |
4930 | -- want is to be sure that for an Itype that's part of record R and is | |
4931 | -- a subtype of type T, that it's frozen after the later of the freeze | |
4932 | -- points of R and T. We have no way of doing that directly, so what we | |
4933 | -- do is force most such Itypes to be frozen as part of freezing R via | |
4934 | -- this procedure and only delay the ones that need to be delayed | |
4935 | -- (mostly the designated types of access types that are defined as | |
4936 | -- part of the record). | |
4937 | ||
4938 | if Is_Private_Type (T) | |
4939 | and then Present (Full_View (T)) | |
4940 | and then Is_Itype (Full_View (T)) | |
4941 | and then Is_Record_Type (Scope (Full_View (T))) | |
4942 | then | |
4943 | Undelay_Type (Full_View (T)); | |
4944 | end if; | |
4945 | ||
4946 | if Is_Concurrent_Type (T) | |
4947 | and then Present (Corresponding_Record_Type (T)) | |
4948 | and then Is_Itype (Corresponding_Record_Type (T)) | |
4949 | and then Is_Record_Type (Scope (Corresponding_Record_Type (T))) | |
4950 | then | |
4951 | Undelay_Type (Corresponding_Record_Type (T)); | |
4952 | end if; | |
4953 | end Undelay_Type; | |
4954 | ||
fbf5a39b AC |
4955 | ------------------ |
4956 | -- Warn_Overlay -- | |
4957 | ------------------ | |
4958 | ||
4959 | procedure Warn_Overlay | |
4960 | (Expr : Node_Id; | |
4961 | Typ : Entity_Id; | |
4962 | Nam : Entity_Id) | |
4963 | is | |
4964 | Ent : constant Entity_Id := Entity (Nam); | |
49e90211 | 4965 | -- The object to which the address clause applies |
fbf5a39b AC |
4966 | |
4967 | Init : Node_Id; | |
4968 | Old : Entity_Id := Empty; | |
4969 | Decl : Node_Id; | |
4970 | ||
4971 | begin | |
4972 | -- No warning if address clause overlay warnings are off | |
4973 | ||
4974 | if not Address_Clause_Overlay_Warnings then | |
4975 | return; | |
4976 | end if; | |
4977 | ||
4978 | -- No warning if there is an explicit initialization | |
4979 | ||
4980 | Init := Original_Node (Expression (Declaration_Node (Ent))); | |
4981 | ||
4982 | if Present (Init) and then Comes_From_Source (Init) then | |
4983 | return; | |
4984 | end if; | |
4985 | ||
edd63e9b ES |
4986 | -- We only give the warning for non-imported entities of a type for |
4987 | -- which a non-null base init proc is defined (or for access types which | |
4988 | -- have implicit null initialization). | |
fbf5a39b AC |
4989 | |
4990 | if Present (Expr) | |
4991 | and then (Has_Non_Null_Base_Init_Proc (Typ) | |
4992 | or else Is_Access_Type (Typ)) | |
4993 | and then not Is_Imported (Ent) | |
4994 | then | |
4995 | if Nkind (Expr) = N_Attribute_Reference | |
4996 | and then Is_Entity_Name (Prefix (Expr)) | |
4997 | then | |
4998 | Old := Entity (Prefix (Expr)); | |
4999 | ||
5000 | elsif Is_Entity_Name (Expr) | |
5001 | and then Ekind (Entity (Expr)) = E_Constant | |
5002 | then | |
5003 | Decl := Declaration_Node (Entity (Expr)); | |
5004 | ||
5005 | if Nkind (Decl) = N_Object_Declaration | |
5006 | and then Present (Expression (Decl)) | |
5007 | and then Nkind (Expression (Decl)) = N_Attribute_Reference | |
5008 | and then Is_Entity_Name (Prefix (Expression (Decl))) | |
5009 | then | |
5010 | Old := Entity (Prefix (Expression (Decl))); | |
5011 | ||
5012 | elsif Nkind (Expr) = N_Function_Call then | |
5013 | return; | |
5014 | end if; | |
5015 | ||
5016 | -- A function call (most likely to To_Address) is probably not | |
5017 | -- an overlay, so skip warning. Ditto if the function call was | |
5018 | -- inlined and transformed into an entity. | |
5019 | ||
5020 | elsif Nkind (Original_Node (Expr)) = N_Function_Call then | |
5021 | return; | |
5022 | end if; | |
5023 | ||
5024 | Decl := Next (Parent (Expr)); | |
5025 | ||
5026 | -- If a pragma Import follows, we assume that it is for the current | |
5027 | -- target of the address clause, and skip the warning. | |
5028 | ||
5029 | if Present (Decl) | |
5030 | and then Nkind (Decl) = N_Pragma | |
5031 | and then Chars (Decl) = Name_Import | |
5032 | then | |
5033 | return; | |
5034 | end if; | |
5035 | ||
5036 | if Present (Old) then | |
5037 | Error_Msg_Node_2 := Old; | |
5038 | Error_Msg_N | |
5039 | ("default initialization of & may modify &?", | |
5040 | Nam); | |
5041 | else | |
5042 | Error_Msg_N | |
5043 | ("default initialization of & may modify overlaid storage?", | |
5044 | Nam); | |
5045 | end if; | |
5046 | ||
5047 | -- Add friendly warning if initialization comes from a packed array | |
5048 | -- component. | |
5049 | ||
5050 | if Is_Record_Type (Typ) then | |
5051 | declare | |
5052 | Comp : Entity_Id; | |
5053 | ||
5054 | begin | |
5055 | Comp := First_Component (Typ); | |
5056 | ||
5057 | while Present (Comp) loop | |
5058 | if Nkind (Parent (Comp)) = N_Component_Declaration | |
5059 | and then Present (Expression (Parent (Comp))) | |
5060 | then | |
5061 | exit; | |
5062 | elsif Is_Array_Type (Etype (Comp)) | |
5063 | and then Present (Packed_Array_Type (Etype (Comp))) | |
5064 | then | |
5065 | Error_Msg_NE | |
5066 | ("packed array component& will be initialized to zero?", | |
5067 | Nam, Comp); | |
5068 | exit; | |
5069 | else | |
5070 | Next_Component (Comp); | |
5071 | end if; | |
5072 | end loop; | |
5073 | end; | |
5074 | end if; | |
5075 | ||
5076 | Error_Msg_N | |
5077 | ("use pragma Import for & to " & | |
5078 | "suppress initialization ('R'M B.1(24))?", | |
5079 | Nam); | |
5080 | end if; | |
5081 | end Warn_Overlay; | |
5082 | ||
70482933 | 5083 | end Freeze; |