]>
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 | -- -- | |
e1691d7e | 9 | -- Copyright (C) 1992-2017, 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 | ||
0e77949e AC |
26 | with Aspects; use Aspects; |
27 | with Atree; use Atree; | |
28 | with Checks; use Checks; | |
29 | with Contracts; use Contracts; | |
30 | with Debug; use Debug; | |
31 | with Einfo; use Einfo; | |
32 | with Elists; use Elists; | |
33 | with Errout; use Errout; | |
34 | with Exp_Ch3; use Exp_Ch3; | |
35 | with Exp_Ch7; use Exp_Ch7; | |
36 | with Exp_Disp; use Exp_Disp; | |
37 | with Exp_Pakd; use Exp_Pakd; | |
38 | with Exp_Util; use Exp_Util; | |
39 | with Exp_Tss; use Exp_Tss; | |
40 | with Fname; use Fname; | |
41 | with Ghost; use Ghost; | |
42 | with Layout; use Layout; | |
43 | with Lib; use Lib; | |
44 | with Namet; use Namet; | |
45 | with Nlists; use Nlists; | |
46 | with Nmake; use Nmake; | |
47 | with Opt; use Opt; | |
48 | with Restrict; use Restrict; | |
49 | with Rident; use Rident; | |
50 | with Rtsfind; use Rtsfind; | |
51 | with Sem; use Sem; | |
52 | with Sem_Aux; use Sem_Aux; | |
53 | with Sem_Cat; use Sem_Cat; | |
54 | with Sem_Ch6; use Sem_Ch6; | |
55 | with Sem_Ch7; use Sem_Ch7; | |
56 | with Sem_Ch8; use Sem_Ch8; | |
57 | with Sem_Ch13; use Sem_Ch13; | |
a187206c | 58 | with Sem_Disp; use Sem_Disp; |
0e77949e AC |
59 | with Sem_Eval; use Sem_Eval; |
60 | with Sem_Mech; use Sem_Mech; | |
61 | with Sem_Prag; use Sem_Prag; | |
62 | with Sem_Res; use Sem_Res; | |
63 | with Sem_Util; use Sem_Util; | |
64 | with Sinfo; use Sinfo; | |
65 | with Snames; use Snames; | |
66 | with Stand; use Stand; | |
67 | with Targparm; use Targparm; | |
68 | with Tbuild; use Tbuild; | |
69 | with Ttypes; use Ttypes; | |
70 | with Uintp; use Uintp; | |
71 | with Urealp; use Urealp; | |
72 | with Warnsw; use Warnsw; | |
70482933 RK |
73 | |
74 | package body Freeze is | |
75 | ||
76 | ----------------------- | |
77 | -- Local Subprograms -- | |
78 | ----------------------- | |
79 | ||
80 | procedure Adjust_Esize_For_Alignment (Typ : Entity_Id); | |
81 | -- Typ is a type that is being frozen. If no size clause is given, | |
82 | -- but a default Esize has been computed, then this default Esize is | |
83 | -- adjusted up if necessary to be consistent with a given alignment, | |
84 | -- but never to a value greater than Long_Long_Integer'Size. This | |
85 | -- is used for all discrete types and for fixed-point types. | |
86 | ||
87 | procedure Build_And_Analyze_Renamed_Body | |
88 | (Decl : Node_Id; | |
89 | New_S : Entity_Id; | |
90 | After : in out Node_Id); | |
49e90211 | 91 | -- Build body for a renaming declaration, insert in tree and analyze |
70482933 | 92 | |
fbf5a39b AC |
93 | procedure Check_Address_Clause (E : Entity_Id); |
94 | -- Apply legality checks to address clauses for object declarations, | |
cf6956bb AC |
95 | -- at the point the object is frozen. Also ensure any initialization is |
96 | -- performed only after the object has been frozen. | |
fbf5a39b | 97 | |
75965852 | 98 | procedure Check_Component_Storage_Order |
ee6208f2 AC |
99 | (Encl_Type : Entity_Id; |
100 | Comp : Entity_Id; | |
101 | ADC : Node_Id; | |
102 | Comp_ADC_Present : out Boolean); | |
75965852 | 103 | -- For an Encl_Type that has a Scalar_Storage_Order attribute definition |
8a7c0400 AC |
104 | -- clause, verify that the component type has an explicit and compatible |
105 | -- attribute/aspect. For arrays, Comp is Empty; for records, it is the | |
106 | -- entity of the component under consideration. For an Encl_Type that | |
107 | -- does not have a Scalar_Storage_Order attribute definition clause, | |
108 | -- verify that the component also does not have such a clause. | |
ee6208f2 AC |
109 | -- ADC is the attribute definition clause if present (or Empty). On return, |
110 | -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order | |
111 | -- attribute definition clause. | |
75965852 | 112 | |
497a660d AC |
113 | procedure Check_Debug_Info_Needed (T : Entity_Id); |
114 | -- As each entity is frozen, this routine is called to deal with the | |
115 | -- setting of Debug_Info_Needed for the entity. This flag is set if | |
116 | -- the entity comes from source, or if we are in Debug_Generated_Code | |
117 | -- mode or if the -gnatdV debug flag is set. However, it never sets | |
118 | -- the flag if Debug_Info_Off is set. This procedure also ensures that | |
119 | -- subsidiary entities have the flag set as required. | |
120 | ||
18c56840 ES |
121 | procedure Check_Expression_Function (N : Node_Id; Nam : Entity_Id); |
122 | -- When an expression function is frozen by a use of it, the expression | |
123 | -- itself is frozen. Check that the expression does not include references | |
33c9f9af AC |
124 | -- to deferred constants without completion. We report this at the freeze |
125 | -- point of the function, to provide a better error message. | |
e8de1a82 | 126 | -- |
3ad33e33 AC |
127 | -- In most cases the expression itself is frozen by the time the function |
128 | -- itself is frozen, because the formals will be frozen by then. However, | |
129 | -- Attribute references to outer types are freeze points for those types; | |
130 | -- this routine generates the required freeze nodes for them. | |
131 | ||
017d237e ES |
132 | procedure Check_Inherited_Conditions (R : Entity_Id); |
133 | -- For a tagged derived type, create wrappers for inherited operations | |
8c519039 | 134 | -- that have a class-wide condition, so it can be properly rewritten if |
017d237e ES |
135 | -- it involves calls to other overriding primitives. |
136 | ||
70482933 RK |
137 | procedure Check_Strict_Alignment (E : Entity_Id); |
138 | -- E is a base type. If E is tagged or has a component that is aliased | |
139 | -- or tagged or contains something this is aliased or tagged, set | |
140 | -- Strict_Alignment. | |
141 | ||
142 | procedure Check_Unsigned_Type (E : Entity_Id); | |
143 | pragma Inline (Check_Unsigned_Type); | |
144 | -- If E is a fixed-point or discrete type, then all the necessary work | |
145 | -- to freeze it is completed except for possible setting of the flag | |
146 | -- Is_Unsigned_Type, which is done by this procedure. The call has no | |
147 | -- effect if the entity E is not a discrete or fixed-point type. | |
148 | ||
149 | procedure Freeze_And_Append | |
150 | (Ent : Entity_Id; | |
c159409f | 151 | N : Node_Id; |
70482933 RK |
152 | Result : in out List_Id); |
153 | -- Freezes Ent using Freeze_Entity, and appends the resulting list of | |
c159409f AC |
154 | -- nodes to Result, modifying Result from No_List if necessary. N has |
155 | -- the same usage as in Freeze_Entity. | |
70482933 RK |
156 | |
157 | procedure Freeze_Enumeration_Type (Typ : Entity_Id); | |
158 | -- Freeze enumeration type. The Esize field is set as processing | |
159 | -- proceeds (i.e. set by default when the type is declared and then | |
160 | -- adjusted by rep clauses. What this procedure does is to make sure | |
161 | -- that if a foreign convention is specified, and no specific size | |
162 | -- is given, then the size must be at least Integer'Size. | |
163 | ||
70482933 RK |
164 | procedure Freeze_Static_Object (E : Entity_Id); |
165 | -- If an object is frozen which has Is_Statically_Allocated set, then | |
166 | -- all referenced types must also be marked with this flag. This routine | |
167 | -- is in charge of meeting this requirement for the object entity E. | |
168 | ||
169 | procedure Freeze_Subprogram (E : Entity_Id); | |
170 | -- Perform freezing actions for a subprogram (create extra formals, | |
171 | -- and set proper default mechanism values). Note that this routine | |
172 | -- is not called for internal subprograms, for which neither of these | |
173 | -- actions is needed (or desirable, we do not want for example to have | |
174 | -- these extra formals present in initialization procedures, where they | |
175 | -- would serve no purpose). In this call E is either a subprogram or | |
176 | -- a subprogram type (i.e. an access to a subprogram). | |
177 | ||
178 | function Is_Fully_Defined (T : Entity_Id) return Boolean; | |
bde58e32 | 179 | -- True if T is not private and has no private components, or has a full |
657a9dd9 AC |
180 | -- view. Used to determine whether the designated type of an access type |
181 | -- should be frozen when the access type is frozen. This is done when an | |
182 | -- allocator is frozen, or an expression that may involve attributes of | |
183 | -- the designated type. Otherwise freezing the access type does not freeze | |
184 | -- the designated type. | |
70482933 RK |
185 | |
186 | procedure Process_Default_Expressions | |
187 | (E : Entity_Id; | |
188 | After : in out Node_Id); | |
c159409f AC |
189 | -- This procedure is called for each subprogram to complete processing of |
190 | -- default expressions at the point where all types are known to be frozen. | |
191 | -- The expressions must be analyzed in full, to make sure that all error | |
192 | -- processing is done (they have only been pre-analyzed). If the expression | |
193 | -- is not an entity or literal, its analysis may generate code which must | |
194 | -- not be executed. In that case we build a function body to hold that | |
195 | -- code. This wrapper function serves no other purpose (it used to be | |
196 | -- called to evaluate the default, but now the default is inlined at each | |
197 | -- point of call). | |
70482933 RK |
198 | |
199 | procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id); | |
c159409f AC |
200 | -- Typ is a record or array type that is being frozen. This routine sets |
201 | -- the default component alignment from the scope stack values if the | |
202 | -- alignment is otherwise not specified. | |
70482933 | 203 | |
220d1fd9 AC |
204 | procedure Set_SSO_From_Default (T : Entity_Id); |
205 | -- T is a record or array type that is being frozen. If it is a base type, | |
206 | -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order | |
207 | -- will be set appropriately. Note that an explicit occurrence of aspect | |
208 | -- Scalar_Storage_Order or an explicit setting of this aspect with an | |
209 | -- attribute definition clause occurs, then these two flags are reset in | |
210 | -- any case, so call will have no effect. | |
211 | ||
c6823a20 | 212 | procedure Undelay_Type (T : Entity_Id); |
c159409f AC |
213 | -- T is a type of a component that we know to be an Itype. We don't want |
214 | -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any | |
215 | -- Full_View or Corresponding_Record_Type. | |
c6823a20 | 216 | |
c31b57af | 217 | procedure Warn_Overlay (Expr : Node_Id; Typ : Entity_Id; Nam : Node_Id); |
fbf5a39b AC |
218 | -- Expr is the expression for an address clause for entity Nam whose type |
219 | -- is Typ. If Typ has a default initialization, and there is no explicit | |
220 | -- initialization in the source declaration, check whether the address | |
221 | -- clause might cause overlaying of an entity, and emit a warning on the | |
222 | -- side effect that the initialization will cause. | |
223 | ||
70482933 RK |
224 | ------------------------------- |
225 | -- Adjust_Esize_For_Alignment -- | |
226 | ------------------------------- | |
227 | ||
228 | procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is | |
229 | Align : Uint; | |
230 | ||
231 | begin | |
232 | if Known_Esize (Typ) and then Known_Alignment (Typ) then | |
233 | Align := Alignment_In_Bits (Typ); | |
234 | ||
235 | if Align > Esize (Typ) | |
236 | and then Align <= Standard_Long_Long_Integer_Size | |
237 | then | |
238 | Set_Esize (Typ, Align); | |
239 | end if; | |
240 | end if; | |
241 | end Adjust_Esize_For_Alignment; | |
242 | ||
243 | ------------------------------------ | |
244 | -- Build_And_Analyze_Renamed_Body -- | |
245 | ------------------------------------ | |
246 | ||
247 | procedure Build_And_Analyze_Renamed_Body | |
248 | (Decl : Node_Id; | |
249 | New_S : Entity_Id; | |
250 | After : in out Node_Id) | |
251 | is | |
ca0cb93e AC |
252 | Body_Decl : constant Node_Id := Unit_Declaration_Node (New_S); |
253 | Ent : constant Entity_Id := Defining_Entity (Decl); | |
254 | Body_Node : Node_Id; | |
255 | Renamed_Subp : Entity_Id; | |
d4fc0fb4 | 256 | |
70482933 | 257 | begin |
1c612f29 RD |
258 | -- If the renamed subprogram is intrinsic, there is no need for a |
259 | -- wrapper body: we set the alias that will be called and expanded which | |
260 | -- completes the declaration. This transformation is only legal if the | |
261 | -- renamed entity has already been elaborated. | |
ca0cb93e | 262 | |
d4fc0fb4 AC |
263 | -- Note that it is legal for a renaming_as_body to rename an intrinsic |
264 | -- subprogram, as long as the renaming occurs before the new entity | |
ef1c0511 | 265 | -- is frozen (RM 8.5.4 (5)). |
d4fc0fb4 AC |
266 | |
267 | if Nkind (Body_Decl) = N_Subprogram_Renaming_Declaration | |
545cb5be | 268 | and then Is_Entity_Name (Name (Body_Decl)) |
d4fc0fb4 | 269 | then |
ca0cb93e AC |
270 | Renamed_Subp := Entity (Name (Body_Decl)); |
271 | else | |
272 | Renamed_Subp := Empty; | |
273 | end if; | |
274 | ||
275 | if Present (Renamed_Subp) | |
276 | and then Is_Intrinsic_Subprogram (Renamed_Subp) | |
ca0cb93e AC |
277 | and then |
278 | (not In_Same_Source_Unit (Renamed_Subp, Ent) | |
279 | or else Sloc (Renamed_Subp) < Sloc (Ent)) | |
879e23f0 | 280 | |
308e6f3a | 281 | -- We can make the renaming entity intrinsic if the renamed function |
545cb5be AC |
282 | -- has an interface name, or if it is one of the shift/rotate |
283 | -- operations known to the compiler. | |
879e23f0 | 284 | |
b69cd36a AC |
285 | and then |
286 | (Present (Interface_Name (Renamed_Subp)) | |
287 | or else Nam_In (Chars (Renamed_Subp), Name_Rotate_Left, | |
288 | Name_Rotate_Right, | |
289 | Name_Shift_Left, | |
290 | Name_Shift_Right, | |
291 | Name_Shift_Right_Arithmetic)) | |
ca0cb93e AC |
292 | then |
293 | Set_Interface_Name (Ent, Interface_Name (Renamed_Subp)); | |
545cb5be | 294 | |
ca0cb93e AC |
295 | if Present (Alias (Renamed_Subp)) then |
296 | Set_Alias (Ent, Alias (Renamed_Subp)); | |
d4fc0fb4 | 297 | else |
ca0cb93e | 298 | Set_Alias (Ent, Renamed_Subp); |
d4fc0fb4 AC |
299 | end if; |
300 | ||
301 | Set_Is_Intrinsic_Subprogram (Ent); | |
302 | Set_Has_Completion (Ent); | |
303 | ||
304 | else | |
305 | Body_Node := Build_Renamed_Body (Decl, New_S); | |
306 | Insert_After (After, Body_Node); | |
307 | Mark_Rewrite_Insertion (Body_Node); | |
308 | Analyze (Body_Node); | |
309 | After := Body_Node; | |
310 | end if; | |
70482933 RK |
311 | end Build_And_Analyze_Renamed_Body; |
312 | ||
313 | ------------------------ | |
314 | -- Build_Renamed_Body -- | |
315 | ------------------------ | |
316 | ||
317 | function Build_Renamed_Body | |
318 | (Decl : Node_Id; | |
fbf5a39b | 319 | New_S : Entity_Id) return Node_Id |
70482933 RK |
320 | is |
321 | Loc : constant Source_Ptr := Sloc (New_S); | |
545cb5be AC |
322 | -- We use for the source location of the renamed body, the location of |
323 | -- the spec entity. It might seem more natural to use the location of | |
324 | -- the renaming declaration itself, but that would be wrong, since then | |
325 | -- the body we create would look as though it was created far too late, | |
326 | -- and this could cause problems with elaboration order analysis, | |
327 | -- particularly in connection with instantiations. | |
70482933 RK |
328 | |
329 | N : constant Node_Id := Unit_Declaration_Node (New_S); | |
330 | Nam : constant Node_Id := Name (N); | |
331 | Old_S : Entity_Id; | |
332 | Spec : constant Node_Id := New_Copy_Tree (Specification (Decl)); | |
333 | Actuals : List_Id := No_List; | |
334 | Call_Node : Node_Id; | |
335 | Call_Name : Node_Id; | |
336 | Body_Node : Node_Id; | |
337 | Formal : Entity_Id; | |
338 | O_Formal : Entity_Id; | |
339 | Param_Spec : Node_Id; | |
340 | ||
def46b54 RD |
341 | Pref : Node_Id := Empty; |
342 | -- If the renamed entity is a primitive operation given in prefix form, | |
343 | -- the prefix is the target object and it has to be added as the first | |
344 | -- actual in the generated call. | |
345 | ||
70482933 | 346 | begin |
def46b54 RD |
347 | -- Determine the entity being renamed, which is the target of the call |
348 | -- statement. If the name is an explicit dereference, this is a renaming | |
349 | -- of a subprogram type rather than a subprogram. The name itself is | |
350 | -- fully analyzed. | |
70482933 RK |
351 | |
352 | if Nkind (Nam) = N_Selected_Component then | |
353 | Old_S := Entity (Selector_Name (Nam)); | |
354 | ||
355 | elsif Nkind (Nam) = N_Explicit_Dereference then | |
356 | Old_S := Etype (Nam); | |
357 | ||
358 | elsif Nkind (Nam) = N_Indexed_Component then | |
70482933 RK |
359 | if Is_Entity_Name (Prefix (Nam)) then |
360 | Old_S := Entity (Prefix (Nam)); | |
361 | else | |
362 | Old_S := Entity (Selector_Name (Prefix (Nam))); | |
363 | end if; | |
364 | ||
365 | elsif Nkind (Nam) = N_Character_Literal then | |
366 | Old_S := Etype (New_S); | |
367 | ||
368 | else | |
369 | Old_S := Entity (Nam); | |
370 | end if; | |
371 | ||
372 | if Is_Entity_Name (Nam) then | |
07fc65c4 | 373 | |
def46b54 RD |
374 | -- If the renamed entity is a predefined operator, retain full name |
375 | -- to ensure its visibility. | |
07fc65c4 GB |
376 | |
377 | if Ekind (Old_S) = E_Operator | |
378 | and then Nkind (Nam) = N_Expanded_Name | |
379 | then | |
380 | Call_Name := New_Copy (Name (N)); | |
381 | else | |
e4494292 | 382 | Call_Name := New_Occurrence_Of (Old_S, Loc); |
07fc65c4 GB |
383 | end if; |
384 | ||
70482933 | 385 | else |
def46b54 RD |
386 | if Nkind (Nam) = N_Selected_Component |
387 | and then Present (First_Formal (Old_S)) | |
388 | and then | |
389 | (Is_Controlling_Formal (First_Formal (Old_S)) | |
390 | or else Is_Class_Wide_Type (Etype (First_Formal (Old_S)))) | |
391 | then | |
392 | ||
393 | -- Retrieve the target object, to be added as a first actual | |
394 | -- in the call. | |
395 | ||
396 | Call_Name := New_Occurrence_Of (Old_S, Loc); | |
397 | Pref := Prefix (Nam); | |
398 | ||
399 | else | |
400 | Call_Name := New_Copy (Name (N)); | |
401 | end if; | |
70482933 | 402 | |
545cb5be | 403 | -- Original name may have been overloaded, but is fully resolved now |
70482933 RK |
404 | |
405 | Set_Is_Overloaded (Call_Name, False); | |
406 | end if; | |
407 | ||
def46b54 | 408 | -- For simple renamings, subsequent calls can be expanded directly as |
d4fc0fb4 | 409 | -- calls to the renamed entity. The body must be generated in any case |
a3068ca6 AC |
410 | -- for calls that may appear elsewhere. This is not done in the case |
411 | -- where the subprogram is an instantiation because the actual proper | |
412 | -- body has not been built yet. | |
70482933 | 413 | |
545cb5be | 414 | if Ekind_In (Old_S, E_Function, E_Procedure) |
70482933 | 415 | and then Nkind (Decl) = N_Subprogram_Declaration |
a3068ca6 | 416 | and then not Is_Generic_Instance (Old_S) |
70482933 RK |
417 | then |
418 | Set_Body_To_Inline (Decl, Old_S); | |
419 | end if; | |
420 | ||
28fa5430 AC |
421 | -- Check whether the return type is a limited view. If the subprogram |
422 | -- is already frozen the generated body may have a non-limited view | |
423 | -- of the type, that must be used, because it is the one in the spec | |
424 | -- of the renaming declaration. | |
425 | ||
426 | if Ekind (Old_S) = E_Function | |
427 | and then Is_Entity_Name (Result_Definition (Spec)) | |
428 | then | |
429 | declare | |
430 | Ret_Type : constant Entity_Id := Etype (Result_Definition (Spec)); | |
431 | begin | |
47346923 | 432 | if Has_Non_Limited_View (Ret_Type) then |
e23e04db AC |
433 | Set_Result_Definition |
434 | (Spec, New_Occurrence_Of (Non_Limited_View (Ret_Type), Loc)); | |
28fa5430 AC |
435 | end if; |
436 | end; | |
437 | end if; | |
438 | ||
70482933 RK |
439 | -- The body generated for this renaming is an internal artifact, and |
440 | -- does not constitute a freeze point for the called entity. | |
441 | ||
442 | Set_Must_Not_Freeze (Call_Name); | |
443 | ||
444 | Formal := First_Formal (Defining_Entity (Decl)); | |
445 | ||
def46b54 RD |
446 | if Present (Pref) then |
447 | declare | |
448 | Pref_Type : constant Entity_Id := Etype (Pref); | |
449 | Form_Type : constant Entity_Id := Etype (First_Formal (Old_S)); | |
450 | ||
451 | begin | |
def46b54 | 452 | -- The controlling formal may be an access parameter, or the |
e14c931f | 453 | -- actual may be an access value, so adjust accordingly. |
def46b54 RD |
454 | |
455 | if Is_Access_Type (Pref_Type) | |
456 | and then not Is_Access_Type (Form_Type) | |
457 | then | |
458 | Actuals := New_List | |
459 | (Make_Explicit_Dereference (Loc, Relocate_Node (Pref))); | |
460 | ||
461 | elsif Is_Access_Type (Form_Type) | |
462 | and then not Is_Access_Type (Pref) | |
463 | then | |
e23e04db AC |
464 | Actuals := |
465 | New_List ( | |
466 | Make_Attribute_Reference (Loc, | |
467 | Attribute_Name => Name_Access, | |
468 | Prefix => Relocate_Node (Pref))); | |
def46b54 RD |
469 | else |
470 | Actuals := New_List (Pref); | |
471 | end if; | |
472 | end; | |
473 | ||
474 | elsif Present (Formal) then | |
70482933 RK |
475 | Actuals := New_List; |
476 | ||
def46b54 RD |
477 | else |
478 | Actuals := No_List; | |
479 | end if; | |
480 | ||
481 | if Present (Formal) then | |
70482933 | 482 | while Present (Formal) loop |
e4494292 | 483 | Append (New_Occurrence_Of (Formal, Loc), Actuals); |
70482933 RK |
484 | Next_Formal (Formal); |
485 | end loop; | |
486 | end if; | |
487 | ||
def46b54 RD |
488 | -- If the renamed entity is an entry, inherit its profile. For other |
489 | -- renamings as bodies, both profiles must be subtype conformant, so it | |
490 | -- is not necessary to replace the profile given in the declaration. | |
491 | -- However, default values that are aggregates are rewritten when | |
492 | -- partially analyzed, so we recover the original aggregate to insure | |
493 | -- that subsequent conformity checking works. Similarly, if the default | |
494 | -- expression was constant-folded, recover the original expression. | |
70482933 RK |
495 | |
496 | Formal := First_Formal (Defining_Entity (Decl)); | |
497 | ||
498 | if Present (Formal) then | |
499 | O_Formal := First_Formal (Old_S); | |
500 | Param_Spec := First (Parameter_Specifications (Spec)); | |
70482933 RK |
501 | while Present (Formal) loop |
502 | if Is_Entry (Old_S) then | |
70482933 RK |
503 | if Nkind (Parameter_Type (Param_Spec)) /= |
504 | N_Access_Definition | |
505 | then | |
506 | Set_Etype (Formal, Etype (O_Formal)); | |
507 | Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal)); | |
508 | end if; | |
509 | ||
07fc65c4 GB |
510 | elsif Nkind (Default_Value (O_Formal)) = N_Aggregate |
511 | or else Nkind (Original_Node (Default_Value (O_Formal))) /= | |
512 | Nkind (Default_Value (O_Formal)) | |
513 | then | |
70482933 RK |
514 | Set_Expression (Param_Spec, |
515 | New_Copy_Tree (Original_Node (Default_Value (O_Formal)))); | |
516 | end if; | |
517 | ||
518 | Next_Formal (Formal); | |
519 | Next_Formal (O_Formal); | |
520 | Next (Param_Spec); | |
521 | end loop; | |
522 | end if; | |
523 | ||
524 | -- If the renamed entity is a function, the generated body contains a | |
525 | -- return statement. Otherwise, build a procedure call. If the entity is | |
526 | -- an entry, subsequent analysis of the call will transform it into the | |
527 | -- proper entry or protected operation call. If the renamed entity is | |
528 | -- a character literal, return it directly. | |
529 | ||
530 | if Ekind (Old_S) = E_Function | |
531 | or else Ekind (Old_S) = E_Operator | |
532 | or else (Ekind (Old_S) = E_Subprogram_Type | |
533 | and then Etype (Old_S) /= Standard_Void_Type) | |
534 | then | |
535 | Call_Node := | |
86cde7b1 | 536 | Make_Simple_Return_Statement (Loc, |
70482933 RK |
537 | Expression => |
538 | Make_Function_Call (Loc, | |
e23e04db | 539 | Name => Call_Name, |
70482933 RK |
540 | Parameter_Associations => Actuals)); |
541 | ||
542 | elsif Ekind (Old_S) = E_Enumeration_Literal then | |
543 | Call_Node := | |
86cde7b1 | 544 | Make_Simple_Return_Statement (Loc, |
70482933 RK |
545 | Expression => New_Occurrence_Of (Old_S, Loc)); |
546 | ||
547 | elsif Nkind (Nam) = N_Character_Literal then | |
548 | Call_Node := | |
e23e04db | 549 | Make_Simple_Return_Statement (Loc, Expression => Call_Name); |
70482933 RK |
550 | |
551 | else | |
552 | Call_Node := | |
553 | Make_Procedure_Call_Statement (Loc, | |
e23e04db | 554 | Name => Call_Name, |
70482933 RK |
555 | Parameter_Associations => Actuals); |
556 | end if; | |
557 | ||
49e90211 | 558 | -- Create entities for subprogram body and formals |
70482933 RK |
559 | |
560 | Set_Defining_Unit_Name (Spec, | |
561 | Make_Defining_Identifier (Loc, Chars => Chars (New_S))); | |
562 | ||
563 | Param_Spec := First (Parameter_Specifications (Spec)); | |
70482933 RK |
564 | while Present (Param_Spec) loop |
565 | Set_Defining_Identifier (Param_Spec, | |
566 | Make_Defining_Identifier (Loc, | |
567 | Chars => Chars (Defining_Identifier (Param_Spec)))); | |
568 | Next (Param_Spec); | |
569 | end loop; | |
570 | ||
571 | Body_Node := | |
572 | Make_Subprogram_Body (Loc, | |
573 | Specification => Spec, | |
574 | Declarations => New_List, | |
575 | Handled_Statement_Sequence => | |
576 | Make_Handled_Sequence_Of_Statements (Loc, | |
577 | Statements => New_List (Call_Node))); | |
578 | ||
579 | if Nkind (Decl) /= N_Subprogram_Declaration then | |
580 | Rewrite (N, | |
581 | Make_Subprogram_Declaration (Loc, | |
582 | Specification => Specification (N))); | |
583 | end if; | |
584 | ||
585 | -- Link the body to the entity whose declaration it completes. If | |
def46b54 RD |
586 | -- the body is analyzed when the renamed entity is frozen, it may |
587 | -- be necessary to restore the proper scope (see package Exp_Ch13). | |
70482933 | 588 | |
1b1d88b1 | 589 | if Nkind (N) = N_Subprogram_Renaming_Declaration |
70482933 RK |
590 | and then Present (Corresponding_Spec (N)) |
591 | then | |
592 | Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N)); | |
593 | else | |
594 | Set_Corresponding_Spec (Body_Node, New_S); | |
595 | end if; | |
596 | ||
597 | return Body_Node; | |
598 | end Build_Renamed_Body; | |
599 | ||
fbf5a39b AC |
600 | -------------------------- |
601 | -- Check_Address_Clause -- | |
602 | -------------------------- | |
603 | ||
604 | procedure Check_Address_Clause (E : Entity_Id) is | |
c31b57af EB |
605 | Addr : constant Node_Id := Address_Clause (E); |
606 | Typ : constant Entity_Id := Etype (E); | |
607 | Decl : Node_Id; | |
26b043e0 | 608 | Expr : Node_Id; |
c31b57af | 609 | Init : Node_Id; |
26b043e0 AC |
610 | Lhs : Node_Id; |
611 | Tag_Assign : Node_Id; | |
fbf5a39b AC |
612 | |
613 | begin | |
614 | if Present (Addr) then | |
c31b57af EB |
615 | |
616 | -- For a deferred constant, the initialization value is on full view | |
617 | ||
618 | if Ekind (E) = E_Constant and then Present (Full_View (E)) then | |
619 | Decl := Declaration_Node (Full_View (E)); | |
620 | else | |
621 | Decl := Declaration_Node (E); | |
622 | end if; | |
623 | ||
fbf5a39b AC |
624 | Expr := Expression (Addr); |
625 | ||
0d901290 | 626 | if Needs_Constant_Address (Decl, Typ) then |
fbf5a39b | 627 | Check_Constant_Address_Clause (Expr, E); |
f3b57ab0 AC |
628 | |
629 | -- Has_Delayed_Freeze was set on E when the address clause was | |
02217452 AC |
630 | -- analyzed, and must remain set because we want the address |
631 | -- clause to be elaborated only after any entity it references | |
632 | -- has been elaborated. | |
fbf5a39b AC |
633 | end if; |
634 | ||
1d57c04f AC |
635 | -- If Rep_Clauses are to be ignored, remove address clause from |
636 | -- list attached to entity, because it may be illegal for gigi, | |
637 | -- for example by breaking order of elaboration.. | |
638 | ||
639 | if Ignore_Rep_Clauses then | |
640 | declare | |
641 | Rep : Node_Id; | |
642 | ||
643 | begin | |
644 | Rep := First_Rep_Item (E); | |
645 | ||
646 | if Rep = Addr then | |
647 | Set_First_Rep_Item (E, Next_Rep_Item (Addr)); | |
648 | ||
649 | else | |
650 | while Present (Rep) | |
651 | and then Next_Rep_Item (Rep) /= Addr | |
652 | loop | |
653 | Rep := Next_Rep_Item (Rep); | |
654 | end loop; | |
655 | end if; | |
656 | ||
657 | if Present (Rep) then | |
658 | Set_Next_Rep_Item (Rep, Next_Rep_Item (Addr)); | |
659 | end if; | |
660 | end; | |
661 | ||
cf28c974 RD |
662 | -- And now remove the address clause |
663 | ||
664 | Kill_Rep_Clause (Addr); | |
1d57c04f AC |
665 | |
666 | elsif not Error_Posted (Expr) | |
048e5cef | 667 | and then not Needs_Finalization (Typ) |
fbf5a39b AC |
668 | then |
669 | Warn_Overlay (Expr, Typ, Name (Addr)); | |
670 | end if; | |
cf6956bb | 671 | |
c31b57af EB |
672 | Init := Expression (Decl); |
673 | ||
674 | -- If a variable, or a non-imported constant, overlays a constant | |
675 | -- object and has an initialization value, then the initialization | |
676 | -- may end up writing into read-only memory. Detect the cases of | |
677 | -- statically identical values and remove the initialization. In | |
678 | -- the other cases, give a warning. We will give other warnings | |
679 | -- later for the variable if it is assigned. | |
680 | ||
681 | if (Ekind (E) = E_Variable | |
d6dffa66 HK |
682 | or else (Ekind (E) = E_Constant |
683 | and then not Is_Imported (E))) | |
c31b57af EB |
684 | and then Overlays_Constant (E) |
685 | and then Present (Init) | |
686 | then | |
687 | declare | |
688 | O_Ent : Entity_Id; | |
689 | Off : Boolean; | |
d6dffa66 | 690 | |
c31b57af EB |
691 | begin |
692 | Find_Overlaid_Entity (Addr, O_Ent, Off); | |
693 | ||
694 | if Ekind (O_Ent) = E_Constant | |
695 | and then Etype (O_Ent) = Typ | |
696 | and then Present (Constant_Value (O_Ent)) | |
d6dffa66 HK |
697 | and then Compile_Time_Compare |
698 | (Init, | |
699 | Constant_Value (O_Ent), | |
700 | Assume_Valid => True) = EQ | |
c31b57af EB |
701 | then |
702 | Set_No_Initialization (Decl); | |
703 | return; | |
704 | ||
705 | elsif Comes_From_Source (Init) | |
706 | and then Address_Clause_Overlay_Warnings | |
707 | then | |
708 | Error_Msg_Sloc := Sloc (Addr); | |
709 | Error_Msg_NE | |
710 | ("??constant& may be modified via address clause#", | |
711 | Decl, O_Ent); | |
712 | end if; | |
713 | end; | |
714 | end if; | |
715 | ||
716 | if Present (Init) then | |
cf6956bb | 717 | |
26b043e0 AC |
718 | -- Capture initialization value at point of declaration, |
719 | -- and make explicit assignment legal, because object may | |
720 | -- be a constant. | |
cf6956bb | 721 | |
c31b57af EB |
722 | Remove_Side_Effects (Init); |
723 | Lhs := New_Occurrence_Of (E, Sloc (Decl)); | |
26b043e0 | 724 | Set_Assignment_OK (Lhs); |
cf6956bb | 725 | |
c31b57af EB |
726 | -- Move initialization to freeze actions, once the object has |
727 | -- been frozen and the address clause alignment check has been | |
cf6956bb AC |
728 | -- performed. |
729 | ||
730 | Append_Freeze_Action (E, | |
c31b57af | 731 | Make_Assignment_Statement (Sloc (Decl), |
26b043e0 | 732 | Name => Lhs, |
cf6956bb AC |
733 | Expression => Expression (Decl))); |
734 | ||
735 | Set_No_Initialization (Decl); | |
26b043e0 AC |
736 | |
737 | -- If the objet is tagged, check whether the tag must be | |
c31b57af | 738 | -- reassigned explicitly. |
26b043e0 AC |
739 | |
740 | Tag_Assign := Make_Tag_Assignment (Decl); | |
741 | if Present (Tag_Assign) then | |
742 | Append_Freeze_Action (E, Tag_Assign); | |
743 | end if; | |
cf6956bb | 744 | end if; |
fbf5a39b AC |
745 | end if; |
746 | end Check_Address_Clause; | |
747 | ||
70482933 RK |
748 | ----------------------------- |
749 | -- Check_Compile_Time_Size -- | |
750 | ----------------------------- | |
751 | ||
752 | procedure Check_Compile_Time_Size (T : Entity_Id) is | |
753 | ||
c6823a20 | 754 | procedure Set_Small_Size (T : Entity_Id; S : Uint); |
34da9c98 EB |
755 | -- Sets the compile time known size (64 bits or less) in the RM_Size |
756 | -- field of T, checking for a size clause that was given which attempts | |
757 | -- to give a smaller size. | |
70482933 RK |
758 | |
759 | function Size_Known (T : Entity_Id) return Boolean; | |
07fc65c4 | 760 | -- Recursive function that does all the work |
70482933 RK |
761 | |
762 | function Static_Discriminated_Components (T : Entity_Id) return Boolean; | |
763 | -- If T is a constrained subtype, its size is not known if any of its | |
764 | -- discriminant constraints is not static and it is not a null record. | |
fbf5a39b | 765 | -- The test is conservative and doesn't check that the components are |
70482933 RK |
766 | -- in fact constrained by non-static discriminant values. Could be made |
767 | -- more precise ??? | |
768 | ||
769 | -------------------- | |
770 | -- Set_Small_Size -- | |
771 | -------------------- | |
772 | ||
c6823a20 | 773 | procedure Set_Small_Size (T : Entity_Id; S : Uint) is |
70482933 | 774 | begin |
34da9c98 | 775 | if S > 64 then |
70482933 RK |
776 | return; |
777 | ||
2593c3e1 AC |
778 | -- Check for bad size clause given |
779 | ||
70482933 RK |
780 | elsif Has_Size_Clause (T) then |
781 | if RM_Size (T) < S then | |
782 | Error_Msg_Uint_1 := S; | |
783 | Error_Msg_NE | |
d58b9515 | 784 | ("size for& too small, minimum allowed is ^", |
70482933 | 785 | Size_Clause (T), T); |
70482933 RK |
786 | end if; |
787 | ||
fc893455 | 788 | -- Set size if not set already |
70482933 | 789 | |
fc893455 AC |
790 | elsif Unknown_RM_Size (T) then |
791 | Set_RM_Size (T, S); | |
70482933 RK |
792 | end if; |
793 | end Set_Small_Size; | |
794 | ||
795 | ---------------- | |
796 | -- Size_Known -- | |
797 | ---------------- | |
798 | ||
799 | function Size_Known (T : Entity_Id) return Boolean is | |
800 | Index : Entity_Id; | |
801 | Comp : Entity_Id; | |
802 | Ctyp : Entity_Id; | |
803 | Low : Node_Id; | |
804 | High : Node_Id; | |
805 | ||
806 | begin | |
807 | if Size_Known_At_Compile_Time (T) then | |
808 | return True; | |
809 | ||
34da9c98 EB |
810 | -- Always True for elementary types, even generic formal elementary |
811 | -- types. We used to return False in the latter case, but the size | |
812 | -- is known at compile time, even in the template, we just do not | |
813 | -- know the exact size but that's not the point of this routine. | |
c6a9797e | 814 | |
34da9c98 | 815 | elsif Is_Elementary_Type (T) or else Is_Task_Type (T) then |
c6a9797e RD |
816 | return True; |
817 | ||
818 | -- Array types | |
70482933 RK |
819 | |
820 | elsif Is_Array_Type (T) then | |
c6a9797e RD |
821 | |
822 | -- String literals always have known size, and we can set it | |
823 | ||
70482933 | 824 | if Ekind (T) = E_String_Literal_Subtype then |
34da9c98 EB |
825 | Set_Small_Size |
826 | (T, Component_Size (T) * String_Literal_Length (T)); | |
70482933 RK |
827 | return True; |
828 | ||
c6a9797e RD |
829 | -- Unconstrained types never have known at compile time size |
830 | ||
70482933 RK |
831 | elsif not Is_Constrained (T) then |
832 | return False; | |
833 | ||
def46b54 RD |
834 | -- Don't do any recursion on type with error posted, since we may |
835 | -- have a malformed type that leads us into a loop. | |
07fc65c4 GB |
836 | |
837 | elsif Error_Posted (T) then | |
838 | return False; | |
839 | ||
c6a9797e RD |
840 | -- Otherwise if component size unknown, then array size unknown |
841 | ||
70482933 RK |
842 | elsif not Size_Known (Component_Type (T)) then |
843 | return False; | |
844 | end if; | |
845 | ||
def46b54 | 846 | -- Check for all indexes static, and also compute possible size |
34da9c98 | 847 | -- (in case it is not greater than 64 and may be packable). |
70482933 RK |
848 | |
849 | declare | |
34da9c98 | 850 | Size : Uint := Component_Size (T); |
70482933 RK |
851 | Dim : Uint; |
852 | ||
853 | begin | |
854 | Index := First_Index (T); | |
70482933 RK |
855 | while Present (Index) loop |
856 | if Nkind (Index) = N_Range then | |
857 | Get_Index_Bounds (Index, Low, High); | |
858 | ||
859 | elsif Error_Posted (Scalar_Range (Etype (Index))) then | |
860 | return False; | |
861 | ||
862 | else | |
863 | Low := Type_Low_Bound (Etype (Index)); | |
864 | High := Type_High_Bound (Etype (Index)); | |
865 | end if; | |
866 | ||
867 | if not Compile_Time_Known_Value (Low) | |
868 | or else not Compile_Time_Known_Value (High) | |
869 | or else Etype (Index) = Any_Type | |
870 | then | |
871 | return False; | |
872 | ||
873 | else | |
874 | Dim := Expr_Value (High) - Expr_Value (Low) + 1; | |
875 | ||
876 | if Dim >= 0 then | |
34da9c98 | 877 | Size := Size * Dim; |
70482933 | 878 | else |
34da9c98 | 879 | Size := Uint_0; |
70482933 RK |
880 | end if; |
881 | end if; | |
882 | ||
883 | Next_Index (Index); | |
884 | end loop; | |
885 | ||
34da9c98 | 886 | Set_Small_Size (T, Size); |
70482933 RK |
887 | return True; |
888 | end; | |
889 | ||
c6a9797e RD |
890 | -- For non-generic private types, go to underlying type if present |
891 | ||
70482933 RK |
892 | elsif Is_Private_Type (T) |
893 | and then not Is_Generic_Type (T) | |
894 | and then Present (Underlying_Type (T)) | |
895 | then | |
def46b54 RD |
896 | -- Don't do any recursion on type with error posted, since we may |
897 | -- have a malformed type that leads us into a loop. | |
07fc65c4 GB |
898 | |
899 | if Error_Posted (T) then | |
900 | return False; | |
901 | else | |
902 | return Size_Known (Underlying_Type (T)); | |
903 | end if; | |
70482933 | 904 | |
c6a9797e RD |
905 | -- Record types |
906 | ||
70482933 | 907 | elsif Is_Record_Type (T) then |
fbf5a39b AC |
908 | |
909 | -- A class-wide type is never considered to have a known size | |
910 | ||
70482933 RK |
911 | if Is_Class_Wide_Type (T) then |
912 | return False; | |
913 | ||
fbf5a39b | 914 | -- A subtype of a variant record must not have non-static |
308e6f3a | 915 | -- discriminated components. |
fbf5a39b AC |
916 | |
917 | elsif T /= Base_Type (T) | |
918 | and then not Static_Discriminated_Components (T) | |
919 | then | |
920 | return False; | |
70482933 | 921 | |
def46b54 RD |
922 | -- Don't do any recursion on type with error posted, since we may |
923 | -- have a malformed type that leads us into a loop. | |
07fc65c4 GB |
924 | |
925 | elsif Error_Posted (T) then | |
926 | return False; | |
fbf5a39b | 927 | end if; |
07fc65c4 | 928 | |
fbf5a39b | 929 | -- Now look at the components of the record |
70482933 | 930 | |
fbf5a39b | 931 | declare |
def46b54 RD |
932 | -- The following two variables are used to keep track of the |
933 | -- size of packed records if we can tell the size of the packed | |
934 | -- record in the front end. Packed_Size_Known is True if so far | |
935 | -- we can figure out the size. It is initialized to True for a | |
ca1ffed0 AC |
936 | -- packed record, unless the record has discriminants or atomic |
937 | -- components or independent components. | |
938 | ||
939 | -- The reason we eliminate the discriminated case is that | |
940 | -- we don't know the way the back end lays out discriminated | |
941 | -- packed records. If Packed_Size_Known is True, then | |
942 | -- Packed_Size is the size in bits so far. | |
fbf5a39b AC |
943 | |
944 | Packed_Size_Known : Boolean := | |
ca1ffed0 AC |
945 | Is_Packed (T) |
946 | and then not Has_Discriminants (T) | |
947 | and then not Has_Atomic_Components (T) | |
948 | and then not Has_Independent_Components (T); | |
fbf5a39b AC |
949 | |
950 | Packed_Size : Uint := Uint_0; | |
515490e0 | 951 | -- Size in bits so far |
fbf5a39b AC |
952 | |
953 | begin | |
954 | -- Test for variant part present | |
955 | ||
956 | if Has_Discriminants (T) | |
957 | and then Present (Parent (T)) | |
958 | and then Nkind (Parent (T)) = N_Full_Type_Declaration | |
959 | and then Nkind (Type_Definition (Parent (T))) = | |
545cb5be | 960 | N_Record_Definition |
fbf5a39b | 961 | and then not Null_Present (Type_Definition (Parent (T))) |
15918371 AC |
962 | and then |
963 | Present (Variant_Part | |
964 | (Component_List (Type_Definition (Parent (T))))) | |
fbf5a39b AC |
965 | then |
966 | -- If variant part is present, and type is unconstrained, | |
967 | -- then we must have defaulted discriminants, or a size | |
968 | -- clause must be present for the type, or else the size | |
969 | -- is definitely not known at compile time. | |
970 | ||
971 | if not Is_Constrained (T) | |
972 | and then | |
545cb5be | 973 | No (Discriminant_Default_Value (First_Discriminant (T))) |
fc893455 | 974 | and then Unknown_RM_Size (T) |
70482933 | 975 | then |
fbf5a39b AC |
976 | return False; |
977 | end if; | |
978 | end if; | |
70482933 | 979 | |
fbf5a39b AC |
980 | -- Loop through components |
981 | ||
fea9e956 | 982 | Comp := First_Component_Or_Discriminant (T); |
fbf5a39b | 983 | while Present (Comp) loop |
fea9e956 | 984 | Ctyp := Etype (Comp); |
fbf5a39b | 985 | |
fea9e956 ES |
986 | -- We do not know the packed size if there is a component |
987 | -- clause present (we possibly could, but this would only | |
988 | -- help in the case of a record with partial rep clauses. | |
989 | -- That's because in the case of full rep clauses, the | |
990 | -- size gets figured out anyway by a different circuit). | |
fbf5a39b | 991 | |
fea9e956 ES |
992 | if Present (Component_Clause (Comp)) then |
993 | Packed_Size_Known := False; | |
994 | end if; | |
70482933 | 995 | |
f280dd8f | 996 | -- We do not know the packed size for an atomic/VFA type |
07aff4e3 | 997 | -- or component, or an independent type or component, or a |
088c7e1b | 998 | -- by-reference type or aliased component (because packing |
07aff4e3 | 999 | -- does not touch these). |
ca1ffed0 | 1000 | |
f280dd8f RD |
1001 | if Is_Atomic_Or_VFA (Ctyp) |
1002 | or else Is_Atomic_Or_VFA (Comp) | |
07aff4e3 AC |
1003 | or else Is_Independent (Ctyp) |
1004 | or else Is_Independent (Comp) | |
ca1ffed0 | 1005 | or else Is_By_Reference_Type (Ctyp) |
515490e0 | 1006 | or else Is_Aliased (Comp) |
ca1ffed0 AC |
1007 | then |
1008 | Packed_Size_Known := False; | |
1009 | end if; | |
1010 | ||
fea9e956 ES |
1011 | -- We need to identify a component that is an array where |
1012 | -- the index type is an enumeration type with non-standard | |
1013 | -- representation, and some bound of the type depends on a | |
1014 | -- discriminant. | |
70482933 | 1015 | |
fea9e956 | 1016 | -- This is because gigi computes the size by doing a |
e14c931f | 1017 | -- substitution of the appropriate discriminant value in |
fea9e956 ES |
1018 | -- the size expression for the base type, and gigi is not |
1019 | -- clever enough to evaluate the resulting expression (which | |
1020 | -- involves a call to rep_to_pos) at compile time. | |
fbf5a39b | 1021 | |
fea9e956 ES |
1022 | -- It would be nice if gigi would either recognize that |
1023 | -- this expression can be computed at compile time, or | |
1024 | -- alternatively figured out the size from the subtype | |
1025 | -- directly, where all the information is at hand ??? | |
fbf5a39b | 1026 | |
fea9e956 | 1027 | if Is_Array_Type (Etype (Comp)) |
8ca597af | 1028 | and then Present (Packed_Array_Impl_Type (Etype (Comp))) |
fea9e956 ES |
1029 | then |
1030 | declare | |
1031 | Ocomp : constant Entity_Id := | |
1032 | Original_Record_Component (Comp); | |
1033 | OCtyp : constant Entity_Id := Etype (Ocomp); | |
1034 | Ind : Node_Id; | |
1035 | Indtyp : Entity_Id; | |
1036 | Lo, Hi : Node_Id; | |
70482933 | 1037 | |
fea9e956 ES |
1038 | begin |
1039 | Ind := First_Index (OCtyp); | |
1040 | while Present (Ind) loop | |
1041 | Indtyp := Etype (Ind); | |
70482933 | 1042 | |
fea9e956 ES |
1043 | if Is_Enumeration_Type (Indtyp) |
1044 | and then Has_Non_Standard_Rep (Indtyp) | |
1045 | then | |
1046 | Lo := Type_Low_Bound (Indtyp); | |
1047 | Hi := Type_High_Bound (Indtyp); | |
fbf5a39b | 1048 | |
fea9e956 ES |
1049 | if Is_Entity_Name (Lo) |
1050 | and then Ekind (Entity (Lo)) = E_Discriminant | |
1051 | then | |
1052 | return False; | |
fbf5a39b | 1053 | |
fea9e956 ES |
1054 | elsif Is_Entity_Name (Hi) |
1055 | and then Ekind (Entity (Hi)) = E_Discriminant | |
1056 | then | |
1057 | return False; | |
1058 | end if; | |
1059 | end if; | |
fbf5a39b | 1060 | |
fea9e956 ES |
1061 | Next_Index (Ind); |
1062 | end loop; | |
1063 | end; | |
1064 | end if; | |
70482933 | 1065 | |
def46b54 RD |
1066 | -- Clearly size of record is not known if the size of one of |
1067 | -- the components is not known. | |
70482933 | 1068 | |
fea9e956 ES |
1069 | if not Size_Known (Ctyp) then |
1070 | return False; | |
1071 | end if; | |
70482933 | 1072 | |
fea9e956 | 1073 | -- Accumulate packed size if possible |
70482933 | 1074 | |
fea9e956 | 1075 | if Packed_Size_Known then |
70482933 | 1076 | |
34da9c98 EB |
1077 | -- We can deal with elementary types, small packed arrays |
1078 | -- if the representation is a modular type and also small | |
1079 | -- record types (if the size is not greater than 64, but | |
1080 | -- the condition is checked by Set_Small_Size). | |
fbf5a39b | 1081 | |
fea9e956 ES |
1082 | if Is_Elementary_Type (Ctyp) |
1083 | or else (Is_Array_Type (Ctyp) | |
8ca597af RD |
1084 | and then Present |
1085 | (Packed_Array_Impl_Type (Ctyp)) | |
2593c3e1 | 1086 | and then Is_Modular_Integer_Type |
8ca597af | 1087 | (Packed_Array_Impl_Type (Ctyp))) |
34da9c98 | 1088 | or else Is_Record_Type (Ctyp) |
fea9e956 | 1089 | then |
2593c3e1 | 1090 | -- If RM_Size is known and static, then we can keep |
34da9c98 | 1091 | -- accumulating the packed size. |
fea9e956 | 1092 | |
34da9c98 | 1093 | if Known_Static_RM_Size (Ctyp) then |
fea9e956 | 1094 | |
34da9c98 | 1095 | Packed_Size := Packed_Size + RM_Size (Ctyp); |
fbf5a39b | 1096 | |
fea9e956 ES |
1097 | -- If we have a field whose RM_Size is not known then |
1098 | -- we can't figure out the packed size here. | |
fbf5a39b AC |
1099 | |
1100 | else | |
1101 | Packed_Size_Known := False; | |
70482933 | 1102 | end if; |
fea9e956 | 1103 | |
34da9c98 | 1104 | -- For other types we can't figure out the packed size |
fea9e956 ES |
1105 | |
1106 | else | |
1107 | Packed_Size_Known := False; | |
70482933 | 1108 | end if; |
fbf5a39b | 1109 | end if; |
70482933 | 1110 | |
fea9e956 | 1111 | Next_Component_Or_Discriminant (Comp); |
fbf5a39b | 1112 | end loop; |
70482933 | 1113 | |
fbf5a39b | 1114 | if Packed_Size_Known then |
c6823a20 | 1115 | Set_Small_Size (T, Packed_Size); |
fbf5a39b | 1116 | end if; |
70482933 | 1117 | |
fbf5a39b AC |
1118 | return True; |
1119 | end; | |
70482933 | 1120 | |
c6a9797e RD |
1121 | -- All other cases, size not known at compile time |
1122 | ||
70482933 RK |
1123 | else |
1124 | return False; | |
1125 | end if; | |
1126 | end Size_Known; | |
1127 | ||
1128 | ------------------------------------- | |
1129 | -- Static_Discriminated_Components -- | |
1130 | ------------------------------------- | |
1131 | ||
1132 | function Static_Discriminated_Components | |
0da2c8ac | 1133 | (T : Entity_Id) return Boolean |
70482933 RK |
1134 | is |
1135 | Constraint : Elmt_Id; | |
1136 | ||
1137 | begin | |
1138 | if Has_Discriminants (T) | |
1139 | and then Present (Discriminant_Constraint (T)) | |
1140 | and then Present (First_Component (T)) | |
1141 | then | |
1142 | Constraint := First_Elmt (Discriminant_Constraint (T)); | |
70482933 RK |
1143 | while Present (Constraint) loop |
1144 | if not Compile_Time_Known_Value (Node (Constraint)) then | |
1145 | return False; | |
1146 | end if; | |
1147 | ||
1148 | Next_Elmt (Constraint); | |
1149 | end loop; | |
1150 | end if; | |
1151 | ||
1152 | return True; | |
1153 | end Static_Discriminated_Components; | |
1154 | ||
1155 | -- Start of processing for Check_Compile_Time_Size | |
1156 | ||
1157 | begin | |
1158 | Set_Size_Known_At_Compile_Time (T, Size_Known (T)); | |
1159 | end Check_Compile_Time_Size; | |
1160 | ||
75965852 AC |
1161 | ----------------------------------- |
1162 | -- Check_Component_Storage_Order -- | |
1163 | ----------------------------------- | |
1164 | ||
1165 | procedure Check_Component_Storage_Order | |
ee6208f2 AC |
1166 | (Encl_Type : Entity_Id; |
1167 | Comp : Entity_Id; | |
1168 | ADC : Node_Id; | |
1169 | Comp_ADC_Present : out Boolean) | |
75965852 | 1170 | is |
6232acb7 | 1171 | Comp_Base : Entity_Id; |
8a7c0400 | 1172 | Comp_ADC : Node_Id; |
5a527952 | 1173 | Encl_Base : Entity_Id; |
75965852 | 1174 | Err_Node : Node_Id; |
75965852 | 1175 | |
5a527952 AC |
1176 | Component_Aliased : Boolean; |
1177 | ||
5df1266a | 1178 | Comp_Byte_Aligned : Boolean; |
e191e5ae | 1179 | -- Set for the record case, True if Comp starts on a byte boundary |
5df1266a AC |
1180 | -- (in which case it is allowed to have different storage order). |
1181 | ||
637a41a5 AC |
1182 | Comp_SSO_Differs : Boolean; |
1183 | -- Set True when the component is a nested composite, and it does not | |
1184 | -- have the same scalar storage order as Encl_Type. | |
1185 | ||
75965852 AC |
1186 | begin |
1187 | -- Record case | |
1188 | ||
1189 | if Present (Comp) then | |
1190 | Err_Node := Comp; | |
6232acb7 | 1191 | Comp_Base := Etype (Comp); |
75965852 | 1192 | |
4ff4293f | 1193 | if Is_Tag (Comp) then |
4ff4293f | 1194 | Comp_Byte_Aligned := True; |
11d59a86 | 1195 | Component_Aliased := False; |
4ff4293f AC |
1196 | |
1197 | else | |
8b034336 AC |
1198 | -- If a component clause is present, check if the component starts |
1199 | -- on a storage element boundary. Otherwise conservatively assume | |
1200 | -- it does so only in the case where the record is not packed. | |
e191e5ae TQ |
1201 | |
1202 | if Present (Component_Clause (Comp)) then | |
1203 | Comp_Byte_Aligned := | |
1204 | Normalized_First_Bit (Comp) mod System_Storage_Unit = 0; | |
1205 | else | |
1206 | Comp_Byte_Aligned := not Is_Packed (Encl_Type); | |
1207 | end if; | |
1208 | ||
11d59a86 | 1209 | Component_Aliased := Is_Aliased (Comp); |
4ff4293f | 1210 | end if; |
5df1266a | 1211 | |
75965852 AC |
1212 | -- Array case |
1213 | ||
1214 | else | |
1215 | Err_Node := Encl_Type; | |
6232acb7 | 1216 | Comp_Base := Component_Type (Encl_Type); |
5df1266a | 1217 | |
11d59a86 | 1218 | Component_Aliased := Has_Aliased_Components (Encl_Type); |
75965852 AC |
1219 | end if; |
1220 | ||
b3408631 RD |
1221 | -- Note: the Reverse_Storage_Order flag is set on the base type, but |
1222 | -- the attribute definition clause is attached to the first subtype. | |
6232acb7 TQ |
1223 | -- Also, if the base type is incomplete or private, go to full view |
1224 | -- if known | |
75965852 | 1225 | |
6232acb7 TQ |
1226 | Encl_Base := Base_Type (Encl_Type); |
1227 | if Present (Underlying_Type (Encl_Base)) then | |
1228 | Encl_Base := Underlying_Type (Encl_Base); | |
1229 | end if; | |
a25ad01c | 1230 | |
6232acb7 TQ |
1231 | Comp_Base := Base_Type (Comp_Base); |
1232 | if Present (Underlying_Type (Comp_Base)) then | |
1233 | Comp_Base := Underlying_Type (Comp_Base); | |
a25ad01c TQ |
1234 | end if; |
1235 | ||
5a527952 AC |
1236 | Comp_ADC := |
1237 | Get_Attribute_Definition_Clause | |
1238 | (First_Subtype (Comp_Base), Attribute_Scalar_Storage_Order); | |
ee6208f2 | 1239 | Comp_ADC_Present := Present (Comp_ADC); |
75965852 | 1240 | |
dc9111cf EB |
1241 | -- Case of record or array component: check storage order compatibility. |
1242 | -- But, if the record has Complex_Representation, then it is treated as | |
1243 | -- a scalar in the back end so the storage order is irrelevant. | |
8a7c0400 | 1244 | |
6232acb7 TQ |
1245 | if (Is_Record_Type (Comp_Base) |
1246 | and then not Has_Complex_Representation (Comp_Base)) | |
1247 | or else Is_Array_Type (Comp_Base) | |
dc9111cf | 1248 | then |
637a41a5 | 1249 | Comp_SSO_Differs := |
5a527952 AC |
1250 | Reverse_Storage_Order (Encl_Base) /= |
1251 | Reverse_Storage_Order (Comp_Base); | |
637a41a5 | 1252 | |
6782b1ef AC |
1253 | -- Parent and extension must have same storage order |
1254 | ||
ae05cdd6 | 1255 | if Present (Comp) and then Chars (Comp) = Name_uParent then |
637a41a5 | 1256 | if Comp_SSO_Differs then |
8190087e AC |
1257 | Error_Msg_N |
1258 | ("record extension must have same scalar storage order as " | |
1259 | & "parent", Err_Node); | |
1260 | end if; | |
1261 | ||
6782b1ef | 1262 | -- If component and composite SSO differs, check that component |
b3f75672 | 1263 | -- falls on byte boundaries and isn't bit packed. |
6782b1ef | 1264 | |
637a41a5 AC |
1265 | elsif Comp_SSO_Differs then |
1266 | ||
1267 | -- Component SSO differs from enclosing composite: | |
1268 | ||
b3f75672 | 1269 | -- Reject if component is a bit-packed array, as it is represented |
637a41a5 AC |
1270 | -- as a scalar internally. |
1271 | ||
b3f75672 | 1272 | if Is_Bit_Packed_Array (Comp_Base) then |
637a41a5 | 1273 | Error_Msg_N |
558fbeb0 HK |
1274 | ("type of packed component must have same scalar storage " |
1275 | & "order as enclosing composite", Err_Node); | |
637a41a5 | 1276 | |
b3f75672 | 1277 | -- Reject if composite is a bit-packed array, as it is rewritten |
e191e5ae TQ |
1278 | -- into an array of scalars. |
1279 | ||
b3f75672 | 1280 | elsif Is_Bit_Packed_Array (Encl_Base) then |
558fbeb0 HK |
1281 | Error_Msg_N |
1282 | ("type of packed array must have same scalar storage order " | |
1283 | & "as component", Err_Node); | |
e191e5ae | 1284 | |
637a41a5 AC |
1285 | -- Reject if not byte aligned |
1286 | ||
6232acb7 | 1287 | elsif Is_Record_Type (Encl_Base) |
558fbeb0 | 1288 | and then not Comp_Byte_Aligned |
e191e5ae | 1289 | then |
637a41a5 AC |
1290 | Error_Msg_N |
1291 | ("type of non-byte-aligned component must have same scalar " | |
1292 | & "storage order as enclosing composite", Err_Node); | |
1e60643a AC |
1293 | |
1294 | -- Warn if specified only for the outer composite | |
1295 | ||
1296 | elsif Present (ADC) and then No (Comp_ADC) then | |
1297 | Error_Msg_NE | |
558fbeb0 | 1298 | ("scalar storage order specified for & does not apply to " |
6232acb7 | 1299 | & "component?", Err_Node, Encl_Base); |
637a41a5 | 1300 | end if; |
5df1266a | 1301 | end if; |
75965852 | 1302 | |
6782b1ef | 1303 | -- Enclosing type has explicit SSO: non-composite component must not |
8a7c0400 AC |
1304 | -- be aliased. |
1305 | ||
6782b1ef | 1306 | elsif Present (ADC) and then Component_Aliased then |
b3408631 | 1307 | Error_Msg_N |
558fbeb0 HK |
1308 | ("aliased component not permitted for type with explicit " |
1309 | & "Scalar_Storage_Order", Err_Node); | |
75965852 AC |
1310 | end if; |
1311 | end Check_Component_Storage_Order; | |
1312 | ||
70482933 RK |
1313 | ----------------------------- |
1314 | -- Check_Debug_Info_Needed -- | |
1315 | ----------------------------- | |
1316 | ||
1317 | procedure Check_Debug_Info_Needed (T : Entity_Id) is | |
1318 | begin | |
1b24ada5 | 1319 | if Debug_Info_Off (T) then |
70482933 RK |
1320 | return; |
1321 | ||
1322 | elsif Comes_From_Source (T) | |
1323 | or else Debug_Generated_Code | |
1324 | or else Debug_Flag_VV | |
1b24ada5 | 1325 | or else Needs_Debug_Info (T) |
70482933 RK |
1326 | then |
1327 | Set_Debug_Info_Needed (T); | |
1328 | end if; | |
1329 | end Check_Debug_Info_Needed; | |
1330 | ||
18c56840 ES |
1331 | ------------------------------- |
1332 | -- Check_Expression_Function -- | |
1333 | ------------------------------- | |
1334 | ||
1335 | procedure Check_Expression_Function (N : Node_Id; Nam : Entity_Id) is | |
18c56840 ES |
1336 | function Find_Constant (Nod : Node_Id) return Traverse_Result; |
1337 | -- Function to search for deferred constant | |
1338 | ||
1339 | ------------------- | |
1340 | -- Find_Constant -- | |
1341 | ------------------- | |
1342 | ||
1343 | function Find_Constant (Nod : Node_Id) return Traverse_Result is | |
1344 | begin | |
4b259b2d AC |
1345 | -- When a constant is initialized with the result of a dispatching |
1346 | -- call, the constant declaration is rewritten as a renaming of the | |
1347 | -- displaced function result. This scenario is not a premature use of | |
1348 | -- a constant even though the Has_Completion flag is not set. | |
1349 | ||
18c56840 ES |
1350 | if Is_Entity_Name (Nod) |
1351 | and then Present (Entity (Nod)) | |
1352 | and then Ekind (Entity (Nod)) = E_Constant | |
4b259b2d AC |
1353 | and then Scope (Entity (Nod)) = Current_Scope |
1354 | and then Nkind (Declaration_Node (Entity (Nod))) = | |
1355 | N_Object_Declaration | |
18c56840 ES |
1356 | and then not Is_Imported (Entity (Nod)) |
1357 | and then not Has_Completion (Entity (Nod)) | |
2a02fa98 | 1358 | and then not Is_Frozen (Entity (Nod)) |
18c56840 ES |
1359 | then |
1360 | Error_Msg_NE | |
1361 | ("premature use of& in call or instance", N, Entity (Nod)); | |
3ad33e33 AC |
1362 | |
1363 | elsif Nkind (Nod) = N_Attribute_Reference then | |
1364 | Analyze (Prefix (Nod)); | |
e8de1a82 | 1365 | |
3ad33e33 AC |
1366 | if Is_Entity_Name (Prefix (Nod)) |
1367 | and then Is_Type (Entity (Prefix (Nod))) | |
1368 | then | |
1369 | Freeze_Before (N, Entity (Prefix (Nod))); | |
1370 | end if; | |
18c56840 ES |
1371 | end if; |
1372 | ||
1373 | return OK; | |
1374 | end Find_Constant; | |
1375 | ||
1376 | procedure Check_Deferred is new Traverse_Proc (Find_Constant); | |
1377 | ||
d43584ca AC |
1378 | -- Local variables |
1379 | ||
1380 | Decl : Node_Id; | |
1381 | ||
18c56840 ES |
1382 | -- Start of processing for Check_Expression_Function |
1383 | ||
1384 | begin | |
1385 | Decl := Original_Node (Unit_Declaration_Node (Nam)); | |
1386 | ||
b5360737 AC |
1387 | -- The subprogram body created for the expression function is not |
1388 | -- itself a freeze point. | |
1389 | ||
18c56840 ES |
1390 | if Scope (Nam) = Current_Scope |
1391 | and then Nkind (Decl) = N_Expression_Function | |
b5360737 | 1392 | and then Nkind (N) /= N_Subprogram_Body |
18c56840 ES |
1393 | then |
1394 | Check_Deferred (Expression (Decl)); | |
1395 | end if; | |
1396 | end Check_Expression_Function; | |
1397 | ||
017d237e ES |
1398 | -------------------------------- |
1399 | -- Check_Inherited_Conditions -- | |
1400 | -------------------------------- | |
1401 | ||
1402 | procedure Check_Inherited_Conditions (R : Entity_Id) is | |
a187206c AC |
1403 | Prim_Ops : constant Elist_Id := Primitive_Operations (R); |
1404 | A_Post : Node_Id; | |
1405 | A_Pre : Node_Id; | |
1406 | Decls : List_Id; | |
b41c731f AC |
1407 | Needs_Wrapper : Boolean; |
1408 | New_Prag : Node_Id; | |
a187206c AC |
1409 | Op_Node : Elmt_Id; |
1410 | Par_Prim : Entity_Id; | |
1411 | Par_Type : Entity_Id; | |
a187206c | 1412 | Prim : Entity_Id; |
017d237e ES |
1413 | |
1414 | begin | |
1415 | Op_Node := First_Elmt (Prim_Ops); | |
1416 | while Present (Op_Node) loop | |
a187206c AC |
1417 | Prim := Node (Op_Node); |
1418 | Needs_Wrapper := False; | |
017d237e | 1419 | |
015f33d7 AC |
1420 | -- Map the overridden primitive to the overriding one. This takes |
1421 | -- care of all overridings and is done only once. | |
002e3d16 ES |
1422 | |
1423 | if Present (Overridden_Operation (Prim)) | |
f31dcd99 | 1424 | and then Comes_From_Source (Prim) |
017d237e | 1425 | then |
002e3d16 ES |
1426 | Update_Primitives_Mapping (Overridden_Operation (Prim), Prim); |
1427 | ||
1428 | -- In SPARK mode this is where we can collect the inherited | |
1429 | -- conditions, because we do not create the Check pragmas that | |
8c519039 | 1430 | -- normally convey the the modified class-wide conditions on |
002e3d16 ES |
1431 | -- overriding operations. |
1432 | ||
1433 | if SPARK_Mode = On then | |
0e77949e AC |
1434 | |
1435 | -- Analyze the contract items of the parent operation, before | |
1436 | -- they are rewritten when inherited. | |
1437 | ||
1438 | Analyze_Entry_Or_Subprogram_Contract | |
1439 | (Overridden_Operation (Prim)); | |
1440 | ||
1441 | -- Now verify the legality of inherited contracts for LSP | |
1442 | -- conformance. | |
1443 | ||
002e3d16 ES |
1444 | Collect_Inherited_Class_Wide_Conditions (Prim); |
1445 | end if; | |
017d237e ES |
1446 | end if; |
1447 | ||
002e3d16 ES |
1448 | Next_Elmt (Op_Node); |
1449 | end loop; | |
1450 | ||
1451 | -- In all cases, we examine inherited operations to check whether they | |
1452 | -- require a wrapper to handle inherited conditions that call other | |
1453 | -- primitives, so that LSP can be verified/enforced. | |
1454 | ||
002e3d16 ES |
1455 | Op_Node := First_Elmt (Prim_Ops); |
1456 | while Present (Op_Node) loop | |
a187206c AC |
1457 | Decls := Empty_List; |
1458 | Prim := Node (Op_Node); | |
1459 | ||
f31dcd99 | 1460 | if not Comes_From_Source (Prim) and then Present (Alias (Prim)) then |
017d237e | 1461 | Par_Prim := Alias (Prim); |
a187206c | 1462 | Par_Type := Find_Dispatching_Type (Par_Prim); |
66340e0e AC |
1463 | |
1464 | -- Analyze the contract items of the parent operation, before | |
1465 | -- they are rewritten when inherited. | |
1466 | ||
1467 | Analyze_Entry_Or_Subprogram_Contract (Par_Prim); | |
1468 | ||
1469 | A_Pre := Get_Pragma (Par_Prim, Pragma_Precondition); | |
e3de253f | 1470 | |
017d237e | 1471 | if Present (A_Pre) and then Class_Present (A_Pre) then |
a187206c | 1472 | New_Prag := New_Copy_Tree (A_Pre); |
8c519039 | 1473 | Build_Class_Wide_Expression |
a187206c AC |
1474 | (Prag => New_Prag, |
1475 | Subp => Prim, | |
1476 | Par_Subp => Par_Prim, | |
1477 | Adjust_Sloc => False, | |
1478 | Needs_Wrapper => Needs_Wrapper); | |
1479 | ||
1480 | if Needs_Wrapper then | |
1481 | Append (New_Prag, Decls); | |
1482 | end if; | |
017d237e ES |
1483 | end if; |
1484 | ||
66340e0e | 1485 | A_Post := Get_Pragma (Par_Prim, Pragma_Postcondition); |
e3de253f | 1486 | |
017d237e | 1487 | if Present (A_Post) and then Class_Present (A_Post) then |
a187206c | 1488 | New_Prag := New_Copy_Tree (A_Pre); |
8c519039 | 1489 | Build_Class_Wide_Expression |
a187206c AC |
1490 | (Prag => New_Prag, |
1491 | Subp => Prim, | |
1492 | Par_Subp => Par_Prim, | |
1493 | Adjust_Sloc => False, | |
1494 | Needs_Wrapper => Needs_Wrapper); | |
1495 | ||
1496 | if Needs_Wrapper then | |
1497 | Append (New_Prag, Decls); | |
1498 | end if; | |
017d237e ES |
1499 | end if; |
1500 | end if; | |
1501 | ||
a187206c AC |
1502 | if Needs_Wrapper and then not Is_Abstract_Subprogram (Par_Prim) then |
1503 | ||
1504 | -- We need to build a new primitive that overrides the inherited | |
1505 | -- one, and whose inherited expression has been updated above. | |
1506 | -- These expressions are the arguments of pragmas that are part | |
1507 | -- of the declarations of the wrapper. The wrapper holds a single | |
1508 | -- statement that is a call to the parent primitive, where the | |
1509 | -- controlling actuals are conversions to the corresponding type | |
1510 | -- in the parent primitive: | |
1511 | ||
b41c731f AC |
1512 | -- procedure New_Prim (F1 : T1.; ...) is |
1513 | -- pragma Check (Precondition, Expr); | |
1514 | -- begin | |
1515 | -- Par_Prim (Par_Type (F1) ..); | |
1516 | -- end; | |
1517 | ||
1518 | -- If the primitive is a function the statement is a call | |
a187206c AC |
1519 | |
1520 | declare | |
1521 | Loc : constant Source_Ptr := Sloc (R); | |
a187206c | 1522 | Actuals : List_Id; |
b41c731f AC |
1523 | Call : Node_Id; |
1524 | Formal : Entity_Id; | |
a187206c AC |
1525 | New_F_Spec : Node_Id; |
1526 | New_Formal : Entity_Id; | |
1527 | New_Proc : Node_Id; | |
1528 | New_Spec : Node_Id; | |
a187206c AC |
1529 | |
1530 | begin | |
b41c731f AC |
1531 | Actuals := Empty_List; |
1532 | New_Spec := Build_Overriding_Spec (Par_Prim, R); | |
a187206c AC |
1533 | Formal := First_Formal (Par_Prim); |
1534 | New_F_Spec := First (Parameter_Specifications (New_Spec)); | |
1535 | ||
1536 | while Present (Formal) loop | |
1537 | New_Formal := Defining_Identifier (New_F_Spec); | |
1538 | ||
b41c731f | 1539 | -- If controlling argument, add conversion |
a187206c AC |
1540 | |
1541 | if Etype (Formal) = Par_Type then | |
1542 | Append_To (Actuals, | |
1543 | Make_Type_Conversion (Loc, | |
1544 | New_Occurrence_Of (Par_Type, Loc), | |
1545 | New_Occurrence_Of (New_Formal, Loc))); | |
1546 | ||
1547 | else | |
1548 | Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc)); | |
1549 | end if; | |
1550 | ||
1551 | Next_Formal (Formal); | |
1552 | Next (New_F_Spec); | |
1553 | end loop; | |
1554 | ||
1555 | if Ekind (Par_Prim) = E_Procedure then | |
b41c731f AC |
1556 | Call := |
1557 | Make_Procedure_Call_Statement (Loc, | |
1558 | Name => | |
1559 | New_Occurrence_Of (Par_Prim, Loc), | |
1560 | Parameter_Associations => Actuals); | |
a187206c | 1561 | else |
b41c731f AC |
1562 | Call := |
1563 | Make_Simple_Return_Statement (Loc, | |
a187206c AC |
1564 | Expression => |
1565 | Make_Function_Call (Loc, | |
b41c731f AC |
1566 | Name => |
1567 | New_Occurrence_Of (Par_Prim, Loc), | |
1568 | Parameter_Associations => Actuals)); | |
a187206c AC |
1569 | end if; |
1570 | ||
b41c731f AC |
1571 | New_Proc := |
1572 | Make_Subprogram_Body (Loc, | |
1573 | Specification => New_Spec, | |
1574 | Declarations => Decls, | |
1575 | Handled_Statement_Sequence => | |
1576 | Make_Handled_Sequence_Of_Statements (Loc, | |
1577 | Statements => New_List (Call), | |
1578 | End_Label => Make_Identifier (Loc, Chars (Prim)))); | |
a187206c AC |
1579 | |
1580 | Insert_After (Parent (R), New_Proc); | |
1581 | Analyze (New_Proc); | |
1582 | end; | |
1583 | ||
1584 | Needs_Wrapper := False; | |
1585 | end if; | |
1586 | ||
017d237e ES |
1587 | Next_Elmt (Op_Node); |
1588 | end loop; | |
1589 | end Check_Inherited_Conditions; | |
1590 | ||
70482933 RK |
1591 | ---------------------------- |
1592 | -- Check_Strict_Alignment -- | |
1593 | ---------------------------- | |
1594 | ||
1595 | procedure Check_Strict_Alignment (E : Entity_Id) is | |
1596 | Comp : Entity_Id; | |
1597 | ||
1598 | begin | |
1599 | if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then | |
1600 | Set_Strict_Alignment (E); | |
1601 | ||
1602 | elsif Is_Array_Type (E) then | |
1603 | Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E))); | |
1604 | ||
1605 | elsif Is_Record_Type (E) then | |
1606 | if Is_Limited_Record (E) then | |
1607 | Set_Strict_Alignment (E); | |
1608 | return; | |
1609 | end if; | |
1610 | ||
1611 | Comp := First_Component (E); | |
70482933 RK |
1612 | while Present (Comp) loop |
1613 | if not Is_Type (Comp) | |
1614 | and then (Strict_Alignment (Etype (Comp)) | |
fbf5a39b | 1615 | or else Is_Aliased (Comp)) |
70482933 RK |
1616 | then |
1617 | Set_Strict_Alignment (E); | |
1618 | return; | |
1619 | end if; | |
1620 | ||
1621 | Next_Component (Comp); | |
1622 | end loop; | |
1623 | end if; | |
1624 | end Check_Strict_Alignment; | |
1625 | ||
1626 | ------------------------- | |
1627 | -- Check_Unsigned_Type -- | |
1628 | ------------------------- | |
1629 | ||
1630 | procedure Check_Unsigned_Type (E : Entity_Id) is | |
1631 | Ancestor : Entity_Id; | |
1632 | Lo_Bound : Node_Id; | |
1633 | Btyp : Entity_Id; | |
1634 | ||
1635 | begin | |
1636 | if not Is_Discrete_Or_Fixed_Point_Type (E) then | |
1637 | return; | |
1638 | end if; | |
1639 | ||
1640 | -- Do not attempt to analyze case where range was in error | |
1641 | ||
ef1c0511 | 1642 | if No (Scalar_Range (E)) or else Error_Posted (Scalar_Range (E)) then |
70482933 RK |
1643 | return; |
1644 | end if; | |
1645 | ||
31101470 | 1646 | -- The situation that is nontrivial is something like: |
70482933 RK |
1647 | |
1648 | -- subtype x1 is integer range -10 .. +10; | |
1649 | -- subtype x2 is x1 range 0 .. V1; | |
1650 | -- subtype x3 is x2 range V2 .. V3; | |
1651 | -- subtype x4 is x3 range V4 .. V5; | |
1652 | ||
1653 | -- where Vn are variables. Here the base type is signed, but we still | |
1654 | -- know that x4 is unsigned because of the lower bound of x2. | |
1655 | ||
1656 | -- The only way to deal with this is to look up the ancestor chain | |
1657 | ||
1658 | Ancestor := E; | |
1659 | loop | |
1660 | if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then | |
1661 | return; | |
1662 | end if; | |
1663 | ||
1664 | Lo_Bound := Type_Low_Bound (Ancestor); | |
1665 | ||
1666 | if Compile_Time_Known_Value (Lo_Bound) then | |
70482933 RK |
1667 | if Expr_Rep_Value (Lo_Bound) >= 0 then |
1668 | Set_Is_Unsigned_Type (E, True); | |
1669 | end if; | |
1670 | ||
1671 | return; | |
1672 | ||
1673 | else | |
1674 | Ancestor := Ancestor_Subtype (Ancestor); | |
1675 | ||
1676 | -- If no ancestor had a static lower bound, go to base type | |
1677 | ||
1678 | if No (Ancestor) then | |
1679 | ||
1680 | -- Note: the reason we still check for a compile time known | |
1681 | -- value for the base type is that at least in the case of | |
1682 | -- generic formals, we can have bounds that fail this test, | |
1683 | -- and there may be other cases in error situations. | |
1684 | ||
1685 | Btyp := Base_Type (E); | |
1686 | ||
1687 | if Btyp = Any_Type or else Etype (Btyp) = Any_Type then | |
1688 | return; | |
1689 | end if; | |
1690 | ||
1691 | Lo_Bound := Type_Low_Bound (Base_Type (E)); | |
1692 | ||
1693 | if Compile_Time_Known_Value (Lo_Bound) | |
1694 | and then Expr_Rep_Value (Lo_Bound) >= 0 | |
1695 | then | |
1696 | Set_Is_Unsigned_Type (E, True); | |
1697 | end if; | |
1698 | ||
1699 | return; | |
70482933 RK |
1700 | end if; |
1701 | end if; | |
1702 | end loop; | |
1703 | end Check_Unsigned_Type; | |
1704 | ||
f280dd8f RD |
1705 | ----------------------------- |
1706 | -- Is_Atomic_VFA_Aggregate -- | |
1707 | ----------------------------- | |
fbf5a39b | 1708 | |
0c6826a5 AC |
1709 | function Is_Atomic_VFA_Aggregate (N : Node_Id) return Boolean is |
1710 | Loc : constant Source_Ptr := Sloc (N); | |
fbf5a39b | 1711 | New_N : Node_Id; |
b0159fbe | 1712 | Par : Node_Id; |
fbf5a39b | 1713 | Temp : Entity_Id; |
0c6826a5 | 1714 | Typ : Entity_Id; |
fbf5a39b AC |
1715 | |
1716 | begin | |
0c6826a5 | 1717 | Par := Parent (N); |
b0159fbe | 1718 | |
01957849 | 1719 | -- Array may be qualified, so find outer context |
b0159fbe AC |
1720 | |
1721 | if Nkind (Par) = N_Qualified_Expression then | |
1722 | Par := Parent (Par); | |
1723 | end if; | |
1724 | ||
0c6826a5 | 1725 | if not Comes_From_Source (Par) then |
b0159fbe | 1726 | return False; |
fbf5a39b | 1727 | end if; |
0c6826a5 AC |
1728 | |
1729 | case Nkind (Par) is | |
1730 | when N_Assignment_Statement => | |
1731 | Typ := Etype (Name (Par)); | |
1732 | ||
1733 | if not Is_Atomic_Or_VFA (Typ) | |
1734 | and then not (Is_Entity_Name (Name (Par)) | |
1735 | and then Is_Atomic_Or_VFA (Entity (Name (Par)))) | |
1736 | then | |
1737 | return False; | |
1738 | end if; | |
1739 | ||
1740 | when N_Object_Declaration => | |
1741 | Typ := Etype (Defining_Identifier (Par)); | |
1742 | ||
1743 | if not Is_Atomic_Or_VFA (Typ) | |
1744 | and then not Is_Atomic_Or_VFA (Defining_Identifier (Par)) | |
1745 | then | |
1746 | return False; | |
1747 | end if; | |
1748 | ||
1749 | when others => | |
1750 | return False; | |
1751 | end case; | |
1752 | ||
1753 | Temp := Make_Temporary (Loc, 'T', N); | |
1754 | New_N := | |
1755 | Make_Object_Declaration (Loc, | |
1756 | Defining_Identifier => Temp, | |
1757 | Object_Definition => New_Occurrence_Of (Typ, Loc), | |
1758 | Expression => Relocate_Node (N)); | |
1759 | Insert_Before (Par, New_N); | |
1760 | Analyze (New_N); | |
1761 | ||
1762 | Set_Expression (Par, New_Occurrence_Of (Temp, Loc)); | |
1763 | return True; | |
f280dd8f | 1764 | end Is_Atomic_VFA_Aggregate; |
fbf5a39b | 1765 | |
2ffcbaa5 AC |
1766 | ----------------------------------------------- |
1767 | -- Explode_Initialization_Compound_Statement -- | |
1768 | ----------------------------------------------- | |
1769 | ||
1770 | procedure Explode_Initialization_Compound_Statement (E : Entity_Id) is | |
1771 | Init_Stmts : constant Node_Id := Initialization_Statements (E); | |
9dc30a5f | 1772 | |
2ffcbaa5 AC |
1773 | begin |
1774 | if Present (Init_Stmts) | |
1775 | and then Nkind (Init_Stmts) = N_Compound_Statement | |
1776 | then | |
1777 | Insert_List_Before (Init_Stmts, Actions (Init_Stmts)); | |
1778 | ||
1779 | -- Note that we rewrite Init_Stmts into a NULL statement, rather than | |
1780 | -- just removing it, because Freeze_All may rely on this particular | |
1781 | -- Node_Id still being present in the enclosing list to know where to | |
1782 | -- stop freezing. | |
1783 | ||
1784 | Rewrite (Init_Stmts, Make_Null_Statement (Sloc (Init_Stmts))); | |
1785 | ||
1786 | Set_Initialization_Statements (E, Empty); | |
1787 | end if; | |
1788 | end Explode_Initialization_Compound_Statement; | |
1789 | ||
70482933 RK |
1790 | ---------------- |
1791 | -- Freeze_All -- | |
1792 | ---------------- | |
1793 | ||
1794 | -- Note: the easy coding for this procedure would be to just build a | |
1795 | -- single list of freeze nodes and then insert them and analyze them | |
1796 | -- all at once. This won't work, because the analysis of earlier freeze | |
1797 | -- nodes may recursively freeze types which would otherwise appear later | |
1798 | -- on in the freeze list. So we must analyze and expand the freeze nodes | |
1799 | -- as they are generated. | |
1800 | ||
1801 | procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is | |
70482933 | 1802 | procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id); |
def46b54 RD |
1803 | -- This is the internal recursive routine that does freezing of entities |
1804 | -- (but NOT the analysis of default expressions, which should not be | |
1805 | -- recursive, we don't want to analyze those till we are sure that ALL | |
1806 | -- the types are frozen). | |
70482933 | 1807 | |
fbf5a39b AC |
1808 | -------------------- |
1809 | -- Freeze_All_Ent -- | |
1810 | -------------------- | |
1811 | ||
545cb5be | 1812 | procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id) is |
70482933 RK |
1813 | E : Entity_Id; |
1814 | Flist : List_Id; | |
1815 | Lastn : Node_Id; | |
1816 | ||
1817 | procedure Process_Flist; | |
def46b54 RD |
1818 | -- If freeze nodes are present, insert and analyze, and reset cursor |
1819 | -- for next insertion. | |
70482933 | 1820 | |
fbf5a39b AC |
1821 | ------------------- |
1822 | -- Process_Flist -- | |
1823 | ------------------- | |
1824 | ||
70482933 RK |
1825 | procedure Process_Flist is |
1826 | begin | |
1827 | if Is_Non_Empty_List (Flist) then | |
1828 | Lastn := Next (After); | |
1829 | Insert_List_After_And_Analyze (After, Flist); | |
1830 | ||
1831 | if Present (Lastn) then | |
1832 | After := Prev (Lastn); | |
1833 | else | |
1834 | After := Last (List_Containing (After)); | |
1835 | end if; | |
1836 | end if; | |
1837 | end Process_Flist; | |
1838 | ||
704228bd | 1839 | -- Start of processing for Freeze_All_Ent |
fbf5a39b | 1840 | |
70482933 RK |
1841 | begin |
1842 | E := From; | |
1843 | while Present (E) loop | |
1844 | ||
1845 | -- If the entity is an inner package which is not a package | |
def46b54 RD |
1846 | -- renaming, then its entities must be frozen at this point. Note |
1847 | -- that such entities do NOT get frozen at the end of the nested | |
1848 | -- package itself (only library packages freeze). | |
70482933 RK |
1849 | |
1850 | -- Same is true for task declarations, where anonymous records | |
1851 | -- created for entry parameters must be frozen. | |
1852 | ||
1853 | if Ekind (E) = E_Package | |
1854 | and then No (Renamed_Object (E)) | |
1855 | and then not Is_Child_Unit (E) | |
1856 | and then not Is_Frozen (E) | |
1857 | then | |
7d8b9c99 | 1858 | Push_Scope (E); |
e3de253f | 1859 | |
70482933 RK |
1860 | Install_Visible_Declarations (E); |
1861 | Install_Private_Declarations (E); | |
70482933 RK |
1862 | Freeze_All (First_Entity (E), After); |
1863 | ||
1864 | End_Package_Scope (E); | |
1865 | ||
d3cb4cc0 AC |
1866 | if Is_Generic_Instance (E) |
1867 | and then Has_Delayed_Freeze (E) | |
1868 | then | |
1869 | Set_Has_Delayed_Freeze (E, False); | |
1870 | Expand_N_Package_Declaration (Unit_Declaration_Node (E)); | |
1871 | end if; | |
1872 | ||
70482933 | 1873 | elsif Ekind (E) in Task_Kind |
e3de253f AC |
1874 | and then Nkind_In (Parent (E), N_Single_Task_Declaration, |
1875 | N_Task_Type_Declaration) | |
70482933 | 1876 | then |
7d8b9c99 | 1877 | Push_Scope (E); |
70482933 RK |
1878 | Freeze_All (First_Entity (E), After); |
1879 | End_Scope; | |
1880 | ||
1881 | -- For a derived tagged type, we must ensure that all the | |
def46b54 RD |
1882 | -- primitive operations of the parent have been frozen, so that |
1883 | -- their addresses will be in the parent's dispatch table at the | |
1884 | -- point it is inherited. | |
70482933 RK |
1885 | |
1886 | elsif Ekind (E) = E_Record_Type | |
1887 | and then Is_Tagged_Type (E) | |
1888 | and then Is_Tagged_Type (Etype (E)) | |
1889 | and then Is_Derived_Type (E) | |
1890 | then | |
1891 | declare | |
1892 | Prim_List : constant Elist_Id := | |
1893 | Primitive_Operations (Etype (E)); | |
fbf5a39b AC |
1894 | |
1895 | Prim : Elmt_Id; | |
1896 | Subp : Entity_Id; | |
70482933 RK |
1897 | |
1898 | begin | |
df3e68b1 | 1899 | Prim := First_Elmt (Prim_List); |
70482933 RK |
1900 | while Present (Prim) loop |
1901 | Subp := Node (Prim); | |
1902 | ||
1903 | if Comes_From_Source (Subp) | |
1904 | and then not Is_Frozen (Subp) | |
1905 | then | |
c159409f | 1906 | Flist := Freeze_Entity (Subp, After); |
70482933 RK |
1907 | Process_Flist; |
1908 | end if; | |
1909 | ||
1910 | Next_Elmt (Prim); | |
1911 | end loop; | |
1912 | end; | |
1913 | end if; | |
1914 | ||
1915 | if not Is_Frozen (E) then | |
c159409f | 1916 | Flist := Freeze_Entity (E, After); |
70482933 | 1917 | Process_Flist; |
47e11d08 AC |
1918 | |
1919 | -- If already frozen, and there are delayed aspects, this is where | |
1920 | -- we do the visibility check for these aspects (see Sem_Ch13 spec | |
1921 | -- for a description of how we handle aspect visibility). | |
1922 | ||
1923 | elsif Has_Delayed_Aspects (E) then | |
02e4edea | 1924 | |
b98e2969 AC |
1925 | -- Retrieve the visibility to the discriminants in order to |
1926 | -- analyze properly the aspects. | |
1927 | ||
1928 | Push_Scope_And_Install_Discriminants (E); | |
1929 | ||
47e11d08 AC |
1930 | declare |
1931 | Ritem : Node_Id; | |
1932 | ||
1933 | begin | |
1934 | Ritem := First_Rep_Item (E); | |
1935 | while Present (Ritem) loop | |
1936 | if Nkind (Ritem) = N_Aspect_Specification | |
bd949ee2 | 1937 | and then Entity (Ritem) = E |
47e11d08 AC |
1938 | and then Is_Delayed_Aspect (Ritem) |
1939 | then | |
1940 | Check_Aspect_At_End_Of_Declarations (Ritem); | |
1941 | end if; | |
1942 | ||
1943 | Ritem := Next_Rep_Item (Ritem); | |
1944 | end loop; | |
1945 | end; | |
b98e2969 AC |
1946 | |
1947 | Uninstall_Discriminants_And_Pop_Scope (E); | |
70482933 RK |
1948 | end if; |
1949 | ||
def46b54 RD |
1950 | -- If an incomplete type is still not frozen, this may be a |
1951 | -- premature freezing because of a body declaration that follows. | |
ef992452 AC |
1952 | -- Indicate where the freezing took place. Freezing will happen |
1953 | -- if the body comes from source, but not if it is internally | |
1954 | -- generated, for example as the body of a type invariant. | |
fbf5a39b | 1955 | |
def46b54 RD |
1956 | -- If the freezing is caused by the end of the current declarative |
1957 | -- part, it is a Taft Amendment type, and there is no error. | |
fbf5a39b AC |
1958 | |
1959 | if not Is_Frozen (E) | |
1960 | and then Ekind (E) = E_Incomplete_Type | |
1961 | then | |
1962 | declare | |
1963 | Bod : constant Node_Id := Next (After); | |
1964 | ||
1965 | begin | |
35fae080 RD |
1966 | -- The presence of a body freezes all entities previously |
1967 | -- declared in the current list of declarations, but this | |
1968 | -- does not apply if the body does not come from source. | |
1969 | -- A type invariant is transformed into a subprogram body | |
1970 | -- which is placed at the end of the private part of the | |
1971 | -- current package, but this body does not freeze incomplete | |
1972 | -- types that may be declared in this private part. | |
1973 | ||
89a53f83 | 1974 | if (Nkind_In (Bod, N_Entry_Body, |
545cb5be AC |
1975 | N_Package_Body, |
1976 | N_Protected_Body, | |
89a53f83 | 1977 | N_Subprogram_Body, |
545cb5be | 1978 | N_Task_Body) |
fbf5a39b | 1979 | or else Nkind (Bod) in N_Body_Stub) |
ef992452 | 1980 | and then |
35fae080 | 1981 | List_Containing (After) = List_Containing (Parent (E)) |
ef992452 | 1982 | and then Comes_From_Source (Bod) |
fbf5a39b AC |
1983 | then |
1984 | Error_Msg_Sloc := Sloc (Next (After)); | |
1985 | Error_Msg_NE | |
1986 | ("type& is frozen# before its full declaration", | |
1987 | Parent (E), E); | |
1988 | end if; | |
1989 | end; | |
1990 | end if; | |
1991 | ||
70482933 RK |
1992 | Next_Entity (E); |
1993 | end loop; | |
1994 | end Freeze_All_Ent; | |
1995 | ||
89a53f83 AC |
1996 | -- Local variables |
1997 | ||
1998 | Decl : Node_Id; | |
1999 | E : Entity_Id; | |
2000 | Item : Entity_Id; | |
2001 | ||
70482933 RK |
2002 | -- Start of processing for Freeze_All |
2003 | ||
2004 | begin | |
2005 | Freeze_All_Ent (From, After); | |
2006 | ||
2007 | -- Now that all types are frozen, we can deal with default expressions | |
2008 | -- that require us to build a default expression functions. This is the | |
2009 | -- point at which such functions are constructed (after all types that | |
2010 | -- might be used in such expressions have been frozen). | |
fbf5a39b | 2011 | |
d4fc0fb4 AC |
2012 | -- For subprograms that are renaming_as_body, we create the wrapper |
2013 | -- bodies as needed. | |
2014 | ||
70482933 RK |
2015 | -- We also add finalization chains to access types whose designated |
2016 | -- types are controlled. This is normally done when freezing the type, | |
2017 | -- but this misses recursive type definitions where the later members | |
c6a9797e | 2018 | -- of the recursion introduce controlled components. |
70482933 RK |
2019 | |
2020 | -- Loop through entities | |
2021 | ||
2022 | E := From; | |
2023 | while Present (E) loop | |
70482933 | 2024 | if Is_Subprogram (E) then |
70482933 RK |
2025 | if not Default_Expressions_Processed (E) then |
2026 | Process_Default_Expressions (E, After); | |
2027 | end if; | |
2028 | ||
2029 | if not Has_Completion (E) then | |
2030 | Decl := Unit_Declaration_Node (E); | |
2031 | ||
2032 | if Nkind (Decl) = N_Subprogram_Renaming_Declaration then | |
8417f4b2 AC |
2033 | if Error_Posted (Decl) then |
2034 | Set_Has_Completion (E); | |
8417f4b2 AC |
2035 | else |
2036 | Build_And_Analyze_Renamed_Body (Decl, E, After); | |
2037 | end if; | |
70482933 RK |
2038 | |
2039 | elsif Nkind (Decl) = N_Subprogram_Declaration | |
2040 | and then Present (Corresponding_Body (Decl)) | |
2041 | and then | |
89a53f83 AC |
2042 | Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) = |
2043 | N_Subprogram_Renaming_Declaration | |
70482933 RK |
2044 | then |
2045 | Build_And_Analyze_Renamed_Body | |
2046 | (Decl, Corresponding_Body (Decl), After); | |
2047 | end if; | |
2048 | end if; | |
2049 | ||
89a53f83 AC |
2050 | -- Freeze the default expressions of entries, entry families, and |
2051 | -- protected subprograms. | |
545cb5be | 2052 | |
89a53f83 AC |
2053 | elsif Is_Concurrent_Type (E) then |
2054 | Item := First_Entity (E); | |
2055 | while Present (Item) loop | |
2056 | if (Is_Entry (Item) or else Is_Subprogram (Item)) | |
2057 | and then not Default_Expressions_Processed (Item) | |
2058 | then | |
2059 | Process_Default_Expressions (Item, After); | |
2060 | end if; | |
70482933 | 2061 | |
89a53f83 AC |
2062 | Next_Entity (Item); |
2063 | end loop; | |
70482933 RK |
2064 | end if; |
2065 | ||
46413d9e AC |
2066 | -- Historical note: We used to create a finalization master for an |
2067 | -- access type whose designated type is not controlled, but contains | |
2c6336be | 2068 | -- private controlled compoments. This form of postprocessing is no |
46413d9e AC |
2069 | -- longer needed because the finalization master is now created when |
2070 | -- the access type is frozen (see Exp_Ch3.Freeze_Type). | |
2071 | ||
70482933 RK |
2072 | Next_Entity (E); |
2073 | end loop; | |
70482933 RK |
2074 | end Freeze_All; |
2075 | ||
2076 | ----------------------- | |
2077 | -- Freeze_And_Append -- | |
2078 | ----------------------- | |
2079 | ||
2080 | procedure Freeze_And_Append | |
2081 | (Ent : Entity_Id; | |
c159409f | 2082 | N : Node_Id; |
70482933 RK |
2083 | Result : in out List_Id) |
2084 | is | |
c159409f | 2085 | L : constant List_Id := Freeze_Entity (Ent, N); |
70482933 RK |
2086 | begin |
2087 | if Is_Non_Empty_List (L) then | |
2088 | if Result = No_List then | |
2089 | Result := L; | |
2090 | else | |
2091 | Append_List (L, Result); | |
2092 | end if; | |
2093 | end if; | |
2094 | end Freeze_And_Append; | |
2095 | ||
2096 | ------------------- | |
2097 | -- Freeze_Before -- | |
2098 | ------------------- | |
2099 | ||
6dc87f5f | 2100 | procedure Freeze_Before |
78bc7fe6 ES |
2101 | (N : Node_Id; |
2102 | T : Entity_Id; | |
2103 | Do_Freeze_Profile : Boolean := True) | |
6dc87f5f | 2104 | is |
78bc7fe6 ES |
2105 | -- Freeze T, then insert the generated Freeze nodes before the node N. |
2106 | -- Flag Freeze_Profile is used when T is an overloadable entity, and | |
2107 | -- indicates whether its profile should be frozen at the same time. | |
6dc87f5f | 2108 | |
78bc7fe6 ES |
2109 | Freeze_Nodes : constant List_Id := |
2110 | Freeze_Entity (T, N, Do_Freeze_Profile); | |
e1691d7e | 2111 | Pack : constant Entity_Id := Scope (T); |
18c56840 | 2112 | |
70482933 | 2113 | begin |
18c56840 ES |
2114 | if Ekind (T) = E_Function then |
2115 | Check_Expression_Function (N, T); | |
2116 | end if; | |
2117 | ||
70482933 | 2118 | if Is_Non_Empty_List (Freeze_Nodes) then |
e1691d7e ES |
2119 | |
2120 | -- If the entity is a type declared in an inner package, it may be | |
2121 | -- frozen by an outer declaration before the package itself is | |
2122 | -- frozen. Install the package scope to analyze the freeze nodes, | |
2123 | -- which may include generated subprograms such as predicate | |
2124 | -- functions, etc. | |
2125 | ||
2126 | if Is_Type (T) and then From_Nested_Package (T) then | |
2127 | Push_Scope (Pack); | |
2128 | Install_Visible_Declarations (Pack); | |
2129 | Install_Private_Declarations (Pack); | |
2130 | Insert_Actions (N, Freeze_Nodes); | |
2131 | End_Package_Scope (Pack); | |
2132 | ||
2133 | else | |
2134 | Insert_Actions (N, Freeze_Nodes); | |
2135 | end if; | |
70482933 RK |
2136 | end if; |
2137 | end Freeze_Before; | |
2138 | ||
2139 | ------------------- | |
2140 | -- Freeze_Entity -- | |
2141 | ------------------- | |
2142 | ||
b0bf18ad AC |
2143 | -- WARNING: This routine manages Ghost regions. Return statements must be |
2144 | -- replaced by gotos which jump to the end of the routine and restore the | |
2145 | -- Ghost mode. | |
2146 | ||
6dc87f5f | 2147 | function Freeze_Entity |
78bc7fe6 ES |
2148 | (E : Entity_Id; |
2149 | N : Node_Id; | |
2150 | Do_Freeze_Profile : Boolean := True) return List_Id | |
6dc87f5f | 2151 | is |
8636f52f HK |
2152 | Loc : constant Source_Ptr := Sloc (N); |
2153 | Atype : Entity_Id; | |
2154 | Comp : Entity_Id; | |
2155 | F_Node : Node_Id; | |
2156 | Formal : Entity_Id; | |
2157 | Indx : Node_Id; | |
0fea901b | 2158 | |
241ebe89 HK |
2159 | Has_Default_Initialization : Boolean := False; |
2160 | -- This flag gets set to true for a variable with default initialization | |
0fea901b | 2161 | |
90878b12 AC |
2162 | Result : List_Id := No_List; |
2163 | -- List of freezing actions, left at No_List if none | |
2164 | ||
241ebe89 HK |
2165 | Test_E : Entity_Id := E; |
2166 | -- This could use a comment ??? | |
4c8a5bb8 | 2167 | |
90878b12 AC |
2168 | procedure Add_To_Result (N : Node_Id); |
2169 | -- N is a freezing action to be appended to the Result | |
2170 | ||
b98e2969 AC |
2171 | function After_Last_Declaration return Boolean; |
2172 | -- If Loc is a freeze_entity that appears after the last declaration | |
2173 | -- in the scope, inhibit error messages on late completion. | |
2174 | ||
70482933 | 2175 | procedure Check_Current_Instance (Comp_Decl : Node_Id); |
edd63e9b ES |
2176 | -- Check that an Access or Unchecked_Access attribute with a prefix |
2177 | -- which is the current instance type can only be applied when the type | |
2178 | -- is limited. | |
70482933 | 2179 | |
ca0eb951 AC |
2180 | procedure Check_Suspicious_Convention (Rec_Type : Entity_Id); |
2181 | -- Give a warning for pragma Convention with language C or C++ applied | |
2182 | -- to a discriminated record type. This is suppressed for the unchecked | |
2183 | -- union case, since the whole point in this case is interface C. We | |
2184 | -- also do not generate this within instantiations, since we will have | |
2185 | -- generated a message on the template. | |
2186 | ||
67b3acf8 RD |
2187 | procedure Check_Suspicious_Modulus (Utype : Entity_Id); |
2188 | -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit | |
2189 | -- integer literal without an explicit corresponding size clause. The | |
2190 | -- caller has checked that Utype is a modular integer type. | |
2191 | ||
63bb4268 AC |
2192 | procedure Freeze_Array_Type (Arr : Entity_Id); |
2193 | -- Freeze array type, including freezing index and component types | |
2194 | ||
b741083a | 2195 | procedure Freeze_Object_Declaration (E : Entity_Id); |
73cc8f62 RD |
2196 | -- Perform checks and generate freeze node if needed for a constant or |
2197 | -- variable declared by an object declaration. | |
b741083a | 2198 | |
3cd4a210 AC |
2199 | function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id; |
2200 | -- Create Freeze_Generic_Entity nodes for types declared in a generic | |
2201 | -- package. Recurse on inner generic packages. | |
2202 | ||
4d1429b2 | 2203 | function Freeze_Profile (E : Entity_Id) return Boolean; |
9ceeaf9d | 2204 | -- Freeze formals and return type of subprogram. If some type in the |
4d9446f9 EB |
2205 | -- profile is incomplete and we are in an instance, freezing of the |
2206 | -- entity will take place elsewhere, and the function returns False. | |
4d1429b2 | 2207 | |
70482933 | 2208 | procedure Freeze_Record_Type (Rec : Entity_Id); |
63bb4268 | 2209 | -- Freeze record type, including freezing component types, and freezing |
edd63e9b | 2210 | -- primitive operations if this is a tagged type. |
70482933 | 2211 | |
e8cddc3b AC |
2212 | function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean; |
2213 | -- Determine whether an arbitrary entity is subject to Boolean aspect | |
2214 | -- Import and its value is specified as True. | |
2215 | ||
ce06d641 AC |
2216 | procedure Inherit_Freeze_Node |
2217 | (Fnod : Node_Id; | |
2218 | Typ : Entity_Id); | |
2219 | -- Set type Typ's freeze node to refer to Fnode. This routine ensures | |
2220 | -- that any attributes attached to Typ's original node are preserved. | |
2221 | ||
32bba3c9 AC |
2222 | procedure Wrap_Imported_Subprogram (E : Entity_Id); |
2223 | -- If E is an entity for an imported subprogram with pre/post-conditions | |
2224 | -- then this procedure will create a wrapper to ensure that proper run- | |
2225 | -- time checking of the pre/postconditions. See body for details. | |
2226 | ||
90878b12 AC |
2227 | ------------------- |
2228 | -- Add_To_Result -- | |
2229 | ------------------- | |
2230 | ||
2231 | procedure Add_To_Result (N : Node_Id) is | |
2232 | begin | |
2233 | if No (Result) then | |
2234 | Result := New_List (N); | |
2235 | else | |
2236 | Append (N, Result); | |
2237 | end if; | |
2238 | end Add_To_Result; | |
2239 | ||
70482933 RK |
2240 | ---------------------------- |
2241 | -- After_Last_Declaration -- | |
2242 | ---------------------------- | |
2243 | ||
2244 | function After_Last_Declaration return Boolean is | |
fb2e11ee | 2245 | Spec : constant Node_Id := Parent (Current_Scope); |
0fea901b | 2246 | |
70482933 RK |
2247 | begin |
2248 | if Nkind (Spec) = N_Package_Specification then | |
2249 | if Present (Private_Declarations (Spec)) then | |
2250 | return Loc >= Sloc (Last (Private_Declarations (Spec))); | |
70482933 RK |
2251 | elsif Present (Visible_Declarations (Spec)) then |
2252 | return Loc >= Sloc (Last (Visible_Declarations (Spec))); | |
2253 | else | |
2254 | return False; | |
2255 | end if; | |
0fea901b | 2256 | |
70482933 RK |
2257 | else |
2258 | return False; | |
2259 | end if; | |
2260 | end After_Last_Declaration; | |
2261 | ||
2262 | ---------------------------- | |
2263 | -- Check_Current_Instance -- | |
2264 | ---------------------------- | |
2265 | ||
2266 | procedure Check_Current_Instance (Comp_Decl : Node_Id) is | |
2267 | ||
e1308fa8 AC |
2268 | function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean; |
2269 | -- Determine whether Typ is compatible with the rules for aliased | |
2270 | -- views of types as defined in RM 3.10 in the various dialects. | |
32c760e6 | 2271 | |
70482933 | 2272 | function Process (N : Node_Id) return Traverse_Result; |
49e90211 | 2273 | -- Process routine to apply check to given node |
70482933 | 2274 | |
e1308fa8 AC |
2275 | ----------------------------- |
2276 | -- Is_Aliased_View_Of_Type -- | |
2277 | ----------------------------- | |
2278 | ||
2279 | function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean is | |
2280 | Typ_Decl : constant Node_Id := Parent (Typ); | |
2281 | ||
2282 | begin | |
2283 | -- Common case | |
2284 | ||
2285 | if Nkind (Typ_Decl) = N_Full_Type_Declaration | |
2286 | and then Limited_Present (Type_Definition (Typ_Decl)) | |
2287 | then | |
2288 | return True; | |
2289 | ||
2290 | -- The following paragraphs describe what a legal aliased view of | |
2291 | -- a type is in the various dialects of Ada. | |
2292 | ||
2293 | -- Ada 95 | |
2294 | ||
2295 | -- The current instance of a limited type, and a formal parameter | |
2296 | -- or generic formal object of a tagged type. | |
2297 | ||
2298 | -- Ada 95 limited type | |
2299 | -- * Type with reserved word "limited" | |
2300 | -- * A protected or task type | |
2301 | -- * A composite type with limited component | |
2302 | ||
2303 | elsif Ada_Version <= Ada_95 then | |
2304 | return Is_Limited_Type (Typ); | |
2305 | ||
2306 | -- Ada 2005 | |
2307 | ||
2308 | -- The current instance of a limited tagged type, a protected | |
2309 | -- type, a task type, or a type that has the reserved word | |
2310 | -- "limited" in its full definition ... a formal parameter or | |
2311 | -- generic formal object of a tagged type. | |
2312 | ||
2313 | -- Ada 2005 limited type | |
2314 | -- * Type with reserved word "limited", "synchronized", "task" | |
2315 | -- or "protected" | |
2316 | -- * A composite type with limited component | |
2317 | -- * A derived type whose parent is a non-interface limited type | |
2318 | ||
2319 | elsif Ada_Version = Ada_2005 then | |
2320 | return | |
2321 | (Is_Limited_Type (Typ) and then Is_Tagged_Type (Typ)) | |
2322 | or else | |
2323 | (Is_Derived_Type (Typ) | |
2324 | and then not Is_Interface (Etype (Typ)) | |
2325 | and then Is_Limited_Type (Etype (Typ))); | |
2326 | ||
2327 | -- Ada 2012 and beyond | |
2328 | ||
2329 | -- The current instance of an immutably limited type ... a formal | |
2330 | -- parameter or generic formal object of a tagged type. | |
2331 | ||
2332 | -- Ada 2012 limited type | |
2333 | -- * Type with reserved word "limited", "synchronized", "task" | |
2334 | -- or "protected" | |
2335 | -- * A composite type with limited component | |
2336 | -- * A derived type whose parent is a non-interface limited type | |
2337 | -- * An incomplete view | |
2338 | ||
2339 | -- Ada 2012 immutably limited type | |
2340 | -- * Explicitly limited record type | |
2341 | -- * Record extension with "limited" present | |
2342 | -- * Non-formal limited private type that is either tagged | |
2343 | -- or has at least one access discriminant with a default | |
2344 | -- expression | |
2345 | -- * Task type, protected type or synchronized interface | |
2346 | -- * Type derived from immutably limited type | |
2347 | ||
2348 | else | |
2349 | return | |
2350 | Is_Immutably_Limited_Type (Typ) | |
2351 | or else Is_Incomplete_Type (Typ); | |
2352 | end if; | |
2353 | end Is_Aliased_View_Of_Type; | |
2354 | ||
fbf5a39b AC |
2355 | ------------- |
2356 | -- Process -- | |
2357 | ------------- | |
2358 | ||
70482933 RK |
2359 | function Process (N : Node_Id) return Traverse_Result is |
2360 | begin | |
2361 | case Nkind (N) is | |
2362 | when N_Attribute_Reference => | |
b69cd36a AC |
2363 | if Nam_In (Attribute_Name (N), Name_Access, |
2364 | Name_Unchecked_Access) | |
70482933 RK |
2365 | and then Is_Entity_Name (Prefix (N)) |
2366 | and then Is_Type (Entity (Prefix (N))) | |
2367 | and then Entity (Prefix (N)) = E | |
2368 | then | |
a9895094 AC |
2369 | if Ada_Version < Ada_2012 then |
2370 | Error_Msg_N | |
2371 | ("current instance must be a limited type", | |
1f0b1e48 | 2372 | Prefix (N)); |
a9895094 AC |
2373 | else |
2374 | Error_Msg_N | |
1f0b1e48 | 2375 | ("current instance must be an immutably limited " |
0fea901b | 2376 | & "type (RM-2012, 7.5 (8.1/3))", Prefix (N)); |
a9895094 | 2377 | end if; |
1f0b1e48 | 2378 | |
70482933 | 2379 | return Abandon; |
1f0b1e48 | 2380 | |
70482933 RK |
2381 | else |
2382 | return OK; | |
2383 | end if; | |
2384 | ||
d8f43ee6 HK |
2385 | when others => |
2386 | return OK; | |
70482933 RK |
2387 | end case; |
2388 | end Process; | |
2389 | ||
2390 | procedure Traverse is new Traverse_Proc (Process); | |
2391 | ||
e1308fa8 | 2392 | -- Local variables |
32c760e6 | 2393 | |
e1308fa8 AC |
2394 | Rec_Type : constant Entity_Id := |
2395 | Scope (Defining_Identifier (Comp_Decl)); | |
32c760e6 | 2396 | |
e1308fa8 | 2397 | -- Start of processing for Check_Current_Instance |
32c760e6 | 2398 | |
e1308fa8 AC |
2399 | begin |
2400 | if not Is_Aliased_View_Of_Type (Rec_Type) then | |
32c760e6 ES |
2401 | Traverse (Comp_Decl); |
2402 | end if; | |
70482933 RK |
2403 | end Check_Current_Instance; |
2404 | ||
ca0eb951 AC |
2405 | --------------------------------- |
2406 | -- Check_Suspicious_Convention -- | |
2407 | --------------------------------- | |
2408 | ||
2409 | procedure Check_Suspicious_Convention (Rec_Type : Entity_Id) is | |
2410 | begin | |
2411 | if Has_Discriminants (Rec_Type) | |
2412 | and then Is_Base_Type (Rec_Type) | |
2413 | and then not Is_Unchecked_Union (Rec_Type) | |
2414 | and then (Convention (Rec_Type) = Convention_C | |
2415 | or else | |
2416 | Convention (Rec_Type) = Convention_CPP) | |
2417 | and then Comes_From_Source (Rec_Type) | |
2418 | and then not In_Instance | |
2419 | and then not Has_Warnings_Off (Rec_Type) | |
2420 | then | |
2421 | declare | |
2422 | Cprag : constant Node_Id := | |
2423 | Get_Rep_Pragma (Rec_Type, Name_Convention); | |
2424 | A2 : Node_Id; | |
2425 | ||
2426 | begin | |
2427 | if Present (Cprag) then | |
2428 | A2 := Next (First (Pragma_Argument_Associations (Cprag))); | |
2429 | ||
2430 | if Convention (Rec_Type) = Convention_C then | |
2431 | Error_Msg_N | |
d65a80fd HK |
2432 | ("?x?discriminated record has no direct equivalent in " |
2433 | & "C", A2); | |
ca0eb951 AC |
2434 | else |
2435 | Error_Msg_N | |
d65a80fd HK |
2436 | ("?x?discriminated record has no direct equivalent in " |
2437 | & "C++", A2); | |
ca0eb951 AC |
2438 | end if; |
2439 | ||
2440 | Error_Msg_NE | |
2441 | ("\?x?use of convention for type& is dubious", | |
2442 | A2, Rec_Type); | |
2443 | end if; | |
2444 | end; | |
2445 | end if; | |
2446 | end Check_Suspicious_Convention; | |
2447 | ||
67b3acf8 RD |
2448 | ------------------------------ |
2449 | -- Check_Suspicious_Modulus -- | |
2450 | ------------------------------ | |
2451 | ||
2452 | procedure Check_Suspicious_Modulus (Utype : Entity_Id) is | |
2453 | Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype)); | |
2454 | ||
2455 | begin | |
685bc70f AC |
2456 | if not Warn_On_Suspicious_Modulus_Value then |
2457 | return; | |
2458 | end if; | |
2459 | ||
67b3acf8 RD |
2460 | if Nkind (Decl) = N_Full_Type_Declaration then |
2461 | declare | |
2462 | Tdef : constant Node_Id := Type_Definition (Decl); | |
3e7302c3 | 2463 | |
67b3acf8 RD |
2464 | begin |
2465 | if Nkind (Tdef) = N_Modular_Type_Definition then | |
2466 | declare | |
2467 | Modulus : constant Node_Id := | |
2468 | Original_Node (Expression (Tdef)); | |
685bc70f | 2469 | |
67b3acf8 RD |
2470 | begin |
2471 | if Nkind (Modulus) = N_Integer_Literal then | |
2472 | declare | |
2473 | Modv : constant Uint := Intval (Modulus); | |
2474 | Sizv : constant Uint := RM_Size (Utype); | |
2475 | ||
2476 | begin | |
2477 | -- First case, modulus and size are the same. This | |
2478 | -- happens if you have something like mod 32, with | |
2479 | -- an explicit size of 32, this is for sure a case | |
2480 | -- where the warning is given, since it is seems | |
2481 | -- very unlikely that someone would want e.g. a | |
2482 | -- five bit type stored in 32 bits. It is much | |
2483 | -- more likely they wanted a 32-bit type. | |
2484 | ||
2485 | if Modv = Sizv then | |
2486 | null; | |
2487 | ||
2488 | -- Second case, the modulus is 32 or 64 and no | |
2489 | -- size clause is present. This is a less clear | |
2490 | -- case for giving the warning, but in the case | |
2491 | -- of 32/64 (5-bit or 6-bit types) these seem rare | |
2492 | -- enough that it is a likely error (and in any | |
2493 | -- case using 2**5 or 2**6 in these cases seems | |
2494 | -- clearer. We don't include 8 or 16 here, simply | |
2495 | -- because in practice 3-bit and 4-bit types are | |
2496 | -- more common and too many false positives if | |
2497 | -- we warn in these cases. | |
2498 | ||
2499 | elsif not Has_Size_Clause (Utype) | |
2500 | and then (Modv = Uint_32 or else Modv = Uint_64) | |
2501 | then | |
2502 | null; | |
2503 | ||
2504 | -- No warning needed | |
2505 | ||
2506 | else | |
2507 | return; | |
2508 | end if; | |
2509 | ||
2510 | -- If we fall through, give warning | |
2511 | ||
2512 | Error_Msg_Uint_1 := Modv; | |
2513 | Error_Msg_N | |
685bc70f | 2514 | ("?M?2 '*'*^' may have been intended here", |
67b3acf8 RD |
2515 | Modulus); |
2516 | end; | |
2517 | end if; | |
2518 | end; | |
2519 | end if; | |
2520 | end; | |
2521 | end if; | |
2522 | end Check_Suspicious_Modulus; | |
2523 | ||
63bb4268 AC |
2524 | ----------------------- |
2525 | -- Freeze_Array_Type -- | |
2526 | ----------------------- | |
2527 | ||
2528 | procedure Freeze_Array_Type (Arr : Entity_Id) is | |
2529 | FS : constant Entity_Id := First_Subtype (Arr); | |
2530 | Ctyp : constant Entity_Id := Component_Type (Arr); | |
2531 | Clause : Entity_Id; | |
2532 | ||
2533 | Non_Standard_Enum : Boolean := False; | |
2534 | -- Set true if any of the index types is an enumeration type with a | |
2535 | -- non-standard representation. | |
2536 | ||
2537 | begin | |
2538 | Freeze_And_Append (Ctyp, N, Result); | |
2539 | ||
2540 | Indx := First_Index (Arr); | |
2541 | while Present (Indx) loop | |
2542 | Freeze_And_Append (Etype (Indx), N, Result); | |
2543 | ||
2544 | if Is_Enumeration_Type (Etype (Indx)) | |
2545 | and then Has_Non_Standard_Rep (Etype (Indx)) | |
2546 | then | |
2547 | Non_Standard_Enum := True; | |
2548 | end if; | |
2549 | ||
2550 | Next_Index (Indx); | |
2551 | end loop; | |
2552 | ||
2553 | -- Processing that is done only for base types | |
2554 | ||
f8c79ade | 2555 | if Ekind (Arr) = E_Array_Type then |
220d1fd9 AC |
2556 | |
2557 | -- Deal with default setting of reverse storage order | |
2558 | ||
2559 | Set_SSO_From_Default (Arr); | |
63bb4268 AC |
2560 | |
2561 | -- Propagate flags for component type | |
2562 | ||
c8593453 | 2563 | if Is_Controlled_Active (Component_Type (Arr)) |
63bb4268 AC |
2564 | or else Has_Controlled_Component (Ctyp) |
2565 | then | |
2566 | Set_Has_Controlled_Component (Arr); | |
2567 | end if; | |
2568 | ||
2569 | if Has_Unchecked_Union (Component_Type (Arr)) then | |
2570 | Set_Has_Unchecked_Union (Arr); | |
2571 | end if; | |
2572 | ||
3ddfabe3 | 2573 | -- The array type requires its own invariant procedure in order to |
104c99ef CD |
2574 | -- verify the component invariant over all elements. In GNATprove |
2575 | -- mode, the component invariants are checked by other means. They | |
2576 | -- should not be added to the array type invariant procedure, so | |
2577 | -- that the procedure can be used to check the array type | |
2578 | -- invariants if any. | |
2579 | ||
2580 | if Has_Invariants (Component_Type (Arr)) | |
2581 | and then not GNATprove_Mode | |
2582 | then | |
3ddfabe3 AC |
2583 | Set_Has_Own_Invariants (Arr); |
2584 | ||
2585 | -- The array type is an implementation base type. Propagate the | |
2586 | -- same property to the first subtype. | |
2587 | ||
2588 | if Is_Itype (Arr) then | |
2589 | Set_Has_Own_Invariants (First_Subtype (Arr)); | |
2590 | end if; | |
2591 | end if; | |
2592 | ||
63bb4268 AC |
2593 | -- Warn for pragma Pack overriding foreign convention |
2594 | ||
2595 | if Has_Foreign_Convention (Ctyp) | |
2596 | and then Has_Pragma_Pack (Arr) | |
2597 | then | |
2598 | declare | |
2599 | CN : constant Name_Id := | |
2600 | Get_Convention_Name (Convention (Ctyp)); | |
2601 | PP : constant Node_Id := | |
2602 | Get_Pragma (First_Subtype (Arr), Pragma_Pack); | |
2603 | begin | |
2604 | if Present (PP) then | |
2605 | Error_Msg_Name_1 := CN; | |
2606 | Error_Msg_Sloc := Sloc (Arr); | |
2607 | Error_Msg_N | |
0fea901b | 2608 | ("pragma Pack affects convention % components #??", PP); |
63bb4268 AC |
2609 | Error_Msg_Name_1 := CN; |
2610 | Error_Msg_N | |
2611 | ("\array components may not have % compatible " | |
2612 | & "representation??", PP); | |
2613 | end if; | |
2614 | end; | |
2615 | end if; | |
2616 | ||
2617 | -- If packing was requested or if the component size was | |
2618 | -- set explicitly, then see if bit packing is required. This | |
2619 | -- processing is only done for base types, since all of the | |
ef1c0511 AC |
2620 | -- representation aspects involved are type-related. |
2621 | ||
2622 | -- This is not just an optimization, if we start processing the | |
2623 | -- subtypes, they interfere with the settings on the base type | |
2624 | -- (this is because Is_Packed has a slightly different meaning | |
2625 | -- before and after freezing). | |
63bb4268 AC |
2626 | |
2627 | declare | |
2628 | Csiz : Uint; | |
2629 | Esiz : Uint; | |
2630 | ||
2631 | begin | |
2632 | if (Is_Packed (Arr) or else Has_Pragma_Pack (Arr)) | |
2633 | and then Known_Static_RM_Size (Ctyp) | |
2634 | and then not Has_Component_Size_Clause (Arr) | |
2635 | then | |
2636 | Csiz := UI_Max (RM_Size (Ctyp), 1); | |
2637 | ||
2638 | elsif Known_Component_Size (Arr) then | |
2639 | Csiz := Component_Size (Arr); | |
2640 | ||
2641 | elsif not Known_Static_Esize (Ctyp) then | |
2642 | Csiz := Uint_0; | |
2643 | ||
2644 | else | |
2645 | Esiz := Esize (Ctyp); | |
2646 | ||
2647 | -- We can set the component size if it is less than 16, | |
2648 | -- rounding it up to the next storage unit size. | |
2649 | ||
2650 | if Esiz <= 8 then | |
2651 | Csiz := Uint_8; | |
2652 | elsif Esiz <= 16 then | |
2653 | Csiz := Uint_16; | |
2654 | else | |
2655 | Csiz := Uint_0; | |
2656 | end if; | |
2657 | ||
2658 | -- Set component size up to match alignment if it would | |
2659 | -- otherwise be less than the alignment. This deals with | |
2660 | -- cases of types whose alignment exceeds their size (the | |
2661 | -- padded type cases). | |
2662 | ||
2663 | if Csiz /= 0 then | |
2664 | declare | |
2665 | A : constant Uint := Alignment_In_Bits (Ctyp); | |
2666 | begin | |
2667 | if Csiz < A then | |
2668 | Csiz := A; | |
2669 | end if; | |
2670 | end; | |
2671 | end if; | |
2672 | end if; | |
2673 | ||
b3f75672 | 2674 | -- Case of component size that may result in bit packing |
63bb4268 AC |
2675 | |
2676 | if 1 <= Csiz and then Csiz <= 64 then | |
2677 | declare | |
2678 | Ent : constant Entity_Id := | |
2679 | First_Subtype (Arr); | |
2680 | Pack_Pragma : constant Node_Id := | |
2681 | Get_Rep_Pragma (Ent, Name_Pack); | |
2682 | Comp_Size_C : constant Node_Id := | |
2683 | Get_Attribute_Definition_Clause | |
2684 | (Ent, Attribute_Component_Size); | |
0fea901b | 2685 | |
63bb4268 AC |
2686 | begin |
2687 | -- Warn if we have pack and component size so that the | |
2688 | -- pack is ignored. | |
2689 | ||
2690 | -- Note: here we must check for the presence of a | |
2691 | -- component size before checking for a Pack pragma to | |
2692 | -- deal with the case where the array type is a derived | |
2693 | -- type whose parent is currently private. | |
2694 | ||
2695 | if Present (Comp_Size_C) | |
2696 | and then Has_Pragma_Pack (Ent) | |
2697 | and then Warn_On_Redundant_Constructs | |
2698 | then | |
2699 | Error_Msg_Sloc := Sloc (Comp_Size_C); | |
2700 | Error_Msg_NE | |
a90bd866 | 2701 | ("?r?pragma Pack for& ignored!", Pack_Pragma, Ent); |
63bb4268 | 2702 | Error_Msg_N |
a90bd866 | 2703 | ("\?r?explicit component size given#!", Pack_Pragma); |
63bb4268 AC |
2704 | Set_Is_Packed (Base_Type (Ent), False); |
2705 | Set_Is_Bit_Packed_Array (Base_Type (Ent), False); | |
2706 | end if; | |
2707 | ||
2708 | -- Set component size if not already set by a component | |
2709 | -- size clause. | |
2710 | ||
2711 | if not Present (Comp_Size_C) then | |
2712 | Set_Component_Size (Arr, Csiz); | |
2713 | end if; | |
2714 | ||
2715 | -- Check for base type of 8, 16, 32 bits, where an | |
2716 | -- unsigned subtype has a length one less than the | |
2717 | -- base type (e.g. Natural subtype of Integer). | |
2718 | ||
2719 | -- In such cases, if a component size was not set | |
2720 | -- explicitly, then generate a warning. | |
2721 | ||
2722 | if Has_Pragma_Pack (Arr) | |
2723 | and then not Present (Comp_Size_C) | |
f8c79ade | 2724 | and then (Csiz = 7 or else Csiz = 15 or else Csiz = 31) |
63bb4268 AC |
2725 | and then Esize (Base_Type (Ctyp)) = Csiz + 1 |
2726 | then | |
2727 | Error_Msg_Uint_1 := Csiz; | |
2728 | ||
2729 | if Present (Pack_Pragma) then | |
2730 | Error_Msg_N | |
0fea901b AC |
2731 | ("??pragma Pack causes component size to be ^!", |
2732 | Pack_Pragma); | |
63bb4268 | 2733 | Error_Msg_N |
0fea901b AC |
2734 | ("\??use Component_Size to set desired value!", |
2735 | Pack_Pragma); | |
63bb4268 AC |
2736 | end if; |
2737 | end if; | |
2738 | ||
b3f75672 | 2739 | -- Bit packing is never needed for 8, 16, 32, 64 |
63bb4268 | 2740 | |
3d626f94 | 2741 | if Addressable (Csiz) then |
497a660d | 2742 | |
b3f75672 EB |
2743 | -- If the Esize of the component is known and equal to |
2744 | -- the component size then even packing is not needed. | |
63bb4268 AC |
2745 | |
2746 | if Known_Static_Esize (Component_Type (Arr)) | |
2747 | and then Esize (Component_Type (Arr)) = Csiz | |
2748 | then | |
b3f75672 EB |
2749 | -- Here the array was requested to be packed, but |
2750 | -- the packing request had no effect whatsoever, | |
2751 | -- so flag Is_Packed is reset. | |
2752 | ||
2753 | -- Note: semantically this means that we lose track | |
2754 | -- of the fact that a derived type inherited pragma | |
2755 | -- Pack that was non-effective, but that is fine. | |
2756 | ||
2757 | -- We regard a Pack pragma as a request to set a | |
2758 | -- representation characteristic, and this request | |
2759 | -- may be ignored. | |
2760 | ||
2761 | Set_Is_Packed (Base_Type (Arr), False); | |
f8c79ade | 2762 | Set_Has_Non_Standard_Rep (Base_Type (Arr), False); |
b3f75672 EB |
2763 | else |
2764 | Set_Is_Packed (Base_Type (Arr), True); | |
2765 | Set_Has_Non_Standard_Rep (Base_Type (Arr), True); | |
63bb4268 AC |
2766 | end if; |
2767 | ||
b3f75672 EB |
2768 | Set_Is_Bit_Packed_Array (Base_Type (Arr), False); |
2769 | ||
2770 | -- Bit packing is not needed for multiples of the storage | |
2771 | -- unit if the type is composite because the back end can | |
2772 | -- byte pack composite types. | |
2773 | ||
2774 | elsif Csiz mod System_Storage_Unit = 0 | |
2775 | and then Is_Composite_Type (Ctyp) | |
2776 | then | |
2777 | ||
2778 | Set_Is_Packed (Base_Type (Arr), True); | |
2779 | Set_Has_Non_Standard_Rep (Base_Type (Arr), True); | |
2780 | Set_Is_Bit_Packed_Array (Base_Type (Arr), False); | |
2781 | ||
2782 | -- In all other cases, bit packing is needed | |
63bb4268 AC |
2783 | |
2784 | else | |
b3f75672 | 2785 | Set_Is_Packed (Base_Type (Arr), True); |
63bb4268 AC |
2786 | Set_Has_Non_Standard_Rep (Base_Type (Arr), True); |
2787 | Set_Is_Bit_Packed_Array (Base_Type (Arr), True); | |
63bb4268 AC |
2788 | end if; |
2789 | end; | |
2790 | end if; | |
2791 | end; | |
2792 | ||
f280dd8f RD |
2793 | -- Check for Aliased or Atomic_Components/Atomic/VFA with |
2794 | -- unsuitable packing or explicit component size clause given. | |
63bb4268 | 2795 | |
7806a9ed | 2796 | if (Has_Aliased_Components (Arr) |
18dae814 | 2797 | or else Has_Atomic_Components (Arr) |
f280dd8f | 2798 | or else Is_Atomic_Or_VFA (Ctyp)) |
ef1c0511 AC |
2799 | and then |
2800 | (Has_Component_Size_Clause (Arr) or else Is_Packed (Arr)) | |
63bb4268 AC |
2801 | then |
2802 | Alias_Atomic_Check : declare | |
2803 | ||
2804 | procedure Complain_CS (T : String); | |
2805 | -- Outputs error messages for incorrect CS clause or pragma | |
f280dd8f RD |
2806 | -- Pack for aliased or atomic/VFA components (T is "aliased" |
2807 | -- or "atomic/vfa"); | |
63bb4268 AC |
2808 | |
2809 | ----------------- | |
2810 | -- Complain_CS -- | |
2811 | ----------------- | |
2812 | ||
2813 | procedure Complain_CS (T : String) is | |
2814 | begin | |
2815 | if Has_Component_Size_Clause (Arr) then | |
2816 | Clause := | |
2817 | Get_Attribute_Definition_Clause | |
2818 | (FS, Attribute_Component_Size); | |
2819 | ||
5dc6778c EB |
2820 | Error_Msg_N |
2821 | ("incorrect component size for " | |
2822 | & T & " components", Clause); | |
2823 | Error_Msg_Uint_1 := Esize (Ctyp); | |
2824 | Error_Msg_N | |
2825 | ("\only allowed value is^", Clause); | |
63bb4268 AC |
2826 | |
2827 | else | |
2828 | Error_Msg_N | |
2829 | ("cannot pack " & T & " components", | |
2830 | Get_Rep_Pragma (FS, Name_Pack)); | |
2831 | end if; | |
63bb4268 AC |
2832 | end Complain_CS; |
2833 | ||
2834 | -- Start of processing for Alias_Atomic_Check | |
2835 | ||
2836 | begin | |
63bb4268 AC |
2837 | -- If object size of component type isn't known, we cannot |
2838 | -- be sure so we defer to the back end. | |
2839 | ||
2840 | if not Known_Static_Esize (Ctyp) then | |
2841 | null; | |
2842 | ||
2843 | -- Case where component size has no effect. First check for | |
2844 | -- object size of component type multiple of the storage | |
2845 | -- unit size. | |
2846 | ||
2847 | elsif Esize (Ctyp) mod System_Storage_Unit = 0 | |
2848 | ||
2849 | -- OK in both packing case and component size case if RM | |
2850 | -- size is known and static and same as the object size. | |
2851 | ||
2852 | and then | |
2853 | ((Known_Static_RM_Size (Ctyp) | |
2854 | and then Esize (Ctyp) = RM_Size (Ctyp)) | |
2855 | ||
2856 | -- Or if we have an explicit component size clause and | |
2857 | -- the component size and object size are equal. | |
2858 | ||
2859 | or else | |
2860 | (Has_Component_Size_Clause (Arr) | |
2861 | and then Component_Size (Arr) = Esize (Ctyp))) | |
2862 | then | |
2863 | null; | |
2864 | ||
7806a9ed | 2865 | elsif Has_Aliased_Components (Arr) then |
63bb4268 AC |
2866 | Complain_CS ("aliased"); |
2867 | ||
f280dd8f RD |
2868 | elsif Has_Atomic_Components (Arr) |
2869 | or else Is_Atomic (Ctyp) | |
63bb4268 AC |
2870 | then |
2871 | Complain_CS ("atomic"); | |
f280dd8f | 2872 | |
57abdadd | 2873 | elsif Is_Volatile_Full_Access (Ctyp) then |
f280dd8f | 2874 | Complain_CS ("volatile full access"); |
63bb4268 AC |
2875 | end if; |
2876 | end Alias_Atomic_Check; | |
2877 | end if; | |
2878 | ||
07aff4e3 AC |
2879 | -- Check for Independent_Components/Independent with unsuitable |
2880 | -- packing or explicit component size clause given. | |
2881 | ||
2882 | if (Has_Independent_Components (Arr) or else Is_Independent (Ctyp)) | |
f280dd8f RD |
2883 | and then |
2884 | (Has_Component_Size_Clause (Arr) or else Is_Packed (Arr)) | |
07aff4e3 AC |
2885 | then |
2886 | begin | |
2887 | -- If object size of component type isn't known, we cannot | |
2888 | -- be sure so we defer to the back end. | |
2889 | ||
2890 | if not Known_Static_Esize (Ctyp) then | |
2891 | null; | |
2892 | ||
2893 | -- Case where component size has no effect. First check for | |
2894 | -- object size of component type multiple of the storage | |
2895 | -- unit size. | |
2896 | ||
2897 | elsif Esize (Ctyp) mod System_Storage_Unit = 0 | |
2898 | ||
2899 | -- OK in both packing case and component size case if RM | |
2900 | -- size is known and multiple of the storage unit size. | |
2901 | ||
2902 | and then | |
2903 | ((Known_Static_RM_Size (Ctyp) | |
2904 | and then RM_Size (Ctyp) mod System_Storage_Unit = 0) | |
2905 | ||
2906 | -- Or if we have an explicit component size clause and | |
2907 | -- the component size is larger than the object size. | |
2908 | ||
2909 | or else | |
2910 | (Has_Component_Size_Clause (Arr) | |
2911 | and then Component_Size (Arr) >= Esize (Ctyp))) | |
2912 | then | |
2913 | null; | |
2914 | ||
2915 | else | |
2916 | if Has_Component_Size_Clause (Arr) then | |
2917 | Clause := | |
2918 | Get_Attribute_Definition_Clause | |
2919 | (FS, Attribute_Component_Size); | |
2920 | ||
2921 | Error_Msg_N | |
2922 | ("incorrect component size for " | |
2923 | & "independent components", Clause); | |
2924 | Error_Msg_Uint_1 := Esize (Ctyp); | |
2925 | Error_Msg_N | |
2926 | ("\minimum allowed is^", Clause); | |
2927 | ||
2928 | else | |
2929 | Error_Msg_N | |
2930 | ("cannot pack independent components", | |
2931 | Get_Rep_Pragma (FS, Name_Pack)); | |
2932 | end if; | |
2933 | end if; | |
2934 | end; | |
2935 | end if; | |
2936 | ||
63bb4268 AC |
2937 | -- Warn for case of atomic type |
2938 | ||
2939 | Clause := Get_Rep_Pragma (FS, Name_Atomic); | |
2940 | ||
2941 | if Present (Clause) | |
2942 | and then not Addressable (Component_Size (FS)) | |
2943 | then | |
2944 | Error_Msg_NE | |
2945 | ("non-atomic components of type& may not be " | |
2946 | & "accessible by separate tasks??", Clause, Arr); | |
2947 | ||
2948 | if Has_Component_Size_Clause (Arr) then | |
ef1c0511 AC |
2949 | Error_Msg_Sloc := Sloc (Get_Attribute_Definition_Clause |
2950 | (FS, Attribute_Component_Size)); | |
2951 | Error_Msg_N ("\because of component size clause#??", Clause); | |
63bb4268 AC |
2952 | |
2953 | elsif Has_Pragma_Pack (Arr) then | |
ef1c0511 AC |
2954 | Error_Msg_Sloc := Sloc (Get_Rep_Pragma (FS, Name_Pack)); |
2955 | Error_Msg_N ("\because of pragma Pack#??", Clause); | |
63bb4268 AC |
2956 | end if; |
2957 | end if; | |
2958 | ||
2959 | -- Check for scalar storage order | |
2960 | ||
ee6208f2 AC |
2961 | declare |
2962 | Dummy : Boolean; | |
2963 | begin | |
2964 | Check_Component_Storage_Order | |
2965 | (Encl_Type => Arr, | |
2966 | Comp => Empty, | |
2967 | ADC => Get_Attribute_Definition_Clause | |
2968 | (First_Subtype (Arr), | |
2969 | Attribute_Scalar_Storage_Order), | |
2970 | Comp_ADC_Present => Dummy); | |
2971 | end; | |
63bb4268 | 2972 | |
ee6208f2 | 2973 | -- Processing that is done only for subtypes |
63bb4268 AC |
2974 | |
2975 | else | |
2976 | -- Acquire alignment from base type | |
2977 | ||
2978 | if Unknown_Alignment (Arr) then | |
2979 | Set_Alignment (Arr, Alignment (Base_Type (Arr))); | |
2980 | Adjust_Esize_Alignment (Arr); | |
2981 | end if; | |
2982 | end if; | |
2983 | ||
2984 | -- Specific checks for bit-packed arrays | |
2985 | ||
2986 | if Is_Bit_Packed_Array (Arr) then | |
2987 | ||
607114db | 2988 | -- Check number of elements for bit-packed arrays that come from |
63bb4268 AC |
2989 | -- source and have compile time known ranges. The bit-packed |
2990 | -- arrays circuitry does not support arrays with more than | |
2991 | -- Integer'Last + 1 elements, and when this restriction is | |
2992 | -- violated, causes incorrect data access. | |
2993 | ||
2994 | -- For the case where this is not compile time known, a run-time | |
2995 | -- check should be generated??? | |
2996 | ||
2997 | if Comes_From_Source (Arr) and then Is_Constrained (Arr) then | |
2998 | declare | |
2999 | Elmts : Uint; | |
3000 | Index : Node_Id; | |
3001 | Ilen : Node_Id; | |
3002 | Ityp : Entity_Id; | |
3003 | ||
3004 | begin | |
3005 | Elmts := Uint_1; | |
3006 | Index := First_Index (Arr); | |
3007 | while Present (Index) loop | |
3008 | Ityp := Etype (Index); | |
3009 | ||
3010 | -- Never generate an error if any index is of a generic | |
3011 | -- type. We will check this in instances. | |
3012 | ||
3013 | if Is_Generic_Type (Ityp) then | |
3014 | Elmts := Uint_0; | |
3015 | exit; | |
3016 | end if; | |
3017 | ||
3018 | Ilen := | |
3019 | Make_Attribute_Reference (Loc, | |
0fea901b | 3020 | Prefix => New_Occurrence_Of (Ityp, Loc), |
63bb4268 AC |
3021 | Attribute_Name => Name_Range_Length); |
3022 | Analyze_And_Resolve (Ilen); | |
3023 | ||
9ceeaf9d AC |
3024 | -- No attempt is made to check number of elements if not |
3025 | -- compile time known. | |
63bb4268 AC |
3026 | |
3027 | if Nkind (Ilen) /= N_Integer_Literal then | |
3028 | Elmts := Uint_0; | |
3029 | exit; | |
3030 | end if; | |
3031 | ||
3032 | Elmts := Elmts * Intval (Ilen); | |
3033 | Next_Index (Index); | |
3034 | end loop; | |
3035 | ||
3036 | if Elmts > Intval (High_Bound | |
ef1c0511 | 3037 | (Scalar_Range (Standard_Integer))) + 1 |
63bb4268 AC |
3038 | then |
3039 | Error_Msg_N | |
3040 | ("bit packed array type may not have " | |
3041 | & "more than Integer''Last+1 elements", Arr); | |
3042 | end if; | |
3043 | end; | |
3044 | end if; | |
3045 | ||
3046 | -- Check size | |
3047 | ||
3048 | if Known_RM_Size (Arr) then | |
3049 | declare | |
0fea901b | 3050 | SizC : constant Node_Id := Size_Clause (Arr); |
63bb4268 | 3051 | Discard : Boolean; |
63bb4268 AC |
3052 | |
3053 | begin | |
3054 | -- It is not clear if it is possible to have no size clause | |
3055 | -- at this stage, but it is not worth worrying about. Post | |
3056 | -- error on the entity name in the size clause if present, | |
3057 | -- else on the type entity itself. | |
3058 | ||
3059 | if Present (SizC) then | |
3060 | Check_Size (Name (SizC), Arr, RM_Size (Arr), Discard); | |
3061 | else | |
3062 | Check_Size (Arr, Arr, RM_Size (Arr), Discard); | |
3063 | end if; | |
3064 | end; | |
3065 | end if; | |
3066 | end if; | |
3067 | ||
9ceeaf9d AC |
3068 | -- If any of the index types was an enumeration type with a non- |
3069 | -- standard rep clause, then we indicate that the array type is | |
607114db | 3070 | -- always packed (even if it is not bit-packed). |
63bb4268 AC |
3071 | |
3072 | if Non_Standard_Enum then | |
3073 | Set_Has_Non_Standard_Rep (Base_Type (Arr)); | |
3074 | Set_Is_Packed (Base_Type (Arr)); | |
3075 | end if; | |
3076 | ||
3077 | Set_Component_Alignment_If_Not_Set (Arr); | |
3078 | ||
607114db | 3079 | -- If the array is packed and bit-packed or packed to eliminate holes |
b3f75672 EB |
3080 | -- in the non-contiguous enumeration index types, we must create the |
3081 | -- packed array type to be used to actually implement the type. This | |
3082 | -- is only needed for real array types (not for string literal types, | |
3083 | -- since they are present only for the front end). | |
63bb4268 AC |
3084 | |
3085 | if Is_Packed (Arr) | |
b3f75672 | 3086 | and then (Is_Bit_Packed_Array (Arr) or else Non_Standard_Enum) |
63bb4268 AC |
3087 | and then Ekind (Arr) /= E_String_Literal_Subtype |
3088 | then | |
8ca597af RD |
3089 | Create_Packed_Array_Impl_Type (Arr); |
3090 | Freeze_And_Append (Packed_Array_Impl_Type (Arr), N, Result); | |
63bb4268 | 3091 | |
8ad1c2df AC |
3092 | -- Make sure that we have the necessary routines to implement the |
3093 | -- packing, and complain now if not. Note that we only test this | |
3094 | -- for constrained array types. | |
3095 | ||
3096 | if Is_Constrained (Arr) | |
3097 | and then Is_Bit_Packed_Array (Arr) | |
3098 | and then Present (Packed_Array_Impl_Type (Arr)) | |
3099 | and then Is_Array_Type (Packed_Array_Impl_Type (Arr)) | |
3100 | then | |
3101 | declare | |
3102 | CS : constant Uint := Component_Size (Arr); | |
3103 | RE : constant RE_Id := Get_Id (UI_To_Int (CS)); | |
3104 | ||
3105 | begin | |
3106 | if RE /= RE_Null | |
3107 | and then not RTE_Available (RE) | |
3108 | then | |
3109 | Error_Msg_CRT | |
3110 | ("packing of " & UI_Image (CS) & "-bit components", | |
3111 | First_Subtype (Etype (Arr))); | |
3112 | ||
3113 | -- Cancel the packing | |
3114 | ||
3115 | Set_Is_Packed (Base_Type (Arr), False); | |
3116 | Set_Is_Bit_Packed_Array (Base_Type (Arr), False); | |
3117 | Set_Packed_Array_Impl_Type (Arr, Empty); | |
3118 | goto Skip_Packed; | |
3119 | end if; | |
3120 | end; | |
3121 | end if; | |
3122 | ||
63bb4268 AC |
3123 | -- Size information of packed array type is copied to the array |
3124 | -- type, since this is really the representation. But do not | |
3125 | -- override explicit existing size values. If the ancestor subtype | |
8ca597af RD |
3126 | -- is constrained the Packed_Array_Impl_Type will be inherited |
3127 | -- from it, but the size may have been provided already, and | |
3128 | -- must not be overridden either. | |
63bb4268 AC |
3129 | |
3130 | if not Has_Size_Clause (Arr) | |
3131 | and then | |
3132 | (No (Ancestor_Subtype (Arr)) | |
3133 | or else not Has_Size_Clause (Ancestor_Subtype (Arr))) | |
3134 | then | |
8ca597af RD |
3135 | Set_Esize (Arr, Esize (Packed_Array_Impl_Type (Arr))); |
3136 | Set_RM_Size (Arr, RM_Size (Packed_Array_Impl_Type (Arr))); | |
63bb4268 AC |
3137 | end if; |
3138 | ||
3139 | if not Has_Alignment_Clause (Arr) then | |
8ca597af | 3140 | Set_Alignment (Arr, Alignment (Packed_Array_Impl_Type (Arr))); |
63bb4268 AC |
3141 | end if; |
3142 | end if; | |
3143 | ||
8ad1c2df AC |
3144 | <<Skip_Packed>> |
3145 | ||
63bb4268 AC |
3146 | -- For non-packed arrays set the alignment of the array to the |
3147 | -- alignment of the component type if it is unknown. Skip this | |
f280dd8f | 3148 | -- in atomic/VFA case (atomic/VFA arrays may need larger alignments). |
63bb4268 AC |
3149 | |
3150 | if not Is_Packed (Arr) | |
3151 | and then Unknown_Alignment (Arr) | |
3152 | and then Known_Alignment (Ctyp) | |
3153 | and then Known_Static_Component_Size (Arr) | |
3154 | and then Known_Static_Esize (Ctyp) | |
3155 | and then Esize (Ctyp) = Component_Size (Arr) | |
f280dd8f | 3156 | and then not Is_Atomic_Or_VFA (Arr) |
63bb4268 AC |
3157 | then |
3158 | Set_Alignment (Arr, Alignment (Component_Type (Arr))); | |
3159 | end if; | |
58996b09 HK |
3160 | |
3161 | -- A Ghost type cannot have a component of protected or task type | |
3162 | -- (SPARK RM 6.9(19)). | |
3163 | ||
3164 | if Is_Ghost_Entity (Arr) and then Is_Concurrent_Type (Ctyp) then | |
3165 | Error_Msg_N | |
3166 | ("ghost array type & cannot have concurrent component type", | |
3167 | Arr); | |
3168 | end if; | |
63bb4268 AC |
3169 | end Freeze_Array_Type; |
3170 | ||
b741083a ES |
3171 | ------------------------------- |
3172 | -- Freeze_Object_Declaration -- | |
3173 | ------------------------------- | |
3174 | ||
3175 | procedure Freeze_Object_Declaration (E : Entity_Id) is | |
3176 | begin | |
73cc8f62 | 3177 | -- Abstract type allowed only for C++ imported variables or constants |
b741083a | 3178 | |
73cc8f62 RD |
3179 | -- Note: we inhibit this check for objects that do not come from |
3180 | -- source because there is at least one case (the expansion of | |
3181 | -- x'Class'Input where x is abstract) where we legitimately | |
3182 | -- generate an abstract object. | |
b741083a ES |
3183 | |
3184 | if Is_Abstract_Type (Etype (E)) | |
3185 | and then Comes_From_Source (Parent (E)) | |
3186 | and then not (Is_Imported (E) and then Is_CPP_Class (Etype (E))) | |
3187 | then | |
3188 | Error_Msg_N ("type of object cannot be abstract", | |
73cc8f62 | 3189 | Object_Definition (Parent (E))); |
b741083a ES |
3190 | |
3191 | if Is_CPP_Class (Etype (E)) then | |
73cc8f62 RD |
3192 | Error_Msg_NE |
3193 | ("\} may need a cpp_constructor", | |
b741083a ES |
3194 | Object_Definition (Parent (E)), Etype (E)); |
3195 | ||
3196 | elsif Present (Expression (Parent (E))) then | |
3197 | Error_Msg_N -- CODEFIX | |
3198 | ("\maybe a class-wide type was meant", | |
3199 | Object_Definition (Parent (E))); | |
3200 | end if; | |
3201 | end if; | |
3202 | ||
3203 | -- For object created by object declaration, perform required | |
3204 | -- categorization (preelaborate and pure) checks. Defer these | |
3205 | -- checks to freeze time since pragma Import inhibits default | |
3206 | -- initialization and thus pragma Import affects these checks. | |
3207 | ||
3208 | Validate_Object_Declaration (Declaration_Node (E)); | |
3209 | ||
3210 | -- If there is an address clause, check that it is valid | |
3211 | -- and if need be move initialization to the freeze node. | |
3212 | ||
3213 | Check_Address_Clause (E); | |
3214 | ||
3215 | -- Similar processing is needed for aspects that may affect | |
3216 | -- object layout, like Alignment, if there is an initialization | |
2df23f66 AC |
3217 | -- expression. We don't do this if there is a pragma Linker_Section, |
3218 | -- because it would prevent the back end from statically initializing | |
3219 | -- the object; we don't want elaboration code in that case. | |
b741083a ES |
3220 | |
3221 | if Has_Delayed_Aspects (E) | |
3222 | and then Expander_Active | |
3223 | and then Is_Array_Type (Etype (E)) | |
3224 | and then Present (Expression (Parent (E))) | |
2df23f66 | 3225 | and then No (Linker_Section_Pragma (E)) |
b741083a ES |
3226 | then |
3227 | declare | |
3228 | Decl : constant Node_Id := Parent (E); | |
73cc8f62 RD |
3229 | Lhs : constant Node_Id := New_Occurrence_Of (E, Loc); |
3230 | ||
b741083a ES |
3231 | begin |
3232 | ||
73cc8f62 RD |
3233 | -- Capture initialization value at point of declaration, and |
3234 | -- make explicit assignment legal, because object may be a | |
3235 | -- constant. | |
b741083a ES |
3236 | |
3237 | Remove_Side_Effects (Expression (Decl)); | |
3238 | Set_Assignment_OK (Lhs); | |
3239 | ||
3240 | -- Move initialization to freeze actions. | |
3241 | ||
3242 | Append_Freeze_Action (E, | |
3243 | Make_Assignment_Statement (Loc, | |
3244 | Name => Lhs, | |
3245 | Expression => Expression (Decl))); | |
3246 | ||
3247 | Set_No_Initialization (Decl); | |
3248 | -- Set_Is_Frozen (E, False); | |
3249 | end; | |
3250 | end if; | |
3251 | ||
3252 | -- Reset Is_True_Constant for non-constant aliased object. We | |
73cc8f62 RD |
3253 | -- consider that the fact that a non-constant object is aliased may |
3254 | -- indicate that some funny business is going on, e.g. an aliased | |
3255 | -- object is passed by reference to a procedure which captures the | |
3256 | -- address of the object, which is later used to assign a new value, | |
3257 | -- even though the compiler thinks that it is not modified. Such | |
3258 | -- code is highly dubious, but we choose to make it "work" for | |
3259 | -- non-constant aliased objects. | |
3260 | ||
3261 | -- Note that we used to do this for all aliased objects, whether or | |
3262 | -- not constant, but this caused anomalies down the line because we | |
3263 | -- ended up with static objects that were not Is_True_Constant. Not | |
3264 | -- resetting Is_True_Constant for (aliased) constant objects ensures | |
3265 | -- that this anomaly never occurs. | |
3266 | ||
3267 | -- However, we don't do that for internal entities. We figure that if | |
3268 | -- we deliberately set Is_True_Constant for an internal entity, e.g. | |
3269 | -- a dispatch table entry, then we mean it. | |
b741083a ES |
3270 | |
3271 | if Ekind (E) /= E_Constant | |
3272 | and then (Is_Aliased (E) or else Is_Aliased (Etype (E))) | |
3273 | and then not Is_Internal_Name (Chars (E)) | |
3274 | then | |
3275 | Set_Is_True_Constant (E, False); | |
3276 | end if; | |
3277 | ||
73cc8f62 RD |
3278 | -- If the object needs any kind of default initialization, an error |
3279 | -- must be issued if No_Default_Initialization applies. The check | |
3280 | -- doesn't apply to imported objects, which are not ever default | |
3281 | -- initialized, and is why the check is deferred until freezing, at | |
3282 | -- which point we know if Import applies. Deferred constants are also | |
3283 | -- exempted from this test because their completion is explicit, or | |
3284 | -- through an import pragma. | |
b741083a | 3285 | |
73cc8f62 | 3286 | if Ekind (E) = E_Constant and then Present (Full_View (E)) then |
b741083a ES |
3287 | null; |
3288 | ||
3289 | elsif Comes_From_Source (E) | |
3290 | and then not Is_Imported (E) | |
3291 | and then not Has_Init_Expression (Declaration_Node (E)) | |
3292 | and then | |
3293 | ((Has_Non_Null_Base_Init_Proc (Etype (E)) | |
3294 | and then not No_Initialization (Declaration_Node (E)) | |
b741083a ES |
3295 | and then not Initialization_Suppressed (Etype (E))) |
3296 | or else | |
3297 | (Needs_Simple_Initialization (Etype (E)) | |
3298 | and then not Is_Internal (E))) | |
3299 | then | |
3300 | Has_Default_Initialization := True; | |
3301 | Check_Restriction | |
3302 | (No_Default_Initialization, Declaration_Node (E)); | |
3303 | end if; | |
3304 | ||
3305 | -- Check that a Thread_Local_Storage variable does not have | |
3306 | -- default initialization, and any explicit initialization must | |
3307 | -- either be the null constant or a static constant. | |
3308 | ||
3309 | if Has_Pragma_Thread_Local_Storage (E) then | |
3310 | declare | |
3311 | Decl : constant Node_Id := Declaration_Node (E); | |
3312 | begin | |
3313 | if Has_Default_Initialization | |
3314 | or else | |
3315 | (Has_Init_Expression (Decl) | |
3316 | and then | |
3317 | (No (Expression (Decl)) | |
3318 | or else not | |
3319 | (Is_OK_Static_Expression (Expression (Decl)) | |
3320 | or else Nkind (Expression (Decl)) = N_Null))) | |
3321 | then | |
3322 | Error_Msg_NE | |
3323 | ("Thread_Local_Storage variable& is " | |
3324 | & "improperly initialized", Decl, E); | |
3325 | Error_Msg_NE | |
3326 | ("\only allowed initialization is explicit " | |
3327 | & "NULL or static expression", Decl, E); | |
3328 | end if; | |
3329 | end; | |
3330 | end if; | |
3331 | ||
3332 | -- For imported objects, set Is_Public unless there is also an | |
3333 | -- address clause, which means that there is no external symbol | |
3334 | -- needed for the Import (Is_Public may still be set for other | |
3335 | -- unrelated reasons). Note that we delayed this processing | |
3336 | -- till freeze time so that we can be sure not to set the flag | |
3337 | -- if there is an address clause. If there is such a clause, | |
3338 | -- then the only purpose of the Import pragma is to suppress | |
3339 | -- implicit initialization. | |
3340 | ||
3341 | if Is_Imported (E) and then No (Address_Clause (E)) then | |
3342 | Set_Is_Public (E); | |
3343 | end if; | |
3344 | ||
3345 | -- For source objects that are not Imported and are library | |
3346 | -- level, if no linker section pragma was given inherit the | |
3347 | -- appropriate linker section from the corresponding type. | |
3348 | ||
3349 | if Comes_From_Source (E) | |
3350 | and then not Is_Imported (E) | |
3351 | and then Is_Library_Level_Entity (E) | |
3352 | and then No (Linker_Section_Pragma (E)) | |
3353 | then | |
3354 | Set_Linker_Section_Pragma | |
3355 | (E, Linker_Section_Pragma (Etype (E))); | |
3356 | end if; | |
3357 | ||
3358 | -- For convention C objects of an enumeration type, warn if the | |
3359 | -- size is not integer size and no explicit size given. Skip | |
3360 | -- warning for Boolean, and Character, assume programmer expects | |
3361 | -- 8-bit sizes for these cases. | |
3362 | ||
3363 | if (Convention (E) = Convention_C | |
73cc8f62 RD |
3364 | or else |
3365 | Convention (E) = Convention_CPP) | |
b741083a ES |
3366 | and then Is_Enumeration_Type (Etype (E)) |
3367 | and then not Is_Character_Type (Etype (E)) | |
3368 | and then not Is_Boolean_Type (Etype (E)) | |
3369 | and then Esize (Etype (E)) < Standard_Integer_Size | |
3370 | and then not Has_Size_Clause (E) | |
3371 | then | |
3372 | Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size); | |
3373 | Error_Msg_N | |
3374 | ("??convention C enumeration object has size less than ^", E); | |
3375 | Error_Msg_N ("\??use explicit size clause to set size", E); | |
3376 | end if; | |
3377 | end Freeze_Object_Declaration; | |
3378 | ||
3cd4a210 AC |
3379 | ----------------------------- |
3380 | -- Freeze_Generic_Entities -- | |
3381 | ----------------------------- | |
3382 | ||
3383 | function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id is | |
5a8a6763 RD |
3384 | E : Entity_Id; |
3385 | F : Node_Id; | |
3cd4a210 AC |
3386 | Flist : List_Id; |
3387 | ||
3388 | begin | |
3389 | Flist := New_List; | |
3390 | E := First_Entity (Pack); | |
3391 | while Present (E) loop | |
3392 | if Is_Type (E) and then not Is_Generic_Type (E) then | |
3393 | F := Make_Freeze_Generic_Entity (Sloc (Pack)); | |
3394 | Set_Entity (F, E); | |
3395 | Append_To (Flist, F); | |
3396 | ||
3397 | elsif Ekind (E) = E_Generic_Package then | |
3398 | Append_List_To (Flist, Freeze_Generic_Entities (E)); | |
3399 | end if; | |
3400 | ||
3401 | Next_Entity (E); | |
3402 | end loop; | |
3403 | ||
3404 | return Flist; | |
3405 | end Freeze_Generic_Entities; | |
3406 | ||
4d1429b2 AC |
3407 | -------------------- |
3408 | -- Freeze_Profile -- | |
3409 | -------------------- | |
3410 | ||
3411 | function Freeze_Profile (E : Entity_Id) return Boolean is | |
3412 | F_Type : Entity_Id; | |
3413 | R_Type : Entity_Id; | |
3414 | Warn_Node : Node_Id; | |
3415 | ||
3416 | begin | |
3417 | -- Loop through formals | |
3418 | ||
3419 | Formal := First_Formal (E); | |
3420 | while Present (Formal) loop | |
3421 | F_Type := Etype (Formal); | |
3422 | ||
9ceeaf9d AC |
3423 | -- AI05-0151: incomplete types can appear in a profile. By the |
3424 | -- time the entity is frozen, the full view must be available, | |
3425 | -- unless it is a limited view. | |
4d1429b2 AC |
3426 | |
3427 | if Is_Incomplete_Type (F_Type) | |
3428 | and then Present (Full_View (F_Type)) | |
3429 | and then not From_Limited_With (F_Type) | |
3430 | then | |
3431 | F_Type := Full_View (F_Type); | |
3432 | Set_Etype (Formal, F_Type); | |
3433 | end if; | |
3434 | ||
4f2cae4a ES |
3435 | if not From_Limited_With (F_Type) then |
3436 | Freeze_And_Append (F_Type, N, Result); | |
3437 | end if; | |
4d1429b2 AC |
3438 | |
3439 | if Is_Private_Type (F_Type) | |
3440 | and then Is_Private_Type (Base_Type (F_Type)) | |
3441 | and then No (Full_View (Base_Type (F_Type))) | |
3442 | and then not Is_Generic_Type (F_Type) | |
3443 | and then not Is_Derived_Type (F_Type) | |
3444 | then | |
9ceeaf9d AC |
3445 | -- If the type of a formal is incomplete, subprogram is being |
3446 | -- frozen prematurely. Within an instance (but not within a | |
3447 | -- wrapper package) this is an artifact of our need to regard | |
3448 | -- the end of an instantiation as a freeze point. Otherwise it | |
3449 | -- is a definite error. | |
4d1429b2 AC |
3450 | |
3451 | if In_Instance then | |
3452 | Set_Is_Frozen (E, False); | |
3453 | Result := No_List; | |
3454 | return False; | |
3455 | ||
3456 | elsif not After_Last_Declaration | |
3457 | and then not Freezing_Library_Level_Tagged_Type | |
3458 | then | |
3459 | Error_Msg_Node_1 := F_Type; | |
3460 | Error_Msg | |
9ceeaf9d | 3461 | ("type & must be fully defined before this point", Loc); |
4d1429b2 AC |
3462 | end if; |
3463 | end if; | |
3464 | ||
9ceeaf9d AC |
3465 | -- Check suspicious parameter for C function. These tests apply |
3466 | -- only to exported/imported subprograms. | |
4d1429b2 AC |
3467 | |
3468 | if Warn_On_Export_Import | |
3469 | and then Comes_From_Source (E) | |
3470 | and then (Convention (E) = Convention_C | |
3471 | or else | |
3472 | Convention (E) = Convention_CPP) | |
3473 | and then (Is_Imported (E) or else Is_Exported (E)) | |
3474 | and then Convention (E) /= Convention (Formal) | |
3475 | and then not Has_Warnings_Off (E) | |
3476 | and then not Has_Warnings_Off (F_Type) | |
3477 | and then not Has_Warnings_Off (Formal) | |
3478 | then | |
3479 | -- Qualify mention of formals with subprogram name | |
3480 | ||
3481 | Error_Msg_Qual_Level := 1; | |
3482 | ||
3483 | -- Check suspicious use of fat C pointer | |
3484 | ||
3485 | if Is_Access_Type (F_Type) | |
3486 | and then Esize (F_Type) > Ttypes.System_Address_Size | |
3487 | then | |
3488 | Error_Msg_N | |
3489 | ("?x?type of & does not correspond to C pointer!", Formal); | |
3490 | ||
3491 | -- Check suspicious return of boolean | |
3492 | ||
3493 | elsif Root_Type (F_Type) = Standard_Boolean | |
3494 | and then Convention (F_Type) = Convention_Ada | |
3495 | and then not Has_Warnings_Off (F_Type) | |
3496 | and then not Has_Size_Clause (F_Type) | |
4d1429b2 | 3497 | then |
9ceeaf9d AC |
3498 | Error_Msg_N |
3499 | ("& is an 8-bit Ada Boolean?x?", Formal); | |
3500 | Error_Msg_N | |
3501 | ("\use appropriate corresponding type in C " | |
4d1429b2 AC |
3502 | & "(e.g. char)?x?", Formal); |
3503 | ||
3504 | -- Check suspicious tagged type | |
3505 | ||
3506 | elsif (Is_Tagged_Type (F_Type) | |
9ceeaf9d AC |
3507 | or else |
3508 | (Is_Access_Type (F_Type) | |
3509 | and then Is_Tagged_Type (Designated_Type (F_Type)))) | |
4d1429b2 AC |
3510 | and then Convention (E) = Convention_C |
3511 | then | |
9ceeaf9d AC |
3512 | Error_Msg_N |
3513 | ("?x?& involves a tagged type which does not " | |
4d1429b2 AC |
3514 | & "correspond to any C type!", Formal); |
3515 | ||
3516 | -- Check wrong convention subprogram pointer | |
3517 | ||
3518 | elsif Ekind (F_Type) = E_Access_Subprogram_Type | |
3519 | and then not Has_Foreign_Convention (F_Type) | |
3520 | then | |
9ceeaf9d AC |
3521 | Error_Msg_N |
3522 | ("?x?subprogram pointer & should " | |
4d1429b2 AC |
3523 | & "have foreign convention!", Formal); |
3524 | Error_Msg_Sloc := Sloc (F_Type); | |
3525 | Error_Msg_NE | |
3526 | ("\?x?add Convention pragma to declaration of &#", | |
3527 | Formal, F_Type); | |
3528 | end if; | |
3529 | ||
3530 | -- Turn off name qualification after message output | |
3531 | ||
3532 | Error_Msg_Qual_Level := 0; | |
3533 | end if; | |
3534 | ||
9ceeaf9d AC |
3535 | -- Check for unconstrained array in exported foreign convention |
3536 | -- case. | |
4d1429b2 AC |
3537 | |
3538 | if Has_Foreign_Convention (E) | |
3539 | and then not Is_Imported (E) | |
3540 | and then Is_Array_Type (F_Type) | |
3541 | and then not Is_Constrained (F_Type) | |
3542 | and then Warn_On_Export_Import | |
4d1429b2 AC |
3543 | then |
3544 | Error_Msg_Qual_Level := 1; | |
3545 | ||
9ceeaf9d AC |
3546 | -- If this is an inherited operation, place the warning on |
3547 | -- the derived type declaration, rather than on the original | |
3548 | -- subprogram. | |
4d1429b2 AC |
3549 | |
3550 | if Nkind (Original_Node (Parent (E))) = N_Full_Type_Declaration | |
3551 | then | |
3552 | Warn_Node := Parent (E); | |
3553 | ||
3554 | if Formal = First_Formal (E) then | |
9ceeaf9d | 3555 | Error_Msg_NE ("??in inherited operation&", Warn_Node, E); |
4d1429b2 AC |
3556 | end if; |
3557 | else | |
3558 | Warn_Node := Formal; | |
3559 | end if; | |
3560 | ||
3561 | Error_Msg_NE ("?x?type of argument& is unconstrained array", | |
3562 | Warn_Node, Formal); | |
3563 | Error_Msg_NE ("?x?foreign caller must pass bounds explicitly", | |
3564 | Warn_Node, Formal); | |
3565 | Error_Msg_Qual_Level := 0; | |
3566 | end if; | |
3567 | ||
3568 | if not From_Limited_With (F_Type) then | |
3569 | if Is_Access_Type (F_Type) then | |
3570 | F_Type := Designated_Type (F_Type); | |
3571 | end if; | |
3572 | ||
3573 | -- If the formal is an anonymous_access_to_subprogram | |
3574 | -- freeze the subprogram type as well, to prevent | |
3575 | -- scope anomalies in gigi, because there is no other | |
3576 | -- clear point at which it could be frozen. | |
3577 | ||
3578 | if Is_Itype (Etype (Formal)) | |
3579 | and then Ekind (F_Type) = E_Subprogram_Type | |
3580 | then | |
3581 | Freeze_And_Append (F_Type, N, Result); | |
3582 | end if; | |
3583 | end if; | |
3584 | ||
3585 | Next_Formal (Formal); | |
3586 | end loop; | |
3587 | ||
3588 | -- Case of function: similar checks on return type | |
3589 | ||
3590 | if Ekind (E) = E_Function then | |
3591 | ||
4d1429b2 AC |
3592 | -- Freeze return type |
3593 | ||
3594 | R_Type := Etype (E); | |
3595 | ||
d8f43ee6 HK |
3596 | -- AI05-0151: the return type may have been incomplete at the |
3597 | -- point of declaration. Replace it with the full view, unless the | |
3598 | -- current type is a limited view. In that case the full view is | |
3599 | -- in a different unit, and gigi finds the non-limited view after | |
3600 | -- the other unit is elaborated. | |
4d1429b2 AC |
3601 | |
3602 | if Ekind (R_Type) = E_Incomplete_Type | |
3603 | and then Present (Full_View (R_Type)) | |
3604 | and then not From_Limited_With (R_Type) | |
3605 | then | |
3606 | R_Type := Full_View (R_Type); | |
3607 | Set_Etype (E, R_Type); | |
4d1429b2 AC |
3608 | end if; |
3609 | ||
3610 | Freeze_And_Append (R_Type, N, Result); | |
3611 | ||
3612 | -- Check suspicious return type for C function | |
3613 | ||
3614 | if Warn_On_Export_Import | |
3615 | and then (Convention (E) = Convention_C | |
3616 | or else | |
3617 | Convention (E) = Convention_CPP) | |
3618 | and then (Is_Imported (E) or else Is_Exported (E)) | |
3619 | then | |
3620 | -- Check suspicious return of fat C pointer | |
3621 | ||
3622 | if Is_Access_Type (R_Type) | |
3623 | and then Esize (R_Type) > Ttypes.System_Address_Size | |
3624 | and then not Has_Warnings_Off (E) | |
3625 | and then not Has_Warnings_Off (R_Type) | |
3626 | then | |
d8f43ee6 HK |
3627 | Error_Msg_N |
3628 | ("?x?return type of& does not correspond to C pointer!", | |
3629 | E); | |
4d1429b2 AC |
3630 | |
3631 | -- Check suspicious return of boolean | |
3632 | ||
3633 | elsif Root_Type (R_Type) = Standard_Boolean | |
3634 | and then Convention (R_Type) = Convention_Ada | |
4d1429b2 AC |
3635 | and then not Has_Warnings_Off (E) |
3636 | and then not Has_Warnings_Off (R_Type) | |
3637 | and then not Has_Size_Clause (R_Type) | |
3638 | then | |
3639 | declare | |
3640 | N : constant Node_Id := | |
3641 | Result_Definition (Declaration_Node (E)); | |
3642 | begin | |
3643 | Error_Msg_NE | |
3644 | ("return type of & is an 8-bit Ada Boolean?x?", N, E); | |
3645 | Error_Msg_NE | |
3646 | ("\use appropriate corresponding type in C " | |
3647 | & "(e.g. char)?x?", N, E); | |
3648 | end; | |
3649 | ||
3650 | -- Check suspicious return tagged type | |
3651 | ||
3652 | elsif (Is_Tagged_Type (R_Type) | |
3653 | or else (Is_Access_Type (R_Type) | |
3654 | and then | |
3655 | Is_Tagged_Type | |
3656 | (Designated_Type (R_Type)))) | |
3657 | and then Convention (E) = Convention_C | |
3658 | and then not Has_Warnings_Off (E) | |
3659 | and then not Has_Warnings_Off (R_Type) | |
3660 | then | |
3661 | Error_Msg_N ("?x?return type of & does not " | |
3662 | & "correspond to C type!", E); | |
3663 | ||
3664 | -- Check return of wrong convention subprogram pointer | |
3665 | ||
3666 | elsif Ekind (R_Type) = E_Access_Subprogram_Type | |
3667 | and then not Has_Foreign_Convention (R_Type) | |
3668 | and then not Has_Warnings_Off (E) | |
3669 | and then not Has_Warnings_Off (R_Type) | |
3670 | then | |
3671 | Error_Msg_N ("?x?& should return a foreign " | |
3672 | & "convention subprogram pointer", E); | |
3673 | Error_Msg_Sloc := Sloc (R_Type); | |
3674 | Error_Msg_NE | |
3675 | ("\?x?add Convention pragma to declaration of& #", | |
3676 | E, R_Type); | |
3677 | end if; | |
3678 | end if; | |
3679 | ||
3680 | -- Give warning for suspicious return of a result of an | |
9ceeaf9d | 3681 | -- unconstrained array type in a foreign convention function. |
4d1429b2 AC |
3682 | |
3683 | if Has_Foreign_Convention (E) | |
3684 | ||
3685 | -- We are looking for a return of unconstrained array | |
3686 | ||
3687 | and then Is_Array_Type (R_Type) | |
3688 | and then not Is_Constrained (R_Type) | |
3689 | ||
9ceeaf9d AC |
3690 | -- Exclude imported routines, the warning does not belong on |
3691 | -- the import, but rather on the routine definition. | |
4d1429b2 AC |
3692 | |
3693 | and then not Is_Imported (E) | |
3694 | ||
9ceeaf9d AC |
3695 | -- Check that general warning is enabled, and that it is not |
3696 | -- suppressed for this particular case. | |
4d1429b2 AC |
3697 | |
3698 | and then Warn_On_Export_Import | |
3699 | and then not Has_Warnings_Off (E) | |
3700 | and then not Has_Warnings_Off (R_Type) | |
3701 | then | |
f3bf0d9a HK |
3702 | Error_Msg_N |
3703 | ("?x?foreign convention function& should not return " | |
3704 | & "unconstrained array!", E); | |
4d1429b2 AC |
3705 | end if; |
3706 | end if; | |
3707 | ||
a79cdb2c BD |
3708 | -- Check suspicious use of Import in pure unit (cases where the RM |
3709 | -- allows calls to be omitted). | |
e5cabfac | 3710 | |
a79cdb2c BD |
3711 | if Is_Imported (E) |
3712 | ||
3713 | -- It might be suspicious if the compilation unit has the Pure | |
3714 | -- aspect/pragma. | |
3715 | ||
3716 | and then Has_Pragma_Pure (Cunit_Entity (Current_Sem_Unit)) | |
3717 | ||
3718 | -- The RM allows omission of calls only in the case of | |
3719 | -- library-level subprograms (see RM-10.2.1(18)). | |
3720 | ||
3721 | and then Is_Library_Level_Entity (E) | |
e5cabfac AC |
3722 | |
3723 | -- Ignore internally generated entity. This happens in some cases | |
3724 | -- of subprograms in specs, where we generate an implied body. | |
3725 | ||
3726 | and then Comes_From_Source (Import_Pragma (E)) | |
3727 | ||
3728 | -- Assume run-time knows what it is doing | |
3729 | ||
3730 | and then not GNAT_Mode | |
3731 | ||
3732 | -- Assume explicit Pure_Function means import is pure | |
3733 | ||
3734 | and then not Has_Pragma_Pure_Function (E) | |
3735 | ||
3736 | -- Don't need warning in relaxed semantics mode | |
3737 | ||
3738 | and then not Relaxed_RM_Semantics | |
3739 | ||
3740 | -- Assume convention Intrinsic is OK, since this is specialized. | |
3741 | -- This deals with the DEC unit current_exception.ads | |
3742 | ||
3743 | and then Convention (E) /= Convention_Intrinsic | |
3744 | ||
4179af27 | 3745 | -- Assume that ASM interface knows what it is doing. This deals |
f96fd197 | 3746 | -- with e.g. unsigned.ads in the AAMP back end. |
e5cabfac AC |
3747 | |
3748 | and then Convention (E) /= Convention_Assembler | |
3749 | then | |
3750 | Error_Msg_N | |
3751 | ("pragma Import in Pure unit??", Import_Pragma (E)); | |
3752 | Error_Msg_NE | |
3753 | ("\calls to & may be omitted (RM 10.2.1(18/3))??", | |
3754 | Import_Pragma (E), E); | |
3755 | end if; | |
3756 | ||
4d1429b2 AC |
3757 | return True; |
3758 | end Freeze_Profile; | |
3759 | ||
70482933 RK |
3760 | ------------------------ |
3761 | -- Freeze_Record_Type -- | |
3762 | ------------------------ | |
3763 | ||
3764 | procedure Freeze_Record_Type (Rec : Entity_Id) is | |
7b4ebba5 | 3765 | ADC : Node_Id; |
70482933 | 3766 | Comp : Entity_Id; |
fbf5a39b | 3767 | IR : Node_Id; |
c6823a20 | 3768 | Prev : Entity_Id; |
70482933 | 3769 | |
67ce0d7e RD |
3770 | Junk : Boolean; |
3771 | pragma Warnings (Off, Junk); | |
3772 | ||
515490e0 AC |
3773 | Aliased_Component : Boolean := False; |
3774 | -- Set True if we find at least one component which is aliased. This | |
3775 | -- is used to prevent Implicit_Packing of the record, since packing | |
3776 | -- cannot modify the size of alignment of an aliased component. | |
3777 | ||
f91caacb | 3778 | All_Elem_Components : Boolean := True; |
820f1162 AC |
3779 | -- True if all components are of a type whose underlying type is |
3780 | -- elementary. | |
8dc10d38 | 3781 | |
f91caacb | 3782 | All_Sized_Components : Boolean := True; |
820f1162 | 3783 | -- True if all components have a known RM_Size |
f91caacb EB |
3784 | |
3785 | All_Storage_Unit_Components : Boolean := True; | |
820f1162 AC |
3786 | -- True if all components have an RM_Size that is a multiple of the |
3787 | -- storage unit. | |
f91caacb EB |
3788 | |
3789 | Elem_Component_Total_Esize : Uint := Uint_0; | |
3790 | -- Accumulates total Esize values of all elementary components. Used | |
3791 | -- for processing of Implicit_Packing. | |
3792 | ||
c70cf4f8 AC |
3793 | Placed_Component : Boolean := False; |
3794 | -- Set True if we find at least one component with a component | |
3795 | -- clause (used to warn about useless Bit_Order pragmas, and also | |
3796 | -- to detect cases where Implicit_Packing may have an effect). | |
3797 | ||
3798 | Rec_Pushed : Boolean := False; | |
3799 | -- Set True if the record type scope Rec has been pushed on the scope | |
3800 | -- stack. Needed for the analysis of delayed aspects specified to the | |
3801 | -- components of Rec. | |
3802 | ||
f91caacb EB |
3803 | Sized_Component_Total_RM_Size : Uint := Uint_0; |
3804 | -- Accumulates total RM_Size values of all sized components. Used | |
3805 | -- for processing of Implicit_Packing. | |
70482933 | 3806 | |
c70cf4f8 AC |
3807 | SSO_ADC : Node_Id; |
3808 | -- Scalar_Storage_Order attribute definition clause for the record | |
3809 | ||
3810 | SSO_ADC_Component : Boolean := False; | |
3811 | -- Set True if we find at least one component whose type has a | |
3812 | -- Scalar_Storage_Order attribute definition clause. | |
3813 | ||
3814 | Unplaced_Component : Boolean := False; | |
3815 | -- Set True if we find at least one component with no component | |
3816 | -- clause (used to warn about useless Pack pragmas). | |
3817 | ||
e18d6a15 JM |
3818 | function Check_Allocator (N : Node_Id) return Node_Id; |
3819 | -- If N is an allocator, possibly wrapped in one or more level of | |
3820 | -- qualified expression(s), return the inner allocator node, else | |
3821 | -- return Empty. | |
19590d70 | 3822 | |
7d8b9c99 RD |
3823 | procedure Check_Itype (Typ : Entity_Id); |
3824 | -- If the component subtype is an access to a constrained subtype of | |
3825 | -- an already frozen type, make the subtype frozen as well. It might | |
3826 | -- otherwise be frozen in the wrong scope, and a freeze node on | |
3827 | -- subtype has no effect. Similarly, if the component subtype is a | |
3828 | -- regular (not protected) access to subprogram, set the anonymous | |
3829 | -- subprogram type to frozen as well, to prevent an out-of-scope | |
3830 | -- freeze node at some eventual point of call. Protected operations | |
3831 | -- are handled elsewhere. | |
6e059adb | 3832 | |
c76bf0bf AC |
3833 | procedure Freeze_Choices_In_Variant_Part (VP : Node_Id); |
3834 | -- Make sure that all types mentioned in Discrete_Choices of the | |
3835 | -- variants referenceed by the Variant_Part VP are frozen. This is | |
3836 | -- a recursive routine to deal with nested variants. | |
3837 | ||
19590d70 GD |
3838 | --------------------- |
3839 | -- Check_Allocator -- | |
3840 | --------------------- | |
3841 | ||
e18d6a15 JM |
3842 | function Check_Allocator (N : Node_Id) return Node_Id is |
3843 | Inner : Node_Id; | |
19590d70 | 3844 | begin |
e18d6a15 | 3845 | Inner := N; |
e18d6a15 JM |
3846 | loop |
3847 | if Nkind (Inner) = N_Allocator then | |
3848 | return Inner; | |
e18d6a15 JM |
3849 | elsif Nkind (Inner) = N_Qualified_Expression then |
3850 | Inner := Expression (Inner); | |
e18d6a15 JM |
3851 | else |
3852 | return Empty; | |
3853 | end if; | |
3854 | end loop; | |
19590d70 GD |
3855 | end Check_Allocator; |
3856 | ||
6871ba5f AC |
3857 | ----------------- |
3858 | -- Check_Itype -- | |
3859 | ----------------- | |
3860 | ||
7d8b9c99 RD |
3861 | procedure Check_Itype (Typ : Entity_Id) is |
3862 | Desig : constant Entity_Id := Designated_Type (Typ); | |
3863 | ||
6e059adb AC |
3864 | begin |
3865 | if not Is_Frozen (Desig) | |
3866 | and then Is_Frozen (Base_Type (Desig)) | |
3867 | then | |
3868 | Set_Is_Frozen (Desig); | |
3869 | ||
3870 | -- In addition, add an Itype_Reference to ensure that the | |
7d8b9c99 RD |
3871 | -- access subtype is elaborated early enough. This cannot be |
3872 | -- done if the subtype may depend on discriminants. | |
6e059adb AC |
3873 | |
3874 | if Ekind (Comp) = E_Component | |
3875 | and then Is_Itype (Etype (Comp)) | |
3876 | and then not Has_Discriminants (Rec) | |
3877 | then | |
3878 | IR := Make_Itype_Reference (Sloc (Comp)); | |
3879 | Set_Itype (IR, Desig); | |
90878b12 | 3880 | Add_To_Result (IR); |
6e059adb | 3881 | end if; |
7d8b9c99 RD |
3882 | |
3883 | elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type | |
3884 | and then Convention (Desig) /= Convention_Protected | |
3885 | then | |
3886 | Set_Is_Frozen (Desig); | |
6e059adb AC |
3887 | end if; |
3888 | end Check_Itype; | |
3889 | ||
c76bf0bf AC |
3890 | ------------------------------------ |
3891 | -- Freeze_Choices_In_Variant_Part -- | |
3892 | ------------------------------------ | |
3893 | ||
3894 | procedure Freeze_Choices_In_Variant_Part (VP : Node_Id) is | |
3895 | pragma Assert (Nkind (VP) = N_Variant_Part); | |
3896 | ||
3897 | Variant : Node_Id; | |
3898 | Choice : Node_Id; | |
3899 | CL : Node_Id; | |
3900 | ||
3901 | begin | |
3902 | -- Loop through variants | |
3903 | ||
3904 | Variant := First_Non_Pragma (Variants (VP)); | |
3905 | while Present (Variant) loop | |
3906 | ||
3907 | -- Loop through choices, checking that all types are frozen | |
3908 | ||
3909 | Choice := First_Non_Pragma (Discrete_Choices (Variant)); | |
3910 | while Present (Choice) loop | |
3911 | if Nkind (Choice) in N_Has_Etype | |
3912 | and then Present (Etype (Choice)) | |
3913 | then | |
3914 | Freeze_And_Append (Etype (Choice), N, Result); | |
3915 | end if; | |
3916 | ||
3917 | Next_Non_Pragma (Choice); | |
3918 | end loop; | |
3919 | ||
3920 | -- Check for nested variant part to process | |
3921 | ||
3922 | CL := Component_List (Variant); | |
3923 | ||
3924 | if not Null_Present (CL) then | |
3925 | if Present (Variant_Part (CL)) then | |
3926 | Freeze_Choices_In_Variant_Part (Variant_Part (CL)); | |
3927 | end if; | |
3928 | end if; | |
3929 | ||
3930 | Next_Non_Pragma (Variant); | |
3931 | end loop; | |
3932 | end Freeze_Choices_In_Variant_Part; | |
3933 | ||
6e059adb AC |
3934 | -- Start of processing for Freeze_Record_Type |
3935 | ||
70482933 | 3936 | begin |
22a83cea AC |
3937 | -- Deal with delayed aspect specifications for components. The |
3938 | -- analysis of the aspect is required to be delayed to the freeze | |
d27f3ff4 AC |
3939 | -- point, thus we analyze the pragma or attribute definition |
3940 | -- clause in the tree at this point. We also analyze the aspect | |
22a83cea AC |
3941 | -- specification node at the freeze point when the aspect doesn't |
3942 | -- correspond to pragma/attribute definition clause. | |
70482933 RK |
3943 | |
3944 | Comp := First_Entity (Rec); | |
c6823a20 | 3945 | while Present (Comp) loop |
b3f532ce | 3946 | if Ekind (Comp) = E_Component |
b7f7dab2 | 3947 | and then Has_Delayed_Aspects (Comp) |
b3f532ce | 3948 | then |
22a83cea AC |
3949 | if not Rec_Pushed then |
3950 | Push_Scope (Rec); | |
3951 | Rec_Pushed := True; | |
b3f532ce | 3952 | |
22a83cea AC |
3953 | -- The visibility to the discriminants must be restored in |
3954 | -- order to properly analyze the aspects. | |
b3f532ce | 3955 | |
22a83cea AC |
3956 | if Has_Discriminants (Rec) then |
3957 | Install_Discriminants (Rec); | |
3958 | end if; | |
b3f532ce AC |
3959 | end if; |
3960 | ||
22a83cea | 3961 | Analyze_Aspects_At_Freeze_Point (Comp); |
b3f532ce AC |
3962 | end if; |
3963 | ||
22a83cea AC |
3964 | Next_Entity (Comp); |
3965 | end loop; | |
3966 | ||
3967 | -- Pop the scope if Rec scope has been pushed on the scope stack | |
3968 | -- during the delayed aspect analysis process. | |
3969 | ||
3970 | if Rec_Pushed then | |
3971 | if Has_Discriminants (Rec) then | |
3972 | Uninstall_Discriminants (Rec); | |
3973 | end if; | |
3974 | ||
3975 | Pop_Scope; | |
3976 | end if; | |
3977 | ||
3978 | -- Freeze components and embedded subtypes | |
3979 | ||
3980 | Comp := First_Entity (Rec); | |
3981 | Prev := Empty; | |
3982 | while Present (Comp) loop | |
515490e0 AC |
3983 | if Is_Aliased (Comp) then |
3984 | Aliased_Component := True; | |
3985 | end if; | |
22a83cea | 3986 | |
b3f532ce | 3987 | -- Handle the component and discriminant case |
70482933 | 3988 | |
d27f3ff4 | 3989 | if Ekind_In (Comp, E_Component, E_Discriminant) then |
70482933 RK |
3990 | declare |
3991 | CC : constant Node_Id := Component_Clause (Comp); | |
3992 | ||
3993 | begin | |
c6823a20 EB |
3994 | -- Freezing a record type freezes the type of each of its |
3995 | -- components. However, if the type of the component is | |
3996 | -- part of this record, we do not want or need a separate | |
3997 | -- Freeze_Node. Note that Is_Itype is wrong because that's | |
3998 | -- also set in private type cases. We also can't check for | |
3999 | -- the Scope being exactly Rec because of private types and | |
4000 | -- record extensions. | |
4001 | ||
4002 | if Is_Itype (Etype (Comp)) | |
4003 | and then Is_Record_Type (Underlying_Type | |
ef1c0511 | 4004 | (Scope (Etype (Comp)))) |
c6823a20 EB |
4005 | then |
4006 | Undelay_Type (Etype (Comp)); | |
4007 | end if; | |
4008 | ||
c159409f | 4009 | Freeze_And_Append (Etype (Comp), N, Result); |
c6823a20 | 4010 | |
63bb4268 AC |
4011 | -- Warn for pragma Pack overriding foreign convention |
4012 | ||
4013 | if Has_Foreign_Convention (Etype (Comp)) | |
4014 | and then Has_Pragma_Pack (Rec) | |
d12b19fa AC |
4015 | |
4016 | -- Don't warn for aliased components, since override | |
4017 | -- cannot happen in that case. | |
4018 | ||
4019 | and then not Is_Aliased (Comp) | |
63bb4268 AC |
4020 | then |
4021 | declare | |
4022 | CN : constant Name_Id := | |
4023 | Get_Convention_Name (Convention (Etype (Comp))); | |
4024 | PP : constant Node_Id := | |
4025 | Get_Pragma (Rec, Pragma_Pack); | |
4026 | begin | |
4027 | if Present (PP) then | |
4028 | Error_Msg_Name_1 := CN; | |
4029 | Error_Msg_Sloc := Sloc (Comp); | |
4030 | Error_Msg_N | |
4031 | ("pragma Pack affects convention % component#??", | |
4032 | PP); | |
4033 | Error_Msg_Name_1 := CN; | |
4034 | Error_Msg_NE | |
4035 | ("\component & may not have % compatible " | |
4036 | & "representation??", PP, Comp); | |
4037 | end if; | |
4038 | end; | |
4039 | end if; | |
4040 | ||
0da2c8ac AC |
4041 | -- Check for error of component clause given for variable |
4042 | -- sized type. We have to delay this test till this point, | |
4043 | -- since the component type has to be frozen for us to know | |
ef1c0511 | 4044 | -- if it is variable length. |
0da2c8ac | 4045 | |
70482933 RK |
4046 | if Present (CC) then |
4047 | Placed_Component := True; | |
4048 | ||
ef1c0511 AC |
4049 | -- We omit this test in a generic context, it will be |
4050 | -- applied at instantiation time. | |
4051 | ||
07fc65c4 GB |
4052 | if Inside_A_Generic then |
4053 | null; | |
4054 | ||
ef1c0511 AC |
4055 | -- Also omit this test in CodePeer mode, since we do not |
4056 | -- have sufficient info on size and rep clauses. | |
4057 | ||
24c34107 AC |
4058 | elsif CodePeer_Mode then |
4059 | null; | |
4060 | ||
71ff3d18 AC |
4061 | -- Omit check if component has a generic type. This can |
4062 | -- happen in an instantiation within a generic in ASIS | |
4063 | -- mode, where we force freeze actions without full | |
4064 | -- expansion. | |
4065 | ||
4066 | elsif Is_Generic_Type (Etype (Comp)) then | |
4067 | null; | |
4068 | ||
ef1c0511 AC |
4069 | -- Do the check |
4070 | ||
7d8b9c99 RD |
4071 | elsif not |
4072 | Size_Known_At_Compile_Time | |
4073 | (Underlying_Type (Etype (Comp))) | |
70482933 RK |
4074 | then |
4075 | Error_Msg_N | |
4076 | ("component clause not allowed for variable " & | |
4077 | "length component", CC); | |
4078 | end if; | |
4079 | ||
4080 | else | |
4081 | Unplaced_Component := True; | |
4082 | end if; | |
70482933 | 4083 | |
0da2c8ac | 4084 | -- Case of component requires byte alignment |
70482933 | 4085 | |
0da2c8ac | 4086 | if Must_Be_On_Byte_Boundary (Etype (Comp)) then |
70482933 | 4087 | |
0da2c8ac | 4088 | -- Set the enclosing record to also require byte align |
70482933 | 4089 | |
0da2c8ac | 4090 | Set_Must_Be_On_Byte_Boundary (Rec); |
70482933 | 4091 | |
7d8b9c99 RD |
4092 | -- Check for component clause that is inconsistent with |
4093 | -- the required byte boundary alignment. | |
70482933 | 4094 | |
0da2c8ac AC |
4095 | if Present (CC) |
4096 | and then Normalized_First_Bit (Comp) mod | |
4097 | System_Storage_Unit /= 0 | |
4098 | then | |
4099 | Error_Msg_N | |
4100 | ("component & must be byte aligned", | |
4101 | Component_Name (Component_Clause (Comp))); | |
4102 | end if; | |
4103 | end if; | |
0da2c8ac | 4104 | end; |
70482933 RK |
4105 | end if; |
4106 | ||
8a95f4e8 RD |
4107 | -- Gather data for possible Implicit_Packing later. Note that at |
4108 | -- this stage we might be dealing with a real component, or with | |
4109 | -- an implicit subtype declaration. | |
8dc10d38 | 4110 | |
f91caacb EB |
4111 | if Known_Static_RM_Size (Etype (Comp)) then |
4112 | Sized_Component_Total_RM_Size := | |
4113 | Sized_Component_Total_RM_Size + RM_Size (Etype (Comp)); | |
4114 | ||
820f1162 AC |
4115 | if Present (Underlying_Type (Etype (Comp))) |
4116 | and then Is_Elementary_Type (Underlying_Type (Etype (Comp))) | |
4117 | then | |
f91caacb EB |
4118 | Elem_Component_Total_Esize := |
4119 | Elem_Component_Total_Esize + Esize (Etype (Comp)); | |
4120 | else | |
4121 | All_Elem_Components := False; | |
4122 | ||
4123 | if RM_Size (Etype (Comp)) mod System_Storage_Unit /= 0 then | |
4124 | All_Storage_Unit_Components := False; | |
4125 | end if; | |
4126 | end if; | |
426d2717 | 4127 | else |
f91caacb | 4128 | All_Sized_Components := False; |
8dc10d38 AC |
4129 | end if; |
4130 | ||
c6823a20 EB |
4131 | -- If the component is an Itype with Delayed_Freeze and is either |
4132 | -- a record or array subtype and its base type has not yet been | |
545cb5be AC |
4133 | -- frozen, we must remove this from the entity list of this record |
4134 | -- and put it on the entity list of the scope of its base type. | |
4135 | -- Note that we know that this is not the type of a component | |
4136 | -- since we cleared Has_Delayed_Freeze for it in the previous | |
4137 | -- loop. Thus this must be the Designated_Type of an access type, | |
4138 | -- which is the type of a component. | |
c6823a20 EB |
4139 | |
4140 | if Is_Itype (Comp) | |
4141 | and then Is_Type (Scope (Comp)) | |
4142 | and then Is_Composite_Type (Comp) | |
4143 | and then Base_Type (Comp) /= Comp | |
4144 | and then Has_Delayed_Freeze (Comp) | |
4145 | and then not Is_Frozen (Base_Type (Comp)) | |
4146 | then | |
4147 | declare | |
4148 | Will_Be_Frozen : Boolean := False; | |
1b24ada5 | 4149 | S : Entity_Id; |
c6823a20 EB |
4150 | |
4151 | begin | |
e80f0cb0 RD |
4152 | -- We have a difficult case to handle here. Suppose Rec is |
4153 | -- subtype being defined in a subprogram that's created as | |
4154 | -- part of the freezing of Rec'Base. In that case, we know | |
4155 | -- that Comp'Base must have already been frozen by the time | |
4156 | -- we get to elaborate this because Gigi doesn't elaborate | |
4157 | -- any bodies until it has elaborated all of the declarative | |
fea9e956 ES |
4158 | -- part. But Is_Frozen will not be set at this point because |
4159 | -- we are processing code in lexical order. | |
4160 | ||
4161 | -- We detect this case by going up the Scope chain of Rec | |
4162 | -- and seeing if we have a subprogram scope before reaching | |
4163 | -- the top of the scope chain or that of Comp'Base. If we | |
4164 | -- do, then mark that Comp'Base will actually be frozen. If | |
4165 | -- so, we merely undelay it. | |
c6823a20 | 4166 | |
1b24ada5 | 4167 | S := Scope (Rec); |
c6823a20 EB |
4168 | while Present (S) loop |
4169 | if Is_Subprogram (S) then | |
4170 | Will_Be_Frozen := True; | |
4171 | exit; | |
4172 | elsif S = Scope (Base_Type (Comp)) then | |
4173 | exit; | |
4174 | end if; | |
4175 | ||
4176 | S := Scope (S); | |
4177 | end loop; | |
4178 | ||
4179 | if Will_Be_Frozen then | |
4180 | Undelay_Type (Comp); | |
0fea901b | 4181 | |
c6823a20 EB |
4182 | else |
4183 | if Present (Prev) then | |
4184 | Set_Next_Entity (Prev, Next_Entity (Comp)); | |
4185 | else | |
4186 | Set_First_Entity (Rec, Next_Entity (Comp)); | |
4187 | end if; | |
4188 | ||
4189 | -- Insert in entity list of scope of base type (which | |
4190 | -- must be an enclosing scope, because still unfrozen). | |
4191 | ||
4192 | Append_Entity (Comp, Scope (Base_Type (Comp))); | |
4193 | end if; | |
4194 | end; | |
4195 | ||
def46b54 RD |
4196 | -- If the component is an access type with an allocator as default |
4197 | -- value, the designated type will be frozen by the corresponding | |
4198 | -- expression in init_proc. In order to place the freeze node for | |
4199 | -- the designated type before that for the current record type, | |
4200 | -- freeze it now. | |
c6823a20 EB |
4201 | |
4202 | -- Same process if the component is an array of access types, | |
4203 | -- initialized with an aggregate. If the designated type is | |
def46b54 RD |
4204 | -- private, it cannot contain allocators, and it is premature |
4205 | -- to freeze the type, so we check for this as well. | |
c6823a20 EB |
4206 | |
4207 | elsif Is_Access_Type (Etype (Comp)) | |
4208 | and then Present (Parent (Comp)) | |
4209 | and then Present (Expression (Parent (Comp))) | |
c6823a20 EB |
4210 | then |
4211 | declare | |
e18d6a15 JM |
4212 | Alloc : constant Node_Id := |
4213 | Check_Allocator (Expression (Parent (Comp))); | |
c6823a20 EB |
4214 | |
4215 | begin | |
e18d6a15 | 4216 | if Present (Alloc) then |
19590d70 | 4217 | |
15918371 | 4218 | -- If component is pointer to a class-wide type, freeze |
e18d6a15 JM |
4219 | -- the specific type in the expression being allocated. |
4220 | -- The expression may be a subtype indication, in which | |
4221 | -- case freeze the subtype mark. | |
c6823a20 | 4222 | |
e18d6a15 JM |
4223 | if Is_Class_Wide_Type |
4224 | (Designated_Type (Etype (Comp))) | |
0f4cb75c | 4225 | then |
e18d6a15 JM |
4226 | if Is_Entity_Name (Expression (Alloc)) then |
4227 | Freeze_And_Append | |
c159409f | 4228 | (Entity (Expression (Alloc)), N, Result); |
0fea901b AC |
4229 | |
4230 | elsif Nkind (Expression (Alloc)) = N_Subtype_Indication | |
e18d6a15 JM |
4231 | then |
4232 | Freeze_And_Append | |
4233 | (Entity (Subtype_Mark (Expression (Alloc))), | |
c159409f | 4234 | N, Result); |
e18d6a15 | 4235 | end if; |
0f4cb75c | 4236 | |
e18d6a15 JM |
4237 | elsif Is_Itype (Designated_Type (Etype (Comp))) then |
4238 | Check_Itype (Etype (Comp)); | |
0f4cb75c | 4239 | |
e18d6a15 JM |
4240 | else |
4241 | Freeze_And_Append | |
c159409f | 4242 | (Designated_Type (Etype (Comp)), N, Result); |
e18d6a15 | 4243 | end if; |
c6823a20 EB |
4244 | end if; |
4245 | end; | |
4246 | ||
4247 | elsif Is_Access_Type (Etype (Comp)) | |
4248 | and then Is_Itype (Designated_Type (Etype (Comp))) | |
4249 | then | |
7d8b9c99 | 4250 | Check_Itype (Etype (Comp)); |
c6823a20 | 4251 | |
7b4ebba5 AC |
4252 | -- Freeze the designated type when initializing a component with |
4253 | -- an aggregate in case the aggregate contains allocators. | |
4254 | ||
4255 | -- type T is ...; | |
4256 | -- type T_Ptr is access all T; | |
4257 | -- type T_Array is array ... of T_Ptr; | |
4258 | ||
4259 | -- type Rec is record | |
4260 | -- Comp : T_Array := (others => ...); | |
4261 | -- end record; | |
4262 | ||
c6823a20 EB |
4263 | elsif Is_Array_Type (Etype (Comp)) |
4264 | and then Is_Access_Type (Component_Type (Etype (Comp))) | |
c6823a20 | 4265 | then |
7b4ebba5 AC |
4266 | declare |
4267 | Comp_Par : constant Node_Id := Parent (Comp); | |
4268 | Desig_Typ : constant Entity_Id := | |
4269 | Designated_Type | |
4270 | (Component_Type (Etype (Comp))); | |
4271 | ||
4272 | begin | |
4273 | -- The only case when this sort of freezing is not done is | |
4274 | -- when the designated type is class-wide and the root type | |
4275 | -- is the record owning the component. This scenario results | |
4276 | -- in a circularity because the class-wide type requires | |
4277 | -- primitives that have not been created yet as the root | |
4278 | -- type is in the process of being frozen. | |
4279 | ||
4280 | -- type Rec is tagged; | |
4281 | -- type Rec_Ptr is access all Rec'Class; | |
4282 | -- type Rec_Array is array ... of Rec_Ptr; | |
4283 | ||
4284 | -- type Rec is record | |
4285 | -- Comp : Rec_Array := (others => ...); | |
4286 | -- end record; | |
4287 | ||
4288 | if Is_Class_Wide_Type (Desig_Typ) | |
4289 | and then Root_Type (Desig_Typ) = Rec | |
4290 | then | |
4291 | null; | |
4292 | ||
4293 | elsif Is_Fully_Defined (Desig_Typ) | |
4294 | and then Present (Comp_Par) | |
4295 | and then Nkind (Comp_Par) = N_Component_Declaration | |
4296 | and then Present (Expression (Comp_Par)) | |
4297 | and then Nkind (Expression (Comp_Par)) = N_Aggregate | |
4298 | then | |
4299 | Freeze_And_Append (Desig_Typ, N, Result); | |
4300 | end if; | |
4301 | end; | |
c6823a20 EB |
4302 | end if; |
4303 | ||
4304 | Prev := Comp; | |
70482933 RK |
4305 | Next_Entity (Comp); |
4306 | end loop; | |
4307 | ||
dc9111cf EB |
4308 | SSO_ADC := |
4309 | Get_Attribute_Definition_Clause | |
4310 | (Rec, Attribute_Scalar_Storage_Order); | |
35fdafcd | 4311 | |
dc9111cf EB |
4312 | -- If the record type has Complex_Representation, then it is treated |
4313 | -- as a scalar in the back end so the storage order is irrelevant. | |
f91510fc | 4314 | |
dc9111cf EB |
4315 | if Has_Complex_Representation (Rec) then |
4316 | if Present (SSO_ADC) then | |
4317 | Error_Msg_N | |
4318 | ("??storage order has no effect with Complex_Representation", | |
4319 | SSO_ADC); | |
4320 | end if; | |
ee6208f2 | 4321 | |
dc9111cf EB |
4322 | else |
4323 | -- Deal with default setting of reverse storage order | |
35fdafcd | 4324 | |
dc9111cf | 4325 | Set_SSO_From_Default (Rec); |
ee6208f2 | 4326 | |
dc9111cf | 4327 | -- Check consistent attribute setting on component types |
220d1fd9 | 4328 | |
dc9111cf EB |
4329 | declare |
4330 | Comp_ADC_Present : Boolean; | |
4331 | begin | |
4332 | Comp := First_Component (Rec); | |
4333 | while Present (Comp) loop | |
4334 | Check_Component_Storage_Order | |
4335 | (Encl_Type => Rec, | |
4336 | Comp => Comp, | |
4337 | ADC => SSO_ADC, | |
4338 | Comp_ADC_Present => Comp_ADC_Present); | |
4339 | SSO_ADC_Component := SSO_ADC_Component or Comp_ADC_Present; | |
4340 | Next_Component (Comp); | |
4341 | end loop; | |
4342 | end; | |
d3b00ce3 | 4343 | |
dc9111cf | 4344 | -- Now deal with reverse storage order/bit order issues |
d3b00ce3 | 4345 | |
dc9111cf | 4346 | if Present (SSO_ADC) then |
d3b00ce3 | 4347 | |
dc9111cf EB |
4348 | -- Check compatibility of Scalar_Storage_Order with Bit_Order, |
4349 | -- if the former is specified. | |
d3b00ce3 | 4350 | |
dc9111cf | 4351 | if Reverse_Bit_Order (Rec) /= Reverse_Storage_Order (Rec) then |
d3b00ce3 | 4352 | |
dc9111cf EB |
4353 | -- Note: report error on Rec, not on SSO_ADC, as ADC may |
4354 | -- apply to some ancestor type. | |
50cd5b4d | 4355 | |
dc9111cf EB |
4356 | Error_Msg_Sloc := Sloc (SSO_ADC); |
4357 | Error_Msg_N | |
4358 | ("scalar storage order for& specified# inconsistent with " | |
4359 | & "bit order", Rec); | |
4360 | end if; | |
4361 | ||
4362 | -- Warn if there is a Scalar_Storage_Order attribute definition | |
4363 | -- clause but no component clause, no component that itself has | |
4364 | -- such an attribute definition, and no pragma Pack. | |
4365 | ||
4366 | if not (Placed_Component | |
4367 | or else | |
4368 | SSO_ADC_Component | |
4369 | or else | |
4370 | Is_Packed (Rec)) | |
4371 | then | |
4372 | Error_Msg_N | |
4373 | ("??scalar storage order specified but no component " | |
4374 | & "clause", SSO_ADC); | |
4375 | end if; | |
d3b00ce3 | 4376 | end if; |
8a7c0400 | 4377 | end if; |
75965852 | 4378 | |
ee6208f2 | 4379 | -- Deal with Bit_Order aspect |
fea9e956 | 4380 | |
2a290fec | 4381 | ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order); |
758ad973 AC |
4382 | |
4383 | if Present (ADC) and then Base_Type (Rec) = Rec then | |
ee6208f2 | 4384 | if not (Placed_Component |
d3e16619 AC |
4385 | or else Present (SSO_ADC) |
4386 | or else Is_Packed (Rec)) | |
ee6208f2 AC |
4387 | then |
4388 | -- Warn if clause has no effect when no component clause is | |
4389 | -- present, but suppress warning if the Bit_Order is required | |
4390 | -- due to the presence of a Scalar_Storage_Order attribute. | |
4391 | ||
15918371 AC |
4392 | Error_Msg_N |
4393 | ("??bit order specification has no effect", ADC); | |
fea9e956 | 4394 | Error_Msg_N |
685bc70f | 4395 | ("\??since no component clauses were specified", ADC); |
fea9e956 | 4396 | |
ee6208f2 | 4397 | -- Here is where we do the processing to adjust component clauses |
52b70b1b TQ |
4398 | -- for reversed bit order, when not using reverse SSO. If an error |
4399 | -- has been reported on Rec already (such as SSO incompatible with | |
4400 | -- bit order), don't bother adjusting as this may generate extra | |
4401 | -- noise. | |
70482933 | 4402 | |
758ad973 | 4403 | elsif Reverse_Bit_Order (Rec) |
2a290fec | 4404 | and then not Reverse_Storage_Order (Rec) |
52b70b1b | 4405 | and then not Error_Posted (Rec) |
758ad973 | 4406 | then |
fea9e956 | 4407 | Adjust_Record_For_Reverse_Bit_Order (Rec); |
702d139e | 4408 | |
758ad973 | 4409 | -- Case where we have both an explicit Bit_Order and the same |
702d139e TQ |
4410 | -- Scalar_Storage_Order: leave record untouched, the back-end |
4411 | -- will take care of required layout conversions. | |
4412 | ||
4413 | else | |
4414 | null; | |
4415 | ||
fea9e956 | 4416 | end if; |
70482933 RK |
4417 | end if; |
4418 | ||
8a95f4e8 RD |
4419 | -- Complete error checking on record representation clause (e.g. |
4420 | -- overlap of components). This is called after adjusting the | |
4421 | -- record for reverse bit order. | |
4422 | ||
4423 | declare | |
4424 | RRC : constant Node_Id := Get_Record_Representation_Clause (Rec); | |
4425 | begin | |
4426 | if Present (RRC) then | |
4427 | Check_Record_Representation_Clause (RRC); | |
4428 | end if; | |
4429 | end; | |
4430 | ||
1b24ada5 RD |
4431 | -- Set OK_To_Reorder_Components depending on debug flags |
4432 | ||
d347f572 | 4433 | if Is_Base_Type (Rec) and then Convention (Rec) = Convention_Ada then |
1b24ada5 | 4434 | if (Has_Discriminants (Rec) and then Debug_Flag_Dot_V) |
d3b00ce3 AC |
4435 | or else |
4436 | (not Has_Discriminants (Rec) and then Debug_Flag_Dot_R) | |
1b24ada5 RD |
4437 | then |
4438 | Set_OK_To_Reorder_Components (Rec); | |
4439 | end if; | |
4440 | end if; | |
4441 | ||
ee094616 RD |
4442 | -- Check for useless pragma Pack when all components placed. We only |
4443 | -- do this check for record types, not subtypes, since a subtype may | |
4444 | -- have all its components placed, and it still makes perfectly good | |
1b24ada5 RD |
4445 | -- sense to pack other subtypes or the parent type. We do not give |
4446 | -- this warning if Optimize_Alignment is set to Space, since the | |
4447 | -- pragma Pack does have an effect in this case (it always resets | |
4448 | -- the alignment to one). | |
70482933 | 4449 | |
ee094616 RD |
4450 | if Ekind (Rec) = E_Record_Type |
4451 | and then Is_Packed (Rec) | |
70482933 | 4452 | and then not Unplaced_Component |
1b24ada5 | 4453 | and then Optimize_Alignment /= 'S' |
70482933 | 4454 | then |
def46b54 RD |
4455 | -- Reset packed status. Probably not necessary, but we do it so |
4456 | -- that there is no chance of the back end doing something strange | |
4457 | -- with this redundant indication of packing. | |
ee094616 | 4458 | |
70482933 | 4459 | Set_Is_Packed (Rec, False); |
ee094616 RD |
4460 | |
4461 | -- Give warning if redundant constructs warnings on | |
4462 | ||
4463 | if Warn_On_Redundant_Constructs then | |
ed2233dc | 4464 | Error_Msg_N -- CODEFIX |
685bc70f | 4465 | ("??pragma Pack has no effect, no unplaced components", |
ee094616 RD |
4466 | Get_Rep_Pragma (Rec, Name_Pack)); |
4467 | end if; | |
70482933 RK |
4468 | end if; |
4469 | ||
ee094616 RD |
4470 | -- If this is the record corresponding to a remote type, freeze the |
4471 | -- remote type here since that is what we are semantically freezing. | |
4472 | -- This prevents the freeze node for that type in an inner scope. | |
70482933 | 4473 | |
8dc10d38 | 4474 | if Ekind (Rec) = E_Record_Type then |
70482933 | 4475 | if Present (Corresponding_Remote_Type (Rec)) then |
c159409f | 4476 | Freeze_And_Append (Corresponding_Remote_Type (Rec), N, Result); |
70482933 RK |
4477 | end if; |
4478 | ||
3ddfabe3 AC |
4479 | -- Check for controlled components, unchecked unions, and type |
4480 | -- invariants. | |
15918371 | 4481 | |
70482933 | 4482 | Comp := First_Component (Rec); |
70482933 | 4483 | while Present (Comp) loop |
80fa4617 EB |
4484 | |
4485 | -- Do not set Has_Controlled_Component on a class-wide | |
4486 | -- equivalent type. See Make_CW_Equivalent_Type. | |
4487 | ||
4488 | if not Is_Class_Wide_Equivalent_Type (Rec) | |
15918371 AC |
4489 | and then |
4490 | (Has_Controlled_Component (Etype (Comp)) | |
4491 | or else | |
4492 | (Chars (Comp) /= Name_uParent | |
c8593453 | 4493 | and then Is_Controlled_Active (Etype (Comp))) |
15918371 AC |
4494 | or else |
4495 | (Is_Protected_Type (Etype (Comp)) | |
4496 | and then | |
4497 | Present (Corresponding_Record_Type (Etype (Comp))) | |
4498 | and then | |
4499 | Has_Controlled_Component | |
4500 | (Corresponding_Record_Type (Etype (Comp))))) | |
70482933 RK |
4501 | then |
4502 | Set_Has_Controlled_Component (Rec); | |
70482933 RK |
4503 | end if; |
4504 | ||
4505 | if Has_Unchecked_Union (Etype (Comp)) then | |
4506 | Set_Has_Unchecked_Union (Rec); | |
4507 | end if; | |
4508 | ||
3ddfabe3 AC |
4509 | -- The record type requires its own invariant procedure in |
4510 | -- order to verify the invariant of each individual component. | |
4511 | -- Do not consider internal components such as _parent because | |
4512 | -- parent class-wide invariants are always inherited. | |
104c99ef CD |
4513 | -- In GNATprove mode, the component invariants are checked by |
4514 | -- other means. They should not be added to the record type | |
4515 | -- invariant procedure, so that the procedure can be used to | |
4516 | -- check the recordy type invariants if any. | |
3ddfabe3 AC |
4517 | |
4518 | if Comes_From_Source (Comp) | |
0289a8d7 | 4519 | and then Has_Invariants (Etype (Comp)) |
104c99ef | 4520 | and then not GNATprove_Mode |
3ddfabe3 AC |
4521 | then |
4522 | Set_Has_Own_Invariants (Rec); | |
4523 | end if; | |
4524 | ||
e1308fa8 AC |
4525 | -- Scan component declaration for likely misuses of current |
4526 | -- instance, either in a constraint or a default expression. | |
70482933 | 4527 | |
e1308fa8 | 4528 | if Has_Per_Object_Constraint (Comp) then |
70482933 RK |
4529 | Check_Current_Instance (Parent (Comp)); |
4530 | end if; | |
4531 | ||
4532 | Next_Component (Comp); | |
4533 | end loop; | |
4534 | end if; | |
4535 | ||
15918371 AC |
4536 | -- Enforce the restriction that access attributes with a current |
4537 | -- instance prefix can only apply to limited types. This comment | |
4538 | -- is floating here, but does not seem to belong here??? | |
4539 | ||
4540 | -- Set component alignment if not otherwise already set | |
4541 | ||
70482933 RK |
4542 | Set_Component_Alignment_If_Not_Set (Rec); |
4543 | ||
ee094616 RD |
4544 | -- For first subtypes, check if there are any fixed-point fields with |
4545 | -- component clauses, where we must check the size. This is not done | |
15918371 | 4546 | -- till the freeze point since for fixed-point types, we do not know |
ee094616 | 4547 | -- the size until the type is frozen. Similar processing applies to |
607114db | 4548 | -- bit-packed arrays. |
70482933 RK |
4549 | |
4550 | if Is_First_Subtype (Rec) then | |
4551 | Comp := First_Component (Rec); | |
70482933 RK |
4552 | while Present (Comp) loop |
4553 | if Present (Component_Clause (Comp)) | |
d05ef0ab | 4554 | and then (Is_Fixed_Point_Type (Etype (Comp)) |
d3e16619 | 4555 | or else Is_Bit_Packed_Array (Etype (Comp))) |
70482933 RK |
4556 | then |
4557 | Check_Size | |
d05ef0ab | 4558 | (Component_Name (Component_Clause (Comp)), |
70482933 RK |
4559 | Etype (Comp), |
4560 | Esize (Comp), | |
4561 | Junk); | |
4562 | end if; | |
4563 | ||
4564 | Next_Component (Comp); | |
4565 | end loop; | |
4566 | end if; | |
7d8b9c99 | 4567 | |
ce14c577 | 4568 | -- See if Size is too small as is (and implicit packing might help) |
8dc10d38 | 4569 | |
426d2717 | 4570 | if not Is_Packed (Rec) |
ce14c577 AC |
4571 | |
4572 | -- No implicit packing if even one component is explicitly placed | |
4573 | ||
426d2717 | 4574 | and then not Placed_Component |
ce14c577 | 4575 | |
515490e0 AC |
4576 | -- Or even one component is aliased |
4577 | ||
4578 | and then not Aliased_Component | |
4579 | ||
f91caacb | 4580 | -- Must have size clause and all sized components |
ce14c577 | 4581 | |
8dc10d38 | 4582 | and then Has_Size_Clause (Rec) |
f91caacb | 4583 | and then All_Sized_Components |
ce14c577 AC |
4584 | |
4585 | -- Do not try implicit packing on records with discriminants, too | |
4586 | -- complicated, especially in the variant record case. | |
4587 | ||
8dc10d38 | 4588 | and then not Has_Discriminants (Rec) |
ce14c577 | 4589 | |
f91caacb EB |
4590 | -- We want to implicitly pack if the specified size of the record |
4591 | -- is less than the sum of the object sizes (no point in packing | |
d4b56371 | 4592 | -- if this is not the case), if we can compute it, i.e. if we have |
f91caacb | 4593 | -- only elementary components. Otherwise, we have at least one |
d4b56371 | 4594 | -- composite component and we want to implicitly pack only if bit |
f91caacb EB |
4595 | -- packing is required for it, as we are sure in this case that |
4596 | -- the back end cannot do the expected layout without packing. | |
ce14c577 | 4597 | |
c70cf4f8 AC |
4598 | and then |
4599 | ((All_Elem_Components | |
4600 | and then RM_Size (Rec) < Elem_Component_Total_Esize) | |
4601 | or else | |
4602 | (not All_Elem_Components | |
4603 | and then not All_Storage_Unit_Components)) | |
ce14c577 AC |
4604 | |
4605 | -- And the total RM size cannot be greater than the specified size | |
a90bd866 | 4606 | -- since otherwise packing will not get us where we have to be. |
ce14c577 | 4607 | |
f91caacb | 4608 | and then RM_Size (Rec) >= Sized_Component_Total_RM_Size |
ce14c577 | 4609 | |
06b599fd | 4610 | -- Never do implicit packing in CodePeer or SPARK modes since |
59e6b23c | 4611 | -- we don't do any packing in these modes, since this generates |
25ebc085 AC |
4612 | -- over-complex code that confuses static analysis, and in |
4613 | -- general, neither CodePeer not GNATprove care about the | |
4614 | -- internal representation of objects. | |
ce14c577 | 4615 | |
f5da7a97 | 4616 | and then not (CodePeer_Mode or GNATprove_Mode) |
8dc10d38 | 4617 | then |
426d2717 AC |
4618 | -- If implicit packing enabled, do it |
4619 | ||
4620 | if Implicit_Packing then | |
4621 | Set_Is_Packed (Rec); | |
4622 | ||
4623 | -- Otherwise flag the size clause | |
4624 | ||
4625 | else | |
4626 | declare | |
4627 | Sz : constant Node_Id := Size_Clause (Rec); | |
4628 | begin | |
ed2233dc | 4629 | Error_Msg_NE -- CODEFIX |
426d2717 | 4630 | ("size given for& too small", Sz, Rec); |
ed2233dc | 4631 | Error_Msg_N -- CODEFIX |
426d2717 AC |
4632 | ("\use explicit pragma Pack " |
4633 | & "or use pragma Implicit_Packing", Sz); | |
4634 | end; | |
4635 | end if; | |
8dc10d38 | 4636 | end if; |
15918371 | 4637 | |
f3bf0d9a | 4638 | -- The following checks are relevant only when SPARK_Mode is on as |
f9e333ab AC |
4639 | -- they are not standard Ada legality rules. |
4640 | ||
4641 | if SPARK_Mode = On then | |
f9e333ab | 4642 | |
7738270b AC |
4643 | -- A discriminated type cannot be effectively volatile |
4644 | -- (SPARK RM 7.1.3(5)). | |
f9e333ab | 4645 | |
7738270b AC |
4646 | if Is_Effectively_Volatile (Rec) then |
4647 | if Has_Discriminants (Rec) then | |
f9e333ab | 4648 | Error_Msg_N ("discriminated type & cannot be volatile", Rec); |
f9e333ab AC |
4649 | end if; |
4650 | ||
d780e54f | 4651 | -- A non-effectively volatile record type cannot contain |
e4b1cd76 | 4652 | -- effectively volatile components (SPARK RM 7.1.3(6)). |
f9e333ab AC |
4653 | |
4654 | else | |
4655 | Comp := First_Component (Rec); | |
4656 | while Present (Comp) loop | |
4657 | if Comes_From_Source (Comp) | |
d780e54f | 4658 | and then Is_Effectively_Volatile (Etype (Comp)) |
f9e333ab AC |
4659 | then |
4660 | Error_Msg_Name_1 := Chars (Rec); | |
4661 | Error_Msg_N | |
4662 | ("component & of non-volatile type % cannot be " | |
4663 | & "volatile", Comp); | |
4664 | end if; | |
4665 | ||
4666 | Next_Component (Comp); | |
4667 | end loop; | |
4668 | end if; | |
75b87c16 AC |
4669 | |
4670 | -- A type which does not yield a synchronized object cannot have | |
4671 | -- a component that yields a synchronized object (SPARK RM 9.5). | |
4672 | ||
4673 | if not Yields_Synchronized_Object (Rec) then | |
4674 | Comp := First_Component (Rec); | |
4675 | while Present (Comp) loop | |
4676 | if Comes_From_Source (Comp) | |
4677 | and then Yields_Synchronized_Object (Etype (Comp)) | |
4678 | then | |
4679 | Error_Msg_Name_1 := Chars (Rec); | |
4680 | Error_Msg_N | |
4681 | ("component & of non-synchronized type % cannot be " | |
4682 | & "synchronized", Comp); | |
4683 | end if; | |
4684 | ||
4685 | Next_Component (Comp); | |
4686 | end loop; | |
4687 | end if; | |
58996b09 HK |
4688 | |
4689 | -- A Ghost type cannot have a component of protected or task type | |
4690 | -- (SPARK RM 6.9(19)). | |
4691 | ||
4692 | if Is_Ghost_Entity (Rec) then | |
4693 | Comp := First_Component (Rec); | |
4694 | while Present (Comp) loop | |
4695 | if Comes_From_Source (Comp) | |
4696 | and then Is_Concurrent_Type (Etype (Comp)) | |
4697 | then | |
4698 | Error_Msg_Name_1 := Chars (Rec); | |
4699 | Error_Msg_N | |
4700 | ("component & of ghost type % cannot be concurrent", | |
4701 | Comp); | |
4702 | end if; | |
4703 | ||
4704 | Next_Component (Comp); | |
4705 | end loop; | |
4706 | end if; | |
f9e333ab AC |
4707 | end if; |
4708 | ||
cad97339 | 4709 | -- Make sure that if we have an iterator aspect, then we have |
7166d535 AC |
4710 | -- either Constant_Indexing or Variable_Indexing. |
4711 | ||
4f2cae4a ES |
4712 | declare |
4713 | Iterator_Aspect : Node_Id; | |
4714 | ||
4715 | begin | |
4716 | Iterator_Aspect := Find_Aspect (Rec, Aspect_Iterator_Element); | |
4717 | ||
4718 | if No (Iterator_Aspect) then | |
4719 | Iterator_Aspect := Find_Aspect (Rec, Aspect_Default_Iterator); | |
4720 | end if; | |
4721 | ||
4722 | if Present (Iterator_Aspect) then | |
4723 | if Has_Aspect (Rec, Aspect_Constant_Indexing) | |
cad97339 | 4724 | or else |
4f2cae4a ES |
4725 | Has_Aspect (Rec, Aspect_Variable_Indexing) |
4726 | then | |
4727 | null; | |
4728 | else | |
4729 | Error_Msg_N | |
4730 | ("Iterator_Element requires indexing aspect", | |
cad97339 | 4731 | Iterator_Aspect); |
4f2cae4a | 4732 | end if; |
7166d535 | 4733 | end if; |
4f2cae4a | 4734 | end; |
7166d535 | 4735 | |
15918371 AC |
4736 | -- All done if not a full record definition |
4737 | ||
4738 | if Ekind (Rec) /= E_Record_Type then | |
4739 | return; | |
4740 | end if; | |
4741 | ||
c76bf0bf AC |
4742 | -- Finally we need to check the variant part to make sure that |
4743 | -- all types within choices are properly frozen as part of the | |
4744 | -- freezing of the record type. | |
15918371 AC |
4745 | |
4746 | Check_Variant_Part : declare | |
4747 | D : constant Node_Id := Declaration_Node (Rec); | |
4748 | T : Node_Id; | |
4749 | C : Node_Id; | |
15918371 AC |
4750 | |
4751 | begin | |
4752 | -- Find component list | |
4753 | ||
4754 | C := Empty; | |
4755 | ||
4756 | if Nkind (D) = N_Full_Type_Declaration then | |
4757 | T := Type_Definition (D); | |
4758 | ||
4759 | if Nkind (T) = N_Record_Definition then | |
4760 | C := Component_List (T); | |
4761 | ||
4762 | elsif Nkind (T) = N_Derived_Type_Definition | |
4763 | and then Present (Record_Extension_Part (T)) | |
4764 | then | |
4765 | C := Component_List (Record_Extension_Part (T)); | |
4766 | end if; | |
4767 | end if; | |
4768 | ||
e7f23f06 | 4769 | -- Case of variant part present |
15918371 AC |
4770 | |
4771 | if Present (C) and then Present (Variant_Part (C)) then | |
c76bf0bf AC |
4772 | Freeze_Choices_In_Variant_Part (Variant_Part (C)); |
4773 | end if; | |
4530b919 | 4774 | |
c76bf0bf AC |
4775 | -- Note: we used to call Check_Choices here, but it is too early, |
4776 | -- since predicated subtypes are frozen here, but their freezing | |
4777 | -- actions are in Analyze_Freeze_Entity, which has not been called | |
4778 | -- yet for entities frozen within this procedure, so we moved that | |
4779 | -- call to the Analyze_Freeze_Entity for the record type. | |
4530b919 | 4780 | |
15918371 | 4781 | end Check_Variant_Part; |
527f5eb6 AC |
4782 | |
4783 | -- Check that all the primitives of an interface type are abstract | |
4784 | -- or null procedures. | |
4785 | ||
4786 | if Is_Interface (Rec) | |
4787 | and then not Error_Posted (Parent (Rec)) | |
4788 | then | |
4789 | declare | |
4790 | Elmt : Elmt_Id; | |
4791 | Subp : Entity_Id; | |
4792 | ||
4793 | begin | |
4794 | Elmt := First_Elmt (Primitive_Operations (Rec)); | |
4795 | while Present (Elmt) loop | |
4796 | Subp := Node (Elmt); | |
4797 | ||
4798 | if not Is_Abstract_Subprogram (Subp) | |
4799 | ||
4800 | -- Avoid reporting the error on inherited primitives | |
4801 | ||
4802 | and then Comes_From_Source (Subp) | |
4803 | then | |
4804 | Error_Msg_Name_1 := Chars (Subp); | |
4805 | ||
4806 | if Ekind (Subp) = E_Procedure then | |
4807 | if not Null_Present (Parent (Subp)) then | |
4808 | Error_Msg_N | |
4809 | ("interface procedure % must be abstract or null", | |
4810 | Parent (Subp)); | |
4811 | end if; | |
4812 | else | |
4813 | Error_Msg_N | |
4814 | ("interface function % must be abstract", | |
4815 | Parent (Subp)); | |
4816 | end if; | |
4817 | end if; | |
4818 | ||
4819 | Next_Elmt (Elmt); | |
4820 | end loop; | |
4821 | end; | |
4822 | end if; | |
017d237e ES |
4823 | |
4824 | -- For a derived tagged type, check whether inherited primitives | |
8c519039 | 4825 | -- might require a wrapper to handle class-wide conditions. |
017d237e ES |
4826 | |
4827 | if Is_Tagged_Type (Rec) and then Is_Derived_Type (Rec) then | |
4828 | Check_Inherited_Conditions (Rec); | |
4829 | end if; | |
70482933 RK |
4830 | end Freeze_Record_Type; |
4831 | ||
e8cddc3b AC |
4832 | ------------------------------- |
4833 | -- Has_Boolean_Aspect_Import -- | |
4834 | ------------------------------- | |
4835 | ||
4836 | function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean is | |
4837 | Decl : constant Node_Id := Declaration_Node (E); | |
4838 | Asp : Node_Id; | |
4839 | Expr : Node_Id; | |
4840 | ||
4841 | begin | |
4842 | if Has_Aspects (Decl) then | |
4843 | Asp := First (Aspect_Specifications (Decl)); | |
4844 | while Present (Asp) loop | |
4845 | Expr := Expression (Asp); | |
4846 | ||
4847 | -- The value of aspect Import is True when the expression is | |
4848 | -- either missing or it is explicitly set to True. | |
4849 | ||
4850 | if Get_Aspect_Id (Asp) = Aspect_Import | |
4851 | and then (No (Expr) | |
4852 | or else (Compile_Time_Known_Value (Expr) | |
4853 | and then Is_True (Expr_Value (Expr)))) | |
4854 | then | |
4855 | return True; | |
4856 | end if; | |
4857 | ||
4858 | Next (Asp); | |
4859 | end loop; | |
4860 | end if; | |
4861 | ||
4862 | return False; | |
4863 | end Has_Boolean_Aspect_Import; | |
4864 | ||
ce06d641 AC |
4865 | ------------------------- |
4866 | -- Inherit_Freeze_Node -- | |
4867 | ------------------------- | |
4868 | ||
4869 | procedure Inherit_Freeze_Node | |
4870 | (Fnod : Node_Id; | |
4871 | Typ : Entity_Id) | |
4872 | is | |
4873 | Typ_Fnod : constant Node_Id := Freeze_Node (Typ); | |
4874 | ||
4875 | begin | |
4876 | Set_Freeze_Node (Typ, Fnod); | |
4877 | Set_Entity (Fnod, Typ); | |
4878 | ||
4879 | -- The input type had an existing node. Propagate relevant attributes | |
4880 | -- from the old freeze node to the inherited freeze node. | |
4881 | ||
4882 | -- ??? if both freeze nodes have attributes, would they differ? | |
4883 | ||
4884 | if Present (Typ_Fnod) then | |
4885 | ||
4886 | -- Attribute Access_Types_To_Process | |
4887 | ||
4888 | if Present (Access_Types_To_Process (Typ_Fnod)) | |
4889 | and then No (Access_Types_To_Process (Fnod)) | |
4890 | then | |
4891 | Set_Access_Types_To_Process (Fnod, | |
4892 | Access_Types_To_Process (Typ_Fnod)); | |
4893 | end if; | |
4894 | ||
4895 | -- Attribute Actions | |
4896 | ||
4897 | if Present (Actions (Typ_Fnod)) and then No (Actions (Fnod)) then | |
4898 | Set_Actions (Fnod, Actions (Typ_Fnod)); | |
4899 | end if; | |
4900 | ||
4901 | -- Attribute First_Subtype_Link | |
4902 | ||
4903 | if Present (First_Subtype_Link (Typ_Fnod)) | |
4904 | and then No (First_Subtype_Link (Fnod)) | |
4905 | then | |
4906 | Set_First_Subtype_Link (Fnod, First_Subtype_Link (Typ_Fnod)); | |
4907 | end if; | |
4908 | ||
4909 | -- Attribute TSS_Elist | |
4910 | ||
4911 | if Present (TSS_Elist (Typ_Fnod)) | |
4912 | and then No (TSS_Elist (Fnod)) | |
4913 | then | |
4914 | Set_TSS_Elist (Fnod, TSS_Elist (Typ_Fnod)); | |
4915 | end if; | |
4916 | end if; | |
4917 | end Inherit_Freeze_Node; | |
4918 | ||
32bba3c9 AC |
4919 | ------------------------------ |
4920 | -- Wrap_Imported_Subprogram -- | |
4921 | ------------------------------ | |
4922 | ||
4923 | -- The issue here is that our normal approach of checking preconditions | |
4924 | -- and postconditions does not work for imported procedures, since we | |
4925 | -- are not generating code for the body. To get around this we create | |
4926 | -- a wrapper, as shown by the following example: | |
4927 | ||
4928 | -- procedure K (A : Integer); | |
4929 | -- pragma Import (C, K); | |
4930 | ||
4931 | -- The spec is rewritten by removing the effects of pragma Import, but | |
4932 | -- leaving the convention unchanged, as though the source had said: | |
4933 | ||
4934 | -- procedure K (A : Integer); | |
4935 | -- pragma Convention (C, K); | |
4936 | ||
4937 | -- and we create a body, added to the entity K freeze actions, which | |
4938 | -- looks like: | |
4939 | ||
4940 | -- procedure K (A : Integer) is | |
4941 | -- procedure K (A : Integer); | |
4942 | -- pragma Import (C, K); | |
4943 | -- begin | |
4944 | -- K (A); | |
4945 | -- end K; | |
4946 | ||
4947 | -- Now the contract applies in the normal way to the outer procedure, | |
4948 | -- and the inner procedure has no contracts, so there is no problem | |
4949 | -- in just calling it to get the original effect. | |
4950 | ||
4951 | -- In the case of a function, we create an appropriate return statement | |
4952 | -- for the subprogram body that calls the inner procedure. | |
4953 | ||
4954 | procedure Wrap_Imported_Subprogram (E : Entity_Id) is | |
2e885a6f AC |
4955 | function Copy_Import_Pragma return Node_Id; |
4956 | -- Obtain a copy of the Import_Pragma which belongs to subprogram E | |
4957 | ||
4958 | ------------------------ | |
4959 | -- Copy_Import_Pragma -- | |
4960 | ------------------------ | |
4961 | ||
4962 | function Copy_Import_Pragma return Node_Id is | |
4963 | ||
4964 | -- The subprogram should have an import pragma, otherwise it does | |
4965 | -- need a wrapper. | |
4966 | ||
4967 | Prag : constant Node_Id := Import_Pragma (E); | |
4968 | pragma Assert (Present (Prag)); | |
4969 | ||
4970 | -- Save all semantic fields of the pragma | |
4971 | ||
4972 | Save_Asp : constant Node_Id := Corresponding_Aspect (Prag); | |
4973 | Save_From : constant Boolean := From_Aspect_Specification (Prag); | |
4974 | Save_Prag : constant Node_Id := Next_Pragma (Prag); | |
4975 | Save_Rep : constant Node_Id := Next_Rep_Item (Prag); | |
4976 | ||
4977 | Result : Node_Id; | |
4978 | ||
4979 | begin | |
4980 | -- Reset all semantic fields. This avoids a potential infinite | |
4981 | -- loop when the pragma comes from an aspect as the duplication | |
4982 | -- will copy the aspect, then copy the corresponding pragma and | |
4983 | -- so on. | |
4984 | ||
4985 | Set_Corresponding_Aspect (Prag, Empty); | |
4986 | Set_From_Aspect_Specification (Prag, False); | |
4987 | Set_Next_Pragma (Prag, Empty); | |
4988 | Set_Next_Rep_Item (Prag, Empty); | |
4989 | ||
4990 | Result := Copy_Separate_Tree (Prag); | |
4991 | ||
4992 | -- Restore the original semantic fields | |
4993 | ||
4994 | Set_Corresponding_Aspect (Prag, Save_Asp); | |
4995 | Set_From_Aspect_Specification (Prag, Save_From); | |
4996 | Set_Next_Pragma (Prag, Save_Prag); | |
4997 | Set_Next_Rep_Item (Prag, Save_Rep); | |
4998 | ||
4999 | return Result; | |
5000 | end Copy_Import_Pragma; | |
5001 | ||
5002 | -- Local variables | |
5003 | ||
32bba3c9 | 5004 | Loc : constant Source_Ptr := Sloc (E); |
f1a3590e | 5005 | CE : constant Name_Id := Chars (E); |
32bba3c9 AC |
5006 | Bod : Node_Id; |
5007 | Forml : Entity_Id; | |
2e885a6f AC |
5008 | Parms : List_Id; |
5009 | Prag : Node_Id; | |
5010 | Spec : Node_Id; | |
5011 | Stmt : Node_Id; | |
5012 | ||
5013 | -- Start of processing for Wrap_Imported_Subprogram | |
32bba3c9 AC |
5014 | |
5015 | begin | |
5016 | -- Nothing to do if not imported | |
5017 | ||
5018 | if not Is_Imported (E) then | |
5019 | return; | |
32bba3c9 AC |
5020 | |
5021 | -- Test enabling conditions for wrapping | |
5022 | ||
f1a3590e | 5023 | elsif Is_Subprogram (E) |
32bba3c9 AC |
5024 | and then Present (Contract (E)) |
5025 | and then Present (Pre_Post_Conditions (Contract (E))) | |
5026 | and then not GNATprove_Mode | |
5027 | then | |
f1a3590e | 5028 | -- Here we do the wrap |
32bba3c9 | 5029 | |
f1a3590e AC |
5030 | -- Note on calls to Copy_Separate_Tree. The trees we are copying |
5031 | -- here are fully analyzed, but we definitely want fully syntactic | |
5032 | -- unanalyzed trees in the body we construct, so that the analysis | |
f34b5d88 RD |
5033 | -- generates the right visibility, and that is exactly what the |
5034 | -- calls to Copy_Separate_Tree give us. | |
f1a3590e | 5035 | |
2e885a6f | 5036 | Prag := Copy_Import_Pragma; |
32bba3c9 AC |
5037 | |
5038 | -- Fix up spec to be not imported any more | |
5039 | ||
32bba3c9 AC |
5040 | Set_Has_Completion (E, False); |
5041 | Set_Import_Pragma (E, Empty); | |
2e885a6f AC |
5042 | Set_Interface_Name (E, Empty); |
5043 | Set_Is_Imported (E, False); | |
32bba3c9 AC |
5044 | |
5045 | -- Grab the subprogram declaration and specification | |
5046 | ||
5047 | Spec := Declaration_Node (E); | |
5048 | ||
5049 | -- Build parameter list that we need | |
5050 | ||
5051 | Parms := New_List; | |
5052 | Forml := First_Formal (E); | |
5053 | while Present (Forml) loop | |
f1a3590e | 5054 | Append_To (Parms, Make_Identifier (Loc, Chars (Forml))); |
32bba3c9 AC |
5055 | Next_Formal (Forml); |
5056 | end loop; | |
5057 | ||
5058 | -- Build the call | |
5059 | ||
5060 | if Ekind_In (E, E_Function, E_Generic_Function) then | |
5061 | Stmt := | |
5062 | Make_Simple_Return_Statement (Loc, | |
5063 | Expression => | |
5064 | Make_Function_Call (Loc, | |
f1a3590e | 5065 | Name => Make_Identifier (Loc, CE), |
32bba3c9 AC |
5066 | Parameter_Associations => Parms)); |
5067 | ||
5068 | else | |
5069 | Stmt := | |
5070 | Make_Procedure_Call_Statement (Loc, | |
f1a3590e | 5071 | Name => Make_Identifier (Loc, CE), |
32bba3c9 AC |
5072 | Parameter_Associations => Parms); |
5073 | end if; | |
5074 | ||
5075 | -- Now build the body | |
5076 | ||
5077 | Bod := | |
5078 | Make_Subprogram_Body (Loc, | |
f1a3590e | 5079 | Specification => |
158d55fa | 5080 | Copy_Separate_Tree (Spec), |
32bba3c9 AC |
5081 | Declarations => New_List ( |
5082 | Make_Subprogram_Declaration (Loc, | |
2e885a6f AC |
5083 | Specification => Copy_Separate_Tree (Spec)), |
5084 | Prag), | |
32bba3c9 AC |
5085 | Handled_Statement_Sequence => |
5086 | Make_Handled_Sequence_Of_Statements (Loc, | |
2e885a6f AC |
5087 | Statements => New_List (Stmt), |
5088 | End_Label => Make_Identifier (Loc, CE))); | |
32bba3c9 AC |
5089 | |
5090 | -- Append the body to freeze result | |
5091 | ||
5092 | Add_To_Result (Bod); | |
5093 | return; | |
32bba3c9 AC |
5094 | |
5095 | -- Case of imported subprogram that does not get wrapped | |
5096 | ||
f1a3590e AC |
5097 | else |
5098 | -- Set Is_Public. All imported entities need an external symbol | |
5099 | -- created for them since they are always referenced from another | |
5100 | -- object file. Note this used to be set when we set Is_Imported | |
5101 | -- back in Sem_Prag, but now we delay it to this point, since we | |
5102 | -- don't want to set this flag if we wrap an imported subprogram. | |
32bba3c9 | 5103 | |
f1a3590e AC |
5104 | Set_Is_Public (E); |
5105 | end if; | |
32bba3c9 AC |
5106 | end Wrap_Imported_Subprogram; |
5107 | ||
1af4455a HK |
5108 | -- Local variables |
5109 | ||
f9a8f910 HK |
5110 | Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
5111 | -- Save the Ghost mode to restore on exit | |
1af4455a | 5112 | |
70482933 RK |
5113 | -- Start of processing for Freeze_Entity |
5114 | ||
5115 | begin | |
1af4455a HK |
5116 | -- The entity being frozen may be subject to pragma Ghost. Set the mode |
5117 | -- now to ensure that any nodes generated during freezing are properly | |
5118 | -- flagged as Ghost. | |
8636f52f | 5119 | |
f9a8f910 | 5120 | Set_Ghost_Mode (E); |
8636f52f | 5121 | |
c6823a20 EB |
5122 | -- We are going to test for various reasons why this entity need not be |
5123 | -- frozen here, but in the case of an Itype that's defined within a | |
5124 | -- record, that test actually applies to the record. | |
5125 | ||
5126 | if Is_Itype (E) and then Is_Record_Type (Scope (E)) then | |
5127 | Test_E := Scope (E); | |
5128 | elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E))) | |
5129 | and then Is_Record_Type (Underlying_Type (Scope (E))) | |
5130 | then | |
5131 | Test_E := Underlying_Type (Scope (E)); | |
5132 | end if; | |
5133 | ||
fbf5a39b | 5134 | -- Do not freeze if already frozen since we only need one freeze node |
70482933 RK |
5135 | |
5136 | if Is_Frozen (E) then | |
d65a80fd HK |
5137 | Result := No_List; |
5138 | goto Leave; | |
70482933 | 5139 | |
136236bd JM |
5140 | elsif Ekind (E) = E_Generic_Package then |
5141 | Result := Freeze_Generic_Entities (E); | |
d65a80fd | 5142 | goto Leave; |
136236bd | 5143 | |
c6823a20 EB |
5144 | -- It is improper to freeze an external entity within a generic because |
5145 | -- its freeze node will appear in a non-valid context. The entity will | |
5146 | -- be frozen in the proper scope after the current generic is analyzed. | |
7640ef8a AC |
5147 | -- However, aspects must be analyzed because they may be queried later |
5148 | -- within the generic itself, and the corresponding pragma or attribute | |
5149 | -- definition has not been analyzed yet. | |
70482933 | 5150 | |
c6823a20 | 5151 | elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then |
7640ef8a AC |
5152 | if Has_Delayed_Aspects (E) then |
5153 | Analyze_Aspects_At_Freeze_Point (E); | |
5154 | end if; | |
5155 | ||
d65a80fd HK |
5156 | Result := No_List; |
5157 | goto Leave; | |
70482933 | 5158 | |
164e06c6 AC |
5159 | -- AI05-0213: A formal incomplete type does not freeze the actual. In |
5160 | -- the instance, the same applies to the subtype renaming the actual. | |
d3cb4cc0 AC |
5161 | |
5162 | elsif Is_Private_Type (E) | |
5163 | and then Is_Generic_Actual_Type (E) | |
5164 | and then No (Full_View (Base_Type (E))) | |
5165 | and then Ada_Version >= Ada_2012 | |
5166 | then | |
d65a80fd HK |
5167 | Result := No_List; |
5168 | goto Leave; | |
d3cb4cc0 | 5169 | |
8575023c AC |
5170 | -- Formal subprograms are never frozen |
5171 | ||
5172 | elsif Is_Formal_Subprogram (E) then | |
d65a80fd HK |
5173 | Result := No_List; |
5174 | goto Leave; | |
8575023c AC |
5175 | |
5176 | -- Generic types are never frozen as they lack delayed semantic checks | |
5a8a6763 RD |
5177 | |
5178 | elsif Is_Generic_Type (E) then | |
d65a80fd HK |
5179 | Result := No_List; |
5180 | goto Leave; | |
5a8a6763 | 5181 | |
70482933 RK |
5182 | -- Do not freeze a global entity within an inner scope created during |
5183 | -- expansion. A call to subprogram E within some internal procedure | |
5184 | -- (a stream attribute for example) might require freezing E, but the | |
5185 | -- freeze node must appear in the same declarative part as E itself. | |
5186 | -- The two-pass elaboration mechanism in gigi guarantees that E will | |
5187 | -- be frozen before the inner call is elaborated. We exclude constants | |
5188 | -- from this test, because deferred constants may be frozen early, and | |
19590d70 GD |
5189 | -- must be diagnosed (e.g. in the case of a deferred constant being used |
5190 | -- in a default expression). If the enclosing subprogram comes from | |
5191 | -- source, or is a generic instance, then the freeze point is the one | |
5192 | -- mandated by the language, and we freeze the entity. A subprogram that | |
5193 | -- is a child unit body that acts as a spec does not have a spec that | |
5194 | -- comes from source, but can only come from source. | |
70482933 | 5195 | |
c6823a20 EB |
5196 | elsif In_Open_Scopes (Scope (Test_E)) |
5197 | and then Scope (Test_E) /= Current_Scope | |
5198 | and then Ekind (Test_E) /= E_Constant | |
70482933 RK |
5199 | then |
5200 | declare | |
3cae7f14 | 5201 | S : Entity_Id; |
70482933 RK |
5202 | |
5203 | begin | |
3cae7f14 | 5204 | S := Current_Scope; |
70482933 RK |
5205 | while Present (S) loop |
5206 | if Is_Overloadable (S) then | |
5207 | if Comes_From_Source (S) | |
5208 | or else Is_Generic_Instance (S) | |
fea9e956 | 5209 | or else Is_Child_Unit (S) |
70482933 RK |
5210 | then |
5211 | exit; | |
5212 | else | |
d65a80fd HK |
5213 | Result := No_List; |
5214 | goto Leave; | |
70482933 RK |
5215 | end if; |
5216 | end if; | |
5217 | ||
5218 | S := Scope (S); | |
5219 | end loop; | |
5220 | end; | |
555360a5 AC |
5221 | |
5222 | -- Similarly, an inlined instance body may make reference to global | |
5223 | -- entities, but these references cannot be the proper freezing point | |
def46b54 RD |
5224 | -- for them, and in the absence of inlining freezing will take place in |
5225 | -- their own scope. Normally instance bodies are analyzed after the | |
5226 | -- enclosing compilation, and everything has been frozen at the proper | |
5227 | -- place, but with front-end inlining an instance body is compiled | |
5228 | -- before the end of the enclosing scope, and as a result out-of-order | |
5229 | -- freezing must be prevented. | |
555360a5 AC |
5230 | |
5231 | elsif Front_End_Inlining | |
7d8b9c99 | 5232 | and then In_Instance_Body |
c6823a20 | 5233 | and then Present (Scope (Test_E)) |
555360a5 AC |
5234 | then |
5235 | declare | |
3cae7f14 | 5236 | S : Entity_Id; |
c6823a20 | 5237 | |
555360a5 | 5238 | begin |
3cae7f14 | 5239 | S := Scope (Test_E); |
555360a5 AC |
5240 | while Present (S) loop |
5241 | if Is_Generic_Instance (S) then | |
5242 | exit; | |
5243 | else | |
5244 | S := Scope (S); | |
5245 | end if; | |
5246 | end loop; | |
5247 | ||
5248 | if No (S) then | |
d65a80fd HK |
5249 | Result := No_List; |
5250 | goto Leave; | |
555360a5 AC |
5251 | end if; |
5252 | end; | |
70482933 RK |
5253 | end if; |
5254 | ||
5f49133f AC |
5255 | -- Add checks to detect proper initialization of scalars that may appear |
5256 | -- as subprogram parameters. | |
0ea55619 | 5257 | |
15e934bf | 5258 | if Is_Subprogram (E) and then Check_Validity_Of_Parameters then |
5f49133f | 5259 | Apply_Parameter_Validity_Checks (E); |
0ea55619 AC |
5260 | end if; |
5261 | ||
9a6dc470 RD |
5262 | -- Deal with delayed aspect specifications. The analysis of the aspect |
5263 | -- is required to be delayed to the freeze point, thus we analyze the | |
5264 | -- pragma or attribute definition clause in the tree at this point. We | |
5265 | -- also analyze the aspect specification node at the freeze point when | |
5266 | -- the aspect doesn't correspond to pragma/attribute definition clause. | |
c159409f AC |
5267 | |
5268 | if Has_Delayed_Aspects (E) then | |
8a0320ad | 5269 | Analyze_Aspects_At_Freeze_Point (E); |
c159409f AC |
5270 | end if; |
5271 | ||
70482933 RK |
5272 | -- Here to freeze the entity |
5273 | ||
70482933 RK |
5274 | Set_Is_Frozen (E); |
5275 | ||
5276 | -- Case of entity being frozen is other than a type | |
5277 | ||
5278 | if not Is_Type (E) then | |
685bc70f | 5279 | |
70482933 RK |
5280 | -- If entity is exported or imported and does not have an external |
5281 | -- name, now is the time to provide the appropriate default name. | |
5282 | -- Skip this if the entity is stubbed, since we don't need a name | |
75a64833 AC |
5283 | -- for any stubbed routine. For the case on intrinsics, if no |
5284 | -- external name is specified, then calls will be handled in | |
545cb5be AC |
5285 | -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an |
5286 | -- external name is provided, then Expand_Intrinsic_Call leaves | |
75a64833 | 5287 | -- calls in place for expansion by GIGI. |
70482933 RK |
5288 | |
5289 | if (Is_Imported (E) or else Is_Exported (E)) | |
5290 | and then No (Interface_Name (E)) | |
5291 | and then Convention (E) /= Convention_Stubbed | |
75a64833 | 5292 | and then Convention (E) /= Convention_Intrinsic |
70482933 RK |
5293 | then |
5294 | Set_Encoded_Interface_Name | |
5295 | (E, Get_Default_External_Name (E)); | |
fbf5a39b | 5296 | |
bbaba73f EB |
5297 | -- If entity is an atomic object appearing in a declaration and |
5298 | -- the expression is an aggregate, assign it to a temporary to | |
5299 | -- ensure that the actual assignment is done atomically rather | |
5300 | -- than component-wise (the assignment to the temp may be done | |
5301 | -- component-wise, but that is harmless). | |
fbf5a39b | 5302 | |
f280dd8f | 5303 | elsif Is_Atomic_Or_VFA (E) |
fbf5a39b AC |
5304 | and then Nkind (Parent (E)) = N_Object_Declaration |
5305 | and then Present (Expression (Parent (E))) | |
bbaba73f | 5306 | and then Nkind (Expression (Parent (E))) = N_Aggregate |
0c6826a5 | 5307 | and then Is_Atomic_VFA_Aggregate (Expression (Parent (E))) |
fbf5a39b | 5308 | then |
b0159fbe | 5309 | null; |
70482933 RK |
5310 | end if; |
5311 | ||
32bba3c9 | 5312 | -- Subprogram case |
70482933 RK |
5313 | |
5314 | if Is_Subprogram (E) then | |
32bba3c9 AC |
5315 | |
5316 | -- Check for needing to wrap imported subprogram | |
5317 | ||
5318 | Wrap_Imported_Subprogram (E); | |
5319 | ||
5320 | -- Freeze all parameter types and the return type (RM 13.14(14)). | |
5321 | -- However skip this for internal subprograms. This is also where | |
5322 | -- any extra formal parameters are created since we now know | |
5323 | -- whether the subprogram will use a foreign convention. | |
5324 | ||
78bc7fe6 ES |
5325 | -- In Ada 2012, freezing a subprogram does not always freeze the |
5326 | -- corresponding profile (see AI05-019). An attribute reference | |
5327 | -- is not a freezing point of the profile. Flag Do_Freeze_Profile | |
5328 | -- indicates whether the profile should be frozen now. | |
c9f95e4c AC |
5329 | -- Other constructs that should not freeze ??? |
5330 | ||
4d1429b2 | 5331 | -- This processing doesn't apply to internal entities (see below) |
b943a971 | 5332 | |
c7658039 | 5333 | if not Is_Internal (E) and then Do_Freeze_Profile then |
4d1429b2 | 5334 | if not Freeze_Profile (E) then |
d65a80fd | 5335 | goto Leave; |
4d1429b2 | 5336 | end if; |
70482933 RK |
5337 | end if; |
5338 | ||
5339 | -- Must freeze its parent first if it is a derived subprogram | |
5340 | ||
5341 | if Present (Alias (E)) then | |
c159409f | 5342 | Freeze_And_Append (Alias (E), N, Result); |
70482933 RK |
5343 | end if; |
5344 | ||
19590d70 GD |
5345 | -- We don't freeze internal subprograms, because we don't normally |
5346 | -- want addition of extra formals or mechanism setting to happen | |
5347 | -- for those. However we do pass through predefined dispatching | |
5348 | -- cases, since extra formals may be needed in some cases, such as | |
5349 | -- for the stream 'Input function (build-in-place formals). | |
5350 | ||
5351 | if not Is_Internal (E) | |
5352 | or else Is_Predefined_Dispatching_Operation (E) | |
5353 | then | |
70482933 RK |
5354 | Freeze_Subprogram (E); |
5355 | end if; | |
5356 | ||
d3e16619 AC |
5357 | -- If warning on suspicious contracts then check for the case of |
5358 | -- a postcondition other than False for a No_Return subprogram. | |
5359 | ||
5360 | if No_Return (E) | |
5361 | and then Warn_On_Suspicious_Contract | |
5362 | and then Present (Contract (E)) | |
5363 | then | |
5364 | declare | |
5365 | Prag : Node_Id := Pre_Post_Conditions (Contract (E)); | |
5366 | Exp : Node_Id; | |
5367 | ||
5368 | begin | |
5369 | while Present (Prag) loop | |
6e759c2a BD |
5370 | if Nam_In (Pragma_Name_Unmapped (Prag), |
5371 | Name_Post, | |
5372 | Name_Postcondition, | |
5373 | Name_Refined_Post) | |
d3e16619 AC |
5374 | then |
5375 | Exp := | |
5376 | Expression | |
5377 | (First (Pragma_Argument_Associations (Prag))); | |
5378 | ||
5379 | if Nkind (Exp) /= N_Identifier | |
5380 | or else Chars (Exp) /= Name_False | |
5381 | then | |
5382 | Error_Msg_NE | |
5383 | ("useless postcondition, & is marked " | |
5384 | & "No_Return?T?", Exp, E); | |
5385 | end if; | |
5386 | end if; | |
5387 | ||
5388 | Prag := Next_Pragma (Prag); | |
5389 | end loop; | |
5390 | end; | |
5391 | end if; | |
5392 | ||
70482933 RK |
5393 | -- Here for other than a subprogram or type |
5394 | ||
5395 | else | |
5396 | -- If entity has a type, and it is not a generic unit, then | |
7d8b9c99 | 5397 | -- freeze it first (RM 13.14(10)). |
70482933 | 5398 | |
ac72c9c5 | 5399 | if Present (Etype (E)) |
70482933 RK |
5400 | and then Ekind (E) /= E_Generic_Function |
5401 | then | |
c159409f | 5402 | Freeze_And_Append (Etype (E), N, Result); |
32a21096 AC |
5403 | |
5404 | -- For an object of an anonymous array type, aspects on the | |
5405 | -- object declaration apply to the type itself. This is the | |
5406 | -- case for Atomic_Components, Volatile_Components, and | |
5407 | -- Independent_Components. In these cases analysis of the | |
5408 | -- generated pragma will mark the anonymous types accordingly, | |
5409 | -- and the object itself does not require a freeze node. | |
5410 | ||
5411 | if Ekind (E) = E_Variable | |
5412 | and then Is_Itype (Etype (E)) | |
5413 | and then Is_Array_Type (Etype (E)) | |
5414 | and then Has_Delayed_Aspects (E) | |
5415 | then | |
5416 | Set_Has_Delayed_Aspects (E, False); | |
5417 | Set_Has_Delayed_Freeze (E, False); | |
5418 | Set_Freeze_Node (E, Empty); | |
5419 | end if; | |
70482933 RK |
5420 | end if; |
5421 | ||
2c9beb8a | 5422 | -- Special processing for objects created by object declaration |
70482933 RK |
5423 | |
5424 | if Nkind (Declaration_Node (E)) = N_Object_Declaration then | |
b741083a | 5425 | Freeze_Object_Declaration (E); |
70482933 RK |
5426 | end if; |
5427 | ||
5428 | -- Check that a constant which has a pragma Volatile[_Components] | |
7d8b9c99 | 5429 | -- or Atomic[_Components] also has a pragma Import (RM C.6(13)). |
70482933 RK |
5430 | |
5431 | -- Note: Atomic[_Components] also sets Volatile[_Components] | |
5432 | ||
5433 | if Ekind (E) = E_Constant | |
5434 | and then (Has_Volatile_Components (E) or else Is_Volatile (E)) | |
5435 | and then not Is_Imported (E) | |
e8cddc3b | 5436 | and then not Has_Boolean_Aspect_Import (E) |
70482933 RK |
5437 | then |
5438 | -- Make sure we actually have a pragma, and have not merely | |
5439 | -- inherited the indication from elsewhere (e.g. an address | |
a90bd866 | 5440 | -- clause, which is not good enough in RM terms). |
70482933 | 5441 | |
1d571f3b | 5442 | if Has_Rep_Pragma (E, Name_Atomic) |
91b1417d | 5443 | or else |
1d571f3b | 5444 | Has_Rep_Pragma (E, Name_Atomic_Components) |
70482933 RK |
5445 | then |
5446 | Error_Msg_N | |
91b1417d | 5447 | ("stand alone atomic constant must be " & |
def46b54 | 5448 | "imported (RM C.6(13))", E); |
91b1417d | 5449 | |
1d571f3b | 5450 | elsif Has_Rep_Pragma (E, Name_Volatile) |
91b1417d | 5451 | or else |
1d571f3b | 5452 | Has_Rep_Pragma (E, Name_Volatile_Components) |
91b1417d AC |
5453 | then |
5454 | Error_Msg_N | |
5455 | ("stand alone volatile constant must be " & | |
86cde7b1 | 5456 | "imported (RM C.6(13))", E); |
70482933 RK |
5457 | end if; |
5458 | end if; | |
5459 | ||
5460 | -- Static objects require special handling | |
5461 | ||
5462 | if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) | |
5463 | and then Is_Statically_Allocated (E) | |
5464 | then | |
5465 | Freeze_Static_Object (E); | |
5466 | end if; | |
5467 | ||
5468 | -- Remaining step is to layout objects | |
5469 | ||
ef1c0511 AC |
5470 | if Ekind_In (E, E_Variable, E_Constant, E_Loop_Parameter) |
5471 | or else Is_Formal (E) | |
70482933 RK |
5472 | then |
5473 | Layout_Object (E); | |
5474 | end if; | |
3a3af4c3 | 5475 | |
2ffcbaa5 AC |
5476 | -- For an object that does not have delayed freezing, and whose |
5477 | -- initialization actions have been captured in a compound | |
5478 | -- statement, move them back now directly within the enclosing | |
5479 | -- statement sequence. | |
3a3af4c3 AC |
5480 | |
5481 | if Ekind_In (E, E_Constant, E_Variable) | |
15e934bf | 5482 | and then not Has_Delayed_Freeze (E) |
3a3af4c3 | 5483 | then |
2ffcbaa5 | 5484 | Explode_Initialization_Compound_Statement (E); |
3a3af4c3 | 5485 | end if; |
70482933 RK |
5486 | end if; |
5487 | ||
5488 | -- Case of a type or subtype being frozen | |
5489 | ||
5490 | else | |
31b5873d GD |
5491 | -- We used to check here that a full type must have preelaborable |
5492 | -- initialization if it completes a private type specified with | |
308e6f3a | 5493 | -- pragma Preelaborable_Initialization, but that missed cases where |
31b5873d GD |
5494 | -- the types occur within a generic package, since the freezing |
5495 | -- that occurs within a containing scope generally skips traversal | |
5496 | -- of a generic unit's declarations (those will be frozen within | |
5497 | -- instances). This check was moved to Analyze_Package_Specification. | |
3f1ede06 | 5498 | |
70482933 RK |
5499 | -- The type may be defined in a generic unit. This can occur when |
5500 | -- freezing a generic function that returns the type (which is | |
5501 | -- defined in a parent unit). It is clearly meaningless to freeze | |
5502 | -- this type. However, if it is a subtype, its size may be determi- | |
5503 | -- nable and used in subsequent checks, so might as well try to | |
5504 | -- compute it. | |
5505 | ||
cf7bb903 | 5506 | -- In Ada 2012, Freeze_Entities is also used in the front end to |
e876c43a AC |
5507 | -- trigger the analysis of aspect expressions, so in this case we |
5508 | -- want to continue the freezing process. | |
5509 | ||
4f94fa11 AC |
5510 | -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead |
5511 | -- In_Generic_Scope (E)??? | |
5512 | ||
70482933 RK |
5513 | if Present (Scope (E)) |
5514 | and then Is_Generic_Unit (Scope (E)) | |
3cd4a210 AC |
5515 | and then |
5516 | (not Has_Predicates (E) | |
5517 | and then not Has_Delayed_Freeze (E)) | |
70482933 RK |
5518 | then |
5519 | Check_Compile_Time_Size (E); | |
d65a80fd HK |
5520 | Result := No_List; |
5521 | goto Leave; | |
70482933 RK |
5522 | end if; |
5523 | ||
e9a79435 RD |
5524 | -- Check for error of Type_Invariant'Class applied to an untagged |
5525 | -- type (check delayed to freeze time when full type is available). | |
2fe258bf AC |
5526 | |
5527 | declare | |
5528 | Prag : constant Node_Id := Get_Pragma (E, Pragma_Invariant); | |
5529 | begin | |
5530 | if Present (Prag) | |
5531 | and then Class_Present (Prag) | |
5532 | and then not Is_Tagged_Type (E) | |
5533 | then | |
5534 | Error_Msg_NE | |
3ddfabe3 | 5535 | ("Type_Invariant''Class cannot be specified for &", Prag, E); |
2fe258bf AC |
5536 | Error_Msg_N |
5537 | ("\can only be specified for a tagged type", Prag); | |
5538 | end if; | |
5539 | end; | |
5540 | ||
58996b09 | 5541 | if Is_Ghost_Entity (E) then |
c5cec2fe | 5542 | |
58996b09 HK |
5543 | -- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify |
5544 | -- this legality rule first to five a finer-grained diagnostic. | |
5545 | ||
5546 | if Is_Concurrent_Type (E) then | |
5547 | Error_Msg_N ("ghost type & cannot be concurrent", E); | |
5548 | ||
4179af27 | 5549 | -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(7)) |
58996b09 HK |
5550 | |
5551 | elsif Is_Effectively_Volatile (E) then | |
5552 | Error_Msg_N ("ghost type & cannot be volatile", E); | |
5553 | end if; | |
c5cec2fe AC |
5554 | end if; |
5555 | ||
70482933 RK |
5556 | -- Deal with special cases of freezing for subtype |
5557 | ||
5558 | if E /= Base_Type (E) then | |
5559 | ||
3d626f94 EB |
5560 | -- Before we do anything else, a specific test for the case of a |
5561 | -- size given for an array where the array would need to be packed | |
5562 | -- in order for the size to be honored, but is not. This is the | |
5563 | -- case where implicit packing may apply. The reason we do this so | |
5564 | -- early is that, if we have implicit packing, the layout of the | |
5565 | -- base type is affected, so we must do this before we freeze the | |
5566 | -- base type. | |
3d529af4 RD |
5567 | |
5568 | -- We could do this processing only if implicit packing is enabled | |
5569 | -- since in all other cases, the error would be caught by the back | |
5570 | -- end. However, we choose to do the check even if we do not have | |
aa0dfa7e | 5571 | -- implicit packing enabled, since this allows us to give a more |
3d626f94 EB |
5572 | -- useful error message (advising use of pragma Implicit_Packing |
5573 | -- or pragma Pack). | |
86cde7b1 RD |
5574 | |
5575 | if Is_Array_Type (E) then | |
5576 | declare | |
3d529af4 RD |
5577 | Ctyp : constant Entity_Id := Component_Type (E); |
5578 | Rsiz : constant Uint := RM_Size (Ctyp); | |
5579 | SZ : constant Node_Id := Size_Clause (E); | |
5580 | Btyp : constant Entity_Id := Base_Type (E); | |
5581 | ||
5582 | Lo : Node_Id; | |
5583 | Hi : Node_Id; | |
5584 | Indx : Node_Id; | |
5585 | ||
3d626f94 EB |
5586 | Dim : Uint; |
5587 | Num_Elmts : Uint := Uint_1; | |
3d529af4 | 5588 | -- Number of elements in array |
86cde7b1 RD |
5589 | |
5590 | begin | |
5591 | -- Check enabling conditions. These are straightforward | |
5592 | -- except for the test for a limited composite type. This | |
5593 | -- eliminates the rare case of a array of limited components | |
5594 | -- where there are issues of whether or not we can go ahead | |
5595 | -- and pack the array (since we can't freely pack and unpack | |
5596 | -- arrays if they are limited). | |
5597 | ||
5598 | -- Note that we check the root type explicitly because the | |
5599 | -- whole point is we are doing this test before we have had | |
5600 | -- a chance to freeze the base type (and it is that freeze | |
5601 | -- action that causes stuff to be inherited). | |
5602 | ||
3d626f94 EB |
5603 | -- The conditions on the size are identical to those used in |
5604 | -- Freeze_Array_Type to set the Is_Packed flag. | |
5605 | ||
3d529af4 | 5606 | if Has_Size_Clause (E) |
fc893455 | 5607 | and then Known_Static_RM_Size (E) |
86cde7b1 RD |
5608 | and then not Is_Packed (E) |
5609 | and then not Has_Pragma_Pack (E) | |
86cde7b1 | 5610 | and then not Has_Component_Size_Clause (E) |
fc893455 | 5611 | and then Known_Static_RM_Size (Ctyp) |
3d626f94 EB |
5612 | and then Rsiz <= 64 |
5613 | and then not (Addressable (Rsiz) | |
5614 | and then Known_Static_Esize (Ctyp) | |
5615 | and then Esize (Ctyp) = Rsiz) | |
5616 | and then not (Rsiz mod System_Storage_Unit = 0 | |
5617 | and then Is_Composite_Type (Ctyp)) | |
86cde7b1 RD |
5618 | and then not Is_Limited_Composite (E) |
5619 | and then not Is_Packed (Root_Type (E)) | |
5620 | and then not Has_Component_Size_Clause (Root_Type (E)) | |
f5da7a97 | 5621 | and then not (CodePeer_Mode or GNATprove_Mode) |
86cde7b1 | 5622 | then |
3d529af4 RD |
5623 | -- Compute number of elements in array |
5624 | ||
3d529af4 RD |
5625 | Indx := First_Index (E); |
5626 | while Present (Indx) loop | |
5627 | Get_Index_Bounds (Indx, Lo, Hi); | |
5628 | ||
5629 | if not (Compile_Time_Known_Value (Lo) | |
5630 | and then | |
5631 | Compile_Time_Known_Value (Hi)) | |
5632 | then | |
5633 | goto No_Implicit_Packing; | |
5634 | end if; | |
86cde7b1 | 5635 | |
3d626f94 EB |
5636 | Dim := Expr_Value (Hi) - Expr_Value (Lo) + 1; |
5637 | ||
5638 | if Dim >= 0 then | |
5639 | Num_Elmts := Num_Elmts * Dim; | |
5640 | else | |
5641 | Num_Elmts := Uint_0; | |
5642 | end if; | |
5643 | ||
3d529af4 RD |
5644 | Next_Index (Indx); |
5645 | end loop; | |
5646 | ||
5647 | -- What we are looking for here is the situation where | |
5648 | -- the RM_Size given would be exactly right if there was | |
3d626f94 EB |
5649 | -- a pragma Pack, resulting in the component size being |
5650 | -- the RM_Size of the component type. | |
5651 | ||
5652 | if RM_Size (E) = Num_Elmts * Rsiz then | |
c70cf4f8 | 5653 | |
3d529af4 | 5654 | -- For implicit packing mode, just set the component |
3d626f94 | 5655 | -- size and Freeze_Array_Type will do the rest. |
86cde7b1 | 5656 | |
3d529af4 | 5657 | if Implicit_Packing then |
3d626f94 | 5658 | Set_Component_Size (Btyp, Rsiz); |
5a989c6b | 5659 | |
c70cf4f8 | 5660 | -- Otherwise give an error message |
3d529af4 RD |
5661 | |
5662 | else | |
5663 | Error_Msg_NE | |
5664 | ("size given for& too small", SZ, E); | |
5665 | Error_Msg_N -- CODEFIX | |
c70cf4f8 AC |
5666 | ("\use explicit pragma Pack or use pragma " |
5667 | & "Implicit_Packing", SZ); | |
3d529af4 | 5668 | end if; |
86cde7b1 RD |
5669 | end if; |
5670 | end if; | |
5671 | end; | |
5672 | end if; | |
5673 | ||
3d529af4 RD |
5674 | <<No_Implicit_Packing>> |
5675 | ||
def46b54 | 5676 | -- If ancestor subtype present, freeze that first. Note that this |
8110ee3b | 5677 | -- will also get the base type frozen. Need RM reference ??? |
70482933 RK |
5678 | |
5679 | Atype := Ancestor_Subtype (E); | |
5680 | ||
5681 | if Present (Atype) then | |
c159409f | 5682 | Freeze_And_Append (Atype, N, Result); |
70482933 | 5683 | |
8110ee3b | 5684 | -- No ancestor subtype present |
70482933 | 5685 | |
8110ee3b RD |
5686 | else |
5687 | -- See if we have a nearest ancestor that has a predicate. | |
5688 | -- That catches the case of derived type with a predicate. | |
5689 | -- Need RM reference here ??? | |
5690 | ||
5691 | Atype := Nearest_Ancestor (E); | |
5692 | ||
5693 | if Present (Atype) and then Has_Predicates (Atype) then | |
5694 | Freeze_And_Append (Atype, N, Result); | |
5695 | end if; | |
5696 | ||
5697 | -- Freeze base type before freezing the entity (RM 13.14(15)) | |
5698 | ||
5699 | if E /= Base_Type (E) then | |
5700 | Freeze_And_Append (Base_Type (E), N, Result); | |
5701 | end if; | |
70482933 RK |
5702 | end if; |
5703 | ||
dc3af7e2 AC |
5704 | -- A subtype inherits all the type-related representation aspects |
5705 | -- from its parents (RM 13.1(8)). | |
5706 | ||
5707 | Inherit_Aspects_At_Freeze_Point (E); | |
5708 | ||
fbf5a39b | 5709 | -- For a derived type, freeze its parent type first (RM 13.14(15)) |
70482933 RK |
5710 | |
5711 | elsif Is_Derived_Type (E) then | |
c159409f AC |
5712 | Freeze_And_Append (Etype (E), N, Result); |
5713 | Freeze_And_Append (First_Subtype (Etype (E)), N, Result); | |
dc3af7e2 AC |
5714 | |
5715 | -- A derived type inherits each type-related representation aspect | |
5716 | -- of its parent type that was directly specified before the | |
5717 | -- declaration of the derived type (RM 13.1(15)). | |
5718 | ||
5719 | Inherit_Aspects_At_Freeze_Point (E); | |
70482933 | 5720 | end if; |
3f1bc2cf AC |
5721 | |
5722 | -- Check for incompatible size and alignment for record type | |
5723 | ||
5724 | if Warn_On_Size_Alignment | |
5725 | and then Is_Record_Type (E) | |
5726 | and then Has_Size_Clause (E) and then Has_Alignment_Clause (E) | |
5727 | ||
5728 | -- If explicit Object_Size clause given assume that the programmer | |
5729 | -- knows what he is doing, and expects the compiler behavior. | |
5730 | ||
5731 | and then not Has_Object_Size_Clause (E) | |
5732 | ||
5733 | -- Check for size not a multiple of alignment | |
5734 | ||
5735 | and then RM_Size (E) mod (Alignment (E) * System_Storage_Unit) /= 0 | |
5736 | then | |
5737 | declare | |
5738 | SC : constant Node_Id := Size_Clause (E); | |
5739 | AC : constant Node_Id := Alignment_Clause (E); | |
5740 | Loc : Node_Id; | |
5741 | Abits : constant Uint := Alignment (E) * System_Storage_Unit; | |
5742 | ||
5743 | begin | |
5744 | if Present (SC) and then Present (AC) then | |
5745 | ||
5746 | -- Give a warning | |
5747 | ||
5748 | if Sloc (SC) > Sloc (AC) then | |
5749 | Loc := SC; | |
5750 | Error_Msg_NE | |
1ca46a77 AC |
5751 | ("?Z?size is not a multiple of alignment for &", |
5752 | Loc, E); | |
3f1bc2cf AC |
5753 | Error_Msg_Sloc := Sloc (AC); |
5754 | Error_Msg_Uint_1 := Alignment (E); | |
1ca46a77 | 5755 | Error_Msg_N ("\?Z?alignment of ^ specified #", Loc); |
3f1bc2cf AC |
5756 | |
5757 | else | |
5758 | Loc := AC; | |
5759 | Error_Msg_NE | |
1ca46a77 AC |
5760 | ("?Z?size is not a multiple of alignment for &", |
5761 | Loc, E); | |
3f1bc2cf AC |
5762 | Error_Msg_Sloc := Sloc (SC); |
5763 | Error_Msg_Uint_1 := RM_Size (E); | |
1ca46a77 | 5764 | Error_Msg_N ("\?Z?size of ^ specified #", Loc); |
3f1bc2cf AC |
5765 | end if; |
5766 | ||
5767 | Error_Msg_Uint_1 := ((RM_Size (E) / Abits) + 1) * Abits; | |
1ca46a77 | 5768 | Error_Msg_N ("\?Z?Object_Size will be increased to ^", Loc); |
3f1bc2cf AC |
5769 | end if; |
5770 | end; | |
5771 | end if; | |
70482933 | 5772 | |
63bb4268 | 5773 | -- Array type |
70482933 RK |
5774 | |
5775 | if Is_Array_Type (E) then | |
63bb4268 | 5776 | Freeze_Array_Type (E); |
70482933 | 5777 | |
fbf5a39b AC |
5778 | -- For a class-wide type, the corresponding specific type is |
5779 | -- frozen as well (RM 13.14(15)) | |
70482933 RK |
5780 | |
5781 | elsif Is_Class_Wide_Type (E) then | |
c159409f | 5782 | Freeze_And_Append (Root_Type (E), N, Result); |
70482933 | 5783 | |
86cde7b1 RD |
5784 | -- If the base type of the class-wide type is still incomplete, |
5785 | -- the class-wide remains unfrozen as well. This is legal when | |
5786 | -- E is the formal of a primitive operation of some other type | |
5787 | -- which is being frozen. | |
5788 | ||
5789 | if not Is_Frozen (Root_Type (E)) then | |
5790 | Set_Is_Frozen (E, False); | |
d65a80fd | 5791 | goto Leave; |
86cde7b1 RD |
5792 | end if; |
5793 | ||
67336960 AC |
5794 | -- The equivalent type associated with a class-wide subtype needs |
5795 | -- to be frozen to ensure that its layout is done. | |
5796 | ||
5797 | if Ekind (E) = E_Class_Wide_Subtype | |
5798 | and then Present (Equivalent_Type (E)) | |
5799 | then | |
5800 | Freeze_And_Append (Equivalent_Type (E), N, Result); | |
5801 | end if; | |
5802 | ||
5803 | -- Generate an itype reference for a library-level class-wide type | |
5804 | -- at the freeze point. Otherwise the first explicit reference to | |
5805 | -- the type may appear in an inner scope which will be rejected by | |
5806 | -- the back-end. | |
70482933 RK |
5807 | |
5808 | if Is_Itype (E) | |
5809 | and then Is_Compilation_Unit (Scope (E)) | |
5810 | then | |
70482933 | 5811 | declare |
fbf5a39b | 5812 | Ref : constant Node_Id := Make_Itype_Reference (Loc); |
70482933 RK |
5813 | |
5814 | begin | |
5815 | Set_Itype (Ref, E); | |
70482933 | 5816 | |
67336960 AC |
5817 | -- From a gigi point of view, a class-wide subtype derives |
5818 | -- from its record equivalent type. As a result, the itype | |
5819 | -- reference must appear after the freeze node of the | |
5820 | -- equivalent type or gigi will reject the reference. | |
fbf5a39b | 5821 | |
67336960 AC |
5822 | if Ekind (E) = E_Class_Wide_Subtype |
5823 | and then Present (Equivalent_Type (E)) | |
5824 | then | |
5825 | Insert_After (Freeze_Node (Equivalent_Type (E)), Ref); | |
5826 | else | |
5827 | Add_To_Result (Ref); | |
5828 | end if; | |
5829 | end; | |
fbf5a39b AC |
5830 | end if; |
5831 | ||
e187fa72 AC |
5832 | -- For a record type or record subtype, freeze all component types |
5833 | -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than | |
5834 | -- using Is_Record_Type, because we don't want to attempt the freeze | |
5835 | -- for the case of a private type with record extension (we will do | |
5836 | -- that later when the full type is frozen). | |
5837 | ||
ca0eb951 AC |
5838 | elsif Ekind_In (E, E_Record_Type, E_Record_Subtype) then |
5839 | if not In_Generic_Scope (E) then | |
5840 | Freeze_Record_Type (E); | |
5841 | end if; | |
5842 | ||
5843 | -- Report a warning if a discriminated record base type has a | |
5844 | -- convention with language C or C++ applied to it. This check is | |
5845 | -- done even within generic scopes (but not in instantiations), | |
5846 | -- which is why we don't do it as part of Freeze_Record_Type. | |
5847 | ||
5848 | Check_Suspicious_Convention (E); | |
70482933 | 5849 | |
220d1fd9 AC |
5850 | -- For a concurrent type, freeze corresponding record type. This does |
5851 | -- not correspond to any specific rule in the RM, but the record type | |
5852 | -- is essentially part of the concurrent type. Also freeze all local | |
5853 | -- entities. This includes record types created for entry parameter | |
5854 | -- blocks and whatever local entities may appear in the private part. | |
70482933 RK |
5855 | |
5856 | elsif Is_Concurrent_Type (E) then | |
5857 | if Present (Corresponding_Record_Type (E)) then | |
ef1c0511 | 5858 | Freeze_And_Append (Corresponding_Record_Type (E), N, Result); |
70482933 RK |
5859 | end if; |
5860 | ||
5861 | Comp := First_Entity (E); | |
70482933 RK |
5862 | while Present (Comp) loop |
5863 | if Is_Type (Comp) then | |
c159409f | 5864 | Freeze_And_Append (Comp, N, Result); |
70482933 RK |
5865 | |
5866 | elsif (Ekind (Comp)) /= E_Function then | |
c6823a20 | 5867 | |
a08bf2de RD |
5868 | -- The guard on the presence of the Etype seems to be needed |
5869 | -- for some CodePeer (-gnatcC) cases, but not clear why??? | |
5870 | ||
5871 | if Present (Etype (Comp)) then | |
5872 | if Is_Itype (Etype (Comp)) | |
5873 | and then Underlying_Type (Scope (Etype (Comp))) = E | |
5874 | then | |
5875 | Undelay_Type (Etype (Comp)); | |
5876 | end if; | |
5877 | ||
5878 | Freeze_And_Append (Etype (Comp), N, Result); | |
5879 | end if; | |
70482933 RK |
5880 | end if; |
5881 | ||
5882 | Next_Entity (Comp); | |
5883 | end loop; | |
5884 | ||
ee094616 RD |
5885 | -- Private types are required to point to the same freeze node as |
5886 | -- their corresponding full views. The freeze node itself has to | |
5887 | -- point to the partial view of the entity (because from the partial | |
5888 | -- view, we can retrieve the full view, but not the reverse). | |
5889 | -- However, in order to freeze correctly, we need to freeze the full | |
5890 | -- view. If we are freezing at the end of a scope (or within the | |
bf0b0e5e | 5891 | -- scope) of the private type, the partial and full views will have |
ee094616 RD |
5892 | -- been swapped, the full view appears first in the entity chain and |
5893 | -- the swapping mechanism ensures that the pointers are properly set | |
5894 | -- (on scope exit). | |
5895 | ||
5896 | -- If we encounter the partial view before the full view (e.g. when | |
5897 | -- freezing from another scope), we freeze the full view, and then | |
5898 | -- set the pointers appropriately since we cannot rely on swapping to | |
5899 | -- fix things up (subtypes in an outer scope might not get swapped). | |
70482933 | 5900 | |
bf0b0e5e AC |
5901 | -- If the full view is itself private, the above requirements apply |
5902 | -- to the underlying full view instead of the full view. But there is | |
5903 | -- no swapping mechanism for the underlying full view so we need to | |
5904 | -- set the pointers appropriately in both cases. | |
5905 | ||
70482933 RK |
5906 | elsif Is_Incomplete_Or_Private_Type (E) |
5907 | and then not Is_Generic_Type (E) | |
5908 | then | |
86cde7b1 RD |
5909 | -- The construction of the dispatch table associated with library |
5910 | -- level tagged types forces freezing of all the primitives of the | |
5911 | -- type, which may cause premature freezing of the partial view. | |
5912 | -- For example: | |
5913 | ||
5914 | -- package Pkg is | |
5915 | -- type T is tagged private; | |
5916 | -- type DT is new T with private; | |
3e24afaa | 5917 | -- procedure Prim (X : in out T; Y : in out DT'Class); |
86cde7b1 RD |
5918 | -- private |
5919 | -- type T is tagged null record; | |
5920 | -- Obj : T; | |
5921 | -- type DT is new T with null record; | |
5922 | -- end; | |
5923 | ||
5924 | -- In this case the type will be frozen later by the usual | |
5925 | -- mechanism: an object declaration, an instantiation, or the | |
5926 | -- end of a declarative part. | |
5927 | ||
5928 | if Is_Library_Level_Tagged_Type (E) | |
5929 | and then not Present (Full_View (E)) | |
5930 | then | |
5931 | Set_Is_Frozen (E, False); | |
d65a80fd | 5932 | goto Leave; |
86cde7b1 | 5933 | |
70482933 RK |
5934 | -- Case of full view present |
5935 | ||
86cde7b1 | 5936 | elsif Present (Full_View (E)) then |
70482933 | 5937 | |
ee094616 RD |
5938 | -- If full view has already been frozen, then no further |
5939 | -- processing is required | |
70482933 RK |
5940 | |
5941 | if Is_Frozen (Full_View (E)) then | |
70482933 RK |
5942 | Set_Has_Delayed_Freeze (E, False); |
5943 | Set_Freeze_Node (E, Empty); | |
70482933 | 5944 | |
ee094616 | 5945 | -- Otherwise freeze full view and patch the pointers so that |
bf0b0e5e AC |
5946 | -- the freeze node will elaborate both views in the back end. |
5947 | -- However, if full view is itself private, freeze underlying | |
625d8a9f | 5948 | -- full view instead and patch the pointers so that the freeze |
bf0b0e5e | 5949 | -- node will elaborate the three views in the back end. |
70482933 RK |
5950 | |
5951 | else | |
fbf5a39b | 5952 | declare |
bf0b0e5e | 5953 | Full : Entity_Id := Full_View (E); |
70482933 | 5954 | |
fbf5a39b AC |
5955 | begin |
5956 | if Is_Private_Type (Full) | |
5957 | and then Present (Underlying_Full_View (Full)) | |
5958 | then | |
bf0b0e5e | 5959 | Full := Underlying_Full_View (Full); |
fbf5a39b | 5960 | end if; |
70482933 | 5961 | |
c159409f | 5962 | Freeze_And_Append (Full, N, Result); |
70482933 | 5963 | |
bf0b0e5e AC |
5964 | if Full /= Full_View (E) |
5965 | and then Has_Delayed_Freeze (Full_View (E)) | |
5966 | then | |
fbf5a39b | 5967 | F_Node := Freeze_Node (Full); |
70482933 | 5968 | |
bf0b0e5e | 5969 | if Present (F_Node) then |
ce06d641 AC |
5970 | Inherit_Freeze_Node |
5971 | (Fnod => F_Node, | |
5972 | Typ => Full_View (E)); | |
bf0b0e5e AC |
5973 | else |
5974 | Set_Has_Delayed_Freeze (Full_View (E), False); | |
5975 | Set_Freeze_Node (Full_View (E), Empty); | |
5976 | end if; | |
5977 | end if; | |
5978 | ||
5979 | if Has_Delayed_Freeze (E) then | |
5980 | F_Node := Freeze_Node (Full_View (E)); | |
5981 | ||
fbf5a39b | 5982 | if Present (F_Node) then |
ce06d641 AC |
5983 | Inherit_Freeze_Node |
5984 | (Fnod => F_Node, | |
5985 | Typ => E); | |
fbf5a39b | 5986 | else |
def46b54 RD |
5987 | -- {Incomplete,Private}_Subtypes with Full_Views |
5988 | -- constrained by discriminants. | |
fbf5a39b AC |
5989 | |
5990 | Set_Has_Delayed_Freeze (E, False); | |
5991 | Set_Freeze_Node (E, Empty); | |
5992 | end if; | |
70482933 | 5993 | end if; |
fbf5a39b | 5994 | end; |
70482933 RK |
5995 | end if; |
5996 | ||
bf0b0e5e AC |
5997 | Check_Debug_Info_Needed (E); |
5998 | ||
ee094616 RD |
5999 | -- AI-117 requires that the convention of a partial view be the |
6000 | -- same as the convention of the full view. Note that this is a | |
6001 | -- recognized breach of privacy, but it's essential for logical | |
6002 | -- consistency of representation, and the lack of a rule in | |
6003 | -- RM95 was an oversight. | |
70482933 RK |
6004 | |
6005 | Set_Convention (E, Convention (Full_View (E))); | |
6006 | ||
6007 | Set_Size_Known_At_Compile_Time (E, | |
6008 | Size_Known_At_Compile_Time (Full_View (E))); | |
6009 | ||
6010 | -- Size information is copied from the full view to the | |
def46b54 | 6011 | -- incomplete or private view for consistency. |
70482933 | 6012 | |
ee094616 RD |
6013 | -- We skip this is the full view is not a type. This is very |
6014 | -- strange of course, and can only happen as a result of | |
6015 | -- certain illegalities, such as a premature attempt to derive | |
6016 | -- from an incomplete type. | |
70482933 RK |
6017 | |
6018 | if Is_Type (Full_View (E)) then | |
6019 | Set_Size_Info (E, Full_View (E)); | |
6020 | Set_RM_Size (E, RM_Size (Full_View (E))); | |
6021 | end if; | |
6022 | ||
d65a80fd | 6023 | goto Leave; |
70482933 | 6024 | |
bf0b0e5e AC |
6025 | -- Case of underlying full view present |
6026 | ||
6027 | elsif Is_Private_Type (E) | |
6028 | and then Present (Underlying_Full_View (E)) | |
6029 | then | |
6030 | if not Is_Frozen (Underlying_Full_View (E)) then | |
6031 | Freeze_And_Append (Underlying_Full_View (E), N, Result); | |
6032 | end if; | |
6033 | ||
6034 | -- Patch the pointers so that the freeze node will elaborate | |
6035 | -- both views in the back end. | |
6036 | ||
6037 | if Has_Delayed_Freeze (E) then | |
6038 | F_Node := Freeze_Node (Underlying_Full_View (E)); | |
6039 | ||
6040 | if Present (F_Node) then | |
ce06d641 AC |
6041 | Inherit_Freeze_Node |
6042 | (Fnod => F_Node, | |
6043 | Typ => E); | |
bf0b0e5e AC |
6044 | else |
6045 | Set_Has_Delayed_Freeze (E, False); | |
6046 | Set_Freeze_Node (E, Empty); | |
6047 | end if; | |
6048 | end if; | |
6049 | ||
6050 | Check_Debug_Info_Needed (E); | |
6051 | ||
d65a80fd | 6052 | goto Leave; |
bf0b0e5e | 6053 | |
70482933 RK |
6054 | -- Case of no full view present. If entity is derived or subtype, |
6055 | -- it is safe to freeze, correctness depends on the frozen status | |
6056 | -- of parent. Otherwise it is either premature usage, or a Taft | |
6057 | -- amendment type, so diagnosis is at the point of use and the | |
6058 | -- type might be frozen later. | |
6059 | ||
ef1c0511 | 6060 | elsif E /= Base_Type (E) or else Is_Derived_Type (E) then |
70482933 RK |
6061 | null; |
6062 | ||
6063 | else | |
6064 | Set_Is_Frozen (E, False); | |
d65a80fd HK |
6065 | Result := No_List; |
6066 | goto Leave; | |
70482933 RK |
6067 | end if; |
6068 | ||
6069 | -- For access subprogram, freeze types of all formals, the return | |
6070 | -- type was already frozen, since it is the Etype of the function. | |
8aec446b | 6071 | -- Formal types can be tagged Taft amendment types, but otherwise |
205c14b0 | 6072 | -- they cannot be incomplete. |
70482933 RK |
6073 | |
6074 | elsif Ekind (E) = E_Subprogram_Type then | |
6075 | Formal := First_Formal (E); | |
6076 | while Present (Formal) loop | |
8aec446b AC |
6077 | if Ekind (Etype (Formal)) = E_Incomplete_Type |
6078 | and then No (Full_View (Etype (Formal))) | |
8aec446b AC |
6079 | then |
6080 | if Is_Tagged_Type (Etype (Formal)) then | |
6081 | null; | |
dd386db0 | 6082 | |
3cae7f14 | 6083 | -- AI05-151: Incomplete types are allowed in access to |
dd386db0 AC |
6084 | -- subprogram specifications. |
6085 | ||
6086 | elsif Ada_Version < Ada_2012 then | |
8aec446b AC |
6087 | Error_Msg_NE |
6088 | ("invalid use of incomplete type&", E, Etype (Formal)); | |
6089 | end if; | |
6090 | end if; | |
6091 | ||
c159409f | 6092 | Freeze_And_Append (Etype (Formal), N, Result); |
70482933 RK |
6093 | Next_Formal (Formal); |
6094 | end loop; | |
6095 | ||
70482933 RK |
6096 | Freeze_Subprogram (E); |
6097 | ||
ee094616 RD |
6098 | -- For access to a protected subprogram, freeze the equivalent type |
6099 | -- (however this is not set if we are not generating code or if this | |
6100 | -- is an anonymous type used just for resolution). | |
70482933 | 6101 | |
fea9e956 | 6102 | elsif Is_Access_Protected_Subprogram_Type (E) then |
57747aec | 6103 | if Present (Equivalent_Type (E)) then |
c159409f | 6104 | Freeze_And_Append (Equivalent_Type (E), N, Result); |
d8db0bca | 6105 | end if; |
70482933 RK |
6106 | end if; |
6107 | ||
6108 | -- Generic types are never seen by the back-end, and are also not | |
6109 | -- processed by the expander (since the expander is turned off for | |
6110 | -- generic processing), so we never need freeze nodes for them. | |
6111 | ||
6112 | if Is_Generic_Type (E) then | |
d65a80fd | 6113 | goto Leave; |
70482933 RK |
6114 | end if; |
6115 | ||
6116 | -- Some special processing for non-generic types to complete | |
6117 | -- representation details not known till the freeze point. | |
6118 | ||
6119 | if Is_Fixed_Point_Type (E) then | |
6120 | Freeze_Fixed_Point_Type (E); | |
6121 | ||
ee094616 RD |
6122 | -- Some error checks required for ordinary fixed-point type. Defer |
6123 | -- these till the freeze-point since we need the small and range | |
6124 | -- values. We only do these checks for base types | |
fbf5a39b | 6125 | |
d347f572 | 6126 | if Is_Ordinary_Fixed_Point_Type (E) and then Is_Base_Type (E) then |
fbf5a39b AC |
6127 | if Small_Value (E) < Ureal_2_M_80 then |
6128 | Error_Msg_Name_1 := Name_Small; | |
6129 | Error_Msg_N | |
7d8b9c99 | 6130 | ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E); |
fbf5a39b AC |
6131 | |
6132 | elsif Small_Value (E) > Ureal_2_80 then | |
6133 | Error_Msg_Name_1 := Name_Small; | |
6134 | Error_Msg_N | |
7d8b9c99 | 6135 | ("`&''%` too large, maximum allowed is 2.0'*'*80", E); |
fbf5a39b AC |
6136 | end if; |
6137 | ||
6138 | if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then | |
6139 | Error_Msg_Name_1 := Name_First; | |
6140 | Error_Msg_N | |
7d8b9c99 | 6141 | ("`&''%` too small, minimum allowed is -10.0'*'*36", E); |
fbf5a39b AC |
6142 | end if; |
6143 | ||
6144 | if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then | |
6145 | Error_Msg_Name_1 := Name_Last; | |
6146 | Error_Msg_N | |
7d8b9c99 | 6147 | ("`&''%` too large, maximum allowed is 10.0'*'*36", E); |
fbf5a39b AC |
6148 | end if; |
6149 | end if; | |
6150 | ||
70482933 RK |
6151 | elsif Is_Enumeration_Type (E) then |
6152 | Freeze_Enumeration_Type (E); | |
6153 | ||
6154 | elsif Is_Integer_Type (E) then | |
6155 | Adjust_Esize_For_Alignment (E); | |
6156 | ||
79afa047 AC |
6157 | if Is_Modular_Integer_Type (E) |
6158 | and then Warn_On_Suspicious_Modulus_Value | |
6159 | then | |
67b3acf8 RD |
6160 | Check_Suspicious_Modulus (E); |
6161 | end if; | |
6162 | ||
e8de1a82 | 6163 | -- The pool applies to named and anonymous access types, but not |
62a64085 AC |
6164 | -- to subprogram and to internal types generated for 'Access |
6165 | -- references. | |
6166 | ||
ea2af26a AC |
6167 | elsif Is_Access_Type (E) |
6168 | and then not Is_Access_Subprogram_Type (E) | |
62a64085 | 6169 | and then Ekind (E) /= E_Access_Attribute_Type |
ea2af26a | 6170 | then |
fab2daeb AC |
6171 | -- If a pragma Default_Storage_Pool applies, and this type has no |
6172 | -- Storage_Pool or Storage_Size clause (which must have occurred | |
6173 | -- before the freezing point), then use the default. This applies | |
6174 | -- only to base types. | |
a5fe079c AC |
6175 | |
6176 | -- None of this applies to access to subprograms, for which there | |
ea2af26a | 6177 | -- are clearly no pools. |
fab2daeb AC |
6178 | |
6179 | if Present (Default_Pool) | |
d347f572 | 6180 | and then Is_Base_Type (E) |
fab2daeb AC |
6181 | and then not Has_Storage_Size_Clause (E) |
6182 | and then No (Associated_Storage_Pool (E)) | |
6183 | then | |
6184 | -- Case of pragma Default_Storage_Pool (null) | |
6185 | ||
6186 | if Nkind (Default_Pool) = N_Null then | |
6187 | Set_No_Pool_Assigned (E); | |
6188 | ||
6189 | -- Case of pragma Default_Storage_Pool (storage_pool_NAME) | |
6190 | ||
6191 | else | |
6192 | Set_Associated_Storage_Pool (E, Entity (Default_Pool)); | |
6193 | end if; | |
6194 | end if; | |
6195 | ||
edd63e9b ES |
6196 | -- Check restriction for standard storage pool |
6197 | ||
6198 | if No (Associated_Storage_Pool (E)) then | |
6199 | Check_Restriction (No_Standard_Storage_Pools, E); | |
6200 | end if; | |
6201 | ||
6202 | -- Deal with error message for pure access type. This is not an | |
6203 | -- error in Ada 2005 if there is no pool (see AI-366). | |
6204 | ||
6205 | if Is_Pure_Unit_Access_Type (E) | |
0791fbe9 | 6206 | and then (Ada_Version < Ada_2005 |
2c1b72d7 | 6207 | or else not No_Pool_Assigned (E)) |
3cd4a210 | 6208 | and then not Is_Generic_Unit (Scope (E)) |
edd63e9b ES |
6209 | then |
6210 | Error_Msg_N ("named access type not allowed in pure unit", E); | |
c6a9797e | 6211 | |
0791fbe9 | 6212 | if Ada_Version >= Ada_2005 then |
c6a9797e | 6213 | Error_Msg_N |
685bc70f | 6214 | ("\would be legal if Storage_Size of 0 given??", E); |
c6a9797e RD |
6215 | |
6216 | elsif No_Pool_Assigned (E) then | |
6217 | Error_Msg_N | |
685bc70f | 6218 | ("\would be legal in Ada 2005??", E); |
c6a9797e RD |
6219 | |
6220 | else | |
6221 | Error_Msg_N | |
6222 | ("\would be legal in Ada 2005 if " | |
685bc70f | 6223 | & "Storage_Size of 0 given??", E); |
c6a9797e | 6224 | end if; |
edd63e9b | 6225 | end if; |
70482933 RK |
6226 | end if; |
6227 | ||
edd63e9b ES |
6228 | -- Case of composite types |
6229 | ||
70482933 RK |
6230 | if Is_Composite_Type (E) then |
6231 | ||
edd63e9b ES |
6232 | -- AI-117 requires that all new primitives of a tagged type must |
6233 | -- inherit the convention of the full view of the type. Inherited | |
6234 | -- and overriding operations are defined to inherit the convention | |
6235 | -- of their parent or overridden subprogram (also specified in | |
ee094616 RD |
6236 | -- AI-117), which will have occurred earlier (in Derive_Subprogram |
6237 | -- and New_Overloaded_Entity). Here we set the convention of | |
6238 | -- primitives that are still convention Ada, which will ensure | |
def46b54 RD |
6239 | -- that any new primitives inherit the type's convention. Class- |
6240 | -- wide types can have a foreign convention inherited from their | |
6241 | -- specific type, but are excluded from this since they don't have | |
6242 | -- any associated primitives. | |
70482933 RK |
6243 | |
6244 | if Is_Tagged_Type (E) | |
6245 | and then not Is_Class_Wide_Type (E) | |
6246 | and then Convention (E) /= Convention_Ada | |
6247 | then | |
6248 | declare | |
6249 | Prim_List : constant Elist_Id := Primitive_Operations (E); | |
07fc65c4 | 6250 | Prim : Elmt_Id; |
3cae7f14 | 6251 | |
70482933 | 6252 | begin |
07fc65c4 | 6253 | Prim := First_Elmt (Prim_List); |
70482933 RK |
6254 | while Present (Prim) loop |
6255 | if Convention (Node (Prim)) = Convention_Ada then | |
6256 | Set_Convention (Node (Prim), Convention (E)); | |
6257 | end if; | |
6258 | ||
6259 | Next_Elmt (Prim); | |
6260 | end loop; | |
6261 | end; | |
6262 | end if; | |
a8551b5f AC |
6263 | |
6264 | -- If the type is a simple storage pool type, then this is where | |
6265 | -- we attempt to locate and validate its Allocate, Deallocate, and | |
6266 | -- Storage_Size operations (the first is required, and the latter | |
6267 | -- two are optional). We also verify that the full type for a | |
6268 | -- private type is allowed to be a simple storage pool type. | |
6269 | ||
f6205414 | 6270 | if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type)) |
a8551b5f AC |
6271 | and then (Is_Base_Type (E) or else Has_Private_Declaration (E)) |
6272 | then | |
a8551b5f AC |
6273 | -- If the type is marked Has_Private_Declaration, then this is |
6274 | -- a full type for a private type that was specified with the | |
f6205414 | 6275 | -- pragma Simple_Storage_Pool_Type, and here we ensure that the |
a8551b5f AC |
6276 | -- pragma is allowed for the full type (for example, it can't |
6277 | -- be an array type, or a nonlimited record type). | |
6278 | ||
6279 | if Has_Private_Declaration (E) then | |
ef1c0511 | 6280 | if (not Is_Record_Type (E) or else not Is_Limited_View (E)) |
a8551b5f AC |
6281 | and then not Is_Private_Type (E) |
6282 | then | |
f6205414 | 6283 | Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type; |
a8551b5f AC |
6284 | Error_Msg_N |
6285 | ("pragma% can only apply to full type that is an " & | |
6286 | "explicitly limited type", E); | |
6287 | end if; | |
6288 | end if; | |
6289 | ||
6290 | Validate_Simple_Pool_Ops : declare | |
6291 | Pool_Type : Entity_Id renames E; | |
6292 | Address_Type : constant Entity_Id := RTE (RE_Address); | |
6293 | Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count); | |
6294 | ||
6295 | procedure Validate_Simple_Pool_Op_Formal | |
6296 | (Pool_Op : Entity_Id; | |
6297 | Pool_Op_Formal : in out Entity_Id; | |
6298 | Expected_Mode : Formal_Kind; | |
6299 | Expected_Type : Entity_Id; | |
6300 | Formal_Name : String; | |
6301 | OK_Formal : in out Boolean); | |
6302 | -- Validate one formal Pool_Op_Formal of the candidate pool | |
6303 | -- operation Pool_Op. The formal must be of Expected_Type | |
6304 | -- and have mode Expected_Mode. OK_Formal will be set to | |
6305 | -- False if the formal doesn't match. If OK_Formal is False | |
6306 | -- on entry, then the formal will effectively be ignored | |
6307 | -- (because validation of the pool op has already failed). | |
6308 | -- Upon return, Pool_Op_Formal will be updated to the next | |
6309 | -- formal, if any. | |
6310 | ||
ef1c0511 AC |
6311 | procedure Validate_Simple_Pool_Operation |
6312 | (Op_Name : Name_Id); | |
a8551b5f AC |
6313 | -- Search for and validate a simple pool operation with the |
6314 | -- name Op_Name. If the name is Allocate, then there must be | |
6315 | -- exactly one such primitive operation for the simple pool | |
6316 | -- type. If the name is Deallocate or Storage_Size, then | |
6317 | -- there can be at most one such primitive operation. The | |
6318 | -- profile of the located primitive must conform to what | |
6319 | -- is expected for each operation. | |
6320 | ||
6321 | ------------------------------------ | |
6322 | -- Validate_Simple_Pool_Op_Formal -- | |
6323 | ------------------------------------ | |
6324 | ||
6325 | procedure Validate_Simple_Pool_Op_Formal | |
6326 | (Pool_Op : Entity_Id; | |
6327 | Pool_Op_Formal : in out Entity_Id; | |
6328 | Expected_Mode : Formal_Kind; | |
6329 | Expected_Type : Entity_Id; | |
6330 | Formal_Name : String; | |
6331 | OK_Formal : in out Boolean) | |
6332 | is | |
6333 | begin | |
6334 | -- If OK_Formal is False on entry, then simply ignore | |
6335 | -- the formal, because an earlier formal has already | |
6336 | -- been flagged. | |
6337 | ||
6338 | if not OK_Formal then | |
6339 | return; | |
6340 | ||
6341 | -- If no formal is passed in, then issue an error for a | |
6342 | -- missing formal. | |
6343 | ||
6344 | elsif not Present (Pool_Op_Formal) then | |
6345 | Error_Msg_NE | |
6346 | ("simple storage pool op missing formal " & | |
6347 | Formal_Name & " of type&", Pool_Op, Expected_Type); | |
6348 | OK_Formal := False; | |
6349 | ||
6350 | return; | |
6351 | end if; | |
6352 | ||
6353 | if Etype (Pool_Op_Formal) /= Expected_Type then | |
260359e3 | 6354 | |
a8551b5f AC |
6355 | -- If the pool type was expected for this formal, then |
6356 | -- this will not be considered a candidate operation | |
6357 | -- for the simple pool, so we unset OK_Formal so that | |
6358 | -- the op and any later formals will be ignored. | |
6359 | ||
6360 | if Expected_Type = Pool_Type then | |
6361 | OK_Formal := False; | |
6362 | ||
6363 | return; | |
6364 | ||
6365 | else | |
6366 | Error_Msg_NE | |
6367 | ("wrong type for formal " & Formal_Name & | |
6368 | " of simple storage pool op; expected type&", | |
6369 | Pool_Op_Formal, Expected_Type); | |
6370 | end if; | |
6371 | end if; | |
6372 | ||
6373 | -- Issue error if formal's mode is not the expected one | |
6374 | ||
6375 | if Ekind (Pool_Op_Formal) /= Expected_Mode then | |
6376 | Error_Msg_N | |
6377 | ("wrong mode for formal of simple storage pool op", | |
6378 | Pool_Op_Formal); | |
6379 | end if; | |
6380 | ||
6381 | -- Advance to the next formal | |
6382 | ||
6383 | Next_Formal (Pool_Op_Formal); | |
6384 | end Validate_Simple_Pool_Op_Formal; | |
6385 | ||
6386 | ------------------------------------ | |
6387 | -- Validate_Simple_Pool_Operation -- | |
6388 | ------------------------------------ | |
6389 | ||
6390 | procedure Validate_Simple_Pool_Operation | |
6391 | (Op_Name : Name_Id) | |
6392 | is | |
6393 | Op : Entity_Id; | |
6394 | Found_Op : Entity_Id := Empty; | |
6395 | Formal : Entity_Id; | |
6396 | Is_OK : Boolean; | |
6397 | ||
6398 | begin | |
6399 | pragma Assert | |
b69cd36a AC |
6400 | (Nam_In (Op_Name, Name_Allocate, |
6401 | Name_Deallocate, | |
6402 | Name_Storage_Size)); | |
a8551b5f AC |
6403 | |
6404 | Error_Msg_Name_1 := Op_Name; | |
6405 | ||
6406 | -- For each homonym declared immediately in the scope | |
6407 | -- of the simple storage pool type, determine whether | |
6408 | -- the homonym is an operation of the pool type, and, | |
6409 | -- if so, check that its profile is as expected for | |
6410 | -- a simple pool operation of that name. | |
6411 | ||
6412 | Op := Get_Name_Entity_Id (Op_Name); | |
6413 | while Present (Op) loop | |
6414 | if Ekind_In (Op, E_Function, E_Procedure) | |
6415 | and then Scope (Op) = Current_Scope | |
6416 | then | |
6417 | Formal := First_Entity (Op); | |
6418 | ||
6419 | Is_OK := True; | |
6420 | ||
6421 | -- The first parameter must be of the pool type | |
6422 | -- in order for the operation to qualify. | |
6423 | ||
6424 | if Op_Name = Name_Storage_Size then | |
6425 | Validate_Simple_Pool_Op_Formal | |
6426 | (Op, Formal, E_In_Parameter, Pool_Type, | |
6427 | "Pool", Is_OK); | |
a8551b5f AC |
6428 | else |
6429 | Validate_Simple_Pool_Op_Formal | |
6430 | (Op, Formal, E_In_Out_Parameter, Pool_Type, | |
6431 | "Pool", Is_OK); | |
6432 | end if; | |
6433 | ||
6434 | -- If another operation with this name has already | |
6435 | -- been located for the type, then flag an error, | |
6436 | -- since we only allow the type to have a single | |
6437 | -- such primitive. | |
6438 | ||
6439 | if Present (Found_Op) and then Is_OK then | |
6440 | Error_Msg_NE | |
6441 | ("only one % operation allowed for " & | |
6442 | "simple storage pool type&", Op, Pool_Type); | |
6443 | end if; | |
6444 | ||
6445 | -- In the case of Allocate and Deallocate, a formal | |
6446 | -- of type System.Address is required. | |
6447 | ||
6448 | if Op_Name = Name_Allocate then | |
6449 | Validate_Simple_Pool_Op_Formal | |
6450 | (Op, Formal, E_Out_Parameter, | |
b69cd36a AC |
6451 | Address_Type, "Storage_Address", Is_OK); |
6452 | ||
a8551b5f AC |
6453 | elsif Op_Name = Name_Deallocate then |
6454 | Validate_Simple_Pool_Op_Formal | |
6455 | (Op, Formal, E_In_Parameter, | |
6456 | Address_Type, "Storage_Address", Is_OK); | |
6457 | end if; | |
6458 | ||
6459 | -- In the case of Allocate and Deallocate, formals | |
6460 | -- of type Storage_Count are required as the third | |
6461 | -- and fourth parameters. | |
6462 | ||
6463 | if Op_Name /= Name_Storage_Size then | |
6464 | Validate_Simple_Pool_Op_Formal | |
6465 | (Op, Formal, E_In_Parameter, | |
6466 | Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK); | |
a8551b5f AC |
6467 | Validate_Simple_Pool_Op_Formal |
6468 | (Op, Formal, E_In_Parameter, | |
6469 | Stg_Cnt_Type, "Alignment", Is_OK); | |
6470 | end if; | |
6471 | ||
6472 | -- If no mismatched formals have been found (Is_OK) | |
6473 | -- and no excess formals are present, then this | |
6474 | -- operation has been validated, so record it. | |
6475 | ||
6476 | if not Present (Formal) and then Is_OK then | |
6477 | Found_Op := Op; | |
6478 | end if; | |
6479 | end if; | |
6480 | ||
6481 | Op := Homonym (Op); | |
6482 | end loop; | |
6483 | ||
6484 | -- There must be a valid Allocate operation for the type, | |
6485 | -- so issue an error if none was found. | |
6486 | ||
6487 | if Op_Name = Name_Allocate | |
6488 | and then not Present (Found_Op) | |
6489 | then | |
6490 | Error_Msg_N ("missing % operation for simple " & | |
6491 | "storage pool type", Pool_Type); | |
6492 | ||
6493 | elsif Present (Found_Op) then | |
260359e3 | 6494 | |
a8551b5f AC |
6495 | -- Simple pool operations can't be abstract |
6496 | ||
6497 | if Is_Abstract_Subprogram (Found_Op) then | |
6498 | Error_Msg_N | |
6499 | ("simple storage pool operation must not be " & | |
6500 | "abstract", Found_Op); | |
6501 | end if; | |
6502 | ||
6503 | -- The Storage_Size operation must be a function with | |
6504 | -- Storage_Count as its result type. | |
6505 | ||
6506 | if Op_Name = Name_Storage_Size then | |
6507 | if Ekind (Found_Op) = E_Procedure then | |
6508 | Error_Msg_N | |
6509 | ("% operation must be a function", Found_Op); | |
6510 | ||
6511 | elsif Etype (Found_Op) /= Stg_Cnt_Type then | |
6512 | Error_Msg_NE | |
6513 | ("wrong result type for%, expected type&", | |
6514 | Found_Op, Stg_Cnt_Type); | |
6515 | end if; | |
6516 | ||
6517 | -- Allocate and Deallocate must be procedures | |
6518 | ||
6519 | elsif Ekind (Found_Op) = E_Function then | |
6520 | Error_Msg_N | |
6521 | ("% operation must be a procedure", Found_Op); | |
6522 | end if; | |
6523 | end if; | |
6524 | end Validate_Simple_Pool_Operation; | |
6525 | ||
6526 | -- Start of processing for Validate_Simple_Pool_Ops | |
6527 | ||
6528 | begin | |
6529 | Validate_Simple_Pool_Operation (Name_Allocate); | |
a8551b5f | 6530 | Validate_Simple_Pool_Operation (Name_Deallocate); |
a8551b5f AC |
6531 | Validate_Simple_Pool_Operation (Name_Storage_Size); |
6532 | end Validate_Simple_Pool_Ops; | |
6533 | end if; | |
70482933 RK |
6534 | end if; |
6535 | ||
ee094616 RD |
6536 | -- Now that all types from which E may depend are frozen, see if the |
6537 | -- size is known at compile time, if it must be unsigned, or if | |
7d8b9c99 | 6538 | -- strict alignment is required |
70482933 RK |
6539 | |
6540 | Check_Compile_Time_Size (E); | |
6541 | Check_Unsigned_Type (E); | |
6542 | ||
6543 | if Base_Type (E) = E then | |
6544 | Check_Strict_Alignment (E); | |
6545 | end if; | |
6546 | ||
6547 | -- Do not allow a size clause for a type which does not have a size | |
6548 | -- that is known at compile time | |
6549 | ||
6550 | if Has_Size_Clause (E) | |
6551 | and then not Size_Known_At_Compile_Time (E) | |
6552 | then | |
e14c931f | 6553 | -- Suppress this message if errors posted on E, even if we are |
07fc65c4 GB |
6554 | -- in all errors mode, since this is often a junk message |
6555 | ||
6556 | if not Error_Posted (E) then | |
6557 | Error_Msg_N | |
6558 | ("size clause not allowed for variable length type", | |
6559 | Size_Clause (E)); | |
6560 | end if; | |
70482933 RK |
6561 | end if; |
6562 | ||
a01b9df6 AC |
6563 | -- Now we set/verify the representation information, in particular |
6564 | -- the size and alignment values. This processing is not required for | |
6565 | -- generic types, since generic types do not play any part in code | |
6566 | -- generation, and so the size and alignment values for such types | |
84c4181d AC |
6567 | -- are irrelevant. Ditto for types declared within a generic unit, |
6568 | -- which may have components that depend on generic parameters, and | |
6569 | -- that will be recreated in an instance. | |
70482933 | 6570 | |
84c4181d AC |
6571 | if Inside_A_Generic then |
6572 | null; | |
70482933 RK |
6573 | |
6574 | -- Otherwise we call the layout procedure | |
6575 | ||
6576 | else | |
6577 | Layout_Type (E); | |
6578 | end if; | |
a01b9df6 | 6579 | |
cc570be6 AC |
6580 | -- If this is an access to subprogram whose designated type is itself |
6581 | -- a subprogram type, the return type of this anonymous subprogram | |
6582 | -- type must be decorated as well. | |
6583 | ||
6584 | if Ekind (E) = E_Anonymous_Access_Subprogram_Type | |
6585 | and then Ekind (Designated_Type (E)) = E_Subprogram_Type | |
6586 | then | |
6587 | Layout_Type (Etype (Designated_Type (E))); | |
6588 | end if; | |
6589 | ||
a01b9df6 AC |
6590 | -- If the type has a Defaut_Value/Default_Component_Value aspect, |
6591 | -- this is where we analye the expression (after the type is frozen, | |
6592 | -- since in the case of Default_Value, we are analyzing with the | |
6593 | -- type itself, and we treat Default_Component_Value similarly for | |
1b73408a | 6594 | -- the sake of uniformity). |
a01b9df6 AC |
6595 | |
6596 | if Is_First_Subtype (E) and then Has_Default_Aspect (E) then | |
6597 | declare | |
37da997b RD |
6598 | Nam : Name_Id; |
6599 | Exp : Node_Id; | |
6600 | Typ : Entity_Id; | |
a01b9df6 AC |
6601 | |
6602 | begin | |
6603 | if Is_Scalar_Type (E) then | |
6604 | Nam := Name_Default_Value; | |
6605 | Typ := E; | |
6d9e03cb | 6606 | Exp := Default_Aspect_Value (Typ); |
a01b9df6 AC |
6607 | else |
6608 | Nam := Name_Default_Component_Value; | |
6609 | Typ := Component_Type (E); | |
37da997b | 6610 | Exp := Default_Aspect_Component_Value (E); |
a01b9df6 AC |
6611 | end if; |
6612 | ||
a01b9df6 AC |
6613 | Analyze_And_Resolve (Exp, Typ); |
6614 | ||
6615 | if Etype (Exp) /= Any_Type then | |
edab6088 | 6616 | if not Is_OK_Static_Expression (Exp) then |
a01b9df6 AC |
6617 | Error_Msg_Name_1 := Nam; |
6618 | Flag_Non_Static_Expr | |
6619 | ("aspect% requires static expression", Exp); | |
6620 | end if; | |
6621 | end if; | |
6622 | end; | |
6623 | end if; | |
70482933 RK |
6624 | |
6625 | -- End of freeze processing for type entities | |
6626 | end if; | |
6627 | ||
6628 | -- Here is where we logically freeze the current entity. If it has a | |
6629 | -- freeze node, then this is the point at which the freeze node is | |
6630 | -- linked into the result list. | |
6631 | ||
6632 | if Has_Delayed_Freeze (E) then | |
6633 | ||
6634 | -- If a freeze node is already allocated, use it, otherwise allocate | |
6635 | -- a new one. The preallocation happens in the case of anonymous base | |
6636 | -- types, where we preallocate so that we can set First_Subtype_Link. | |
6637 | -- Note that we reset the Sloc to the current freeze location. | |
6638 | ||
6639 | if Present (Freeze_Node (E)) then | |
6640 | F_Node := Freeze_Node (E); | |
6641 | Set_Sloc (F_Node, Loc); | |
6642 | ||
6643 | else | |
d65a80fd | 6644 | F_Node := New_Node (N_Freeze_Entity, Loc); |
70482933 RK |
6645 | Set_Freeze_Node (E, F_Node); |
6646 | Set_Access_Types_To_Process (F_Node, No_Elist); | |
6647 | Set_TSS_Elist (F_Node, No_Elist); | |
6648 | Set_Actions (F_Node, No_List); | |
6649 | end if; | |
6650 | ||
6651 | Set_Entity (F_Node, E); | |
90878b12 | 6652 | Add_To_Result (F_Node); |
35ae2ed8 AC |
6653 | |
6654 | -- A final pass over record types with discriminants. If the type | |
6655 | -- has an incomplete declaration, there may be constrained access | |
6656 | -- subtypes declared elsewhere, which do not depend on the discrimi- | |
6657 | -- nants of the type, and which are used as component types (i.e. | |
6658 | -- the full view is a recursive type). The designated types of these | |
6659 | -- subtypes can only be elaborated after the type itself, and they | |
6660 | -- need an itype reference. | |
6661 | ||
0d66b596 | 6662 | if Ekind (E) = E_Record_Type and then Has_Discriminants (E) then |
35ae2ed8 AC |
6663 | declare |
6664 | Comp : Entity_Id; | |
6665 | IR : Node_Id; | |
6666 | Typ : Entity_Id; | |
6667 | ||
6668 | begin | |
6669 | Comp := First_Component (E); | |
35ae2ed8 AC |
6670 | while Present (Comp) loop |
6671 | Typ := Etype (Comp); | |
6672 | ||
6673 | if Ekind (Comp) = E_Component | |
6674 | and then Is_Access_Type (Typ) | |
6675 | and then Scope (Typ) /= E | |
6676 | and then Base_Type (Designated_Type (Typ)) = E | |
6677 | and then Is_Itype (Designated_Type (Typ)) | |
6678 | then | |
6679 | IR := Make_Itype_Reference (Sloc (Comp)); | |
6680 | Set_Itype (IR, Designated_Type (Typ)); | |
6681 | Append (IR, Result); | |
6682 | end if; | |
6683 | ||
6684 | Next_Component (Comp); | |
6685 | end loop; | |
6686 | end; | |
6687 | end if; | |
70482933 RK |
6688 | end if; |
6689 | ||
6690 | -- When a type is frozen, the first subtype of the type is frozen as | |
6691 | -- well (RM 13.14(15)). This has to be done after freezing the type, | |
6692 | -- since obviously the first subtype depends on its own base type. | |
6693 | ||
6694 | if Is_Type (E) then | |
c159409f | 6695 | Freeze_And_Append (First_Subtype (E), N, Result); |
70482933 RK |
6696 | |
6697 | -- If we just froze a tagged non-class wide record, then freeze the | |
6698 | -- corresponding class-wide type. This must be done after the tagged | |
6699 | -- type itself is frozen, because the class-wide type refers to the | |
6700 | -- tagged type which generates the class. | |
6701 | ||
6702 | if Is_Tagged_Type (E) | |
6703 | and then not Is_Class_Wide_Type (E) | |
6704 | and then Present (Class_Wide_Type (E)) | |
6705 | then | |
c159409f | 6706 | Freeze_And_Append (Class_Wide_Type (E), N, Result); |
70482933 RK |
6707 | end if; |
6708 | end if; | |
6709 | ||
6710 | Check_Debug_Info_Needed (E); | |
6711 | ||
6712 | -- Special handling for subprograms | |
6713 | ||
6714 | if Is_Subprogram (E) then | |
6715 | ||
6716 | -- If subprogram has address clause then reset Is_Public flag, since | |
6717 | -- we do not want the backend to generate external references. | |
6718 | ||
6719 | if Present (Address_Clause (E)) | |
6720 | and then not Is_Library_Level_Entity (E) | |
6721 | then | |
6722 | Set_Is_Public (E, False); | |
70482933 | 6723 | end if; |
70482933 RK |
6724 | end if; |
6725 | ||
d65a80fd | 6726 | <<Leave>> |
f9a8f910 HK |
6727 | Restore_Ghost_Mode (Saved_GM); |
6728 | ||
70482933 RK |
6729 | return Result; |
6730 | end Freeze_Entity; | |
6731 | ||
6732 | ----------------------------- | |
6733 | -- Freeze_Enumeration_Type -- | |
6734 | ----------------------------- | |
6735 | ||
6736 | procedure Freeze_Enumeration_Type (Typ : Entity_Id) is | |
6737 | begin | |
d677afa9 ES |
6738 | -- By default, if no size clause is present, an enumeration type with |
6739 | -- Convention C is assumed to interface to a C enum, and has integer | |
6740 | -- size. This applies to types. For subtypes, verify that its base | |
be482a8c AC |
6741 | -- type has no size clause either. Treat other foreign conventions |
6742 | -- in the same way, and also make sure alignment is set right. | |
d677afa9 | 6743 | |
70482933 RK |
6744 | if Has_Foreign_Convention (Typ) |
6745 | and then not Has_Size_Clause (Typ) | |
d677afa9 | 6746 | and then not Has_Size_Clause (Base_Type (Typ)) |
70482933 | 6747 | and then Esize (Typ) < Standard_Integer_Size |
d0ef7921 AC |
6748 | |
6749 | -- Don't do this if Short_Enums on target | |
6750 | ||
f27ad2b2 | 6751 | and then not Target_Short_Enums |
70482933 RK |
6752 | then |
6753 | Init_Esize (Typ, Standard_Integer_Size); | |
be482a8c | 6754 | Set_Alignment (Typ, Alignment (Standard_Integer)); |
d677afa9 | 6755 | |
d0ef7921 AC |
6756 | -- Normal Ada case or size clause present or not Long_C_Enums on target |
6757 | ||
70482933 | 6758 | else |
d677afa9 ES |
6759 | -- If the enumeration type interfaces to C, and it has a size clause |
6760 | -- that specifies less than int size, it warrants a warning. The | |
6761 | -- user may intend the C type to be an enum or a char, so this is | |
6762 | -- not by itself an error that the Ada compiler can detect, but it | |
6763 | -- it is a worth a heads-up. For Boolean and Character types we | |
6764 | -- assume that the programmer has the proper C type in mind. | |
6765 | ||
6766 | if Convention (Typ) = Convention_C | |
6767 | and then Has_Size_Clause (Typ) | |
6768 | and then Esize (Typ) /= Esize (Standard_Integer) | |
6769 | and then not Is_Boolean_Type (Typ) | |
6770 | and then not Is_Character_Type (Typ) | |
d0ef7921 AC |
6771 | |
6772 | -- Don't do this if Short_Enums on target | |
6773 | ||
f27ad2b2 | 6774 | and then not Target_Short_Enums |
d677afa9 ES |
6775 | then |
6776 | Error_Msg_N | |
685bc70f | 6777 | ("C enum types have the size of a C int??", Size_Clause (Typ)); |
d677afa9 ES |
6778 | end if; |
6779 | ||
70482933 RK |
6780 | Adjust_Esize_For_Alignment (Typ); |
6781 | end if; | |
6782 | end Freeze_Enumeration_Type; | |
6783 | ||
6784 | ----------------------- | |
6785 | -- Freeze_Expression -- | |
6786 | ----------------------- | |
6787 | ||
6788 | procedure Freeze_Expression (N : Node_Id) is | |
c6a9797e RD |
6789 | In_Spec_Exp : constant Boolean := In_Spec_Expression; |
6790 | Typ : Entity_Id; | |
6791 | Nam : Entity_Id; | |
6792 | Desig_Typ : Entity_Id; | |
6793 | P : Node_Id; | |
6794 | Parent_P : Node_Id; | |
70482933 RK |
6795 | |
6796 | Freeze_Outside : Boolean := False; | |
6797 | -- This flag is set true if the entity must be frozen outside the | |
6798 | -- current subprogram. This happens in the case of expander generated | |
6799 | -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do | |
6800 | -- not freeze all entities like other bodies, but which nevertheless | |
6801 | -- may reference entities that have to be frozen before the body and | |
6802 | -- obviously cannot be frozen inside the body. | |
6803 | ||
dc06dd83 AC |
6804 | function Find_Aggregate_Component_Desig_Type return Entity_Id; |
6805 | -- If the expression is an array aggregate, the type of the component | |
6806 | -- expressions is also frozen. If the component type is an access type | |
6807 | -- and the expressions include allocators, the designed type is frozen | |
6808 | -- as well. | |
6809 | ||
3ad33e33 | 6810 | function In_Expanded_Body (N : Node_Id) return Boolean; |
70482933 | 6811 | -- Given an N_Handled_Sequence_Of_Statements node N, determines whether |
c6823a20 | 6812 | -- it is the handled statement sequence of an expander-generated |
7d8b9c99 RD |
6813 | -- subprogram (init proc, stream subprogram, or renaming as body). |
6814 | -- If so, this is not a freezing context. | |
70482933 | 6815 | |
dc06dd83 AC |
6816 | ----------------------------------------- |
6817 | -- Find_Aggregate_Component_Desig_Type -- | |
6818 | ----------------------------------------- | |
6819 | ||
6820 | function Find_Aggregate_Component_Desig_Type return Entity_Id is | |
6821 | Assoc : Node_Id; | |
6822 | Exp : Node_Id; | |
6823 | ||
6824 | begin | |
6825 | if Present (Expressions (N)) then | |
6826 | Exp := First (Expressions (N)); | |
6827 | while Present (Exp) loop | |
6828 | if Nkind (Exp) = N_Allocator then | |
6829 | return Designated_Type (Component_Type (Etype (N))); | |
6830 | end if; | |
6831 | ||
6832 | Next (Exp); | |
6833 | end loop; | |
6834 | end if; | |
6835 | ||
6836 | if Present (Component_Associations (N)) then | |
6837 | Assoc := First (Component_Associations (N)); | |
6838 | while Present (Assoc) loop | |
6839 | if Nkind (Expression (Assoc)) = N_Allocator then | |
6840 | return Designated_Type (Component_Type (Etype (N))); | |
6841 | end if; | |
6842 | ||
6843 | Next (Assoc); | |
6844 | end loop; | |
6845 | end if; | |
6846 | ||
6847 | return Empty; | |
6848 | end Find_Aggregate_Component_Desig_Type; | |
6849 | ||
3ad33e33 AC |
6850 | ---------------------- |
6851 | -- In_Expanded_Body -- | |
6852 | ---------------------- | |
fbf5a39b | 6853 | |
3ad33e33 | 6854 | function In_Expanded_Body (N : Node_Id) return Boolean is |
7d8b9c99 RD |
6855 | P : Node_Id; |
6856 | Id : Entity_Id; | |
70482933 RK |
6857 | |
6858 | begin | |
6859 | if Nkind (N) = N_Subprogram_Body then | |
6860 | P := N; | |
6861 | else | |
6862 | P := Parent (N); | |
6863 | end if; | |
6864 | ||
6865 | if Nkind (P) /= N_Subprogram_Body then | |
6866 | return False; | |
6867 | ||
6868 | else | |
7d8b9c99 RD |
6869 | Id := Defining_Unit_Name (Specification (P)); |
6870 | ||
3ad33e33 AC |
6871 | -- The following are expander-created bodies, or bodies that |
6872 | -- are not freeze points. | |
21791d97 | 6873 | |
7d8b9c99 | 6874 | if Nkind (Id) = N_Defining_Identifier |
21791d97 AC |
6875 | and then (Is_Init_Proc (Id) |
6876 | or else Is_TSS (Id, TSS_Stream_Input) | |
6877 | or else Is_TSS (Id, TSS_Stream_Output) | |
6878 | or else Is_TSS (Id, TSS_Stream_Read) | |
6879 | or else Is_TSS (Id, TSS_Stream_Write) | |
6880 | or else Nkind_In (Original_Node (P), | |
6881 | N_Subprogram_Renaming_Declaration, | |
6882 | N_Expression_Function)) | |
70482933 RK |
6883 | then |
6884 | return True; | |
6885 | else | |
6886 | return False; | |
6887 | end if; | |
6888 | end if; | |
3ad33e33 | 6889 | end In_Expanded_Body; |
70482933 RK |
6890 | |
6891 | -- Start of processing for Freeze_Expression | |
6892 | ||
6893 | begin | |
edd63e9b ES |
6894 | -- Immediate return if freezing is inhibited. This flag is set by the |
6895 | -- analyzer to stop freezing on generated expressions that would cause | |
6896 | -- freezing if they were in the source program, but which are not | |
6897 | -- supposed to freeze, since they are created. | |
70482933 RK |
6898 | |
6899 | if Must_Not_Freeze (N) then | |
6900 | return; | |
6901 | end if; | |
6902 | ||
6903 | -- If expression is non-static, then it does not freeze in a default | |
6904 | -- expression, see section "Handling of Default Expressions" in the | |
fe58fea7 AC |
6905 | -- spec of package Sem for further details. Note that we have to make |
6906 | -- sure that we actually have a real expression (if we have a subtype | |
edab6088 RD |
6907 | -- indication, we can't test Is_OK_Static_Expression). However, we |
6908 | -- exclude the case of the prefix of an attribute of a static scalar | |
6909 | -- subtype from this early return, because static subtype attributes | |
6910 | -- should always cause freezing, even in default expressions, but | |
6911 | -- the attribute may not have been marked as static yet (because in | |
6912 | -- Resolve_Attribute, the call to Eval_Attribute follows the call of | |
6913 | -- Freeze_Expression on the prefix). | |
70482933 | 6914 | |
c6a9797e | 6915 | if In_Spec_Exp |
70482933 | 6916 | and then Nkind (N) in N_Subexpr |
edab6088 | 6917 | and then not Is_OK_Static_Expression (N) |
fe58fea7 AC |
6918 | and then (Nkind (Parent (N)) /= N_Attribute_Reference |
6919 | or else not (Is_Entity_Name (N) | |
6920 | and then Is_Type (Entity (N)) | |
edab6088 | 6921 | and then Is_OK_Static_Subtype (Entity (N)))) |
70482933 RK |
6922 | then |
6923 | return; | |
6924 | end if; | |
6925 | ||
6926 | -- Freeze type of expression if not frozen already | |
6927 | ||
fbf5a39b AC |
6928 | Typ := Empty; |
6929 | ||
6930 | if Nkind (N) in N_Has_Etype then | |
6931 | if not Is_Frozen (Etype (N)) then | |
6932 | Typ := Etype (N); | |
6933 | ||
6934 | -- Base type may be an derived numeric type that is frozen at | |
6935 | -- the point of declaration, but first_subtype is still unfrozen. | |
6936 | ||
6937 | elsif not Is_Frozen (First_Subtype (Etype (N))) then | |
6938 | Typ := First_Subtype (Etype (N)); | |
6939 | end if; | |
70482933 RK |
6940 | end if; |
6941 | ||
6942 | -- For entity name, freeze entity if not frozen already. A special | |
6943 | -- exception occurs for an identifier that did not come from source. | |
6944 | -- We don't let such identifiers freeze a non-internal entity, i.e. | |
6945 | -- an entity that did come from source, since such an identifier was | |
6946 | -- generated by the expander, and cannot have any semantic effect on | |
6947 | -- the freezing semantics. For example, this stops the parameter of | |
6948 | -- an initialization procedure from freezing the variable. | |
6949 | ||
6950 | if Is_Entity_Name (N) | |
6951 | and then not Is_Frozen (Entity (N)) | |
6952 | and then (Nkind (N) /= N_Identifier | |
6953 | or else Comes_From_Source (N) | |
6954 | or else not Comes_From_Source (Entity (N))) | |
6955 | then | |
6956 | Nam := Entity (N); | |
18c56840 ES |
6957 | |
6958 | if Present (Nam) and then Ekind (Nam) = E_Function then | |
6959 | Check_Expression_Function (N, Nam); | |
6960 | end if; | |
6961 | ||
70482933 RK |
6962 | else |
6963 | Nam := Empty; | |
6964 | end if; | |
6965 | ||
49e90211 | 6966 | -- For an allocator freeze designated type if not frozen already |
70482933 | 6967 | |
ee094616 RD |
6968 | -- For an aggregate whose component type is an access type, freeze the |
6969 | -- designated type now, so that its freeze does not appear within the | |
6970 | -- loop that might be created in the expansion of the aggregate. If the | |
6971 | -- designated type is a private type without full view, the expression | |
6972 | -- cannot contain an allocator, so the type is not frozen. | |
70482933 | 6973 | |
7aedb36a AC |
6974 | -- For a function, we freeze the entity when the subprogram declaration |
6975 | -- is frozen, but a function call may appear in an initialization proc. | |
f6cf5b85 | 6976 | -- before the declaration is frozen. We need to generate the extra |
7aedb36a | 6977 | -- formals, if any, to ensure that the expansion of the call includes |
2f4f3f3f AC |
6978 | -- the proper actuals. This only applies to Ada subprograms, not to |
6979 | -- imported ones. | |
7aedb36a | 6980 | |
70482933 | 6981 | Desig_Typ := Empty; |
70482933 | 6982 | |
fbf5a39b | 6983 | case Nkind (N) is |
70482933 RK |
6984 | when N_Allocator => |
6985 | Desig_Typ := Designated_Type (Etype (N)); | |
6986 | ||
6987 | when N_Aggregate => | |
6988 | if Is_Array_Type (Etype (N)) | |
6989 | and then Is_Access_Type (Component_Type (Etype (N))) | |
6990 | then | |
dc06dd83 AC |
6991 | |
6992 | -- Check whether aggregate includes allocators. | |
6993 | ||
6994 | Desig_Typ := Find_Aggregate_Component_Desig_Type; | |
70482933 RK |
6995 | end if; |
6996 | ||
d8f43ee6 HK |
6997 | when N_Indexed_Component |
6998 | | N_Selected_Component | |
6999 | | N_Slice | |
7000 | => | |
70482933 RK |
7001 | if Is_Access_Type (Etype (Prefix (N))) then |
7002 | Desig_Typ := Designated_Type (Etype (Prefix (N))); | |
7003 | end if; | |
7004 | ||
7aedb36a AC |
7005 | when N_Identifier => |
7006 | if Present (Nam) | |
7007 | and then Ekind (Nam) = E_Function | |
7008 | and then Nkind (Parent (N)) = N_Function_Call | |
2f4f3f3f | 7009 | and then Convention (Nam) = Convention_Ada |
7aedb36a AC |
7010 | then |
7011 | Create_Extra_Formals (Nam); | |
7012 | end if; | |
7013 | ||
70482933 RK |
7014 | when others => |
7015 | null; | |
70482933 RK |
7016 | end case; |
7017 | ||
7018 | if Desig_Typ /= Empty | |
7019 | and then (Is_Frozen (Desig_Typ) | |
7020 | or else (not Is_Fully_Defined (Desig_Typ))) | |
7021 | then | |
7022 | Desig_Typ := Empty; | |
7023 | end if; | |
7024 | ||
7025 | -- All done if nothing needs freezing | |
7026 | ||
7027 | if No (Typ) | |
7028 | and then No (Nam) | |
7029 | and then No (Desig_Typ) | |
7030 | then | |
7031 | return; | |
7032 | end if; | |
7033 | ||
f15749aa AC |
7034 | -- Examine the enclosing context by climbing the parent chain. The |
7035 | -- traversal serves two purposes - to detect scenarios where freezeing | |
7036 | -- is not needed and to find the proper insertion point for the freeze | |
7037 | -- nodes. Although somewhat similar to Insert_Actions, this traversal | |
7038 | -- is freezing semantics-sensitive. Inserting freeze nodes blindly in | |
7039 | -- the tree may result in types being frozen too early. | |
70482933 RK |
7040 | |
7041 | P := N; | |
7042 | loop | |
7043 | Parent_P := Parent (P); | |
7044 | ||
ee094616 RD |
7045 | -- If we don't have a parent, then we are not in a well-formed tree. |
7046 | -- This is an unusual case, but there are some legitimate situations | |
7047 | -- in which this occurs, notably when the expressions in the range of | |
7048 | -- a type declaration are resolved. We simply ignore the freeze | |
7049 | -- request in this case. Is this right ??? | |
70482933 RK |
7050 | |
7051 | if No (Parent_P) then | |
7052 | return; | |
7053 | end if; | |
7054 | ||
7055 | -- See if we have got to an appropriate point in the tree | |
7056 | ||
7057 | case Nkind (Parent_P) is | |
7058 | ||
edd63e9b ES |
7059 | -- A special test for the exception of (RM 13.14(8)) for the case |
7060 | -- of per-object expressions (RM 3.8(18)) occurring in component | |
7061 | -- definition or a discrete subtype definition. Note that we test | |
7062 | -- for a component declaration which includes both cases we are | |
7063 | -- interested in, and furthermore the tree does not have explicit | |
7064 | -- nodes for either of these two constructs. | |
70482933 RK |
7065 | |
7066 | when N_Component_Declaration => | |
7067 | ||
7068 | -- The case we want to test for here is an identifier that is | |
7069 | -- a per-object expression, this is either a discriminant that | |
7070 | -- appears in a context other than the component declaration | |
7071 | -- or it is a reference to the type of the enclosing construct. | |
7072 | ||
7073 | -- For either of these cases, we skip the freezing | |
7074 | ||
c6a9797e | 7075 | if not In_Spec_Expression |
70482933 RK |
7076 | and then Nkind (N) = N_Identifier |
7077 | and then (Present (Entity (N))) | |
7078 | then | |
7079 | -- We recognize the discriminant case by just looking for | |
7080 | -- a reference to a discriminant. It can only be one for | |
7081 | -- the enclosing construct. Skip freezing in this case. | |
7082 | ||
7083 | if Ekind (Entity (N)) = E_Discriminant then | |
7084 | return; | |
7085 | ||
7086 | -- For the case of a reference to the enclosing record, | |
7087 | -- (or task or protected type), we look for a type that | |
7088 | -- matches the current scope. | |
7089 | ||
7090 | elsif Entity (N) = Current_Scope then | |
7091 | return; | |
7092 | end if; | |
7093 | end if; | |
7094 | ||
edd63e9b ES |
7095 | -- If we have an enumeration literal that appears as the choice in |
7096 | -- the aggregate of an enumeration representation clause, then | |
7097 | -- freezing does not occur (RM 13.14(10)). | |
70482933 RK |
7098 | |
7099 | when N_Enumeration_Representation_Clause => | |
7100 | ||
7101 | -- The case we are looking for is an enumeration literal | |
7102 | ||
7103 | if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal) | |
7104 | and then Is_Enumeration_Type (Etype (N)) | |
7105 | then | |
7106 | -- If enumeration literal appears directly as the choice, | |
e14c931f | 7107 | -- do not freeze (this is the normal non-overloaded case) |
70482933 RK |
7108 | |
7109 | if Nkind (Parent (N)) = N_Component_Association | |
7110 | and then First (Choices (Parent (N))) = N | |
7111 | then | |
7112 | return; | |
7113 | ||
ee094616 RD |
7114 | -- If enumeration literal appears as the name of function |
7115 | -- which is the choice, then also do not freeze. This | |
7116 | -- happens in the overloaded literal case, where the | |
70482933 RK |
7117 | -- enumeration literal is temporarily changed to a function |
7118 | -- call for overloading analysis purposes. | |
7119 | ||
7120 | elsif Nkind (Parent (N)) = N_Function_Call | |
7121 | and then | |
7122 | Nkind (Parent (Parent (N))) = N_Component_Association | |
7123 | and then | |
7124 | First (Choices (Parent (Parent (N)))) = Parent (N) | |
7125 | then | |
7126 | return; | |
7127 | end if; | |
7128 | end if; | |
7129 | ||
7130 | -- Normally if the parent is a handled sequence of statements, | |
7131 | -- then the current node must be a statement, and that is an | |
7132 | -- appropriate place to insert a freeze node. | |
7133 | ||
7134 | when N_Handled_Sequence_Of_Statements => | |
7135 | ||
edd63e9b ES |
7136 | -- An exception occurs when the sequence of statements is for |
7137 | -- an expander generated body that did not do the usual freeze | |
7138 | -- all operation. In this case we usually want to freeze | |
7139 | -- outside this body, not inside it, and we skip past the | |
7140 | -- subprogram body that we are inside. | |
70482933 | 7141 | |
3ad33e33 | 7142 | if In_Expanded_Body (Parent_P) then |
70482933 RK |
7143 | declare |
7144 | Subp : constant Node_Id := Parent (Parent_P); | |
95081e99 | 7145 | Spec : Entity_Id; |
70482933 RK |
7146 | |
7147 | begin | |
95081e99 AC |
7148 | -- Freeze the entity only when it is declared inside the |
7149 | -- body of the expander generated procedure. This case | |
7150 | -- is recognized by the scope of the entity or its type, | |
7151 | -- which is either the spec for some enclosing body, or | |
7152 | -- (in the case of init_procs, for which there are no | |
7153 | -- separate specs) the current scope. | |
7154 | ||
70482933 | 7155 | if Nkind (Subp) = N_Subprogram_Body then |
95081e99 | 7156 | Spec := Corresponding_Spec (Subp); |
70482933 | 7157 | |
95081e99 | 7158 | if (Present (Typ) and then Scope (Typ) = Spec) |
70482933 | 7159 | or else |
95081e99 | 7160 | (Present (Nam) and then Scope (Nam) = Spec) |
70482933 RK |
7161 | then |
7162 | exit; | |
7163 | ||
7164 | elsif Present (Typ) | |
7165 | and then Scope (Typ) = Current_Scope | |
95081e99 | 7166 | and then Defining_Entity (Subp) = Current_Scope |
70482933 RK |
7167 | then |
7168 | exit; | |
7169 | end if; | |
7170 | end if; | |
70482933 | 7171 | |
95081e99 AC |
7172 | -- An expression function may act as a completion of |
7173 | -- a function declaration. As such, it can reference | |
7174 | -- entities declared between the two views: | |
70482933 | 7175 | |
95081e99 AC |
7176 | -- Hidden []; -- 1 |
7177 | -- function F return ...; | |
7178 | -- private | |
7179 | -- function Hidden return ...; | |
7180 | -- function F return ... is (Hidden); -- 2 | |
7181 | ||
7182 | -- Refering to the example above, freezing the expression | |
7183 | -- of F (2) would place Hidden's freeze node (1) in the | |
7184 | -- wrong place. Avoid explicit freezing and let the usual | |
7185 | -- scenarios do the job - for example, reaching the end | |
3ad33e33 | 7186 | -- of the private declarations, or a call to F. |
95081e99 AC |
7187 | |
7188 | if Nkind (Original_Node (Subp)) = | |
7189 | N_Expression_Function | |
7190 | then | |
7191 | null; | |
7192 | ||
7193 | -- Freeze outside the body | |
7194 | ||
7195 | else | |
7196 | Parent_P := Parent (Parent_P); | |
7197 | Freeze_Outside := True; | |
7198 | end if; | |
7199 | end; | |
70482933 RK |
7200 | |
7201 | -- Here if normal case where we are in handled statement | |
7202 | -- sequence and want to do the insertion right there. | |
7203 | ||
7204 | else | |
7205 | exit; | |
7206 | end if; | |
7207 | ||
ee094616 RD |
7208 | -- If parent is a body or a spec or a block, then the current node |
7209 | -- is a statement or declaration and we can insert the freeze node | |
7210 | -- before it. | |
70482933 | 7211 | |
d8f43ee6 HK |
7212 | when N_Block_Statement |
7213 | | N_Entry_Body | |
7214 | | N_Package_Body | |
7215 | | N_Package_Specification | |
7216 | | N_Protected_Body | |
7217 | | N_Subprogram_Body | |
7218 | | N_Task_Body | |
7219 | => | |
7220 | exit; | |
70482933 RK |
7221 | |
7222 | -- The expander is allowed to define types in any statements list, | |
7223 | -- so any of the following parent nodes also mark a freezing point | |
7224 | -- if the actual node is in a list of statements or declarations. | |
7225 | ||
d8f43ee6 HK |
7226 | when N_Abortable_Part |
7227 | | N_Accept_Alternative | |
7228 | | N_And_Then | |
7229 | | N_Case_Statement_Alternative | |
7230 | | N_Compilation_Unit_Aux | |
7231 | | N_Conditional_Entry_Call | |
7232 | | N_Delay_Alternative | |
7233 | | N_Elsif_Part | |
7234 | | N_Entry_Call_Alternative | |
7235 | | N_Exception_Handler | |
7236 | | N_Extended_Return_Statement | |
7237 | | N_Freeze_Entity | |
7238 | | N_If_Statement | |
7239 | | N_Or_Else | |
7240 | | N_Selective_Accept | |
7241 | | N_Triggering_Alternative | |
7242 | => | |
70482933 RK |
7243 | exit when Is_List_Member (P); |
7244 | ||
33ca2867 AC |
7245 | -- Freeze nodes produced by an expression coming from the Actions |
7246 | -- list of a N_Expression_With_Actions node must remain within the | |
7247 | -- Actions list. Inserting the freeze nodes further up the tree | |
7248 | -- may lead to use before declaration issues in the case of array | |
7249 | -- types. | |
7250 | ||
7251 | when N_Expression_With_Actions => | |
7252 | if Is_List_Member (P) | |
7253 | and then List_Containing (P) = Actions (Parent_P) | |
7254 | then | |
7255 | exit; | |
7256 | end if; | |
7257 | ||
7258 | -- Note: N_Loop_Statement is a special case. A type that appears | |
7259 | -- in the source can never be frozen in a loop (this occurs only | |
7260 | -- because of a loop expanded by the expander), so we keep on | |
7261 | -- going. Otherwise we terminate the search. Same is true of any | |
7262 | -- entity which comes from source. (if they have predefined type, | |
7263 | -- that type does not appear to come from source, but the entity | |
7264 | -- should not be frozen here). | |
70482933 RK |
7265 | |
7266 | when N_Loop_Statement => | |
7267 | exit when not Comes_From_Source (Etype (N)) | |
7268 | and then (No (Nam) or else not Comes_From_Source (Nam)); | |
7269 | ||
7270 | -- For all other cases, keep looking at parents | |
7271 | ||
7272 | when others => | |
7273 | null; | |
7274 | end case; | |
7275 | ||
7276 | -- We fall through the case if we did not yet find the proper | |
a90bd866 | 7277 | -- place in the free for inserting the freeze node, so climb. |
70482933 RK |
7278 | |
7279 | P := Parent_P; | |
7280 | end loop; | |
7281 | ||
edd63e9b ES |
7282 | -- If the expression appears in a record or an initialization procedure, |
7283 | -- the freeze nodes are collected and attached to the current scope, to | |
7284 | -- be inserted and analyzed on exit from the scope, to insure that | |
7285 | -- generated entities appear in the correct scope. If the expression is | |
7286 | -- a default for a discriminant specification, the scope is still void. | |
7287 | -- The expression can also appear in the discriminant part of a private | |
7288 | -- or concurrent type. | |
70482933 | 7289 | |
c6823a20 | 7290 | -- If the expression appears in a constrained subcomponent of an |
edd63e9b ES |
7291 | -- enclosing record declaration, the freeze nodes must be attached to |
7292 | -- the outer record type so they can eventually be placed in the | |
c6823a20 EB |
7293 | -- enclosing declaration list. |
7294 | ||
ee094616 RD |
7295 | -- The other case requiring this special handling is if we are in a |
7296 | -- default expression, since in that case we are about to freeze a | |
7297 | -- static type, and the freeze scope needs to be the outer scope, not | |
7298 | -- the scope of the subprogram with the default parameter. | |
70482933 | 7299 | |
c6a9797e RD |
7300 | -- For default expressions and other spec expressions in generic units, |
7301 | -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of | |
7302 | -- placing them at the proper place, after the generic unit. | |
70482933 | 7303 | |
c6a9797e | 7304 | if (In_Spec_Exp and not Inside_A_Generic) |
70482933 RK |
7305 | or else Freeze_Outside |
7306 | or else (Is_Type (Current_Scope) | |
7307 | and then (not Is_Concurrent_Type (Current_Scope) | |
7308 | or else not Has_Completion (Current_Scope))) | |
7309 | or else Ekind (Current_Scope) = E_Void | |
7310 | then | |
7311 | declare | |
df378148 AC |
7312 | N : constant Node_Id := Current_Scope; |
7313 | Freeze_Nodes : List_Id := No_List; | |
7314 | Pos : Int := Scope_Stack.Last; | |
70482933 RK |
7315 | |
7316 | begin | |
7317 | if Present (Desig_Typ) then | |
c159409f | 7318 | Freeze_And_Append (Desig_Typ, N, Freeze_Nodes); |
70482933 RK |
7319 | end if; |
7320 | ||
7321 | if Present (Typ) then | |
c159409f | 7322 | Freeze_And_Append (Typ, N, Freeze_Nodes); |
70482933 RK |
7323 | end if; |
7324 | ||
7325 | if Present (Nam) then | |
c159409f | 7326 | Freeze_And_Append (Nam, N, Freeze_Nodes); |
70482933 RK |
7327 | end if; |
7328 | ||
c6823a20 | 7329 | -- The current scope may be that of a constrained component of |
df378148 AC |
7330 | -- an enclosing record declaration, or of a loop of an enclosing |
7331 | -- quantified expression, which is above the current scope in the | |
7332 | -- scope stack. Indeed in the context of a quantified expression, | |
7333 | -- a scope is created and pushed above the current scope in order | |
7334 | -- to emulate the loop-like behavior of the quantified expression. | |
6191e212 AC |
7335 | -- If the expression is within a top-level pragma, as for a pre- |
7336 | -- condition on a library-level subprogram, nothing to do. | |
c6823a20 | 7337 | |
6191e212 | 7338 | if not Is_Compilation_Unit (Current_Scope) |
df378148 AC |
7339 | and then (Is_Record_Type (Scope (Current_Scope)) |
7340 | or else Nkind (Parent (Current_Scope)) = | |
21791d97 | 7341 | N_Quantified_Expression) |
6191e212 | 7342 | then |
c6823a20 EB |
7343 | Pos := Pos - 1; |
7344 | end if; | |
7345 | ||
70482933 | 7346 | if Is_Non_Empty_List (Freeze_Nodes) then |
c6823a20 EB |
7347 | if No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then |
7348 | Scope_Stack.Table (Pos).Pending_Freeze_Actions := | |
c159409f | 7349 | Freeze_Nodes; |
70482933 | 7350 | else |
cd5a9750 AC |
7351 | Append_List (Freeze_Nodes, |
7352 | Scope_Stack.Table (Pos).Pending_Freeze_Actions); | |
70482933 RK |
7353 | end if; |
7354 | end if; | |
7355 | end; | |
7356 | ||
7357 | return; | |
7358 | end if; | |
7359 | ||
7360 | -- Now we have the right place to do the freezing. First, a special | |
c6a9797e RD |
7361 | -- adjustment, if we are in spec-expression analysis mode, these freeze |
7362 | -- actions must not be thrown away (normally all inserted actions are | |
7363 | -- thrown away in this mode. However, the freeze actions are from static | |
7364 | -- expressions and one of the important reasons we are doing this | |
ee094616 | 7365 | -- special analysis is to get these freeze actions. Therefore we turn |
c6a9797e | 7366 | -- off the In_Spec_Expression mode to propagate these freeze actions. |
ee094616 | 7367 | -- This also means they get properly analyzed and expanded. |
70482933 | 7368 | |
c6a9797e | 7369 | In_Spec_Expression := False; |
70482933 | 7370 | |
fbf5a39b | 7371 | -- Freeze the designated type of an allocator (RM 13.14(13)) |
70482933 RK |
7372 | |
7373 | if Present (Desig_Typ) then | |
7374 | Freeze_Before (P, Desig_Typ); | |
7375 | end if; | |
7376 | ||
fbf5a39b | 7377 | -- Freeze type of expression (RM 13.14(10)). Note that we took care of |
70482933 RK |
7378 | -- the enumeration representation clause exception in the loop above. |
7379 | ||
7380 | if Present (Typ) then | |
7381 | Freeze_Before (P, Typ); | |
7382 | end if; | |
7383 | ||
fbf5a39b | 7384 | -- Freeze name if one is present (RM 13.14(11)) |
70482933 RK |
7385 | |
7386 | if Present (Nam) then | |
7387 | Freeze_Before (P, Nam); | |
7388 | end if; | |
7389 | ||
c6a9797e RD |
7390 | -- Restore In_Spec_Expression flag |
7391 | ||
7392 | In_Spec_Expression := In_Spec_Exp; | |
70482933 RK |
7393 | end Freeze_Expression; |
7394 | ||
7395 | ----------------------------- | |
7396 | -- Freeze_Fixed_Point_Type -- | |
7397 | ----------------------------- | |
7398 | ||
edd63e9b ES |
7399 | -- Certain fixed-point types and subtypes, including implicit base types |
7400 | -- and declared first subtypes, have not yet set up a range. This is | |
7401 | -- because the range cannot be set until the Small and Size values are | |
7402 | -- known, and these are not known till the type is frozen. | |
70482933 | 7403 | |
edd63e9b ES |
7404 | -- To signal this case, Scalar_Range contains an unanalyzed syntactic range |
7405 | -- whose bounds are unanalyzed real literals. This routine will recognize | |
7406 | -- this case, and transform this range node into a properly typed range | |
7407 | -- with properly analyzed and resolved values. | |
70482933 RK |
7408 | |
7409 | procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is | |
7410 | Rng : constant Node_Id := Scalar_Range (Typ); | |
7411 | Lo : constant Node_Id := Low_Bound (Rng); | |
7412 | Hi : constant Node_Id := High_Bound (Rng); | |
7413 | Btyp : constant Entity_Id := Base_Type (Typ); | |
7414 | Brng : constant Node_Id := Scalar_Range (Btyp); | |
7415 | BLo : constant Node_Id := Low_Bound (Brng); | |
7416 | BHi : constant Node_Id := High_Bound (Brng); | |
7417 | Small : constant Ureal := Small_Value (Typ); | |
7418 | Loval : Ureal; | |
7419 | Hival : Ureal; | |
7420 | Atype : Entity_Id; | |
7421 | ||
4b6f99f5 RD |
7422 | Orig_Lo : Ureal; |
7423 | Orig_Hi : Ureal; | |
7424 | -- Save original bounds (for shaving tests) | |
7425 | ||
70482933 | 7426 | Actual_Size : Nat; |
4b6f99f5 | 7427 | -- Actual size chosen |
70482933 RK |
7428 | |
7429 | function Fsize (Lov, Hiv : Ureal) return Nat; | |
7430 | -- Returns size of type with given bounds. Also leaves these | |
7431 | -- bounds set as the current bounds of the Typ. | |
7432 | ||
0da2c8ac AC |
7433 | ----------- |
7434 | -- Fsize -- | |
7435 | ----------- | |
7436 | ||
70482933 RK |
7437 | function Fsize (Lov, Hiv : Ureal) return Nat is |
7438 | begin | |
7439 | Set_Realval (Lo, Lov); | |
7440 | Set_Realval (Hi, Hiv); | |
7441 | return Minimum_Size (Typ); | |
7442 | end Fsize; | |
7443 | ||
0da2c8ac | 7444 | -- Start of processing for Freeze_Fixed_Point_Type |
70482933 RK |
7445 | |
7446 | begin | |
7447 | -- If Esize of a subtype has not previously been set, set it now | |
7448 | ||
7449 | if Unknown_Esize (Typ) then | |
7450 | Atype := Ancestor_Subtype (Typ); | |
7451 | ||
7452 | if Present (Atype) then | |
fbf5a39b | 7453 | Set_Esize (Typ, Esize (Atype)); |
70482933 | 7454 | else |
fbf5a39b | 7455 | Set_Esize (Typ, Esize (Base_Type (Typ))); |
70482933 RK |
7456 | end if; |
7457 | end if; | |
7458 | ||
ee094616 RD |
7459 | -- Immediate return if the range is already analyzed. This means that |
7460 | -- the range is already set, and does not need to be computed by this | |
7461 | -- routine. | |
70482933 RK |
7462 | |
7463 | if Analyzed (Rng) then | |
7464 | return; | |
7465 | end if; | |
7466 | ||
7467 | -- Immediate return if either of the bounds raises Constraint_Error | |
7468 | ||
7469 | if Raises_Constraint_Error (Lo) | |
7470 | or else Raises_Constraint_Error (Hi) | |
7471 | then | |
7472 | return; | |
7473 | end if; | |
7474 | ||
7475 | Loval := Realval (Lo); | |
7476 | Hival := Realval (Hi); | |
7477 | ||
4b6f99f5 RD |
7478 | Orig_Lo := Loval; |
7479 | Orig_Hi := Hival; | |
7480 | ||
70482933 RK |
7481 | -- Ordinary fixed-point case |
7482 | ||
7483 | if Is_Ordinary_Fixed_Point_Type (Typ) then | |
7484 | ||
7485 | -- For the ordinary fixed-point case, we are allowed to fudge the | |
ee094616 RD |
7486 | -- end-points up or down by small. Generally we prefer to fudge up, |
7487 | -- i.e. widen the bounds for non-model numbers so that the end points | |
7488 | -- are included. However there are cases in which this cannot be | |
7489 | -- done, and indeed cases in which we may need to narrow the bounds. | |
7490 | -- The following circuit makes the decision. | |
70482933 | 7491 | |
ee094616 RD |
7492 | -- Note: our terminology here is that Incl_EP means that the bounds |
7493 | -- are widened by Small if necessary to include the end points, and | |
7494 | -- Excl_EP means that the bounds are narrowed by Small to exclude the | |
7495 | -- end-points if this reduces the size. | |
70482933 RK |
7496 | |
7497 | -- Note that in the Incl case, all we care about is including the | |
7498 | -- end-points. In the Excl case, we want to narrow the bounds as | |
7499 | -- much as permitted by the RM, to give the smallest possible size. | |
7500 | ||
7501 | Fudge : declare | |
7502 | Loval_Incl_EP : Ureal; | |
7503 | Hival_Incl_EP : Ureal; | |
7504 | ||
7505 | Loval_Excl_EP : Ureal; | |
7506 | Hival_Excl_EP : Ureal; | |
7507 | ||
7508 | Size_Incl_EP : Nat; | |
7509 | Size_Excl_EP : Nat; | |
7510 | ||
7511 | Model_Num : Ureal; | |
7512 | First_Subt : Entity_Id; | |
7513 | Actual_Lo : Ureal; | |
7514 | Actual_Hi : Ureal; | |
7515 | ||
7516 | begin | |
7517 | -- First step. Base types are required to be symmetrical. Right | |
7518 | -- now, the base type range is a copy of the first subtype range. | |
7519 | -- This will be corrected before we are done, but right away we | |
7520 | -- need to deal with the case where both bounds are non-negative. | |
7521 | -- In this case, we set the low bound to the negative of the high | |
7522 | -- bound, to make sure that the size is computed to include the | |
7523 | -- required sign. Note that we do not need to worry about the | |
7524 | -- case of both bounds negative, because the sign will be dealt | |
7525 | -- with anyway. Furthermore we can't just go making such a bound | |
7526 | -- symmetrical, since in a twos-complement system, there is an | |
e14c931f | 7527 | -- extra negative value which could not be accommodated on the |
70482933 RK |
7528 | -- positive side. |
7529 | ||
7530 | if Typ = Btyp | |
7531 | and then not UR_Is_Negative (Loval) | |
7532 | and then Hival > Loval | |
7533 | then | |
7534 | Loval := -Hival; | |
7535 | Set_Realval (Lo, Loval); | |
7536 | end if; | |
7537 | ||
7538 | -- Compute the fudged bounds. If the number is a model number, | |
edd63e9b ES |
7539 | -- then we do nothing to include it, but we are allowed to backoff |
7540 | -- to the next adjacent model number when we exclude it. If it is | |
7541 | -- not a model number then we straddle the two values with the | |
7542 | -- model numbers on either side. | |
70482933 RK |
7543 | |
7544 | Model_Num := UR_Trunc (Loval / Small) * Small; | |
7545 | ||
7546 | if Loval = Model_Num then | |
7547 | Loval_Incl_EP := Model_Num; | |
7548 | else | |
7549 | Loval_Incl_EP := Model_Num - Small; | |
7550 | end if; | |
7551 | ||
7552 | -- The low value excluding the end point is Small greater, but | |
7553 | -- we do not do this exclusion if the low value is positive, | |
7554 | -- since it can't help the size and could actually hurt by | |
7555 | -- crossing the high bound. | |
7556 | ||
7557 | if UR_Is_Negative (Loval_Incl_EP) then | |
7558 | Loval_Excl_EP := Loval_Incl_EP + Small; | |
def46b54 RD |
7559 | |
7560 | -- If the value went from negative to zero, then we have the | |
7561 | -- case where Loval_Incl_EP is the model number just below | |
7562 | -- zero, so we want to stick to the negative value for the | |
7563 | -- base type to maintain the condition that the size will | |
7564 | -- include signed values. | |
7565 | ||
7566 | if Typ = Btyp | |
7567 | and then UR_Is_Zero (Loval_Excl_EP) | |
7568 | then | |
7569 | Loval_Excl_EP := Loval_Incl_EP; | |
7570 | end if; | |
7571 | ||
70482933 RK |
7572 | else |
7573 | Loval_Excl_EP := Loval_Incl_EP; | |
7574 | end if; | |
7575 | ||
7576 | -- Similar processing for upper bound and high value | |
7577 | ||
7578 | Model_Num := UR_Trunc (Hival / Small) * Small; | |
7579 | ||
7580 | if Hival = Model_Num then | |
7581 | Hival_Incl_EP := Model_Num; | |
7582 | else | |
7583 | Hival_Incl_EP := Model_Num + Small; | |
7584 | end if; | |
7585 | ||
7586 | if UR_Is_Positive (Hival_Incl_EP) then | |
7587 | Hival_Excl_EP := Hival_Incl_EP - Small; | |
7588 | else | |
7589 | Hival_Excl_EP := Hival_Incl_EP; | |
7590 | end if; | |
7591 | ||
ee094616 RD |
7592 | -- One further adjustment is needed. In the case of subtypes, we |
7593 | -- cannot go outside the range of the base type, or we get | |
70482933 | 7594 | -- peculiarities, and the base type range is already set. This |
ee094616 RD |
7595 | -- only applies to the Incl values, since clearly the Excl values |
7596 | -- are already as restricted as they are allowed to be. | |
70482933 RK |
7597 | |
7598 | if Typ /= Btyp then | |
7599 | Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo)); | |
7600 | Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi)); | |
7601 | end if; | |
7602 | ||
7603 | -- Get size including and excluding end points | |
7604 | ||
7605 | Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP); | |
7606 | Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP); | |
7607 | ||
7608 | -- No need to exclude end-points if it does not reduce size | |
7609 | ||
7610 | if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then | |
7611 | Loval_Excl_EP := Loval_Incl_EP; | |
7612 | end if; | |
7613 | ||
7614 | if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then | |
7615 | Hival_Excl_EP := Hival_Incl_EP; | |
7616 | end if; | |
7617 | ||
7618 | -- Now we set the actual size to be used. We want to use the | |
7619 | -- bounds fudged up to include the end-points but only if this | |
7620 | -- can be done without violating a specifically given size | |
7621 | -- size clause or causing an unacceptable increase in size. | |
7622 | ||
7623 | -- Case of size clause given | |
7624 | ||
7625 | if Has_Size_Clause (Typ) then | |
7626 | ||
7627 | -- Use the inclusive size only if it is consistent with | |
7628 | -- the explicitly specified size. | |
7629 | ||
7630 | if Size_Incl_EP <= RM_Size (Typ) then | |
7631 | Actual_Lo := Loval_Incl_EP; | |
7632 | Actual_Hi := Hival_Incl_EP; | |
7633 | Actual_Size := Size_Incl_EP; | |
7634 | ||
7635 | -- If the inclusive size is too large, we try excluding | |
7636 | -- the end-points (will be caught later if does not work). | |
7637 | ||
7638 | else | |
7639 | Actual_Lo := Loval_Excl_EP; | |
7640 | Actual_Hi := Hival_Excl_EP; | |
7641 | Actual_Size := Size_Excl_EP; | |
7642 | end if; | |
7643 | ||
7644 | -- Case of size clause not given | |
7645 | ||
7646 | else | |
7647 | -- If we have a base type whose corresponding first subtype | |
7648 | -- has an explicit size that is large enough to include our | |
7649 | -- end-points, then do so. There is no point in working hard | |
7650 | -- to get a base type whose size is smaller than the specified | |
7651 | -- size of the first subtype. | |
7652 | ||
7653 | First_Subt := First_Subtype (Typ); | |
7654 | ||
7655 | if Has_Size_Clause (First_Subt) | |
7656 | and then Size_Incl_EP <= Esize (First_Subt) | |
7657 | then | |
7658 | Actual_Size := Size_Incl_EP; | |
7659 | Actual_Lo := Loval_Incl_EP; | |
7660 | Actual_Hi := Hival_Incl_EP; | |
7661 | ||
7662 | -- If excluding the end-points makes the size smaller and | |
7663 | -- results in a size of 8,16,32,64, then we take the smaller | |
7664 | -- size. For the 64 case, this is compulsory. For the other | |
7665 | -- cases, it seems reasonable. We like to include end points | |
7666 | -- if we can, but not at the expense of moving to the next | |
7667 | -- natural boundary of size. | |
7668 | ||
7669 | elsif Size_Incl_EP /= Size_Excl_EP | |
094cefda | 7670 | and then Addressable (Size_Excl_EP) |
70482933 RK |
7671 | then |
7672 | Actual_Size := Size_Excl_EP; | |
7673 | Actual_Lo := Loval_Excl_EP; | |
7674 | Actual_Hi := Hival_Excl_EP; | |
7675 | ||
7676 | -- Otherwise we can definitely include the end points | |
7677 | ||
7678 | else | |
7679 | Actual_Size := Size_Incl_EP; | |
7680 | Actual_Lo := Loval_Incl_EP; | |
7681 | Actual_Hi := Hival_Incl_EP; | |
7682 | end if; | |
7683 | ||
edd63e9b ES |
7684 | -- One pathological case: normally we never fudge a low bound |
7685 | -- down, since it would seem to increase the size (if it has | |
7686 | -- any effect), but for ranges containing single value, or no | |
7687 | -- values, the high bound can be small too large. Consider: | |
70482933 RK |
7688 | |
7689 | -- type t is delta 2.0**(-14) | |
7690 | -- range 131072.0 .. 0; | |
7691 | ||
edd63e9b ES |
7692 | -- That lower bound is *just* outside the range of 32 bits, and |
7693 | -- does need fudging down in this case. Note that the bounds | |
7694 | -- will always have crossed here, since the high bound will be | |
7695 | -- fudged down if necessary, as in the case of: | |
70482933 RK |
7696 | |
7697 | -- type t is delta 2.0**(-14) | |
7698 | -- range 131072.0 .. 131072.0; | |
7699 | ||
edd63e9b ES |
7700 | -- So we detect the situation by looking for crossed bounds, |
7701 | -- and if the bounds are crossed, and the low bound is greater | |
7702 | -- than zero, we will always back it off by small, since this | |
7703 | -- is completely harmless. | |
70482933 RK |
7704 | |
7705 | if Actual_Lo > Actual_Hi then | |
7706 | if UR_Is_Positive (Actual_Lo) then | |
7707 | Actual_Lo := Loval_Incl_EP - Small; | |
7708 | Actual_Size := Fsize (Actual_Lo, Actual_Hi); | |
7709 | ||
7710 | -- And of course, we need to do exactly the same parallel | |
7711 | -- fudge for flat ranges in the negative region. | |
7712 | ||
7713 | elsif UR_Is_Negative (Actual_Hi) then | |
7714 | Actual_Hi := Hival_Incl_EP + Small; | |
7715 | Actual_Size := Fsize (Actual_Lo, Actual_Hi); | |
7716 | end if; | |
7717 | end if; | |
7718 | end if; | |
7719 | ||
7720 | Set_Realval (Lo, Actual_Lo); | |
7721 | Set_Realval (Hi, Actual_Hi); | |
7722 | end Fudge; | |
7723 | ||
7724 | -- For the decimal case, none of this fudging is required, since there | |
7725 | -- are no end-point problems in the decimal case (the end-points are | |
7726 | -- always included). | |
7727 | ||
7728 | else | |
7729 | Actual_Size := Fsize (Loval, Hival); | |
7730 | end if; | |
7731 | ||
7732 | -- At this stage, the actual size has been calculated and the proper | |
7733 | -- required bounds are stored in the low and high bounds. | |
7734 | ||
7735 | if Actual_Size > 64 then | |
7736 | Error_Msg_Uint_1 := UI_From_Int (Actual_Size); | |
7737 | Error_Msg_N | |
7d8b9c99 RD |
7738 | ("size required (^) for type& too large, maximum allowed is 64", |
7739 | Typ); | |
70482933 RK |
7740 | Actual_Size := 64; |
7741 | end if; | |
7742 | ||
7743 | -- Check size against explicit given size | |
7744 | ||
7745 | if Has_Size_Clause (Typ) then | |
7746 | if Actual_Size > RM_Size (Typ) then | |
7747 | Error_Msg_Uint_1 := RM_Size (Typ); | |
7748 | Error_Msg_Uint_2 := UI_From_Int (Actual_Size); | |
7749 | Error_Msg_NE | |
7d8b9c99 | 7750 | ("size given (^) for type& too small, minimum allowed is ^", |
70482933 RK |
7751 | Size_Clause (Typ), Typ); |
7752 | ||
7753 | else | |
7754 | Actual_Size := UI_To_Int (Esize (Typ)); | |
7755 | end if; | |
7756 | ||
7757 | -- Increase size to next natural boundary if no size clause given | |
7758 | ||
7759 | else | |
7760 | if Actual_Size <= 8 then | |
7761 | Actual_Size := 8; | |
7762 | elsif Actual_Size <= 16 then | |
7763 | Actual_Size := 16; | |
7764 | elsif Actual_Size <= 32 then | |
7765 | Actual_Size := 32; | |
7766 | else | |
7767 | Actual_Size := 64; | |
7768 | end if; | |
7769 | ||
7770 | Init_Esize (Typ, Actual_Size); | |
7771 | Adjust_Esize_For_Alignment (Typ); | |
7772 | end if; | |
7773 | ||
edd63e9b ES |
7774 | -- If we have a base type, then expand the bounds so that they extend to |
7775 | -- the full width of the allocated size in bits, to avoid junk range | |
7776 | -- checks on intermediate computations. | |
70482933 RK |
7777 | |
7778 | if Base_Type (Typ) = Typ then | |
7779 | Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1)))); | |
7780 | Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1))); | |
7781 | end if; | |
7782 | ||
7783 | -- Final step is to reanalyze the bounds using the proper type | |
7784 | -- and set the Corresponding_Integer_Value fields of the literals. | |
7785 | ||
7786 | Set_Etype (Lo, Empty); | |
7787 | Set_Analyzed (Lo, False); | |
7788 | Analyze (Lo); | |
7789 | ||
edd63e9b ES |
7790 | -- Resolve with universal fixed if the base type, and the base type if |
7791 | -- it is a subtype. Note we can't resolve the base type with itself, | |
7792 | -- that would be a reference before definition. | |
70482933 RK |
7793 | |
7794 | if Typ = Btyp then | |
7795 | Resolve (Lo, Universal_Fixed); | |
7796 | else | |
7797 | Resolve (Lo, Btyp); | |
7798 | end if; | |
7799 | ||
7800 | -- Set corresponding integer value for bound | |
7801 | ||
7802 | Set_Corresponding_Integer_Value | |
7803 | (Lo, UR_To_Uint (Realval (Lo) / Small)); | |
7804 | ||
7805 | -- Similar processing for high bound | |
7806 | ||
7807 | Set_Etype (Hi, Empty); | |
7808 | Set_Analyzed (Hi, False); | |
7809 | Analyze (Hi); | |
7810 | ||
7811 | if Typ = Btyp then | |
7812 | Resolve (Hi, Universal_Fixed); | |
7813 | else | |
7814 | Resolve (Hi, Btyp); | |
7815 | end if; | |
7816 | ||
7817 | Set_Corresponding_Integer_Value | |
7818 | (Hi, UR_To_Uint (Realval (Hi) / Small)); | |
7819 | ||
7820 | -- Set type of range to correspond to bounds | |
7821 | ||
7822 | Set_Etype (Rng, Etype (Lo)); | |
7823 | ||
fbf5a39b | 7824 | -- Set Esize to calculated size if not set already |
70482933 | 7825 | |
fbf5a39b AC |
7826 | if Unknown_Esize (Typ) then |
7827 | Init_Esize (Typ, Actual_Size); | |
7828 | end if; | |
70482933 RK |
7829 | |
7830 | -- Set RM_Size if not already set. If already set, check value | |
7831 | ||
7832 | declare | |
7833 | Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ)); | |
7834 | ||
7835 | begin | |
7836 | if RM_Size (Typ) /= Uint_0 then | |
7837 | if RM_Size (Typ) < Minsiz then | |
7838 | Error_Msg_Uint_1 := RM_Size (Typ); | |
7839 | Error_Msg_Uint_2 := Minsiz; | |
7840 | Error_Msg_NE | |
7d8b9c99 | 7841 | ("size given (^) for type& too small, minimum allowed is ^", |
70482933 RK |
7842 | Size_Clause (Typ), Typ); |
7843 | end if; | |
7844 | ||
7845 | else | |
7846 | Set_RM_Size (Typ, Minsiz); | |
7847 | end if; | |
7848 | end; | |
4b6f99f5 RD |
7849 | |
7850 | -- Check for shaving | |
7851 | ||
7852 | if Comes_From_Source (Typ) then | |
4b6f99f5 | 7853 | |
8eb8461d AC |
7854 | -- In SPARK mode the given bounds must be strictly representable |
7855 | ||
7856 | if SPARK_Mode = On then | |
7857 | if Orig_Lo < Expr_Value_R (Lo) then | |
7858 | Error_Msg_NE | |
7859 | ("declared low bound of type & is outside type range", | |
7860 | Lo, Typ); | |
7861 | end if; | |
7862 | ||
7863 | if Orig_Hi > Expr_Value_R (Hi) then | |
7864 | Error_Msg_NE | |
7865 | ("declared high bound of type & is outside type range", | |
7866 | Hi, Typ); | |
7867 | end if; | |
7868 | ||
7869 | else | |
7870 | if Orig_Lo < Expr_Value_R (Lo) then | |
7871 | Error_Msg_N | |
7872 | ("declared low bound of type & is outside type range??", Typ); | |
7873 | Error_Msg_N | |
7874 | ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ); | |
7875 | end if; | |
7876 | ||
7877 | if Orig_Hi > Expr_Value_R (Hi) then | |
7878 | Error_Msg_N | |
7879 | ("declared high bound of type & is outside type range??", | |
7880 | Typ); | |
7881 | Error_Msg_N | |
7882 | ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ); | |
7883 | end if; | |
4b6f99f5 RD |
7884 | end if; |
7885 | end if; | |
70482933 RK |
7886 | end Freeze_Fixed_Point_Type; |
7887 | ||
7888 | ------------------ | |
7889 | -- Freeze_Itype -- | |
7890 | ------------------ | |
7891 | ||
7892 | procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is | |
7893 | L : List_Id; | |
7894 | ||
7895 | begin | |
7896 | Set_Has_Delayed_Freeze (T); | |
c159409f | 7897 | L := Freeze_Entity (T, N); |
70482933 RK |
7898 | |
7899 | if Is_Non_Empty_List (L) then | |
7900 | Insert_Actions (N, L); | |
7901 | end if; | |
7902 | end Freeze_Itype; | |
7903 | ||
7904 | -------------------------- | |
7905 | -- Freeze_Static_Object -- | |
7906 | -------------------------- | |
7907 | ||
7908 | procedure Freeze_Static_Object (E : Entity_Id) is | |
7909 | ||
7910 | Cannot_Be_Static : exception; | |
7911 | -- Exception raised if the type of a static object cannot be made | |
7912 | -- static. This happens if the type depends on non-global objects. | |
7913 | ||
7914 | procedure Ensure_Expression_Is_SA (N : Node_Id); | |
ee094616 RD |
7915 | -- Called to ensure that an expression used as part of a type definition |
7916 | -- is statically allocatable, which means that the expression type is | |
7917 | -- statically allocatable, and the expression is either static, or a | |
7918 | -- reference to a library level constant. | |
70482933 RK |
7919 | |
7920 | procedure Ensure_Type_Is_SA (Typ : Entity_Id); | |
7921 | -- Called to mark a type as static, checking that it is possible | |
7922 | -- to set the type as static. If it is not possible, then the | |
7923 | -- exception Cannot_Be_Static is raised. | |
7924 | ||
7925 | ----------------------------- | |
7926 | -- Ensure_Expression_Is_SA -- | |
7927 | ----------------------------- | |
7928 | ||
7929 | procedure Ensure_Expression_Is_SA (N : Node_Id) is | |
7930 | Ent : Entity_Id; | |
7931 | ||
7932 | begin | |
7933 | Ensure_Type_Is_SA (Etype (N)); | |
7934 | ||
edab6088 | 7935 | if Is_OK_Static_Expression (N) then |
70482933 RK |
7936 | return; |
7937 | ||
7938 | elsif Nkind (N) = N_Identifier then | |
7939 | Ent := Entity (N); | |
7940 | ||
7941 | if Present (Ent) | |
7942 | and then Ekind (Ent) = E_Constant | |
7943 | and then Is_Library_Level_Entity (Ent) | |
7944 | then | |
7945 | return; | |
7946 | end if; | |
7947 | end if; | |
7948 | ||
7949 | raise Cannot_Be_Static; | |
7950 | end Ensure_Expression_Is_SA; | |
7951 | ||
7952 | ----------------------- | |
7953 | -- Ensure_Type_Is_SA -- | |
7954 | ----------------------- | |
7955 | ||
7956 | procedure Ensure_Type_Is_SA (Typ : Entity_Id) is | |
7957 | N : Node_Id; | |
7958 | C : Entity_Id; | |
7959 | ||
7960 | begin | |
7961 | -- If type is library level, we are all set | |
7962 | ||
7963 | if Is_Library_Level_Entity (Typ) then | |
7964 | return; | |
7965 | end if; | |
7966 | ||
ee094616 RD |
7967 | -- We are also OK if the type already marked as statically allocated, |
7968 | -- which means we processed it before. | |
70482933 RK |
7969 | |
7970 | if Is_Statically_Allocated (Typ) then | |
7971 | return; | |
7972 | end if; | |
7973 | ||
7974 | -- Mark type as statically allocated | |
7975 | ||
7976 | Set_Is_Statically_Allocated (Typ); | |
7977 | ||
7978 | -- Check that it is safe to statically allocate this type | |
7979 | ||
7980 | if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then | |
7981 | Ensure_Expression_Is_SA (Type_Low_Bound (Typ)); | |
7982 | Ensure_Expression_Is_SA (Type_High_Bound (Typ)); | |
7983 | ||
7984 | elsif Is_Array_Type (Typ) then | |
7985 | N := First_Index (Typ); | |
7986 | while Present (N) loop | |
7987 | Ensure_Type_Is_SA (Etype (N)); | |
7988 | Next_Index (N); | |
7989 | end loop; | |
7990 | ||
7991 | Ensure_Type_Is_SA (Component_Type (Typ)); | |
7992 | ||
7993 | elsif Is_Access_Type (Typ) then | |
7994 | if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then | |
7995 | ||
7996 | declare | |
7997 | F : Entity_Id; | |
7998 | T : constant Entity_Id := Etype (Designated_Type (Typ)); | |
7999 | ||
8000 | begin | |
8001 | if T /= Standard_Void_Type then | |
8002 | Ensure_Type_Is_SA (T); | |
8003 | end if; | |
8004 | ||
8005 | F := First_Formal (Designated_Type (Typ)); | |
70482933 RK |
8006 | while Present (F) loop |
8007 | Ensure_Type_Is_SA (Etype (F)); | |
8008 | Next_Formal (F); | |
8009 | end loop; | |
8010 | end; | |
8011 | ||
8012 | else | |
8013 | Ensure_Type_Is_SA (Designated_Type (Typ)); | |
8014 | end if; | |
8015 | ||
8016 | elsif Is_Record_Type (Typ) then | |
8017 | C := First_Entity (Typ); | |
70482933 RK |
8018 | while Present (C) loop |
8019 | if Ekind (C) = E_Discriminant | |
8020 | or else Ekind (C) = E_Component | |
8021 | then | |
8022 | Ensure_Type_Is_SA (Etype (C)); | |
8023 | ||
8024 | elsif Is_Type (C) then | |
8025 | Ensure_Type_Is_SA (C); | |
8026 | end if; | |
8027 | ||
8028 | Next_Entity (C); | |
8029 | end loop; | |
8030 | ||
8031 | elsif Ekind (Typ) = E_Subprogram_Type then | |
8032 | Ensure_Type_Is_SA (Etype (Typ)); | |
8033 | ||
8034 | C := First_Formal (Typ); | |
8035 | while Present (C) loop | |
8036 | Ensure_Type_Is_SA (Etype (C)); | |
8037 | Next_Formal (C); | |
8038 | end loop; | |
8039 | ||
8040 | else | |
8041 | raise Cannot_Be_Static; | |
8042 | end if; | |
8043 | end Ensure_Type_Is_SA; | |
8044 | ||
8045 | -- Start of processing for Freeze_Static_Object | |
8046 | ||
8047 | begin | |
8048 | Ensure_Type_Is_SA (Etype (E)); | |
8049 | ||
8050 | exception | |
8051 | when Cannot_Be_Static => | |
8052 | ||
09494c32 AC |
8053 | -- If the object that cannot be static is imported or exported, then |
8054 | -- issue an error message saying that this object cannot be imported | |
8055 | -- or exported. If it has an address clause it is an overlay in the | |
8056 | -- current partition and the static requirement is not relevant. | |
d606f1df | 8057 | -- Do not issue any error message when ignoring rep clauses. |
09494c32 | 8058 | |
d606f1df AC |
8059 | if Ignore_Rep_Clauses then |
8060 | null; | |
8061 | ||
8062 | elsif Is_Imported (E) then | |
8063 | if No (Address_Clause (E)) then | |
8064 | Error_Msg_N | |
8065 | ("& cannot be imported (local type is not constant)", E); | |
8066 | end if; | |
70482933 RK |
8067 | |
8068 | -- Otherwise must be exported, something is wrong if compiler | |
8069 | -- is marking something as statically allocated which cannot be). | |
8070 | ||
8071 | else pragma Assert (Is_Exported (E)); | |
8072 | Error_Msg_N | |
8073 | ("& cannot be exported (local type is not constant)", E); | |
8074 | end if; | |
8075 | end Freeze_Static_Object; | |
8076 | ||
8077 | ----------------------- | |
8078 | -- Freeze_Subprogram -- | |
8079 | ----------------------- | |
8080 | ||
8081 | procedure Freeze_Subprogram (E : Entity_Id) is | |
f991bd8e HK |
8082 | procedure Set_Profile_Convention (Subp_Id : Entity_Id); |
8083 | -- Set the conventions of all anonymous access-to-subprogram formals and | |
8084 | -- result subtype of subprogram Subp_Id to the convention of Subp_Id. | |
8085 | ||
8086 | ---------------------------- | |
8087 | -- Set_Profile_Convention -- | |
8088 | ---------------------------- | |
8089 | ||
8090 | procedure Set_Profile_Convention (Subp_Id : Entity_Id) is | |
8091 | Conv : constant Convention_Id := Convention (Subp_Id); | |
8092 | ||
8093 | procedure Set_Type_Convention (Typ : Entity_Id); | |
8094 | -- Set the convention of anonymous access-to-subprogram type Typ and | |
8095 | -- its designated type to Conv. | |
8096 | ||
8097 | ------------------------- | |
8098 | -- Set_Type_Convention -- | |
8099 | ------------------------- | |
8100 | ||
8101 | procedure Set_Type_Convention (Typ : Entity_Id) is | |
8102 | begin | |
8103 | -- Set the convention on both the anonymous access-to-subprogram | |
8104 | -- type and the subprogram type it points to because both types | |
8105 | -- participate in conformance-related checks. | |
8106 | ||
8107 | if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then | |
8108 | Set_Convention (Typ, Conv); | |
8109 | Set_Convention (Designated_Type (Typ), Conv); | |
8110 | end if; | |
8111 | end Set_Type_Convention; | |
8112 | ||
8113 | -- Local variables | |
8114 | ||
8115 | Formal : Entity_Id; | |
8116 | ||
8117 | -- Start of processing for Set_Profile_Convention | |
8118 | ||
8119 | begin | |
8120 | Formal := First_Formal (Subp_Id); | |
8121 | while Present (Formal) loop | |
8122 | Set_Type_Convention (Etype (Formal)); | |
8123 | Next_Formal (Formal); | |
8124 | end loop; | |
8125 | ||
8126 | if Ekind (Subp_Id) = E_Function then | |
8127 | Set_Type_Convention (Etype (Subp_Id)); | |
8128 | end if; | |
8129 | end Set_Profile_Convention; | |
8130 | ||
8131 | -- Local variables | |
8132 | ||
70482933 | 8133 | F : Entity_Id; |
f991bd8e HK |
8134 | Retype : Entity_Id; |
8135 | ||
8136 | -- Start of processing for Freeze_Subprogram | |
70482933 RK |
8137 | |
8138 | begin | |
8139 | -- Subprogram may not have an address clause unless it is imported | |
8140 | ||
8141 | if Present (Address_Clause (E)) then | |
8142 | if not Is_Imported (E) then | |
8143 | Error_Msg_N | |
f991bd8e | 8144 | ("address clause can only be given for imported subprogram", |
70482933 RK |
8145 | Name (Address_Clause (E))); |
8146 | end if; | |
8147 | end if; | |
8148 | ||
91b1417d | 8149 | -- Reset the Pure indication on an imported subprogram unless an |
2db5b47e AC |
8150 | -- explicit Pure_Function pragma was present or the subprogram is an |
8151 | -- intrinsic. We do this because otherwise it is an insidious error | |
8152 | -- to call a non-pure function from pure unit and have calls | |
8153 | -- mysteriously optimized away. What happens here is that the Import | |
8154 | -- can bypass the normal check to ensure that pure units call only pure | |
8155 | -- subprograms. | |
91b1417d | 8156 | |
3e247e58 RD |
8157 | -- The reason for the intrinsic exception is that in general, intrinsic |
8158 | -- functions (such as shifts) are pure anyway. The only exceptions are | |
8159 | -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure | |
8160 | -- in any case, so no problem arises. | |
8161 | ||
91b1417d AC |
8162 | if Is_Imported (E) |
8163 | and then Is_Pure (E) | |
8164 | and then not Has_Pragma_Pure_Function (E) | |
2db5b47e | 8165 | and then not Is_Intrinsic_Subprogram (E) |
91b1417d AC |
8166 | then |
8167 | Set_Is_Pure (E, False); | |
8168 | end if; | |
8169 | ||
90e7b558 AC |
8170 | -- We also reset the Pure indication on a subprogram with an Address |
8171 | -- parameter, because the parameter may be used as a pointer and the | |
8172 | -- referenced data may change even if the address value does not. | |
8173 | ||
8174 | -- Note that if the programmer gave an explicit Pure_Function pragma, | |
f991bd8e HK |
8175 | -- then we believe the programmer, and leave the subprogram Pure. We |
8176 | -- also suppress this check on run-time files. | |
90e7b558 AC |
8177 | |
8178 | if Is_Pure (E) | |
8179 | and then Is_Subprogram (E) | |
8180 | and then not Has_Pragma_Pure_Function (E) | |
8181 | and then not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)) | |
8182 | then | |
8183 | Check_Function_With_Address_Parameter (E); | |
8184 | end if; | |
8185 | ||
f991bd8e | 8186 | -- Ensure that all anonymous access-to-subprogram types inherit the |
0d1e3cc9 | 8187 | -- convention of their related subprogram (RM 6.3.1 13.1/3). This is |
f991bd8e HK |
8188 | -- not done for a defaulted convention Ada because those types also |
8189 | -- default to Ada. Convention Protected must not be propagated when | |
8190 | -- the subprogram is an entry because this would be illegal. The only | |
8191 | -- way to force convention Protected on these kinds of types is to | |
8192 | -- include keyword "protected" in the access definition. | |
8193 | ||
8194 | if Convention (E) /= Convention_Ada | |
8195 | and then Convention (E) /= Convention_Protected | |
8196 | then | |
8197 | Set_Profile_Convention (E); | |
8198 | end if; | |
8199 | ||
70482933 RK |
8200 | -- For non-foreign convention subprograms, this is where we create |
8201 | -- the extra formals (for accessibility level and constrained bit | |
8202 | -- information). We delay this till the freeze point precisely so | |
a90bd866 | 8203 | -- that we know the convention. |
70482933 RK |
8204 | |
8205 | if not Has_Foreign_Convention (E) then | |
8206 | Create_Extra_Formals (E); | |
8207 | Set_Mechanisms (E); | |
8208 | ||
8209 | -- If this is convention Ada and a Valued_Procedure, that's odd | |
8210 | ||
8211 | if Ekind (E) = E_Procedure | |
8212 | and then Is_Valued_Procedure (E) | |
8213 | and then Convention (E) = Convention_Ada | |
fbf5a39b | 8214 | and then Warn_On_Export_Import |
70482933 RK |
8215 | then |
8216 | Error_Msg_N | |
685bc70f | 8217 | ("??Valued_Procedure has no effect for convention Ada", E); |
70482933 RK |
8218 | Set_Is_Valued_Procedure (E, False); |
8219 | end if; | |
8220 | ||
8221 | -- Case of foreign convention | |
8222 | ||
8223 | else | |
8224 | Set_Mechanisms (E); | |
8225 | ||
7a5b62b0 | 8226 | -- For foreign conventions, warn about return of unconstrained array |
70482933 RK |
8227 | |
8228 | if Ekind (E) = E_Function then | |
8229 | Retype := Underlying_Type (Etype (E)); | |
8230 | ||
8231 | -- If no return type, probably some other error, e.g. a | |
8232 | -- missing full declaration, so ignore. | |
8233 | ||
8234 | if No (Retype) then | |
8235 | null; | |
8236 | ||
8237 | -- If the return type is generic, we have emitted a warning | |
edd63e9b ES |
8238 | -- earlier on, and there is nothing else to check here. Specific |
8239 | -- instantiations may lead to erroneous behavior. | |
70482933 RK |
8240 | |
8241 | elsif Is_Generic_Type (Etype (E)) then | |
8242 | null; | |
8243 | ||
e7d72fb9 | 8244 | -- Display warning if returning unconstrained array |
59366db6 | 8245 | |
70482933 RK |
8246 | elsif Is_Array_Type (Retype) |
8247 | and then not Is_Constrained (Retype) | |
e7d72fb9 | 8248 | |
df3e68b1 HK |
8249 | -- Check appropriate warning is enabled (should we check for |
8250 | -- Warnings (Off) on specific entities here, probably so???) | |
e7d72fb9 | 8251 | |
fbf5a39b | 8252 | and then Warn_On_Export_Import |
70482933 | 8253 | then |
fbf5a39b | 8254 | Error_Msg_N |
685bc70f | 8255 | ("?x?foreign convention function& should not return " & |
fbf5a39b | 8256 | "unconstrained array", E); |
70482933 RK |
8257 | return; |
8258 | end if; | |
8259 | end if; | |
8260 | ||
8261 | -- If any of the formals for an exported foreign convention | |
edd63e9b ES |
8262 | -- subprogram have defaults, then emit an appropriate warning since |
8263 | -- this is odd (default cannot be used from non-Ada code) | |
70482933 RK |
8264 | |
8265 | if Is_Exported (E) then | |
8266 | F := First_Formal (E); | |
8267 | while Present (F) loop | |
fbf5a39b AC |
8268 | if Warn_On_Export_Import |
8269 | and then Present (Default_Value (F)) | |
8270 | then | |
70482933 | 8271 | Error_Msg_N |
685bc70f | 8272 | ("?x?parameter cannot be defaulted in non-Ada call", |
70482933 RK |
8273 | Default_Value (F)); |
8274 | end if; | |
8275 | ||
8276 | Next_Formal (F); | |
8277 | end loop; | |
8278 | end if; | |
8279 | end if; | |
8280 | ||
edd63e9b ES |
8281 | -- Pragma Inline_Always is disallowed for dispatching subprograms |
8282 | -- because the address of such subprograms is saved in the dispatch | |
8283 | -- table to support dispatching calls, and dispatching calls cannot | |
8284 | -- be inlined. This is consistent with the restriction against using | |
8285 | -- 'Access or 'Address on an Inline_Always subprogram. | |
8286 | ||
def46b54 RD |
8287 | if Is_Dispatching_Operation (E) |
8288 | and then Has_Pragma_Inline_Always (E) | |
8289 | then | |
edd63e9b ES |
8290 | Error_Msg_N |
8291 | ("pragma Inline_Always not allowed for dispatching subprograms", E); | |
8292 | end if; | |
c6a9797e RD |
8293 | |
8294 | -- Because of the implicit representation of inherited predefined | |
8295 | -- operators in the front-end, the overriding status of the operation | |
8296 | -- may be affected when a full view of a type is analyzed, and this is | |
8297 | -- not captured by the analysis of the corresponding type declaration. | |
8298 | -- Therefore the correctness of a not-overriding indicator must be | |
8299 | -- rechecked when the subprogram is frozen. | |
8300 | ||
8301 | if Nkind (E) = N_Defining_Operator_Symbol | |
8302 | and then not Error_Posted (Parent (E)) | |
8303 | then | |
8304 | Check_Overriding_Indicator (E, Empty, Is_Primitive (E)); | |
8305 | end if; | |
51b42ffa AC |
8306 | |
8307 | if Modify_Tree_For_C | |
8308 | and then Nkind (Parent (E)) = N_Function_Specification | |
8309 | and then Is_Array_Type (Etype (E)) | |
8310 | and then Is_Constrained (Etype (E)) | |
8311 | and then not Is_Unchecked_Conversion_Instance (E) | |
8312 | and then not Rewritten_For_C (E) | |
8313 | then | |
8314 | Build_Procedure_Form (Unit_Declaration_Node (E)); | |
8315 | end if; | |
70482933 RK |
8316 | end Freeze_Subprogram; |
8317 | ||
15ce9ca2 AC |
8318 | ---------------------- |
8319 | -- Is_Fully_Defined -- | |
8320 | ---------------------- | |
70482933 | 8321 | |
70482933 RK |
8322 | function Is_Fully_Defined (T : Entity_Id) return Boolean is |
8323 | begin | |
8324 | if Ekind (T) = E_Class_Wide_Type then | |
8325 | return Is_Fully_Defined (Etype (T)); | |
657a9dd9 AC |
8326 | |
8327 | elsif Is_Array_Type (T) then | |
8328 | return Is_Fully_Defined (Component_Type (T)); | |
8329 | ||
8330 | elsif Is_Record_Type (T) | |
8331 | and not Is_Private_Type (T) | |
8332 | then | |
ee094616 RD |
8333 | -- Verify that the record type has no components with private types |
8334 | -- without completion. | |
657a9dd9 AC |
8335 | |
8336 | declare | |
8337 | Comp : Entity_Id; | |
bde58e32 | 8338 | |
657a9dd9 AC |
8339 | begin |
8340 | Comp := First_Component (T); | |
657a9dd9 AC |
8341 | while Present (Comp) loop |
8342 | if not Is_Fully_Defined (Etype (Comp)) then | |
8343 | return False; | |
8344 | end if; | |
8345 | ||
8346 | Next_Component (Comp); | |
8347 | end loop; | |
8348 | return True; | |
8349 | end; | |
8350 | ||
30537990 | 8351 | -- For the designated type of an access to subprogram, all types in |
4519314c AC |
8352 | -- the profile must be fully defined. |
8353 | ||
8354 | elsif Ekind (T) = E_Subprogram_Type then | |
8355 | declare | |
8356 | F : Entity_Id; | |
8357 | ||
8358 | begin | |
8359 | F := First_Formal (T); | |
8360 | while Present (F) loop | |
8361 | if not Is_Fully_Defined (Etype (F)) then | |
8362 | return False; | |
8363 | end if; | |
8364 | ||
8365 | Next_Formal (F); | |
8366 | end loop; | |
8367 | ||
8368 | return Is_Fully_Defined (Etype (T)); | |
8369 | end; | |
8370 | ||
86cde7b1 RD |
8371 | else |
8372 | return not Is_Private_Type (T) | |
8373 | or else Present (Full_View (Base_Type (T))); | |
70482933 RK |
8374 | end if; |
8375 | end Is_Fully_Defined; | |
8376 | ||
70d904ca | 8377 | --------------------------------- |
70482933 RK |
8378 | -- Process_Default_Expressions -- |
8379 | --------------------------------- | |
8380 | ||
8381 | procedure Process_Default_Expressions | |
8382 | (E : Entity_Id; | |
8383 | After : in out Node_Id) | |
8384 | is | |
8385 | Loc : constant Source_Ptr := Sloc (E); | |
8386 | Dbody : Node_Id; | |
8387 | Formal : Node_Id; | |
8388 | Dcopy : Node_Id; | |
8389 | Dnam : Entity_Id; | |
8390 | ||
8391 | begin | |
8392 | Set_Default_Expressions_Processed (E); | |
8393 | ||
ee094616 RD |
8394 | -- A subprogram instance and its associated anonymous subprogram share |
8395 | -- their signature. The default expression functions are defined in the | |
8396 | -- wrapper packages for the anonymous subprogram, and should not be | |
8397 | -- generated again for the instance. | |
70482933 RK |
8398 | |
8399 | if Is_Generic_Instance (E) | |
8400 | and then Present (Alias (E)) | |
8401 | and then Default_Expressions_Processed (Alias (E)) | |
8402 | then | |
8403 | return; | |
8404 | end if; | |
8405 | ||
8406 | Formal := First_Formal (E); | |
70482933 RK |
8407 | while Present (Formal) loop |
8408 | if Present (Default_Value (Formal)) then | |
8409 | ||
8410 | -- We work with a copy of the default expression because we | |
8411 | -- do not want to disturb the original, since this would mess | |
8412 | -- up the conformance checking. | |
8413 | ||
8414 | Dcopy := New_Copy_Tree (Default_Value (Formal)); | |
8415 | ||
8416 | -- The analysis of the expression may generate insert actions, | |
8417 | -- which of course must not be executed. We wrap those actions | |
8418 | -- in a procedure that is not called, and later on eliminated. | |
8419 | -- The following cases have no side-effects, and are analyzed | |
8420 | -- directly. | |
8421 | ||
8422 | if Nkind (Dcopy) = N_Identifier | |
ef1c0511 AC |
8423 | or else Nkind_In (Dcopy, N_Expanded_Name, |
8424 | N_Integer_Literal, | |
8425 | N_Character_Literal, | |
21c51f53 RD |
8426 | N_String_Literal, |
8427 | N_Real_Literal) | |
70482933 | 8428 | or else (Nkind (Dcopy) = N_Attribute_Reference |
ef1c0511 AC |
8429 | and then Attribute_Name (Dcopy) = Name_Null_Parameter) |
8430 | or else Known_Null (Dcopy) | |
70482933 | 8431 | then |
70482933 | 8432 | -- If there is no default function, we must still do a full |
ee094616 RD |
8433 | -- analyze call on the default value, to ensure that all error |
8434 | -- checks are performed, e.g. those associated with static | |
8435 | -- evaluation. Note: this branch will always be taken if the | |
8436 | -- analyzer is turned off (but we still need the error checks). | |
70482933 RK |
8437 | |
8438 | -- Note: the setting of parent here is to meet the requirement | |
8439 | -- that we can only analyze the expression while attached to | |
8440 | -- the tree. Really the requirement is that the parent chain | |
8441 | -- be set, we don't actually need to be in the tree. | |
8442 | ||
8443 | Set_Parent (Dcopy, Declaration_Node (Formal)); | |
8444 | Analyze (Dcopy); | |
8445 | ||
8446 | -- Default expressions are resolved with their own type if the | |
8447 | -- context is generic, to avoid anomalies with private types. | |
8448 | ||
8449 | if Ekind (Scope (E)) = E_Generic_Package then | |
fbf5a39b | 8450 | Resolve (Dcopy); |
70482933 RK |
8451 | else |
8452 | Resolve (Dcopy, Etype (Formal)); | |
8453 | end if; | |
8454 | ||
8455 | -- If that resolved expression will raise constraint error, | |
8456 | -- then flag the default value as raising constraint error. | |
8457 | -- This allows a proper error message on the calls. | |
8458 | ||
8459 | if Raises_Constraint_Error (Dcopy) then | |
8460 | Set_Raises_Constraint_Error (Default_Value (Formal)); | |
8461 | end if; | |
8462 | ||
8463 | -- If the default is a parameterless call, we use the name of | |
8464 | -- the called function directly, and there is no body to build. | |
8465 | ||
8466 | elsif Nkind (Dcopy) = N_Function_Call | |
8467 | and then No (Parameter_Associations (Dcopy)) | |
8468 | then | |
8469 | null; | |
8470 | ||
8471 | -- Else construct and analyze the body of a wrapper procedure | |
8472 | -- that contains an object declaration to hold the expression. | |
44900051 | 8473 | -- Given that this is done only to complete the analysis, it is |
70482933 RK |
8474 | -- simpler to build a procedure than a function which might |
8475 | -- involve secondary stack expansion. | |
8476 | ||
8477 | else | |
b29def53 | 8478 | Dnam := Make_Temporary (Loc, 'D'); |
70482933 RK |
8479 | |
8480 | Dbody := | |
8481 | Make_Subprogram_Body (Loc, | |
8482 | Specification => | |
8483 | Make_Procedure_Specification (Loc, | |
8484 | Defining_Unit_Name => Dnam), | |
8485 | ||
8486 | Declarations => New_List ( | |
8487 | Make_Object_Declaration (Loc, | |
2c1b72d7 AC |
8488 | Defining_Identifier => Make_Temporary (Loc, 'T'), |
8489 | Object_Definition => | |
df3e68b1 | 8490 | New_Occurrence_Of (Etype (Formal), Loc), |
2c1b72d7 | 8491 | Expression => New_Copy_Tree (Dcopy))), |
70482933 RK |
8492 | |
8493 | Handled_Statement_Sequence => | |
8494 | Make_Handled_Sequence_Of_Statements (Loc, | |
2c1b72d7 | 8495 | Statements => Empty_List)); |
70482933 RK |
8496 | |
8497 | Set_Scope (Dnam, Scope (E)); | |
8498 | Set_Assignment_OK (First (Declarations (Dbody))); | |
8499 | Set_Is_Eliminated (Dnam); | |
8500 | Insert_After (After, Dbody); | |
8501 | Analyze (Dbody); | |
8502 | After := Dbody; | |
8503 | end if; | |
8504 | end if; | |
8505 | ||
8506 | Next_Formal (Formal); | |
8507 | end loop; | |
70482933 RK |
8508 | end Process_Default_Expressions; |
8509 | ||
8510 | ---------------------------------------- | |
8511 | -- Set_Component_Alignment_If_Not_Set -- | |
8512 | ---------------------------------------- | |
8513 | ||
8514 | procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is | |
8515 | begin | |
8516 | -- Ignore if not base type, subtypes don't need anything | |
8517 | ||
8518 | if Typ /= Base_Type (Typ) then | |
8519 | return; | |
8520 | end if; | |
8521 | ||
8522 | -- Do not override existing representation | |
8523 | ||
8524 | if Is_Packed (Typ) then | |
8525 | return; | |
8526 | ||
8527 | elsif Has_Specified_Layout (Typ) then | |
8528 | return; | |
8529 | ||
8530 | elsif Component_Alignment (Typ) /= Calign_Default then | |
8531 | return; | |
8532 | ||
8533 | else | |
8534 | Set_Component_Alignment | |
8535 | (Typ, Scope_Stack.Table | |
8536 | (Scope_Stack.Last).Component_Alignment_Default); | |
8537 | end if; | |
8538 | end Set_Component_Alignment_If_Not_Set; | |
8539 | ||
220d1fd9 AC |
8540 | -------------------------- |
8541 | -- Set_SSO_From_Default -- | |
8542 | -------------------------- | |
8543 | ||
8544 | procedure Set_SSO_From_Default (T : Entity_Id) is | |
1a779058 AC |
8545 | Reversed : Boolean; |
8546 | ||
220d1fd9 | 8547 | begin |
bcdb6b04 AC |
8548 | -- Set default SSO for an array or record base type, except in case of |
8549 | -- a type extension (which always inherits the SSO of its parent type). | |
eefd2467 AC |
8550 | |
8551 | if Is_Base_Type (T) | |
8552 | and then (Is_Array_Type (T) | |
5e9d6f05 AC |
8553 | or else (Is_Record_Type (T) |
8554 | and then not (Is_Tagged_Type (T) | |
8555 | and then Is_Derived_Type (T)))) | |
220d1fd9 | 8556 | then |
1a779058 AC |
8557 | Reversed := |
8558 | (Bytes_Big_Endian and then SSO_Set_Low_By_Default (T)) | |
8559 | or else | |
8560 | (not Bytes_Big_Endian and then SSO_Set_High_By_Default (T)); | |
8561 | ||
8562 | if (SSO_Set_Low_By_Default (T) or else SSO_Set_High_By_Default (T)) | |
7ed57189 | 8563 | |
95e0ceef AC |
8564 | -- For a record type, if bit order is specified explicitly, |
8565 | -- then do not set SSO from default if not consistent. Note that | |
8566 | -- we do not want to look at a Bit_Order attribute definition | |
8567 | -- for a parent: if we were to inherit Bit_Order, then both | |
18dae814 RD |
8568 | -- SSO_Set_*_By_Default flags would have been cleared already |
8569 | -- (by Inherit_Aspects_At_Freeze_Point). | |
7ed57189 AC |
8570 | |
8571 | and then not | |
8572 | (Is_Record_Type (T) | |
95e0ceef AC |
8573 | and then |
8574 | Has_Rep_Item (T, Name_Bit_Order, Check_Parents => False) | |
1a779058 | 8575 | and then Reverse_Bit_Order (T) /= Reversed) |
220d1fd9 AC |
8576 | then |
8577 | -- If flags cause reverse storage order, then set the result. Note | |
8578 | -- that we would have ignored the pragma setting the non default | |
8579 | -- storage order in any case, hence the assertion at this point. | |
8580 | ||
1a779058 AC |
8581 | pragma Assert |
8582 | (not Reversed or else Support_Nondefault_SSO_On_Target); | |
8583 | ||
8584 | Set_Reverse_Storage_Order (T, Reversed); | |
7ed57189 | 8585 | |
1a779058 AC |
8586 | -- For a record type, also set reversed bit order. Note: if a bit |
8587 | -- order has been specified explicitly, then this is a no-op. | |
7ed57189 AC |
8588 | |
8589 | if Is_Record_Type (T) then | |
1a779058 | 8590 | Set_Reverse_Bit_Order (T, Reversed); |
7ed57189 | 8591 | end if; |
220d1fd9 AC |
8592 | end if; |
8593 | end if; | |
8594 | end Set_SSO_From_Default; | |
8595 | ||
c6823a20 EB |
8596 | ------------------ |
8597 | -- Undelay_Type -- | |
8598 | ------------------ | |
8599 | ||
8600 | procedure Undelay_Type (T : Entity_Id) is | |
8601 | begin | |
8602 | Set_Has_Delayed_Freeze (T, False); | |
8603 | Set_Freeze_Node (T, Empty); | |
8604 | ||
8605 | -- Since we don't want T to have a Freeze_Node, we don't want its | |
8606 | -- Full_View or Corresponding_Record_Type to have one either. | |
8607 | ||
e80f0cb0 | 8608 | -- ??? Fundamentally, this whole handling is unpleasant. What we really |
ee094616 RD |
8609 | -- want is to be sure that for an Itype that's part of record R and is a |
8610 | -- subtype of type T, that it's frozen after the later of the freeze | |
c6823a20 EB |
8611 | -- points of R and T. We have no way of doing that directly, so what we |
8612 | -- do is force most such Itypes to be frozen as part of freezing R via | |
8613 | -- this procedure and only delay the ones that need to be delayed | |
ee094616 RD |
8614 | -- (mostly the designated types of access types that are defined as part |
8615 | -- of the record). | |
c6823a20 EB |
8616 | |
8617 | if Is_Private_Type (T) | |
8618 | and then Present (Full_View (T)) | |
8619 | and then Is_Itype (Full_View (T)) | |
8620 | and then Is_Record_Type (Scope (Full_View (T))) | |
8621 | then | |
8622 | Undelay_Type (Full_View (T)); | |
8623 | end if; | |
8624 | ||
8625 | if Is_Concurrent_Type (T) | |
8626 | and then Present (Corresponding_Record_Type (T)) | |
8627 | and then Is_Itype (Corresponding_Record_Type (T)) | |
8628 | and then Is_Record_Type (Scope (Corresponding_Record_Type (T))) | |
8629 | then | |
8630 | Undelay_Type (Corresponding_Record_Type (T)); | |
8631 | end if; | |
8632 | end Undelay_Type; | |
8633 | ||
fbf5a39b AC |
8634 | ------------------ |
8635 | -- Warn_Overlay -- | |
8636 | ------------------ | |
8637 | ||
c31b57af | 8638 | procedure Warn_Overlay (Expr : Node_Id; Typ : Entity_Id; Nam : Entity_Id) is |
fbf5a39b | 8639 | Ent : constant Entity_Id := Entity (Nam); |
49e90211 | 8640 | -- The object to which the address clause applies |
fbf5a39b AC |
8641 | |
8642 | Init : Node_Id; | |
8643 | Old : Entity_Id := Empty; | |
8644 | Decl : Node_Id; | |
8645 | ||
8646 | begin | |
8647 | -- No warning if address clause overlay warnings are off | |
8648 | ||
8649 | if not Address_Clause_Overlay_Warnings then | |
8650 | return; | |
8651 | end if; | |
8652 | ||
8653 | -- No warning if there is an explicit initialization | |
8654 | ||
8655 | Init := Original_Node (Expression (Declaration_Node (Ent))); | |
8656 | ||
8657 | if Present (Init) and then Comes_From_Source (Init) then | |
8658 | return; | |
8659 | end if; | |
8660 | ||
edd63e9b | 8661 | -- We only give the warning for non-imported entities of a type for |
0ac73189 | 8662 | -- which a non-null base init proc is defined, or for objects of access |
a5d83d61 | 8663 | -- types with implicit null initialization, or when Normalize_Scalars |
0ac73189 AC |
8664 | -- applies and the type is scalar or a string type (the latter being |
8665 | -- tested for because predefined String types are initialized by inline | |
a5d83d61 AC |
8666 | -- code rather than by an init_proc). Note that we do not give the |
8667 | -- warning for Initialize_Scalars, since we suppressed initialization | |
e526d0c7 | 8668 | -- in this case. Also, do not warn if Suppress_Initialization is set. |
fbf5a39b AC |
8669 | |
8670 | if Present (Expr) | |
fbf5a39b | 8671 | and then not Is_Imported (Ent) |
e526d0c7 | 8672 | and then not Initialization_Suppressed (Typ) |
0ac73189 | 8673 | and then (Has_Non_Null_Base_Init_Proc (Typ) |
e526d0c7 AC |
8674 | or else Is_Access_Type (Typ) |
8675 | or else (Normalize_Scalars | |
8676 | and then (Is_Scalar_Type (Typ) | |
8677 | or else Is_String_Type (Typ)))) | |
fbf5a39b AC |
8678 | then |
8679 | if Nkind (Expr) = N_Attribute_Reference | |
8680 | and then Is_Entity_Name (Prefix (Expr)) | |
8681 | then | |
8682 | Old := Entity (Prefix (Expr)); | |
8683 | ||
8684 | elsif Is_Entity_Name (Expr) | |
8685 | and then Ekind (Entity (Expr)) = E_Constant | |
8686 | then | |
8687 | Decl := Declaration_Node (Entity (Expr)); | |
8688 | ||
8689 | if Nkind (Decl) = N_Object_Declaration | |
8690 | and then Present (Expression (Decl)) | |
8691 | and then Nkind (Expression (Decl)) = N_Attribute_Reference | |
8692 | and then Is_Entity_Name (Prefix (Expression (Decl))) | |
8693 | then | |
8694 | Old := Entity (Prefix (Expression (Decl))); | |
8695 | ||
8696 | elsif Nkind (Expr) = N_Function_Call then | |
8697 | return; | |
8698 | end if; | |
8699 | ||
ee094616 RD |
8700 | -- A function call (most likely to To_Address) is probably not an |
8701 | -- overlay, so skip warning. Ditto if the function call was inlined | |
8702 | -- and transformed into an entity. | |
fbf5a39b AC |
8703 | |
8704 | elsif Nkind (Original_Node (Expr)) = N_Function_Call then | |
8705 | return; | |
8706 | end if; | |
8707 | ||
fbf5a39b | 8708 | -- If a pragma Import follows, we assume that it is for the current |
ab260a3e ES |
8709 | -- target of the address clause, and skip the warning. There may be |
8710 | -- a source pragma or an aspect that specifies import and generates | |
8711 | -- the corresponding pragma. These will indicate that the entity is | |
8712 | -- imported and that is checked above so that the spurious warning | |
8713 | -- (generated when the entity is frozen) will be suppressed. The | |
8714 | -- pragma may be attached to the aspect, so it is not yet a list | |
8715 | -- member. | |
fbf5a39b | 8716 | |
2290a0fe AC |
8717 | if Is_List_Member (Parent (Expr)) then |
8718 | Decl := Next (Parent (Expr)); | |
8719 | ||
8720 | if Present (Decl) | |
8721 | and then Nkind (Decl) = N_Pragma | |
6e759c2a | 8722 | and then Pragma_Name (Decl) = Name_Import |
2290a0fe AC |
8723 | then |
8724 | return; | |
8725 | end if; | |
fbf5a39b AC |
8726 | end if; |
8727 | ||
2290a0fe AC |
8728 | -- Otherwise give warning message |
8729 | ||
fbf5a39b AC |
8730 | if Present (Old) then |
8731 | Error_Msg_Node_2 := Old; | |
8732 | Error_Msg_N | |
685bc70f | 8733 | ("default initialization of & may modify &??", |
fbf5a39b AC |
8734 | Nam); |
8735 | else | |
8736 | Error_Msg_N | |
685bc70f | 8737 | ("default initialization of & may modify overlaid storage??", |
fbf5a39b AC |
8738 | Nam); |
8739 | end if; | |
8740 | ||
8741 | -- Add friendly warning if initialization comes from a packed array | |
8742 | -- component. | |
8743 | ||
be035558 | 8744 | if Is_Record_Type (Typ) then |
fbf5a39b AC |
8745 | declare |
8746 | Comp : Entity_Id; | |
8747 | ||
8748 | begin | |
8749 | Comp := First_Component (Typ); | |
fbf5a39b AC |
8750 | while Present (Comp) loop |
8751 | if Nkind (Parent (Comp)) = N_Component_Declaration | |
8752 | and then Present (Expression (Parent (Comp))) | |
8753 | then | |
8754 | exit; | |
8755 | elsif Is_Array_Type (Etype (Comp)) | |
8ca597af | 8756 | and then Present (Packed_Array_Impl_Type (Etype (Comp))) |
fbf5a39b AC |
8757 | then |
8758 | Error_Msg_NE | |
3f1ede06 | 8759 | ("\packed array component& " & |
685bc70f | 8760 | "will be initialized to zero??", |
3f1ede06 | 8761 | Nam, Comp); |
fbf5a39b AC |
8762 | exit; |
8763 | else | |
8764 | Next_Component (Comp); | |
8765 | end if; | |
8766 | end loop; | |
8767 | end; | |
8768 | end if; | |
8769 | ||
8770 | Error_Msg_N | |
3f1ede06 | 8771 | ("\use pragma Import for & to " & |
685bc70f | 8772 | "suppress initialization (RM B.1(24))??", |
3f1ede06 | 8773 | Nam); |
fbf5a39b AC |
8774 | end if; |
8775 | end Warn_Overlay; | |
8776 | ||
70482933 | 8777 | end Freeze; |