| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- E X P _ A T T R -- |
| 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 Accessibility; use Accessibility; |
| 27 |
with Atree; use Atree; |
| 28 |
with Checks; use Checks; |
| 29 |
with Debug; use Debug; |
| 30 |
with Einfo; use Einfo; |
| 31 |
with Einfo.Entities; use Einfo.Entities; |
| 32 |
with Einfo.Utils; use Einfo.Utils; |
| 33 |
with Elists; use Elists; |
| 34 |
with Exp_Atag; use Exp_Atag; |
| 35 |
with Exp_Ch3; use Exp_Ch3; |
| 36 |
with Exp_Ch6; use Exp_Ch6; |
| 37 |
with Exp_Ch9; use Exp_Ch9; |
| 38 |
with Exp_Dist; use Exp_Dist; |
| 39 |
with Exp_Imgv; use Exp_Imgv; |
| 40 |
with Exp_Pakd; use Exp_Pakd; |
| 41 |
with Exp_Strm; use Exp_Strm; |
| 42 |
with Exp_Put_Image; |
| 43 |
with Exp_Tss; use Exp_Tss; |
| 44 |
with Exp_Util; use Exp_Util; |
| 45 |
with Expander; use Expander; |
| 46 |
with Freeze; use Freeze; |
| 47 |
with Gnatvsn; use Gnatvsn; |
| 48 |
with Itypes; use Itypes; |
| 49 |
with Lib; use Lib; |
| 50 |
with Namet; use Namet; |
| 51 |
with Nmake; use Nmake; |
| 52 |
with Nlists; use Nlists; |
| 53 |
with Opt; use Opt; |
| 54 |
with Restrict; use Restrict; |
| 55 |
with Rident; use Rident; |
| 56 |
with Rtsfind; use Rtsfind; |
| 57 |
with Sem; use Sem; |
| 58 |
with Sem_Aux; use Sem_Aux; |
| 59 |
with Sem_Ch6; use Sem_Ch6; |
| 60 |
with Sem_Ch7; use Sem_Ch7; |
| 61 |
with Sem_Ch8; use Sem_Ch8; |
| 62 |
with Sem_Eval; use Sem_Eval; |
| 63 |
with Sem_Res; use Sem_Res; |
| 64 |
with Sem_Util; use Sem_Util; |
| 65 |
with Sinfo; use Sinfo; |
| 66 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 67 |
with Sinfo.Utils; use Sinfo.Utils; |
| 68 |
with Snames; use Snames; |
| 69 |
with Stand; use Stand; |
| 70 |
with Stringt; use Stringt; |
| 71 |
with Strub; use Strub; |
| 72 |
with Tbuild; use Tbuild; |
| 73 |
with Ttypes; use Ttypes; |
| 74 |
with Uintp; use Uintp; |
| 75 |
with Uname; use Uname; |
| 76 |
with Urealp; use Urealp; |
| 77 |
with Validsw; use Validsw; |
| 78 |
|
| 79 |
with GNAT.HTable; |
| 80 |
|
| 81 |
package body Exp_Attr is |
| 82 |
|
| 83 |
package Cached_Attribute_Ops is |
| 84 |
|
| 85 |
Map_Size : constant := 63; |
| 86 |
subtype Header_Num is Integer range 0 .. Map_Size - 1; |
| 87 |
|
| 88 |
function Attribute_Op_Hash (Id : Entity_Id) return Header_Num is |
| 89 |
(Header_Num (Id mod Map_Size)); |
| 90 |
|
| 91 |
-- Caches used to avoid building duplicate subprograms for a single |
| 92 |
-- type/attribute pair (where the attribute is either Put_Image or |
| 93 |
-- one of the four streaming attributes). The type used as a key in |
| 94 |
-- in accessing these maps should not be the entity of a subtype. |
| 95 |
|
| 96 |
package Read_Map is new GNAT.HTable.Simple_HTable |
| 97 |
(Header_Num => Header_Num, |
| 98 |
Key => Entity_Id, |
| 99 |
Element => Entity_Id, |
| 100 |
No_Element => Empty, |
| 101 |
Hash => Attribute_Op_Hash, |
| 102 |
Equal => "="); |
| 103 |
|
| 104 |
package Write_Map is new GNAT.HTable.Simple_HTable |
| 105 |
(Header_Num => Header_Num, |
| 106 |
Key => Entity_Id, |
| 107 |
Element => Entity_Id, |
| 108 |
No_Element => Empty, |
| 109 |
Hash => Attribute_Op_Hash, |
| 110 |
Equal => "="); |
| 111 |
|
| 112 |
package Input_Map is new GNAT.HTable.Simple_HTable |
| 113 |
(Header_Num => Header_Num, |
| 114 |
Key => Entity_Id, |
| 115 |
Element => Entity_Id, |
| 116 |
No_Element => Empty, |
| 117 |
Hash => Attribute_Op_Hash, |
| 118 |
Equal => "="); |
| 119 |
|
| 120 |
package Output_Map is new GNAT.HTable.Simple_HTable |
| 121 |
(Header_Num => Header_Num, |
| 122 |
Key => Entity_Id, |
| 123 |
Element => Entity_Id, |
| 124 |
No_Element => Empty, |
| 125 |
Hash => Attribute_Op_Hash, |
| 126 |
Equal => "="); |
| 127 |
|
| 128 |
package Put_Image_Map is new GNAT.HTable.Simple_HTable |
| 129 |
(Header_Num => Header_Num, |
| 130 |
Key => Entity_Id, |
| 131 |
Element => Entity_Id, |
| 132 |
No_Element => Empty, |
| 133 |
Hash => Attribute_Op_Hash, |
| 134 |
Equal => "="); |
| 135 |
|
| 136 |
procedure Validate_Cached_Candidate |
| 137 |
(Subp : in out Entity_Id; |
| 138 |
Attr_Ref : Node_Id); |
| 139 |
-- If Subp is non-empty but it is not callable from the point of |
| 140 |
-- Attr_Ref (perhaps because it is not visible from that point), |
| 141 |
-- then Subp is set to Empty. Otherwise, do nothing. |
| 142 |
|
| 143 |
end Cached_Attribute_Ops; |
| 144 |
|
| 145 |
----------------------- |
| 146 |
-- Local Subprograms -- |
| 147 |
----------------------- |
| 148 |
|
| 149 |
function Build_Array_VS_Func |
| 150 |
(Attr : Node_Id; |
| 151 |
Formal_Typ : Entity_Id; |
| 152 |
Array_Typ : Entity_Id) return Entity_Id; |
| 153 |
-- Validate the components of an array type by means of a function. Return |
| 154 |
-- the entity of the validation function. The parameters are as follows: |
| 155 |
-- |
| 156 |
-- * Attr - the 'Valid_Scalars attribute for which the function is |
| 157 |
-- generated. |
| 158 |
-- |
| 159 |
-- * Formal_Typ - the type of the generated function's only formal |
| 160 |
-- parameter. |
| 161 |
-- |
| 162 |
-- * Array_Typ - the array type whose components are to be validated |
| 163 |
|
| 164 |
function Build_Disp_Get_Task_Id_Call (Actual : Node_Id) return Node_Id; |
| 165 |
-- Build a call to Disp_Get_Task_Id, passing Actual as actual parameter |
| 166 |
|
| 167 |
function Build_Record_VS_Func |
| 168 |
(Attr : Node_Id; |
| 169 |
Formal_Typ : Entity_Id; |
| 170 |
Rec_Typ : Entity_Id) return Entity_Id; |
| 171 |
-- Validate the components, discriminants, and variants of a record type by |
| 172 |
-- means of a function. Return the entity of the validation function. The |
| 173 |
-- parameters are as follows: |
| 174 |
-- |
| 175 |
-- * Attr - the 'Valid_Scalars attribute for which the function is |
| 176 |
-- generated. |
| 177 |
-- |
| 178 |
-- * Formal_Typ - the type of the generated function's only formal |
| 179 |
-- parameter. |
| 180 |
-- |
| 181 |
-- * Rec_Typ - the record type whose internals are to be validated |
| 182 |
|
| 183 |
function Default_Streaming_Unavailable (Typ : Entity_Id) return Boolean; |
| 184 |
-- In most cases, references to unavailable streaming attributes |
| 185 |
-- are rejected at compile time. In some obscure cases involving |
| 186 |
-- generics and formal derived types, the problem is dealt with at runtime. |
| 187 |
|
| 188 |
procedure Expand_Access_To_Protected_Op |
| 189 |
(N : Node_Id; |
| 190 |
Pref : Node_Id; |
| 191 |
Typ : Entity_Id); |
| 192 |
-- An attribute reference to a protected subprogram is transformed into |
| 193 |
-- a pair of pointers: one to the object, and one to the operations. |
| 194 |
-- This expansion is performed for 'Access and for 'Unrestricted_Access. |
| 195 |
|
| 196 |
procedure Expand_Fpt_Attribute |
| 197 |
(N : Node_Id; |
| 198 |
Pkg : RE_Id; |
| 199 |
Nam : Name_Id; |
| 200 |
Args : List_Id); |
| 201 |
-- This procedure expands a call to a floating-point attribute function. |
| 202 |
-- N is the attribute reference node, and Args is a list of arguments to |
| 203 |
-- be passed to the function call. Pkg identifies the package containing |
| 204 |
-- the appropriate instantiation of System.Fat_Gen. Float arguments in Args |
| 205 |
-- have already been converted to the floating-point type for which Pkg was |
| 206 |
-- instantiated. The Nam argument is the relevant attribute processing |
| 207 |
-- routine to be called. This is the same as the attribute name. |
| 208 |
|
| 209 |
procedure Expand_Fpt_Attribute_R (N : Node_Id); |
| 210 |
-- This procedure expands a call to a floating-point attribute function |
| 211 |
-- that takes a single floating-point argument. The function to be called |
| 212 |
-- is always the same as the attribute name. |
| 213 |
|
| 214 |
procedure Expand_Fpt_Attribute_RI (N : Node_Id); |
| 215 |
-- This procedure expands a call to a floating-point attribute function |
| 216 |
-- that takes one floating-point argument and one integer argument. The |
| 217 |
-- function to be called is always the same as the attribute name. |
| 218 |
|
| 219 |
procedure Expand_Fpt_Attribute_RR (N : Node_Id); |
| 220 |
-- This procedure expands a call to a floating-point attribute function |
| 221 |
-- that takes two floating-point arguments. The function to be called |
| 222 |
-- is always the same as the attribute name. |
| 223 |
|
| 224 |
procedure Expand_Loop_Entry_Attribute (N : Node_Id); |
| 225 |
-- Handle the expansion of attribute 'Loop_Entry. As a result, the related |
| 226 |
-- loop may be converted into a conditional block. See body for details. |
| 227 |
|
| 228 |
procedure Expand_Min_Max_Attribute (N : Node_Id); |
| 229 |
-- Handle the expansion of attributes 'Max and 'Min |
| 230 |
|
| 231 |
procedure Expand_Pred_Succ_Attribute (N : Node_Id); |
| 232 |
-- Handles expansion of Pred or Succ attributes for case of non-real |
| 233 |
-- operand with overflow checking required. |
| 234 |
|
| 235 |
procedure Expand_Update_Attribute (N : Node_Id); |
| 236 |
-- Handle the expansion of attribute Update |
| 237 |
|
| 238 |
procedure Find_Fat_Info |
| 239 |
(T : Entity_Id; |
| 240 |
Fat_Type : out Entity_Id; |
| 241 |
Fat_Pkg : out RE_Id); |
| 242 |
-- Given a floating-point type T, identifies the package containing the |
| 243 |
-- attributes for this type (returned in Fat_Pkg), and the corresponding |
| 244 |
-- type for which this package was instantiated from Fat_Gen. Error if T |
| 245 |
-- is not a floating-point type. |
| 246 |
|
| 247 |
function Find_Stream_Subprogram |
| 248 |
(Typ : Entity_Id; |
| 249 |
Nam : TSS_Name_Type; |
| 250 |
Attr_Ref : Node_Id) return Entity_Id; |
| 251 |
-- Returns the stream-oriented subprogram attribute for Typ. For tagged |
| 252 |
-- types, the corresponding primitive operation is looked up, else the |
| 253 |
-- appropriate TSS from the type itself, or from its closest ancestor |
| 254 |
-- defining it, is returned. In both cases, inheritance of representation |
| 255 |
-- aspects is thus taken into account. Attr_Ref is used to identify the |
| 256 |
-- point from which the function result will be referenced. |
| 257 |
|
| 258 |
function Full_Base (T : Entity_Id) return Entity_Id; |
| 259 |
-- The stream functions need to examine the underlying representation of |
| 260 |
-- composite types. In some cases T may be non-private but its base type |
| 261 |
-- is, in which case the function returns the corresponding full view. |
| 262 |
|
| 263 |
function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id; |
| 264 |
-- Given a type, find a corresponding stream convert pragma that applies to |
| 265 |
-- the implementation base type of this type (Typ). If found, return the |
| 266 |
-- pragma node, otherwise return Empty if no pragma is found. |
| 267 |
|
| 268 |
function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean; |
| 269 |
-- Utility for array attributes, returns true on packed constrained |
| 270 |
-- arrays, and on access to same. |
| 271 |
|
| 272 |
function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean; |
| 273 |
-- Returns true iff the given node refers to an attribute call that |
| 274 |
-- can be expanded directly by the back end and does not need front end |
| 275 |
-- expansion. Typically used for rounding and truncation attributes that |
| 276 |
-- appear directly inside a conversion to integer. |
| 277 |
|
| 278 |
function Is_User_Defined_Enumeration_Type (Typ : Entity_Id) return Boolean; |
| 279 |
-- Returns True if Typ is a user-defined enumeration type, in the sense |
| 280 |
-- that its literals are declared in the source. |
| 281 |
|
| 282 |
function Interunit_Ref_OK |
| 283 |
(Subp_Unit, Attr_Ref_Unit : Node_Id) return Boolean is |
| 284 |
(In_Same_Extended_Unit (Subp_Unit, Attr_Ref_Unit) |
| 285 |
-- If subp declared in unit body, then we don't want to refer |
| 286 |
-- to it from within unit spec so return False in that case. |
| 287 |
and then not (not Is_Body (Unit (Attr_Ref_Unit)) |
| 288 |
and Is_Body (Unit (Subp_Unit)))); |
| 289 |
-- Returns True if it is ok to refer to a cached subprogram declared in |
| 290 |
-- Subp_Unit from the point of an attribute reference occurring in |
| 291 |
-- Attr_Ref_Unit. Both arguments are usually N_Compilation_Nodes, |
| 292 |
-- although there are cases where Subp_Unit might be a type declared in |
| 293 |
-- package Standard (in which case the In_Same_Extended_Unit call will |
| 294 |
-- return False). |
| 295 |
|
| 296 |
package body Cached_Attribute_Ops is |
| 297 |
|
| 298 |
------------------------------- |
| 299 |
-- Validate_Cached_Candidate -- |
| 300 |
------------------------------- |
| 301 |
|
| 302 |
procedure Validate_Cached_Candidate |
| 303 |
(Subp : in out Entity_Id; |
| 304 |
Attr_Ref : Node_Id) is |
| 305 |
begin |
| 306 |
if No (Subp) then |
| 307 |
return; |
| 308 |
end if; |
| 309 |
|
| 310 |
declare |
| 311 |
Subp_Comp_Unit : constant Node_Id := |
| 312 |
Enclosing_Comp_Unit_Node (Subp); |
| 313 |
Attr_Ref_Comp_Unit : constant Node_Id := |
| 314 |
Enclosing_Comp_Unit_Node (Attr_Ref); |
| 315 |
|
| 316 |
-- The preceding Enclosing_Comp_Unit_Node calls are needed |
| 317 |
-- (as opposed to changing Interunit_Ref_OK so that it could |
| 318 |
-- be passed Subp and Attr_Ref) because the games we play |
| 319 |
-- with source position info for these conjured-up routines can |
| 320 |
-- confuse In_Same_Extended_Unit (which is called from in |
| 321 |
-- Interunit_Ref_OK) in the case where one of these |
| 322 |
-- conjured-up routines contains an attribute reference |
| 323 |
-- denoting another such routine (e.g., if the Put_Image routine |
| 324 |
-- for a composite type contains a Some_Component_Type'Put_Image |
| 325 |
-- attribute reference). Calling Enclosing_Comp_Unit_Node first |
| 326 |
-- avoids the case where In_Same_Extended_Unit gets confused. |
| 327 |
|
| 328 |
begin |
| 329 |
if Interunit_Ref_OK (Subp_Comp_Unit, Attr_Ref_Comp_Unit) |
| 330 |
and then (Is_Library_Level_Entity (Subp) |
| 331 |
or else Enclosing_Dynamic_Scope (Subp) = |
| 332 |
Enclosing_Lib_Unit_Entity (Subp)) |
| 333 |
then |
| 334 |
return; |
| 335 |
end if; |
| 336 |
end; |
| 337 |
|
| 338 |
-- We have previously tried being more ambitious here in hopes of |
| 339 |
-- referencing subprograms declared in other units (as opposed |
| 340 |
-- to generating a new copy for the current unit) if they are |
| 341 |
-- visible from the point of Attr_Ref. Unfortunately, |
| 342 |
-- we ran into problems with generating inconsistent linknames |
| 343 |
-- (e.g., a procedure declared with a name ending in "_304PI" being |
| 344 |
-- unsuccessfully referenced from another unit via a name ending in |
| 345 |
-- "_305PI"). So, after a fair amount of unsuccessful debugging, |
| 346 |
-- it was decided to abandon the effort. |
| 347 |
|
| 348 |
Subp := Empty; |
| 349 |
end Validate_Cached_Candidate; |
| 350 |
end Cached_Attribute_Ops; |
| 351 |
|
| 352 |
------------------------- |
| 353 |
-- Build_Array_VS_Func -- |
| 354 |
------------------------- |
| 355 |
|
| 356 |
function Build_Array_VS_Func |
| 357 |
(Attr : Node_Id; |
| 358 |
Formal_Typ : Entity_Id; |
| 359 |
Array_Typ : Entity_Id) return Entity_Id |
| 360 |
is |
| 361 |
Loc : constant Source_Ptr := Sloc (Attr); |
| 362 |
Comp_Typ : constant Entity_Id := |
| 363 |
Validated_View (Component_Type (Array_Typ)); |
| 364 |
|
| 365 |
function Validate_Component |
| 366 |
(Obj_Id : Entity_Id; |
| 367 |
Indexes : List_Id) return Node_Id; |
| 368 |
-- Process a single component denoted by indexes Indexes. Obj_Id denotes |
| 369 |
-- the entity of the validation parameter. Return the check associated |
| 370 |
-- with the component. |
| 371 |
|
| 372 |
function Validate_Dimension |
| 373 |
(Obj_Id : Entity_Id; |
| 374 |
Dim : Int; |
| 375 |
Indexes : List_Id) return Node_Id; |
| 376 |
-- Process dimension Dim of the array type. Obj_Id denotes the entity |
| 377 |
-- of the validation parameter. Indexes is a list where each dimension |
| 378 |
-- deposits its loop variable, which will later identify a component. |
| 379 |
-- Return the loop associated with the current dimension. |
| 380 |
|
| 381 |
------------------------ |
| 382 |
-- Validate_Component -- |
| 383 |
------------------------ |
| 384 |
|
| 385 |
function Validate_Component |
| 386 |
(Obj_Id : Entity_Id; |
| 387 |
Indexes : List_Id) return Node_Id |
| 388 |
is |
| 389 |
Attr_Nam : Name_Id; |
| 390 |
|
| 391 |
begin |
| 392 |
if Is_Scalar_Type (Comp_Typ) then |
| 393 |
Attr_Nam := Name_Valid; |
| 394 |
else |
| 395 |
Attr_Nam := Name_Valid_Scalars; |
| 396 |
end if; |
| 397 |
|
| 398 |
-- Generate: |
| 399 |
-- if not Array_Typ (Obj_Id) (Indexes)'Valid[_Scalars] then |
| 400 |
-- return False; |
| 401 |
-- end if; |
| 402 |
|
| 403 |
return |
| 404 |
Make_If_Statement (Loc, |
| 405 |
Condition => |
| 406 |
Make_Op_Not (Loc, |
| 407 |
Right_Opnd => |
| 408 |
Make_Attribute_Reference (Loc, |
| 409 |
Prefix => |
| 410 |
Make_Indexed_Component (Loc, |
| 411 |
Prefix => |
| 412 |
Unchecked_Convert_To (Array_Typ, |
| 413 |
New_Occurrence_Of (Obj_Id, Loc)), |
| 414 |
Expressions => Indexes), |
| 415 |
Attribute_Name => Attr_Nam)), |
| 416 |
|
| 417 |
Then_Statements => New_List ( |
| 418 |
Make_Simple_Return_Statement (Loc, |
| 419 |
Expression => New_Occurrence_Of (Standard_False, Loc)))); |
| 420 |
end Validate_Component; |
| 421 |
|
| 422 |
------------------------ |
| 423 |
-- Validate_Dimension -- |
| 424 |
------------------------ |
| 425 |
|
| 426 |
function Validate_Dimension |
| 427 |
(Obj_Id : Entity_Id; |
| 428 |
Dim : Int; |
| 429 |
Indexes : List_Id) return Node_Id |
| 430 |
is |
| 431 |
Index : Entity_Id; |
| 432 |
|
| 433 |
begin |
| 434 |
-- Validate the component once all dimensions have produced their |
| 435 |
-- individual loops. |
| 436 |
|
| 437 |
if Dim > Number_Dimensions (Array_Typ) then |
| 438 |
return Validate_Component (Obj_Id, Indexes); |
| 439 |
|
| 440 |
-- Process the current dimension |
| 441 |
|
| 442 |
else |
| 443 |
Index := |
| 444 |
Make_Defining_Identifier (Loc, New_External_Name ('J', Dim)); |
| 445 |
|
| 446 |
Append_To (Indexes, New_Occurrence_Of (Index, Loc)); |
| 447 |
|
| 448 |
-- Generate: |
| 449 |
-- for J1 in Array_Typ (Obj_Id)'Range (1) loop |
| 450 |
-- for JN in Array_Typ (Obj_Id)'Range (N) loop |
| 451 |
-- if not Array_Typ (Obj_Id) (Indexes)'Valid[_Scalars] |
| 452 |
-- then |
| 453 |
-- return False; |
| 454 |
-- end if; |
| 455 |
-- end loop; |
| 456 |
-- end loop; |
| 457 |
|
| 458 |
return |
| 459 |
Make_Implicit_Loop_Statement (Attr, |
| 460 |
Identifier => Empty, |
| 461 |
Iteration_Scheme => |
| 462 |
Make_Iteration_Scheme (Loc, |
| 463 |
Loop_Parameter_Specification => |
| 464 |
Make_Loop_Parameter_Specification (Loc, |
| 465 |
Defining_Identifier => Index, |
| 466 |
Discrete_Subtype_Definition => |
| 467 |
Make_Attribute_Reference (Loc, |
| 468 |
Prefix => |
| 469 |
Unchecked_Convert_To (Array_Typ, |
| 470 |
New_Occurrence_Of (Obj_Id, Loc)), |
| 471 |
Attribute_Name => Name_Range, |
| 472 |
Expressions => New_List ( |
| 473 |
Make_Integer_Literal (Loc, Dim))))), |
| 474 |
Statements => New_List ( |
| 475 |
Validate_Dimension (Obj_Id, Dim + 1, Indexes))); |
| 476 |
end if; |
| 477 |
end Validate_Dimension; |
| 478 |
|
| 479 |
-- Local variables |
| 480 |
|
| 481 |
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V'); |
| 482 |
Indexes : constant List_Id := New_List; |
| 483 |
Obj_Id : constant Entity_Id := Make_Temporary (Loc, 'A'); |
| 484 |
Stmts : List_Id; |
| 485 |
|
| 486 |
-- Start of processing for Build_Array_VS_Func |
| 487 |
|
| 488 |
begin |
| 489 |
Stmts := New_List (Validate_Dimension (Obj_Id, 1, Indexes)); |
| 490 |
|
| 491 |
-- Generate: |
| 492 |
-- return True; |
| 493 |
|
| 494 |
Append_To (Stmts, |
| 495 |
Make_Simple_Return_Statement (Loc, |
| 496 |
Expression => New_Occurrence_Of (Standard_True, Loc))); |
| 497 |
|
| 498 |
-- Generate: |
| 499 |
-- function Func_Id (Obj_Id : Formal_Typ) return Boolean is |
| 500 |
-- begin |
| 501 |
-- Stmts |
| 502 |
-- end Func_Id; |
| 503 |
|
| 504 |
Mutate_Ekind (Func_Id, E_Function); |
| 505 |
Set_Is_Internal (Func_Id); |
| 506 |
Set_Is_Pure (Func_Id); |
| 507 |
|
| 508 |
if not Debug_Generated_Code then |
| 509 |
Set_Debug_Info_Off (Func_Id); |
| 510 |
end if; |
| 511 |
|
| 512 |
Insert_Action (Attr, |
| 513 |
Make_Subprogram_Body (Loc, |
| 514 |
Specification => |
| 515 |
Make_Function_Specification (Loc, |
| 516 |
Defining_Unit_Name => Func_Id, |
| 517 |
Parameter_Specifications => New_List ( |
| 518 |
Make_Parameter_Specification (Loc, |
| 519 |
Defining_Identifier => Obj_Id, |
| 520 |
Parameter_Type => New_Occurrence_Of (Formal_Typ, Loc))), |
| 521 |
Result_Definition => |
| 522 |
New_Occurrence_Of (Standard_Boolean, Loc)), |
| 523 |
Declarations => New_List, |
| 524 |
Handled_Statement_Sequence => |
| 525 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 526 |
Statements => Stmts))); |
| 527 |
|
| 528 |
return Func_Id; |
| 529 |
end Build_Array_VS_Func; |
| 530 |
|
| 531 |
--------------------------------- |
| 532 |
-- Build_Disp_Get_Task_Id_Call -- |
| 533 |
--------------------------------- |
| 534 |
|
| 535 |
function Build_Disp_Get_Task_Id_Call (Actual : Node_Id) return Node_Id is |
| 536 |
Loc : constant Source_Ptr := Sloc (Actual); |
| 537 |
Typ : constant Entity_Id := Etype (Actual); |
| 538 |
Subp : constant Entity_Id := Find_Prim_Op (Typ, Name_uDisp_Get_Task_Id); |
| 539 |
|
| 540 |
begin |
| 541 |
-- Generate: |
| 542 |
-- _Disp_Get_Task_Id (Actual) |
| 543 |
|
| 544 |
return |
| 545 |
Make_Function_Call (Loc, |
| 546 |
Name => New_Occurrence_Of (Subp, Loc), |
| 547 |
Parameter_Associations => New_List (Actual)); |
| 548 |
end Build_Disp_Get_Task_Id_Call; |
| 549 |
|
| 550 |
-------------------------- |
| 551 |
-- Build_Record_VS_Func -- |
| 552 |
-------------------------- |
| 553 |
|
| 554 |
function Build_Record_VS_Func |
| 555 |
(Attr : Node_Id; |
| 556 |
Formal_Typ : Entity_Id; |
| 557 |
Rec_Typ : Entity_Id) return Entity_Id |
| 558 |
is |
| 559 |
-- NOTE: The logic of Build_Record_VS_Func is intentionally passive. |
| 560 |
-- It generates code only when there are components, discriminants, |
| 561 |
-- or variant parts to validate. |
| 562 |
|
| 563 |
-- NOTE: The routines within Build_Record_VS_Func are intentionally |
| 564 |
-- unnested to avoid deep indentation of code. |
| 565 |
|
| 566 |
Loc : constant Source_Ptr := Sloc (Attr); |
| 567 |
|
| 568 |
procedure Validate_Component_List |
| 569 |
(Obj_Id : Entity_Id; |
| 570 |
Comp_List : Node_Id; |
| 571 |
Stmts : in out List_Id); |
| 572 |
-- Process all components and variant parts of component list Comp_List. |
| 573 |
-- Obj_Id denotes the entity of the validation parameter. All new code |
| 574 |
-- is added to list Stmts. |
| 575 |
|
| 576 |
procedure Validate_Field |
| 577 |
(Obj_Id : Entity_Id; |
| 578 |
Field : Node_Id; |
| 579 |
Cond : in out Node_Id); |
| 580 |
-- Process component declaration or discriminant specification Field. |
| 581 |
-- Obj_Id denotes the entity of the validation parameter. Cond denotes |
| 582 |
-- an "or else" conditional expression which contains the new code (if |
| 583 |
-- any). |
| 584 |
|
| 585 |
procedure Validate_Fields |
| 586 |
(Obj_Id : Entity_Id; |
| 587 |
Fields : List_Id; |
| 588 |
Stmts : in out List_Id); |
| 589 |
-- Process component declarations or discriminant specifications in list |
| 590 |
-- Fields. Obj_Id denotes the entity of the validation parameter. All |
| 591 |
-- new code is added to list Stmts. |
| 592 |
|
| 593 |
procedure Validate_Variant |
| 594 |
(Obj_Id : Entity_Id; |
| 595 |
Var : Node_Id; |
| 596 |
Alts : in out List_Id); |
| 597 |
-- Process variant Var. Obj_Id denotes the entity of the validation |
| 598 |
-- parameter. Alts denotes a list of case statement alternatives which |
| 599 |
-- contains the new code (if any). |
| 600 |
|
| 601 |
procedure Validate_Variant_Part |
| 602 |
(Obj_Id : Entity_Id; |
| 603 |
Var_Part : Node_Id; |
| 604 |
Stmts : in out List_Id); |
| 605 |
-- Process variant part Var_Part. Obj_Id denotes the entity of the |
| 606 |
-- validation parameter. All new code is added to list Stmts. |
| 607 |
|
| 608 |
----------------------------- |
| 609 |
-- Validate_Component_List -- |
| 610 |
----------------------------- |
| 611 |
|
| 612 |
procedure Validate_Component_List |
| 613 |
(Obj_Id : Entity_Id; |
| 614 |
Comp_List : Node_Id; |
| 615 |
Stmts : in out List_Id) |
| 616 |
is |
| 617 |
Var_Part : constant Node_Id := Variant_Part (Comp_List); |
| 618 |
|
| 619 |
begin |
| 620 |
-- Validate all components |
| 621 |
|
| 622 |
Validate_Fields |
| 623 |
(Obj_Id => Obj_Id, |
| 624 |
Fields => Component_Items (Comp_List), |
| 625 |
Stmts => Stmts); |
| 626 |
|
| 627 |
-- Validate the variant part |
| 628 |
|
| 629 |
if Present (Var_Part) then |
| 630 |
Validate_Variant_Part |
| 631 |
(Obj_Id => Obj_Id, |
| 632 |
Var_Part => Var_Part, |
| 633 |
Stmts => Stmts); |
| 634 |
end if; |
| 635 |
end Validate_Component_List; |
| 636 |
|
| 637 |
-------------------- |
| 638 |
-- Validate_Field -- |
| 639 |
-------------------- |
| 640 |
|
| 641 |
procedure Validate_Field |
| 642 |
(Obj_Id : Entity_Id; |
| 643 |
Field : Node_Id; |
| 644 |
Cond : in out Node_Id) |
| 645 |
is |
| 646 |
Field_Id : constant Entity_Id := Defining_Entity (Field); |
| 647 |
Field_Nam : constant Name_Id := Chars (Field_Id); |
| 648 |
Field_Typ : constant Entity_Id := Validated_View (Etype (Field_Id)); |
| 649 |
Attr_Nam : Name_Id; |
| 650 |
|
| 651 |
begin |
| 652 |
-- Do not process internally-generated fields. Note that checking for |
| 653 |
-- Comes_From_Source is not correct because this will eliminate the |
| 654 |
-- components within the corresponding record of a protected type. |
| 655 |
|
| 656 |
if Field_Nam in Name_uObject | Name_uParent | Name_uTag then |
| 657 |
null; |
| 658 |
|
| 659 |
-- Do not process fields without any scalar components |
| 660 |
|
| 661 |
elsif not Scalar_Part_Present (Field_Typ) then |
| 662 |
null; |
| 663 |
|
| 664 |
-- Otherwise the field needs to be validated. Use Make_Identifier |
| 665 |
-- rather than New_Occurrence_Of to identify the field because the |
| 666 |
-- wrong entity may be picked up when private types are involved. |
| 667 |
|
| 668 |
-- Generate: |
| 669 |
-- [or else] not Rec_Typ (Obj_Id).Item_Nam'Valid[_Scalars] |
| 670 |
|
| 671 |
else |
| 672 |
if Is_Scalar_Type (Field_Typ) then |
| 673 |
Attr_Nam := Name_Valid; |
| 674 |
else |
| 675 |
Attr_Nam := Name_Valid_Scalars; |
| 676 |
end if; |
| 677 |
|
| 678 |
Evolve_Or_Else (Cond, |
| 679 |
Make_Op_Not (Loc, |
| 680 |
Right_Opnd => |
| 681 |
Make_Attribute_Reference (Loc, |
| 682 |
Prefix => |
| 683 |
Make_Selected_Component (Loc, |
| 684 |
Prefix => |
| 685 |
Unchecked_Convert_To (Rec_Typ, |
| 686 |
New_Occurrence_Of (Obj_Id, Loc)), |
| 687 |
Selector_Name => Make_Identifier (Loc, Field_Nam)), |
| 688 |
Attribute_Name => Attr_Nam))); |
| 689 |
end if; |
| 690 |
end Validate_Field; |
| 691 |
|
| 692 |
--------------------- |
| 693 |
-- Validate_Fields -- |
| 694 |
--------------------- |
| 695 |
|
| 696 |
procedure Validate_Fields |
| 697 |
(Obj_Id : Entity_Id; |
| 698 |
Fields : List_Id; |
| 699 |
Stmts : in out List_Id) |
| 700 |
is |
| 701 |
Cond : Node_Id; |
| 702 |
Field : Node_Id; |
| 703 |
|
| 704 |
begin |
| 705 |
-- Assume that none of the fields are eligible for verification |
| 706 |
|
| 707 |
Cond := Empty; |
| 708 |
|
| 709 |
-- Validate all fields |
| 710 |
|
| 711 |
Field := First_Non_Pragma (Fields); |
| 712 |
while Present (Field) loop |
| 713 |
Validate_Field |
| 714 |
(Obj_Id => Obj_Id, |
| 715 |
Field => Field, |
| 716 |
Cond => Cond); |
| 717 |
|
| 718 |
Next_Non_Pragma (Field); |
| 719 |
end loop; |
| 720 |
|
| 721 |
-- Generate: |
| 722 |
-- if not Rec_Typ (Obj_Id).Item_Nam_1'Valid[_Scalars] |
| 723 |
-- or else not Rec_Typ (Obj_Id).Item_Nam_N'Valid[_Scalars] |
| 724 |
-- then |
| 725 |
-- return False; |
| 726 |
-- end if; |
| 727 |
|
| 728 |
if Present (Cond) then |
| 729 |
Append_New_To (Stmts, |
| 730 |
Make_Implicit_If_Statement (Attr, |
| 731 |
Condition => Cond, |
| 732 |
Then_Statements => New_List ( |
| 733 |
Make_Simple_Return_Statement (Loc, |
| 734 |
Expression => New_Occurrence_Of (Standard_False, Loc))))); |
| 735 |
end if; |
| 736 |
end Validate_Fields; |
| 737 |
|
| 738 |
---------------------- |
| 739 |
-- Validate_Variant -- |
| 740 |
---------------------- |
| 741 |
|
| 742 |
procedure Validate_Variant |
| 743 |
(Obj_Id : Entity_Id; |
| 744 |
Var : Node_Id; |
| 745 |
Alts : in out List_Id) |
| 746 |
is |
| 747 |
Stmts : List_Id; |
| 748 |
|
| 749 |
begin |
| 750 |
-- Assume that none of the components and variants are eligible for |
| 751 |
-- verification. |
| 752 |
|
| 753 |
Stmts := No_List; |
| 754 |
|
| 755 |
-- Validate components |
| 756 |
|
| 757 |
Validate_Component_List |
| 758 |
(Obj_Id => Obj_Id, |
| 759 |
Comp_List => Component_List (Var), |
| 760 |
Stmts => Stmts); |
| 761 |
|
| 762 |
-- Generate a null statement in case none of the components were |
| 763 |
-- verified because this will otherwise eliminate an alternative |
| 764 |
-- from the variant case statement and render the generated code |
| 765 |
-- illegal. |
| 766 |
|
| 767 |
if No (Stmts) then |
| 768 |
Append_New_To (Stmts, Make_Null_Statement (Loc)); |
| 769 |
end if; |
| 770 |
|
| 771 |
-- Generate: |
| 772 |
-- when Discrete_Choices => |
| 773 |
-- Stmts |
| 774 |
|
| 775 |
Append_New_To (Alts, |
| 776 |
Make_Case_Statement_Alternative (Loc, |
| 777 |
Discrete_Choices => |
| 778 |
New_Copy_List_Tree (Discrete_Choices (Var)), |
| 779 |
Statements => Stmts)); |
| 780 |
end Validate_Variant; |
| 781 |
|
| 782 |
--------------------------- |
| 783 |
-- Validate_Variant_Part -- |
| 784 |
--------------------------- |
| 785 |
|
| 786 |
procedure Validate_Variant_Part |
| 787 |
(Obj_Id : Entity_Id; |
| 788 |
Var_Part : Node_Id; |
| 789 |
Stmts : in out List_Id) |
| 790 |
is |
| 791 |
Vars : constant List_Id := Variants (Var_Part); |
| 792 |
Alts : List_Id; |
| 793 |
Var : Node_Id; |
| 794 |
|
| 795 |
begin |
| 796 |
-- Assume that none of the variants are eligible for verification |
| 797 |
|
| 798 |
Alts := No_List; |
| 799 |
|
| 800 |
-- Validate variants |
| 801 |
|
| 802 |
Var := First_Non_Pragma (Vars); |
| 803 |
while Present (Var) loop |
| 804 |
Validate_Variant |
| 805 |
(Obj_Id => Obj_Id, |
| 806 |
Var => Var, |
| 807 |
Alts => Alts); |
| 808 |
|
| 809 |
Next_Non_Pragma (Var); |
| 810 |
end loop; |
| 811 |
|
| 812 |
-- Even though individual variants may lack eligible components, the |
| 813 |
-- alternatives must still be generated. |
| 814 |
|
| 815 |
pragma Assert (Present (Alts)); |
| 816 |
|
| 817 |
-- Generate: |
| 818 |
-- case Rec_Typ (Obj_Id).Discriminant is |
| 819 |
-- when Discrete_Choices_1 => |
| 820 |
-- Stmts_1 |
| 821 |
-- when Discrete_Choices_N => |
| 822 |
-- Stmts_N |
| 823 |
-- end case; |
| 824 |
|
| 825 |
Append_New_To (Stmts, |
| 826 |
Make_Case_Statement (Loc, |
| 827 |
Expression => |
| 828 |
Make_Selected_Component (Loc, |
| 829 |
Prefix => |
| 830 |
Unchecked_Convert_To (Rec_Typ, |
| 831 |
New_Occurrence_Of (Obj_Id, Loc)), |
| 832 |
Selector_Name => New_Copy_Tree (Name (Var_Part))), |
| 833 |
Alternatives => Alts)); |
| 834 |
end Validate_Variant_Part; |
| 835 |
|
| 836 |
-- Local variables |
| 837 |
|
| 838 |
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V'); |
| 839 |
Obj_Id : constant Entity_Id := Make_Temporary (Loc, 'R'); |
| 840 |
Comps : Node_Id; |
| 841 |
Stmts : List_Id; |
| 842 |
Typ : Entity_Id; |
| 843 |
Typ_Decl : Node_Id; |
| 844 |
Typ_Def : Node_Id; |
| 845 |
Typ_Ext : Node_Id; |
| 846 |
|
| 847 |
-- Start of processing for Build_Record_VS_Func |
| 848 |
|
| 849 |
begin |
| 850 |
Typ := Validated_View (Rec_Typ); |
| 851 |
|
| 852 |
-- Use the root type when dealing with a class-wide type |
| 853 |
|
| 854 |
if Is_Class_Wide_Type (Typ) then |
| 855 |
Typ := Validated_View (Root_Type (Typ)); |
| 856 |
end if; |
| 857 |
|
| 858 |
Typ_Decl := Declaration_Node (Typ); |
| 859 |
Typ_Def := Type_Definition (Typ_Decl); |
| 860 |
|
| 861 |
-- The components of a derived type are located in the extension part |
| 862 |
|
| 863 |
if Nkind (Typ_Def) = N_Derived_Type_Definition then |
| 864 |
Typ_Ext := Record_Extension_Part (Typ_Def); |
| 865 |
|
| 866 |
if Present (Typ_Ext) then |
| 867 |
Comps := Component_List (Typ_Ext); |
| 868 |
else |
| 869 |
Comps := Empty; |
| 870 |
end if; |
| 871 |
|
| 872 |
-- Otherwise the components are available in the definition |
| 873 |
|
| 874 |
else |
| 875 |
Comps := Component_List (Typ_Def); |
| 876 |
end if; |
| 877 |
|
| 878 |
-- The code generated by this routine is as follows: |
| 879 |
-- |
| 880 |
-- function Func_Id (Obj_Id : Formal_Typ) return Boolean is |
| 881 |
-- begin |
| 882 |
-- if not Rec_Typ (Obj_Id).Discriminant_1'Valid[_Scalars] |
| 883 |
-- or else not Rec_Typ (Obj_Id).Discriminant_N'Valid[_Scalars] |
| 884 |
-- then |
| 885 |
-- return False; |
| 886 |
-- end if; |
| 887 |
-- |
| 888 |
-- if not Rec_Typ (Obj_Id).Component_1'Valid[_Scalars] |
| 889 |
-- or else not Rec_Typ (Obj_Id).Component_N'Valid[_Scalars] |
| 890 |
-- then |
| 891 |
-- return False; |
| 892 |
-- end if; |
| 893 |
-- |
| 894 |
-- case Discriminant_1 is |
| 895 |
-- when Choice_1 => |
| 896 |
-- if not Rec_Typ (Obj_Id).Component_1'Valid[_Scalars] |
| 897 |
-- or else not Rec_Typ (Obj_Id).Component_N'Valid[_Scalars] |
| 898 |
-- then |
| 899 |
-- return False; |
| 900 |
-- end if; |
| 901 |
-- |
| 902 |
-- case Discriminant_N is |
| 903 |
-- ... |
| 904 |
-- when Choice_N => |
| 905 |
-- ... |
| 906 |
-- end case; |
| 907 |
-- |
| 908 |
-- return True; |
| 909 |
-- end Func_Id; |
| 910 |
|
| 911 |
-- Assume that the record type lacks eligible components, discriminants, |
| 912 |
-- and variant parts. |
| 913 |
|
| 914 |
Stmts := No_List; |
| 915 |
|
| 916 |
-- Validate the discriminants |
| 917 |
|
| 918 |
if not Is_Unchecked_Union (Rec_Typ) then |
| 919 |
Validate_Fields |
| 920 |
(Obj_Id => Obj_Id, |
| 921 |
Fields => Discriminant_Specifications (Typ_Decl), |
| 922 |
Stmts => Stmts); |
| 923 |
end if; |
| 924 |
|
| 925 |
-- Validate the components and variant parts |
| 926 |
|
| 927 |
Validate_Component_List |
| 928 |
(Obj_Id => Obj_Id, |
| 929 |
Comp_List => Comps, |
| 930 |
Stmts => Stmts); |
| 931 |
|
| 932 |
-- Generate: |
| 933 |
-- return True; |
| 934 |
|
| 935 |
Append_New_To (Stmts, |
| 936 |
Make_Simple_Return_Statement (Loc, |
| 937 |
Expression => New_Occurrence_Of (Standard_True, Loc))); |
| 938 |
|
| 939 |
-- Generate: |
| 940 |
-- function Func_Id (Obj_Id : Formal_Typ) return Boolean is |
| 941 |
-- begin |
| 942 |
-- Stmts |
| 943 |
-- end Func_Id; |
| 944 |
|
| 945 |
Mutate_Ekind (Func_Id, E_Function); |
| 946 |
Set_Is_Internal (Func_Id); |
| 947 |
Set_Is_Pure (Func_Id); |
| 948 |
|
| 949 |
if not Debug_Generated_Code then |
| 950 |
Set_Debug_Info_Off (Func_Id); |
| 951 |
end if; |
| 952 |
|
| 953 |
Insert_Action (Attr, |
| 954 |
Make_Subprogram_Body (Loc, |
| 955 |
Specification => |
| 956 |
Make_Function_Specification (Loc, |
| 957 |
Defining_Unit_Name => Func_Id, |
| 958 |
Parameter_Specifications => New_List ( |
| 959 |
Make_Parameter_Specification (Loc, |
| 960 |
Defining_Identifier => Obj_Id, |
| 961 |
Parameter_Type => New_Occurrence_Of (Formal_Typ, Loc))), |
| 962 |
Result_Definition => |
| 963 |
New_Occurrence_Of (Standard_Boolean, Loc)), |
| 964 |
Declarations => New_List, |
| 965 |
Handled_Statement_Sequence => |
| 966 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 967 |
Statements => Stmts)), |
| 968 |
Suppress => Discriminant_Check); |
| 969 |
|
| 970 |
return Func_Id; |
| 971 |
end Build_Record_VS_Func; |
| 972 |
|
| 973 |
----------------------------------- |
| 974 |
-- Default_Streaming_Unavailable -- |
| 975 |
----------------------------------- |
| 976 |
|
| 977 |
function Default_Streaming_Unavailable (Typ : Entity_Id) return Boolean is |
| 978 |
Btyp : constant Entity_Id := Implementation_Base_Type (Typ); |
| 979 |
begin |
| 980 |
if Is_Immutably_Limited_Type (Btyp) |
| 981 |
and then not Is_Tagged_Type (Btyp) |
| 982 |
and then not (Ekind (Btyp) = E_Record_Type |
| 983 |
and then Present (Corresponding_Concurrent_Type (Btyp))) |
| 984 |
then |
| 985 |
pragma Assert (In_Instance_Body); |
| 986 |
return True; |
| 987 |
end if; |
| 988 |
return False; |
| 989 |
end Default_Streaming_Unavailable; |
| 990 |
|
| 991 |
----------------------------------- |
| 992 |
-- Expand_Access_To_Protected_Op -- |
| 993 |
----------------------------------- |
| 994 |
|
| 995 |
procedure Expand_Access_To_Protected_Op |
| 996 |
(N : Node_Id; |
| 997 |
Pref : Node_Id; |
| 998 |
Typ : Entity_Id) |
| 999 |
is |
| 1000 |
-- The value of the attribute_reference is a record containing two |
| 1001 |
-- fields: an access to the protected object, and an access to the |
| 1002 |
-- subprogram itself. The prefix is an identifier or a selected |
| 1003 |
-- component. |
| 1004 |
|
| 1005 |
function Has_By_Protected_Procedure_Prefixed_View return Boolean; |
| 1006 |
-- Determine whether Pref denotes the prefixed class-wide interface |
| 1007 |
-- view of a procedure with synchronization kind By_Protected_Procedure. |
| 1008 |
|
| 1009 |
---------------------------------------------- |
| 1010 |
-- Has_By_Protected_Procedure_Prefixed_View -- |
| 1011 |
---------------------------------------------- |
| 1012 |
|
| 1013 |
function Has_By_Protected_Procedure_Prefixed_View return Boolean is |
| 1014 |
begin |
| 1015 |
return Nkind (Pref) = N_Selected_Component |
| 1016 |
and then Nkind (Prefix (Pref)) in N_Has_Entity |
| 1017 |
and then Present (Entity (Prefix (Pref))) |
| 1018 |
and then Is_Class_Wide_Type (Etype (Entity (Prefix (Pref)))) |
| 1019 |
and then (Is_Synchronized_Interface (Etype (Entity (Prefix (Pref)))) |
| 1020 |
or else |
| 1021 |
Is_Protected_Interface (Etype (Entity (Prefix (Pref))))) |
| 1022 |
and then Is_By_Protected_Procedure (Entity (Selector_Name (Pref))); |
| 1023 |
end Has_By_Protected_Procedure_Prefixed_View; |
| 1024 |
|
| 1025 |
-- Local variables |
| 1026 |
|
| 1027 |
Loc : constant Source_Ptr := Sloc (N); |
| 1028 |
Agg : Node_Id; |
| 1029 |
Btyp : constant Entity_Id := Base_Type (Typ); |
| 1030 |
Sub : Entity_Id := Empty; |
| 1031 |
Sub_Ref : Node_Id; |
| 1032 |
E_T : constant Entity_Id := Equivalent_Type (Btyp); |
| 1033 |
Acc : constant Entity_Id := |
| 1034 |
Etype (Next_Component (First_Component (E_T))); |
| 1035 |
Obj_Ref : Node_Id; |
| 1036 |
Curr : Entity_Id; |
| 1037 |
|
| 1038 |
-- Start of processing for Expand_Access_To_Protected_Op |
| 1039 |
|
| 1040 |
begin |
| 1041 |
-- Within the body of the protected type, the prefix designates a local |
| 1042 |
-- operation, and the object is the first parameter of the corresponding |
| 1043 |
-- protected body of the current enclosing operation. |
| 1044 |
|
| 1045 |
if Is_Entity_Name (Pref) then |
| 1046 |
-- All indirect calls are external calls, so must do locking and |
| 1047 |
-- barrier reevaluation, even if the 'Access occurs within the |
| 1048 |
-- protected body. Hence the call to External_Subprogram, as opposed |
| 1049 |
-- to Protected_Body_Subprogram, below. See RM-9.5(5). This means |
| 1050 |
-- that indirect calls from within the same protected body will |
| 1051 |
-- deadlock, as allowed by RM-9.5.1(8,15,17). |
| 1052 |
|
| 1053 |
Sub := New_Occurrence_Of (External_Subprogram (Entity (Pref)), Loc); |
| 1054 |
|
| 1055 |
-- Don't traverse the scopes when the attribute occurs within an init |
| 1056 |
-- proc, because we directly use the _init formal of the init proc in |
| 1057 |
-- that case. |
| 1058 |
|
| 1059 |
Curr := Current_Scope; |
| 1060 |
if not Is_Init_Proc (Curr) then |
| 1061 |
pragma Assert (In_Open_Scopes (Scope (Entity (Pref)))); |
| 1062 |
|
| 1063 |
while Scope (Curr) /= Scope (Entity (Pref)) loop |
| 1064 |
Curr := Scope (Curr); |
| 1065 |
end loop; |
| 1066 |
end if; |
| 1067 |
|
| 1068 |
-- In case of protected entries the first formal of its Protected_ |
| 1069 |
-- Body_Subprogram is the address of the object. |
| 1070 |
|
| 1071 |
if Ekind (Curr) = E_Entry then |
| 1072 |
Obj_Ref := |
| 1073 |
New_Occurrence_Of |
| 1074 |
(First_Formal |
| 1075 |
(Protected_Body_Subprogram (Curr)), Loc); |
| 1076 |
|
| 1077 |
-- If the current scope is an init proc, then use the address of the |
| 1078 |
-- _init formal as the object reference. |
| 1079 |
|
| 1080 |
elsif Is_Init_Proc (Curr) then |
| 1081 |
Obj_Ref := |
| 1082 |
Make_Attribute_Reference (Loc, |
| 1083 |
Prefix => New_Occurrence_Of (First_Formal (Curr), Loc), |
| 1084 |
Attribute_Name => Name_Address); |
| 1085 |
|
| 1086 |
-- In case of protected subprograms the first formal of its |
| 1087 |
-- Protected_Body_Subprogram is the object and we get its address. |
| 1088 |
|
| 1089 |
else |
| 1090 |
Obj_Ref := |
| 1091 |
Make_Attribute_Reference (Loc, |
| 1092 |
Prefix => |
| 1093 |
New_Occurrence_Of |
| 1094 |
(First_Formal |
| 1095 |
(Protected_Body_Subprogram (Curr)), Loc), |
| 1096 |
Attribute_Name => Name_Address); |
| 1097 |
end if; |
| 1098 |
|
| 1099 |
elsif Has_By_Protected_Procedure_Prefixed_View then |
| 1100 |
Obj_Ref := |
| 1101 |
Make_Attribute_Reference (Loc, |
| 1102 |
Prefix => Relocate_Node (Prefix (Pref)), |
| 1103 |
Attribute_Name => Name_Address); |
| 1104 |
|
| 1105 |
-- Analyze the object address with expansion disabled. Required |
| 1106 |
-- because its expansion would displace the pointer to the object, |
| 1107 |
-- which is not correct at this stage since the object type is a |
| 1108 |
-- class-wide interface type and we are dispatching a call to a |
| 1109 |
-- thunk (which would erroneously displace the pointer again). |
| 1110 |
|
| 1111 |
Expander_Mode_Save_And_Set (False); |
| 1112 |
Analyze (Obj_Ref); |
| 1113 |
Set_Analyzed (Obj_Ref); |
| 1114 |
Expander_Mode_Restore; |
| 1115 |
|
| 1116 |
-- Case where the prefix is not an entity name. Find the |
| 1117 |
-- version of the protected operation to be called from |
| 1118 |
-- outside the protected object. |
| 1119 |
|
| 1120 |
else |
| 1121 |
Sub := |
| 1122 |
New_Occurrence_Of |
| 1123 |
(External_Subprogram |
| 1124 |
(Entity (Selector_Name (Pref))), Loc); |
| 1125 |
|
| 1126 |
Obj_Ref := |
| 1127 |
Make_Attribute_Reference (Loc, |
| 1128 |
Prefix => Relocate_Node (Prefix (Pref)), |
| 1129 |
Attribute_Name => Name_Address); |
| 1130 |
end if; |
| 1131 |
|
| 1132 |
if Has_By_Protected_Procedure_Prefixed_View then |
| 1133 |
declare |
| 1134 |
Ctrl_Tag : Node_Id := Duplicate_Subexpr (Prefix (Pref)); |
| 1135 |
Prim_Addr : Node_Id; |
| 1136 |
Subp : constant Entity_Id := Entity (Selector_Name (Pref)); |
| 1137 |
Typ : constant Entity_Id := |
| 1138 |
Etype (Etype (Entity (Prefix (Pref)))); |
| 1139 |
begin |
| 1140 |
-- The target subprogram is a thunk; retrieve its address from |
| 1141 |
-- its secondary dispatch table slot. |
| 1142 |
|
| 1143 |
Build_Get_Prim_Op_Address (Loc, |
| 1144 |
Typ => Typ, |
| 1145 |
Tag_Node => Ctrl_Tag, |
| 1146 |
Position => DT_Position (Subp), |
| 1147 |
New_Node => Prim_Addr); |
| 1148 |
|
| 1149 |
-- Mark the access to the target subprogram as an access to the |
| 1150 |
-- dispatch table and perform an unchecked type conversion to such |
| 1151 |
-- access type. This is required to allow the backend to properly |
| 1152 |
-- identify and handle the access to the dispatch table slot on |
| 1153 |
-- targets where the dispatch table contains descriptors (instead |
| 1154 |
-- of pointers). |
| 1155 |
|
| 1156 |
Set_Is_Dispatch_Table_Entity (Acc); |
| 1157 |
Sub_Ref := Unchecked_Convert_To (Acc, Prim_Addr); |
| 1158 |
Analyze (Sub_Ref); |
| 1159 |
|
| 1160 |
Agg := |
| 1161 |
Make_Aggregate (Loc, |
| 1162 |
Expressions => New_List (Obj_Ref, Sub_Ref)); |
| 1163 |
end; |
| 1164 |
|
| 1165 |
-- Common case |
| 1166 |
|
| 1167 |
else |
| 1168 |
Sub_Ref := |
| 1169 |
Make_Attribute_Reference (Loc, |
| 1170 |
Prefix => Sub, |
| 1171 |
Attribute_Name => Name_Access); |
| 1172 |
|
| 1173 |
-- We set the type of the access reference to the already generated |
| 1174 |
-- access_to_subprogram type, and declare the reference analyzed, |
| 1175 |
-- to prevent further expansion when the enclosing aggregate is |
| 1176 |
-- analyzed. |
| 1177 |
|
| 1178 |
Set_Etype (Sub_Ref, Acc); |
| 1179 |
Set_Analyzed (Sub_Ref); |
| 1180 |
|
| 1181 |
Agg := |
| 1182 |
Make_Aggregate (Loc, |
| 1183 |
Expressions => New_List (Obj_Ref, Sub_Ref)); |
| 1184 |
|
| 1185 |
-- Sub_Ref has been marked as analyzed, but we still need to make |
| 1186 |
-- sure Sub is correctly frozen. |
| 1187 |
|
| 1188 |
Freeze_Before (N, Entity (Sub)); |
| 1189 |
end if; |
| 1190 |
|
| 1191 |
Rewrite (N, Agg); |
| 1192 |
Analyze_And_Resolve (N, E_T); |
| 1193 |
|
| 1194 |
-- For subsequent analysis, the node must retain its type. The backend |
| 1195 |
-- will replace it with the equivalent type where needed. |
| 1196 |
|
| 1197 |
Set_Etype (N, Typ); |
| 1198 |
end Expand_Access_To_Protected_Op; |
| 1199 |
|
| 1200 |
-------------------------- |
| 1201 |
-- Expand_Fpt_Attribute -- |
| 1202 |
-------------------------- |
| 1203 |
|
| 1204 |
procedure Expand_Fpt_Attribute |
| 1205 |
(N : Node_Id; |
| 1206 |
Pkg : RE_Id; |
| 1207 |
Nam : Name_Id; |
| 1208 |
Args : List_Id) |
| 1209 |
is |
| 1210 |
Loc : constant Source_Ptr := Sloc (N); |
| 1211 |
Typ : constant Entity_Id := Etype (N); |
| 1212 |
Fnm : Node_Id; |
| 1213 |
|
| 1214 |
begin |
| 1215 |
-- The function name is the selected component Attr_xxx.yyy where |
| 1216 |
-- Attr_xxx is the package name, and yyy is the argument Nam. |
| 1217 |
|
| 1218 |
-- Note: it would be more usual to have separate RE entries for each |
| 1219 |
-- of the entities in the Fat packages, but first they have identical |
| 1220 |
-- names (so we would have to have lots of renaming declarations to |
| 1221 |
-- meet the normal RE rule of separate names for all runtime entities), |
| 1222 |
-- and second there would be an awful lot of them. |
| 1223 |
|
| 1224 |
Fnm := |
| 1225 |
Make_Selected_Component (Loc, |
| 1226 |
Prefix => New_Occurrence_Of (RTE (Pkg), Loc), |
| 1227 |
Selector_Name => Make_Identifier (Loc, Nam)); |
| 1228 |
|
| 1229 |
-- The generated call is given the provided set of parameters, and then |
| 1230 |
-- wrapped in a conversion which converts the result to the target type. |
| 1231 |
|
| 1232 |
Rewrite (N, |
| 1233 |
Convert_To (Typ, |
| 1234 |
Make_Function_Call (Loc, |
| 1235 |
Name => Fnm, |
| 1236 |
Parameter_Associations => Args))); |
| 1237 |
|
| 1238 |
Analyze_And_Resolve (N, Typ); |
| 1239 |
end Expand_Fpt_Attribute; |
| 1240 |
|
| 1241 |
---------------------------- |
| 1242 |
-- Expand_Fpt_Attribute_R -- |
| 1243 |
---------------------------- |
| 1244 |
|
| 1245 |
-- The single argument is converted to its root type to call the |
| 1246 |
-- appropriate runtime function, with the actual call being built |
| 1247 |
-- by Expand_Fpt_Attribute |
| 1248 |
|
| 1249 |
procedure Expand_Fpt_Attribute_R (N : Node_Id) is |
| 1250 |
E1 : constant Node_Id := First (Expressions (N)); |
| 1251 |
Ftp : Entity_Id; |
| 1252 |
Pkg : RE_Id; |
| 1253 |
begin |
| 1254 |
Find_Fat_Info (Etype (E1), Ftp, Pkg); |
| 1255 |
Expand_Fpt_Attribute |
| 1256 |
(N, Pkg, Attribute_Name (N), |
| 1257 |
New_List (Unchecked_Convert_To (Ftp, Relocate_Node (E1)))); |
| 1258 |
end Expand_Fpt_Attribute_R; |
| 1259 |
|
| 1260 |
----------------------------- |
| 1261 |
-- Expand_Fpt_Attribute_RI -- |
| 1262 |
----------------------------- |
| 1263 |
|
| 1264 |
-- The first argument is converted to its root type and the second |
| 1265 |
-- argument is converted to standard long long integer to call the |
| 1266 |
-- appropriate runtime function, with the actual call being built |
| 1267 |
-- by Expand_Fpt_Attribute |
| 1268 |
|
| 1269 |
procedure Expand_Fpt_Attribute_RI (N : Node_Id) is |
| 1270 |
E1 : constant Node_Id := First (Expressions (N)); |
| 1271 |
E2 : constant Node_Id := Next (E1); |
| 1272 |
Ftp : Entity_Id; |
| 1273 |
Pkg : RE_Id; |
| 1274 |
begin |
| 1275 |
Find_Fat_Info (Etype (E1), Ftp, Pkg); |
| 1276 |
Expand_Fpt_Attribute |
| 1277 |
(N, Pkg, Attribute_Name (N), |
| 1278 |
New_List ( |
| 1279 |
Unchecked_Convert_To (Ftp, Relocate_Node (E1)), |
| 1280 |
Unchecked_Convert_To (Standard_Integer, Relocate_Node (E2)))); |
| 1281 |
end Expand_Fpt_Attribute_RI; |
| 1282 |
|
| 1283 |
----------------------------- |
| 1284 |
-- Expand_Fpt_Attribute_RR -- |
| 1285 |
----------------------------- |
| 1286 |
|
| 1287 |
-- The two arguments are converted to their root types to call the |
| 1288 |
-- appropriate runtime function, with the actual call being built |
| 1289 |
-- by Expand_Fpt_Attribute |
| 1290 |
|
| 1291 |
procedure Expand_Fpt_Attribute_RR (N : Node_Id) is |
| 1292 |
E1 : constant Node_Id := First (Expressions (N)); |
| 1293 |
E2 : constant Node_Id := Next (E1); |
| 1294 |
Ftp : Entity_Id; |
| 1295 |
Pkg : RE_Id; |
| 1296 |
|
| 1297 |
begin |
| 1298 |
Find_Fat_Info (Etype (E1), Ftp, Pkg); |
| 1299 |
Expand_Fpt_Attribute |
| 1300 |
(N, Pkg, Attribute_Name (N), |
| 1301 |
New_List ( |
| 1302 |
Unchecked_Convert_To (Ftp, Relocate_Node (E1)), |
| 1303 |
Unchecked_Convert_To (Ftp, Relocate_Node (E2)))); |
| 1304 |
end Expand_Fpt_Attribute_RR; |
| 1305 |
|
| 1306 |
--------------------------------- |
| 1307 |
-- Expand_Loop_Entry_Attribute -- |
| 1308 |
--------------------------------- |
| 1309 |
|
| 1310 |
procedure Expand_Loop_Entry_Attribute (N : Node_Id) is |
| 1311 |
procedure Build_Conditional_Block |
| 1312 |
(Loc : Source_Ptr; |
| 1313 |
Cond : Node_Id; |
| 1314 |
Loop_Stmt : Node_Id; |
| 1315 |
If_Stmt : out Node_Id; |
| 1316 |
Blk_Stmt : out Node_Id); |
| 1317 |
-- Create a block Blk_Stmt with an empty declarative list and a single |
| 1318 |
-- loop Loop_Stmt. The block is encased in an if statement If_Stmt with |
| 1319 |
-- condition Cond. If_Stmt is Empty when there is no condition provided. |
| 1320 |
|
| 1321 |
function Is_Array_Iteration (N : Node_Id) return Boolean; |
| 1322 |
-- Determine whether loop statement N denotes an Ada 2012 iteration over |
| 1323 |
-- an array object. |
| 1324 |
|
| 1325 |
----------------------------- |
| 1326 |
-- Build_Conditional_Block -- |
| 1327 |
----------------------------- |
| 1328 |
|
| 1329 |
procedure Build_Conditional_Block |
| 1330 |
(Loc : Source_Ptr; |
| 1331 |
Cond : Node_Id; |
| 1332 |
Loop_Stmt : Node_Id; |
| 1333 |
If_Stmt : out Node_Id; |
| 1334 |
Blk_Stmt : out Node_Id) |
| 1335 |
is |
| 1336 |
begin |
| 1337 |
-- Do not reanalyze the original loop statement because it is simply |
| 1338 |
-- being relocated. |
| 1339 |
|
| 1340 |
Set_Analyzed (Loop_Stmt); |
| 1341 |
|
| 1342 |
Blk_Stmt := |
| 1343 |
Make_Block_Statement (Loc, |
| 1344 |
Declarations => New_List, |
| 1345 |
Handled_Statement_Sequence => |
| 1346 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1347 |
Statements => New_List (Loop_Stmt))); |
| 1348 |
|
| 1349 |
if Present (Cond) then |
| 1350 |
If_Stmt := |
| 1351 |
Make_If_Statement (Loc, |
| 1352 |
Condition => Cond, |
| 1353 |
Then_Statements => New_List (Blk_Stmt)); |
| 1354 |
else |
| 1355 |
If_Stmt := Empty; |
| 1356 |
end if; |
| 1357 |
end Build_Conditional_Block; |
| 1358 |
|
| 1359 |
------------------------ |
| 1360 |
-- Is_Array_Iteration -- |
| 1361 |
------------------------ |
| 1362 |
|
| 1363 |
function Is_Array_Iteration (N : Node_Id) return Boolean is |
| 1364 |
Stmt : constant Node_Id := Original_Node (N); |
| 1365 |
Iter : Node_Id; |
| 1366 |
|
| 1367 |
begin |
| 1368 |
if Nkind (Stmt) = N_Loop_Statement |
| 1369 |
and then Present (Iteration_Scheme (Stmt)) |
| 1370 |
and then Present (Iterator_Specification (Iteration_Scheme (Stmt))) |
| 1371 |
then |
| 1372 |
Iter := Iterator_Specification (Iteration_Scheme (Stmt)); |
| 1373 |
|
| 1374 |
return |
| 1375 |
Of_Present (Iter) and then Is_Array_Type (Etype (Name (Iter))); |
| 1376 |
end if; |
| 1377 |
|
| 1378 |
return False; |
| 1379 |
end Is_Array_Iteration; |
| 1380 |
|
| 1381 |
-- Local variables |
| 1382 |
|
| 1383 |
Pref : constant Node_Id := Prefix (N); |
| 1384 |
Base_Typ : constant Entity_Id := Base_Type (Etype (Pref)); |
| 1385 |
Exprs : constant List_Id := Expressions (N); |
| 1386 |
Loc : constant Source_Ptr := Sloc (N); |
| 1387 |
Aux_Decl : Node_Id; |
| 1388 |
Blk : Node_Id := Empty; |
| 1389 |
Decls : List_Id; |
| 1390 |
Installed : Boolean; |
| 1391 |
Loop_Id : Entity_Id; |
| 1392 |
Loop_Stmt : Node_Id; |
| 1393 |
Result : Node_Id := Empty; |
| 1394 |
Scheme : Node_Id; |
| 1395 |
Temp_Decl : Node_Id; |
| 1396 |
Temp_Id : Entity_Id; |
| 1397 |
|
| 1398 |
-- Start of processing for Expand_Loop_Entry_Attribute |
| 1399 |
|
| 1400 |
begin |
| 1401 |
-- Step 1: Find the related loop |
| 1402 |
|
| 1403 |
-- The loop label variant of attribute 'Loop_Entry already has all the |
| 1404 |
-- information in its expression. |
| 1405 |
|
| 1406 |
if Present (Exprs) then |
| 1407 |
Loop_Id := Entity (First (Exprs)); |
| 1408 |
Loop_Stmt := Label_Construct (Parent (Loop_Id)); |
| 1409 |
|
| 1410 |
-- Climb the parent chain to find the nearest enclosing loop. Skip |
| 1411 |
-- all internally generated loops for quantified expressions and for |
| 1412 |
-- element iterators over multidimensional arrays because the pragma |
| 1413 |
-- applies to source loop. |
| 1414 |
|
| 1415 |
else |
| 1416 |
Loop_Stmt := N; |
| 1417 |
while Present (Loop_Stmt) loop |
| 1418 |
if Nkind (Loop_Stmt) = N_Loop_Statement |
| 1419 |
and then Nkind (Original_Node (Loop_Stmt)) = N_Loop_Statement |
| 1420 |
and then Comes_From_Source (Original_Node (Loop_Stmt)) |
| 1421 |
then |
| 1422 |
exit; |
| 1423 |
end if; |
| 1424 |
|
| 1425 |
Loop_Stmt := Parent (Loop_Stmt); |
| 1426 |
end loop; |
| 1427 |
|
| 1428 |
Loop_Id := Entity (Identifier (Loop_Stmt)); |
| 1429 |
end if; |
| 1430 |
|
| 1431 |
-- Step 2: Transform the loop |
| 1432 |
|
| 1433 |
-- The loop has already been transformed during the expansion of a prior |
| 1434 |
-- 'Loop_Entry attribute. Retrieve the declarative list of the block. |
| 1435 |
|
| 1436 |
if Has_Loop_Entry_Attributes (Loop_Id) then |
| 1437 |
|
| 1438 |
-- When the related loop name appears as the argument of attribute |
| 1439 |
-- Loop_Entry, the corresponding label construct is the generated |
| 1440 |
-- block statement. This is because the expander reuses the label. |
| 1441 |
|
| 1442 |
if Nkind (Loop_Stmt) = N_Block_Statement then |
| 1443 |
Decls := Declarations (Loop_Stmt); |
| 1444 |
|
| 1445 |
-- In all other cases, the loop must appear in the handled sequence |
| 1446 |
-- of statements of the generated block. |
| 1447 |
|
| 1448 |
else |
| 1449 |
pragma Assert |
| 1450 |
(Nkind (Parent (Loop_Stmt)) = N_Handled_Sequence_Of_Statements |
| 1451 |
and then |
| 1452 |
Nkind (Parent (Parent (Loop_Stmt))) = N_Block_Statement); |
| 1453 |
|
| 1454 |
Decls := Declarations (Parent (Parent (Loop_Stmt))); |
| 1455 |
end if; |
| 1456 |
|
| 1457 |
-- Transform the loop into a conditional block |
| 1458 |
|
| 1459 |
else |
| 1460 |
Set_Has_Loop_Entry_Attributes (Loop_Id); |
| 1461 |
Scheme := Iteration_Scheme (Loop_Stmt); |
| 1462 |
|
| 1463 |
-- Infinite loops are transformed into: |
| 1464 |
|
| 1465 |
-- declare |
| 1466 |
-- Temp1 : constant <type of Pref1> := <Pref1>; |
| 1467 |
-- . . . |
| 1468 |
-- TempN : constant <type of PrefN> := <PrefN>; |
| 1469 |
-- begin |
| 1470 |
-- loop |
| 1471 |
-- <original source statements with attribute rewrites> |
| 1472 |
-- end loop; |
| 1473 |
-- end; |
| 1474 |
|
| 1475 |
if No (Scheme) then |
| 1476 |
Build_Conditional_Block (Loc, |
| 1477 |
Cond => Empty, |
| 1478 |
Loop_Stmt => Relocate_Node (Loop_Stmt), |
| 1479 |
If_Stmt => Result, |
| 1480 |
Blk_Stmt => Blk); |
| 1481 |
|
| 1482 |
Result := Blk; |
| 1483 |
|
| 1484 |
-- While loops are transformed into: |
| 1485 |
|
| 1486 |
-- function Fnn return Boolean is |
| 1487 |
-- begin |
| 1488 |
-- <condition actions> |
| 1489 |
-- return <condition>; |
| 1490 |
-- end Fnn; |
| 1491 |
|
| 1492 |
-- if Fnn then |
| 1493 |
-- declare |
| 1494 |
-- Temp1 : constant <type of Pref1> := <Pref1>; |
| 1495 |
-- . . . |
| 1496 |
-- TempN : constant <type of PrefN> := <PrefN>; |
| 1497 |
-- begin |
| 1498 |
-- loop |
| 1499 |
-- <original source statements with attribute rewrites> |
| 1500 |
-- exit when not Fnn; |
| 1501 |
-- end loop; |
| 1502 |
-- end; |
| 1503 |
-- end if; |
| 1504 |
|
| 1505 |
-- Note that loops over iterators and containers are already |
| 1506 |
-- converted into while loops. |
| 1507 |
|
| 1508 |
elsif Present (Condition (Scheme)) then |
| 1509 |
declare |
| 1510 |
Func_Decl : Node_Id; |
| 1511 |
Func_Id : Entity_Id; |
| 1512 |
Stmts : List_Id; |
| 1513 |
|
| 1514 |
begin |
| 1515 |
Func_Id := Make_Temporary (Loc, 'F'); |
| 1516 |
|
| 1517 |
-- Wrap the condition of the while loop in a Boolean function. |
| 1518 |
-- This avoids the duplication of the same code which may lead |
| 1519 |
-- to gigi issues with respect to multiple declaration of the |
| 1520 |
-- same entity in the presence of side effects or checks. Note |
| 1521 |
-- that the condition actions must also be relocated into the |
| 1522 |
-- wrapping function because they may contain itypes, e.g. in |
| 1523 |
-- the case of a comparison involving slices. |
| 1524 |
|
| 1525 |
-- Generate: |
| 1526 |
-- <condition actions> |
| 1527 |
-- return <condition>; |
| 1528 |
|
| 1529 |
if Present (Condition_Actions (Scheme)) then |
| 1530 |
Stmts := Condition_Actions (Scheme); |
| 1531 |
else |
| 1532 |
Stmts := New_List; |
| 1533 |
end if; |
| 1534 |
|
| 1535 |
Append_To (Stmts, |
| 1536 |
Make_Simple_Return_Statement (Loc, |
| 1537 |
Expression => |
| 1538 |
New_Copy_Tree (Condition (Scheme), |
| 1539 |
New_Scope => Func_Id))); |
| 1540 |
|
| 1541 |
-- Generate: |
| 1542 |
-- function Fnn return Boolean is |
| 1543 |
-- begin |
| 1544 |
-- <Stmts> |
| 1545 |
-- end Fnn; |
| 1546 |
|
| 1547 |
Func_Decl := |
| 1548 |
Make_Subprogram_Body (Loc, |
| 1549 |
Specification => |
| 1550 |
Make_Function_Specification (Loc, |
| 1551 |
Defining_Unit_Name => Func_Id, |
| 1552 |
Result_Definition => |
| 1553 |
New_Occurrence_Of (Standard_Boolean, Loc)), |
| 1554 |
Declarations => Empty_List, |
| 1555 |
Handled_Statement_Sequence => |
| 1556 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 1557 |
Statements => Stmts)); |
| 1558 |
|
| 1559 |
-- The function is inserted before the related loop. Make sure |
| 1560 |
-- to analyze it in the context of the loop's enclosing scope. |
| 1561 |
|
| 1562 |
Push_Scope (Scope (Loop_Id)); |
| 1563 |
Insert_Action (Loop_Stmt, Func_Decl); |
| 1564 |
Pop_Scope; |
| 1565 |
|
| 1566 |
-- The analysis of the condition may have generated entities |
| 1567 |
-- (such as itypes) that are now used within the function. |
| 1568 |
-- Adjust their scopes accordingly so that their use appears |
| 1569 |
-- in their scope of definition. |
| 1570 |
|
| 1571 |
declare |
| 1572 |
Ent : Entity_Id; |
| 1573 |
|
| 1574 |
begin |
| 1575 |
Ent := First_Entity (Loop_Id); |
| 1576 |
|
| 1577 |
while Present (Ent) loop |
| 1578 |
-- Various entities that now occur within the function |
| 1579 |
-- need to have their scope reset, but not all entities |
| 1580 |
-- associated with Loop_Id are now inside the function. |
| 1581 |
-- The function entity itself and loop parameters can |
| 1582 |
-- be outside the function, and there may be others. |
| 1583 |
-- It's not clear how the determination of what entity |
| 1584 |
-- scopes need to be adjusted can be made accurately. |
| 1585 |
-- Perhaps it will be necessary to traverse the function |
| 1586 |
-- body to find the exact entities whose scopes need to |
| 1587 |
-- be reset to the function's Entity_Id. ??? |
| 1588 |
|
| 1589 |
if Ekind (Ent) /= E_Loop_Parameter |
| 1590 |
and then Ent /= Func_Id |
| 1591 |
then |
| 1592 |
Set_Scope (Ent, Func_Id); |
| 1593 |
end if; |
| 1594 |
|
| 1595 |
Next_Entity (Ent); |
| 1596 |
end loop; |
| 1597 |
end; |
| 1598 |
|
| 1599 |
-- Transform the original while loop into an infinite loop |
| 1600 |
-- where the last statement checks the negated condition. This |
| 1601 |
-- placement ensures that the condition will not be evaluated |
| 1602 |
-- twice on the first iteration. |
| 1603 |
|
| 1604 |
Set_Iteration_Scheme (Loop_Stmt, Empty); |
| 1605 |
Scheme := Empty; |
| 1606 |
|
| 1607 |
-- Generate: |
| 1608 |
-- exit when not Fnn; |
| 1609 |
|
| 1610 |
Append_To (Statements (Loop_Stmt), |
| 1611 |
Make_Exit_Statement (Loc, |
| 1612 |
Condition => |
| 1613 |
Make_Op_Not (Loc, |
| 1614 |
Right_Opnd => |
| 1615 |
Make_Function_Call (Loc, |
| 1616 |
Name => New_Occurrence_Of (Func_Id, Loc))))); |
| 1617 |
|
| 1618 |
Build_Conditional_Block (Loc, |
| 1619 |
Cond => |
| 1620 |
Make_Function_Call (Loc, |
| 1621 |
Name => New_Occurrence_Of (Func_Id, Loc)), |
| 1622 |
Loop_Stmt => Relocate_Node (Loop_Stmt), |
| 1623 |
If_Stmt => Result, |
| 1624 |
Blk_Stmt => Blk); |
| 1625 |
end; |
| 1626 |
|
| 1627 |
-- Ada 2012 iteration over an array is transformed into: |
| 1628 |
|
| 1629 |
-- if <Array_Nam>'Length (1) > 0 |
| 1630 |
-- and then <Array_Nam>'Length (N) > 0 |
| 1631 |
-- then |
| 1632 |
-- declare |
| 1633 |
-- Temp1 : constant <type of Pref1> := <Pref1>; |
| 1634 |
-- . . . |
| 1635 |
-- TempN : constant <type of PrefN> := <PrefN>; |
| 1636 |
-- begin |
| 1637 |
-- for X in ... loop -- multiple loops depending on dims |
| 1638 |
-- <original source statements with attribute rewrites> |
| 1639 |
-- end loop; |
| 1640 |
-- end; |
| 1641 |
-- end if; |
| 1642 |
|
| 1643 |
elsif Is_Array_Iteration (Loop_Stmt) then |
| 1644 |
declare |
| 1645 |
Array_Nam : constant Entity_Id := |
| 1646 |
Entity (Name (Iterator_Specification |
| 1647 |
(Iteration_Scheme (Original_Node (Loop_Stmt))))); |
| 1648 |
Num_Dims : constant Pos := |
| 1649 |
Number_Dimensions (Etype (Array_Nam)); |
| 1650 |
Cond : Node_Id := Empty; |
| 1651 |
Check : Node_Id; |
| 1652 |
|
| 1653 |
begin |
| 1654 |
-- Generate a check which determines whether all dimensions of |
| 1655 |
-- the array are non-null. |
| 1656 |
|
| 1657 |
for Dim in 1 .. Num_Dims loop |
| 1658 |
Check := |
| 1659 |
Make_Op_Gt (Loc, |
| 1660 |
Left_Opnd => |
| 1661 |
Make_Attribute_Reference (Loc, |
| 1662 |
Prefix => New_Occurrence_Of (Array_Nam, Loc), |
| 1663 |
Attribute_Name => Name_Length, |
| 1664 |
Expressions => New_List ( |
| 1665 |
Make_Integer_Literal (Loc, Dim))), |
| 1666 |
Right_Opnd => |
| 1667 |
Make_Integer_Literal (Loc, 0)); |
| 1668 |
|
| 1669 |
if No (Cond) then |
| 1670 |
Cond := Check; |
| 1671 |
else |
| 1672 |
Cond := |
| 1673 |
Make_And_Then (Loc, |
| 1674 |
Left_Opnd => Cond, |
| 1675 |
Right_Opnd => Check); |
| 1676 |
end if; |
| 1677 |
end loop; |
| 1678 |
|
| 1679 |
Build_Conditional_Block (Loc, |
| 1680 |
Cond => Cond, |
| 1681 |
Loop_Stmt => Relocate_Node (Loop_Stmt), |
| 1682 |
If_Stmt => Result, |
| 1683 |
Blk_Stmt => Blk); |
| 1684 |
end; |
| 1685 |
|
| 1686 |
-- For loops are transformed into: |
| 1687 |
|
| 1688 |
-- if <Low> <= <High> then |
| 1689 |
-- declare |
| 1690 |
-- Temp1 : constant <type of Pref1> := <Pref1>; |
| 1691 |
-- . . . |
| 1692 |
-- TempN : constant <type of PrefN> := <PrefN>; |
| 1693 |
-- begin |
| 1694 |
-- for <Def_Id> in <Low> .. <High> loop |
| 1695 |
-- <original source statements with attribute rewrites> |
| 1696 |
-- end loop; |
| 1697 |
-- end; |
| 1698 |
-- end if; |
| 1699 |
|
| 1700 |
elsif Present (Loop_Parameter_Specification (Scheme)) then |
| 1701 |
declare |
| 1702 |
Loop_Spec : constant Node_Id := |
| 1703 |
Loop_Parameter_Specification (Scheme); |
| 1704 |
Cond : Node_Id; |
| 1705 |
Subt_Def : Node_Id; |
| 1706 |
|
| 1707 |
begin |
| 1708 |
Subt_Def := Discrete_Subtype_Definition (Loop_Spec); |
| 1709 |
|
| 1710 |
-- When the loop iterates over a subtype indication with a |
| 1711 |
-- range, use the low and high bounds of the subtype itself. |
| 1712 |
|
| 1713 |
if Nkind (Subt_Def) = N_Subtype_Indication then |
| 1714 |
Subt_Def := Scalar_Range (Etype (Subt_Def)); |
| 1715 |
end if; |
| 1716 |
|
| 1717 |
pragma Assert (Nkind (Subt_Def) = N_Range); |
| 1718 |
|
| 1719 |
-- Generate |
| 1720 |
-- Low <= High |
| 1721 |
|
| 1722 |
Cond := |
| 1723 |
Make_Op_Le (Loc, |
| 1724 |
Left_Opnd => New_Copy_Tree (Low_Bound (Subt_Def)), |
| 1725 |
Right_Opnd => New_Copy_Tree (High_Bound (Subt_Def))); |
| 1726 |
|
| 1727 |
Build_Conditional_Block (Loc, |
| 1728 |
Cond => Cond, |
| 1729 |
Loop_Stmt => Relocate_Node (Loop_Stmt), |
| 1730 |
If_Stmt => Result, |
| 1731 |
Blk_Stmt => Blk); |
| 1732 |
end; |
| 1733 |
end if; |
| 1734 |
|
| 1735 |
Decls := Declarations (Blk); |
| 1736 |
end if; |
| 1737 |
|
| 1738 |
-- Step 3: Create a constant to capture the value of the prefix at the |
| 1739 |
-- entry point into the loop. |
| 1740 |
|
| 1741 |
Temp_Id := Make_Temporary (Loc, 'P'); |
| 1742 |
|
| 1743 |
-- Preserve the tag of the prefix by offering a specific view of the |
| 1744 |
-- class-wide version of the prefix. |
| 1745 |
|
| 1746 |
if Is_Tagged_Type (Base_Typ) then |
| 1747 |
Tagged_Case : declare |
| 1748 |
CW_Temp : Entity_Id; |
| 1749 |
CW_Typ : Entity_Id; |
| 1750 |
|
| 1751 |
begin |
| 1752 |
-- Generate: |
| 1753 |
-- CW_Temp : constant Base_Typ'Class := Base_Typ'Class (Pref); |
| 1754 |
|
| 1755 |
CW_Temp := Make_Temporary (Loc, 'T'); |
| 1756 |
CW_Typ := Class_Wide_Type (Base_Typ); |
| 1757 |
|
| 1758 |
Aux_Decl := |
| 1759 |
Make_Object_Declaration (Loc, |
| 1760 |
Defining_Identifier => CW_Temp, |
| 1761 |
Constant_Present => True, |
| 1762 |
Object_Definition => New_Occurrence_Of (CW_Typ, Loc), |
| 1763 |
Expression => |
| 1764 |
Convert_To (CW_Typ, Relocate_Node (Pref))); |
| 1765 |
Append_To (Decls, Aux_Decl); |
| 1766 |
|
| 1767 |
-- Generate: |
| 1768 |
-- Temp : Base_Typ renames Base_Typ (CW_Temp); |
| 1769 |
|
| 1770 |
Temp_Decl := |
| 1771 |
Make_Object_Renaming_Declaration (Loc, |
| 1772 |
Defining_Identifier => Temp_Id, |
| 1773 |
Subtype_Mark => New_Occurrence_Of (Base_Typ, Loc), |
| 1774 |
Name => |
| 1775 |
Convert_To (Base_Typ, New_Occurrence_Of (CW_Temp, Loc))); |
| 1776 |
Append_To (Decls, Temp_Decl); |
| 1777 |
end Tagged_Case; |
| 1778 |
|
| 1779 |
-- Untagged case |
| 1780 |
|
| 1781 |
else |
| 1782 |
Untagged_Case : declare |
| 1783 |
Temp_Expr : Node_Id; |
| 1784 |
|
| 1785 |
begin |
| 1786 |
Aux_Decl := Empty; |
| 1787 |
|
| 1788 |
Temp_Expr := Relocate_Node (Pref); |
| 1789 |
|
| 1790 |
-- For Etype (Temp_Expr) in some cases we cannot use either |
| 1791 |
-- Etype (Pref) or Base_Typ. So we set Etype (Temp_Expr) to null |
| 1792 |
-- and mark Temp_Expr as requiring analysis. Rather than trying |
| 1793 |
-- to sort out exactly when this is needed, we do it |
| 1794 |
-- unconditionally. |
| 1795 |
-- One case where this is needed is when |
| 1796 |
-- 1) Pref is an N_Selected_Component name that |
| 1797 |
-- refers to a component which is subject to a |
| 1798 |
-- discriminant-dependent constraint; and |
| 1799 |
-- 2) The prefix of that N_Selected_Component refers to a |
| 1800 |
-- formal parameter with an unconstrained subtype; and |
| 1801 |
-- 3) Pref has only been preanalyzed (so that |
| 1802 |
-- Build_Actual_Subtype_Of_Component has not been called |
| 1803 |
-- and Etype (Pref) equals the Etype of the component). |
| 1804 |
|
| 1805 |
Set_Etype (Temp_Expr, Empty); |
| 1806 |
Set_Analyzed (Temp_Expr, False); |
| 1807 |
|
| 1808 |
-- Generate: |
| 1809 |
-- Temp : constant Base_Typ := Pref; |
| 1810 |
|
| 1811 |
Temp_Decl := |
| 1812 |
Make_Object_Declaration (Loc, |
| 1813 |
Defining_Identifier => Temp_Id, |
| 1814 |
Constant_Present => True, |
| 1815 |
Object_Definition => New_Occurrence_Of (Base_Typ, Loc), |
| 1816 |
Expression => Temp_Expr); |
| 1817 |
Append_To (Decls, Temp_Decl); |
| 1818 |
end Untagged_Case; |
| 1819 |
end if; |
| 1820 |
|
| 1821 |
-- Step 4: Analyze all bits |
| 1822 |
|
| 1823 |
Installed := Current_Scope = Scope (Loop_Id); |
| 1824 |
|
| 1825 |
-- Depending on the pracement of attribute 'Loop_Entry relative to the |
| 1826 |
-- associated loop, ensure the proper visibility for analysis. |
| 1827 |
|
| 1828 |
if not Installed then |
| 1829 |
Push_Scope (Scope (Loop_Id)); |
| 1830 |
end if; |
| 1831 |
|
| 1832 |
-- Analyze constant declaration with simple value propagation disabled, |
| 1833 |
-- because the values at the loop entry might be different than the |
| 1834 |
-- values at the occurrence of Loop_Entry attribute. |
| 1835 |
|
| 1836 |
declare |
| 1837 |
Save_Debug_Flag_MM : constant Boolean := Debug_Flag_MM; |
| 1838 |
begin |
| 1839 |
Debug_Flag_MM := True; |
| 1840 |
|
| 1841 |
if Present (Aux_Decl) then |
| 1842 |
Analyze (Aux_Decl); |
| 1843 |
end if; |
| 1844 |
|
| 1845 |
Analyze (Temp_Decl); |
| 1846 |
|
| 1847 |
Debug_Flag_MM := Save_Debug_Flag_MM; |
| 1848 |
end; |
| 1849 |
|
| 1850 |
-- If the conditional block has just been created, then analyze it; |
| 1851 |
-- otherwise it was analyzed when a previous 'Loop_Entry was expanded. |
| 1852 |
|
| 1853 |
if Present (Result) then |
| 1854 |
Rewrite (Loop_Stmt, Result); |
| 1855 |
Analyze (Loop_Stmt); |
| 1856 |
end if; |
| 1857 |
|
| 1858 |
Rewrite (N, New_Occurrence_Of (Temp_Id, Loc)); |
| 1859 |
Analyze (N); |
| 1860 |
|
| 1861 |
if not Installed then |
| 1862 |
Pop_Scope; |
| 1863 |
end if; |
| 1864 |
end Expand_Loop_Entry_Attribute; |
| 1865 |
|
| 1866 |
------------------------------ |
| 1867 |
-- Expand_Min_Max_Attribute -- |
| 1868 |
------------------------------ |
| 1869 |
|
| 1870 |
procedure Expand_Min_Max_Attribute (N : Node_Id) is |
| 1871 |
begin |
| 1872 |
-- Min and Max are handled by the back end (except that static cases |
| 1873 |
-- have already been evaluated during semantic processing, although the |
| 1874 |
-- back end should not count on this). The one bit of special processing |
| 1875 |
-- required in the normal case is that these two attributes typically |
| 1876 |
-- generate conditionals in the code, so check the relevant restriction. |
| 1877 |
|
| 1878 |
Check_Restriction (No_Implicit_Conditionals, N); |
| 1879 |
end Expand_Min_Max_Attribute; |
| 1880 |
|
| 1881 |
---------------------------------- |
| 1882 |
-- Expand_N_Attribute_Reference -- |
| 1883 |
---------------------------------- |
| 1884 |
|
| 1885 |
procedure Expand_N_Attribute_Reference (N : Node_Id) is |
| 1886 |
Loc : constant Source_Ptr := Sloc (N); |
| 1887 |
Pref : constant Node_Id := Prefix (N); |
| 1888 |
Exprs : constant List_Id := Expressions (N); |
| 1889 |
|
| 1890 |
generic |
| 1891 |
with procedure Build_Type_Attr_Subprogram |
| 1892 |
(Typ : Entity_Id; |
| 1893 |
Decl : out Node_Id; |
| 1894 |
Subp : out Entity_Id); |
| 1895 |
procedure Build_And_Insert_Type_Attr_Subp |
| 1896 |
(Typ : Entity_Id; |
| 1897 |
Decl : out Node_Id; |
| 1898 |
Subp : out Entity_Id; |
| 1899 |
Attr_Ref : Node_Id); |
| 1900 |
|
| 1901 |
-- If we have two calls to (for example) |
| 1902 |
-- Some_Untagged_Record_Type'Put_Image, we'd like |
| 1903 |
-- to generate just one procedure and call it twice (as opposed to |
| 1904 |
-- generating two effectively-identical procedures). Hoisting the |
| 1905 |
-- declaration of the procedure ensures that a second such attribute |
| 1906 |
-- reference in the current library unit will not need to generate a |
| 1907 |
-- second procedure. |
| 1908 |
|
| 1909 |
function Get_Integer_Type (Typ : Entity_Id) return Entity_Id; |
| 1910 |
-- Return a small integer type appropriate for the enumeration type |
| 1911 |
|
| 1912 |
procedure Rewrite_Attribute_Proc_Call (Pname : Entity_Id); |
| 1913 |
-- Rewrites an attribute for Read, Write, Output, or Put_Image with a |
| 1914 |
-- call to the appropriate TSS procedure. Pname is the entity for the |
| 1915 |
-- procedure to call. |
| 1916 |
|
| 1917 |
------------------------------------- |
| 1918 |
-- Build_And_Insert_Type_Attr_Subp -- |
| 1919 |
------------------------------------- |
| 1920 |
|
| 1921 |
procedure Build_And_Insert_Type_Attr_Subp |
| 1922 |
(Typ : Entity_Id; |
| 1923 |
Decl : out Node_Id; |
| 1924 |
Subp : out Entity_Id; |
| 1925 |
Attr_Ref : Node_Id) |
| 1926 |
is |
| 1927 |
procedure Build; |
| 1928 |
procedure Build is |
| 1929 |
begin |
| 1930 |
Build_Type_Attr_Subprogram |
| 1931 |
(Typ => Typ, |
| 1932 |
Decl => Decl, |
| 1933 |
Subp => Subp); |
| 1934 |
end Build; |
| 1935 |
|
| 1936 |
Ancestor : Node_Id := Attr_Ref; |
| 1937 |
Insertion_Scope : Entity_Id := Empty; |
| 1938 |
Insertion_Point : Node_Id := Empty; |
| 1939 |
Insert_Before : Boolean := False; |
| 1940 |
Typ_Comp_Unit : Node_Id := Enclosing_Comp_Unit_Node (Typ); |
| 1941 |
begin |
| 1942 |
-- handle no-enclosing-comp-unit cases |
| 1943 |
if No (Typ_Comp_Unit) then |
| 1944 |
if Is_Itype (Typ) then |
| 1945 |
Typ_Comp_Unit := Enclosing_Comp_Unit_Node |
| 1946 |
(Associated_Node_For_Itype (Typ)); |
| 1947 |
elsif Sloc (Typ) <= Standard_Location then |
| 1948 |
Typ_Comp_Unit := Typ; -- not a comp unit node, but that's ok |
| 1949 |
end if; |
| 1950 |
pragma Assert (Present (Typ_Comp_Unit)); |
| 1951 |
end if; |
| 1952 |
|
| 1953 |
if Interunit_Ref_OK (Typ_Comp_Unit, |
| 1954 |
Enclosing_Comp_Unit_Node (Attr_Ref)) |
| 1955 |
-- See comment accompanying earlier call to Interunit_Ref_OK |
| 1956 |
-- for discussion of these Enclosing_Comp_Unit_Node calls. |
| 1957 |
then |
| 1958 |
-- Typ is declared in the current unit, so |
| 1959 |
-- we want to hoist to the same scope as Typ. |
| 1960 |
|
| 1961 |
Insertion_Scope := Scope (Typ); |
| 1962 |
Insertion_Point := Freeze_Node (Typ); |
| 1963 |
else |
| 1964 |
-- Typ is declared in a different unit, so |
| 1965 |
-- hoist to library level. |
| 1966 |
|
| 1967 |
pragma Assert (Is_Library_Level_Entity (Typ)); |
| 1968 |
|
| 1969 |
while Present (Ancestor) loop |
| 1970 |
if Is_List_Member (Ancestor) then |
| 1971 |
Insertion_Point := First (List_Containing (Ancestor)); |
| 1972 |
|
| 1973 |
-- A hazard to avoid here is use-before-definition |
| 1974 |
-- errors that can result when we have two of these |
| 1975 |
-- subprograms where one calls the other (e.g., given |
| 1976 |
-- Put_Image procedures for a composite type and |
| 1977 |
-- for a component type, the former will often call |
| 1978 |
-- the latter). At the time a subprogram is inserted, |
| 1979 |
-- we know that the one and only call to it is |
| 1980 |
-- somewhere in the subtree rooted at Ancestor. |
| 1981 |
-- So that placement constraint is easy to satisfy. |
| 1982 |
-- But if we construct another subprogram later and |
| 1983 |
-- if that second subprogram calls the first one, |
| 1984 |
-- then we need to be careful not to place the |
| 1985 |
-- second one ahead of the first one. That is the goal |
| 1986 |
-- of this loop. This may need to be revised if it turns |
| 1987 |
-- out that other stuff is being inserted on the list, |
| 1988 |
-- so that the loop terminates too early. |
| 1989 |
|
| 1990 |
-- On the other hand, it seems like inserting things |
| 1991 |
-- earlier offers more opportunities for sharing. |
| 1992 |
-- If Ancestor occurs in the statement list of a |
| 1993 |
-- subprogram body (ignore the HSS node for now), |
| 1994 |
-- then perhaps we should look for an insertion site |
| 1995 |
-- in the decl list of the subprogram body and only |
| 1996 |
-- look in the statement list if the decl list is empty. |
| 1997 |
-- Similarly if Ancestor occors in the private decls list |
| 1998 |
-- for a package spec that has a non-empty visible |
| 1999 |
-- decls list. No examples where this would result in more |
| 2000 |
-- sharing and less duplication have been observed, so this |
| 2001 |
-- is just speculation. |
| 2002 |
|
| 2003 |
while Insertion_Point /= Ancestor |
| 2004 |
and then Nkind (Insertion_Point) = N_Subprogram_Body |
| 2005 |
and then not Comes_From_Source (Insertion_Point) |
| 2006 |
loop |
| 2007 |
Next (Insertion_Point); |
| 2008 |
end loop; |
| 2009 |
|
| 2010 |
pragma Assert (Present (Insertion_Point)); |
| 2011 |
end if; |
| 2012 |
Ancestor := Parent (Ancestor); |
| 2013 |
end loop; |
| 2014 |
|
| 2015 |
if Present (Insertion_Point) then |
| 2016 |
Insert_Before := True; |
| 2017 |
Insertion_Scope := |
| 2018 |
Find_Enclosing_Scope (Insertion_Point); |
| 2019 |
end if; |
| 2020 |
end if; |
| 2021 |
|
| 2022 |
if Present (Insertion_Point) |
| 2023 |
and Present (Insertion_Scope) |
| 2024 |
then |
| 2025 |
Push_Scope (Insertion_Scope); |
| 2026 |
Build; |
| 2027 |
if Insert_Before then |
| 2028 |
Insert_Action |
| 2029 |
(Insertion_Point, Ins_Action => Decl); |
| 2030 |
else |
| 2031 |
Insert_Action_After |
| 2032 |
(Insertion_Point, Ins_Action => Decl); |
| 2033 |
end if; |
| 2034 |
Pop_Scope; |
| 2035 |
else |
| 2036 |
-- Hoisting was unsuccessful, so no need to |
| 2037 |
-- Push/Pop a scope. |
| 2038 |
|
| 2039 |
Build; |
| 2040 |
Insert_Action (Attr_Ref, Ins_Action => Decl); |
| 2041 |
end if; |
| 2042 |
end Build_And_Insert_Type_Attr_Subp; |
| 2043 |
|
| 2044 |
---------------------- |
| 2045 |
-- Get_Integer_Type -- |
| 2046 |
---------------------- |
| 2047 |
|
| 2048 |
function Get_Integer_Type (Typ : Entity_Id) return Entity_Id is |
| 2049 |
Siz : constant Uint := Esize (Base_Type (Typ)); |
| 2050 |
|
| 2051 |
begin |
| 2052 |
-- We need to accommodate invalid values of the base type since we |
| 2053 |
-- accept them for Enum_Rep and Pos, so we reason on the Esize. |
| 2054 |
|
| 2055 |
return Small_Integer_Type_For (Siz, Uns => Is_Unsigned_Type (Typ)); |
| 2056 |
end Get_Integer_Type; |
| 2057 |
|
| 2058 |
--------------------------------- |
| 2059 |
-- Rewrite_Attribute_Proc_Call -- |
| 2060 |
--------------------------------- |
| 2061 |
|
| 2062 |
procedure Rewrite_Attribute_Proc_Call (Pname : Entity_Id) is |
| 2063 |
Item : constant Node_Id := Next (First (Exprs)); |
| 2064 |
Item_Typ : constant Entity_Id := Etype (Item); |
| 2065 |
Formal : constant Entity_Id := Next_Formal (First_Formal (Pname)); |
| 2066 |
Formal_Typ : constant Entity_Id := Etype (Formal); |
| 2067 |
Is_Written : constant Boolean := Ekind (Formal) /= E_In_Parameter; |
| 2068 |
|
| 2069 |
begin |
| 2070 |
-- The expansion depends on Item, the second actual, which is |
| 2071 |
-- the object being streamed in or out. |
| 2072 |
|
| 2073 |
-- If the item is a component of a packed array type, and |
| 2074 |
-- a conversion is needed on exit, we introduce a temporary to |
| 2075 |
-- hold the value, because otherwise the packed reference will |
| 2076 |
-- not be properly expanded. |
| 2077 |
|
| 2078 |
if Nkind (Item) = N_Indexed_Component |
| 2079 |
and then Is_Packed (Base_Type (Etype (Prefix (Item)))) |
| 2080 |
and then Base_Type (Item_Typ) /= Base_Type (Formal_Typ) |
| 2081 |
and then Is_Written |
| 2082 |
then |
| 2083 |
declare |
| 2084 |
Temp : constant Entity_Id := Make_Temporary (Loc, 'V'); |
| 2085 |
Decl : Node_Id; |
| 2086 |
Assn : Node_Id; |
| 2087 |
|
| 2088 |
begin |
| 2089 |
Decl := |
| 2090 |
Make_Object_Declaration (Loc, |
| 2091 |
Defining_Identifier => Temp, |
| 2092 |
Object_Definition => New_Occurrence_Of (Formal_Typ, Loc)); |
| 2093 |
Set_Etype (Temp, Formal_Typ); |
| 2094 |
|
| 2095 |
Assn := |
| 2096 |
Make_Assignment_Statement (Loc, |
| 2097 |
Name => New_Copy_Tree (Item), |
| 2098 |
Expression => |
| 2099 |
Unchecked_Convert_To |
| 2100 |
(Item_Typ, New_Occurrence_Of (Temp, Loc))); |
| 2101 |
|
| 2102 |
Rewrite (Item, New_Occurrence_Of (Temp, Loc)); |
| 2103 |
Insert_Actions (N, |
| 2104 |
New_List ( |
| 2105 |
Decl, |
| 2106 |
Make_Procedure_Call_Statement (Loc, |
| 2107 |
Name => New_Occurrence_Of (Pname, Loc), |
| 2108 |
Parameter_Associations => Exprs), |
| 2109 |
Assn)); |
| 2110 |
|
| 2111 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 2112 |
return; |
| 2113 |
end; |
| 2114 |
end if; |
| 2115 |
|
| 2116 |
-- For the class-wide dispatching cases, and for cases in which |
| 2117 |
-- the base type of the second argument matches the base type of |
| 2118 |
-- the corresponding formal parameter (that is to say the stream |
| 2119 |
-- operation is not inherited), we are all set, and can use the |
| 2120 |
-- argument unchanged. |
| 2121 |
|
| 2122 |
if not Is_Class_Wide_Type (Entity (Pref)) |
| 2123 |
and then not Is_Class_Wide_Type (Etype (Item)) |
| 2124 |
and then Base_Type (Item_Typ) /= Base_Type (Formal_Typ) |
| 2125 |
then |
| 2126 |
-- Perform an unchecked conversion when either the argument or |
| 2127 |
-- the formal parameter are of a private type. |
| 2128 |
|
| 2129 |
if (Is_Private_Type (Base_Type (Formal_Typ)) |
| 2130 |
or else Is_Private_Type (Base_Type (Item_Typ))) |
| 2131 |
and then (Is_By_Reference_Type (Formal_Typ) or else |
| 2132 |
not Is_Written) |
| 2133 |
then |
| 2134 |
Rewrite (Item, |
| 2135 |
Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item))); |
| 2136 |
|
| 2137 |
-- Otherwise perform a regular type conversion to ensure that all |
| 2138 |
-- relevant checks are installed. |
| 2139 |
|
| 2140 |
else |
| 2141 |
Rewrite (Item, Convert_To (Formal_Typ, Relocate_Node (Item))); |
| 2142 |
end if; |
| 2143 |
|
| 2144 |
-- For untagged derived types set Assignment_OK, to prevent |
| 2145 |
-- copies from being created when the unchecked conversion |
| 2146 |
-- is expanded (which would happen in Remove_Side_Effects |
| 2147 |
-- if Expand_N_Unchecked_Conversion were allowed to call |
| 2148 |
-- Force_Evaluation). The copy could violate Ada semantics in |
| 2149 |
-- cases such as an actual that is an out parameter. Note that |
| 2150 |
-- this approach is also used in exp_ch7 for calls to controlled |
| 2151 |
-- type operations to prevent problems with actuals wrapped in |
| 2152 |
-- unchecked conversions. |
| 2153 |
|
| 2154 |
if Is_Untagged_Derivation (Etype (Expression (Item))) then |
| 2155 |
Set_Assignment_OK (Item); |
| 2156 |
end if; |
| 2157 |
end if; |
| 2158 |
|
| 2159 |
-- The stream operation to call might be a renaming created by an |
| 2160 |
-- attribute definition clause, and might not be frozen yet. Ensure |
| 2161 |
-- that it has the necessary extra formals. |
| 2162 |
|
| 2163 |
if not Is_Frozen (Pname) then |
| 2164 |
Create_Extra_Formals (Pname); |
| 2165 |
end if; |
| 2166 |
|
| 2167 |
-- And now rewrite the call |
| 2168 |
|
| 2169 |
Rewrite (N, |
| 2170 |
Make_Procedure_Call_Statement (Loc, |
| 2171 |
Name => New_Occurrence_Of (Pname, Loc), |
| 2172 |
Parameter_Associations => Exprs)); |
| 2173 |
|
| 2174 |
Analyze (N); |
| 2175 |
end Rewrite_Attribute_Proc_Call; |
| 2176 |
|
| 2177 |
Typ : constant Entity_Id := Etype (N); |
| 2178 |
Btyp : constant Entity_Id := Base_Type (Typ); |
| 2179 |
Ptyp : constant Entity_Id := Etype (Pref); |
| 2180 |
Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N)); |
| 2181 |
|
| 2182 |
-- Start of processing for Expand_N_Attribute_Reference |
| 2183 |
|
| 2184 |
begin |
| 2185 |
-- Do required validity checking, if enabled. |
| 2186 |
-- |
| 2187 |
-- Skip check for output parameters of an Asm instruction (since their |
| 2188 |
-- valuesare not set till after the attribute has been elaborated), |
| 2189 |
-- for the arguments of a 'Read attribute reference (since the |
| 2190 |
-- scalar argument is an OUT scalar) and for the arguments of a |
| 2191 |
-- 'Has_Same_Storage or 'Overlaps_Storage attribute reference (which not |
| 2192 |
-- considered to be reads of their prefixes and expressions, see |
| 2193 |
-- RM 13.3(73.10/3)). |
| 2194 |
|
| 2195 |
if Validity_Checks_On and then Validity_Check_Operands |
| 2196 |
and then Id /= Attribute_Asm_Output |
| 2197 |
and then Id /= Attribute_Read |
| 2198 |
and then Id /= Attribute_Has_Same_Storage |
| 2199 |
and then Id /= Attribute_Overlaps_Storage |
| 2200 |
then |
| 2201 |
declare |
| 2202 |
Expr : Node_Id; |
| 2203 |
begin |
| 2204 |
Expr := First (Expressions (N)); |
| 2205 |
while Present (Expr) loop |
| 2206 |
Ensure_Valid (Expr); |
| 2207 |
Next (Expr); |
| 2208 |
end loop; |
| 2209 |
end; |
| 2210 |
end if; |
| 2211 |
|
| 2212 |
-- Ada 2005 (AI-318-02): If attribute prefix is a call to a build-in- |
| 2213 |
-- place function, then a temporary return object needs to be created |
| 2214 |
-- and access to it must be passed to the function. |
| 2215 |
|
| 2216 |
if Is_Build_In_Place_Function_Call (Pref) then |
| 2217 |
|
| 2218 |
-- If attribute is 'Old, the context is a postcondition, and |
| 2219 |
-- the temporary must go in the corresponding subprogram, not |
| 2220 |
-- the postcondition function or any created blocks, as when |
| 2221 |
-- the attribute appears in a quantified expression. This is |
| 2222 |
-- handled below in the expansion of the attribute. |
| 2223 |
|
| 2224 |
if Attribute_Name (Parent (Pref)) = Name_Old then |
| 2225 |
null; |
| 2226 |
else |
| 2227 |
Make_Build_In_Place_Call_In_Anonymous_Context (Pref); |
| 2228 |
end if; |
| 2229 |
|
| 2230 |
-- Ada 2005 (AI-318-02): Specialization of the previous case for prefix |
| 2231 |
-- containing build-in-place function calls whose returned object covers |
| 2232 |
-- interface types. |
| 2233 |
|
| 2234 |
elsif Present (Unqual_BIP_Iface_Function_Call (Pref)) then |
| 2235 |
Make_Build_In_Place_Iface_Call_In_Anonymous_Context (Pref); |
| 2236 |
end if; |
| 2237 |
|
| 2238 |
-- If prefix is a protected type name, this is a reference to the |
| 2239 |
-- current instance of the type. For a component definition, nothing |
| 2240 |
-- to do (expansion will occur in the init proc). In other contexts, |
| 2241 |
-- rewrite into reference to current instance. |
| 2242 |
|
| 2243 |
if Is_Protected_Self_Reference (Pref) |
| 2244 |
and then not |
| 2245 |
(Nkind (Parent (N)) in N_Index_Or_Discriminant_Constraint |
| 2246 |
| N_Discriminant_Association |
| 2247 |
and then Nkind (Parent (Parent (Parent (Parent (N))))) = |
| 2248 |
N_Component_Definition) |
| 2249 |
|
| 2250 |
-- No action needed for these attributes since the current instance |
| 2251 |
-- will be rewritten to be the name of the _object parameter |
| 2252 |
-- associated with the enclosing protected subprogram (see below). |
| 2253 |
|
| 2254 |
and then Id /= Attribute_Access |
| 2255 |
and then Id /= Attribute_Unchecked_Access |
| 2256 |
and then Id /= Attribute_Unrestricted_Access |
| 2257 |
then |
| 2258 |
Rewrite (Pref, Concurrent_Ref (Pref)); |
| 2259 |
Analyze (Pref); |
| 2260 |
end if; |
| 2261 |
|
| 2262 |
-- Remaining processing depends on specific attribute |
| 2263 |
|
| 2264 |
-- Note: individual sections of the following case statement are |
| 2265 |
-- allowed to assume there is no code after the case statement, and |
| 2266 |
-- are legitimately allowed to execute return statements if they have |
| 2267 |
-- nothing more to do. |
| 2268 |
|
| 2269 |
case Id is |
| 2270 |
|
| 2271 |
-- Internal attributes used to deal with Ada 2012 delayed aspects. These |
| 2272 |
-- were already rejected by the parser. Thus they shouldn't appear here. |
| 2273 |
|
| 2274 |
when Internal_Attribute_Id => |
| 2275 |
raise Program_Error; |
| 2276 |
|
| 2277 |
------------ |
| 2278 |
-- Access -- |
| 2279 |
------------ |
| 2280 |
|
| 2281 |
when Attribute_Access |
| 2282 |
| Attribute_Unchecked_Access |
| 2283 |
| Attribute_Unrestricted_Access |
| 2284 |
=> |
| 2285 |
Access_Cases : declare |
| 2286 |
Ref_Object : constant Node_Id := Get_Referenced_Object (Pref); |
| 2287 |
Btyp_DDT : Entity_Id; |
| 2288 |
|
| 2289 |
procedure Add_Implicit_Interface_Type_Conversion; |
| 2290 |
-- Ada 2005 (AI-251): The designated type is an interface type; |
| 2291 |
-- add an implicit type conversion to force the displacement of |
| 2292 |
-- the pointer to reference the secondary dispatch table. |
| 2293 |
|
| 2294 |
function Enclosing_Object (N : Node_Id) return Node_Id; |
| 2295 |
-- If N denotes a compound name (selected component, indexed |
| 2296 |
-- component, or slice), returns the name of the outermost such |
| 2297 |
-- enclosing object. Otherwise returns N. If the object is a |
| 2298 |
-- renaming, then the renamed object is returned. |
| 2299 |
|
| 2300 |
-------------------------------------------- |
| 2301 |
-- Add_Implicit_Interface_Type_Conversion -- |
| 2302 |
-------------------------------------------- |
| 2303 |
|
| 2304 |
procedure Add_Implicit_Interface_Type_Conversion is |
| 2305 |
begin |
| 2306 |
pragma Assert (Is_Interface (Btyp_DDT)); |
| 2307 |
|
| 2308 |
-- Handle cases were no action is required. |
| 2309 |
|
| 2310 |
if not Comes_From_Source (N) |
| 2311 |
and then not Comes_From_Source (Ref_Object) |
| 2312 |
and then (Nkind (Ref_Object) not in N_Has_Chars |
| 2313 |
or else Chars (Ref_Object) /= Name_uInit) |
| 2314 |
then |
| 2315 |
return; |
| 2316 |
end if; |
| 2317 |
|
| 2318 |
-- Common case |
| 2319 |
|
| 2320 |
if Nkind (Ref_Object) /= N_Explicit_Dereference then |
| 2321 |
|
| 2322 |
-- No implicit conversion required if types match, or if |
| 2323 |
-- the prefix is the class_wide_type of the interface. In |
| 2324 |
-- either case passing an object of the interface type has |
| 2325 |
-- already set the pointer correctly. |
| 2326 |
|
| 2327 |
if Btyp_DDT = Etype (Ref_Object) |
| 2328 |
or else |
| 2329 |
(Is_Class_Wide_Type (Etype (Ref_Object)) |
| 2330 |
and then |
| 2331 |
Class_Wide_Type (Btyp_DDT) = Etype (Ref_Object)) |
| 2332 |
then |
| 2333 |
null; |
| 2334 |
|
| 2335 |
else |
| 2336 |
Rewrite (Prefix (N), |
| 2337 |
Convert_To (Btyp_DDT, |
| 2338 |
New_Copy_Tree (Prefix (N)))); |
| 2339 |
|
| 2340 |
Analyze_And_Resolve (Prefix (N), Btyp_DDT); |
| 2341 |
end if; |
| 2342 |
|
| 2343 |
-- When the object is an explicit dereference, convert the |
| 2344 |
-- dereference's prefix. |
| 2345 |
|
| 2346 |
else |
| 2347 |
declare |
| 2348 |
Obj_DDT : constant Entity_Id := |
| 2349 |
Base_Type |
| 2350 |
(Directly_Designated_Type |
| 2351 |
(Etype (Prefix (Ref_Object)))); |
| 2352 |
begin |
| 2353 |
-- No implicit conversion required if designated types |
| 2354 |
-- match. |
| 2355 |
|
| 2356 |
if Obj_DDT /= Btyp_DDT |
| 2357 |
and then not (Is_Class_Wide_Type (Obj_DDT) |
| 2358 |
and then Etype (Obj_DDT) = Btyp_DDT) |
| 2359 |
then |
| 2360 |
Rewrite (N, |
| 2361 |
Convert_To (Typ, |
| 2362 |
New_Copy_Tree (Prefix (Ref_Object)))); |
| 2363 |
Analyze_And_Resolve (N, Typ); |
| 2364 |
end if; |
| 2365 |
end; |
| 2366 |
end if; |
| 2367 |
end Add_Implicit_Interface_Type_Conversion; |
| 2368 |
|
| 2369 |
---------------------- |
| 2370 |
-- Enclosing_Object -- |
| 2371 |
---------------------- |
| 2372 |
|
| 2373 |
function Enclosing_Object (N : Node_Id) return Node_Id is |
| 2374 |
Obj_Name : Node_Id; |
| 2375 |
|
| 2376 |
begin |
| 2377 |
Obj_Name := N; |
| 2378 |
while Nkind (Obj_Name) in N_Selected_Component |
| 2379 |
| N_Indexed_Component |
| 2380 |
| N_Slice |
| 2381 |
loop |
| 2382 |
Obj_Name := Prefix (Obj_Name); |
| 2383 |
end loop; |
| 2384 |
|
| 2385 |
return Get_Referenced_Object (Obj_Name); |
| 2386 |
end Enclosing_Object; |
| 2387 |
|
| 2388 |
-- Local declarations |
| 2389 |
|
| 2390 |
Enc_Object : Node_Id := Enclosing_Object (Ref_Object); |
| 2391 |
|
| 2392 |
-- Start of processing for Access_Cases |
| 2393 |
|
| 2394 |
begin |
| 2395 |
Btyp_DDT := Designated_Type (Btyp); |
| 2396 |
|
| 2397 |
-- When Enc_Object is a view conversion then RM 3.10.2 (9) |
| 2398 |
-- applies and we obtain the expression being converted. |
| 2399 |
-- Otherwise we do not dig any deeper since a conversion |
| 2400 |
-- might generate a copy and we can't assume it will be as |
| 2401 |
-- long-lived as the original. |
| 2402 |
|
| 2403 |
while Nkind (Enc_Object) = N_Type_Conversion |
| 2404 |
and then Is_View_Conversion (Enc_Object) |
| 2405 |
loop |
| 2406 |
Enc_Object := Expression (Enc_Object); |
| 2407 |
end loop; |
| 2408 |
|
| 2409 |
-- Handle designated types that come from the limited view |
| 2410 |
|
| 2411 |
if From_Limited_With (Btyp_DDT) |
| 2412 |
and then Has_Non_Limited_View (Btyp_DDT) |
| 2413 |
then |
| 2414 |
Btyp_DDT := Non_Limited_View (Btyp_DDT); |
| 2415 |
end if; |
| 2416 |
|
| 2417 |
-- In order to improve the text of error messages, the designated |
| 2418 |
-- type of access-to-subprogram itypes is set by the semantics as |
| 2419 |
-- the associated subprogram entity (see sem_attr). Now we replace |
| 2420 |
-- such node with the proper E_Subprogram_Type itype. |
| 2421 |
|
| 2422 |
if Id = Attribute_Unrestricted_Access |
| 2423 |
and then Is_Subprogram (Directly_Designated_Type (Typ)) |
| 2424 |
then |
| 2425 |
-- The following conditions ensure that this special management |
| 2426 |
-- is done only for "Address!(Prim'Unrestricted_Access)" nodes. |
| 2427 |
-- At this stage other cases in which the designated type is |
| 2428 |
-- still a subprogram (instead of an E_Subprogram_Type) are |
| 2429 |
-- wrong because the semantics must have overridden the type of |
| 2430 |
-- the node with the type imposed by the context. |
| 2431 |
|
| 2432 |
if Nkind (Parent (N)) = N_Unchecked_Type_Conversion |
| 2433 |
and then Is_RTE (Etype (Parent (N)), RE_Prim_Ptr) |
| 2434 |
then |
| 2435 |
Set_Etype (N, RTE (RE_Prim_Ptr)); |
| 2436 |
|
| 2437 |
else |
| 2438 |
declare |
| 2439 |
Subp : constant Entity_Id := |
| 2440 |
Directly_Designated_Type (Typ); |
| 2441 |
Etyp : Entity_Id; |
| 2442 |
Extra : Entity_Id := Empty; |
| 2443 |
New_Formal : Entity_Id; |
| 2444 |
Old_Formal : Entity_Id := First_Formal (Subp); |
| 2445 |
Subp_Typ : Entity_Id; |
| 2446 |
|
| 2447 |
begin |
| 2448 |
Subp_Typ := Create_Itype (E_Subprogram_Type, N); |
| 2449 |
Copy_Strub_Mode (Subp_Typ, Subp); |
| 2450 |
Set_Etype (Subp_Typ, Etype (Subp)); |
| 2451 |
Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp)); |
| 2452 |
|
| 2453 |
if Present (Old_Formal) then |
| 2454 |
New_Formal := New_Copy (Old_Formal); |
| 2455 |
Set_First_Entity (Subp_Typ, New_Formal); |
| 2456 |
|
| 2457 |
loop |
| 2458 |
Set_Scope (New_Formal, Subp_Typ); |
| 2459 |
Etyp := Etype (New_Formal); |
| 2460 |
|
| 2461 |
-- Handle itypes. There is no need to duplicate |
| 2462 |
-- here the itypes associated with record types |
| 2463 |
-- (i.e the implicit full view of private types). |
| 2464 |
|
| 2465 |
if Is_Itype (Etyp) |
| 2466 |
and then Ekind (Base_Type (Etyp)) /= E_Record_Type |
| 2467 |
then |
| 2468 |
Extra := New_Copy (Etyp); |
| 2469 |
Set_Parent (Extra, New_Formal); |
| 2470 |
Set_Etype (New_Formal, Extra); |
| 2471 |
Set_Scope (Extra, Subp_Typ); |
| 2472 |
end if; |
| 2473 |
|
| 2474 |
Extra := New_Formal; |
| 2475 |
Next_Formal (Old_Formal); |
| 2476 |
exit when No (Old_Formal); |
| 2477 |
|
| 2478 |
Link_Entities (New_Formal, New_Copy (Old_Formal)); |
| 2479 |
Next_Entity (New_Formal); |
| 2480 |
end loop; |
| 2481 |
|
| 2482 |
Unlink_Next_Entity (New_Formal); |
| 2483 |
Set_Last_Entity (Subp_Typ, Extra); |
| 2484 |
end if; |
| 2485 |
|
| 2486 |
-- Now that the explicit formals have been duplicated, |
| 2487 |
-- any extra formals needed by the subprogram must be |
| 2488 |
-- created. |
| 2489 |
|
| 2490 |
if Present (Extra) then |
| 2491 |
Set_Extra_Formal (Extra, Empty); |
| 2492 |
end if; |
| 2493 |
|
| 2494 |
Create_Extra_Formals (Subp_Typ); |
| 2495 |
Set_Directly_Designated_Type (Typ, Subp_Typ); |
| 2496 |
end; |
| 2497 |
end if; |
| 2498 |
end if; |
| 2499 |
|
| 2500 |
if Is_Access_Protected_Subprogram_Type (Btyp) then |
| 2501 |
Expand_Access_To_Protected_Op (N, Pref, Typ); |
| 2502 |
|
| 2503 |
elsif Is_Access_Subprogram_Type (Btyp) |
| 2504 |
and then Is_Entity_Name (Pref) |
| 2505 |
then |
| 2506 |
-- If prefix is a subprogram that has class-wide preconditions |
| 2507 |
-- and an indirect-call wrapper (ICW) of the subprogram is |
| 2508 |
-- available then replace the prefix by the ICW. |
| 2509 |
|
| 2510 |
if Present (Class_Preconditions (Entity (Pref))) |
| 2511 |
and then Present (Indirect_Call_Wrapper (Entity (Pref))) |
| 2512 |
then |
| 2513 |
Rewrite (Pref, |
| 2514 |
New_Occurrence_Of |
| 2515 |
(Indirect_Call_Wrapper (Entity (Pref)), Loc)); |
| 2516 |
Analyze_And_Resolve (N, Typ); |
| 2517 |
end if; |
| 2518 |
|
| 2519 |
-- Ensure the availability of the extra formals to check that |
| 2520 |
-- they match. |
| 2521 |
|
| 2522 |
if not Is_Frozen (Entity (Pref)) |
| 2523 |
or else From_Limited_With (Etype (Entity (Pref))) |
| 2524 |
then |
| 2525 |
Create_Extra_Formals (Entity (Pref)); |
| 2526 |
end if; |
| 2527 |
|
| 2528 |
if not Is_Frozen (Btyp_DDT) |
| 2529 |
or else From_Limited_With (Etype (Btyp_DDT)) |
| 2530 |
then |
| 2531 |
Create_Extra_Formals (Btyp_DDT); |
| 2532 |
end if; |
| 2533 |
|
| 2534 |
pragma Assert |
| 2535 |
(Extra_Formals_Match_OK |
| 2536 |
(E => Entity (Pref), Ref_E => Btyp_DDT)); |
| 2537 |
|
| 2538 |
-- If prefix is a type name, this is a reference to the current |
| 2539 |
-- instance of the type, within its initialization procedure. |
| 2540 |
|
| 2541 |
elsif Is_Entity_Name (Pref) |
| 2542 |
and then Is_Type (Entity (Pref)) |
| 2543 |
then |
| 2544 |
declare |
| 2545 |
Par : Node_Id; |
| 2546 |
Formal : Entity_Id; |
| 2547 |
|
| 2548 |
begin |
| 2549 |
-- If the current instance name denotes a task type, then |
| 2550 |
-- the access attribute is rewritten to be the name of the |
| 2551 |
-- "_task" parameter associated with the task type's task |
| 2552 |
-- procedure. An unchecked conversion is applied to ensure |
| 2553 |
-- a type match in cases of expander-generated calls (e.g. |
| 2554 |
-- init procs). |
| 2555 |
|
| 2556 |
if Is_Task_Type (Entity (Pref)) then |
| 2557 |
Formal := |
| 2558 |
First_Entity (Get_Task_Body_Procedure (Entity (Pref))); |
| 2559 |
while Present (Formal) loop |
| 2560 |
exit when Chars (Formal) = Name_uTask; |
| 2561 |
Next_Entity (Formal); |
| 2562 |
end loop; |
| 2563 |
|
| 2564 |
pragma Assert (Present (Formal)); |
| 2565 |
|
| 2566 |
Rewrite (N, |
| 2567 |
Unchecked_Convert_To (Typ, |
| 2568 |
New_Occurrence_Of (Formal, Loc))); |
| 2569 |
Set_Etype (N, Typ); |
| 2570 |
|
| 2571 |
elsif Is_Protected_Type (Entity (Pref)) then |
| 2572 |
|
| 2573 |
-- No action needed for current instance located in a |
| 2574 |
-- component definition (expansion will occur in the |
| 2575 |
-- init proc) |
| 2576 |
|
| 2577 |
if Is_Protected_Type (Current_Scope) then |
| 2578 |
null; |
| 2579 |
|
| 2580 |
-- If the current instance reference is located in a |
| 2581 |
-- protected subprogram or entry then rewrite the access |
| 2582 |
-- attribute to be the name of the "_object" parameter. |
| 2583 |
-- An unchecked conversion is applied to ensure a type |
| 2584 |
-- match in cases of expander-generated calls (e.g. init |
| 2585 |
-- procs). |
| 2586 |
|
| 2587 |
-- The code may be nested in a block, so find enclosing |
| 2588 |
-- scope that is a protected operation. |
| 2589 |
|
| 2590 |
else |
| 2591 |
declare |
| 2592 |
Subp : Entity_Id; |
| 2593 |
|
| 2594 |
begin |
| 2595 |
Subp := Current_Scope; |
| 2596 |
while Ekind (Subp) in E_Loop | E_Block loop |
| 2597 |
Subp := Scope (Subp); |
| 2598 |
end loop; |
| 2599 |
|
| 2600 |
Formal := |
| 2601 |
First_Entity |
| 2602 |
(Protected_Body_Subprogram (Subp)); |
| 2603 |
|
| 2604 |
-- For a protected subprogram the _Object parameter |
| 2605 |
-- is the protected record, so we create an access |
| 2606 |
-- to it. The _Object parameter of an entry is an |
| 2607 |
-- address. |
| 2608 |
|
| 2609 |
if Ekind (Subp) = E_Entry then |
| 2610 |
Rewrite (N, |
| 2611 |
Unchecked_Convert_To (Typ, |
| 2612 |
New_Occurrence_Of (Formal, Loc))); |
| 2613 |
Set_Etype (N, Typ); |
| 2614 |
|
| 2615 |
else |
| 2616 |
Rewrite (N, |
| 2617 |
Unchecked_Convert_To (Typ, |
| 2618 |
Make_Attribute_Reference (Loc, |
| 2619 |
Attribute_Name => Name_Unrestricted_Access, |
| 2620 |
Prefix => |
| 2621 |
New_Occurrence_Of (Formal, Loc)))); |
| 2622 |
Analyze_And_Resolve (N); |
| 2623 |
end if; |
| 2624 |
end; |
| 2625 |
end if; |
| 2626 |
|
| 2627 |
-- The expression must appear in a default expression, |
| 2628 |
-- (which in the initialization procedure is the right-hand |
| 2629 |
-- side of an assignment), and not in a discriminant |
| 2630 |
-- constraint. |
| 2631 |
|
| 2632 |
else |
| 2633 |
Par := Parent (N); |
| 2634 |
while Present (Par) loop |
| 2635 |
exit when Nkind (Par) = N_Assignment_Statement; |
| 2636 |
|
| 2637 |
if Nkind (Par) = N_Component_Declaration then |
| 2638 |
return; |
| 2639 |
end if; |
| 2640 |
|
| 2641 |
Par := Parent (Par); |
| 2642 |
end loop; |
| 2643 |
|
| 2644 |
if Present (Par) then |
| 2645 |
Rewrite (N, |
| 2646 |
Make_Attribute_Reference (Loc, |
| 2647 |
Prefix => Make_Identifier (Loc, Name_uInit), |
| 2648 |
Attribute_Name => Attribute_Name (N))); |
| 2649 |
|
| 2650 |
Analyze_And_Resolve (N, Typ); |
| 2651 |
end if; |
| 2652 |
end if; |
| 2653 |
end; |
| 2654 |
|
| 2655 |
-- If the prefix of an Access attribute is a dereference of an |
| 2656 |
-- access parameter (or a renaming of such a dereference, or a |
| 2657 |
-- subcomponent of such a dereference) and the context is a |
| 2658 |
-- general access type (including the type of an object or |
| 2659 |
-- component with an access_definition, but not the anonymous |
| 2660 |
-- type of an access parameter or access discriminant), then |
| 2661 |
-- apply an accessibility check to the access parameter. We used |
| 2662 |
-- to rewrite the access parameter as a type conversion, but that |
| 2663 |
-- could only be done if the immediate prefix of the Access |
| 2664 |
-- attribute was the dereference, and didn't handle cases where |
| 2665 |
-- the attribute is applied to a subcomponent of the dereference, |
| 2666 |
-- since there's generally no available, appropriate access type |
| 2667 |
-- to convert to in that case. The attribute is passed as the |
| 2668 |
-- point to insert the check, because the access parameter may |
| 2669 |
-- come from a renaming, possibly in a different scope, and the |
| 2670 |
-- check must be associated with the attribute itself. |
| 2671 |
|
| 2672 |
elsif Id = Attribute_Access |
| 2673 |
and then Nkind (Enc_Object) = N_Explicit_Dereference |
| 2674 |
and then Is_Entity_Name (Prefix (Enc_Object)) |
| 2675 |
and then (Ekind (Btyp) = E_General_Access_Type |
| 2676 |
or else Is_Local_Anonymous_Access (Btyp)) |
| 2677 |
and then Is_Formal (Entity (Prefix (Enc_Object))) |
| 2678 |
and then Ekind (Etype (Entity (Prefix (Enc_Object)))) |
| 2679 |
= E_Anonymous_Access_Type |
| 2680 |
and then Present (Extra_Accessibility |
| 2681 |
(Entity (Prefix (Enc_Object)))) |
| 2682 |
and then not No_Dynamic_Accessibility_Checks_Enabled (Enc_Object) |
| 2683 |
then |
| 2684 |
Apply_Accessibility_Check (Prefix (Enc_Object), Typ, N); |
| 2685 |
|
| 2686 |
-- Ada 2005 (AI-251): If the designated type is an interface we |
| 2687 |
-- add an implicit conversion to force the displacement of the |
| 2688 |
-- pointer to reference the secondary dispatch table. |
| 2689 |
|
| 2690 |
if Is_Interface (Btyp_DDT) then |
| 2691 |
Add_Implicit_Interface_Type_Conversion; |
| 2692 |
end if; |
| 2693 |
|
| 2694 |
-- Ada 2005 (AI-251): If the designated type is an interface we |
| 2695 |
-- add an implicit conversion to force the displacement of the |
| 2696 |
-- pointer to reference the secondary dispatch table. |
| 2697 |
|
| 2698 |
elsif Is_Interface (Btyp_DDT) then |
| 2699 |
Add_Implicit_Interface_Type_Conversion; |
| 2700 |
end if; |
| 2701 |
end Access_Cases; |
| 2702 |
|
| 2703 |
-------------- |
| 2704 |
-- Adjacent -- |
| 2705 |
-------------- |
| 2706 |
|
| 2707 |
-- Transforms 'Adjacent into a call to the floating-point attribute |
| 2708 |
-- function Adjacent in Fat_xxx (where xxx is the root type) |
| 2709 |
|
| 2710 |
when Attribute_Adjacent => |
| 2711 |
Expand_Fpt_Attribute_RR (N); |
| 2712 |
|
| 2713 |
------------- |
| 2714 |
-- Address -- |
| 2715 |
------------- |
| 2716 |
|
| 2717 |
when Attribute_Address => Address : declare |
| 2718 |
Task_Proc : Entity_Id; |
| 2719 |
|
| 2720 |
function Is_Unnested_Component_Init (N : Node_Id) return Boolean; |
| 2721 |
-- Returns True if N is being used to initialize a component of |
| 2722 |
-- an activation record object where the component corresponds to |
| 2723 |
-- the object denoted by the prefix of the attribute N. |
| 2724 |
|
| 2725 |
function Is_Unnested_Component_Init (N : Node_Id) return Boolean is |
| 2726 |
begin |
| 2727 |
return Present (Parent (N)) |
| 2728 |
and then Nkind (Parent (N)) = N_Assignment_Statement |
| 2729 |
and then Is_Entity_Name (Pref) |
| 2730 |
and then Present (Activation_Record_Component (Entity (Pref))) |
| 2731 |
and then Nkind (Name (Parent (N))) = N_Selected_Component |
| 2732 |
and then Entity (Selector_Name (Name (Parent (N)))) = |
| 2733 |
Activation_Record_Component (Entity (Pref)); |
| 2734 |
end Is_Unnested_Component_Init; |
| 2735 |
|
| 2736 |
-- Start of processing for Address |
| 2737 |
|
| 2738 |
begin |
| 2739 |
-- If the prefix is a task or a task type, the useful address is that |
| 2740 |
-- of the procedure for the task body, i.e. the actual program unit. |
| 2741 |
-- We replace the original entity with that of the procedure. |
| 2742 |
|
| 2743 |
if Is_Entity_Name (Pref) |
| 2744 |
and then Is_Task_Type (Entity (Pref)) |
| 2745 |
then |
| 2746 |
Task_Proc := Next_Entity (Root_Type (Ptyp)); |
| 2747 |
|
| 2748 |
while Present (Task_Proc) loop |
| 2749 |
exit when Ekind (Task_Proc) = E_Procedure |
| 2750 |
and then Etype (First_Formal (Task_Proc)) = |
| 2751 |
Corresponding_Record_Type (Ptyp); |
| 2752 |
Next_Entity (Task_Proc); |
| 2753 |
end loop; |
| 2754 |
|
| 2755 |
if Present (Task_Proc) then |
| 2756 |
Set_Entity (Pref, Task_Proc); |
| 2757 |
Set_Etype (Pref, Etype (Task_Proc)); |
| 2758 |
end if; |
| 2759 |
|
| 2760 |
-- Similarly, the address of a protected operation is the address |
| 2761 |
-- of the corresponding protected body, regardless of the protected |
| 2762 |
-- object from which it is selected. |
| 2763 |
|
| 2764 |
elsif Nkind (Pref) = N_Selected_Component |
| 2765 |
and then Is_Subprogram (Entity (Selector_Name (Pref))) |
| 2766 |
and then Is_Protected_Type (Scope (Entity (Selector_Name (Pref)))) |
| 2767 |
then |
| 2768 |
Rewrite (Pref, |
| 2769 |
New_Occurrence_Of ( |
| 2770 |
External_Subprogram (Entity (Selector_Name (Pref))), Loc)); |
| 2771 |
|
| 2772 |
elsif Nkind (Pref) = N_Explicit_Dereference |
| 2773 |
and then Ekind (Ptyp) = E_Subprogram_Type |
| 2774 |
and then Convention (Ptyp) = Convention_Protected |
| 2775 |
then |
| 2776 |
-- The prefix is be a dereference of an access_to_protected_ |
| 2777 |
-- subprogram. The desired address is the second component of |
| 2778 |
-- the record that represents the access. |
| 2779 |
|
| 2780 |
declare |
| 2781 |
Addr : constant Entity_Id := Etype (N); |
| 2782 |
Ptr : constant Node_Id := Prefix (Pref); |
| 2783 |
T : constant Entity_Id := |
| 2784 |
Equivalent_Type (Base_Type (Etype (Ptr))); |
| 2785 |
|
| 2786 |
begin |
| 2787 |
Rewrite (N, |
| 2788 |
Unchecked_Convert_To (Addr, |
| 2789 |
Make_Selected_Component (Loc, |
| 2790 |
Prefix => Unchecked_Convert_To (T, Ptr), |
| 2791 |
Selector_Name => New_Occurrence_Of ( |
| 2792 |
Next_Entity (First_Entity (T)), Loc)))); |
| 2793 |
|
| 2794 |
Analyze_And_Resolve (N, Addr); |
| 2795 |
end; |
| 2796 |
|
| 2797 |
-- 'Address is an actual parameter of the call to the implicit |
| 2798 |
-- subprogram To_Pointer instantiated with a class-wide interface |
| 2799 |
-- type; its expansion requires adding an implicit type conversion |
| 2800 |
-- to force displacement of the "this" pointer. |
| 2801 |
|
| 2802 |
elsif Tagged_Type_Expansion |
| 2803 |
and then Nkind (Parent (N)) = N_Function_Call |
| 2804 |
and then Nkind (Name (Parent (N))) in N_Has_Entity |
| 2805 |
and then Is_Intrinsic_Subprogram (Entity (Name (Parent (N)))) |
| 2806 |
and then Chars (Entity (Name (Parent (N)))) = Name_To_Pointer |
| 2807 |
and then Is_Interface (Designated_Type (Etype (Parent (N)))) |
| 2808 |
and then Is_Class_Wide_Type (Designated_Type (Etype (Parent (N)))) |
| 2809 |
then |
| 2810 |
declare |
| 2811 |
Iface_Typ : constant Entity_Id := |
| 2812 |
Designated_Type (Etype (Parent (N))); |
| 2813 |
begin |
| 2814 |
Rewrite (Pref, Convert_To (Iface_Typ, Relocate_Node (Pref))); |
| 2815 |
Analyze_And_Resolve (Pref, Iface_Typ); |
| 2816 |
return; |
| 2817 |
end; |
| 2818 |
|
| 2819 |
-- Ada 2005 (AI-251): Class-wide interface objects are always |
| 2820 |
-- "displaced" to reference the tag associated with the interface |
| 2821 |
-- type. In order to obtain the real address of such objects we |
| 2822 |
-- generate a call to a run-time subprogram that returns the base |
| 2823 |
-- address of the object. This call is not generated in cases where |
| 2824 |
-- the attribute is being used to initialize a component of an |
| 2825 |
-- activation record object where the component corresponds to |
| 2826 |
-- prefix of the attribute (for back ends that require "unnesting" |
| 2827 |
-- of nested subprograms), since the address needs to be assigned |
| 2828 |
-- as-is to such components. Likewise for a return object. |
| 2829 |
|
| 2830 |
elsif Tagged_Type_Expansion |
| 2831 |
and then Is_Class_Wide_Type (Ptyp) |
| 2832 |
and then Is_Interface (Underlying_Type (Ptyp)) |
| 2833 |
and then not (Is_Entity_Name (Pref) |
| 2834 |
and then (Is_Subprogram (Entity (Pref)) |
| 2835 |
or else Is_Return_Object (Entity (Pref)))) |
| 2836 |
and then not Is_Unnested_Component_Init (N) |
| 2837 |
then |
| 2838 |
Rewrite (N, |
| 2839 |
Make_Function_Call (Loc, |
| 2840 |
Name => New_Occurrence_Of (RTE (RE_Base_Address), Loc), |
| 2841 |
Parameter_Associations => New_List (Relocate_Node (N)))); |
| 2842 |
Analyze (N); |
| 2843 |
return; |
| 2844 |
end if; |
| 2845 |
|
| 2846 |
-- Deal with packed array reference, other cases are handled by |
| 2847 |
-- the back end. |
| 2848 |
|
| 2849 |
if Involves_Packed_Array_Reference (Pref) then |
| 2850 |
Expand_Packed_Address_Reference (N); |
| 2851 |
end if; |
| 2852 |
end Address; |
| 2853 |
|
| 2854 |
--------------- |
| 2855 |
-- Alignment -- |
| 2856 |
--------------- |
| 2857 |
|
| 2858 |
when Attribute_Alignment => Alignment : declare |
| 2859 |
New_Node : Node_Id; |
| 2860 |
|
| 2861 |
begin |
| 2862 |
-- For class-wide types, X'Class'Alignment is transformed into a |
| 2863 |
-- direct reference to the Alignment of the class type, so that the |
| 2864 |
-- back end does not have to deal with the X'Class'Alignment |
| 2865 |
-- reference. |
| 2866 |
|
| 2867 |
if Is_Entity_Name (Pref) |
| 2868 |
and then Is_Class_Wide_Type (Entity (Pref)) |
| 2869 |
then |
| 2870 |
Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc)); |
| 2871 |
return; |
| 2872 |
|
| 2873 |
-- For x'Alignment applied to an object of a class wide type, |
| 2874 |
-- transform X'Alignment into a call to the predefined primitive |
| 2875 |
-- operation _Alignment applied to X. |
| 2876 |
|
| 2877 |
elsif Is_Class_Wide_Type (Ptyp) then |
| 2878 |
New_Node := |
| 2879 |
Make_Attribute_Reference (Loc, |
| 2880 |
Prefix => Pref, |
| 2881 |
Attribute_Name => Name_Tag); |
| 2882 |
|
| 2883 |
New_Node := Build_Get_Alignment (Loc, New_Node); |
| 2884 |
|
| 2885 |
-- Case where the context is an unchecked conversion to a specific |
| 2886 |
-- integer type. We directly convert from the alignment's type. |
| 2887 |
|
| 2888 |
if Nkind (Parent (N)) = N_Unchecked_Type_Conversion then |
| 2889 |
Rewrite (N, New_Node); |
| 2890 |
Analyze_And_Resolve (N); |
| 2891 |
return; |
| 2892 |
|
| 2893 |
-- Case where the context is a specific integer type with which |
| 2894 |
-- the original attribute was compatible. But the alignment has a |
| 2895 |
-- specific type in a-tags.ads (Standard.Natural) so, in order to |
| 2896 |
-- preserve type compatibility, we must convert explicitly. |
| 2897 |
|
| 2898 |
elsif Typ /= Standard_Natural then |
| 2899 |
New_Node := Convert_To (Typ, New_Node); |
| 2900 |
end if; |
| 2901 |
|
| 2902 |
Rewrite (N, New_Node); |
| 2903 |
Analyze_And_Resolve (N, Typ); |
| 2904 |
return; |
| 2905 |
|
| 2906 |
-- For all other cases, we just have to deal with the case of |
| 2907 |
-- the fact that the result can be universal. |
| 2908 |
|
| 2909 |
else |
| 2910 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 2911 |
end if; |
| 2912 |
end Alignment; |
| 2913 |
|
| 2914 |
--------------------------- |
| 2915 |
-- Asm_Input, Asm_Output -- |
| 2916 |
--------------------------- |
| 2917 |
|
| 2918 |
-- The Asm_Input and Asm_Output attributes are not expanded at this |
| 2919 |
-- stage, but will be eliminated in the expansion of the Asm call, |
| 2920 |
-- see Exp_Intr for details. So the back end will never see them. |
| 2921 |
|
| 2922 |
when Attribute_Asm_Input |
| 2923 |
| Attribute_Asm_Output |
| 2924 |
=> |
| 2925 |
null; |
| 2926 |
|
| 2927 |
--------- |
| 2928 |
-- Bit -- |
| 2929 |
--------- |
| 2930 |
|
| 2931 |
-- We compute this if a packed array reference was present, otherwise we |
| 2932 |
-- leave the computation up to the back end. |
| 2933 |
|
| 2934 |
when Attribute_Bit => |
| 2935 |
if Involves_Packed_Array_Reference (Pref) then |
| 2936 |
Expand_Packed_Bit_Reference (N); |
| 2937 |
else |
| 2938 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 2939 |
end if; |
| 2940 |
|
| 2941 |
------------------ |
| 2942 |
-- Bit_Position -- |
| 2943 |
------------------ |
| 2944 |
|
| 2945 |
-- We leave the computation up to the back end, since we don't know what |
| 2946 |
-- layout will be chosen if no component clause was specified. |
| 2947 |
|
| 2948 |
when Attribute_Bit_Position => |
| 2949 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 2950 |
|
| 2951 |
------------------ |
| 2952 |
-- Body_Version -- |
| 2953 |
------------------ |
| 2954 |
|
| 2955 |
-- A reference to P'Body_Version or P'Version is expanded to |
| 2956 |
|
| 2957 |
-- Vnn : Unsigned; |
| 2958 |
-- pragma Import (C, Vnn, "uuuuT"); |
| 2959 |
-- ... |
| 2960 |
-- Get_Version_String (Vnn) |
| 2961 |
|
| 2962 |
-- where uuuu is the unit name (dots replaced by double underscore) |
| 2963 |
-- and T is B for the cases of Body_Version, or Version applied to a |
| 2964 |
-- subprogram acting as its own spec, and S for Version applied to a |
| 2965 |
-- subprogram spec or package. This sequence of code references the |
| 2966 |
-- unsigned constant created in the main program by the binder. |
| 2967 |
|
| 2968 |
-- A special exception occurs for Standard, where the string returned |
| 2969 |
-- is a copy of the library string in gnatvsn.ads. |
| 2970 |
|
| 2971 |
when Attribute_Body_Version |
| 2972 |
| Attribute_Version |
| 2973 |
=> |
| 2974 |
Version : declare |
| 2975 |
E : constant Entity_Id := Make_Temporary (Loc, 'V'); |
| 2976 |
Pent : Entity_Id; |
| 2977 |
S : String_Id; |
| 2978 |
|
| 2979 |
begin |
| 2980 |
-- If not library unit, get to containing library unit |
| 2981 |
|
| 2982 |
Pent := Entity (Pref); |
| 2983 |
while Pent /= Standard_Standard |
| 2984 |
and then Scope (Pent) /= Standard_Standard |
| 2985 |
and then not Is_Child_Unit (Pent) |
| 2986 |
loop |
| 2987 |
Pent := Scope (Pent); |
| 2988 |
end loop; |
| 2989 |
|
| 2990 |
-- Special case Standard and Standard.ASCII |
| 2991 |
|
| 2992 |
if Pent = Standard_Standard or else Pent = Standard_ASCII then |
| 2993 |
Rewrite (N, |
| 2994 |
Make_String_Literal (Loc, |
| 2995 |
Strval => Verbose_Library_Version)); |
| 2996 |
|
| 2997 |
-- All other cases |
| 2998 |
|
| 2999 |
else |
| 3000 |
-- Build required string constant |
| 3001 |
|
| 3002 |
Get_Name_String (Get_Unit_Name (Pent)); |
| 3003 |
|
| 3004 |
Start_String; |
| 3005 |
for J in 1 .. Name_Len - 2 loop |
| 3006 |
if Name_Buffer (J) = '.' then |
| 3007 |
Store_String_Chars ("__"); |
| 3008 |
else |
| 3009 |
Store_String_Char (Get_Char_Code (Name_Buffer (J))); |
| 3010 |
end if; |
| 3011 |
end loop; |
| 3012 |
|
| 3013 |
-- Case of subprogram acting as its own spec, always use body |
| 3014 |
|
| 3015 |
if Nkind (Declaration_Node (Pent)) in N_Subprogram_Specification |
| 3016 |
and then Nkind (Parent (Declaration_Node (Pent))) = |
| 3017 |
N_Subprogram_Body |
| 3018 |
and then Acts_As_Spec (Parent (Declaration_Node (Pent))) |
| 3019 |
then |
| 3020 |
Store_String_Chars ("B"); |
| 3021 |
|
| 3022 |
-- Case of no body present, always use spec |
| 3023 |
|
| 3024 |
elsif not Unit_Requires_Body (Pent) then |
| 3025 |
Store_String_Chars ("S"); |
| 3026 |
|
| 3027 |
-- Otherwise use B for Body_Version, S for spec |
| 3028 |
|
| 3029 |
elsif Id = Attribute_Body_Version then |
| 3030 |
Store_String_Chars ("B"); |
| 3031 |
else |
| 3032 |
Store_String_Chars ("S"); |
| 3033 |
end if; |
| 3034 |
|
| 3035 |
S := End_String; |
| 3036 |
Lib.Version_Referenced (S); |
| 3037 |
|
| 3038 |
-- Insert the object declaration |
| 3039 |
|
| 3040 |
Insert_Actions (N, New_List ( |
| 3041 |
Make_Object_Declaration (Loc, |
| 3042 |
Defining_Identifier => E, |
| 3043 |
Object_Definition => |
| 3044 |
New_Occurrence_Of (RTE (RE_Unsigned), Loc)))); |
| 3045 |
|
| 3046 |
-- Set entity as imported with correct external name |
| 3047 |
|
| 3048 |
Set_Is_Imported (E); |
| 3049 |
Set_Interface_Name (E, Make_String_Literal (Loc, S)); |
| 3050 |
|
| 3051 |
-- Set entity as internal to ensure proper Sprint output of its |
| 3052 |
-- implicit importation. |
| 3053 |
|
| 3054 |
Set_Is_Internal (E); |
| 3055 |
|
| 3056 |
-- And now rewrite original reference |
| 3057 |
|
| 3058 |
Rewrite (N, |
| 3059 |
Make_Function_Call (Loc, |
| 3060 |
Name => |
| 3061 |
New_Occurrence_Of (RTE (RE_Get_Version_String), Loc), |
| 3062 |
Parameter_Associations => New_List ( |
| 3063 |
New_Occurrence_Of (E, Loc)))); |
| 3064 |
end if; |
| 3065 |
|
| 3066 |
Analyze_And_Resolve (N, RTE (RE_Version_String)); |
| 3067 |
end Version; |
| 3068 |
|
| 3069 |
------------- |
| 3070 |
-- Ceiling -- |
| 3071 |
------------- |
| 3072 |
|
| 3073 |
-- Transforms 'Ceiling into a call to the floating-point attribute |
| 3074 |
-- function Ceiling in Fat_xxx (where xxx is the root type) |
| 3075 |
|
| 3076 |
when Attribute_Ceiling => |
| 3077 |
Expand_Fpt_Attribute_R (N); |
| 3078 |
|
| 3079 |
-------------- |
| 3080 |
-- Callable -- |
| 3081 |
-------------- |
| 3082 |
|
| 3083 |
-- Transforms 'Callable attribute into a call to the Callable function |
| 3084 |
|
| 3085 |
when Attribute_Callable => |
| 3086 |
|
| 3087 |
-- We have an object of a task interface class-wide type as a prefix |
| 3088 |
-- to Callable. Generate: |
| 3089 |
-- callable (Task_Id (Pref._disp_get_task_id)); |
| 3090 |
|
| 3091 |
if Ada_Version >= Ada_2005 |
| 3092 |
and then Ekind (Ptyp) = E_Class_Wide_Type |
| 3093 |
and then Is_Interface (Ptyp) |
| 3094 |
and then Is_Task_Interface (Ptyp) |
| 3095 |
then |
| 3096 |
Rewrite (N, |
| 3097 |
Make_Function_Call (Loc, |
| 3098 |
Name => |
| 3099 |
New_Occurrence_Of (RTE (RE_Callable), Loc), |
| 3100 |
Parameter_Associations => New_List ( |
| 3101 |
Unchecked_Convert_To |
| 3102 |
(RTE (RO_ST_Task_Id), |
| 3103 |
Build_Disp_Get_Task_Id_Call (Pref))))); |
| 3104 |
|
| 3105 |
else |
| 3106 |
Rewrite (N, Build_Call_With_Task (Pref, RTE (RE_Callable))); |
| 3107 |
end if; |
| 3108 |
|
| 3109 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 3110 |
|
| 3111 |
------------ |
| 3112 |
-- Caller -- |
| 3113 |
------------ |
| 3114 |
|
| 3115 |
-- Transforms 'Caller attribute into a call to either the |
| 3116 |
-- Task_Entry_Caller or the Protected_Entry_Caller function. |
| 3117 |
|
| 3118 |
when Attribute_Caller => Caller : declare |
| 3119 |
Id_Kind : constant Entity_Id := RTE (RO_AT_Task_Id); |
| 3120 |
Ent : constant Entity_Id := Entity (Pref); |
| 3121 |
Conctype : constant Entity_Id := Scope (Ent); |
| 3122 |
Nest_Depth : Nat := 0; |
| 3123 |
Name : Node_Id; |
| 3124 |
S : Entity_Id; |
| 3125 |
|
| 3126 |
begin |
| 3127 |
-- Protected case |
| 3128 |
|
| 3129 |
if Is_Protected_Type (Conctype) then |
| 3130 |
case Corresponding_Runtime_Package (Conctype) is |
| 3131 |
when System_Tasking_Protected_Objects_Entries => |
| 3132 |
Name := |
| 3133 |
New_Occurrence_Of |
| 3134 |
(RTE (RE_Protected_Entry_Caller), Loc); |
| 3135 |
|
| 3136 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 3137 |
Name := |
| 3138 |
New_Occurrence_Of |
| 3139 |
(RTE (RE_Protected_Single_Entry_Caller), Loc); |
| 3140 |
|
| 3141 |
when others => |
| 3142 |
raise Program_Error; |
| 3143 |
end case; |
| 3144 |
|
| 3145 |
Rewrite (N, |
| 3146 |
Unchecked_Convert_To (Id_Kind, |
| 3147 |
Make_Function_Call (Loc, |
| 3148 |
Name => Name, |
| 3149 |
Parameter_Associations => New_List ( |
| 3150 |
New_Occurrence_Of |
| 3151 |
(Find_Protection_Object (Current_Scope), Loc))))); |
| 3152 |
|
| 3153 |
-- Task case |
| 3154 |
|
| 3155 |
else |
| 3156 |
-- Determine the nesting depth of the E'Caller attribute, that |
| 3157 |
-- is, how many accept statements are nested within the accept |
| 3158 |
-- statement for E at the point of E'Caller. The runtime uses |
| 3159 |
-- this depth to find the specified entry call. |
| 3160 |
|
| 3161 |
for J in reverse 0 .. Scope_Stack.Last loop |
| 3162 |
S := Scope_Stack.Table (J).Entity; |
| 3163 |
|
| 3164 |
-- We should not reach the scope of the entry, as it should |
| 3165 |
-- already have been checked in Sem_Attr that this attribute |
| 3166 |
-- reference is within a matching accept statement. |
| 3167 |
|
| 3168 |
pragma Assert (S /= Conctype); |
| 3169 |
|
| 3170 |
if S = Ent then |
| 3171 |
exit; |
| 3172 |
|
| 3173 |
elsif Is_Entry (S) then |
| 3174 |
Nest_Depth := Nest_Depth + 1; |
| 3175 |
end if; |
| 3176 |
end loop; |
| 3177 |
|
| 3178 |
Rewrite (N, |
| 3179 |
Unchecked_Convert_To (Id_Kind, |
| 3180 |
Make_Function_Call (Loc, |
| 3181 |
Name => |
| 3182 |
New_Occurrence_Of (RTE (RE_Task_Entry_Caller), Loc), |
| 3183 |
Parameter_Associations => New_List ( |
| 3184 |
Make_Integer_Literal (Loc, |
| 3185 |
Intval => Nest_Depth))))); |
| 3186 |
end if; |
| 3187 |
|
| 3188 |
Analyze_And_Resolve (N, Id_Kind); |
| 3189 |
end Caller; |
| 3190 |
|
| 3191 |
-------------------- |
| 3192 |
-- Component_Size -- |
| 3193 |
-------------------- |
| 3194 |
|
| 3195 |
-- Component_Size is handled by the back end |
| 3196 |
|
| 3197 |
when Attribute_Component_Size => |
| 3198 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 3199 |
|
| 3200 |
------------- |
| 3201 |
-- Compose -- |
| 3202 |
------------- |
| 3203 |
|
| 3204 |
-- Transforms 'Compose into a call to the floating-point attribute |
| 3205 |
-- function Compose in Fat_xxx (where xxx is the root type) |
| 3206 |
|
| 3207 |
-- Note: we strictly should have special code here to deal with the |
| 3208 |
-- case of absurdly negative arguments (less than Integer'First) |
| 3209 |
-- which will return a (signed) zero value, but it hardly seems |
| 3210 |
-- worth the effort. Absurdly large positive arguments will raise |
| 3211 |
-- constraint error which is fine. |
| 3212 |
|
| 3213 |
when Attribute_Compose => |
| 3214 |
Expand_Fpt_Attribute_RI (N); |
| 3215 |
|
| 3216 |
----------------- |
| 3217 |
-- Constrained -- |
| 3218 |
----------------- |
| 3219 |
|
| 3220 |
when Attribute_Constrained => Constrained : declare |
| 3221 |
Formal_Ent : constant Entity_Id := Param_Entity (Pref); |
| 3222 |
|
| 3223 |
begin |
| 3224 |
-- Reference to a parameter where the value is passed as an extra |
| 3225 |
-- actual, corresponding to the extra formal referenced by the |
| 3226 |
-- Extra_Constrained field of the corresponding formal. If this |
| 3227 |
-- is an entry in-parameter, it is replaced by a constant renaming |
| 3228 |
-- for which Extra_Constrained is never created. |
| 3229 |
|
| 3230 |
if Present (Formal_Ent) |
| 3231 |
and then Ekind (Formal_Ent) /= E_Constant |
| 3232 |
and then Present (Extra_Constrained (Formal_Ent)) |
| 3233 |
then |
| 3234 |
Rewrite (N, |
| 3235 |
New_Occurrence_Of |
| 3236 |
(Extra_Constrained (Formal_Ent), Loc)); |
| 3237 |
|
| 3238 |
-- If the prefix is an access to object, the attribute applies to |
| 3239 |
-- the designated object, so rewrite with an explicit dereference. |
| 3240 |
|
| 3241 |
elsif Is_Access_Type (Ptyp) |
| 3242 |
and then |
| 3243 |
(not Is_Entity_Name (Pref) or else Is_Object (Entity (Pref))) |
| 3244 |
then |
| 3245 |
Rewrite (Pref, |
| 3246 |
Make_Explicit_Dereference (Loc, Relocate_Node (Pref))); |
| 3247 |
|
| 3248 |
-- For variables with a Extra_Constrained field, we use the |
| 3249 |
-- corresponding entity. |
| 3250 |
|
| 3251 |
elsif Nkind (Pref) = N_Identifier |
| 3252 |
and then Ekind (Entity (Pref)) = E_Variable |
| 3253 |
and then Present (Extra_Constrained (Entity (Pref))) |
| 3254 |
then |
| 3255 |
Rewrite (N, |
| 3256 |
New_Occurrence_Of |
| 3257 |
(Extra_Constrained (Entity (Pref)), Loc)); |
| 3258 |
|
| 3259 |
-- For all other cases, we can tell at compile time |
| 3260 |
|
| 3261 |
else |
| 3262 |
-- For access type, apply access check as needed |
| 3263 |
|
| 3264 |
if Is_Entity_Name (Pref) |
| 3265 |
and then not Is_Type (Entity (Pref)) |
| 3266 |
and then Is_Access_Type (Ptyp) |
| 3267 |
then |
| 3268 |
Apply_Access_Check (N); |
| 3269 |
end if; |
| 3270 |
|
| 3271 |
Rewrite (N, |
| 3272 |
New_Occurrence_Of |
| 3273 |
(Boolean_Literals |
| 3274 |
(Exp_Util.Attribute_Constrained_Static_Value (Pref)), Loc)); |
| 3275 |
end if; |
| 3276 |
|
| 3277 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 3278 |
end Constrained; |
| 3279 |
|
| 3280 |
--------------- |
| 3281 |
-- Copy_Sign -- |
| 3282 |
--------------- |
| 3283 |
|
| 3284 |
-- Transforms 'Copy_Sign into a call to the floating-point attribute |
| 3285 |
-- function Copy_Sign in Fat_xxx (where xxx is the root type). |
| 3286 |
|
| 3287 |
when Attribute_Copy_Sign => |
| 3288 |
Expand_Fpt_Attribute_RR (N); |
| 3289 |
|
| 3290 |
----------- |
| 3291 |
-- Count -- |
| 3292 |
----------- |
| 3293 |
|
| 3294 |
-- Transforms 'Count attribute into a call to the Count function |
| 3295 |
|
| 3296 |
when Attribute_Count => Count : declare |
| 3297 |
Call : Node_Id; |
| 3298 |
Conctyp : Entity_Id; |
| 3299 |
Entnam : Node_Id; |
| 3300 |
Entry_Id : Entity_Id; |
| 3301 |
Index : Node_Id; |
| 3302 |
Name : Node_Id; |
| 3303 |
|
| 3304 |
begin |
| 3305 |
-- If the prefix is a member of an entry family, retrieve both |
| 3306 |
-- entry name and index. For a simple entry there is no index. |
| 3307 |
|
| 3308 |
if Nkind (Pref) = N_Indexed_Component then |
| 3309 |
Entnam := Prefix (Pref); |
| 3310 |
Index := First (Expressions (Pref)); |
| 3311 |
else |
| 3312 |
Entnam := Pref; |
| 3313 |
Index := Empty; |
| 3314 |
end if; |
| 3315 |
|
| 3316 |
Entry_Id := Entity (Entnam); |
| 3317 |
|
| 3318 |
-- Find the concurrent type in which this attribute is referenced |
| 3319 |
-- (there had better be one). |
| 3320 |
|
| 3321 |
Conctyp := Current_Scope; |
| 3322 |
while not Is_Concurrent_Type (Conctyp) loop |
| 3323 |
Conctyp := Scope (Conctyp); |
| 3324 |
end loop; |
| 3325 |
|
| 3326 |
-- Protected case |
| 3327 |
|
| 3328 |
if Is_Protected_Type (Conctyp) then |
| 3329 |
|
| 3330 |
-- No need to transform 'Count into a function call if the current |
| 3331 |
-- scope has been eliminated. In this case such transformation is |
| 3332 |
-- also not viable because the enclosing protected object is not |
| 3333 |
-- available. |
| 3334 |
|
| 3335 |
if Is_Eliminated (Current_Scope) then |
| 3336 |
return; |
| 3337 |
end if; |
| 3338 |
|
| 3339 |
case Corresponding_Runtime_Package (Conctyp) is |
| 3340 |
when System_Tasking_Protected_Objects_Entries => |
| 3341 |
Name := New_Occurrence_Of (RTE (RE_Protected_Count), Loc); |
| 3342 |
|
| 3343 |
Call := |
| 3344 |
Make_Function_Call (Loc, |
| 3345 |
Name => Name, |
| 3346 |
Parameter_Associations => New_List ( |
| 3347 |
New_Occurrence_Of |
| 3348 |
(Find_Protection_Object (Current_Scope), Loc), |
| 3349 |
Entry_Index_Expression |
| 3350 |
(Loc, Entry_Id, Index, Scope (Entry_Id)))); |
| 3351 |
|
| 3352 |
when System_Tasking_Protected_Objects_Single_Entry => |
| 3353 |
Name := |
| 3354 |
New_Occurrence_Of (RTE (RE_Protected_Count_Entry), Loc); |
| 3355 |
|
| 3356 |
Call := |
| 3357 |
Make_Function_Call (Loc, |
| 3358 |
Name => Name, |
| 3359 |
Parameter_Associations => New_List ( |
| 3360 |
New_Occurrence_Of |
| 3361 |
(Find_Protection_Object (Current_Scope), Loc))); |
| 3362 |
|
| 3363 |
when others => |
| 3364 |
raise Program_Error; |
| 3365 |
end case; |
| 3366 |
|
| 3367 |
-- Task case |
| 3368 |
|
| 3369 |
else |
| 3370 |
Call := |
| 3371 |
Make_Function_Call (Loc, |
| 3372 |
Name => New_Occurrence_Of (RTE (RE_Task_Count), Loc), |
| 3373 |
Parameter_Associations => New_List ( |
| 3374 |
Entry_Index_Expression (Loc, |
| 3375 |
Entry_Id, Index, Scope (Entry_Id)))); |
| 3376 |
end if; |
| 3377 |
|
| 3378 |
-- The call returns type Natural but the context is universal integer |
| 3379 |
-- so any integer type is allowed. The attribute was already resolved |
| 3380 |
-- so its Etype is the required result type. If the base type of the |
| 3381 |
-- context type is other than Standard.Integer we put in a conversion |
| 3382 |
-- to the required type. This can be a normal typed conversion since |
| 3383 |
-- both input and output types of the conversion are integer types |
| 3384 |
|
| 3385 |
if Base_Type (Typ) /= Base_Type (Standard_Integer) then |
| 3386 |
Rewrite (N, Convert_To (Typ, Call)); |
| 3387 |
else |
| 3388 |
Rewrite (N, Call); |
| 3389 |
end if; |
| 3390 |
|
| 3391 |
Analyze_And_Resolve (N, Typ); |
| 3392 |
end Count; |
| 3393 |
|
| 3394 |
--------------------- |
| 3395 |
-- Descriptor_Size -- |
| 3396 |
--------------------- |
| 3397 |
|
| 3398 |
-- Descriptor_Size is handled by the back end |
| 3399 |
|
| 3400 |
when Attribute_Descriptor_Size => |
| 3401 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 3402 |
|
| 3403 |
--------------- |
| 3404 |
-- Elab_Body -- |
| 3405 |
--------------- |
| 3406 |
|
| 3407 |
-- This processing is shared by Elab_Spec |
| 3408 |
|
| 3409 |
-- What we do is to insert the following declarations |
| 3410 |
|
| 3411 |
-- procedure tnn; |
| 3412 |
-- pragma Import (C, enn, "name___elabb/s"); |
| 3413 |
|
| 3414 |
-- and then the Elab_Body/Spec attribute is replaced by a reference |
| 3415 |
-- to this defining identifier. |
| 3416 |
|
| 3417 |
when Attribute_Elab_Body |
| 3418 |
| Attribute_Elab_Spec |
| 3419 |
=> |
| 3420 |
-- Leave attribute unexpanded in CodePeer mode: the gnat2scil |
| 3421 |
-- back-end knows how to handle these attributes directly. |
| 3422 |
|
| 3423 |
if CodePeer_Mode then |
| 3424 |
return; |
| 3425 |
end if; |
| 3426 |
|
| 3427 |
Elab_Body : declare |
| 3428 |
Ent : constant Entity_Id := Make_Temporary (Loc, 'E'); |
| 3429 |
Str : String_Id; |
| 3430 |
Lang : Node_Id; |
| 3431 |
|
| 3432 |
procedure Make_Elab_String (Nod : Node_Id); |
| 3433 |
-- Given Nod, an identifier, or a selected component, put the |
| 3434 |
-- image into the current string literal, with double underline |
| 3435 |
-- between components. |
| 3436 |
|
| 3437 |
---------------------- |
| 3438 |
-- Make_Elab_String -- |
| 3439 |
---------------------- |
| 3440 |
|
| 3441 |
procedure Make_Elab_String (Nod : Node_Id) is |
| 3442 |
begin |
| 3443 |
if Nkind (Nod) = N_Selected_Component then |
| 3444 |
Make_Elab_String (Prefix (Nod)); |
| 3445 |
Store_String_Char ('_'); |
| 3446 |
Store_String_Char ('_'); |
| 3447 |
Get_Name_String (Chars (Selector_Name (Nod))); |
| 3448 |
|
| 3449 |
else |
| 3450 |
pragma Assert (Nkind (Nod) = N_Identifier); |
| 3451 |
Get_Name_String (Chars (Nod)); |
| 3452 |
end if; |
| 3453 |
|
| 3454 |
Store_String_Chars (Name_Buffer (1 .. Name_Len)); |
| 3455 |
end Make_Elab_String; |
| 3456 |
|
| 3457 |
-- Start of processing for Elab_Body/Elab_Spec |
| 3458 |
|
| 3459 |
begin |
| 3460 |
-- First we need to prepare the string literal for the name of |
| 3461 |
-- the elaboration routine to be referenced. |
| 3462 |
|
| 3463 |
Start_String; |
| 3464 |
Make_Elab_String (Pref); |
| 3465 |
Store_String_Chars ("___elab"); |
| 3466 |
Lang := Make_Identifier (Loc, Name_C); |
| 3467 |
|
| 3468 |
if Id = Attribute_Elab_Body then |
| 3469 |
Store_String_Char ('b'); |
| 3470 |
else |
| 3471 |
Store_String_Char ('s'); |
| 3472 |
end if; |
| 3473 |
|
| 3474 |
Str := End_String; |
| 3475 |
|
| 3476 |
Insert_Actions (N, New_List ( |
| 3477 |
Make_Subprogram_Declaration (Loc, |
| 3478 |
Specification => |
| 3479 |
Make_Procedure_Specification (Loc, |
| 3480 |
Defining_Unit_Name => Ent)), |
| 3481 |
|
| 3482 |
Make_Pragma (Loc, |
| 3483 |
Chars => Name_Import, |
| 3484 |
Pragma_Argument_Associations => New_List ( |
| 3485 |
Make_Pragma_Argument_Association (Loc, Expression => Lang), |
| 3486 |
|
| 3487 |
Make_Pragma_Argument_Association (Loc, |
| 3488 |
Expression => Make_Identifier (Loc, Chars (Ent))), |
| 3489 |
|
| 3490 |
Make_Pragma_Argument_Association (Loc, |
| 3491 |
Expression => Make_String_Literal (Loc, Str)))))); |
| 3492 |
|
| 3493 |
Set_Entity (N, Ent); |
| 3494 |
Rewrite (N, New_Occurrence_Of (Ent, Loc)); |
| 3495 |
end Elab_Body; |
| 3496 |
|
| 3497 |
-------------------- |
| 3498 |
-- Elab_Subp_Body -- |
| 3499 |
-------------------- |
| 3500 |
|
| 3501 |
-- Always ignored. In CodePeer mode, gnat2scil knows how to handle |
| 3502 |
-- this attribute directly, and if we are not in CodePeer mode it is |
| 3503 |
-- entirely ignored ??? |
| 3504 |
|
| 3505 |
when Attribute_Elab_Subp_Body => |
| 3506 |
return; |
| 3507 |
|
| 3508 |
---------------- |
| 3509 |
-- Elaborated -- |
| 3510 |
---------------- |
| 3511 |
|
| 3512 |
-- Elaborated is always True for preelaborated units, predefined units, |
| 3513 |
-- pure units and units which have Elaborate_Body pragmas. These units |
| 3514 |
-- have no elaboration entity. |
| 3515 |
|
| 3516 |
-- Note: The Elaborated attribute is never passed to the back end |
| 3517 |
|
| 3518 |
when Attribute_Elaborated => Elaborated : declare |
| 3519 |
Elab_Id : constant Entity_Id := Elaboration_Entity (Entity (Pref)); |
| 3520 |
|
| 3521 |
begin |
| 3522 |
if Present (Elab_Id) then |
| 3523 |
Rewrite (N, |
| 3524 |
Make_Op_Ne (Loc, |
| 3525 |
Left_Opnd => New_Occurrence_Of (Elab_Id, Loc), |
| 3526 |
Right_Opnd => Make_Integer_Literal (Loc, Uint_0))); |
| 3527 |
|
| 3528 |
Analyze_And_Resolve (N, Typ); |
| 3529 |
else |
| 3530 |
Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); |
| 3531 |
end if; |
| 3532 |
end Elaborated; |
| 3533 |
|
| 3534 |
-------------- |
| 3535 |
-- Enum_Rep -- |
| 3536 |
-------------- |
| 3537 |
|
| 3538 |
when Attribute_Enum_Rep => Enum_Rep : declare |
| 3539 |
Expr : Node_Id; |
| 3540 |
|
| 3541 |
begin |
| 3542 |
-- Get the expression, which is X for Enum_Type'Enum_Rep (X) or |
| 3543 |
-- X'Enum_Rep. |
| 3544 |
|
| 3545 |
if Is_Non_Empty_List (Exprs) then |
| 3546 |
Expr := First (Exprs); |
| 3547 |
else |
| 3548 |
Expr := Pref; |
| 3549 |
end if; |
| 3550 |
|
| 3551 |
-- If not constant-folded, Enum_Type'Enum_Rep (X) or X'Enum_Rep |
| 3552 |
-- expands to |
| 3553 |
|
| 3554 |
-- target-type!(X) |
| 3555 |
|
| 3556 |
-- This is an unchecked conversion from the enumeration type to the |
| 3557 |
-- target integer type, which is treated by the back end as a normal |
| 3558 |
-- integer conversion, treating the enumeration type as an integer, |
| 3559 |
-- which is exactly what we want. Unlike for the Pos attribute, we |
| 3560 |
-- cannot use a regular conversion since the associated check would |
| 3561 |
-- involve comparing the converted bounds, i.e. would involve the use |
| 3562 |
-- of 'Pos instead 'Enum_Rep for these bounds. |
| 3563 |
|
| 3564 |
-- However the target type is universal integer in most cases, which |
| 3565 |
-- is a very large type, so in the case of an enumeration type, we |
| 3566 |
-- first convert to a small signed integer type in order not to lose |
| 3567 |
-- the size information. |
| 3568 |
|
| 3569 |
if Is_Enumeration_Type (Ptyp) then |
| 3570 |
Rewrite (N, Unchecked_Convert_To (Get_Integer_Type (Ptyp), Expr)); |
| 3571 |
Convert_To_And_Rewrite (Typ, N); |
| 3572 |
|
| 3573 |
-- Deal with integer types (replace by conversion) |
| 3574 |
|
| 3575 |
else |
| 3576 |
Rewrite (N, Convert_To (Typ, Expr)); |
| 3577 |
end if; |
| 3578 |
|
| 3579 |
Analyze_And_Resolve (N, Typ); |
| 3580 |
end Enum_Rep; |
| 3581 |
|
| 3582 |
-------------- |
| 3583 |
-- Enum_Val -- |
| 3584 |
-------------- |
| 3585 |
|
| 3586 |
when Attribute_Enum_Val => Enum_Val : declare |
| 3587 |
Expr : Node_Id; |
| 3588 |
Btyp : constant Entity_Id := Base_Type (Ptyp); |
| 3589 |
|
| 3590 |
begin |
| 3591 |
-- X'Enum_Val (Y) expands to |
| 3592 |
|
| 3593 |
-- [constraint_error when _rep_to_pos (Y, False) = -1, msg] |
| 3594 |
-- X!(Y); |
| 3595 |
|
| 3596 |
Expr := Unchecked_Convert_To (Ptyp, First (Exprs)); |
| 3597 |
|
| 3598 |
-- Ensure that the expression is not truncated since the "bad" bits |
| 3599 |
-- are desired. |
| 3600 |
|
| 3601 |
if Nkind (Expr) = N_Unchecked_Type_Conversion then |
| 3602 |
Set_No_Truncation (Expr); |
| 3603 |
end if; |
| 3604 |
|
| 3605 |
Insert_Action (N, |
| 3606 |
Make_Raise_Constraint_Error (Loc, |
| 3607 |
Condition => |
| 3608 |
Make_Op_Eq (Loc, |
| 3609 |
Left_Opnd => |
| 3610 |
Make_Function_Call (Loc, |
| 3611 |
Name => |
| 3612 |
New_Occurrence_Of (TSS (Btyp, TSS_Rep_To_Pos), Loc), |
| 3613 |
Parameter_Associations => New_List ( |
| 3614 |
Relocate_Node (Duplicate_Subexpr (Expr)), |
| 3615 |
New_Occurrence_Of (Standard_False, Loc))), |
| 3616 |
|
| 3617 |
Right_Opnd => Make_Integer_Literal (Loc, -1)), |
| 3618 |
Reason => CE_Range_Check_Failed)); |
| 3619 |
|
| 3620 |
Rewrite (N, Expr); |
| 3621 |
Analyze_And_Resolve (N, Ptyp); |
| 3622 |
end Enum_Val; |
| 3623 |
|
| 3624 |
-------------- |
| 3625 |
-- Exponent -- |
| 3626 |
-------------- |
| 3627 |
|
| 3628 |
-- Transforms 'Exponent into a call to the floating-point attribute |
| 3629 |
-- function Exponent in Fat_xxx (where xxx is the root type) |
| 3630 |
|
| 3631 |
when Attribute_Exponent => |
| 3632 |
Expand_Fpt_Attribute_R (N); |
| 3633 |
|
| 3634 |
------------------ |
| 3635 |
-- External_Tag -- |
| 3636 |
------------------ |
| 3637 |
|
| 3638 |
-- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag) |
| 3639 |
|
| 3640 |
when Attribute_External_Tag => |
| 3641 |
Rewrite (N, |
| 3642 |
Make_Function_Call (Loc, |
| 3643 |
Name => |
| 3644 |
New_Occurrence_Of (RTE (RE_External_Tag), Loc), |
| 3645 |
Parameter_Associations => New_List ( |
| 3646 |
Make_Attribute_Reference (Loc, |
| 3647 |
Attribute_Name => Name_Tag, |
| 3648 |
Prefix => Prefix (N))))); |
| 3649 |
|
| 3650 |
Analyze_And_Resolve (N, Standard_String); |
| 3651 |
|
| 3652 |
----------------------- |
| 3653 |
-- Finalization_Size -- |
| 3654 |
----------------------- |
| 3655 |
|
| 3656 |
when Attribute_Finalization_Size => Finalization_Size : declare |
| 3657 |
function Calculate_Header_Size return Node_Id; |
| 3658 |
-- Generate a runtime call to calculate the size of the hidden header |
| 3659 |
-- along with any added padding which would precede a heap-allocated |
| 3660 |
-- object of the prefix type. |
| 3661 |
|
| 3662 |
--------------------------- |
| 3663 |
-- Calculate_Header_Size -- |
| 3664 |
--------------------------- |
| 3665 |
|
| 3666 |
function Calculate_Header_Size return Node_Id is |
| 3667 |
begin |
| 3668 |
-- Generate: |
| 3669 |
-- Typ (Header_Size_With_Padding (Pref'Alignment)) |
| 3670 |
|
| 3671 |
return |
| 3672 |
Convert_To (Typ, |
| 3673 |
Make_Function_Call (Loc, |
| 3674 |
Name => |
| 3675 |
New_Occurrence_Of (RTE (RE_Header_Size_With_Padding), Loc), |
| 3676 |
|
| 3677 |
Parameter_Associations => New_List ( |
| 3678 |
Make_Attribute_Reference (Loc, |
| 3679 |
Prefix => New_Copy_Tree (Pref), |
| 3680 |
Attribute_Name => Name_Alignment)))); |
| 3681 |
end Calculate_Header_Size; |
| 3682 |
|
| 3683 |
-- Local variables |
| 3684 |
|
| 3685 |
P_Loc : constant Source_Ptr := Sloc (Pref); |
| 3686 |
Size : Entity_Id; |
| 3687 |
|
| 3688 |
-- Start of processing for Finalization_Size |
| 3689 |
|
| 3690 |
begin |
| 3691 |
-- If the prefix is an interface type, generate code to obtain its |
| 3692 |
-- address and displace it to reference the base of the object. |
| 3693 |
|
| 3694 |
if Is_Interface (Ptyp) then |
| 3695 |
-- Generate: |
| 3696 |
-- Ptyp!(tag_ptr!($base_address (ptr.all'address)).all) |
| 3697 |
|
| 3698 |
Rewrite (Pref, |
| 3699 |
Unchecked_Convert_To (Ptyp, |
| 3700 |
Make_Explicit_Dereference (P_Loc, |
| 3701 |
Unchecked_Convert_To (RTE (RE_Tag_Ptr), |
| 3702 |
Make_Function_Call (P_Loc, |
| 3703 |
Name => New_Occurrence_Of |
| 3704 |
(RTE (RE_Base_Address), P_Loc), |
| 3705 |
Parameter_Associations => |
| 3706 |
New_List ( |
| 3707 |
Make_Attribute_Reference (P_Loc, |
| 3708 |
Prefix => Duplicate_Subexpr (Pref), |
| 3709 |
Attribute_Name => Name_Address))))))); |
| 3710 |
Analyze_And_Resolve (Pref, Ptyp); |
| 3711 |
end if; |
| 3712 |
|
| 3713 |
-- If the prefix is the dereference of an access value subject to |
| 3714 |
-- pragma No_Heap_Finalization, then no header has been added. |
| 3715 |
|
| 3716 |
if Nkind (Pref) = N_Explicit_Dereference |
| 3717 |
and then No_Heap_Finalization (Etype (Prefix (Pref))) |
| 3718 |
then |
| 3719 |
Rewrite (N, Make_Integer_Literal (Loc, 0)); |
| 3720 |
|
| 3721 |
-- An object of a class-wide type first requires a runtime check to |
| 3722 |
-- determine whether it is actually controlled or not. Depending on |
| 3723 |
-- the outcome of this check, the Finalization_Size of the object |
| 3724 |
-- may be zero or some positive value. |
| 3725 |
-- |
| 3726 |
-- In this scenario, Pref'Finalization_Size is expanded into |
| 3727 |
-- |
| 3728 |
-- Size : Integer := 0; |
| 3729 |
-- |
| 3730 |
-- if Needs_Finalization (Pref'Tag) then |
| 3731 |
-- Size := Integer (Header_Size_With_Padding (Pref'Alignment)); |
| 3732 |
-- end if; |
| 3733 |
-- |
| 3734 |
-- and the attribute reference is replaced with a reference to Size. |
| 3735 |
|
| 3736 |
elsif Is_Class_Wide_Type (Ptyp) then |
| 3737 |
Size := Make_Temporary (Loc, 'S'); |
| 3738 |
|
| 3739 |
Insert_Actions (N, New_List ( |
| 3740 |
|
| 3741 |
-- Generate: |
| 3742 |
-- Size : Integer := 0; |
| 3743 |
|
| 3744 |
Make_Object_Declaration (Loc, |
| 3745 |
Defining_Identifier => Size, |
| 3746 |
Object_Definition => |
| 3747 |
New_Occurrence_Of (Standard_Integer, Loc), |
| 3748 |
Expression => Make_Integer_Literal (Loc, 0)), |
| 3749 |
|
| 3750 |
-- Generate: |
| 3751 |
-- if Needs_Finalization (Pref'Tag) then |
| 3752 |
-- Size := |
| 3753 |
-- Integer (Header_Size_With_Padding (Pref'Alignment)); |
| 3754 |
-- end if; |
| 3755 |
|
| 3756 |
Make_If_Statement (Loc, |
| 3757 |
Condition => |
| 3758 |
Make_Function_Call (Loc, |
| 3759 |
Name => |
| 3760 |
New_Occurrence_Of (RTE (RE_Needs_Finalization), Loc), |
| 3761 |
|
| 3762 |
Parameter_Associations => New_List ( |
| 3763 |
Make_Attribute_Reference (Loc, |
| 3764 |
Prefix => New_Copy_Tree (Pref), |
| 3765 |
Attribute_Name => Name_Tag))), |
| 3766 |
|
| 3767 |
Then_Statements => New_List ( |
| 3768 |
Make_Assignment_Statement (Loc, |
| 3769 |
Name => New_Occurrence_Of (Size, Loc), |
| 3770 |
Expression => |
| 3771 |
Convert_To |
| 3772 |
(Standard_Integer, Calculate_Header_Size)))))); |
| 3773 |
|
| 3774 |
Rewrite (N, New_Occurrence_Of (Size, Loc)); |
| 3775 |
|
| 3776 |
-- The prefix is known to be controlled at compile time and to |
| 3777 |
-- require strict finalization. Calculate Finalization_Size by |
| 3778 |
-- calling function Header_Size_With_Padding. |
| 3779 |
|
| 3780 |
elsif Needs_Finalization (Ptyp) |
| 3781 |
and then not Has_Relaxed_Finalization (Ptyp) |
| 3782 |
then |
| 3783 |
Rewrite (N, Calculate_Header_Size); |
| 3784 |
|
| 3785 |
-- The prefix is not an object with controlled parts, so its |
| 3786 |
-- Finalization_Size is zero. |
| 3787 |
|
| 3788 |
else |
| 3789 |
Rewrite (N, Make_Integer_Literal (Loc, 0)); |
| 3790 |
end if; |
| 3791 |
|
| 3792 |
-- Due to cases where the entity type of the attribute is already |
| 3793 |
-- resolved the rewritten N must get re-resolved to its appropriate |
| 3794 |
-- type. |
| 3795 |
|
| 3796 |
Analyze_And_Resolve (N, Typ); |
| 3797 |
end Finalization_Size; |
| 3798 |
|
| 3799 |
----------------- |
| 3800 |
-- First, Last -- |
| 3801 |
----------------- |
| 3802 |
|
| 3803 |
when Attribute_First |
| 3804 |
| Attribute_Last |
| 3805 |
=> |
| 3806 |
-- If the prefix type is a constrained packed array type which |
| 3807 |
-- already has a Packed_Array_Impl_Type representation defined, then |
| 3808 |
-- replace this attribute with a direct reference to the attribute of |
| 3809 |
-- the appropriate index subtype (since otherwise the back end will |
| 3810 |
-- try to give us the value of 'First for this implementation type). |
| 3811 |
-- Do not do this if Ptyp depends on a discriminant as its bounds |
| 3812 |
-- are only available through N. |
| 3813 |
|
| 3814 |
if Is_Constrained_Packed_Array (Ptyp) |
| 3815 |
and then not Size_Depends_On_Discriminant (Ptyp) |
| 3816 |
then |
| 3817 |
Rewrite (N, |
| 3818 |
Make_Attribute_Reference (Loc, |
| 3819 |
Attribute_Name => Attribute_Name (N), |
| 3820 |
Prefix => |
| 3821 |
New_Occurrence_Of (Get_Index_Subtype (N), Loc))); |
| 3822 |
Analyze_And_Resolve (N, Typ); |
| 3823 |
|
| 3824 |
-- For a constrained array type, if the bound is a reference to an |
| 3825 |
-- entity which is not a discriminant, just replace with a direct |
| 3826 |
-- reference. Note that this must be in keeping with what is done |
| 3827 |
-- for scalar types in order for range checks to be elided in loops. |
| 3828 |
|
| 3829 |
-- However, avoid doing it if the array type is public because, in |
| 3830 |
-- this case, we effectively rely on the back end to create public |
| 3831 |
-- symbols with consistent names across units for the array bounds. |
| 3832 |
|
| 3833 |
elsif Is_Array_Type (Ptyp) |
| 3834 |
and then Is_Constrained (Ptyp) |
| 3835 |
and then not Is_Public (Ptyp) |
| 3836 |
then |
| 3837 |
declare |
| 3838 |
Bnd : Node_Id; |
| 3839 |
|
| 3840 |
begin |
| 3841 |
if Id = Attribute_First then |
| 3842 |
Bnd := Type_Low_Bound (Get_Index_Subtype (N)); |
| 3843 |
else |
| 3844 |
Bnd := Type_High_Bound (Get_Index_Subtype (N)); |
| 3845 |
end if; |
| 3846 |
|
| 3847 |
if Is_Entity_Name (Bnd) |
| 3848 |
and then Ekind (Entity (Bnd)) /= E_Discriminant |
| 3849 |
then |
| 3850 |
Rewrite (N, New_Occurrence_Of (Entity (Bnd), Loc)); |
| 3851 |
end if; |
| 3852 |
end; |
| 3853 |
|
| 3854 |
-- For access type, apply access check as needed |
| 3855 |
|
| 3856 |
elsif Is_Access_Type (Ptyp) then |
| 3857 |
Apply_Access_Check (N); |
| 3858 |
|
| 3859 |
-- For scalar type, if the bound is a reference to an entity, just |
| 3860 |
-- replace with a direct reference. Note that we can only have a |
| 3861 |
-- reference to a constant entity at this stage, anything else would |
| 3862 |
-- have already been rewritten. |
| 3863 |
|
| 3864 |
elsif Is_Scalar_Type (Ptyp) then |
| 3865 |
declare |
| 3866 |
Bnd : Node_Id; |
| 3867 |
|
| 3868 |
begin |
| 3869 |
if Id = Attribute_First then |
| 3870 |
Bnd := Type_Low_Bound (Ptyp); |
| 3871 |
else |
| 3872 |
Bnd := Type_High_Bound (Ptyp); |
| 3873 |
end if; |
| 3874 |
|
| 3875 |
if Is_Entity_Name (Bnd) then |
| 3876 |
Rewrite (N, New_Occurrence_Of (Entity (Bnd), Loc)); |
| 3877 |
end if; |
| 3878 |
end; |
| 3879 |
end if; |
| 3880 |
|
| 3881 |
--------------- |
| 3882 |
-- First_Bit -- |
| 3883 |
--------------- |
| 3884 |
|
| 3885 |
-- We leave the computation up to the back end, since we don't know what |
| 3886 |
-- layout will be chosen if no component clause was specified. |
| 3887 |
|
| 3888 |
when Attribute_First_Bit => |
| 3889 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 3890 |
|
| 3891 |
-------------------------------- |
| 3892 |
-- Fixed_Value, Integer_Value -- |
| 3893 |
-------------------------------- |
| 3894 |
|
| 3895 |
-- We transform |
| 3896 |
|
| 3897 |
-- fixtype'Fixed_Value (integer-value) |
| 3898 |
-- inttype'Integer_Value (fixed-value) |
| 3899 |
|
| 3900 |
-- into |
| 3901 |
|
| 3902 |
-- fixtype (integer-value) |
| 3903 |
-- inttype (fixed-value) |
| 3904 |
|
| 3905 |
-- respectively. |
| 3906 |
|
| 3907 |
-- We set Conversion_OK on the conversion because we do not want it |
| 3908 |
-- to go through the fixed-point conversion circuits. |
| 3909 |
|
| 3910 |
when Attribute_Fixed_Value |
| 3911 |
| Attribute_Integer_Value |
| 3912 |
=> |
| 3913 |
Rewrite (N, OK_Convert_To (Entity (Pref), First (Exprs))); |
| 3914 |
|
| 3915 |
-- Note that it might appear that a properly analyzed unchecked |
| 3916 |
-- conversion would be just fine here, but that's not the case, |
| 3917 |
-- since the full range checks performed by the following calls |
| 3918 |
-- are critical. |
| 3919 |
|
| 3920 |
Apply_Type_Conversion_Checks (N); |
| 3921 |
|
| 3922 |
-- Note that Apply_Type_Conversion_Checks only deals with the |
| 3923 |
-- overflow checks on conversions involving fixed-point types |
| 3924 |
-- so we must apply range checks manually on them and expand. |
| 3925 |
|
| 3926 |
Apply_Scalar_Range_Check |
| 3927 |
(Expression (N), Etype (N), Fixed_Int => True); |
| 3928 |
|
| 3929 |
Set_Analyzed (N); |
| 3930 |
Expand (N); |
| 3931 |
|
| 3932 |
----------- |
| 3933 |
-- Floor -- |
| 3934 |
----------- |
| 3935 |
|
| 3936 |
-- Transforms 'Floor into a call to the floating-point attribute |
| 3937 |
-- function Floor in Fat_xxx (where xxx is the root type) |
| 3938 |
|
| 3939 |
when Attribute_Floor => |
| 3940 |
Expand_Fpt_Attribute_R (N); |
| 3941 |
|
| 3942 |
---------- |
| 3943 |
-- Fore -- |
| 3944 |
---------- |
| 3945 |
|
| 3946 |
-- For the fixed-point type Typ: |
| 3947 |
|
| 3948 |
-- Typ'Fore |
| 3949 |
|
| 3950 |
-- expands into |
| 3951 |
|
| 3952 |
-- System.Fore_xx (ftyp (Typ'First), ftyp (Typ'Last) [,pm]) |
| 3953 |
|
| 3954 |
-- For decimal fixed-point types |
| 3955 |
-- xx = Decimal{32,64,128} |
| 3956 |
-- ftyp = Integer_{32,64,128} |
| 3957 |
-- pm = Typ'Scale |
| 3958 |
|
| 3959 |
-- For the most common ordinary fixed-point types |
| 3960 |
-- xx = Fixed{32,64,128} |
| 3961 |
-- ftyp = Integer_{32,64,128} |
| 3962 |
-- pm = numerator of Typ'Small |
| 3963 |
-- denominator of Typ'Small |
| 3964 |
-- min (scale of Typ'Small, 0) |
| 3965 |
|
| 3966 |
-- For other ordinary fixed-point types |
| 3967 |
-- xx = Fixed |
| 3968 |
-- ftyp = Long_Float |
| 3969 |
-- pm = none |
| 3970 |
|
| 3971 |
-- Note that we know that the type is a nonstatic subtype, or Fore would |
| 3972 |
-- have been computed statically in Eval_Attribute. |
| 3973 |
|
| 3974 |
when Attribute_Fore => |
| 3975 |
declare |
| 3976 |
Arg_List : List_Id; |
| 3977 |
Fid : RE_Id; |
| 3978 |
Ftyp : Entity_Id; |
| 3979 |
|
| 3980 |
begin |
| 3981 |
if Is_Decimal_Fixed_Point_Type (Ptyp) then |
| 3982 |
if Esize (Ptyp) <= 32 then |
| 3983 |
Fid := RE_Fore_Decimal32; |
| 3984 |
Ftyp := RTE (RE_Integer_32); |
| 3985 |
elsif Esize (Ptyp) <= 64 then |
| 3986 |
Fid := RE_Fore_Decimal64; |
| 3987 |
Ftyp := RTE (RE_Integer_64); |
| 3988 |
else |
| 3989 |
Fid := RE_Fore_Decimal128; |
| 3990 |
Ftyp := RTE (RE_Integer_128); |
| 3991 |
end if; |
| 3992 |
|
| 3993 |
else |
| 3994 |
declare |
| 3995 |
Num : constant Uint := Norm_Num (Small_Value (Ptyp)); |
| 3996 |
Den : constant Uint := Norm_Den (Small_Value (Ptyp)); |
| 3997 |
Max : constant Uint := UI_Max (Num, Den); |
| 3998 |
Min : constant Uint := UI_Min (Num, Den); |
| 3999 |
Siz : constant Uint := Esize (Ptyp); |
| 4000 |
|
| 4001 |
begin |
| 4002 |
if Siz <= 32 |
| 4003 |
and then Max <= Uint_2 ** 31 |
| 4004 |
and then (Min = Uint_1 |
| 4005 |
or else Num < Den |
| 4006 |
or else Num < Uint_10 ** 8) |
| 4007 |
then |
| 4008 |
Fid := RE_Fore_Fixed32; |
| 4009 |
Ftyp := RTE (RE_Integer_32); |
| 4010 |
elsif Siz <= 64 |
| 4011 |
and then Max <= Uint_2 ** 63 |
| 4012 |
and then (Min = Uint_1 |
| 4013 |
or else Num < Den |
| 4014 |
or else Num < Uint_10 ** 17) |
| 4015 |
then |
| 4016 |
Fid := RE_Fore_Fixed64; |
| 4017 |
Ftyp := RTE (RE_Integer_64); |
| 4018 |
elsif System_Max_Integer_Size = 128 |
| 4019 |
and then Max <= Uint_2 ** 127 |
| 4020 |
and then (Min = Uint_1 |
| 4021 |
or else Num < Den |
| 4022 |
or else Num < Uint_10 ** 37) |
| 4023 |
then |
| 4024 |
Fid := RE_Fore_Fixed128; |
| 4025 |
Ftyp := RTE (RE_Integer_128); |
| 4026 |
else |
| 4027 |
Fid := RE_Fore_Fixed; |
| 4028 |
Ftyp := Standard_Long_Float; |
| 4029 |
end if; |
| 4030 |
end; |
| 4031 |
end if; |
| 4032 |
|
| 4033 |
Arg_List := New_List ( |
| 4034 |
Convert_To (Ftyp, |
| 4035 |
Make_Attribute_Reference (Loc, |
| 4036 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 4037 |
Attribute_Name => Name_First))); |
| 4038 |
|
| 4039 |
Append_To (Arg_List, |
| 4040 |
Convert_To (Ftyp, |
| 4041 |
Make_Attribute_Reference (Loc, |
| 4042 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 4043 |
Attribute_Name => Name_Last))); |
| 4044 |
|
| 4045 |
-- For decimal, append Scale and also set to do literal conversion |
| 4046 |
|
| 4047 |
if Is_Decimal_Fixed_Point_Type (Ptyp) then |
| 4048 |
Set_Conversion_OK (First (Arg_List)); |
| 4049 |
Set_Conversion_OK (Next (First (Arg_List))); |
| 4050 |
|
| 4051 |
Append_To (Arg_List, |
| 4052 |
Make_Integer_Literal (Loc, Scale_Value (Ptyp))); |
| 4053 |
|
| 4054 |
-- For ordinary fixed-point types, append Num, Den and Scale |
| 4055 |
-- parameters and also set to do literal conversion |
| 4056 |
|
| 4057 |
elsif Fid /= RE_Fore_Fixed then |
| 4058 |
Set_Conversion_OK (First (Arg_List)); |
| 4059 |
Set_Conversion_OK (Next (First (Arg_List))); |
| 4060 |
|
| 4061 |
Append_To (Arg_List, |
| 4062 |
Make_Integer_Literal (Loc, -Norm_Num (Small_Value (Ptyp)))); |
| 4063 |
|
| 4064 |
Append_To (Arg_List, |
| 4065 |
Make_Integer_Literal (Loc, -Norm_Den (Small_Value (Ptyp)))); |
| 4066 |
|
| 4067 |
declare |
| 4068 |
Val : Ureal := Small_Value (Ptyp); |
| 4069 |
Scale : Int := 0; |
| 4070 |
|
| 4071 |
begin |
| 4072 |
while Val >= Ureal_10 loop |
| 4073 |
Val := Val / Ureal_10; |
| 4074 |
Scale := Scale - 1; |
| 4075 |
end loop; |
| 4076 |
|
| 4077 |
Append_To (Arg_List, |
| 4078 |
Make_Integer_Literal (Loc, UI_From_Int (Scale))); |
| 4079 |
end; |
| 4080 |
end if; |
| 4081 |
|
| 4082 |
Rewrite (N, |
| 4083 |
Convert_To (Typ, |
| 4084 |
Make_Function_Call (Loc, |
| 4085 |
Name => |
| 4086 |
New_Occurrence_Of (RTE (Fid), Loc), |
| 4087 |
Parameter_Associations => Arg_List))); |
| 4088 |
|
| 4089 |
Analyze_And_Resolve (N, Typ); |
| 4090 |
end; |
| 4091 |
|
| 4092 |
-------------- |
| 4093 |
-- Fraction -- |
| 4094 |
-------------- |
| 4095 |
|
| 4096 |
-- Transforms 'Fraction into a call to the floating-point attribute |
| 4097 |
-- function Fraction in Fat_xxx (where xxx is the root type) |
| 4098 |
|
| 4099 |
when Attribute_Fraction => |
| 4100 |
Expand_Fpt_Attribute_R (N); |
| 4101 |
|
| 4102 |
-------------- |
| 4103 |
-- From_Any -- |
| 4104 |
-------------- |
| 4105 |
|
| 4106 |
when Attribute_From_Any => From_Any : declare |
| 4107 |
Decls : constant List_Id := New_List; |
| 4108 |
|
| 4109 |
begin |
| 4110 |
Rewrite (N, |
| 4111 |
Build_From_Any_Call (Ptyp, |
| 4112 |
Relocate_Node (First (Exprs)), |
| 4113 |
Decls)); |
| 4114 |
Insert_Actions (N, Decls); |
| 4115 |
Analyze_And_Resolve (N, Ptyp); |
| 4116 |
end From_Any; |
| 4117 |
|
| 4118 |
---------------------- |
| 4119 |
-- Has_Same_Storage -- |
| 4120 |
---------------------- |
| 4121 |
|
| 4122 |
when Attribute_Has_Same_Storage => Has_Same_Storage : declare |
| 4123 |
X : constant Node_Id := Pref; |
| 4124 |
Y : constant Node_Id := First (Exprs); |
| 4125 |
-- The arguments |
| 4126 |
|
| 4127 |
X_Addr : Node_Id; |
| 4128 |
Y_Addr : Node_Id; |
| 4129 |
-- Rhe expressions for their addresses |
| 4130 |
|
| 4131 |
X_Size : Node_Id; |
| 4132 |
Y_Size : Node_Id; |
| 4133 |
-- Rhe expressions for their sizes |
| 4134 |
|
| 4135 |
begin |
| 4136 |
-- The attribute is expanded as: |
| 4137 |
|
| 4138 |
-- (X'address = Y'address) |
| 4139 |
-- and then (X'Size = Y'Size) |
| 4140 |
-- and then (X'Size /= 0) (AI12-0077) |
| 4141 |
|
| 4142 |
-- If both arguments have the same Etype the second conjunct can be |
| 4143 |
-- omitted. |
| 4144 |
|
| 4145 |
X_Addr := |
| 4146 |
Make_Attribute_Reference (Loc, |
| 4147 |
Attribute_Name => Name_Address, |
| 4148 |
Prefix => New_Copy_Tree (X)); |
| 4149 |
|
| 4150 |
Y_Addr := |
| 4151 |
Make_Attribute_Reference (Loc, |
| 4152 |
Attribute_Name => Name_Address, |
| 4153 |
Prefix => New_Copy_Tree (Y)); |
| 4154 |
|
| 4155 |
X_Size := |
| 4156 |
Make_Attribute_Reference (Loc, |
| 4157 |
Attribute_Name => Name_Size, |
| 4158 |
Prefix => New_Copy_Tree (X)); |
| 4159 |
|
| 4160 |
if Etype (X) = Etype (Y) then |
| 4161 |
Rewrite (N, |
| 4162 |
Make_And_Then (Loc, |
| 4163 |
Left_Opnd => |
| 4164 |
Make_Op_Eq (Loc, |
| 4165 |
Left_Opnd => X_Addr, |
| 4166 |
Right_Opnd => Y_Addr), |
| 4167 |
Right_Opnd => |
| 4168 |
Make_Op_Ne (Loc, |
| 4169 |
Left_Opnd => X_Size, |
| 4170 |
Right_Opnd => Make_Integer_Literal (Loc, 0)))); |
| 4171 |
else |
| 4172 |
Y_Size := |
| 4173 |
Make_Attribute_Reference (Loc, |
| 4174 |
Attribute_Name => Name_Size, |
| 4175 |
Prefix => New_Copy_Tree (Y)); |
| 4176 |
|
| 4177 |
Rewrite (N, |
| 4178 |
Make_And_Then (Loc, |
| 4179 |
Left_Opnd => |
| 4180 |
Make_Op_Eq (Loc, |
| 4181 |
Left_Opnd => X_Addr, |
| 4182 |
Right_Opnd => Y_Addr), |
| 4183 |
Right_Opnd => |
| 4184 |
Make_And_Then (Loc, |
| 4185 |
Left_Opnd => |
| 4186 |
Make_Op_Eq (Loc, |
| 4187 |
Left_Opnd => X_Size, |
| 4188 |
Right_Opnd => Y_Size), |
| 4189 |
Right_Opnd => |
| 4190 |
Make_Op_Ne (Loc, |
| 4191 |
Left_Opnd => New_Copy_Tree (X_Size), |
| 4192 |
Right_Opnd => Make_Integer_Literal (Loc, 0))))); |
| 4193 |
end if; |
| 4194 |
|
| 4195 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 4196 |
end Has_Same_Storage; |
| 4197 |
|
| 4198 |
-------------- |
| 4199 |
-- Identity -- |
| 4200 |
-------------- |
| 4201 |
|
| 4202 |
-- For an exception returns a reference to the exception data: |
| 4203 |
-- Exception_Id!(Prefix'Reference) |
| 4204 |
|
| 4205 |
-- For a task it returns a reference to the _task_id component of |
| 4206 |
-- corresponding record: |
| 4207 |
|
| 4208 |
-- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined |
| 4209 |
|
| 4210 |
-- in Ada.Task_Identification |
| 4211 |
|
| 4212 |
when Attribute_Identity => Identity : declare |
| 4213 |
Id_Kind : Entity_Id; |
| 4214 |
|
| 4215 |
begin |
| 4216 |
if Ptyp = Standard_Exception_Type then |
| 4217 |
Id_Kind := RTE (RE_Exception_Id); |
| 4218 |
|
| 4219 |
if Present (Renamed_Entity (Entity (Pref))) then |
| 4220 |
Set_Entity (Pref, Renamed_Entity (Entity (Pref))); |
| 4221 |
end if; |
| 4222 |
|
| 4223 |
Rewrite (N, |
| 4224 |
Unchecked_Convert_To (Id_Kind, Make_Reference (Loc, Pref))); |
| 4225 |
else |
| 4226 |
Id_Kind := RTE (RO_AT_Task_Id); |
| 4227 |
|
| 4228 |
-- If the prefix is a task interface, the Task_Id is obtained |
| 4229 |
-- dynamically through a dispatching call, as for other task |
| 4230 |
-- attributes applied to interfaces. |
| 4231 |
|
| 4232 |
if Ada_Version >= Ada_2005 |
| 4233 |
and then Ekind (Ptyp) = E_Class_Wide_Type |
| 4234 |
and then Is_Interface (Ptyp) |
| 4235 |
and then Is_Task_Interface (Ptyp) |
| 4236 |
then |
| 4237 |
Rewrite (N, |
| 4238 |
Unchecked_Convert_To |
| 4239 |
(Id_Kind, Build_Disp_Get_Task_Id_Call (Pref))); |
| 4240 |
|
| 4241 |
else |
| 4242 |
Rewrite (N, |
| 4243 |
Unchecked_Convert_To (Id_Kind, Concurrent_Ref (Pref))); |
| 4244 |
end if; |
| 4245 |
end if; |
| 4246 |
|
| 4247 |
Analyze_And_Resolve (N, Id_Kind); |
| 4248 |
end Identity; |
| 4249 |
|
| 4250 |
----------- |
| 4251 |
-- Image -- |
| 4252 |
----------- |
| 4253 |
|
| 4254 |
when Attribute_Image => |
| 4255 |
|
| 4256 |
-- Leave attribute unexpanded in CodePeer mode: the gnat2scil |
| 4257 |
-- back-end knows how to handle this attribute directly. |
| 4258 |
|
| 4259 |
if CodePeer_Mode then |
| 4260 |
return; |
| 4261 |
end if; |
| 4262 |
|
| 4263 |
Exp_Imgv.Expand_Image_Attribute (N); |
| 4264 |
|
| 4265 |
--------- |
| 4266 |
-- Img -- |
| 4267 |
--------- |
| 4268 |
|
| 4269 |
-- X'Img is expanded to typ'Image (X), where typ is the type of X |
| 4270 |
|
| 4271 |
when Attribute_Img => |
| 4272 |
Exp_Imgv.Expand_Image_Attribute (N); |
| 4273 |
|
| 4274 |
----------- |
| 4275 |
-- Index -- |
| 4276 |
----------- |
| 4277 |
|
| 4278 |
-- Transforms 'Index attribute into a reference to the second formal of |
| 4279 |
-- the wrapper built for an entry family that has contract cases (see |
| 4280 |
-- Exp_Ch9.Build_Contract_Wrapper). |
| 4281 |
|
| 4282 |
when Attribute_Index => Index : declare |
| 4283 |
Entry_Id : constant Entity_Id := Entity (Pref); |
| 4284 |
Entry_Idx : constant Entity_Id := |
| 4285 |
Next_Entity |
| 4286 |
(First_Entity (Contract_Wrapper (Entry_Id))); |
| 4287 |
begin |
| 4288 |
Rewrite (N, New_Occurrence_Of (Entry_Idx, Loc)); |
| 4289 |
Analyze_And_Resolve (N, Typ); |
| 4290 |
end Index; |
| 4291 |
|
| 4292 |
----------------- |
| 4293 |
-- Initialized -- |
| 4294 |
----------------- |
| 4295 |
|
| 4296 |
-- For execution, we could either implement an approximation of this |
| 4297 |
-- aspect, or use Valid_Scalars as a first approximation. For now we do |
| 4298 |
-- the latter. |
| 4299 |
|
| 4300 |
when Attribute_Initialized => |
| 4301 |
|
| 4302 |
-- Do not expand 'Initialized in CodePeer mode, it will be handled |
| 4303 |
-- by the back-end directly. |
| 4304 |
|
| 4305 |
if CodePeer_Mode then |
| 4306 |
return; |
| 4307 |
end if; |
| 4308 |
|
| 4309 |
Rewrite |
| 4310 |
(N, |
| 4311 |
Make_Attribute_Reference |
| 4312 |
(Sloc => Loc, |
| 4313 |
Prefix => Pref, |
| 4314 |
Attribute_Name => Name_Valid_Scalars, |
| 4315 |
Expressions => Exprs)); |
| 4316 |
|
| 4317 |
Analyze_And_Resolve (N); |
| 4318 |
|
| 4319 |
----------- |
| 4320 |
-- Input -- |
| 4321 |
----------- |
| 4322 |
|
| 4323 |
when Attribute_Input => Input : declare |
| 4324 |
P_Type : constant Entity_Id := Entity (Pref); |
| 4325 |
B_Type : constant Entity_Id := Base_Type (P_Type); |
| 4326 |
U_Type : constant Entity_Id := Underlying_Type (P_Type); |
| 4327 |
Strm : constant Node_Id := First (Exprs); |
| 4328 |
Fname : Entity_Id; |
| 4329 |
Decl : Node_Id; |
| 4330 |
Call : Node_Id; |
| 4331 |
Prag : Node_Id; |
| 4332 |
Arg2 : Node_Id; |
| 4333 |
Rfunc : Node_Id; |
| 4334 |
|
| 4335 |
Cntrl : Node_Id := Empty; |
| 4336 |
-- Value for controlling argument in call. Always Empty except in |
| 4337 |
-- the dispatching (class-wide type) case, where it is a reference |
| 4338 |
-- to the dummy object initialized to the right internal tag. |
| 4339 |
|
| 4340 |
procedure Freeze_Stream_Subprogram (F : Entity_Id); |
| 4341 |
-- The expansion of the attribute reference may generate a call to |
| 4342 |
-- a user-defined stream subprogram that is frozen by the call. This |
| 4343 |
-- can lead to access-before-elaboration problem if the reference |
| 4344 |
-- appears in an object declaration and the subprogram body has not |
| 4345 |
-- been seen. The freezing of the subprogram requires special code |
| 4346 |
-- because it appears in an expanded context where expressions do |
| 4347 |
-- not freeze their constituents. |
| 4348 |
|
| 4349 |
------------------------------ |
| 4350 |
-- Freeze_Stream_Subprogram -- |
| 4351 |
------------------------------ |
| 4352 |
|
| 4353 |
procedure Freeze_Stream_Subprogram (F : Entity_Id) is |
| 4354 |
Decl : constant Node_Id := Unit_Declaration_Node (F); |
| 4355 |
Bod : Node_Id; |
| 4356 |
|
| 4357 |
begin |
| 4358 |
-- If this is user-defined subprogram, the corresponding |
| 4359 |
-- stream function appears as a renaming-as-body, and the |
| 4360 |
-- user subprogram must be retrieved by tree traversal. |
| 4361 |
|
| 4362 |
if Present (Decl) |
| 4363 |
and then Nkind (Decl) = N_Subprogram_Declaration |
| 4364 |
and then Present (Corresponding_Body (Decl)) |
| 4365 |
then |
| 4366 |
Bod := Corresponding_Body (Decl); |
| 4367 |
|
| 4368 |
if Nkind (Unit_Declaration_Node (Bod)) = |
| 4369 |
N_Subprogram_Renaming_Declaration |
| 4370 |
then |
| 4371 |
Set_Is_Frozen (Entity (Name (Unit_Declaration_Node (Bod)))); |
| 4372 |
end if; |
| 4373 |
end if; |
| 4374 |
end Freeze_Stream_Subprogram; |
| 4375 |
|
| 4376 |
-- Start of processing for Input |
| 4377 |
|
| 4378 |
begin |
| 4379 |
-- If no underlying type, we have an error that will be diagnosed |
| 4380 |
-- elsewhere, so here we just completely ignore the expansion. |
| 4381 |
|
| 4382 |
if No (U_Type) then |
| 4383 |
return; |
| 4384 |
end if; |
| 4385 |
|
| 4386 |
-- Stream operations can appear in user code even if the restriction |
| 4387 |
-- No_Streams is active (for example, when instantiating a predefined |
| 4388 |
-- container). In that case rewrite the attribute as a Raise to |
| 4389 |
-- prevent any run-time use. |
| 4390 |
|
| 4391 |
if Restriction_Active (No_Streams) then |
| 4392 |
Rewrite (N, |
| 4393 |
Make_Raise_Program_Error (Loc, |
| 4394 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 4395 |
Set_Etype (N, B_Type); |
| 4396 |
return; |
| 4397 |
end if; |
| 4398 |
|
| 4399 |
-- If there is a TSS for Input, just call it |
| 4400 |
|
| 4401 |
Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input, N); |
| 4402 |
|
| 4403 |
if No (Fname) then |
| 4404 |
|
| 4405 |
-- If there is a Stream_Convert pragma, use it, we rewrite |
| 4406 |
|
| 4407 |
-- sourcetyp'Input (stream) |
| 4408 |
|
| 4409 |
-- as |
| 4410 |
|
| 4411 |
-- sourcetyp (streamread (strmtyp'Input (stream))); |
| 4412 |
|
| 4413 |
-- where streamread is the given Read function that converts an |
| 4414 |
-- argument of type strmtyp to type sourcetyp or a type from which |
| 4415 |
-- it is derived (extra conversion required for the derived case). |
| 4416 |
|
| 4417 |
Prag := Get_Stream_Convert_Pragma (P_Type); |
| 4418 |
|
| 4419 |
if Present (Prag) then |
| 4420 |
Arg2 := Next (First (Pragma_Argument_Associations (Prag))); |
| 4421 |
Rfunc := Entity (Expression (Arg2)); |
| 4422 |
|
| 4423 |
Rewrite (N, |
| 4424 |
Convert_To (B_Type, |
| 4425 |
Make_Function_Call (Loc, |
| 4426 |
Name => New_Occurrence_Of (Rfunc, Loc), |
| 4427 |
Parameter_Associations => New_List ( |
| 4428 |
Make_Attribute_Reference (Loc, |
| 4429 |
Prefix => |
| 4430 |
New_Occurrence_Of |
| 4431 |
(Etype (First_Formal (Rfunc)), Loc), |
| 4432 |
Attribute_Name => Name_Input, |
| 4433 |
Expressions => Exprs))))); |
| 4434 |
|
| 4435 |
Analyze_And_Resolve (N, B_Type); |
| 4436 |
return; |
| 4437 |
|
| 4438 |
-- Limited types |
| 4439 |
|
| 4440 |
elsif Default_Streaming_Unavailable (U_Type) then |
| 4441 |
-- Do the same thing here as is done above in the |
| 4442 |
-- case where a No_Streams restriction is active. |
| 4443 |
|
| 4444 |
Rewrite (N, |
| 4445 |
Make_Raise_Program_Error (Loc, |
| 4446 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 4447 |
Set_Etype (N, B_Type); |
| 4448 |
return; |
| 4449 |
|
| 4450 |
-- Elementary types |
| 4451 |
|
| 4452 |
elsif Is_Elementary_Type (U_Type) then |
| 4453 |
|
| 4454 |
-- A special case arises if we have a defined _Read routine, |
| 4455 |
-- since in this case we are required to call this routine. |
| 4456 |
|
| 4457 |
if Present (Find_Inherited_TSS (P_Type, TSS_Stream_Read)) then |
| 4458 |
Build_Record_Or_Elementary_Input_Function |
| 4459 |
(P_Type, Decl, Fname); |
| 4460 |
Insert_Action (N, Decl); |
| 4461 |
|
| 4462 |
-- For normal cases, we call the I_xxx routine directly |
| 4463 |
|
| 4464 |
else |
| 4465 |
Rewrite (N, Build_Elementary_Input_Call (N)); |
| 4466 |
Analyze_And_Resolve (N, P_Type); |
| 4467 |
return; |
| 4468 |
end if; |
| 4469 |
|
| 4470 |
-- Array type case |
| 4471 |
|
| 4472 |
elsif Is_Array_Type (U_Type) then |
| 4473 |
declare |
| 4474 |
procedure Build_And_Insert_Array_Input_Func is |
| 4475 |
new Build_And_Insert_Type_Attr_Subp |
| 4476 |
(Build_Array_Input_Function); |
| 4477 |
begin |
| 4478 |
Build_And_Insert_Array_Input_Func |
| 4479 |
(Typ => Full_Base (U_Type), |
| 4480 |
Decl => Decl, |
| 4481 |
Subp => Fname, |
| 4482 |
Attr_Ref => N); |
| 4483 |
end; |
| 4484 |
|
| 4485 |
-- Dispatching case with class-wide type |
| 4486 |
|
| 4487 |
elsif Is_Class_Wide_Type (P_Type) then |
| 4488 |
|
| 4489 |
-- No need to do anything else compiling under restriction |
| 4490 |
-- No_Dispatching_Calls. During the semantic analysis we |
| 4491 |
-- already notified such violation. |
| 4492 |
|
| 4493 |
if Restriction_Active (No_Dispatching_Calls) then |
| 4494 |
return; |
| 4495 |
end if; |
| 4496 |
|
| 4497 |
declare |
| 4498 |
Rtyp : constant Entity_Id := Root_Type (P_Type); |
| 4499 |
|
| 4500 |
Expr : Node_Id; -- call to Descendant_Tag |
| 4501 |
Get_Tag : Node_Id; -- expression to read the 'Tag |
| 4502 |
|
| 4503 |
begin |
| 4504 |
-- Read the internal tag (RM 13.13.2(34)) and use it to |
| 4505 |
-- initialize a dummy tag value. We used to unconditionally |
| 4506 |
-- generate: |
| 4507 |
-- |
| 4508 |
-- Descendant_Tag (String'Input (Strm), P_Type); |
| 4509 |
-- |
| 4510 |
-- which turns into a call to String_Input_Blk_IO. However, |
| 4511 |
-- if the input is malformed, that could try to read an |
| 4512 |
-- enormous String, causing chaos. So instead we call |
| 4513 |
-- String_Input_Tag, which does the same thing as |
| 4514 |
-- String_Input_Blk_IO, except that if the String is |
| 4515 |
-- absurdly long, it raises an exception. |
| 4516 |
-- |
| 4517 |
-- However, if the No_Stream_Optimizations restriction |
| 4518 |
-- is active, we disable this unnecessary attempt at |
| 4519 |
-- robustness; we really need to read the string |
| 4520 |
-- character-by-character. |
| 4521 |
-- |
| 4522 |
-- This value is used only to provide a controlling |
| 4523 |
-- argument for the eventual _Input call. Descendant_Tag is |
| 4524 |
-- called rather than Internal_Tag to ensure that we have a |
| 4525 |
-- tag for a type that is descended from the prefix type and |
| 4526 |
-- declared at the same accessibility level (the exception |
| 4527 |
-- Tag_Error will be raised otherwise). The level check is |
| 4528 |
-- required for Ada 2005 because tagged types can be |
| 4529 |
-- extended in nested scopes (AI-344). |
| 4530 |
|
| 4531 |
-- Note: we used to generate an explicit declaration of a |
| 4532 |
-- constant Ada.Tags.Tag object, and use an occurrence of |
| 4533 |
-- this constant in Cntrl, but this caused a secondary stack |
| 4534 |
-- leak. |
| 4535 |
|
| 4536 |
if Restriction_Active (No_Stream_Optimizations) then |
| 4537 |
Get_Tag := |
| 4538 |
Make_Attribute_Reference (Loc, |
| 4539 |
Prefix => |
| 4540 |
New_Occurrence_Of (Standard_String, Loc), |
| 4541 |
Attribute_Name => Name_Input, |
| 4542 |
Expressions => New_List ( |
| 4543 |
Relocate_Node (Duplicate_Subexpr (Strm)))); |
| 4544 |
else |
| 4545 |
Get_Tag := |
| 4546 |
Make_Function_Call (Loc, |
| 4547 |
Name => |
| 4548 |
New_Occurrence_Of |
| 4549 |
(RTE (RE_String_Input_Tag), Loc), |
| 4550 |
Parameter_Associations => New_List ( |
| 4551 |
Relocate_Node (Duplicate_Subexpr (Strm)))); |
| 4552 |
end if; |
| 4553 |
|
| 4554 |
Expr := |
| 4555 |
Make_Function_Call (Loc, |
| 4556 |
Name => |
| 4557 |
New_Occurrence_Of (RTE (RE_Descendant_Tag), Loc), |
| 4558 |
Parameter_Associations => New_List ( |
| 4559 |
Get_Tag, |
| 4560 |
Make_Attribute_Reference (Loc, |
| 4561 |
Prefix => New_Occurrence_Of (P_Type, Loc), |
| 4562 |
Attribute_Name => Name_Tag))); |
| 4563 |
|
| 4564 |
Set_Etype (Expr, RTE (RE_Tag)); |
| 4565 |
|
| 4566 |
-- Now we need to get the entity for the call, and construct |
| 4567 |
-- a function call node, where we preset a reference to Dnn |
| 4568 |
-- as the controlling argument (doing an unchecked convert |
| 4569 |
-- to the class-wide tagged type to make it look like a real |
| 4570 |
-- tagged object). |
| 4571 |
|
| 4572 |
Fname := Find_Prim_Op (Rtyp, TSS_Stream_Input); |
| 4573 |
Cntrl := Unchecked_Convert_To (P_Type, Expr); |
| 4574 |
Set_Etype (Cntrl, P_Type); |
| 4575 |
Set_Parent (Cntrl, N); |
| 4576 |
end; |
| 4577 |
|
| 4578 |
-- For tagged types, use the primitive Input function |
| 4579 |
|
| 4580 |
elsif Is_Tagged_Type (U_Type) then |
| 4581 |
Fname := Find_Prim_Op (U_Type, TSS_Stream_Input); |
| 4582 |
|
| 4583 |
-- All other record type cases, including protected records. The |
| 4584 |
-- latter only arise for expander generated code for handling |
| 4585 |
-- shared passive partition access. |
| 4586 |
|
| 4587 |
else |
| 4588 |
pragma Assert |
| 4589 |
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); |
| 4590 |
|
| 4591 |
-- Ada 2005 (AI-216): Program_Error is raised executing default |
| 4592 |
-- implementation of the Input attribute of an unchecked union |
| 4593 |
-- type if the type lacks default discriminant values. |
| 4594 |
|
| 4595 |
if Is_Unchecked_Union (Base_Type (U_Type)) |
| 4596 |
and then |
| 4597 |
No (Discriminant_Default_Value (First_Discriminant (U_Type))) |
| 4598 |
then |
| 4599 |
Rewrite (N, |
| 4600 |
Make_Raise_Program_Error (Loc, |
| 4601 |
Reason => PE_Unchecked_Union_Restriction)); |
| 4602 |
Set_Etype (N, B_Type); |
| 4603 |
return; |
| 4604 |
end if; |
| 4605 |
|
| 4606 |
-- Build the type's Input function, passing the subtype rather |
| 4607 |
-- than its base type, because checks are needed in the case of |
| 4608 |
-- constrained discriminants (see Ada 2012 AI05-0192). |
| 4609 |
-- |
| 4610 |
-- ??? Is this correct in the case where the prefix of the |
| 4611 |
-- attribute is a constrained subtype of a type whose |
| 4612 |
-- first named subtype is unconstrained? Shouldn't we be |
| 4613 |
-- passing in the first named subtype of the type? |
| 4614 |
|
| 4615 |
declare |
| 4616 |
procedure Build_And_Insert_Record_Input_Func is |
| 4617 |
new Build_And_Insert_Type_Attr_Subp |
| 4618 |
(Build_Record_Or_Elementary_Input_Function); |
| 4619 |
begin |
| 4620 |
Build_And_Insert_Record_Input_Func |
| 4621 |
(Typ => U_Type, |
| 4622 |
Decl => Decl, |
| 4623 |
Subp => Fname, |
| 4624 |
Attr_Ref => N); |
| 4625 |
end; |
| 4626 |
|
| 4627 |
if Nkind (Parent (N)) = N_Object_Declaration |
| 4628 |
and then Is_Record_Type (U_Type) |
| 4629 |
then |
| 4630 |
-- The stream function may contain calls to user-defined |
| 4631 |
-- Read procedures for individual components. |
| 4632 |
|
| 4633 |
declare |
| 4634 |
Comp : Entity_Id; |
| 4635 |
Func : Entity_Id; |
| 4636 |
|
| 4637 |
begin |
| 4638 |
Comp := First_Component (U_Type); |
| 4639 |
while Present (Comp) loop |
| 4640 |
Func := |
| 4641 |
Find_Stream_Subprogram |
| 4642 |
(Etype (Comp), TSS_Stream_Read, N); |
| 4643 |
|
| 4644 |
if Present (Func) then |
| 4645 |
Freeze_Stream_Subprogram (Func); |
| 4646 |
end if; |
| 4647 |
|
| 4648 |
Next_Component (Comp); |
| 4649 |
end loop; |
| 4650 |
end; |
| 4651 |
end if; |
| 4652 |
end if; |
| 4653 |
end if; |
| 4654 |
|
| 4655 |
-- If we fall through, Fname is the function to be called. The result |
| 4656 |
-- is obtained by calling the appropriate function, then converting |
| 4657 |
-- the result. The conversion does a subtype check. |
| 4658 |
|
| 4659 |
Call := |
| 4660 |
Make_Function_Call (Loc, |
| 4661 |
Name => New_Occurrence_Of (Fname, Loc), |
| 4662 |
Parameter_Associations => New_List ( |
| 4663 |
Relocate_Node (Strm))); |
| 4664 |
|
| 4665 |
Set_Controlling_Argument (Call, Cntrl); |
| 4666 |
Rewrite (N, Unchecked_Convert_To (P_Type, Call)); |
| 4667 |
Analyze_And_Resolve (N, P_Type); |
| 4668 |
|
| 4669 |
if Nkind (Parent (N)) = N_Object_Declaration then |
| 4670 |
Freeze_Stream_Subprogram (Fname); |
| 4671 |
end if; |
| 4672 |
|
| 4673 |
if not Is_Tagged_Type (P_Type) then |
| 4674 |
Cached_Attribute_Ops.Input_Map.Set (U_Type, Fname); |
| 4675 |
end if; |
| 4676 |
end Input; |
| 4677 |
|
| 4678 |
------------------- |
| 4679 |
-- Invalid_Value -- |
| 4680 |
------------------- |
| 4681 |
|
| 4682 |
when Attribute_Invalid_Value => |
| 4683 |
Rewrite (N, Get_Simple_Init_Val (Ptyp, N)); |
| 4684 |
|
| 4685 |
-- The value produced may be a conversion of a literal, which must be |
| 4686 |
-- resolved to establish its proper type. |
| 4687 |
|
| 4688 |
Analyze_And_Resolve (N); |
| 4689 |
|
| 4690 |
-------------- |
| 4691 |
-- Last_Bit -- |
| 4692 |
-------------- |
| 4693 |
|
| 4694 |
-- We leave the computation up to the back end, since we don't know what |
| 4695 |
-- layout will be chosen if no component clause was specified. |
| 4696 |
|
| 4697 |
when Attribute_Last_Bit => |
| 4698 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 4699 |
|
| 4700 |
------------------ |
| 4701 |
-- Leading_Part -- |
| 4702 |
------------------ |
| 4703 |
|
| 4704 |
-- Transforms 'Leading_Part into a call to the floating-point attribute |
| 4705 |
-- function Leading_Part in Fat_xxx (where xxx is the root type) |
| 4706 |
|
| 4707 |
-- Note: strictly, we should generate special case code to deal with |
| 4708 |
-- absurdly large positive arguments (greater than Integer'Last), which |
| 4709 |
-- result in returning the first argument unchanged, but it hardly seems |
| 4710 |
-- worth the effort. We raise constraint error for absurdly negative |
| 4711 |
-- arguments which is fine. |
| 4712 |
|
| 4713 |
when Attribute_Leading_Part => |
| 4714 |
Expand_Fpt_Attribute_RI (N); |
| 4715 |
|
| 4716 |
------------ |
| 4717 |
-- Length -- |
| 4718 |
------------ |
| 4719 |
|
| 4720 |
when Attribute_Length => Length : declare |
| 4721 |
Ityp : Entity_Id; |
| 4722 |
Xnum : Uint; |
| 4723 |
|
| 4724 |
begin |
| 4725 |
-- Processing for packed array types |
| 4726 |
|
| 4727 |
if Is_Packed_Array (Ptyp) then |
| 4728 |
Ityp := Get_Index_Subtype (N); |
| 4729 |
|
| 4730 |
-- If the index type, Ityp, is an enumeration type with holes, |
| 4731 |
-- then we calculate X'Length explicitly using |
| 4732 |
|
| 4733 |
-- Typ'Max |
| 4734 |
-- (0, Ityp'Pos (X'Last (N)) - |
| 4735 |
-- Ityp'Pos (X'First (N)) + 1); |
| 4736 |
|
| 4737 |
-- Since the bounds in the template are the representation values |
| 4738 |
-- and the back end would get the wrong value. |
| 4739 |
|
| 4740 |
if Is_Enumeration_Type (Ityp) |
| 4741 |
and then Present (Enum_Pos_To_Rep (Base_Type (Ityp))) |
| 4742 |
then |
| 4743 |
if No (Exprs) then |
| 4744 |
Xnum := Uint_1; |
| 4745 |
else |
| 4746 |
Xnum := Expr_Value (First (Expressions (N))); |
| 4747 |
end if; |
| 4748 |
|
| 4749 |
Rewrite (N, |
| 4750 |
Make_Attribute_Reference (Loc, |
| 4751 |
Prefix => New_Occurrence_Of (Typ, Loc), |
| 4752 |
Attribute_Name => Name_Max, |
| 4753 |
Expressions => New_List |
| 4754 |
(Make_Integer_Literal (Loc, 0), |
| 4755 |
|
| 4756 |
Make_Op_Add (Loc, |
| 4757 |
Left_Opnd => |
| 4758 |
Make_Op_Subtract (Loc, |
| 4759 |
Left_Opnd => |
| 4760 |
Make_Attribute_Reference (Loc, |
| 4761 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 4762 |
Attribute_Name => Name_Pos, |
| 4763 |
|
| 4764 |
Expressions => New_List ( |
| 4765 |
Make_Attribute_Reference (Loc, |
| 4766 |
Prefix => Duplicate_Subexpr (Pref), |
| 4767 |
Attribute_Name => Name_Last, |
| 4768 |
Expressions => New_List ( |
| 4769 |
Make_Integer_Literal (Loc, Xnum))))), |
| 4770 |
|
| 4771 |
Right_Opnd => |
| 4772 |
Make_Attribute_Reference (Loc, |
| 4773 |
Prefix => New_Occurrence_Of (Ityp, Loc), |
| 4774 |
Attribute_Name => Name_Pos, |
| 4775 |
|
| 4776 |
Expressions => New_List ( |
| 4777 |
Make_Attribute_Reference (Loc, |
| 4778 |
Prefix => |
| 4779 |
Duplicate_Subexpr_No_Checks (Pref), |
| 4780 |
Attribute_Name => Name_First, |
| 4781 |
Expressions => New_List ( |
| 4782 |
Make_Integer_Literal (Loc, Xnum)))))), |
| 4783 |
|
| 4784 |
Right_Opnd => Make_Integer_Literal (Loc, 1))))); |
| 4785 |
|
| 4786 |
Analyze_And_Resolve (N, Typ, Suppress => All_Checks); |
| 4787 |
return; |
| 4788 |
|
| 4789 |
-- If the prefix type is a constrained packed array type which |
| 4790 |
-- already has a Packed_Array_Impl_Type representation defined, |
| 4791 |
-- then replace this attribute with a reference to 'Range_Length |
| 4792 |
-- of the appropriate index subtype (since otherwise the |
| 4793 |
-- back end will try to give us the value of 'Length for |
| 4794 |
-- this implementation type). |
| 4795 |
|
| 4796 |
elsif Is_Constrained (Ptyp) then |
| 4797 |
Rewrite (N, |
| 4798 |
Make_Attribute_Reference (Loc, |
| 4799 |
Attribute_Name => Name_Range_Length, |
| 4800 |
Prefix => New_Occurrence_Of (Ityp, Loc))); |
| 4801 |
Analyze_And_Resolve (N, Typ); |
| 4802 |
end if; |
| 4803 |
|
| 4804 |
-- Access type case |
| 4805 |
|
| 4806 |
elsif Is_Access_Type (Ptyp) then |
| 4807 |
Apply_Access_Check (N); |
| 4808 |
|
| 4809 |
-- If the designated type is a packed array type, then we convert |
| 4810 |
-- the reference to: |
| 4811 |
|
| 4812 |
-- typ'Max (0, 1 + |
| 4813 |
-- xtyp'Pos (Pref'Last (Expr)) - |
| 4814 |
-- xtyp'Pos (Pref'First (Expr))); |
| 4815 |
|
| 4816 |
-- This is a bit complex, but it is the easiest thing to do that |
| 4817 |
-- works in all cases including enum types with holes xtyp here |
| 4818 |
-- is the appropriate index type. |
| 4819 |
|
| 4820 |
declare |
| 4821 |
Dtyp : constant Entity_Id := Designated_Type (Ptyp); |
| 4822 |
Xtyp : Entity_Id; |
| 4823 |
|
| 4824 |
begin |
| 4825 |
if Is_Packed_Array (Dtyp) then |
| 4826 |
Xtyp := Get_Index_Subtype (N); |
| 4827 |
|
| 4828 |
Rewrite (N, |
| 4829 |
Make_Attribute_Reference (Loc, |
| 4830 |
Prefix => New_Occurrence_Of (Typ, Loc), |
| 4831 |
Attribute_Name => Name_Max, |
| 4832 |
Expressions => New_List ( |
| 4833 |
Make_Integer_Literal (Loc, 0), |
| 4834 |
|
| 4835 |
Make_Op_Add (Loc, |
| 4836 |
Make_Integer_Literal (Loc, 1), |
| 4837 |
Make_Op_Subtract (Loc, |
| 4838 |
Left_Opnd => |
| 4839 |
Make_Attribute_Reference (Loc, |
| 4840 |
Prefix => New_Occurrence_Of (Xtyp, Loc), |
| 4841 |
Attribute_Name => Name_Pos, |
| 4842 |
Expressions => New_List ( |
| 4843 |
Make_Attribute_Reference (Loc, |
| 4844 |
Prefix => Duplicate_Subexpr (Pref), |
| 4845 |
Attribute_Name => Name_Last, |
| 4846 |
Expressions => |
| 4847 |
New_Copy_List (Exprs)))), |
| 4848 |
|
| 4849 |
Right_Opnd => |
| 4850 |
Make_Attribute_Reference (Loc, |
| 4851 |
Prefix => New_Occurrence_Of (Xtyp, Loc), |
| 4852 |
Attribute_Name => Name_Pos, |
| 4853 |
Expressions => New_List ( |
| 4854 |
Make_Attribute_Reference (Loc, |
| 4855 |
Prefix => |
| 4856 |
Duplicate_Subexpr_No_Checks (Pref), |
| 4857 |
Attribute_Name => Name_First, |
| 4858 |
Expressions => |
| 4859 |
New_Copy_List (Exprs))))))))); |
| 4860 |
|
| 4861 |
Analyze_And_Resolve (N, Typ); |
| 4862 |
end if; |
| 4863 |
end; |
| 4864 |
|
| 4865 |
-- Overflow-related transformations need Length attribute rewritten |
| 4866 |
-- using non-attribute expressions. So generate |
| 4867 |
-- (if Pref'First > Pref'Last |
| 4868 |
-- then 0 |
| 4869 |
-- else ((Pref'Last - Pref'First) + 1)) . |
| 4870 |
|
| 4871 |
elsif Overflow_Check_Mode in Minimized_Or_Eliminated |
| 4872 |
|
| 4873 |
-- This Comes_From_Source test fixes a regression test failure |
| 4874 |
-- involving a Length attribute reference generated as part of |
| 4875 |
-- the expansion of a concatentation operator; it is unclear |
| 4876 |
-- whether this is the right solution to that problem. |
| 4877 |
|
| 4878 |
and then Comes_From_Source (N) |
| 4879 |
|
| 4880 |
-- This Base_Type equality test is so that we only perform this |
| 4881 |
-- transformation if we can do it without introducing |
| 4882 |
-- a type conversion anywhere in the resulting expansion; |
| 4883 |
-- a type conversion is just as bad as a Length attribute |
| 4884 |
-- reference for those overflow-related transformations. |
| 4885 |
|
| 4886 |
and then Btyp = Base_Type (Get_Index_Subtype (N)) |
| 4887 |
|
| 4888 |
then |
| 4889 |
declare |
| 4890 |
function Prefix_Bound |
| 4891 |
(Bound_Attr_Name : Name_Id; Is_First_Copy : Boolean := False) |
| 4892 |
return Node_Id; |
| 4893 |
-- constructs a Pref'First or Pref'Last attribute reference |
| 4894 |
|
| 4895 |
------------------ |
| 4896 |
-- Prefix_Bound -- |
| 4897 |
------------------ |
| 4898 |
|
| 4899 |
function Prefix_Bound |
| 4900 |
(Bound_Attr_Name : Name_Id; Is_First_Copy : Boolean := False) |
| 4901 |
return Node_Id |
| 4902 |
is |
| 4903 |
Prefix : constant Node_Id := |
| 4904 |
(if Is_First_Copy |
| 4905 |
then Duplicate_Subexpr (Pref) |
| 4906 |
else Duplicate_Subexpr_No_Checks (Pref)); |
| 4907 |
begin |
| 4908 |
return Make_Attribute_Reference (Loc, |
| 4909 |
Prefix => Prefix, |
| 4910 |
Attribute_Name => Bound_Attr_Name, |
| 4911 |
Expressions => New_Copy_List (Exprs)); |
| 4912 |
end Prefix_Bound; |
| 4913 |
begin |
| 4914 |
Rewrite (N, |
| 4915 |
Make_If_Expression (Loc, |
| 4916 |
Expressions => |
| 4917 |
New_List ( |
| 4918 |
Node1 => Make_Op_Gt (Loc, |
| 4919 |
Prefix_Bound (Name_First, |
| 4920 |
Is_First_Copy => True), |
| 4921 |
Prefix_Bound (Name_Last)), |
| 4922 |
Node2 => Make_Integer_Literal (Loc, 0), |
| 4923 |
Node3 => Make_Op_Add (Loc, |
| 4924 |
Make_Op_Subtract (Loc, |
| 4925 |
Prefix_Bound (Name_Last), |
| 4926 |
Prefix_Bound (Name_First)), |
| 4927 |
Make_Integer_Literal (Loc, 1))))); |
| 4928 |
|
| 4929 |
Analyze_And_Resolve (N, Typ); |
| 4930 |
end; |
| 4931 |
|
| 4932 |
-- Otherwise leave it to the back end |
| 4933 |
|
| 4934 |
else |
| 4935 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 4936 |
end if; |
| 4937 |
end Length; |
| 4938 |
|
| 4939 |
-- Attribute Loop_Entry is replaced with a reference to a constant value |
| 4940 |
-- which captures the prefix at the entry point of the related loop. The |
| 4941 |
-- loop itself may be transformed into a conditional block. |
| 4942 |
|
| 4943 |
when Attribute_Loop_Entry => |
| 4944 |
Expand_Loop_Entry_Attribute (N); |
| 4945 |
|
| 4946 |
------------- |
| 4947 |
-- Machine -- |
| 4948 |
------------- |
| 4949 |
|
| 4950 |
-- Transforms 'Machine into a call to the floating-point attribute |
| 4951 |
-- function Machine in Fat_xxx (where xxx is the root type). |
| 4952 |
-- Expansion is avoided for cases the back end can handle directly. |
| 4953 |
|
| 4954 |
when Attribute_Machine => |
| 4955 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 4956 |
Expand_Fpt_Attribute_R (N); |
| 4957 |
end if; |
| 4958 |
|
| 4959 |
---------------------- |
| 4960 |
-- Machine_Rounding -- |
| 4961 |
---------------------- |
| 4962 |
|
| 4963 |
-- Transforms 'Machine_Rounding into a call to the floating-point |
| 4964 |
-- attribute function Machine_Rounding in Fat_xxx (where xxx is the root |
| 4965 |
-- type). Expansion is avoided for cases the back end can handle |
| 4966 |
-- directly. |
| 4967 |
|
| 4968 |
when Attribute_Machine_Rounding => |
| 4969 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 4970 |
Expand_Fpt_Attribute_R (N); |
| 4971 |
end if; |
| 4972 |
|
| 4973 |
------------------ |
| 4974 |
-- Machine_Size -- |
| 4975 |
------------------ |
| 4976 |
|
| 4977 |
-- Machine_Size is equivalent to Object_Size, so transform it into |
| 4978 |
-- Object_Size and that way the back end never sees Machine_Size. |
| 4979 |
|
| 4980 |
when Attribute_Machine_Size => |
| 4981 |
Rewrite (N, |
| 4982 |
Make_Attribute_Reference (Loc, |
| 4983 |
Prefix => Prefix (N), |
| 4984 |
Attribute_Name => Name_Object_Size)); |
| 4985 |
|
| 4986 |
Analyze_And_Resolve (N, Typ); |
| 4987 |
|
| 4988 |
-------------- |
| 4989 |
-- Mantissa -- |
| 4990 |
-------------- |
| 4991 |
|
| 4992 |
-- The only case that can get this far is the dynamic case of the old |
| 4993 |
-- Ada 83 Mantissa attribute for the fixed-point case. For this case, |
| 4994 |
-- we expand: |
| 4995 |
|
| 4996 |
-- typ'Mantissa |
| 4997 |
|
| 4998 |
-- into |
| 4999 |
|
| 5000 |
-- ityp (System.Mantissa.Mantissa_Value |
| 5001 |
-- (Integer'Integer_Value (typ'First), |
| 5002 |
-- Integer'Integer_Value (typ'Last))); |
| 5003 |
|
| 5004 |
when Attribute_Mantissa => |
| 5005 |
Rewrite (N, |
| 5006 |
Convert_To (Typ, |
| 5007 |
Make_Function_Call (Loc, |
| 5008 |
Name => |
| 5009 |
New_Occurrence_Of (RTE (RE_Mantissa_Value), Loc), |
| 5010 |
|
| 5011 |
Parameter_Associations => New_List ( |
| 5012 |
Make_Attribute_Reference (Loc, |
| 5013 |
Prefix => New_Occurrence_Of (Standard_Integer, Loc), |
| 5014 |
Attribute_Name => Name_Integer_Value, |
| 5015 |
Expressions => New_List ( |
| 5016 |
Make_Attribute_Reference (Loc, |
| 5017 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 5018 |
Attribute_Name => Name_First))), |
| 5019 |
|
| 5020 |
Make_Attribute_Reference (Loc, |
| 5021 |
Prefix => New_Occurrence_Of (Standard_Integer, Loc), |
| 5022 |
Attribute_Name => Name_Integer_Value, |
| 5023 |
Expressions => New_List ( |
| 5024 |
Make_Attribute_Reference (Loc, |
| 5025 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 5026 |
Attribute_Name => Name_Last))))))); |
| 5027 |
|
| 5028 |
Analyze_And_Resolve (N, Typ); |
| 5029 |
|
| 5030 |
--------- |
| 5031 |
-- Max -- |
| 5032 |
--------- |
| 5033 |
|
| 5034 |
when Attribute_Max => |
| 5035 |
Expand_Min_Max_Attribute (N); |
| 5036 |
|
| 5037 |
---------------------------------- |
| 5038 |
-- Max_Size_In_Storage_Elements -- |
| 5039 |
---------------------------------- |
| 5040 |
|
| 5041 |
when Attribute_Max_Size_In_Storage_Elements => declare |
| 5042 |
Typ : constant Entity_Id := Etype (N); |
| 5043 |
|
| 5044 |
begin |
| 5045 |
-- Tranform T'Class'Max_Size_In_Storage_Elements (for any T) into |
| 5046 |
-- Storage_Count'Pos (Storage_Count'Last), because it must include |
| 5047 |
-- all descendants, which can be arbitrarily large. Note that the |
| 5048 |
-- back end must not see any 'Class attribute references. |
| 5049 |
-- The 'Pos is to make it be of type universal_integer. |
| 5050 |
-- |
| 5051 |
-- ???If T'Class'Size is specified, it should probably affect |
| 5052 |
-- T'Class'Max_Size_In_Storage_Elements accordingly. |
| 5053 |
|
| 5054 |
if Is_Entity_Name (Pref) |
| 5055 |
and then Is_Class_Wide_Type (Entity (Pref)) |
| 5056 |
then |
| 5057 |
declare |
| 5058 |
Storage_Count_Type : constant Entity_Id := |
| 5059 |
RTE (RE_Storage_Count); |
| 5060 |
Attr : constant Node_Id := |
| 5061 |
Make_Attribute_Reference (Loc, |
| 5062 |
Prefix => New_Occurrence_Of (Storage_Count_Type, Loc), |
| 5063 |
Attribute_Name => Name_Pos, |
| 5064 |
Expressions => New_List ( |
| 5065 |
Make_Attribute_Reference (Loc, |
| 5066 |
Prefix => New_Occurrence_Of (Storage_Count_Type, Loc), |
| 5067 |
Attribute_Name => Name_Last))); |
| 5068 |
begin |
| 5069 |
Rewrite (N, Attr); |
| 5070 |
Analyze_And_Resolve (N, Typ); |
| 5071 |
return; |
| 5072 |
end; |
| 5073 |
|
| 5074 |
-- Heap-allocated controlled objects contain two extra pointers which |
| 5075 |
-- are not part of the actual type. Transform the attribute reference |
| 5076 |
-- into a runtime expression to add the size of the hidden header. |
| 5077 |
|
| 5078 |
elsif Needs_Finalization (Ptyp) |
| 5079 |
and then not Header_Size_Added (N) |
| 5080 |
then |
| 5081 |
Set_Header_Size_Added (N); |
| 5082 |
|
| 5083 |
-- Generate: |
| 5084 |
-- P'Max_Size_In_Storage_Elements + |
| 5085 |
-- Typ (Header_Size_With_Padding (Ptyp'Alignment)) |
| 5086 |
|
| 5087 |
Rewrite (N, |
| 5088 |
Make_Op_Add (Loc, |
| 5089 |
Left_Opnd => Relocate_Node (N), |
| 5090 |
Right_Opnd => |
| 5091 |
Convert_To (Typ, |
| 5092 |
Make_Function_Call (Loc, |
| 5093 |
Name => |
| 5094 |
New_Occurrence_Of |
| 5095 |
(RTE (RE_Header_Size_With_Padding), Loc), |
| 5096 |
|
| 5097 |
Parameter_Associations => New_List ( |
| 5098 |
Make_Attribute_Reference (Loc, |
| 5099 |
Prefix => |
| 5100 |
New_Occurrence_Of (Ptyp, Loc), |
| 5101 |
Attribute_Name => Name_Alignment)))))); |
| 5102 |
|
| 5103 |
Analyze_And_Resolve (N, Typ); |
| 5104 |
return; |
| 5105 |
end if; |
| 5106 |
|
| 5107 |
-- In the other cases apply the required checks |
| 5108 |
|
| 5109 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 5110 |
end; |
| 5111 |
|
| 5112 |
-------------------- |
| 5113 |
-- Mechanism_Code -- |
| 5114 |
-------------------- |
| 5115 |
|
| 5116 |
when Attribute_Mechanism_Code => |
| 5117 |
|
| 5118 |
-- We must replace the prefix in the renamed case |
| 5119 |
|
| 5120 |
if Is_Entity_Name (Pref) |
| 5121 |
and then Present (Alias (Entity (Pref))) |
| 5122 |
then |
| 5123 |
Set_Renamed_Subprogram (Pref, Alias (Entity (Pref))); |
| 5124 |
end if; |
| 5125 |
|
| 5126 |
--------- |
| 5127 |
-- Min -- |
| 5128 |
--------- |
| 5129 |
|
| 5130 |
when Attribute_Min => |
| 5131 |
Expand_Min_Max_Attribute (N); |
| 5132 |
|
| 5133 |
--------- |
| 5134 |
-- Mod -- |
| 5135 |
--------- |
| 5136 |
|
| 5137 |
when Attribute_Mod => Mod_Case : declare |
| 5138 |
Arg : constant Node_Id := Relocate_Node (First (Exprs)); |
| 5139 |
Hi : constant Node_Id := Type_High_Bound (Base_Type (Etype (Arg))); |
| 5140 |
Modv : constant Uint := Modulus (Btyp); |
| 5141 |
|
| 5142 |
begin |
| 5143 |
|
| 5144 |
-- This is not so simple. The issue is what type to use for the |
| 5145 |
-- computation of the modular value. In addition we need to use |
| 5146 |
-- the base type as above to retrieve a static bound for the |
| 5147 |
-- comparisons that follow. |
| 5148 |
|
| 5149 |
-- The easy case is when the modulus value is within the bounds |
| 5150 |
-- of the signed integer type of the argument. In this case we can |
| 5151 |
-- just do the computation in that signed integer type, and then |
| 5152 |
-- do an ordinary conversion to the target type. |
| 5153 |
|
| 5154 |
if Modv <= Expr_Value (Hi) then |
| 5155 |
Rewrite (N, |
| 5156 |
Convert_To (Btyp, |
| 5157 |
Make_Op_Mod (Loc, |
| 5158 |
Left_Opnd => Arg, |
| 5159 |
Right_Opnd => Make_Integer_Literal (Loc, Modv)))); |
| 5160 |
|
| 5161 |
-- Here we know that the modulus is larger than type'Last of the |
| 5162 |
-- integer type. There are two cases to consider: |
| 5163 |
|
| 5164 |
-- a) The integer value is non-negative. In this case, it is |
| 5165 |
-- returned as the result (since it is less than the modulus). |
| 5166 |
|
| 5167 |
-- b) The integer value is negative. In this case, we know that the |
| 5168 |
-- result is modulus + value, where the value might be as small as |
| 5169 |
-- -modulus. The trouble is what type do we use to do the subtract. |
| 5170 |
-- No type will do, since modulus can be as big as 2**128, and no |
| 5171 |
-- integer type accommodates this value. Let's do bit of algebra |
| 5172 |
|
| 5173 |
-- modulus + value |
| 5174 |
-- = modulus - (-value) |
| 5175 |
-- = (modulus - 1) - (-value - 1) |
| 5176 |
|
| 5177 |
-- Now modulus - 1 is certainly in range of the modular type. |
| 5178 |
-- -value is in the range 1 .. modulus, so -value -1 is in the |
| 5179 |
-- range 0 .. modulus-1 which is in range of the modular type. |
| 5180 |
-- Furthermore, (-value - 1) can be expressed as -(value + 1) |
| 5181 |
-- which we can compute using the integer base type. |
| 5182 |
|
| 5183 |
-- Once this is done we analyze the if expression without range |
| 5184 |
-- checks, because we know everything is in range, and we want |
| 5185 |
-- to prevent spurious warnings on either branch. |
| 5186 |
|
| 5187 |
else |
| 5188 |
Rewrite (N, |
| 5189 |
Make_If_Expression (Loc, |
| 5190 |
Expressions => New_List ( |
| 5191 |
Make_Op_Ge (Loc, |
| 5192 |
Left_Opnd => Duplicate_Subexpr (Arg), |
| 5193 |
Right_Opnd => Make_Integer_Literal (Loc, 0)), |
| 5194 |
|
| 5195 |
Convert_To (Btyp, |
| 5196 |
Duplicate_Subexpr_No_Checks (Arg)), |
| 5197 |
|
| 5198 |
Make_Op_Subtract (Loc, |
| 5199 |
Left_Opnd => |
| 5200 |
Make_Integer_Literal (Loc, |
| 5201 |
Intval => Modv - 1), |
| 5202 |
Right_Opnd => |
| 5203 |
Convert_To (Btyp, |
| 5204 |
Make_Op_Minus (Loc, |
| 5205 |
Right_Opnd => |
| 5206 |
Make_Op_Add (Loc, |
| 5207 |
Left_Opnd => Duplicate_Subexpr_No_Checks (Arg), |
| 5208 |
Right_Opnd => |
| 5209 |
Make_Integer_Literal (Loc, |
| 5210 |
Intval => 1)))))))); |
| 5211 |
|
| 5212 |
end if; |
| 5213 |
|
| 5214 |
Analyze_And_Resolve (N, Btyp, Suppress => All_Checks); |
| 5215 |
end Mod_Case; |
| 5216 |
|
| 5217 |
----------- |
| 5218 |
-- Model -- |
| 5219 |
----------- |
| 5220 |
|
| 5221 |
-- Transforms 'Model into a call to the floating-point attribute |
| 5222 |
-- function Model in Fat_xxx (where xxx is the root type). |
| 5223 |
-- Expansion is avoided for cases the back end can handle directly. |
| 5224 |
|
| 5225 |
when Attribute_Model => |
| 5226 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 5227 |
Expand_Fpt_Attribute_R (N); |
| 5228 |
end if; |
| 5229 |
|
| 5230 |
----------------- |
| 5231 |
-- Object_Size -- |
| 5232 |
----------------- |
| 5233 |
|
| 5234 |
-- The processing for Object_Size shares the processing for Size |
| 5235 |
|
| 5236 |
--------- |
| 5237 |
-- Old -- |
| 5238 |
--------- |
| 5239 |
|
| 5240 |
when Attribute_Old => Old : declare |
| 5241 |
CW_Temp : Entity_Id; |
| 5242 |
CW_Typ : Entity_Id; |
| 5243 |
Decl : Node_Id; |
| 5244 |
Ins_Nod : Node_Id; |
| 5245 |
Temp : Entity_Id; |
| 5246 |
|
| 5247 |
use Old_Attr_Util.Conditional_Evaluation; |
| 5248 |
use Old_Attr_Util.Indirect_Temps; |
| 5249 |
begin |
| 5250 |
-- 'Old can only appear in the case where local contract-related |
| 5251 |
-- wrapper has been generated with the purpose of wrapping the |
| 5252 |
-- original declarations and statements. |
| 5253 |
|
| 5254 |
Temp := Make_Temporary (Loc, 'T', Pref); |
| 5255 |
|
| 5256 |
-- Set the entity kind now in order to mark the temporary as a |
| 5257 |
-- handler of attribute 'Old's prefix. |
| 5258 |
|
| 5259 |
Mutate_Ekind (Temp, E_Constant); |
| 5260 |
Set_Stores_Attribute_Old_Prefix (Temp); |
| 5261 |
|
| 5262 |
-- Locate the insertion place of the internal temporary that saves |
| 5263 |
-- the 'Old value. |
| 5264 |
|
| 5265 |
Ins_Nod := N; |
| 5266 |
while Nkind (Ins_Nod) /= N_Subprogram_Body loop |
| 5267 |
Ins_Nod := Parent (Ins_Nod); |
| 5268 |
end loop; |
| 5269 |
|
| 5270 |
pragma Assert (Present (Wrapped_Statements |
| 5271 |
(if Acts_As_Spec (Ins_Nod) |
| 5272 |
then Defining_Unit_Name (Specification (Ins_Nod)) |
| 5273 |
else Corresponding_Spec (Ins_Nod)))); |
| 5274 |
|
| 5275 |
Ins_Nod := Last (Declarations (Ins_Nod)); |
| 5276 |
|
| 5277 |
if Eligible_For_Conditional_Evaluation (N) then |
| 5278 |
declare |
| 5279 |
Eval_Stmts : constant List_Id := New_List; |
| 5280 |
|
| 5281 |
procedure Append_For_Indirect_Temp |
| 5282 |
(N : Node_Id; Is_Eval_Stmt : Boolean); |
| 5283 |
-- Append either a declaration (which is to be elaborated |
| 5284 |
-- unconditionally) or an evaluation statement (which is |
| 5285 |
-- to be executed conditionally). |
| 5286 |
|
| 5287 |
------------------------------ |
| 5288 |
-- Append_For_Indirect_Temp -- |
| 5289 |
------------------------------ |
| 5290 |
|
| 5291 |
procedure Append_For_Indirect_Temp |
| 5292 |
(N : Node_Id; Is_Eval_Stmt : Boolean) |
| 5293 |
is |
| 5294 |
begin |
| 5295 |
if Is_Eval_Stmt then |
| 5296 |
Append_To (Eval_Stmts, N); |
| 5297 |
else |
| 5298 |
Insert_Before_And_Analyze (Ins_Nod, N); |
| 5299 |
end if; |
| 5300 |
end Append_For_Indirect_Temp; |
| 5301 |
|
| 5302 |
procedure Declare_Indirect_Temporary is new |
| 5303 |
Declare_Indirect_Temp |
| 5304 |
(Append_Item => Append_For_Indirect_Temp); |
| 5305 |
begin |
| 5306 |
Declare_Indirect_Temporary |
| 5307 |
(Attr_Prefix => Pref, Indirect_Temp => Temp); |
| 5308 |
|
| 5309 |
Insert_After_And_Analyze ( |
| 5310 |
Ins_Nod, |
| 5311 |
Make_If_Statement |
| 5312 |
(Sloc => Loc, |
| 5313 |
Condition => Conditional_Evaluation_Condition (N), |
| 5314 |
Then_Statements => Eval_Stmts)); |
| 5315 |
|
| 5316 |
Rewrite (N, Indirect_Temp_Value |
| 5317 |
(Temp => Temp, |
| 5318 |
Typ => Etype (Pref), |
| 5319 |
Loc => Loc)); |
| 5320 |
return; |
| 5321 |
end; |
| 5322 |
|
| 5323 |
-- Preserve the tag of the prefix by offering a specific view of the |
| 5324 |
-- class-wide version of the prefix. |
| 5325 |
|
| 5326 |
elsif Is_Tagged_Type (Typ) then |
| 5327 |
|
| 5328 |
-- Generate: |
| 5329 |
-- CW_Temp : constant Typ'Class := Typ'Class (Pref); |
| 5330 |
|
| 5331 |
CW_Temp := Make_Temporary (Loc, 'T'); |
| 5332 |
CW_Typ := Class_Wide_Type (Typ); |
| 5333 |
|
| 5334 |
Decl := |
| 5335 |
Make_Object_Declaration (Loc, |
| 5336 |
Defining_Identifier => CW_Temp, |
| 5337 |
Constant_Present => True, |
| 5338 |
Object_Definition => New_Occurrence_Of (CW_Typ, Loc), |
| 5339 |
Expression => |
| 5340 |
Convert_To (CW_Typ, Relocate_Node (Pref))); |
| 5341 |
|
| 5342 |
Insert_Before_And_Analyze (Ins_Nod, Decl); |
| 5343 |
|
| 5344 |
-- Generate: |
| 5345 |
-- Temp : Typ renames Typ (CW_Temp); |
| 5346 |
|
| 5347 |
Insert_Before_And_Analyze (Ins_Nod, |
| 5348 |
Make_Object_Renaming_Declaration (Loc, |
| 5349 |
Defining_Identifier => Temp, |
| 5350 |
Subtype_Mark => New_Occurrence_Of (Typ, Loc), |
| 5351 |
Name => |
| 5352 |
Convert_To (Typ, New_Occurrence_Of (CW_Temp, Loc)))); |
| 5353 |
|
| 5354 |
Set_Stores_Attribute_Old_Prefix (CW_Temp); |
| 5355 |
|
| 5356 |
-- Non-tagged case |
| 5357 |
|
| 5358 |
else |
| 5359 |
-- Generate: |
| 5360 |
-- Temp : constant Typ := Pref; |
| 5361 |
|
| 5362 |
Decl := |
| 5363 |
Make_Object_Declaration (Loc, |
| 5364 |
Defining_Identifier => Temp, |
| 5365 |
Constant_Present => True, |
| 5366 |
Object_Definition => New_Occurrence_Of (Typ, Loc), |
| 5367 |
Expression => Relocate_Node (Pref)); |
| 5368 |
|
| 5369 |
Insert_Before_And_Analyze (Ins_Nod, Decl); |
| 5370 |
|
| 5371 |
end if; |
| 5372 |
|
| 5373 |
-- Ensure that the prefix of attribute 'Old is valid. The check must |
| 5374 |
-- be inserted after the expansion of the attribute has taken place |
| 5375 |
-- to reflect the new placement of the prefix. |
| 5376 |
|
| 5377 |
if Validity_Checks_On and then Validity_Check_Operands then |
| 5378 |
|
| 5379 |
-- Object declaration that captures the attribute prefix might |
| 5380 |
-- be rewritten into object renaming declaration. |
| 5381 |
|
| 5382 |
if Nkind (Decl) = N_Object_Declaration then |
| 5383 |
Ensure_Valid (Expression (Decl)); |
| 5384 |
else |
| 5385 |
pragma Assert (Nkind (Decl) = N_Object_Renaming_Declaration |
| 5386 |
and then Is_Rewrite_Substitution (Decl)); |
| 5387 |
Ensure_Valid (Name (Decl)); |
| 5388 |
end if; |
| 5389 |
end if; |
| 5390 |
|
| 5391 |
Rewrite (N, New_Occurrence_Of (Temp, Loc)); |
| 5392 |
end Old; |
| 5393 |
|
| 5394 |
---------------------- |
| 5395 |
-- Overlaps_Storage -- |
| 5396 |
---------------------- |
| 5397 |
|
| 5398 |
when Attribute_Overlaps_Storage => Overlaps_Storage : declare |
| 5399 |
X : constant Node_Id := Pref; |
| 5400 |
Y : constant Node_Id := First (Exprs); |
| 5401 |
-- The arguments |
| 5402 |
|
| 5403 |
X_Addr, Y_Addr : Node_Id; |
| 5404 |
|
| 5405 |
-- The expressions for their integer addresses |
| 5406 |
|
| 5407 |
X_Size, Y_Size : Node_Id; |
| 5408 |
|
| 5409 |
-- The expressions for their sizes |
| 5410 |
|
| 5411 |
Cond : Node_Id; |
| 5412 |
|
| 5413 |
begin |
| 5414 |
-- Attribute expands into: |
| 5415 |
|
| 5416 |
-- (if X'Size = 0 or else Y'Size = 0 then |
| 5417 |
-- False |
| 5418 |
-- else |
| 5419 |
-- (if X'Address <= Y'Address then |
| 5420 |
-- (X'Address + X'Size - 1) >= Y'Address |
| 5421 |
-- else |
| 5422 |
-- (Y'Address + Y'Size - 1) >= X'Address)) |
| 5423 |
|
| 5424 |
-- with the proper address operations. We convert addresses to |
| 5425 |
-- integer addresses to use predefined arithmetic. The size is |
| 5426 |
-- expressed in storage units. We add copies of X_Addr and Y_Addr |
| 5427 |
-- to prevent the appearance of the same node in two places in |
| 5428 |
-- the tree. |
| 5429 |
|
| 5430 |
X_Addr := |
| 5431 |
Unchecked_Convert_To (RTE (RE_Integer_Address), |
| 5432 |
Make_Attribute_Reference (Loc, |
| 5433 |
Attribute_Name => Name_Address, |
| 5434 |
Prefix => New_Copy_Tree (X))); |
| 5435 |
|
| 5436 |
Y_Addr := |
| 5437 |
Unchecked_Convert_To (RTE (RE_Integer_Address), |
| 5438 |
Make_Attribute_Reference (Loc, |
| 5439 |
Attribute_Name => Name_Address, |
| 5440 |
Prefix => New_Copy_Tree (Y))); |
| 5441 |
|
| 5442 |
X_Size := |
| 5443 |
Make_Op_Divide (Loc, |
| 5444 |
Left_Opnd => |
| 5445 |
Make_Attribute_Reference (Loc, |
| 5446 |
Attribute_Name => Name_Size, |
| 5447 |
Prefix => New_Copy_Tree (X)), |
| 5448 |
Right_Opnd => |
| 5449 |
Make_Integer_Literal (Loc, System_Storage_Unit)); |
| 5450 |
|
| 5451 |
Y_Size := |
| 5452 |
Make_Op_Divide (Loc, |
| 5453 |
Left_Opnd => |
| 5454 |
Make_Attribute_Reference (Loc, |
| 5455 |
Attribute_Name => Name_Size, |
| 5456 |
Prefix => New_Copy_Tree (Y)), |
| 5457 |
Right_Opnd => |
| 5458 |
Make_Integer_Literal (Loc, System_Storage_Unit)); |
| 5459 |
|
| 5460 |
Cond := |
| 5461 |
Make_Op_Le (Loc, |
| 5462 |
Left_Opnd => X_Addr, |
| 5463 |
Right_Opnd => Y_Addr); |
| 5464 |
|
| 5465 |
-- Perform the rewriting |
| 5466 |
|
| 5467 |
Rewrite (N, |
| 5468 |
Make_If_Expression (Loc, New_List ( |
| 5469 |
|
| 5470 |
-- Generate a check for zero-sized things like a null record with |
| 5471 |
-- size zero or an array with zero length since they have no |
| 5472 |
-- opportunity of overlapping. |
| 5473 |
|
| 5474 |
-- Without this check, a zero-sized object can trigger a false |
| 5475 |
-- runtime result if it's compared against another object in |
| 5476 |
-- its declarative region, due to the zero-sized object having |
| 5477 |
-- the same address. |
| 5478 |
|
| 5479 |
Make_Or_Else (Loc, |
| 5480 |
Left_Opnd => |
| 5481 |
Make_Op_Eq (Loc, |
| 5482 |
Left_Opnd => |
| 5483 |
Make_Attribute_Reference (Loc, |
| 5484 |
Attribute_Name => Name_Size, |
| 5485 |
Prefix => New_Copy_Tree (X)), |
| 5486 |
Right_Opnd => Make_Integer_Literal (Loc, 0)), |
| 5487 |
Right_Opnd => |
| 5488 |
Make_Op_Eq (Loc, |
| 5489 |
Left_Opnd => |
| 5490 |
Make_Attribute_Reference (Loc, |
| 5491 |
Attribute_Name => Name_Size, |
| 5492 |
Prefix => New_Copy_Tree (Y)), |
| 5493 |
Right_Opnd => Make_Integer_Literal (Loc, 0))), |
| 5494 |
|
| 5495 |
New_Occurrence_Of (Standard_False, Loc), |
| 5496 |
|
| 5497 |
-- Non-zero-size overlap check |
| 5498 |
|
| 5499 |
Make_If_Expression (Loc, New_List ( |
| 5500 |
Cond, |
| 5501 |
|
| 5502 |
Make_Op_Ge (Loc, |
| 5503 |
Left_Opnd => |
| 5504 |
Make_Op_Add (Loc, |
| 5505 |
Left_Opnd => New_Copy_Tree (X_Addr), |
| 5506 |
Right_Opnd => |
| 5507 |
Make_Op_Subtract (Loc, |
| 5508 |
Left_Opnd => X_Size, |
| 5509 |
Right_Opnd => Make_Integer_Literal (Loc, 1))), |
| 5510 |
Right_Opnd => Y_Addr), |
| 5511 |
|
| 5512 |
Make_Op_Ge (Loc, |
| 5513 |
Left_Opnd => |
| 5514 |
Make_Op_Add (Loc, |
| 5515 |
Left_Opnd => New_Copy_Tree (Y_Addr), |
| 5516 |
Right_Opnd => |
| 5517 |
Make_Op_Subtract (Loc, |
| 5518 |
Left_Opnd => Y_Size, |
| 5519 |
Right_Opnd => Make_Integer_Literal (Loc, 1))), |
| 5520 |
Right_Opnd => X_Addr)))))); |
| 5521 |
|
| 5522 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 5523 |
end Overlaps_Storage; |
| 5524 |
|
| 5525 |
------------ |
| 5526 |
-- Output -- |
| 5527 |
------------ |
| 5528 |
|
| 5529 |
when Attribute_Output => Output : declare |
| 5530 |
P_Type : constant Entity_Id := Entity (Pref); |
| 5531 |
U_Type : constant Entity_Id := Underlying_Type (P_Type); |
| 5532 |
Pname : Entity_Id; |
| 5533 |
Decl : Node_Id; |
| 5534 |
Prag : Node_Id; |
| 5535 |
Arg3 : Node_Id; |
| 5536 |
Wfunc : Node_Id; |
| 5537 |
|
| 5538 |
begin |
| 5539 |
-- If no underlying type, we have an error that will be diagnosed |
| 5540 |
-- elsewhere, so here we just completely ignore the expansion. |
| 5541 |
|
| 5542 |
if No (U_Type) then |
| 5543 |
return; |
| 5544 |
end if; |
| 5545 |
|
| 5546 |
-- Stream operations can appear in user code even if the restriction |
| 5547 |
-- No_Streams is active (for example, when instantiating a predefined |
| 5548 |
-- container). In that case rewrite the attribute as a Raise to |
| 5549 |
-- prevent any run-time use. |
| 5550 |
|
| 5551 |
if Restriction_Active (No_Streams) then |
| 5552 |
Rewrite (N, |
| 5553 |
Make_Raise_Program_Error (Loc, |
| 5554 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 5555 |
Set_Etype (N, Standard_Void_Type); |
| 5556 |
return; |
| 5557 |
end if; |
| 5558 |
|
| 5559 |
-- If TSS for Output is present, just call it |
| 5560 |
|
| 5561 |
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output, N); |
| 5562 |
|
| 5563 |
if No (Pname) then |
| 5564 |
|
| 5565 |
-- If there is a Stream_Convert pragma, use it, we rewrite |
| 5566 |
|
| 5567 |
-- sourcetyp'Output (stream, Item) |
| 5568 |
|
| 5569 |
-- as |
| 5570 |
|
| 5571 |
-- strmtyp'Output (Stream, strmwrite (acttyp (Item))); |
| 5572 |
|
| 5573 |
-- where strmwrite is the given Write function that converts an |
| 5574 |
-- argument of type sourcetyp or a type acctyp, from which it is |
| 5575 |
-- derived to type strmtyp. The conversion to acttyp is required |
| 5576 |
-- for the derived case. |
| 5577 |
|
| 5578 |
Prag := Get_Stream_Convert_Pragma (P_Type); |
| 5579 |
|
| 5580 |
if Present (Prag) then |
| 5581 |
Arg3 := |
| 5582 |
Next (Next (First (Pragma_Argument_Associations (Prag)))); |
| 5583 |
Wfunc := Entity (Expression (Arg3)); |
| 5584 |
|
| 5585 |
Rewrite (N, |
| 5586 |
Make_Attribute_Reference (Loc, |
| 5587 |
Prefix => New_Occurrence_Of (Etype (Wfunc), Loc), |
| 5588 |
Attribute_Name => Name_Output, |
| 5589 |
Expressions => New_List ( |
| 5590 |
Relocate_Node (First (Exprs)), |
| 5591 |
Make_Function_Call (Loc, |
| 5592 |
Name => New_Occurrence_Of (Wfunc, Loc), |
| 5593 |
Parameter_Associations => New_List ( |
| 5594 |
OK_Convert_To (Etype (First_Formal (Wfunc)), |
| 5595 |
Relocate_Node (Next (First (Exprs))))))))); |
| 5596 |
|
| 5597 |
Analyze (N); |
| 5598 |
return; |
| 5599 |
|
| 5600 |
-- Limited types |
| 5601 |
|
| 5602 |
elsif Default_Streaming_Unavailable (U_Type) then |
| 5603 |
-- Do the same thing here as is done above in the |
| 5604 |
-- case where a No_Streams restriction is active. |
| 5605 |
|
| 5606 |
Rewrite (N, |
| 5607 |
Make_Raise_Program_Error (Loc, |
| 5608 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 5609 |
Set_Etype (N, Standard_Void_Type); |
| 5610 |
return; |
| 5611 |
|
| 5612 |
-- For elementary types, we call the W_xxx routine directly. Note |
| 5613 |
-- that the effect of Write and Output is identical for the case |
| 5614 |
-- of an elementary type (there are no discriminants or bounds). |
| 5615 |
|
| 5616 |
elsif Is_Elementary_Type (U_Type) then |
| 5617 |
|
| 5618 |
-- A special case arises if we have a defined _Write routine, |
| 5619 |
-- since in this case we are required to call this routine. |
| 5620 |
|
| 5621 |
if Present (Find_Inherited_TSS (P_Type, TSS_Stream_Write)) then |
| 5622 |
Build_Record_Or_Elementary_Output_Procedure |
| 5623 |
(P_Type, Decl, Pname); |
| 5624 |
Insert_Action (N, Decl); |
| 5625 |
|
| 5626 |
-- For normal cases, we call the W_xxx routine directly |
| 5627 |
|
| 5628 |
else |
| 5629 |
Rewrite (N, Build_Elementary_Write_Call (N)); |
| 5630 |
Analyze (N); |
| 5631 |
return; |
| 5632 |
end if; |
| 5633 |
|
| 5634 |
-- Array type case |
| 5635 |
|
| 5636 |
elsif Is_Array_Type (U_Type) then |
| 5637 |
declare |
| 5638 |
procedure Build_And_Insert_Array_Output_Proc is |
| 5639 |
new Build_And_Insert_Type_Attr_Subp |
| 5640 |
(Build_Array_Output_Procedure); |
| 5641 |
begin |
| 5642 |
Build_And_Insert_Array_Output_Proc |
| 5643 |
(Typ => Full_Base (U_Type), |
| 5644 |
Decl => Decl, |
| 5645 |
Subp => Pname, |
| 5646 |
Attr_Ref => N); |
| 5647 |
end; |
| 5648 |
|
| 5649 |
-- Class-wide case, first output external tag, then dispatch |
| 5650 |
-- to the appropriate primitive Output function (RM 13.13.2(31)). |
| 5651 |
|
| 5652 |
elsif Is_Class_Wide_Type (P_Type) then |
| 5653 |
|
| 5654 |
-- No need to do anything else compiling under restriction |
| 5655 |
-- No_Dispatching_Calls. During the semantic analysis we |
| 5656 |
-- already notified such violation. |
| 5657 |
|
| 5658 |
if Restriction_Active (No_Dispatching_Calls) then |
| 5659 |
return; |
| 5660 |
end if; |
| 5661 |
|
| 5662 |
Tag_Write : declare |
| 5663 |
Strm : constant Node_Id := First (Exprs); |
| 5664 |
Item : constant Node_Id := Next (Strm); |
| 5665 |
|
| 5666 |
begin |
| 5667 |
-- Ada 2005 (AI-344): Check that the accessibility level |
| 5668 |
-- of the type of the output object is not deeper than |
| 5669 |
-- that of the attribute's prefix type. |
| 5670 |
|
| 5671 |
-- if Get_Access_Level (Item'Tag) |
| 5672 |
-- /= Get_Access_Level (P_Type'Tag) |
| 5673 |
-- then |
| 5674 |
-- raise Tag_Error; |
| 5675 |
-- end if; |
| 5676 |
|
| 5677 |
-- String'Output (Strm, External_Tag (Item'Tag)); |
| 5678 |
|
| 5679 |
-- We cannot figure out a practical way to implement this |
| 5680 |
-- accessibility check on virtual machines, so we omit it. |
| 5681 |
|
| 5682 |
if Ada_Version >= Ada_2005 |
| 5683 |
and then Tagged_Type_Expansion |
| 5684 |
then |
| 5685 |
Insert_Action (N, |
| 5686 |
Make_Implicit_If_Statement (N, |
| 5687 |
Condition => |
| 5688 |
Make_Op_Ne (Loc, |
| 5689 |
Left_Opnd => |
| 5690 |
Build_Get_Access_Level (Loc, |
| 5691 |
Make_Attribute_Reference (Loc, |
| 5692 |
Prefix => |
| 5693 |
Relocate_Node ( |
| 5694 |
Duplicate_Subexpr (Item, |
| 5695 |
Name_Req => True)), |
| 5696 |
Attribute_Name => Name_Tag)), |
| 5697 |
|
| 5698 |
Right_Opnd => |
| 5699 |
Make_Integer_Literal (Loc, |
| 5700 |
Type_Access_Level (P_Type))), |
| 5701 |
|
| 5702 |
Then_Statements => |
| 5703 |
New_List (Make_Raise_Statement (Loc, |
| 5704 |
New_Occurrence_Of ( |
| 5705 |
RTE (RE_Tag_Error), Loc))))); |
| 5706 |
end if; |
| 5707 |
|
| 5708 |
Insert_Action (N, |
| 5709 |
Make_Attribute_Reference (Loc, |
| 5710 |
Prefix => New_Occurrence_Of (Standard_String, Loc), |
| 5711 |
Attribute_Name => Name_Output, |
| 5712 |
Expressions => New_List ( |
| 5713 |
Relocate_Node (Duplicate_Subexpr (Strm)), |
| 5714 |
Make_Function_Call (Loc, |
| 5715 |
Name => |
| 5716 |
New_Occurrence_Of (RTE (RE_External_Tag), Loc), |
| 5717 |
Parameter_Associations => New_List ( |
| 5718 |
Make_Attribute_Reference (Loc, |
| 5719 |
Prefix => |
| 5720 |
Relocate_Node |
| 5721 |
(Duplicate_Subexpr (Item, Name_Req => True)), |
| 5722 |
Attribute_Name => Name_Tag)))))); |
| 5723 |
end Tag_Write; |
| 5724 |
|
| 5725 |
Pname := Find_Prim_Op (U_Type, TSS_Stream_Output); |
| 5726 |
|
| 5727 |
-- Tagged type case, use the primitive Output function |
| 5728 |
|
| 5729 |
elsif Is_Tagged_Type (U_Type) then |
| 5730 |
Pname := Find_Prim_Op (U_Type, TSS_Stream_Output); |
| 5731 |
|
| 5732 |
-- All other record type cases, including protected records. |
| 5733 |
-- The latter only arise for expander generated code for |
| 5734 |
-- handling shared passive partition access. |
| 5735 |
|
| 5736 |
else |
| 5737 |
pragma Assert |
| 5738 |
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); |
| 5739 |
|
| 5740 |
-- Ada 2005 (AI-216): Program_Error is raised when executing |
| 5741 |
-- the default implementation of the Output attribute of an |
| 5742 |
-- unchecked union type if the type lacks default discriminant |
| 5743 |
-- values. |
| 5744 |
|
| 5745 |
if Is_Unchecked_Union (Base_Type (U_Type)) |
| 5746 |
and then |
| 5747 |
No (Discriminant_Default_Value (First_Discriminant (U_Type))) |
| 5748 |
then |
| 5749 |
Rewrite (N, |
| 5750 |
Make_Raise_Program_Error (Loc, |
| 5751 |
Reason => PE_Unchecked_Union_Restriction)); |
| 5752 |
Set_Etype (N, Standard_Void_Type); |
| 5753 |
return; |
| 5754 |
end if; |
| 5755 |
|
| 5756 |
declare |
| 5757 |
procedure Build_And_Insert_Record_Output_Proc is |
| 5758 |
new Build_And_Insert_Type_Attr_Subp |
| 5759 |
(Build_Record_Or_Elementary_Output_Procedure); |
| 5760 |
begin |
| 5761 |
Build_And_Insert_Record_Output_Proc |
| 5762 |
(Typ => Base_Type (U_Type), |
| 5763 |
Decl => Decl, |
| 5764 |
Subp => Pname, |
| 5765 |
Attr_Ref => N); |
| 5766 |
end; |
| 5767 |
end if; |
| 5768 |
end if; |
| 5769 |
|
| 5770 |
-- If we fall through, Pname is the name of the procedure to call |
| 5771 |
|
| 5772 |
Rewrite_Attribute_Proc_Call (Pname); |
| 5773 |
|
| 5774 |
if not Is_Tagged_Type (P_Type) then |
| 5775 |
Cached_Attribute_Ops.Output_Map.Set (U_Type, Pname); |
| 5776 |
end if; |
| 5777 |
end Output; |
| 5778 |
|
| 5779 |
--------- |
| 5780 |
-- Pos -- |
| 5781 |
--------- |
| 5782 |
|
| 5783 |
-- For enumeration types, with a non-standard representation we generate |
| 5784 |
-- a call to the _Rep_To_Pos function created when the type was frozen. |
| 5785 |
-- The call has the form: |
| 5786 |
|
| 5787 |
-- _rep_to_pos (expr, flag) |
| 5788 |
|
| 5789 |
-- The parameter flag is True if range checks are enabled, causing |
| 5790 |
-- Program_Error to be raised if the expression has an invalid |
| 5791 |
-- representation, and False if range checks are suppressed. |
| 5792 |
|
| 5793 |
-- For enumeration types with a standard representation, Pos can be |
| 5794 |
-- rewritten as a simple conversion with Conversion_OK set. |
| 5795 |
|
| 5796 |
-- For integer types, Pos is equivalent to a simple integer conversion |
| 5797 |
-- and we rewrite it as such. |
| 5798 |
|
| 5799 |
when Attribute_Pos => Pos : declare |
| 5800 |
Expr : constant Node_Id := First (Exprs); |
| 5801 |
Etyp : Entity_Id := Base_Type (Ptyp); |
| 5802 |
|
| 5803 |
begin |
| 5804 |
-- Deal with zero/non-zero boolean values |
| 5805 |
|
| 5806 |
if Is_Boolean_Type (Etyp) then |
| 5807 |
Adjust_Condition (Expr); |
| 5808 |
Etyp := Standard_Boolean; |
| 5809 |
Set_Prefix (N, New_Occurrence_Of (Standard_Boolean, Loc)); |
| 5810 |
end if; |
| 5811 |
|
| 5812 |
-- Case of enumeration type |
| 5813 |
|
| 5814 |
if Is_Enumeration_Type (Etyp) then |
| 5815 |
|
| 5816 |
-- Non-standard enumeration type (generate call) |
| 5817 |
|
| 5818 |
if Present (Enum_Pos_To_Rep (Etyp)) then |
| 5819 |
Append_To (Exprs, Rep_To_Pos_Flag (Etyp, Loc)); |
| 5820 |
Rewrite (N, |
| 5821 |
Convert_To (Typ, |
| 5822 |
Make_Function_Call (Loc, |
| 5823 |
Name => |
| 5824 |
New_Occurrence_Of (TSS (Etyp, TSS_Rep_To_Pos), Loc), |
| 5825 |
Parameter_Associations => Exprs))); |
| 5826 |
|
| 5827 |
-- Standard enumeration type (replace by conversion) |
| 5828 |
|
| 5829 |
-- This is simply a direct conversion from the enumeration type to |
| 5830 |
-- the target integer type, which is treated by the back end as a |
| 5831 |
-- normal integer conversion, treating the enumeration type as an |
| 5832 |
-- integer, which is exactly what we want. We set Conversion_OK to |
| 5833 |
-- make sure that the analyzer does not complain about what might |
| 5834 |
-- be an illegal conversion. |
| 5835 |
|
| 5836 |
-- However the target type is universal integer in most cases, |
| 5837 |
-- which is a very large type, so we first convert to a small |
| 5838 |
-- signed integer type in order not to lose the size information. |
| 5839 |
|
| 5840 |
else |
| 5841 |
Rewrite (N, OK_Convert_To (Get_Integer_Type (Ptyp), Expr)); |
| 5842 |
Convert_To_And_Rewrite (Typ, N); |
| 5843 |
|
| 5844 |
end if; |
| 5845 |
|
| 5846 |
-- Deal with integer types (replace by conversion) |
| 5847 |
|
| 5848 |
else |
| 5849 |
Rewrite (N, Convert_To (Typ, Expr)); |
| 5850 |
end if; |
| 5851 |
|
| 5852 |
Analyze_And_Resolve (N, Typ); |
| 5853 |
end Pos; |
| 5854 |
|
| 5855 |
-------------- |
| 5856 |
-- Position -- |
| 5857 |
-------------- |
| 5858 |
|
| 5859 |
-- We leave the computation up to the back end, since we don't know what |
| 5860 |
-- layout will be chosen if no component clause was specified. |
| 5861 |
|
| 5862 |
when Attribute_Position => |
| 5863 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 5864 |
|
| 5865 |
---------- |
| 5866 |
-- Pred -- |
| 5867 |
---------- |
| 5868 |
|
| 5869 |
-- 1. Deal with enumeration types with holes. |
| 5870 |
-- 2. For floating-point, generate call to attribute function. |
| 5871 |
-- 3. For other cases, deal with constraint checking. |
| 5872 |
|
| 5873 |
when Attribute_Pred => Pred : declare |
| 5874 |
Etyp : constant Entity_Id := Base_Type (Ptyp); |
| 5875 |
|
| 5876 |
begin |
| 5877 |
-- For enumeration types with non-standard representations, we |
| 5878 |
-- expand typ'Pred (x) into: |
| 5879 |
|
| 5880 |
-- Pos_To_Rep (Rep_To_Pos (x) - 1) |
| 5881 |
|
| 5882 |
-- if the representation is non-contiguous, and just x - 1 if it is |
| 5883 |
-- after having dealt with constraint checking. |
| 5884 |
|
| 5885 |
if Is_Enumeration_Type (Etyp) |
| 5886 |
and then Present (Enum_Pos_To_Rep (Etyp)) |
| 5887 |
then |
| 5888 |
if Has_Contiguous_Rep (Etyp) then |
| 5889 |
if not Range_Checks_Suppressed (Ptyp) then |
| 5890 |
Set_Do_Range_Check (First (Exprs), False); |
| 5891 |
Expand_Pred_Succ_Attribute (N); |
| 5892 |
end if; |
| 5893 |
|
| 5894 |
Rewrite (N, |
| 5895 |
Unchecked_Convert_To (Etyp, |
| 5896 |
Make_Op_Subtract (Loc, |
| 5897 |
Left_Opnd => |
| 5898 |
Unchecked_Convert_To ( |
| 5899 |
Integer_Type_For |
| 5900 |
(Esize (Etyp), Is_Unsigned_Type (Etyp)), |
| 5901 |
First (Exprs)), |
| 5902 |
Right_Opnd => |
| 5903 |
Make_Integer_Literal (Loc, 1)))); |
| 5904 |
|
| 5905 |
else |
| 5906 |
-- Add Boolean parameter depending on check suppression |
| 5907 |
|
| 5908 |
Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc)); |
| 5909 |
Rewrite (N, |
| 5910 |
Make_Indexed_Component (Loc, |
| 5911 |
Prefix => |
| 5912 |
New_Occurrence_Of |
| 5913 |
(Enum_Pos_To_Rep (Etyp), Loc), |
| 5914 |
Expressions => New_List ( |
| 5915 |
Make_Op_Subtract (Loc, |
| 5916 |
Left_Opnd => |
| 5917 |
Make_Function_Call (Loc, |
| 5918 |
Name => |
| 5919 |
New_Occurrence_Of |
| 5920 |
(TSS (Etyp, TSS_Rep_To_Pos), Loc), |
| 5921 |
Parameter_Associations => Exprs), |
| 5922 |
Right_Opnd => Make_Integer_Literal (Loc, 1))))); |
| 5923 |
end if; |
| 5924 |
|
| 5925 |
-- Suppress checks since they have all been done above |
| 5926 |
|
| 5927 |
Analyze_And_Resolve (N, Typ, Suppress => All_Checks); |
| 5928 |
|
| 5929 |
-- For floating-point, we transform 'Pred into a call to the Pred |
| 5930 |
-- floating-point attribute function in Fat_xxx (xxx is root type). |
| 5931 |
-- Note that this function takes care of the overflow case. |
| 5932 |
|
| 5933 |
elsif Is_Floating_Point_Type (Ptyp) then |
| 5934 |
Expand_Fpt_Attribute_R (N); |
| 5935 |
Analyze_And_Resolve (N, Typ); |
| 5936 |
|
| 5937 |
-- For modular types, nothing to do (no overflow, since wraps) |
| 5938 |
|
| 5939 |
elsif Is_Modular_Integer_Type (Ptyp) then |
| 5940 |
null; |
| 5941 |
|
| 5942 |
-- For other types, if argument is marked as needing a range check or |
| 5943 |
-- overflow checking is enabled, we must generate a check. |
| 5944 |
|
| 5945 |
elsif not Overflow_Checks_Suppressed (Ptyp) |
| 5946 |
or else Do_Range_Check (First (Exprs)) |
| 5947 |
then |
| 5948 |
Set_Do_Range_Check (First (Exprs), False); |
| 5949 |
Expand_Pred_Succ_Attribute (N); |
| 5950 |
end if; |
| 5951 |
end Pred; |
| 5952 |
|
| 5953 |
---------------------------------- |
| 5954 |
-- Preelaborable_Initialization -- |
| 5955 |
---------------------------------- |
| 5956 |
|
| 5957 |
when Attribute_Preelaborable_Initialization => |
| 5958 |
|
| 5959 |
-- This attribute should already be folded during analysis, but if |
| 5960 |
-- for some reason it hasn't been, we fold it now. |
| 5961 |
|
| 5962 |
Fold_Uint |
| 5963 |
(N, |
| 5964 |
UI_From_Int |
| 5965 |
(Boolean'Pos (Has_Preelaborable_Initialization (Ptyp))), |
| 5966 |
Static => False); |
| 5967 |
|
| 5968 |
-------------- |
| 5969 |
-- Priority -- |
| 5970 |
-------------- |
| 5971 |
|
| 5972 |
-- Ada 2005 (AI-327): Dynamic ceiling priorities |
| 5973 |
|
| 5974 |
-- We rewrite X'Priority as the following run-time call: |
| 5975 |
|
| 5976 |
-- Get_Ceiling (X._Object) |
| 5977 |
|
| 5978 |
-- Note that although X'Priority is notionally an object, it is quite |
| 5979 |
-- deliberately not defined as an aliased object in the RM. This means |
| 5980 |
-- that it works fine to rewrite it as a call, without having to worry |
| 5981 |
-- about complications that would other arise from X'Priority'Access, |
| 5982 |
-- which is illegal, because of the lack of aliasing. |
| 5983 |
|
| 5984 |
when Attribute_Priority => Priority : declare |
| 5985 |
Call : Node_Id; |
| 5986 |
New_Itype : Entity_Id; |
| 5987 |
Object_Parm : Node_Id; |
| 5988 |
Prottyp : Entity_Id; |
| 5989 |
RT_Subprg : RE_Id; |
| 5990 |
Subprg : Entity_Id; |
| 5991 |
|
| 5992 |
begin |
| 5993 |
-- Look for the enclosing protected type |
| 5994 |
|
| 5995 |
Prottyp := Current_Scope; |
| 5996 |
while not Is_Protected_Type (Prottyp) loop |
| 5997 |
Prottyp := Scope (Prottyp); |
| 5998 |
end loop; |
| 5999 |
|
| 6000 |
pragma Assert (Is_Protected_Type (Prottyp)); |
| 6001 |
|
| 6002 |
-- Generate the actual of the call |
| 6003 |
|
| 6004 |
Subprg := Current_Scope; |
| 6005 |
while not (Is_Subprogram_Or_Entry (Subprg) |
| 6006 |
and then Present (Protected_Body_Subprogram (Subprg))) |
| 6007 |
loop |
| 6008 |
Subprg := Scope (Subprg); |
| 6009 |
end loop; |
| 6010 |
|
| 6011 |
-- Use of 'Priority inside protected entries and barriers (in both |
| 6012 |
-- cases the type of the first formal of their expanded subprogram |
| 6013 |
-- is Address). |
| 6014 |
|
| 6015 |
if Etype (First_Entity (Protected_Body_Subprogram (Subprg))) = |
| 6016 |
RTE (RE_Address) |
| 6017 |
then |
| 6018 |
-- In the expansion of protected entries the type of the first |
| 6019 |
-- formal of the Protected_Body_Subprogram is an Address. In order |
| 6020 |
-- to reference the _object component we generate: |
| 6021 |
|
| 6022 |
-- type T is access p__ptTV; |
| 6023 |
-- freeze T [] |
| 6024 |
|
| 6025 |
New_Itype := Create_Itype (E_Access_Type, N); |
| 6026 |
Set_Etype (New_Itype, New_Itype); |
| 6027 |
Set_Directly_Designated_Type (New_Itype, |
| 6028 |
Corresponding_Record_Type (Prottyp)); |
| 6029 |
Freeze_Itype (New_Itype, N); |
| 6030 |
|
| 6031 |
-- Generate: |
| 6032 |
-- T!(O)._object'unchecked_access |
| 6033 |
|
| 6034 |
Object_Parm := |
| 6035 |
Make_Attribute_Reference (Loc, |
| 6036 |
Prefix => |
| 6037 |
Make_Selected_Component (Loc, |
| 6038 |
Prefix => |
| 6039 |
Unchecked_Convert_To (New_Itype, |
| 6040 |
New_Occurrence_Of |
| 6041 |
(First_Entity (Protected_Body_Subprogram (Subprg)), |
| 6042 |
Loc)), |
| 6043 |
Selector_Name => Make_Identifier (Loc, Name_uObject)), |
| 6044 |
Attribute_Name => Name_Unchecked_Access); |
| 6045 |
|
| 6046 |
-- Use of 'Priority inside a protected subprogram |
| 6047 |
|
| 6048 |
else |
| 6049 |
Object_Parm := |
| 6050 |
Make_Attribute_Reference (Loc, |
| 6051 |
Prefix => |
| 6052 |
Make_Selected_Component (Loc, |
| 6053 |
Prefix => |
| 6054 |
New_Occurrence_Of |
| 6055 |
(First_Entity (Protected_Body_Subprogram (Subprg)), |
| 6056 |
Loc), |
| 6057 |
Selector_Name => Make_Identifier (Loc, Name_uObject)), |
| 6058 |
Attribute_Name => Name_Unchecked_Access); |
| 6059 |
end if; |
| 6060 |
|
| 6061 |
-- Select the appropriate run-time subprogram |
| 6062 |
|
| 6063 |
if Has_Entries (Prottyp) then |
| 6064 |
RT_Subprg := RO_PE_Get_Ceiling; |
| 6065 |
else |
| 6066 |
RT_Subprg := RE_Get_Ceiling; |
| 6067 |
end if; |
| 6068 |
|
| 6069 |
Call := |
| 6070 |
Make_Function_Call (Loc, |
| 6071 |
Name => |
| 6072 |
New_Occurrence_Of (RTE (RT_Subprg), Loc), |
| 6073 |
Parameter_Associations => New_List (Object_Parm)); |
| 6074 |
|
| 6075 |
Rewrite (N, Call); |
| 6076 |
|
| 6077 |
-- Avoid the generation of extra checks on the pointer to the |
| 6078 |
-- protected object. |
| 6079 |
|
| 6080 |
Analyze_And_Resolve (N, Typ, Suppress => Access_Check); |
| 6081 |
end Priority; |
| 6082 |
|
| 6083 |
--------------- |
| 6084 |
-- Put_Image -- |
| 6085 |
--------------- |
| 6086 |
|
| 6087 |
when Attribute_Put_Image => Put_Image : declare |
| 6088 |
use Exp_Put_Image; |
| 6089 |
U_Type : constant Entity_Id := Underlying_Type (Entity (Pref)); |
| 6090 |
C_Type : Entity_Id; |
| 6091 |
Pname : Entity_Id; |
| 6092 |
Decl : Node_Id; |
| 6093 |
|
| 6094 |
begin |
| 6095 |
-- If no underlying type, we have an error that will be diagnosed |
| 6096 |
-- elsewhere, so here we just completely ignore the expansion. |
| 6097 |
|
| 6098 |
if No (U_Type) then |
| 6099 |
return; |
| 6100 |
end if; |
| 6101 |
|
| 6102 |
-- If there is a TSS for Put_Image, just call it. This is true for |
| 6103 |
-- tagged types (if enabled) and if there is a user-specified |
| 6104 |
-- Put_Image. |
| 6105 |
|
| 6106 |
Pname := TSS (U_Type, TSS_Put_Image); |
| 6107 |
if No (Pname) then |
| 6108 |
if Is_Tagged_Type (U_Type) and then Is_Derived_Type (U_Type) then |
| 6109 |
Pname := Find_Optional_Prim_Op (U_Type, TSS_Put_Image); |
| 6110 |
else |
| 6111 |
Pname := Find_Inherited_TSS (U_Type, TSS_Put_Image); |
| 6112 |
end if; |
| 6113 |
end if; |
| 6114 |
|
| 6115 |
if No (Pname) then |
| 6116 |
if Is_String_Type (U_Type) then |
| 6117 |
declare |
| 6118 |
R : constant Entity_Id := Root_Type (U_Type); |
| 6119 |
|
| 6120 |
begin |
| 6121 |
if Is_Private_Type (R) then |
| 6122 |
C_Type := Component_Type (Full_View (R)); |
| 6123 |
else |
| 6124 |
C_Type := Component_Type (R); |
| 6125 |
end if; |
| 6126 |
|
| 6127 |
C_Type := Root_Type (Underlying_Type (C_Type)); |
| 6128 |
end; |
| 6129 |
end if; |
| 6130 |
|
| 6131 |
-- If Put_Image is disabled, call the "unknown" version |
| 6132 |
|
| 6133 |
if not Put_Image_Enabled (U_Type) then |
| 6134 |
Rewrite (N, Build_Unknown_Put_Image_Call (N)); |
| 6135 |
Analyze (N); |
| 6136 |
return; |
| 6137 |
|
| 6138 |
-- For elementary types, we call the routine in System.Put_Images |
| 6139 |
-- directly. |
| 6140 |
|
| 6141 |
elsif Is_Elementary_Type (U_Type) then |
| 6142 |
Rewrite (N, Build_Elementary_Put_Image_Call (N)); |
| 6143 |
Analyze (N); |
| 6144 |
return; |
| 6145 |
|
| 6146 |
-- String type objects, including custom string types, and |
| 6147 |
-- excluding C arrays. |
| 6148 |
|
| 6149 |
elsif Is_String_Type (U_Type) |
| 6150 |
and then C_Type in Standard_Character |
| 6151 |
| Standard_Wide_Character |
| 6152 |
| Standard_Wide_Wide_Character |
| 6153 |
and then (not RTU_Loaded (Interfaces_C) |
| 6154 |
or else Enclosing_Lib_Unit_Entity (U_Type) |
| 6155 |
/= RTU_Entity (Interfaces_C)) |
| 6156 |
then |
| 6157 |
Rewrite (N, Build_String_Put_Image_Call (N)); |
| 6158 |
Analyze (N); |
| 6159 |
return; |
| 6160 |
|
| 6161 |
elsif Is_Array_Type (U_Type) then |
| 6162 |
Pname := Cached_Attribute_Ops.Put_Image_Map.Get (U_Type); |
| 6163 |
Cached_Attribute_Ops.Validate_Cached_Candidate |
| 6164 |
(Pname, Attr_Ref => N); |
| 6165 |
if No (Pname) then |
| 6166 |
declare |
| 6167 |
procedure Build_And_Insert_Array_Put_Image_Proc is |
| 6168 |
new Build_And_Insert_Type_Attr_Subp |
| 6169 |
(Build_Array_Put_Image_Procedure); |
| 6170 |
|
| 6171 |
begin |
| 6172 |
Build_And_Insert_Array_Put_Image_Proc |
| 6173 |
(Typ => U_Type, |
| 6174 |
Decl => Decl, |
| 6175 |
Subp => Pname, |
| 6176 |
Attr_Ref => N); |
| 6177 |
end; |
| 6178 |
|
| 6179 |
Cached_Attribute_Ops.Put_Image_Map.Set (U_Type, Pname); |
| 6180 |
end if; |
| 6181 |
|
| 6182 |
-- Tagged type case, use the primitive Put_Image function. Note |
| 6183 |
-- that this will dispatch in the class-wide case which is what we |
| 6184 |
-- want. |
| 6185 |
|
| 6186 |
elsif Is_Tagged_Type (U_Type) then |
| 6187 |
Pname := Find_Optional_Prim_Op (U_Type, TSS_Put_Image); |
| 6188 |
|
| 6189 |
-- ????Need Find_Optional_Prim_Op instead of Find_Prim_Op, |
| 6190 |
-- because we might be deriving from a predefined type, which |
| 6191 |
-- currently has Put_Image_Enabled False. |
| 6192 |
|
| 6193 |
if No (Pname) then |
| 6194 |
Rewrite (N, Build_Unknown_Put_Image_Call (N)); |
| 6195 |
Analyze (N); |
| 6196 |
return; |
| 6197 |
end if; |
| 6198 |
|
| 6199 |
elsif Is_Protected_Type (U_Type) then |
| 6200 |
Rewrite (N, Build_Protected_Put_Image_Call (N)); |
| 6201 |
Analyze (N); |
| 6202 |
return; |
| 6203 |
|
| 6204 |
elsif Is_Task_Type (U_Type) then |
| 6205 |
Rewrite (N, Build_Task_Put_Image_Call (N)); |
| 6206 |
Analyze (N); |
| 6207 |
return; |
| 6208 |
|
| 6209 |
-- All other record type cases |
| 6210 |
|
| 6211 |
else |
| 6212 |
pragma Assert (Is_Record_Type (U_Type)); |
| 6213 |
declare |
| 6214 |
Base_Typ : constant Entity_Id := Full_Base (U_Type); |
| 6215 |
begin |
| 6216 |
Pname := Cached_Attribute_Ops.Put_Image_Map.Get (Base_Typ); |
| 6217 |
Cached_Attribute_Ops.Validate_Cached_Candidate |
| 6218 |
(Pname, Attr_Ref => N); |
| 6219 |
if No (Pname) then |
| 6220 |
declare |
| 6221 |
procedure Build_And_Insert_Record_Put_Image_Proc is |
| 6222 |
new Build_And_Insert_Type_Attr_Subp |
| 6223 |
(Build_Record_Put_Image_Procedure); |
| 6224 |
|
| 6225 |
begin |
| 6226 |
Build_And_Insert_Record_Put_Image_Proc |
| 6227 |
(Typ => Base_Typ, |
| 6228 |
Decl => Decl, |
| 6229 |
Subp => Pname, |
| 6230 |
Attr_Ref => N); |
| 6231 |
end; |
| 6232 |
|
| 6233 |
Cached_Attribute_Ops.Put_Image_Map.Set (Base_Typ, Pname); |
| 6234 |
end if; |
| 6235 |
end; |
| 6236 |
end if; |
| 6237 |
end if; |
| 6238 |
|
| 6239 |
-- If we fall through, Pname is the procedure to be called |
| 6240 |
|
| 6241 |
Rewrite_Attribute_Proc_Call (Pname); |
| 6242 |
end Put_Image; |
| 6243 |
|
| 6244 |
------------------ |
| 6245 |
-- Range_Length -- |
| 6246 |
------------------ |
| 6247 |
|
| 6248 |
when Attribute_Range_Length => |
| 6249 |
|
| 6250 |
-- The only special processing required is for the case where |
| 6251 |
-- Range_Length is applied to an enumeration type with holes. |
| 6252 |
-- In this case we transform |
| 6253 |
|
| 6254 |
-- X'Range_Length |
| 6255 |
|
| 6256 |
-- to |
| 6257 |
|
| 6258 |
-- X'Pos (X'Last) - X'Pos (X'First) + 1 |
| 6259 |
|
| 6260 |
-- So that the result reflects the proper Pos values instead |
| 6261 |
-- of the underlying representations. |
| 6262 |
|
| 6263 |
if Is_Enumeration_Type (Ptyp) |
| 6264 |
and then Has_Non_Standard_Rep (Ptyp) |
| 6265 |
then |
| 6266 |
Rewrite (N, |
| 6267 |
Make_Op_Add (Loc, |
| 6268 |
Left_Opnd => |
| 6269 |
Make_Op_Subtract (Loc, |
| 6270 |
Left_Opnd => |
| 6271 |
Make_Attribute_Reference (Loc, |
| 6272 |
Attribute_Name => Name_Pos, |
| 6273 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 6274 |
Expressions => New_List ( |
| 6275 |
Make_Attribute_Reference (Loc, |
| 6276 |
Attribute_Name => Name_Last, |
| 6277 |
Prefix => |
| 6278 |
New_Occurrence_Of (Ptyp, Loc)))), |
| 6279 |
|
| 6280 |
Right_Opnd => |
| 6281 |
Make_Attribute_Reference (Loc, |
| 6282 |
Attribute_Name => Name_Pos, |
| 6283 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 6284 |
Expressions => New_List ( |
| 6285 |
Make_Attribute_Reference (Loc, |
| 6286 |
Attribute_Name => Name_First, |
| 6287 |
Prefix => |
| 6288 |
New_Occurrence_Of (Ptyp, Loc))))), |
| 6289 |
|
| 6290 |
Right_Opnd => Make_Integer_Literal (Loc, 1))); |
| 6291 |
|
| 6292 |
Analyze_And_Resolve (N, Typ); |
| 6293 |
|
| 6294 |
-- For all other cases, the attribute is handled by the back end, but |
| 6295 |
-- we need to deal with the case of the range check on a universal |
| 6296 |
-- integer. |
| 6297 |
|
| 6298 |
else |
| 6299 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 6300 |
end if; |
| 6301 |
|
| 6302 |
------------ |
| 6303 |
-- Reduce -- |
| 6304 |
------------ |
| 6305 |
|
| 6306 |
when Attribute_Reduce => |
| 6307 |
declare |
| 6308 |
E1 : constant Node_Id := First (Exprs); |
| 6309 |
E2 : constant Node_Id := Next (E1); |
| 6310 |
Bnn : constant Entity_Id := Make_Temporary (Loc, 'B', N); |
| 6311 |
|
| 6312 |
Accum_Typ : Entity_Id := Empty; |
| 6313 |
New_Loop : Node_Id; |
| 6314 |
|
| 6315 |
function Build_Stat (Comp : Node_Id) return Node_Id; |
| 6316 |
-- The reducer can be a function, a procedure whose first |
| 6317 |
-- parameter is in-out, or an attribute that is a function, |
| 6318 |
-- which (for now) can only be Min/Max. This subprogram |
| 6319 |
-- builds the corresponding computation for the generated loop |
| 6320 |
-- and retrieves the accumulator type as per RM 4.5.10(19/5). |
| 6321 |
|
| 6322 |
---------------- |
| 6323 |
-- Build_Stat -- |
| 6324 |
---------------- |
| 6325 |
|
| 6326 |
function Build_Stat (Comp : Node_Id) return Node_Id is |
| 6327 |
Stat : Node_Id; |
| 6328 |
|
| 6329 |
begin |
| 6330 |
if Nkind (E1) = N_Attribute_Reference then |
| 6331 |
Accum_Typ := Base_Type (Entity (Prefix (E1))); |
| 6332 |
Stat := Make_Assignment_Statement (Loc, |
| 6333 |
Name => New_Occurrence_Of (Bnn, Loc), |
| 6334 |
Expression => Make_Attribute_Reference (Loc, |
| 6335 |
Attribute_Name => Attribute_Name (E1), |
| 6336 |
Prefix => New_Copy (Prefix (E1)), |
| 6337 |
Expressions => New_List ( |
| 6338 |
New_Occurrence_Of (Bnn, Loc), |
| 6339 |
Comp))); |
| 6340 |
|
| 6341 |
elsif Ekind (Entity (E1)) = E_Procedure then |
| 6342 |
Accum_Typ := Etype (First_Formal (Entity (E1))); |
| 6343 |
Stat := Make_Procedure_Call_Statement (Loc, |
| 6344 |
Name => New_Occurrence_Of (Entity (E1), Loc), |
| 6345 |
Parameter_Associations => New_List ( |
| 6346 |
New_Occurrence_Of (Bnn, Loc), |
| 6347 |
Comp)); |
| 6348 |
|
| 6349 |
else |
| 6350 |
Accum_Typ := Etype (Entity (E1)); |
| 6351 |
Stat := Make_Assignment_Statement (Loc, |
| 6352 |
Name => New_Occurrence_Of (Bnn, Loc), |
| 6353 |
Expression => Make_Function_Call (Loc, |
| 6354 |
Name => New_Occurrence_Of (Entity (E1), Loc), |
| 6355 |
Parameter_Associations => New_List ( |
| 6356 |
New_Occurrence_Of (Bnn, Loc), |
| 6357 |
Comp))); |
| 6358 |
end if; |
| 6359 |
|
| 6360 |
-- Try to cope if E1 is wrong because it is an overloaded |
| 6361 |
-- subprogram that happens to be the first candidate |
| 6362 |
-- on a homonym chain, but that resolution candidate turns |
| 6363 |
-- out to be the wrong one. |
| 6364 |
-- This workaround usually gets the right type, but it can |
| 6365 |
-- yield the wrong subtype of that type. |
| 6366 |
|
| 6367 |
if Base_Type (Accum_Typ) /= Base_Type (Etype (N)) then |
| 6368 |
Accum_Typ := Etype (N); |
| 6369 |
end if; |
| 6370 |
|
| 6371 |
-- If Accum_Typ is a universal numeric type and the prefix |
| 6372 |
-- is not an aggregate, use its component type in order to |
| 6373 |
-- avoid resolution problems later on. |
| 6374 |
|
| 6375 |
if Is_Universal_Numeric_Type (Accum_Typ) then |
| 6376 |
if Nkind (Prefix (N)) /= N_Aggregate then |
| 6377 |
Accum_Typ := Component_Type (Etype (Prefix (N))); |
| 6378 |
end if; |
| 6379 |
end if; |
| 6380 |
|
| 6381 |
return Stat; |
| 6382 |
end Build_Stat; |
| 6383 |
|
| 6384 |
-- If the prefix is an aggregate, its unique component is an |
| 6385 |
-- Iterated_Element, and we create a loop out of its iterator. |
| 6386 |
-- The iterated_component_association is parsed as a loop parameter |
| 6387 |
-- specification with "in" or as a container iterator with "of". |
| 6388 |
|
| 6389 |
begin |
| 6390 |
if Nkind (Prefix (N)) = N_Aggregate then |
| 6391 |
declare |
| 6392 |
Stream : constant Node_Id := |
| 6393 |
First (Component_Associations (Prefix (N))); |
| 6394 |
Expr : constant Node_Id := Expression (Stream); |
| 6395 |
Id : constant Node_Id := Defining_Identifier (Stream); |
| 6396 |
It_Spec : constant Node_Id := |
| 6397 |
Iterator_Specification (Stream); |
| 6398 |
Ch : Node_Id; |
| 6399 |
Iter : Node_Id; |
| 6400 |
|
| 6401 |
begin |
| 6402 |
-- Iteration may be given by an element iterator: |
| 6403 |
|
| 6404 |
if Nkind (Stream) = N_Iterated_Component_Association |
| 6405 |
and then Present (It_Spec) |
| 6406 |
and then Of_Present (It_Spec) |
| 6407 |
then |
| 6408 |
Iter := |
| 6409 |
Make_Iteration_Scheme (Loc, |
| 6410 |
Iterator_Specification => |
| 6411 |
Relocate_Node (It_Spec), |
| 6412 |
Loop_Parameter_Specification => Empty); |
| 6413 |
|
| 6414 |
else |
| 6415 |
Ch := First (Discrete_Choices (Stream)); |
| 6416 |
Iter := |
| 6417 |
Make_Iteration_Scheme (Loc, |
| 6418 |
Iterator_Specification => Empty, |
| 6419 |
Loop_Parameter_Specification => |
| 6420 |
Make_Loop_Parameter_Specification (Loc, |
| 6421 |
Defining_Identifier => New_Copy (Id), |
| 6422 |
Discrete_Subtype_Definition => |
| 6423 |
Relocate_Node (Ch))); |
| 6424 |
end if; |
| 6425 |
|
| 6426 |
New_Loop := Make_Loop_Statement (Loc, |
| 6427 |
Iteration_Scheme => Iter, |
| 6428 |
End_Label => Empty, |
| 6429 |
Statements => |
| 6430 |
New_List (Build_Stat (Relocate_Node (Expr)))); |
| 6431 |
end; |
| 6432 |
|
| 6433 |
else |
| 6434 |
-- If the prefix is a name, we construct an element iterator |
| 6435 |
-- over it. Its expansion will verify that it is an array or |
| 6436 |
-- a container with the proper aspects. |
| 6437 |
|
| 6438 |
declare |
| 6439 |
Elem : constant Entity_Id := Make_Temporary (Loc, 'E', N); |
| 6440 |
|
| 6441 |
Iter : Node_Id; |
| 6442 |
|
| 6443 |
begin |
| 6444 |
Iter := |
| 6445 |
Make_Iterator_Specification (Loc, |
| 6446 |
Defining_Identifier => Elem, |
| 6447 |
Subtype_Indication => Empty, |
| 6448 |
Of_Present => True, |
| 6449 |
Name => Relocate_Node (Prefix (N))); |
| 6450 |
|
| 6451 |
New_Loop := Make_Loop_Statement (Loc, |
| 6452 |
Iteration_Scheme => |
| 6453 |
Make_Iteration_Scheme (Loc, |
| 6454 |
Iterator_Specification => Iter, |
| 6455 |
Loop_Parameter_Specification => Empty), |
| 6456 |
End_Label => Empty, |
| 6457 |
Statements => New_List ( |
| 6458 |
Build_Stat (New_Occurrence_Of (Elem, Loc)))); |
| 6459 |
|
| 6460 |
end; |
| 6461 |
end if; |
| 6462 |
|
| 6463 |
Rewrite (N, |
| 6464 |
Make_Expression_With_Actions (Loc, |
| 6465 |
Actions => New_List ( |
| 6466 |
Make_Object_Declaration (Loc, |
| 6467 |
Defining_Identifier => Bnn, |
| 6468 |
Object_Definition => |
| 6469 |
New_Occurrence_Of (Accum_Typ, Loc), |
| 6470 |
Expression => Relocate_Node (E2)), New_Loop), |
| 6471 |
Expression => New_Occurrence_Of (Bnn, Loc))); |
| 6472 |
|
| 6473 |
Analyze_And_Resolve (N, Accum_Typ); |
| 6474 |
end; |
| 6475 |
|
| 6476 |
---------- |
| 6477 |
-- Read -- |
| 6478 |
---------- |
| 6479 |
|
| 6480 |
when Attribute_Read => Read : declare |
| 6481 |
P_Type : constant Entity_Id := Entity (Pref); |
| 6482 |
B_Type : constant Entity_Id := Base_Type (P_Type); |
| 6483 |
U_Type : constant Entity_Id := Underlying_Type (P_Type); |
| 6484 |
Pname : Entity_Id; |
| 6485 |
Decl : Node_Id; |
| 6486 |
Prag : Node_Id; |
| 6487 |
Arg2 : Node_Id; |
| 6488 |
Rfunc : Node_Id; |
| 6489 |
Lhs : Node_Id; |
| 6490 |
Rhs : Node_Id; |
| 6491 |
|
| 6492 |
begin |
| 6493 |
-- If no underlying type, we have an error that will be diagnosed |
| 6494 |
-- elsewhere, so here we just completely ignore the expansion. |
| 6495 |
|
| 6496 |
if No (U_Type) then |
| 6497 |
return; |
| 6498 |
end if; |
| 6499 |
|
| 6500 |
-- Stream operations can appear in user code even if the restriction |
| 6501 |
-- No_Streams is active (for example, when instantiating a predefined |
| 6502 |
-- container). In that case rewrite the attribute as a Raise to |
| 6503 |
-- prevent any run-time use. |
| 6504 |
|
| 6505 |
if Restriction_Active (No_Streams) then |
| 6506 |
Rewrite (N, |
| 6507 |
Make_Raise_Program_Error (Loc, |
| 6508 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 6509 |
Set_Etype (N, B_Type); |
| 6510 |
return; |
| 6511 |
end if; |
| 6512 |
|
| 6513 |
-- The simple case, if there is a TSS for Read, just call it |
| 6514 |
|
| 6515 |
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read, N); |
| 6516 |
|
| 6517 |
if No (Pname) then |
| 6518 |
|
| 6519 |
-- If there is a Stream_Convert pragma, use it, we rewrite |
| 6520 |
|
| 6521 |
-- sourcetyp'Read (stream, Item) |
| 6522 |
|
| 6523 |
-- as |
| 6524 |
|
| 6525 |
-- Item := sourcetyp (strmread (strmtyp'Input (Stream))); |
| 6526 |
|
| 6527 |
-- where strmread is the given Read function that converts an |
| 6528 |
-- argument of type strmtyp to type sourcetyp or a type from which |
| 6529 |
-- it is derived. The conversion to sourcetyp is required in the |
| 6530 |
-- latter case. |
| 6531 |
|
| 6532 |
-- A special case arises if Item is a type conversion in which |
| 6533 |
-- case, we have to expand to: |
| 6534 |
|
| 6535 |
-- Itemx := typex (strmread (strmtyp'Input (Stream))); |
| 6536 |
|
| 6537 |
-- where Itemx is the expression of the type conversion (i.e. |
| 6538 |
-- the actual object), and typex is the type of Itemx. |
| 6539 |
|
| 6540 |
Prag := Get_Stream_Convert_Pragma (P_Type); |
| 6541 |
|
| 6542 |
if Present (Prag) then |
| 6543 |
Arg2 := Next (First (Pragma_Argument_Associations (Prag))); |
| 6544 |
Rfunc := Entity (Expression (Arg2)); |
| 6545 |
Lhs := Relocate_Node (Next (First (Exprs))); |
| 6546 |
Rhs := |
| 6547 |
OK_Convert_To (B_Type, |
| 6548 |
Make_Function_Call (Loc, |
| 6549 |
Name => New_Occurrence_Of (Rfunc, Loc), |
| 6550 |
Parameter_Associations => New_List ( |
| 6551 |
Make_Attribute_Reference (Loc, |
| 6552 |
Prefix => |
| 6553 |
New_Occurrence_Of |
| 6554 |
(Etype (First_Formal (Rfunc)), Loc), |
| 6555 |
Attribute_Name => Name_Input, |
| 6556 |
Expressions => New_List ( |
| 6557 |
Relocate_Node (First (Exprs))))))); |
| 6558 |
|
| 6559 |
if Nkind (Lhs) = N_Type_Conversion then |
| 6560 |
Lhs := Expression (Lhs); |
| 6561 |
Rhs := Convert_To (Etype (Lhs), Rhs); |
| 6562 |
end if; |
| 6563 |
|
| 6564 |
Rewrite (N, |
| 6565 |
Make_Assignment_Statement (Loc, |
| 6566 |
Name => Lhs, |
| 6567 |
Expression => Rhs)); |
| 6568 |
Set_Assignment_OK (Lhs); |
| 6569 |
Analyze (N); |
| 6570 |
return; |
| 6571 |
|
| 6572 |
-- Limited types |
| 6573 |
|
| 6574 |
elsif Default_Streaming_Unavailable (U_Type) then |
| 6575 |
-- Do the same thing here as is done above in the |
| 6576 |
-- case where a No_Streams restriction is active. |
| 6577 |
|
| 6578 |
Rewrite (N, |
| 6579 |
Make_Raise_Program_Error (Loc, |
| 6580 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 6581 |
Set_Etype (N, B_Type); |
| 6582 |
return; |
| 6583 |
|
| 6584 |
-- For elementary types, we call the I_xxx routine using the first |
| 6585 |
-- parameter and then assign the result into the second parameter. |
| 6586 |
-- We set Assignment_OK to deal with the conversion case. |
| 6587 |
|
| 6588 |
elsif Is_Elementary_Type (U_Type) then |
| 6589 |
declare |
| 6590 |
Lhs : Node_Id; |
| 6591 |
Rhs : Node_Id; |
| 6592 |
|
| 6593 |
begin |
| 6594 |
Lhs := Relocate_Node (Next (First (Exprs))); |
| 6595 |
Rhs := Build_Elementary_Input_Call (N); |
| 6596 |
|
| 6597 |
if Nkind (Lhs) = N_Type_Conversion then |
| 6598 |
Lhs := Expression (Lhs); |
| 6599 |
Rhs := Convert_To (Etype (Lhs), Rhs); |
| 6600 |
end if; |
| 6601 |
|
| 6602 |
Set_Assignment_OK (Lhs); |
| 6603 |
|
| 6604 |
Rewrite (N, |
| 6605 |
Make_Assignment_Statement (Loc, |
| 6606 |
Name => Lhs, |
| 6607 |
Expression => Rhs)); |
| 6608 |
|
| 6609 |
Analyze (N); |
| 6610 |
return; |
| 6611 |
end; |
| 6612 |
|
| 6613 |
-- Array type case |
| 6614 |
|
| 6615 |
elsif Is_Array_Type (U_Type) then |
| 6616 |
declare |
| 6617 |
procedure Build_And_Insert_Array_Read_Proc is |
| 6618 |
new Build_And_Insert_Type_Attr_Subp |
| 6619 |
(Build_Array_Read_Procedure); |
| 6620 |
begin |
| 6621 |
Build_And_Insert_Array_Read_Proc |
| 6622 |
(Typ => Full_Base (U_Type), |
| 6623 |
Decl => Decl, |
| 6624 |
Subp => Pname, |
| 6625 |
Attr_Ref => N); |
| 6626 |
end; |
| 6627 |
|
| 6628 |
-- Tagged type case, use the primitive Read function. Note that |
| 6629 |
-- this will dispatch in the class-wide case which is what we want |
| 6630 |
|
| 6631 |
elsif Is_Tagged_Type (U_Type) then |
| 6632 |
Pname := Find_Prim_Op (U_Type, TSS_Stream_Read); |
| 6633 |
|
| 6634 |
-- All other record type cases, including protected records. The |
| 6635 |
-- latter only arise for expander generated code for handling |
| 6636 |
-- shared passive partition access. |
| 6637 |
|
| 6638 |
else |
| 6639 |
pragma Assert |
| 6640 |
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); |
| 6641 |
|
| 6642 |
-- Ada 2005 (AI-216): Program_Error is raised when executing |
| 6643 |
-- the default implementation of the Read attribute of an |
| 6644 |
-- Unchecked_Union type. We replace the attribute with a |
| 6645 |
-- raise statement (rather than inserting it before) to handle |
| 6646 |
-- properly the case of an unchecked union that is a record |
| 6647 |
-- component. |
| 6648 |
|
| 6649 |
if Is_Unchecked_Union (Base_Type (U_Type)) then |
| 6650 |
Rewrite (N, |
| 6651 |
Make_Raise_Program_Error (Loc, |
| 6652 |
Reason => PE_Unchecked_Union_Restriction)); |
| 6653 |
Set_Etype (N, B_Type); |
| 6654 |
return; |
| 6655 |
end if; |
| 6656 |
|
| 6657 |
declare |
| 6658 |
procedure Build_Record_Read_Proc |
| 6659 |
(Typ : Entity_Id; |
| 6660 |
Decl : out Node_Id; |
| 6661 |
Subp : out Entity_Id); |
| 6662 |
|
| 6663 |
procedure Build_Record_Read_Proc |
| 6664 |
(Typ : Entity_Id; |
| 6665 |
Decl : out Node_Id; |
| 6666 |
Subp : out Entity_Id) is |
| 6667 |
begin |
| 6668 |
if Has_Defaulted_Discriminants (Typ) then |
| 6669 |
Build_Mutable_Record_Read_Procedure |
| 6670 |
(Typ, Decl, Subp); |
| 6671 |
else |
| 6672 |
Build_Record_Read_Procedure |
| 6673 |
(Typ, Decl, Subp); |
| 6674 |
end if; |
| 6675 |
end Build_Record_Read_Proc; |
| 6676 |
|
| 6677 |
procedure Build_And_Insert_Record_Read_Proc is |
| 6678 |
new Build_And_Insert_Type_Attr_Subp |
| 6679 |
(Build_Record_Read_Proc); |
| 6680 |
begin |
| 6681 |
Build_And_Insert_Record_Read_Proc |
| 6682 |
(Typ => Full_Base (U_Type), |
| 6683 |
Decl => Decl, |
| 6684 |
Subp => Pname, |
| 6685 |
Attr_Ref => N); |
| 6686 |
end; |
| 6687 |
end if; |
| 6688 |
end if; |
| 6689 |
|
| 6690 |
Rewrite_Attribute_Proc_Call (Pname); |
| 6691 |
|
| 6692 |
if not Is_Tagged_Type (P_Type) then |
| 6693 |
Cached_Attribute_Ops.Read_Map.Set (U_Type, Pname); |
| 6694 |
end if; |
| 6695 |
end Read; |
| 6696 |
|
| 6697 |
--------- |
| 6698 |
-- Ref -- |
| 6699 |
--------- |
| 6700 |
|
| 6701 |
-- Ref is identical to To_Address, see To_Address for processing |
| 6702 |
|
| 6703 |
--------------- |
| 6704 |
-- Remainder -- |
| 6705 |
--------------- |
| 6706 |
|
| 6707 |
-- Transforms 'Remainder into a call to the floating-point attribute |
| 6708 |
-- function Remainder in Fat_xxx (where xxx is the root type) |
| 6709 |
|
| 6710 |
when Attribute_Remainder => |
| 6711 |
Expand_Fpt_Attribute_RR (N); |
| 6712 |
|
| 6713 |
------------ |
| 6714 |
-- Result -- |
| 6715 |
------------ |
| 6716 |
|
| 6717 |
-- Transform 'Result into reference to _Result formal. At the point |
| 6718 |
-- where a legal 'Result attribute is expanded, we know that we are in |
| 6719 |
-- the context of a _Postcondition function with a _Result parameter. |
| 6720 |
|
| 6721 |
when Attribute_Result => |
| 6722 |
Rewrite (N, Make_Identifier (Loc, Chars => Name_uResult)); |
| 6723 |
Analyze_And_Resolve (N, Typ); |
| 6724 |
|
| 6725 |
----------- |
| 6726 |
-- Round -- |
| 6727 |
----------- |
| 6728 |
|
| 6729 |
-- The handling of the Round attribute is delicate when the operand is |
| 6730 |
-- universal fixed. In this case, the processing in Sem_Attr introduced |
| 6731 |
-- a conversion to universal real, reflecting the semantics of Round, |
| 6732 |
-- but we do not want anything to do with universal real at run time, |
| 6733 |
-- since this corresponds to using floating-point arithmetic. |
| 6734 |
|
| 6735 |
-- What we have now is that the Etype of the Round attribute correctly |
| 6736 |
-- indicates the final result type. The operand of the Round is the |
| 6737 |
-- conversion to universal real, described above, and the operand of |
| 6738 |
-- this conversion is the actual operand of Round, which may be the |
| 6739 |
-- special case of a fixed point multiplication or division. |
| 6740 |
|
| 6741 |
-- The expander will expand first the operand of the conversion, then |
| 6742 |
-- the conversion, and finally the round attribute itself, since we |
| 6743 |
-- always work inside out. But we cannot simply process naively in this |
| 6744 |
-- order. In the semantic world where universal fixed and real really |
| 6745 |
-- exist and have infinite precision, there is no problem, but in the |
| 6746 |
-- implementation world, where universal real is a floating-point type, |
| 6747 |
-- we would get the wrong result. |
| 6748 |
|
| 6749 |
-- So the approach is as follows. When expanding a multiply or divide |
| 6750 |
-- whose type is universal fixed, Fixup_Universal_Fixed_Operation will |
| 6751 |
-- look up and skip the conversion to universal real if its parent is |
| 6752 |
-- a Round attribute, taking information from this attribute node. In |
| 6753 |
-- the other cases, Expand_N_Type_Conversion does the same by looking |
| 6754 |
-- at its parent to see if it is a Round attribute, before calling the |
| 6755 |
-- fixed-point expansion routine. |
| 6756 |
|
| 6757 |
-- This means that by the time we get to expanding the Round attribute |
| 6758 |
-- itself, the Round is nothing more than a type conversion (and will |
| 6759 |
-- often be a null type conversion), so we just replace it with the |
| 6760 |
-- appropriate conversion operation. |
| 6761 |
|
| 6762 |
when Attribute_Round => |
| 6763 |
if Etype (First (Exprs)) = Etype (N) then |
| 6764 |
Rewrite (N, Relocate_Node (First (Exprs))); |
| 6765 |
else |
| 6766 |
Rewrite (N, Convert_To (Etype (N), First (Exprs))); |
| 6767 |
Set_Rounded_Result (N); |
| 6768 |
end if; |
| 6769 |
Analyze_And_Resolve (N); |
| 6770 |
|
| 6771 |
-------------- |
| 6772 |
-- Rounding -- |
| 6773 |
-------------- |
| 6774 |
|
| 6775 |
-- Transforms 'Rounding into a call to the floating-point attribute |
| 6776 |
-- function Rounding in Fat_xxx (where xxx is the root type) |
| 6777 |
-- Expansion is avoided for cases the back end can handle directly. |
| 6778 |
|
| 6779 |
when Attribute_Rounding => |
| 6780 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 6781 |
Expand_Fpt_Attribute_R (N); |
| 6782 |
end if; |
| 6783 |
|
| 6784 |
------------- |
| 6785 |
-- Scaling -- |
| 6786 |
------------- |
| 6787 |
|
| 6788 |
-- Transforms 'Scaling into a call to the floating-point attribute |
| 6789 |
-- function Scaling in Fat_xxx (where xxx is the root type) |
| 6790 |
|
| 6791 |
when Attribute_Scaling => |
| 6792 |
Expand_Fpt_Attribute_RI (N); |
| 6793 |
|
| 6794 |
---------------------------------------- |
| 6795 |
-- Simple_Storage_Pool & Storage_Pool -- |
| 6796 |
---------------------------------------- |
| 6797 |
|
| 6798 |
when Attribute_Simple_Storage_Pool | Attribute_Storage_Pool => |
| 6799 |
Rewrite (N, |
| 6800 |
Make_Type_Conversion (Loc, |
| 6801 |
Subtype_Mark => New_Occurrence_Of (Etype (N), Loc), |
| 6802 |
Expression => New_Occurrence_Of (Entity (N), Loc))); |
| 6803 |
Analyze_And_Resolve (N, Typ); |
| 6804 |
|
| 6805 |
---------- |
| 6806 |
-- Size -- |
| 6807 |
---------- |
| 6808 |
|
| 6809 |
when Attribute_Object_Size |
| 6810 |
| Attribute_Size |
| 6811 |
| Attribute_Value_Size |
| 6812 |
| Attribute_VADS_Size |
| 6813 |
=> |
| 6814 |
Size : declare |
| 6815 |
New_Node : Node_Id; |
| 6816 |
|
| 6817 |
begin |
| 6818 |
-- Processing for VADS_Size case. Note that this processing |
| 6819 |
-- removes all traces of VADS_Size from the tree, and completes |
| 6820 |
-- all required processing for VADS_Size by translating the |
| 6821 |
-- attribute reference to an appropriate Size or Object_Size |
| 6822 |
-- reference. |
| 6823 |
|
| 6824 |
if Id = Attribute_VADS_Size |
| 6825 |
or else (Use_VADS_Size and then Id = Attribute_Size) |
| 6826 |
then |
| 6827 |
-- If the size is specified, then we simply use the specified |
| 6828 |
-- size. This applies to both types and objects. The size of an |
| 6829 |
-- object can be specified in the following ways: |
| 6830 |
|
| 6831 |
-- An explicit size clause is given for an object |
| 6832 |
-- A component size is specified for an indexed component |
| 6833 |
-- A component clause is specified for a selected component |
| 6834 |
-- The object is a component of a packed composite object |
| 6835 |
|
| 6836 |
-- If the size is specified, then VADS_Size of an object |
| 6837 |
|
| 6838 |
if (Is_Entity_Name (Pref) |
| 6839 |
and then Present (Size_Clause (Entity (Pref)))) |
| 6840 |
or else |
| 6841 |
(Nkind (Pref) = N_Component_Clause |
| 6842 |
and then (Present (Component_Clause |
| 6843 |
(Entity (Selector_Name (Pref)))) |
| 6844 |
or else Is_Packed (Etype (Prefix (Pref))))) |
| 6845 |
or else |
| 6846 |
(Nkind (Pref) = N_Indexed_Component |
| 6847 |
and then (Known_Component_Size (Etype (Prefix (Pref))) |
| 6848 |
or else Is_Packed (Etype (Prefix (Pref))))) |
| 6849 |
then |
| 6850 |
Set_Attribute_Name (N, Name_Size); |
| 6851 |
|
| 6852 |
-- Otherwise if we have an object rather than a type, then |
| 6853 |
-- the VADS_Size attribute applies to the type of the object, |
| 6854 |
-- rather than the object itself. This is one of the respects |
| 6855 |
-- in which VADS_Size differs from Size. |
| 6856 |
|
| 6857 |
else |
| 6858 |
if (not Is_Entity_Name (Pref) |
| 6859 |
or else not Is_Type (Entity (Pref))) |
| 6860 |
and then (Is_Scalar_Type (Ptyp) |
| 6861 |
or else Is_Constrained (Ptyp)) |
| 6862 |
then |
| 6863 |
Rewrite (Pref, New_Occurrence_Of (Ptyp, Loc)); |
| 6864 |
end if; |
| 6865 |
|
| 6866 |
-- For a scalar type for which no size was explicitly given, |
| 6867 |
-- VADS_Size means Object_Size. This is the other respect in |
| 6868 |
-- which VADS_Size differs from Size. |
| 6869 |
|
| 6870 |
if Is_Scalar_Type (Ptyp) |
| 6871 |
and then No (Size_Clause (Ptyp)) |
| 6872 |
then |
| 6873 |
Set_Attribute_Name (N, Name_Object_Size); |
| 6874 |
|
| 6875 |
-- In all other cases, Size and VADS_Size are the same |
| 6876 |
|
| 6877 |
else |
| 6878 |
Set_Attribute_Name (N, Name_Size); |
| 6879 |
end if; |
| 6880 |
end if; |
| 6881 |
end if; |
| 6882 |
|
| 6883 |
-- If the prefix is X'Class, transform it into a direct reference |
| 6884 |
-- to the class-wide type, because the back end must not see a |
| 6885 |
-- 'Class reference. |
| 6886 |
|
| 6887 |
if Is_Entity_Name (Pref) |
| 6888 |
and then Is_Class_Wide_Type (Entity (Pref)) |
| 6889 |
then |
| 6890 |
Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc)); |
| 6891 |
return; |
| 6892 |
|
| 6893 |
-- For X'Size applied to an object of a class-wide type, transform |
| 6894 |
-- X'Size into a call to the primitive operation _Size applied to |
| 6895 |
-- X. |
| 6896 |
|
| 6897 |
elsif Is_Class_Wide_Type (Ptyp) then |
| 6898 |
|
| 6899 |
-- No need to do anything else compiling under restriction |
| 6900 |
-- No_Dispatching_Calls. During the semantic analysis we |
| 6901 |
-- already noted this restriction violation. |
| 6902 |
|
| 6903 |
if Restriction_Active (No_Dispatching_Calls) then |
| 6904 |
return; |
| 6905 |
end if; |
| 6906 |
|
| 6907 |
New_Node := |
| 6908 |
Make_Function_Call (Loc, |
| 6909 |
Name => |
| 6910 |
New_Occurrence_Of (Find_Prim_Op (Ptyp, Name_uSize), Loc), |
| 6911 |
Parameter_Associations => New_List (Pref)); |
| 6912 |
|
| 6913 |
if Typ /= Standard_Long_Long_Integer then |
| 6914 |
|
| 6915 |
-- The context is a specific integer type with which the |
| 6916 |
-- original attribute was compatible. The function has a |
| 6917 |
-- specific type as well, so to preserve the compatibility |
| 6918 |
-- we must convert explicitly. |
| 6919 |
|
| 6920 |
New_Node := Convert_To (Typ, New_Node); |
| 6921 |
end if; |
| 6922 |
|
| 6923 |
Rewrite (N, New_Node); |
| 6924 |
Analyze_And_Resolve (N, Typ); |
| 6925 |
return; |
| 6926 |
end if; |
| 6927 |
|
| 6928 |
-- Call Expand_Size_Attribute to do the final part of the |
| 6929 |
-- expansion which is shared with GNATprove expansion. |
| 6930 |
|
| 6931 |
Expand_Size_Attribute (N); |
| 6932 |
end Size; |
| 6933 |
|
| 6934 |
------------------ |
| 6935 |
-- Storage_Size -- |
| 6936 |
------------------ |
| 6937 |
|
| 6938 |
when Attribute_Storage_Size => Storage_Size : declare |
| 6939 |
Alloc_Op : Entity_Id := Empty; |
| 6940 |
|
| 6941 |
begin |
| 6942 |
|
| 6943 |
-- Access type case, always go to the root type |
| 6944 |
|
| 6945 |
-- The case of access types results in a value of zero for the case |
| 6946 |
-- where no storage size attribute clause has been given. If a |
| 6947 |
-- storage size has been given, then the attribute is converted |
| 6948 |
-- to a reference to the variable used to hold this value. |
| 6949 |
|
| 6950 |
if Is_Access_Type (Ptyp) then |
| 6951 |
if Present (Storage_Size_Variable (Root_Type (Ptyp))) then |
| 6952 |
Rewrite (N, |
| 6953 |
Convert_To (Typ, |
| 6954 |
Make_Attribute_Reference (Loc, |
| 6955 |
Prefix => New_Occurrence_Of |
| 6956 |
(Etype (Storage_Size_Variable (Root_Type (Ptyp))), Loc), |
| 6957 |
Attribute_Name => Name_Max, |
| 6958 |
Expressions => New_List ( |
| 6959 |
Make_Integer_Literal (Loc, 0), |
| 6960 |
New_Occurrence_Of |
| 6961 |
(Storage_Size_Variable (Root_Type (Ptyp)), Loc))))); |
| 6962 |
|
| 6963 |
elsif Present (Associated_Storage_Pool (Root_Type (Ptyp))) then |
| 6964 |
|
| 6965 |
-- If the access type is associated with a simple storage pool |
| 6966 |
-- object, then attempt to locate the optional Storage_Size |
| 6967 |
-- function of the simple storage pool type. If not found, |
| 6968 |
-- then the result will default to zero. |
| 6969 |
|
| 6970 |
if Present (Get_Rep_Pragma (Root_Type (Ptyp), |
| 6971 |
Name_Simple_Storage_Pool_Type)) |
| 6972 |
then |
| 6973 |
declare |
| 6974 |
Pool_Type : constant Entity_Id := |
| 6975 |
Base_Type (Etype (Entity (N))); |
| 6976 |
|
| 6977 |
begin |
| 6978 |
Alloc_Op := Get_Name_Entity_Id (Name_Storage_Size); |
| 6979 |
while Present (Alloc_Op) loop |
| 6980 |
if Scope (Alloc_Op) = Scope (Pool_Type) |
| 6981 |
and then Present (First_Formal (Alloc_Op)) |
| 6982 |
and then Etype (First_Formal (Alloc_Op)) = Pool_Type |
| 6983 |
then |
| 6984 |
exit; |
| 6985 |
end if; |
| 6986 |
|
| 6987 |
Alloc_Op := Homonym (Alloc_Op); |
| 6988 |
end loop; |
| 6989 |
end; |
| 6990 |
|
| 6991 |
-- In the normal Storage_Pool case, retrieve the primitive |
| 6992 |
-- function associated with the pool type. |
| 6993 |
|
| 6994 |
else |
| 6995 |
Alloc_Op := |
| 6996 |
Find_Prim_Op |
| 6997 |
(Etype (Associated_Storage_Pool (Root_Type (Ptyp))), |
| 6998 |
Attribute_Name (N)); |
| 6999 |
end if; |
| 7000 |
|
| 7001 |
-- If Storage_Size wasn't found (can only occur in the simple |
| 7002 |
-- storage pool case), then simply use zero for the result. |
| 7003 |
|
| 7004 |
if No (Alloc_Op) then |
| 7005 |
Rewrite (N, Make_Integer_Literal (Loc, 0)); |
| 7006 |
|
| 7007 |
-- Otherwise, rewrite the allocator as a call to pool type's |
| 7008 |
-- Storage_Size function. |
| 7009 |
|
| 7010 |
else |
| 7011 |
Rewrite (N, |
| 7012 |
Convert_To (Typ, |
| 7013 |
Make_Function_Call (Loc, |
| 7014 |
Name => |
| 7015 |
New_Occurrence_Of (Alloc_Op, Loc), |
| 7016 |
|
| 7017 |
Parameter_Associations => New_List ( |
| 7018 |
New_Occurrence_Of |
| 7019 |
(Associated_Storage_Pool |
| 7020 |
(Root_Type (Ptyp)), Loc))))); |
| 7021 |
end if; |
| 7022 |
|
| 7023 |
else |
| 7024 |
Rewrite (N, Make_Integer_Literal (Loc, 0)); |
| 7025 |
end if; |
| 7026 |
|
| 7027 |
Analyze_And_Resolve (N, Typ); |
| 7028 |
|
| 7029 |
-- For tasks, we retrieve the size directly from the TCB. The |
| 7030 |
-- size may depend on a discriminant of the type, and therefore |
| 7031 |
-- can be a per-object expression, so type-level information is |
| 7032 |
-- not sufficient in general. There are four cases to consider: |
| 7033 |
|
| 7034 |
-- a) If the attribute appears within a task body, the designated |
| 7035 |
-- TCB is obtained by a call to Self. |
| 7036 |
|
| 7037 |
-- b) If the prefix of the attribute is the name of a task object, |
| 7038 |
-- the designated TCB is the one stored in the corresponding record. |
| 7039 |
|
| 7040 |
-- c) If the prefix is a task type, the size is obtained from the |
| 7041 |
-- size variable created for each task type |
| 7042 |
|
| 7043 |
-- d) If no Storage_Size was specified for the type, there is no |
| 7044 |
-- size variable, and the value is a system-specific default. |
| 7045 |
|
| 7046 |
else |
| 7047 |
if In_Open_Scopes (Ptyp) then |
| 7048 |
|
| 7049 |
-- Storage_Size (Self) |
| 7050 |
|
| 7051 |
Rewrite (N, |
| 7052 |
Convert_To (Typ, |
| 7053 |
Make_Function_Call (Loc, |
| 7054 |
Name => |
| 7055 |
New_Occurrence_Of (RTE (RE_Storage_Size), Loc), |
| 7056 |
Parameter_Associations => |
| 7057 |
New_List ( |
| 7058 |
Make_Function_Call (Loc, |
| 7059 |
Name => |
| 7060 |
New_Occurrence_Of (RTE (RE_Self), Loc)))))); |
| 7061 |
|
| 7062 |
elsif not Is_Entity_Name (Pref) |
| 7063 |
or else not Is_Type (Entity (Pref)) |
| 7064 |
then |
| 7065 |
-- Storage_Size (Rec (Obj).Size) |
| 7066 |
|
| 7067 |
Rewrite (N, |
| 7068 |
Convert_To (Typ, |
| 7069 |
Make_Function_Call (Loc, |
| 7070 |
Name => |
| 7071 |
New_Occurrence_Of (RTE (RE_Storage_Size), Loc), |
| 7072 |
Parameter_Associations => |
| 7073 |
New_List ( |
| 7074 |
Make_Selected_Component (Loc, |
| 7075 |
Prefix => |
| 7076 |
Unchecked_Convert_To ( |
| 7077 |
Corresponding_Record_Type (Ptyp), |
| 7078 |
New_Copy_Tree (Pref)), |
| 7079 |
Selector_Name => |
| 7080 |
Make_Identifier (Loc, Name_uTask_Id)))))); |
| 7081 |
|
| 7082 |
elsif Present (Storage_Size_Variable (Ptyp)) then |
| 7083 |
|
| 7084 |
-- Static Storage_Size pragma given for type: retrieve value |
| 7085 |
-- from its allocated storage variable. |
| 7086 |
|
| 7087 |
Rewrite (N, |
| 7088 |
Convert_To (Typ, |
| 7089 |
Make_Function_Call (Loc, |
| 7090 |
Name => New_Occurrence_Of ( |
| 7091 |
RTE (RE_Adjust_Storage_Size), Loc), |
| 7092 |
Parameter_Associations => |
| 7093 |
New_List ( |
| 7094 |
New_Occurrence_Of ( |
| 7095 |
Storage_Size_Variable (Ptyp), Loc))))); |
| 7096 |
else |
| 7097 |
-- Get system default |
| 7098 |
|
| 7099 |
Rewrite (N, |
| 7100 |
Convert_To (Typ, |
| 7101 |
Make_Function_Call (Loc, |
| 7102 |
Name => |
| 7103 |
New_Occurrence_Of ( |
| 7104 |
RTE (RE_Default_Stack_Size), Loc)))); |
| 7105 |
end if; |
| 7106 |
|
| 7107 |
Analyze_And_Resolve (N, Typ); |
| 7108 |
end if; |
| 7109 |
end Storage_Size; |
| 7110 |
|
| 7111 |
----------------- |
| 7112 |
-- Stream_Size -- |
| 7113 |
----------------- |
| 7114 |
|
| 7115 |
when Attribute_Stream_Size => |
| 7116 |
Rewrite (N, |
| 7117 |
Make_Integer_Literal (Loc, Intval => Get_Stream_Size (Ptyp))); |
| 7118 |
Analyze_And_Resolve (N, Typ); |
| 7119 |
|
| 7120 |
---------- |
| 7121 |
-- Succ -- |
| 7122 |
---------- |
| 7123 |
|
| 7124 |
-- 1. Deal with enumeration types with holes. |
| 7125 |
-- 2. For floating-point, generate call to attribute function. |
| 7126 |
-- 3. For other cases, deal with constraint checking. |
| 7127 |
|
| 7128 |
when Attribute_Succ => Succ : declare |
| 7129 |
Etyp : constant Entity_Id := Base_Type (Ptyp); |
| 7130 |
|
| 7131 |
begin |
| 7132 |
-- For enumeration types with non-standard representations, we |
| 7133 |
-- expand typ'Pred (x) into: |
| 7134 |
|
| 7135 |
-- Pos_To_Rep (Rep_To_Pos (x) + 1) |
| 7136 |
|
| 7137 |
-- if the representation is non-contiguous, and just x + 1 if it is |
| 7138 |
-- after having dealt with constraint checking. |
| 7139 |
|
| 7140 |
if Is_Enumeration_Type (Etyp) |
| 7141 |
and then Present (Enum_Pos_To_Rep (Etyp)) |
| 7142 |
then |
| 7143 |
if Has_Contiguous_Rep (Etyp) then |
| 7144 |
if not Range_Checks_Suppressed (Ptyp) then |
| 7145 |
Set_Do_Range_Check (First (Exprs), False); |
| 7146 |
Expand_Pred_Succ_Attribute (N); |
| 7147 |
end if; |
| 7148 |
|
| 7149 |
Rewrite (N, |
| 7150 |
Unchecked_Convert_To (Etyp, |
| 7151 |
Make_Op_Add (Loc, |
| 7152 |
Left_Opnd => |
| 7153 |
Unchecked_Convert_To ( |
| 7154 |
Integer_Type_For |
| 7155 |
(Esize (Etyp), Is_Unsigned_Type (Etyp)), |
| 7156 |
First (Exprs)), |
| 7157 |
Right_Opnd => |
| 7158 |
Make_Integer_Literal (Loc, 1)))); |
| 7159 |
|
| 7160 |
else |
| 7161 |
-- Add Boolean parameter depending on check suppression |
| 7162 |
|
| 7163 |
Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc)); |
| 7164 |
Rewrite (N, |
| 7165 |
Make_Indexed_Component (Loc, |
| 7166 |
Prefix => |
| 7167 |
New_Occurrence_Of |
| 7168 |
(Enum_Pos_To_Rep (Etyp), Loc), |
| 7169 |
Expressions => New_List ( |
| 7170 |
Make_Op_Add (Loc, |
| 7171 |
Left_Opnd => |
| 7172 |
Make_Function_Call (Loc, |
| 7173 |
Name => |
| 7174 |
New_Occurrence_Of |
| 7175 |
(TSS (Etyp, TSS_Rep_To_Pos), Loc), |
| 7176 |
Parameter_Associations => Exprs), |
| 7177 |
Right_Opnd => Make_Integer_Literal (Loc, 1))))); |
| 7178 |
end if; |
| 7179 |
|
| 7180 |
-- Suppress checks since they have all been done above |
| 7181 |
|
| 7182 |
Analyze_And_Resolve (N, Typ, Suppress => All_Checks); |
| 7183 |
|
| 7184 |
-- For floating-point, we transform 'Succ into a call to the Succ |
| 7185 |
-- floating-point attribute function in Fat_xxx (xxx is root type). |
| 7186 |
-- Note that this function takes care of the overflow case. |
| 7187 |
|
| 7188 |
elsif Is_Floating_Point_Type (Ptyp) then |
| 7189 |
Expand_Fpt_Attribute_R (N); |
| 7190 |
Analyze_And_Resolve (N, Typ); |
| 7191 |
|
| 7192 |
-- For modular types, nothing to do (no overflow, since wraps) |
| 7193 |
|
| 7194 |
elsif Is_Modular_Integer_Type (Ptyp) then |
| 7195 |
null; |
| 7196 |
|
| 7197 |
-- For other types, if argument is marked as needing a range check or |
| 7198 |
-- overflow checking is enabled, we must generate a check. |
| 7199 |
|
| 7200 |
elsif not Overflow_Checks_Suppressed (Ptyp) |
| 7201 |
or else Do_Range_Check (First (Exprs)) |
| 7202 |
then |
| 7203 |
Set_Do_Range_Check (First (Exprs), False); |
| 7204 |
Expand_Pred_Succ_Attribute (N); |
| 7205 |
end if; |
| 7206 |
end Succ; |
| 7207 |
|
| 7208 |
--------- |
| 7209 |
-- Tag -- |
| 7210 |
--------- |
| 7211 |
|
| 7212 |
-- Transforms X'Tag into a direct reference to the tag of X |
| 7213 |
|
| 7214 |
when Attribute_Tag => Tag : declare |
| 7215 |
Ttyp : Entity_Id; |
| 7216 |
Prefix_Is_Type : Boolean; |
| 7217 |
|
| 7218 |
begin |
| 7219 |
if Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then |
| 7220 |
Ttyp := Entity (Pref); |
| 7221 |
Prefix_Is_Type := True; |
| 7222 |
else |
| 7223 |
Ttyp := Ptyp; |
| 7224 |
Prefix_Is_Type := False; |
| 7225 |
end if; |
| 7226 |
|
| 7227 |
-- In the case of a class-wide equivalent type without a parent, |
| 7228 |
-- the _Tag component has been built in Make_CW_Equivalent_Type |
| 7229 |
-- manually and must be referenced directly. |
| 7230 |
|
| 7231 |
if Ekind (Ttyp) = E_Class_Wide_Subtype |
| 7232 |
and then Present (Equivalent_Type (Ttyp)) |
| 7233 |
and then No (Parent_Subtype (Equivalent_Type (Ttyp))) |
| 7234 |
then |
| 7235 |
Ttyp := Equivalent_Type (Ttyp); |
| 7236 |
|
| 7237 |
-- In all the other cases of class-wide type, including an equivalent |
| 7238 |
-- type with a parent, the _Tag component ultimately present is that |
| 7239 |
-- of the root type. |
| 7240 |
|
| 7241 |
elsif Is_Class_Wide_Type (Ttyp) then |
| 7242 |
Ttyp := Root_Type (Ttyp); |
| 7243 |
end if; |
| 7244 |
|
| 7245 |
Ttyp := Underlying_Type (Ttyp); |
| 7246 |
|
| 7247 |
-- Ada 2005: The type may be a synchronized tagged type, in which |
| 7248 |
-- case the tag information is stored in the corresponding record. |
| 7249 |
|
| 7250 |
if Is_Concurrent_Type (Ttyp) then |
| 7251 |
Ttyp := Corresponding_Record_Type (Ttyp); |
| 7252 |
end if; |
| 7253 |
|
| 7254 |
if Prefix_Is_Type then |
| 7255 |
|
| 7256 |
-- For VMs we leave the type attribute unexpanded because |
| 7257 |
-- there's not a dispatching table to reference. |
| 7258 |
|
| 7259 |
if Tagged_Type_Expansion then |
| 7260 |
Rewrite (N, |
| 7261 |
Unchecked_Convert_To (RTE (RE_Tag), |
| 7262 |
New_Occurrence_Of |
| 7263 |
(Node (First_Elmt (Access_Disp_Table (Ttyp))), Loc))); |
| 7264 |
Analyze_And_Resolve (N, RTE (RE_Tag)); |
| 7265 |
end if; |
| 7266 |
|
| 7267 |
-- Ada 2005 (AI-251): The use of 'Tag in the sources always |
| 7268 |
-- references the primary tag of the actual object. If 'Tag is |
| 7269 |
-- applied to class-wide interface objects we generate code that |
| 7270 |
-- displaces "this" to reference the base of the object. |
| 7271 |
|
| 7272 |
elsif Comes_From_Source (N) |
| 7273 |
and then Is_Class_Wide_Type (Etype (Prefix (N))) |
| 7274 |
and then Is_Interface (Underlying_Type (Etype (Prefix (N)))) |
| 7275 |
then |
| 7276 |
-- Generate: |
| 7277 |
-- (To_Tag_Ptr (Prefix'Address)).all |
| 7278 |
|
| 7279 |
-- Note that Prefix'Address is recursively expanded into a call |
| 7280 |
-- to Base_Address (Obj.Tag) |
| 7281 |
|
| 7282 |
-- Not needed for VM targets, since all handled by the VM |
| 7283 |
|
| 7284 |
if Tagged_Type_Expansion then |
| 7285 |
Rewrite (N, |
| 7286 |
Make_Explicit_Dereference (Loc, |
| 7287 |
Unchecked_Convert_To (RTE (RE_Tag_Ptr), |
| 7288 |
Make_Attribute_Reference (Loc, |
| 7289 |
Prefix => Relocate_Node (Pref), |
| 7290 |
Attribute_Name => Name_Address)))); |
| 7291 |
Analyze_And_Resolve (N, RTE (RE_Tag)); |
| 7292 |
end if; |
| 7293 |
|
| 7294 |
else |
| 7295 |
Rewrite (N, |
| 7296 |
Make_Selected_Component (Loc, |
| 7297 |
Prefix => Relocate_Node (Pref), |
| 7298 |
Selector_Name => |
| 7299 |
New_Occurrence_Of (First_Tag_Component (Ttyp), Loc))); |
| 7300 |
Analyze_And_Resolve (N, RTE (RE_Tag)); |
| 7301 |
end if; |
| 7302 |
end Tag; |
| 7303 |
|
| 7304 |
---------------- |
| 7305 |
-- Terminated -- |
| 7306 |
---------------- |
| 7307 |
|
| 7308 |
-- Transforms 'Terminated attribute into a call to Terminated function |
| 7309 |
|
| 7310 |
when Attribute_Terminated => Terminated : begin |
| 7311 |
|
| 7312 |
-- The prefix of Terminated is of a task interface class-wide type. |
| 7313 |
-- Generate: |
| 7314 |
-- terminated (Task_Id (_disp_get_task_id (Pref))); |
| 7315 |
|
| 7316 |
if Ada_Version >= Ada_2005 |
| 7317 |
and then Ekind (Ptyp) = E_Class_Wide_Type |
| 7318 |
and then Is_Interface (Ptyp) |
| 7319 |
and then Is_Task_Interface (Ptyp) |
| 7320 |
then |
| 7321 |
Rewrite (N, |
| 7322 |
Make_Function_Call (Loc, |
| 7323 |
Name => |
| 7324 |
New_Occurrence_Of (RTE (RE_Terminated), Loc), |
| 7325 |
Parameter_Associations => New_List ( |
| 7326 |
Unchecked_Convert_To |
| 7327 |
(RTE (RO_ST_Task_Id), |
| 7328 |
Build_Disp_Get_Task_Id_Call (Pref))))); |
| 7329 |
|
| 7330 |
elsif Restricted_Profile then |
| 7331 |
Rewrite (N, |
| 7332 |
Build_Call_With_Task (Pref, RTE (RE_Restricted_Terminated))); |
| 7333 |
|
| 7334 |
else |
| 7335 |
Rewrite (N, |
| 7336 |
Build_Call_With_Task (Pref, RTE (RE_Terminated))); |
| 7337 |
end if; |
| 7338 |
|
| 7339 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 7340 |
end Terminated; |
| 7341 |
|
| 7342 |
---------------- |
| 7343 |
-- To_Address -- |
| 7344 |
---------------- |
| 7345 |
|
| 7346 |
-- Transforms System'To_Address (X) and System.Address'Ref (X) into |
| 7347 |
-- unchecked conversion from (integral) type of X to type address. If |
| 7348 |
-- the To_Address is a static expression, the transformed expression |
| 7349 |
-- also needs to be static, because we do some legality checks (e.g. |
| 7350 |
-- for Thread_Local_Storage) after this transformation. |
| 7351 |
|
| 7352 |
when Attribute_Ref |
| 7353 |
| Attribute_To_Address |
| 7354 |
=> |
| 7355 |
To_Address : declare |
| 7356 |
Is_Static : constant Boolean := Is_Static_Expression (N); |
| 7357 |
|
| 7358 |
begin |
| 7359 |
Rewrite (N, |
| 7360 |
Unchecked_Convert_To (RTE (RE_Address), |
| 7361 |
Relocate_Node (First (Exprs)))); |
| 7362 |
Set_Is_Static_Expression (N, Is_Static); |
| 7363 |
|
| 7364 |
Analyze_And_Resolve (N, RTE (RE_Address)); |
| 7365 |
end To_Address; |
| 7366 |
|
| 7367 |
------------ |
| 7368 |
-- To_Any -- |
| 7369 |
------------ |
| 7370 |
|
| 7371 |
when Attribute_To_Any => To_Any : declare |
| 7372 |
Decls : constant List_Id := New_List; |
| 7373 |
begin |
| 7374 |
Rewrite (N, |
| 7375 |
Build_To_Any_Call |
| 7376 |
(Loc, |
| 7377 |
Convert_To (Ptyp, |
| 7378 |
Relocate_Node (First (Exprs))), Decls)); |
| 7379 |
Insert_Actions (N, Decls); |
| 7380 |
Analyze_And_Resolve (N, RTE (RE_Any)); |
| 7381 |
end To_Any; |
| 7382 |
|
| 7383 |
---------------- |
| 7384 |
-- Truncation -- |
| 7385 |
---------------- |
| 7386 |
|
| 7387 |
-- Transforms 'Truncation into a call to the floating-point attribute |
| 7388 |
-- function Truncation in Fat_xxx (where xxx is the root type). |
| 7389 |
-- Expansion is avoided for cases the back end can handle directly. |
| 7390 |
|
| 7391 |
when Attribute_Truncation => |
| 7392 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 7393 |
Expand_Fpt_Attribute_R (N); |
| 7394 |
end if; |
| 7395 |
|
| 7396 |
-------------- |
| 7397 |
-- TypeCode -- |
| 7398 |
-------------- |
| 7399 |
|
| 7400 |
when Attribute_TypeCode => TypeCode : declare |
| 7401 |
Decls : constant List_Id := New_List; |
| 7402 |
begin |
| 7403 |
Rewrite (N, Build_TypeCode_Call (Loc, Ptyp, Decls)); |
| 7404 |
Insert_Actions (N, Decls); |
| 7405 |
Analyze_And_Resolve (N, RTE (RE_TypeCode)); |
| 7406 |
end TypeCode; |
| 7407 |
|
| 7408 |
----------------------- |
| 7409 |
-- Unbiased_Rounding -- |
| 7410 |
----------------------- |
| 7411 |
|
| 7412 |
-- Transforms 'Unbiased_Rounding into a call to the floating-point |
| 7413 |
-- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the |
| 7414 |
-- root type). Expansion is avoided for cases the back end can handle |
| 7415 |
-- directly. |
| 7416 |
|
| 7417 |
when Attribute_Unbiased_Rounding => |
| 7418 |
if not Is_Inline_Floating_Point_Attribute (N) then |
| 7419 |
Expand_Fpt_Attribute_R (N); |
| 7420 |
end if; |
| 7421 |
|
| 7422 |
------------ |
| 7423 |
-- Update -- |
| 7424 |
------------ |
| 7425 |
|
| 7426 |
when Attribute_Update => |
| 7427 |
Expand_Update_Attribute (N); |
| 7428 |
|
| 7429 |
--------------- |
| 7430 |
-- VADS_Size -- |
| 7431 |
--------------- |
| 7432 |
|
| 7433 |
-- The processing for VADS_Size is shared with Size |
| 7434 |
|
| 7435 |
--------- |
| 7436 |
-- Val -- |
| 7437 |
--------- |
| 7438 |
|
| 7439 |
-- For enumeration types with a non-standard representation we use the |
| 7440 |
-- _Pos_To_Rep array that was created when the type was frozen, unless |
| 7441 |
-- the representation is contiguous in which case we use an addition. |
| 7442 |
|
| 7443 |
-- For enumeration types with a standard representation, Val can be |
| 7444 |
-- rewritten as a simple conversion with Conversion_OK set. |
| 7445 |
|
| 7446 |
-- For integer types, Val is equivalent to a simple integer conversion |
| 7447 |
-- and we rewrite it as such. |
| 7448 |
|
| 7449 |
when Attribute_Val => Val : declare |
| 7450 |
Etyp : constant Entity_Id := Base_Type (Ptyp); |
| 7451 |
Expr : constant Node_Id := First (Exprs); |
| 7452 |
Rtyp : Entity_Id; |
| 7453 |
|
| 7454 |
begin |
| 7455 |
-- Case of enumeration type |
| 7456 |
|
| 7457 |
if Is_Enumeration_Type (Etyp) then |
| 7458 |
|
| 7459 |
-- Non-contiguous non-standard enumeration type |
| 7460 |
|
| 7461 |
if Present (Enum_Pos_To_Rep (Etyp)) |
| 7462 |
and then not Has_Contiguous_Rep (Etyp) |
| 7463 |
then |
| 7464 |
Rewrite (N, |
| 7465 |
Make_Indexed_Component (Loc, |
| 7466 |
Prefix => |
| 7467 |
New_Occurrence_Of (Enum_Pos_To_Rep (Etyp), Loc), |
| 7468 |
Expressions => New_List ( |
| 7469 |
Convert_To (Standard_Integer, Expr)))); |
| 7470 |
|
| 7471 |
Analyze_And_Resolve (N, Typ); |
| 7472 |
|
| 7473 |
-- Standard or contiguous non-standard enumeration type |
| 7474 |
|
| 7475 |
else |
| 7476 |
-- If the argument is marked as requiring a range check then |
| 7477 |
-- generate it here, after looking through a conversion to |
| 7478 |
-- universal integer, if any. |
| 7479 |
|
| 7480 |
if Do_Range_Check (Expr) then |
| 7481 |
if Present (Enum_Pos_To_Rep (Etyp)) then |
| 7482 |
Rtyp := Enum_Pos_To_Rep (Etyp); |
| 7483 |
else |
| 7484 |
Rtyp := Etyp; |
| 7485 |
end if; |
| 7486 |
|
| 7487 |
if Nkind (Expr) = N_Type_Conversion |
| 7488 |
and then Entity (Subtype_Mark (Expr)) = Universal_Integer |
| 7489 |
then |
| 7490 |
Generate_Range_Check |
| 7491 |
(Expression (Expr), Rtyp, CE_Range_Check_Failed); |
| 7492 |
|
| 7493 |
else |
| 7494 |
Generate_Range_Check (Expr, Rtyp, CE_Range_Check_Failed); |
| 7495 |
end if; |
| 7496 |
|
| 7497 |
Set_Do_Range_Check (Expr, False); |
| 7498 |
end if; |
| 7499 |
|
| 7500 |
-- Contiguous non-standard enumeration type |
| 7501 |
|
| 7502 |
if Present (Enum_Pos_To_Rep (Etyp)) then |
| 7503 |
Rewrite (N, |
| 7504 |
Unchecked_Convert_To (Etyp, |
| 7505 |
Make_Op_Add (Loc, |
| 7506 |
Left_Opnd => |
| 7507 |
Make_Integer_Literal (Loc, |
| 7508 |
Enumeration_Rep (First_Literal (Etyp))), |
| 7509 |
Right_Opnd => |
| 7510 |
Unchecked_Convert_To ( |
| 7511 |
Integer_Type_For |
| 7512 |
(Esize (Etyp), Is_Unsigned_Type (Etyp)), |
| 7513 |
Expr)))); |
| 7514 |
|
| 7515 |
-- Standard enumeration type |
| 7516 |
|
| 7517 |
else |
| 7518 |
Rewrite (N, OK_Convert_To (Typ, Expr)); |
| 7519 |
end if; |
| 7520 |
|
| 7521 |
-- Suppress checks since the range check was done above |
| 7522 |
-- and it guarantees that the addition cannot overflow. |
| 7523 |
|
| 7524 |
Analyze_And_Resolve (N, Typ, Suppress => All_Checks); |
| 7525 |
end if; |
| 7526 |
|
| 7527 |
-- Deal with integer types |
| 7528 |
|
| 7529 |
elsif Is_Integer_Type (Etyp) then |
| 7530 |
Rewrite (N, Convert_To (Typ, Expr)); |
| 7531 |
Analyze_And_Resolve (N, Typ); |
| 7532 |
end if; |
| 7533 |
end Val; |
| 7534 |
|
| 7535 |
----------- |
| 7536 |
-- Valid -- |
| 7537 |
----------- |
| 7538 |
|
| 7539 |
-- The code for valid is dependent on the particular types involved. |
| 7540 |
-- See separate sections below for the generated code in each case. |
| 7541 |
|
| 7542 |
when Attribute_Valid => Valid : declare |
| 7543 |
PBtyp : Entity_Id := Implementation_Base_Type (Validated_View (Ptyp)); |
| 7544 |
pragma Assert (Is_Scalar_Type (PBtyp) |
| 7545 |
or else Serious_Errors_Detected > 0); |
| 7546 |
|
| 7547 |
-- The scalar base type, looking through private types |
| 7548 |
|
| 7549 |
Save_Validity_Checks_On : constant Boolean := Validity_Checks_On; |
| 7550 |
-- Save the validity checking mode. We always turn off validity |
| 7551 |
-- checking during process of 'Valid since this is one place |
| 7552 |
-- where we do not want the implicit validity checks to interfere |
| 7553 |
-- with the explicit validity check that the programmer is doing. |
| 7554 |
|
| 7555 |
function Make_Range_Test return Node_Id; |
| 7556 |
-- Build the code for a range test of the form |
| 7557 |
-- PBtyp!(Pref) in PBtyp!(Ptyp'First) .. PBtyp!(Ptyp'Last) |
| 7558 |
|
| 7559 |
--------------------- |
| 7560 |
-- Make_Range_Test -- |
| 7561 |
--------------------- |
| 7562 |
|
| 7563 |
function Make_Range_Test return Node_Id is |
| 7564 |
Temp : Node_Id; |
| 7565 |
|
| 7566 |
begin |
| 7567 |
-- The prefix of attribute 'Valid should always denote an object |
| 7568 |
-- reference. The reference is either coming directly from source |
| 7569 |
-- or is produced by validity check expansion. The object may be |
| 7570 |
-- wrapped in a conversion in which case the call to Unqual_Conv |
| 7571 |
-- will yield it. |
| 7572 |
|
| 7573 |
-- If the prefix denotes a variable which captures the value of |
| 7574 |
-- an object for validation purposes, use the variable in the |
| 7575 |
-- range test. This ensures that no extra copies or extra reads |
| 7576 |
-- are produced as part of the test. Generate: |
| 7577 |
|
| 7578 |
-- Temp : ... := Object; |
| 7579 |
-- if not Temp in ... then |
| 7580 |
|
| 7581 |
if Is_Validation_Variable_Reference (Pref) then |
| 7582 |
Temp := New_Occurrence_Of (Entity (Unqual_Conv (Pref)), Loc); |
| 7583 |
|
| 7584 |
-- Otherwise the prefix is either a source object or a constant |
| 7585 |
-- produced by validity check expansion. Generate: |
| 7586 |
|
| 7587 |
-- Temp : constant ... := Pref; |
| 7588 |
-- if not Temp in ... then |
| 7589 |
|
| 7590 |
else |
| 7591 |
Temp := Duplicate_Subexpr (Pref); |
| 7592 |
end if; |
| 7593 |
|
| 7594 |
declare |
| 7595 |
Val_Typ : constant Entity_Id := Validated_View (Ptyp); |
| 7596 |
begin |
| 7597 |
return |
| 7598 |
Make_In (Loc, |
| 7599 |
Left_Opnd => Unchecked_Convert_To (PBtyp, Temp), |
| 7600 |
Right_Opnd => |
| 7601 |
Make_Range (Loc, |
| 7602 |
Low_Bound => |
| 7603 |
Unchecked_Convert_To (PBtyp, |
| 7604 |
Make_Attribute_Reference (Loc, |
| 7605 |
Prefix => |
| 7606 |
New_Occurrence_Of (Val_Typ, Loc), |
| 7607 |
Attribute_Name => Name_First)), |
| 7608 |
High_Bound => |
| 7609 |
Unchecked_Convert_To (PBtyp, |
| 7610 |
Make_Attribute_Reference (Loc, |
| 7611 |
Prefix => |
| 7612 |
New_Occurrence_Of (Val_Typ, Loc), |
| 7613 |
Attribute_Name => Name_Last)))); |
| 7614 |
end; |
| 7615 |
end Make_Range_Test; |
| 7616 |
|
| 7617 |
-- Local variables |
| 7618 |
|
| 7619 |
Tst : Node_Id; |
| 7620 |
|
| 7621 |
-- Start of processing for Attribute_Valid |
| 7622 |
|
| 7623 |
begin |
| 7624 |
-- Do not expand sourced code 'Valid reference in CodePeer mode, |
| 7625 |
-- will be handled by the back-end directly. |
| 7626 |
|
| 7627 |
if CodePeer_Mode and then Comes_From_Source (N) then |
| 7628 |
return; |
| 7629 |
end if; |
| 7630 |
|
| 7631 |
-- Turn off validity checks. We do not want any implicit validity |
| 7632 |
-- checks to intefere with the explicit check from the attribute |
| 7633 |
|
| 7634 |
Validity_Checks_On := False; |
| 7635 |
|
| 7636 |
-- Floating-point case. This case is handled by the Valid attribute |
| 7637 |
-- code in the floating-point attribute run-time library. |
| 7638 |
|
| 7639 |
if Is_Floating_Point_Type (PBtyp) then |
| 7640 |
Float_Valid : declare |
| 7641 |
Pkg : RE_Id; |
| 7642 |
Ftp : Entity_Id; |
| 7643 |
|
| 7644 |
function Get_Fat_Entity (Nam : Name_Id) return Entity_Id; |
| 7645 |
-- Return entity for Pkg.Nam |
| 7646 |
|
| 7647 |
-------------------- |
| 7648 |
-- Get_Fat_Entity -- |
| 7649 |
-------------------- |
| 7650 |
|
| 7651 |
function Get_Fat_Entity (Nam : Name_Id) return Entity_Id is |
| 7652 |
Exp_Name : constant Node_Id := |
| 7653 |
Make_Selected_Component (Loc, |
| 7654 |
Prefix => New_Occurrence_Of (RTE (Pkg), Loc), |
| 7655 |
Selector_Name => Make_Identifier (Loc, Nam)); |
| 7656 |
begin |
| 7657 |
Find_Selected_Component (Exp_Name); |
| 7658 |
return Entity (Exp_Name); |
| 7659 |
end Get_Fat_Entity; |
| 7660 |
|
| 7661 |
-- Start of processing for Float_Valid |
| 7662 |
|
| 7663 |
begin |
| 7664 |
Find_Fat_Info (PBtyp, Ftp, Pkg); |
| 7665 |
|
| 7666 |
-- If the prefix is a reverse SSO component, or is possibly |
| 7667 |
-- unaligned, first create a temporary copy that is in |
| 7668 |
-- native SSO, and properly aligned. Make it Volatile to |
| 7669 |
-- prevent folding in the back-end. Note that we use an |
| 7670 |
-- intermediate constrained string type to initialize the |
| 7671 |
-- temporary, as the value at hand might be invalid, and in |
| 7672 |
-- that case it cannot be copied using a floating point |
| 7673 |
-- register. |
| 7674 |
|
| 7675 |
if In_Reverse_Storage_Order_Object (Pref) |
| 7676 |
or else Is_Possibly_Unaligned_Object (Pref) |
| 7677 |
then |
| 7678 |
declare |
| 7679 |
Temp : constant Entity_Id := |
| 7680 |
Make_Temporary (Loc, 'F'); |
| 7681 |
|
| 7682 |
Fat_S : constant Entity_Id := |
| 7683 |
Get_Fat_Entity (Name_S); |
| 7684 |
-- Constrained string subtype of appropriate size |
| 7685 |
|
| 7686 |
Fat_P : constant Entity_Id := |
| 7687 |
Get_Fat_Entity (Name_P); |
| 7688 |
-- Access to Fat_S |
| 7689 |
|
| 7690 |
Decl : constant Node_Id := |
| 7691 |
Make_Object_Declaration (Loc, |
| 7692 |
Defining_Identifier => Temp, |
| 7693 |
Aliased_Present => True, |
| 7694 |
Object_Definition => |
| 7695 |
New_Occurrence_Of (Ptyp, Loc)); |
| 7696 |
|
| 7697 |
begin |
| 7698 |
Set_Aspect_Specifications (Decl, New_List ( |
| 7699 |
Make_Aspect_Specification (Loc, |
| 7700 |
Identifier => |
| 7701 |
Make_Identifier (Loc, Name_Volatile)))); |
| 7702 |
|
| 7703 |
Insert_Actions (N, |
| 7704 |
New_List ( |
| 7705 |
Decl, |
| 7706 |
|
| 7707 |
Make_Assignment_Statement (Loc, |
| 7708 |
Name => |
| 7709 |
Make_Explicit_Dereference (Loc, |
| 7710 |
Prefix => |
| 7711 |
Unchecked_Convert_To (Fat_P, |
| 7712 |
Make_Attribute_Reference (Loc, |
| 7713 |
Prefix => |
| 7714 |
New_Occurrence_Of (Temp, Loc), |
| 7715 |
Attribute_Name => |
| 7716 |
Name_Unrestricted_Access))), |
| 7717 |
Expression => |
| 7718 |
Unchecked_Convert_To (Fat_S, |
| 7719 |
Relocate_Node (Pref)))), |
| 7720 |
|
| 7721 |
Suppress => All_Checks); |
| 7722 |
|
| 7723 |
Rewrite (Pref, New_Occurrence_Of (Temp, Loc)); |
| 7724 |
end; |
| 7725 |
end if; |
| 7726 |
|
| 7727 |
-- We now have an object of the proper endianness and |
| 7728 |
-- alignment, and can construct a Valid attribute. |
| 7729 |
|
| 7730 |
-- We make sure the prefix of this valid attribute is |
| 7731 |
-- marked as not coming from source, to avoid losing |
| 7732 |
-- warnings from 'Valid looking like a possible update. |
| 7733 |
|
| 7734 |
Set_Comes_From_Source (Pref, False); |
| 7735 |
|
| 7736 |
Expand_Fpt_Attribute |
| 7737 |
(N, Pkg, Name_Valid, |
| 7738 |
New_List ( |
| 7739 |
Make_Attribute_Reference (Loc, |
| 7740 |
Prefix => Unchecked_Convert_To (Ftp, Pref), |
| 7741 |
Attribute_Name => Name_Unrestricted_Access))); |
| 7742 |
|
| 7743 |
-- One more task, we still need a range check. Required |
| 7744 |
-- only if we have a constraint, since the Valid routine |
| 7745 |
-- catches infinities properly (infinities are never valid). |
| 7746 |
|
| 7747 |
-- The way we do the range check is simply to create the |
| 7748 |
-- expression: Valid (N) and then Base_Type(Pref) in Typ. |
| 7749 |
|
| 7750 |
if not Subtypes_Statically_Match (Ptyp, PBtyp) then |
| 7751 |
Rewrite (N, |
| 7752 |
Make_And_Then (Loc, |
| 7753 |
Left_Opnd => Relocate_Node (N), |
| 7754 |
Right_Opnd => |
| 7755 |
Make_In (Loc, |
| 7756 |
Left_Opnd => Convert_To (PBtyp, Pref), |
| 7757 |
Right_Opnd => New_Occurrence_Of (Ptyp, Loc)))); |
| 7758 |
end if; |
| 7759 |
end Float_Valid; |
| 7760 |
|
| 7761 |
-- Enumeration type with holes |
| 7762 |
|
| 7763 |
-- For enumeration types with holes, the Pos value constructed by |
| 7764 |
-- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a |
| 7765 |
-- second argument of False returns minus one for an invalid value, |
| 7766 |
-- and the non-negative pos value for a valid value, so the |
| 7767 |
-- expansion of X'Valid is simply: |
| 7768 |
|
| 7769 |
-- type(X)'Pos (X) >= 0 |
| 7770 |
|
| 7771 |
-- We can't quite generate it that way because of the requirement |
| 7772 |
-- for the non-standard second argument of False in the resulting |
| 7773 |
-- rep_to_pos call, so we have to explicitly create: |
| 7774 |
|
| 7775 |
-- _rep_to_pos (X, False) >= 0 |
| 7776 |
|
| 7777 |
-- If we have an enumeration subtype, we also check that the |
| 7778 |
-- value is in range: |
| 7779 |
|
| 7780 |
-- _rep_to_pos (X, False) >= 0 |
| 7781 |
-- and then |
| 7782 |
-- (X >= type(X)'First and then type(X)'Last <= X) |
| 7783 |
|
| 7784 |
elsif Is_Enumeration_Type (Ptyp) |
| 7785 |
and then Present (Enum_Pos_To_Rep (PBtyp)) |
| 7786 |
then |
| 7787 |
Tst := |
| 7788 |
Make_Op_Ge (Loc, |
| 7789 |
Left_Opnd => |
| 7790 |
Make_Function_Call (Loc, |
| 7791 |
Name => |
| 7792 |
New_Occurrence_Of (TSS (PBtyp, TSS_Rep_To_Pos), Loc), |
| 7793 |
Parameter_Associations => New_List ( |
| 7794 |
Pref, |
| 7795 |
New_Occurrence_Of (Standard_False, Loc))), |
| 7796 |
Right_Opnd => Make_Integer_Literal (Loc, 0)); |
| 7797 |
|
| 7798 |
-- Skip the range test for boolean types, as it buys us |
| 7799 |
-- nothing. The function called above already fails for |
| 7800 |
-- values different from both True and False. |
| 7801 |
|
| 7802 |
if Ptyp /= PBtyp and then not Is_Boolean_Type (PBtyp) |
| 7803 |
and then |
| 7804 |
(Type_Low_Bound (Ptyp) /= Type_Low_Bound (PBtyp) |
| 7805 |
or else |
| 7806 |
Type_High_Bound (Ptyp) /= Type_High_Bound (PBtyp)) |
| 7807 |
then |
| 7808 |
-- The call to Make_Range_Test will create declarations |
| 7809 |
-- that need a proper insertion point, but Pref is now |
| 7810 |
-- attached to a node with no ancestor. Attach to tree |
| 7811 |
-- even if it is to be rewritten below. |
| 7812 |
|
| 7813 |
Set_Parent (Tst, Parent (N)); |
| 7814 |
|
| 7815 |
Tst := |
| 7816 |
Make_And_Then (Loc, |
| 7817 |
Left_Opnd => Make_Range_Test, |
| 7818 |
Right_Opnd => Tst); |
| 7819 |
end if; |
| 7820 |
|
| 7821 |
Rewrite (N, Tst); |
| 7822 |
|
| 7823 |
-- Fortran convention booleans |
| 7824 |
|
| 7825 |
-- For the very special case of Fortran convention booleans, the |
| 7826 |
-- value is always valid, since it is an integer with the semantics |
| 7827 |
-- that non-zero is true, and any value is permissible. |
| 7828 |
|
| 7829 |
elsif Is_Boolean_Type (Ptyp) |
| 7830 |
and then Convention (Ptyp) = Convention_Fortran |
| 7831 |
then |
| 7832 |
Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); |
| 7833 |
|
| 7834 |
-- For biased representations, we will be doing an unchecked |
| 7835 |
-- conversion without unbiasing the result. That means that the range |
| 7836 |
-- test has to take this into account, and the proper form of the |
| 7837 |
-- test is: |
| 7838 |
|
| 7839 |
-- PBtyp!(Pref) < PBtyp!(Ptyp'Range_Length) |
| 7840 |
|
| 7841 |
elsif Has_Biased_Representation (Ptyp) then |
| 7842 |
PBtyp := RTE (RE_Unsigned_32); |
| 7843 |
Rewrite (N, |
| 7844 |
Make_Op_Lt (Loc, |
| 7845 |
Left_Opnd => |
| 7846 |
Unchecked_Convert_To (PBtyp, Duplicate_Subexpr (Pref)), |
| 7847 |
Right_Opnd => |
| 7848 |
Unchecked_Convert_To (PBtyp, |
| 7849 |
Make_Attribute_Reference (Loc, |
| 7850 |
Prefix => New_Occurrence_Of (Ptyp, Loc), |
| 7851 |
Attribute_Name => Name_Range_Length)))); |
| 7852 |
|
| 7853 |
-- For all other scalar types, what we want logically is a |
| 7854 |
-- range test: |
| 7855 |
|
| 7856 |
-- X in type(X)'First .. type(X)'Last |
| 7857 |
|
| 7858 |
-- But that's precisely what won't work because of possible |
| 7859 |
-- unwanted optimization (and indeed the basic motivation for |
| 7860 |
-- the Valid attribute is exactly that this test does not work). |
| 7861 |
-- What will work is: |
| 7862 |
|
| 7863 |
-- PBtyp!(X) >= PBtyp!(type(X)'First) |
| 7864 |
-- and then |
| 7865 |
-- PBtyp!(X) <= PBtyp!(type(X)'Last) |
| 7866 |
|
| 7867 |
-- where PBtyp is an integer type large enough to cover the full |
| 7868 |
-- range of possible stored values (i.e. it is chosen on the basis |
| 7869 |
-- of the size of the type, not the range of the values). We write |
| 7870 |
-- this as two tests, rather than a range check, so that static |
| 7871 |
-- evaluation will easily remove either or both of the checks if |
| 7872 |
-- they can be statically determined to be true (this happens |
| 7873 |
-- when the type of X is static and the range extends to the full |
| 7874 |
-- range of stored values). |
| 7875 |
|
| 7876 |
-- Unsigned types. Note: it is safe to consider only whether the |
| 7877 |
-- subtype is unsigned, since we will in that case be doing all |
| 7878 |
-- unsigned comparisons based on the subtype range. Since we use the |
| 7879 |
-- actual subtype object size, this is appropriate. |
| 7880 |
|
| 7881 |
-- For example, if we have |
| 7882 |
|
| 7883 |
-- subtype x is integer range 1 .. 200; |
| 7884 |
-- for x'Object_Size use 8; |
| 7885 |
|
| 7886 |
-- Now the base type is signed, but objects of this type are bits |
| 7887 |
-- unsigned, and doing an unsigned test of the range 1 to 200 is |
| 7888 |
-- correct, even though a value greater than 127 looks signed to a |
| 7889 |
-- signed comparison. |
| 7890 |
|
| 7891 |
else |
| 7892 |
declare |
| 7893 |
Uns : constant Boolean := |
| 7894 |
Is_Unsigned_Type (Validated_View (Ptyp)); |
| 7895 |
|
| 7896 |
Size : Uint; |
| 7897 |
P : Node_Id := Pref; |
| 7898 |
|
| 7899 |
begin |
| 7900 |
-- If the prefix is an object, use the Esize from this object |
| 7901 |
-- to handle in a more user friendly way the case of objects |
| 7902 |
-- or components with a large Size aspect: if a Size aspect is |
| 7903 |
-- specified, we want to read a scalar value as large as the |
| 7904 |
-- Size, unless the Size is larger than |
| 7905 |
-- System_Max_Integer_Size. |
| 7906 |
|
| 7907 |
if Nkind (P) = N_Selected_Component then |
| 7908 |
P := Selector_Name (P); |
| 7909 |
end if; |
| 7910 |
|
| 7911 |
if Nkind (P) in N_Has_Entity |
| 7912 |
and then Present (Entity (P)) |
| 7913 |
and then Is_Object (Entity (P)) |
| 7914 |
and then Known_Esize (Entity (P)) |
| 7915 |
then |
| 7916 |
if Esize (Entity (P)) <= System_Max_Integer_Size then |
| 7917 |
Size := Esize (Entity (P)); |
| 7918 |
else |
| 7919 |
Size := UI_From_Int (System_Max_Integer_Size); |
| 7920 |
end if; |
| 7921 |
else |
| 7922 |
Size := Esize (Ptyp); |
| 7923 |
end if; |
| 7924 |
|
| 7925 |
PBtyp := Small_Integer_Type_For (Size, Uns); |
| 7926 |
Rewrite (N, Make_Range_Test); |
| 7927 |
end; |
| 7928 |
end if; |
| 7929 |
|
| 7930 |
-- If a predicate is present, then we do the predicate test, even if |
| 7931 |
-- within the predicate function (infinite recursion is warned about |
| 7932 |
-- in Sem_Attr in that case). |
| 7933 |
|
| 7934 |
declare |
| 7935 |
Pred_Func : constant Entity_Id := Predicate_Function (Ptyp); |
| 7936 |
|
| 7937 |
begin |
| 7938 |
if Present (Pred_Func) then |
| 7939 |
Rewrite (N, |
| 7940 |
Make_And_Then (Loc, |
| 7941 |
Left_Opnd => Relocate_Node (N), |
| 7942 |
Right_Opnd => Make_Predicate_Call (Ptyp, Pref))); |
| 7943 |
end if; |
| 7944 |
end; |
| 7945 |
|
| 7946 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 7947 |
Validity_Checks_On := Save_Validity_Checks_On; |
| 7948 |
end Valid; |
| 7949 |
|
| 7950 |
----------------- |
| 7951 |
-- Valid_Value -- |
| 7952 |
----------------- |
| 7953 |
|
| 7954 |
when Attribute_Valid_Value => |
| 7955 |
Exp_Imgv.Expand_Valid_Value_Attribute (N); |
| 7956 |
|
| 7957 |
------------------- |
| 7958 |
-- Valid_Scalars -- |
| 7959 |
------------------- |
| 7960 |
|
| 7961 |
when Attribute_Valid_Scalars => Valid_Scalars : declare |
| 7962 |
Val_Typ : constant Entity_Id := Validated_View (Ptyp); |
| 7963 |
Expr : Node_Id; |
| 7964 |
|
| 7965 |
begin |
| 7966 |
-- Assume that the prefix does not need validation |
| 7967 |
|
| 7968 |
Expr := Empty; |
| 7969 |
|
| 7970 |
-- Attribute 'Valid_Scalars is not supported on private tagged types; |
| 7971 |
-- see a detailed explanation where this attribute is analyzed. |
| 7972 |
|
| 7973 |
if Is_Private_Type (Ptyp) and then Is_Tagged_Type (Ptyp) then |
| 7974 |
null; |
| 7975 |
|
| 7976 |
-- Attribute 'Valid_Scalars evaluates to True when the type lacks |
| 7977 |
-- scalars. |
| 7978 |
|
| 7979 |
elsif not Scalar_Part_Present (Val_Typ) then |
| 7980 |
null; |
| 7981 |
|
| 7982 |
-- Attribute 'Valid_Scalars is the same as attribute 'Valid when the |
| 7983 |
-- validated type is a scalar type. Generate: |
| 7984 |
|
| 7985 |
-- Val_Typ (Pref)'Valid |
| 7986 |
|
| 7987 |
elsif Is_Scalar_Type (Val_Typ) then |
| 7988 |
Expr := |
| 7989 |
Make_Attribute_Reference (Loc, |
| 7990 |
Prefix => |
| 7991 |
Unchecked_Convert_To (Val_Typ, New_Copy_Tree (Pref)), |
| 7992 |
Attribute_Name => Name_Valid); |
| 7993 |
|
| 7994 |
-- Required by LLVM although the sizes are the same??? |
| 7995 |
|
| 7996 |
if Nkind (Prefix (Expr)) = N_Unchecked_Type_Conversion then |
| 7997 |
Set_No_Truncation (Prefix (Expr)); |
| 7998 |
end if; |
| 7999 |
|
| 8000 |
-- Validate the scalar components of an array by iterating over all |
| 8001 |
-- dimensions of the array while checking individual components. |
| 8002 |
|
| 8003 |
elsif Is_Array_Type (Val_Typ) then |
| 8004 |
Expr := |
| 8005 |
Make_Function_Call (Loc, |
| 8006 |
Name => |
| 8007 |
New_Occurrence_Of |
| 8008 |
(Build_Array_VS_Func |
| 8009 |
(Attr => N, |
| 8010 |
Formal_Typ => Ptyp, |
| 8011 |
Array_Typ => Val_Typ), |
| 8012 |
Loc), |
| 8013 |
Parameter_Associations => New_List (Pref)); |
| 8014 |
|
| 8015 |
-- Validate the scalar components, discriminants of a record type by |
| 8016 |
-- examining the structure of a record type. |
| 8017 |
|
| 8018 |
elsif Is_Record_Type (Val_Typ) then |
| 8019 |
Expr := |
| 8020 |
Make_Function_Call (Loc, |
| 8021 |
Name => |
| 8022 |
New_Occurrence_Of |
| 8023 |
(Build_Record_VS_Func |
| 8024 |
(Attr => N, |
| 8025 |
Formal_Typ => Ptyp, |
| 8026 |
Rec_Typ => Val_Typ), |
| 8027 |
Loc), |
| 8028 |
Parameter_Associations => New_List (Pref)); |
| 8029 |
end if; |
| 8030 |
|
| 8031 |
-- Default the attribute to True when the type of the prefix does not |
| 8032 |
-- need validation. |
| 8033 |
|
| 8034 |
if No (Expr) then |
| 8035 |
Expr := New_Occurrence_Of (Standard_True, Loc); |
| 8036 |
end if; |
| 8037 |
|
| 8038 |
Rewrite (N, Expr); |
| 8039 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 8040 |
Set_Is_Static_Expression (N, False); |
| 8041 |
end Valid_Scalars; |
| 8042 |
|
| 8043 |
----------- |
| 8044 |
-- Value -- |
| 8045 |
----------- |
| 8046 |
|
| 8047 |
when Attribute_Value => |
| 8048 |
Exp_Imgv.Expand_Value_Attribute (N); |
| 8049 |
|
| 8050 |
----------------- |
| 8051 |
-- Value_Size -- |
| 8052 |
----------------- |
| 8053 |
|
| 8054 |
-- The processing for Value_Size shares the processing for Size |
| 8055 |
|
| 8056 |
------------- |
| 8057 |
-- Version -- |
| 8058 |
------------- |
| 8059 |
|
| 8060 |
-- The processing for Version shares the processing for Body_Version |
| 8061 |
|
| 8062 |
---------------- |
| 8063 |
-- Wide_Image -- |
| 8064 |
---------------- |
| 8065 |
|
| 8066 |
when Attribute_Wide_Image => |
| 8067 |
-- Leave attribute unexpanded in CodePeer mode: the gnat2scil |
| 8068 |
-- back-end knows how to handle this attribute directly. |
| 8069 |
|
| 8070 |
if CodePeer_Mode then |
| 8071 |
return; |
| 8072 |
end if; |
| 8073 |
|
| 8074 |
Exp_Imgv.Expand_Wide_Image_Attribute (N); |
| 8075 |
|
| 8076 |
--------------------- |
| 8077 |
-- Wide_Wide_Image -- |
| 8078 |
--------------------- |
| 8079 |
|
| 8080 |
when Attribute_Wide_Wide_Image => |
| 8081 |
-- Leave attribute unexpanded in CodePeer mode: the gnat2scil |
| 8082 |
-- back-end knows how to handle this attribute directly. |
| 8083 |
|
| 8084 |
if CodePeer_Mode then |
| 8085 |
return; |
| 8086 |
end if; |
| 8087 |
|
| 8088 |
Exp_Imgv.Expand_Wide_Wide_Image_Attribute (N); |
| 8089 |
|
| 8090 |
---------------- |
| 8091 |
-- Wide_Value -- |
| 8092 |
---------------- |
| 8093 |
|
| 8094 |
-- We expand typ'Wide_Value (X) into |
| 8095 |
|
| 8096 |
-- typ'Value |
| 8097 |
-- (Wide_String_To_String (X, Wide_Character_Encoding_Method)) |
| 8098 |
|
| 8099 |
-- Wide_String_To_String is a runtime function that converts its wide |
| 8100 |
-- string argument to String, converting any non-translatable characters |
| 8101 |
-- into appropriate escape sequences. This preserves the required |
| 8102 |
-- semantics of Wide_Value in all cases, and results in a very simple |
| 8103 |
-- implementation approach. |
| 8104 |
|
| 8105 |
-- Note: for this approach to be fully standard compliant for the cases |
| 8106 |
-- where typ is Wide_Character and Wide_Wide_Character, the encoding |
| 8107 |
-- method must cover the entire character range (e.g. UTF-8). But that |
| 8108 |
-- is a reasonable requirement when dealing with encoded character |
| 8109 |
-- sequences. Presumably if one of the restrictive encoding mechanisms |
| 8110 |
-- is in use such as Shift-JIS, then characters that cannot be |
| 8111 |
-- represented using this encoding will not appear in any case. |
| 8112 |
|
| 8113 |
when Attribute_Wide_Value => |
| 8114 |
Rewrite (N, |
| 8115 |
Make_Attribute_Reference (Loc, |
| 8116 |
Prefix => Pref, |
| 8117 |
Attribute_Name => Name_Value, |
| 8118 |
|
| 8119 |
Expressions => New_List ( |
| 8120 |
Make_Function_Call (Loc, |
| 8121 |
Name => |
| 8122 |
New_Occurrence_Of |
| 8123 |
(RTE (if Is_User_Defined_Enumeration_Type (Typ) |
| 8124 |
then RE_Enum_Wide_String_To_String |
| 8125 |
else RE_Wide_String_To_String), Loc), |
| 8126 |
|
| 8127 |
Parameter_Associations => New_List ( |
| 8128 |
Relocate_Node (First (Exprs)), |
| 8129 |
Make_Integer_Literal (Loc, |
| 8130 |
Intval => Int (Wide_Character_Encoding_Method))))))); |
| 8131 |
|
| 8132 |
Analyze_And_Resolve (N, Typ); |
| 8133 |
|
| 8134 |
--------------------- |
| 8135 |
-- Wide_Wide_Value -- |
| 8136 |
--------------------- |
| 8137 |
|
| 8138 |
-- We expand typ'Wide_Value_Value (X) into |
| 8139 |
|
| 8140 |
-- typ'Value |
| 8141 |
-- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method)) |
| 8142 |
|
| 8143 |
-- See Wide_Value for more information. This is not quite right where |
| 8144 |
-- typ = Wide_Wide_Character, because the encoding method may not cover |
| 8145 |
-- the whole character type. |
| 8146 |
|
| 8147 |
when Attribute_Wide_Wide_Value => |
| 8148 |
Rewrite (N, |
| 8149 |
Make_Attribute_Reference (Loc, |
| 8150 |
Prefix => Pref, |
| 8151 |
Attribute_Name => Name_Value, |
| 8152 |
|
| 8153 |
Expressions => New_List ( |
| 8154 |
Make_Function_Call (Loc, |
| 8155 |
Name => |
| 8156 |
New_Occurrence_Of |
| 8157 |
(RTE (if Is_User_Defined_Enumeration_Type (Typ) |
| 8158 |
then RE_Enum_Wide_Wide_String_To_String |
| 8159 |
else RE_Wide_Wide_String_To_String), Loc), |
| 8160 |
|
| 8161 |
Parameter_Associations => New_List ( |
| 8162 |
Relocate_Node (First (Exprs)), |
| 8163 |
Make_Integer_Literal (Loc, |
| 8164 |
Intval => Int (Wide_Character_Encoding_Method))))))); |
| 8165 |
|
| 8166 |
Analyze_And_Resolve (N, Typ); |
| 8167 |
|
| 8168 |
--------------------- |
| 8169 |
-- Wide_Wide_Width -- |
| 8170 |
--------------------- |
| 8171 |
|
| 8172 |
when Attribute_Wide_Wide_Width => |
| 8173 |
Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide); |
| 8174 |
|
| 8175 |
---------------- |
| 8176 |
-- Wide_Width -- |
| 8177 |
---------------- |
| 8178 |
|
| 8179 |
when Attribute_Wide_Width => |
| 8180 |
Exp_Imgv.Expand_Width_Attribute (N, Wide); |
| 8181 |
|
| 8182 |
----------- |
| 8183 |
-- Width -- |
| 8184 |
----------- |
| 8185 |
|
| 8186 |
when Attribute_Width => |
| 8187 |
Exp_Imgv.Expand_Width_Attribute (N, Normal); |
| 8188 |
|
| 8189 |
----------- |
| 8190 |
-- Write -- |
| 8191 |
----------- |
| 8192 |
|
| 8193 |
when Attribute_Write => Write : declare |
| 8194 |
P_Type : constant Entity_Id := Entity (Pref); |
| 8195 |
U_Type : constant Entity_Id := Underlying_Type (P_Type); |
| 8196 |
Pname : Entity_Id; |
| 8197 |
Decl : Node_Id; |
| 8198 |
Prag : Node_Id; |
| 8199 |
Arg3 : Node_Id; |
| 8200 |
Wfunc : Node_Id; |
| 8201 |
|
| 8202 |
begin |
| 8203 |
-- If no underlying type, we have an error that will be diagnosed |
| 8204 |
-- elsewhere, so here we just completely ignore the expansion. |
| 8205 |
|
| 8206 |
if No (U_Type) then |
| 8207 |
return; |
| 8208 |
end if; |
| 8209 |
|
| 8210 |
-- Stream operations can appear in user code even if the restriction |
| 8211 |
-- No_Streams is active (for example, when instantiating a predefined |
| 8212 |
-- container). In that case rewrite the attribute as a Raise to |
| 8213 |
-- prevent any run-time use. |
| 8214 |
|
| 8215 |
if Restriction_Active (No_Streams) then |
| 8216 |
Rewrite (N, |
| 8217 |
Make_Raise_Program_Error (Loc, |
| 8218 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 8219 |
Set_Etype (N, U_Type); |
| 8220 |
return; |
| 8221 |
end if; |
| 8222 |
|
| 8223 |
-- The simple case, if there is a TSS for Write, just call it |
| 8224 |
|
| 8225 |
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write, N); |
| 8226 |
|
| 8227 |
if No (Pname) then |
| 8228 |
|
| 8229 |
-- If there is a Stream_Convert pragma, use it, we rewrite |
| 8230 |
|
| 8231 |
-- sourcetyp'Output (stream, Item) |
| 8232 |
|
| 8233 |
-- as |
| 8234 |
|
| 8235 |
-- strmtyp'Output (Stream, strmwrite (acttyp (Item))); |
| 8236 |
|
| 8237 |
-- where strmwrite is the given Write function that converts an |
| 8238 |
-- argument of type sourcetyp or a type acctyp, from which it is |
| 8239 |
-- derived to type strmtyp. The conversion to acttyp is required |
| 8240 |
-- for the derived case. |
| 8241 |
|
| 8242 |
Prag := Get_Stream_Convert_Pragma (P_Type); |
| 8243 |
|
| 8244 |
if Present (Prag) then |
| 8245 |
Arg3 := |
| 8246 |
Next (Next (First (Pragma_Argument_Associations (Prag)))); |
| 8247 |
Wfunc := Entity (Expression (Arg3)); |
| 8248 |
|
| 8249 |
Rewrite (N, |
| 8250 |
Make_Attribute_Reference (Loc, |
| 8251 |
Prefix => New_Occurrence_Of (Etype (Wfunc), Loc), |
| 8252 |
Attribute_Name => Name_Output, |
| 8253 |
Expressions => New_List ( |
| 8254 |
Relocate_Node (First (Exprs)), |
| 8255 |
Make_Function_Call (Loc, |
| 8256 |
Name => New_Occurrence_Of (Wfunc, Loc), |
| 8257 |
Parameter_Associations => New_List ( |
| 8258 |
OK_Convert_To (Etype (First_Formal (Wfunc)), |
| 8259 |
Relocate_Node (Next (First (Exprs))))))))); |
| 8260 |
|
| 8261 |
Analyze (N); |
| 8262 |
return; |
| 8263 |
|
| 8264 |
-- Limited types |
| 8265 |
|
| 8266 |
elsif Default_Streaming_Unavailable (U_Type) then |
| 8267 |
-- Do the same thing here as is done above in the |
| 8268 |
-- case where a No_Streams restriction is active. |
| 8269 |
|
| 8270 |
Rewrite (N, |
| 8271 |
Make_Raise_Program_Error (Loc, |
| 8272 |
Reason => PE_Stream_Operation_Not_Allowed)); |
| 8273 |
Set_Etype (N, U_Type); |
| 8274 |
return; |
| 8275 |
|
| 8276 |
-- For elementary types, we call the W_xxx routine directly |
| 8277 |
|
| 8278 |
elsif Is_Elementary_Type (U_Type) then |
| 8279 |
Rewrite (N, Build_Elementary_Write_Call (N)); |
| 8280 |
Analyze (N); |
| 8281 |
return; |
| 8282 |
|
| 8283 |
-- Array type case |
| 8284 |
|
| 8285 |
elsif Is_Array_Type (U_Type) then |
| 8286 |
declare |
| 8287 |
procedure Build_And_Insert_Array_Write_Proc is |
| 8288 |
new Build_And_Insert_Type_Attr_Subp |
| 8289 |
(Build_Array_Write_Procedure); |
| 8290 |
begin |
| 8291 |
Build_And_Insert_Array_Write_Proc |
| 8292 |
(Typ => Full_Base (U_Type), |
| 8293 |
Decl => Decl, |
| 8294 |
Subp => Pname, |
| 8295 |
Attr_Ref => N); |
| 8296 |
end; |
| 8297 |
|
| 8298 |
-- Tagged type case, use the primitive Write function. Note that |
| 8299 |
-- this will dispatch in the class-wide case which is what we want |
| 8300 |
|
| 8301 |
elsif Is_Tagged_Type (U_Type) then |
| 8302 |
Pname := Find_Prim_Op (U_Type, TSS_Stream_Write); |
| 8303 |
|
| 8304 |
-- All other record type cases, including protected records. |
| 8305 |
-- The latter only arise for expander generated code for |
| 8306 |
-- handling shared passive partition access. |
| 8307 |
|
| 8308 |
else |
| 8309 |
pragma Assert |
| 8310 |
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type)); |
| 8311 |
|
| 8312 |
-- Ada 2005 (AI-216): Program_Error is raised when executing |
| 8313 |
-- the default implementation of the Write attribute of an |
| 8314 |
-- Unchecked_Union type. However, if the 'Write reference is |
| 8315 |
-- within the generated Output stream procedure, Write outputs |
| 8316 |
-- the components, and the default values of the discriminant |
| 8317 |
-- are streamed by the Output procedure itself. If there are |
| 8318 |
-- no default values this is also erroneous. |
| 8319 |
|
| 8320 |
if Is_Unchecked_Union (Base_Type (U_Type)) then |
| 8321 |
if (not Is_TSS (Current_Scope, TSS_Stream_Output) |
| 8322 |
and not Is_TSS (Current_Scope, TSS_Stream_Write)) |
| 8323 |
or else No (Discriminant_Default_Value |
| 8324 |
(First_Discriminant (U_Type))) |
| 8325 |
then |
| 8326 |
Rewrite (N, |
| 8327 |
Make_Raise_Program_Error (Loc, |
| 8328 |
Reason => PE_Unchecked_Union_Restriction)); |
| 8329 |
Set_Etype (N, U_Type); |
| 8330 |
return; |
| 8331 |
end if; |
| 8332 |
end if; |
| 8333 |
|
| 8334 |
declare |
| 8335 |
procedure Build_Record_Write_Proc |
| 8336 |
(Typ : Entity_Id; |
| 8337 |
Decl : out Node_Id; |
| 8338 |
Subp : out Entity_Id); |
| 8339 |
|
| 8340 |
procedure Build_Record_Write_Proc |
| 8341 |
(Typ : Entity_Id; |
| 8342 |
Decl : out Node_Id; |
| 8343 |
Subp : out Entity_Id) is |
| 8344 |
begin |
| 8345 |
if Has_Defaulted_Discriminants (Typ) then |
| 8346 |
Build_Mutable_Record_Write_Procedure |
| 8347 |
(Typ, Decl, Subp); |
| 8348 |
else |
| 8349 |
Build_Record_Write_Procedure |
| 8350 |
(Typ, Decl, Subp); |
| 8351 |
end if; |
| 8352 |
end Build_Record_Write_Proc; |
| 8353 |
|
| 8354 |
procedure Build_And_Insert_Record_Write_Proc is |
| 8355 |
new Build_And_Insert_Type_Attr_Subp |
| 8356 |
(Build_Record_Write_Proc); |
| 8357 |
begin |
| 8358 |
Build_And_Insert_Record_Write_Proc |
| 8359 |
(Typ => Full_Base (U_Type), |
| 8360 |
Decl => Decl, |
| 8361 |
Subp => Pname, |
| 8362 |
Attr_Ref => N); |
| 8363 |
end; |
| 8364 |
end if; |
| 8365 |
end if; |
| 8366 |
|
| 8367 |
-- If we fall through, Pname is the procedure to be called |
| 8368 |
|
| 8369 |
Rewrite_Attribute_Proc_Call (Pname); |
| 8370 |
|
| 8371 |
if not Is_Tagged_Type (P_Type) then |
| 8372 |
Cached_Attribute_Ops.Write_Map.Set (U_Type, Pname); |
| 8373 |
end if; |
| 8374 |
end Write; |
| 8375 |
|
| 8376 |
-- The following attributes are handled by the back end (except that |
| 8377 |
-- static cases have already been evaluated during semantic processing, |
| 8378 |
-- but in any case the back end should not count on this). |
| 8379 |
|
| 8380 |
when Attribute_Code_Address |
| 8381 |
| Attribute_Deref |
| 8382 |
| Attribute_Null_Parameter |
| 8383 |
| Attribute_Passed_By_Reference |
| 8384 |
| Attribute_Pool_Address |
| 8385 |
=> |
| 8386 |
null; |
| 8387 |
|
| 8388 |
-- The following attributes should not appear at this stage, since they |
| 8389 |
-- have already been handled by the analyzer (and properly rewritten |
| 8390 |
-- with corresponding values or entities to represent the right values). |
| 8391 |
|
| 8392 |
when Attribute_Abort_Signal |
| 8393 |
| Attribute_Address_Size |
| 8394 |
| Attribute_Aft |
| 8395 |
| Attribute_Atomic_Always_Lock_Free |
| 8396 |
| Attribute_Base |
| 8397 |
| Attribute_Bit_Order |
| 8398 |
| Attribute_Class |
| 8399 |
| Attribute_Compiler_Version |
| 8400 |
| Attribute_Default_Bit_Order |
| 8401 |
| Attribute_Default_Scalar_Storage_Order |
| 8402 |
| Attribute_Definite |
| 8403 |
| Attribute_Delta |
| 8404 |
| Attribute_Denorm |
| 8405 |
| Attribute_Digits |
| 8406 |
| Attribute_Emax |
| 8407 |
| Attribute_Enabled |
| 8408 |
| Attribute_Epsilon |
| 8409 |
| Attribute_Fast_Math |
| 8410 |
| Attribute_First_Valid |
| 8411 |
| Attribute_Has_Access_Values |
| 8412 |
| Attribute_Has_Discriminants |
| 8413 |
| Attribute_Has_Tagged_Values |
| 8414 |
| Attribute_Large |
| 8415 |
| Attribute_Last_Valid |
| 8416 |
| Attribute_Library_Level |
| 8417 |
| Attribute_Machine_Emax |
| 8418 |
| Attribute_Machine_Emin |
| 8419 |
| Attribute_Machine_Mantissa |
| 8420 |
| Attribute_Machine_Overflows |
| 8421 |
| Attribute_Machine_Radix |
| 8422 |
| Attribute_Machine_Rounds |
| 8423 |
| Attribute_Max_Alignment_For_Allocation |
| 8424 |
| Attribute_Max_Integer_Size |
| 8425 |
| Attribute_Maximum_Alignment |
| 8426 |
| Attribute_Model_Emin |
| 8427 |
| Attribute_Model_Epsilon |
| 8428 |
| Attribute_Model_Mantissa |
| 8429 |
| Attribute_Model_Small |
| 8430 |
| Attribute_Modulus |
| 8431 |
| Attribute_Partition_ID |
| 8432 |
| Attribute_Range |
| 8433 |
| Attribute_Restriction_Set |
| 8434 |
| Attribute_Safe_Emax |
| 8435 |
| Attribute_Safe_First |
| 8436 |
| Attribute_Safe_Large |
| 8437 |
| Attribute_Safe_Last |
| 8438 |
| Attribute_Safe_Small |
| 8439 |
| Attribute_Scalar_Storage_Order |
| 8440 |
| Attribute_Scale |
| 8441 |
| Attribute_Signed_Zeros |
| 8442 |
| Attribute_Small |
| 8443 |
| Attribute_Small_Denominator |
| 8444 |
| Attribute_Small_Numerator |
| 8445 |
| Attribute_Storage_Unit |
| 8446 |
| Attribute_Stub_Type |
| 8447 |
| Attribute_Super |
| 8448 |
| Attribute_System_Allocator_Alignment |
| 8449 |
| Attribute_Target_Name |
| 8450 |
| Attribute_Type_Class |
| 8451 |
| Attribute_Type_Key |
| 8452 |
| Attribute_Unconstrained_Array |
| 8453 |
| Attribute_Universal_Literal_String |
| 8454 |
| Attribute_Wchar_T_Size |
| 8455 |
| Attribute_Word_Size |
| 8456 |
=> |
| 8457 |
raise Program_Error; |
| 8458 |
end case; |
| 8459 |
|
| 8460 |
-- Note: as mentioned earlier, individual sections of the above case |
| 8461 |
-- statement assume there is no code after the case statement, and are |
| 8462 |
-- legitimately allowed to execute return statements if they have nothing |
| 8463 |
-- more to do, so DO NOT add code at this point. |
| 8464 |
|
| 8465 |
exception |
| 8466 |
when RE_Not_Available => |
| 8467 |
return; |
| 8468 |
end Expand_N_Attribute_Reference; |
| 8469 |
|
| 8470 |
-------------------------------- |
| 8471 |
-- Expand_Pred_Succ_Attribute -- |
| 8472 |
-------------------------------- |
| 8473 |
|
| 8474 |
-- For typ'Pred (exp), we generate the check |
| 8475 |
|
| 8476 |
-- [constraint_error when exp = typ'Base'First] |
| 8477 |
|
| 8478 |
-- Similarly, for typ'Succ (exp), we generate the check |
| 8479 |
|
| 8480 |
-- [constraint_error when exp = typ'Base'Last] |
| 8481 |
|
| 8482 |
-- These checks are not generated for modular types, since the proper |
| 8483 |
-- semantics for Succ and Pred on modular types is to wrap, not raise CE. |
| 8484 |
-- We also suppress these checks if we are the right side of an assignment |
| 8485 |
-- statement or the expression of an object declaration, where the flag |
| 8486 |
-- Suppress_Assignment_Checks is set for the assignment/declaration. |
| 8487 |
|
| 8488 |
procedure Expand_Pred_Succ_Attribute (N : Node_Id) is |
| 8489 |
Loc : constant Source_Ptr := Sloc (N); |
| 8490 |
P : constant Node_Id := Parent (N); |
| 8491 |
Cnam : Name_Id; |
| 8492 |
|
| 8493 |
begin |
| 8494 |
if Attribute_Name (N) = Name_Pred then |
| 8495 |
Cnam := Name_First; |
| 8496 |
else |
| 8497 |
Cnam := Name_Last; |
| 8498 |
end if; |
| 8499 |
|
| 8500 |
if Nkind (P) not in N_Assignment_Statement | N_Object_Declaration |
| 8501 |
or else not Suppress_Assignment_Checks (P) |
| 8502 |
then |
| 8503 |
Insert_Action (N, |
| 8504 |
Make_Raise_Constraint_Error (Loc, |
| 8505 |
Condition => |
| 8506 |
Make_Op_Eq (Loc, |
| 8507 |
Left_Opnd => |
| 8508 |
Duplicate_Subexpr_Move_Checks (First (Expressions (N))), |
| 8509 |
Right_Opnd => |
| 8510 |
Make_Attribute_Reference (Loc, |
| 8511 |
Prefix => |
| 8512 |
New_Occurrence_Of (Base_Type (Etype (Prefix (N))), Loc), |
| 8513 |
Attribute_Name => Cnam)), |
| 8514 |
Reason => CE_Overflow_Check_Failed)); |
| 8515 |
end if; |
| 8516 |
end Expand_Pred_Succ_Attribute; |
| 8517 |
|
| 8518 |
--------------------------- |
| 8519 |
-- Expand_Size_Attribute -- |
| 8520 |
--------------------------- |
| 8521 |
|
| 8522 |
procedure Expand_Size_Attribute (N : Node_Id) is |
| 8523 |
Loc : constant Source_Ptr := Sloc (N); |
| 8524 |
Typ : constant Entity_Id := Etype (N); |
| 8525 |
Pref : constant Node_Id := Prefix (N); |
| 8526 |
Ptyp : constant Entity_Id := Etype (Pref); |
| 8527 |
Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N)); |
| 8528 |
Siz : Uint; |
| 8529 |
|
| 8530 |
begin |
| 8531 |
-- Case of known RM_Size of a type |
| 8532 |
|
| 8533 |
if Id in Attribute_Size | Attribute_Value_Size |
| 8534 |
and then Is_Entity_Name (Pref) |
| 8535 |
and then Is_Type (Entity (Pref)) |
| 8536 |
and then Known_Static_RM_Size (Entity (Pref)) |
| 8537 |
then |
| 8538 |
Siz := RM_Size (Entity (Pref)); |
| 8539 |
|
| 8540 |
-- Case of known Esize of a type |
| 8541 |
|
| 8542 |
elsif Id = Attribute_Object_Size |
| 8543 |
and then Is_Entity_Name (Pref) |
| 8544 |
and then Is_Type (Entity (Pref)) |
| 8545 |
and then Known_Static_Esize (Entity (Pref)) |
| 8546 |
then |
| 8547 |
Siz := Esize (Entity (Pref)); |
| 8548 |
|
| 8549 |
-- Case of known size of object |
| 8550 |
|
| 8551 |
elsif Id = Attribute_Size |
| 8552 |
and then Is_Entity_Name (Pref) |
| 8553 |
and then Is_Object (Entity (Pref)) |
| 8554 |
and then Known_Static_Esize (Entity (Pref)) |
| 8555 |
then |
| 8556 |
Siz := Esize (Entity (Pref)); |
| 8557 |
|
| 8558 |
-- For an array component, we can do Size in the front end if the |
| 8559 |
-- component_size of the array is set. |
| 8560 |
|
| 8561 |
elsif Nkind (Pref) = N_Indexed_Component then |
| 8562 |
Siz := Component_Size (Etype (Prefix (Pref))); |
| 8563 |
|
| 8564 |
-- For a record component, we can do Size in the front end if there is a |
| 8565 |
-- component clause, or if the record is packed and the component's size |
| 8566 |
-- is known at compile time. |
| 8567 |
|
| 8568 |
elsif Nkind (Pref) = N_Selected_Component then |
| 8569 |
declare |
| 8570 |
Rec : constant Entity_Id := Etype (Prefix (Pref)); |
| 8571 |
Comp : constant Entity_Id := Entity (Selector_Name (Pref)); |
| 8572 |
|
| 8573 |
begin |
| 8574 |
if Present (Component_Clause (Comp)) then |
| 8575 |
Siz := Esize (Comp); |
| 8576 |
|
| 8577 |
elsif Is_Packed (Rec) then |
| 8578 |
Siz := RM_Size (Ptyp); |
| 8579 |
|
| 8580 |
else |
| 8581 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 8582 |
return; |
| 8583 |
end if; |
| 8584 |
end; |
| 8585 |
|
| 8586 |
-- All other cases are handled by the back end |
| 8587 |
|
| 8588 |
else |
| 8589 |
-- If Size is applied to a formal parameter that is of a packed |
| 8590 |
-- array subtype, then apply Size to the actual subtype. |
| 8591 |
|
| 8592 |
if Is_Entity_Name (Pref) |
| 8593 |
and then Is_Formal (Entity (Pref)) |
| 8594 |
and then Is_Packed_Array (Ptyp) |
| 8595 |
then |
| 8596 |
Rewrite (N, |
| 8597 |
Make_Attribute_Reference (Loc, |
| 8598 |
Prefix => |
| 8599 |
New_Occurrence_Of (Get_Actual_Subtype (Pref), Loc), |
| 8600 |
Attribute_Name => Name_Size)); |
| 8601 |
Analyze_And_Resolve (N, Typ); |
| 8602 |
|
| 8603 |
-- If Size is applied to a dereference of an access to unconstrained |
| 8604 |
-- packed array, the back end needs to see its unconstrained nominal |
| 8605 |
-- type, but also a hint to the actual constrained type. |
| 8606 |
|
| 8607 |
elsif Nkind (Pref) = N_Explicit_Dereference |
| 8608 |
and then Is_Packed_Array (Ptyp) |
| 8609 |
and then not Is_Constrained (Ptyp) |
| 8610 |
then |
| 8611 |
Set_Actual_Designated_Subtype (Pref, Get_Actual_Subtype (Pref)); |
| 8612 |
|
| 8613 |
-- If Size was applied to a slice of a bit-packed array, we rewrite |
| 8614 |
-- it into the product of Length and Component_Size. We need to do so |
| 8615 |
-- because bit-packed arrays are represented internally as arrays of |
| 8616 |
-- System.Unsigned_Types.Packed_Byte for code generation purposes so |
| 8617 |
-- the size is always rounded up in the back end. |
| 8618 |
|
| 8619 |
elsif Nkind (Pref) = N_Slice and then Is_Bit_Packed_Array (Ptyp) then |
| 8620 |
Rewrite (N, |
| 8621 |
Make_Op_Multiply (Loc, |
| 8622 |
Make_Attribute_Reference (Loc, |
| 8623 |
Prefix => Duplicate_Subexpr (Pref, Name_Req => True), |
| 8624 |
Attribute_Name => Name_Length), |
| 8625 |
Make_Attribute_Reference (Loc, |
| 8626 |
Prefix => Duplicate_Subexpr (Pref, Name_Req => True), |
| 8627 |
Attribute_Name => Name_Component_Size))); |
| 8628 |
Analyze_And_Resolve (N, Typ); |
| 8629 |
end if; |
| 8630 |
|
| 8631 |
-- Apply the required checks last, after rewriting has taken place |
| 8632 |
|
| 8633 |
Apply_Universal_Integer_Attribute_Checks (N); |
| 8634 |
return; |
| 8635 |
end if; |
| 8636 |
|
| 8637 |
-- Common processing for record and array component case |
| 8638 |
|
| 8639 |
if Present (Siz) and then Siz /= 0 then |
| 8640 |
declare |
| 8641 |
CS : constant Boolean := Comes_From_Source (N); |
| 8642 |
|
| 8643 |
begin |
| 8644 |
Rewrite (N, Make_Integer_Literal (Loc, Siz)); |
| 8645 |
|
| 8646 |
-- This integer literal is not a static expression. We do not |
| 8647 |
-- call Analyze_And_Resolve here, because this would activate |
| 8648 |
-- the circuit for deciding that a static value was out of range, |
| 8649 |
-- and we don't want that. |
| 8650 |
|
| 8651 |
-- So just manually set the type, mark the expression as |
| 8652 |
-- nonstatic, and then ensure that the result is checked |
| 8653 |
-- properly if the attribute comes from source (if it was |
| 8654 |
-- internally generated, we never need a constraint check). |
| 8655 |
|
| 8656 |
Set_Etype (N, Typ); |
| 8657 |
Set_Is_Static_Expression (N, False); |
| 8658 |
|
| 8659 |
if CS then |
| 8660 |
Apply_Constraint_Check (N, Typ); |
| 8661 |
end if; |
| 8662 |
end; |
| 8663 |
end if; |
| 8664 |
end Expand_Size_Attribute; |
| 8665 |
|
| 8666 |
----------------------------- |
| 8667 |
-- Expand_Update_Attribute -- |
| 8668 |
----------------------------- |
| 8669 |
|
| 8670 |
procedure Expand_Update_Attribute (N : Node_Id) is |
| 8671 |
procedure Process_Component_Or_Element_Update |
| 8672 |
(Temp : Entity_Id; |
| 8673 |
Comp : Node_Id; |
| 8674 |
Expr : Node_Id; |
| 8675 |
Typ : Entity_Id); |
| 8676 |
-- Generate the statements necessary to update a single component or an |
| 8677 |
-- element of the prefix. The code is inserted before the attribute N. |
| 8678 |
-- Temp denotes the entity of the anonymous object created to reflect |
| 8679 |
-- the changes in values. Comp is the component/index expression to be |
| 8680 |
-- updated. Expr is an expression yielding the new value of Comp. Typ |
| 8681 |
-- is the type of the prefix of attribute Update. |
| 8682 |
|
| 8683 |
procedure Process_Range_Update |
| 8684 |
(Temp : Entity_Id; |
| 8685 |
Comp : Node_Id; |
| 8686 |
Expr : Node_Id; |
| 8687 |
Typ : Entity_Id); |
| 8688 |
-- Generate the statements necessary to update a slice of the prefix. |
| 8689 |
-- The code is inserted before the attribute N. Temp denotes the entity |
| 8690 |
-- of the anonymous object created to reflect the changes in values. |
| 8691 |
-- Comp is range of the slice to be updated. Expr is an expression |
| 8692 |
-- yielding the new value of Comp. Typ is the type of the prefix of |
| 8693 |
-- attribute Update. |
| 8694 |
|
| 8695 |
----------------------------------------- |
| 8696 |
-- Process_Component_Or_Element_Update -- |
| 8697 |
----------------------------------------- |
| 8698 |
|
| 8699 |
procedure Process_Component_Or_Element_Update |
| 8700 |
(Temp : Entity_Id; |
| 8701 |
Comp : Node_Id; |
| 8702 |
Expr : Node_Id; |
| 8703 |
Typ : Entity_Id) |
| 8704 |
is |
| 8705 |
Loc : constant Source_Ptr := Sloc (Comp); |
| 8706 |
Exprs : List_Id; |
| 8707 |
LHS : Node_Id; |
| 8708 |
|
| 8709 |
begin |
| 8710 |
-- An array element may be modified by the following relations |
| 8711 |
-- depending on the number of dimensions: |
| 8712 |
|
| 8713 |
-- 1 => Expr -- one dimensional update |
| 8714 |
-- (1, ..., N) => Expr -- multi dimensional update |
| 8715 |
|
| 8716 |
-- The above forms are converted in assignment statements where the |
| 8717 |
-- left hand side is an indexed component: |
| 8718 |
|
| 8719 |
-- Temp (1) := Expr; -- one dimensional update |
| 8720 |
-- Temp (1, ..., N) := Expr; -- multi dimensional update |
| 8721 |
|
| 8722 |
if Is_Array_Type (Typ) then |
| 8723 |
|
| 8724 |
-- The index expressions of a multi dimensional array update |
| 8725 |
-- appear as an aggregate. |
| 8726 |
|
| 8727 |
if Nkind (Comp) = N_Aggregate then |
| 8728 |
Exprs := New_Copy_List_Tree (Expressions (Comp)); |
| 8729 |
else |
| 8730 |
Exprs := New_List (Relocate_Node (Comp)); |
| 8731 |
end if; |
| 8732 |
|
| 8733 |
LHS := |
| 8734 |
Make_Indexed_Component (Loc, |
| 8735 |
Prefix => New_Occurrence_Of (Temp, Loc), |
| 8736 |
Expressions => Exprs); |
| 8737 |
|
| 8738 |
-- A record component update appears in the following form: |
| 8739 |
|
| 8740 |
-- Comp => Expr |
| 8741 |
|
| 8742 |
-- The above relation is transformed into an assignment statement |
| 8743 |
-- where the left hand side is a selected component: |
| 8744 |
|
| 8745 |
-- Temp.Comp := Expr; |
| 8746 |
|
| 8747 |
else pragma Assert (Is_Record_Type (Typ)); |
| 8748 |
LHS := |
| 8749 |
Make_Selected_Component (Loc, |
| 8750 |
Prefix => New_Occurrence_Of (Temp, Loc), |
| 8751 |
Selector_Name => Relocate_Node (Comp)); |
| 8752 |
end if; |
| 8753 |
|
| 8754 |
Insert_Action (N, |
| 8755 |
Make_Assignment_Statement (Loc, |
| 8756 |
Name => LHS, |
| 8757 |
Expression => Relocate_Node (Expr))); |
| 8758 |
end Process_Component_Or_Element_Update; |
| 8759 |
|
| 8760 |
-------------------------- |
| 8761 |
-- Process_Range_Update -- |
| 8762 |
-------------------------- |
| 8763 |
|
| 8764 |
procedure Process_Range_Update |
| 8765 |
(Temp : Entity_Id; |
| 8766 |
Comp : Node_Id; |
| 8767 |
Expr : Node_Id; |
| 8768 |
Typ : Entity_Id) |
| 8769 |
is |
| 8770 |
Index_Typ : constant Entity_Id := Etype (First_Index (Typ)); |
| 8771 |
Loc : constant Source_Ptr := Sloc (Comp); |
| 8772 |
Index : Entity_Id; |
| 8773 |
|
| 8774 |
begin |
| 8775 |
-- A range update appears as |
| 8776 |
|
| 8777 |
-- (Low .. High => Expr) |
| 8778 |
|
| 8779 |
-- The above construct is transformed into a loop that iterates over |
| 8780 |
-- the given range and modifies the corresponding array values to the |
| 8781 |
-- value of Expr: |
| 8782 |
|
| 8783 |
-- for Index in Low .. High loop |
| 8784 |
-- Temp (<Index_Typ> (Index)) := Expr; |
| 8785 |
-- end loop; |
| 8786 |
|
| 8787 |
Index := Make_Temporary (Loc, 'I'); |
| 8788 |
|
| 8789 |
Insert_Action (N, |
| 8790 |
Make_Loop_Statement (Loc, |
| 8791 |
Iteration_Scheme => |
| 8792 |
Make_Iteration_Scheme (Loc, |
| 8793 |
Loop_Parameter_Specification => |
| 8794 |
Make_Loop_Parameter_Specification (Loc, |
| 8795 |
Defining_Identifier => Index, |
| 8796 |
Discrete_Subtype_Definition => Relocate_Node (Comp))), |
| 8797 |
|
| 8798 |
Statements => New_List ( |
| 8799 |
Make_Assignment_Statement (Loc, |
| 8800 |
Name => |
| 8801 |
Make_Indexed_Component (Loc, |
| 8802 |
Prefix => New_Occurrence_Of (Temp, Loc), |
| 8803 |
Expressions => New_List ( |
| 8804 |
Convert_To (Index_Typ, |
| 8805 |
New_Occurrence_Of (Index, Loc)))), |
| 8806 |
Expression => Relocate_Node (Expr))), |
| 8807 |
|
| 8808 |
End_Label => Empty)); |
| 8809 |
end Process_Range_Update; |
| 8810 |
|
| 8811 |
-- Local variables |
| 8812 |
|
| 8813 |
Aggr : constant Node_Id := First (Expressions (N)); |
| 8814 |
Loc : constant Source_Ptr := Sloc (N); |
| 8815 |
Pref : constant Node_Id := Prefix (N); |
| 8816 |
Typ : constant Entity_Id := Etype (Pref); |
| 8817 |
Assoc : Node_Id; |
| 8818 |
Comp : Node_Id; |
| 8819 |
CW_Temp : Entity_Id; |
| 8820 |
CW_Typ : Entity_Id; |
| 8821 |
Expr : Node_Id; |
| 8822 |
Temp : Entity_Id; |
| 8823 |
|
| 8824 |
-- Start of processing for Expand_Update_Attribute |
| 8825 |
|
| 8826 |
begin |
| 8827 |
-- Create the anonymous object to store the value of the prefix and |
| 8828 |
-- capture subsequent changes in value. |
| 8829 |
|
| 8830 |
Temp := Make_Temporary (Loc, 'T', Pref); |
| 8831 |
|
| 8832 |
-- Preserve the tag of the prefix by offering a specific view of the |
| 8833 |
-- class-wide version of the prefix. |
| 8834 |
|
| 8835 |
if Is_Tagged_Type (Typ) then |
| 8836 |
|
| 8837 |
-- Generate: |
| 8838 |
-- CW_Temp : Typ'Class := Typ'Class (Pref); |
| 8839 |
|
| 8840 |
CW_Temp := Make_Temporary (Loc, 'T'); |
| 8841 |
CW_Typ := Class_Wide_Type (Typ); |
| 8842 |
|
| 8843 |
Insert_Action (N, |
| 8844 |
Make_Object_Declaration (Loc, |
| 8845 |
Defining_Identifier => CW_Temp, |
| 8846 |
Object_Definition => New_Occurrence_Of (CW_Typ, Loc), |
| 8847 |
Expression => |
| 8848 |
Convert_To (CW_Typ, Relocate_Node (Pref)))); |
| 8849 |
|
| 8850 |
-- Generate: |
| 8851 |
-- Temp : Typ renames Typ (CW_Temp); |
| 8852 |
|
| 8853 |
Insert_Action (N, |
| 8854 |
Make_Object_Renaming_Declaration (Loc, |
| 8855 |
Defining_Identifier => Temp, |
| 8856 |
Subtype_Mark => New_Occurrence_Of (Typ, Loc), |
| 8857 |
Name => |
| 8858 |
Convert_To (Typ, New_Occurrence_Of (CW_Temp, Loc)))); |
| 8859 |
|
| 8860 |
-- Non-tagged case |
| 8861 |
|
| 8862 |
else |
| 8863 |
-- Generate: |
| 8864 |
-- Temp : Typ := Pref; |
| 8865 |
|
| 8866 |
Insert_Action (N, |
| 8867 |
Make_Object_Declaration (Loc, |
| 8868 |
Defining_Identifier => Temp, |
| 8869 |
Object_Definition => New_Occurrence_Of (Typ, Loc), |
| 8870 |
Expression => Relocate_Node (Pref))); |
| 8871 |
end if; |
| 8872 |
|
| 8873 |
-- Process the update aggregate |
| 8874 |
|
| 8875 |
Assoc := First (Component_Associations (Aggr)); |
| 8876 |
while Present (Assoc) loop |
| 8877 |
Comp := First (Choices (Assoc)); |
| 8878 |
Expr := Expression (Assoc); |
| 8879 |
while Present (Comp) loop |
| 8880 |
if Nkind (Comp) = N_Range then |
| 8881 |
Process_Range_Update (Temp, Comp, Expr, Typ); |
| 8882 |
elsif Nkind (Comp) = N_Subtype_Indication then |
| 8883 |
Process_Range_Update |
| 8884 |
(Temp, Range_Expression (Constraint (Comp)), Expr, Typ); |
| 8885 |
else |
| 8886 |
Process_Component_Or_Element_Update (Temp, Comp, Expr, Typ); |
| 8887 |
end if; |
| 8888 |
|
| 8889 |
Next (Comp); |
| 8890 |
end loop; |
| 8891 |
|
| 8892 |
Next (Assoc); |
| 8893 |
end loop; |
| 8894 |
|
| 8895 |
-- The attribute is replaced by a reference to the anonymous object |
| 8896 |
|
| 8897 |
Rewrite (N, New_Occurrence_Of (Temp, Loc)); |
| 8898 |
Analyze (N); |
| 8899 |
end Expand_Update_Attribute; |
| 8900 |
|
| 8901 |
------------------- |
| 8902 |
-- Find_Fat_Info -- |
| 8903 |
------------------- |
| 8904 |
|
| 8905 |
procedure Find_Fat_Info |
| 8906 |
(T : Entity_Id; |
| 8907 |
Fat_Type : out Entity_Id; |
| 8908 |
Fat_Pkg : out RE_Id) |
| 8909 |
is |
| 8910 |
Rtyp : constant Entity_Id := Root_Type (T); |
| 8911 |
|
| 8912 |
begin |
| 8913 |
-- All we do is use the root type (historically this dealt with |
| 8914 |
-- VAX-float .. to be cleaned up further later ???) |
| 8915 |
|
| 8916 |
if Rtyp = Standard_Short_Float or else Rtyp = Standard_Float then |
| 8917 |
Fat_Type := Standard_Float; |
| 8918 |
Fat_Pkg := RE_Attr_Float; |
| 8919 |
|
| 8920 |
elsif Rtyp = Standard_Long_Float then |
| 8921 |
Fat_Type := Standard_Long_Float; |
| 8922 |
Fat_Pkg := RE_Attr_Long_Float; |
| 8923 |
|
| 8924 |
elsif Rtyp = Standard_Long_Long_Float then |
| 8925 |
Fat_Type := Standard_Long_Long_Float; |
| 8926 |
Fat_Pkg := RE_Attr_Long_Long_Float; |
| 8927 |
|
| 8928 |
-- Universal real (which is its own root type) is treated as being |
| 8929 |
-- equivalent to Standard.Long_Long_Float, since it is defined to |
| 8930 |
-- have the same precision as the longest Float type. |
| 8931 |
|
| 8932 |
elsif Rtyp = Universal_Real then |
| 8933 |
Fat_Type := Standard_Long_Long_Float; |
| 8934 |
Fat_Pkg := RE_Attr_Long_Long_Float; |
| 8935 |
|
| 8936 |
else |
| 8937 |
raise Program_Error; |
| 8938 |
end if; |
| 8939 |
end Find_Fat_Info; |
| 8940 |
|
| 8941 |
---------------------------- |
| 8942 |
-- Find_Stream_Subprogram -- |
| 8943 |
---------------------------- |
| 8944 |
|
| 8945 |
function Find_Stream_Subprogram |
| 8946 |
(Typ : Entity_Id; |
| 8947 |
Nam : TSS_Name_Type; |
| 8948 |
Attr_Ref : Node_Id) return Entity_Id |
| 8949 |
is |
| 8950 |
-- Local declarations |
| 8951 |
|
| 8952 |
Base_Typ : constant Entity_Id := Base_Type (Typ); |
| 8953 |
Ent : Entity_Id := TSS (Typ, Nam); |
| 8954 |
|
| 8955 |
-- Start of processing for Find_Stream_Subprogram |
| 8956 |
|
| 8957 |
begin |
| 8958 |
if Present (Ent) then |
| 8959 |
return Ent; |
| 8960 |
end if; |
| 8961 |
|
| 8962 |
-- Everything after this point is an optimization. In other words, |
| 8963 |
-- there should be no *correctness* problems if we were to |
| 8964 |
-- unconditionally return Empty here. |
| 8965 |
|
| 8966 |
if Is_Unchecked_Union (Base_Typ) then |
| 8967 |
-- Conservatively avoid possible problems (e.g., Write behaves |
| 8968 |
-- differently for a U_U type when called by Output vs. when |
| 8969 |
-- called from elsewhere). |
| 8970 |
|
| 8971 |
return Empty; |
| 8972 |
end if; |
| 8973 |
|
| 8974 |
declare |
| 8975 |
function U_Base return Entity_Id is |
| 8976 |
(Underlying_Type (Base_Type (Typ))); |
| 8977 |
-- Return the right type node for use in a C_A_O map lookup. |
| 8978 |
-- In particular, we do not want the entity for a subtype. |
| 8979 |
begin |
| 8980 |
if Nam = TSS_Stream_Read then |
| 8981 |
Ent := Cached_Attribute_Ops.Read_Map.Get (U_Base); |
| 8982 |
elsif Nam = TSS_Stream_Write then |
| 8983 |
Ent := Cached_Attribute_Ops.Write_Map.Get (U_Base); |
| 8984 |
elsif Nam = TSS_Stream_Input then |
| 8985 |
Ent := Cached_Attribute_Ops.Input_Map.Get (U_Base); |
| 8986 |
elsif Nam = TSS_Stream_Output then |
| 8987 |
Ent := Cached_Attribute_Ops.Output_Map.Get (U_Base); |
| 8988 |
end if; |
| 8989 |
end; |
| 8990 |
|
| 8991 |
Cached_Attribute_Ops.Validate_Cached_Candidate |
| 8992 |
(Subp => Ent, Attr_Ref => Attr_Ref); |
| 8993 |
|
| 8994 |
if Present (Ent) then |
| 8995 |
return Ent; |
| 8996 |
end if; |
| 8997 |
|
| 8998 |
-- Stream attributes for strings are expanded into library calls. The |
| 8999 |
-- following checks are disabled when the run-time is not available or |
| 9000 |
-- when compiling predefined types due to bootstrap issues. As a result, |
| 9001 |
-- the compiler will generate in-place stream routines for string types |
| 9002 |
-- that appear in GNAT's library, but will generate calls via rtsfind |
| 9003 |
-- to library routines for user code. |
| 9004 |
|
| 9005 |
-- Note: In the case of using a configurable run time, it is very likely |
| 9006 |
-- that stream routines for string types are not present (they require |
| 9007 |
-- file system support). In this case, the specific stream routines for |
| 9008 |
-- strings are not used, relying on the regular stream mechanism |
| 9009 |
-- instead. That is why we include the test RTE_Available when dealing |
| 9010 |
-- with these cases. |
| 9011 |
|
| 9012 |
if not Is_Predefined_Unit (Current_Sem_Unit) then |
| 9013 |
-- Storage_Array as defined in package System.Storage_Elements |
| 9014 |
|
| 9015 |
if Is_RTE (Base_Typ, RE_Storage_Array) then |
| 9016 |
|
| 9017 |
-- Case of No_Stream_Optimizations restriction active |
| 9018 |
|
| 9019 |
if Restriction_Active (No_Stream_Optimizations) then |
| 9020 |
if Nam = TSS_Stream_Input |
| 9021 |
and then RTE_Available (RE_Storage_Array_Input) |
| 9022 |
then |
| 9023 |
return RTE (RE_Storage_Array_Input); |
| 9024 |
|
| 9025 |
elsif Nam = TSS_Stream_Output |
| 9026 |
and then RTE_Available (RE_Storage_Array_Output) |
| 9027 |
then |
| 9028 |
return RTE (RE_Storage_Array_Output); |
| 9029 |
|
| 9030 |
elsif Nam = TSS_Stream_Read |
| 9031 |
and then RTE_Available (RE_Storage_Array_Read) |
| 9032 |
then |
| 9033 |
return RTE (RE_Storage_Array_Read); |
| 9034 |
|
| 9035 |
elsif Nam = TSS_Stream_Write |
| 9036 |
and then RTE_Available (RE_Storage_Array_Write) |
| 9037 |
then |
| 9038 |
return RTE (RE_Storage_Array_Write); |
| 9039 |
|
| 9040 |
elsif Nam /= TSS_Stream_Input and then |
| 9041 |
Nam /= TSS_Stream_Output and then |
| 9042 |
Nam /= TSS_Stream_Read and then |
| 9043 |
Nam /= TSS_Stream_Write |
| 9044 |
then |
| 9045 |
raise Program_Error; |
| 9046 |
end if; |
| 9047 |
|
| 9048 |
-- Restriction No_Stream_Optimizations is not set, so we can go |
| 9049 |
-- ahead and optimize using the block IO forms of the routines. |
| 9050 |
|
| 9051 |
else |
| 9052 |
if Nam = TSS_Stream_Input |
| 9053 |
and then RTE_Available (RE_Storage_Array_Input_Blk_IO) |
| 9054 |
then |
| 9055 |
return RTE (RE_Storage_Array_Input_Blk_IO); |
| 9056 |
|
| 9057 |
elsif Nam = TSS_Stream_Output |
| 9058 |
and then RTE_Available (RE_Storage_Array_Output_Blk_IO) |
| 9059 |
then |
| 9060 |
return RTE (RE_Storage_Array_Output_Blk_IO); |
| 9061 |
|
| 9062 |
elsif Nam = TSS_Stream_Read |
| 9063 |
and then RTE_Available (RE_Storage_Array_Read_Blk_IO) |
| 9064 |
then |
| 9065 |
return RTE (RE_Storage_Array_Read_Blk_IO); |
| 9066 |
|
| 9067 |
elsif Nam = TSS_Stream_Write |
| 9068 |
and then RTE_Available (RE_Storage_Array_Write_Blk_IO) |
| 9069 |
then |
| 9070 |
return RTE (RE_Storage_Array_Write_Blk_IO); |
| 9071 |
|
| 9072 |
elsif Nam /= TSS_Stream_Input and then |
| 9073 |
Nam /= TSS_Stream_Output and then |
| 9074 |
Nam /= TSS_Stream_Read and then |
| 9075 |
Nam /= TSS_Stream_Write |
| 9076 |
then |
| 9077 |
raise Program_Error; |
| 9078 |
end if; |
| 9079 |
end if; |
| 9080 |
|
| 9081 |
-- Stream_Element_Array as defined in package Ada.Streams |
| 9082 |
|
| 9083 |
elsif Is_RTE (Base_Typ, RE_Stream_Element_Array) then |
| 9084 |
|
| 9085 |
-- Case of No_Stream_Optimizations restriction active |
| 9086 |
|
| 9087 |
if Restriction_Active (No_Stream_Optimizations) then |
| 9088 |
if Nam = TSS_Stream_Input |
| 9089 |
and then RTE_Available (RE_Stream_Element_Array_Input) |
| 9090 |
then |
| 9091 |
return RTE (RE_Stream_Element_Array_Input); |
| 9092 |
|
| 9093 |
elsif Nam = TSS_Stream_Output |
| 9094 |
and then RTE_Available (RE_Stream_Element_Array_Output) |
| 9095 |
then |
| 9096 |
return RTE (RE_Stream_Element_Array_Output); |
| 9097 |
|
| 9098 |
elsif Nam = TSS_Stream_Read |
| 9099 |
and then RTE_Available (RE_Stream_Element_Array_Read) |
| 9100 |
then |
| 9101 |
return RTE (RE_Stream_Element_Array_Read); |
| 9102 |
|
| 9103 |
elsif Nam = TSS_Stream_Write |
| 9104 |
and then RTE_Available (RE_Stream_Element_Array_Write) |
| 9105 |
then |
| 9106 |
return RTE (RE_Stream_Element_Array_Write); |
| 9107 |
|
| 9108 |
elsif Nam /= TSS_Stream_Input and then |
| 9109 |
Nam /= TSS_Stream_Output and then |
| 9110 |
Nam /= TSS_Stream_Read and then |
| 9111 |
Nam /= TSS_Stream_Write |
| 9112 |
then |
| 9113 |
raise Program_Error; |
| 9114 |
end if; |
| 9115 |
|
| 9116 |
-- Restriction No_Stream_Optimizations is not set, so we can go |
| 9117 |
-- ahead and optimize using the block IO forms of the routines. |
| 9118 |
|
| 9119 |
else |
| 9120 |
if Nam = TSS_Stream_Input |
| 9121 |
and then RTE_Available (RE_Stream_Element_Array_Input_Blk_IO) |
| 9122 |
then |
| 9123 |
return RTE (RE_Stream_Element_Array_Input_Blk_IO); |
| 9124 |
|
| 9125 |
elsif Nam = TSS_Stream_Output |
| 9126 |
and then RTE_Available (RE_Stream_Element_Array_Output_Blk_IO) |
| 9127 |
then |
| 9128 |
return RTE (RE_Stream_Element_Array_Output_Blk_IO); |
| 9129 |
|
| 9130 |
elsif Nam = TSS_Stream_Read |
| 9131 |
and then RTE_Available (RE_Stream_Element_Array_Read_Blk_IO) |
| 9132 |
then |
| 9133 |
return RTE (RE_Stream_Element_Array_Read_Blk_IO); |
| 9134 |
|
| 9135 |
elsif Nam = TSS_Stream_Write |
| 9136 |
and then RTE_Available (RE_Stream_Element_Array_Write_Blk_IO) |
| 9137 |
then |
| 9138 |
return RTE (RE_Stream_Element_Array_Write_Blk_IO); |
| 9139 |
|
| 9140 |
elsif Nam /= TSS_Stream_Input and then |
| 9141 |
Nam /= TSS_Stream_Output and then |
| 9142 |
Nam /= TSS_Stream_Read and then |
| 9143 |
Nam /= TSS_Stream_Write |
| 9144 |
then |
| 9145 |
raise Program_Error; |
| 9146 |
end if; |
| 9147 |
end if; |
| 9148 |
|
| 9149 |
-- String as defined in package Ada |
| 9150 |
|
| 9151 |
elsif Base_Typ = Standard_String then |
| 9152 |
|
| 9153 |
-- Case of No_Stream_Optimizations restriction active |
| 9154 |
|
| 9155 |
if Restriction_Active (No_Stream_Optimizations) then |
| 9156 |
if Nam = TSS_Stream_Input |
| 9157 |
and then RTE_Available (RE_String_Input) |
| 9158 |
then |
| 9159 |
return RTE (RE_String_Input); |
| 9160 |
|
| 9161 |
elsif Nam = TSS_Stream_Output |
| 9162 |
and then RTE_Available (RE_String_Output) |
| 9163 |
then |
| 9164 |
return RTE (RE_String_Output); |
| 9165 |
|
| 9166 |
elsif Nam = TSS_Stream_Read |
| 9167 |
and then RTE_Available (RE_String_Read) |
| 9168 |
then |
| 9169 |
return RTE (RE_String_Read); |
| 9170 |
|
| 9171 |
elsif Nam = TSS_Stream_Write |
| 9172 |
and then RTE_Available (RE_String_Write) |
| 9173 |
then |
| 9174 |
return RTE (RE_String_Write); |
| 9175 |
|
| 9176 |
elsif Nam /= TSS_Stream_Input and then |
| 9177 |
Nam /= TSS_Stream_Output and then |
| 9178 |
Nam /= TSS_Stream_Read and then |
| 9179 |
Nam /= TSS_Stream_Write |
| 9180 |
then |
| 9181 |
raise Program_Error; |
| 9182 |
end if; |
| 9183 |
|
| 9184 |
-- Restriction No_Stream_Optimizations is not set, so we can go |
| 9185 |
-- ahead and optimize using the block IO forms of the routines. |
| 9186 |
|
| 9187 |
else |
| 9188 |
if Nam = TSS_Stream_Input |
| 9189 |
and then RTE_Available (RE_String_Input_Blk_IO) |
| 9190 |
then |
| 9191 |
return RTE (RE_String_Input_Blk_IO); |
| 9192 |
|
| 9193 |
elsif Nam = TSS_Stream_Output |
| 9194 |
and then RTE_Available (RE_String_Output_Blk_IO) |
| 9195 |
then |
| 9196 |
return RTE (RE_String_Output_Blk_IO); |
| 9197 |
|
| 9198 |
elsif Nam = TSS_Stream_Read |
| 9199 |
and then RTE_Available (RE_String_Read_Blk_IO) |
| 9200 |
then |
| 9201 |
return RTE (RE_String_Read_Blk_IO); |
| 9202 |
|
| 9203 |
elsif Nam = TSS_Stream_Write |
| 9204 |
and then RTE_Available (RE_String_Write_Blk_IO) |
| 9205 |
then |
| 9206 |
return RTE (RE_String_Write_Blk_IO); |
| 9207 |
|
| 9208 |
elsif Nam /= TSS_Stream_Input and then |
| 9209 |
Nam /= TSS_Stream_Output and then |
| 9210 |
Nam /= TSS_Stream_Read and then |
| 9211 |
Nam /= TSS_Stream_Write |
| 9212 |
then |
| 9213 |
raise Program_Error; |
| 9214 |
end if; |
| 9215 |
end if; |
| 9216 |
|
| 9217 |
-- Wide_String as defined in package Ada |
| 9218 |
|
| 9219 |
elsif Base_Typ = Standard_Wide_String then |
| 9220 |
|
| 9221 |
-- Case of No_Stream_Optimizations restriction active |
| 9222 |
|
| 9223 |
if Restriction_Active (No_Stream_Optimizations) then |
| 9224 |
if Nam = TSS_Stream_Input |
| 9225 |
and then RTE_Available (RE_Wide_String_Input) |
| 9226 |
then |
| 9227 |
return RTE (RE_Wide_String_Input); |
| 9228 |
|
| 9229 |
elsif Nam = TSS_Stream_Output |
| 9230 |
and then RTE_Available (RE_Wide_String_Output) |
| 9231 |
then |
| 9232 |
return RTE (RE_Wide_String_Output); |
| 9233 |
|
| 9234 |
elsif Nam = TSS_Stream_Read |
| 9235 |
and then RTE_Available (RE_Wide_String_Read) |
| 9236 |
then |
| 9237 |
return RTE (RE_Wide_String_Read); |
| 9238 |
|
| 9239 |
elsif Nam = TSS_Stream_Write |
| 9240 |
and then RTE_Available (RE_Wide_String_Write) |
| 9241 |
then |
| 9242 |
return RTE (RE_Wide_String_Write); |
| 9243 |
|
| 9244 |
elsif Nam /= TSS_Stream_Input and then |
| 9245 |
Nam /= TSS_Stream_Output and then |
| 9246 |
Nam /= TSS_Stream_Read and then |
| 9247 |
Nam /= TSS_Stream_Write |
| 9248 |
then |
| 9249 |
raise Program_Error; |
| 9250 |
end if; |
| 9251 |
|
| 9252 |
-- Restriction No_Stream_Optimizations is not set, so we can go |
| 9253 |
-- ahead and optimize using the block IO forms of the routines. |
| 9254 |
|
| 9255 |
else |
| 9256 |
if Nam = TSS_Stream_Input |
| 9257 |
and then RTE_Available (RE_Wide_String_Input_Blk_IO) |
| 9258 |
then |
| 9259 |
return RTE (RE_Wide_String_Input_Blk_IO); |
| 9260 |
|
| 9261 |
elsif Nam = TSS_Stream_Output |
| 9262 |
and then RTE_Available (RE_Wide_String_Output_Blk_IO) |
| 9263 |
then |
| 9264 |
return RTE (RE_Wide_String_Output_Blk_IO); |
| 9265 |
|
| 9266 |
elsif Nam = TSS_Stream_Read |
| 9267 |
and then RTE_Available (RE_Wide_String_Read_Blk_IO) |
| 9268 |
then |
| 9269 |
return RTE (RE_Wide_String_Read_Blk_IO); |
| 9270 |
|
| 9271 |
elsif Nam = TSS_Stream_Write |
| 9272 |
and then RTE_Available (RE_Wide_String_Write_Blk_IO) |
| 9273 |
then |
| 9274 |
return RTE (RE_Wide_String_Write_Blk_IO); |
| 9275 |
|
| 9276 |
elsif Nam /= TSS_Stream_Input and then |
| 9277 |
Nam /= TSS_Stream_Output and then |
| 9278 |
Nam /= TSS_Stream_Read and then |
| 9279 |
Nam /= TSS_Stream_Write |
| 9280 |
then |
| 9281 |
raise Program_Error; |
| 9282 |
end if; |
| 9283 |
end if; |
| 9284 |
|
| 9285 |
-- Wide_Wide_String as defined in package Ada |
| 9286 |
|
| 9287 |
elsif Base_Typ = Standard_Wide_Wide_String then |
| 9288 |
|
| 9289 |
-- Case of No_Stream_Optimizations restriction active |
| 9290 |
|
| 9291 |
if Restriction_Active (No_Stream_Optimizations) then |
| 9292 |
if Nam = TSS_Stream_Input |
| 9293 |
and then RTE_Available (RE_Wide_Wide_String_Input) |
| 9294 |
then |
| 9295 |
return RTE (RE_Wide_Wide_String_Input); |
| 9296 |
|
| 9297 |
elsif Nam = TSS_Stream_Output |
| 9298 |
and then RTE_Available (RE_Wide_Wide_String_Output) |
| 9299 |
then |
| 9300 |
return RTE (RE_Wide_Wide_String_Output); |
| 9301 |
|
| 9302 |
elsif Nam = TSS_Stream_Read |
| 9303 |
and then RTE_Available (RE_Wide_Wide_String_Read) |
| 9304 |
then |
| 9305 |
return RTE (RE_Wide_Wide_String_Read); |
| 9306 |
|
| 9307 |
elsif Nam = TSS_Stream_Write |
| 9308 |
and then RTE_Available (RE_Wide_Wide_String_Write) |
| 9309 |
then |
| 9310 |
return RTE (RE_Wide_Wide_String_Write); |
| 9311 |
|
| 9312 |
elsif Nam /= TSS_Stream_Input and then |
| 9313 |
Nam /= TSS_Stream_Output and then |
| 9314 |
Nam /= TSS_Stream_Read and then |
| 9315 |
Nam /= TSS_Stream_Write |
| 9316 |
then |
| 9317 |
raise Program_Error; |
| 9318 |
end if; |
| 9319 |
|
| 9320 |
-- Restriction No_Stream_Optimizations is not set, so we can go |
| 9321 |
-- ahead and optimize using the block IO forms of the routines. |
| 9322 |
|
| 9323 |
else |
| 9324 |
if Nam = TSS_Stream_Input |
| 9325 |
and then RTE_Available (RE_Wide_Wide_String_Input_Blk_IO) |
| 9326 |
then |
| 9327 |
return RTE (RE_Wide_Wide_String_Input_Blk_IO); |
| 9328 |
|
| 9329 |
elsif Nam = TSS_Stream_Output |
| 9330 |
and then RTE_Available (RE_Wide_Wide_String_Output_Blk_IO) |
| 9331 |
then |
| 9332 |
return RTE (RE_Wide_Wide_String_Output_Blk_IO); |
| 9333 |
|
| 9334 |
elsif Nam = TSS_Stream_Read |
| 9335 |
and then RTE_Available (RE_Wide_Wide_String_Read_Blk_IO) |
| 9336 |
then |
| 9337 |
return RTE (RE_Wide_Wide_String_Read_Blk_IO); |
| 9338 |
|
| 9339 |
elsif Nam = TSS_Stream_Write |
| 9340 |
and then RTE_Available (RE_Wide_Wide_String_Write_Blk_IO) |
| 9341 |
then |
| 9342 |
return RTE (RE_Wide_Wide_String_Write_Blk_IO); |
| 9343 |
|
| 9344 |
elsif Nam /= TSS_Stream_Input and then |
| 9345 |
Nam /= TSS_Stream_Output and then |
| 9346 |
Nam /= TSS_Stream_Read and then |
| 9347 |
Nam /= TSS_Stream_Write |
| 9348 |
then |
| 9349 |
raise Program_Error; |
| 9350 |
end if; |
| 9351 |
end if; |
| 9352 |
end if; |
| 9353 |
end if; |
| 9354 |
|
| 9355 |
if Is_Tagged_Type (Typ) and then Is_Derived_Type (Typ) then |
| 9356 |
return Find_Prim_Op (Typ, Nam); |
| 9357 |
else |
| 9358 |
return Find_Inherited_TSS (Typ, Nam); |
| 9359 |
end if; |
| 9360 |
end Find_Stream_Subprogram; |
| 9361 |
|
| 9362 |
--------------- |
| 9363 |
-- Full_Base -- |
| 9364 |
--------------- |
| 9365 |
|
| 9366 |
function Full_Base (T : Entity_Id) return Entity_Id is |
| 9367 |
BT : Entity_Id; |
| 9368 |
|
| 9369 |
begin |
| 9370 |
BT := Base_Type (T); |
| 9371 |
|
| 9372 |
if Is_Private_Type (BT) |
| 9373 |
and then Present (Full_View (BT)) |
| 9374 |
then |
| 9375 |
BT := Full_View (BT); |
| 9376 |
end if; |
| 9377 |
|
| 9378 |
return BT; |
| 9379 |
end Full_Base; |
| 9380 |
|
| 9381 |
------------------------------- |
| 9382 |
-- Get_Stream_Convert_Pragma -- |
| 9383 |
------------------------------- |
| 9384 |
|
| 9385 |
function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id is |
| 9386 |
Typ : Entity_Id; |
| 9387 |
N : Node_Id; |
| 9388 |
|
| 9389 |
begin |
| 9390 |
-- Note: we cannot use Get_Rep_Pragma here because of the peculiarity |
| 9391 |
-- that a stream convert pragma for a tagged type is not inherited from |
| 9392 |
-- its parent. Probably what is wrong here is that it is basically |
| 9393 |
-- incorrect to consider a stream convert pragma to be a representation |
| 9394 |
-- pragma at all ??? |
| 9395 |
|
| 9396 |
N := First_Rep_Item (Implementation_Base_Type (T)); |
| 9397 |
while Present (N) loop |
| 9398 |
if Nkind (N) = N_Pragma |
| 9399 |
and then Pragma_Name (N) = Name_Stream_Convert |
| 9400 |
then |
| 9401 |
-- For tagged types this pragma is not inherited, so we |
| 9402 |
-- must verify that it is defined for the given type and |
| 9403 |
-- not an ancestor. |
| 9404 |
|
| 9405 |
Typ := |
| 9406 |
Entity (Expression (First (Pragma_Argument_Associations (N)))); |
| 9407 |
|
| 9408 |
if not Is_Tagged_Type (T) |
| 9409 |
or else T = Typ |
| 9410 |
or else (Is_Private_Type (Typ) and then T = Full_View (Typ)) |
| 9411 |
then |
| 9412 |
return N; |
| 9413 |
end if; |
| 9414 |
end if; |
| 9415 |
|
| 9416 |
Next_Rep_Item (N); |
| 9417 |
end loop; |
| 9418 |
|
| 9419 |
return Empty; |
| 9420 |
end Get_Stream_Convert_Pragma; |
| 9421 |
|
| 9422 |
--------------------------------- |
| 9423 |
-- Is_Constrained_Packed_Array -- |
| 9424 |
--------------------------------- |
| 9425 |
|
| 9426 |
function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean is |
| 9427 |
Arr : Entity_Id := Typ; |
| 9428 |
|
| 9429 |
begin |
| 9430 |
if Is_Access_Type (Arr) then |
| 9431 |
Arr := Designated_Type (Arr); |
| 9432 |
end if; |
| 9433 |
|
| 9434 |
return Is_Array_Type (Arr) |
| 9435 |
and then Is_Constrained (Arr) |
| 9436 |
and then Present (Packed_Array_Impl_Type (Arr)); |
| 9437 |
end Is_Constrained_Packed_Array; |
| 9438 |
|
| 9439 |
---------------------------------------- |
| 9440 |
-- Is_Inline_Floating_Point_Attribute -- |
| 9441 |
---------------------------------------- |
| 9442 |
|
| 9443 |
function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean is |
| 9444 |
Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N)); |
| 9445 |
|
| 9446 |
function Is_GCC_Target return Boolean; |
| 9447 |
-- Return True if we are using a GCC target/back-end |
| 9448 |
-- ??? Note: the implementation is kludgy/fragile |
| 9449 |
|
| 9450 |
------------------- |
| 9451 |
-- Is_GCC_Target -- |
| 9452 |
------------------- |
| 9453 |
|
| 9454 |
function Is_GCC_Target return Boolean is |
| 9455 |
begin |
| 9456 |
return not CodePeer_Mode; |
| 9457 |
end Is_GCC_Target; |
| 9458 |
|
| 9459 |
-- Start of processing for Is_Inline_Floating_Point_Attribute |
| 9460 |
|
| 9461 |
begin |
| 9462 |
-- Machine and Model can be expanded by the GCC back end only |
| 9463 |
|
| 9464 |
if Id = Attribute_Machine or else Id = Attribute_Model then |
| 9465 |
return Is_GCC_Target; |
| 9466 |
|
| 9467 |
-- Remaining cases handled by all back ends are Rounding and Truncation |
| 9468 |
-- when appearing as the operand of a conversion to some integer type. |
| 9469 |
|
| 9470 |
elsif Nkind (Parent (N)) /= N_Type_Conversion |
| 9471 |
or else not Is_Integer_Type (Etype (Parent (N))) |
| 9472 |
then |
| 9473 |
return False; |
| 9474 |
end if; |
| 9475 |
|
| 9476 |
-- Here we are in the integer conversion context. We reuse Rounding for |
| 9477 |
-- Machine_Rounding as System.Fat_Gen, which is a permissible behavior. |
| 9478 |
|
| 9479 |
return |
| 9480 |
Id = Attribute_Rounding |
| 9481 |
or else Id = Attribute_Machine_Rounding |
| 9482 |
or else Id = Attribute_Truncation; |
| 9483 |
end Is_Inline_Floating_Point_Attribute; |
| 9484 |
|
| 9485 |
-------------------------------------- |
| 9486 |
-- Is_User_Defined_Enumeration_Type -- |
| 9487 |
-------------------------------------- |
| 9488 |
|
| 9489 |
function Is_User_Defined_Enumeration_Type (Typ : Entity_Id) return Boolean |
| 9490 |
is |
| 9491 |
Rtyp : constant Entity_Id := Root_Type (Base_Type (Typ)); |
| 9492 |
|
| 9493 |
begin |
| 9494 |
return Is_Enumeration_Type (Rtyp) |
| 9495 |
and then Rtyp not in Standard_Boolean |
| 9496 |
| Standard_Character |
| 9497 |
| Standard_Wide_Character |
| 9498 |
| Standard_Wide_Wide_Character; |
| 9499 |
end Is_User_Defined_Enumeration_Type; |
| 9500 |
|
| 9501 |
end Exp_Attr; |