| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- F R E E Z E -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with 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 Einfo.Entities; use Einfo.Entities; |
| 33 |
with Einfo.Utils; use Einfo.Utils; |
| 34 |
with Elists; use Elists; |
| 35 |
with Errout; use Errout; |
| 36 |
with Exp_Ch7; use Exp_Ch7; |
| 37 |
with Exp_Disp; use Exp_Disp; |
| 38 |
with Exp_Pakd; use Exp_Pakd; |
| 39 |
with Exp_Util; use Exp_Util; |
| 40 |
with Exp_Tss; use Exp_Tss; |
| 41 |
with Ghost; use Ghost; |
| 42 |
with Layout; use Layout; |
| 43 |
with Lib; use Lib; |
| 44 |
with Local_Restrict; |
| 45 |
with Namet; use Namet; |
| 46 |
with Nlists; use Nlists; |
| 47 |
with Nmake; use Nmake; |
| 48 |
with Opt; use Opt; |
| 49 |
with Restrict; use Restrict; |
| 50 |
with Rident; use Rident; |
| 51 |
with Rtsfind; use Rtsfind; |
| 52 |
with Sem; use Sem; |
| 53 |
with Sem_Aux; use Sem_Aux; |
| 54 |
with Sem_Cat; use Sem_Cat; |
| 55 |
with Sem_Ch3; use Sem_Ch3; |
| 56 |
with Sem_Ch6; use Sem_Ch6; |
| 57 |
with Sem_Ch7; use Sem_Ch7; |
| 58 |
with Sem_Ch8; use Sem_Ch8; |
| 59 |
with Sem_Ch13; use Sem_Ch13; |
| 60 |
with Sem_Disp; use Sem_Disp; |
| 61 |
with Sem_Eval; use Sem_Eval; |
| 62 |
with Sem_Mech; use Sem_Mech; |
| 63 |
with Sem_Prag; use Sem_Prag; |
| 64 |
with Sem_Res; use Sem_Res; |
| 65 |
with Sem_Util; use Sem_Util; |
| 66 |
with Sinfo; use Sinfo; |
| 67 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 68 |
with Sinfo.Utils; use Sinfo.Utils; |
| 69 |
with Snames; use Snames; |
| 70 |
with Stand; use Stand; |
| 71 |
with Stringt; use Stringt; |
| 72 |
with Strub; use Strub; |
| 73 |
with Targparm; use Targparm; |
| 74 |
with Tbuild; use Tbuild; |
| 75 |
with Ttypes; use Ttypes; |
| 76 |
with Uintp; use Uintp; |
| 77 |
with Urealp; use Urealp; |
| 78 |
with Warnsw; use Warnsw; |
| 79 |
|
| 80 |
package body Freeze is |
| 81 |
|
| 82 |
----------------------- |
| 83 |
-- Local Subprograms -- |
| 84 |
----------------------- |
| 85 |
|
| 86 |
procedure Adjust_Esize_For_Alignment (Typ : Entity_Id); |
| 87 |
-- Typ is a type that is being frozen. If no size clause is given, |
| 88 |
-- but a default Esize has been computed, then this default Esize is |
| 89 |
-- adjusted up if necessary to be consistent with a given alignment, |
| 90 |
-- but never to a value greater than System_Max_Integer_Size. This is |
| 91 |
-- used for all discrete types and for fixed-point types. |
| 92 |
|
| 93 |
procedure Build_And_Analyze_Renamed_Body |
| 94 |
(Decl : Node_Id; |
| 95 |
New_S : Entity_Id; |
| 96 |
After : in out Node_Id); |
| 97 |
-- Build body for a renaming declaration, insert in tree and analyze |
| 98 |
|
| 99 |
procedure Check_Address_Clause (E : Entity_Id); |
| 100 |
-- Apply legality checks to address clauses for object declarations, |
| 101 |
-- at the point the object is frozen. |
| 102 |
|
| 103 |
procedure Check_Component_Storage_Order |
| 104 |
(Encl_Type : Entity_Id; |
| 105 |
Comp : Entity_Id; |
| 106 |
ADC : Node_Id; |
| 107 |
Comp_ADC_Present : out Boolean); |
| 108 |
-- For an Encl_Type that has a Scalar_Storage_Order attribute definition |
| 109 |
-- clause, verify that the component type has an explicit and compatible |
| 110 |
-- attribute/aspect. For arrays, Comp is Empty; for records, it is the |
| 111 |
-- entity of the component under consideration. For an Encl_Type that |
| 112 |
-- does not have a Scalar_Storage_Order attribute definition clause, |
| 113 |
-- verify that the component also does not have such a clause. |
| 114 |
-- ADC is the attribute definition clause if present (or Empty). On return, |
| 115 |
-- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order |
| 116 |
-- attribute definition clause. |
| 117 |
|
| 118 |
procedure Check_Debug_Info_Needed (T : Entity_Id); |
| 119 |
-- As each entity is frozen, this routine is called to deal with the |
| 120 |
-- setting of Debug_Info_Needed for the entity. This flag is set if |
| 121 |
-- the entity comes from source, or if we are in Debug_Generated_Code |
| 122 |
-- mode or if the -gnatdV debug flag is set. However, it never sets |
| 123 |
-- the flag if Debug_Info_Off is set. This procedure also ensures that |
| 124 |
-- subsidiary entities have the flag set as required. |
| 125 |
|
| 126 |
procedure Check_Expression_Function (N : Node_Id; Nam : Entity_Id); |
| 127 |
-- When an expression function is frozen by a use of it, the expression |
| 128 |
-- itself is frozen. Check that the expression does not include references |
| 129 |
-- to deferred constants without completion. We report this at the freeze |
| 130 |
-- point of the function, to provide a better error message. |
| 131 |
-- |
| 132 |
-- In most cases the expression itself is frozen by the time the function |
| 133 |
-- itself is frozen, because the formals will be frozen by then. However, |
| 134 |
-- Attribute references to outer types are freeze points for those types; |
| 135 |
-- this routine generates the required freeze nodes for them. |
| 136 |
|
| 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; |
| 151 |
N : Node_Id; |
| 152 |
Result : in out List_Id); |
| 153 |
-- Freezes Ent using Freeze_Entity, and appends the resulting list of |
| 154 |
-- nodes to Result, modifying Result from No_List if necessary. N has |
| 155 |
-- the same usage as in Freeze_Entity. |
| 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 |
|
| 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; |
| 179 |
-- True if T is not private and has no private components, or has a full |
| 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. |
| 185 |
|
| 186 |
procedure Process_Default_Expressions |
| 187 |
(E : Entity_Id; |
| 188 |
After : in out Node_Id); |
| 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 preanalyzed). 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). |
| 198 |
|
| 199 |
procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id); |
| 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. |
| 203 |
|
| 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 |
|
| 212 |
function Should_Freeze_Type |
| 213 |
(Typ : Entity_Id; |
| 214 |
E : Entity_Id; |
| 215 |
N : Node_Id) return Boolean; |
| 216 |
-- True if Typ should be frozen when the profile of E is being frozen at N. |
| 217 |
|
| 218 |
-- ??? Expression functions that are not completions shouldn't freeze types |
| 219 |
-- but our current expansion and freezing model requires an early freezing |
| 220 |
-- when the tag of Typ is needed or for an aggregate with a subtype of Typ, |
| 221 |
-- so we return True in these cases. |
| 222 |
|
| 223 |
procedure Undelay_Type (T : Entity_Id); |
| 224 |
-- T is a type of a component that we know to be an Itype. We don't want |
| 225 |
-- this to have a Freeze_Node, so ensure it doesn't. Do the same for any |
| 226 |
-- Full_View or Corresponding_Record_Type. |
| 227 |
|
| 228 |
procedure Warn_Overlay (Expr : Node_Id; Typ : Entity_Id; Nam : Node_Id); |
| 229 |
-- Expr is the expression for an address clause for the entity denoted by |
| 230 |
-- Nam whose type is Typ. If Typ has a default initialization, and there is |
| 231 |
-- no explicit initialization in the source declaration, check whether the |
| 232 |
-- address clause might cause overlaying of an entity, and emit a warning |
| 233 |
-- on the side effect that the initialization will cause. |
| 234 |
|
| 235 |
------------------------------- |
| 236 |
-- Adjust_Esize_For_Alignment -- |
| 237 |
------------------------------- |
| 238 |
|
| 239 |
procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is |
| 240 |
Align : Uint; |
| 241 |
|
| 242 |
begin |
| 243 |
if Known_Esize (Typ) and then Known_Alignment (Typ) then |
| 244 |
Align := Alignment_In_Bits (Typ); |
| 245 |
|
| 246 |
if Align > Esize (Typ) then |
| 247 |
if Align > System_Max_Integer_Size then |
| 248 |
pragma Assert (Serious_Errors_Detected > 0); |
| 249 |
else |
| 250 |
Set_Esize (Typ, Align); |
| 251 |
end if; |
| 252 |
end if; |
| 253 |
end if; |
| 254 |
end Adjust_Esize_For_Alignment; |
| 255 |
|
| 256 |
------------------------------------ |
| 257 |
-- Build_And_Analyze_Renamed_Body -- |
| 258 |
------------------------------------ |
| 259 |
|
| 260 |
procedure Build_And_Analyze_Renamed_Body |
| 261 |
(Decl : Node_Id; |
| 262 |
New_S : Entity_Id; |
| 263 |
After : in out Node_Id) |
| 264 |
is |
| 265 |
Body_Decl : constant Node_Id := Unit_Declaration_Node (New_S); |
| 266 |
Ent : constant Entity_Id := Defining_Entity (Decl); |
| 267 |
Body_Node : Node_Id; |
| 268 |
Renamed_Subp : Entity_Id; |
| 269 |
|
| 270 |
begin |
| 271 |
-- If the renamed subprogram is intrinsic, there is no need for a |
| 272 |
-- wrapper body: we set the alias that will be called and expanded which |
| 273 |
-- completes the declaration. This transformation is only legal if the |
| 274 |
-- renamed entity has already been elaborated. |
| 275 |
|
| 276 |
-- Note that it is legal for a renaming_as_body to rename an intrinsic |
| 277 |
-- subprogram, as long as the renaming occurs before the new entity |
| 278 |
-- is frozen (RM 8.5.4 (5)). |
| 279 |
|
| 280 |
if Nkind (Body_Decl) = N_Subprogram_Renaming_Declaration |
| 281 |
and then Is_Entity_Name (Name (Body_Decl)) |
| 282 |
then |
| 283 |
Renamed_Subp := Entity (Name (Body_Decl)); |
| 284 |
else |
| 285 |
Renamed_Subp := Empty; |
| 286 |
end if; |
| 287 |
|
| 288 |
if Present (Renamed_Subp) |
| 289 |
and then Is_Intrinsic_Subprogram (Renamed_Subp) |
| 290 |
and then |
| 291 |
(not In_Same_Source_Unit (Renamed_Subp, Ent) |
| 292 |
or else Sloc (Renamed_Subp) < Sloc (Ent)) |
| 293 |
|
| 294 |
-- We can make the renaming entity intrinsic if the renamed function |
| 295 |
-- has an interface name, or if it is one of the shift/rotate |
| 296 |
-- operations known to the compiler. |
| 297 |
|
| 298 |
and then |
| 299 |
(Present (Interface_Name (Renamed_Subp)) |
| 300 |
or else Chars (Renamed_Subp) in Name_Rotate_Left |
| 301 |
| Name_Rotate_Right |
| 302 |
| Name_Shift_Left |
| 303 |
| Name_Shift_Right |
| 304 |
| Name_Shift_Right_Arithmetic) |
| 305 |
then |
| 306 |
Set_Interface_Name (Ent, Interface_Name (Renamed_Subp)); |
| 307 |
|
| 308 |
if Present (Alias (Renamed_Subp)) then |
| 309 |
Set_Alias (Ent, Alias (Renamed_Subp)); |
| 310 |
else |
| 311 |
Set_Alias (Ent, Renamed_Subp); |
| 312 |
end if; |
| 313 |
|
| 314 |
Set_Is_Intrinsic_Subprogram (Ent); |
| 315 |
Set_Has_Completion (Ent); |
| 316 |
|
| 317 |
else |
| 318 |
Body_Node := Build_Renamed_Body (Decl, New_S); |
| 319 |
Insert_After (After, Body_Node); |
| 320 |
Mark_Rewrite_Insertion (Body_Node); |
| 321 |
Analyze (Body_Node); |
| 322 |
After := Body_Node; |
| 323 |
end if; |
| 324 |
end Build_And_Analyze_Renamed_Body; |
| 325 |
|
| 326 |
------------------------ |
| 327 |
-- Build_Renamed_Body -- |
| 328 |
------------------------ |
| 329 |
|
| 330 |
function Build_Renamed_Body |
| 331 |
(Decl : Node_Id; |
| 332 |
New_S : Entity_Id) return Node_Id |
| 333 |
is |
| 334 |
Loc : constant Source_Ptr := Sloc (New_S); |
| 335 |
-- We use for the source location of the renamed body, the location of |
| 336 |
-- the spec entity. It might seem more natural to use the location of |
| 337 |
-- the renaming declaration itself, but that would be wrong, since then |
| 338 |
-- the body we create would look as though it was created far too late, |
| 339 |
-- and this could cause problems with elaboration order analysis, |
| 340 |
-- particularly in connection with instantiations. |
| 341 |
|
| 342 |
N : constant Node_Id := Unit_Declaration_Node (New_S); |
| 343 |
Nam : constant Node_Id := Name (N); |
| 344 |
Old_S : Entity_Id; |
| 345 |
Spec : constant Node_Id := New_Copy_Tree (Specification (Decl)); |
| 346 |
Actuals : List_Id; |
| 347 |
Call_Node : Node_Id; |
| 348 |
Call_Name : Node_Id; |
| 349 |
Body_Node : Node_Id; |
| 350 |
Formal : Entity_Id; |
| 351 |
O_Formal : Entity_Id; |
| 352 |
Param_Spec : Node_Id; |
| 353 |
|
| 354 |
Pref : Node_Id := Empty; |
| 355 |
-- If the renamed entity is a primitive operation given in prefix form, |
| 356 |
-- the prefix is the target object and it has to be added as the first |
| 357 |
-- actual in the generated call. |
| 358 |
|
| 359 |
begin |
| 360 |
-- Determine the entity being renamed, which is the target of the call |
| 361 |
-- statement. If the name is an explicit dereference, this is a renaming |
| 362 |
-- of a subprogram type rather than a subprogram. The name itself is |
| 363 |
-- fully analyzed. |
| 364 |
|
| 365 |
if Nkind (Nam) = N_Selected_Component then |
| 366 |
Old_S := Entity (Selector_Name (Nam)); |
| 367 |
|
| 368 |
elsif Nkind (Nam) = N_Explicit_Dereference then |
| 369 |
Old_S := Etype (Nam); |
| 370 |
|
| 371 |
elsif Nkind (Nam) = N_Indexed_Component then |
| 372 |
if Is_Entity_Name (Prefix (Nam)) then |
| 373 |
Old_S := Entity (Prefix (Nam)); |
| 374 |
else |
| 375 |
Old_S := Entity (Selector_Name (Prefix (Nam))); |
| 376 |
end if; |
| 377 |
|
| 378 |
elsif Nkind (Nam) = N_Character_Literal then |
| 379 |
Old_S := Etype (New_S); |
| 380 |
|
| 381 |
else |
| 382 |
Old_S := Entity (Nam); |
| 383 |
end if; |
| 384 |
|
| 385 |
if Is_Entity_Name (Nam) then |
| 386 |
|
| 387 |
-- If the renamed entity is a predefined operator, retain full name |
| 388 |
-- to ensure its visibility. |
| 389 |
|
| 390 |
if Ekind (Old_S) = E_Operator |
| 391 |
and then Nkind (Nam) = N_Expanded_Name |
| 392 |
then |
| 393 |
Call_Name := New_Copy (Name (N)); |
| 394 |
else |
| 395 |
Call_Name := New_Occurrence_Of (Old_S, Loc); |
| 396 |
end if; |
| 397 |
|
| 398 |
else |
| 399 |
if Nkind (Nam) = N_Selected_Component |
| 400 |
and then Present (First_Formal (Old_S)) |
| 401 |
and then |
| 402 |
(Is_Controlling_Formal (First_Formal (Old_S)) |
| 403 |
or else Is_Class_Wide_Type (Etype (First_Formal (Old_S)))) |
| 404 |
then |
| 405 |
|
| 406 |
-- Retrieve the target object, to be added as a first actual |
| 407 |
-- in the call. |
| 408 |
|
| 409 |
Call_Name := New_Occurrence_Of (Old_S, Loc); |
| 410 |
Pref := Prefix (Nam); |
| 411 |
|
| 412 |
else |
| 413 |
Call_Name := New_Copy (Name (N)); |
| 414 |
end if; |
| 415 |
|
| 416 |
-- Original name may have been overloaded, but is fully resolved now |
| 417 |
|
| 418 |
Set_Is_Overloaded (Call_Name, False); |
| 419 |
end if; |
| 420 |
|
| 421 |
if Nkind (Decl) /= N_Subprogram_Declaration then |
| 422 |
Rewrite (N, |
| 423 |
Make_Subprogram_Declaration (Loc, |
| 424 |
Specification => Specification (N))); |
| 425 |
end if; |
| 426 |
|
| 427 |
-- For simple renamings, subsequent calls can be expanded directly as |
| 428 |
-- calls to the renamed entity. The body must be generated in any case |
| 429 |
-- for calls that may appear elsewhere. This is not done in the case |
| 430 |
-- where the subprogram is an instantiation because the actual proper |
| 431 |
-- body has not been built yet. |
| 432 |
|
| 433 |
if Ekind (Old_S) in E_Function | E_Procedure |
| 434 |
and then not Is_Generic_Instance (Old_S) |
| 435 |
then |
| 436 |
Set_Body_To_Inline (Decl, Old_S); |
| 437 |
end if; |
| 438 |
|
| 439 |
-- Check whether the return type is a limited view. If the subprogram |
| 440 |
-- is already frozen the generated body may have a non-limited view |
| 441 |
-- of the type, that must be used, because it is the one in the spec |
| 442 |
-- of the renaming declaration. |
| 443 |
|
| 444 |
if Ekind (Old_S) = E_Function |
| 445 |
and then Is_Entity_Name (Result_Definition (Spec)) |
| 446 |
then |
| 447 |
declare |
| 448 |
Ret_Type : constant Entity_Id := Etype (Result_Definition (Spec)); |
| 449 |
begin |
| 450 |
if Has_Non_Limited_View (Ret_Type) then |
| 451 |
Set_Result_Definition |
| 452 |
(Spec, New_Occurrence_Of (Non_Limited_View (Ret_Type), Loc)); |
| 453 |
end if; |
| 454 |
end; |
| 455 |
end if; |
| 456 |
|
| 457 |
-- The body generated for this renaming is an internal artifact, and |
| 458 |
-- does not constitute a freeze point for the called entity. |
| 459 |
|
| 460 |
Set_Must_Not_Freeze (Call_Name); |
| 461 |
|
| 462 |
Formal := First_Formal (Defining_Entity (Decl)); |
| 463 |
|
| 464 |
if Present (Pref) then |
| 465 |
declare |
| 466 |
Pref_Type : constant Entity_Id := Etype (Pref); |
| 467 |
Form_Type : constant Entity_Id := Etype (First_Formal (Old_S)); |
| 468 |
|
| 469 |
begin |
| 470 |
-- The controlling formal may be an access parameter, or the |
| 471 |
-- actual may be an access value, so adjust accordingly. |
| 472 |
|
| 473 |
if Is_Access_Type (Pref_Type) |
| 474 |
and then not Is_Access_Type (Form_Type) |
| 475 |
then |
| 476 |
Actuals := New_List |
| 477 |
(Make_Explicit_Dereference (Loc, Relocate_Node (Pref))); |
| 478 |
|
| 479 |
elsif Is_Access_Type (Form_Type) |
| 480 |
and then not Is_Access_Type (Pref) |
| 481 |
then |
| 482 |
Actuals := |
| 483 |
New_List ( |
| 484 |
Make_Attribute_Reference (Loc, |
| 485 |
Attribute_Name => Name_Access, |
| 486 |
Prefix => Relocate_Node (Pref))); |
| 487 |
else |
| 488 |
Actuals := New_List (Pref); |
| 489 |
end if; |
| 490 |
end; |
| 491 |
|
| 492 |
elsif Present (Formal) then |
| 493 |
Actuals := New_List; |
| 494 |
|
| 495 |
else |
| 496 |
Actuals := No_List; |
| 497 |
end if; |
| 498 |
|
| 499 |
while Present (Formal) loop |
| 500 |
Append (New_Occurrence_Of (Formal, Loc), Actuals); |
| 501 |
Next_Formal (Formal); |
| 502 |
end loop; |
| 503 |
|
| 504 |
-- If the renamed entity is an entry, inherit its profile. For other |
| 505 |
-- renamings as bodies, both profiles must be subtype conformant, so it |
| 506 |
-- is not necessary to replace the profile given in the declaration. |
| 507 |
-- However, default values that are aggregates are rewritten when |
| 508 |
-- partially analyzed, so we recover the original aggregate to insure |
| 509 |
-- that subsequent conformity checking works. Similarly, if the default |
| 510 |
-- expression was constant-folded, recover the original expression. |
| 511 |
|
| 512 |
Formal := First_Formal (Defining_Entity (Decl)); |
| 513 |
|
| 514 |
if Present (Formal) then |
| 515 |
O_Formal := First_Formal (Old_S); |
| 516 |
Param_Spec := First (Parameter_Specifications (Spec)); |
| 517 |
while Present (Formal) loop |
| 518 |
if Is_Entry (Old_S) then |
| 519 |
if Nkind (Parameter_Type (Param_Spec)) /= |
| 520 |
N_Access_Definition |
| 521 |
then |
| 522 |
Set_Etype (Formal, Etype (O_Formal)); |
| 523 |
Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal)); |
| 524 |
end if; |
| 525 |
|
| 526 |
elsif Nkind (Default_Value (O_Formal)) = N_Aggregate |
| 527 |
or else Nkind (Original_Node (Default_Value (O_Formal))) /= |
| 528 |
Nkind (Default_Value (O_Formal)) |
| 529 |
then |
| 530 |
Set_Expression (Param_Spec, |
| 531 |
New_Copy_Tree (Original_Node (Default_Value (O_Formal)))); |
| 532 |
end if; |
| 533 |
|
| 534 |
Next_Formal (Formal); |
| 535 |
Next_Formal (O_Formal); |
| 536 |
Next (Param_Spec); |
| 537 |
end loop; |
| 538 |
end if; |
| 539 |
|
| 540 |
-- If the renamed entity is a function, the generated body contains a |
| 541 |
-- return statement. Otherwise, build a procedure call. If the entity is |
| 542 |
-- an entry, subsequent analysis of the call will transform it into the |
| 543 |
-- proper entry or protected operation call. If the renamed entity is |
| 544 |
-- a character literal, return it directly. |
| 545 |
|
| 546 |
if Ekind (Old_S) = E_Function |
| 547 |
or else Ekind (Old_S) = E_Operator |
| 548 |
or else (Ekind (Old_S) = E_Subprogram_Type |
| 549 |
and then Etype (Old_S) /= Standard_Void_Type) |
| 550 |
then |
| 551 |
Call_Node := |
| 552 |
Make_Simple_Return_Statement (Loc, |
| 553 |
Expression => |
| 554 |
Make_Function_Call (Loc, |
| 555 |
Name => Call_Name, |
| 556 |
Parameter_Associations => Actuals)); |
| 557 |
|
| 558 |
elsif Ekind (Old_S) = E_Enumeration_Literal then |
| 559 |
Call_Node := |
| 560 |
Make_Simple_Return_Statement (Loc, |
| 561 |
Expression => New_Occurrence_Of (Old_S, Loc)); |
| 562 |
|
| 563 |
elsif Nkind (Nam) = N_Character_Literal then |
| 564 |
Call_Node := |
| 565 |
Make_Simple_Return_Statement (Loc, Expression => Call_Name); |
| 566 |
|
| 567 |
else |
| 568 |
Call_Node := |
| 569 |
Make_Procedure_Call_Statement (Loc, |
| 570 |
Name => Call_Name, |
| 571 |
Parameter_Associations => Actuals); |
| 572 |
end if; |
| 573 |
|
| 574 |
-- Create entities for subprogram body and formals |
| 575 |
|
| 576 |
Set_Defining_Unit_Name (Spec, |
| 577 |
Make_Defining_Identifier (Loc, Chars => Chars (New_S))); |
| 578 |
|
| 579 |
Param_Spec := First (Parameter_Specifications (Spec)); |
| 580 |
while Present (Param_Spec) loop |
| 581 |
Set_Defining_Identifier (Param_Spec, |
| 582 |
Make_Defining_Identifier (Loc, |
| 583 |
Chars => Chars (Defining_Identifier (Param_Spec)))); |
| 584 |
Next (Param_Spec); |
| 585 |
end loop; |
| 586 |
|
| 587 |
-- Copy SPARK pragma from renaming declaration |
| 588 |
|
| 589 |
Set_SPARK_Pragma |
| 590 |
(Defining_Unit_Name (Spec), SPARK_Pragma (New_S)); |
| 591 |
Set_SPARK_Pragma_Inherited |
| 592 |
(Defining_Unit_Name (Spec), SPARK_Pragma_Inherited (New_S)); |
| 593 |
|
| 594 |
-- In GNATprove, prefer to generate an expression function whenever |
| 595 |
-- possible, to benefit from the more precise analysis in that case |
| 596 |
-- (as if an implicit postcondition had been generated). |
| 597 |
|
| 598 |
if GNATprove_Mode |
| 599 |
and then Nkind (Call_Node) = N_Simple_Return_Statement |
| 600 |
then |
| 601 |
Body_Node := |
| 602 |
Make_Expression_Function (Loc, |
| 603 |
Specification => Spec, |
| 604 |
Expression => Expression (Call_Node)); |
| 605 |
else |
| 606 |
Body_Node := |
| 607 |
Make_Subprogram_Body (Loc, |
| 608 |
Specification => Spec, |
| 609 |
Declarations => New_List, |
| 610 |
Handled_Statement_Sequence => |
| 611 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 612 |
Statements => New_List (Call_Node))); |
| 613 |
end if; |
| 614 |
|
| 615 |
-- Link the body to the entity whose declaration it completes. If |
| 616 |
-- the body is analyzed when the renamed entity is frozen, it may |
| 617 |
-- be necessary to restore the proper scope (see package Exp_Ch13). |
| 618 |
|
| 619 |
if Nkind (N) = N_Subprogram_Renaming_Declaration |
| 620 |
and then Present (Corresponding_Spec (N)) |
| 621 |
then |
| 622 |
Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N)); |
| 623 |
else |
| 624 |
Set_Corresponding_Spec (Body_Node, New_S); |
| 625 |
end if; |
| 626 |
|
| 627 |
return Body_Node; |
| 628 |
end Build_Renamed_Body; |
| 629 |
|
| 630 |
-------------------------- |
| 631 |
-- Check_Address_Clause -- |
| 632 |
-------------------------- |
| 633 |
|
| 634 |
procedure Check_Address_Clause (E : Entity_Id) is |
| 635 |
Addr : constant Node_Id := Address_Clause (E); |
| 636 |
Typ : constant Entity_Id := Etype (E); |
| 637 |
|
| 638 |
Decl : Node_Id; |
| 639 |
Expr : Node_Id; |
| 640 |
Init : Node_Id; |
| 641 |
|
| 642 |
begin |
| 643 |
if Present (Addr) then |
| 644 |
|
| 645 |
-- For a deferred constant, the initialization value is on full view |
| 646 |
|
| 647 |
if Ekind (E) = E_Constant and then Present (Full_View (E)) then |
| 648 |
Decl := Declaration_Node (Full_View (E)); |
| 649 |
else |
| 650 |
Decl := Declaration_Node (E); |
| 651 |
end if; |
| 652 |
|
| 653 |
Expr := Expression (Addr); |
| 654 |
|
| 655 |
if Needs_Constant_Address (Decl, Typ) then |
| 656 |
Check_Constant_Address_Clause (Expr, E); |
| 657 |
|
| 658 |
-- Has_Delayed_Freeze was set on E when the address clause was |
| 659 |
-- analyzed, and must remain set because we want the address |
| 660 |
-- clause to be elaborated only after any entity it references |
| 661 |
-- has been elaborated. |
| 662 |
end if; |
| 663 |
|
| 664 |
-- If Rep_Clauses are to be ignored, remove address clause from |
| 665 |
-- list attached to entity, because it may be illegal for gigi, |
| 666 |
-- for example by breaking order of elaboration. |
| 667 |
|
| 668 |
if Ignore_Rep_Clauses then |
| 669 |
declare |
| 670 |
Rep : Node_Id; |
| 671 |
|
| 672 |
begin |
| 673 |
Rep := First_Rep_Item (E); |
| 674 |
|
| 675 |
if Rep = Addr then |
| 676 |
Set_First_Rep_Item (E, Next_Rep_Item (Addr)); |
| 677 |
|
| 678 |
else |
| 679 |
while Present (Rep) |
| 680 |
and then Next_Rep_Item (Rep) /= Addr |
| 681 |
loop |
| 682 |
Next_Rep_Item (Rep); |
| 683 |
end loop; |
| 684 |
end if; |
| 685 |
|
| 686 |
if Present (Rep) then |
| 687 |
Set_Next_Rep_Item (Rep, Next_Rep_Item (Addr)); |
| 688 |
end if; |
| 689 |
end; |
| 690 |
|
| 691 |
-- And now remove the address clause |
| 692 |
|
| 693 |
Kill_Rep_Clause (Addr); |
| 694 |
|
| 695 |
elsif not Error_Posted (Expr) |
| 696 |
and then not Needs_Finalization (Typ) |
| 697 |
then |
| 698 |
Warn_Overlay (Expr, Typ, Name (Addr)); |
| 699 |
end if; |
| 700 |
|
| 701 |
Init := Expression (Decl); |
| 702 |
|
| 703 |
-- If a variable, or a non-imported constant, overlays a constant |
| 704 |
-- object and has an initialization value, then the initialization |
| 705 |
-- may end up writing into read-only memory. Detect the cases of |
| 706 |
-- statically identical values and remove the initialization. In |
| 707 |
-- the other cases, give a warning. We will give other warnings |
| 708 |
-- later for the variable if it is assigned. |
| 709 |
|
| 710 |
if (Ekind (E) = E_Variable |
| 711 |
or else (Ekind (E) = E_Constant |
| 712 |
and then not Is_Imported (E))) |
| 713 |
and then Overlays_Constant (E) |
| 714 |
and then Present (Init) |
| 715 |
then |
| 716 |
declare |
| 717 |
O_Ent : Entity_Id; |
| 718 |
Off : Boolean; |
| 719 |
|
| 720 |
begin |
| 721 |
Find_Overlaid_Entity (Addr, O_Ent, Off); |
| 722 |
|
| 723 |
if Ekind (O_Ent) = E_Constant |
| 724 |
and then Etype (O_Ent) = Typ |
| 725 |
and then Present (Constant_Value (O_Ent)) |
| 726 |
and then Compile_Time_Compare |
| 727 |
(Init, |
| 728 |
Constant_Value (O_Ent), |
| 729 |
Assume_Valid => True) = EQ |
| 730 |
then |
| 731 |
Set_No_Initialization (Decl); |
| 732 |
return; |
| 733 |
|
| 734 |
elsif Comes_From_Source (Init) |
| 735 |
and then Address_Clause_Overlay_Warnings |
| 736 |
then |
| 737 |
Error_Msg_Sloc := Sloc (Addr); |
| 738 |
Error_Msg_NE |
| 739 |
("?o?constant& may be modified via address clause#", |
| 740 |
Decl, O_Ent); |
| 741 |
end if; |
| 742 |
end; |
| 743 |
end if; |
| 744 |
end if; |
| 745 |
end Check_Address_Clause; |
| 746 |
|
| 747 |
----------------------------- |
| 748 |
-- Check_Compile_Time_Size -- |
| 749 |
----------------------------- |
| 750 |
|
| 751 |
procedure Check_Compile_Time_Size (T : Entity_Id) is |
| 752 |
|
| 753 |
procedure Set_Small_Size (T : Entity_Id; S : Uint); |
| 754 |
-- Sets the compile time known size in the RM_Size field of T, checking |
| 755 |
-- for a size clause that was given which attempts to give a small size. |
| 756 |
|
| 757 |
function Size_Known (T : Entity_Id) return Boolean; |
| 758 |
-- Recursive function that does all the work |
| 759 |
|
| 760 |
function Static_Discriminated_Components (T : Entity_Id) return Boolean; |
| 761 |
-- If T is a constrained subtype, its size is not known if any of its |
| 762 |
-- discriminant constraints is not static and it is not a null record. |
| 763 |
-- The test is conservative and doesn't check that the components are |
| 764 |
-- in fact constrained by non-static discriminant values. Could be made |
| 765 |
-- more precise ??? |
| 766 |
|
| 767 |
function Value_Known (Exp : Node_Id) return Boolean; |
| 768 |
-- Return True if the value of expression Exp is known at compile time |
| 769 |
|
| 770 |
-------------------- |
| 771 |
-- Set_Small_Size -- |
| 772 |
-------------------- |
| 773 |
|
| 774 |
procedure Set_Small_Size (T : Entity_Id; S : Uint) is |
| 775 |
begin |
| 776 |
if S > System_Max_Integer_Size then |
| 777 |
return; |
| 778 |
|
| 779 |
-- Check for bad size clause given |
| 780 |
|
| 781 |
elsif Has_Size_Clause (T) then |
| 782 |
if RM_Size (T) < S then |
| 783 |
Error_Msg_Uint_1 := S; |
| 784 |
Error_Msg_NE (Size_Too_Small_Message, Size_Clause (T), T); |
| 785 |
end if; |
| 786 |
|
| 787 |
-- Set size if not set already. Do not set it to Uint_0, because in |
| 788 |
-- some cases (notably array-of-record), the Component_Size is |
| 789 |
-- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and |
| 790 |
-- Component_Size will eventually be set correctly by the back end. |
| 791 |
|
| 792 |
elsif not Known_RM_Size (T) and then S /= Uint_0 then |
| 793 |
Set_RM_Size (T, S); |
| 794 |
end if; |
| 795 |
end Set_Small_Size; |
| 796 |
|
| 797 |
---------------- |
| 798 |
-- Size_Known -- |
| 799 |
---------------- |
| 800 |
|
| 801 |
function Size_Known (T : Entity_Id) return Boolean is |
| 802 |
Comp : Entity_Id; |
| 803 |
Ctyp : Entity_Id; |
| 804 |
|
| 805 |
begin |
| 806 |
if Size_Known_At_Compile_Time (T) then |
| 807 |
return True; |
| 808 |
|
| 809 |
-- Always True for elementary types, even generic formal elementary |
| 810 |
-- types. We used to return False in the latter case, but the size |
| 811 |
-- is known at compile time, even in the template, we just do not |
| 812 |
-- know the exact size but that's not the point of this routine. |
| 813 |
|
| 814 |
elsif Is_Elementary_Type (T) or else Is_Task_Type (T) then |
| 815 |
return True; |
| 816 |
|
| 817 |
-- Array types |
| 818 |
|
| 819 |
elsif Is_Array_Type (T) then |
| 820 |
|
| 821 |
-- String literals always have known size, and we can set it |
| 822 |
|
| 823 |
if Ekind (T) = E_String_Literal_Subtype then |
| 824 |
if Known_Component_Size (T) then |
| 825 |
Set_Small_Size |
| 826 |
(T, Component_Size (T) * String_Literal_Length (T)); |
| 827 |
|
| 828 |
else |
| 829 |
-- The following is wrong, but does what previous versions |
| 830 |
-- did. The Component_Size is unknown for the string in a |
| 831 |
-- pragma Warnings. |
| 832 |
Set_Small_Size (T, Uint_0); |
| 833 |
end if; |
| 834 |
|
| 835 |
return True; |
| 836 |
|
| 837 |
-- Unconstrained types never have known at compile time size |
| 838 |
|
| 839 |
elsif not Is_Constrained (T) then |
| 840 |
return False; |
| 841 |
|
| 842 |
-- Don't do any recursion on type with error posted, since we may |
| 843 |
-- have a malformed type that leads us into a loop. |
| 844 |
|
| 845 |
elsif Error_Posted (T) then |
| 846 |
return False; |
| 847 |
|
| 848 |
-- Otherwise if component size unknown, then array size unknown |
| 849 |
|
| 850 |
elsif not Size_Known (Component_Type (T)) then |
| 851 |
return False; |
| 852 |
end if; |
| 853 |
|
| 854 |
-- Check for all indexes static, and also compute possible size |
| 855 |
-- (in case it is not greater than System_Max_Integer_Size and |
| 856 |
-- thus may be packable). |
| 857 |
|
| 858 |
declare |
| 859 |
Index : Entity_Id; |
| 860 |
Low : Node_Id; |
| 861 |
High : Node_Id; |
| 862 |
Size : Uint := Component_Size (T); |
| 863 |
Dim : Uint; |
| 864 |
|
| 865 |
begin |
| 866 |
-- See comment in Set_Small_Size above |
| 867 |
|
| 868 |
if No (Size) then |
| 869 |
Size := Uint_0; |
| 870 |
end if; |
| 871 |
|
| 872 |
Index := First_Index (T); |
| 873 |
while Present (Index) loop |
| 874 |
if Nkind (Index) = N_Range then |
| 875 |
Get_Index_Bounds (Index, Low, High); |
| 876 |
|
| 877 |
elsif Error_Posted (Scalar_Range (Etype (Index))) then |
| 878 |
return False; |
| 879 |
|
| 880 |
else |
| 881 |
Low := Type_Low_Bound (Etype (Index)); |
| 882 |
High := Type_High_Bound (Etype (Index)); |
| 883 |
end if; |
| 884 |
|
| 885 |
if Etype (Index) = Any_Type then |
| 886 |
return False; |
| 887 |
|
| 888 |
elsif Compile_Time_Known_Value (Low) |
| 889 |
and then Compile_Time_Known_Value (High) |
| 890 |
then |
| 891 |
|
| 892 |
Dim := Expr_Value (High) - Expr_Value (Low) + 1; |
| 893 |
|
| 894 |
if Dim > Uint_0 then |
| 895 |
Size := Size * Dim; |
| 896 |
else |
| 897 |
Size := Uint_0; |
| 898 |
end if; |
| 899 |
|
| 900 |
elsif Value_Known (Low) and then Value_Known (High) then |
| 901 |
Size := Uint_0; |
| 902 |
|
| 903 |
else |
| 904 |
return False; |
| 905 |
end if; |
| 906 |
|
| 907 |
Next_Index (Index); |
| 908 |
end loop; |
| 909 |
|
| 910 |
Set_Small_Size (T, Size); |
| 911 |
return True; |
| 912 |
end; |
| 913 |
|
| 914 |
-- For non-generic private types, go to underlying type if present |
| 915 |
|
| 916 |
elsif Is_Private_Type (T) |
| 917 |
and then not Is_Generic_Type (T) |
| 918 |
and then Present (Underlying_Type (T)) |
| 919 |
then |
| 920 |
-- Don't do any recursion on type with error posted, since we may |
| 921 |
-- have a malformed type that leads us into a loop. |
| 922 |
|
| 923 |
if Error_Posted (T) then |
| 924 |
return False; |
| 925 |
else |
| 926 |
return Size_Known (Underlying_Type (T)); |
| 927 |
end if; |
| 928 |
|
| 929 |
-- Record types |
| 930 |
|
| 931 |
elsif Is_Record_Type (T) then |
| 932 |
|
| 933 |
-- A subtype of a variant record must not have non-static |
| 934 |
-- discriminated components. |
| 935 |
|
| 936 |
if T /= Base_Type (T) |
| 937 |
and then not Static_Discriminated_Components (T) |
| 938 |
then |
| 939 |
return False; |
| 940 |
|
| 941 |
-- Don't do any recursion on type with error posted, since we may |
| 942 |
-- have a malformed type that leads us into a loop. |
| 943 |
|
| 944 |
elsif Error_Posted (T) then |
| 945 |
return False; |
| 946 |
end if; |
| 947 |
|
| 948 |
-- Now look at the components of the record |
| 949 |
|
| 950 |
declare |
| 951 |
-- The following two variables are used to keep track of the |
| 952 |
-- size of packed records if we can tell the size of the packed |
| 953 |
-- record in the front end. Packed_Size_Known is True if so far |
| 954 |
-- we can figure out the size. It is initialized to True for a |
| 955 |
-- packed record, unless the record has either discriminants or |
| 956 |
-- independent components, or is a strict-alignment type, since |
| 957 |
-- it cannot be fully packed in this case. |
| 958 |
|
| 959 |
-- The reason we eliminate the discriminated case is that |
| 960 |
-- we don't know the way the back end lays out discriminated |
| 961 |
-- packed records. If Packed_Size_Known is True, then |
| 962 |
-- Packed_Size is the size in bits so far. |
| 963 |
|
| 964 |
Packed_Size_Known : Boolean := |
| 965 |
Is_Packed (T) |
| 966 |
and then not Has_Discriminants (T) |
| 967 |
and then not Has_Independent_Components (T) |
| 968 |
and then not Strict_Alignment (T); |
| 969 |
|
| 970 |
Packed_Size : Uint := Uint_0; |
| 971 |
-- Size in bits so far |
| 972 |
|
| 973 |
begin |
| 974 |
-- Test for variant part present |
| 975 |
|
| 976 |
if Has_Discriminants (T) |
| 977 |
and then Present (Parent (T)) |
| 978 |
and then Nkind (Parent (T)) = N_Full_Type_Declaration |
| 979 |
and then Nkind (Type_Definition (Parent (T))) = |
| 980 |
N_Record_Definition |
| 981 |
and then not Null_Present (Type_Definition (Parent (T))) |
| 982 |
and then |
| 983 |
Present (Variant_Part |
| 984 |
(Component_List (Type_Definition (Parent (T))))) |
| 985 |
then |
| 986 |
-- If variant part is present, and type is unconstrained, |
| 987 |
-- then we must have defaulted discriminants, or a size |
| 988 |
-- clause must be present for the type, or else the size |
| 989 |
-- is definitely not known at compile time. |
| 990 |
|
| 991 |
if not Is_Constrained (T) |
| 992 |
and then |
| 993 |
No (Discriminant_Default_Value (First_Discriminant (T))) |
| 994 |
and then not Known_RM_Size (T) |
| 995 |
and then not Known_Esize (T) |
| 996 |
then |
| 997 |
return False; |
| 998 |
end if; |
| 999 |
end if; |
| 1000 |
|
| 1001 |
-- Loop through components |
| 1002 |
|
| 1003 |
Comp := First_Component_Or_Discriminant (T); |
| 1004 |
while Present (Comp) loop |
| 1005 |
Ctyp := Etype (Comp); |
| 1006 |
|
| 1007 |
-- We do not know the packed size if there is a component |
| 1008 |
-- clause present (we possibly could, but this would only |
| 1009 |
-- help in the case of a record with partial rep clauses. |
| 1010 |
-- That's because in the case of full rep clauses, the |
| 1011 |
-- size gets figured out anyway by a different circuit). |
| 1012 |
|
| 1013 |
if Present (Component_Clause (Comp)) then |
| 1014 |
Packed_Size_Known := False; |
| 1015 |
end if; |
| 1016 |
|
| 1017 |
-- We do not know the packed size for an independent |
| 1018 |
-- component or if it is of a strict-alignment type, |
| 1019 |
-- since packing does not touch these (RM 13.2(7)). |
| 1020 |
|
| 1021 |
if Is_Independent (Comp) |
| 1022 |
or else Is_Independent (Ctyp) |
| 1023 |
or else Strict_Alignment (Ctyp) |
| 1024 |
then |
| 1025 |
Packed_Size_Known := False; |
| 1026 |
end if; |
| 1027 |
|
| 1028 |
-- We need to identify a component that is an array where |
| 1029 |
-- the index type is an enumeration type with non-standard |
| 1030 |
-- representation, and some bound of the type depends on a |
| 1031 |
-- discriminant. |
| 1032 |
|
| 1033 |
-- This is because gigi computes the size by doing a |
| 1034 |
-- substitution of the appropriate discriminant value in |
| 1035 |
-- the size expression for the base type, and gigi is not |
| 1036 |
-- clever enough to evaluate the resulting expression (which |
| 1037 |
-- involves a call to rep_to_pos) at compile time. |
| 1038 |
|
| 1039 |
-- It would be nice if gigi would either recognize that |
| 1040 |
-- this expression can be computed at compile time, or |
| 1041 |
-- alternatively figured out the size from the subtype |
| 1042 |
-- directly, where all the information is at hand ??? |
| 1043 |
|
| 1044 |
if Is_Array_Type (Etype (Comp)) |
| 1045 |
and then Present (Packed_Array_Impl_Type (Etype (Comp))) |
| 1046 |
then |
| 1047 |
declare |
| 1048 |
Ocomp : constant Entity_Id := |
| 1049 |
Original_Record_Component (Comp); |
| 1050 |
OCtyp : constant Entity_Id := Etype (Ocomp); |
| 1051 |
Ind : Node_Id; |
| 1052 |
Indtyp : Entity_Id; |
| 1053 |
Lo, Hi : Node_Id; |
| 1054 |
|
| 1055 |
begin |
| 1056 |
Ind := First_Index (OCtyp); |
| 1057 |
while Present (Ind) loop |
| 1058 |
Indtyp := Etype (Ind); |
| 1059 |
|
| 1060 |
if Is_Enumeration_Type (Indtyp) |
| 1061 |
and then Has_Non_Standard_Rep (Indtyp) |
| 1062 |
then |
| 1063 |
Lo := Type_Low_Bound (Indtyp); |
| 1064 |
Hi := Type_High_Bound (Indtyp); |
| 1065 |
|
| 1066 |
if Is_Entity_Name (Lo) |
| 1067 |
and then Ekind (Entity (Lo)) = E_Discriminant |
| 1068 |
then |
| 1069 |
return False; |
| 1070 |
|
| 1071 |
elsif Is_Entity_Name (Hi) |
| 1072 |
and then Ekind (Entity (Hi)) = E_Discriminant |
| 1073 |
then |
| 1074 |
return False; |
| 1075 |
end if; |
| 1076 |
end if; |
| 1077 |
|
| 1078 |
Next_Index (Ind); |
| 1079 |
end loop; |
| 1080 |
end; |
| 1081 |
end if; |
| 1082 |
|
| 1083 |
-- Clearly size of record is not known if the size of one of |
| 1084 |
-- the components is not known. |
| 1085 |
|
| 1086 |
if not Size_Known (Ctyp) then |
| 1087 |
return False; |
| 1088 |
end if; |
| 1089 |
|
| 1090 |
-- Accumulate packed size if possible |
| 1091 |
|
| 1092 |
if Packed_Size_Known then |
| 1093 |
|
| 1094 |
-- We can deal with elementary types, small packed arrays |
| 1095 |
-- if the representation is a modular type and also small |
| 1096 |
-- record types as checked by Set_Small_Size. |
| 1097 |
|
| 1098 |
if Is_Elementary_Type (Ctyp) |
| 1099 |
or else (Is_Array_Type (Ctyp) |
| 1100 |
and then Present |
| 1101 |
(Packed_Array_Impl_Type (Ctyp)) |
| 1102 |
and then Is_Modular_Integer_Type |
| 1103 |
(Packed_Array_Impl_Type (Ctyp))) |
| 1104 |
or else Is_Record_Type (Ctyp) |
| 1105 |
then |
| 1106 |
-- If RM_Size is known and static, then we can keep |
| 1107 |
-- accumulating the packed size. |
| 1108 |
|
| 1109 |
if Known_Static_RM_Size (Ctyp) then |
| 1110 |
|
| 1111 |
Packed_Size := Packed_Size + RM_Size (Ctyp); |
| 1112 |
|
| 1113 |
-- If we have a field whose RM_Size is not known then |
| 1114 |
-- we can't figure out the packed size here. |
| 1115 |
|
| 1116 |
else |
| 1117 |
Packed_Size_Known := False; |
| 1118 |
end if; |
| 1119 |
|
| 1120 |
-- For other types we can't figure out the packed size |
| 1121 |
|
| 1122 |
else |
| 1123 |
Packed_Size_Known := False; |
| 1124 |
end if; |
| 1125 |
end if; |
| 1126 |
|
| 1127 |
Next_Component_Or_Discriminant (Comp); |
| 1128 |
end loop; |
| 1129 |
|
| 1130 |
if Packed_Size_Known then |
| 1131 |
Set_Small_Size (T, Packed_Size); |
| 1132 |
end if; |
| 1133 |
|
| 1134 |
return True; |
| 1135 |
end; |
| 1136 |
|
| 1137 |
-- All other cases, size not known at compile time |
| 1138 |
|
| 1139 |
else |
| 1140 |
return False; |
| 1141 |
end if; |
| 1142 |
end Size_Known; |
| 1143 |
|
| 1144 |
------------------------------------- |
| 1145 |
-- Static_Discriminated_Components -- |
| 1146 |
------------------------------------- |
| 1147 |
|
| 1148 |
function Static_Discriminated_Components |
| 1149 |
(T : Entity_Id) return Boolean |
| 1150 |
is |
| 1151 |
Constraint : Elmt_Id; |
| 1152 |
|
| 1153 |
begin |
| 1154 |
if Has_Discriminants (T) |
| 1155 |
and then Present (Discriminant_Constraint (T)) |
| 1156 |
and then Present (First_Component (T)) |
| 1157 |
then |
| 1158 |
Constraint := First_Elmt (Discriminant_Constraint (T)); |
| 1159 |
while Present (Constraint) loop |
| 1160 |
if not Compile_Time_Known_Value (Node (Constraint)) then |
| 1161 |
return False; |
| 1162 |
end if; |
| 1163 |
|
| 1164 |
Next_Elmt (Constraint); |
| 1165 |
end loop; |
| 1166 |
end if; |
| 1167 |
|
| 1168 |
return True; |
| 1169 |
end Static_Discriminated_Components; |
| 1170 |
|
| 1171 |
----------------- |
| 1172 |
-- Value_Known -- |
| 1173 |
----------------- |
| 1174 |
|
| 1175 |
function Value_Known (Exp : Node_Id) return Boolean is |
| 1176 |
begin |
| 1177 |
-- This is the immediate case |
| 1178 |
|
| 1179 |
if Compile_Time_Known_Value (Exp) then |
| 1180 |
return True; |
| 1181 |
end if; |
| 1182 |
|
| 1183 |
-- The value may be known only to the back end, the typical example |
| 1184 |
-- being the alignment or the various sizes of composite types; in |
| 1185 |
-- the latter case, we may mutually recurse with Size_Known. |
| 1186 |
|
| 1187 |
case Nkind (Exp) is |
| 1188 |
when N_Attribute_Reference => |
| 1189 |
declare |
| 1190 |
P : constant Node_Id := Prefix (Exp); |
| 1191 |
|
| 1192 |
begin |
| 1193 |
if not Is_Entity_Name (P) |
| 1194 |
or else not Is_Type (Entity (P)) |
| 1195 |
then |
| 1196 |
return False; |
| 1197 |
end if; |
| 1198 |
|
| 1199 |
case Get_Attribute_Id (Attribute_Name (Exp)) is |
| 1200 |
when Attribute_Alignment => |
| 1201 |
return True; |
| 1202 |
|
| 1203 |
when Attribute_Component_Size => |
| 1204 |
return Size_Known (Component_Type (Entity (P))); |
| 1205 |
|
| 1206 |
when Attribute_Object_Size |
| 1207 |
| Attribute_Size |
| 1208 |
| Attribute_Value_Size |
| 1209 |
=> |
| 1210 |
return Size_Known (Entity (P)); |
| 1211 |
|
| 1212 |
when others => |
| 1213 |
return False; |
| 1214 |
end case; |
| 1215 |
end; |
| 1216 |
|
| 1217 |
when N_Binary_Op => |
| 1218 |
return Value_Known (Left_Opnd (Exp)) |
| 1219 |
and then Value_Known (Right_Opnd (Exp)); |
| 1220 |
|
| 1221 |
when N_Qualified_Expression |
| 1222 |
| N_Type_Conversion |
| 1223 |
| N_Unchecked_Type_Conversion |
| 1224 |
=> |
| 1225 |
return Value_Known (Expression (Exp)); |
| 1226 |
|
| 1227 |
when N_Unary_Op => |
| 1228 |
return Value_Known (Right_Opnd (Exp)); |
| 1229 |
|
| 1230 |
when others => |
| 1231 |
return False; |
| 1232 |
end case; |
| 1233 |
end Value_Known; |
| 1234 |
|
| 1235 |
-- Start of processing for Check_Compile_Time_Size |
| 1236 |
|
| 1237 |
begin |
| 1238 |
Set_Size_Known_At_Compile_Time (T, Size_Known (T)); |
| 1239 |
end Check_Compile_Time_Size; |
| 1240 |
|
| 1241 |
----------------------------------- |
| 1242 |
-- Check_Component_Storage_Order -- |
| 1243 |
----------------------------------- |
| 1244 |
|
| 1245 |
procedure Check_Component_Storage_Order |
| 1246 |
(Encl_Type : Entity_Id; |
| 1247 |
Comp : Entity_Id; |
| 1248 |
ADC : Node_Id; |
| 1249 |
Comp_ADC_Present : out Boolean) |
| 1250 |
is |
| 1251 |
Comp_Base : Entity_Id; |
| 1252 |
Comp_ADC : Node_Id; |
| 1253 |
Encl_Base : Entity_Id; |
| 1254 |
Err_Node : Node_Id; |
| 1255 |
|
| 1256 |
Component_Aliased : Boolean; |
| 1257 |
|
| 1258 |
Comp_Byte_Aligned : Boolean := False; |
| 1259 |
-- Set for the record case, True if Comp is aligned on byte boundaries |
| 1260 |
-- (in which case it is allowed to have different storage order). |
| 1261 |
|
| 1262 |
Comp_SSO_Differs : Boolean; |
| 1263 |
-- Set True when the component is a nested composite, and it does not |
| 1264 |
-- have the same scalar storage order as Encl_Type. |
| 1265 |
|
| 1266 |
begin |
| 1267 |
-- Record case |
| 1268 |
|
| 1269 |
if Present (Comp) then |
| 1270 |
Err_Node := Comp; |
| 1271 |
Comp_Base := Etype (Comp); |
| 1272 |
|
| 1273 |
if Is_Tag (Comp) then |
| 1274 |
Comp_Byte_Aligned := True; |
| 1275 |
Component_Aliased := False; |
| 1276 |
|
| 1277 |
else |
| 1278 |
-- If a component clause is present, check if the component starts |
| 1279 |
-- and ends on byte boundaries. Otherwise conservatively assume it |
| 1280 |
-- does so only in the case where the record is not packed. |
| 1281 |
|
| 1282 |
if Present (Component_Clause (Comp)) then |
| 1283 |
Comp_Byte_Aligned := |
| 1284 |
Known_Normalized_First_Bit (Comp) |
| 1285 |
and then |
| 1286 |
Known_Esize (Comp) |
| 1287 |
and then |
| 1288 |
Normalized_First_Bit (Comp) mod System_Storage_Unit = 0 |
| 1289 |
and then |
| 1290 |
Esize (Comp) mod System_Storage_Unit = 0; |
| 1291 |
else |
| 1292 |
Comp_Byte_Aligned := not Is_Packed (Encl_Type); |
| 1293 |
end if; |
| 1294 |
|
| 1295 |
Component_Aliased := Is_Aliased (Comp); |
| 1296 |
end if; |
| 1297 |
|
| 1298 |
-- Array case |
| 1299 |
|
| 1300 |
else |
| 1301 |
Err_Node := Encl_Type; |
| 1302 |
Comp_Base := Component_Type (Encl_Type); |
| 1303 |
|
| 1304 |
Component_Aliased := Has_Aliased_Components (Encl_Type); |
| 1305 |
end if; |
| 1306 |
|
| 1307 |
-- Note: the Reverse_Storage_Order flag is set on the base type, but |
| 1308 |
-- the attribute definition clause is attached to the first subtype. |
| 1309 |
-- Also, if the base type is incomplete or private, go to full view |
| 1310 |
-- if known |
| 1311 |
|
| 1312 |
Encl_Base := Base_Type (Encl_Type); |
| 1313 |
if Present (Underlying_Type (Encl_Base)) then |
| 1314 |
Encl_Base := Underlying_Type (Encl_Base); |
| 1315 |
end if; |
| 1316 |
|
| 1317 |
Comp_Base := Base_Type (Comp_Base); |
| 1318 |
if Present (Underlying_Type (Comp_Base)) then |
| 1319 |
Comp_Base := Underlying_Type (Comp_Base); |
| 1320 |
end if; |
| 1321 |
|
| 1322 |
Comp_ADC := |
| 1323 |
Get_Attribute_Definition_Clause |
| 1324 |
(First_Subtype (Comp_Base), Attribute_Scalar_Storage_Order); |
| 1325 |
Comp_ADC_Present := Present (Comp_ADC); |
| 1326 |
|
| 1327 |
-- Case of record or array component: check storage order compatibility. |
| 1328 |
-- But, if the record has Complex_Representation, then it is treated as |
| 1329 |
-- a scalar in the back end so the storage order is irrelevant. |
| 1330 |
|
| 1331 |
if (Is_Record_Type (Comp_Base) |
| 1332 |
and then not Has_Complex_Representation (Comp_Base)) |
| 1333 |
or else Is_Array_Type (Comp_Base) |
| 1334 |
then |
| 1335 |
Comp_SSO_Differs := |
| 1336 |
Reverse_Storage_Order (Encl_Base) /= |
| 1337 |
Reverse_Storage_Order (Comp_Base); |
| 1338 |
|
| 1339 |
-- Parent and extension must have same storage order |
| 1340 |
|
| 1341 |
if Present (Comp) and then Chars (Comp) = Name_uParent then |
| 1342 |
if Comp_SSO_Differs then |
| 1343 |
Error_Msg_N |
| 1344 |
("record extension must have same scalar storage order as " |
| 1345 |
& "parent", Err_Node); |
| 1346 |
end if; |
| 1347 |
|
| 1348 |
-- If component and composite SSO differs, check that component |
| 1349 |
-- falls on byte boundaries and isn't bit packed. |
| 1350 |
|
| 1351 |
elsif Comp_SSO_Differs then |
| 1352 |
|
| 1353 |
-- Component SSO differs from enclosing composite: |
| 1354 |
|
| 1355 |
-- Reject if composite is a bit-packed array, as it is rewritten |
| 1356 |
-- into an array of scalars. |
| 1357 |
|
| 1358 |
if Is_Bit_Packed_Array (Encl_Base) then |
| 1359 |
Error_Msg_N |
| 1360 |
("type of packed array must have same scalar storage order " |
| 1361 |
& "as component", Err_Node); |
| 1362 |
|
| 1363 |
-- Reject if not byte aligned |
| 1364 |
|
| 1365 |
elsif Is_Record_Type (Encl_Base) |
| 1366 |
and then not Comp_Byte_Aligned |
| 1367 |
then |
| 1368 |
if Present (Component_Clause (Comp)) then |
| 1369 |
Error_Msg_N |
| 1370 |
("type of non-byte-aligned component must have same scalar" |
| 1371 |
& " storage order as enclosing record", Err_Node); |
| 1372 |
else |
| 1373 |
Error_Msg_N |
| 1374 |
("type of packed component must have same scalar" |
| 1375 |
& " storage order as enclosing record", Err_Node); |
| 1376 |
end if; |
| 1377 |
|
| 1378 |
-- Warn if specified only for the outer composite |
| 1379 |
|
| 1380 |
elsif Present (ADC) and then No (Comp_ADC) then |
| 1381 |
Error_Msg_NE |
| 1382 |
("scalar storage order specified for & does not apply to " |
| 1383 |
& "component?", Err_Node, Encl_Base); |
| 1384 |
end if; |
| 1385 |
end if; |
| 1386 |
|
| 1387 |
-- Enclosing type has explicit SSO: non-composite component must not |
| 1388 |
-- be aliased. |
| 1389 |
|
| 1390 |
elsif Present (ADC) and then Component_Aliased then |
| 1391 |
Error_Msg_N |
| 1392 |
("aliased component not permitted for type with explicit " |
| 1393 |
& "Scalar_Storage_Order", Err_Node); |
| 1394 |
end if; |
| 1395 |
end Check_Component_Storage_Order; |
| 1396 |
|
| 1397 |
----------------------------- |
| 1398 |
-- Check_Debug_Info_Needed -- |
| 1399 |
----------------------------- |
| 1400 |
|
| 1401 |
procedure Check_Debug_Info_Needed (T : Entity_Id) is |
| 1402 |
begin |
| 1403 |
if Debug_Info_Off (T) then |
| 1404 |
return; |
| 1405 |
|
| 1406 |
elsif Comes_From_Source (T) |
| 1407 |
or else Debug_Generated_Code |
| 1408 |
or else Debug_Flag_VV |
| 1409 |
or else Needs_Debug_Info (T) |
| 1410 |
then |
| 1411 |
Set_Debug_Info_Needed (T); |
| 1412 |
end if; |
| 1413 |
end Check_Debug_Info_Needed; |
| 1414 |
|
| 1415 |
------------------------------- |
| 1416 |
-- Check_Expression_Function -- |
| 1417 |
------------------------------- |
| 1418 |
|
| 1419 |
procedure Check_Expression_Function (N : Node_Id; Nam : Entity_Id) is |
| 1420 |
function Find_Constant (Nod : Node_Id) return Traverse_Result; |
| 1421 |
-- Function to search for deferred constant |
| 1422 |
|
| 1423 |
------------------- |
| 1424 |
-- Find_Constant -- |
| 1425 |
------------------- |
| 1426 |
|
| 1427 |
function Find_Constant (Nod : Node_Id) return Traverse_Result is |
| 1428 |
begin |
| 1429 |
-- When a constant is initialized with the result of a dispatching |
| 1430 |
-- call, the constant declaration is rewritten as a renaming of the |
| 1431 |
-- displaced function result. This scenario is not a premature use of |
| 1432 |
-- a constant even though the Has_Completion flag is not set. |
| 1433 |
|
| 1434 |
if Is_Entity_Name (Nod) |
| 1435 |
and then Present (Entity (Nod)) |
| 1436 |
and then Ekind (Entity (Nod)) = E_Constant |
| 1437 |
and then Scope (Entity (Nod)) = Current_Scope |
| 1438 |
and then Nkind (Declaration_Node (Entity (Nod))) = |
| 1439 |
N_Object_Declaration |
| 1440 |
and then not Is_Imported (Entity (Nod)) |
| 1441 |
and then not Has_Completion (Entity (Nod)) |
| 1442 |
and then not (Present (Full_View (Entity (Nod))) |
| 1443 |
and then Has_Completion (Full_View (Entity (Nod)))) |
| 1444 |
then |
| 1445 |
Error_Msg_NE |
| 1446 |
("premature use of& in call or instance", N, Entity (Nod)); |
| 1447 |
|
| 1448 |
elsif Nkind (Nod) = N_Attribute_Reference then |
| 1449 |
Analyze (Prefix (Nod)); |
| 1450 |
|
| 1451 |
if Is_Entity_Name (Prefix (Nod)) |
| 1452 |
and then Is_Type (Entity (Prefix (Nod))) |
| 1453 |
then |
| 1454 |
if Expander_Active then |
| 1455 |
Check_Fully_Declared (Entity (Prefix (Nod)), N); |
| 1456 |
end if; |
| 1457 |
|
| 1458 |
Freeze_Before (N, Entity (Prefix (Nod))); |
| 1459 |
end if; |
| 1460 |
end if; |
| 1461 |
|
| 1462 |
return OK; |
| 1463 |
end Find_Constant; |
| 1464 |
|
| 1465 |
procedure Check_Deferred is new Traverse_Proc (Find_Constant); |
| 1466 |
|
| 1467 |
-- Local variables |
| 1468 |
|
| 1469 |
Decl : Node_Id; |
| 1470 |
|
| 1471 |
-- Start of processing for Check_Expression_Function |
| 1472 |
|
| 1473 |
begin |
| 1474 |
Decl := Original_Node (Unit_Declaration_Node (Nam)); |
| 1475 |
|
| 1476 |
-- The subprogram body created for the expression function is not |
| 1477 |
-- itself a freeze point. |
| 1478 |
|
| 1479 |
if Scope (Nam) = Current_Scope |
| 1480 |
and then Nkind (Decl) = N_Expression_Function |
| 1481 |
and then Nkind (N) /= N_Subprogram_Body |
| 1482 |
then |
| 1483 |
Check_Deferred (Expression (Decl)); |
| 1484 |
end if; |
| 1485 |
end Check_Expression_Function; |
| 1486 |
|
| 1487 |
-------------------------------- |
| 1488 |
-- Check_Inherited_Conditions -- |
| 1489 |
-------------------------------- |
| 1490 |
|
| 1491 |
procedure Check_Inherited_Conditions |
| 1492 |
(R : Entity_Id; |
| 1493 |
Late_Overriding : Boolean := False) |
| 1494 |
is |
| 1495 |
Prim_Ops : constant Elist_Id := Primitive_Operations (R); |
| 1496 |
Decls : List_Id; |
| 1497 |
Op_Node : Elmt_Id; |
| 1498 |
Par_Prim : Entity_Id; |
| 1499 |
Prim : Entity_Id; |
| 1500 |
|
| 1501 |
type Wrapper_Kind is (No_Wrapper, LSP_Wrapper, Condition_Wrapper); |
| 1502 |
|
| 1503 |
Wrapper_Needed : Wrapper_Kind; |
| 1504 |
-- Kind of wrapper needed by a given inherited primitive of tagged |
| 1505 |
-- type R: |
| 1506 |
-- * No_Wrapper: No wrapper is needed. |
| 1507 |
-- * LSP_Wrapper: Wrapper that handles inherited class-wide pre/post |
| 1508 |
-- conditions that call overridden primitives. |
| 1509 |
-- * Condition_Wrapper: Wrapper of inherited subprogram that implements |
| 1510 |
-- additional interface primitives of the derived type that have |
| 1511 |
-- class-wide pre-/postconditions. |
| 1512 |
|
| 1513 |
function Build_DTW_Body |
| 1514 |
(Loc : Source_Ptr; |
| 1515 |
DTW_Spec : Node_Id; |
| 1516 |
DTW_Decls : List_Id; |
| 1517 |
Par_Prim : Entity_Id; |
| 1518 |
Wrapped_Subp : Entity_Id) return Node_Id; |
| 1519 |
-- Build the body of the dispatch table wrapper containing the given |
| 1520 |
-- spec and declarations; the call to the wrapped subprogram includes |
| 1521 |
-- the proper type conversion. |
| 1522 |
|
| 1523 |
function Build_DTW_Spec (Par_Prim : Entity_Id) return Node_Id; |
| 1524 |
-- Build the spec of the dispatch table wrapper |
| 1525 |
|
| 1526 |
procedure Build_Inherited_Condition_Pragmas |
| 1527 |
(Subp : Entity_Id; |
| 1528 |
LSP_Wrapper_Needed : out Boolean); |
| 1529 |
-- Build corresponding pragmas for an operation whose ancestor has |
| 1530 |
-- class-wide pre/postconditions. If the operation is inherited then |
| 1531 |
-- Wrapper_Needed is returned True to force the creation of a wrapper |
| 1532 |
-- for the inherited operation. If the ancestor is being overridden, |
| 1533 |
-- the pragmas are constructed only to verify their legality, in case |
| 1534 |
-- they contain calls to other primitives that may have been overridden. |
| 1535 |
|
| 1536 |
procedure Check_Interface_Primitives_Strub_Mode; |
| 1537 |
-- Called when R is an interface type to check strub mode compatibility |
| 1538 |
-- all its primitives. |
| 1539 |
|
| 1540 |
function Needs_Wrapper |
| 1541 |
(Class_Cond : Node_Id; |
| 1542 |
Subp : Entity_Id; |
| 1543 |
Par_Subp : Entity_Id) return Boolean; |
| 1544 |
-- Checks whether the dispatch-table wrapper (DTW) for Subp must be |
| 1545 |
-- built to evaluate the given class-wide condition. |
| 1546 |
|
| 1547 |
-------------------- |
| 1548 |
-- Build_DTW_Body -- |
| 1549 |
-------------------- |
| 1550 |
|
| 1551 |
function Build_DTW_Body |
| 1552 |
(Loc : Source_Ptr; |
| 1553 |
DTW_Spec : Node_Id; |
| 1554 |
DTW_Decls : List_Id; |
| 1555 |
Par_Prim : Entity_Id; |
| 1556 |
Wrapped_Subp : Entity_Id) return Node_Id |
| 1557 |
is |
| 1558 |
Actuals : constant List_Id := Empty_List; |
| 1559 |
Call : Node_Id; |
| 1560 |
Formal : Entity_Id := First_Formal (Par_Prim); |
| 1561 |
New_F_Spec : Entity_Id := First (Parameter_Specifications (DTW_Spec)); |
| 1562 |
New_Formal : Entity_Id; |
| 1563 |
|
| 1564 |
begin |
| 1565 |
-- Build parameter association for call to wrapped subprogram |
| 1566 |
|
| 1567 |
while Present (Formal) loop |
| 1568 |
New_Formal := Defining_Identifier (New_F_Spec); |
| 1569 |
|
| 1570 |
-- If the controlling argument is inherited, add conversion to |
| 1571 |
-- parent type for the call. |
| 1572 |
|
| 1573 |
if Is_Controlling_Formal (Formal) then |
| 1574 |
Append_To (Actuals, |
| 1575 |
Make_Type_Conversion (Loc, |
| 1576 |
New_Occurrence_Of (Etype (Formal), Loc), |
| 1577 |
New_Occurrence_Of (New_Formal, Loc))); |
| 1578 |
else |
| 1579 |
Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc)); |
| 1580 |
end if; |
| 1581 |
|
| 1582 |
Next_Formal (Formal); |
| 1583 |
Next (New_F_Spec); |
| 1584 |
end loop; |
| 1585 |
|
| 1586 |
if Ekind (Wrapped_Subp) = E_Procedure then |
| 1587 |
Call := |
| 1588 |
Make_Procedure_Call_Statement (Loc, |
| 1589 |
Name => New_Occurrence_Of (Wrapped_Subp, Loc), |
| 1590 |
Parameter_Associations => Actuals); |
| 1591 |
else |
| 1592 |
Call := |
| 1593 |
Make_Simple_Return_Statement (Loc, |
| 1594 |
Expression => |
| 1595 |
Make_Function_Call (Loc, |
| 1596 |
Name => New_Occurrence_Of (Wrapped_Subp, Loc), |
| 1597 |
Parameter_Associations => Actuals)); |
| 1598 |
end if; |
| 1599 |
|
| 1600 |
return |
| 1601 |
Make_Subprogram_Body (Loc, |
| 1602 |
Specification => Copy_Subprogram_Spec (DTW_Spec), |
| 1603 |
Declarations => DTW_Decls, |
| 1604 |
Handled_Statement_Sequence => |
| 1605 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1606 |
Statements => New_List (Call), |
| 1607 |
End_Label => Make_Identifier (Loc, |
| 1608 |
Chars (Defining_Entity (DTW_Spec))))); |
| 1609 |
end Build_DTW_Body; |
| 1610 |
|
| 1611 |
-------------------- |
| 1612 |
-- Build_DTW_Spec -- |
| 1613 |
-------------------- |
| 1614 |
|
| 1615 |
function Build_DTW_Spec (Par_Prim : Entity_Id) return Node_Id is |
| 1616 |
DTW_Id : Entity_Id; |
| 1617 |
DTW_Spec : Node_Id; |
| 1618 |
|
| 1619 |
begin |
| 1620 |
DTW_Spec := Build_Overriding_Spec (Par_Prim, R); |
| 1621 |
DTW_Id := Defining_Entity (DTW_Spec); |
| 1622 |
|
| 1623 |
-- Clear the not-overriding indicator since the DTW wrapper overrides |
| 1624 |
-- its wrapped subprogram; required because if present in the parent |
| 1625 |
-- primitive, given that Build_Overriding_Spec inherits it, we report |
| 1626 |
-- spurious errors. |
| 1627 |
|
| 1628 |
Set_Must_Not_Override (DTW_Spec, False); |
| 1629 |
|
| 1630 |
-- Add minimal decoration of fields |
| 1631 |
|
| 1632 |
Mutate_Ekind (DTW_Id, Ekind (Par_Prim)); |
| 1633 |
Set_Is_Dispatch_Table_Wrapper (DTW_Id); |
| 1634 |
Set_Is_Wrapper (DTW_Id); |
| 1635 |
|
| 1636 |
-- The DTW wrapper is never a null procedure |
| 1637 |
|
| 1638 |
if Nkind (DTW_Spec) = N_Procedure_Specification then |
| 1639 |
Set_Null_Present (DTW_Spec, False); |
| 1640 |
end if; |
| 1641 |
|
| 1642 |
return DTW_Spec; |
| 1643 |
end Build_DTW_Spec; |
| 1644 |
|
| 1645 |
--------------------------------------- |
| 1646 |
-- Build_Inherited_Condition_Pragmas -- |
| 1647 |
--------------------------------------- |
| 1648 |
|
| 1649 |
procedure Build_Inherited_Condition_Pragmas |
| 1650 |
(Subp : Entity_Id; |
| 1651 |
LSP_Wrapper_Needed : out Boolean) |
| 1652 |
is |
| 1653 |
Class_Pre : constant Node_Id := |
| 1654 |
Class_Preconditions (Ultimate_Alias (Subp)); |
| 1655 |
Class_Post : Node_Id := Class_Postconditions (Par_Prim); |
| 1656 |
A_Post : Node_Id; |
| 1657 |
New_Prag : Node_Id; |
| 1658 |
|
| 1659 |
begin |
| 1660 |
LSP_Wrapper_Needed := False; |
| 1661 |
|
| 1662 |
if No (Class_Pre) and then No (Class_Post) then |
| 1663 |
return; |
| 1664 |
end if; |
| 1665 |
|
| 1666 |
-- For class-wide preconditions we just evaluate whether the wrapper |
| 1667 |
-- is needed; there is no need to build the pragma since the check |
| 1668 |
-- is performed on the caller side. |
| 1669 |
|
| 1670 |
if Present (Class_Pre) |
| 1671 |
and then Needs_Wrapper (Class_Pre, Subp, Par_Prim) |
| 1672 |
then |
| 1673 |
LSP_Wrapper_Needed := True; |
| 1674 |
end if; |
| 1675 |
|
| 1676 |
-- For class-wide postconditions we evaluate whether the wrapper is |
| 1677 |
-- needed and we build the class-wide postcondition pragma to install |
| 1678 |
-- it in the wrapper. |
| 1679 |
|
| 1680 |
if Present (Class_Post) |
| 1681 |
and then Needs_Wrapper (Class_Post, Subp, Par_Prim) |
| 1682 |
then |
| 1683 |
LSP_Wrapper_Needed := True; |
| 1684 |
|
| 1685 |
-- Update the class-wide postcondition |
| 1686 |
|
| 1687 |
Class_Post := New_Copy_Tree (Class_Post); |
| 1688 |
Build_Class_Wide_Expression |
| 1689 |
(Pragma_Or_Expr => Class_Post, |
| 1690 |
Subp => Subp, |
| 1691 |
Par_Subp => Par_Prim, |
| 1692 |
Adjust_Sloc => False); |
| 1693 |
|
| 1694 |
-- Install the updated class-wide postcondition in a copy of the |
| 1695 |
-- pragma postcondition defined for the nearest ancestor. |
| 1696 |
|
| 1697 |
A_Post := Get_Class_Wide_Pragma (Par_Prim, |
| 1698 |
Pragma_Postcondition); |
| 1699 |
|
| 1700 |
if No (A_Post) then |
| 1701 |
declare |
| 1702 |
Subps : constant Subprogram_List := |
| 1703 |
Inherited_Subprograms (Subp); |
| 1704 |
begin |
| 1705 |
for Index in Subps'Range loop |
| 1706 |
A_Post := Get_Class_Wide_Pragma (Subps (Index), |
| 1707 |
Pragma_Postcondition); |
| 1708 |
exit when Present (A_Post); |
| 1709 |
end loop; |
| 1710 |
end; |
| 1711 |
end if; |
| 1712 |
|
| 1713 |
-- A_Post can be null here if the postcondition was inlined in the |
| 1714 |
-- called subprogram. |
| 1715 |
|
| 1716 |
if Present (A_Post) then |
| 1717 |
New_Prag := New_Copy_Tree (A_Post); |
| 1718 |
Rewrite |
| 1719 |
(Expression (First (Pragma_Argument_Associations (New_Prag))), |
| 1720 |
Class_Post); |
| 1721 |
Append (New_Prag, Decls); |
| 1722 |
end if; |
| 1723 |
end if; |
| 1724 |
end Build_Inherited_Condition_Pragmas; |
| 1725 |
|
| 1726 |
------------------------------------------- |
| 1727 |
-- Check_Interface_Primitives_Strub_Mode -- |
| 1728 |
------------------------------------------- |
| 1729 |
|
| 1730 |
procedure Check_Interface_Primitives_Strub_Mode is |
| 1731 |
Elmt : Elmt_Id; |
| 1732 |
Iface_Elmt : Elmt_Id; |
| 1733 |
Iface : Entity_Id; |
| 1734 |
Iface_Prim : Entity_Id; |
| 1735 |
Ifaces_List : Elist_Id; |
| 1736 |
Op_Node : Elmt_Id; |
| 1737 |
Prim : Entity_Id; |
| 1738 |
Prim_Iface : Entity_Id; |
| 1739 |
|
| 1740 |
begin |
| 1741 |
pragma Assert (Is_Interface (R)); |
| 1742 |
|
| 1743 |
-- Collect interfaces extended by interface type R |
| 1744 |
|
| 1745 |
Collect_Interfaces (R, Ifaces_List); |
| 1746 |
|
| 1747 |
Op_Node := First_Elmt (Prim_Ops); |
| 1748 |
while Present (Op_Node) loop |
| 1749 |
Prim := Node (Op_Node); |
| 1750 |
Prim_Iface := R; |
| 1751 |
Par_Prim := Overridden_Operation (Prim); |
| 1752 |
|
| 1753 |
-- We only need to check entities defined in the sources |
| 1754 |
|
| 1755 |
-- Check that overrider and overridden primitives have the same |
| 1756 |
-- strub mode. |
| 1757 |
|
| 1758 |
if Present (Par_Prim) then |
| 1759 |
Check_Same_Strub_Mode (Prim, Par_Prim); |
| 1760 |
|
| 1761 |
-- No need to check internally added predefined primitives since |
| 1762 |
-- they all have the same strub mode. |
| 1763 |
|
| 1764 |
elsif Is_Predefined_Dispatching_Operation (Prim) |
| 1765 |
and then not Comes_From_Source (Prim) |
| 1766 |
then |
| 1767 |
null; |
| 1768 |
|
| 1769 |
-- Check strub mode of matching primitives of all the interface |
| 1770 |
-- types, since several interface types may define primitives with |
| 1771 |
-- the same profile that will be implemented by a single primitive |
| 1772 |
-- of tagged types implementing R, and therefore must have the |
| 1773 |
-- same strub mode. |
| 1774 |
|
| 1775 |
else |
| 1776 |
-- If this interface primitive has been inherited this is an |
| 1777 |
-- internal entity we rely on its renamed entity (which is the |
| 1778 |
-- entity defined in the sources). |
| 1779 |
|
| 1780 |
if Present (Alias (Prim)) then |
| 1781 |
Prim := Ultimate_Alias (Prim); |
| 1782 |
Prim_Iface := Find_Dispatching_Type (Prim); |
| 1783 |
end if; |
| 1784 |
|
| 1785 |
-- Search for primitives conformant with this one in the other |
| 1786 |
-- interface types. |
| 1787 |
|
| 1788 |
Iface_Elmt := First_Elmt (Ifaces_List); |
| 1789 |
while Present (Iface_Elmt) loop |
| 1790 |
Iface := Node (Iface_Elmt); |
| 1791 |
|
| 1792 |
if Iface /= Prim_Iface then |
| 1793 |
Elmt := First_Elmt (Primitive_Operations (Iface)); |
| 1794 |
while Present (Elmt) loop |
| 1795 |
Iface_Prim := Node (Elmt); |
| 1796 |
|
| 1797 |
if Chars (Iface_Prim) = Chars (Prim) |
| 1798 |
and then Comes_From_Source (Iface_Prim) |
| 1799 |
and then Is_Interface_Conformant |
| 1800 |
(Prim_Iface, Iface_Prim, Prim) |
| 1801 |
then |
| 1802 |
-- Check the strub mode passing the original |
| 1803 |
-- primitive (instead of its alias); required |
| 1804 |
-- to report the error at the right location. |
| 1805 |
|
| 1806 |
Check_Same_Strub_Mode (Node (Op_Node), Iface_Prim); |
| 1807 |
end if; |
| 1808 |
|
| 1809 |
Next_Elmt (Elmt); |
| 1810 |
end loop; |
| 1811 |
end if; |
| 1812 |
|
| 1813 |
Next_Elmt (Iface_Elmt); |
| 1814 |
end loop; |
| 1815 |
end if; |
| 1816 |
|
| 1817 |
Next_Elmt (Op_Node); |
| 1818 |
end loop; |
| 1819 |
end Check_Interface_Primitives_Strub_Mode; |
| 1820 |
|
| 1821 |
------------------- |
| 1822 |
-- Needs_Wrapper -- |
| 1823 |
------------------- |
| 1824 |
|
| 1825 |
function Needs_Wrapper |
| 1826 |
(Class_Cond : Node_Id; |
| 1827 |
Subp : Entity_Id; |
| 1828 |
Par_Subp : Entity_Id) return Boolean |
| 1829 |
is |
| 1830 |
Result : Boolean := False; |
| 1831 |
|
| 1832 |
function Check_Entity (N : Node_Id) return Traverse_Result; |
| 1833 |
-- Check calls to overridden primitives |
| 1834 |
|
| 1835 |
-------------------- |
| 1836 |
-- Replace_Entity -- |
| 1837 |
-------------------- |
| 1838 |
|
| 1839 |
function Check_Entity (N : Node_Id) return Traverse_Result is |
| 1840 |
New_E : Entity_Id; |
| 1841 |
|
| 1842 |
begin |
| 1843 |
if Nkind (N) = N_Identifier |
| 1844 |
and then Present (Entity (N)) |
| 1845 |
and then |
| 1846 |
(Is_Formal (Entity (N)) or else Is_Subprogram (Entity (N))) |
| 1847 |
and then |
| 1848 |
(Nkind (Parent (N)) /= N_Attribute_Reference |
| 1849 |
or else Attribute_Name (Parent (N)) /= Name_Class) |
| 1850 |
then |
| 1851 |
-- Determine whether entity has a renaming |
| 1852 |
|
| 1853 |
New_E := Get_Mapped_Entity (Entity (N)); |
| 1854 |
|
| 1855 |
-- If the entity is an overridden primitive and we are not |
| 1856 |
-- in GNATprove mode, we must build a wrapper for the current |
| 1857 |
-- inherited operation. If the reference is the prefix of an |
| 1858 |
-- attribute such as 'Result (or others ???) there is no need |
| 1859 |
-- for a wrapper: the condition is just rewritten in terms of |
| 1860 |
-- the inherited subprogram. |
| 1861 |
|
| 1862 |
if Present (New_E) |
| 1863 |
and then Comes_From_Source (New_E) |
| 1864 |
and then Is_Subprogram (New_E) |
| 1865 |
and then Nkind (Parent (N)) /= N_Attribute_Reference |
| 1866 |
and then not GNATprove_Mode |
| 1867 |
then |
| 1868 |
Result := True; |
| 1869 |
return Abandon; |
| 1870 |
end if; |
| 1871 |
end if; |
| 1872 |
|
| 1873 |
return OK; |
| 1874 |
end Check_Entity; |
| 1875 |
|
| 1876 |
procedure Check_Condition_Entities is |
| 1877 |
new Traverse_Proc (Check_Entity); |
| 1878 |
|
| 1879 |
-- Start of processing for Needs_Wrapper |
| 1880 |
|
| 1881 |
begin |
| 1882 |
Update_Primitives_Mapping (Par_Subp, Subp); |
| 1883 |
|
| 1884 |
Map_Formals (Par_Subp, Subp); |
| 1885 |
Check_Condition_Entities (Class_Cond); |
| 1886 |
|
| 1887 |
return Result; |
| 1888 |
end Needs_Wrapper; |
| 1889 |
|
| 1890 |
Wrappers_List : Elist_Id := No_Elist; |
| 1891 |
-- List containing identifiers of built wrappers. Used to defer building |
| 1892 |
-- and analyzing their class-wide precondition subprograms. |
| 1893 |
|
| 1894 |
Condition_Candidates_List : Elist_Id := No_Elist; |
| 1895 |
-- List containing inherited primitives of tagged type R that implement |
| 1896 |
-- interface primitives that have pre-/postconditions. |
| 1897 |
|
| 1898 |
-- Start of processing for Check_Inherited_Conditions |
| 1899 |
|
| 1900 |
begin |
| 1901 |
if Late_Overriding then |
| 1902 |
Op_Node := First_Elmt (Prim_Ops); |
| 1903 |
while Present (Op_Node) loop |
| 1904 |
Prim := Node (Op_Node); |
| 1905 |
|
| 1906 |
-- Map the overridden primitive to the overriding one |
| 1907 |
|
| 1908 |
if Present (Overridden_Operation (Prim)) |
| 1909 |
and then Comes_From_Source (Prim) |
| 1910 |
then |
| 1911 |
Par_Prim := Overridden_Operation (Prim); |
| 1912 |
Update_Primitives_Mapping (Par_Prim, Prim); |
| 1913 |
|
| 1914 |
-- Force discarding previous mappings of its formals |
| 1915 |
|
| 1916 |
Map_Formals (Par_Prim, Prim, Force_Update => True); |
| 1917 |
end if; |
| 1918 |
|
| 1919 |
Next_Elmt (Op_Node); |
| 1920 |
end loop; |
| 1921 |
end if; |
| 1922 |
|
| 1923 |
-- For interface types we only need to check strub mode compatibility |
| 1924 |
-- of their primitives (since they don't have wrappers). |
| 1925 |
|
| 1926 |
if Is_Interface (R) then |
| 1927 |
Check_Interface_Primitives_Strub_Mode; |
| 1928 |
return; |
| 1929 |
end if; |
| 1930 |
|
| 1931 |
-- Perform validity checks on the inherited conditions of overriding |
| 1932 |
-- operations, for conformance with LSP, and apply SPARK-specific |
| 1933 |
-- restrictions on inherited conditions. |
| 1934 |
|
| 1935 |
Op_Node := First_Elmt (Prim_Ops); |
| 1936 |
while Present (Op_Node) loop |
| 1937 |
Prim := Node (Op_Node); |
| 1938 |
Par_Prim := Overridden_Operation (Prim); |
| 1939 |
|
| 1940 |
if Present (Par_Prim) |
| 1941 |
and then Comes_From_Source (Prim) |
| 1942 |
then |
| 1943 |
-- When the primitive is an LSP wrapper we climb to the parent |
| 1944 |
-- primitive that has the inherited contract. |
| 1945 |
|
| 1946 |
if Is_LSP_Wrapper (Par_Prim) then |
| 1947 |
Par_Prim := LSP_Subprogram (Par_Prim); |
| 1948 |
end if; |
| 1949 |
|
| 1950 |
-- Check that overrider and overridden operations have |
| 1951 |
-- the same strub mode. |
| 1952 |
|
| 1953 |
Check_Same_Strub_Mode (Prim, Par_Prim); |
| 1954 |
|
| 1955 |
-- Analyze the contract items of the overridden operation, before |
| 1956 |
-- they are rewritten as pragmas. |
| 1957 |
|
| 1958 |
Analyze_Entry_Or_Subprogram_Contract (Par_Prim); |
| 1959 |
|
| 1960 |
-- In GNATprove mode this is where we can collect the inherited |
| 1961 |
-- conditions, because we do not create the Check pragmas that |
| 1962 |
-- normally convey the modified class-wide conditions on |
| 1963 |
-- overriding operations. |
| 1964 |
|
| 1965 |
if GNATprove_Mode then |
| 1966 |
Collect_Inherited_Class_Wide_Conditions (Prim); |
| 1967 |
end if; |
| 1968 |
|
| 1969 |
-- Check strub mode compatibility of primitives that implement |
| 1970 |
-- interface primitives. |
| 1971 |
|
| 1972 |
elsif Present (Interface_Alias (Prim)) then |
| 1973 |
Check_Same_Strub_Mode (Alias (Prim), Interface_Alias (Prim)); |
| 1974 |
end if; |
| 1975 |
|
| 1976 |
Next_Elmt (Op_Node); |
| 1977 |
end loop; |
| 1978 |
|
| 1979 |
-- Collect inherited primitives that may need a wrapper to handle |
| 1980 |
-- pre-/postconditions of interface primitives; done to improve the |
| 1981 |
-- performance when checking if postcondition wrappers are needed. |
| 1982 |
|
| 1983 |
Op_Node := First_Elmt (Prim_Ops); |
| 1984 |
while Present (Op_Node) loop |
| 1985 |
Prim := Node (Op_Node); |
| 1986 |
|
| 1987 |
if Present (Interface_Alias (Prim)) |
| 1988 |
and then not Comes_From_Source (Alias (Prim)) |
| 1989 |
and then |
| 1990 |
(Present (Class_Preconditions (Interface_Alias (Prim))) |
| 1991 |
or else |
| 1992 |
Present (Class_Postconditions (Interface_Alias (Prim)))) |
| 1993 |
then |
| 1994 |
if No (Condition_Candidates_List) then |
| 1995 |
Condition_Candidates_List := New_Elmt_List; |
| 1996 |
end if; |
| 1997 |
|
| 1998 |
Append_Unique_Elmt (Alias (Prim), Condition_Candidates_List); |
| 1999 |
end if; |
| 2000 |
|
| 2001 |
Next_Elmt (Op_Node); |
| 2002 |
end loop; |
| 2003 |
|
| 2004 |
-- Now examine the inherited operations to check whether they require |
| 2005 |
-- a wrapper to handle inherited conditions that call other primitives, |
| 2006 |
-- so that LSP can be verified/enforced. |
| 2007 |
|
| 2008 |
Op_Node := First_Elmt (Prim_Ops); |
| 2009 |
|
| 2010 |
while Present (Op_Node) loop |
| 2011 |
Decls := Empty_List; |
| 2012 |
Prim := Node (Op_Node); |
| 2013 |
Wrapper_Needed := No_Wrapper; |
| 2014 |
|
| 2015 |
-- Skip internal entities built for mapping interface primitives |
| 2016 |
|
| 2017 |
if not Comes_From_Source (Prim) |
| 2018 |
and then Present (Alias (Prim)) |
| 2019 |
and then No (Interface_Alias (Prim)) |
| 2020 |
then |
| 2021 |
Par_Prim := Ultimate_Alias (Prim); |
| 2022 |
|
| 2023 |
-- When the primitive is an LSP wrapper we climb to the parent |
| 2024 |
-- primitive that has the inherited contract. |
| 2025 |
|
| 2026 |
if Is_LSP_Wrapper (Par_Prim) then |
| 2027 |
Par_Prim := LSP_Subprogram (Par_Prim); |
| 2028 |
end if; |
| 2029 |
|
| 2030 |
-- Analyze the contract items of the parent operation, and |
| 2031 |
-- determine whether this inherited primitive needs a LSP |
| 2032 |
-- wrapper. This is determined when the condition is rewritten |
| 2033 |
-- in sem_prag, using the mapping between overridden and |
| 2034 |
-- overriding operations built in the loop above. |
| 2035 |
|
| 2036 |
declare |
| 2037 |
LSP_Wrapper_Needed : Boolean; |
| 2038 |
|
| 2039 |
begin |
| 2040 |
Analyze_Entry_Or_Subprogram_Contract (Par_Prim); |
| 2041 |
Build_Inherited_Condition_Pragmas (Prim, LSP_Wrapper_Needed); |
| 2042 |
|
| 2043 |
if LSP_Wrapper_Needed then |
| 2044 |
Wrapper_Needed := LSP_Wrapper; |
| 2045 |
end if; |
| 2046 |
end; |
| 2047 |
|
| 2048 |
-- If the LSP wrapper is not needed but the tagged type R |
| 2049 |
-- implements additional interface types, and this inherited |
| 2050 |
-- primitive covers an interface primitive of these additional |
| 2051 |
-- interface types that has class-wide postconditions, then it |
| 2052 |
-- requires a pre-/postconditions wrapper. |
| 2053 |
|
| 2054 |
if Wrapper_Needed = No_Wrapper |
| 2055 |
and then Present (Interfaces (R)) |
| 2056 |
and then Present (Condition_Candidates_List) |
| 2057 |
and then Contains (Condition_Candidates_List, Prim) |
| 2058 |
then |
| 2059 |
declare |
| 2060 |
Elmt : Elmt_Id; |
| 2061 |
Ent : Entity_Id; |
| 2062 |
Iface : Entity_Id; |
| 2063 |
Iface_Elmt : Elmt_Id; |
| 2064 |
|
| 2065 |
begin |
| 2066 |
Elmt := First_Elmt (Prim_Ops); |
| 2067 |
|
| 2068 |
Search : while Present (Elmt) loop |
| 2069 |
Ent := Node (Elmt); |
| 2070 |
|
| 2071 |
-- Perform the search relying on the internal entities |
| 2072 |
-- that link tagged type primitives with interface |
| 2073 |
-- primitives. |
| 2074 |
|
| 2075 |
if Present (Interface_Alias (Ent)) |
| 2076 |
and then (Alias (Ent)) = Prim |
| 2077 |
and then |
| 2078 |
(Present (Class_Preconditions (Interface_Alias (Ent))) |
| 2079 |
or else Present (Class_Postconditions |
| 2080 |
(Interface_Alias (Ent)))) |
| 2081 |
then |
| 2082 |
Iface := Find_Dispatching_Type (Interface_Alias (Ent)); |
| 2083 |
|
| 2084 |
-- We only need to locate primitives of additional |
| 2085 |
-- interfaces implemented by tagged type R (since |
| 2086 |
-- inherited primitives of parent types that cover |
| 2087 |
-- primitives of inherited interface types don't |
| 2088 |
-- need a wrapper). |
| 2089 |
|
| 2090 |
Iface_Elmt := First_Elmt (Interfaces (R)); |
| 2091 |
while Present (Iface_Elmt) loop |
| 2092 |
if Node (Iface_Elmt) = Iface then |
| 2093 |
Wrapper_Needed := Condition_Wrapper; |
| 2094 |
exit Search; |
| 2095 |
end if; |
| 2096 |
|
| 2097 |
Next_Elmt (Iface_Elmt); |
| 2098 |
end loop; |
| 2099 |
end if; |
| 2100 |
|
| 2101 |
Next_Elmt (Elmt); |
| 2102 |
end loop Search; |
| 2103 |
end; |
| 2104 |
end if; |
| 2105 |
end if; |
| 2106 |
|
| 2107 |
if Wrapper_Needed /= No_Wrapper |
| 2108 |
and then not Is_Abstract_Subprogram (Par_Prim) |
| 2109 |
and then Expander_Active |
| 2110 |
then |
| 2111 |
-- Build the dispatch-table wrapper (DTW). The support for |
| 2112 |
-- AI12-0195 relies on two kind of wrappers: one for indirect |
| 2113 |
-- calls (also used for AI12-0220), and one for putting in the |
| 2114 |
-- dispatch table: |
| 2115 |
-- |
| 2116 |
-- 1) "indirect-call wrapper" (ICW) is needed anytime there are |
| 2117 |
-- class-wide preconditions. Prim'Access will point directly |
| 2118 |
-- at the ICW if any, or at the "pristine" body if Prim has |
| 2119 |
-- no class-wide preconditions. |
| 2120 |
-- |
| 2121 |
-- 2) "dispatch-table wrapper" (DTW) is needed anytime the class |
| 2122 |
-- wide preconditions *or* the class-wide postconditions are |
| 2123 |
-- affected by overriding. |
| 2124 |
-- |
| 2125 |
-- The DTW holds a single statement that is a single call where |
| 2126 |
-- the controlling actuals are conversions to the corresponding |
| 2127 |
-- type in the parent primitive. If the primitive is a function |
| 2128 |
-- the statement is a return statement with a call. |
| 2129 |
|
| 2130 |
declare |
| 2131 |
Alias_Id : constant Entity_Id := Ultimate_Alias (Prim); |
| 2132 |
Loc : constant Source_Ptr := Sloc (R); |
| 2133 |
DTW_Body : Node_Id; |
| 2134 |
DTW_Decl : Node_Id; |
| 2135 |
DTW_Id : Entity_Id; |
| 2136 |
DTW_Spec : Node_Id; |
| 2137 |
|
| 2138 |
Prim_Next_E : constant Entity_Id := Next_Entity (Prim); |
| 2139 |
Prim_Prev_E : constant Entity_Id := Prev_Entity (Prim); |
| 2140 |
|
| 2141 |
begin |
| 2142 |
DTW_Spec := Build_DTW_Spec (Par_Prim); |
| 2143 |
DTW_Id := Defining_Entity (DTW_Spec); |
| 2144 |
DTW_Decl := Make_Subprogram_Declaration (Loc, |
| 2145 |
Specification => DTW_Spec); |
| 2146 |
|
| 2147 |
-- LSP wrappers reference the parent primitive that has the |
| 2148 |
-- the class-wide pre/post condition that calls overridden |
| 2149 |
-- primitives. Condition wrappers do not have this attribute |
| 2150 |
-- (see predicate Is_LSP_Wrapper). |
| 2151 |
|
| 2152 |
if Wrapper_Needed = LSP_Wrapper then |
| 2153 |
Set_LSP_Subprogram (DTW_Id, Par_Prim); |
| 2154 |
end if; |
| 2155 |
|
| 2156 |
-- The spec of the wrapper has been built using the source |
| 2157 |
-- location of its parent primitive; we must update it now |
| 2158 |
-- (with the source location of the internal primitive built |
| 2159 |
-- by Derive_Subprogram that will override this wrapper) to |
| 2160 |
-- avoid inlining conflicts between internally built helpers |
| 2161 |
-- for class-wide pre/postconditions of the parent and the |
| 2162 |
-- helpers built for this wrapper. |
| 2163 |
|
| 2164 |
Set_Sloc (DTW_Id, Sloc (Prim)); |
| 2165 |
|
| 2166 |
-- For LSP_Wrappers of subprograms that inherit class-wide |
| 2167 |
-- preconditions the DTW wrapper reuses the ICW of the parent |
| 2168 |
-- (which checks the parent interpretation of the class-wide |
| 2169 |
-- preconditions); the interpretation of the class-wide |
| 2170 |
-- preconditions for the inherited subprogram is checked |
| 2171 |
-- at the caller side. |
| 2172 |
|
| 2173 |
-- When the subprogram inherits class-wide postconditions |
| 2174 |
-- the DTW also checks the interpretation of the class-wide |
| 2175 |
-- postconditions for the inherited subprogram, and the body |
| 2176 |
-- of the parent checks its interpretation of the parent for |
| 2177 |
-- the class-wide postconditions. |
| 2178 |
|
| 2179 |
-- procedure Prim (F1 : T1; ...) is |
| 2180 |
-- [ pragma Postcondition (check => Expr); ] |
| 2181 |
-- begin |
| 2182 |
-- Par_Prim_ICW (Par_Type (F1), ...); |
| 2183 |
-- end; |
| 2184 |
|
| 2185 |
if Wrapper_Needed = LSP_Wrapper |
| 2186 |
and then Present (Indirect_Call_Wrapper (Par_Prim)) |
| 2187 |
then |
| 2188 |
DTW_Body := |
| 2189 |
Build_DTW_Body (Loc, |
| 2190 |
DTW_Spec => DTW_Spec, |
| 2191 |
DTW_Decls => Decls, |
| 2192 |
Par_Prim => Par_Prim, |
| 2193 |
Wrapped_Subp => Indirect_Call_Wrapper (Par_Prim)); |
| 2194 |
|
| 2195 |
-- For LSP_Wrappers of subprograms that only inherit class-wide |
| 2196 |
-- postconditions, and also for Condition_Wrappers (wrappers of |
| 2197 |
-- inherited subprograms that implement additional interface |
| 2198 |
-- primitives that have class-wide pre-/postconditions), the |
| 2199 |
-- DTW wrapper calls the parent primitive (which on its body |
| 2200 |
-- checks the interpretation of the class-wide post-conditions |
| 2201 |
-- for the parent subprogram), and the DTW checks the |
| 2202 |
-- interpretation of the class-wide postconditions for the |
| 2203 |
-- inherited subprogram. |
| 2204 |
|
| 2205 |
-- procedure Prim (F1 : T1; ...) is |
| 2206 |
-- pragma Postcondition (check => Expr); |
| 2207 |
-- begin |
| 2208 |
-- Par_Prim (Par_Type (F1), ...); |
| 2209 |
-- end; |
| 2210 |
|
| 2211 |
-- No class-wide preconditions runtime check is generated for |
| 2212 |
-- this wrapper call to the parent primitive, since the check |
| 2213 |
-- is performed by the caller of the DTW wrapper (see routine |
| 2214 |
-- Install_Class_Preconditions_Check). |
| 2215 |
|
| 2216 |
else |
| 2217 |
DTW_Body := |
| 2218 |
Build_DTW_Body (Loc, |
| 2219 |
DTW_Spec => DTW_Spec, |
| 2220 |
DTW_Decls => Decls, |
| 2221 |
Par_Prim => Par_Prim, |
| 2222 |
Wrapped_Subp => Par_Prim); |
| 2223 |
end if; |
| 2224 |
|
| 2225 |
-- Insert the declaration of the wrapper before the freezing |
| 2226 |
-- node of the record type declaration to ensure that it will |
| 2227 |
-- override the internal primitive built by Derive_Subprogram. |
| 2228 |
|
| 2229 |
if Late_Overriding then |
| 2230 |
Ensure_Freeze_Node (R); |
| 2231 |
Insert_Before_And_Analyze (Freeze_Node (R), DTW_Decl); |
| 2232 |
else |
| 2233 |
Append_Freeze_Action (R, DTW_Decl); |
| 2234 |
Analyze (DTW_Decl); |
| 2235 |
end if; |
| 2236 |
|
| 2237 |
-- The analyis of DTW_Decl has removed Prim from its scope |
| 2238 |
-- chain and added DTW_Id at the end of the scope chain. Move |
| 2239 |
-- DTW_Id to its correct place in the scope chain: the analysis |
| 2240 |
-- of the wrapper declaration has just added DTW_Id at the end |
| 2241 |
-- of the list of entities of its scope. However, given that |
| 2242 |
-- this wrapper overrides Prim, we must move DTW_Id to the |
| 2243 |
-- original place of Prim in its scope chain. This is required |
| 2244 |
-- for wrappers of private type primitives to ensure their |
| 2245 |
-- correct visibility since wrappers are built when the full |
| 2246 |
-- tagged type declaration is frozen (in the private part of |
| 2247 |
-- the package) but they may override primitives defined in the |
| 2248 |
-- public part of the package. |
| 2249 |
|
| 2250 |
declare |
| 2251 |
DTW_Prev_E : constant Entity_Id := Prev_Entity (DTW_Id); |
| 2252 |
|
| 2253 |
begin |
| 2254 |
pragma Assert (Last_Entity (Current_Scope) = DTW_Id); |
| 2255 |
pragma Assert |
| 2256 |
(Ekind (Current_Scope) not in E_Package | E_Generic_Package |
| 2257 |
or else No (First_Private_Entity (Current_Scope)) |
| 2258 |
or else First_Private_Entity (Current_Scope) /= DTW_Id); |
| 2259 |
|
| 2260 |
-- Remove DTW_Id from the end of the doubly-linked list of |
| 2261 |
-- entities of this scope; no need to handle removing it |
| 2262 |
-- from the beginning of the chain since such case can never |
| 2263 |
-- occur for this entity. |
| 2264 |
|
| 2265 |
Set_Last_Entity (Current_Scope, DTW_Prev_E); |
| 2266 |
Set_Next_Entity (DTW_Prev_E, Empty); |
| 2267 |
|
| 2268 |
-- Place DTW_Id back in the original place of its wrapped |
| 2269 |
-- primitive in the list of entities of this scope. |
| 2270 |
|
| 2271 |
Link_Entities (Prim_Prev_E, DTW_Id); |
| 2272 |
Link_Entities (DTW_Id, Prim_Next_E); |
| 2273 |
end; |
| 2274 |
|
| 2275 |
-- Insert the body of the wrapper in the freeze actions of |
| 2276 |
-- its record type declaration to ensure that it is placed |
| 2277 |
-- in the scope of its declaration but not too early to cause |
| 2278 |
-- premature freezing of other entities. |
| 2279 |
|
| 2280 |
Append_Freeze_Action (R, DTW_Body); |
| 2281 |
Analyze (DTW_Body); |
| 2282 |
|
| 2283 |
-- Ensure correct decoration |
| 2284 |
|
| 2285 |
pragma Assert (Is_Dispatching_Operation (DTW_Id)); |
| 2286 |
pragma Assert (Present (Overridden_Operation (DTW_Id))); |
| 2287 |
pragma Assert (Overridden_Operation (DTW_Id) = Alias_Id); |
| 2288 |
|
| 2289 |
-- Inherit dispatch table slot |
| 2290 |
|
| 2291 |
Set_DTC_Entity_Value (R, DTW_Id); |
| 2292 |
Set_DT_Position (DTW_Id, DT_Position (Alias_Id)); |
| 2293 |
|
| 2294 |
-- Register the wrapper in the dispatch table |
| 2295 |
|
| 2296 |
if Late_Overriding |
| 2297 |
and then not Building_Static_DT (R) |
| 2298 |
then |
| 2299 |
Insert_List_After_And_Analyze (Freeze_Node (R), |
| 2300 |
Register_Primitive (Loc, DTW_Id)); |
| 2301 |
end if; |
| 2302 |
|
| 2303 |
-- Defer building helpers and ICW for the DTW. Required to |
| 2304 |
-- ensure uniqueness in their names because when building |
| 2305 |
-- these wrappers for overlapped subprograms their homonym |
| 2306 |
-- number is not definite until all these dispatch table |
| 2307 |
-- wrappers of tagged type R have been analyzed. |
| 2308 |
|
| 2309 |
if Present (Indirect_Call_Wrapper (Par_Prim)) then |
| 2310 |
Append_New_Elmt (DTW_Id, Wrappers_List); |
| 2311 |
end if; |
| 2312 |
end; |
| 2313 |
end if; |
| 2314 |
|
| 2315 |
Next_Elmt (Op_Node); |
| 2316 |
end loop; |
| 2317 |
|
| 2318 |
-- Build and analyze deferred class-wide precondition subprograms of |
| 2319 |
-- built wrappers. |
| 2320 |
|
| 2321 |
if Present (Wrappers_List) then |
| 2322 |
declare |
| 2323 |
Body_N : Node_Id; |
| 2324 |
CW_Subp : Entity_Id; |
| 2325 |
Decl_N : Node_Id; |
| 2326 |
DTW_Id : Entity_Id; |
| 2327 |
Elmt : Elmt_Id; |
| 2328 |
|
| 2329 |
begin |
| 2330 |
Elmt := First_Elmt (Wrappers_List); |
| 2331 |
|
| 2332 |
while Present (Elmt) loop |
| 2333 |
DTW_Id := Node (Elmt); |
| 2334 |
Next_Elmt (Elmt); |
| 2335 |
|
| 2336 |
Merge_Class_Conditions (DTW_Id); |
| 2337 |
Make_Class_Precondition_Subps (DTW_Id, Late_Overriding); |
| 2338 |
|
| 2339 |
CW_Subp := Static_Call_Helper (DTW_Id); |
| 2340 |
Decl_N := Unit_Declaration_Node (CW_Subp); |
| 2341 |
Analyze (Decl_N); |
| 2342 |
|
| 2343 |
-- If the DTW was built for a late-overriding primitive |
| 2344 |
-- its body must be analyzed now (since the tagged type |
| 2345 |
-- is already frozen). |
| 2346 |
|
| 2347 |
if Late_Overriding then |
| 2348 |
Body_N := |
| 2349 |
Unit_Declaration_Node (Corresponding_Body (Decl_N)); |
| 2350 |
Analyze (Body_N); |
| 2351 |
end if; |
| 2352 |
end loop; |
| 2353 |
end; |
| 2354 |
end if; |
| 2355 |
end Check_Inherited_Conditions; |
| 2356 |
|
| 2357 |
---------------------------- |
| 2358 |
-- Check_Strict_Alignment -- |
| 2359 |
---------------------------- |
| 2360 |
|
| 2361 |
procedure Check_Strict_Alignment (E : Entity_Id) is |
| 2362 |
Comp : Entity_Id; |
| 2363 |
|
| 2364 |
begin |
| 2365 |
-- Bit-packed array types do not require strict alignment, even if they |
| 2366 |
-- are by-reference types, because they are accessed in a special way. |
| 2367 |
|
| 2368 |
if Is_By_Reference_Type (E) and then not Is_Bit_Packed_Array (E) then |
| 2369 |
Set_Strict_Alignment (E); |
| 2370 |
|
| 2371 |
elsif Is_Array_Type (E) then |
| 2372 |
Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E))); |
| 2373 |
|
| 2374 |
-- RM 13.2(7.1/4): Any component of a packed type that contains an |
| 2375 |
-- aliased part shall be aligned according to the alignment of its |
| 2376 |
-- subtype. |
| 2377 |
|
| 2378 |
-- Unfortunately this breaks Florist, which has had the bad habit |
| 2379 |
-- of overaligning all the types it declares on 32-bit platforms, |
| 2380 |
-- so make an exception if the component size is the storage unit. |
| 2381 |
|
| 2382 |
-- Other legacy codebases could also be affected because this was |
| 2383 |
-- historically not enforced, so -gnatd_l can be used to disable it. |
| 2384 |
|
| 2385 |
if Has_Aliased_Components (E) |
| 2386 |
and then not (Known_Component_Size (E) |
| 2387 |
and then Component_Size (E) = System_Storage_Unit) |
| 2388 |
and then not Debug_Flag_Underscore_L |
| 2389 |
then |
| 2390 |
Set_Strict_Alignment (E); |
| 2391 |
end if; |
| 2392 |
|
| 2393 |
elsif Is_Record_Type (E) then |
| 2394 |
Comp := First_Component (E); |
| 2395 |
while Present (Comp) loop |
| 2396 |
if not Is_Type (Comp) |
| 2397 |
and then (Is_Aliased (Comp) |
| 2398 |
or else Strict_Alignment (Etype (Comp))) |
| 2399 |
then |
| 2400 |
Set_Strict_Alignment (E); |
| 2401 |
return; |
| 2402 |
end if; |
| 2403 |
|
| 2404 |
Next_Component (Comp); |
| 2405 |
end loop; |
| 2406 |
end if; |
| 2407 |
end Check_Strict_Alignment; |
| 2408 |
|
| 2409 |
------------------------- |
| 2410 |
-- Check_Unsigned_Type -- |
| 2411 |
------------------------- |
| 2412 |
|
| 2413 |
procedure Check_Unsigned_Type (E : Entity_Id) is |
| 2414 |
Ancestor : Entity_Id; |
| 2415 |
Lo_Bound : Node_Id; |
| 2416 |
Btyp : Entity_Id; |
| 2417 |
|
| 2418 |
begin |
| 2419 |
if not Is_Discrete_Or_Fixed_Point_Type (E) then |
| 2420 |
return; |
| 2421 |
end if; |
| 2422 |
|
| 2423 |
-- Do not attempt to analyze case where range was in error |
| 2424 |
|
| 2425 |
if No (Scalar_Range (E)) or else Error_Posted (Scalar_Range (E)) then |
| 2426 |
return; |
| 2427 |
end if; |
| 2428 |
|
| 2429 |
-- The situation that is nontrivial is something like: |
| 2430 |
|
| 2431 |
-- subtype x1 is integer range -10 .. +10; |
| 2432 |
-- subtype x2 is x1 range 0 .. V1; |
| 2433 |
-- subtype x3 is x2 range V2 .. V3; |
| 2434 |
-- subtype x4 is x3 range V4 .. V5; |
| 2435 |
|
| 2436 |
-- where Vn are variables. Here the base type is signed, but we still |
| 2437 |
-- know that x4 is unsigned because of the lower bound of x2. |
| 2438 |
|
| 2439 |
-- The only way to deal with this is to look up the ancestor chain |
| 2440 |
|
| 2441 |
Ancestor := E; |
| 2442 |
loop |
| 2443 |
if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then |
| 2444 |
return; |
| 2445 |
end if; |
| 2446 |
|
| 2447 |
Lo_Bound := Type_Low_Bound (Ancestor); |
| 2448 |
|
| 2449 |
if Compile_Time_Known_Value (Lo_Bound) then |
| 2450 |
if Expr_Rep_Value (Lo_Bound) >= 0 then |
| 2451 |
Set_Is_Unsigned_Type (E, True); |
| 2452 |
end if; |
| 2453 |
|
| 2454 |
return; |
| 2455 |
|
| 2456 |
else |
| 2457 |
Ancestor := Ancestor_Subtype (Ancestor); |
| 2458 |
|
| 2459 |
-- If no ancestor had a static lower bound, go to base type |
| 2460 |
|
| 2461 |
if No (Ancestor) then |
| 2462 |
|
| 2463 |
-- Note: the reason we still check for a compile time known |
| 2464 |
-- value for the base type is that at least in the case of |
| 2465 |
-- generic formals, we can have bounds that fail this test, |
| 2466 |
-- and there may be other cases in error situations. |
| 2467 |
|
| 2468 |
Btyp := Base_Type (E); |
| 2469 |
|
| 2470 |
if Btyp = Any_Type or else Etype (Btyp) = Any_Type then |
| 2471 |
return; |
| 2472 |
end if; |
| 2473 |
|
| 2474 |
Lo_Bound := Type_Low_Bound (Base_Type (E)); |
| 2475 |
|
| 2476 |
if Compile_Time_Known_Value (Lo_Bound) |
| 2477 |
and then Expr_Rep_Value (Lo_Bound) >= 0 |
| 2478 |
then |
| 2479 |
Set_Is_Unsigned_Type (E, True); |
| 2480 |
end if; |
| 2481 |
|
| 2482 |
return; |
| 2483 |
end if; |
| 2484 |
end if; |
| 2485 |
end loop; |
| 2486 |
end Check_Unsigned_Type; |
| 2487 |
|
| 2488 |
----------------------------------------------- |
| 2489 |
-- Explode_Initialization_Compound_Statement -- |
| 2490 |
----------------------------------------------- |
| 2491 |
|
| 2492 |
procedure Explode_Initialization_Compound_Statement (E : Entity_Id) is |
| 2493 |
Init_Stmts : constant Node_Id := Initialization_Statements (E); |
| 2494 |
|
| 2495 |
begin |
| 2496 |
if Present (Init_Stmts) |
| 2497 |
and then Nkind (Init_Stmts) = N_Compound_Statement |
| 2498 |
then |
| 2499 |
-- If the entity has its freezing delayed, append the initialization |
| 2500 |
-- actions to its freeze actions. Otherwise insert them back at the |
| 2501 |
-- point where they have been generated. |
| 2502 |
|
| 2503 |
if Has_Delayed_Freeze (E) then |
| 2504 |
Append_Freeze_Actions (E, Actions (Init_Stmts)); |
| 2505 |
else |
| 2506 |
Insert_List_Before (Init_Stmts, Actions (Init_Stmts)); |
| 2507 |
end if; |
| 2508 |
|
| 2509 |
-- Note that we rewrite Init_Stmts into a null statement, rather than |
| 2510 |
-- just removing it, because Freeze_All may rely on this particular |
| 2511 |
-- node still being present in the enclosing list to know where to |
| 2512 |
-- stop freezing. |
| 2513 |
|
| 2514 |
Rewrite (Init_Stmts, Make_Null_Statement (Sloc (Init_Stmts))); |
| 2515 |
|
| 2516 |
Set_Initialization_Statements (E, Empty); |
| 2517 |
end if; |
| 2518 |
end Explode_Initialization_Compound_Statement; |
| 2519 |
|
| 2520 |
---------------- |
| 2521 |
-- Freeze_All -- |
| 2522 |
---------------- |
| 2523 |
|
| 2524 |
-- Note: the easy coding for this procedure would be to just build a |
| 2525 |
-- single list of freeze nodes and then insert them and analyze them |
| 2526 |
-- all at once. This won't work, because the analysis of earlier freeze |
| 2527 |
-- nodes may recursively freeze types which would otherwise appear later |
| 2528 |
-- on in the freeze list. So we must analyze and expand the freeze nodes |
| 2529 |
-- as they are generated. |
| 2530 |
|
| 2531 |
procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is |
| 2532 |
procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id); |
| 2533 |
-- This is the internal recursive routine that does freezing of entities |
| 2534 |
-- (but NOT the analysis of default expressions, which should not be |
| 2535 |
-- recursive, we don't want to analyze those till we are sure that ALL |
| 2536 |
-- the types are frozen). |
| 2537 |
|
| 2538 |
-------------------- |
| 2539 |
-- Freeze_All_Ent -- |
| 2540 |
-------------------- |
| 2541 |
|
| 2542 |
procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id) is |
| 2543 |
E : Entity_Id; |
| 2544 |
Flist : List_Id; |
| 2545 |
|
| 2546 |
procedure Process_Flist; |
| 2547 |
-- If freeze nodes are present, insert and analyze, and reset cursor |
| 2548 |
-- for next insertion. |
| 2549 |
|
| 2550 |
------------------- |
| 2551 |
-- Process_Flist -- |
| 2552 |
------------------- |
| 2553 |
|
| 2554 |
procedure Process_Flist is |
| 2555 |
Lastn : Node_Id; |
| 2556 |
begin |
| 2557 |
if Is_Non_Empty_List (Flist) then |
| 2558 |
Lastn := Next (After); |
| 2559 |
Insert_List_After_And_Analyze (After, Flist); |
| 2560 |
|
| 2561 |
if Present (Lastn) then |
| 2562 |
After := Prev (Lastn); |
| 2563 |
else |
| 2564 |
After := Last (List_Containing (After)); |
| 2565 |
end if; |
| 2566 |
end if; |
| 2567 |
end Process_Flist; |
| 2568 |
|
| 2569 |
-- Start of processing for Freeze_All_Ent |
| 2570 |
|
| 2571 |
begin |
| 2572 |
E := From; |
| 2573 |
while Present (E) loop |
| 2574 |
|
| 2575 |
-- If the entity is an inner package which is not a package |
| 2576 |
-- renaming, then its entities must be frozen at this point. Note |
| 2577 |
-- that such entities do NOT get frozen at the end of the nested |
| 2578 |
-- package itself (only library packages freeze). |
| 2579 |
|
| 2580 |
-- Same is true for task declarations, where anonymous records |
| 2581 |
-- created for entry parameters must be frozen. |
| 2582 |
|
| 2583 |
if Ekind (E) = E_Package |
| 2584 |
and then No (Renamed_Entity (E)) |
| 2585 |
and then not Is_Child_Unit (E) |
| 2586 |
and then not Is_Frozen (E) |
| 2587 |
then |
| 2588 |
Push_Scope (E); |
| 2589 |
|
| 2590 |
Install_Visible_Declarations (E); |
| 2591 |
Install_Private_Declarations (E); |
| 2592 |
Freeze_All (First_Entity (E), After); |
| 2593 |
|
| 2594 |
End_Package_Scope (E); |
| 2595 |
|
| 2596 |
if Is_Generic_Instance (E) |
| 2597 |
and then Has_Delayed_Freeze (E) |
| 2598 |
then |
| 2599 |
Set_Has_Delayed_Freeze (E, False); |
| 2600 |
Expand_N_Package_Declaration (Unit_Declaration_Node (E)); |
| 2601 |
end if; |
| 2602 |
|
| 2603 |
elsif Ekind (E) in Task_Kind |
| 2604 |
and then Nkind (Parent (E)) in |
| 2605 |
N_Single_Task_Declaration | N_Task_Type_Declaration |
| 2606 |
then |
| 2607 |
Push_Scope (E); |
| 2608 |
Freeze_All (First_Entity (E), After); |
| 2609 |
End_Scope; |
| 2610 |
|
| 2611 |
-- For a derived tagged type, we must ensure that all the |
| 2612 |
-- primitive operations of the parent have been frozen, so that |
| 2613 |
-- their addresses will be in the parent's dispatch table at the |
| 2614 |
-- point it is inherited. |
| 2615 |
|
| 2616 |
elsif Ekind (E) = E_Record_Type |
| 2617 |
and then Is_Tagged_Type (E) |
| 2618 |
and then Is_Tagged_Type (Etype (E)) |
| 2619 |
and then Is_Derived_Type (E) |
| 2620 |
then |
| 2621 |
declare |
| 2622 |
Prim_List : constant Elist_Id := |
| 2623 |
Primitive_Operations (Etype (E)); |
| 2624 |
|
| 2625 |
Prim : Elmt_Id; |
| 2626 |
Subp : Entity_Id; |
| 2627 |
|
| 2628 |
begin |
| 2629 |
Prim := First_Elmt (Prim_List); |
| 2630 |
while Present (Prim) loop |
| 2631 |
Subp := Node (Prim); |
| 2632 |
|
| 2633 |
if Comes_From_Source (Subp) |
| 2634 |
and then not Is_Frozen (Subp) |
| 2635 |
then |
| 2636 |
Flist := Freeze_Entity (Subp, After); |
| 2637 |
Process_Flist; |
| 2638 |
end if; |
| 2639 |
|
| 2640 |
Next_Elmt (Prim); |
| 2641 |
end loop; |
| 2642 |
end; |
| 2643 |
end if; |
| 2644 |
|
| 2645 |
if not Is_Frozen (E) then |
| 2646 |
Flist := Freeze_Entity (E, After); |
| 2647 |
Process_Flist; |
| 2648 |
|
| 2649 |
-- If already frozen, and there are delayed aspects, this is where |
| 2650 |
-- we do the visibility check for these aspects (see Sem_Ch13 spec |
| 2651 |
-- for a description of how we handle aspect visibility). |
| 2652 |
|
| 2653 |
elsif Has_Delayed_Aspects (E) then |
| 2654 |
Check_Aspects_At_End_Of_Declarations (E); |
| 2655 |
end if; |
| 2656 |
|
| 2657 |
-- If an incomplete type is still not frozen, this may be a |
| 2658 |
-- premature freezing because of a body declaration that follows. |
| 2659 |
-- Indicate where the freezing took place. Freezing will happen |
| 2660 |
-- if the body comes from source, but not if it is internally |
| 2661 |
-- generated, for example as the body of a type invariant. |
| 2662 |
|
| 2663 |
-- If the freezing is caused by the end of the current declarative |
| 2664 |
-- part, it is a Taft Amendment type, and there is no error. |
| 2665 |
|
| 2666 |
if not Is_Frozen (E) |
| 2667 |
and then Ekind (E) = E_Incomplete_Type |
| 2668 |
then |
| 2669 |
declare |
| 2670 |
Bod : constant Node_Id := Next (After); |
| 2671 |
|
| 2672 |
begin |
| 2673 |
-- The presence of a body freezes all entities previously |
| 2674 |
-- declared in the current list of declarations, but this |
| 2675 |
-- does not apply if the body does not come from source. |
| 2676 |
-- A type invariant is transformed into a subprogram body |
| 2677 |
-- which is placed at the end of the private part of the |
| 2678 |
-- current package, but this body does not freeze incomplete |
| 2679 |
-- types that may be declared in this private part. |
| 2680 |
|
| 2681 |
if Comes_From_Source (Bod) |
| 2682 |
and then Nkind (Bod) in N_Entry_Body |
| 2683 |
| N_Package_Body |
| 2684 |
| N_Protected_Body |
| 2685 |
| N_Subprogram_Body |
| 2686 |
| N_Task_Body |
| 2687 |
| N_Body_Stub |
| 2688 |
and then |
| 2689 |
In_Same_List (After, Parent (E)) |
| 2690 |
then |
| 2691 |
Error_Msg_Sloc := Sloc (Next (After)); |
| 2692 |
Error_Msg_NE |
| 2693 |
("type& is frozen# before its full declaration", |
| 2694 |
Parent (E), E); |
| 2695 |
end if; |
| 2696 |
end; |
| 2697 |
end if; |
| 2698 |
|
| 2699 |
Next_Entity (E); |
| 2700 |
end loop; |
| 2701 |
end Freeze_All_Ent; |
| 2702 |
|
| 2703 |
-- Local variables |
| 2704 |
|
| 2705 |
Decl : Node_Id; |
| 2706 |
E : Entity_Id; |
| 2707 |
Item : Entity_Id; |
| 2708 |
|
| 2709 |
-- Start of processing for Freeze_All |
| 2710 |
|
| 2711 |
begin |
| 2712 |
Freeze_All_Ent (From, After); |
| 2713 |
|
| 2714 |
-- Now that all types are frozen, we can deal with default expressions |
| 2715 |
-- that require us to build a default expression functions. This is the |
| 2716 |
-- point at which such functions are constructed (after all types that |
| 2717 |
-- might be used in such expressions have been frozen). |
| 2718 |
|
| 2719 |
-- For subprograms that are renaming_as_body, we create the wrapper |
| 2720 |
-- bodies as needed. |
| 2721 |
|
| 2722 |
-- We also add finalization chains to access types whose designated |
| 2723 |
-- types are controlled. This is normally done when freezing the type, |
| 2724 |
-- but this misses recursive type definitions where the later members |
| 2725 |
-- of the recursion introduce controlled components. |
| 2726 |
|
| 2727 |
-- Loop through entities |
| 2728 |
|
| 2729 |
E := From; |
| 2730 |
while Present (E) loop |
| 2731 |
if Is_Subprogram (E) then |
| 2732 |
if not Default_Expressions_Processed (E) then |
| 2733 |
Process_Default_Expressions (E, After); |
| 2734 |
end if; |
| 2735 |
|
| 2736 |
-- Check subprogram renamings for the same strub-mode. |
| 2737 |
-- Avoid rechecking dispatching operations, that's taken |
| 2738 |
-- care of in Check_Inherited_Conditions, that covers |
| 2739 |
-- inherited interface operations. |
| 2740 |
|
| 2741 |
Item := Alias (E); |
| 2742 |
if Present (Item) |
| 2743 |
and then not Is_Dispatching_Operation (E) |
| 2744 |
then |
| 2745 |
Check_Same_Strub_Mode (E, Item); |
| 2746 |
end if; |
| 2747 |
|
| 2748 |
if not Has_Completion (E) then |
| 2749 |
Decl := Unit_Declaration_Node (E); |
| 2750 |
|
| 2751 |
if Nkind (Decl) = N_Subprogram_Renaming_Declaration then |
| 2752 |
if Error_Posted (Decl) then |
| 2753 |
Set_Has_Completion (E); |
| 2754 |
else |
| 2755 |
Build_And_Analyze_Renamed_Body (Decl, E, After); |
| 2756 |
end if; |
| 2757 |
|
| 2758 |
elsif Nkind (Decl) = N_Subprogram_Declaration |
| 2759 |
and then Present (Corresponding_Body (Decl)) |
| 2760 |
and then |
| 2761 |
Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) = |
| 2762 |
N_Subprogram_Renaming_Declaration |
| 2763 |
then |
| 2764 |
Build_And_Analyze_Renamed_Body |
| 2765 |
(Decl, Corresponding_Body (Decl), After); |
| 2766 |
end if; |
| 2767 |
end if; |
| 2768 |
|
| 2769 |
-- Freeze the default expressions of entries, entry families, and |
| 2770 |
-- protected subprograms. |
| 2771 |
|
| 2772 |
elsif Is_Concurrent_Type (E) then |
| 2773 |
Item := First_Entity (E); |
| 2774 |
while Present (Item) loop |
| 2775 |
if Is_Subprogram_Or_Entry (Item) |
| 2776 |
and then not Default_Expressions_Processed (Item) |
| 2777 |
then |
| 2778 |
Process_Default_Expressions (Item, After); |
| 2779 |
end if; |
| 2780 |
|
| 2781 |
Next_Entity (Item); |
| 2782 |
end loop; |
| 2783 |
end if; |
| 2784 |
|
| 2785 |
-- Historical note: We used to create a finalization collection for |
| 2786 |
-- access types whose designated type is not controlled, but contains |
| 2787 |
-- private controlled compoments. This form of postprocessing is no |
| 2788 |
-- longer needed because the finalization collection is now created |
| 2789 |
-- when the access type is frozen (see Exp_Ch3.Freeze_Type). |
| 2790 |
|
| 2791 |
Next_Entity (E); |
| 2792 |
end loop; |
| 2793 |
end Freeze_All; |
| 2794 |
|
| 2795 |
----------------------- |
| 2796 |
-- Freeze_And_Append -- |
| 2797 |
----------------------- |
| 2798 |
|
| 2799 |
procedure Freeze_And_Append |
| 2800 |
(Ent : Entity_Id; |
| 2801 |
N : Node_Id; |
| 2802 |
Result : in out List_Id) |
| 2803 |
is |
| 2804 |
-- Freezing an Expression_Function does not freeze its profile: |
| 2805 |
-- the formals will have been frozen otherwise before the E_F |
| 2806 |
-- can be called. |
| 2807 |
|
| 2808 |
L : constant List_Id := |
| 2809 |
Freeze_Entity |
| 2810 |
(Ent, N, Do_Freeze_Profile => not Is_Expression_Function (Ent)); |
| 2811 |
begin |
| 2812 |
if Is_Non_Empty_List (L) then |
| 2813 |
if Result = No_List then |
| 2814 |
Result := L; |
| 2815 |
else |
| 2816 |
Append_List (L, Result); |
| 2817 |
end if; |
| 2818 |
end if; |
| 2819 |
end Freeze_And_Append; |
| 2820 |
|
| 2821 |
------------------- |
| 2822 |
-- Freeze_Before -- |
| 2823 |
------------------- |
| 2824 |
|
| 2825 |
procedure Freeze_Before |
| 2826 |
(N : Node_Id; |
| 2827 |
T : Entity_Id; |
| 2828 |
Do_Freeze_Profile : Boolean := True) |
| 2829 |
is |
| 2830 |
-- Freeze T, then insert the generated Freeze nodes before the node N. |
| 2831 |
-- Flag Freeze_Profile is used when T is an overloadable entity, and |
| 2832 |
-- indicates whether its profile should be frozen at the same time. |
| 2833 |
|
| 2834 |
Freeze_Nodes : constant List_Id := |
| 2835 |
Freeze_Entity (T, N, Do_Freeze_Profile); |
| 2836 |
Pack : constant Entity_Id := Scope (T); |
| 2837 |
|
| 2838 |
begin |
| 2839 |
if Ekind (T) = E_Function then |
| 2840 |
Check_Expression_Function (N, T); |
| 2841 |
end if; |
| 2842 |
|
| 2843 |
if Is_Non_Empty_List (Freeze_Nodes) then |
| 2844 |
|
| 2845 |
-- If the entity is a type declared in an inner package, it may be |
| 2846 |
-- frozen by an outer declaration before the package itself is |
| 2847 |
-- frozen. Install the package scope to analyze the freeze nodes, |
| 2848 |
-- which may include generated subprograms such as predicate |
| 2849 |
-- functions, etc. |
| 2850 |
|
| 2851 |
if Is_Type (T) and then From_Nested_Package (T) then |
| 2852 |
Push_Scope (Pack); |
| 2853 |
Install_Visible_Declarations (Pack); |
| 2854 |
Install_Private_Declarations (Pack); |
| 2855 |
Insert_Actions (N, Freeze_Nodes); |
| 2856 |
End_Package_Scope (Pack); |
| 2857 |
|
| 2858 |
else |
| 2859 |
Insert_Actions (N, Freeze_Nodes); |
| 2860 |
end if; |
| 2861 |
end if; |
| 2862 |
end Freeze_Before; |
| 2863 |
|
| 2864 |
------------------- |
| 2865 |
-- Freeze_Entity -- |
| 2866 |
------------------- |
| 2867 |
|
| 2868 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 2869 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 2870 |
-- Ghost mode. |
| 2871 |
|
| 2872 |
function Freeze_Entity |
| 2873 |
(E : Entity_Id; |
| 2874 |
N : Node_Id; |
| 2875 |
Do_Freeze_Profile : Boolean := True) return List_Id |
| 2876 |
is |
| 2877 |
Loc : constant Source_Ptr := Sloc (N); |
| 2878 |
|
| 2879 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 2880 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 2881 |
-- Save the Ghost-related attributes to restore on exit |
| 2882 |
|
| 2883 |
Atype : Entity_Id; |
| 2884 |
Comp : Entity_Id; |
| 2885 |
F_Node : Node_Id; |
| 2886 |
Formal : Entity_Id; |
| 2887 |
Indx : Node_Id; |
| 2888 |
|
| 2889 |
Result : List_Id := No_List; |
| 2890 |
-- List of freezing actions, left at No_List if none |
| 2891 |
|
| 2892 |
Test_E : Entity_Id := E; |
| 2893 |
-- A local temporary used to test if freezing is necessary for E, since |
| 2894 |
-- its value can be set to something other than E in certain cases. For |
| 2895 |
-- example, E cannot be used directly in cases such as when it is an |
| 2896 |
-- Itype defined within a record - since it is the location of record |
| 2897 |
-- which matters. |
| 2898 |
|
| 2899 |
procedure Add_To_Result (Fnod : Node_Id); |
| 2900 |
-- Add freeze action Fnod to list Result |
| 2901 |
|
| 2902 |
function After_Last_Declaration return Boolean; |
| 2903 |
-- If Loc is a freeze_entity that appears after the last declaration |
| 2904 |
-- in the scope, inhibit error messages on late completion. |
| 2905 |
|
| 2906 |
procedure Check_Current_Instance (Comp_Decl : Node_Id); |
| 2907 |
-- Check that an Access or Unchecked_Access attribute with a prefix |
| 2908 |
-- which is the current instance type can only be applied when the type |
| 2909 |
-- is limited. |
| 2910 |
|
| 2911 |
procedure Check_No_Parts_Violations |
| 2912 |
(Typ : Entity_Id; Aspect_No_Parts : Aspect_Id) with |
| 2913 |
Pre => Aspect_No_Parts in |
| 2914 |
Aspect_No_Controlled_Parts | Aspect_No_Task_Parts; |
| 2915 |
-- Check that Typ does not violate the semantics of the specified |
| 2916 |
-- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is |
| 2917 |
-- specified on Typ or one of its ancestors. |
| 2918 |
|
| 2919 |
procedure Check_Suspicious_Convention (Rec_Type : Entity_Id); |
| 2920 |
-- Give a warning for pragma Convention with language C or C++ applied |
| 2921 |
-- to a discriminated record type. This is suppressed for the unchecked |
| 2922 |
-- union case, since the whole point in this case is interface C. We |
| 2923 |
-- also do not generate this within instantiations, since we will have |
| 2924 |
-- generated a message on the template. |
| 2925 |
|
| 2926 |
procedure Check_Suspicious_Modulus (Utype : Entity_Id); |
| 2927 |
-- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit |
| 2928 |
-- integer literal without an explicit corresponding size clause. The |
| 2929 |
-- caller has checked that Utype is a modular integer type. |
| 2930 |
|
| 2931 |
procedure Freeze_Array_Type (Arr : Entity_Id); |
| 2932 |
-- Freeze array type, including freezing index and component types |
| 2933 |
|
| 2934 |
procedure Freeze_Object_Declaration (E : Entity_Id); |
| 2935 |
-- Perform checks and generate freeze node if needed for a constant or |
| 2936 |
-- variable declared by an object declaration. |
| 2937 |
|
| 2938 |
function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id; |
| 2939 |
-- Create Freeze_Generic_Entity nodes for types declared in a generic |
| 2940 |
-- package. Recurse on inner generic packages. |
| 2941 |
|
| 2942 |
function Freeze_Profile (E : Entity_Id) return Boolean; |
| 2943 |
-- Freeze formals and return type of subprogram. If some type in the |
| 2944 |
-- profile is incomplete and we are in an instance, freezing of the |
| 2945 |
-- entity will take place elsewhere, and the function returns False. |
| 2946 |
|
| 2947 |
procedure Freeze_Record_Type (Rec : Entity_Id); |
| 2948 |
-- Freeze record type, including freezing component types, and freezing |
| 2949 |
-- primitive operations if this is a tagged type. |
| 2950 |
|
| 2951 |
function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean; |
| 2952 |
-- Determine whether an arbitrary entity is subject to Boolean aspect |
| 2953 |
-- Import and its value is specified as True. |
| 2954 |
|
| 2955 |
procedure Inherit_Freeze_Node |
| 2956 |
(Fnod : Node_Id; |
| 2957 |
Typ : Entity_Id); |
| 2958 |
-- Set type Typ's freeze node to refer to Fnode. This routine ensures |
| 2959 |
-- that any attributes attached to Typ's original node are preserved. |
| 2960 |
|
| 2961 |
procedure Wrap_Imported_Subprogram (E : Entity_Id); |
| 2962 |
-- If E is an entity for an imported subprogram with pre/post-conditions |
| 2963 |
-- then this procedure will create a wrapper to ensure that proper run- |
| 2964 |
-- time checking of the pre/postconditions. See body for details. |
| 2965 |
|
| 2966 |
------------------- |
| 2967 |
-- Add_To_Result -- |
| 2968 |
------------------- |
| 2969 |
|
| 2970 |
procedure Add_To_Result (Fnod : Node_Id) is |
| 2971 |
begin |
| 2972 |
Append_New_To (Result, Fnod); |
| 2973 |
end Add_To_Result; |
| 2974 |
|
| 2975 |
---------------------------- |
| 2976 |
-- After_Last_Declaration -- |
| 2977 |
---------------------------- |
| 2978 |
|
| 2979 |
function After_Last_Declaration return Boolean is |
| 2980 |
Spec : constant Node_Id := Parent (Current_Scope); |
| 2981 |
|
| 2982 |
begin |
| 2983 |
if Nkind (Spec) = N_Package_Specification then |
| 2984 |
if Present (Private_Declarations (Spec)) then |
| 2985 |
return Loc >= Sloc (Last (Private_Declarations (Spec))); |
| 2986 |
elsif Present (Visible_Declarations (Spec)) then |
| 2987 |
return Loc >= Sloc (Last (Visible_Declarations (Spec))); |
| 2988 |
else |
| 2989 |
return False; |
| 2990 |
end if; |
| 2991 |
|
| 2992 |
else |
| 2993 |
return False; |
| 2994 |
end if; |
| 2995 |
end After_Last_Declaration; |
| 2996 |
|
| 2997 |
---------------------------- |
| 2998 |
-- Check_Current_Instance -- |
| 2999 |
---------------------------- |
| 3000 |
|
| 3001 |
procedure Check_Current_Instance (Comp_Decl : Node_Id) is |
| 3002 |
|
| 3003 |
function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean; |
| 3004 |
-- Determine whether Typ is compatible with the rules for aliased |
| 3005 |
-- views of types as defined in RM 3.10 in the various dialects. |
| 3006 |
|
| 3007 |
function Process (N : Node_Id) return Traverse_Result; |
| 3008 |
-- Process routine to apply check to given node |
| 3009 |
|
| 3010 |
----------------------------- |
| 3011 |
-- Is_Aliased_View_Of_Type -- |
| 3012 |
----------------------------- |
| 3013 |
|
| 3014 |
function Is_Aliased_View_Of_Type (Typ : Entity_Id) return Boolean is |
| 3015 |
Typ_Decl : constant Node_Id := Parent (Typ); |
| 3016 |
|
| 3017 |
begin |
| 3018 |
-- Common case |
| 3019 |
|
| 3020 |
if Nkind (Typ_Decl) = N_Full_Type_Declaration |
| 3021 |
and then Limited_Present (Type_Definition (Typ_Decl)) |
| 3022 |
then |
| 3023 |
return True; |
| 3024 |
|
| 3025 |
-- The following paragraphs describe what a legal aliased view of |
| 3026 |
-- a type is in the various dialects of Ada. |
| 3027 |
|
| 3028 |
-- Ada 95 |
| 3029 |
|
| 3030 |
-- The current instance of a limited type, and a formal parameter |
| 3031 |
-- or generic formal object of a tagged type. |
| 3032 |
|
| 3033 |
-- Ada 95 limited type |
| 3034 |
-- * Type with reserved word "limited" |
| 3035 |
-- * A protected or task type |
| 3036 |
-- * A composite type with limited component |
| 3037 |
|
| 3038 |
elsif Ada_Version <= Ada_95 then |
| 3039 |
return Is_Limited_Type (Typ); |
| 3040 |
|
| 3041 |
-- Ada 2005 |
| 3042 |
|
| 3043 |
-- The current instance of a limited tagged type, a protected |
| 3044 |
-- type, a task type, or a type that has the reserved word |
| 3045 |
-- "limited" in its full definition ... a formal parameter or |
| 3046 |
-- generic formal object of a tagged type. |
| 3047 |
|
| 3048 |
-- Ada 2005 limited type |
| 3049 |
-- * Type with reserved word "limited", "synchronized", "task" |
| 3050 |
-- or "protected" |
| 3051 |
-- * A composite type with limited component |
| 3052 |
-- * A derived type whose parent is a non-interface limited type |
| 3053 |
|
| 3054 |
elsif Ada_Version = Ada_2005 then |
| 3055 |
return |
| 3056 |
(Is_Limited_Type (Typ) and then Is_Tagged_Type (Typ)) |
| 3057 |
or else |
| 3058 |
(Is_Derived_Type (Typ) |
| 3059 |
and then not Is_Interface (Etype (Typ)) |
| 3060 |
and then Is_Limited_Type (Etype (Typ))); |
| 3061 |
|
| 3062 |
-- Ada 2012 and beyond |
| 3063 |
|
| 3064 |
-- The current instance of an immutably limited type ... a formal |
| 3065 |
-- parameter or generic formal object of a tagged type. |
| 3066 |
|
| 3067 |
-- Ada 2012 limited type |
| 3068 |
-- * Type with reserved word "limited", "synchronized", "task" |
| 3069 |
-- or "protected" |
| 3070 |
-- * A composite type with limited component |
| 3071 |
-- * A derived type whose parent is a non-interface limited type |
| 3072 |
-- * An incomplete view |
| 3073 |
|
| 3074 |
-- Ada 2012 immutably limited type |
| 3075 |
-- * Explicitly limited record type |
| 3076 |
-- * Record extension with "limited" present |
| 3077 |
-- * Non-formal limited private type that is either tagged |
| 3078 |
-- or has at least one access discriminant with a default |
| 3079 |
-- expression |
| 3080 |
-- * Task type, protected type or synchronized interface |
| 3081 |
-- * Type derived from immutably limited type |
| 3082 |
|
| 3083 |
else |
| 3084 |
return |
| 3085 |
Is_Immutably_Limited_Type (Typ) |
| 3086 |
or else Is_Incomplete_Type (Typ); |
| 3087 |
end if; |
| 3088 |
end Is_Aliased_View_Of_Type; |
| 3089 |
|
| 3090 |
------------- |
| 3091 |
-- Process -- |
| 3092 |
------------- |
| 3093 |
|
| 3094 |
function Process (N : Node_Id) return Traverse_Result is |
| 3095 |
begin |
| 3096 |
case Nkind (N) is |
| 3097 |
when N_Attribute_Reference => |
| 3098 |
if Attribute_Name (N) in Name_Access | Name_Unchecked_Access |
| 3099 |
and then Is_Entity_Name (Prefix (N)) |
| 3100 |
and then Entity (Prefix (N)) = E |
| 3101 |
then |
| 3102 |
if Ada_Version < Ada_2012 then |
| 3103 |
Error_Msg_N |
| 3104 |
("current instance must be a limited type", |
| 3105 |
Prefix (N)); |
| 3106 |
else |
| 3107 |
Error_Msg_N |
| 3108 |
("current instance must be an immutably limited " |
| 3109 |
& "type (RM-2012, 7.5 (8.1/3))", Prefix (N)); |
| 3110 |
end if; |
| 3111 |
|
| 3112 |
return Abandon; |
| 3113 |
|
| 3114 |
else |
| 3115 |
return OK; |
| 3116 |
end if; |
| 3117 |
|
| 3118 |
when others => |
| 3119 |
return OK; |
| 3120 |
end case; |
| 3121 |
end Process; |
| 3122 |
|
| 3123 |
procedure Traverse is new Traverse_Proc (Process); |
| 3124 |
|
| 3125 |
-- Local variables |
| 3126 |
|
| 3127 |
Rec_Type : constant Entity_Id := |
| 3128 |
Scope (Defining_Identifier (Comp_Decl)); |
| 3129 |
|
| 3130 |
-- Start of processing for Check_Current_Instance |
| 3131 |
|
| 3132 |
begin |
| 3133 |
if not Is_Aliased_View_Of_Type (Rec_Type) then |
| 3134 |
Traverse (Comp_Decl); |
| 3135 |
end if; |
| 3136 |
end Check_Current_Instance; |
| 3137 |
|
| 3138 |
------------------------------- |
| 3139 |
-- Check_No_Parts_Violations -- |
| 3140 |
------------------------------- |
| 3141 |
|
| 3142 |
procedure Check_No_Parts_Violations |
| 3143 |
(Typ : Entity_Id; Aspect_No_Parts : Aspect_Id) |
| 3144 |
is |
| 3145 |
|
| 3146 |
function Find_Aspect_No_Parts |
| 3147 |
(Typ : Entity_Id) return Node_Id; |
| 3148 |
-- Search for Aspect_No_Parts on a given type. When |
| 3149 |
-- the aspect is not explicity specified Empty is returned. |
| 3150 |
|
| 3151 |
function Get_Aspect_No_Parts_Value |
| 3152 |
(Typ : Entity_Id) return Entity_Id; |
| 3153 |
-- Obtain the value for the Aspect_No_Parts on a given |
| 3154 |
-- type. When the aspect is not explicitly specified Empty is |
| 3155 |
-- returned. |
| 3156 |
|
| 3157 |
function Has_Aspect_No_Parts |
| 3158 |
(Typ : Entity_Id) return Boolean; |
| 3159 |
-- Predicate function which identifies whether No_Parts |
| 3160 |
-- is explicitly specified on a given type. |
| 3161 |
|
| 3162 |
------------------------------------- |
| 3163 |
-- Find_Aspect_No_Parts -- |
| 3164 |
------------------------------------- |
| 3165 |
|
| 3166 |
function Find_Aspect_No_Parts |
| 3167 |
(Typ : Entity_Id) return Node_Id |
| 3168 |
is |
| 3169 |
Partial_View : constant Entity_Id := |
| 3170 |
Incomplete_Or_Partial_View (Typ); |
| 3171 |
|
| 3172 |
Aspect_Spec : Entity_Id := |
| 3173 |
Find_Aspect (Typ, Aspect_No_Parts); |
| 3174 |
Curr_Aspect_Spec : Entity_Id; |
| 3175 |
begin |
| 3176 |
-- Examine Typ's associated node, when present, since aspect |
| 3177 |
-- specifications do not get transferred when nodes get rewritten. |
| 3178 |
|
| 3179 |
-- For example, this can happen in the expansion of array types |
| 3180 |
|
| 3181 |
if No (Aspect_Spec) |
| 3182 |
and then Present (Associated_Node_For_Itype (Typ)) |
| 3183 |
and then Nkind (Associated_Node_For_Itype (Typ)) |
| 3184 |
= N_Full_Type_Declaration |
| 3185 |
then |
| 3186 |
Aspect_Spec := |
| 3187 |
Find_Aspect |
| 3188 |
(Id => Defining_Identifier |
| 3189 |
(Associated_Node_For_Itype (Typ)), |
| 3190 |
A => Aspect_No_Parts); |
| 3191 |
end if; |
| 3192 |
|
| 3193 |
-- Examine aspects specifications on private type declarations |
| 3194 |
|
| 3195 |
-- Should Find_Aspect be improved to handle this case ??? |
| 3196 |
|
| 3197 |
if No (Aspect_Spec) |
| 3198 |
and then Present (Partial_View) |
| 3199 |
and then Present |
| 3200 |
(Aspect_Specifications |
| 3201 |
(Declaration_Node |
| 3202 |
(Partial_View))) |
| 3203 |
then |
| 3204 |
Curr_Aspect_Spec := |
| 3205 |
First |
| 3206 |
(Aspect_Specifications |
| 3207 |
(Declaration_Node |
| 3208 |
(Partial_View))); |
| 3209 |
|
| 3210 |
-- Search through aspects present on the private type |
| 3211 |
|
| 3212 |
while Present (Curr_Aspect_Spec) loop |
| 3213 |
if Get_Aspect_Id (Curr_Aspect_Spec) = Aspect_No_Parts then |
| 3214 |
Aspect_Spec := Curr_Aspect_Spec; |
| 3215 |
exit; |
| 3216 |
end if; |
| 3217 |
|
| 3218 |
Next (Curr_Aspect_Spec); |
| 3219 |
end loop; |
| 3220 |
|
| 3221 |
end if; |
| 3222 |
|
| 3223 |
-- When errors are posted on the aspect return Empty |
| 3224 |
|
| 3225 |
if Error_Posted (Aspect_Spec) then |
| 3226 |
return Empty; |
| 3227 |
end if; |
| 3228 |
|
| 3229 |
return Aspect_Spec; |
| 3230 |
end Find_Aspect_No_Parts; |
| 3231 |
|
| 3232 |
------------------------------------------ |
| 3233 |
-- Get_Aspect_No_Parts_Value -- |
| 3234 |
------------------------------------------ |
| 3235 |
|
| 3236 |
function Get_Aspect_No_Parts_Value |
| 3237 |
(Typ : Entity_Id) return Entity_Id |
| 3238 |
is |
| 3239 |
Aspect_Spec : constant Entity_Id := |
| 3240 |
Find_Aspect_No_Parts (Typ); |
| 3241 |
begin |
| 3242 |
-- Return the value of the aspect when present |
| 3243 |
|
| 3244 |
if Present (Aspect_Spec) then |
| 3245 |
|
| 3246 |
-- No expression is the same as True |
| 3247 |
|
| 3248 |
if No (Expression (Aspect_Spec)) then |
| 3249 |
return Standard_True; |
| 3250 |
end if; |
| 3251 |
|
| 3252 |
-- Assume its expression has already been constant folded into |
| 3253 |
-- a Boolean value and return its value. |
| 3254 |
|
| 3255 |
return Entity (Expression (Aspect_Spec)); |
| 3256 |
end if; |
| 3257 |
|
| 3258 |
-- Otherwise, the aspect is not specified - so return Empty |
| 3259 |
|
| 3260 |
return Empty; |
| 3261 |
end Get_Aspect_No_Parts_Value; |
| 3262 |
|
| 3263 |
------------------------------------ |
| 3264 |
-- Has_Aspect_No_Parts -- |
| 3265 |
------------------------------------ |
| 3266 |
|
| 3267 |
function Has_Aspect_No_Parts |
| 3268 |
(Typ : Entity_Id) return Boolean |
| 3269 |
is (Present (Find_Aspect_No_Parts (Typ))); |
| 3270 |
|
| 3271 |
-- Generic instances |
| 3272 |
|
| 3273 |
------------------------------------------- |
| 3274 |
-- Get_Generic_Formal_Types_In_Hierarchy -- |
| 3275 |
------------------------------------------- |
| 3276 |
|
| 3277 |
function Get_Generic_Formal_Types_In_Hierarchy |
| 3278 |
is new Collect_Types_In_Hierarchy (Predicate => Is_Generic_Formal); |
| 3279 |
-- Return a list of all types within a given type's hierarchy which |
| 3280 |
-- are generic formals. |
| 3281 |
|
| 3282 |
---------------------------------------- |
| 3283 |
-- Get_Types_With_Aspect_In_Hierarchy -- |
| 3284 |
---------------------------------------- |
| 3285 |
|
| 3286 |
function Get_Types_With_Aspect_In_Hierarchy |
| 3287 |
is new Collect_Types_In_Hierarchy |
| 3288 |
(Predicate => Has_Aspect_No_Parts); |
| 3289 |
-- Returns a list of all types within a given type's hierarchy which |
| 3290 |
-- have the Aspect_No_Parts specified. |
| 3291 |
|
| 3292 |
-- Local declarations |
| 3293 |
|
| 3294 |
Aspect_Value : Entity_Id; |
| 3295 |
Curr_Value : Entity_Id; |
| 3296 |
Curr_Typ_Elmt : Elmt_Id; |
| 3297 |
Curr_Body_Elmt : Elmt_Id; |
| 3298 |
Curr_Formal_Elmt : Elmt_Id; |
| 3299 |
Gen_Bodies : Elist_Id; |
| 3300 |
Gen_Formals : Elist_Id; |
| 3301 |
Scop : Entity_Id; |
| 3302 |
Types_With_Aspect : Elist_Id; |
| 3303 |
|
| 3304 |
-- Start of processing for Check_No_Parts_Violations |
| 3305 |
|
| 3306 |
begin |
| 3307 |
-- Nothing to check if the type is elementary or artificial |
| 3308 |
|
| 3309 |
if Is_Elementary_Type (Typ) or else not Comes_From_Source (Typ) then |
| 3310 |
return; |
| 3311 |
end if; |
| 3312 |
|
| 3313 |
Types_With_Aspect := Get_Types_With_Aspect_In_Hierarchy (Typ); |
| 3314 |
|
| 3315 |
-- Nothing to check if there are no types with No_Parts specified |
| 3316 |
|
| 3317 |
if Is_Empty_Elmt_List (Types_With_Aspect) then |
| 3318 |
return; |
| 3319 |
end if; |
| 3320 |
|
| 3321 |
-- Set name for all errors below |
| 3322 |
|
| 3323 |
Error_Msg_Name_1 := Aspect_Names (Aspect_No_Parts); |
| 3324 |
|
| 3325 |
-- Obtain the aspect value for No_Parts for comparison |
| 3326 |
|
| 3327 |
Aspect_Value := |
| 3328 |
Get_Aspect_No_Parts_Value |
| 3329 |
(Node (First_Elmt (Types_With_Aspect))); |
| 3330 |
|
| 3331 |
-- When the value is True and there are controlled/task parts or the |
| 3332 |
-- type itself is controlled/task, trigger the appropriate error. |
| 3333 |
|
| 3334 |
if Aspect_Value = Standard_True then |
| 3335 |
if Aspect_No_Parts = Aspect_No_Controlled_Parts then |
| 3336 |
if Is_Controlled (Typ) or else Has_Controlled_Component (Typ) |
| 3337 |
then |
| 3338 |
Error_Msg_N |
| 3339 |
("aspect % applied to controlled type &", Typ); |
| 3340 |
end if; |
| 3341 |
|
| 3342 |
elsif Aspect_No_Parts = Aspect_No_Task_Parts then |
| 3343 |
if Has_Task (Typ) then |
| 3344 |
Error_Msg_N |
| 3345 |
("aspect % applied to task type &", Typ); |
| 3346 |
Error_Msg_N |
| 3347 |
("\replace task components with access-to-task-type " |
| 3348 |
& "components", Typ); |
| 3349 |
end if; |
| 3350 |
|
| 3351 |
else |
| 3352 |
raise Program_Error; |
| 3353 |
end if; |
| 3354 |
end if; |
| 3355 |
|
| 3356 |
-- Move through Types_With_Aspect - checking that the value specified |
| 3357 |
-- for their corresponding Aspect_No_Parts do not override each |
| 3358 |
-- other. |
| 3359 |
|
| 3360 |
Curr_Typ_Elmt := First_Elmt (Types_With_Aspect); |
| 3361 |
while Present (Curr_Typ_Elmt) loop |
| 3362 |
Curr_Value := |
| 3363 |
Get_Aspect_No_Parts_Value (Node (Curr_Typ_Elmt)); |
| 3364 |
|
| 3365 |
-- Compare the aspect value against the current type |
| 3366 |
|
| 3367 |
if Curr_Value /= Aspect_Value then |
| 3368 |
Error_Msg_NE |
| 3369 |
("cannot override aspect % of " |
| 3370 |
& "ancestor type &", Typ, Node (Curr_Typ_Elmt)); |
| 3371 |
return; |
| 3372 |
end if; |
| 3373 |
|
| 3374 |
Next_Elmt (Curr_Typ_Elmt); |
| 3375 |
end loop; |
| 3376 |
|
| 3377 |
-- Issue an error if the aspect applies to a type declared inside a |
| 3378 |
-- generic body and if said type derives from or has a component |
| 3379 |
-- of ageneric formal type - since those are considered to have |
| 3380 |
-- controlled/task parts and have Aspect_No_Parts specified as |
| 3381 |
-- False by default (RM H.4.1(4/5) is about the language-defined |
| 3382 |
-- No_Controlled_Parts aspect, and we are using the same rules for |
| 3383 |
-- No_Task_Parts). |
| 3384 |
|
| 3385 |
-- We do not check tagged types since deriving from a formal type |
| 3386 |
-- within an enclosing generic unit is already illegal |
| 3387 |
-- (RM 3.9.1 (4/2)). |
| 3388 |
|
| 3389 |
if Aspect_Value = Standard_True |
| 3390 |
and then In_Generic_Body (Typ) |
| 3391 |
and then not Is_Tagged_Type (Typ) |
| 3392 |
then |
| 3393 |
Gen_Bodies := New_Elmt_List; |
| 3394 |
Gen_Formals := |
| 3395 |
Get_Generic_Formal_Types_In_Hierarchy |
| 3396 |
(Typ => Typ, |
| 3397 |
Examine_Components => True); |
| 3398 |
|
| 3399 |
-- Climb scopes collecting generic bodies |
| 3400 |
|
| 3401 |
Scop := Scope (Typ); |
| 3402 |
while Present (Scop) and then Scop /= Standard_Standard loop |
| 3403 |
|
| 3404 |
-- Generic package body |
| 3405 |
|
| 3406 |
if Ekind (Scop) = E_Generic_Package |
| 3407 |
and then In_Package_Body (Scop) |
| 3408 |
then |
| 3409 |
Append_Elmt (Scop, Gen_Bodies); |
| 3410 |
|
| 3411 |
-- Generic subprogram body |
| 3412 |
|
| 3413 |
elsif Is_Generic_Subprogram (Scop) then |
| 3414 |
Append_Elmt (Scop, Gen_Bodies); |
| 3415 |
end if; |
| 3416 |
|
| 3417 |
Scop := Scope (Scop); |
| 3418 |
end loop; |
| 3419 |
|
| 3420 |
-- Warn about the improper use of Aspect_No_Parts on a type |
| 3421 |
-- declaration deriving from or that has a component of a generic |
| 3422 |
-- formal type within the formal type's corresponding generic |
| 3423 |
-- body by moving through all formal types in Typ's hierarchy and |
| 3424 |
-- checking if they are formals in any of the enclosing generic |
| 3425 |
-- bodies. |
| 3426 |
|
| 3427 |
-- However, a special exception gets made for formal types which |
| 3428 |
-- derive from a type which has Aspect_No_Parts True. |
| 3429 |
|
| 3430 |
-- For example: |
| 3431 |
|
| 3432 |
-- generic |
| 3433 |
-- type Form is private; |
| 3434 |
-- package G is |
| 3435 |
-- type Type_A is new Form with No_Controlled_Parts; -- OK |
| 3436 |
-- end; |
| 3437 |
-- |
| 3438 |
-- package body G is |
| 3439 |
-- type Type_B is new Form with No_Controlled_Parts; -- ERROR |
| 3440 |
-- end; |
| 3441 |
|
| 3442 |
-- generic |
| 3443 |
-- type Form is private; |
| 3444 |
-- package G is |
| 3445 |
-- type Type_A is record C : Form; end record |
| 3446 |
-- with No_Controlled_Parts; -- OK |
| 3447 |
-- end; |
| 3448 |
-- |
| 3449 |
-- package body G is |
| 3450 |
-- type Type_B is record C : Form; end record |
| 3451 |
-- with No_Controlled_Parts; -- ERROR |
| 3452 |
-- end; |
| 3453 |
|
| 3454 |
-- type Root is tagged null record with No_Controlled_Parts; |
| 3455 |
-- |
| 3456 |
-- generic |
| 3457 |
-- type Form is new Root with private; |
| 3458 |
-- package G is |
| 3459 |
-- type Type_A is record C : Form; end record |
| 3460 |
-- with No_Controlled_Parts; -- OK |
| 3461 |
-- end; |
| 3462 |
-- |
| 3463 |
-- package body G is |
| 3464 |
-- type Type_B is record C : Form; end record |
| 3465 |
-- with No_Controlled_Parts; -- OK |
| 3466 |
-- end; |
| 3467 |
|
| 3468 |
Curr_Formal_Elmt := First_Elmt (Gen_Formals); |
| 3469 |
while Present (Curr_Formal_Elmt) loop |
| 3470 |
|
| 3471 |
Curr_Body_Elmt := First_Elmt (Gen_Bodies); |
| 3472 |
while Present (Curr_Body_Elmt) loop |
| 3473 |
|
| 3474 |
-- Obtain types in the formal type's hierarchy which have |
| 3475 |
-- the aspect specified. |
| 3476 |
|
| 3477 |
Types_With_Aspect := |
| 3478 |
Get_Types_With_Aspect_In_Hierarchy |
| 3479 |
(Node (Curr_Formal_Elmt)); |
| 3480 |
|
| 3481 |
-- We found a type declaration in a generic body where both |
| 3482 |
-- Aspect_No_Parts is true and one of its ancestors is a |
| 3483 |
-- generic formal type. |
| 3484 |
|
| 3485 |
if Scope (Node (Curr_Formal_Elmt)) = |
| 3486 |
Node (Curr_Body_Elmt) |
| 3487 |
|
| 3488 |
-- Check that no ancestors of the formal type have |
| 3489 |
-- Aspect_No_Parts True before issuing the error. |
| 3490 |
|
| 3491 |
and then (Is_Empty_Elmt_List (Types_With_Aspect) |
| 3492 |
or else |
| 3493 |
Get_Aspect_No_Parts_Value |
| 3494 |
(Node (First_Elmt (Types_With_Aspect))) |
| 3495 |
= Standard_False) |
| 3496 |
then |
| 3497 |
Error_Msg_Node_1 := Typ; |
| 3498 |
Error_Msg_Node_2 := Node (Curr_Formal_Elmt); |
| 3499 |
Error_Msg |
| 3500 |
("aspect % cannot be applied to " |
| 3501 |
& "type & which has an ancestor or component of " |
| 3502 |
& "formal type & within the formal type's " |
| 3503 |
& "corresponding generic body", Sloc (Typ)); |
| 3504 |
end if; |
| 3505 |
|
| 3506 |
Next_Elmt (Curr_Body_Elmt); |
| 3507 |
end loop; |
| 3508 |
|
| 3509 |
Next_Elmt (Curr_Formal_Elmt); |
| 3510 |
end loop; |
| 3511 |
end if; |
| 3512 |
end Check_No_Parts_Violations; |
| 3513 |
|
| 3514 |
--------------------------------- |
| 3515 |
-- Check_Suspicious_Convention -- |
| 3516 |
--------------------------------- |
| 3517 |
|
| 3518 |
procedure Check_Suspicious_Convention (Rec_Type : Entity_Id) is |
| 3519 |
begin |
| 3520 |
if Has_Discriminants (Rec_Type) |
| 3521 |
and then Is_Base_Type (Rec_Type) |
| 3522 |
and then not Is_Unchecked_Union (Rec_Type) |
| 3523 |
and then (Convention (Rec_Type) = Convention_C |
| 3524 |
or else |
| 3525 |
Convention (Rec_Type) = Convention_CPP) |
| 3526 |
and then Comes_From_Source (Rec_Type) |
| 3527 |
and then not In_Instance |
| 3528 |
and then not Has_Warnings_Off (Rec_Type) |
| 3529 |
then |
| 3530 |
declare |
| 3531 |
Cprag : constant Node_Id := |
| 3532 |
Get_Rep_Pragma (Rec_Type, Name_Convention); |
| 3533 |
A2 : Node_Id; |
| 3534 |
|
| 3535 |
begin |
| 3536 |
if Present (Cprag) then |
| 3537 |
A2 := Next (First (Pragma_Argument_Associations (Cprag))); |
| 3538 |
|
| 3539 |
if Convention (Rec_Type) = Convention_C then |
| 3540 |
Error_Msg_N |
| 3541 |
("?x?discriminated record has no direct equivalent in " |
| 3542 |
& "C", A2); |
| 3543 |
else |
| 3544 |
Error_Msg_N |
| 3545 |
("?x?discriminated record has no direct equivalent in " |
| 3546 |
& "C++", A2); |
| 3547 |
end if; |
| 3548 |
|
| 3549 |
Error_Msg_NE |
| 3550 |
("\?x?use of convention for type& is dubious", |
| 3551 |
A2, Rec_Type); |
| 3552 |
end if; |
| 3553 |
end; |
| 3554 |
end if; |
| 3555 |
end Check_Suspicious_Convention; |
| 3556 |
|
| 3557 |
------------------------------ |
| 3558 |
-- Check_Suspicious_Modulus -- |
| 3559 |
------------------------------ |
| 3560 |
|
| 3561 |
procedure Check_Suspicious_Modulus (Utype : Entity_Id) is |
| 3562 |
Decl : constant Node_Id := Declaration_Node (Underlying_Type (Utype)); |
| 3563 |
|
| 3564 |
begin |
| 3565 |
if not Warn_On_Suspicious_Modulus_Value then |
| 3566 |
return; |
| 3567 |
end if; |
| 3568 |
|
| 3569 |
if Nkind (Decl) = N_Full_Type_Declaration then |
| 3570 |
declare |
| 3571 |
Tdef : constant Node_Id := Type_Definition (Decl); |
| 3572 |
|
| 3573 |
begin |
| 3574 |
if Nkind (Tdef) = N_Modular_Type_Definition then |
| 3575 |
declare |
| 3576 |
Modulus : constant Node_Id := |
| 3577 |
Original_Node (Expression (Tdef)); |
| 3578 |
|
| 3579 |
begin |
| 3580 |
if Nkind (Modulus) = N_Integer_Literal then |
| 3581 |
declare |
| 3582 |
Modv : constant Uint := Intval (Modulus); |
| 3583 |
Sizv : constant Uint := RM_Size (Utype); |
| 3584 |
|
| 3585 |
begin |
| 3586 |
-- First case, modulus and size are the same. This |
| 3587 |
-- happens if you have something like mod 32, with |
| 3588 |
-- an explicit size of 32, this is for sure a case |
| 3589 |
-- where the warning is given, since it is seems |
| 3590 |
-- very unlikely that someone would want e.g. a |
| 3591 |
-- five bit type stored in 32 bits. It is much |
| 3592 |
-- more likely they wanted a 32-bit type. |
| 3593 |
|
| 3594 |
if Modv = Sizv then |
| 3595 |
null; |
| 3596 |
|
| 3597 |
-- Second case, the modulus is 32 or 64 and no |
| 3598 |
-- size clause is present. This is a less clear |
| 3599 |
-- case for giving the warning, but in the case |
| 3600 |
-- of 32/64 (5-bit or 6-bit types) these seem rare |
| 3601 |
-- enough that it is a likely error (and in any |
| 3602 |
-- case using 2**5 or 2**6 in these cases seems |
| 3603 |
-- clearer. We don't include 8 or 16 here, simply |
| 3604 |
-- because in practice 3-bit and 4-bit types are |
| 3605 |
-- more common and too many false positives if |
| 3606 |
-- we warn in these cases. |
| 3607 |
|
| 3608 |
elsif not Has_Size_Clause (Utype) |
| 3609 |
and then (Modv = Uint_32 or else Modv = Uint_64) |
| 3610 |
then |
| 3611 |
null; |
| 3612 |
|
| 3613 |
-- No warning needed |
| 3614 |
|
| 3615 |
else |
| 3616 |
return; |
| 3617 |
end if; |
| 3618 |
|
| 3619 |
-- If we fall through, give warning |
| 3620 |
|
| 3621 |
Error_Msg_Uint_1 := Modv; |
| 3622 |
Error_Msg_N |
| 3623 |
("?.m?2 '*'*^' may have been intended here", |
| 3624 |
Modulus); |
| 3625 |
end; |
| 3626 |
end if; |
| 3627 |
end; |
| 3628 |
end if; |
| 3629 |
end; |
| 3630 |
end if; |
| 3631 |
end Check_Suspicious_Modulus; |
| 3632 |
|
| 3633 |
----------------------- |
| 3634 |
-- Freeze_Array_Type -- |
| 3635 |
----------------------- |
| 3636 |
|
| 3637 |
procedure Freeze_Array_Type (Arr : Entity_Id) is |
| 3638 |
FS : constant Entity_Id := First_Subtype (Arr); |
| 3639 |
Ctyp : constant Entity_Id := Component_Type (Arr); |
| 3640 |
|
| 3641 |
Clause : Node_Id; |
| 3642 |
-- Set to Component_Size clause or Atomic pragma, if any |
| 3643 |
|
| 3644 |
Non_Standard_Enum : Boolean := False; |
| 3645 |
-- Set true if any of the index types is an enumeration type with a |
| 3646 |
-- non-standard representation. |
| 3647 |
|
| 3648 |
begin |
| 3649 |
Freeze_And_Append (Ctyp, N, Result); |
| 3650 |
|
| 3651 |
Indx := First_Index (Arr); |
| 3652 |
while Present (Indx) loop |
| 3653 |
Freeze_And_Append (Etype (Indx), N, Result); |
| 3654 |
|
| 3655 |
if Is_Enumeration_Type (Etype (Indx)) |
| 3656 |
and then Has_Non_Standard_Rep (Etype (Indx)) |
| 3657 |
then |
| 3658 |
Non_Standard_Enum := True; |
| 3659 |
end if; |
| 3660 |
|
| 3661 |
Next_Index (Indx); |
| 3662 |
end loop; |
| 3663 |
|
| 3664 |
-- Processing that is done only for base types |
| 3665 |
|
| 3666 |
if Ekind (Arr) = E_Array_Type then |
| 3667 |
|
| 3668 |
-- Deal with default setting of reverse storage order |
| 3669 |
|
| 3670 |
Set_SSO_From_Default (Arr); |
| 3671 |
|
| 3672 |
-- Propagate flags from component type |
| 3673 |
|
| 3674 |
Propagate_Concurrent_Flags (Arr, Ctyp); |
| 3675 |
Propagate_Controlled_Flags (Arr, Ctyp, Comp => True); |
| 3676 |
|
| 3677 |
if Has_Unchecked_Union (Ctyp) then |
| 3678 |
Set_Has_Unchecked_Union (Arr); |
| 3679 |
end if; |
| 3680 |
|
| 3681 |
-- The array type requires its own invariant procedure in order to |
| 3682 |
-- verify the component invariant over all elements. In GNATprove |
| 3683 |
-- mode, the component invariants are checked by other means. They |
| 3684 |
-- should not be added to the array type invariant procedure, so |
| 3685 |
-- that the procedure can be used to check the array type |
| 3686 |
-- invariants if any. |
| 3687 |
|
| 3688 |
if Has_Invariants (Ctyp) |
| 3689 |
and then not GNATprove_Mode |
| 3690 |
then |
| 3691 |
Set_Has_Own_Invariants (Arr); |
| 3692 |
end if; |
| 3693 |
|
| 3694 |
-- Warn for pragma Pack overriding foreign convention |
| 3695 |
|
| 3696 |
if Has_Foreign_Convention (Ctyp) |
| 3697 |
and then Has_Pragma_Pack (Arr) |
| 3698 |
then |
| 3699 |
declare |
| 3700 |
CN : constant Name_Id := |
| 3701 |
Get_Convention_Name (Convention (Ctyp)); |
| 3702 |
PP : constant Node_Id := |
| 3703 |
Get_Pragma (First_Subtype (Arr), Pragma_Pack); |
| 3704 |
begin |
| 3705 |
if Present (PP) then |
| 3706 |
Error_Msg_Name_1 := CN; |
| 3707 |
Error_Msg_Sloc := Sloc (Arr); |
| 3708 |
Error_Msg_N |
| 3709 |
("pragma Pack affects convention % components #??", PP); |
| 3710 |
Error_Msg_Name_1 := CN; |
| 3711 |
Error_Msg_N |
| 3712 |
("\array components may not have % compatible " |
| 3713 |
& "representation??", PP); |
| 3714 |
end if; |
| 3715 |
end; |
| 3716 |
end if; |
| 3717 |
|
| 3718 |
-- Check for Aliased or Atomic or Full Access or Independent |
| 3719 |
-- components with an unsuitable component size clause given. |
| 3720 |
-- The main purpose is to give an error when bit packing would |
| 3721 |
-- be required to honor the component size, because bit packing |
| 3722 |
-- is incompatible with these aspects; when bit packing is not |
| 3723 |
-- required, the final validation of the component size may be |
| 3724 |
-- left to the back end. |
| 3725 |
|
| 3726 |
if Has_Component_Size_Clause (Arr) then |
| 3727 |
CS_Check : declare |
| 3728 |
procedure Complain_CS (T : String; Min : Boolean := False); |
| 3729 |
-- Output an error message for an unsuitable component size |
| 3730 |
-- clause for independent components (T is either "aliased" |
| 3731 |
-- or "atomic" or "volatile full access" or "independent"). |
| 3732 |
|
| 3733 |
----------------- |
| 3734 |
-- Complain_CS -- |
| 3735 |
----------------- |
| 3736 |
|
| 3737 |
procedure Complain_CS (T : String; Min : Boolean := False) is |
| 3738 |
begin |
| 3739 |
Clause := |
| 3740 |
Get_Attribute_Definition_Clause |
| 3741 |
(FS, Attribute_Component_Size); |
| 3742 |
|
| 3743 |
Error_Msg_N |
| 3744 |
("incorrect component size for " & T & " components", |
| 3745 |
Clause); |
| 3746 |
|
| 3747 |
if Known_Static_Esize (Ctyp) then |
| 3748 |
Error_Msg_Uint_1 := Esize (Ctyp); |
| 3749 |
if Min then |
| 3750 |
Error_Msg_N ("\minimum allowed value is^", Clause); |
| 3751 |
else |
| 3752 |
Error_Msg_N ("\only allowed value is^", Clause); |
| 3753 |
end if; |
| 3754 |
else |
| 3755 |
Error_Msg_N |
| 3756 |
("\must be multiple of storage unit", Clause); |
| 3757 |
end if; |
| 3758 |
end Complain_CS; |
| 3759 |
|
| 3760 |
-- Start of processing for CS_Check |
| 3761 |
|
| 3762 |
begin |
| 3763 |
-- OK if the component size and object size are equal, or |
| 3764 |
-- if the component size is a multiple of the storage unit. |
| 3765 |
|
| 3766 |
if (if Known_Static_Esize (Ctyp) |
| 3767 |
then Component_Size (Arr) = Esize (Ctyp) |
| 3768 |
else Component_Size (Arr) mod System_Storage_Unit = 0) |
| 3769 |
then |
| 3770 |
null; |
| 3771 |
|
| 3772 |
elsif Has_Aliased_Components (Arr) then |
| 3773 |
Complain_CS ("aliased"); |
| 3774 |
|
| 3775 |
elsif Has_Atomic_Components (Arr) |
| 3776 |
or else Is_Atomic (Ctyp) |
| 3777 |
then |
| 3778 |
Complain_CS ("atomic"); |
| 3779 |
|
| 3780 |
elsif Is_Volatile_Full_Access (Ctyp) then |
| 3781 |
Complain_CS ("volatile full access"); |
| 3782 |
|
| 3783 |
-- For Independent a larger size is permitted |
| 3784 |
|
| 3785 |
elsif (Has_Independent_Components (Arr) |
| 3786 |
or else Is_Independent (Ctyp)) |
| 3787 |
and then (not Known_Static_Esize (Ctyp) |
| 3788 |
or else Component_Size (Arr) < Esize (Ctyp)) |
| 3789 |
then |
| 3790 |
Complain_CS ("independent", Min => True); |
| 3791 |
end if; |
| 3792 |
end CS_Check; |
| 3793 |
|
| 3794 |
-- Check for Aliased or Atomic or Full Access or Independent |
| 3795 |
-- components with an unsuitable aspect/pragma Pack given. |
| 3796 |
-- The main purpose is to prevent bit packing from occurring, |
| 3797 |
-- because bit packing is incompatible with these aspects; when |
| 3798 |
-- bit packing cannot occur, the final handling of the packing |
| 3799 |
-- may be left to the back end. |
| 3800 |
|
| 3801 |
elsif Is_Packed (Arr) and then Known_Static_RM_Size (Ctyp) then |
| 3802 |
Pack_Check : declare |
| 3803 |
|
| 3804 |
procedure Complain_Pack (T : String); |
| 3805 |
-- Output a warning message for an unsuitable aspect/pragma |
| 3806 |
-- Pack for independent components (T is either "aliased" or |
| 3807 |
-- "atomic" or "volatile full access" or "independent") and |
| 3808 |
-- reset the Is_Packed flag on the array type. |
| 3809 |
|
| 3810 |
------------------- |
| 3811 |
-- Complain_Pack -- |
| 3812 |
------------------- |
| 3813 |
|
| 3814 |
procedure Complain_Pack (T : String) is |
| 3815 |
begin |
| 3816 |
Error_Msg_N |
| 3817 |
("?cannot pack " & T & " components (RM 13.2(7))", |
| 3818 |
Get_Rep_Pragma (FS, Name_Pack)); |
| 3819 |
|
| 3820 |
Set_Is_Packed (Arr, False); |
| 3821 |
end Complain_Pack; |
| 3822 |
|
| 3823 |
-- Start of processing for Pack_Check |
| 3824 |
|
| 3825 |
begin |
| 3826 |
-- OK if the component size and object size are equal, or |
| 3827 |
-- if the component size is a multiple of the storage unit. |
| 3828 |
|
| 3829 |
if (if Known_Static_Esize (Ctyp) |
| 3830 |
then RM_Size (Ctyp) = Esize (Ctyp) |
| 3831 |
else RM_Size (Ctyp) mod System_Storage_Unit = 0) |
| 3832 |
then |
| 3833 |
null; |
| 3834 |
|
| 3835 |
elsif Has_Aliased_Components (Arr) then |
| 3836 |
Complain_Pack ("aliased"); |
| 3837 |
|
| 3838 |
elsif Has_Atomic_Components (Arr) |
| 3839 |
or else Is_Atomic (Ctyp) |
| 3840 |
then |
| 3841 |
Complain_Pack ("atomic"); |
| 3842 |
|
| 3843 |
elsif Is_Volatile_Full_Access (Ctyp) then |
| 3844 |
Complain_Pack ("volatile full access"); |
| 3845 |
|
| 3846 |
elsif Has_Independent_Components (Arr) |
| 3847 |
or else Is_Independent (Ctyp) |
| 3848 |
then |
| 3849 |
Complain_Pack ("independent"); |
| 3850 |
end if; |
| 3851 |
end Pack_Check; |
| 3852 |
end if; |
| 3853 |
|
| 3854 |
-- If packing was requested or if the component size was |
| 3855 |
-- set explicitly, then see if bit packing is required. This |
| 3856 |
-- processing is only done for base types, since all of the |
| 3857 |
-- representation aspects involved are type-related. |
| 3858 |
|
| 3859 |
-- This is not just an optimization, if we start processing the |
| 3860 |
-- subtypes, they interfere with the settings on the base type |
| 3861 |
-- (this is because Is_Packed has a slightly different meaning |
| 3862 |
-- before and after freezing). |
| 3863 |
|
| 3864 |
declare |
| 3865 |
Csiz : Uint; |
| 3866 |
Esiz : Uint; |
| 3867 |
|
| 3868 |
begin |
| 3869 |
if Is_Packed (Arr) |
| 3870 |
and then Known_Static_RM_Size (Ctyp) |
| 3871 |
and then not Has_Component_Size_Clause (Arr) |
| 3872 |
then |
| 3873 |
Csiz := UI_Max (RM_Size (Ctyp), 1); |
| 3874 |
|
| 3875 |
elsif Known_Component_Size (Arr) then |
| 3876 |
Csiz := Component_Size (Arr); |
| 3877 |
|
| 3878 |
elsif not Known_Static_Esize (Ctyp) then |
| 3879 |
Csiz := Uint_0; |
| 3880 |
|
| 3881 |
else |
| 3882 |
Esiz := Esize (Ctyp); |
| 3883 |
|
| 3884 |
-- We can set the component size if it is less than 16, |
| 3885 |
-- rounding it up to the next storage unit size. |
| 3886 |
|
| 3887 |
if Esiz <= 8 then |
| 3888 |
Csiz := Uint_8; |
| 3889 |
elsif Esiz <= 16 then |
| 3890 |
Csiz := Uint_16; |
| 3891 |
else |
| 3892 |
Csiz := Uint_0; |
| 3893 |
end if; |
| 3894 |
|
| 3895 |
-- Set component size up to match alignment if it would |
| 3896 |
-- otherwise be less than the alignment. This deals with |
| 3897 |
-- cases of types whose alignment exceeds their size (the |
| 3898 |
-- padded type cases). |
| 3899 |
|
| 3900 |
if Csiz /= 0 and then Known_Alignment (Ctyp) then |
| 3901 |
declare |
| 3902 |
A : constant Uint := Alignment_In_Bits (Ctyp); |
| 3903 |
begin |
| 3904 |
if Csiz < A then |
| 3905 |
Csiz := A; |
| 3906 |
end if; |
| 3907 |
end; |
| 3908 |
end if; |
| 3909 |
end if; |
| 3910 |
|
| 3911 |
-- Case of component size that may result in bit packing |
| 3912 |
|
| 3913 |
if 1 <= Csiz and then Csiz <= System_Max_Integer_Size then |
| 3914 |
declare |
| 3915 |
Ent : constant Entity_Id := |
| 3916 |
First_Subtype (Arr); |
| 3917 |
Pack_Pragma : constant Node_Id := |
| 3918 |
Get_Rep_Pragma (Ent, Name_Pack); |
| 3919 |
Comp_Size_C : constant Node_Id := |
| 3920 |
Get_Attribute_Definition_Clause |
| 3921 |
(Ent, Attribute_Component_Size); |
| 3922 |
|
| 3923 |
begin |
| 3924 |
-- Warn if we have pack and component size so that the |
| 3925 |
-- pack is ignored. |
| 3926 |
|
| 3927 |
-- Note: here we must check for the presence of a |
| 3928 |
-- component size before checking for a Pack pragma to |
| 3929 |
-- deal with the case where the array type is a derived |
| 3930 |
-- type whose parent is currently private. |
| 3931 |
|
| 3932 |
if Present (Comp_Size_C) |
| 3933 |
and then Has_Pragma_Pack (Ent) |
| 3934 |
and then Warn_On_Redundant_Constructs |
| 3935 |
then |
| 3936 |
Error_Msg_Sloc := Sloc (Comp_Size_C); |
| 3937 |
Error_Msg_NE |
| 3938 |
("?r?pragma Pack for& ignored!", Pack_Pragma, Ent); |
| 3939 |
Error_Msg_N |
| 3940 |
("\?r?explicit component size given#!", Pack_Pragma); |
| 3941 |
Set_Is_Packed (Base_Type (Ent), False); |
| 3942 |
Set_Is_Bit_Packed_Array (Base_Type (Ent), False); |
| 3943 |
end if; |
| 3944 |
|
| 3945 |
-- Set component size if not already set by a component |
| 3946 |
-- size clause. |
| 3947 |
|
| 3948 |
if No (Comp_Size_C) then |
| 3949 |
Set_Component_Size (Arr, Csiz); |
| 3950 |
end if; |
| 3951 |
|
| 3952 |
-- Check for base type of 8, 16, 32 bits, where an |
| 3953 |
-- unsigned subtype has a length one less than the |
| 3954 |
-- base type (e.g. Natural subtype of Integer). |
| 3955 |
|
| 3956 |
-- In such cases, if a component size was not set |
| 3957 |
-- explicitly, then generate a warning. |
| 3958 |
|
| 3959 |
if Has_Pragma_Pack (Arr) |
| 3960 |
and then No (Comp_Size_C) |
| 3961 |
and then (Csiz = 7 or else Csiz = 15 or else Csiz = 31) |
| 3962 |
and then Known_Esize (Base_Type (Ctyp)) |
| 3963 |
and then Esize (Base_Type (Ctyp)) = Csiz + 1 |
| 3964 |
then |
| 3965 |
Error_Msg_Uint_1 := Csiz; |
| 3966 |
|
| 3967 |
if Present (Pack_Pragma) then |
| 3968 |
Error_Msg_N |
| 3969 |
("??pragma Pack causes component size to be ^!", |
| 3970 |
Pack_Pragma); |
| 3971 |
Error_Msg_N |
| 3972 |
("\??use Component_Size to set desired value!", |
| 3973 |
Pack_Pragma); |
| 3974 |
end if; |
| 3975 |
end if; |
| 3976 |
|
| 3977 |
-- Bit packing is never needed for 8, 16, 32, 64 or 128 |
| 3978 |
|
| 3979 |
if Addressable (Csiz) then |
| 3980 |
|
| 3981 |
-- If the Esize of the component is known and equal to |
| 3982 |
-- the component size then even packing is not needed. |
| 3983 |
|
| 3984 |
if Known_Static_Esize (Ctyp) |
| 3985 |
and then Esize (Ctyp) = Csiz |
| 3986 |
then |
| 3987 |
-- Here the array was requested to be packed, but |
| 3988 |
-- the packing request had no effect whatsoever, |
| 3989 |
-- so flag Is_Packed is reset. |
| 3990 |
|
| 3991 |
-- Note: semantically this means that we lose track |
| 3992 |
-- of the fact that a derived type inherited pragma |
| 3993 |
-- Pack that was non-effective, but that is fine. |
| 3994 |
|
| 3995 |
-- We regard a Pack pragma as a request to set a |
| 3996 |
-- representation characteristic, and this request |
| 3997 |
-- may be ignored. |
| 3998 |
|
| 3999 |
Set_Is_Packed (Base_Type (Arr), False); |
| 4000 |
Set_Has_Non_Standard_Rep (Base_Type (Arr), False); |
| 4001 |
else |
| 4002 |
Set_Is_Packed (Base_Type (Arr), True); |
| 4003 |
Set_Has_Non_Standard_Rep (Base_Type (Arr), True); |
| 4004 |
end if; |
| 4005 |
|
| 4006 |
Set_Is_Bit_Packed_Array (Base_Type (Arr), False); |
| 4007 |
|
| 4008 |
-- Bit packing is not needed for multiples of the storage |
| 4009 |
-- unit if the type is composite because the back end can |
| 4010 |
-- byte pack composite types efficiently. That's not true |
| 4011 |
-- for discrete types because every read would generate a |
| 4012 |
-- lot of instructions, so we keep using the manipulation |
| 4013 |
-- routines of the runtime for them. |
| 4014 |
|
| 4015 |
elsif Csiz mod System_Storage_Unit = 0 |
| 4016 |
and then Is_Composite_Type (Ctyp) |
| 4017 |
then |
| 4018 |
Set_Is_Packed (Base_Type (Arr), True); |
| 4019 |
Set_Has_Non_Standard_Rep (Base_Type (Arr), True); |
| 4020 |
Set_Is_Bit_Packed_Array (Base_Type (Arr), False); |
| 4021 |
|
| 4022 |
-- In all other cases, bit packing is needed |
| 4023 |
|
| 4024 |
else |
| 4025 |
Set_Is_Packed (Base_Type (Arr), True); |
| 4026 |
Set_Has_Non_Standard_Rep (Base_Type (Arr), True); |
| 4027 |
Set_Is_Bit_Packed_Array (Base_Type (Arr), True); |
| 4028 |
end if; |
| 4029 |
end; |
| 4030 |
end if; |
| 4031 |
end; |
| 4032 |
|
| 4033 |
-- Warn for case of atomic type |
| 4034 |
|
| 4035 |
Clause := Get_Rep_Pragma (FS, Name_Atomic); |
| 4036 |
|
| 4037 |
if Present (Clause) |
| 4038 |
and then not Addressable (Component_Size (FS)) |
| 4039 |
then |
| 4040 |
Error_Msg_NE |
| 4041 |
("non-atomic components of type& may not be " |
| 4042 |
& "accessible by separate tasks??", Clause, Arr); |
| 4043 |
|
| 4044 |
if Has_Component_Size_Clause (Arr) then |
| 4045 |
Error_Msg_Sloc := Sloc (Get_Attribute_Definition_Clause |
| 4046 |
(FS, Attribute_Component_Size)); |
| 4047 |
Error_Msg_N ("\because of component size clause#??", Clause); |
| 4048 |
|
| 4049 |
elsif Has_Pragma_Pack (Arr) then |
| 4050 |
Error_Msg_Sloc := Sloc (Get_Rep_Pragma (FS, Name_Pack)); |
| 4051 |
Error_Msg_N ("\because of pragma Pack#??", Clause); |
| 4052 |
end if; |
| 4053 |
end if; |
| 4054 |
|
| 4055 |
-- Check for scalar storage order |
| 4056 |
|
| 4057 |
declare |
| 4058 |
Dummy : Boolean; |
| 4059 |
begin |
| 4060 |
Check_Component_Storage_Order |
| 4061 |
(Encl_Type => Arr, |
| 4062 |
Comp => Empty, |
| 4063 |
ADC => Get_Attribute_Definition_Clause |
| 4064 |
(First_Subtype (Arr), |
| 4065 |
Attribute_Scalar_Storage_Order), |
| 4066 |
Comp_ADC_Present => Dummy); |
| 4067 |
end; |
| 4068 |
|
| 4069 |
-- Processing that is done only for subtypes |
| 4070 |
|
| 4071 |
else |
| 4072 |
-- Acquire alignment from base type. Known_Alignment of the base |
| 4073 |
-- type is False for Wide_String, for example. |
| 4074 |
|
| 4075 |
if not Known_Alignment (Arr) |
| 4076 |
and then Known_Alignment (Base_Type (Arr)) |
| 4077 |
then |
| 4078 |
Set_Alignment (Arr, Alignment (Base_Type (Arr))); |
| 4079 |
Adjust_Esize_Alignment (Arr); |
| 4080 |
end if; |
| 4081 |
end if; |
| 4082 |
|
| 4083 |
-- Specific checks for bit-packed arrays |
| 4084 |
|
| 4085 |
if Is_Bit_Packed_Array (Arr) then |
| 4086 |
|
| 4087 |
-- Check number of elements for bit-packed arrays that come from |
| 4088 |
-- source and have compile time known ranges. The bit-packed |
| 4089 |
-- arrays circuitry does not support arrays with more than |
| 4090 |
-- Integer'Last + 1 elements, and when this restriction is |
| 4091 |
-- violated, causes incorrect data access. |
| 4092 |
|
| 4093 |
-- For the case where this is not compile time known, a run-time |
| 4094 |
-- check should be generated??? |
| 4095 |
|
| 4096 |
if Comes_From_Source (Arr) and then Is_Constrained (Arr) then |
| 4097 |
declare |
| 4098 |
Elmts : Uint; |
| 4099 |
Index : Node_Id; |
| 4100 |
Ilen : Node_Id; |
| 4101 |
Ityp : Entity_Id; |
| 4102 |
|
| 4103 |
begin |
| 4104 |
Elmts := Uint_1; |
| 4105 |
Index := First_Index (Arr); |
| 4106 |
while Present (Index) loop |
| 4107 |
Ityp := Etype (Index); |
| 4108 |
|
| 4109 |
-- Never generate an error if any index is of a generic |
| 4110 |
-- type. We will check this in instances. |
| 4111 |
|
| 4112 |
if Is_Generic_Type (Ityp) then |
| 4113 |
Elmts := Uint_0; |
| 4114 |
exit; |
| 4115 |
end if; |
| 4116 |
|
| 4117 |
Ilen := |
| 4118 |
Make_Attribute_Reference (Loc, |
| 4119 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 4120 |
Attribute_Name => Name_Range_Length); |
| 4121 |
Analyze_And_Resolve (Ilen); |
| 4122 |
|
| 4123 |
-- No attempt is made to check number of elements if not |
| 4124 |
-- compile time known. |
| 4125 |
|
| 4126 |
if Nkind (Ilen) /= N_Integer_Literal then |
| 4127 |
Elmts := Uint_0; |
| 4128 |
exit; |
| 4129 |
end if; |
| 4130 |
|
| 4131 |
Elmts := Elmts * Intval (Ilen); |
| 4132 |
Next_Index (Index); |
| 4133 |
end loop; |
| 4134 |
|
| 4135 |
if Elmts > Intval (High_Bound |
| 4136 |
(Scalar_Range (Standard_Integer))) + 1 |
| 4137 |
then |
| 4138 |
Error_Msg_N |
| 4139 |
("bit packed array type may not have " |
| 4140 |
& "more than Integer''Last+1 elements", Arr); |
| 4141 |
end if; |
| 4142 |
end; |
| 4143 |
end if; |
| 4144 |
|
| 4145 |
-- Check size |
| 4146 |
|
| 4147 |
if Known_RM_Size (Arr) then |
| 4148 |
declare |
| 4149 |
SizC : constant Node_Id := Size_Clause (Arr); |
| 4150 |
Discard : Boolean; |
| 4151 |
|
| 4152 |
begin |
| 4153 |
-- It is not clear if it is possible to have no size clause |
| 4154 |
-- at this stage, but it is not worth worrying about. Post |
| 4155 |
-- error on the entity name in the size clause if present, |
| 4156 |
-- else on the type entity itself. |
| 4157 |
|
| 4158 |
if Present (SizC) then |
| 4159 |
Check_Size (Name (SizC), Arr, RM_Size (Arr), Discard); |
| 4160 |
else |
| 4161 |
Check_Size (Arr, Arr, RM_Size (Arr), Discard); |
| 4162 |
end if; |
| 4163 |
end; |
| 4164 |
end if; |
| 4165 |
end if; |
| 4166 |
|
| 4167 |
-- If any of the index types was an enumeration type with a non- |
| 4168 |
-- standard rep clause, then we indicate that the array type is |
| 4169 |
-- always packed (even if it is not bit-packed). |
| 4170 |
|
| 4171 |
if Non_Standard_Enum then |
| 4172 |
Set_Has_Non_Standard_Rep (Base_Type (Arr)); |
| 4173 |
Set_Is_Packed (Base_Type (Arr)); |
| 4174 |
end if; |
| 4175 |
|
| 4176 |
Set_Component_Alignment_If_Not_Set (Arr); |
| 4177 |
|
| 4178 |
-- If the array is packed and bit-packed or packed to eliminate holes |
| 4179 |
-- in the non-contiguous enumeration index types, we must create the |
| 4180 |
-- packed array type to be used to actually implement the type. This |
| 4181 |
-- is only needed for real array types (not for string literal types, |
| 4182 |
-- since they are present only for the front end). |
| 4183 |
|
| 4184 |
if Is_Packed (Arr) |
| 4185 |
and then (Is_Bit_Packed_Array (Arr) or else Non_Standard_Enum) |
| 4186 |
and then Ekind (Arr) /= E_String_Literal_Subtype |
| 4187 |
then |
| 4188 |
Create_Packed_Array_Impl_Type (Arr); |
| 4189 |
Freeze_And_Append (Packed_Array_Impl_Type (Arr), N, Result); |
| 4190 |
|
| 4191 |
-- Make sure that we have the necessary routines to implement the |
| 4192 |
-- packing, and complain now if not. Note that we only test this |
| 4193 |
-- for constrained array types. |
| 4194 |
|
| 4195 |
if Is_Constrained (Arr) |
| 4196 |
and then Is_Bit_Packed_Array (Arr) |
| 4197 |
and then Present (Packed_Array_Impl_Type (Arr)) |
| 4198 |
and then Is_Array_Type (Packed_Array_Impl_Type (Arr)) |
| 4199 |
then |
| 4200 |
declare |
| 4201 |
CS : constant Uint := Component_Size (Arr); |
| 4202 |
RE : constant RE_Id := Get_Id (UI_To_Int (CS)); |
| 4203 |
|
| 4204 |
begin |
| 4205 |
if RE /= RE_Null |
| 4206 |
and then not RTE_Available (RE) |
| 4207 |
then |
| 4208 |
Error_Msg_CRT |
| 4209 |
("packing of " & UI_Image (CS) & "-bit components", |
| 4210 |
First_Subtype (Etype (Arr))); |
| 4211 |
|
| 4212 |
-- Cancel the packing |
| 4213 |
|
| 4214 |
Set_Is_Packed (Base_Type (Arr), False); |
| 4215 |
Set_Is_Bit_Packed_Array (Base_Type (Arr), False); |
| 4216 |
Set_Packed_Array_Impl_Type (Arr, Empty); |
| 4217 |
goto Skip_Packed; |
| 4218 |
end if; |
| 4219 |
end; |
| 4220 |
end if; |
| 4221 |
|
| 4222 |
-- Size information of packed array type is copied to the array |
| 4223 |
-- type, since this is really the representation. But do not |
| 4224 |
-- override explicit existing size values. If the ancestor subtype |
| 4225 |
-- is constrained the Packed_Array_Impl_Type will be inherited |
| 4226 |
-- from it, but the size may have been provided already, and |
| 4227 |
-- must not be overridden either. |
| 4228 |
|
| 4229 |
if not Has_Size_Clause (Arr) |
| 4230 |
and then |
| 4231 |
(No (Ancestor_Subtype (Arr)) |
| 4232 |
or else not Has_Size_Clause (Ancestor_Subtype (Arr))) |
| 4233 |
then |
| 4234 |
Copy_Esize (To => Arr, From => Packed_Array_Impl_Type (Arr)); |
| 4235 |
Copy_RM_Size (To => Arr, From => Packed_Array_Impl_Type (Arr)); |
| 4236 |
end if; |
| 4237 |
|
| 4238 |
if not Has_Alignment_Clause (Arr) then |
| 4239 |
Copy_Alignment |
| 4240 |
(To => Arr, From => Packed_Array_Impl_Type (Arr)); |
| 4241 |
end if; |
| 4242 |
end if; |
| 4243 |
|
| 4244 |
<<Skip_Packed>> |
| 4245 |
|
| 4246 |
-- A Ghost type cannot have a component of protected or task type |
| 4247 |
-- (SPARK RM 6.9(21)). |
| 4248 |
|
| 4249 |
if Is_Ghost_Entity (Arr) and then Is_Concurrent_Type (Ctyp) then |
| 4250 |
Error_Msg_N |
| 4251 |
("ghost array type & cannot have concurrent component type", |
| 4252 |
Arr); |
| 4253 |
end if; |
| 4254 |
end Freeze_Array_Type; |
| 4255 |
|
| 4256 |
------------------------------- |
| 4257 |
-- Freeze_Object_Declaration -- |
| 4258 |
------------------------------- |
| 4259 |
|
| 4260 |
procedure Freeze_Object_Declaration (E : Entity_Id) is |
| 4261 |
Decl : constant Node_Id := Declaration_Node (E); |
| 4262 |
|
| 4263 |
procedure Check_Large_Modular_Array (Typ : Entity_Id); |
| 4264 |
-- Check that the size of array type Typ can be computed without |
| 4265 |
-- overflow, and generates a Storage_Error otherwise. This is only |
| 4266 |
-- relevant for array types whose index is a modular type with |
| 4267 |
-- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic |
| 4268 |
-- might yield a meaningless value for the length of the array, |
| 4269 |
-- or its corresponding attribute. |
| 4270 |
|
| 4271 |
procedure Check_Pragma_Thread_Local_Storage (Var_Id : Entity_Id); |
| 4272 |
-- Ensure that the initialization state of variable Var_Id subject |
| 4273 |
-- to pragma Thread_Local_Storage agrees with the semantics of the |
| 4274 |
-- pragma. |
| 4275 |
|
| 4276 |
function Has_Default_Initialization |
| 4277 |
(Obj_Id : Entity_Id) return Boolean; |
| 4278 |
-- Determine whether object Obj_Id default initialized |
| 4279 |
|
| 4280 |
------------------------------- |
| 4281 |
-- Check_Large_Modular_Array -- |
| 4282 |
------------------------------- |
| 4283 |
|
| 4284 |
procedure Check_Large_Modular_Array (Typ : Entity_Id) is |
| 4285 |
Obj_Loc : constant Source_Ptr := Sloc (E); |
| 4286 |
Idx_Typ : Entity_Id; |
| 4287 |
|
| 4288 |
begin |
| 4289 |
-- Nothing to do when expansion is disabled because this routine |
| 4290 |
-- generates a runtime check. |
| 4291 |
|
| 4292 |
if not Expander_Active then |
| 4293 |
return; |
| 4294 |
|
| 4295 |
-- Nothing to do for String literal subtypes because their index |
| 4296 |
-- cannot be a modular type. |
| 4297 |
|
| 4298 |
elsif Ekind (Typ) = E_String_Literal_Subtype then |
| 4299 |
return; |
| 4300 |
|
| 4301 |
-- Nothing to do for an imported object because the object will |
| 4302 |
-- be created on the exporting side. |
| 4303 |
|
| 4304 |
elsif Is_Imported (E) then |
| 4305 |
return; |
| 4306 |
|
| 4307 |
-- Nothing to do for unconstrained array types. This case arises |
| 4308 |
-- when the object declaration is illegal. |
| 4309 |
|
| 4310 |
elsif not Is_Constrained (Typ) then |
| 4311 |
return; |
| 4312 |
end if; |
| 4313 |
|
| 4314 |
Idx_Typ := Etype (First_Index (Typ)); |
| 4315 |
|
| 4316 |
-- To prevent arithmetic overflow with large values, we raise |
| 4317 |
-- Storage_Error under the following guard: |
| 4318 |
-- |
| 4319 |
-- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30) |
| 4320 |
-- |
| 4321 |
-- This takes care of the boundary case, but it is preferable to |
| 4322 |
-- use a smaller limit, because even on 64-bit architectures an |
| 4323 |
-- array of more than 2 ** 30 bytes is likely to raise |
| 4324 |
-- Storage_Error. |
| 4325 |
|
| 4326 |
if Is_Modular_Integer_Type (Idx_Typ) |
| 4327 |
and then RM_Size (Idx_Typ) = Standard_Long_Long_Integer_Size |
| 4328 |
then |
| 4329 |
-- Ensure that the type of the object is elaborated before |
| 4330 |
-- the check itself is emitted to avoid elaboration issues |
| 4331 |
-- in the code generator at the library level. |
| 4332 |
|
| 4333 |
if Is_Itype (Etype (E)) |
| 4334 |
and then In_Open_Scopes (Scope (Etype (E))) |
| 4335 |
then |
| 4336 |
declare |
| 4337 |
Ref_Node : constant Node_Id := |
| 4338 |
Make_Itype_Reference (Obj_Loc); |
| 4339 |
begin |
| 4340 |
Set_Itype (Ref_Node, Etype (E)); |
| 4341 |
Insert_Action (Decl, Ref_Node); |
| 4342 |
end; |
| 4343 |
end if; |
| 4344 |
|
| 4345 |
Insert_Action (Decl, |
| 4346 |
Make_Raise_Storage_Error (Obj_Loc, |
| 4347 |
Condition => |
| 4348 |
Make_Op_Ge (Obj_Loc, |
| 4349 |
Left_Opnd => |
| 4350 |
Make_Op_Subtract (Obj_Loc, |
| 4351 |
Left_Opnd => |
| 4352 |
Make_Op_Divide (Obj_Loc, |
| 4353 |
Left_Opnd => |
| 4354 |
Make_Attribute_Reference (Obj_Loc, |
| 4355 |
Prefix => |
| 4356 |
New_Occurrence_Of (Typ, Obj_Loc), |
| 4357 |
Attribute_Name => Name_Last), |
| 4358 |
Right_Opnd => |
| 4359 |
Make_Integer_Literal (Obj_Loc, Uint_2)), |
| 4360 |
Right_Opnd => |
| 4361 |
Make_Op_Divide (Obj_Loc, |
| 4362 |
Left_Opnd => |
| 4363 |
Make_Attribute_Reference (Obj_Loc, |
| 4364 |
Prefix => |
| 4365 |
New_Occurrence_Of (Typ, Obj_Loc), |
| 4366 |
Attribute_Name => Name_First), |
| 4367 |
Right_Opnd => |
| 4368 |
Make_Integer_Literal (Obj_Loc, Uint_2))), |
| 4369 |
Right_Opnd => |
| 4370 |
Make_Integer_Literal (Obj_Loc, (Uint_2 ** 30))), |
| 4371 |
Reason => SE_Object_Too_Large)); |
| 4372 |
end if; |
| 4373 |
end Check_Large_Modular_Array; |
| 4374 |
|
| 4375 |
--------------------------------------- |
| 4376 |
-- Check_Pragma_Thread_Local_Storage -- |
| 4377 |
--------------------------------------- |
| 4378 |
|
| 4379 |
procedure Check_Pragma_Thread_Local_Storage (Var_Id : Entity_Id) is |
| 4380 |
function Has_Incompatible_Initialization |
| 4381 |
(Var_Decl : Node_Id) return Boolean; |
| 4382 |
-- Determine whether variable Var_Id with declaration Var_Decl is |
| 4383 |
-- initialized with a value that violates the semantics of pragma |
| 4384 |
-- Thread_Local_Storage. |
| 4385 |
|
| 4386 |
------------------------------------- |
| 4387 |
-- Has_Incompatible_Initialization -- |
| 4388 |
------------------------------------- |
| 4389 |
|
| 4390 |
function Has_Incompatible_Initialization |
| 4391 |
(Var_Decl : Node_Id) return Boolean |
| 4392 |
is |
| 4393 |
Init_Expr : constant Node_Id := Expression (Var_Decl); |
| 4394 |
|
| 4395 |
begin |
| 4396 |
-- The variable is default-initialized. This directly violates |
| 4397 |
-- the semantics of the pragma. |
| 4398 |
|
| 4399 |
if Has_Default_Initialization (Var_Id) then |
| 4400 |
return True; |
| 4401 |
|
| 4402 |
-- The variable has explicit initialization. In this case only |
| 4403 |
-- a handful of values satisfy the semantics of the pragma. |
| 4404 |
|
| 4405 |
elsif Has_Init_Expression (Var_Decl) |
| 4406 |
and then Present (Init_Expr) |
| 4407 |
then |
| 4408 |
-- "null" is a legal form of initialization |
| 4409 |
|
| 4410 |
if Nkind (Init_Expr) = N_Null then |
| 4411 |
return False; |
| 4412 |
|
| 4413 |
-- A static expression is a legal form of initialization |
| 4414 |
|
| 4415 |
elsif Is_Static_Expression (Init_Expr) then |
| 4416 |
return False; |
| 4417 |
|
| 4418 |
-- A static aggregate is a legal form of initialization |
| 4419 |
|
| 4420 |
elsif Nkind (Init_Expr) = N_Aggregate |
| 4421 |
and then Compile_Time_Known_Aggregate (Init_Expr) |
| 4422 |
then |
| 4423 |
return False; |
| 4424 |
|
| 4425 |
-- All other initialization expressions violate the semantic |
| 4426 |
-- of the pragma. |
| 4427 |
|
| 4428 |
else |
| 4429 |
return True; |
| 4430 |
end if; |
| 4431 |
|
| 4432 |
-- The variable lacks any kind of initialization, which agrees |
| 4433 |
-- with the semantics of the pragma. |
| 4434 |
|
| 4435 |
else |
| 4436 |
return False; |
| 4437 |
end if; |
| 4438 |
end Has_Incompatible_Initialization; |
| 4439 |
|
| 4440 |
-- Local declarations |
| 4441 |
|
| 4442 |
Var_Decl : constant Node_Id := Declaration_Node (Var_Id); |
| 4443 |
|
| 4444 |
-- Start of processing for Check_Pragma_Thread_Local_Storage |
| 4445 |
|
| 4446 |
begin |
| 4447 |
-- A variable whose initialization is suppressed lacks any kind of |
| 4448 |
-- initialization. |
| 4449 |
|
| 4450 |
if Suppress_Initialization (Var_Id) then |
| 4451 |
null; |
| 4452 |
|
| 4453 |
-- The variable has default initialization, or is explicitly |
| 4454 |
-- initialized to a value other than null, static expression, |
| 4455 |
-- or a static aggregate. |
| 4456 |
|
| 4457 |
elsif Has_Incompatible_Initialization (Var_Decl) then |
| 4458 |
Error_Msg_NE |
| 4459 |
("Thread_Local_Storage variable& is improperly initialized", |
| 4460 |
Var_Decl, Var_Id); |
| 4461 |
Error_Msg_NE |
| 4462 |
("\only allowed initialization is explicit NULL, static " |
| 4463 |
& "expression or static aggregate", Var_Decl, Var_Id); |
| 4464 |
end if; |
| 4465 |
end Check_Pragma_Thread_Local_Storage; |
| 4466 |
|
| 4467 |
-------------------------------- |
| 4468 |
-- Has_Default_Initialization -- |
| 4469 |
-------------------------------- |
| 4470 |
|
| 4471 |
function Has_Default_Initialization |
| 4472 |
(Obj_Id : Entity_Id) return Boolean |
| 4473 |
is |
| 4474 |
Obj_Decl : constant Node_Id := Declaration_Node (Obj_Id); |
| 4475 |
Obj_Typ : constant Entity_Id := Etype (Obj_Id); |
| 4476 |
|
| 4477 |
begin |
| 4478 |
return |
| 4479 |
Comes_From_Source (Obj_Id) |
| 4480 |
and then not Is_Imported (Obj_Id) |
| 4481 |
and then not Has_Init_Expression (Obj_Decl) |
| 4482 |
and then |
| 4483 |
((Has_Non_Null_Base_Init_Proc (Obj_Typ) |
| 4484 |
and then not No_Initialization (Obj_Decl) |
| 4485 |
and then not Initialization_Suppressed (Obj_Typ)) |
| 4486 |
or else |
| 4487 |
(Needs_Simple_Initialization (Obj_Typ) |
| 4488 |
and then not Is_Internal (Obj_Id))); |
| 4489 |
end Has_Default_Initialization; |
| 4490 |
|
| 4491 |
-- Local variables |
| 4492 |
|
| 4493 |
Typ : constant Entity_Id := Etype (E); |
| 4494 |
Def : Node_Id; |
| 4495 |
|
| 4496 |
-- Start of processing for Freeze_Object_Declaration |
| 4497 |
|
| 4498 |
begin |
| 4499 |
-- Abstract type allowed only for C++ imported variables or constants |
| 4500 |
|
| 4501 |
-- Note: we inhibit this check for objects that do not come from |
| 4502 |
-- source because there is at least one case (the expansion of |
| 4503 |
-- x'Class'Input where x is abstract) where we legitimately |
| 4504 |
-- generate an abstract object. |
| 4505 |
|
| 4506 |
if Is_Abstract_Type (Typ) |
| 4507 |
and then Comes_From_Source (Parent (E)) |
| 4508 |
and then not (Is_Imported (E) and then Is_CPP_Class (Typ)) |
| 4509 |
then |
| 4510 |
Def := Object_Definition (Parent (E)); |
| 4511 |
|
| 4512 |
Error_Msg_N ("type of object cannot be abstract", Def); |
| 4513 |
|
| 4514 |
if Is_CPP_Class (Etype (E)) then |
| 4515 |
Error_Msg_NE ("\} may need a cpp_constructor", Def, Typ); |
| 4516 |
|
| 4517 |
elsif Present (Expression (Parent (E))) then |
| 4518 |
Error_Msg_N -- CODEFIX |
| 4519 |
("\maybe a class-wide type was meant", Def); |
| 4520 |
end if; |
| 4521 |
end if; |
| 4522 |
|
| 4523 |
-- For object created by object declaration, perform required |
| 4524 |
-- categorization (preelaborate and pure) checks. Defer these |
| 4525 |
-- checks to freeze time since pragma Import inhibits default |
| 4526 |
-- initialization and thus pragma Import affects these checks. |
| 4527 |
|
| 4528 |
Validate_Object_Declaration (Decl); |
| 4529 |
|
| 4530 |
-- If there is an address clause, check that it is valid |
| 4531 |
|
| 4532 |
Check_Address_Clause (E); |
| 4533 |
|
| 4534 |
-- If the object has an address clause or a delayed aspect, remove |
| 4535 |
-- the side effects from initial expression, except in the case of |
| 4536 |
-- limited build-in-place calls and aggregates, which have their own |
| 4537 |
-- expansion elsewhere. This exception is necessary to avoid copying |
| 4538 |
-- limited objects. |
| 4539 |
|
| 4540 |
if Expander_Active |
| 4541 |
and then |
| 4542 |
(Present (Address_Clause (E)) or else Has_Delayed_Aspects (E)) |
| 4543 |
and then Present (Expression (Decl)) |
| 4544 |
and then not No_Initialization (Decl) |
| 4545 |
and then not Is_Inherently_Limited_Type (Typ) |
| 4546 |
then |
| 4547 |
declare |
| 4548 |
Init : constant Node_Id := Expression (Decl); |
| 4549 |
Lhs : constant Node_Id := New_Occurrence_Of (E, Loc); |
| 4550 |
|
| 4551 |
Assign : Node_Id; |
| 4552 |
|
| 4553 |
begin |
| 4554 |
-- Capture initialization value at point of declaration, and |
| 4555 |
-- make explicit assignment legal, because object may be a |
| 4556 |
-- constant. |
| 4557 |
|
| 4558 |
Remove_Side_Effects (Init); |
| 4559 |
Set_Assignment_OK (Lhs); |
| 4560 |
|
| 4561 |
Assign := |
| 4562 |
Make_Assignment_Statement (Sloc (Decl), |
| 4563 |
Name => Lhs, |
| 4564 |
Expression => Init); |
| 4565 |
|
| 4566 |
Set_No_Initialization (Decl); |
| 4567 |
|
| 4568 |
-- If the initialization expression is an aggregate, we do not |
| 4569 |
-- adjust after the assignment but, in either case, we do not |
| 4570 |
-- finalize before since the object is now uninitialized. Note |
| 4571 |
-- that Make_Tag_Ctrl_Assignment will also automatically insert |
| 4572 |
-- the tag assignment in the tagged case. |
| 4573 |
|
| 4574 |
if Nkind (Unqualify (Init)) = N_Aggregate then |
| 4575 |
Set_No_Ctrl_Actions (Assign); |
| 4576 |
else |
| 4577 |
Set_No_Finalize_Actions (Assign); |
| 4578 |
end if; |
| 4579 |
|
| 4580 |
-- Move initialization to freeze actions, once the object has |
| 4581 |
-- been frozen and the address clause alignment check has been |
| 4582 |
-- performed. |
| 4583 |
|
| 4584 |
Append_Freeze_Action (E, Assign); |
| 4585 |
end; |
| 4586 |
end if; |
| 4587 |
|
| 4588 |
-- Reset Is_True_Constant for non-constant aliased object. We |
| 4589 |
-- consider that the fact that a non-constant object is aliased may |
| 4590 |
-- indicate that some funny business is going on, e.g. an aliased |
| 4591 |
-- object is passed by reference to a procedure which captures the |
| 4592 |
-- address of the object, which is later used to assign a new value, |
| 4593 |
-- even though the compiler thinks that it is not modified. Such |
| 4594 |
-- code is highly dubious, but we choose to make it "work" for |
| 4595 |
-- non-constant aliased objects. |
| 4596 |
|
| 4597 |
-- Note that we used to do this for all aliased objects, whether or |
| 4598 |
-- not constant, but this caused anomalies down the line because we |
| 4599 |
-- ended up with static objects that were not Is_True_Constant. Not |
| 4600 |
-- resetting Is_True_Constant for (aliased) constant objects ensures |
| 4601 |
-- that this anomaly never occurs. |
| 4602 |
|
| 4603 |
-- However, we don't do that for internal entities. We figure that if |
| 4604 |
-- we deliberately set Is_True_Constant for an internal entity, e.g. |
| 4605 |
-- a dispatch table entry, then we mean it. |
| 4606 |
|
| 4607 |
if Ekind (E) /= E_Constant |
| 4608 |
and then (Is_Aliased (E) or else Is_Aliased (Typ)) |
| 4609 |
and then not Is_Internal_Name (Chars (E)) |
| 4610 |
then |
| 4611 |
Set_Is_True_Constant (E, False); |
| 4612 |
end if; |
| 4613 |
|
| 4614 |
-- If the object needs any kind of default initialization, an error |
| 4615 |
-- must be issued if No_Default_Initialization applies. The check |
| 4616 |
-- doesn't apply to imported objects, which are not ever default |
| 4617 |
-- initialized, and is why the check is deferred until freezing, at |
| 4618 |
-- which point we know if Import applies. Deferred constants are also |
| 4619 |
-- exempted from this test because their completion is explicit, or |
| 4620 |
-- through an import pragma. |
| 4621 |
|
| 4622 |
if Ekind (E) = E_Constant and then Present (Full_View (E)) then |
| 4623 |
null; |
| 4624 |
|
| 4625 |
elsif Has_Default_Initialization (E) then |
| 4626 |
Check_Restriction (No_Default_Initialization, Decl); |
| 4627 |
end if; |
| 4628 |
|
| 4629 |
-- Ensure that a variable subject to pragma Thread_Local_Storage |
| 4630 |
-- |
| 4631 |
-- * Lacks default initialization, or |
| 4632 |
-- |
| 4633 |
-- * The initialization expression is either "null", a static |
| 4634 |
-- constant, or a compile-time known aggregate. |
| 4635 |
|
| 4636 |
if Has_Pragma_Thread_Local_Storage (E) then |
| 4637 |
Check_Pragma_Thread_Local_Storage (E); |
| 4638 |
end if; |
| 4639 |
|
| 4640 |
-- For imported objects, set Is_Public unless there is also an |
| 4641 |
-- address clause, which means that there is no external symbol |
| 4642 |
-- needed for the Import (Is_Public may still be set for other |
| 4643 |
-- unrelated reasons). Note that we delayed this processing |
| 4644 |
-- till freeze time so that we can be sure not to set the flag |
| 4645 |
-- if there is an address clause. If there is such a clause, |
| 4646 |
-- then the only purpose of the Import pragma is to suppress |
| 4647 |
-- implicit initialization. |
| 4648 |
|
| 4649 |
if Is_Imported (E) and then No (Address_Clause (E)) then |
| 4650 |
Set_Is_Public (E); |
| 4651 |
end if; |
| 4652 |
|
| 4653 |
-- For source objects that are not Imported and are library level, if |
| 4654 |
-- no linker section pragma was given inherit the appropriate linker |
| 4655 |
-- section from the corresponding type. |
| 4656 |
|
| 4657 |
if Comes_From_Source (E) |
| 4658 |
and then not Is_Imported (E) |
| 4659 |
and then Is_Library_Level_Entity (E) |
| 4660 |
and then No (Linker_Section_Pragma (E)) |
| 4661 |
then |
| 4662 |
Set_Linker_Section_Pragma (E, Linker_Section_Pragma (Typ)); |
| 4663 |
end if; |
| 4664 |
|
| 4665 |
-- For convention C objects of an enumeration type, warn if the size |
| 4666 |
-- is not integer size and no explicit size given. Skip warning for |
| 4667 |
-- Boolean and Character, and assume programmer expects 8-bit sizes |
| 4668 |
-- for these cases. |
| 4669 |
|
| 4670 |
if (Convention (E) = Convention_C |
| 4671 |
or else |
| 4672 |
Convention (E) = Convention_CPP) |
| 4673 |
and then Is_Enumeration_Type (Typ) |
| 4674 |
and then not Is_Character_Type (Typ) |
| 4675 |
and then not Is_Boolean_Type (Typ) |
| 4676 |
and then Esize (Typ) < Standard_Integer_Size |
| 4677 |
and then not Has_Size_Clause (E) |
| 4678 |
then |
| 4679 |
Error_Msg_Uint_1 := UI_From_Int (Standard_Integer_Size); |
| 4680 |
Error_Msg_N |
| 4681 |
("??convention C enumeration object has size less than ^", E); |
| 4682 |
Error_Msg_N ("\??use explicit size clause to set size", E); |
| 4683 |
end if; |
| 4684 |
|
| 4685 |
-- Declaring too big an array in disabled ghost code is OK |
| 4686 |
|
| 4687 |
if Is_Array_Type (Typ) and then not Is_Ignored_Ghost_Entity (E) then |
| 4688 |
Check_Large_Modular_Array (Typ); |
| 4689 |
end if; |
| 4690 |
end Freeze_Object_Declaration; |
| 4691 |
|
| 4692 |
----------------------------- |
| 4693 |
-- Freeze_Generic_Entities -- |
| 4694 |
----------------------------- |
| 4695 |
|
| 4696 |
function Freeze_Generic_Entities (Pack : Entity_Id) return List_Id is |
| 4697 |
E : Entity_Id; |
| 4698 |
F : Node_Id; |
| 4699 |
Flist : List_Id; |
| 4700 |
|
| 4701 |
begin |
| 4702 |
Flist := New_List; |
| 4703 |
E := First_Entity (Pack); |
| 4704 |
while Present (E) loop |
| 4705 |
if Is_Type (E) and then not Is_Generic_Type (E) then |
| 4706 |
F := Make_Freeze_Generic_Entity (Sloc (Pack)); |
| 4707 |
Set_Entity (F, E); |
| 4708 |
Append_To (Flist, F); |
| 4709 |
|
| 4710 |
elsif Ekind (E) = E_Generic_Package then |
| 4711 |
Append_List_To (Flist, Freeze_Generic_Entities (E)); |
| 4712 |
end if; |
| 4713 |
|
| 4714 |
Next_Entity (E); |
| 4715 |
end loop; |
| 4716 |
|
| 4717 |
return Flist; |
| 4718 |
end Freeze_Generic_Entities; |
| 4719 |
|
| 4720 |
-------------------- |
| 4721 |
-- Freeze_Profile -- |
| 4722 |
-------------------- |
| 4723 |
|
| 4724 |
function Freeze_Profile (E : Entity_Id) return Boolean is |
| 4725 |
F_Type : Entity_Id; |
| 4726 |
R_Type : Entity_Id; |
| 4727 |
Warn_Node : Node_Id; |
| 4728 |
|
| 4729 |
begin |
| 4730 |
-- Loop through formals |
| 4731 |
|
| 4732 |
Formal := First_Formal (E); |
| 4733 |
while Present (Formal) loop |
| 4734 |
F_Type := Etype (Formal); |
| 4735 |
|
| 4736 |
-- AI05-0151: incomplete types can appear in a profile. By the |
| 4737 |
-- time the entity is frozen, the full view must be available, |
| 4738 |
-- unless it is a limited view. |
| 4739 |
|
| 4740 |
if Is_Incomplete_Type (F_Type) |
| 4741 |
and then Present (Full_View (F_Type)) |
| 4742 |
and then not From_Limited_With (F_Type) |
| 4743 |
then |
| 4744 |
F_Type := Full_View (F_Type); |
| 4745 |
Set_Etype (Formal, F_Type); |
| 4746 |
end if; |
| 4747 |
|
| 4748 |
if not From_Limited_With (F_Type) |
| 4749 |
and then Should_Freeze_Type (F_Type, E, N) |
| 4750 |
then |
| 4751 |
Freeze_And_Append (F_Type, N, Result); |
| 4752 |
end if; |
| 4753 |
|
| 4754 |
if Is_Private_Type (F_Type) |
| 4755 |
and then Is_Private_Type (Base_Type (F_Type)) |
| 4756 |
and then No (Full_View (Base_Type (F_Type))) |
| 4757 |
and then not Is_Generic_Type (F_Type) |
| 4758 |
and then not Is_Derived_Type (F_Type) |
| 4759 |
then |
| 4760 |
-- If the type of a formal is incomplete, subprogram is being |
| 4761 |
-- frozen prematurely. Within an instance (but not within a |
| 4762 |
-- wrapper package) this is an artifact of our need to regard |
| 4763 |
-- the end of an instantiation as a freeze point. Otherwise it |
| 4764 |
-- is a definite error. |
| 4765 |
|
| 4766 |
if In_Instance then |
| 4767 |
Set_Is_Frozen (E, False); |
| 4768 |
Result := No_List; |
| 4769 |
return False; |
| 4770 |
|
| 4771 |
elsif not After_Last_Declaration then |
| 4772 |
Error_Msg_NE |
| 4773 |
("type & must be fully defined before this point", |
| 4774 |
N, |
| 4775 |
F_Type); |
| 4776 |
end if; |
| 4777 |
end if; |
| 4778 |
|
| 4779 |
-- Check suspicious parameter for C function. These tests apply |
| 4780 |
-- only to exported/imported subprograms. |
| 4781 |
|
| 4782 |
if Warn_On_Export_Import |
| 4783 |
and then Comes_From_Source (E) |
| 4784 |
and then Convention (E) in Convention_C_Family |
| 4785 |
and then (Is_Imported (E) or else Is_Exported (E)) |
| 4786 |
and then Convention (E) /= Convention (Formal) |
| 4787 |
and then not Has_Warnings_Off (E) |
| 4788 |
and then not Has_Warnings_Off (F_Type) |
| 4789 |
and then not Has_Warnings_Off (Formal) |
| 4790 |
then |
| 4791 |
-- Qualify mention of formals with subprogram name |
| 4792 |
|
| 4793 |
Error_Msg_Qual_Level := 1; |
| 4794 |
|
| 4795 |
-- Check suspicious use of fat C pointer, but do not emit |
| 4796 |
-- a warning on an access to subprogram when unnesting is |
| 4797 |
-- active. |
| 4798 |
|
| 4799 |
if Is_Access_Type (F_Type) |
| 4800 |
and then Known_Esize (F_Type) |
| 4801 |
and then Esize (F_Type) > Ttypes.System_Address_Size |
| 4802 |
and then (not Unnest_Subprogram_Mode |
| 4803 |
or else not Is_Access_Subprogram_Type (F_Type)) |
| 4804 |
then |
| 4805 |
Error_Msg_N |
| 4806 |
("?x?type of & does not correspond to C pointer!", Formal); |
| 4807 |
|
| 4808 |
-- Check suspicious return of boolean |
| 4809 |
|
| 4810 |
elsif Root_Type (F_Type) = Standard_Boolean |
| 4811 |
and then Convention (F_Type) = Convention_Ada |
| 4812 |
and then not Has_Warnings_Off (F_Type) |
| 4813 |
and then not Has_Size_Clause (F_Type) |
| 4814 |
and then Present (Esize (F_Type)) |
| 4815 |
and then Esize (F_Type) = 8 |
| 4816 |
then |
| 4817 |
Error_Msg_N |
| 4818 |
("& is an 8-bit Ada Boolean?x?", Formal); |
| 4819 |
Error_Msg_N |
| 4820 |
("\use appropriate corresponding type in C " |
| 4821 |
& "(e.g. char)?x?", Formal); |
| 4822 |
|
| 4823 |
-- Check suspicious tagged type |
| 4824 |
|
| 4825 |
elsif (Is_Tagged_Type (F_Type) |
| 4826 |
or else |
| 4827 |
(Is_Access_Type (F_Type) |
| 4828 |
and then Is_Tagged_Type (Designated_Type (F_Type)))) |
| 4829 |
and then Convention (E) = Convention_C |
| 4830 |
then |
| 4831 |
Error_Msg_N |
| 4832 |
("?x?& involves a tagged type which does not " |
| 4833 |
& "correspond to any C type!", Formal); |
| 4834 |
|
| 4835 |
-- Check wrong convention subprogram pointer |
| 4836 |
|
| 4837 |
elsif Ekind (F_Type) = E_Access_Subprogram_Type |
| 4838 |
and then not Has_Foreign_Convention (F_Type) |
| 4839 |
then |
| 4840 |
Error_Msg_N |
| 4841 |
("?x?subprogram pointer & should " |
| 4842 |
& "have foreign convention!", Formal); |
| 4843 |
Error_Msg_Sloc := Sloc (F_Type); |
| 4844 |
Error_Msg_NE |
| 4845 |
("\?x?add Convention pragma to declaration of &#", |
| 4846 |
Formal, F_Type); |
| 4847 |
end if; |
| 4848 |
|
| 4849 |
-- Turn off name qualification after message output |
| 4850 |
|
| 4851 |
Error_Msg_Qual_Level := 0; |
| 4852 |
end if; |
| 4853 |
|
| 4854 |
-- Check for unconstrained array in exported foreign convention |
| 4855 |
-- case. |
| 4856 |
|
| 4857 |
if Has_Foreign_Convention (E) |
| 4858 |
and then not Is_Imported (E) |
| 4859 |
and then Is_Array_Type (F_Type) |
| 4860 |
and then not Is_Constrained (F_Type) |
| 4861 |
and then Warn_On_Export_Import |
| 4862 |
then |
| 4863 |
Error_Msg_Qual_Level := 1; |
| 4864 |
|
| 4865 |
-- If this is an inherited operation, place the warning on |
| 4866 |
-- the derived type declaration, rather than on the original |
| 4867 |
-- subprogram. |
| 4868 |
|
| 4869 |
if Nkind (Original_Node (Parent (E))) = N_Full_Type_Declaration |
| 4870 |
then |
| 4871 |
Warn_Node := Parent (E); |
| 4872 |
|
| 4873 |
if Formal = First_Formal (E) then |
| 4874 |
Error_Msg_NE ("??in inherited operation&", Warn_Node, E); |
| 4875 |
end if; |
| 4876 |
else |
| 4877 |
Warn_Node := Formal; |
| 4878 |
end if; |
| 4879 |
|
| 4880 |
Error_Msg_NE ("?x?type of argument& is unconstrained array", |
| 4881 |
Warn_Node, Formal); |
| 4882 |
Error_Msg_N ("\?x?foreign caller must pass bounds explicitly", |
| 4883 |
Warn_Node); |
| 4884 |
Error_Msg_Qual_Level := 0; |
| 4885 |
end if; |
| 4886 |
|
| 4887 |
if not From_Limited_With (F_Type) then |
| 4888 |
if Is_Access_Type (F_Type) then |
| 4889 |
F_Type := Designated_Type (F_Type); |
| 4890 |
end if; |
| 4891 |
end if; |
| 4892 |
|
| 4893 |
Next_Formal (Formal); |
| 4894 |
end loop; |
| 4895 |
|
| 4896 |
-- Case of function: similar checks on return type |
| 4897 |
|
| 4898 |
if Ekind (E) = E_Function then |
| 4899 |
|
| 4900 |
-- Freeze return type |
| 4901 |
|
| 4902 |
R_Type := Etype (E); |
| 4903 |
|
| 4904 |
-- AI05-0151: the return type may have been incomplete at the |
| 4905 |
-- point of declaration. Replace it with the full view, unless the |
| 4906 |
-- current type is a limited view. In that case the full view is |
| 4907 |
-- in a different unit, and gigi finds the non-limited view after |
| 4908 |
-- the other unit is elaborated. |
| 4909 |
|
| 4910 |
if Ekind (R_Type) = E_Incomplete_Type |
| 4911 |
and then Present (Full_View (R_Type)) |
| 4912 |
and then not From_Limited_With (R_Type) |
| 4913 |
then |
| 4914 |
R_Type := Full_View (R_Type); |
| 4915 |
Set_Etype (E, R_Type); |
| 4916 |
end if; |
| 4917 |
|
| 4918 |
if Should_Freeze_Type (R_Type, E, N) then |
| 4919 |
Freeze_And_Append (R_Type, N, Result); |
| 4920 |
end if; |
| 4921 |
|
| 4922 |
-- Check suspicious return type for C function |
| 4923 |
|
| 4924 |
if Warn_On_Export_Import |
| 4925 |
and then Comes_From_Source (E) |
| 4926 |
and then Convention (E) in Convention_C_Family |
| 4927 |
and then (Is_Imported (E) or else Is_Exported (E)) |
| 4928 |
then |
| 4929 |
-- Check suspicious return of fat C pointer |
| 4930 |
|
| 4931 |
if Is_Access_Type (R_Type) |
| 4932 |
and then Known_Esize (R_Type) |
| 4933 |
and then Esize (R_Type) > Ttypes.System_Address_Size |
| 4934 |
and then not Has_Warnings_Off (E) |
| 4935 |
and then not Has_Warnings_Off (R_Type) |
| 4936 |
then |
| 4937 |
Error_Msg_N |
| 4938 |
("?x?return type of& does not correspond to C pointer!", |
| 4939 |
E); |
| 4940 |
|
| 4941 |
-- Check suspicious return of boolean |
| 4942 |
|
| 4943 |
elsif Root_Type (R_Type) = Standard_Boolean |
| 4944 |
and then Convention (R_Type) = Convention_Ada |
| 4945 |
and then not Has_Warnings_Off (E) |
| 4946 |
and then not Has_Warnings_Off (R_Type) |
| 4947 |
and then not Has_Size_Clause (R_Type) |
| 4948 |
then |
| 4949 |
declare |
| 4950 |
N : constant Node_Id := |
| 4951 |
Result_Definition (Declaration_Node (E)); |
| 4952 |
begin |
| 4953 |
Error_Msg_NE |
| 4954 |
("return type of & is an 8-bit Ada Boolean?x?", N, E); |
| 4955 |
Error_Msg_NE |
| 4956 |
("\use appropriate corresponding type in C " |
| 4957 |
& "(e.g. char)?x?", N, E); |
| 4958 |
end; |
| 4959 |
|
| 4960 |
-- Check suspicious return tagged type |
| 4961 |
|
| 4962 |
elsif (Is_Tagged_Type (R_Type) |
| 4963 |
or else (Is_Access_Type (R_Type) |
| 4964 |
and then |
| 4965 |
Is_Tagged_Type |
| 4966 |
(Designated_Type (R_Type)))) |
| 4967 |
and then Convention (E) = Convention_C |
| 4968 |
and then not Has_Warnings_Off (E) |
| 4969 |
and then not Has_Warnings_Off (R_Type) |
| 4970 |
then |
| 4971 |
Error_Msg_N ("?x?return type of & does not " |
| 4972 |
& "correspond to C type!", E); |
| 4973 |
|
| 4974 |
-- Check return of wrong convention subprogram pointer |
| 4975 |
|
| 4976 |
elsif Ekind (R_Type) = E_Access_Subprogram_Type |
| 4977 |
and then not Has_Foreign_Convention (R_Type) |
| 4978 |
and then not Has_Warnings_Off (E) |
| 4979 |
and then not Has_Warnings_Off (R_Type) |
| 4980 |
then |
| 4981 |
Error_Msg_N ("?x?& should return a foreign " |
| 4982 |
& "convention subprogram pointer", E); |
| 4983 |
Error_Msg_Sloc := Sloc (R_Type); |
| 4984 |
Error_Msg_NE |
| 4985 |
("\?x?add Convention pragma to declaration of& #", |
| 4986 |
E, R_Type); |
| 4987 |
end if; |
| 4988 |
end if; |
| 4989 |
|
| 4990 |
-- Give warning for suspicious return of a result of an |
| 4991 |
-- unconstrained array type in a foreign convention function. |
| 4992 |
|
| 4993 |
if Has_Foreign_Convention (E) |
| 4994 |
|
| 4995 |
-- We are looking for a return of unconstrained array |
| 4996 |
|
| 4997 |
and then Is_Array_Type (R_Type) |
| 4998 |
and then not Is_Constrained (R_Type) |
| 4999 |
|
| 5000 |
-- Exclude imported routines, the warning does not belong on |
| 5001 |
-- the import, but rather on the routine definition. |
| 5002 |
|
| 5003 |
and then not Is_Imported (E) |
| 5004 |
|
| 5005 |
-- Check that general warning is enabled, and that it is not |
| 5006 |
-- suppressed for this particular case. |
| 5007 |
|
| 5008 |
and then Warn_On_Export_Import |
| 5009 |
and then not Has_Warnings_Off (E) |
| 5010 |
and then not Has_Warnings_Off (R_Type) |
| 5011 |
then |
| 5012 |
Error_Msg_N |
| 5013 |
("?x?foreign convention function& should not return " |
| 5014 |
& "unconstrained array!", E); |
| 5015 |
end if; |
| 5016 |
end if; |
| 5017 |
|
| 5018 |
-- Check suspicious use of Import in pure unit (cases where the RM |
| 5019 |
-- allows calls to be omitted). |
| 5020 |
|
| 5021 |
if Is_Imported (E) |
| 5022 |
|
| 5023 |
-- It might be suspicious if the compilation unit has the Pure |
| 5024 |
-- aspect/pragma. |
| 5025 |
|
| 5026 |
and then Has_Pragma_Pure (Cunit_Entity (Current_Sem_Unit)) |
| 5027 |
|
| 5028 |
-- The RM allows omission of calls only in the case of |
| 5029 |
-- library-level subprograms (see RM-10.2.1(18)). |
| 5030 |
|
| 5031 |
and then Is_Library_Level_Entity (E) |
| 5032 |
|
| 5033 |
-- Ignore internally generated entity. This happens in some cases |
| 5034 |
-- of subprograms in specs, where we generate an implied body. |
| 5035 |
|
| 5036 |
and then Comes_From_Source (Import_Pragma (E)) |
| 5037 |
|
| 5038 |
-- Assume run-time knows what it is doing |
| 5039 |
|
| 5040 |
and then not GNAT_Mode |
| 5041 |
|
| 5042 |
-- Assume explicit Pure_Function means import is pure |
| 5043 |
|
| 5044 |
and then not Has_Pragma_Pure_Function (E) |
| 5045 |
|
| 5046 |
-- Don't need warning in relaxed semantics mode |
| 5047 |
|
| 5048 |
and then not Relaxed_RM_Semantics |
| 5049 |
|
| 5050 |
-- Assume convention Intrinsic is OK, since this is specialized. |
| 5051 |
-- This deals with the DEC unit current_exception.ads |
| 5052 |
|
| 5053 |
and then Convention (E) /= Convention_Intrinsic |
| 5054 |
|
| 5055 |
-- Assume that ASM interface knows what it is doing |
| 5056 |
|
| 5057 |
and then Convention (E) /= Convention_Assembler |
| 5058 |
then |
| 5059 |
Error_Msg_N |
| 5060 |
("pragma Import in Pure unit??", Import_Pragma (E)); |
| 5061 |
Error_Msg_NE |
| 5062 |
("\calls to & may be omitted (RM 10.2.1(18/3))??", |
| 5063 |
Import_Pragma (E), E); |
| 5064 |
end if; |
| 5065 |
|
| 5066 |
return True; |
| 5067 |
end Freeze_Profile; |
| 5068 |
|
| 5069 |
------------------------ |
| 5070 |
-- Freeze_Record_Type -- |
| 5071 |
------------------------ |
| 5072 |
|
| 5073 |
procedure Freeze_Record_Type (Rec : Entity_Id) is |
| 5074 |
ADC : Node_Id; |
| 5075 |
Comp : Entity_Id; |
| 5076 |
IR : Node_Id; |
| 5077 |
Prev : Entity_Id; |
| 5078 |
|
| 5079 |
Junk : Boolean; |
| 5080 |
pragma Warnings (Off, Junk); |
| 5081 |
|
| 5082 |
Aliased_Component : Boolean := False; |
| 5083 |
-- Set True if we find at least one component which is aliased. This |
| 5084 |
-- is used to prevent Implicit_Packing of the record, since packing |
| 5085 |
-- cannot modify the size of alignment of an aliased component. |
| 5086 |
|
| 5087 |
All_Elem_Components : Boolean := True; |
| 5088 |
-- True if all components are of a type whose underlying type is |
| 5089 |
-- elementary. |
| 5090 |
|
| 5091 |
All_Sized_Components : Boolean := True; |
| 5092 |
-- True if all components have a known RM_Size |
| 5093 |
|
| 5094 |
All_Storage_Unit_Components : Boolean := True; |
| 5095 |
-- True if all components have an RM_Size that is a multiple of the |
| 5096 |
-- storage unit. |
| 5097 |
|
| 5098 |
Elem_Component_Total_Esize : Uint := Uint_0; |
| 5099 |
-- Accumulates total Esize values of all elementary components. Used |
| 5100 |
-- for processing of Implicit_Packing. |
| 5101 |
|
| 5102 |
Final_Storage_Only : Boolean := True; |
| 5103 |
-- Used to compute the Finalize_Storage_Only flag |
| 5104 |
|
| 5105 |
Placed_Component : Boolean := False; |
| 5106 |
-- Set True if we find at least one component with a component |
| 5107 |
-- clause (used to warn about useless Bit_Order pragmas, and also |
| 5108 |
-- to detect cases where Implicit_Packing may have an effect). |
| 5109 |
|
| 5110 |
Relaxed_Finalization : Boolean := True; |
| 5111 |
-- Used to compute the Has_Relaxed_Finalization flag |
| 5112 |
|
| 5113 |
Sized_Component_Total_RM_Size : Uint := Uint_0; |
| 5114 |
-- Accumulates total RM_Size values of all sized components. Used |
| 5115 |
-- for processing of Implicit_Packing. |
| 5116 |
|
| 5117 |
Sized_Component_Total_Round_RM_Size : Uint := Uint_0; |
| 5118 |
-- Accumulates total RM_Size values of all sized components, rounded |
| 5119 |
-- individually to a multiple of the storage unit. |
| 5120 |
|
| 5121 |
SSO_ADC : Node_Id; |
| 5122 |
-- Scalar_Storage_Order attribute definition clause for the record |
| 5123 |
|
| 5124 |
SSO_ADC_Component : Boolean := False; |
| 5125 |
-- Set True if we find at least one component whose type has a |
| 5126 |
-- Scalar_Storage_Order attribute definition clause. |
| 5127 |
|
| 5128 |
Unplaced_Component : Boolean := False; |
| 5129 |
-- Set True if we find at least one component with no component |
| 5130 |
-- clause (used to warn about useless Pack pragmas). |
| 5131 |
|
| 5132 |
procedure Check_Itype (Typ : Entity_Id); |
| 5133 |
-- If the component subtype is an access to a constrained subtype of |
| 5134 |
-- an already frozen type, make the subtype frozen as well. It might |
| 5135 |
-- otherwise be frozen in the wrong scope, and a freeze node on |
| 5136 |
-- subtype has no effect. Similarly, if the component subtype is a |
| 5137 |
-- regular (not protected) access to subprogram, set the anonymous |
| 5138 |
-- subprogram type to frozen as well, to prevent an out-of-scope |
| 5139 |
-- freeze node at some eventual point of call. Protected operations |
| 5140 |
-- are handled elsewhere. |
| 5141 |
|
| 5142 |
procedure Freeze_Choices_In_Variant_Part (VP : Node_Id); |
| 5143 |
-- Make sure that all types mentioned in Discrete_Choices of the |
| 5144 |
-- variants referenceed by the Variant_Part VP are frozen. This is |
| 5145 |
-- a recursive routine to deal with nested variants. |
| 5146 |
|
| 5147 |
procedure Warn_If_Implicitly_Inherited_Aspects (Tag_Typ : Entity_Id); |
| 5148 |
-- Report a warning for Tag_Typ when it implicitly inherits the |
| 5149 |
-- First_Controlling_Parameter aspect but does not explicitly |
| 5150 |
-- specify it. |
| 5151 |
|
| 5152 |
----------------- |
| 5153 |
-- Check_Itype -- |
| 5154 |
----------------- |
| 5155 |
|
| 5156 |
procedure Check_Itype (Typ : Entity_Id) is |
| 5157 |
Desig : constant Entity_Id := Designated_Type (Typ); |
| 5158 |
|
| 5159 |
begin |
| 5160 |
if not Is_Frozen (Desig) |
| 5161 |
and then Is_Frozen (Base_Type (Desig)) |
| 5162 |
then |
| 5163 |
Set_Is_Frozen (Desig); |
| 5164 |
|
| 5165 |
-- In addition, add an Itype_Reference to ensure that the |
| 5166 |
-- access subtype is elaborated early enough. This cannot be |
| 5167 |
-- done if the subtype may depend on discriminants. |
| 5168 |
|
| 5169 |
if Ekind (Comp) = E_Component |
| 5170 |
and then Is_Itype (Etype (Comp)) |
| 5171 |
and then not Has_Discriminants (Rec) |
| 5172 |
then |
| 5173 |
IR := Make_Itype_Reference (Sloc (Comp)); |
| 5174 |
Set_Itype (IR, Desig); |
| 5175 |
Add_To_Result (IR); |
| 5176 |
end if; |
| 5177 |
|
| 5178 |
elsif Ekind (Typ) = E_Anonymous_Access_Subprogram_Type |
| 5179 |
and then Convention (Desig) /= Convention_Protected |
| 5180 |
then |
| 5181 |
Set_Is_Frozen (Desig); |
| 5182 |
Create_Extra_Formals (Desig); |
| 5183 |
end if; |
| 5184 |
end Check_Itype; |
| 5185 |
|
| 5186 |
------------------------------------ |
| 5187 |
-- Freeze_Choices_In_Variant_Part -- |
| 5188 |
------------------------------------ |
| 5189 |
|
| 5190 |
procedure Freeze_Choices_In_Variant_Part (VP : Node_Id) is |
| 5191 |
pragma Assert (Nkind (VP) = N_Variant_Part); |
| 5192 |
|
| 5193 |
Variant : Node_Id; |
| 5194 |
Choice : Node_Id; |
| 5195 |
CL : Node_Id; |
| 5196 |
|
| 5197 |
begin |
| 5198 |
-- Loop through variants |
| 5199 |
|
| 5200 |
Variant := First_Non_Pragma (Variants (VP)); |
| 5201 |
while Present (Variant) loop |
| 5202 |
|
| 5203 |
-- Loop through choices, checking that all types are frozen |
| 5204 |
|
| 5205 |
Choice := First_Non_Pragma (Discrete_Choices (Variant)); |
| 5206 |
while Present (Choice) loop |
| 5207 |
if Nkind (Choice) in N_Has_Etype |
| 5208 |
and then Present (Etype (Choice)) |
| 5209 |
then |
| 5210 |
Freeze_And_Append (Etype (Choice), N, Result); |
| 5211 |
end if; |
| 5212 |
|
| 5213 |
Next_Non_Pragma (Choice); |
| 5214 |
end loop; |
| 5215 |
|
| 5216 |
-- Check for nested variant part to process |
| 5217 |
|
| 5218 |
CL := Component_List (Variant); |
| 5219 |
|
| 5220 |
if not Null_Present (CL) then |
| 5221 |
if Present (Variant_Part (CL)) then |
| 5222 |
Freeze_Choices_In_Variant_Part (Variant_Part (CL)); |
| 5223 |
end if; |
| 5224 |
end if; |
| 5225 |
|
| 5226 |
Next_Non_Pragma (Variant); |
| 5227 |
end loop; |
| 5228 |
end Freeze_Choices_In_Variant_Part; |
| 5229 |
|
| 5230 |
------------------------------------------ |
| 5231 |
-- Warn_If_Implicitly_Inherited_Aspects -- |
| 5232 |
------------------------------------------ |
| 5233 |
|
| 5234 |
procedure Warn_If_Implicitly_Inherited_Aspects (Tag_Typ : Entity_Id) |
| 5235 |
is |
| 5236 |
function Has_First_Ctrl_Param_Aspect return Boolean; |
| 5237 |
-- Determines if Tag_Typ explicitly has the aspect/pragma |
| 5238 |
-- First_Controlling_Parameter. |
| 5239 |
|
| 5240 |
--------------------------------- |
| 5241 |
-- Has_First_Ctrl_Param_Aspect -- |
| 5242 |
--------------------------------- |
| 5243 |
|
| 5244 |
function Has_First_Ctrl_Param_Aspect return Boolean is |
| 5245 |
Decl_Nod : constant Node_Id := Parent (Tag_Typ); |
| 5246 |
Asp_Nod : Node_Id; |
| 5247 |
Nod : Node_Id; |
| 5248 |
Pragma_Arg : Node_Id; |
| 5249 |
Pragma_Ent : Entity_Id; |
| 5250 |
|
| 5251 |
begin |
| 5252 |
pragma Assert (Nkind (Decl_Nod) = N_Full_Type_Declaration); |
| 5253 |
|
| 5254 |
if Present (Aspect_Specifications (Decl_Nod)) then |
| 5255 |
Asp_Nod := First (Aspect_Specifications (Decl_Nod)); |
| 5256 |
while Present (Asp_Nod) loop |
| 5257 |
if Chars (Identifier (Asp_Nod)) |
| 5258 |
= Name_First_Controlling_Parameter |
| 5259 |
then |
| 5260 |
return True; |
| 5261 |
end if; |
| 5262 |
|
| 5263 |
Next (Asp_Nod); |
| 5264 |
end loop; |
| 5265 |
end if; |
| 5266 |
|
| 5267 |
-- Search for the occurrence of the pragma |
| 5268 |
|
| 5269 |
Nod := Next (Decl_Nod); |
| 5270 |
while Present (Nod) loop |
| 5271 |
if Nkind (Nod) = N_Pragma |
| 5272 |
and then Chars (Pragma_Identifier (Nod)) |
| 5273 |
= Name_First_Controlling_Parameter |
| 5274 |
and then Present (Pragma_Argument_Associations (Nod)) |
| 5275 |
then |
| 5276 |
Pragma_Arg := |
| 5277 |
Expression (First (Pragma_Argument_Associations (Nod))); |
| 5278 |
|
| 5279 |
if Nkind (Pragma_Arg) = N_Identifier |
| 5280 |
and then Present (Entity (Pragma_Arg)) |
| 5281 |
then |
| 5282 |
Pragma_Ent := Entity (Pragma_Arg); |
| 5283 |
|
| 5284 |
if Pragma_Ent = Tag_Typ |
| 5285 |
or else |
| 5286 |
(Is_Concurrent_Type (Pragma_Ent) |
| 5287 |
and then |
| 5288 |
Corresponding_Record_Type (Pragma_Ent) |
| 5289 |
= Tag_Typ) |
| 5290 |
then |
| 5291 |
return True; |
| 5292 |
end if; |
| 5293 |
end if; |
| 5294 |
end if; |
| 5295 |
|
| 5296 |
Next (Nod); |
| 5297 |
end loop; |
| 5298 |
|
| 5299 |
return False; |
| 5300 |
end Has_First_Ctrl_Param_Aspect; |
| 5301 |
|
| 5302 |
-- Local Variables |
| 5303 |
|
| 5304 |
Has_Aspect_First_Ctrl_Param : constant Boolean := |
| 5305 |
Has_First_Ctrl_Param_Aspect; |
| 5306 |
|
| 5307 |
-- Start of processing for Warn_Implicitly_Inherited_Aspects |
| 5308 |
|
| 5309 |
begin |
| 5310 |
-- Handle cases where reporting the warning is not needed |
| 5311 |
|
| 5312 |
if not Warn_On_Non_Dispatching_Primitives then |
| 5313 |
return; |
| 5314 |
|
| 5315 |
-- No check needed when this is the full view of a private type |
| 5316 |
-- declaration since the pragma/aspect must be placed and checked |
| 5317 |
-- in the partial view, and it is implicitly propagated to the |
| 5318 |
-- full view. |
| 5319 |
|
| 5320 |
elsif Has_Private_Declaration (Tag_Typ) |
| 5321 |
and then Is_Tagged_Type (Incomplete_Or_Partial_View (Tag_Typ)) |
| 5322 |
then |
| 5323 |
return; |
| 5324 |
|
| 5325 |
-- Similar case but applied to concurrent types |
| 5326 |
|
| 5327 |
elsif Is_Concurrent_Record_Type (Tag_Typ) |
| 5328 |
and then Has_Private_Declaration |
| 5329 |
(Corresponding_Concurrent_Type (Tag_Typ)) |
| 5330 |
and then Is_Tagged_Type |
| 5331 |
(Incomplete_Or_Partial_View |
| 5332 |
(Corresponding_Concurrent_Type (Tag_Typ))) |
| 5333 |
then |
| 5334 |
return; |
| 5335 |
end if; |
| 5336 |
|
| 5337 |
if Etype (Tag_Typ) /= Tag_Typ |
| 5338 |
and then Has_First_Controlling_Parameter_Aspect (Etype (Tag_Typ)) |
| 5339 |
then |
| 5340 |
-- The attribute was implicitly inherited |
| 5341 |
pragma Assert |
| 5342 |
(Has_First_Controlling_Parameter_Aspect (Tag_Typ)); |
| 5343 |
|
| 5344 |
-- No warning needed when the current tagged type is not |
| 5345 |
-- an interface type since by definition the aspect is |
| 5346 |
-- implicitly propagated from its parent type; the warning |
| 5347 |
-- is reported on interface types since it may not be so |
| 5348 |
-- clear when some implemented interface types have the |
| 5349 |
-- aspect and other interface types don't have it. For |
| 5350 |
-- interface types, we don't report the warning when the |
| 5351 |
-- interface type is an extension of a single interface |
| 5352 |
-- type (for similarity with the behavior with regular |
| 5353 |
-- tagged types). |
| 5354 |
|
| 5355 |
if not Has_Aspect_First_Ctrl_Param |
| 5356 |
and then Is_Interface (Tag_Typ) |
| 5357 |
and then not Is_Empty_Elmt_List (Interfaces (Tag_Typ)) |
| 5358 |
then |
| 5359 |
Error_Msg_N |
| 5360 |
("?_j?implicitly inherits aspect 'First_'Controlling_'" |
| 5361 |
& "Parameter!", Tag_Typ); |
| 5362 |
Error_Msg_NE |
| 5363 |
("\?_j?from & and must be confirmed explicitly!", |
| 5364 |
Tag_Typ, Etype (Tag_Typ)); |
| 5365 |
end if; |
| 5366 |
|
| 5367 |
elsif Present (Interfaces (Tag_Typ)) |
| 5368 |
and then not Is_Empty_Elmt_List (Interfaces (Tag_Typ)) |
| 5369 |
then |
| 5370 |
-- To maintain consistency with the behavior when the aspect |
| 5371 |
-- is implicitly inherited from its parent type, we do not |
| 5372 |
-- report a warning for concurrent record types that implement |
| 5373 |
-- a single interface type. By definition, the aspect is |
| 5374 |
-- propagated from that interface type as if it were the parent |
| 5375 |
-- type. For example: |
| 5376 |
|
| 5377 |
-- type Iface is interface with First_Controlling_Parameter; |
| 5378 |
-- task type T is new Iface with ... |
| 5379 |
|
| 5380 |
if Is_Concurrent_Record_Type (Tag_Typ) |
| 5381 |
and then No (Next_Elmt (First_Elmt (Interfaces (Tag_Typ)))) |
| 5382 |
then |
| 5383 |
null; |
| 5384 |
|
| 5385 |
else |
| 5386 |
declare |
| 5387 |
Elmt : Elmt_Id := First_Elmt (Interfaces (Tag_Typ)); |
| 5388 |
Iface : Entity_Id; |
| 5389 |
|
| 5390 |
begin |
| 5391 |
while Present (Elmt) loop |
| 5392 |
Iface := Node (Elmt); |
| 5393 |
pragma Assert (Present (Iface)); |
| 5394 |
|
| 5395 |
if Has_First_Controlling_Parameter_Aspect (Iface) |
| 5396 |
and then not Has_Aspect_First_Ctrl_Param |
| 5397 |
then |
| 5398 |
pragma Assert |
| 5399 |
(Has_First_Controlling_Parameter_Aspect |
| 5400 |
(Tag_Typ)); |
| 5401 |
Error_Msg_N |
| 5402 |
("?_j?implicitly inherits aspect 'First_'" |
| 5403 |
& "Controlling_'Parameter", Tag_Typ); |
| 5404 |
Error_Msg_NE |
| 5405 |
("\?_j?from & and must be confirmed explicitly!", |
| 5406 |
Tag_Typ, Iface); |
| 5407 |
exit; |
| 5408 |
end if; |
| 5409 |
|
| 5410 |
Next_Elmt (Elmt); |
| 5411 |
end loop; |
| 5412 |
end; |
| 5413 |
end if; |
| 5414 |
end if; |
| 5415 |
end Warn_If_Implicitly_Inherited_Aspects; |
| 5416 |
|
| 5417 |
-- Start of processing for Freeze_Record_Type |
| 5418 |
|
| 5419 |
begin |
| 5420 |
-- Freeze components and embedded subtypes |
| 5421 |
|
| 5422 |
Comp := First_Entity (Rec); |
| 5423 |
Prev := Empty; |
| 5424 |
while Present (Comp) loop |
| 5425 |
if Is_Aliased (Comp) then |
| 5426 |
Aliased_Component := True; |
| 5427 |
end if; |
| 5428 |
|
| 5429 |
-- Handle the component and discriminant case |
| 5430 |
|
| 5431 |
if Ekind (Comp) in E_Component | E_Discriminant then |
| 5432 |
declare |
| 5433 |
CC : constant Node_Id := Component_Clause (Comp); |
| 5434 |
|
| 5435 |
begin |
| 5436 |
-- Freezing a record type freezes the type of each of its |
| 5437 |
-- components. However, if the type of the component is |
| 5438 |
-- part of this record, we do not want or need a separate |
| 5439 |
-- Freeze_Node. Note that Is_Itype is wrong because that's |
| 5440 |
-- also set in private type cases. We also can't check for |
| 5441 |
-- the Scope being exactly Rec because of private types and |
| 5442 |
-- record extensions. |
| 5443 |
|
| 5444 |
if Is_Itype (Etype (Comp)) |
| 5445 |
and then Is_Record_Type (Underlying_Type |
| 5446 |
(Scope (Etype (Comp)))) |
| 5447 |
then |
| 5448 |
Undelay_Type (Etype (Comp)); |
| 5449 |
end if; |
| 5450 |
|
| 5451 |
Freeze_And_Append (Etype (Comp), N, Result); |
| 5452 |
|
| 5453 |
-- Warn for pragma Pack overriding foreign convention |
| 5454 |
|
| 5455 |
if Has_Foreign_Convention (Etype (Comp)) |
| 5456 |
and then Has_Pragma_Pack (Rec) |
| 5457 |
|
| 5458 |
-- Don't warn for aliased components, since override |
| 5459 |
-- cannot happen in that case. |
| 5460 |
|
| 5461 |
and then not Is_Aliased (Comp) |
| 5462 |
then |
| 5463 |
declare |
| 5464 |
CN : constant Name_Id := |
| 5465 |
Get_Convention_Name (Convention (Etype (Comp))); |
| 5466 |
PP : constant Node_Id := |
| 5467 |
Get_Pragma (Rec, Pragma_Pack); |
| 5468 |
begin |
| 5469 |
if Present (PP) then |
| 5470 |
Error_Msg_Name_1 := CN; |
| 5471 |
Error_Msg_Sloc := Sloc (Comp); |
| 5472 |
Error_Msg_N |
| 5473 |
("pragma Pack affects convention % component#??", |
| 5474 |
PP); |
| 5475 |
Error_Msg_Name_1 := CN; |
| 5476 |
Error_Msg_NE |
| 5477 |
("\component & may not have % compatible " |
| 5478 |
& "representation??", PP, Comp); |
| 5479 |
end if; |
| 5480 |
end; |
| 5481 |
end if; |
| 5482 |
|
| 5483 |
-- Check for error of component clause given for variable |
| 5484 |
-- sized type. We have to delay this test till this point, |
| 5485 |
-- since the component type has to be frozen for us to know |
| 5486 |
-- if it is variable length. |
| 5487 |
|
| 5488 |
if Present (CC) then |
| 5489 |
Placed_Component := True; |
| 5490 |
|
| 5491 |
-- We omit this test in a generic context, it will be |
| 5492 |
-- applied at instantiation time. |
| 5493 |
|
| 5494 |
if Inside_A_Generic then |
| 5495 |
null; |
| 5496 |
|
| 5497 |
-- Also omit this test in CodePeer mode, since we do not |
| 5498 |
-- have sufficient info on size and rep clauses. |
| 5499 |
|
| 5500 |
elsif CodePeer_Mode then |
| 5501 |
null; |
| 5502 |
|
| 5503 |
-- Do the check |
| 5504 |
|
| 5505 |
elsif not |
| 5506 |
Size_Known_At_Compile_Time |
| 5507 |
(Underlying_Type (Etype (Comp))) |
| 5508 |
then |
| 5509 |
Error_Msg_N |
| 5510 |
("component clause not allowed for variable " & |
| 5511 |
"length component", CC); |
| 5512 |
end if; |
| 5513 |
|
| 5514 |
else |
| 5515 |
Unplaced_Component := True; |
| 5516 |
end if; |
| 5517 |
|
| 5518 |
-- Case of component requires byte alignment |
| 5519 |
|
| 5520 |
if Must_Be_On_Byte_Boundary (Etype (Comp)) then |
| 5521 |
|
| 5522 |
-- Set the enclosing record to also require byte align |
| 5523 |
|
| 5524 |
Set_Must_Be_On_Byte_Boundary (Rec); |
| 5525 |
|
| 5526 |
-- Check for component clause that is inconsistent with |
| 5527 |
-- the required byte boundary alignment. |
| 5528 |
|
| 5529 |
if Present (CC) |
| 5530 |
and then Normalized_First_Bit (Comp) mod |
| 5531 |
System_Storage_Unit /= 0 |
| 5532 |
then |
| 5533 |
Error_Msg_N |
| 5534 |
("component & must be byte aligned", |
| 5535 |
Component_Name (Component_Clause (Comp))); |
| 5536 |
end if; |
| 5537 |
end if; |
| 5538 |
end; |
| 5539 |
end if; |
| 5540 |
|
| 5541 |
-- Gather data for possible Implicit_Packing later. Note that at |
| 5542 |
-- this stage we might be dealing with a real component, or with |
| 5543 |
-- an implicit subtype declaration. |
| 5544 |
|
| 5545 |
if Known_Static_RM_Size (Etype (Comp)) then |
| 5546 |
declare |
| 5547 |
Comp_Type : constant Entity_Id := Etype (Comp); |
| 5548 |
Comp_Size : constant Uint := RM_Size (Comp_Type); |
| 5549 |
SSU : constant Int := Ttypes.System_Storage_Unit; |
| 5550 |
|
| 5551 |
begin |
| 5552 |
Sized_Component_Total_RM_Size := |
| 5553 |
Sized_Component_Total_RM_Size + Comp_Size; |
| 5554 |
|
| 5555 |
Sized_Component_Total_Round_RM_Size := |
| 5556 |
Sized_Component_Total_Round_RM_Size + |
| 5557 |
(Comp_Size + SSU - 1) / SSU * SSU; |
| 5558 |
|
| 5559 |
if Present (Underlying_Type (Comp_Type)) |
| 5560 |
and then Is_Elementary_Type (Underlying_Type (Comp_Type)) |
| 5561 |
then |
| 5562 |
Elem_Component_Total_Esize := |
| 5563 |
Elem_Component_Total_Esize + Esize (Comp_Type); |
| 5564 |
else |
| 5565 |
All_Elem_Components := False; |
| 5566 |
|
| 5567 |
if Comp_Size mod SSU /= 0 then |
| 5568 |
All_Storage_Unit_Components := False; |
| 5569 |
end if; |
| 5570 |
end if; |
| 5571 |
end; |
| 5572 |
else |
| 5573 |
All_Sized_Components := False; |
| 5574 |
end if; |
| 5575 |
|
| 5576 |
-- If the component is an Itype with Delayed_Freeze and is either |
| 5577 |
-- a record or array subtype and its base type has not yet been |
| 5578 |
-- frozen, we must remove this from the entity list of this record |
| 5579 |
-- and put it on the entity list of the scope of its base type. |
| 5580 |
-- Note that we know that this is not the type of a component |
| 5581 |
-- since we cleared Has_Delayed_Freeze for it in the previous |
| 5582 |
-- loop. Thus this must be the Designated_Type of an access type, |
| 5583 |
-- which is the type of a component. |
| 5584 |
|
| 5585 |
if Is_Itype (Comp) |
| 5586 |
and then Is_Type (Scope (Comp)) |
| 5587 |
and then Is_Composite_Type (Comp) |
| 5588 |
and then Base_Type (Comp) /= Comp |
| 5589 |
and then Has_Delayed_Freeze (Comp) |
| 5590 |
and then not Is_Frozen (Base_Type (Comp)) |
| 5591 |
then |
| 5592 |
declare |
| 5593 |
Will_Be_Frozen : Boolean := False; |
| 5594 |
S : Entity_Id; |
| 5595 |
|
| 5596 |
begin |
| 5597 |
-- We have a difficult case to handle here. Suppose Rec is |
| 5598 |
-- subtype being defined in a subprogram that's created as |
| 5599 |
-- part of the freezing of Rec'Base. In that case, we know |
| 5600 |
-- that Comp'Base must have already been frozen by the time |
| 5601 |
-- we get to elaborate this because Gigi doesn't elaborate |
| 5602 |
-- any bodies until it has elaborated all of the declarative |
| 5603 |
-- part. But Is_Frozen will not be set at this point because |
| 5604 |
-- we are processing code in lexical order. |
| 5605 |
|
| 5606 |
-- We detect this case by going up the Scope chain of Rec |
| 5607 |
-- and seeing if we have a subprogram scope before reaching |
| 5608 |
-- the top of the scope chain or that of Comp'Base. If we |
| 5609 |
-- do, then mark that Comp'Base will actually be frozen. If |
| 5610 |
-- so, we merely undelay it. |
| 5611 |
|
| 5612 |
S := Scope (Rec); |
| 5613 |
while Present (S) loop |
| 5614 |
if Is_Subprogram (S) then |
| 5615 |
Will_Be_Frozen := True; |
| 5616 |
exit; |
| 5617 |
elsif S = Scope (Base_Type (Comp)) then |
| 5618 |
exit; |
| 5619 |
end if; |
| 5620 |
|
| 5621 |
S := Scope (S); |
| 5622 |
end loop; |
| 5623 |
|
| 5624 |
if Will_Be_Frozen then |
| 5625 |
Undelay_Type (Comp); |
| 5626 |
|
| 5627 |
else |
| 5628 |
if Present (Prev) then |
| 5629 |
Link_Entities (Prev, Next_Entity (Comp)); |
| 5630 |
else |
| 5631 |
Set_First_Entity (Rec, Next_Entity (Comp)); |
| 5632 |
end if; |
| 5633 |
|
| 5634 |
-- Insert in entity list of scope of base type (which |
| 5635 |
-- must be an enclosing scope, because still unfrozen). |
| 5636 |
|
| 5637 |
Append_Entity (Comp, Scope (Base_Type (Comp))); |
| 5638 |
end if; |
| 5639 |
end; |
| 5640 |
|
| 5641 |
-- If the component is an access type with an allocator as default |
| 5642 |
-- value, the designated type will be frozen by the corresponding |
| 5643 |
-- expression in init_proc. In order to place the freeze node for |
| 5644 |
-- the designated type before that for the current record type, |
| 5645 |
-- freeze it now. |
| 5646 |
|
| 5647 |
-- Same process if the component is an array of access types, |
| 5648 |
-- initialized with an aggregate. If the designated type is |
| 5649 |
-- private, it cannot contain allocators, and it is premature |
| 5650 |
-- to freeze the type, so we check for this as well. |
| 5651 |
|
| 5652 |
elsif Is_Access_Type (Etype (Comp)) |
| 5653 |
and then Present (Parent (Comp)) |
| 5654 |
and then |
| 5655 |
Nkind (Parent (Comp)) |
| 5656 |
in N_Component_Declaration | N_Discriminant_Specification |
| 5657 |
and then Present (Expression (Parent (Comp))) |
| 5658 |
then |
| 5659 |
declare |
| 5660 |
Alloc : constant Node_Id := |
| 5661 |
Unqualify (Expression (Parent (Comp))); |
| 5662 |
|
| 5663 |
begin |
| 5664 |
if Nkind (Alloc) = N_Allocator then |
| 5665 |
|
| 5666 |
-- If component is pointer to a class-wide type, freeze |
| 5667 |
-- the specific type in the expression being allocated. |
| 5668 |
-- The expression may be a subtype indication, in which |
| 5669 |
-- case freeze the subtype mark. |
| 5670 |
|
| 5671 |
if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) |
| 5672 |
then |
| 5673 |
if Is_Entity_Name (Expression (Alloc)) then |
| 5674 |
Freeze_And_Append |
| 5675 |
(Entity (Expression (Alloc)), N, Result); |
| 5676 |
|
| 5677 |
elsif Nkind (Expression (Alloc)) = N_Subtype_Indication |
| 5678 |
then |
| 5679 |
Freeze_And_Append |
| 5680 |
(Entity (Subtype_Mark (Expression (Alloc))), |
| 5681 |
N, Result); |
| 5682 |
end if; |
| 5683 |
elsif Is_Itype (Designated_Type (Etype (Comp))) then |
| 5684 |
Check_Itype (Etype (Comp)); |
| 5685 |
else |
| 5686 |
Freeze_And_Append |
| 5687 |
(Designated_Type (Etype (Comp)), N, Result); |
| 5688 |
end if; |
| 5689 |
end if; |
| 5690 |
end; |
| 5691 |
elsif Is_Access_Type (Etype (Comp)) |
| 5692 |
and then Is_Itype (Designated_Type (Etype (Comp))) |
| 5693 |
then |
| 5694 |
Check_Itype (Etype (Comp)); |
| 5695 |
|
| 5696 |
-- Freeze the designated type when initializing a component with |
| 5697 |
-- an aggregate in case the aggregate contains allocators. |
| 5698 |
|
| 5699 |
-- type T is ...; |
| 5700 |
-- type T_Ptr is access all T; |
| 5701 |
-- type T_Array is array ... of T_Ptr; |
| 5702 |
|
| 5703 |
-- type Rec is record |
| 5704 |
-- Comp : T_Array := (others => ...); |
| 5705 |
-- end record; |
| 5706 |
|
| 5707 |
elsif Is_Array_Type (Etype (Comp)) |
| 5708 |
and then Is_Access_Type (Component_Type (Etype (Comp))) |
| 5709 |
then |
| 5710 |
declare |
| 5711 |
Comp_Par : constant Node_Id := Parent (Comp); |
| 5712 |
Desig_Typ : constant Entity_Id := |
| 5713 |
Designated_Type |
| 5714 |
(Component_Type (Etype (Comp))); |
| 5715 |
|
| 5716 |
begin |
| 5717 |
-- The only case when this sort of freezing is not done is |
| 5718 |
-- when the designated type is class-wide and the root type |
| 5719 |
-- is the record owning the component. This scenario results |
| 5720 |
-- in a circularity because the class-wide type requires |
| 5721 |
-- primitives that have not been created yet as the root |
| 5722 |
-- type is in the process of being frozen. |
| 5723 |
|
| 5724 |
-- type Rec is tagged; |
| 5725 |
-- type Rec_Ptr is access all Rec'Class; |
| 5726 |
-- type Rec_Array is array ... of Rec_Ptr; |
| 5727 |
|
| 5728 |
-- type Rec is record |
| 5729 |
-- Comp : Rec_Array := (others => ...); |
| 5730 |
-- end record; |
| 5731 |
|
| 5732 |
if Is_Class_Wide_Type (Desig_Typ) |
| 5733 |
and then Root_Type (Desig_Typ) = Rec |
| 5734 |
then |
| 5735 |
null; |
| 5736 |
|
| 5737 |
elsif Is_Fully_Defined (Desig_Typ) |
| 5738 |
and then Present (Comp_Par) |
| 5739 |
and then Nkind (Comp_Par) = N_Component_Declaration |
| 5740 |
and then Present (Expression (Comp_Par)) |
| 5741 |
and then Nkind (Expression (Comp_Par)) = N_Aggregate |
| 5742 |
then |
| 5743 |
Freeze_And_Append (Desig_Typ, N, Result); |
| 5744 |
end if; |
| 5745 |
end; |
| 5746 |
end if; |
| 5747 |
|
| 5748 |
Prev := Comp; |
| 5749 |
Next_Entity (Comp); |
| 5750 |
end loop; |
| 5751 |
|
| 5752 |
SSO_ADC := |
| 5753 |
Get_Attribute_Definition_Clause |
| 5754 |
(Rec, Attribute_Scalar_Storage_Order); |
| 5755 |
|
| 5756 |
-- If the record type has Complex_Representation, then it is treated |
| 5757 |
-- as a scalar in the back end so the storage order is irrelevant. |
| 5758 |
|
| 5759 |
if Has_Complex_Representation (Rec) then |
| 5760 |
if Present (SSO_ADC) then |
| 5761 |
Error_Msg_N |
| 5762 |
("??storage order has no effect with Complex_Representation", |
| 5763 |
SSO_ADC); |
| 5764 |
end if; |
| 5765 |
|
| 5766 |
else |
| 5767 |
-- Deal with default setting of reverse storage order |
| 5768 |
|
| 5769 |
Set_SSO_From_Default (Rec); |
| 5770 |
|
| 5771 |
-- Check consistent attribute setting on component types |
| 5772 |
|
| 5773 |
declare |
| 5774 |
Comp_ADC_Present : Boolean; |
| 5775 |
begin |
| 5776 |
Comp := First_Component (Rec); |
| 5777 |
while Present (Comp) loop |
| 5778 |
Check_Component_Storage_Order |
| 5779 |
(Encl_Type => Rec, |
| 5780 |
Comp => Comp, |
| 5781 |
ADC => SSO_ADC, |
| 5782 |
Comp_ADC_Present => Comp_ADC_Present); |
| 5783 |
SSO_ADC_Component := SSO_ADC_Component or Comp_ADC_Present; |
| 5784 |
Next_Component (Comp); |
| 5785 |
end loop; |
| 5786 |
end; |
| 5787 |
|
| 5788 |
-- Now deal with reverse storage order/bit order issues |
| 5789 |
|
| 5790 |
if Present (SSO_ADC) then |
| 5791 |
|
| 5792 |
-- Check compatibility of Scalar_Storage_Order with Bit_Order, |
| 5793 |
-- if the former is specified. |
| 5794 |
|
| 5795 |
if Reverse_Bit_Order (Rec) /= Reverse_Storage_Order (Rec) then |
| 5796 |
|
| 5797 |
-- Note: report error on Rec, not on SSO_ADC, as ADC may |
| 5798 |
-- apply to some ancestor type. |
| 5799 |
|
| 5800 |
Error_Msg_Sloc := Sloc (SSO_ADC); |
| 5801 |
Error_Msg_N |
| 5802 |
("scalar storage order for& specified# inconsistent with " |
| 5803 |
& "bit order", Rec); |
| 5804 |
end if; |
| 5805 |
|
| 5806 |
-- Warn if there is a Scalar_Storage_Order attribute definition |
| 5807 |
-- clause but no component clause, no component that itself has |
| 5808 |
-- such an attribute definition, and no pragma Pack. |
| 5809 |
|
| 5810 |
if not (Placed_Component |
| 5811 |
or else |
| 5812 |
SSO_ADC_Component |
| 5813 |
or else |
| 5814 |
Is_Packed (Rec)) |
| 5815 |
then |
| 5816 |
Error_Msg_N |
| 5817 |
("??scalar storage order specified but no component " |
| 5818 |
& "clause", SSO_ADC); |
| 5819 |
end if; |
| 5820 |
end if; |
| 5821 |
end if; |
| 5822 |
|
| 5823 |
-- Deal with Bit_Order aspect |
| 5824 |
|
| 5825 |
ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order); |
| 5826 |
|
| 5827 |
if Present (ADC) and then Base_Type (Rec) = Rec then |
| 5828 |
if not (Placed_Component |
| 5829 |
or else Present (SSO_ADC) |
| 5830 |
or else Is_Packed (Rec)) |
| 5831 |
then |
| 5832 |
-- Warn if clause has no effect when no component clause is |
| 5833 |
-- present, but suppress warning if the Bit_Order is required |
| 5834 |
-- due to the presence of a Scalar_Storage_Order attribute. |
| 5835 |
|
| 5836 |
Error_Msg_N |
| 5837 |
("??bit order specification has no effect", ADC); |
| 5838 |
Error_Msg_N |
| 5839 |
("\??since no component clauses were specified", ADC); |
| 5840 |
|
| 5841 |
-- Here is where we do the processing to adjust component clauses |
| 5842 |
-- for reversed bit order, when not using reverse SSO. If an error |
| 5843 |
-- has been reported on Rec already (such as SSO incompatible with |
| 5844 |
-- bit order), don't bother adjusting as this may generate extra |
| 5845 |
-- noise. |
| 5846 |
|
| 5847 |
elsif Reverse_Bit_Order (Rec) |
| 5848 |
and then not Reverse_Storage_Order (Rec) |
| 5849 |
and then not Error_Posted (Rec) |
| 5850 |
then |
| 5851 |
Adjust_Record_For_Reverse_Bit_Order (Rec); |
| 5852 |
|
| 5853 |
-- Case where we have both an explicit Bit_Order and the same |
| 5854 |
-- Scalar_Storage_Order: leave record untouched, the back-end |
| 5855 |
-- will take care of required layout conversions. |
| 5856 |
|
| 5857 |
else |
| 5858 |
null; |
| 5859 |
|
| 5860 |
end if; |
| 5861 |
end if; |
| 5862 |
|
| 5863 |
-- Check for useless pragma Pack when all components placed. We only |
| 5864 |
-- do this check for record types, not subtypes, since a subtype may |
| 5865 |
-- have all its components placed, and it still makes perfectly good |
| 5866 |
-- sense to pack other subtypes or the parent type. We do not give |
| 5867 |
-- this warning if Optimize_Alignment is set to Space, since the |
| 5868 |
-- pragma Pack does have an effect in this case (it always resets |
| 5869 |
-- the alignment to one). |
| 5870 |
|
| 5871 |
if Ekind (Rec) = E_Record_Type |
| 5872 |
and then Is_Packed (Rec) |
| 5873 |
and then not Unplaced_Component |
| 5874 |
and then Optimize_Alignment /= 'S' |
| 5875 |
then |
| 5876 |
-- Reset packed status. Probably not necessary, but we do it so |
| 5877 |
-- that there is no chance of the back end doing something strange |
| 5878 |
-- with this redundant indication of packing. |
| 5879 |
|
| 5880 |
Set_Is_Packed (Rec, False); |
| 5881 |
|
| 5882 |
-- Give warning if redundant constructs warnings on |
| 5883 |
|
| 5884 |
if Warn_On_Redundant_Constructs then |
| 5885 |
Error_Msg_N -- CODEFIX |
| 5886 |
("?r?pragma Pack has no effect, no unplaced components", |
| 5887 |
Get_Rep_Pragma (Rec, Name_Pack)); |
| 5888 |
end if; |
| 5889 |
end if; |
| 5890 |
|
| 5891 |
-- If this is the record corresponding to a remote type, freeze the |
| 5892 |
-- remote type here since that is what we are semantically freezing. |
| 5893 |
-- This prevents the freeze node for that type in an inner scope. |
| 5894 |
|
| 5895 |
if Ekind (Rec) = E_Record_Type then |
| 5896 |
if Present (Corresponding_Remote_Type (Rec)) then |
| 5897 |
Freeze_And_Append (Corresponding_Remote_Type (Rec), N, Result); |
| 5898 |
end if; |
| 5899 |
|
| 5900 |
-- Check for tasks, protected and controlled components, unchecked |
| 5901 |
-- unions, and type invariants. |
| 5902 |
|
| 5903 |
Comp := First_Component (Rec); |
| 5904 |
while Present (Comp) loop |
| 5905 |
Propagate_Concurrent_Flags (Rec, Etype (Comp)); |
| 5906 |
|
| 5907 |
-- Do not set Has_Controlled_Component on a class-wide |
| 5908 |
-- equivalent type. See Make_CW_Equivalent_Type. |
| 5909 |
|
| 5910 |
if not Is_Class_Wide_Equivalent_Type (Rec) |
| 5911 |
and then |
| 5912 |
(Has_Controlled_Component (Etype (Comp)) |
| 5913 |
or else |
| 5914 |
(Chars (Comp) /= Name_uParent |
| 5915 |
and then Is_Controlled (Etype (Comp))) |
| 5916 |
or else |
| 5917 |
(Is_Protected_Type (Etype (Comp)) |
| 5918 |
and then |
| 5919 |
Present (Corresponding_Record_Type (Etype (Comp))) |
| 5920 |
and then |
| 5921 |
Has_Controlled_Component |
| 5922 |
(Corresponding_Record_Type (Etype (Comp))))) |
| 5923 |
then |
| 5924 |
Set_Has_Controlled_Component (Rec); |
| 5925 |
Final_Storage_Only := |
| 5926 |
Final_Storage_Only |
| 5927 |
and then Finalize_Storage_Only (Etype (Comp)); |
| 5928 |
Relaxed_Finalization := |
| 5929 |
Relaxed_Finalization |
| 5930 |
and then Has_Relaxed_Finalization (Etype (Comp)); |
| 5931 |
end if; |
| 5932 |
|
| 5933 |
if Has_Unchecked_Union (Etype (Comp)) then |
| 5934 |
Set_Has_Unchecked_Union (Rec); |
| 5935 |
end if; |
| 5936 |
|
| 5937 |
-- The record type requires its own invariant procedure in |
| 5938 |
-- order to verify the invariant of each individual component. |
| 5939 |
-- Do not consider internal components such as _parent because |
| 5940 |
-- parent class-wide invariants are always inherited. |
| 5941 |
-- In GNATprove mode, the component invariants are checked by |
| 5942 |
-- other means. They should not be added to the record type |
| 5943 |
-- invariant procedure, so that the procedure can be used to |
| 5944 |
-- check the recordy type invariants if any. |
| 5945 |
|
| 5946 |
if Comes_From_Source (Comp) |
| 5947 |
and then Has_Invariants (Etype (Comp)) |
| 5948 |
and then not GNATprove_Mode |
| 5949 |
then |
| 5950 |
Set_Has_Own_Invariants (Rec); |
| 5951 |
end if; |
| 5952 |
|
| 5953 |
-- Scan component declaration for likely misuses of current |
| 5954 |
-- instance, either in a constraint or a default expression. |
| 5955 |
|
| 5956 |
if Has_Per_Object_Constraint (Comp) then |
| 5957 |
Check_Current_Instance (Parent (Comp)); |
| 5958 |
end if; |
| 5959 |
|
| 5960 |
Next_Component (Comp); |
| 5961 |
end loop; |
| 5962 |
|
| 5963 |
-- For a type that is not directly controlled but has controlled |
| 5964 |
-- components, Finalize_Storage_Only is set if all the controlled |
| 5965 |
-- components are Finalize_Storage_Only. The same processing is |
| 5966 |
-- appled to Has_Relaxed_Finalization. |
| 5967 |
|
| 5968 |
if not Is_Controlled (Rec) and then Has_Controlled_Component (Rec) |
| 5969 |
then |
| 5970 |
Set_Finalize_Storage_Only (Rec, Final_Storage_Only); |
| 5971 |
Set_Has_Relaxed_Finalization (Rec, Relaxed_Finalization); |
| 5972 |
end if; |
| 5973 |
end if; |
| 5974 |
|
| 5975 |
-- Enforce the restriction that access attributes with a current |
| 5976 |
-- instance prefix can only apply to limited types. This comment |
| 5977 |
-- is floating here, but does not seem to belong here??? |
| 5978 |
|
| 5979 |
-- Set component alignment if not otherwise already set |
| 5980 |
|
| 5981 |
Set_Component_Alignment_If_Not_Set (Rec); |
| 5982 |
|
| 5983 |
-- For first subtypes, check if there are any fixed-point fields with |
| 5984 |
-- component clauses, where we must check the size. This is not done |
| 5985 |
-- till the freeze point since for fixed-point types, we do not know |
| 5986 |
-- the size until the type is frozen. Similar processing applies to |
| 5987 |
-- bit-packed arrays. |
| 5988 |
|
| 5989 |
if Is_First_Subtype (Rec) then |
| 5990 |
Comp := First_Component (Rec); |
| 5991 |
while Present (Comp) loop |
| 5992 |
if Present (Component_Clause (Comp)) |
| 5993 |
and then (Is_Fixed_Point_Type (Etype (Comp)) |
| 5994 |
or else Is_Bit_Packed_Array (Etype (Comp))) |
| 5995 |
then |
| 5996 |
Check_Size |
| 5997 |
(Component_Name (Component_Clause (Comp)), |
| 5998 |
Etype (Comp), |
| 5999 |
Esize (Comp), |
| 6000 |
Junk); |
| 6001 |
end if; |
| 6002 |
|
| 6003 |
Next_Component (Comp); |
| 6004 |
end loop; |
| 6005 |
end if; |
| 6006 |
|
| 6007 |
-- See if Size is too small as is (and implicit packing might help) |
| 6008 |
|
| 6009 |
if not Is_Packed (Rec) |
| 6010 |
|
| 6011 |
-- No implicit packing if even one component is explicitly placed |
| 6012 |
|
| 6013 |
and then not Placed_Component |
| 6014 |
|
| 6015 |
-- Or even one component is aliased |
| 6016 |
|
| 6017 |
and then not Aliased_Component |
| 6018 |
|
| 6019 |
-- Must have size clause and all sized components |
| 6020 |
|
| 6021 |
and then Has_Size_Clause (Rec) |
| 6022 |
and then All_Sized_Components |
| 6023 |
|
| 6024 |
-- Do not try implicit packing on records with discriminants, too |
| 6025 |
-- complicated, especially in the variant record case. |
| 6026 |
|
| 6027 |
and then not Has_Discriminants (Rec) |
| 6028 |
|
| 6029 |
-- We want to implicitly pack if the specified size of the record |
| 6030 |
-- is less than the sum of the object sizes (no point in packing |
| 6031 |
-- if this is not the case), if we can compute it, i.e. if we have |
| 6032 |
-- only elementary components. Otherwise, we have at least one |
| 6033 |
-- composite component and we want to implicitly pack only if bit |
| 6034 |
-- packing is required for it, as we are sure in this case that |
| 6035 |
-- the back end cannot do the expected layout without packing. |
| 6036 |
|
| 6037 |
and then |
| 6038 |
((All_Elem_Components |
| 6039 |
and then RM_Size (Rec) < Elem_Component_Total_Esize) |
| 6040 |
or else |
| 6041 |
(not All_Elem_Components |
| 6042 |
and then not All_Storage_Unit_Components |
| 6043 |
and then RM_Size (Rec) < Sized_Component_Total_Round_RM_Size)) |
| 6044 |
|
| 6045 |
-- And the total RM size cannot be greater than the specified size |
| 6046 |
-- since otherwise packing will not get us where we have to be. |
| 6047 |
|
| 6048 |
and then Sized_Component_Total_RM_Size <= RM_Size (Rec) |
| 6049 |
|
| 6050 |
-- Never do implicit packing in CodePeer or SPARK modes since |
| 6051 |
-- we don't do any packing in these modes, since this generates |
| 6052 |
-- over-complex code that confuses static analysis, and in |
| 6053 |
-- general, neither CodePeer not GNATprove care about the |
| 6054 |
-- internal representation of objects. |
| 6055 |
|
| 6056 |
and then not (CodePeer_Mode or GNATprove_Mode) |
| 6057 |
then |
| 6058 |
-- If implicit packing enabled, do it |
| 6059 |
|
| 6060 |
if Implicit_Packing then |
| 6061 |
Set_Is_Packed (Rec); |
| 6062 |
|
| 6063 |
-- Otherwise flag the size clause |
| 6064 |
|
| 6065 |
else |
| 6066 |
declare |
| 6067 |
Sz : constant Node_Id := Size_Clause (Rec); |
| 6068 |
begin |
| 6069 |
Error_Msg_NE -- CODEFIX |
| 6070 |
("size given for& too small", Sz, Rec); |
| 6071 |
Error_Msg_N -- CODEFIX |
| 6072 |
("\use explicit pragma Pack " |
| 6073 |
& "or use pragma Implicit_Packing", Sz); |
| 6074 |
end; |
| 6075 |
end if; |
| 6076 |
end if; |
| 6077 |
|
| 6078 |
-- Make sure that if we have an iterator aspect, then we have |
| 6079 |
-- either Constant_Indexing or Variable_Indexing. |
| 6080 |
|
| 6081 |
declare |
| 6082 |
Iterator_Aspect : Node_Id; |
| 6083 |
|
| 6084 |
begin |
| 6085 |
Iterator_Aspect := Find_Aspect (Rec, Aspect_Iterator_Element); |
| 6086 |
|
| 6087 |
if No (Iterator_Aspect) then |
| 6088 |
Iterator_Aspect := Find_Aspect (Rec, Aspect_Default_Iterator); |
| 6089 |
end if; |
| 6090 |
|
| 6091 |
if Present (Iterator_Aspect) then |
| 6092 |
if Has_Aspect (Rec, Aspect_Constant_Indexing) |
| 6093 |
or else |
| 6094 |
Has_Aspect (Rec, Aspect_Variable_Indexing) |
| 6095 |
then |
| 6096 |
null; |
| 6097 |
else |
| 6098 |
if Get_Aspect_Id (Iterator_Aspect) = Aspect_Iterator_Element |
| 6099 |
then |
| 6100 |
Error_Msg_N ("Iterator_Element requires indexing aspect", |
| 6101 |
Iterator_Aspect); |
| 6102 |
|
| 6103 |
else |
| 6104 |
Error_Msg_N ("Default_Iterator requires indexing aspect", |
| 6105 |
Iterator_Aspect); |
| 6106 |
end if; |
| 6107 |
end if; |
| 6108 |
end if; |
| 6109 |
end; |
| 6110 |
|
| 6111 |
-- All done if not a full record definition |
| 6112 |
|
| 6113 |
if Ekind (Rec) /= E_Record_Type then |
| 6114 |
return; |
| 6115 |
end if; |
| 6116 |
|
| 6117 |
-- Finally we need to check the variant part to make sure that |
| 6118 |
-- all types within choices are properly frozen as part of the |
| 6119 |
-- freezing of the record type. |
| 6120 |
|
| 6121 |
Check_Variant_Part : declare |
| 6122 |
D : constant Node_Id := Declaration_Node (Rec); |
| 6123 |
T : Node_Id; |
| 6124 |
C : Node_Id; |
| 6125 |
|
| 6126 |
begin |
| 6127 |
-- Find component list |
| 6128 |
|
| 6129 |
C := Empty; |
| 6130 |
|
| 6131 |
if Nkind (D) = N_Full_Type_Declaration then |
| 6132 |
T := Type_Definition (D); |
| 6133 |
|
| 6134 |
if Nkind (T) = N_Record_Definition then |
| 6135 |
C := Component_List (T); |
| 6136 |
|
| 6137 |
elsif Nkind (T) = N_Derived_Type_Definition |
| 6138 |
and then Present (Record_Extension_Part (T)) |
| 6139 |
then |
| 6140 |
C := Component_List (Record_Extension_Part (T)); |
| 6141 |
end if; |
| 6142 |
end if; |
| 6143 |
|
| 6144 |
-- Case of variant part present |
| 6145 |
|
| 6146 |
if Present (C) and then Present (Variant_Part (C)) then |
| 6147 |
Freeze_Choices_In_Variant_Part (Variant_Part (C)); |
| 6148 |
end if; |
| 6149 |
|
| 6150 |
-- Note: we used to call Check_Choices here, but it is too early, |
| 6151 |
-- since predicated subtypes are frozen here, but their freezing |
| 6152 |
-- actions are in Analyze_Freeze_Entity, which has not been called |
| 6153 |
-- yet for entities frozen within this procedure, so we moved that |
| 6154 |
-- call to the Analyze_Freeze_Entity for the record type. |
| 6155 |
|
| 6156 |
end Check_Variant_Part; |
| 6157 |
|
| 6158 |
-- Check that all the primitives of an interface type are abstract |
| 6159 |
-- or null procedures. |
| 6160 |
|
| 6161 |
if Is_Interface (Rec) |
| 6162 |
and then not Error_Posted (Parent (Rec)) |
| 6163 |
then |
| 6164 |
declare |
| 6165 |
Elmt : Elmt_Id; |
| 6166 |
Subp : Entity_Id; |
| 6167 |
|
| 6168 |
begin |
| 6169 |
Elmt := First_Elmt (Primitive_Operations (Rec)); |
| 6170 |
while Present (Elmt) loop |
| 6171 |
Subp := Node (Elmt); |
| 6172 |
|
| 6173 |
if not Is_Abstract_Subprogram (Subp) |
| 6174 |
|
| 6175 |
-- Avoid reporting the error on inherited primitives |
| 6176 |
|
| 6177 |
and then Comes_From_Source (Subp) |
| 6178 |
then |
| 6179 |
Error_Msg_Name_1 := Chars (Subp); |
| 6180 |
|
| 6181 |
if Ekind (Subp) = E_Procedure then |
| 6182 |
if not Null_Present (Parent (Subp)) then |
| 6183 |
Error_Msg_N |
| 6184 |
("interface procedure % must be abstract or null", |
| 6185 |
Parent (Subp)); |
| 6186 |
end if; |
| 6187 |
else |
| 6188 |
Error_Msg_N |
| 6189 |
("interface function % must be abstract", |
| 6190 |
Parent (Subp)); |
| 6191 |
end if; |
| 6192 |
end if; |
| 6193 |
|
| 6194 |
Next_Elmt (Elmt); |
| 6195 |
end loop; |
| 6196 |
end; |
| 6197 |
end if; |
| 6198 |
|
| 6199 |
-- For tagged types, warn on an implicitly inherited aspect/pragma |
| 6200 |
-- First_Controlling_Parameter that is not explicitly set. |
| 6201 |
|
| 6202 |
if Is_Tagged_Type (Rec) then |
| 6203 |
Warn_If_Implicitly_Inherited_Aspects (Rec); |
| 6204 |
end if; |
| 6205 |
end Freeze_Record_Type; |
| 6206 |
|
| 6207 |
------------------------------- |
| 6208 |
-- Has_Boolean_Aspect_Import -- |
| 6209 |
------------------------------- |
| 6210 |
|
| 6211 |
function Has_Boolean_Aspect_Import (E : Entity_Id) return Boolean is |
| 6212 |
Decl : constant Node_Id := Declaration_Node (E); |
| 6213 |
Asp : Node_Id; |
| 6214 |
Expr : Node_Id; |
| 6215 |
|
| 6216 |
begin |
| 6217 |
if Has_Aspects (Decl) then |
| 6218 |
Asp := First (Aspect_Specifications (Decl)); |
| 6219 |
while Present (Asp) loop |
| 6220 |
Expr := Expression (Asp); |
| 6221 |
|
| 6222 |
-- The value of aspect Import is True when the expression is |
| 6223 |
-- either missing or it is explicitly set to True. |
| 6224 |
|
| 6225 |
if Get_Aspect_Id (Asp) = Aspect_Import |
| 6226 |
and then (No (Expr) |
| 6227 |
or else (Compile_Time_Known_Value (Expr) |
| 6228 |
and then Is_True (Expr_Value (Expr)))) |
| 6229 |
then |
| 6230 |
return True; |
| 6231 |
end if; |
| 6232 |
|
| 6233 |
Next (Asp); |
| 6234 |
end loop; |
| 6235 |
end if; |
| 6236 |
|
| 6237 |
return False; |
| 6238 |
end Has_Boolean_Aspect_Import; |
| 6239 |
|
| 6240 |
------------------------- |
| 6241 |
-- Inherit_Freeze_Node -- |
| 6242 |
------------------------- |
| 6243 |
|
| 6244 |
procedure Inherit_Freeze_Node |
| 6245 |
(Fnod : Node_Id; |
| 6246 |
Typ : Entity_Id) |
| 6247 |
is |
| 6248 |
Typ_Fnod : constant Node_Id := Freeze_Node (Typ); |
| 6249 |
|
| 6250 |
begin |
| 6251 |
Set_Freeze_Node (Typ, Fnod); |
| 6252 |
Set_Entity (Fnod, Typ); |
| 6253 |
|
| 6254 |
-- The input type had an existing node. Propagate relevant attributes |
| 6255 |
-- from the old freeze node to the inherited freeze node. |
| 6256 |
|
| 6257 |
-- ??? if both freeze nodes have attributes, would they differ? |
| 6258 |
|
| 6259 |
if Present (Typ_Fnod) then |
| 6260 |
|
| 6261 |
-- Attribute Access_Types_To_Process |
| 6262 |
|
| 6263 |
if Present (Access_Types_To_Process (Typ_Fnod)) |
| 6264 |
and then No (Access_Types_To_Process (Fnod)) |
| 6265 |
then |
| 6266 |
Set_Access_Types_To_Process (Fnod, |
| 6267 |
Access_Types_To_Process (Typ_Fnod)); |
| 6268 |
end if; |
| 6269 |
|
| 6270 |
-- Attribute Actions |
| 6271 |
|
| 6272 |
if Present (Actions (Typ_Fnod)) and then No (Actions (Fnod)) then |
| 6273 |
Set_Actions (Fnod, Actions (Typ_Fnod)); |
| 6274 |
end if; |
| 6275 |
|
| 6276 |
-- Attribute First_Subtype_Link |
| 6277 |
|
| 6278 |
if Present (First_Subtype_Link (Typ_Fnod)) |
| 6279 |
and then No (First_Subtype_Link (Fnod)) |
| 6280 |
then |
| 6281 |
Set_First_Subtype_Link (Fnod, First_Subtype_Link (Typ_Fnod)); |
| 6282 |
end if; |
| 6283 |
|
| 6284 |
-- Attribute TSS_Elist |
| 6285 |
|
| 6286 |
if Present (TSS_Elist (Typ_Fnod)) |
| 6287 |
and then No (TSS_Elist (Fnod)) |
| 6288 |
then |
| 6289 |
Set_TSS_Elist (Fnod, TSS_Elist (Typ_Fnod)); |
| 6290 |
end if; |
| 6291 |
end if; |
| 6292 |
end Inherit_Freeze_Node; |
| 6293 |
|
| 6294 |
------------------------------ |
| 6295 |
-- Wrap_Imported_Subprogram -- |
| 6296 |
------------------------------ |
| 6297 |
|
| 6298 |
-- The issue here is that our normal approach of checking preconditions |
| 6299 |
-- and postconditions does not work for imported procedures, since we |
| 6300 |
-- are not generating code for the body. To get around this we create |
| 6301 |
-- a wrapper, as shown by the following example: |
| 6302 |
|
| 6303 |
-- procedure K (A : Integer); |
| 6304 |
-- pragma Import (C, K); |
| 6305 |
|
| 6306 |
-- The spec is rewritten by removing the effects of pragma Import, but |
| 6307 |
-- leaving the convention unchanged, as though the source had said: |
| 6308 |
|
| 6309 |
-- procedure K (A : Integer); |
| 6310 |
-- pragma Convention (C, K); |
| 6311 |
|
| 6312 |
-- and we create a body, added to the entity K freeze actions, which |
| 6313 |
-- looks like: |
| 6314 |
|
| 6315 |
-- procedure K (A : Integer) is |
| 6316 |
-- procedure K (A : Integer); |
| 6317 |
-- pragma Import (C, K); |
| 6318 |
-- begin |
| 6319 |
-- K (A); |
| 6320 |
-- end K; |
| 6321 |
|
| 6322 |
-- Now the contract applies in the normal way to the outer procedure, |
| 6323 |
-- and the inner procedure has no contracts, so there is no problem |
| 6324 |
-- in just calling it to get the original effect. |
| 6325 |
|
| 6326 |
-- In the case of a function, we create an appropriate return statement |
| 6327 |
-- for the subprogram body that calls the inner procedure. |
| 6328 |
|
| 6329 |
procedure Wrap_Imported_Subprogram (E : Entity_Id) is |
| 6330 |
function Copy_Import_Pragma return Node_Id; |
| 6331 |
-- Obtain a copy of the Import_Pragma which belongs to subprogram E |
| 6332 |
|
| 6333 |
------------------------ |
| 6334 |
-- Copy_Import_Pragma -- |
| 6335 |
------------------------ |
| 6336 |
|
| 6337 |
function Copy_Import_Pragma return Node_Id is |
| 6338 |
|
| 6339 |
-- The subprogram should have an import pragma, otherwise it does |
| 6340 |
-- need a wrapper. |
| 6341 |
|
| 6342 |
Prag : constant Node_Id := Import_Pragma (E); |
| 6343 |
pragma Assert (Present (Prag)); |
| 6344 |
|
| 6345 |
-- Save all semantic fields of the pragma |
| 6346 |
|
| 6347 |
Save_Asp : constant Node_Id := Corresponding_Aspect (Prag); |
| 6348 |
Save_From : constant Boolean := From_Aspect_Specification (Prag); |
| 6349 |
Save_Prag : constant Node_Id := Next_Pragma (Prag); |
| 6350 |
Save_Rep : constant Node_Id := Next_Rep_Item (Prag); |
| 6351 |
|
| 6352 |
Result : Node_Id; |
| 6353 |
|
| 6354 |
begin |
| 6355 |
-- Reset all semantic fields. This avoids a potential infinite |
| 6356 |
-- loop when the pragma comes from an aspect as the duplication |
| 6357 |
-- will copy the aspect, then copy the corresponding pragma and |
| 6358 |
-- so on. |
| 6359 |
|
| 6360 |
Set_Corresponding_Aspect (Prag, Empty); |
| 6361 |
Set_From_Aspect_Specification (Prag, False); |
| 6362 |
Set_Next_Pragma (Prag, Empty); |
| 6363 |
Set_Next_Rep_Item (Prag, Empty); |
| 6364 |
|
| 6365 |
Result := Copy_Separate_Tree (Prag); |
| 6366 |
|
| 6367 |
-- Restore the original semantic fields |
| 6368 |
|
| 6369 |
Set_Corresponding_Aspect (Prag, Save_Asp); |
| 6370 |
Set_From_Aspect_Specification (Prag, Save_From); |
| 6371 |
Set_Next_Pragma (Prag, Save_Prag); |
| 6372 |
Set_Next_Rep_Item (Prag, Save_Rep); |
| 6373 |
|
| 6374 |
return Result; |
| 6375 |
end Copy_Import_Pragma; |
| 6376 |
|
| 6377 |
-- Local variables |
| 6378 |
|
| 6379 |
Loc : constant Source_Ptr := Sloc (E); |
| 6380 |
CE : constant Name_Id := Chars (E); |
| 6381 |
Bod : Node_Id; |
| 6382 |
Forml : Entity_Id; |
| 6383 |
Parms : List_Id; |
| 6384 |
Prag : Node_Id; |
| 6385 |
Spec : Node_Id; |
| 6386 |
Stmt : Node_Id; |
| 6387 |
|
| 6388 |
-- Start of processing for Wrap_Imported_Subprogram |
| 6389 |
|
| 6390 |
begin |
| 6391 |
-- Nothing to do if not imported |
| 6392 |
|
| 6393 |
if not Is_Imported (E) then |
| 6394 |
return; |
| 6395 |
|
| 6396 |
-- Test enabling conditions for wrapping |
| 6397 |
|
| 6398 |
elsif Is_Subprogram (E) |
| 6399 |
and then Present (Contract (E)) |
| 6400 |
and then Present (Pre_Post_Conditions (Contract (E))) |
| 6401 |
and then not GNATprove_Mode |
| 6402 |
then |
| 6403 |
-- Here we do the wrap |
| 6404 |
|
| 6405 |
Prag := Copy_Import_Pragma; |
| 6406 |
|
| 6407 |
-- Fix up spec so it is no longer imported and has convention Ada |
| 6408 |
|
| 6409 |
Set_Has_Completion (E, False); |
| 6410 |
Set_Import_Pragma (E, Empty); |
| 6411 |
Set_Interface_Name (E, Empty); |
| 6412 |
Set_Is_Imported (E, False); |
| 6413 |
Set_Convention (E, Convention_Ada); |
| 6414 |
|
| 6415 |
-- Grab the subprogram declaration and specification |
| 6416 |
|
| 6417 |
Spec := Declaration_Node (E); |
| 6418 |
|
| 6419 |
-- Build parameter list that we need |
| 6420 |
|
| 6421 |
Parms := New_List; |
| 6422 |
Forml := First_Formal (E); |
| 6423 |
while Present (Forml) loop |
| 6424 |
Append_To (Parms, Make_Identifier (Loc, Chars (Forml))); |
| 6425 |
Next_Formal (Forml); |
| 6426 |
end loop; |
| 6427 |
|
| 6428 |
-- Build the call |
| 6429 |
|
| 6430 |
-- An imported function whose result type is anonymous access |
| 6431 |
-- creates a new anonymous access type when it is relocated into |
| 6432 |
-- the declarations of the body generated below. As a result, the |
| 6433 |
-- accessibility level of these two anonymous access types may not |
| 6434 |
-- be compatible even though they are essentially the same type. |
| 6435 |
-- Use an unchecked type conversion to reconcile this case. Note |
| 6436 |
-- that the conversion is safe because in the named access type |
| 6437 |
-- case, both the body and imported function utilize the same |
| 6438 |
-- type. |
| 6439 |
|
| 6440 |
if Ekind (E) in E_Function | E_Generic_Function then |
| 6441 |
Stmt := |
| 6442 |
Make_Simple_Return_Statement (Loc, |
| 6443 |
Expression => |
| 6444 |
Unchecked_Convert_To (Etype (E), |
| 6445 |
Make_Function_Call (Loc, |
| 6446 |
Name => Make_Identifier (Loc, CE), |
| 6447 |
Parameter_Associations => Parms))); |
| 6448 |
|
| 6449 |
else |
| 6450 |
Stmt := |
| 6451 |
Make_Procedure_Call_Statement (Loc, |
| 6452 |
Name => Make_Identifier (Loc, CE), |
| 6453 |
Parameter_Associations => Parms); |
| 6454 |
end if; |
| 6455 |
|
| 6456 |
-- Now build the body |
| 6457 |
|
| 6458 |
Bod := |
| 6459 |
Make_Subprogram_Body (Loc, |
| 6460 |
Specification => Copy_Subprogram_Spec (Spec), |
| 6461 |
Declarations => New_List ( |
| 6462 |
Make_Subprogram_Declaration (Loc, |
| 6463 |
Specification => Copy_Subprogram_Spec (Spec)), |
| 6464 |
Prag), |
| 6465 |
Handled_Statement_Sequence => |
| 6466 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 6467 |
Statements => New_List (Stmt), |
| 6468 |
End_Label => Make_Identifier (Loc, CE))); |
| 6469 |
|
| 6470 |
-- Append the body to freeze result |
| 6471 |
|
| 6472 |
Add_To_Result (Bod); |
| 6473 |
return; |
| 6474 |
|
| 6475 |
-- Case of imported subprogram that does not get wrapped |
| 6476 |
|
| 6477 |
else |
| 6478 |
-- Set Is_Public. All imported entities need an external symbol |
| 6479 |
-- created for them since they are always referenced from another |
| 6480 |
-- object file. Note this used to be set when we set Is_Imported |
| 6481 |
-- back in Sem_Prag, but now we delay it to this point, since we |
| 6482 |
-- don't want to set this flag if we wrap an imported subprogram. |
| 6483 |
|
| 6484 |
Set_Is_Public (E); |
| 6485 |
end if; |
| 6486 |
end Wrap_Imported_Subprogram; |
| 6487 |
|
| 6488 |
-- Start of processing for Freeze_Entity |
| 6489 |
|
| 6490 |
begin |
| 6491 |
-- The entity being frozen may be subject to pragma Ghost. Set the mode |
| 6492 |
-- now to ensure that any nodes generated during freezing are properly |
| 6493 |
-- flagged as Ghost. |
| 6494 |
|
| 6495 |
Set_Ghost_Mode (E); |
| 6496 |
|
| 6497 |
-- We are going to test for various reasons why this entity need not be |
| 6498 |
-- frozen here, but in the case of an Itype that's defined within a |
| 6499 |
-- record, that test actually applies to the record. |
| 6500 |
|
| 6501 |
if Is_Itype (E) and then Is_Record_Type (Scope (E)) then |
| 6502 |
Test_E := Scope (E); |
| 6503 |
|
| 6504 |
elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E))) |
| 6505 |
and then Is_Record_Type (Underlying_Type (Scope (E))) |
| 6506 |
then |
| 6507 |
Test_E := Underlying_Type (Scope (E)); |
| 6508 |
end if; |
| 6509 |
|
| 6510 |
-- Do not freeze if already frozen since we only need one freeze node |
| 6511 |
|
| 6512 |
if Is_Frozen (E) then |
| 6513 |
|
| 6514 |
if Is_Itype (E) |
| 6515 |
and then not Is_Base_Type (E) |
| 6516 |
and then not Is_Frozen (Etype (E)) |
| 6517 |
then |
| 6518 |
-- If a frozen subtype of an unfrozen type seems impossible |
| 6519 |
-- then see Analyze_Protected_Definition.Undelay_Itypes. |
| 6520 |
|
| 6521 |
Result := Freeze_Entity |
| 6522 |
(Etype (E), N, Do_Freeze_Profile => Do_Freeze_Profile); |
| 6523 |
else |
| 6524 |
Result := No_List; |
| 6525 |
end if; |
| 6526 |
|
| 6527 |
goto Leave; |
| 6528 |
|
| 6529 |
-- Do not freeze under strict preanalysis |
| 6530 |
|
| 6531 |
elsif Preanalysis_Active |
| 6532 |
and then not Within_Spec_Static_Expression (N) |
| 6533 |
then |
| 6534 |
Result := No_List; |
| 6535 |
goto Leave; |
| 6536 |
|
| 6537 |
elsif Ekind (E) = E_Generic_Package then |
| 6538 |
Result := Freeze_Generic_Entities (E); |
| 6539 |
goto Leave; |
| 6540 |
|
| 6541 |
-- It is improper to freeze an external entity within a generic because |
| 6542 |
-- its freeze node will appear in a non-valid context. The entity will |
| 6543 |
-- be frozen in the proper scope after the current generic is analyzed. |
| 6544 |
-- However, aspects must be analyzed because they may be queried later |
| 6545 |
-- within the generic itself, and the corresponding pragma or attribute |
| 6546 |
-- definition has not been analyzed yet. After this, indicate that the |
| 6547 |
-- entity has no further delayed aspects, to prevent a later aspect |
| 6548 |
-- analysis out of the scope of the generic. |
| 6549 |
|
| 6550 |
elsif Inside_A_Generic and then External_Ref_In_Generic (Test_E) then |
| 6551 |
if Has_Delayed_Aspects (E) then |
| 6552 |
Analyze_Aspects_At_Freeze_Point (E); |
| 6553 |
Set_Has_Delayed_Aspects (E, False); |
| 6554 |
end if; |
| 6555 |
|
| 6556 |
Result := No_List; |
| 6557 |
goto Leave; |
| 6558 |
|
| 6559 |
-- AI05-0213: A formal incomplete type does not freeze the actual. In |
| 6560 |
-- the instance, the same applies to the subtype renaming the actual. |
| 6561 |
|
| 6562 |
elsif Is_Private_Type (E) |
| 6563 |
and then Is_Generic_Actual_Type (E) |
| 6564 |
and then No (Full_View (Base_Type (E))) |
| 6565 |
and then Ada_Version >= Ada_2012 |
| 6566 |
then |
| 6567 |
Result := No_List; |
| 6568 |
goto Leave; |
| 6569 |
|
| 6570 |
-- Formal subprograms are never frozen |
| 6571 |
|
| 6572 |
elsif Is_Formal_Subprogram (E) then |
| 6573 |
Result := No_List; |
| 6574 |
goto Leave; |
| 6575 |
|
| 6576 |
-- Generic types are never frozen as they lack delayed semantic checks |
| 6577 |
|
| 6578 |
elsif Is_Generic_Type (E) then |
| 6579 |
Result := No_List; |
| 6580 |
goto Leave; |
| 6581 |
|
| 6582 |
-- Do not freeze a global entity within an inner scope created during |
| 6583 |
-- expansion. A call to subprogram E within some internal procedure |
| 6584 |
-- (a stream attribute for example) might require freezing E, but the |
| 6585 |
-- freeze node must appear in the same declarative part as E itself. |
| 6586 |
-- The two-pass elaboration mechanism in gigi guarantees that E will |
| 6587 |
-- be frozen before the inner call is elaborated. We exclude constants |
| 6588 |
-- from this test, because deferred constants may be frozen early, and |
| 6589 |
-- must be diagnosed (e.g. in the case of a deferred constant being used |
| 6590 |
-- in a default expression). If the enclosing subprogram comes from |
| 6591 |
-- source, or is a generic instance, then the freeze point is the one |
| 6592 |
-- mandated by the language, and we freeze the entity. A subprogram that |
| 6593 |
-- is a child unit body that acts as a spec does not have a spec that |
| 6594 |
-- comes from source, but can only come from source. |
| 6595 |
|
| 6596 |
elsif In_Open_Scopes (Scope (Test_E)) |
| 6597 |
and then Scope (Test_E) /= Current_Scope |
| 6598 |
and then Ekind (Test_E) /= E_Constant |
| 6599 |
then |
| 6600 |
-- Here we deal with the special case of the expansion of |
| 6601 |
-- postconditions. Previously this was handled by the loop below, |
| 6602 |
-- since these postcondition checks got isolated to a separate, |
| 6603 |
-- internally generated, subprogram. Now, however, the postcondition |
| 6604 |
-- checks get contained within their corresponding subprogram |
| 6605 |
-- directly. |
| 6606 |
|
| 6607 |
if not Comes_From_Source (N) |
| 6608 |
and then Nkind (N) = N_Pragma |
| 6609 |
and then From_Aspect_Specification (N) |
| 6610 |
and then Is_Valid_Assertion_Kind (Original_Aspect_Pragma_Name (N)) |
| 6611 |
|
| 6612 |
-- Now, verify the placement of the pragma is within an expanded |
| 6613 |
-- subprogram which contains postcondition expansion - detected |
| 6614 |
-- through the presence of the "Wrapped_Statements" field. |
| 6615 |
|
| 6616 |
and then Present (Enclosing_Subprogram (Current_Scope)) |
| 6617 |
and then Present (Wrapped_Statements |
| 6618 |
(Enclosing_Subprogram (Current_Scope))) |
| 6619 |
then |
| 6620 |
goto Leave; |
| 6621 |
end if; |
| 6622 |
|
| 6623 |
-- Otherwise, loop through scopes checking if an enclosing scope |
| 6624 |
-- comes from source or is a generic. Note that, for the purpose |
| 6625 |
-- of this test, we need to consider that the internally generated |
| 6626 |
-- subprogram described above comes from source too if the original |
| 6627 |
-- subprogram itself does. |
| 6628 |
|
| 6629 |
declare |
| 6630 |
S : Entity_Id; |
| 6631 |
|
| 6632 |
begin |
| 6633 |
S := Current_Scope; |
| 6634 |
while Present (S) loop |
| 6635 |
if Is_Overloadable (S) then |
| 6636 |
if Comes_From_Source (S) |
| 6637 |
or else (Chars (S) = Name_uWrapped_Statements |
| 6638 |
and then Comes_From_Source (Scope (S))) |
| 6639 |
or else Is_Generic_Instance (S) |
| 6640 |
or else Is_Child_Unit (S) |
| 6641 |
then |
| 6642 |
exit; |
| 6643 |
else |
| 6644 |
Result := No_List; |
| 6645 |
goto Leave; |
| 6646 |
end if; |
| 6647 |
end if; |
| 6648 |
|
| 6649 |
S := Scope (S); |
| 6650 |
end loop; |
| 6651 |
end; |
| 6652 |
|
| 6653 |
-- Similarly, an inlined instance body may make reference to global |
| 6654 |
-- entities, but these references cannot be the proper freezing point |
| 6655 |
-- for them, and in the absence of inlining freezing will take place in |
| 6656 |
-- their own scope. Normally instance bodies are analyzed after the |
| 6657 |
-- enclosing compilation, and everything has been frozen at the proper |
| 6658 |
-- place, but with front-end inlining an instance body is compiled |
| 6659 |
-- before the end of the enclosing scope, and as a result out-of-order |
| 6660 |
-- freezing must be prevented. |
| 6661 |
|
| 6662 |
elsif Front_End_Inlining |
| 6663 |
and then In_Instance_Body |
| 6664 |
and then Present (Scope (Test_E)) |
| 6665 |
then |
| 6666 |
declare |
| 6667 |
S : Entity_Id; |
| 6668 |
|
| 6669 |
begin |
| 6670 |
S := Scope (Test_E); |
| 6671 |
while Present (S) loop |
| 6672 |
if Is_Generic_Instance (S) then |
| 6673 |
exit; |
| 6674 |
else |
| 6675 |
S := Scope (S); |
| 6676 |
end if; |
| 6677 |
end loop; |
| 6678 |
|
| 6679 |
if No (S) then |
| 6680 |
Result := No_List; |
| 6681 |
goto Leave; |
| 6682 |
end if; |
| 6683 |
end; |
| 6684 |
end if; |
| 6685 |
|
| 6686 |
-- Add checks to detect proper initialization of scalars that may appear |
| 6687 |
-- as subprogram parameters. |
| 6688 |
|
| 6689 |
if Is_Subprogram (E) and then Check_Validity_Of_Parameters then |
| 6690 |
Apply_Parameter_Validity_Checks (E); |
| 6691 |
end if; |
| 6692 |
|
| 6693 |
-- Deal with delayed aspect specifications. The analysis of the aspect |
| 6694 |
-- is required to be delayed to the freeze point, thus we analyze the |
| 6695 |
-- pragma or attribute definition clause in the tree at this point. We |
| 6696 |
-- also analyze the aspect specification node at the freeze point when |
| 6697 |
-- the aspect doesn't correspond to pragma/attribute definition clause. |
| 6698 |
-- In addition, a derived type may have inherited aspects that were |
| 6699 |
-- delayed in the parent, so these must also be captured now. |
| 6700 |
|
| 6701 |
-- For a record type, we deal with the delayed aspect specifications on |
| 6702 |
-- components first, which is consistent with the non-delayed case and |
| 6703 |
-- makes it possible to have a single processing to detect conflicts. |
| 6704 |
|
| 6705 |
if Is_Record_Type (E) then |
| 6706 |
declare |
| 6707 |
Comp : Entity_Id; |
| 6708 |
|
| 6709 |
Rec_Pushed : Boolean := False; |
| 6710 |
-- Set True if the record type E has been pushed on the scope |
| 6711 |
-- stack. Needed for the analysis of delayed aspects specified |
| 6712 |
-- to the components of Rec. |
| 6713 |
|
| 6714 |
begin |
| 6715 |
Comp := First_Component (E); |
| 6716 |
while Present (Comp) loop |
| 6717 |
if Has_Delayed_Aspects (Comp) then |
| 6718 |
if not Rec_Pushed then |
| 6719 |
Push_Scope (E); |
| 6720 |
Rec_Pushed := True; |
| 6721 |
|
| 6722 |
-- The visibility to the discriminants must be restored |
| 6723 |
-- in order to properly analyze the aspects. |
| 6724 |
|
| 6725 |
if Has_Discriminants (E) then |
| 6726 |
Install_Discriminants (E); |
| 6727 |
end if; |
| 6728 |
end if; |
| 6729 |
|
| 6730 |
Analyze_Aspects_At_Freeze_Point (Comp); |
| 6731 |
end if; |
| 6732 |
|
| 6733 |
Next_Component (Comp); |
| 6734 |
end loop; |
| 6735 |
|
| 6736 |
-- Pop the scope if Rec scope has been pushed on the scope stack |
| 6737 |
-- during the delayed aspect analysis process. |
| 6738 |
|
| 6739 |
if Rec_Pushed then |
| 6740 |
if Has_Discriminants (E) then |
| 6741 |
Uninstall_Discriminants (E); |
| 6742 |
end if; |
| 6743 |
|
| 6744 |
Pop_Scope; |
| 6745 |
end if; |
| 6746 |
end; |
| 6747 |
end if; |
| 6748 |
|
| 6749 |
if Is_Derived_Type (E) and then Is_First_Subtype (E) then |
| 6750 |
|
| 6751 |
-- If a derived type's parent type is not already frozen and has |
| 6752 |
-- delayed aspects, analyze the parent type's aspects at this point, |
| 6753 |
-- so that the following call to update the type's inherited aspects |
| 6754 |
-- will be effective. |
| 6755 |
|
| 6756 |
if not Is_Frozen (Etype (E)) |
| 6757 |
and then Has_Delayed_Aspects (Etype (E)) |
| 6758 |
then |
| 6759 |
Analyze_Aspects_At_Freeze_Point (Etype (E)); |
| 6760 |
Set_Has_Delayed_Aspects (Etype (E), False); |
| 6761 |
end if; |
| 6762 |
|
| 6763 |
-- Identify the various subprograms associated with any inherited |
| 6764 |
-- nonoverridable aspects at this point rather than allowing them |
| 6765 |
-- to be resolved during analysis. |
| 6766 |
|
| 6767 |
Inherit_Nonoverridable_Aspects (E, Etype (E)); |
| 6768 |
|
| 6769 |
declare |
| 6770 |
Iface : Node_Id := First (Abstract_Interface_List (E)); |
| 6771 |
begin |
| 6772 |
while Present (Iface) loop |
| 6773 |
Inherit_Nonoverridable_Aspects (E, Entity (Iface)); |
| 6774 |
Next (Iface); |
| 6775 |
end loop; |
| 6776 |
end; |
| 6777 |
end if; |
| 6778 |
|
| 6779 |
if Has_Delayed_Aspects (E) then |
| 6780 |
Analyze_Aspects_At_Freeze_Point (E); |
| 6781 |
end if; |
| 6782 |
|
| 6783 |
-- Here to freeze the entity |
| 6784 |
|
| 6785 |
Set_Is_Frozen (E); |
| 6786 |
|
| 6787 |
-- Case of entity being frozen is other than a type |
| 6788 |
|
| 6789 |
if not Is_Type (E) then |
| 6790 |
|
| 6791 |
-- If entity is exported or imported and does not have an external |
| 6792 |
-- name, now is the time to provide the appropriate default name. |
| 6793 |
-- Skip this if the entity is stubbed, since we don't need a name |
| 6794 |
-- for any stubbed routine. For the case on intrinsics, if no |
| 6795 |
-- external name is specified, then calls will be handled in |
| 6796 |
-- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an |
| 6797 |
-- external name is provided, then Expand_Intrinsic_Call leaves |
| 6798 |
-- calls in place for expansion by GIGI. |
| 6799 |
|
| 6800 |
if (Is_Imported (E) or else Is_Exported (E)) |
| 6801 |
and then No (Interface_Name (E)) |
| 6802 |
and then Convention (E) /= Convention_Stubbed |
| 6803 |
and then Convention (E) /= Convention_Intrinsic |
| 6804 |
then |
| 6805 |
Set_Encoded_Interface_Name |
| 6806 |
(E, Get_Default_External_Name (E)); |
| 6807 |
end if; |
| 6808 |
|
| 6809 |
-- Subprogram case |
| 6810 |
|
| 6811 |
if Is_Subprogram (E) then |
| 6812 |
|
| 6813 |
-- Check for needing to wrap imported subprogram |
| 6814 |
|
| 6815 |
if not Inside_A_Generic then |
| 6816 |
Wrap_Imported_Subprogram (E); |
| 6817 |
end if; |
| 6818 |
|
| 6819 |
-- Freeze all parameter types and the return type (RM 13.14(14)). |
| 6820 |
-- However skip this for internal subprograms. This is also where |
| 6821 |
-- any extra formal parameters are created since we now know |
| 6822 |
-- whether the subprogram will use a foreign convention. |
| 6823 |
|
| 6824 |
-- In Ada 2012, freezing a subprogram does not always freeze the |
| 6825 |
-- corresponding profile (see AI05-019). An attribute reference |
| 6826 |
-- is not a freezing point of the profile. Similarly, we do not |
| 6827 |
-- freeze the profile of primitives of a library-level tagged type |
| 6828 |
-- when we are building its dispatch table. Flag Do_Freeze_Profile |
| 6829 |
-- indicates whether the profile should be frozen now. |
| 6830 |
|
| 6831 |
-- This processing doesn't apply to internal entities (see below) |
| 6832 |
|
| 6833 |
if not Is_Internal (E) and then Do_Freeze_Profile then |
| 6834 |
if not Freeze_Profile (E) then |
| 6835 |
goto Leave; |
| 6836 |
end if; |
| 6837 |
end if; |
| 6838 |
|
| 6839 |
-- Must freeze its parent first if it is a derived subprogram |
| 6840 |
|
| 6841 |
if Present (Alias (E)) then |
| 6842 |
Freeze_And_Append (Alias (E), N, Result); |
| 6843 |
end if; |
| 6844 |
|
| 6845 |
-- We don't freeze internal subprograms, because we don't normally |
| 6846 |
-- want addition of extra formals or mechanism setting to happen |
| 6847 |
-- for those. However we do pass through predefined dispatching |
| 6848 |
-- cases, since extra formals may be needed in some cases, such as |
| 6849 |
-- for the stream 'Input function (build-in-place formals). |
| 6850 |
|
| 6851 |
if not Is_Internal (E) |
| 6852 |
or else Is_Predefined_Dispatching_Operation (E) |
| 6853 |
then |
| 6854 |
Freeze_Subprogram (E); |
| 6855 |
end if; |
| 6856 |
|
| 6857 |
-- If warning on suspicious contracts then check for the case of |
| 6858 |
-- a postcondition other than False for a No_Return subprogram. |
| 6859 |
|
| 6860 |
if No_Return (E) |
| 6861 |
and then Warn_On_Suspicious_Contract |
| 6862 |
and then Present (Contract (E)) |
| 6863 |
then |
| 6864 |
declare |
| 6865 |
Prag : Node_Id := Pre_Post_Conditions (Contract (E)); |
| 6866 |
Exp : Node_Id; |
| 6867 |
|
| 6868 |
begin |
| 6869 |
while Present (Prag) loop |
| 6870 |
if Pragma_Name_Unmapped (Prag) in Name_Post |
| 6871 |
| Name_Postcondition |
| 6872 |
| Name_Refined_Post |
| 6873 |
then |
| 6874 |
Exp := |
| 6875 |
Expression |
| 6876 |
(First (Pragma_Argument_Associations (Prag))); |
| 6877 |
|
| 6878 |
if Nkind (Exp) /= N_Identifier |
| 6879 |
or else Chars (Exp) /= Name_False |
| 6880 |
then |
| 6881 |
Error_Msg_NE |
| 6882 |
("useless postcondition, & is marked " |
| 6883 |
& "No_Return?.t?", Exp, E); |
| 6884 |
end if; |
| 6885 |
end if; |
| 6886 |
|
| 6887 |
Prag := Next_Pragma (Prag); |
| 6888 |
end loop; |
| 6889 |
end; |
| 6890 |
end if; |
| 6891 |
|
| 6892 |
-- Here for other than a subprogram or type |
| 6893 |
|
| 6894 |
else |
| 6895 |
-- If entity has a type declared in the current scope, and it is |
| 6896 |
-- not a generic unit, then freeze it first. |
| 6897 |
|
| 6898 |
if Present (Etype (E)) |
| 6899 |
and then Ekind (E) /= E_Generic_Function |
| 6900 |
and then Within_Scope (Etype (E), Current_Scope) |
| 6901 |
then |
| 6902 |
Freeze_And_Append (Etype (E), N, Result); |
| 6903 |
end if; |
| 6904 |
|
| 6905 |
-- Special processing for objects created by object declaration; |
| 6906 |
-- we protect the call to Declaration_Node against entities of |
| 6907 |
-- expressions replaced by the frontend with an N_Raise_CE node. |
| 6908 |
|
| 6909 |
if Ekind (E) in E_Constant | E_Variable |
| 6910 |
and then Nkind (Declaration_Node (E)) = N_Object_Declaration |
| 6911 |
then |
| 6912 |
Freeze_Object_Declaration (E); |
| 6913 |
end if; |
| 6914 |
|
| 6915 |
-- Check that a constant which has a pragma Volatile[_Components] |
| 6916 |
-- or Atomic[_Components] also has a pragma Import (RM C.6(13)). |
| 6917 |
|
| 6918 |
-- Note: Atomic[_Components] also sets Volatile[_Components] |
| 6919 |
|
| 6920 |
if Ekind (E) = E_Constant |
| 6921 |
and then (Has_Volatile_Components (E) or else Is_Volatile (E)) |
| 6922 |
and then not Is_Imported (E) |
| 6923 |
and then not Has_Boolean_Aspect_Import (E) |
| 6924 |
then |
| 6925 |
-- Make sure we actually have a pragma, and have not merely |
| 6926 |
-- inherited the indication from elsewhere (e.g. an address |
| 6927 |
-- clause, which is not good enough in RM terms). |
| 6928 |
|
| 6929 |
if Has_Rep_Pragma (E, Name_Atomic) |
| 6930 |
or else |
| 6931 |
Has_Rep_Pragma (E, Name_Atomic_Components) |
| 6932 |
then |
| 6933 |
Error_Msg_N |
| 6934 |
("standalone atomic constant must be " & |
| 6935 |
"imported (RM C.6(13))", E); |
| 6936 |
|
| 6937 |
elsif Has_Rep_Pragma (E, Name_Volatile) |
| 6938 |
or else |
| 6939 |
Has_Rep_Pragma (E, Name_Volatile_Components) |
| 6940 |
then |
| 6941 |
Error_Msg_N |
| 6942 |
("standalone volatile constant must be " & |
| 6943 |
"imported (RM C.6(13))", E); |
| 6944 |
end if; |
| 6945 |
end if; |
| 6946 |
|
| 6947 |
-- Statically allocated objects require special handling |
| 6948 |
|
| 6949 |
if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) |
| 6950 |
and then No (Renamed_Object (E)) |
| 6951 |
and then Is_Statically_Allocated (E) |
| 6952 |
then |
| 6953 |
Freeze_Static_Object (E); |
| 6954 |
end if; |
| 6955 |
|
| 6956 |
-- Remaining step is to layout objects |
| 6957 |
|
| 6958 |
if Ekind (E) in E_Variable | E_Constant | E_Loop_Parameter |
| 6959 |
or else Is_Formal (E) |
| 6960 |
then |
| 6961 |
Layout_Object (E); |
| 6962 |
end if; |
| 6963 |
|
| 6964 |
-- For an object that does not have delayed freezing, and whose |
| 6965 |
-- initialization actions have been captured in a compound |
| 6966 |
-- statement, move them back now directly within the enclosing |
| 6967 |
-- statement sequence. |
| 6968 |
|
| 6969 |
if Ekind (E) in E_Constant | E_Variable |
| 6970 |
and then not Has_Delayed_Freeze (E) |
| 6971 |
then |
| 6972 |
Explode_Initialization_Compound_Statement (E); |
| 6973 |
end if; |
| 6974 |
|
| 6975 |
-- Do not generate a freeze node for a generic unit |
| 6976 |
|
| 6977 |
if Is_Generic_Unit (E) then |
| 6978 |
Result := No_List; |
| 6979 |
goto Leave; |
| 6980 |
end if; |
| 6981 |
end if; |
| 6982 |
|
| 6983 |
-- Case of a type or subtype being frozen |
| 6984 |
|
| 6985 |
else |
| 6986 |
-- Verify several SPARK legality rules related to Ghost types now |
| 6987 |
-- that the type is frozen. |
| 6988 |
|
| 6989 |
Check_Ghost_Type (E); |
| 6990 |
|
| 6991 |
-- We used to check here that a full type must have preelaborable |
| 6992 |
-- initialization if it completes a private type specified with |
| 6993 |
-- pragma Preelaborable_Initialization, but that missed cases where |
| 6994 |
-- the types occur within a generic package, since the freezing |
| 6995 |
-- that occurs within a containing scope generally skips traversal |
| 6996 |
-- of a generic unit's declarations (those will be frozen within |
| 6997 |
-- instances). This check was moved to Analyze_Package_Specification. |
| 6998 |
|
| 6999 |
-- The type may be defined in a generic unit. This can occur when |
| 7000 |
-- freezing a generic function that returns the type (which is |
| 7001 |
-- defined in a parent unit). It is clearly meaningless to freeze |
| 7002 |
-- this type. However, if it is a subtype, its size may be determi- |
| 7003 |
-- nable and used in subsequent checks, so might as well try to |
| 7004 |
-- compute it. |
| 7005 |
|
| 7006 |
-- In Ada 2012, Freeze_Entities is also used in the front end to |
| 7007 |
-- trigger the analysis of aspect expressions, so in this case we |
| 7008 |
-- want to continue the freezing process. |
| 7009 |
|
| 7010 |
-- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead |
| 7011 |
-- In_Generic_Scope (E)??? |
| 7012 |
|
| 7013 |
if Present (Scope (E)) |
| 7014 |
and then Is_Generic_Unit (Scope (E)) |
| 7015 |
and then |
| 7016 |
(not Has_Predicates (E) |
| 7017 |
and then not Has_Delayed_Freeze (E)) |
| 7018 |
then |
| 7019 |
Check_Compile_Time_Size (E); |
| 7020 |
Result := No_List; |
| 7021 |
goto Leave; |
| 7022 |
end if; |
| 7023 |
|
| 7024 |
-- Check for error of Type_Invariant'Class applied to an untagged |
| 7025 |
-- type (check delayed to freeze time when full type is available). |
| 7026 |
|
| 7027 |
declare |
| 7028 |
Prag : constant Node_Id := Get_Pragma (E, Pragma_Invariant); |
| 7029 |
begin |
| 7030 |
if Present (Prag) |
| 7031 |
and then Class_Present (Prag) |
| 7032 |
and then not Is_Tagged_Type (E) |
| 7033 |
then |
| 7034 |
Error_Msg_NE |
| 7035 |
("Type_Invariant''Class cannot be specified for &", Prag, E); |
| 7036 |
Error_Msg_N |
| 7037 |
("\can only be specified for a tagged type", Prag); |
| 7038 |
end if; |
| 7039 |
end; |
| 7040 |
|
| 7041 |
-- If the entity is a declaration of an access-to-subprogram type |
| 7042 |
-- with pre/postcondition contracts, build the wrapper (if it hasn't |
| 7043 |
-- already been done during aspect processing), and propagate the |
| 7044 |
-- pre/postcondition pragmas to the wrapper. |
| 7045 |
|
| 7046 |
if Ada_Version >= Ada_2022 |
| 7047 |
and then Expander_Active |
| 7048 |
and then Ekind (E) = E_Access_Subprogram_Type |
| 7049 |
and then Nkind (Parent (E)) = N_Full_Type_Declaration |
| 7050 |
and then Present (Contract (Designated_Type (E))) |
| 7051 |
and then not Is_Derived_Type (E) |
| 7052 |
then |
| 7053 |
Build_Access_Subprogram_Wrapper (Parent (E)); |
| 7054 |
end if; |
| 7055 |
|
| 7056 |
-- Deal with special cases of freezing for subtype |
| 7057 |
|
| 7058 |
if E /= Base_Type (E) then |
| 7059 |
|
| 7060 |
-- Before we do anything else, a specific test for the case of a |
| 7061 |
-- size given for an array where the array would need to be packed |
| 7062 |
-- in order for the size to be honored, but is not. This is the |
| 7063 |
-- case where implicit packing may apply. The reason we do this so |
| 7064 |
-- early is that, if we have implicit packing, the layout of the |
| 7065 |
-- base type is affected, so we must do this before we freeze the |
| 7066 |
-- base type. |
| 7067 |
|
| 7068 |
-- We could do this processing only if implicit packing is enabled |
| 7069 |
-- since in all other cases, the error would be caught by the back |
| 7070 |
-- end. However, we choose to do the check even if we do not have |
| 7071 |
-- implicit packing enabled, since this allows us to give a more |
| 7072 |
-- useful error message (advising use of pragma Implicit_Packing |
| 7073 |
-- or pragma Pack). |
| 7074 |
|
| 7075 |
if Is_Array_Type (E) then |
| 7076 |
declare |
| 7077 |
Ctyp : constant Entity_Id := Component_Type (E); |
| 7078 |
Rsiz : constant Uint := |
| 7079 |
(if Known_RM_Size (Ctyp) then RM_Size (Ctyp) else Uint_0); |
| 7080 |
SZ : constant Node_Id := Size_Clause (E); |
| 7081 |
Btyp : constant Entity_Id := Base_Type (E); |
| 7082 |
|
| 7083 |
Lo : Node_Id; |
| 7084 |
Hi : Node_Id; |
| 7085 |
Indx : Node_Id; |
| 7086 |
|
| 7087 |
Dim : Uint; |
| 7088 |
Num_Elmts : Uint := Uint_1; |
| 7089 |
-- Number of elements in array |
| 7090 |
|
| 7091 |
begin |
| 7092 |
-- Check enabling conditions. These are straightforward |
| 7093 |
-- except for the test for a limited composite type. This |
| 7094 |
-- eliminates the rare case of a array of limited components |
| 7095 |
-- where there are issues of whether or not we can go ahead |
| 7096 |
-- and pack the array (since we can't freely pack and unpack |
| 7097 |
-- arrays if they are limited). |
| 7098 |
|
| 7099 |
-- Note that we check the root type explicitly because the |
| 7100 |
-- whole point is we are doing this test before we have had |
| 7101 |
-- a chance to freeze the base type (and it is that freeze |
| 7102 |
-- action that causes stuff to be inherited). |
| 7103 |
|
| 7104 |
-- The conditions on the size are identical to those used in |
| 7105 |
-- Freeze_Array_Type to set the Is_Packed flag. |
| 7106 |
|
| 7107 |
if Has_Size_Clause (E) |
| 7108 |
and then Known_Static_RM_Size (E) |
| 7109 |
and then not Is_Packed (E) |
| 7110 |
and then not Has_Pragma_Pack (E) |
| 7111 |
and then not Has_Component_Size_Clause (E) |
| 7112 |
and then Known_Static_RM_Size (Ctyp) |
| 7113 |
and then Rsiz <= System_Max_Integer_Size |
| 7114 |
and then not (Addressable (Rsiz) |
| 7115 |
and then Known_Static_Esize (Ctyp) |
| 7116 |
and then Esize (Ctyp) = Rsiz) |
| 7117 |
and then not (Rsiz mod System_Storage_Unit = 0 |
| 7118 |
and then Is_Composite_Type (Ctyp)) |
| 7119 |
and then not Is_Limited_Composite (E) |
| 7120 |
and then not Is_Packed (Root_Type (E)) |
| 7121 |
and then not Has_Component_Size_Clause (Root_Type (E)) |
| 7122 |
and then not (CodePeer_Mode or GNATprove_Mode) |
| 7123 |
then |
| 7124 |
-- Compute number of elements in array |
| 7125 |
|
| 7126 |
Indx := First_Index (E); |
| 7127 |
while Present (Indx) loop |
| 7128 |
Get_Index_Bounds (Indx, Lo, Hi); |
| 7129 |
|
| 7130 |
if not (Compile_Time_Known_Value (Lo) |
| 7131 |
and then |
| 7132 |
Compile_Time_Known_Value (Hi)) |
| 7133 |
then |
| 7134 |
goto No_Implicit_Packing; |
| 7135 |
end if; |
| 7136 |
|
| 7137 |
Dim := Expr_Value (Hi) - Expr_Value (Lo) + 1; |
| 7138 |
|
| 7139 |
if Dim > Uint_0 then |
| 7140 |
Num_Elmts := Num_Elmts * Dim; |
| 7141 |
else |
| 7142 |
Num_Elmts := Uint_0; |
| 7143 |
end if; |
| 7144 |
|
| 7145 |
Next_Index (Indx); |
| 7146 |
end loop; |
| 7147 |
|
| 7148 |
-- What we are looking for here is the situation where |
| 7149 |
-- the RM_Size given would be exactly right if there was |
| 7150 |
-- a pragma Pack, resulting in the component size being |
| 7151 |
-- the RM_Size of the component type. |
| 7152 |
|
| 7153 |
if RM_Size (E) = Num_Elmts * Rsiz then |
| 7154 |
|
| 7155 |
-- For implicit packing mode, just set the component |
| 7156 |
-- size and Freeze_Array_Type will do the rest. |
| 7157 |
|
| 7158 |
if Implicit_Packing then |
| 7159 |
Set_Component_Size (Btyp, Rsiz); |
| 7160 |
|
| 7161 |
-- Otherwise give an error message, except that if the |
| 7162 |
-- specified Size is zero, there is no need for pragma |
| 7163 |
-- Pack. Note that size zero is not considered |
| 7164 |
-- Addressable. |
| 7165 |
|
| 7166 |
elsif RM_Size (E) /= Uint_0 then |
| 7167 |
Error_Msg_NE |
| 7168 |
("size given for& too small", SZ, E); |
| 7169 |
Error_Msg_N -- CODEFIX |
| 7170 |
("\use explicit pragma Pack or use pragma " |
| 7171 |
& "Implicit_Packing", SZ); |
| 7172 |
end if; |
| 7173 |
end if; |
| 7174 |
end if; |
| 7175 |
end; |
| 7176 |
end if; |
| 7177 |
|
| 7178 |
<<No_Implicit_Packing>> |
| 7179 |
|
| 7180 |
-- If ancestor subtype present, freeze that first. Note that this |
| 7181 |
-- will also get the base type frozen. Need RM reference ??? |
| 7182 |
|
| 7183 |
Atype := Ancestor_Subtype (E); |
| 7184 |
|
| 7185 |
if Present (Atype) then |
| 7186 |
Freeze_And_Append (Atype, N, Result); |
| 7187 |
|
| 7188 |
-- No ancestor subtype present |
| 7189 |
|
| 7190 |
else |
| 7191 |
-- See if we have a nearest ancestor that has a predicate. |
| 7192 |
-- That catches the case of derived type with a predicate. |
| 7193 |
-- Need RM reference here ??? |
| 7194 |
|
| 7195 |
Atype := Nearest_Ancestor (E); |
| 7196 |
|
| 7197 |
if Present (Atype) and then Has_Predicates (Atype) then |
| 7198 |
Freeze_And_Append (Atype, N, Result); |
| 7199 |
end if; |
| 7200 |
|
| 7201 |
-- Freeze base type before freezing the entity (RM 13.14(15)) |
| 7202 |
|
| 7203 |
if E /= Base_Type (E) then |
| 7204 |
Freeze_And_Append (Base_Type (E), N, Result); |
| 7205 |
end if; |
| 7206 |
end if; |
| 7207 |
|
| 7208 |
-- A subtype inherits all the type-related representation aspects |
| 7209 |
-- from its parents (RM 13.1(8)). |
| 7210 |
|
| 7211 |
if May_Inherit_Delayed_Rep_Aspects (E) then |
| 7212 |
Inherit_Delayed_Rep_Aspects (E); |
| 7213 |
end if; |
| 7214 |
|
| 7215 |
Inherit_Aspects_At_Freeze_Point (E); |
| 7216 |
|
| 7217 |
-- For a derived type, freeze its parent type first (RM 13.14(15)) |
| 7218 |
|
| 7219 |
elsif Is_Derived_Type (E) then |
| 7220 |
Freeze_And_Append (Etype (E), N, Result); |
| 7221 |
|
| 7222 |
-- A derived type inherits each type-related representation aspect |
| 7223 |
-- of its parent type that was directly specified before the |
| 7224 |
-- declaration of the derived type (RM 13.1(15)). |
| 7225 |
|
| 7226 |
if May_Inherit_Delayed_Rep_Aspects (E) then |
| 7227 |
Inherit_Delayed_Rep_Aspects (E); |
| 7228 |
end if; |
| 7229 |
|
| 7230 |
Inherit_Aspects_At_Freeze_Point (E); |
| 7231 |
end if; |
| 7232 |
|
| 7233 |
-- Case of array type |
| 7234 |
|
| 7235 |
if Is_Array_Type (E) then |
| 7236 |
Freeze_Array_Type (E); |
| 7237 |
end if; |
| 7238 |
|
| 7239 |
-- Check for incompatible size and alignment for array/record type |
| 7240 |
|
| 7241 |
if Warn_On_Size_Alignment |
| 7242 |
and then (Is_Array_Type (E) or else Is_Record_Type (E)) |
| 7243 |
and then Has_Size_Clause (E) |
| 7244 |
and then Has_Alignment_Clause (E) |
| 7245 |
|
| 7246 |
-- If explicit Object_Size clause given assume that the programmer |
| 7247 |
-- knows what he is doing, and expects the compiler behavior. |
| 7248 |
|
| 7249 |
and then not Has_Object_Size_Clause (E) |
| 7250 |
|
| 7251 |
-- It does not really make sense to warn for the minimum alignment |
| 7252 |
-- since the programmer could not get rid of the warning. |
| 7253 |
|
| 7254 |
and then Alignment (E) > 1 |
| 7255 |
|
| 7256 |
-- Check for size not a multiple of alignment |
| 7257 |
|
| 7258 |
and then RM_Size (E) mod (Alignment (E) * System_Storage_Unit) /= 0 |
| 7259 |
then |
| 7260 |
declare |
| 7261 |
SC : constant Node_Id := Size_Clause (E); |
| 7262 |
AC : constant Node_Id := Alignment_Clause (E); |
| 7263 |
Loc : Node_Id; |
| 7264 |
Abits : constant Uint := Alignment (E) * System_Storage_Unit; |
| 7265 |
|
| 7266 |
begin |
| 7267 |
if Present (SC) and then Present (AC) then |
| 7268 |
|
| 7269 |
-- Give a warning |
| 7270 |
|
| 7271 |
if Sloc (SC) > Sloc (AC) then |
| 7272 |
Loc := SC; |
| 7273 |
Error_Msg_NE |
| 7274 |
("?.z?size is not a multiple of alignment for &", |
| 7275 |
Loc, E); |
| 7276 |
Error_Msg_Sloc := Sloc (AC); |
| 7277 |
Error_Msg_Uint_1 := Alignment (E); |
| 7278 |
Error_Msg_N ("\?.z?alignment of ^ specified #", Loc); |
| 7279 |
|
| 7280 |
else |
| 7281 |
Loc := AC; |
| 7282 |
Error_Msg_NE |
| 7283 |
("?.z?size is not a multiple of alignment for &", |
| 7284 |
Loc, E); |
| 7285 |
Error_Msg_Sloc := Sloc (SC); |
| 7286 |
Error_Msg_Uint_1 := RM_Size (E); |
| 7287 |
Error_Msg_N ("\?.z?size of ^ specified #", Loc); |
| 7288 |
end if; |
| 7289 |
|
| 7290 |
Error_Msg_Uint_1 := ((RM_Size (E) / Abits) + 1) * Abits; |
| 7291 |
Error_Msg_N ("\?.z?Object_Size will be increased to ^", Loc); |
| 7292 |
end if; |
| 7293 |
end; |
| 7294 |
end if; |
| 7295 |
|
| 7296 |
-- For a class-wide type, the corresponding specific type is |
| 7297 |
-- frozen as well (RM 13.14(15)) |
| 7298 |
|
| 7299 |
if Is_Class_Wide_Type (E) then |
| 7300 |
Freeze_And_Append (Root_Type (E), N, Result); |
| 7301 |
|
| 7302 |
-- If the base type of the class-wide type is still incomplete, |
| 7303 |
-- the class-wide remains unfrozen as well. This is legal when |
| 7304 |
-- E is the formal of a primitive operation of some other type |
| 7305 |
-- which is being frozen. |
| 7306 |
|
| 7307 |
if not Is_Frozen (Root_Type (E)) then |
| 7308 |
Set_Is_Frozen (E, False); |
| 7309 |
goto Leave; |
| 7310 |
end if; |
| 7311 |
|
| 7312 |
-- The equivalent type associated with a class-wide subtype needs |
| 7313 |
-- to be frozen to ensure that its layout is done. |
| 7314 |
|
| 7315 |
if Ekind (E) = E_Class_Wide_Subtype |
| 7316 |
and then Present (Equivalent_Type (E)) |
| 7317 |
then |
| 7318 |
Freeze_And_Append (Equivalent_Type (E), N, Result); |
| 7319 |
end if; |
| 7320 |
|
| 7321 |
-- Generate an itype reference for a library-level class-wide type |
| 7322 |
-- at the freeze point. Otherwise the first explicit reference to |
| 7323 |
-- the type may appear in an inner scope which will be rejected by |
| 7324 |
-- the back-end. |
| 7325 |
|
| 7326 |
if Is_Itype (E) |
| 7327 |
and then Is_Compilation_Unit (Scope (E)) |
| 7328 |
then |
| 7329 |
declare |
| 7330 |
Ref : constant Node_Id := Make_Itype_Reference (Loc); |
| 7331 |
|
| 7332 |
begin |
| 7333 |
Set_Itype (Ref, E); |
| 7334 |
|
| 7335 |
-- From a gigi point of view, a class-wide subtype derives |
| 7336 |
-- from its record equivalent type. As a result, the itype |
| 7337 |
-- reference must appear after the freeze node of the |
| 7338 |
-- equivalent type or gigi will reject the reference. |
| 7339 |
|
| 7340 |
if Ekind (E) = E_Class_Wide_Subtype |
| 7341 |
and then Present (Equivalent_Type (E)) |
| 7342 |
then |
| 7343 |
Insert_After (Freeze_Node (Equivalent_Type (E)), Ref); |
| 7344 |
else |
| 7345 |
Add_To_Result (Ref); |
| 7346 |
end if; |
| 7347 |
end; |
| 7348 |
end if; |
| 7349 |
|
| 7350 |
-- For a record type or record subtype, freeze all component types |
| 7351 |
-- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than |
| 7352 |
-- using Is_Record_Type, because we don't want to attempt the freeze |
| 7353 |
-- for the case of a private type with record extension (we will do |
| 7354 |
-- that later when the full type is frozen). |
| 7355 |
|
| 7356 |
elsif Ekind (E) in E_Record_Type | E_Record_Subtype then |
| 7357 |
if not In_Generic_Scope (E) then |
| 7358 |
-- If this is a class-wide equivalent type for a non-interface |
| 7359 |
-- root type, freeze the root type. |
| 7360 |
|
| 7361 |
if Is_Class_Wide_Equivalent_Type (E) |
| 7362 |
and then Present (Parent_Subtype (E)) |
| 7363 |
then |
| 7364 |
Freeze_And_Append (Parent_Subtype (E), N, Result); |
| 7365 |
end if; |
| 7366 |
|
| 7367 |
Freeze_Record_Type (E); |
| 7368 |
end if; |
| 7369 |
|
| 7370 |
-- Report a warning if a discriminated record base type has a |
| 7371 |
-- convention with language C or C++ applied to it. This check is |
| 7372 |
-- done even within generic scopes (but not in instantiations), |
| 7373 |
-- which is why we don't do it as part of Freeze_Record_Type. |
| 7374 |
|
| 7375 |
Check_Suspicious_Convention (E); |
| 7376 |
|
| 7377 |
-- For a concurrent type, freeze corresponding record type. This does |
| 7378 |
-- not correspond to any specific rule in the RM, but the record type |
| 7379 |
-- is essentially part of the concurrent type. Also freeze all local |
| 7380 |
-- entities. This includes record types created for entry parameter |
| 7381 |
-- blocks and whatever local entities may appear in the private part. |
| 7382 |
|
| 7383 |
elsif Is_Concurrent_Type (E) then |
| 7384 |
if Present (Corresponding_Record_Type (E)) then |
| 7385 |
Freeze_And_Append (Corresponding_Record_Type (E), N, Result); |
| 7386 |
end if; |
| 7387 |
|
| 7388 |
Comp := First_Entity (E); |
| 7389 |
while Present (Comp) loop |
| 7390 |
if Is_Type (Comp) then |
| 7391 |
Freeze_And_Append (Comp, N, Result); |
| 7392 |
|
| 7393 |
elsif Ekind (Comp) /= E_Function then |
| 7394 |
|
| 7395 |
-- The guard on the presence of the Etype seems to be needed |
| 7396 |
-- for some CodePeer (-gnatcC) cases, but not clear why??? |
| 7397 |
|
| 7398 |
if Present (Etype (Comp)) then |
| 7399 |
if Is_Itype (Etype (Comp)) |
| 7400 |
and then Underlying_Type (Scope (Etype (Comp))) = E |
| 7401 |
then |
| 7402 |
Undelay_Type (Etype (Comp)); |
| 7403 |
end if; |
| 7404 |
|
| 7405 |
Freeze_And_Append (Etype (Comp), N, Result); |
| 7406 |
end if; |
| 7407 |
end if; |
| 7408 |
|
| 7409 |
Next_Entity (Comp); |
| 7410 |
end loop; |
| 7411 |
|
| 7412 |
-- Private types are required to point to the same freeze node as |
| 7413 |
-- their corresponding full views. The freeze node itself has to |
| 7414 |
-- point to the partial view of the entity (because from the partial |
| 7415 |
-- view, we can retrieve the full view, but not the reverse). |
| 7416 |
-- However, in order to freeze correctly, we need to freeze the full |
| 7417 |
-- view. If we are freezing at the end of a scope (or within the |
| 7418 |
-- scope) of the private type, the partial and full views will have |
| 7419 |
-- been swapped, the full view appears first in the entity chain and |
| 7420 |
-- the swapping mechanism ensures that the pointers are properly set |
| 7421 |
-- (on scope exit). |
| 7422 |
|
| 7423 |
-- If we encounter the partial view before the full view (e.g. when |
| 7424 |
-- freezing from another scope), we freeze the full view, and then |
| 7425 |
-- set the pointers appropriately since we cannot rely on swapping to |
| 7426 |
-- fix things up (subtypes in an outer scope might not get swapped). |
| 7427 |
|
| 7428 |
-- If the full view is itself private, the above requirements apply |
| 7429 |
-- to the underlying full view instead of the full view. But there is |
| 7430 |
-- no swapping mechanism for the underlying full view so we need to |
| 7431 |
-- set the pointers appropriately in both cases. |
| 7432 |
|
| 7433 |
elsif Is_Incomplete_Or_Private_Type (E) |
| 7434 |
and then not Is_Generic_Type (E) |
| 7435 |
then |
| 7436 |
-- The construction of the dispatch table associated with library |
| 7437 |
-- level tagged types forces freezing of all the primitives of the |
| 7438 |
-- type, which may cause premature freezing of the partial view. |
| 7439 |
-- For example: |
| 7440 |
|
| 7441 |
-- package Pkg is |
| 7442 |
-- type T is tagged private; |
| 7443 |
-- type DT is new T with private; |
| 7444 |
-- procedure Prim (X : in out T; Y : in out DT'Class); |
| 7445 |
-- private |
| 7446 |
-- type T is tagged null record; |
| 7447 |
-- Obj : T; |
| 7448 |
-- type DT is new T with null record; |
| 7449 |
-- end; |
| 7450 |
|
| 7451 |
-- In this case the type will be frozen later by the usual |
| 7452 |
-- mechanism: an object declaration, an instantiation, or the |
| 7453 |
-- end of a declarative part. |
| 7454 |
|
| 7455 |
if Is_Library_Level_Tagged_Type (E) |
| 7456 |
and then No (Full_View (E)) |
| 7457 |
then |
| 7458 |
Set_Is_Frozen (E, False); |
| 7459 |
goto Leave; |
| 7460 |
|
| 7461 |
-- Case of full view present |
| 7462 |
|
| 7463 |
elsif Present (Full_View (E)) then |
| 7464 |
|
| 7465 |
-- If full view has already been frozen, then no further |
| 7466 |
-- processing is required |
| 7467 |
|
| 7468 |
if Is_Frozen (Full_View (E)) then |
| 7469 |
Set_Has_Delayed_Freeze (E, False); |
| 7470 |
Set_Freeze_Node (E, Empty); |
| 7471 |
|
| 7472 |
-- Otherwise freeze full view and patch the pointers so that |
| 7473 |
-- the freeze node will elaborate both views in the back end. |
| 7474 |
-- However, if full view is itself private, freeze underlying |
| 7475 |
-- full view instead and patch the pointers so that the freeze |
| 7476 |
-- node will elaborate the three views in the back end. |
| 7477 |
|
| 7478 |
else |
| 7479 |
declare |
| 7480 |
Full : Entity_Id := Full_View (E); |
| 7481 |
|
| 7482 |
begin |
| 7483 |
if Is_Private_Type (Full) |
| 7484 |
and then Present (Underlying_Full_View (Full)) |
| 7485 |
then |
| 7486 |
Full := Underlying_Full_View (Full); |
| 7487 |
end if; |
| 7488 |
|
| 7489 |
Freeze_And_Append (Full, N, Result); |
| 7490 |
|
| 7491 |
if Full /= Full_View (E) |
| 7492 |
and then Has_Delayed_Freeze (Full_View (E)) |
| 7493 |
then |
| 7494 |
F_Node := Freeze_Node (Full); |
| 7495 |
|
| 7496 |
if Present (F_Node) then |
| 7497 |
Inherit_Freeze_Node |
| 7498 |
(Fnod => F_Node, Typ => Full_View (E)); |
| 7499 |
else |
| 7500 |
Set_Has_Delayed_Freeze (Full_View (E), False); |
| 7501 |
Set_Freeze_Node (Full_View (E), Empty); |
| 7502 |
end if; |
| 7503 |
end if; |
| 7504 |
|
| 7505 |
if Has_Delayed_Freeze (E) then |
| 7506 |
F_Node := Freeze_Node (Full_View (E)); |
| 7507 |
|
| 7508 |
if Present (F_Node) then |
| 7509 |
Inherit_Freeze_Node (Fnod => F_Node, Typ => E); |
| 7510 |
else |
| 7511 |
-- {Incomplete,Private}_Subtypes with Full_Views |
| 7512 |
-- constrained by discriminants. |
| 7513 |
|
| 7514 |
Set_Has_Delayed_Freeze (E, False); |
| 7515 |
Set_Freeze_Node (E, Empty); |
| 7516 |
end if; |
| 7517 |
end if; |
| 7518 |
end; |
| 7519 |
end if; |
| 7520 |
|
| 7521 |
Check_Debug_Info_Needed (E); |
| 7522 |
|
| 7523 |
-- AI95-117 requires that the convention of a partial view be |
| 7524 |
-- the same as the convention of the full view. Note that this |
| 7525 |
-- is a recognized breach of privacy, but it's essential for |
| 7526 |
-- logical consistency of representation, and the lack of a |
| 7527 |
-- rule in RM95 was an oversight. |
| 7528 |
|
| 7529 |
Set_Convention (E, Convention (Full_View (E))); |
| 7530 |
|
| 7531 |
Set_Size_Known_At_Compile_Time (E, |
| 7532 |
Size_Known_At_Compile_Time (Full_View (E))); |
| 7533 |
|
| 7534 |
-- Size information is copied from the full view to the |
| 7535 |
-- incomplete or private view for consistency. |
| 7536 |
|
| 7537 |
-- We skip this is the full view is not a type. This is very |
| 7538 |
-- strange of course, and can only happen as a result of |
| 7539 |
-- certain illegalities, such as a premature attempt to derive |
| 7540 |
-- from an incomplete type. |
| 7541 |
|
| 7542 |
if Is_Type (Full_View (E)) then |
| 7543 |
Set_Size_Info (E, Full_View (E)); |
| 7544 |
Copy_RM_Size (To => E, From => Full_View (E)); |
| 7545 |
end if; |
| 7546 |
|
| 7547 |
goto Leave; |
| 7548 |
|
| 7549 |
-- Case of underlying full view present |
| 7550 |
|
| 7551 |
elsif Is_Private_Type (E) |
| 7552 |
and then Present (Underlying_Full_View (E)) |
| 7553 |
then |
| 7554 |
if not Is_Frozen (Underlying_Full_View (E)) then |
| 7555 |
Freeze_And_Append (Underlying_Full_View (E), N, Result); |
| 7556 |
end if; |
| 7557 |
|
| 7558 |
-- Patch the pointers so that the freeze node will elaborate |
| 7559 |
-- both views in the back end. |
| 7560 |
|
| 7561 |
if Has_Delayed_Freeze (E) then |
| 7562 |
F_Node := Freeze_Node (Underlying_Full_View (E)); |
| 7563 |
|
| 7564 |
if Present (F_Node) then |
| 7565 |
Inherit_Freeze_Node |
| 7566 |
(Fnod => F_Node, |
| 7567 |
Typ => E); |
| 7568 |
else |
| 7569 |
Set_Has_Delayed_Freeze (E, False); |
| 7570 |
Set_Freeze_Node (E, Empty); |
| 7571 |
end if; |
| 7572 |
end if; |
| 7573 |
|
| 7574 |
Check_Debug_Info_Needed (E); |
| 7575 |
|
| 7576 |
goto Leave; |
| 7577 |
|
| 7578 |
-- Case of no full view present. If entity is subtype or derived, |
| 7579 |
-- it is safe to freeze, correctness depends on the frozen status |
| 7580 |
-- of parent. Otherwise it is either premature usage, or a Taft |
| 7581 |
-- amendment type, so diagnosis is at the point of use and the |
| 7582 |
-- type might be frozen later. |
| 7583 |
|
| 7584 |
elsif E /= Base_Type (E) then |
| 7585 |
declare |
| 7586 |
Btyp : constant Entity_Id := Base_Type (E); |
| 7587 |
|
| 7588 |
begin |
| 7589 |
-- However, if the base type is itself private and has no |
| 7590 |
-- (underlying) full view either, wait until the full type |
| 7591 |
-- declaration is seen and all the full views are created. |
| 7592 |
|
| 7593 |
if Is_Private_Type (Btyp) |
| 7594 |
and then No (Full_View (Btyp)) |
| 7595 |
and then No (Underlying_Full_View (Btyp)) |
| 7596 |
and then Has_Delayed_Freeze (Btyp) |
| 7597 |
and then No (Freeze_Node (Btyp)) |
| 7598 |
then |
| 7599 |
Set_Is_Frozen (E, False); |
| 7600 |
Result := No_List; |
| 7601 |
goto Leave; |
| 7602 |
end if; |
| 7603 |
end; |
| 7604 |
|
| 7605 |
elsif Is_Derived_Type (E) then |
| 7606 |
null; |
| 7607 |
|
| 7608 |
else |
| 7609 |
Set_Is_Frozen (E, False); |
| 7610 |
Result := No_List; |
| 7611 |
goto Leave; |
| 7612 |
end if; |
| 7613 |
|
| 7614 |
-- For access subprogram, freeze types of all formals, the return |
| 7615 |
-- type was already frozen, since it is the Etype of the function. |
| 7616 |
-- Formal types can be tagged Taft amendment types, but otherwise |
| 7617 |
-- they cannot be incomplete. |
| 7618 |
|
| 7619 |
elsif Ekind (E) = E_Subprogram_Type then |
| 7620 |
Formal := First_Formal (E); |
| 7621 |
while Present (Formal) loop |
| 7622 |
if Ekind (Etype (Formal)) = E_Incomplete_Type |
| 7623 |
and then No (Full_View (Etype (Formal))) |
| 7624 |
then |
| 7625 |
if Is_Tagged_Type (Etype (Formal)) then |
| 7626 |
null; |
| 7627 |
|
| 7628 |
-- AI05-151: Incomplete types are allowed in access to |
| 7629 |
-- subprogram specifications. |
| 7630 |
|
| 7631 |
elsif Ada_Version < Ada_2012 then |
| 7632 |
Error_Msg_NE |
| 7633 |
("invalid use of incomplete type&", E, Etype (Formal)); |
| 7634 |
end if; |
| 7635 |
end if; |
| 7636 |
|
| 7637 |
Freeze_And_Append (Etype (Formal), N, Result); |
| 7638 |
Next_Formal (Formal); |
| 7639 |
end loop; |
| 7640 |
|
| 7641 |
Freeze_Subprogram (E); |
| 7642 |
|
| 7643 |
-- For access to a protected subprogram, freeze the equivalent type |
| 7644 |
-- (however this is not set if we are not generating code or if this |
| 7645 |
-- is an anonymous type used just for resolution). |
| 7646 |
|
| 7647 |
elsif Is_Access_Protected_Subprogram_Type (E) then |
| 7648 |
if Present (Equivalent_Type (E)) then |
| 7649 |
Freeze_And_Append (Equivalent_Type (E), N, Result); |
| 7650 |
end if; |
| 7651 |
end if; |
| 7652 |
|
| 7653 |
-- Generic types are never seen by the back-end, and are also not |
| 7654 |
-- processed by the expander (since the expander is turned off for |
| 7655 |
-- generic processing), so we never need freeze nodes for them. |
| 7656 |
|
| 7657 |
if Is_Generic_Type (E) then |
| 7658 |
goto Leave; |
| 7659 |
end if; |
| 7660 |
|
| 7661 |
-- Some special processing for non-generic types to complete |
| 7662 |
-- representation details not known till the freeze point. |
| 7663 |
|
| 7664 |
if Is_Fixed_Point_Type (E) then |
| 7665 |
Freeze_Fixed_Point_Type (E); |
| 7666 |
|
| 7667 |
elsif Is_Enumeration_Type (E) then |
| 7668 |
Freeze_Enumeration_Type (E); |
| 7669 |
|
| 7670 |
elsif Is_Integer_Type (E) then |
| 7671 |
Adjust_Esize_For_Alignment (E); |
| 7672 |
|
| 7673 |
if Is_Modular_Integer_Type (E) then |
| 7674 |
-- Standard_Address has been built with the assumption that its |
| 7675 |
-- modulus was System_Address_Size, but this is not a universal |
| 7676 |
-- property and may need to be corrected. |
| 7677 |
|
| 7678 |
if Is_RTE (E, RE_Address) then |
| 7679 |
Set_Modulus (Standard_Address, Modulus (E)); |
| 7680 |
Set_Intval |
| 7681 |
(High_Bound (Scalar_Range (Standard_Address)), |
| 7682 |
Modulus (E) - 1); |
| 7683 |
|
| 7684 |
elsif Warn_On_Suspicious_Modulus_Value then |
| 7685 |
Check_Suspicious_Modulus (E); |
| 7686 |
end if; |
| 7687 |
end if; |
| 7688 |
|
| 7689 |
-- The pool applies to named and anonymous access types, but not |
| 7690 |
-- to subprogram and to internal types generated for 'Access |
| 7691 |
-- references. |
| 7692 |
|
| 7693 |
elsif Is_Access_Object_Type (E) |
| 7694 |
and then Ekind (E) /= E_Access_Attribute_Type |
| 7695 |
then |
| 7696 |
-- If a pragma Default_Storage_Pool applies, and this type has no |
| 7697 |
-- Storage_Pool or Storage_Size clause (which must have occurred |
| 7698 |
-- before the freezing point), then use the default. This applies |
| 7699 |
-- only to base types. |
| 7700 |
|
| 7701 |
-- None of this applies to access to subprograms, for which there |
| 7702 |
-- are clearly no pools. |
| 7703 |
|
| 7704 |
if Present (Default_Pool) |
| 7705 |
and then Is_Base_Type (E) |
| 7706 |
and then not Has_Storage_Size_Clause (E) |
| 7707 |
and then No (Associated_Storage_Pool (E)) |
| 7708 |
then |
| 7709 |
-- Case of pragma Default_Storage_Pool (null) |
| 7710 |
|
| 7711 |
if Nkind (Default_Pool) = N_Null then |
| 7712 |
Set_No_Pool_Assigned (E); |
| 7713 |
|
| 7714 |
-- Case of pragma Default_Storage_Pool (Standard) |
| 7715 |
|
| 7716 |
elsif Entity (Default_Pool) = Standard_Standard then |
| 7717 |
Set_Associated_Storage_Pool (E, RTE (RE_Global_Pool_Object)); |
| 7718 |
|
| 7719 |
-- Case of pragma Default_Storage_Pool (storage_pool_NAME) |
| 7720 |
|
| 7721 |
else |
| 7722 |
Set_Associated_Storage_Pool (E, Entity (Default_Pool)); |
| 7723 |
end if; |
| 7724 |
end if; |
| 7725 |
|
| 7726 |
-- Check restriction for standard storage pool |
| 7727 |
|
| 7728 |
if No (Associated_Storage_Pool (E)) then |
| 7729 |
Check_Restriction (No_Standard_Storage_Pools, E); |
| 7730 |
end if; |
| 7731 |
|
| 7732 |
-- Deal with error message for pure access type. This is not an |
| 7733 |
-- error in Ada 2005 if there is no pool (see AI-366). |
| 7734 |
|
| 7735 |
if Is_Pure_Unit_Access_Type (E) |
| 7736 |
and then (Ada_Version < Ada_2005 |
| 7737 |
or else not No_Pool_Assigned (E)) |
| 7738 |
and then not Is_Generic_Unit (Scope (E)) |
| 7739 |
then |
| 7740 |
Error_Msg_N ("named access type not allowed in pure unit", E); |
| 7741 |
|
| 7742 |
if Ada_Version >= Ada_2005 then |
| 7743 |
Error_Msg_N |
| 7744 |
("\would be legal if Storage_Size of 0 given", E); |
| 7745 |
|
| 7746 |
elsif No_Pool_Assigned (E) then |
| 7747 |
Error_Msg_N |
| 7748 |
("\would be legal in Ada 2005", E); |
| 7749 |
|
| 7750 |
else |
| 7751 |
Error_Msg_N |
| 7752 |
("\would be legal in Ada 2005 if " |
| 7753 |
& "Storage_Size of 0 given", E); |
| 7754 |
end if; |
| 7755 |
end if; |
| 7756 |
end if; |
| 7757 |
|
| 7758 |
-- Case of composite types |
| 7759 |
|
| 7760 |
if Is_Composite_Type (E) then |
| 7761 |
|
| 7762 |
-- AI95-117 requires that all new primitives of a tagged type |
| 7763 |
-- must inherit the convention of the full view of the |
| 7764 |
-- type. Inherited and overriding operations are defined to |
| 7765 |
-- inherit the convention of their parent or overridden |
| 7766 |
-- subprogram (also specified in AI-117), which will have |
| 7767 |
-- occurred earlier (in Derive_Subprogram and |
| 7768 |
-- New_Overloaded_Entity). Here we set the convention of |
| 7769 |
-- primitives that are still convention Ada, which will ensure |
| 7770 |
-- that any new primitives inherit the type's convention. We |
| 7771 |
-- don't do this for primitives that are internal to avoid |
| 7772 |
-- potential problems in the case of nested subprograms and |
| 7773 |
-- convention C. In addition, class-wide types can have a |
| 7774 |
-- foreign convention inherited from their specific type, but |
| 7775 |
-- are excluded from this since they don't have any associated |
| 7776 |
-- primitives. |
| 7777 |
|
| 7778 |
if Is_Tagged_Type (E) |
| 7779 |
and then not Is_Class_Wide_Type (E) |
| 7780 |
and then Convention (E) /= Convention_Ada |
| 7781 |
then |
| 7782 |
declare |
| 7783 |
Prim_List : constant Elist_Id := Primitive_Operations (E); |
| 7784 |
Prim : Elmt_Id; |
| 7785 |
|
| 7786 |
begin |
| 7787 |
Prim := First_Elmt (Prim_List); |
| 7788 |
while Present (Prim) loop |
| 7789 |
if Convention (Node (Prim)) = Convention_Ada |
| 7790 |
and then Comes_From_Source (Node (Prim)) |
| 7791 |
then |
| 7792 |
Set_Convention (Node (Prim), Convention (E)); |
| 7793 |
end if; |
| 7794 |
|
| 7795 |
Next_Elmt (Prim); |
| 7796 |
end loop; |
| 7797 |
end; |
| 7798 |
end if; |
| 7799 |
|
| 7800 |
-- If the type is a simple storage pool type, then this is where |
| 7801 |
-- we attempt to locate and validate its Allocate, Deallocate, and |
| 7802 |
-- Storage_Size operations (the first is required, and the latter |
| 7803 |
-- two are optional). We also verify that the full type for a |
| 7804 |
-- private type is allowed to be a simple storage pool type. |
| 7805 |
|
| 7806 |
if Present (Get_Rep_Pragma (E, Name_Simple_Storage_Pool_Type)) |
| 7807 |
and then (Is_Base_Type (E) or else Has_Private_Declaration (E)) |
| 7808 |
then |
| 7809 |
-- If the type is marked Has_Private_Declaration, then this is |
| 7810 |
-- a full type for a private type that was specified with the |
| 7811 |
-- pragma Simple_Storage_Pool_Type, and here we ensure that the |
| 7812 |
-- pragma is allowed for the full type (for example, it can't |
| 7813 |
-- be an array type, or a nonlimited record type). |
| 7814 |
|
| 7815 |
if Has_Private_Declaration (E) then |
| 7816 |
if (not Is_Record_Type (E) |
| 7817 |
or else not Is_Inherently_Limited_Type (E)) |
| 7818 |
and then not Is_Private_Type (E) |
| 7819 |
then |
| 7820 |
Error_Msg_Name_1 := Name_Simple_Storage_Pool_Type; |
| 7821 |
Error_Msg_N |
| 7822 |
("pragma% can only apply to full type that is an " & |
| 7823 |
"explicitly limited type", E); |
| 7824 |
end if; |
| 7825 |
end if; |
| 7826 |
|
| 7827 |
Validate_Simple_Pool_Ops : declare |
| 7828 |
Pool_Type : Entity_Id renames E; |
| 7829 |
Address_Type : constant Entity_Id := RTE (RE_Address); |
| 7830 |
Stg_Cnt_Type : constant Entity_Id := RTE (RE_Storage_Count); |
| 7831 |
|
| 7832 |
procedure Validate_Simple_Pool_Op_Formal |
| 7833 |
(Pool_Op : Entity_Id; |
| 7834 |
Pool_Op_Formal : in out Entity_Id; |
| 7835 |
Expected_Mode : Formal_Kind; |
| 7836 |
Expected_Type : Entity_Id; |
| 7837 |
Formal_Name : String; |
| 7838 |
OK_Formal : in out Boolean); |
| 7839 |
-- Validate one formal Pool_Op_Formal of the candidate pool |
| 7840 |
-- operation Pool_Op. The formal must be of Expected_Type |
| 7841 |
-- and have mode Expected_Mode. OK_Formal will be set to |
| 7842 |
-- False if the formal doesn't match. If OK_Formal is False |
| 7843 |
-- on entry, then the formal will effectively be ignored |
| 7844 |
-- (because validation of the pool op has already failed). |
| 7845 |
-- Upon return, Pool_Op_Formal will be updated to the next |
| 7846 |
-- formal, if any. |
| 7847 |
|
| 7848 |
procedure Validate_Simple_Pool_Operation |
| 7849 |
(Op_Name : Name_Id); |
| 7850 |
-- Search for and validate a simple pool operation with the |
| 7851 |
-- name Op_Name. If the name is Allocate, then there must be |
| 7852 |
-- exactly one such primitive operation for the simple pool |
| 7853 |
-- type. If the name is Deallocate or Storage_Size, then |
| 7854 |
-- there can be at most one such primitive operation. The |
| 7855 |
-- profile of the located primitive must conform to what |
| 7856 |
-- is expected for each operation. |
| 7857 |
|
| 7858 |
------------------------------------ |
| 7859 |
-- Validate_Simple_Pool_Op_Formal -- |
| 7860 |
------------------------------------ |
| 7861 |
|
| 7862 |
procedure Validate_Simple_Pool_Op_Formal |
| 7863 |
(Pool_Op : Entity_Id; |
| 7864 |
Pool_Op_Formal : in out Entity_Id; |
| 7865 |
Expected_Mode : Formal_Kind; |
| 7866 |
Expected_Type : Entity_Id; |
| 7867 |
Formal_Name : String; |
| 7868 |
OK_Formal : in out Boolean) |
| 7869 |
is |
| 7870 |
begin |
| 7871 |
-- If OK_Formal is False on entry, then simply ignore |
| 7872 |
-- the formal, because an earlier formal has already |
| 7873 |
-- been flagged. |
| 7874 |
|
| 7875 |
if not OK_Formal then |
| 7876 |
return; |
| 7877 |
|
| 7878 |
-- If no formal is passed in, then issue an error for a |
| 7879 |
-- missing formal. |
| 7880 |
|
| 7881 |
elsif No (Pool_Op_Formal) then |
| 7882 |
Error_Msg_NE |
| 7883 |
("simple storage pool op missing formal " & |
| 7884 |
Formal_Name & " of type&", Pool_Op, Expected_Type); |
| 7885 |
OK_Formal := False; |
| 7886 |
|
| 7887 |
return; |
| 7888 |
end if; |
| 7889 |
|
| 7890 |
if Etype (Pool_Op_Formal) /= Expected_Type then |
| 7891 |
|
| 7892 |
-- If the pool type was expected for this formal, then |
| 7893 |
-- this will not be considered a candidate operation |
| 7894 |
-- for the simple pool, so we unset OK_Formal so that |
| 7895 |
-- the op and any later formals will be ignored. |
| 7896 |
|
| 7897 |
if Expected_Type = Pool_Type then |
| 7898 |
OK_Formal := False; |
| 7899 |
|
| 7900 |
return; |
| 7901 |
|
| 7902 |
else |
| 7903 |
Error_Msg_NE |
| 7904 |
("wrong type for formal " & Formal_Name & |
| 7905 |
" of simple storage pool op; expected type&", |
| 7906 |
Pool_Op_Formal, Expected_Type); |
| 7907 |
end if; |
| 7908 |
end if; |
| 7909 |
|
| 7910 |
-- Issue error if formal's mode is not the expected one |
| 7911 |
|
| 7912 |
if Ekind (Pool_Op_Formal) /= Expected_Mode then |
| 7913 |
Error_Msg_N |
| 7914 |
("wrong mode for formal of simple storage pool op", |
| 7915 |
Pool_Op_Formal); |
| 7916 |
end if; |
| 7917 |
|
| 7918 |
-- Advance to the next formal |
| 7919 |
|
| 7920 |
Next_Formal (Pool_Op_Formal); |
| 7921 |
end Validate_Simple_Pool_Op_Formal; |
| 7922 |
|
| 7923 |
------------------------------------ |
| 7924 |
-- Validate_Simple_Pool_Operation -- |
| 7925 |
------------------------------------ |
| 7926 |
|
| 7927 |
procedure Validate_Simple_Pool_Operation |
| 7928 |
(Op_Name : Name_Id) |
| 7929 |
is |
| 7930 |
Op : Entity_Id; |
| 7931 |
Found_Op : Entity_Id := Empty; |
| 7932 |
Formal : Entity_Id; |
| 7933 |
Is_OK : Boolean; |
| 7934 |
|
| 7935 |
begin |
| 7936 |
pragma Assert |
| 7937 |
(Op_Name in Name_Allocate |
| 7938 |
| Name_Deallocate |
| 7939 |
| Name_Storage_Size); |
| 7940 |
|
| 7941 |
Error_Msg_Name_1 := Op_Name; |
| 7942 |
|
| 7943 |
-- For each homonym declared immediately in the scope |
| 7944 |
-- of the simple storage pool type, determine whether |
| 7945 |
-- the homonym is an operation of the pool type, and, |
| 7946 |
-- if so, check that its profile is as expected for |
| 7947 |
-- a simple pool operation of that name. |
| 7948 |
|
| 7949 |
Op := Get_Name_Entity_Id (Op_Name); |
| 7950 |
while Present (Op) loop |
| 7951 |
if Ekind (Op) in E_Function | E_Procedure |
| 7952 |
and then Scope (Op) = Current_Scope |
| 7953 |
then |
| 7954 |
Formal := First_Entity (Op); |
| 7955 |
|
| 7956 |
Is_OK := True; |
| 7957 |
|
| 7958 |
-- The first parameter must be of the pool type |
| 7959 |
-- in order for the operation to qualify. |
| 7960 |
|
| 7961 |
if Op_Name = Name_Storage_Size then |
| 7962 |
Validate_Simple_Pool_Op_Formal |
| 7963 |
(Op, Formal, E_In_Parameter, Pool_Type, |
| 7964 |
"Pool", Is_OK); |
| 7965 |
else |
| 7966 |
Validate_Simple_Pool_Op_Formal |
| 7967 |
(Op, Formal, E_In_Out_Parameter, Pool_Type, |
| 7968 |
"Pool", Is_OK); |
| 7969 |
end if; |
| 7970 |
|
| 7971 |
-- If another operation with this name has already |
| 7972 |
-- been located for the type, then flag an error, |
| 7973 |
-- since we only allow the type to have a single |
| 7974 |
-- such primitive. |
| 7975 |
|
| 7976 |
if Present (Found_Op) and then Is_OK then |
| 7977 |
Error_Msg_NE |
| 7978 |
("only one % operation allowed for " & |
| 7979 |
"simple storage pool type&", Op, Pool_Type); |
| 7980 |
end if; |
| 7981 |
|
| 7982 |
-- In the case of Allocate and Deallocate, a formal |
| 7983 |
-- of type System.Address is required. |
| 7984 |
|
| 7985 |
if Op_Name = Name_Allocate then |
| 7986 |
Validate_Simple_Pool_Op_Formal |
| 7987 |
(Op, Formal, E_Out_Parameter, |
| 7988 |
Address_Type, "Storage_Address", Is_OK); |
| 7989 |
|
| 7990 |
elsif Op_Name = Name_Deallocate then |
| 7991 |
Validate_Simple_Pool_Op_Formal |
| 7992 |
(Op, Formal, E_In_Parameter, |
| 7993 |
Address_Type, "Storage_Address", Is_OK); |
| 7994 |
end if; |
| 7995 |
|
| 7996 |
-- In the case of Allocate and Deallocate, formals |
| 7997 |
-- of type Storage_Count are required as the third |
| 7998 |
-- and fourth parameters. |
| 7999 |
|
| 8000 |
if Op_Name /= Name_Storage_Size then |
| 8001 |
Validate_Simple_Pool_Op_Formal |
| 8002 |
(Op, Formal, E_In_Parameter, |
| 8003 |
Stg_Cnt_Type, "Size_In_Storage_Units", Is_OK); |
| 8004 |
Validate_Simple_Pool_Op_Formal |
| 8005 |
(Op, Formal, E_In_Parameter, |
| 8006 |
Stg_Cnt_Type, "Alignment", Is_OK); |
| 8007 |
end if; |
| 8008 |
|
| 8009 |
-- If no mismatched formals have been found (Is_OK) |
| 8010 |
-- and no excess formals are present, then this |
| 8011 |
-- operation has been validated, so record it. |
| 8012 |
|
| 8013 |
if No (Formal) and then Is_OK then |
| 8014 |
Found_Op := Op; |
| 8015 |
end if; |
| 8016 |
end if; |
| 8017 |
|
| 8018 |
Op := Homonym (Op); |
| 8019 |
end loop; |
| 8020 |
|
| 8021 |
-- There must be a valid Allocate operation for the type, |
| 8022 |
-- so issue an error if none was found. |
| 8023 |
|
| 8024 |
if Op_Name = Name_Allocate |
| 8025 |
and then No (Found_Op) |
| 8026 |
then |
| 8027 |
Error_Msg_N ("missing % operation for simple " & |
| 8028 |
"storage pool type", Pool_Type); |
| 8029 |
|
| 8030 |
elsif Present (Found_Op) then |
| 8031 |
|
| 8032 |
-- Simple pool operations can't be abstract |
| 8033 |
|
| 8034 |
if Is_Abstract_Subprogram (Found_Op) then |
| 8035 |
Error_Msg_N |
| 8036 |
("simple storage pool operation must not be " & |
| 8037 |
"abstract", Found_Op); |
| 8038 |
end if; |
| 8039 |
|
| 8040 |
-- The Storage_Size operation must be a function with |
| 8041 |
-- Storage_Count as its result type. |
| 8042 |
|
| 8043 |
if Op_Name = Name_Storage_Size then |
| 8044 |
if Ekind (Found_Op) = E_Procedure then |
| 8045 |
Error_Msg_N |
| 8046 |
("% operation must be a function", Found_Op); |
| 8047 |
|
| 8048 |
elsif Etype (Found_Op) /= Stg_Cnt_Type then |
| 8049 |
Error_Msg_NE |
| 8050 |
("wrong result type for%, expected type&", |
| 8051 |
Found_Op, Stg_Cnt_Type); |
| 8052 |
end if; |
| 8053 |
|
| 8054 |
-- Allocate and Deallocate must be procedures |
| 8055 |
|
| 8056 |
elsif Ekind (Found_Op) = E_Function then |
| 8057 |
Error_Msg_N |
| 8058 |
("% operation must be a procedure", Found_Op); |
| 8059 |
end if; |
| 8060 |
end if; |
| 8061 |
end Validate_Simple_Pool_Operation; |
| 8062 |
|
| 8063 |
-- Start of processing for Validate_Simple_Pool_Ops |
| 8064 |
|
| 8065 |
begin |
| 8066 |
Validate_Simple_Pool_Operation (Name_Allocate); |
| 8067 |
Validate_Simple_Pool_Operation (Name_Deallocate); |
| 8068 |
Validate_Simple_Pool_Operation (Name_Storage_Size); |
| 8069 |
end Validate_Simple_Pool_Ops; |
| 8070 |
end if; |
| 8071 |
end if; |
| 8072 |
|
| 8073 |
-- Now that all types from which E may depend are frozen, see if |
| 8074 |
-- strict alignment is required, a component clause on a record |
| 8075 |
-- is correct, the size is known at compile time and if it must |
| 8076 |
-- be unsigned, in that order. |
| 8077 |
|
| 8078 |
if Base_Type (E) = E then |
| 8079 |
Check_Strict_Alignment (E); |
| 8080 |
end if; |
| 8081 |
|
| 8082 |
if Ekind (E) in E_Record_Type | E_Record_Subtype then |
| 8083 |
declare |
| 8084 |
RC : constant Node_Id := Get_Record_Representation_Clause (E); |
| 8085 |
begin |
| 8086 |
if Present (RC) then |
| 8087 |
Check_Record_Representation_Clause (RC); |
| 8088 |
end if; |
| 8089 |
end; |
| 8090 |
end if; |
| 8091 |
|
| 8092 |
Check_Compile_Time_Size (E); |
| 8093 |
|
| 8094 |
Check_Unsigned_Type (E); |
| 8095 |
|
| 8096 |
-- Do not allow a size clause for a type which does not have a size |
| 8097 |
-- that is known at compile time |
| 8098 |
|
| 8099 |
if (Has_Size_Clause (E) or else Has_Object_Size_Clause (E)) |
| 8100 |
and then not Size_Known_At_Compile_Time (E) |
| 8101 |
and then not Is_Mutably_Tagged_Type (E) |
| 8102 |
then |
| 8103 |
-- Suppress this message if errors posted on E, even if we are |
| 8104 |
-- in all errors mode, since this is often a junk message |
| 8105 |
|
| 8106 |
if not Error_Posted (E) then |
| 8107 |
Error_Msg_N |
| 8108 |
("size clause not allowed for variable length type", |
| 8109 |
Size_Clause (E)); |
| 8110 |
end if; |
| 8111 |
end if; |
| 8112 |
|
| 8113 |
-- Now we set/verify the representation information, in particular |
| 8114 |
-- the size and alignment values. This processing is not required for |
| 8115 |
-- generic types, since generic types do not play any part in code |
| 8116 |
-- generation, and so the size and alignment values for such types |
| 8117 |
-- are irrelevant. Ditto for types declared within a generic unit, |
| 8118 |
-- which may have components that depend on generic parameters, and |
| 8119 |
-- that will be recreated in an instance, except for static subtypes |
| 8120 |
-- because they may be referenced in the static expressions of the |
| 8121 |
-- generic unit, which need to be evaluated during its processing. |
| 8122 |
|
| 8123 |
if Inside_A_Generic and then not Is_Static_Subtype (E) then |
| 8124 |
null; |
| 8125 |
|
| 8126 |
-- Otherwise we call the layout procedure |
| 8127 |
|
| 8128 |
else |
| 8129 |
Layout_Type (E); |
| 8130 |
end if; |
| 8131 |
|
| 8132 |
-- If this is an access to subprogram whose designated type is itself |
| 8133 |
-- a subprogram type, the return type of this anonymous subprogram |
| 8134 |
-- type must be decorated as well. |
| 8135 |
|
| 8136 |
if Ekind (E) = E_Anonymous_Access_Subprogram_Type |
| 8137 |
and then Ekind (Designated_Type (E)) = E_Subprogram_Type |
| 8138 |
then |
| 8139 |
Layout_Type (Etype (Designated_Type (E))); |
| 8140 |
end if; |
| 8141 |
|
| 8142 |
-- If the type has a Defaut_Value/Default_Component_Value aspect, |
| 8143 |
-- this is where we analyze the expression (after the type is frozen, |
| 8144 |
-- since in the case of Default_Value, we are analyzing with the |
| 8145 |
-- type itself, and we treat Default_Component_Value similarly for |
| 8146 |
-- the sake of uniformity). |
| 8147 |
|
| 8148 |
-- But for an inherited Default_Value aspect specification, the type |
| 8149 |
-- of the aspect remains the parent type. RM 3.3.1(11.1), a dynamic |
| 8150 |
-- semantics rule, says "The implicit initial value for a scalar |
| 8151 |
-- subtype that has the Default_Value aspect specified is the value |
| 8152 |
-- of that aspect converted to the nominal subtype". For an inherited |
| 8153 |
-- Default_Value aspect specification, no conversion is evaluated at |
| 8154 |
-- the point of the derived type declaration. |
| 8155 |
|
| 8156 |
if Is_First_Subtype (E) |
| 8157 |
and then Has_Default_Aspect (E) |
| 8158 |
and then |
| 8159 |
(not Is_Scalar_Type (E) |
| 8160 |
or else |
| 8161 |
not Is_Derived_Type (E) |
| 8162 |
or else |
| 8163 |
Default_Aspect_Value (E) |
| 8164 |
/= Default_Aspect_Value (Etype (Base_Type (E)))) |
| 8165 |
then |
| 8166 |
declare |
| 8167 |
Nam : Name_Id; |
| 8168 |
Exp : Node_Id; |
| 8169 |
Typ : Entity_Id; |
| 8170 |
|
| 8171 |
begin |
| 8172 |
if Is_Scalar_Type (E) then |
| 8173 |
Nam := Name_Default_Value; |
| 8174 |
Typ := E; |
| 8175 |
Exp := Default_Aspect_Value (Typ); |
| 8176 |
else |
| 8177 |
Nam := Name_Default_Component_Value; |
| 8178 |
Typ := Component_Type (E); |
| 8179 |
Exp := Default_Aspect_Component_Value (E); |
| 8180 |
end if; |
| 8181 |
|
| 8182 |
Analyze_And_Resolve (Exp, Typ); |
| 8183 |
|
| 8184 |
if Etype (Exp) /= Any_Type then |
| 8185 |
if not Is_OK_Static_Expression (Exp) then |
| 8186 |
Error_Msg_Name_1 := Nam; |
| 8187 |
Flag_Non_Static_Expr |
| 8188 |
("aspect% requires static expression", Exp); |
| 8189 |
end if; |
| 8190 |
end if; |
| 8191 |
end; |
| 8192 |
end if; |
| 8193 |
|
| 8194 |
-- Verify at this point that No_Controlled_Parts and No_Task_Parts, |
| 8195 |
-- when specified on the current type or one of its ancestors, has |
| 8196 |
-- not been overridden and that no violation of the aspect has |
| 8197 |
-- occurred. |
| 8198 |
|
| 8199 |
-- It is important that we perform the checks here after the type has |
| 8200 |
-- been processed because if said type depended on a private type it |
| 8201 |
-- will not have been marked controlled or having tasks. |
| 8202 |
|
| 8203 |
Check_No_Parts_Violations (E, Aspect_No_Controlled_Parts); |
| 8204 |
Check_No_Parts_Violations (E, Aspect_No_Task_Parts); |
| 8205 |
|
| 8206 |
-- End of freeze processing for type entities |
| 8207 |
end if; |
| 8208 |
|
| 8209 |
-- Here is where we logically freeze the current entity. If it has a |
| 8210 |
-- freeze node, then this is the point at which the freeze node is |
| 8211 |
-- linked into the result list. |
| 8212 |
|
| 8213 |
if Has_Delayed_Freeze (E) then |
| 8214 |
|
| 8215 |
-- If a freeze node is already allocated, use it, otherwise allocate |
| 8216 |
-- a new one. The preallocation happens in the case of anonymous base |
| 8217 |
-- types, where we preallocate so that we can set First_Subtype_Link. |
| 8218 |
-- Note that we reset the Sloc to the current freeze location. |
| 8219 |
|
| 8220 |
if Present (Freeze_Node (E)) then |
| 8221 |
F_Node := Freeze_Node (E); |
| 8222 |
Set_Sloc (F_Node, Loc); |
| 8223 |
|
| 8224 |
else |
| 8225 |
F_Node := New_Node (N_Freeze_Entity, Loc); |
| 8226 |
Set_Freeze_Node (E, F_Node); |
| 8227 |
Set_Access_Types_To_Process (F_Node, No_Elist); |
| 8228 |
Set_TSS_Elist (F_Node, No_Elist); |
| 8229 |
Set_Actions (F_Node, No_List); |
| 8230 |
end if; |
| 8231 |
|
| 8232 |
Set_Entity (F_Node, E); |
| 8233 |
Add_To_Result (F_Node); |
| 8234 |
|
| 8235 |
-- A final pass over record types with discriminants. If the type |
| 8236 |
-- has an incomplete declaration, there may be constrained access |
| 8237 |
-- subtypes declared elsewhere, which do not depend on the discrimi- |
| 8238 |
-- nants of the type, and which are used as component types (i.e. |
| 8239 |
-- the full view is a recursive type). The designated types of these |
| 8240 |
-- subtypes can only be elaborated after the type itself, and they |
| 8241 |
-- need an itype reference. |
| 8242 |
|
| 8243 |
if Ekind (E) = E_Record_Type and then Has_Discriminants (E) then |
| 8244 |
declare |
| 8245 |
Comp : Entity_Id; |
| 8246 |
IR : Node_Id; |
| 8247 |
Typ : Entity_Id; |
| 8248 |
|
| 8249 |
begin |
| 8250 |
Comp := First_Component (E); |
| 8251 |
while Present (Comp) loop |
| 8252 |
Typ := Etype (Comp); |
| 8253 |
|
| 8254 |
if Is_Access_Type (Typ) |
| 8255 |
and then Scope (Typ) /= E |
| 8256 |
and then Base_Type (Designated_Type (Typ)) = E |
| 8257 |
and then Is_Itype (Designated_Type (Typ)) |
| 8258 |
then |
| 8259 |
IR := Make_Itype_Reference (Sloc (Comp)); |
| 8260 |
Set_Itype (IR, Designated_Type (Typ)); |
| 8261 |
Append (IR, Result); |
| 8262 |
end if; |
| 8263 |
|
| 8264 |
Next_Component (Comp); |
| 8265 |
end loop; |
| 8266 |
end; |
| 8267 |
end if; |
| 8268 |
end if; |
| 8269 |
|
| 8270 |
-- When a type is frozen, the first subtype of the type is frozen as |
| 8271 |
-- well (RM 13.14(15)). This has to be done after freezing the type, |
| 8272 |
-- since obviously the first subtype depends on its own base type. |
| 8273 |
|
| 8274 |
if Is_Type (E) then |
| 8275 |
Freeze_And_Append (First_Subtype (E), N, Result); |
| 8276 |
|
| 8277 |
-- If we just froze a tagged non-class-wide record, then freeze the |
| 8278 |
-- corresponding class-wide type. This must be done after the tagged |
| 8279 |
-- type itself is frozen, because the class-wide type refers to the |
| 8280 |
-- tagged type which generates the class. |
| 8281 |
|
| 8282 |
-- For a tagged type, freeze explicitly those primitive operations |
| 8283 |
-- that are expression functions, which otherwise have no clear |
| 8284 |
-- freeze point: these have to be frozen before the dispatch table |
| 8285 |
-- for the type is built, and before any explicit call to the |
| 8286 |
-- primitive, which would otherwise be the freeze point for it. |
| 8287 |
|
| 8288 |
if Is_Tagged_Type (E) |
| 8289 |
and then not Is_Class_Wide_Type (E) |
| 8290 |
and then Present (Class_Wide_Type (E)) |
| 8291 |
then |
| 8292 |
Freeze_And_Append (Class_Wide_Type (E), N, Result); |
| 8293 |
|
| 8294 |
declare |
| 8295 |
Ops : constant Elist_Id := Primitive_Operations (E); |
| 8296 |
|
| 8297 |
Elmt : Elmt_Id; |
| 8298 |
Subp : Entity_Id; |
| 8299 |
|
| 8300 |
begin |
| 8301 |
if Ops /= No_Elist then |
| 8302 |
Elmt := First_Elmt (Ops); |
| 8303 |
while Present (Elmt) loop |
| 8304 |
Subp := Node (Elmt); |
| 8305 |
if Is_Expression_Function (Subp) then |
| 8306 |
Freeze_And_Append (Subp, N, Result); |
| 8307 |
end if; |
| 8308 |
|
| 8309 |
Next_Elmt (Elmt); |
| 8310 |
end loop; |
| 8311 |
end if; |
| 8312 |
end; |
| 8313 |
end if; |
| 8314 |
end if; |
| 8315 |
|
| 8316 |
Check_Debug_Info_Needed (E); |
| 8317 |
|
| 8318 |
-- If subprogram has address clause then reset Is_Public flag, since we |
| 8319 |
-- do not want the backend to generate external references. |
| 8320 |
|
| 8321 |
if Is_Subprogram (E) |
| 8322 |
and then Present (Address_Clause (E)) |
| 8323 |
and then not Is_Library_Level_Entity (E) |
| 8324 |
then |
| 8325 |
Set_Is_Public (E, False); |
| 8326 |
end if; |
| 8327 |
|
| 8328 |
-- The Ghost mode of the enclosing context is ignored, while the |
| 8329 |
-- entity being frozen is living. Insert the freezing action prior |
| 8330 |
-- to the start of the enclosing ignored Ghost region. As a result |
| 8331 |
-- the freezeing action will be preserved when the ignored Ghost |
| 8332 |
-- context is eliminated. The insertion must take place even when |
| 8333 |
-- the context is a spec expression, otherwise "Handling of Default |
| 8334 |
-- and Per-Object Expressions" will suppress the insertion, and the |
| 8335 |
-- freeze node will be dropped on the floor. |
| 8336 |
|
| 8337 |
if Saved_GM = Ignore |
| 8338 |
and then Ghost_Mode /= Ignore |
| 8339 |
and then Present (Ignored_Ghost_Region) |
| 8340 |
then |
| 8341 |
Insert_Actions |
| 8342 |
(Assoc_Node => Ignored_Ghost_Region, |
| 8343 |
Ins_Actions => Result, |
| 8344 |
Spec_Expr_OK => True); |
| 8345 |
|
| 8346 |
Result := No_List; |
| 8347 |
end if; |
| 8348 |
|
| 8349 |
<<Leave>> |
| 8350 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 8351 |
|
| 8352 |
return Result; |
| 8353 |
end Freeze_Entity; |
| 8354 |
|
| 8355 |
----------------------------- |
| 8356 |
-- Freeze_Enumeration_Type -- |
| 8357 |
----------------------------- |
| 8358 |
|
| 8359 |
procedure Freeze_Enumeration_Type (Typ : Entity_Id) is |
| 8360 |
begin |
| 8361 |
-- By default, if no size clause is present, an enumeration type with |
| 8362 |
-- Convention C is assumed to interface to a C enum and has integer |
| 8363 |
-- size, except for a boolean type because it is assumed to interface |
| 8364 |
-- to _Bool introduced in C99. This applies to types. For subtypes, |
| 8365 |
-- verify that its base type has no size clause either. Treat other |
| 8366 |
-- foreign conventions in the same way, and also make sure alignment |
| 8367 |
-- is set right. |
| 8368 |
|
| 8369 |
if Has_Foreign_Convention (Typ) |
| 8370 |
and then not Is_Boolean_Type (Typ) |
| 8371 |
and then not Has_Size_Clause (Typ) |
| 8372 |
and then not Has_Size_Clause (Base_Type (Typ)) |
| 8373 |
and then Esize (Typ) < Standard_Integer_Size |
| 8374 |
|
| 8375 |
-- Don't do this if Short_Enums on target |
| 8376 |
|
| 8377 |
and then not Target_Short_Enums |
| 8378 |
then |
| 8379 |
Set_Esize (Typ, UI_From_Int (Standard_Integer_Size)); |
| 8380 |
Set_Alignment (Typ, Alignment (Standard_Integer)); |
| 8381 |
|
| 8382 |
-- Normal Ada case or size clause present or not Long_C_Enums on target |
| 8383 |
|
| 8384 |
else |
| 8385 |
-- If the enumeration type interfaces to C, and it has a size clause |
| 8386 |
-- that is smaller than the size of int, it warrants a warning. The |
| 8387 |
-- user may intend the C type to be a boolean or a char, so this is |
| 8388 |
-- not by itself an error that the Ada compiler can detect, but it |
| 8389 |
-- is worth a heads-up. For Boolean and Character types we |
| 8390 |
-- assume that the programmer has the proper C type in mind. |
| 8391 |
-- For explicit sizes larger than int, assume the user knows what |
| 8392 |
-- he is doing and that the code is intentional. |
| 8393 |
|
| 8394 |
if Convention (Typ) = Convention_C |
| 8395 |
and then Has_Size_Clause (Typ) |
| 8396 |
and then Esize (Typ) < Standard_Integer_Size |
| 8397 |
and then not Is_Boolean_Type (Typ) |
| 8398 |
and then not Is_Character_Type (Typ) |
| 8399 |
|
| 8400 |
-- Don't do this if Short_Enums on target |
| 8401 |
|
| 8402 |
and then not Target_Short_Enums |
| 8403 |
then |
| 8404 |
Error_Msg_N |
| 8405 |
("??the size of enums in C is implementation-defined", |
| 8406 |
Size_Clause (Typ)); |
| 8407 |
Error_Msg_N |
| 8408 |
("\??check that the C counterpart has size of " & |
| 8409 |
UI_Image (Esize (Typ)), |
| 8410 |
Size_Clause (Typ)); |
| 8411 |
end if; |
| 8412 |
|
| 8413 |
Adjust_Esize_For_Alignment (Typ); |
| 8414 |
end if; |
| 8415 |
|
| 8416 |
-- Reject a very large size on a type with a non-standard representation |
| 8417 |
-- because Expand_Freeze_Enumeration_Type cannot deal with it. |
| 8418 |
|
| 8419 |
if Has_Non_Standard_Rep (Typ) |
| 8420 |
and then Known_Esize (Typ) |
| 8421 |
and then Esize (Typ) > System_Max_Integer_Size |
| 8422 |
then |
| 8423 |
Error_Msg_N |
| 8424 |
("enumeration type with representation clause too large", Typ); |
| 8425 |
Error_Msg_Uint_1 := UI_From_Int (System_Max_Integer_Size); |
| 8426 |
Error_Msg_N |
| 8427 |
("\the size of such a type cannot exceed ^ bits", Typ); |
| 8428 |
end if; |
| 8429 |
end Freeze_Enumeration_Type; |
| 8430 |
|
| 8431 |
----------------------- |
| 8432 |
-- Freeze_Expression -- |
| 8433 |
----------------------- |
| 8434 |
|
| 8435 |
procedure Freeze_Expression (N : Node_Id) is |
| 8436 |
|
| 8437 |
function Declared_In_Expanded_Body |
| 8438 |
(N : Node_Id; |
| 8439 |
Typ : Entity_Id; |
| 8440 |
Nam : Entity_Id) return Boolean; |
| 8441 |
-- Given the N_Handled_Sequence_Of_Statements node of an expander |
| 8442 |
-- generated subprogram body, determines if the frozen entity is |
| 8443 |
-- declared inside this body. This is recognized locating the |
| 8444 |
-- enclosing subprogram of the entity Name or its Type and |
| 8445 |
-- checking if it is this subprogram body. |
| 8446 |
|
| 8447 |
function Find_Aggregate_Component_Desig_Type return Entity_Id; |
| 8448 |
-- If the expression is an array aggregate, the type of the component |
| 8449 |
-- expressions is also frozen. If the component type is an access type |
| 8450 |
-- and the expressions include allocators, the designed type is frozen |
| 8451 |
-- as well. |
| 8452 |
|
| 8453 |
function In_Expanded_Body (N : Node_Id) return Boolean; |
| 8454 |
-- Given an N_Handled_Sequence_Of_Statements node, determines whether it |
| 8455 |
-- is the statement sequence of an expander-generated subprogram body or |
| 8456 |
-- of a renaming_as_body. If so, this is not a freezing context and the |
| 8457 |
-- entity will be frozen at a later point. |
| 8458 |
|
| 8459 |
function Has_Decl_In_List |
| 8460 |
(E : Entity_Id; |
| 8461 |
N : Node_Id; |
| 8462 |
L : List_Id) return Boolean; |
| 8463 |
-- Determines whether an entity E referenced in node N is declared in |
| 8464 |
-- the list L. |
| 8465 |
|
| 8466 |
------------------------------- |
| 8467 |
-- Declared_In_Expanded_Body -- |
| 8468 |
------------------------------- |
| 8469 |
|
| 8470 |
function Declared_In_Expanded_Body |
| 8471 |
(N : Node_Id; |
| 8472 |
Typ : Entity_Id; |
| 8473 |
Nam : Entity_Id) return Boolean |
| 8474 |
is |
| 8475 |
pragma Assert (In_Expanded_Body (N)); |
| 8476 |
|
| 8477 |
Subp_Body : constant Node_Id := Parent (N); |
| 8478 |
Subp_Id : Entity_Id; |
| 8479 |
Scop : Entity_Id; |
| 8480 |
|
| 8481 |
begin |
| 8482 |
if Acts_As_Spec (Subp_Body) then |
| 8483 |
Subp_Id := Unique_Defining_Entity (Specification (Subp_Body)); |
| 8484 |
else |
| 8485 |
Subp_Id := Corresponding_Spec (Subp_Body); |
| 8486 |
end if; |
| 8487 |
|
| 8488 |
if Present (Typ) then |
| 8489 |
Scop := Scope (Typ); |
| 8490 |
elsif Present (Nam) then |
| 8491 |
Scop := Scope (Nam); |
| 8492 |
else |
| 8493 |
Scop := Standard_Standard; |
| 8494 |
end if; |
| 8495 |
|
| 8496 |
while Scop /= Standard_Standard |
| 8497 |
and then not Is_Subprogram (Scop) |
| 8498 |
loop |
| 8499 |
Scop := Scope (Scop); |
| 8500 |
end loop; |
| 8501 |
|
| 8502 |
return Scop = Subp_Id; |
| 8503 |
end Declared_In_Expanded_Body; |
| 8504 |
|
| 8505 |
----------------------------------------- |
| 8506 |
-- Find_Aggregate_Component_Desig_Type -- |
| 8507 |
----------------------------------------- |
| 8508 |
|
| 8509 |
function Find_Aggregate_Component_Desig_Type return Entity_Id is |
| 8510 |
Assoc : Node_Id; |
| 8511 |
Exp : Node_Id; |
| 8512 |
|
| 8513 |
begin |
| 8514 |
if Present (Expressions (N)) then |
| 8515 |
Exp := First (Expressions (N)); |
| 8516 |
while Present (Exp) loop |
| 8517 |
if Nkind (Exp) = N_Allocator then |
| 8518 |
return Designated_Type (Component_Type (Etype (N))); |
| 8519 |
end if; |
| 8520 |
|
| 8521 |
Next (Exp); |
| 8522 |
end loop; |
| 8523 |
end if; |
| 8524 |
|
| 8525 |
if Present (Component_Associations (N)) then |
| 8526 |
Assoc := First (Component_Associations (N)); |
| 8527 |
while Present (Assoc) loop |
| 8528 |
if Nkind (Expression (Assoc)) = N_Allocator then |
| 8529 |
return Designated_Type (Component_Type (Etype (N))); |
| 8530 |
end if; |
| 8531 |
|
| 8532 |
Next (Assoc); |
| 8533 |
end loop; |
| 8534 |
end if; |
| 8535 |
|
| 8536 |
return Empty; |
| 8537 |
end Find_Aggregate_Component_Desig_Type; |
| 8538 |
|
| 8539 |
---------------------- |
| 8540 |
-- In_Expanded_Body -- |
| 8541 |
---------------------- |
| 8542 |
|
| 8543 |
function In_Expanded_Body (N : Node_Id) return Boolean is |
| 8544 |
P : constant Node_Id := Parent (N); |
| 8545 |
Id : Entity_Id; |
| 8546 |
|
| 8547 |
begin |
| 8548 |
if Nkind (P) /= N_Subprogram_Body then |
| 8549 |
return False; |
| 8550 |
|
| 8551 |
-- Treat the generated body of an expression function like other |
| 8552 |
-- bodies generated during expansion (e.g. stream subprograms) so |
| 8553 |
-- that those bodies are not treated as freezing points. |
| 8554 |
|
| 8555 |
elsif Was_Expression_Function (P) then |
| 8556 |
pragma Assert (not Comes_From_Source (P)); |
| 8557 |
return True; |
| 8558 |
|
| 8559 |
-- This is the body of a generated predicate function |
| 8560 |
|
| 8561 |
elsif Present (Corresponding_Spec (P)) |
| 8562 |
and then Is_Predicate_Function (Corresponding_Spec (P)) |
| 8563 |
then |
| 8564 |
return True; |
| 8565 |
|
| 8566 |
-- This is the body of a helper/wrapper built for CW preconditions |
| 8567 |
|
| 8568 |
elsif Present (Corresponding_Spec (P)) |
| 8569 |
and then |
| 8570 |
Present (Class_Preconditions_Subprogram (Corresponding_Spec (P))) |
| 8571 |
then |
| 8572 |
return True; |
| 8573 |
|
| 8574 |
else |
| 8575 |
Id := Defining_Unit_Name (Specification (P)); |
| 8576 |
|
| 8577 |
-- This is the body of a Type-Specific Support routine or the one |
| 8578 |
-- generated for a renaming_as_body. |
| 8579 |
|
| 8580 |
if Nkind (Id) = N_Defining_Identifier |
| 8581 |
and then (Is_Init_Proc (Id) |
| 8582 |
or else Is_TSS (Id, TSS_Stream_Input) |
| 8583 |
or else Is_TSS (Id, TSS_Stream_Output) |
| 8584 |
or else Is_TSS (Id, TSS_Stream_Read) |
| 8585 |
or else Is_TSS (Id, TSS_Stream_Write) |
| 8586 |
or else Is_TSS (Id, TSS_Put_Image) |
| 8587 |
or else Nkind (Original_Node (P)) = |
| 8588 |
N_Subprogram_Renaming_Declaration) |
| 8589 |
then |
| 8590 |
return True; |
| 8591 |
else |
| 8592 |
return False; |
| 8593 |
end if; |
| 8594 |
end if; |
| 8595 |
end In_Expanded_Body; |
| 8596 |
|
| 8597 |
---------------------- |
| 8598 |
-- Has_Decl_In_List -- |
| 8599 |
---------------------- |
| 8600 |
|
| 8601 |
function Has_Decl_In_List |
| 8602 |
(E : Entity_Id; |
| 8603 |
N : Node_Id; |
| 8604 |
L : List_Id) return Boolean |
| 8605 |
is |
| 8606 |
Decl_Node : Node_Id; |
| 8607 |
|
| 8608 |
begin |
| 8609 |
-- If E is an itype, pretend that it is declared in N except for a |
| 8610 |
-- class-wide subtype with an equivalent type, because this latter |
| 8611 |
-- type comes with a bona-fide declaration node. |
| 8612 |
|
| 8613 |
if Is_Itype (E) then |
| 8614 |
if Ekind (E) = E_Class_Wide_Subtype |
| 8615 |
and then Present (Equivalent_Type (E)) |
| 8616 |
then |
| 8617 |
Decl_Node := Declaration_Node (Equivalent_Type (E)); |
| 8618 |
else |
| 8619 |
Decl_Node := N; |
| 8620 |
end if; |
| 8621 |
|
| 8622 |
else |
| 8623 |
Decl_Node := Declaration_Node (E); |
| 8624 |
end if; |
| 8625 |
|
| 8626 |
return Is_List_Member (Decl_Node) |
| 8627 |
and then List_Containing (Decl_Node) = L; |
| 8628 |
end Has_Decl_In_List; |
| 8629 |
|
| 8630 |
-- Local variables |
| 8631 |
|
| 8632 |
In_Spec_Exp : constant Boolean := In_Spec_Expression; |
| 8633 |
|
| 8634 |
Desig_Typ : Entity_Id; |
| 8635 |
Nam : Entity_Id; |
| 8636 |
P : Node_Id; |
| 8637 |
Parent_P : Node_Id; |
| 8638 |
Typ : Entity_Id; |
| 8639 |
|
| 8640 |
Allocator_Typ : Entity_Id := Empty; |
| 8641 |
|
| 8642 |
Freeze_Outside_Subp : Entity_Id := Empty; |
| 8643 |
-- This entity is set if we are inside a subprogram body and the frozen |
| 8644 |
-- entity is defined in the enclosing scope of this subprogram. In such |
| 8645 |
-- case we must skip the subprogram body when climbing the parents chain |
| 8646 |
-- to locate the correct placement for the freezing node. |
| 8647 |
|
| 8648 |
-- Start of processing for Freeze_Expression |
| 8649 |
|
| 8650 |
begin |
| 8651 |
-- Immediate return if freezing is inhibited. This flag is set by the |
| 8652 |
-- analyzer to stop freezing on generated expressions that would cause |
| 8653 |
-- freezing if they were in the source program, but which are not |
| 8654 |
-- supposed to freeze, since they are created. |
| 8655 |
|
| 8656 |
if Must_Not_Freeze (N) then |
| 8657 |
return; |
| 8658 |
|
| 8659 |
elsif Preanalysis_Active then |
| 8660 |
|
| 8661 |
-- Do not freeze under strict preanalysis |
| 8662 |
|
| 8663 |
if not In_Spec_Exp then |
| 8664 |
return; |
| 8665 |
|
| 8666 |
-- If expression is non-static, then it does not freeze in a default |
| 8667 |
-- expression, see section "Handling of Default Expressions" in the |
| 8668 |
-- spec of package Sem for further details. |
| 8669 |
|
| 8670 |
elsif not Within_Spec_Static_Expression (N) then |
| 8671 |
return; |
| 8672 |
end if; |
| 8673 |
end if; |
| 8674 |
|
| 8675 |
-- Freeze type of expression if not frozen already |
| 8676 |
|
| 8677 |
Typ := Empty; |
| 8678 |
|
| 8679 |
if Nkind (N) in N_Has_Etype and then Present (Etype (N)) then |
| 8680 |
if not Is_Frozen (Etype (N)) then |
| 8681 |
Typ := Etype (N); |
| 8682 |
|
| 8683 |
-- Base type may be an derived numeric type that is frozen at the |
| 8684 |
-- point of declaration, but first_subtype is still unfrozen. |
| 8685 |
|
| 8686 |
elsif not Is_Frozen (First_Subtype (Etype (N))) then |
| 8687 |
Typ := First_Subtype (Etype (N)); |
| 8688 |
end if; |
| 8689 |
end if; |
| 8690 |
|
| 8691 |
-- For entity name, freeze entity if not frozen already. A special |
| 8692 |
-- exception occurs for an identifier that did not come from source. |
| 8693 |
-- We don't let such identifiers freeze a non-internal entity, i.e. |
| 8694 |
-- an entity that did come from source, since such an identifier was |
| 8695 |
-- generated by the expander, and cannot have any semantic effect on |
| 8696 |
-- the freezing semantics. For example, this stops the parameter of |
| 8697 |
-- an initialization procedure from freezing the variable. |
| 8698 |
|
| 8699 |
if Is_Entity_Name (N) |
| 8700 |
and then Present (Entity (N)) |
| 8701 |
and then not Is_Frozen (Entity (N)) |
| 8702 |
and then (Nkind (N) /= N_Identifier |
| 8703 |
or else Comes_From_Source (N) |
| 8704 |
or else not Comes_From_Source (Entity (N))) |
| 8705 |
then |
| 8706 |
Nam := Entity (N); |
| 8707 |
|
| 8708 |
if Present (Nam) and then Ekind (Nam) = E_Function then |
| 8709 |
Check_Expression_Function (N, Nam); |
| 8710 |
end if; |
| 8711 |
|
| 8712 |
else |
| 8713 |
Nam := Empty; |
| 8714 |
end if; |
| 8715 |
|
| 8716 |
-- For an allocator freeze designated type if not frozen already |
| 8717 |
|
| 8718 |
-- For an aggregate whose component type is an access type, freeze the |
| 8719 |
-- designated type now, so that its freeze does not appear within the |
| 8720 |
-- loop that might be created in the expansion of the aggregate. If the |
| 8721 |
-- designated type is a private type without full view, the expression |
| 8722 |
-- cannot contain an allocator, so the type is not frozen. |
| 8723 |
|
| 8724 |
-- For a function, we freeze the entity when the subprogram declaration |
| 8725 |
-- is frozen, but a function call may appear in an initialization proc. |
| 8726 |
-- before the declaration is frozen. We need to generate the extra |
| 8727 |
-- formals, if any, to ensure that the expansion of the call includes |
| 8728 |
-- the proper actuals. This only applies to Ada subprograms, not to |
| 8729 |
-- imported ones. |
| 8730 |
|
| 8731 |
Desig_Typ := Empty; |
| 8732 |
|
| 8733 |
case Nkind (N) is |
| 8734 |
when N_Allocator => |
| 8735 |
Desig_Typ := Designated_Type (Etype (N)); |
| 8736 |
|
| 8737 |
if Nkind (Expression (N)) = N_Qualified_Expression then |
| 8738 |
Allocator_Typ := Entity (Subtype_Mark (Expression (N))); |
| 8739 |
end if; |
| 8740 |
|
| 8741 |
when N_Aggregate => |
| 8742 |
if Is_Array_Type (Etype (N)) |
| 8743 |
and then Is_Access_Type (Component_Type (Etype (N))) |
| 8744 |
then |
| 8745 |
-- Check whether aggregate includes allocators |
| 8746 |
|
| 8747 |
Desig_Typ := Find_Aggregate_Component_Desig_Type; |
| 8748 |
end if; |
| 8749 |
|
| 8750 |
when N_Indexed_Component |
| 8751 |
| N_Selected_Component |
| 8752 |
| N_Slice |
| 8753 |
=> |
| 8754 |
if Is_Access_Type (Etype (Prefix (N))) then |
| 8755 |
Desig_Typ := Designated_Type (Etype (Prefix (N))); |
| 8756 |
end if; |
| 8757 |
|
| 8758 |
when N_Identifier => |
| 8759 |
if Present (Nam) |
| 8760 |
and then Ekind (Nam) = E_Function |
| 8761 |
and then Nkind (Parent (N)) = N_Function_Call |
| 8762 |
and then not Has_Foreign_Convention (Nam) |
| 8763 |
then |
| 8764 |
Create_Extra_Formals (Nam); |
| 8765 |
end if; |
| 8766 |
|
| 8767 |
when others => |
| 8768 |
null; |
| 8769 |
end case; |
| 8770 |
|
| 8771 |
if Desig_Typ /= Empty |
| 8772 |
and then (Is_Frozen (Desig_Typ) |
| 8773 |
or else not Is_Fully_Defined (Desig_Typ)) |
| 8774 |
then |
| 8775 |
Desig_Typ := Empty; |
| 8776 |
end if; |
| 8777 |
|
| 8778 |
-- All done if nothing needs freezing |
| 8779 |
|
| 8780 |
if No (Typ) |
| 8781 |
and then No (Nam) |
| 8782 |
and then No (Desig_Typ) |
| 8783 |
and then No (Allocator_Typ) |
| 8784 |
then |
| 8785 |
return; |
| 8786 |
end if; |
| 8787 |
|
| 8788 |
-- Check if we are inside a subprogram body and the frozen entity is |
| 8789 |
-- defined in the enclosing scope of this subprogram. In such case we |
| 8790 |
-- must skip the subprogram when climbing the parents chain to locate |
| 8791 |
-- the correct placement for the freezing node. |
| 8792 |
|
| 8793 |
-- This is not needed for default expressions and other spec expressions |
| 8794 |
-- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb) |
| 8795 |
-- takes care of placing them at the proper place, after the generic |
| 8796 |
-- unit. |
| 8797 |
|
| 8798 |
if Present (Nam) |
| 8799 |
and then Scope (Nam) /= Current_Scope |
| 8800 |
and then not (In_Spec_Exp and then Inside_A_Generic) |
| 8801 |
then |
| 8802 |
declare |
| 8803 |
S : Entity_Id := Current_Scope; |
| 8804 |
|
| 8805 |
begin |
| 8806 |
while Present (S) |
| 8807 |
and then In_Same_Source_Unit (Nam, S) |
| 8808 |
loop |
| 8809 |
if Scope (S) = Scope (Nam) then |
| 8810 |
if Is_Subprogram (S) and then Has_Completion (S) then |
| 8811 |
Freeze_Outside_Subp := S; |
| 8812 |
end if; |
| 8813 |
|
| 8814 |
exit; |
| 8815 |
end if; |
| 8816 |
|
| 8817 |
S := Scope (S); |
| 8818 |
end loop; |
| 8819 |
end; |
| 8820 |
end if; |
| 8821 |
|
| 8822 |
-- Examine the enclosing context by climbing the parent chain |
| 8823 |
|
| 8824 |
-- If we identified that we must freeze the entity outside of a given |
| 8825 |
-- subprogram then we just climb up to that subprogram checking if some |
| 8826 |
-- enclosing node is marked as Must_Not_Freeze (since in such case we |
| 8827 |
-- must not freeze yet this entity). |
| 8828 |
|
| 8829 |
P := N; |
| 8830 |
|
| 8831 |
if Present (Freeze_Outside_Subp) then |
| 8832 |
loop |
| 8833 |
-- Do not freeze the current expression if another expression in |
| 8834 |
-- the chain of parents must not be frozen. |
| 8835 |
|
| 8836 |
if Nkind (P) in N_Subexpr and then Must_Not_Freeze (P) then |
| 8837 |
return; |
| 8838 |
end if; |
| 8839 |
|
| 8840 |
Parent_P := Parent (P); |
| 8841 |
|
| 8842 |
-- If we don't have a parent, then we are not in a well-formed |
| 8843 |
-- tree. This is an unusual case, but there are some legitimate |
| 8844 |
-- situations in which this occurs, notably when the expressions |
| 8845 |
-- in the range of a type declaration are resolved. We simply |
| 8846 |
-- ignore the freeze request in this case. |
| 8847 |
|
| 8848 |
if No (Parent_P) then |
| 8849 |
return; |
| 8850 |
end if; |
| 8851 |
|
| 8852 |
-- If the parent is a subprogram body, the candidate insertion |
| 8853 |
-- point is just ahead of it. |
| 8854 |
|
| 8855 |
if Nkind (Parent_P) = N_Subprogram_Body |
| 8856 |
and then Unique_Defining_Entity (Parent_P) = |
| 8857 |
Freeze_Outside_Subp |
| 8858 |
then |
| 8859 |
P := Parent_P; |
| 8860 |
exit; |
| 8861 |
end if; |
| 8862 |
|
| 8863 |
P := Parent_P; |
| 8864 |
end loop; |
| 8865 |
|
| 8866 |
-- Otherwise the traversal serves two purposes - to detect scenarios |
| 8867 |
-- where freezeing is not needed and to find the proper insertion point |
| 8868 |
-- for the freeze nodes. Although somewhat similar to Insert_Actions, |
| 8869 |
-- this traversal is freezing semantics-sensitive. Inserting freeze |
| 8870 |
-- nodes blindly in the tree may result in types being frozen too early. |
| 8871 |
|
| 8872 |
else |
| 8873 |
loop |
| 8874 |
-- Do not freeze the current expression if another expression in |
| 8875 |
-- the chain of parents must not be frozen. |
| 8876 |
|
| 8877 |
if Nkind (P) in N_Subexpr and then Must_Not_Freeze (P) then |
| 8878 |
return; |
| 8879 |
end if; |
| 8880 |
|
| 8881 |
Parent_P := Parent (P); |
| 8882 |
|
| 8883 |
-- If we don't have a parent, then we are not in a well-formed |
| 8884 |
-- tree. This is an unusual case, but there are some legitimate |
| 8885 |
-- situations in which this occurs, notably when the expressions |
| 8886 |
-- in the range of a type declaration are resolved. We simply |
| 8887 |
-- ignore the freeze request in this case. |
| 8888 |
|
| 8889 |
if No (Parent_P) then |
| 8890 |
return; |
| 8891 |
end if; |
| 8892 |
|
| 8893 |
-- See if we have got to an appropriate point in the tree |
| 8894 |
|
| 8895 |
case Nkind (Parent_P) is |
| 8896 |
|
| 8897 |
-- A special test for the exception of (RM 13.14(8)) for the |
| 8898 |
-- case of per-object expressions (RM 3.8(18)) occurring in |
| 8899 |
-- component definition or a discrete subtype definition. Note |
| 8900 |
-- that we test for a component declaration which includes both |
| 8901 |
-- cases we are interested in, and furthermore the tree does |
| 8902 |
-- not have explicit nodes for either of these two constructs. |
| 8903 |
|
| 8904 |
when N_Component_Declaration => |
| 8905 |
|
| 8906 |
-- The case we want to test for here is an identifier that |
| 8907 |
-- is a per-object expression, this is either a discriminant |
| 8908 |
-- that appears in a context other than the component |
| 8909 |
-- declaration or it is a reference to the type of the |
| 8910 |
-- enclosing construct. |
| 8911 |
|
| 8912 |
-- For either of these cases, we skip the freezing |
| 8913 |
|
| 8914 |
if not In_Spec_Expression |
| 8915 |
and then Nkind (N) = N_Identifier |
| 8916 |
and then Present (Entity (N)) |
| 8917 |
then |
| 8918 |
-- We recognize the discriminant case by just looking for |
| 8919 |
-- a reference to a discriminant. It can only be one for |
| 8920 |
-- the enclosing construct. Skip freezing in this case. |
| 8921 |
|
| 8922 |
if Ekind (Entity (N)) = E_Discriminant then |
| 8923 |
return; |
| 8924 |
|
| 8925 |
-- For the case of a reference to the enclosing record, |
| 8926 |
-- (or task or protected type), we look for a type that |
| 8927 |
-- matches the current scope. |
| 8928 |
|
| 8929 |
elsif Entity (N) = Current_Scope then |
| 8930 |
return; |
| 8931 |
end if; |
| 8932 |
end if; |
| 8933 |
|
| 8934 |
-- If we have an enumeration literal that appears as the choice |
| 8935 |
-- in the aggregate of an enumeration representation clause, |
| 8936 |
-- then freezing does not occur (RM 13.14(10)). |
| 8937 |
|
| 8938 |
when N_Enumeration_Representation_Clause => |
| 8939 |
|
| 8940 |
-- The case we are looking for is an enumeration literal |
| 8941 |
|
| 8942 |
if Nkind (N) in N_Identifier | N_Character_Literal |
| 8943 |
and then Is_Enumeration_Type (Etype (N)) |
| 8944 |
then |
| 8945 |
-- If enumeration literal appears directly as the choice, |
| 8946 |
-- do not freeze (this is the normal non-overloaded case) |
| 8947 |
|
| 8948 |
if Nkind (Parent (N)) = N_Component_Association |
| 8949 |
and then First (Choices (Parent (N))) = N |
| 8950 |
then |
| 8951 |
return; |
| 8952 |
|
| 8953 |
-- If enumeration literal appears as the name of function |
| 8954 |
-- which is the choice, then also do not freeze. This |
| 8955 |
-- happens in the overloaded literal case, where the |
| 8956 |
-- enumeration literal is temporarily changed to a |
| 8957 |
-- function call for overloading analysis purposes. |
| 8958 |
|
| 8959 |
elsif Nkind (Parent (N)) = N_Function_Call |
| 8960 |
and then Nkind (Parent (Parent (N))) = |
| 8961 |
N_Component_Association |
| 8962 |
and then First (Choices (Parent (Parent (N)))) = |
| 8963 |
Parent (N) |
| 8964 |
then |
| 8965 |
return; |
| 8966 |
end if; |
| 8967 |
end if; |
| 8968 |
|
| 8969 |
-- Normally if the parent is a handled sequence of statements, |
| 8970 |
-- then the current node must be a statement, and that is an |
| 8971 |
-- appropriate place to insert a freeze node. |
| 8972 |
|
| 8973 |
when N_Handled_Sequence_Of_Statements => |
| 8974 |
|
| 8975 |
-- An exception occurs when the sequence of statements is |
| 8976 |
-- for an expander generated body that did not do the usual |
| 8977 |
-- freeze all operation. In this case we usually want to |
| 8978 |
-- freeze outside this body, not inside it, unless the |
| 8979 |
-- entity is declared inside this expander generated body. |
| 8980 |
|
| 8981 |
exit when not In_Expanded_Body (Parent_P) |
| 8982 |
or else Declared_In_Expanded_Body (Parent_P, Typ, Nam); |
| 8983 |
|
| 8984 |
-- If parent is a body or a spec or a block, then the current |
| 8985 |
-- node is a statement or declaration and we can insert the |
| 8986 |
-- freeze node before it. |
| 8987 |
|
| 8988 |
when N_Block_Statement |
| 8989 |
| N_Entry_Body |
| 8990 |
| N_Package_Body |
| 8991 |
| N_Package_Specification |
| 8992 |
| N_Protected_Body |
| 8993 |
| N_Subprogram_Body |
| 8994 |
| N_Task_Body |
| 8995 |
=> |
| 8996 |
exit; |
| 8997 |
|
| 8998 |
-- The expander is allowed to define types in any statements |
| 8999 |
-- list, so any of the following parent nodes also mark a |
| 9000 |
-- freezing point if the actual node is in a list of |
| 9001 |
-- statements or declarations. |
| 9002 |
|
| 9003 |
when N_Abortable_Part |
| 9004 |
| N_Accept_Alternative |
| 9005 |
| N_Case_Statement_Alternative |
| 9006 |
| N_Compilation_Unit_Aux |
| 9007 |
| N_Conditional_Entry_Call |
| 9008 |
| N_Delay_Alternative |
| 9009 |
| N_Elsif_Part |
| 9010 |
| N_Entry_Call_Alternative |
| 9011 |
| N_Exception_Handler |
| 9012 |
| N_Extended_Return_Statement |
| 9013 |
| N_Freeze_Entity |
| 9014 |
| N_If_Statement |
| 9015 |
| N_Selective_Accept |
| 9016 |
| N_Triggering_Alternative |
| 9017 |
=> |
| 9018 |
if No (Current_Subprogram) then |
| 9019 |
exit when Is_List_Member (P); |
| 9020 |
|
| 9021 |
-- Check exceptional case documented above for an enclosing |
| 9022 |
-- handled sequence of statements. |
| 9023 |
|
| 9024 |
else |
| 9025 |
declare |
| 9026 |
Par : Node_Id := Parent (Parent_P); |
| 9027 |
|
| 9028 |
begin |
| 9029 |
while Present (Par) |
| 9030 |
and then |
| 9031 |
Nkind (Par) /= N_Handled_Sequence_Of_Statements |
| 9032 |
and then Nkind (Parent (Par)) /= N_Subprogram_Body |
| 9033 |
loop |
| 9034 |
Par := Parent (Par); |
| 9035 |
end loop; |
| 9036 |
|
| 9037 |
-- If we don't have a parent, then we are not in a |
| 9038 |
-- well-formed tree and we ignore the freeze request. |
| 9039 |
-- See previous comment in the enclosing loop. |
| 9040 |
|
| 9041 |
if No (Par) then |
| 9042 |
return; |
| 9043 |
end if; |
| 9044 |
|
| 9045 |
exit when not In_Expanded_Body (Par) |
| 9046 |
or else Declared_In_Expanded_Body (Par, Typ, Nam); |
| 9047 |
end; |
| 9048 |
end if; |
| 9049 |
|
| 9050 |
-- The freeze nodes produced by an expression coming from the |
| 9051 |
-- Actions list of an N_Expression_With_Actions, short-circuit |
| 9052 |
-- expression or N_Case_Expression_Alternative node must remain |
| 9053 |
-- within the Actions list if they freeze an entity declared in |
| 9054 |
-- this list, as inserting the freeze nodes further up the tree |
| 9055 |
-- may lead to use before declaration issues for the entity. |
| 9056 |
|
| 9057 |
when N_Case_Expression_Alternative |
| 9058 |
| N_Expression_With_Actions |
| 9059 |
| N_Short_Circuit |
| 9060 |
=> |
| 9061 |
exit when (Present (Nam) |
| 9062 |
and then |
| 9063 |
Has_Decl_In_List (Nam, P, Actions (Parent_P))) |
| 9064 |
or else (Present (Typ) |
| 9065 |
and then |
| 9066 |
Has_Decl_In_List (Typ, P, Actions (Parent_P))); |
| 9067 |
|
| 9068 |
-- Likewise for an N_If_Expression and its two Actions list |
| 9069 |
|
| 9070 |
when N_If_Expression => |
| 9071 |
declare |
| 9072 |
L1 : constant List_Id := Then_Actions (Parent_P); |
| 9073 |
L2 : constant List_Id := Else_Actions (Parent_P); |
| 9074 |
|
| 9075 |
begin |
| 9076 |
exit when (Present (Nam) |
| 9077 |
and then |
| 9078 |
Has_Decl_In_List (Nam, P, L1)) |
| 9079 |
or else (Present (Typ) |
| 9080 |
and then |
| 9081 |
Has_Decl_In_List (Typ, P, L1)) |
| 9082 |
or else (Present (Nam) |
| 9083 |
and then |
| 9084 |
Has_Decl_In_List (Nam, P, L2)) |
| 9085 |
or else (Present (Typ) |
| 9086 |
and then |
| 9087 |
Has_Decl_In_List (Typ, P, L2)); |
| 9088 |
end; |
| 9089 |
|
| 9090 |
-- N_Loop_Statement is a special case: a type that appears in |
| 9091 |
-- the source can never be frozen in a loop (this occurs only |
| 9092 |
-- because of a loop expanded by the expander), so we keep on |
| 9093 |
-- going. Otherwise we terminate the search. Same is true of |
| 9094 |
-- any entity which comes from source (if it has a predefined |
| 9095 |
-- type, this type does not appear to come from source, but the |
| 9096 |
-- entity should not be frozen here). |
| 9097 |
|
| 9098 |
when N_Loop_Statement => |
| 9099 |
exit when not Comes_From_Source (Etype (N)) |
| 9100 |
and then (No (Nam) or else not Comes_From_Source (Nam)); |
| 9101 |
|
| 9102 |
-- For all other cases, keep looking at parents |
| 9103 |
|
| 9104 |
when others => |
| 9105 |
null; |
| 9106 |
end case; |
| 9107 |
|
| 9108 |
-- We fall through the case if we did not yet find the proper |
| 9109 |
-- place in the tree for inserting the freeze node, so climb. |
| 9110 |
|
| 9111 |
P := Parent_P; |
| 9112 |
end loop; |
| 9113 |
end if; |
| 9114 |
|
| 9115 |
-- If the expression appears in a record or an initialization procedure, |
| 9116 |
-- the freeze nodes are collected and attached to the current scope, to |
| 9117 |
-- be inserted and analyzed on exit from the scope, to insure that |
| 9118 |
-- generated entities appear in the correct scope. If the expression is |
| 9119 |
-- a default for a discriminant specification, the scope is still void. |
| 9120 |
-- The expression can also appear in the discriminant part of a private |
| 9121 |
-- or concurrent type. |
| 9122 |
|
| 9123 |
-- If the expression appears in a constrained subcomponent of an |
| 9124 |
-- enclosing record declaration, the freeze nodes must be attached to |
| 9125 |
-- the outer record type so they can eventually be placed in the |
| 9126 |
-- enclosing declaration list. |
| 9127 |
|
| 9128 |
-- The other case requiring this special handling is if we are in a |
| 9129 |
-- default expression, since in that case we are about to freeze a |
| 9130 |
-- static type, and the freeze scope needs to be the outer scope, not |
| 9131 |
-- the scope of the subprogram with the default parameter. |
| 9132 |
|
| 9133 |
-- For default expressions and other spec expressions in generic units, |
| 9134 |
-- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of |
| 9135 |
-- placing them at the proper place, after the generic unit. |
| 9136 |
|
| 9137 |
if (In_Spec_Exp and not Inside_A_Generic) |
| 9138 |
or else (Is_Type (Current_Scope) |
| 9139 |
and then (not Is_Concurrent_Type (Current_Scope) |
| 9140 |
or else not Has_Completion (Current_Scope))) |
| 9141 |
or else Ekind (Current_Scope) = E_Void |
| 9142 |
then |
| 9143 |
declare |
| 9144 |
Freeze_Nodes : List_Id := No_List; |
| 9145 |
Pos : Int := Scope_Stack.Last; |
| 9146 |
Scop : Entity_Id := Current_Scope; |
| 9147 |
|
| 9148 |
begin |
| 9149 |
if Present (Desig_Typ) then |
| 9150 |
Freeze_And_Append (Desig_Typ, N, Freeze_Nodes); |
| 9151 |
end if; |
| 9152 |
|
| 9153 |
if Present (Typ) then |
| 9154 |
Freeze_And_Append (Typ, N, Freeze_Nodes); |
| 9155 |
end if; |
| 9156 |
|
| 9157 |
if Present (Nam) then |
| 9158 |
Freeze_And_Append (Nam, N, Freeze_Nodes); |
| 9159 |
end if; |
| 9160 |
|
| 9161 |
-- The current scope may be that of a constrained component of |
| 9162 |
-- an enclosing record declaration, or a block of an enclosing |
| 9163 |
-- declare expression in Ada 2022, or of a loop of an enclosing |
| 9164 |
-- quantified expression or aggregate with an iterated component |
| 9165 |
-- in Ada 2022, which is above the current scope in the scope |
| 9166 |
-- stack. Indeed in the context of a quantified expression or |
| 9167 |
-- an aggregate with an iterated component, an internal scope is |
| 9168 |
-- created and pushed above the current scope in order to emulate |
| 9169 |
-- the loop-like behavior of the construct. |
| 9170 |
-- If the expression is within a top-level pragma, as for a pre- |
| 9171 |
-- condition on a library-level subprogram, nothing to do. |
| 9172 |
|
| 9173 |
if not Is_Compilation_Unit (Scop) then |
| 9174 |
if Is_Record_Type (Scope (Scop)) then |
| 9175 |
Pos := Pos - 1; |
| 9176 |
|
| 9177 |
else |
| 9178 |
while Ekind (Scop) in E_Block | E_Loop |
| 9179 |
and then Is_Internal (Scop) |
| 9180 |
loop |
| 9181 |
Pos := Pos - 1; |
| 9182 |
Scop := Scope (Scop); |
| 9183 |
end loop; |
| 9184 |
end if; |
| 9185 |
end if; |
| 9186 |
|
| 9187 |
if Is_Non_Empty_List (Freeze_Nodes) then |
| 9188 |
|
| 9189 |
-- When the current scope is transient, insert the freeze nodes |
| 9190 |
-- prior to the expression that produced them. Transient scopes |
| 9191 |
-- may create additional declarations when finalizing objects |
| 9192 |
-- or managing the secondary stack. Inserting the freeze nodes |
| 9193 |
-- of those constructs prior to the scope would result in a |
| 9194 |
-- freeze-before-declaration, therefore the freeze node must |
| 9195 |
-- remain interleaved with their constructs. |
| 9196 |
|
| 9197 |
if Scope_Is_Transient then |
| 9198 |
Insert_Actions (N, Freeze_Nodes); |
| 9199 |
|
| 9200 |
elsif No (Scope_Stack.Table (Pos).Pending_Freeze_Actions) then |
| 9201 |
Scope_Stack.Table (Pos).Pending_Freeze_Actions := |
| 9202 |
Freeze_Nodes; |
| 9203 |
else |
| 9204 |
Append_List (Freeze_Nodes, |
| 9205 |
Scope_Stack.Table (Pos).Pending_Freeze_Actions); |
| 9206 |
end if; |
| 9207 |
end if; |
| 9208 |
end; |
| 9209 |
|
| 9210 |
return; |
| 9211 |
end if; |
| 9212 |
|
| 9213 |
-- Now we have the right place to do the freezing. First, a special |
| 9214 |
-- adjustment, if we are in spec-expression analysis mode, these freeze |
| 9215 |
-- actions must not be thrown away (normally all inserted actions are |
| 9216 |
-- thrown away in this mode). However, the freeze actions are from |
| 9217 |
-- static expressions and one of the important reasons we are doing this |
| 9218 |
-- special analysis is to get these freeze actions. Therefore we turn |
| 9219 |
-- off the In_Spec_Expression mode to propagate these freeze actions. |
| 9220 |
-- This also means they get properly analyzed and expanded. |
| 9221 |
|
| 9222 |
In_Spec_Expression := False; |
| 9223 |
|
| 9224 |
-- Freeze the subtype mark before a qualified expression on an |
| 9225 |
-- allocator as per AARM 13.14(4.a). This is needed in particular to |
| 9226 |
-- generate predicate functions. |
| 9227 |
|
| 9228 |
if Present (Allocator_Typ) then |
| 9229 |
Freeze_Before (P, Allocator_Typ); |
| 9230 |
end if; |
| 9231 |
|
| 9232 |
-- Freeze the designated type of an allocator (RM 13.14(13)) |
| 9233 |
|
| 9234 |
if Present (Desig_Typ) then |
| 9235 |
Freeze_Before (P, Desig_Typ); |
| 9236 |
end if; |
| 9237 |
|
| 9238 |
-- Freeze type of expression (RM 13.14(10)). Note that we took care of |
| 9239 |
-- the enumeration representation clause exception in the loop above. |
| 9240 |
|
| 9241 |
if Present (Typ) then |
| 9242 |
Freeze_Before (P, Typ); |
| 9243 |
end if; |
| 9244 |
|
| 9245 |
-- Freeze name if one is present (RM 13.14(11)) |
| 9246 |
|
| 9247 |
if Present (Nam) then |
| 9248 |
Freeze_Before (P, Nam); |
| 9249 |
end if; |
| 9250 |
|
| 9251 |
-- Restore In_Spec_Expression flag |
| 9252 |
|
| 9253 |
In_Spec_Expression := In_Spec_Exp; |
| 9254 |
end Freeze_Expression; |
| 9255 |
|
| 9256 |
----------------------- |
| 9257 |
-- Freeze_Expr_Types -- |
| 9258 |
----------------------- |
| 9259 |
|
| 9260 |
procedure Freeze_Expr_Types |
| 9261 |
(Def_Id : Entity_Id; |
| 9262 |
Typ : Entity_Id; |
| 9263 |
Expr : Node_Id; |
| 9264 |
N : Node_Id) |
| 9265 |
is |
| 9266 |
function Cloned_Expression return Node_Id; |
| 9267 |
-- Build a duplicate of the expression of the return statement that has |
| 9268 |
-- no defining entities shared with the original expression. |
| 9269 |
|
| 9270 |
function Freeze_Type_Refs (Node : Node_Id) return Traverse_Result; |
| 9271 |
-- Freeze all types referenced in the subtree rooted at Node |
| 9272 |
|
| 9273 |
----------------------- |
| 9274 |
-- Cloned_Expression -- |
| 9275 |
----------------------- |
| 9276 |
|
| 9277 |
function Cloned_Expression return Node_Id is |
| 9278 |
function Clone_Id (Node : Node_Id) return Traverse_Result; |
| 9279 |
-- Tree traversal routine that clones the defining identifier of |
| 9280 |
-- iterator and loop parameter specification nodes. |
| 9281 |
|
| 9282 |
-------------- |
| 9283 |
-- Clone_Id -- |
| 9284 |
-------------- |
| 9285 |
|
| 9286 |
function Clone_Id (Node : Node_Id) return Traverse_Result is |
| 9287 |
begin |
| 9288 |
if Nkind (Node) in |
| 9289 |
N_Iterator_Specification | N_Loop_Parameter_Specification |
| 9290 |
then |
| 9291 |
Set_Defining_Identifier |
| 9292 |
(Node, New_Copy (Defining_Identifier (Node))); |
| 9293 |
end if; |
| 9294 |
|
| 9295 |
return OK; |
| 9296 |
end Clone_Id; |
| 9297 |
|
| 9298 |
procedure Clone_Def_Ids is new Traverse_Proc (Clone_Id); |
| 9299 |
|
| 9300 |
-- Local variable |
| 9301 |
|
| 9302 |
Dup_Expr : constant Node_Id := New_Copy_Tree (Expr); |
| 9303 |
|
| 9304 |
-- Start of processing for Cloned_Expression |
| 9305 |
|
| 9306 |
begin |
| 9307 |
-- We must duplicate the expression with semantic information to |
| 9308 |
-- inherit the decoration of global entities in generic instances. |
| 9309 |
-- Set the parent of the new node to be the parent of the original |
| 9310 |
-- to get the proper context, which is needed for complete error |
| 9311 |
-- reporting and for semantic analysis. |
| 9312 |
|
| 9313 |
Set_Parent (Dup_Expr, Parent (Expr)); |
| 9314 |
|
| 9315 |
-- Replace the defining identifier of iterators and loop param |
| 9316 |
-- specifications by a clone to ensure that the cloned expression |
| 9317 |
-- and the original expression don't have shared identifiers; |
| 9318 |
-- otherwise, as part of the preanalysis of the expression, these |
| 9319 |
-- shared identifiers may be left decorated with itypes which |
| 9320 |
-- will not be available in the tree passed to the backend. |
| 9321 |
|
| 9322 |
Clone_Def_Ids (Dup_Expr); |
| 9323 |
|
| 9324 |
return Dup_Expr; |
| 9325 |
end Cloned_Expression; |
| 9326 |
|
| 9327 |
---------------------- |
| 9328 |
-- Freeze_Type_Refs -- |
| 9329 |
---------------------- |
| 9330 |
|
| 9331 |
function Freeze_Type_Refs (Node : Node_Id) return Traverse_Result is |
| 9332 |
procedure Check_And_Freeze_Type (Typ : Entity_Id); |
| 9333 |
-- Check that Typ is fully declared and freeze it if so |
| 9334 |
|
| 9335 |
--------------------------- |
| 9336 |
-- Check_And_Freeze_Type -- |
| 9337 |
--------------------------- |
| 9338 |
|
| 9339 |
procedure Check_And_Freeze_Type (Typ : Entity_Id) is |
| 9340 |
begin |
| 9341 |
-- Skip Itypes created by the preanalysis, and itypes whose |
| 9342 |
-- scope is another type (i.e. component subtypes that depend |
| 9343 |
-- on a discriminant), |
| 9344 |
|
| 9345 |
if Is_Itype (Typ) |
| 9346 |
and then (Scope_Within_Or_Same (Scope (Typ), Def_Id) |
| 9347 |
or else Is_Type (Scope (Typ))) |
| 9348 |
then |
| 9349 |
return; |
| 9350 |
end if; |
| 9351 |
|
| 9352 |
-- This provides a better error message than generating primitives |
| 9353 |
-- whose compilation fails much later. Refine the error message if |
| 9354 |
-- possible. |
| 9355 |
|
| 9356 |
Check_Fully_Declared (Typ, Node); |
| 9357 |
|
| 9358 |
if Error_Posted (Node) then |
| 9359 |
if Has_Private_Component (Typ) |
| 9360 |
and then not Is_Private_Type (Typ) |
| 9361 |
then |
| 9362 |
Error_Msg_NE ("\type& has private component", Node, Typ); |
| 9363 |
end if; |
| 9364 |
|
| 9365 |
else |
| 9366 |
Freeze_Before (N, Typ); |
| 9367 |
end if; |
| 9368 |
end Check_And_Freeze_Type; |
| 9369 |
|
| 9370 |
-- Start of processing for Freeze_Type_Refs |
| 9371 |
|
| 9372 |
begin |
| 9373 |
-- Check that a type referenced by an entity can be frozen |
| 9374 |
|
| 9375 |
if Is_Entity_Name (Node) and then Present (Entity (Node)) then |
| 9376 |
-- The entity itself may be a type, as in a membership test |
| 9377 |
-- or an attribute reference. Freezing its own type would be |
| 9378 |
-- incomplete if the entity is derived or an extension. |
| 9379 |
|
| 9380 |
if Is_Type (Entity (Node)) then |
| 9381 |
Check_And_Freeze_Type (Entity (Node)); |
| 9382 |
|
| 9383 |
else |
| 9384 |
Check_And_Freeze_Type (Etype (Entity (Node))); |
| 9385 |
end if; |
| 9386 |
|
| 9387 |
-- Check that the enclosing record type can be frozen |
| 9388 |
|
| 9389 |
if Ekind (Entity (Node)) in E_Component | E_Discriminant then |
| 9390 |
Check_And_Freeze_Type (Scope (Entity (Node))); |
| 9391 |
end if; |
| 9392 |
|
| 9393 |
-- Freezing an access type does not freeze the designated type, but |
| 9394 |
-- freezing conversions between access to interfaces requires that |
| 9395 |
-- the interface types themselves be frozen, so that dispatch table |
| 9396 |
-- entities are properly created. |
| 9397 |
|
| 9398 |
-- Unclear whether a more general rule is needed ??? |
| 9399 |
|
| 9400 |
elsif Nkind (Node) = N_Type_Conversion |
| 9401 |
and then Is_Access_Type (Etype (Node)) |
| 9402 |
and then Is_Interface (Designated_Type (Etype (Node))) |
| 9403 |
then |
| 9404 |
Check_And_Freeze_Type (Designated_Type (Etype (Node))); |
| 9405 |
end if; |
| 9406 |
|
| 9407 |
-- An implicit dereference freezes the designated type. In the case |
| 9408 |
-- of a dispatching call whose controlling argument is an access |
| 9409 |
-- type, the dereference is not made explicit, so we must check for |
| 9410 |
-- such a call and freeze the designated type. |
| 9411 |
|
| 9412 |
if Nkind (Node) in N_Has_Etype |
| 9413 |
and then Present (Etype (Node)) |
| 9414 |
and then Is_Access_Type (Etype (Node)) |
| 9415 |
then |
| 9416 |
if Nkind (Parent (Node)) = N_Function_Call |
| 9417 |
and then Node = Controlling_Argument (Parent (Node)) |
| 9418 |
then |
| 9419 |
Check_And_Freeze_Type (Designated_Type (Etype (Node))); |
| 9420 |
|
| 9421 |
-- An explicit dereference freezes the designated type as well, |
| 9422 |
-- even though that type is not attached to an entity in the |
| 9423 |
-- expression. |
| 9424 |
|
| 9425 |
elsif Nkind (Parent (Node)) = N_Explicit_Dereference then |
| 9426 |
Check_And_Freeze_Type (Designated_Type (Etype (Node))); |
| 9427 |
end if; |
| 9428 |
|
| 9429 |
-- An iterator specification freezes the iterator type, even though |
| 9430 |
-- that type is not attached to an entity in the construct. |
| 9431 |
|
| 9432 |
elsif Nkind (Node) in N_Has_Etype |
| 9433 |
and then Present (Etype (Node)) |
| 9434 |
and then Nkind (Parent (Node)) = N_Iterator_Specification |
| 9435 |
and then Node = Name (Parent (Node)) |
| 9436 |
then |
| 9437 |
declare |
| 9438 |
Iter : constant Node_Id := |
| 9439 |
Find_Value_Of_Aspect (Etype (Node), Aspect_Default_Iterator); |
| 9440 |
|
| 9441 |
begin |
| 9442 |
if Present (Iter) then |
| 9443 |
Check_And_Freeze_Type (Etype (Iter)); |
| 9444 |
end if; |
| 9445 |
end; |
| 9446 |
end if; |
| 9447 |
|
| 9448 |
-- No point in posting several errors on the same expression |
| 9449 |
|
| 9450 |
if Serious_Errors_Detected > 0 then |
| 9451 |
return Abandon; |
| 9452 |
else |
| 9453 |
return OK; |
| 9454 |
end if; |
| 9455 |
end Freeze_Type_Refs; |
| 9456 |
|
| 9457 |
procedure Freeze_References is new Traverse_Proc (Freeze_Type_Refs); |
| 9458 |
|
| 9459 |
-- Local variables |
| 9460 |
|
| 9461 |
Saved_First_Entity : constant Entity_Id := First_Entity (Def_Id); |
| 9462 |
Saved_Last_Entity : constant Entity_Id := Last_Entity (Def_Id); |
| 9463 |
Dup_Expr : constant Node_Id := Cloned_Expression; |
| 9464 |
|
| 9465 |
-- Start of processing for Freeze_Expr_Types |
| 9466 |
|
| 9467 |
begin |
| 9468 |
-- Preanalyze a duplicate of the expression to have available the |
| 9469 |
-- minimum decoration needed to locate referenced unfrozen types |
| 9470 |
-- without adding any decoration to the function expression. |
| 9471 |
|
| 9472 |
-- This routine is also applied to expressions in the contract for |
| 9473 |
-- the subprogram. If that happens when expanding the code for |
| 9474 |
-- pre/postconditions during expansion of the subprogram body, the |
| 9475 |
-- subprogram is already installed. |
| 9476 |
|
| 9477 |
-- Call Preanalyze_Spec_Expression instead of Preanalyze_And_Resolve |
| 9478 |
-- for the sake of consistency with Analyze_Expression_Function. |
| 9479 |
|
| 9480 |
if Def_Id /= Current_Scope then |
| 9481 |
Push_Scope (Def_Id); |
| 9482 |
Install_Formals (Def_Id); |
| 9483 |
Preanalyze_Spec_Expression (Dup_Expr, Typ); |
| 9484 |
End_Scope; |
| 9485 |
else |
| 9486 |
Preanalyze_Spec_Expression (Dup_Expr, Typ); |
| 9487 |
end if; |
| 9488 |
|
| 9489 |
-- Restore certain attributes of Def_Id since the preanalysis may |
| 9490 |
-- have introduced itypes to this scope, thus modifying attributes |
| 9491 |
-- First_Entity and Last_Entity. |
| 9492 |
|
| 9493 |
Set_First_Entity (Def_Id, Saved_First_Entity); |
| 9494 |
Set_Last_Entity (Def_Id, Saved_Last_Entity); |
| 9495 |
|
| 9496 |
if Present (Last_Entity (Def_Id)) then |
| 9497 |
Set_Next_Entity (Last_Entity (Def_Id), Empty); |
| 9498 |
end if; |
| 9499 |
|
| 9500 |
-- Freeze all types referenced in the expression |
| 9501 |
|
| 9502 |
Freeze_References (Dup_Expr); |
| 9503 |
end Freeze_Expr_Types; |
| 9504 |
|
| 9505 |
----------------------------- |
| 9506 |
-- Freeze_Fixed_Point_Type -- |
| 9507 |
----------------------------- |
| 9508 |
|
| 9509 |
-- Certain fixed-point types and subtypes, including implicit base types |
| 9510 |
-- and declared first subtypes, have not yet set up a range. This is |
| 9511 |
-- because the range cannot be set until the Small and Size values are |
| 9512 |
-- known, and these are not known till the type is frozen. |
| 9513 |
|
| 9514 |
-- To signal this case, Scalar_Range contains an unanalyzed syntactic range |
| 9515 |
-- whose bounds are unanalyzed real literals. This routine will recognize |
| 9516 |
-- this case, and transform this range node into a properly typed range |
| 9517 |
-- with properly analyzed and resolved values. |
| 9518 |
|
| 9519 |
procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is |
| 9520 |
Rng : constant Node_Id := Scalar_Range (Typ); |
| 9521 |
Lo : constant Node_Id := Low_Bound (Rng); |
| 9522 |
Hi : constant Node_Id := High_Bound (Rng); |
| 9523 |
Btyp : constant Entity_Id := Base_Type (Typ); |
| 9524 |
Brng : constant Node_Id := Scalar_Range (Btyp); |
| 9525 |
BLo : constant Node_Id := Low_Bound (Brng); |
| 9526 |
BHi : constant Node_Id := High_Bound (Brng); |
| 9527 |
Ftyp : constant Entity_Id := Underlying_Type (First_Subtype (Typ)); |
| 9528 |
|
| 9529 |
Small : Ureal; |
| 9530 |
Loval : Ureal; |
| 9531 |
Hival : Ureal; |
| 9532 |
Atype : Entity_Id; |
| 9533 |
|
| 9534 |
Orig_Lo : Ureal; |
| 9535 |
Orig_Hi : Ureal; |
| 9536 |
-- Save original bounds (for shaving tests) |
| 9537 |
|
| 9538 |
Actual_Size : Int; |
| 9539 |
-- Actual size chosen |
| 9540 |
|
| 9541 |
function Fsize (Lov, Hiv : Ureal) return Int; |
| 9542 |
-- Returns size of type with given bounds. Also leaves these |
| 9543 |
-- bounds set as the current bounds of the Typ. |
| 9544 |
|
| 9545 |
function Larger (A, B : Ureal) return Boolean; |
| 9546 |
-- Returns true if A > B with a margin of Typ'Small |
| 9547 |
|
| 9548 |
function Smaller (A, B : Ureal) return Boolean; |
| 9549 |
-- Returns true if A < B with a margin of Typ'Small |
| 9550 |
|
| 9551 |
----------- |
| 9552 |
-- Fsize -- |
| 9553 |
----------- |
| 9554 |
|
| 9555 |
function Fsize (Lov, Hiv : Ureal) return Int is |
| 9556 |
begin |
| 9557 |
Set_Realval (Lo, Lov); |
| 9558 |
Set_Realval (Hi, Hiv); |
| 9559 |
return Minimum_Size (Typ); |
| 9560 |
end Fsize; |
| 9561 |
|
| 9562 |
------------ |
| 9563 |
-- Larger -- |
| 9564 |
------------ |
| 9565 |
|
| 9566 |
function Larger (A, B : Ureal) return Boolean is |
| 9567 |
begin |
| 9568 |
return A > B and then A - Small_Value (Typ) > B; |
| 9569 |
end Larger; |
| 9570 |
|
| 9571 |
------------- |
| 9572 |
-- Smaller -- |
| 9573 |
------------- |
| 9574 |
|
| 9575 |
function Smaller (A, B : Ureal) return Boolean is |
| 9576 |
begin |
| 9577 |
return A < B and then A + Small_Value (Typ) < B; |
| 9578 |
end Smaller; |
| 9579 |
|
| 9580 |
-- Start of processing for Freeze_Fixed_Point_Type |
| 9581 |
|
| 9582 |
begin |
| 9583 |
-- The type, or its first subtype if we are freezing the anonymous |
| 9584 |
-- base, may have a delayed Small aspect. It must be analyzed now, |
| 9585 |
-- so that all characteristics of the type (size, bounds) can be |
| 9586 |
-- computed and validated in the call to Minimum_Size that follows. |
| 9587 |
|
| 9588 |
if Has_Delayed_Aspects (Ftyp) then |
| 9589 |
Analyze_Aspects_At_Freeze_Point (Ftyp); |
| 9590 |
Set_Has_Delayed_Aspects (Ftyp, False); |
| 9591 |
end if; |
| 9592 |
|
| 9593 |
if May_Inherit_Delayed_Rep_Aspects (Ftyp) then |
| 9594 |
Inherit_Delayed_Rep_Aspects (Ftyp); |
| 9595 |
Set_May_Inherit_Delayed_Rep_Aspects (Ftyp, False); |
| 9596 |
end if; |
| 9597 |
|
| 9598 |
-- Inherit the Small value from the first subtype in any case |
| 9599 |
|
| 9600 |
if Typ /= Ftyp then |
| 9601 |
Set_Small_Value (Typ, Small_Value (Ftyp)); |
| 9602 |
end if; |
| 9603 |
|
| 9604 |
-- If Esize of a subtype has not previously been set, set it now |
| 9605 |
|
| 9606 |
if not Known_Esize (Typ) then |
| 9607 |
Atype := Ancestor_Subtype (Typ); |
| 9608 |
|
| 9609 |
if Present (Atype) then |
| 9610 |
Set_Esize (Typ, Esize (Atype)); |
| 9611 |
else |
| 9612 |
Copy_Esize (To => Typ, From => Btyp); |
| 9613 |
end if; |
| 9614 |
end if; |
| 9615 |
|
| 9616 |
-- Immediate return if the range is already analyzed. This means that |
| 9617 |
-- the range is already set, and does not need to be computed by this |
| 9618 |
-- routine. |
| 9619 |
|
| 9620 |
if Analyzed (Rng) then |
| 9621 |
return; |
| 9622 |
end if; |
| 9623 |
|
| 9624 |
-- Immediate return if either of the bounds raises Constraint_Error |
| 9625 |
|
| 9626 |
if Raises_Constraint_Error (Lo) |
| 9627 |
or else Raises_Constraint_Error (Hi) |
| 9628 |
then |
| 9629 |
return; |
| 9630 |
end if; |
| 9631 |
|
| 9632 |
Small := Small_Value (Typ); |
| 9633 |
Loval := Realval (Lo); |
| 9634 |
Hival := Realval (Hi); |
| 9635 |
|
| 9636 |
Orig_Lo := Loval; |
| 9637 |
Orig_Hi := Hival; |
| 9638 |
|
| 9639 |
-- Ordinary fixed-point case |
| 9640 |
|
| 9641 |
if Is_Ordinary_Fixed_Point_Type (Typ) then |
| 9642 |
|
| 9643 |
-- For the ordinary fixed-point case, we are allowed to fudge the |
| 9644 |
-- end-points up or down by small. Generally we prefer to fudge up, |
| 9645 |
-- i.e. widen the bounds for non-model numbers so that the end points |
| 9646 |
-- are included. However there are cases in which this cannot be |
| 9647 |
-- done, and indeed cases in which we may need to narrow the bounds. |
| 9648 |
-- The following circuit makes the decision. |
| 9649 |
|
| 9650 |
-- Note: our terminology here is that Incl_EP means that the bounds |
| 9651 |
-- are widened by Small if necessary to include the end points, and |
| 9652 |
-- Excl_EP means that the bounds are narrowed by Small to exclude the |
| 9653 |
-- end-points if this reduces the size. |
| 9654 |
|
| 9655 |
-- Note that in the Incl case, all we care about is including the |
| 9656 |
-- end-points. In the Excl case, we want to narrow the bounds as |
| 9657 |
-- much as permitted by the RM, to give the smallest possible size. |
| 9658 |
|
| 9659 |
Fudge : declare |
| 9660 |
Loval_Incl_EP : Ureal; |
| 9661 |
Hival_Incl_EP : Ureal; |
| 9662 |
|
| 9663 |
Loval_Excl_EP : Ureal; |
| 9664 |
Hival_Excl_EP : Ureal; |
| 9665 |
|
| 9666 |
Size_Incl_EP : Int; |
| 9667 |
Size_Excl_EP : Int; |
| 9668 |
|
| 9669 |
Model_Num : Ureal; |
| 9670 |
Actual_Lo : Ureal; |
| 9671 |
Actual_Hi : Ureal; |
| 9672 |
|
| 9673 |
begin |
| 9674 |
-- First step. Base types are required to be symmetrical. Right |
| 9675 |
-- now, the base type range is a copy of the first subtype range. |
| 9676 |
-- This will be corrected before we are done, but right away we |
| 9677 |
-- need to deal with the case where both bounds are non-negative. |
| 9678 |
-- In this case, we set the low bound to the negative of the high |
| 9679 |
-- bound, to make sure that the size is computed to include the |
| 9680 |
-- required sign. Note that we do not need to worry about the |
| 9681 |
-- case of both bounds negative, because the sign will be dealt |
| 9682 |
-- with anyway. Furthermore we can't just go making such a bound |
| 9683 |
-- symmetrical, since in a twos-complement system, there is an |
| 9684 |
-- extra negative value which could not be accommodated on the |
| 9685 |
-- positive side. |
| 9686 |
|
| 9687 |
if Typ = Btyp |
| 9688 |
and then not UR_Is_Negative (Loval) |
| 9689 |
and then Hival > Loval |
| 9690 |
then |
| 9691 |
Loval := -Hival; |
| 9692 |
Set_Realval (Lo, Loval); |
| 9693 |
end if; |
| 9694 |
|
| 9695 |
-- Compute the fudged bounds. If the bound is a model number, (or |
| 9696 |
-- greater if given low bound, smaller if high bound) then we do |
| 9697 |
-- nothing to include it, but we are allowed to backoff to the |
| 9698 |
-- next adjacent model number when we exclude it. If it is not a |
| 9699 |
-- model number then we straddle the two values with the model |
| 9700 |
-- numbers on either side. |
| 9701 |
|
| 9702 |
Model_Num := UR_Trunc (Loval / Small) * Small; |
| 9703 |
|
| 9704 |
if UR_Ge (Loval, Model_Num) then |
| 9705 |
Loval_Incl_EP := Model_Num; |
| 9706 |
else |
| 9707 |
Loval_Incl_EP := Model_Num - Small; |
| 9708 |
end if; |
| 9709 |
|
| 9710 |
-- The low value excluding the end point is Small greater, but |
| 9711 |
-- we do not do this exclusion if the low value is positive, |
| 9712 |
-- since it can't help the size and could actually hurt by |
| 9713 |
-- crossing the high bound. |
| 9714 |
|
| 9715 |
if UR_Is_Negative (Loval_Incl_EP) then |
| 9716 |
Loval_Excl_EP := Loval_Incl_EP + Small; |
| 9717 |
|
| 9718 |
-- If the value went from negative to zero, then we have the |
| 9719 |
-- case where Loval_Incl_EP is the model number just below |
| 9720 |
-- zero, so we want to stick to the negative value for the |
| 9721 |
-- base type to maintain the condition that the size will |
| 9722 |
-- include signed values. |
| 9723 |
|
| 9724 |
if Typ = Btyp |
| 9725 |
and then UR_Is_Zero (Loval_Excl_EP) |
| 9726 |
then |
| 9727 |
Loval_Excl_EP := Loval_Incl_EP; |
| 9728 |
end if; |
| 9729 |
|
| 9730 |
else |
| 9731 |
Loval_Excl_EP := Loval_Incl_EP; |
| 9732 |
end if; |
| 9733 |
|
| 9734 |
-- Similar processing for upper bound and high value |
| 9735 |
|
| 9736 |
Model_Num := UR_Trunc (Hival / Small) * Small; |
| 9737 |
|
| 9738 |
if UR_Le (Hival, Model_Num) then |
| 9739 |
Hival_Incl_EP := Model_Num; |
| 9740 |
else |
| 9741 |
Hival_Incl_EP := Model_Num + Small; |
| 9742 |
end if; |
| 9743 |
|
| 9744 |
if UR_Is_Positive (Hival_Incl_EP) then |
| 9745 |
Hival_Excl_EP := Hival_Incl_EP - Small; |
| 9746 |
else |
| 9747 |
Hival_Excl_EP := Hival_Incl_EP; |
| 9748 |
end if; |
| 9749 |
|
| 9750 |
-- One further adjustment is needed. In the case of subtypes, we |
| 9751 |
-- cannot go outside the range of the base type, or we get |
| 9752 |
-- peculiarities, and the base type range is already set. This |
| 9753 |
-- only applies to the Incl values, since clearly the Excl values |
| 9754 |
-- are already as restricted as they are allowed to be. |
| 9755 |
|
| 9756 |
if Typ /= Btyp then |
| 9757 |
Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo)); |
| 9758 |
Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi)); |
| 9759 |
end if; |
| 9760 |
|
| 9761 |
-- Get size including and excluding end points |
| 9762 |
|
| 9763 |
Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP); |
| 9764 |
Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP); |
| 9765 |
|
| 9766 |
-- No need to exclude end-points if it does not reduce size |
| 9767 |
|
| 9768 |
if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then |
| 9769 |
Loval_Excl_EP := Loval_Incl_EP; |
| 9770 |
end if; |
| 9771 |
|
| 9772 |
if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then |
| 9773 |
Hival_Excl_EP := Hival_Incl_EP; |
| 9774 |
end if; |
| 9775 |
|
| 9776 |
-- Now we set the actual size to be used. We want to use the |
| 9777 |
-- bounds fudged up to include the end-points but only if this |
| 9778 |
-- can be done without violating a specifically given size |
| 9779 |
-- size clause or causing an unacceptable increase in size. |
| 9780 |
|
| 9781 |
-- Case of size clause given |
| 9782 |
|
| 9783 |
if Has_Size_Clause (Typ) then |
| 9784 |
|
| 9785 |
-- Use the inclusive size only if it is consistent with |
| 9786 |
-- the explicitly specified size. |
| 9787 |
|
| 9788 |
if Size_Incl_EP <= RM_Size (Typ) then |
| 9789 |
Actual_Lo := Loval_Incl_EP; |
| 9790 |
Actual_Hi := Hival_Incl_EP; |
| 9791 |
Actual_Size := Size_Incl_EP; |
| 9792 |
|
| 9793 |
-- If the inclusive size is too large, we try excluding |
| 9794 |
-- the end-points (will be caught later if does not work). |
| 9795 |
|
| 9796 |
else |
| 9797 |
Actual_Lo := Loval_Excl_EP; |
| 9798 |
Actual_Hi := Hival_Excl_EP; |
| 9799 |
Actual_Size := Size_Excl_EP; |
| 9800 |
end if; |
| 9801 |
|
| 9802 |
-- Case of size clause not given |
| 9803 |
|
| 9804 |
else |
| 9805 |
-- If we have a base type whose corresponding first subtype |
| 9806 |
-- has an explicit size that is large enough to include our |
| 9807 |
-- end-points, then do so. There is no point in working hard |
| 9808 |
-- to get a base type whose size is smaller than the specified |
| 9809 |
-- size of the first subtype. |
| 9810 |
|
| 9811 |
if Has_Size_Clause (Ftyp) |
| 9812 |
and then Size_Incl_EP <= Esize (Ftyp) |
| 9813 |
then |
| 9814 |
Actual_Size := Size_Incl_EP; |
| 9815 |
Actual_Lo := Loval_Incl_EP; |
| 9816 |
Actual_Hi := Hival_Incl_EP; |
| 9817 |
|
| 9818 |
-- If excluding the end-points makes the size smaller and |
| 9819 |
-- results in a size of 8,16,32,64, then we take the smaller |
| 9820 |
-- size. For the 64 case, this is compulsory. For the other |
| 9821 |
-- cases, it seems reasonable. We like to include end points |
| 9822 |
-- if we can, but not at the expense of moving to the next |
| 9823 |
-- natural boundary of size. |
| 9824 |
|
| 9825 |
elsif Size_Incl_EP /= Size_Excl_EP |
| 9826 |
and then Addressable (Size_Excl_EP) |
| 9827 |
then |
| 9828 |
Actual_Size := Size_Excl_EP; |
| 9829 |
Actual_Lo := Loval_Excl_EP; |
| 9830 |
Actual_Hi := Hival_Excl_EP; |
| 9831 |
|
| 9832 |
-- Otherwise we can definitely include the end points |
| 9833 |
|
| 9834 |
else |
| 9835 |
Actual_Size := Size_Incl_EP; |
| 9836 |
Actual_Lo := Loval_Incl_EP; |
| 9837 |
Actual_Hi := Hival_Incl_EP; |
| 9838 |
end if; |
| 9839 |
|
| 9840 |
-- One pathological case: normally we never fudge a low bound |
| 9841 |
-- down, since it would seem to increase the size (if it has |
| 9842 |
-- any effect), but for ranges containing single value, or no |
| 9843 |
-- values, the high bound can be small too large. Consider: |
| 9844 |
|
| 9845 |
-- type t is delta 2.0**(-14) |
| 9846 |
-- range 131072.0 .. 0; |
| 9847 |
|
| 9848 |
-- That lower bound is *just* outside the range of 32 bits, and |
| 9849 |
-- does need fudging down in this case. Note that the bounds |
| 9850 |
-- will always have crossed here, since the high bound will be |
| 9851 |
-- fudged down if necessary, as in the case of: |
| 9852 |
|
| 9853 |
-- type t is delta 2.0**(-14) |
| 9854 |
-- range 131072.0 .. 131072.0; |
| 9855 |
|
| 9856 |
-- So we detect the situation by looking for crossed bounds, |
| 9857 |
-- and if the bounds are crossed, and the low bound is greater |
| 9858 |
-- than zero, we will always back it off by small, since this |
| 9859 |
-- is completely harmless. |
| 9860 |
|
| 9861 |
if Actual_Lo > Actual_Hi then |
| 9862 |
if UR_Is_Positive (Actual_Lo) then |
| 9863 |
Actual_Lo := Loval_Incl_EP - Small; |
| 9864 |
Actual_Size := Fsize (Actual_Lo, Actual_Hi); |
| 9865 |
|
| 9866 |
-- And of course, we need to do exactly the same parallel |
| 9867 |
-- fudge for flat ranges in the negative region. |
| 9868 |
|
| 9869 |
elsif UR_Is_Negative (Actual_Hi) then |
| 9870 |
Actual_Hi := Hival_Incl_EP + Small; |
| 9871 |
Actual_Size := Fsize (Actual_Lo, Actual_Hi); |
| 9872 |
end if; |
| 9873 |
end if; |
| 9874 |
end if; |
| 9875 |
|
| 9876 |
Set_Realval (Lo, Actual_Lo); |
| 9877 |
Set_Realval (Hi, Actual_Hi); |
| 9878 |
end Fudge; |
| 9879 |
|
| 9880 |
-- Enforce some limitations for ordinary fixed-point types. They come |
| 9881 |
-- from an exact algorithm used to implement Text_IO.Fixed_IO and the |
| 9882 |
-- Fore, Image and Value attributes. The requirement on the Small is |
| 9883 |
-- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of |
| 9884 |
-- Siz bits (Siz=32,64,128) and the requirement on the bounds is to |
| 9885 |
-- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is |
| 9886 |
-- given by the formula N = floor ((Siz - 1) * log 2 / log 10). |
| 9887 |
|
| 9888 |
-- If the bounds of a 32-bit type are too large, force 64-bit type |
| 9889 |
|
| 9890 |
if Actual_Size <= 32 |
| 9891 |
and then Small <= Ureal_2_31 |
| 9892 |
and then (Smaller (Expr_Value_R (Lo), Ureal_M_2_10_18) |
| 9893 |
or else Larger (Expr_Value_R (Hi), Ureal_2_10_18)) |
| 9894 |
then |
| 9895 |
Actual_Size := 33; |
| 9896 |
end if; |
| 9897 |
|
| 9898 |
-- If the bounds of a 64-bit type are too large, force 128-bit type |
| 9899 |
|
| 9900 |
if System_Max_Integer_Size = 128 |
| 9901 |
and then Actual_Size <= 64 |
| 9902 |
and then Small <= Ureal_2_63 |
| 9903 |
and then (Smaller (Expr_Value_R (Lo), Ureal_M_9_10_36) |
| 9904 |
or else Larger (Expr_Value_R (Hi), Ureal_9_10_36)) |
| 9905 |
then |
| 9906 |
Actual_Size := 65; |
| 9907 |
end if; |
| 9908 |
|
| 9909 |
-- Give error messages for first subtypes and not base types, as the |
| 9910 |
-- bounds of base types are always maximum for their size, see below. |
| 9911 |
|
| 9912 |
if System_Max_Integer_Size < 128 and then Typ /= Btyp then |
| 9913 |
|
| 9914 |
-- See the 128-bit case below for the reason why we cannot test |
| 9915 |
-- against the 2**(-63) .. 2**63 range. This quirk should have |
| 9916 |
-- been kludged around as in the 128-bit case below, but it was |
| 9917 |
-- not and we end up with a ludicrous range as a result??? |
| 9918 |
|
| 9919 |
if Small < Ureal_2_M_80 then |
| 9920 |
Error_Msg_Name_1 := Name_Small; |
| 9921 |
Error_Msg_N |
| 9922 |
("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ); |
| 9923 |
|
| 9924 |
elsif Small > Ureal_2_80 then |
| 9925 |
Error_Msg_Name_1 := Name_Small; |
| 9926 |
Error_Msg_N |
| 9927 |
("`&''%` too large, maximum allowed is 2.0'*'*80", Typ); |
| 9928 |
end if; |
| 9929 |
|
| 9930 |
if Smaller (Expr_Value_R (Lo), Ureal_M_9_10_36) then |
| 9931 |
Error_Msg_Name_1 := Name_First; |
| 9932 |
Error_Msg_N |
| 9933 |
("`&''%` too small, minimum allowed is -9.0E+36", Typ); |
| 9934 |
end if; |
| 9935 |
|
| 9936 |
if Larger (Expr_Value_R (Hi), Ureal_9_10_36) then |
| 9937 |
Error_Msg_Name_1 := Name_Last; |
| 9938 |
Error_Msg_N |
| 9939 |
("`&''%` too large, maximum allowed is 9.0E+36", Typ); |
| 9940 |
end if; |
| 9941 |
|
| 9942 |
elsif System_Max_Integer_Size = 128 and then Typ /= Btyp then |
| 9943 |
|
| 9944 |
-- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1)) |
| 9945 |
-- but we cannot really support anything smaller than Fine_Delta |
| 9946 |
-- because of the way we implement I/O for fixed point types??? |
| 9947 |
|
| 9948 |
if Small = Ureal_2_M_128 then |
| 9949 |
null; |
| 9950 |
|
| 9951 |
elsif Small < Ureal_2_M_127 then |
| 9952 |
Error_Msg_Name_1 := Name_Small; |
| 9953 |
Error_Msg_N |
| 9954 |
("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ); |
| 9955 |
|
| 9956 |
elsif Small > Ureal_2_127 then |
| 9957 |
Error_Msg_Name_1 := Name_Small; |
| 9958 |
Error_Msg_N |
| 9959 |
("`&''%` too large, maximum allowed is 2.0'*'*127", Typ); |
| 9960 |
end if; |
| 9961 |
|
| 9962 |
if Actual_Size > 64 |
| 9963 |
and then (Norm_Num (Small) > Uint_2 ** 127 |
| 9964 |
or else Norm_Den (Small) > Uint_2 ** 127) |
| 9965 |
and then Small /= Ureal_2_M_128 |
| 9966 |
then |
| 9967 |
Error_Msg_Name_1 := Name_Small; |
| 9968 |
Error_Msg_N |
| 9969 |
("`&''%` not the ratio of two 128-bit integers", Typ); |
| 9970 |
end if; |
| 9971 |
|
| 9972 |
if Smaller (Expr_Value_R (Lo), Ureal_M_10_76) then |
| 9973 |
Error_Msg_Name_1 := Name_First; |
| 9974 |
Error_Msg_N |
| 9975 |
("`&''%` too small, minimum allowed is -1.0E+76", Typ); |
| 9976 |
end if; |
| 9977 |
|
| 9978 |
if Larger (Expr_Value_R (Hi), Ureal_10_76) then |
| 9979 |
Error_Msg_Name_1 := Name_Last; |
| 9980 |
Error_Msg_N |
| 9981 |
("`&''%` too large, maximum allowed is 1.0E+76", Typ); |
| 9982 |
end if; |
| 9983 |
end if; |
| 9984 |
|
| 9985 |
-- For the decimal case, none of this fudging is required, since there |
| 9986 |
-- are no end-point problems in the decimal case (the end-points are |
| 9987 |
-- always included). |
| 9988 |
|
| 9989 |
else |
| 9990 |
Actual_Size := Fsize (Loval, Hival); |
| 9991 |
end if; |
| 9992 |
|
| 9993 |
-- At this stage, the actual size has been calculated and the proper |
| 9994 |
-- required bounds are stored in the low and high bounds. |
| 9995 |
|
| 9996 |
if Actual_Size > System_Max_Integer_Size then |
| 9997 |
Error_Msg_Uint_1 := UI_From_Int (Actual_Size); |
| 9998 |
Error_Msg_Uint_2 := UI_From_Int (System_Max_Integer_Size); |
| 9999 |
Error_Msg_N |
| 10000 |
("size required (^) for type& too large, maximum allowed is ^", |
| 10001 |
Typ); |
| 10002 |
Actual_Size := System_Max_Integer_Size; |
| 10003 |
end if; |
| 10004 |
|
| 10005 |
-- Check size against explicit given size |
| 10006 |
|
| 10007 |
if Has_Size_Clause (Typ) then |
| 10008 |
if Actual_Size > RM_Size (Typ) then |
| 10009 |
Error_Msg_Uint_1 := RM_Size (Typ); |
| 10010 |
Error_Msg_Uint_2 := UI_From_Int (Actual_Size); |
| 10011 |
Error_Msg_NE |
| 10012 |
("size given (^) for type& too small, minimum allowed is ^", |
| 10013 |
Size_Clause (Typ), Typ); |
| 10014 |
|
| 10015 |
else |
| 10016 |
Actual_Size := UI_To_Int (Esize (Typ)); |
| 10017 |
end if; |
| 10018 |
|
| 10019 |
-- Increase size to next natural boundary if no size clause given |
| 10020 |
|
| 10021 |
else |
| 10022 |
if Actual_Size <= 8 then |
| 10023 |
Actual_Size := 8; |
| 10024 |
elsif Actual_Size <= 16 then |
| 10025 |
Actual_Size := 16; |
| 10026 |
elsif Actual_Size <= 32 then |
| 10027 |
Actual_Size := 32; |
| 10028 |
elsif Actual_Size <= 64 then |
| 10029 |
Actual_Size := 64; |
| 10030 |
else |
| 10031 |
Actual_Size := 128; |
| 10032 |
end if; |
| 10033 |
|
| 10034 |
Set_Esize (Typ, UI_From_Int (Actual_Size)); |
| 10035 |
Adjust_Esize_For_Alignment (Typ); |
| 10036 |
end if; |
| 10037 |
|
| 10038 |
-- If we have a base type, then expand the bounds so that they extend to |
| 10039 |
-- the full width of the allocated size in bits, to avoid junk range |
| 10040 |
-- checks on intermediate computations. |
| 10041 |
|
| 10042 |
if Typ = Btyp then |
| 10043 |
Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1)))); |
| 10044 |
Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1))); |
| 10045 |
end if; |
| 10046 |
|
| 10047 |
-- Final step is to reanalyze the bounds using the proper type |
| 10048 |
-- and set the Corresponding_Integer_Value fields of the literals. |
| 10049 |
|
| 10050 |
Set_Etype (Lo, Empty); |
| 10051 |
Set_Analyzed (Lo, False); |
| 10052 |
Analyze (Lo); |
| 10053 |
|
| 10054 |
-- Resolve with universal fixed if the base type, and with the base |
| 10055 |
-- type if we are freezing a subtype. Note we can't resolve the base |
| 10056 |
-- type with itself, that would be a reference before definition. |
| 10057 |
-- The resolution of the bounds of a subtype, if they are given by real |
| 10058 |
-- literals, includes the setting of the Corresponding_Integer_Value, |
| 10059 |
-- as for other literals of a fixed-point type. |
| 10060 |
|
| 10061 |
if Typ = Btyp then |
| 10062 |
Resolve (Lo, Universal_Fixed); |
| 10063 |
Set_Corresponding_Integer_Value |
| 10064 |
(Lo, UR_To_Uint (Realval (Lo) / Small)); |
| 10065 |
else |
| 10066 |
Resolve (Lo, Btyp); |
| 10067 |
end if; |
| 10068 |
|
| 10069 |
-- Similar processing for high bound |
| 10070 |
|
| 10071 |
Set_Etype (Hi, Empty); |
| 10072 |
Set_Analyzed (Hi, False); |
| 10073 |
Analyze (Hi); |
| 10074 |
|
| 10075 |
if Typ = Btyp then |
| 10076 |
Resolve (Hi, Universal_Fixed); |
| 10077 |
Set_Corresponding_Integer_Value |
| 10078 |
(Hi, UR_To_Uint (Realval (Hi) / Small)); |
| 10079 |
else |
| 10080 |
Resolve (Hi, Btyp); |
| 10081 |
end if; |
| 10082 |
|
| 10083 |
-- Set type of range to correspond to bounds |
| 10084 |
|
| 10085 |
Set_Etype (Rng, Etype (Lo)); |
| 10086 |
|
| 10087 |
-- Set Esize to calculated size if not set already |
| 10088 |
|
| 10089 |
if not Known_Esize (Typ) then |
| 10090 |
Set_Esize (Typ, UI_From_Int (Actual_Size)); |
| 10091 |
end if; |
| 10092 |
|
| 10093 |
-- Set RM_Size if not already set. If already set, check value |
| 10094 |
|
| 10095 |
declare |
| 10096 |
Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ)); |
| 10097 |
|
| 10098 |
begin |
| 10099 |
if Known_RM_Size (Typ) then |
| 10100 |
if RM_Size (Typ) < Minsiz then |
| 10101 |
Error_Msg_Uint_1 := RM_Size (Typ); |
| 10102 |
Error_Msg_Uint_2 := Minsiz; |
| 10103 |
Error_Msg_NE |
| 10104 |
("size given (^) for type& too small, minimum allowed is ^", |
| 10105 |
Size_Clause (Typ), Typ); |
| 10106 |
end if; |
| 10107 |
|
| 10108 |
else |
| 10109 |
Set_RM_Size (Typ, Minsiz); |
| 10110 |
end if; |
| 10111 |
end; |
| 10112 |
|
| 10113 |
-- Check for shaving |
| 10114 |
|
| 10115 |
if Comes_From_Source (Typ) then |
| 10116 |
|
| 10117 |
-- In SPARK mode the given bounds must be strictly representable |
| 10118 |
|
| 10119 |
if SPARK_Mode = On then |
| 10120 |
if Orig_Lo < Expr_Value_R (Lo) then |
| 10121 |
Error_Msg_NE |
| 10122 |
("declared low bound of type & is outside type range", |
| 10123 |
Lo, Typ); |
| 10124 |
end if; |
| 10125 |
|
| 10126 |
if Orig_Hi > Expr_Value_R (Hi) then |
| 10127 |
Error_Msg_NE |
| 10128 |
("declared high bound of type & is outside type range", |
| 10129 |
Hi, Typ); |
| 10130 |
end if; |
| 10131 |
|
| 10132 |
else |
| 10133 |
if Orig_Lo < Expr_Value_R (Lo) then |
| 10134 |
Error_Msg_N |
| 10135 |
("declared low bound of type & is outside type range??", Typ); |
| 10136 |
Error_Msg_N |
| 10137 |
("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ); |
| 10138 |
end if; |
| 10139 |
|
| 10140 |
if Orig_Hi > Expr_Value_R (Hi) then |
| 10141 |
Error_Msg_N |
| 10142 |
("declared high bound of type & is outside type range??", |
| 10143 |
Typ); |
| 10144 |
Error_Msg_N |
| 10145 |
("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ); |
| 10146 |
end if; |
| 10147 |
end if; |
| 10148 |
end if; |
| 10149 |
end Freeze_Fixed_Point_Type; |
| 10150 |
|
| 10151 |
------------------ |
| 10152 |
-- Freeze_Itype -- |
| 10153 |
------------------ |
| 10154 |
|
| 10155 |
procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is |
| 10156 |
L : List_Id; |
| 10157 |
|
| 10158 |
begin |
| 10159 |
Set_Has_Delayed_Freeze (T); |
| 10160 |
L := Freeze_Entity (T, N); |
| 10161 |
|
| 10162 |
Insert_Actions (N, L); |
| 10163 |
end Freeze_Itype; |
| 10164 |
|
| 10165 |
-------------------------- |
| 10166 |
-- Freeze_Static_Object -- |
| 10167 |
-------------------------- |
| 10168 |
|
| 10169 |
procedure Freeze_Static_Object (E : Entity_Id) is |
| 10170 |
|
| 10171 |
Cannot_Be_Static : exception; |
| 10172 |
-- Exception raised if the type of a static object cannot be made |
| 10173 |
-- static. This happens if the type depends on non-global objects. |
| 10174 |
|
| 10175 |
procedure Ensure_Expression_Is_SA (N : Node_Id); |
| 10176 |
-- Called to ensure that an expression used as part of a type definition |
| 10177 |
-- is statically allocatable, which means that the expression type is |
| 10178 |
-- statically allocatable, and the expression is either static, or a |
| 10179 |
-- reference to a library level constant. |
| 10180 |
|
| 10181 |
procedure Ensure_Type_Is_SA (Typ : Entity_Id); |
| 10182 |
-- Called to mark a type as static, checking that it is possible |
| 10183 |
-- to set the type as static. If it is not possible, then the |
| 10184 |
-- exception Cannot_Be_Static is raised. |
| 10185 |
|
| 10186 |
----------------------------- |
| 10187 |
-- Ensure_Expression_Is_SA -- |
| 10188 |
----------------------------- |
| 10189 |
|
| 10190 |
procedure Ensure_Expression_Is_SA (N : Node_Id) is |
| 10191 |
Ent : Entity_Id; |
| 10192 |
|
| 10193 |
begin |
| 10194 |
Ensure_Type_Is_SA (Etype (N)); |
| 10195 |
|
| 10196 |
if Is_OK_Static_Expression (N) then |
| 10197 |
return; |
| 10198 |
|
| 10199 |
elsif Nkind (N) = N_Identifier then |
| 10200 |
Ent := Entity (N); |
| 10201 |
|
| 10202 |
if Present (Ent) |
| 10203 |
and then Ekind (Ent) = E_Constant |
| 10204 |
and then Is_Library_Level_Entity (Ent) |
| 10205 |
then |
| 10206 |
return; |
| 10207 |
end if; |
| 10208 |
end if; |
| 10209 |
|
| 10210 |
raise Cannot_Be_Static; |
| 10211 |
end Ensure_Expression_Is_SA; |
| 10212 |
|
| 10213 |
----------------------- |
| 10214 |
-- Ensure_Type_Is_SA -- |
| 10215 |
----------------------- |
| 10216 |
|
| 10217 |
procedure Ensure_Type_Is_SA (Typ : Entity_Id) is |
| 10218 |
N : Node_Id; |
| 10219 |
C : Entity_Id; |
| 10220 |
|
| 10221 |
begin |
| 10222 |
-- If type is library level, we are all set |
| 10223 |
|
| 10224 |
if Is_Library_Level_Entity (Typ) then |
| 10225 |
return; |
| 10226 |
end if; |
| 10227 |
|
| 10228 |
-- We are also OK if the type already marked as statically allocated, |
| 10229 |
-- which means we processed it before. |
| 10230 |
|
| 10231 |
if Is_Statically_Allocated (Typ) then |
| 10232 |
return; |
| 10233 |
end if; |
| 10234 |
|
| 10235 |
-- Mark type as statically allocated |
| 10236 |
|
| 10237 |
Set_Is_Statically_Allocated (Typ); |
| 10238 |
|
| 10239 |
-- Check that it is safe to statically allocate this type |
| 10240 |
|
| 10241 |
if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then |
| 10242 |
Ensure_Expression_Is_SA (Type_Low_Bound (Typ)); |
| 10243 |
Ensure_Expression_Is_SA (Type_High_Bound (Typ)); |
| 10244 |
|
| 10245 |
elsif Is_Array_Type (Typ) then |
| 10246 |
N := First_Index (Typ); |
| 10247 |
while Present (N) loop |
| 10248 |
Ensure_Type_Is_SA (Etype (N)); |
| 10249 |
Next_Index (N); |
| 10250 |
end loop; |
| 10251 |
|
| 10252 |
Ensure_Type_Is_SA (Component_Type (Typ)); |
| 10253 |
|
| 10254 |
elsif Is_Access_Type (Typ) then |
| 10255 |
if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then |
| 10256 |
|
| 10257 |
declare |
| 10258 |
F : Entity_Id; |
| 10259 |
T : constant Entity_Id := Etype (Designated_Type (Typ)); |
| 10260 |
|
| 10261 |
begin |
| 10262 |
if T /= Standard_Void_Type then |
| 10263 |
Ensure_Type_Is_SA (T); |
| 10264 |
end if; |
| 10265 |
|
| 10266 |
F := First_Formal (Designated_Type (Typ)); |
| 10267 |
while Present (F) loop |
| 10268 |
Ensure_Type_Is_SA (Etype (F)); |
| 10269 |
Next_Formal (F); |
| 10270 |
end loop; |
| 10271 |
end; |
| 10272 |
|
| 10273 |
else |
| 10274 |
Ensure_Type_Is_SA (Designated_Type (Typ)); |
| 10275 |
end if; |
| 10276 |
|
| 10277 |
elsif Is_Record_Type (Typ) then |
| 10278 |
C := First_Entity (Typ); |
| 10279 |
while Present (C) loop |
| 10280 |
if Ekind (C) = E_Discriminant |
| 10281 |
or else Ekind (C) = E_Component |
| 10282 |
then |
| 10283 |
Ensure_Type_Is_SA (Etype (C)); |
| 10284 |
|
| 10285 |
elsif Is_Type (C) then |
| 10286 |
Ensure_Type_Is_SA (C); |
| 10287 |
end if; |
| 10288 |
|
| 10289 |
Next_Entity (C); |
| 10290 |
end loop; |
| 10291 |
|
| 10292 |
elsif Ekind (Typ) = E_Subprogram_Type then |
| 10293 |
Ensure_Type_Is_SA (Etype (Typ)); |
| 10294 |
|
| 10295 |
C := First_Formal (Typ); |
| 10296 |
while Present (C) loop |
| 10297 |
Ensure_Type_Is_SA (Etype (C)); |
| 10298 |
Next_Formal (C); |
| 10299 |
end loop; |
| 10300 |
|
| 10301 |
else |
| 10302 |
raise Cannot_Be_Static; |
| 10303 |
end if; |
| 10304 |
end Ensure_Type_Is_SA; |
| 10305 |
|
| 10306 |
-- Start of processing for Freeze_Static_Object |
| 10307 |
|
| 10308 |
begin |
| 10309 |
Ensure_Type_Is_SA (Etype (E)); |
| 10310 |
|
| 10311 |
exception |
| 10312 |
when Cannot_Be_Static => |
| 10313 |
|
| 10314 |
-- If the object that cannot be static is imported or exported, then |
| 10315 |
-- issue an error message saying that this object cannot be imported |
| 10316 |
-- or exported. If it has an address clause it is an overlay in the |
| 10317 |
-- current partition and the static requirement is not relevant. |
| 10318 |
-- Do not issue any error message when ignoring rep clauses or for |
| 10319 |
-- compiler-generated entities. |
| 10320 |
|
| 10321 |
if Ignore_Rep_Clauses then |
| 10322 |
null; |
| 10323 |
|
| 10324 |
elsif not Comes_From_Source (E) then |
| 10325 |
pragma |
| 10326 |
Assert (Nkind (Parent (Declaration_Node (E))) in N_Case_Statement |
| 10327 |
| N_If_Statement); |
| 10328 |
|
| 10329 |
elsif Is_Imported (E) then |
| 10330 |
if No (Address_Clause (E)) then |
| 10331 |
Error_Msg_N |
| 10332 |
("& cannot be imported (local type is not constant)", E); |
| 10333 |
end if; |
| 10334 |
|
| 10335 |
-- Otherwise must be exported, something is wrong if compiler |
| 10336 |
-- is marking something as statically allocated which cannot be). |
| 10337 |
|
| 10338 |
else pragma Assert (Is_Exported (E)); |
| 10339 |
Error_Msg_N |
| 10340 |
("& cannot be exported (local type is not constant)", E); |
| 10341 |
end if; |
| 10342 |
end Freeze_Static_Object; |
| 10343 |
|
| 10344 |
----------------------- |
| 10345 |
-- Freeze_Subprogram -- |
| 10346 |
----------------------- |
| 10347 |
|
| 10348 |
procedure Freeze_Subprogram (E : Entity_Id) is |
| 10349 |
|
| 10350 |
procedure Set_Profile_Convention (Subp_Id : Entity_Id); |
| 10351 |
-- Set the conventions of all anonymous access-to-subprogram formals and |
| 10352 |
-- result subtype of subprogram Subp_Id to the convention of Subp_Id. |
| 10353 |
|
| 10354 |
---------------------------- |
| 10355 |
-- Set_Profile_Convention -- |
| 10356 |
---------------------------- |
| 10357 |
|
| 10358 |
procedure Set_Profile_Convention (Subp_Id : Entity_Id) is |
| 10359 |
Conv : constant Convention_Id := Convention (Subp_Id); |
| 10360 |
|
| 10361 |
procedure Set_Type_Convention (Typ : Entity_Id); |
| 10362 |
-- Set the convention of anonymous access-to-subprogram type Typ and |
| 10363 |
-- its designated type to Conv. |
| 10364 |
|
| 10365 |
------------------------- |
| 10366 |
-- Set_Type_Convention -- |
| 10367 |
------------------------- |
| 10368 |
|
| 10369 |
procedure Set_Type_Convention (Typ : Entity_Id) is |
| 10370 |
begin |
| 10371 |
-- Set the convention on both the anonymous access-to-subprogram |
| 10372 |
-- type and the subprogram type it points to because both types |
| 10373 |
-- participate in conformance-related checks. |
| 10374 |
|
| 10375 |
if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then |
| 10376 |
Set_Convention (Typ, Conv); |
| 10377 |
Set_Convention (Designated_Type (Typ), Conv); |
| 10378 |
end if; |
| 10379 |
end Set_Type_Convention; |
| 10380 |
|
| 10381 |
-- Local variables |
| 10382 |
|
| 10383 |
Formal : Entity_Id; |
| 10384 |
|
| 10385 |
-- Start of processing for Set_Profile_Convention |
| 10386 |
|
| 10387 |
begin |
| 10388 |
Formal := First_Formal (Subp_Id); |
| 10389 |
while Present (Formal) loop |
| 10390 |
Set_Type_Convention (Etype (Formal)); |
| 10391 |
Next_Formal (Formal); |
| 10392 |
end loop; |
| 10393 |
|
| 10394 |
if Ekind (Subp_Id) = E_Function then |
| 10395 |
Set_Type_Convention (Etype (Subp_Id)); |
| 10396 |
end if; |
| 10397 |
end Set_Profile_Convention; |
| 10398 |
|
| 10399 |
-- Local variables |
| 10400 |
|
| 10401 |
F : Entity_Id; |
| 10402 |
Retype : Entity_Id; |
| 10403 |
|
| 10404 |
-- Start of processing for Freeze_Subprogram |
| 10405 |
|
| 10406 |
begin |
| 10407 |
-- Subprogram may not have an address clause unless it is imported |
| 10408 |
|
| 10409 |
if Present (Address_Clause (E)) then |
| 10410 |
if not Is_Imported (E) then |
| 10411 |
Error_Msg_N |
| 10412 |
("address clause can only be given for imported subprogram", |
| 10413 |
Name (Address_Clause (E))); |
| 10414 |
end if; |
| 10415 |
end if; |
| 10416 |
|
| 10417 |
-- Reset the Pure indication on an imported subprogram unless an |
| 10418 |
-- explicit Pure_Function pragma was present or the subprogram is an |
| 10419 |
-- intrinsic. We do this because otherwise it is an insidious error |
| 10420 |
-- to call a non-pure function from pure unit and have calls |
| 10421 |
-- mysteriously optimized away. What happens here is that the Import |
| 10422 |
-- can bypass the normal check to ensure that pure units call only pure |
| 10423 |
-- subprograms. |
| 10424 |
|
| 10425 |
-- The reason for the intrinsic exception is that in general, intrinsic |
| 10426 |
-- functions (such as shifts) are pure anyway. The only exceptions are |
| 10427 |
-- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure |
| 10428 |
-- in any case, so no problem arises. |
| 10429 |
|
| 10430 |
if Is_Imported (E) |
| 10431 |
and then Is_Pure (E) |
| 10432 |
and then not Has_Pragma_Pure_Function (E) |
| 10433 |
and then not Is_Intrinsic_Subprogram (E) |
| 10434 |
then |
| 10435 |
Set_Is_Pure (E, False); |
| 10436 |
end if; |
| 10437 |
|
| 10438 |
-- For C++ constructors check that their external name has been given |
| 10439 |
-- (either in pragma CPP_Constructor or in a pragma import). |
| 10440 |
|
| 10441 |
if Is_Constructor (E) |
| 10442 |
and then Convention (E) = Convention_CPP |
| 10443 |
and then |
| 10444 |
(No (Interface_Name (E)) |
| 10445 |
or else String_Equal |
| 10446 |
(L => Strval (Interface_Name (E)), |
| 10447 |
R => Strval (Get_Default_External_Name (E)))) |
| 10448 |
then |
| 10449 |
Error_Msg_N |
| 10450 |
("'C++ constructor must have external name or link name", E); |
| 10451 |
end if; |
| 10452 |
|
| 10453 |
-- We also reset the Pure indication on a subprogram with an Address |
| 10454 |
-- parameter, because the parameter may be used as a pointer and the |
| 10455 |
-- referenced data may change even if the address value does not. |
| 10456 |
|
| 10457 |
-- Note that if the programmer gave an explicit Pure_Function pragma, |
| 10458 |
-- then we believe the programmer, and leave the subprogram Pure. We |
| 10459 |
-- also suppress this check on run-time files. |
| 10460 |
|
| 10461 |
if Is_Pure (E) |
| 10462 |
and then Is_Subprogram (E) |
| 10463 |
and then not Has_Pragma_Pure_Function (E) |
| 10464 |
and then not Is_Internal_Unit (Current_Sem_Unit) |
| 10465 |
then |
| 10466 |
Check_Function_With_Address_Parameter (E); |
| 10467 |
end if; |
| 10468 |
|
| 10469 |
-- Ensure that all anonymous access-to-subprogram types inherit the |
| 10470 |
-- convention of their related subprogram (RM 6.3.1(13.1/5)). This is |
| 10471 |
-- not done for a defaulted convention Ada because those types also |
| 10472 |
-- default to Ada. Convention Protected must not be propagated when |
| 10473 |
-- the subprogram is an entry because this would be illegal. The only |
| 10474 |
-- way to force convention Protected on these kinds of types is to |
| 10475 |
-- include keyword "protected" in the access definition. Conventions |
| 10476 |
-- Entry and Intrinsic are also not propagated (specified by AI12-0207). |
| 10477 |
|
| 10478 |
if Convention (E) /= Convention_Ada |
| 10479 |
and then Convention (E) /= Convention_Protected |
| 10480 |
and then Convention (E) /= Convention_Entry |
| 10481 |
and then Convention (E) /= Convention_Intrinsic |
| 10482 |
then |
| 10483 |
Set_Profile_Convention (E); |
| 10484 |
end if; |
| 10485 |
|
| 10486 |
-- For non-foreign convention subprograms, this is where we create |
| 10487 |
-- the extra formals (for accessibility level and constrained bit |
| 10488 |
-- information). We delay this till the freeze point precisely so |
| 10489 |
-- that we know the convention. |
| 10490 |
|
| 10491 |
if not Has_Foreign_Convention (E) then |
| 10492 |
|
| 10493 |
-- Extra formals of dispatching operations are added later by |
| 10494 |
-- Expand_Freeze_Record_Type, which also adds extra formals to |
| 10495 |
-- internal entities built to handle interface types. |
| 10496 |
|
| 10497 |
if not Is_Dispatching_Operation (E) then |
| 10498 |
Create_Extra_Formals (E); |
| 10499 |
|
| 10500 |
pragma Assert |
| 10501 |
((Ekind (E) = E_Subprogram_Type |
| 10502 |
and then Extra_Formals_OK (E)) |
| 10503 |
or else |
| 10504 |
(Is_Subprogram (E) |
| 10505 |
and then Extra_Formals_OK (E) |
| 10506 |
and then |
| 10507 |
(No (Overridden_Operation (E)) |
| 10508 |
or else Extra_Formals_Match_OK (E, |
| 10509 |
Ultimate_Alias (Overridden_Operation (E)))))); |
| 10510 |
end if; |
| 10511 |
|
| 10512 |
Set_Mechanisms (E); |
| 10513 |
|
| 10514 |
-- If this is convention Ada and a Valued_Procedure, that's odd |
| 10515 |
|
| 10516 |
if Ekind (E) = E_Procedure |
| 10517 |
and then Is_Valued_Procedure (E) |
| 10518 |
and then Convention (E) = Convention_Ada |
| 10519 |
and then Warn_On_Export_Import |
| 10520 |
then |
| 10521 |
Error_Msg_N |
| 10522 |
("??Valued_Procedure has no effect for convention Ada", E); |
| 10523 |
Set_Is_Valued_Procedure (E, False); |
| 10524 |
end if; |
| 10525 |
|
| 10526 |
-- Case of foreign convention |
| 10527 |
|
| 10528 |
else |
| 10529 |
Set_Mechanisms (E); |
| 10530 |
|
| 10531 |
-- For foreign conventions, warn about return of unconstrained array |
| 10532 |
|
| 10533 |
if Ekind (E) = E_Function then |
| 10534 |
Retype := Underlying_Type (Etype (E)); |
| 10535 |
|
| 10536 |
-- If no return type, probably some other error, e.g. a |
| 10537 |
-- missing full declaration, so ignore. |
| 10538 |
|
| 10539 |
if No (Retype) then |
| 10540 |
null; |
| 10541 |
|
| 10542 |
-- If the return type is generic, we have emitted a warning |
| 10543 |
-- earlier on, and there is nothing else to check here. Specific |
| 10544 |
-- instantiations may lead to erroneous behavior. |
| 10545 |
|
| 10546 |
elsif Is_Generic_Type (Etype (E)) then |
| 10547 |
null; |
| 10548 |
|
| 10549 |
-- Display warning if returning unconstrained array |
| 10550 |
|
| 10551 |
elsif Is_Array_Type (Retype) |
| 10552 |
and then not Is_Constrained (Retype) |
| 10553 |
|
| 10554 |
-- Check appropriate warning is enabled (should we check for |
| 10555 |
-- Warnings (Off) on specific entities here, probably so???) |
| 10556 |
|
| 10557 |
and then Warn_On_Export_Import |
| 10558 |
then |
| 10559 |
Error_Msg_N |
| 10560 |
("?x?foreign convention function& should not return " & |
| 10561 |
"unconstrained array", E); |
| 10562 |
return; |
| 10563 |
end if; |
| 10564 |
end if; |
| 10565 |
|
| 10566 |
-- If any of the formals for an exported foreign convention |
| 10567 |
-- subprogram have defaults, then emit an appropriate warning since |
| 10568 |
-- this is odd (default cannot be used from non-Ada code) |
| 10569 |
|
| 10570 |
if Is_Exported (E) then |
| 10571 |
F := First_Formal (E); |
| 10572 |
while Present (F) loop |
| 10573 |
if Warn_On_Export_Import |
| 10574 |
and then Present (Default_Value (F)) |
| 10575 |
then |
| 10576 |
Error_Msg_N |
| 10577 |
("?x?parameter cannot be defaulted in non-Ada call", |
| 10578 |
Default_Value (F)); |
| 10579 |
end if; |
| 10580 |
|
| 10581 |
Next_Formal (F); |
| 10582 |
end loop; |
| 10583 |
end if; |
| 10584 |
end if; |
| 10585 |
|
| 10586 |
-- Pragma Inline_Always is disallowed for dispatching subprograms |
| 10587 |
-- because the address of such subprograms is saved in the dispatch |
| 10588 |
-- table to support dispatching calls, and dispatching calls cannot |
| 10589 |
-- be inlined. This is consistent with the restriction against using |
| 10590 |
-- 'Access or 'Address on an Inline_Always subprogram. |
| 10591 |
|
| 10592 |
if Is_Dispatching_Operation (E) |
| 10593 |
and then Has_Pragma_Inline_Always (E) |
| 10594 |
then |
| 10595 |
Error_Msg_N |
| 10596 |
("pragma Inline_Always not allowed for dispatching subprograms", E); |
| 10597 |
end if; |
| 10598 |
|
| 10599 |
if Is_Dispatching_Operation (E) |
| 10600 |
and then Present (Overridden_Operation (E)) |
| 10601 |
then |
| 10602 |
Local_Restrict.Check_Overriding |
| 10603 |
(Overrider_Op => E, Overridden_Op => Overridden_Operation (E)); |
| 10604 |
end if; |
| 10605 |
|
| 10606 |
-- Because of the implicit representation of inherited predefined |
| 10607 |
-- operators in the front-end, the overriding status of the operation |
| 10608 |
-- may be affected when a full view of a type is analyzed, and this is |
| 10609 |
-- not captured by the analysis of the corresponding type declaration. |
| 10610 |
-- Therefore the correctness of a not-overriding indicator must be |
| 10611 |
-- rechecked when the subprogram is frozen. |
| 10612 |
|
| 10613 |
if Nkind (E) = N_Defining_Operator_Symbol |
| 10614 |
and then not Error_Posted (Parent (E)) |
| 10615 |
then |
| 10616 |
Check_Overriding_Indicator (E, Empty, Is_Primitive (E)); |
| 10617 |
end if; |
| 10618 |
|
| 10619 |
-- Check illegal subprograms of tagged types and interface types that |
| 10620 |
-- have aspect/pragma First_Controlling_Parameter. |
| 10621 |
|
| 10622 |
if Comes_From_Source (E) |
| 10623 |
and then Is_Abstract_Subprogram (E) |
| 10624 |
then |
| 10625 |
if Is_Dispatching_Operation (E) then |
| 10626 |
if Ekind (E) = E_Function |
| 10627 |
and then Is_Interface (Etype (E)) |
| 10628 |
and then not Is_Class_Wide_Type (Etype (E)) |
| 10629 |
and then Has_First_Controlling_Parameter_Aspect |
| 10630 |
(Find_Dispatching_Type (E)) |
| 10631 |
then |
| 10632 |
Error_Msg_NE |
| 10633 |
("'First_'Controlling_'Parameter disallows returning a " |
| 10634 |
& "non-class-wide interface type", |
| 10635 |
E, Etype (E)); |
| 10636 |
end if; |
| 10637 |
|
| 10638 |
else |
| 10639 |
-- The type of the formals cannot be an interface type |
| 10640 |
|
| 10641 |
if Present (First_Formal (E)) then |
| 10642 |
declare |
| 10643 |
Formal : Entity_Id := First_Formal (E); |
| 10644 |
Has_Aspect : Boolean := False; |
| 10645 |
|
| 10646 |
begin |
| 10647 |
-- Check if some formal has the aspect |
| 10648 |
|
| 10649 |
while Present (Formal) loop |
| 10650 |
if Is_Tagged_Type (Etype (Formal)) |
| 10651 |
and then |
| 10652 |
Has_First_Controlling_Parameter_Aspect |
| 10653 |
(Etype (Formal)) |
| 10654 |
then |
| 10655 |
Has_Aspect := True; |
| 10656 |
end if; |
| 10657 |
|
| 10658 |
Next_Formal (Formal); |
| 10659 |
end loop; |
| 10660 |
|
| 10661 |
-- If the aspect is present then report the error |
| 10662 |
|
| 10663 |
if Has_Aspect then |
| 10664 |
Formal := First_Formal (E); |
| 10665 |
|
| 10666 |
while Present (Formal) loop |
| 10667 |
if Is_Interface (Etype (Formal)) |
| 10668 |
and then not Is_Class_Wide_Type (Etype (Formal)) |
| 10669 |
then |
| 10670 |
Error_Msg_NE |
| 10671 |
("not a dispatching primitive of interface type&", |
| 10672 |
E, Etype (Formal)); |
| 10673 |
Error_Msg_N |
| 10674 |
("\disallowed by 'First_'Controlling_'Parameter " |
| 10675 |
& "aspect", E); |
| 10676 |
end if; |
| 10677 |
|
| 10678 |
Next_Formal (Formal); |
| 10679 |
end loop; |
| 10680 |
end if; |
| 10681 |
end; |
| 10682 |
end if; |
| 10683 |
|
| 10684 |
if Ekind (E) = E_Function |
| 10685 |
and then Is_Interface (Etype (E)) |
| 10686 |
and then not Is_Class_Wide_Type (Etype (E)) |
| 10687 |
and then Has_First_Controlling_Parameter_Aspect (Etype (E)) |
| 10688 |
then |
| 10689 |
Error_Msg_NE |
| 10690 |
("not a dispatching primitive of interface type&", |
| 10691 |
E, Etype (E)); |
| 10692 |
Error_Msg_N |
| 10693 |
("\disallowed by 'First_'Controlling_'Parameter " |
| 10694 |
& "aspect", E); |
| 10695 |
end if; |
| 10696 |
end if; |
| 10697 |
end if; |
| 10698 |
end Freeze_Subprogram; |
| 10699 |
|
| 10700 |
---------------------- |
| 10701 |
-- Is_Fully_Defined -- |
| 10702 |
---------------------- |
| 10703 |
|
| 10704 |
function Is_Fully_Defined (T : Entity_Id) return Boolean is |
| 10705 |
begin |
| 10706 |
if Ekind (T) = E_Class_Wide_Type then |
| 10707 |
return Is_Fully_Defined (Etype (T)); |
| 10708 |
|
| 10709 |
elsif Is_Array_Type (T) then |
| 10710 |
return Is_Fully_Defined (Component_Type (T)); |
| 10711 |
|
| 10712 |
elsif Is_Record_Type (T) |
| 10713 |
and not Is_Private_Type (T) |
| 10714 |
then |
| 10715 |
-- Verify that the record type has no components with private types |
| 10716 |
-- without completion. |
| 10717 |
|
| 10718 |
declare |
| 10719 |
Comp : Entity_Id; |
| 10720 |
|
| 10721 |
begin |
| 10722 |
Comp := First_Component (T); |
| 10723 |
while Present (Comp) loop |
| 10724 |
if not Is_Fully_Defined (Etype (Comp)) then |
| 10725 |
return False; |
| 10726 |
end if; |
| 10727 |
|
| 10728 |
Next_Component (Comp); |
| 10729 |
end loop; |
| 10730 |
return True; |
| 10731 |
end; |
| 10732 |
|
| 10733 |
-- For the designated type of an access to subprogram, all types in |
| 10734 |
-- the profile must be fully defined. |
| 10735 |
|
| 10736 |
elsif Ekind (T) = E_Subprogram_Type then |
| 10737 |
declare |
| 10738 |
F : Entity_Id; |
| 10739 |
|
| 10740 |
begin |
| 10741 |
F := First_Formal (T); |
| 10742 |
while Present (F) loop |
| 10743 |
if not Is_Fully_Defined (Etype (F)) then |
| 10744 |
return False; |
| 10745 |
end if; |
| 10746 |
|
| 10747 |
Next_Formal (F); |
| 10748 |
end loop; |
| 10749 |
|
| 10750 |
return Is_Fully_Defined (Etype (T)); |
| 10751 |
end; |
| 10752 |
|
| 10753 |
else |
| 10754 |
return not Is_Private_Type (T) |
| 10755 |
or else Present (Full_View (Base_Type (T))); |
| 10756 |
end if; |
| 10757 |
end Is_Fully_Defined; |
| 10758 |
|
| 10759 |
--------------------------------- |
| 10760 |
-- Process_Default_Expressions -- |
| 10761 |
--------------------------------- |
| 10762 |
|
| 10763 |
procedure Process_Default_Expressions |
| 10764 |
(E : Entity_Id; |
| 10765 |
After : in out Node_Id) |
| 10766 |
is |
| 10767 |
Loc : constant Source_Ptr := Sloc (E); |
| 10768 |
Dbody : Node_Id; |
| 10769 |
Formal : Node_Id; |
| 10770 |
Dcopy : Node_Id; |
| 10771 |
Dnam : Entity_Id; |
| 10772 |
|
| 10773 |
begin |
| 10774 |
Set_Default_Expressions_Processed (E); |
| 10775 |
|
| 10776 |
-- A subprogram instance and its associated anonymous subprogram share |
| 10777 |
-- their signature. The default expression functions are defined in the |
| 10778 |
-- wrapper packages for the anonymous subprogram, and should not be |
| 10779 |
-- generated again for the instance. |
| 10780 |
|
| 10781 |
if Is_Generic_Instance (E) |
| 10782 |
and then Present (Alias (E)) |
| 10783 |
and then Default_Expressions_Processed (Alias (E)) |
| 10784 |
then |
| 10785 |
return; |
| 10786 |
end if; |
| 10787 |
|
| 10788 |
Formal := First_Formal (E); |
| 10789 |
while Present (Formal) loop |
| 10790 |
if Present (Default_Value (Formal)) then |
| 10791 |
|
| 10792 |
-- We work with a copy of the default expression because we |
| 10793 |
-- do not want to disturb the original, since this would mess |
| 10794 |
-- up the conformance checking. |
| 10795 |
|
| 10796 |
Dcopy := New_Copy_Tree (Default_Value (Formal)); |
| 10797 |
|
| 10798 |
-- The analysis of the expression may generate insert actions, |
| 10799 |
-- which of course must not be executed. We wrap those actions |
| 10800 |
-- in a procedure that is not called, and later on eliminated. |
| 10801 |
-- The following cases have no side effects, and are analyzed |
| 10802 |
-- directly. |
| 10803 |
|
| 10804 |
if Nkind (Dcopy) = N_Identifier |
| 10805 |
or else Nkind (Dcopy) in N_Expanded_Name |
| 10806 |
| N_Integer_Literal |
| 10807 |
| N_Character_Literal |
| 10808 |
| N_String_Literal |
| 10809 |
| N_Real_Literal |
| 10810 |
or else (Nkind (Dcopy) = N_Attribute_Reference |
| 10811 |
and then Attribute_Name (Dcopy) = Name_Null_Parameter) |
| 10812 |
or else Known_Null (Dcopy) |
| 10813 |
then |
| 10814 |
-- If there is no default function, we must still do a full |
| 10815 |
-- analyze call on the default value, to ensure that all error |
| 10816 |
-- checks are performed, e.g. those associated with static |
| 10817 |
-- evaluation. Note: this branch will always be taken if the |
| 10818 |
-- analyzer is turned off (but we still need the error checks). |
| 10819 |
|
| 10820 |
-- Note: the setting of parent here is to meet the requirement |
| 10821 |
-- that we can only analyze the expression while attached to |
| 10822 |
-- the tree. Really the requirement is that the parent chain |
| 10823 |
-- be set, we don't actually need to be in the tree. |
| 10824 |
|
| 10825 |
Set_Parent (Dcopy, Declaration_Node (Formal)); |
| 10826 |
Analyze (Dcopy); |
| 10827 |
|
| 10828 |
-- Default expressions are resolved with their own type if the |
| 10829 |
-- context is generic, to avoid anomalies with private types. |
| 10830 |
|
| 10831 |
if Ekind (Scope (E)) = E_Generic_Package then |
| 10832 |
Resolve (Dcopy); |
| 10833 |
else |
| 10834 |
Resolve (Dcopy, Etype (Formal)); |
| 10835 |
end if; |
| 10836 |
|
| 10837 |
-- If that resolved expression will raise constraint error, |
| 10838 |
-- then flag the default value as raising constraint error. |
| 10839 |
-- This allows a proper error message on the calls. |
| 10840 |
|
| 10841 |
if Raises_Constraint_Error (Dcopy) then |
| 10842 |
Set_Raises_Constraint_Error (Default_Value (Formal)); |
| 10843 |
end if; |
| 10844 |
|
| 10845 |
-- If the default is a parameterless call, we use the name of |
| 10846 |
-- the called function directly, and there is no body to build. |
| 10847 |
|
| 10848 |
elsif Nkind (Dcopy) = N_Function_Call |
| 10849 |
and then No (Parameter_Associations (Dcopy)) |
| 10850 |
then |
| 10851 |
null; |
| 10852 |
|
| 10853 |
-- Else construct and analyze the body of a wrapper procedure |
| 10854 |
-- that contains an object declaration to hold the expression. |
| 10855 |
-- Given that this is done only to complete the analysis, it is |
| 10856 |
-- simpler to build a procedure than a function which might |
| 10857 |
-- involve secondary stack expansion. |
| 10858 |
|
| 10859 |
else |
| 10860 |
Dnam := Make_Temporary (Loc, 'D'); |
| 10861 |
|
| 10862 |
Dbody := |
| 10863 |
Make_Subprogram_Body (Loc, |
| 10864 |
Specification => |
| 10865 |
Make_Procedure_Specification (Loc, |
| 10866 |
Defining_Unit_Name => Dnam), |
| 10867 |
|
| 10868 |
Declarations => New_List ( |
| 10869 |
Make_Object_Declaration (Loc, |
| 10870 |
Defining_Identifier => Make_Temporary (Loc, 'T'), |
| 10871 |
Object_Definition => |
| 10872 |
New_Occurrence_Of (Etype (Formal), Loc), |
| 10873 |
Expression => New_Copy_Tree (Dcopy))), |
| 10874 |
|
| 10875 |
Handled_Statement_Sequence => |
| 10876 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 10877 |
Statements => Empty_List)); |
| 10878 |
|
| 10879 |
Set_Scope (Dnam, Scope (E)); |
| 10880 |
Set_Assignment_OK (First (Declarations (Dbody))); |
| 10881 |
Set_Is_Eliminated (Dnam); |
| 10882 |
Insert_After (After, Dbody); |
| 10883 |
Analyze (Dbody); |
| 10884 |
After := Dbody; |
| 10885 |
end if; |
| 10886 |
end if; |
| 10887 |
|
| 10888 |
Next_Formal (Formal); |
| 10889 |
end loop; |
| 10890 |
end Process_Default_Expressions; |
| 10891 |
|
| 10892 |
---------------------------------------- |
| 10893 |
-- Set_Component_Alignment_If_Not_Set -- |
| 10894 |
---------------------------------------- |
| 10895 |
|
| 10896 |
procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is |
| 10897 |
begin |
| 10898 |
-- Ignore if not base type, subtypes don't need anything |
| 10899 |
|
| 10900 |
if Typ /= Base_Type (Typ) then |
| 10901 |
return; |
| 10902 |
end if; |
| 10903 |
|
| 10904 |
-- Do not override existing representation |
| 10905 |
|
| 10906 |
if Is_Packed (Typ) then |
| 10907 |
return; |
| 10908 |
|
| 10909 |
elsif Has_Specified_Layout (Typ) then |
| 10910 |
return; |
| 10911 |
|
| 10912 |
elsif Component_Alignment (Typ) /= Calign_Default then |
| 10913 |
return; |
| 10914 |
|
| 10915 |
else |
| 10916 |
Set_Component_Alignment |
| 10917 |
(Typ, Scope_Stack.Table |
| 10918 |
(Scope_Stack.Last).Component_Alignment_Default); |
| 10919 |
end if; |
| 10920 |
end Set_Component_Alignment_If_Not_Set; |
| 10921 |
|
| 10922 |
-------------------------- |
| 10923 |
-- Set_SSO_From_Default -- |
| 10924 |
-------------------------- |
| 10925 |
|
| 10926 |
procedure Set_SSO_From_Default (T : Entity_Id) is |
| 10927 |
Reversed : Boolean; |
| 10928 |
|
| 10929 |
begin |
| 10930 |
-- Set default SSO for an array or record base type, except in case of |
| 10931 |
-- a type extension (which always inherits the SSO of its parent type). |
| 10932 |
|
| 10933 |
if Is_Base_Type (T) |
| 10934 |
and then (Is_Array_Type (T) |
| 10935 |
or else (Is_Record_Type (T) |
| 10936 |
and then not (Is_Tagged_Type (T) |
| 10937 |
and then Is_Derived_Type (T)))) |
| 10938 |
then |
| 10939 |
Reversed := |
| 10940 |
(Bytes_Big_Endian and then SSO_Set_Low_By_Default (T)) |
| 10941 |
or else |
| 10942 |
(not Bytes_Big_Endian and then SSO_Set_High_By_Default (T)); |
| 10943 |
|
| 10944 |
if (SSO_Set_Low_By_Default (T) or else SSO_Set_High_By_Default (T)) |
| 10945 |
|
| 10946 |
-- For a record type, if bit order is specified explicitly, |
| 10947 |
-- then do not set SSO from default if not consistent. Note that |
| 10948 |
-- we do not want to look at a Bit_Order attribute definition |
| 10949 |
-- for a parent: if we were to inherit Bit_Order, then both |
| 10950 |
-- SSO_Set_*_By_Default flags would have been cleared already |
| 10951 |
-- (by Inherit_Aspects_At_Freeze_Point). |
| 10952 |
|
| 10953 |
and then not |
| 10954 |
(Is_Record_Type (T) |
| 10955 |
and then |
| 10956 |
Has_Rep_Item (T, Name_Bit_Order, Check_Parents => False) |
| 10957 |
and then Reverse_Bit_Order (T) /= Reversed) |
| 10958 |
then |
| 10959 |
-- If flags cause reverse storage order, then set the result. Note |
| 10960 |
-- that we would have ignored the pragma setting the non default |
| 10961 |
-- storage order in any case, hence the assertion at this point. |
| 10962 |
|
| 10963 |
pragma Assert |
| 10964 |
(not Reversed or else Support_Nondefault_SSO_On_Target); |
| 10965 |
|
| 10966 |
Set_Reverse_Storage_Order (T, Reversed); |
| 10967 |
|
| 10968 |
-- For a record type, also set reversed bit order. Note: if a bit |
| 10969 |
-- order has been specified explicitly, then this is a no-op. |
| 10970 |
|
| 10971 |
if Is_Record_Type (T) then |
| 10972 |
Set_Reverse_Bit_Order (T, Reversed); |
| 10973 |
end if; |
| 10974 |
end if; |
| 10975 |
end if; |
| 10976 |
end Set_SSO_From_Default; |
| 10977 |
|
| 10978 |
------------------------ |
| 10979 |
-- Should_Freeze_Type -- |
| 10980 |
------------------------ |
| 10981 |
|
| 10982 |
function Should_Freeze_Type |
| 10983 |
(Typ : Entity_Id; |
| 10984 |
E : Entity_Id; |
| 10985 |
N : Node_Id) return Boolean |
| 10986 |
is |
| 10987 |
Decl : constant Node_Id := Original_Node (Unit_Declaration_Node (E)); |
| 10988 |
|
| 10989 |
function Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate |
| 10990 |
(N : Node_Id) return Traverse_Result; |
| 10991 |
-- Return Abandon if N is a dispatching call to a subprogram |
| 10992 |
-- declared in the same scope as Typ, or a tagged result that |
| 10993 |
-- needs specific expansion, or an aggregate whose type is Typ. |
| 10994 |
|
| 10995 |
function Check_Freezing is new |
| 10996 |
Traverse_Func (Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate); |
| 10997 |
-- Return Abandon if the input expression requires freezing Typ |
| 10998 |
|
| 10999 |
function Within_Simple_Return_Statement (N : Node_Id) return Boolean; |
| 11000 |
-- Determine whether N is the expression of a simple return statement, |
| 11001 |
-- or the dependent expression of a conditional expression which is |
| 11002 |
-- the expression of a simple return statement, including recursively. |
| 11003 |
|
| 11004 |
------------------------------------------------------- |
| 11005 |
-- Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate -- |
| 11006 |
------------------------------------------------------- |
| 11007 |
|
| 11008 |
function Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate |
| 11009 |
(N : Node_Id) return Traverse_Result |
| 11010 |
is |
| 11011 |
begin |
| 11012 |
if Nkind (N) = N_Function_Call |
| 11013 |
and then Present (Controlling_Argument (N)) |
| 11014 |
and then Scope (Entity (Original_Node (Name (N)))) = Scope (Typ) |
| 11015 |
then |
| 11016 |
return Abandon; |
| 11017 |
|
| 11018 |
-- The expansion done in Expand_Simple_Function_Return will assign |
| 11019 |
-- the tag to the result in this case. |
| 11020 |
|
| 11021 |
elsif Is_Conversion_Or_Reference_To_Formal (N) |
| 11022 |
and then Within_Simple_Return_Statement (N) |
| 11023 |
and then Etype (N) = Typ |
| 11024 |
and then Is_Tagged_Type (Typ) |
| 11025 |
and then not Is_Class_Wide_Type (Typ) |
| 11026 |
then |
| 11027 |
return Abandon; |
| 11028 |
|
| 11029 |
elsif Nkind (N) in N_Aggregate |
| 11030 |
| N_Delta_Aggregate |
| 11031 |
| N_Extension_Aggregate |
| 11032 |
and then Base_Type (Etype (N)) = Base_Type (Typ) |
| 11033 |
then |
| 11034 |
return Abandon; |
| 11035 |
|
| 11036 |
else |
| 11037 |
return OK; |
| 11038 |
end if; |
| 11039 |
end Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate; |
| 11040 |
|
| 11041 |
------------------------------------ |
| 11042 |
-- Within_Simple_Return_Statement -- |
| 11043 |
------------------------------------ |
| 11044 |
|
| 11045 |
function Within_Simple_Return_Statement (N : Node_Id) return Boolean is |
| 11046 |
Par : constant Node_Id := Parent (N); |
| 11047 |
|
| 11048 |
begin |
| 11049 |
if Nkind (Par) = N_Simple_Return_Statement then |
| 11050 |
return True; |
| 11051 |
|
| 11052 |
elsif Nkind (Par) = N_Case_Expression_Alternative then |
| 11053 |
return Within_Simple_Return_Statement (Parent (Par)); |
| 11054 |
|
| 11055 |
elsif Nkind (Par) = N_If_Expression |
| 11056 |
and then N /= First (Expressions (Par)) |
| 11057 |
then |
| 11058 |
return Within_Simple_Return_Statement (Par); |
| 11059 |
|
| 11060 |
else |
| 11061 |
return False; |
| 11062 |
end if; |
| 11063 |
end Within_Simple_Return_Statement; |
| 11064 |
|
| 11065 |
-- Start of processing for Should_Freeze_Type |
| 11066 |
|
| 11067 |
begin |
| 11068 |
return Within_Scope (Typ, Current_Scope) |
| 11069 |
or else (Nkind (N) = N_Subprogram_Renaming_Declaration |
| 11070 |
and then Present (Corresponding_Formal_Spec (N))) |
| 11071 |
or else (Present (Decl) |
| 11072 |
and then Nkind (Decl) = N_Expression_Function |
| 11073 |
and then Check_Freezing (Expression (Decl)) = Abandon); |
| 11074 |
end Should_Freeze_Type; |
| 11075 |
|
| 11076 |
------------------ |
| 11077 |
-- Undelay_Type -- |
| 11078 |
------------------ |
| 11079 |
|
| 11080 |
procedure Undelay_Type (T : Entity_Id) is |
| 11081 |
begin |
| 11082 |
Set_Has_Delayed_Freeze (T, False); |
| 11083 |
Set_Freeze_Node (T, Empty); |
| 11084 |
|
| 11085 |
-- Since we don't want T to have a Freeze_Node, we don't want its |
| 11086 |
-- Full_View or Corresponding_Record_Type to have one either. |
| 11087 |
|
| 11088 |
-- ??? Fundamentally, this whole handling is unpleasant. What we really |
| 11089 |
-- want is to be sure that for an Itype that's part of record R and is a |
| 11090 |
-- subtype of type T, that it's frozen after the later of the freeze |
| 11091 |
-- points of R and T. We have no way of doing that directly, so what we |
| 11092 |
-- do is force most such Itypes to be frozen as part of freezing R via |
| 11093 |
-- this procedure and only delay the ones that need to be delayed |
| 11094 |
-- (mostly the designated types of access types that are defined as part |
| 11095 |
-- of the record). |
| 11096 |
|
| 11097 |
if Is_Private_Type (T) |
| 11098 |
and then Present (Full_View (T)) |
| 11099 |
and then Is_Itype (Full_View (T)) |
| 11100 |
and then Is_Record_Type (Scope (Full_View (T))) |
| 11101 |
then |
| 11102 |
Undelay_Type (Full_View (T)); |
| 11103 |
end if; |
| 11104 |
|
| 11105 |
if Is_Concurrent_Type (T) |
| 11106 |
and then Present (Corresponding_Record_Type (T)) |
| 11107 |
and then Is_Itype (Corresponding_Record_Type (T)) |
| 11108 |
and then Is_Record_Type (Scope (Corresponding_Record_Type (T))) |
| 11109 |
then |
| 11110 |
Undelay_Type (Corresponding_Record_Type (T)); |
| 11111 |
end if; |
| 11112 |
end Undelay_Type; |
| 11113 |
|
| 11114 |
------------------ |
| 11115 |
-- Warn_Overlay -- |
| 11116 |
------------------ |
| 11117 |
|
| 11118 |
procedure Warn_Overlay (Expr : Node_Id; Typ : Entity_Id; Nam : Node_Id) is |
| 11119 |
Ent : constant Entity_Id := Entity (Nam); |
| 11120 |
-- The object to which the address clause applies |
| 11121 |
|
| 11122 |
Init : Node_Id; |
| 11123 |
Old : Entity_Id := Empty; |
| 11124 |
Decl : Node_Id; |
| 11125 |
|
| 11126 |
begin |
| 11127 |
-- No warning if address clause overlay warnings are off |
| 11128 |
|
| 11129 |
if not Address_Clause_Overlay_Warnings then |
| 11130 |
return; |
| 11131 |
end if; |
| 11132 |
|
| 11133 |
-- No warning if there is an explicit initialization |
| 11134 |
|
| 11135 |
Init := Original_Node (Expression (Declaration_Node (Ent))); |
| 11136 |
|
| 11137 |
if Present (Init) and then Comes_From_Source (Init) then |
| 11138 |
return; |
| 11139 |
end if; |
| 11140 |
|
| 11141 |
-- No warning if there is no default initialization |
| 11142 |
|
| 11143 |
if No_Initialization (Declaration_Node (Ent)) then |
| 11144 |
return; |
| 11145 |
end if; |
| 11146 |
|
| 11147 |
-- We only give the warning for non-imported entities of a type for |
| 11148 |
-- which a non-null base init proc is defined, or for objects of access |
| 11149 |
-- types with implicit null initialization, or when Normalize_Scalars |
| 11150 |
-- applies and the type is scalar or a string type (the latter being |
| 11151 |
-- tested for because predefined String types are initialized by inline |
| 11152 |
-- code rather than by an init_proc). Note that we do not give the |
| 11153 |
-- warning for Initialize_Scalars, since we suppressed initialization |
| 11154 |
-- in this case. Also, do not warn if Suppress_Initialization is set |
| 11155 |
-- either on the type, or on the object via pragma or aspect. |
| 11156 |
|
| 11157 |
if Present (Expr) |
| 11158 |
and then not Is_Imported (Ent) |
| 11159 |
and then not Initialization_Suppressed (Typ) |
| 11160 |
and then not (Ekind (Ent) = E_Variable |
| 11161 |
and then Initialization_Suppressed (Ent)) |
| 11162 |
and then (Has_Non_Null_Base_Init_Proc (Typ) |
| 11163 |
or else Is_Access_Type (Typ) |
| 11164 |
or else (Normalize_Scalars |
| 11165 |
and then (Is_Scalar_Type (Typ) |
| 11166 |
or else Is_String_Type (Typ)))) |
| 11167 |
then |
| 11168 |
if Nkind (Expr) = N_Attribute_Reference |
| 11169 |
and then Is_Entity_Name (Prefix (Expr)) |
| 11170 |
then |
| 11171 |
Old := Entity (Prefix (Expr)); |
| 11172 |
|
| 11173 |
elsif Is_Entity_Name (Expr) |
| 11174 |
and then Ekind (Entity (Expr)) = E_Constant |
| 11175 |
then |
| 11176 |
Decl := Declaration_Node (Entity (Expr)); |
| 11177 |
|
| 11178 |
if Nkind (Decl) = N_Object_Declaration |
| 11179 |
and then Present (Expression (Decl)) |
| 11180 |
and then Nkind (Expression (Decl)) = N_Attribute_Reference |
| 11181 |
and then Is_Entity_Name (Prefix (Expression (Decl))) |
| 11182 |
then |
| 11183 |
Old := Entity (Prefix (Expression (Decl))); |
| 11184 |
|
| 11185 |
elsif Nkind (Expr) = N_Function_Call then |
| 11186 |
return; |
| 11187 |
end if; |
| 11188 |
|
| 11189 |
-- A function call (most likely to To_Address) is probably not an |
| 11190 |
-- overlay, so skip warning. Ditto if the function call was inlined |
| 11191 |
-- and transformed into an entity. |
| 11192 |
|
| 11193 |
elsif Nkind (Original_Node (Expr)) = N_Function_Call then |
| 11194 |
return; |
| 11195 |
end if; |
| 11196 |
|
| 11197 |
-- If a pragma Import follows, we assume that it is for the current |
| 11198 |
-- target of the address clause, and skip the warning. There may be |
| 11199 |
-- a source pragma or an aspect that specifies import and generates |
| 11200 |
-- the corresponding pragma. These will indicate that the entity is |
| 11201 |
-- imported and that is checked above so that the spurious warning |
| 11202 |
-- (generated when the entity is frozen) will be suppressed. The |
| 11203 |
-- pragma may be attached to the aspect, so it is not yet a list |
| 11204 |
-- member. |
| 11205 |
|
| 11206 |
if Is_List_Member (Parent (Expr)) then |
| 11207 |
Decl := Next (Parent (Expr)); |
| 11208 |
|
| 11209 |
if Present (Decl) |
| 11210 |
and then Nkind (Decl) = N_Pragma |
| 11211 |
and then Pragma_Name (Decl) = Name_Import |
| 11212 |
then |
| 11213 |
return; |
| 11214 |
end if; |
| 11215 |
end if; |
| 11216 |
|
| 11217 |
-- Otherwise give warning message |
| 11218 |
|
| 11219 |
if Present (Old) then |
| 11220 |
Error_Msg_Node_2 := Old; |
| 11221 |
Error_Msg_N |
| 11222 |
("default initialization of & may modify &?o?", |
| 11223 |
Nam); |
| 11224 |
else |
| 11225 |
Error_Msg_N |
| 11226 |
("default initialization of & may modify overlaid storage?o?", |
| 11227 |
Nam); |
| 11228 |
end if; |
| 11229 |
|
| 11230 |
-- Add friendly warning if initialization comes from a packed array |
| 11231 |
-- component. |
| 11232 |
|
| 11233 |
if Is_Record_Type (Typ) then |
| 11234 |
declare |
| 11235 |
Comp : Entity_Id; |
| 11236 |
|
| 11237 |
begin |
| 11238 |
Comp := First_Component (Typ); |
| 11239 |
while Present (Comp) loop |
| 11240 |
if Nkind (Parent (Comp)) = N_Component_Declaration |
| 11241 |
and then Present (Expression (Parent (Comp))) |
| 11242 |
then |
| 11243 |
exit; |
| 11244 |
elsif Is_Array_Type (Etype (Comp)) |
| 11245 |
and then Present (Packed_Array_Impl_Type (Etype (Comp))) |
| 11246 |
then |
| 11247 |
Error_Msg_NE |
| 11248 |
("\packed array component& " & |
| 11249 |
"will be initialized to zero?o?", |
| 11250 |
Nam, Comp); |
| 11251 |
exit; |
| 11252 |
else |
| 11253 |
Next_Component (Comp); |
| 11254 |
end if; |
| 11255 |
end loop; |
| 11256 |
end; |
| 11257 |
end if; |
| 11258 |
|
| 11259 |
Error_Msg_N |
| 11260 |
("\use pragma Import for & to " & |
| 11261 |
"suppress initialization (RM B.1(24))?o?", |
| 11262 |
Nam); |
| 11263 |
end if; |
| 11264 |
end Warn_Overlay; |
| 11265 |
|
| 11266 |
end Freeze; |