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