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