| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ U T I L -- |
| 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 Casing; use Casing; |
| 28 |
with Checks; use Checks; |
| 29 |
with Debug; use Debug; |
| 30 |
with Einfo.Utils; use Einfo.Utils; |
| 31 |
with Elists; use Elists; |
| 32 |
with Errout; use Errout; |
| 33 |
with Exp_Ch6; use Exp_Ch6; |
| 34 |
with Exp_Ch11; use Exp_Ch11; |
| 35 |
with Exp_Util; use Exp_Util; |
| 36 |
with Fname; use Fname; |
| 37 |
with Freeze; use Freeze; |
| 38 |
with Itypes; use Itypes; |
| 39 |
with Lib; use Lib; |
| 40 |
with Lib.Xref; use Lib.Xref; |
| 41 |
with Mutably_Tagged; use Mutably_Tagged; |
| 42 |
with Namet.Sp; use Namet.Sp; |
| 43 |
with Nlists; use Nlists; |
| 44 |
with Nmake; use Nmake; |
| 45 |
with Output; use Output; |
| 46 |
with Restrict; use Restrict; |
| 47 |
with Rident; use Rident; |
| 48 |
with Rtsfind; use Rtsfind; |
| 49 |
with Sem; use Sem; |
| 50 |
with Sem_Aux; use Sem_Aux; |
| 51 |
with Sem_Attr; use Sem_Attr; |
| 52 |
with Sem_Cat; use Sem_Cat; |
| 53 |
with Sem_Ch6; use Sem_Ch6; |
| 54 |
with Sem_Ch8; use Sem_Ch8; |
| 55 |
with Sem_Ch13; use Sem_Ch13; |
| 56 |
with Sem_Dim; use Sem_Dim; |
| 57 |
with Sem_Disp; use Sem_Disp; |
| 58 |
with Sem_Elab; use Sem_Elab; |
| 59 |
with Sem_Eval; use Sem_Eval; |
| 60 |
with Sem_Prag; use Sem_Prag; |
| 61 |
with Sem_Res; use Sem_Res; |
| 62 |
with Sem_Warn; use Sem_Warn; |
| 63 |
with Sem_Type; use Sem_Type; |
| 64 |
with Sinfo; use Sinfo; |
| 65 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 66 |
with Sinfo.Utils; use Sinfo.Utils; |
| 67 |
with Sinput; use Sinput; |
| 68 |
with Stand; use Stand; |
| 69 |
with Style; |
| 70 |
with Stringt; use Stringt; |
| 71 |
with Targparm; use Targparm; |
| 72 |
with Tbuild; use Tbuild; |
| 73 |
with Ttypes; use Ttypes; |
| 74 |
with Uname; use Uname; |
| 75 |
with Warnsw; use Warnsw; |
| 76 |
|
| 77 |
with GNAT.Heap_Sort_G; |
| 78 |
with GNAT.HTable; use GNAT.HTable; |
| 79 |
|
| 80 |
package body Sem_Util is |
| 81 |
|
| 82 |
--------------------------- |
| 83 |
-- Local Data Structures -- |
| 84 |
--------------------------- |
| 85 |
|
| 86 |
Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty); |
| 87 |
-- A collection to hold the entities of the variables declared in package |
| 88 |
-- System.Scalar_Values which describe the invalid values of scalar types. |
| 89 |
|
| 90 |
Invalid_Binder_Values_Set : Boolean := False; |
| 91 |
-- This flag prevents multiple attempts to initialize Invalid_Binder_Values |
| 92 |
|
| 93 |
Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal); |
| 94 |
-- A collection to hold the invalid values of float types as specified by |
| 95 |
-- pragma Initialize_Scalars. |
| 96 |
|
| 97 |
Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint); |
| 98 |
-- A collection to hold the invalid values of integer types as specified |
| 99 |
-- by pragma Initialize_Scalars. |
| 100 |
|
| 101 |
----------------------- |
| 102 |
-- Local Subprograms -- |
| 103 |
----------------------- |
| 104 |
|
| 105 |
function Build_Component_Subtype |
| 106 |
(C : List_Id; |
| 107 |
Loc : Source_Ptr; |
| 108 |
T : Entity_Id) return Node_Id; |
| 109 |
-- This function builds the subtype for Build_Actual_Subtype_Of_Component |
| 110 |
-- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints, |
| 111 |
-- Loc is the source location, T is the original subtype. |
| 112 |
|
| 113 |
procedure Examine_Array_Bounds |
| 114 |
(Typ : Entity_Id; |
| 115 |
All_Static : out Boolean; |
| 116 |
Has_Empty : out Boolean); |
| 117 |
-- Inspect the index constraints of array type Typ. Flag All_Static is set |
| 118 |
-- when all ranges are static. Flag Has_Empty is set only when All_Static |
| 119 |
-- is set and indicates that at least one range is empty. |
| 120 |
|
| 121 |
function Has_Enabled_Property |
| 122 |
(Item_Id : Entity_Id; |
| 123 |
Property : Name_Id) return Boolean; |
| 124 |
-- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled. |
| 125 |
-- Determine whether the state abstraction, object, or type denoted by |
| 126 |
-- entity Item_Id has enabled property Property. |
| 127 |
|
| 128 |
function Has_Null_Extension (T : Entity_Id) return Boolean; |
| 129 |
-- T is a derived tagged type. Check whether the type extension is null. |
| 130 |
-- If the parent type is fully initialized, T can be treated as such. |
| 131 |
|
| 132 |
function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean; |
| 133 |
-- Determine whether arbitrary entity Id denotes an atomic object as per |
| 134 |
-- RM C.6(7). |
| 135 |
|
| 136 |
generic |
| 137 |
with function Is_Effectively_Volatile_Entity |
| 138 |
(Id : Entity_Id) return Boolean; |
| 139 |
-- Function to use on object and type entities |
| 140 |
function Is_Effectively_Volatile_Object_Shared |
| 141 |
(N : Node_Id) return Boolean; |
| 142 |
-- Shared function used to detect effectively volatile objects and |
| 143 |
-- effectively volatile objects for reading. |
| 144 |
|
| 145 |
function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean; |
| 146 |
-- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type |
| 147 |
-- with discriminants whose default values are static, examine only the |
| 148 |
-- components in the selected variant to determine whether all of them |
| 149 |
-- have a default. |
| 150 |
|
| 151 |
function Is_Preelaborable_Function (Id : Entity_Id) return Boolean; |
| 152 |
-- Ada 2022: Determine whether the specified function is suitable as the |
| 153 |
-- name of a call in a preelaborable construct (RM 10.2.1(7/5)). |
| 154 |
|
| 155 |
type Null_Status_Kind is |
| 156 |
(Is_Null, |
| 157 |
-- This value indicates that a subexpression is known to have a null |
| 158 |
-- value at compile time. |
| 159 |
|
| 160 |
Is_Non_Null, |
| 161 |
-- This value indicates that a subexpression is known to have a non-null |
| 162 |
-- value at compile time. |
| 163 |
|
| 164 |
Unknown); |
| 165 |
-- This value indicates that it cannot be determined at compile time |
| 166 |
-- whether a subexpression yields a null or non-null value. |
| 167 |
|
| 168 |
function Null_Status (N : Node_Id) return Null_Status_Kind; |
| 169 |
-- Determine whether subexpression N of an access type yields a null value, |
| 170 |
-- a non-null value, or the value cannot be determined at compile time. The |
| 171 |
-- routine does not take simple flow diagnostics into account, it relies on |
| 172 |
-- static facts such as the presence of null exclusions. |
| 173 |
|
| 174 |
----------------------------- |
| 175 |
-- Abstract_Interface_List -- |
| 176 |
----------------------------- |
| 177 |
|
| 178 |
function Abstract_Interface_List (Typ : Entity_Id) return List_Id is |
| 179 |
Nod : Node_Id; |
| 180 |
|
| 181 |
begin |
| 182 |
if Is_Concurrent_Type (Typ) then |
| 183 |
|
| 184 |
-- If we are dealing with a synchronized subtype, go to the base |
| 185 |
-- type, whose declaration has the interface list. |
| 186 |
|
| 187 |
Nod := Declaration_Node (Base_Type (Typ)); |
| 188 |
|
| 189 |
if Nkind (Nod) in N_Full_Type_Declaration | N_Private_Type_Declaration |
| 190 |
then |
| 191 |
return Empty_List; |
| 192 |
end if; |
| 193 |
|
| 194 |
elsif Ekind (Typ) = E_Record_Type_With_Private then |
| 195 |
if Nkind (Parent (Typ)) = N_Full_Type_Declaration then |
| 196 |
Nod := Type_Definition (Parent (Typ)); |
| 197 |
|
| 198 |
elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then |
| 199 |
if Present (Full_View (Typ)) |
| 200 |
and then |
| 201 |
Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration |
| 202 |
then |
| 203 |
Nod := Type_Definition (Parent (Full_View (Typ))); |
| 204 |
|
| 205 |
-- If the full-view is not available we cannot do anything else |
| 206 |
-- here (the source has errors). |
| 207 |
|
| 208 |
else |
| 209 |
return Empty_List; |
| 210 |
end if; |
| 211 |
|
| 212 |
-- Support for generic formals with interfaces is still missing ??? |
| 213 |
|
| 214 |
elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then |
| 215 |
return Empty_List; |
| 216 |
|
| 217 |
else |
| 218 |
pragma Assert |
| 219 |
(Nkind (Parent (Typ)) = N_Private_Extension_Declaration); |
| 220 |
Nod := Parent (Typ); |
| 221 |
end if; |
| 222 |
|
| 223 |
elsif Ekind (Typ) = E_Record_Subtype then |
| 224 |
Nod := Type_Definition (Parent (Etype (Typ))); |
| 225 |
|
| 226 |
elsif Ekind (Typ) = E_Record_Subtype_With_Private then |
| 227 |
|
| 228 |
-- Recurse, because parent may still be a private extension. Also |
| 229 |
-- note that the full view of the subtype or the full view of its |
| 230 |
-- base type may (both) be unavailable. |
| 231 |
|
| 232 |
return Abstract_Interface_List (Etype (Typ)); |
| 233 |
|
| 234 |
elsif Ekind (Typ) = E_Record_Type then |
| 235 |
if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then |
| 236 |
Nod := Formal_Type_Definition (Parent (Typ)); |
| 237 |
else |
| 238 |
Nod := Type_Definition (Parent (Typ)); |
| 239 |
end if; |
| 240 |
|
| 241 |
-- Otherwise the type is of a kind which does not implement interfaces |
| 242 |
|
| 243 |
else |
| 244 |
return Empty_List; |
| 245 |
end if; |
| 246 |
|
| 247 |
return Interface_List (Nod); |
| 248 |
end Abstract_Interface_List; |
| 249 |
|
| 250 |
---------------------------------- |
| 251 |
-- Acquire_Warning_Match_String -- |
| 252 |
---------------------------------- |
| 253 |
|
| 254 |
function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is |
| 255 |
S : constant String := To_String (Strval (Str_Lit)); |
| 256 |
begin |
| 257 |
if S = "" then |
| 258 |
return ""; |
| 259 |
else |
| 260 |
-- Put "*" before or after or both, if it's not already there |
| 261 |
|
| 262 |
declare |
| 263 |
F : constant Boolean := S (S'First) = '*'; |
| 264 |
L : constant Boolean := S (S'Last) = '*'; |
| 265 |
begin |
| 266 |
if F then |
| 267 |
if L then |
| 268 |
return S; |
| 269 |
else |
| 270 |
return S & "*"; |
| 271 |
end if; |
| 272 |
else |
| 273 |
if L then |
| 274 |
return "*" & S; |
| 275 |
else |
| 276 |
return "*" & S & "*"; |
| 277 |
end if; |
| 278 |
end if; |
| 279 |
end; |
| 280 |
end if; |
| 281 |
end Acquire_Warning_Match_String; |
| 282 |
|
| 283 |
-------------------------------- |
| 284 |
-- Add_Access_Type_To_Process -- |
| 285 |
-------------------------------- |
| 286 |
|
| 287 |
procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is |
| 288 |
L : Elist_Id; |
| 289 |
|
| 290 |
begin |
| 291 |
Ensure_Freeze_Node (E); |
| 292 |
L := Access_Types_To_Process (Freeze_Node (E)); |
| 293 |
|
| 294 |
if No (L) then |
| 295 |
L := New_Elmt_List; |
| 296 |
Set_Access_Types_To_Process (Freeze_Node (E), L); |
| 297 |
end if; |
| 298 |
|
| 299 |
Append_Elmt (A, L); |
| 300 |
end Add_Access_Type_To_Process; |
| 301 |
|
| 302 |
-------------------------- |
| 303 |
-- Add_Block_Identifier -- |
| 304 |
-------------------------- |
| 305 |
|
| 306 |
procedure Add_Block_Identifier |
| 307 |
(N : Node_Id; |
| 308 |
Id : out Entity_Id; |
| 309 |
Scope : Entity_Id := Current_Scope) |
| 310 |
is |
| 311 |
Loc : constant Source_Ptr := Sloc (N); |
| 312 |
|
| 313 |
begin |
| 314 |
pragma Assert (Nkind (N) = N_Block_Statement); |
| 315 |
|
| 316 |
-- The block already has a label, return its entity |
| 317 |
|
| 318 |
if Present (Identifier (N)) then |
| 319 |
Id := Entity (Identifier (N)); |
| 320 |
|
| 321 |
-- Create a new block label and set its attributes |
| 322 |
|
| 323 |
else |
| 324 |
Id := New_Internal_Entity (E_Block, Scope, Loc, 'B'); |
| 325 |
Set_Etype (Id, Standard_Void_Type); |
| 326 |
Set_Parent (Id, N); |
| 327 |
Set_Identifier (N, New_Occurrence_Of (Id, Loc)); |
| 328 |
Set_Block_Node (Id, Identifier (N)); |
| 329 |
end if; |
| 330 |
end Add_Block_Identifier; |
| 331 |
|
| 332 |
---------------------------- |
| 333 |
-- Add_Global_Declaration -- |
| 334 |
---------------------------- |
| 335 |
|
| 336 |
procedure Add_Global_Declaration (N : Node_Id) is |
| 337 |
Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit)); |
| 338 |
|
| 339 |
begin |
| 340 |
if No (Declarations (Aux_Node)) then |
| 341 |
Set_Declarations (Aux_Node, New_List); |
| 342 |
end if; |
| 343 |
|
| 344 |
Append_To (Declarations (Aux_Node), N); |
| 345 |
Analyze (N); |
| 346 |
end Add_Global_Declaration; |
| 347 |
|
| 348 |
-------------------------------- |
| 349 |
-- Address_Integer_Convert_OK -- |
| 350 |
-------------------------------- |
| 351 |
|
| 352 |
function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is |
| 353 |
begin |
| 354 |
if Allow_Integer_Address |
| 355 |
and then ((Is_Descendant_Of_Address (T1) |
| 356 |
and then Is_Private_Type (T1) |
| 357 |
and then Is_Integer_Type (T2)) |
| 358 |
or else |
| 359 |
(Is_Descendant_Of_Address (T2) |
| 360 |
and then Is_Private_Type (T2) |
| 361 |
and then Is_Integer_Type (T1))) |
| 362 |
then |
| 363 |
return True; |
| 364 |
else |
| 365 |
return False; |
| 366 |
end if; |
| 367 |
end Address_Integer_Convert_OK; |
| 368 |
|
| 369 |
------------------- |
| 370 |
-- Address_Value -- |
| 371 |
------------------- |
| 372 |
|
| 373 |
function Address_Value (N : Node_Id) return Node_Id is |
| 374 |
Expr : Node_Id := N; |
| 375 |
|
| 376 |
begin |
| 377 |
loop |
| 378 |
-- For constant, get constant expression |
| 379 |
|
| 380 |
if Is_Entity_Name (Expr) |
| 381 |
and then Ekind (Entity (Expr)) = E_Constant |
| 382 |
then |
| 383 |
Expr := Constant_Value (Entity (Expr)); |
| 384 |
|
| 385 |
-- For unchecked conversion, get result to convert |
| 386 |
|
| 387 |
elsif Nkind (Expr) = N_Unchecked_Type_Conversion then |
| 388 |
Expr := Expression (Expr); |
| 389 |
|
| 390 |
-- For (common case) of To_Address call, get argument |
| 391 |
|
| 392 |
elsif Nkind (Expr) = N_Function_Call |
| 393 |
and then Is_Entity_Name (Name (Expr)) |
| 394 |
and then Is_RTE (Entity (Name (Expr)), RE_To_Address) |
| 395 |
then |
| 396 |
Expr := First_Actual (Expr); |
| 397 |
|
| 398 |
-- We finally have the real expression |
| 399 |
|
| 400 |
else |
| 401 |
exit; |
| 402 |
end if; |
| 403 |
end loop; |
| 404 |
|
| 405 |
return Expr; |
| 406 |
end Address_Value; |
| 407 |
|
| 408 |
----------------- |
| 409 |
-- Addressable -- |
| 410 |
----------------- |
| 411 |
|
| 412 |
function Addressable (V : Uint) return Boolean is |
| 413 |
begin |
| 414 |
if No (V) then |
| 415 |
return False; |
| 416 |
end if; |
| 417 |
|
| 418 |
return V = Uint_8 or else |
| 419 |
V = Uint_16 or else |
| 420 |
V = Uint_32 or else |
| 421 |
V = Uint_64 or else |
| 422 |
(V = Uint_128 and then System_Max_Integer_Size = 128); |
| 423 |
end Addressable; |
| 424 |
|
| 425 |
function Addressable (V : Int) return Boolean is |
| 426 |
begin |
| 427 |
return V = 8 or else |
| 428 |
V = 16 or else |
| 429 |
V = 32 or else |
| 430 |
V = 64 or else |
| 431 |
V = System_Max_Integer_Size; |
| 432 |
end Addressable; |
| 433 |
|
| 434 |
--------------------------------- |
| 435 |
-- Aggregate_Constraint_Checks -- |
| 436 |
--------------------------------- |
| 437 |
|
| 438 |
procedure Aggregate_Constraint_Checks |
| 439 |
(Exp : Node_Id; |
| 440 |
Check_Typ : Entity_Id) |
| 441 |
is |
| 442 |
Exp_Typ : constant Entity_Id := Etype (Exp); |
| 443 |
|
| 444 |
begin |
| 445 |
if Raises_Constraint_Error (Exp) then |
| 446 |
return; |
| 447 |
end if; |
| 448 |
|
| 449 |
-- Ada 2005 (AI-230): Generate a conversion to an anonymous access |
| 450 |
-- component's type to force the appropriate accessibility checks. |
| 451 |
|
| 452 |
-- Ada 2005 (AI-231): Generate conversion to the null-excluding type to |
| 453 |
-- force the corresponding run-time check |
| 454 |
|
| 455 |
if Is_Access_Type (Check_Typ) |
| 456 |
and then Is_Local_Anonymous_Access (Check_Typ) |
| 457 |
then |
| 458 |
Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); |
| 459 |
Analyze_And_Resolve (Exp, Check_Typ); |
| 460 |
Check_Unset_Reference (Exp); |
| 461 |
end if; |
| 462 |
|
| 463 |
-- What follows is really expansion activity, so check that expansion |
| 464 |
-- is on and is allowed. In GNATprove mode, we also want check flags to |
| 465 |
-- be added in the tree, so that the formal verification can rely on |
| 466 |
-- those to be present. In GNATprove mode for formal verification, some |
| 467 |
-- treatment typically only done during expansion needs to be performed |
| 468 |
-- on the tree, but it should not be applied inside generics. Otherwise, |
| 469 |
-- this breaks the name resolution mechanism for generic instances. |
| 470 |
|
| 471 |
if not Expander_Active |
| 472 |
and not (GNATprove_Mode and not Inside_A_Generic) |
| 473 |
then |
| 474 |
return; |
| 475 |
end if; |
| 476 |
|
| 477 |
if Is_Access_Type (Check_Typ) |
| 478 |
and then Can_Never_Be_Null (Check_Typ) |
| 479 |
and then not Can_Never_Be_Null (Exp_Typ) |
| 480 |
then |
| 481 |
Install_Null_Excluding_Check (Exp); |
| 482 |
end if; |
| 483 |
|
| 484 |
-- First check if we have to insert discriminant checks |
| 485 |
|
| 486 |
if Has_Discriminants (Exp_Typ) then |
| 487 |
Apply_Discriminant_Check (Exp, Check_Typ); |
| 488 |
|
| 489 |
-- Next emit length checks for array aggregates |
| 490 |
|
| 491 |
elsif Is_Array_Type (Exp_Typ) then |
| 492 |
Apply_Length_Check (Exp, Check_Typ); |
| 493 |
|
| 494 |
-- Finally emit scalar and string checks. If we are dealing with a |
| 495 |
-- scalar literal we need to check by hand because the Etype of |
| 496 |
-- literals is not necessarily correct. |
| 497 |
|
| 498 |
elsif Is_Scalar_Type (Exp_Typ) |
| 499 |
and then Compile_Time_Known_Value (Exp) |
| 500 |
then |
| 501 |
if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then |
| 502 |
Apply_Compile_Time_Constraint_Error |
| 503 |
(Exp, "value not in range of}??", CE_Range_Check_Failed, |
| 504 |
Ent => Base_Type (Check_Typ), |
| 505 |
Typ => Base_Type (Check_Typ)); |
| 506 |
|
| 507 |
elsif Is_Out_Of_Range (Exp, Check_Typ) then |
| 508 |
Apply_Compile_Time_Constraint_Error |
| 509 |
(Exp, "value not in range of}??", CE_Range_Check_Failed, |
| 510 |
Ent => Check_Typ, |
| 511 |
Typ => Check_Typ); |
| 512 |
|
| 513 |
elsif not Range_Checks_Suppressed (Check_Typ) then |
| 514 |
Apply_Scalar_Range_Check (Exp, Check_Typ); |
| 515 |
end if; |
| 516 |
|
| 517 |
-- Verify that target type is also scalar, to prevent view anomalies |
| 518 |
-- in instantiations. |
| 519 |
|
| 520 |
elsif (Is_Scalar_Type (Exp_Typ) |
| 521 |
or else Nkind (Exp) = N_String_Literal) |
| 522 |
and then Is_Scalar_Type (Check_Typ) |
| 523 |
and then Exp_Typ /= Check_Typ |
| 524 |
then |
| 525 |
-- If expression is a constant, it is worthwhile checking whether it |
| 526 |
-- is a bound of the type. |
| 527 |
|
| 528 |
if Is_Entity_Name (Exp) |
| 529 |
and then Ekind (Entity (Exp)) = E_Constant |
| 530 |
then |
| 531 |
if (Is_Entity_Name (Type_Low_Bound (Check_Typ)) |
| 532 |
and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ))) |
| 533 |
or else |
| 534 |
(Is_Entity_Name (Type_High_Bound (Check_Typ)) |
| 535 |
and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ))) |
| 536 |
then |
| 537 |
return; |
| 538 |
end if; |
| 539 |
end if; |
| 540 |
|
| 541 |
-- Change Exp into Check_Typ'(Exp) to ensure that range checks are |
| 542 |
-- performed at run time. |
| 543 |
|
| 544 |
Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); |
| 545 |
Analyze_And_Resolve (Exp, Check_Typ); |
| 546 |
Check_Unset_Reference (Exp); |
| 547 |
|
| 548 |
end if; |
| 549 |
end Aggregate_Constraint_Checks; |
| 550 |
|
| 551 |
----------------------- |
| 552 |
-- Alignment_In_Bits -- |
| 553 |
----------------------- |
| 554 |
|
| 555 |
function Alignment_In_Bits (E : Entity_Id) return Uint is |
| 556 |
begin |
| 557 |
return Alignment (E) * System_Storage_Unit; |
| 558 |
end Alignment_In_Bits; |
| 559 |
|
| 560 |
-------------------------------------- |
| 561 |
-- All_Composite_Constraints_Static -- |
| 562 |
-------------------------------------- |
| 563 |
|
| 564 |
function All_Composite_Constraints_Static |
| 565 |
(Constr : Node_Id) return Boolean |
| 566 |
is |
| 567 |
begin |
| 568 |
if No (Constr) or else Error_Posted (Constr) then |
| 569 |
return True; |
| 570 |
end if; |
| 571 |
|
| 572 |
case Nkind (Constr) is |
| 573 |
when N_Subexpr => |
| 574 |
if Nkind (Constr) in N_Has_Entity |
| 575 |
and then Present (Entity (Constr)) |
| 576 |
then |
| 577 |
if Is_Type (Entity (Constr)) then |
| 578 |
return |
| 579 |
not Is_Discrete_Type (Entity (Constr)) |
| 580 |
or else Is_OK_Static_Subtype (Entity (Constr)); |
| 581 |
end if; |
| 582 |
|
| 583 |
elsif Nkind (Constr) = N_Range then |
| 584 |
return |
| 585 |
Is_OK_Static_Expression (Low_Bound (Constr)) |
| 586 |
and then |
| 587 |
Is_OK_Static_Expression (High_Bound (Constr)); |
| 588 |
|
| 589 |
elsif Nkind (Constr) = N_Attribute_Reference |
| 590 |
and then Attribute_Name (Constr) = Name_Range |
| 591 |
then |
| 592 |
return |
| 593 |
Is_OK_Static_Expression |
| 594 |
(Type_Low_Bound (Etype (Prefix (Constr)))) |
| 595 |
and then |
| 596 |
Is_OK_Static_Expression |
| 597 |
(Type_High_Bound (Etype (Prefix (Constr)))); |
| 598 |
end if; |
| 599 |
|
| 600 |
return |
| 601 |
No (Etype (Constr)) -- previous error |
| 602 |
or else not Is_Discrete_Type (Etype (Constr)) |
| 603 |
or else Is_OK_Static_Expression (Constr); |
| 604 |
|
| 605 |
when N_Discriminant_Association => |
| 606 |
return All_Composite_Constraints_Static (Expression (Constr)); |
| 607 |
|
| 608 |
when N_Range_Constraint => |
| 609 |
return |
| 610 |
All_Composite_Constraints_Static (Range_Expression (Constr)); |
| 611 |
|
| 612 |
when N_Index_Or_Discriminant_Constraint => |
| 613 |
declare |
| 614 |
One_Cstr : Entity_Id; |
| 615 |
begin |
| 616 |
One_Cstr := First (Constraints (Constr)); |
| 617 |
while Present (One_Cstr) loop |
| 618 |
if not All_Composite_Constraints_Static (One_Cstr) then |
| 619 |
return False; |
| 620 |
end if; |
| 621 |
|
| 622 |
Next (One_Cstr); |
| 623 |
end loop; |
| 624 |
end; |
| 625 |
|
| 626 |
return True; |
| 627 |
|
| 628 |
when N_Subtype_Indication => |
| 629 |
return |
| 630 |
All_Composite_Constraints_Static (Subtype_Mark (Constr)) |
| 631 |
and then |
| 632 |
All_Composite_Constraints_Static (Constraint (Constr)); |
| 633 |
|
| 634 |
when others => |
| 635 |
raise Program_Error; |
| 636 |
end case; |
| 637 |
end All_Composite_Constraints_Static; |
| 638 |
|
| 639 |
------------------------ |
| 640 |
-- Append_Entity_Name -- |
| 641 |
------------------------ |
| 642 |
|
| 643 |
procedure Append_Entity_Name |
| 644 |
(Buf : in out Bounded_String; E : Entity_Id) |
| 645 |
is |
| 646 |
Scop : constant Node_Id := Scope (E); |
| 647 |
-- We recursively print the scope to Buf, and then print the simple |
| 648 |
-- name, along with some special cases (see below). So for A.B.C.D, |
| 649 |
-- recursively print A.B.C, then print D. |
| 650 |
begin |
| 651 |
-- If E is not a source entity, then skip the simple name and just |
| 652 |
-- recursively print its scope. However, certain entities have |
| 653 |
-- Comes_From_Source = False, even though we DO want to print the |
| 654 |
-- simple name; this happens for specless child subprogram bodies |
| 655 |
-- and for subprogram instances. |
| 656 |
|
| 657 |
if not Comes_From_Source (E) then |
| 658 |
if Is_Compilation_Unit (E) then |
| 659 |
null; |
| 660 |
elsif Is_Generic_Instance (E) |
| 661 |
and then Ekind (E) in E_Function | E_Procedure |
| 662 |
then |
| 663 |
null; |
| 664 |
else |
| 665 |
Append_Entity_Name (Buf, Scope (E)); |
| 666 |
return; -- skip the simple name |
| 667 |
end if; |
| 668 |
end if; |
| 669 |
|
| 670 |
-- Just print entity name if its scope is at the outer level |
| 671 |
|
| 672 |
if No (Scop) or Scop = Standard_Standard then |
| 673 |
null; |
| 674 |
|
| 675 |
-- If scope comes from source, write scope and entity |
| 676 |
|
| 677 |
elsif Comes_From_Source (Scop) then |
| 678 |
Append_Entity_Name (Buf, Scop); |
| 679 |
Append (Buf, '.'); |
| 680 |
|
| 681 |
-- Otherwise (non-source scope) skip one level |
| 682 |
|
| 683 |
else |
| 684 |
Append_Entity_Name (Buf, Scope (Scop)); |
| 685 |
Append (Buf, '.'); |
| 686 |
end if; |
| 687 |
|
| 688 |
-- Print the simple name |
| 689 |
|
| 690 |
declare |
| 691 |
E_Name : Bounded_String; |
| 692 |
begin |
| 693 |
Append_Unqualified_Decoded (E_Name, Chars (E)); |
| 694 |
|
| 695 |
-- Remove trailing upper-case letters from the name (useful for |
| 696 |
-- dealing with some cases of internal names generated in the case |
| 697 |
-- of references from within a generic). |
| 698 |
|
| 699 |
while E_Name.Length > 1 |
| 700 |
and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z' |
| 701 |
loop |
| 702 |
E_Name.Length := E_Name.Length - 1; |
| 703 |
end loop; |
| 704 |
|
| 705 |
-- Adjust casing appropriately (gets name from source if possible) |
| 706 |
|
| 707 |
Adjust_Name_Case (E_Name, Sloc (E)); |
| 708 |
Append (Buf, E_Name); |
| 709 |
end; |
| 710 |
end Append_Entity_Name; |
| 711 |
|
| 712 |
--------------------------------- |
| 713 |
-- Append_Inherited_Subprogram -- |
| 714 |
--------------------------------- |
| 715 |
|
| 716 |
procedure Append_Inherited_Subprogram (S : Entity_Id) is |
| 717 |
Par : constant Entity_Id := Alias (S); |
| 718 |
-- The parent subprogram |
| 719 |
|
| 720 |
Scop : constant Entity_Id := Scope (Par); |
| 721 |
-- The scope of definition of the parent subprogram |
| 722 |
|
| 723 |
Typ : constant Entity_Id := Defining_Entity (Parent (S)); |
| 724 |
-- The derived type of which S is a primitive operation |
| 725 |
|
| 726 |
Decl : Node_Id; |
| 727 |
Next_E : Entity_Id; |
| 728 |
|
| 729 |
begin |
| 730 |
if Ekind (Current_Scope) = E_Package |
| 731 |
and then In_Private_Part (Current_Scope) |
| 732 |
and then Has_Private_Declaration (Typ) |
| 733 |
and then Is_Tagged_Type (Typ) |
| 734 |
and then Scop = Current_Scope |
| 735 |
then |
| 736 |
-- The inherited operation is available at the earliest place after |
| 737 |
-- the derived type declaration (RM 7.3.1 (6/1)). This is only |
| 738 |
-- relevant for type extensions. If the parent operation appears |
| 739 |
-- after the type extension, the operation is not visible. |
| 740 |
|
| 741 |
Decl := First |
| 742 |
(Visible_Declarations |
| 743 |
(Package_Specification (Current_Scope))); |
| 744 |
while Present (Decl) loop |
| 745 |
if Nkind (Decl) = N_Private_Extension_Declaration |
| 746 |
and then Defining_Entity (Decl) = Typ |
| 747 |
then |
| 748 |
if Sloc (Decl) > Sloc (Par) then |
| 749 |
Next_E := Next_Entity (Par); |
| 750 |
Link_Entities (Par, S); |
| 751 |
Link_Entities (S, Next_E); |
| 752 |
return; |
| 753 |
|
| 754 |
else |
| 755 |
exit; |
| 756 |
end if; |
| 757 |
end if; |
| 758 |
|
| 759 |
Next (Decl); |
| 760 |
end loop; |
| 761 |
end if; |
| 762 |
|
| 763 |
-- If partial view is not a type extension, or it appears before the |
| 764 |
-- subprogram declaration, insert normally at end of entity list. |
| 765 |
|
| 766 |
Append_Entity (S, Current_Scope); |
| 767 |
end Append_Inherited_Subprogram; |
| 768 |
|
| 769 |
----------------------------------------- |
| 770 |
-- Apply_Compile_Time_Constraint_Error -- |
| 771 |
----------------------------------------- |
| 772 |
|
| 773 |
procedure Apply_Compile_Time_Constraint_Error |
| 774 |
(N : Node_Id; |
| 775 |
Msg : String; |
| 776 |
Reason : RT_Exception_Code; |
| 777 |
Ent : Entity_Id := Empty; |
| 778 |
Typ : Entity_Id := Empty; |
| 779 |
Loc : Source_Ptr := No_Location; |
| 780 |
Warn : Boolean := False; |
| 781 |
Emit_Message : Boolean := True) |
| 782 |
is |
| 783 |
Stat : constant Boolean := Is_Static_Expression (N); |
| 784 |
R_Stat : constant Node_Id := |
| 785 |
Make_Raise_Constraint_Error (Sloc (N), Reason => Reason); |
| 786 |
Rtyp : Entity_Id; |
| 787 |
|
| 788 |
begin |
| 789 |
if No (Typ) then |
| 790 |
Rtyp := Etype (N); |
| 791 |
else |
| 792 |
Rtyp := Typ; |
| 793 |
end if; |
| 794 |
|
| 795 |
if Emit_Message then |
| 796 |
Discard_Node |
| 797 |
(Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn)); |
| 798 |
end if; |
| 799 |
|
| 800 |
-- Now we replace the node by an N_Raise_Constraint_Error node |
| 801 |
-- This does not need reanalyzing, so set it as analyzed now. |
| 802 |
|
| 803 |
Rewrite (N, R_Stat); |
| 804 |
Set_Analyzed (N, True); |
| 805 |
|
| 806 |
Set_Etype (N, Rtyp); |
| 807 |
Set_Raises_Constraint_Error (N); |
| 808 |
|
| 809 |
-- Now deal with possible local raise handling |
| 810 |
|
| 811 |
Possible_Local_Raise (N, Standard_Constraint_Error); |
| 812 |
|
| 813 |
-- If the original expression was marked as static, the result is |
| 814 |
-- still marked as static, but the Raises_Constraint_Error flag is |
| 815 |
-- always set so that further static evaluation is not attempted. |
| 816 |
|
| 817 |
if Stat then |
| 818 |
Set_Is_Static_Expression (N); |
| 819 |
end if; |
| 820 |
end Apply_Compile_Time_Constraint_Error; |
| 821 |
|
| 822 |
--------------------------- |
| 823 |
-- Async_Readers_Enabled -- |
| 824 |
--------------------------- |
| 825 |
|
| 826 |
function Async_Readers_Enabled (Id : Entity_Id) return Boolean is |
| 827 |
begin |
| 828 |
return Has_Enabled_Property (Id, Name_Async_Readers); |
| 829 |
end Async_Readers_Enabled; |
| 830 |
|
| 831 |
--------------------------- |
| 832 |
-- Async_Writers_Enabled -- |
| 833 |
--------------------------- |
| 834 |
|
| 835 |
function Async_Writers_Enabled (Id : Entity_Id) return Boolean is |
| 836 |
begin |
| 837 |
return Has_Enabled_Property (Id, Name_Async_Writers); |
| 838 |
end Async_Writers_Enabled; |
| 839 |
|
| 840 |
-------------------------------------- |
| 841 |
-- Available_Full_View_Of_Component -- |
| 842 |
-------------------------------------- |
| 843 |
|
| 844 |
function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is |
| 845 |
ST : constant Entity_Id := Scope (T); |
| 846 |
SCT : constant Entity_Id := Scope (Component_Type (T)); |
| 847 |
begin |
| 848 |
return In_Open_Scopes (ST) |
| 849 |
and then In_Open_Scopes (SCT) |
| 850 |
and then Scope_Depth (ST) >= Scope_Depth (SCT); |
| 851 |
end Available_Full_View_Of_Component; |
| 852 |
|
| 853 |
---------------- |
| 854 |
-- Bad_Aspect -- |
| 855 |
---------------- |
| 856 |
|
| 857 |
procedure Bad_Aspect |
| 858 |
(N : Node_Id; |
| 859 |
Nam : Name_Id; |
| 860 |
Warn : Boolean := False) |
| 861 |
is |
| 862 |
begin |
| 863 |
Error_Msg_Warn := Warn; |
| 864 |
Error_Msg_N ("<<& is not a valid aspect identifier", N); |
| 865 |
|
| 866 |
-- Check bad spelling |
| 867 |
Error_Msg_Name_1 := Aspect_Spell_Check (Nam); |
| 868 |
if Error_Msg_Name_1 /= No_Name then |
| 869 |
Error_Msg_N -- CODEFIX |
| 870 |
("\<<possible misspelling of %", N); |
| 871 |
end if; |
| 872 |
end Bad_Aspect; |
| 873 |
|
| 874 |
------------------- |
| 875 |
-- Bad_Attribute -- |
| 876 |
------------------- |
| 877 |
|
| 878 |
procedure Bad_Attribute |
| 879 |
(N : Node_Id; |
| 880 |
Nam : Name_Id; |
| 881 |
Warn : Boolean := False) |
| 882 |
is |
| 883 |
begin |
| 884 |
Error_Msg_Warn := Warn; |
| 885 |
Error_Msg_N ("<<unrecognized attribute&", N); |
| 886 |
|
| 887 |
-- Check for possible misspelling |
| 888 |
|
| 889 |
Error_Msg_Name_1 := Attribute_Spell_Check (Nam); |
| 890 |
if Error_Msg_Name_1 /= No_Name then |
| 891 |
Error_Msg_N -- CODEFIX |
| 892 |
("\<<possible misspelling of %", N); |
| 893 |
end if; |
| 894 |
end Bad_Attribute; |
| 895 |
|
| 896 |
-------------------------------- |
| 897 |
-- Bad_Predicated_Subtype_Use -- |
| 898 |
-------------------------------- |
| 899 |
|
| 900 |
procedure Bad_Predicated_Subtype_Use |
| 901 |
(Msg : String; |
| 902 |
N : Node_Id; |
| 903 |
Typ : Entity_Id; |
| 904 |
Suggest_Static : Boolean := False) |
| 905 |
is |
| 906 |
Gen : Entity_Id; |
| 907 |
|
| 908 |
begin |
| 909 |
-- Avoid cascaded errors |
| 910 |
|
| 911 |
if Error_Posted (N) then |
| 912 |
return; |
| 913 |
end if; |
| 914 |
|
| 915 |
if Inside_A_Generic then |
| 916 |
Gen := Current_Scope; |
| 917 |
while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop |
| 918 |
Gen := Scope (Gen); |
| 919 |
end loop; |
| 920 |
|
| 921 |
if No (Gen) then |
| 922 |
return; |
| 923 |
end if; |
| 924 |
|
| 925 |
if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then |
| 926 |
Set_No_Predicate_On_Actual (Typ); |
| 927 |
end if; |
| 928 |
|
| 929 |
elsif Has_Predicates (Typ) then |
| 930 |
if Is_Generic_Actual_Type (Typ) then |
| 931 |
|
| 932 |
-- The restriction on loop parameters is only that the type |
| 933 |
-- should only have static predicates. |
| 934 |
|
| 935 |
if Nkind (Parent (N)) = N_Loop_Parameter_Specification |
| 936 |
and then not Has_Dynamic_Predicate_Aspect (Typ) |
| 937 |
and then not Has_Ghost_Predicate_Aspect (Typ) |
| 938 |
and then Is_OK_Static_Subtype (Typ) |
| 939 |
then |
| 940 |
return; |
| 941 |
end if; |
| 942 |
|
| 943 |
Gen := Current_Scope; |
| 944 |
while not Is_Generic_Instance (Gen) loop |
| 945 |
Gen := Scope (Gen); |
| 946 |
end loop; |
| 947 |
|
| 948 |
pragma Assert (Present (Gen)); |
| 949 |
|
| 950 |
if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then |
| 951 |
Error_Msg_Warn := SPARK_Mode /= On; |
| 952 |
Error_Msg_FE (Msg & "<<", N, Typ); |
| 953 |
Error_Msg_F ("\Program_Error [<<", N); |
| 954 |
|
| 955 |
Insert_Action (N, |
| 956 |
Make_Raise_Program_Error (Sloc (N), |
| 957 |
Reason => PE_Bad_Predicated_Generic_Type)); |
| 958 |
|
| 959 |
else |
| 960 |
Error_Msg_FE (Msg, N, Typ); |
| 961 |
end if; |
| 962 |
|
| 963 |
else |
| 964 |
Error_Msg_FE (Msg, N, Typ); |
| 965 |
end if; |
| 966 |
|
| 967 |
-- Suggest to use First_Valid/Last_Valid instead of First/Last/Range |
| 968 |
-- if the predicate is static. |
| 969 |
|
| 970 |
if not Has_Dynamic_Predicate_Aspect (Typ) |
| 971 |
and then not Has_Ghost_Predicate_Aspect (Typ) |
| 972 |
and then Has_Static_Predicate (Typ) |
| 973 |
and then Nkind (N) = N_Attribute_Reference |
| 974 |
then |
| 975 |
declare |
| 976 |
Aname : constant Name_Id := Attribute_Name (N); |
| 977 |
Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname); |
| 978 |
begin |
| 979 |
case Attr_Id is |
| 980 |
when Attribute_First => |
| 981 |
Error_Msg_F ("\use attribute First_Valid instead", N); |
| 982 |
when Attribute_Last => |
| 983 |
Error_Msg_F ("\use attribute Last_Valid instead", N); |
| 984 |
when Attribute_Range => |
| 985 |
Error_Msg_F ("\use attributes First_Valid and " |
| 986 |
& "Last_Valid instead", N); |
| 987 |
when others => |
| 988 |
null; |
| 989 |
end case; |
| 990 |
end; |
| 991 |
end if; |
| 992 |
|
| 993 |
-- Emit an optional suggestion on how to remedy the error if the |
| 994 |
-- context warrants it. |
| 995 |
|
| 996 |
if Suggest_Static and then Has_Static_Predicate (Typ) then |
| 997 |
Error_Msg_FE ("\predicate of & should be marked static", N, Typ); |
| 998 |
end if; |
| 999 |
end if; |
| 1000 |
end Bad_Predicated_Subtype_Use; |
| 1001 |
|
| 1002 |
----------------------------------------- |
| 1003 |
-- Bad_Unordered_Enumeration_Reference -- |
| 1004 |
----------------------------------------- |
| 1005 |
|
| 1006 |
function Bad_Unordered_Enumeration_Reference |
| 1007 |
(N : Node_Id; |
| 1008 |
T : Entity_Id) return Boolean |
| 1009 |
is |
| 1010 |
begin |
| 1011 |
return Is_Enumeration_Type (T) |
| 1012 |
and then Warn_On_Unordered_Enumeration_Type |
| 1013 |
and then not Is_Generic_Type (T) |
| 1014 |
and then Comes_From_Source (N) |
| 1015 |
and then not Has_Pragma_Ordered (T) |
| 1016 |
and then not In_Same_Extended_Unit (N, T); |
| 1017 |
end Bad_Unordered_Enumeration_Reference; |
| 1018 |
|
| 1019 |
---------------------------- |
| 1020 |
-- Begin_Keyword_Location -- |
| 1021 |
---------------------------- |
| 1022 |
|
| 1023 |
function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is |
| 1024 |
HSS : Node_Id; |
| 1025 |
|
| 1026 |
begin |
| 1027 |
pragma Assert |
| 1028 |
(Nkind (N) in |
| 1029 |
N_Block_Statement | |
| 1030 |
N_Entry_Body | |
| 1031 |
N_Package_Body | |
| 1032 |
N_Subprogram_Body | |
| 1033 |
N_Task_Body); |
| 1034 |
|
| 1035 |
HSS := Handled_Statement_Sequence (N); |
| 1036 |
|
| 1037 |
-- When the handled sequence of statements comes from source, the |
| 1038 |
-- location of the "begin" keyword is that of the sequence itself. |
| 1039 |
-- Note that an internal construct may inherit a source sequence. |
| 1040 |
|
| 1041 |
if Comes_From_Source (HSS) then |
| 1042 |
return Sloc (HSS); |
| 1043 |
|
| 1044 |
-- The parser generates an internal handled sequence of statements to |
| 1045 |
-- capture the location of the "begin" keyword if present in the source. |
| 1046 |
-- Since there are no source statements, the location of the "begin" |
| 1047 |
-- keyword is effectively that of the "end" keyword. |
| 1048 |
|
| 1049 |
elsif Comes_From_Source (N) then |
| 1050 |
return Sloc (HSS); |
| 1051 |
|
| 1052 |
-- Otherwise the construct is internal and should carry the location of |
| 1053 |
-- the original construct which prompted its creation. |
| 1054 |
|
| 1055 |
else |
| 1056 |
return Sloc (N); |
| 1057 |
end if; |
| 1058 |
end Begin_Keyword_Location; |
| 1059 |
|
| 1060 |
-------------------------- |
| 1061 |
-- Build_Actual_Subtype -- |
| 1062 |
-------------------------- |
| 1063 |
|
| 1064 |
function Build_Actual_Subtype |
| 1065 |
(T : Entity_Id; |
| 1066 |
N : Node_Or_Entity_Id) return Node_Id |
| 1067 |
is |
| 1068 |
Loc : Source_Ptr; |
| 1069 |
-- Normally Sloc (N), but may point to corresponding body in some cases |
| 1070 |
|
| 1071 |
Constraints : List_Id; |
| 1072 |
Decl : Node_Id; |
| 1073 |
Discr : Entity_Id; |
| 1074 |
Hi : Node_Id; |
| 1075 |
Lo : Node_Id; |
| 1076 |
Subt : Entity_Id; |
| 1077 |
Disc_Type : Entity_Id; |
| 1078 |
Obj : Node_Id; |
| 1079 |
Index : Node_Id; |
| 1080 |
|
| 1081 |
begin |
| 1082 |
Loc := Sloc (N); |
| 1083 |
|
| 1084 |
if Nkind (N) = N_Defining_Identifier then |
| 1085 |
Obj := New_Occurrence_Of (N, Loc); |
| 1086 |
|
| 1087 |
-- If this is a formal parameter of a subprogram declaration, and |
| 1088 |
-- we are compiling the body, we want the declaration for the |
| 1089 |
-- actual subtype to carry the source position of the body, to |
| 1090 |
-- prevent anomalies in gdb when stepping through the code. |
| 1091 |
|
| 1092 |
if Is_Formal (N) then |
| 1093 |
declare |
| 1094 |
Decl : constant Node_Id := Unit_Declaration_Node (Scope (N)); |
| 1095 |
begin |
| 1096 |
if Nkind (Decl) = N_Subprogram_Declaration |
| 1097 |
and then Present (Corresponding_Body (Decl)) |
| 1098 |
then |
| 1099 |
Loc := Sloc (Corresponding_Body (Decl)); |
| 1100 |
end if; |
| 1101 |
end; |
| 1102 |
end if; |
| 1103 |
|
| 1104 |
else |
| 1105 |
Obj := N; |
| 1106 |
end if; |
| 1107 |
|
| 1108 |
if Is_Array_Type (T) then |
| 1109 |
Constraints := New_List; |
| 1110 |
Index := First_Index (T); |
| 1111 |
|
| 1112 |
for J in 1 .. Number_Dimensions (T) loop |
| 1113 |
|
| 1114 |
-- Build an array subtype declaration with the nominal subtype and |
| 1115 |
-- the bounds of the actual. Add the declaration in front of the |
| 1116 |
-- local declarations for the subprogram, for analysis before any |
| 1117 |
-- reference to the formal in the body. |
| 1118 |
|
| 1119 |
-- If this is for an index with a fixed lower bound, then use |
| 1120 |
-- the fixed lower bound as the lower bound of the actual |
| 1121 |
-- subtype's corresponding index. |
| 1122 |
|
| 1123 |
if not Is_Constrained (T) |
| 1124 |
and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Index)) |
| 1125 |
then |
| 1126 |
Lo := New_Copy_Tree (Type_Low_Bound (Etype (Index))); |
| 1127 |
|
| 1128 |
else |
| 1129 |
Lo := |
| 1130 |
Make_Attribute_Reference (Loc, |
| 1131 |
Prefix => |
| 1132 |
Duplicate_Subexpr_No_Checks (Obj, Name_Req => True), |
| 1133 |
Attribute_Name => Name_First, |
| 1134 |
Expressions => New_List ( |
| 1135 |
Make_Integer_Literal (Loc, J))); |
| 1136 |
end if; |
| 1137 |
|
| 1138 |
Hi := |
| 1139 |
Make_Attribute_Reference (Loc, |
| 1140 |
Prefix => |
| 1141 |
Duplicate_Subexpr_No_Checks (Obj, Name_Req => True), |
| 1142 |
Attribute_Name => Name_Last, |
| 1143 |
Expressions => New_List ( |
| 1144 |
Make_Integer_Literal (Loc, J))); |
| 1145 |
|
| 1146 |
Append (Make_Range (Loc, Lo, Hi), Constraints); |
| 1147 |
|
| 1148 |
Next_Index (Index); |
| 1149 |
end loop; |
| 1150 |
|
| 1151 |
-- If the type has unknown discriminants there is no constrained |
| 1152 |
-- subtype to build. This is never called for a formal or for a |
| 1153 |
-- lhs, so returning the type is ok ??? |
| 1154 |
|
| 1155 |
elsif Has_Unknown_Discriminants (T) then |
| 1156 |
return T; |
| 1157 |
|
| 1158 |
else |
| 1159 |
Constraints := New_List; |
| 1160 |
|
| 1161 |
-- Type T is a generic derived type, inherit the discriminants from |
| 1162 |
-- the parent type. |
| 1163 |
|
| 1164 |
if Is_Private_Type (T) |
| 1165 |
and then No (Full_View (T)) |
| 1166 |
|
| 1167 |
-- T was flagged as an error if it was declared as a formal |
| 1168 |
-- derived type with known discriminants. In this case there |
| 1169 |
-- is no need to look at the parent type since T already carries |
| 1170 |
-- its own discriminants. |
| 1171 |
|
| 1172 |
and then not Error_Posted (T) |
| 1173 |
then |
| 1174 |
Disc_Type := Etype (Base_Type (T)); |
| 1175 |
else |
| 1176 |
Disc_Type := T; |
| 1177 |
end if; |
| 1178 |
|
| 1179 |
Discr := First_Discriminant (Disc_Type); |
| 1180 |
while Present (Discr) loop |
| 1181 |
Append_To (Constraints, |
| 1182 |
Make_Selected_Component (Loc, |
| 1183 |
Prefix => |
| 1184 |
Duplicate_Subexpr_No_Checks (Obj), |
| 1185 |
Selector_Name => New_Occurrence_Of (Discr, Loc))); |
| 1186 |
Next_Discriminant (Discr); |
| 1187 |
end loop; |
| 1188 |
end if; |
| 1189 |
|
| 1190 |
Subt := Make_Temporary (Loc, 'S', Related_Node => N); |
| 1191 |
Set_Is_Internal (Subt); |
| 1192 |
|
| 1193 |
Decl := |
| 1194 |
Make_Subtype_Declaration (Loc, |
| 1195 |
Defining_Identifier => Subt, |
| 1196 |
Subtype_Indication => |
| 1197 |
Make_Subtype_Indication (Loc, |
| 1198 |
Subtype_Mark => New_Occurrence_Of (T, Loc), |
| 1199 |
Constraint => |
| 1200 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 1201 |
Constraints => Constraints))); |
| 1202 |
|
| 1203 |
Mark_Rewrite_Insertion (Decl); |
| 1204 |
return Decl; |
| 1205 |
end Build_Actual_Subtype; |
| 1206 |
|
| 1207 |
--------------------------------------- |
| 1208 |
-- Build_Actual_Subtype_Of_Component -- |
| 1209 |
--------------------------------------- |
| 1210 |
|
| 1211 |
function Build_Actual_Subtype_Of_Component |
| 1212 |
(T : Entity_Id; |
| 1213 |
N : Node_Id) return Node_Id |
| 1214 |
is |
| 1215 |
Loc : constant Source_Ptr := Sloc (N); |
| 1216 |
P : constant Node_Id := Prefix (N); |
| 1217 |
|
| 1218 |
D : Elmt_Id; |
| 1219 |
Id : Node_Id; |
| 1220 |
Index_Typ : Entity_Id; |
| 1221 |
Sel : Entity_Id := Empty; |
| 1222 |
|
| 1223 |
Desig_Typ : Entity_Id; |
| 1224 |
-- This is either a copy of T, or if T is an access type, then it is |
| 1225 |
-- the directly designated type of this access type. |
| 1226 |
|
| 1227 |
function Build_Access_Record_Constraint (C : List_Id) return List_Id; |
| 1228 |
-- If the record component is a constrained access to the current |
| 1229 |
-- record, the subtype has not been constructed during analysis of |
| 1230 |
-- the enclosing record type (see Analyze_Access). In that case, build |
| 1231 |
-- a constrained access subtype after replacing references to the |
| 1232 |
-- enclosing discriminants with the corresponding discriminant values |
| 1233 |
-- of the prefix. |
| 1234 |
|
| 1235 |
function Build_Actual_Array_Constraint return List_Id; |
| 1236 |
-- If one or more of the bounds of the component depends on |
| 1237 |
-- discriminants, build actual constraint using the discriminants |
| 1238 |
-- of the prefix, as above. |
| 1239 |
|
| 1240 |
function Build_Actual_Record_Constraint return List_Id; |
| 1241 |
-- Similar to previous one, for discriminated components constrained |
| 1242 |
-- by the discriminant of the enclosing object. |
| 1243 |
|
| 1244 |
function Build_Discriminant_Reference |
| 1245 |
(Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id; |
| 1246 |
-- Build a reference to the discriminant denoted by Discrim_Name. |
| 1247 |
-- The prefix of the result is usually Obj, but it could be |
| 1248 |
-- a prefix of Obj in some corner cases. |
| 1249 |
|
| 1250 |
function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id; |
| 1251 |
-- Copy the subtree rooted at N and insert an explicit dereference if it |
| 1252 |
-- is of an access type. |
| 1253 |
|
| 1254 |
----------------------------------- |
| 1255 |
-- Build_Actual_Array_Constraint -- |
| 1256 |
----------------------------------- |
| 1257 |
|
| 1258 |
function Build_Actual_Array_Constraint return List_Id is |
| 1259 |
Constraints : constant List_Id := New_List; |
| 1260 |
Indx : Node_Id; |
| 1261 |
Hi : Node_Id; |
| 1262 |
Lo : Node_Id; |
| 1263 |
Old_Hi : Node_Id; |
| 1264 |
Old_Lo : Node_Id; |
| 1265 |
|
| 1266 |
begin |
| 1267 |
Indx := First_Index (Desig_Typ); |
| 1268 |
while Present (Indx) loop |
| 1269 |
Old_Lo := Type_Low_Bound (Etype (Indx)); |
| 1270 |
Old_Hi := Type_High_Bound (Etype (Indx)); |
| 1271 |
|
| 1272 |
if Denotes_Discriminant (Old_Lo) then |
| 1273 |
Lo := Build_Discriminant_Reference (Old_Lo); |
| 1274 |
else |
| 1275 |
Lo := New_Copy_Tree (Old_Lo); |
| 1276 |
|
| 1277 |
-- The new bound will be reanalyzed in the enclosing |
| 1278 |
-- declaration. For literal bounds that come from a type |
| 1279 |
-- declaration, the type of the context must be imposed, so |
| 1280 |
-- insure that analysis will take place. For non-universal |
| 1281 |
-- types this is not strictly necessary. |
| 1282 |
|
| 1283 |
Set_Analyzed (Lo, False); |
| 1284 |
end if; |
| 1285 |
|
| 1286 |
if Denotes_Discriminant (Old_Hi) then |
| 1287 |
Hi := Build_Discriminant_Reference (Old_Hi); |
| 1288 |
else |
| 1289 |
Hi := New_Copy_Tree (Old_Hi); |
| 1290 |
Set_Analyzed (Hi, False); |
| 1291 |
end if; |
| 1292 |
|
| 1293 |
Append (Make_Range (Loc, Lo, Hi), Constraints); |
| 1294 |
Next_Index (Indx); |
| 1295 |
end loop; |
| 1296 |
|
| 1297 |
return Constraints; |
| 1298 |
end Build_Actual_Array_Constraint; |
| 1299 |
|
| 1300 |
------------------------------------ |
| 1301 |
-- Build_Actual_Record_Constraint -- |
| 1302 |
------------------------------------ |
| 1303 |
|
| 1304 |
function Build_Actual_Record_Constraint return List_Id is |
| 1305 |
Constraints : constant List_Id := New_List; |
| 1306 |
D : Elmt_Id; |
| 1307 |
D_Val : Node_Id; |
| 1308 |
|
| 1309 |
begin |
| 1310 |
D := First_Elmt (Discriminant_Constraint (Desig_Typ)); |
| 1311 |
while Present (D) loop |
| 1312 |
if Denotes_Discriminant (Node (D)) then |
| 1313 |
D_Val := Build_Discriminant_Reference (Node (D)); |
| 1314 |
else |
| 1315 |
D_Val := New_Copy_Tree (Node (D)); |
| 1316 |
end if; |
| 1317 |
|
| 1318 |
Append (D_Val, Constraints); |
| 1319 |
Next_Elmt (D); |
| 1320 |
end loop; |
| 1321 |
|
| 1322 |
return Constraints; |
| 1323 |
end Build_Actual_Record_Constraint; |
| 1324 |
|
| 1325 |
---------------------------------- |
| 1326 |
-- Build_Discriminant_Reference -- |
| 1327 |
---------------------------------- |
| 1328 |
|
| 1329 |
function Build_Discriminant_Reference |
| 1330 |
(Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id |
| 1331 |
is |
| 1332 |
Discrim : constant Entity_Id := Entity (Discrim_Name); |
| 1333 |
|
| 1334 |
function Obj_Is_Good_Prefix return Boolean; |
| 1335 |
-- Returns True if Obj.Discrim makes sense; that is, if |
| 1336 |
-- Obj has Discrim as one of its discriminants (or is an |
| 1337 |
-- access value that designates such an object). |
| 1338 |
|
| 1339 |
------------------------ |
| 1340 |
-- Obj_Is_Good_Prefix -- |
| 1341 |
------------------------ |
| 1342 |
|
| 1343 |
function Obj_Is_Good_Prefix return Boolean is |
| 1344 |
Obj_Type : Entity_Id := |
| 1345 |
Implementation_Base_Type (Etype (Obj)); |
| 1346 |
|
| 1347 |
Discriminated_Type : constant Entity_Id := |
| 1348 |
Implementation_Base_Type |
| 1349 |
(Scope (Original_Record_Component (Discrim))); |
| 1350 |
begin |
| 1351 |
-- The order of the following two tests matters in the |
| 1352 |
-- access-to-class-wide case. |
| 1353 |
|
| 1354 |
if Is_Access_Type (Obj_Type) then |
| 1355 |
Obj_Type := Implementation_Base_Type |
| 1356 |
(Designated_Type (Obj_Type)); |
| 1357 |
end if; |
| 1358 |
|
| 1359 |
if Is_Class_Wide_Type (Obj_Type) then |
| 1360 |
Obj_Type := Implementation_Base_Type |
| 1361 |
(Find_Specific_Type (Obj_Type)); |
| 1362 |
end if; |
| 1363 |
|
| 1364 |
-- If a type T1 defines a discriminant D1, then Obj.D1 is ok (for |
| 1365 |
-- our purposes here) if T1 is an ancestor of the type of Obj. |
| 1366 |
-- So that's what we would like to test for here. |
| 1367 |
-- The bad news: Is_Ancestor is only defined in the tagged case. |
| 1368 |
-- The good news: in the untagged case, Implementation_Base_Type |
| 1369 |
-- looks through derived types so we can use a simpler test. |
| 1370 |
|
| 1371 |
if Is_Tagged_Type (Discriminated_Type) then |
| 1372 |
return Is_Ancestor (Discriminated_Type, Obj_Type); |
| 1373 |
else |
| 1374 |
return Discriminated_Type = Obj_Type; |
| 1375 |
end if; |
| 1376 |
end Obj_Is_Good_Prefix; |
| 1377 |
|
| 1378 |
-- Start of processing for Build_Discriminant_Reference |
| 1379 |
|
| 1380 |
begin |
| 1381 |
if not Obj_Is_Good_Prefix then |
| 1382 |
-- If the given discriminant is not a component of the given |
| 1383 |
-- object, then try the enclosing object. |
| 1384 |
|
| 1385 |
if Nkind (Obj) = N_Selected_Component then |
| 1386 |
return Build_Discriminant_Reference |
| 1387 |
(Discrim_Name => Discrim_Name, |
| 1388 |
Obj => Prefix (Obj)); |
| 1389 |
elsif Nkind (Obj) in N_Has_Entity |
| 1390 |
and then Nkind (Parent (Entity (Obj))) = |
| 1391 |
N_Object_Renaming_Declaration |
| 1392 |
then |
| 1393 |
-- Look through a renaming (a corner case of a corner case). |
| 1394 |
return Build_Discriminant_Reference |
| 1395 |
(Discrim_Name => Discrim_Name, |
| 1396 |
Obj => Name (Parent (Entity (Obj)))); |
| 1397 |
else |
| 1398 |
-- We are in some unexpected case here, so revert to the |
| 1399 |
-- old behavior (by falling through to it). |
| 1400 |
null; |
| 1401 |
end if; |
| 1402 |
end if; |
| 1403 |
|
| 1404 |
return Make_Selected_Component (Loc, |
| 1405 |
Prefix => Copy_And_Maybe_Dereference (Obj), |
| 1406 |
Selector_Name => New_Occurrence_Of (Discrim, Loc)); |
| 1407 |
end Build_Discriminant_Reference; |
| 1408 |
|
| 1409 |
------------------------------------ |
| 1410 |
-- Build_Access_Record_Constraint -- |
| 1411 |
------------------------------------ |
| 1412 |
|
| 1413 |
function Build_Access_Record_Constraint (C : List_Id) return List_Id is |
| 1414 |
Constraints : constant List_Id := New_List; |
| 1415 |
D : Node_Id; |
| 1416 |
D_Val : Node_Id; |
| 1417 |
|
| 1418 |
begin |
| 1419 |
-- Retrieve the constraint from the component declaration, because |
| 1420 |
-- the component subtype has not been constructed and the component |
| 1421 |
-- type is an unconstrained access. |
| 1422 |
|
| 1423 |
D := First (C); |
| 1424 |
while Present (D) loop |
| 1425 |
if Nkind (D) = N_Discriminant_Association |
| 1426 |
and then Denotes_Discriminant (Expression (D)) |
| 1427 |
then |
| 1428 |
D_Val := New_Copy_Tree (D); |
| 1429 |
Set_Expression (D_Val, |
| 1430 |
Make_Selected_Component (Loc, |
| 1431 |
Prefix => Copy_And_Maybe_Dereference (P), |
| 1432 |
Selector_Name => |
| 1433 |
New_Occurrence_Of (Entity (Expression (D)), Loc))); |
| 1434 |
|
| 1435 |
elsif Denotes_Discriminant (D) then |
| 1436 |
D_Val := Make_Selected_Component (Loc, |
| 1437 |
Prefix => Copy_And_Maybe_Dereference (P), |
| 1438 |
Selector_Name => New_Occurrence_Of (Entity (D), Loc)); |
| 1439 |
|
| 1440 |
else |
| 1441 |
D_Val := New_Copy_Tree (D); |
| 1442 |
end if; |
| 1443 |
|
| 1444 |
Append (D_Val, Constraints); |
| 1445 |
Next (D); |
| 1446 |
end loop; |
| 1447 |
|
| 1448 |
return Constraints; |
| 1449 |
end Build_Access_Record_Constraint; |
| 1450 |
|
| 1451 |
-------------------------------- |
| 1452 |
-- Copy_And_Maybe_Dereference -- |
| 1453 |
-------------------------------- |
| 1454 |
|
| 1455 |
function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id is |
| 1456 |
New_N : constant Node_Id := New_Copy_Tree (N); |
| 1457 |
|
| 1458 |
begin |
| 1459 |
if Is_Access_Type (Etype (N)) then |
| 1460 |
return Make_Explicit_Dereference (Sloc (Parent (N)), New_N); |
| 1461 |
|
| 1462 |
else |
| 1463 |
return New_N; |
| 1464 |
end if; |
| 1465 |
end Copy_And_Maybe_Dereference; |
| 1466 |
|
| 1467 |
-- Start of processing for Build_Actual_Subtype_Of_Component |
| 1468 |
|
| 1469 |
begin |
| 1470 |
-- The subtype does not need to be created during preanalysis |
| 1471 |
|
| 1472 |
if Preanalysis_Active then |
| 1473 |
return Empty; |
| 1474 |
|
| 1475 |
-- More comments for the rest of this body would be good ??? |
| 1476 |
|
| 1477 |
elsif Nkind (N) = N_Explicit_Dereference then |
| 1478 |
if Is_Composite_Type (T) |
| 1479 |
and then not Is_Constrained (T) |
| 1480 |
and then not (Is_Class_Wide_Type (T) |
| 1481 |
and then Is_Constrained (Root_Type (T))) |
| 1482 |
and then not Has_Unknown_Discriminants (T) |
| 1483 |
then |
| 1484 |
-- If the type of the dereference is already constrained, it is an |
| 1485 |
-- actual subtype. |
| 1486 |
|
| 1487 |
if Is_Array_Type (Etype (N)) |
| 1488 |
and then Is_Constrained (Etype (N)) |
| 1489 |
then |
| 1490 |
return Empty; |
| 1491 |
else |
| 1492 |
Remove_Side_Effects (P); |
| 1493 |
return Build_Actual_Subtype (T, N); |
| 1494 |
end if; |
| 1495 |
|
| 1496 |
else |
| 1497 |
return Empty; |
| 1498 |
end if; |
| 1499 |
|
| 1500 |
elsif Nkind (N) = N_Selected_Component then |
| 1501 |
-- The entity of the selected component allows us to retrieve |
| 1502 |
-- the original constraint from its component declaration. |
| 1503 |
|
| 1504 |
Sel := Entity (Selector_Name (N)); |
| 1505 |
if Parent_Kind (Sel) /= N_Component_Declaration then |
| 1506 |
return Empty; |
| 1507 |
end if; |
| 1508 |
end if; |
| 1509 |
|
| 1510 |
if Is_Access_Type (T) then |
| 1511 |
Desig_Typ := Designated_Type (T); |
| 1512 |
|
| 1513 |
else |
| 1514 |
Desig_Typ := T; |
| 1515 |
end if; |
| 1516 |
|
| 1517 |
if Ekind (Desig_Typ) = E_Array_Subtype then |
| 1518 |
Id := First_Index (Desig_Typ); |
| 1519 |
|
| 1520 |
-- Check whether an index bound is constrained by a discriminant |
| 1521 |
|
| 1522 |
while Present (Id) loop |
| 1523 |
Index_Typ := Underlying_Type (Etype (Id)); |
| 1524 |
|
| 1525 |
if Denotes_Discriminant (Type_Low_Bound (Index_Typ)) |
| 1526 |
or else |
| 1527 |
Denotes_Discriminant (Type_High_Bound (Index_Typ)) |
| 1528 |
then |
| 1529 |
Remove_Side_Effects (P); |
| 1530 |
return |
| 1531 |
Build_Component_Subtype |
| 1532 |
(Build_Actual_Array_Constraint, Loc, Base_Type (T)); |
| 1533 |
end if; |
| 1534 |
|
| 1535 |
Next_Index (Id); |
| 1536 |
end loop; |
| 1537 |
|
| 1538 |
elsif Is_Composite_Type (Desig_Typ) |
| 1539 |
and then Has_Discriminants (Desig_Typ) |
| 1540 |
and then not Is_Empty_Elmt_List (Discriminant_Constraint (Desig_Typ)) |
| 1541 |
and then not Has_Unknown_Discriminants (Desig_Typ) |
| 1542 |
then |
| 1543 |
if Is_Private_Type (Desig_Typ) |
| 1544 |
and then No (Discriminant_Constraint (Desig_Typ)) |
| 1545 |
then |
| 1546 |
Desig_Typ := Full_View (Desig_Typ); |
| 1547 |
end if; |
| 1548 |
|
| 1549 |
D := First_Elmt (Discriminant_Constraint (Desig_Typ)); |
| 1550 |
while Present (D) loop |
| 1551 |
if Denotes_Discriminant (Node (D)) then |
| 1552 |
Remove_Side_Effects (P); |
| 1553 |
return |
| 1554 |
Build_Component_Subtype ( |
| 1555 |
Build_Actual_Record_Constraint, Loc, Base_Type (T)); |
| 1556 |
end if; |
| 1557 |
|
| 1558 |
Next_Elmt (D); |
| 1559 |
end loop; |
| 1560 |
|
| 1561 |
-- Special processing for an access record component that is |
| 1562 |
-- the target of an assignment. If the designated type is an |
| 1563 |
-- unconstrained discriminated record we create its actual |
| 1564 |
-- subtype now. |
| 1565 |
|
| 1566 |
elsif Ekind (T) = E_Access_Type |
| 1567 |
and then Present (Sel) |
| 1568 |
and then Has_Per_Object_Constraint (Sel) |
| 1569 |
and then Nkind (Parent (N)) = N_Assignment_Statement |
| 1570 |
and then N = Name (Parent (N)) |
| 1571 |
-- and then not Inside_Init_Proc |
| 1572 |
-- and then Has_Discriminants (Desig_Typ) |
| 1573 |
-- and then not Is_Constrained (Desig_Typ) |
| 1574 |
then |
| 1575 |
declare |
| 1576 |
S_Indic : constant Node_Id := |
| 1577 |
(Subtype_Indication |
| 1578 |
(Component_Definition (Parent (Sel)))); |
| 1579 |
Discs : List_Id; |
| 1580 |
begin |
| 1581 |
if Nkind (S_Indic) = N_Subtype_Indication then |
| 1582 |
Discs := Constraints (Constraint (S_Indic)); |
| 1583 |
|
| 1584 |
Remove_Side_Effects (P); |
| 1585 |
return Build_Component_Subtype |
| 1586 |
(Build_Access_Record_Constraint (Discs), Loc, T); |
| 1587 |
else |
| 1588 |
return Empty; |
| 1589 |
end if; |
| 1590 |
end; |
| 1591 |
end if; |
| 1592 |
|
| 1593 |
-- If none of the above, the actual and nominal subtypes are the same |
| 1594 |
|
| 1595 |
return Empty; |
| 1596 |
end Build_Actual_Subtype_Of_Component; |
| 1597 |
|
| 1598 |
----------------------------- |
| 1599 |
-- Build_Component_Subtype -- |
| 1600 |
----------------------------- |
| 1601 |
|
| 1602 |
function Build_Component_Subtype |
| 1603 |
(C : List_Id; |
| 1604 |
Loc : Source_Ptr; |
| 1605 |
T : Entity_Id) return Node_Id |
| 1606 |
is |
| 1607 |
Subt : Entity_Id; |
| 1608 |
Decl : Node_Id; |
| 1609 |
|
| 1610 |
begin |
| 1611 |
-- Unchecked_Union components do not require component subtypes |
| 1612 |
|
| 1613 |
if Is_Unchecked_Union (T) then |
| 1614 |
return Empty; |
| 1615 |
end if; |
| 1616 |
|
| 1617 |
Subt := Make_Temporary (Loc, 'S'); |
| 1618 |
Set_Is_Internal (Subt); |
| 1619 |
|
| 1620 |
Decl := |
| 1621 |
Make_Subtype_Declaration (Loc, |
| 1622 |
Defining_Identifier => Subt, |
| 1623 |
Subtype_Indication => |
| 1624 |
Make_Subtype_Indication (Loc, |
| 1625 |
Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc), |
| 1626 |
Constraint => |
| 1627 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 1628 |
Constraints => C))); |
| 1629 |
|
| 1630 |
Mark_Rewrite_Insertion (Decl); |
| 1631 |
return Decl; |
| 1632 |
end Build_Component_Subtype; |
| 1633 |
|
| 1634 |
----------------------------- |
| 1635 |
-- Build_Constrained_Itype -- |
| 1636 |
----------------------------- |
| 1637 |
|
| 1638 |
procedure Build_Constrained_Itype |
| 1639 |
(N : Node_Id; |
| 1640 |
Typ : Entity_Id; |
| 1641 |
New_Assoc_List : List_Id) |
| 1642 |
is |
| 1643 |
Constrs : constant List_Id := New_List; |
| 1644 |
Loc : constant Source_Ptr := Sloc (N); |
| 1645 |
Def_Id : Entity_Id; |
| 1646 |
Indic : Node_Id; |
| 1647 |
New_Assoc : Node_Id; |
| 1648 |
Subtyp_Decl : Node_Id; |
| 1649 |
|
| 1650 |
begin |
| 1651 |
New_Assoc := First (New_Assoc_List); |
| 1652 |
while Present (New_Assoc) loop |
| 1653 |
|
| 1654 |
-- There is exactly one choice in the component association (and |
| 1655 |
-- it is either a discriminant, a component or the others clause). |
| 1656 |
pragma Assert (List_Length (Choices (New_Assoc)) = 1); |
| 1657 |
|
| 1658 |
-- Duplicate expression for the discriminant and put it on the |
| 1659 |
-- list of constraints for the itype declaration. |
| 1660 |
|
| 1661 |
if Is_Entity_Name (First (Choices (New_Assoc))) |
| 1662 |
and then |
| 1663 |
Ekind (Entity (First (Choices (New_Assoc)))) = E_Discriminant |
| 1664 |
then |
| 1665 |
Append_To (Constrs, Duplicate_Subexpr (Expression (New_Assoc))); |
| 1666 |
end if; |
| 1667 |
|
| 1668 |
Next (New_Assoc); |
| 1669 |
end loop; |
| 1670 |
|
| 1671 |
if Has_Unknown_Discriminants (Typ) |
| 1672 |
and then Present (Underlying_Record_View (Typ)) |
| 1673 |
then |
| 1674 |
Indic := |
| 1675 |
Make_Subtype_Indication (Loc, |
| 1676 |
Subtype_Mark => |
| 1677 |
New_Occurrence_Of (Underlying_Record_View (Typ), Loc), |
| 1678 |
Constraint => |
| 1679 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 1680 |
Constraints => Constrs)); |
| 1681 |
else |
| 1682 |
Indic := |
| 1683 |
Make_Subtype_Indication (Loc, |
| 1684 |
Subtype_Mark => |
| 1685 |
New_Occurrence_Of (Base_Type (Typ), Loc), |
| 1686 |
Constraint => |
| 1687 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 1688 |
Constraints => Constrs)); |
| 1689 |
end if; |
| 1690 |
|
| 1691 |
Def_Id := Create_Itype (Ekind (Typ), N); |
| 1692 |
|
| 1693 |
Subtyp_Decl := |
| 1694 |
Make_Subtype_Declaration (Loc, |
| 1695 |
Defining_Identifier => Def_Id, |
| 1696 |
Subtype_Indication => Indic); |
| 1697 |
Set_Parent (Subtyp_Decl, Parent (N)); |
| 1698 |
|
| 1699 |
-- Itypes must be analyzed with checks off (see itypes.ads) |
| 1700 |
|
| 1701 |
Analyze (Subtyp_Decl, Suppress => All_Checks); |
| 1702 |
|
| 1703 |
Set_Etype (N, Def_Id); |
| 1704 |
end Build_Constrained_Itype; |
| 1705 |
|
| 1706 |
--------------------------- |
| 1707 |
-- Build_Default_Subtype -- |
| 1708 |
--------------------------- |
| 1709 |
|
| 1710 |
function Build_Default_Subtype |
| 1711 |
(T : Entity_Id; |
| 1712 |
N : Node_Id) return Entity_Id |
| 1713 |
is |
| 1714 |
Loc : constant Source_Ptr := Sloc (N); |
| 1715 |
Disc : Entity_Id; |
| 1716 |
|
| 1717 |
Bas : Entity_Id; |
| 1718 |
-- The base type that is to be constrained by the defaults |
| 1719 |
|
| 1720 |
begin |
| 1721 |
if not Has_Discriminants (T) or else Is_Constrained (T) then |
| 1722 |
return T; |
| 1723 |
end if; |
| 1724 |
|
| 1725 |
Bas := Base_Type (T); |
| 1726 |
|
| 1727 |
-- If T is non-private but its base type is private, this is the |
| 1728 |
-- completion of a subtype declaration whose parent type is private |
| 1729 |
-- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants |
| 1730 |
-- are to be found in the full view of the base. Check that the private |
| 1731 |
-- status of T and its base differ. |
| 1732 |
|
| 1733 |
if Is_Private_Type (Bas) |
| 1734 |
and then not Is_Private_Type (T) |
| 1735 |
and then Present (Full_View (Bas)) |
| 1736 |
then |
| 1737 |
Bas := Full_View (Bas); |
| 1738 |
end if; |
| 1739 |
|
| 1740 |
Disc := First_Discriminant (T); |
| 1741 |
|
| 1742 |
if No (Discriminant_Default_Value (Disc)) then |
| 1743 |
return T; |
| 1744 |
end if; |
| 1745 |
|
| 1746 |
declare |
| 1747 |
Act : constant Entity_Id := Make_Temporary (Loc, 'S'); |
| 1748 |
Constraints : constant List_Id := New_List; |
| 1749 |
Decl : Node_Id; |
| 1750 |
|
| 1751 |
begin |
| 1752 |
while Present (Disc) loop |
| 1753 |
Append_To (Constraints, |
| 1754 |
New_Copy_Tree |
| 1755 |
(Discriminant_Default_Value (Disc), New_Sloc => Loc)); |
| 1756 |
Next_Discriminant (Disc); |
| 1757 |
end loop; |
| 1758 |
|
| 1759 |
Decl := |
| 1760 |
Make_Subtype_Declaration (Loc, |
| 1761 |
Defining_Identifier => Act, |
| 1762 |
Subtype_Indication => |
| 1763 |
Make_Subtype_Indication (Loc, |
| 1764 |
Subtype_Mark => New_Occurrence_Of (Bas, Loc), |
| 1765 |
Constraint => |
| 1766 |
Make_Index_Or_Discriminant_Constraint (Loc, |
| 1767 |
Constraints => Constraints))); |
| 1768 |
|
| 1769 |
Insert_Action (N, Decl); |
| 1770 |
|
| 1771 |
-- If the context is a component declaration the subtype declaration |
| 1772 |
-- will be analyzed when the enclosing type is frozen, otherwise do |
| 1773 |
-- it now. |
| 1774 |
|
| 1775 |
if Ekind (Current_Scope) /= E_Record_Type then |
| 1776 |
Analyze (Decl); |
| 1777 |
end if; |
| 1778 |
|
| 1779 |
return Act; |
| 1780 |
end; |
| 1781 |
end Build_Default_Subtype; |
| 1782 |
|
| 1783 |
------------------------------ |
| 1784 |
-- Build_Default_Subtype_OK -- |
| 1785 |
------------------------------ |
| 1786 |
|
| 1787 |
function Build_Default_Subtype_OK (T : Entity_Id) return Boolean is |
| 1788 |
begin |
| 1789 |
if Is_Constrained (T) then |
| 1790 |
|
| 1791 |
-- We won't build a new subtype if T is constrained |
| 1792 |
|
| 1793 |
return False; |
| 1794 |
end if; |
| 1795 |
|
| 1796 |
return Is_Definite_Subtype (T) and then Is_Inherently_Limited_Type (T); |
| 1797 |
end Build_Default_Subtype_OK; |
| 1798 |
|
| 1799 |
-------------------------------------------- |
| 1800 |
-- Build_Discriminal_Subtype_Of_Component -- |
| 1801 |
-------------------------------------------- |
| 1802 |
|
| 1803 |
function Build_Discriminal_Subtype_Of_Component |
| 1804 |
(T : Entity_Id) return Node_Id |
| 1805 |
is |
| 1806 |
Loc : constant Source_Ptr := Sloc (T); |
| 1807 |
D : Elmt_Id; |
| 1808 |
Id : Node_Id; |
| 1809 |
|
| 1810 |
function Build_Discriminal_Array_Constraint return List_Id; |
| 1811 |
-- If one or more of the bounds of the component depends on |
| 1812 |
-- discriminants, build actual constraint using the discriminants |
| 1813 |
-- of the prefix. |
| 1814 |
|
| 1815 |
function Build_Discriminal_Record_Constraint return List_Id; |
| 1816 |
-- Similar to previous one, for discriminated components constrained by |
| 1817 |
-- the discriminant of the enclosing object. |
| 1818 |
|
| 1819 |
---------------------------------------- |
| 1820 |
-- Build_Discriminal_Array_Constraint -- |
| 1821 |
---------------------------------------- |
| 1822 |
|
| 1823 |
function Build_Discriminal_Array_Constraint return List_Id is |
| 1824 |
Constraints : constant List_Id := New_List; |
| 1825 |
Indx : Node_Id; |
| 1826 |
Hi : Node_Id; |
| 1827 |
Lo : Node_Id; |
| 1828 |
Old_Hi : Node_Id; |
| 1829 |
Old_Lo : Node_Id; |
| 1830 |
|
| 1831 |
begin |
| 1832 |
Indx := First_Index (T); |
| 1833 |
while Present (Indx) loop |
| 1834 |
Old_Lo := Type_Low_Bound (Etype (Indx)); |
| 1835 |
Old_Hi := Type_High_Bound (Etype (Indx)); |
| 1836 |
|
| 1837 |
if Denotes_Discriminant (Old_Lo) then |
| 1838 |
Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc); |
| 1839 |
|
| 1840 |
else |
| 1841 |
Lo := New_Copy_Tree (Old_Lo); |
| 1842 |
end if; |
| 1843 |
|
| 1844 |
if Denotes_Discriminant (Old_Hi) then |
| 1845 |
Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc); |
| 1846 |
|
| 1847 |
else |
| 1848 |
Hi := New_Copy_Tree (Old_Hi); |
| 1849 |
end if; |
| 1850 |
|
| 1851 |
Append (Make_Range (Loc, Lo, Hi), Constraints); |
| 1852 |
Next_Index (Indx); |
| 1853 |
end loop; |
| 1854 |
|
| 1855 |
return Constraints; |
| 1856 |
end Build_Discriminal_Array_Constraint; |
| 1857 |
|
| 1858 |
----------------------------------------- |
| 1859 |
-- Build_Discriminal_Record_Constraint -- |
| 1860 |
----------------------------------------- |
| 1861 |
|
| 1862 |
function Build_Discriminal_Record_Constraint return List_Id is |
| 1863 |
Constraints : constant List_Id := New_List; |
| 1864 |
D : Elmt_Id; |
| 1865 |
D_Val : Node_Id; |
| 1866 |
|
| 1867 |
begin |
| 1868 |
D := First_Elmt (Discriminant_Constraint (T)); |
| 1869 |
while Present (D) loop |
| 1870 |
if Denotes_Discriminant (Node (D)) then |
| 1871 |
D_Val := |
| 1872 |
New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc); |
| 1873 |
else |
| 1874 |
D_Val := New_Copy_Tree (Node (D)); |
| 1875 |
end if; |
| 1876 |
|
| 1877 |
Append (D_Val, Constraints); |
| 1878 |
Next_Elmt (D); |
| 1879 |
end loop; |
| 1880 |
|
| 1881 |
return Constraints; |
| 1882 |
end Build_Discriminal_Record_Constraint; |
| 1883 |
|
| 1884 |
-- Start of processing for Build_Discriminal_Subtype_Of_Component |
| 1885 |
|
| 1886 |
begin |
| 1887 |
if Ekind (T) = E_Array_Subtype then |
| 1888 |
Id := First_Index (T); |
| 1889 |
while Present (Id) loop |
| 1890 |
if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) |
| 1891 |
or else |
| 1892 |
Denotes_Discriminant (Type_High_Bound (Etype (Id))) |
| 1893 |
then |
| 1894 |
return Build_Component_Subtype |
| 1895 |
(Build_Discriminal_Array_Constraint, Loc, T); |
| 1896 |
end if; |
| 1897 |
|
| 1898 |
Next_Index (Id); |
| 1899 |
end loop; |
| 1900 |
|
| 1901 |
elsif Ekind (T) = E_Record_Subtype |
| 1902 |
and then Has_Discriminants (T) |
| 1903 |
and then not Has_Unknown_Discriminants (T) |
| 1904 |
then |
| 1905 |
D := First_Elmt (Discriminant_Constraint (T)); |
| 1906 |
while Present (D) loop |
| 1907 |
if Denotes_Discriminant (Node (D)) then |
| 1908 |
return Build_Component_Subtype |
| 1909 |
(Build_Discriminal_Record_Constraint, Loc, T); |
| 1910 |
end if; |
| 1911 |
|
| 1912 |
Next_Elmt (D); |
| 1913 |
end loop; |
| 1914 |
end if; |
| 1915 |
|
| 1916 |
-- If none of the above, the actual and nominal subtypes are the same |
| 1917 |
|
| 1918 |
return Empty; |
| 1919 |
end Build_Discriminal_Subtype_Of_Component; |
| 1920 |
|
| 1921 |
------------------------------ |
| 1922 |
-- Build_Elaboration_Entity -- |
| 1923 |
------------------------------ |
| 1924 |
|
| 1925 |
procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is |
| 1926 |
Loc : constant Source_Ptr := Sloc (N); |
| 1927 |
Decl : Node_Id; |
| 1928 |
Elab_Ent : Entity_Id; |
| 1929 |
|
| 1930 |
procedure Set_Package_Name (Ent : Entity_Id); |
| 1931 |
-- Given an entity, sets the fully qualified name of the entity in |
| 1932 |
-- Name_Buffer, with components separated by double underscores. This |
| 1933 |
-- is a recursive routine that climbs the scope chain to Standard. |
| 1934 |
|
| 1935 |
---------------------- |
| 1936 |
-- Set_Package_Name -- |
| 1937 |
---------------------- |
| 1938 |
|
| 1939 |
procedure Set_Package_Name (Ent : Entity_Id) is |
| 1940 |
begin |
| 1941 |
if Scope (Ent) /= Standard_Standard then |
| 1942 |
Set_Package_Name (Scope (Ent)); |
| 1943 |
|
| 1944 |
declare |
| 1945 |
Nam : constant String := Get_Name_String (Chars (Ent)); |
| 1946 |
begin |
| 1947 |
Name_Buffer (Name_Len + 1) := '_'; |
| 1948 |
Name_Buffer (Name_Len + 2) := '_'; |
| 1949 |
Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam; |
| 1950 |
Name_Len := Name_Len + Nam'Length + 2; |
| 1951 |
end; |
| 1952 |
|
| 1953 |
else |
| 1954 |
Get_Name_String (Chars (Ent)); |
| 1955 |
end if; |
| 1956 |
end Set_Package_Name; |
| 1957 |
|
| 1958 |
-- Start of processing for Build_Elaboration_Entity |
| 1959 |
|
| 1960 |
begin |
| 1961 |
-- Ignore call if already constructed |
| 1962 |
|
| 1963 |
if Present (Elaboration_Entity (Spec_Id)) then |
| 1964 |
return; |
| 1965 |
|
| 1966 |
-- Do not generate an elaboration entity in GNATprove move because the |
| 1967 |
-- elaboration counter is a form of expansion. |
| 1968 |
|
| 1969 |
elsif GNATprove_Mode then |
| 1970 |
return; |
| 1971 |
|
| 1972 |
-- See if we need elaboration entity |
| 1973 |
|
| 1974 |
-- We always need an elaboration entity when preserving control flow, as |
| 1975 |
-- we want to remain explicit about the unit's elaboration order. |
| 1976 |
|
| 1977 |
elsif Opt.Suppress_Control_Flow_Optimizations then |
| 1978 |
null; |
| 1979 |
|
| 1980 |
-- We always need an elaboration entity for the dynamic elaboration |
| 1981 |
-- model, since it is needed to properly generate the PE exception for |
| 1982 |
-- access before elaboration. |
| 1983 |
|
| 1984 |
elsif Dynamic_Elaboration_Checks then |
| 1985 |
null; |
| 1986 |
|
| 1987 |
-- For the static model, we don't need the elaboration counter if this |
| 1988 |
-- unit is sure to have no elaboration code, since that means there |
| 1989 |
-- is no elaboration unit to be called. Note that we can't just decide |
| 1990 |
-- after the fact by looking to see whether there was elaboration code, |
| 1991 |
-- because that's too late to make this decision. |
| 1992 |
|
| 1993 |
elsif Restriction_Active (No_Elaboration_Code) then |
| 1994 |
return; |
| 1995 |
|
| 1996 |
-- Similarly, for the static model, we can skip the elaboration counter |
| 1997 |
-- if we have the No_Multiple_Elaboration restriction, since for the |
| 1998 |
-- static model, that's the only purpose of the counter (to avoid |
| 1999 |
-- multiple elaboration). |
| 2000 |
|
| 2001 |
elsif Restriction_Active (No_Multiple_Elaboration) then |
| 2002 |
return; |
| 2003 |
end if; |
| 2004 |
|
| 2005 |
-- Here we need the elaboration entity |
| 2006 |
|
| 2007 |
-- Construct name of elaboration entity as xxx_E, where xxx is the unit |
| 2008 |
-- name with dots replaced by double underscore. We have to manually |
| 2009 |
-- construct this name, since it will be elaborated in the outer scope, |
| 2010 |
-- and thus will not have the unit name automatically prepended. |
| 2011 |
|
| 2012 |
Set_Package_Name (Spec_Id); |
| 2013 |
Add_Str_To_Name_Buffer ("_E"); |
| 2014 |
|
| 2015 |
-- Create elaboration counter |
| 2016 |
|
| 2017 |
Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find); |
| 2018 |
Set_Elaboration_Entity (Spec_Id, Elab_Ent); |
| 2019 |
|
| 2020 |
Decl := |
| 2021 |
Make_Object_Declaration (Loc, |
| 2022 |
Defining_Identifier => Elab_Ent, |
| 2023 |
Object_Definition => |
| 2024 |
New_Occurrence_Of (Standard_Short_Integer, Loc), |
| 2025 |
Expression => Make_Integer_Literal (Loc, Uint_0)); |
| 2026 |
|
| 2027 |
Push_Scope (Standard_Standard); |
| 2028 |
Add_Global_Declaration (Decl); |
| 2029 |
Pop_Scope; |
| 2030 |
|
| 2031 |
-- Reset True_Constant indication, since we will indeed assign a value |
| 2032 |
-- to the variable in the binder main. We also kill the Current_Value |
| 2033 |
-- and Last_Assignment fields for the same reason. |
| 2034 |
|
| 2035 |
Set_Is_True_Constant (Elab_Ent, False); |
| 2036 |
Set_Current_Value (Elab_Ent, Empty); |
| 2037 |
Set_Last_Assignment (Elab_Ent, Empty); |
| 2038 |
|
| 2039 |
-- We do not want any further qualification of the name (if we did not |
| 2040 |
-- do this, we would pick up the name of the generic package in the case |
| 2041 |
-- of a library level generic instantiation). |
| 2042 |
|
| 2043 |
Set_Has_Qualified_Name (Elab_Ent); |
| 2044 |
Set_Has_Fully_Qualified_Name (Elab_Ent); |
| 2045 |
end Build_Elaboration_Entity; |
| 2046 |
|
| 2047 |
-------------------------------- |
| 2048 |
-- Build_Explicit_Dereference -- |
| 2049 |
-------------------------------- |
| 2050 |
|
| 2051 |
procedure Build_Explicit_Dereference |
| 2052 |
(Expr : Node_Id; |
| 2053 |
Disc : Entity_Id) |
| 2054 |
is |
| 2055 |
Loc : constant Source_Ptr := Sloc (Expr); |
| 2056 |
I : Interp_Index; |
| 2057 |
It : Interp; |
| 2058 |
|
| 2059 |
begin |
| 2060 |
-- An entity of a type with a reference aspect is overloaded with |
| 2061 |
-- both interpretations: with and without the dereference. Now that |
| 2062 |
-- the dereference is made explicit, set the type of the node properly, |
| 2063 |
-- to prevent anomalies in the backend. Same if the expression is an |
| 2064 |
-- overloaded function call whose return type has a reference aspect. |
| 2065 |
|
| 2066 |
if Is_Entity_Name (Expr) then |
| 2067 |
Set_Etype (Expr, Etype (Entity (Expr))); |
| 2068 |
|
| 2069 |
-- The designated entity will not be examined again when resolving |
| 2070 |
-- the dereference, so generate a reference to it now. |
| 2071 |
|
| 2072 |
Generate_Reference (Entity (Expr), Expr); |
| 2073 |
|
| 2074 |
elsif Nkind (Expr) = N_Function_Call then |
| 2075 |
|
| 2076 |
-- If the name of the indexing function is overloaded, locate the one |
| 2077 |
-- whose return type has an implicit dereference on the desired |
| 2078 |
-- discriminant, and set entity and type of function call. |
| 2079 |
|
| 2080 |
if Is_Overloaded (Name (Expr)) then |
| 2081 |
Get_First_Interp (Name (Expr), I, It); |
| 2082 |
|
| 2083 |
while Present (It.Nam) loop |
| 2084 |
if Ekind ((It.Typ)) = E_Record_Type |
| 2085 |
and then First_Entity ((It.Typ)) = Disc |
| 2086 |
then |
| 2087 |
Set_Entity (Name (Expr), It.Nam); |
| 2088 |
Set_Etype (Name (Expr), Etype (It.Nam)); |
| 2089 |
exit; |
| 2090 |
end if; |
| 2091 |
|
| 2092 |
Get_Next_Interp (I, It); |
| 2093 |
end loop; |
| 2094 |
end if; |
| 2095 |
|
| 2096 |
-- Set type of call from resolved function name. |
| 2097 |
|
| 2098 |
Set_Etype (Expr, Etype (Name (Expr))); |
| 2099 |
end if; |
| 2100 |
|
| 2101 |
Set_Is_Overloaded (Expr, False); |
| 2102 |
|
| 2103 |
-- The expression will often be a generalized indexing that yields a |
| 2104 |
-- container element that is then dereferenced, in which case the |
| 2105 |
-- generalized indexing call is also non-overloaded. |
| 2106 |
|
| 2107 |
if Nkind (Expr) = N_Indexed_Component |
| 2108 |
and then Present (Generalized_Indexing (Expr)) |
| 2109 |
then |
| 2110 |
Set_Is_Overloaded (Generalized_Indexing (Expr), False); |
| 2111 |
end if; |
| 2112 |
|
| 2113 |
Rewrite (Expr, |
| 2114 |
Make_Explicit_Dereference (Loc, |
| 2115 |
Prefix => |
| 2116 |
Make_Selected_Component (Loc, |
| 2117 |
Prefix => Relocate_Node (Expr), |
| 2118 |
Selector_Name => New_Occurrence_Of (Disc, Loc)))); |
| 2119 |
Set_Etype (Prefix (Expr), Etype (Disc)); |
| 2120 |
Set_Etype (Expr, Designated_Type (Etype (Disc))); |
| 2121 |
end Build_Explicit_Dereference; |
| 2122 |
|
| 2123 |
--------------------------- |
| 2124 |
-- Build_Overriding_Spec -- |
| 2125 |
--------------------------- |
| 2126 |
|
| 2127 |
function Build_Overriding_Spec |
| 2128 |
(Op : Entity_Id; |
| 2129 |
Typ : Entity_Id) return Node_Id |
| 2130 |
is |
| 2131 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 2132 |
Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op); |
| 2133 |
Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op)); |
| 2134 |
|
| 2135 |
Formal_Spec : Node_Id; |
| 2136 |
Formal_Type : Node_Id; |
| 2137 |
New_Spec : Node_Id; |
| 2138 |
|
| 2139 |
begin |
| 2140 |
New_Spec := Copy_Subprogram_Spec (Spec); |
| 2141 |
|
| 2142 |
Formal_Spec := First (Parameter_Specifications (New_Spec)); |
| 2143 |
while Present (Formal_Spec) loop |
| 2144 |
Formal_Type := Parameter_Type (Formal_Spec); |
| 2145 |
|
| 2146 |
if Is_Entity_Name (Formal_Type) |
| 2147 |
and then Entity (Formal_Type) = Par_Typ |
| 2148 |
then |
| 2149 |
Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc)); |
| 2150 |
|
| 2151 |
elsif Nkind (Formal_Type) = N_Access_Definition |
| 2152 |
and then Entity (Subtype_Mark (Formal_Type)) = Par_Typ |
| 2153 |
then |
| 2154 |
Rewrite (Subtype_Mark (Formal_Type), New_Occurrence_Of (Typ, Loc)); |
| 2155 |
end if; |
| 2156 |
|
| 2157 |
Next (Formal_Spec); |
| 2158 |
end loop; |
| 2159 |
|
| 2160 |
return New_Spec; |
| 2161 |
end Build_Overriding_Spec; |
| 2162 |
|
| 2163 |
------------------- |
| 2164 |
-- Build_Subtype -- |
| 2165 |
------------------- |
| 2166 |
|
| 2167 |
function Build_Subtype |
| 2168 |
(Related_Node : Node_Id; |
| 2169 |
Loc : Source_Ptr; |
| 2170 |
Typ : Entity_Id; |
| 2171 |
Constraints : List_Id) |
| 2172 |
return Entity_Id |
| 2173 |
is |
| 2174 |
Indic : Node_Id; |
| 2175 |
Subtyp_Decl : Node_Id; |
| 2176 |
Def_Id : Entity_Id; |
| 2177 |
Btyp : Entity_Id := Base_Type (Typ); |
| 2178 |
|
| 2179 |
begin |
| 2180 |
-- The Related_Node better be here or else we won't be able to |
| 2181 |
-- attach new itypes to a node in the tree. |
| 2182 |
|
| 2183 |
pragma Assert (Present (Related_Node)); |
| 2184 |
|
| 2185 |
-- If the view of the component's type is incomplete or private |
| 2186 |
-- with unknown discriminants, then the constraint must be applied |
| 2187 |
-- to the full type. |
| 2188 |
|
| 2189 |
if Has_Unknown_Discriminants (Btyp) |
| 2190 |
and then Present (Underlying_Type (Btyp)) |
| 2191 |
then |
| 2192 |
Btyp := Underlying_Type (Btyp); |
| 2193 |
end if; |
| 2194 |
|
| 2195 |
Indic := |
| 2196 |
Make_Subtype_Indication (Loc, |
| 2197 |
Subtype_Mark => New_Occurrence_Of (Btyp, Loc), |
| 2198 |
Constraint => |
| 2199 |
Make_Index_Or_Discriminant_Constraint (Loc, Constraints)); |
| 2200 |
|
| 2201 |
Def_Id := Create_Itype (Ekind (Typ), Related_Node); |
| 2202 |
|
| 2203 |
Subtyp_Decl := |
| 2204 |
Make_Subtype_Declaration (Loc, |
| 2205 |
Defining_Identifier => Def_Id, |
| 2206 |
Subtype_Indication => Indic); |
| 2207 |
|
| 2208 |
Set_Parent (Subtyp_Decl, Parent (Related_Node)); |
| 2209 |
|
| 2210 |
-- Itypes must be analyzed with checks off (see package Itypes) |
| 2211 |
|
| 2212 |
Analyze (Subtyp_Decl, Suppress => All_Checks); |
| 2213 |
|
| 2214 |
if Is_Itype (Def_Id) and then Has_Predicates (Typ) then |
| 2215 |
Inherit_Predicate_Flags (Def_Id, Typ); |
| 2216 |
|
| 2217 |
-- Indicate where the predicate function may be found |
| 2218 |
|
| 2219 |
if Is_Itype (Typ) then |
| 2220 |
if Present (Predicate_Function (Def_Id)) then |
| 2221 |
null; |
| 2222 |
|
| 2223 |
elsif Present (Predicate_Function (Typ)) then |
| 2224 |
Set_Predicate_Function (Def_Id, Predicate_Function (Typ)); |
| 2225 |
|
| 2226 |
else |
| 2227 |
Set_Predicated_Parent (Def_Id, Predicated_Parent (Typ)); |
| 2228 |
end if; |
| 2229 |
|
| 2230 |
elsif No (Predicate_Function (Def_Id)) then |
| 2231 |
Set_Predicated_Parent (Def_Id, Typ); |
| 2232 |
end if; |
| 2233 |
end if; |
| 2234 |
|
| 2235 |
return Def_Id; |
| 2236 |
end Build_Subtype; |
| 2237 |
|
| 2238 |
----------------------------------- |
| 2239 |
-- Cannot_Raise_Constraint_Error -- |
| 2240 |
----------------------------------- |
| 2241 |
|
| 2242 |
function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is |
| 2243 |
|
| 2244 |
function List_Cannot_Raise_CE (L : List_Id) return Boolean; |
| 2245 |
-- Returns True if none of the list members cannot possibly raise |
| 2246 |
-- Constraint_Error. |
| 2247 |
|
| 2248 |
-------------------------- |
| 2249 |
-- List_Cannot_Raise_CE -- |
| 2250 |
-------------------------- |
| 2251 |
|
| 2252 |
function List_Cannot_Raise_CE (L : List_Id) return Boolean is |
| 2253 |
N : Node_Id; |
| 2254 |
begin |
| 2255 |
N := First (L); |
| 2256 |
while Present (N) loop |
| 2257 |
if Cannot_Raise_Constraint_Error (N) then |
| 2258 |
Next (N); |
| 2259 |
else |
| 2260 |
return False; |
| 2261 |
end if; |
| 2262 |
end loop; |
| 2263 |
|
| 2264 |
return True; |
| 2265 |
end List_Cannot_Raise_CE; |
| 2266 |
|
| 2267 |
-- Start of processing for Cannot_Raise_Constraint_Error |
| 2268 |
|
| 2269 |
begin |
| 2270 |
if Compile_Time_Known_Value (Expr) then |
| 2271 |
return True; |
| 2272 |
|
| 2273 |
elsif Do_Range_Check (Expr) then |
| 2274 |
return False; |
| 2275 |
|
| 2276 |
elsif Raises_Constraint_Error (Expr) then |
| 2277 |
return False; |
| 2278 |
|
| 2279 |
else |
| 2280 |
case Nkind (Expr) is |
| 2281 |
when N_Identifier => |
| 2282 |
return True; |
| 2283 |
|
| 2284 |
when N_Expanded_Name => |
| 2285 |
return True; |
| 2286 |
|
| 2287 |
when N_Indexed_Component => |
| 2288 |
return not Do_Range_Check (Expr) |
| 2289 |
and then Cannot_Raise_Constraint_Error (Prefix (Expr)) |
| 2290 |
and then List_Cannot_Raise_CE (Expressions (Expr)); |
| 2291 |
|
| 2292 |
when N_Selected_Component => |
| 2293 |
return not Do_Discriminant_Check (Expr) |
| 2294 |
and then Cannot_Raise_Constraint_Error (Prefix (Expr)); |
| 2295 |
|
| 2296 |
when N_Attribute_Reference => |
| 2297 |
if Do_Overflow_Check (Expr) then |
| 2298 |
return False; |
| 2299 |
|
| 2300 |
elsif No (Expressions (Expr)) then |
| 2301 |
return True; |
| 2302 |
|
| 2303 |
else |
| 2304 |
return List_Cannot_Raise_CE (Expressions (Expr)); |
| 2305 |
end if; |
| 2306 |
|
| 2307 |
when N_Type_Conversion => |
| 2308 |
if Do_Overflow_Check (Expr) |
| 2309 |
or else Do_Length_Check (Expr) |
| 2310 |
then |
| 2311 |
return False; |
| 2312 |
else |
| 2313 |
return Cannot_Raise_Constraint_Error (Expression (Expr)); |
| 2314 |
end if; |
| 2315 |
|
| 2316 |
when N_Unchecked_Type_Conversion => |
| 2317 |
return Cannot_Raise_Constraint_Error (Expression (Expr)); |
| 2318 |
|
| 2319 |
when N_Unary_Op => |
| 2320 |
if Do_Overflow_Check (Expr) then |
| 2321 |
return False; |
| 2322 |
else |
| 2323 |
return Cannot_Raise_Constraint_Error (Right_Opnd (Expr)); |
| 2324 |
end if; |
| 2325 |
|
| 2326 |
when N_Op_Divide |
| 2327 |
| N_Op_Mod |
| 2328 |
| N_Op_Rem |
| 2329 |
=> |
| 2330 |
if Do_Division_Check (Expr) |
| 2331 |
or else |
| 2332 |
Do_Overflow_Check (Expr) |
| 2333 |
then |
| 2334 |
return False; |
| 2335 |
else |
| 2336 |
return |
| 2337 |
Cannot_Raise_Constraint_Error (Left_Opnd (Expr)) |
| 2338 |
and then |
| 2339 |
Cannot_Raise_Constraint_Error (Right_Opnd (Expr)); |
| 2340 |
end if; |
| 2341 |
|
| 2342 |
when N_Op_Add |
| 2343 |
| N_Op_And |
| 2344 |
| N_Op_Concat |
| 2345 |
| N_Op_Eq |
| 2346 |
| N_Op_Expon |
| 2347 |
| N_Op_Ge |
| 2348 |
| N_Op_Gt |
| 2349 |
| N_Op_Le |
| 2350 |
| N_Op_Lt |
| 2351 |
| N_Op_Multiply |
| 2352 |
| N_Op_Ne |
| 2353 |
| N_Op_Or |
| 2354 |
| N_Op_Rotate_Left |
| 2355 |
| N_Op_Rotate_Right |
| 2356 |
| N_Op_Shift_Left |
| 2357 |
| N_Op_Shift_Right |
| 2358 |
| N_Op_Shift_Right_Arithmetic |
| 2359 |
| N_Op_Subtract |
| 2360 |
| N_Op_Xor |
| 2361 |
=> |
| 2362 |
if Do_Overflow_Check (Expr) then |
| 2363 |
return False; |
| 2364 |
else |
| 2365 |
return |
| 2366 |
Cannot_Raise_Constraint_Error (Left_Opnd (Expr)) |
| 2367 |
and then |
| 2368 |
Cannot_Raise_Constraint_Error (Right_Opnd (Expr)); |
| 2369 |
end if; |
| 2370 |
|
| 2371 |
when others => |
| 2372 |
return False; |
| 2373 |
end case; |
| 2374 |
end if; |
| 2375 |
end Cannot_Raise_Constraint_Error; |
| 2376 |
|
| 2377 |
------------------------------- |
| 2378 |
-- Check_Ambiguous_Aggregate -- |
| 2379 |
------------------------------- |
| 2380 |
|
| 2381 |
procedure Check_Ambiguous_Aggregate (Call : Node_Id) is |
| 2382 |
Actual : Node_Id; |
| 2383 |
|
| 2384 |
begin |
| 2385 |
if Ada_Version >= Ada_2022 then |
| 2386 |
Actual := First_Actual (Call); |
| 2387 |
while Present (Actual) loop |
| 2388 |
if Nkind (Actual) = N_Aggregate then |
| 2389 |
Error_Msg_N |
| 2390 |
("\add type qualification to aggregate actual", Actual); |
| 2391 |
exit; |
| 2392 |
end if; |
| 2393 |
Next_Actual (Actual); |
| 2394 |
end loop; |
| 2395 |
end if; |
| 2396 |
end Check_Ambiguous_Aggregate; |
| 2397 |
|
| 2398 |
----------------------------------------- |
| 2399 |
-- Check_Dynamically_Tagged_Expression -- |
| 2400 |
----------------------------------------- |
| 2401 |
|
| 2402 |
procedure Check_Dynamically_Tagged_Expression |
| 2403 |
(Expr : Node_Id; |
| 2404 |
Typ : Entity_Id; |
| 2405 |
Related_Nod : Node_Id) |
| 2406 |
is |
| 2407 |
begin |
| 2408 |
pragma Assert (Is_Tagged_Type (Typ)); |
| 2409 |
|
| 2410 |
-- In order to avoid spurious errors when analyzing the expanded code, |
| 2411 |
-- this check is done only for nodes that come from source and for |
| 2412 |
-- actuals of generic instantiations. |
| 2413 |
|
| 2414 |
if (Comes_From_Source (Related_Nod) |
| 2415 |
or else In_Generic_Actual (Expr)) |
| 2416 |
and then (Is_Class_Wide_Type (Etype (Expr)) |
| 2417 |
or else Is_Dynamically_Tagged (Expr)) |
| 2418 |
and then not Is_Class_Wide_Type (Typ) |
| 2419 |
then |
| 2420 |
Error_Msg_N ("dynamically tagged expression not allowed!", Expr); |
| 2421 |
end if; |
| 2422 |
end Check_Dynamically_Tagged_Expression; |
| 2423 |
|
| 2424 |
-------------------------- |
| 2425 |
-- Check_Fully_Declared -- |
| 2426 |
-------------------------- |
| 2427 |
|
| 2428 |
procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is |
| 2429 |
begin |
| 2430 |
if Ekind (T) = E_Incomplete_Type then |
| 2431 |
|
| 2432 |
-- Ada 2005 (AI-50217): If the type is available through a limited |
| 2433 |
-- with_clause, verify that its full view has been analyzed. |
| 2434 |
|
| 2435 |
if From_Limited_With (T) |
| 2436 |
and then Present (Non_Limited_View (T)) |
| 2437 |
and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type |
| 2438 |
then |
| 2439 |
-- The non-limited view is fully declared |
| 2440 |
|
| 2441 |
null; |
| 2442 |
|
| 2443 |
else |
| 2444 |
Error_Msg_NE |
| 2445 |
("premature usage of incomplete}", N, First_Subtype (T)); |
| 2446 |
end if; |
| 2447 |
|
| 2448 |
-- Need comments for these tests ??? |
| 2449 |
|
| 2450 |
elsif Has_Private_Component (T) |
| 2451 |
and then not Is_Generic_Type (Root_Type (T)) |
| 2452 |
and then not In_Spec_Expression |
| 2453 |
then |
| 2454 |
-- Special case: if T is the anonymous type created for a single |
| 2455 |
-- task or protected object, use the name of the source object. |
| 2456 |
|
| 2457 |
if Is_Concurrent_Type (T) |
| 2458 |
and then not Comes_From_Source (T) |
| 2459 |
and then Nkind (N) = N_Object_Declaration |
| 2460 |
then |
| 2461 |
Error_Msg_NE |
| 2462 |
("type of& has incomplete component", |
| 2463 |
N, Defining_Identifier (N)); |
| 2464 |
else |
| 2465 |
Error_Msg_NE |
| 2466 |
("premature usage of incomplete}", |
| 2467 |
N, First_Subtype (T)); |
| 2468 |
end if; |
| 2469 |
end if; |
| 2470 |
end Check_Fully_Declared; |
| 2471 |
|
| 2472 |
------------------------------------------- |
| 2473 |
-- Check_Function_With_Address_Parameter -- |
| 2474 |
------------------------------------------- |
| 2475 |
|
| 2476 |
procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is |
| 2477 |
F : Entity_Id; |
| 2478 |
T : Entity_Id; |
| 2479 |
|
| 2480 |
begin |
| 2481 |
F := First_Formal (Subp_Id); |
| 2482 |
while Present (F) loop |
| 2483 |
T := Etype (F); |
| 2484 |
|
| 2485 |
if Is_Private_Type (T) and then Present (Full_View (T)) then |
| 2486 |
T := Full_View (T); |
| 2487 |
end if; |
| 2488 |
|
| 2489 |
if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then |
| 2490 |
Set_Is_Pure (Subp_Id, False); |
| 2491 |
exit; |
| 2492 |
end if; |
| 2493 |
|
| 2494 |
Next_Formal (F); |
| 2495 |
end loop; |
| 2496 |
end Check_Function_With_Address_Parameter; |
| 2497 |
|
| 2498 |
------------------------------------- |
| 2499 |
-- Check_Function_Writable_Actuals -- |
| 2500 |
------------------------------------- |
| 2501 |
|
| 2502 |
procedure Check_Function_Writable_Actuals (N : Node_Id) is |
| 2503 |
Writable_Actuals_List : Elist_Id := No_Elist; |
| 2504 |
Identifiers_List : Elist_Id := No_Elist; |
| 2505 |
Aggr_Error_Node : Node_Id := Empty; |
| 2506 |
Error_Node : Node_Id := Empty; |
| 2507 |
|
| 2508 |
procedure Collect_Identifiers (N : Node_Id); |
| 2509 |
-- In a single traversal of subtree N collect in Writable_Actuals_List |
| 2510 |
-- all the actuals of functions with writable actuals, and in the list |
| 2511 |
-- Identifiers_List collect all the identifiers that are not actuals of |
| 2512 |
-- functions with writable actuals. If a writable actual is referenced |
| 2513 |
-- twice as writable actual then Error_Node is set to reference its |
| 2514 |
-- second occurrence, the error is reported, and the tree traversal |
| 2515 |
-- is abandoned. |
| 2516 |
|
| 2517 |
------------------------- |
| 2518 |
-- Collect_Identifiers -- |
| 2519 |
------------------------- |
| 2520 |
|
| 2521 |
procedure Collect_Identifiers (N : Node_Id) is |
| 2522 |
|
| 2523 |
function Check_Node (N : Node_Id) return Traverse_Result; |
| 2524 |
-- Process a single node during the tree traversal to collect the |
| 2525 |
-- writable actuals of functions and all the identifiers which are |
| 2526 |
-- not writable actuals of functions. |
| 2527 |
|
| 2528 |
function Contains (List : Elist_Id; N : Node_Id) return Boolean; |
| 2529 |
-- Returns True if List has a node whose Entity is Entity (N) |
| 2530 |
|
| 2531 |
---------------- |
| 2532 |
-- Check_Node -- |
| 2533 |
---------------- |
| 2534 |
|
| 2535 |
function Check_Node (N : Node_Id) return Traverse_Result is |
| 2536 |
Is_Writable_Actual : Boolean := False; |
| 2537 |
Id : Entity_Id := Empty; |
| 2538 |
-- Default init of Id for CodePeer |
| 2539 |
|
| 2540 |
begin |
| 2541 |
if Nkind (N) = N_Identifier then |
| 2542 |
|
| 2543 |
-- No analysis possible if the entity is not decorated |
| 2544 |
|
| 2545 |
if No (Entity (N)) then |
| 2546 |
return Skip; |
| 2547 |
|
| 2548 |
-- Don't collect identifiers of packages, called functions, etc |
| 2549 |
|
| 2550 |
elsif Ekind (Entity (N)) in |
| 2551 |
E_Package | E_Function | E_Procedure | E_Entry |
| 2552 |
then |
| 2553 |
return Skip; |
| 2554 |
|
| 2555 |
-- For rewritten nodes, continue the traversal in the original |
| 2556 |
-- subtree. Needed to handle aggregates in original expressions |
| 2557 |
-- extracted from the tree by Remove_Side_Effects. |
| 2558 |
|
| 2559 |
elsif Is_Rewrite_Substitution (N) then |
| 2560 |
Collect_Identifiers (Original_Node (N)); |
| 2561 |
return Skip; |
| 2562 |
|
| 2563 |
-- For now we skip aggregate discriminants, since they require |
| 2564 |
-- performing the analysis in two phases to identify conflicts: |
| 2565 |
-- first one analyzing discriminants and second one analyzing |
| 2566 |
-- the rest of components (since at run time, discriminants are |
| 2567 |
-- evaluated prior to components): too much computation cost |
| 2568 |
-- to identify a corner case??? |
| 2569 |
|
| 2570 |
elsif Nkind (Parent (N)) = N_Component_Association |
| 2571 |
and then Nkind (Parent (Parent (N))) in |
| 2572 |
N_Aggregate | N_Extension_Aggregate |
| 2573 |
then |
| 2574 |
declare |
| 2575 |
Choice : constant Node_Id := First (Choices (Parent (N))); |
| 2576 |
|
| 2577 |
begin |
| 2578 |
if Ekind (Entity (N)) = E_Discriminant then |
| 2579 |
return Skip; |
| 2580 |
|
| 2581 |
elsif Expression (Parent (N)) = N |
| 2582 |
and then Nkind (Choice) = N_Identifier |
| 2583 |
and then Ekind (Entity (Choice)) = E_Discriminant |
| 2584 |
then |
| 2585 |
return Skip; |
| 2586 |
end if; |
| 2587 |
end; |
| 2588 |
|
| 2589 |
-- Analyze if N is a writable actual of a function |
| 2590 |
|
| 2591 |
elsif Nkind (Parent (N)) = N_Function_Call then |
| 2592 |
declare |
| 2593 |
Call : constant Node_Id := Parent (N); |
| 2594 |
Actual : Node_Id; |
| 2595 |
Formal : Node_Id; |
| 2596 |
|
| 2597 |
begin |
| 2598 |
Id := Get_Called_Entity (Call); |
| 2599 |
|
| 2600 |
-- In case of previous error, no check is possible |
| 2601 |
|
| 2602 |
if No (Id) then |
| 2603 |
return Abandon; |
| 2604 |
end if; |
| 2605 |
|
| 2606 |
if Ekind (Id) in E_Function | E_Generic_Function |
| 2607 |
and then Has_Out_Or_In_Out_Parameter (Id) |
| 2608 |
then |
| 2609 |
Formal := First_Formal (Id); |
| 2610 |
Actual := First_Actual (Call); |
| 2611 |
while Present (Actual) and then Present (Formal) loop |
| 2612 |
if Actual = N then |
| 2613 |
if Ekind (Formal) in E_Out_Parameter |
| 2614 |
| E_In_Out_Parameter |
| 2615 |
then |
| 2616 |
Is_Writable_Actual := True; |
| 2617 |
end if; |
| 2618 |
|
| 2619 |
exit; |
| 2620 |
end if; |
| 2621 |
|
| 2622 |
Next_Formal (Formal); |
| 2623 |
Next_Actual (Actual); |
| 2624 |
end loop; |
| 2625 |
end if; |
| 2626 |
end; |
| 2627 |
end if; |
| 2628 |
|
| 2629 |
if Is_Writable_Actual then |
| 2630 |
|
| 2631 |
-- Skip checking the error in non-elementary types since |
| 2632 |
-- RM 6.4.1(6.15/3) is restricted to elementary types, but |
| 2633 |
-- store this actual in Writable_Actuals_List since it is |
| 2634 |
-- needed to perform checks on other constructs that have |
| 2635 |
-- arbitrary order of evaluation (for example, aggregates). |
| 2636 |
|
| 2637 |
if not Is_Elementary_Type (Etype (N)) then |
| 2638 |
if not Contains (Writable_Actuals_List, N) then |
| 2639 |
Append_New_Elmt (N, To => Writable_Actuals_List); |
| 2640 |
end if; |
| 2641 |
|
| 2642 |
-- Second occurrence of an elementary type writable actual |
| 2643 |
|
| 2644 |
elsif Contains (Writable_Actuals_List, N) then |
| 2645 |
|
| 2646 |
-- Report the error on the second occurrence of the |
| 2647 |
-- identifier. We cannot assume that N is the second |
| 2648 |
-- occurrence (according to their location in the |
| 2649 |
-- sources), since Traverse_Func walks through Field2 |
| 2650 |
-- last (see comment in the body of Traverse_Func). |
| 2651 |
|
| 2652 |
declare |
| 2653 |
Elmt : Elmt_Id; |
| 2654 |
|
| 2655 |
begin |
| 2656 |
Elmt := First_Elmt (Writable_Actuals_List); |
| 2657 |
while Present (Elmt) |
| 2658 |
and then Entity (Node (Elmt)) /= Entity (N) |
| 2659 |
loop |
| 2660 |
Next_Elmt (Elmt); |
| 2661 |
end loop; |
| 2662 |
|
| 2663 |
if Sloc (N) > Sloc (Node (Elmt)) then |
| 2664 |
Error_Node := N; |
| 2665 |
else |
| 2666 |
Error_Node := Node (Elmt); |
| 2667 |
end if; |
| 2668 |
|
| 2669 |
Error_Msg_NE |
| 2670 |
("value may be affected by call to & " |
| 2671 |
& "because order of evaluation is arbitrary", |
| 2672 |
Error_Node, Id); |
| 2673 |
return Abandon; |
| 2674 |
end; |
| 2675 |
|
| 2676 |
-- First occurrence of a elementary type writable actual |
| 2677 |
|
| 2678 |
else |
| 2679 |
Append_New_Elmt (N, To => Writable_Actuals_List); |
| 2680 |
end if; |
| 2681 |
|
| 2682 |
else |
| 2683 |
if No (Identifiers_List) then |
| 2684 |
Identifiers_List := New_Elmt_List; |
| 2685 |
end if; |
| 2686 |
|
| 2687 |
Append_Unique_Elmt (N, Identifiers_List); |
| 2688 |
end if; |
| 2689 |
end if; |
| 2690 |
|
| 2691 |
return OK; |
| 2692 |
end Check_Node; |
| 2693 |
|
| 2694 |
-------------- |
| 2695 |
-- Contains -- |
| 2696 |
-------------- |
| 2697 |
|
| 2698 |
function Contains |
| 2699 |
(List : Elist_Id; |
| 2700 |
N : Node_Id) return Boolean |
| 2701 |
is |
| 2702 |
pragma Assert (Nkind (N) in N_Has_Entity); |
| 2703 |
|
| 2704 |
Elmt : Elmt_Id; |
| 2705 |
|
| 2706 |
begin |
| 2707 |
if No (List) then |
| 2708 |
return False; |
| 2709 |
end if; |
| 2710 |
|
| 2711 |
Elmt := First_Elmt (List); |
| 2712 |
while Present (Elmt) loop |
| 2713 |
if Entity (Node (Elmt)) = Entity (N) then |
| 2714 |
return True; |
| 2715 |
else |
| 2716 |
Next_Elmt (Elmt); |
| 2717 |
end if; |
| 2718 |
end loop; |
| 2719 |
|
| 2720 |
return False; |
| 2721 |
end Contains; |
| 2722 |
|
| 2723 |
------------------ |
| 2724 |
-- Do_Traversal -- |
| 2725 |
------------------ |
| 2726 |
|
| 2727 |
procedure Do_Traversal is new Traverse_Proc (Check_Node); |
| 2728 |
-- The traversal procedure |
| 2729 |
|
| 2730 |
-- Start of processing for Collect_Identifiers |
| 2731 |
|
| 2732 |
begin |
| 2733 |
if Present (Error_Node) then |
| 2734 |
return; |
| 2735 |
end if; |
| 2736 |
|
| 2737 |
if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then |
| 2738 |
return; |
| 2739 |
end if; |
| 2740 |
|
| 2741 |
Do_Traversal (N); |
| 2742 |
end Collect_Identifiers; |
| 2743 |
|
| 2744 |
-- Start of processing for Check_Function_Writable_Actuals |
| 2745 |
|
| 2746 |
begin |
| 2747 |
-- The check only applies to Ada 2012 code on which Check_Actuals has |
| 2748 |
-- been set, and only to constructs that have multiple constituents |
| 2749 |
-- whose order of evaluation is not specified by the language. |
| 2750 |
|
| 2751 |
if Ada_Version < Ada_2012 |
| 2752 |
or else not Check_Actuals (N) |
| 2753 |
or else Nkind (N) not in N_Op |
| 2754 |
| N_Membership_Test |
| 2755 |
| N_Range |
| 2756 |
| N_Aggregate |
| 2757 |
| N_Extension_Aggregate |
| 2758 |
| N_Full_Type_Declaration |
| 2759 |
| N_Function_Call |
| 2760 |
| N_Procedure_Call_Statement |
| 2761 |
| N_Entry_Call_Statement |
| 2762 |
or else (Nkind (N) = N_Full_Type_Declaration |
| 2763 |
and then not Is_Record_Type (Defining_Identifier (N))) |
| 2764 |
|
| 2765 |
-- In addition, this check only applies to source code, not to code |
| 2766 |
-- generated by constraint checks. |
| 2767 |
|
| 2768 |
or else not Comes_From_Source (N) |
| 2769 |
then |
| 2770 |
return; |
| 2771 |
end if; |
| 2772 |
|
| 2773 |
-- If a construct C has two or more direct constituents that are names |
| 2774 |
-- or expressions whose evaluation may occur in an arbitrary order, at |
| 2775 |
-- least one of which contains a function call with an in out or out |
| 2776 |
-- parameter, then the construct is legal only if: for each name N that |
| 2777 |
-- is passed as a parameter of mode in out or out to some inner function |
| 2778 |
-- call C2 (not including the construct C itself), there is no other |
| 2779 |
-- name anywhere within a direct constituent of the construct C other |
| 2780 |
-- than the one containing C2, that is known to refer to the same |
| 2781 |
-- object (RM 6.4.1(6.17/3)). |
| 2782 |
|
| 2783 |
case Nkind (N) is |
| 2784 |
when N_Range => |
| 2785 |
Collect_Identifiers (Low_Bound (N)); |
| 2786 |
Collect_Identifiers (High_Bound (N)); |
| 2787 |
|
| 2788 |
when N_Membership_Test |
| 2789 |
| N_Op |
| 2790 |
=> |
| 2791 |
declare |
| 2792 |
Expr : Node_Id; |
| 2793 |
|
| 2794 |
begin |
| 2795 |
Collect_Identifiers (Left_Opnd (N)); |
| 2796 |
|
| 2797 |
if Present (Right_Opnd (N)) then |
| 2798 |
Collect_Identifiers (Right_Opnd (N)); |
| 2799 |
end if; |
| 2800 |
|
| 2801 |
if Nkind (N) in N_Membership_Test then |
| 2802 |
Expr := First (Alternatives (N)); |
| 2803 |
while Present (Expr) loop |
| 2804 |
Collect_Identifiers (Expr); |
| 2805 |
|
| 2806 |
Next (Expr); |
| 2807 |
end loop; |
| 2808 |
end if; |
| 2809 |
end; |
| 2810 |
|
| 2811 |
when N_Full_Type_Declaration => |
| 2812 |
declare |
| 2813 |
function Get_Record_Part (N : Node_Id) return Node_Id; |
| 2814 |
-- Return the record part of this record type definition |
| 2815 |
|
| 2816 |
--------------------- |
| 2817 |
-- Get_Record_Part -- |
| 2818 |
--------------------- |
| 2819 |
|
| 2820 |
function Get_Record_Part (N : Node_Id) return Node_Id is |
| 2821 |
Type_Def : constant Node_Id := Type_Definition (N); |
| 2822 |
begin |
| 2823 |
if Nkind (Type_Def) = N_Derived_Type_Definition then |
| 2824 |
return Record_Extension_Part (Type_Def); |
| 2825 |
else |
| 2826 |
return Type_Def; |
| 2827 |
end if; |
| 2828 |
end Get_Record_Part; |
| 2829 |
|
| 2830 |
Comp : Node_Id; |
| 2831 |
Def_Id : Entity_Id := Defining_Identifier (N); |
| 2832 |
Rec : Node_Id := Get_Record_Part (N); |
| 2833 |
|
| 2834 |
begin |
| 2835 |
-- No need to perform any analysis if the record has no |
| 2836 |
-- components |
| 2837 |
|
| 2838 |
if No (Rec) or else No (Component_List (Rec)) then |
| 2839 |
return; |
| 2840 |
end if; |
| 2841 |
|
| 2842 |
-- Collect the identifiers starting from the deepest |
| 2843 |
-- derivation. Done to report the error in the deepest |
| 2844 |
-- derivation. |
| 2845 |
|
| 2846 |
loop |
| 2847 |
if Present (Component_List (Rec)) then |
| 2848 |
Comp := First (Component_Items (Component_List (Rec))); |
| 2849 |
while Present (Comp) loop |
| 2850 |
if Nkind (Comp) = N_Component_Declaration |
| 2851 |
and then Present (Expression (Comp)) |
| 2852 |
then |
| 2853 |
Collect_Identifiers (Expression (Comp)); |
| 2854 |
end if; |
| 2855 |
|
| 2856 |
Next (Comp); |
| 2857 |
end loop; |
| 2858 |
end if; |
| 2859 |
|
| 2860 |
exit when No (Underlying_Type (Etype (Def_Id))) |
| 2861 |
or else Base_Type (Underlying_Type (Etype (Def_Id))) |
| 2862 |
= Def_Id; |
| 2863 |
|
| 2864 |
Def_Id := Base_Type (Underlying_Type (Etype (Def_Id))); |
| 2865 |
Rec := Get_Record_Part (Parent (Def_Id)); |
| 2866 |
end loop; |
| 2867 |
end; |
| 2868 |
|
| 2869 |
when N_Entry_Call_Statement |
| 2870 |
| N_Subprogram_Call |
| 2871 |
=> |
| 2872 |
declare |
| 2873 |
Id : constant Entity_Id := Get_Called_Entity (N); |
| 2874 |
Formal : Node_Id; |
| 2875 |
Actual : Node_Id; |
| 2876 |
|
| 2877 |
begin |
| 2878 |
Formal := First_Formal (Id); |
| 2879 |
Actual := First_Actual (N); |
| 2880 |
while Present (Actual) and then Present (Formal) loop |
| 2881 |
if Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter |
| 2882 |
then |
| 2883 |
Collect_Identifiers (Actual); |
| 2884 |
end if; |
| 2885 |
|
| 2886 |
Next_Formal (Formal); |
| 2887 |
Next_Actual (Actual); |
| 2888 |
end loop; |
| 2889 |
end; |
| 2890 |
|
| 2891 |
when N_Aggregate |
| 2892 |
| N_Extension_Aggregate |
| 2893 |
=> |
| 2894 |
declare |
| 2895 |
Assoc : Node_Id; |
| 2896 |
Choice : Node_Id; |
| 2897 |
Comp_Expr : Node_Id; |
| 2898 |
|
| 2899 |
begin |
| 2900 |
-- Handle the N_Others_Choice of array aggregates with static |
| 2901 |
-- bounds. There is no need to perform this analysis in |
| 2902 |
-- aggregates without static bounds since we cannot evaluate |
| 2903 |
-- if the N_Others_Choice covers several elements. There is |
| 2904 |
-- no need to handle the N_Others choice of record aggregates |
| 2905 |
-- since at this stage it has been already expanded by |
| 2906 |
-- Resolve_Record_Aggregate. |
| 2907 |
|
| 2908 |
if Is_Array_Type (Etype (N)) |
| 2909 |
and then Nkind (N) = N_Aggregate |
| 2910 |
and then Present (Aggregate_Bounds (N)) |
| 2911 |
and then Compile_Time_Known_Bounds (Etype (N)) |
| 2912 |
and then Expr_Value (High_Bound (Aggregate_Bounds (N))) |
| 2913 |
> |
| 2914 |
Expr_Value (Low_Bound (Aggregate_Bounds (N))) |
| 2915 |
then |
| 2916 |
declare |
| 2917 |
Count_Components : Uint; |
| 2918 |
Num_Components : Uint; |
| 2919 |
Others_Assoc : Node_Id := Empty; |
| 2920 |
Others_Choice : Node_Id := Empty; |
| 2921 |
Others_Box_Present : Boolean := False; |
| 2922 |
|
| 2923 |
begin |
| 2924 |
-- Count positional associations |
| 2925 |
|
| 2926 |
Count_Components := |
| 2927 |
UI_From_Int (List_Length (Expressions (N))); |
| 2928 |
|
| 2929 |
-- Count the rest of elements and locate the N_Others |
| 2930 |
-- choice (if any) |
| 2931 |
|
| 2932 |
Assoc := First (Component_Associations (N)); |
| 2933 |
while Present (Assoc) loop |
| 2934 |
Choice := First (Choices (Assoc)); |
| 2935 |
while Present (Choice) loop |
| 2936 |
if Nkind (Choice) = N_Others_Choice then |
| 2937 |
Others_Assoc := Assoc; |
| 2938 |
Others_Choice := Choice; |
| 2939 |
Others_Box_Present := Box_Present (Assoc); |
| 2940 |
|
| 2941 |
-- Count several components |
| 2942 |
|
| 2943 |
elsif Nkind (Choice) in |
| 2944 |
N_Range | N_Subtype_Indication |
| 2945 |
or else (Is_Entity_Name (Choice) |
| 2946 |
and then Is_Type (Entity (Choice))) |
| 2947 |
then |
| 2948 |
declare |
| 2949 |
L, H : Node_Id; |
| 2950 |
begin |
| 2951 |
Get_Index_Bounds (Choice, L, H); |
| 2952 |
pragma Assert |
| 2953 |
(Compile_Time_Known_Value (L) |
| 2954 |
and then Compile_Time_Known_Value (H)); |
| 2955 |
Count_Components := |
| 2956 |
Count_Components |
| 2957 |
+ Expr_Value (H) - Expr_Value (L) + 1; |
| 2958 |
end; |
| 2959 |
|
| 2960 |
-- Count single component. No other case available |
| 2961 |
-- since we are handling an aggregate with static |
| 2962 |
-- bounds. |
| 2963 |
|
| 2964 |
else |
| 2965 |
pragma Assert (Is_OK_Static_Expression (Choice) |
| 2966 |
or else Nkind (Choice) = N_Identifier |
| 2967 |
or else Nkind (Choice) = N_Integer_Literal); |
| 2968 |
|
| 2969 |
Count_Components := Count_Components + 1; |
| 2970 |
end if; |
| 2971 |
|
| 2972 |
Next (Choice); |
| 2973 |
end loop; |
| 2974 |
|
| 2975 |
Next (Assoc); |
| 2976 |
end loop; |
| 2977 |
|
| 2978 |
Num_Components := |
| 2979 |
Expr_Value (High_Bound (Aggregate_Bounds (N))) - |
| 2980 |
Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1; |
| 2981 |
|
| 2982 |
pragma Assert (Count_Components <= Num_Components); |
| 2983 |
|
| 2984 |
-- Handle the N_Others choice if it covers several |
| 2985 |
-- components |
| 2986 |
|
| 2987 |
if Present (Others_Choice) |
| 2988 |
and then (Num_Components - Count_Components) > 1 |
| 2989 |
then |
| 2990 |
if not Others_Box_Present then |
| 2991 |
|
| 2992 |
-- At this stage, if expansion is active, the |
| 2993 |
-- expression of the others choice has not been |
| 2994 |
-- analyzed. Hence we generate a duplicate and |
| 2995 |
-- we analyze it silently to have available the |
| 2996 |
-- minimum decoration required to collect the |
| 2997 |
-- identifiers. |
| 2998 |
|
| 2999 |
pragma Assert (Present (Others_Assoc)); |
| 3000 |
|
| 3001 |
if not Expander_Active then |
| 3002 |
Comp_Expr := Expression (Others_Assoc); |
| 3003 |
else |
| 3004 |
Comp_Expr := |
| 3005 |
New_Copy_Tree (Expression (Others_Assoc)); |
| 3006 |
Preanalyze_Without_Errors (Comp_Expr); |
| 3007 |
end if; |
| 3008 |
|
| 3009 |
Collect_Identifiers (Comp_Expr); |
| 3010 |
|
| 3011 |
if Present (Writable_Actuals_List) then |
| 3012 |
|
| 3013 |
-- As suggested by Robert, at current stage we |
| 3014 |
-- report occurrences of this case as warnings. |
| 3015 |
|
| 3016 |
Error_Msg_N |
| 3017 |
("writable function parameter may affect " |
| 3018 |
& "value in other component because order " |
| 3019 |
& "of evaluation is unspecified??", |
| 3020 |
Node (First_Elmt (Writable_Actuals_List))); |
| 3021 |
end if; |
| 3022 |
end if; |
| 3023 |
end if; |
| 3024 |
end; |
| 3025 |
|
| 3026 |
-- For an array aggregate, a discrete_choice_list that has |
| 3027 |
-- a nonstatic range is considered as two or more separate |
| 3028 |
-- occurrences of the expression (RM 6.4.1(6.20/3)). |
| 3029 |
|
| 3030 |
elsif Is_Array_Type (Etype (N)) |
| 3031 |
and then Nkind (N) = N_Aggregate |
| 3032 |
and then Present (Aggregate_Bounds (N)) |
| 3033 |
and then not Compile_Time_Known_Bounds (Etype (N)) |
| 3034 |
then |
| 3035 |
-- Collect identifiers found in the dynamic bounds |
| 3036 |
|
| 3037 |
declare |
| 3038 |
Count_Components : Natural := 0; |
| 3039 |
Low, High : Node_Id; |
| 3040 |
|
| 3041 |
begin |
| 3042 |
Assoc := First (Component_Associations (N)); |
| 3043 |
while Present (Assoc) loop |
| 3044 |
Choice := First (Choices (Assoc)); |
| 3045 |
while Present (Choice) loop |
| 3046 |
if Nkind (Choice) in |
| 3047 |
N_Range | N_Subtype_Indication |
| 3048 |
or else (Is_Entity_Name (Choice) |
| 3049 |
and then Is_Type (Entity (Choice))) |
| 3050 |
then |
| 3051 |
Get_Index_Bounds (Choice, Low, High); |
| 3052 |
|
| 3053 |
if not Compile_Time_Known_Value (Low) then |
| 3054 |
Collect_Identifiers (Low); |
| 3055 |
|
| 3056 |
if No (Aggr_Error_Node) then |
| 3057 |
Aggr_Error_Node := Low; |
| 3058 |
end if; |
| 3059 |
end if; |
| 3060 |
|
| 3061 |
if not Compile_Time_Known_Value (High) then |
| 3062 |
Collect_Identifiers (High); |
| 3063 |
|
| 3064 |
if No (Aggr_Error_Node) then |
| 3065 |
Aggr_Error_Node := High; |
| 3066 |
end if; |
| 3067 |
end if; |
| 3068 |
|
| 3069 |
-- The RM rule is violated if there is more than |
| 3070 |
-- a single choice in a component association. |
| 3071 |
|
| 3072 |
else |
| 3073 |
Count_Components := Count_Components + 1; |
| 3074 |
|
| 3075 |
if No (Aggr_Error_Node) |
| 3076 |
and then Count_Components > 1 |
| 3077 |
then |
| 3078 |
Aggr_Error_Node := Choice; |
| 3079 |
end if; |
| 3080 |
|
| 3081 |
if not Compile_Time_Known_Value (Choice) then |
| 3082 |
Collect_Identifiers (Choice); |
| 3083 |
end if; |
| 3084 |
end if; |
| 3085 |
|
| 3086 |
Next (Choice); |
| 3087 |
end loop; |
| 3088 |
|
| 3089 |
Next (Assoc); |
| 3090 |
end loop; |
| 3091 |
end; |
| 3092 |
end if; |
| 3093 |
|
| 3094 |
-- Handle ancestor part of extension aggregates |
| 3095 |
|
| 3096 |
if Nkind (N) = N_Extension_Aggregate then |
| 3097 |
Collect_Identifiers (Ancestor_Part (N)); |
| 3098 |
end if; |
| 3099 |
|
| 3100 |
-- Handle positional associations |
| 3101 |
|
| 3102 |
if Present (Expressions (N)) then |
| 3103 |
Comp_Expr := First (Expressions (N)); |
| 3104 |
while Present (Comp_Expr) loop |
| 3105 |
if not Is_OK_Static_Expression (Comp_Expr) then |
| 3106 |
Collect_Identifiers (Comp_Expr); |
| 3107 |
end if; |
| 3108 |
|
| 3109 |
Next (Comp_Expr); |
| 3110 |
end loop; |
| 3111 |
end if; |
| 3112 |
|
| 3113 |
-- Handle named associations |
| 3114 |
|
| 3115 |
if Present (Component_Associations (N)) then |
| 3116 |
Assoc := First (Component_Associations (N)); |
| 3117 |
while Present (Assoc) loop |
| 3118 |
|
| 3119 |
Handle_Association : declare |
| 3120 |
|
| 3121 |
procedure Collect_Expression_Ids (Expr : Node_Id); |
| 3122 |
-- Collect identifiers in association expression Expr |
| 3123 |
|
| 3124 |
procedure Handle_Association_Choices |
| 3125 |
(Choices : List_Id; Expr : Node_Id); |
| 3126 |
-- Collect identifiers in an association expression |
| 3127 |
-- Expr for each choice in Choices. |
| 3128 |
|
| 3129 |
---------------------------- |
| 3130 |
-- Collect_Expression_Ids -- |
| 3131 |
---------------------------- |
| 3132 |
|
| 3133 |
procedure Collect_Expression_Ids (Expr : Node_Id) is |
| 3134 |
Comp_Expr : Node_Id; |
| 3135 |
|
| 3136 |
begin |
| 3137 |
if not Analyzed (Expr) then |
| 3138 |
Comp_Expr := New_Copy_Tree (Expr); |
| 3139 |
Set_Parent (Comp_Expr, Parent (N)); |
| 3140 |
Preanalyze_Without_Errors (Comp_Expr); |
| 3141 |
else |
| 3142 |
Comp_Expr := Expr; |
| 3143 |
end if; |
| 3144 |
|
| 3145 |
Collect_Identifiers (Comp_Expr); |
| 3146 |
end Collect_Expression_Ids; |
| 3147 |
|
| 3148 |
-------------------------------- |
| 3149 |
-- Handle_Association_Choices -- |
| 3150 |
-------------------------------- |
| 3151 |
|
| 3152 |
procedure Handle_Association_Choices |
| 3153 |
(Choices : List_Id; Expr : Node_Id) |
| 3154 |
is |
| 3155 |
Choice : Node_Id := First (Choices); |
| 3156 |
|
| 3157 |
begin |
| 3158 |
while Present (Choice) loop |
| 3159 |
|
| 3160 |
-- For now skip discriminants since it requires |
| 3161 |
-- performing analysis in two phases: first one |
| 3162 |
-- analyzing discriminants and second analyzing |
| 3163 |
-- the rest of components since discriminants |
| 3164 |
-- are evaluated prior to components: too much |
| 3165 |
-- extra work to detect a corner case??? |
| 3166 |
|
| 3167 |
if Nkind (Choice) in N_Has_Entity |
| 3168 |
and then Present (Entity (Choice)) |
| 3169 |
and then |
| 3170 |
Ekind (Entity (Choice)) = E_Discriminant |
| 3171 |
then |
| 3172 |
null; |
| 3173 |
|
| 3174 |
else |
| 3175 |
Collect_Expression_Ids (Expr); |
| 3176 |
end if; |
| 3177 |
|
| 3178 |
Next (Choice); |
| 3179 |
end loop; |
| 3180 |
end Handle_Association_Choices; |
| 3181 |
|
| 3182 |
begin |
| 3183 |
if not Box_Present (Assoc) then |
| 3184 |
if Nkind (Assoc) = N_Component_Association then |
| 3185 |
Handle_Association_Choices |
| 3186 |
(Choices (Assoc), Expression (Assoc)); |
| 3187 |
|
| 3188 |
elsif |
| 3189 |
Nkind (Assoc) = N_Iterated_Component_Association |
| 3190 |
and then Present (Defining_Identifier (Assoc)) |
| 3191 |
then |
| 3192 |
Handle_Association_Choices |
| 3193 |
(Discrete_Choices (Assoc), Expression (Assoc)); |
| 3194 |
|
| 3195 |
-- Nkind (Assoc) = N_Iterated_Component_Association |
| 3196 |
-- with iterator_specification, or |
| 3197 |
-- Nkind (Assoc) = N_Iterated_Element_Association |
| 3198 |
-- with loop_parameter_specification |
| 3199 |
-- or iterator_specification |
| 3200 |
-- |
| 3201 |
-- It seems that we might also need to deal with |
| 3202 |
-- iterable/iterator_names and iterator_filters |
| 3203 |
-- within iterator_specifications, and range bounds |
| 3204 |
-- within loop_parameter_specifications, but the |
| 3205 |
-- utility of doing that seems very low. ??? |
| 3206 |
|
| 3207 |
else |
| 3208 |
Collect_Expression_Ids (Expression (Assoc)); |
| 3209 |
end if; |
| 3210 |
end if; |
| 3211 |
end Handle_Association; |
| 3212 |
|
| 3213 |
Next (Assoc); |
| 3214 |
end loop; |
| 3215 |
end if; |
| 3216 |
end; |
| 3217 |
|
| 3218 |
when others => |
| 3219 |
return; |
| 3220 |
end case; |
| 3221 |
|
| 3222 |
-- No further action needed if we already reported an error |
| 3223 |
|
| 3224 |
if Present (Error_Node) then |
| 3225 |
return; |
| 3226 |
end if; |
| 3227 |
|
| 3228 |
-- Check violation of RM 6.20/3 in aggregates |
| 3229 |
|
| 3230 |
if Present (Aggr_Error_Node) |
| 3231 |
and then Present (Writable_Actuals_List) |
| 3232 |
then |
| 3233 |
Error_Msg_N |
| 3234 |
("value may be affected by call in other component because they " |
| 3235 |
& "are evaluated in unspecified order", |
| 3236 |
Node (First_Elmt (Writable_Actuals_List))); |
| 3237 |
return; |
| 3238 |
end if; |
| 3239 |
|
| 3240 |
-- Check if some writable argument of a function is referenced |
| 3241 |
|
| 3242 |
if Present (Writable_Actuals_List) |
| 3243 |
and then Present (Identifiers_List) |
| 3244 |
then |
| 3245 |
declare |
| 3246 |
Elmt_1 : Elmt_Id; |
| 3247 |
Elmt_2 : Elmt_Id; |
| 3248 |
|
| 3249 |
begin |
| 3250 |
Elmt_1 := First_Elmt (Writable_Actuals_List); |
| 3251 |
while Present (Elmt_1) loop |
| 3252 |
Elmt_2 := First_Elmt (Identifiers_List); |
| 3253 |
while Present (Elmt_2) loop |
| 3254 |
if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then |
| 3255 |
case Nkind (Parent (Node (Elmt_2))) is |
| 3256 |
when N_Aggregate |
| 3257 |
| N_Component_Association |
| 3258 |
| N_Component_Declaration |
| 3259 |
=> |
| 3260 |
Error_Msg_N |
| 3261 |
("value may be affected by call in other " |
| 3262 |
& "component because they are evaluated " |
| 3263 |
& "in unspecified order", |
| 3264 |
Node (Elmt_2)); |
| 3265 |
|
| 3266 |
when N_Membership_Test => |
| 3267 |
Error_Msg_N |
| 3268 |
("value may be affected by call in other " |
| 3269 |
& "alternative because they are evaluated " |
| 3270 |
& "in unspecified order", |
| 3271 |
Node (Elmt_2)); |
| 3272 |
|
| 3273 |
when others => |
| 3274 |
Error_Msg_N |
| 3275 |
("value of actual may be affected by call in " |
| 3276 |
& "other actual because they are evaluated " |
| 3277 |
& "in unspecified order", |
| 3278 |
Node (Elmt_2)); |
| 3279 |
end case; |
| 3280 |
end if; |
| 3281 |
|
| 3282 |
Next_Elmt (Elmt_2); |
| 3283 |
end loop; |
| 3284 |
|
| 3285 |
Next_Elmt (Elmt_1); |
| 3286 |
end loop; |
| 3287 |
end; |
| 3288 |
end if; |
| 3289 |
end Check_Function_Writable_Actuals; |
| 3290 |
|
| 3291 |
-------------------------------- |
| 3292 |
-- Check_Implicit_Dereference -- |
| 3293 |
-------------------------------- |
| 3294 |
|
| 3295 |
procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is |
| 3296 |
Disc : Entity_Id; |
| 3297 |
Desig : Entity_Id; |
| 3298 |
Nam : Node_Id; |
| 3299 |
|
| 3300 |
begin |
| 3301 |
if Nkind (N) = N_Indexed_Component |
| 3302 |
and then Present (Generalized_Indexing (N)) |
| 3303 |
then |
| 3304 |
Nam := Generalized_Indexing (N); |
| 3305 |
else |
| 3306 |
Nam := N; |
| 3307 |
end if; |
| 3308 |
|
| 3309 |
if Ada_Version < Ada_2012 |
| 3310 |
or else not Has_Implicit_Dereference (Base_Type (Typ)) |
| 3311 |
then |
| 3312 |
return; |
| 3313 |
|
| 3314 |
elsif not Comes_From_Source (N) |
| 3315 |
and then Nkind (N) /= N_Indexed_Component |
| 3316 |
then |
| 3317 |
return; |
| 3318 |
|
| 3319 |
elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then |
| 3320 |
null; |
| 3321 |
|
| 3322 |
else |
| 3323 |
Disc := First_Discriminant (Typ); |
| 3324 |
while Present (Disc) loop |
| 3325 |
if Has_Implicit_Dereference (Disc) then |
| 3326 |
Desig := Designated_Type (Etype (Disc)); |
| 3327 |
Add_One_Interp (Nam, Disc, Desig); |
| 3328 |
|
| 3329 |
-- If the node is a generalized indexing, add interpretation |
| 3330 |
-- to that node as well, for subsequent resolution. |
| 3331 |
|
| 3332 |
if Nkind (N) = N_Indexed_Component then |
| 3333 |
Add_One_Interp (N, Disc, Desig); |
| 3334 |
end if; |
| 3335 |
|
| 3336 |
-- If the operation comes from a generic unit and the context |
| 3337 |
-- is a selected component, the selector name may be global |
| 3338 |
-- and set in the instance already. Remove the entity to |
| 3339 |
-- force resolution of the selected component, and the |
| 3340 |
-- generation of an explicit dereference if needed. |
| 3341 |
|
| 3342 |
if In_Instance |
| 3343 |
and then Nkind (Parent (Nam)) = N_Selected_Component |
| 3344 |
then |
| 3345 |
Set_Entity (Selector_Name (Parent (Nam)), Empty); |
| 3346 |
end if; |
| 3347 |
|
| 3348 |
exit; |
| 3349 |
end if; |
| 3350 |
|
| 3351 |
Next_Discriminant (Disc); |
| 3352 |
end loop; |
| 3353 |
end if; |
| 3354 |
end Check_Implicit_Dereference; |
| 3355 |
|
| 3356 |
---------------------------------- |
| 3357 |
-- Check_Internal_Protected_Use -- |
| 3358 |
---------------------------------- |
| 3359 |
|
| 3360 |
procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is |
| 3361 |
S : Entity_Id; |
| 3362 |
Prot : Entity_Id; |
| 3363 |
|
| 3364 |
begin |
| 3365 |
Prot := Empty; |
| 3366 |
|
| 3367 |
S := Current_Scope; |
| 3368 |
while Present (S) loop |
| 3369 |
if S = Standard_Standard then |
| 3370 |
exit; |
| 3371 |
|
| 3372 |
elsif Ekind (S) = E_Function |
| 3373 |
and then Ekind (Scope (S)) = E_Protected_Type |
| 3374 |
then |
| 3375 |
Prot := Scope (S); |
| 3376 |
exit; |
| 3377 |
end if; |
| 3378 |
|
| 3379 |
S := Scope (S); |
| 3380 |
end loop; |
| 3381 |
|
| 3382 |
if Present (Prot) |
| 3383 |
and then Scope (Nam) = Prot |
| 3384 |
and then Ekind (Nam) /= E_Function |
| 3385 |
then |
| 3386 |
-- An indirect function call (e.g. a callback within a protected |
| 3387 |
-- function body) is not statically illegal. If the access type is |
| 3388 |
-- anonymous and is the type of an access parameter, the scope of Nam |
| 3389 |
-- will be the protected type, but it is not a protected operation. |
| 3390 |
|
| 3391 |
if Ekind (Nam) = E_Subprogram_Type |
| 3392 |
and then Nkind (Associated_Node_For_Itype (Nam)) = |
| 3393 |
N_Function_Specification |
| 3394 |
then |
| 3395 |
null; |
| 3396 |
|
| 3397 |
elsif Nkind (N) = N_Subprogram_Renaming_Declaration then |
| 3398 |
Error_Msg_N |
| 3399 |
("within protected function cannot use protected procedure in " |
| 3400 |
& "renaming or as generic actual", N); |
| 3401 |
|
| 3402 |
elsif Nkind (N) = N_Attribute_Reference then |
| 3403 |
Error_Msg_N |
| 3404 |
("within protected function cannot take access of protected " |
| 3405 |
& "procedure", N); |
| 3406 |
|
| 3407 |
else |
| 3408 |
Error_Msg_N |
| 3409 |
("within protected function, protected object is constant", N); |
| 3410 |
Error_Msg_N |
| 3411 |
("\cannot call operation that may modify it", N); |
| 3412 |
end if; |
| 3413 |
end if; |
| 3414 |
|
| 3415 |
-- Verify that an internal call does not appear within a precondition |
| 3416 |
-- of a protected operation. This implements AI12-0166. |
| 3417 |
-- The precondition aspect has been rewritten as a pragma Precondition |
| 3418 |
-- and we check whether the scope of the called subprogram is the same |
| 3419 |
-- as that of the entity to which the aspect applies. |
| 3420 |
|
| 3421 |
if Convention (Nam) = Convention_Protected then |
| 3422 |
declare |
| 3423 |
P : Node_Id; |
| 3424 |
|
| 3425 |
begin |
| 3426 |
P := Parent (N); |
| 3427 |
while Present (P) loop |
| 3428 |
if Nkind (P) = N_Pragma |
| 3429 |
and then Chars (Pragma_Identifier (P)) = Name_Precondition |
| 3430 |
and then From_Aspect_Specification (P) |
| 3431 |
and then |
| 3432 |
Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam) |
| 3433 |
then |
| 3434 |
Error_Msg_N |
| 3435 |
("internal call cannot appear in precondition of " |
| 3436 |
& "protected operation", N); |
| 3437 |
return; |
| 3438 |
|
| 3439 |
elsif Nkind (P) = N_Pragma |
| 3440 |
and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases |
| 3441 |
then |
| 3442 |
-- Check whether call is in a case guard. It is legal in a |
| 3443 |
-- consequence. |
| 3444 |
|
| 3445 |
P := N; |
| 3446 |
while Present (P) loop |
| 3447 |
if Nkind (Parent (P)) = N_Component_Association |
| 3448 |
and then P /= Expression (Parent (P)) |
| 3449 |
then |
| 3450 |
Error_Msg_N |
| 3451 |
("internal call cannot appear in case guard in a " |
| 3452 |
& "contract case", N); |
| 3453 |
end if; |
| 3454 |
|
| 3455 |
P := Parent (P); |
| 3456 |
end loop; |
| 3457 |
|
| 3458 |
return; |
| 3459 |
|
| 3460 |
elsif Nkind (P) = N_Parameter_Specification |
| 3461 |
and then Scope (Current_Scope) = Scope (Nam) |
| 3462 |
and then Nkind (Parent (P)) in |
| 3463 |
N_Entry_Declaration | N_Subprogram_Declaration |
| 3464 |
then |
| 3465 |
Error_Msg_N |
| 3466 |
("internal call cannot appear in default for formal of " |
| 3467 |
& "protected operation", N); |
| 3468 |
return; |
| 3469 |
|
| 3470 |
-- Prevent the search from going too far |
| 3471 |
|
| 3472 |
elsif Is_Body_Or_Package_Declaration (P) then |
| 3473 |
exit; |
| 3474 |
end if; |
| 3475 |
|
| 3476 |
P := Parent (P); |
| 3477 |
end loop; |
| 3478 |
end; |
| 3479 |
end if; |
| 3480 |
end Check_Internal_Protected_Use; |
| 3481 |
|
| 3482 |
--------------------------------------- |
| 3483 |
-- Check_Later_Vs_Basic_Declarations -- |
| 3484 |
--------------------------------------- |
| 3485 |
|
| 3486 |
procedure Check_Later_Vs_Basic_Declarations |
| 3487 |
(Decls : List_Id; |
| 3488 |
During_Parsing : Boolean) |
| 3489 |
is |
| 3490 |
Body_Sloc : Source_Ptr; |
| 3491 |
Decl : Node_Id; |
| 3492 |
|
| 3493 |
function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean; |
| 3494 |
-- Return whether Decl is considered as a declarative item. |
| 3495 |
-- When During_Parsing is True, the semantics of Ada 83 is followed. |
| 3496 |
-- When During_Parsing is False, the semantics of SPARK is followed. |
| 3497 |
|
| 3498 |
------------------------------- |
| 3499 |
-- Is_Later_Declarative_Item -- |
| 3500 |
------------------------------- |
| 3501 |
|
| 3502 |
function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is |
| 3503 |
begin |
| 3504 |
if Nkind (Decl) in N_Later_Decl_Item then |
| 3505 |
return True; |
| 3506 |
|
| 3507 |
elsif Nkind (Decl) = N_Pragma then |
| 3508 |
return True; |
| 3509 |
|
| 3510 |
elsif During_Parsing then |
| 3511 |
return False; |
| 3512 |
|
| 3513 |
-- In SPARK, a package declaration is not considered as a later |
| 3514 |
-- declarative item. |
| 3515 |
|
| 3516 |
elsif Nkind (Decl) = N_Package_Declaration then |
| 3517 |
return False; |
| 3518 |
|
| 3519 |
-- In SPARK, a renaming is considered as a later declarative item |
| 3520 |
|
| 3521 |
elsif Nkind (Decl) in N_Renaming_Declaration then |
| 3522 |
return True; |
| 3523 |
|
| 3524 |
else |
| 3525 |
return False; |
| 3526 |
end if; |
| 3527 |
end Is_Later_Declarative_Item; |
| 3528 |
|
| 3529 |
-- Start of processing for Check_Later_Vs_Basic_Declarations |
| 3530 |
|
| 3531 |
begin |
| 3532 |
Decl := First (Decls); |
| 3533 |
|
| 3534 |
-- Loop through sequence of basic declarative items |
| 3535 |
|
| 3536 |
Outer : while Present (Decl) loop |
| 3537 |
if Nkind (Decl) not in |
| 3538 |
N_Subprogram_Body | N_Package_Body | N_Task_Body |
| 3539 |
and then Nkind (Decl) not in N_Body_Stub |
| 3540 |
then |
| 3541 |
Next (Decl); |
| 3542 |
|
| 3543 |
-- Once a body is encountered, we only allow later declarative |
| 3544 |
-- items. The inner loop checks the rest of the list. |
| 3545 |
|
| 3546 |
else |
| 3547 |
Body_Sloc := Sloc (Decl); |
| 3548 |
|
| 3549 |
Inner : while Present (Decl) loop |
| 3550 |
if not Is_Later_Declarative_Item (Decl) then |
| 3551 |
if During_Parsing then |
| 3552 |
if Ada_Version = Ada_83 then |
| 3553 |
Error_Msg_Sloc := Body_Sloc; |
| 3554 |
Error_Msg_N |
| 3555 |
("(Ada 83) decl cannot appear after body#", Decl); |
| 3556 |
end if; |
| 3557 |
end if; |
| 3558 |
end if; |
| 3559 |
|
| 3560 |
Next (Decl); |
| 3561 |
end loop Inner; |
| 3562 |
end if; |
| 3563 |
end loop Outer; |
| 3564 |
end Check_Later_Vs_Basic_Declarations; |
| 3565 |
|
| 3566 |
--------------------------- |
| 3567 |
-- Check_No_Hidden_State -- |
| 3568 |
--------------------------- |
| 3569 |
|
| 3570 |
procedure Check_No_Hidden_State (Id : Entity_Id) is |
| 3571 |
Context : Entity_Id := Empty; |
| 3572 |
Not_Visible : Boolean := False; |
| 3573 |
Scop : Entity_Id; |
| 3574 |
|
| 3575 |
begin |
| 3576 |
pragma Assert (Ekind (Id) in E_Abstract_State | E_Variable); |
| 3577 |
|
| 3578 |
-- Nothing to do for internally-generated abstract states and variables |
| 3579 |
-- because they do not represent the hidden state of the source unit. |
| 3580 |
|
| 3581 |
if not Comes_From_Source (Id) then |
| 3582 |
return; |
| 3583 |
end if; |
| 3584 |
|
| 3585 |
-- Find the proper context where the object or state appears |
| 3586 |
|
| 3587 |
Scop := Scope (Id); |
| 3588 |
while Present (Scop) loop |
| 3589 |
Context := Scop; |
| 3590 |
|
| 3591 |
-- Keep track of the context's visibility |
| 3592 |
|
| 3593 |
Not_Visible := Not_Visible or else In_Private_Part (Context); |
| 3594 |
|
| 3595 |
-- Prevent the search from going too far |
| 3596 |
|
| 3597 |
if Context = Standard_Standard then |
| 3598 |
return; |
| 3599 |
|
| 3600 |
-- Objects and states that appear immediately within a subprogram or |
| 3601 |
-- entry inside a construct nested within a subprogram do not |
| 3602 |
-- introduce a hidden state. They behave as local variable |
| 3603 |
-- declarations. The same is true for elaboration code inside a block |
| 3604 |
-- or a task. |
| 3605 |
|
| 3606 |
elsif Is_Subprogram_Or_Entry (Context) |
| 3607 |
or else Ekind (Context) in E_Block | E_Task_Type |
| 3608 |
then |
| 3609 |
return; |
| 3610 |
end if; |
| 3611 |
|
| 3612 |
-- Stop the traversal when a package subject to a null abstract state |
| 3613 |
-- has been found. |
| 3614 |
|
| 3615 |
if Is_Package_Or_Generic_Package (Context) |
| 3616 |
and then Has_Null_Abstract_State (Context) |
| 3617 |
then |
| 3618 |
exit; |
| 3619 |
end if; |
| 3620 |
|
| 3621 |
Scop := Scope (Scop); |
| 3622 |
end loop; |
| 3623 |
|
| 3624 |
-- At this point we know that there is at least one package with a null |
| 3625 |
-- abstract state in visibility. Emit an error message unconditionally |
| 3626 |
-- if the entity being processed is a state because the placement of the |
| 3627 |
-- related package is irrelevant. This is not the case for objects as |
| 3628 |
-- the intermediate context matters. |
| 3629 |
|
| 3630 |
if Present (Context) |
| 3631 |
and then (Ekind (Id) = E_Abstract_State or else Not_Visible) |
| 3632 |
then |
| 3633 |
Error_Msg_N ("cannot introduce hidden state &", Id); |
| 3634 |
Error_Msg_NE ("\package & has null abstract state", Id, Context); |
| 3635 |
end if; |
| 3636 |
end Check_No_Hidden_State; |
| 3637 |
|
| 3638 |
-------------------------------------------- |
| 3639 |
-- Check_Inherited_Nonoverridable_Aspects -- |
| 3640 |
-------------------------------------------- |
| 3641 |
|
| 3642 |
procedure Check_Inherited_Nonoverridable_Aspects |
| 3643 |
(Inheritor : Entity_Id; |
| 3644 |
Interface_List : List_Id; |
| 3645 |
Parent_Type : Entity_Id) is |
| 3646 |
|
| 3647 |
-- array needed for iterating over subtype values |
| 3648 |
Nonoverridable_Aspects : constant array (Positive range <>) of |
| 3649 |
Nonoverridable_Aspect_Id := |
| 3650 |
(Aspect_Default_Iterator, |
| 3651 |
Aspect_Iterator_Element, |
| 3652 |
Aspect_Implicit_Dereference, |
| 3653 |
Aspect_Constant_Indexing, |
| 3654 |
Aspect_Variable_Indexing, |
| 3655 |
Aspect_Aggregate, |
| 3656 |
Aspect_Max_Entry_Queue_Length |
| 3657 |
-- , Aspect_No_Controlled_Parts |
| 3658 |
); |
| 3659 |
|
| 3660 |
-- Note that none of these 8 aspects can be specified (for a type) |
| 3661 |
-- via a pragma. For 7 of them, the corresponding pragma does not |
| 3662 |
-- exist. The Pragma_Id enumeration type does include |
| 3663 |
-- Pragma_Max_Entry_Queue_Length, but that pragma is only use to |
| 3664 |
-- specify the aspect for a protected entry or entry family, not for |
| 3665 |
-- a type, and therefore cannot introduce the sorts of inheritance |
| 3666 |
-- issues that we are concerned with in this procedure. |
| 3667 |
|
| 3668 |
type Entity_Array is array (Nat range <>) of Entity_Id; |
| 3669 |
|
| 3670 |
function Ancestor_Entities return Entity_Array; |
| 3671 |
-- Returns all progenitors (including parent type, if present) |
| 3672 |
|
| 3673 |
procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors |
| 3674 |
(Aspect : Nonoverridable_Aspect_Id; |
| 3675 |
Ancestor_1 : Entity_Id; |
| 3676 |
Aspect_Spec_1 : Node_Id; |
| 3677 |
Ancestor_2 : Entity_Id; |
| 3678 |
Aspect_Spec_2 : Node_Id); |
| 3679 |
-- A given aspect has been specified for each of two ancestors; |
| 3680 |
-- check that the two aspect specifications are compatible (see |
| 3681 |
-- RM 13.1.1(18.5) and AI12-0211). |
| 3682 |
|
| 3683 |
----------------------- |
| 3684 |
-- Ancestor_Entities -- |
| 3685 |
----------------------- |
| 3686 |
|
| 3687 |
function Ancestor_Entities return Entity_Array is |
| 3688 |
Ifc_Count : constant Nat := List_Length (Interface_List); |
| 3689 |
Ifc_Ancestors : Entity_Array (1 .. Ifc_Count); |
| 3690 |
Ifc : Node_Id := First (Interface_List); |
| 3691 |
begin |
| 3692 |
for Idx in Ifc_Ancestors'Range loop |
| 3693 |
Ifc_Ancestors (Idx) := Entity (Ifc); |
| 3694 |
pragma Assert (Present (Ifc_Ancestors (Idx))); |
| 3695 |
Ifc := Next (Ifc); |
| 3696 |
end loop; |
| 3697 |
pragma Assert (No (Ifc)); |
| 3698 |
if Present (Parent_Type) then |
| 3699 |
return Parent_Type & Ifc_Ancestors; |
| 3700 |
else |
| 3701 |
return Ifc_Ancestors; |
| 3702 |
end if; |
| 3703 |
end Ancestor_Entities; |
| 3704 |
|
| 3705 |
------------------------------------------------------- |
| 3706 |
-- Check_Consistency_For_One_Aspect_Of_Two_Ancestors -- |
| 3707 |
------------------------------------------------------- |
| 3708 |
|
| 3709 |
procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors |
| 3710 |
(Aspect : Nonoverridable_Aspect_Id; |
| 3711 |
Ancestor_1 : Entity_Id; |
| 3712 |
Aspect_Spec_1 : Node_Id; |
| 3713 |
Ancestor_2 : Entity_Id; |
| 3714 |
Aspect_Spec_2 : Node_Id) is |
| 3715 |
begin |
| 3716 |
if not Is_Confirming (Aspect, Aspect_Spec_1, Aspect_Spec_2) then |
| 3717 |
Error_Msg_Name_1 := Aspect_Names (Aspect); |
| 3718 |
Error_Msg_Name_2 := Chars (Ancestor_1); |
| 3719 |
Error_Msg_Name_3 := Chars (Ancestor_2); |
| 3720 |
|
| 3721 |
Error_Msg ( |
| 3722 |
"incompatible % aspects inherited from ancestors % and %", |
| 3723 |
Sloc (Inheritor)); |
| 3724 |
end if; |
| 3725 |
end Check_Consistency_For_One_Aspect_Of_Two_Ancestors; |
| 3726 |
|
| 3727 |
Ancestors : constant Entity_Array := Ancestor_Entities; |
| 3728 |
|
| 3729 |
-- start of processing for Check_Inherited_Nonoverridable_Aspects |
| 3730 |
begin |
| 3731 |
-- No Ada_Version check here; AI12-0211 is a binding interpretation. |
| 3732 |
|
| 3733 |
if Ancestors'Length < 2 then |
| 3734 |
return; -- Inconsistency impossible; it takes 2 to disagree. |
| 3735 |
elsif In_Instance_Body then |
| 3736 |
return; -- No legality checking in an instance body. |
| 3737 |
end if; |
| 3738 |
|
| 3739 |
for Aspect of Nonoverridable_Aspects loop |
| 3740 |
declare |
| 3741 |
First_Ancestor_With_Aspect : Entity_Id := Empty; |
| 3742 |
First_Aspect_Spec, Current_Aspect_Spec : Node_Id := Empty; |
| 3743 |
begin |
| 3744 |
for Ancestor of Ancestors loop |
| 3745 |
Current_Aspect_Spec := Find_Aspect (Ancestor, Aspect); |
| 3746 |
if Present (Current_Aspect_Spec) then |
| 3747 |
if Present (First_Ancestor_With_Aspect) then |
| 3748 |
Check_Consistency_For_One_Aspect_Of_Two_Ancestors |
| 3749 |
(Aspect => Aspect, |
| 3750 |
Ancestor_1 => First_Ancestor_With_Aspect, |
| 3751 |
Aspect_Spec_1 => First_Aspect_Spec, |
| 3752 |
Ancestor_2 => Ancestor, |
| 3753 |
Aspect_Spec_2 => Current_Aspect_Spec); |
| 3754 |
else |
| 3755 |
First_Ancestor_With_Aspect := Ancestor; |
| 3756 |
First_Aspect_Spec := Current_Aspect_Spec; |
| 3757 |
end if; |
| 3758 |
end if; |
| 3759 |
end loop; |
| 3760 |
end; |
| 3761 |
end loop; |
| 3762 |
end Check_Inherited_Nonoverridable_Aspects; |
| 3763 |
|
| 3764 |
------------------- |
| 3765 |
-- Check_Parents -- |
| 3766 |
------------------- |
| 3767 |
|
| 3768 |
function Check_Parents (N : Node_Id; List : Elist_Id) return Boolean is |
| 3769 |
|
| 3770 |
function Check_Node |
| 3771 |
(Parent_Node : Node_Id; |
| 3772 |
N : Node_Id) return Traverse_Result; |
| 3773 |
-- Process a single node. |
| 3774 |
|
| 3775 |
---------------- |
| 3776 |
-- Check_Node -- |
| 3777 |
---------------- |
| 3778 |
|
| 3779 |
function Check_Node |
| 3780 |
(Parent_Node : Node_Id; |
| 3781 |
N : Node_Id) return Traverse_Result is |
| 3782 |
begin |
| 3783 |
if Nkind (N) = N_Identifier |
| 3784 |
and then Parent (N) /= Parent_Node |
| 3785 |
and then Present (Entity (N)) |
| 3786 |
and then Contains (List, Entity (N)) |
| 3787 |
then |
| 3788 |
return Abandon; |
| 3789 |
end if; |
| 3790 |
|
| 3791 |
return OK; |
| 3792 |
end Check_Node; |
| 3793 |
|
| 3794 |
function Traverse is new Traverse_Func_With_Parent (Check_Node); |
| 3795 |
|
| 3796 |
-- Start of processing for Check_Parents |
| 3797 |
|
| 3798 |
begin |
| 3799 |
return Traverse (N) = OK; |
| 3800 |
end Check_Parents; |
| 3801 |
|
| 3802 |
----------------------------- |
| 3803 |
-- Check_Part_Of_Reference -- |
| 3804 |
----------------------------- |
| 3805 |
|
| 3806 |
procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is |
| 3807 |
function Is_Enclosing_Package_Body |
| 3808 |
(Body_Decl : Node_Id; |
| 3809 |
Obj_Id : Entity_Id) return Boolean; |
| 3810 |
pragma Inline (Is_Enclosing_Package_Body); |
| 3811 |
-- Determine whether package body Body_Decl or its corresponding spec |
| 3812 |
-- immediately encloses the declaration of object Obj_Id. |
| 3813 |
|
| 3814 |
function Is_Internal_Declaration_Or_Body |
| 3815 |
(Decl : Node_Id) return Boolean; |
| 3816 |
pragma Inline (Is_Internal_Declaration_Or_Body); |
| 3817 |
-- Determine whether declaration or body denoted by Decl is internal |
| 3818 |
|
| 3819 |
function Is_Single_Declaration_Or_Body |
| 3820 |
(Decl : Node_Id; |
| 3821 |
Conc_Typ : Entity_Id) return Boolean; |
| 3822 |
pragma Inline (Is_Single_Declaration_Or_Body); |
| 3823 |
-- Determine whether protected/task declaration or body denoted by Decl |
| 3824 |
-- belongs to single concurrent type Conc_Typ. |
| 3825 |
|
| 3826 |
function Is_Single_Task_Pragma |
| 3827 |
(Prag : Node_Id; |
| 3828 |
Task_Typ : Entity_Id) return Boolean; |
| 3829 |
pragma Inline (Is_Single_Task_Pragma); |
| 3830 |
-- Determine whether pragma Prag belongs to single task type Task_Typ |
| 3831 |
|
| 3832 |
------------------------------- |
| 3833 |
-- Is_Enclosing_Package_Body -- |
| 3834 |
------------------------------- |
| 3835 |
|
| 3836 |
function Is_Enclosing_Package_Body |
| 3837 |
(Body_Decl : Node_Id; |
| 3838 |
Obj_Id : Entity_Id) return Boolean |
| 3839 |
is |
| 3840 |
Obj_Context : Node_Id; |
| 3841 |
|
| 3842 |
begin |
| 3843 |
-- Find the context of the object declaration |
| 3844 |
|
| 3845 |
Obj_Context := Parent (Declaration_Node (Obj_Id)); |
| 3846 |
|
| 3847 |
if Nkind (Obj_Context) = N_Package_Specification then |
| 3848 |
Obj_Context := Parent (Obj_Context); |
| 3849 |
end if; |
| 3850 |
|
| 3851 |
-- The object appears immediately within the package body |
| 3852 |
|
| 3853 |
if Obj_Context = Body_Decl then |
| 3854 |
return True; |
| 3855 |
|
| 3856 |
-- The object appears immediately within the corresponding spec |
| 3857 |
|
| 3858 |
elsif Nkind (Obj_Context) = N_Package_Declaration |
| 3859 |
and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) = |
| 3860 |
Obj_Context |
| 3861 |
then |
| 3862 |
return True; |
| 3863 |
end if; |
| 3864 |
|
| 3865 |
return False; |
| 3866 |
end Is_Enclosing_Package_Body; |
| 3867 |
|
| 3868 |
------------------------------------- |
| 3869 |
-- Is_Internal_Declaration_Or_Body -- |
| 3870 |
------------------------------------- |
| 3871 |
|
| 3872 |
function Is_Internal_Declaration_Or_Body |
| 3873 |
(Decl : Node_Id) return Boolean |
| 3874 |
is |
| 3875 |
begin |
| 3876 |
if Comes_From_Source (Decl) then |
| 3877 |
return False; |
| 3878 |
|
| 3879 |
-- A body generated for an expression function which has not been |
| 3880 |
-- inserted into the tree yet (In_Spec_Expression is True) is not |
| 3881 |
-- considered internal. |
| 3882 |
|
| 3883 |
elsif Nkind (Decl) = N_Subprogram_Body |
| 3884 |
and then Was_Expression_Function (Decl) |
| 3885 |
and then not In_Spec_Expression |
| 3886 |
then |
| 3887 |
return False; |
| 3888 |
end if; |
| 3889 |
|
| 3890 |
return True; |
| 3891 |
end Is_Internal_Declaration_Or_Body; |
| 3892 |
|
| 3893 |
----------------------------------- |
| 3894 |
-- Is_Single_Declaration_Or_Body -- |
| 3895 |
----------------------------------- |
| 3896 |
|
| 3897 |
function Is_Single_Declaration_Or_Body |
| 3898 |
(Decl : Node_Id; |
| 3899 |
Conc_Typ : Entity_Id) return Boolean |
| 3900 |
is |
| 3901 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl); |
| 3902 |
|
| 3903 |
begin |
| 3904 |
return |
| 3905 |
Present (Anonymous_Object (Spec_Id)) |
| 3906 |
and then Anonymous_Object (Spec_Id) = Conc_Typ; |
| 3907 |
end Is_Single_Declaration_Or_Body; |
| 3908 |
|
| 3909 |
--------------------------- |
| 3910 |
-- Is_Single_Task_Pragma -- |
| 3911 |
--------------------------- |
| 3912 |
|
| 3913 |
function Is_Single_Task_Pragma |
| 3914 |
(Prag : Node_Id; |
| 3915 |
Task_Typ : Entity_Id) return Boolean |
| 3916 |
is |
| 3917 |
Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag); |
| 3918 |
|
| 3919 |
begin |
| 3920 |
-- To qualify, the pragma must be associated with single task type |
| 3921 |
-- Task_Typ. |
| 3922 |
|
| 3923 |
return |
| 3924 |
Is_Single_Task_Object (Task_Typ) |
| 3925 |
and then Nkind (Decl) = N_Object_Declaration |
| 3926 |
and then Defining_Entity (Decl) = Task_Typ; |
| 3927 |
end Is_Single_Task_Pragma; |
| 3928 |
|
| 3929 |
-- Local variables |
| 3930 |
|
| 3931 |
Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id); |
| 3932 |
Par : Node_Id; |
| 3933 |
Prag_Nam : Name_Id; |
| 3934 |
Prev : Node_Id; |
| 3935 |
|
| 3936 |
-- Start of processing for Check_Part_Of_Reference |
| 3937 |
|
| 3938 |
begin |
| 3939 |
-- Nothing to do when the variable was recorded, but did not become a |
| 3940 |
-- constituent of a single concurrent type. |
| 3941 |
|
| 3942 |
if No (Conc_Obj) then |
| 3943 |
return; |
| 3944 |
end if; |
| 3945 |
|
| 3946 |
-- Traverse the parent chain looking for a suitable context for the |
| 3947 |
-- reference to the concurrent constituent. |
| 3948 |
|
| 3949 |
Prev := Ref; |
| 3950 |
Par := Parent (Prev); |
| 3951 |
while Present (Par) loop |
| 3952 |
if Nkind (Par) = N_Pragma then |
| 3953 |
Prag_Nam := Pragma_Name (Par); |
| 3954 |
|
| 3955 |
-- A concurrent constituent is allowed to appear in pragmas |
| 3956 |
-- Initial_Condition and Initializes as this is part of the |
| 3957 |
-- elaboration checks for the constituent (SPARK RM 9(3)). |
| 3958 |
|
| 3959 |
if Prag_Nam in Name_Initial_Condition | Name_Initializes then |
| 3960 |
return; |
| 3961 |
|
| 3962 |
-- When the reference appears within pragma Depends or Global, |
| 3963 |
-- check whether the pragma applies to a single task type. Note |
| 3964 |
-- that the pragma may not encapsulated by the type definition, |
| 3965 |
-- but this is still a valid context. |
| 3966 |
|
| 3967 |
elsif Prag_Nam in Name_Depends | Name_Global |
| 3968 |
and then Is_Single_Task_Pragma (Par, Conc_Obj) |
| 3969 |
then |
| 3970 |
return; |
| 3971 |
end if; |
| 3972 |
|
| 3973 |
-- The reference appears somewhere in the definition of a single |
| 3974 |
-- concurrent type (SPARK RM 9(3)). |
| 3975 |
|
| 3976 |
elsif Nkind (Par) in |
| 3977 |
N_Single_Protected_Declaration | N_Single_Task_Declaration |
| 3978 |
and then Defining_Entity (Par) = Conc_Obj |
| 3979 |
then |
| 3980 |
return; |
| 3981 |
|
| 3982 |
-- The reference appears within the declaration or body of a single |
| 3983 |
-- concurrent type (SPARK RM 9(3)). |
| 3984 |
|
| 3985 |
elsif Nkind (Par) in N_Protected_Body |
| 3986 |
| N_Protected_Type_Declaration |
| 3987 |
| N_Task_Body |
| 3988 |
| N_Task_Type_Declaration |
| 3989 |
and then Is_Single_Declaration_Or_Body (Par, Conc_Obj) |
| 3990 |
then |
| 3991 |
return; |
| 3992 |
|
| 3993 |
-- The reference appears within the statement list of the object's |
| 3994 |
-- immediately enclosing package (SPARK RM 9(3)). |
| 3995 |
|
| 3996 |
elsif Nkind (Par) = N_Package_Body |
| 3997 |
and then Nkind (Prev) = N_Handled_Sequence_Of_Statements |
| 3998 |
and then Is_Enclosing_Package_Body (Par, Var_Id) |
| 3999 |
then |
| 4000 |
return; |
| 4001 |
|
| 4002 |
-- The reference has been relocated within an internally generated |
| 4003 |
-- package or subprogram. Assume that the reference is legal as the |
| 4004 |
-- real check was already performed in the original context of the |
| 4005 |
-- reference. |
| 4006 |
|
| 4007 |
elsif Nkind (Par) in N_Package_Body |
| 4008 |
| N_Package_Declaration |
| 4009 |
| N_Subprogram_Body |
| 4010 |
| N_Subprogram_Declaration |
| 4011 |
and then Is_Internal_Declaration_Or_Body (Par) |
| 4012 |
then |
| 4013 |
return; |
| 4014 |
|
| 4015 |
-- The reference has been relocated to an inlined body for GNATprove. |
| 4016 |
-- Assume that the reference is legal as the real check was already |
| 4017 |
-- performed in the original context of the reference. |
| 4018 |
|
| 4019 |
elsif GNATprove_Mode |
| 4020 |
and then Nkind (Par) = N_Subprogram_Body |
| 4021 |
and then Chars (Defining_Entity (Par)) = Name_uParent |
| 4022 |
then |
| 4023 |
return; |
| 4024 |
end if; |
| 4025 |
|
| 4026 |
Prev := Par; |
| 4027 |
Par := Parent (Prev); |
| 4028 |
end loop; |
| 4029 |
|
| 4030 |
-- At this point it is known that the reference does not appear within a |
| 4031 |
-- legal context. |
| 4032 |
|
| 4033 |
Error_Msg_NE |
| 4034 |
("reference to variable & cannot appear in this context", Ref, Var_Id); |
| 4035 |
Error_Msg_Name_1 := Chars (Var_Id); |
| 4036 |
|
| 4037 |
if Is_Single_Protected_Object (Conc_Obj) then |
| 4038 |
Error_Msg_NE |
| 4039 |
("\% is constituent of single protected type &", Ref, Conc_Obj); |
| 4040 |
|
| 4041 |
else |
| 4042 |
Error_Msg_NE |
| 4043 |
("\% is constituent of single task type &", Ref, Conc_Obj); |
| 4044 |
end if; |
| 4045 |
end Check_Part_Of_Reference; |
| 4046 |
|
| 4047 |
------------------------------------------ |
| 4048 |
-- Check_Potentially_Blocking_Operation -- |
| 4049 |
------------------------------------------ |
| 4050 |
|
| 4051 |
procedure Check_Potentially_Blocking_Operation (N : Node_Id) is |
| 4052 |
S : Entity_Id; |
| 4053 |
|
| 4054 |
begin |
| 4055 |
-- N is one of the potentially blocking operations listed in 9.5.1(8). |
| 4056 |
-- When pragma Detect_Blocking is active, the run time will raise |
| 4057 |
-- Program_Error. Here we only issue a warning, since we generally |
| 4058 |
-- support the use of potentially blocking operations in the absence |
| 4059 |
-- of the pragma. |
| 4060 |
|
| 4061 |
-- Indirect blocking through a subprogram call cannot be diagnosed |
| 4062 |
-- statically without interprocedural analysis, so we do not attempt |
| 4063 |
-- to do it here. |
| 4064 |
|
| 4065 |
S := Scope (Current_Scope); |
| 4066 |
while Present (S) and then S /= Standard_Standard loop |
| 4067 |
if Is_Protected_Type (S) then |
| 4068 |
Error_Msg_N |
| 4069 |
("potentially blocking operation in protected operation??", N); |
| 4070 |
return; |
| 4071 |
end if; |
| 4072 |
|
| 4073 |
S := Scope (S); |
| 4074 |
end loop; |
| 4075 |
end Check_Potentially_Blocking_Operation; |
| 4076 |
|
| 4077 |
------------------------------------ |
| 4078 |
-- Check_Previous_Null_Procedure -- |
| 4079 |
------------------------------------ |
| 4080 |
|
| 4081 |
procedure Check_Previous_Null_Procedure |
| 4082 |
(Decl : Node_Id; |
| 4083 |
Prev : Entity_Id) |
| 4084 |
is |
| 4085 |
begin |
| 4086 |
if Ekind (Prev) = E_Procedure |
| 4087 |
and then Nkind (Parent (Prev)) = N_Procedure_Specification |
| 4088 |
and then Null_Present (Parent (Prev)) |
| 4089 |
then |
| 4090 |
Error_Msg_Sloc := Sloc (Prev); |
| 4091 |
Error_Msg_N |
| 4092 |
("declaration cannot complete previous null procedure#", Decl); |
| 4093 |
end if; |
| 4094 |
end Check_Previous_Null_Procedure; |
| 4095 |
|
| 4096 |
--------------------------------- |
| 4097 |
-- Check_Result_And_Post_State -- |
| 4098 |
--------------------------------- |
| 4099 |
|
| 4100 |
procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is |
| 4101 |
procedure Check_Result_And_Post_State_In_Pragma |
| 4102 |
(Prag : Node_Id; |
| 4103 |
Result_Seen : in out Boolean); |
| 4104 |
-- Determine whether pragma Prag mentions attribute 'Result and whether |
| 4105 |
-- the pragma contains an expression that evaluates differently in pre- |
| 4106 |
-- and post-state. Prag is a [refined] postcondition or a contract-cases |
| 4107 |
-- pragma. Result_Seen is set when the pragma mentions attribute 'Result |
| 4108 |
|
| 4109 |
------------------------------------------- |
| 4110 |
-- Check_Result_And_Post_State_In_Pragma -- |
| 4111 |
------------------------------------------- |
| 4112 |
|
| 4113 |
procedure Check_Result_And_Post_State_In_Pragma |
| 4114 |
(Prag : Node_Id; |
| 4115 |
Result_Seen : in out Boolean) |
| 4116 |
is |
| 4117 |
procedure Check_Conjunct (Expr : Node_Id); |
| 4118 |
-- Check an individual conjunct in a conjunction of Boolean |
| 4119 |
-- expressions, connected by "and" or "and then" operators. |
| 4120 |
|
| 4121 |
procedure Check_Conjuncts (Expr : Node_Id); |
| 4122 |
-- Apply the post-state check to every conjunct in an expression, in |
| 4123 |
-- case this is a conjunction of Boolean expressions. Otherwise apply |
| 4124 |
-- it to the expression as a whole. |
| 4125 |
|
| 4126 |
procedure Check_Expression (Expr : Node_Id); |
| 4127 |
-- Perform the 'Result and post-state checks on a given expression |
| 4128 |
|
| 4129 |
function Is_Function_Result (N : Node_Id) return Traverse_Result; |
| 4130 |
-- Attempt to find attribute 'Result in a subtree denoted by N |
| 4131 |
|
| 4132 |
function Mentions_Post_State (N : Node_Id) return Boolean; |
| 4133 |
-- Determine whether a subtree denoted by N mentions any construct |
| 4134 |
-- that denotes a post-state. |
| 4135 |
|
| 4136 |
procedure Check_Function_Result is |
| 4137 |
new Traverse_Proc (Is_Function_Result); |
| 4138 |
|
| 4139 |
-------------------- |
| 4140 |
-- Check_Conjunct -- |
| 4141 |
-------------------- |
| 4142 |
|
| 4143 |
procedure Check_Conjunct (Expr : Node_Id) is |
| 4144 |
function Adjust_Message (Msg : String) return String; |
| 4145 |
-- Prepend a prefix to the input message Msg denoting that the |
| 4146 |
-- message applies to a conjunct in the expression, when this |
| 4147 |
-- is the case. |
| 4148 |
|
| 4149 |
function Applied_On_Conjunct return Boolean; |
| 4150 |
-- Returns True if the message applies to a conjunct in the |
| 4151 |
-- expression, instead of the whole expression. |
| 4152 |
|
| 4153 |
function Has_Global_Output (Subp : Entity_Id) return Boolean; |
| 4154 |
-- Returns True if Subp has an output in its Global contract |
| 4155 |
|
| 4156 |
function Has_No_Output (Subp : Entity_Id) return Boolean; |
| 4157 |
-- Returns True if Subp has no declared output: no function |
| 4158 |
-- result, no output parameter, and no output in its Global |
| 4159 |
-- contract. |
| 4160 |
|
| 4161 |
-------------------- |
| 4162 |
-- Adjust_Message -- |
| 4163 |
-------------------- |
| 4164 |
|
| 4165 |
function Adjust_Message (Msg : String) return String is |
| 4166 |
begin |
| 4167 |
if Applied_On_Conjunct then |
| 4168 |
return "conjunct in " & Msg; |
| 4169 |
else |
| 4170 |
return Msg; |
| 4171 |
end if; |
| 4172 |
end Adjust_Message; |
| 4173 |
|
| 4174 |
------------------------- |
| 4175 |
-- Applied_On_Conjunct -- |
| 4176 |
------------------------- |
| 4177 |
|
| 4178 |
function Applied_On_Conjunct return Boolean is |
| 4179 |
begin |
| 4180 |
-- Expr is the conjunct of an enclosing "and" expression |
| 4181 |
|
| 4182 |
return Nkind (Parent (Expr)) in N_Subexpr; |
| 4183 |
end Applied_On_Conjunct; |
| 4184 |
|
| 4185 |
----------------------- |
| 4186 |
-- Has_Global_Output -- |
| 4187 |
----------------------- |
| 4188 |
|
| 4189 |
function Has_Global_Output (Subp : Entity_Id) return Boolean is |
| 4190 |
Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global); |
| 4191 |
List : Node_Id; |
| 4192 |
Assoc : Node_Id; |
| 4193 |
|
| 4194 |
begin |
| 4195 |
if No (Global) then |
| 4196 |
return False; |
| 4197 |
end if; |
| 4198 |
|
| 4199 |
List := Expression (Get_Argument (Global, Subp)); |
| 4200 |
|
| 4201 |
-- Empty list (no global items) or single global item |
| 4202 |
-- declaration (only input items). |
| 4203 |
|
| 4204 |
if Nkind (List) in N_Null |
| 4205 |
| N_Expanded_Name |
| 4206 |
| N_Identifier |
| 4207 |
| N_Selected_Component |
| 4208 |
then |
| 4209 |
return False; |
| 4210 |
|
| 4211 |
-- Simple global list (only input items) or moded global list |
| 4212 |
-- declaration. |
| 4213 |
|
| 4214 |
elsif Nkind (List) = N_Aggregate then |
| 4215 |
if Present (Expressions (List)) then |
| 4216 |
return False; |
| 4217 |
|
| 4218 |
else |
| 4219 |
Assoc := First (Component_Associations (List)); |
| 4220 |
while Present (Assoc) loop |
| 4221 |
if Chars (First (Choices (Assoc))) /= Name_Input then |
| 4222 |
return True; |
| 4223 |
end if; |
| 4224 |
|
| 4225 |
Next (Assoc); |
| 4226 |
end loop; |
| 4227 |
|
| 4228 |
return False; |
| 4229 |
end if; |
| 4230 |
|
| 4231 |
-- To accommodate partial decoration of disabled SPARK |
| 4232 |
-- features, this routine may be called with illegal input. |
| 4233 |
-- If this is the case, do not raise Program_Error. |
| 4234 |
|
| 4235 |
else |
| 4236 |
return False; |
| 4237 |
end if; |
| 4238 |
end Has_Global_Output; |
| 4239 |
|
| 4240 |
------------------- |
| 4241 |
-- Has_No_Output -- |
| 4242 |
------------------- |
| 4243 |
|
| 4244 |
function Has_No_Output (Subp : Entity_Id) return Boolean is |
| 4245 |
Param : Entity_Id; |
| 4246 |
|
| 4247 |
begin |
| 4248 |
-- A function has its result as output |
| 4249 |
|
| 4250 |
if Ekind (Subp) = E_Function then |
| 4251 |
return False; |
| 4252 |
end if; |
| 4253 |
|
| 4254 |
-- An OUT or IN OUT parameter is an output |
| 4255 |
|
| 4256 |
Param := First_Formal (Subp); |
| 4257 |
while Present (Param) loop |
| 4258 |
if Ekind (Param) in E_Out_Parameter | E_In_Out_Parameter then |
| 4259 |
return False; |
| 4260 |
end if; |
| 4261 |
|
| 4262 |
Next_Formal (Param); |
| 4263 |
end loop; |
| 4264 |
|
| 4265 |
-- An item of mode Output or In_Out in the Global contract is |
| 4266 |
-- an output. |
| 4267 |
|
| 4268 |
if Has_Global_Output (Subp) then |
| 4269 |
return False; |
| 4270 |
end if; |
| 4271 |
|
| 4272 |
return True; |
| 4273 |
end Has_No_Output; |
| 4274 |
|
| 4275 |
-- Local variables |
| 4276 |
|
| 4277 |
Err_Node : Node_Id; |
| 4278 |
-- Error node when reporting a warning on a (refined) |
| 4279 |
-- postcondition. |
| 4280 |
|
| 4281 |
-- Start of processing for Check_Conjunct |
| 4282 |
|
| 4283 |
begin |
| 4284 |
if Applied_On_Conjunct then |
| 4285 |
Err_Node := Expr; |
| 4286 |
else |
| 4287 |
Err_Node := Prag; |
| 4288 |
end if; |
| 4289 |
|
| 4290 |
-- Do not report missing reference to outcome in postcondition if |
| 4291 |
-- either the postcondition is trivially True or False, or if the |
| 4292 |
-- subprogram is ghost and has no declared output. |
| 4293 |
|
| 4294 |
if not Is_Trivial_Boolean (Expr) |
| 4295 |
and then not Mentions_Post_State (Expr) |
| 4296 |
and then not (Is_Ghost_Entity (Subp_Id) |
| 4297 |
and then Has_No_Output (Subp_Id)) |
| 4298 |
and then not Is_Wrapper (Subp_Id) |
| 4299 |
then |
| 4300 |
case Pragma_Name (Prag) is |
| 4301 |
when Name_Contract_Cases => |
| 4302 |
Error_Msg_NE (Adjust_Message |
| 4303 |
("contract case does not check the outcome of calling " |
| 4304 |
& "&?.t?"), Expr, Subp_Id); |
| 4305 |
|
| 4306 |
when Name_Refined_Post => |
| 4307 |
Error_Msg_NE (Adjust_Message |
| 4308 |
("refined postcondition does not check the outcome of " |
| 4309 |
& "calling &?.t?"), Err_Node, Subp_Id); |
| 4310 |
|
| 4311 |
when Name_Postcondition => |
| 4312 |
Error_Msg_NE (Adjust_Message |
| 4313 |
("postcondition does not check the outcome of calling " |
| 4314 |
& "&?.t?"), Err_Node, Subp_Id); |
| 4315 |
|
| 4316 |
when others => pragma Assert (False); |
| 4317 |
end case; |
| 4318 |
end if; |
| 4319 |
end Check_Conjunct; |
| 4320 |
|
| 4321 |
--------------------- |
| 4322 |
-- Check_Conjuncts -- |
| 4323 |
--------------------- |
| 4324 |
|
| 4325 |
procedure Check_Conjuncts (Expr : Node_Id) is |
| 4326 |
begin |
| 4327 |
if Nkind (Expr) in N_Op_And | N_And_Then then |
| 4328 |
Check_Conjuncts (Left_Opnd (Expr)); |
| 4329 |
Check_Conjuncts (Right_Opnd (Expr)); |
| 4330 |
else |
| 4331 |
Check_Conjunct (Expr); |
| 4332 |
end if; |
| 4333 |
end Check_Conjuncts; |
| 4334 |
|
| 4335 |
---------------------- |
| 4336 |
-- Check_Expression -- |
| 4337 |
---------------------- |
| 4338 |
|
| 4339 |
procedure Check_Expression (Expr : Node_Id) is |
| 4340 |
begin |
| 4341 |
if not Is_Trivial_Boolean (Expr) then |
| 4342 |
Check_Function_Result (Expr); |
| 4343 |
Check_Conjuncts (Expr); |
| 4344 |
end if; |
| 4345 |
end Check_Expression; |
| 4346 |
|
| 4347 |
------------------------ |
| 4348 |
-- Is_Function_Result -- |
| 4349 |
------------------------ |
| 4350 |
|
| 4351 |
function Is_Function_Result (N : Node_Id) return Traverse_Result is |
| 4352 |
begin |
| 4353 |
if Is_Attribute_Result (N) then |
| 4354 |
Result_Seen := True; |
| 4355 |
return Abandon; |
| 4356 |
|
| 4357 |
-- Warn on infinite recursion if call is to current function |
| 4358 |
|
| 4359 |
elsif Nkind (N) = N_Function_Call |
| 4360 |
and then Is_Entity_Name (Name (N)) |
| 4361 |
and then Entity (Name (N)) = Subp_Id |
| 4362 |
and then not Is_Potentially_Unevaluated (N) |
| 4363 |
then |
| 4364 |
Error_Msg_NE |
| 4365 |
("call to & within its postcondition will lead to infinite " |
| 4366 |
& "recursion?", N, Subp_Id); |
| 4367 |
return OK; |
| 4368 |
|
| 4369 |
-- Continue the traversal |
| 4370 |
|
| 4371 |
else |
| 4372 |
return OK; |
| 4373 |
end if; |
| 4374 |
end Is_Function_Result; |
| 4375 |
|
| 4376 |
------------------------- |
| 4377 |
-- Mentions_Post_State -- |
| 4378 |
------------------------- |
| 4379 |
|
| 4380 |
function Mentions_Post_State (N : Node_Id) return Boolean is |
| 4381 |
function Is_Post_State (N : Node_Id) return Traverse_Result; |
| 4382 |
-- If called with a construct that denotes a post-state, then |
| 4383 |
-- abandon the search. |
| 4384 |
|
| 4385 |
------------------- |
| 4386 |
-- Is_Post_State -- |
| 4387 |
------------------- |
| 4388 |
|
| 4389 |
function Is_Post_State (N : Node_Id) return Traverse_Result is |
| 4390 |
Ent : Entity_Id; |
| 4391 |
|
| 4392 |
begin |
| 4393 |
if Nkind (N) in N_Explicit_Dereference | N_Function_Call then |
| 4394 |
return Abandon; |
| 4395 |
|
| 4396 |
elsif Nkind (N) in N_Expanded_Name | N_Identifier then |
| 4397 |
Ent := Entity (N); |
| 4398 |
|
| 4399 |
-- Treat an undecorated reference as OK |
| 4400 |
|
| 4401 |
if No (Ent) |
| 4402 |
|
| 4403 |
-- A reference to an assignable entity is considered a |
| 4404 |
-- change in the post-state of a subprogram. |
| 4405 |
|
| 4406 |
or else Ekind (Ent) in E_Generic_In_Out_Parameter |
| 4407 |
| E_In_Out_Parameter |
| 4408 |
| E_Out_Parameter |
| 4409 |
| E_Variable |
| 4410 |
|
| 4411 |
-- The reference may be modified through a dereference |
| 4412 |
|
| 4413 |
or else (Is_Access_Type (Etype (Ent)) |
| 4414 |
and then Nkind (Parent (N)) = |
| 4415 |
N_Selected_Component) |
| 4416 |
then |
| 4417 |
return Abandon; |
| 4418 |
end if; |
| 4419 |
|
| 4420 |
elsif Nkind (N) = N_Attribute_Reference then |
| 4421 |
if Attribute_Name (N) = Name_Old then |
| 4422 |
return Skip; |
| 4423 |
|
| 4424 |
elsif Attribute_Name (N) = Name_Result then |
| 4425 |
return Abandon; |
| 4426 |
end if; |
| 4427 |
end if; |
| 4428 |
|
| 4429 |
return OK; |
| 4430 |
end Is_Post_State; |
| 4431 |
|
| 4432 |
function Find_Post_State is new Traverse_Func (Is_Post_State); |
| 4433 |
|
| 4434 |
-- Start of processing for Mentions_Post_State |
| 4435 |
|
| 4436 |
begin |
| 4437 |
return Find_Post_State (N) = Abandon; |
| 4438 |
end Mentions_Post_State; |
| 4439 |
|
| 4440 |
-- Local variables |
| 4441 |
|
| 4442 |
Expr : constant Node_Id := |
| 4443 |
Get_Pragma_Arg |
| 4444 |
(First (Pragma_Argument_Associations (Prag))); |
| 4445 |
Nam : constant Name_Id := Pragma_Name (Prag); |
| 4446 |
CCase : Node_Id; |
| 4447 |
|
| 4448 |
-- Start of processing for Check_Result_And_Post_State_In_Pragma |
| 4449 |
|
| 4450 |
begin |
| 4451 |
-- Examine all consequences |
| 4452 |
|
| 4453 |
if Nam = Name_Contract_Cases then |
| 4454 |
CCase := First (Component_Associations (Expr)); |
| 4455 |
while Present (CCase) loop |
| 4456 |
Check_Expression (Expression (CCase)); |
| 4457 |
|
| 4458 |
Next (CCase); |
| 4459 |
end loop; |
| 4460 |
|
| 4461 |
-- Examine the expression of a postcondition |
| 4462 |
|
| 4463 |
else pragma Assert (Nam in Name_Postcondition | Name_Refined_Post); |
| 4464 |
Check_Expression (Expr); |
| 4465 |
end if; |
| 4466 |
end Check_Result_And_Post_State_In_Pragma; |
| 4467 |
|
| 4468 |
-- Local variables |
| 4469 |
|
| 4470 |
Items : constant Node_Id := Contract (Subp_Id); |
| 4471 |
Case_Prag : Node_Id := Empty; |
| 4472 |
Post_Prag : Node_Id := Empty; |
| 4473 |
Prag : Node_Id; |
| 4474 |
Seen_In_Case : Boolean := False; |
| 4475 |
Seen_In_Post : Boolean := False; |
| 4476 |
Spec_Id : constant Entity_Id := Unique_Entity (Subp_Id); |
| 4477 |
|
| 4478 |
-- Start of processing for Check_Result_And_Post_State |
| 4479 |
|
| 4480 |
begin |
| 4481 |
-- Do not check in instances, because we already checked the generic |
| 4482 |
|
| 4483 |
if In_Instance then |
| 4484 |
return; |
| 4485 |
|
| 4486 |
-- The lack of attribute 'Result or a post-state is classified as a |
| 4487 |
-- suspicious contract. Do not perform the check if the corresponding |
| 4488 |
-- switch is not set. |
| 4489 |
|
| 4490 |
elsif not Warn_On_Suspicious_Contract then |
| 4491 |
return; |
| 4492 |
|
| 4493 |
-- Nothing to do if there is no contract |
| 4494 |
|
| 4495 |
elsif No (Items) then |
| 4496 |
return; |
| 4497 |
|
| 4498 |
-- If the subprogram has a contract Exceptional_Cases, it is often |
| 4499 |
-- useful to refer only to the pre-state in the postcondition, to |
| 4500 |
-- indicate when the subprogram might terminate normally. |
| 4501 |
|
| 4502 |
elsif Present (Get_Pragma (Subp_Id, Pragma_Exceptional_Cases)) then |
| 4503 |
return; |
| 4504 |
|
| 4505 |
-- Same if the subprogram has a contract Always_Terminates => Cond, |
| 4506 |
-- where Cond is not syntactically True. |
| 4507 |
|
| 4508 |
else |
| 4509 |
declare |
| 4510 |
Prag : constant Node_Id := |
| 4511 |
Get_Pragma (Subp_Id, Pragma_Always_Terminates); |
| 4512 |
begin |
| 4513 |
if Present (Prag) |
| 4514 |
and then Present (Pragma_Argument_Associations (Prag)) |
| 4515 |
then |
| 4516 |
declare |
| 4517 |
Cond : constant Node_Id := |
| 4518 |
Get_Pragma_Arg |
| 4519 |
(First (Pragma_Argument_Associations (Prag))); |
| 4520 |
begin |
| 4521 |
if not Compile_Time_Known_Value (Cond) |
| 4522 |
or else not Is_True (Expr_Value (Cond)) |
| 4523 |
then |
| 4524 |
return; |
| 4525 |
end if; |
| 4526 |
end; |
| 4527 |
end if; |
| 4528 |
end; |
| 4529 |
end if; |
| 4530 |
|
| 4531 |
-- Examine all postconditions for attribute 'Result and a post-state |
| 4532 |
|
| 4533 |
Prag := Pre_Post_Conditions (Items); |
| 4534 |
while Present (Prag) loop |
| 4535 |
if Pragma_Name_Unmapped (Prag) |
| 4536 |
in Name_Postcondition | Name_Refined_Post |
| 4537 |
and then not Error_Posted (Prag) |
| 4538 |
then |
| 4539 |
Post_Prag := Prag; |
| 4540 |
Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post); |
| 4541 |
end if; |
| 4542 |
|
| 4543 |
Prag := Next_Pragma (Prag); |
| 4544 |
end loop; |
| 4545 |
|
| 4546 |
-- Examine the contract cases of the subprogram for attribute 'Result |
| 4547 |
-- and a post-state. |
| 4548 |
|
| 4549 |
Prag := Contract_Test_Cases (Items); |
| 4550 |
while Present (Prag) loop |
| 4551 |
if Pragma_Name (Prag) = Name_Contract_Cases |
| 4552 |
and then not Error_Posted (Prag) |
| 4553 |
then |
| 4554 |
Case_Prag := Prag; |
| 4555 |
Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case); |
| 4556 |
end if; |
| 4557 |
|
| 4558 |
Prag := Next_Pragma (Prag); |
| 4559 |
end loop; |
| 4560 |
|
| 4561 |
-- Do not emit any errors if the subprogram is not a function |
| 4562 |
|
| 4563 |
if Ekind (Spec_Id) not in E_Function | E_Generic_Function then |
| 4564 |
null; |
| 4565 |
|
| 4566 |
-- Regardless of whether the function has postconditions or contract |
| 4567 |
-- cases, or whether they mention attribute 'Result, an [IN] OUT formal |
| 4568 |
-- parameter is always treated as a result. |
| 4569 |
|
| 4570 |
elsif Has_Out_Or_In_Out_Parameter (Spec_Id) then |
| 4571 |
null; |
| 4572 |
|
| 4573 |
-- The function has both a postcondition and contract cases and they do |
| 4574 |
-- not mention attribute 'Result. |
| 4575 |
|
| 4576 |
elsif Present (Case_Prag) |
| 4577 |
and then not Seen_In_Case |
| 4578 |
and then Present (Post_Prag) |
| 4579 |
and then not Seen_In_Post |
| 4580 |
then |
| 4581 |
Error_Msg_N |
| 4582 |
("neither postcondition nor contract cases mention function " |
| 4583 |
& "result?.t?", Post_Prag); |
| 4584 |
|
| 4585 |
-- The function has contract cases only and they do not mention |
| 4586 |
-- attribute 'Result. |
| 4587 |
|
| 4588 |
elsif Present (Case_Prag) and then not Seen_In_Case then |
| 4589 |
Error_Msg_N |
| 4590 |
("contract cases do not mention function result?.t?", Case_Prag); |
| 4591 |
|
| 4592 |
-- The function has non-trivial postconditions only and they do not |
| 4593 |
-- mention attribute 'Result. |
| 4594 |
|
| 4595 |
elsif Present (Post_Prag) |
| 4596 |
and then not Seen_In_Post |
| 4597 |
and then not Is_Trivial_Boolean |
| 4598 |
(Get_Pragma_Arg (First (Pragma_Argument_Associations (Post_Prag)))) |
| 4599 |
then |
| 4600 |
Error_Msg_N |
| 4601 |
("postcondition does not mention function result?.t?", Post_Prag); |
| 4602 |
end if; |
| 4603 |
end Check_Result_And_Post_State; |
| 4604 |
|
| 4605 |
----------------------------- |
| 4606 |
-- Check_State_Refinements -- |
| 4607 |
----------------------------- |
| 4608 |
|
| 4609 |
procedure Check_State_Refinements |
| 4610 |
(Context : Node_Id; |
| 4611 |
Is_Main_Unit : Boolean := False) |
| 4612 |
is |
| 4613 |
procedure Check_Package (Pack : Node_Id); |
| 4614 |
-- Verify that all abstract states of a [generic] package denoted by its |
| 4615 |
-- declarative node Pack have proper refinement. Recursively verify the |
| 4616 |
-- visible and private declarations of the [generic] package for other |
| 4617 |
-- nested packages. |
| 4618 |
|
| 4619 |
procedure Check_Packages_In (Decls : List_Id); |
| 4620 |
-- Seek out [generic] package declarations within declarative list Decls |
| 4621 |
-- and verify the status of their abstract state refinement. |
| 4622 |
|
| 4623 |
function SPARK_Mode_Is_Off (N : Node_Id) return Boolean; |
| 4624 |
-- Determine whether construct N is subject to pragma SPARK_Mode Off |
| 4625 |
|
| 4626 |
------------------- |
| 4627 |
-- Check_Package -- |
| 4628 |
------------------- |
| 4629 |
|
| 4630 |
procedure Check_Package (Pack : Node_Id) is |
| 4631 |
Body_Id : constant Entity_Id := Corresponding_Body (Pack); |
| 4632 |
Spec : constant Node_Id := Specification (Pack); |
| 4633 |
States : constant Elist_Id := |
| 4634 |
Abstract_States (Defining_Entity (Pack)); |
| 4635 |
|
| 4636 |
State_Elmt : Elmt_Id; |
| 4637 |
State_Id : Entity_Id; |
| 4638 |
|
| 4639 |
begin |
| 4640 |
-- Do not verify proper state refinement when the package is subject |
| 4641 |
-- to pragma SPARK_Mode Off because this disables the requirement for |
| 4642 |
-- state refinement. |
| 4643 |
|
| 4644 |
if SPARK_Mode_Is_Off (Pack) then |
| 4645 |
null; |
| 4646 |
|
| 4647 |
-- State refinement can only occur in a completing package body. Do |
| 4648 |
-- not verify proper state refinement when the body is subject to |
| 4649 |
-- pragma SPARK_Mode Off because this disables the requirement for |
| 4650 |
-- state refinement. |
| 4651 |
|
| 4652 |
elsif Present (Body_Id) |
| 4653 |
and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id)) |
| 4654 |
then |
| 4655 |
null; |
| 4656 |
|
| 4657 |
-- Do not verify proper state refinement when the package is an |
| 4658 |
-- instance as this check was already performed in the generic. |
| 4659 |
|
| 4660 |
elsif Present (Generic_Parent (Spec)) then |
| 4661 |
null; |
| 4662 |
|
| 4663 |
-- Otherwise examine the contents of the package |
| 4664 |
|
| 4665 |
else |
| 4666 |
if Present (States) then |
| 4667 |
State_Elmt := First_Elmt (States); |
| 4668 |
while Present (State_Elmt) loop |
| 4669 |
State_Id := Node (State_Elmt); |
| 4670 |
|
| 4671 |
-- Emit an error when a non-null state lacks refinement, |
| 4672 |
-- but has Part_Of constituents or there is a package |
| 4673 |
-- body (SPARK RM 7.1.4(4)). Constituents in private |
| 4674 |
-- child packages, which are not known at this stage, |
| 4675 |
-- independently require the existence of a package body. |
| 4676 |
|
| 4677 |
if not Is_Null_State (State_Id) |
| 4678 |
and then No (Refinement_Constituents (State_Id)) |
| 4679 |
and then |
| 4680 |
(Present (Part_Of_Constituents (State_Id)) |
| 4681 |
or else |
| 4682 |
Present (Body_Id)) |
| 4683 |
then |
| 4684 |
Error_Msg_N ("state & requires refinement", State_Id); |
| 4685 |
Error_Msg_N ("\package body should have Refined_State " |
| 4686 |
& "for state & with constituents", State_Id); |
| 4687 |
end if; |
| 4688 |
|
| 4689 |
Next_Elmt (State_Elmt); |
| 4690 |
end loop; |
| 4691 |
end if; |
| 4692 |
|
| 4693 |
Check_Packages_In (Visible_Declarations (Spec)); |
| 4694 |
Check_Packages_In (Private_Declarations (Spec)); |
| 4695 |
end if; |
| 4696 |
end Check_Package; |
| 4697 |
|
| 4698 |
----------------------- |
| 4699 |
-- Check_Packages_In -- |
| 4700 |
----------------------- |
| 4701 |
|
| 4702 |
procedure Check_Packages_In (Decls : List_Id) is |
| 4703 |
Decl : Node_Id; |
| 4704 |
|
| 4705 |
begin |
| 4706 |
if Present (Decls) then |
| 4707 |
Decl := First (Decls); |
| 4708 |
while Present (Decl) loop |
| 4709 |
if Nkind (Decl) in N_Generic_Package_Declaration |
| 4710 |
| N_Package_Declaration |
| 4711 |
then |
| 4712 |
Check_Package (Decl); |
| 4713 |
end if; |
| 4714 |
|
| 4715 |
Next (Decl); |
| 4716 |
end loop; |
| 4717 |
end if; |
| 4718 |
end Check_Packages_In; |
| 4719 |
|
| 4720 |
----------------------- |
| 4721 |
-- SPARK_Mode_Is_Off -- |
| 4722 |
----------------------- |
| 4723 |
|
| 4724 |
function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is |
| 4725 |
Id : constant Entity_Id := Defining_Entity (N); |
| 4726 |
Prag : constant Node_Id := SPARK_Pragma (Id); |
| 4727 |
|
| 4728 |
begin |
| 4729 |
-- Default the mode to "off" when the context is an instance and all |
| 4730 |
-- SPARK_Mode pragmas found within are to be ignored. |
| 4731 |
|
| 4732 |
if Ignore_SPARK_Mode_Pragmas (Id) then |
| 4733 |
return True; |
| 4734 |
|
| 4735 |
else |
| 4736 |
return |
| 4737 |
Present (Prag) |
| 4738 |
and then Get_SPARK_Mode_From_Annotation (Prag) = Off; |
| 4739 |
end if; |
| 4740 |
end SPARK_Mode_Is_Off; |
| 4741 |
|
| 4742 |
-- Start of processing for Check_State_Refinements |
| 4743 |
|
| 4744 |
begin |
| 4745 |
-- A block may declare a nested package |
| 4746 |
|
| 4747 |
if Nkind (Context) = N_Block_Statement then |
| 4748 |
Check_Packages_In (Declarations (Context)); |
| 4749 |
|
| 4750 |
-- An entry, protected, subprogram, or task body may declare a nested |
| 4751 |
-- package. |
| 4752 |
|
| 4753 |
elsif Nkind (Context) in N_Entry_Body |
| 4754 |
| N_Protected_Body |
| 4755 |
| N_Subprogram_Body |
| 4756 |
| N_Task_Body |
| 4757 |
then |
| 4758 |
-- Do not verify proper state refinement when the body is subject to |
| 4759 |
-- pragma SPARK_Mode Off because this disables the requirement for |
| 4760 |
-- state refinement. |
| 4761 |
|
| 4762 |
if not SPARK_Mode_Is_Off (Context) then |
| 4763 |
Check_Packages_In (Declarations (Context)); |
| 4764 |
end if; |
| 4765 |
|
| 4766 |
-- A package body may declare a nested package |
| 4767 |
|
| 4768 |
elsif Nkind (Context) = N_Package_Body then |
| 4769 |
Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context))); |
| 4770 |
|
| 4771 |
-- Do not verify proper state refinement when the body is subject to |
| 4772 |
-- pragma SPARK_Mode Off because this disables the requirement for |
| 4773 |
-- state refinement. |
| 4774 |
|
| 4775 |
if not SPARK_Mode_Is_Off (Context) then |
| 4776 |
Check_Packages_In (Declarations (Context)); |
| 4777 |
end if; |
| 4778 |
|
| 4779 |
-- A library level [generic] package may declare a nested package |
| 4780 |
|
| 4781 |
elsif Nkind (Context) in |
| 4782 |
N_Generic_Package_Declaration | N_Package_Declaration |
| 4783 |
and then Is_Main_Unit |
| 4784 |
then |
| 4785 |
Check_Package (Context); |
| 4786 |
end if; |
| 4787 |
end Check_State_Refinements; |
| 4788 |
|
| 4789 |
------------------------------ |
| 4790 |
-- Check_Unprotected_Access -- |
| 4791 |
------------------------------ |
| 4792 |
|
| 4793 |
procedure Check_Unprotected_Access |
| 4794 |
(Context : Node_Id; |
| 4795 |
Expr : Node_Id) |
| 4796 |
is |
| 4797 |
Cont_Encl_Typ : Entity_Id; |
| 4798 |
Pref_Encl_Typ : Entity_Id; |
| 4799 |
|
| 4800 |
function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id; |
| 4801 |
-- Check whether Obj is a private component of a protected object. |
| 4802 |
-- Return the protected type where the component resides, Empty |
| 4803 |
-- otherwise. |
| 4804 |
|
| 4805 |
function Is_Public_Operation return Boolean; |
| 4806 |
-- Verify that the enclosing operation is callable from outside the |
| 4807 |
-- protected object, to minimize false positives. |
| 4808 |
|
| 4809 |
------------------------------ |
| 4810 |
-- Enclosing_Protected_Type -- |
| 4811 |
------------------------------ |
| 4812 |
|
| 4813 |
function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is |
| 4814 |
begin |
| 4815 |
if Is_Entity_Name (Obj) then |
| 4816 |
declare |
| 4817 |
Ent : Entity_Id := Entity (Obj); |
| 4818 |
|
| 4819 |
begin |
| 4820 |
-- The object can be a renaming of a private component, use |
| 4821 |
-- the original record component. |
| 4822 |
|
| 4823 |
if Is_Prival (Ent) then |
| 4824 |
Ent := Prival_Link (Ent); |
| 4825 |
end if; |
| 4826 |
|
| 4827 |
if Is_Protected_Type (Scope (Ent)) then |
| 4828 |
return Scope (Ent); |
| 4829 |
end if; |
| 4830 |
end; |
| 4831 |
end if; |
| 4832 |
|
| 4833 |
-- For indexed and selected components, recursively check the prefix |
| 4834 |
|
| 4835 |
if Nkind (Obj) in N_Indexed_Component | N_Selected_Component then |
| 4836 |
return Enclosing_Protected_Type (Prefix (Obj)); |
| 4837 |
|
| 4838 |
-- The object does not denote a protected component |
| 4839 |
|
| 4840 |
else |
| 4841 |
return Empty; |
| 4842 |
end if; |
| 4843 |
end Enclosing_Protected_Type; |
| 4844 |
|
| 4845 |
------------------------- |
| 4846 |
-- Is_Public_Operation -- |
| 4847 |
------------------------- |
| 4848 |
|
| 4849 |
function Is_Public_Operation return Boolean is |
| 4850 |
S : Entity_Id; |
| 4851 |
E : Entity_Id; |
| 4852 |
|
| 4853 |
begin |
| 4854 |
S := Current_Scope; |
| 4855 |
while Present (S) and then S /= Pref_Encl_Typ loop |
| 4856 |
if Scope (S) = Pref_Encl_Typ then |
| 4857 |
E := First_Entity (Pref_Encl_Typ); |
| 4858 |
while Present (E) |
| 4859 |
and then E /= First_Private_Entity (Pref_Encl_Typ) |
| 4860 |
loop |
| 4861 |
if E = S then |
| 4862 |
return True; |
| 4863 |
end if; |
| 4864 |
|
| 4865 |
Next_Entity (E); |
| 4866 |
end loop; |
| 4867 |
end if; |
| 4868 |
|
| 4869 |
S := Scope (S); |
| 4870 |
end loop; |
| 4871 |
|
| 4872 |
return False; |
| 4873 |
end Is_Public_Operation; |
| 4874 |
|
| 4875 |
-- Start of processing for Check_Unprotected_Access |
| 4876 |
|
| 4877 |
begin |
| 4878 |
if Nkind (Expr) = N_Attribute_Reference |
| 4879 |
and then Attribute_Name (Expr) = Name_Unchecked_Access |
| 4880 |
then |
| 4881 |
Cont_Encl_Typ := Enclosing_Protected_Type (Context); |
| 4882 |
Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr)); |
| 4883 |
|
| 4884 |
-- Check whether we are trying to export a protected component to a |
| 4885 |
-- context with an equal or lower access level. |
| 4886 |
|
| 4887 |
if Present (Pref_Encl_Typ) |
| 4888 |
and then No (Cont_Encl_Typ) |
| 4889 |
and then Is_Public_Operation |
| 4890 |
and then Scope_Depth (Pref_Encl_Typ) |
| 4891 |
>= Static_Accessibility_Level |
| 4892 |
(Context, Object_Decl_Level) |
| 4893 |
then |
| 4894 |
Error_Msg_N |
| 4895 |
("??possible unprotected access to protected data", Expr); |
| 4896 |
end if; |
| 4897 |
end if; |
| 4898 |
end Check_Unprotected_Access; |
| 4899 |
|
| 4900 |
------------------------------ |
| 4901 |
-- Check_Unused_Body_States -- |
| 4902 |
------------------------------ |
| 4903 |
|
| 4904 |
procedure Check_Unused_Body_States (Body_Id : Entity_Id) is |
| 4905 |
procedure Process_Refinement_Clause |
| 4906 |
(Clause : Node_Id; |
| 4907 |
States : Elist_Id); |
| 4908 |
-- Inspect all constituents of refinement clause Clause and remove any |
| 4909 |
-- matches from body state list States. |
| 4910 |
|
| 4911 |
procedure Report_Unused_Body_States (States : Elist_Id); |
| 4912 |
-- Emit errors for each abstract state or object found in list States |
| 4913 |
|
| 4914 |
------------------------------- |
| 4915 |
-- Process_Refinement_Clause -- |
| 4916 |
------------------------------- |
| 4917 |
|
| 4918 |
procedure Process_Refinement_Clause |
| 4919 |
(Clause : Node_Id; |
| 4920 |
States : Elist_Id) |
| 4921 |
is |
| 4922 |
procedure Process_Constituent (Constit : Node_Id); |
| 4923 |
-- Remove constituent Constit from body state list States |
| 4924 |
|
| 4925 |
------------------------- |
| 4926 |
-- Process_Constituent -- |
| 4927 |
------------------------- |
| 4928 |
|
| 4929 |
procedure Process_Constituent (Constit : Node_Id) is |
| 4930 |
Constit_Id : Entity_Id; |
| 4931 |
|
| 4932 |
begin |
| 4933 |
-- Guard against illegal constituents. Only abstract states and |
| 4934 |
-- objects can appear on the right hand side of a refinement. |
| 4935 |
|
| 4936 |
if Is_Entity_Name (Constit) then |
| 4937 |
Constit_Id := Entity_Of (Constit); |
| 4938 |
|
| 4939 |
if Present (Constit_Id) |
| 4940 |
and then Ekind (Constit_Id) in |
| 4941 |
E_Abstract_State | E_Constant | E_Variable |
| 4942 |
then |
| 4943 |
Remove (States, Constit_Id); |
| 4944 |
end if; |
| 4945 |
end if; |
| 4946 |
end Process_Constituent; |
| 4947 |
|
| 4948 |
-- Local variables |
| 4949 |
|
| 4950 |
Constit : Node_Id; |
| 4951 |
|
| 4952 |
-- Start of processing for Process_Refinement_Clause |
| 4953 |
|
| 4954 |
begin |
| 4955 |
if Nkind (Clause) = N_Component_Association then |
| 4956 |
Constit := Expression (Clause); |
| 4957 |
|
| 4958 |
-- Multiple constituents appear as an aggregate |
| 4959 |
|
| 4960 |
if Nkind (Constit) = N_Aggregate then |
| 4961 |
Constit := First (Expressions (Constit)); |
| 4962 |
while Present (Constit) loop |
| 4963 |
Process_Constituent (Constit); |
| 4964 |
Next (Constit); |
| 4965 |
end loop; |
| 4966 |
|
| 4967 |
-- Various forms of a single constituent |
| 4968 |
|
| 4969 |
else |
| 4970 |
Process_Constituent (Constit); |
| 4971 |
end if; |
| 4972 |
end if; |
| 4973 |
end Process_Refinement_Clause; |
| 4974 |
|
| 4975 |
------------------------------- |
| 4976 |
-- Report_Unused_Body_States -- |
| 4977 |
------------------------------- |
| 4978 |
|
| 4979 |
procedure Report_Unused_Body_States (States : Elist_Id) is |
| 4980 |
Posted : Boolean := False; |
| 4981 |
State_Elmt : Elmt_Id; |
| 4982 |
State_Id : Entity_Id; |
| 4983 |
|
| 4984 |
begin |
| 4985 |
if Present (States) then |
| 4986 |
State_Elmt := First_Elmt (States); |
| 4987 |
while Present (State_Elmt) loop |
| 4988 |
State_Id := Node (State_Elmt); |
| 4989 |
|
| 4990 |
-- Constants are part of the hidden state of a package, but the |
| 4991 |
-- compiler cannot determine whether they have variable input |
| 4992 |
-- (SPARK RM 7.1.1(2)) and cannot classify them properly as a |
| 4993 |
-- hidden state. Do not emit an error when a constant does not |
| 4994 |
-- participate in a state refinement, even though it acts as a |
| 4995 |
-- hidden state. |
| 4996 |
|
| 4997 |
if Ekind (State_Id) = E_Constant then |
| 4998 |
null; |
| 4999 |
|
| 5000 |
-- Overlays do not contribute to package state |
| 5001 |
|
| 5002 |
elsif Ekind (State_Id) = E_Variable |
| 5003 |
and then Present (Ultimate_Overlaid_Entity (State_Id)) |
| 5004 |
then |
| 5005 |
null; |
| 5006 |
|
| 5007 |
-- Generate an error message of the form: |
| 5008 |
|
| 5009 |
-- body of package ... has unused hidden states |
| 5010 |
-- abstract state ... defined at ... |
| 5011 |
-- variable ... defined at ... |
| 5012 |
|
| 5013 |
else |
| 5014 |
if not Posted then |
| 5015 |
Posted := True; |
| 5016 |
SPARK_Msg_N |
| 5017 |
("body of package & has unused hidden states", Body_Id); |
| 5018 |
end if; |
| 5019 |
|
| 5020 |
Error_Msg_Sloc := Sloc (State_Id); |
| 5021 |
|
| 5022 |
if Ekind (State_Id) = E_Abstract_State then |
| 5023 |
SPARK_Msg_NE |
| 5024 |
("\abstract state & defined #", Body_Id, State_Id); |
| 5025 |
|
| 5026 |
else |
| 5027 |
SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id); |
| 5028 |
end if; |
| 5029 |
end if; |
| 5030 |
|
| 5031 |
Next_Elmt (State_Elmt); |
| 5032 |
end loop; |
| 5033 |
end if; |
| 5034 |
end Report_Unused_Body_States; |
| 5035 |
|
| 5036 |
-- Local variables |
| 5037 |
|
| 5038 |
Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State); |
| 5039 |
Spec_Id : constant Entity_Id := Spec_Entity (Body_Id); |
| 5040 |
Clause : Node_Id; |
| 5041 |
States : Elist_Id; |
| 5042 |
|
| 5043 |
-- Start of processing for Check_Unused_Body_States |
| 5044 |
|
| 5045 |
begin |
| 5046 |
-- Inspect the clauses of pragma Refined_State and determine whether all |
| 5047 |
-- visible states declared within the package body participate in the |
| 5048 |
-- refinement. |
| 5049 |
|
| 5050 |
if Present (Prag) then |
| 5051 |
Clause := Expression (Get_Argument (Prag, Spec_Id)); |
| 5052 |
States := Collect_Body_States (Body_Id); |
| 5053 |
|
| 5054 |
-- Multiple non-null state refinements appear as an aggregate |
| 5055 |
|
| 5056 |
if Nkind (Clause) = N_Aggregate then |
| 5057 |
Clause := First (Component_Associations (Clause)); |
| 5058 |
while Present (Clause) loop |
| 5059 |
Process_Refinement_Clause (Clause, States); |
| 5060 |
Next (Clause); |
| 5061 |
end loop; |
| 5062 |
|
| 5063 |
-- Various forms of a single state refinement |
| 5064 |
|
| 5065 |
else |
| 5066 |
Process_Refinement_Clause (Clause, States); |
| 5067 |
end if; |
| 5068 |
|
| 5069 |
-- Ensure that all abstract states and objects declared in the |
| 5070 |
-- package body state space are utilized as constituents. |
| 5071 |
|
| 5072 |
Report_Unused_Body_States (States); |
| 5073 |
end if; |
| 5074 |
end Check_Unused_Body_States; |
| 5075 |
|
| 5076 |
----------------- |
| 5077 |
-- Choice_List -- |
| 5078 |
----------------- |
| 5079 |
|
| 5080 |
function Choice_List (N : Node_Id) return List_Id is |
| 5081 |
begin |
| 5082 |
if Nkind (N) = N_Iterated_Component_Association then |
| 5083 |
return Discrete_Choices (N); |
| 5084 |
else |
| 5085 |
return Choices (N); |
| 5086 |
end if; |
| 5087 |
end Choice_List; |
| 5088 |
|
| 5089 |
--------------------- |
| 5090 |
-- Class_Condition -- |
| 5091 |
--------------------- |
| 5092 |
|
| 5093 |
function Class_Condition |
| 5094 |
(Kind : Condition_Kind; |
| 5095 |
Subp : Entity_Id) return Node_Id is |
| 5096 |
|
| 5097 |
begin |
| 5098 |
case Kind is |
| 5099 |
when Class_Postcondition => |
| 5100 |
return Class_Postconditions (Subp); |
| 5101 |
|
| 5102 |
when Class_Precondition => |
| 5103 |
return Class_Preconditions (Subp); |
| 5104 |
|
| 5105 |
when Ignored_Class_Postcondition => |
| 5106 |
return Ignored_Class_Postconditions (Subp); |
| 5107 |
|
| 5108 |
when Ignored_Class_Precondition => |
| 5109 |
return Ignored_Class_Preconditions (Subp); |
| 5110 |
end case; |
| 5111 |
end Class_Condition; |
| 5112 |
|
| 5113 |
------------------------- |
| 5114 |
-- Collect_Body_States -- |
| 5115 |
------------------------- |
| 5116 |
|
| 5117 |
function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is |
| 5118 |
function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean; |
| 5119 |
-- Determine whether object Obj_Id is a suitable visible state of a |
| 5120 |
-- package body. |
| 5121 |
|
| 5122 |
procedure Collect_Visible_States |
| 5123 |
(Pack_Id : Entity_Id; |
| 5124 |
States : in out Elist_Id); |
| 5125 |
-- Gather the entities of all abstract states and objects declared in |
| 5126 |
-- the visible state space of package Pack_Id. |
| 5127 |
|
| 5128 |
---------------------------- |
| 5129 |
-- Collect_Visible_States -- |
| 5130 |
---------------------------- |
| 5131 |
|
| 5132 |
procedure Collect_Visible_States |
| 5133 |
(Pack_Id : Entity_Id; |
| 5134 |
States : in out Elist_Id) |
| 5135 |
is |
| 5136 |
Item_Id : Entity_Id; |
| 5137 |
|
| 5138 |
begin |
| 5139 |
-- Traverse the entity chain of the package and inspect all visible |
| 5140 |
-- items. |
| 5141 |
|
| 5142 |
Item_Id := First_Entity (Pack_Id); |
| 5143 |
while Present (Item_Id) and then not In_Private_Part (Item_Id) loop |
| 5144 |
|
| 5145 |
-- Do not consider internally generated items as those cannot be |
| 5146 |
-- named and participate in refinement. |
| 5147 |
|
| 5148 |
if not Comes_From_Source (Item_Id) then |
| 5149 |
null; |
| 5150 |
|
| 5151 |
elsif Ekind (Item_Id) = E_Abstract_State then |
| 5152 |
Append_New_Elmt (Item_Id, States); |
| 5153 |
|
| 5154 |
elsif Ekind (Item_Id) in E_Constant | E_Variable |
| 5155 |
and then Is_Visible_Object (Item_Id) |
| 5156 |
then |
| 5157 |
Append_New_Elmt (Item_Id, States); |
| 5158 |
|
| 5159 |
-- Recursively gather the visible states of a nested package |
| 5160 |
-- except for nested package renamings. |
| 5161 |
|
| 5162 |
elsif Ekind (Item_Id) = E_Package |
| 5163 |
and then No (Renamed_Entity (Item_Id)) |
| 5164 |
then |
| 5165 |
Collect_Visible_States (Item_Id, States); |
| 5166 |
end if; |
| 5167 |
|
| 5168 |
Next_Entity (Item_Id); |
| 5169 |
end loop; |
| 5170 |
end Collect_Visible_States; |
| 5171 |
|
| 5172 |
----------------------- |
| 5173 |
-- Is_Visible_Object -- |
| 5174 |
----------------------- |
| 5175 |
|
| 5176 |
function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is |
| 5177 |
begin |
| 5178 |
-- Objects that map generic formals to their actuals are not visible |
| 5179 |
-- from outside the generic instantiation. |
| 5180 |
|
| 5181 |
if Present (Corresponding_Generic_Association |
| 5182 |
(Declaration_Node (Obj_Id))) |
| 5183 |
then |
| 5184 |
return False; |
| 5185 |
|
| 5186 |
-- Constituents of a single protected/task type act as components of |
| 5187 |
-- the type and are not visible from outside the type. |
| 5188 |
|
| 5189 |
elsif Ekind (Obj_Id) = E_Variable |
| 5190 |
and then Present (Encapsulating_State (Obj_Id)) |
| 5191 |
and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id)) |
| 5192 |
then |
| 5193 |
return False; |
| 5194 |
|
| 5195 |
else |
| 5196 |
return True; |
| 5197 |
end if; |
| 5198 |
end Is_Visible_Object; |
| 5199 |
|
| 5200 |
-- Local variables |
| 5201 |
|
| 5202 |
Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id); |
| 5203 |
Decl : Node_Id; |
| 5204 |
Item_Id : Entity_Id; |
| 5205 |
States : Elist_Id := No_Elist; |
| 5206 |
|
| 5207 |
-- Start of processing for Collect_Body_States |
| 5208 |
|
| 5209 |
begin |
| 5210 |
-- Inspect the declarations of the body looking for source objects, |
| 5211 |
-- packages and package instantiations. Note that even though this |
| 5212 |
-- processing is very similar to Collect_Visible_States, a package |
| 5213 |
-- body does not have a First/Next_Entity list. |
| 5214 |
|
| 5215 |
Decl := First (Declarations (Body_Decl)); |
| 5216 |
while Present (Decl) loop |
| 5217 |
|
| 5218 |
-- Capture source objects as internally generated temporaries cannot |
| 5219 |
-- be named and participate in refinement. |
| 5220 |
|
| 5221 |
if Nkind (Decl) = N_Object_Declaration then |
| 5222 |
Item_Id := Defining_Entity (Decl); |
| 5223 |
|
| 5224 |
if Comes_From_Source (Item_Id) |
| 5225 |
and then Is_Visible_Object (Item_Id) |
| 5226 |
then |
| 5227 |
Append_New_Elmt (Item_Id, States); |
| 5228 |
end if; |
| 5229 |
|
| 5230 |
-- Capture the visible abstract states and objects of a source |
| 5231 |
-- package [instantiation]. |
| 5232 |
|
| 5233 |
elsif Nkind (Decl) = N_Package_Declaration then |
| 5234 |
Item_Id := Defining_Entity (Decl); |
| 5235 |
|
| 5236 |
if Comes_From_Source (Item_Id) then |
| 5237 |
Collect_Visible_States (Item_Id, States); |
| 5238 |
end if; |
| 5239 |
end if; |
| 5240 |
|
| 5241 |
Next (Decl); |
| 5242 |
end loop; |
| 5243 |
|
| 5244 |
return States; |
| 5245 |
end Collect_Body_States; |
| 5246 |
|
| 5247 |
------------------------ |
| 5248 |
-- Collect_Interfaces -- |
| 5249 |
------------------------ |
| 5250 |
|
| 5251 |
procedure Collect_Interfaces |
| 5252 |
(T : Entity_Id; |
| 5253 |
Ifaces_List : out Elist_Id; |
| 5254 |
Exclude_Parents : Boolean := False; |
| 5255 |
Use_Full_View : Boolean := True) |
| 5256 |
is |
| 5257 |
procedure Collect (Typ : Entity_Id); |
| 5258 |
-- Subsidiary subprogram used to traverse the whole list |
| 5259 |
-- of directly and indirectly implemented interfaces |
| 5260 |
|
| 5261 |
------------- |
| 5262 |
-- Collect -- |
| 5263 |
------------- |
| 5264 |
|
| 5265 |
procedure Collect (Typ : Entity_Id) is |
| 5266 |
Ancestor : Entity_Id; |
| 5267 |
Full_T : Entity_Id; |
| 5268 |
Id : Node_Id; |
| 5269 |
Iface : Entity_Id; |
| 5270 |
|
| 5271 |
begin |
| 5272 |
Full_T := Typ; |
| 5273 |
|
| 5274 |
-- Handle private types and subtypes |
| 5275 |
|
| 5276 |
if Use_Full_View |
| 5277 |
and then Is_Private_Type (Typ) |
| 5278 |
and then Present (Full_View (Typ)) |
| 5279 |
then |
| 5280 |
Full_T := Full_View (Typ); |
| 5281 |
|
| 5282 |
if Ekind (Full_T) = E_Record_Subtype then |
| 5283 |
Full_T := Etype (Typ); |
| 5284 |
|
| 5285 |
if Present (Full_View (Full_T)) then |
| 5286 |
Full_T := Full_View (Full_T); |
| 5287 |
end if; |
| 5288 |
end if; |
| 5289 |
end if; |
| 5290 |
|
| 5291 |
-- Include the ancestor if we are generating the whole list of |
| 5292 |
-- abstract interfaces. |
| 5293 |
|
| 5294 |
if Etype (Full_T) /= Typ |
| 5295 |
|
| 5296 |
-- Protect the frontend against wrong sources. For example: |
| 5297 |
|
| 5298 |
-- package P is |
| 5299 |
-- type A is tagged null record; |
| 5300 |
-- type B is new A with private; |
| 5301 |
-- type C is new A with private; |
| 5302 |
-- private |
| 5303 |
-- type B is new C with null record; |
| 5304 |
-- type C is new B with null record; |
| 5305 |
-- end P; |
| 5306 |
|
| 5307 |
and then Etype (Full_T) /= T |
| 5308 |
then |
| 5309 |
Ancestor := Etype (Full_T); |
| 5310 |
Collect (Ancestor); |
| 5311 |
|
| 5312 |
if Is_Interface (Ancestor) and then not Exclude_Parents then |
| 5313 |
Append_Unique_Elmt (Ancestor, Ifaces_List); |
| 5314 |
end if; |
| 5315 |
end if; |
| 5316 |
|
| 5317 |
-- Traverse the graph of ancestor interfaces |
| 5318 |
|
| 5319 |
Id := First (Abstract_Interface_List (Full_T)); |
| 5320 |
while Present (Id) loop |
| 5321 |
Iface := Etype (Id); |
| 5322 |
|
| 5323 |
-- Protect against wrong uses. For example: |
| 5324 |
-- type I is interface; |
| 5325 |
-- type O is tagged null record; |
| 5326 |
-- type Wrong is new I and O with null record; -- ERROR |
| 5327 |
|
| 5328 |
if Is_Interface (Iface) then |
| 5329 |
if Exclude_Parents |
| 5330 |
and then Etype (T) /= T |
| 5331 |
and then Interface_Present_In_Ancestor (Etype (T), Iface) |
| 5332 |
then |
| 5333 |
null; |
| 5334 |
else |
| 5335 |
Collect (Iface); |
| 5336 |
Append_Unique_Elmt (Iface, Ifaces_List); |
| 5337 |
end if; |
| 5338 |
end if; |
| 5339 |
|
| 5340 |
Next (Id); |
| 5341 |
end loop; |
| 5342 |
end Collect; |
| 5343 |
|
| 5344 |
-- Start of processing for Collect_Interfaces |
| 5345 |
|
| 5346 |
begin |
| 5347 |
pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T)); |
| 5348 |
Ifaces_List := New_Elmt_List; |
| 5349 |
Collect (T); |
| 5350 |
end Collect_Interfaces; |
| 5351 |
|
| 5352 |
---------------------------------- |
| 5353 |
-- Collect_Interface_Components -- |
| 5354 |
---------------------------------- |
| 5355 |
|
| 5356 |
procedure Collect_Interface_Components |
| 5357 |
(Tagged_Type : Entity_Id; |
| 5358 |
Components_List : out Elist_Id) |
| 5359 |
is |
| 5360 |
procedure Collect (Typ : Entity_Id); |
| 5361 |
-- Subsidiary subprogram used to climb to the parents |
| 5362 |
|
| 5363 |
------------- |
| 5364 |
-- Collect -- |
| 5365 |
------------- |
| 5366 |
|
| 5367 |
procedure Collect (Typ : Entity_Id) is |
| 5368 |
Tag_Comp : Entity_Id; |
| 5369 |
Parent_Typ : Entity_Id; |
| 5370 |
|
| 5371 |
begin |
| 5372 |
-- Handle private types |
| 5373 |
|
| 5374 |
if Present (Full_View (Etype (Typ))) then |
| 5375 |
Parent_Typ := Full_View (Etype (Typ)); |
| 5376 |
else |
| 5377 |
Parent_Typ := Etype (Typ); |
| 5378 |
end if; |
| 5379 |
|
| 5380 |
if Parent_Typ /= Typ |
| 5381 |
|
| 5382 |
-- Protect the frontend against wrong sources. For example: |
| 5383 |
|
| 5384 |
-- package P is |
| 5385 |
-- type A is tagged null record; |
| 5386 |
-- type B is new A with private; |
| 5387 |
-- type C is new A with private; |
| 5388 |
-- private |
| 5389 |
-- type B is new C with null record; |
| 5390 |
-- type C is new B with null record; |
| 5391 |
-- end P; |
| 5392 |
|
| 5393 |
and then Parent_Typ /= Tagged_Type |
| 5394 |
then |
| 5395 |
Collect (Parent_Typ); |
| 5396 |
end if; |
| 5397 |
|
| 5398 |
-- Collect the components containing tags of secondary dispatch |
| 5399 |
-- tables. |
| 5400 |
|
| 5401 |
Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ)); |
| 5402 |
while Present (Tag_Comp) loop |
| 5403 |
pragma Assert (Present (Related_Type (Tag_Comp))); |
| 5404 |
Append_Elmt (Tag_Comp, Components_List); |
| 5405 |
|
| 5406 |
Tag_Comp := Next_Tag_Component (Tag_Comp); |
| 5407 |
end loop; |
| 5408 |
end Collect; |
| 5409 |
|
| 5410 |
-- Start of processing for Collect_Interface_Components |
| 5411 |
|
| 5412 |
begin |
| 5413 |
pragma Assert (Ekind (Tagged_Type) = E_Record_Type |
| 5414 |
and then Is_Tagged_Type (Tagged_Type)); |
| 5415 |
|
| 5416 |
Components_List := New_Elmt_List; |
| 5417 |
Collect (Tagged_Type); |
| 5418 |
end Collect_Interface_Components; |
| 5419 |
|
| 5420 |
----------------------------- |
| 5421 |
-- Collect_Interfaces_Info -- |
| 5422 |
----------------------------- |
| 5423 |
|
| 5424 |
procedure Collect_Interfaces_Info |
| 5425 |
(T : Entity_Id; |
| 5426 |
Ifaces_List : out Elist_Id; |
| 5427 |
Components_List : out Elist_Id; |
| 5428 |
Tags_List : out Elist_Id) |
| 5429 |
is |
| 5430 |
Comps_List : Elist_Id; |
| 5431 |
Comp_Elmt : Elmt_Id; |
| 5432 |
Comp_Iface : Entity_Id; |
| 5433 |
Iface_Elmt : Elmt_Id; |
| 5434 |
Iface : Entity_Id; |
| 5435 |
|
| 5436 |
function Search_Tag (Iface : Entity_Id) return Entity_Id; |
| 5437 |
-- Search for the secondary tag associated with the interface type |
| 5438 |
-- Iface that is implemented by T. |
| 5439 |
|
| 5440 |
---------------- |
| 5441 |
-- Search_Tag -- |
| 5442 |
---------------- |
| 5443 |
|
| 5444 |
function Search_Tag (Iface : Entity_Id) return Entity_Id is |
| 5445 |
ADT : Elmt_Id; |
| 5446 |
begin |
| 5447 |
if not Is_CPP_Class (T) then |
| 5448 |
ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T)))); |
| 5449 |
else |
| 5450 |
ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T))); |
| 5451 |
end if; |
| 5452 |
|
| 5453 |
while Present (ADT) |
| 5454 |
and then Is_Tag (Node (ADT)) |
| 5455 |
and then Related_Type (Node (ADT)) /= Iface |
| 5456 |
loop |
| 5457 |
-- Skip secondary dispatch table referencing thunks to user |
| 5458 |
-- defined primitives covered by this interface. |
| 5459 |
|
| 5460 |
pragma Assert (Has_Suffix (Node (ADT), 'P')); |
| 5461 |
Next_Elmt (ADT); |
| 5462 |
|
| 5463 |
-- Skip secondary dispatch tables of Ada types |
| 5464 |
|
| 5465 |
if not Is_CPP_Class (T) then |
| 5466 |
|
| 5467 |
-- Skip secondary dispatch table referencing thunks to |
| 5468 |
-- predefined primitives. |
| 5469 |
|
| 5470 |
pragma Assert (Has_Suffix (Node (ADT), 'Y')); |
| 5471 |
Next_Elmt (ADT); |
| 5472 |
|
| 5473 |
-- Skip secondary dispatch table referencing user-defined |
| 5474 |
-- primitives covered by this interface. |
| 5475 |
|
| 5476 |
pragma Assert (Has_Suffix (Node (ADT), 'D')); |
| 5477 |
Next_Elmt (ADT); |
| 5478 |
|
| 5479 |
-- Skip secondary dispatch table referencing predefined |
| 5480 |
-- primitives. |
| 5481 |
|
| 5482 |
pragma Assert (Has_Suffix (Node (ADT), 'Z')); |
| 5483 |
Next_Elmt (ADT); |
| 5484 |
end if; |
| 5485 |
end loop; |
| 5486 |
|
| 5487 |
pragma Assert (Is_Tag (Node (ADT))); |
| 5488 |
return Node (ADT); |
| 5489 |
end Search_Tag; |
| 5490 |
|
| 5491 |
-- Start of processing for Collect_Interfaces_Info |
| 5492 |
|
| 5493 |
begin |
| 5494 |
Collect_Interfaces (T, Ifaces_List); |
| 5495 |
Collect_Interface_Components (T, Comps_List); |
| 5496 |
|
| 5497 |
-- Search for the record component and tag associated with each |
| 5498 |
-- interface type of T. |
| 5499 |
|
| 5500 |
Components_List := New_Elmt_List; |
| 5501 |
Tags_List := New_Elmt_List; |
| 5502 |
|
| 5503 |
Iface_Elmt := First_Elmt (Ifaces_List); |
| 5504 |
while Present (Iface_Elmt) loop |
| 5505 |
Iface := Node (Iface_Elmt); |
| 5506 |
|
| 5507 |
-- Associate the primary tag component and the primary dispatch table |
| 5508 |
-- with all the interfaces that are parents of T |
| 5509 |
|
| 5510 |
if Is_Ancestor (Iface, T, Use_Full_View => True) then |
| 5511 |
Append_Elmt (First_Tag_Component (T), Components_List); |
| 5512 |
Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List); |
| 5513 |
|
| 5514 |
-- Otherwise search for the tag component and secondary dispatch |
| 5515 |
-- table of Iface |
| 5516 |
|
| 5517 |
else |
| 5518 |
Comp_Elmt := First_Elmt (Comps_List); |
| 5519 |
while Present (Comp_Elmt) loop |
| 5520 |
Comp_Iface := Related_Type (Node (Comp_Elmt)); |
| 5521 |
|
| 5522 |
if Comp_Iface = Iface |
| 5523 |
or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True) |
| 5524 |
then |
| 5525 |
Append_Elmt (Node (Comp_Elmt), Components_List); |
| 5526 |
Append_Elmt (Search_Tag (Comp_Iface), Tags_List); |
| 5527 |
exit; |
| 5528 |
end if; |
| 5529 |
|
| 5530 |
Next_Elmt (Comp_Elmt); |
| 5531 |
end loop; |
| 5532 |
pragma Assert (Present (Comp_Elmt)); |
| 5533 |
end if; |
| 5534 |
|
| 5535 |
Next_Elmt (Iface_Elmt); |
| 5536 |
end loop; |
| 5537 |
end Collect_Interfaces_Info; |
| 5538 |
|
| 5539 |
--------------------- |
| 5540 |
-- Collect_Parents -- |
| 5541 |
--------------------- |
| 5542 |
|
| 5543 |
procedure Collect_Parents |
| 5544 |
(T : Entity_Id; |
| 5545 |
List : out Elist_Id; |
| 5546 |
Use_Full_View : Boolean := True) |
| 5547 |
is |
| 5548 |
Current_Typ : Entity_Id := T; |
| 5549 |
Parent_Typ : Entity_Id; |
| 5550 |
|
| 5551 |
begin |
| 5552 |
List := New_Elmt_List; |
| 5553 |
|
| 5554 |
-- No action if the if the type has no parents |
| 5555 |
|
| 5556 |
if T = Etype (T) then |
| 5557 |
return; |
| 5558 |
end if; |
| 5559 |
|
| 5560 |
loop |
| 5561 |
Parent_Typ := Etype (Current_Typ); |
| 5562 |
|
| 5563 |
if Is_Private_Type (Parent_Typ) |
| 5564 |
and then Present (Full_View (Parent_Typ)) |
| 5565 |
and then Use_Full_View |
| 5566 |
then |
| 5567 |
Parent_Typ := Full_View (Base_Type (Parent_Typ)); |
| 5568 |
end if; |
| 5569 |
|
| 5570 |
Append_Elmt (Parent_Typ, List); |
| 5571 |
|
| 5572 |
exit when Parent_Typ = Current_Typ; |
| 5573 |
Current_Typ := Parent_Typ; |
| 5574 |
end loop; |
| 5575 |
end Collect_Parents; |
| 5576 |
|
| 5577 |
---------------------------------- |
| 5578 |
-- Collect_Primitive_Operations -- |
| 5579 |
---------------------------------- |
| 5580 |
|
| 5581 |
function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is |
| 5582 |
B_Type : constant Entity_Id := Base_Type (T); |
| 5583 |
|
| 5584 |
function Match (E : Entity_Id) return Boolean; |
| 5585 |
-- True if E's base type is B_Type, or E is of an anonymous access type |
| 5586 |
-- and the base type of its designated type is B_Type. |
| 5587 |
|
| 5588 |
----------- |
| 5589 |
-- Match -- |
| 5590 |
----------- |
| 5591 |
|
| 5592 |
function Match (E : Entity_Id) return Boolean is |
| 5593 |
Etyp : Entity_Id := Etype (E); |
| 5594 |
|
| 5595 |
begin |
| 5596 |
if Ekind (Etyp) = E_Anonymous_Access_Type then |
| 5597 |
Etyp := Designated_Type (Etyp); |
| 5598 |
end if; |
| 5599 |
|
| 5600 |
-- In Ada 2012 a primitive operation may have a formal of an |
| 5601 |
-- incomplete view of the parent type. |
| 5602 |
|
| 5603 |
return Base_Type (Etyp) = B_Type |
| 5604 |
or else |
| 5605 |
(Ada_Version >= Ada_2012 |
| 5606 |
and then Ekind (Etyp) = E_Incomplete_Type |
| 5607 |
and then Full_View (Etyp) = B_Type); |
| 5608 |
end Match; |
| 5609 |
|
| 5610 |
-- Local variables |
| 5611 |
|
| 5612 |
B_Decl : constant Node_Id := Original_Node (Parent (B_Type)); |
| 5613 |
B_Scope : Entity_Id := Scope (B_Type); |
| 5614 |
Op_List : Elist_Id; |
| 5615 |
Eq_Prims_List : Elist_Id := No_Elist; |
| 5616 |
Formal : Entity_Id; |
| 5617 |
Is_Prim : Boolean; |
| 5618 |
Is_Type_In_Pkg : Boolean; |
| 5619 |
Formal_Derived : Boolean := False; |
| 5620 |
Id : Entity_Id; |
| 5621 |
|
| 5622 |
-- Start of processing for Collect_Primitive_Operations |
| 5623 |
|
| 5624 |
begin |
| 5625 |
-- For tagged types, the primitive operations are collected as they |
| 5626 |
-- are declared, and held in an explicit list which is simply returned. |
| 5627 |
|
| 5628 |
if Is_Tagged_Type (B_Type) then |
| 5629 |
return Primitive_Operations (B_Type); |
| 5630 |
|
| 5631 |
-- An untagged generic type that is a derived type inherits the |
| 5632 |
-- primitive operations of its parent type. Other formal types only |
| 5633 |
-- have predefined operators, which are not explicitly represented. |
| 5634 |
|
| 5635 |
elsif Is_Generic_Type (B_Type) then |
| 5636 |
if Nkind (B_Decl) = N_Formal_Type_Declaration |
| 5637 |
and then Nkind (Formal_Type_Definition (B_Decl)) = |
| 5638 |
N_Formal_Derived_Type_Definition |
| 5639 |
then |
| 5640 |
Formal_Derived := True; |
| 5641 |
else |
| 5642 |
return New_Elmt_List; |
| 5643 |
end if; |
| 5644 |
end if; |
| 5645 |
|
| 5646 |
Op_List := New_Elmt_List; |
| 5647 |
|
| 5648 |
if B_Scope = Standard_Standard then |
| 5649 |
if B_Type = Standard_String then |
| 5650 |
Append_Elmt (Standard_Op_Concat, Op_List); |
| 5651 |
|
| 5652 |
elsif B_Type = Standard_Wide_String then |
| 5653 |
Append_Elmt (Standard_Op_Concatw, Op_List); |
| 5654 |
|
| 5655 |
else |
| 5656 |
null; |
| 5657 |
end if; |
| 5658 |
|
| 5659 |
-- Locate the primitive subprograms of the type |
| 5660 |
|
| 5661 |
else |
| 5662 |
-- The primitive operations appear after the base type, except if the |
| 5663 |
-- derivation happens within the private part of B_Scope and the type |
| 5664 |
-- is a private type, in which case both the type and some primitive |
| 5665 |
-- operations may appear before the base type, and the list of |
| 5666 |
-- candidates starts after the type. |
| 5667 |
|
| 5668 |
if In_Open_Scopes (B_Scope) |
| 5669 |
and then Scope (T) = B_Scope |
| 5670 |
and then In_Private_Part (B_Scope) |
| 5671 |
then |
| 5672 |
Id := Next_Entity (T); |
| 5673 |
|
| 5674 |
-- In Ada 2012, If the type has an incomplete partial view, there may |
| 5675 |
-- be primitive operations declared before the full view, so we need |
| 5676 |
-- to start scanning from the incomplete view, which is earlier on |
| 5677 |
-- the entity chain. |
| 5678 |
|
| 5679 |
elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration |
| 5680 |
and then Present (Incomplete_View (Parent (B_Type))) |
| 5681 |
then |
| 5682 |
Id := Incomplete_View (Parent (B_Type)); |
| 5683 |
|
| 5684 |
-- If T is a derived from a type with an incomplete view declared |
| 5685 |
-- elsewhere, that incomplete view is irrelevant, we want the |
| 5686 |
-- operations in the scope of T. |
| 5687 |
|
| 5688 |
if Scope (Id) /= Scope (B_Type) then |
| 5689 |
Id := Next_Entity (B_Type); |
| 5690 |
end if; |
| 5691 |
|
| 5692 |
else |
| 5693 |
Id := Next_Entity (B_Type); |
| 5694 |
end if; |
| 5695 |
|
| 5696 |
-- Set flag if this is a type in a package spec |
| 5697 |
|
| 5698 |
Is_Type_In_Pkg := |
| 5699 |
Is_Package_Or_Generic_Package (B_Scope) |
| 5700 |
and then |
| 5701 |
Parent_Kind (Declaration_Node (First_Subtype (T))) /= |
| 5702 |
N_Package_Body; |
| 5703 |
|
| 5704 |
while Present (Id) loop |
| 5705 |
|
| 5706 |
-- Test whether the result type or any of the parameter types of |
| 5707 |
-- each subprogram following the type match that type when the |
| 5708 |
-- type is declared in a package spec, is a derived type, or the |
| 5709 |
-- subprogram is marked as primitive. (The Is_Primitive test is |
| 5710 |
-- needed to find primitives of nonderived types in declarative |
| 5711 |
-- parts that happen to override the predefined "=" operator.) |
| 5712 |
|
| 5713 |
-- Note that generic formal subprograms are not considered to be |
| 5714 |
-- primitive operations and thus are never inherited. |
| 5715 |
|
| 5716 |
if Is_Overloadable (Id) |
| 5717 |
and then (Is_Type_In_Pkg |
| 5718 |
or else Is_Derived_Type (B_Type) |
| 5719 |
or else Is_Primitive (Id)) |
| 5720 |
and then Parent_Kind (Parent (Id)) |
| 5721 |
not in N_Formal_Subprogram_Declaration |
| 5722 |
then |
| 5723 |
Is_Prim := False; |
| 5724 |
|
| 5725 |
if Match (Id) then |
| 5726 |
Is_Prim := True; |
| 5727 |
|
| 5728 |
else |
| 5729 |
Formal := First_Formal (Id); |
| 5730 |
while Present (Formal) loop |
| 5731 |
if Match (Formal) then |
| 5732 |
Is_Prim := True; |
| 5733 |
exit; |
| 5734 |
end if; |
| 5735 |
|
| 5736 |
Next_Formal (Formal); |
| 5737 |
end loop; |
| 5738 |
end if; |
| 5739 |
|
| 5740 |
-- For a formal derived type, the only primitives are the ones |
| 5741 |
-- inherited from the parent type. Operations appearing in the |
| 5742 |
-- package declaration are not primitive for it. |
| 5743 |
|
| 5744 |
if Is_Prim |
| 5745 |
and then (not Formal_Derived or else Present (Alias (Id))) |
| 5746 |
then |
| 5747 |
-- In the special case of an equality operator aliased to |
| 5748 |
-- an overriding dispatching equality belonging to the same |
| 5749 |
-- type, we don't include it in the list of primitives. |
| 5750 |
-- This avoids inheriting multiple equality operators when |
| 5751 |
-- deriving from untagged private types whose full type is |
| 5752 |
-- tagged, which can otherwise cause ambiguities. Note that |
| 5753 |
-- this should only happen for this kind of untagged parent |
| 5754 |
-- type, since normally dispatching operations are inherited |
| 5755 |
-- using the type's Primitive_Operations list. |
| 5756 |
|
| 5757 |
if Chars (Id) = Name_Op_Eq |
| 5758 |
and then Is_Dispatching_Operation (Id) |
| 5759 |
and then Present (Alias (Id)) |
| 5760 |
and then Present (Overridden_Operation (Alias (Id))) |
| 5761 |
and then Base_Type (Etype (First_Entity (Id))) = |
| 5762 |
Base_Type (Etype (First_Entity (Alias (Id)))) |
| 5763 |
then |
| 5764 |
null; |
| 5765 |
|
| 5766 |
-- Include the subprogram in the list of primitives |
| 5767 |
|
| 5768 |
else |
| 5769 |
Append_Elmt (Id, Op_List); |
| 5770 |
|
| 5771 |
-- Save collected equality primitives for later filtering |
| 5772 |
-- (if we are processing a private type for which we can |
| 5773 |
-- collect several candidates). |
| 5774 |
|
| 5775 |
if Inherits_From_Tagged_Full_View (T) |
| 5776 |
and then Chars (Id) = Name_Op_Eq |
| 5777 |
and then Etype (First_Formal (Id)) = |
| 5778 |
Etype (Next_Formal (First_Formal (Id))) |
| 5779 |
then |
| 5780 |
Append_New_Elmt (Id, Eq_Prims_List); |
| 5781 |
end if; |
| 5782 |
end if; |
| 5783 |
end if; |
| 5784 |
end if; |
| 5785 |
|
| 5786 |
Next_Entity (Id); |
| 5787 |
|
| 5788 |
-- For a type declared in System, some of its operations may |
| 5789 |
-- appear in the target-specific extension to System. |
| 5790 |
|
| 5791 |
if No (Id) |
| 5792 |
and then Is_RTU (B_Scope, System) |
| 5793 |
and then Present_System_Aux |
| 5794 |
then |
| 5795 |
B_Scope := System_Aux_Id; |
| 5796 |
Id := First_Entity (System_Aux_Id); |
| 5797 |
end if; |
| 5798 |
end loop; |
| 5799 |
|
| 5800 |
-- Filter collected equality primitives |
| 5801 |
|
| 5802 |
if Inherits_From_Tagged_Full_View (T) |
| 5803 |
and then Present (Eq_Prims_List) |
| 5804 |
then |
| 5805 |
declare |
| 5806 |
First : constant Elmt_Id := First_Elmt (Eq_Prims_List); |
| 5807 |
Second : Elmt_Id; |
| 5808 |
|
| 5809 |
begin |
| 5810 |
pragma Assert (No (Next_Elmt (First)) |
| 5811 |
or else No (Next_Elmt (Next_Elmt (First)))); |
| 5812 |
|
| 5813 |
-- No action needed if we have collected a single equality |
| 5814 |
-- primitive |
| 5815 |
|
| 5816 |
if Present (Next_Elmt (First)) then |
| 5817 |
Second := Next_Elmt (First); |
| 5818 |
|
| 5819 |
if Is_Dispatching_Operation |
| 5820 |
(Ultimate_Alias (Node (First))) |
| 5821 |
then |
| 5822 |
Remove (Op_List, Node (First)); |
| 5823 |
|
| 5824 |
elsif Is_Dispatching_Operation |
| 5825 |
(Ultimate_Alias (Node (Second))) |
| 5826 |
then |
| 5827 |
Remove (Op_List, Node (Second)); |
| 5828 |
|
| 5829 |
else |
| 5830 |
raise Program_Error; |
| 5831 |
end if; |
| 5832 |
end if; |
| 5833 |
end; |
| 5834 |
end if; |
| 5835 |
end if; |
| 5836 |
|
| 5837 |
return Op_List; |
| 5838 |
end Collect_Primitive_Operations; |
| 5839 |
|
| 5840 |
----------------------------------- |
| 5841 |
-- Compile_Time_Constraint_Error -- |
| 5842 |
----------------------------------- |
| 5843 |
|
| 5844 |
function Compile_Time_Constraint_Error |
| 5845 |
(N : Node_Id; |
| 5846 |
Msg : String; |
| 5847 |
Ent : Entity_Id := Empty; |
| 5848 |
Loc : Source_Ptr := No_Location; |
| 5849 |
Warn : Boolean := False; |
| 5850 |
Extra_Msg : String := "") return Node_Id |
| 5851 |
is |
| 5852 |
Msgc : String (1 .. Msg'Length + 3); |
| 5853 |
-- Copy of message, with room for possible ?? or << and ! at end |
| 5854 |
|
| 5855 |
Msgl : Natural; |
| 5856 |
Wmsg : Boolean; |
| 5857 |
Eloc : Source_Ptr; |
| 5858 |
|
| 5859 |
begin |
| 5860 |
-- If this is a warning, convert it into an error if we are in code |
| 5861 |
-- subject to SPARK_Mode being set On, unless Warn is True to force a |
| 5862 |
-- warning. The rationale is that a compile-time constraint error should |
| 5863 |
-- lead to an error instead of a warning when SPARK_Mode is On, but in |
| 5864 |
-- a few cases we prefer to issue a warning and generate both a suitable |
| 5865 |
-- run-time error in GNAT and a suitable check message in GNATprove. |
| 5866 |
-- Those cases are those that likely correspond to deactivated SPARK |
| 5867 |
-- code, so that this kind of code can be compiled and analyzed instead |
| 5868 |
-- of being rejected. |
| 5869 |
|
| 5870 |
Error_Msg_Warn := Warn or SPARK_Mode /= On; |
| 5871 |
|
| 5872 |
-- A static constraint error in an instance body is not a fatal error. |
| 5873 |
-- We choose to inhibit the message altogether, because there is no |
| 5874 |
-- obvious node (for now) on which to post it. On the other hand the |
| 5875 |
-- offending node must be replaced with a constraint_error in any case. |
| 5876 |
|
| 5877 |
-- No messages are generated if we already posted an error on this node |
| 5878 |
|
| 5879 |
if not Error_Posted (N) then |
| 5880 |
if Loc /= No_Location then |
| 5881 |
Eloc := Loc; |
| 5882 |
else |
| 5883 |
Eloc := Sloc (N); |
| 5884 |
end if; |
| 5885 |
|
| 5886 |
-- Copy message to Msgc, converting any ? in the message into < |
| 5887 |
-- instead, so that we have an error in GNATprove mode. |
| 5888 |
|
| 5889 |
Msgl := Msg'Length; |
| 5890 |
|
| 5891 |
for J in 1 .. Msgl loop |
| 5892 |
if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then |
| 5893 |
Msgc (J) := '<'; |
| 5894 |
else |
| 5895 |
Msgc (J) := Msg (J); |
| 5896 |
end if; |
| 5897 |
end loop; |
| 5898 |
|
| 5899 |
-- Message is a warning, even in Ada 95 case |
| 5900 |
|
| 5901 |
if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then |
| 5902 |
Wmsg := True; |
| 5903 |
|
| 5904 |
-- In Ada 83, all messages are warnings. In the private part and the |
| 5905 |
-- body of an instance, constraint_checks are only warnings. We also |
| 5906 |
-- make this a warning if the Warn parameter is set. |
| 5907 |
|
| 5908 |
elsif Warn |
| 5909 |
or else (Ada_Version = Ada_83 and then Comes_From_Source (N)) |
| 5910 |
or else In_Instance_Not_Visible |
| 5911 |
then |
| 5912 |
Msgl := Msgl + 1; |
| 5913 |
Msgc (Msgl) := '<'; |
| 5914 |
Msgl := Msgl + 1; |
| 5915 |
Msgc (Msgl) := '<'; |
| 5916 |
Wmsg := True; |
| 5917 |
|
| 5918 |
-- Otherwise we have a real error message (Ada 95 static case) and we |
| 5919 |
-- make this an unconditional message. Note that in the warning case |
| 5920 |
-- we do not make the message unconditional, it seems reasonable to |
| 5921 |
-- delete messages like this (about exceptions that will be raised) |
| 5922 |
-- in dead code. |
| 5923 |
|
| 5924 |
else |
| 5925 |
Wmsg := False; |
| 5926 |
Msgl := Msgl + 1; |
| 5927 |
Msgc (Msgl) := '!'; |
| 5928 |
end if; |
| 5929 |
|
| 5930 |
-- One more test, skip the warning if the related expression is |
| 5931 |
-- statically unevaluated, since we don't want to warn about what |
| 5932 |
-- will happen when something is evaluated if it never will be |
| 5933 |
-- evaluated. |
| 5934 |
|
| 5935 |
-- Suppress error reporting when checking that the expression of a |
| 5936 |
-- static expression function is a potentially static expression, |
| 5937 |
-- because we don't want additional errors being reported during the |
| 5938 |
-- preanalysis of the expression (see Analyze_Expression_Function). |
| 5939 |
|
| 5940 |
if not Is_Statically_Unevaluated (N) |
| 5941 |
and then not Checking_Potentially_Static_Expression |
| 5942 |
then |
| 5943 |
if Present (Ent) then |
| 5944 |
Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc); |
| 5945 |
else |
| 5946 |
Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc); |
| 5947 |
end if; |
| 5948 |
|
| 5949 |
-- Emit any extra message as a continuation |
| 5950 |
|
| 5951 |
if Extra_Msg /= "" then |
| 5952 |
Error_Msg_N ('\' & Extra_Msg, N); |
| 5953 |
end if; |
| 5954 |
|
| 5955 |
if Wmsg then |
| 5956 |
|
| 5957 |
-- Check whether the context is an Init_Proc |
| 5958 |
|
| 5959 |
if Inside_Init_Proc then |
| 5960 |
declare |
| 5961 |
Init_Proc_Type : constant Entity_Id := |
| 5962 |
Etype (First_Formal (Current_Scope_No_Loops)); |
| 5963 |
|
| 5964 |
Conc_Typ : constant Entity_Id := |
| 5965 |
(if Present (Init_Proc_Type) |
| 5966 |
and then Ekind (Init_Proc_Type) = E_Record_Type |
| 5967 |
then Corresponding_Concurrent_Type (Init_Proc_Type) |
| 5968 |
else Empty); |
| 5969 |
|
| 5970 |
begin |
| 5971 |
-- Don't complain if the corresponding concurrent type |
| 5972 |
-- doesn't come from source (i.e. a single task/protected |
| 5973 |
-- object). |
| 5974 |
|
| 5975 |
if Present (Conc_Typ) |
| 5976 |
and then not Comes_From_Source (Conc_Typ) |
| 5977 |
then |
| 5978 |
Error_Msg ("\& [<<", Eloc, N); |
| 5979 |
|
| 5980 |
else |
| 5981 |
if GNATprove_Mode then |
| 5982 |
Error_Msg |
| 5983 |
("\Constraint_Error would have been raised" |
| 5984 |
& " for objects of this type", Eloc, N); |
| 5985 |
else |
| 5986 |
Error_Msg |
| 5987 |
("\Constraint_Error will be raised" |
| 5988 |
& " for objects of this type", Eloc, N); |
| 5989 |
end if; |
| 5990 |
end if; |
| 5991 |
end; |
| 5992 |
|
| 5993 |
else |
| 5994 |
Error_Msg ("\Constraint_Error [<<", Eloc, N); |
| 5995 |
end if; |
| 5996 |
|
| 5997 |
else |
| 5998 |
Error_Msg ("\static expression fails Constraint_Check", Eloc); |
| 5999 |
Set_Error_Posted (N); |
| 6000 |
end if; |
| 6001 |
end if; |
| 6002 |
end if; |
| 6003 |
|
| 6004 |
return N; |
| 6005 |
end Compile_Time_Constraint_Error; |
| 6006 |
|
| 6007 |
---------------------------- |
| 6008 |
-- Compute_Returns_By_Ref -- |
| 6009 |
---------------------------- |
| 6010 |
|
| 6011 |
procedure Compute_Returns_By_Ref (Func : Entity_Id) is |
| 6012 |
Kind : constant Entity_Kind := Ekind (Func); |
| 6013 |
Typ : constant Entity_Id := Etype (Func); |
| 6014 |
|
| 6015 |
begin |
| 6016 |
-- Nothing to do for procedures |
| 6017 |
|
| 6018 |
if Kind in E_Procedure | E_Generic_Procedure |
| 6019 |
or else (Kind = E_Subprogram_Type and then Typ = Standard_Void_Type) |
| 6020 |
then |
| 6021 |
null; |
| 6022 |
|
| 6023 |
-- The build-in-place protocols return a reference to the result |
| 6024 |
|
| 6025 |
elsif Is_Build_In_Place_Function (Func) then |
| 6026 |
Set_Returns_By_Ref (Func); |
| 6027 |
|
| 6028 |
-- In Ada 95, limited types are returned by reference, but not if the |
| 6029 |
-- convention is other than Ada. |
| 6030 |
|
| 6031 |
elsif Is_Inherently_Limited_Type (Typ) |
| 6032 |
and then not Has_Foreign_Convention (Func) |
| 6033 |
then |
| 6034 |
Set_Returns_By_Ref (Func); |
| 6035 |
end if; |
| 6036 |
end Compute_Returns_By_Ref; |
| 6037 |
|
| 6038 |
-------------------------------- |
| 6039 |
-- Collect_Types_In_Hierarchy -- |
| 6040 |
-------------------------------- |
| 6041 |
|
| 6042 |
function Collect_Types_In_Hierarchy |
| 6043 |
(Typ : Entity_Id; |
| 6044 |
Examine_Components : Boolean := False) return Elist_Id |
| 6045 |
is |
| 6046 |
Results : Elist_Id; |
| 6047 |
|
| 6048 |
procedure Process_Type (Typ : Entity_Id); |
| 6049 |
-- Collect type Typ if it satisfies function Predicate. Do so for its |
| 6050 |
-- parent type, base type, progenitor types, and any component types. |
| 6051 |
|
| 6052 |
------------------ |
| 6053 |
-- Process_Type -- |
| 6054 |
------------------ |
| 6055 |
|
| 6056 |
procedure Process_Type (Typ : Entity_Id) is |
| 6057 |
Comp : Entity_Id; |
| 6058 |
Iface_Elmt : Elmt_Id; |
| 6059 |
|
| 6060 |
begin |
| 6061 |
if not Is_Type (Typ) or else Error_Posted (Typ) then |
| 6062 |
return; |
| 6063 |
end if; |
| 6064 |
|
| 6065 |
-- Collect the current type if it satisfies the predicate |
| 6066 |
|
| 6067 |
if Predicate (Typ) then |
| 6068 |
Append_Elmt (Typ, Results); |
| 6069 |
end if; |
| 6070 |
|
| 6071 |
-- Process component types |
| 6072 |
|
| 6073 |
if Examine_Components then |
| 6074 |
|
| 6075 |
-- Examine components and discriminants |
| 6076 |
|
| 6077 |
if Is_Concurrent_Type (Typ) |
| 6078 |
or else Is_Incomplete_Or_Private_Type (Typ) |
| 6079 |
or else Is_Record_Type (Typ) |
| 6080 |
or else Has_Discriminants (Typ) |
| 6081 |
then |
| 6082 |
Comp := First_Component_Or_Discriminant (Typ); |
| 6083 |
|
| 6084 |
while Present (Comp) loop |
| 6085 |
Process_Type (Etype (Comp)); |
| 6086 |
|
| 6087 |
Next_Component_Or_Discriminant (Comp); |
| 6088 |
end loop; |
| 6089 |
|
| 6090 |
-- Examine array components |
| 6091 |
|
| 6092 |
elsif Ekind (Typ) = E_Array_Type then |
| 6093 |
Process_Type (Component_Type (Typ)); |
| 6094 |
end if; |
| 6095 |
end if; |
| 6096 |
|
| 6097 |
-- Examine parent type |
| 6098 |
|
| 6099 |
if Etype (Typ) /= Typ then |
| 6100 |
-- Prevent infinite recursion, which can happen in illegal |
| 6101 |
-- programs. Silently return if illegal. For now, just deal |
| 6102 |
-- with the 2-type cycle case. Larger cycles will get |
| 6103 |
-- SIGSEGV at compile time from running out of stack. |
| 6104 |
|
| 6105 |
if Etype (Etype (Typ)) = Typ then |
| 6106 |
if Total_Errors_Detected = 0 then |
| 6107 |
raise Program_Error; |
| 6108 |
else |
| 6109 |
return; |
| 6110 |
end if; |
| 6111 |
end if; |
| 6112 |
|
| 6113 |
Process_Type (Etype (Typ)); |
| 6114 |
end if; |
| 6115 |
|
| 6116 |
-- Examine base type |
| 6117 |
|
| 6118 |
if Base_Type (Typ) /= Typ then |
| 6119 |
Process_Type (Base_Type (Typ)); |
| 6120 |
end if; |
| 6121 |
|
| 6122 |
-- Examine interfaces |
| 6123 |
|
| 6124 |
if Is_Record_Type (Typ) |
| 6125 |
and then Present (Interfaces (Typ)) |
| 6126 |
then |
| 6127 |
Iface_Elmt := First_Elmt (Interfaces (Typ)); |
| 6128 |
while Present (Iface_Elmt) loop |
| 6129 |
Process_Type (Node (Iface_Elmt)); |
| 6130 |
|
| 6131 |
Next_Elmt (Iface_Elmt); |
| 6132 |
end loop; |
| 6133 |
end if; |
| 6134 |
end Process_Type; |
| 6135 |
|
| 6136 |
-- Start of processing for Collect_Types_In_Hierarchy |
| 6137 |
|
| 6138 |
begin |
| 6139 |
Results := New_Elmt_List; |
| 6140 |
Process_Type (Typ); |
| 6141 |
return Results; |
| 6142 |
end Collect_Types_In_Hierarchy; |
| 6143 |
|
| 6144 |
----------------------- |
| 6145 |
-- Conditional_Delay -- |
| 6146 |
----------------------- |
| 6147 |
|
| 6148 |
procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is |
| 6149 |
begin |
| 6150 |
if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then |
| 6151 |
Set_Has_Delayed_Freeze (New_Ent); |
| 6152 |
end if; |
| 6153 |
end Conditional_Delay; |
| 6154 |
|
| 6155 |
------------------------- |
| 6156 |
-- Copy_Component_List -- |
| 6157 |
------------------------- |
| 6158 |
|
| 6159 |
function Copy_Component_List |
| 6160 |
(R_Typ : Entity_Id; |
| 6161 |
Loc : Source_Ptr) return List_Id |
| 6162 |
is |
| 6163 |
Comp : Node_Id; |
| 6164 |
Comps : constant List_Id := New_List; |
| 6165 |
|
| 6166 |
begin |
| 6167 |
Comp := First_Component (Underlying_Type (R_Typ)); |
| 6168 |
while Present (Comp) loop |
| 6169 |
if Comes_From_Source (Comp) then |
| 6170 |
declare |
| 6171 |
Comp_Decl : constant Node_Id := Declaration_Node (Comp); |
| 6172 |
begin |
| 6173 |
Append_To (Comps, |
| 6174 |
Make_Component_Declaration (Loc, |
| 6175 |
Defining_Identifier => |
| 6176 |
Make_Defining_Identifier (Loc, Chars (Comp)), |
| 6177 |
Component_Definition => |
| 6178 |
New_Copy_Tree |
| 6179 |
(Component_Definition (Comp_Decl), New_Sloc => Loc))); |
| 6180 |
end; |
| 6181 |
end if; |
| 6182 |
|
| 6183 |
Next_Component (Comp); |
| 6184 |
end loop; |
| 6185 |
|
| 6186 |
return Comps; |
| 6187 |
end Copy_Component_List; |
| 6188 |
|
| 6189 |
----------------------- |
| 6190 |
-- Copy_Ghost_Aspect -- |
| 6191 |
----------------------- |
| 6192 |
|
| 6193 |
procedure Copy_Ghost_Aspect (From : Node_Id; To : Node_Id) is |
| 6194 |
pragma Assert (not Has_Aspects (To)); |
| 6195 |
Asp : Node_Id; |
| 6196 |
|
| 6197 |
begin |
| 6198 |
if Has_Aspects (From) then |
| 6199 |
Asp := Find_Aspect (Defining_Entity (From), Aspect_Ghost); |
| 6200 |
|
| 6201 |
if Present (Asp) then |
| 6202 |
Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp))); |
| 6203 |
end if; |
| 6204 |
end if; |
| 6205 |
end Copy_Ghost_Aspect; |
| 6206 |
|
| 6207 |
------------------------- |
| 6208 |
-- Copy_Parameter_List -- |
| 6209 |
------------------------- |
| 6210 |
|
| 6211 |
function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is |
| 6212 |
Loc : constant Source_Ptr := Sloc (Subp_Id); |
| 6213 |
Plist : List_Id; |
| 6214 |
Formal : Entity_Id := First_Formal (Subp_Id); |
| 6215 |
|
| 6216 |
begin |
| 6217 |
if Present (Formal) then |
| 6218 |
Plist := New_List; |
| 6219 |
while Present (Formal) loop |
| 6220 |
Append_To (Plist, |
| 6221 |
Make_Parameter_Specification (Loc, |
| 6222 |
Defining_Identifier => |
| 6223 |
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)), |
| 6224 |
In_Present => In_Present (Parent (Formal)), |
| 6225 |
Out_Present => Out_Present (Parent (Formal)), |
| 6226 |
Parameter_Type => |
| 6227 |
New_Occurrence_Of (Etype (Formal), Loc), |
| 6228 |
Expression => |
| 6229 |
New_Copy_Tree (Expression (Parent (Formal))))); |
| 6230 |
|
| 6231 |
Next_Formal (Formal); |
| 6232 |
end loop; |
| 6233 |
else |
| 6234 |
Plist := No_List; |
| 6235 |
end if; |
| 6236 |
|
| 6237 |
return Plist; |
| 6238 |
end Copy_Parameter_List; |
| 6239 |
|
| 6240 |
---------------------------- |
| 6241 |
-- Copy_SPARK_Mode_Aspect -- |
| 6242 |
---------------------------- |
| 6243 |
|
| 6244 |
procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is |
| 6245 |
pragma Assert (not Has_Aspects (To)); |
| 6246 |
Asp : Node_Id; |
| 6247 |
|
| 6248 |
begin |
| 6249 |
if Has_Aspects (From) then |
| 6250 |
Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode); |
| 6251 |
|
| 6252 |
if Present (Asp) then |
| 6253 |
Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp))); |
| 6254 |
end if; |
| 6255 |
end if; |
| 6256 |
end Copy_SPARK_Mode_Aspect; |
| 6257 |
|
| 6258 |
-------------------------- |
| 6259 |
-- Copy_Subprogram_Spec -- |
| 6260 |
-------------------------- |
| 6261 |
|
| 6262 |
function Copy_Subprogram_Spec |
| 6263 |
(Spec : Node_Id; |
| 6264 |
New_Sloc : Source_Ptr := No_Location) return Node_Id |
| 6265 |
is |
| 6266 |
Def_Id : Node_Id; |
| 6267 |
Formal_Spec : Node_Id; |
| 6268 |
Result : Node_Id; |
| 6269 |
|
| 6270 |
begin |
| 6271 |
-- The structure of the original tree must be replicated without any |
| 6272 |
-- alterations. Use New_Copy_Tree for this purpose. |
| 6273 |
|
| 6274 |
Result := New_Copy_Tree (Spec, New_Sloc => New_Sloc); |
| 6275 |
|
| 6276 |
-- However, the spec of a null procedure carries the corresponding null |
| 6277 |
-- statement of the body (created by the parser), and this cannot be |
| 6278 |
-- shared with the new subprogram spec. |
| 6279 |
|
| 6280 |
if Nkind (Result) = N_Procedure_Specification then |
| 6281 |
Set_Null_Statement (Result, Empty); |
| 6282 |
end if; |
| 6283 |
|
| 6284 |
-- Create a new entity for the defining unit name |
| 6285 |
|
| 6286 |
Def_Id := Defining_Unit_Name (Result); |
| 6287 |
|
| 6288 |
case Nkind (Def_Id) is |
| 6289 |
when N_Defining_Identifier => |
| 6290 |
Def_Id := Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)); |
| 6291 |
when N_Defining_Operator_Symbol => |
| 6292 |
Def_Id := |
| 6293 |
Make_Defining_Operator_Symbol (Sloc (Def_Id), Chars (Def_Id)); |
| 6294 |
when others => raise Program_Error; |
| 6295 |
end case; |
| 6296 |
|
| 6297 |
Set_Defining_Unit_Name (Result, Def_Id); |
| 6298 |
|
| 6299 |
-- Create new entities for the formal parameters |
| 6300 |
|
| 6301 |
Formal_Spec := First (Parameter_Specifications (Result)); |
| 6302 |
while Present (Formal_Spec) loop |
| 6303 |
Def_Id := Defining_Identifier (Formal_Spec); |
| 6304 |
Set_Defining_Identifier (Formal_Spec, |
| 6305 |
Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id))); |
| 6306 |
|
| 6307 |
Next (Formal_Spec); |
| 6308 |
end loop; |
| 6309 |
|
| 6310 |
return Result; |
| 6311 |
end Copy_Subprogram_Spec; |
| 6312 |
|
| 6313 |
-------------------------------- |
| 6314 |
-- Corresponding_Generic_Type -- |
| 6315 |
-------------------------------- |
| 6316 |
|
| 6317 |
function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is |
| 6318 |
Inst : Entity_Id; |
| 6319 |
Gen : Entity_Id; |
| 6320 |
Typ : Entity_Id; |
| 6321 |
|
| 6322 |
begin |
| 6323 |
if not Is_Generic_Actual_Type (T) then |
| 6324 |
return Any_Type; |
| 6325 |
|
| 6326 |
-- If the actual is the actual of an enclosing instance, resolution |
| 6327 |
-- was correct in the generic. |
| 6328 |
|
| 6329 |
elsif Nkind (Parent (T)) = N_Subtype_Declaration |
| 6330 |
and then Is_Entity_Name (Subtype_Indication (Parent (T))) |
| 6331 |
and then |
| 6332 |
Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T)))) |
| 6333 |
then |
| 6334 |
return Any_Type; |
| 6335 |
|
| 6336 |
else |
| 6337 |
Inst := Scope (T); |
| 6338 |
|
| 6339 |
if Is_Wrapper_Package (Inst) then |
| 6340 |
Inst := Related_Instance (Inst); |
| 6341 |
end if; |
| 6342 |
|
| 6343 |
Gen := |
| 6344 |
Generic_Parent |
| 6345 |
(Specification (Unit_Declaration_Node (Inst))); |
| 6346 |
|
| 6347 |
-- Generic actual has the same name as the corresponding formal |
| 6348 |
|
| 6349 |
Typ := First_Entity (Gen); |
| 6350 |
while Present (Typ) loop |
| 6351 |
if Chars (Typ) = Chars (T) then |
| 6352 |
return Typ; |
| 6353 |
end if; |
| 6354 |
|
| 6355 |
Next_Entity (Typ); |
| 6356 |
end loop; |
| 6357 |
|
| 6358 |
return Any_Type; |
| 6359 |
end if; |
| 6360 |
end Corresponding_Generic_Type; |
| 6361 |
|
| 6362 |
-------------------------------------- |
| 6363 |
-- Corresponding_Op_Of_Derived_Type -- |
| 6364 |
-------------------------------------- |
| 6365 |
|
| 6366 |
function Corresponding_Op_Of_Derived_Type |
| 6367 |
(Ancestor_Op : Entity_Id; |
| 6368 |
Descendant_Type : Entity_Id) return Entity_Id |
| 6369 |
is |
| 6370 |
function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id; |
| 6371 |
-- Search for the untagged type of the primitive operation Prim. |
| 6372 |
|
| 6373 |
function Profile_Matches_Ancestor (S : Entity_Id) return Boolean; |
| 6374 |
-- Returns True if subprogram S has the proper profile for an |
| 6375 |
-- overriding of Ancestor_Op (that is, corresponding formals either |
| 6376 |
-- have the same type, or are corresponding controlling formals, |
| 6377 |
-- and similarly for result types). |
| 6378 |
|
| 6379 |
--------------------------- |
| 6380 |
-- Find_Untagged_Type_Of -- |
| 6381 |
--------------------------- |
| 6382 |
|
| 6383 |
function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id is |
| 6384 |
E : Entity_Id := First_Entity (Scope (Prim)); |
| 6385 |
|
| 6386 |
begin |
| 6387 |
while Present (E) and then E /= Prim loop |
| 6388 |
if Is_Type (E) and then not Is_Tagged_Type (E) |
| 6389 |
and then Contains (Direct_Primitive_Operations (E), Prim) |
| 6390 |
then |
| 6391 |
return E; |
| 6392 |
end if; |
| 6393 |
|
| 6394 |
Next_Entity (E); |
| 6395 |
end loop; |
| 6396 |
|
| 6397 |
-- If a primitive is not found, then return Empty, and in that case |
| 6398 |
-- the ancestor subprogram will be returned (which can occur in |
| 6399 |
-- class-wide subprogram cases, which are not primitives). |
| 6400 |
|
| 6401 |
return Empty; |
| 6402 |
end Find_Untagged_Type_Of; |
| 6403 |
|
| 6404 |
------------------------------ |
| 6405 |
-- Profile_Matches_Ancestor -- |
| 6406 |
------------------------------ |
| 6407 |
|
| 6408 |
function Profile_Matches_Ancestor (S : Entity_Id) return Boolean is |
| 6409 |
F1 : Entity_Id := First_Formal (Ancestor_Op); |
| 6410 |
F2 : Entity_Id := First_Formal (S); |
| 6411 |
Impl_Type_1 : Entity_Id; |
| 6412 |
Impl_Type_2 : Entity_Id; |
| 6413 |
|
| 6414 |
begin |
| 6415 |
if Ekind (Ancestor_Op) /= Ekind (S) then |
| 6416 |
return False; |
| 6417 |
end if; |
| 6418 |
|
| 6419 |
-- ??? This function should probably be extended to account for |
| 6420 |
-- anonymous access formals and anonymous access result types. |
| 6421 |
|
| 6422 |
while Present (F1) and then Present (F2) loop |
| 6423 |
Impl_Type_1 := Implementation_Base_Type (Etype (F1)); |
| 6424 |
Impl_Type_2 := Implementation_Base_Type (Etype (F2)); |
| 6425 |
|
| 6426 |
if Impl_Type_1 = Impl_Type_2 |
| 6427 |
or else Is_Ancestor (Impl_Type_1, Impl_Type_2) |
| 6428 |
or else (Is_Interface (Impl_Type_1) |
| 6429 |
and then |
| 6430 |
Is_Progenitor (Impl_Type_1, Impl_Type_2)) |
| 6431 |
then |
| 6432 |
Next_Formal (F1); |
| 6433 |
Next_Formal (F2); |
| 6434 |
else |
| 6435 |
return False; |
| 6436 |
end if; |
| 6437 |
end loop; |
| 6438 |
|
| 6439 |
Impl_Type_1 := Implementation_Base_Type (Etype (Ancestor_Op)); |
| 6440 |
Impl_Type_2 := Implementation_Base_Type (Etype (S)); |
| 6441 |
|
| 6442 |
return No (F1) |
| 6443 |
and then No (F2) |
| 6444 |
and then (Impl_Type_1 = Impl_Type_2 |
| 6445 |
or else |
| 6446 |
Is_Ancestor (Impl_Type_1, Impl_Type_2) |
| 6447 |
or else |
| 6448 |
(Is_Interface (Impl_Type_1) |
| 6449 |
and then Is_Progenitor (Impl_Type_1, Impl_Type_2))); |
| 6450 |
end Profile_Matches_Ancestor; |
| 6451 |
|
| 6452 |
-- Local variables |
| 6453 |
|
| 6454 |
Elmt : Elmt_Id; |
| 6455 |
Subp : Entity_Id; |
| 6456 |
Typ : constant Entity_Id := |
| 6457 |
(if Is_Dispatching_Operation (Ancestor_Op) |
| 6458 |
then Find_Dispatching_Type (Ancestor_Op) |
| 6459 |
else Find_Untagged_Type_Of (Ancestor_Op)); |
| 6460 |
|
| 6461 |
-- Start of processing for Corresponding_Op_Of_Derived_Type |
| 6462 |
|
| 6463 |
begin |
| 6464 |
-- If Ancestor_Op isn't a primitive of the parent type, then simply |
| 6465 |
-- return it (it can be a nonprimitive class-wide subprogram). |
| 6466 |
|
| 6467 |
if No (Typ) |
| 6468 |
or else (not Is_Ancestor (Typ, Descendant_Type) |
| 6469 |
and then not Is_Progenitor (Typ, Descendant_Type)) |
| 6470 |
then |
| 6471 |
return Ancestor_Op; |
| 6472 |
end if; |
| 6473 |
|
| 6474 |
Elmt := First_Elmt (Primitive_Operations (Descendant_Type)); |
| 6475 |
|
| 6476 |
while Present (Elmt) loop |
| 6477 |
Subp := Node (Elmt); |
| 6478 |
|
| 6479 |
-- For regular primitives we need to check the profile against |
| 6480 |
-- the ancestor when the name matches the name of Ancestor_Op, |
| 6481 |
-- but for predefined dispatching operations we cannot rely on |
| 6482 |
-- the name of the primitive to identify a candidate since their |
| 6483 |
-- name is internally built by adding a suffix to the name of the |
| 6484 |
-- tagged type. |
| 6485 |
|
| 6486 |
if Chars (Subp) = Chars (Ancestor_Op) |
| 6487 |
or else Is_Predefined_Dispatching_Operation (Subp) |
| 6488 |
then |
| 6489 |
-- Handle case where Ancestor_Op is a primitive of a progenitor. |
| 6490 |
-- We rely on internal entities that map interface primitives: |
| 6491 |
-- their attribute Interface_Alias references the interface |
| 6492 |
-- primitive, and their Alias attribute references the primitive |
| 6493 |
-- of Descendant_Type implementing that interface primitive. |
| 6494 |
|
| 6495 |
if Present (Interface_Alias (Subp)) then |
| 6496 |
if Interface_Alias (Subp) = Ancestor_Op then |
| 6497 |
return Alias (Subp); |
| 6498 |
end if; |
| 6499 |
|
| 6500 |
-- Otherwise, return subprogram when profile matches its ancestor |
| 6501 |
|
| 6502 |
elsif Profile_Matches_Ancestor (Subp) then |
| 6503 |
return Subp; |
| 6504 |
end if; |
| 6505 |
end if; |
| 6506 |
|
| 6507 |
Next_Elmt (Elmt); |
| 6508 |
end loop; |
| 6509 |
|
| 6510 |
pragma Assert (False); |
| 6511 |
return Empty; |
| 6512 |
end Corresponding_Op_Of_Derived_Type; |
| 6513 |
|
| 6514 |
-------------------- |
| 6515 |
-- Current_Entity -- |
| 6516 |
-------------------- |
| 6517 |
|
| 6518 |
-- The currently visible definition for a given identifier is the |
| 6519 |
-- one most chained at the start of the visibility chain, i.e. the |
| 6520 |
-- one that is referenced by the Node_Id value of the name of the |
| 6521 |
-- given identifier. |
| 6522 |
|
| 6523 |
function Current_Entity (N : Node_Id) return Entity_Id is |
| 6524 |
begin |
| 6525 |
return Get_Name_Entity_Id (Chars (N)); |
| 6526 |
end Current_Entity; |
| 6527 |
|
| 6528 |
----------------------------- |
| 6529 |
-- Current_Entity_In_Scope -- |
| 6530 |
----------------------------- |
| 6531 |
|
| 6532 |
function Current_Entity_In_Scope (N : Name_Id) return Entity_Id is |
| 6533 |
CS : constant Entity_Id := Current_Scope; |
| 6534 |
|
| 6535 |
E : Entity_Id; |
| 6536 |
|
| 6537 |
begin |
| 6538 |
E := Get_Name_Entity_Id (N); |
| 6539 |
|
| 6540 |
if No (E) then |
| 6541 |
null; |
| 6542 |
|
| 6543 |
elsif Scope_Is_Transient then |
| 6544 |
while Present (E) loop |
| 6545 |
exit when Scope (E) = CS or else Scope (E) = Scope (CS); |
| 6546 |
|
| 6547 |
E := Homonym (E); |
| 6548 |
end loop; |
| 6549 |
|
| 6550 |
else |
| 6551 |
while Present (E) loop |
| 6552 |
exit when Scope (E) = CS; |
| 6553 |
|
| 6554 |
E := Homonym (E); |
| 6555 |
end loop; |
| 6556 |
end if; |
| 6557 |
|
| 6558 |
return E; |
| 6559 |
end Current_Entity_In_Scope; |
| 6560 |
|
| 6561 |
----------------------------- |
| 6562 |
-- Current_Entity_In_Scope -- |
| 6563 |
----------------------------- |
| 6564 |
|
| 6565 |
function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is |
| 6566 |
begin |
| 6567 |
return Current_Entity_In_Scope (Chars (N)); |
| 6568 |
end Current_Entity_In_Scope; |
| 6569 |
|
| 6570 |
------------------- |
| 6571 |
-- Current_Scope -- |
| 6572 |
------------------- |
| 6573 |
|
| 6574 |
function Current_Scope return Entity_Id is |
| 6575 |
begin |
| 6576 |
if Scope_Stack.Last = -1 then |
| 6577 |
return Standard_Standard; |
| 6578 |
else |
| 6579 |
declare |
| 6580 |
C : constant Entity_Id := |
| 6581 |
Scope_Stack.Table (Scope_Stack.Last).Entity; |
| 6582 |
begin |
| 6583 |
if Present (C) then |
| 6584 |
return C; |
| 6585 |
else |
| 6586 |
return Standard_Standard; |
| 6587 |
end if; |
| 6588 |
end; |
| 6589 |
end if; |
| 6590 |
end Current_Scope; |
| 6591 |
|
| 6592 |
---------------------------- |
| 6593 |
-- Current_Scope_No_Loops -- |
| 6594 |
---------------------------- |
| 6595 |
|
| 6596 |
function Current_Scope_No_Loops return Entity_Id is |
| 6597 |
S : Entity_Id; |
| 6598 |
|
| 6599 |
begin |
| 6600 |
-- Examine the scope stack starting from the current scope and skip any |
| 6601 |
-- internally generated loops. |
| 6602 |
|
| 6603 |
S := Current_Scope; |
| 6604 |
while Present (S) and then S /= Standard_Standard loop |
| 6605 |
if Ekind (S) = E_Loop and then not Comes_From_Source (S) then |
| 6606 |
S := Scope (S); |
| 6607 |
else |
| 6608 |
exit; |
| 6609 |
end if; |
| 6610 |
end loop; |
| 6611 |
|
| 6612 |
return S; |
| 6613 |
end Current_Scope_No_Loops; |
| 6614 |
|
| 6615 |
------------------------ |
| 6616 |
-- Current_Subprogram -- |
| 6617 |
------------------------ |
| 6618 |
|
| 6619 |
function Current_Subprogram return Entity_Id is |
| 6620 |
Scop : constant Entity_Id := Current_Scope; |
| 6621 |
begin |
| 6622 |
if Is_Subprogram_Or_Generic_Subprogram (Scop) then |
| 6623 |
return Scop; |
| 6624 |
else |
| 6625 |
return Enclosing_Subprogram (Scop); |
| 6626 |
end if; |
| 6627 |
end Current_Subprogram; |
| 6628 |
|
| 6629 |
------------------------------ |
| 6630 |
-- CW_Or_Needs_Finalization -- |
| 6631 |
------------------------------ |
| 6632 |
|
| 6633 |
function CW_Or_Needs_Finalization (Typ : Entity_Id) return Boolean is |
| 6634 |
begin |
| 6635 |
return Is_Class_Wide_Type (Typ) or else Needs_Finalization (Typ); |
| 6636 |
end CW_Or_Needs_Finalization; |
| 6637 |
|
| 6638 |
--------------------- |
| 6639 |
-- Defining_Entity -- |
| 6640 |
--------------------- |
| 6641 |
|
| 6642 |
function Defining_Entity (N : Node_Id) return Entity_Id is |
| 6643 |
Ent : constant Entity_Id := Defining_Entity_Or_Empty (N); |
| 6644 |
|
| 6645 |
begin |
| 6646 |
if Present (Ent) then |
| 6647 |
return Ent; |
| 6648 |
|
| 6649 |
else |
| 6650 |
raise Program_Error; |
| 6651 |
end if; |
| 6652 |
end Defining_Entity; |
| 6653 |
|
| 6654 |
------------------------------ |
| 6655 |
-- Defining_Entity_Or_Empty -- |
| 6656 |
------------------------------ |
| 6657 |
|
| 6658 |
function Defining_Entity_Or_Empty (N : Node_Id) return Entity_Id is |
| 6659 |
begin |
| 6660 |
case Nkind (N) is |
| 6661 |
when N_Abstract_Subprogram_Declaration |
| 6662 |
| N_Expression_Function |
| 6663 |
| N_Formal_Subprogram_Declaration |
| 6664 |
| N_Generic_Package_Declaration |
| 6665 |
| N_Generic_Subprogram_Declaration |
| 6666 |
| N_Package_Declaration |
| 6667 |
| N_Subprogram_Body |
| 6668 |
| N_Subprogram_Body_Stub |
| 6669 |
| N_Subprogram_Declaration |
| 6670 |
| N_Subprogram_Renaming_Declaration |
| 6671 |
=> |
| 6672 |
return Defining_Entity (Specification (N)); |
| 6673 |
|
| 6674 |
when N_Component_Declaration |
| 6675 |
| N_Defining_Program_Unit_Name |
| 6676 |
| N_Discriminant_Specification |
| 6677 |
| N_Entry_Body |
| 6678 |
| N_Entry_Declaration |
| 6679 |
| N_Entry_Index_Specification |
| 6680 |
| N_Exception_Declaration |
| 6681 |
| N_Exception_Renaming_Declaration |
| 6682 |
| N_Formal_Object_Declaration |
| 6683 |
| N_Formal_Package_Declaration |
| 6684 |
| N_Formal_Type_Declaration |
| 6685 |
| N_Full_Type_Declaration |
| 6686 |
| N_Implicit_Label_Declaration |
| 6687 |
| N_Incomplete_Type_Declaration |
| 6688 |
| N_Iterator_Specification |
| 6689 |
| N_Loop_Parameter_Specification |
| 6690 |
| N_Number_Declaration |
| 6691 |
| N_Object_Declaration |
| 6692 |
| N_Object_Renaming_Declaration |
| 6693 |
| N_Package_Body_Stub |
| 6694 |
| N_Parameter_Specification |
| 6695 |
| N_Private_Extension_Declaration |
| 6696 |
| N_Private_Type_Declaration |
| 6697 |
| N_Protected_Body |
| 6698 |
| N_Protected_Body_Stub |
| 6699 |
| N_Protected_Type_Declaration |
| 6700 |
| N_Single_Protected_Declaration |
| 6701 |
| N_Single_Task_Declaration |
| 6702 |
| N_Subtype_Declaration |
| 6703 |
| N_Task_Body |
| 6704 |
| N_Task_Body_Stub |
| 6705 |
| N_Task_Type_Declaration |
| 6706 |
=> |
| 6707 |
return Defining_Identifier (N); |
| 6708 |
|
| 6709 |
when N_Compilation_Unit => |
| 6710 |
return Defining_Entity (Unit (N)); |
| 6711 |
|
| 6712 |
when N_Subunit => |
| 6713 |
return Defining_Entity (Proper_Body (N)); |
| 6714 |
|
| 6715 |
when N_Function_Instantiation |
| 6716 |
| N_Function_Specification |
| 6717 |
| N_Generic_Function_Renaming_Declaration |
| 6718 |
| N_Generic_Package_Renaming_Declaration |
| 6719 |
| N_Generic_Procedure_Renaming_Declaration |
| 6720 |
| N_Package_Body |
| 6721 |
| N_Package_Instantiation |
| 6722 |
| N_Package_Renaming_Declaration |
| 6723 |
| N_Package_Specification |
| 6724 |
| N_Procedure_Instantiation |
| 6725 |
| N_Procedure_Specification |
| 6726 |
=> |
| 6727 |
declare |
| 6728 |
Nam : constant Node_Id := Defining_Unit_Name (N); |
| 6729 |
Err : Entity_Id := Empty; |
| 6730 |
|
| 6731 |
begin |
| 6732 |
if Nkind (Nam) in N_Entity then |
| 6733 |
return Nam; |
| 6734 |
|
| 6735 |
-- For Error, make up a name and attach to declaration so we |
| 6736 |
-- can continue semantic analysis. |
| 6737 |
|
| 6738 |
elsif Nam = Error then |
| 6739 |
Err := Make_Temporary (Sloc (N), 'T'); |
| 6740 |
Set_Defining_Unit_Name (N, Err); |
| 6741 |
|
| 6742 |
return Err; |
| 6743 |
|
| 6744 |
-- If not an entity, get defining identifier |
| 6745 |
|
| 6746 |
else |
| 6747 |
return Defining_Identifier (Nam); |
| 6748 |
end if; |
| 6749 |
end; |
| 6750 |
|
| 6751 |
when N_Block_Statement |
| 6752 |
| N_Loop_Statement |
| 6753 |
=> |
| 6754 |
return Entity (Identifier (N)); |
| 6755 |
|
| 6756 |
when others => |
| 6757 |
return Empty; |
| 6758 |
end case; |
| 6759 |
end Defining_Entity_Or_Empty; |
| 6760 |
|
| 6761 |
-------------------------- |
| 6762 |
-- Denotes_Discriminant -- |
| 6763 |
-------------------------- |
| 6764 |
|
| 6765 |
function Denotes_Discriminant |
| 6766 |
(N : Node_Id; |
| 6767 |
Check_Concurrent : Boolean := False) return Boolean |
| 6768 |
is |
| 6769 |
E : Entity_Id; |
| 6770 |
|
| 6771 |
begin |
| 6772 |
if not Is_Entity_Name (N) or else No (Entity (N)) then |
| 6773 |
return False; |
| 6774 |
else |
| 6775 |
E := Entity (N); |
| 6776 |
end if; |
| 6777 |
|
| 6778 |
-- If we are checking in a default expression, the discriminant has been |
| 6779 |
-- rewritten as the corresponding discriminal. |
| 6780 |
|
| 6781 |
-- If we are checking for a protected type, the discriminant may have |
| 6782 |
-- been rewritten as the corresponding discriminal of the original type |
| 6783 |
-- or of the corresponding concurrent record, depending on whether we |
| 6784 |
-- are in the spec or body of the protected type. |
| 6785 |
|
| 6786 |
return Ekind (E) = E_Discriminant |
| 6787 |
or else (In_Default_Expr |
| 6788 |
and then Ekind (E) = E_In_Parameter |
| 6789 |
and then Present (Discriminal_Link (E))) |
| 6790 |
or else |
| 6791 |
(Check_Concurrent |
| 6792 |
and then Ekind (E) = E_In_Parameter |
| 6793 |
and then Present (Discriminal_Link (E)) |
| 6794 |
and then |
| 6795 |
(Is_Concurrent_Type (Scope (Discriminal_Link (E))) |
| 6796 |
or else |
| 6797 |
Is_Concurrent_Record_Type (Scope (Discriminal_Link (E))))); |
| 6798 |
end Denotes_Discriminant; |
| 6799 |
|
| 6800 |
------------------------- |
| 6801 |
-- Denotes_Same_Object -- |
| 6802 |
------------------------- |
| 6803 |
|
| 6804 |
function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is |
| 6805 |
function Is_Object_Renaming (N : Node_Id) return Boolean; |
| 6806 |
-- Return true if N names an object renaming entity |
| 6807 |
|
| 6808 |
function Is_Valid_Renaming (N : Node_Id) return Boolean; |
| 6809 |
-- For renamings, return False if the prefix of any dereference within |
| 6810 |
-- the renamed object_name is a variable, or any expression within the |
| 6811 |
-- renamed object_name contains references to variables or calls on |
| 6812 |
-- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3)) |
| 6813 |
|
| 6814 |
------------------------ |
| 6815 |
-- Is_Object_Renaming -- |
| 6816 |
------------------------ |
| 6817 |
|
| 6818 |
function Is_Object_Renaming (N : Node_Id) return Boolean is |
| 6819 |
begin |
| 6820 |
return Is_Entity_Name (N) |
| 6821 |
and then Ekind (Entity (N)) in E_Variable | E_Constant |
| 6822 |
and then Present (Renamed_Object (Entity (N))); |
| 6823 |
end Is_Object_Renaming; |
| 6824 |
|
| 6825 |
----------------------- |
| 6826 |
-- Is_Valid_Renaming -- |
| 6827 |
----------------------- |
| 6828 |
|
| 6829 |
function Is_Valid_Renaming (N : Node_Id) return Boolean is |
| 6830 |
begin |
| 6831 |
if Is_Object_Renaming (N) |
| 6832 |
and then not Is_Valid_Renaming (Renamed_Object (Entity (N))) |
| 6833 |
then |
| 6834 |
return False; |
| 6835 |
end if; |
| 6836 |
|
| 6837 |
-- Check if any expression within the renamed object_name contains no |
| 6838 |
-- references to variables nor calls on nonstatic functions. |
| 6839 |
|
| 6840 |
if Nkind (N) = N_Indexed_Component then |
| 6841 |
declare |
| 6842 |
Indx : Node_Id; |
| 6843 |
|
| 6844 |
begin |
| 6845 |
Indx := First (Expressions (N)); |
| 6846 |
while Present (Indx) loop |
| 6847 |
if not Is_OK_Static_Expression (Indx) then |
| 6848 |
return False; |
| 6849 |
end if; |
| 6850 |
|
| 6851 |
Next (Indx); |
| 6852 |
end loop; |
| 6853 |
end; |
| 6854 |
|
| 6855 |
elsif Nkind (N) = N_Slice then |
| 6856 |
declare |
| 6857 |
Rng : constant Node_Id := Discrete_Range (N); |
| 6858 |
begin |
| 6859 |
-- Bounds specified as a range |
| 6860 |
|
| 6861 |
if Nkind (Rng) = N_Range then |
| 6862 |
if not Is_OK_Static_Range (Rng) then |
| 6863 |
return False; |
| 6864 |
end if; |
| 6865 |
|
| 6866 |
-- Bounds specified as a constrained subtype indication |
| 6867 |
|
| 6868 |
elsif Nkind (Rng) = N_Subtype_Indication then |
| 6869 |
if not Is_OK_Static_Range |
| 6870 |
(Range_Expression (Constraint (Rng))) |
| 6871 |
then |
| 6872 |
return False; |
| 6873 |
end if; |
| 6874 |
|
| 6875 |
-- Bounds specified as a subtype name |
| 6876 |
|
| 6877 |
elsif not Is_OK_Static_Expression (Rng) then |
| 6878 |
return False; |
| 6879 |
end if; |
| 6880 |
end; |
| 6881 |
end if; |
| 6882 |
|
| 6883 |
if Has_Prefix (N) then |
| 6884 |
declare |
| 6885 |
P : constant Node_Id := Prefix (N); |
| 6886 |
|
| 6887 |
begin |
| 6888 |
if Nkind (N) = N_Explicit_Dereference |
| 6889 |
and then Is_Variable (P) |
| 6890 |
then |
| 6891 |
return False; |
| 6892 |
|
| 6893 |
elsif Is_Entity_Name (P) |
| 6894 |
and then Ekind (Entity (P)) = E_Function |
| 6895 |
then |
| 6896 |
return False; |
| 6897 |
|
| 6898 |
elsif Nkind (P) = N_Function_Call then |
| 6899 |
return False; |
| 6900 |
end if; |
| 6901 |
|
| 6902 |
-- Recursion to continue traversing the prefix of the |
| 6903 |
-- renaming expression |
| 6904 |
|
| 6905 |
return Is_Valid_Renaming (P); |
| 6906 |
end; |
| 6907 |
end if; |
| 6908 |
|
| 6909 |
return True; |
| 6910 |
end Is_Valid_Renaming; |
| 6911 |
|
| 6912 |
-- Start of processing for Denotes_Same_Object |
| 6913 |
|
| 6914 |
begin |
| 6915 |
-- Both names statically denote the same stand-alone object or |
| 6916 |
-- parameter (RM 6.4.1(6.6/3)). |
| 6917 |
|
| 6918 |
if Is_Entity_Name (A1) |
| 6919 |
and then Is_Entity_Name (A2) |
| 6920 |
and then Entity (A1) = Entity (A2) |
| 6921 |
then |
| 6922 |
return True; |
| 6923 |
|
| 6924 |
-- Both names are selected_components, their prefixes are known to |
| 6925 |
-- denote the same object, and their selector_names denote the same |
| 6926 |
-- component (RM 6.4.1(6.7/3)). |
| 6927 |
|
| 6928 |
elsif Nkind (A1) = N_Selected_Component |
| 6929 |
and then Nkind (A2) = N_Selected_Component |
| 6930 |
then |
| 6931 |
return Denotes_Same_Object (Prefix (A1), Prefix (A2)) |
| 6932 |
and then |
| 6933 |
Entity (Selector_Name (A1)) = Entity (Selector_Name (A2)); |
| 6934 |
|
| 6935 |
-- Both names are dereferences and the dereferenced names are known to |
| 6936 |
-- denote the same object (RM 6.4.1(6.8/3)). |
| 6937 |
|
| 6938 |
elsif Nkind (A1) = N_Explicit_Dereference |
| 6939 |
and then Nkind (A2) = N_Explicit_Dereference |
| 6940 |
then |
| 6941 |
return Denotes_Same_Object (Prefix (A1), Prefix (A2)); |
| 6942 |
|
| 6943 |
-- Both names are indexed_components, their prefixes are known to denote |
| 6944 |
-- the same object, and each of the pairs of corresponding index values |
| 6945 |
-- are either both static expressions with the same static value or both |
| 6946 |
-- names that are known to denote the same object (RM 6.4.1(6.9/3)). |
| 6947 |
|
| 6948 |
elsif Nkind (A1) = N_Indexed_Component |
| 6949 |
and then Nkind (A2) = N_Indexed_Component |
| 6950 |
then |
| 6951 |
if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then |
| 6952 |
return False; |
| 6953 |
else |
| 6954 |
declare |
| 6955 |
Indx1 : Node_Id; |
| 6956 |
Indx2 : Node_Id; |
| 6957 |
|
| 6958 |
begin |
| 6959 |
Indx1 := First (Expressions (A1)); |
| 6960 |
Indx2 := First (Expressions (A2)); |
| 6961 |
while Present (Indx1) loop |
| 6962 |
|
| 6963 |
-- Indexes must denote the same static value or same object |
| 6964 |
|
| 6965 |
if Is_OK_Static_Expression (Indx1) then |
| 6966 |
if not Is_OK_Static_Expression (Indx2) then |
| 6967 |
return False; |
| 6968 |
|
| 6969 |
elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then |
| 6970 |
return False; |
| 6971 |
end if; |
| 6972 |
|
| 6973 |
elsif not Denotes_Same_Object (Indx1, Indx2) then |
| 6974 |
return False; |
| 6975 |
end if; |
| 6976 |
|
| 6977 |
Next (Indx1); |
| 6978 |
Next (Indx2); |
| 6979 |
end loop; |
| 6980 |
|
| 6981 |
return True; |
| 6982 |
end; |
| 6983 |
end if; |
| 6984 |
|
| 6985 |
-- Both names are slices, their prefixes are known to denote the same |
| 6986 |
-- object, and the two slices have statically matching index constraints |
| 6987 |
-- (RM 6.4.1(6.10/3)). |
| 6988 |
|
| 6989 |
elsif Nkind (A1) = N_Slice |
| 6990 |
and then Nkind (A2) = N_Slice |
| 6991 |
then |
| 6992 |
if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then |
| 6993 |
return False; |
| 6994 |
else |
| 6995 |
declare |
| 6996 |
Lo1, Lo2, Hi1, Hi2 : Node_Id; |
| 6997 |
|
| 6998 |
begin |
| 6999 |
Get_Index_Bounds (Discrete_Range (A1), Lo1, Hi1); |
| 7000 |
Get_Index_Bounds (Discrete_Range (A2), Lo2, Hi2); |
| 7001 |
|
| 7002 |
-- Check whether bounds are statically identical. There is no |
| 7003 |
-- attempt to detect partial overlap of slices. |
| 7004 |
|
| 7005 |
return Is_OK_Static_Expression (Lo1) |
| 7006 |
and then Is_OK_Static_Expression (Lo2) |
| 7007 |
and then Is_OK_Static_Expression (Hi1) |
| 7008 |
and then Is_OK_Static_Expression (Hi2) |
| 7009 |
and then Expr_Value (Lo1) = Expr_Value (Lo2) |
| 7010 |
and then Expr_Value (Hi1) = Expr_Value (Hi2); |
| 7011 |
end; |
| 7012 |
end if; |
| 7013 |
|
| 7014 |
-- One of the two names statically denotes a renaming declaration whose |
| 7015 |
-- renamed object_name is known to denote the same object as the other; |
| 7016 |
-- the prefix of any dereference within the renamed object_name is not a |
| 7017 |
-- variable, and any expression within the renamed object_name contains |
| 7018 |
-- no references to variables nor calls on nonstatic functions (RM |
| 7019 |
-- 6.4.1(6.11/3)). |
| 7020 |
|
| 7021 |
elsif Is_Object_Renaming (A1) |
| 7022 |
and then Is_Valid_Renaming (A1) |
| 7023 |
then |
| 7024 |
return Denotes_Same_Object (Renamed_Object (Entity (A1)), A2); |
| 7025 |
|
| 7026 |
elsif Is_Object_Renaming (A2) |
| 7027 |
and then Is_Valid_Renaming (A2) |
| 7028 |
then |
| 7029 |
return Denotes_Same_Object (A1, Renamed_Object (Entity (A2))); |
| 7030 |
|
| 7031 |
else |
| 7032 |
return False; |
| 7033 |
end if; |
| 7034 |
end Denotes_Same_Object; |
| 7035 |
|
| 7036 |
------------------------- |
| 7037 |
-- Denotes_Same_Prefix -- |
| 7038 |
------------------------- |
| 7039 |
|
| 7040 |
function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is |
| 7041 |
begin |
| 7042 |
if Is_Entity_Name (A1) then |
| 7043 |
if Nkind (A2) in N_Selected_Component | N_Indexed_Component |
| 7044 |
and then not Is_Access_Type (Etype (A1)) |
| 7045 |
then |
| 7046 |
return Denotes_Same_Object (A1, Prefix (A2)) |
| 7047 |
or else Denotes_Same_Prefix (A1, Prefix (A2)); |
| 7048 |
else |
| 7049 |
return False; |
| 7050 |
end if; |
| 7051 |
|
| 7052 |
elsif Is_Entity_Name (A2) then |
| 7053 |
return Denotes_Same_Prefix (A1 => A2, A2 => A1); |
| 7054 |
|
| 7055 |
elsif Nkind (A1) in N_Selected_Component | N_Indexed_Component | N_Slice |
| 7056 |
and then |
| 7057 |
Nkind (A2) in N_Selected_Component | N_Indexed_Component | N_Slice |
| 7058 |
then |
| 7059 |
declare |
| 7060 |
Root1, Root2 : Node_Id; |
| 7061 |
Depth1, Depth2 : Nat := 0; |
| 7062 |
|
| 7063 |
begin |
| 7064 |
Root1 := Prefix (A1); |
| 7065 |
while not Is_Entity_Name (Root1) loop |
| 7066 |
if Nkind (Root1) not in |
| 7067 |
N_Selected_Component | N_Indexed_Component |
| 7068 |
then |
| 7069 |
return False; |
| 7070 |
else |
| 7071 |
Root1 := Prefix (Root1); |
| 7072 |
end if; |
| 7073 |
|
| 7074 |
Depth1 := Depth1 + 1; |
| 7075 |
end loop; |
| 7076 |
|
| 7077 |
Root2 := Prefix (A2); |
| 7078 |
while not Is_Entity_Name (Root2) loop |
| 7079 |
if Nkind (Root2) not in |
| 7080 |
N_Selected_Component | N_Indexed_Component |
| 7081 |
then |
| 7082 |
return False; |
| 7083 |
else |
| 7084 |
Root2 := Prefix (Root2); |
| 7085 |
end if; |
| 7086 |
|
| 7087 |
Depth2 := Depth2 + 1; |
| 7088 |
end loop; |
| 7089 |
|
| 7090 |
-- If both have the same depth and they do not denote the same |
| 7091 |
-- object, they are disjoint and no warning is needed. |
| 7092 |
|
| 7093 |
if Depth1 = Depth2 then |
| 7094 |
return False; |
| 7095 |
|
| 7096 |
elsif Depth1 > Depth2 then |
| 7097 |
Root1 := Prefix (A1); |
| 7098 |
for J in 1 .. Depth1 - Depth2 - 1 loop |
| 7099 |
Root1 := Prefix (Root1); |
| 7100 |
end loop; |
| 7101 |
|
| 7102 |
return Denotes_Same_Object (Root1, A2); |
| 7103 |
|
| 7104 |
else |
| 7105 |
Root2 := Prefix (A2); |
| 7106 |
for J in 1 .. Depth2 - Depth1 - 1 loop |
| 7107 |
Root2 := Prefix (Root2); |
| 7108 |
end loop; |
| 7109 |
|
| 7110 |
return Denotes_Same_Object (A1, Root2); |
| 7111 |
end if; |
| 7112 |
end; |
| 7113 |
|
| 7114 |
else |
| 7115 |
return False; |
| 7116 |
end if; |
| 7117 |
end Denotes_Same_Prefix; |
| 7118 |
|
| 7119 |
---------------------- |
| 7120 |
-- Denotes_Variable -- |
| 7121 |
---------------------- |
| 7122 |
|
| 7123 |
function Denotes_Variable (N : Node_Id) return Boolean is |
| 7124 |
begin |
| 7125 |
return Is_Variable (N) and then Paren_Count (N) = 0; |
| 7126 |
end Denotes_Variable; |
| 7127 |
|
| 7128 |
----------------------------- |
| 7129 |
-- Depends_On_Discriminant -- |
| 7130 |
----------------------------- |
| 7131 |
|
| 7132 |
function Depends_On_Discriminant (N : Node_Id) return Boolean is |
| 7133 |
L : Node_Id; |
| 7134 |
H : Node_Id; |
| 7135 |
|
| 7136 |
begin |
| 7137 |
Get_Index_Bounds (N, L, H); |
| 7138 |
return Denotes_Discriminant (L) or else Denotes_Discriminant (H); |
| 7139 |
end Depends_On_Discriminant; |
| 7140 |
|
| 7141 |
------------------------------------- |
| 7142 |
-- Derivation_Too_Early_To_Inherit -- |
| 7143 |
------------------------------------- |
| 7144 |
|
| 7145 |
function Derivation_Too_Early_To_Inherit |
| 7146 |
(Typ : Entity_Id; Streaming_Op : TSS_Name_Type) return Boolean is |
| 7147 |
|
| 7148 |
Btyp : constant Entity_Id := Implementation_Base_Type (Typ); |
| 7149 |
Parent_Type : Entity_Id; |
| 7150 |
|
| 7151 |
Real_Rep : Node_Id; |
| 7152 |
|
| 7153 |
-- Start of processing for Derivation_Too_Early_To_Inherit |
| 7154 |
|
| 7155 |
begin |
| 7156 |
if Is_Derived_Type (Btyp) then |
| 7157 |
Parent_Type := Implementation_Base_Type (Etype (Btyp)); |
| 7158 |
pragma Assert (Parent_Type /= Btyp); |
| 7159 |
|
| 7160 |
if Has_Stream_Attribute_Definition |
| 7161 |
(Parent_Type, Streaming_Op, Real_Rep => Real_Rep) |
| 7162 |
|
| 7163 |
and then In_Same_Extended_Unit (Btyp, Parent_Type) |
| 7164 |
and then Instantiation (Get_Source_File_Index (Sloc (Btyp))) = |
| 7165 |
Instantiation (Get_Source_File_Index (Sloc (Parent_Type))) |
| 7166 |
then |
| 7167 |
return Earlier_In_Extended_Unit (Btyp, Real_Rep); |
| 7168 |
end if; |
| 7169 |
end if; |
| 7170 |
|
| 7171 |
return False; |
| 7172 |
end Derivation_Too_Early_To_Inherit; |
| 7173 |
|
| 7174 |
------------------------- |
| 7175 |
-- Designate_Same_Unit -- |
| 7176 |
------------------------- |
| 7177 |
|
| 7178 |
function Designate_Same_Unit |
| 7179 |
(Name1 : Node_Id; |
| 7180 |
Name2 : Node_Id) return Boolean |
| 7181 |
is |
| 7182 |
K1 : constant Node_Kind := Nkind (Name1); |
| 7183 |
K2 : constant Node_Kind := Nkind (Name2); |
| 7184 |
|
| 7185 |
function Prefix_Node (N : Node_Id) return Node_Id; |
| 7186 |
-- Returns the parent unit name node of a defining program unit name |
| 7187 |
-- or the prefix if N is a selected component or an expanded name. |
| 7188 |
|
| 7189 |
function Select_Node (N : Node_Id) return Node_Id; |
| 7190 |
-- Returns the defining identifier node of a defining program unit |
| 7191 |
-- name or the selector node if N is a selected component or an |
| 7192 |
-- expanded name. |
| 7193 |
|
| 7194 |
----------------- |
| 7195 |
-- Prefix_Node -- |
| 7196 |
----------------- |
| 7197 |
|
| 7198 |
function Prefix_Node (N : Node_Id) return Node_Id is |
| 7199 |
begin |
| 7200 |
if Nkind (N) = N_Defining_Program_Unit_Name then |
| 7201 |
return Name (N); |
| 7202 |
else |
| 7203 |
return Prefix (N); |
| 7204 |
end if; |
| 7205 |
end Prefix_Node; |
| 7206 |
|
| 7207 |
----------------- |
| 7208 |
-- Select_Node -- |
| 7209 |
----------------- |
| 7210 |
|
| 7211 |
function Select_Node (N : Node_Id) return Node_Id is |
| 7212 |
begin |
| 7213 |
if Nkind (N) = N_Defining_Program_Unit_Name then |
| 7214 |
return Defining_Identifier (N); |
| 7215 |
else |
| 7216 |
return Selector_Name (N); |
| 7217 |
end if; |
| 7218 |
end Select_Node; |
| 7219 |
|
| 7220 |
-- Start of processing for Designate_Same_Unit |
| 7221 |
|
| 7222 |
begin |
| 7223 |
if K1 in N_Identifier | N_Defining_Identifier |
| 7224 |
and then |
| 7225 |
K2 in N_Identifier | N_Defining_Identifier |
| 7226 |
then |
| 7227 |
return Chars (Name1) = Chars (Name2); |
| 7228 |
|
| 7229 |
elsif K1 in N_Expanded_Name |
| 7230 |
| N_Selected_Component |
| 7231 |
| N_Defining_Program_Unit_Name |
| 7232 |
and then |
| 7233 |
K2 in N_Expanded_Name |
| 7234 |
| N_Selected_Component |
| 7235 |
| N_Defining_Program_Unit_Name |
| 7236 |
then |
| 7237 |
return |
| 7238 |
Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)) |
| 7239 |
and then |
| 7240 |
Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2)); |
| 7241 |
|
| 7242 |
else |
| 7243 |
return False; |
| 7244 |
end if; |
| 7245 |
end Designate_Same_Unit; |
| 7246 |
|
| 7247 |
------------------------ |
| 7248 |
-- Discriminated_Size -- |
| 7249 |
------------------------ |
| 7250 |
|
| 7251 |
function Discriminated_Size (Comp : Entity_Id) return Boolean is |
| 7252 |
function Non_Static_Bound (Bound : Node_Id) return Boolean; |
| 7253 |
-- Check whether the bound of an index is non-static and does denote |
| 7254 |
-- a discriminant, in which case any object of the type (protected or |
| 7255 |
-- otherwise) will have a non-static size. |
| 7256 |
|
| 7257 |
---------------------- |
| 7258 |
-- Non_Static_Bound -- |
| 7259 |
---------------------- |
| 7260 |
|
| 7261 |
function Non_Static_Bound (Bound : Node_Id) return Boolean is |
| 7262 |
begin |
| 7263 |
if Is_OK_Static_Expression (Bound) then |
| 7264 |
return False; |
| 7265 |
|
| 7266 |
-- If the bound is given by a discriminant it is non-static |
| 7267 |
-- (A static constraint replaces the reference with the value). |
| 7268 |
-- In an protected object the discriminant has been replaced by |
| 7269 |
-- the corresponding discriminal within the protected operation. |
| 7270 |
|
| 7271 |
elsif Is_Entity_Name (Bound) |
| 7272 |
and then |
| 7273 |
(Ekind (Entity (Bound)) = E_Discriminant |
| 7274 |
or else Present (Discriminal_Link (Entity (Bound)))) |
| 7275 |
then |
| 7276 |
return False; |
| 7277 |
|
| 7278 |
else |
| 7279 |
return True; |
| 7280 |
end if; |
| 7281 |
end Non_Static_Bound; |
| 7282 |
|
| 7283 |
-- Local variables |
| 7284 |
|
| 7285 |
Typ : constant Entity_Id := Etype (Comp); |
| 7286 |
Index : Node_Id; |
| 7287 |
|
| 7288 |
-- Start of processing for Discriminated_Size |
| 7289 |
|
| 7290 |
begin |
| 7291 |
if not Is_Array_Type (Typ) then |
| 7292 |
return False; |
| 7293 |
end if; |
| 7294 |
|
| 7295 |
if Ekind (Typ) = E_Array_Subtype then |
| 7296 |
Index := First_Index (Typ); |
| 7297 |
while Present (Index) loop |
| 7298 |
if Non_Static_Bound (Low_Bound (Index)) |
| 7299 |
or else Non_Static_Bound (High_Bound (Index)) |
| 7300 |
then |
| 7301 |
return False; |
| 7302 |
end if; |
| 7303 |
|
| 7304 |
Next_Index (Index); |
| 7305 |
end loop; |
| 7306 |
|
| 7307 |
return True; |
| 7308 |
end if; |
| 7309 |
|
| 7310 |
return False; |
| 7311 |
end Discriminated_Size; |
| 7312 |
|
| 7313 |
----------------------------- |
| 7314 |
-- Effective_Reads_Enabled -- |
| 7315 |
----------------------------- |
| 7316 |
|
| 7317 |
function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is |
| 7318 |
begin |
| 7319 |
return Has_Enabled_Property (Id, Name_Effective_Reads); |
| 7320 |
end Effective_Reads_Enabled; |
| 7321 |
|
| 7322 |
------------------------------ |
| 7323 |
-- Effective_Writes_Enabled -- |
| 7324 |
------------------------------ |
| 7325 |
|
| 7326 |
function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is |
| 7327 |
begin |
| 7328 |
return Has_Enabled_Property (Id, Name_Effective_Writes); |
| 7329 |
end Effective_Writes_Enabled; |
| 7330 |
|
| 7331 |
------------------------------ |
| 7332 |
-- Enclosing_Comp_Unit_Node -- |
| 7333 |
------------------------------ |
| 7334 |
|
| 7335 |
function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is |
| 7336 |
Current_Node : Node_Id; |
| 7337 |
|
| 7338 |
begin |
| 7339 |
Current_Node := N; |
| 7340 |
while Present (Current_Node) |
| 7341 |
and then Nkind (Current_Node) /= N_Compilation_Unit |
| 7342 |
loop |
| 7343 |
Current_Node := Parent (Current_Node); |
| 7344 |
end loop; |
| 7345 |
|
| 7346 |
return Current_Node; |
| 7347 |
end Enclosing_Comp_Unit_Node; |
| 7348 |
|
| 7349 |
-------------------------- |
| 7350 |
-- Enclosing_CPP_Parent -- |
| 7351 |
-------------------------- |
| 7352 |
|
| 7353 |
function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is |
| 7354 |
Parent_Typ : Entity_Id := Typ; |
| 7355 |
|
| 7356 |
begin |
| 7357 |
while not Is_CPP_Class (Parent_Typ) |
| 7358 |
and then Etype (Parent_Typ) /= Parent_Typ |
| 7359 |
loop |
| 7360 |
Parent_Typ := Etype (Parent_Typ); |
| 7361 |
|
| 7362 |
if Is_Private_Type (Parent_Typ) then |
| 7363 |
Parent_Typ := Full_View (Base_Type (Parent_Typ)); |
| 7364 |
end if; |
| 7365 |
end loop; |
| 7366 |
|
| 7367 |
pragma Assert (Is_CPP_Class (Parent_Typ)); |
| 7368 |
return Parent_Typ; |
| 7369 |
end Enclosing_CPP_Parent; |
| 7370 |
|
| 7371 |
--------------------------- |
| 7372 |
-- Enclosing_Declaration -- |
| 7373 |
--------------------------- |
| 7374 |
|
| 7375 |
function Enclosing_Declaration (N : Node_Id) return Node_Id is |
| 7376 |
Decl : Node_Id := N; |
| 7377 |
|
| 7378 |
begin |
| 7379 |
while Present (Decl) |
| 7380 |
and then not (Nkind (Decl) in N_Declaration |
| 7381 |
or else |
| 7382 |
Nkind (Decl) in N_Later_Decl_Item |
| 7383 |
or else |
| 7384 |
Nkind (Decl) in N_Renaming_Declaration |
| 7385 |
or else |
| 7386 |
Nkind (Decl) = N_Number_Declaration) |
| 7387 |
loop |
| 7388 |
Decl := Parent (Decl); |
| 7389 |
end loop; |
| 7390 |
|
| 7391 |
-- cope with oddness in definition of N_Declaration |
| 7392 |
if Nkind (Decl) in N_Subprogram_Specification then |
| 7393 |
Decl := Parent (Decl); |
| 7394 |
end if; |
| 7395 |
|
| 7396 |
return Decl; |
| 7397 |
end Enclosing_Declaration; |
| 7398 |
|
| 7399 |
---------------------------------------- |
| 7400 |
-- Enclosing_Declaration_Or_Statement -- |
| 7401 |
---------------------------------------- |
| 7402 |
|
| 7403 |
function Enclosing_Declaration_Or_Statement |
| 7404 |
(N : Node_Id) return Node_Id |
| 7405 |
is |
| 7406 |
Par : Node_Id; |
| 7407 |
|
| 7408 |
begin |
| 7409 |
Par := N; |
| 7410 |
while Present (Par) loop |
| 7411 |
if Is_Declaration (Par) or else Is_Statement (Par) then |
| 7412 |
return Par; |
| 7413 |
|
| 7414 |
-- Prevent the search from going too far |
| 7415 |
|
| 7416 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 7417 |
exit; |
| 7418 |
end if; |
| 7419 |
|
| 7420 |
Par := Parent (Par); |
| 7421 |
end loop; |
| 7422 |
|
| 7423 |
return N; |
| 7424 |
end Enclosing_Declaration_Or_Statement; |
| 7425 |
|
| 7426 |
---------------------------- |
| 7427 |
-- Enclosing_Generic_Body -- |
| 7428 |
---------------------------- |
| 7429 |
|
| 7430 |
function Enclosing_Generic_Body (N : Node_Id) return Node_Id is |
| 7431 |
Par : Node_Id; |
| 7432 |
Spec_Id : Entity_Id; |
| 7433 |
|
| 7434 |
begin |
| 7435 |
Par := Parent (N); |
| 7436 |
while Present (Par) loop |
| 7437 |
if Nkind (Par) in N_Package_Body | N_Subprogram_Body then |
| 7438 |
Spec_Id := Corresponding_Spec (Par); |
| 7439 |
|
| 7440 |
if Present (Spec_Id) |
| 7441 |
and then Nkind (Unit_Declaration_Node (Spec_Id)) in |
| 7442 |
N_Generic_Declaration |
| 7443 |
then |
| 7444 |
return Par; |
| 7445 |
end if; |
| 7446 |
end if; |
| 7447 |
|
| 7448 |
Par := Parent (Par); |
| 7449 |
end loop; |
| 7450 |
|
| 7451 |
return Empty; |
| 7452 |
end Enclosing_Generic_Body; |
| 7453 |
|
| 7454 |
---------------------------- |
| 7455 |
-- Enclosing_Generic_Unit -- |
| 7456 |
---------------------------- |
| 7457 |
|
| 7458 |
function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is |
| 7459 |
Par : Node_Id; |
| 7460 |
Spec_Decl : Node_Id; |
| 7461 |
Spec_Id : Entity_Id; |
| 7462 |
|
| 7463 |
begin |
| 7464 |
Par := Parent (N); |
| 7465 |
while Present (Par) loop |
| 7466 |
if Nkind (Par) in N_Generic_Declaration then |
| 7467 |
return Par; |
| 7468 |
|
| 7469 |
elsif Nkind (Par) in N_Package_Body | N_Subprogram_Body then |
| 7470 |
Spec_Id := Corresponding_Spec (Par); |
| 7471 |
|
| 7472 |
if Present (Spec_Id) then |
| 7473 |
Spec_Decl := Unit_Declaration_Node (Spec_Id); |
| 7474 |
|
| 7475 |
if Nkind (Spec_Decl) in N_Generic_Declaration then |
| 7476 |
return Spec_Decl; |
| 7477 |
end if; |
| 7478 |
end if; |
| 7479 |
end if; |
| 7480 |
|
| 7481 |
Par := Parent (Par); |
| 7482 |
end loop; |
| 7483 |
|
| 7484 |
return Empty; |
| 7485 |
end Enclosing_Generic_Unit; |
| 7486 |
|
| 7487 |
------------------- |
| 7488 |
-- Enclosing_HSS -- |
| 7489 |
------------------- |
| 7490 |
|
| 7491 |
function Enclosing_HSS (Stmt : Node_Id) return Node_Id is |
| 7492 |
Par : Node_Id; |
| 7493 |
begin |
| 7494 |
pragma Assert (Is_Statement (Stmt)); |
| 7495 |
|
| 7496 |
Par := Parent (Stmt); |
| 7497 |
while Present (Par) loop |
| 7498 |
|
| 7499 |
if Nkind (Par) = N_Handled_Sequence_Of_Statements then |
| 7500 |
return Par; |
| 7501 |
|
| 7502 |
-- Prevent the search from going too far |
| 7503 |
|
| 7504 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 7505 |
return Empty; |
| 7506 |
|
| 7507 |
end if; |
| 7508 |
|
| 7509 |
Par := Parent (Par); |
| 7510 |
end loop; |
| 7511 |
|
| 7512 |
return Par; |
| 7513 |
end Enclosing_HSS; |
| 7514 |
|
| 7515 |
------------------------------- |
| 7516 |
-- Enclosing_Lib_Unit_Entity -- |
| 7517 |
------------------------------- |
| 7518 |
|
| 7519 |
function Enclosing_Lib_Unit_Entity |
| 7520 |
(E : Entity_Id := Current_Scope) return Entity_Id |
| 7521 |
is |
| 7522 |
Unit_Entity : Entity_Id; |
| 7523 |
|
| 7524 |
begin |
| 7525 |
-- Look for enclosing library unit entity by following scope links. |
| 7526 |
-- Equivalent to, but faster than indexing through the scope stack. |
| 7527 |
|
| 7528 |
Unit_Entity := E; |
| 7529 |
while (Present (Scope (Unit_Entity)) |
| 7530 |
and then Scope (Unit_Entity) /= Standard_Standard) |
| 7531 |
and not Is_Child_Unit (Unit_Entity) |
| 7532 |
loop |
| 7533 |
Unit_Entity := Scope (Unit_Entity); |
| 7534 |
end loop; |
| 7535 |
|
| 7536 |
return Unit_Entity; |
| 7537 |
end Enclosing_Lib_Unit_Entity; |
| 7538 |
|
| 7539 |
----------------------------- |
| 7540 |
-- Enclosing_Lib_Unit_Node -- |
| 7541 |
----------------------------- |
| 7542 |
|
| 7543 |
function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is |
| 7544 |
Encl_Unit : Node_Id; |
| 7545 |
|
| 7546 |
begin |
| 7547 |
Encl_Unit := Enclosing_Comp_Unit_Node (N); |
| 7548 |
while Present (Encl_Unit) |
| 7549 |
and then Nkind (Unit (Encl_Unit)) = N_Subunit |
| 7550 |
loop |
| 7551 |
Encl_Unit := Subunit_Parent (Encl_Unit); |
| 7552 |
end loop; |
| 7553 |
|
| 7554 |
pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit); |
| 7555 |
return Encl_Unit; |
| 7556 |
end Enclosing_Lib_Unit_Node; |
| 7557 |
|
| 7558 |
----------------------- |
| 7559 |
-- Enclosing_Package -- |
| 7560 |
----------------------- |
| 7561 |
|
| 7562 |
function Enclosing_Package (N : Node_Or_Entity_Id) return Entity_Id is |
| 7563 |
Dynamic_Scope : Entity_Id; |
| 7564 |
|
| 7565 |
begin |
| 7566 |
-- Obtain the enclosing scope when N is a Node_Id - taking care to |
| 7567 |
-- handle the case when the enclosing scope is already a package. |
| 7568 |
|
| 7569 |
if Nkind (N) not in N_Entity then |
| 7570 |
declare |
| 7571 |
Encl_Scop : constant Entity_Id := Find_Enclosing_Scope (N); |
| 7572 |
begin |
| 7573 |
if No (Encl_Scop) then |
| 7574 |
return Empty; |
| 7575 |
elsif Ekind (Encl_Scop) in |
| 7576 |
E_Generic_Package | E_Package | E_Package_Body |
| 7577 |
then |
| 7578 |
return Encl_Scop; |
| 7579 |
end if; |
| 7580 |
|
| 7581 |
return Enclosing_Package (Encl_Scop); |
| 7582 |
end; |
| 7583 |
end if; |
| 7584 |
|
| 7585 |
-- When N is already an Entity_Id proceed |
| 7586 |
|
| 7587 |
Dynamic_Scope := Enclosing_Dynamic_Scope (N); |
| 7588 |
if Dynamic_Scope = Standard_Standard then |
| 7589 |
return Standard_Standard; |
| 7590 |
|
| 7591 |
elsif Dynamic_Scope = Empty then |
| 7592 |
return Empty; |
| 7593 |
|
| 7594 |
elsif Ekind (Dynamic_Scope) in |
| 7595 |
E_Generic_Package | E_Package | E_Package_Body |
| 7596 |
then |
| 7597 |
return Dynamic_Scope; |
| 7598 |
|
| 7599 |
else |
| 7600 |
return Enclosing_Package (Dynamic_Scope); |
| 7601 |
end if; |
| 7602 |
end Enclosing_Package; |
| 7603 |
|
| 7604 |
------------------------------------- |
| 7605 |
-- Enclosing_Package_Or_Subprogram -- |
| 7606 |
------------------------------------- |
| 7607 |
|
| 7608 |
function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is |
| 7609 |
S : Entity_Id; |
| 7610 |
|
| 7611 |
begin |
| 7612 |
S := Scope (E); |
| 7613 |
while Present (S) loop |
| 7614 |
if Is_Package_Or_Generic_Package (S) |
| 7615 |
or else Is_Subprogram_Or_Generic_Subprogram (S) |
| 7616 |
then |
| 7617 |
return S; |
| 7618 |
|
| 7619 |
else |
| 7620 |
S := Scope (S); |
| 7621 |
end if; |
| 7622 |
end loop; |
| 7623 |
|
| 7624 |
return Empty; |
| 7625 |
end Enclosing_Package_Or_Subprogram; |
| 7626 |
|
| 7627 |
-------------------------- |
| 7628 |
-- Enclosing_Subprogram -- |
| 7629 |
-------------------------- |
| 7630 |
|
| 7631 |
function Enclosing_Subprogram (N : Node_Or_Entity_Id) return Entity_Id is |
| 7632 |
Dyn_Scop : Entity_Id; |
| 7633 |
Encl_Scop : Entity_Id; |
| 7634 |
|
| 7635 |
begin |
| 7636 |
-- Obtain the enclosing scope when N is a Node_Id - taking care to |
| 7637 |
-- handle the case when the enclosing scope is already a subprogram. |
| 7638 |
|
| 7639 |
if Nkind (N) not in N_Entity then |
| 7640 |
Encl_Scop := Find_Enclosing_Scope (N); |
| 7641 |
|
| 7642 |
if No (Encl_Scop) then |
| 7643 |
return Empty; |
| 7644 |
elsif Ekind (Encl_Scop) in Subprogram_Kind then |
| 7645 |
return Encl_Scop; |
| 7646 |
end if; |
| 7647 |
|
| 7648 |
return Enclosing_Subprogram (Encl_Scop); |
| 7649 |
end if; |
| 7650 |
|
| 7651 |
-- When N is already an Entity_Id proceed |
| 7652 |
|
| 7653 |
Dyn_Scop := Enclosing_Dynamic_Scope (N); |
| 7654 |
if Dyn_Scop = Standard_Standard then |
| 7655 |
return Empty; |
| 7656 |
|
| 7657 |
elsif Dyn_Scop = Empty then |
| 7658 |
return Empty; |
| 7659 |
|
| 7660 |
elsif Ekind (Dyn_Scop) = E_Subprogram_Body then |
| 7661 |
return Corresponding_Spec (Parent (Parent (Dyn_Scop))); |
| 7662 |
|
| 7663 |
elsif Ekind (Dyn_Scop) in E_Block | E_Loop | E_Return_Statement then |
| 7664 |
return Enclosing_Subprogram (Dyn_Scop); |
| 7665 |
|
| 7666 |
elsif Ekind (Dyn_Scop) in E_Entry | E_Entry_Family then |
| 7667 |
|
| 7668 |
-- For a task entry or entry family, return the enclosing subprogram |
| 7669 |
-- of the task itself. |
| 7670 |
|
| 7671 |
if Ekind (Scope (Dyn_Scop)) = E_Task_Type then |
| 7672 |
return Enclosing_Subprogram (Dyn_Scop); |
| 7673 |
|
| 7674 |
-- A protected entry or entry family is rewritten as a protected |
| 7675 |
-- procedure which is the desired enclosing subprogram. This is |
| 7676 |
-- relevant when unnesting a procedure local to an entry body. |
| 7677 |
|
| 7678 |
else |
| 7679 |
return Protected_Body_Subprogram (Dyn_Scop); |
| 7680 |
end if; |
| 7681 |
|
| 7682 |
elsif Ekind (Dyn_Scop) = E_Task_Type then |
| 7683 |
return Get_Task_Body_Procedure (Dyn_Scop); |
| 7684 |
|
| 7685 |
-- The scope may appear as a private type or as a private extension |
| 7686 |
-- whose completion is a task or protected type. |
| 7687 |
|
| 7688 |
elsif Ekind (Dyn_Scop) in |
| 7689 |
E_Limited_Private_Type | E_Record_Type_With_Private |
| 7690 |
and then Present (Full_View (Dyn_Scop)) |
| 7691 |
and then Ekind (Full_View (Dyn_Scop)) in E_Task_Type | E_Protected_Type |
| 7692 |
then |
| 7693 |
return Get_Task_Body_Procedure (Full_View (Dyn_Scop)); |
| 7694 |
|
| 7695 |
-- No body is generated if the protected operation is eliminated |
| 7696 |
|
| 7697 |
elsif not Is_Eliminated (Dyn_Scop) |
| 7698 |
and then Present (Protected_Body_Subprogram (Dyn_Scop)) |
| 7699 |
then |
| 7700 |
return Protected_Body_Subprogram (Dyn_Scop); |
| 7701 |
|
| 7702 |
else |
| 7703 |
return Dyn_Scop; |
| 7704 |
end if; |
| 7705 |
end Enclosing_Subprogram; |
| 7706 |
|
| 7707 |
-------------------------- |
| 7708 |
-- End_Keyword_Location -- |
| 7709 |
-------------------------- |
| 7710 |
|
| 7711 |
function End_Keyword_Location (N : Node_Id) return Source_Ptr is |
| 7712 |
function End_Label_Loc (Nod : Node_Id) return Source_Ptr; |
| 7713 |
-- Return the source location of Nod's end label according to the |
| 7714 |
-- following precedence rules: |
| 7715 |
-- |
| 7716 |
-- 1) If the end label exists, return its location |
| 7717 |
-- 2) If Nod exists, return its location |
| 7718 |
-- 3) Return the location of N |
| 7719 |
|
| 7720 |
------------------- |
| 7721 |
-- End_Label_Loc -- |
| 7722 |
------------------- |
| 7723 |
|
| 7724 |
function End_Label_Loc (Nod : Node_Id) return Source_Ptr is |
| 7725 |
Label : Node_Id; |
| 7726 |
|
| 7727 |
begin |
| 7728 |
if Present (Nod) then |
| 7729 |
Label := End_Label (Nod); |
| 7730 |
|
| 7731 |
if Present (Label) then |
| 7732 |
return Sloc (Label); |
| 7733 |
else |
| 7734 |
return Sloc (Nod); |
| 7735 |
end if; |
| 7736 |
|
| 7737 |
else |
| 7738 |
return Sloc (N); |
| 7739 |
end if; |
| 7740 |
end End_Label_Loc; |
| 7741 |
|
| 7742 |
-- Local variables |
| 7743 |
|
| 7744 |
Owner : Node_Id := Empty; |
| 7745 |
|
| 7746 |
-- Start of processing for End_Keyword_Location |
| 7747 |
|
| 7748 |
begin |
| 7749 |
if Nkind (N) in N_Block_Statement |
| 7750 |
| N_Entry_Body |
| 7751 |
| N_Package_Body |
| 7752 |
| N_Subprogram_Body |
| 7753 |
| N_Task_Body |
| 7754 |
then |
| 7755 |
Owner := Handled_Statement_Sequence (N); |
| 7756 |
|
| 7757 |
elsif Nkind (N) = N_Package_Declaration then |
| 7758 |
Owner := Specification (N); |
| 7759 |
|
| 7760 |
elsif Nkind (N) = N_Protected_Body then |
| 7761 |
Owner := N; |
| 7762 |
|
| 7763 |
elsif Nkind (N) in N_Protected_Type_Declaration |
| 7764 |
| N_Single_Protected_Declaration |
| 7765 |
then |
| 7766 |
Owner := Protected_Definition (N); |
| 7767 |
|
| 7768 |
elsif Nkind (N) in N_Single_Task_Declaration | N_Task_Type_Declaration |
| 7769 |
then |
| 7770 |
Owner := Task_Definition (N); |
| 7771 |
|
| 7772 |
-- This routine should not be called with other contexts |
| 7773 |
|
| 7774 |
else |
| 7775 |
pragma Assert (False); |
| 7776 |
null; |
| 7777 |
end if; |
| 7778 |
|
| 7779 |
return End_Label_Loc (Owner); |
| 7780 |
end End_Keyword_Location; |
| 7781 |
|
| 7782 |
------------------------ |
| 7783 |
-- Ensure_Freeze_Node -- |
| 7784 |
------------------------ |
| 7785 |
|
| 7786 |
procedure Ensure_Freeze_Node (E : Entity_Id) is |
| 7787 |
FN : Node_Id; |
| 7788 |
begin |
| 7789 |
if No (Freeze_Node (E)) then |
| 7790 |
FN := Make_Freeze_Entity (Sloc (E)); |
| 7791 |
Set_Has_Delayed_Freeze (E); |
| 7792 |
Set_Freeze_Node (E, FN); |
| 7793 |
Set_Access_Types_To_Process (FN, No_Elist); |
| 7794 |
Set_TSS_Elist (FN, No_Elist); |
| 7795 |
Set_Entity (FN, E); |
| 7796 |
end if; |
| 7797 |
end Ensure_Freeze_Node; |
| 7798 |
|
| 7799 |
---------------- |
| 7800 |
-- Enter_Name -- |
| 7801 |
---------------- |
| 7802 |
|
| 7803 |
procedure Enter_Name (Def_Id : Entity_Id) is |
| 7804 |
C : constant Entity_Id := Current_Entity (Def_Id); |
| 7805 |
E : constant Entity_Id := Current_Entity_In_Scope (Def_Id); |
| 7806 |
S : constant Entity_Id := Current_Scope; |
| 7807 |
|
| 7808 |
begin |
| 7809 |
Generate_Definition (Def_Id); |
| 7810 |
|
| 7811 |
-- Add new name to current scope declarations. Check for duplicate |
| 7812 |
-- declaration, which may or may not be a genuine error. |
| 7813 |
|
| 7814 |
if Present (E) then |
| 7815 |
|
| 7816 |
-- Case of previous entity entered because of a missing declaration |
| 7817 |
-- or else a bad subtype indication. Best is to use the new entity, |
| 7818 |
-- and make the previous one invisible. |
| 7819 |
|
| 7820 |
if Etype (E) = Any_Type then |
| 7821 |
Set_Is_Immediately_Visible (E, False); |
| 7822 |
|
| 7823 |
-- Case of renaming declaration constructed for package instances. |
| 7824 |
-- If there is an explicit declaration with the same identifier, |
| 7825 |
-- the renaming is not immediately visible any longer, but remains |
| 7826 |
-- visible through selected component notation. |
| 7827 |
|
| 7828 |
elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration |
| 7829 |
and then not Comes_From_Source (E) |
| 7830 |
then |
| 7831 |
Set_Is_Immediately_Visible (E, False); |
| 7832 |
|
| 7833 |
-- The new entity may be the package renaming, which has the |
| 7834 |
-- same name as a generic formal which has been seen already. |
| 7835 |
|
| 7836 |
elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration |
| 7837 |
and then not Comes_From_Source (Def_Id) |
| 7838 |
then |
| 7839 |
Set_Is_Immediately_Visible (E, False); |
| 7840 |
|
| 7841 |
-- For a fat pointer corresponding to a remote access to subprogram, |
| 7842 |
-- we use the same identifier as the RAS type, so that the proper |
| 7843 |
-- name appears in the stub. This type is only retrieved through |
| 7844 |
-- the RAS type and never by visibility, and is not added to the |
| 7845 |
-- visibility list (see below). |
| 7846 |
|
| 7847 |
elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration |
| 7848 |
and then Ekind (Def_Id) = E_Record_Type |
| 7849 |
and then Present (Corresponding_Remote_Type (Def_Id)) |
| 7850 |
then |
| 7851 |
null; |
| 7852 |
|
| 7853 |
-- Case of an implicit operation or derived literal. The new entity |
| 7854 |
-- hides the implicit one, which is removed from all visibility, |
| 7855 |
-- i.e. the entity list of its scope, and homonym chain of its name. |
| 7856 |
|
| 7857 |
elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E)) |
| 7858 |
or else Is_Internal (E) |
| 7859 |
then |
| 7860 |
declare |
| 7861 |
Decl : constant Node_Id := Parent (E); |
| 7862 |
Prev : Entity_Id; |
| 7863 |
Prev_Vis : Entity_Id; |
| 7864 |
|
| 7865 |
begin |
| 7866 |
-- If E is an implicit declaration, it cannot be the first |
| 7867 |
-- entity in the scope. |
| 7868 |
|
| 7869 |
Prev := First_Entity (Current_Scope); |
| 7870 |
while Present (Prev) and then Next_Entity (Prev) /= E loop |
| 7871 |
Next_Entity (Prev); |
| 7872 |
end loop; |
| 7873 |
|
| 7874 |
if No (Prev) then |
| 7875 |
|
| 7876 |
-- If E is not on the entity chain of the current scope, |
| 7877 |
-- it is an implicit declaration in the generic formal |
| 7878 |
-- part of a generic subprogram. When analyzing the body, |
| 7879 |
-- the generic formals are visible but not on the entity |
| 7880 |
-- chain of the subprogram. The new entity will become |
| 7881 |
-- the visible one in the body. |
| 7882 |
|
| 7883 |
pragma Assert |
| 7884 |
(Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration); |
| 7885 |
null; |
| 7886 |
|
| 7887 |
else |
| 7888 |
Link_Entities (Prev, Next_Entity (E)); |
| 7889 |
|
| 7890 |
if No (Next_Entity (Prev)) then |
| 7891 |
Set_Last_Entity (Current_Scope, Prev); |
| 7892 |
end if; |
| 7893 |
|
| 7894 |
if E = Current_Entity (E) then |
| 7895 |
Prev_Vis := Empty; |
| 7896 |
|
| 7897 |
else |
| 7898 |
Prev_Vis := Current_Entity (E); |
| 7899 |
while Homonym (Prev_Vis) /= E loop |
| 7900 |
Prev_Vis := Homonym (Prev_Vis); |
| 7901 |
end loop; |
| 7902 |
end if; |
| 7903 |
|
| 7904 |
if Present (Prev_Vis) then |
| 7905 |
|
| 7906 |
-- Skip E in the visibility chain |
| 7907 |
|
| 7908 |
Set_Homonym (Prev_Vis, Homonym (E)); |
| 7909 |
|
| 7910 |
else |
| 7911 |
Set_Name_Entity_Id (Chars (E), Homonym (E)); |
| 7912 |
end if; |
| 7913 |
|
| 7914 |
-- The inherited operation cannot be retrieved |
| 7915 |
-- by name, even though it may remain accesssible |
| 7916 |
-- in some cases involving subprogram bodies without |
| 7917 |
-- specs appearing in with_clauses.. |
| 7918 |
|
| 7919 |
Set_Is_Immediately_Visible (E, False); |
| 7920 |
end if; |
| 7921 |
end; |
| 7922 |
|
| 7923 |
-- This section of code could use a comment ??? |
| 7924 |
|
| 7925 |
elsif Present (Etype (E)) |
| 7926 |
and then Is_Concurrent_Type (Etype (E)) |
| 7927 |
and then E = Def_Id |
| 7928 |
then |
| 7929 |
return; |
| 7930 |
|
| 7931 |
-- If the homograph is a protected component renaming, it should not |
| 7932 |
-- be hiding the current entity. Such renamings are treated as weak |
| 7933 |
-- declarations. |
| 7934 |
|
| 7935 |
elsif Is_Prival (E) then |
| 7936 |
Set_Is_Immediately_Visible (E, False); |
| 7937 |
|
| 7938 |
-- In this case the current entity is a protected component renaming. |
| 7939 |
-- Perform minimal decoration by setting the scope and return since |
| 7940 |
-- the prival should not be hiding other visible entities. |
| 7941 |
|
| 7942 |
elsif Is_Prival (Def_Id) then |
| 7943 |
Set_Scope (Def_Id, Current_Scope); |
| 7944 |
return; |
| 7945 |
|
| 7946 |
-- Analogous to privals, the discriminal generated for an entry index |
| 7947 |
-- parameter acts as a weak declaration. Perform minimal decoration |
| 7948 |
-- to avoid bogus errors. |
| 7949 |
|
| 7950 |
elsif Is_Discriminal (Def_Id) |
| 7951 |
and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter |
| 7952 |
then |
| 7953 |
Set_Scope (Def_Id, Current_Scope); |
| 7954 |
return; |
| 7955 |
|
| 7956 |
-- In the body or private part of an instance, a type extension may |
| 7957 |
-- introduce a component with the same name as that of an actual. The |
| 7958 |
-- legality rule is not enforced, but the semantics of the full type |
| 7959 |
-- with two components of same name are not clear at this point??? |
| 7960 |
|
| 7961 |
elsif In_Instance_Not_Visible then |
| 7962 |
null; |
| 7963 |
|
| 7964 |
-- When compiling a package body, some child units may have become |
| 7965 |
-- visible. They cannot conflict with local entities that hide them. |
| 7966 |
|
| 7967 |
elsif Is_Child_Unit (E) |
| 7968 |
and then In_Open_Scopes (Scope (E)) |
| 7969 |
and then not Is_Immediately_Visible (E) |
| 7970 |
then |
| 7971 |
null; |
| 7972 |
|
| 7973 |
-- Conversely, with front-end inlining we may compile the parent body |
| 7974 |
-- first, and a child unit subsequently. The context is now the |
| 7975 |
-- parent spec, and body entities are not visible. |
| 7976 |
|
| 7977 |
elsif Is_Child_Unit (Def_Id) |
| 7978 |
and then Is_Package_Body_Entity (E) |
| 7979 |
and then not In_Package_Body (Current_Scope) |
| 7980 |
then |
| 7981 |
null; |
| 7982 |
|
| 7983 |
-- Case of genuine duplicate declaration |
| 7984 |
|
| 7985 |
else |
| 7986 |
Error_Msg_Sloc := Sloc (E); |
| 7987 |
|
| 7988 |
-- If the previous declaration is an incomplete type declaration |
| 7989 |
-- this may be an attempt to complete it with a private type. The |
| 7990 |
-- following avoids confusing cascaded errors. |
| 7991 |
|
| 7992 |
if Nkind (Parent (E)) = N_Incomplete_Type_Declaration |
| 7993 |
and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration |
| 7994 |
then |
| 7995 |
Error_Msg_N |
| 7996 |
("incomplete type cannot be completed with a private " & |
| 7997 |
"declaration", Parent (Def_Id)); |
| 7998 |
Set_Is_Immediately_Visible (E, False); |
| 7999 |
Set_Full_View (E, Def_Id); |
| 8000 |
|
| 8001 |
-- An inherited component of a record conflicts with a new |
| 8002 |
-- discriminant. The discriminant is inserted first in the scope, |
| 8003 |
-- but the error should be posted on it, not on the component. |
| 8004 |
|
| 8005 |
elsif Ekind (E) = E_Discriminant |
| 8006 |
and then Present (Scope (Def_Id)) |
| 8007 |
and then Scope (Def_Id) /= Current_Scope |
| 8008 |
then |
| 8009 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 8010 |
Error_Msg_N ("& conflicts with declaration#", E); |
| 8011 |
return; |
| 8012 |
|
| 8013 |
-- If the name of the unit appears in its own context clause, a |
| 8014 |
-- dummy package with the name has already been created, and the |
| 8015 |
-- error emitted. Try to continue quietly. |
| 8016 |
|
| 8017 |
elsif Error_Posted (E) |
| 8018 |
and then Sloc (E) = No_Location |
| 8019 |
and then Nkind (Parent (E)) = N_Package_Specification |
| 8020 |
and then Current_Scope = Standard_Standard |
| 8021 |
then |
| 8022 |
Set_Scope (Def_Id, Current_Scope); |
| 8023 |
return; |
| 8024 |
|
| 8025 |
else |
| 8026 |
Error_Msg_N ("& conflicts with declaration#", Def_Id); |
| 8027 |
|
| 8028 |
-- Avoid cascaded messages with duplicate components in |
| 8029 |
-- derived types. |
| 8030 |
|
| 8031 |
if Ekind (E) in E_Component | E_Discriminant then |
| 8032 |
return; |
| 8033 |
end if; |
| 8034 |
end if; |
| 8035 |
|
| 8036 |
if Nkind (Parent (Parent (Def_Id))) = |
| 8037 |
N_Generic_Subprogram_Declaration |
| 8038 |
and then Def_Id = |
| 8039 |
Defining_Entity (Specification (Parent (Parent (Def_Id)))) |
| 8040 |
then |
| 8041 |
Error_Msg_N ("\generic units cannot be overloaded", Def_Id); |
| 8042 |
end if; |
| 8043 |
|
| 8044 |
-- If entity is in standard, then we are in trouble, because it |
| 8045 |
-- means that we have a library package with a duplicated name. |
| 8046 |
-- That's hard to recover from, so abort. |
| 8047 |
|
| 8048 |
if S = Standard_Standard then |
| 8049 |
raise Unrecoverable_Error; |
| 8050 |
|
| 8051 |
-- Otherwise we continue with the declaration. Having two |
| 8052 |
-- identical declarations should not cause us too much trouble. |
| 8053 |
|
| 8054 |
else |
| 8055 |
null; |
| 8056 |
end if; |
| 8057 |
end if; |
| 8058 |
end if; |
| 8059 |
|
| 8060 |
-- If we fall through, declaration is OK, at least OK enough to continue |
| 8061 |
|
| 8062 |
-- If Def_Id is a discriminant or a record component we are in the midst |
| 8063 |
-- of inheriting components in a derived record definition. Preserve |
| 8064 |
-- their Ekind and Etype. |
| 8065 |
|
| 8066 |
if Ekind (Def_Id) in E_Discriminant | E_Component then |
| 8067 |
null; |
| 8068 |
|
| 8069 |
-- If a type is already set, leave it alone (happens when a type |
| 8070 |
-- declaration is reanalyzed following a call to the optimizer). |
| 8071 |
|
| 8072 |
elsif Present (Etype (Def_Id)) then |
| 8073 |
null; |
| 8074 |
|
| 8075 |
else |
| 8076 |
Set_Etype (Def_Id, Any_Type); -- avoid cascaded errors |
| 8077 |
end if; |
| 8078 |
|
| 8079 |
-- All entities except Itypes are immediately visible |
| 8080 |
|
| 8081 |
if not Is_Itype (Def_Id) then |
| 8082 |
Set_Is_Immediately_Visible (Def_Id); |
| 8083 |
Set_Current_Entity (Def_Id); |
| 8084 |
end if; |
| 8085 |
|
| 8086 |
Set_Homonym (Def_Id, C); |
| 8087 |
Append_Entity (Def_Id, S); |
| 8088 |
Set_Public_Status (Def_Id); |
| 8089 |
|
| 8090 |
-- Warn if new entity hides an old one |
| 8091 |
|
| 8092 |
if Warn_On_Hiding and then Present (C) then |
| 8093 |
Warn_On_Hiding_Entity (Def_Id, Hidden => C, Visible => Def_Id, |
| 8094 |
On_Use_Clause => False); |
| 8095 |
end if; |
| 8096 |
end Enter_Name; |
| 8097 |
|
| 8098 |
--------------- |
| 8099 |
-- Entity_Of -- |
| 8100 |
--------------- |
| 8101 |
|
| 8102 |
function Entity_Of (N : Node_Id) return Entity_Id is |
| 8103 |
Id : Entity_Id; |
| 8104 |
Ren : Node_Id; |
| 8105 |
|
| 8106 |
begin |
| 8107 |
-- Assume that the arbitrary node does not have an entity |
| 8108 |
|
| 8109 |
Id := Empty; |
| 8110 |
|
| 8111 |
if Is_Entity_Name (N) then |
| 8112 |
Id := Entity (N); |
| 8113 |
|
| 8114 |
-- Follow a possible chain of renamings to reach the earliest renamed |
| 8115 |
-- source object. |
| 8116 |
|
| 8117 |
while Present (Id) |
| 8118 |
and then Is_Object (Id) |
| 8119 |
and then Present (Renamed_Object (Id)) |
| 8120 |
loop |
| 8121 |
Ren := Renamed_Object (Id); |
| 8122 |
|
| 8123 |
-- The reference renames a function result. Check the original |
| 8124 |
-- node in case expansion relocates the function call. |
| 8125 |
|
| 8126 |
-- Ren : ... renames Func_Call; |
| 8127 |
|
| 8128 |
if Nkind (Original_Node (Ren)) = N_Function_Call then |
| 8129 |
exit; |
| 8130 |
|
| 8131 |
-- The reference renames an abstract state or a whole object |
| 8132 |
|
| 8133 |
-- Obj : ...; |
| 8134 |
-- Ren : ... renames Obj; |
| 8135 |
|
| 8136 |
elsif Is_Entity_Name (Ren) then |
| 8137 |
|
| 8138 |
-- Do not follow a renaming that goes through a generic formal, |
| 8139 |
-- because these entities are hidden and must not be referenced |
| 8140 |
-- from outside the generic. |
| 8141 |
|
| 8142 |
if Is_Hidden (Entity (Ren)) then |
| 8143 |
exit; |
| 8144 |
|
| 8145 |
else |
| 8146 |
Id := Entity (Ren); |
| 8147 |
end if; |
| 8148 |
|
| 8149 |
-- Otherwise the reference renames something which does not yield |
| 8150 |
-- an abstract state or a whole object. Treat the reference as not |
| 8151 |
-- having a proper entity for SPARK legality purposes. |
| 8152 |
|
| 8153 |
else |
| 8154 |
Id := Empty; |
| 8155 |
exit; |
| 8156 |
end if; |
| 8157 |
end loop; |
| 8158 |
end if; |
| 8159 |
|
| 8160 |
return Id; |
| 8161 |
end Entity_Of; |
| 8162 |
|
| 8163 |
-------------------------- |
| 8164 |
-- Examine_Array_Bounds -- |
| 8165 |
-------------------------- |
| 8166 |
|
| 8167 |
procedure Examine_Array_Bounds |
| 8168 |
(Typ : Entity_Id; |
| 8169 |
All_Static : out Boolean; |
| 8170 |
Has_Empty : out Boolean) |
| 8171 |
is |
| 8172 |
function Is_OK_Static_Bound (Bound : Node_Id) return Boolean; |
| 8173 |
-- Determine whether bound Bound is a suitable static bound |
| 8174 |
|
| 8175 |
------------------------ |
| 8176 |
-- Is_OK_Static_Bound -- |
| 8177 |
------------------------ |
| 8178 |
|
| 8179 |
function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is |
| 8180 |
begin |
| 8181 |
return |
| 8182 |
not Error_Posted (Bound) |
| 8183 |
and then Is_OK_Static_Expression (Bound); |
| 8184 |
end Is_OK_Static_Bound; |
| 8185 |
|
| 8186 |
-- Local variables |
| 8187 |
|
| 8188 |
Hi_Bound : Node_Id; |
| 8189 |
Index : Node_Id; |
| 8190 |
Lo_Bound : Node_Id; |
| 8191 |
|
| 8192 |
-- Start of processing for Examine_Array_Bounds |
| 8193 |
|
| 8194 |
begin |
| 8195 |
-- An unconstrained array type does not have static bounds, and it is |
| 8196 |
-- not known whether they are empty or not. |
| 8197 |
|
| 8198 |
if not Is_Constrained (Typ) then |
| 8199 |
All_Static := False; |
| 8200 |
Has_Empty := False; |
| 8201 |
return; |
| 8202 |
|
| 8203 |
-- A string literal has static bounds, and is not empty as long as it |
| 8204 |
-- contains at least one character. |
| 8205 |
|
| 8206 |
elsif Ekind (Typ) = E_String_Literal_Subtype then |
| 8207 |
All_Static := True; |
| 8208 |
Has_Empty := String_Literal_Length (Typ) = 0; |
| 8209 |
return; |
| 8210 |
end if; |
| 8211 |
|
| 8212 |
-- Assume that all bounds are static and not empty |
| 8213 |
|
| 8214 |
All_Static := True; |
| 8215 |
Has_Empty := False; |
| 8216 |
|
| 8217 |
-- Examine each index |
| 8218 |
|
| 8219 |
Index := First_Index (Typ); |
| 8220 |
while Present (Index) loop |
| 8221 |
if Is_Discrete_Type (Etype (Index)) then |
| 8222 |
Get_Index_Bounds (Index, Lo_Bound, Hi_Bound); |
| 8223 |
|
| 8224 |
if Is_OK_Static_Bound (Lo_Bound) |
| 8225 |
and then |
| 8226 |
Is_OK_Static_Bound (Hi_Bound) |
| 8227 |
then |
| 8228 |
-- The static bounds produce an empty range |
| 8229 |
|
| 8230 |
if Is_Null_Range (Lo_Bound, Hi_Bound) then |
| 8231 |
Has_Empty := True; |
| 8232 |
end if; |
| 8233 |
|
| 8234 |
-- Otherwise at least one of the bounds is not static |
| 8235 |
|
| 8236 |
else |
| 8237 |
All_Static := False; |
| 8238 |
end if; |
| 8239 |
|
| 8240 |
-- Otherwise the index is non-discrete, therefore not static |
| 8241 |
|
| 8242 |
else |
| 8243 |
All_Static := False; |
| 8244 |
end if; |
| 8245 |
|
| 8246 |
Next_Index (Index); |
| 8247 |
end loop; |
| 8248 |
end Examine_Array_Bounds; |
| 8249 |
|
| 8250 |
------------------- |
| 8251 |
-- Exceptions_OK -- |
| 8252 |
------------------- |
| 8253 |
|
| 8254 |
function Exceptions_OK return Boolean is |
| 8255 |
begin |
| 8256 |
return |
| 8257 |
not (Restriction_Active (No_Exception_Handlers) or else |
| 8258 |
Restriction_Active (No_Exception_Propagation) or else |
| 8259 |
Restriction_Active (No_Exceptions)); |
| 8260 |
end Exceptions_OK; |
| 8261 |
|
| 8262 |
-------------------------- |
| 8263 |
-- Explain_Limited_Type -- |
| 8264 |
-------------------------- |
| 8265 |
|
| 8266 |
procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is |
| 8267 |
C : Entity_Id; |
| 8268 |
|
| 8269 |
begin |
| 8270 |
-- For array, component type must be limited |
| 8271 |
|
| 8272 |
if Is_Array_Type (T) then |
| 8273 |
Error_Msg_Node_2 := T; |
| 8274 |
Error_Msg_NE |
| 8275 |
("\component type& of type& is limited", N, Component_Type (T)); |
| 8276 |
Explain_Limited_Type (Component_Type (T), N); |
| 8277 |
|
| 8278 |
elsif Is_Record_Type (T) then |
| 8279 |
|
| 8280 |
-- No need for extra messages if explicit limited record |
| 8281 |
|
| 8282 |
if Is_Limited_Record (Base_Type (T)) then |
| 8283 |
return; |
| 8284 |
end if; |
| 8285 |
|
| 8286 |
-- Otherwise find a limited component. Check only components that |
| 8287 |
-- come from source, or inherited components that appear in the |
| 8288 |
-- source of the ancestor. |
| 8289 |
|
| 8290 |
C := First_Component (T); |
| 8291 |
while Present (C) loop |
| 8292 |
if Is_Limited_Type (Etype (C)) |
| 8293 |
and then |
| 8294 |
(Comes_From_Source (C) |
| 8295 |
or else |
| 8296 |
(Present (Original_Record_Component (C)) |
| 8297 |
and then |
| 8298 |
Comes_From_Source (Original_Record_Component (C)))) |
| 8299 |
then |
| 8300 |
Error_Msg_Node_2 := T; |
| 8301 |
Error_Msg_NE ("\component& of type& has limited type", N, C); |
| 8302 |
Explain_Limited_Type (Etype (C), N); |
| 8303 |
return; |
| 8304 |
end if; |
| 8305 |
|
| 8306 |
Next_Component (C); |
| 8307 |
end loop; |
| 8308 |
|
| 8309 |
-- The type may be declared explicitly limited, even if no component |
| 8310 |
-- of it is limited, in which case we fall out of the loop. |
| 8311 |
return; |
| 8312 |
end if; |
| 8313 |
end Explain_Limited_Type; |
| 8314 |
|
| 8315 |
--------------------------------------- |
| 8316 |
-- Expression_Of_Expression_Function -- |
| 8317 |
--------------------------------------- |
| 8318 |
|
| 8319 |
function Expression_Of_Expression_Function |
| 8320 |
(Subp : Entity_Id) return Node_Id |
| 8321 |
is |
| 8322 |
Expr_Func : Node_Id := Empty; |
| 8323 |
|
| 8324 |
begin |
| 8325 |
pragma Assert (Is_Expression_Function_Or_Completion (Subp)); |
| 8326 |
|
| 8327 |
if Nkind (Original_Node (Subprogram_Spec (Subp))) = |
| 8328 |
N_Expression_Function |
| 8329 |
then |
| 8330 |
Expr_Func := Original_Node (Subprogram_Spec (Subp)); |
| 8331 |
|
| 8332 |
elsif Nkind (Original_Node (Subprogram_Body (Subp))) = |
| 8333 |
N_Expression_Function |
| 8334 |
then |
| 8335 |
Expr_Func := Original_Node (Subprogram_Body (Subp)); |
| 8336 |
|
| 8337 |
else |
| 8338 |
pragma Assert (False); |
| 8339 |
null; |
| 8340 |
end if; |
| 8341 |
|
| 8342 |
return Original_Node (Expression (Expr_Func)); |
| 8343 |
end Expression_Of_Expression_Function; |
| 8344 |
|
| 8345 |
------------------------------- |
| 8346 |
-- Extensions_Visible_Status -- |
| 8347 |
------------------------------- |
| 8348 |
|
| 8349 |
function Extensions_Visible_Status |
| 8350 |
(Id : Entity_Id) return Extensions_Visible_Mode |
| 8351 |
is |
| 8352 |
Arg : Node_Id; |
| 8353 |
Decl : Node_Id; |
| 8354 |
Expr : Node_Id; |
| 8355 |
Prag : Node_Id; |
| 8356 |
Subp : Entity_Id; |
| 8357 |
|
| 8358 |
begin |
| 8359 |
-- When a formal parameter is subject to Extensions_Visible, the pragma |
| 8360 |
-- is stored in the contract of related subprogram. |
| 8361 |
|
| 8362 |
if Is_Formal (Id) then |
| 8363 |
Subp := Scope (Id); |
| 8364 |
|
| 8365 |
elsif Is_Subprogram_Or_Generic_Subprogram (Id) then |
| 8366 |
Subp := Id; |
| 8367 |
|
| 8368 |
-- No other construct carries this pragma |
| 8369 |
|
| 8370 |
else |
| 8371 |
return Extensions_Visible_None; |
| 8372 |
end if; |
| 8373 |
|
| 8374 |
Prag := Get_Pragma (Subp, Pragma_Extensions_Visible); |
| 8375 |
|
| 8376 |
-- In certain cases analysis may request the Extensions_Visible status |
| 8377 |
-- of an expression function before the pragma has been analyzed yet. |
| 8378 |
-- Inspect the declarative items after the expression function looking |
| 8379 |
-- for the pragma (if any). |
| 8380 |
|
| 8381 |
if No (Prag) and then Is_Expression_Function (Subp) then |
| 8382 |
Decl := Next (Unit_Declaration_Node (Subp)); |
| 8383 |
while Present (Decl) loop |
| 8384 |
if Nkind (Decl) = N_Pragma |
| 8385 |
and then Pragma_Name (Decl) = Name_Extensions_Visible |
| 8386 |
then |
| 8387 |
Prag := Decl; |
| 8388 |
exit; |
| 8389 |
|
| 8390 |
-- A source construct ends the region where Extensions_Visible may |
| 8391 |
-- appear, stop the traversal. An expanded expression function is |
| 8392 |
-- no longer a source construct, but it must still be recognized. |
| 8393 |
|
| 8394 |
elsif Comes_From_Source (Decl) |
| 8395 |
or else |
| 8396 |
(Nkind (Decl) in N_Subprogram_Body | N_Subprogram_Declaration |
| 8397 |
and then Is_Expression_Function (Defining_Entity (Decl))) |
| 8398 |
then |
| 8399 |
exit; |
| 8400 |
end if; |
| 8401 |
|
| 8402 |
Next (Decl); |
| 8403 |
end loop; |
| 8404 |
end if; |
| 8405 |
|
| 8406 |
-- Extract the value from the Boolean expression (if any) |
| 8407 |
|
| 8408 |
if Present (Prag) then |
| 8409 |
Arg := First (Pragma_Argument_Associations (Prag)); |
| 8410 |
|
| 8411 |
if Present (Arg) then |
| 8412 |
Expr := Get_Pragma_Arg (Arg); |
| 8413 |
|
| 8414 |
-- When the associated subprogram is an expression function, the |
| 8415 |
-- argument of the pragma may not have been analyzed. |
| 8416 |
|
| 8417 |
if not Analyzed (Expr) then |
| 8418 |
Preanalyze_And_Resolve (Expr, Standard_Boolean); |
| 8419 |
end if; |
| 8420 |
|
| 8421 |
-- Guard against cascading errors when the argument of pragma |
| 8422 |
-- Extensions_Visible is not a valid static Boolean expression. |
| 8423 |
|
| 8424 |
if Error_Posted (Expr) then |
| 8425 |
return Extensions_Visible_None; |
| 8426 |
|
| 8427 |
elsif Is_True (Expr_Value (Expr)) then |
| 8428 |
return Extensions_Visible_True; |
| 8429 |
|
| 8430 |
else |
| 8431 |
return Extensions_Visible_False; |
| 8432 |
end if; |
| 8433 |
|
| 8434 |
-- Otherwise the aspect or pragma defaults to True |
| 8435 |
|
| 8436 |
else |
| 8437 |
return Extensions_Visible_True; |
| 8438 |
end if; |
| 8439 |
|
| 8440 |
-- Otherwise aspect or pragma Extensions_Visible is not inherited or |
| 8441 |
-- directly specified. In SPARK code, its value defaults to "False". |
| 8442 |
|
| 8443 |
elsif SPARK_Mode = On then |
| 8444 |
return Extensions_Visible_False; |
| 8445 |
|
| 8446 |
-- In non-SPARK code, aspect or pragma Extensions_Visible defaults to |
| 8447 |
-- "True". |
| 8448 |
|
| 8449 |
else |
| 8450 |
return Extensions_Visible_True; |
| 8451 |
end if; |
| 8452 |
end Extensions_Visible_Status; |
| 8453 |
|
| 8454 |
----------------- |
| 8455 |
-- Find_Actual -- |
| 8456 |
----------------- |
| 8457 |
|
| 8458 |
procedure Find_Actual |
| 8459 |
(N : Node_Id; |
| 8460 |
Formal : out Entity_Id; |
| 8461 |
Call : out Node_Id) |
| 8462 |
is |
| 8463 |
Context : constant Node_Id := Parent (N); |
| 8464 |
Actual : Node_Id; |
| 8465 |
Call_Nam : Node_Id; |
| 8466 |
Call_Ent : Node_Id := Empty; |
| 8467 |
|
| 8468 |
begin |
| 8469 |
if Nkind (Context) in N_Indexed_Component | N_Selected_Component |
| 8470 |
and then N = Prefix (Context) |
| 8471 |
then |
| 8472 |
Find_Actual (Context, Formal, Call); |
| 8473 |
return; |
| 8474 |
|
| 8475 |
elsif Nkind (Context) = N_Parameter_Association |
| 8476 |
and then N = Explicit_Actual_Parameter (Context) |
| 8477 |
then |
| 8478 |
Call := Parent (Context); |
| 8479 |
|
| 8480 |
elsif Nkind (Context) in N_Entry_Call_Statement |
| 8481 |
| N_Function_Call |
| 8482 |
| N_Procedure_Call_Statement |
| 8483 |
then |
| 8484 |
Call := Context; |
| 8485 |
|
| 8486 |
else |
| 8487 |
Formal := Empty; |
| 8488 |
Call := Empty; |
| 8489 |
return; |
| 8490 |
end if; |
| 8491 |
|
| 8492 |
-- If we have a call to a subprogram look for the parameter. Note that |
| 8493 |
-- we exclude overloaded calls, since we don't know enough to be sure |
| 8494 |
-- of giving the right answer in this case. |
| 8495 |
|
| 8496 |
if Nkind (Call) in N_Entry_Call_Statement |
| 8497 |
| N_Function_Call |
| 8498 |
| N_Procedure_Call_Statement |
| 8499 |
then |
| 8500 |
Call_Nam := Name (Call); |
| 8501 |
|
| 8502 |
-- A call to an entry family may appear as an indexed component |
| 8503 |
|
| 8504 |
if Nkind (Call_Nam) = N_Indexed_Component then |
| 8505 |
Call_Nam := Prefix (Call_Nam); |
| 8506 |
end if; |
| 8507 |
|
| 8508 |
-- A call to a protected or task entry appears as a selected |
| 8509 |
-- component rather than an expanded name. |
| 8510 |
|
| 8511 |
if Nkind (Call_Nam) = N_Selected_Component then |
| 8512 |
Call_Nam := Selector_Name (Call_Nam); |
| 8513 |
end if; |
| 8514 |
|
| 8515 |
-- If Call_Nam is an entity name, get its entity |
| 8516 |
|
| 8517 |
if Is_Entity_Name (Call_Nam) then |
| 8518 |
Call_Ent := Entity (Call_Nam); |
| 8519 |
|
| 8520 |
-- If it is a dereference, get the designated subprogram type |
| 8521 |
|
| 8522 |
elsif Nkind (Call_Nam) = N_Explicit_Dereference then |
| 8523 |
declare |
| 8524 |
Typ : Entity_Id := Etype (Prefix (Call_Nam)); |
| 8525 |
begin |
| 8526 |
if Present (Full_View (Typ)) then |
| 8527 |
Typ := Full_View (Typ); |
| 8528 |
elsif Is_Private_Type (Typ) |
| 8529 |
and then Present (Underlying_Full_View (Typ)) |
| 8530 |
then |
| 8531 |
Typ := Underlying_Full_View (Typ); |
| 8532 |
end if; |
| 8533 |
|
| 8534 |
if Is_Access_Type (Typ) then |
| 8535 |
Call_Ent := Directly_Designated_Type (Typ); |
| 8536 |
else |
| 8537 |
pragma Assert (Has_Implicit_Dereference (Typ)); |
| 8538 |
Formal := Empty; |
| 8539 |
Call := Empty; |
| 8540 |
return; |
| 8541 |
end if; |
| 8542 |
end; |
| 8543 |
end if; |
| 8544 |
|
| 8545 |
if Present (Call_Ent) |
| 8546 |
and then (Is_Generic_Subprogram (Call_Ent) |
| 8547 |
or else Is_Overloadable (Call_Ent) |
| 8548 |
or else Ekind (Call_Ent) in E_Entry_Family |
| 8549 |
| E_Subprogram_Body |
| 8550 |
| E_Subprogram_Type) |
| 8551 |
and then not Is_Overloaded (Call_Nam) |
| 8552 |
then |
| 8553 |
-- If node is name in call it is not an actual |
| 8554 |
|
| 8555 |
if N = Call_Nam then |
| 8556 |
Formal := Empty; |
| 8557 |
Call := Empty; |
| 8558 |
return; |
| 8559 |
end if; |
| 8560 |
|
| 8561 |
-- Fall here if we are definitely a parameter |
| 8562 |
|
| 8563 |
Actual := First_Actual (Call); |
| 8564 |
Formal := First_Formal (Call_Ent); |
| 8565 |
while Present (Formal) and then Present (Actual) loop |
| 8566 |
if Actual = N then |
| 8567 |
return; |
| 8568 |
|
| 8569 |
-- An actual that is the prefix in a prefixed call may have |
| 8570 |
-- been rewritten in the call. Check if sloc and kinds and |
| 8571 |
-- names match. |
| 8572 |
|
| 8573 |
elsif Sloc (Actual) = Sloc (N) |
| 8574 |
and then Nkind (Actual) = N_Identifier |
| 8575 |
and then Nkind (Actual) = Nkind (N) |
| 8576 |
and then Chars (Actual) = Chars (N) |
| 8577 |
then |
| 8578 |
return; |
| 8579 |
|
| 8580 |
else |
| 8581 |
Next_Actual (Actual); |
| 8582 |
Next_Formal (Formal); |
| 8583 |
end if; |
| 8584 |
end loop; |
| 8585 |
end if; |
| 8586 |
end if; |
| 8587 |
|
| 8588 |
-- Fall through here if we did not find matching actual |
| 8589 |
|
| 8590 |
Formal := Empty; |
| 8591 |
Call := Empty; |
| 8592 |
end Find_Actual; |
| 8593 |
|
| 8594 |
--------------------------- |
| 8595 |
-- Find_Body_Discriminal -- |
| 8596 |
--------------------------- |
| 8597 |
|
| 8598 |
function Find_Body_Discriminal |
| 8599 |
(Spec_Discriminant : Entity_Id) return Entity_Id |
| 8600 |
is |
| 8601 |
Tsk : Entity_Id; |
| 8602 |
Disc : Entity_Id; |
| 8603 |
|
| 8604 |
begin |
| 8605 |
-- If expansion is suppressed, then the scope can be the concurrent type |
| 8606 |
-- itself rather than a corresponding concurrent record type. |
| 8607 |
|
| 8608 |
if Is_Concurrent_Type (Scope (Spec_Discriminant)) then |
| 8609 |
Tsk := Scope (Spec_Discriminant); |
| 8610 |
|
| 8611 |
else |
| 8612 |
pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant))); |
| 8613 |
|
| 8614 |
Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant)); |
| 8615 |
end if; |
| 8616 |
|
| 8617 |
-- Find discriminant of original concurrent type, and use its current |
| 8618 |
-- discriminal, which is the renaming within the task/protected body. |
| 8619 |
|
| 8620 |
Disc := First_Discriminant (Tsk); |
| 8621 |
while Present (Disc) loop |
| 8622 |
if Chars (Disc) = Chars (Spec_Discriminant) then |
| 8623 |
return Discriminal (Disc); |
| 8624 |
end if; |
| 8625 |
|
| 8626 |
Next_Discriminant (Disc); |
| 8627 |
end loop; |
| 8628 |
|
| 8629 |
-- That loop should always succeed in finding a matching entry and |
| 8630 |
-- returning. Fatal error if not. |
| 8631 |
|
| 8632 |
raise Program_Error; |
| 8633 |
end Find_Body_Discriminal; |
| 8634 |
|
| 8635 |
------------------------------------- |
| 8636 |
-- Find_Corresponding_Discriminant -- |
| 8637 |
------------------------------------- |
| 8638 |
|
| 8639 |
function Find_Corresponding_Discriminant |
| 8640 |
(Id : Node_Id; |
| 8641 |
Typ : Entity_Id) return Entity_Id |
| 8642 |
is |
| 8643 |
Par_Disc : Entity_Id; |
| 8644 |
Old_Disc : Entity_Id; |
| 8645 |
New_Disc : Entity_Id; |
| 8646 |
|
| 8647 |
begin |
| 8648 |
Par_Disc := Original_Record_Component (Original_Discriminant (Id)); |
| 8649 |
|
| 8650 |
-- The original type may currently be private, and the discriminant |
| 8651 |
-- only appear on its full view. |
| 8652 |
|
| 8653 |
if Is_Private_Type (Scope (Par_Disc)) |
| 8654 |
and then not Has_Discriminants (Scope (Par_Disc)) |
| 8655 |
and then Present (Full_View (Scope (Par_Disc))) |
| 8656 |
then |
| 8657 |
Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc))); |
| 8658 |
else |
| 8659 |
Old_Disc := First_Discriminant (Scope (Par_Disc)); |
| 8660 |
end if; |
| 8661 |
|
| 8662 |
if Is_Class_Wide_Type (Typ) then |
| 8663 |
New_Disc := First_Discriminant (Root_Type (Typ)); |
| 8664 |
else |
| 8665 |
New_Disc := First_Discriminant (Typ); |
| 8666 |
end if; |
| 8667 |
|
| 8668 |
while Present (Old_Disc) and then Present (New_Disc) loop |
| 8669 |
if Old_Disc = Par_Disc then |
| 8670 |
return New_Disc; |
| 8671 |
end if; |
| 8672 |
|
| 8673 |
Next_Discriminant (Old_Disc); |
| 8674 |
Next_Discriminant (New_Disc); |
| 8675 |
end loop; |
| 8676 |
|
| 8677 |
-- Should always find it |
| 8678 |
|
| 8679 |
raise Program_Error; |
| 8680 |
end Find_Corresponding_Discriminant; |
| 8681 |
|
| 8682 |
------------------- |
| 8683 |
-- Find_DIC_Type -- |
| 8684 |
------------------- |
| 8685 |
|
| 8686 |
function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is |
| 8687 |
Curr_Typ : Entity_Id; |
| 8688 |
-- The current type being examined in the parent hierarchy traversal |
| 8689 |
|
| 8690 |
DIC_Typ : Entity_Id; |
| 8691 |
-- The type which carries the DIC pragma. This variable denotes the |
| 8692 |
-- partial view when private types are involved. |
| 8693 |
|
| 8694 |
Par_Typ : Entity_Id; |
| 8695 |
-- The parent type of the current type. This variable denotes the full |
| 8696 |
-- view when private types are involved. |
| 8697 |
|
| 8698 |
begin |
| 8699 |
-- The input type defines its own DIC pragma, therefore it is the owner |
| 8700 |
|
| 8701 |
if Has_Own_DIC (Typ) then |
| 8702 |
DIC_Typ := Typ; |
| 8703 |
|
| 8704 |
-- Otherwise the DIC pragma is inherited from a parent type |
| 8705 |
|
| 8706 |
else |
| 8707 |
pragma Assert (Has_Inherited_DIC (Typ)); |
| 8708 |
|
| 8709 |
-- Climb the parent chain |
| 8710 |
|
| 8711 |
Curr_Typ := Typ; |
| 8712 |
loop |
| 8713 |
-- Inspect the parent type. Do not consider subtypes as they |
| 8714 |
-- inherit the DIC attributes from their base types. |
| 8715 |
|
| 8716 |
DIC_Typ := Base_Type (Etype (Curr_Typ)); |
| 8717 |
|
| 8718 |
-- Look at the full view of a private type because the type may |
| 8719 |
-- have a hidden parent introduced in the full view. |
| 8720 |
|
| 8721 |
Par_Typ := DIC_Typ; |
| 8722 |
|
| 8723 |
if Is_Private_Type (Par_Typ) |
| 8724 |
and then Present (Full_View (Par_Typ)) |
| 8725 |
then |
| 8726 |
Par_Typ := Full_View (Par_Typ); |
| 8727 |
end if; |
| 8728 |
|
| 8729 |
-- Stop the climb once the nearest parent type which defines a DIC |
| 8730 |
-- pragma of its own is encountered or when the root of the parent |
| 8731 |
-- chain is reached. |
| 8732 |
|
| 8733 |
exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ; |
| 8734 |
|
| 8735 |
Curr_Typ := Par_Typ; |
| 8736 |
end loop; |
| 8737 |
end if; |
| 8738 |
|
| 8739 |
return DIC_Typ; |
| 8740 |
end Find_DIC_Type; |
| 8741 |
|
| 8742 |
---------------------------------- |
| 8743 |
-- Find_Enclosing_Iterator_Loop -- |
| 8744 |
---------------------------------- |
| 8745 |
|
| 8746 |
function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is |
| 8747 |
Constr : Node_Id; |
| 8748 |
S : Entity_Id; |
| 8749 |
|
| 8750 |
begin |
| 8751 |
-- Traverse the scope chain looking for an iterator loop. Such loops are |
| 8752 |
-- usually transformed into blocks, hence the use of Original_Node. |
| 8753 |
|
| 8754 |
S := Id; |
| 8755 |
while Present (S) and then S /= Standard_Standard loop |
| 8756 |
if Ekind (S) = E_Loop |
| 8757 |
and then Nkind (Parent (S)) = N_Implicit_Label_Declaration |
| 8758 |
then |
| 8759 |
Constr := Original_Node (Label_Construct (Parent (S))); |
| 8760 |
|
| 8761 |
if Nkind (Constr) = N_Loop_Statement |
| 8762 |
and then Present (Iteration_Scheme (Constr)) |
| 8763 |
and then Nkind (Iterator_Specification |
| 8764 |
(Iteration_Scheme (Constr))) = |
| 8765 |
N_Iterator_Specification |
| 8766 |
then |
| 8767 |
return S; |
| 8768 |
end if; |
| 8769 |
end if; |
| 8770 |
|
| 8771 |
S := Scope (S); |
| 8772 |
end loop; |
| 8773 |
|
| 8774 |
return Empty; |
| 8775 |
end Find_Enclosing_Iterator_Loop; |
| 8776 |
|
| 8777 |
-------------------------- |
| 8778 |
-- Find_Enclosing_Scope -- |
| 8779 |
-------------------------- |
| 8780 |
|
| 8781 |
function Find_Enclosing_Scope (N : Node_Id) return Scope_Kind_Id is |
| 8782 |
Par : Node_Id; |
| 8783 |
|
| 8784 |
begin |
| 8785 |
-- If N is an entity, simply return its Scope |
| 8786 |
|
| 8787 |
if Nkind (N) in N_Entity then |
| 8788 |
return Scope (N); |
| 8789 |
end if; |
| 8790 |
|
| 8791 |
-- Examine the parent chain looking for a construct which defines a |
| 8792 |
-- scope. |
| 8793 |
|
| 8794 |
Par := Parent (N); |
| 8795 |
while Present (Par) loop |
| 8796 |
case Nkind (Par) is |
| 8797 |
|
| 8798 |
-- The construct denotes a declaration, the proper scope is its |
| 8799 |
-- entity. |
| 8800 |
|
| 8801 |
when N_Entry_Declaration |
| 8802 |
| N_Expression_Function |
| 8803 |
| N_Full_Type_Declaration |
| 8804 |
| N_Generic_Package_Declaration |
| 8805 |
| N_Generic_Subprogram_Declaration |
| 8806 |
| N_Package_Declaration |
| 8807 |
| N_Private_Extension_Declaration |
| 8808 |
| N_Protected_Type_Declaration |
| 8809 |
| N_Single_Protected_Declaration |
| 8810 |
| N_Single_Task_Declaration |
| 8811 |
| N_Subprogram_Declaration |
| 8812 |
| N_Task_Type_Declaration |
| 8813 |
=> |
| 8814 |
return Defining_Entity (Par); |
| 8815 |
|
| 8816 |
-- The construct denotes a body, the proper scope is the entity of |
| 8817 |
-- the corresponding spec or that of the body if the body does not |
| 8818 |
-- complete a previous declaration. |
| 8819 |
|
| 8820 |
when N_Entry_Body |
| 8821 |
| N_Package_Body |
| 8822 |
| N_Protected_Body |
| 8823 |
| N_Subprogram_Body |
| 8824 |
| N_Task_Body |
| 8825 |
=> |
| 8826 |
return Unique_Defining_Entity (Par); |
| 8827 |
|
| 8828 |
-- Special cases |
| 8829 |
|
| 8830 |
-- Blocks carry either a source or an internally-generated scope, |
| 8831 |
-- unless the block is a byproduct of exception handling. |
| 8832 |
|
| 8833 |
when N_Block_Statement => |
| 8834 |
if not Exception_Junk (Par) then |
| 8835 |
return Entity (Identifier (Par)); |
| 8836 |
end if; |
| 8837 |
|
| 8838 |
-- Loops carry an internally-generated scope |
| 8839 |
|
| 8840 |
when N_Loop_Statement => |
| 8841 |
return Entity (Identifier (Par)); |
| 8842 |
|
| 8843 |
-- Extended return statements carry an internally-generated scope |
| 8844 |
|
| 8845 |
when N_Extended_Return_Statement => |
| 8846 |
return Return_Statement_Entity (Par); |
| 8847 |
|
| 8848 |
-- A traversal from a subunit continues via the corresponding stub |
| 8849 |
|
| 8850 |
when N_Subunit => |
| 8851 |
Par := Corresponding_Stub (Par); |
| 8852 |
|
| 8853 |
when others => |
| 8854 |
null; |
| 8855 |
end case; |
| 8856 |
|
| 8857 |
Par := Parent (Par); |
| 8858 |
end loop; |
| 8859 |
|
| 8860 |
return Standard_Standard; |
| 8861 |
end Find_Enclosing_Scope; |
| 8862 |
|
| 8863 |
------------------------------------ |
| 8864 |
-- Find_Loop_In_Conditional_Block -- |
| 8865 |
------------------------------------ |
| 8866 |
|
| 8867 |
function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is |
| 8868 |
Stmt : Node_Id; |
| 8869 |
|
| 8870 |
begin |
| 8871 |
Stmt := N; |
| 8872 |
|
| 8873 |
if Nkind (Stmt) = N_If_Statement then |
| 8874 |
Stmt := First (Then_Statements (Stmt)); |
| 8875 |
end if; |
| 8876 |
|
| 8877 |
pragma Assert (Nkind (Stmt) = N_Block_Statement); |
| 8878 |
|
| 8879 |
-- Inspect the statements of the conditional block. In general the loop |
| 8880 |
-- should be the first statement in the statement sequence of the block, |
| 8881 |
-- but the finalization machinery may have introduced extra object |
| 8882 |
-- declarations. |
| 8883 |
|
| 8884 |
Stmt := First (Statements (Handled_Statement_Sequence (Stmt))); |
| 8885 |
while Present (Stmt) loop |
| 8886 |
if Nkind (Stmt) = N_Loop_Statement then |
| 8887 |
return Stmt; |
| 8888 |
end if; |
| 8889 |
|
| 8890 |
Next (Stmt); |
| 8891 |
end loop; |
| 8892 |
|
| 8893 |
-- The expansion of attribute 'Loop_Entry produced a malformed block |
| 8894 |
|
| 8895 |
raise Program_Error; |
| 8896 |
end Find_Loop_In_Conditional_Block; |
| 8897 |
|
| 8898 |
-------------------------- |
| 8899 |
-- Find_Overlaid_Entity -- |
| 8900 |
-------------------------- |
| 8901 |
|
| 8902 |
procedure Find_Overlaid_Entity |
| 8903 |
(N : Node_Id; |
| 8904 |
Ent : out Entity_Id; |
| 8905 |
Off : out Boolean) |
| 8906 |
is |
| 8907 |
pragma Assert |
| 8908 |
(Nkind (N) = N_Attribute_Definition_Clause |
| 8909 |
and then Chars (N) = Name_Address); |
| 8910 |
|
| 8911 |
Expr : Node_Id; |
| 8912 |
|
| 8913 |
begin |
| 8914 |
-- We are looking for one of the two following forms: |
| 8915 |
|
| 8916 |
-- for X'Address use Y'Address |
| 8917 |
|
| 8918 |
-- or |
| 8919 |
|
| 8920 |
-- Const : constant Address := expr; |
| 8921 |
-- ... |
| 8922 |
-- for X'Address use Const; |
| 8923 |
|
| 8924 |
-- In the second case, the expr is either Y'Address, or recursively a |
| 8925 |
-- constant that eventually references Y'Address. |
| 8926 |
|
| 8927 |
Ent := Empty; |
| 8928 |
Off := False; |
| 8929 |
|
| 8930 |
Expr := Expression (N); |
| 8931 |
|
| 8932 |
-- This loop checks the form of the expression for Y'Address, using |
| 8933 |
-- recursion to deal with intermediate constants. |
| 8934 |
|
| 8935 |
loop |
| 8936 |
-- Check for Y'Address |
| 8937 |
|
| 8938 |
if Nkind (Expr) = N_Attribute_Reference |
| 8939 |
and then Attribute_Name (Expr) = Name_Address |
| 8940 |
then |
| 8941 |
Expr := Prefix (Expr); |
| 8942 |
exit; |
| 8943 |
|
| 8944 |
-- Check for Const where Const is a constant entity |
| 8945 |
|
| 8946 |
elsif Is_Entity_Name (Expr) |
| 8947 |
and then Ekind (Entity (Expr)) = E_Constant |
| 8948 |
then |
| 8949 |
Expr := Constant_Value (Entity (Expr)); |
| 8950 |
|
| 8951 |
-- Anything else does not need checking |
| 8952 |
|
| 8953 |
else |
| 8954 |
return; |
| 8955 |
end if; |
| 8956 |
end loop; |
| 8957 |
|
| 8958 |
-- This loop checks the form of the prefix for an entity, using |
| 8959 |
-- recursion to deal with intermediate components. |
| 8960 |
|
| 8961 |
loop |
| 8962 |
-- Check for Y where Y is an entity |
| 8963 |
|
| 8964 |
if Is_Entity_Name (Expr) then |
| 8965 |
Ent := Entity (Expr); |
| 8966 |
|
| 8967 |
-- If expansion is disabled, then we might see an entity of a |
| 8968 |
-- protected component or of a discriminant of a concurrent unit. |
| 8969 |
-- Ignore such entities, because further warnings for overlays |
| 8970 |
-- expect this routine to only collect entities of entire objects. |
| 8971 |
|
| 8972 |
if Ekind (Ent) in E_Component | E_Discriminant then |
| 8973 |
pragma Assert |
| 8974 |
(not Expander_Active |
| 8975 |
and then Is_Concurrent_Type (Scope (Ent))); |
| 8976 |
Ent := Empty; |
| 8977 |
end if; |
| 8978 |
return; |
| 8979 |
|
| 8980 |
-- Check for components |
| 8981 |
|
| 8982 |
elsif Nkind (Expr) in N_Selected_Component | N_Indexed_Component then |
| 8983 |
Expr := Prefix (Expr); |
| 8984 |
Off := True; |
| 8985 |
|
| 8986 |
-- Anything else does not need checking |
| 8987 |
|
| 8988 |
else |
| 8989 |
return; |
| 8990 |
end if; |
| 8991 |
end loop; |
| 8992 |
end Find_Overlaid_Entity; |
| 8993 |
|
| 8994 |
------------------------- |
| 8995 |
-- Find_Parameter_Type -- |
| 8996 |
------------------------- |
| 8997 |
|
| 8998 |
function Find_Parameter_Type (Param : Node_Id) return Entity_Id is |
| 8999 |
begin |
| 9000 |
if Nkind (Param) /= N_Parameter_Specification then |
| 9001 |
return Empty; |
| 9002 |
|
| 9003 |
-- For an access parameter, obtain the type from the formal entity |
| 9004 |
-- itself, because access to subprogram nodes do not carry a type. |
| 9005 |
-- Shouldn't we always use the formal entity ??? |
| 9006 |
|
| 9007 |
elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then |
| 9008 |
return Etype (Defining_Identifier (Param)); |
| 9009 |
|
| 9010 |
else |
| 9011 |
return Etype (Parameter_Type (Param)); |
| 9012 |
end if; |
| 9013 |
end Find_Parameter_Type; |
| 9014 |
|
| 9015 |
----------------------------------- |
| 9016 |
-- Find_Placement_In_State_Space -- |
| 9017 |
----------------------------------- |
| 9018 |
|
| 9019 |
procedure Find_Placement_In_State_Space |
| 9020 |
(Item_Id : Entity_Id; |
| 9021 |
Placement : out State_Space_Kind; |
| 9022 |
Pack_Id : out Entity_Id) |
| 9023 |
is |
| 9024 |
function Inside_Package_Body (Id : Entity_Id) return Boolean; |
| 9025 |
function Inside_Private_Part (Id : Entity_Id) return Boolean; |
| 9026 |
-- Return True if Id is declared directly within the package body |
| 9027 |
-- and the package private parts, respectively. We cannot use |
| 9028 |
-- In_Private_Part/In_Body_Part flags, as these are only set during the |
| 9029 |
-- analysis of the package itself, while Find_Placement_In_State_Space |
| 9030 |
-- can be called on an entity of another package. |
| 9031 |
|
| 9032 |
------------------------ |
| 9033 |
-- Inside_Package_Body -- |
| 9034 |
------------------------ |
| 9035 |
|
| 9036 |
function Inside_Package_Body (Id : Entity_Id) return Boolean is |
| 9037 |
Spec_Id : constant Entity_Id := Scope (Id); |
| 9038 |
Body_Decl : constant Opt_N_Package_Body_Id := Package_Body (Spec_Id); |
| 9039 |
Decl : constant Node_Id := Enclosing_Declaration (Id); |
| 9040 |
begin |
| 9041 |
if Present (Body_Decl) |
| 9042 |
and then Is_List_Member (Decl) |
| 9043 |
and then List_Containing (Decl) = Declarations (Body_Decl) |
| 9044 |
then |
| 9045 |
return True; |
| 9046 |
else |
| 9047 |
return False; |
| 9048 |
end if; |
| 9049 |
end Inside_Package_Body; |
| 9050 |
|
| 9051 |
------------------------- |
| 9052 |
-- Inside_Private_Part -- |
| 9053 |
------------------------- |
| 9054 |
|
| 9055 |
function Inside_Private_Part (Id : Entity_Id) return Boolean is |
| 9056 |
Spec_Id : constant Entity_Id := Scope (Id); |
| 9057 |
Private_Decls : constant List_Id := |
| 9058 |
Private_Declarations (Package_Specification (Spec_Id)); |
| 9059 |
Decl : constant Node_Id := Enclosing_Declaration (Id); |
| 9060 |
begin |
| 9061 |
if Is_List_Member (Decl) |
| 9062 |
and then List_Containing (Decl) = Private_Decls |
| 9063 |
then |
| 9064 |
return True; |
| 9065 |
|
| 9066 |
elsif Ekind (Id) = E_Package |
| 9067 |
and then Is_Private_Library_Unit (Id) |
| 9068 |
then |
| 9069 |
return True; |
| 9070 |
|
| 9071 |
else |
| 9072 |
return False; |
| 9073 |
end if; |
| 9074 |
end Inside_Private_Part; |
| 9075 |
|
| 9076 |
-- Local variables |
| 9077 |
|
| 9078 |
Context : Entity_Id; |
| 9079 |
|
| 9080 |
-- Start of processing for Find_Placement_In_State_Space |
| 9081 |
|
| 9082 |
begin |
| 9083 |
-- Assume that the item does not appear in the state space of a package |
| 9084 |
|
| 9085 |
Placement := Not_In_Package; |
| 9086 |
|
| 9087 |
-- Climb the scope stack and examine the enclosing context |
| 9088 |
|
| 9089 |
Context := Item_Id; |
| 9090 |
Pack_Id := Scope (Context); |
| 9091 |
while Present (Pack_Id) and then Pack_Id /= Standard_Standard loop |
| 9092 |
if Is_Package_Or_Generic_Package (Pack_Id) then |
| 9093 |
|
| 9094 |
-- A package body is a cut off point for the traversal as the |
| 9095 |
-- item cannot be visible to the outside from this point on. |
| 9096 |
|
| 9097 |
if Inside_Package_Body (Context) then |
| 9098 |
Placement := Body_State_Space; |
| 9099 |
return; |
| 9100 |
|
| 9101 |
-- The private part of a package is a cut off point for the |
| 9102 |
-- traversal as the item cannot be visible to the outside |
| 9103 |
-- from this point on. |
| 9104 |
|
| 9105 |
elsif Inside_Private_Part (Context) then |
| 9106 |
Placement := Private_State_Space; |
| 9107 |
return; |
| 9108 |
|
| 9109 |
-- The item or its enclosing package appear in the visible state |
| 9110 |
-- space of a generic package. |
| 9111 |
|
| 9112 |
elsif Ekind (Pack_Id) = E_Generic_Package then |
| 9113 |
Placement := Not_In_Package; |
| 9114 |
Pack_Id := Empty; |
| 9115 |
return; |
| 9116 |
|
| 9117 |
-- When the item appears in the visible state space of a package, |
| 9118 |
-- continue to climb the scope stack as this may not be the final |
| 9119 |
-- state space. |
| 9120 |
|
| 9121 |
else |
| 9122 |
Placement := Visible_State_Space; |
| 9123 |
|
| 9124 |
-- The visible state space of a child unit acts as the proper |
| 9125 |
-- placement of an item, unless this is a private child unit. |
| 9126 |
|
| 9127 |
if Is_Child_Unit (Pack_Id) |
| 9128 |
and then not Is_Private_Library_Unit (Pack_Id) |
| 9129 |
then |
| 9130 |
return; |
| 9131 |
end if; |
| 9132 |
end if; |
| 9133 |
|
| 9134 |
-- The item or its enclosing package appear in a construct that has |
| 9135 |
-- no state space. |
| 9136 |
|
| 9137 |
else |
| 9138 |
Placement := Not_In_Package; |
| 9139 |
Pack_Id := Empty; |
| 9140 |
return; |
| 9141 |
end if; |
| 9142 |
|
| 9143 |
Context := Scope (Context); |
| 9144 |
Pack_Id := Scope (Context); |
| 9145 |
end loop; |
| 9146 |
end Find_Placement_In_State_Space; |
| 9147 |
|
| 9148 |
----------------------- |
| 9149 |
-- Find_Primitive_Eq -- |
| 9150 |
----------------------- |
| 9151 |
|
| 9152 |
function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is |
| 9153 |
function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id; |
| 9154 |
-- Search for the equality primitive; return Empty if the primitive is |
| 9155 |
-- not found. |
| 9156 |
|
| 9157 |
------------------ |
| 9158 |
-- Find_Eq_Prim -- |
| 9159 |
------------------ |
| 9160 |
|
| 9161 |
function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is |
| 9162 |
Prim : Entity_Id; |
| 9163 |
Prim_Elmt : Elmt_Id; |
| 9164 |
|
| 9165 |
begin |
| 9166 |
Prim_Elmt := First_Elmt (Prims_List); |
| 9167 |
while Present (Prim_Elmt) loop |
| 9168 |
Prim := Node (Prim_Elmt); |
| 9169 |
|
| 9170 |
-- Locate primitive equality with the right signature |
| 9171 |
|
| 9172 |
if Chars (Prim) = Name_Op_Eq |
| 9173 |
and then Etype (First_Formal (Prim)) = |
| 9174 |
Etype (Next_Formal (First_Formal (Prim))) |
| 9175 |
and then Base_Type (Etype (Prim)) = Standard_Boolean |
| 9176 |
then |
| 9177 |
return Prim; |
| 9178 |
end if; |
| 9179 |
|
| 9180 |
Next_Elmt (Prim_Elmt); |
| 9181 |
end loop; |
| 9182 |
|
| 9183 |
return Empty; |
| 9184 |
end Find_Eq_Prim; |
| 9185 |
|
| 9186 |
-- Local Variables |
| 9187 |
|
| 9188 |
Eq_Prim : Entity_Id; |
| 9189 |
Full_Type : Entity_Id; |
| 9190 |
|
| 9191 |
-- Start of processing for Find_Primitive_Eq |
| 9192 |
|
| 9193 |
begin |
| 9194 |
if Is_Private_Type (Typ) then |
| 9195 |
Full_Type := Underlying_Type (Typ); |
| 9196 |
else |
| 9197 |
Full_Type := Typ; |
| 9198 |
end if; |
| 9199 |
|
| 9200 |
if No (Full_Type) then |
| 9201 |
return Empty; |
| 9202 |
end if; |
| 9203 |
|
| 9204 |
Full_Type := Base_Type (Full_Type); |
| 9205 |
|
| 9206 |
-- When the base type itself is private, use the full view |
| 9207 |
|
| 9208 |
if Is_Private_Type (Full_Type) then |
| 9209 |
Full_Type := Underlying_Type (Full_Type); |
| 9210 |
end if; |
| 9211 |
|
| 9212 |
if Is_Class_Wide_Type (Full_Type) then |
| 9213 |
Full_Type := Root_Type (Full_Type); |
| 9214 |
end if; |
| 9215 |
|
| 9216 |
if not Is_Tagged_Type (Full_Type) then |
| 9217 |
Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ)); |
| 9218 |
|
| 9219 |
-- If this is an untagged private type completed with a derivation of |
| 9220 |
-- an untagged private type whose full view is a tagged type, we use |
| 9221 |
-- the primitive operations of the private parent type (since it does |
| 9222 |
-- not have a full view, and also because its equality primitive may |
| 9223 |
-- have been overridden in its untagged full view). If no equality was |
| 9224 |
-- defined for it then take its dispatching equality primitive. |
| 9225 |
|
| 9226 |
elsif Inherits_From_Tagged_Full_View (Typ) then |
| 9227 |
Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ)); |
| 9228 |
|
| 9229 |
if No (Eq_Prim) then |
| 9230 |
Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type)); |
| 9231 |
end if; |
| 9232 |
|
| 9233 |
else |
| 9234 |
Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type)); |
| 9235 |
end if; |
| 9236 |
|
| 9237 |
return Eq_Prim; |
| 9238 |
end Find_Primitive_Eq; |
| 9239 |
|
| 9240 |
------------------------ |
| 9241 |
-- Find_Specific_Type -- |
| 9242 |
------------------------ |
| 9243 |
|
| 9244 |
function Find_Specific_Type (CW : Entity_Id) return Entity_Id is |
| 9245 |
Typ : Entity_Id := Root_Type (CW); |
| 9246 |
|
| 9247 |
begin |
| 9248 |
if Ekind (Typ) = E_Incomplete_Type then |
| 9249 |
if From_Limited_With (Typ) then |
| 9250 |
Typ := Non_Limited_View (Typ); |
| 9251 |
else |
| 9252 |
Typ := Full_View (Typ); |
| 9253 |
end if; |
| 9254 |
end if; |
| 9255 |
|
| 9256 |
if Is_Private_Type (Typ) |
| 9257 |
and then not Is_Tagged_Type (Typ) |
| 9258 |
and then Present (Full_View (Typ)) |
| 9259 |
then |
| 9260 |
return Full_View (Typ); |
| 9261 |
else |
| 9262 |
return Typ; |
| 9263 |
end if; |
| 9264 |
end Find_Specific_Type; |
| 9265 |
|
| 9266 |
----------------------------- |
| 9267 |
-- Find_Static_Alternative -- |
| 9268 |
----------------------------- |
| 9269 |
|
| 9270 |
function Find_Static_Alternative (N : Node_Id) return Node_Id is |
| 9271 |
Expr : constant Node_Id := Expression (N); |
| 9272 |
Val : constant Uint := Expr_Value (Expr); |
| 9273 |
Alt : Node_Id; |
| 9274 |
Choice : Node_Id; |
| 9275 |
|
| 9276 |
begin |
| 9277 |
Alt := First (Alternatives (N)); |
| 9278 |
|
| 9279 |
Search : loop |
| 9280 |
if Nkind (Alt) /= N_Pragma then |
| 9281 |
Choice := First (Discrete_Choices (Alt)); |
| 9282 |
while Present (Choice) loop |
| 9283 |
|
| 9284 |
-- Others choice, always matches |
| 9285 |
|
| 9286 |
if Nkind (Choice) = N_Others_Choice then |
| 9287 |
exit Search; |
| 9288 |
|
| 9289 |
-- Range, check if value is in the range |
| 9290 |
|
| 9291 |
elsif Nkind (Choice) = N_Range then |
| 9292 |
exit Search when |
| 9293 |
Val >= Expr_Value (Low_Bound (Choice)) |
| 9294 |
and then |
| 9295 |
Val <= Expr_Value (High_Bound (Choice)); |
| 9296 |
|
| 9297 |
-- Choice is a subtype name. Note that we know it must |
| 9298 |
-- be a static subtype, since otherwise it would have |
| 9299 |
-- been diagnosed as illegal. |
| 9300 |
|
| 9301 |
elsif Is_Entity_Name (Choice) |
| 9302 |
and then Is_Type (Entity (Choice)) |
| 9303 |
then |
| 9304 |
exit Search when Is_In_Range (Expr, Etype (Choice), |
| 9305 |
Assume_Valid => False); |
| 9306 |
|
| 9307 |
-- Choice is a subtype indication |
| 9308 |
|
| 9309 |
elsif Nkind (Choice) = N_Subtype_Indication then |
| 9310 |
declare |
| 9311 |
C : constant Node_Id := Constraint (Choice); |
| 9312 |
R : constant Node_Id := Range_Expression (C); |
| 9313 |
|
| 9314 |
begin |
| 9315 |
exit Search when |
| 9316 |
Val >= Expr_Value (Low_Bound (R)) |
| 9317 |
and then |
| 9318 |
Val <= Expr_Value (High_Bound (R)); |
| 9319 |
end; |
| 9320 |
|
| 9321 |
-- Choice is a simple expression |
| 9322 |
|
| 9323 |
else |
| 9324 |
exit Search when Val = Expr_Value (Choice); |
| 9325 |
end if; |
| 9326 |
|
| 9327 |
Next (Choice); |
| 9328 |
end loop; |
| 9329 |
end if; |
| 9330 |
|
| 9331 |
Next (Alt); |
| 9332 |
pragma Assert (Present (Alt)); |
| 9333 |
end loop Search; |
| 9334 |
|
| 9335 |
-- The above loop *must* terminate by finding a match, since we know the |
| 9336 |
-- case statement is valid, and the value of the expression is known at |
| 9337 |
-- compile time. When we fall out of the loop, Alt points to the |
| 9338 |
-- alternative that we know will be selected at run time. |
| 9339 |
|
| 9340 |
return Alt; |
| 9341 |
end Find_Static_Alternative; |
| 9342 |
|
| 9343 |
------------------ |
| 9344 |
-- First_Actual -- |
| 9345 |
------------------ |
| 9346 |
|
| 9347 |
function First_Actual (Node : Node_Id) return Node_Id is |
| 9348 |
N : Node_Id; |
| 9349 |
|
| 9350 |
begin |
| 9351 |
if No (Parameter_Associations (Node)) then |
| 9352 |
return Empty; |
| 9353 |
end if; |
| 9354 |
|
| 9355 |
N := First (Parameter_Associations (Node)); |
| 9356 |
|
| 9357 |
if Nkind (N) = N_Parameter_Association then |
| 9358 |
return First_Named_Actual (Node); |
| 9359 |
else |
| 9360 |
return N; |
| 9361 |
end if; |
| 9362 |
end First_Actual; |
| 9363 |
|
| 9364 |
------------------ |
| 9365 |
-- First_Global -- |
| 9366 |
------------------ |
| 9367 |
|
| 9368 |
function First_Global |
| 9369 |
(Subp : Entity_Id; |
| 9370 |
Global_Mode : Name_Id; |
| 9371 |
Refined : Boolean := False) return Node_Id |
| 9372 |
is |
| 9373 |
function First_From_Global_List |
| 9374 |
(List : Node_Id; |
| 9375 |
Global_Mode : Name_Id := Name_Input) return Entity_Id; |
| 9376 |
-- Get the first item with suitable mode from List |
| 9377 |
|
| 9378 |
---------------------------- |
| 9379 |
-- First_From_Global_List -- |
| 9380 |
---------------------------- |
| 9381 |
|
| 9382 |
function First_From_Global_List |
| 9383 |
(List : Node_Id; |
| 9384 |
Global_Mode : Name_Id := Name_Input) return Entity_Id |
| 9385 |
is |
| 9386 |
Assoc : Node_Id; |
| 9387 |
|
| 9388 |
begin |
| 9389 |
-- Empty list (no global items) |
| 9390 |
|
| 9391 |
if Nkind (List) = N_Null then |
| 9392 |
return Empty; |
| 9393 |
|
| 9394 |
-- Single global item declaration (only input items) |
| 9395 |
|
| 9396 |
elsif Nkind (List) in N_Expanded_Name | N_Identifier then |
| 9397 |
if Global_Mode = Name_Input then |
| 9398 |
return List; |
| 9399 |
else |
| 9400 |
return Empty; |
| 9401 |
end if; |
| 9402 |
|
| 9403 |
-- Simple global list (only input items) or moded global list |
| 9404 |
-- declaration. |
| 9405 |
|
| 9406 |
elsif Nkind (List) = N_Aggregate then |
| 9407 |
if Present (Expressions (List)) then |
| 9408 |
if Global_Mode = Name_Input then |
| 9409 |
return First (Expressions (List)); |
| 9410 |
else |
| 9411 |
return Empty; |
| 9412 |
end if; |
| 9413 |
|
| 9414 |
else |
| 9415 |
Assoc := First (Component_Associations (List)); |
| 9416 |
while Present (Assoc) loop |
| 9417 |
|
| 9418 |
-- When we find the desired mode in an association, call |
| 9419 |
-- recursively First_From_Global_List as if the mode was |
| 9420 |
-- Name_Input, in order to reuse the existing machinery |
| 9421 |
-- for the other cases. |
| 9422 |
|
| 9423 |
if Chars (First (Choices (Assoc))) = Global_Mode then |
| 9424 |
return First_From_Global_List (Expression (Assoc)); |
| 9425 |
end if; |
| 9426 |
|
| 9427 |
Next (Assoc); |
| 9428 |
end loop; |
| 9429 |
|
| 9430 |
return Empty; |
| 9431 |
end if; |
| 9432 |
|
| 9433 |
-- To accommodate partial decoration of disabled SPARK features, |
| 9434 |
-- this routine may be called with illegal input. If this is the |
| 9435 |
-- case, do not raise Program_Error. |
| 9436 |
|
| 9437 |
else |
| 9438 |
return Empty; |
| 9439 |
end if; |
| 9440 |
end First_From_Global_List; |
| 9441 |
|
| 9442 |
-- Local variables |
| 9443 |
|
| 9444 |
Global : Node_Id := Empty; |
| 9445 |
Body_Id : Entity_Id; |
| 9446 |
|
| 9447 |
-- Start of processing for First_Global |
| 9448 |
|
| 9449 |
begin |
| 9450 |
pragma Assert (Global_Mode in Name_In_Out |
| 9451 |
| Name_Input |
| 9452 |
| Name_Output |
| 9453 |
| Name_Proof_In); |
| 9454 |
|
| 9455 |
-- Retrieve the suitable pragma Global or Refined_Global. In the second |
| 9456 |
-- case, it can only be located on the body entity. |
| 9457 |
|
| 9458 |
if Refined then |
| 9459 |
if Is_Subprogram_Or_Generic_Subprogram (Subp) then |
| 9460 |
Body_Id := Subprogram_Body_Entity (Subp); |
| 9461 |
|
| 9462 |
elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then |
| 9463 |
Body_Id := Corresponding_Body (Parent (Subp)); |
| 9464 |
|
| 9465 |
-- ??? It should be possible to retrieve the Refined_Global on the |
| 9466 |
-- task body associated to the task object. This is not yet possible. |
| 9467 |
|
| 9468 |
elsif Is_Single_Task_Object (Subp) then |
| 9469 |
Body_Id := Empty; |
| 9470 |
|
| 9471 |
else |
| 9472 |
Body_Id := Empty; |
| 9473 |
end if; |
| 9474 |
|
| 9475 |
if Present (Body_Id) then |
| 9476 |
Global := Get_Pragma (Body_Id, Pragma_Refined_Global); |
| 9477 |
end if; |
| 9478 |
else |
| 9479 |
Global := Get_Pragma (Subp, Pragma_Global); |
| 9480 |
end if; |
| 9481 |
|
| 9482 |
-- No corresponding global if pragma is not present |
| 9483 |
|
| 9484 |
if No (Global) then |
| 9485 |
return Empty; |
| 9486 |
|
| 9487 |
-- Otherwise retrieve the corresponding list of items depending on the |
| 9488 |
-- Global_Mode. |
| 9489 |
|
| 9490 |
else |
| 9491 |
return First_From_Global_List |
| 9492 |
(Expression (Get_Argument (Global, Subp)), Global_Mode); |
| 9493 |
end if; |
| 9494 |
end First_Global; |
| 9495 |
|
| 9496 |
------------- |
| 9497 |
-- Fix_Msg -- |
| 9498 |
------------- |
| 9499 |
|
| 9500 |
function Fix_Msg (Id : Entity_Id; Msg : String) return String is |
| 9501 |
Is_Task : constant Boolean := |
| 9502 |
Ekind (Id) in E_Task_Body | E_Task_Type |
| 9503 |
or else Is_Single_Task_Object (Id); |
| 9504 |
Msg_Last : constant Natural := Msg'Last; |
| 9505 |
Msg_Index : Natural; |
| 9506 |
Res : String (Msg'Range) := (others => ' '); |
| 9507 |
Res_Index : Natural; |
| 9508 |
|
| 9509 |
begin |
| 9510 |
-- Copy all characters from the input message Msg to result Res with |
| 9511 |
-- suitable replacements. |
| 9512 |
|
| 9513 |
Msg_Index := Msg'First; |
| 9514 |
Res_Index := Res'First; |
| 9515 |
while Msg_Index <= Msg_Last loop |
| 9516 |
|
| 9517 |
-- Replace "subprogram" with a different word |
| 9518 |
|
| 9519 |
if Msg_Index <= Msg_Last - 10 |
| 9520 |
and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram" |
| 9521 |
then |
| 9522 |
if Is_Entry (Id) then |
| 9523 |
Res (Res_Index .. Res_Index + 4) := "entry"; |
| 9524 |
Res_Index := Res_Index + 5; |
| 9525 |
|
| 9526 |
elsif Is_Task then |
| 9527 |
Res (Res_Index .. Res_Index + 8) := "task type"; |
| 9528 |
Res_Index := Res_Index + 9; |
| 9529 |
|
| 9530 |
else |
| 9531 |
Res (Res_Index .. Res_Index + 9) := "subprogram"; |
| 9532 |
Res_Index := Res_Index + 10; |
| 9533 |
end if; |
| 9534 |
|
| 9535 |
Msg_Index := Msg_Index + 10; |
| 9536 |
|
| 9537 |
-- Replace "protected" with a different word |
| 9538 |
|
| 9539 |
elsif Msg_Index <= Msg_Last - 9 |
| 9540 |
and then Msg (Msg_Index .. Msg_Index + 8) = "protected" |
| 9541 |
and then Is_Task |
| 9542 |
then |
| 9543 |
Res (Res_Index .. Res_Index + 3) := "task"; |
| 9544 |
Res_Index := Res_Index + 4; |
| 9545 |
Msg_Index := Msg_Index + 9; |
| 9546 |
|
| 9547 |
-- Otherwise copy the character |
| 9548 |
|
| 9549 |
else |
| 9550 |
Res (Res_Index) := Msg (Msg_Index); |
| 9551 |
Msg_Index := Msg_Index + 1; |
| 9552 |
Res_Index := Res_Index + 1; |
| 9553 |
end if; |
| 9554 |
end loop; |
| 9555 |
|
| 9556 |
return Res (Res'First .. Res_Index - 1); |
| 9557 |
end Fix_Msg; |
| 9558 |
|
| 9559 |
------------------------- |
| 9560 |
-- From_Nested_Package -- |
| 9561 |
------------------------- |
| 9562 |
|
| 9563 |
function From_Nested_Package (T : Entity_Id) return Boolean is |
| 9564 |
Pack : constant Entity_Id := Scope (T); |
| 9565 |
|
| 9566 |
begin |
| 9567 |
return |
| 9568 |
Ekind (Pack) = E_Package |
| 9569 |
and then not Is_Frozen (Pack) |
| 9570 |
and then not In_Open_Scopes (Pack) |
| 9571 |
and then In_Open_Scopes (Scope (Pack)); |
| 9572 |
end From_Nested_Package; |
| 9573 |
|
| 9574 |
----------------------- |
| 9575 |
-- Gather_Components -- |
| 9576 |
----------------------- |
| 9577 |
|
| 9578 |
procedure Gather_Components |
| 9579 |
(Typ : Entity_Id; |
| 9580 |
Comp_List : Node_Id; |
| 9581 |
Governed_By : List_Id; |
| 9582 |
Into : Elist_Id; |
| 9583 |
Report_Errors : out Boolean; |
| 9584 |
Allow_Compile_Time : Boolean := False; |
| 9585 |
Include_Interface_Tag : Boolean := False) |
| 9586 |
is |
| 9587 |
Assoc : Node_Id; |
| 9588 |
Variant : Node_Id; |
| 9589 |
Discrete_Choice : Node_Id; |
| 9590 |
Comp_Item : Node_Id; |
| 9591 |
Discrim : Entity_Id; |
| 9592 |
Discrim_Name : Node_Id; |
| 9593 |
|
| 9594 |
type Discriminant_Value_Status is |
| 9595 |
(Static_Expr, Static_Subtype, Bad); |
| 9596 |
subtype Good_Discrim_Value_Status is Discriminant_Value_Status |
| 9597 |
range Static_Expr .. Static_Subtype; -- range excludes Bad |
| 9598 |
|
| 9599 |
Discrim_Value : Node_Id; |
| 9600 |
Discrim_Value_Subtype : Node_Id; |
| 9601 |
Discrim_Value_Status : Discriminant_Value_Status := Bad; |
| 9602 |
|
| 9603 |
function OK_Scope_For_Discrim_Value_Error_Messages return Boolean is |
| 9604 |
(Scope (Original_Record_Component |
| 9605 |
(Entity (First (Choices (Assoc))))) = Typ); |
| 9606 |
-- Used to avoid generating error messages having a source position |
| 9607 |
-- which refers to somewhere (e.g., a discriminant value in a derived |
| 9608 |
-- tagged type declaration) unrelated to the offending construct. This |
| 9609 |
-- is required for correctness - clients of Gather_Components such as |
| 9610 |
-- Sem_Ch3.Create_Constrained_Components depend on this function |
| 9611 |
-- returning True while processing semantically correct examples; |
| 9612 |
-- generating an error message in this case would be wrong. |
| 9613 |
|
| 9614 |
begin |
| 9615 |
Report_Errors := False; |
| 9616 |
|
| 9617 |
if No (Comp_List) or else Null_Present (Comp_List) then |
| 9618 |
return; |
| 9619 |
end if; |
| 9620 |
|
| 9621 |
Comp_Item := First (Component_Items (Comp_List)); |
| 9622 |
while Present (Comp_Item) loop |
| 9623 |
|
| 9624 |
-- Skip the tag of a tagged record, as well as all items that are not |
| 9625 |
-- user components (anonymous types, rep clauses, Parent field, |
| 9626 |
-- controller field). |
| 9627 |
|
| 9628 |
if Nkind (Comp_Item) = N_Component_Declaration then |
| 9629 |
declare |
| 9630 |
Comp : constant Entity_Id := Defining_Identifier (Comp_Item); |
| 9631 |
begin |
| 9632 |
if not (Is_Tag (Comp) |
| 9633 |
and then not |
| 9634 |
(Include_Interface_Tag |
| 9635 |
and then Etype (Comp) = RTE (RE_Interface_Tag))) |
| 9636 |
and then Chars (Comp) /= Name_uParent |
| 9637 |
then |
| 9638 |
Append_Elmt (Comp, Into); |
| 9639 |
end if; |
| 9640 |
end; |
| 9641 |
end if; |
| 9642 |
|
| 9643 |
Next (Comp_Item); |
| 9644 |
end loop; |
| 9645 |
|
| 9646 |
if No (Variant_Part (Comp_List)) then |
| 9647 |
return; |
| 9648 |
else |
| 9649 |
Discrim_Name := Name (Variant_Part (Comp_List)); |
| 9650 |
Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List))); |
| 9651 |
end if; |
| 9652 |
|
| 9653 |
-- Look for the discriminant that governs this variant part. |
| 9654 |
-- The discriminant *must* be in the Governed_By List |
| 9655 |
|
| 9656 |
Assoc := First (Governed_By); |
| 9657 |
Find_Constraint : loop |
| 9658 |
Discrim := First (Choices (Assoc)); |
| 9659 |
pragma Assert (No (Next (Discrim))); |
| 9660 |
|
| 9661 |
exit Find_Constraint when |
| 9662 |
Chars (Discrim_Name) = Chars (Discrim) |
| 9663 |
or else |
| 9664 |
(Present (Corresponding_Discriminant (Entity (Discrim))) |
| 9665 |
and then Chars (Corresponding_Discriminant |
| 9666 |
(Entity (Discrim))) = Chars (Discrim_Name)) |
| 9667 |
or else |
| 9668 |
Chars (Original_Record_Component (Entity (Discrim))) = |
| 9669 |
Chars (Discrim_Name); |
| 9670 |
|
| 9671 |
if No (Next (Assoc)) then |
| 9672 |
if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then |
| 9673 |
|
| 9674 |
-- If the type is a tagged type with inherited discriminants, |
| 9675 |
-- use the stored constraint on the parent in order to find |
| 9676 |
-- the values of discriminants that are otherwise hidden by an |
| 9677 |
-- explicit constraint. Renamed discriminants are handled in |
| 9678 |
-- the code above. |
| 9679 |
|
| 9680 |
-- If several parent discriminants are renamed by a single |
| 9681 |
-- discriminant of the derived type, the call to obtain the |
| 9682 |
-- Corresponding_Discriminant field only retrieves the last |
| 9683 |
-- of them. We recover the constraint on the others from the |
| 9684 |
-- Stored_Constraint as well. |
| 9685 |
|
| 9686 |
-- An inherited discriminant may have been constrained in a |
| 9687 |
-- later ancestor (not the immediate parent) so we must examine |
| 9688 |
-- the stored constraint of all of them to locate the inherited |
| 9689 |
-- value. |
| 9690 |
|
| 9691 |
declare |
| 9692 |
C : Elmt_Id; |
| 9693 |
D : Entity_Id; |
| 9694 |
T : Entity_Id := Typ; |
| 9695 |
|
| 9696 |
begin |
| 9697 |
while Is_Derived_Type (T) loop |
| 9698 |
if Present (Stored_Constraint (T)) then |
| 9699 |
D := First_Discriminant (Etype (T)); |
| 9700 |
C := First_Elmt (Stored_Constraint (T)); |
| 9701 |
while Present (D) and then Present (C) loop |
| 9702 |
if Chars (Discrim_Name) = Chars (D) then |
| 9703 |
if Is_Entity_Name (Node (C)) |
| 9704 |
and then Entity (Node (C)) = Entity (Discrim) |
| 9705 |
then |
| 9706 |
-- D is renamed by Discrim, whose value is |
| 9707 |
-- given in Assoc. |
| 9708 |
|
| 9709 |
null; |
| 9710 |
|
| 9711 |
else |
| 9712 |
Assoc := |
| 9713 |
Make_Component_Association (Sloc (Typ), |
| 9714 |
New_List |
| 9715 |
(New_Occurrence_Of (D, Sloc (Typ))), |
| 9716 |
Duplicate_Subexpr_No_Checks (Node (C))); |
| 9717 |
end if; |
| 9718 |
|
| 9719 |
exit Find_Constraint; |
| 9720 |
end if; |
| 9721 |
|
| 9722 |
Next_Discriminant (D); |
| 9723 |
Next_Elmt (C); |
| 9724 |
end loop; |
| 9725 |
end if; |
| 9726 |
|
| 9727 |
-- Discriminant may be inherited from ancestor |
| 9728 |
|
| 9729 |
T := Etype (T); |
| 9730 |
end loop; |
| 9731 |
end; |
| 9732 |
end if; |
| 9733 |
end if; |
| 9734 |
|
| 9735 |
Next (Assoc); |
| 9736 |
|
| 9737 |
if No (Assoc) then |
| 9738 |
Error_Msg_NE |
| 9739 |
("missing value for discriminant&", |
| 9740 |
First (Governed_By), Discrim_Name); |
| 9741 |
|
| 9742 |
Report_Errors := True; |
| 9743 |
return; |
| 9744 |
end if; |
| 9745 |
end loop Find_Constraint; |
| 9746 |
|
| 9747 |
Discrim_Value := Expression (Assoc); |
| 9748 |
|
| 9749 |
if Is_OK_Static_Expression (Discrim_Value) |
| 9750 |
or else (Allow_Compile_Time |
| 9751 |
and then Compile_Time_Known_Value (Discrim_Value)) |
| 9752 |
then |
| 9753 |
Discrim_Value_Status := Static_Expr; |
| 9754 |
else |
| 9755 |
if Ada_Version >= Ada_2022 then |
| 9756 |
if Is_Rewrite_Substitution (Discrim_Value) |
| 9757 |
and then Nkind (Discrim_Value) = N_Type_Conversion |
| 9758 |
and then Etype (Original_Node (Discrim_Value)) |
| 9759 |
= Etype (Expression (Discrim_Value)) |
| 9760 |
then |
| 9761 |
Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value)); |
| 9762 |
-- An unhelpful (for this code) type conversion may be |
| 9763 |
-- introduced in some cases; deal with it. |
| 9764 |
else |
| 9765 |
Discrim_Value_Subtype := Etype (Discrim_Value); |
| 9766 |
end if; |
| 9767 |
|
| 9768 |
if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then |
| 9769 |
not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype), |
| 9770 |
Type_High_Bound (Discrim_Value_Subtype)) |
| 9771 |
then |
| 9772 |
-- Is_Null_Range test doesn't account for predicates, as in |
| 9773 |
-- subtype Null_By_Predicate is Natural |
| 9774 |
-- with Static_Predicate => Null_By_Predicate < 0; |
| 9775 |
-- so test for that null case separately. |
| 9776 |
|
| 9777 |
if not Has_Static_Predicate (Discrim_Value_Subtype) |
| 9778 |
or else Present (First (Static_Discrete_Predicate |
| 9779 |
(Discrim_Value_Subtype))) |
| 9780 |
then |
| 9781 |
Discrim_Value_Status := Static_Subtype; |
| 9782 |
end if; |
| 9783 |
end if; |
| 9784 |
end if; |
| 9785 |
|
| 9786 |
if Discrim_Value_Status = Bad then |
| 9787 |
|
| 9788 |
-- If the variant part is governed by a discriminant of the type |
| 9789 |
-- this is an error. If the variant part and the discriminant are |
| 9790 |
-- inherited from an ancestor this is legal (AI05-220) unless the |
| 9791 |
-- components are being gathered for an aggregate, in which case |
| 9792 |
-- the caller must check Report_Errors. |
| 9793 |
-- |
| 9794 |
-- In Ada 2022 the above rules are relaxed. A nonstatic governing |
| 9795 |
-- discriminant is OK as long as it has a static subtype and |
| 9796 |
-- every value of that subtype (and there must be at least one) |
| 9797 |
-- selects the same variant. |
| 9798 |
|
| 9799 |
if OK_Scope_For_Discrim_Value_Error_Messages then |
| 9800 |
if Ada_Version >= Ada_2022 then |
| 9801 |
Error_Msg_FE |
| 9802 |
("value for discriminant & must be static or " & |
| 9803 |
"discriminant's nominal subtype must be static " & |
| 9804 |
"and non-null!", |
| 9805 |
Discrim_Value, Discrim); |
| 9806 |
else |
| 9807 |
Error_Msg_FE |
| 9808 |
("value for discriminant & must be static!", |
| 9809 |
Discrim_Value, Discrim); |
| 9810 |
end if; |
| 9811 |
Why_Not_Static (Discrim_Value); |
| 9812 |
end if; |
| 9813 |
|
| 9814 |
Report_Errors := True; |
| 9815 |
return; |
| 9816 |
end if; |
| 9817 |
end if; |
| 9818 |
|
| 9819 |
Search_For_Discriminant_Value : declare |
| 9820 |
Low : Node_Id; |
| 9821 |
High : Node_Id; |
| 9822 |
|
| 9823 |
UI_High : Uint; |
| 9824 |
UI_Low : Uint; |
| 9825 |
UI_Discrim_Value : Uint; |
| 9826 |
|
| 9827 |
begin |
| 9828 |
case Good_Discrim_Value_Status'(Discrim_Value_Status) is |
| 9829 |
when Static_Expr => |
| 9830 |
UI_Discrim_Value := Expr_Value (Discrim_Value); |
| 9831 |
when Static_Subtype => |
| 9832 |
-- Arbitrarily pick one value of the subtype and look |
| 9833 |
-- for the variant associated with that value; we will |
| 9834 |
-- check later that the same variant is associated with |
| 9835 |
-- all of the other values of the subtype. |
| 9836 |
if Has_Static_Predicate (Discrim_Value_Subtype) then |
| 9837 |
declare |
| 9838 |
Range_Or_Expr : constant Node_Id := |
| 9839 |
First (Static_Discrete_Predicate |
| 9840 |
(Discrim_Value_Subtype)); |
| 9841 |
begin |
| 9842 |
if Nkind (Range_Or_Expr) = N_Range then |
| 9843 |
UI_Discrim_Value := |
| 9844 |
Expr_Value (Low_Bound (Range_Or_Expr)); |
| 9845 |
else |
| 9846 |
UI_Discrim_Value := Expr_Value (Range_Or_Expr); |
| 9847 |
end if; |
| 9848 |
end; |
| 9849 |
else |
| 9850 |
UI_Discrim_Value := |
| 9851 |
Expr_Value (Type_Low_Bound (Discrim_Value_Subtype)); |
| 9852 |
end if; |
| 9853 |
end case; |
| 9854 |
|
| 9855 |
Find_Discrete_Value : while Present (Variant) loop |
| 9856 |
|
| 9857 |
-- If a choice is a subtype with a static predicate, it must |
| 9858 |
-- be rewritten as an explicit list of non-predicated choices. |
| 9859 |
|
| 9860 |
Expand_Static_Predicates_In_Choices (Variant); |
| 9861 |
|
| 9862 |
Discrete_Choice := First (Discrete_Choices (Variant)); |
| 9863 |
while Present (Discrete_Choice) loop |
| 9864 |
exit Find_Discrete_Value when |
| 9865 |
Nkind (Discrete_Choice) = N_Others_Choice; |
| 9866 |
|
| 9867 |
Get_Index_Bounds (Discrete_Choice, Low, High); |
| 9868 |
|
| 9869 |
UI_Low := Expr_Value (Low); |
| 9870 |
UI_High := Expr_Value (High); |
| 9871 |
|
| 9872 |
exit Find_Discrete_Value when |
| 9873 |
UI_Low <= UI_Discrim_Value |
| 9874 |
and then |
| 9875 |
UI_High >= UI_Discrim_Value; |
| 9876 |
|
| 9877 |
Next (Discrete_Choice); |
| 9878 |
end loop; |
| 9879 |
|
| 9880 |
Next_Non_Pragma (Variant); |
| 9881 |
end loop Find_Discrete_Value; |
| 9882 |
end Search_For_Discriminant_Value; |
| 9883 |
|
| 9884 |
-- The case statement must include a variant that corresponds to the |
| 9885 |
-- value of the discriminant, unless the discriminant type has a |
| 9886 |
-- static predicate. In that case the absence of an others_choice that |
| 9887 |
-- would cover this value becomes a run-time error (3.8.1 (21.1/2)). |
| 9888 |
|
| 9889 |
if No (Variant) |
| 9890 |
and then not Has_Static_Predicate (Etype (Discrim_Name)) |
| 9891 |
then |
| 9892 |
Error_Msg_NE |
| 9893 |
("value of discriminant & is out of range", Discrim_Value, Discrim); |
| 9894 |
Report_Errors := True; |
| 9895 |
return; |
| 9896 |
end if; |
| 9897 |
|
| 9898 |
-- If we have found the corresponding choice, recursively add its |
| 9899 |
-- components to the Into list. The nested components are part of |
| 9900 |
-- the same record type. |
| 9901 |
|
| 9902 |
if Present (Variant) then |
| 9903 |
if Discrim_Value_Status = Static_Subtype then |
| 9904 |
declare |
| 9905 |
Discrim_Value_Subtype_Intervals : |
| 9906 |
constant Interval_Lists.Discrete_Interval_List := |
| 9907 |
Interval_Lists.Type_Intervals (Discrim_Value_Subtype); |
| 9908 |
|
| 9909 |
Variant_Intervals : |
| 9910 |
constant Interval_Lists.Discrete_Interval_List := |
| 9911 |
Interval_Lists.Choice_List_Intervals |
| 9912 |
(Discrete_Choices => Discrete_Choices (Variant)); |
| 9913 |
begin |
| 9914 |
if not Interval_Lists.Is_Subset |
| 9915 |
(Subset => Discrim_Value_Subtype_Intervals, |
| 9916 |
Of_Set => Variant_Intervals) |
| 9917 |
then |
| 9918 |
if OK_Scope_For_Discrim_Value_Error_Messages then |
| 9919 |
Error_Msg_NE |
| 9920 |
("no single variant is associated with all values of " & |
| 9921 |
"the subtype of discriminant value &", |
| 9922 |
Discrim_Value, Discrim); |
| 9923 |
end if; |
| 9924 |
Report_Errors := True; |
| 9925 |
return; |
| 9926 |
end if; |
| 9927 |
end; |
| 9928 |
end if; |
| 9929 |
|
| 9930 |
Gather_Components |
| 9931 |
(Typ, Component_List (Variant), Governed_By, Into, |
| 9932 |
Report_Errors, Allow_Compile_Time); |
| 9933 |
end if; |
| 9934 |
end Gather_Components; |
| 9935 |
|
| 9936 |
------------------------ |
| 9937 |
-- Get_Actual_Subtype -- |
| 9938 |
------------------------ |
| 9939 |
|
| 9940 |
function Get_Actual_Subtype (N : Node_Id) return Entity_Id is |
| 9941 |
Typ : constant Entity_Id := Etype (N); |
| 9942 |
Utyp : Entity_Id := Underlying_Type (Typ); |
| 9943 |
Decl : Node_Id; |
| 9944 |
Atyp : Entity_Id; |
| 9945 |
|
| 9946 |
begin |
| 9947 |
if No (Utyp) then |
| 9948 |
Utyp := Typ; |
| 9949 |
end if; |
| 9950 |
|
| 9951 |
-- If what we have is an identifier that references a subprogram |
| 9952 |
-- formal, or a variable or constant object, then we get the actual |
| 9953 |
-- subtype from the referenced entity if one has been built. |
| 9954 |
|
| 9955 |
if Nkind (N) in N_Identifier | N_Expanded_Name |
| 9956 |
and then |
| 9957 |
(Is_Formal (Entity (N)) |
| 9958 |
or else Ekind (Entity (N)) = E_Constant |
| 9959 |
or else Ekind (Entity (N)) = E_Variable) |
| 9960 |
and then Present (Actual_Subtype (Entity (N))) |
| 9961 |
then |
| 9962 |
return Actual_Subtype (Entity (N)); |
| 9963 |
|
| 9964 |
-- Similarly, if we have an explicit dereference, then we get the |
| 9965 |
-- actual subtype from the node itself if one has been built. |
| 9966 |
|
| 9967 |
elsif Nkind (N) = N_Explicit_Dereference |
| 9968 |
and then Present (Actual_Designated_Subtype (N)) |
| 9969 |
then |
| 9970 |
return Actual_Designated_Subtype (N); |
| 9971 |
|
| 9972 |
-- Actual subtype of unchecked union is always itself. We never need |
| 9973 |
-- the "real" actual subtype. If we did, we couldn't get it anyway |
| 9974 |
-- because the discriminant is not available. The restrictions on |
| 9975 |
-- Unchecked_Union are designed to make sure that this is OK. |
| 9976 |
|
| 9977 |
elsif Is_Unchecked_Union (Base_Type (Utyp)) then |
| 9978 |
return Typ; |
| 9979 |
|
| 9980 |
-- Here for the unconstrained case, we must find actual subtype |
| 9981 |
-- No actual subtype is available, so we must build it on the fly. |
| 9982 |
|
| 9983 |
-- Checking the type, not the underlying type, for constrainedness |
| 9984 |
-- seems to be necessary. Maybe all the tests should be on the type??? |
| 9985 |
|
| 9986 |
elsif not Is_Constrained (Typ) |
| 9987 |
and then (Is_Array_Type (Utyp) |
| 9988 |
or else (Is_Record_Type (Utyp) |
| 9989 |
and then Has_Discriminants (Utyp))) |
| 9990 |
and then not Has_Unknown_Discriminants (Utyp) |
| 9991 |
and then not (Ekind (Utyp) = E_String_Literal_Subtype) |
| 9992 |
then |
| 9993 |
-- If the type has no discriminants, there is no subtype to build, |
| 9994 |
-- even if the underlying type is discriminated. |
| 9995 |
|
| 9996 |
if Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then |
| 9997 |
return Typ; |
| 9998 |
|
| 9999 |
-- If we are performing preanalysis on a conjured-up copy of a name |
| 10000 |
-- (see calls to Preanalyze_Range in sem_ch5.adb) then we don't want |
| 10001 |
-- to freeze Atyp, now or ever. In this case, the tree we eventually |
| 10002 |
-- pass to the back end should contain no references to Atyp (and a |
| 10003 |
-- freeze node would contain such a reference). |
| 10004 |
|
| 10005 |
elsif not (Expander_Active or GNATprove_Mode) then |
| 10006 |
return Typ; |
| 10007 |
|
| 10008 |
-- Else build the actual subtype |
| 10009 |
|
| 10010 |
else |
| 10011 |
Decl := Build_Actual_Subtype (Typ, N); |
| 10012 |
|
| 10013 |
-- The call may yield a declaration, or just return the entity |
| 10014 |
|
| 10015 |
if Decl = Typ then |
| 10016 |
return Typ; |
| 10017 |
end if; |
| 10018 |
|
| 10019 |
Atyp := Defining_Identifier (Decl); |
| 10020 |
|
| 10021 |
-- The actual subtype is an Itype, so analyze the declaration |
| 10022 |
-- after attaching it to the tree, to get the type defined. |
| 10023 |
|
| 10024 |
Set_Parent (Decl, N); |
| 10025 |
Set_Is_Itype (Atyp); |
| 10026 |
Analyze (Decl, Suppress => All_Checks); |
| 10027 |
Set_Associated_Node_For_Itype (Atyp, N); |
| 10028 |
|
| 10029 |
-- We need to freeze the actual subtype immediately. This is |
| 10030 |
-- needed because otherwise this Itype will not get frozen |
| 10031 |
-- at all; it is always safe to freeze on creation because |
| 10032 |
-- any associated types must be frozen at this point. |
| 10033 |
|
| 10034 |
Freeze_Itype (Atyp, N); |
| 10035 |
return Atyp; |
| 10036 |
end if; |
| 10037 |
|
| 10038 |
-- For all remaining cases, the actual subtype is the same as |
| 10039 |
-- the nominal type. |
| 10040 |
|
| 10041 |
else |
| 10042 |
return Typ; |
| 10043 |
end if; |
| 10044 |
end Get_Actual_Subtype; |
| 10045 |
|
| 10046 |
------------------------------------- |
| 10047 |
-- Get_Actual_Subtype_If_Available -- |
| 10048 |
------------------------------------- |
| 10049 |
|
| 10050 |
function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is |
| 10051 |
begin |
| 10052 |
-- If what we have is an identifier that references a subprogram |
| 10053 |
-- formal, or a variable or constant object, then we get the actual |
| 10054 |
-- subtype from the referenced entity if one has been built. |
| 10055 |
|
| 10056 |
if Nkind (N) in N_Identifier | N_Expanded_Name |
| 10057 |
and then |
| 10058 |
(Is_Formal (Entity (N)) |
| 10059 |
or else Ekind (Entity (N)) = E_Constant |
| 10060 |
or else Ekind (Entity (N)) = E_Variable) |
| 10061 |
and then Present (Actual_Subtype (Entity (N))) |
| 10062 |
then |
| 10063 |
return Actual_Subtype (Entity (N)); |
| 10064 |
|
| 10065 |
-- Similarly, if we have an explicit dereference, then we get the |
| 10066 |
-- actual subtype from the node itself if one has been built. |
| 10067 |
|
| 10068 |
elsif Nkind (N) = N_Explicit_Dereference |
| 10069 |
and then Present (Actual_Designated_Subtype (N)) |
| 10070 |
then |
| 10071 |
return Actual_Designated_Subtype (N); |
| 10072 |
|
| 10073 |
-- Otherwise the Etype of N is returned unchanged |
| 10074 |
|
| 10075 |
else |
| 10076 |
return Etype (N); |
| 10077 |
end if; |
| 10078 |
end Get_Actual_Subtype_If_Available; |
| 10079 |
|
| 10080 |
------------------------ |
| 10081 |
-- Get_Body_From_Stub -- |
| 10082 |
------------------------ |
| 10083 |
|
| 10084 |
function Get_Body_From_Stub (N : Node_Id) return Node_Id is |
| 10085 |
begin |
| 10086 |
return Proper_Body (Unit (Stub_Subunit (N))); |
| 10087 |
end Get_Body_From_Stub; |
| 10088 |
|
| 10089 |
--------------------- |
| 10090 |
-- Get_Cursor_Type -- |
| 10091 |
--------------------- |
| 10092 |
|
| 10093 |
function Get_Cursor_Type |
| 10094 |
(Aspect : Node_Id; |
| 10095 |
Typ : Entity_Id) return Entity_Id |
| 10096 |
is |
| 10097 |
Assoc : Node_Id; |
| 10098 |
Func : Entity_Id; |
| 10099 |
First_Op : Entity_Id; |
| 10100 |
Cursor : Entity_Id; |
| 10101 |
|
| 10102 |
begin |
| 10103 |
-- If error already detected, return |
| 10104 |
|
| 10105 |
if Error_Posted (Aspect) then |
| 10106 |
return Any_Type; |
| 10107 |
end if; |
| 10108 |
|
| 10109 |
-- The cursor type for an Iterable aspect is the return type of a |
| 10110 |
-- non-overloaded First primitive operation. Locate association for |
| 10111 |
-- First. |
| 10112 |
|
| 10113 |
Assoc := First (Component_Associations (Expression (Aspect))); |
| 10114 |
First_Op := Any_Id; |
| 10115 |
while Present (Assoc) loop |
| 10116 |
if Chars (First (Choices (Assoc))) = Name_First then |
| 10117 |
First_Op := Expression (Assoc); |
| 10118 |
exit; |
| 10119 |
end if; |
| 10120 |
|
| 10121 |
Next (Assoc); |
| 10122 |
end loop; |
| 10123 |
|
| 10124 |
if First_Op = Any_Id then |
| 10125 |
Error_Msg_N ("aspect Iterable must specify First operation", Aspect); |
| 10126 |
return Any_Type; |
| 10127 |
|
| 10128 |
elsif not Analyzed (First_Op) then |
| 10129 |
Analyze (First_Op); |
| 10130 |
end if; |
| 10131 |
|
| 10132 |
Cursor := Any_Type; |
| 10133 |
|
| 10134 |
-- Locate function with desired name and profile in scope of type |
| 10135 |
-- In the rare case where the type is an integer type, a base type |
| 10136 |
-- is created for it, check that the base type of the first formal |
| 10137 |
-- of First matches the base type of the domain. |
| 10138 |
|
| 10139 |
Func := First_Entity (Scope (Typ)); |
| 10140 |
while Present (Func) loop |
| 10141 |
if Chars (Func) = Chars (First_Op) |
| 10142 |
and then Ekind (Func) = E_Function |
| 10143 |
and then Present (First_Formal (Func)) |
| 10144 |
and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ) |
| 10145 |
and then No (Next_Formal (First_Formal (Func))) |
| 10146 |
then |
| 10147 |
if Cursor /= Any_Type then |
| 10148 |
Error_Msg_N |
| 10149 |
("operation First for iterable type must be unique", Aspect); |
| 10150 |
return Any_Type; |
| 10151 |
else |
| 10152 |
Cursor := Etype (Func); |
| 10153 |
end if; |
| 10154 |
end if; |
| 10155 |
|
| 10156 |
Next_Entity (Func); |
| 10157 |
end loop; |
| 10158 |
|
| 10159 |
-- If not found, no way to resolve remaining primitives |
| 10160 |
|
| 10161 |
if Cursor = Any_Type then |
| 10162 |
Error_Msg_N |
| 10163 |
("primitive operation for Iterable type must appear in the same " |
| 10164 |
& "list of declarations as the type", Aspect); |
| 10165 |
end if; |
| 10166 |
|
| 10167 |
return Cursor; |
| 10168 |
end Get_Cursor_Type; |
| 10169 |
|
| 10170 |
function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is |
| 10171 |
begin |
| 10172 |
return Etype (Get_Iterable_Type_Primitive (Typ, Name_First)); |
| 10173 |
end Get_Cursor_Type; |
| 10174 |
|
| 10175 |
------------------------------- |
| 10176 |
-- Get_Default_External_Name -- |
| 10177 |
------------------------------- |
| 10178 |
|
| 10179 |
function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is |
| 10180 |
begin |
| 10181 |
Get_Decoded_Name_String (Chars (E)); |
| 10182 |
|
| 10183 |
if Opt.External_Name_Imp_Casing = Uppercase then |
| 10184 |
Set_Casing (All_Upper_Case); |
| 10185 |
else |
| 10186 |
Set_Casing (All_Lower_Case); |
| 10187 |
end if; |
| 10188 |
|
| 10189 |
return |
| 10190 |
Make_String_Literal (Sloc (E), |
| 10191 |
Strval => String_From_Name_Buffer); |
| 10192 |
end Get_Default_External_Name; |
| 10193 |
|
| 10194 |
-------------------------- |
| 10195 |
-- Get_Enclosing_Object -- |
| 10196 |
-------------------------- |
| 10197 |
|
| 10198 |
function Get_Enclosing_Object (N : Node_Id) return Entity_Id is |
| 10199 |
begin |
| 10200 |
if Is_Entity_Name (N) then |
| 10201 |
return Entity (N); |
| 10202 |
else |
| 10203 |
case Nkind (N) is |
| 10204 |
when N_Indexed_Component |
| 10205 |
| N_Selected_Component |
| 10206 |
| N_Slice |
| 10207 |
=> |
| 10208 |
-- If not generating code, a dereference may be left implicit. |
| 10209 |
-- In thoses cases, return Empty. |
| 10210 |
|
| 10211 |
if Is_Access_Type (Etype (Prefix (N))) then |
| 10212 |
return Empty; |
| 10213 |
else |
| 10214 |
return Get_Enclosing_Object (Prefix (N)); |
| 10215 |
end if; |
| 10216 |
|
| 10217 |
when N_Type_Conversion => |
| 10218 |
return Get_Enclosing_Object (Expression (N)); |
| 10219 |
|
| 10220 |
when others => |
| 10221 |
return Empty; |
| 10222 |
end case; |
| 10223 |
end if; |
| 10224 |
end Get_Enclosing_Object; |
| 10225 |
|
| 10226 |
------------------------------- |
| 10227 |
-- Get_Enclosing_Deep_Object -- |
| 10228 |
------------------------------- |
| 10229 |
|
| 10230 |
function Get_Enclosing_Deep_Object (N : Node_Id) return Entity_Id is |
| 10231 |
begin |
| 10232 |
if Is_Entity_Name (N) then |
| 10233 |
return Entity (N); |
| 10234 |
else |
| 10235 |
case Nkind (N) is |
| 10236 |
when N_Explicit_Dereference |
| 10237 |
| N_Indexed_Component |
| 10238 |
| N_Selected_Component |
| 10239 |
| N_Slice |
| 10240 |
=> |
| 10241 |
return Get_Enclosing_Deep_Object (Prefix (N)); |
| 10242 |
|
| 10243 |
when N_Type_Conversion => |
| 10244 |
return Get_Enclosing_Deep_Object (Expression (N)); |
| 10245 |
|
| 10246 |
when others => |
| 10247 |
return Empty; |
| 10248 |
end case; |
| 10249 |
end if; |
| 10250 |
end Get_Enclosing_Deep_Object; |
| 10251 |
|
| 10252 |
--------------------------- |
| 10253 |
-- Get_Enum_Lit_From_Pos -- |
| 10254 |
--------------------------- |
| 10255 |
|
| 10256 |
function Get_Enum_Lit_From_Pos |
| 10257 |
(T : Entity_Id; |
| 10258 |
Pos : Uint; |
| 10259 |
Loc : Source_Ptr) return Node_Id |
| 10260 |
is |
| 10261 |
Btyp : Entity_Id := Base_Type (T); |
| 10262 |
Lit : Node_Id; |
| 10263 |
LLoc : Source_Ptr; |
| 10264 |
|
| 10265 |
begin |
| 10266 |
-- In the case where the literal is of type Character, Wide_Character |
| 10267 |
-- or Wide_Wide_Character or of a type derived from them, there needs |
| 10268 |
-- to be some special handling since there is no explicit chain of |
| 10269 |
-- literals to search. Instead, an N_Character_Literal node is created |
| 10270 |
-- with the appropriate Char_Code and Chars fields. |
| 10271 |
|
| 10272 |
if Is_Standard_Character_Type (T) then |
| 10273 |
Set_Character_Literal_Name (UI_To_CC (Pos)); |
| 10274 |
|
| 10275 |
return |
| 10276 |
Make_Character_Literal (Loc, |
| 10277 |
Chars => Name_Find, |
| 10278 |
Char_Literal_Value => Pos); |
| 10279 |
|
| 10280 |
-- For all other cases, we have a complete table of literals, and |
| 10281 |
-- we simply iterate through the chain of literal until the one |
| 10282 |
-- with the desired position value is found. |
| 10283 |
|
| 10284 |
else |
| 10285 |
if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then |
| 10286 |
Btyp := Full_View (Btyp); |
| 10287 |
end if; |
| 10288 |
|
| 10289 |
Lit := First_Literal (Btyp); |
| 10290 |
|
| 10291 |
-- Position in the enumeration type starts at 0 |
| 10292 |
|
| 10293 |
if Pos < 0 then |
| 10294 |
raise Constraint_Error; |
| 10295 |
end if; |
| 10296 |
|
| 10297 |
for J in 1 .. UI_To_Int (Pos) loop |
| 10298 |
Next_Literal (Lit); |
| 10299 |
|
| 10300 |
-- If Lit is Empty, Pos is not in range, so raise Constraint_Error |
| 10301 |
-- inside the loop to avoid calling Next_Literal on Empty. |
| 10302 |
|
| 10303 |
if No (Lit) then |
| 10304 |
raise Constraint_Error; |
| 10305 |
end if; |
| 10306 |
end loop; |
| 10307 |
|
| 10308 |
-- Create a new node from Lit, with source location provided by Loc |
| 10309 |
-- if not equal to No_Location, or by copying the source location of |
| 10310 |
-- Lit otherwise. |
| 10311 |
|
| 10312 |
LLoc := Loc; |
| 10313 |
|
| 10314 |
if LLoc = No_Location then |
| 10315 |
LLoc := Sloc (Lit); |
| 10316 |
end if; |
| 10317 |
|
| 10318 |
return New_Occurrence_Of (Lit, LLoc); |
| 10319 |
end if; |
| 10320 |
end Get_Enum_Lit_From_Pos; |
| 10321 |
|
| 10322 |
---------------------- |
| 10323 |
-- Get_Fullest_View -- |
| 10324 |
---------------------- |
| 10325 |
|
| 10326 |
function Get_Fullest_View |
| 10327 |
(E : Entity_Id; |
| 10328 |
Include_PAT : Boolean := True; |
| 10329 |
Recurse : Boolean := True) return Entity_Id |
| 10330 |
is |
| 10331 |
New_E : Entity_Id := Empty; |
| 10332 |
|
| 10333 |
begin |
| 10334 |
-- Prevent cascaded errors |
| 10335 |
|
| 10336 |
if No (E) then |
| 10337 |
return E; |
| 10338 |
end if; |
| 10339 |
|
| 10340 |
-- Look at each kind of entity to see where we may need to go deeper. |
| 10341 |
|
| 10342 |
case Ekind (E) is |
| 10343 |
when Incomplete_Kind => |
| 10344 |
if From_Limited_With (E) then |
| 10345 |
New_E := Non_Limited_View (E); |
| 10346 |
elsif Present (Full_View (E)) then |
| 10347 |
New_E := Full_View (E); |
| 10348 |
elsif Ekind (E) = E_Incomplete_Subtype then |
| 10349 |
New_E := Etype (E); |
| 10350 |
end if; |
| 10351 |
|
| 10352 |
when Private_Kind => |
| 10353 |
if Present (Underlying_Full_View (E)) then |
| 10354 |
New_E := Underlying_Full_View (E); |
| 10355 |
elsif Present (Full_View (E)) then |
| 10356 |
New_E := Full_View (E); |
| 10357 |
elsif Etype (E) /= E then |
| 10358 |
New_E := Etype (E); |
| 10359 |
end if; |
| 10360 |
|
| 10361 |
when Array_Kind => |
| 10362 |
if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then |
| 10363 |
New_E := Packed_Array_Impl_Type (E); |
| 10364 |
end if; |
| 10365 |
|
| 10366 |
when E_Record_Subtype => |
| 10367 |
if Present (Cloned_Subtype (E)) then |
| 10368 |
New_E := Cloned_Subtype (E); |
| 10369 |
end if; |
| 10370 |
|
| 10371 |
when E_Class_Wide_Type => |
| 10372 |
New_E := Root_Type (E); |
| 10373 |
|
| 10374 |
when E_Class_Wide_Subtype => |
| 10375 |
if Present (Equivalent_Type (E)) then |
| 10376 |
New_E := Equivalent_Type (E); |
| 10377 |
elsif Present (Cloned_Subtype (E)) then |
| 10378 |
New_E := Cloned_Subtype (E); |
| 10379 |
end if; |
| 10380 |
|
| 10381 |
when E_Protected_Subtype |
| 10382 |
| E_Protected_Type |
| 10383 |
| E_Task_Subtype |
| 10384 |
| E_Task_Type |
| 10385 |
=> |
| 10386 |
if Present (Corresponding_Record_Type (E)) then |
| 10387 |
New_E := Corresponding_Record_Type (E); |
| 10388 |
end if; |
| 10389 |
|
| 10390 |
when E_Access_Protected_Subprogram_Type |
| 10391 |
| E_Anonymous_Access_Protected_Subprogram_Type |
| 10392 |
=> |
| 10393 |
if Present (Equivalent_Type (E)) then |
| 10394 |
New_E := Equivalent_Type (E); |
| 10395 |
end if; |
| 10396 |
|
| 10397 |
when E_Access_Subtype => |
| 10398 |
New_E := Base_Type (E); |
| 10399 |
|
| 10400 |
when others => |
| 10401 |
null; |
| 10402 |
end case; |
| 10403 |
|
| 10404 |
-- If we found a fuller view, either return it or recurse. Otherwise, |
| 10405 |
-- return our input. |
| 10406 |
|
| 10407 |
return (if No (New_E) then E |
| 10408 |
elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse) |
| 10409 |
else New_E); |
| 10410 |
end Get_Fullest_View; |
| 10411 |
|
| 10412 |
------------------------ |
| 10413 |
-- Get_Generic_Entity -- |
| 10414 |
------------------------ |
| 10415 |
|
| 10416 |
function Get_Generic_Entity (N : Node_Id) return Entity_Id is |
| 10417 |
Ent : constant Entity_Id := Entity (Name (N)); |
| 10418 |
begin |
| 10419 |
if Present (Renamed_Entity (Ent)) then |
| 10420 |
return Renamed_Entity (Ent); |
| 10421 |
else |
| 10422 |
return Ent; |
| 10423 |
end if; |
| 10424 |
end Get_Generic_Entity; |
| 10425 |
|
| 10426 |
------------------------------------- |
| 10427 |
-- Get_Incomplete_View_Of_Ancestor -- |
| 10428 |
------------------------------------- |
| 10429 |
|
| 10430 |
function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is |
| 10431 |
Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); |
| 10432 |
Par_Scope : Entity_Id; |
| 10433 |
Par_Type : Entity_Id; |
| 10434 |
|
| 10435 |
begin |
| 10436 |
-- The incomplete view of an ancestor is only relevant for private |
| 10437 |
-- derived types in child units. |
| 10438 |
|
| 10439 |
if not Is_Derived_Type (E) |
| 10440 |
or else not Is_Child_Unit (Cur_Unit) |
| 10441 |
then |
| 10442 |
return Empty; |
| 10443 |
|
| 10444 |
else |
| 10445 |
Par_Scope := Scope (Cur_Unit); |
| 10446 |
if No (Par_Scope) then |
| 10447 |
return Empty; |
| 10448 |
end if; |
| 10449 |
|
| 10450 |
Par_Type := Etype (Base_Type (E)); |
| 10451 |
|
| 10452 |
-- Traverse list of ancestor types until we find one declared in |
| 10453 |
-- a parent or grandparent unit (two levels seem sufficient). |
| 10454 |
|
| 10455 |
while Present (Par_Type) loop |
| 10456 |
if Scope (Par_Type) = Par_Scope |
| 10457 |
or else Scope (Par_Type) = Scope (Par_Scope) |
| 10458 |
then |
| 10459 |
return Par_Type; |
| 10460 |
|
| 10461 |
elsif not Is_Derived_Type (Par_Type) then |
| 10462 |
return Empty; |
| 10463 |
|
| 10464 |
else |
| 10465 |
Par_Type := Etype (Base_Type (Par_Type)); |
| 10466 |
end if; |
| 10467 |
end loop; |
| 10468 |
|
| 10469 |
-- If none found, there is no relevant ancestor type. |
| 10470 |
|
| 10471 |
return Empty; |
| 10472 |
end if; |
| 10473 |
end Get_Incomplete_View_Of_Ancestor; |
| 10474 |
|
| 10475 |
---------------------- |
| 10476 |
-- Get_Index_Bounds -- |
| 10477 |
---------------------- |
| 10478 |
|
| 10479 |
procedure Get_Index_Bounds |
| 10480 |
(N : Node_Id; |
| 10481 |
L : out Node_Id; |
| 10482 |
H : out Node_Id; |
| 10483 |
Use_Full_View : Boolean := False) |
| 10484 |
is |
| 10485 |
function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id; |
| 10486 |
-- Obtain the scalar range of type Typ. If flag Use_Full_View is set and |
| 10487 |
-- Typ qualifies, the scalar range is obtained from the full view of the |
| 10488 |
-- type. |
| 10489 |
|
| 10490 |
-------------------------- |
| 10491 |
-- Scalar_Range_Of_Type -- |
| 10492 |
-------------------------- |
| 10493 |
|
| 10494 |
function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is |
| 10495 |
T : Entity_Id := Typ; |
| 10496 |
|
| 10497 |
begin |
| 10498 |
if Use_Full_View and then Present (Full_View (T)) then |
| 10499 |
T := Full_View (T); |
| 10500 |
end if; |
| 10501 |
|
| 10502 |
return Scalar_Range (T); |
| 10503 |
end Scalar_Range_Of_Type; |
| 10504 |
|
| 10505 |
-- Local variables |
| 10506 |
|
| 10507 |
Kind : constant Node_Kind := Nkind (N); |
| 10508 |
Rng : Node_Id; |
| 10509 |
|
| 10510 |
-- Start of processing for Get_Index_Bounds |
| 10511 |
|
| 10512 |
begin |
| 10513 |
if Kind = N_Range then |
| 10514 |
L := Low_Bound (N); |
| 10515 |
H := High_Bound (N); |
| 10516 |
|
| 10517 |
elsif Kind = N_Subtype_Indication then |
| 10518 |
Rng := Range_Expression (Constraint (N)); |
| 10519 |
|
| 10520 |
if Rng = Error then |
| 10521 |
L := Error; |
| 10522 |
H := Error; |
| 10523 |
return; |
| 10524 |
|
| 10525 |
else |
| 10526 |
L := Low_Bound (Range_Expression (Constraint (N))); |
| 10527 |
H := High_Bound (Range_Expression (Constraint (N))); |
| 10528 |
end if; |
| 10529 |
|
| 10530 |
elsif Is_Entity_Name (N) |
| 10531 |
and then Present (Entity (N)) |
| 10532 |
and then Is_Type (Entity (N)) |
| 10533 |
then |
| 10534 |
Rng := Scalar_Range_Of_Type (Entity (N)); |
| 10535 |
|
| 10536 |
if Error_Posted (Rng) then |
| 10537 |
L := Error; |
| 10538 |
H := Error; |
| 10539 |
|
| 10540 |
elsif Nkind (Rng) = N_Subtype_Indication then |
| 10541 |
Get_Index_Bounds (Rng, L, H); |
| 10542 |
|
| 10543 |
else |
| 10544 |
L := Low_Bound (Rng); |
| 10545 |
H := High_Bound (Rng); |
| 10546 |
end if; |
| 10547 |
|
| 10548 |
else |
| 10549 |
-- N is an expression, indicating a range with one value |
| 10550 |
|
| 10551 |
L := N; |
| 10552 |
H := N; |
| 10553 |
end if; |
| 10554 |
end Get_Index_Bounds; |
| 10555 |
|
| 10556 |
function Get_Index_Bounds |
| 10557 |
(N : Node_Id; |
| 10558 |
Use_Full_View : Boolean := False) return Range_Nodes is |
| 10559 |
Result : Range_Nodes; |
| 10560 |
begin |
| 10561 |
Get_Index_Bounds (N, Result.First, Result.Last, Use_Full_View); |
| 10562 |
return Result; |
| 10563 |
end Get_Index_Bounds; |
| 10564 |
|
| 10565 |
function Get_Index_Bounds |
| 10566 |
(N : Node_Id; |
| 10567 |
Use_Full_View : Boolean := False) return Range_Values is |
| 10568 |
Nodes : constant Range_Nodes := Get_Index_Bounds (N, Use_Full_View); |
| 10569 |
begin |
| 10570 |
return (Expr_Value (Nodes.First), Expr_Value (Nodes.Last)); |
| 10571 |
end Get_Index_Bounds; |
| 10572 |
|
| 10573 |
----------------------------- |
| 10574 |
-- Get_Interfacing_Aspects -- |
| 10575 |
----------------------------- |
| 10576 |
|
| 10577 |
procedure Get_Interfacing_Aspects |
| 10578 |
(Iface_Asp : Node_Id; |
| 10579 |
Conv_Asp : out Node_Id; |
| 10580 |
EN_Asp : out Node_Id; |
| 10581 |
Expo_Asp : out Node_Id; |
| 10582 |
Imp_Asp : out Node_Id; |
| 10583 |
LN_Asp : out Node_Id; |
| 10584 |
Do_Checks : Boolean := False) |
| 10585 |
is |
| 10586 |
procedure Save_Or_Duplication_Error |
| 10587 |
(Asp : Node_Id; |
| 10588 |
To : in out Node_Id); |
| 10589 |
-- Save the value of aspect Asp in node To. If To already has a value, |
| 10590 |
-- then this is considered a duplicate use of aspect. Emit an error if |
| 10591 |
-- flag Do_Checks is set. |
| 10592 |
|
| 10593 |
------------------------------- |
| 10594 |
-- Save_Or_Duplication_Error -- |
| 10595 |
------------------------------- |
| 10596 |
|
| 10597 |
procedure Save_Or_Duplication_Error |
| 10598 |
(Asp : Node_Id; |
| 10599 |
To : in out Node_Id) |
| 10600 |
is |
| 10601 |
begin |
| 10602 |
-- Detect an extra aspect and issue an error |
| 10603 |
|
| 10604 |
if Present (To) then |
| 10605 |
if Do_Checks then |
| 10606 |
Error_Msg_Name_1 := Chars (Identifier (Asp)); |
| 10607 |
Error_Msg_Sloc := Sloc (To); |
| 10608 |
Error_Msg_N ("aspect % previously given #", Asp); |
| 10609 |
end if; |
| 10610 |
|
| 10611 |
-- Otherwise capture the aspect |
| 10612 |
|
| 10613 |
else |
| 10614 |
To := Asp; |
| 10615 |
end if; |
| 10616 |
end Save_Or_Duplication_Error; |
| 10617 |
|
| 10618 |
-- Local variables |
| 10619 |
|
| 10620 |
Asp : Node_Id; |
| 10621 |
Asp_Id : Aspect_Id; |
| 10622 |
|
| 10623 |
-- The following variables capture each individual aspect |
| 10624 |
|
| 10625 |
Conv : Node_Id := Empty; |
| 10626 |
EN : Node_Id := Empty; |
| 10627 |
Expo : Node_Id := Empty; |
| 10628 |
Imp : Node_Id := Empty; |
| 10629 |
LN : Node_Id := Empty; |
| 10630 |
|
| 10631 |
-- Start of processing for Get_Interfacing_Aspects |
| 10632 |
|
| 10633 |
begin |
| 10634 |
-- The input interfacing aspect should reside in an aspect specification |
| 10635 |
-- list. |
| 10636 |
|
| 10637 |
pragma Assert (Is_List_Member (Iface_Asp)); |
| 10638 |
|
| 10639 |
-- Examine the aspect specifications of the related entity. Find and |
| 10640 |
-- capture all interfacing aspects. Detect duplicates and emit errors |
| 10641 |
-- if applicable. |
| 10642 |
|
| 10643 |
Asp := First (List_Containing (Iface_Asp)); |
| 10644 |
while Present (Asp) loop |
| 10645 |
Asp_Id := Get_Aspect_Id (Asp); |
| 10646 |
|
| 10647 |
if Asp_Id = Aspect_Convention then |
| 10648 |
Save_Or_Duplication_Error (Asp, Conv); |
| 10649 |
|
| 10650 |
elsif Asp_Id = Aspect_External_Name then |
| 10651 |
Save_Or_Duplication_Error (Asp, EN); |
| 10652 |
|
| 10653 |
elsif Asp_Id = Aspect_Export then |
| 10654 |
Save_Or_Duplication_Error (Asp, Expo); |
| 10655 |
|
| 10656 |
elsif Asp_Id = Aspect_Import then |
| 10657 |
Save_Or_Duplication_Error (Asp, Imp); |
| 10658 |
|
| 10659 |
elsif Asp_Id = Aspect_Link_Name then |
| 10660 |
Save_Or_Duplication_Error (Asp, LN); |
| 10661 |
end if; |
| 10662 |
|
| 10663 |
Next (Asp); |
| 10664 |
end loop; |
| 10665 |
|
| 10666 |
Conv_Asp := Conv; |
| 10667 |
EN_Asp := EN; |
| 10668 |
Expo_Asp := Expo; |
| 10669 |
Imp_Asp := Imp; |
| 10670 |
LN_Asp := LN; |
| 10671 |
end Get_Interfacing_Aspects; |
| 10672 |
|
| 10673 |
--------------------------------- |
| 10674 |
-- Get_Iterable_Type_Primitive -- |
| 10675 |
--------------------------------- |
| 10676 |
|
| 10677 |
function Get_Iterable_Type_Primitive |
| 10678 |
(Typ : Entity_Id; |
| 10679 |
Nam : Name_Id) return Entity_Id |
| 10680 |
is |
| 10681 |
pragma Assert |
| 10682 |
(Is_Type (Typ) |
| 10683 |
and then |
| 10684 |
Nam in Name_Element |
| 10685 |
| Name_First |
| 10686 |
| Name_Has_Element |
| 10687 |
| Name_Last |
| 10688 |
| Name_Next |
| 10689 |
| Name_Previous); |
| 10690 |
|
| 10691 |
Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable); |
| 10692 |
Assoc : Node_Id; |
| 10693 |
|
| 10694 |
begin |
| 10695 |
if No (Funcs) then |
| 10696 |
return Empty; |
| 10697 |
|
| 10698 |
else |
| 10699 |
Assoc := First (Component_Associations (Funcs)); |
| 10700 |
while Present (Assoc) loop |
| 10701 |
if Chars (First (Choices (Assoc))) = Nam then |
| 10702 |
return Entity (Expression (Assoc)); |
| 10703 |
end if; |
| 10704 |
|
| 10705 |
Next (Assoc); |
| 10706 |
end loop; |
| 10707 |
|
| 10708 |
return Empty; |
| 10709 |
end if; |
| 10710 |
end Get_Iterable_Type_Primitive; |
| 10711 |
|
| 10712 |
--------------------------- |
| 10713 |
-- Get_Library_Unit_Name -- |
| 10714 |
--------------------------- |
| 10715 |
|
| 10716 |
function Get_Library_Unit_Name (Decl_Node : Node_Id) return String_Id is |
| 10717 |
Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node); |
| 10718 |
Buf : Bounded_String; |
| 10719 |
begin |
| 10720 |
Get_Unit_Name_String (Buf, Unit_Name_Id, Suffix => False); |
| 10721 |
return String_From_Name_Buffer (Buf); |
| 10722 |
end Get_Library_Unit_Name; |
| 10723 |
|
| 10724 |
-------------------------- |
| 10725 |
-- Get_Max_Queue_Length -- |
| 10726 |
-------------------------- |
| 10727 |
|
| 10728 |
function Get_Max_Queue_Length (Id : Entity_Id) return Uint is |
| 10729 |
pragma Assert (Is_Entry (Id)); |
| 10730 |
PMQL : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length); |
| 10731 |
PMEQL : constant Entity_Id := |
| 10732 |
Get_Pragma (Id, Pragma_Max_Entry_Queue_Length); |
| 10733 |
Max : Uint; |
| 10734 |
|
| 10735 |
begin |
| 10736 |
-- A value of 0 or -1 represents no maximum specified, and entries and |
| 10737 |
-- entry families with no Max_Queue_Length aspect or pragma default to |
| 10738 |
-- it. |
| 10739 |
|
| 10740 |
-- We have already checked that there is at most one of these pragmas |
| 10741 |
|
| 10742 |
if Present (PMQL) then |
| 10743 |
Max := Expr_Value |
| 10744 |
(Expression (First (Pragma_Argument_Associations (PMQL)))); |
| 10745 |
elsif Present (PMEQL) then |
| 10746 |
Max := Expr_Value |
| 10747 |
(Expression (First (Pragma_Argument_Associations (PMEQL)))); |
| 10748 |
else |
| 10749 |
Max := Uint_0; |
| 10750 |
end if; |
| 10751 |
|
| 10752 |
-- Since -1 and 0 are equivalent, return 0 for instances of -1 for |
| 10753 |
-- uniformity. |
| 10754 |
|
| 10755 |
if Max = -1 then |
| 10756 |
Max := Uint_0; |
| 10757 |
end if; |
| 10758 |
|
| 10759 |
return Max; |
| 10760 |
end Get_Max_Queue_Length; |
| 10761 |
|
| 10762 |
------------------------ |
| 10763 |
-- Get_Name_Entity_Id -- |
| 10764 |
------------------------ |
| 10765 |
|
| 10766 |
function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is |
| 10767 |
begin |
| 10768 |
return Entity_Id (Get_Name_Table_Int (Id)); |
| 10769 |
end Get_Name_Entity_Id; |
| 10770 |
|
| 10771 |
------------------------------ |
| 10772 |
-- Get_Name_From_CTC_Pragma -- |
| 10773 |
------------------------------ |
| 10774 |
|
| 10775 |
function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is |
| 10776 |
Arg : constant Node_Id := |
| 10777 |
Get_Pragma_Arg (First (Pragma_Argument_Associations (N))); |
| 10778 |
begin |
| 10779 |
return Strval (Expr_Value_S (Arg)); |
| 10780 |
end Get_Name_From_CTC_Pragma; |
| 10781 |
|
| 10782 |
----------------------- |
| 10783 |
-- Get_Parent_Entity -- |
| 10784 |
----------------------- |
| 10785 |
|
| 10786 |
function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is |
| 10787 |
begin |
| 10788 |
if Nkind (Unit) = N_Package_Body |
| 10789 |
and then Nkind (Original_Node (Unit)) = N_Package_Instantiation |
| 10790 |
then |
| 10791 |
return Defining_Entity |
| 10792 |
(Specification (Instance_Spec (Original_Node (Unit)))); |
| 10793 |
elsif Nkind (Unit) = N_Package_Instantiation then |
| 10794 |
return Defining_Entity (Specification (Instance_Spec (Unit))); |
| 10795 |
else |
| 10796 |
return Defining_Entity (Unit); |
| 10797 |
end if; |
| 10798 |
end Get_Parent_Entity; |
| 10799 |
|
| 10800 |
------------------- |
| 10801 |
-- Get_Pragma_Id -- |
| 10802 |
------------------- |
| 10803 |
|
| 10804 |
function Get_Pragma_Id (N : Node_Id) return Pragma_Id is |
| 10805 |
begin |
| 10806 |
return Get_Pragma_Id (Pragma_Name_Unmapped (N)); |
| 10807 |
end Get_Pragma_Id; |
| 10808 |
|
| 10809 |
------------------------ |
| 10810 |
-- Get_Qualified_Name -- |
| 10811 |
------------------------ |
| 10812 |
|
| 10813 |
function Get_Qualified_Name |
| 10814 |
(Id : Entity_Id; |
| 10815 |
Suffix : Entity_Id := Empty) return Name_Id |
| 10816 |
is |
| 10817 |
Suffix_Nam : Name_Id := No_Name; |
| 10818 |
|
| 10819 |
begin |
| 10820 |
if Present (Suffix) then |
| 10821 |
Suffix_Nam := Chars (Suffix); |
| 10822 |
end if; |
| 10823 |
|
| 10824 |
return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id)); |
| 10825 |
end Get_Qualified_Name; |
| 10826 |
|
| 10827 |
function Get_Qualified_Name |
| 10828 |
(Nam : Name_Id; |
| 10829 |
Suffix : Name_Id := No_Name; |
| 10830 |
Scop : Entity_Id := Current_Scope) return Name_Id |
| 10831 |
is |
| 10832 |
procedure Add_Scope (S : Entity_Id); |
| 10833 |
-- Add the fully qualified form of scope S to the name buffer. The |
| 10834 |
-- format is: |
| 10835 |
-- s-1__s__ |
| 10836 |
|
| 10837 |
--------------- |
| 10838 |
-- Add_Scope -- |
| 10839 |
--------------- |
| 10840 |
|
| 10841 |
procedure Add_Scope (S : Entity_Id) is |
| 10842 |
begin |
| 10843 |
if S = Empty then |
| 10844 |
null; |
| 10845 |
|
| 10846 |
elsif S = Standard_Standard then |
| 10847 |
null; |
| 10848 |
|
| 10849 |
else |
| 10850 |
Add_Scope (Scope (S)); |
| 10851 |
Get_Name_String_And_Append (Chars (S)); |
| 10852 |
Add_Str_To_Name_Buffer ("__"); |
| 10853 |
end if; |
| 10854 |
end Add_Scope; |
| 10855 |
|
| 10856 |
-- Start of processing for Get_Qualified_Name |
| 10857 |
|
| 10858 |
begin |
| 10859 |
Name_Len := 0; |
| 10860 |
Add_Scope (Scop); |
| 10861 |
|
| 10862 |
-- Append the base name after all scopes have been chained |
| 10863 |
|
| 10864 |
Get_Name_String_And_Append (Nam); |
| 10865 |
|
| 10866 |
-- Append the suffix (if present) |
| 10867 |
|
| 10868 |
if Suffix /= No_Name then |
| 10869 |
Add_Str_To_Name_Buffer ("__"); |
| 10870 |
Get_Name_String_And_Append (Suffix); |
| 10871 |
end if; |
| 10872 |
|
| 10873 |
return Name_Find; |
| 10874 |
end Get_Qualified_Name; |
| 10875 |
|
| 10876 |
----------------------- |
| 10877 |
-- Get_Reason_String -- |
| 10878 |
----------------------- |
| 10879 |
|
| 10880 |
procedure Get_Reason_String (N : Node_Id) is |
| 10881 |
begin |
| 10882 |
if Nkind (N) = N_String_Literal then |
| 10883 |
Store_String_Chars (Strval (N)); |
| 10884 |
|
| 10885 |
elsif Nkind (N) = N_Op_Concat then |
| 10886 |
Get_Reason_String (Left_Opnd (N)); |
| 10887 |
Get_Reason_String (Right_Opnd (N)); |
| 10888 |
|
| 10889 |
-- If not of required form, error |
| 10890 |
|
| 10891 |
else |
| 10892 |
Error_Msg_N |
| 10893 |
("Reason for pragma Warnings has wrong form", N); |
| 10894 |
Error_Msg_N |
| 10895 |
("\must be string literal or concatenation of string literals", N); |
| 10896 |
return; |
| 10897 |
end if; |
| 10898 |
end Get_Reason_String; |
| 10899 |
|
| 10900 |
-------------------------------- |
| 10901 |
-- Get_Reference_Discriminant -- |
| 10902 |
-------------------------------- |
| 10903 |
|
| 10904 |
function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is |
| 10905 |
D : Entity_Id; |
| 10906 |
|
| 10907 |
begin |
| 10908 |
D := First_Discriminant (Typ); |
| 10909 |
while Present (D) loop |
| 10910 |
if Has_Implicit_Dereference (D) then |
| 10911 |
return D; |
| 10912 |
end if; |
| 10913 |
Next_Discriminant (D); |
| 10914 |
end loop; |
| 10915 |
|
| 10916 |
return Empty; |
| 10917 |
end Get_Reference_Discriminant; |
| 10918 |
|
| 10919 |
--------------------------- |
| 10920 |
-- Get_Referenced_Object -- |
| 10921 |
--------------------------- |
| 10922 |
|
| 10923 |
function Get_Referenced_Object (N : Node_Id) return Node_Id is |
| 10924 |
R : Node_Id; |
| 10925 |
|
| 10926 |
begin |
| 10927 |
R := N; |
| 10928 |
while Is_Entity_Name (R) |
| 10929 |
and then Is_Object (Entity (R)) |
| 10930 |
and then Present (Renamed_Object (Entity (R))) |
| 10931 |
loop |
| 10932 |
R := Renamed_Object (Entity (R)); |
| 10933 |
end loop; |
| 10934 |
|
| 10935 |
return R; |
| 10936 |
end Get_Referenced_Object; |
| 10937 |
|
| 10938 |
------------------------ |
| 10939 |
-- Get_Renamed_Entity -- |
| 10940 |
------------------------ |
| 10941 |
|
| 10942 |
function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is |
| 10943 |
R : Entity_Id := E; |
| 10944 |
begin |
| 10945 |
while Present (Renamed_Entity (R)) loop |
| 10946 |
R := Renamed_Entity (R); |
| 10947 |
end loop; |
| 10948 |
|
| 10949 |
return R; |
| 10950 |
end Get_Renamed_Entity; |
| 10951 |
|
| 10952 |
----------------------- |
| 10953 |
-- Get_Return_Object -- |
| 10954 |
----------------------- |
| 10955 |
|
| 10956 |
function Get_Return_Object (N : Node_Id) return Entity_Id is |
| 10957 |
Decl : Node_Id; |
| 10958 |
|
| 10959 |
begin |
| 10960 |
Decl := First (Return_Object_Declarations (N)); |
| 10961 |
while Present (Decl) loop |
| 10962 |
exit when Nkind (Decl) = N_Object_Declaration |
| 10963 |
and then Is_Return_Object (Defining_Identifier (Decl)); |
| 10964 |
Next (Decl); |
| 10965 |
end loop; |
| 10966 |
|
| 10967 |
pragma Assert (Present (Decl)); |
| 10968 |
return Defining_Identifier (Decl); |
| 10969 |
end Get_Return_Object; |
| 10970 |
|
| 10971 |
--------------------------- |
| 10972 |
-- Get_Subprogram_Entity -- |
| 10973 |
--------------------------- |
| 10974 |
|
| 10975 |
function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is |
| 10976 |
Subp : Node_Id; |
| 10977 |
Subp_Id : Entity_Id; |
| 10978 |
|
| 10979 |
begin |
| 10980 |
if Nkind (Nod) = N_Accept_Statement then |
| 10981 |
Subp := Entry_Direct_Name (Nod); |
| 10982 |
|
| 10983 |
elsif Nkind (Nod) = N_Slice then |
| 10984 |
Subp := Prefix (Nod); |
| 10985 |
|
| 10986 |
else |
| 10987 |
Subp := Name (Nod); |
| 10988 |
end if; |
| 10989 |
|
| 10990 |
-- Strip the subprogram call |
| 10991 |
|
| 10992 |
loop |
| 10993 |
if Nkind (Subp) in N_Explicit_Dereference |
| 10994 |
| N_Indexed_Component |
| 10995 |
| N_Selected_Component |
| 10996 |
then |
| 10997 |
Subp := Prefix (Subp); |
| 10998 |
|
| 10999 |
elsif Nkind (Subp) in N_Type_Conversion |
| 11000 |
| N_Unchecked_Type_Conversion |
| 11001 |
then |
| 11002 |
Subp := Expression (Subp); |
| 11003 |
|
| 11004 |
else |
| 11005 |
exit; |
| 11006 |
end if; |
| 11007 |
end loop; |
| 11008 |
|
| 11009 |
-- Extract the entity of the subprogram call |
| 11010 |
|
| 11011 |
if Is_Entity_Name (Subp) then |
| 11012 |
Subp_Id := Entity (Subp); |
| 11013 |
|
| 11014 |
if Ekind (Subp_Id) = E_Access_Subprogram_Type then |
| 11015 |
Subp_Id := Directly_Designated_Type (Subp_Id); |
| 11016 |
end if; |
| 11017 |
|
| 11018 |
if Is_Subprogram (Subp_Id) then |
| 11019 |
return Subp_Id; |
| 11020 |
else |
| 11021 |
return Empty; |
| 11022 |
end if; |
| 11023 |
|
| 11024 |
-- The search did not find a construct that denotes a subprogram |
| 11025 |
|
| 11026 |
else |
| 11027 |
return Empty; |
| 11028 |
end if; |
| 11029 |
end Get_Subprogram_Entity; |
| 11030 |
|
| 11031 |
----------------------------- |
| 11032 |
-- Get_Task_Body_Procedure -- |
| 11033 |
----------------------------- |
| 11034 |
|
| 11035 |
function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is |
| 11036 |
begin |
| 11037 |
-- Note: A task type may be the completion of a private type with |
| 11038 |
-- discriminants. When performing elaboration checks on a task |
| 11039 |
-- declaration, the current view of the type may be the private one, |
| 11040 |
-- and the procedure that holds the body of the task is held in its |
| 11041 |
-- underlying type. |
| 11042 |
|
| 11043 |
-- This is an odd function, why not have Task_Body_Procedure do |
| 11044 |
-- the following digging??? |
| 11045 |
|
| 11046 |
return Task_Body_Procedure (Underlying_Type (Root_Type (E))); |
| 11047 |
end Get_Task_Body_Procedure; |
| 11048 |
|
| 11049 |
------------------------------- |
| 11050 |
-- Get_User_Defined_Equality -- |
| 11051 |
------------------------------- |
| 11052 |
|
| 11053 |
function Get_User_Defined_Equality (E : Entity_Id) return Entity_Id is |
| 11054 |
Prim : Elmt_Id; |
| 11055 |
|
| 11056 |
begin |
| 11057 |
Prim := First_Elmt (Collect_Primitive_Operations (E)); |
| 11058 |
while Present (Prim) loop |
| 11059 |
if Is_User_Defined_Equality (Node (Prim)) then |
| 11060 |
return Node (Prim); |
| 11061 |
end if; |
| 11062 |
|
| 11063 |
Next_Elmt (Prim); |
| 11064 |
end loop; |
| 11065 |
|
| 11066 |
return Empty; |
| 11067 |
end Get_User_Defined_Equality; |
| 11068 |
|
| 11069 |
--------------- |
| 11070 |
-- Get_Views -- |
| 11071 |
--------------- |
| 11072 |
|
| 11073 |
procedure Get_Views |
| 11074 |
(Typ : Entity_Id; |
| 11075 |
Priv_Typ : out Entity_Id; |
| 11076 |
Full_Typ : out Entity_Id; |
| 11077 |
UFull_Typ : out Entity_Id; |
| 11078 |
CRec_Typ : out Entity_Id) |
| 11079 |
is |
| 11080 |
IP_View : Entity_Id; |
| 11081 |
|
| 11082 |
begin |
| 11083 |
-- Assume that none of the views can be recovered |
| 11084 |
|
| 11085 |
Priv_Typ := Empty; |
| 11086 |
Full_Typ := Empty; |
| 11087 |
UFull_Typ := Empty; |
| 11088 |
CRec_Typ := Empty; |
| 11089 |
|
| 11090 |
-- The input type is the corresponding record type of a protected or a |
| 11091 |
-- task type. |
| 11092 |
|
| 11093 |
if Ekind (Typ) = E_Record_Type |
| 11094 |
and then Is_Concurrent_Record_Type (Typ) |
| 11095 |
then |
| 11096 |
CRec_Typ := Typ; |
| 11097 |
Full_Typ := Corresponding_Concurrent_Type (CRec_Typ); |
| 11098 |
Priv_Typ := Incomplete_Or_Partial_View (Full_Typ); |
| 11099 |
|
| 11100 |
-- Otherwise the input type denotes an arbitrary type |
| 11101 |
|
| 11102 |
else |
| 11103 |
IP_View := Incomplete_Or_Partial_View (Typ); |
| 11104 |
|
| 11105 |
-- The input type denotes the full view of a private type |
| 11106 |
|
| 11107 |
if Present (IP_View) then |
| 11108 |
Priv_Typ := IP_View; |
| 11109 |
Full_Typ := Typ; |
| 11110 |
|
| 11111 |
-- The input type is a private type |
| 11112 |
|
| 11113 |
elsif Is_Private_Type (Typ) then |
| 11114 |
Priv_Typ := Typ; |
| 11115 |
Full_Typ := Full_View (Priv_Typ); |
| 11116 |
|
| 11117 |
-- Otherwise the input type does not have any views |
| 11118 |
|
| 11119 |
else |
| 11120 |
Full_Typ := Typ; |
| 11121 |
end if; |
| 11122 |
|
| 11123 |
if Present (Full_Typ) and then Is_Private_Type (Full_Typ) then |
| 11124 |
UFull_Typ := Underlying_Full_View (Full_Typ); |
| 11125 |
|
| 11126 |
if Present (UFull_Typ) |
| 11127 |
and then Ekind (UFull_Typ) in E_Protected_Type | E_Task_Type |
| 11128 |
then |
| 11129 |
CRec_Typ := Corresponding_Record_Type (UFull_Typ); |
| 11130 |
end if; |
| 11131 |
|
| 11132 |
else |
| 11133 |
if Present (Full_Typ) |
| 11134 |
and then Ekind (Full_Typ) in E_Protected_Type | E_Task_Type |
| 11135 |
then |
| 11136 |
CRec_Typ := Corresponding_Record_Type (Full_Typ); |
| 11137 |
end if; |
| 11138 |
end if; |
| 11139 |
end if; |
| 11140 |
end Get_Views; |
| 11141 |
|
| 11142 |
------------------------------ |
| 11143 |
-- Has_Compatible_Alignment -- |
| 11144 |
------------------------------ |
| 11145 |
|
| 11146 |
function Has_Compatible_Alignment |
| 11147 |
(Obj : Entity_Id; |
| 11148 |
Expr : Node_Id; |
| 11149 |
Layout_Done : Boolean) return Alignment_Result |
| 11150 |
is |
| 11151 |
function Has_Compatible_Alignment_Internal |
| 11152 |
(Obj : Entity_Id; |
| 11153 |
Expr : Node_Id; |
| 11154 |
Layout_Done : Boolean; |
| 11155 |
Default : Alignment_Result) return Alignment_Result; |
| 11156 |
-- This is the internal recursive function that actually does the work. |
| 11157 |
-- There is one additional parameter, which says what the result should |
| 11158 |
-- be if no alignment information is found, and there is no definite |
| 11159 |
-- indication of compatible alignments. At the outer level, this is set |
| 11160 |
-- to Unknown, but for internal recursive calls in the case where types |
| 11161 |
-- are known to be correct, it is set to Known_Compatible. |
| 11162 |
|
| 11163 |
--------------------------------------- |
| 11164 |
-- Has_Compatible_Alignment_Internal -- |
| 11165 |
--------------------------------------- |
| 11166 |
|
| 11167 |
function Has_Compatible_Alignment_Internal |
| 11168 |
(Obj : Entity_Id; |
| 11169 |
Expr : Node_Id; |
| 11170 |
Layout_Done : Boolean; |
| 11171 |
Default : Alignment_Result) return Alignment_Result |
| 11172 |
is |
| 11173 |
Result : Alignment_Result := Known_Compatible; |
| 11174 |
-- Holds the current status of the result. Note that once a value of |
| 11175 |
-- Known_Incompatible is set, it is sticky and does not get changed |
| 11176 |
-- to Unknown (the value in Result only gets worse as we go along, |
| 11177 |
-- never better). |
| 11178 |
|
| 11179 |
Offs : Uint := No_Uint; |
| 11180 |
-- Set to a factor of the offset from the base object when Expr is a |
| 11181 |
-- selected or indexed component, based on Component_Bit_Offset and |
| 11182 |
-- Component_Size respectively. A negative value is used to represent |
| 11183 |
-- a value that is not known at compile time. |
| 11184 |
|
| 11185 |
procedure Check_Prefix; |
| 11186 |
-- Checks the prefix recursively in the case where the expression |
| 11187 |
-- is an indexed or selected component. |
| 11188 |
|
| 11189 |
procedure Set_Result (R : Alignment_Result); |
| 11190 |
-- If R represents a worse outcome (unknown instead of known |
| 11191 |
-- compatible, or known incompatible), then set Result to R. |
| 11192 |
|
| 11193 |
------------------ |
| 11194 |
-- Check_Prefix -- |
| 11195 |
------------------ |
| 11196 |
|
| 11197 |
procedure Check_Prefix is |
| 11198 |
begin |
| 11199 |
-- The subtlety here is that in doing a recursive call to check |
| 11200 |
-- the prefix, we have to decide what to do in the case where we |
| 11201 |
-- don't find any specific indication of an alignment problem. |
| 11202 |
|
| 11203 |
-- At the outer level, we normally set Unknown as the result in |
| 11204 |
-- this case, since we can only set Known_Compatible if we really |
| 11205 |
-- know that the alignment value is OK, but for the recursive |
| 11206 |
-- call, in the case where the types match, and we have not |
| 11207 |
-- specified a peculiar alignment for the object, we are only |
| 11208 |
-- concerned about suspicious rep clauses, the default case does |
| 11209 |
-- not affect us, since the compiler will, in the absence of such |
| 11210 |
-- rep clauses, ensure that the alignment is correct. |
| 11211 |
|
| 11212 |
if Default = Known_Compatible |
| 11213 |
or else |
| 11214 |
(Etype (Obj) = Etype (Expr) |
| 11215 |
and then (not Known_Alignment (Obj) |
| 11216 |
or else |
| 11217 |
Alignment (Obj) = Alignment (Etype (Obj)))) |
| 11218 |
then |
| 11219 |
Set_Result |
| 11220 |
(Has_Compatible_Alignment_Internal |
| 11221 |
(Obj, Prefix (Expr), Layout_Done, Known_Compatible)); |
| 11222 |
|
| 11223 |
-- In all other cases, we need a full check on the prefix |
| 11224 |
|
| 11225 |
else |
| 11226 |
Set_Result |
| 11227 |
(Has_Compatible_Alignment_Internal |
| 11228 |
(Obj, Prefix (Expr), Layout_Done, Unknown)); |
| 11229 |
end if; |
| 11230 |
end Check_Prefix; |
| 11231 |
|
| 11232 |
---------------- |
| 11233 |
-- Set_Result -- |
| 11234 |
---------------- |
| 11235 |
|
| 11236 |
procedure Set_Result (R : Alignment_Result) is |
| 11237 |
begin |
| 11238 |
if R > Result then |
| 11239 |
Result := R; |
| 11240 |
end if; |
| 11241 |
end Set_Result; |
| 11242 |
|
| 11243 |
-- Start of processing for Has_Compatible_Alignment_Internal |
| 11244 |
|
| 11245 |
begin |
| 11246 |
-- If Expr is a selected component, we must make sure there is no |
| 11247 |
-- potentially troublesome component clause and that the record is |
| 11248 |
-- not packed if the layout is not done. |
| 11249 |
|
| 11250 |
if Nkind (Expr) = N_Selected_Component then |
| 11251 |
|
| 11252 |
-- Packing generates unknown alignment if layout is not done |
| 11253 |
|
| 11254 |
if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then |
| 11255 |
Set_Result (Unknown); |
| 11256 |
end if; |
| 11257 |
|
| 11258 |
-- Check prefix and component offset |
| 11259 |
|
| 11260 |
Check_Prefix; |
| 11261 |
Offs := Component_Bit_Offset (Entity (Selector_Name (Expr))); |
| 11262 |
|
| 11263 |
-- If Expr is an indexed component, we must make sure there is no |
| 11264 |
-- potentially troublesome Component_Size clause and that the array |
| 11265 |
-- is not bit-packed if the layout is not done. |
| 11266 |
|
| 11267 |
elsif Nkind (Expr) = N_Indexed_Component then |
| 11268 |
declare |
| 11269 |
Typ : constant Entity_Id := Etype (Prefix (Expr)); |
| 11270 |
|
| 11271 |
begin |
| 11272 |
-- Packing generates unknown alignment if layout is not done |
| 11273 |
|
| 11274 |
if Is_Bit_Packed_Array (Typ) and then not Layout_Done then |
| 11275 |
Set_Result (Unknown); |
| 11276 |
end if; |
| 11277 |
|
| 11278 |
-- Check prefix and component offset (or at least size) |
| 11279 |
|
| 11280 |
Check_Prefix; |
| 11281 |
Offs := Indexed_Component_Bit_Offset (Expr); |
| 11282 |
if No (Offs) then |
| 11283 |
Offs := Component_Size (Typ); |
| 11284 |
end if; |
| 11285 |
end; |
| 11286 |
end if; |
| 11287 |
|
| 11288 |
-- If we have a null offset, the result is entirely determined by |
| 11289 |
-- the base object and has already been computed recursively. |
| 11290 |
|
| 11291 |
if Present (Offs) and then Offs = Uint_0 then |
| 11292 |
null; |
| 11293 |
|
| 11294 |
-- Case where we know the alignment of the object |
| 11295 |
|
| 11296 |
elsif Known_Alignment (Obj) then |
| 11297 |
declare |
| 11298 |
ObjA : constant Uint := Alignment (Obj); |
| 11299 |
ExpA : Uint := No_Uint; |
| 11300 |
SizA : Uint := No_Uint; |
| 11301 |
|
| 11302 |
begin |
| 11303 |
-- If alignment of Obj is 1, then we are always OK |
| 11304 |
|
| 11305 |
if ObjA = 1 then |
| 11306 |
Set_Result (Known_Compatible); |
| 11307 |
|
| 11308 |
-- Alignment of Obj is greater than 1, so we need to check |
| 11309 |
|
| 11310 |
else |
| 11311 |
-- If we have an offset, see if it is compatible |
| 11312 |
|
| 11313 |
if Present (Offs) and then Offs > Uint_0 then |
| 11314 |
if Offs mod (System_Storage_Unit * ObjA) /= 0 then |
| 11315 |
Set_Result (Known_Incompatible); |
| 11316 |
end if; |
| 11317 |
|
| 11318 |
-- See if Expr is an object with known alignment |
| 11319 |
|
| 11320 |
elsif Is_Entity_Name (Expr) |
| 11321 |
and then Known_Alignment (Entity (Expr)) |
| 11322 |
then |
| 11323 |
Offs := Uint_0; |
| 11324 |
ExpA := Alignment (Entity (Expr)); |
| 11325 |
|
| 11326 |
-- Otherwise, we can use the alignment of the type of Expr |
| 11327 |
-- given that we already checked for discombobulating rep |
| 11328 |
-- clauses for the cases of indexed and selected components |
| 11329 |
-- above. |
| 11330 |
|
| 11331 |
elsif Known_Alignment (Etype (Expr)) then |
| 11332 |
ExpA := Alignment (Etype (Expr)); |
| 11333 |
|
| 11334 |
-- Otherwise the alignment is unknown |
| 11335 |
|
| 11336 |
else |
| 11337 |
Set_Result (Default); |
| 11338 |
end if; |
| 11339 |
|
| 11340 |
-- If we got an alignment, see if it is acceptable |
| 11341 |
|
| 11342 |
if Present (ExpA) and then ExpA < ObjA then |
| 11343 |
Set_Result (Known_Incompatible); |
| 11344 |
end if; |
| 11345 |
|
| 11346 |
-- If Expr is a component or an entire object with a known |
| 11347 |
-- alignment, then we are fine. Otherwise, if its size is |
| 11348 |
-- known, it must be big enough for the required alignment. |
| 11349 |
|
| 11350 |
if Present (Offs) then |
| 11351 |
null; |
| 11352 |
|
| 11353 |
-- See if Expr is an object with known size |
| 11354 |
|
| 11355 |
elsif Is_Entity_Name (Expr) |
| 11356 |
and then Known_Static_Esize (Entity (Expr)) |
| 11357 |
then |
| 11358 |
SizA := Esize (Entity (Expr)); |
| 11359 |
|
| 11360 |
-- Otherwise, we check the object size of the Expr type |
| 11361 |
|
| 11362 |
elsif Known_Static_Esize (Etype (Expr)) then |
| 11363 |
SizA := Esize (Etype (Expr)); |
| 11364 |
end if; |
| 11365 |
|
| 11366 |
-- If we got a size, see if it is a multiple of the Obj |
| 11367 |
-- alignment; if not, then the alignment cannot be |
| 11368 |
-- acceptable, since the size is always a multiple of the |
| 11369 |
-- alignment. |
| 11370 |
|
| 11371 |
if Present (SizA) then |
| 11372 |
if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then |
| 11373 |
Set_Result (Known_Incompatible); |
| 11374 |
end if; |
| 11375 |
end if; |
| 11376 |
end if; |
| 11377 |
end; |
| 11378 |
|
| 11379 |
-- If we do not know required alignment, any non-zero offset is a |
| 11380 |
-- potential problem (but certainly may be OK, so result is unknown). |
| 11381 |
|
| 11382 |
elsif Present (Offs) then |
| 11383 |
Set_Result (Unknown); |
| 11384 |
|
| 11385 |
-- If we can't find the result by direct comparison of alignment |
| 11386 |
-- values, then there is still one case that we can determine known |
| 11387 |
-- result, and that is when we can determine that the types are the |
| 11388 |
-- same, and no alignments are specified. Then we known that the |
| 11389 |
-- alignments are compatible, even if we don't know the alignment |
| 11390 |
-- value in the front end. |
| 11391 |
|
| 11392 |
elsif Etype (Obj) = Etype (Expr) then |
| 11393 |
|
| 11394 |
-- Types are the same, but we have to check for possible size |
| 11395 |
-- and alignments on the Expr object that may make the alignment |
| 11396 |
-- different, even though the types are the same. |
| 11397 |
|
| 11398 |
if Is_Entity_Name (Expr) then |
| 11399 |
|
| 11400 |
-- First check alignment of the Expr object. Any alignment less |
| 11401 |
-- than Maximum_Alignment is worrisome since this is the case |
| 11402 |
-- where we do not know the alignment of Obj. |
| 11403 |
|
| 11404 |
if Known_Alignment (Entity (Expr)) |
| 11405 |
and then Alignment (Entity (Expr)) < Ttypes.Maximum_Alignment |
| 11406 |
then |
| 11407 |
Set_Result (Unknown); |
| 11408 |
|
| 11409 |
-- Now check size of Expr object. Any size that is not an even |
| 11410 |
-- multiple of Maximum_Alignment is also worrisome since it |
| 11411 |
-- may cause the alignment of the object to be less than the |
| 11412 |
-- alignment of the type. |
| 11413 |
|
| 11414 |
elsif Known_Static_Esize (Entity (Expr)) |
| 11415 |
and then |
| 11416 |
Esize (Entity (Expr)) mod |
| 11417 |
(Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit) |
| 11418 |
/= 0 |
| 11419 |
then |
| 11420 |
Set_Result (Unknown); |
| 11421 |
|
| 11422 |
-- Otherwise same type is decisive |
| 11423 |
|
| 11424 |
else |
| 11425 |
Set_Result (Known_Compatible); |
| 11426 |
end if; |
| 11427 |
end if; |
| 11428 |
|
| 11429 |
-- Another case to deal with is when there is an explicit size or |
| 11430 |
-- alignment clause when the types are not the same. If so, then the |
| 11431 |
-- result is Unknown. We don't need to do this test if the Default is |
| 11432 |
-- Unknown, since that result will be set in any case. |
| 11433 |
|
| 11434 |
elsif Default /= Unknown |
| 11435 |
and then (Has_Size_Clause (Etype (Expr)) |
| 11436 |
or else |
| 11437 |
Has_Alignment_Clause (Etype (Expr))) |
| 11438 |
then |
| 11439 |
Set_Result (Unknown); |
| 11440 |
|
| 11441 |
-- If no indication found, set default |
| 11442 |
|
| 11443 |
else |
| 11444 |
Set_Result (Default); |
| 11445 |
end if; |
| 11446 |
|
| 11447 |
-- Return worst result found |
| 11448 |
|
| 11449 |
return Result; |
| 11450 |
end Has_Compatible_Alignment_Internal; |
| 11451 |
|
| 11452 |
-- Start of processing for Has_Compatible_Alignment |
| 11453 |
|
| 11454 |
begin |
| 11455 |
-- If Obj has no specified alignment, then set alignment from the type |
| 11456 |
-- alignment. Perhaps we should always do this, but for sure we should |
| 11457 |
-- do it when there is an address clause since we can do more if the |
| 11458 |
-- alignment is known. |
| 11459 |
|
| 11460 |
if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then |
| 11461 |
Set_Alignment (Obj, Alignment (Etype (Obj))); |
| 11462 |
end if; |
| 11463 |
|
| 11464 |
-- Now do the internal call that does all the work |
| 11465 |
|
| 11466 |
return |
| 11467 |
Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown); |
| 11468 |
end Has_Compatible_Alignment; |
| 11469 |
|
| 11470 |
---------------------- |
| 11471 |
-- Has_Declarations -- |
| 11472 |
---------------------- |
| 11473 |
|
| 11474 |
function Has_Declarations (N : Node_Id) return Boolean is |
| 11475 |
begin |
| 11476 |
return Nkind (N) in N_Accept_Statement |
| 11477 |
| N_Block_Statement |
| 11478 |
| N_Compilation_Unit_Aux |
| 11479 |
| N_Entry_Body |
| 11480 |
| N_Package_Body |
| 11481 |
| N_Protected_Body |
| 11482 |
| N_Subprogram_Body |
| 11483 |
| N_Task_Body |
| 11484 |
| N_Package_Specification; |
| 11485 |
end Has_Declarations; |
| 11486 |
|
| 11487 |
--------------------------------- |
| 11488 |
-- Has_Defaulted_Discriminants -- |
| 11489 |
--------------------------------- |
| 11490 |
|
| 11491 |
function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is |
| 11492 |
begin |
| 11493 |
return Has_Discriminants (Typ) |
| 11494 |
and then Present (Discriminant_Default_Value |
| 11495 |
(First_Discriminant (Typ))); |
| 11496 |
end Has_Defaulted_Discriminants; |
| 11497 |
|
| 11498 |
------------------- |
| 11499 |
-- Has_Denormals -- |
| 11500 |
------------------- |
| 11501 |
|
| 11502 |
function Has_Denormals (E : Entity_Id) return Boolean is |
| 11503 |
begin |
| 11504 |
return Is_Floating_Point_Type (E) and then Denorm_On_Target; |
| 11505 |
end Has_Denormals; |
| 11506 |
|
| 11507 |
------------------------------------------- |
| 11508 |
-- Has_Discriminant_Dependent_Constraint -- |
| 11509 |
------------------------------------------- |
| 11510 |
|
| 11511 |
function Has_Discriminant_Dependent_Constraint |
| 11512 |
(Comp : Entity_Id) return Boolean |
| 11513 |
is |
| 11514 |
Comp_Decl : constant Node_Id := Parent (Comp); |
| 11515 |
Subt_Indic : Node_Id; |
| 11516 |
Constr : Node_Id; |
| 11517 |
Assn : Node_Id; |
| 11518 |
|
| 11519 |
begin |
| 11520 |
-- Discriminants can't depend on discriminants |
| 11521 |
|
| 11522 |
if Ekind (Comp) = E_Discriminant then |
| 11523 |
return False; |
| 11524 |
|
| 11525 |
else |
| 11526 |
Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl)); |
| 11527 |
|
| 11528 |
if Nkind (Subt_Indic) = N_Subtype_Indication then |
| 11529 |
Constr := Constraint (Subt_Indic); |
| 11530 |
|
| 11531 |
if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then |
| 11532 |
Assn := First (Constraints (Constr)); |
| 11533 |
while Present (Assn) loop |
| 11534 |
case Nkind (Assn) is |
| 11535 |
when N_Identifier |
| 11536 |
| N_Range |
| 11537 |
| N_Subtype_Indication |
| 11538 |
=> |
| 11539 |
if Depends_On_Discriminant (Assn) then |
| 11540 |
return True; |
| 11541 |
end if; |
| 11542 |
|
| 11543 |
when N_Discriminant_Association => |
| 11544 |
if Depends_On_Discriminant (Expression (Assn)) then |
| 11545 |
return True; |
| 11546 |
end if; |
| 11547 |
|
| 11548 |
when others => |
| 11549 |
null; |
| 11550 |
end case; |
| 11551 |
|
| 11552 |
Next (Assn); |
| 11553 |
end loop; |
| 11554 |
end if; |
| 11555 |
end if; |
| 11556 |
end if; |
| 11557 |
|
| 11558 |
return False; |
| 11559 |
end Has_Discriminant_Dependent_Constraint; |
| 11560 |
|
| 11561 |
-------------------------------------- |
| 11562 |
-- Has_Effectively_Volatile_Profile -- |
| 11563 |
-------------------------------------- |
| 11564 |
|
| 11565 |
function Has_Effectively_Volatile_Profile |
| 11566 |
(Subp_Id : Entity_Id) return Boolean |
| 11567 |
is |
| 11568 |
Formal : Entity_Id; |
| 11569 |
|
| 11570 |
begin |
| 11571 |
-- Inspect the formal parameters looking for an effectively volatile |
| 11572 |
-- type for reading. |
| 11573 |
|
| 11574 |
Formal := First_Formal (Subp_Id); |
| 11575 |
while Present (Formal) loop |
| 11576 |
if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then |
| 11577 |
return True; |
| 11578 |
end if; |
| 11579 |
|
| 11580 |
Next_Formal (Formal); |
| 11581 |
end loop; |
| 11582 |
|
| 11583 |
-- Inspect the return type of functions |
| 11584 |
|
| 11585 |
if Ekind (Subp_Id) in E_Function | E_Generic_Function |
| 11586 |
and then Is_Effectively_Volatile_For_Reading (Etype (Subp_Id)) |
| 11587 |
then |
| 11588 |
return True; |
| 11589 |
end if; |
| 11590 |
|
| 11591 |
return False; |
| 11592 |
end Has_Effectively_Volatile_Profile; |
| 11593 |
|
| 11594 |
-------------------------- |
| 11595 |
-- Has_Enabled_Property -- |
| 11596 |
-------------------------- |
| 11597 |
|
| 11598 |
function Has_Enabled_Property |
| 11599 |
(Item_Id : Entity_Id; |
| 11600 |
Property : Name_Id) return Boolean |
| 11601 |
is |
| 11602 |
function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean; |
| 11603 |
-- Determine whether a protected type or variable denoted by Item_Id |
| 11604 |
-- has the property enabled. |
| 11605 |
|
| 11606 |
function State_Has_Enabled_Property return Boolean; |
| 11607 |
-- Determine whether a state denoted by Item_Id has the property enabled |
| 11608 |
|
| 11609 |
function Type_Or_Variable_Has_Enabled_Property |
| 11610 |
(Item_Id : Entity_Id) return Boolean; |
| 11611 |
-- Determine whether type or variable denoted by Item_Id has the |
| 11612 |
-- property enabled. |
| 11613 |
|
| 11614 |
----------------------------------------------------- |
| 11615 |
-- Protected_Type_Or_Variable_Has_Enabled_Property -- |
| 11616 |
----------------------------------------------------- |
| 11617 |
|
| 11618 |
function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean |
| 11619 |
is |
| 11620 |
begin |
| 11621 |
-- Protected entities always have the properties Async_Readers and |
| 11622 |
-- Async_Writers (SPARK RM 7.1.2(16)). |
| 11623 |
|
| 11624 |
if Property = Name_Async_Readers |
| 11625 |
or else Property = Name_Async_Writers |
| 11626 |
then |
| 11627 |
return True; |
| 11628 |
|
| 11629 |
-- Protected objects that have Part_Of components also inherit their |
| 11630 |
-- properties Effective_Reads and Effective_Writes |
| 11631 |
-- (SPARK RM 7.1.2(16)). |
| 11632 |
|
| 11633 |
elsif Is_Single_Protected_Object (Item_Id) then |
| 11634 |
declare |
| 11635 |
Constit_Elmt : Elmt_Id; |
| 11636 |
Constit_Id : Entity_Id; |
| 11637 |
Constits : constant Elist_Id := |
| 11638 |
Part_Of_Constituents (Item_Id); |
| 11639 |
begin |
| 11640 |
if Present (Constits) then |
| 11641 |
Constit_Elmt := First_Elmt (Constits); |
| 11642 |
while Present (Constit_Elmt) loop |
| 11643 |
Constit_Id := Node (Constit_Elmt); |
| 11644 |
|
| 11645 |
if Has_Enabled_Property (Constit_Id, Property) then |
| 11646 |
return True; |
| 11647 |
end if; |
| 11648 |
|
| 11649 |
Next_Elmt (Constit_Elmt); |
| 11650 |
end loop; |
| 11651 |
end if; |
| 11652 |
end; |
| 11653 |
end if; |
| 11654 |
|
| 11655 |
return False; |
| 11656 |
end Protected_Type_Or_Variable_Has_Enabled_Property; |
| 11657 |
|
| 11658 |
-------------------------------- |
| 11659 |
-- State_Has_Enabled_Property -- |
| 11660 |
-------------------------------- |
| 11661 |
|
| 11662 |
function State_Has_Enabled_Property return Boolean is |
| 11663 |
Decl : constant Node_Id := Parent (Item_Id); |
| 11664 |
|
| 11665 |
procedure Find_Simple_Properties |
| 11666 |
(Has_External : out Boolean; |
| 11667 |
Has_Synchronous : out Boolean); |
| 11668 |
-- Extract the simple properties associated with declaration Decl |
| 11669 |
|
| 11670 |
function Is_Enabled_External_Property return Boolean; |
| 11671 |
-- Determine whether property Property appears within the external |
| 11672 |
-- property list of declaration Decl, and return its status. |
| 11673 |
|
| 11674 |
---------------------------- |
| 11675 |
-- Find_Simple_Properties -- |
| 11676 |
---------------------------- |
| 11677 |
|
| 11678 |
procedure Find_Simple_Properties |
| 11679 |
(Has_External : out Boolean; |
| 11680 |
Has_Synchronous : out Boolean) |
| 11681 |
is |
| 11682 |
Opt : Node_Id; |
| 11683 |
|
| 11684 |
begin |
| 11685 |
-- Assume that none of the properties are available |
| 11686 |
|
| 11687 |
Has_External := False; |
| 11688 |
Has_Synchronous := False; |
| 11689 |
|
| 11690 |
Opt := First (Expressions (Decl)); |
| 11691 |
while Present (Opt) loop |
| 11692 |
if Nkind (Opt) = N_Identifier then |
| 11693 |
if Chars (Opt) = Name_External then |
| 11694 |
Has_External := True; |
| 11695 |
|
| 11696 |
elsif Chars (Opt) = Name_Synchronous then |
| 11697 |
Has_Synchronous := True; |
| 11698 |
end if; |
| 11699 |
end if; |
| 11700 |
|
| 11701 |
Next (Opt); |
| 11702 |
end loop; |
| 11703 |
end Find_Simple_Properties; |
| 11704 |
|
| 11705 |
---------------------------------- |
| 11706 |
-- Is_Enabled_External_Property -- |
| 11707 |
---------------------------------- |
| 11708 |
|
| 11709 |
function Is_Enabled_External_Property return Boolean is |
| 11710 |
Opt : Node_Id; |
| 11711 |
Opt_Nam : Node_Id; |
| 11712 |
Prop : Node_Id; |
| 11713 |
Prop_Nam : Node_Id; |
| 11714 |
Props : Node_Id; |
| 11715 |
|
| 11716 |
begin |
| 11717 |
Opt := First (Component_Associations (Decl)); |
| 11718 |
while Present (Opt) loop |
| 11719 |
Opt_Nam := First (Choices (Opt)); |
| 11720 |
|
| 11721 |
if Nkind (Opt_Nam) = N_Identifier |
| 11722 |
and then Chars (Opt_Nam) = Name_External |
| 11723 |
then |
| 11724 |
Props := Expression (Opt); |
| 11725 |
|
| 11726 |
-- Multiple properties appear as an aggregate |
| 11727 |
|
| 11728 |
if Nkind (Props) = N_Aggregate then |
| 11729 |
|
| 11730 |
-- Simple property form |
| 11731 |
|
| 11732 |
Prop := First (Expressions (Props)); |
| 11733 |
while Present (Prop) loop |
| 11734 |
if Chars (Prop) = Property then |
| 11735 |
return True; |
| 11736 |
end if; |
| 11737 |
|
| 11738 |
Next (Prop); |
| 11739 |
end loop; |
| 11740 |
|
| 11741 |
-- Property with expression form |
| 11742 |
|
| 11743 |
Prop := First (Component_Associations (Props)); |
| 11744 |
while Present (Prop) loop |
| 11745 |
Prop_Nam := First (Choices (Prop)); |
| 11746 |
|
| 11747 |
-- The property can be represented in two ways: |
| 11748 |
-- others => <value> |
| 11749 |
-- <property> => <value> |
| 11750 |
|
| 11751 |
if Nkind (Prop_Nam) = N_Others_Choice |
| 11752 |
or else (Nkind (Prop_Nam) = N_Identifier |
| 11753 |
and then Chars (Prop_Nam) = Property) |
| 11754 |
then |
| 11755 |
return Is_True (Expr_Value (Expression (Prop))); |
| 11756 |
end if; |
| 11757 |
|
| 11758 |
Next (Prop); |
| 11759 |
end loop; |
| 11760 |
|
| 11761 |
-- Single property |
| 11762 |
|
| 11763 |
else |
| 11764 |
return Chars (Props) = Property; |
| 11765 |
end if; |
| 11766 |
end if; |
| 11767 |
|
| 11768 |
Next (Opt); |
| 11769 |
end loop; |
| 11770 |
|
| 11771 |
return False; |
| 11772 |
end Is_Enabled_External_Property; |
| 11773 |
|
| 11774 |
-- Local variables |
| 11775 |
|
| 11776 |
Has_External : Boolean; |
| 11777 |
Has_Synchronous : Boolean; |
| 11778 |
|
| 11779 |
-- Start of processing for State_Has_Enabled_Property |
| 11780 |
|
| 11781 |
begin |
| 11782 |
-- The declaration of an external abstract state appears as an |
| 11783 |
-- extension aggregate. If this is not the case, properties can |
| 11784 |
-- never be set. |
| 11785 |
|
| 11786 |
if Nkind (Decl) /= N_Extension_Aggregate then |
| 11787 |
return False; |
| 11788 |
end if; |
| 11789 |
|
| 11790 |
Find_Simple_Properties (Has_External, Has_Synchronous); |
| 11791 |
|
| 11792 |
-- Simple option External enables all properties (SPARK RM 7.1.2(2)) |
| 11793 |
|
| 11794 |
if Has_External then |
| 11795 |
return True; |
| 11796 |
|
| 11797 |
-- Option External may enable or disable specific properties |
| 11798 |
|
| 11799 |
elsif Is_Enabled_External_Property then |
| 11800 |
return True; |
| 11801 |
|
| 11802 |
-- Simple option Synchronous |
| 11803 |
-- |
| 11804 |
-- enables disables |
| 11805 |
-- Async_Readers Effective_Reads |
| 11806 |
-- Async_Writers Effective_Writes |
| 11807 |
-- |
| 11808 |
-- Note that both forms of External have higher precedence than |
| 11809 |
-- Synchronous (SPARK RM 7.1.4(9)). |
| 11810 |
|
| 11811 |
elsif Has_Synchronous then |
| 11812 |
return Property in Name_Async_Readers | Name_Async_Writers; |
| 11813 |
end if; |
| 11814 |
|
| 11815 |
return False; |
| 11816 |
end State_Has_Enabled_Property; |
| 11817 |
|
| 11818 |
------------------------------------------- |
| 11819 |
-- Type_Or_Variable_Has_Enabled_Property -- |
| 11820 |
------------------------------------------- |
| 11821 |
|
| 11822 |
function Type_Or_Variable_Has_Enabled_Property |
| 11823 |
(Item_Id : Entity_Id) return Boolean |
| 11824 |
is |
| 11825 |
AR : constant Node_Id := |
| 11826 |
Get_Pragma (Item_Id, Pragma_Async_Readers); |
| 11827 |
AW : constant Node_Id := |
| 11828 |
Get_Pragma (Item_Id, Pragma_Async_Writers); |
| 11829 |
ER : constant Node_Id := |
| 11830 |
Get_Pragma (Item_Id, Pragma_Effective_Reads); |
| 11831 |
EW : constant Node_Id := |
| 11832 |
Get_Pragma (Item_Id, Pragma_Effective_Writes); |
| 11833 |
|
| 11834 |
Is_Derived_Type_With_Volatile_Parent_Type : constant Boolean := |
| 11835 |
Is_Derived_Type (Item_Id) |
| 11836 |
and then Is_Effectively_Volatile (Etype (Base_Type (Item_Id))); |
| 11837 |
|
| 11838 |
begin |
| 11839 |
-- A non-effectively volatile object can never possess external |
| 11840 |
-- properties. |
| 11841 |
|
| 11842 |
if not Is_Effectively_Volatile (Item_Id) then |
| 11843 |
return False; |
| 11844 |
|
| 11845 |
-- External properties related to variables come in two flavors - |
| 11846 |
-- explicit and implicit. The explicit case is characterized by the |
| 11847 |
-- presence of a property pragma with an optional Boolean flag. The |
| 11848 |
-- property is enabled when the flag evaluates to True or the flag is |
| 11849 |
-- missing altogether. |
| 11850 |
|
| 11851 |
elsif Property = Name_Async_Readers and then Present (AR) then |
| 11852 |
return Is_Enabled_Pragma (AR); |
| 11853 |
|
| 11854 |
elsif Property = Name_Async_Writers and then Present (AW) then |
| 11855 |
return Is_Enabled_Pragma (AW); |
| 11856 |
|
| 11857 |
elsif Property = Name_Effective_Reads and then Present (ER) then |
| 11858 |
return Is_Enabled_Pragma (ER); |
| 11859 |
|
| 11860 |
elsif Property = Name_Effective_Writes and then Present (EW) then |
| 11861 |
return Is_Enabled_Pragma (EW); |
| 11862 |
|
| 11863 |
-- If other properties are set explicitly, then this one is set |
| 11864 |
-- implicitly to False, except in the case of a derived type |
| 11865 |
-- whose parent type is volatile (in that case, we will inherit |
| 11866 |
-- from the parent type, below). |
| 11867 |
|
| 11868 |
elsif (Present (AR) |
| 11869 |
or else Present (AW) |
| 11870 |
or else Present (ER) |
| 11871 |
or else Present (EW)) |
| 11872 |
and then not Is_Derived_Type_With_Volatile_Parent_Type |
| 11873 |
then |
| 11874 |
return False; |
| 11875 |
|
| 11876 |
-- For a private type (including subtype of a private types), look at |
| 11877 |
-- the full view. |
| 11878 |
|
| 11879 |
elsif Is_Private_Type (Item_Id) and then Present (Full_View (Item_Id)) |
| 11880 |
then |
| 11881 |
return Type_Or_Variable_Has_Enabled_Property (Full_View (Item_Id)); |
| 11882 |
|
| 11883 |
-- For a derived type whose parent type is volatile, the |
| 11884 |
-- property may be inherited (but ignore a non-volatile parent). |
| 11885 |
|
| 11886 |
elsif Is_Derived_Type_With_Volatile_Parent_Type then |
| 11887 |
return Type_Or_Variable_Has_Enabled_Property |
| 11888 |
(First_Subtype (Etype (Base_Type (Item_Id)))); |
| 11889 |
|
| 11890 |
-- For a subtype, the property will be inherited from its base type. |
| 11891 |
|
| 11892 |
elsif Is_Type (Item_Id) |
| 11893 |
and then not Is_Base_Type (Item_Id) |
| 11894 |
then |
| 11895 |
return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id)); |
| 11896 |
|
| 11897 |
-- If not specified explicitly for an object and its type |
| 11898 |
-- is effectively volatile, then take result from the type. |
| 11899 |
|
| 11900 |
elsif Is_Object (Item_Id) |
| 11901 |
and then Is_Effectively_Volatile (Etype (Item_Id)) |
| 11902 |
then |
| 11903 |
return Has_Enabled_Property (Etype (Item_Id), Property); |
| 11904 |
|
| 11905 |
-- The implicit case lacks all property pragmas |
| 11906 |
|
| 11907 |
elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then |
| 11908 |
if Is_Protected_Type (Etype (Item_Id)) then |
| 11909 |
return Protected_Type_Or_Variable_Has_Enabled_Property; |
| 11910 |
else |
| 11911 |
return True; |
| 11912 |
end if; |
| 11913 |
|
| 11914 |
else |
| 11915 |
return False; |
| 11916 |
end if; |
| 11917 |
end Type_Or_Variable_Has_Enabled_Property; |
| 11918 |
|
| 11919 |
-- Start of processing for Has_Enabled_Property |
| 11920 |
|
| 11921 |
begin |
| 11922 |
-- Abstract states and variables have a flexible scheme of specifying |
| 11923 |
-- external properties. |
| 11924 |
|
| 11925 |
if Ekind (Item_Id) = E_Abstract_State then |
| 11926 |
return State_Has_Enabled_Property; |
| 11927 |
|
| 11928 |
elsif Ekind (Item_Id) in E_Variable | E_Constant then |
| 11929 |
return Type_Or_Variable_Has_Enabled_Property (Item_Id); |
| 11930 |
|
| 11931 |
-- Other objects can only inherit properties through their type. We |
| 11932 |
-- cannot call directly Type_Or_Variable_Has_Enabled_Property on |
| 11933 |
-- these as they don't have contracts attached, which is expected by |
| 11934 |
-- this function. |
| 11935 |
|
| 11936 |
elsif Is_Object (Item_Id) then |
| 11937 |
return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id)); |
| 11938 |
|
| 11939 |
elsif Is_Type (Item_Id) then |
| 11940 |
return Type_Or_Variable_Has_Enabled_Property |
| 11941 |
(Item_Id => First_Subtype (Item_Id)); |
| 11942 |
|
| 11943 |
-- Otherwise a property is enabled when the related item is effectively |
| 11944 |
-- volatile. |
| 11945 |
|
| 11946 |
else |
| 11947 |
return Is_Effectively_Volatile (Item_Id); |
| 11948 |
end if; |
| 11949 |
end Has_Enabled_Property; |
| 11950 |
|
| 11951 |
------------------------------------- |
| 11952 |
-- Has_Full_Default_Initialization -- |
| 11953 |
------------------------------------- |
| 11954 |
|
| 11955 |
function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is |
| 11956 |
Comp : Entity_Id; |
| 11957 |
|
| 11958 |
begin |
| 11959 |
-- A type subject to pragma Default_Initial_Condition may be fully |
| 11960 |
-- default initialized depending on inheritance and the argument of |
| 11961 |
-- the pragma. Since any type may act as the full view of a private |
| 11962 |
-- type, this check must be performed prior to the specialized tests |
| 11963 |
-- below. |
| 11964 |
|
| 11965 |
if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then |
| 11966 |
return True; |
| 11967 |
end if; |
| 11968 |
|
| 11969 |
-- A scalar type is fully default initialized if it is subject to aspect |
| 11970 |
-- Default_Value. |
| 11971 |
|
| 11972 |
if Is_Scalar_Type (Typ) then |
| 11973 |
return Has_Default_Aspect (Typ); |
| 11974 |
|
| 11975 |
-- An access type is fully default initialized by default |
| 11976 |
|
| 11977 |
elsif Is_Access_Type (Typ) then |
| 11978 |
return True; |
| 11979 |
|
| 11980 |
-- An array type is fully default initialized if its element type is |
| 11981 |
-- scalar and the array type carries aspect Default_Component_Value or |
| 11982 |
-- the element type is fully default initialized. |
| 11983 |
|
| 11984 |
elsif Is_Array_Type (Typ) then |
| 11985 |
return |
| 11986 |
Has_Default_Aspect (Typ) |
| 11987 |
or else Has_Full_Default_Initialization (Component_Type (Typ)); |
| 11988 |
|
| 11989 |
-- A protected type, record type, or type extension is fully default |
| 11990 |
-- initialized if all its components either carry an initialization |
| 11991 |
-- expression or have a type that is fully default initialized. The |
| 11992 |
-- parent type of a type extension must be fully default initialized. |
| 11993 |
|
| 11994 |
elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then |
| 11995 |
|
| 11996 |
-- Inspect all entities defined in the scope of the type, looking for |
| 11997 |
-- uninitialized components. |
| 11998 |
|
| 11999 |
Comp := First_Component (Typ); |
| 12000 |
while Present (Comp) loop |
| 12001 |
if Comes_From_Source (Comp) |
| 12002 |
and then No (Expression (Parent (Comp))) |
| 12003 |
and then not Has_Full_Default_Initialization (Etype (Comp)) |
| 12004 |
then |
| 12005 |
return False; |
| 12006 |
end if; |
| 12007 |
|
| 12008 |
Next_Component (Comp); |
| 12009 |
end loop; |
| 12010 |
|
| 12011 |
-- Ensure that the parent type of a type extension is fully default |
| 12012 |
-- initialized. |
| 12013 |
|
| 12014 |
if Etype (Typ) /= Typ |
| 12015 |
and then not Has_Full_Default_Initialization (Etype (Typ)) |
| 12016 |
then |
| 12017 |
return False; |
| 12018 |
end if; |
| 12019 |
|
| 12020 |
-- If we get here, then all components and parent portion are fully |
| 12021 |
-- default initialized. |
| 12022 |
|
| 12023 |
return True; |
| 12024 |
|
| 12025 |
-- A task type is fully default initialized by default |
| 12026 |
|
| 12027 |
elsif Is_Task_Type (Typ) then |
| 12028 |
return True; |
| 12029 |
|
| 12030 |
-- Otherwise the type is not fully default initialized |
| 12031 |
|
| 12032 |
else |
| 12033 |
return False; |
| 12034 |
end if; |
| 12035 |
end Has_Full_Default_Initialization; |
| 12036 |
|
| 12037 |
----------------------------------------------- |
| 12038 |
-- Has_Fully_Default_Initializing_DIC_Pragma -- |
| 12039 |
----------------------------------------------- |
| 12040 |
|
| 12041 |
function Has_Fully_Default_Initializing_DIC_Pragma |
| 12042 |
(Typ : Entity_Id) return Boolean |
| 12043 |
is |
| 12044 |
Args : List_Id; |
| 12045 |
Prag : Node_Id; |
| 12046 |
|
| 12047 |
begin |
| 12048 |
-- A type that inherits pragma Default_Initial_Condition from a parent |
| 12049 |
-- type is automatically fully default initialized. |
| 12050 |
|
| 12051 |
if Has_Inherited_DIC (Typ) then |
| 12052 |
return True; |
| 12053 |
|
| 12054 |
-- Otherwise the type is fully default initialized only when the pragma |
| 12055 |
-- appears without an argument, or the argument is non-null. |
| 12056 |
|
| 12057 |
elsif Has_Own_DIC (Typ) then |
| 12058 |
Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition); |
| 12059 |
pragma Assert (Present (Prag)); |
| 12060 |
Args := Pragma_Argument_Associations (Prag); |
| 12061 |
|
| 12062 |
-- The pragma appears without an argument in which case it defaults |
| 12063 |
-- to True. |
| 12064 |
|
| 12065 |
if No (Args) then |
| 12066 |
return True; |
| 12067 |
|
| 12068 |
-- The pragma appears with a non-null expression |
| 12069 |
|
| 12070 |
elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then |
| 12071 |
return True; |
| 12072 |
end if; |
| 12073 |
end if; |
| 12074 |
|
| 12075 |
return False; |
| 12076 |
end Has_Fully_Default_Initializing_DIC_Pragma; |
| 12077 |
|
| 12078 |
--------------------------------- |
| 12079 |
-- Has_Inferable_Discriminants -- |
| 12080 |
--------------------------------- |
| 12081 |
|
| 12082 |
function Has_Inferable_Discriminants (N : Node_Id) return Boolean is |
| 12083 |
|
| 12084 |
function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean; |
| 12085 |
-- Determines whether the left-most prefix of a selected component is a |
| 12086 |
-- formal parameter in a subprogram. Assumes N is a selected component. |
| 12087 |
|
| 12088 |
-------------------------------- |
| 12089 |
-- Prefix_Is_Formal_Parameter -- |
| 12090 |
-------------------------------- |
| 12091 |
|
| 12092 |
function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is |
| 12093 |
Sel_Comp : Node_Id; |
| 12094 |
|
| 12095 |
begin |
| 12096 |
-- Move to the left-most prefix by climbing up the tree |
| 12097 |
|
| 12098 |
Sel_Comp := N; |
| 12099 |
while Present (Parent (Sel_Comp)) |
| 12100 |
and then Nkind (Parent (Sel_Comp)) = N_Selected_Component |
| 12101 |
loop |
| 12102 |
Sel_Comp := Parent (Sel_Comp); |
| 12103 |
end loop; |
| 12104 |
|
| 12105 |
return Is_Formal (Entity (Prefix (Sel_Comp))); |
| 12106 |
end Prefix_Is_Formal_Parameter; |
| 12107 |
|
| 12108 |
-- Start of processing for Has_Inferable_Discriminants |
| 12109 |
|
| 12110 |
begin |
| 12111 |
-- For selected components, the subtype of the selector must be a |
| 12112 |
-- constrained Unchecked_Union. If the component is subject to a |
| 12113 |
-- per-object constraint, then the enclosing object must either be |
| 12114 |
-- a regular discriminated type or must have inferable discriminants. |
| 12115 |
|
| 12116 |
if Nkind (N) = N_Selected_Component then |
| 12117 |
-- The call to Has_Inferable_Discriminants will determine whether |
| 12118 |
-- the selector has a constrained Unchecked_Union nominal type. |
| 12119 |
|
| 12120 |
if not Has_Inferable_Discriminants (Selector_Name (N)) then |
| 12121 |
return False; |
| 12122 |
end if; |
| 12123 |
|
| 12124 |
-- A small hack. If we have a per-object constrained selected |
| 12125 |
-- component of a formal parameter, return True since we do not |
| 12126 |
-- know the actual parameter association yet. |
| 12127 |
|
| 12128 |
return not Has_Per_Object_Constraint (Entity (Selector_Name (N))) |
| 12129 |
or else not Is_Unchecked_Union (Etype (Prefix (N))) |
| 12130 |
or else Has_Inferable_Discriminants (Prefix (N)) |
| 12131 |
or else Prefix_Is_Formal_Parameter (N); |
| 12132 |
|
| 12133 |
-- A qualified expression has inferable discriminants if its subtype |
| 12134 |
-- mark is a constrained Unchecked_Union subtype. |
| 12135 |
|
| 12136 |
elsif Nkind (N) = N_Qualified_Expression then |
| 12137 |
return Is_Unchecked_Union (Etype (Subtype_Mark (N))) |
| 12138 |
and then Is_Constrained (Etype (Subtype_Mark (N))); |
| 12139 |
|
| 12140 |
-- For all other names, it is sufficient to have a constrained |
| 12141 |
-- Unchecked_Union nominal subtype, unless it is incomplete or |
| 12142 |
-- private because it cannot have a known discriminant part in |
| 12143 |
-- this case (RM B.3.3 (11/2)). |
| 12144 |
|
| 12145 |
else |
| 12146 |
return Is_Unchecked_Union (Etype (N)) |
| 12147 |
and then Is_Constrained (Etype (N)) |
| 12148 |
and then not Is_Incomplete_Or_Private_Type (Etype (N)); |
| 12149 |
end if; |
| 12150 |
end Has_Inferable_Discriminants; |
| 12151 |
|
| 12152 |
-------------------- |
| 12153 |
-- Has_Infinities -- |
| 12154 |
-------------------- |
| 12155 |
|
| 12156 |
function Has_Infinities (E : Entity_Id) return Boolean is |
| 12157 |
begin |
| 12158 |
return |
| 12159 |
Is_Floating_Point_Type (E) |
| 12160 |
and then Nkind (Scalar_Range (E)) = N_Range |
| 12161 |
and then Includes_Infinities (Scalar_Range (E)); |
| 12162 |
end Has_Infinities; |
| 12163 |
|
| 12164 |
-------------------- |
| 12165 |
-- Has_Interfaces -- |
| 12166 |
-------------------- |
| 12167 |
|
| 12168 |
function Has_Interfaces |
| 12169 |
(T : Entity_Id; |
| 12170 |
Use_Full_View : Boolean := True) return Boolean |
| 12171 |
is |
| 12172 |
Typ : Entity_Id := Base_Type (T); |
| 12173 |
|
| 12174 |
begin |
| 12175 |
-- Handle concurrent types |
| 12176 |
|
| 12177 |
if Is_Concurrent_Type (Typ) then |
| 12178 |
Typ := Corresponding_Record_Type (Typ); |
| 12179 |
end if; |
| 12180 |
|
| 12181 |
if No (Typ) |
| 12182 |
or else not Is_Record_Type (Typ) |
| 12183 |
or else not Is_Tagged_Type (Typ) |
| 12184 |
then |
| 12185 |
return False; |
| 12186 |
end if; |
| 12187 |
|
| 12188 |
-- Handle private types |
| 12189 |
|
| 12190 |
if Use_Full_View and then Present (Full_View (Typ)) then |
| 12191 |
Typ := Full_View (Typ); |
| 12192 |
end if; |
| 12193 |
|
| 12194 |
-- Handle concurrent record types |
| 12195 |
|
| 12196 |
if Is_Concurrent_Record_Type (Typ) |
| 12197 |
and then Is_Non_Empty_List (Abstract_Interface_List (Typ)) |
| 12198 |
then |
| 12199 |
return True; |
| 12200 |
end if; |
| 12201 |
|
| 12202 |
loop |
| 12203 |
if Is_Interface (Typ) |
| 12204 |
or else |
| 12205 |
(Is_Record_Type (Typ) |
| 12206 |
and then Present (Interfaces (Typ)) |
| 12207 |
and then not Is_Empty_Elmt_List (Interfaces (Typ))) |
| 12208 |
then |
| 12209 |
return True; |
| 12210 |
end if; |
| 12211 |
|
| 12212 |
exit when Etype (Typ) = Typ |
| 12213 |
|
| 12214 |
-- Handle private types |
| 12215 |
|
| 12216 |
or else (Present (Full_View (Etype (Typ))) |
| 12217 |
and then Full_View (Etype (Typ)) = Typ) |
| 12218 |
|
| 12219 |
-- Protect frontend against wrong sources with cyclic derivations |
| 12220 |
|
| 12221 |
or else Etype (Typ) = T; |
| 12222 |
|
| 12223 |
-- Climb to the ancestor type handling private types |
| 12224 |
|
| 12225 |
if Present (Full_View (Etype (Typ))) then |
| 12226 |
Typ := Full_View (Etype (Typ)); |
| 12227 |
else |
| 12228 |
Typ := Etype (Typ); |
| 12229 |
end if; |
| 12230 |
end loop; |
| 12231 |
|
| 12232 |
return False; |
| 12233 |
end Has_Interfaces; |
| 12234 |
|
| 12235 |
-------------------------- |
| 12236 |
-- Has_Max_Queue_Length -- |
| 12237 |
-------------------------- |
| 12238 |
|
| 12239 |
function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is |
| 12240 |
begin |
| 12241 |
return |
| 12242 |
Ekind (Id) = E_Entry |
| 12243 |
and then |
| 12244 |
(Present (Get_Pragma (Id, Pragma_Max_Queue_Length)) |
| 12245 |
or else |
| 12246 |
Present (Get_Pragma (Id, Pragma_Max_Entry_Queue_Length))); |
| 12247 |
end Has_Max_Queue_Length; |
| 12248 |
|
| 12249 |
--------------------------------- |
| 12250 |
-- Has_No_Obvious_Side_Effects -- |
| 12251 |
--------------------------------- |
| 12252 |
|
| 12253 |
function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is |
| 12254 |
begin |
| 12255 |
-- For now handle literals, constants, and non-volatile variables and |
| 12256 |
-- expressions combining these with operators or short circuit forms. |
| 12257 |
|
| 12258 |
if Nkind (N) in N_Numeric_Or_String_Literal then |
| 12259 |
return True; |
| 12260 |
|
| 12261 |
elsif Nkind (N) = N_Character_Literal then |
| 12262 |
return True; |
| 12263 |
|
| 12264 |
elsif Nkind (N) in N_Unary_Op then |
| 12265 |
return Has_No_Obvious_Side_Effects (Right_Opnd (N)); |
| 12266 |
|
| 12267 |
elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then |
| 12268 |
return Has_No_Obvious_Side_Effects (Left_Opnd (N)) |
| 12269 |
and then |
| 12270 |
Has_No_Obvious_Side_Effects (Right_Opnd (N)); |
| 12271 |
|
| 12272 |
elsif Nkind (N) = N_Expression_With_Actions |
| 12273 |
and then Is_Empty_List (Actions (N)) |
| 12274 |
then |
| 12275 |
return Has_No_Obvious_Side_Effects (Expression (N)); |
| 12276 |
|
| 12277 |
elsif Nkind (N) in N_Has_Entity then |
| 12278 |
return Present (Entity (N)) |
| 12279 |
and then |
| 12280 |
Ekind (Entity (N)) in |
| 12281 |
E_Variable | E_Constant | E_Enumeration_Literal | |
| 12282 |
E_In_Parameter | E_Out_Parameter | E_In_Out_Parameter |
| 12283 |
and then not Is_Volatile (Entity (N)); |
| 12284 |
|
| 12285 |
else |
| 12286 |
return False; |
| 12287 |
end if; |
| 12288 |
end Has_No_Obvious_Side_Effects; |
| 12289 |
|
| 12290 |
----------------------------- |
| 12291 |
-- Has_Non_Null_Refinement -- |
| 12292 |
----------------------------- |
| 12293 |
|
| 12294 |
function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is |
| 12295 |
Constits : Elist_Id; |
| 12296 |
|
| 12297 |
begin |
| 12298 |
pragma Assert (Ekind (Id) = E_Abstract_State); |
| 12299 |
Constits := Refinement_Constituents (Id); |
| 12300 |
|
| 12301 |
-- For a refinement to be non-null, the first constituent must be |
| 12302 |
-- anything other than null. |
| 12303 |
|
| 12304 |
return |
| 12305 |
Present (Constits) |
| 12306 |
and then Nkind (Node (First_Elmt (Constits))) /= N_Null; |
| 12307 |
end Has_Non_Null_Refinement; |
| 12308 |
|
| 12309 |
----------------------------- |
| 12310 |
-- Has_Non_Null_Statements -- |
| 12311 |
----------------------------- |
| 12312 |
|
| 12313 |
function Has_Non_Null_Statements (L : List_Id) return Boolean is |
| 12314 |
Node : Node_Id; |
| 12315 |
|
| 12316 |
begin |
| 12317 |
Node := First (L); |
| 12318 |
|
| 12319 |
while Present (Node) loop |
| 12320 |
if Nkind (Node) not in N_Null_Statement | N_Call_Marker then |
| 12321 |
return True; |
| 12322 |
end if; |
| 12323 |
|
| 12324 |
Next (Node); |
| 12325 |
end loop; |
| 12326 |
|
| 12327 |
return False; |
| 12328 |
end Has_Non_Null_Statements; |
| 12329 |
|
| 12330 |
---------------------------------- |
| 12331 |
-- Is_Access_Subprogram_Wrapper -- |
| 12332 |
---------------------------------- |
| 12333 |
|
| 12334 |
function Is_Access_Subprogram_Wrapper (E : Entity_Id) return Boolean is |
| 12335 |
Formal : constant Entity_Id := Last_Formal (E); |
| 12336 |
begin |
| 12337 |
return Present (Formal) |
| 12338 |
and then Ekind (Etype (Formal)) in Access_Subprogram_Kind |
| 12339 |
and then Access_Subprogram_Wrapper |
| 12340 |
(Directly_Designated_Type (Etype (Formal))) = E; |
| 12341 |
end Is_Access_Subprogram_Wrapper; |
| 12342 |
|
| 12343 |
--------------------------- |
| 12344 |
-- Is_Explicitly_Aliased -- |
| 12345 |
--------------------------- |
| 12346 |
|
| 12347 |
function Is_Explicitly_Aliased (N : Node_Id) return Boolean is |
| 12348 |
begin |
| 12349 |
return Is_Formal (N) |
| 12350 |
and then Present (Parent (N)) |
| 12351 |
and then Nkind (Parent (N)) = N_Parameter_Specification |
| 12352 |
and then Aliased_Present (Parent (N)); |
| 12353 |
end Is_Explicitly_Aliased; |
| 12354 |
|
| 12355 |
---------------------------- |
| 12356 |
-- Is_Container_Aggregate -- |
| 12357 |
---------------------------- |
| 12358 |
|
| 12359 |
function Is_Container_Aggregate (Exp : Node_Id) return Boolean is |
| 12360 |
|
| 12361 |
function Is_Record_Aggregate return Boolean is |
| 12362 |
(Is_Parenthesis_Aggregate (Exp)); |
| 12363 |
-- Given an aggregate whose type is a record type with specified |
| 12364 |
-- Aggregate aspect, we determine whether it is a record aggregate or |
| 12365 |
-- a container aggregate by ckecking whether it uses parentheses () or |
| 12366 |
-- square brackets []. If the code where the aggregate occurs can see |
| 12367 |
-- only a partial view of the aggregate's type then the aggregate cannot |
| 12368 |
-- be a record type and must then use []; an aggregate of a private type |
| 12369 |
-- has to be a container aggregate and must then use []. |
| 12370 |
|
| 12371 |
begin |
| 12372 |
return Nkind (Exp) = N_Aggregate |
| 12373 |
and then Has_Aspect (Etype (Exp), Aspect_Aggregate) |
| 12374 |
and then not Is_Record_Aggregate; |
| 12375 |
end Is_Container_Aggregate; |
| 12376 |
|
| 12377 |
----------------------------- |
| 12378 |
-- Is_Extended_Access_Type -- |
| 12379 |
----------------------------- |
| 12380 |
|
| 12381 |
function Is_Extended_Access_Type (Ent : Entity_Id) return Boolean is |
| 12382 |
Btype : constant Entity_Id := Available_View (Base_Type (Ent)); |
| 12383 |
begin |
| 12384 |
if Has_Aspect (Btype, Aspect_Extended_Access) then |
| 12385 |
declare |
| 12386 |
Aspect_Expr : constant Node_Id := |
| 12387 |
Expression (Find_Aspect (Btype, Aspect_Extended_Access)); |
| 12388 |
begin |
| 12389 |
return No (Aspect_Expr) or else Expr_Value (Aspect_Expr) /= 0; |
| 12390 |
end; |
| 12391 |
elsif Is_Derived_Type (Btype) then |
| 12392 |
return Is_Extended_Access_Type (Etype (Btype)); |
| 12393 |
else |
| 12394 |
return False; |
| 12395 |
end if; |
| 12396 |
end Is_Extended_Access_Type; |
| 12397 |
|
| 12398 |
--------------------------------- |
| 12399 |
-- Side_Effect_Free_Statements -- |
| 12400 |
--------------------------------- |
| 12401 |
|
| 12402 |
function Side_Effect_Free_Statements (L : List_Id) return Boolean is |
| 12403 |
Node : Node_Id; |
| 12404 |
|
| 12405 |
begin |
| 12406 |
Node := First (L); |
| 12407 |
|
| 12408 |
while Present (Node) loop |
| 12409 |
case Nkind (Node) is |
| 12410 |
when N_Null_Statement | N_Call_Marker => |
| 12411 |
null; |
| 12412 |
|
| 12413 |
when N_Raise_xxx_Error => |
| 12414 |
if Comes_From_Source (Node) then |
| 12415 |
return False; |
| 12416 |
end if; |
| 12417 |
|
| 12418 |
when N_Object_Declaration => |
| 12419 |
if Present (Expression (Node)) |
| 12420 |
and then not Side_Effect_Free (Expression (Node)) |
| 12421 |
then |
| 12422 |
return False; |
| 12423 |
end if; |
| 12424 |
|
| 12425 |
when others => |
| 12426 |
return False; |
| 12427 |
end case; |
| 12428 |
|
| 12429 |
Next (Node); |
| 12430 |
end loop; |
| 12431 |
|
| 12432 |
return True; |
| 12433 |
end Side_Effect_Free_Statements; |
| 12434 |
|
| 12435 |
--------------------------- |
| 12436 |
-- Side_Effect_Free_Loop -- |
| 12437 |
--------------------------- |
| 12438 |
|
| 12439 |
function Side_Effect_Free_Loop (N : Node_Id) return Boolean is |
| 12440 |
Scheme : Node_Id; |
| 12441 |
Spec : Node_Id; |
| 12442 |
Subt : Node_Id; |
| 12443 |
|
| 12444 |
begin |
| 12445 |
-- If this is not a loop (e.g. because the loop has been rewritten), |
| 12446 |
-- then return false. |
| 12447 |
|
| 12448 |
if Nkind (N) /= N_Loop_Statement then |
| 12449 |
return False; |
| 12450 |
end if; |
| 12451 |
|
| 12452 |
-- First check the statements |
| 12453 |
|
| 12454 |
if Side_Effect_Free_Statements (Statements (N)) then |
| 12455 |
|
| 12456 |
-- Then check the loop condition/indexes |
| 12457 |
|
| 12458 |
if Present (Iteration_Scheme (N)) then |
| 12459 |
Scheme := Iteration_Scheme (N); |
| 12460 |
|
| 12461 |
if Present (Condition (Scheme)) |
| 12462 |
or else Present (Iterator_Specification (Scheme)) |
| 12463 |
then |
| 12464 |
return False; |
| 12465 |
elsif Present (Loop_Parameter_Specification (Scheme)) then |
| 12466 |
Spec := Loop_Parameter_Specification (Scheme); |
| 12467 |
Subt := Discrete_Subtype_Definition (Spec); |
| 12468 |
|
| 12469 |
if Present (Subt) then |
| 12470 |
if Nkind (Subt) = N_Range then |
| 12471 |
return Side_Effect_Free (Low_Bound (Subt)) |
| 12472 |
and then Side_Effect_Free (High_Bound (Subt)); |
| 12473 |
else |
| 12474 |
-- subtype indication |
| 12475 |
|
| 12476 |
return True; |
| 12477 |
end if; |
| 12478 |
end if; |
| 12479 |
end if; |
| 12480 |
end if; |
| 12481 |
end if; |
| 12482 |
|
| 12483 |
return False; |
| 12484 |
end Side_Effect_Free_Loop; |
| 12485 |
|
| 12486 |
---------------------------------- |
| 12487 |
-- Has_Non_Trivial_Precondition -- |
| 12488 |
---------------------------------- |
| 12489 |
|
| 12490 |
function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is |
| 12491 |
Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre, |
| 12492 |
Class_Present => True); |
| 12493 |
begin |
| 12494 |
return |
| 12495 |
Present (Pre) |
| 12496 |
and then not Is_Entity_Name (Expression (Pre)); |
| 12497 |
end Has_Non_Trivial_Precondition; |
| 12498 |
|
| 12499 |
------------------- |
| 12500 |
-- Has_Null_Body -- |
| 12501 |
------------------- |
| 12502 |
|
| 12503 |
function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is |
| 12504 |
Body_Id : Entity_Id; |
| 12505 |
Decl : Node_Id; |
| 12506 |
Spec : Node_Id; |
| 12507 |
Stmt1 : Node_Id; |
| 12508 |
Stmt2 : Node_Id; |
| 12509 |
|
| 12510 |
begin |
| 12511 |
Spec := Parent (Proc_Id); |
| 12512 |
Decl := Parent (Spec); |
| 12513 |
|
| 12514 |
-- Retrieve the entity of the procedure body (e.g. invariant proc). |
| 12515 |
|
| 12516 |
if Nkind (Spec) = N_Procedure_Specification |
| 12517 |
and then Nkind (Decl) = N_Subprogram_Declaration |
| 12518 |
then |
| 12519 |
Body_Id := Corresponding_Body (Decl); |
| 12520 |
|
| 12521 |
-- The body acts as a spec |
| 12522 |
|
| 12523 |
else |
| 12524 |
Body_Id := Proc_Id; |
| 12525 |
end if; |
| 12526 |
|
| 12527 |
-- The body will be generated later |
| 12528 |
|
| 12529 |
if No (Body_Id) then |
| 12530 |
return False; |
| 12531 |
end if; |
| 12532 |
|
| 12533 |
Spec := Parent (Body_Id); |
| 12534 |
Decl := Parent (Spec); |
| 12535 |
|
| 12536 |
pragma Assert |
| 12537 |
(Nkind (Spec) = N_Procedure_Specification |
| 12538 |
and then Nkind (Decl) = N_Subprogram_Body); |
| 12539 |
|
| 12540 |
Stmt1 := First (Statements (Handled_Statement_Sequence (Decl))); |
| 12541 |
|
| 12542 |
-- Look for a null statement followed by an optional return |
| 12543 |
-- statement. |
| 12544 |
|
| 12545 |
if Nkind (Stmt1) = N_Null_Statement then |
| 12546 |
Stmt2 := Next (Stmt1); |
| 12547 |
|
| 12548 |
if Present (Stmt2) then |
| 12549 |
return Nkind (Stmt2) = N_Simple_Return_Statement; |
| 12550 |
else |
| 12551 |
return True; |
| 12552 |
end if; |
| 12553 |
end if; |
| 12554 |
|
| 12555 |
return False; |
| 12556 |
end Has_Null_Body; |
| 12557 |
|
| 12558 |
------------------------ |
| 12559 |
-- Has_Null_Exclusion -- |
| 12560 |
------------------------ |
| 12561 |
|
| 12562 |
function Has_Null_Exclusion (N : Node_Id) return Boolean is |
| 12563 |
begin |
| 12564 |
case Nkind (N) is |
| 12565 |
when N_Access_Definition |
| 12566 |
| N_Access_Function_Definition |
| 12567 |
| N_Access_Procedure_Definition |
| 12568 |
| N_Access_To_Object_Definition |
| 12569 |
| N_Allocator |
| 12570 |
| N_Derived_Type_Definition |
| 12571 |
| N_Function_Specification |
| 12572 |
| N_Subtype_Declaration |
| 12573 |
=> |
| 12574 |
return Null_Exclusion_Present (N); |
| 12575 |
|
| 12576 |
when N_Component_Definition |
| 12577 |
| N_Formal_Object_Declaration |
| 12578 |
=> |
| 12579 |
if Present (Subtype_Mark (N)) then |
| 12580 |
return Null_Exclusion_Present (N); |
| 12581 |
else pragma Assert (Present (Access_Definition (N))); |
| 12582 |
return Null_Exclusion_Present (Access_Definition (N)); |
| 12583 |
end if; |
| 12584 |
|
| 12585 |
when N_Object_Renaming_Declaration => |
| 12586 |
if Present (Subtype_Mark (N)) then |
| 12587 |
return Null_Exclusion_Present (N); |
| 12588 |
elsif Present (Access_Definition (N)) then |
| 12589 |
return Null_Exclusion_Present (Access_Definition (N)); |
| 12590 |
else |
| 12591 |
return False; -- Case of no subtype in renaming (AI12-0275) |
| 12592 |
end if; |
| 12593 |
|
| 12594 |
when N_Discriminant_Specification => |
| 12595 |
if Nkind (Discriminant_Type (N)) = N_Access_Definition then |
| 12596 |
return Null_Exclusion_Present (Discriminant_Type (N)); |
| 12597 |
else |
| 12598 |
return Null_Exclusion_Present (N); |
| 12599 |
end if; |
| 12600 |
|
| 12601 |
when N_Object_Declaration => |
| 12602 |
if Nkind (Object_Definition (N)) = N_Access_Definition then |
| 12603 |
return Null_Exclusion_Present (Object_Definition (N)); |
| 12604 |
else |
| 12605 |
return Null_Exclusion_Present (N); |
| 12606 |
end if; |
| 12607 |
|
| 12608 |
when N_Parameter_Specification => |
| 12609 |
if Nkind (Parameter_Type (N)) = N_Access_Definition then |
| 12610 |
return Null_Exclusion_Present (Parameter_Type (N)) |
| 12611 |
or else Null_Exclusion_Present (N); |
| 12612 |
else |
| 12613 |
return Null_Exclusion_Present (N); |
| 12614 |
end if; |
| 12615 |
|
| 12616 |
when others => |
| 12617 |
return False; |
| 12618 |
end case; |
| 12619 |
end Has_Null_Exclusion; |
| 12620 |
|
| 12621 |
------------------------ |
| 12622 |
-- Has_Null_Extension -- |
| 12623 |
------------------------ |
| 12624 |
|
| 12625 |
function Has_Null_Extension (T : Entity_Id) return Boolean is |
| 12626 |
B : constant Entity_Id := Base_Type (T); |
| 12627 |
Comps : Node_Id; |
| 12628 |
Ext : Node_Id; |
| 12629 |
|
| 12630 |
begin |
| 12631 |
if Nkind (Parent (B)) = N_Full_Type_Declaration |
| 12632 |
and then Present (Record_Extension_Part (Type_Definition (Parent (B)))) |
| 12633 |
then |
| 12634 |
Ext := Record_Extension_Part (Type_Definition (Parent (B))); |
| 12635 |
|
| 12636 |
if Present (Ext) then |
| 12637 |
if Null_Present (Ext) then |
| 12638 |
return True; |
| 12639 |
else |
| 12640 |
Comps := Component_List (Ext); |
| 12641 |
|
| 12642 |
-- The null component list is rewritten during analysis to |
| 12643 |
-- include the parent component. Any other component indicates |
| 12644 |
-- that the extension was not originally null. |
| 12645 |
|
| 12646 |
return Null_Present (Comps) |
| 12647 |
or else No (Next (First (Component_Items (Comps)))); |
| 12648 |
end if; |
| 12649 |
else |
| 12650 |
return False; |
| 12651 |
end if; |
| 12652 |
|
| 12653 |
else |
| 12654 |
return False; |
| 12655 |
end if; |
| 12656 |
end Has_Null_Extension; |
| 12657 |
|
| 12658 |
------------------------- |
| 12659 |
-- Has_Null_Refinement -- |
| 12660 |
------------------------- |
| 12661 |
|
| 12662 |
function Has_Null_Refinement (Id : Entity_Id) return Boolean is |
| 12663 |
Constits : Elist_Id; |
| 12664 |
|
| 12665 |
begin |
| 12666 |
pragma Assert (Ekind (Id) = E_Abstract_State); |
| 12667 |
Constits := Refinement_Constituents (Id); |
| 12668 |
|
| 12669 |
-- For a refinement to be null, the state's sole constituent must be a |
| 12670 |
-- null. |
| 12671 |
|
| 12672 |
return |
| 12673 |
Present (Constits) |
| 12674 |
and then Nkind (Node (First_Elmt (Constits))) = N_Null; |
| 12675 |
end Has_Null_Refinement; |
| 12676 |
|
| 12677 |
------------------------------------------ |
| 12678 |
-- Has_Nonstatic_Class_Wide_Pre_Or_Post -- |
| 12679 |
------------------------------------------ |
| 12680 |
|
| 12681 |
function Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post |
| 12682 |
(Subp : Entity_Id) return Boolean |
| 12683 |
is |
| 12684 |
Disp_Type : constant Entity_Id := Find_Dispatching_Type (Subp); |
| 12685 |
Prag : Node_Id; |
| 12686 |
Pragma_Arg : Node_Id; |
| 12687 |
|
| 12688 |
begin |
| 12689 |
if Present (Disp_Type) |
| 12690 |
and then Is_Abstract_Type (Disp_Type) |
| 12691 |
and then Present (Contract (Subp)) |
| 12692 |
then |
| 12693 |
Prag := Pre_Post_Conditions (Contract (Subp)); |
| 12694 |
|
| 12695 |
while Present (Prag) loop |
| 12696 |
if Pragma_Name (Prag) in Name_Precondition | Name_Postcondition |
| 12697 |
and then Class_Present (Prag) |
| 12698 |
then |
| 12699 |
Pragma_Arg := |
| 12700 |
First (Pragma_Argument_Associations (Prag)); |
| 12701 |
|
| 12702 |
if not Is_Static_Expression (Expression (Pragma_Arg)) then |
| 12703 |
return True; |
| 12704 |
end if; |
| 12705 |
end if; |
| 12706 |
|
| 12707 |
Prag := Next_Pragma (Prag); |
| 12708 |
end loop; |
| 12709 |
end if; |
| 12710 |
|
| 12711 |
return False; |
| 12712 |
end Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post; |
| 12713 |
|
| 12714 |
------------------------------- |
| 12715 |
-- Has_Overriding_Initialize -- |
| 12716 |
------------------------------- |
| 12717 |
|
| 12718 |
function Has_Overriding_Initialize (T : Entity_Id) return Boolean is |
| 12719 |
BT : constant Entity_Id := Base_Type (T); |
| 12720 |
P : Elmt_Id; |
| 12721 |
|
| 12722 |
begin |
| 12723 |
if Is_Controlled (BT) then |
| 12724 |
if Is_RTU (Scope (BT), Ada_Finalization) then |
| 12725 |
return False; |
| 12726 |
|
| 12727 |
elsif Present (Primitive_Operations (BT)) then |
| 12728 |
P := First_Elmt (Primitive_Operations (BT)); |
| 12729 |
while Present (P) loop |
| 12730 |
declare |
| 12731 |
Init : constant Entity_Id := Node (P); |
| 12732 |
Formal : constant Entity_Id := First_Formal (Init); |
| 12733 |
begin |
| 12734 |
if Ekind (Init) = E_Procedure |
| 12735 |
and then Chars (Init) = Name_Initialize |
| 12736 |
and then Comes_From_Source (Init) |
| 12737 |
and then Present (Formal) |
| 12738 |
and then Etype (Formal) = BT |
| 12739 |
and then No (Next_Formal (Formal)) |
| 12740 |
and then (Ada_Version < Ada_2012 |
| 12741 |
or else not Null_Present (Parent (Init))) |
| 12742 |
then |
| 12743 |
return True; |
| 12744 |
end if; |
| 12745 |
end; |
| 12746 |
|
| 12747 |
Next_Elmt (P); |
| 12748 |
end loop; |
| 12749 |
end if; |
| 12750 |
|
| 12751 |
-- Here if type itself does not have a non-null Initialize operation: |
| 12752 |
-- check immediate ancestor. |
| 12753 |
|
| 12754 |
if Is_Derived_Type (BT) |
| 12755 |
and then Has_Overriding_Initialize (Etype (BT)) |
| 12756 |
then |
| 12757 |
return True; |
| 12758 |
end if; |
| 12759 |
end if; |
| 12760 |
|
| 12761 |
return False; |
| 12762 |
end Has_Overriding_Initialize; |
| 12763 |
|
| 12764 |
-------------------------------------- |
| 12765 |
-- Has_Preelaborable_Initialization -- |
| 12766 |
-------------------------------------- |
| 12767 |
|
| 12768 |
function Has_Preelaborable_Initialization |
| 12769 |
(E : Entity_Id; |
| 12770 |
Preelab_Init_Expr : Node_Id := Empty) return Boolean |
| 12771 |
is |
| 12772 |
Has_PE : Boolean; |
| 12773 |
|
| 12774 |
procedure Check_Components (E : Entity_Id); |
| 12775 |
-- Check component/discriminant chain, sets Has_PE False if a component |
| 12776 |
-- or discriminant does not meet the preelaborable initialization rules. |
| 12777 |
|
| 12778 |
function Type_Named_In_Preelab_Init_Expression |
| 12779 |
(Typ : Entity_Id; |
| 12780 |
Expr : Node_Id) return Boolean; |
| 12781 |
-- Returns True iff Typ'Preelaborable_Initialization occurs in Expr |
| 12782 |
-- (where Expr may be a conjunction of one or more P_I attributes). |
| 12783 |
|
| 12784 |
---------------------- |
| 12785 |
-- Check_Components -- |
| 12786 |
---------------------- |
| 12787 |
|
| 12788 |
procedure Check_Components (E : Entity_Id) is |
| 12789 |
Ent : Entity_Id; |
| 12790 |
Exp : Node_Id; |
| 12791 |
|
| 12792 |
begin |
| 12793 |
-- Loop through components and discriminants of record or protected |
| 12794 |
-- type. |
| 12795 |
|
| 12796 |
Ent := First_Component_Or_Discriminant (E); |
| 12797 |
while Present (Ent) loop |
| 12798 |
|
| 12799 |
case Ekind (Ent) is |
| 12800 |
when E_Component => |
| 12801 |
|
| 12802 |
-- Get default expression if any. If there is no declaration |
| 12803 |
-- node, it means we have an internal entity. The parent and |
| 12804 |
-- tag fields are examples of such entities. For such cases, |
| 12805 |
-- we just test the type of the entity. |
| 12806 |
|
| 12807 |
if Present (Declaration_Node (Ent)) then |
| 12808 |
Exp := Expression (Declaration_Node (Ent)); |
| 12809 |
else |
| 12810 |
Exp := Empty; |
| 12811 |
end if; |
| 12812 |
|
| 12813 |
when E_Discriminant => |
| 12814 |
|
| 12815 |
-- Note: for a renamed discriminant, the Declaration_Node |
| 12816 |
-- may point to the one from the ancestor, and have a |
| 12817 |
-- different expression, so use the proper attribute to |
| 12818 |
-- retrieve the expression from the derived constraint. |
| 12819 |
|
| 12820 |
Exp := Discriminant_Default_Value (Ent); |
| 12821 |
|
| 12822 |
when others => |
| 12823 |
raise Program_Error; |
| 12824 |
end case; |
| 12825 |
|
| 12826 |
-- A component has PI if it has no default expression and the |
| 12827 |
-- component type has PI. |
| 12828 |
|
| 12829 |
if No (Exp) then |
| 12830 |
if not Has_Preelaborable_Initialization |
| 12831 |
(Etype (Ent), Preelab_Init_Expr) |
| 12832 |
then |
| 12833 |
Has_PE := False; |
| 12834 |
exit; |
| 12835 |
end if; |
| 12836 |
|
| 12837 |
-- Require the default expression to be preelaborable |
| 12838 |
|
| 12839 |
elsif not Is_Preelaborable_Construct (Exp) then |
| 12840 |
Has_PE := False; |
| 12841 |
exit; |
| 12842 |
end if; |
| 12843 |
|
| 12844 |
Next_Component_Or_Discriminant (Ent); |
| 12845 |
end loop; |
| 12846 |
end Check_Components; |
| 12847 |
|
| 12848 |
-------------------------------------- |
| 12849 |
-- Type_Named_In_Preelab_Expression -- |
| 12850 |
-------------------------------------- |
| 12851 |
|
| 12852 |
function Type_Named_In_Preelab_Init_Expression |
| 12853 |
(Typ : Entity_Id; |
| 12854 |
Expr : Node_Id) return Boolean |
| 12855 |
is |
| 12856 |
begin |
| 12857 |
-- Return True if Expr is a Preelaborable_Initialization attribute |
| 12858 |
-- and the prefix is a subtype that has the same type as Typ. |
| 12859 |
|
| 12860 |
if Nkind (Expr) = N_Attribute_Reference |
| 12861 |
and then Attribute_Name (Expr) = Name_Preelaborable_Initialization |
| 12862 |
and then Is_Entity_Name (Prefix (Expr)) |
| 12863 |
and then Base_Type (Entity (Prefix (Expr))) = Base_Type (Typ) |
| 12864 |
then |
| 12865 |
return True; |
| 12866 |
|
| 12867 |
-- In the case where Expr is a conjunction, test whether either |
| 12868 |
-- operand is a Preelaborable_Initialization attribute whose prefix |
| 12869 |
-- has the same type as Typ, and return True if so. |
| 12870 |
|
| 12871 |
elsif Nkind (Expr) = N_Op_And |
| 12872 |
and then |
| 12873 |
(Type_Named_In_Preelab_Init_Expression (Typ, Left_Opnd (Expr)) |
| 12874 |
or else |
| 12875 |
Type_Named_In_Preelab_Init_Expression (Typ, Right_Opnd (Expr))) |
| 12876 |
then |
| 12877 |
return True; |
| 12878 |
|
| 12879 |
-- Typ not named in a Preelaborable_Initialization attribute of Expr |
| 12880 |
|
| 12881 |
else |
| 12882 |
return False; |
| 12883 |
end if; |
| 12884 |
end Type_Named_In_Preelab_Init_Expression; |
| 12885 |
|
| 12886 |
-- Start of processing for Has_Preelaborable_Initialization |
| 12887 |
|
| 12888 |
begin |
| 12889 |
-- Immediate return if already marked as known preelaborable init. This |
| 12890 |
-- covers types for which this function has already been called once |
| 12891 |
-- and returned True (in which case the result is cached), and also |
| 12892 |
-- types to which a pragma Preelaborable_Initialization applies. |
| 12893 |
|
| 12894 |
if Known_To_Have_Preelab_Init (E) then |
| 12895 |
return True; |
| 12896 |
end if; |
| 12897 |
|
| 12898 |
-- If the type is a subtype representing a generic actual type, then |
| 12899 |
-- test whether its base type has preelaborable initialization since |
| 12900 |
-- the subtype representing the actual does not inherit this attribute |
| 12901 |
-- from the actual or formal. (but maybe it should???) |
| 12902 |
|
| 12903 |
if Is_Generic_Actual_Type (E) then |
| 12904 |
return Has_Preelaborable_Initialization (Base_Type (E)); |
| 12905 |
end if; |
| 12906 |
|
| 12907 |
-- All elementary types have preelaborable initialization |
| 12908 |
|
| 12909 |
if Is_Elementary_Type (E) then |
| 12910 |
Has_PE := True; |
| 12911 |
|
| 12912 |
-- Array types have PI if the component type has PI |
| 12913 |
|
| 12914 |
elsif Is_Array_Type (E) then |
| 12915 |
Has_PE := Has_Preelaborable_Initialization |
| 12916 |
(Component_Type (E), Preelab_Init_Expr); |
| 12917 |
|
| 12918 |
-- A derived type has preelaborable initialization if its parent type |
| 12919 |
-- has preelaborable initialization and (in the case of a derived record |
| 12920 |
-- extension) if the non-inherited components all have preelaborable |
| 12921 |
-- initialization. However, a user-defined controlled type with an |
| 12922 |
-- overriding Initialize procedure does not have preelaborable |
| 12923 |
-- initialization. |
| 12924 |
|
| 12925 |
elsif Is_Derived_Type (E) then |
| 12926 |
|
| 12927 |
-- When the rule of RM 10.2.1(11.8/5) applies, we presume a component |
| 12928 |
-- of a generic formal derived type has preelaborable initialization. |
| 12929 |
-- (See comment on spec of Has_Preelaborable_Initialization.) |
| 12930 |
|
| 12931 |
if Is_Generic_Type (E) |
| 12932 |
and then Present (Preelab_Init_Expr) |
| 12933 |
and then |
| 12934 |
Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr) |
| 12935 |
then |
| 12936 |
return True; |
| 12937 |
end if; |
| 12938 |
|
| 12939 |
-- If the derived type is a private extension then it doesn't have |
| 12940 |
-- preelaborable initialization. |
| 12941 |
|
| 12942 |
if Ekind (Base_Type (E)) = E_Record_Type_With_Private then |
| 12943 |
return False; |
| 12944 |
end if; |
| 12945 |
|
| 12946 |
-- First check whether ancestor type has preelaborable initialization |
| 12947 |
|
| 12948 |
Has_PE := Has_Preelaborable_Initialization |
| 12949 |
(Etype (Base_Type (E)), Preelab_Init_Expr); |
| 12950 |
|
| 12951 |
-- If OK, check extension components (if any) |
| 12952 |
|
| 12953 |
if Has_PE and then Is_Record_Type (E) then |
| 12954 |
Check_Components (E); |
| 12955 |
end if; |
| 12956 |
|
| 12957 |
-- Check specifically for 10.2.1(11.4/2) exception: a controlled type |
| 12958 |
-- with a user defined Initialize procedure does not have PI. If |
| 12959 |
-- the type is untagged, the control primitives come from a component |
| 12960 |
-- that has already been checked. |
| 12961 |
|
| 12962 |
if Has_PE |
| 12963 |
and then Is_Controlled (E) |
| 12964 |
and then Is_Tagged_Type (E) |
| 12965 |
and then Has_Overriding_Initialize (E) |
| 12966 |
then |
| 12967 |
Has_PE := False; |
| 12968 |
end if; |
| 12969 |
|
| 12970 |
-- Private types not derived from a type having preelaborable init and |
| 12971 |
-- that are not marked with pragma Preelaborable_Initialization do not |
| 12972 |
-- have preelaborable initialization. |
| 12973 |
|
| 12974 |
elsif Is_Private_Type (E) then |
| 12975 |
|
| 12976 |
-- When the rule of RM 10.2.1(11.8/5) applies, we presume a component |
| 12977 |
-- of a generic formal private type has preelaborable initialization. |
| 12978 |
-- (See comment on spec of Has_Preelaborable_Initialization.) |
| 12979 |
|
| 12980 |
if Is_Generic_Type (E) |
| 12981 |
and then Present (Preelab_Init_Expr) |
| 12982 |
and then |
| 12983 |
Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr) |
| 12984 |
then |
| 12985 |
return True; |
| 12986 |
else |
| 12987 |
return False; |
| 12988 |
end if; |
| 12989 |
|
| 12990 |
-- Record type has PI if it is non private and all components have PI |
| 12991 |
|
| 12992 |
elsif Is_Record_Type (E) then |
| 12993 |
Has_PE := True; |
| 12994 |
Check_Components (E); |
| 12995 |
|
| 12996 |
-- Protected types must not have entries, and components must meet |
| 12997 |
-- same set of rules as for record components. |
| 12998 |
|
| 12999 |
elsif Is_Protected_Type (E) then |
| 13000 |
if Has_Entries (E) then |
| 13001 |
Has_PE := False; |
| 13002 |
else |
| 13003 |
Has_PE := True; |
| 13004 |
Check_Components (E); |
| 13005 |
end if; |
| 13006 |
|
| 13007 |
-- Type System.Address always has preelaborable initialization |
| 13008 |
|
| 13009 |
elsif Is_RTE (E, RE_Address) then |
| 13010 |
Has_PE := True; |
| 13011 |
|
| 13012 |
-- In all other cases, type does not have preelaborable initialization |
| 13013 |
|
| 13014 |
else |
| 13015 |
return False; |
| 13016 |
end if; |
| 13017 |
|
| 13018 |
-- If type has preelaborable initialization, cache result |
| 13019 |
|
| 13020 |
if Has_PE then |
| 13021 |
Set_Known_To_Have_Preelab_Init (E); |
| 13022 |
end if; |
| 13023 |
|
| 13024 |
return Has_PE; |
| 13025 |
end Has_Preelaborable_Initialization; |
| 13026 |
|
| 13027 |
---------------- |
| 13028 |
-- Has_Prefix -- |
| 13029 |
---------------- |
| 13030 |
|
| 13031 |
function Has_Prefix (N : Node_Id) return Boolean is |
| 13032 |
begin |
| 13033 |
return Nkind (N) in |
| 13034 |
N_Attribute_Reference | N_Expanded_Name | N_Explicit_Dereference | |
| 13035 |
N_Indexed_Component | N_Reference | N_Selected_Component | |
| 13036 |
N_Slice; |
| 13037 |
end Has_Prefix; |
| 13038 |
|
| 13039 |
--------------------------- |
| 13040 |
-- Has_Private_Component -- |
| 13041 |
--------------------------- |
| 13042 |
|
| 13043 |
function Has_Private_Component (Type_Id : Entity_Id) return Boolean is |
| 13044 |
Btype : Entity_Id := Base_Type (Type_Id); |
| 13045 |
Component : Entity_Id; |
| 13046 |
|
| 13047 |
begin |
| 13048 |
if Error_Posted (Type_Id) |
| 13049 |
or else Error_Posted (Btype) |
| 13050 |
then |
| 13051 |
return False; |
| 13052 |
end if; |
| 13053 |
|
| 13054 |
if Is_Class_Wide_Type (Btype) then |
| 13055 |
Btype := Root_Type (Btype); |
| 13056 |
end if; |
| 13057 |
|
| 13058 |
if Is_Private_Type (Btype) then |
| 13059 |
declare |
| 13060 |
UT : constant Entity_Id := Underlying_Type (Btype); |
| 13061 |
begin |
| 13062 |
if No (UT) then |
| 13063 |
if No (Full_View (Btype)) then |
| 13064 |
return not Is_Generic_Type (Btype) |
| 13065 |
and then |
| 13066 |
not Is_Generic_Type (Root_Type (Btype)); |
| 13067 |
else |
| 13068 |
return not Is_Generic_Type (Root_Type (Full_View (Btype))); |
| 13069 |
end if; |
| 13070 |
else |
| 13071 |
return not Is_Frozen (UT) and then Has_Private_Component (UT); |
| 13072 |
end if; |
| 13073 |
end; |
| 13074 |
|
| 13075 |
elsif Is_Array_Type (Btype) then |
| 13076 |
return Has_Private_Component (Component_Type (Btype)); |
| 13077 |
|
| 13078 |
elsif Is_Record_Type (Btype) then |
| 13079 |
Component := First_Component (Btype); |
| 13080 |
while Present (Component) loop |
| 13081 |
if Has_Private_Component (Etype (Component)) then |
| 13082 |
return True; |
| 13083 |
end if; |
| 13084 |
|
| 13085 |
Next_Component (Component); |
| 13086 |
end loop; |
| 13087 |
|
| 13088 |
return False; |
| 13089 |
|
| 13090 |
elsif Is_Protected_Type (Btype) |
| 13091 |
and then Present (Corresponding_Record_Type (Btype)) |
| 13092 |
then |
| 13093 |
return Has_Private_Component (Corresponding_Record_Type (Btype)); |
| 13094 |
|
| 13095 |
else |
| 13096 |
return False; |
| 13097 |
end if; |
| 13098 |
end Has_Private_Component; |
| 13099 |
|
| 13100 |
-------------------------------- |
| 13101 |
-- Has_Relaxed_Initialization -- |
| 13102 |
-------------------------------- |
| 13103 |
|
| 13104 |
function Has_Relaxed_Initialization (E : Entity_Id) return Boolean is |
| 13105 |
|
| 13106 |
function Denotes_Relaxed_Parameter |
| 13107 |
(Expr : Node_Id; |
| 13108 |
Param : Entity_Id) |
| 13109 |
return Boolean; |
| 13110 |
-- Returns True iff expression Expr denotes a formal parameter or |
| 13111 |
-- function Param (through its attribute Result). |
| 13112 |
|
| 13113 |
------------------------------- |
| 13114 |
-- Denotes_Relaxed_Parameter -- |
| 13115 |
------------------------------- |
| 13116 |
|
| 13117 |
function Denotes_Relaxed_Parameter |
| 13118 |
(Expr : Node_Id; |
| 13119 |
Param : Entity_Id) return Boolean is |
| 13120 |
begin |
| 13121 |
if Nkind (Expr) in N_Identifier | N_Expanded_Name then |
| 13122 |
return Entity (Expr) = Param; |
| 13123 |
else |
| 13124 |
pragma Assert (Is_Attribute_Result (Expr)); |
| 13125 |
return Entity (Prefix (Expr)) = Param; |
| 13126 |
end if; |
| 13127 |
end Denotes_Relaxed_Parameter; |
| 13128 |
|
| 13129 |
-- Start of processing for Has_Relaxed_Initialization |
| 13130 |
|
| 13131 |
begin |
| 13132 |
-- When analyzing, we checked all syntax legality rules for the aspect |
| 13133 |
-- Relaxed_Initialization, but didn't store the property anywhere (e.g. |
| 13134 |
-- as an Einfo flag). To query the property we look directly at the AST, |
| 13135 |
-- but now without any syntactic checks. |
| 13136 |
|
| 13137 |
case Ekind (E) is |
| 13138 |
-- Constants have this aspect attached directly; for deferred |
| 13139 |
-- constants, the aspect is attached to the partial view. |
| 13140 |
|
| 13141 |
when E_Constant => |
| 13142 |
return Has_Aspect (E, Aspect_Relaxed_Initialization); |
| 13143 |
|
| 13144 |
-- Variables have this aspect attached directly |
| 13145 |
|
| 13146 |
when E_Variable => |
| 13147 |
return Has_Aspect (E, Aspect_Relaxed_Initialization); |
| 13148 |
|
| 13149 |
-- Types have this aspect attached directly (though we only allow it |
| 13150 |
-- to be specified for the first subtype). For private types, the |
| 13151 |
-- aspect is attached to the partial view. |
| 13152 |
|
| 13153 |
when Type_Kind => |
| 13154 |
pragma Assert (Is_First_Subtype (E)); |
| 13155 |
return Has_Aspect (E, Aspect_Relaxed_Initialization); |
| 13156 |
|
| 13157 |
-- Formal parameters and functions have the Relaxed_Initialization |
| 13158 |
-- aspect attached to the subprogram entity and must be listed in |
| 13159 |
-- the aspect expression. |
| 13160 |
|
| 13161 |
when Formal_Kind |
| 13162 |
| E_Function |
| 13163 |
=> |
| 13164 |
declare |
| 13165 |
Subp_Id : Entity_Id; |
| 13166 |
Aspect_Expr : Node_Id; |
| 13167 |
Param_Expr : Node_Id; |
| 13168 |
Assoc : Node_Id; |
| 13169 |
|
| 13170 |
begin |
| 13171 |
if Is_Formal (E) then |
| 13172 |
Subp_Id := Scope (E); |
| 13173 |
else |
| 13174 |
Subp_Id := E; |
| 13175 |
end if; |
| 13176 |
|
| 13177 |
if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then |
| 13178 |
Aspect_Expr := |
| 13179 |
Find_Value_Of_Aspect |
| 13180 |
(Subp_Id, Aspect_Relaxed_Initialization); |
| 13181 |
|
| 13182 |
-- Aspect expression is either an aggregate with an optional |
| 13183 |
-- Boolean expression (which defaults to True), e.g.: |
| 13184 |
-- |
| 13185 |
-- function F (X : Integer) return Integer |
| 13186 |
-- with Relaxed_Initialization => (X => True, F'Result); |
| 13187 |
|
| 13188 |
if Nkind (Aspect_Expr) = N_Aggregate then |
| 13189 |
|
| 13190 |
if Present (Component_Associations (Aspect_Expr)) then |
| 13191 |
Assoc := First (Component_Associations (Aspect_Expr)); |
| 13192 |
|
| 13193 |
while Present (Assoc) loop |
| 13194 |
if Denotes_Relaxed_Parameter |
| 13195 |
(First (Choices (Assoc)), E) |
| 13196 |
then |
| 13197 |
return |
| 13198 |
Is_True |
| 13199 |
(Static_Boolean (Expression (Assoc))); |
| 13200 |
end if; |
| 13201 |
|
| 13202 |
Next (Assoc); |
| 13203 |
end loop; |
| 13204 |
end if; |
| 13205 |
|
| 13206 |
Param_Expr := First (Expressions (Aspect_Expr)); |
| 13207 |
|
| 13208 |
while Present (Param_Expr) loop |
| 13209 |
if Denotes_Relaxed_Parameter (Param_Expr, E) then |
| 13210 |
return True; |
| 13211 |
end if; |
| 13212 |
|
| 13213 |
Next (Param_Expr); |
| 13214 |
end loop; |
| 13215 |
|
| 13216 |
return False; |
| 13217 |
|
| 13218 |
-- or it is a single identifier, e.g.: |
| 13219 |
-- |
| 13220 |
-- function F (X : Integer) return Integer |
| 13221 |
-- with Relaxed_Initialization => X; |
| 13222 |
|
| 13223 |
else |
| 13224 |
return Denotes_Relaxed_Parameter (Aspect_Expr, E); |
| 13225 |
end if; |
| 13226 |
else |
| 13227 |
return False; |
| 13228 |
end if; |
| 13229 |
end; |
| 13230 |
|
| 13231 |
when others => |
| 13232 |
raise Program_Error; |
| 13233 |
end case; |
| 13234 |
end Has_Relaxed_Initialization; |
| 13235 |
|
| 13236 |
---------------------- |
| 13237 |
-- Has_Signed_Zeros -- |
| 13238 |
---------------------- |
| 13239 |
|
| 13240 |
function Has_Signed_Zeros (E : Entity_Id) return Boolean is |
| 13241 |
begin |
| 13242 |
return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target; |
| 13243 |
end Has_Signed_Zeros; |
| 13244 |
|
| 13245 |
------------------------------ |
| 13246 |
-- Has_Significant_Contract -- |
| 13247 |
------------------------------ |
| 13248 |
|
| 13249 |
function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is |
| 13250 |
Subp_Nam : constant Name_Id := Chars (Subp_Id); |
| 13251 |
|
| 13252 |
begin |
| 13253 |
-- _Finalizer procedure |
| 13254 |
|
| 13255 |
if Subp_Nam = Name_uFinalizer then |
| 13256 |
return False; |
| 13257 |
|
| 13258 |
-- _Wrapped_Statements procedure which gets generated as part of the |
| 13259 |
-- expansion of postconditions. |
| 13260 |
|
| 13261 |
elsif Subp_Nam = Name_uWrapped_Statements then |
| 13262 |
return False; |
| 13263 |
|
| 13264 |
-- Predicate function |
| 13265 |
|
| 13266 |
elsif Ekind (Subp_Id) = E_Function |
| 13267 |
and then Is_Predicate_Function (Subp_Id) |
| 13268 |
then |
| 13269 |
return False; |
| 13270 |
|
| 13271 |
-- TSS subprogram |
| 13272 |
|
| 13273 |
elsif Get_TSS_Name (Subp_Id) /= TSS_Null then |
| 13274 |
return False; |
| 13275 |
|
| 13276 |
else |
| 13277 |
return True; |
| 13278 |
end if; |
| 13279 |
end Has_Significant_Contract; |
| 13280 |
|
| 13281 |
----------------------------- |
| 13282 |
-- Has_Static_Array_Bounds -- |
| 13283 |
----------------------------- |
| 13284 |
|
| 13285 |
function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is |
| 13286 |
All_Static : Boolean; |
| 13287 |
Dummy : Boolean; |
| 13288 |
|
| 13289 |
begin |
| 13290 |
Examine_Array_Bounds (Typ, All_Static, Dummy); |
| 13291 |
|
| 13292 |
return All_Static; |
| 13293 |
end Has_Static_Array_Bounds; |
| 13294 |
|
| 13295 |
----------------------------------- |
| 13296 |
-- Has_Static_Empty_Array_Bounds -- |
| 13297 |
----------------------------------- |
| 13298 |
|
| 13299 |
function Has_Static_Empty_Array_Bounds (Typ : Node_Id) return Boolean is |
| 13300 |
All_Static : Boolean; |
| 13301 |
Has_Empty : Boolean; |
| 13302 |
|
| 13303 |
begin |
| 13304 |
Examine_Array_Bounds (Typ, All_Static, Has_Empty); |
| 13305 |
|
| 13306 |
return Has_Empty; |
| 13307 |
end Has_Static_Empty_Array_Bounds; |
| 13308 |
|
| 13309 |
--------------------------------------- |
| 13310 |
-- Has_Static_Non_Empty_Array_Bounds -- |
| 13311 |
--------------------------------------- |
| 13312 |
|
| 13313 |
function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is |
| 13314 |
All_Static : Boolean; |
| 13315 |
Has_Empty : Boolean; |
| 13316 |
|
| 13317 |
begin |
| 13318 |
Examine_Array_Bounds (Typ, All_Static, Has_Empty); |
| 13319 |
|
| 13320 |
return All_Static and not Has_Empty; |
| 13321 |
end Has_Static_Non_Empty_Array_Bounds; |
| 13322 |
|
| 13323 |
---------------- |
| 13324 |
-- Has_Stream -- |
| 13325 |
---------------- |
| 13326 |
|
| 13327 |
function Has_Stream (T : Entity_Id) return Boolean is |
| 13328 |
E : Entity_Id; |
| 13329 |
|
| 13330 |
begin |
| 13331 |
if No (T) then |
| 13332 |
return False; |
| 13333 |
|
| 13334 |
elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then |
| 13335 |
return True; |
| 13336 |
|
| 13337 |
elsif Is_Array_Type (T) then |
| 13338 |
return Has_Stream (Component_Type (T)); |
| 13339 |
|
| 13340 |
elsif Is_Record_Type (T) then |
| 13341 |
E := First_Component (T); |
| 13342 |
while Present (E) loop |
| 13343 |
if Has_Stream (Etype (E)) then |
| 13344 |
return True; |
| 13345 |
else |
| 13346 |
Next_Component (E); |
| 13347 |
end if; |
| 13348 |
end loop; |
| 13349 |
|
| 13350 |
return False; |
| 13351 |
|
| 13352 |
elsif Is_Private_Type (T) then |
| 13353 |
return Has_Stream (Underlying_Type (T)); |
| 13354 |
|
| 13355 |
else |
| 13356 |
return False; |
| 13357 |
end if; |
| 13358 |
end Has_Stream; |
| 13359 |
|
| 13360 |
---------------- |
| 13361 |
-- Has_Suffix -- |
| 13362 |
---------------- |
| 13363 |
|
| 13364 |
function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is |
| 13365 |
begin |
| 13366 |
Get_Name_String (Chars (E)); |
| 13367 |
return Name_Buffer (Name_Len) = Suffix; |
| 13368 |
end Has_Suffix; |
| 13369 |
|
| 13370 |
---------------- |
| 13371 |
-- Add_Suffix -- |
| 13372 |
---------------- |
| 13373 |
|
| 13374 |
function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is |
| 13375 |
begin |
| 13376 |
Get_Name_String (Chars (E)); |
| 13377 |
Add_Char_To_Name_Buffer (Suffix); |
| 13378 |
return Name_Find; |
| 13379 |
end Add_Suffix; |
| 13380 |
|
| 13381 |
------------------- |
| 13382 |
-- Remove_Suffix -- |
| 13383 |
------------------- |
| 13384 |
|
| 13385 |
function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is |
| 13386 |
begin |
| 13387 |
pragma Assert (Has_Suffix (E, Suffix)); |
| 13388 |
Get_Name_String (Chars (E)); |
| 13389 |
Name_Len := Name_Len - 1; |
| 13390 |
return Name_Find; |
| 13391 |
end Remove_Suffix; |
| 13392 |
|
| 13393 |
---------------------------------- |
| 13394 |
-- Replace_Null_By_Null_Address -- |
| 13395 |
---------------------------------- |
| 13396 |
|
| 13397 |
procedure Replace_Null_By_Null_Address (N : Node_Id) is |
| 13398 |
procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id); |
| 13399 |
-- Replace operand Op with a reference to Null_Address when the operand |
| 13400 |
-- denotes a null Address. Other_Op denotes the other operand. |
| 13401 |
|
| 13402 |
-------------------------- |
| 13403 |
-- Replace_Null_Operand -- |
| 13404 |
-------------------------- |
| 13405 |
|
| 13406 |
procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is |
| 13407 |
begin |
| 13408 |
-- Check the type of the complementary operand since the N_Null node |
| 13409 |
-- has not been decorated yet. |
| 13410 |
|
| 13411 |
if Nkind (Op) = N_Null |
| 13412 |
and then Is_Descendant_Of_Address (Etype (Other_Op)) |
| 13413 |
then |
| 13414 |
Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op))); |
| 13415 |
end if; |
| 13416 |
end Replace_Null_Operand; |
| 13417 |
|
| 13418 |
-- Start of processing for Replace_Null_By_Null_Address |
| 13419 |
|
| 13420 |
begin |
| 13421 |
pragma Assert (Relaxed_RM_Semantics); |
| 13422 |
pragma Assert (Nkind (N) in N_Null | N_Op_Compare); |
| 13423 |
|
| 13424 |
if Nkind (N) = N_Null then |
| 13425 |
Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N))); |
| 13426 |
|
| 13427 |
else |
| 13428 |
declare |
| 13429 |
L : constant Node_Id := Left_Opnd (N); |
| 13430 |
R : constant Node_Id := Right_Opnd (N); |
| 13431 |
|
| 13432 |
begin |
| 13433 |
Replace_Null_Operand (L, Other_Op => R); |
| 13434 |
Replace_Null_Operand (R, Other_Op => L); |
| 13435 |
end; |
| 13436 |
end if; |
| 13437 |
end Replace_Null_By_Null_Address; |
| 13438 |
|
| 13439 |
-------------------------- |
| 13440 |
-- Has_Tagged_Component -- |
| 13441 |
-------------------------- |
| 13442 |
|
| 13443 |
function Has_Tagged_Component (Typ : Entity_Id) return Boolean is |
| 13444 |
Comp : Entity_Id; |
| 13445 |
|
| 13446 |
begin |
| 13447 |
if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then |
| 13448 |
return Has_Tagged_Component (Underlying_Type (Typ)); |
| 13449 |
|
| 13450 |
elsif Is_Array_Type (Typ) then |
| 13451 |
return Has_Tagged_Component (Component_Type (Typ)); |
| 13452 |
|
| 13453 |
elsif Is_Tagged_Type (Typ) then |
| 13454 |
return True; |
| 13455 |
|
| 13456 |
elsif Is_Record_Type (Typ) then |
| 13457 |
Comp := First_Component (Typ); |
| 13458 |
while Present (Comp) loop |
| 13459 |
if Has_Tagged_Component (Etype (Comp)) then |
| 13460 |
return True; |
| 13461 |
end if; |
| 13462 |
|
| 13463 |
Next_Component (Comp); |
| 13464 |
end loop; |
| 13465 |
|
| 13466 |
return False; |
| 13467 |
|
| 13468 |
else |
| 13469 |
return False; |
| 13470 |
end if; |
| 13471 |
end Has_Tagged_Component; |
| 13472 |
|
| 13473 |
----------------------------- |
| 13474 |
-- Has_Undefined_Reference -- |
| 13475 |
----------------------------- |
| 13476 |
|
| 13477 |
function Has_Undefined_Reference (Expr : Node_Id) return Boolean is |
| 13478 |
Has_Undef_Ref : Boolean := False; |
| 13479 |
-- Flag set when expression Expr contains at least one undefined |
| 13480 |
-- reference. |
| 13481 |
|
| 13482 |
function Is_Undefined_Reference (N : Node_Id) return Traverse_Result; |
| 13483 |
-- Determine whether N denotes a reference and if it does, whether it is |
| 13484 |
-- undefined. |
| 13485 |
|
| 13486 |
---------------------------- |
| 13487 |
-- Is_Undefined_Reference -- |
| 13488 |
---------------------------- |
| 13489 |
|
| 13490 |
function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is |
| 13491 |
begin |
| 13492 |
if Is_Entity_Name (N) |
| 13493 |
and then Present (Entity (N)) |
| 13494 |
and then Entity (N) = Any_Id |
| 13495 |
then |
| 13496 |
Has_Undef_Ref := True; |
| 13497 |
return Abandon; |
| 13498 |
end if; |
| 13499 |
|
| 13500 |
return OK; |
| 13501 |
end Is_Undefined_Reference; |
| 13502 |
|
| 13503 |
procedure Find_Undefined_References is |
| 13504 |
new Traverse_Proc (Is_Undefined_Reference); |
| 13505 |
|
| 13506 |
-- Start of processing for Has_Undefined_Reference |
| 13507 |
|
| 13508 |
begin |
| 13509 |
Find_Undefined_References (Expr); |
| 13510 |
|
| 13511 |
return Has_Undef_Ref; |
| 13512 |
end Has_Undefined_Reference; |
| 13513 |
|
| 13514 |
---------------------------------------- |
| 13515 |
-- Has_Effectively_Volatile_Component -- |
| 13516 |
---------------------------------------- |
| 13517 |
|
| 13518 |
function Has_Effectively_Volatile_Component |
| 13519 |
(Typ : Entity_Id) return Boolean |
| 13520 |
is |
| 13521 |
Comp : Entity_Id; |
| 13522 |
|
| 13523 |
begin |
| 13524 |
if Has_Volatile_Components (Typ) then |
| 13525 |
return True; |
| 13526 |
|
| 13527 |
elsif Is_Array_Type (Typ) then |
| 13528 |
return Is_Effectively_Volatile (Component_Type (Typ)); |
| 13529 |
|
| 13530 |
elsif Is_Record_Type (Typ) then |
| 13531 |
Comp := First_Component (Typ); |
| 13532 |
while Present (Comp) loop |
| 13533 |
if Is_Effectively_Volatile (Etype (Comp)) then |
| 13534 |
return True; |
| 13535 |
end if; |
| 13536 |
|
| 13537 |
Next_Component (Comp); |
| 13538 |
end loop; |
| 13539 |
end if; |
| 13540 |
|
| 13541 |
return False; |
| 13542 |
end Has_Effectively_Volatile_Component; |
| 13543 |
|
| 13544 |
------------------------ |
| 13545 |
-- Has_Enabled_Aspect -- |
| 13546 |
------------------------ |
| 13547 |
|
| 13548 |
function Has_Enabled_Aspect |
| 13549 |
(Id : Entity_Id; |
| 13550 |
A : Aspect_Id) |
| 13551 |
return Boolean |
| 13552 |
is |
| 13553 |
Asp : constant Node_Id := Find_Aspect (Id, A); |
| 13554 |
begin |
| 13555 |
if Present (Asp) then |
| 13556 |
if Present (Expression (Asp)) then |
| 13557 |
return Is_True (Static_Boolean (Expression (Asp))); |
| 13558 |
else |
| 13559 |
return True; |
| 13560 |
end if; |
| 13561 |
else |
| 13562 |
return False; |
| 13563 |
end if; |
| 13564 |
end Has_Enabled_Aspect; |
| 13565 |
|
| 13566 |
---------------------------- |
| 13567 |
-- Has_Volatile_Component -- |
| 13568 |
---------------------------- |
| 13569 |
|
| 13570 |
function Has_Volatile_Component (Typ : Entity_Id) return Boolean is |
| 13571 |
Comp : Entity_Id; |
| 13572 |
|
| 13573 |
begin |
| 13574 |
if Has_Volatile_Components (Typ) then |
| 13575 |
return True; |
| 13576 |
|
| 13577 |
elsif Is_Array_Type (Typ) then |
| 13578 |
return Is_Volatile (Component_Type (Typ)); |
| 13579 |
|
| 13580 |
elsif Is_Record_Type (Typ) then |
| 13581 |
Comp := First_Component (Typ); |
| 13582 |
while Present (Comp) loop |
| 13583 |
if Is_Volatile_Object_Ref (Comp) then |
| 13584 |
return True; |
| 13585 |
end if; |
| 13586 |
|
| 13587 |
Next_Component (Comp); |
| 13588 |
end loop; |
| 13589 |
end if; |
| 13590 |
|
| 13591 |
return False; |
| 13592 |
end Has_Volatile_Component; |
| 13593 |
|
| 13594 |
------------------------- |
| 13595 |
-- Implementation_Kind -- |
| 13596 |
------------------------- |
| 13597 |
|
| 13598 |
function Implementation_Kind (Subp : Entity_Id) return Name_Id is |
| 13599 |
Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented); |
| 13600 |
Arg : Node_Id; |
| 13601 |
begin |
| 13602 |
pragma Assert (Present (Impl_Prag)); |
| 13603 |
Arg := Last (Pragma_Argument_Associations (Impl_Prag)); |
| 13604 |
return Chars (Get_Pragma_Arg (Arg)); |
| 13605 |
end Implementation_Kind; |
| 13606 |
|
| 13607 |
-------------------------- |
| 13608 |
-- Implements_Interface -- |
| 13609 |
-------------------------- |
| 13610 |
|
| 13611 |
function Implements_Interface |
| 13612 |
(Typ_Ent : Entity_Id; |
| 13613 |
Iface_Ent : Entity_Id; |
| 13614 |
Exclude_Parents : Boolean := False) return Boolean |
| 13615 |
is |
| 13616 |
Ifaces_List : Elist_Id; |
| 13617 |
Elmt : Elmt_Id; |
| 13618 |
Iface : Entity_Id := Base_Type (Iface_Ent); |
| 13619 |
Typ : Entity_Id := Base_Type (Typ_Ent); |
| 13620 |
|
| 13621 |
begin |
| 13622 |
if Is_Class_Wide_Type (Typ) then |
| 13623 |
Typ := Root_Type (Typ); |
| 13624 |
end if; |
| 13625 |
|
| 13626 |
if not Has_Interfaces (Typ) then |
| 13627 |
return False; |
| 13628 |
end if; |
| 13629 |
|
| 13630 |
if Is_Class_Wide_Type (Iface) then |
| 13631 |
Iface := Root_Type (Iface); |
| 13632 |
end if; |
| 13633 |
|
| 13634 |
Collect_Interfaces (Typ, Ifaces_List); |
| 13635 |
|
| 13636 |
Elmt := First_Elmt (Ifaces_List); |
| 13637 |
while Present (Elmt) loop |
| 13638 |
if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True) |
| 13639 |
and then Exclude_Parents |
| 13640 |
then |
| 13641 |
null; |
| 13642 |
|
| 13643 |
elsif Node (Elmt) = Iface then |
| 13644 |
return True; |
| 13645 |
end if; |
| 13646 |
|
| 13647 |
Next_Elmt (Elmt); |
| 13648 |
end loop; |
| 13649 |
|
| 13650 |
return False; |
| 13651 |
end Implements_Interface; |
| 13652 |
|
| 13653 |
-------------------------------- |
| 13654 |
-- Implicitly_Designated_Type -- |
| 13655 |
-------------------------------- |
| 13656 |
|
| 13657 |
function Implicitly_Designated_Type (Typ : Entity_Id) return Entity_Id is |
| 13658 |
Desig : constant Entity_Id := Designated_Type (Typ); |
| 13659 |
|
| 13660 |
begin |
| 13661 |
-- An implicit dereference is a legal occurrence of an incomplete type |
| 13662 |
-- imported through a limited_with clause, if the full view is visible. |
| 13663 |
|
| 13664 |
if Is_Incomplete_Type (Desig) |
| 13665 |
and then From_Limited_With (Desig) |
| 13666 |
and then not From_Limited_With (Scope (Desig)) |
| 13667 |
and then |
| 13668 |
(Is_Immediately_Visible (Scope (Desig)) |
| 13669 |
or else |
| 13670 |
(Is_Child_Unit (Scope (Desig)) |
| 13671 |
and then Is_Visible_Lib_Unit (Scope (Desig)))) |
| 13672 |
then |
| 13673 |
return Available_View (Desig); |
| 13674 |
else |
| 13675 |
return Desig; |
| 13676 |
end if; |
| 13677 |
end Implicitly_Designated_Type; |
| 13678 |
|
| 13679 |
------------------------------------ |
| 13680 |
-- In_Assertion_Expression_Pragma -- |
| 13681 |
------------------------------------ |
| 13682 |
|
| 13683 |
function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is |
| 13684 |
Par : Node_Id; |
| 13685 |
Prag : Node_Id := Empty; |
| 13686 |
|
| 13687 |
begin |
| 13688 |
-- Climb the parent chain looking for an enclosing pragma |
| 13689 |
|
| 13690 |
Par := N; |
| 13691 |
while Present (Par) loop |
| 13692 |
if Nkind (Par) = N_Pragma then |
| 13693 |
Prag := Par; |
| 13694 |
exit; |
| 13695 |
|
| 13696 |
-- Precondition-like pragmas are expanded into if statements, check |
| 13697 |
-- the original node instead. |
| 13698 |
|
| 13699 |
elsif Nkind (Original_Node (Par)) = N_Pragma then |
| 13700 |
Prag := Original_Node (Par); |
| 13701 |
exit; |
| 13702 |
|
| 13703 |
-- The expansion of attribute 'Old generates a constant to capture |
| 13704 |
-- the result of the prefix. If the parent traversal reaches |
| 13705 |
-- one of these constants, then the node technically came from a |
| 13706 |
-- postcondition-like pragma. Note that the Ekind is not tested here |
| 13707 |
-- because N may be the expression of an object declaration which is |
| 13708 |
-- currently being analyzed. Such objects carry Ekind of E_Void. |
| 13709 |
|
| 13710 |
elsif Nkind (Par) = N_Object_Declaration |
| 13711 |
and then Constant_Present (Par) |
| 13712 |
and then Stores_Attribute_Old_Prefix (Defining_Entity (Par)) |
| 13713 |
then |
| 13714 |
return True; |
| 13715 |
|
| 13716 |
-- Prevent the search from going too far |
| 13717 |
|
| 13718 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 13719 |
return False; |
| 13720 |
end if; |
| 13721 |
|
| 13722 |
Par := Parent (Par); |
| 13723 |
end loop; |
| 13724 |
|
| 13725 |
return |
| 13726 |
Present (Prag) |
| 13727 |
and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag)); |
| 13728 |
end In_Assertion_Expression_Pragma; |
| 13729 |
|
| 13730 |
------------------- |
| 13731 |
-- In_Check_Node -- |
| 13732 |
------------------- |
| 13733 |
|
| 13734 |
function In_Check_Node (N : Node_Id) return Boolean is |
| 13735 |
Par : Node_Id := Parent (N); |
| 13736 |
begin |
| 13737 |
while Present (Par) loop |
| 13738 |
if Nkind (Par) in N_Raise_xxx_Error then |
| 13739 |
return True; |
| 13740 |
|
| 13741 |
-- Prevent the search from going too far |
| 13742 |
|
| 13743 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 13744 |
return False; |
| 13745 |
|
| 13746 |
else |
| 13747 |
Par := Parent (Par); |
| 13748 |
end if; |
| 13749 |
end loop; |
| 13750 |
|
| 13751 |
return False; |
| 13752 |
end In_Check_Node; |
| 13753 |
|
| 13754 |
------------------------------- |
| 13755 |
-- In_Generic_Formal_Package -- |
| 13756 |
------------------------------- |
| 13757 |
|
| 13758 |
function In_Generic_Formal_Package (E : Entity_Id) return Boolean is |
| 13759 |
Par : Node_Id; |
| 13760 |
|
| 13761 |
begin |
| 13762 |
Par := Parent (E); |
| 13763 |
while Present (Par) loop |
| 13764 |
if Nkind (Par) = N_Formal_Package_Declaration |
| 13765 |
or else Nkind (Original_Node (Par)) = N_Formal_Package_Declaration |
| 13766 |
then |
| 13767 |
return True; |
| 13768 |
end if; |
| 13769 |
|
| 13770 |
Par := Parent (Par); |
| 13771 |
end loop; |
| 13772 |
|
| 13773 |
return False; |
| 13774 |
end In_Generic_Formal_Package; |
| 13775 |
|
| 13776 |
---------------------- |
| 13777 |
-- In_Generic_Scope -- |
| 13778 |
---------------------- |
| 13779 |
|
| 13780 |
function In_Generic_Scope (E : Entity_Id) return Boolean is |
| 13781 |
S : Entity_Id; |
| 13782 |
|
| 13783 |
begin |
| 13784 |
S := Scope (E); |
| 13785 |
while Present (S) and then S /= Standard_Standard loop |
| 13786 |
if Is_Generic_Unit (S) then |
| 13787 |
return True; |
| 13788 |
end if; |
| 13789 |
|
| 13790 |
S := Scope (S); |
| 13791 |
end loop; |
| 13792 |
|
| 13793 |
return False; |
| 13794 |
end In_Generic_Scope; |
| 13795 |
|
| 13796 |
----------------- |
| 13797 |
-- In_Instance -- |
| 13798 |
----------------- |
| 13799 |
|
| 13800 |
function In_Instance return Boolean is |
| 13801 |
Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); |
| 13802 |
S : Entity_Id; |
| 13803 |
|
| 13804 |
begin |
| 13805 |
S := Current_Scope; |
| 13806 |
while Present (S) and then S /= Standard_Standard loop |
| 13807 |
if Is_Generic_Instance (S) then |
| 13808 |
|
| 13809 |
-- A child instance is always compiled in the context of a parent |
| 13810 |
-- instance. Nevertheless, its actuals must not be analyzed in an |
| 13811 |
-- instance context. We detect this case by examining the current |
| 13812 |
-- compilation unit, which must be a child instance, and checking |
| 13813 |
-- that it has not been analyzed yet. |
| 13814 |
|
| 13815 |
if Is_Child_Unit (Curr_Unit) |
| 13816 |
and then Nkind (Unit (Cunit (Current_Sem_Unit))) = |
| 13817 |
N_Package_Instantiation |
| 13818 |
and then Ekind (Curr_Unit) = E_Void |
| 13819 |
then |
| 13820 |
return False; |
| 13821 |
else |
| 13822 |
return True; |
| 13823 |
end if; |
| 13824 |
end if; |
| 13825 |
|
| 13826 |
S := Scope (S); |
| 13827 |
end loop; |
| 13828 |
|
| 13829 |
return False; |
| 13830 |
end In_Instance; |
| 13831 |
|
| 13832 |
---------------------- |
| 13833 |
-- In_Instance_Body -- |
| 13834 |
---------------------- |
| 13835 |
|
| 13836 |
function In_Instance_Body return Boolean is |
| 13837 |
S : Entity_Id; |
| 13838 |
|
| 13839 |
begin |
| 13840 |
S := Current_Scope; |
| 13841 |
while Present (S) and then S /= Standard_Standard loop |
| 13842 |
if Ekind (S) in E_Function | E_Procedure |
| 13843 |
and then Is_Generic_Instance (S) |
| 13844 |
then |
| 13845 |
return True; |
| 13846 |
|
| 13847 |
elsif Ekind (S) = E_Package |
| 13848 |
and then In_Package_Body (S) |
| 13849 |
and then Is_Generic_Instance (S) |
| 13850 |
then |
| 13851 |
return True; |
| 13852 |
end if; |
| 13853 |
|
| 13854 |
S := Scope (S); |
| 13855 |
end loop; |
| 13856 |
|
| 13857 |
return False; |
| 13858 |
end In_Instance_Body; |
| 13859 |
|
| 13860 |
----------------------------- |
| 13861 |
-- In_Instance_Not_Visible -- |
| 13862 |
----------------------------- |
| 13863 |
|
| 13864 |
function In_Instance_Not_Visible return Boolean is |
| 13865 |
S : Entity_Id; |
| 13866 |
|
| 13867 |
begin |
| 13868 |
S := Current_Scope; |
| 13869 |
while Present (S) and then S /= Standard_Standard loop |
| 13870 |
if Ekind (S) in E_Function | E_Procedure |
| 13871 |
and then Is_Generic_Instance (S) |
| 13872 |
then |
| 13873 |
return True; |
| 13874 |
|
| 13875 |
elsif Ekind (S) = E_Package |
| 13876 |
and then (In_Package_Body (S) or else In_Private_Part (S)) |
| 13877 |
and then Is_Generic_Instance (S) |
| 13878 |
then |
| 13879 |
return True; |
| 13880 |
end if; |
| 13881 |
|
| 13882 |
S := Scope (S); |
| 13883 |
end loop; |
| 13884 |
|
| 13885 |
return False; |
| 13886 |
end In_Instance_Not_Visible; |
| 13887 |
|
| 13888 |
------------------------------ |
| 13889 |
-- In_Instance_Visible_Part -- |
| 13890 |
------------------------------ |
| 13891 |
|
| 13892 |
function In_Instance_Visible_Part |
| 13893 |
(Id : Entity_Id := Current_Scope) return Boolean |
| 13894 |
is |
| 13895 |
Inst : Entity_Id; |
| 13896 |
|
| 13897 |
begin |
| 13898 |
Inst := Id; |
| 13899 |
while Present (Inst) and then Inst /= Standard_Standard loop |
| 13900 |
if Ekind (Inst) = E_Package |
| 13901 |
and then Is_Generic_Instance (Inst) |
| 13902 |
and then not In_Package_Body (Inst) |
| 13903 |
and then not In_Private_Part (Inst) |
| 13904 |
then |
| 13905 |
return True; |
| 13906 |
end if; |
| 13907 |
|
| 13908 |
Inst := Scope (Inst); |
| 13909 |
end loop; |
| 13910 |
|
| 13911 |
return False; |
| 13912 |
end In_Instance_Visible_Part; |
| 13913 |
|
| 13914 |
--------------------- |
| 13915 |
-- In_Package_Body -- |
| 13916 |
--------------------- |
| 13917 |
|
| 13918 |
function In_Package_Body return Boolean is |
| 13919 |
S : Entity_Id; |
| 13920 |
|
| 13921 |
begin |
| 13922 |
S := Current_Scope; |
| 13923 |
while Present (S) and then S /= Standard_Standard loop |
| 13924 |
if Ekind (S) = E_Package and then In_Package_Body (S) then |
| 13925 |
return True; |
| 13926 |
else |
| 13927 |
S := Scope (S); |
| 13928 |
end if; |
| 13929 |
end loop; |
| 13930 |
|
| 13931 |
return False; |
| 13932 |
end In_Package_Body; |
| 13933 |
|
| 13934 |
-------------------------- |
| 13935 |
-- In_Pragma_Expression -- |
| 13936 |
-------------------------- |
| 13937 |
|
| 13938 |
function In_Pragma_Expression |
| 13939 |
(N : Node_Id; Nam : Name_Id := No_Name) return Boolean |
| 13940 |
is |
| 13941 |
P : Node_Id := Parent (N); |
| 13942 |
|
| 13943 |
begin |
| 13944 |
loop |
| 13945 |
if No (P) then |
| 13946 |
return False; |
| 13947 |
|
| 13948 |
-- Prevent the search from going too far |
| 13949 |
|
| 13950 |
elsif Is_Body_Or_Package_Declaration (P) then |
| 13951 |
return False; |
| 13952 |
|
| 13953 |
elsif Nkind (P) = N_Pragma |
| 13954 |
and then (Nam = No_Name or else Pragma_Name (P) = Nam) |
| 13955 |
then |
| 13956 |
return True; |
| 13957 |
|
| 13958 |
else |
| 13959 |
P := Parent (P); |
| 13960 |
end if; |
| 13961 |
end loop; |
| 13962 |
end In_Pragma_Expression; |
| 13963 |
|
| 13964 |
--------------------------- |
| 13965 |
-- In_Pre_Post_Condition -- |
| 13966 |
--------------------------- |
| 13967 |
|
| 13968 |
function In_Pre_Post_Condition |
| 13969 |
(N : Node_Id; Class_Wide_Only : Boolean := False) return Boolean |
| 13970 |
is |
| 13971 |
Par : Node_Id; |
| 13972 |
Prag : Node_Id := Empty; |
| 13973 |
Prag_Id : Pragma_Id; |
| 13974 |
|
| 13975 |
begin |
| 13976 |
-- Climb the parent chain looking for an enclosing pragma |
| 13977 |
|
| 13978 |
Par := N; |
| 13979 |
while Present (Par) loop |
| 13980 |
if Nkind (Par) = N_Pragma then |
| 13981 |
Prag := Par; |
| 13982 |
exit; |
| 13983 |
|
| 13984 |
-- Prevent the search from going too far |
| 13985 |
|
| 13986 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 13987 |
exit; |
| 13988 |
end if; |
| 13989 |
|
| 13990 |
Par := Parent (Par); |
| 13991 |
end loop; |
| 13992 |
|
| 13993 |
if Present (Prag) then |
| 13994 |
Prag_Id := Get_Pragma_Id (Prag); |
| 13995 |
|
| 13996 |
if Class_Wide_Only then |
| 13997 |
return |
| 13998 |
Prag_Id = Pragma_Post_Class |
| 13999 |
or else Prag_Id = Pragma_Pre_Class |
| 14000 |
or else (Class_Present (Prag) |
| 14001 |
and then (Prag_Id = Pragma_Post |
| 14002 |
or else Prag_Id = Pragma_Postcondition |
| 14003 |
or else Prag_Id = Pragma_Pre |
| 14004 |
or else Prag_Id = Pragma_Precondition)); |
| 14005 |
else |
| 14006 |
return |
| 14007 |
Prag_Id = Pragma_Post |
| 14008 |
or else Prag_Id = Pragma_Post_Class |
| 14009 |
or else Prag_Id = Pragma_Postcondition |
| 14010 |
or else Prag_Id = Pragma_Pre |
| 14011 |
or else Prag_Id = Pragma_Pre_Class |
| 14012 |
or else Prag_Id = Pragma_Precondition; |
| 14013 |
end if; |
| 14014 |
|
| 14015 |
-- Otherwise the node is not enclosed by a pre/postcondition pragma |
| 14016 |
|
| 14017 |
else |
| 14018 |
return False; |
| 14019 |
end if; |
| 14020 |
end In_Pre_Post_Condition; |
| 14021 |
|
| 14022 |
------------------------------ |
| 14023 |
-- In_Quantified_Expression -- |
| 14024 |
------------------------------ |
| 14025 |
|
| 14026 |
function In_Quantified_Expression (N : Node_Id) return Boolean is |
| 14027 |
P : Node_Id; |
| 14028 |
begin |
| 14029 |
P := Parent (N); |
| 14030 |
loop |
| 14031 |
if No (P) then |
| 14032 |
return False; |
| 14033 |
|
| 14034 |
-- Prevent the search from going too far |
| 14035 |
|
| 14036 |
elsif Is_Body_Or_Package_Declaration (P) then |
| 14037 |
return False; |
| 14038 |
|
| 14039 |
elsif Nkind (P) = N_Quantified_Expression then |
| 14040 |
return True; |
| 14041 |
else |
| 14042 |
P := Parent (P); |
| 14043 |
end if; |
| 14044 |
end loop; |
| 14045 |
end In_Quantified_Expression; |
| 14046 |
|
| 14047 |
------------------------------------- |
| 14048 |
-- In_Reverse_Storage_Order_Object -- |
| 14049 |
------------------------------------- |
| 14050 |
|
| 14051 |
function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is |
| 14052 |
Pref : Node_Id; |
| 14053 |
Btyp : Entity_Id := Empty; |
| 14054 |
|
| 14055 |
begin |
| 14056 |
-- Climb up indexed components |
| 14057 |
|
| 14058 |
Pref := N; |
| 14059 |
loop |
| 14060 |
case Nkind (Pref) is |
| 14061 |
when N_Selected_Component => |
| 14062 |
Pref := Prefix (Pref); |
| 14063 |
exit; |
| 14064 |
|
| 14065 |
when N_Indexed_Component => |
| 14066 |
Pref := Prefix (Pref); |
| 14067 |
|
| 14068 |
when others => |
| 14069 |
Pref := Empty; |
| 14070 |
exit; |
| 14071 |
end case; |
| 14072 |
end loop; |
| 14073 |
|
| 14074 |
if Present (Pref) then |
| 14075 |
Btyp := Base_Type (Etype (Pref)); |
| 14076 |
end if; |
| 14077 |
|
| 14078 |
return Present (Btyp) |
| 14079 |
and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp)) |
| 14080 |
and then Reverse_Storage_Order (Btyp); |
| 14081 |
end In_Reverse_Storage_Order_Object; |
| 14082 |
|
| 14083 |
------------------------------ |
| 14084 |
-- In_Same_Declarative_Part -- |
| 14085 |
------------------------------ |
| 14086 |
|
| 14087 |
function In_Same_Declarative_Part |
| 14088 |
(Context : Node_Id; |
| 14089 |
N : Node_Id) return Boolean |
| 14090 |
is |
| 14091 |
Cont : Node_Id := Context; |
| 14092 |
Nod : Node_Id; |
| 14093 |
|
| 14094 |
begin |
| 14095 |
if Nkind (Cont) = N_Compilation_Unit_Aux then |
| 14096 |
Cont := Parent (Cont); |
| 14097 |
end if; |
| 14098 |
|
| 14099 |
Nod := Parent (N); |
| 14100 |
while Present (Nod) loop |
| 14101 |
if Nod = Cont then |
| 14102 |
return True; |
| 14103 |
|
| 14104 |
elsif Nkind (Nod) in N_Accept_Statement |
| 14105 |
| N_Block_Statement |
| 14106 |
| N_Compilation_Unit |
| 14107 |
| N_Entry_Body |
| 14108 |
| N_Package_Body |
| 14109 |
| N_Package_Declaration |
| 14110 |
| N_Protected_Body |
| 14111 |
| N_Subprogram_Body |
| 14112 |
| N_Task_Body |
| 14113 |
then |
| 14114 |
return False; |
| 14115 |
|
| 14116 |
elsif Nkind (Nod) = N_Subunit then |
| 14117 |
Nod := Corresponding_Stub (Nod); |
| 14118 |
|
| 14119 |
else |
| 14120 |
Nod := Parent (Nod); |
| 14121 |
end if; |
| 14122 |
end loop; |
| 14123 |
|
| 14124 |
return False; |
| 14125 |
end In_Same_Declarative_Part; |
| 14126 |
|
| 14127 |
-------------------------------------- |
| 14128 |
-- In_Subprogram_Or_Concurrent_Unit -- |
| 14129 |
-------------------------------------- |
| 14130 |
|
| 14131 |
function In_Subprogram_Or_Concurrent_Unit return Boolean is |
| 14132 |
E : Entity_Id; |
| 14133 |
K : Entity_Kind; |
| 14134 |
|
| 14135 |
begin |
| 14136 |
-- Use scope chain to check successively outer scopes |
| 14137 |
|
| 14138 |
E := Current_Scope; |
| 14139 |
loop |
| 14140 |
K := Ekind (E); |
| 14141 |
|
| 14142 |
if K in Subprogram_Kind |
| 14143 |
or else K in Concurrent_Kind |
| 14144 |
or else K in Generic_Subprogram_Kind |
| 14145 |
then |
| 14146 |
return True; |
| 14147 |
|
| 14148 |
elsif E = Standard_Standard then |
| 14149 |
return False; |
| 14150 |
end if; |
| 14151 |
|
| 14152 |
E := Scope (E); |
| 14153 |
end loop; |
| 14154 |
end In_Subprogram_Or_Concurrent_Unit; |
| 14155 |
|
| 14156 |
---------------- |
| 14157 |
-- In_Subtree -- |
| 14158 |
---------------- |
| 14159 |
|
| 14160 |
function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is |
| 14161 |
Curr : Node_Id; |
| 14162 |
|
| 14163 |
begin |
| 14164 |
Curr := N; |
| 14165 |
while Present (Curr) loop |
| 14166 |
if Curr = Root then |
| 14167 |
return True; |
| 14168 |
end if; |
| 14169 |
|
| 14170 |
Curr := Parent (Curr); |
| 14171 |
end loop; |
| 14172 |
|
| 14173 |
return False; |
| 14174 |
end In_Subtree; |
| 14175 |
|
| 14176 |
---------------- |
| 14177 |
-- In_Subtree -- |
| 14178 |
---------------- |
| 14179 |
|
| 14180 |
function In_Subtree |
| 14181 |
(N : Node_Id; |
| 14182 |
Root1 : Node_Id; |
| 14183 |
Root2 : Node_Id) return Boolean |
| 14184 |
is |
| 14185 |
Curr : Node_Id; |
| 14186 |
|
| 14187 |
begin |
| 14188 |
Curr := N; |
| 14189 |
while Present (Curr) loop |
| 14190 |
if Curr = Root1 or else Curr = Root2 then |
| 14191 |
return True; |
| 14192 |
end if; |
| 14193 |
|
| 14194 |
Curr := Parent (Curr); |
| 14195 |
end loop; |
| 14196 |
|
| 14197 |
return False; |
| 14198 |
end In_Subtree; |
| 14199 |
|
| 14200 |
--------------------- |
| 14201 |
-- In_Return_Value -- |
| 14202 |
--------------------- |
| 14203 |
|
| 14204 |
function In_Return_Value (Expr : Node_Id) return Boolean is |
| 14205 |
Par : Node_Id; |
| 14206 |
Prev_Par : Node_Id; |
| 14207 |
Pre : Node_Id; |
| 14208 |
In_Function_Call : Boolean := False; |
| 14209 |
|
| 14210 |
begin |
| 14211 |
-- Move through parent nodes to determine if Expr contributes to the |
| 14212 |
-- return value of the current subprogram. |
| 14213 |
|
| 14214 |
Par := Expr; |
| 14215 |
Prev_Par := Empty; |
| 14216 |
while Present (Par) loop |
| 14217 |
|
| 14218 |
case Nkind (Par) is |
| 14219 |
-- Ignore ranges and they don't contribute to the result |
| 14220 |
|
| 14221 |
when N_Range => |
| 14222 |
return False; |
| 14223 |
|
| 14224 |
-- An object declaration whose parent is an extended return |
| 14225 |
-- statement is a return object. |
| 14226 |
|
| 14227 |
when N_Object_Declaration => |
| 14228 |
if Present (Parent (Par)) |
| 14229 |
and then Nkind (Parent (Par)) = N_Extended_Return_Statement |
| 14230 |
then |
| 14231 |
return True; |
| 14232 |
end if; |
| 14233 |
|
| 14234 |
-- We hit a simple return statement, so we know we are in one |
| 14235 |
|
| 14236 |
when N_Simple_Return_Statement => |
| 14237 |
return True; |
| 14238 |
|
| 14239 |
-- Only include one nexting level of function calls |
| 14240 |
|
| 14241 |
when N_Function_Call => |
| 14242 |
if not In_Function_Call then |
| 14243 |
In_Function_Call := True; |
| 14244 |
|
| 14245 |
-- When the function return type has implicit dereference |
| 14246 |
-- specified we know it cannot directly contribute to the |
| 14247 |
-- return value. |
| 14248 |
|
| 14249 |
if Present (Etype (Par)) |
| 14250 |
and then Has_Implicit_Dereference |
| 14251 |
(Get_Full_View (Etype (Par))) |
| 14252 |
then |
| 14253 |
return False; |
| 14254 |
end if; |
| 14255 |
else |
| 14256 |
return False; |
| 14257 |
end if; |
| 14258 |
|
| 14259 |
-- Check if we are on the right-hand side of an assignment |
| 14260 |
-- statement to a return object. |
| 14261 |
|
| 14262 |
-- This is not specified in the RM ??? |
| 14263 |
|
| 14264 |
when N_Assignment_Statement => |
| 14265 |
if Prev_Par = Name (Par) then |
| 14266 |
return False; |
| 14267 |
end if; |
| 14268 |
|
| 14269 |
Pre := Name (Par); |
| 14270 |
while Present (Pre) loop |
| 14271 |
if Is_Entity_Name (Pre) |
| 14272 |
and then Is_Return_Object (Entity (Pre)) |
| 14273 |
then |
| 14274 |
return True; |
| 14275 |
end if; |
| 14276 |
|
| 14277 |
exit when Nkind (Pre) not in N_Selected_Component |
| 14278 |
| N_Indexed_Component |
| 14279 |
| N_Slice; |
| 14280 |
|
| 14281 |
Pre := Prefix (Pre); |
| 14282 |
end loop; |
| 14283 |
|
| 14284 |
-- Otherwise, we hit a master which was not relevant |
| 14285 |
|
| 14286 |
when others => |
| 14287 |
if Is_Master (Par) then |
| 14288 |
return False; |
| 14289 |
end if; |
| 14290 |
end case; |
| 14291 |
|
| 14292 |
-- Iterate up to the next parent, keeping track of the previous one |
| 14293 |
|
| 14294 |
Prev_Par := Par; |
| 14295 |
Par := Parent (Par); |
| 14296 |
end loop; |
| 14297 |
|
| 14298 |
return False; |
| 14299 |
end In_Return_Value; |
| 14300 |
|
| 14301 |
----------------------------------------- |
| 14302 |
-- In_Statement_Condition_With_Actions -- |
| 14303 |
----------------------------------------- |
| 14304 |
|
| 14305 |
function In_Statement_Condition_With_Actions (N : Node_Id) return Boolean is |
| 14306 |
Prev : Node_Id := N; |
| 14307 |
P : Node_Id := Parent (N); |
| 14308 |
-- P and Prev will be used for traversing the AST, while maintaining an |
| 14309 |
-- invariant that P = Parent (Prev). |
| 14310 |
begin |
| 14311 |
while Present (P) loop |
| 14312 |
if Nkind (P) = N_Iteration_Scheme |
| 14313 |
and then Prev = Condition (P) |
| 14314 |
then |
| 14315 |
return True; |
| 14316 |
|
| 14317 |
elsif Nkind (P) = N_Elsif_Part |
| 14318 |
and then Prev = Condition (P) |
| 14319 |
then |
| 14320 |
return True; |
| 14321 |
|
| 14322 |
-- No point in going beyond statements |
| 14323 |
|
| 14324 |
elsif Nkind (N) in N_Statement_Other_Than_Procedure_Call |
| 14325 |
| N_Procedure_Call_Statement |
| 14326 |
then |
| 14327 |
exit; |
| 14328 |
|
| 14329 |
-- Prevent the search from going too far |
| 14330 |
|
| 14331 |
elsif Is_Body_Or_Package_Declaration (P) then |
| 14332 |
exit; |
| 14333 |
end if; |
| 14334 |
|
| 14335 |
Prev := P; |
| 14336 |
P := Parent (P); |
| 14337 |
end loop; |
| 14338 |
|
| 14339 |
return False; |
| 14340 |
end In_Statement_Condition_With_Actions; |
| 14341 |
|
| 14342 |
--------------------- |
| 14343 |
-- In_Visible_Part -- |
| 14344 |
--------------------- |
| 14345 |
|
| 14346 |
function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is |
| 14347 |
begin |
| 14348 |
return Is_Package_Or_Generic_Package (Scope_Id) |
| 14349 |
and then In_Open_Scopes (Scope_Id) |
| 14350 |
and then not In_Package_Body (Scope_Id) |
| 14351 |
and then not In_Private_Part (Scope_Id); |
| 14352 |
end In_Visible_Part; |
| 14353 |
|
| 14354 |
-------------------------------- |
| 14355 |
-- Incomplete_Or_Partial_View -- |
| 14356 |
-------------------------------- |
| 14357 |
|
| 14358 |
function Incomplete_Or_Partial_View |
| 14359 |
(Id : Entity_Id; Partial_Only : Boolean := False) return Entity_Id |
| 14360 |
is |
| 14361 |
S : constant Entity_Id := Scope (Id); |
| 14362 |
|
| 14363 |
function Inspect_Decls |
| 14364 |
(Decls : List_Id; |
| 14365 |
Taft : Boolean := False) return Entity_Id; |
| 14366 |
-- Check whether a declarative region contains the incomplete or partial |
| 14367 |
-- view of Id. |
| 14368 |
|
| 14369 |
------------------- |
| 14370 |
-- Inspect_Decls -- |
| 14371 |
------------------- |
| 14372 |
|
| 14373 |
function Inspect_Decls |
| 14374 |
(Decls : List_Id; |
| 14375 |
Taft : Boolean := False) return Entity_Id |
| 14376 |
is |
| 14377 |
Decl : Node_Id; |
| 14378 |
Match : Node_Id; |
| 14379 |
|
| 14380 |
begin |
| 14381 |
Decl := First (Decls); |
| 14382 |
while Present (Decl) loop |
| 14383 |
Match := Empty; |
| 14384 |
|
| 14385 |
-- The partial view of a Taft-amendment type is an incomplete |
| 14386 |
-- type. |
| 14387 |
|
| 14388 |
if Taft then |
| 14389 |
if Nkind (Decl) = N_Incomplete_Type_Declaration then |
| 14390 |
Match := Defining_Identifier (Decl); |
| 14391 |
end if; |
| 14392 |
|
| 14393 |
-- Otherwise look for a private type whose full view matches the |
| 14394 |
-- input type. Note that this checks full_type_declaration nodes |
| 14395 |
-- to account for derivations from a private type where the type |
| 14396 |
-- declaration hold the partial view and the full view is an |
| 14397 |
-- itype. |
| 14398 |
|
| 14399 |
elsif Nkind (Decl) in N_Full_Type_Declaration |
| 14400 |
| N_Private_Extension_Declaration |
| 14401 |
| N_Private_Type_Declaration |
| 14402 |
then |
| 14403 |
Match := Defining_Identifier (Decl); |
| 14404 |
end if; |
| 14405 |
|
| 14406 |
-- Guard against unanalyzed entities |
| 14407 |
|
| 14408 |
if Present (Match) |
| 14409 |
and then Is_Type (Match) |
| 14410 |
and then Present (Full_View (Match)) |
| 14411 |
and then Full_View (Match) = Id |
| 14412 |
then |
| 14413 |
return Match; |
| 14414 |
end if; |
| 14415 |
|
| 14416 |
Next (Decl); |
| 14417 |
end loop; |
| 14418 |
|
| 14419 |
return Empty; |
| 14420 |
end Inspect_Decls; |
| 14421 |
|
| 14422 |
-- Local variables |
| 14423 |
|
| 14424 |
Prev : Entity_Id; |
| 14425 |
|
| 14426 |
-- Start of processing for Incomplete_Or_Partial_View |
| 14427 |
|
| 14428 |
begin |
| 14429 |
-- Deferred constant or incomplete type case |
| 14430 |
|
| 14431 |
Prev := Current_Entity (Id); |
| 14432 |
|
| 14433 |
while Present (Prev) loop |
| 14434 |
exit when Scope (Prev) = S; |
| 14435 |
|
| 14436 |
Prev := Homonym (Prev); |
| 14437 |
end loop; |
| 14438 |
|
| 14439 |
if Present (Prev) |
| 14440 |
and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant) |
| 14441 |
and then Present (Full_View (Prev)) |
| 14442 |
and then Full_View (Prev) = Id |
| 14443 |
and then not Partial_Only |
| 14444 |
then |
| 14445 |
return Prev; |
| 14446 |
end if; |
| 14447 |
|
| 14448 |
-- Private or Taft amendment type case |
| 14449 |
|
| 14450 |
if Present (S) and then Is_Package_Or_Generic_Package (S) then |
| 14451 |
declare |
| 14452 |
Pkg_Decl : constant Node_Id := Package_Specification (S); |
| 14453 |
|
| 14454 |
begin |
| 14455 |
-- It is known that Typ has a private view, look for it in the |
| 14456 |
-- visible declarations of the enclosing scope. A special case |
| 14457 |
-- of this is when the two views have been exchanged - the full |
| 14458 |
-- appears earlier than the private. |
| 14459 |
|
| 14460 |
if Has_Private_Declaration (Id) then |
| 14461 |
Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl)); |
| 14462 |
|
| 14463 |
-- Exchanged view case, look in the private declarations |
| 14464 |
|
| 14465 |
if No (Prev) then |
| 14466 |
Prev := Inspect_Decls (Private_Declarations (Pkg_Decl)); |
| 14467 |
end if; |
| 14468 |
|
| 14469 |
return Prev; |
| 14470 |
|
| 14471 |
-- Otherwise if this is the package body, then Typ is a potential |
| 14472 |
-- Taft amendment type. The incomplete view should be located in |
| 14473 |
-- the private declarations of the enclosing scope. |
| 14474 |
|
| 14475 |
elsif In_Package_Body (S) and then not Partial_Only then |
| 14476 |
return Inspect_Decls (Private_Declarations (Pkg_Decl), True); |
| 14477 |
end if; |
| 14478 |
end; |
| 14479 |
end if; |
| 14480 |
|
| 14481 |
-- The type has no incomplete or private view |
| 14482 |
|
| 14483 |
return Empty; |
| 14484 |
end Incomplete_Or_Partial_View; |
| 14485 |
|
| 14486 |
--------------------------------------- |
| 14487 |
-- Incomplete_View_From_Limited_With -- |
| 14488 |
--------------------------------------- |
| 14489 |
|
| 14490 |
function Incomplete_View_From_Limited_With |
| 14491 |
(Typ : Entity_Id) return Entity_Id |
| 14492 |
is |
| 14493 |
begin |
| 14494 |
-- It might make sense to make this an attribute in Einfo, and set it |
| 14495 |
-- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on |
| 14496 |
-- slots for new attributes, and it seems a bit simpler to just search |
| 14497 |
-- the Limited_View (if it exists) for an incomplete type whose |
| 14498 |
-- Non_Limited_View is Typ. |
| 14499 |
|
| 14500 |
if Ekind (Scope (Typ)) = E_Package |
| 14501 |
and then Present (Limited_View (Scope (Typ))) |
| 14502 |
then |
| 14503 |
declare |
| 14504 |
Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ))); |
| 14505 |
begin |
| 14506 |
while Present (Ent) loop |
| 14507 |
if Is_Incomplete_Type (Ent) |
| 14508 |
and then Non_Limited_View (Ent) = Typ |
| 14509 |
then |
| 14510 |
return Ent; |
| 14511 |
end if; |
| 14512 |
|
| 14513 |
Next_Entity (Ent); |
| 14514 |
end loop; |
| 14515 |
end; |
| 14516 |
end if; |
| 14517 |
|
| 14518 |
return Typ; |
| 14519 |
end Incomplete_View_From_Limited_With; |
| 14520 |
|
| 14521 |
---------------------------------- |
| 14522 |
-- Indexed_Component_Bit_Offset -- |
| 14523 |
---------------------------------- |
| 14524 |
|
| 14525 |
function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is |
| 14526 |
Exp : constant Node_Id := First (Expressions (N)); |
| 14527 |
Typ : constant Entity_Id := Etype (Prefix (N)); |
| 14528 |
Off : constant Uint := Component_Size (Typ); |
| 14529 |
Ind : Node_Id; |
| 14530 |
|
| 14531 |
begin |
| 14532 |
-- Return early if the component size is not known or variable |
| 14533 |
|
| 14534 |
if No (Off) or else Off < Uint_0 then |
| 14535 |
return No_Uint; |
| 14536 |
end if; |
| 14537 |
|
| 14538 |
-- Deal with the degenerate case of an empty component |
| 14539 |
|
| 14540 |
if Off = Uint_0 then |
| 14541 |
return Off; |
| 14542 |
end if; |
| 14543 |
|
| 14544 |
-- Check that both the index value and the low bound are known |
| 14545 |
|
| 14546 |
if not Compile_Time_Known_Value (Exp) then |
| 14547 |
return No_Uint; |
| 14548 |
end if; |
| 14549 |
|
| 14550 |
Ind := First_Index (Typ); |
| 14551 |
if No (Ind) then |
| 14552 |
return No_Uint; |
| 14553 |
end if; |
| 14554 |
|
| 14555 |
-- Do not attempt to compute offsets within multi-dimensional arrays |
| 14556 |
|
| 14557 |
if Present (Next_Index (Ind)) then |
| 14558 |
return No_Uint; |
| 14559 |
end if; |
| 14560 |
|
| 14561 |
if Nkind (Ind) = N_Subtype_Indication then |
| 14562 |
Ind := Constraint (Ind); |
| 14563 |
|
| 14564 |
if Nkind (Ind) = N_Range_Constraint then |
| 14565 |
Ind := Range_Expression (Ind); |
| 14566 |
end if; |
| 14567 |
end if; |
| 14568 |
|
| 14569 |
if Nkind (Ind) /= N_Range |
| 14570 |
or else not Compile_Time_Known_Value (Low_Bound (Ind)) |
| 14571 |
then |
| 14572 |
return No_Uint; |
| 14573 |
end if; |
| 14574 |
|
| 14575 |
-- Return the scaled offset |
| 14576 |
|
| 14577 |
return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound (Ind))); |
| 14578 |
end Indexed_Component_Bit_Offset; |
| 14579 |
|
| 14580 |
------------------------------------ |
| 14581 |
-- Inherit_Nonoverridable_Aspects -- |
| 14582 |
------------------------------------ |
| 14583 |
|
| 14584 |
procedure Inherit_Nonoverridable_Aspects |
| 14585 |
(Typ : Entity_Id; From_Typ : Entity_Id) |
| 14586 |
is |
| 14587 |
|
| 14588 |
procedure Inherit_Nonoverridable_Aspect (Item : Node_Id); |
| 14589 |
-- Inherited nonoverridable aspects usually depend on operations of the |
| 14590 |
-- derived type, inherited or overridden. If an aspect is not explicitly |
| 14591 |
-- specified but rather is inherited, then its components (which usually |
| 14592 |
-- denote subprograms) must generally be associated with operations of |
| 14593 |
-- the derived type (with some exceptions, such as inherited class-wide |
| 14594 |
-- operations for indexing aspects). Item is a nonoverridable element |
| 14595 |
-- of From_Typ's Rep_Item list. A new aspect item is created and is |
| 14596 |
-- associated with the appropriate operations of the derived type, |
| 14597 |
-- and that aspect item is inserted at the beginning of Typ's Rep_Item |
| 14598 |
-- list. For an aspect that specifies a subprogram name, this procedure |
| 14599 |
-- also identifies which subprograms are denoted by the derived type's |
| 14600 |
-- inherited aspect (including inherited, overriding, and in some cases |
| 14601 |
-- new subprograms of the derived type). |
| 14602 |
|
| 14603 |
----------------------------------- |
| 14604 |
-- Inherit_Nonoverridable_Aspect -- |
| 14605 |
----------------------------------- |
| 14606 |
|
| 14607 |
procedure Inherit_Nonoverridable_Aspect (Item : Node_Id) is |
| 14608 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 14609 |
Assoc : Node_Id; |
| 14610 |
New_Item : Node_Id; |
| 14611 |
Item_Aspect_Id : constant Nonoverridable_Aspect_Id := |
| 14612 |
Get_Aspect_Id (Item); |
| 14613 |
|
| 14614 |
begin |
| 14615 |
New_Item := Make_Aspect_Specification ( |
| 14616 |
Sloc => Loc, |
| 14617 |
Identifier => Identifier (Item), |
| 14618 |
Expression => New_Copy_Tree (Expression (Item))); |
| 14619 |
Set_Entity (New_Item, Typ); |
| 14620 |
|
| 14621 |
-- We are trying here to implement RM 13.1(15.5): |
| 14622 |
-- if the name denotes one or more primitive subprograms of |
| 14623 |
-- the type, the inherited aspect is a name that denotes the |
| 14624 |
-- corresponding primitive subprogram(s) of the derived type; |
| 14625 |
|
| 14626 |
case Item_Aspect_Id is |
| 14627 |
when Aspect_Aggregate => |
| 14628 |
Assoc := First (Component_Associations (Expression (New_Item))); |
| 14629 |
|
| 14630 |
-- Replace aggregate operations coming from the aspect of the |
| 14631 |
-- parent type with the corresponding operations of the derived |
| 14632 |
-- type (which can be inherited or overriding). |
| 14633 |
|
| 14634 |
while Present (Assoc) loop |
| 14635 |
pragma Assert (Nkind (Expression (Assoc)) = N_Identifier); |
| 14636 |
|
| 14637 |
Set_Entity |
| 14638 |
(Expression (Assoc), |
| 14639 |
Corresponding_Op_Of_Derived_Type |
| 14640 |
(Ancestor_Op => Entity (Expression (Assoc)), |
| 14641 |
Descendant_Type => Typ)); |
| 14642 |
Next (Assoc); |
| 14643 |
end loop; |
| 14644 |
|
| 14645 |
when Aspect_Integer_Literal |
| 14646 |
| Aspect_Real_Literal |
| 14647 |
| Aspect_String_Literal |
| 14648 |
=> |
| 14649 |
Set_Entity |
| 14650 |
(Expression (New_Item), |
| 14651 |
Corresponding_Op_Of_Derived_Type |
| 14652 |
(Ancestor_Op => Entity (Expression (Item)), |
| 14653 |
Descendant_Type => Typ)); |
| 14654 |
|
| 14655 |
-- Build corresponding attribute definition clause for following |
| 14656 |
-- name-valued aspects (needed later in Is_Confirming). |
| 14657 |
|
| 14658 |
when Aspect_Default_Iterator |
| 14659 |
| Aspect_Constant_Indexing |
| 14660 |
| Aspect_Variable_Indexing |
| 14661 |
=> |
| 14662 |
declare |
| 14663 |
Expr_Copy : constant Node_Id := |
| 14664 |
New_Copy_Tree (Expression (Item)); |
| 14665 |
|
| 14666 |
Aitem : constant Node_Id := |
| 14667 |
Make_Attribute_Definition_Clause (Loc, |
| 14668 |
Name => New_Occurrence_Of (Typ, Loc), |
| 14669 |
Chars => Chars (Identifier (Item)), |
| 14670 |
Expression => Expr_Copy); |
| 14671 |
|
| 14672 |
New_Entity : Entity_Id := Empty; |
| 14673 |
Parent_Indexing_Subps : Elist_Id; |
| 14674 |
New_Indexing_Subps : Elist_Id; |
| 14675 |
Subp_Elmt : Elmt_Id; |
| 14676 |
|
| 14677 |
begin |
| 14678 |
Set_Parent (Aitem, New_Item); |
| 14679 |
|
| 14680 |
if Nkind (Expr_Copy) in N_Has_Entity |
| 14681 |
and then Present (Entity (Expr_Copy)) |
| 14682 |
then |
| 14683 |
if Present (Primitive_Operations (Typ)) then |
| 14684 |
|
| 14685 |
-- Indexing aspects allow multiple subprograms |
| 14686 |
|
| 14687 |
if Item_Aspect_Id in Aspect_Constant_Indexing |
| 14688 |
| Aspect_Variable_Indexing |
| 14689 |
then |
| 14690 |
Parent_Indexing_Subps := Aspect_Subprograms (Item); |
| 14691 |
Subp_Elmt := First_Elmt (Parent_Indexing_Subps); |
| 14692 |
|
| 14693 |
New_Indexing_Subps := No_Elist; |
| 14694 |
|
| 14695 |
-- First collect the functions of the derived type |
| 14696 |
-- that correspond to the functions inherited from |
| 14697 |
-- an ancestor type (From_Typ). Note that in some |
| 14698 |
-- cases these may be class-wide functions rather |
| 14699 |
-- than primitives. |
| 14700 |
|
| 14701 |
while Present (Subp_Elmt) loop |
| 14702 |
New_Entity := Corresponding_Op_Of_Derived_Type |
| 14703 |
(Ancestor_Op => Node (Subp_Elmt), |
| 14704 |
Descendant_Type => Typ); |
| 14705 |
|
| 14706 |
-- Add the corresponding subprogram to the new |
| 14707 |
-- aspect's list of subprograms. |
| 14708 |
|
| 14709 |
Append_New_Elmt (New_Entity, New_Indexing_Subps); |
| 14710 |
|
| 14711 |
Next_Elmt (Subp_Elmt); |
| 14712 |
end loop; |
| 14713 |
|
| 14714 |
-- Traverse the primitive operations of the type |
| 14715 |
-- to locate any indexing functions that have been |
| 14716 |
-- added to the type (i.e., that have been neither |
| 14717 |
-- inherited, nor override any of the inherited |
| 14718 |
-- indexing functions). |
| 14719 |
|
| 14720 |
-- ??? Note that this doesn't currently account for |
| 14721 |
-- the possibility of added nonprimitive indexing |
| 14722 |
-- functions (class-wide functions of the derived |
| 14723 |
-- type). This presumably would require traversing |
| 14724 |
-- all of the declarations of the immediately |
| 14725 |
-- enclosing declaration list, which perhaps we |
| 14726 |
-- should arguably be doing in any case, rather |
| 14727 |
-- than separately gathering inherited, overriding, |
| 14728 |
-- and new indexing functions (and which might also |
| 14729 |
-- be more efficient). Perhaps this could/should be |
| 14730 |
-- done in Analyze_Aspects_At_Freeze_Point, but |
| 14731 |
-- experimenting with that led to difficulties. |
| 14732 |
|
| 14733 |
declare |
| 14734 |
Prim_Ops : constant Elist_Id := |
| 14735 |
Primitive_Operations (Typ); |
| 14736 |
Prim_Elmt : Elmt_Id := First_Elmt (Prim_Ops); |
| 14737 |
Prim_Id : Entity_Id; |
| 14738 |
Valid_Func : Boolean; |
| 14739 |
|
| 14740 |
begin |
| 14741 |
while Present (Prim_Elmt) loop |
| 14742 |
Prim_Id := Node (Prim_Elmt); |
| 14743 |
|
| 14744 |
if Chars (Prim_Id) = Chars (Expression (Item)) |
| 14745 |
and then |
| 14746 |
not Is_Inherited_Operation (Prim_Id) |
| 14747 |
and then |
| 14748 |
not Is_Overriding_Subprogram (Prim_Id) |
| 14749 |
then |
| 14750 |
-- Verify that the new primitive has |
| 14751 |
-- a correct profile to qualify as an |
| 14752 |
-- indexing function for Typ. |
| 14753 |
|
| 14754 |
Check_Function_For_Indexing_Aspect |
| 14755 |
(New_Item, Typ, Prim_Id, Valid_Func); |
| 14756 |
|
| 14757 |
if Valid_Func then |
| 14758 |
Append_New_Elmt |
| 14759 |
(Prim_Id, New_Indexing_Subps); |
| 14760 |
end if; |
| 14761 |
end if; |
| 14762 |
|
| 14763 |
Next_Elmt (Prim_Elmt); |
| 14764 |
end loop; |
| 14765 |
end; |
| 14766 |
|
| 14767 |
-- Save new list of indexing functions on aspect |
| 14768 |
|
| 14769 |
Set_Aspect_Subprograms |
| 14770 |
(New_Item, New_Indexing_Subps); |
| 14771 |
|
| 14772 |
-- Item_Aspect_Id = Aspect_Default_Iterator |
| 14773 |
|
| 14774 |
else |
| 14775 |
New_Entity := Corresponding_Op_Of_Derived_Type |
| 14776 |
(Ancestor_Op => Entity (Expr_Copy), |
| 14777 |
Descendant_Type => Typ); |
| 14778 |
end if; |
| 14779 |
end if; |
| 14780 |
|
| 14781 |
Set_Entity (Expr_Copy, New_Entity); |
| 14782 |
|
| 14783 |
-- We want the Entity attributes of the two expressions |
| 14784 |
-- to agree. |
| 14785 |
|
| 14786 |
Set_Entity (Expression (New_Item), Entity (Expr_Copy)); |
| 14787 |
|
| 14788 |
end if; |
| 14789 |
|
| 14790 |
Set_From_Aspect_Specification (Aitem); |
| 14791 |
Set_Is_Delayed_Aspect (Aitem); |
| 14792 |
Set_Aspect_Rep_Item (New_Item, Aitem); |
| 14793 |
Set_Parent (Aitem, New_Item); |
| 14794 |
end; |
| 14795 |
|
| 14796 |
-- Nothing special to do for the other nonoverridable aspects |
| 14797 |
|
| 14798 |
when Aspect_Implicit_Dereference |
| 14799 |
| Aspect_Iterator_Element |
| 14800 |
| Aspect_Max_Entry_Queue_Length |
| 14801 |
| Aspect_No_Controlled_Parts |
| 14802 |
=> |
| 14803 |
return; |
| 14804 |
end case; |
| 14805 |
|
| 14806 |
Set_Expression_Copy (New_Item, New_Copy_Tree (Expression (New_Item))); |
| 14807 |
|
| 14808 |
-- Place new aspect spec in list of rep clauses, to ensure |
| 14809 |
-- later resolution. |
| 14810 |
|
| 14811 |
Set_Next_Rep_Item (New_Item, First_Rep_Item (Typ)); |
| 14812 |
Set_First_Rep_Item (Typ, New_Item); |
| 14813 |
Set_Is_Delayed_Aspect (New_Item); |
| 14814 |
Set_Has_Delayed_Aspects (Typ); |
| 14815 |
end Inherit_Nonoverridable_Aspect; |
| 14816 |
|
| 14817 |
-- Local declarations |
| 14818 |
|
| 14819 |
Item : Node_Id; |
| 14820 |
|
| 14821 |
-- Start of processing for Inherit_Nonoverridable_Aspects |
| 14822 |
|
| 14823 |
begin |
| 14824 |
-- Typ may be the full type of a type derived from a private type, |
| 14825 |
-- in which case the full type primitive operations list can be empty. |
| 14826 |
-- In that case its nonoverridable aspects shouldn't be updated, and |
| 14827 |
-- we rely on the private view's aspect having been updated. (It's not |
| 14828 |
-- clear whether this is appropriate handling for these???) |
| 14829 |
|
| 14830 |
if Has_Private_Declaration (Typ) |
| 14831 |
and then |
| 14832 |
(No (Direct_Primitive_Operations (Typ)) |
| 14833 |
or else Is_Empty_Elmt_List (Direct_Primitive_Operations (Typ))) |
| 14834 |
then |
| 14835 |
return; |
| 14836 |
end if; |
| 14837 |
|
| 14838 |
-- Inherit and update any nonoverridable aspects that come from the |
| 14839 |
-- parent type that should refer to inherited or overriding operations. |
| 14840 |
|
| 14841 |
Item := First_Rep_Item (From_Typ); |
| 14842 |
|
| 14843 |
while Present (Item) loop |
| 14844 |
if Nkind (Item) = N_Aspect_Specification |
| 14845 |
and then Get_Aspect_Id (Item) in Nonoverridable_Aspect_Id |
| 14846 |
and then Entity (Item) = Base_Type (From_Typ) |
| 14847 |
then |
| 14848 |
Inherit_Nonoverridable_Aspect (Item); |
| 14849 |
end if; |
| 14850 |
|
| 14851 |
Item := Next_Rep_Item (Item); |
| 14852 |
end loop; |
| 14853 |
end Inherit_Nonoverridable_Aspects; |
| 14854 |
|
| 14855 |
----------------------------- |
| 14856 |
-- Inherit_Predicate_Flags -- |
| 14857 |
----------------------------- |
| 14858 |
|
| 14859 |
procedure Inherit_Predicate_Flags |
| 14860 |
(Subt, Par : Entity_Id; |
| 14861 |
Only_Flags : Boolean := False) |
| 14862 |
is |
| 14863 |
begin |
| 14864 |
if Ada_Version < Ada_2012 |
| 14865 |
or else Present (Predicate_Function (Subt)) |
| 14866 |
then |
| 14867 |
return; |
| 14868 |
end if; |
| 14869 |
|
| 14870 |
Set_Has_Predicates (Subt, Has_Predicates (Par)); |
| 14871 |
Set_Has_Static_Predicate_Aspect |
| 14872 |
(Subt, Has_Static_Predicate_Aspect (Par)); |
| 14873 |
Set_Has_Dynamic_Predicate_Aspect |
| 14874 |
(Subt, Has_Dynamic_Predicate_Aspect (Par)); |
| 14875 |
Set_Has_Ghost_Predicate_Aspect |
| 14876 |
(Subt, Has_Ghost_Predicate_Aspect (Par)); |
| 14877 |
|
| 14878 |
-- A named subtype does not inherit the predicate function of its |
| 14879 |
-- parent but an itype declared for a loop index needs the discrete |
| 14880 |
-- predicate information of its parent to execute the loop properly. |
| 14881 |
-- Moreover, a named private subtype whose full view is an itype also |
| 14882 |
-- needs to inherit a predicate function because it will not be frozen. |
| 14883 |
-- A non-discrete type may has a static predicate (for example True) |
| 14884 |
-- but has no static_discrete_predicate. |
| 14885 |
|
| 14886 |
if not Only_Flags |
| 14887 |
and then (Is_Itype (Subt) |
| 14888 |
or else (Ekind (Subt) = E_Private_Subtype |
| 14889 |
and then Present (Full_View (Subt)) |
| 14890 |
and then Is_Itype (Full_View (Subt)))) |
| 14891 |
and then Present (Predicate_Function (Par)) |
| 14892 |
then |
| 14893 |
Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par)); |
| 14894 |
|
| 14895 |
if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then |
| 14896 |
Set_Static_Discrete_Predicate |
| 14897 |
(Subt, Static_Discrete_Predicate (Par)); |
| 14898 |
end if; |
| 14899 |
end if; |
| 14900 |
end Inherit_Predicate_Flags; |
| 14901 |
|
| 14902 |
---------------------------- |
| 14903 |
-- Inherit_Rep_Item_Chain -- |
| 14904 |
---------------------------- |
| 14905 |
|
| 14906 |
procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is |
| 14907 |
Item : Node_Id; |
| 14908 |
Next_Item : Node_Id; |
| 14909 |
|
| 14910 |
begin |
| 14911 |
-- There are several inheritance scenarios to consider depending on |
| 14912 |
-- whether both types have rep item chains and whether the destination |
| 14913 |
-- type already inherits part of the source type's rep item chain. |
| 14914 |
|
| 14915 |
-- 1) The source type lacks a rep item chain |
| 14916 |
-- From_Typ ---> Empty |
| 14917 |
-- |
| 14918 |
-- Typ --------> Item (or Empty) |
| 14919 |
|
| 14920 |
-- In this case inheritance cannot take place because there are no items |
| 14921 |
-- to inherit. |
| 14922 |
|
| 14923 |
-- 2) The destination type lacks a rep item chain |
| 14924 |
-- From_Typ ---> Item ---> ... |
| 14925 |
-- |
| 14926 |
-- Typ --------> Empty |
| 14927 |
|
| 14928 |
-- Inheritance takes place by setting the First_Rep_Item of the |
| 14929 |
-- destination type to the First_Rep_Item of the source type. |
| 14930 |
-- From_Typ ---> Item ---> ... |
| 14931 |
-- ^ |
| 14932 |
-- Typ -----------+ |
| 14933 |
|
| 14934 |
-- 3.1) Both source and destination types have at least one rep item. |
| 14935 |
-- The destination type does NOT inherit a rep item from the source |
| 14936 |
-- type. |
| 14937 |
-- From_Typ ---> Item ---> Item |
| 14938 |
-- |
| 14939 |
-- Typ --------> Item ---> Item |
| 14940 |
|
| 14941 |
-- Inheritance takes place by setting the Next_Rep_Item of the last item |
| 14942 |
-- of the destination type to the First_Rep_Item of the source type. |
| 14943 |
-- From_Typ -------------------> Item ---> Item |
| 14944 |
-- ^ |
| 14945 |
-- Typ --------> Item ---> Item --+ |
| 14946 |
|
| 14947 |
-- 3.2) Both source and destination types have at least one rep item. |
| 14948 |
-- The destination type DOES inherit part of the rep item chain of the |
| 14949 |
-- source type. |
| 14950 |
-- From_Typ ---> Item ---> Item ---> Item |
| 14951 |
-- ^ |
| 14952 |
-- Typ --------> Item ------+ |
| 14953 |
|
| 14954 |
-- This rare case arises when the full view of a private extension must |
| 14955 |
-- inherit the rep item chain from the full view of its parent type and |
| 14956 |
-- the full view of the parent type contains extra rep items. Currently |
| 14957 |
-- only invariants may lead to such form of inheritance. |
| 14958 |
|
| 14959 |
-- type From_Typ is tagged private |
| 14960 |
-- with Type_Invariant'Class => Item_2; |
| 14961 |
|
| 14962 |
-- type Typ is new From_Typ with private |
| 14963 |
-- with Type_Invariant => Item_4; |
| 14964 |
|
| 14965 |
-- At this point the rep item chains contain the following items |
| 14966 |
|
| 14967 |
-- From_Typ -----------> Item_2 ---> Item_3 |
| 14968 |
-- ^ |
| 14969 |
-- Typ --------> Item_4 --+ |
| 14970 |
|
| 14971 |
-- The full views of both types may introduce extra invariants |
| 14972 |
|
| 14973 |
-- type From_Typ is tagged null record |
| 14974 |
-- with Type_Invariant => Item_1; |
| 14975 |
|
| 14976 |
-- type Typ is new From_Typ with null record; |
| 14977 |
|
| 14978 |
-- The full view of Typ would have to inherit any new rep items added to |
| 14979 |
-- the full view of From_Typ. |
| 14980 |
|
| 14981 |
-- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3 |
| 14982 |
-- ^ |
| 14983 |
-- Typ --------> Item_4 --+ |
| 14984 |
|
| 14985 |
-- To achieve this form of inheritance, the destination type must first |
| 14986 |
-- sever the link between its own rep chain and that of the source type, |
| 14987 |
-- then inheritance 3.1 takes place. |
| 14988 |
|
| 14989 |
-- Case 1: The source type lacks a rep item chain |
| 14990 |
|
| 14991 |
if No (First_Rep_Item (From_Typ)) then |
| 14992 |
return; |
| 14993 |
|
| 14994 |
-- Case 2: The destination type lacks a rep item chain |
| 14995 |
|
| 14996 |
elsif No (First_Rep_Item (Typ)) then |
| 14997 |
Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ)); |
| 14998 |
|
| 14999 |
-- Case 3: Both the source and destination types have at least one rep |
| 15000 |
-- item. Traverse the rep item chain of the destination type to find the |
| 15001 |
-- last rep item. |
| 15002 |
|
| 15003 |
else |
| 15004 |
Item := Empty; |
| 15005 |
Next_Item := First_Rep_Item (Typ); |
| 15006 |
while Present (Next_Item) loop |
| 15007 |
|
| 15008 |
-- Detect a link between the destination type's rep chain and that |
| 15009 |
-- of the source type. There are two possibilities: |
| 15010 |
|
| 15011 |
-- Variant 1 |
| 15012 |
-- Next_Item |
| 15013 |
-- V |
| 15014 |
-- From_Typ ---> Item_1 ---> |
| 15015 |
-- ^ |
| 15016 |
-- Typ -----------+ |
| 15017 |
-- |
| 15018 |
-- Item is Empty |
| 15019 |
|
| 15020 |
-- Variant 2 |
| 15021 |
-- Next_Item |
| 15022 |
-- V |
| 15023 |
-- From_Typ ---> Item_1 ---> Item_2 ---> |
| 15024 |
-- ^ |
| 15025 |
-- Typ --------> Item_3 ------+ |
| 15026 |
-- ^ |
| 15027 |
-- Item |
| 15028 |
|
| 15029 |
if Present_In_Rep_Item (From_Typ, Next_Item) then |
| 15030 |
exit; |
| 15031 |
end if; |
| 15032 |
|
| 15033 |
Item := Next_Item; |
| 15034 |
Next_Item := Next_Rep_Item (Next_Item); |
| 15035 |
end loop; |
| 15036 |
|
| 15037 |
-- Inherit the source type's rep item chain |
| 15038 |
|
| 15039 |
if Present (Item) then |
| 15040 |
Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ)); |
| 15041 |
else |
| 15042 |
Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ)); |
| 15043 |
end if; |
| 15044 |
end if; |
| 15045 |
end Inherit_Rep_Item_Chain; |
| 15046 |
|
| 15047 |
------------------------------------ |
| 15048 |
-- Inherits_From_Tagged_Full_View -- |
| 15049 |
------------------------------------ |
| 15050 |
|
| 15051 |
function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is |
| 15052 |
begin |
| 15053 |
return Is_Private_Type (Typ) |
| 15054 |
and then Present (Full_View (Typ)) |
| 15055 |
and then Is_Private_Type (Full_View (Typ)) |
| 15056 |
and then not Is_Tagged_Type (Full_View (Typ)) |
| 15057 |
and then Present (Underlying_Type (Full_View (Typ))) |
| 15058 |
and then Is_Tagged_Type (Underlying_Type (Full_View (Typ))); |
| 15059 |
end Inherits_From_Tagged_Full_View; |
| 15060 |
|
| 15061 |
--------------------------------- |
| 15062 |
-- Insert_Explicit_Dereference -- |
| 15063 |
--------------------------------- |
| 15064 |
|
| 15065 |
procedure Insert_Explicit_Dereference (N : Node_Id) is |
| 15066 |
New_Prefix : constant Node_Id := Relocate_Node (N); |
| 15067 |
Ent : Entity_Id := Empty; |
| 15068 |
Pref : Node_Id := Empty; |
| 15069 |
I : Interp_Index; |
| 15070 |
It : Interp; |
| 15071 |
T : Entity_Id; |
| 15072 |
|
| 15073 |
begin |
| 15074 |
Save_Interps (N, New_Prefix); |
| 15075 |
|
| 15076 |
Rewrite (N, |
| 15077 |
Make_Explicit_Dereference (Sloc (Parent (N)), |
| 15078 |
Prefix => New_Prefix)); |
| 15079 |
|
| 15080 |
Set_Etype (N, Designated_Type (Etype (New_Prefix))); |
| 15081 |
|
| 15082 |
if Is_Overloaded (New_Prefix) then |
| 15083 |
|
| 15084 |
-- The dereference is also overloaded, and its interpretations are |
| 15085 |
-- the designated types of the interpretations of the original node. |
| 15086 |
|
| 15087 |
Set_Etype (N, Any_Type); |
| 15088 |
|
| 15089 |
Get_First_Interp (New_Prefix, I, It); |
| 15090 |
while Present (It.Nam) loop |
| 15091 |
T := It.Typ; |
| 15092 |
|
| 15093 |
if Is_Access_Type (T) then |
| 15094 |
Add_One_Interp (N, Designated_Type (T), Designated_Type (T)); |
| 15095 |
end if; |
| 15096 |
|
| 15097 |
Get_Next_Interp (I, It); |
| 15098 |
end loop; |
| 15099 |
|
| 15100 |
else |
| 15101 |
-- Prefix is unambiguous: mark the original prefix (which might |
| 15102 |
-- Come_From_Source) as a reference, since the new (relocated) one |
| 15103 |
-- won't be taken into account. |
| 15104 |
|
| 15105 |
if Is_Entity_Name (New_Prefix) then |
| 15106 |
Ent := Entity (New_Prefix); |
| 15107 |
Pref := New_Prefix; |
| 15108 |
|
| 15109 |
-- For a retrieval of a subcomponent of some composite object, |
| 15110 |
-- retrieve the ultimate entity if there is one. |
| 15111 |
|
| 15112 |
elsif Nkind (New_Prefix) in N_Selected_Component | N_Indexed_Component |
| 15113 |
then |
| 15114 |
Pref := Prefix (New_Prefix); |
| 15115 |
while Present (Pref) |
| 15116 |
and then Nkind (Pref) in |
| 15117 |
N_Selected_Component | N_Indexed_Component |
| 15118 |
loop |
| 15119 |
Pref := Prefix (Pref); |
| 15120 |
end loop; |
| 15121 |
|
| 15122 |
if Present (Pref) and then Is_Entity_Name (Pref) then |
| 15123 |
Ent := Entity (Pref); |
| 15124 |
end if; |
| 15125 |
end if; |
| 15126 |
|
| 15127 |
-- Place the reference on the entity node |
| 15128 |
|
| 15129 |
if Present (Ent) then |
| 15130 |
Generate_Reference (Ent, Pref); |
| 15131 |
end if; |
| 15132 |
end if; |
| 15133 |
end Insert_Explicit_Dereference; |
| 15134 |
|
| 15135 |
------------------------------------------ |
| 15136 |
-- Inspect_Deferred_Constant_Completion -- |
| 15137 |
------------------------------------------ |
| 15138 |
|
| 15139 |
procedure Inspect_Deferred_Constant_Completion (Decl : Node_Id) is |
| 15140 |
begin |
| 15141 |
-- Deferred constant signature |
| 15142 |
|
| 15143 |
if Nkind (Decl) = N_Object_Declaration |
| 15144 |
and then Constant_Present (Decl) |
| 15145 |
and then No (Expression (Decl)) |
| 15146 |
|
| 15147 |
-- No need to check internally generated constants |
| 15148 |
|
| 15149 |
and then Comes_From_Source (Decl) |
| 15150 |
|
| 15151 |
-- The constant is not completed. A full object declaration or a |
| 15152 |
-- pragma Import complete a deferred constant. |
| 15153 |
|
| 15154 |
and then not Has_Completion (Defining_Identifier (Decl)) |
| 15155 |
then |
| 15156 |
Error_Msg_N |
| 15157 |
("constant declaration requires initialization expression", |
| 15158 |
Defining_Identifier (Decl)); |
| 15159 |
end if; |
| 15160 |
end Inspect_Deferred_Constant_Completion; |
| 15161 |
|
| 15162 |
procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is |
| 15163 |
Decl : Node_Id; |
| 15164 |
|
| 15165 |
begin |
| 15166 |
Decl := First (Decls); |
| 15167 |
while Present (Decl) loop |
| 15168 |
Inspect_Deferred_Constant_Completion (Decl); |
| 15169 |
Next (Decl); |
| 15170 |
end loop; |
| 15171 |
end Inspect_Deferred_Constant_Completion; |
| 15172 |
|
| 15173 |
------------------------------- |
| 15174 |
-- Install_Elaboration_Model -- |
| 15175 |
------------------------------- |
| 15176 |
|
| 15177 |
procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is |
| 15178 |
function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id; |
| 15179 |
-- Try to find pragma Elaboration_Checks in arbitrary list L. Return |
| 15180 |
-- Empty if there is no such pragma. |
| 15181 |
|
| 15182 |
------------------------------------ |
| 15183 |
-- Find_Elaboration_Checks_Pragma -- |
| 15184 |
------------------------------------ |
| 15185 |
|
| 15186 |
function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is |
| 15187 |
Item : Node_Id; |
| 15188 |
|
| 15189 |
begin |
| 15190 |
Item := First (L); |
| 15191 |
while Present (Item) loop |
| 15192 |
if Nkind (Item) = N_Pragma |
| 15193 |
and then Pragma_Name (Item) = Name_Elaboration_Checks |
| 15194 |
then |
| 15195 |
return Item; |
| 15196 |
end if; |
| 15197 |
|
| 15198 |
Next (Item); |
| 15199 |
end loop; |
| 15200 |
|
| 15201 |
return Empty; |
| 15202 |
end Find_Elaboration_Checks_Pragma; |
| 15203 |
|
| 15204 |
-- Local variables |
| 15205 |
|
| 15206 |
Args : List_Id; |
| 15207 |
Model : Node_Id; |
| 15208 |
Prag : Node_Id; |
| 15209 |
Unit : Node_Id; |
| 15210 |
|
| 15211 |
-- Start of processing for Install_Elaboration_Model |
| 15212 |
|
| 15213 |
begin |
| 15214 |
-- Nothing to do when the unit does not exist |
| 15215 |
|
| 15216 |
if No (Unit_Id) then |
| 15217 |
return; |
| 15218 |
end if; |
| 15219 |
|
| 15220 |
Unit := Parent (Unit_Declaration_Node (Unit_Id)); |
| 15221 |
|
| 15222 |
-- Nothing to do when the unit is not a library unit |
| 15223 |
|
| 15224 |
if Nkind (Unit) /= N_Compilation_Unit then |
| 15225 |
return; |
| 15226 |
end if; |
| 15227 |
|
| 15228 |
Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit)); |
| 15229 |
|
| 15230 |
-- The compilation unit is subject to pragma Elaboration_Checks. Set the |
| 15231 |
-- elaboration model as specified by the pragma. |
| 15232 |
|
| 15233 |
if Present (Prag) then |
| 15234 |
Args := Pragma_Argument_Associations (Prag); |
| 15235 |
|
| 15236 |
-- Guard against an illegal pragma. The sole argument must be an |
| 15237 |
-- identifier which specifies either Dynamic or Static model. |
| 15238 |
|
| 15239 |
if Present (Args) then |
| 15240 |
Model := Get_Pragma_Arg (First (Args)); |
| 15241 |
|
| 15242 |
if Nkind (Model) = N_Identifier then |
| 15243 |
Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic; |
| 15244 |
end if; |
| 15245 |
end if; |
| 15246 |
end if; |
| 15247 |
end Install_Elaboration_Model; |
| 15248 |
|
| 15249 |
----------------------------- |
| 15250 |
-- Install_Generic_Formals -- |
| 15251 |
----------------------------- |
| 15252 |
|
| 15253 |
procedure Install_Generic_Formals (Subp_Id : Entity_Id) is |
| 15254 |
E : Entity_Id; |
| 15255 |
|
| 15256 |
begin |
| 15257 |
pragma Assert (Is_Generic_Subprogram (Subp_Id)); |
| 15258 |
|
| 15259 |
E := First_Entity (Subp_Id); |
| 15260 |
while Present (E) loop |
| 15261 |
Install_Entity (E); |
| 15262 |
Next_Entity (E); |
| 15263 |
end loop; |
| 15264 |
end Install_Generic_Formals; |
| 15265 |
|
| 15266 |
------------------------ |
| 15267 |
-- Install_SPARK_Mode -- |
| 15268 |
------------------------ |
| 15269 |
|
| 15270 |
procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is |
| 15271 |
begin |
| 15272 |
SPARK_Mode := Mode; |
| 15273 |
SPARK_Mode_Pragma := Prag; |
| 15274 |
end Install_SPARK_Mode; |
| 15275 |
|
| 15276 |
-------------------------- |
| 15277 |
-- Invalid_Scalar_Value -- |
| 15278 |
-------------------------- |
| 15279 |
|
| 15280 |
function Invalid_Scalar_Value |
| 15281 |
(Loc : Source_Ptr; |
| 15282 |
Scal_Typ : Scalar_Id) return Node_Id |
| 15283 |
is |
| 15284 |
function Invalid_Binder_Value return Node_Id; |
| 15285 |
-- Return a reference to the corresponding invalid value for type |
| 15286 |
-- Scal_Typ as defined in unit System.Scalar_Values. |
| 15287 |
|
| 15288 |
function Invalid_Float_Value return Node_Id; |
| 15289 |
-- Return the invalid value of float type Scal_Typ |
| 15290 |
|
| 15291 |
function Invalid_Integer_Value return Node_Id; |
| 15292 |
-- Return the invalid value of integer type Scal_Typ |
| 15293 |
|
| 15294 |
procedure Set_Invalid_Binder_Values; |
| 15295 |
-- Set the contents of collection Invalid_Binder_Values |
| 15296 |
|
| 15297 |
-------------------------- |
| 15298 |
-- Invalid_Binder_Value -- |
| 15299 |
-------------------------- |
| 15300 |
|
| 15301 |
function Invalid_Binder_Value return Node_Id is |
| 15302 |
Val_Id : Entity_Id; |
| 15303 |
|
| 15304 |
begin |
| 15305 |
-- Initialize the collection of invalid binder values the first time |
| 15306 |
-- around. |
| 15307 |
|
| 15308 |
Set_Invalid_Binder_Values; |
| 15309 |
|
| 15310 |
-- Obtain the corresponding variable from System.Scalar_Values which |
| 15311 |
-- holds the invalid value for this type. |
| 15312 |
|
| 15313 |
Val_Id := Invalid_Binder_Values (Scal_Typ); |
| 15314 |
pragma Assert (Present (Val_Id)); |
| 15315 |
|
| 15316 |
return New_Occurrence_Of (Val_Id, Loc); |
| 15317 |
end Invalid_Binder_Value; |
| 15318 |
|
| 15319 |
------------------------- |
| 15320 |
-- Invalid_Float_Value -- |
| 15321 |
------------------------- |
| 15322 |
|
| 15323 |
function Invalid_Float_Value return Node_Id is |
| 15324 |
Value : constant Ureal := Invalid_Floats (Scal_Typ); |
| 15325 |
|
| 15326 |
begin |
| 15327 |
-- Pragma Invalid_Scalars did not specify an invalid value for this |
| 15328 |
-- type. Fall back to the value provided by the binder. |
| 15329 |
|
| 15330 |
if Value = No_Ureal then |
| 15331 |
return Invalid_Binder_Value; |
| 15332 |
else |
| 15333 |
return Make_Real_Literal (Loc, Realval => Value); |
| 15334 |
end if; |
| 15335 |
end Invalid_Float_Value; |
| 15336 |
|
| 15337 |
--------------------------- |
| 15338 |
-- Invalid_Integer_Value -- |
| 15339 |
--------------------------- |
| 15340 |
|
| 15341 |
function Invalid_Integer_Value return Node_Id is |
| 15342 |
Value : constant Uint := Invalid_Integers (Scal_Typ); |
| 15343 |
|
| 15344 |
begin |
| 15345 |
-- Pragma Invalid_Scalars did not specify an invalid value for this |
| 15346 |
-- type. Fall back to the value provided by the binder. |
| 15347 |
|
| 15348 |
if No (Value) then |
| 15349 |
return Invalid_Binder_Value; |
| 15350 |
else |
| 15351 |
return Make_Integer_Literal (Loc, Intval => Value); |
| 15352 |
end if; |
| 15353 |
end Invalid_Integer_Value; |
| 15354 |
|
| 15355 |
------------------------------- |
| 15356 |
-- Set_Invalid_Binder_Values -- |
| 15357 |
------------------------------- |
| 15358 |
|
| 15359 |
procedure Set_Invalid_Binder_Values is |
| 15360 |
begin |
| 15361 |
if not Invalid_Binder_Values_Set then |
| 15362 |
Invalid_Binder_Values_Set := True; |
| 15363 |
|
| 15364 |
-- Initialize the contents of the collection once since RTE calls |
| 15365 |
-- are not cheap. |
| 15366 |
|
| 15367 |
Invalid_Binder_Values := |
| 15368 |
(Name_Short_Float => RTE (RE_IS_Isf), |
| 15369 |
Name_Float => RTE (RE_IS_Ifl), |
| 15370 |
Name_Long_Float => RTE (RE_IS_Ilf), |
| 15371 |
Name_Long_Long_Float => RTE (RE_IS_Ill), |
| 15372 |
Name_Signed_8 => RTE (RE_IS_Is1), |
| 15373 |
Name_Signed_16 => RTE (RE_IS_Is2), |
| 15374 |
Name_Signed_32 => RTE (RE_IS_Is4), |
| 15375 |
Name_Signed_64 => RTE (RE_IS_Is8), |
| 15376 |
Name_Signed_128 => Empty, |
| 15377 |
Name_Unsigned_8 => RTE (RE_IS_Iu1), |
| 15378 |
Name_Unsigned_16 => RTE (RE_IS_Iu2), |
| 15379 |
Name_Unsigned_32 => RTE (RE_IS_Iu4), |
| 15380 |
Name_Unsigned_64 => RTE (RE_IS_Iu8), |
| 15381 |
Name_Unsigned_128 => Empty); |
| 15382 |
|
| 15383 |
if System_Max_Integer_Size < 128 then |
| 15384 |
Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is8); |
| 15385 |
Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu8); |
| 15386 |
else |
| 15387 |
Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is16); |
| 15388 |
Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu16); |
| 15389 |
end if; |
| 15390 |
end if; |
| 15391 |
end Set_Invalid_Binder_Values; |
| 15392 |
|
| 15393 |
-- Start of processing for Invalid_Scalar_Value |
| 15394 |
|
| 15395 |
begin |
| 15396 |
if Scal_Typ in Float_Scalar_Id then |
| 15397 |
return Invalid_Float_Value; |
| 15398 |
|
| 15399 |
else pragma Assert (Scal_Typ in Integer_Scalar_Id); |
| 15400 |
return Invalid_Integer_Value; |
| 15401 |
end if; |
| 15402 |
end Invalid_Scalar_Value; |
| 15403 |
|
| 15404 |
------------------------ |
| 15405 |
-- Is_Access_Variable -- |
| 15406 |
------------------------ |
| 15407 |
|
| 15408 |
function Is_Access_Variable (E : Entity_Id) return Boolean is |
| 15409 |
begin |
| 15410 |
return Is_Access_Type (E) |
| 15411 |
and then not Is_Access_Constant (E) |
| 15412 |
and then Ekind (Directly_Designated_Type (E)) /= E_Subprogram_Type; |
| 15413 |
end Is_Access_Variable; |
| 15414 |
|
| 15415 |
----------------------------- |
| 15416 |
-- Is_Actual_Out_Parameter -- |
| 15417 |
----------------------------- |
| 15418 |
|
| 15419 |
function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is |
| 15420 |
Formal : Entity_Id; |
| 15421 |
Call : Node_Id; |
| 15422 |
begin |
| 15423 |
Find_Actual (N, Formal, Call); |
| 15424 |
return Present (Formal) and then Ekind (Formal) = E_Out_Parameter; |
| 15425 |
end Is_Actual_Out_Parameter; |
| 15426 |
|
| 15427 |
-------------------------------- |
| 15428 |
-- Is_Actual_In_Out_Parameter -- |
| 15429 |
-------------------------------- |
| 15430 |
|
| 15431 |
function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean is |
| 15432 |
Formal : Entity_Id; |
| 15433 |
Call : Node_Id; |
| 15434 |
begin |
| 15435 |
Find_Actual (N, Formal, Call); |
| 15436 |
return Present (Formal) and then Ekind (Formal) = E_In_Out_Parameter; |
| 15437 |
end Is_Actual_In_Out_Parameter; |
| 15438 |
|
| 15439 |
--------------------------------------- |
| 15440 |
-- Is_Actual_Out_Or_In_Out_Parameter -- |
| 15441 |
--------------------------------------- |
| 15442 |
|
| 15443 |
function Is_Actual_Out_Or_In_Out_Parameter (N : Node_Id) return Boolean is |
| 15444 |
Formal : Entity_Id; |
| 15445 |
Call : Node_Id; |
| 15446 |
begin |
| 15447 |
Find_Actual (N, Formal, Call); |
| 15448 |
return Present (Formal) |
| 15449 |
and then Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter; |
| 15450 |
end Is_Actual_Out_Or_In_Out_Parameter; |
| 15451 |
|
| 15452 |
------------------------- |
| 15453 |
-- Is_Actual_Parameter -- |
| 15454 |
------------------------- |
| 15455 |
|
| 15456 |
function Is_Actual_Parameter (N : Node_Id) return Boolean is |
| 15457 |
PK : constant Node_Kind := Nkind (Parent (N)); |
| 15458 |
|
| 15459 |
begin |
| 15460 |
case PK is |
| 15461 |
when N_Parameter_Association => |
| 15462 |
return N = Explicit_Actual_Parameter (Parent (N)); |
| 15463 |
|
| 15464 |
when N_Entry_Call_Statement |
| 15465 |
| N_Subprogram_Call |
| 15466 |
=> |
| 15467 |
return Is_List_Member (N) |
| 15468 |
and then |
| 15469 |
List_Containing (N) = Parameter_Associations (Parent (N)); |
| 15470 |
|
| 15471 |
when others => |
| 15472 |
return False; |
| 15473 |
end case; |
| 15474 |
end Is_Actual_Parameter; |
| 15475 |
|
| 15476 |
--------------------- |
| 15477 |
-- Is_Aliased_View -- |
| 15478 |
--------------------- |
| 15479 |
|
| 15480 |
function Is_Aliased_View |
| 15481 |
(Obj : Node_Id; For_Extended : Boolean := False) return Boolean |
| 15482 |
is |
| 15483 |
E : Entity_Id; |
| 15484 |
|
| 15485 |
-- Ensure that For_Extended parameter is propagated in recursive |
| 15486 |
-- calls by hiding the version that has the wrong default. |
| 15487 |
|
| 15488 |
function Is_Aliased_View |
| 15489 |
(Obj : Node_Id; For_SF : Boolean := For_Extended) return Boolean |
| 15490 |
renames Sem_Util.Is_Aliased_View; |
| 15491 |
|
| 15492 |
begin |
| 15493 |
if Is_Entity_Name (Obj) then |
| 15494 |
E := Entity (Obj); |
| 15495 |
|
| 15496 |
return |
| 15497 |
(Is_Object (E) |
| 15498 |
and then |
| 15499 |
(Is_Aliased (E) |
| 15500 |
or else (Present (Renamed_Object (E)) |
| 15501 |
and then Is_Aliased_View (Renamed_Object (E))))) |
| 15502 |
|
| 15503 |
or else ((Is_Formal (E) or else Is_Formal_Object (E)) |
| 15504 |
and then Is_Tagged_Type (Etype (E))) |
| 15505 |
|
| 15506 |
or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E)) |
| 15507 |
|
| 15508 |
-- Current instance of type, either directly or as rewritten |
| 15509 |
-- reference to the current object. |
| 15510 |
|
| 15511 |
or else (Is_Entity_Name (Original_Node (Obj)) |
| 15512 |
and then Present (Entity (Original_Node (Obj))) |
| 15513 |
and then Is_Type (Entity (Original_Node (Obj)))) |
| 15514 |
|
| 15515 |
or else (Is_Type (E) and then E = Current_Scope) |
| 15516 |
|
| 15517 |
or else (Is_Incomplete_Or_Private_Type (E) |
| 15518 |
and then Full_View (E) = Current_Scope) |
| 15519 |
|
| 15520 |
-- Ada 2012 AI05-0053: the return object of an extended return |
| 15521 |
-- statement is aliased if its type is immutably limited. |
| 15522 |
|
| 15523 |
or else (Is_Return_Object (E) |
| 15524 |
and then Is_Inherently_Limited_Type (Etype (E))) |
| 15525 |
|
| 15526 |
-- The current instance of a limited type is aliased, so |
| 15527 |
-- we want to allow uses of T'Access in the init proc for |
| 15528 |
-- a limited type T. However, we don't want to mark the formal |
| 15529 |
-- parameter as being aliased since that could impact callers. |
| 15530 |
|
| 15531 |
or else (Is_Formal (E) |
| 15532 |
and then Chars (E) = Name_uInit |
| 15533 |
and then Is_Inherently_Limited_Type (Etype (E))); |
| 15534 |
|
| 15535 |
elsif Nkind (Obj) = N_Selected_Component then |
| 15536 |
return Is_Aliased (Entity (Selector_Name (Obj))); |
| 15537 |
|
| 15538 |
elsif Nkind (Obj) = N_Indexed_Component then |
| 15539 |
return Has_Aliased_Components (Etype (Prefix (Obj))) |
| 15540 |
or else |
| 15541 |
(Is_Access_Type (Etype (Prefix (Obj))) |
| 15542 |
and then Has_Aliased_Components |
| 15543 |
(Designated_Type (Etype (Prefix (Obj))))); |
| 15544 |
|
| 15545 |
-- Handle a 'Super view conversion |
| 15546 |
|
| 15547 |
elsif Nkind (Obj) = N_Attribute_Reference |
| 15548 |
and then Attribute_Name (Obj) = Name_Super |
| 15549 |
then |
| 15550 |
return Is_Aliased_View (Prefix (Obj)); |
| 15551 |
|
| 15552 |
elsif Nkind (Obj) in N_Unchecked_Type_Conversion | N_Type_Conversion then |
| 15553 |
return Is_Tagged_Type (Etype (Obj)) |
| 15554 |
and then Is_Aliased_View (Expression (Obj)); |
| 15555 |
|
| 15556 |
-- Ada 2022 AI12-0228 |
| 15557 |
|
| 15558 |
elsif Nkind (Obj) = N_Qualified_Expression |
| 15559 |
and then Ada_Version >= Ada_2012 |
| 15560 |
then |
| 15561 |
return Is_Aliased_View (Expression (Obj)); |
| 15562 |
|
| 15563 |
elsif Is_Expanded_Class_Wide_Interface_Object_Decl (Parent (Obj)) then |
| 15564 |
return Is_Aliased |
| 15565 |
(Defining_Identifier (Original_Node (Parent (Obj)))); |
| 15566 |
|
| 15567 |
-- The dereference of an access-to-object value denotes an aliased view, |
| 15568 |
-- but this routine uses the rules of the language so we need to exclude |
| 15569 |
-- rewritten constructs that introduce artificial dereferences. |
| 15570 |
|
| 15571 |
elsif Nkind (Obj) = N_Explicit_Dereference then |
| 15572 |
-- If For_Extended is False then a dereference of an extended access |
| 15573 |
-- value is, by definition, not aliased. |
| 15574 |
-- This is to prevent covert illegal type conversion via either |
| 15575 |
-- Not_Extended_Type'(Extended_Ptr.all'Access) |
| 15576 |
-- or by passing Extended_Ptr.all as an actual parameter |
| 15577 |
-- corresponding to an explicitly aliased formal parameter |
| 15578 |
-- (which would allow the callee to evaluate Aliased_Param'Access). |
| 15579 |
|
| 15580 |
if Is_Extended_Access_Type (Etype (Prefix (Obj))) |
| 15581 |
and then not For_Extended |
| 15582 |
then |
| 15583 |
return False; |
| 15584 |
end if; |
| 15585 |
|
| 15586 |
return not Is_Captured_Function_Call (Obj) |
| 15587 |
and then not |
| 15588 |
(Nkind (Parent (Obj)) = N_Object_Renaming_Declaration |
| 15589 |
and then Is_Return_Object (Defining_Entity (Parent (Obj)))); |
| 15590 |
|
| 15591 |
elsif Nkind (Obj) = N_Slice then |
| 15592 |
-- A slice of a bit-packed array is not considered aliased even |
| 15593 |
-- for an extended access type because even extended access types |
| 15594 |
-- don't support bit pointers. |
| 15595 |
|
| 15596 |
return For_Extended |
| 15597 |
and then Is_Aliased_View (Prefix (Obj)) |
| 15598 |
and then not Is_Bit_Packed_Array (Etype (Obj)); |
| 15599 |
|
| 15600 |
else |
| 15601 |
return False; |
| 15602 |
end if; |
| 15603 |
end Is_Aliased_View; |
| 15604 |
|
| 15605 |
------------------------- |
| 15606 |
-- Is_Ancestor_Package -- |
| 15607 |
------------------------- |
| 15608 |
|
| 15609 |
function Is_Ancestor_Package |
| 15610 |
(E1 : Entity_Id; |
| 15611 |
E2 : Entity_Id) return Boolean |
| 15612 |
is |
| 15613 |
Par : Entity_Id := E2; |
| 15614 |
begin |
| 15615 |
while Present (Par) and then Par /= Standard_Standard loop |
| 15616 |
if Par = E1 then |
| 15617 |
return True; |
| 15618 |
end if; |
| 15619 |
|
| 15620 |
Par := Scope (Par); |
| 15621 |
end loop; |
| 15622 |
|
| 15623 |
return False; |
| 15624 |
end Is_Ancestor_Package; |
| 15625 |
|
| 15626 |
---------------------- |
| 15627 |
-- Is_Atomic_Object -- |
| 15628 |
---------------------- |
| 15629 |
|
| 15630 |
function Is_Atomic_Object (N : Node_Id) return Boolean is |
| 15631 |
function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean; |
| 15632 |
-- Determine whether prefix P has atomic components. This requires the |
| 15633 |
-- presence of an Atomic_Components aspect/pragma. |
| 15634 |
|
| 15635 |
--------------------------------- |
| 15636 |
-- Prefix_Has_Atomic_Components -- |
| 15637 |
--------------------------------- |
| 15638 |
|
| 15639 |
function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is |
| 15640 |
Typ : constant Entity_Id := Etype (P); |
| 15641 |
|
| 15642 |
begin |
| 15643 |
if Is_Access_Type (Typ) then |
| 15644 |
return Has_Atomic_Components (Designated_Type (Typ)); |
| 15645 |
|
| 15646 |
elsif Has_Atomic_Components (Typ) then |
| 15647 |
return True; |
| 15648 |
|
| 15649 |
elsif Is_Entity_Name (P) |
| 15650 |
and then Has_Atomic_Components (Entity (P)) |
| 15651 |
then |
| 15652 |
return True; |
| 15653 |
|
| 15654 |
else |
| 15655 |
return False; |
| 15656 |
end if; |
| 15657 |
end Prefix_Has_Atomic_Components; |
| 15658 |
|
| 15659 |
-- Start of processing for Is_Atomic_Object |
| 15660 |
|
| 15661 |
begin |
| 15662 |
if Is_Entity_Name (N) then |
| 15663 |
return Is_Atomic_Object_Entity (Entity (N)); |
| 15664 |
|
| 15665 |
elsif Is_Atomic (Etype (N)) then |
| 15666 |
return True; |
| 15667 |
|
| 15668 |
elsif Nkind (N) = N_Indexed_Component then |
| 15669 |
return Prefix_Has_Atomic_Components (Prefix (N)); |
| 15670 |
|
| 15671 |
elsif Nkind (N) = N_Selected_Component then |
| 15672 |
return Is_Atomic (Entity (Selector_Name (N))); |
| 15673 |
|
| 15674 |
else |
| 15675 |
return False; |
| 15676 |
end if; |
| 15677 |
end Is_Atomic_Object; |
| 15678 |
|
| 15679 |
----------------------------- |
| 15680 |
-- Is_Atomic_Object_Entity -- |
| 15681 |
----------------------------- |
| 15682 |
|
| 15683 |
function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is |
| 15684 |
begin |
| 15685 |
return |
| 15686 |
Is_Object (Id) |
| 15687 |
and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id))); |
| 15688 |
end Is_Atomic_Object_Entity; |
| 15689 |
|
| 15690 |
----------------------------- |
| 15691 |
-- Is_Attribute_Loop_Entry -- |
| 15692 |
----------------------------- |
| 15693 |
|
| 15694 |
function Is_Attribute_Loop_Entry (N : Node_Id) return Boolean is |
| 15695 |
begin |
| 15696 |
return Nkind (N) = N_Attribute_Reference |
| 15697 |
and then Attribute_Name (N) = Name_Loop_Entry; |
| 15698 |
end Is_Attribute_Loop_Entry; |
| 15699 |
|
| 15700 |
---------------------- |
| 15701 |
-- Is_Attribute_Old -- |
| 15702 |
---------------------- |
| 15703 |
|
| 15704 |
function Is_Attribute_Old (N : Node_Id) return Boolean is |
| 15705 |
begin |
| 15706 |
return Nkind (N) = N_Attribute_Reference |
| 15707 |
and then Attribute_Name (N) = Name_Old; |
| 15708 |
end Is_Attribute_Old; |
| 15709 |
|
| 15710 |
------------------------- |
| 15711 |
-- Is_Attribute_Result -- |
| 15712 |
------------------------- |
| 15713 |
|
| 15714 |
function Is_Attribute_Result (N : Node_Id) return Boolean is |
| 15715 |
begin |
| 15716 |
return Nkind (N) = N_Attribute_Reference |
| 15717 |
and then Attribute_Name (N) = Name_Result; |
| 15718 |
end Is_Attribute_Result; |
| 15719 |
|
| 15720 |
------------------------- |
| 15721 |
-- Is_Attribute_Update -- |
| 15722 |
------------------------- |
| 15723 |
|
| 15724 |
function Is_Attribute_Update (N : Node_Id) return Boolean is |
| 15725 |
begin |
| 15726 |
return Nkind (N) = N_Attribute_Reference |
| 15727 |
and then Attribute_Name (N) = Name_Update; |
| 15728 |
end Is_Attribute_Update; |
| 15729 |
|
| 15730 |
------------------------------------ |
| 15731 |
-- Is_Body_Or_Package_Declaration -- |
| 15732 |
------------------------------------ |
| 15733 |
|
| 15734 |
function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is |
| 15735 |
begin |
| 15736 |
return Is_Body (N) or else Nkind (N) = N_Package_Declaration; |
| 15737 |
end Is_Body_Or_Package_Declaration; |
| 15738 |
|
| 15739 |
----------------------- |
| 15740 |
-- Is_Bounded_String -- |
| 15741 |
----------------------- |
| 15742 |
|
| 15743 |
function Is_Bounded_String (T : Entity_Id) return Boolean is |
| 15744 |
Under : constant Entity_Id := Underlying_Type (Root_Type (T)); |
| 15745 |
|
| 15746 |
begin |
| 15747 |
-- Check whether T is ultimately derived from Ada.Strings.Superbounded. |
| 15748 |
-- Super_String, or one of the [Wide_]Wide_ versions. This will |
| 15749 |
-- be True for all the Bounded_String types in instances of the |
| 15750 |
-- Generic_Bounded_Length generics, and for types derived from those. |
| 15751 |
|
| 15752 |
return Present (Under) |
| 15753 |
and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else |
| 15754 |
Is_RTE (Root_Type (Under), RO_WI_Super_String) or else |
| 15755 |
Is_RTE (Root_Type (Under), RO_WW_Super_String)); |
| 15756 |
end Is_Bounded_String; |
| 15757 |
|
| 15758 |
------------------------------- |
| 15759 |
-- Is_By_Protected_Procedure -- |
| 15760 |
------------------------------- |
| 15761 |
|
| 15762 |
function Is_By_Protected_Procedure (Id : Entity_Id) return Boolean is |
| 15763 |
begin |
| 15764 |
return Ekind (Id) = E_Procedure |
| 15765 |
and then Present (Get_Rep_Pragma (Id, Name_Implemented)) |
| 15766 |
and then Implementation_Kind (Id) = Name_By_Protected_Procedure; |
| 15767 |
end Is_By_Protected_Procedure; |
| 15768 |
|
| 15769 |
--------------------- |
| 15770 |
-- Is_CCT_Instance -- |
| 15771 |
--------------------- |
| 15772 |
|
| 15773 |
function Is_CCT_Instance |
| 15774 |
(Ref_Id : Entity_Id; |
| 15775 |
Context_Id : Entity_Id) return Boolean |
| 15776 |
is |
| 15777 |
begin |
| 15778 |
pragma Assert (Ekind (Ref_Id) in E_Protected_Type | E_Task_Type); |
| 15779 |
|
| 15780 |
if Is_Single_Task_Object (Context_Id) then |
| 15781 |
return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id); |
| 15782 |
|
| 15783 |
else |
| 15784 |
pragma Assert |
| 15785 |
(Ekind (Context_Id) in |
| 15786 |
E_Entry | E_Entry_Family | E_Function | E_Package | |
| 15787 |
E_Procedure | E_Protected_Type | E_Task_Type |
| 15788 |
or else Is_Record_Type (Context_Id)); |
| 15789 |
return Scope_Within_Or_Same (Context_Id, Ref_Id); |
| 15790 |
end if; |
| 15791 |
end Is_CCT_Instance; |
| 15792 |
|
| 15793 |
------------------------- |
| 15794 |
-- Is_Child_Or_Sibling -- |
| 15795 |
------------------------- |
| 15796 |
|
| 15797 |
function Is_Child_Or_Sibling |
| 15798 |
(Pack_1 : Entity_Id; |
| 15799 |
Pack_2 : Entity_Id) return Boolean |
| 15800 |
is |
| 15801 |
function Distance_From_Standard (Pack : Entity_Id) return Nat; |
| 15802 |
-- Given an arbitrary package, return the number of "climbs" necessary |
| 15803 |
-- to reach scope Standard_Standard. |
| 15804 |
|
| 15805 |
procedure Equalize_Depths |
| 15806 |
(Pack : in out Entity_Id; |
| 15807 |
Depth : in out Nat; |
| 15808 |
Depth_To_Reach : Nat); |
| 15809 |
-- Given an arbitrary package, its depth and a target depth to reach, |
| 15810 |
-- climb the scope chain until the said depth is reached. The pointer |
| 15811 |
-- to the package and its depth a modified during the climb. |
| 15812 |
|
| 15813 |
---------------------------- |
| 15814 |
-- Distance_From_Standard -- |
| 15815 |
---------------------------- |
| 15816 |
|
| 15817 |
function Distance_From_Standard (Pack : Entity_Id) return Nat is |
| 15818 |
Dist : Nat; |
| 15819 |
Scop : Entity_Id; |
| 15820 |
|
| 15821 |
begin |
| 15822 |
Dist := 0; |
| 15823 |
Scop := Pack; |
| 15824 |
while Present (Scop) and then Scop /= Standard_Standard loop |
| 15825 |
Dist := Dist + 1; |
| 15826 |
Scop := Scope (Scop); |
| 15827 |
end loop; |
| 15828 |
|
| 15829 |
return Dist; |
| 15830 |
end Distance_From_Standard; |
| 15831 |
|
| 15832 |
--------------------- |
| 15833 |
-- Equalize_Depths -- |
| 15834 |
--------------------- |
| 15835 |
|
| 15836 |
procedure Equalize_Depths |
| 15837 |
(Pack : in out Entity_Id; |
| 15838 |
Depth : in out Nat; |
| 15839 |
Depth_To_Reach : Nat) |
| 15840 |
is |
| 15841 |
begin |
| 15842 |
-- The package must be at a greater or equal depth |
| 15843 |
|
| 15844 |
if Depth < Depth_To_Reach then |
| 15845 |
raise Program_Error; |
| 15846 |
end if; |
| 15847 |
|
| 15848 |
-- Climb the scope chain until the desired depth is reached |
| 15849 |
|
| 15850 |
while Present (Pack) and then Depth /= Depth_To_Reach loop |
| 15851 |
Pack := Scope (Pack); |
| 15852 |
Depth := Depth - 1; |
| 15853 |
end loop; |
| 15854 |
end Equalize_Depths; |
| 15855 |
|
| 15856 |
-- Local variables |
| 15857 |
|
| 15858 |
P_1 : Entity_Id := Pack_1; |
| 15859 |
P_1_Child : Boolean := False; |
| 15860 |
P_1_Depth : Nat := Distance_From_Standard (P_1); |
| 15861 |
P_2 : Entity_Id := Pack_2; |
| 15862 |
P_2_Child : Boolean := False; |
| 15863 |
P_2_Depth : Nat := Distance_From_Standard (P_2); |
| 15864 |
|
| 15865 |
-- Start of processing for Is_Child_Or_Sibling |
| 15866 |
|
| 15867 |
begin |
| 15868 |
pragma Assert |
| 15869 |
(Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package); |
| 15870 |
|
| 15871 |
-- Both packages denote the same entity, therefore they cannot be |
| 15872 |
-- children or siblings. |
| 15873 |
|
| 15874 |
if P_1 = P_2 then |
| 15875 |
return False; |
| 15876 |
|
| 15877 |
-- One of the packages is at a deeper level than the other. Note that |
| 15878 |
-- both may still come from different hierarchies. |
| 15879 |
|
| 15880 |
-- (root) P_2 |
| 15881 |
-- / \ : |
| 15882 |
-- X P_2 or X |
| 15883 |
-- : : |
| 15884 |
-- P_1 P_1 |
| 15885 |
|
| 15886 |
elsif P_1_Depth > P_2_Depth then |
| 15887 |
Equalize_Depths |
| 15888 |
(Pack => P_1, |
| 15889 |
Depth => P_1_Depth, |
| 15890 |
Depth_To_Reach => P_2_Depth); |
| 15891 |
P_1_Child := True; |
| 15892 |
|
| 15893 |
-- (root) P_1 |
| 15894 |
-- / \ : |
| 15895 |
-- P_1 X or X |
| 15896 |
-- : : |
| 15897 |
-- P_2 P_2 |
| 15898 |
|
| 15899 |
elsif P_2_Depth > P_1_Depth then |
| 15900 |
Equalize_Depths |
| 15901 |
(Pack => P_2, |
| 15902 |
Depth => P_2_Depth, |
| 15903 |
Depth_To_Reach => P_1_Depth); |
| 15904 |
P_2_Child := True; |
| 15905 |
end if; |
| 15906 |
|
| 15907 |
-- At this stage the package pointers have been elevated to the same |
| 15908 |
-- depth. If the related entities are the same, then one package is a |
| 15909 |
-- potential child of the other: |
| 15910 |
|
| 15911 |
-- P_1 |
| 15912 |
-- : |
| 15913 |
-- X became P_1 P_2 or vice versa |
| 15914 |
-- : |
| 15915 |
-- P_2 |
| 15916 |
|
| 15917 |
if P_1 = P_2 then |
| 15918 |
if P_1_Child then |
| 15919 |
return Is_Child_Unit (Pack_1); |
| 15920 |
|
| 15921 |
else pragma Assert (P_2_Child); |
| 15922 |
return Is_Child_Unit (Pack_2); |
| 15923 |
end if; |
| 15924 |
|
| 15925 |
-- The packages may come from the same package chain or from entirely |
| 15926 |
-- different hierarchies. To determine this, climb the scope stack until |
| 15927 |
-- a common root is found. |
| 15928 |
|
| 15929 |
-- (root) (root 1) (root 2) |
| 15930 |
-- / \ | | |
| 15931 |
-- P_1 P_2 P_1 P_2 |
| 15932 |
|
| 15933 |
else |
| 15934 |
while Present (P_1) and then Present (P_2) loop |
| 15935 |
|
| 15936 |
-- The two packages may be siblings |
| 15937 |
|
| 15938 |
if P_1 = P_2 then |
| 15939 |
return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2); |
| 15940 |
end if; |
| 15941 |
|
| 15942 |
P_1 := Scope (P_1); |
| 15943 |
P_2 := Scope (P_2); |
| 15944 |
end loop; |
| 15945 |
end if; |
| 15946 |
|
| 15947 |
return False; |
| 15948 |
end Is_Child_Or_Sibling; |
| 15949 |
|
| 15950 |
------------------- |
| 15951 |
-- Is_Confirming -- |
| 15952 |
------------------- |
| 15953 |
|
| 15954 |
function Is_Confirming (Aspect : Nonoverridable_Aspect_Id; |
| 15955 |
Aspect_Spec_1, Aspect_Spec_2 : Node_Id) |
| 15956 |
return Boolean is |
| 15957 |
function Names_Match (Nm1, Nm2 : Node_Id) return Boolean; |
| 15958 |
|
| 15959 |
----------------- |
| 15960 |
-- Names_Match -- |
| 15961 |
----------------- |
| 15962 |
|
| 15963 |
function Names_Match (Nm1, Nm2 : Node_Id) return Boolean is |
| 15964 |
begin |
| 15965 |
if Nkind (Nm1) /= Nkind (Nm2) then |
| 15966 |
return False; |
| 15967 |
-- This may be too restrictive given that visibility |
| 15968 |
-- may allow an identifier in one case and an expanded |
| 15969 |
-- name in the other. |
| 15970 |
end if; |
| 15971 |
case Nkind (Nm1) is |
| 15972 |
when N_Identifier => |
| 15973 |
return Name_Equals (Chars (Nm1), Chars (Nm2)); |
| 15974 |
|
| 15975 |
when N_Expanded_Name => |
| 15976 |
-- An inherited operation has the same name as its |
| 15977 |
-- ancestor, but they may have different scopes. |
| 15978 |
-- This may be too permissive for Iterator_Element, which |
| 15979 |
-- is intended to be identical in parent and derived type. |
| 15980 |
|
| 15981 |
return Names_Match (Selector_Name (Nm1), |
| 15982 |
Selector_Name (Nm2)); |
| 15983 |
|
| 15984 |
when N_Empty => |
| 15985 |
return True; -- needed for Aggregate aspect checking |
| 15986 |
|
| 15987 |
when others => |
| 15988 |
-- e.g., 'Class attribute references |
| 15989 |
if Is_Entity_Name (Nm1) and Is_Entity_Name (Nm2) then |
| 15990 |
return Entity (Nm1) = Entity (Nm2); |
| 15991 |
end if; |
| 15992 |
|
| 15993 |
raise Program_Error; |
| 15994 |
end case; |
| 15995 |
end Names_Match; |
| 15996 |
|
| 15997 |
-- Start of processing for Is_Confirming |
| 15998 |
|
| 15999 |
begin |
| 16000 |
-- allow users to disable "shall be confirming" check, at least for now |
| 16001 |
if Relaxed_RM_Semantics then |
| 16002 |
return True; |
| 16003 |
end if; |
| 16004 |
|
| 16005 |
-- ??? Type conversion here (along with "when others =>" below) is a |
| 16006 |
-- workaround for a bootstrapping problem related to casing on a |
| 16007 |
-- static-predicate-bearing subtype. |
| 16008 |
|
| 16009 |
case Aspect_Id (Aspect) is |
| 16010 |
-- name-valued aspects; compare text of names, not resolution. |
| 16011 |
when Aspect_Default_Iterator |
| 16012 |
| Aspect_Iterator_Element |
| 16013 |
| Aspect_Constant_Indexing |
| 16014 |
| Aspect_Variable_Indexing => |
| 16015 |
return Names_Match (Expression (Aspect_Spec_1), |
| 16016 |
Expression (Aspect_Spec_2)); |
| 16017 |
|
| 16018 |
-- A confirming aspect for Implicit_Dereference on a derived type |
| 16019 |
-- has already been checked in Analyze_Aspect_Implicit_Dereference, |
| 16020 |
-- including the presence of renamed discriminants. |
| 16021 |
|
| 16022 |
when Aspect_Implicit_Dereference => |
| 16023 |
return True; |
| 16024 |
|
| 16025 |
-- one of a kind |
| 16026 |
when Aspect_Aggregate => |
| 16027 |
declare |
| 16028 |
Empty_1, |
| 16029 |
Add_Named_1, |
| 16030 |
Add_Unnamed_1, |
| 16031 |
New_Indexed_1, |
| 16032 |
Assign_Indexed_1, |
| 16033 |
Empty_2, |
| 16034 |
Add_Named_2, |
| 16035 |
Add_Unnamed_2, |
| 16036 |
New_Indexed_2, |
| 16037 |
Assign_Indexed_2 : Node_Id := Empty; |
| 16038 |
begin |
| 16039 |
Parse_Aspect_Aggregate |
| 16040 |
(N => Expression (Aspect_Spec_1), |
| 16041 |
Empty_Subp => Empty_1, |
| 16042 |
Add_Named_Subp => Add_Named_1, |
| 16043 |
Add_Unnamed_Subp => Add_Unnamed_1, |
| 16044 |
New_Indexed_Subp => New_Indexed_1, |
| 16045 |
Assign_Indexed_Subp => Assign_Indexed_1); |
| 16046 |
Parse_Aspect_Aggregate |
| 16047 |
(N => Expression (Aspect_Spec_2), |
| 16048 |
Empty_Subp => Empty_2, |
| 16049 |
Add_Named_Subp => Add_Named_2, |
| 16050 |
Add_Unnamed_Subp => Add_Unnamed_2, |
| 16051 |
New_Indexed_Subp => New_Indexed_2, |
| 16052 |
Assign_Indexed_Subp => Assign_Indexed_2); |
| 16053 |
return |
| 16054 |
Names_Match (Empty_1, Empty_2) and then |
| 16055 |
Names_Match (Add_Named_1, Add_Named_2) and then |
| 16056 |
Names_Match (Add_Unnamed_1, Add_Unnamed_2) and then |
| 16057 |
Names_Match (New_Indexed_1, New_Indexed_2) and then |
| 16058 |
Names_Match (Assign_Indexed_1, Assign_Indexed_2); |
| 16059 |
end; |
| 16060 |
|
| 16061 |
-- Checking for this aspect is performed elsewhere during freezing |
| 16062 |
when Aspect_No_Controlled_Parts => |
| 16063 |
return True; |
| 16064 |
|
| 16065 |
-- scalar-valued aspects; compare (static) values. |
| 16066 |
when Aspect_Max_Entry_Queue_Length => |
| 16067 |
-- This should be unreachable. Max_Entry_Queue_Length is |
| 16068 |
-- supported only for protected entries, not for types. |
| 16069 |
pragma Assert (Serious_Errors_Detected /= 0); |
| 16070 |
return True; |
| 16071 |
|
| 16072 |
when others => |
| 16073 |
raise Program_Error; |
| 16074 |
end case; |
| 16075 |
end Is_Confirming; |
| 16076 |
|
| 16077 |
----------------------------- |
| 16078 |
-- Is_Concurrent_Interface -- |
| 16079 |
----------------------------- |
| 16080 |
|
| 16081 |
function Is_Concurrent_Interface (T : Entity_Id) return Boolean is |
| 16082 |
begin |
| 16083 |
return Is_Protected_Interface (T) |
| 16084 |
or else Is_Synchronized_Interface (T) |
| 16085 |
or else Is_Task_Interface (T); |
| 16086 |
end Is_Concurrent_Interface; |
| 16087 |
|
| 16088 |
------------------------------------------------------ |
| 16089 |
-- Is_Conjunction_Of_Formal_Preelab_Init_Attributes -- |
| 16090 |
------------------------------------------------------ |
| 16091 |
|
| 16092 |
function Is_Conjunction_Of_Formal_Preelab_Init_Attributes |
| 16093 |
(Expr : Node_Id) return Boolean |
| 16094 |
is |
| 16095 |
|
| 16096 |
function Is_Formal_Preelab_Init_Attribute |
| 16097 |
(N : Node_Id) return Boolean; |
| 16098 |
-- Returns True if N is a Preelaborable_Initialization attribute |
| 16099 |
-- applied to a generic formal type, or N's Original_Node is such |
| 16100 |
-- an attribute. |
| 16101 |
|
| 16102 |
-------------------------------------- |
| 16103 |
-- Is_Formal_Preelab_Init_Attribute -- |
| 16104 |
-------------------------------------- |
| 16105 |
|
| 16106 |
function Is_Formal_Preelab_Init_Attribute |
| 16107 |
(N : Node_Id) return Boolean |
| 16108 |
is |
| 16109 |
Orig_N : constant Node_Id := Original_Node (N); |
| 16110 |
|
| 16111 |
begin |
| 16112 |
return Nkind (Orig_N) = N_Attribute_Reference |
| 16113 |
and then Attribute_Name (Orig_N) = Name_Preelaborable_Initialization |
| 16114 |
and then Is_Entity_Name (Prefix (Orig_N)) |
| 16115 |
and then Is_Generic_Type (Entity (Prefix (Orig_N))); |
| 16116 |
end Is_Formal_Preelab_Init_Attribute; |
| 16117 |
|
| 16118 |
-- Start of Is_Conjunction_Of_Formal_Preelab_Init_Attributes |
| 16119 |
|
| 16120 |
begin |
| 16121 |
return Is_Formal_Preelab_Init_Attribute (Expr) |
| 16122 |
or else (Nkind (Expr) = N_Op_And |
| 16123 |
and then |
| 16124 |
Is_Conjunction_Of_Formal_Preelab_Init_Attributes |
| 16125 |
(Left_Opnd (Expr)) |
| 16126 |
and then |
| 16127 |
Is_Conjunction_Of_Formal_Preelab_Init_Attributes |
| 16128 |
(Right_Opnd (Expr))); |
| 16129 |
end Is_Conjunction_Of_Formal_Preelab_Init_Attributes; |
| 16130 |
|
| 16131 |
----------------------- |
| 16132 |
-- Is_Constant_Bound -- |
| 16133 |
----------------------- |
| 16134 |
|
| 16135 |
function Is_Constant_Bound (Exp : Node_Id) return Boolean is |
| 16136 |
begin |
| 16137 |
if Compile_Time_Known_Value (Exp) then |
| 16138 |
return True; |
| 16139 |
|
| 16140 |
elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then |
| 16141 |
return Is_Constant_Object (Entity (Exp)) |
| 16142 |
or else Ekind (Entity (Exp)) = E_Enumeration_Literal; |
| 16143 |
|
| 16144 |
elsif Nkind (Exp) in N_Binary_Op then |
| 16145 |
return Is_Constant_Bound (Left_Opnd (Exp)) |
| 16146 |
and then Is_Constant_Bound (Right_Opnd (Exp)) |
| 16147 |
and then Scope (Entity (Exp)) = Standard_Standard; |
| 16148 |
|
| 16149 |
else |
| 16150 |
return False; |
| 16151 |
end if; |
| 16152 |
end Is_Constant_Bound; |
| 16153 |
|
| 16154 |
--------------------------- |
| 16155 |
-- Is_Container_Element -- |
| 16156 |
--------------------------- |
| 16157 |
|
| 16158 |
function Is_Container_Element (Exp : Node_Id) return Boolean is |
| 16159 |
Loc : constant Source_Ptr := Sloc (Exp); |
| 16160 |
Pref : constant Node_Id := Prefix (Exp); |
| 16161 |
|
| 16162 |
Call : Node_Id; |
| 16163 |
-- Call to an indexing aspect |
| 16164 |
|
| 16165 |
Cont_Typ : Entity_Id; |
| 16166 |
-- The type of the container being accessed |
| 16167 |
|
| 16168 |
Elem_Typ : Entity_Id; |
| 16169 |
-- Its element type |
| 16170 |
|
| 16171 |
Indexing : Entity_Id; |
| 16172 |
Is_Const : Boolean; |
| 16173 |
-- Indicates that constant indexing is used, and the element is thus |
| 16174 |
-- a constant. |
| 16175 |
|
| 16176 |
Ref_Typ : Entity_Id; |
| 16177 |
-- The reference type returned by the indexing operation |
| 16178 |
|
| 16179 |
begin |
| 16180 |
-- If C is a container, in a context that imposes the element type of |
| 16181 |
-- that container, the indexing notation C (X) is rewritten as: |
| 16182 |
|
| 16183 |
-- Indexing (C, X).Discr.all |
| 16184 |
|
| 16185 |
-- where Indexing is one of the indexing aspects of the container. |
| 16186 |
-- If the context does not require a reference, the construct can be |
| 16187 |
-- rewritten as |
| 16188 |
|
| 16189 |
-- Element (C, X) |
| 16190 |
|
| 16191 |
-- First, verify that the construct has the proper form |
| 16192 |
|
| 16193 |
if not Expander_Active then |
| 16194 |
return False; |
| 16195 |
|
| 16196 |
elsif Nkind (Pref) /= N_Selected_Component then |
| 16197 |
return False; |
| 16198 |
|
| 16199 |
elsif Nkind (Prefix (Pref)) /= N_Function_Call then |
| 16200 |
return False; |
| 16201 |
|
| 16202 |
else |
| 16203 |
Call := Prefix (Pref); |
| 16204 |
Ref_Typ := Etype (Call); |
| 16205 |
end if; |
| 16206 |
|
| 16207 |
if not Has_Implicit_Dereference (Ref_Typ) |
| 16208 |
or else No (First (Parameter_Associations (Call))) |
| 16209 |
or else not Is_Entity_Name (Name (Call)) |
| 16210 |
then |
| 16211 |
return False; |
| 16212 |
end if; |
| 16213 |
|
| 16214 |
-- Retrieve type of container object, and its iterator aspects |
| 16215 |
|
| 16216 |
Cont_Typ := Etype (First (Parameter_Associations (Call))); |
| 16217 |
Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing); |
| 16218 |
Is_Const := False; |
| 16219 |
|
| 16220 |
if No (Indexing) then |
| 16221 |
|
| 16222 |
-- Container should have at least one indexing operation |
| 16223 |
|
| 16224 |
return False; |
| 16225 |
|
| 16226 |
elsif Entity (Name (Call)) /= Entity (Indexing) then |
| 16227 |
|
| 16228 |
-- This may be a variable indexing operation |
| 16229 |
|
| 16230 |
Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing); |
| 16231 |
|
| 16232 |
if No (Indexing) |
| 16233 |
or else Entity (Name (Call)) /= Entity (Indexing) |
| 16234 |
then |
| 16235 |
return False; |
| 16236 |
end if; |
| 16237 |
|
| 16238 |
else |
| 16239 |
Is_Const := True; |
| 16240 |
end if; |
| 16241 |
|
| 16242 |
Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element); |
| 16243 |
|
| 16244 |
if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then |
| 16245 |
return False; |
| 16246 |
end if; |
| 16247 |
|
| 16248 |
-- Check that the expression is not the target of an assignment, in |
| 16249 |
-- which case the rewriting is not possible. |
| 16250 |
|
| 16251 |
if not Is_Const then |
| 16252 |
declare |
| 16253 |
Par : Node_Id; |
| 16254 |
|
| 16255 |
begin |
| 16256 |
Par := Exp; |
| 16257 |
while Present (Par) |
| 16258 |
loop |
| 16259 |
if Nkind (Parent (Par)) = N_Assignment_Statement |
| 16260 |
and then Par = Name (Parent (Par)) |
| 16261 |
then |
| 16262 |
return False; |
| 16263 |
|
| 16264 |
-- A renaming produces a reference, and the transformation |
| 16265 |
-- does not apply. |
| 16266 |
|
| 16267 |
elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then |
| 16268 |
return False; |
| 16269 |
|
| 16270 |
elsif Nkind (Parent (Par)) in N_Entry_Call_Statement |
| 16271 |
| N_Subprogram_Call |
| 16272 |
then |
| 16273 |
-- Check that the element is not part of an actual for an |
| 16274 |
-- in-out parameter. |
| 16275 |
|
| 16276 |
declare |
| 16277 |
F : Entity_Id; |
| 16278 |
A : Node_Id; |
| 16279 |
|
| 16280 |
begin |
| 16281 |
F := First_Formal (Entity (Name (Parent (Par)))); |
| 16282 |
A := First_Actual (Parent (Par)); |
| 16283 |
while Present (F) loop |
| 16284 |
if A = Par and then Ekind (F) /= E_In_Parameter then |
| 16285 |
return False; |
| 16286 |
end if; |
| 16287 |
|
| 16288 |
Next_Formal (F); |
| 16289 |
Next_Actual (A); |
| 16290 |
end loop; |
| 16291 |
end; |
| 16292 |
|
| 16293 |
-- E_In_Parameter in a call: element is not modified. |
| 16294 |
|
| 16295 |
exit; |
| 16296 |
end if; |
| 16297 |
|
| 16298 |
Par := Parent (Par); |
| 16299 |
end loop; |
| 16300 |
end; |
| 16301 |
end if; |
| 16302 |
|
| 16303 |
-- The expression has the proper form and the context requires the |
| 16304 |
-- element type. Retrieve the Element function of the container and |
| 16305 |
-- rewrite the construct as a call to it. |
| 16306 |
|
| 16307 |
declare |
| 16308 |
Op : Elmt_Id; |
| 16309 |
|
| 16310 |
begin |
| 16311 |
Op := First_Elmt (Primitive_Operations (Cont_Typ)); |
| 16312 |
while Present (Op) loop |
| 16313 |
exit when Chars (Node (Op)) = Name_Element; |
| 16314 |
Next_Elmt (Op); |
| 16315 |
end loop; |
| 16316 |
|
| 16317 |
if No (Op) then |
| 16318 |
return False; |
| 16319 |
|
| 16320 |
else |
| 16321 |
Rewrite (Exp, |
| 16322 |
Make_Function_Call (Loc, |
| 16323 |
Name => New_Occurrence_Of (Node (Op), Loc), |
| 16324 |
Parameter_Associations => Parameter_Associations (Call))); |
| 16325 |
Analyze_And_Resolve (Exp, Entity (Elem_Typ)); |
| 16326 |
return True; |
| 16327 |
end if; |
| 16328 |
end; |
| 16329 |
end Is_Container_Element; |
| 16330 |
|
| 16331 |
---------------------------- |
| 16332 |
-- Is_Contract_Annotation -- |
| 16333 |
---------------------------- |
| 16334 |
|
| 16335 |
function Is_Contract_Annotation (Item : Node_Id) return Boolean is |
| 16336 |
begin |
| 16337 |
return Is_Package_Contract_Annotation (Item) |
| 16338 |
or else |
| 16339 |
Is_Subprogram_Contract_Annotation (Item); |
| 16340 |
end Is_Contract_Annotation; |
| 16341 |
|
| 16342 |
-------------------------------------- |
| 16343 |
-- Is_Controlling_Limited_Procedure -- |
| 16344 |
-------------------------------------- |
| 16345 |
|
| 16346 |
function Is_Controlling_Limited_Procedure |
| 16347 |
(Proc_Nam : Entity_Id) return Boolean |
| 16348 |
is |
| 16349 |
Param : Node_Id; |
| 16350 |
Param_Typ : Entity_Id := Empty; |
| 16351 |
|
| 16352 |
begin |
| 16353 |
if Ekind (Proc_Nam) = E_Procedure |
| 16354 |
and then Present (Parameter_Specifications (Parent (Proc_Nam))) |
| 16355 |
then |
| 16356 |
Param := |
| 16357 |
Parameter_Type |
| 16358 |
(First (Parameter_Specifications (Parent (Proc_Nam)))); |
| 16359 |
|
| 16360 |
-- The formal may be an anonymous access type |
| 16361 |
|
| 16362 |
if Nkind (Param) = N_Access_Definition then |
| 16363 |
Param_Typ := Entity (Subtype_Mark (Param)); |
| 16364 |
else |
| 16365 |
Param_Typ := Etype (Param); |
| 16366 |
end if; |
| 16367 |
|
| 16368 |
-- In the case where an Itype was created for a dispatching call, the |
| 16369 |
-- procedure call has been rewritten. The actual may be an access to |
| 16370 |
-- interface type in which case it is the designated type that is the |
| 16371 |
-- controlling type. |
| 16372 |
|
| 16373 |
elsif Present (Associated_Node_For_Itype (Proc_Nam)) |
| 16374 |
and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam))) |
| 16375 |
and then |
| 16376 |
Present (Parameter_Associations |
| 16377 |
(Associated_Node_For_Itype (Proc_Nam))) |
| 16378 |
then |
| 16379 |
Param_Typ := |
| 16380 |
Etype (First (Parameter_Associations |
| 16381 |
(Associated_Node_For_Itype (Proc_Nam)))); |
| 16382 |
|
| 16383 |
if Ekind (Param_Typ) = E_Anonymous_Access_Type then |
| 16384 |
Param_Typ := Directly_Designated_Type (Param_Typ); |
| 16385 |
end if; |
| 16386 |
end if; |
| 16387 |
|
| 16388 |
if Present (Param_Typ) then |
| 16389 |
return |
| 16390 |
Is_Interface (Param_Typ) |
| 16391 |
and then Is_Limited_Record (Param_Typ); |
| 16392 |
end if; |
| 16393 |
|
| 16394 |
return False; |
| 16395 |
end Is_Controlling_Limited_Procedure; |
| 16396 |
|
| 16397 |
----------------------------- |
| 16398 |
-- Is_CPP_Constructor_Call -- |
| 16399 |
----------------------------- |
| 16400 |
|
| 16401 |
function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is |
| 16402 |
Ret_Typ : Entity_Id; |
| 16403 |
|
| 16404 |
begin |
| 16405 |
if Nkind (N) /= N_Function_Call then |
| 16406 |
return False; |
| 16407 |
end if; |
| 16408 |
|
| 16409 |
Ret_Typ := Base_Type (Etype (N)); |
| 16410 |
|
| 16411 |
if Is_Class_Wide_Type (Ret_Typ) then |
| 16412 |
Ret_Typ := Root_Type (Ret_Typ); |
| 16413 |
end if; |
| 16414 |
|
| 16415 |
if Is_Private_Type (Ret_Typ) then |
| 16416 |
Ret_Typ := Underlying_Type (Ret_Typ); |
| 16417 |
end if; |
| 16418 |
|
| 16419 |
return Present (Ret_Typ) |
| 16420 |
and then Is_CPP_Class (Ret_Typ) |
| 16421 |
and then Is_Constructor (Entity (Name (N))) |
| 16422 |
and then Is_Imported (Entity (Name (N))); |
| 16423 |
end Is_CPP_Constructor_Call; |
| 16424 |
|
| 16425 |
------------------------- |
| 16426 |
-- Is_Current_Instance -- |
| 16427 |
------------------------- |
| 16428 |
|
| 16429 |
function Is_Current_Instance (N : Node_Id) return Boolean is |
| 16430 |
Typ : constant Entity_Id := Entity (N); |
| 16431 |
P : Node_Id; |
| 16432 |
|
| 16433 |
begin |
| 16434 |
-- Since Ada 2005, the "current instance" rule does not apply |
| 16435 |
-- to a type_mark in an access_definition (RM 8.6), |
| 16436 |
-- although it does apply in an access_to_object definition. |
| 16437 |
-- So the rule does not apply in the definition of an anonymous |
| 16438 |
-- access type, but it does apply in the definition of a named |
| 16439 |
-- access-to-object type. |
| 16440 |
-- The rule also does not apply in a designated subprogram profile. |
| 16441 |
|
| 16442 |
if Ada_Version >= Ada_2005 then |
| 16443 |
case Nkind (Parent (N)) is |
| 16444 |
when N_Access_Definition | N_Access_Function_Definition => |
| 16445 |
return False; |
| 16446 |
when N_Parameter_Specification => |
| 16447 |
if Nkind (Parent (Parent (N))) in |
| 16448 |
N_Access_To_Subprogram_Definition |
| 16449 |
then |
| 16450 |
return False; |
| 16451 |
end if; |
| 16452 |
when others => |
| 16453 |
null; |
| 16454 |
end case; |
| 16455 |
end if; |
| 16456 |
|
| 16457 |
-- Simplest case: entity is a concurrent type and we are currently |
| 16458 |
-- inside the body. This will eventually be expanded into a call to |
| 16459 |
-- Self (for tasks) or _object (for protected objects). |
| 16460 |
|
| 16461 |
if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then |
| 16462 |
return True; |
| 16463 |
|
| 16464 |
else |
| 16465 |
-- Check whether the context is a (sub)type declaration for the |
| 16466 |
-- type entity. |
| 16467 |
|
| 16468 |
P := Parent (N); |
| 16469 |
while Present (P) loop |
| 16470 |
if Nkind (P) in N_Full_Type_Declaration |
| 16471 |
| N_Private_Type_Declaration |
| 16472 |
| N_Subtype_Declaration |
| 16473 |
and then Comes_From_Source (P) |
| 16474 |
|
| 16475 |
-- If the type has a previous incomplete declaration, the |
| 16476 |
-- reference in the type definition may have the incomplete |
| 16477 |
-- view. So, here we detect if this incomplete view is a current |
| 16478 |
-- instance by checking if its full view is the entity of the |
| 16479 |
-- full declaration begin analyzed. |
| 16480 |
|
| 16481 |
and then |
| 16482 |
(Defining_Entity (P) = Typ |
| 16483 |
or else |
| 16484 |
(Ekind (Typ) = E_Incomplete_Type |
| 16485 |
and then Full_View (Typ) = Defining_Entity (P))) |
| 16486 |
then |
| 16487 |
return True; |
| 16488 |
|
| 16489 |
-- A subtype name may appear in an aspect specification for a |
| 16490 |
-- Predicate_Failure aspect, for which we do not construct a |
| 16491 |
-- wrapper procedure. The subtype will be replaced by the |
| 16492 |
-- expression being tested when the corresponding predicate |
| 16493 |
-- check is expanded. It may also appear in the pragma Predicate |
| 16494 |
-- expression during legality checking. |
| 16495 |
|
| 16496 |
elsif Nkind (P) = N_Aspect_Specification |
| 16497 |
and then Nkind (Parent (P)) = N_Subtype_Declaration |
| 16498 |
and then Underlying_Type (Defining_Identifier (Parent (P))) = |
| 16499 |
Underlying_Type (Typ) |
| 16500 |
then |
| 16501 |
return True; |
| 16502 |
|
| 16503 |
elsif Nkind (P) = N_Pragma |
| 16504 |
and then Get_Pragma_Id (P) in Pragma_Predicate |
| 16505 |
| Pragma_Predicate_Failure |
| 16506 |
|
| 16507 |
-- For "pragma Predicate (T, Is_OK (T))", return False for the |
| 16508 |
-- first use of T and True for the second. |
| 16509 |
|
| 16510 |
and then |
| 16511 |
N /= Expression (First (Pragma_Argument_Associations (P))) |
| 16512 |
then |
| 16513 |
declare |
| 16514 |
Arg : constant Entity_Id := |
| 16515 |
Entity (Expression (Get_Argument (P))); |
| 16516 |
begin |
| 16517 |
if Underlying_Type (Arg) = Underlying_Type (Typ) then |
| 16518 |
return True; |
| 16519 |
end if; |
| 16520 |
end; |
| 16521 |
end if; |
| 16522 |
|
| 16523 |
P := Parent (P); |
| 16524 |
end loop; |
| 16525 |
end if; |
| 16526 |
|
| 16527 |
-- In any other context this is not a current instance reference. |
| 16528 |
|
| 16529 |
return False; |
| 16530 |
end Is_Current_Instance; |
| 16531 |
|
| 16532 |
-------------------------------------------------- |
| 16533 |
-- Is_Current_Instance_Reference_In_Type_Aspect -- |
| 16534 |
-------------------------------------------------- |
| 16535 |
|
| 16536 |
function Is_Current_Instance_Reference_In_Type_Aspect |
| 16537 |
(N : Node_Id) return Boolean |
| 16538 |
is |
| 16539 |
begin |
| 16540 |
-- When a current_instance is referenced within an aspect_specification |
| 16541 |
-- of a type or subtype, it will show up as a reference to the formal |
| 16542 |
-- parameter of the aspect's associated subprogram rather than as a |
| 16543 |
-- reference to the type or subtype itself (in fact, the original name |
| 16544 |
-- is never even analyzed). We check for predicate, invariant, and |
| 16545 |
-- Default_Initial_Condition subprograms (in theory there could be |
| 16546 |
-- other cases added, in which case this function will need updating). |
| 16547 |
|
| 16548 |
if Is_Entity_Name (N) then |
| 16549 |
return Present (Entity (N)) |
| 16550 |
and then Ekind (Entity (N)) = E_In_Parameter |
| 16551 |
and then Ekind (Scope (Entity (N))) in E_Function | E_Procedure |
| 16552 |
and then |
| 16553 |
(Is_Predicate_Function (Scope (Entity (N))) |
| 16554 |
or else Is_Invariant_Procedure (Scope (Entity (N))) |
| 16555 |
or else Is_Partial_Invariant_Procedure (Scope (Entity (N))) |
| 16556 |
or else Is_DIC_Procedure (Scope (Entity (N)))); |
| 16557 |
|
| 16558 |
else |
| 16559 |
case Nkind (N) is |
| 16560 |
when N_Indexed_Component |
| 16561 |
| N_Slice |
| 16562 |
=> |
| 16563 |
return |
| 16564 |
Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N)); |
| 16565 |
|
| 16566 |
when N_Selected_Component => |
| 16567 |
return |
| 16568 |
Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N)); |
| 16569 |
|
| 16570 |
when N_Type_Conversion => |
| 16571 |
return Is_Current_Instance_Reference_In_Type_Aspect |
| 16572 |
(Expression (N)); |
| 16573 |
|
| 16574 |
when N_Qualified_Expression => |
| 16575 |
return Is_Current_Instance_Reference_In_Type_Aspect |
| 16576 |
(Expression (N)); |
| 16577 |
|
| 16578 |
when others => |
| 16579 |
return False; |
| 16580 |
end case; |
| 16581 |
end if; |
| 16582 |
end Is_Current_Instance_Reference_In_Type_Aspect; |
| 16583 |
|
| 16584 |
-------------------- |
| 16585 |
-- Is_Declaration -- |
| 16586 |
-------------------- |
| 16587 |
|
| 16588 |
function Is_Declaration |
| 16589 |
(N : Node_Id; |
| 16590 |
Body_OK : Boolean := True; |
| 16591 |
Concurrent_OK : Boolean := True; |
| 16592 |
Formal_OK : Boolean := True; |
| 16593 |
Generic_OK : Boolean := True; |
| 16594 |
Instantiation_OK : Boolean := True; |
| 16595 |
Renaming_OK : Boolean := True; |
| 16596 |
Stub_OK : Boolean := True; |
| 16597 |
Subprogram_OK : Boolean := True; |
| 16598 |
Type_OK : Boolean := True) return Boolean |
| 16599 |
is |
| 16600 |
begin |
| 16601 |
case Nkind (N) is |
| 16602 |
|
| 16603 |
-- Body declarations |
| 16604 |
|
| 16605 |
when N_Proper_Body => |
| 16606 |
return Body_OK; |
| 16607 |
|
| 16608 |
-- Concurrent type declarations |
| 16609 |
|
| 16610 |
when N_Protected_Type_Declaration |
| 16611 |
| N_Single_Protected_Declaration |
| 16612 |
| N_Single_Task_Declaration |
| 16613 |
| N_Task_Type_Declaration |
| 16614 |
=> |
| 16615 |
return Concurrent_OK or Type_OK; |
| 16616 |
|
| 16617 |
-- Formal declarations |
| 16618 |
|
| 16619 |
when N_Formal_Abstract_Subprogram_Declaration |
| 16620 |
| N_Formal_Concrete_Subprogram_Declaration |
| 16621 |
| N_Formal_Object_Declaration |
| 16622 |
| N_Formal_Package_Declaration |
| 16623 |
| N_Formal_Type_Declaration |
| 16624 |
=> |
| 16625 |
return Formal_OK; |
| 16626 |
|
| 16627 |
-- Generic declarations |
| 16628 |
|
| 16629 |
when N_Generic_Package_Declaration |
| 16630 |
| N_Generic_Subprogram_Declaration |
| 16631 |
=> |
| 16632 |
return Generic_OK; |
| 16633 |
|
| 16634 |
-- Generic instantiations |
| 16635 |
|
| 16636 |
when N_Function_Instantiation |
| 16637 |
| N_Package_Instantiation |
| 16638 |
| N_Procedure_Instantiation |
| 16639 |
=> |
| 16640 |
return Instantiation_OK; |
| 16641 |
|
| 16642 |
-- Generic renaming declarations |
| 16643 |
|
| 16644 |
when N_Generic_Renaming_Declaration => |
| 16645 |
return Generic_OK or Renaming_OK; |
| 16646 |
|
| 16647 |
-- Renaming declarations |
| 16648 |
|
| 16649 |
when N_Exception_Renaming_Declaration |
| 16650 |
| N_Object_Renaming_Declaration |
| 16651 |
| N_Package_Renaming_Declaration |
| 16652 |
| N_Subprogram_Renaming_Declaration |
| 16653 |
=> |
| 16654 |
return Renaming_OK; |
| 16655 |
|
| 16656 |
-- Stub declarations |
| 16657 |
|
| 16658 |
when N_Body_Stub => |
| 16659 |
return Stub_OK; |
| 16660 |
|
| 16661 |
-- Subprogram declarations |
| 16662 |
|
| 16663 |
when N_Abstract_Subprogram_Declaration |
| 16664 |
| N_Entry_Declaration |
| 16665 |
| N_Expression_Function |
| 16666 |
| N_Subprogram_Declaration |
| 16667 |
=> |
| 16668 |
return Subprogram_OK; |
| 16669 |
|
| 16670 |
-- Type declarations |
| 16671 |
|
| 16672 |
when N_Full_Type_Declaration |
| 16673 |
| N_Incomplete_Type_Declaration |
| 16674 |
| N_Private_Extension_Declaration |
| 16675 |
| N_Private_Type_Declaration |
| 16676 |
| N_Subtype_Declaration |
| 16677 |
=> |
| 16678 |
return Type_OK; |
| 16679 |
|
| 16680 |
-- Miscellaneous |
| 16681 |
|
| 16682 |
when N_Component_Declaration |
| 16683 |
| N_Exception_Declaration |
| 16684 |
| N_Implicit_Label_Declaration |
| 16685 |
| N_Number_Declaration |
| 16686 |
| N_Object_Declaration |
| 16687 |
| N_Package_Declaration |
| 16688 |
=> |
| 16689 |
return True; |
| 16690 |
|
| 16691 |
when others => |
| 16692 |
return False; |
| 16693 |
end case; |
| 16694 |
end Is_Declaration; |
| 16695 |
|
| 16696 |
-------------------------------- |
| 16697 |
-- Is_Declared_Within_Variant -- |
| 16698 |
-------------------------------- |
| 16699 |
|
| 16700 |
function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is |
| 16701 |
Comp_Decl : constant Node_Id := Parent (Comp); |
| 16702 |
Comp_List : constant Node_Id := Parent (Comp_Decl); |
| 16703 |
begin |
| 16704 |
return Nkind (Parent (Comp_List)) = N_Variant; |
| 16705 |
end Is_Declared_Within_Variant; |
| 16706 |
|
| 16707 |
---------------------------------------------- |
| 16708 |
-- Is_Dependent_Component_Of_Mutable_Object -- |
| 16709 |
---------------------------------------------- |
| 16710 |
|
| 16711 |
function Is_Dependent_Component_Of_Mutable_Object |
| 16712 |
(Object : Node_Id) return Boolean |
| 16713 |
is |
| 16714 |
P : Node_Id; |
| 16715 |
Prefix_Type : Entity_Id; |
| 16716 |
P_Aliased : Boolean := False; |
| 16717 |
Comp : Entity_Id; |
| 16718 |
|
| 16719 |
Deref : Node_Id := Original_Node (Object); |
| 16720 |
-- Dereference node, in something like X.all.Y(2) |
| 16721 |
|
| 16722 |
-- Start of processing for Is_Dependent_Component_Of_Mutable_Object |
| 16723 |
|
| 16724 |
begin |
| 16725 |
-- Find the dereference node if any |
| 16726 |
|
| 16727 |
while Nkind (Deref) in |
| 16728 |
N_Indexed_Component | N_Selected_Component | N_Slice |
| 16729 |
loop |
| 16730 |
Deref := Original_Node (Prefix (Deref)); |
| 16731 |
end loop; |
| 16732 |
|
| 16733 |
-- If the prefix is a qualified expression of a variable, then function |
| 16734 |
-- Is_Variable will return False for that because a qualified expression |
| 16735 |
-- denotes a constant view, so we need to get the name being qualified |
| 16736 |
-- so we can test below whether that's a variable (or a dereference). |
| 16737 |
|
| 16738 |
if Nkind (Deref) = N_Qualified_Expression then |
| 16739 |
Deref := Expression (Deref); |
| 16740 |
end if; |
| 16741 |
|
| 16742 |
-- Ada 2005: If we have a component or slice of a dereference, something |
| 16743 |
-- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable |
| 16744 |
-- will return False, because it is indeed a constant view. But it might |
| 16745 |
-- be a view of a variable object, so we want the following condition to |
| 16746 |
-- be True in that case. |
| 16747 |
|
| 16748 |
if Is_Variable (Object) |
| 16749 |
or else Is_Variable (Deref) |
| 16750 |
or else |
| 16751 |
(Ada_Version >= Ada_2005 |
| 16752 |
and then (Nkind (Deref) = N_Explicit_Dereference |
| 16753 |
or else (Present (Etype (Deref)) |
| 16754 |
and then Is_Access_Type (Etype (Deref))))) |
| 16755 |
then |
| 16756 |
if Nkind (Object) = N_Selected_Component then |
| 16757 |
|
| 16758 |
-- If the selector is not a component, then we definitely return |
| 16759 |
-- False (it could be a function selector in a prefix form call |
| 16760 |
-- occurring in an iterator specification). |
| 16761 |
|
| 16762 |
if (Present (Entity (Selector_Name (Object))) |
| 16763 |
and then Ekind (Entity (Selector_Name (Object))) not in |
| 16764 |
E_Component | E_Discriminant) |
| 16765 |
or else |
| 16766 |
(Inside_A_Generic |
| 16767 |
and then Nkind (Parent (Selector_Name (Object))) |
| 16768 |
= N_Function_Call) |
| 16769 |
then |
| 16770 |
return False; |
| 16771 |
end if; |
| 16772 |
|
| 16773 |
-- Get the original node of the prefix in case it has been |
| 16774 |
-- rewritten, which can occur, for example, in qualified |
| 16775 |
-- expression cases. Also, a discriminant check on a selected |
| 16776 |
-- component may be expanded into a dereference when removing |
| 16777 |
-- side effects, and the subtype of the original node may be |
| 16778 |
-- unconstrained. |
| 16779 |
|
| 16780 |
P := Original_Node (Prefix (Object)); |
| 16781 |
Prefix_Type := Etype (P); |
| 16782 |
|
| 16783 |
-- If the prefix is a qualified expression, we want to look at its |
| 16784 |
-- operand. |
| 16785 |
|
| 16786 |
if Nkind (P) = N_Qualified_Expression then |
| 16787 |
P := Expression (P); |
| 16788 |
Prefix_Type := Etype (P); |
| 16789 |
end if; |
| 16790 |
|
| 16791 |
if Is_Entity_Name (P) then |
| 16792 |
-- The Etype may not be set on P (which is wrong) in certain |
| 16793 |
-- corner cases involving the deprecated front-end inlining of |
| 16794 |
-- subprograms (via -gnatN), so use the Etype set on the |
| 16795 |
-- the entity for these instances since we know it is present. |
| 16796 |
|
| 16797 |
if No (Prefix_Type) then |
| 16798 |
Prefix_Type := Etype (Entity (P)); |
| 16799 |
end if; |
| 16800 |
|
| 16801 |
if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then |
| 16802 |
Prefix_Type := Base_Type (Prefix_Type); |
| 16803 |
end if; |
| 16804 |
|
| 16805 |
if Is_Aliased (Entity (P)) then |
| 16806 |
P_Aliased := True; |
| 16807 |
end if; |
| 16808 |
|
| 16809 |
-- For explicit dereferences we get the access prefix so we can |
| 16810 |
-- treat this similarly to implicit dereferences and examine the |
| 16811 |
-- kind of the access type and its designated subtype further |
| 16812 |
-- below. |
| 16813 |
|
| 16814 |
elsif Nkind (P) = N_Explicit_Dereference then |
| 16815 |
P := Prefix (P); |
| 16816 |
Prefix_Type := Etype (P); |
| 16817 |
|
| 16818 |
else |
| 16819 |
-- Check for prefix being an aliased component??? |
| 16820 |
|
| 16821 |
null; |
| 16822 |
end if; |
| 16823 |
|
| 16824 |
-- A heap object is constrained by its initial value |
| 16825 |
|
| 16826 |
-- Ada 2005 (AI-363): Always assume the object could be mutable in |
| 16827 |
-- the dereferenced case, since the access value might denote an |
| 16828 |
-- unconstrained aliased object, whereas in Ada 95 the designated |
| 16829 |
-- object is guaranteed to be constrained. A worst-case assumption |
| 16830 |
-- has to apply in Ada 2005 because we can't tell at compile |
| 16831 |
-- time whether the object is "constrained by its initial value", |
| 16832 |
-- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic |
| 16833 |
-- rules (these rules are acknowledged to need fixing). We don't |
| 16834 |
-- impose this more stringent checking for earlier Ada versions or |
| 16835 |
-- when Relaxed_RM_Semantics applies (the latter for CodePeer's |
| 16836 |
-- benefit, though it's unclear on why using -gnat95 would not be |
| 16837 |
-- sufficient???). |
| 16838 |
|
| 16839 |
if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then |
| 16840 |
if Is_Access_Type (Prefix_Type) |
| 16841 |
or else Nkind (P) = N_Explicit_Dereference |
| 16842 |
then |
| 16843 |
return False; |
| 16844 |
end if; |
| 16845 |
|
| 16846 |
else pragma Assert (Ada_Version >= Ada_2005); |
| 16847 |
if Is_Access_Type (Prefix_Type) then |
| 16848 |
-- We need to make sure we have the base subtype, in case |
| 16849 |
-- this is actually an access subtype (whose Ekind will be |
| 16850 |
-- E_Access_Subtype). |
| 16851 |
|
| 16852 |
Prefix_Type := Etype (Prefix_Type); |
| 16853 |
|
| 16854 |
-- If the access type is pool-specific, and there is no |
| 16855 |
-- constrained partial view of the designated type, then the |
| 16856 |
-- designated object is known to be constrained. If it's a |
| 16857 |
-- formal access type and the renaming is in the generic |
| 16858 |
-- spec, we also treat it as pool-specific (known to be |
| 16859 |
-- constrained), but assume the worst if in the generic body |
| 16860 |
-- (see RM 3.3(23.3/3)). |
| 16861 |
|
| 16862 |
if Ekind (Prefix_Type) = E_Access_Type |
| 16863 |
and then (not Is_Generic_Type (Prefix_Type) |
| 16864 |
or else not In_Generic_Body (Current_Scope)) |
| 16865 |
and then not Object_Type_Has_Constrained_Partial_View |
| 16866 |
(Typ => Designated_Type (Prefix_Type), |
| 16867 |
Scop => Current_Scope) |
| 16868 |
then |
| 16869 |
return False; |
| 16870 |
|
| 16871 |
-- Otherwise (general access type, or there is a constrained |
| 16872 |
-- partial view of the designated type), we need to check |
| 16873 |
-- based on the designated type. |
| 16874 |
|
| 16875 |
else |
| 16876 |
Prefix_Type := Designated_Type (Prefix_Type); |
| 16877 |
end if; |
| 16878 |
end if; |
| 16879 |
end if; |
| 16880 |
|
| 16881 |
Comp := |
| 16882 |
Original_Record_Component (Entity (Selector_Name (Object))); |
| 16883 |
|
| 16884 |
-- As per AI-0017, the renaming is illegal in a generic body, even |
| 16885 |
-- if the subtype is indefinite (only applies to prefixes of an |
| 16886 |
-- untagged formal type, see RM 3.3 (23.11/3)). |
| 16887 |
|
| 16888 |
-- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable |
| 16889 |
|
| 16890 |
if not Is_Constrained (Prefix_Type) |
| 16891 |
and then (Is_Definite_Subtype (Prefix_Type) |
| 16892 |
or else |
| 16893 |
(not Is_Tagged_Type (Prefix_Type) |
| 16894 |
and then Is_Generic_Type (Prefix_Type) |
| 16895 |
and then In_Generic_Body (Current_Scope))) |
| 16896 |
|
| 16897 |
and then (Is_Declared_Within_Variant (Comp) |
| 16898 |
or else Has_Discriminant_Dependent_Constraint (Comp)) |
| 16899 |
and then (not P_Aliased or else Ada_Version >= Ada_2005) |
| 16900 |
then |
| 16901 |
return True; |
| 16902 |
|
| 16903 |
-- If the prefix is of an access type at this point, then we want |
| 16904 |
-- to return False, rather than calling this function recursively |
| 16905 |
-- on the access object (which itself might be a discriminant- |
| 16906 |
-- dependent component of some other object, but that isn't |
| 16907 |
-- relevant to checking the object passed to us). This avoids |
| 16908 |
-- issuing wrong errors when compiling with -gnatc, where there |
| 16909 |
-- can be implicit dereferences that have not been expanded. |
| 16910 |
|
| 16911 |
elsif Is_Access_Type (Etype (Prefix (Object))) then |
| 16912 |
return False; |
| 16913 |
|
| 16914 |
else |
| 16915 |
return |
| 16916 |
Is_Dependent_Component_Of_Mutable_Object (Prefix (Object)); |
| 16917 |
end if; |
| 16918 |
|
| 16919 |
elsif Nkind (Object) = N_Indexed_Component |
| 16920 |
or else Nkind (Object) = N_Slice |
| 16921 |
then |
| 16922 |
return Is_Dependent_Component_Of_Mutable_Object |
| 16923 |
(Original_Node (Prefix (Object))); |
| 16924 |
|
| 16925 |
-- A type conversion that Is_Variable is a view conversion: |
| 16926 |
-- go back to the denoted object. |
| 16927 |
|
| 16928 |
elsif Nkind (Object) = N_Type_Conversion then |
| 16929 |
return |
| 16930 |
Is_Dependent_Component_Of_Mutable_Object |
| 16931 |
(Original_Node (Expression (Object))); |
| 16932 |
end if; |
| 16933 |
end if; |
| 16934 |
|
| 16935 |
return False; |
| 16936 |
end Is_Dependent_Component_Of_Mutable_Object; |
| 16937 |
|
| 16938 |
--------------------- |
| 16939 |
-- Is_Dereferenced -- |
| 16940 |
--------------------- |
| 16941 |
|
| 16942 |
function Is_Dereferenced (N : Node_Id) return Boolean is |
| 16943 |
P : constant Node_Id := Parent (N); |
| 16944 |
begin |
| 16945 |
return Nkind (P) in N_Selected_Component |
| 16946 |
| N_Explicit_Dereference |
| 16947 |
| N_Indexed_Component |
| 16948 |
| N_Slice |
| 16949 |
and then Prefix (P) = N; |
| 16950 |
end Is_Dereferenced; |
| 16951 |
|
| 16952 |
---------------------- |
| 16953 |
-- Is_Descendant_Of -- |
| 16954 |
---------------------- |
| 16955 |
|
| 16956 |
function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is |
| 16957 |
T : Entity_Id; |
| 16958 |
Etyp : Entity_Id; |
| 16959 |
|
| 16960 |
begin |
| 16961 |
pragma Assert (Nkind (T1) in N_Entity); |
| 16962 |
pragma Assert (Nkind (T2) in N_Entity); |
| 16963 |
|
| 16964 |
T := Base_Type (T1); |
| 16965 |
|
| 16966 |
-- Immediate return if the types match |
| 16967 |
|
| 16968 |
if T = T2 then |
| 16969 |
return True; |
| 16970 |
|
| 16971 |
-- Comment needed here ??? |
| 16972 |
|
| 16973 |
elsif Ekind (T) = E_Class_Wide_Type then |
| 16974 |
return Etype (T) = T2; |
| 16975 |
|
| 16976 |
-- All other cases |
| 16977 |
|
| 16978 |
else |
| 16979 |
loop |
| 16980 |
Etyp := Etype (T); |
| 16981 |
|
| 16982 |
-- Done if we found the type we are looking for |
| 16983 |
|
| 16984 |
if Etyp = T2 then |
| 16985 |
return True; |
| 16986 |
|
| 16987 |
-- Done if no more derivations to check |
| 16988 |
|
| 16989 |
elsif T = T1 |
| 16990 |
or else T = Etyp |
| 16991 |
then |
| 16992 |
return False; |
| 16993 |
|
| 16994 |
-- Following test catches error cases resulting from prev errors |
| 16995 |
|
| 16996 |
elsif No (Etyp) then |
| 16997 |
return False; |
| 16998 |
|
| 16999 |
elsif Is_Private_Type (T) and then Etyp = Full_View (T) then |
| 17000 |
return False; |
| 17001 |
|
| 17002 |
elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then |
| 17003 |
return False; |
| 17004 |
end if; |
| 17005 |
|
| 17006 |
T := Base_Type (Etyp); |
| 17007 |
end loop; |
| 17008 |
end if; |
| 17009 |
end Is_Descendant_Of; |
| 17010 |
|
| 17011 |
---------------------------------------- |
| 17012 |
-- Is_Descendant_Of_Suspension_Object -- |
| 17013 |
---------------------------------------- |
| 17014 |
|
| 17015 |
function Is_Descendant_Of_Suspension_Object |
| 17016 |
(Typ : Entity_Id) return Boolean |
| 17017 |
is |
| 17018 |
Cur_Typ : Entity_Id; |
| 17019 |
Par_Typ : Entity_Id; |
| 17020 |
|
| 17021 |
begin |
| 17022 |
-- Climb the type derivation chain checking each parent type against |
| 17023 |
-- Suspension_Object. |
| 17024 |
|
| 17025 |
Cur_Typ := Base_Type (Typ); |
| 17026 |
while Present (Cur_Typ) loop |
| 17027 |
Par_Typ := Etype (Cur_Typ); |
| 17028 |
|
| 17029 |
-- The current type is a match |
| 17030 |
|
| 17031 |
if Is_RTE (Cur_Typ, RE_Suspension_Object) then |
| 17032 |
return True; |
| 17033 |
|
| 17034 |
-- Stop the traversal once the root of the derivation chain has been |
| 17035 |
-- reached. In that case the current type is its own base type. |
| 17036 |
|
| 17037 |
elsif Cur_Typ = Par_Typ then |
| 17038 |
exit; |
| 17039 |
end if; |
| 17040 |
|
| 17041 |
Cur_Typ := Base_Type (Par_Typ); |
| 17042 |
end loop; |
| 17043 |
|
| 17044 |
return False; |
| 17045 |
end Is_Descendant_Of_Suspension_Object; |
| 17046 |
|
| 17047 |
--------------------------------------------- |
| 17048 |
-- Is_Double_Precision_Floating_Point_Type -- |
| 17049 |
--------------------------------------------- |
| 17050 |
|
| 17051 |
function Is_Double_Precision_Floating_Point_Type |
| 17052 |
(E : Entity_Id) return Boolean is |
| 17053 |
begin |
| 17054 |
return Is_Floating_Point_Type (E) |
| 17055 |
and then Machine_Radix_Value (E) = Uint_2 |
| 17056 |
and then Machine_Mantissa_Value (E) = UI_From_Int (53) |
| 17057 |
and then Machine_Emax_Value (E) = Uint_2 ** Uint_10 |
| 17058 |
and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10); |
| 17059 |
end Is_Double_Precision_Floating_Point_Type; |
| 17060 |
|
| 17061 |
----------------------------- |
| 17062 |
-- Is_Effectively_Volatile -- |
| 17063 |
----------------------------- |
| 17064 |
|
| 17065 |
function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is |
| 17066 |
Comp : Entity_Id; |
| 17067 |
Has_Vol_Comp : Boolean := False; |
| 17068 |
begin |
| 17069 |
if Is_Type (Id) then |
| 17070 |
|
| 17071 |
-- An arbitrary type is effectively volatile when it is subject to |
| 17072 |
-- pragma Atomic or Volatile, unless No_Caching is enabled. |
| 17073 |
|
| 17074 |
if Is_Volatile (Id) |
| 17075 |
and then not No_Caching_Enabled (Id) |
| 17076 |
then |
| 17077 |
return True; |
| 17078 |
|
| 17079 |
-- An array type is effectively volatile when it is subject to pragma |
| 17080 |
-- Atomic_Components or Volatile_Components or its component type is |
| 17081 |
-- effectively volatile. |
| 17082 |
|
| 17083 |
elsif Is_Array_Type (Id) then |
| 17084 |
if Has_Volatile_Components (Id) then |
| 17085 |
return True; |
| 17086 |
else |
| 17087 |
declare |
| 17088 |
Anc : Entity_Id := Base_Type (Id); |
| 17089 |
begin |
| 17090 |
if Is_Private_Type (Anc) then |
| 17091 |
Anc := Full_View (Anc); |
| 17092 |
end if; |
| 17093 |
|
| 17094 |
-- Test for presence of ancestor, as the full view of a |
| 17095 |
-- private type may be missing in case of error. |
| 17096 |
|
| 17097 |
return Present (Anc) |
| 17098 |
and then Is_Effectively_Volatile (Component_Type (Anc)); |
| 17099 |
end; |
| 17100 |
end if; |
| 17101 |
|
| 17102 |
-- A protected type is always volatile |
| 17103 |
|
| 17104 |
elsif Is_Protected_Type (Id) then |
| 17105 |
return True; |
| 17106 |
|
| 17107 |
-- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is |
| 17108 |
-- automatically volatile. |
| 17109 |
|
| 17110 |
elsif Is_Descendant_Of_Suspension_Object (Id) then |
| 17111 |
return True; |
| 17112 |
|
| 17113 |
-- A record type for which all components have an effectively |
| 17114 |
-- volatile type. |
| 17115 |
|
| 17116 |
elsif Is_Record_Type (Id) then |
| 17117 |
|
| 17118 |
-- Inspect all components defined in the scope of the type, |
| 17119 |
-- looking for those whose type is not effecively volatile. |
| 17120 |
|
| 17121 |
Comp := First_Component (Id); |
| 17122 |
while Present (Comp) loop |
| 17123 |
if Comes_From_Source (Comp) then |
| 17124 |
if Is_Effectively_Volatile (Etype (Comp)) then |
| 17125 |
Has_Vol_Comp := True; |
| 17126 |
|
| 17127 |
-- The component is not effecively volatile |
| 17128 |
|
| 17129 |
else |
| 17130 |
return False; |
| 17131 |
end if; |
| 17132 |
end if; |
| 17133 |
|
| 17134 |
Next_Component (Comp); |
| 17135 |
end loop; |
| 17136 |
|
| 17137 |
-- If we get here, then all components are of an effectively |
| 17138 |
-- volatile type. |
| 17139 |
|
| 17140 |
return Has_Vol_Comp; |
| 17141 |
|
| 17142 |
-- Otherwise the type is not effectively volatile |
| 17143 |
|
| 17144 |
else |
| 17145 |
return False; |
| 17146 |
end if; |
| 17147 |
|
| 17148 |
-- Otherwise Id denotes an object |
| 17149 |
|
| 17150 |
else pragma Assert (Is_Object (Id)); |
| 17151 |
-- A volatile object for which No_Caching is enabled is not |
| 17152 |
-- effectively volatile. |
| 17153 |
|
| 17154 |
return |
| 17155 |
(Is_Volatile (Id) |
| 17156 |
and then not |
| 17157 |
(Ekind (Id) = E_Variable and then No_Caching_Enabled (Id))) |
| 17158 |
or else Has_Volatile_Components (Id) |
| 17159 |
or else Is_Effectively_Volatile (Etype (Id)); |
| 17160 |
end if; |
| 17161 |
end Is_Effectively_Volatile; |
| 17162 |
|
| 17163 |
----------------------------------------- |
| 17164 |
-- Is_Effectively_Volatile_For_Reading -- |
| 17165 |
----------------------------------------- |
| 17166 |
|
| 17167 |
function Is_Effectively_Volatile_For_Reading |
| 17168 |
(Id : Entity_Id) return Boolean |
| 17169 |
is |
| 17170 |
Comp : Entity_Id; |
| 17171 |
begin |
| 17172 |
-- A concurrent type is effectively volatile for reading |
| 17173 |
|
| 17174 |
if Is_Concurrent_Type (Id) then |
| 17175 |
return True; |
| 17176 |
|
| 17177 |
elsif Is_Effectively_Volatile (Id) then |
| 17178 |
|
| 17179 |
-- Other volatile types and objects are effectively volatile for |
| 17180 |
-- reading when they have property Async_Writers or Effective_Reads |
| 17181 |
-- set to True. This includes the case of an array type whose |
| 17182 |
-- Volatile_Components aspect is True (hence it is effectively |
| 17183 |
-- volatile) which does not have the properties Async_Writers |
| 17184 |
-- and Effective_Reads set to False. |
| 17185 |
|
| 17186 |
if Async_Writers_Enabled (Id) |
| 17187 |
or else Effective_Reads_Enabled (Id) |
| 17188 |
then |
| 17189 |
return True; |
| 17190 |
|
| 17191 |
-- In addition, an array type is effectively volatile for reading |
| 17192 |
-- when its component type is effectively volatile for reading. |
| 17193 |
|
| 17194 |
elsif Is_Array_Type (Id) then |
| 17195 |
declare |
| 17196 |
Anc : Entity_Id := Base_Type (Id); |
| 17197 |
begin |
| 17198 |
if Is_Private_Type (Anc) then |
| 17199 |
Anc := Full_View (Anc); |
| 17200 |
end if; |
| 17201 |
|
| 17202 |
-- Test for presence of ancestor, as the full view of a |
| 17203 |
-- private type may be missing in case of error. |
| 17204 |
|
| 17205 |
return Present (Anc) |
| 17206 |
and then Is_Effectively_Volatile_For_Reading |
| 17207 |
(Component_Type (Anc)); |
| 17208 |
end; |
| 17209 |
|
| 17210 |
-- In addition, a record type is effectively volatile for reading |
| 17211 |
-- if at least one component has an effectively volatile type for |
| 17212 |
-- reading. |
| 17213 |
|
| 17214 |
elsif Is_Record_Type (Id) then |
| 17215 |
Comp := First_Component (Id); |
| 17216 |
while Present (Comp) loop |
| 17217 |
if Comes_From_Source (Comp) |
| 17218 |
and then Is_Effectively_Volatile_For_Reading (Etype (Comp)) |
| 17219 |
then |
| 17220 |
return True; |
| 17221 |
end if; |
| 17222 |
Next_Component (Comp); |
| 17223 |
end loop; |
| 17224 |
|
| 17225 |
return False; |
| 17226 |
end if; |
| 17227 |
end if; |
| 17228 |
|
| 17229 |
return False; |
| 17230 |
|
| 17231 |
end Is_Effectively_Volatile_For_Reading; |
| 17232 |
|
| 17233 |
------------------------------------ |
| 17234 |
-- Is_Effectively_Volatile_Object -- |
| 17235 |
------------------------------------ |
| 17236 |
|
| 17237 |
function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is |
| 17238 |
function Is_Effectively_Volatile_Object_Inst |
| 17239 |
is new Is_Effectively_Volatile_Object_Shared (Is_Effectively_Volatile); |
| 17240 |
begin |
| 17241 |
return Is_Effectively_Volatile_Object_Inst (N); |
| 17242 |
end Is_Effectively_Volatile_Object; |
| 17243 |
|
| 17244 |
------------------------------------------------ |
| 17245 |
-- Is_Effectively_Volatile_Object_For_Reading -- |
| 17246 |
------------------------------------------------ |
| 17247 |
|
| 17248 |
function Is_Effectively_Volatile_Object_For_Reading |
| 17249 |
(N : Node_Id) return Boolean |
| 17250 |
is |
| 17251 |
function Is_Effectively_Volatile_Object_For_Reading_Inst |
| 17252 |
is new Is_Effectively_Volatile_Object_Shared |
| 17253 |
(Is_Effectively_Volatile_For_Reading); |
| 17254 |
begin |
| 17255 |
return Is_Effectively_Volatile_Object_For_Reading_Inst (N); |
| 17256 |
end Is_Effectively_Volatile_Object_For_Reading; |
| 17257 |
|
| 17258 |
------------------------------------------- |
| 17259 |
-- Is_Effectively_Volatile_Object_Shared -- |
| 17260 |
------------------------------------------- |
| 17261 |
|
| 17262 |
function Is_Effectively_Volatile_Object_Shared |
| 17263 |
(N : Node_Id) return Boolean |
| 17264 |
is |
| 17265 |
begin |
| 17266 |
if Is_Entity_Name (N) then |
| 17267 |
return Is_Object (Entity (N)) |
| 17268 |
and then Is_Effectively_Volatile_Entity (Entity (N)); |
| 17269 |
|
| 17270 |
elsif Nkind (N) in N_Indexed_Component | N_Slice then |
| 17271 |
return Is_Effectively_Volatile_Object_Shared (Prefix (N)); |
| 17272 |
|
| 17273 |
elsif Nkind (N) = N_Selected_Component then |
| 17274 |
return |
| 17275 |
Is_Effectively_Volatile_Object_Shared (Prefix (N)) |
| 17276 |
or else |
| 17277 |
Is_Effectively_Volatile_Object_Shared (Selector_Name (N)); |
| 17278 |
|
| 17279 |
elsif Nkind (N) in N_Qualified_Expression |
| 17280 |
| N_Unchecked_Type_Conversion |
| 17281 |
| N_Type_Conversion |
| 17282 |
then |
| 17283 |
return Is_Effectively_Volatile_Object_Shared (Expression (N)); |
| 17284 |
|
| 17285 |
else |
| 17286 |
return False; |
| 17287 |
end if; |
| 17288 |
end Is_Effectively_Volatile_Object_Shared; |
| 17289 |
|
| 17290 |
---------------------------------------- |
| 17291 |
-- Is_Entity_Of_Quantified_Expression -- |
| 17292 |
---------------------------------------- |
| 17293 |
|
| 17294 |
function Is_Entity_Of_Quantified_Expression (Id : Entity_Id) return Boolean |
| 17295 |
is |
| 17296 |
Par : constant Node_Id := Parent (Id); |
| 17297 |
|
| 17298 |
begin |
| 17299 |
return (Nkind (Par) = N_Loop_Parameter_Specification |
| 17300 |
or else Nkind (Par) = N_Iterator_Specification) |
| 17301 |
and then Defining_Identifier (Par) = Id |
| 17302 |
and then Nkind (Parent (Par)) = N_Quantified_Expression; |
| 17303 |
end Is_Entity_Of_Quantified_Expression; |
| 17304 |
|
| 17305 |
------------------- |
| 17306 |
-- Is_Entry_Body -- |
| 17307 |
------------------- |
| 17308 |
|
| 17309 |
function Is_Entry_Body (Id : Entity_Id) return Boolean is |
| 17310 |
begin |
| 17311 |
return |
| 17312 |
Is_Entry (Id) |
| 17313 |
and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body; |
| 17314 |
end Is_Entry_Body; |
| 17315 |
|
| 17316 |
-------------------------- |
| 17317 |
-- Is_Entry_Declaration -- |
| 17318 |
-------------------------- |
| 17319 |
|
| 17320 |
function Is_Entry_Declaration (Id : Entity_Id) return Boolean is |
| 17321 |
begin |
| 17322 |
return |
| 17323 |
Is_Entry (Id) |
| 17324 |
and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration; |
| 17325 |
end Is_Entry_Declaration; |
| 17326 |
|
| 17327 |
------------------------------------ |
| 17328 |
-- Is_Expanded_Priority_Attribute -- |
| 17329 |
------------------------------------ |
| 17330 |
|
| 17331 |
function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is |
| 17332 |
begin |
| 17333 |
return |
| 17334 |
Nkind (E) = N_Function_Call |
| 17335 |
and then not Configurable_Run_Time_Mode |
| 17336 |
and then Nkind (Original_Node (E)) = N_Attribute_Reference |
| 17337 |
and then (Is_RTE (Entity (Name (E)), RE_Get_Ceiling) |
| 17338 |
or else Is_RTE (Entity (Name (E)), RO_PE_Get_Ceiling)); |
| 17339 |
end Is_Expanded_Priority_Attribute; |
| 17340 |
|
| 17341 |
---------------------------- |
| 17342 |
-- Is_Expression_Function -- |
| 17343 |
---------------------------- |
| 17344 |
|
| 17345 |
function Is_Expression_Function (Subp : Entity_Id) return Boolean is |
| 17346 |
begin |
| 17347 |
if Ekind (Subp) in E_Function | E_Subprogram_Body then |
| 17348 |
return |
| 17349 |
Nkind (Original_Node (Unit_Declaration_Node (Subp))) = |
| 17350 |
N_Expression_Function; |
| 17351 |
else |
| 17352 |
return False; |
| 17353 |
end if; |
| 17354 |
end Is_Expression_Function; |
| 17355 |
|
| 17356 |
------------------------------------------ |
| 17357 |
-- Is_Expression_Function_Or_Completion -- |
| 17358 |
------------------------------------------ |
| 17359 |
|
| 17360 |
function Is_Expression_Function_Or_Completion |
| 17361 |
(Subp : Entity_Id) return Boolean |
| 17362 |
is |
| 17363 |
Subp_Decl : Node_Id; |
| 17364 |
|
| 17365 |
begin |
| 17366 |
if Ekind (Subp) = E_Function then |
| 17367 |
Subp_Decl := Unit_Declaration_Node (Subp); |
| 17368 |
|
| 17369 |
-- The function declaration is either an expression function or is |
| 17370 |
-- completed by an expression function body. |
| 17371 |
|
| 17372 |
return |
| 17373 |
Is_Expression_Function (Subp) |
| 17374 |
or else (Nkind (Subp_Decl) = N_Subprogram_Declaration |
| 17375 |
and then Present (Corresponding_Body (Subp_Decl)) |
| 17376 |
and then Is_Expression_Function |
| 17377 |
(Corresponding_Body (Subp_Decl))); |
| 17378 |
|
| 17379 |
elsif Ekind (Subp) = E_Subprogram_Body then |
| 17380 |
return Is_Expression_Function (Subp); |
| 17381 |
|
| 17382 |
else |
| 17383 |
return False; |
| 17384 |
end if; |
| 17385 |
end Is_Expression_Function_Or_Completion; |
| 17386 |
|
| 17387 |
----------------------------------------------- |
| 17388 |
-- Is_Extended_Precision_Floating_Point_Type -- |
| 17389 |
----------------------------------------------- |
| 17390 |
|
| 17391 |
function Is_Extended_Precision_Floating_Point_Type |
| 17392 |
(E : Entity_Id) return Boolean is |
| 17393 |
begin |
| 17394 |
return Is_Floating_Point_Type (E) |
| 17395 |
and then Machine_Radix_Value (E) = Uint_2 |
| 17396 |
and then Machine_Mantissa_Value (E) = Uint_64 |
| 17397 |
and then Machine_Emax_Value (E) = Uint_2 ** Uint_14 |
| 17398 |
and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_14); |
| 17399 |
end Is_Extended_Precision_Floating_Point_Type; |
| 17400 |
|
| 17401 |
----------------------- |
| 17402 |
-- Is_EVF_Expression -- |
| 17403 |
----------------------- |
| 17404 |
|
| 17405 |
function Is_EVF_Expression (N : Node_Id) return Boolean is |
| 17406 |
Orig_N : constant Node_Id := Original_Node (N); |
| 17407 |
Alt : Node_Id; |
| 17408 |
Expr : Node_Id; |
| 17409 |
Id : Entity_Id; |
| 17410 |
|
| 17411 |
begin |
| 17412 |
-- Detect a reference to a formal parameter of a specific tagged type |
| 17413 |
-- whose related subprogram is subject to pragma Expresions_Visible with |
| 17414 |
-- value "False". |
| 17415 |
|
| 17416 |
if Is_Entity_Name (N) and then Present (Entity (N)) then |
| 17417 |
Id := Entity (N); |
| 17418 |
|
| 17419 |
return |
| 17420 |
Is_Formal (Id) |
| 17421 |
and then Is_Specific_Tagged_Type (Etype (Id)) |
| 17422 |
and then Extensions_Visible_Status (Id) = |
| 17423 |
Extensions_Visible_False; |
| 17424 |
|
| 17425 |
-- A case expression is an EVF expression when it contains at least one |
| 17426 |
-- EVF dependent_expression. Note that a case expression may have been |
| 17427 |
-- expanded, hence the use of Original_Node. |
| 17428 |
|
| 17429 |
elsif Nkind (Orig_N) = N_Case_Expression then |
| 17430 |
Alt := First (Alternatives (Orig_N)); |
| 17431 |
while Present (Alt) loop |
| 17432 |
if Is_EVF_Expression (Expression (Alt)) then |
| 17433 |
return True; |
| 17434 |
end if; |
| 17435 |
|
| 17436 |
Next (Alt); |
| 17437 |
end loop; |
| 17438 |
|
| 17439 |
-- An if expression is an EVF expression when it contains at least one |
| 17440 |
-- EVF dependent_expression. Note that an if expression may have been |
| 17441 |
-- expanded, hence the use of Original_Node. |
| 17442 |
|
| 17443 |
elsif Nkind (Orig_N) = N_If_Expression then |
| 17444 |
Expr := Next (First (Expressions (Orig_N))); |
| 17445 |
while Present (Expr) loop |
| 17446 |
if Is_EVF_Expression (Expr) then |
| 17447 |
return True; |
| 17448 |
end if; |
| 17449 |
|
| 17450 |
Next (Expr); |
| 17451 |
end loop; |
| 17452 |
|
| 17453 |
-- A qualified expression or a type conversion is an EVF expression when |
| 17454 |
-- its operand is an EVF expression. |
| 17455 |
|
| 17456 |
elsif Nkind (N) in N_Qualified_Expression |
| 17457 |
| N_Unchecked_Type_Conversion |
| 17458 |
| N_Type_Conversion |
| 17459 |
then |
| 17460 |
return Is_EVF_Expression (Expression (N)); |
| 17461 |
|
| 17462 |
-- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when |
| 17463 |
-- their prefix denotes an EVF expression. |
| 17464 |
|
| 17465 |
elsif Nkind (N) = N_Attribute_Reference |
| 17466 |
and then Attribute_Name (N) in Name_Loop_Entry |
| 17467 |
| Name_Old |
| 17468 |
| Name_Update |
| 17469 |
then |
| 17470 |
return Is_EVF_Expression (Prefix (N)); |
| 17471 |
end if; |
| 17472 |
|
| 17473 |
return False; |
| 17474 |
end Is_EVF_Expression; |
| 17475 |
|
| 17476 |
-------------- |
| 17477 |
-- Is_False -- |
| 17478 |
-------------- |
| 17479 |
|
| 17480 |
function Is_False (U : Opt_Ubool) return Boolean is |
| 17481 |
begin |
| 17482 |
return not Is_True (U); |
| 17483 |
end Is_False; |
| 17484 |
|
| 17485 |
--------------------------- |
| 17486 |
-- Is_Fixed_Model_Number -- |
| 17487 |
--------------------------- |
| 17488 |
|
| 17489 |
function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is |
| 17490 |
S : constant Ureal := Small_Value (T); |
| 17491 |
M : Urealp.Save_Mark; |
| 17492 |
R : Boolean; |
| 17493 |
|
| 17494 |
begin |
| 17495 |
M := Urealp.Mark; |
| 17496 |
R := (U = UR_Trunc (U / S) * S); |
| 17497 |
Urealp.Release (M); |
| 17498 |
return R; |
| 17499 |
end Is_Fixed_Model_Number; |
| 17500 |
|
| 17501 |
----------------------------- |
| 17502 |
-- Is_Full_Access_Object -- |
| 17503 |
----------------------------- |
| 17504 |
|
| 17505 |
function Is_Full_Access_Object (N : Node_Id) return Boolean is |
| 17506 |
begin |
| 17507 |
return Is_Atomic_Object (N) |
| 17508 |
or else Is_Volatile_Full_Access_Object_Ref (N); |
| 17509 |
end Is_Full_Access_Object; |
| 17510 |
|
| 17511 |
------------------------------- |
| 17512 |
-- Is_Fully_Initialized_Type -- |
| 17513 |
------------------------------- |
| 17514 |
|
| 17515 |
function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is |
| 17516 |
begin |
| 17517 |
-- Scalar types |
| 17518 |
|
| 17519 |
if Is_Scalar_Type (Typ) then |
| 17520 |
|
| 17521 |
-- A scalar type with an aspect Default_Value is fully initialized |
| 17522 |
|
| 17523 |
-- Note: Iniitalize/Normalize_Scalars also ensure full initialization |
| 17524 |
-- of a scalar type, but we don't take that into account here, since |
| 17525 |
-- we don't want these to affect warnings. |
| 17526 |
|
| 17527 |
return Has_Default_Aspect (Typ); |
| 17528 |
|
| 17529 |
elsif Is_Access_Type (Typ) then |
| 17530 |
return True; |
| 17531 |
|
| 17532 |
elsif Is_Array_Type (Typ) then |
| 17533 |
if Is_Fully_Initialized_Type (Component_Type (Typ)) |
| 17534 |
or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ)) |
| 17535 |
then |
| 17536 |
return True; |
| 17537 |
end if; |
| 17538 |
|
| 17539 |
-- An interesting case, if we have a constrained type one of whose |
| 17540 |
-- bounds is known to be null, then there are no elements to be |
| 17541 |
-- initialized, so all the elements are initialized. |
| 17542 |
|
| 17543 |
if Is_Constrained (Typ) then |
| 17544 |
declare |
| 17545 |
Indx : Node_Id; |
| 17546 |
Indx_Typ : Entity_Id; |
| 17547 |
Lbd, Hbd : Node_Id; |
| 17548 |
|
| 17549 |
begin |
| 17550 |
Indx := First_Index (Typ); |
| 17551 |
while Present (Indx) loop |
| 17552 |
if Etype (Indx) = Any_Type then |
| 17553 |
return False; |
| 17554 |
|
| 17555 |
-- If index is a range, use directly |
| 17556 |
|
| 17557 |
elsif Nkind (Indx) = N_Range then |
| 17558 |
Lbd := Low_Bound (Indx); |
| 17559 |
Hbd := High_Bound (Indx); |
| 17560 |
|
| 17561 |
else |
| 17562 |
Indx_Typ := Etype (Indx); |
| 17563 |
|
| 17564 |
if Is_Private_Type (Indx_Typ) then |
| 17565 |
Indx_Typ := Full_View (Indx_Typ); |
| 17566 |
end if; |
| 17567 |
|
| 17568 |
if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then |
| 17569 |
return False; |
| 17570 |
else |
| 17571 |
Lbd := Type_Low_Bound (Indx_Typ); |
| 17572 |
Hbd := Type_High_Bound (Indx_Typ); |
| 17573 |
end if; |
| 17574 |
end if; |
| 17575 |
|
| 17576 |
if Compile_Time_Known_Value (Lbd) |
| 17577 |
and then |
| 17578 |
Compile_Time_Known_Value (Hbd) |
| 17579 |
then |
| 17580 |
if Expr_Value (Hbd) < Expr_Value (Lbd) then |
| 17581 |
return True; |
| 17582 |
end if; |
| 17583 |
end if; |
| 17584 |
|
| 17585 |
Next_Index (Indx); |
| 17586 |
end loop; |
| 17587 |
end; |
| 17588 |
end if; |
| 17589 |
|
| 17590 |
-- If no null indexes, then type is not fully initialized |
| 17591 |
|
| 17592 |
return False; |
| 17593 |
|
| 17594 |
-- Record types |
| 17595 |
|
| 17596 |
elsif Is_Record_Type (Typ) then |
| 17597 |
-- Mutably tagged types get default initialized to their parent |
| 17598 |
-- subtype's default values. |
| 17599 |
|
| 17600 |
if Is_Mutably_Tagged_CW_Equivalent_Type (Typ) then |
| 17601 |
return True; |
| 17602 |
end if; |
| 17603 |
|
| 17604 |
if Has_Defaulted_Discriminants (Typ) |
| 17605 |
and then Is_Fully_Initialized_Variant (Typ) |
| 17606 |
then |
| 17607 |
return True; |
| 17608 |
end if; |
| 17609 |
|
| 17610 |
-- We consider bounded string types to be fully initialized, because |
| 17611 |
-- otherwise we get false alarms when the Data component is not |
| 17612 |
-- default-initialized. |
| 17613 |
|
| 17614 |
if Is_Bounded_String (Typ) then |
| 17615 |
return True; |
| 17616 |
end if; |
| 17617 |
|
| 17618 |
-- Controlled records are considered to be fully initialized if |
| 17619 |
-- there is a user defined Initialize routine. This may not be |
| 17620 |
-- entirely correct, but as the spec notes, we are guessing here |
| 17621 |
-- what is best from the point of view of issuing warnings. |
| 17622 |
|
| 17623 |
if Is_Controlled (Typ) then |
| 17624 |
declare |
| 17625 |
Utyp : constant Entity_Id := Underlying_Type (Typ); |
| 17626 |
|
| 17627 |
begin |
| 17628 |
if Present (Utyp) then |
| 17629 |
declare |
| 17630 |
Init : constant Entity_Id := |
| 17631 |
Find_Controlled_Prim_Op (Utyp, Name_Initialize); |
| 17632 |
|
| 17633 |
begin |
| 17634 |
if Present (Init) |
| 17635 |
and then Comes_From_Source (Init) |
| 17636 |
and then not In_Predefined_Unit (Init) |
| 17637 |
then |
| 17638 |
return True; |
| 17639 |
|
| 17640 |
elsif Is_Tagged_Type (Typ) |
| 17641 |
and then Is_Derived_Type (Typ) |
| 17642 |
and then Has_Null_Extension (Typ) |
| 17643 |
and then |
| 17644 |
Is_Fully_Initialized_Type (Etype (Base_Type (Typ))) |
| 17645 |
then |
| 17646 |
return True; |
| 17647 |
end if; |
| 17648 |
end; |
| 17649 |
end if; |
| 17650 |
end; |
| 17651 |
end if; |
| 17652 |
|
| 17653 |
-- Otherwise see if all record components are initialized |
| 17654 |
|
| 17655 |
declare |
| 17656 |
Comp : Entity_Id; |
| 17657 |
|
| 17658 |
begin |
| 17659 |
Comp := First_Component (Typ); |
| 17660 |
while Present (Comp) loop |
| 17661 |
if (No (Parent (Comp)) |
| 17662 |
or else No (Expression (Parent (Comp)))) |
| 17663 |
and then not Is_Fully_Initialized_Type (Etype (Comp)) |
| 17664 |
|
| 17665 |
-- Special VM case for tag components, which need to be |
| 17666 |
-- defined in this case, but are never initialized as VMs |
| 17667 |
-- are using other dispatching mechanisms. Ignore this |
| 17668 |
-- uninitialized case. Note that this applies both to the |
| 17669 |
-- uTag entry and the main vtable pointer (CPP_Class case). |
| 17670 |
|
| 17671 |
and then (Tagged_Type_Expansion or else not Is_Tag (Comp)) |
| 17672 |
then |
| 17673 |
return False; |
| 17674 |
end if; |
| 17675 |
|
| 17676 |
Next_Component (Comp); |
| 17677 |
end loop; |
| 17678 |
end; |
| 17679 |
|
| 17680 |
-- No uninitialized components, so type is fully initialized. |
| 17681 |
-- Note that this catches the case of no components as well. |
| 17682 |
|
| 17683 |
return True; |
| 17684 |
|
| 17685 |
elsif Is_Concurrent_Type (Typ) then |
| 17686 |
return True; |
| 17687 |
|
| 17688 |
elsif Is_Private_Type (Typ) then |
| 17689 |
declare |
| 17690 |
U : constant Entity_Id := Underlying_Type (Typ); |
| 17691 |
|
| 17692 |
begin |
| 17693 |
if No (U) then |
| 17694 |
return False; |
| 17695 |
else |
| 17696 |
return Is_Fully_Initialized_Type (U); |
| 17697 |
end if; |
| 17698 |
end; |
| 17699 |
|
| 17700 |
else |
| 17701 |
return False; |
| 17702 |
end if; |
| 17703 |
end Is_Fully_Initialized_Type; |
| 17704 |
|
| 17705 |
---------------------------------- |
| 17706 |
-- Is_Fully_Initialized_Variant -- |
| 17707 |
---------------------------------- |
| 17708 |
|
| 17709 |
function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is |
| 17710 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 17711 |
Constraints : constant List_Id := New_List; |
| 17712 |
Components : constant Elist_Id := New_Elmt_List; |
| 17713 |
Comp_Elmt : Elmt_Id; |
| 17714 |
Comp_Id : Node_Id; |
| 17715 |
Comp_List : Node_Id; |
| 17716 |
Discr : Entity_Id; |
| 17717 |
Discr_Val : Node_Id; |
| 17718 |
|
| 17719 |
Report_Errors : Boolean; |
| 17720 |
pragma Warnings (Off, Report_Errors); |
| 17721 |
|
| 17722 |
begin |
| 17723 |
if Serious_Errors_Detected > 0 then |
| 17724 |
return False; |
| 17725 |
end if; |
| 17726 |
|
| 17727 |
if Is_Record_Type (Typ) |
| 17728 |
and then Nkind (Parent (Typ)) = N_Full_Type_Declaration |
| 17729 |
and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition |
| 17730 |
then |
| 17731 |
Comp_List := Component_List (Type_Definition (Parent (Typ))); |
| 17732 |
|
| 17733 |
Discr := First_Discriminant (Typ); |
| 17734 |
while Present (Discr) loop |
| 17735 |
if Nkind (Parent (Discr)) = N_Discriminant_Specification then |
| 17736 |
Discr_Val := Expression (Parent (Discr)); |
| 17737 |
|
| 17738 |
if Present (Discr_Val) |
| 17739 |
and then Is_OK_Static_Expression (Discr_Val) |
| 17740 |
then |
| 17741 |
Append_To (Constraints, |
| 17742 |
Make_Component_Association (Loc, |
| 17743 |
Choices => New_List (New_Occurrence_Of (Discr, Loc)), |
| 17744 |
Expression => New_Copy (Discr_Val))); |
| 17745 |
else |
| 17746 |
return False; |
| 17747 |
end if; |
| 17748 |
else |
| 17749 |
return False; |
| 17750 |
end if; |
| 17751 |
|
| 17752 |
Next_Discriminant (Discr); |
| 17753 |
end loop; |
| 17754 |
|
| 17755 |
Gather_Components |
| 17756 |
(Typ => Typ, |
| 17757 |
Comp_List => Comp_List, |
| 17758 |
Governed_By => Constraints, |
| 17759 |
Into => Components, |
| 17760 |
Report_Errors => Report_Errors); |
| 17761 |
|
| 17762 |
-- Check that each component present is fully initialized |
| 17763 |
|
| 17764 |
Comp_Elmt := First_Elmt (Components); |
| 17765 |
while Present (Comp_Elmt) loop |
| 17766 |
Comp_Id := Node (Comp_Elmt); |
| 17767 |
|
| 17768 |
if Ekind (Comp_Id) = E_Component |
| 17769 |
and then (No (Parent (Comp_Id)) |
| 17770 |
or else No (Expression (Parent (Comp_Id)))) |
| 17771 |
and then not Is_Fully_Initialized_Type (Etype (Comp_Id)) |
| 17772 |
then |
| 17773 |
return False; |
| 17774 |
end if; |
| 17775 |
|
| 17776 |
Next_Elmt (Comp_Elmt); |
| 17777 |
end loop; |
| 17778 |
|
| 17779 |
return True; |
| 17780 |
|
| 17781 |
elsif Is_Private_Type (Typ) then |
| 17782 |
declare |
| 17783 |
U : constant Entity_Id := Underlying_Type (Typ); |
| 17784 |
|
| 17785 |
begin |
| 17786 |
if No (U) then |
| 17787 |
return False; |
| 17788 |
else |
| 17789 |
return Is_Fully_Initialized_Variant (U); |
| 17790 |
end if; |
| 17791 |
end; |
| 17792 |
|
| 17793 |
else |
| 17794 |
return False; |
| 17795 |
end if; |
| 17796 |
end Is_Fully_Initialized_Variant; |
| 17797 |
|
| 17798 |
----------------------------------- |
| 17799 |
-- Is_Function_With_Side_Effects -- |
| 17800 |
----------------------------------- |
| 17801 |
|
| 17802 |
function Is_Function_With_Side_Effects (Subp : Entity_Id) return Boolean is |
| 17803 |
Arg : Node_Id; |
| 17804 |
Expr : Node_Id; |
| 17805 |
Prag : constant Node_Id := Get_Pragma (Subp, Pragma_Side_Effects); |
| 17806 |
|
| 17807 |
begin |
| 17808 |
-- Extract the value from the Boolean expression (if any) |
| 17809 |
|
| 17810 |
if Present (Prag) then |
| 17811 |
Arg := First (Pragma_Argument_Associations (Prag)); |
| 17812 |
|
| 17813 |
if Present (Arg) then |
| 17814 |
Expr := Get_Pragma_Arg (Arg); |
| 17815 |
|
| 17816 |
return Is_True (Expr_Value (Expr)); |
| 17817 |
|
| 17818 |
-- Otherwise the aspect or pragma defaults to True |
| 17819 |
|
| 17820 |
else |
| 17821 |
return True; |
| 17822 |
end if; |
| 17823 |
end if; |
| 17824 |
|
| 17825 |
return False; |
| 17826 |
end Is_Function_With_Side_Effects; |
| 17827 |
|
| 17828 |
------------------------------------ |
| 17829 |
-- Is_Generic_Declaration_Or_Body -- |
| 17830 |
------------------------------------ |
| 17831 |
|
| 17832 |
function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is |
| 17833 |
Spec_Decl : Node_Id; |
| 17834 |
|
| 17835 |
begin |
| 17836 |
-- Package/subprogram body |
| 17837 |
|
| 17838 |
if Nkind (Decl) in N_Package_Body | N_Subprogram_Body |
| 17839 |
and then Present (Corresponding_Spec (Decl)) |
| 17840 |
then |
| 17841 |
Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl)); |
| 17842 |
|
| 17843 |
-- Package/subprogram body stub |
| 17844 |
|
| 17845 |
elsif Nkind (Decl) in N_Package_Body_Stub | N_Subprogram_Body_Stub |
| 17846 |
and then Present (Corresponding_Spec_Of_Stub (Decl)) |
| 17847 |
then |
| 17848 |
Spec_Decl := |
| 17849 |
Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl)); |
| 17850 |
|
| 17851 |
-- All other cases |
| 17852 |
|
| 17853 |
else |
| 17854 |
Spec_Decl := Decl; |
| 17855 |
end if; |
| 17856 |
|
| 17857 |
-- Rather than inspecting the defining entity of the spec declaration, |
| 17858 |
-- look at its Nkind. This takes care of the case where the analysis of |
| 17859 |
-- a generic body modifies the Ekind of its spec to allow for recursive |
| 17860 |
-- calls. |
| 17861 |
|
| 17862 |
return Nkind (Spec_Decl) in N_Generic_Declaration; |
| 17863 |
end Is_Generic_Declaration_Or_Body; |
| 17864 |
|
| 17865 |
--------------------------- |
| 17866 |
-- Is_Independent_Object -- |
| 17867 |
--------------------------- |
| 17868 |
|
| 17869 |
function Is_Independent_Object (N : Node_Id) return Boolean is |
| 17870 |
function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean; |
| 17871 |
-- Determine whether arbitrary entity Id denotes an object that is |
| 17872 |
-- Independent. |
| 17873 |
|
| 17874 |
function Prefix_Has_Independent_Components (P : Node_Id) return Boolean; |
| 17875 |
-- Determine whether prefix P has independent components. This requires |
| 17876 |
-- the presence of an Independent_Components aspect/pragma. |
| 17877 |
|
| 17878 |
------------------------------------ |
| 17879 |
-- Is_Independent_Object_Entity -- |
| 17880 |
------------------------------------ |
| 17881 |
|
| 17882 |
function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is |
| 17883 |
begin |
| 17884 |
return |
| 17885 |
Is_Object (Id) |
| 17886 |
and then (Is_Independent (Id) |
| 17887 |
or else |
| 17888 |
Is_Independent (Etype (Id))); |
| 17889 |
end Is_Independent_Object_Entity; |
| 17890 |
|
| 17891 |
------------------------------------- |
| 17892 |
-- Prefix_Has_Independent_Components -- |
| 17893 |
------------------------------------- |
| 17894 |
|
| 17895 |
function Prefix_Has_Independent_Components (P : Node_Id) return Boolean |
| 17896 |
is |
| 17897 |
Typ : constant Entity_Id := Etype (P); |
| 17898 |
|
| 17899 |
begin |
| 17900 |
if Is_Access_Type (Typ) then |
| 17901 |
return Has_Independent_Components (Designated_Type (Typ)); |
| 17902 |
|
| 17903 |
elsif Has_Independent_Components (Typ) then |
| 17904 |
return True; |
| 17905 |
|
| 17906 |
elsif Is_Entity_Name (P) |
| 17907 |
and then Has_Independent_Components (Entity (P)) |
| 17908 |
then |
| 17909 |
return True; |
| 17910 |
|
| 17911 |
else |
| 17912 |
return False; |
| 17913 |
end if; |
| 17914 |
end Prefix_Has_Independent_Components; |
| 17915 |
|
| 17916 |
-- Start of processing for Is_Independent_Object |
| 17917 |
|
| 17918 |
begin |
| 17919 |
if Is_Entity_Name (N) then |
| 17920 |
return Is_Independent_Object_Entity (Entity (N)); |
| 17921 |
|
| 17922 |
elsif Is_Independent (Etype (N)) then |
| 17923 |
return True; |
| 17924 |
|
| 17925 |
elsif Nkind (N) = N_Indexed_Component then |
| 17926 |
return Prefix_Has_Independent_Components (Prefix (N)); |
| 17927 |
|
| 17928 |
elsif Nkind (N) = N_Selected_Component then |
| 17929 |
return Prefix_Has_Independent_Components (Prefix (N)) |
| 17930 |
or else Is_Independent (Entity (Selector_Name (N))); |
| 17931 |
|
| 17932 |
else |
| 17933 |
return False; |
| 17934 |
end if; |
| 17935 |
end Is_Independent_Object; |
| 17936 |
|
| 17937 |
---------------------------- |
| 17938 |
-- Is_Inherited_Operation -- |
| 17939 |
---------------------------- |
| 17940 |
|
| 17941 |
function Is_Inherited_Operation (E : Entity_Id) return Boolean is |
| 17942 |
pragma Assert (Is_Overloadable (E)); |
| 17943 |
Kind : constant Node_Kind := Nkind (Parent (E)); |
| 17944 |
begin |
| 17945 |
return Kind = N_Full_Type_Declaration |
| 17946 |
or else Kind = N_Private_Extension_Declaration |
| 17947 |
or else Kind = N_Subtype_Declaration |
| 17948 |
or else (Ekind (E) = E_Enumeration_Literal |
| 17949 |
and then Is_Derived_Type (Etype (E))); |
| 17950 |
end Is_Inherited_Operation; |
| 17951 |
|
| 17952 |
-------------------------------------- |
| 17953 |
-- Is_Inlinable_Expression_Function -- |
| 17954 |
-------------------------------------- |
| 17955 |
|
| 17956 |
function Is_Inlinable_Expression_Function |
| 17957 |
(Subp : Entity_Id) return Boolean |
| 17958 |
is |
| 17959 |
Return_Expr : Node_Id; |
| 17960 |
|
| 17961 |
begin |
| 17962 |
if Is_Expression_Function_Or_Completion (Subp) |
| 17963 |
and then Has_Pragma_Inline_Always (Subp) |
| 17964 |
and then Needs_No_Actuals (Subp) |
| 17965 |
and then No (Contract (Subp)) |
| 17966 |
and then not Is_Dispatching_Operation (Subp) |
| 17967 |
and then Needs_Finalization (Etype (Subp)) |
| 17968 |
and then not Is_Class_Wide_Type (Etype (Subp)) |
| 17969 |
and then not Has_Invariants (Etype (Subp)) |
| 17970 |
and then Present (Subprogram_Body (Subp)) |
| 17971 |
and then Was_Expression_Function (Subprogram_Body (Subp)) |
| 17972 |
then |
| 17973 |
Return_Expr := Expression_Of_Expression_Function (Subp); |
| 17974 |
|
| 17975 |
-- The returned object must not have a qualified expression and its |
| 17976 |
-- nominal subtype must be statically compatible with the result |
| 17977 |
-- subtype of the expression function. |
| 17978 |
|
| 17979 |
return |
| 17980 |
Nkind (Return_Expr) = N_Identifier |
| 17981 |
and then Etype (Return_Expr) = Etype (Subp); |
| 17982 |
end if; |
| 17983 |
|
| 17984 |
return False; |
| 17985 |
end Is_Inlinable_Expression_Function; |
| 17986 |
|
| 17987 |
----------------------- |
| 17988 |
-- Is_Internal_Block -- |
| 17989 |
----------------------- |
| 17990 |
|
| 17991 |
function Is_Internal_Block (N : Node_Id) return Boolean is |
| 17992 |
begin |
| 17993 |
return Nkind (N) = N_Block_Statement |
| 17994 |
and then Is_Internal (Entity (Identifier (N))); |
| 17995 |
end Is_Internal_Block; |
| 17996 |
|
| 17997 |
----------------- |
| 17998 |
-- Is_Iterator -- |
| 17999 |
----------------- |
| 18000 |
|
| 18001 |
function Is_Iterator (Typ : Entity_Id) return Boolean is |
| 18002 |
function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean; |
| 18003 |
-- Determine whether type Iter_Typ is a predefined forward or reversible |
| 18004 |
-- iterator. |
| 18005 |
|
| 18006 |
---------------------- |
| 18007 |
-- Denotes_Iterator -- |
| 18008 |
---------------------- |
| 18009 |
|
| 18010 |
function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is |
| 18011 |
begin |
| 18012 |
-- Check that the name matches, and that the ultimate ancestor is in |
| 18013 |
-- a predefined unit, i.e the one that declares iterator interfaces. |
| 18014 |
|
| 18015 |
return |
| 18016 |
Chars (Iter_Typ) in Name_Forward_Iterator | Name_Reversible_Iterator |
| 18017 |
and then In_Predefined_Unit (Root_Type (Iter_Typ)); |
| 18018 |
end Denotes_Iterator; |
| 18019 |
|
| 18020 |
-- Local variables |
| 18021 |
|
| 18022 |
Iface_Elmt : Elmt_Id; |
| 18023 |
Ifaces : Elist_Id; |
| 18024 |
|
| 18025 |
-- Start of processing for Is_Iterator |
| 18026 |
|
| 18027 |
begin |
| 18028 |
-- The type may be a subtype of a descendant of the proper instance of |
| 18029 |
-- the predefined interface type, so we must use the root type of the |
| 18030 |
-- given type. The same is done for Is_Reversible_Iterator. |
| 18031 |
|
| 18032 |
if Is_Class_Wide_Type (Typ) |
| 18033 |
and then Denotes_Iterator (Root_Type (Typ)) |
| 18034 |
then |
| 18035 |
return True; |
| 18036 |
|
| 18037 |
elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then |
| 18038 |
return False; |
| 18039 |
|
| 18040 |
elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then |
| 18041 |
return True; |
| 18042 |
|
| 18043 |
else |
| 18044 |
Collect_Interfaces (Typ, Ifaces); |
| 18045 |
|
| 18046 |
Iface_Elmt := First_Elmt (Ifaces); |
| 18047 |
while Present (Iface_Elmt) loop |
| 18048 |
if Denotes_Iterator (Node (Iface_Elmt)) then |
| 18049 |
return True; |
| 18050 |
end if; |
| 18051 |
|
| 18052 |
Next_Elmt (Iface_Elmt); |
| 18053 |
end loop; |
| 18054 |
|
| 18055 |
return False; |
| 18056 |
end if; |
| 18057 |
end Is_Iterator; |
| 18058 |
|
| 18059 |
---------------------------- |
| 18060 |
-- Is_Iterator_Over_Array -- |
| 18061 |
---------------------------- |
| 18062 |
|
| 18063 |
function Is_Iterator_Over_Array (N : Node_Id) return Boolean is |
| 18064 |
Container : constant Node_Id := Name (N); |
| 18065 |
Container_Typ : constant Entity_Id := Base_Type (Etype (Container)); |
| 18066 |
begin |
| 18067 |
return Is_Array_Type (Container_Typ); |
| 18068 |
end Is_Iterator_Over_Array; |
| 18069 |
|
| 18070 |
-------------------------- |
| 18071 |
-- Known_To_Be_Assigned -- |
| 18072 |
-------------------------- |
| 18073 |
|
| 18074 |
function Known_To_Be_Assigned |
| 18075 |
(N : Node_Id; |
| 18076 |
Only_LHS : Boolean := False) return Boolean |
| 18077 |
is |
| 18078 |
function Known_Assn (N : Node_Id) return Boolean is |
| 18079 |
(Known_To_Be_Assigned (N, Only_LHS)); |
| 18080 |
-- Local function to simplify the passing of parameters for recursive |
| 18081 |
-- calls. |
| 18082 |
|
| 18083 |
P : constant Node_Id := Parent (N); |
| 18084 |
Form : Entity_Id := Empty; |
| 18085 |
Call : Node_Id := Empty; |
| 18086 |
|
| 18087 |
-- Start of processing for Known_To_Be_Assigned |
| 18088 |
|
| 18089 |
begin |
| 18090 |
-- Check for out parameters |
| 18091 |
|
| 18092 |
Find_Actual (N, Form, Call); |
| 18093 |
|
| 18094 |
if Present (Form) then |
| 18095 |
return Ekind (Form) /= E_In_Parameter and then not Only_LHS; |
| 18096 |
end if; |
| 18097 |
|
| 18098 |
-- Otherwise look at the parent |
| 18099 |
|
| 18100 |
case Nkind (P) is |
| 18101 |
|
| 18102 |
-- Test left side of assignment |
| 18103 |
|
| 18104 |
when N_Assignment_Statement => |
| 18105 |
return N = Name (P); |
| 18106 |
|
| 18107 |
-- Test prefix of component or attribute. Note that the prefix of an |
| 18108 |
-- explicit or implicit dereference cannot be an l-value. In the case |
| 18109 |
-- of a 'Read attribute, the reference can be an actual in the |
| 18110 |
-- argument list of the attribute. |
| 18111 |
|
| 18112 |
when N_Attribute_Reference => |
| 18113 |
return |
| 18114 |
not Only_LHS and then |
| 18115 |
((N = Prefix (P) |
| 18116 |
and then Name_Implies_Lvalue_Prefix (Attribute_Name (P))) |
| 18117 |
or else |
| 18118 |
Attribute_Name (P) = Name_Read); |
| 18119 |
|
| 18120 |
-- For an expanded name, the name is an lvalue if the expanded name |
| 18121 |
-- is an lvalue, but the prefix is never an lvalue, since it is just |
| 18122 |
-- the scope where the name is found. |
| 18123 |
|
| 18124 |
when N_Expanded_Name => |
| 18125 |
if N = Prefix (P) then |
| 18126 |
return Known_Assn (P); |
| 18127 |
else |
| 18128 |
return False; |
| 18129 |
end if; |
| 18130 |
|
| 18131 |
-- For a selected component A.B, A is certainly an lvalue if A.B is. |
| 18132 |
-- B is a little interesting, if we have A.B := 3, there is some |
| 18133 |
-- discussion as to whether B is an lvalue or not, we choose to say |
| 18134 |
-- it is. Note however that A is not an lvalue if it is of an access |
| 18135 |
-- type since this is an implicit dereference. |
| 18136 |
|
| 18137 |
when N_Selected_Component => |
| 18138 |
if N = Prefix (P) |
| 18139 |
and then Present (Etype (N)) |
| 18140 |
and then Is_Access_Type (Etype (N)) |
| 18141 |
then |
| 18142 |
return False; |
| 18143 |
else |
| 18144 |
return Known_Assn (P); |
| 18145 |
end if; |
| 18146 |
|
| 18147 |
-- For an indexed component or slice, the index or slice bounds is |
| 18148 |
-- never an lvalue. The prefix is an lvalue if the indexed component |
| 18149 |
-- or slice is an lvalue, except if it is an access type, where we |
| 18150 |
-- have an implicit dereference. |
| 18151 |
|
| 18152 |
when N_Indexed_Component | N_Slice => |
| 18153 |
if N /= Prefix (P) |
| 18154 |
or else (Present (Etype (N)) and then Is_Access_Type (Etype (N))) |
| 18155 |
then |
| 18156 |
return False; |
| 18157 |
else |
| 18158 |
return Known_Assn (P); |
| 18159 |
end if; |
| 18160 |
|
| 18161 |
-- Prefix of a reference is an lvalue if the reference is an lvalue |
| 18162 |
|
| 18163 |
when N_Reference => |
| 18164 |
return Known_Assn (P); |
| 18165 |
|
| 18166 |
-- Prefix of explicit dereference is never an lvalue |
| 18167 |
|
| 18168 |
when N_Explicit_Dereference => |
| 18169 |
return False; |
| 18170 |
|
| 18171 |
-- Test for appearing in a conversion that itself appears in an |
| 18172 |
-- lvalue context, since this should be an lvalue. |
| 18173 |
|
| 18174 |
when N_Type_Conversion => |
| 18175 |
return Known_Assn (P); |
| 18176 |
|
| 18177 |
-- Test for appearance in object renaming declaration |
| 18178 |
|
| 18179 |
when N_Object_Renaming_Declaration => |
| 18180 |
return not Only_LHS; |
| 18181 |
|
| 18182 |
-- All other references are definitely not lvalues |
| 18183 |
|
| 18184 |
when others => |
| 18185 |
return False; |
| 18186 |
end case; |
| 18187 |
end Known_To_Be_Assigned; |
| 18188 |
|
| 18189 |
----------------------------- |
| 18190 |
-- Is_Library_Level_Entity -- |
| 18191 |
----------------------------- |
| 18192 |
|
| 18193 |
function Is_Library_Level_Entity (E : Entity_Id) return Boolean is |
| 18194 |
begin |
| 18195 |
-- The following is a small optimization, and it also properly handles |
| 18196 |
-- discriminals, which in task bodies might appear in expressions before |
| 18197 |
-- the corresponding procedure has been created, and which therefore do |
| 18198 |
-- not have an assigned scope. |
| 18199 |
|
| 18200 |
if Is_Formal (E) then |
| 18201 |
return False; |
| 18202 |
|
| 18203 |
-- If we somehow got an empty value for Scope, the tree must be |
| 18204 |
-- malformed. Rather than blow up we return True in this case. |
| 18205 |
|
| 18206 |
elsif No (Scope (E)) then |
| 18207 |
return True; |
| 18208 |
|
| 18209 |
-- Handle loops since Enclosing_Dynamic_Scope skips them; required to |
| 18210 |
-- properly handle entities local to quantified expressions in library |
| 18211 |
-- level specifications. |
| 18212 |
|
| 18213 |
elsif Ekind (Scope (E)) = E_Loop then |
| 18214 |
return False; |
| 18215 |
end if; |
| 18216 |
|
| 18217 |
-- Normal test is simply that the enclosing dynamic scope is Standard |
| 18218 |
|
| 18219 |
return Enclosing_Dynamic_Scope (E) = Standard_Standard; |
| 18220 |
end Is_Library_Level_Entity; |
| 18221 |
|
| 18222 |
-------------------------------- |
| 18223 |
-- Is_Limited_Class_Wide_Type -- |
| 18224 |
-------------------------------- |
| 18225 |
|
| 18226 |
function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is |
| 18227 |
begin |
| 18228 |
return |
| 18229 |
Is_Class_Wide_Type (Typ) |
| 18230 |
and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ)); |
| 18231 |
end Is_Limited_Class_Wide_Type; |
| 18232 |
|
| 18233 |
--------------------------------- |
| 18234 |
-- Is_Local_Variable_Reference -- |
| 18235 |
--------------------------------- |
| 18236 |
|
| 18237 |
function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is |
| 18238 |
begin |
| 18239 |
if not Is_Entity_Name (Expr) then |
| 18240 |
return False; |
| 18241 |
|
| 18242 |
else |
| 18243 |
declare |
| 18244 |
Ent : constant Entity_Id := Entity (Expr); |
| 18245 |
Sub : constant Entity_Id := Enclosing_Subprogram (Ent); |
| 18246 |
begin |
| 18247 |
if Ekind (Ent) |
| 18248 |
not in E_Variable | E_In_Out_Parameter | E_Out_Parameter |
| 18249 |
then |
| 18250 |
return False; |
| 18251 |
else |
| 18252 |
return Present (Sub) and then Sub = Current_Subprogram; |
| 18253 |
end if; |
| 18254 |
end; |
| 18255 |
end if; |
| 18256 |
end Is_Local_Variable_Reference; |
| 18257 |
|
| 18258 |
--------------- |
| 18259 |
-- Is_Master -- |
| 18260 |
--------------- |
| 18261 |
|
| 18262 |
function Is_Master (N : Node_Id) return Boolean is |
| 18263 |
Disable_Subexpression_Masters : constant Boolean := True; |
| 18264 |
|
| 18265 |
begin |
| 18266 |
if Nkind (N) in N_Subprogram_Body | N_Task_Body | N_Entry_Body |
| 18267 |
or else Is_Statement (N) |
| 18268 |
then |
| 18269 |
return True; |
| 18270 |
end if; |
| 18271 |
|
| 18272 |
-- We avoid returning True when the master is a subexpression described |
| 18273 |
-- in RM 7.6.1(3/2) for the proposes of accessibility level calculation |
| 18274 |
-- in Accessibility_Level_Helper.Innermost_Master_Scope_Depth ??? |
| 18275 |
|
| 18276 |
if not Disable_Subexpression_Masters |
| 18277 |
and then Nkind (N) in N_Subexpr |
| 18278 |
then |
| 18279 |
declare |
| 18280 |
Par : Node_Id := N; |
| 18281 |
|
| 18282 |
subtype N_Simple_Statement_Other_Than_Simple_Return |
| 18283 |
is Node_Kind with Static_Predicate => |
| 18284 |
N_Simple_Statement_Other_Than_Simple_Return |
| 18285 |
in N_Abort_Statement |
| 18286 |
| N_Assignment_Statement |
| 18287 |
| N_Code_Statement |
| 18288 |
| N_Delay_Statement |
| 18289 |
| N_Entry_Call_Statement |
| 18290 |
| N_Free_Statement |
| 18291 |
| N_Goto_Statement |
| 18292 |
| N_Null_Statement |
| 18293 |
| N_Raise_Statement |
| 18294 |
| N_Requeue_Statement |
| 18295 |
| N_Exit_Statement |
| 18296 |
| N_Procedure_Call_Statement; |
| 18297 |
begin |
| 18298 |
while Present (Par) loop |
| 18299 |
Par := Parent (Par); |
| 18300 |
if Nkind (Par) in N_Subexpr | |
| 18301 |
N_Simple_Statement_Other_Than_Simple_Return |
| 18302 |
then |
| 18303 |
return False; |
| 18304 |
end if; |
| 18305 |
end loop; |
| 18306 |
|
| 18307 |
return True; |
| 18308 |
end; |
| 18309 |
end if; |
| 18310 |
|
| 18311 |
return False; |
| 18312 |
end Is_Master; |
| 18313 |
|
| 18314 |
----------------------- |
| 18315 |
-- Is_Name_Reference -- |
| 18316 |
----------------------- |
| 18317 |
|
| 18318 |
function Is_Name_Reference (N : Node_Id) return Boolean is |
| 18319 |
begin |
| 18320 |
if Is_Entity_Name (N) then |
| 18321 |
return Present (Entity (N)) and then Is_Object (Entity (N)); |
| 18322 |
end if; |
| 18323 |
|
| 18324 |
case Nkind (N) is |
| 18325 |
when N_Indexed_Component |
| 18326 |
| N_Slice |
| 18327 |
=> |
| 18328 |
return |
| 18329 |
Is_Name_Reference (Prefix (N)) |
| 18330 |
or else Is_Access_Type (Etype (Prefix (N))); |
| 18331 |
|
| 18332 |
-- Attributes 'Input, 'Old and 'Result produce objects |
| 18333 |
|
| 18334 |
when N_Attribute_Reference => |
| 18335 |
return Attribute_Name (N) in Name_Input | Name_Old | Name_Result; |
| 18336 |
|
| 18337 |
when N_Selected_Component => |
| 18338 |
return |
| 18339 |
Is_Name_Reference (Selector_Name (N)) |
| 18340 |
and then |
| 18341 |
(Is_Name_Reference (Prefix (N)) |
| 18342 |
or else Is_Access_Type (Etype (Prefix (N)))); |
| 18343 |
|
| 18344 |
when N_Explicit_Dereference => |
| 18345 |
return True; |
| 18346 |
|
| 18347 |
-- A view conversion of a tagged name is a name reference |
| 18348 |
|
| 18349 |
when N_Type_Conversion => |
| 18350 |
return |
| 18351 |
Is_Tagged_Type (Etype (Subtype_Mark (N))) |
| 18352 |
and then Is_Tagged_Type (Etype (Expression (N))) |
| 18353 |
and then Is_Name_Reference (Expression (N)); |
| 18354 |
|
| 18355 |
-- An unchecked type conversion is considered to be a name if the |
| 18356 |
-- operand is a name (this construction arises only as a result of |
| 18357 |
-- expansion activities). |
| 18358 |
|
| 18359 |
when N_Unchecked_Type_Conversion => |
| 18360 |
return Is_Name_Reference (Expression (N)); |
| 18361 |
|
| 18362 |
when others => |
| 18363 |
return False; |
| 18364 |
end case; |
| 18365 |
end Is_Name_Reference; |
| 18366 |
|
| 18367 |
-------------------------- |
| 18368 |
-- Is_Newly_Constructed -- |
| 18369 |
-------------------------- |
| 18370 |
|
| 18371 |
function Is_Newly_Constructed |
| 18372 |
(Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean |
| 18373 |
is |
| 18374 |
Original_Exp : constant Node_Id := Original_Node (Exp); |
| 18375 |
|
| 18376 |
function Is_NC (Exp : Node_Id) return Boolean is |
| 18377 |
(Is_Newly_Constructed (Exp, Context_Requires_NC)); |
| 18378 |
|
| 18379 |
-- If the context requires that the expression shall be newly |
| 18380 |
-- constructed, then "True" is a good result in the sense that the |
| 18381 |
-- expression satisfies the requirements of the context (and "False" |
| 18382 |
-- is analogously a bad result). If the context requires that the |
| 18383 |
-- expression shall *not* be newly constructed, then things are |
| 18384 |
-- reversed: "False" is the good value and "True" is the bad value. |
| 18385 |
|
| 18386 |
Good_Result : constant Boolean := Context_Requires_NC; |
| 18387 |
Bad_Result : constant Boolean := not Good_Result; |
| 18388 |
begin |
| 18389 |
case Nkind (Original_Exp) is |
| 18390 |
when N_Aggregate |
| 18391 |
| N_Extension_Aggregate |
| 18392 |
| N_Function_Call |
| 18393 |
| N_Op |
| 18394 |
=> |
| 18395 |
return True; |
| 18396 |
|
| 18397 |
when N_Identifier => |
| 18398 |
return Present (Entity (Original_Exp)) |
| 18399 |
and then Ekind (Entity (Original_Exp)) = E_Function; |
| 18400 |
|
| 18401 |
when N_Qualified_Expression => |
| 18402 |
return Is_NC (Expression (Original_Exp)); |
| 18403 |
|
| 18404 |
when N_Type_Conversion |
| 18405 |
| N_Unchecked_Type_Conversion |
| 18406 |
=> |
| 18407 |
if Is_View_Conversion (Original_Exp) then |
| 18408 |
return Is_NC (Expression (Original_Exp)); |
| 18409 |
elsif not Comes_From_Source (Exp) then |
| 18410 |
if Exp /= Original_Exp then |
| 18411 |
return Is_NC (Original_Exp); |
| 18412 |
else |
| 18413 |
return Is_NC (Expression (Original_Exp)); |
| 18414 |
end if; |
| 18415 |
else |
| 18416 |
return False; |
| 18417 |
end if; |
| 18418 |
|
| 18419 |
when N_Explicit_Dereference |
| 18420 |
| N_Indexed_Component |
| 18421 |
| N_Selected_Component |
| 18422 |
=> |
| 18423 |
return Nkind (Exp) = N_Function_Call; |
| 18424 |
|
| 18425 |
-- A use of 'Input is a function call, hence allowed. Normally the |
| 18426 |
-- attribute will be changed to a call, but the attribute by itself |
| 18427 |
-- can occur with -gnatc. |
| 18428 |
|
| 18429 |
when N_Attribute_Reference => |
| 18430 |
return Attribute_Name (Original_Exp) = Name_Input; |
| 18431 |
|
| 18432 |
-- "return raise ..." is OK |
| 18433 |
|
| 18434 |
when N_Raise_Expression => |
| 18435 |
return Good_Result; |
| 18436 |
|
| 18437 |
-- For a case expression, all dependent expressions must be legal |
| 18438 |
|
| 18439 |
when N_Case_Expression => |
| 18440 |
declare |
| 18441 |
Alt : Node_Id; |
| 18442 |
|
| 18443 |
begin |
| 18444 |
Alt := First (Alternatives (Original_Exp)); |
| 18445 |
while Present (Alt) loop |
| 18446 |
if Is_NC (Expression (Alt)) = Bad_Result then |
| 18447 |
return Bad_Result; |
| 18448 |
end if; |
| 18449 |
|
| 18450 |
Next (Alt); |
| 18451 |
end loop; |
| 18452 |
|
| 18453 |
return Good_Result; |
| 18454 |
end; |
| 18455 |
|
| 18456 |
-- For an if expression, all dependent expressions must be legal |
| 18457 |
|
| 18458 |
when N_If_Expression => |
| 18459 |
declare |
| 18460 |
Then_Expr : constant Node_Id := |
| 18461 |
Next (First (Expressions (Original_Exp))); |
| 18462 |
Else_Expr : constant Node_Id := Next (Then_Expr); |
| 18463 |
begin |
| 18464 |
if Is_NC (Then_Expr) = Bad_Result |
| 18465 |
or else Is_NC (Else_Expr) = Bad_Result |
| 18466 |
then |
| 18467 |
return Bad_Result; |
| 18468 |
else |
| 18469 |
return Good_Result; |
| 18470 |
end if; |
| 18471 |
end; |
| 18472 |
|
| 18473 |
when others => |
| 18474 |
return False; |
| 18475 |
end case; |
| 18476 |
end Is_Newly_Constructed; |
| 18477 |
|
| 18478 |
------------------------------------ |
| 18479 |
-- Is_Non_Preelaborable_Construct -- |
| 18480 |
------------------------------------ |
| 18481 |
|
| 18482 |
function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is |
| 18483 |
|
| 18484 |
-- NOTE: the routines within Is_Non_Preelaborable_Construct are |
| 18485 |
-- intentionally unnested to avoid deep indentation of code. |
| 18486 |
|
| 18487 |
Non_Preelaborable : exception; |
| 18488 |
-- This exception is raised when the construct violates preelaborability |
| 18489 |
-- to terminate the recursion. |
| 18490 |
|
| 18491 |
procedure Visit (Nod : Node_Id); |
| 18492 |
-- Semantically inspect construct Nod to determine whether it violates |
| 18493 |
-- preelaborability. This routine raises Non_Preelaborable. |
| 18494 |
|
| 18495 |
procedure Visit_List (List : List_Id); |
| 18496 |
pragma Inline (Visit_List); |
| 18497 |
-- Invoke Visit on each element of list List. This routine raises |
| 18498 |
-- Non_Preelaborable. |
| 18499 |
|
| 18500 |
procedure Visit_Pragma (Prag : Node_Id); |
| 18501 |
pragma Inline (Visit_Pragma); |
| 18502 |
-- Semantically inspect pragma Prag to determine whether it violates |
| 18503 |
-- preelaborability. This routine raises Non_Preelaborable. |
| 18504 |
|
| 18505 |
procedure Visit_Subexpression (Expr : Node_Id); |
| 18506 |
pragma Inline (Visit_Subexpression); |
| 18507 |
-- Semantically inspect expression Expr to determine whether it violates |
| 18508 |
-- preelaborability. This routine raises Non_Preelaborable. |
| 18509 |
|
| 18510 |
----------- |
| 18511 |
-- Visit -- |
| 18512 |
----------- |
| 18513 |
|
| 18514 |
procedure Visit (Nod : Node_Id) is |
| 18515 |
begin |
| 18516 |
case Nkind (Nod) is |
| 18517 |
|
| 18518 |
-- Declarations |
| 18519 |
|
| 18520 |
when N_Component_Declaration => |
| 18521 |
|
| 18522 |
-- Defining_Identifier is left out because it is not relevant |
| 18523 |
-- for preelaborability. |
| 18524 |
|
| 18525 |
Visit (Component_Definition (Nod)); |
| 18526 |
Visit (Expression (Nod)); |
| 18527 |
|
| 18528 |
when N_Derived_Type_Definition => |
| 18529 |
|
| 18530 |
-- Interface_List is left out because it is not relevant for |
| 18531 |
-- preelaborability. |
| 18532 |
|
| 18533 |
Visit (Record_Extension_Part (Nod)); |
| 18534 |
Visit (Subtype_Indication (Nod)); |
| 18535 |
|
| 18536 |
when N_Entry_Declaration => |
| 18537 |
|
| 18538 |
-- A protected type with at leat one entry is not preelaborable |
| 18539 |
-- while task types are never preelaborable. This renders entry |
| 18540 |
-- declarations non-preelaborable. |
| 18541 |
|
| 18542 |
raise Non_Preelaborable; |
| 18543 |
|
| 18544 |
when N_Full_Type_Declaration => |
| 18545 |
|
| 18546 |
-- Defining_Identifier and Discriminant_Specifications are left |
| 18547 |
-- out because they are not relevant for preelaborability. |
| 18548 |
|
| 18549 |
Visit (Type_Definition (Nod)); |
| 18550 |
|
| 18551 |
when N_Function_Instantiation |
| 18552 |
| N_Package_Instantiation |
| 18553 |
| N_Procedure_Instantiation |
| 18554 |
=> |
| 18555 |
-- Defining_Unit_Name and Name are left out because they are |
| 18556 |
-- not relevant for preelaborability. |
| 18557 |
|
| 18558 |
Visit_List (Generic_Associations (Nod)); |
| 18559 |
|
| 18560 |
when N_Object_Declaration => |
| 18561 |
|
| 18562 |
-- Defining_Identifier is left out because it is not relevant |
| 18563 |
-- for preelaborability. |
| 18564 |
|
| 18565 |
Visit (Object_Definition (Nod)); |
| 18566 |
|
| 18567 |
if Has_Init_Expression (Nod) then |
| 18568 |
Visit (Expression (Nod)); |
| 18569 |
|
| 18570 |
elsif not Constant_Present (Nod) |
| 18571 |
and then not Has_Preelaborable_Initialization |
| 18572 |
(Etype (Defining_Entity (Nod))) |
| 18573 |
then |
| 18574 |
raise Non_Preelaborable; |
| 18575 |
end if; |
| 18576 |
|
| 18577 |
when N_Private_Extension_Declaration |
| 18578 |
| N_Subtype_Declaration |
| 18579 |
=> |
| 18580 |
-- Defining_Identifier, Discriminant_Specifications, and |
| 18581 |
-- Interface_List are left out because they are not relevant |
| 18582 |
-- for preelaborability. |
| 18583 |
|
| 18584 |
Visit (Subtype_Indication (Nod)); |
| 18585 |
|
| 18586 |
when N_Protected_Type_Declaration |
| 18587 |
| N_Single_Protected_Declaration |
| 18588 |
=> |
| 18589 |
-- Defining_Identifier, Discriminant_Specifications, and |
| 18590 |
-- Interface_List are left out because they are not relevant |
| 18591 |
-- for preelaborability. |
| 18592 |
|
| 18593 |
Visit (Protected_Definition (Nod)); |
| 18594 |
|
| 18595 |
-- A [single] task type is never preelaborable |
| 18596 |
|
| 18597 |
when N_Single_Task_Declaration |
| 18598 |
| N_Task_Type_Declaration |
| 18599 |
=> |
| 18600 |
raise Non_Preelaborable; |
| 18601 |
|
| 18602 |
-- Pragmas |
| 18603 |
|
| 18604 |
when N_Pragma => |
| 18605 |
Visit_Pragma (Nod); |
| 18606 |
|
| 18607 |
-- Statements |
| 18608 |
|
| 18609 |
when N_Statement_Other_Than_Procedure_Call => |
| 18610 |
if Nkind (Nod) /= N_Null_Statement then |
| 18611 |
raise Non_Preelaborable; |
| 18612 |
end if; |
| 18613 |
|
| 18614 |
-- Subexpressions |
| 18615 |
|
| 18616 |
when N_Subexpr => |
| 18617 |
Visit_Subexpression (Nod); |
| 18618 |
|
| 18619 |
-- Special |
| 18620 |
|
| 18621 |
when N_Access_To_Object_Definition => |
| 18622 |
Visit (Subtype_Indication (Nod)); |
| 18623 |
|
| 18624 |
when N_Case_Expression_Alternative => |
| 18625 |
Visit (Expression (Nod)); |
| 18626 |
Visit_List (Discrete_Choices (Nod)); |
| 18627 |
|
| 18628 |
when N_Component_Definition => |
| 18629 |
Visit (Access_Definition (Nod)); |
| 18630 |
Visit (Subtype_Indication (Nod)); |
| 18631 |
|
| 18632 |
when N_Component_List => |
| 18633 |
Visit_List (Component_Items (Nod)); |
| 18634 |
Visit (Variant_Part (Nod)); |
| 18635 |
|
| 18636 |
when N_Constrained_Array_Definition => |
| 18637 |
Visit_List (Discrete_Subtype_Definitions (Nod)); |
| 18638 |
Visit (Component_Definition (Nod)); |
| 18639 |
|
| 18640 |
when N_Delta_Constraint |
| 18641 |
| N_Digits_Constraint |
| 18642 |
=> |
| 18643 |
-- Delta_Expression and Digits_Expression are left out because |
| 18644 |
-- they are not relevant for preelaborability. |
| 18645 |
|
| 18646 |
Visit (Range_Constraint (Nod)); |
| 18647 |
|
| 18648 |
when N_Discriminant_Specification => |
| 18649 |
|
| 18650 |
-- Defining_Identifier and Expression are left out because they |
| 18651 |
-- are not relevant for preelaborability. |
| 18652 |
|
| 18653 |
Visit (Discriminant_Type (Nod)); |
| 18654 |
|
| 18655 |
when N_Generic_Association => |
| 18656 |
|
| 18657 |
-- Selector_Name is left out because it is not relevant for |
| 18658 |
-- preelaborability. |
| 18659 |
|
| 18660 |
Visit (Explicit_Generic_Actual_Parameter (Nod)); |
| 18661 |
|
| 18662 |
when N_Index_Or_Discriminant_Constraint => |
| 18663 |
Visit_List (Constraints (Nod)); |
| 18664 |
|
| 18665 |
when N_Iterator_Specification => |
| 18666 |
|
| 18667 |
-- Defining_Identifier is left out because it is not relevant |
| 18668 |
-- for preelaborability. |
| 18669 |
|
| 18670 |
Visit (Name (Nod)); |
| 18671 |
Visit (Subtype_Indication (Nod)); |
| 18672 |
|
| 18673 |
when N_Loop_Parameter_Specification => |
| 18674 |
|
| 18675 |
-- Defining_Identifier is left out because it is not relevant |
| 18676 |
-- for preelaborability. |
| 18677 |
|
| 18678 |
Visit (Discrete_Subtype_Definition (Nod)); |
| 18679 |
|
| 18680 |
when N_Parameter_Association => |
| 18681 |
Visit (Explicit_Actual_Parameter (N)); |
| 18682 |
|
| 18683 |
when N_Protected_Definition => |
| 18684 |
|
| 18685 |
-- End_Label is left out because it is not relevant for |
| 18686 |
-- preelaborability. |
| 18687 |
|
| 18688 |
Visit_List (Private_Declarations (Nod)); |
| 18689 |
Visit_List (Visible_Declarations (Nod)); |
| 18690 |
|
| 18691 |
when N_Range_Constraint => |
| 18692 |
Visit (Range_Expression (Nod)); |
| 18693 |
|
| 18694 |
when N_Record_Definition |
| 18695 |
| N_Variant |
| 18696 |
=> |
| 18697 |
-- End_Label, Discrete_Choices, and Interface_List are left out |
| 18698 |
-- because they are not relevant for preelaborability. |
| 18699 |
|
| 18700 |
Visit (Component_List (Nod)); |
| 18701 |
|
| 18702 |
when N_Subtype_Indication => |
| 18703 |
|
| 18704 |
-- Subtype_Mark is left out because it is not relevant for |
| 18705 |
-- preelaborability. |
| 18706 |
|
| 18707 |
Visit (Constraint (Nod)); |
| 18708 |
|
| 18709 |
when N_Unconstrained_Array_Definition => |
| 18710 |
|
| 18711 |
-- Subtype_Marks is left out because it is not relevant for |
| 18712 |
-- preelaborability. |
| 18713 |
|
| 18714 |
Visit (Component_Definition (Nod)); |
| 18715 |
|
| 18716 |
when N_Variant_Part => |
| 18717 |
|
| 18718 |
-- Name is left out because it is not relevant for |
| 18719 |
-- preelaborability. |
| 18720 |
|
| 18721 |
Visit_List (Variants (Nod)); |
| 18722 |
|
| 18723 |
-- Default |
| 18724 |
|
| 18725 |
when others => |
| 18726 |
null; |
| 18727 |
end case; |
| 18728 |
end Visit; |
| 18729 |
|
| 18730 |
---------------- |
| 18731 |
-- Visit_List -- |
| 18732 |
---------------- |
| 18733 |
|
| 18734 |
procedure Visit_List (List : List_Id) is |
| 18735 |
Nod : Node_Id; |
| 18736 |
|
| 18737 |
begin |
| 18738 |
Nod := First (List); |
| 18739 |
while Present (Nod) loop |
| 18740 |
Visit (Nod); |
| 18741 |
Next (Nod); |
| 18742 |
end loop; |
| 18743 |
end Visit_List; |
| 18744 |
|
| 18745 |
------------------ |
| 18746 |
-- Visit_Pragma -- |
| 18747 |
------------------ |
| 18748 |
|
| 18749 |
procedure Visit_Pragma (Prag : Node_Id) is |
| 18750 |
begin |
| 18751 |
case Get_Pragma_Id (Prag) is |
| 18752 |
when Pragma_Assert |
| 18753 |
| Pragma_Assert_And_Cut |
| 18754 |
| Pragma_Assume |
| 18755 |
| Pragma_Async_Readers |
| 18756 |
| Pragma_Async_Writers |
| 18757 |
| Pragma_Attribute_Definition |
| 18758 |
| Pragma_Check |
| 18759 |
| Pragma_Constant_After_Elaboration |
| 18760 |
| Pragma_CPU |
| 18761 |
| Pragma_Deadline_Floor |
| 18762 |
| Pragma_Dispatching_Domain |
| 18763 |
| Pragma_Effective_Reads |
| 18764 |
| Pragma_Effective_Writes |
| 18765 |
| Pragma_Extensions_Visible |
| 18766 |
| Pragma_Ghost |
| 18767 |
| Pragma_Secondary_Stack_Size |
| 18768 |
| Pragma_Task_Name |
| 18769 |
| Pragma_Volatile_Function |
| 18770 |
=> |
| 18771 |
Visit_List (Pragma_Argument_Associations (Prag)); |
| 18772 |
|
| 18773 |
-- Default |
| 18774 |
|
| 18775 |
when others => |
| 18776 |
null; |
| 18777 |
end case; |
| 18778 |
end Visit_Pragma; |
| 18779 |
|
| 18780 |
------------------------- |
| 18781 |
-- Visit_Subexpression -- |
| 18782 |
------------------------- |
| 18783 |
|
| 18784 |
procedure Visit_Subexpression (Expr : Node_Id) is |
| 18785 |
procedure Visit_Aggregate (Aggr : Node_Id); |
| 18786 |
pragma Inline (Visit_Aggregate); |
| 18787 |
-- Semantically inspect aggregate Aggr to determine whether it |
| 18788 |
-- violates preelaborability. |
| 18789 |
|
| 18790 |
--------------------- |
| 18791 |
-- Visit_Aggregate -- |
| 18792 |
--------------------- |
| 18793 |
|
| 18794 |
procedure Visit_Aggregate (Aggr : Node_Id) is |
| 18795 |
begin |
| 18796 |
if not Is_Preelaborable_Aggregate (Aggr) then |
| 18797 |
raise Non_Preelaborable; |
| 18798 |
end if; |
| 18799 |
end Visit_Aggregate; |
| 18800 |
|
| 18801 |
-- Start of processing for Visit_Subexpression |
| 18802 |
|
| 18803 |
begin |
| 18804 |
case Nkind (Expr) is |
| 18805 |
when N_Allocator |
| 18806 |
| N_Qualified_Expression |
| 18807 |
| N_Type_Conversion |
| 18808 |
| N_Unchecked_Type_Conversion |
| 18809 |
=> |
| 18810 |
-- Subpool_Handle_Name and Subtype_Mark are left out because |
| 18811 |
-- they are not relevant for preelaborability. |
| 18812 |
|
| 18813 |
Visit (Expression (Expr)); |
| 18814 |
|
| 18815 |
when N_Aggregate |
| 18816 |
| N_Extension_Aggregate |
| 18817 |
=> |
| 18818 |
Visit_Aggregate (Expr); |
| 18819 |
|
| 18820 |
when N_Attribute_Reference |
| 18821 |
| N_Explicit_Dereference |
| 18822 |
| N_Reference |
| 18823 |
=> |
| 18824 |
-- Attribute_Name and Expressions are left out because they are |
| 18825 |
-- not relevant for preelaborability. |
| 18826 |
|
| 18827 |
Visit (Prefix (Expr)); |
| 18828 |
|
| 18829 |
when N_Case_Expression => |
| 18830 |
|
| 18831 |
-- End_Span is left out because it is not relevant for |
| 18832 |
-- preelaborability. |
| 18833 |
|
| 18834 |
Visit_List (Alternatives (Expr)); |
| 18835 |
Visit (Expression (Expr)); |
| 18836 |
|
| 18837 |
when N_Delta_Aggregate => |
| 18838 |
Visit_Aggregate (Expr); |
| 18839 |
Visit (Expression (Expr)); |
| 18840 |
|
| 18841 |
when N_Expression_With_Actions => |
| 18842 |
Visit_List (Actions (Expr)); |
| 18843 |
Visit (Expression (Expr)); |
| 18844 |
|
| 18845 |
when N_Function_Call => |
| 18846 |
|
| 18847 |
-- Ada 2022 (AI12-0175): Calls to certain functions that are |
| 18848 |
-- essentially unchecked conversions are preelaborable. |
| 18849 |
|
| 18850 |
if Ada_Version >= Ada_2022 |
| 18851 |
and then Nkind (Expr) = N_Function_Call |
| 18852 |
and then Is_Entity_Name (Name (Expr)) |
| 18853 |
and then Is_Preelaborable_Function (Entity (Name (Expr))) |
| 18854 |
then |
| 18855 |
Visit_List (Parameter_Associations (Expr)); |
| 18856 |
else |
| 18857 |
raise Non_Preelaborable; |
| 18858 |
end if; |
| 18859 |
|
| 18860 |
when N_If_Expression => |
| 18861 |
Visit_List (Expressions (Expr)); |
| 18862 |
|
| 18863 |
when N_Quantified_Expression => |
| 18864 |
Visit (Condition (Expr)); |
| 18865 |
Visit (Iterator_Specification (Expr)); |
| 18866 |
Visit (Loop_Parameter_Specification (Expr)); |
| 18867 |
|
| 18868 |
when N_Range => |
| 18869 |
Visit (High_Bound (Expr)); |
| 18870 |
Visit (Low_Bound (Expr)); |
| 18871 |
|
| 18872 |
when N_Slice => |
| 18873 |
Visit (Discrete_Range (Expr)); |
| 18874 |
Visit (Prefix (Expr)); |
| 18875 |
|
| 18876 |
-- Default |
| 18877 |
|
| 18878 |
when others => |
| 18879 |
|
| 18880 |
-- The evaluation of an object name is not preelaborable, |
| 18881 |
-- unless the name is a static expression (checked further |
| 18882 |
-- below), or statically denotes a discriminant. |
| 18883 |
|
| 18884 |
if Is_Entity_Name (Expr) then |
| 18885 |
Object_Name : declare |
| 18886 |
Id : constant Entity_Id := Entity (Expr); |
| 18887 |
|
| 18888 |
begin |
| 18889 |
if Is_Object (Id) then |
| 18890 |
if Ekind (Id) = E_Discriminant then |
| 18891 |
null; |
| 18892 |
|
| 18893 |
elsif Ekind (Id) in E_Constant | E_In_Parameter |
| 18894 |
and then Present (Discriminal_Link (Id)) |
| 18895 |
then |
| 18896 |
null; |
| 18897 |
|
| 18898 |
else |
| 18899 |
raise Non_Preelaborable; |
| 18900 |
end if; |
| 18901 |
end if; |
| 18902 |
end Object_Name; |
| 18903 |
|
| 18904 |
-- A non-static expression is not preelaborable |
| 18905 |
|
| 18906 |
elsif not Is_OK_Static_Expression (Expr) then |
| 18907 |
raise Non_Preelaborable; |
| 18908 |
end if; |
| 18909 |
end case; |
| 18910 |
end Visit_Subexpression; |
| 18911 |
|
| 18912 |
-- Start of processing for Is_Non_Preelaborable_Construct |
| 18913 |
|
| 18914 |
begin |
| 18915 |
Visit (N); |
| 18916 |
|
| 18917 |
-- At this point it is known that the construct is preelaborable |
| 18918 |
|
| 18919 |
return False; |
| 18920 |
|
| 18921 |
exception |
| 18922 |
|
| 18923 |
-- The elaboration of the construct performs an action which violates |
| 18924 |
-- preelaborability. |
| 18925 |
|
| 18926 |
when Non_Preelaborable => |
| 18927 |
return True; |
| 18928 |
end Is_Non_Preelaborable_Construct; |
| 18929 |
|
| 18930 |
--------------------------------- |
| 18931 |
-- Is_Nontrivial_DIC_Procedure -- |
| 18932 |
--------------------------------- |
| 18933 |
|
| 18934 |
function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is |
| 18935 |
Body_Decl : Node_Id; |
| 18936 |
Stmt : Node_Id; |
| 18937 |
|
| 18938 |
begin |
| 18939 |
if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then |
| 18940 |
Body_Decl := |
| 18941 |
Unit_Declaration_Node |
| 18942 |
(Corresponding_Body (Unit_Declaration_Node (Id))); |
| 18943 |
|
| 18944 |
-- The body of the Default_Initial_Condition procedure must contain |
| 18945 |
-- at least one statement, otherwise the generation of the subprogram |
| 18946 |
-- body failed. |
| 18947 |
|
| 18948 |
pragma Assert (Present (Handled_Statement_Sequence (Body_Decl))); |
| 18949 |
|
| 18950 |
-- To qualify as nontrivial, the first statement of the procedure |
| 18951 |
-- must be a check in the form of an if statement. If the original |
| 18952 |
-- Default_Initial_Condition expression was folded, then the first |
| 18953 |
-- statement is not a check. |
| 18954 |
|
| 18955 |
Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl))); |
| 18956 |
|
| 18957 |
return |
| 18958 |
Nkind (Stmt) = N_If_Statement |
| 18959 |
and then Nkind (Original_Node (Stmt)) = N_Pragma; |
| 18960 |
end if; |
| 18961 |
|
| 18962 |
return False; |
| 18963 |
end Is_Nontrivial_DIC_Procedure; |
| 18964 |
|
| 18965 |
----------------------- |
| 18966 |
-- Is_Null_Extension -- |
| 18967 |
----------------------- |
| 18968 |
|
| 18969 |
function Is_Null_Extension |
| 18970 |
(T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean |
| 18971 |
is |
| 18972 |
Type_Decl : Node_Id; |
| 18973 |
Type_Def : Node_Id; |
| 18974 |
begin |
| 18975 |
pragma Assert (not Is_Class_Wide_Type (T)); |
| 18976 |
|
| 18977 |
if Ignore_Privacy then |
| 18978 |
Type_Decl := Parent (Underlying_Type (Base_Type (T))); |
| 18979 |
else |
| 18980 |
Type_Decl := Parent (Base_Type (T)); |
| 18981 |
if Nkind (Type_Decl) /= N_Full_Type_Declaration then |
| 18982 |
return False; |
| 18983 |
end if; |
| 18984 |
end if; |
| 18985 |
pragma Assert (Nkind (Type_Decl) = N_Full_Type_Declaration); |
| 18986 |
Type_Def := Type_Definition (Type_Decl); |
| 18987 |
if Present (Discriminant_Specifications (Type_Decl)) |
| 18988 |
or else Nkind (Type_Def) /= N_Derived_Type_Definition |
| 18989 |
or else not Is_Tagged_Type (T) |
| 18990 |
or else No (Record_Extension_Part (Type_Def)) |
| 18991 |
then |
| 18992 |
return False; |
| 18993 |
end if; |
| 18994 |
|
| 18995 |
return Is_Null_Record_Definition (Record_Extension_Part (Type_Def)); |
| 18996 |
end Is_Null_Extension; |
| 18997 |
|
| 18998 |
-------------------------- |
| 18999 |
-- Is_Null_Extension_Of -- |
| 19000 |
-------------------------- |
| 19001 |
|
| 19002 |
function Is_Null_Extension_Of |
| 19003 |
(Descendant, Ancestor : Entity_Id) return Boolean |
| 19004 |
is |
| 19005 |
Ancestor_Type : constant Entity_Id := |
| 19006 |
Underlying_Type (Base_Type (Ancestor)); |
| 19007 |
Descendant_Type : Entity_Id := Underlying_Type (Base_Type (Descendant)); |
| 19008 |
begin |
| 19009 |
pragma Assert (not Is_Class_Wide_Type (Descendant)); |
| 19010 |
pragma Assert (not Is_Class_Wide_Type (Ancestor)); |
| 19011 |
pragma Assert (Descendant_Type /= Ancestor_Type); |
| 19012 |
|
| 19013 |
while Descendant_Type /= Ancestor_Type loop |
| 19014 |
if not Is_Null_Extension |
| 19015 |
(Descendant_Type, Ignore_Privacy => True) |
| 19016 |
then |
| 19017 |
return False; |
| 19018 |
end if; |
| 19019 |
Descendant_Type := Etype (Subtype_Indication |
| 19020 |
(Type_Definition (Parent (Descendant_Type)))); |
| 19021 |
Descendant_Type := Underlying_Type (Base_Type (Descendant_Type)); |
| 19022 |
end loop; |
| 19023 |
return True; |
| 19024 |
end Is_Null_Extension_Of; |
| 19025 |
|
| 19026 |
------------------------------- |
| 19027 |
-- Is_Null_Record_Definition -- |
| 19028 |
------------------------------- |
| 19029 |
|
| 19030 |
function Is_Null_Record_Definition (Record_Def : Node_Id) return Boolean is |
| 19031 |
Item : Node_Id; |
| 19032 |
begin |
| 19033 |
-- Testing Null_Present is just an optimization, not required |
| 19034 |
|
| 19035 |
if Null_Present (Record_Def) then |
| 19036 |
return True; |
| 19037 |
elsif Present (Variant_Part (Component_List (Record_Def))) then |
| 19038 |
return False; |
| 19039 |
end if; |
| 19040 |
|
| 19041 |
Item := First_Non_Pragma (Component_Items (Component_List (Record_Def))); |
| 19042 |
|
| 19043 |
while Present (Item) loop |
| 19044 |
pragma Assert (Nkind (Item) = N_Component_Declaration); |
| 19045 |
if Is_Internal_Name (Chars (Defining_Identifier (Item))) then |
| 19046 |
null; |
| 19047 |
else |
| 19048 |
return False; |
| 19049 |
end if; |
| 19050 |
Next_Non_Pragma (Item); |
| 19051 |
end loop; |
| 19052 |
|
| 19053 |
return True; |
| 19054 |
end Is_Null_Record_Definition; |
| 19055 |
|
| 19056 |
------------------------- |
| 19057 |
-- Is_Null_Record_Type -- |
| 19058 |
------------------------- |
| 19059 |
|
| 19060 |
function Is_Null_Record_Type |
| 19061 |
(T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean |
| 19062 |
is |
| 19063 |
Decl : Node_Id; |
| 19064 |
Type_Def : Node_Id; |
| 19065 |
begin |
| 19066 |
if not Is_Record_Type (T) then |
| 19067 |
return False; |
| 19068 |
end if; |
| 19069 |
|
| 19070 |
if Ignore_Privacy then |
| 19071 |
Decl := Parent (Underlying_Type (Base_Type (T))); |
| 19072 |
else |
| 19073 |
Decl := Parent (Base_Type (T)); |
| 19074 |
if Nkind (Decl) /= N_Full_Type_Declaration then |
| 19075 |
return False; |
| 19076 |
end if; |
| 19077 |
end if; |
| 19078 |
pragma Assert (Nkind (Decl) = N_Full_Type_Declaration); |
| 19079 |
Type_Def := Type_Definition (Decl); |
| 19080 |
|
| 19081 |
if Has_Discriminants (Defining_Identifier (Decl)) then |
| 19082 |
return False; |
| 19083 |
end if; |
| 19084 |
|
| 19085 |
case Nkind (Type_Def) is |
| 19086 |
when N_Record_Definition => |
| 19087 |
return Is_Null_Record_Definition (Type_Def); |
| 19088 |
when N_Derived_Type_Definition => |
| 19089 |
if not Is_Null_Record_Type |
| 19090 |
(Etype (Subtype_Indication (Type_Def)), |
| 19091 |
Ignore_Privacy => Ignore_Privacy) |
| 19092 |
then |
| 19093 |
return False; |
| 19094 |
elsif not Is_Tagged_Type (T) then |
| 19095 |
return True; |
| 19096 |
else |
| 19097 |
return Is_Null_Extension (T, Ignore_Privacy => Ignore_Privacy); |
| 19098 |
end if; |
| 19099 |
when others => |
| 19100 |
return False; |
| 19101 |
end case; |
| 19102 |
end Is_Null_Record_Type; |
| 19103 |
|
| 19104 |
--------------------- |
| 19105 |
-- Is_Object_Image -- |
| 19106 |
--------------------- |
| 19107 |
|
| 19108 |
function Is_Object_Image (Prefix : Node_Id) return Boolean is |
| 19109 |
begin |
| 19110 |
-- Here we test for the case that the prefix is not a type and assume |
| 19111 |
-- if it is not then it must be a named value or an object reference. |
| 19112 |
-- This is because the parser always checks that prefixes of attributes |
| 19113 |
-- are named. |
| 19114 |
|
| 19115 |
return not (Is_Entity_Name (Prefix) |
| 19116 |
and then Is_Type (Entity (Prefix)) |
| 19117 |
and then not Is_Current_Instance (Prefix)); |
| 19118 |
end Is_Object_Image; |
| 19119 |
|
| 19120 |
------------------------- |
| 19121 |
-- Is_Object_Reference -- |
| 19122 |
------------------------- |
| 19123 |
|
| 19124 |
function Is_Object_Reference (N : Node_Id) return Boolean is |
| 19125 |
function Safe_Prefix (N : Node_Id) return Node_Id; |
| 19126 |
-- Return Prefix (N) unless it has been rewritten as an |
| 19127 |
-- N_Raise_xxx_Error node, in which case return its original node. |
| 19128 |
|
| 19129 |
----------------- |
| 19130 |
-- Safe_Prefix -- |
| 19131 |
----------------- |
| 19132 |
|
| 19133 |
function Safe_Prefix (N : Node_Id) return Node_Id is |
| 19134 |
begin |
| 19135 |
if Nkind (Prefix (N)) in N_Raise_xxx_Error then |
| 19136 |
return Original_Node (Prefix (N)); |
| 19137 |
else |
| 19138 |
return Prefix (N); |
| 19139 |
end if; |
| 19140 |
end Safe_Prefix; |
| 19141 |
|
| 19142 |
begin |
| 19143 |
-- AI12-0068: Note that a current instance reference in a type or |
| 19144 |
-- subtype's aspect_specification is considered a value, not an object |
| 19145 |
-- (see RM 8.6(18/5)). |
| 19146 |
|
| 19147 |
if Is_Entity_Name (N) then |
| 19148 |
return Present (Entity (N)) and then Is_Object (Entity (N)) |
| 19149 |
and then not Is_Current_Instance_Reference_In_Type_Aspect (N); |
| 19150 |
|
| 19151 |
else |
| 19152 |
case Nkind (N) is |
| 19153 |
when N_Indexed_Component |
| 19154 |
| N_Slice |
| 19155 |
=> |
| 19156 |
return |
| 19157 |
Is_Object_Reference (Safe_Prefix (N)) |
| 19158 |
or else Is_Access_Type (Etype (Safe_Prefix (N))); |
| 19159 |
|
| 19160 |
-- In Ada 95, a function call is a constant object; a procedure |
| 19161 |
-- call is not. |
| 19162 |
|
| 19163 |
-- Note that predefined operators are functions as well, and so |
| 19164 |
-- are attributes that are (can be renamed as) functions. |
| 19165 |
|
| 19166 |
when N_Function_Call |
| 19167 |
| N_Op |
| 19168 |
=> |
| 19169 |
return Etype (N) /= Standard_Void_Type; |
| 19170 |
|
| 19171 |
-- Attributes references 'Loop_Entry, 'Old, 'Priority and 'Result |
| 19172 |
-- yield objects, even though they are not functions. |
| 19173 |
|
| 19174 |
when N_Attribute_Reference => |
| 19175 |
return |
| 19176 |
Attribute_Name (N) in Name_Loop_Entry |
| 19177 |
| Name_Old |
| 19178 |
| Name_Priority |
| 19179 |
| Name_Result |
| 19180 |
or else Is_Function_Attribute_Name (Attribute_Name (N)); |
| 19181 |
|
| 19182 |
when N_Selected_Component => |
| 19183 |
return |
| 19184 |
Is_Object_Reference (Selector_Name (N)) |
| 19185 |
and then |
| 19186 |
(Is_Object_Reference (Safe_Prefix (N)) |
| 19187 |
or else Is_Access_Type (Etype (Safe_Prefix (N)))); |
| 19188 |
|
| 19189 |
-- An explicit dereference denotes an object, except that a |
| 19190 |
-- conditional expression gets turned into an explicit dereference |
| 19191 |
-- in some cases, and conditional expressions are not object |
| 19192 |
-- names. |
| 19193 |
|
| 19194 |
when N_Explicit_Dereference => |
| 19195 |
return Nkind (Original_Node (N)) not in |
| 19196 |
N_Case_Expression | N_If_Expression; |
| 19197 |
|
| 19198 |
-- A view conversion of a tagged object is an object reference |
| 19199 |
|
| 19200 |
when N_Type_Conversion => |
| 19201 |
if Ada_Version <= Ada_2012 then |
| 19202 |
-- A view conversion of a tagged object is an object |
| 19203 |
-- reference. |
| 19204 |
return Is_Tagged_Type (Etype (Subtype_Mark (N))) |
| 19205 |
and then Is_Tagged_Type (Etype (Expression (N))) |
| 19206 |
and then Is_Object_Reference (Expression (N)); |
| 19207 |
|
| 19208 |
else |
| 19209 |
-- AI12-0226: In Ada 2022 a value conversion of an object is |
| 19210 |
-- an object. |
| 19211 |
|
| 19212 |
return Is_Object_Reference (Expression (N)); |
| 19213 |
end if; |
| 19214 |
|
| 19215 |
-- An unchecked type conversion is considered to be an object if |
| 19216 |
-- the operand is an object (this construction arises only as a |
| 19217 |
-- result of expansion activities). |
| 19218 |
|
| 19219 |
when N_Unchecked_Type_Conversion => |
| 19220 |
return True; |
| 19221 |
|
| 19222 |
-- AI05-0003: In Ada 2012 a qualified expression is a name. |
| 19223 |
-- This allows disambiguation of function calls and the use |
| 19224 |
-- of aggregates in more contexts. |
| 19225 |
|
| 19226 |
when N_Qualified_Expression => |
| 19227 |
return Ada_Version >= Ada_2012 |
| 19228 |
and then Is_Object_Reference (Expression (N)); |
| 19229 |
|
| 19230 |
-- In Ada 95 an aggregate is an object reference |
| 19231 |
|
| 19232 |
when N_Aggregate |
| 19233 |
| N_Delta_Aggregate |
| 19234 |
| N_Extension_Aggregate |
| 19235 |
=> |
| 19236 |
return Ada_Version >= Ada_95; |
| 19237 |
|
| 19238 |
-- A string literal is not an object reference, but it might come |
| 19239 |
-- from rewriting of an object reference, e.g. from folding of an |
| 19240 |
-- aggregate. |
| 19241 |
|
| 19242 |
when N_String_Literal => |
| 19243 |
return Is_Rewrite_Substitution (N) |
| 19244 |
and then Is_Object_Reference (Original_Node (N)); |
| 19245 |
|
| 19246 |
-- AI12-0125: Target name represents a constant object |
| 19247 |
|
| 19248 |
when N_Target_Name => |
| 19249 |
return True; |
| 19250 |
|
| 19251 |
when others => |
| 19252 |
return False; |
| 19253 |
end case; |
| 19254 |
end if; |
| 19255 |
end Is_Object_Reference; |
| 19256 |
|
| 19257 |
----------------------------------- |
| 19258 |
-- Is_OK_Variable_For_Out_Formal -- |
| 19259 |
----------------------------------- |
| 19260 |
|
| 19261 |
function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is |
| 19262 |
begin |
| 19263 |
Note_Possible_Modification (AV, Sure => True); |
| 19264 |
|
| 19265 |
-- We must reject parenthesized variable names. Comes_From_Source is |
| 19266 |
-- checked because there are currently cases where the compiler violates |
| 19267 |
-- this rule (e.g. passing a task object to its controlled Initialize |
| 19268 |
-- routine). This should be properly documented in sinfo??? |
| 19269 |
|
| 19270 |
if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then |
| 19271 |
return False; |
| 19272 |
|
| 19273 |
-- A variable is always allowed |
| 19274 |
|
| 19275 |
elsif Is_Variable (AV) then |
| 19276 |
return True; |
| 19277 |
|
| 19278 |
-- Generalized indexing operations are rewritten as explicit |
| 19279 |
-- dereferences, and it is only during resolution that we can |
| 19280 |
-- check whether the context requires an access_to_variable type. |
| 19281 |
|
| 19282 |
elsif Nkind (AV) = N_Explicit_Dereference |
| 19283 |
and then Present (Etype (Original_Node (AV))) |
| 19284 |
and then Has_Implicit_Dereference (Etype (Original_Node (AV))) |
| 19285 |
and then Ada_Version >= Ada_2012 |
| 19286 |
then |
| 19287 |
return not Is_Access_Constant (Etype (Prefix (AV))); |
| 19288 |
|
| 19289 |
-- Unchecked conversions are allowed only if they come from the |
| 19290 |
-- generated code, which sometimes uses unchecked conversions for out |
| 19291 |
-- parameters in cases where code generation is unaffected. We tell |
| 19292 |
-- source unchecked conversions by seeing if they are rewrites of |
| 19293 |
-- an original Unchecked_Conversion function call, or of an explicit |
| 19294 |
-- conversion of a function call or an aggregate (as may happen in the |
| 19295 |
-- expansion of a packed array aggregate). |
| 19296 |
|
| 19297 |
elsif Nkind (AV) = N_Unchecked_Type_Conversion then |
| 19298 |
if Nkind (Original_Node (AV)) in N_Function_Call | N_Aggregate then |
| 19299 |
return False; |
| 19300 |
|
| 19301 |
elsif Nkind (Original_Node (Expression (AV))) = N_Function_Call then |
| 19302 |
return False; |
| 19303 |
|
| 19304 |
elsif Nkind (Original_Node (AV)) = N_Type_Conversion then |
| 19305 |
return Is_OK_Variable_For_Out_Formal (Expression (AV)); |
| 19306 |
|
| 19307 |
else |
| 19308 |
return True; |
| 19309 |
end if; |
| 19310 |
|
| 19311 |
-- Normal type conversions are allowed if argument is a variable |
| 19312 |
|
| 19313 |
elsif Nkind (AV) = N_Type_Conversion then |
| 19314 |
if Is_Variable (Expression (AV)) |
| 19315 |
and then Paren_Count (Expression (AV)) = 0 |
| 19316 |
then |
| 19317 |
Note_Possible_Modification (Expression (AV), Sure => True); |
| 19318 |
return True; |
| 19319 |
|
| 19320 |
-- We also allow a non-parenthesized expression that raises |
| 19321 |
-- constraint error if it rewrites what used to be a variable |
| 19322 |
|
| 19323 |
elsif Raises_Constraint_Error (Expression (AV)) |
| 19324 |
and then Paren_Count (Expression (AV)) = 0 |
| 19325 |
and then Is_Variable (Original_Node (Expression (AV))) |
| 19326 |
then |
| 19327 |
return True; |
| 19328 |
|
| 19329 |
-- Type conversion of something other than a variable |
| 19330 |
|
| 19331 |
else |
| 19332 |
return False; |
| 19333 |
end if; |
| 19334 |
|
| 19335 |
-- If this node is rewritten, then test the original form, if that is |
| 19336 |
-- OK, then we consider the rewritten node OK (for example, if the |
| 19337 |
-- original node is a conversion, then Is_Variable will not be true |
| 19338 |
-- but we still want to allow the conversion if it converts a variable). |
| 19339 |
|
| 19340 |
elsif Is_Rewrite_Substitution (AV) then |
| 19341 |
return Is_OK_Variable_For_Out_Formal (Original_Node (AV)); |
| 19342 |
|
| 19343 |
-- All other non-variables are rejected |
| 19344 |
|
| 19345 |
else |
| 19346 |
return False; |
| 19347 |
end if; |
| 19348 |
end Is_OK_Variable_For_Out_Formal; |
| 19349 |
|
| 19350 |
---------------------------- |
| 19351 |
-- Is_OK_Volatile_Context -- |
| 19352 |
---------------------------- |
| 19353 |
|
| 19354 |
function Is_OK_Volatile_Context |
| 19355 |
(Context : Node_Id; |
| 19356 |
Obj_Ref : Node_Id; |
| 19357 |
Check_Actuals : Boolean) return Boolean |
| 19358 |
is |
| 19359 |
function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean; |
| 19360 |
-- Determine whether an arbitrary node denotes a call to a protected |
| 19361 |
-- entry, function, or procedure in prefixed form where the prefix is |
| 19362 |
-- Obj_Ref. |
| 19363 |
|
| 19364 |
function Within_Check (Nod : Node_Id) return Boolean; |
| 19365 |
-- Determine whether an arbitrary node appears in a check node |
| 19366 |
|
| 19367 |
function Within_Volatile_Function (Id : Entity_Id) return Boolean; |
| 19368 |
-- Determine whether an arbitrary entity appears in a volatile function |
| 19369 |
|
| 19370 |
--------------------------------- |
| 19371 |
-- Is_Protected_Operation_Call -- |
| 19372 |
--------------------------------- |
| 19373 |
|
| 19374 |
function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is |
| 19375 |
Pref : Node_Id; |
| 19376 |
Subp : Node_Id; |
| 19377 |
|
| 19378 |
begin |
| 19379 |
-- A call to a protected operations retains its selected component |
| 19380 |
-- form as opposed to other prefixed calls that are transformed in |
| 19381 |
-- expanded names. |
| 19382 |
|
| 19383 |
if Nkind (Nod) = N_Selected_Component then |
| 19384 |
Pref := Prefix (Nod); |
| 19385 |
Subp := Selector_Name (Nod); |
| 19386 |
|
| 19387 |
return |
| 19388 |
Pref = Obj_Ref |
| 19389 |
and then Present (Etype (Pref)) |
| 19390 |
and then Is_Protected_Type (Etype (Pref)) |
| 19391 |
and then Is_Entity_Name (Subp) |
| 19392 |
and then Present (Entity (Subp)) |
| 19393 |
and then Ekind (Entity (Subp)) in |
| 19394 |
E_Entry | E_Entry_Family | E_Function | E_Procedure; |
| 19395 |
else |
| 19396 |
return False; |
| 19397 |
end if; |
| 19398 |
end Is_Protected_Operation_Call; |
| 19399 |
|
| 19400 |
------------------ |
| 19401 |
-- Within_Check -- |
| 19402 |
------------------ |
| 19403 |
|
| 19404 |
function Within_Check (Nod : Node_Id) return Boolean is |
| 19405 |
Par : Node_Id; |
| 19406 |
|
| 19407 |
begin |
| 19408 |
-- Climb the parent chain looking for a check node |
| 19409 |
|
| 19410 |
Par := Nod; |
| 19411 |
while Present (Par) loop |
| 19412 |
if Nkind (Par) in N_Raise_xxx_Error then |
| 19413 |
return True; |
| 19414 |
|
| 19415 |
-- Prevent the search from going too far |
| 19416 |
|
| 19417 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 19418 |
exit; |
| 19419 |
end if; |
| 19420 |
|
| 19421 |
Par := Parent (Par); |
| 19422 |
end loop; |
| 19423 |
|
| 19424 |
return False; |
| 19425 |
end Within_Check; |
| 19426 |
|
| 19427 |
------------------------------ |
| 19428 |
-- Within_Volatile_Function -- |
| 19429 |
------------------------------ |
| 19430 |
|
| 19431 |
function Within_Volatile_Function (Id : Entity_Id) return Boolean is |
| 19432 |
pragma Assert (Ekind (Id) = E_Return_Statement); |
| 19433 |
|
| 19434 |
Func_Id : constant Entity_Id := Return_Applies_To (Id); |
| 19435 |
|
| 19436 |
begin |
| 19437 |
pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function); |
| 19438 |
|
| 19439 |
return Is_Volatile_Function (Func_Id); |
| 19440 |
end Within_Volatile_Function; |
| 19441 |
|
| 19442 |
-- Local variables |
| 19443 |
|
| 19444 |
Obj_Id : Entity_Id; |
| 19445 |
|
| 19446 |
-- Start of processing for Is_OK_Volatile_Context |
| 19447 |
|
| 19448 |
begin |
| 19449 |
-- Ignore context restriction when doing preanalysis, e.g. on a copy of |
| 19450 |
-- an expression function, because this copy is not fully decorated and |
| 19451 |
-- it is not possible to reliably decide the legality of the context. |
| 19452 |
-- Any violations will be reported anyway when doing the full analysis. |
| 19453 |
|
| 19454 |
if not Full_Analysis then |
| 19455 |
return True; |
| 19456 |
end if; |
| 19457 |
|
| 19458 |
-- For actual parameters within explicit parameter associations switch |
| 19459 |
-- the context to the corresponding subprogram call. |
| 19460 |
|
| 19461 |
if Nkind (Context) = N_Parameter_Association then |
| 19462 |
return Is_OK_Volatile_Context (Context => Parent (Context), |
| 19463 |
Obj_Ref => Obj_Ref, |
| 19464 |
Check_Actuals => Check_Actuals); |
| 19465 |
|
| 19466 |
-- The volatile object appears on either side of an assignment |
| 19467 |
|
| 19468 |
elsif Nkind (Context) = N_Assignment_Statement then |
| 19469 |
return True; |
| 19470 |
|
| 19471 |
-- The volatile object is part of the initialization expression of |
| 19472 |
-- another object. |
| 19473 |
|
| 19474 |
elsif Nkind (Context) = N_Object_Declaration |
| 19475 |
and then Present (Expression (Context)) |
| 19476 |
and then Expression (Context) = Obj_Ref |
| 19477 |
and then Nkind (Parent (Context)) /= N_Expression_With_Actions |
| 19478 |
then |
| 19479 |
Obj_Id := Defining_Entity (Context); |
| 19480 |
|
| 19481 |
-- The volatile object acts as the initialization expression of an |
| 19482 |
-- extended return statement. This is valid context as long as the |
| 19483 |
-- function is volatile. |
| 19484 |
|
| 19485 |
if Is_Return_Object (Obj_Id) then |
| 19486 |
return Within_Volatile_Function (Scope (Obj_Id)); |
| 19487 |
|
| 19488 |
-- Otherwise this is a normal object initialization |
| 19489 |
|
| 19490 |
else |
| 19491 |
return True; |
| 19492 |
end if; |
| 19493 |
|
| 19494 |
-- The volatile object acts as the name of a renaming declaration |
| 19495 |
|
| 19496 |
elsif Nkind (Context) = N_Object_Renaming_Declaration |
| 19497 |
and then Name (Context) = Obj_Ref |
| 19498 |
then |
| 19499 |
return True; |
| 19500 |
|
| 19501 |
-- The volatile object appears as an actual parameter in a call to an |
| 19502 |
-- instance of Unchecked_Conversion whose result is renamed. |
| 19503 |
|
| 19504 |
elsif Nkind (Context) = N_Function_Call |
| 19505 |
and then Is_Entity_Name (Name (Context)) |
| 19506 |
and then Is_Unchecked_Conversion_Instance (Entity (Name (Context))) |
| 19507 |
and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration |
| 19508 |
then |
| 19509 |
return True; |
| 19510 |
|
| 19511 |
-- The volatile object is actually the prefix in a protected entry, |
| 19512 |
-- function, or procedure call. |
| 19513 |
|
| 19514 |
elsif Is_Protected_Operation_Call (Context) then |
| 19515 |
return True; |
| 19516 |
|
| 19517 |
-- The volatile object appears as the expression of a simple return |
| 19518 |
-- statement that applies to a volatile function. |
| 19519 |
|
| 19520 |
elsif Nkind (Context) = N_Simple_Return_Statement |
| 19521 |
and then Expression (Context) = Obj_Ref |
| 19522 |
then |
| 19523 |
return |
| 19524 |
Within_Volatile_Function (Return_Statement_Entity (Context)); |
| 19525 |
|
| 19526 |
-- The volatile object appears as the prefix of a name occurring in a |
| 19527 |
-- non-interfering context. |
| 19528 |
|
| 19529 |
elsif Nkind (Context) in |
| 19530 |
N_Attribute_Reference | |
| 19531 |
N_Explicit_Dereference | |
| 19532 |
N_Indexed_Component | |
| 19533 |
N_Selected_Component | |
| 19534 |
N_Slice |
| 19535 |
and then Prefix (Context) = Obj_Ref |
| 19536 |
and then Is_OK_Volatile_Context |
| 19537 |
(Context => Parent (Context), |
| 19538 |
Obj_Ref => Context, |
| 19539 |
Check_Actuals => Check_Actuals) |
| 19540 |
then |
| 19541 |
return True; |
| 19542 |
|
| 19543 |
-- The volatile object appears as the prefix of attributes Address, |
| 19544 |
-- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length, |
| 19545 |
-- Position, Size, Storage_Size. |
| 19546 |
|
| 19547 |
elsif Nkind (Context) = N_Attribute_Reference |
| 19548 |
and then Prefix (Context) = Obj_Ref |
| 19549 |
and then Attribute_Name (Context) in Name_Address |
| 19550 |
| Name_Alignment |
| 19551 |
| Name_Component_Size |
| 19552 |
| Name_First |
| 19553 |
| Name_First_Bit |
| 19554 |
| Name_Last |
| 19555 |
| Name_Last_Bit |
| 19556 |
| Name_Length |
| 19557 |
| Name_Position |
| 19558 |
| Name_Size |
| 19559 |
| Name_Storage_Size |
| 19560 |
then |
| 19561 |
return True; |
| 19562 |
|
| 19563 |
-- The volatile object appears as the expression of a type conversion |
| 19564 |
-- occurring in a non-interfering context. |
| 19565 |
|
| 19566 |
elsif Nkind (Context) in N_Qualified_Expression |
| 19567 |
| N_Type_Conversion |
| 19568 |
| N_Unchecked_Type_Conversion |
| 19569 |
and then Expression (Context) = Obj_Ref |
| 19570 |
and then Is_OK_Volatile_Context |
| 19571 |
(Context => Parent (Context), |
| 19572 |
Obj_Ref => Context, |
| 19573 |
Check_Actuals => Check_Actuals) |
| 19574 |
then |
| 19575 |
return True; |
| 19576 |
|
| 19577 |
-- The volatile object appears as the expression in a delay statement |
| 19578 |
|
| 19579 |
elsif Nkind (Context) in N_Delay_Statement then |
| 19580 |
return True; |
| 19581 |
|
| 19582 |
-- Allow references to volatile objects in various checks. This is not a |
| 19583 |
-- direct SPARK 2014 requirement. |
| 19584 |
|
| 19585 |
elsif Within_Check (Context) then |
| 19586 |
return True; |
| 19587 |
|
| 19588 |
-- References to effectively volatile objects that appear as actual |
| 19589 |
-- parameters in subprogram calls can be examined only after call itself |
| 19590 |
-- has been resolved. Before that, assume such references to be legal. |
| 19591 |
|
| 19592 |
elsif Nkind (Context) in N_Subprogram_Call | N_Entry_Call_Statement then |
| 19593 |
if Check_Actuals then |
| 19594 |
declare |
| 19595 |
Call : Node_Id; |
| 19596 |
Formal : Entity_Id; |
| 19597 |
Subp : constant Entity_Id := Get_Called_Entity (Context); |
| 19598 |
begin |
| 19599 |
Find_Actual (Obj_Ref, Formal, Call); |
| 19600 |
pragma Assert (Call = Context); |
| 19601 |
|
| 19602 |
-- An effectively volatile object may act as an actual when the |
| 19603 |
-- corresponding formal is of a non-scalar effectively volatile |
| 19604 |
-- type (SPARK RM 7.1.3(9)). |
| 19605 |
|
| 19606 |
if not Is_Scalar_Type (Etype (Formal)) |
| 19607 |
and then Is_Effectively_Volatile_For_Reading (Etype (Formal)) |
| 19608 |
then |
| 19609 |
return True; |
| 19610 |
|
| 19611 |
-- An effectively volatile object may act as an actual in a |
| 19612 |
-- call to an instance of Unchecked_Conversion. (SPARK RM |
| 19613 |
-- 7.1.3(9)). |
| 19614 |
|
| 19615 |
elsif Is_Unchecked_Conversion_Instance (Subp) then |
| 19616 |
return True; |
| 19617 |
|
| 19618 |
else |
| 19619 |
return False; |
| 19620 |
end if; |
| 19621 |
end; |
| 19622 |
else |
| 19623 |
return True; |
| 19624 |
end if; |
| 19625 |
else |
| 19626 |
return False; |
| 19627 |
end if; |
| 19628 |
end Is_OK_Volatile_Context; |
| 19629 |
|
| 19630 |
------------------------------------ |
| 19631 |
-- Is_Package_Contract_Annotation -- |
| 19632 |
------------------------------------ |
| 19633 |
|
| 19634 |
function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is |
| 19635 |
Nam : Name_Id; |
| 19636 |
|
| 19637 |
begin |
| 19638 |
if Nkind (Item) = N_Aspect_Specification then |
| 19639 |
Nam := Chars (Identifier (Item)); |
| 19640 |
|
| 19641 |
else pragma Assert (Nkind (Item) = N_Pragma); |
| 19642 |
Nam := Pragma_Name (Item); |
| 19643 |
end if; |
| 19644 |
|
| 19645 |
return Nam = Name_Abstract_State |
| 19646 |
or else Nam = Name_Initial_Condition |
| 19647 |
or else Nam = Name_Initializes |
| 19648 |
or else Nam = Name_Refined_State; |
| 19649 |
end Is_Package_Contract_Annotation; |
| 19650 |
|
| 19651 |
----------------------------------- |
| 19652 |
-- Is_Partially_Initialized_Type -- |
| 19653 |
----------------------------------- |
| 19654 |
|
| 19655 |
function Is_Partially_Initialized_Type |
| 19656 |
(Typ : Entity_Id; |
| 19657 |
Include_Implicit : Boolean := True) return Boolean |
| 19658 |
is |
| 19659 |
begin |
| 19660 |
if Is_Scalar_Type (Typ) then |
| 19661 |
return Has_Default_Aspect (Base_Type (Typ)); |
| 19662 |
|
| 19663 |
elsif Is_Access_Type (Typ) then |
| 19664 |
return Include_Implicit; |
| 19665 |
|
| 19666 |
elsif Is_Array_Type (Typ) then |
| 19667 |
|
| 19668 |
-- If component type is partially initialized, so is array type |
| 19669 |
|
| 19670 |
if Has_Default_Aspect (Base_Type (Typ)) |
| 19671 |
or else Is_Partially_Initialized_Type |
| 19672 |
(Component_Type (Typ), Include_Implicit) |
| 19673 |
then |
| 19674 |
return True; |
| 19675 |
|
| 19676 |
-- Otherwise we are only partially initialized if we are fully |
| 19677 |
-- initialized (this is the empty array case, no point in us |
| 19678 |
-- duplicating that code here). |
| 19679 |
|
| 19680 |
else |
| 19681 |
return Is_Fully_Initialized_Type (Typ); |
| 19682 |
end if; |
| 19683 |
|
| 19684 |
elsif Is_Record_Type (Typ) then |
| 19685 |
|
| 19686 |
-- A discriminated type is always partially initialized if in |
| 19687 |
-- all mode |
| 19688 |
|
| 19689 |
if Has_Discriminants (Typ) and then Include_Implicit then |
| 19690 |
return True; |
| 19691 |
|
| 19692 |
-- A tagged type is always partially initialized |
| 19693 |
|
| 19694 |
elsif Is_Tagged_Type (Typ) then |
| 19695 |
return True; |
| 19696 |
|
| 19697 |
-- Case of nondiscriminated record |
| 19698 |
|
| 19699 |
else |
| 19700 |
declare |
| 19701 |
Comp : Entity_Id; |
| 19702 |
|
| 19703 |
Component_Present : Boolean := False; |
| 19704 |
-- Set True if at least one component is present. If no |
| 19705 |
-- components are present, then record type is fully |
| 19706 |
-- initialized (another odd case, like the null array). |
| 19707 |
|
| 19708 |
begin |
| 19709 |
-- Loop through components |
| 19710 |
|
| 19711 |
Comp := First_Component (Typ); |
| 19712 |
while Present (Comp) loop |
| 19713 |
Component_Present := True; |
| 19714 |
|
| 19715 |
-- If a component has an initialization expression then the |
| 19716 |
-- enclosing record type is partially initialized |
| 19717 |
|
| 19718 |
if Present (Parent (Comp)) |
| 19719 |
and then Present (Expression (Parent (Comp))) |
| 19720 |
then |
| 19721 |
return True; |
| 19722 |
|
| 19723 |
-- If a component is of a type which is itself partially |
| 19724 |
-- initialized, then the enclosing record type is also. |
| 19725 |
|
| 19726 |
elsif Is_Partially_Initialized_Type |
| 19727 |
(Etype (Comp), Include_Implicit) |
| 19728 |
then |
| 19729 |
return True; |
| 19730 |
end if; |
| 19731 |
|
| 19732 |
Next_Component (Comp); |
| 19733 |
end loop; |
| 19734 |
|
| 19735 |
-- No initialized components found. If we found any components |
| 19736 |
-- they were all uninitialized so the result is false. |
| 19737 |
|
| 19738 |
if Component_Present then |
| 19739 |
return False; |
| 19740 |
|
| 19741 |
-- But if we found no components, then all the components are |
| 19742 |
-- initialized so we consider the type to be initialized. |
| 19743 |
|
| 19744 |
else |
| 19745 |
return True; |
| 19746 |
end if; |
| 19747 |
end; |
| 19748 |
end if; |
| 19749 |
|
| 19750 |
-- Concurrent types are always fully initialized |
| 19751 |
|
| 19752 |
elsif Is_Concurrent_Type (Typ) then |
| 19753 |
return True; |
| 19754 |
|
| 19755 |
-- For a private type, go to underlying type. If there is no underlying |
| 19756 |
-- type then just assume this partially initialized. Not clear if this |
| 19757 |
-- can happen in a non-error case, but no harm in testing for this. |
| 19758 |
|
| 19759 |
elsif Is_Private_Type (Typ) then |
| 19760 |
declare |
| 19761 |
U : constant Entity_Id := Underlying_Type (Typ); |
| 19762 |
begin |
| 19763 |
if No (U) then |
| 19764 |
return True; |
| 19765 |
else |
| 19766 |
return Is_Partially_Initialized_Type (U, Include_Implicit); |
| 19767 |
end if; |
| 19768 |
end; |
| 19769 |
|
| 19770 |
-- For any other type (are there any?) assume partially initialized |
| 19771 |
|
| 19772 |
else |
| 19773 |
return True; |
| 19774 |
end if; |
| 19775 |
end Is_Partially_Initialized_Type; |
| 19776 |
|
| 19777 |
------------------------------------ |
| 19778 |
-- Is_Potentially_Persistent_Type -- |
| 19779 |
------------------------------------ |
| 19780 |
|
| 19781 |
function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is |
| 19782 |
Comp : Entity_Id; |
| 19783 |
Indx : Node_Id; |
| 19784 |
|
| 19785 |
begin |
| 19786 |
-- For private type, test corresponding full type |
| 19787 |
|
| 19788 |
if Is_Private_Type (T) then |
| 19789 |
return Is_Potentially_Persistent_Type (Full_View (T)); |
| 19790 |
|
| 19791 |
-- Scalar types are potentially persistent |
| 19792 |
|
| 19793 |
elsif Is_Scalar_Type (T) then |
| 19794 |
return True; |
| 19795 |
|
| 19796 |
-- Record type is potentially persistent if not tagged and the types of |
| 19797 |
-- all it components are potentially persistent, and no component has |
| 19798 |
-- an initialization expression. |
| 19799 |
|
| 19800 |
elsif Is_Record_Type (T) |
| 19801 |
and then not Is_Tagged_Type (T) |
| 19802 |
and then not Is_Partially_Initialized_Type (T) |
| 19803 |
then |
| 19804 |
Comp := First_Component (T); |
| 19805 |
while Present (Comp) loop |
| 19806 |
if not Is_Potentially_Persistent_Type (Etype (Comp)) then |
| 19807 |
return False; |
| 19808 |
else |
| 19809 |
Next_Entity (Comp); |
| 19810 |
end if; |
| 19811 |
end loop; |
| 19812 |
|
| 19813 |
return True; |
| 19814 |
|
| 19815 |
-- Array type is potentially persistent if its component type is |
| 19816 |
-- potentially persistent and if all its constraints are static. |
| 19817 |
|
| 19818 |
elsif Is_Array_Type (T) then |
| 19819 |
if not Is_Potentially_Persistent_Type (Component_Type (T)) then |
| 19820 |
return False; |
| 19821 |
end if; |
| 19822 |
|
| 19823 |
Indx := First_Index (T); |
| 19824 |
while Present (Indx) loop |
| 19825 |
if not Is_OK_Static_Subtype (Etype (Indx)) then |
| 19826 |
return False; |
| 19827 |
else |
| 19828 |
Next_Index (Indx); |
| 19829 |
end if; |
| 19830 |
end loop; |
| 19831 |
|
| 19832 |
return True; |
| 19833 |
|
| 19834 |
-- All other types are not potentially persistent |
| 19835 |
|
| 19836 |
else |
| 19837 |
return False; |
| 19838 |
end if; |
| 19839 |
end Is_Potentially_Persistent_Type; |
| 19840 |
|
| 19841 |
-------------------------------- |
| 19842 |
-- Is_Potentially_Unevaluated -- |
| 19843 |
-------------------------------- |
| 19844 |
|
| 19845 |
function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is |
| 19846 |
function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean; |
| 19847 |
-- Aggr is an array aggregate with static bounds and an others clause; |
| 19848 |
-- return True if the others choice of the given array aggregate does |
| 19849 |
-- not cover any component (i.e. is null). |
| 19850 |
|
| 19851 |
function Immediate_Context_Implies_Is_Potentially_Unevaluated |
| 19852 |
(Expr : Node_Id) return Boolean; |
| 19853 |
-- Return True if the *immediate* context of this expression tells us |
| 19854 |
-- that it is potentially unevaluated; return False if the *immediate* |
| 19855 |
-- context doesn't provide an answer to this question and we need to |
| 19856 |
-- keep looking. |
| 19857 |
|
| 19858 |
function Non_Static_Or_Null_Range (N : Node_Id) return Boolean; |
| 19859 |
-- Return True if the given range is nonstatic or null |
| 19860 |
|
| 19861 |
---------------------------- |
| 19862 |
-- Has_Null_Others_Choice -- |
| 19863 |
---------------------------- |
| 19864 |
|
| 19865 |
function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean is |
| 19866 |
Idx : constant Node_Id := First_Index (Etype (Aggr)); |
| 19867 |
Hiv : constant Uint := Expr_Value (Type_High_Bound (Etype (Idx))); |
| 19868 |
Lov : constant Uint := Expr_Value (Type_Low_Bound (Etype (Idx))); |
| 19869 |
|
| 19870 |
begin |
| 19871 |
declare |
| 19872 |
Intervals : constant Interval_Lists.Discrete_Interval_List := |
| 19873 |
Interval_Lists.Aggregate_Intervals (Aggr); |
| 19874 |
|
| 19875 |
begin |
| 19876 |
-- The others choice is null if, after normalization, we |
| 19877 |
-- have a single interval covering the whole aggregate. |
| 19878 |
|
| 19879 |
return Intervals'Length = 1 |
| 19880 |
and then |
| 19881 |
Intervals (Intervals'First).Low = Lov |
| 19882 |
and then |
| 19883 |
Intervals (Intervals'First).High = Hiv; |
| 19884 |
end; |
| 19885 |
|
| 19886 |
-- If the aggregate is malformed (that is, indexes are not disjoint) |
| 19887 |
-- then no action is needed at this stage; the error will be reported |
| 19888 |
-- later by the frontend. |
| 19889 |
|
| 19890 |
exception |
| 19891 |
when Interval_Lists.Intervals_Error => |
| 19892 |
return False; |
| 19893 |
end Has_Null_Others_Choice; |
| 19894 |
|
| 19895 |
---------------------------------------------------------- |
| 19896 |
-- Immediate_Context_Implies_Is_Potentially_Unevaluated -- |
| 19897 |
---------------------------------------------------------- |
| 19898 |
|
| 19899 |
function Immediate_Context_Implies_Is_Potentially_Unevaluated |
| 19900 |
(Expr : Node_Id) return Boolean |
| 19901 |
is |
| 19902 |
Par : constant Node_Id := Parent (Expr); |
| 19903 |
|
| 19904 |
function Aggregate_Type return Node_Id is (Etype (Parent (Par))); |
| 19905 |
begin |
| 19906 |
if Nkind (Par) = N_If_Expression then |
| 19907 |
return Is_Elsif (Par) or else Expr /= First (Expressions (Par)); |
| 19908 |
|
| 19909 |
elsif Nkind (Par) = N_Case_Expression then |
| 19910 |
return Expr /= Expression (Par); |
| 19911 |
|
| 19912 |
elsif Nkind (Par) in N_Short_Circuit then |
| 19913 |
return Expr = Right_Opnd (Par); |
| 19914 |
|
| 19915 |
elsif Nkind (Par) in N_Membership_Test then |
| 19916 |
|
| 19917 |
-- If the membership includes several alternatives, only the first |
| 19918 |
-- is definitely evaluated. |
| 19919 |
|
| 19920 |
if Present (Alternatives (Par)) then |
| 19921 |
return Expr /= First (Alternatives (Par)); |
| 19922 |
|
| 19923 |
-- If this is a range membership both bounds are evaluated |
| 19924 |
|
| 19925 |
else |
| 19926 |
return False; |
| 19927 |
end if; |
| 19928 |
|
| 19929 |
elsif Nkind (Par) = N_Quantified_Expression then |
| 19930 |
return Expr = Condition (Par); |
| 19931 |
|
| 19932 |
elsif Nkind (Par) in N_Component_Association |
| 19933 |
| N_Iterated_Component_Association |
| 19934 |
and then Expr = Expression (Par) |
| 19935 |
and then Nkind (Parent (Par)) |
| 19936 |
in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate |
| 19937 |
and then Present (Aggregate_Type) |
| 19938 |
and then Aggregate_Type /= Any_Composite |
| 19939 |
then |
| 19940 |
if Is_Array_Type (Aggregate_Type) then |
| 19941 |
if Ada_Version >= Ada_2022 then |
| 19942 |
-- For Ada 2022, this predicate returns True for |
| 19943 |
-- any "repeatedly evaluated" expression. |
| 19944 |
return True; |
| 19945 |
end if; |
| 19946 |
|
| 19947 |
declare |
| 19948 |
Choice : Node_Id; |
| 19949 |
In_Others_Choice : Boolean := False; |
| 19950 |
Array_Agg : constant Node_Id := Parent (Par); |
| 19951 |
begin |
| 19952 |
-- The expression of an array_component_association is |
| 19953 |
-- potentially unevaluated if the associated choice is a |
| 19954 |
-- subtype_indication or range that defines a nonstatic or |
| 19955 |
-- null range. |
| 19956 |
|
| 19957 |
Choice := First (Choices (Par)); |
| 19958 |
while Present (Choice) loop |
| 19959 |
if Nkind (Choice) = N_Range |
| 19960 |
and then Non_Static_Or_Null_Range (Choice) |
| 19961 |
then |
| 19962 |
return True; |
| 19963 |
|
| 19964 |
elsif Nkind (Choice) = N_Identifier |
| 19965 |
and then Present (Scalar_Range (Etype (Choice))) |
| 19966 |
and then |
| 19967 |
Non_Static_Or_Null_Range |
| 19968 |
(Scalar_Range (Etype (Choice))) |
| 19969 |
then |
| 19970 |
return True; |
| 19971 |
|
| 19972 |
elsif Nkind (Choice) = N_Others_Choice then |
| 19973 |
In_Others_Choice := True; |
| 19974 |
end if; |
| 19975 |
|
| 19976 |
Next (Choice); |
| 19977 |
end loop; |
| 19978 |
|
| 19979 |
-- It is also potentially unevaluated if the associated |
| 19980 |
-- choice is an others choice and the applicable index |
| 19981 |
-- constraint is nonstatic or null. |
| 19982 |
|
| 19983 |
if In_Others_Choice then |
| 19984 |
if not Compile_Time_Known_Bounds (Aggregate_Type) then |
| 19985 |
return True; |
| 19986 |
else |
| 19987 |
return Has_Null_Others_Choice (Array_Agg); |
| 19988 |
end if; |
| 19989 |
end if; |
| 19990 |
end; |
| 19991 |
|
| 19992 |
elsif Is_Container_Aggregate (Parent (Par)) then |
| 19993 |
-- a component of a container aggregate |
| 19994 |
return True; |
| 19995 |
end if; |
| 19996 |
|
| 19997 |
return False; |
| 19998 |
|
| 19999 |
else |
| 20000 |
return False; |
| 20001 |
end if; |
| 20002 |
end Immediate_Context_Implies_Is_Potentially_Unevaluated; |
| 20003 |
|
| 20004 |
------------------------------ |
| 20005 |
-- Non_Static_Or_Null_Range -- |
| 20006 |
------------------------------ |
| 20007 |
|
| 20008 |
function Non_Static_Or_Null_Range (N : Node_Id) return Boolean is |
| 20009 |
Low, High : Node_Id; |
| 20010 |
|
| 20011 |
begin |
| 20012 |
Get_Index_Bounds (N, Low, High); |
| 20013 |
|
| 20014 |
-- Check static bounds |
| 20015 |
|
| 20016 |
if not Compile_Time_Known_Value (Low) |
| 20017 |
or else not Compile_Time_Known_Value (High) |
| 20018 |
then |
| 20019 |
return True; |
| 20020 |
|
| 20021 |
-- Check null range |
| 20022 |
|
| 20023 |
elsif Expr_Value (High) < Expr_Value (Low) then |
| 20024 |
return True; |
| 20025 |
end if; |
| 20026 |
|
| 20027 |
return False; |
| 20028 |
end Non_Static_Or_Null_Range; |
| 20029 |
|
| 20030 |
-- Local variables |
| 20031 |
|
| 20032 |
Expr : Node_Id; |
| 20033 |
Par : Node_Id; |
| 20034 |
|
| 20035 |
-- Start of processing for Is_Potentially_Unevaluated |
| 20036 |
|
| 20037 |
begin |
| 20038 |
Expr := N; |
| 20039 |
Par := Parent (Expr); |
| 20040 |
|
| 20041 |
while Present (Par) |
| 20042 |
and then Nkind (Par) /= N_Pragma_Argument_Association |
| 20043 |
loop |
| 20044 |
if Comes_From_Source (Par) |
| 20045 |
and then |
| 20046 |
Immediate_Context_Implies_Is_Potentially_Unevaluated (Expr) |
| 20047 |
then |
| 20048 |
return True; |
| 20049 |
|
| 20050 |
-- For component associations continue climbing; it may be part of an |
| 20051 |
-- array aggregate. For iterated component association we know that |
| 20052 |
-- it belongs to an array aggreate, but only its expression is |
| 20053 |
-- potentially unevaluated, not discrete choice list or iterator |
| 20054 |
-- specification. |
| 20055 |
|
| 20056 |
elsif Nkind (Par) in N_Component_Association |
| 20057 |
| N_Iterated_Component_Association |
| 20058 |
then |
| 20059 |
null; |
| 20060 |
|
| 20061 |
-- If the context is not an expression, or if is the result of |
| 20062 |
-- expansion of an enclosing construct (such as another attribute) |
| 20063 |
-- the predicate does not apply. |
| 20064 |
|
| 20065 |
elsif Nkind (Par) = N_Case_Expression_Alternative then |
| 20066 |
null; |
| 20067 |
|
| 20068 |
elsif Nkind (Par) not in N_Subexpr |
| 20069 |
or else not Comes_From_Source (Par) |
| 20070 |
then |
| 20071 |
return False; |
| 20072 |
end if; |
| 20073 |
|
| 20074 |
Expr := Par; |
| 20075 |
Par := Parent (Par); |
| 20076 |
end loop; |
| 20077 |
|
| 20078 |
return False; |
| 20079 |
end Is_Potentially_Unevaluated; |
| 20080 |
|
| 20081 |
----------------------------------------- |
| 20082 |
-- Is_Predefined_Dispatching_Operation -- |
| 20083 |
----------------------------------------- |
| 20084 |
|
| 20085 |
function Is_Predefined_Dispatching_Operation |
| 20086 |
(E : Entity_Id) return Boolean |
| 20087 |
is |
| 20088 |
TSS_Name : TSS_Name_Type; |
| 20089 |
|
| 20090 |
begin |
| 20091 |
if not Is_Dispatching_Operation (E) then |
| 20092 |
return False; |
| 20093 |
end if; |
| 20094 |
|
| 20095 |
Get_Name_String (Chars (E)); |
| 20096 |
|
| 20097 |
-- Most predefined primitives have internally generated names. Equality |
| 20098 |
-- must be treated differently; the predefined operation is recognized |
| 20099 |
-- as a homogeneous binary operator that returns Boolean. |
| 20100 |
|
| 20101 |
if Name_Len > TSS_Name_Type'Last then |
| 20102 |
TSS_Name := |
| 20103 |
TSS_Name_Type |
| 20104 |
(Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len)); |
| 20105 |
|
| 20106 |
if Chars (E) in Name_uAssign | Name_uSize |
| 20107 |
or else |
| 20108 |
(Chars (E) = Name_Op_Eq |
| 20109 |
and then Etype (First_Formal (E)) = Etype (Last_Formal (E))) |
| 20110 |
or else TSS_Name = TSS_Deep_Adjust |
| 20111 |
or else TSS_Name = TSS_Deep_Finalize |
| 20112 |
or else TSS_Name = TSS_Stream_Input |
| 20113 |
or else TSS_Name = TSS_Stream_Output |
| 20114 |
or else TSS_Name = TSS_Stream_Read |
| 20115 |
or else TSS_Name = TSS_Stream_Write |
| 20116 |
or else TSS_Name = TSS_Put_Image |
| 20117 |
or else Is_Predefined_Interface_Primitive (E) |
| 20118 |
then |
| 20119 |
return True; |
| 20120 |
end if; |
| 20121 |
end if; |
| 20122 |
|
| 20123 |
return False; |
| 20124 |
end Is_Predefined_Dispatching_Operation; |
| 20125 |
|
| 20126 |
--------------------------------------- |
| 20127 |
-- Is_Predefined_Interface_Primitive -- |
| 20128 |
--------------------------------------- |
| 20129 |
|
| 20130 |
function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is |
| 20131 |
begin |
| 20132 |
-- In VM targets we don't restrict the functionality of this test to |
| 20133 |
-- compiling in Ada 2005 mode since in VM targets any tagged type has |
| 20134 |
-- these primitives. |
| 20135 |
|
| 20136 |
return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion) |
| 20137 |
and then Chars (E) in Name_uDisp_Asynchronous_Select |
| 20138 |
| Name_uDisp_Conditional_Select |
| 20139 |
| Name_uDisp_Get_Prim_Op_Kind |
| 20140 |
| Name_uDisp_Get_Task_Id |
| 20141 |
| Name_uDisp_Requeue |
| 20142 |
| Name_uDisp_Timed_Select; |
| 20143 |
end Is_Predefined_Interface_Primitive; |
| 20144 |
|
| 20145 |
--------------------------------------- |
| 20146 |
-- Is_Predefined_Internal_Operation -- |
| 20147 |
--------------------------------------- |
| 20148 |
|
| 20149 |
function Is_Predefined_Internal_Operation |
| 20150 |
(E : Entity_Id) return Boolean |
| 20151 |
is |
| 20152 |
TSS_Name : TSS_Name_Type; |
| 20153 |
|
| 20154 |
begin |
| 20155 |
if not Is_Dispatching_Operation (E) then |
| 20156 |
return False; |
| 20157 |
end if; |
| 20158 |
|
| 20159 |
Get_Name_String (Chars (E)); |
| 20160 |
|
| 20161 |
-- Most predefined primitives have internally generated names. Equality |
| 20162 |
-- must be treated differently; the predefined operation is recognized |
| 20163 |
-- as a homogeneous binary operator that returns Boolean. |
| 20164 |
|
| 20165 |
if Name_Len > TSS_Name_Type'Last then |
| 20166 |
TSS_Name := |
| 20167 |
TSS_Name_Type |
| 20168 |
(Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len)); |
| 20169 |
|
| 20170 |
if Chars (E) in Name_uSize | Name_uAssign |
| 20171 |
or else |
| 20172 |
(Chars (E) = Name_Op_Eq |
| 20173 |
and then Etype (First_Formal (E)) = Etype (Last_Formal (E))) |
| 20174 |
or else TSS_Name = TSS_Deep_Adjust |
| 20175 |
or else TSS_Name = TSS_Deep_Finalize |
| 20176 |
or else Is_Predefined_Interface_Primitive (E) |
| 20177 |
then |
| 20178 |
return True; |
| 20179 |
end if; |
| 20180 |
end if; |
| 20181 |
|
| 20182 |
return False; |
| 20183 |
end Is_Predefined_Internal_Operation; |
| 20184 |
|
| 20185 |
-------------------------------- |
| 20186 |
-- Is_Preelaborable_Aggregate -- |
| 20187 |
-------------------------------- |
| 20188 |
|
| 20189 |
function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is |
| 20190 |
Aggr_Typ : constant Entity_Id := Etype (Aggr); |
| 20191 |
Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ); |
| 20192 |
|
| 20193 |
Anc_Part : Node_Id; |
| 20194 |
Assoc : Node_Id; |
| 20195 |
Choice : Node_Id; |
| 20196 |
Comp_Typ : Entity_Id := Empty; -- init to avoid warning |
| 20197 |
Expr : Node_Id; |
| 20198 |
|
| 20199 |
begin |
| 20200 |
if Array_Aggr then |
| 20201 |
Comp_Typ := Component_Type (Aggr_Typ); |
| 20202 |
end if; |
| 20203 |
|
| 20204 |
-- Inspect the ancestor part |
| 20205 |
|
| 20206 |
if Nkind (Aggr) = N_Extension_Aggregate then |
| 20207 |
Anc_Part := Ancestor_Part (Aggr); |
| 20208 |
|
| 20209 |
-- The ancestor denotes a subtype mark |
| 20210 |
|
| 20211 |
if Is_Entity_Name (Anc_Part) |
| 20212 |
and then Is_Type (Entity (Anc_Part)) |
| 20213 |
then |
| 20214 |
if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then |
| 20215 |
return False; |
| 20216 |
end if; |
| 20217 |
|
| 20218 |
-- Otherwise the ancestor denotes an expression |
| 20219 |
|
| 20220 |
elsif not Is_Preelaborable_Construct (Anc_Part) then |
| 20221 |
return False; |
| 20222 |
end if; |
| 20223 |
end if; |
| 20224 |
|
| 20225 |
-- Inspect the positional associations |
| 20226 |
|
| 20227 |
Expr := First (Expressions (Aggr)); |
| 20228 |
while Present (Expr) loop |
| 20229 |
if not Is_Preelaborable_Construct (Expr) then |
| 20230 |
return False; |
| 20231 |
end if; |
| 20232 |
|
| 20233 |
Next (Expr); |
| 20234 |
end loop; |
| 20235 |
|
| 20236 |
-- Inspect the named associations |
| 20237 |
|
| 20238 |
Assoc := First (Component_Associations (Aggr)); |
| 20239 |
while Present (Assoc) loop |
| 20240 |
|
| 20241 |
-- Inspect the choices of the current named association |
| 20242 |
|
| 20243 |
Choice := First (Choices (Assoc)); |
| 20244 |
while Present (Choice) loop |
| 20245 |
if Array_Aggr then |
| 20246 |
|
| 20247 |
-- For a choice to be preelaborable, it must denote either a |
| 20248 |
-- static range or a static expression. |
| 20249 |
|
| 20250 |
if Nkind (Choice) = N_Others_Choice then |
| 20251 |
null; |
| 20252 |
|
| 20253 |
elsif Nkind (Choice) = N_Range then |
| 20254 |
if not Is_OK_Static_Range (Choice) then |
| 20255 |
return False; |
| 20256 |
end if; |
| 20257 |
|
| 20258 |
elsif not Is_OK_Static_Expression (Choice) then |
| 20259 |
return False; |
| 20260 |
end if; |
| 20261 |
|
| 20262 |
else |
| 20263 |
Comp_Typ := Etype (Choice); |
| 20264 |
end if; |
| 20265 |
|
| 20266 |
Next (Choice); |
| 20267 |
end loop; |
| 20268 |
|
| 20269 |
-- The type of the choice must have preelaborable initialization if |
| 20270 |
-- the association carries a <>. |
| 20271 |
|
| 20272 |
pragma Assert (Present (Comp_Typ)); |
| 20273 |
if Box_Present (Assoc) then |
| 20274 |
if not Has_Preelaborable_Initialization (Comp_Typ) then |
| 20275 |
return False; |
| 20276 |
end if; |
| 20277 |
|
| 20278 |
-- The type of the expression must have preelaborable initialization |
| 20279 |
|
| 20280 |
elsif not Is_Preelaborable_Construct (Expression (Assoc)) then |
| 20281 |
return False; |
| 20282 |
end if; |
| 20283 |
|
| 20284 |
Next (Assoc); |
| 20285 |
end loop; |
| 20286 |
|
| 20287 |
-- At this point the aggregate is preelaborable |
| 20288 |
|
| 20289 |
return True; |
| 20290 |
end Is_Preelaborable_Aggregate; |
| 20291 |
|
| 20292 |
-------------------------------- |
| 20293 |
-- Is_Preelaborable_Construct -- |
| 20294 |
-------------------------------- |
| 20295 |
|
| 20296 |
function Is_Preelaborable_Construct (N : Node_Id) return Boolean is |
| 20297 |
begin |
| 20298 |
-- Aggregates |
| 20299 |
|
| 20300 |
if Nkind (N) in N_Aggregate | N_Extension_Aggregate then |
| 20301 |
return Is_Preelaborable_Aggregate (N); |
| 20302 |
|
| 20303 |
-- Attributes are allowed in general, even if their prefix is a formal |
| 20304 |
-- type. It seems that certain attributes known not to be static might |
| 20305 |
-- not be allowed, but there are no rules to prevent them. |
| 20306 |
|
| 20307 |
elsif Nkind (N) = N_Attribute_Reference then |
| 20308 |
return True; |
| 20309 |
|
| 20310 |
-- Expressions |
| 20311 |
|
| 20312 |
elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then |
| 20313 |
return True; |
| 20314 |
|
| 20315 |
elsif Nkind (N) = N_Qualified_Expression then |
| 20316 |
return Is_Preelaborable_Construct (Expression (N)); |
| 20317 |
|
| 20318 |
-- Names are preelaborable when they denote a discriminant of an |
| 20319 |
-- enclosing type. Discriminals are also considered for this check. |
| 20320 |
|
| 20321 |
elsif Is_Entity_Name (N) |
| 20322 |
and then Present (Entity (N)) |
| 20323 |
and then |
| 20324 |
(Ekind (Entity (N)) = E_Discriminant |
| 20325 |
or else (Ekind (Entity (N)) in E_Constant | E_In_Parameter |
| 20326 |
and then Present (Discriminal_Link (Entity (N))))) |
| 20327 |
then |
| 20328 |
return True; |
| 20329 |
|
| 20330 |
-- Statements |
| 20331 |
|
| 20332 |
elsif Nkind (N) = N_Null then |
| 20333 |
return True; |
| 20334 |
|
| 20335 |
-- Ada 2022 (AI12-0175): Calls to certain functions that are essentially |
| 20336 |
-- unchecked conversions are preelaborable. |
| 20337 |
|
| 20338 |
elsif Ada_Version >= Ada_2022 |
| 20339 |
and then Nkind (N) = N_Function_Call |
| 20340 |
and then Is_Entity_Name (Name (N)) |
| 20341 |
and then Is_Preelaborable_Function (Entity (Name (N))) |
| 20342 |
then |
| 20343 |
declare |
| 20344 |
A : Node_Id; |
| 20345 |
begin |
| 20346 |
A := First_Actual (N); |
| 20347 |
|
| 20348 |
while Present (A) loop |
| 20349 |
if not Is_Preelaborable_Construct (A) then |
| 20350 |
return False; |
| 20351 |
end if; |
| 20352 |
|
| 20353 |
Next_Actual (A); |
| 20354 |
end loop; |
| 20355 |
end; |
| 20356 |
|
| 20357 |
return True; |
| 20358 |
|
| 20359 |
-- Otherwise the construct is not preelaborable |
| 20360 |
|
| 20361 |
else |
| 20362 |
return False; |
| 20363 |
end if; |
| 20364 |
end Is_Preelaborable_Construct; |
| 20365 |
|
| 20366 |
------------------------------- |
| 20367 |
-- Is_Preelaborable_Function -- |
| 20368 |
------------------------------- |
| 20369 |
|
| 20370 |
function Is_Preelaborable_Function (Id : Entity_Id) return Boolean is |
| 20371 |
SATAC : constant Rtsfind.RTU_Id := System_Address_To_Access_Conversions; |
| 20372 |
Scop : constant Entity_Id := Scope (Id); |
| 20373 |
|
| 20374 |
begin |
| 20375 |
-- Small optimization: every allowed function has convention Intrinsic |
| 20376 |
-- (see Analyze_Subprogram_Instantiation for the subtlety in the test). |
| 20377 |
|
| 20378 |
if not Is_Intrinsic_Subprogram (Id) |
| 20379 |
and then Convention (Id) /= Convention_Intrinsic |
| 20380 |
then |
| 20381 |
return False; |
| 20382 |
end if; |
| 20383 |
|
| 20384 |
-- An instance of Unchecked_Conversion |
| 20385 |
|
| 20386 |
if Is_Unchecked_Conversion_Instance (Id) then |
| 20387 |
return True; |
| 20388 |
end if; |
| 20389 |
|
| 20390 |
-- A function declared in System.Storage_Elements |
| 20391 |
|
| 20392 |
if Is_RTU (Scop, System_Storage_Elements) then |
| 20393 |
return True; |
| 20394 |
end if; |
| 20395 |
|
| 20396 |
-- The functions To_Pointer and To_Address declared in an instance of |
| 20397 |
-- System.Address_To_Access_Conversions (they are the only ones). |
| 20398 |
|
| 20399 |
if Ekind (Scop) = E_Package |
| 20400 |
and then Nkind (Parent (Scop)) = N_Package_Specification |
| 20401 |
and then Present (Generic_Parent (Parent (Scop))) |
| 20402 |
and then Is_RTU (Generic_Parent (Parent (Scop)), SATAC) |
| 20403 |
then |
| 20404 |
return True; |
| 20405 |
end if; |
| 20406 |
|
| 20407 |
return False; |
| 20408 |
end Is_Preelaborable_Function; |
| 20409 |
|
| 20410 |
----------------------------- |
| 20411 |
-- Is_Private_Library_Unit -- |
| 20412 |
----------------------------- |
| 20413 |
|
| 20414 |
function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is |
| 20415 |
Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit)); |
| 20416 |
begin |
| 20417 |
return Nkind (Comp_Unit) = N_Compilation_Unit |
| 20418 |
and then Private_Present (Comp_Unit); |
| 20419 |
end Is_Private_Library_Unit; |
| 20420 |
|
| 20421 |
--------------------------------- |
| 20422 |
-- Is_Protected_Self_Reference -- |
| 20423 |
--------------------------------- |
| 20424 |
|
| 20425 |
function Is_Protected_Self_Reference (N : Node_Id) return Boolean is |
| 20426 |
|
| 20427 |
function In_Access_Definition (N : Node_Id) return Boolean; |
| 20428 |
-- Returns true if N belongs to an access definition |
| 20429 |
|
| 20430 |
-------------------------- |
| 20431 |
-- In_Access_Definition -- |
| 20432 |
-------------------------- |
| 20433 |
|
| 20434 |
function In_Access_Definition (N : Node_Id) return Boolean is |
| 20435 |
P : Node_Id; |
| 20436 |
|
| 20437 |
begin |
| 20438 |
P := Parent (N); |
| 20439 |
while Present (P) loop |
| 20440 |
if Nkind (P) = N_Access_Definition then |
| 20441 |
return True; |
| 20442 |
end if; |
| 20443 |
|
| 20444 |
P := Parent (P); |
| 20445 |
end loop; |
| 20446 |
|
| 20447 |
return False; |
| 20448 |
end In_Access_Definition; |
| 20449 |
|
| 20450 |
-- Start of processing for Is_Protected_Self_Reference |
| 20451 |
|
| 20452 |
begin |
| 20453 |
-- Verify that prefix is analyzed and has the proper form. Note that |
| 20454 |
-- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also |
| 20455 |
-- produce the address of an entity, do not analyze their prefix |
| 20456 |
-- because they denote entities that are not necessarily visible. |
| 20457 |
-- Neither of them can apply to a protected type. |
| 20458 |
|
| 20459 |
return Ada_Version >= Ada_2005 |
| 20460 |
and then Is_Entity_Name (N) |
| 20461 |
and then Present (Entity (N)) |
| 20462 |
and then Is_Protected_Type (Entity (N)) |
| 20463 |
and then In_Open_Scopes (Entity (N)) |
| 20464 |
and then not In_Access_Definition (N); |
| 20465 |
end Is_Protected_Self_Reference; |
| 20466 |
|
| 20467 |
----------------------------- |
| 20468 |
-- Is_RCI_Pkg_Spec_Or_Body -- |
| 20469 |
----------------------------- |
| 20470 |
|
| 20471 |
function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is |
| 20472 |
|
| 20473 |
function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean; |
| 20474 |
-- Return True if the unit of Cunit is an RCI package declaration |
| 20475 |
|
| 20476 |
--------------------------- |
| 20477 |
-- Is_RCI_Pkg_Decl_Cunit -- |
| 20478 |
--------------------------- |
| 20479 |
|
| 20480 |
function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is |
| 20481 |
The_Unit : constant Node_Id := Unit (Cunit); |
| 20482 |
|
| 20483 |
begin |
| 20484 |
if Nkind (The_Unit) /= N_Package_Declaration then |
| 20485 |
return False; |
| 20486 |
end if; |
| 20487 |
|
| 20488 |
return Is_Remote_Call_Interface (Defining_Entity (The_Unit)); |
| 20489 |
end Is_RCI_Pkg_Decl_Cunit; |
| 20490 |
|
| 20491 |
-- Start of processing for Is_RCI_Pkg_Spec_Or_Body |
| 20492 |
|
| 20493 |
begin |
| 20494 |
return Is_RCI_Pkg_Decl_Cunit (Cunit) |
| 20495 |
or else |
| 20496 |
(Nkind (Unit (Cunit)) = N_Package_Body |
| 20497 |
and then Is_RCI_Pkg_Decl_Cunit (Spec_Lib_Unit (Cunit))); |
| 20498 |
end Is_RCI_Pkg_Spec_Or_Body; |
| 20499 |
|
| 20500 |
----------------------------------------- |
| 20501 |
-- Is_Remote_Access_To_Class_Wide_Type -- |
| 20502 |
----------------------------------------- |
| 20503 |
|
| 20504 |
function Is_Remote_Access_To_Class_Wide_Type |
| 20505 |
(E : Entity_Id) return Boolean |
| 20506 |
is |
| 20507 |
begin |
| 20508 |
-- A remote access to class-wide type is a general access to object type |
| 20509 |
-- declared in the visible part of a Remote_Types or Remote_Call_ |
| 20510 |
-- Interface unit. |
| 20511 |
|
| 20512 |
return Ekind (E) = E_General_Access_Type |
| 20513 |
and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E)); |
| 20514 |
end Is_Remote_Access_To_Class_Wide_Type; |
| 20515 |
|
| 20516 |
----------------------------------------- |
| 20517 |
-- Is_Remote_Access_To_Subprogram_Type -- |
| 20518 |
----------------------------------------- |
| 20519 |
|
| 20520 |
function Is_Remote_Access_To_Subprogram_Type |
| 20521 |
(E : Entity_Id) return Boolean |
| 20522 |
is |
| 20523 |
begin |
| 20524 |
return (Ekind (E) = E_Access_Subprogram_Type |
| 20525 |
or else (Ekind (E) = E_Record_Type |
| 20526 |
and then Present (Corresponding_Remote_Type (E)))) |
| 20527 |
and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E)); |
| 20528 |
end Is_Remote_Access_To_Subprogram_Type; |
| 20529 |
|
| 20530 |
-------------------- |
| 20531 |
-- Is_Remote_Call -- |
| 20532 |
-------------------- |
| 20533 |
|
| 20534 |
function Is_Remote_Call (N : Node_Id) return Boolean is |
| 20535 |
begin |
| 20536 |
if Nkind (N) not in N_Subprogram_Call then |
| 20537 |
|
| 20538 |
-- An entry call cannot be remote |
| 20539 |
|
| 20540 |
return False; |
| 20541 |
|
| 20542 |
elsif Nkind (Name (N)) in N_Has_Entity |
| 20543 |
and then Is_Remote_Call_Interface (Entity (Name (N))) |
| 20544 |
then |
| 20545 |
-- A subprogram declared in the spec of a RCI package is remote |
| 20546 |
|
| 20547 |
return True; |
| 20548 |
|
| 20549 |
elsif Nkind (Name (N)) = N_Explicit_Dereference |
| 20550 |
and then Is_Remote_Access_To_Subprogram_Type |
| 20551 |
(Etype (Prefix (Name (N)))) |
| 20552 |
then |
| 20553 |
-- The dereference of a RAS is a remote call |
| 20554 |
|
| 20555 |
return True; |
| 20556 |
|
| 20557 |
elsif Present (Controlling_Argument (N)) |
| 20558 |
and then Is_Remote_Access_To_Class_Wide_Type |
| 20559 |
(Etype (Controlling_Argument (N))) |
| 20560 |
then |
| 20561 |
-- Any primitive operation call with a controlling argument of |
| 20562 |
-- a RACW type is a remote call. |
| 20563 |
|
| 20564 |
return True; |
| 20565 |
end if; |
| 20566 |
|
| 20567 |
-- All other calls are local calls |
| 20568 |
|
| 20569 |
return False; |
| 20570 |
end Is_Remote_Call; |
| 20571 |
|
| 20572 |
---------------------- |
| 20573 |
-- Is_Renamed_Entry -- |
| 20574 |
---------------------- |
| 20575 |
|
| 20576 |
function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is |
| 20577 |
Orig_Node : Node_Id := Empty; |
| 20578 |
Subp_Decl : Node_Id := |
| 20579 |
(if No (Parent (Proc_Nam)) then Empty else Parent (Parent (Proc_Nam))); |
| 20580 |
|
| 20581 |
function Is_Entry (Nam : Node_Id) return Boolean; |
| 20582 |
-- Determine whether Nam is an entry. Traverse selectors if there are |
| 20583 |
-- nested selected components. |
| 20584 |
|
| 20585 |
-------------- |
| 20586 |
-- Is_Entry -- |
| 20587 |
-------------- |
| 20588 |
|
| 20589 |
function Is_Entry (Nam : Node_Id) return Boolean is |
| 20590 |
begin |
| 20591 |
if Nkind (Nam) = N_Selected_Component then |
| 20592 |
return Is_Entry (Selector_Name (Nam)); |
| 20593 |
end if; |
| 20594 |
|
| 20595 |
return Ekind (Entity (Nam)) = E_Entry; |
| 20596 |
end Is_Entry; |
| 20597 |
|
| 20598 |
-- Start of processing for Is_Renamed_Entry |
| 20599 |
|
| 20600 |
begin |
| 20601 |
if Present (Alias (Proc_Nam)) then |
| 20602 |
Subp_Decl := Parent (Parent (Alias (Proc_Nam))); |
| 20603 |
end if; |
| 20604 |
|
| 20605 |
-- Look for a rewritten subprogram renaming declaration |
| 20606 |
|
| 20607 |
if Nkind (Subp_Decl) = N_Subprogram_Declaration |
| 20608 |
and then Present (Original_Node (Subp_Decl)) |
| 20609 |
then |
| 20610 |
Orig_Node := Original_Node (Subp_Decl); |
| 20611 |
end if; |
| 20612 |
|
| 20613 |
-- The rewritten subprogram is actually an entry |
| 20614 |
|
| 20615 |
if Present (Orig_Node) |
| 20616 |
and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration |
| 20617 |
and then Is_Entry (Name (Orig_Node)) |
| 20618 |
then |
| 20619 |
return True; |
| 20620 |
end if; |
| 20621 |
|
| 20622 |
return False; |
| 20623 |
end Is_Renamed_Entry; |
| 20624 |
|
| 20625 |
---------------------------- |
| 20626 |
-- Is_Reversible_Iterator -- |
| 20627 |
---------------------------- |
| 20628 |
|
| 20629 |
function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is |
| 20630 |
Ifaces_List : Elist_Id; |
| 20631 |
Iface_Elmt : Elmt_Id; |
| 20632 |
Iface : Entity_Id; |
| 20633 |
|
| 20634 |
begin |
| 20635 |
if Is_Class_Wide_Type (Typ) |
| 20636 |
and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator |
| 20637 |
and then In_Predefined_Unit (Root_Type (Typ)) |
| 20638 |
then |
| 20639 |
return True; |
| 20640 |
|
| 20641 |
elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then |
| 20642 |
return False; |
| 20643 |
|
| 20644 |
else |
| 20645 |
Collect_Interfaces (Typ, Ifaces_List); |
| 20646 |
|
| 20647 |
Iface_Elmt := First_Elmt (Ifaces_List); |
| 20648 |
while Present (Iface_Elmt) loop |
| 20649 |
Iface := Node (Iface_Elmt); |
| 20650 |
if Chars (Iface) = Name_Reversible_Iterator |
| 20651 |
and then In_Predefined_Unit (Iface) |
| 20652 |
then |
| 20653 |
return True; |
| 20654 |
end if; |
| 20655 |
|
| 20656 |
Next_Elmt (Iface_Elmt); |
| 20657 |
end loop; |
| 20658 |
end if; |
| 20659 |
|
| 20660 |
return False; |
| 20661 |
end Is_Reversible_Iterator; |
| 20662 |
|
| 20663 |
--------------------------------- |
| 20664 |
-- Is_Single_Concurrent_Object -- |
| 20665 |
--------------------------------- |
| 20666 |
|
| 20667 |
function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is |
| 20668 |
begin |
| 20669 |
return |
| 20670 |
Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id); |
| 20671 |
end Is_Single_Concurrent_Object; |
| 20672 |
|
| 20673 |
------------------------------- |
| 20674 |
-- Is_Single_Concurrent_Type -- |
| 20675 |
------------------------------- |
| 20676 |
|
| 20677 |
function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is |
| 20678 |
begin |
| 20679 |
return |
| 20680 |
Ekind (Id) in E_Protected_Type | E_Task_Type |
| 20681 |
and then Is_Single_Concurrent_Type_Declaration |
| 20682 |
(Declaration_Node (Id)); |
| 20683 |
end Is_Single_Concurrent_Type; |
| 20684 |
|
| 20685 |
------------------------------------------- |
| 20686 |
-- Is_Single_Concurrent_Type_Declaration -- |
| 20687 |
------------------------------------------- |
| 20688 |
|
| 20689 |
function Is_Single_Concurrent_Type_Declaration |
| 20690 |
(N : Node_Id) return Boolean |
| 20691 |
is |
| 20692 |
begin |
| 20693 |
return Nkind (Original_Node (N)) in |
| 20694 |
N_Single_Protected_Declaration | N_Single_Task_Declaration; |
| 20695 |
end Is_Single_Concurrent_Type_Declaration; |
| 20696 |
|
| 20697 |
--------------------------------------------- |
| 20698 |
-- Is_Single_Precision_Floating_Point_Type -- |
| 20699 |
--------------------------------------------- |
| 20700 |
|
| 20701 |
function Is_Single_Precision_Floating_Point_Type |
| 20702 |
(E : Entity_Id) return Boolean is |
| 20703 |
begin |
| 20704 |
return Is_Floating_Point_Type (E) |
| 20705 |
and then Machine_Radix_Value (E) = Uint_2 |
| 20706 |
and then Machine_Mantissa_Value (E) = Uint_24 |
| 20707 |
and then Machine_Emax_Value (E) = Uint_2 ** Uint_7 |
| 20708 |
and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7); |
| 20709 |
end Is_Single_Precision_Floating_Point_Type; |
| 20710 |
|
| 20711 |
-------------------------------- |
| 20712 |
-- Is_Single_Protected_Object -- |
| 20713 |
-------------------------------- |
| 20714 |
|
| 20715 |
function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is |
| 20716 |
begin |
| 20717 |
return |
| 20718 |
Ekind (Id) = E_Variable |
| 20719 |
and then Ekind (Etype (Id)) = E_Protected_Type |
| 20720 |
and then Is_Single_Concurrent_Type (Etype (Id)); |
| 20721 |
end Is_Single_Protected_Object; |
| 20722 |
|
| 20723 |
--------------------------- |
| 20724 |
-- Is_Single_Task_Object -- |
| 20725 |
--------------------------- |
| 20726 |
|
| 20727 |
function Is_Single_Task_Object (Id : Entity_Id) return Boolean is |
| 20728 |
begin |
| 20729 |
return |
| 20730 |
Ekind (Id) = E_Variable |
| 20731 |
and then Ekind (Etype (Id)) = E_Task_Type |
| 20732 |
and then Is_Single_Concurrent_Type (Etype (Id)); |
| 20733 |
end Is_Single_Task_Object; |
| 20734 |
|
| 20735 |
----------------------------- |
| 20736 |
-- Is_Specific_Tagged_Type -- |
| 20737 |
----------------------------- |
| 20738 |
|
| 20739 |
function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is |
| 20740 |
Full_Typ : Entity_Id; |
| 20741 |
|
| 20742 |
begin |
| 20743 |
-- Handle private types |
| 20744 |
|
| 20745 |
if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
| 20746 |
Full_Typ := Full_View (Typ); |
| 20747 |
else |
| 20748 |
Full_Typ := Typ; |
| 20749 |
end if; |
| 20750 |
|
| 20751 |
-- A specific tagged type is a non-class-wide tagged type |
| 20752 |
|
| 20753 |
return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ); |
| 20754 |
end Is_Specific_Tagged_Type; |
| 20755 |
|
| 20756 |
------------------ |
| 20757 |
-- Is_Statement -- |
| 20758 |
------------------ |
| 20759 |
|
| 20760 |
function Is_Statement (N : Node_Id) return Boolean is |
| 20761 |
begin |
| 20762 |
return |
| 20763 |
Nkind (N) in N_Statement_Other_Than_Procedure_Call |
| 20764 |
or else Nkind (N) = N_Procedure_Call_Statement; |
| 20765 |
end Is_Statement; |
| 20766 |
|
| 20767 |
-------------------------------------- |
| 20768 |
-- Is_Static_Discriminant_Component -- |
| 20769 |
-------------------------------------- |
| 20770 |
|
| 20771 |
function Is_Static_Discriminant_Component (N : Node_Id) return Boolean is |
| 20772 |
begin |
| 20773 |
return Nkind (N) = N_Selected_Component |
| 20774 |
and then not Is_In_Discriminant_Check (N) |
| 20775 |
and then Present (Etype (Prefix (N))) |
| 20776 |
and then Ekind (Etype (Prefix (N))) = E_Record_Subtype |
| 20777 |
and then Has_Static_Discriminants (Etype (Prefix (N))) |
| 20778 |
and then Present (Entity (Selector_Name (N))) |
| 20779 |
and then Ekind (Entity (Selector_Name (N))) = E_Discriminant |
| 20780 |
and then not In_Check_Node (N); |
| 20781 |
end Is_Static_Discriminant_Component; |
| 20782 |
|
| 20783 |
------------------------ |
| 20784 |
-- Is_Static_Function -- |
| 20785 |
------------------------ |
| 20786 |
|
| 20787 |
function Is_Static_Function (Subp : Entity_Id) return Boolean is |
| 20788 |
begin |
| 20789 |
-- Always return False for pre Ada 2022 to e.g. ignore the Static |
| 20790 |
-- aspect in package Interfaces for Ada_Version < 2022 and also |
| 20791 |
-- for efficiency. |
| 20792 |
|
| 20793 |
return Ada_Version >= Ada_2022 |
| 20794 |
and then Has_Enabled_Aspect (Subp, Aspect_Static); |
| 20795 |
end Is_Static_Function; |
| 20796 |
|
| 20797 |
----------------------------- |
| 20798 |
-- Is_Static_Function_Call -- |
| 20799 |
----------------------------- |
| 20800 |
|
| 20801 |
function Is_Static_Function_Call (Call : Node_Id) return Boolean is |
| 20802 |
function Has_All_Static_Actuals (Call : Node_Id) return Boolean; |
| 20803 |
-- Return whether all actual parameters of Call are static expressions |
| 20804 |
|
| 20805 |
---------------------------- |
| 20806 |
-- Has_All_Static_Actuals -- |
| 20807 |
---------------------------- |
| 20808 |
|
| 20809 |
function Has_All_Static_Actuals (Call : Node_Id) return Boolean is |
| 20810 |
Actual : Node_Id := First_Actual (Call); |
| 20811 |
String_Result : constant Boolean := |
| 20812 |
Is_String_Type (Etype (Entity (Name (Call)))); |
| 20813 |
|
| 20814 |
begin |
| 20815 |
while Present (Actual) loop |
| 20816 |
if not Is_Static_Expression (Actual) then |
| 20817 |
|
| 20818 |
-- ??? In the string-returning case we want to avoid a call |
| 20819 |
-- being made to Establish_Transient_Scope in Resolve_Call, |
| 20820 |
-- but at the point where that's tested for (which now includes |
| 20821 |
-- a call to test Is_Static_Function_Call), the actuals of the |
| 20822 |
-- call haven't been resolved, so expressions of the actuals |
| 20823 |
-- may not have been marked Is_Static_Expression yet, so we |
| 20824 |
-- force them to be resolved here, so we can tell if they're |
| 20825 |
-- static. Calling Resolve here is admittedly a kludge, and we |
| 20826 |
-- limit this call to string-returning cases. |
| 20827 |
|
| 20828 |
if String_Result then |
| 20829 |
Resolve (Actual); |
| 20830 |
end if; |
| 20831 |
|
| 20832 |
-- Test flag again in case it's now True due to above Resolve |
| 20833 |
|
| 20834 |
if not Is_Static_Expression (Actual) then |
| 20835 |
return False; |
| 20836 |
end if; |
| 20837 |
end if; |
| 20838 |
|
| 20839 |
Next_Actual (Actual); |
| 20840 |
end loop; |
| 20841 |
|
| 20842 |
return True; |
| 20843 |
end Has_All_Static_Actuals; |
| 20844 |
|
| 20845 |
begin |
| 20846 |
return Nkind (Call) = N_Function_Call |
| 20847 |
and then Is_Entity_Name (Name (Call)) |
| 20848 |
and then Is_Static_Function (Entity (Name (Call))) |
| 20849 |
and then Has_All_Static_Actuals (Call); |
| 20850 |
end Is_Static_Function_Call; |
| 20851 |
|
| 20852 |
------------------------------------------- |
| 20853 |
-- Is_Subcomponent_Of_Full_Access_Object -- |
| 20854 |
------------------------------------------- |
| 20855 |
|
| 20856 |
function Is_Subcomponent_Of_Full_Access_Object (N : Node_Id) return Boolean |
| 20857 |
is |
| 20858 |
R : Node_Id; |
| 20859 |
|
| 20860 |
begin |
| 20861 |
R := Get_Referenced_Object (N); |
| 20862 |
|
| 20863 |
while Nkind (R) in N_Indexed_Component | N_Selected_Component | N_Slice |
| 20864 |
loop |
| 20865 |
R := Get_Referenced_Object (Prefix (R)); |
| 20866 |
|
| 20867 |
-- If the prefix is an access value, only the designated type matters |
| 20868 |
|
| 20869 |
if Is_Access_Type (Etype (R)) then |
| 20870 |
if Is_Full_Access (Designated_Type (Etype (R))) then |
| 20871 |
return True; |
| 20872 |
end if; |
| 20873 |
|
| 20874 |
else |
| 20875 |
if Is_Full_Access_Object (R) then |
| 20876 |
return True; |
| 20877 |
end if; |
| 20878 |
end if; |
| 20879 |
end loop; |
| 20880 |
|
| 20881 |
return False; |
| 20882 |
end Is_Subcomponent_Of_Full_Access_Object; |
| 20883 |
|
| 20884 |
--------------------------------------- |
| 20885 |
-- Is_Subprogram_Contract_Annotation -- |
| 20886 |
--------------------------------------- |
| 20887 |
|
| 20888 |
function Is_Subprogram_Contract_Annotation |
| 20889 |
(Item : Node_Id) return Boolean |
| 20890 |
is |
| 20891 |
Nam : Name_Id; |
| 20892 |
|
| 20893 |
begin |
| 20894 |
if Nkind (Item) = N_Aspect_Specification then |
| 20895 |
Nam := Chars (Identifier (Item)); |
| 20896 |
|
| 20897 |
else pragma Assert (Nkind (Item) = N_Pragma); |
| 20898 |
Nam := Pragma_Name (Item); |
| 20899 |
end if; |
| 20900 |
|
| 20901 |
return Nam = Name_Always_Terminates |
| 20902 |
or else Nam = Name_Contract_Cases |
| 20903 |
or else Nam = Name_Depends |
| 20904 |
or else Nam = Name_Exceptional_Cases |
| 20905 |
or else Nam = Name_Extensions_Visible |
| 20906 |
or else Nam = Name_Global |
| 20907 |
or else Nam = Name_Post |
| 20908 |
or else Nam = Name_Post_Class |
| 20909 |
or else Nam = Name_Postcondition |
| 20910 |
or else Nam = Name_Pre |
| 20911 |
or else Nam = Name_Pre_Class |
| 20912 |
or else Nam = Name_Precondition |
| 20913 |
or else Nam = Name_Refined_Depends |
| 20914 |
or else Nam = Name_Refined_Global |
| 20915 |
or else Nam = Name_Refined_Post |
| 20916 |
or else Nam = Name_Subprogram_Variant |
| 20917 |
or else Nam = Name_Test_Case; |
| 20918 |
end Is_Subprogram_Contract_Annotation; |
| 20919 |
|
| 20920 |
-------------------------------------------------- |
| 20921 |
-- Is_Subprogram_Stub_Without_Prior_Declaration -- |
| 20922 |
-------------------------------------------------- |
| 20923 |
|
| 20924 |
function Is_Subprogram_Stub_Without_Prior_Declaration |
| 20925 |
(N : Node_Id) return Boolean |
| 20926 |
is |
| 20927 |
begin |
| 20928 |
pragma Assert (Nkind (N) = N_Subprogram_Body_Stub); |
| 20929 |
|
| 20930 |
case Ekind (Defining_Entity (N)) is |
| 20931 |
|
| 20932 |
-- A subprogram stub without prior declaration serves as declaration |
| 20933 |
-- for the actual subprogram body. As such, it has an attached |
| 20934 |
-- defining entity of E_Function or E_Procedure. |
| 20935 |
|
| 20936 |
when E_Function |
| 20937 |
| E_Procedure |
| 20938 |
=> |
| 20939 |
return True; |
| 20940 |
|
| 20941 |
-- Otherwise, it is completes a [generic] subprogram declaration |
| 20942 |
|
| 20943 |
when E_Generic_Function |
| 20944 |
| E_Generic_Procedure |
| 20945 |
| E_Subprogram_Body |
| 20946 |
=> |
| 20947 |
return False; |
| 20948 |
|
| 20949 |
when others => |
| 20950 |
raise Program_Error; |
| 20951 |
end case; |
| 20952 |
end Is_Subprogram_Stub_Without_Prior_Declaration; |
| 20953 |
|
| 20954 |
--------------------------- |
| 20955 |
-- Is_Suitable_Primitive -- |
| 20956 |
--------------------------- |
| 20957 |
|
| 20958 |
function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is |
| 20959 |
begin |
| 20960 |
-- The Default_Initial_Condition and invariant procedures must not be |
| 20961 |
-- treated as primitive operations even when they apply to a tagged |
| 20962 |
-- type. These routines must not act as targets of dispatching calls |
| 20963 |
-- because they already utilize class-wide-precondition semantics to |
| 20964 |
-- handle inheritance and overriding. |
| 20965 |
|
| 20966 |
if Ekind (Subp_Id) = E_Procedure |
| 20967 |
and then (Is_DIC_Procedure (Subp_Id) |
| 20968 |
or else |
| 20969 |
Is_Invariant_Procedure (Subp_Id)) |
| 20970 |
then |
| 20971 |
return False; |
| 20972 |
end if; |
| 20973 |
|
| 20974 |
return True; |
| 20975 |
end Is_Suitable_Primitive; |
| 20976 |
|
| 20977 |
---------------------------- |
| 20978 |
-- Is_Synchronized_Object -- |
| 20979 |
---------------------------- |
| 20980 |
|
| 20981 |
function Is_Synchronized_Object (Id : Entity_Id) return Boolean is |
| 20982 |
Prag : Node_Id; |
| 20983 |
|
| 20984 |
begin |
| 20985 |
if Is_Object (Id) then |
| 20986 |
|
| 20987 |
-- The object is synchronized if it is of a type that yields a |
| 20988 |
-- synchronized object. |
| 20989 |
|
| 20990 |
if Yields_Synchronized_Object (Etype (Id)) then |
| 20991 |
return True; |
| 20992 |
|
| 20993 |
-- The object is synchronized if it is atomic and Async_Writers is |
| 20994 |
-- enabled. |
| 20995 |
|
| 20996 |
elsif Is_Atomic_Object_Entity (Id) |
| 20997 |
and then Async_Writers_Enabled (Id) |
| 20998 |
then |
| 20999 |
return True; |
| 21000 |
|
| 21001 |
-- A constant is a synchronized object by default, unless its type is |
| 21002 |
-- access-to-variable type. |
| 21003 |
|
| 21004 |
elsif Ekind (Id) = E_Constant |
| 21005 |
and then not Is_Access_Variable (Etype (Id)) |
| 21006 |
then |
| 21007 |
return True; |
| 21008 |
|
| 21009 |
-- A variable is a synchronized object if it is subject to pragma |
| 21010 |
-- Constant_After_Elaboration. |
| 21011 |
|
| 21012 |
elsif Ekind (Id) = E_Variable then |
| 21013 |
Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration); |
| 21014 |
|
| 21015 |
return Present (Prag) and then Is_Enabled_Pragma (Prag); |
| 21016 |
end if; |
| 21017 |
end if; |
| 21018 |
|
| 21019 |
-- Otherwise the input is not an object or it does not qualify as a |
| 21020 |
-- synchronized object. |
| 21021 |
|
| 21022 |
return False; |
| 21023 |
end Is_Synchronized_Object; |
| 21024 |
|
| 21025 |
--------------------------------- |
| 21026 |
-- Is_Synchronized_Tagged_Type -- |
| 21027 |
--------------------------------- |
| 21028 |
|
| 21029 |
function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is |
| 21030 |
Kind : constant Entity_Kind := Ekind (Base_Type (E)); |
| 21031 |
|
| 21032 |
begin |
| 21033 |
-- A task or protected type derived from an interface is a tagged type. |
| 21034 |
-- Such a tagged type is called a synchronized tagged type, as are |
| 21035 |
-- synchronized interfaces and private extensions whose declaration |
| 21036 |
-- includes the reserved word synchronized. |
| 21037 |
|
| 21038 |
return (Is_Tagged_Type (E) |
| 21039 |
and then (Kind = E_Task_Type |
| 21040 |
or else |
| 21041 |
Kind = E_Protected_Type)) |
| 21042 |
or else |
| 21043 |
(Is_Interface (E) |
| 21044 |
and then Is_Synchronized_Interface (E)) |
| 21045 |
or else |
| 21046 |
(Ekind (E) = E_Record_Type_With_Private |
| 21047 |
and then Nkind (Parent (E)) = N_Private_Extension_Declaration |
| 21048 |
and then (Synchronized_Present (Parent (E)) |
| 21049 |
or else Is_Synchronized_Interface (Etype (E)))); |
| 21050 |
end Is_Synchronized_Tagged_Type; |
| 21051 |
|
| 21052 |
----------------- |
| 21053 |
-- Is_Transfer -- |
| 21054 |
----------------- |
| 21055 |
|
| 21056 |
function Is_Transfer (N : Node_Id) return Boolean is |
| 21057 |
Kind : constant Node_Kind := Nkind (N); |
| 21058 |
|
| 21059 |
begin |
| 21060 |
if Kind in N_Simple_Return_Statement |
| 21061 |
| N_Extended_Return_Statement |
| 21062 |
| N_Goto_Statement |
| 21063 |
| N_Raise_Statement |
| 21064 |
| N_Requeue_Statement |
| 21065 |
then |
| 21066 |
return True; |
| 21067 |
|
| 21068 |
elsif Kind in N_Exit_Statement | N_Raise_xxx_Error |
| 21069 |
and then No (Condition (N)) |
| 21070 |
then |
| 21071 |
return True; |
| 21072 |
|
| 21073 |
elsif Kind = N_Procedure_Call_Statement |
| 21074 |
and then Is_Entity_Name (Name (N)) |
| 21075 |
and then Present (Entity (Name (N))) |
| 21076 |
and then No_Return (Entity (Name (N))) |
| 21077 |
then |
| 21078 |
return True; |
| 21079 |
|
| 21080 |
elsif Nkind (Original_Node (N)) = N_Raise_Statement then |
| 21081 |
return True; |
| 21082 |
|
| 21083 |
else |
| 21084 |
return False; |
| 21085 |
end if; |
| 21086 |
end Is_Transfer; |
| 21087 |
|
| 21088 |
------------- |
| 21089 |
-- Is_True -- |
| 21090 |
------------- |
| 21091 |
|
| 21092 |
function Is_True (U : Opt_Ubool) return Boolean is |
| 21093 |
begin |
| 21094 |
return No (U) or else U = Uint_1; |
| 21095 |
end Is_True; |
| 21096 |
|
| 21097 |
------------------------ |
| 21098 |
-- Is_Trivial_Boolean -- |
| 21099 |
------------------------ |
| 21100 |
|
| 21101 |
function Is_Trivial_Boolean (N : Node_Id) return Boolean is |
| 21102 |
begin |
| 21103 |
return Comes_From_Source (N) |
| 21104 |
and then Nkind (N) in N_Identifier | N_Expanded_Name |
| 21105 |
and then Entity (N) in Standard_True | Standard_False; |
| 21106 |
end Is_Trivial_Boolean; |
| 21107 |
|
| 21108 |
-------------------------------------- |
| 21109 |
-- Is_Unchecked_Conversion_Instance -- |
| 21110 |
-------------------------------------- |
| 21111 |
|
| 21112 |
function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is |
| 21113 |
Par : Node_Id; |
| 21114 |
|
| 21115 |
begin |
| 21116 |
-- Look for a function whose generic parent is the predefined intrinsic |
| 21117 |
-- function Unchecked_Conversion, or for one that renames such an |
| 21118 |
-- instance. |
| 21119 |
|
| 21120 |
if Ekind (Id) = E_Function then |
| 21121 |
Par := Parent (Id); |
| 21122 |
|
| 21123 |
if Nkind (Par) = N_Function_Specification then |
| 21124 |
Par := Generic_Parent (Par); |
| 21125 |
|
| 21126 |
if Present (Par) then |
| 21127 |
return |
| 21128 |
Chars (Par) = Name_Unchecked_Conversion |
| 21129 |
and then Is_Intrinsic_Subprogram (Par) |
| 21130 |
and then In_Predefined_Unit (Par); |
| 21131 |
else |
| 21132 |
return |
| 21133 |
Present (Alias (Id)) |
| 21134 |
and then Is_Unchecked_Conversion_Instance (Alias (Id)); |
| 21135 |
end if; |
| 21136 |
end if; |
| 21137 |
end if; |
| 21138 |
|
| 21139 |
return False; |
| 21140 |
end Is_Unchecked_Conversion_Instance; |
| 21141 |
|
| 21142 |
------------------------------- |
| 21143 |
-- Is_Universal_Numeric_Type -- |
| 21144 |
------------------------------- |
| 21145 |
|
| 21146 |
function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is |
| 21147 |
begin |
| 21148 |
return T = Universal_Integer or else T = Universal_Real; |
| 21149 |
end Is_Universal_Numeric_Type; |
| 21150 |
|
| 21151 |
------------------------------------- |
| 21152 |
-- Is_Unconstrained_Or_Tagged_Item -- |
| 21153 |
------------------------------------- |
| 21154 |
|
| 21155 |
function Is_Unconstrained_Or_Tagged_Item |
| 21156 |
(Item : Entity_Id) return Boolean |
| 21157 |
is |
| 21158 |
Typ : constant Entity_Id := Etype (Item); |
| 21159 |
begin |
| 21160 |
if Is_Tagged_Type (Typ) then |
| 21161 |
return True; |
| 21162 |
|
| 21163 |
elsif Is_Array_Type (Typ) |
| 21164 |
or else Is_Record_Type (Typ) |
| 21165 |
or else Is_Private_Type (Typ) |
| 21166 |
then |
| 21167 |
return not Is_Constrained (Typ); |
| 21168 |
|
| 21169 |
else |
| 21170 |
return False; |
| 21171 |
end if; |
| 21172 |
end Is_Unconstrained_Or_Tagged_Item; |
| 21173 |
|
| 21174 |
------------------------------ |
| 21175 |
-- Is_User_Defined_Equality -- |
| 21176 |
------------------------------ |
| 21177 |
|
| 21178 |
function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is |
| 21179 |
F1, F2 : Entity_Id; |
| 21180 |
|
| 21181 |
begin |
| 21182 |
-- An equality operator is a function that carries the name "=", returns |
| 21183 |
-- Boolean, and has exactly two formal parameters of an identical type. |
| 21184 |
|
| 21185 |
if Ekind (Id) = E_Function |
| 21186 |
and then Chars (Id) = Name_Op_Eq |
| 21187 |
and then Base_Type (Etype (Id)) = Standard_Boolean |
| 21188 |
then |
| 21189 |
F1 := First_Formal (Id); |
| 21190 |
|
| 21191 |
if No (F1) then |
| 21192 |
return False; |
| 21193 |
end if; |
| 21194 |
|
| 21195 |
F2 := Next_Formal (F1); |
| 21196 |
|
| 21197 |
return Present (F2) |
| 21198 |
and then No (Next_Formal (F2)) |
| 21199 |
and then Base_Type (Etype (F1)) = Base_Type (Etype (F2)); |
| 21200 |
|
| 21201 |
else |
| 21202 |
return False; |
| 21203 |
end if; |
| 21204 |
end Is_User_Defined_Equality; |
| 21205 |
|
| 21206 |
----------------------------- |
| 21207 |
-- Is_User_Defined_Literal -- |
| 21208 |
----------------------------- |
| 21209 |
|
| 21210 |
function Is_User_Defined_Literal |
| 21211 |
(N : Node_Id; |
| 21212 |
Typ : Entity_Id) return Boolean |
| 21213 |
is |
| 21214 |
Literal_Aspect_Map : |
| 21215 |
constant array (N_Numeric_Or_String_Literal) of Aspect_Id := |
| 21216 |
(N_Integer_Literal => Aspect_Integer_Literal, |
| 21217 |
N_Interpolated_String_Literal => No_Aspect, |
| 21218 |
N_Real_Literal => Aspect_Real_Literal, |
| 21219 |
N_String_Literal => Aspect_String_Literal); |
| 21220 |
|
| 21221 |
begin |
| 21222 |
-- Return True when N is either a literal or a named number and the |
| 21223 |
-- type has the appropriate user-defined literal aspect. |
| 21224 |
|
| 21225 |
return (Nkind (N) in N_Numeric_Or_String_Literal |
| 21226 |
and then Has_Aspect (Typ, Literal_Aspect_Map (Nkind (N)))) |
| 21227 |
or else |
| 21228 |
(Is_Entity_Name (N) |
| 21229 |
and then Present (Entity (N)) |
| 21230 |
and then |
| 21231 |
((Ekind (Entity (N)) = E_Named_Integer |
| 21232 |
and then Has_Aspect (Typ, Aspect_Integer_Literal)) |
| 21233 |
or else |
| 21234 |
(Ekind (Entity (N)) = E_Named_Real |
| 21235 |
and then Has_Aspect (Typ, Aspect_Real_Literal)))); |
| 21236 |
end Is_User_Defined_Literal; |
| 21237 |
|
| 21238 |
-------------------------------------- |
| 21239 |
-- Is_Validation_Variable_Reference -- |
| 21240 |
-------------------------------------- |
| 21241 |
|
| 21242 |
function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is |
| 21243 |
Var : constant Node_Id := Unqual_Conv (N); |
| 21244 |
Var_Id : Entity_Id; |
| 21245 |
|
| 21246 |
begin |
| 21247 |
Var_Id := Empty; |
| 21248 |
|
| 21249 |
if Is_Entity_Name (Var) then |
| 21250 |
Var_Id := Entity (Var); |
| 21251 |
end if; |
| 21252 |
|
| 21253 |
return |
| 21254 |
Present (Var_Id) |
| 21255 |
and then Ekind (Var_Id) = E_Variable |
| 21256 |
and then Present (Validated_Object (Var_Id)); |
| 21257 |
end Is_Validation_Variable_Reference; |
| 21258 |
|
| 21259 |
---------------------------- |
| 21260 |
-- Is_Variable_Size_Array -- |
| 21261 |
---------------------------- |
| 21262 |
|
| 21263 |
function Is_Variable_Size_Array (E : Entity_Id) return Boolean is |
| 21264 |
Idx : Node_Id; |
| 21265 |
|
| 21266 |
begin |
| 21267 |
pragma Assert (Is_Array_Type (E)); |
| 21268 |
|
| 21269 |
-- Check if some index is initialized with a non-constant value |
| 21270 |
|
| 21271 |
Idx := First_Index (E); |
| 21272 |
while Present (Idx) loop |
| 21273 |
if Nkind (Idx) = N_Range then |
| 21274 |
if not Is_Constant_Bound (Low_Bound (Idx)) |
| 21275 |
or else not Is_Constant_Bound (High_Bound (Idx)) |
| 21276 |
then |
| 21277 |
return True; |
| 21278 |
end if; |
| 21279 |
end if; |
| 21280 |
|
| 21281 |
Next_Index (Idx); |
| 21282 |
end loop; |
| 21283 |
|
| 21284 |
return False; |
| 21285 |
end Is_Variable_Size_Array; |
| 21286 |
|
| 21287 |
----------------------------- |
| 21288 |
-- Is_Variable_Size_Record -- |
| 21289 |
----------------------------- |
| 21290 |
|
| 21291 |
function Is_Variable_Size_Record (E : Entity_Id) return Boolean is |
| 21292 |
Comp : Entity_Id; |
| 21293 |
Comp_Typ : Entity_Id; |
| 21294 |
|
| 21295 |
begin |
| 21296 |
pragma Assert (Is_Record_Type (E)); |
| 21297 |
|
| 21298 |
Comp := First_Component (E); |
| 21299 |
while Present (Comp) loop |
| 21300 |
Comp_Typ := Underlying_Type (Etype (Comp)); |
| 21301 |
|
| 21302 |
-- Recursive call if the record type has discriminants |
| 21303 |
|
| 21304 |
if Is_Record_Type (Comp_Typ) |
| 21305 |
and then Has_Discriminants (Comp_Typ) |
| 21306 |
and then Is_Variable_Size_Record (Comp_Typ) |
| 21307 |
then |
| 21308 |
return True; |
| 21309 |
|
| 21310 |
elsif Is_Array_Type (Comp_Typ) |
| 21311 |
and then Is_Variable_Size_Array (Comp_Typ) |
| 21312 |
then |
| 21313 |
return True; |
| 21314 |
end if; |
| 21315 |
|
| 21316 |
Next_Component (Comp); |
| 21317 |
end loop; |
| 21318 |
|
| 21319 |
return False; |
| 21320 |
end Is_Variable_Size_Record; |
| 21321 |
|
| 21322 |
----------------- |
| 21323 |
-- Is_Variable -- |
| 21324 |
----------------- |
| 21325 |
|
| 21326 |
-- Should Is_Variable be refactored to better handle dereferences and |
| 21327 |
-- technical debt ??? |
| 21328 |
|
| 21329 |
function Is_Variable |
| 21330 |
(N : Node_Id; |
| 21331 |
Use_Original_Node : Boolean := True) return Boolean |
| 21332 |
is |
| 21333 |
Orig_Node : Node_Id; |
| 21334 |
|
| 21335 |
function In_Protected_Function (E : Entity_Id) return Boolean; |
| 21336 |
-- Within a protected function, the private components of the enclosing |
| 21337 |
-- protected type are constants. A function nested within a (protected) |
| 21338 |
-- procedure is not itself protected. Within the body of a protected |
| 21339 |
-- function the current instance of the protected type is a constant. |
| 21340 |
|
| 21341 |
function Is_Variable_Prefix (P : Node_Id) return Boolean; |
| 21342 |
-- Prefixes can involve implicit dereferences, in which case we must |
| 21343 |
-- test for the case of a reference of a constant access type, which can |
| 21344 |
-- can never be a variable. |
| 21345 |
|
| 21346 |
--------------------------- |
| 21347 |
-- In_Protected_Function -- |
| 21348 |
--------------------------- |
| 21349 |
|
| 21350 |
function In_Protected_Function (E : Entity_Id) return Boolean is |
| 21351 |
Prot : Entity_Id; |
| 21352 |
S : Entity_Id; |
| 21353 |
|
| 21354 |
begin |
| 21355 |
-- E is the current instance of a type |
| 21356 |
|
| 21357 |
if Is_Type (E) then |
| 21358 |
Prot := E; |
| 21359 |
|
| 21360 |
-- E is an object |
| 21361 |
|
| 21362 |
else |
| 21363 |
Prot := Scope (E); |
| 21364 |
end if; |
| 21365 |
|
| 21366 |
if not Is_Protected_Type (Prot) then |
| 21367 |
return False; |
| 21368 |
|
| 21369 |
else |
| 21370 |
S := Current_Scope; |
| 21371 |
while Present (S) and then S /= Prot loop |
| 21372 |
if Ekind (S) = E_Function and then Scope (S) = Prot then |
| 21373 |
return True; |
| 21374 |
end if; |
| 21375 |
|
| 21376 |
S := Scope (S); |
| 21377 |
end loop; |
| 21378 |
|
| 21379 |
return False; |
| 21380 |
end if; |
| 21381 |
end In_Protected_Function; |
| 21382 |
|
| 21383 |
------------------------ |
| 21384 |
-- Is_Variable_Prefix -- |
| 21385 |
------------------------ |
| 21386 |
|
| 21387 |
function Is_Variable_Prefix (P : Node_Id) return Boolean is |
| 21388 |
begin |
| 21389 |
if Is_Access_Type (Etype (P)) then |
| 21390 |
return not Is_Access_Constant (Root_Type (Etype (P))); |
| 21391 |
|
| 21392 |
-- For the case of an indexed component whose prefix has a packed |
| 21393 |
-- array type, the prefix has been rewritten into a type conversion. |
| 21394 |
-- Determine variable-ness from the converted expression. |
| 21395 |
|
| 21396 |
elsif Nkind (P) = N_Type_Conversion |
| 21397 |
and then not Comes_From_Source (P) |
| 21398 |
and then Is_Packed_Array (Etype (P)) |
| 21399 |
then |
| 21400 |
return Is_Variable (Expression (P)); |
| 21401 |
|
| 21402 |
else |
| 21403 |
return Is_Variable (P); |
| 21404 |
end if; |
| 21405 |
end Is_Variable_Prefix; |
| 21406 |
|
| 21407 |
-- Start of processing for Is_Variable |
| 21408 |
|
| 21409 |
begin |
| 21410 |
-- Special check, allow x'Deref(expr) as a variable |
| 21411 |
|
| 21412 |
if Nkind (N) = N_Attribute_Reference |
| 21413 |
and then Attribute_Name (N) = Name_Deref |
| 21414 |
then |
| 21415 |
return True; |
| 21416 |
end if; |
| 21417 |
|
| 21418 |
-- Check if we perform the test on the original node since this may be a |
| 21419 |
-- test of syntactic categories which must not be disturbed by whatever |
| 21420 |
-- rewriting might have occurred. For example, an aggregate, which is |
| 21421 |
-- certainly NOT a variable, could be turned into a variable by |
| 21422 |
-- expansion. |
| 21423 |
|
| 21424 |
if Use_Original_Node then |
| 21425 |
Orig_Node := Original_Node (N); |
| 21426 |
else |
| 21427 |
Orig_Node := N; |
| 21428 |
end if; |
| 21429 |
|
| 21430 |
-- Definitely OK if Assignment_OK is set. Since this is something that |
| 21431 |
-- only gets set for expanded nodes, the test is on N, not Orig_Node. |
| 21432 |
|
| 21433 |
if Nkind (N) in N_Subexpr and then Assignment_OK (N) then |
| 21434 |
return True; |
| 21435 |
|
| 21436 |
-- It is possible that N is a selected component of a view conversion, |
| 21437 |
-- and in that case get the expression of the conversion and test |
| 21438 |
-- whether it is indeed a variable. |
| 21439 |
|
| 21440 |
elsif Nkind (N) = N_Selected_Component |
| 21441 |
and then Is_View_Conversion (Ultimate_Prefix (N)) |
| 21442 |
and then Is_Variable (Expression (Ultimate_Prefix (N))) |
| 21443 |
then |
| 21444 |
return True; |
| 21445 |
|
| 21446 |
-- Normally we go to the original node, but there is one exception where |
| 21447 |
-- we use the rewritten node, namely when it is an explicit dereference. |
| 21448 |
-- The generated code may rewrite a prefix which is an access type with |
| 21449 |
-- an explicit dereference. The dereference is a variable, even though |
| 21450 |
-- the original node may not be (since it could be a constant of the |
| 21451 |
-- access type). |
| 21452 |
|
| 21453 |
-- In Ada 2005 we have a further case to consider: the prefix may be a |
| 21454 |
-- function call given in prefix notation. The original node appears to |
| 21455 |
-- be a selected component, but we need to examine the call. |
| 21456 |
|
| 21457 |
elsif Nkind (N) = N_Explicit_Dereference |
| 21458 |
and then Nkind (Orig_Node) /= N_Explicit_Dereference |
| 21459 |
and then Present (Etype (Orig_Node)) |
| 21460 |
and then Is_Access_Type (Etype (Orig_Node)) |
| 21461 |
then |
| 21462 |
-- Note that if the prefix is an explicit dereference that does not |
| 21463 |
-- come from source, we must check for a rewritten function call in |
| 21464 |
-- prefixed notation before other forms of rewriting, to prevent a |
| 21465 |
-- compiler crash. |
| 21466 |
|
| 21467 |
return |
| 21468 |
(Nkind (Orig_Node) = N_Function_Call |
| 21469 |
and then not Is_Access_Constant (Etype (Prefix (N)))) |
| 21470 |
or else |
| 21471 |
Is_Variable_Prefix (Original_Node (Prefix (N))); |
| 21472 |
|
| 21473 |
-- Generalized indexing operations are rewritten as explicit |
| 21474 |
-- dereferences, and it is only during resolution that we can |
| 21475 |
-- check whether the context requires an access_to_variable type. |
| 21476 |
|
| 21477 |
elsif Nkind (N) = N_Explicit_Dereference |
| 21478 |
and then Present (Etype (Orig_Node)) |
| 21479 |
and then Has_Implicit_Dereference (Etype (Orig_Node)) |
| 21480 |
and then Ada_Version >= Ada_2012 |
| 21481 |
then |
| 21482 |
return not Is_Access_Constant (Etype (Prefix (N))); |
| 21483 |
|
| 21484 |
-- A function call is never a variable |
| 21485 |
|
| 21486 |
elsif Nkind (N) = N_Function_Call then |
| 21487 |
return False; |
| 21488 |
|
| 21489 |
-- All remaining checks use the original node |
| 21490 |
|
| 21491 |
elsif Is_Entity_Name (Orig_Node) |
| 21492 |
and then Present (Entity (Orig_Node)) |
| 21493 |
then |
| 21494 |
declare |
| 21495 |
E : constant Entity_Id := Entity (Orig_Node); |
| 21496 |
K : constant Entity_Kind := Ekind (E); |
| 21497 |
|
| 21498 |
begin |
| 21499 |
if Is_Loop_Parameter (E) then |
| 21500 |
return False; |
| 21501 |
end if; |
| 21502 |
|
| 21503 |
return (K = E_Variable |
| 21504 |
and then Nkind (Parent (E)) /= N_Exception_Handler) |
| 21505 |
or else (K = E_Component |
| 21506 |
and then not In_Protected_Function (E)) |
| 21507 |
or else (Present (Etype (E)) |
| 21508 |
and then Is_Access_Variable (Etype (E)) |
| 21509 |
and then Is_Dereferenced (N)) |
| 21510 |
or else K = E_Out_Parameter |
| 21511 |
or else K = E_In_Out_Parameter |
| 21512 |
or else K = E_Generic_In_Out_Parameter |
| 21513 |
|
| 21514 |
-- Current instance of type. If this is a protected type, check |
| 21515 |
-- we are not within the body of one of its protected functions. |
| 21516 |
|
| 21517 |
or else (Is_Type (E) |
| 21518 |
and then In_Open_Scopes (E) |
| 21519 |
and then not In_Protected_Function (E)) |
| 21520 |
|
| 21521 |
or else (Is_Incomplete_Or_Private_Type (E) |
| 21522 |
and then In_Open_Scopes (Full_View (E))); |
| 21523 |
end; |
| 21524 |
|
| 21525 |
else |
| 21526 |
case Nkind (Orig_Node) is |
| 21527 |
when N_Indexed_Component |
| 21528 |
| N_Slice |
| 21529 |
=> |
| 21530 |
return Is_Variable_Prefix (Prefix (Orig_Node)); |
| 21531 |
|
| 21532 |
when N_Selected_Component => |
| 21533 |
return Is_Variable (Selector_Name (Orig_Node)) |
| 21534 |
and then Is_Variable_Prefix (Prefix (Orig_Node)); |
| 21535 |
|
| 21536 |
-- For an explicit dereference, the type of the prefix cannot |
| 21537 |
-- be an access to constant or an access to subprogram. |
| 21538 |
|
| 21539 |
when N_Explicit_Dereference => |
| 21540 |
declare |
| 21541 |
Typ : constant Entity_Id := Etype (Prefix (Orig_Node)); |
| 21542 |
begin |
| 21543 |
return Is_Access_Type (Typ) |
| 21544 |
and then not Is_Access_Constant (Root_Type (Typ)) |
| 21545 |
and then Ekind (Typ) /= E_Access_Subprogram_Type; |
| 21546 |
end; |
| 21547 |
|
| 21548 |
-- Handle the case where 'Super is present - representing a view |
| 21549 |
-- conversion. |
| 21550 |
|
| 21551 |
when N_Attribute_Reference => |
| 21552 |
if Attribute_Name (Orig_Node) = Name_Super then |
| 21553 |
return Is_Variable (Prefix (Orig_Node)); |
| 21554 |
end if; |
| 21555 |
|
| 21556 |
return False; |
| 21557 |
|
| 21558 |
-- The type conversion is the case where we do not deal with the |
| 21559 |
-- context dependent special case of an actual parameter. Thus |
| 21560 |
-- the type conversion is only considered a variable for the |
| 21561 |
-- purposes of this routine if the target type is tagged. However, |
| 21562 |
-- a type conversion is considered to be a variable if it does not |
| 21563 |
-- come from source (this deals for example with the conversions |
| 21564 |
-- of expressions to their actual subtypes). |
| 21565 |
|
| 21566 |
when N_Type_Conversion => |
| 21567 |
return Is_Variable (Expression (Orig_Node)) |
| 21568 |
and then |
| 21569 |
(not Comes_From_Source (Orig_Node) |
| 21570 |
or else |
| 21571 |
(Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node))) |
| 21572 |
and then |
| 21573 |
Is_Tagged_Type (Etype (Expression (Orig_Node))))); |
| 21574 |
|
| 21575 |
-- GNAT allows an unchecked type conversion as a variable. This |
| 21576 |
-- only affects the generation of internal expanded code, since |
| 21577 |
-- calls to instantiations of Unchecked_Conversion are never |
| 21578 |
-- considered variables (since they are function calls). |
| 21579 |
|
| 21580 |
when N_Unchecked_Type_Conversion => |
| 21581 |
return Is_Variable (Expression (Orig_Node)); |
| 21582 |
|
| 21583 |
when others => |
| 21584 |
return False; |
| 21585 |
end case; |
| 21586 |
end if; |
| 21587 |
end Is_Variable; |
| 21588 |
|
| 21589 |
------------------------ |
| 21590 |
-- Is_View_Conversion -- |
| 21591 |
------------------------ |
| 21592 |
|
| 21593 |
function Is_View_Conversion (N : Node_Id) return Boolean is |
| 21594 |
begin |
| 21595 |
if Nkind (N) = N_Type_Conversion |
| 21596 |
and then Nkind (Unqual_Conv (N)) in N_Has_Etype |
| 21597 |
then |
| 21598 |
if Is_Tagged_Type (Etype (N)) |
| 21599 |
and then (Is_Tagged_Type (Etype (Unqual_Conv (N))) |
| 21600 |
or else Is_Class_Wide_Equivalent_Type |
| 21601 |
(Etype (Unqual_Conv (N)))) |
| 21602 |
then |
| 21603 |
return True; |
| 21604 |
|
| 21605 |
elsif Is_Actual_Parameter (N) |
| 21606 |
and then (Is_Actual_Out_Parameter (N) |
| 21607 |
or else Is_Actual_In_Out_Parameter (N)) |
| 21608 |
then |
| 21609 |
return True; |
| 21610 |
end if; |
| 21611 |
end if; |
| 21612 |
|
| 21613 |
return False; |
| 21614 |
end Is_View_Conversion; |
| 21615 |
|
| 21616 |
--------------------------- |
| 21617 |
-- Is_Visibly_Controlled -- |
| 21618 |
--------------------------- |
| 21619 |
|
| 21620 |
function Is_Visibly_Controlled (T : Entity_Id) return Boolean is |
| 21621 |
Root : constant Entity_Id := Root_Type (T); |
| 21622 |
begin |
| 21623 |
return Chars (Scope (Root)) = Name_Finalization |
| 21624 |
and then Chars (Scope (Scope (Root))) = Name_Ada |
| 21625 |
and then Scope (Scope (Scope (Root))) = Standard_Standard; |
| 21626 |
end Is_Visibly_Controlled; |
| 21627 |
|
| 21628 |
---------------------------------------- |
| 21629 |
-- Is_Volatile_Full_Access_Object_Ref -- |
| 21630 |
---------------------------------------- |
| 21631 |
|
| 21632 |
function Is_Volatile_Full_Access_Object_Ref (N : Node_Id) return Boolean is |
| 21633 |
function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean; |
| 21634 |
-- Determine whether arbitrary entity Id denotes an object that is |
| 21635 |
-- Volatile_Full_Access. |
| 21636 |
|
| 21637 |
---------------------------- |
| 21638 |
-- Is_VFA_Object_Entity -- |
| 21639 |
---------------------------- |
| 21640 |
|
| 21641 |
function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is |
| 21642 |
begin |
| 21643 |
return |
| 21644 |
Is_Object (Id) |
| 21645 |
and then (Is_Volatile_Full_Access (Id) |
| 21646 |
or else |
| 21647 |
Is_Volatile_Full_Access (Etype (Id))); |
| 21648 |
end Is_VFA_Object_Entity; |
| 21649 |
|
| 21650 |
-- Start of processing for Is_Volatile_Full_Access_Object_Ref |
| 21651 |
|
| 21652 |
begin |
| 21653 |
if Is_Entity_Name (N) then |
| 21654 |
return Is_VFA_Object_Entity (Entity (N)); |
| 21655 |
|
| 21656 |
elsif Is_Volatile_Full_Access (Etype (N)) then |
| 21657 |
return True; |
| 21658 |
|
| 21659 |
elsif Nkind (N) = N_Selected_Component then |
| 21660 |
return Is_Volatile_Full_Access (Entity (Selector_Name (N))); |
| 21661 |
|
| 21662 |
else |
| 21663 |
return False; |
| 21664 |
end if; |
| 21665 |
end Is_Volatile_Full_Access_Object_Ref; |
| 21666 |
|
| 21667 |
-------------------------- |
| 21668 |
-- Is_Volatile_Function -- |
| 21669 |
-------------------------- |
| 21670 |
|
| 21671 |
function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is |
| 21672 |
begin |
| 21673 |
pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function); |
| 21674 |
|
| 21675 |
-- A protected function is volatile |
| 21676 |
|
| 21677 |
if Nkind (Parent (Unit_Declaration_Node (Func_Id))) = |
| 21678 |
N_Protected_Definition |
| 21679 |
then |
| 21680 |
return True; |
| 21681 |
|
| 21682 |
-- An instance of Ada.Unchecked_Conversion is a volatile function if |
| 21683 |
-- either the source or the target are effectively volatile. |
| 21684 |
|
| 21685 |
elsif Is_Unchecked_Conversion_Instance (Func_Id) |
| 21686 |
and then Has_Effectively_Volatile_Profile (Func_Id) |
| 21687 |
then |
| 21688 |
return True; |
| 21689 |
|
| 21690 |
-- A function with side-effects is volatile |
| 21691 |
|
| 21692 |
elsif Is_Function_With_Side_Effects (Func_Id) then |
| 21693 |
return True; |
| 21694 |
|
| 21695 |
-- Otherwise the function is treated as volatile if it is subject to |
| 21696 |
-- enabled pragma Volatile_Function. |
| 21697 |
|
| 21698 |
else |
| 21699 |
return |
| 21700 |
Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function)); |
| 21701 |
end if; |
| 21702 |
end Is_Volatile_Function; |
| 21703 |
|
| 21704 |
---------------------------- |
| 21705 |
-- Is_Volatile_Object_Ref -- |
| 21706 |
---------------------------- |
| 21707 |
|
| 21708 |
function Is_Volatile_Object_Ref (N : Node_Id) return Boolean is |
| 21709 |
function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean; |
| 21710 |
-- Determine whether arbitrary entity Id denotes an object that is |
| 21711 |
-- Volatile. |
| 21712 |
|
| 21713 |
function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean; |
| 21714 |
-- Determine whether prefix P has volatile components. This requires |
| 21715 |
-- the presence of a Volatile_Components aspect/pragma or that P be |
| 21716 |
-- itself a volatile object as per RM C.6(8). |
| 21717 |
|
| 21718 |
--------------------------------- |
| 21719 |
-- Is_Volatile_Object_Entity -- |
| 21720 |
--------------------------------- |
| 21721 |
|
| 21722 |
function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is |
| 21723 |
begin |
| 21724 |
return |
| 21725 |
Is_Object (Id) |
| 21726 |
and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id))); |
| 21727 |
end Is_Volatile_Object_Entity; |
| 21728 |
|
| 21729 |
------------------------------------ |
| 21730 |
-- Prefix_Has_Volatile_Components -- |
| 21731 |
------------------------------------ |
| 21732 |
|
| 21733 |
function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is |
| 21734 |
Typ : constant Entity_Id := Etype (P); |
| 21735 |
|
| 21736 |
begin |
| 21737 |
if Is_Access_Type (Typ) then |
| 21738 |
declare |
| 21739 |
Dtyp : constant Entity_Id := Designated_Type (Typ); |
| 21740 |
|
| 21741 |
begin |
| 21742 |
return Has_Volatile_Components (Dtyp) |
| 21743 |
or else Is_Volatile (Dtyp); |
| 21744 |
end; |
| 21745 |
|
| 21746 |
elsif Has_Volatile_Components (Typ) then |
| 21747 |
return True; |
| 21748 |
|
| 21749 |
elsif Is_Entity_Name (P) |
| 21750 |
and then Has_Volatile_Component (Entity (P)) |
| 21751 |
then |
| 21752 |
return True; |
| 21753 |
|
| 21754 |
elsif Is_Volatile_Object_Ref (P) then |
| 21755 |
return True; |
| 21756 |
|
| 21757 |
else |
| 21758 |
return False; |
| 21759 |
end if; |
| 21760 |
end Prefix_Has_Volatile_Components; |
| 21761 |
|
| 21762 |
-- Start of processing for Is_Volatile_Object_Ref |
| 21763 |
|
| 21764 |
begin |
| 21765 |
if Is_Entity_Name (N) then |
| 21766 |
return Is_Volatile_Object_Entity (Entity (N)); |
| 21767 |
|
| 21768 |
elsif Is_Volatile (Etype (N)) then |
| 21769 |
return True; |
| 21770 |
|
| 21771 |
elsif Nkind (N) = N_Indexed_Component then |
| 21772 |
return Prefix_Has_Volatile_Components (Prefix (N)); |
| 21773 |
|
| 21774 |
elsif Nkind (N) = N_Selected_Component then |
| 21775 |
return Prefix_Has_Volatile_Components (Prefix (N)) |
| 21776 |
or else Is_Volatile (Entity (Selector_Name (N))); |
| 21777 |
|
| 21778 |
else |
| 21779 |
return False; |
| 21780 |
end if; |
| 21781 |
end Is_Volatile_Object_Ref; |
| 21782 |
|
| 21783 |
----------------------------- |
| 21784 |
-- Iterate_Call_Parameters -- |
| 21785 |
----------------------------- |
| 21786 |
|
| 21787 |
procedure Iterate_Call_Parameters (Call : Node_Id) is |
| 21788 |
Actual : Node_Id := First_Actual (Call); |
| 21789 |
Formal : Entity_Id := First_Formal (Get_Called_Entity (Call)); |
| 21790 |
|
| 21791 |
begin |
| 21792 |
while Present (Formal) and then Present (Actual) loop |
| 21793 |
Handle_Parameter (Formal, Actual); |
| 21794 |
|
| 21795 |
Next_Formal (Formal); |
| 21796 |
Next_Actual (Actual); |
| 21797 |
end loop; |
| 21798 |
|
| 21799 |
pragma Assert (No (Formal)); |
| 21800 |
pragma Assert (No (Actual)); |
| 21801 |
end Iterate_Call_Parameters; |
| 21802 |
|
| 21803 |
-------------------------------- |
| 21804 |
-- Iterate_Interface_Ancestor -- |
| 21805 |
-------------------------------- |
| 21806 |
|
| 21807 |
function Iterator_Interface_Ancestor (Typ : Entity_Id) return Entity_Id is |
| 21808 |
begin |
| 21809 |
if Has_Interfaces (Typ) then |
| 21810 |
declare |
| 21811 |
Iface_Elmt : Elmt_Id; |
| 21812 |
Ifaces : Elist_Id; |
| 21813 |
Root_Iface : Entity_Id; |
| 21814 |
|
| 21815 |
begin |
| 21816 |
Collect_Interfaces (Typ, Ifaces); |
| 21817 |
|
| 21818 |
Iface_Elmt := First_Elmt (Ifaces); |
| 21819 |
while Present (Iface_Elmt) loop |
| 21820 |
Root_Iface := Root_Type (Node (Iface_Elmt)); |
| 21821 |
|
| 21822 |
if Chars (Root_Iface) |
| 21823 |
in Name_Forward_Iterator | Name_Reversible_Iterator |
| 21824 |
and then In_Predefined_Unit (Root_Iface) |
| 21825 |
then |
| 21826 |
return Root_Iface; |
| 21827 |
end if; |
| 21828 |
|
| 21829 |
Next_Elmt (Iface_Elmt); |
| 21830 |
end loop; |
| 21831 |
end; |
| 21832 |
end if; |
| 21833 |
|
| 21834 |
return Empty; |
| 21835 |
end Iterator_Interface_Ancestor; |
| 21836 |
|
| 21837 |
------------------------- |
| 21838 |
-- Kill_Current_Values -- |
| 21839 |
------------------------- |
| 21840 |
|
| 21841 |
procedure Kill_Current_Values |
| 21842 |
(Ent : Entity_Id; |
| 21843 |
Last_Assignment_Only : Boolean := False) |
| 21844 |
is |
| 21845 |
begin |
| 21846 |
if Is_Assignable (Ent) then |
| 21847 |
Set_Last_Assignment (Ent, Empty); |
| 21848 |
end if; |
| 21849 |
|
| 21850 |
if Is_Object (Ent) then |
| 21851 |
if not Last_Assignment_Only then |
| 21852 |
Kill_Checks (Ent); |
| 21853 |
Set_Current_Value (Ent, Empty); |
| 21854 |
|
| 21855 |
-- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags |
| 21856 |
-- for a constant. Once the constant is elaborated, its value is |
| 21857 |
-- not changed, therefore the associated flags that describe the |
| 21858 |
-- value should not be modified either. |
| 21859 |
|
| 21860 |
if Ekind (Ent) = E_Constant then |
| 21861 |
null; |
| 21862 |
|
| 21863 |
-- Non-constant entities |
| 21864 |
|
| 21865 |
else |
| 21866 |
if not Can_Never_Be_Null (Ent) then |
| 21867 |
Set_Is_Known_Non_Null (Ent, False); |
| 21868 |
end if; |
| 21869 |
|
| 21870 |
Set_Is_Known_Null (Ent, False); |
| 21871 |
|
| 21872 |
-- Reset the Is_Known_Valid flag unless the type is always |
| 21873 |
-- valid. This does not apply to a loop parameter because its |
| 21874 |
-- bounds are defined by the loop header and therefore always |
| 21875 |
-- valid. |
| 21876 |
|
| 21877 |
if not Is_Known_Valid (Etype (Ent)) |
| 21878 |
and then Ekind (Ent) /= E_Loop_Parameter |
| 21879 |
then |
| 21880 |
Set_Is_Known_Valid (Ent, False); |
| 21881 |
end if; |
| 21882 |
end if; |
| 21883 |
end if; |
| 21884 |
end if; |
| 21885 |
end Kill_Current_Values; |
| 21886 |
|
| 21887 |
procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is |
| 21888 |
S : Entity_Id; |
| 21889 |
|
| 21890 |
begin |
| 21891 |
-- Kill all saved checks, a special case of killing saved values |
| 21892 |
|
| 21893 |
if not Last_Assignment_Only then |
| 21894 |
Kill_All_Checks; |
| 21895 |
end if; |
| 21896 |
|
| 21897 |
-- Loop through relevant scopes, which includes the current scope and |
| 21898 |
-- any parent scopes if the current scope is a block or a package. |
| 21899 |
|
| 21900 |
S := Current_Scope; |
| 21901 |
Scope_Loop : loop |
| 21902 |
|
| 21903 |
-- Clear current values of all entities in current scope |
| 21904 |
|
| 21905 |
declare |
| 21906 |
Ent : Entity_Id; |
| 21907 |
begin |
| 21908 |
Ent := First_Entity (S); |
| 21909 |
while Present (Ent) loop |
| 21910 |
Kill_Current_Values (Ent, Last_Assignment_Only); |
| 21911 |
Next_Entity (Ent); |
| 21912 |
end loop; |
| 21913 |
end; |
| 21914 |
|
| 21915 |
-- If this is a not a subprogram, deal with parents |
| 21916 |
|
| 21917 |
if not Is_Subprogram (S) then |
| 21918 |
S := Scope (S); |
| 21919 |
exit Scope_Loop when S = Standard_Standard; |
| 21920 |
else |
| 21921 |
exit Scope_Loop; |
| 21922 |
end if; |
| 21923 |
end loop Scope_Loop; |
| 21924 |
end Kill_Current_Values; |
| 21925 |
|
| 21926 |
-------------------------- |
| 21927 |
-- Kill_Size_Check_Code -- |
| 21928 |
-------------------------- |
| 21929 |
|
| 21930 |
procedure Kill_Size_Check_Code (E : Entity_Id) is |
| 21931 |
begin |
| 21932 |
if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) |
| 21933 |
and then Present (Size_Check_Code (E)) |
| 21934 |
then |
| 21935 |
Remove (Size_Check_Code (E)); |
| 21936 |
Set_Size_Check_Code (E, Empty); |
| 21937 |
end if; |
| 21938 |
end Kill_Size_Check_Code; |
| 21939 |
|
| 21940 |
-------------------- |
| 21941 |
-- Known_Non_Null -- |
| 21942 |
-------------------- |
| 21943 |
|
| 21944 |
function Known_Non_Null (N : Node_Id) return Boolean is |
| 21945 |
Status : constant Null_Status_Kind := Null_Status (N); |
| 21946 |
|
| 21947 |
Id : Entity_Id; |
| 21948 |
Op : Node_Kind; |
| 21949 |
Val : Node_Id; |
| 21950 |
|
| 21951 |
begin |
| 21952 |
-- The expression yields a non-null value ignoring simple flow analysis |
| 21953 |
|
| 21954 |
if Status = Is_Non_Null then |
| 21955 |
return True; |
| 21956 |
|
| 21957 |
-- Otherwise check whether N is a reference to an entity that appears |
| 21958 |
-- within a conditional construct. |
| 21959 |
|
| 21960 |
elsif Is_Entity_Name (N) and then Present (Entity (N)) then |
| 21961 |
|
| 21962 |
-- First check if we are in decisive conditional |
| 21963 |
|
| 21964 |
Get_Current_Value_Condition (N, Op, Val); |
| 21965 |
|
| 21966 |
if Known_Null (Val) then |
| 21967 |
if Op = N_Op_Eq then |
| 21968 |
return False; |
| 21969 |
elsif Op = N_Op_Ne then |
| 21970 |
return True; |
| 21971 |
end if; |
| 21972 |
end if; |
| 21973 |
|
| 21974 |
-- If OK to do replacement, test Is_Known_Non_Null flag |
| 21975 |
|
| 21976 |
Id := Entity (N); |
| 21977 |
|
| 21978 |
if OK_To_Do_Constant_Replacement (Id) then |
| 21979 |
return Is_Known_Non_Null (Id); |
| 21980 |
end if; |
| 21981 |
end if; |
| 21982 |
|
| 21983 |
-- Otherwise it is not possible to determine whether N yields a non-null |
| 21984 |
-- value. |
| 21985 |
|
| 21986 |
return False; |
| 21987 |
end Known_Non_Null; |
| 21988 |
|
| 21989 |
---------------- |
| 21990 |
-- Known_Null -- |
| 21991 |
---------------- |
| 21992 |
|
| 21993 |
function Known_Null (N : Node_Id) return Boolean is |
| 21994 |
Status : constant Null_Status_Kind := Null_Status (N); |
| 21995 |
|
| 21996 |
Id : Entity_Id; |
| 21997 |
Op : Node_Kind; |
| 21998 |
Val : Node_Id; |
| 21999 |
|
| 22000 |
begin |
| 22001 |
-- The expression yields a null value ignoring simple flow analysis |
| 22002 |
|
| 22003 |
if Status = Is_Null then |
| 22004 |
return True; |
| 22005 |
|
| 22006 |
-- Otherwise check whether N is a reference to an entity that appears |
| 22007 |
-- within a conditional construct. |
| 22008 |
|
| 22009 |
elsif Is_Entity_Name (N) and then Present (Entity (N)) then |
| 22010 |
|
| 22011 |
-- First check if we are in decisive conditional |
| 22012 |
|
| 22013 |
Get_Current_Value_Condition (N, Op, Val); |
| 22014 |
|
| 22015 |
-- If Get_Current_Value_Condition were to return Val = N, then the |
| 22016 |
-- recursion below could be infinite. |
| 22017 |
|
| 22018 |
if Val = N then |
| 22019 |
raise Program_Error; |
| 22020 |
end if; |
| 22021 |
|
| 22022 |
if Known_Null (Val) then |
| 22023 |
if Op = N_Op_Eq then |
| 22024 |
return True; |
| 22025 |
elsif Op = N_Op_Ne then |
| 22026 |
return False; |
| 22027 |
end if; |
| 22028 |
end if; |
| 22029 |
|
| 22030 |
-- If OK to do replacement, test Is_Known_Null flag |
| 22031 |
|
| 22032 |
Id := Entity (N); |
| 22033 |
|
| 22034 |
if OK_To_Do_Constant_Replacement (Id) then |
| 22035 |
return Is_Known_Null (Id); |
| 22036 |
end if; |
| 22037 |
end if; |
| 22038 |
|
| 22039 |
-- Otherwise it is not possible to determine whether N yields a null |
| 22040 |
-- value. |
| 22041 |
|
| 22042 |
return False; |
| 22043 |
end Known_Null; |
| 22044 |
|
| 22045 |
--------------------------- |
| 22046 |
-- Last_Source_Statement -- |
| 22047 |
--------------------------- |
| 22048 |
|
| 22049 |
function Last_Source_Statement (HSS : Node_Id) return Node_Id is |
| 22050 |
N : Node_Id; |
| 22051 |
|
| 22052 |
begin |
| 22053 |
N := Last (Statements (HSS)); |
| 22054 |
while Present (N) loop |
| 22055 |
exit when Comes_From_Source (N); |
| 22056 |
Prev (N); |
| 22057 |
end loop; |
| 22058 |
|
| 22059 |
return N; |
| 22060 |
end Last_Source_Statement; |
| 22061 |
|
| 22062 |
----------------------- |
| 22063 |
-- Mark_Coextensions -- |
| 22064 |
----------------------- |
| 22065 |
|
| 22066 |
procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is |
| 22067 |
Is_Dynamic : Boolean; |
| 22068 |
-- Indicates whether the context causes nested coextensions to be |
| 22069 |
-- dynamic or static |
| 22070 |
|
| 22071 |
function Mark_Allocator (N : Node_Id) return Traverse_Result; |
| 22072 |
-- Recognize an allocator node and label it as a dynamic coextension |
| 22073 |
|
| 22074 |
-------------------- |
| 22075 |
-- Mark_Allocator -- |
| 22076 |
-------------------- |
| 22077 |
|
| 22078 |
function Mark_Allocator (N : Node_Id) return Traverse_Result is |
| 22079 |
begin |
| 22080 |
if Nkind (N) = N_Allocator then |
| 22081 |
if Is_Dynamic then |
| 22082 |
Set_Is_Static_Coextension (N, False); |
| 22083 |
Set_Is_Dynamic_Coextension (N); |
| 22084 |
|
| 22085 |
-- If the allocator expression is potentially dynamic, it may |
| 22086 |
-- be expanded out of order and require dynamic allocation |
| 22087 |
-- anyway, so we treat the coextension itself as dynamic. |
| 22088 |
-- Potential optimization ??? |
| 22089 |
|
| 22090 |
elsif Nkind (Expression (N)) = N_Qualified_Expression |
| 22091 |
and then Nkind (Expression (Expression (N))) = N_Op_Concat |
| 22092 |
then |
| 22093 |
Set_Is_Static_Coextension (N, False); |
| 22094 |
Set_Is_Dynamic_Coextension (N); |
| 22095 |
else |
| 22096 |
Set_Is_Dynamic_Coextension (N, False); |
| 22097 |
Set_Is_Static_Coextension (N); |
| 22098 |
end if; |
| 22099 |
end if; |
| 22100 |
|
| 22101 |
return OK; |
| 22102 |
end Mark_Allocator; |
| 22103 |
|
| 22104 |
procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator); |
| 22105 |
|
| 22106 |
-- Start of processing for Mark_Coextensions |
| 22107 |
|
| 22108 |
begin |
| 22109 |
-- An allocator that appears on the right-hand side of an assignment is |
| 22110 |
-- treated as a potentially dynamic coextension when the right-hand side |
| 22111 |
-- is an allocator or a qualified expression. |
| 22112 |
|
| 22113 |
-- Obj := new ...'(new Coextension ...); |
| 22114 |
|
| 22115 |
if Nkind (Context_Nod) = N_Assignment_Statement then |
| 22116 |
Is_Dynamic := Nkind (Expression (Context_Nod)) in |
| 22117 |
N_Allocator | N_Qualified_Expression; |
| 22118 |
|
| 22119 |
-- An allocator that appears within the expression of a simple return |
| 22120 |
-- statement is treated as a potentially dynamic coextension when the |
| 22121 |
-- expression is either aggregate, allocator, or qualified expression. |
| 22122 |
|
| 22123 |
-- return (new Coextension ...); |
| 22124 |
-- return new ...'(new Coextension ...); |
| 22125 |
|
| 22126 |
elsif Nkind (Context_Nod) = N_Simple_Return_Statement then |
| 22127 |
Is_Dynamic := Nkind (Expression (Context_Nod)) in |
| 22128 |
N_Aggregate | N_Allocator | N_Qualified_Expression; |
| 22129 |
|
| 22130 |
-- An alloctor that appears within the initialization expression of an |
| 22131 |
-- object declaration is considered a potentially dynamic coextension |
| 22132 |
-- when the initialization expression is an allocator or a qualified |
| 22133 |
-- expression. |
| 22134 |
|
| 22135 |
-- Obj : ... := new ...'(new Coextension ...); |
| 22136 |
|
| 22137 |
-- A similar case arises when the object declaration is part of an |
| 22138 |
-- extended return statement. |
| 22139 |
|
| 22140 |
-- return Obj : ... := new ...'(new Coextension ...); |
| 22141 |
-- return Obj : ... := (new Coextension ...); |
| 22142 |
|
| 22143 |
elsif Nkind (Context_Nod) = N_Object_Declaration then |
| 22144 |
Is_Dynamic := Nkind (Root_Nod) in N_Allocator | N_Qualified_Expression |
| 22145 |
or else Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement; |
| 22146 |
|
| 22147 |
-- This routine should not be called with constructs that cannot contain |
| 22148 |
-- coextensions. |
| 22149 |
|
| 22150 |
else |
| 22151 |
raise Program_Error; |
| 22152 |
end if; |
| 22153 |
|
| 22154 |
Mark_Allocators (Root_Nod); |
| 22155 |
end Mark_Coextensions; |
| 22156 |
|
| 22157 |
--------------------------------- |
| 22158 |
-- Mark_Elaboration_Attributes -- |
| 22159 |
--------------------------------- |
| 22160 |
|
| 22161 |
procedure Mark_Elaboration_Attributes |
| 22162 |
(N_Id : Node_Or_Entity_Id; |
| 22163 |
Checks : Boolean := False; |
| 22164 |
Level : Boolean := False; |
| 22165 |
Modes : Boolean := False; |
| 22166 |
Warnings : Boolean := False) |
| 22167 |
is |
| 22168 |
function Elaboration_Checks_OK |
| 22169 |
(Target_Id : Entity_Id; |
| 22170 |
Context_Id : Entity_Id) return Boolean; |
| 22171 |
-- Determine whether elaboration checks are enabled for target Target_Id |
| 22172 |
-- which resides within context Context_Id. |
| 22173 |
|
| 22174 |
procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id); |
| 22175 |
-- Preserve relevant attributes of the context in arbitrary entity Id |
| 22176 |
|
| 22177 |
procedure Mark_Elaboration_Attributes_Node (N : Node_Id); |
| 22178 |
-- Preserve relevant attributes of the context in arbitrary node N |
| 22179 |
|
| 22180 |
--------------------------- |
| 22181 |
-- Elaboration_Checks_OK -- |
| 22182 |
--------------------------- |
| 22183 |
|
| 22184 |
function Elaboration_Checks_OK |
| 22185 |
(Target_Id : Entity_Id; |
| 22186 |
Context_Id : Entity_Id) return Boolean |
| 22187 |
is |
| 22188 |
Encl_Scop : Entity_Id; |
| 22189 |
|
| 22190 |
begin |
| 22191 |
-- Elaboration checks are suppressed for the target |
| 22192 |
|
| 22193 |
if Elaboration_Checks_Suppressed (Target_Id) then |
| 22194 |
return False; |
| 22195 |
end if; |
| 22196 |
|
| 22197 |
-- Otherwise elaboration checks are OK for the target, but may be |
| 22198 |
-- suppressed for the context where the target is declared. |
| 22199 |
|
| 22200 |
Encl_Scop := Context_Id; |
| 22201 |
while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop |
| 22202 |
if Elaboration_Checks_Suppressed (Encl_Scop) then |
| 22203 |
return False; |
| 22204 |
end if; |
| 22205 |
|
| 22206 |
Encl_Scop := Scope (Encl_Scop); |
| 22207 |
end loop; |
| 22208 |
|
| 22209 |
-- Neither the target nor its declarative context have elaboration |
| 22210 |
-- checks suppressed. |
| 22211 |
|
| 22212 |
return True; |
| 22213 |
end Elaboration_Checks_OK; |
| 22214 |
|
| 22215 |
------------------------------------ |
| 22216 |
-- Mark_Elaboration_Attributes_Id -- |
| 22217 |
------------------------------------ |
| 22218 |
|
| 22219 |
procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is |
| 22220 |
begin |
| 22221 |
-- Mark the status of elaboration checks in effect. Do not reset the |
| 22222 |
-- status in case the entity is reanalyzed with checks suppressed. |
| 22223 |
|
| 22224 |
if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then |
| 22225 |
Set_Is_Elaboration_Checks_OK_Id (Id, |
| 22226 |
Elaboration_Checks_OK |
| 22227 |
(Target_Id => Id, |
| 22228 |
Context_Id => Scope (Id))); |
| 22229 |
end if; |
| 22230 |
|
| 22231 |
-- Mark the status of elaboration warnings in effect. Do not reset |
| 22232 |
-- the status in case the entity is reanalyzed with warnings off. |
| 22233 |
|
| 22234 |
if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then |
| 22235 |
Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings); |
| 22236 |
end if; |
| 22237 |
end Mark_Elaboration_Attributes_Id; |
| 22238 |
|
| 22239 |
-------------------------------------- |
| 22240 |
-- Mark_Elaboration_Attributes_Node -- |
| 22241 |
-------------------------------------- |
| 22242 |
|
| 22243 |
procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is |
| 22244 |
function Extract_Name (N : Node_Id) return Node_Id; |
| 22245 |
-- Obtain the Name attribute of call or instantiation N |
| 22246 |
|
| 22247 |
------------------ |
| 22248 |
-- Extract_Name -- |
| 22249 |
------------------ |
| 22250 |
|
| 22251 |
function Extract_Name (N : Node_Id) return Node_Id is |
| 22252 |
Nam : Node_Id; |
| 22253 |
|
| 22254 |
begin |
| 22255 |
Nam := Name (N); |
| 22256 |
|
| 22257 |
-- A call to an entry family appears in indexed form |
| 22258 |
|
| 22259 |
if Nkind (Nam) = N_Indexed_Component then |
| 22260 |
Nam := Prefix (Nam); |
| 22261 |
end if; |
| 22262 |
|
| 22263 |
-- The name may also appear in qualified form |
| 22264 |
|
| 22265 |
if Nkind (Nam) = N_Selected_Component then |
| 22266 |
Nam := Selector_Name (Nam); |
| 22267 |
end if; |
| 22268 |
|
| 22269 |
return Nam; |
| 22270 |
end Extract_Name; |
| 22271 |
|
| 22272 |
-- Local variables |
| 22273 |
|
| 22274 |
Context_Id : Entity_Id; |
| 22275 |
Nam : Node_Id; |
| 22276 |
|
| 22277 |
-- Start of processing for Mark_Elaboration_Attributes_Node |
| 22278 |
|
| 22279 |
begin |
| 22280 |
-- Mark the status of elaboration checks in effect. Do not reset the |
| 22281 |
-- status in case the node is reanalyzed with checks suppressed. |
| 22282 |
|
| 22283 |
if Checks and then not Is_Elaboration_Checks_OK_Node (N) then |
| 22284 |
|
| 22285 |
-- Assignments, attribute references, and variable references do |
| 22286 |
-- not have a "declarative" context. |
| 22287 |
|
| 22288 |
Context_Id := Empty; |
| 22289 |
|
| 22290 |
-- The status of elaboration checks for calls and instantiations |
| 22291 |
-- depends on the most recent pragma Suppress/Unsuppress, as well |
| 22292 |
-- as the suppression status of the context where the target is |
| 22293 |
-- defined. |
| 22294 |
|
| 22295 |
-- package Pack is |
| 22296 |
-- function Func ...; |
| 22297 |
-- end Pack; |
| 22298 |
|
| 22299 |
-- with Pack; |
| 22300 |
-- procedure Main is |
| 22301 |
-- pragma Suppress (Elaboration_Checks, Pack); |
| 22302 |
-- X : ... := Pack.Func; |
| 22303 |
-- ... |
| 22304 |
|
| 22305 |
-- In the example above, the call to Func has elaboration checks |
| 22306 |
-- enabled because there is no active general purpose suppression |
| 22307 |
-- pragma, however the elaboration checks of Pack are explicitly |
| 22308 |
-- suppressed. As a result the elaboration checks of the call must |
| 22309 |
-- be disabled in order to preserve this dependency. |
| 22310 |
|
| 22311 |
if Nkind (N) in N_Entry_Call_Statement |
| 22312 |
| N_Function_Call |
| 22313 |
| N_Function_Instantiation |
| 22314 |
| N_Package_Instantiation |
| 22315 |
| N_Procedure_Call_Statement |
| 22316 |
| N_Procedure_Instantiation |
| 22317 |
then |
| 22318 |
Nam := Extract_Name (N); |
| 22319 |
|
| 22320 |
if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then |
| 22321 |
Context_Id := Scope (Entity (Nam)); |
| 22322 |
end if; |
| 22323 |
end if; |
| 22324 |
|
| 22325 |
Set_Is_Elaboration_Checks_OK_Node (N, |
| 22326 |
Elaboration_Checks_OK |
| 22327 |
(Target_Id => Empty, |
| 22328 |
Context_Id => Context_Id)); |
| 22329 |
end if; |
| 22330 |
|
| 22331 |
-- Mark the enclosing level of the node. Do not reset the status in |
| 22332 |
-- case the node is relocated and reanalyzed. |
| 22333 |
|
| 22334 |
if Level and then not Is_Declaration_Level_Node (N) then |
| 22335 |
Set_Is_Declaration_Level_Node (N, |
| 22336 |
Find_Enclosing_Level (N) = Declaration_Level); |
| 22337 |
end if; |
| 22338 |
|
| 22339 |
-- Mark the Ghost and SPARK mode in effect |
| 22340 |
|
| 22341 |
if Modes then |
| 22342 |
if Ghost_Mode = Ignore then |
| 22343 |
Set_Is_Ignored_Ghost_Node (N); |
| 22344 |
end if; |
| 22345 |
|
| 22346 |
if SPARK_Mode = On then |
| 22347 |
Set_Is_SPARK_Mode_On_Node (N); |
| 22348 |
end if; |
| 22349 |
end if; |
| 22350 |
|
| 22351 |
-- Mark the status of elaboration warnings in effect. Do not reset |
| 22352 |
-- the status in case the node is reanalyzed with warnings off. |
| 22353 |
|
| 22354 |
if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then |
| 22355 |
Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings); |
| 22356 |
end if; |
| 22357 |
end Mark_Elaboration_Attributes_Node; |
| 22358 |
|
| 22359 |
-- Start of processing for Mark_Elaboration_Attributes |
| 22360 |
|
| 22361 |
begin |
| 22362 |
-- Do not capture any elaboration-related attributes when switch -gnatH |
| 22363 |
-- (legacy elaboration checking mode enabled) is in effect because the |
| 22364 |
-- attributes are useless to the legacy model. |
| 22365 |
|
| 22366 |
if Legacy_Elaboration_Checks then |
| 22367 |
return; |
| 22368 |
end if; |
| 22369 |
|
| 22370 |
if Nkind (N_Id) in N_Entity then |
| 22371 |
Mark_Elaboration_Attributes_Id (N_Id); |
| 22372 |
else |
| 22373 |
Mark_Elaboration_Attributes_Node (N_Id); |
| 22374 |
end if; |
| 22375 |
end Mark_Elaboration_Attributes; |
| 22376 |
|
| 22377 |
---------------------------------------- |
| 22378 |
-- Mark_Save_Invocation_Graph_Of_Body -- |
| 22379 |
---------------------------------------- |
| 22380 |
|
| 22381 |
procedure Mark_Save_Invocation_Graph_Of_Body is |
| 22382 |
Main : constant Node_Id := Cunit (Main_Unit); |
| 22383 |
Main_Unit : constant Node_Id := Unit (Main); |
| 22384 |
Aux_Id : Entity_Id; |
| 22385 |
|
| 22386 |
begin |
| 22387 |
Set_Save_Invocation_Graph_Of_Body (Main); |
| 22388 |
|
| 22389 |
-- Assume that the main unit does not have a complimentary unit |
| 22390 |
|
| 22391 |
Aux_Id := Empty; |
| 22392 |
|
| 22393 |
-- Obtain the complimentary unit of the main unit |
| 22394 |
|
| 22395 |
if Nkind (Main_Unit) in N_Generic_Package_Declaration |
| 22396 |
| N_Generic_Subprogram_Declaration |
| 22397 |
| N_Package_Declaration |
| 22398 |
| N_Subprogram_Declaration |
| 22399 |
then |
| 22400 |
Aux_Id := Corresponding_Body (Main_Unit); |
| 22401 |
|
| 22402 |
elsif Nkind (Main_Unit) in N_Package_Body |
| 22403 |
| N_Subprogram_Body |
| 22404 |
| N_Subprogram_Renaming_Declaration |
| 22405 |
then |
| 22406 |
Aux_Id := Corresponding_Spec (Main_Unit); |
| 22407 |
end if; |
| 22408 |
|
| 22409 |
if Present (Aux_Id) then |
| 22410 |
Set_Save_Invocation_Graph_Of_Body |
| 22411 |
(Parent (Unit_Declaration_Node (Aux_Id))); |
| 22412 |
end if; |
| 22413 |
end Mark_Save_Invocation_Graph_Of_Body; |
| 22414 |
|
| 22415 |
---------------------------------- |
| 22416 |
-- Matching_Static_Array_Bounds -- |
| 22417 |
---------------------------------- |
| 22418 |
|
| 22419 |
function Matching_Static_Array_Bounds |
| 22420 |
(L_Typ : Node_Id; |
| 22421 |
R_Typ : Node_Id) return Boolean |
| 22422 |
is |
| 22423 |
L_Ndims : constant Nat := Number_Dimensions (L_Typ); |
| 22424 |
R_Ndims : constant Nat := Number_Dimensions (R_Typ); |
| 22425 |
|
| 22426 |
L_Index : Node_Id := Empty; -- init to ... |
| 22427 |
R_Index : Node_Id := Empty; -- ...avoid warnings |
| 22428 |
L_Low : Node_Id; |
| 22429 |
L_High : Node_Id; |
| 22430 |
L_Len : Uint; |
| 22431 |
R_Low : Node_Id; |
| 22432 |
R_High : Node_Id; |
| 22433 |
R_Len : Uint; |
| 22434 |
|
| 22435 |
begin |
| 22436 |
if L_Ndims /= R_Ndims then |
| 22437 |
return False; |
| 22438 |
end if; |
| 22439 |
|
| 22440 |
-- Unconstrained types do not have static bounds |
| 22441 |
|
| 22442 |
if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then |
| 22443 |
return False; |
| 22444 |
end if; |
| 22445 |
|
| 22446 |
-- First treat specially the first dimension, as the lower bound and |
| 22447 |
-- length of string literals are not stored like those of arrays. |
| 22448 |
|
| 22449 |
if Ekind (L_Typ) = E_String_Literal_Subtype then |
| 22450 |
L_Low := String_Literal_Low_Bound (L_Typ); |
| 22451 |
L_Len := String_Literal_Length (L_Typ); |
| 22452 |
else |
| 22453 |
L_Index := First_Index (L_Typ); |
| 22454 |
Get_Index_Bounds (L_Index, L_Low, L_High); |
| 22455 |
|
| 22456 |
if Is_OK_Static_Expression (L_Low) |
| 22457 |
and then |
| 22458 |
Is_OK_Static_Expression (L_High) |
| 22459 |
then |
| 22460 |
if Expr_Value (L_High) < Expr_Value (L_Low) then |
| 22461 |
L_Len := Uint_0; |
| 22462 |
else |
| 22463 |
L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1; |
| 22464 |
end if; |
| 22465 |
else |
| 22466 |
return False; |
| 22467 |
end if; |
| 22468 |
end if; |
| 22469 |
|
| 22470 |
if Ekind (R_Typ) = E_String_Literal_Subtype then |
| 22471 |
R_Low := String_Literal_Low_Bound (R_Typ); |
| 22472 |
R_Len := String_Literal_Length (R_Typ); |
| 22473 |
else |
| 22474 |
R_Index := First_Index (R_Typ); |
| 22475 |
Get_Index_Bounds (R_Index, R_Low, R_High); |
| 22476 |
|
| 22477 |
if Is_OK_Static_Expression (R_Low) |
| 22478 |
and then |
| 22479 |
Is_OK_Static_Expression (R_High) |
| 22480 |
then |
| 22481 |
if Expr_Value (R_High) < Expr_Value (R_Low) then |
| 22482 |
R_Len := Uint_0; |
| 22483 |
else |
| 22484 |
R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1; |
| 22485 |
end if; |
| 22486 |
else |
| 22487 |
return False; |
| 22488 |
end if; |
| 22489 |
end if; |
| 22490 |
|
| 22491 |
if (Is_OK_Static_Expression (L_Low) |
| 22492 |
and then |
| 22493 |
Is_OK_Static_Expression (R_Low)) |
| 22494 |
and then Expr_Value (L_Low) = Expr_Value (R_Low) |
| 22495 |
and then L_Len = R_Len |
| 22496 |
then |
| 22497 |
null; |
| 22498 |
else |
| 22499 |
return False; |
| 22500 |
end if; |
| 22501 |
|
| 22502 |
-- Then treat all other dimensions |
| 22503 |
|
| 22504 |
for Indx in 2 .. L_Ndims loop |
| 22505 |
Next (L_Index); |
| 22506 |
Next (R_Index); |
| 22507 |
|
| 22508 |
Get_Index_Bounds (L_Index, L_Low, L_High); |
| 22509 |
Get_Index_Bounds (R_Index, R_Low, R_High); |
| 22510 |
|
| 22511 |
if (Is_OK_Static_Expression (L_Low) and then |
| 22512 |
Is_OK_Static_Expression (L_High) and then |
| 22513 |
Is_OK_Static_Expression (R_Low) and then |
| 22514 |
Is_OK_Static_Expression (R_High)) |
| 22515 |
and then (Expr_Value (L_Low) = Expr_Value (R_Low) |
| 22516 |
and then |
| 22517 |
Expr_Value (L_High) = Expr_Value (R_High)) |
| 22518 |
then |
| 22519 |
null; |
| 22520 |
else |
| 22521 |
return False; |
| 22522 |
end if; |
| 22523 |
end loop; |
| 22524 |
|
| 22525 |
-- If we fall through the loop, all indexes matched |
| 22526 |
|
| 22527 |
return True; |
| 22528 |
end Matching_Static_Array_Bounds; |
| 22529 |
|
| 22530 |
----------------- |
| 22531 |
-- Might_Raise -- |
| 22532 |
----------------- |
| 22533 |
|
| 22534 |
function Might_Raise (N : Node_Id) return Boolean is |
| 22535 |
Result : Boolean := False; |
| 22536 |
|
| 22537 |
function Process (N : Node_Id) return Traverse_Result; |
| 22538 |
-- Set Result to True if we find something that could raise an exception |
| 22539 |
|
| 22540 |
------------- |
| 22541 |
-- Process -- |
| 22542 |
------------- |
| 22543 |
|
| 22544 |
function Process (N : Node_Id) return Traverse_Result is |
| 22545 |
begin |
| 22546 |
if Nkind (N) in N_Procedure_Call_Statement |
| 22547 |
| N_Function_Call |
| 22548 |
| N_Raise_Statement |
| 22549 |
| N_Raise_xxx_Error |
| 22550 |
| N_Raise_Expression |
| 22551 |
then |
| 22552 |
Result := True; |
| 22553 |
return Abandon; |
| 22554 |
else |
| 22555 |
return OK; |
| 22556 |
end if; |
| 22557 |
end Process; |
| 22558 |
|
| 22559 |
procedure Set_Result is new Traverse_Proc (Process); |
| 22560 |
|
| 22561 |
-- Start of processing for Might_Raise |
| 22562 |
|
| 22563 |
begin |
| 22564 |
-- False if exceptions can't be propagated |
| 22565 |
|
| 22566 |
if No_Exception_Handlers_Set then |
| 22567 |
return False; |
| 22568 |
end if; |
| 22569 |
|
| 22570 |
-- If the checks handled by the back end are not disabled, we cannot |
| 22571 |
-- ensure that no exception will be raised. |
| 22572 |
|
| 22573 |
if not Access_Checks_Suppressed (Empty) |
| 22574 |
or else not Discriminant_Checks_Suppressed (Empty) |
| 22575 |
or else not Range_Checks_Suppressed (Empty) |
| 22576 |
or else not Index_Checks_Suppressed (Empty) |
| 22577 |
or else Opt.Stack_Checking_Enabled |
| 22578 |
then |
| 22579 |
return True; |
| 22580 |
end if; |
| 22581 |
|
| 22582 |
Set_Result (N); |
| 22583 |
return Result; |
| 22584 |
end Might_Raise; |
| 22585 |
|
| 22586 |
---------------------------------------- |
| 22587 |
-- Nearest_Class_Condition_Subprogram -- |
| 22588 |
---------------------------------------- |
| 22589 |
|
| 22590 |
function Nearest_Class_Condition_Subprogram |
| 22591 |
(Kind : Condition_Kind; |
| 22592 |
Spec_Id : Entity_Id) return Entity_Id |
| 22593 |
is |
| 22594 |
Subp_Id : constant Entity_Id := Ultimate_Alias (Spec_Id); |
| 22595 |
|
| 22596 |
begin |
| 22597 |
-- Prevent cascaded errors |
| 22598 |
|
| 22599 |
if not Is_Dispatching_Operation (Subp_Id) then |
| 22600 |
return Empty; |
| 22601 |
|
| 22602 |
-- No need to search if this subprogram has class-wide postconditions |
| 22603 |
|
| 22604 |
elsif Present (Class_Condition (Kind, Subp_Id)) then |
| 22605 |
return Subp_Id; |
| 22606 |
end if; |
| 22607 |
|
| 22608 |
-- Process the contracts of inherited subprograms, looking for |
| 22609 |
-- class-wide pre/postconditions. |
| 22610 |
|
| 22611 |
declare |
| 22612 |
Subps : constant Subprogram_List := Inherited_Subprograms (Subp_Id); |
| 22613 |
Subp_Id : Entity_Id; |
| 22614 |
|
| 22615 |
begin |
| 22616 |
for Index in Subps'Range loop |
| 22617 |
Subp_Id := Subps (Index); |
| 22618 |
|
| 22619 |
if Present (Alias (Subp_Id)) then |
| 22620 |
Subp_Id := Ultimate_Alias (Subp_Id); |
| 22621 |
end if; |
| 22622 |
|
| 22623 |
-- Wrappers of class-wide pre/postconditions reference the |
| 22624 |
-- parent primitive that has the inherited contract. |
| 22625 |
|
| 22626 |
if Is_LSP_Wrapper (Subp_Id) then |
| 22627 |
Subp_Id := LSP_Subprogram (Subp_Id); |
| 22628 |
end if; |
| 22629 |
|
| 22630 |
if Present (Class_Condition (Kind, Subp_Id)) then |
| 22631 |
return Subp_Id; |
| 22632 |
end if; |
| 22633 |
end loop; |
| 22634 |
end; |
| 22635 |
|
| 22636 |
return Empty; |
| 22637 |
end Nearest_Class_Condition_Subprogram; |
| 22638 |
|
| 22639 |
-------------------------------- |
| 22640 |
-- Nearest_Enclosing_Instance -- |
| 22641 |
-------------------------------- |
| 22642 |
|
| 22643 |
function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is |
| 22644 |
Inst : Entity_Id; |
| 22645 |
|
| 22646 |
begin |
| 22647 |
Inst := Scope (E); |
| 22648 |
while Present (Inst) and then Inst /= Standard_Standard loop |
| 22649 |
if Is_Generic_Instance (Inst) then |
| 22650 |
return Inst; |
| 22651 |
end if; |
| 22652 |
|
| 22653 |
Inst := Scope (Inst); |
| 22654 |
end loop; |
| 22655 |
|
| 22656 |
return Empty; |
| 22657 |
end Nearest_Enclosing_Instance; |
| 22658 |
|
| 22659 |
------------------------ |
| 22660 |
-- Needs_Finalization -- |
| 22661 |
------------------------ |
| 22662 |
|
| 22663 |
function Needs_Finalization (Typ : Entity_Id) return Boolean is |
| 22664 |
function Has_Some_Controlled_Component |
| 22665 |
(Input_Typ : Entity_Id) return Boolean; |
| 22666 |
-- Determine whether type Input_Typ has at least one controlled |
| 22667 |
-- component. |
| 22668 |
|
| 22669 |
----------------------------------- |
| 22670 |
-- Has_Some_Controlled_Component -- |
| 22671 |
----------------------------------- |
| 22672 |
|
| 22673 |
function Has_Some_Controlled_Component |
| 22674 |
(Input_Typ : Entity_Id) return Boolean |
| 22675 |
is |
| 22676 |
Comp : Entity_Id; |
| 22677 |
|
| 22678 |
begin |
| 22679 |
-- When a type is already frozen and has at least one controlled |
| 22680 |
-- component, or is manually decorated, it is sufficient to inspect |
| 22681 |
-- flag Has_Controlled_Component. |
| 22682 |
|
| 22683 |
if Has_Controlled_Component (Input_Typ) then |
| 22684 |
return True; |
| 22685 |
|
| 22686 |
-- Otherwise inspect the internals of the type |
| 22687 |
|
| 22688 |
elsif not Is_Frozen (Input_Typ) then |
| 22689 |
if Is_Array_Type (Input_Typ) then |
| 22690 |
return Needs_Finalization (Component_Type (Input_Typ)); |
| 22691 |
|
| 22692 |
elsif Is_Record_Type (Input_Typ) then |
| 22693 |
Comp := First_Component (Input_Typ); |
| 22694 |
while Present (Comp) loop |
| 22695 |
-- Skip _Parent component like Record_Type_Definition |
| 22696 |
|
| 22697 |
if Chars (Comp) /= Name_uParent |
| 22698 |
and then Needs_Finalization (Etype (Comp)) |
| 22699 |
then |
| 22700 |
return True; |
| 22701 |
end if; |
| 22702 |
|
| 22703 |
Next_Component (Comp); |
| 22704 |
end loop; |
| 22705 |
end if; |
| 22706 |
end if; |
| 22707 |
|
| 22708 |
return False; |
| 22709 |
end Has_Some_Controlled_Component; |
| 22710 |
|
| 22711 |
-- Start of processing for Needs_Finalization |
| 22712 |
|
| 22713 |
begin |
| 22714 |
-- Certain run-time configurations and targets do not provide support |
| 22715 |
-- for controlled types. |
| 22716 |
|
| 22717 |
if Restriction_Active (No_Finalization) then |
| 22718 |
return False; |
| 22719 |
|
| 22720 |
-- C++ types are not considered controlled. It is assumed that the non- |
| 22721 |
-- Ada side will handle their clean up. |
| 22722 |
|
| 22723 |
elsif Convention (Typ) = Convention_CPP then |
| 22724 |
return False; |
| 22725 |
|
| 22726 |
-- Class-wide types are treated as controlled because derivations from |
| 22727 |
-- the root type may introduce controlled components. |
| 22728 |
|
| 22729 |
elsif Is_Class_Wide_Type (Typ) then |
| 22730 |
return True; |
| 22731 |
|
| 22732 |
-- Concurrent types are controlled as long as their corresponding record |
| 22733 |
-- is controlled. |
| 22734 |
|
| 22735 |
elsif Is_Concurrent_Type (Typ) |
| 22736 |
and then Present (Corresponding_Record_Type (Typ)) |
| 22737 |
and then Needs_Finalization (Corresponding_Record_Type (Typ)) |
| 22738 |
then |
| 22739 |
return True; |
| 22740 |
|
| 22741 |
-- Otherwise the type is controlled when it is either derived from type |
| 22742 |
-- [Limited_]Controlled and not subject to aspect Disable_Controlled, or |
| 22743 |
-- contains at least one controlled component. |
| 22744 |
|
| 22745 |
else |
| 22746 |
return |
| 22747 |
Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ); |
| 22748 |
end if; |
| 22749 |
end Needs_Finalization; |
| 22750 |
|
| 22751 |
---------------------- |
| 22752 |
-- Needs_One_Actual -- |
| 22753 |
---------------------- |
| 22754 |
|
| 22755 |
function Needs_One_Actual (E : Entity_Id) return Boolean is |
| 22756 |
Formal : Entity_Id; |
| 22757 |
|
| 22758 |
begin |
| 22759 |
-- Ada 2005 or later, and formals present. The first formal must be |
| 22760 |
-- of a type that supports prefix notation: a controlling argument, |
| 22761 |
-- a class-wide type, an access to such, or an untagged record type |
| 22762 |
-- (when compiling with Core_Extensions allowed). |
| 22763 |
|
| 22764 |
if Ada_Version >= Ada_2005 |
| 22765 |
and then Present (First_Formal (E)) |
| 22766 |
and then No (Default_Value (First_Formal (E))) |
| 22767 |
and then |
| 22768 |
(Is_Controlling_Formal (First_Formal (E)) |
| 22769 |
or else Is_Class_Wide_Type (Etype (First_Formal (E))) |
| 22770 |
or else Is_Anonymous_Access_Type (Etype (First_Formal (E))) |
| 22771 |
or else (Core_Extensions_Allowed |
| 22772 |
and then Is_Record_Type (Etype (First_Formal (E))))) |
| 22773 |
then |
| 22774 |
Formal := Next_Formal (First_Formal (E)); |
| 22775 |
while Present (Formal) loop |
| 22776 |
if No (Default_Value (Formal)) then |
| 22777 |
return False; |
| 22778 |
end if; |
| 22779 |
|
| 22780 |
Next_Formal (Formal); |
| 22781 |
end loop; |
| 22782 |
|
| 22783 |
return True; |
| 22784 |
|
| 22785 |
-- Ada 83/95 or no formals |
| 22786 |
|
| 22787 |
else |
| 22788 |
return False; |
| 22789 |
end if; |
| 22790 |
end Needs_One_Actual; |
| 22791 |
|
| 22792 |
---------------------------- |
| 22793 |
-- Needs_Secondary_Stack -- |
| 22794 |
---------------------------- |
| 22795 |
|
| 22796 |
function Needs_Secondary_Stack (Id : Entity_Id) return Boolean is |
| 22797 |
pragma Assert (if Present (Id) then Ekind (Id) in E_Void | Type_Kind); |
| 22798 |
|
| 22799 |
function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean; |
| 22800 |
-- Called for untagged record and protected types. Return True if the |
| 22801 |
-- size of function results is known in the caller for Typ. |
| 22802 |
|
| 22803 |
function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean; |
| 22804 |
-- Returns True if Typ is a nonlimited record with defaulted |
| 22805 |
-- discriminants whose max size makes it unsuitable for allocating on |
| 22806 |
-- the primary stack. |
| 22807 |
|
| 22808 |
------------------------------ |
| 22809 |
-- Caller_Known_Size_Record -- |
| 22810 |
------------------------------ |
| 22811 |
|
| 22812 |
function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is |
| 22813 |
pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ)); |
| 22814 |
|
| 22815 |
function Depends_On_Discriminant (Typ : Entity_Id) return Boolean; |
| 22816 |
-- Called for untagged record and protected types. Return True if Typ |
| 22817 |
-- depends on discriminants, either directly when it is unconstrained |
| 22818 |
-- or indirectly when it is constrained by uplevel discriminants. |
| 22819 |
|
| 22820 |
----------------------------- |
| 22821 |
-- Depends_On_Discriminant -- |
| 22822 |
----------------------------- |
| 22823 |
|
| 22824 |
function Depends_On_Discriminant (Typ : Entity_Id) return Boolean is |
| 22825 |
Cons : Elmt_Id; |
| 22826 |
|
| 22827 |
begin |
| 22828 |
if Has_Discriminants (Typ) then |
| 22829 |
if not Is_Constrained (Typ) then |
| 22830 |
return True; |
| 22831 |
|
| 22832 |
else |
| 22833 |
Cons := First_Elmt (Discriminant_Constraint (Typ)); |
| 22834 |
while Present (Cons) loop |
| 22835 |
if Nkind (Node (Cons)) = N_Identifier |
| 22836 |
and then Ekind (Entity (Node (Cons))) = E_Discriminant |
| 22837 |
then |
| 22838 |
return True; |
| 22839 |
end if; |
| 22840 |
|
| 22841 |
Next_Elmt (Cons); |
| 22842 |
end loop; |
| 22843 |
end if; |
| 22844 |
end if; |
| 22845 |
|
| 22846 |
return False; |
| 22847 |
end Depends_On_Discriminant; |
| 22848 |
|
| 22849 |
-- Start of processing for Caller_Known_Size_Record |
| 22850 |
|
| 22851 |
begin |
| 22852 |
-- This is a protected type without Corresponding_Record_Type set, |
| 22853 |
-- typically because expansion is disabled. The safe thing to do is |
| 22854 |
-- to return True, so Needs_Secondary_Stack returns False. |
| 22855 |
|
| 22856 |
if No (Typ) then |
| 22857 |
return True; |
| 22858 |
end if; |
| 22859 |
|
| 22860 |
-- If either size is specified for the type, then it's known in the |
| 22861 |
-- caller in particular. Note that, even if the clause is confirming, |
| 22862 |
-- this does not change the outcome since the size was already known. |
| 22863 |
|
| 22864 |
if Has_Size_Clause (First_Subtype (Typ)) |
| 22865 |
or else Has_Object_Size_Clause (First_Subtype (Typ)) |
| 22866 |
then |
| 22867 |
return True; |
| 22868 |
end if; |
| 22869 |
|
| 22870 |
-- First see if we have a variant part and return False if it depends |
| 22871 |
-- on discriminants. |
| 22872 |
|
| 22873 |
if Has_Variant_Part (Typ) and then Depends_On_Discriminant (Typ) then |
| 22874 |
return False; |
| 22875 |
end if; |
| 22876 |
|
| 22877 |
-- Then loop over components and return False if their subtype has a |
| 22878 |
-- caller-unknown size, possibly recursively. |
| 22879 |
|
| 22880 |
-- ??? This is overly conservative, an array could be nested inside |
| 22881 |
-- some other record that is constrained by nondiscriminants. That |
| 22882 |
-- is, the recursive calls are too conservative. |
| 22883 |
|
| 22884 |
declare |
| 22885 |
Comp : Entity_Id; |
| 22886 |
|
| 22887 |
begin |
| 22888 |
Comp := First_Component (Typ); |
| 22889 |
while Present (Comp) loop |
| 22890 |
declare |
| 22891 |
Comp_Type : constant Entity_Id := |
| 22892 |
Underlying_Type (Etype (Comp)); |
| 22893 |
|
| 22894 |
begin |
| 22895 |
if Is_Record_Type (Comp_Type) then |
| 22896 |
if not Caller_Known_Size_Record (Comp_Type) then |
| 22897 |
return False; |
| 22898 |
end if; |
| 22899 |
|
| 22900 |
elsif Is_Protected_Type (Comp_Type) then |
| 22901 |
if not Caller_Known_Size_Record |
| 22902 |
(Corresponding_Record_Type (Comp_Type)) |
| 22903 |
then |
| 22904 |
return False; |
| 22905 |
end if; |
| 22906 |
|
| 22907 |
elsif Is_Array_Type (Comp_Type) then |
| 22908 |
if Size_Depends_On_Discriminant (Comp_Type) then |
| 22909 |
return False; |
| 22910 |
end if; |
| 22911 |
end if; |
| 22912 |
end; |
| 22913 |
|
| 22914 |
Next_Component (Comp); |
| 22915 |
end loop; |
| 22916 |
end; |
| 22917 |
|
| 22918 |
return True; |
| 22919 |
end Caller_Known_Size_Record; |
| 22920 |
|
| 22921 |
------------------------------ |
| 22922 |
-- Large_Max_Size_Mutable -- |
| 22923 |
------------------------------ |
| 22924 |
|
| 22925 |
function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is |
| 22926 |
pragma Assert (Typ = Underlying_Type (Typ)); |
| 22927 |
|
| 22928 |
function Is_Large_Discrete_Type (T : Entity_Id) return Boolean; |
| 22929 |
-- Returns true if the discrete type T has a large range |
| 22930 |
|
| 22931 |
---------------------------- |
| 22932 |
-- Is_Large_Discrete_Type -- |
| 22933 |
---------------------------- |
| 22934 |
|
| 22935 |
function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is |
| 22936 |
Threshold : constant Int := 16; |
| 22937 |
-- Arbitrary threshold above which we consider it "large". We want |
| 22938 |
-- a fairly large threshold, because these large types really |
| 22939 |
-- shouldn't have default discriminants in the first place, in |
| 22940 |
-- most cases. |
| 22941 |
|
| 22942 |
begin |
| 22943 |
return UI_To_Int (RM_Size (T)) > Threshold; |
| 22944 |
end Is_Large_Discrete_Type; |
| 22945 |
|
| 22946 |
-- Start of processing for Large_Max_Size_Mutable |
| 22947 |
|
| 22948 |
begin |
| 22949 |
if Is_Record_Type (Typ) |
| 22950 |
and then not Is_Inherently_Limited_Type (Typ) |
| 22951 |
and then Has_Defaulted_Discriminants (Typ) |
| 22952 |
then |
| 22953 |
-- Loop through the components, looking for an array whose upper |
| 22954 |
-- bound(s) depends on discriminants, where both the subtype of |
| 22955 |
-- the discriminant and the index subtype are too large. |
| 22956 |
|
| 22957 |
declare |
| 22958 |
Comp : Entity_Id; |
| 22959 |
|
| 22960 |
begin |
| 22961 |
Comp := First_Component (Typ); |
| 22962 |
while Present (Comp) loop |
| 22963 |
declare |
| 22964 |
Comp_Type : constant Entity_Id := |
| 22965 |
Underlying_Type (Etype (Comp)); |
| 22966 |
|
| 22967 |
Hi : Node_Id; |
| 22968 |
Indx : Node_Id; |
| 22969 |
Ityp : Entity_Id; |
| 22970 |
|
| 22971 |
begin |
| 22972 |
if Present (Comp_Type) |
| 22973 |
and then Is_Array_Type (Comp_Type) |
| 22974 |
then |
| 22975 |
Indx := First_Index (Comp_Type); |
| 22976 |
|
| 22977 |
while Present (Indx) loop |
| 22978 |
Ityp := Etype (Indx); |
| 22979 |
Hi := Type_High_Bound (Ityp); |
| 22980 |
|
| 22981 |
if Nkind (Hi) = N_Identifier |
| 22982 |
and then Ekind (Entity (Hi)) = E_Discriminant |
| 22983 |
and then Is_Large_Discrete_Type (Ityp) |
| 22984 |
and then Is_Large_Discrete_Type |
| 22985 |
(Etype (Entity (Hi))) |
| 22986 |
then |
| 22987 |
return True; |
| 22988 |
end if; |
| 22989 |
|
| 22990 |
Next_Index (Indx); |
| 22991 |
end loop; |
| 22992 |
end if; |
| 22993 |
end; |
| 22994 |
|
| 22995 |
Next_Component (Comp); |
| 22996 |
end loop; |
| 22997 |
end; |
| 22998 |
end if; |
| 22999 |
|
| 23000 |
return False; |
| 23001 |
end Large_Max_Size_Mutable; |
| 23002 |
|
| 23003 |
-- Local declarations |
| 23004 |
|
| 23005 |
Typ : constant Entity_Id := Underlying_Type (Id); |
| 23006 |
|
| 23007 |
-- Start of processing for Needs_Secondary_Stack |
| 23008 |
|
| 23009 |
begin |
| 23010 |
-- This is a private type which is not completed yet. This can only |
| 23011 |
-- happen in a default expression (of a formal parameter or of a |
| 23012 |
-- record component). The safe thing to do is to return False. |
| 23013 |
|
| 23014 |
if No (Typ) then |
| 23015 |
return False; |
| 23016 |
end if; |
| 23017 |
|
| 23018 |
-- Do not expand transient scope for non-existent procedure return or |
| 23019 |
-- string literal types. |
| 23020 |
|
| 23021 |
if Typ = Standard_Void_Type |
| 23022 |
or else Ekind (Typ) = E_String_Literal_Subtype |
| 23023 |
then |
| 23024 |
return False; |
| 23025 |
|
| 23026 |
-- If Typ is a generic formal incomplete type, then we want to look at |
| 23027 |
-- the actual type. |
| 23028 |
|
| 23029 |
elsif Ekind (Typ) = E_Record_Subtype |
| 23030 |
and then Present (Cloned_Subtype (Typ)) |
| 23031 |
then |
| 23032 |
return Needs_Secondary_Stack (Cloned_Subtype (Typ)); |
| 23033 |
|
| 23034 |
-- Class-wide types obviously have an unknown size. For specific tagged |
| 23035 |
-- types, if a call returning one of them is dispatching on result, and |
| 23036 |
-- this type is not returned on the secondary stack, then the call goes |
| 23037 |
-- through a thunk that only moves the result from the primary onto the |
| 23038 |
-- secondary stack, because the computation of the size of the result is |
| 23039 |
-- possible but complex from the outside. |
| 23040 |
|
| 23041 |
elsif Is_Class_Wide_Type (Typ) then |
| 23042 |
return True; |
| 23043 |
|
| 23044 |
-- If the return slot of the back end cannot be accessed, then there |
| 23045 |
-- is no way to call Adjust at the right time for the return object if |
| 23046 |
-- the type needs finalization, so the return object must be allocated |
| 23047 |
-- on the secondary stack. |
| 23048 |
|
| 23049 |
elsif not Back_End_Return_Slot and then Needs_Finalization (Typ) then |
| 23050 |
return True; |
| 23051 |
|
| 23052 |
-- Definite subtypes have a known size. This includes all elementary |
| 23053 |
-- types. Tasks have a known size even if they have discriminants, so |
| 23054 |
-- we return False here, with one exception: |
| 23055 |
-- For a type like: |
| 23056 |
-- type T (Last : Natural := 0) is |
| 23057 |
-- X : String (1 .. Last); |
| 23058 |
-- end record; |
| 23059 |
-- we return True. That's because for "P(F(...));", where F returns T, |
| 23060 |
-- we don't know the size of the result at the call site, so if we |
| 23061 |
-- allocated it on the primary stack, we would have to allocate the |
| 23062 |
-- maximum size, which is way too big. |
| 23063 |
|
| 23064 |
elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then |
| 23065 |
return Large_Max_Size_Mutable (Typ); |
| 23066 |
|
| 23067 |
-- Indefinite (discriminated) record type |
| 23068 |
|
| 23069 |
elsif Is_Record_Type (Typ) then |
| 23070 |
return not Caller_Known_Size_Record (Typ); |
| 23071 |
|
| 23072 |
-- Indefinite (discriminated) protected type |
| 23073 |
|
| 23074 |
elsif Is_Protected_Type (Typ) then |
| 23075 |
return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ)); |
| 23076 |
|
| 23077 |
-- Unconstrained array type |
| 23078 |
|
| 23079 |
else |
| 23080 |
pragma Assert (Is_Array_Type (Typ) and then not Is_Constrained (Typ)); |
| 23081 |
return True; |
| 23082 |
end if; |
| 23083 |
end Needs_Secondary_Stack; |
| 23084 |
|
| 23085 |
--------------------------------- |
| 23086 |
-- Needs_Simple_Initialization -- |
| 23087 |
--------------------------------- |
| 23088 |
|
| 23089 |
function Needs_Simple_Initialization |
| 23090 |
(Typ : Entity_Id; |
| 23091 |
Consider_IS : Boolean := True) return Boolean |
| 23092 |
is |
| 23093 |
Consider_IS_NS : constant Boolean := |
| 23094 |
Normalize_Scalars or (Initialize_Scalars and Consider_IS); |
| 23095 |
|
| 23096 |
begin |
| 23097 |
-- Never need initialization if it is suppressed |
| 23098 |
|
| 23099 |
if Initialization_Suppressed (Typ) then |
| 23100 |
return False; |
| 23101 |
end if; |
| 23102 |
|
| 23103 |
-- Check for private type, in which case test applies to the underlying |
| 23104 |
-- type of the private type. |
| 23105 |
|
| 23106 |
if Is_Private_Type (Typ) then |
| 23107 |
declare |
| 23108 |
RT : constant Entity_Id := Underlying_Type (Typ); |
| 23109 |
begin |
| 23110 |
if Present (RT) then |
| 23111 |
return Needs_Simple_Initialization (RT); |
| 23112 |
else |
| 23113 |
return False; |
| 23114 |
end if; |
| 23115 |
end; |
| 23116 |
|
| 23117 |
-- Scalar type with Default_Value aspect requires initialization |
| 23118 |
|
| 23119 |
elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then |
| 23120 |
return True; |
| 23121 |
|
| 23122 |
-- Cases needing simple initialization are access types, and, if pragma |
| 23123 |
-- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar |
| 23124 |
-- types. |
| 23125 |
|
| 23126 |
elsif Is_Access_Type (Typ) |
| 23127 |
or else (Consider_IS_NS and then Is_Scalar_Type (Typ)) |
| 23128 |
then |
| 23129 |
return True; |
| 23130 |
|
| 23131 |
-- Mutably tagged types require default initialization |
| 23132 |
|
| 23133 |
elsif Is_Mutably_Tagged_CW_Equivalent_Type (Typ) then |
| 23134 |
return True; |
| 23135 |
|
| 23136 |
-- If Initialize/Normalize_Scalars is in effect, string objects also |
| 23137 |
-- need initialization, unless they are created in the course of |
| 23138 |
-- expanding an aggregate (since in the latter case they will be |
| 23139 |
-- filled with appropriate initializing values before they are used). |
| 23140 |
|
| 23141 |
elsif Consider_IS_NS |
| 23142 |
and then Is_Standard_String_Type (Typ) |
| 23143 |
and then |
| 23144 |
(not Is_Itype (Typ) |
| 23145 |
or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate) |
| 23146 |
then |
| 23147 |
return True; |
| 23148 |
|
| 23149 |
else |
| 23150 |
return False; |
| 23151 |
end if; |
| 23152 |
end Needs_Simple_Initialization; |
| 23153 |
|
| 23154 |
------------------------------------- |
| 23155 |
-- Needs_Variable_Reference_Marker -- |
| 23156 |
------------------------------------- |
| 23157 |
|
| 23158 |
function Needs_Variable_Reference_Marker |
| 23159 |
(N : Node_Id; |
| 23160 |
Calls_OK : Boolean) return Boolean |
| 23161 |
is |
| 23162 |
function Within_Suitable_Context (Ref : Node_Id) return Boolean; |
| 23163 |
-- Deteremine whether variable reference Ref appears within a suitable |
| 23164 |
-- context that allows the creation of a marker. |
| 23165 |
|
| 23166 |
----------------------------- |
| 23167 |
-- Within_Suitable_Context -- |
| 23168 |
----------------------------- |
| 23169 |
|
| 23170 |
function Within_Suitable_Context (Ref : Node_Id) return Boolean is |
| 23171 |
Par : Node_Id; |
| 23172 |
|
| 23173 |
begin |
| 23174 |
Par := Ref; |
| 23175 |
while Present (Par) loop |
| 23176 |
|
| 23177 |
-- The context is not suitable when the reference appears within |
| 23178 |
-- the formal part of an instantiation which acts as compilation |
| 23179 |
-- unit because there is no proper list for the insertion of the |
| 23180 |
-- marker. |
| 23181 |
|
| 23182 |
if Nkind (Par) = N_Generic_Association |
| 23183 |
and then Nkind (Parent (Par)) in N_Generic_Instantiation |
| 23184 |
and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit |
| 23185 |
then |
| 23186 |
return False; |
| 23187 |
|
| 23188 |
-- The context is not suitable when the reference appears within |
| 23189 |
-- a pragma. If the pragma has run-time semantics, the reference |
| 23190 |
-- will be reconsidered once the pragma is expanded. |
| 23191 |
|
| 23192 |
elsif Nkind (Par) = N_Pragma then |
| 23193 |
return False; |
| 23194 |
|
| 23195 |
-- The context is not suitable when the reference appears within a |
| 23196 |
-- subprogram call, and the caller requests this behavior. |
| 23197 |
|
| 23198 |
elsif not Calls_OK |
| 23199 |
and then Nkind (Par) in N_Entry_Call_Statement |
| 23200 |
| N_Function_Call |
| 23201 |
| N_Procedure_Call_Statement |
| 23202 |
then |
| 23203 |
return False; |
| 23204 |
|
| 23205 |
-- Prevent the search from going too far |
| 23206 |
|
| 23207 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 23208 |
exit; |
| 23209 |
end if; |
| 23210 |
|
| 23211 |
Par := Parent (Par); |
| 23212 |
end loop; |
| 23213 |
|
| 23214 |
return True; |
| 23215 |
end Within_Suitable_Context; |
| 23216 |
|
| 23217 |
-- Local variables |
| 23218 |
|
| 23219 |
Prag : Node_Id; |
| 23220 |
Var_Id : Entity_Id; |
| 23221 |
|
| 23222 |
-- Start of processing for Needs_Variable_Reference_Marker |
| 23223 |
|
| 23224 |
begin |
| 23225 |
-- No marker needs to be created when switch -gnatH (legacy elaboration |
| 23226 |
-- checking mode enabled) is in effect because the legacy ABE mechanism |
| 23227 |
-- does not use markers. |
| 23228 |
|
| 23229 |
if Legacy_Elaboration_Checks then |
| 23230 |
return False; |
| 23231 |
|
| 23232 |
-- No marker needs to be created when the reference is preanalyzed |
| 23233 |
-- because the marker will be inserted in the wrong place. |
| 23234 |
|
| 23235 |
elsif Preanalysis_Active then |
| 23236 |
return False; |
| 23237 |
|
| 23238 |
-- Only references warrant a marker |
| 23239 |
|
| 23240 |
elsif Nkind (N) not in N_Expanded_Name | N_Identifier then |
| 23241 |
return False; |
| 23242 |
|
| 23243 |
-- Only source references warrant a marker |
| 23244 |
|
| 23245 |
elsif not Comes_From_Source (N) then |
| 23246 |
return False; |
| 23247 |
|
| 23248 |
-- No marker needs to be created when the reference is erroneous, left |
| 23249 |
-- in a bad state, or does not denote a variable. |
| 23250 |
|
| 23251 |
elsif not (Present (Entity (N)) |
| 23252 |
and then Ekind (Entity (N)) = E_Variable |
| 23253 |
and then Entity (N) /= Any_Id) |
| 23254 |
then |
| 23255 |
return False; |
| 23256 |
end if; |
| 23257 |
|
| 23258 |
Var_Id := Entity (N); |
| 23259 |
Prag := SPARK_Pragma (Var_Id); |
| 23260 |
|
| 23261 |
-- Both the variable and reference must appear in SPARK_Mode On regions |
| 23262 |
-- because this elaboration scenario falls under the SPARK rules. |
| 23263 |
|
| 23264 |
if not (Comes_From_Source (Var_Id) |
| 23265 |
and then Present (Prag) |
| 23266 |
and then Get_SPARK_Mode_From_Annotation (Prag) = On |
| 23267 |
and then Is_SPARK_Mode_On_Node (N)) |
| 23268 |
then |
| 23269 |
return False; |
| 23270 |
|
| 23271 |
-- No marker needs to be created when the reference does not appear |
| 23272 |
-- within a suitable context (see body for details). |
| 23273 |
|
| 23274 |
-- Performance note: parent traversal |
| 23275 |
|
| 23276 |
elsif not Within_Suitable_Context (N) then |
| 23277 |
return False; |
| 23278 |
end if; |
| 23279 |
|
| 23280 |
-- At this point it is known that the variable reference will play a |
| 23281 |
-- role in ABE diagnostics and requires a marker. |
| 23282 |
|
| 23283 |
return True; |
| 23284 |
end Needs_Variable_Reference_Marker; |
| 23285 |
|
| 23286 |
------------------------ |
| 23287 |
-- New_Copy_List_Tree -- |
| 23288 |
------------------------ |
| 23289 |
|
| 23290 |
function New_Copy_List_Tree (List : List_Id) return List_Id is |
| 23291 |
NL : List_Id; |
| 23292 |
E : Node_Id; |
| 23293 |
|
| 23294 |
begin |
| 23295 |
if List = No_List then |
| 23296 |
return No_List; |
| 23297 |
|
| 23298 |
else |
| 23299 |
NL := New_List; |
| 23300 |
E := First (List); |
| 23301 |
|
| 23302 |
while Present (E) loop |
| 23303 |
Append (New_Copy_Tree (E), NL); |
| 23304 |
Next (E); |
| 23305 |
end loop; |
| 23306 |
|
| 23307 |
return NL; |
| 23308 |
end if; |
| 23309 |
end New_Copy_List_Tree; |
| 23310 |
|
| 23311 |
------------------- |
| 23312 |
-- New_Copy_Tree -- |
| 23313 |
------------------- |
| 23314 |
|
| 23315 |
-- The following tables play a key role in replicating entities and Itypes. |
| 23316 |
-- They are intentionally declared at the library level rather than within |
| 23317 |
-- New_Copy_Tree to avoid elaborating them on each call. This performance |
| 23318 |
-- optimization saves up to 2% of the entire compilation time spent in the |
| 23319 |
-- front end. Care should be taken to reset the tables on each new call to |
| 23320 |
-- New_Copy_Tree. |
| 23321 |
|
| 23322 |
NCT_Table_Max : constant := 511; |
| 23323 |
|
| 23324 |
subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1; |
| 23325 |
|
| 23326 |
function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index; |
| 23327 |
-- Obtain the hash value of node or entity Key |
| 23328 |
|
| 23329 |
-------------------- |
| 23330 |
-- NCT_Table_Hash -- |
| 23331 |
-------------------- |
| 23332 |
|
| 23333 |
function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is |
| 23334 |
begin |
| 23335 |
return NCT_Table_Index (Key mod NCT_Table_Max); |
| 23336 |
end NCT_Table_Hash; |
| 23337 |
|
| 23338 |
---------------------- |
| 23339 |
-- NCT_New_Entities -- |
| 23340 |
---------------------- |
| 23341 |
|
| 23342 |
-- The following table maps old entities and Itypes to their corresponding |
| 23343 |
-- new entities and Itypes. |
| 23344 |
|
| 23345 |
-- Aaa -> Xxx |
| 23346 |
|
| 23347 |
package NCT_New_Entities is new Simple_HTable ( |
| 23348 |
Header_Num => NCT_Table_Index, |
| 23349 |
Element => Entity_Id, |
| 23350 |
No_Element => Empty, |
| 23351 |
Key => Entity_Id, |
| 23352 |
Hash => NCT_Table_Hash, |
| 23353 |
Equal => "="); |
| 23354 |
|
| 23355 |
------------------------ |
| 23356 |
-- NCT_Pending_Itypes -- |
| 23357 |
------------------------ |
| 23358 |
|
| 23359 |
-- The following table maps old Associated_Node_For_Itype nodes to a set of |
| 23360 |
-- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three |
| 23361 |
-- have the same Associated_Node_For_Itype Ppp, and their corresponding new |
| 23362 |
-- Itypes Xxx, Yyy, Zzz, the table contains the following mapping: |
| 23363 |
|
| 23364 |
-- Ppp -> (Xxx, Yyy, Zzz) |
| 23365 |
|
| 23366 |
-- The set is expressed as an Elist |
| 23367 |
|
| 23368 |
package NCT_Pending_Itypes is new Simple_HTable ( |
| 23369 |
Header_Num => NCT_Table_Index, |
| 23370 |
Element => Elist_Id, |
| 23371 |
No_Element => No_Elist, |
| 23372 |
Key => Node_Id, |
| 23373 |
Hash => NCT_Table_Hash, |
| 23374 |
Equal => "="); |
| 23375 |
|
| 23376 |
NCT_Tables_In_Use : Boolean := False; |
| 23377 |
-- This flag keeps track of whether the two tables NCT_New_Entities and |
| 23378 |
-- NCT_Pending_Itypes are in use. The flag is part of an optimization |
| 23379 |
-- where certain operations are not performed if the tables are not in |
| 23380 |
-- use. This saves up to 8% of the entire compilation time spent in the |
| 23381 |
-- front end. |
| 23382 |
|
| 23383 |
------------------- |
| 23384 |
-- New_Copy_Tree -- |
| 23385 |
------------------- |
| 23386 |
|
| 23387 |
function New_Copy_Tree |
| 23388 |
(Source : Node_Id; |
| 23389 |
Map : Elist_Id := No_Elist; |
| 23390 |
New_Sloc : Source_Ptr := No_Location; |
| 23391 |
New_Scope : Entity_Id := Empty) return Node_Id |
| 23392 |
is |
| 23393 |
-- This routine performs low-level tree manipulations and needs access |
| 23394 |
-- to the internals of the tree. |
| 23395 |
|
| 23396 |
EWA_Level : Nat := 0; |
| 23397 |
-- This counter keeps track of how many N_Expression_With_Actions nodes |
| 23398 |
-- are encountered during a depth-first traversal of the subtree. These |
| 23399 |
-- nodes may define new entities in their Actions lists and thus require |
| 23400 |
-- special processing. |
| 23401 |
|
| 23402 |
EWA_Inner_Scope_Level : Nat := 0; |
| 23403 |
-- This counter keeps track of how many scoping constructs appear within |
| 23404 |
-- an N_Expression_With_Actions node. |
| 23405 |
|
| 23406 |
procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id); |
| 23407 |
pragma Inline (Add_New_Entity); |
| 23408 |
-- Add an entry in the NCT_New_Entities table which maps key Old_Id to |
| 23409 |
-- value New_Id. Old_Id is an entity which appears within the Actions |
| 23410 |
-- list of an N_Expression_With_Actions node, or within an entity map. |
| 23411 |
-- New_Id is the corresponding new entity generated during Phase 1. |
| 23412 |
|
| 23413 |
procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id); |
| 23414 |
pragma Inline (Add_Pending_Itype); |
| 23415 |
-- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to |
| 23416 |
-- value Itype. Assoc_Nod is the associated node of an itype. Itype is |
| 23417 |
-- an itype. |
| 23418 |
|
| 23419 |
procedure Build_NCT_Tables (Entity_Map : Elist_Id); |
| 23420 |
pragma Inline (Build_NCT_Tables); |
| 23421 |
-- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the |
| 23422 |
-- information supplied in entity map Entity_Map. The format of the |
| 23423 |
-- entity map must be as follows: |
| 23424 |
-- |
| 23425 |
-- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN |
| 23426 |
|
| 23427 |
function Copy_Any_Node_With_Replacement |
| 23428 |
(N : Node_Or_Entity_Id) return Node_Or_Entity_Id; |
| 23429 |
pragma Inline (Copy_Any_Node_With_Replacement); |
| 23430 |
-- Replicate entity or node N by invoking one of the following routines: |
| 23431 |
-- |
| 23432 |
-- Copy_Node_With_Replacement |
| 23433 |
-- Corresponding_Entity |
| 23434 |
|
| 23435 |
function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id; |
| 23436 |
-- Replicate the elements of entity list List |
| 23437 |
|
| 23438 |
function Copy_Field_With_Replacement |
| 23439 |
(Field : Union_Id; |
| 23440 |
Old_Par : Node_Id := Empty; |
| 23441 |
New_Par : Node_Id := Empty; |
| 23442 |
Semantic : Boolean := False) return Union_Id; |
| 23443 |
-- Replicate field Field by invoking one of the following routines: |
| 23444 |
-- |
| 23445 |
-- Copy_Elist_With_Replacement |
| 23446 |
-- Copy_List_With_Replacement |
| 23447 |
-- Copy_Node_With_Replacement |
| 23448 |
-- Corresponding_Entity |
| 23449 |
-- |
| 23450 |
-- If the field is not an entity list, entity, itype, syntactic list, |
| 23451 |
-- or node, then the field is returned unchanged. The routine always |
| 23452 |
-- replicates entities, itypes, and valid syntactic fields. Old_Par is |
| 23453 |
-- the expected parent of a syntactic field. New_Par is the new parent |
| 23454 |
-- associated with a replicated syntactic field. Flag Semantic should |
| 23455 |
-- be set when the input is a semantic field. |
| 23456 |
|
| 23457 |
function Copy_List_With_Replacement (List : List_Id) return List_Id; |
| 23458 |
-- Replicate the elements of syntactic list List |
| 23459 |
|
| 23460 |
function Copy_Node_With_Replacement (N : Node_Id) return Node_Id; |
| 23461 |
-- Replicate node N |
| 23462 |
|
| 23463 |
function Corresponding_Entity (Id : Entity_Id) return Entity_Id; |
| 23464 |
pragma Inline (Corresponding_Entity); |
| 23465 |
-- Return the corresponding new entity of Id generated during Phase 1. |
| 23466 |
-- If there is no such entity, return Id. |
| 23467 |
|
| 23468 |
function In_Entity_Map |
| 23469 |
(Id : Entity_Id; |
| 23470 |
Entity_Map : Elist_Id) return Boolean; |
| 23471 |
pragma Inline (In_Entity_Map); |
| 23472 |
-- Determine whether entity Id is one of the old ids specified in entity |
| 23473 |
-- map Entity_Map. The format of the entity map must be as follows: |
| 23474 |
-- |
| 23475 |
-- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN |
| 23476 |
|
| 23477 |
procedure Update_CFS_Sloc (N : Node_Or_Entity_Id); |
| 23478 |
pragma Inline (Update_CFS_Sloc); |
| 23479 |
-- Update the Comes_From_Source and Sloc attributes of node or entity N |
| 23480 |
|
| 23481 |
procedure Update_Controlling_Argument |
| 23482 |
(Old_Call : Node_Id; |
| 23483 |
New_Call : Node_Id); |
| 23484 |
pragma Inline (Update_Controlling_Argument); |
| 23485 |
-- Update Controlling_Argument of New_Call base on Old_Call to make it |
| 23486 |
-- points to the corresponding newly copied actual parameter. |
| 23487 |
|
| 23488 |
procedure Update_Named_Associations |
| 23489 |
(Old_Call : Node_Id; |
| 23490 |
New_Call : Node_Id); |
| 23491 |
pragma Inline (Update_Named_Associations); |
| 23492 |
-- Update semantic chain First/Next_Named_Association of call New_call |
| 23493 |
-- based on call Old_Call. |
| 23494 |
|
| 23495 |
procedure Update_New_Entities (Entity_Map : Elist_Id); |
| 23496 |
pragma Inline (Update_New_Entities); |
| 23497 |
-- Update the semantic attributes of all new entities generated during |
| 23498 |
-- Phase 1 that do not appear in entity map Entity_Map. The format of |
| 23499 |
-- the entity map must be as follows: |
| 23500 |
-- |
| 23501 |
-- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN |
| 23502 |
|
| 23503 |
procedure Update_Pending_Itypes |
| 23504 |
(Old_Assoc : Node_Id; |
| 23505 |
New_Assoc : Node_Id); |
| 23506 |
pragma Inline (Update_Pending_Itypes); |
| 23507 |
-- Update semantic attribute Associated_Node_For_Itype to refer to node |
| 23508 |
-- New_Assoc for all itypes whose associated node is Old_Assoc. |
| 23509 |
|
| 23510 |
procedure Update_Semantic_Fields (Id : Entity_Id); |
| 23511 |
pragma Inline (Update_Semantic_Fields); |
| 23512 |
-- Subsidiary to Update_New_Entities. Update semantic fields of entity |
| 23513 |
-- or itype Id. |
| 23514 |
|
| 23515 |
procedure Visit_Any_Node (N : Node_Or_Entity_Id); |
| 23516 |
pragma Inline (Visit_Any_Node); |
| 23517 |
-- Visit entity of node N by invoking one of the following routines: |
| 23518 |
-- |
| 23519 |
-- Visit_Entity |
| 23520 |
-- Visit_Itype |
| 23521 |
-- Visit_Node |
| 23522 |
|
| 23523 |
procedure Visit_Elist (List : Elist_Id); |
| 23524 |
-- Visit the elements of entity list List |
| 23525 |
|
| 23526 |
procedure Visit_Entity (Id : Entity_Id); |
| 23527 |
-- Visit entity Id. This action may create a new entity of Id and save |
| 23528 |
-- it in table NCT_New_Entities. |
| 23529 |
|
| 23530 |
procedure Visit_Field |
| 23531 |
(Field : Union_Id; |
| 23532 |
Par_Nod : Node_Id := Empty; |
| 23533 |
Semantic : Boolean := False); |
| 23534 |
-- Visit field Field by invoking one of the following routines: |
| 23535 |
-- |
| 23536 |
-- Visit_Elist |
| 23537 |
-- Visit_Entity |
| 23538 |
-- Visit_Itype |
| 23539 |
-- Visit_List |
| 23540 |
-- Visit_Node |
| 23541 |
-- |
| 23542 |
-- If the field is not an entity list, entity, itype, syntactic list, |
| 23543 |
-- or node, then the field is not visited. The routine always visits |
| 23544 |
-- valid syntactic fields. Par_Nod is the expected parent of the |
| 23545 |
-- syntactic field. Flag Semantic should be set when the input is a |
| 23546 |
-- semantic field. |
| 23547 |
|
| 23548 |
procedure Visit_Itype (Itype : Entity_Id); |
| 23549 |
-- Visit itype Itype. This action may create a new entity for Itype and |
| 23550 |
-- save it in table NCT_New_Entities. In addition, the routine may map |
| 23551 |
-- the associated node of Itype to the new itype in NCT_Pending_Itypes. |
| 23552 |
|
| 23553 |
procedure Visit_List (List : List_Id); |
| 23554 |
-- Visit the elements of syntactic list List |
| 23555 |
|
| 23556 |
procedure Visit_Node (N : Node_Id); |
| 23557 |
-- Visit node N |
| 23558 |
|
| 23559 |
procedure Visit_Semantic_Fields (Id : Entity_Id); |
| 23560 |
pragma Inline (Visit_Semantic_Fields); |
| 23561 |
-- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic |
| 23562 |
-- fields of entity or itype Id. |
| 23563 |
|
| 23564 |
-------------------- |
| 23565 |
-- Add_New_Entity -- |
| 23566 |
-------------------- |
| 23567 |
|
| 23568 |
procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is |
| 23569 |
begin |
| 23570 |
pragma Assert (Present (Old_Id)); |
| 23571 |
pragma Assert (Present (New_Id)); |
| 23572 |
pragma Assert (Nkind (Old_Id) in N_Entity); |
| 23573 |
pragma Assert (Nkind (New_Id) in N_Entity); |
| 23574 |
|
| 23575 |
NCT_Tables_In_Use := True; |
| 23576 |
|
| 23577 |
-- Sanity check the NCT_New_Entities table. No previous mapping with |
| 23578 |
-- key Old_Id should exist. |
| 23579 |
|
| 23580 |
pragma Assert (No (NCT_New_Entities.Get (Old_Id))); |
| 23581 |
|
| 23582 |
-- Establish the mapping |
| 23583 |
|
| 23584 |
-- Old_Id -> New_Id |
| 23585 |
|
| 23586 |
NCT_New_Entities.Set (Old_Id, New_Id); |
| 23587 |
end Add_New_Entity; |
| 23588 |
|
| 23589 |
----------------------- |
| 23590 |
-- Add_Pending_Itype -- |
| 23591 |
----------------------- |
| 23592 |
|
| 23593 |
procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is |
| 23594 |
Itypes : Elist_Id; |
| 23595 |
|
| 23596 |
begin |
| 23597 |
pragma Assert (Present (Assoc_Nod)); |
| 23598 |
pragma Assert (Present (Itype)); |
| 23599 |
pragma Assert (Nkind (Itype) in N_Entity); |
| 23600 |
pragma Assert (Is_Itype (Itype)); |
| 23601 |
|
| 23602 |
NCT_Tables_In_Use := True; |
| 23603 |
|
| 23604 |
-- It is not possible to sanity check the NCT_Pendint_Itypes table |
| 23605 |
-- directly because a single node may act as the associated node for |
| 23606 |
-- multiple itypes. |
| 23607 |
|
| 23608 |
Itypes := NCT_Pending_Itypes.Get (Assoc_Nod); |
| 23609 |
|
| 23610 |
if No (Itypes) then |
| 23611 |
Itypes := New_Elmt_List; |
| 23612 |
NCT_Pending_Itypes.Set (Assoc_Nod, Itypes); |
| 23613 |
end if; |
| 23614 |
|
| 23615 |
-- Establish the mapping |
| 23616 |
|
| 23617 |
-- Assoc_Nod -> (Itype, ...) |
| 23618 |
|
| 23619 |
-- Avoid inserting the same itype multiple times. This involves a |
| 23620 |
-- linear search, however the set of itypes with the same associated |
| 23621 |
-- node is very small. |
| 23622 |
|
| 23623 |
Append_Unique_Elmt (Itype, Itypes); |
| 23624 |
end Add_Pending_Itype; |
| 23625 |
|
| 23626 |
---------------------- |
| 23627 |
-- Build_NCT_Tables -- |
| 23628 |
---------------------- |
| 23629 |
|
| 23630 |
procedure Build_NCT_Tables (Entity_Map : Elist_Id) is |
| 23631 |
Elmt : Elmt_Id; |
| 23632 |
Old_Id : Entity_Id; |
| 23633 |
New_Id : Entity_Id; |
| 23634 |
|
| 23635 |
begin |
| 23636 |
-- Nothing to do when there is no entity map |
| 23637 |
|
| 23638 |
if No (Entity_Map) then |
| 23639 |
return; |
| 23640 |
end if; |
| 23641 |
|
| 23642 |
Elmt := First_Elmt (Entity_Map); |
| 23643 |
while Present (Elmt) loop |
| 23644 |
|
| 23645 |
-- Extract the (Old_Id, New_Id) pair from the entity map |
| 23646 |
|
| 23647 |
Old_Id := Node (Elmt); |
| 23648 |
Next_Elmt (Elmt); |
| 23649 |
|
| 23650 |
New_Id := Node (Elmt); |
| 23651 |
Next_Elmt (Elmt); |
| 23652 |
|
| 23653 |
-- Establish the following mapping within table NCT_New_Entities |
| 23654 |
|
| 23655 |
-- Old_Id -> New_Id |
| 23656 |
|
| 23657 |
Add_New_Entity (Old_Id, New_Id); |
| 23658 |
|
| 23659 |
-- Establish the following mapping within table NCT_Pending_Itypes |
| 23660 |
-- when the new entity is an itype. |
| 23661 |
|
| 23662 |
-- Assoc_Nod -> (New_Id, ...) |
| 23663 |
|
| 23664 |
-- IMPORTANT: the associated node is that of the old itype because |
| 23665 |
-- the node will be replicated in Phase 2. |
| 23666 |
|
| 23667 |
if Is_Itype (Old_Id) then |
| 23668 |
Add_Pending_Itype |
| 23669 |
(Assoc_Nod => Associated_Node_For_Itype (Old_Id), |
| 23670 |
Itype => New_Id); |
| 23671 |
end if; |
| 23672 |
end loop; |
| 23673 |
end Build_NCT_Tables; |
| 23674 |
|
| 23675 |
------------------------------------ |
| 23676 |
-- Copy_Any_Node_With_Replacement -- |
| 23677 |
------------------------------------ |
| 23678 |
|
| 23679 |
function Copy_Any_Node_With_Replacement |
| 23680 |
(N : Node_Or_Entity_Id) return Node_Or_Entity_Id |
| 23681 |
is |
| 23682 |
begin |
| 23683 |
if Nkind (N) in N_Entity then |
| 23684 |
return Corresponding_Entity (N); |
| 23685 |
else |
| 23686 |
return Copy_Node_With_Replacement (N); |
| 23687 |
end if; |
| 23688 |
end Copy_Any_Node_With_Replacement; |
| 23689 |
|
| 23690 |
--------------------------------- |
| 23691 |
-- Copy_Elist_With_Replacement -- |
| 23692 |
--------------------------------- |
| 23693 |
|
| 23694 |
function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is |
| 23695 |
Elmt : Elmt_Id; |
| 23696 |
Result : Elist_Id; |
| 23697 |
|
| 23698 |
begin |
| 23699 |
-- Copy the contents of the old list. Note that the list itself may |
| 23700 |
-- be empty, in which case the routine returns a new empty list. This |
| 23701 |
-- avoids sharing lists between subtrees. The element of an entity |
| 23702 |
-- list could be an entity or a node, hence the invocation of routine |
| 23703 |
-- Copy_Any_Node_With_Replacement. |
| 23704 |
|
| 23705 |
if Present (List) then |
| 23706 |
Result := New_Elmt_List; |
| 23707 |
|
| 23708 |
Elmt := First_Elmt (List); |
| 23709 |
while Present (Elmt) loop |
| 23710 |
Append_Elmt |
| 23711 |
(Copy_Any_Node_With_Replacement (Node (Elmt)), Result); |
| 23712 |
|
| 23713 |
Next_Elmt (Elmt); |
| 23714 |
end loop; |
| 23715 |
|
| 23716 |
-- Otherwise the list does not exist |
| 23717 |
|
| 23718 |
else |
| 23719 |
Result := No_Elist; |
| 23720 |
end if; |
| 23721 |
|
| 23722 |
return Result; |
| 23723 |
end Copy_Elist_With_Replacement; |
| 23724 |
|
| 23725 |
--------------------------------- |
| 23726 |
-- Copy_Field_With_Replacement -- |
| 23727 |
--------------------------------- |
| 23728 |
|
| 23729 |
function Copy_Field_With_Replacement |
| 23730 |
(Field : Union_Id; |
| 23731 |
Old_Par : Node_Id := Empty; |
| 23732 |
New_Par : Node_Id := Empty; |
| 23733 |
Semantic : Boolean := False) return Union_Id |
| 23734 |
is |
| 23735 |
begin |
| 23736 |
-- The field is empty |
| 23737 |
|
| 23738 |
if Field = Union_Id (Empty) then |
| 23739 |
return Field; |
| 23740 |
|
| 23741 |
-- The field is an entity/itype/node |
| 23742 |
|
| 23743 |
elsif Field in Node_Range then |
| 23744 |
declare |
| 23745 |
Old_N : constant Node_Id := Node_Id (Field); |
| 23746 |
Syntactic : constant Boolean := |
| 23747 |
Is_Syntactic_Node (Source => Old_Par, Field => Old_N); |
| 23748 |
|
| 23749 |
New_N : Node_Id; |
| 23750 |
|
| 23751 |
begin |
| 23752 |
-- The field is an entity/itype |
| 23753 |
|
| 23754 |
if Nkind (Old_N) in N_Entity then |
| 23755 |
|
| 23756 |
-- An entity/itype is always replicated |
| 23757 |
|
| 23758 |
New_N := Corresponding_Entity (Old_N); |
| 23759 |
|
| 23760 |
-- Update the parent pointer when the entity is a syntactic |
| 23761 |
-- field. Note that itypes do not have parent pointers. |
| 23762 |
|
| 23763 |
if Syntactic and then New_N /= Old_N then |
| 23764 |
Set_Parent (New_N, New_Par); |
| 23765 |
end if; |
| 23766 |
|
| 23767 |
-- The field is a node |
| 23768 |
|
| 23769 |
else |
| 23770 |
-- A node is replicated when it is either a syntactic field |
| 23771 |
-- or when the caller treats it as a semantic attribute. |
| 23772 |
|
| 23773 |
if Syntactic or else Semantic then |
| 23774 |
New_N := Copy_Node_With_Replacement (Old_N); |
| 23775 |
|
| 23776 |
-- Update the parent pointer when the node is a syntactic |
| 23777 |
-- field. |
| 23778 |
|
| 23779 |
if Syntactic and then New_N /= Old_N then |
| 23780 |
Set_Parent (New_N, New_Par); |
| 23781 |
end if; |
| 23782 |
|
| 23783 |
-- Otherwise the node is returned unchanged |
| 23784 |
|
| 23785 |
else |
| 23786 |
New_N := Old_N; |
| 23787 |
end if; |
| 23788 |
end if; |
| 23789 |
|
| 23790 |
return Union_Id (New_N); |
| 23791 |
end; |
| 23792 |
|
| 23793 |
-- The field is an entity list |
| 23794 |
|
| 23795 |
elsif Field in Elist_Range then |
| 23796 |
return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field))); |
| 23797 |
|
| 23798 |
-- The field is a syntactic list |
| 23799 |
|
| 23800 |
elsif Field in List_Range then |
| 23801 |
declare |
| 23802 |
Old_List : constant List_Id := List_Id (Field); |
| 23803 |
Syntactic : constant Boolean := Parent (Old_List) = Old_Par; |
| 23804 |
|
| 23805 |
New_List : List_Id; |
| 23806 |
|
| 23807 |
begin |
| 23808 |
-- A list is replicated when it is either a syntactic field or |
| 23809 |
-- when the caller treats it as a semantic attribute. |
| 23810 |
|
| 23811 |
if Syntactic or else Semantic then |
| 23812 |
New_List := Copy_List_With_Replacement (Old_List); |
| 23813 |
|
| 23814 |
-- Update the parent pointer when the list is a syntactic |
| 23815 |
-- field. |
| 23816 |
|
| 23817 |
if Syntactic and then New_List /= Old_List then |
| 23818 |
Set_Parent (New_List, New_Par); |
| 23819 |
end if; |
| 23820 |
|
| 23821 |
-- Otherwise the list is returned unchanged |
| 23822 |
|
| 23823 |
else |
| 23824 |
New_List := Old_List; |
| 23825 |
end if; |
| 23826 |
|
| 23827 |
return Union_Id (New_List); |
| 23828 |
end; |
| 23829 |
|
| 23830 |
-- Otherwise the field denotes an attribute that does not need to be |
| 23831 |
-- replicated (Chars, literals, etc). |
| 23832 |
|
| 23833 |
else |
| 23834 |
return Field; |
| 23835 |
end if; |
| 23836 |
end Copy_Field_With_Replacement; |
| 23837 |
|
| 23838 |
-------------------------------- |
| 23839 |
-- Copy_List_With_Replacement -- |
| 23840 |
-------------------------------- |
| 23841 |
|
| 23842 |
function Copy_List_With_Replacement (List : List_Id) return List_Id is |
| 23843 |
Elmt : Node_Id; |
| 23844 |
Result : List_Id; |
| 23845 |
|
| 23846 |
begin |
| 23847 |
-- Copy the contents of the old list. Note that the list itself may |
| 23848 |
-- be empty, in which case the routine returns a new empty list. This |
| 23849 |
-- avoids sharing lists between subtrees. The element of a syntactic |
| 23850 |
-- list is always a node, never an entity or itype, hence the call to |
| 23851 |
-- routine Copy_Node_With_Replacement. |
| 23852 |
|
| 23853 |
if Present (List) then |
| 23854 |
Result := New_List; |
| 23855 |
|
| 23856 |
Elmt := First (List); |
| 23857 |
while Present (Elmt) loop |
| 23858 |
Append (Copy_Node_With_Replacement (Elmt), Result); |
| 23859 |
|
| 23860 |
Next (Elmt); |
| 23861 |
end loop; |
| 23862 |
|
| 23863 |
-- Otherwise the list does not exist |
| 23864 |
|
| 23865 |
else |
| 23866 |
Result := No_List; |
| 23867 |
end if; |
| 23868 |
|
| 23869 |
return Result; |
| 23870 |
end Copy_List_With_Replacement; |
| 23871 |
|
| 23872 |
-------------------------------- |
| 23873 |
-- Copy_Node_With_Replacement -- |
| 23874 |
-------------------------------- |
| 23875 |
|
| 23876 |
function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is |
| 23877 |
Result : Node_Id; |
| 23878 |
|
| 23879 |
function Transform (U : Union_Id) return Union_Id; |
| 23880 |
-- Copies one field, replacing N with Result |
| 23881 |
|
| 23882 |
--------------- |
| 23883 |
-- Transform -- |
| 23884 |
--------------- |
| 23885 |
|
| 23886 |
function Transform (U : Union_Id) return Union_Id is |
| 23887 |
begin |
| 23888 |
return Copy_Field_With_Replacement |
| 23889 |
(Field => U, |
| 23890 |
Old_Par => N, |
| 23891 |
New_Par => Result); |
| 23892 |
end Transform; |
| 23893 |
|
| 23894 |
procedure Walk is new Walk_Sinfo_Fields_Pairwise (Transform); |
| 23895 |
|
| 23896 |
-- Start of processing for Copy_Node_With_Replacement |
| 23897 |
|
| 23898 |
begin |
| 23899 |
-- Assume that the node must be returned unchanged |
| 23900 |
|
| 23901 |
Result := N; |
| 23902 |
|
| 23903 |
if N > Empty_Or_Error then |
| 23904 |
pragma Assert (Nkind (N) not in N_Entity); |
| 23905 |
|
| 23906 |
Result := New_Copy (N); |
| 23907 |
|
| 23908 |
Walk (Result, Result); |
| 23909 |
|
| 23910 |
-- Update the Comes_From_Source and Sloc attributes of the node |
| 23911 |
-- in case the caller has supplied new values. |
| 23912 |
|
| 23913 |
Update_CFS_Sloc (Result); |
| 23914 |
|
| 23915 |
-- Update the Associated_Node_For_Itype attribute of all itypes |
| 23916 |
-- created during Phase 1 whose associated node is N. As a result |
| 23917 |
-- the Associated_Node_For_Itype refers to the replicated node. |
| 23918 |
-- No action needs to be taken when the Associated_Node_For_Itype |
| 23919 |
-- refers to an entity because this was already handled during |
| 23920 |
-- Phase 1, in Visit_Itype. |
| 23921 |
|
| 23922 |
Update_Pending_Itypes |
| 23923 |
(Old_Assoc => N, |
| 23924 |
New_Assoc => Result); |
| 23925 |
|
| 23926 |
-- Update the First/Next_Named_Association chain and the |
| 23927 |
-- Controlling_Argument for a replicated call. |
| 23928 |
|
| 23929 |
if Nkind (N) in N_Entry_Call_Statement |
| 23930 |
| N_Subprogram_Call |
| 23931 |
then |
| 23932 |
Update_Named_Associations |
| 23933 |
(Old_Call => N, |
| 23934 |
New_Call => Result); |
| 23935 |
|
| 23936 |
if Nkind (N) in N_Subprogram_Call then |
| 23937 |
Update_Controlling_Argument |
| 23938 |
(Old_Call => N, |
| 23939 |
New_Call => Result); |
| 23940 |
end if; |
| 23941 |
|
| 23942 |
-- Update the Renamed_Object attribute of a replicated object |
| 23943 |
-- declaration. |
| 23944 |
|
| 23945 |
elsif Nkind (N) = N_Object_Renaming_Declaration then |
| 23946 |
Set_Renamed_Object_Of_Possibly_Void |
| 23947 |
(Defining_Entity (Result), Name (Result)); |
| 23948 |
|
| 23949 |
-- Update the Chars attribute of identifiers |
| 23950 |
|
| 23951 |
elsif Nkind (N) = N_Identifier then |
| 23952 |
|
| 23953 |
-- The Entity field of identifiers that denote aspects is used |
| 23954 |
-- to store arbitrary expressions (and hence we must check that |
| 23955 |
-- they reference an actual entity before copying their Chars |
| 23956 |
-- value). |
| 23957 |
|
| 23958 |
if Present (Entity (Result)) |
| 23959 |
and then Nkind (Entity (Result)) in N_Entity |
| 23960 |
then |
| 23961 |
Set_Chars (Result, Chars (Entity (Result))); |
| 23962 |
end if; |
| 23963 |
end if; |
| 23964 |
|
| 23965 |
Copy_Dimensions (From => N, To => Result); |
| 23966 |
end if; |
| 23967 |
|
| 23968 |
return Result; |
| 23969 |
end Copy_Node_With_Replacement; |
| 23970 |
|
| 23971 |
-------------------------- |
| 23972 |
-- Corresponding_Entity -- |
| 23973 |
-------------------------- |
| 23974 |
|
| 23975 |
function Corresponding_Entity (Id : Entity_Id) return Entity_Id is |
| 23976 |
New_Id : Entity_Id; |
| 23977 |
Result : Entity_Id; |
| 23978 |
|
| 23979 |
begin |
| 23980 |
-- Assume that the entity must be returned unchanged |
| 23981 |
|
| 23982 |
Result := Id; |
| 23983 |
|
| 23984 |
if Id > Empty_Or_Error then |
| 23985 |
pragma Assert (Nkind (Id) in N_Entity); |
| 23986 |
|
| 23987 |
-- Determine whether the entity has a corresponding new entity |
| 23988 |
-- generated during Phase 1 and if it does, use it. |
| 23989 |
|
| 23990 |
if NCT_Tables_In_Use then |
| 23991 |
New_Id := NCT_New_Entities.Get (Id); |
| 23992 |
|
| 23993 |
if Present (New_Id) then |
| 23994 |
Result := New_Id; |
| 23995 |
end if; |
| 23996 |
end if; |
| 23997 |
end if; |
| 23998 |
|
| 23999 |
return Result; |
| 24000 |
end Corresponding_Entity; |
| 24001 |
|
| 24002 |
------------------- |
| 24003 |
-- In_Entity_Map -- |
| 24004 |
------------------- |
| 24005 |
|
| 24006 |
function In_Entity_Map |
| 24007 |
(Id : Entity_Id; |
| 24008 |
Entity_Map : Elist_Id) return Boolean |
| 24009 |
is |
| 24010 |
Elmt : Elmt_Id; |
| 24011 |
Old_Id : Entity_Id; |
| 24012 |
|
| 24013 |
begin |
| 24014 |
-- The entity map contains pairs (Old_Id, New_Id). The advancement |
| 24015 |
-- step always skips the New_Id portion of the pair. |
| 24016 |
|
| 24017 |
if Present (Entity_Map) then |
| 24018 |
Elmt := First_Elmt (Entity_Map); |
| 24019 |
while Present (Elmt) loop |
| 24020 |
Old_Id := Node (Elmt); |
| 24021 |
|
| 24022 |
if Old_Id = Id then |
| 24023 |
return True; |
| 24024 |
end if; |
| 24025 |
|
| 24026 |
Next_Elmt (Elmt); |
| 24027 |
Next_Elmt (Elmt); |
| 24028 |
end loop; |
| 24029 |
end if; |
| 24030 |
|
| 24031 |
return False; |
| 24032 |
end In_Entity_Map; |
| 24033 |
|
| 24034 |
--------------------- |
| 24035 |
-- Update_CFS_Sloc -- |
| 24036 |
--------------------- |
| 24037 |
|
| 24038 |
procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is |
| 24039 |
begin |
| 24040 |
-- A new source location defaults the Comes_From_Source attribute |
| 24041 |
|
| 24042 |
if New_Sloc /= No_Location then |
| 24043 |
Set_Comes_From_Source (N, Get_Comes_From_Source_Default); |
| 24044 |
Set_Sloc (N, New_Sloc); |
| 24045 |
end if; |
| 24046 |
end Update_CFS_Sloc; |
| 24047 |
|
| 24048 |
--------------------------------- |
| 24049 |
-- Update_Controlling_Argument -- |
| 24050 |
--------------------------------- |
| 24051 |
|
| 24052 |
procedure Update_Controlling_Argument |
| 24053 |
(Old_Call : Node_Id; |
| 24054 |
New_Call : Node_Id) |
| 24055 |
is |
| 24056 |
New_Act : Node_Id; |
| 24057 |
Old_Act : Node_Id; |
| 24058 |
|
| 24059 |
Old_Ctrl_Arg : constant Node_Id := Controlling_Argument (Old_Call); |
| 24060 |
-- Controlling argument of the old call node |
| 24061 |
|
| 24062 |
Replaced : Boolean := False; |
| 24063 |
-- Flag to make sure that replacement works as expected |
| 24064 |
|
| 24065 |
begin |
| 24066 |
if No (Old_Ctrl_Arg) then |
| 24067 |
return; |
| 24068 |
end if; |
| 24069 |
|
| 24070 |
-- Recreate the Controlling_Argument of a call by traversing both the |
| 24071 |
-- old and new actual parameters in parallel. |
| 24072 |
|
| 24073 |
New_Act := First (Parameter_Associations (New_Call)); |
| 24074 |
Old_Act := First (Parameter_Associations (Old_Call)); |
| 24075 |
while Present (Old_Act) loop |
| 24076 |
|
| 24077 |
-- Actual parameter appears either in a named parameter |
| 24078 |
-- association or directly. |
| 24079 |
|
| 24080 |
if Nkind (Old_Act) = N_Parameter_Association then |
| 24081 |
if Explicit_Actual_Parameter (Old_Act) = Old_Ctrl_Arg then |
| 24082 |
Set_Controlling_Argument |
| 24083 |
(New_Call, Explicit_Actual_Parameter (New_Act)); |
| 24084 |
Replaced := True; |
| 24085 |
exit; |
| 24086 |
end if; |
| 24087 |
|
| 24088 |
elsif Old_Act = Old_Ctrl_Arg then |
| 24089 |
Set_Controlling_Argument (New_Call, New_Act); |
| 24090 |
Replaced := True; |
| 24091 |
exit; |
| 24092 |
end if; |
| 24093 |
|
| 24094 |
Next (New_Act); |
| 24095 |
Next (Old_Act); |
| 24096 |
end loop; |
| 24097 |
|
| 24098 |
pragma Assert (Replaced); |
| 24099 |
end Update_Controlling_Argument; |
| 24100 |
|
| 24101 |
------------------------------- |
| 24102 |
-- Update_Named_Associations -- |
| 24103 |
------------------------------- |
| 24104 |
|
| 24105 |
procedure Update_Named_Associations |
| 24106 |
(Old_Call : Node_Id; |
| 24107 |
New_Call : Node_Id) |
| 24108 |
is |
| 24109 |
New_Act : Node_Id; |
| 24110 |
New_Next : Node_Id; |
| 24111 |
Old_Act : Node_Id; |
| 24112 |
Old_Next : Node_Id; |
| 24113 |
|
| 24114 |
begin |
| 24115 |
if No (First_Named_Actual (Old_Call)) then |
| 24116 |
return; |
| 24117 |
end if; |
| 24118 |
|
| 24119 |
-- Recreate the First/Next_Named_Actual chain of a call by traversing |
| 24120 |
-- the chains of both the old and new calls in parallel. |
| 24121 |
|
| 24122 |
New_Act := First (Parameter_Associations (New_Call)); |
| 24123 |
Old_Act := First (Parameter_Associations (Old_Call)); |
| 24124 |
while Present (Old_Act) loop |
| 24125 |
if Nkind (Old_Act) = N_Parameter_Association |
| 24126 |
and then Explicit_Actual_Parameter (Old_Act) |
| 24127 |
= First_Named_Actual (Old_Call) |
| 24128 |
then |
| 24129 |
Set_First_Named_Actual (New_Call, |
| 24130 |
Explicit_Actual_Parameter (New_Act)); |
| 24131 |
end if; |
| 24132 |
|
| 24133 |
if Nkind (Old_Act) = N_Parameter_Association |
| 24134 |
and then Present (Next_Named_Actual (Old_Act)) |
| 24135 |
then |
| 24136 |
-- Scan the actual parameter list to find the next suitable |
| 24137 |
-- named actual. Note that the list may be out of order. |
| 24138 |
|
| 24139 |
New_Next := First (Parameter_Associations (New_Call)); |
| 24140 |
Old_Next := First (Parameter_Associations (Old_Call)); |
| 24141 |
while Nkind (Old_Next) /= N_Parameter_Association |
| 24142 |
or else Explicit_Actual_Parameter (Old_Next) /= |
| 24143 |
Next_Named_Actual (Old_Act) |
| 24144 |
loop |
| 24145 |
Next (New_Next); |
| 24146 |
Next (Old_Next); |
| 24147 |
end loop; |
| 24148 |
|
| 24149 |
Set_Next_Named_Actual (New_Act, |
| 24150 |
Explicit_Actual_Parameter (New_Next)); |
| 24151 |
end if; |
| 24152 |
|
| 24153 |
Next (New_Act); |
| 24154 |
Next (Old_Act); |
| 24155 |
end loop; |
| 24156 |
end Update_Named_Associations; |
| 24157 |
|
| 24158 |
------------------------- |
| 24159 |
-- Update_New_Entities -- |
| 24160 |
------------------------- |
| 24161 |
|
| 24162 |
procedure Update_New_Entities (Entity_Map : Elist_Id) is |
| 24163 |
New_Id : Entity_Id := Empty; |
| 24164 |
Old_Id : Entity_Id := Empty; |
| 24165 |
|
| 24166 |
begin |
| 24167 |
if NCT_Tables_In_Use then |
| 24168 |
NCT_New_Entities.Get_First (Old_Id, New_Id); |
| 24169 |
|
| 24170 |
-- Update the semantic fields of all new entities created during |
| 24171 |
-- Phase 1 which were not supplied via an entity map. |
| 24172 |
-- ??? Is there a better way of distinguishing those? |
| 24173 |
|
| 24174 |
while Present (Old_Id) and then Present (New_Id) loop |
| 24175 |
if not In_Entity_Map (Old_Id, Entity_Map) then |
| 24176 |
Update_Semantic_Fields (New_Id); |
| 24177 |
end if; |
| 24178 |
|
| 24179 |
NCT_New_Entities.Get_Next (Old_Id, New_Id); |
| 24180 |
end loop; |
| 24181 |
end if; |
| 24182 |
end Update_New_Entities; |
| 24183 |
|
| 24184 |
--------------------------- |
| 24185 |
-- Update_Pending_Itypes -- |
| 24186 |
--------------------------- |
| 24187 |
|
| 24188 |
procedure Update_Pending_Itypes |
| 24189 |
(Old_Assoc : Node_Id; |
| 24190 |
New_Assoc : Node_Id) |
| 24191 |
is |
| 24192 |
Item : Elmt_Id; |
| 24193 |
Itypes : Elist_Id; |
| 24194 |
|
| 24195 |
begin |
| 24196 |
if NCT_Tables_In_Use then |
| 24197 |
Itypes := NCT_Pending_Itypes.Get (Old_Assoc); |
| 24198 |
|
| 24199 |
-- Update the Associated_Node_For_Itype attribute for all itypes |
| 24200 |
-- which originally refer to Old_Assoc to designate New_Assoc. |
| 24201 |
|
| 24202 |
if Present (Itypes) then |
| 24203 |
Item := First_Elmt (Itypes); |
| 24204 |
while Present (Item) loop |
| 24205 |
Set_Associated_Node_For_Itype (Node (Item), New_Assoc); |
| 24206 |
|
| 24207 |
Next_Elmt (Item); |
| 24208 |
end loop; |
| 24209 |
end if; |
| 24210 |
end if; |
| 24211 |
end Update_Pending_Itypes; |
| 24212 |
|
| 24213 |
---------------------------- |
| 24214 |
-- Update_Semantic_Fields -- |
| 24215 |
---------------------------- |
| 24216 |
|
| 24217 |
procedure Update_Semantic_Fields (Id : Entity_Id) is |
| 24218 |
begin |
| 24219 |
-- Discriminant_Constraint |
| 24220 |
|
| 24221 |
if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then |
| 24222 |
Set_Discriminant_Constraint (Id, Elist_Id ( |
| 24223 |
Copy_Field_With_Replacement |
| 24224 |
(Field => Union_Id (Discriminant_Constraint (Id)), |
| 24225 |
Semantic => True))); |
| 24226 |
end if; |
| 24227 |
|
| 24228 |
-- Etype |
| 24229 |
|
| 24230 |
Set_Etype (Id, Node_Id ( |
| 24231 |
Copy_Field_With_Replacement |
| 24232 |
(Field => Union_Id (Etype (Id)), |
| 24233 |
Semantic => True))); |
| 24234 |
|
| 24235 |
-- First_Index |
| 24236 |
-- Packed_Array_Impl_Type |
| 24237 |
|
| 24238 |
if Is_Array_Type (Id) then |
| 24239 |
if Present (First_Index (Id)) then |
| 24240 |
Set_First_Index (Id, First (List_Id ( |
| 24241 |
Copy_Field_With_Replacement |
| 24242 |
(Field => Union_Id (List_Containing (First_Index (Id))), |
| 24243 |
Semantic => True)))); |
| 24244 |
end if; |
| 24245 |
|
| 24246 |
if Is_Packed (Id) then |
| 24247 |
Set_Packed_Array_Impl_Type (Id, Node_Id ( |
| 24248 |
Copy_Field_With_Replacement |
| 24249 |
(Field => Union_Id (Packed_Array_Impl_Type (Id)), |
| 24250 |
Semantic => True))); |
| 24251 |
end if; |
| 24252 |
end if; |
| 24253 |
|
| 24254 |
-- Prev_Entity |
| 24255 |
|
| 24256 |
Set_Prev_Entity (Id, Node_Id ( |
| 24257 |
Copy_Field_With_Replacement |
| 24258 |
(Field => Union_Id (Prev_Entity (Id)), |
| 24259 |
Semantic => True))); |
| 24260 |
|
| 24261 |
-- Next_Entity |
| 24262 |
|
| 24263 |
Set_Next_Entity (Id, Node_Id ( |
| 24264 |
Copy_Field_With_Replacement |
| 24265 |
(Field => Union_Id (Next_Entity (Id)), |
| 24266 |
Semantic => True))); |
| 24267 |
|
| 24268 |
-- Scalar_Range |
| 24269 |
|
| 24270 |
if Is_Discrete_Type (Id) then |
| 24271 |
Set_Scalar_Range (Id, Node_Id ( |
| 24272 |
Copy_Field_With_Replacement |
| 24273 |
(Field => Union_Id (Scalar_Range (Id)), |
| 24274 |
Semantic => True))); |
| 24275 |
end if; |
| 24276 |
|
| 24277 |
-- Scope |
| 24278 |
|
| 24279 |
-- Update the scope when the caller specified an explicit one |
| 24280 |
|
| 24281 |
if Present (New_Scope) then |
| 24282 |
Set_Scope (Id, New_Scope); |
| 24283 |
else |
| 24284 |
Set_Scope (Id, Node_Id ( |
| 24285 |
Copy_Field_With_Replacement |
| 24286 |
(Field => Union_Id (Scope (Id)), |
| 24287 |
Semantic => True))); |
| 24288 |
end if; |
| 24289 |
end Update_Semantic_Fields; |
| 24290 |
|
| 24291 |
-------------------- |
| 24292 |
-- Visit_Any_Node -- |
| 24293 |
-------------------- |
| 24294 |
|
| 24295 |
procedure Visit_Any_Node (N : Node_Or_Entity_Id) is |
| 24296 |
begin |
| 24297 |
if Nkind (N) in N_Entity then |
| 24298 |
if Is_Itype (N) then |
| 24299 |
Visit_Itype (N); |
| 24300 |
else |
| 24301 |
Visit_Entity (N); |
| 24302 |
end if; |
| 24303 |
else |
| 24304 |
Visit_Node (N); |
| 24305 |
end if; |
| 24306 |
end Visit_Any_Node; |
| 24307 |
|
| 24308 |
----------------- |
| 24309 |
-- Visit_Elist -- |
| 24310 |
----------------- |
| 24311 |
|
| 24312 |
procedure Visit_Elist (List : Elist_Id) is |
| 24313 |
Elmt : Elmt_Id; |
| 24314 |
|
| 24315 |
begin |
| 24316 |
-- The element of an entity list could be an entity, itype, or a |
| 24317 |
-- node, hence the call to Visit_Any_Node. |
| 24318 |
|
| 24319 |
if Present (List) then |
| 24320 |
Elmt := First_Elmt (List); |
| 24321 |
while Present (Elmt) loop |
| 24322 |
Visit_Any_Node (Node (Elmt)); |
| 24323 |
|
| 24324 |
Next_Elmt (Elmt); |
| 24325 |
end loop; |
| 24326 |
end if; |
| 24327 |
end Visit_Elist; |
| 24328 |
|
| 24329 |
------------------ |
| 24330 |
-- Visit_Entity -- |
| 24331 |
------------------ |
| 24332 |
|
| 24333 |
procedure Visit_Entity (Id : Entity_Id) is |
| 24334 |
New_Id : Entity_Id; |
| 24335 |
|
| 24336 |
begin |
| 24337 |
pragma Assert (Nkind (Id) in N_Entity); |
| 24338 |
pragma Assert (not Is_Itype (Id)); |
| 24339 |
|
| 24340 |
-- Nothing to do when the entity is not defined in the Actions list |
| 24341 |
-- of an N_Expression_With_Actions node. |
| 24342 |
|
| 24343 |
if EWA_Level = 0 then |
| 24344 |
return; |
| 24345 |
|
| 24346 |
-- Nothing to do when the entity is defined in a scoping construct |
| 24347 |
-- within an N_Expression_With_Actions node. |
| 24348 |
|
| 24349 |
elsif EWA_Inner_Scope_Level > 0 then |
| 24350 |
return; |
| 24351 |
|
| 24352 |
-- Nothing to do when the entity was already visited |
| 24353 |
|
| 24354 |
elsif NCT_Tables_In_Use |
| 24355 |
and then Present (NCT_New_Entities.Get (Id)) |
| 24356 |
then |
| 24357 |
return; |
| 24358 |
|
| 24359 |
-- Nothing to do when the declaration node of the entity is not in |
| 24360 |
-- the subtree being replicated. |
| 24361 |
|
| 24362 |
elsif not In_Subtree |
| 24363 |
(N => Declaration_Node (Id), |
| 24364 |
Root => Source) |
| 24365 |
then |
| 24366 |
return; |
| 24367 |
end if; |
| 24368 |
|
| 24369 |
-- Create a new entity by directly copying the old entity. This |
| 24370 |
-- action causes all attributes of the old entity to be inherited. |
| 24371 |
|
| 24372 |
New_Id := New_Copy (Id); |
| 24373 |
|
| 24374 |
-- Create a new name for the new entity because the back end needs |
| 24375 |
-- distinct names for debugging purposes, provided that the entity |
| 24376 |
-- has already been analyzed. |
| 24377 |
|
| 24378 |
if Ekind (Id) /= E_Void then |
| 24379 |
Set_Chars (New_Id, New_Internal_Name ('T')); |
| 24380 |
end if; |
| 24381 |
|
| 24382 |
-- Update the Comes_From_Source and Sloc attributes of the entity in |
| 24383 |
-- case the caller has supplied new values. |
| 24384 |
|
| 24385 |
Update_CFS_Sloc (New_Id); |
| 24386 |
|
| 24387 |
-- Establish the following mapping within table NCT_New_Entities: |
| 24388 |
|
| 24389 |
-- Id -> New_Id |
| 24390 |
|
| 24391 |
Add_New_Entity (Id, New_Id); |
| 24392 |
|
| 24393 |
-- Deal with the semantic fields of entities. The fields are visited |
| 24394 |
-- because they may mention entities which reside within the subtree |
| 24395 |
-- being copied. |
| 24396 |
|
| 24397 |
Visit_Semantic_Fields (Id); |
| 24398 |
end Visit_Entity; |
| 24399 |
|
| 24400 |
----------------- |
| 24401 |
-- Visit_Field -- |
| 24402 |
----------------- |
| 24403 |
|
| 24404 |
procedure Visit_Field |
| 24405 |
(Field : Union_Id; |
| 24406 |
Par_Nod : Node_Id := Empty; |
| 24407 |
Semantic : Boolean := False) |
| 24408 |
is |
| 24409 |
begin |
| 24410 |
-- The field is empty |
| 24411 |
|
| 24412 |
if Field = Union_Id (Empty) then |
| 24413 |
return; |
| 24414 |
|
| 24415 |
-- The field is an entity/itype/node |
| 24416 |
|
| 24417 |
elsif Field in Node_Range then |
| 24418 |
declare |
| 24419 |
N : constant Node_Id := Node_Id (Field); |
| 24420 |
|
| 24421 |
begin |
| 24422 |
-- The field is an entity/itype |
| 24423 |
|
| 24424 |
if Nkind (N) in N_Entity then |
| 24425 |
|
| 24426 |
-- Itypes are always visited |
| 24427 |
|
| 24428 |
if Is_Itype (N) then |
| 24429 |
Visit_Itype (N); |
| 24430 |
|
| 24431 |
-- An entity is visited when it is either a syntactic field |
| 24432 |
-- or when the caller treats it as a semantic attribute. |
| 24433 |
|
| 24434 |
elsif Parent (N) = Par_Nod or else Semantic then |
| 24435 |
Visit_Entity (N); |
| 24436 |
end if; |
| 24437 |
|
| 24438 |
-- The field is a node |
| 24439 |
|
| 24440 |
else |
| 24441 |
-- A node is visited when it is either a syntactic field or |
| 24442 |
-- when the caller treats it as a semantic attribute. |
| 24443 |
|
| 24444 |
if Parent (N) = Par_Nod or else Semantic then |
| 24445 |
Visit_Node (N); |
| 24446 |
end if; |
| 24447 |
end if; |
| 24448 |
end; |
| 24449 |
|
| 24450 |
-- The field is an entity list |
| 24451 |
|
| 24452 |
elsif Field in Elist_Range then |
| 24453 |
Visit_Elist (Elist_Id (Field)); |
| 24454 |
|
| 24455 |
-- The field is a syntax list |
| 24456 |
|
| 24457 |
elsif Field in List_Range then |
| 24458 |
declare |
| 24459 |
List : constant List_Id := List_Id (Field); |
| 24460 |
|
| 24461 |
begin |
| 24462 |
-- A syntax list is visited when it is either a syntactic field |
| 24463 |
-- or when the caller treats it as a semantic attribute. |
| 24464 |
|
| 24465 |
if Parent (List) = Par_Nod or else Semantic then |
| 24466 |
Visit_List (List); |
| 24467 |
end if; |
| 24468 |
end; |
| 24469 |
|
| 24470 |
-- Otherwise the field denotes information which does not need to be |
| 24471 |
-- visited (chars, literals, etc.). |
| 24472 |
|
| 24473 |
else |
| 24474 |
null; |
| 24475 |
end if; |
| 24476 |
end Visit_Field; |
| 24477 |
|
| 24478 |
----------------- |
| 24479 |
-- Visit_Itype -- |
| 24480 |
----------------- |
| 24481 |
|
| 24482 |
procedure Visit_Itype (Itype : Entity_Id) is |
| 24483 |
New_Assoc : Node_Id; |
| 24484 |
New_Itype : Entity_Id; |
| 24485 |
Old_Assoc : Node_Id; |
| 24486 |
|
| 24487 |
begin |
| 24488 |
pragma Assert (Nkind (Itype) in N_Entity); |
| 24489 |
pragma Assert (Is_Itype (Itype)); |
| 24490 |
|
| 24491 |
-- Itypes that describe the designated type of access to subprograms |
| 24492 |
-- have the structure of subprogram declarations, with signatures, |
| 24493 |
-- etc. Either we duplicate the signatures completely, or choose to |
| 24494 |
-- share such itypes, which is fine because their elaboration will |
| 24495 |
-- have no side effects. |
| 24496 |
|
| 24497 |
if Ekind (Itype) = E_Subprogram_Type then |
| 24498 |
return; |
| 24499 |
|
| 24500 |
-- Nothing to do if the itype was already visited |
| 24501 |
|
| 24502 |
elsif NCT_Tables_In_Use |
| 24503 |
and then Present (NCT_New_Entities.Get (Itype)) |
| 24504 |
then |
| 24505 |
return; |
| 24506 |
|
| 24507 |
-- Nothing to do if the associated node of the itype is not within |
| 24508 |
-- the subtree being replicated. |
| 24509 |
|
| 24510 |
elsif not In_Subtree |
| 24511 |
(N => Associated_Node_For_Itype (Itype), |
| 24512 |
Root => Source) |
| 24513 |
then |
| 24514 |
return; |
| 24515 |
end if; |
| 24516 |
|
| 24517 |
-- Create a new itype by directly copying the old itype. This action |
| 24518 |
-- causes all attributes of the old itype to be inherited. |
| 24519 |
|
| 24520 |
New_Itype := New_Copy (Itype); |
| 24521 |
|
| 24522 |
-- Create a new name for the new itype because the back end requires |
| 24523 |
-- distinct names for debugging purposes. |
| 24524 |
|
| 24525 |
Set_Chars (New_Itype, New_Internal_Name ('T')); |
| 24526 |
|
| 24527 |
-- Update the Comes_From_Source and Sloc attributes of the itype in |
| 24528 |
-- case the caller has supplied new values. |
| 24529 |
|
| 24530 |
Update_CFS_Sloc (New_Itype); |
| 24531 |
|
| 24532 |
-- Establish the following mapping within table NCT_New_Entities: |
| 24533 |
|
| 24534 |
-- Itype -> New_Itype |
| 24535 |
|
| 24536 |
Add_New_Entity (Itype, New_Itype); |
| 24537 |
|
| 24538 |
-- The new itype must be unfrozen because the resulting subtree may |
| 24539 |
-- be inserted anywhere and cause an earlier or later freezing. |
| 24540 |
|
| 24541 |
if Present (Freeze_Node (New_Itype)) then |
| 24542 |
Set_Freeze_Node (New_Itype, Empty); |
| 24543 |
Set_Is_Frozen (New_Itype, False); |
| 24544 |
end if; |
| 24545 |
|
| 24546 |
-- If a record subtype is simply copied, the entity list will be |
| 24547 |
-- shared, so Cloned_Subtype must be set to indicate this. |
| 24548 |
|
| 24549 |
if Ekind (Itype) in E_Class_Wide_Subtype | E_Record_Subtype then |
| 24550 |
Set_Cloned_Subtype (New_Itype, Itype); |
| 24551 |
end if; |
| 24552 |
|
| 24553 |
-- The associated node may denote an entity, in which case it may |
| 24554 |
-- already have a new corresponding entity created during a prior |
| 24555 |
-- call to Visit_Entity or Visit_Itype for the same subtree. |
| 24556 |
|
| 24557 |
-- Given |
| 24558 |
-- Old_Assoc ---------> New_Assoc |
| 24559 |
|
| 24560 |
-- Created by Visit_Itype |
| 24561 |
-- Itype -------------> New_Itype |
| 24562 |
-- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated |
| 24563 |
|
| 24564 |
-- In the example above, Old_Assoc is an arbitrary entity that was |
| 24565 |
-- already visited for the same subtree and has a corresponding new |
| 24566 |
-- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue |
| 24567 |
-- of copying entities, however it must be updated to New_Assoc. |
| 24568 |
|
| 24569 |
Old_Assoc := Associated_Node_For_Itype (Itype); |
| 24570 |
|
| 24571 |
if Nkind (Old_Assoc) in N_Entity then |
| 24572 |
if NCT_Tables_In_Use then |
| 24573 |
New_Assoc := NCT_New_Entities.Get (Old_Assoc); |
| 24574 |
|
| 24575 |
if Present (New_Assoc) then |
| 24576 |
Set_Associated_Node_For_Itype (New_Itype, New_Assoc); |
| 24577 |
end if; |
| 24578 |
end if; |
| 24579 |
|
| 24580 |
-- Otherwise the associated node denotes a node. Postpone the update |
| 24581 |
-- until Phase 2 when the node is replicated. Establish the following |
| 24582 |
-- mapping within table NCT_Pending_Itypes: |
| 24583 |
|
| 24584 |
-- Old_Assoc -> (New_Type, ...) |
| 24585 |
|
| 24586 |
else |
| 24587 |
Add_Pending_Itype (Old_Assoc, New_Itype); |
| 24588 |
end if; |
| 24589 |
|
| 24590 |
-- Deal with the semantic fields of itypes. The fields are visited |
| 24591 |
-- because they may mention entities that reside within the subtree |
| 24592 |
-- being copied. |
| 24593 |
|
| 24594 |
Visit_Semantic_Fields (Itype); |
| 24595 |
end Visit_Itype; |
| 24596 |
|
| 24597 |
---------------- |
| 24598 |
-- Visit_List -- |
| 24599 |
---------------- |
| 24600 |
|
| 24601 |
procedure Visit_List (List : List_Id) is |
| 24602 |
Elmt : Node_Id; |
| 24603 |
|
| 24604 |
begin |
| 24605 |
-- Note that the element of a syntactic list is always a node, never |
| 24606 |
-- an entity or itype, hence the call to Visit_Node. |
| 24607 |
|
| 24608 |
Elmt := First (List); |
| 24609 |
while Present (Elmt) loop |
| 24610 |
Visit_Node (Elmt); |
| 24611 |
|
| 24612 |
Next (Elmt); |
| 24613 |
end loop; |
| 24614 |
end Visit_List; |
| 24615 |
|
| 24616 |
---------------- |
| 24617 |
-- Visit_Node -- |
| 24618 |
---------------- |
| 24619 |
|
| 24620 |
procedure Visit_Node (N : Node_Id) is |
| 24621 |
begin |
| 24622 |
pragma Assert (Nkind (N) not in N_Entity); |
| 24623 |
|
| 24624 |
-- If the node is a quantified expression and expander is active, |
| 24625 |
-- it contains an implicit declaration that may require a new entity |
| 24626 |
-- when the condition has already been (pre)analyzed. |
| 24627 |
|
| 24628 |
if Nkind (N) = N_Expression_With_Actions |
| 24629 |
or else |
| 24630 |
(Nkind (N) = N_Quantified_Expression and then Expander_Active) |
| 24631 |
then |
| 24632 |
EWA_Level := EWA_Level + 1; |
| 24633 |
|
| 24634 |
elsif EWA_Level > 0 |
| 24635 |
and then Nkind (N) in N_Block_Statement |
| 24636 |
| N_Subprogram_Body |
| 24637 |
| N_Subprogram_Declaration |
| 24638 |
then |
| 24639 |
EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1; |
| 24640 |
end if; |
| 24641 |
|
| 24642 |
-- If the node is a block, we need to process all declarations |
| 24643 |
-- in the block and make new entities for each. |
| 24644 |
|
| 24645 |
if Nkind (N) = N_Block_Statement then |
| 24646 |
declare |
| 24647 |
Decl : Node_Id := First (Declarations (N)); |
| 24648 |
|
| 24649 |
begin |
| 24650 |
while Present (Decl) loop |
| 24651 |
if Nkind (Decl) = N_Object_Declaration then |
| 24652 |
Add_New_Entity (Defining_Identifier (Decl), |
| 24653 |
New_Copy (Defining_Identifier (Decl))); |
| 24654 |
end if; |
| 24655 |
|
| 24656 |
Next (Decl); |
| 24657 |
end loop; |
| 24658 |
end; |
| 24659 |
end if; |
| 24660 |
|
| 24661 |
declare |
| 24662 |
procedure Action (U : Union_Id); |
| 24663 |
procedure Action (U : Union_Id) is |
| 24664 |
begin |
| 24665 |
Visit_Field (Field => U, Par_Nod => N); |
| 24666 |
end Action; |
| 24667 |
|
| 24668 |
procedure Walk is new Walk_Sinfo_Fields (Action); |
| 24669 |
begin |
| 24670 |
Walk (N); |
| 24671 |
end; |
| 24672 |
|
| 24673 |
if EWA_Level > 0 |
| 24674 |
and then Nkind (N) in N_Block_Statement |
| 24675 |
| N_Subprogram_Body |
| 24676 |
| N_Subprogram_Declaration |
| 24677 |
then |
| 24678 |
EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1; |
| 24679 |
|
| 24680 |
elsif Nkind (N) = N_Expression_With_Actions |
| 24681 |
or else |
| 24682 |
(Nkind (N) = N_Quantified_Expression and then Expander_Active) |
| 24683 |
then |
| 24684 |
EWA_Level := EWA_Level - 1; |
| 24685 |
end if; |
| 24686 |
end Visit_Node; |
| 24687 |
|
| 24688 |
--------------------------- |
| 24689 |
-- Visit_Semantic_Fields -- |
| 24690 |
--------------------------- |
| 24691 |
|
| 24692 |
procedure Visit_Semantic_Fields (Id : Entity_Id) is |
| 24693 |
begin |
| 24694 |
pragma Assert (Nkind (Id) in N_Entity); |
| 24695 |
|
| 24696 |
-- Discriminant_Constraint |
| 24697 |
|
| 24698 |
if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then |
| 24699 |
Visit_Field |
| 24700 |
(Field => Union_Id (Discriminant_Constraint (Id)), |
| 24701 |
Semantic => True); |
| 24702 |
end if; |
| 24703 |
|
| 24704 |
-- Etype |
| 24705 |
|
| 24706 |
Visit_Field |
| 24707 |
(Field => Union_Id (Etype (Id)), |
| 24708 |
Semantic => True); |
| 24709 |
|
| 24710 |
-- First_Index |
| 24711 |
-- Packed_Array_Impl_Type |
| 24712 |
|
| 24713 |
if Is_Array_Type (Id) then |
| 24714 |
if Present (First_Index (Id)) then |
| 24715 |
Visit_Field |
| 24716 |
(Field => Union_Id (List_Containing (First_Index (Id))), |
| 24717 |
Semantic => True); |
| 24718 |
end if; |
| 24719 |
|
| 24720 |
if Is_Packed (Id) then |
| 24721 |
Visit_Field |
| 24722 |
(Field => Union_Id (Packed_Array_Impl_Type (Id)), |
| 24723 |
Semantic => True); |
| 24724 |
end if; |
| 24725 |
end if; |
| 24726 |
|
| 24727 |
-- Scalar_Range |
| 24728 |
|
| 24729 |
if Is_Discrete_Type (Id) then |
| 24730 |
Visit_Field |
| 24731 |
(Field => Union_Id (Scalar_Range (Id)), |
| 24732 |
Semantic => True); |
| 24733 |
end if; |
| 24734 |
end Visit_Semantic_Fields; |
| 24735 |
|
| 24736 |
-- Start of processing for New_Copy_Tree |
| 24737 |
|
| 24738 |
begin |
| 24739 |
-- Routine New_Copy_Tree performs a deep copy of a subtree by creating |
| 24740 |
-- shallow copies for each node within, and then updating the child and |
| 24741 |
-- parent pointers accordingly. This process is straightforward, however |
| 24742 |
-- the routine must deal with the following complications: |
| 24743 |
|
| 24744 |
-- * Entities defined within N_Expression_With_Actions nodes must be |
| 24745 |
-- replicated rather than shared to avoid introducing two identical |
| 24746 |
-- symbols within the same scope. Note that no other expression can |
| 24747 |
-- currently define entities. |
| 24748 |
|
| 24749 |
-- do |
| 24750 |
-- Source_Low : ...; |
| 24751 |
-- Source_High : ...; |
| 24752 |
|
| 24753 |
-- <reference to Source_Low> |
| 24754 |
-- <reference to Source_High> |
| 24755 |
-- in ... end; |
| 24756 |
|
| 24757 |
-- New_Copy_Tree handles this case by first creating new entities |
| 24758 |
-- and then updating all existing references to point to these new |
| 24759 |
-- entities. |
| 24760 |
|
| 24761 |
-- do |
| 24762 |
-- New_Low : ...; |
| 24763 |
-- New_High : ...; |
| 24764 |
|
| 24765 |
-- <reference to New_Low> |
| 24766 |
-- <reference to New_High> |
| 24767 |
-- in ... end; |
| 24768 |
|
| 24769 |
-- * Itypes defined within the subtree must be replicated to avoid any |
| 24770 |
-- dependencies on invalid or inaccessible data. |
| 24771 |
|
| 24772 |
-- subtype Source_Itype is ... range Source_Low .. Source_High; |
| 24773 |
|
| 24774 |
-- New_Copy_Tree handles this case by first creating a new itype in |
| 24775 |
-- the same fashion as entities, and then updating various relevant |
| 24776 |
-- constraints. |
| 24777 |
|
| 24778 |
-- subtype New_Itype is ... range New_Low .. New_High; |
| 24779 |
|
| 24780 |
-- * The Associated_Node_For_Itype field of itypes must be updated to |
| 24781 |
-- reference the proper replicated entity or node. |
| 24782 |
|
| 24783 |
-- * Semantic fields of entities such as Etype and Scope must be |
| 24784 |
-- updated to reference the proper replicated entities. |
| 24785 |
|
| 24786 |
-- * Some semantic fields of nodes must be updated to reference |
| 24787 |
-- the proper replicated nodes. |
| 24788 |
|
| 24789 |
-- Finally, quantified expressions contain an implicit declaration for |
| 24790 |
-- the bound variable. Given that quantified expressions appearing |
| 24791 |
-- in contracts are copied to create pragmas and eventually checking |
| 24792 |
-- procedures, a new bound variable must be created for each copy, to |
| 24793 |
-- prevent multiple declarations of the same symbol. |
| 24794 |
|
| 24795 |
-- To meet all these demands, routine New_Copy_Tree is split into two |
| 24796 |
-- phases. |
| 24797 |
|
| 24798 |
-- Phase 1 traverses the tree in order to locate entities and itypes |
| 24799 |
-- defined within the subtree. New entities are generated and saved in |
| 24800 |
-- table NCT_New_Entities. The semantic fields of all new entities and |
| 24801 |
-- itypes are then updated accordingly. |
| 24802 |
|
| 24803 |
-- Phase 2 traverses the tree in order to replicate each node. Various |
| 24804 |
-- semantic fields of nodes and entities are updated accordingly. |
| 24805 |
|
| 24806 |
-- Preparatory phase. Clear the contents of tables NCT_New_Entities and |
| 24807 |
-- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some |
| 24808 |
-- data inside. |
| 24809 |
|
| 24810 |
if NCT_Tables_In_Use then |
| 24811 |
NCT_Tables_In_Use := False; |
| 24812 |
|
| 24813 |
NCT_New_Entities.Reset; |
| 24814 |
NCT_Pending_Itypes.Reset; |
| 24815 |
end if; |
| 24816 |
|
| 24817 |
-- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data |
| 24818 |
-- supplied by a linear entity map. The tables offer faster access to |
| 24819 |
-- the same data. |
| 24820 |
|
| 24821 |
Build_NCT_Tables (Map); |
| 24822 |
|
| 24823 |
-- Execute Phase 1. Traverse the subtree and generate new entities for |
| 24824 |
-- the following cases: |
| 24825 |
|
| 24826 |
-- * An entity defined within an N_Expression_With_Actions node |
| 24827 |
|
| 24828 |
-- * An itype referenced within the subtree where the associated node |
| 24829 |
-- is also in the subtree. |
| 24830 |
|
| 24831 |
-- All new entities are accessible via table NCT_New_Entities, which |
| 24832 |
-- contains mappings of the form: |
| 24833 |
|
| 24834 |
-- Old_Entity -> New_Entity |
| 24835 |
-- Old_Itype -> New_Itype |
| 24836 |
|
| 24837 |
-- In addition, the associated nodes of all new itypes are mapped in |
| 24838 |
-- table NCT_Pending_Itypes: |
| 24839 |
|
| 24840 |
-- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN) |
| 24841 |
|
| 24842 |
Visit_Any_Node (Source); |
| 24843 |
|
| 24844 |
-- Update the semantic attributes of all new entities generated during |
| 24845 |
-- Phase 1 before starting Phase 2. The updates could be performed in |
| 24846 |
-- routine Corresponding_Entity, however this may cause the same entity |
| 24847 |
-- to be updated multiple times, effectively generating useless nodes. |
| 24848 |
-- Keeping the updates separates from Phase 2 ensures that only one set |
| 24849 |
-- of attributes is generated for an entity at any one time. |
| 24850 |
|
| 24851 |
Update_New_Entities (Map); |
| 24852 |
|
| 24853 |
-- Execute Phase 2. Replicate the source subtree one node at a time. |
| 24854 |
-- The following transformations take place: |
| 24855 |
|
| 24856 |
-- * References to entities and itypes are updated to refer to the |
| 24857 |
-- new entities and itypes generated during Phase 1. |
| 24858 |
|
| 24859 |
-- * All Associated_Node_For_Itype attributes of itypes are updated |
| 24860 |
-- to refer to the new replicated Associated_Node_For_Itype. |
| 24861 |
|
| 24862 |
return Copy_Node_With_Replacement (Source); |
| 24863 |
end New_Copy_Tree; |
| 24864 |
|
| 24865 |
------------------------- |
| 24866 |
-- New_External_Entity -- |
| 24867 |
------------------------- |
| 24868 |
|
| 24869 |
function New_External_Entity |
| 24870 |
(Kind : Entity_Kind; |
| 24871 |
Scope_Id : Entity_Id; |
| 24872 |
Sloc_Value : Source_Ptr; |
| 24873 |
Related_Id : Entity_Id; |
| 24874 |
Suffix : Character; |
| 24875 |
Suffix_Index : Int := 0; |
| 24876 |
Prefix : Character := ' ') return Entity_Id |
| 24877 |
is |
| 24878 |
N : constant Entity_Id := |
| 24879 |
Make_Defining_Identifier (Sloc_Value, |
| 24880 |
New_External_Name |
| 24881 |
(Chars (Related_Id), Suffix, Suffix_Index, Prefix)); |
| 24882 |
|
| 24883 |
begin |
| 24884 |
Mutate_Ekind (N, Kind); |
| 24885 |
Set_Is_Internal (N, True); |
| 24886 |
Append_Entity (N, Scope_Id); |
| 24887 |
Set_Public_Status (N); |
| 24888 |
|
| 24889 |
if Kind in Type_Kind then |
| 24890 |
Reinit_Size_Align (N); |
| 24891 |
end if; |
| 24892 |
|
| 24893 |
return N; |
| 24894 |
end New_External_Entity; |
| 24895 |
|
| 24896 |
------------------------- |
| 24897 |
-- New_Internal_Entity -- |
| 24898 |
------------------------- |
| 24899 |
|
| 24900 |
function New_Internal_Entity |
| 24901 |
(Kind : Entity_Kind; |
| 24902 |
Scope_Id : Entity_Id; |
| 24903 |
Sloc_Value : Source_Ptr; |
| 24904 |
Id_Char : Character) return Entity_Id |
| 24905 |
is |
| 24906 |
N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char); |
| 24907 |
|
| 24908 |
begin |
| 24909 |
Mutate_Ekind (N, Kind); |
| 24910 |
Set_Is_Internal (N, True); |
| 24911 |
Append_Entity (N, Scope_Id); |
| 24912 |
|
| 24913 |
if Kind in Type_Kind then |
| 24914 |
Reinit_Size_Align (N); |
| 24915 |
end if; |
| 24916 |
|
| 24917 |
return N; |
| 24918 |
end New_Internal_Entity; |
| 24919 |
|
| 24920 |
----------------- |
| 24921 |
-- Next_Actual -- |
| 24922 |
----------------- |
| 24923 |
|
| 24924 |
function Next_Actual (Actual_Id : Node_Id) return Node_Id is |
| 24925 |
Par : constant Node_Id := Parent (Actual_Id); |
| 24926 |
N : Node_Id; |
| 24927 |
|
| 24928 |
begin |
| 24929 |
-- If we are pointing at a positional parameter, it is a member of a |
| 24930 |
-- node list (the list of parameters), and the next parameter is the |
| 24931 |
-- next node on the list, unless we hit a parameter association, then |
| 24932 |
-- we shift to using the chain whose head is the First_Named_Actual in |
| 24933 |
-- the parent, and then is threaded using the Next_Named_Actual of the |
| 24934 |
-- Parameter_Association. All this fiddling is because the original node |
| 24935 |
-- list is in the textual call order, and what we need is the |
| 24936 |
-- declaration order. |
| 24937 |
|
| 24938 |
if Is_List_Member (Actual_Id) then |
| 24939 |
N := Next (Actual_Id); |
| 24940 |
|
| 24941 |
if Nkind (N) = N_Parameter_Association then |
| 24942 |
|
| 24943 |
-- In case of a build-in-place call, the call will no longer be a |
| 24944 |
-- call; it will have been rewritten. |
| 24945 |
|
| 24946 |
if Nkind (Par) in N_Entry_Call_Statement |
| 24947 |
| N_Function_Call |
| 24948 |
| N_Procedure_Call_Statement |
| 24949 |
then |
| 24950 |
return First_Named_Actual (Par); |
| 24951 |
|
| 24952 |
-- In case of a call rewritten in GNATprove mode while "inlining |
| 24953 |
-- for proof" go to the original call. |
| 24954 |
|
| 24955 |
elsif Nkind (Par) = N_Null_Statement then |
| 24956 |
pragma Assert |
| 24957 |
(GNATprove_Mode |
| 24958 |
and then |
| 24959 |
Nkind (Original_Node (Par)) in N_Subprogram_Call); |
| 24960 |
|
| 24961 |
return First_Named_Actual (Original_Node (Par)); |
| 24962 |
else |
| 24963 |
return Empty; |
| 24964 |
end if; |
| 24965 |
else |
| 24966 |
return N; |
| 24967 |
end if; |
| 24968 |
|
| 24969 |
else |
| 24970 |
return Next_Named_Actual (Parent (Actual_Id)); |
| 24971 |
end if; |
| 24972 |
end Next_Actual; |
| 24973 |
|
| 24974 |
procedure Next_Actual (Actual_Id : in out Node_Id) is |
| 24975 |
begin |
| 24976 |
Actual_Id := Next_Actual (Actual_Id); |
| 24977 |
end Next_Actual; |
| 24978 |
|
| 24979 |
----------------- |
| 24980 |
-- Next_Global -- |
| 24981 |
----------------- |
| 24982 |
|
| 24983 |
function Next_Global (Node : Node_Id) return Node_Id is |
| 24984 |
begin |
| 24985 |
-- The global item may either be in a list, or by itself, in which case |
| 24986 |
-- there is no next global item with the same mode. |
| 24987 |
|
| 24988 |
if Is_List_Member (Node) then |
| 24989 |
return Next (Node); |
| 24990 |
else |
| 24991 |
return Empty; |
| 24992 |
end if; |
| 24993 |
end Next_Global; |
| 24994 |
|
| 24995 |
procedure Next_Global (Node : in out Node_Id) is |
| 24996 |
begin |
| 24997 |
Node := Next_Global (Node); |
| 24998 |
end Next_Global; |
| 24999 |
|
| 25000 |
------------------------ |
| 25001 |
-- No_Caching_Enabled -- |
| 25002 |
------------------------ |
| 25003 |
|
| 25004 |
function No_Caching_Enabled (Id : Entity_Id) return Boolean is |
| 25005 |
Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching); |
| 25006 |
Arg1 : Node_Id; |
| 25007 |
|
| 25008 |
begin |
| 25009 |
if Present (Prag) then |
| 25010 |
Arg1 := First (Pragma_Argument_Associations (Prag)); |
| 25011 |
|
| 25012 |
-- The pragma has an optional Boolean expression, the related |
| 25013 |
-- property is enabled only when the expression evaluates to True. |
| 25014 |
|
| 25015 |
if Present (Arg1) then |
| 25016 |
return Is_True (Expr_Value (Get_Pragma_Arg (Arg1))); |
| 25017 |
|
| 25018 |
-- Otherwise the lack of expression enables the property by |
| 25019 |
-- default. |
| 25020 |
|
| 25021 |
else |
| 25022 |
return True; |
| 25023 |
end if; |
| 25024 |
|
| 25025 |
-- The property was never set in the first place |
| 25026 |
|
| 25027 |
else |
| 25028 |
return False; |
| 25029 |
end if; |
| 25030 |
end No_Caching_Enabled; |
| 25031 |
|
| 25032 |
-------------------------- |
| 25033 |
-- No_Heap_Finalization -- |
| 25034 |
-------------------------- |
| 25035 |
|
| 25036 |
function No_Heap_Finalization (Typ : Entity_Id) return Boolean is |
| 25037 |
begin |
| 25038 |
if Ekind (Typ) in E_Access_Type | E_General_Access_Type |
| 25039 |
and then Is_Library_Level_Entity (Typ) |
| 25040 |
then |
| 25041 |
-- A global No_Heap_Finalization pragma applies to all library-level |
| 25042 |
-- named access-to-object types. |
| 25043 |
|
| 25044 |
if Present (No_Heap_Finalization_Pragma) then |
| 25045 |
return True; |
| 25046 |
|
| 25047 |
-- The library-level named access-to-object type itself is subject to |
| 25048 |
-- pragma No_Heap_Finalization. |
| 25049 |
|
| 25050 |
elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then |
| 25051 |
return True; |
| 25052 |
end if; |
| 25053 |
end if; |
| 25054 |
|
| 25055 |
return False; |
| 25056 |
end No_Heap_Finalization; |
| 25057 |
|
| 25058 |
----------------------- |
| 25059 |
-- Normalize_Actuals -- |
| 25060 |
----------------------- |
| 25061 |
|
| 25062 |
-- Chain actuals according to formals of subprogram. If there are no named |
| 25063 |
-- associations, the chain is simply the list of Parameter Associations, |
| 25064 |
-- since the order is the same as the declaration order. If there are named |
| 25065 |
-- associations, then the First_Named_Actual field in the N_Function_Call |
| 25066 |
-- or N_Procedure_Call_Statement node points to the Parameter_Association |
| 25067 |
-- node for the parameter that comes first in declaration order. The |
| 25068 |
-- remaining named parameters are then chained in declaration order using |
| 25069 |
-- Next_Named_Actual. |
| 25070 |
|
| 25071 |
-- This routine also verifies that the number of actuals is compatible with |
| 25072 |
-- the number and default values of formals, but performs no type checking |
| 25073 |
-- (type checking is done by the caller). |
| 25074 |
|
| 25075 |
-- If the matching succeeds, Success is set to True and the caller proceeds |
| 25076 |
-- with type-checking. If the match is unsuccessful, then Success is set to |
| 25077 |
-- False, and the caller attempts a different interpretation, if there is |
| 25078 |
-- one. |
| 25079 |
|
| 25080 |
-- If the flag Report is on, the call is not overloaded, and a failure to |
| 25081 |
-- match can be reported here, rather than in the caller. |
| 25082 |
|
| 25083 |
procedure Normalize_Actuals |
| 25084 |
(N : Node_Id; |
| 25085 |
S : Entity_Id; |
| 25086 |
Report : Boolean; |
| 25087 |
Success : out Boolean) |
| 25088 |
is |
| 25089 |
Actuals : constant List_Id := Parameter_Associations (N); |
| 25090 |
Actual : Node_Id := Empty; |
| 25091 |
Formal : Entity_Id; |
| 25092 |
Last : Node_Id := Empty; |
| 25093 |
First_Named : Node_Id := Empty; |
| 25094 |
Found : Boolean; |
| 25095 |
|
| 25096 |
Formals_To_Match : Int := 0; |
| 25097 |
Actuals_To_Match : Int := 0; |
| 25098 |
|
| 25099 |
procedure Chain (A : Node_Id); |
| 25100 |
-- Add named actual at the proper place in the list, using the |
| 25101 |
-- Next_Named_Actual link. |
| 25102 |
|
| 25103 |
function Reporting return Boolean; |
| 25104 |
-- Determines if an error is to be reported. To report an error, we |
| 25105 |
-- need Report to be True, and also we do not report errors caused |
| 25106 |
-- by calls to init procs that occur within other init procs. Such |
| 25107 |
-- errors must always be cascaded errors, since if all the types are |
| 25108 |
-- declared correctly, the compiler will certainly build decent calls. |
| 25109 |
|
| 25110 |
----------- |
| 25111 |
-- Chain -- |
| 25112 |
----------- |
| 25113 |
|
| 25114 |
procedure Chain (A : Node_Id) is |
| 25115 |
begin |
| 25116 |
if No (Last) then |
| 25117 |
|
| 25118 |
-- Call node points to first actual in list |
| 25119 |
|
| 25120 |
Set_First_Named_Actual (N, Explicit_Actual_Parameter (A)); |
| 25121 |
|
| 25122 |
else |
| 25123 |
Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A)); |
| 25124 |
end if; |
| 25125 |
|
| 25126 |
Last := A; |
| 25127 |
Set_Next_Named_Actual (Last, Empty); |
| 25128 |
end Chain; |
| 25129 |
|
| 25130 |
--------------- |
| 25131 |
-- Reporting -- |
| 25132 |
--------------- |
| 25133 |
|
| 25134 |
function Reporting return Boolean is |
| 25135 |
begin |
| 25136 |
if not Report then |
| 25137 |
return False; |
| 25138 |
|
| 25139 |
elsif not Within_Init_Proc then |
| 25140 |
return True; |
| 25141 |
|
| 25142 |
elsif Is_Init_Proc (Entity (Name (N))) then |
| 25143 |
return False; |
| 25144 |
|
| 25145 |
else |
| 25146 |
return True; |
| 25147 |
end if; |
| 25148 |
end Reporting; |
| 25149 |
|
| 25150 |
-- Start of processing for Normalize_Actuals |
| 25151 |
|
| 25152 |
begin |
| 25153 |
if Is_Access_Type (S) then |
| 25154 |
|
| 25155 |
-- The name in the call is a function call that returns an access |
| 25156 |
-- to subprogram. The designated type has the list of formals. |
| 25157 |
|
| 25158 |
Formals_To_Match := Number_Formals (Designated_Type (S)); |
| 25159 |
else |
| 25160 |
Formals_To_Match := Number_Formals (S); |
| 25161 |
end if; |
| 25162 |
|
| 25163 |
-- Find if there is a named association, and verify that no positional |
| 25164 |
-- associations appear after named ones. |
| 25165 |
|
| 25166 |
Actual := First (Actuals); |
| 25167 |
|
| 25168 |
while Present (Actual) |
| 25169 |
and then Nkind (Actual) /= N_Parameter_Association |
| 25170 |
loop |
| 25171 |
Actuals_To_Match := Actuals_To_Match + 1; |
| 25172 |
Next (Actual); |
| 25173 |
end loop; |
| 25174 |
|
| 25175 |
if No (Actual) and Actuals_To_Match = Formals_To_Match then |
| 25176 |
|
| 25177 |
-- Most common case: positional notation, no defaults |
| 25178 |
|
| 25179 |
Success := True; |
| 25180 |
return; |
| 25181 |
|
| 25182 |
elsif Actuals_To_Match > Formals_To_Match then |
| 25183 |
|
| 25184 |
-- Too many actuals: will not work |
| 25185 |
|
| 25186 |
if Reporting then |
| 25187 |
if Is_Entity_Name (Name (N)) then |
| 25188 |
Error_Msg_N ("too many arguments in call to&", Name (N)); |
| 25189 |
else |
| 25190 |
Error_Msg_N ("too many arguments in call", N); |
| 25191 |
end if; |
| 25192 |
end if; |
| 25193 |
|
| 25194 |
Success := False; |
| 25195 |
return; |
| 25196 |
end if; |
| 25197 |
|
| 25198 |
First_Named := Actual; |
| 25199 |
|
| 25200 |
while Present (Actual) loop |
| 25201 |
if Nkind (Actual) /= N_Parameter_Association then |
| 25202 |
Error_Msg_N |
| 25203 |
("positional parameters not allowed after named ones", Actual); |
| 25204 |
Success := False; |
| 25205 |
return; |
| 25206 |
|
| 25207 |
else |
| 25208 |
Actuals_To_Match := Actuals_To_Match + 1; |
| 25209 |
end if; |
| 25210 |
|
| 25211 |
Next (Actual); |
| 25212 |
end loop; |
| 25213 |
|
| 25214 |
Actual := First (Actuals); |
| 25215 |
Formal := First_Formal (S); |
| 25216 |
while Present (Formal) loop |
| 25217 |
|
| 25218 |
-- Match the formals in order. If the corresponding actual is |
| 25219 |
-- positional, nothing to do. Else scan the list of named actuals |
| 25220 |
-- to find the one with the right name. |
| 25221 |
|
| 25222 |
if Present (Actual) |
| 25223 |
and then Nkind (Actual) /= N_Parameter_Association |
| 25224 |
then |
| 25225 |
Next (Actual); |
| 25226 |
Actuals_To_Match := Actuals_To_Match - 1; |
| 25227 |
Formals_To_Match := Formals_To_Match - 1; |
| 25228 |
|
| 25229 |
else |
| 25230 |
-- For named parameters, search the list of actuals to find |
| 25231 |
-- one that matches the next formal name. |
| 25232 |
|
| 25233 |
Actual := First_Named; |
| 25234 |
Found := False; |
| 25235 |
while Present (Actual) loop |
| 25236 |
if Chars (Selector_Name (Actual)) = Chars (Formal) then |
| 25237 |
Found := True; |
| 25238 |
Chain (Actual); |
| 25239 |
Actuals_To_Match := Actuals_To_Match - 1; |
| 25240 |
Formals_To_Match := Formals_To_Match - 1; |
| 25241 |
exit; |
| 25242 |
end if; |
| 25243 |
|
| 25244 |
Next (Actual); |
| 25245 |
end loop; |
| 25246 |
|
| 25247 |
if not Found then |
| 25248 |
if Ekind (Formal) /= E_In_Parameter |
| 25249 |
or else No (Default_Value (Formal)) |
| 25250 |
then |
| 25251 |
if Reporting then |
| 25252 |
if (Comes_From_Source (S) |
| 25253 |
or else Sloc (S) = Standard_Location) |
| 25254 |
and then Is_Overloadable (S) |
| 25255 |
then |
| 25256 |
if No (Actuals) |
| 25257 |
and then |
| 25258 |
Nkind (Parent (N)) in N_Procedure_Call_Statement |
| 25259 |
| N_Function_Call |
| 25260 |
| N_Parameter_Association |
| 25261 |
and then Ekind (S) /= E_Function |
| 25262 |
then |
| 25263 |
Set_Etype (N, Etype (S)); |
| 25264 |
|
| 25265 |
else |
| 25266 |
Error_Msg_Name_1 := Chars (S); |
| 25267 |
Error_Msg_Sloc := Sloc (S); |
| 25268 |
Error_Msg_NE |
| 25269 |
("missing argument for parameter & " |
| 25270 |
& "in call to % declared #", N, Formal); |
| 25271 |
end if; |
| 25272 |
|
| 25273 |
elsif Is_Overloadable (S) then |
| 25274 |
Error_Msg_Name_1 := Chars (S); |
| 25275 |
|
| 25276 |
-- Point to type derivation that generated the |
| 25277 |
-- operation. |
| 25278 |
|
| 25279 |
Error_Msg_Sloc := Sloc (Parent (S)); |
| 25280 |
|
| 25281 |
Error_Msg_NE |
| 25282 |
("missing argument for parameter & " |
| 25283 |
& "in call to % (inherited) #", N, Formal); |
| 25284 |
|
| 25285 |
else |
| 25286 |
Error_Msg_NE |
| 25287 |
("missing argument for parameter &", N, Formal); |
| 25288 |
end if; |
| 25289 |
end if; |
| 25290 |
|
| 25291 |
Success := False; |
| 25292 |
return; |
| 25293 |
|
| 25294 |
else |
| 25295 |
Formals_To_Match := Formals_To_Match - 1; |
| 25296 |
end if; |
| 25297 |
end if; |
| 25298 |
end if; |
| 25299 |
|
| 25300 |
Next_Formal (Formal); |
| 25301 |
end loop; |
| 25302 |
|
| 25303 |
if Formals_To_Match = 0 and then Actuals_To_Match = 0 then |
| 25304 |
Success := True; |
| 25305 |
return; |
| 25306 |
|
| 25307 |
else |
| 25308 |
if Reporting then |
| 25309 |
|
| 25310 |
-- Find some superfluous named actual that did not get |
| 25311 |
-- attached to the list of associations. |
| 25312 |
|
| 25313 |
Actual := First (Actuals); |
| 25314 |
while Present (Actual) loop |
| 25315 |
if Nkind (Actual) = N_Parameter_Association |
| 25316 |
and then Actual /= Last |
| 25317 |
and then No (Next_Named_Actual (Actual)) |
| 25318 |
then |
| 25319 |
-- A validity check may introduce a copy of a call that |
| 25320 |
-- includes an extra actual (for example for an unrelated |
| 25321 |
-- accessibility check). Check that the extra actual matches |
| 25322 |
-- some extra formal, which must exist already because |
| 25323 |
-- subprogram must be frozen at this point. |
| 25324 |
|
| 25325 |
if Present (Extra_Formals (S)) |
| 25326 |
and then not Comes_From_Source (Actual) |
| 25327 |
and then Nkind (Actual) = N_Parameter_Association |
| 25328 |
and then Chars (Extra_Formals (S)) = |
| 25329 |
Chars (Selector_Name (Actual)) |
| 25330 |
then |
| 25331 |
null; |
| 25332 |
else |
| 25333 |
Error_Msg_N |
| 25334 |
("unmatched actual & in call", Selector_Name (Actual)); |
| 25335 |
exit; |
| 25336 |
end if; |
| 25337 |
end if; |
| 25338 |
|
| 25339 |
Next (Actual); |
| 25340 |
end loop; |
| 25341 |
end if; |
| 25342 |
|
| 25343 |
Success := False; |
| 25344 |
return; |
| 25345 |
end if; |
| 25346 |
end Normalize_Actuals; |
| 25347 |
|
| 25348 |
-------------------------------- |
| 25349 |
-- Note_Possible_Modification -- |
| 25350 |
-------------------------------- |
| 25351 |
|
| 25352 |
procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is |
| 25353 |
Modification_Comes_From_Source : constant Boolean := |
| 25354 |
Comes_From_Source (Parent (N)); |
| 25355 |
|
| 25356 |
Ent : Entity_Id; |
| 25357 |
Exp : Node_Id; |
| 25358 |
|
| 25359 |
begin |
| 25360 |
-- Loop to find referenced entity, if there is one |
| 25361 |
|
| 25362 |
Exp := N; |
| 25363 |
loop |
| 25364 |
Ent := Empty; |
| 25365 |
|
| 25366 |
if Is_Entity_Name (Exp) then |
| 25367 |
Ent := Entity (Exp); |
| 25368 |
|
| 25369 |
-- If the entity is missing, it is an undeclared identifier, |
| 25370 |
-- and there is nothing to annotate. |
| 25371 |
|
| 25372 |
if No (Ent) then |
| 25373 |
return; |
| 25374 |
end if; |
| 25375 |
|
| 25376 |
elsif Nkind (Exp) = N_Explicit_Dereference then |
| 25377 |
declare |
| 25378 |
P : constant Node_Id := Prefix (Exp); |
| 25379 |
|
| 25380 |
begin |
| 25381 |
-- In formal verification mode, keep track of all reads and |
| 25382 |
-- writes through explicit dereferences. |
| 25383 |
|
| 25384 |
if GNATprove_Mode then |
| 25385 |
SPARK_Specific.Generate_Dereference (N, 'm'); |
| 25386 |
end if; |
| 25387 |
|
| 25388 |
if Nkind (P) = N_Selected_Component |
| 25389 |
and then Present (Entry_Formal (Entity (Selector_Name (P)))) |
| 25390 |
then |
| 25391 |
-- Case of a reference to an entry formal |
| 25392 |
|
| 25393 |
Ent := Entry_Formal (Entity (Selector_Name (P))); |
| 25394 |
|
| 25395 |
elsif Nkind (P) = N_Identifier |
| 25396 |
and then Nkind (Parent (Entity (P))) = N_Object_Declaration |
| 25397 |
and then Present (Expression (Parent (Entity (P)))) |
| 25398 |
and then Nkind (Expression (Parent (Entity (P)))) = |
| 25399 |
N_Reference |
| 25400 |
then |
| 25401 |
-- Case of a reference to a value on which side effects have |
| 25402 |
-- been removed. |
| 25403 |
|
| 25404 |
Exp := Prefix (Expression (Parent (Entity (P)))); |
| 25405 |
goto Continue; |
| 25406 |
|
| 25407 |
else |
| 25408 |
return; |
| 25409 |
end if; |
| 25410 |
end; |
| 25411 |
|
| 25412 |
elsif Nkind (Exp) in N_Type_Conversion | N_Unchecked_Type_Conversion |
| 25413 |
then |
| 25414 |
Exp := Expression (Exp); |
| 25415 |
goto Continue; |
| 25416 |
|
| 25417 |
elsif Nkind (Exp) in |
| 25418 |
N_Slice | N_Indexed_Component | N_Selected_Component |
| 25419 |
then |
| 25420 |
-- Special check, if the prefix is an access type, then return |
| 25421 |
-- since we are modifying the thing pointed to, not the prefix. |
| 25422 |
-- When we are expanding, most usually the prefix is replaced |
| 25423 |
-- by an explicit dereference, and this test is not needed, but |
| 25424 |
-- in some cases (notably -gnatc mode and generics) when we do |
| 25425 |
-- not do full expansion, we need this special test. |
| 25426 |
|
| 25427 |
if Is_Access_Type (Etype (Prefix (Exp))) then |
| 25428 |
return; |
| 25429 |
|
| 25430 |
-- Otherwise go to prefix and keep going |
| 25431 |
|
| 25432 |
else |
| 25433 |
Exp := Prefix (Exp); |
| 25434 |
goto Continue; |
| 25435 |
end if; |
| 25436 |
|
| 25437 |
-- All other cases, not a modification |
| 25438 |
|
| 25439 |
else |
| 25440 |
return; |
| 25441 |
end if; |
| 25442 |
|
| 25443 |
-- Now look for entity being referenced |
| 25444 |
|
| 25445 |
if Present (Ent) then |
| 25446 |
if Is_Object (Ent) then |
| 25447 |
if Comes_From_Source (Exp) |
| 25448 |
or else Modification_Comes_From_Source |
| 25449 |
then |
| 25450 |
-- Give warning if pragma unmodified is given and we are |
| 25451 |
-- sure this is a modification. |
| 25452 |
|
| 25453 |
if Has_Pragma_Unmodified (Ent) and then Sure then |
| 25454 |
|
| 25455 |
-- Note that the entity may be present only as a result |
| 25456 |
-- of pragma Unused. |
| 25457 |
|
| 25458 |
if Has_Pragma_Unused (Ent) then |
| 25459 |
Error_Msg_NE |
| 25460 |
("??aspect Unused specified for &!", N, Ent); |
| 25461 |
else |
| 25462 |
Error_Msg_NE |
| 25463 |
("??aspect Unmodified specified for &!", N, Ent); |
| 25464 |
end if; |
| 25465 |
end if; |
| 25466 |
|
| 25467 |
Set_Never_Set_In_Source (Ent, False); |
| 25468 |
end if; |
| 25469 |
|
| 25470 |
Set_Is_True_Constant (Ent, False); |
| 25471 |
Set_Current_Value (Ent, Empty); |
| 25472 |
Set_Is_Known_Null (Ent, False); |
| 25473 |
|
| 25474 |
if not Can_Never_Be_Null (Ent) then |
| 25475 |
Set_Is_Known_Non_Null (Ent, False); |
| 25476 |
end if; |
| 25477 |
|
| 25478 |
-- Follow renaming chain |
| 25479 |
|
| 25480 |
if Ekind (Ent) in E_Variable | E_Constant |
| 25481 |
and then Present (Renamed_Object (Ent)) |
| 25482 |
then |
| 25483 |
Exp := Renamed_Object (Ent); |
| 25484 |
|
| 25485 |
-- If the entity is the loop variable in an iteration over |
| 25486 |
-- a container, retrieve container expression to indicate |
| 25487 |
-- possible modification. |
| 25488 |
|
| 25489 |
if Present (Related_Expression (Ent)) |
| 25490 |
and then Nkind (Parent (Related_Expression (Ent))) = |
| 25491 |
N_Iterator_Specification |
| 25492 |
then |
| 25493 |
Exp := Original_Node (Related_Expression (Ent)); |
| 25494 |
end if; |
| 25495 |
|
| 25496 |
goto Continue; |
| 25497 |
|
| 25498 |
-- The expression may be the renaming of a subcomponent of an |
| 25499 |
-- array or container. The assignment to the subcomponent is |
| 25500 |
-- a modification of the container. |
| 25501 |
|
| 25502 |
elsif Comes_From_Source (Original_Node (Exp)) |
| 25503 |
and then Nkind (Original_Node (Exp)) in |
| 25504 |
N_Selected_Component | N_Indexed_Component |
| 25505 |
then |
| 25506 |
Exp := Prefix (Original_Node (Exp)); |
| 25507 |
goto Continue; |
| 25508 |
end if; |
| 25509 |
|
| 25510 |
-- Generate a reference only if the assignment comes from |
| 25511 |
-- source. This excludes, for example, calls to a dispatching |
| 25512 |
-- assignment operation when the left-hand side is tagged. In |
| 25513 |
-- GNATprove mode, we need those references also on generated |
| 25514 |
-- code, as these are used to compute the local effects of |
| 25515 |
-- subprograms. |
| 25516 |
|
| 25517 |
if Modification_Comes_From_Source or GNATprove_Mode then |
| 25518 |
Generate_Reference (Ent, Exp, 'm'); |
| 25519 |
|
| 25520 |
-- If the target of the assignment is the bound variable |
| 25521 |
-- in an iterator, indicate that the corresponding array |
| 25522 |
-- or container is also modified. |
| 25523 |
|
| 25524 |
if Ada_Version >= Ada_2012 |
| 25525 |
and then Nkind (Parent (Ent)) = N_Iterator_Specification |
| 25526 |
then |
| 25527 |
declare |
| 25528 |
Domain : constant Node_Id := Name (Parent (Ent)); |
| 25529 |
|
| 25530 |
begin |
| 25531 |
-- ??? In the full version of the construct, the |
| 25532 |
-- domain of iteration can be given by an expression. |
| 25533 |
|
| 25534 |
if Is_Entity_Name (Domain) then |
| 25535 |
Generate_Reference (Entity (Domain), Exp, 'm'); |
| 25536 |
Set_Is_True_Constant (Entity (Domain), False); |
| 25537 |
Set_Never_Set_In_Source (Entity (Domain), False); |
| 25538 |
end if; |
| 25539 |
end; |
| 25540 |
end if; |
| 25541 |
end if; |
| 25542 |
end if; |
| 25543 |
|
| 25544 |
Kill_Checks (Ent); |
| 25545 |
|
| 25546 |
-- If we are sure this is a modification from source, and we know |
| 25547 |
-- this modifies a constant, then give an appropriate warning. |
| 25548 |
|
| 25549 |
if Sure |
| 25550 |
and then Modification_Comes_From_Source |
| 25551 |
and then Overlays_Constant (Ent) |
| 25552 |
and then Address_Clause_Overlay_Warnings |
| 25553 |
then |
| 25554 |
declare |
| 25555 |
Addr : constant Node_Id := Address_Clause (Ent); |
| 25556 |
O_Ent : Entity_Id; |
| 25557 |
Off : Boolean; |
| 25558 |
|
| 25559 |
begin |
| 25560 |
Find_Overlaid_Entity (Addr, O_Ent, Off); |
| 25561 |
|
| 25562 |
Error_Msg_Sloc := Sloc (Addr); |
| 25563 |
Error_Msg_NE |
| 25564 |
("?o?constant& may be modified via address clause#", |
| 25565 |
N, O_Ent); |
| 25566 |
end; |
| 25567 |
end if; |
| 25568 |
|
| 25569 |
return; |
| 25570 |
end if; |
| 25571 |
|
| 25572 |
<<Continue>> |
| 25573 |
null; |
| 25574 |
end loop; |
| 25575 |
end Note_Possible_Modification; |
| 25576 |
|
| 25577 |
----------------- |
| 25578 |
-- Null_Status -- |
| 25579 |
----------------- |
| 25580 |
|
| 25581 |
function Null_Status (N : Node_Id) return Null_Status_Kind is |
| 25582 |
function Is_Null_Excluding_Def (Def : Node_Id) return Boolean; |
| 25583 |
-- Determine whether definition Def carries a null exclusion |
| 25584 |
|
| 25585 |
function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind; |
| 25586 |
-- Determine the null status of arbitrary entity Id |
| 25587 |
|
| 25588 |
function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind; |
| 25589 |
-- Determine the null status of type Typ |
| 25590 |
|
| 25591 |
--------------------------- |
| 25592 |
-- Is_Null_Excluding_Def -- |
| 25593 |
--------------------------- |
| 25594 |
|
| 25595 |
function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is |
| 25596 |
begin |
| 25597 |
return Nkind (Def) in N_Access_Definition |
| 25598 |
| N_Access_Function_Definition |
| 25599 |
| N_Access_Procedure_Definition |
| 25600 |
| N_Access_To_Object_Definition |
| 25601 |
| N_Component_Definition |
| 25602 |
| N_Derived_Type_Definition |
| 25603 |
and then Null_Exclusion_Present (Def); |
| 25604 |
end Is_Null_Excluding_Def; |
| 25605 |
|
| 25606 |
--------------------------- |
| 25607 |
-- Null_Status_Of_Entity -- |
| 25608 |
--------------------------- |
| 25609 |
|
| 25610 |
function Null_Status_Of_Entity |
| 25611 |
(Id : Entity_Id) return Null_Status_Kind |
| 25612 |
is |
| 25613 |
Decl : constant Node_Id := Declaration_Node (Id); |
| 25614 |
Def : Node_Id; |
| 25615 |
|
| 25616 |
begin |
| 25617 |
-- The value of an imported or exported entity may be set externally |
| 25618 |
-- regardless of a null exclusion. As a result, the value cannot be |
| 25619 |
-- determined statically. |
| 25620 |
|
| 25621 |
if Is_Imported (Id) or else Is_Exported (Id) then |
| 25622 |
return Unknown; |
| 25623 |
|
| 25624 |
elsif Nkind (Decl) in N_Component_Declaration |
| 25625 |
| N_Discriminant_Specification |
| 25626 |
| N_Formal_Object_Declaration |
| 25627 |
| N_Object_Declaration |
| 25628 |
| N_Object_Renaming_Declaration |
| 25629 |
| N_Parameter_Specification |
| 25630 |
then |
| 25631 |
-- A component declaration yields a non-null value when either |
| 25632 |
-- its component definition or access definition carries a null |
| 25633 |
-- exclusion. |
| 25634 |
|
| 25635 |
if Nkind (Decl) = N_Component_Declaration then |
| 25636 |
Def := Component_Definition (Decl); |
| 25637 |
|
| 25638 |
if Is_Null_Excluding_Def (Def) then |
| 25639 |
return Is_Non_Null; |
| 25640 |
end if; |
| 25641 |
|
| 25642 |
Def := Access_Definition (Def); |
| 25643 |
|
| 25644 |
if Present (Def) and then Is_Null_Excluding_Def (Def) then |
| 25645 |
return Is_Non_Null; |
| 25646 |
end if; |
| 25647 |
|
| 25648 |
-- A formal object declaration yields a non-null value if its |
| 25649 |
-- access definition carries a null exclusion. If the object is |
| 25650 |
-- default initialized, then the value depends on the expression. |
| 25651 |
|
| 25652 |
elsif Nkind (Decl) = N_Formal_Object_Declaration then |
| 25653 |
Def := Access_Definition (Decl); |
| 25654 |
|
| 25655 |
if Present (Def) and then Is_Null_Excluding_Def (Def) then |
| 25656 |
return Is_Non_Null; |
| 25657 |
end if; |
| 25658 |
|
| 25659 |
-- A constant may yield a null or non-null value depending on its |
| 25660 |
-- initialization expression. |
| 25661 |
|
| 25662 |
elsif Ekind (Id) = E_Constant then |
| 25663 |
return Null_Status (Constant_Value (Id)); |
| 25664 |
|
| 25665 |
-- The construct yields a non-null value when it has a null |
| 25666 |
-- exclusion. |
| 25667 |
|
| 25668 |
elsif Null_Exclusion_Present (Decl) then |
| 25669 |
return Is_Non_Null; |
| 25670 |
|
| 25671 |
-- An object renaming declaration yields a non-null value if its |
| 25672 |
-- access definition carries a null exclusion. Otherwise the value |
| 25673 |
-- depends on the renamed name. |
| 25674 |
|
| 25675 |
elsif Nkind (Decl) = N_Object_Renaming_Declaration then |
| 25676 |
Def := Access_Definition (Decl); |
| 25677 |
|
| 25678 |
if Present (Def) and then Is_Null_Excluding_Def (Def) then |
| 25679 |
return Is_Non_Null; |
| 25680 |
|
| 25681 |
else |
| 25682 |
return Null_Status (Name (Decl)); |
| 25683 |
end if; |
| 25684 |
end if; |
| 25685 |
end if; |
| 25686 |
|
| 25687 |
-- At this point the declaration of the entity does not carry a null |
| 25688 |
-- exclusion and lacks an initialization expression. Check the status |
| 25689 |
-- of its type. |
| 25690 |
|
| 25691 |
return Null_Status_Of_Type (Etype (Id)); |
| 25692 |
end Null_Status_Of_Entity; |
| 25693 |
|
| 25694 |
------------------------- |
| 25695 |
-- Null_Status_Of_Type -- |
| 25696 |
------------------------- |
| 25697 |
|
| 25698 |
function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is |
| 25699 |
Curr : Entity_Id; |
| 25700 |
Decl : Node_Id; |
| 25701 |
|
| 25702 |
begin |
| 25703 |
-- Traverse the type chain looking for types with null exclusion |
| 25704 |
|
| 25705 |
Curr := Typ; |
| 25706 |
while Present (Curr) and then Etype (Curr) /= Curr loop |
| 25707 |
Decl := Parent (Curr); |
| 25708 |
|
| 25709 |
-- Guard against itypes which do not always have declarations. A |
| 25710 |
-- type yields a non-null value if it carries a null exclusion. |
| 25711 |
|
| 25712 |
if Present (Decl) then |
| 25713 |
if Nkind (Decl) = N_Full_Type_Declaration |
| 25714 |
and then Is_Null_Excluding_Def (Type_Definition (Decl)) |
| 25715 |
then |
| 25716 |
return Is_Non_Null; |
| 25717 |
|
| 25718 |
elsif Nkind (Decl) = N_Subtype_Declaration |
| 25719 |
and then Null_Exclusion_Present (Decl) |
| 25720 |
then |
| 25721 |
return Is_Non_Null; |
| 25722 |
end if; |
| 25723 |
end if; |
| 25724 |
|
| 25725 |
Curr := Etype (Curr); |
| 25726 |
end loop; |
| 25727 |
|
| 25728 |
-- The type chain does not contain any null excluding types |
| 25729 |
|
| 25730 |
return Unknown; |
| 25731 |
end Null_Status_Of_Type; |
| 25732 |
|
| 25733 |
-- Start of processing for Null_Status |
| 25734 |
|
| 25735 |
begin |
| 25736 |
-- Prevent cascaded errors or infinite loops when trying to determine |
| 25737 |
-- the null status of an erroneous construct. |
| 25738 |
|
| 25739 |
if Error_Posted (N) then |
| 25740 |
return Unknown; |
| 25741 |
|
| 25742 |
-- An allocator always creates a non-null value |
| 25743 |
|
| 25744 |
elsif Nkind (N) = N_Allocator then |
| 25745 |
return Is_Non_Null; |
| 25746 |
|
| 25747 |
-- Taking the 'Access of something yields a non-null value |
| 25748 |
|
| 25749 |
elsif Nkind (N) = N_Attribute_Reference |
| 25750 |
and then Attribute_Name (N) in Name_Access |
| 25751 |
| Name_Unchecked_Access |
| 25752 |
| Name_Unrestricted_Access |
| 25753 |
then |
| 25754 |
return Is_Non_Null; |
| 25755 |
|
| 25756 |
-- "null" yields null |
| 25757 |
|
| 25758 |
elsif Nkind (N) = N_Null then |
| 25759 |
return Is_Null; |
| 25760 |
|
| 25761 |
-- Check the status of the operand of a type conversion |
| 25762 |
|
| 25763 |
elsif Nkind (N) in N_Type_Conversion | N_Unchecked_Type_Conversion then |
| 25764 |
return Null_Status (Expression (N)); |
| 25765 |
|
| 25766 |
-- The input denotes a reference to an entity. Determine whether the |
| 25767 |
-- entity or its type yields a null or non-null value. |
| 25768 |
|
| 25769 |
elsif Is_Entity_Name (N) and then Present (Entity (N)) then |
| 25770 |
return Null_Status_Of_Entity (Entity (N)); |
| 25771 |
end if; |
| 25772 |
|
| 25773 |
-- Otherwise it is not possible to determine the null status of the |
| 25774 |
-- subexpression at compile time without resorting to simple flow |
| 25775 |
-- analysis. |
| 25776 |
|
| 25777 |
return Unknown; |
| 25778 |
end Null_Status; |
| 25779 |
|
| 25780 |
-------------------------------------- |
| 25781 |
-- Null_To_Null_Address_Convert_OK -- |
| 25782 |
-------------------------------------- |
| 25783 |
|
| 25784 |
function Null_To_Null_Address_Convert_OK |
| 25785 |
(N : Node_Id; |
| 25786 |
Typ : Entity_Id := Empty) return Boolean |
| 25787 |
is |
| 25788 |
begin |
| 25789 |
if not Relaxed_RM_Semantics then |
| 25790 |
return False; |
| 25791 |
end if; |
| 25792 |
|
| 25793 |
if Nkind (N) = N_Null then |
| 25794 |
return Present (Typ) and then Is_Descendant_Of_Address (Typ); |
| 25795 |
|
| 25796 |
elsif Nkind (N) in N_Op_Compare then |
| 25797 |
declare |
| 25798 |
L : constant Node_Id := Left_Opnd (N); |
| 25799 |
R : constant Node_Id := Right_Opnd (N); |
| 25800 |
|
| 25801 |
begin |
| 25802 |
-- We check the Etype of the complementary operand since the |
| 25803 |
-- N_Null node is not decorated at this stage. |
| 25804 |
|
| 25805 |
return |
| 25806 |
((Nkind (L) = N_Null |
| 25807 |
and then Is_Descendant_Of_Address (Etype (R))) |
| 25808 |
or else |
| 25809 |
(Nkind (R) = N_Null |
| 25810 |
and then Is_Descendant_Of_Address (Etype (L)))); |
| 25811 |
end; |
| 25812 |
end if; |
| 25813 |
|
| 25814 |
return False; |
| 25815 |
end Null_To_Null_Address_Convert_OK; |
| 25816 |
|
| 25817 |
--------------------------------- |
| 25818 |
-- Number_Of_Elements_In_Array -- |
| 25819 |
--------------------------------- |
| 25820 |
|
| 25821 |
function Number_Of_Elements_In_Array (T : Entity_Id) return Nat is |
| 25822 |
Indx : Node_Id; |
| 25823 |
Typ : Entity_Id; |
| 25824 |
Low : Node_Id; |
| 25825 |
High : Node_Id; |
| 25826 |
Num : Nat := 1; |
| 25827 |
|
| 25828 |
begin |
| 25829 |
pragma Assert (Is_Array_Type (T)); |
| 25830 |
|
| 25831 |
Indx := First_Index (T); |
| 25832 |
while Present (Indx) loop |
| 25833 |
Typ := Underlying_Type (Etype (Indx)); |
| 25834 |
|
| 25835 |
-- Never look at junk bounds of a generic type |
| 25836 |
|
| 25837 |
if Is_Generic_Type (Typ) then |
| 25838 |
return 0; |
| 25839 |
end if; |
| 25840 |
|
| 25841 |
-- Check the array bounds are known at compile time and return zero |
| 25842 |
-- if they are not. |
| 25843 |
|
| 25844 |
Low := Type_Low_Bound (Typ); |
| 25845 |
High := Type_High_Bound (Typ); |
| 25846 |
|
| 25847 |
if not Compile_Time_Known_Value (Low) then |
| 25848 |
return 0; |
| 25849 |
elsif not Compile_Time_Known_Value (High) then |
| 25850 |
return 0; |
| 25851 |
else |
| 25852 |
Num := |
| 25853 |
Num * Int'Max |
| 25854 |
(0, UI_To_Int (Expr_Value (High) - Expr_Value (Low) + Uint_1)); |
| 25855 |
end if; |
| 25856 |
|
| 25857 |
Next_Index (Indx); |
| 25858 |
end loop; |
| 25859 |
|
| 25860 |
return Num; |
| 25861 |
end Number_Of_Elements_In_Array; |
| 25862 |
|
| 25863 |
--------------------------------- |
| 25864 |
-- Original_Aspect_Pragma_Name -- |
| 25865 |
--------------------------------- |
| 25866 |
|
| 25867 |
function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is |
| 25868 |
Item : Node_Id; |
| 25869 |
Item_Nam : Name_Id; |
| 25870 |
|
| 25871 |
begin |
| 25872 |
pragma Assert (Nkind (N) in N_Aspect_Specification | N_Pragma); |
| 25873 |
|
| 25874 |
Item := N; |
| 25875 |
|
| 25876 |
-- The pragma was generated to emulate an aspect, use the original |
| 25877 |
-- aspect specification. |
| 25878 |
|
| 25879 |
if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then |
| 25880 |
Item := Corresponding_Aspect (Item); |
| 25881 |
end if; |
| 25882 |
|
| 25883 |
-- Retrieve the name of the aspect/pragma. As assertion pragmas from |
| 25884 |
-- a generic instantiation might have been rewritten into pragma Check, |
| 25885 |
-- we look at the original node for Item. Note also that Pre, Pre_Class, |
| 25886 |
-- Post and Post_Class rewrite their pragma identifier to preserve the |
| 25887 |
-- original name, so we look at the original node for the identifier. |
| 25888 |
-- ??? this is kludgey |
| 25889 |
|
| 25890 |
if Nkind (Item) = N_Pragma then |
| 25891 |
Item_Nam := |
| 25892 |
Chars (Original_Node (Pragma_Identifier (Original_Node (Item)))); |
| 25893 |
|
| 25894 |
if Item_Nam = Name_Check then |
| 25895 |
-- Pragma "Check" preserves the original pragma name as its first |
| 25896 |
-- argument. |
| 25897 |
Item_Nam := |
| 25898 |
Chars (Expression (First (Pragma_Argument_Associations |
| 25899 |
(Original_Node (Item))))); |
| 25900 |
end if; |
| 25901 |
|
| 25902 |
else |
| 25903 |
pragma Assert (Nkind (Item) = N_Aspect_Specification); |
| 25904 |
Item_Nam := Chars (Identifier (Item)); |
| 25905 |
end if; |
| 25906 |
|
| 25907 |
-- Deal with 'Class by converting the name to its _XXX form |
| 25908 |
|
| 25909 |
if Class_Present (Item) then |
| 25910 |
if Item_Nam = Name_Invariant then |
| 25911 |
Item_Nam := Name_uInvariant; |
| 25912 |
|
| 25913 |
elsif Item_Nam = Name_Post then |
| 25914 |
Item_Nam := Name_uPost; |
| 25915 |
|
| 25916 |
elsif Item_Nam = Name_Pre then |
| 25917 |
Item_Nam := Name_uPre; |
| 25918 |
|
| 25919 |
elsif Item_Nam in Name_Type_Invariant | Name_Type_Invariant_Class |
| 25920 |
then |
| 25921 |
Item_Nam := Name_uType_Invariant; |
| 25922 |
|
| 25923 |
-- Nothing to do for other cases (e.g. a Check that derived from |
| 25924 |
-- Pre_Class and has the flag set). Also we do nothing if the name |
| 25925 |
-- is already in special _xxx form. |
| 25926 |
|
| 25927 |
end if; |
| 25928 |
end if; |
| 25929 |
|
| 25930 |
return Item_Nam; |
| 25931 |
end Original_Aspect_Pragma_Name; |
| 25932 |
|
| 25933 |
-------------------------------------- |
| 25934 |
-- Original_Corresponding_Operation -- |
| 25935 |
-------------------------------------- |
| 25936 |
|
| 25937 |
function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id |
| 25938 |
is |
| 25939 |
Typ : constant Entity_Id := Find_Dispatching_Type (S); |
| 25940 |
|
| 25941 |
begin |
| 25942 |
-- If S is an inherited primitive S2 the original corresponding |
| 25943 |
-- operation of S is the original corresponding operation of S2 |
| 25944 |
|
| 25945 |
if Present (Alias (S)) |
| 25946 |
and then Find_Dispatching_Type (Alias (S)) /= Typ |
| 25947 |
then |
| 25948 |
return Original_Corresponding_Operation (Alias (S)); |
| 25949 |
|
| 25950 |
-- If S overrides an inherited subprogram S2 the original corresponding |
| 25951 |
-- operation of S is the original corresponding operation of S2 |
| 25952 |
|
| 25953 |
elsif Present (Overridden_Operation (S)) then |
| 25954 |
return Original_Corresponding_Operation (Overridden_Operation (S)); |
| 25955 |
|
| 25956 |
-- otherwise it is S itself |
| 25957 |
|
| 25958 |
else |
| 25959 |
return S; |
| 25960 |
end if; |
| 25961 |
end Original_Corresponding_Operation; |
| 25962 |
|
| 25963 |
----------------------------------- |
| 25964 |
-- Original_View_In_Visible_Part -- |
| 25965 |
----------------------------------- |
| 25966 |
|
| 25967 |
function Original_View_In_Visible_Part |
| 25968 |
(Typ : Entity_Id) return Boolean |
| 25969 |
is |
| 25970 |
Scop : constant Entity_Id := Scope (Typ); |
| 25971 |
|
| 25972 |
begin |
| 25973 |
-- The scope must be a package |
| 25974 |
|
| 25975 |
if not Is_Package_Or_Generic_Package (Scop) then |
| 25976 |
return False; |
| 25977 |
end if; |
| 25978 |
|
| 25979 |
-- A type with a private declaration has a private view declared in |
| 25980 |
-- the visible part. |
| 25981 |
|
| 25982 |
if Has_Private_Declaration (Typ) then |
| 25983 |
return True; |
| 25984 |
end if; |
| 25985 |
|
| 25986 |
return List_Containing (Parent (Typ)) = |
| 25987 |
Visible_Declarations (Package_Specification (Scop)); |
| 25988 |
end Original_View_In_Visible_Part; |
| 25989 |
|
| 25990 |
------------------- |
| 25991 |
-- Output_Entity -- |
| 25992 |
------------------- |
| 25993 |
|
| 25994 |
procedure Output_Entity (Id : Entity_Id) is |
| 25995 |
Scop : Entity_Id; |
| 25996 |
|
| 25997 |
begin |
| 25998 |
Scop := Scope (Id); |
| 25999 |
|
| 26000 |
-- The entity may lack a scope when it is in the process of being |
| 26001 |
-- analyzed. Use the current scope as an approximation. |
| 26002 |
|
| 26003 |
if No (Scop) then |
| 26004 |
Scop := Current_Scope; |
| 26005 |
end if; |
| 26006 |
|
| 26007 |
Output_Name (Chars (Id), Scop); |
| 26008 |
end Output_Entity; |
| 26009 |
|
| 26010 |
----------------- |
| 26011 |
-- Output_Name -- |
| 26012 |
----------------- |
| 26013 |
|
| 26014 |
procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is |
| 26015 |
begin |
| 26016 |
Write_Str |
| 26017 |
(Get_Name_String |
| 26018 |
(Get_Qualified_Name |
| 26019 |
(Nam => Nam, |
| 26020 |
Suffix => No_Name, |
| 26021 |
Scop => Scop))); |
| 26022 |
Write_Eol; |
| 26023 |
end Output_Name; |
| 26024 |
|
| 26025 |
------------------ |
| 26026 |
-- Param_Entity -- |
| 26027 |
------------------ |
| 26028 |
|
| 26029 |
-- This would be trivial, simply a test for an identifier that was a |
| 26030 |
-- reference to a formal, if it were not for the fact that a previous call |
| 26031 |
-- to Expand_Entry_Parameter will have modified the reference to the |
| 26032 |
-- identifier. A formal of a protected entity is rewritten as |
| 26033 |
|
| 26034 |
-- typ!(recobj).rec.all'Constrained |
| 26035 |
|
| 26036 |
-- where rec is a selector whose Entry_Formal link points to the formal |
| 26037 |
|
| 26038 |
-- If the type of the entry parameter has a representation clause, then an |
| 26039 |
-- extra temp is involved (see below). |
| 26040 |
|
| 26041 |
-- For a formal of a task entity, the formal is rewritten as a local |
| 26042 |
-- renaming. |
| 26043 |
|
| 26044 |
-- In addition, a formal that is marked volatile because it is aliased |
| 26045 |
-- through an address clause is rewritten as dereference as well. |
| 26046 |
|
| 26047 |
function Param_Entity (N : Node_Id) return Entity_Id is |
| 26048 |
Renamed_Obj : Node_Id; |
| 26049 |
|
| 26050 |
begin |
| 26051 |
-- Simple reference case |
| 26052 |
|
| 26053 |
if Nkind (N) in N_Identifier | N_Expanded_Name then |
| 26054 |
if Is_Formal (Entity (N)) then |
| 26055 |
return Entity (N); |
| 26056 |
|
| 26057 |
-- Handle renamings of formal parameters and formals of tasks that |
| 26058 |
-- are rewritten as renamings. |
| 26059 |
|
| 26060 |
elsif Nkind (Parent (Entity (N))) = N_Object_Renaming_Declaration then |
| 26061 |
Renamed_Obj := Get_Referenced_Object (Renamed_Object (Entity (N))); |
| 26062 |
|
| 26063 |
if Is_Entity_Name (Renamed_Obj) |
| 26064 |
and then Is_Formal (Entity (Renamed_Obj)) |
| 26065 |
then |
| 26066 |
return Entity (Renamed_Obj); |
| 26067 |
|
| 26068 |
elsif |
| 26069 |
Nkind (Parent (Parent (Entity (N)))) = N_Accept_Statement |
| 26070 |
then |
| 26071 |
return Entity (N); |
| 26072 |
end if; |
| 26073 |
end if; |
| 26074 |
|
| 26075 |
else |
| 26076 |
if Nkind (N) = N_Explicit_Dereference then |
| 26077 |
declare |
| 26078 |
P : Node_Id := Prefix (N); |
| 26079 |
S : Node_Id; |
| 26080 |
E : Entity_Id; |
| 26081 |
Decl : Node_Id; |
| 26082 |
|
| 26083 |
begin |
| 26084 |
-- If the type of an entry parameter has a representation |
| 26085 |
-- clause, then the prefix is not a selected component, but |
| 26086 |
-- instead a reference to a temp pointing at the selected |
| 26087 |
-- component. In this case, set P to be the initial value of |
| 26088 |
-- that temp. |
| 26089 |
|
| 26090 |
if Nkind (P) = N_Identifier then |
| 26091 |
E := Entity (P); |
| 26092 |
|
| 26093 |
if Ekind (E) = E_Constant then |
| 26094 |
Decl := Parent (E); |
| 26095 |
|
| 26096 |
if Nkind (Decl) = N_Object_Declaration then |
| 26097 |
P := Expression (Decl); |
| 26098 |
end if; |
| 26099 |
end if; |
| 26100 |
end if; |
| 26101 |
|
| 26102 |
if Nkind (P) = N_Selected_Component then |
| 26103 |
S := Selector_Name (P); |
| 26104 |
|
| 26105 |
if Present (Entry_Formal (Entity (S))) then |
| 26106 |
return Entry_Formal (Entity (S)); |
| 26107 |
end if; |
| 26108 |
|
| 26109 |
elsif Nkind (Original_Node (N)) = N_Identifier then |
| 26110 |
return Param_Entity (Original_Node (N)); |
| 26111 |
end if; |
| 26112 |
end; |
| 26113 |
end if; |
| 26114 |
end if; |
| 26115 |
|
| 26116 |
return Empty; |
| 26117 |
end Param_Entity; |
| 26118 |
|
| 26119 |
---------------------- |
| 26120 |
-- Policy_In_Effect -- |
| 26121 |
---------------------- |
| 26122 |
|
| 26123 |
function Policy_In_Effect (Policy : Name_Id) return Name_Id is |
| 26124 |
function Policy_In_List (List : Node_Id) return Name_Id; |
| 26125 |
-- Determine the mode of a policy in a N_Pragma list |
| 26126 |
|
| 26127 |
-------------------- |
| 26128 |
-- Policy_In_List -- |
| 26129 |
-------------------- |
| 26130 |
|
| 26131 |
function Policy_In_List (List : Node_Id) return Name_Id is |
| 26132 |
Arg1 : Node_Id; |
| 26133 |
Arg2 : Node_Id; |
| 26134 |
Prag : Node_Id; |
| 26135 |
|
| 26136 |
begin |
| 26137 |
Prag := List; |
| 26138 |
while Present (Prag) loop |
| 26139 |
Arg1 := First (Pragma_Argument_Associations (Prag)); |
| 26140 |
Arg2 := Next (Arg1); |
| 26141 |
|
| 26142 |
Arg1 := Get_Pragma_Arg (Arg1); |
| 26143 |
Arg2 := Get_Pragma_Arg (Arg2); |
| 26144 |
|
| 26145 |
-- The current Check_Policy pragma matches the requested policy or |
| 26146 |
-- appears in the single argument form (Assertion, policy_id). |
| 26147 |
|
| 26148 |
if Chars (Arg1) in Name_Assertion | Policy then |
| 26149 |
return Chars (Arg2); |
| 26150 |
end if; |
| 26151 |
|
| 26152 |
Prag := Next_Pragma (Prag); |
| 26153 |
end loop; |
| 26154 |
|
| 26155 |
return No_Name; |
| 26156 |
end Policy_In_List; |
| 26157 |
|
| 26158 |
-- Local variables |
| 26159 |
|
| 26160 |
Kind : Name_Id; |
| 26161 |
|
| 26162 |
-- Start of processing for Policy_In_Effect |
| 26163 |
|
| 26164 |
begin |
| 26165 |
if not Is_Valid_Assertion_Kind (Policy) then |
| 26166 |
raise Program_Error; |
| 26167 |
end if; |
| 26168 |
|
| 26169 |
-- Inspect all policy pragmas that appear within scopes (if any) |
| 26170 |
|
| 26171 |
Kind := Policy_In_List (Check_Policy_List); |
| 26172 |
|
| 26173 |
-- Inspect all configuration policy pragmas (if any) |
| 26174 |
|
| 26175 |
if Kind = No_Name then |
| 26176 |
Kind := Policy_In_List (Check_Policy_List_Config); |
| 26177 |
end if; |
| 26178 |
|
| 26179 |
-- The context lacks policy pragmas, determine the mode based on whether |
| 26180 |
-- assertions are enabled at the configuration level. This ensures that |
| 26181 |
-- the policy is preserved when analyzing generics. |
| 26182 |
|
| 26183 |
if Kind = No_Name then |
| 26184 |
if Assertions_Enabled_Config then |
| 26185 |
Kind := Name_Check; |
| 26186 |
else |
| 26187 |
Kind := Name_Ignore; |
| 26188 |
end if; |
| 26189 |
end if; |
| 26190 |
|
| 26191 |
-- In CodePeer mode and GNATprove mode, we need to consider all |
| 26192 |
-- assertions, unless they are disabled. Force Name_Check on |
| 26193 |
-- ignored assertions. |
| 26194 |
|
| 26195 |
if Kind in Name_Ignore | Name_Off |
| 26196 |
and then (CodePeer_Mode or GNATprove_Mode) |
| 26197 |
then |
| 26198 |
Kind := Name_Check; |
| 26199 |
end if; |
| 26200 |
|
| 26201 |
return Kind; |
| 26202 |
end Policy_In_Effect; |
| 26203 |
|
| 26204 |
------------------------------------------- |
| 26205 |
-- Preanalyze_And_Resolve_Without_Errors -- |
| 26206 |
------------------------------------------- |
| 26207 |
|
| 26208 |
procedure Preanalyze_And_Resolve_Without_Errors (N : Node_Id) is |
| 26209 |
Status : constant Boolean := Get_Ignore_Errors; |
| 26210 |
begin |
| 26211 |
Set_Ignore_Errors (True); |
| 26212 |
Preanalyze_And_Resolve (N); |
| 26213 |
Set_Ignore_Errors (Status); |
| 26214 |
end Preanalyze_And_Resolve_Without_Errors; |
| 26215 |
|
| 26216 |
------------------------------- |
| 26217 |
-- Preanalyze_Without_Errors -- |
| 26218 |
------------------------------- |
| 26219 |
|
| 26220 |
procedure Preanalyze_Without_Errors (N : Node_Id) is |
| 26221 |
Status : constant Boolean := Get_Ignore_Errors; |
| 26222 |
begin |
| 26223 |
Set_Ignore_Errors (True); |
| 26224 |
Preanalyze (N); |
| 26225 |
Set_Ignore_Errors (Status); |
| 26226 |
end Preanalyze_Without_Errors; |
| 26227 |
|
| 26228 |
----------------------- |
| 26229 |
-- Predicate_Enabled -- |
| 26230 |
----------------------- |
| 26231 |
|
| 26232 |
function Predicate_Enabled (Typ : Entity_Id) return Boolean is |
| 26233 |
begin |
| 26234 |
return Present (Predicate_Function (Typ)) |
| 26235 |
and then not Predicates_Ignored (Typ) |
| 26236 |
and then not Predicate_Checks_Suppressed (Empty); |
| 26237 |
end Predicate_Enabled; |
| 26238 |
|
| 26239 |
---------------------------------- |
| 26240 |
-- Predicate_Failure_Expression -- |
| 26241 |
---------------------------------- |
| 26242 |
|
| 26243 |
function Predicate_Failure_Expression |
| 26244 |
(Typ : Entity_Id; Inherited_OK : Boolean) return Node_Id |
| 26245 |
is |
| 26246 |
PF_Aspect : constant Node_Id := |
| 26247 |
Find_Aspect (Typ, Aspect_Predicate_Failure); |
| 26248 |
begin |
| 26249 |
-- Check for Predicate_Failure aspect specification via an |
| 26250 |
-- aspect_specification (as opposed to via a pragma). |
| 26251 |
|
| 26252 |
if Present (PF_Aspect) then |
| 26253 |
if Inherited_OK or else Entity (PF_Aspect) = Typ then |
| 26254 |
return Expression (PF_Aspect); |
| 26255 |
else |
| 26256 |
return Empty; |
| 26257 |
end if; |
| 26258 |
end if; |
| 26259 |
|
| 26260 |
-- Check for Predicate_Failure aspect specification via a pragma. |
| 26261 |
|
| 26262 |
declare |
| 26263 |
Rep_Item : Node_Id := First_Rep_Item (Typ); |
| 26264 |
begin |
| 26265 |
while Present (Rep_Item) loop |
| 26266 |
if Nkind (Rep_Item) = N_Pragma |
| 26267 |
and then Get_Pragma_Id (Rep_Item) = Pragma_Predicate_Failure |
| 26268 |
then |
| 26269 |
declare |
| 26270 |
Arg1 : constant Node_Id := |
| 26271 |
Get_Pragma_Arg |
| 26272 |
(First (Pragma_Argument_Associations (Rep_Item))); |
| 26273 |
Arg2 : constant Node_Id := |
| 26274 |
Get_Pragma_Arg |
| 26275 |
(Next (First (Pragma_Argument_Associations (Rep_Item)))); |
| 26276 |
begin |
| 26277 |
if Inherited_OK or else |
| 26278 |
(Nkind (Arg1) in N_Has_Entity |
| 26279 |
and then Entity (Arg1) = Typ) |
| 26280 |
then |
| 26281 |
return Arg2; |
| 26282 |
end if; |
| 26283 |
end; |
| 26284 |
end if; |
| 26285 |
|
| 26286 |
Next_Rep_Item (Rep_Item); |
| 26287 |
end loop; |
| 26288 |
end; |
| 26289 |
|
| 26290 |
-- If we are interested in an inherited Predicate_Failure aspect |
| 26291 |
-- and we have an ancestor to inherit from, then recursively check |
| 26292 |
-- for that case. |
| 26293 |
|
| 26294 |
if Inherited_OK and then Present (Nearest_Ancestor (Typ)) then |
| 26295 |
return Predicate_Failure_Expression (Nearest_Ancestor (Typ), |
| 26296 |
Inherited_OK => True); |
| 26297 |
end if; |
| 26298 |
|
| 26299 |
return Empty; |
| 26300 |
end Predicate_Failure_Expression; |
| 26301 |
|
| 26302 |
---------------------------------- |
| 26303 |
-- Predicate_Tests_On_Arguments -- |
| 26304 |
---------------------------------- |
| 26305 |
|
| 26306 |
function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is |
| 26307 |
begin |
| 26308 |
-- Always test predicates on indirect call |
| 26309 |
|
| 26310 |
if Ekind (Subp) = E_Subprogram_Type then |
| 26311 |
return True; |
| 26312 |
|
| 26313 |
-- Do not test predicates on call to generated default Finalize, since |
| 26314 |
-- we are not interested in whether something we are finalizing (and |
| 26315 |
-- typically destroying) satisfies its predicates. |
| 26316 |
|
| 26317 |
elsif Chars (Subp) = Name_Finalize |
| 26318 |
and then not Comes_From_Source (Subp) |
| 26319 |
then |
| 26320 |
return False; |
| 26321 |
|
| 26322 |
-- Do not test predicates on any internally generated routines |
| 26323 |
|
| 26324 |
elsif Is_Internal_Name (Chars (Subp)) then |
| 26325 |
return False; |
| 26326 |
|
| 26327 |
-- Do not test predicates on call to Init_Proc, since if needed the |
| 26328 |
-- predicate test will occur at some other point. |
| 26329 |
|
| 26330 |
elsif Is_Init_Proc (Subp) then |
| 26331 |
return False; |
| 26332 |
|
| 26333 |
-- Do not test predicates on call to predicate function, since this |
| 26334 |
-- would cause infinite recursion. |
| 26335 |
|
| 26336 |
elsif Ekind (Subp) = E_Function |
| 26337 |
and then Is_Predicate_Function (Subp) |
| 26338 |
then |
| 26339 |
return False; |
| 26340 |
|
| 26341 |
-- For now, no other exceptions |
| 26342 |
|
| 26343 |
else |
| 26344 |
return True; |
| 26345 |
end if; |
| 26346 |
end Predicate_Tests_On_Arguments; |
| 26347 |
|
| 26348 |
----------------------- |
| 26349 |
-- Private_Component -- |
| 26350 |
----------------------- |
| 26351 |
|
| 26352 |
function Private_Component (Type_Id : Entity_Id) return Entity_Id is |
| 26353 |
Ancestor : constant Entity_Id := Base_Type (Type_Id); |
| 26354 |
|
| 26355 |
function Trace_Components |
| 26356 |
(T : Entity_Id; |
| 26357 |
Check : Boolean) return Entity_Id; |
| 26358 |
-- Recursive function that does the work, and checks against circular |
| 26359 |
-- definition for each subcomponent type. |
| 26360 |
|
| 26361 |
---------------------- |
| 26362 |
-- Trace_Components -- |
| 26363 |
---------------------- |
| 26364 |
|
| 26365 |
function Trace_Components |
| 26366 |
(T : Entity_Id; |
| 26367 |
Check : Boolean) return Entity_Id |
| 26368 |
is |
| 26369 |
Btype : constant Entity_Id := Base_Type (T); |
| 26370 |
Component : Entity_Id; |
| 26371 |
P : Entity_Id; |
| 26372 |
Candidate : Entity_Id := Empty; |
| 26373 |
|
| 26374 |
begin |
| 26375 |
if Check and then Btype = Ancestor then |
| 26376 |
Error_Msg_N ("circular type definition", Type_Id); |
| 26377 |
return Any_Type; |
| 26378 |
end if; |
| 26379 |
|
| 26380 |
if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then |
| 26381 |
if Present (Full_View (Btype)) |
| 26382 |
and then Is_Record_Type (Full_View (Btype)) |
| 26383 |
and then not Is_Frozen (Btype) |
| 26384 |
then |
| 26385 |
-- To indicate that the ancestor depends on a private type, the |
| 26386 |
-- current Btype is sufficient. However, to check for circular |
| 26387 |
-- definition we must recurse on the full view. |
| 26388 |
|
| 26389 |
Candidate := Trace_Components (Full_View (Btype), True); |
| 26390 |
|
| 26391 |
if Candidate = Any_Type then |
| 26392 |
return Any_Type; |
| 26393 |
else |
| 26394 |
return Btype; |
| 26395 |
end if; |
| 26396 |
|
| 26397 |
else |
| 26398 |
return Btype; |
| 26399 |
end if; |
| 26400 |
|
| 26401 |
elsif Is_Array_Type (Btype) then |
| 26402 |
return Trace_Components (Component_Type (Btype), True); |
| 26403 |
|
| 26404 |
elsif Is_Record_Type (Btype) then |
| 26405 |
Component := First_Entity (Btype); |
| 26406 |
while Present (Component) |
| 26407 |
and then Comes_From_Source (Component) |
| 26408 |
loop |
| 26409 |
-- Skip anonymous types generated by constrained components |
| 26410 |
|
| 26411 |
if not Is_Type (Component) then |
| 26412 |
P := Trace_Components (Etype (Component), True); |
| 26413 |
|
| 26414 |
if Present (P) then |
| 26415 |
if P = Any_Type then |
| 26416 |
return P; |
| 26417 |
else |
| 26418 |
Candidate := P; |
| 26419 |
end if; |
| 26420 |
end if; |
| 26421 |
end if; |
| 26422 |
|
| 26423 |
Next_Entity (Component); |
| 26424 |
end loop; |
| 26425 |
|
| 26426 |
return Candidate; |
| 26427 |
|
| 26428 |
else |
| 26429 |
return Empty; |
| 26430 |
end if; |
| 26431 |
end Trace_Components; |
| 26432 |
|
| 26433 |
-- Start of processing for Private_Component |
| 26434 |
|
| 26435 |
begin |
| 26436 |
return Trace_Components (Type_Id, False); |
| 26437 |
end Private_Component; |
| 26438 |
|
| 26439 |
--------------------------- |
| 26440 |
-- Primitive_Names_Match -- |
| 26441 |
--------------------------- |
| 26442 |
|
| 26443 |
function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is |
| 26444 |
function Non_Internal_Name (E : Entity_Id) return Name_Id; |
| 26445 |
-- Given an internal name, returns the corresponding non-internal name |
| 26446 |
|
| 26447 |
------------------------ |
| 26448 |
-- Non_Internal_Name -- |
| 26449 |
------------------------ |
| 26450 |
|
| 26451 |
function Non_Internal_Name (E : Entity_Id) return Name_Id is |
| 26452 |
begin |
| 26453 |
Get_Name_String (Chars (E)); |
| 26454 |
Name_Len := Name_Len - 1; |
| 26455 |
return Name_Find; |
| 26456 |
end Non_Internal_Name; |
| 26457 |
|
| 26458 |
-- Start of processing for Primitive_Names_Match |
| 26459 |
|
| 26460 |
begin |
| 26461 |
pragma Assert (Present (E1) and then Present (E2)); |
| 26462 |
|
| 26463 |
return Chars (E1) = Chars (E2) |
| 26464 |
or else |
| 26465 |
(not Is_Internal_Name (Chars (E1)) |
| 26466 |
and then Is_Internal_Name (Chars (E2)) |
| 26467 |
and then Non_Internal_Name (E2) = Chars (E1)) |
| 26468 |
or else |
| 26469 |
(not Is_Internal_Name (Chars (E2)) |
| 26470 |
and then Is_Internal_Name (Chars (E1)) |
| 26471 |
and then Non_Internal_Name (E1) = Chars (E2)) |
| 26472 |
or else |
| 26473 |
(Is_Predefined_Dispatching_Operation (E1) |
| 26474 |
and then Is_Predefined_Dispatching_Operation (E2) |
| 26475 |
and then Same_TSS (E1, E2)) |
| 26476 |
or else |
| 26477 |
(Is_Init_Proc (E1) and then Is_Init_Proc (E2)); |
| 26478 |
end Primitive_Names_Match; |
| 26479 |
|
| 26480 |
----------------------- |
| 26481 |
-- Process_End_Label -- |
| 26482 |
----------------------- |
| 26483 |
|
| 26484 |
procedure Process_End_Label |
| 26485 |
(N : Node_Id; |
| 26486 |
Typ : Character; |
| 26487 |
Ent : Entity_Id) |
| 26488 |
is |
| 26489 |
Loc : Source_Ptr; |
| 26490 |
Nam : Node_Id; |
| 26491 |
Scop : Entity_Id; |
| 26492 |
|
| 26493 |
Label_Ref : Boolean; |
| 26494 |
-- Set True if reference to end label itself is required |
| 26495 |
|
| 26496 |
Endl : Node_Id; |
| 26497 |
-- Gets set to the operator symbol or identifier that references the |
| 26498 |
-- entity Ent. For the child unit case, this is the identifier from the |
| 26499 |
-- designator. For other cases, this is simply Endl. |
| 26500 |
|
| 26501 |
procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id); |
| 26502 |
-- N is an identifier node that appears as a parent unit reference in |
| 26503 |
-- the case where Ent is a child unit. This procedure generates an |
| 26504 |
-- appropriate cross-reference entry. E is the corresponding entity. |
| 26505 |
|
| 26506 |
------------------------- |
| 26507 |
-- Generate_Parent_Ref -- |
| 26508 |
------------------------- |
| 26509 |
|
| 26510 |
procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is |
| 26511 |
begin |
| 26512 |
-- If names do not match, something weird, skip reference |
| 26513 |
|
| 26514 |
if Chars (E) = Chars (N) then |
| 26515 |
|
| 26516 |
-- Generate the reference. We do NOT consider this as a reference |
| 26517 |
-- for unreferenced symbol purposes. |
| 26518 |
|
| 26519 |
Generate_Reference (E, N, 'r', Set_Ref => False, Force => True); |
| 26520 |
|
| 26521 |
if Style_Check then |
| 26522 |
Style.Check_Identifier (N, E); |
| 26523 |
end if; |
| 26524 |
end if; |
| 26525 |
end Generate_Parent_Ref; |
| 26526 |
|
| 26527 |
-- Start of processing for Process_End_Label |
| 26528 |
|
| 26529 |
begin |
| 26530 |
-- If no node, ignore. This happens in some error situations, and |
| 26531 |
-- also for some internally generated structures where no end label |
| 26532 |
-- references are required in any case. |
| 26533 |
|
| 26534 |
if No (N) then |
| 26535 |
return; |
| 26536 |
end if; |
| 26537 |
|
| 26538 |
-- Nothing to do if no End_Label, happens for internally generated |
| 26539 |
-- constructs where we don't want an end label reference anyway. Also |
| 26540 |
-- nothing to do if Endl is a string literal, which means there was |
| 26541 |
-- some prior error (bad operator symbol) |
| 26542 |
|
| 26543 |
Endl := End_Label (N); |
| 26544 |
|
| 26545 |
if No (Endl) or else Nkind (Endl) = N_String_Literal then |
| 26546 |
return; |
| 26547 |
end if; |
| 26548 |
|
| 26549 |
-- Reference node is not in extended main source unit |
| 26550 |
|
| 26551 |
if not In_Extended_Main_Source_Unit (N) then |
| 26552 |
|
| 26553 |
-- Generally we do not collect references except for the extended |
| 26554 |
-- main source unit. The one exception is the 'e' entry for a |
| 26555 |
-- package spec, where it is useful for a client to have the |
| 26556 |
-- ending information to define scopes. |
| 26557 |
|
| 26558 |
if Typ /= 'e' then |
| 26559 |
return; |
| 26560 |
|
| 26561 |
else |
| 26562 |
Label_Ref := False; |
| 26563 |
|
| 26564 |
-- For this case, we can ignore any parent references, but we |
| 26565 |
-- need the package name itself for the 'e' entry. |
| 26566 |
|
| 26567 |
if Nkind (Endl) = N_Designator then |
| 26568 |
Endl := Identifier (Endl); |
| 26569 |
end if; |
| 26570 |
end if; |
| 26571 |
|
| 26572 |
-- Reference is in extended main source unit |
| 26573 |
|
| 26574 |
else |
| 26575 |
Label_Ref := True; |
| 26576 |
|
| 26577 |
-- For designator, generate references for the parent entries |
| 26578 |
|
| 26579 |
if Nkind (Endl) = N_Designator then |
| 26580 |
|
| 26581 |
-- Generate references for the prefix if the END line comes from |
| 26582 |
-- source (otherwise we do not need these references) We climb the |
| 26583 |
-- scope stack to find the expected entities. |
| 26584 |
|
| 26585 |
if Comes_From_Source (Endl) then |
| 26586 |
Nam := Name (Endl); |
| 26587 |
Scop := Current_Scope; |
| 26588 |
while Nkind (Nam) = N_Selected_Component loop |
| 26589 |
Scop := Scope (Scop); |
| 26590 |
exit when No (Scop); |
| 26591 |
Generate_Parent_Ref (Selector_Name (Nam), Scop); |
| 26592 |
Nam := Prefix (Nam); |
| 26593 |
end loop; |
| 26594 |
|
| 26595 |
if Present (Scop) then |
| 26596 |
Generate_Parent_Ref (Nam, Scope (Scop)); |
| 26597 |
end if; |
| 26598 |
end if; |
| 26599 |
|
| 26600 |
Endl := Identifier (Endl); |
| 26601 |
end if; |
| 26602 |
end if; |
| 26603 |
|
| 26604 |
-- If the end label is not for the given entity, then either we have |
| 26605 |
-- some previous error, or this is a generic instantiation for which |
| 26606 |
-- we do not need to make a cross-reference in this case anyway. In |
| 26607 |
-- either case we simply ignore the call. |
| 26608 |
|
| 26609 |
if Chars (Ent) /= Chars (Endl) then |
| 26610 |
return; |
| 26611 |
end if; |
| 26612 |
|
| 26613 |
-- If label was really there, then generate a normal reference and then |
| 26614 |
-- adjust the location in the end label to point past the name (which |
| 26615 |
-- should almost always be the semicolon). |
| 26616 |
|
| 26617 |
Loc := Sloc (Endl); |
| 26618 |
|
| 26619 |
if Comes_From_Source (Endl) then |
| 26620 |
|
| 26621 |
-- If a label reference is required, then do the style check and |
| 26622 |
-- generate an l-type cross-reference entry for the label |
| 26623 |
|
| 26624 |
if Label_Ref then |
| 26625 |
if Style_Check then |
| 26626 |
Style.Check_Identifier (Endl, Ent); |
| 26627 |
end if; |
| 26628 |
|
| 26629 |
Generate_Reference (Ent, Endl, 'l', Set_Ref => False); |
| 26630 |
end if; |
| 26631 |
|
| 26632 |
-- Set the location to point past the label (normally this will |
| 26633 |
-- mean the semicolon immediately following the label). This is |
| 26634 |
-- done for the sake of the 'e' or 't' entry generated below. |
| 26635 |
|
| 26636 |
Get_Decoded_Name_String (Chars (Endl)); |
| 26637 |
Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len)); |
| 26638 |
end if; |
| 26639 |
|
| 26640 |
-- Now generate the e/t reference |
| 26641 |
|
| 26642 |
Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True); |
| 26643 |
|
| 26644 |
-- Restore Sloc, in case modified above, since we have an identifier |
| 26645 |
-- and the normal Sloc should be left set in the tree. |
| 26646 |
|
| 26647 |
Set_Sloc (Endl, Loc); |
| 26648 |
end Process_End_Label; |
| 26649 |
|
| 26650 |
-------------------------------- |
| 26651 |
-- Propagate_Concurrent_Flags -- |
| 26652 |
-------------------------------- |
| 26653 |
|
| 26654 |
procedure Propagate_Concurrent_Flags |
| 26655 |
(Typ : Entity_Id; |
| 26656 |
Comp_Typ : Entity_Id) |
| 26657 |
is |
| 26658 |
begin |
| 26659 |
if Has_Task (Comp_Typ) then |
| 26660 |
Set_Has_Task (Typ); |
| 26661 |
end if; |
| 26662 |
|
| 26663 |
if Has_Protected (Comp_Typ) then |
| 26664 |
Set_Has_Protected (Typ); |
| 26665 |
end if; |
| 26666 |
|
| 26667 |
if Has_Timing_Event (Comp_Typ) then |
| 26668 |
Set_Has_Timing_Event (Typ); |
| 26669 |
end if; |
| 26670 |
end Propagate_Concurrent_Flags; |
| 26671 |
|
| 26672 |
-------------------------------- |
| 26673 |
-- Propagate_Controlled_Flags -- |
| 26674 |
-------------------------------- |
| 26675 |
|
| 26676 |
procedure Propagate_Controlled_Flags |
| 26677 |
(Typ : Entity_Id; |
| 26678 |
From_Typ : Entity_Id; |
| 26679 |
Comp : Boolean := False; |
| 26680 |
Deriv : Boolean := False) |
| 26681 |
is |
| 26682 |
begin |
| 26683 |
-- It does not make sense to have both Comp and Deriv set True |
| 26684 |
|
| 26685 |
pragma Assert (not Comp or else not Deriv); |
| 26686 |
|
| 26687 |
-- This implementation only supports array types for the component case. |
| 26688 |
-- Disregard Is_Controlled_Active and Disable_Controlled in this case. |
| 26689 |
|
| 26690 |
if Comp then |
| 26691 |
pragma Assert (Is_Array_Type (Typ)); |
| 26692 |
|
| 26693 |
else |
| 26694 |
if Is_Controlled_Active (From_Typ) then |
| 26695 |
Set_Is_Controlled_Active (Typ); |
| 26696 |
end if; |
| 26697 |
|
| 26698 |
if Disable_Controlled (From_Typ) then |
| 26699 |
Set_Disable_Controlled (Typ); |
| 26700 |
end if; |
| 26701 |
end if; |
| 26702 |
|
| 26703 |
-- Direct controlled types do not inherit Finalize_Storage_Only |
| 26704 |
|
| 26705 |
if not (Deriv and then Is_Controlled (From_Typ)) then |
| 26706 |
if Finalize_Storage_Only (From_Typ) then |
| 26707 |
Set_Finalize_Storage_Only (Typ); |
| 26708 |
end if; |
| 26709 |
end if; |
| 26710 |
|
| 26711 |
-- Is_Controlled yields Has_Controlled_Component for component |
| 26712 |
|
| 26713 |
if Has_Controlled_Component (From_Typ) |
| 26714 |
or else (Comp and then Is_Controlled (From_Typ)) |
| 26715 |
then |
| 26716 |
Set_Has_Controlled_Component (Typ); |
| 26717 |
end if; |
| 26718 |
|
| 26719 |
if Has_Relaxed_Finalization (From_Typ) then |
| 26720 |
Set_Has_Relaxed_Finalization (Typ); |
| 26721 |
end if; |
| 26722 |
end Propagate_Controlled_Flags; |
| 26723 |
|
| 26724 |
------------------------------ |
| 26725 |
-- Propagate_DIC_Attributes -- |
| 26726 |
------------------------------ |
| 26727 |
|
| 26728 |
procedure Propagate_DIC_Attributes |
| 26729 |
(Typ : Entity_Id; |
| 26730 |
From_Typ : Entity_Id) |
| 26731 |
is |
| 26732 |
DIC_Proc : Entity_Id; |
| 26733 |
Partial_DIC_Proc : Entity_Id; |
| 26734 |
|
| 26735 |
begin |
| 26736 |
if Present (Typ) and then Present (From_Typ) then |
| 26737 |
pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ)); |
| 26738 |
|
| 26739 |
-- Nothing to do if both the source and the destination denote the |
| 26740 |
-- same type. |
| 26741 |
|
| 26742 |
if From_Typ = Typ then |
| 26743 |
return; |
| 26744 |
|
| 26745 |
-- Nothing to do when the destination denotes an incomplete type |
| 26746 |
-- because the DIC is associated with the current instance of a |
| 26747 |
-- private type, thus it can never apply to an incomplete type. |
| 26748 |
|
| 26749 |
elsif Is_Incomplete_Type (Typ) then |
| 26750 |
return; |
| 26751 |
end if; |
| 26752 |
|
| 26753 |
DIC_Proc := DIC_Procedure (From_Typ); |
| 26754 |
Partial_DIC_Proc := Partial_DIC_Procedure (From_Typ); |
| 26755 |
|
| 26756 |
-- The setting of the attributes is intentionally conservative. This |
| 26757 |
-- prevents accidental clobbering of enabled attributes. We need to |
| 26758 |
-- call Base_Type twice, because it is sometimes not set to an actual |
| 26759 |
-- base type??? |
| 26760 |
|
| 26761 |
if Has_Inherited_DIC (From_Typ) then |
| 26762 |
Set_Has_Inherited_DIC (Base_Type (Base_Type (Typ))); |
| 26763 |
end if; |
| 26764 |
|
| 26765 |
if Has_Own_DIC (From_Typ) then |
| 26766 |
Set_Has_Own_DIC (Base_Type (Base_Type (Typ))); |
| 26767 |
end if; |
| 26768 |
|
| 26769 |
if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then |
| 26770 |
Set_DIC_Procedure (Typ, DIC_Proc); |
| 26771 |
end if; |
| 26772 |
|
| 26773 |
if Present (Partial_DIC_Proc) |
| 26774 |
and then No (Partial_DIC_Procedure (Typ)) |
| 26775 |
then |
| 26776 |
Set_Partial_DIC_Procedure (Typ, Partial_DIC_Proc); |
| 26777 |
end if; |
| 26778 |
end if; |
| 26779 |
end Propagate_DIC_Attributes; |
| 26780 |
|
| 26781 |
------------------------------------ |
| 26782 |
-- Propagate_Invariant_Attributes -- |
| 26783 |
------------------------------------ |
| 26784 |
|
| 26785 |
procedure Propagate_Invariant_Attributes |
| 26786 |
(Typ : Entity_Id; |
| 26787 |
From_Typ : Entity_Id) |
| 26788 |
is |
| 26789 |
Full_IP : Entity_Id; |
| 26790 |
Part_IP : Entity_Id; |
| 26791 |
|
| 26792 |
begin |
| 26793 |
if Present (Typ) and then Present (From_Typ) then |
| 26794 |
pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ)); |
| 26795 |
|
| 26796 |
-- Nothing to do if both the source and the destination denote the |
| 26797 |
-- same type. |
| 26798 |
|
| 26799 |
if From_Typ = Typ then |
| 26800 |
return; |
| 26801 |
end if; |
| 26802 |
|
| 26803 |
Full_IP := Invariant_Procedure (From_Typ); |
| 26804 |
Part_IP := Partial_Invariant_Procedure (From_Typ); |
| 26805 |
|
| 26806 |
-- The setting of the attributes is intentionally conservative. This |
| 26807 |
-- prevents accidental clobbering of enabled attributes. We need to |
| 26808 |
-- call Base_Type twice, because it is sometimes not set to an actual |
| 26809 |
-- base type??? |
| 26810 |
|
| 26811 |
if Has_Inheritable_Invariants (From_Typ) then |
| 26812 |
Set_Has_Inheritable_Invariants (Base_Type (Base_Type (Typ))); |
| 26813 |
end if; |
| 26814 |
|
| 26815 |
if Has_Inherited_Invariants (From_Typ) then |
| 26816 |
Set_Has_Inherited_Invariants (Base_Type (Base_Type (Typ))); |
| 26817 |
end if; |
| 26818 |
|
| 26819 |
if Has_Own_Invariants (From_Typ) then |
| 26820 |
Set_Has_Own_Invariants (Base_Type (Base_Type (Typ))); |
| 26821 |
end if; |
| 26822 |
|
| 26823 |
if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then |
| 26824 |
Set_Invariant_Procedure (Typ, Full_IP); |
| 26825 |
end if; |
| 26826 |
|
| 26827 |
if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ)) |
| 26828 |
then |
| 26829 |
Set_Partial_Invariant_Procedure (Typ, Part_IP); |
| 26830 |
end if; |
| 26831 |
end if; |
| 26832 |
end Propagate_Invariant_Attributes; |
| 26833 |
|
| 26834 |
------------------------------------ |
| 26835 |
-- Propagate_Predicate_Attributes -- |
| 26836 |
------------------------------------ |
| 26837 |
|
| 26838 |
procedure Propagate_Predicate_Attributes |
| 26839 |
(Typ : Entity_Id; |
| 26840 |
From_Typ : Entity_Id) |
| 26841 |
is |
| 26842 |
Pred_Func : Entity_Id; |
| 26843 |
begin |
| 26844 |
if Present (Typ) and then Present (From_Typ) then |
| 26845 |
pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ)); |
| 26846 |
|
| 26847 |
-- Nothing to do if both the source and the destination denote the |
| 26848 |
-- same type. |
| 26849 |
|
| 26850 |
if From_Typ = Typ then |
| 26851 |
return; |
| 26852 |
end if; |
| 26853 |
|
| 26854 |
Pred_Func := Predicate_Function (From_Typ); |
| 26855 |
|
| 26856 |
-- The setting of the attributes is intentionally conservative. This |
| 26857 |
-- prevents accidental clobbering of enabled attributes. |
| 26858 |
|
| 26859 |
if Has_Predicates (From_Typ) then |
| 26860 |
Set_Has_Predicates (Typ); |
| 26861 |
end if; |
| 26862 |
|
| 26863 |
if Present (Pred_Func) and then No (Predicate_Function (Typ)) then |
| 26864 |
Set_Predicate_Function (Typ, Pred_Func); |
| 26865 |
end if; |
| 26866 |
end if; |
| 26867 |
end Propagate_Predicate_Attributes; |
| 26868 |
|
| 26869 |
--------------------------------------- |
| 26870 |
-- Record_Possible_Part_Of_Reference -- |
| 26871 |
--------------------------------------- |
| 26872 |
|
| 26873 |
procedure Record_Possible_Part_Of_Reference |
| 26874 |
(Var_Id : Entity_Id; |
| 26875 |
Ref : Node_Id) |
| 26876 |
is |
| 26877 |
Encap : constant Entity_Id := Encapsulating_State (Var_Id); |
| 26878 |
Refs : Elist_Id; |
| 26879 |
|
| 26880 |
begin |
| 26881 |
-- The variable is a constituent of a single protected/task type. Such |
| 26882 |
-- a variable acts as a component of the type and must appear within a |
| 26883 |
-- specific region (SPARK RM 9(3)). Instead of recording the reference, |
| 26884 |
-- verify its legality now. |
| 26885 |
|
| 26886 |
if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then |
| 26887 |
Check_Part_Of_Reference (Var_Id, Ref); |
| 26888 |
|
| 26889 |
-- The variable is subject to pragma Part_Of and may eventually become a |
| 26890 |
-- constituent of a single protected/task type. Record the reference to |
| 26891 |
-- verify its placement when the contract of the variable is analyzed. |
| 26892 |
|
| 26893 |
elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then |
| 26894 |
Refs := Part_Of_References (Var_Id); |
| 26895 |
|
| 26896 |
if No (Refs) then |
| 26897 |
Refs := New_Elmt_List; |
| 26898 |
Set_Part_Of_References (Var_Id, Refs); |
| 26899 |
end if; |
| 26900 |
|
| 26901 |
Append_Elmt (Ref, Refs); |
| 26902 |
end if; |
| 26903 |
end Record_Possible_Part_Of_Reference; |
| 26904 |
|
| 26905 |
---------------- |
| 26906 |
-- Referenced -- |
| 26907 |
---------------- |
| 26908 |
|
| 26909 |
function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is |
| 26910 |
Seen : Boolean := False; |
| 26911 |
|
| 26912 |
function Is_Reference (N : Node_Id) return Traverse_Result; |
| 26913 |
-- Determine whether node N denotes a reference to Id. If this is the |
| 26914 |
-- case, set global flag Seen to True and stop the traversal. |
| 26915 |
|
| 26916 |
------------------ |
| 26917 |
-- Is_Reference -- |
| 26918 |
------------------ |
| 26919 |
|
| 26920 |
function Is_Reference (N : Node_Id) return Traverse_Result is |
| 26921 |
begin |
| 26922 |
if Is_Entity_Name (N) |
| 26923 |
and then Present (Entity (N)) |
| 26924 |
and then Entity (N) = Id |
| 26925 |
then |
| 26926 |
Seen := True; |
| 26927 |
return Abandon; |
| 26928 |
else |
| 26929 |
return OK; |
| 26930 |
end if; |
| 26931 |
end Is_Reference; |
| 26932 |
|
| 26933 |
procedure Inspect_Expression is new Traverse_Proc (Is_Reference); |
| 26934 |
|
| 26935 |
-- Start of processing for Referenced |
| 26936 |
|
| 26937 |
begin |
| 26938 |
Inspect_Expression (Expr); |
| 26939 |
return Seen; |
| 26940 |
end Referenced; |
| 26941 |
|
| 26942 |
------------------------------------ |
| 26943 |
-- References_Generic_Formal_Type -- |
| 26944 |
------------------------------------ |
| 26945 |
|
| 26946 |
function References_Generic_Formal_Type (N : Node_Id) return Boolean is |
| 26947 |
|
| 26948 |
function Process (N : Node_Id) return Traverse_Result; |
| 26949 |
-- Process one node in search for generic formal type |
| 26950 |
|
| 26951 |
------------- |
| 26952 |
-- Process -- |
| 26953 |
------------- |
| 26954 |
|
| 26955 |
function Process (N : Node_Id) return Traverse_Result is |
| 26956 |
begin |
| 26957 |
if Nkind (N) in N_Has_Entity then |
| 26958 |
declare |
| 26959 |
E : constant Entity_Id := Entity (N); |
| 26960 |
begin |
| 26961 |
if Present (E) then |
| 26962 |
if Is_Generic_Type (E) then |
| 26963 |
return Abandon; |
| 26964 |
elsif Present (Etype (E)) |
| 26965 |
and then Is_Generic_Type (Etype (E)) |
| 26966 |
then |
| 26967 |
return Abandon; |
| 26968 |
end if; |
| 26969 |
end if; |
| 26970 |
end; |
| 26971 |
end if; |
| 26972 |
|
| 26973 |
return Atree.OK; |
| 26974 |
end Process; |
| 26975 |
|
| 26976 |
function Traverse is new Traverse_Func (Process); |
| 26977 |
-- Traverse tree to look for generic type |
| 26978 |
|
| 26979 |
begin |
| 26980 |
if Inside_A_Generic then |
| 26981 |
return Traverse (N) = Abandon; |
| 26982 |
else |
| 26983 |
return False; |
| 26984 |
end if; |
| 26985 |
end References_Generic_Formal_Type; |
| 26986 |
|
| 26987 |
------------------------------- |
| 26988 |
-- Remove_Entity_And_Homonym -- |
| 26989 |
------------------------------- |
| 26990 |
|
| 26991 |
procedure Remove_Entity_And_Homonym (Id : Entity_Id) is |
| 26992 |
begin |
| 26993 |
Remove_Entity (Id); |
| 26994 |
Remove_Homonym (Id); |
| 26995 |
end Remove_Entity_And_Homonym; |
| 26996 |
|
| 26997 |
-------------------- |
| 26998 |
-- Remove_Homonym -- |
| 26999 |
-------------------- |
| 27000 |
|
| 27001 |
procedure Remove_Homonym (Id : Entity_Id) is |
| 27002 |
Hom : Entity_Id; |
| 27003 |
Prev : Entity_Id := Empty; |
| 27004 |
|
| 27005 |
begin |
| 27006 |
if Id = Current_Entity (Id) then |
| 27007 |
if Present (Homonym (Id)) then |
| 27008 |
Set_Current_Entity (Homonym (Id)); |
| 27009 |
else |
| 27010 |
Set_Name_Entity_Id (Chars (Id), Empty); |
| 27011 |
end if; |
| 27012 |
|
| 27013 |
else |
| 27014 |
Hom := Current_Entity (Id); |
| 27015 |
while Present (Hom) and then Hom /= Id loop |
| 27016 |
Prev := Hom; |
| 27017 |
Hom := Homonym (Hom); |
| 27018 |
end loop; |
| 27019 |
|
| 27020 |
-- If Id is not on the homonym chain, nothing to do |
| 27021 |
|
| 27022 |
if Present (Hom) then |
| 27023 |
Set_Homonym (Prev, Homonym (Id)); |
| 27024 |
end if; |
| 27025 |
end if; |
| 27026 |
end Remove_Homonym; |
| 27027 |
|
| 27028 |
------------------------------ |
| 27029 |
-- Remove_Overloaded_Entity -- |
| 27030 |
------------------------------ |
| 27031 |
|
| 27032 |
procedure Remove_Overloaded_Entity (Id : Entity_Id) is |
| 27033 |
procedure Remove_Primitive_Of (Typ : Entity_Id); |
| 27034 |
-- Remove primitive subprogram Id from the list of primitives that |
| 27035 |
-- belong to type Typ. |
| 27036 |
|
| 27037 |
------------------------- |
| 27038 |
-- Remove_Primitive_Of -- |
| 27039 |
------------------------- |
| 27040 |
|
| 27041 |
procedure Remove_Primitive_Of (Typ : Entity_Id) is |
| 27042 |
Prims : Elist_Id; |
| 27043 |
|
| 27044 |
begin |
| 27045 |
if Is_Tagged_Type (Typ) then |
| 27046 |
Prims := Direct_Primitive_Operations (Typ); |
| 27047 |
|
| 27048 |
if Present (Prims) then |
| 27049 |
Remove (Prims, Id); |
| 27050 |
end if; |
| 27051 |
end if; |
| 27052 |
end Remove_Primitive_Of; |
| 27053 |
|
| 27054 |
-- Local variables |
| 27055 |
|
| 27056 |
Formal : Entity_Id; |
| 27057 |
|
| 27058 |
-- Start of processing for Remove_Overloaded_Entity |
| 27059 |
|
| 27060 |
begin |
| 27061 |
Remove_Entity_And_Homonym (Id); |
| 27062 |
|
| 27063 |
-- The entity denotes a primitive subprogram. Remove it from the list of |
| 27064 |
-- primitives of the associated controlling type. |
| 27065 |
|
| 27066 |
if Ekind (Id) in E_Function | E_Procedure and then Is_Primitive (Id) then |
| 27067 |
Formal := First_Formal (Id); |
| 27068 |
while Present (Formal) loop |
| 27069 |
if Is_Controlling_Formal (Formal) then |
| 27070 |
Remove_Primitive_Of (Etype (Formal)); |
| 27071 |
exit; |
| 27072 |
end if; |
| 27073 |
|
| 27074 |
Next_Formal (Formal); |
| 27075 |
end loop; |
| 27076 |
|
| 27077 |
if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then |
| 27078 |
Remove_Primitive_Of (Etype (Id)); |
| 27079 |
end if; |
| 27080 |
end if; |
| 27081 |
end Remove_Overloaded_Entity; |
| 27082 |
|
| 27083 |
--------------------- |
| 27084 |
-- Rep_To_Pos_Flag -- |
| 27085 |
--------------------- |
| 27086 |
|
| 27087 |
function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is |
| 27088 |
begin |
| 27089 |
return New_Occurrence_Of |
| 27090 |
(Boolean_Literals (not Range_Checks_Suppressed (E)), Loc); |
| 27091 |
end Rep_To_Pos_Flag; |
| 27092 |
|
| 27093 |
-------------------- |
| 27094 |
-- Require_Entity -- |
| 27095 |
-------------------- |
| 27096 |
|
| 27097 |
procedure Require_Entity (N : Node_Id) is |
| 27098 |
begin |
| 27099 |
if Is_Entity_Name (N) and then No (Entity (N)) then |
| 27100 |
if Total_Errors_Detected /= 0 then |
| 27101 |
Set_Entity (N, Any_Id); |
| 27102 |
else |
| 27103 |
raise Program_Error; |
| 27104 |
end if; |
| 27105 |
end if; |
| 27106 |
end Require_Entity; |
| 27107 |
|
| 27108 |
------------------------------ |
| 27109 |
-- Requires_Transient_Scope -- |
| 27110 |
------------------------------ |
| 27111 |
|
| 27112 |
function Requires_Transient_Scope (Typ : Entity_Id) return Boolean is |
| 27113 |
begin |
| 27114 |
return Needs_Secondary_Stack (Typ) or else Needs_Finalization (Typ); |
| 27115 |
end Requires_Transient_Scope; |
| 27116 |
|
| 27117 |
-------------------------- |
| 27118 |
-- Reset_Analyzed_Flags -- |
| 27119 |
-------------------------- |
| 27120 |
|
| 27121 |
procedure Reset_Analyzed_Flags (N : Node_Id) is |
| 27122 |
function Clear_Analyzed (N : Node_Id) return Traverse_Result; |
| 27123 |
-- Function used to reset Analyzed flags in tree. Note that we do |
| 27124 |
-- not reset Analyzed flags in entities, since there is no need to |
| 27125 |
-- reanalyze entities, and indeed, it is wrong to do so, since it |
| 27126 |
-- can result in generating auxiliary stuff more than once. |
| 27127 |
|
| 27128 |
-------------------- |
| 27129 |
-- Clear_Analyzed -- |
| 27130 |
-------------------- |
| 27131 |
|
| 27132 |
function Clear_Analyzed (N : Node_Id) return Traverse_Result is |
| 27133 |
begin |
| 27134 |
if Nkind (N) not in N_Entity then |
| 27135 |
Set_Analyzed (N, False); |
| 27136 |
end if; |
| 27137 |
|
| 27138 |
return OK; |
| 27139 |
end Clear_Analyzed; |
| 27140 |
|
| 27141 |
procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed); |
| 27142 |
|
| 27143 |
-- Start of processing for Reset_Analyzed_Flags |
| 27144 |
|
| 27145 |
begin |
| 27146 |
Reset_Analyzed (N); |
| 27147 |
end Reset_Analyzed_Flags; |
| 27148 |
|
| 27149 |
------------------------ |
| 27150 |
-- Restore_SPARK_Mode -- |
| 27151 |
------------------------ |
| 27152 |
|
| 27153 |
procedure Restore_SPARK_Mode |
| 27154 |
(Mode : SPARK_Mode_Type; |
| 27155 |
Prag : Node_Id) |
| 27156 |
is |
| 27157 |
begin |
| 27158 |
SPARK_Mode := Mode; |
| 27159 |
SPARK_Mode_Pragma := Prag; |
| 27160 |
end Restore_SPARK_Mode; |
| 27161 |
|
| 27162 |
-------------------------------- |
| 27163 |
-- Returns_Unconstrained_Type -- |
| 27164 |
-------------------------------- |
| 27165 |
|
| 27166 |
function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is |
| 27167 |
begin |
| 27168 |
return Ekind (Subp) = E_Function |
| 27169 |
and then not Is_Scalar_Type (Etype (Subp)) |
| 27170 |
and then not Is_Access_Type (Etype (Subp)) |
| 27171 |
and then not Is_Constrained (Etype (Subp)); |
| 27172 |
end Returns_Unconstrained_Type; |
| 27173 |
|
| 27174 |
---------------------------- |
| 27175 |
-- Root_Type_Of_Full_View -- |
| 27176 |
---------------------------- |
| 27177 |
|
| 27178 |
function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is |
| 27179 |
Rtyp : constant Entity_Id := Root_Type (T); |
| 27180 |
|
| 27181 |
begin |
| 27182 |
-- The root type of the full view may itself be a private type. Keep |
| 27183 |
-- looking for the ultimate derivation parent. |
| 27184 |
|
| 27185 |
if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then |
| 27186 |
return Root_Type_Of_Full_View (Full_View (Rtyp)); |
| 27187 |
else |
| 27188 |
return Rtyp; |
| 27189 |
end if; |
| 27190 |
end Root_Type_Of_Full_View; |
| 27191 |
|
| 27192 |
--------------------------- |
| 27193 |
-- Safe_To_Capture_Value -- |
| 27194 |
--------------------------- |
| 27195 |
|
| 27196 |
function Safe_To_Capture_Value |
| 27197 |
(N : Node_Id; |
| 27198 |
Ent : Entity_Id; |
| 27199 |
Cond : Boolean := False) return Boolean |
| 27200 |
is |
| 27201 |
begin |
| 27202 |
-- The only entities for which we track constant values are variables |
| 27203 |
-- that are not renamings, constants and formal parameters, so check |
| 27204 |
-- if we have this case. |
| 27205 |
|
| 27206 |
-- Note: it may seem odd to track constant values for constants, but in |
| 27207 |
-- fact this routine is used for other purposes than simply capturing |
| 27208 |
-- the value. In particular, the setting of Known[_Non]_Null and |
| 27209 |
-- Is_Known_Valid. |
| 27210 |
|
| 27211 |
if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent))) |
| 27212 |
or else |
| 27213 |
Ekind (Ent) = E_Constant |
| 27214 |
or else |
| 27215 |
Is_Formal (Ent) |
| 27216 |
then |
| 27217 |
null; |
| 27218 |
|
| 27219 |
-- For conditionals, we also allow loop parameters |
| 27220 |
|
| 27221 |
elsif Cond and then Ekind (Ent) = E_Loop_Parameter then |
| 27222 |
null; |
| 27223 |
|
| 27224 |
-- For all other cases, not just unsafe, but impossible to capture |
| 27225 |
-- Current_Value, since the above are the only entities which have |
| 27226 |
-- Current_Value fields. |
| 27227 |
|
| 27228 |
else |
| 27229 |
return False; |
| 27230 |
end if; |
| 27231 |
|
| 27232 |
-- Skip if volatile or aliased, since funny things might be going on in |
| 27233 |
-- these cases which we cannot necessarily track. Also skip any variable |
| 27234 |
-- for which an address clause is given, or whose address is taken. Also |
| 27235 |
-- never capture value of library level variables (an attempt to do so |
| 27236 |
-- can occur in the case of package elaboration code). |
| 27237 |
|
| 27238 |
if Treat_As_Volatile (Ent) |
| 27239 |
or else Is_Aliased (Ent) |
| 27240 |
or else Present (Address_Clause (Ent)) |
| 27241 |
or else Address_Taken (Ent) |
| 27242 |
or else (Is_Library_Level_Entity (Ent) |
| 27243 |
and then Ekind (Ent) = E_Variable) |
| 27244 |
then |
| 27245 |
return False; |
| 27246 |
end if; |
| 27247 |
|
| 27248 |
-- OK, all above conditions are met. We also require that the scope of |
| 27249 |
-- the reference be the same as the scope of the entity, not counting |
| 27250 |
-- packages and blocks and loops. |
| 27251 |
|
| 27252 |
declare |
| 27253 |
E_Scope : constant Entity_Id := Scope (Ent); |
| 27254 |
R_Scope : Entity_Id; |
| 27255 |
|
| 27256 |
begin |
| 27257 |
R_Scope := Current_Scope; |
| 27258 |
while R_Scope /= Standard_Standard loop |
| 27259 |
exit when R_Scope = E_Scope; |
| 27260 |
|
| 27261 |
if Ekind (R_Scope) not in E_Package | E_Block | E_Loop then |
| 27262 |
return False; |
| 27263 |
else |
| 27264 |
R_Scope := Scope (R_Scope); |
| 27265 |
end if; |
| 27266 |
end loop; |
| 27267 |
end; |
| 27268 |
|
| 27269 |
-- We also require that the reference does not appear in a context |
| 27270 |
-- where it is not sure to be executed (i.e. a conditional context |
| 27271 |
-- or an exception handler). We skip this if Cond is True, since the |
| 27272 |
-- capturing of values from conditional tests handles this ok. |
| 27273 |
|
| 27274 |
if Cond or else No (N) then |
| 27275 |
return True; |
| 27276 |
end if; |
| 27277 |
|
| 27278 |
declare |
| 27279 |
Desc : Node_Id; |
| 27280 |
P : Node_Id; |
| 27281 |
|
| 27282 |
begin |
| 27283 |
Desc := N; |
| 27284 |
|
| 27285 |
-- Seems dubious that case expressions are not handled here ??? |
| 27286 |
|
| 27287 |
P := Parent (N); |
| 27288 |
while Present (P) loop |
| 27289 |
if Is_Body (P) then |
| 27290 |
return True; |
| 27291 |
|
| 27292 |
elsif Nkind (P) = N_If_Statement |
| 27293 |
or else Nkind (P) = N_Case_Statement |
| 27294 |
or else (Nkind (P) in N_Short_Circuit |
| 27295 |
and then Desc = Right_Opnd (P)) |
| 27296 |
or else (Nkind (P) = N_If_Expression |
| 27297 |
and then Desc /= First (Expressions (P))) |
| 27298 |
or else Nkind (P) = N_Exception_Handler |
| 27299 |
or else Nkind (P) = N_Selective_Accept |
| 27300 |
or else Nkind (P) = N_Conditional_Entry_Call |
| 27301 |
or else Nkind (P) = N_Timed_Entry_Call |
| 27302 |
or else Nkind (P) = N_Asynchronous_Select |
| 27303 |
then |
| 27304 |
return False; |
| 27305 |
|
| 27306 |
else |
| 27307 |
Desc := P; |
| 27308 |
P := Parent (P); |
| 27309 |
|
| 27310 |
-- A special Ada 2012 case: the original node may be part |
| 27311 |
-- of the else_actions of a conditional expression, in which |
| 27312 |
-- case it might not have been expanded yet, and appears in |
| 27313 |
-- a non-syntactic list of actions. In that case it is clearly |
| 27314 |
-- not safe to save a value. |
| 27315 |
|
| 27316 |
if No (P) |
| 27317 |
and then Is_List_Member (Desc) |
| 27318 |
and then No (Parent (List_Containing (Desc))) |
| 27319 |
then |
| 27320 |
return False; |
| 27321 |
end if; |
| 27322 |
end if; |
| 27323 |
end loop; |
| 27324 |
end; |
| 27325 |
|
| 27326 |
-- OK, looks safe to set value |
| 27327 |
|
| 27328 |
return True; |
| 27329 |
end Safe_To_Capture_Value; |
| 27330 |
|
| 27331 |
--------------- |
| 27332 |
-- Same_Name -- |
| 27333 |
--------------- |
| 27334 |
|
| 27335 |
function Same_Name (N1, N2 : Node_Id) return Boolean is |
| 27336 |
K1 : constant Node_Kind := Nkind (N1); |
| 27337 |
K2 : constant Node_Kind := Nkind (N2); |
| 27338 |
|
| 27339 |
begin |
| 27340 |
if K1 in N_Identifier | N_Defining_Identifier |
| 27341 |
and then K2 in N_Identifier | N_Defining_Identifier |
| 27342 |
then |
| 27343 |
return Chars (N1) = Chars (N2); |
| 27344 |
|
| 27345 |
elsif K1 in N_Selected_Component | N_Expanded_Name |
| 27346 |
and then K2 in N_Selected_Component | N_Expanded_Name |
| 27347 |
then |
| 27348 |
return Same_Name (Selector_Name (N1), Selector_Name (N2)) |
| 27349 |
and then Same_Name (Prefix (N1), Prefix (N2)); |
| 27350 |
|
| 27351 |
else |
| 27352 |
return False; |
| 27353 |
end if; |
| 27354 |
end Same_Name; |
| 27355 |
|
| 27356 |
----------------- |
| 27357 |
-- Same_Object -- |
| 27358 |
----------------- |
| 27359 |
|
| 27360 |
function Same_Object (Node1, Node2 : Node_Id) return Boolean is |
| 27361 |
N1 : constant Node_Id := Original_Node (Node1); |
| 27362 |
N2 : constant Node_Id := Original_Node (Node2); |
| 27363 |
-- We do the tests on original nodes, since we are most interested |
| 27364 |
-- in the original source, not any expansion that got in the way. |
| 27365 |
|
| 27366 |
K1 : constant Node_Kind := Nkind (N1); |
| 27367 |
K2 : constant Node_Kind := Nkind (N2); |
| 27368 |
|
| 27369 |
begin |
| 27370 |
-- First case, both are entities with same entity |
| 27371 |
|
| 27372 |
if K1 in N_Has_Entity and then K2 in N_Has_Entity then |
| 27373 |
declare |
| 27374 |
EN1 : constant Entity_Id := Entity (N1); |
| 27375 |
EN2 : constant Entity_Id := Entity (N2); |
| 27376 |
begin |
| 27377 |
if Present (EN1) and then Present (EN2) |
| 27378 |
and then (Ekind (EN1) in E_Variable | E_Constant |
| 27379 |
or else Is_Formal (EN1)) |
| 27380 |
and then EN1 = EN2 |
| 27381 |
then |
| 27382 |
return True; |
| 27383 |
end if; |
| 27384 |
end; |
| 27385 |
end if; |
| 27386 |
|
| 27387 |
-- Second case, selected component with same selector, same record |
| 27388 |
|
| 27389 |
if K1 = N_Selected_Component |
| 27390 |
and then K2 = N_Selected_Component |
| 27391 |
and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2)) |
| 27392 |
then |
| 27393 |
return Same_Object (Prefix (N1), Prefix (N2)); |
| 27394 |
|
| 27395 |
-- Third case, indexed component with same subscripts, same array |
| 27396 |
|
| 27397 |
elsif K1 = N_Indexed_Component |
| 27398 |
and then K2 = N_Indexed_Component |
| 27399 |
and then Same_Object (Prefix (N1), Prefix (N2)) |
| 27400 |
then |
| 27401 |
declare |
| 27402 |
E1, E2 : Node_Id; |
| 27403 |
begin |
| 27404 |
E1 := First (Expressions (N1)); |
| 27405 |
E2 := First (Expressions (N2)); |
| 27406 |
while Present (E1) loop |
| 27407 |
if not Same_Value (E1, E2) then |
| 27408 |
return False; |
| 27409 |
else |
| 27410 |
Next (E1); |
| 27411 |
Next (E2); |
| 27412 |
end if; |
| 27413 |
end loop; |
| 27414 |
|
| 27415 |
return True; |
| 27416 |
end; |
| 27417 |
|
| 27418 |
-- Fourth case, slice of same array with same bounds |
| 27419 |
|
| 27420 |
elsif K1 = N_Slice |
| 27421 |
and then K2 = N_Slice |
| 27422 |
and then Nkind (Discrete_Range (N1)) = N_Range |
| 27423 |
and then Nkind (Discrete_Range (N2)) = N_Range |
| 27424 |
and then Same_Value (Low_Bound (Discrete_Range (N1)), |
| 27425 |
Low_Bound (Discrete_Range (N2))) |
| 27426 |
and then Same_Value (High_Bound (Discrete_Range (N1)), |
| 27427 |
High_Bound (Discrete_Range (N2))) |
| 27428 |
then |
| 27429 |
return Same_Name (Prefix (N1), Prefix (N2)); |
| 27430 |
|
| 27431 |
-- All other cases, not clearly the same object |
| 27432 |
|
| 27433 |
else |
| 27434 |
return False; |
| 27435 |
end if; |
| 27436 |
end Same_Object; |
| 27437 |
|
| 27438 |
--------------------------------- |
| 27439 |
-- Same_Or_Aliased_Subprograms -- |
| 27440 |
--------------------------------- |
| 27441 |
|
| 27442 |
function Same_Or_Aliased_Subprograms |
| 27443 |
(S : Entity_Id; |
| 27444 |
E : Entity_Id) return Boolean |
| 27445 |
is |
| 27446 |
Subp_Alias : constant Entity_Id := Alias (S); |
| 27447 |
Subp : Entity_Id := E; |
| 27448 |
begin |
| 27449 |
-- During expansion of subprograms with postconditions the original |
| 27450 |
-- subprogram's declarations and statements get wrapped into a local |
| 27451 |
-- _Wrapped_Statements subprogram. |
| 27452 |
|
| 27453 |
if Chars (Subp) = Name_uWrapped_Statements then |
| 27454 |
Subp := Enclosing_Subprogram (Subp); |
| 27455 |
end if; |
| 27456 |
|
| 27457 |
return S = Subp |
| 27458 |
or else (Present (Subp_Alias) and then Subp_Alias = Subp); |
| 27459 |
end Same_Or_Aliased_Subprograms; |
| 27460 |
|
| 27461 |
--------------- |
| 27462 |
-- Same_Type -- |
| 27463 |
--------------- |
| 27464 |
|
| 27465 |
function Same_Type (T1, T2 : Entity_Id) return Boolean is |
| 27466 |
begin |
| 27467 |
if T1 = T2 then |
| 27468 |
return True; |
| 27469 |
|
| 27470 |
elsif not Is_Constrained (T1) |
| 27471 |
and then not Is_Constrained (T2) |
| 27472 |
and then Base_Type (T1) = Base_Type (T2) |
| 27473 |
then |
| 27474 |
return True; |
| 27475 |
|
| 27476 |
-- For now don't bother with case of identical constraints, to be |
| 27477 |
-- fiddled with later on perhaps (this is only used for optimization |
| 27478 |
-- purposes, so it is not critical to do a best possible job) |
| 27479 |
|
| 27480 |
else |
| 27481 |
return False; |
| 27482 |
end if; |
| 27483 |
end Same_Type; |
| 27484 |
|
| 27485 |
---------------- |
| 27486 |
-- Same_Value -- |
| 27487 |
---------------- |
| 27488 |
|
| 27489 |
function Same_Value (Node1, Node2 : Node_Id) return Boolean is |
| 27490 |
begin |
| 27491 |
if Compile_Time_Known_Value (Node1) |
| 27492 |
and then Compile_Time_Known_Value (Node2) |
| 27493 |
then |
| 27494 |
-- Handle properly compile-time expressions that are not |
| 27495 |
-- scalar. |
| 27496 |
|
| 27497 |
if Is_String_Type (Etype (Node1)) then |
| 27498 |
return Expr_Value_S (Node1) = Expr_Value_S (Node2); |
| 27499 |
|
| 27500 |
else |
| 27501 |
return Expr_Value (Node1) = Expr_Value (Node2); |
| 27502 |
end if; |
| 27503 |
|
| 27504 |
elsif Same_Object (Node1, Node2) then |
| 27505 |
return True; |
| 27506 |
else |
| 27507 |
return False; |
| 27508 |
end if; |
| 27509 |
end Same_Value; |
| 27510 |
|
| 27511 |
-------------------- |
| 27512 |
-- Set_SPARK_Mode -- |
| 27513 |
-------------------- |
| 27514 |
|
| 27515 |
procedure Set_SPARK_Mode (Context : Entity_Id) is |
| 27516 |
begin |
| 27517 |
-- Do not consider illegal or partially decorated constructs |
| 27518 |
|
| 27519 |
if Ekind (Context) = E_Void or else Error_Posted (Context) then |
| 27520 |
null; |
| 27521 |
|
| 27522 |
elsif Present (SPARK_Pragma (Context)) then |
| 27523 |
Install_SPARK_Mode |
| 27524 |
(Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)), |
| 27525 |
Prag => SPARK_Pragma (Context)); |
| 27526 |
end if; |
| 27527 |
end Set_SPARK_Mode; |
| 27528 |
|
| 27529 |
------------------------- |
| 27530 |
-- Scalar_Part_Present -- |
| 27531 |
------------------------- |
| 27532 |
|
| 27533 |
function Scalar_Part_Present (Typ : Entity_Id) return Boolean is |
| 27534 |
Val_Typ : constant Entity_Id := Validated_View (Typ); |
| 27535 |
Field : Entity_Id; |
| 27536 |
|
| 27537 |
begin |
| 27538 |
if Is_Scalar_Type (Val_Typ) then |
| 27539 |
return True; |
| 27540 |
|
| 27541 |
elsif Is_Array_Type (Val_Typ) then |
| 27542 |
return Scalar_Part_Present (Component_Type (Val_Typ)); |
| 27543 |
|
| 27544 |
elsif Is_Record_Type (Val_Typ) then |
| 27545 |
Field := First_Component_Or_Discriminant (Val_Typ); |
| 27546 |
while Present (Field) loop |
| 27547 |
if Scalar_Part_Present (Etype (Field)) then |
| 27548 |
return True; |
| 27549 |
end if; |
| 27550 |
|
| 27551 |
Next_Component_Or_Discriminant (Field); |
| 27552 |
end loop; |
| 27553 |
end if; |
| 27554 |
|
| 27555 |
return False; |
| 27556 |
end Scalar_Part_Present; |
| 27557 |
|
| 27558 |
------------------------ |
| 27559 |
-- Scope_Is_Transient -- |
| 27560 |
------------------------ |
| 27561 |
|
| 27562 |
function Scope_Is_Transient return Boolean is |
| 27563 |
begin |
| 27564 |
return Scope_Stack.Table (Scope_Stack.Last).Is_Transient; |
| 27565 |
end Scope_Is_Transient; |
| 27566 |
|
| 27567 |
------------------ |
| 27568 |
-- Scope_Within -- |
| 27569 |
------------------ |
| 27570 |
|
| 27571 |
function Scope_Within |
| 27572 |
(Inner : Entity_Id; |
| 27573 |
Outer : Entity_Id) return Boolean |
| 27574 |
is |
| 27575 |
Curr : Entity_Id; |
| 27576 |
|
| 27577 |
begin |
| 27578 |
Curr := Inner; |
| 27579 |
while Present (Curr) and then Curr /= Standard_Standard loop |
| 27580 |
Curr := Scope (Curr); |
| 27581 |
|
| 27582 |
if Curr = Outer then |
| 27583 |
return True; |
| 27584 |
|
| 27585 |
-- A selective accept body appears within a task type, but the |
| 27586 |
-- enclosing subprogram is the procedure of the task body. |
| 27587 |
|
| 27588 |
elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type |
| 27589 |
and then |
| 27590 |
Outer = Task_Body_Procedure (Implementation_Base_Type (Curr)) |
| 27591 |
then |
| 27592 |
return True; |
| 27593 |
|
| 27594 |
-- Ditto for the body of a protected operation |
| 27595 |
|
| 27596 |
elsif Is_Subprogram (Curr) |
| 27597 |
and then Outer = Protected_Body_Subprogram (Curr) |
| 27598 |
then |
| 27599 |
return True; |
| 27600 |
|
| 27601 |
-- The body of a protected operation is within the protected type |
| 27602 |
|
| 27603 |
elsif Is_Subprogram (Curr) |
| 27604 |
and then Present (Protected_Subprogram (Curr)) |
| 27605 |
and then Is_Protected_Type (Outer) |
| 27606 |
and then Scope (Protected_Subprogram (Curr)) = Outer |
| 27607 |
then |
| 27608 |
return True; |
| 27609 |
|
| 27610 |
-- Outside of its scope, a synchronized type may just be private |
| 27611 |
|
| 27612 |
elsif Is_Private_Type (Curr) |
| 27613 |
and then Present (Full_View (Curr)) |
| 27614 |
and then Is_Concurrent_Type (Full_View (Curr)) |
| 27615 |
then |
| 27616 |
return Scope_Within (Full_View (Curr), Outer); |
| 27617 |
end if; |
| 27618 |
end loop; |
| 27619 |
|
| 27620 |
return False; |
| 27621 |
end Scope_Within; |
| 27622 |
|
| 27623 |
-------------------------- |
| 27624 |
-- Scope_Within_Or_Same -- |
| 27625 |
-------------------------- |
| 27626 |
|
| 27627 |
function Scope_Within_Or_Same |
| 27628 |
(Inner : Entity_Id; |
| 27629 |
Outer : Entity_Id) return Boolean |
| 27630 |
is |
| 27631 |
Curr : Entity_Id := Inner; |
| 27632 |
|
| 27633 |
begin |
| 27634 |
-- Similar to the above, but check for scope identity first |
| 27635 |
|
| 27636 |
while Present (Curr) and then Curr /= Standard_Standard loop |
| 27637 |
if Curr = Outer then |
| 27638 |
return True; |
| 27639 |
|
| 27640 |
elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type |
| 27641 |
and then |
| 27642 |
Outer = Task_Body_Procedure (Implementation_Base_Type (Curr)) |
| 27643 |
then |
| 27644 |
return True; |
| 27645 |
|
| 27646 |
elsif Is_Subprogram (Curr) |
| 27647 |
and then Outer = Protected_Body_Subprogram (Curr) |
| 27648 |
then |
| 27649 |
return True; |
| 27650 |
|
| 27651 |
elsif Is_Subprogram (Curr) |
| 27652 |
and then Present (Protected_Subprogram (Curr)) |
| 27653 |
and then Is_Protected_Type (Outer) |
| 27654 |
and then Scope (Protected_Subprogram (Curr)) = Outer |
| 27655 |
then |
| 27656 |
return True; |
| 27657 |
|
| 27658 |
elsif Is_Private_Type (Curr) |
| 27659 |
and then Present (Full_View (Curr)) |
| 27660 |
then |
| 27661 |
if Full_View (Curr) = Outer then |
| 27662 |
return True; |
| 27663 |
else |
| 27664 |
return Scope_Within (Full_View (Curr), Outer); |
| 27665 |
end if; |
| 27666 |
end if; |
| 27667 |
|
| 27668 |
Curr := Scope (Curr); |
| 27669 |
end loop; |
| 27670 |
|
| 27671 |
return False; |
| 27672 |
end Scope_Within_Or_Same; |
| 27673 |
|
| 27674 |
------------------------ |
| 27675 |
-- Set_Current_Entity -- |
| 27676 |
------------------------ |
| 27677 |
|
| 27678 |
-- The given entity is to be set as the currently visible definition of its |
| 27679 |
-- associated name (i.e. the Node_Id associated with its name). All we have |
| 27680 |
-- to do is to get the name from the identifier, and then set the |
| 27681 |
-- associated Node_Id to point to the given entity. |
| 27682 |
|
| 27683 |
procedure Set_Current_Entity (E : Entity_Id) is |
| 27684 |
begin |
| 27685 |
Set_Name_Entity_Id (Chars (E), E); |
| 27686 |
end Set_Current_Entity; |
| 27687 |
|
| 27688 |
--------------------------- |
| 27689 |
-- Set_Debug_Info_Needed -- |
| 27690 |
--------------------------- |
| 27691 |
|
| 27692 |
procedure Set_Debug_Info_Needed (T : Entity_Id) is |
| 27693 |
|
| 27694 |
procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id); |
| 27695 |
pragma Inline (Set_Debug_Info_Needed_If_Not_Set); |
| 27696 |
-- Used to set debug info in a related node if not set already |
| 27697 |
|
| 27698 |
-------------------------------------- |
| 27699 |
-- Set_Debug_Info_Needed_If_Not_Set -- |
| 27700 |
-------------------------------------- |
| 27701 |
|
| 27702 |
procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is |
| 27703 |
begin |
| 27704 |
if Present (E) and then not Needs_Debug_Info (E) then |
| 27705 |
Set_Debug_Info_Needed (E); |
| 27706 |
|
| 27707 |
-- For a private type, indicate that the full view also needs |
| 27708 |
-- debug information. |
| 27709 |
|
| 27710 |
if Is_Type (E) |
| 27711 |
and then Is_Private_Type (E) |
| 27712 |
and then Present (Full_View (E)) |
| 27713 |
then |
| 27714 |
Set_Debug_Info_Needed (Full_View (E)); |
| 27715 |
end if; |
| 27716 |
end if; |
| 27717 |
end Set_Debug_Info_Needed_If_Not_Set; |
| 27718 |
|
| 27719 |
-- Start of processing for Set_Debug_Info_Needed |
| 27720 |
|
| 27721 |
begin |
| 27722 |
-- Nothing to do if there is no available entity |
| 27723 |
|
| 27724 |
if No (T) then |
| 27725 |
return; |
| 27726 |
|
| 27727 |
-- Nothing to do for an entity with suppressed debug information |
| 27728 |
|
| 27729 |
elsif Debug_Info_Off (T) then |
| 27730 |
return; |
| 27731 |
|
| 27732 |
-- Nothing to do for an ignored Ghost entity because the entity will be |
| 27733 |
-- eliminated from the tree. |
| 27734 |
|
| 27735 |
elsif Is_Ignored_Ghost_Entity (T) then |
| 27736 |
return; |
| 27737 |
|
| 27738 |
-- Nothing to do if entity comes from a predefined file. Library files |
| 27739 |
-- are compiled without debug information, but inlined bodies of these |
| 27740 |
-- routines may appear in user code, and debug information on them ends |
| 27741 |
-- up complicating debugging the user code. |
| 27742 |
|
| 27743 |
elsif In_Inlined_Body and then In_Predefined_Unit (T) then |
| 27744 |
Set_Needs_Debug_Info (T, False); |
| 27745 |
end if; |
| 27746 |
|
| 27747 |
-- Set flag in entity itself. Note that we will go through the following |
| 27748 |
-- circuitry even if the flag is already set on T. That's intentional, |
| 27749 |
-- it makes sure that the flag will be set in subsidiary entities. |
| 27750 |
|
| 27751 |
Set_Needs_Debug_Info (T); |
| 27752 |
|
| 27753 |
-- Set flag on subsidiary entities if not set already |
| 27754 |
|
| 27755 |
if Is_Object (T) then |
| 27756 |
Set_Debug_Info_Needed_If_Not_Set (Etype (T)); |
| 27757 |
|
| 27758 |
elsif Is_Type (T) then |
| 27759 |
Set_Debug_Info_Needed_If_Not_Set (Etype (T)); |
| 27760 |
|
| 27761 |
if Is_Record_Type (T) then |
| 27762 |
declare |
| 27763 |
Ent : Entity_Id := First_Entity (T); |
| 27764 |
begin |
| 27765 |
while Present (Ent) loop |
| 27766 |
Set_Debug_Info_Needed_If_Not_Set (Ent); |
| 27767 |
Next_Entity (Ent); |
| 27768 |
end loop; |
| 27769 |
end; |
| 27770 |
|
| 27771 |
-- For a class wide subtype, we also need debug information |
| 27772 |
-- for the equivalent type. |
| 27773 |
|
| 27774 |
if Ekind (T) = E_Class_Wide_Subtype then |
| 27775 |
Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T)); |
| 27776 |
end if; |
| 27777 |
|
| 27778 |
elsif Is_Array_Type (T) then |
| 27779 |
Set_Debug_Info_Needed_If_Not_Set (Component_Type (T)); |
| 27780 |
|
| 27781 |
declare |
| 27782 |
Indx : Node_Id := First_Index (T); |
| 27783 |
begin |
| 27784 |
while Present (Indx) loop |
| 27785 |
Set_Debug_Info_Needed_If_Not_Set (Etype (Indx)); |
| 27786 |
Next_Index (Indx); |
| 27787 |
end loop; |
| 27788 |
end; |
| 27789 |
|
| 27790 |
-- For a packed array type, we also need debug information for |
| 27791 |
-- the type used to represent the packed array. Conversely, we |
| 27792 |
-- also need it for the former if we need it for the latter. |
| 27793 |
|
| 27794 |
if Is_Packed (T) then |
| 27795 |
Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T)); |
| 27796 |
end if; |
| 27797 |
|
| 27798 |
if Is_Packed_Array_Impl_Type (T) then |
| 27799 |
Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T)); |
| 27800 |
end if; |
| 27801 |
|
| 27802 |
elsif Is_Access_Type (T) then |
| 27803 |
Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T)); |
| 27804 |
|
| 27805 |
elsif Is_Private_Type (T) then |
| 27806 |
declare |
| 27807 |
FV : constant Entity_Id := Full_View (T); |
| 27808 |
|
| 27809 |
begin |
| 27810 |
Set_Debug_Info_Needed_If_Not_Set (FV); |
| 27811 |
|
| 27812 |
-- If the full view is itself a derived private type, we need |
| 27813 |
-- debug information on its underlying type. |
| 27814 |
|
| 27815 |
if Present (FV) |
| 27816 |
and then Is_Private_Type (FV) |
| 27817 |
and then Present (Underlying_Full_View (FV)) |
| 27818 |
then |
| 27819 |
Set_Needs_Debug_Info (Underlying_Full_View (FV)); |
| 27820 |
end if; |
| 27821 |
end; |
| 27822 |
|
| 27823 |
elsif Is_Protected_Type (T) then |
| 27824 |
Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T)); |
| 27825 |
|
| 27826 |
elsif Is_Scalar_Type (T) then |
| 27827 |
|
| 27828 |
-- If the subrange bounds are materialized by dedicated constant |
| 27829 |
-- objects, also include them in the debug info to make sure the |
| 27830 |
-- debugger can properly use them. |
| 27831 |
|
| 27832 |
if Present (Scalar_Range (T)) |
| 27833 |
and then Nkind (Scalar_Range (T)) = N_Range |
| 27834 |
then |
| 27835 |
declare |
| 27836 |
Low_Bnd : constant Node_Id := Type_Low_Bound (T); |
| 27837 |
High_Bnd : constant Node_Id := Type_High_Bound (T); |
| 27838 |
|
| 27839 |
begin |
| 27840 |
if Is_Entity_Name (Low_Bnd) then |
| 27841 |
Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd)); |
| 27842 |
end if; |
| 27843 |
|
| 27844 |
if Is_Entity_Name (High_Bnd) then |
| 27845 |
Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd)); |
| 27846 |
end if; |
| 27847 |
end; |
| 27848 |
end if; |
| 27849 |
end if; |
| 27850 |
end if; |
| 27851 |
end Set_Debug_Info_Needed; |
| 27852 |
|
| 27853 |
-------------------------------- |
| 27854 |
-- Set_Debug_Info_Defining_Id -- |
| 27855 |
-------------------------------- |
| 27856 |
|
| 27857 |
procedure Set_Debug_Info_Defining_Id (N : Node_Id) is |
| 27858 |
begin |
| 27859 |
if Comes_From_Source (Defining_Identifier (N)) |
| 27860 |
or else Debug_Generated_Code |
| 27861 |
then |
| 27862 |
Set_Debug_Info_Needed (Defining_Identifier (N)); |
| 27863 |
end if; |
| 27864 |
end Set_Debug_Info_Defining_Id; |
| 27865 |
|
| 27866 |
---------------------------- |
| 27867 |
-- Set_Entity_With_Checks -- |
| 27868 |
---------------------------- |
| 27869 |
|
| 27870 |
procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is |
| 27871 |
Val_Actual : Entity_Id; |
| 27872 |
Nod : Node_Id; |
| 27873 |
Post_Node : Node_Id; |
| 27874 |
|
| 27875 |
begin |
| 27876 |
-- Unconditionally set the entity |
| 27877 |
|
| 27878 |
Set_Entity (N, Val); |
| 27879 |
|
| 27880 |
-- The node to post on is the selector in the case of an expanded name, |
| 27881 |
-- and otherwise the node itself. |
| 27882 |
|
| 27883 |
if Nkind (N) = N_Expanded_Name then |
| 27884 |
Post_Node := Selector_Name (N); |
| 27885 |
else |
| 27886 |
Post_Node := N; |
| 27887 |
end if; |
| 27888 |
|
| 27889 |
-- Check for violation of No_Fixed_IO |
| 27890 |
|
| 27891 |
if Restriction_Check_Required (No_Fixed_IO) |
| 27892 |
and then |
| 27893 |
((RTU_Loaded (Ada_Text_IO) |
| 27894 |
and then (Is_RTE (Val, RE_Decimal_IO) |
| 27895 |
or else |
| 27896 |
Is_RTE (Val, RE_Fixed_IO))) |
| 27897 |
|
| 27898 |
or else |
| 27899 |
(RTU_Loaded (Ada_Wide_Text_IO) |
| 27900 |
and then (Is_RTE (Val, RO_WT_Decimal_IO) |
| 27901 |
or else |
| 27902 |
Is_RTE (Val, RO_WT_Fixed_IO))) |
| 27903 |
|
| 27904 |
or else |
| 27905 |
(RTU_Loaded (Ada_Wide_Wide_Text_IO) |
| 27906 |
and then (Is_RTE (Val, RO_WW_Decimal_IO) |
| 27907 |
or else |
| 27908 |
Is_RTE (Val, RO_WW_Fixed_IO)))) |
| 27909 |
|
| 27910 |
-- A special extra check, don't complain about a reference from within |
| 27911 |
-- the Ada.Interrupts package itself! |
| 27912 |
|
| 27913 |
and then not In_Same_Extended_Unit (N, Val) |
| 27914 |
then |
| 27915 |
Check_Restriction (No_Fixed_IO, Post_Node); |
| 27916 |
end if; |
| 27917 |
|
| 27918 |
-- Remaining checks are only done on source nodes. Note that we test |
| 27919 |
-- for violation of No_Fixed_IO even on non-source nodes, because the |
| 27920 |
-- cases for checking violations of this restriction are instantiations |
| 27921 |
-- where the reference in the instance has Comes_From_Source False. |
| 27922 |
|
| 27923 |
if not Comes_From_Source (N) then |
| 27924 |
return; |
| 27925 |
end if; |
| 27926 |
|
| 27927 |
-- Check for violation of No_Abort_Statements, which is triggered by |
| 27928 |
-- call to Ada.Task_Identification.Abort_Task. |
| 27929 |
|
| 27930 |
if Restriction_Check_Required (No_Abort_Statements) |
| 27931 |
and then Is_RTE (Val, RE_Abort_Task) |
| 27932 |
|
| 27933 |
-- A special extra check, don't complain about a reference from within |
| 27934 |
-- the Ada.Task_Identification package itself! |
| 27935 |
|
| 27936 |
and then not In_Same_Extended_Unit (N, Val) |
| 27937 |
then |
| 27938 |
Check_Restriction (No_Abort_Statements, Post_Node); |
| 27939 |
end if; |
| 27940 |
|
| 27941 |
if Val = Standard_Long_Long_Integer then |
| 27942 |
Check_Restriction (No_Long_Long_Integers, Post_Node); |
| 27943 |
end if; |
| 27944 |
|
| 27945 |
-- Check for violation of No_Dynamic_Attachment |
| 27946 |
|
| 27947 |
if Restriction_Check_Required (No_Dynamic_Attachment) |
| 27948 |
and then RTU_Loaded (Ada_Interrupts) |
| 27949 |
and then (Is_RTE (Val, RE_Is_Reserved) or else |
| 27950 |
Is_RTE (Val, RE_Is_Attached) or else |
| 27951 |
Is_RTE (Val, RE_Current_Handler) or else |
| 27952 |
Is_RTE (Val, RE_Attach_Handler) or else |
| 27953 |
Is_RTE (Val, RE_Exchange_Handler) or else |
| 27954 |
Is_RTE (Val, RE_Detach_Handler) or else |
| 27955 |
Is_RTE (Val, RE_Reference)) |
| 27956 |
|
| 27957 |
-- A special extra check, don't complain about a reference from within |
| 27958 |
-- the Ada.Interrupts package itself! |
| 27959 |
|
| 27960 |
and then not In_Same_Extended_Unit (N, Val) |
| 27961 |
then |
| 27962 |
Check_Restriction (No_Dynamic_Attachment, Post_Node); |
| 27963 |
end if; |
| 27964 |
|
| 27965 |
-- Check for No_Implementation_Identifiers |
| 27966 |
|
| 27967 |
if Restriction_Check_Required (No_Implementation_Identifiers) then |
| 27968 |
|
| 27969 |
-- We have an implementation defined entity if it is marked as |
| 27970 |
-- implementation defined, or is defined in a package marked as |
| 27971 |
-- implementation defined. However, library packages themselves |
| 27972 |
-- are excluded (we don't want to flag Interfaces itself, just |
| 27973 |
-- the entities within it). |
| 27974 |
|
| 27975 |
if (Is_Implementation_Defined (Val) |
| 27976 |
or else |
| 27977 |
(Present (Scope (Val)) |
| 27978 |
and then Is_Implementation_Defined (Scope (Val)))) |
| 27979 |
and then not (Is_Package_Or_Generic_Package (Val) |
| 27980 |
and then Is_Library_Level_Entity (Val)) |
| 27981 |
then |
| 27982 |
Check_Restriction (No_Implementation_Identifiers, Post_Node); |
| 27983 |
end if; |
| 27984 |
end if; |
| 27985 |
|
| 27986 |
-- Do the style check |
| 27987 |
|
| 27988 |
if Style_Check |
| 27989 |
and then not Suppress_Style_Checks (Val) |
| 27990 |
and then not In_Instance |
| 27991 |
then |
| 27992 |
if Nkind (N) = N_Identifier then |
| 27993 |
Nod := N; |
| 27994 |
elsif Nkind (N) = N_Expanded_Name then |
| 27995 |
Nod := Selector_Name (N); |
| 27996 |
else |
| 27997 |
return; |
| 27998 |
end if; |
| 27999 |
|
| 28000 |
-- A special situation arises for derived operations, where we want |
| 28001 |
-- to do the check against the parent (since the Sloc of the derived |
| 28002 |
-- operation points to the derived type declaration itself). |
| 28003 |
|
| 28004 |
Val_Actual := Val; |
| 28005 |
while not Comes_From_Source (Val_Actual) |
| 28006 |
and then Nkind (Val_Actual) in N_Entity |
| 28007 |
and then (Ekind (Val_Actual) = E_Enumeration_Literal |
| 28008 |
or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual)) |
| 28009 |
and then Present (Alias (Val_Actual)) |
| 28010 |
loop |
| 28011 |
Val_Actual := Alias (Val_Actual); |
| 28012 |
end loop; |
| 28013 |
|
| 28014 |
-- Renaming declarations for generic actuals do not come from source, |
| 28015 |
-- and have a different name from that of the entity they rename, so |
| 28016 |
-- there is no style check to perform here. |
| 28017 |
|
| 28018 |
if Chars (Nod) = Chars (Val_Actual) then |
| 28019 |
Style.Check_Identifier (Nod, Val_Actual); |
| 28020 |
end if; |
| 28021 |
end if; |
| 28022 |
end Set_Entity_With_Checks; |
| 28023 |
|
| 28024 |
------------------------------ |
| 28025 |
-- Set_Invalid_Scalar_Value -- |
| 28026 |
------------------------------ |
| 28027 |
|
| 28028 |
procedure Set_Invalid_Scalar_Value |
| 28029 |
(Scal_Typ : Float_Scalar_Id; |
| 28030 |
Value : Ureal) |
| 28031 |
is |
| 28032 |
Slot : Ureal renames Invalid_Floats (Scal_Typ); |
| 28033 |
|
| 28034 |
begin |
| 28035 |
-- Detect an attempt to set a different value for the same scalar type |
| 28036 |
|
| 28037 |
pragma Assert (Slot = No_Ureal); |
| 28038 |
Slot := Value; |
| 28039 |
end Set_Invalid_Scalar_Value; |
| 28040 |
|
| 28041 |
------------------------------ |
| 28042 |
-- Set_Invalid_Scalar_Value -- |
| 28043 |
------------------------------ |
| 28044 |
|
| 28045 |
procedure Set_Invalid_Scalar_Value |
| 28046 |
(Scal_Typ : Integer_Scalar_Id; |
| 28047 |
Value : Uint) |
| 28048 |
is |
| 28049 |
Slot : Uint renames Invalid_Integers (Scal_Typ); |
| 28050 |
|
| 28051 |
begin |
| 28052 |
-- Detect an attempt to set a different value for the same scalar type |
| 28053 |
|
| 28054 |
pragma Assert (No (Slot)); |
| 28055 |
Slot := Value; |
| 28056 |
end Set_Invalid_Scalar_Value; |
| 28057 |
|
| 28058 |
------------------------ |
| 28059 |
-- Set_Name_Entity_Id -- |
| 28060 |
------------------------ |
| 28061 |
|
| 28062 |
procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is |
| 28063 |
begin |
| 28064 |
Set_Name_Table_Int (Id, Int (Val)); |
| 28065 |
end Set_Name_Entity_Id; |
| 28066 |
|
| 28067 |
--------------------- |
| 28068 |
-- Set_Next_Actual -- |
| 28069 |
--------------------- |
| 28070 |
|
| 28071 |
procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is |
| 28072 |
begin |
| 28073 |
if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then |
| 28074 |
Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id); |
| 28075 |
end if; |
| 28076 |
end Set_Next_Actual; |
| 28077 |
|
| 28078 |
---------------------------------- |
| 28079 |
-- Set_Optimize_Alignment_Flags -- |
| 28080 |
---------------------------------- |
| 28081 |
|
| 28082 |
procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is |
| 28083 |
begin |
| 28084 |
if Optimize_Alignment = 'S' then |
| 28085 |
Set_Optimize_Alignment_Space (E); |
| 28086 |
elsif Optimize_Alignment = 'T' then |
| 28087 |
Set_Optimize_Alignment_Time (E); |
| 28088 |
end if; |
| 28089 |
end Set_Optimize_Alignment_Flags; |
| 28090 |
|
| 28091 |
----------------------- |
| 28092 |
-- Set_Public_Status -- |
| 28093 |
----------------------- |
| 28094 |
|
| 28095 |
procedure Set_Public_Status (Id : Entity_Id) is |
| 28096 |
S : constant Entity_Id := Current_Scope; |
| 28097 |
|
| 28098 |
function Within_HSS_Or_If (E : Entity_Id) return Boolean; |
| 28099 |
-- Determines if E is defined within handled statement sequence or |
| 28100 |
-- an if statement, returns True if so, False otherwise. |
| 28101 |
|
| 28102 |
---------------------- |
| 28103 |
-- Within_HSS_Or_If -- |
| 28104 |
---------------------- |
| 28105 |
|
| 28106 |
function Within_HSS_Or_If (E : Entity_Id) return Boolean is |
| 28107 |
N : Node_Id; |
| 28108 |
begin |
| 28109 |
N := Declaration_Node (E); |
| 28110 |
loop |
| 28111 |
N := Parent (N); |
| 28112 |
|
| 28113 |
if No (N) then |
| 28114 |
return False; |
| 28115 |
|
| 28116 |
elsif Nkind (N) in |
| 28117 |
N_Handled_Sequence_Of_Statements | N_If_Statement |
| 28118 |
then |
| 28119 |
return True; |
| 28120 |
end if; |
| 28121 |
end loop; |
| 28122 |
end Within_HSS_Or_If; |
| 28123 |
|
| 28124 |
-- Start of processing for Set_Public_Status |
| 28125 |
|
| 28126 |
begin |
| 28127 |
-- Everything in the scope of Standard is public |
| 28128 |
|
| 28129 |
if S = Standard_Standard then |
| 28130 |
Set_Is_Public (Id); |
| 28131 |
|
| 28132 |
-- Entity is definitely not public if enclosing scope is not public |
| 28133 |
|
| 28134 |
elsif not Is_Public (S) then |
| 28135 |
return; |
| 28136 |
|
| 28137 |
-- An object or function declaration that occurs in a handled sequence |
| 28138 |
-- of statements or within an if statement is the declaration for a |
| 28139 |
-- temporary object or local subprogram generated by the expander. It |
| 28140 |
-- never needs to be made public and furthermore, making it public can |
| 28141 |
-- cause back end problems. |
| 28142 |
|
| 28143 |
elsif Nkind (Parent (Id)) in |
| 28144 |
N_Object_Declaration | N_Function_Specification |
| 28145 |
and then Within_HSS_Or_If (Id) |
| 28146 |
then |
| 28147 |
return; |
| 28148 |
|
| 28149 |
-- Entities in public packages or records are public |
| 28150 |
|
| 28151 |
elsif Ekind (S) = E_Package or Is_Record_Type (S) then |
| 28152 |
Set_Is_Public (Id); |
| 28153 |
|
| 28154 |
-- The bounds of an entry family declaration can generate object |
| 28155 |
-- declarations that are visible to the back-end, e.g. in the |
| 28156 |
-- the declaration of a composite type that contains tasks. |
| 28157 |
|
| 28158 |
elsif Is_Concurrent_Type (S) |
| 28159 |
and then not Has_Completion (S) |
| 28160 |
and then Nkind (Parent (Id)) = N_Object_Declaration |
| 28161 |
then |
| 28162 |
Set_Is_Public (Id); |
| 28163 |
end if; |
| 28164 |
end Set_Public_Status; |
| 28165 |
|
| 28166 |
----------------------------- |
| 28167 |
-- Set_Referenced_Modified -- |
| 28168 |
----------------------------- |
| 28169 |
|
| 28170 |
procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is |
| 28171 |
Pref : Node_Id; |
| 28172 |
|
| 28173 |
begin |
| 28174 |
-- Deal with indexed components, selected components, or slices where |
| 28175 |
-- the prefix is modified. |
| 28176 |
|
| 28177 |
if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then |
| 28178 |
|
| 28179 |
-- Grab the original node to avoid looking at internally generated |
| 28180 |
-- objects. |
| 28181 |
|
| 28182 |
Pref := Original_Node (Prefix (N)); |
| 28183 |
|
| 28184 |
-- If prefix is access type, then it is the designated object that is |
| 28185 |
-- being modified, which means we have no entity to set the flag on. |
| 28186 |
|
| 28187 |
if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then |
| 28188 |
return; |
| 28189 |
|
| 28190 |
-- Otherwise chase the prefix |
| 28191 |
|
| 28192 |
else |
| 28193 |
Set_Referenced_Modified (Pref, Out_Param); |
| 28194 |
end if; |
| 28195 |
|
| 28196 |
-- Otherwise see if we have an entity name (only other case to process) |
| 28197 |
|
| 28198 |
elsif Is_Entity_Name (N) and then Present (Entity (N)) then |
| 28199 |
Set_Referenced_As_LHS (Entity (N), not Out_Param); |
| 28200 |
Set_Referenced_As_Out_Parameter (Entity (N), Out_Param); |
| 28201 |
end if; |
| 28202 |
end Set_Referenced_Modified; |
| 28203 |
|
| 28204 |
------------------ |
| 28205 |
-- Set_Rep_Info -- |
| 28206 |
------------------ |
| 28207 |
|
| 28208 |
procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is |
| 28209 |
begin |
| 28210 |
Set_Is_Atomic (T1, Is_Atomic (T2)); |
| 28211 |
Set_Is_Independent (T1, Is_Independent (T2)); |
| 28212 |
Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2)); |
| 28213 |
|
| 28214 |
if Is_Base_Type (T1) then |
| 28215 |
Set_Is_Volatile (T1, Is_Volatile (T2)); |
| 28216 |
end if; |
| 28217 |
end Set_Rep_Info; |
| 28218 |
|
| 28219 |
------------------- |
| 28220 |
-- Set_Size_Info -- |
| 28221 |
------------------- |
| 28222 |
|
| 28223 |
procedure Set_Size_Info (T1, T2 : Entity_Id) is |
| 28224 |
begin |
| 28225 |
-- We copy Esize, but not RM_Size, since in general RM_Size is |
| 28226 |
-- subtype specific and does not get inherited by all subtypes. |
| 28227 |
|
| 28228 |
Copy_Esize (To => T1, From => T2); |
| 28229 |
Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2)); |
| 28230 |
|
| 28231 |
if Is_Discrete_Or_Fixed_Point_Type (T1) |
| 28232 |
and then |
| 28233 |
Is_Discrete_Or_Fixed_Point_Type (T2) |
| 28234 |
then |
| 28235 |
Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2)); |
| 28236 |
end if; |
| 28237 |
|
| 28238 |
Copy_Alignment (To => T1, From => T2); |
| 28239 |
end Set_Size_Info; |
| 28240 |
|
| 28241 |
------------------------------ |
| 28242 |
-- Should_Ignore_Pragma_Par -- |
| 28243 |
------------------------------ |
| 28244 |
|
| 28245 |
function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is |
| 28246 |
pragma Assert (Compiler_State = Parsing); |
| 28247 |
-- This one can't work during semantic analysis, because we don't have a |
| 28248 |
-- correct Current_Source_File. |
| 28249 |
|
| 28250 |
Result : constant Boolean := |
| 28251 |
Get_Name_Table_Boolean3 (Prag_Name) |
| 28252 |
and then not Is_Internal_File_Name |
| 28253 |
(File_Name (Current_Source_File)); |
| 28254 |
begin |
| 28255 |
return Result; |
| 28256 |
end Should_Ignore_Pragma_Par; |
| 28257 |
|
| 28258 |
------------------------------ |
| 28259 |
-- Should_Ignore_Pragma_Sem -- |
| 28260 |
------------------------------ |
| 28261 |
|
| 28262 |
function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is |
| 28263 |
pragma Assert (Compiler_State = Analyzing); |
| 28264 |
Prag_Name : constant Name_Id := Pragma_Name (N); |
| 28265 |
Result : constant Boolean := |
| 28266 |
Get_Name_Table_Boolean3 (Prag_Name) |
| 28267 |
and then not In_Internal_Unit (N); |
| 28268 |
|
| 28269 |
begin |
| 28270 |
return Result; |
| 28271 |
end Should_Ignore_Pragma_Sem; |
| 28272 |
|
| 28273 |
-------------------- |
| 28274 |
-- Static_Boolean -- |
| 28275 |
-------------------- |
| 28276 |
|
| 28277 |
function Static_Boolean (N : Node_Id) return Opt_Ubool is |
| 28278 |
begin |
| 28279 |
Analyze_And_Resolve (N, Standard_Boolean); |
| 28280 |
|
| 28281 |
if N = Error |
| 28282 |
or else Error_Posted (N) |
| 28283 |
or else Etype (N) = Any_Type |
| 28284 |
then |
| 28285 |
return No_Uint; |
| 28286 |
end if; |
| 28287 |
|
| 28288 |
if Is_OK_Static_Expression (N) then |
| 28289 |
return Expr_Value (N); |
| 28290 |
|
| 28291 |
elsif Etype (N) = Any_Type then |
| 28292 |
return No_Uint; |
| 28293 |
|
| 28294 |
else |
| 28295 |
Flag_Non_Static_Expr |
| 28296 |
("static boolean expression required here", N); |
| 28297 |
return No_Uint; |
| 28298 |
end if; |
| 28299 |
end Static_Boolean; |
| 28300 |
|
| 28301 |
-------------------- |
| 28302 |
-- Static_Integer -- |
| 28303 |
-------------------- |
| 28304 |
|
| 28305 |
function Static_Integer (N : Node_Id) return Uint is |
| 28306 |
begin |
| 28307 |
Analyze_And_Resolve (N, Any_Integer); |
| 28308 |
|
| 28309 |
if N = Error |
| 28310 |
or else Error_Posted (N) |
| 28311 |
or else Etype (N) = Any_Type |
| 28312 |
then |
| 28313 |
return No_Uint; |
| 28314 |
end if; |
| 28315 |
|
| 28316 |
if Is_OK_Static_Expression (N) then |
| 28317 |
return Expr_Value (N); |
| 28318 |
|
| 28319 |
elsif Etype (N) = Any_Type then |
| 28320 |
return No_Uint; |
| 28321 |
|
| 28322 |
else |
| 28323 |
Flag_Non_Static_Expr |
| 28324 |
("static integer expression required here", N); |
| 28325 |
return No_Uint; |
| 28326 |
end if; |
| 28327 |
end Static_Integer; |
| 28328 |
|
| 28329 |
------------------------------- |
| 28330 |
-- Statically_Denotes_Entity -- |
| 28331 |
------------------------------- |
| 28332 |
|
| 28333 |
function Statically_Denotes_Entity (N : Node_Id) return Boolean is |
| 28334 |
E : Entity_Id; |
| 28335 |
begin |
| 28336 |
if not Is_Entity_Name (N) then |
| 28337 |
return False; |
| 28338 |
else |
| 28339 |
E := Entity (N); |
| 28340 |
end if; |
| 28341 |
|
| 28342 |
return |
| 28343 |
Nkind (Parent (E)) /= N_Object_Renaming_Declaration |
| 28344 |
or else Is_Prival (E) |
| 28345 |
or else Statically_Denotes_Entity (Renamed_Object (E)); |
| 28346 |
end Statically_Denotes_Entity; |
| 28347 |
|
| 28348 |
------------------------------- |
| 28349 |
-- Statically_Denotes_Object -- |
| 28350 |
------------------------------- |
| 28351 |
|
| 28352 |
function Statically_Denotes_Object (N : Node_Id) return Boolean is |
| 28353 |
begin |
| 28354 |
return Statically_Denotes_Entity (N) |
| 28355 |
and then Is_Object_Reference (N); |
| 28356 |
end Statically_Denotes_Object; |
| 28357 |
|
| 28358 |
-------------------------- |
| 28359 |
-- Statically_Different -- |
| 28360 |
-------------------------- |
| 28361 |
|
| 28362 |
function Statically_Different (E1, E2 : Node_Id) return Boolean is |
| 28363 |
R1 : constant Node_Id := Get_Referenced_Object (E1); |
| 28364 |
R2 : constant Node_Id := Get_Referenced_Object (E2); |
| 28365 |
begin |
| 28366 |
-- Two identifiers are statically different if they denote different |
| 28367 |
-- entities that are not formal parameters. |
| 28368 |
|
| 28369 |
if Is_Entity_Name (R1) and then Is_Entity_Name (R2) then |
| 28370 |
return Entity (R1) /= Entity (R2) |
| 28371 |
and then not Is_Formal (Entity (R1)) |
| 28372 |
and then not Is_Formal (Entity (R2)); |
| 28373 |
|
| 28374 |
-- A function call that does not return its result by reference denotes |
| 28375 |
-- a constant object that is statically different from anything else. |
| 28376 |
|
| 28377 |
elsif (Nkind (R1) = N_Function_Call |
| 28378 |
and then Is_Entity_Name (Name (R1)) |
| 28379 |
and then not Returns_By_Ref (Entity (Name (R1)))) |
| 28380 |
or else (Nkind (R2) = N_Function_Call |
| 28381 |
and then Is_Entity_Name (Name (R2)) |
| 28382 |
and then not Returns_By_Ref (Entity (Name (R2)))) |
| 28383 |
then |
| 28384 |
return R1 /= R2; |
| 28385 |
|
| 28386 |
else |
| 28387 |
return False; |
| 28388 |
end if; |
| 28389 |
end Statically_Different; |
| 28390 |
|
| 28391 |
----------------------------- |
| 28392 |
-- Statically_Names_Object -- |
| 28393 |
----------------------------- |
| 28394 |
|
| 28395 |
function Statically_Names_Object (N : Node_Id) return Boolean is |
| 28396 |
begin |
| 28397 |
if Statically_Denotes_Object (N) then |
| 28398 |
return True; |
| 28399 |
elsif Is_Entity_Name (N) then |
| 28400 |
declare |
| 28401 |
E : constant Entity_Id := Entity (N); |
| 28402 |
begin |
| 28403 |
return Nkind (Parent (E)) = N_Object_Renaming_Declaration |
| 28404 |
and then Statically_Names_Object (Renamed_Object (E)); |
| 28405 |
end; |
| 28406 |
end if; |
| 28407 |
|
| 28408 |
case Nkind (N) is |
| 28409 |
when N_Indexed_Component => |
| 28410 |
if Is_Access_Type (Etype (Prefix (N))) then |
| 28411 |
-- treat implicit dereference same as explicit |
| 28412 |
return False; |
| 28413 |
end if; |
| 28414 |
|
| 28415 |
if not Is_Constrained (Etype (Prefix (N))) then |
| 28416 |
return False; |
| 28417 |
end if; |
| 28418 |
|
| 28419 |
declare |
| 28420 |
Indx : Node_Id := First_Index (Etype (Prefix (N))); |
| 28421 |
Expr : Node_Id := First (Expressions (N)); |
| 28422 |
Index_Subtype : Node_Id; |
| 28423 |
begin |
| 28424 |
loop |
| 28425 |
Index_Subtype := Etype (Indx); |
| 28426 |
|
| 28427 |
if not Is_Static_Subtype (Index_Subtype) then |
| 28428 |
return False; |
| 28429 |
end if; |
| 28430 |
if not Is_OK_Static_Expression (Expr) then |
| 28431 |
return False; |
| 28432 |
end if; |
| 28433 |
|
| 28434 |
declare |
| 28435 |
Index_Value : constant Uint := Expr_Value (Expr); |
| 28436 |
Low_Value : constant Uint := |
| 28437 |
Expr_Value (Type_Low_Bound (Index_Subtype)); |
| 28438 |
High_Value : constant Uint := |
| 28439 |
Expr_Value (Type_High_Bound (Index_Subtype)); |
| 28440 |
begin |
| 28441 |
if Index_Value < Low_Value |
| 28442 |
or Index_Value > High_Value |
| 28443 |
then |
| 28444 |
return False; |
| 28445 |
end if; |
| 28446 |
end; |
| 28447 |
|
| 28448 |
Next_Index (Indx); |
| 28449 |
Expr := Next (Expr); |
| 28450 |
pragma Assert (Present (Indx) = Present (Expr) |
| 28451 |
or else Serious_Errors_Detected > 0); |
| 28452 |
exit when not (Present (Indx) and Present (Expr)); |
| 28453 |
end loop; |
| 28454 |
end; |
| 28455 |
|
| 28456 |
when N_Selected_Component => |
| 28457 |
if Is_Access_Type (Etype (Prefix (N))) then |
| 28458 |
-- treat implicit dereference same as explicit |
| 28459 |
return False; |
| 28460 |
end if; |
| 28461 |
|
| 28462 |
if Ekind (Entity (Selector_Name (N))) not in |
| 28463 |
E_Component | E_Discriminant |
| 28464 |
then |
| 28465 |
return False; |
| 28466 |
end if; |
| 28467 |
|
| 28468 |
declare |
| 28469 |
Comp : constant Entity_Id := |
| 28470 |
Original_Record_Component (Entity (Selector_Name (N))); |
| 28471 |
begin |
| 28472 |
-- AI12-0373 confirms that we should not call |
| 28473 |
-- Has_Discriminant_Dependent_Constraint here which would be |
| 28474 |
-- too strong. |
| 28475 |
|
| 28476 |
if Is_Declared_Within_Variant (Comp) then |
| 28477 |
return False; |
| 28478 |
end if; |
| 28479 |
end; |
| 28480 |
|
| 28481 |
when others => -- includes N_Slice, N_Explicit_Dereference |
| 28482 |
return False; |
| 28483 |
end case; |
| 28484 |
|
| 28485 |
pragma Assert (Present (Prefix (N))); |
| 28486 |
|
| 28487 |
return Statically_Names_Object (Prefix (N)); |
| 28488 |
end Statically_Names_Object; |
| 28489 |
|
| 28490 |
--------------------------------- |
| 28491 |
-- String_From_Numeric_Literal -- |
| 28492 |
--------------------------------- |
| 28493 |
|
| 28494 |
function String_From_Numeric_Literal (N : Node_Id) return String_Id is |
| 28495 |
Loc : constant Source_Ptr := Sloc (N); |
| 28496 |
Sbuffer : constant Source_Buffer_Ptr := |
| 28497 |
Source_Text (Get_Source_File_Index (Loc)); |
| 28498 |
Src_Ptr : Source_Ptr := Loc; |
| 28499 |
|
| 28500 |
C : Character := Sbuffer (Src_Ptr); |
| 28501 |
-- Current source program character |
| 28502 |
|
| 28503 |
function Belongs_To_Numeric_Literal (C : Character) return Boolean; |
| 28504 |
-- Return True if C belongs to the numeric literal |
| 28505 |
|
| 28506 |
-------------------------------- |
| 28507 |
-- Belongs_To_Numeric_Literal -- |
| 28508 |
-------------------------------- |
| 28509 |
|
| 28510 |
function Belongs_To_Numeric_Literal (C : Character) return Boolean is |
| 28511 |
begin |
| 28512 |
case C is |
| 28513 |
when '0' .. '9' | '_' | '.' | 'e' | '#' | 'A' .. 'F' => |
| 28514 |
return True; |
| 28515 |
|
| 28516 |
-- Make sure '+' or '-' is part of an exponent |
| 28517 |
|
| 28518 |
when '+' | '-' => |
| 28519 |
declare |
| 28520 |
Prev_C : constant Character := Sbuffer (Src_Ptr - 1); |
| 28521 |
begin |
| 28522 |
return Prev_C in 'e' | 'E'; |
| 28523 |
end; |
| 28524 |
|
| 28525 |
-- Other characters cannot belong to a numeric literal |
| 28526 |
|
| 28527 |
when others => |
| 28528 |
return False; |
| 28529 |
end case; |
| 28530 |
end Belongs_To_Numeric_Literal; |
| 28531 |
|
| 28532 |
-- Start of processing for String_From_Numeric_Literal |
| 28533 |
|
| 28534 |
begin |
| 28535 |
Start_String; |
| 28536 |
while Belongs_To_Numeric_Literal (C) loop |
| 28537 |
Store_String_Char (C); |
| 28538 |
Src_Ptr := Src_Ptr + 1; |
| 28539 |
C := Sbuffer (Src_Ptr); |
| 28540 |
end loop; |
| 28541 |
|
| 28542 |
return End_String; |
| 28543 |
end String_From_Numeric_Literal; |
| 28544 |
|
| 28545 |
-------------------------------------- |
| 28546 |
-- Subject_To_Loop_Entry_Attributes -- |
| 28547 |
-------------------------------------- |
| 28548 |
|
| 28549 |
function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is |
| 28550 |
Stmt : Node_Id; |
| 28551 |
|
| 28552 |
begin |
| 28553 |
Stmt := N; |
| 28554 |
|
| 28555 |
-- The expansion mechanism transform a loop subject to at least one |
| 28556 |
-- 'Loop_Entry attribute into a conditional block. Infinite loops lack |
| 28557 |
-- the conditional part. |
| 28558 |
|
| 28559 |
if Nkind (Stmt) in N_Block_Statement | N_If_Statement |
| 28560 |
and then Nkind (Original_Node (N)) = N_Loop_Statement |
| 28561 |
then |
| 28562 |
Stmt := Original_Node (N); |
| 28563 |
end if; |
| 28564 |
|
| 28565 |
return |
| 28566 |
Nkind (Stmt) = N_Loop_Statement |
| 28567 |
and then Present (Identifier (Stmt)) |
| 28568 |
and then Present (Entity (Identifier (Stmt))) |
| 28569 |
and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt))); |
| 28570 |
end Subject_To_Loop_Entry_Attributes; |
| 28571 |
|
| 28572 |
------------------------------- |
| 28573 |
-- Support_Atomic_Primitives -- |
| 28574 |
------------------------------- |
| 28575 |
|
| 28576 |
function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is |
| 28577 |
Size : Int; |
| 28578 |
|
| 28579 |
begin |
| 28580 |
-- Verify the alignment of Typ is known |
| 28581 |
|
| 28582 |
if not Known_Alignment (Typ) then |
| 28583 |
return False; |
| 28584 |
end if; |
| 28585 |
|
| 28586 |
if Known_Static_Esize (Typ) then |
| 28587 |
Size := UI_To_Int (Esize (Typ)); |
| 28588 |
|
| 28589 |
-- If the Esize (Object_Size) is unknown at compile time, look at the |
| 28590 |
-- RM_Size (Value_Size) which may have been set by an explicit rep item. |
| 28591 |
|
| 28592 |
elsif Known_Static_RM_Size (Typ) then |
| 28593 |
Size := UI_To_Int (RM_Size (Typ)); |
| 28594 |
|
| 28595 |
-- Otherwise, the size is considered to be unknown. |
| 28596 |
|
| 28597 |
else |
| 28598 |
return False; |
| 28599 |
end if; |
| 28600 |
|
| 28601 |
-- Check that the size of the component is 8, 16, 32, or 64 bits and |
| 28602 |
-- that Typ is properly aligned. |
| 28603 |
|
| 28604 |
case Size is |
| 28605 |
when 8 | 16 | 32 | 64 => |
| 28606 |
return Size = UI_To_Int (Alignment (Typ)) * 8; |
| 28607 |
|
| 28608 |
when others => |
| 28609 |
return False; |
| 28610 |
end case; |
| 28611 |
end Support_Atomic_Primitives; |
| 28612 |
|
| 28613 |
----------------- |
| 28614 |
-- Trace_Scope -- |
| 28615 |
----------------- |
| 28616 |
|
| 28617 |
procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is |
| 28618 |
begin |
| 28619 |
if Debug_Flag_W then |
| 28620 |
for J in 0 .. Scope_Stack.Last loop |
| 28621 |
Write_Str (" "); |
| 28622 |
end loop; |
| 28623 |
|
| 28624 |
Write_Str (Msg); |
| 28625 |
Write_Name (Chars (E)); |
| 28626 |
Write_Str (" from "); |
| 28627 |
Write_Location (Sloc (N)); |
| 28628 |
Write_Eol; |
| 28629 |
end if; |
| 28630 |
end Trace_Scope; |
| 28631 |
|
| 28632 |
----------------------- |
| 28633 |
-- Transfer_Entities -- |
| 28634 |
----------------------- |
| 28635 |
|
| 28636 |
procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is |
| 28637 |
procedure Set_Public_Status_Of (Id : Entity_Id); |
| 28638 |
-- Set the Is_Public attribute of arbitrary entity Id by calling routine |
| 28639 |
-- Set_Public_Status. If successful and Id denotes a record type, set |
| 28640 |
-- the Is_Public attribute of its fields. |
| 28641 |
|
| 28642 |
-------------------------- |
| 28643 |
-- Set_Public_Status_Of -- |
| 28644 |
-------------------------- |
| 28645 |
|
| 28646 |
procedure Set_Public_Status_Of (Id : Entity_Id) is |
| 28647 |
Field : Entity_Id; |
| 28648 |
|
| 28649 |
begin |
| 28650 |
if not Is_Public (Id) then |
| 28651 |
Set_Public_Status (Id); |
| 28652 |
|
| 28653 |
-- When the input entity is a public record type, ensure that all |
| 28654 |
-- its internal fields are also exposed to the linker. The fields |
| 28655 |
-- of a class-wide type are never made public. |
| 28656 |
|
| 28657 |
if Is_Public (Id) |
| 28658 |
and then Is_Record_Type (Id) |
| 28659 |
and then not Is_Class_Wide_Type (Id) |
| 28660 |
then |
| 28661 |
Field := First_Entity (Id); |
| 28662 |
while Present (Field) loop |
| 28663 |
Set_Is_Public (Field); |
| 28664 |
Next_Entity (Field); |
| 28665 |
end loop; |
| 28666 |
end if; |
| 28667 |
end if; |
| 28668 |
end Set_Public_Status_Of; |
| 28669 |
|
| 28670 |
-- Local variables |
| 28671 |
|
| 28672 |
Full_Id : Entity_Id; |
| 28673 |
Id : Entity_Id; |
| 28674 |
|
| 28675 |
-- Start of processing for Transfer_Entities |
| 28676 |
|
| 28677 |
begin |
| 28678 |
Id := First_Entity (From); |
| 28679 |
|
| 28680 |
if Present (Id) then |
| 28681 |
|
| 28682 |
-- Merge the entity chain of the source scope with that of the |
| 28683 |
-- destination scope. |
| 28684 |
|
| 28685 |
if Present (Last_Entity (To)) then |
| 28686 |
Link_Entities (Last_Entity (To), Id); |
| 28687 |
else |
| 28688 |
Set_First_Entity (To, Id); |
| 28689 |
end if; |
| 28690 |
|
| 28691 |
Set_Last_Entity (To, Last_Entity (From)); |
| 28692 |
|
| 28693 |
-- Inspect the entities of the source scope and update their Scope |
| 28694 |
-- attribute. |
| 28695 |
|
| 28696 |
while Present (Id) loop |
| 28697 |
Set_Scope (Id, To); |
| 28698 |
Set_Public_Status_Of (Id); |
| 28699 |
|
| 28700 |
-- Handle an internally generated full view for a private type |
| 28701 |
|
| 28702 |
if Is_Private_Type (Id) |
| 28703 |
and then Present (Full_View (Id)) |
| 28704 |
and then Is_Itype (Full_View (Id)) |
| 28705 |
then |
| 28706 |
Full_Id := Full_View (Id); |
| 28707 |
|
| 28708 |
Set_Scope (Full_Id, To); |
| 28709 |
Set_Public_Status_Of (Full_Id); |
| 28710 |
end if; |
| 28711 |
|
| 28712 |
Next_Entity (Id); |
| 28713 |
end loop; |
| 28714 |
|
| 28715 |
Set_First_Entity (From, Empty); |
| 28716 |
Set_Last_Entity (From, Empty); |
| 28717 |
end if; |
| 28718 |
end Transfer_Entities; |
| 28719 |
|
| 28720 |
------------------------ |
| 28721 |
-- Traverse_More_Func -- |
| 28722 |
------------------------ |
| 28723 |
|
| 28724 |
function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is |
| 28725 |
|
| 28726 |
Processing_Itype : Boolean := False; |
| 28727 |
-- Set to True while traversing the nodes under an Itype, to prevent |
| 28728 |
-- looping on Itype handling during that traversal. |
| 28729 |
|
| 28730 |
function Process_More (N : Node_Id) return Traverse_Result; |
| 28731 |
-- Wrapper over the Process callback to handle parts of the AST that |
| 28732 |
-- are not normally traversed as syntactic children. |
| 28733 |
|
| 28734 |
function Traverse_Rec (N : Node_Id) return Traverse_Final_Result; |
| 28735 |
-- Main recursive traversal implemented as an instantiation of |
| 28736 |
-- Traverse_Func over a modified Process callback. |
| 28737 |
|
| 28738 |
------------------ |
| 28739 |
-- Process_More -- |
| 28740 |
------------------ |
| 28741 |
|
| 28742 |
function Process_More (N : Node_Id) return Traverse_Result is |
| 28743 |
|
| 28744 |
procedure Traverse_More (N : Node_Id; |
| 28745 |
Res : in out Traverse_Result); |
| 28746 |
procedure Traverse_More (L : List_Id; |
| 28747 |
Res : in out Traverse_Result); |
| 28748 |
-- Traverse a node or list and update the traversal result to value |
| 28749 |
-- Abandon when needed. |
| 28750 |
|
| 28751 |
------------------- |
| 28752 |
-- Traverse_More -- |
| 28753 |
------------------- |
| 28754 |
|
| 28755 |
procedure Traverse_More (N : Node_Id; |
| 28756 |
Res : in out Traverse_Result) |
| 28757 |
is |
| 28758 |
begin |
| 28759 |
-- Do not process any more nodes if Abandon was reached |
| 28760 |
|
| 28761 |
if Res = Abandon then |
| 28762 |
return; |
| 28763 |
end if; |
| 28764 |
|
| 28765 |
if Traverse_Rec (N) = Abandon then |
| 28766 |
Res := Abandon; |
| 28767 |
end if; |
| 28768 |
end Traverse_More; |
| 28769 |
|
| 28770 |
procedure Traverse_More (L : List_Id; |
| 28771 |
Res : in out Traverse_Result) |
| 28772 |
is |
| 28773 |
N : Node_Id := First (L); |
| 28774 |
|
| 28775 |
begin |
| 28776 |
-- Do not process any more nodes if Abandon was reached |
| 28777 |
|
| 28778 |
if Res = Abandon then |
| 28779 |
return; |
| 28780 |
end if; |
| 28781 |
|
| 28782 |
while Present (N) loop |
| 28783 |
Traverse_More (N, Res); |
| 28784 |
Next (N); |
| 28785 |
end loop; |
| 28786 |
end Traverse_More; |
| 28787 |
|
| 28788 |
-- Local variables |
| 28789 |
|
| 28790 |
Node : Node_Id; |
| 28791 |
Result : Traverse_Result; |
| 28792 |
|
| 28793 |
-- Start of processing for Process_More |
| 28794 |
|
| 28795 |
begin |
| 28796 |
-- Initial callback to Process. Return immediately on Skip/Abandon. |
| 28797 |
-- Otherwise update the value of Node for further processing of |
| 28798 |
-- non-syntactic children. |
| 28799 |
|
| 28800 |
Result := Process (N); |
| 28801 |
|
| 28802 |
case Result is |
| 28803 |
when OK => Node := N; |
| 28804 |
when OK_Orig => Node := Original_Node (N); |
| 28805 |
when Skip => return Skip; |
| 28806 |
when Abandon => return Abandon; |
| 28807 |
end case; |
| 28808 |
|
| 28809 |
-- Process the relevant semantic children which are a logical part of |
| 28810 |
-- the AST under this node before returning for the processing of |
| 28811 |
-- syntactic children. |
| 28812 |
|
| 28813 |
-- Start with all non-syntactic lists of action nodes |
| 28814 |
|
| 28815 |
case Nkind (Node) is |
| 28816 |
when N_Component_Association => |
| 28817 |
Traverse_More (Loop_Actions (Node), Result); |
| 28818 |
|
| 28819 |
when N_Elsif_Part => |
| 28820 |
Traverse_More (Condition_Actions (Node), Result); |
| 28821 |
|
| 28822 |
when N_Short_Circuit => |
| 28823 |
Traverse_More (Actions (Node), Result); |
| 28824 |
|
| 28825 |
when N_Case_Expression_Alternative => |
| 28826 |
Traverse_More (Actions (Node), Result); |
| 28827 |
|
| 28828 |
when N_Iterated_Component_Association => |
| 28829 |
Traverse_More (Loop_Actions (Node), Result); |
| 28830 |
|
| 28831 |
when N_Iterated_Element_Association => |
| 28832 |
Traverse_More (Loop_Actions (Node), Result); |
| 28833 |
|
| 28834 |
when N_Iteration_Scheme => |
| 28835 |
Traverse_More (Condition_Actions (Node), Result); |
| 28836 |
|
| 28837 |
when N_If_Expression => |
| 28838 |
Traverse_More (Then_Actions (Node), Result); |
| 28839 |
Traverse_More (Else_Actions (Node), Result); |
| 28840 |
|
| 28841 |
-- Various nodes have a field Actions as a syntactic node, |
| 28842 |
-- so it will be traversed in the regular syntactic traversal. |
| 28843 |
|
| 28844 |
when N_Compilation_Unit_Aux |
| 28845 |
| N_Compound_Statement |
| 28846 |
| N_Expression_With_Actions |
| 28847 |
| N_Freeze_Entity |
| 28848 |
=> |
| 28849 |
null; |
| 28850 |
|
| 28851 |
when others => |
| 28852 |
null; |
| 28853 |
end case; |
| 28854 |
|
| 28855 |
-- If Process_Itypes is True, process unattached nodes which come |
| 28856 |
-- from Itypes. This only concerns currently ranges of scalar |
| 28857 |
-- (possibly as index) types. This traversal is protected against |
| 28858 |
-- looping with Processing_Itype. |
| 28859 |
|
| 28860 |
if Process_Itypes |
| 28861 |
and then not Processing_Itype |
| 28862 |
and then Nkind (Node) in N_Has_Etype |
| 28863 |
and then Present (Etype (Node)) |
| 28864 |
and then Is_Itype (Etype (Node)) |
| 28865 |
then |
| 28866 |
declare |
| 28867 |
Typ : constant Entity_Id := Etype (Node); |
| 28868 |
begin |
| 28869 |
Processing_Itype := True; |
| 28870 |
|
| 28871 |
case Ekind (Typ) is |
| 28872 |
when Scalar_Kind => |
| 28873 |
Traverse_More (Scalar_Range (Typ), Result); |
| 28874 |
|
| 28875 |
when Array_Kind => |
| 28876 |
declare |
| 28877 |
Index : Node_Id := First_Index (Typ); |
| 28878 |
Rng : Node_Id; |
| 28879 |
begin |
| 28880 |
while Present (Index) loop |
| 28881 |
if Nkind (Index) in N_Has_Entity then |
| 28882 |
Rng := Scalar_Range (Entity (Index)); |
| 28883 |
else |
| 28884 |
Rng := Index; |
| 28885 |
end if; |
| 28886 |
|
| 28887 |
Traverse_More (Rng, Result); |
| 28888 |
Next_Index (Index); |
| 28889 |
end loop; |
| 28890 |
end; |
| 28891 |
when others => |
| 28892 |
null; |
| 28893 |
end case; |
| 28894 |
|
| 28895 |
Processing_Itype := False; |
| 28896 |
end; |
| 28897 |
end if; |
| 28898 |
|
| 28899 |
return Result; |
| 28900 |
end Process_More; |
| 28901 |
|
| 28902 |
-- Define Traverse_Rec as a renaming of the instantiation, as an |
| 28903 |
-- instantiation cannot complete a previous spec. |
| 28904 |
|
| 28905 |
function Traverse_Recursive is new Traverse_Func (Process_More); |
| 28906 |
function Traverse_Rec (N : Node_Id) return Traverse_Final_Result |
| 28907 |
renames Traverse_Recursive; |
| 28908 |
|
| 28909 |
-- Start of processing for Traverse_More_Func |
| 28910 |
|
| 28911 |
begin |
| 28912 |
return Traverse_Rec (Node); |
| 28913 |
end Traverse_More_Func; |
| 28914 |
|
| 28915 |
------------------------ |
| 28916 |
-- Traverse_More_Proc -- |
| 28917 |
------------------------ |
| 28918 |
|
| 28919 |
procedure Traverse_More_Proc (Node : Node_Id) is |
| 28920 |
function Traverse is new Traverse_More_Func (Process, Process_Itypes); |
| 28921 |
Discard : Traverse_Final_Result; |
| 28922 |
pragma Warnings (Off, Discard); |
| 28923 |
begin |
| 28924 |
Discard := Traverse (Node); |
| 28925 |
end Traverse_More_Proc; |
| 28926 |
|
| 28927 |
------------------------------------ |
| 28928 |
-- Type_Without_Stream_Operation -- |
| 28929 |
------------------------------------ |
| 28930 |
|
| 28931 |
function Type_Without_Stream_Operation |
| 28932 |
(T : Entity_Id; |
| 28933 |
Op : TSS_Name_Type := TSS_Null) return Entity_Id |
| 28934 |
is |
| 28935 |
BT : constant Entity_Id := Base_Type (T); |
| 28936 |
Op_Missing : Boolean; |
| 28937 |
|
| 28938 |
begin |
| 28939 |
if Is_Elementary_Type (T) then |
| 28940 |
if Op = TSS_Null then |
| 28941 |
Op_Missing := |
| 28942 |
No (TSS (BT, TSS_Stream_Read)) |
| 28943 |
or else No (TSS (BT, TSS_Stream_Write)); |
| 28944 |
|
| 28945 |
else |
| 28946 |
Op_Missing := No (TSS (BT, Op)); |
| 28947 |
end if; |
| 28948 |
|
| 28949 |
if Op_Missing then |
| 28950 |
return T; |
| 28951 |
else |
| 28952 |
return Empty; |
| 28953 |
end if; |
| 28954 |
|
| 28955 |
elsif Is_Array_Type (T) then |
| 28956 |
return Type_Without_Stream_Operation (Component_Type (T), Op); |
| 28957 |
|
| 28958 |
elsif Is_Record_Type (T) then |
| 28959 |
declare |
| 28960 |
Comp : Entity_Id; |
| 28961 |
C_Typ : Entity_Id; |
| 28962 |
|
| 28963 |
begin |
| 28964 |
Comp := First_Component (T); |
| 28965 |
while Present (Comp) loop |
| 28966 |
C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op); |
| 28967 |
|
| 28968 |
if Present (C_Typ) then |
| 28969 |
return C_Typ; |
| 28970 |
end if; |
| 28971 |
|
| 28972 |
Next_Component (Comp); |
| 28973 |
end loop; |
| 28974 |
|
| 28975 |
return Empty; |
| 28976 |
end; |
| 28977 |
|
| 28978 |
elsif Is_Private_Type (T) and then Present (Full_View (T)) then |
| 28979 |
return Type_Without_Stream_Operation (Full_View (T), Op); |
| 28980 |
else |
| 28981 |
return Empty; |
| 28982 |
end if; |
| 28983 |
end Type_Without_Stream_Operation; |
| 28984 |
|
| 28985 |
------------------------------ |
| 28986 |
-- Ultimate_Overlaid_Entity -- |
| 28987 |
------------------------------ |
| 28988 |
|
| 28989 |
function Ultimate_Overlaid_Entity (E : Entity_Id) return Entity_Id is |
| 28990 |
Address : Node_Id; |
| 28991 |
Alias : Entity_Id := E; |
| 28992 |
Offset : Boolean; |
| 28993 |
|
| 28994 |
begin |
| 28995 |
-- Currently this routine is only called for stand-alone objects that |
| 28996 |
-- have been analysed, since the analysis of the Address aspect is often |
| 28997 |
-- delayed. |
| 28998 |
|
| 28999 |
pragma Assert (Ekind (E) in E_Constant | E_Variable); |
| 29000 |
|
| 29001 |
loop |
| 29002 |
Address := Address_Clause (Alias); |
| 29003 |
if Present (Address) then |
| 29004 |
Find_Overlaid_Entity (Address, Alias, Offset); |
| 29005 |
if Present (Alias) then |
| 29006 |
null; |
| 29007 |
else |
| 29008 |
return Empty; |
| 29009 |
end if; |
| 29010 |
elsif Alias = E then |
| 29011 |
return Empty; |
| 29012 |
else |
| 29013 |
return Alias; |
| 29014 |
end if; |
| 29015 |
end loop; |
| 29016 |
end Ultimate_Overlaid_Entity; |
| 29017 |
|
| 29018 |
--------------------- |
| 29019 |
-- Ultimate_Prefix -- |
| 29020 |
--------------------- |
| 29021 |
|
| 29022 |
function Ultimate_Prefix (N : Node_Id) return Node_Id is |
| 29023 |
Pref : Node_Id; |
| 29024 |
|
| 29025 |
begin |
| 29026 |
Pref := N; |
| 29027 |
while Nkind (Pref) in N_Explicit_Dereference |
| 29028 |
| N_Indexed_Component |
| 29029 |
| N_Selected_Component |
| 29030 |
| N_Slice |
| 29031 |
loop |
| 29032 |
Pref := Prefix (Pref); |
| 29033 |
end loop; |
| 29034 |
|
| 29035 |
return Pref; |
| 29036 |
end Ultimate_Prefix; |
| 29037 |
|
| 29038 |
---------------------------- |
| 29039 |
-- Unique_Defining_Entity -- |
| 29040 |
---------------------------- |
| 29041 |
|
| 29042 |
function Unique_Defining_Entity (N : Node_Id) return Entity_Id is |
| 29043 |
begin |
| 29044 |
return Unique_Entity (Defining_Entity (N)); |
| 29045 |
end Unique_Defining_Entity; |
| 29046 |
|
| 29047 |
------------------- |
| 29048 |
-- Unique_Entity -- |
| 29049 |
------------------- |
| 29050 |
|
| 29051 |
function Unique_Entity (E : Entity_Id) return Entity_Id is |
| 29052 |
U : Entity_Id := E; |
| 29053 |
P : Node_Id; |
| 29054 |
|
| 29055 |
begin |
| 29056 |
case Ekind (E) is |
| 29057 |
when E_Constant => |
| 29058 |
if Present (Full_View (E)) then |
| 29059 |
U := Full_View (E); |
| 29060 |
end if; |
| 29061 |
|
| 29062 |
when Entry_Kind => |
| 29063 |
if Nkind (Parent (E)) = N_Entry_Body then |
| 29064 |
declare |
| 29065 |
Prot_Item : Entity_Id; |
| 29066 |
Prot_Type : Entity_Id; |
| 29067 |
|
| 29068 |
begin |
| 29069 |
if Ekind (E) = E_Entry then |
| 29070 |
Prot_Type := Scope (E); |
| 29071 |
|
| 29072 |
-- Bodies of entry families are nested within an extra scope |
| 29073 |
-- that contains an entry index declaration. |
| 29074 |
|
| 29075 |
else |
| 29076 |
Prot_Type := Scope (Scope (E)); |
| 29077 |
end if; |
| 29078 |
|
| 29079 |
-- A protected type may be declared as a private type, in |
| 29080 |
-- which case we need to get its full view. |
| 29081 |
|
| 29082 |
if Is_Private_Type (Prot_Type) then |
| 29083 |
Prot_Type := Full_View (Prot_Type); |
| 29084 |
end if; |
| 29085 |
|
| 29086 |
-- Full view may not be present on error, in which case |
| 29087 |
-- return E by default. |
| 29088 |
|
| 29089 |
if Present (Prot_Type) then |
| 29090 |
pragma Assert (Ekind (Prot_Type) = E_Protected_Type); |
| 29091 |
|
| 29092 |
-- Traverse the entity list of the protected type and |
| 29093 |
-- locate an entry declaration which matches the entry |
| 29094 |
-- body. |
| 29095 |
|
| 29096 |
Prot_Item := First_Entity (Prot_Type); |
| 29097 |
while Present (Prot_Item) loop |
| 29098 |
if Ekind (Prot_Item) in Entry_Kind |
| 29099 |
and then Corresponding_Body (Parent (Prot_Item)) = E |
| 29100 |
then |
| 29101 |
U := Prot_Item; |
| 29102 |
exit; |
| 29103 |
end if; |
| 29104 |
|
| 29105 |
Next_Entity (Prot_Item); |
| 29106 |
end loop; |
| 29107 |
end if; |
| 29108 |
end; |
| 29109 |
end if; |
| 29110 |
|
| 29111 |
when Formal_Kind => |
| 29112 |
if Present (Spec_Entity (E)) then |
| 29113 |
U := Spec_Entity (E); |
| 29114 |
end if; |
| 29115 |
|
| 29116 |
when E_Package_Body => |
| 29117 |
P := Parent (E); |
| 29118 |
|
| 29119 |
if Nkind (P) = N_Defining_Program_Unit_Name then |
| 29120 |
P := Parent (P); |
| 29121 |
end if; |
| 29122 |
|
| 29123 |
if Nkind (P) = N_Package_Body |
| 29124 |
and then Present (Corresponding_Spec (P)) |
| 29125 |
then |
| 29126 |
U := Corresponding_Spec (P); |
| 29127 |
|
| 29128 |
elsif Nkind (P) = N_Package_Body_Stub |
| 29129 |
and then Present (Corresponding_Spec_Of_Stub (P)) |
| 29130 |
then |
| 29131 |
U := Corresponding_Spec_Of_Stub (P); |
| 29132 |
end if; |
| 29133 |
|
| 29134 |
when E_Protected_Body => |
| 29135 |
P := Parent (E); |
| 29136 |
|
| 29137 |
if Nkind (P) = N_Protected_Body |
| 29138 |
and then Present (Corresponding_Spec (P)) |
| 29139 |
then |
| 29140 |
U := Corresponding_Spec (P); |
| 29141 |
|
| 29142 |
elsif Nkind (P) = N_Protected_Body_Stub |
| 29143 |
and then Present (Corresponding_Spec_Of_Stub (P)) |
| 29144 |
then |
| 29145 |
U := Corresponding_Spec_Of_Stub (P); |
| 29146 |
|
| 29147 |
if Is_Single_Protected_Object (U) then |
| 29148 |
U := Etype (U); |
| 29149 |
end if; |
| 29150 |
end if; |
| 29151 |
|
| 29152 |
if Is_Private_Type (U) then |
| 29153 |
U := Full_View (U); |
| 29154 |
end if; |
| 29155 |
|
| 29156 |
when E_Subprogram_Body => |
| 29157 |
P := Parent (E); |
| 29158 |
|
| 29159 |
if Nkind (P) = N_Defining_Program_Unit_Name then |
| 29160 |
P := Parent (P); |
| 29161 |
end if; |
| 29162 |
|
| 29163 |
P := Parent (P); |
| 29164 |
|
| 29165 |
if Nkind (P) = N_Subprogram_Body |
| 29166 |
and then Present (Corresponding_Spec (P)) |
| 29167 |
then |
| 29168 |
U := Corresponding_Spec (P); |
| 29169 |
|
| 29170 |
elsif Nkind (P) = N_Subprogram_Body_Stub |
| 29171 |
and then Present (Corresponding_Spec_Of_Stub (P)) |
| 29172 |
then |
| 29173 |
U := Corresponding_Spec_Of_Stub (P); |
| 29174 |
|
| 29175 |
elsif Nkind (P) = N_Subprogram_Renaming_Declaration then |
| 29176 |
U := Corresponding_Spec (P); |
| 29177 |
end if; |
| 29178 |
|
| 29179 |
when E_Task_Body => |
| 29180 |
P := Parent (E); |
| 29181 |
|
| 29182 |
if Nkind (P) = N_Task_Body |
| 29183 |
and then Present (Corresponding_Spec (P)) |
| 29184 |
then |
| 29185 |
U := Corresponding_Spec (P); |
| 29186 |
|
| 29187 |
elsif Nkind (P) = N_Task_Body_Stub |
| 29188 |
and then Present (Corresponding_Spec_Of_Stub (P)) |
| 29189 |
then |
| 29190 |
U := Corresponding_Spec_Of_Stub (P); |
| 29191 |
|
| 29192 |
if Is_Single_Task_Object (U) then |
| 29193 |
U := Etype (U); |
| 29194 |
end if; |
| 29195 |
end if; |
| 29196 |
|
| 29197 |
if Is_Private_Type (U) then |
| 29198 |
U := Full_View (U); |
| 29199 |
end if; |
| 29200 |
|
| 29201 |
when Type_Kind => |
| 29202 |
if Present (Full_View (E)) then |
| 29203 |
U := Full_View (E); |
| 29204 |
end if; |
| 29205 |
|
| 29206 |
when others => |
| 29207 |
null; |
| 29208 |
end case; |
| 29209 |
|
| 29210 |
return U; |
| 29211 |
end Unique_Entity; |
| 29212 |
|
| 29213 |
----------------- |
| 29214 |
-- Unique_Name -- |
| 29215 |
----------------- |
| 29216 |
|
| 29217 |
function Unique_Name (E : Entity_Id) return String is |
| 29218 |
|
| 29219 |
-- Local subprograms |
| 29220 |
|
| 29221 |
function Add_Homonym_Suffix (E : Entity_Id) return String; |
| 29222 |
|
| 29223 |
function This_Name return String; |
| 29224 |
|
| 29225 |
------------------------ |
| 29226 |
-- Add_Homonym_Suffix -- |
| 29227 |
------------------------ |
| 29228 |
|
| 29229 |
function Add_Homonym_Suffix (E : Entity_Id) return String is |
| 29230 |
|
| 29231 |
-- Names in E_Subprogram_Body or E_Package_Body entities are not |
| 29232 |
-- reliable, as they may not include the overloading suffix. |
| 29233 |
-- Instead, when looking for the name of E or one of its enclosing |
| 29234 |
-- scope, we get the name of the corresponding Unique_Entity. |
| 29235 |
|
| 29236 |
U : constant Entity_Id := Unique_Entity (E); |
| 29237 |
Nam : constant String := Get_Name_String (Chars (U)); |
| 29238 |
|
| 29239 |
begin |
| 29240 |
-- If E has homonyms but is not fully qualified, as done in |
| 29241 |
-- GNATprove mode, append the homonym number on the fly. Strip the |
| 29242 |
-- leading space character in the image of natural numbers. Also do |
| 29243 |
-- not print the homonym value of 1. |
| 29244 |
|
| 29245 |
if Has_Homonym (U) then |
| 29246 |
declare |
| 29247 |
N : constant Pos := Homonym_Number (U); |
| 29248 |
S : constant String := N'Img; |
| 29249 |
begin |
| 29250 |
if N > 1 then |
| 29251 |
return Nam & "__" & S (2 .. S'Last); |
| 29252 |
end if; |
| 29253 |
end; |
| 29254 |
end if; |
| 29255 |
|
| 29256 |
return Nam; |
| 29257 |
end Add_Homonym_Suffix; |
| 29258 |
|
| 29259 |
--------------- |
| 29260 |
-- This_Name -- |
| 29261 |
--------------- |
| 29262 |
|
| 29263 |
function This_Name return String is |
| 29264 |
begin |
| 29265 |
return Add_Homonym_Suffix (E); |
| 29266 |
end This_Name; |
| 29267 |
|
| 29268 |
-- Local variables |
| 29269 |
|
| 29270 |
U : constant Entity_Id := Unique_Entity (E); |
| 29271 |
|
| 29272 |
-- Start of processing for Unique_Name |
| 29273 |
|
| 29274 |
begin |
| 29275 |
if E = Standard_Standard |
| 29276 |
or else Has_Fully_Qualified_Name (E) |
| 29277 |
then |
| 29278 |
return This_Name; |
| 29279 |
|
| 29280 |
elsif Ekind (E) = E_Enumeration_Literal then |
| 29281 |
return Unique_Name (Etype (E)) & "__" & This_Name; |
| 29282 |
|
| 29283 |
else |
| 29284 |
declare |
| 29285 |
S : constant Entity_Id := Scope (U); |
| 29286 |
pragma Assert (Present (S)); |
| 29287 |
|
| 29288 |
begin |
| 29289 |
-- Prefix names of predefined types with standard__, but leave |
| 29290 |
-- names of user-defined packages and subprograms without prefix |
| 29291 |
-- (even if technically they are nested in the Standard package). |
| 29292 |
|
| 29293 |
if S = Standard_Standard then |
| 29294 |
if Ekind (U) = E_Package or else Is_Subprogram (U) then |
| 29295 |
return This_Name; |
| 29296 |
else |
| 29297 |
return Unique_Name (S) & "__" & This_Name; |
| 29298 |
end if; |
| 29299 |
|
| 29300 |
-- For intances of generic subprograms use the name of the related |
| 29301 |
-- instance and skip the scope of its wrapper package. |
| 29302 |
|
| 29303 |
elsif Is_Wrapper_Package (S) then |
| 29304 |
pragma Assert (Scope (S) = Scope (Related_Instance (S))); |
| 29305 |
-- Wrapper package and the instantiation are in the same scope |
| 29306 |
|
| 29307 |
declare |
| 29308 |
Related_Name : constant String := |
| 29309 |
Add_Homonym_Suffix (Related_Instance (S)); |
| 29310 |
Enclosing_Name : constant String := |
| 29311 |
Unique_Name (Scope (S)) & "__" & Related_Name; |
| 29312 |
|
| 29313 |
begin |
| 29314 |
if Is_Subprogram (U) |
| 29315 |
and then not Is_Generic_Actual_Subprogram (U) |
| 29316 |
then |
| 29317 |
return Enclosing_Name; |
| 29318 |
else |
| 29319 |
return Enclosing_Name & "__" & This_Name; |
| 29320 |
end if; |
| 29321 |
end; |
| 29322 |
|
| 29323 |
elsif Is_Child_Unit (U) then |
| 29324 |
return Child_Prefix & Unique_Name (S) & "__" & This_Name; |
| 29325 |
else |
| 29326 |
return Unique_Name (S) & "__" & This_Name; |
| 29327 |
end if; |
| 29328 |
end; |
| 29329 |
end if; |
| 29330 |
end Unique_Name; |
| 29331 |
|
| 29332 |
--------------------- |
| 29333 |
-- Unit_Is_Visible -- |
| 29334 |
--------------------- |
| 29335 |
|
| 29336 |
function Unit_Is_Visible (U : Entity_Id) return Boolean is |
| 29337 |
Curr : constant Node_Id := Cunit (Current_Sem_Unit); |
| 29338 |
Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); |
| 29339 |
|
| 29340 |
function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean; |
| 29341 |
-- For a child unit, check whether unit appears in a with_clause |
| 29342 |
-- of a parent. |
| 29343 |
|
| 29344 |
function Unit_In_Context (Comp_Unit : Node_Id) return Boolean; |
| 29345 |
-- Scan the context clause of one compilation unit looking for a |
| 29346 |
-- with_clause for the unit in question. |
| 29347 |
|
| 29348 |
---------------------------- |
| 29349 |
-- Unit_In_Parent_Context -- |
| 29350 |
---------------------------- |
| 29351 |
|
| 29352 |
function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is |
| 29353 |
begin |
| 29354 |
if Unit_In_Context (Par_Unit) then |
| 29355 |
return True; |
| 29356 |
|
| 29357 |
elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then |
| 29358 |
return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit))); |
| 29359 |
|
| 29360 |
else |
| 29361 |
return False; |
| 29362 |
end if; |
| 29363 |
end Unit_In_Parent_Context; |
| 29364 |
|
| 29365 |
--------------------- |
| 29366 |
-- Unit_In_Context -- |
| 29367 |
--------------------- |
| 29368 |
|
| 29369 |
function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is |
| 29370 |
Clause : Node_Id; |
| 29371 |
|
| 29372 |
begin |
| 29373 |
Clause := First (Context_Items (Comp_Unit)); |
| 29374 |
while Present (Clause) loop |
| 29375 |
if Nkind (Clause) = N_With_Clause then |
| 29376 |
if Withed_Lib_Unit (Clause) = U then |
| 29377 |
return True; |
| 29378 |
|
| 29379 |
-- The with_clause may denote a renaming of the unit we are |
| 29380 |
-- looking for, eg. Text_IO which renames Ada.Text_IO. |
| 29381 |
|
| 29382 |
elsif |
| 29383 |
Renamed_Entity (Entity (Name (Clause))) = |
| 29384 |
Defining_Entity (Unit (U)) |
| 29385 |
then |
| 29386 |
return True; |
| 29387 |
end if; |
| 29388 |
end if; |
| 29389 |
|
| 29390 |
Next (Clause); |
| 29391 |
end loop; |
| 29392 |
|
| 29393 |
return False; |
| 29394 |
end Unit_In_Context; |
| 29395 |
|
| 29396 |
-- Start of processing for Unit_Is_Visible |
| 29397 |
|
| 29398 |
begin |
| 29399 |
-- The currrent unit is directly visible |
| 29400 |
|
| 29401 |
if Curr = U then |
| 29402 |
return True; |
| 29403 |
|
| 29404 |
elsif Unit_In_Context (Curr) then |
| 29405 |
return True; |
| 29406 |
|
| 29407 |
-- If the current unit is a body, check the context of the spec |
| 29408 |
|
| 29409 |
elsif Nkind (Unit (Curr)) = N_Package_Body |
| 29410 |
or else |
| 29411 |
(Nkind (Unit (Curr)) = N_Subprogram_Body |
| 29412 |
and then not Acts_As_Spec (Unit (Curr))) |
| 29413 |
then |
| 29414 |
if Unit_In_Context (Spec_Lib_Unit (Curr)) then |
| 29415 |
return True; |
| 29416 |
end if; |
| 29417 |
end if; |
| 29418 |
|
| 29419 |
-- If the spec is a child unit, examine the parents |
| 29420 |
|
| 29421 |
if Is_Child_Unit (Curr_Entity) then |
| 29422 |
if Nkind (Unit (Curr)) in N_Lib_Unit_Body then |
| 29423 |
return |
| 29424 |
Unit_In_Parent_Context |
| 29425 |
(Parent_Spec (Unit (Spec_Lib_Unit (Curr)))); |
| 29426 |
else |
| 29427 |
return Unit_In_Parent_Context (Parent_Spec (Unit (Curr))); |
| 29428 |
end if; |
| 29429 |
|
| 29430 |
else |
| 29431 |
return False; |
| 29432 |
end if; |
| 29433 |
end Unit_Is_Visible; |
| 29434 |
|
| 29435 |
------------------------------ |
| 29436 |
-- Universal_Interpretation -- |
| 29437 |
------------------------------ |
| 29438 |
|
| 29439 |
function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is |
| 29440 |
Index : Interp_Index; |
| 29441 |
It : Interp; |
| 29442 |
|
| 29443 |
begin |
| 29444 |
-- The argument may be a formal parameter of an operator or subprogram |
| 29445 |
-- with multiple interpretations, or else an expression for an actual. |
| 29446 |
|
| 29447 |
if Nkind (Opnd) = N_Defining_Identifier |
| 29448 |
or else not Is_Overloaded (Opnd) |
| 29449 |
then |
| 29450 |
if Is_Universal_Numeric_Type (Etype (Opnd)) then |
| 29451 |
return Etype (Opnd); |
| 29452 |
else |
| 29453 |
return Empty; |
| 29454 |
end if; |
| 29455 |
|
| 29456 |
else |
| 29457 |
Get_First_Interp (Opnd, Index, It); |
| 29458 |
while Present (It.Typ) loop |
| 29459 |
if Is_Universal_Numeric_Type (It.Typ) then |
| 29460 |
return It.Typ; |
| 29461 |
end if; |
| 29462 |
|
| 29463 |
Get_Next_Interp (Index, It); |
| 29464 |
end loop; |
| 29465 |
|
| 29466 |
return Empty; |
| 29467 |
end if; |
| 29468 |
end Universal_Interpretation; |
| 29469 |
|
| 29470 |
--------------- |
| 29471 |
-- Unqualify -- |
| 29472 |
--------------- |
| 29473 |
|
| 29474 |
function Unqualify (Expr : Node_Id) return Node_Id is |
| 29475 |
begin |
| 29476 |
-- Recurse to handle unlikely case of multiple levels of qualification |
| 29477 |
|
| 29478 |
if Nkind (Expr) = N_Qualified_Expression then |
| 29479 |
return Unqualify (Expression (Expr)); |
| 29480 |
|
| 29481 |
-- Normal case, not a qualified expression |
| 29482 |
|
| 29483 |
else |
| 29484 |
return Expr; |
| 29485 |
end if; |
| 29486 |
end Unqualify; |
| 29487 |
|
| 29488 |
----------------- |
| 29489 |
-- Unqual_Conv -- |
| 29490 |
----------------- |
| 29491 |
|
| 29492 |
function Unqual_Conv (Expr : Node_Id) return Node_Id is |
| 29493 |
begin |
| 29494 |
-- Recurse to handle unlikely case of multiple levels of qualification |
| 29495 |
-- and/or conversion. |
| 29496 |
|
| 29497 |
if Nkind (Expr) in N_Qualified_Expression |
| 29498 |
| N_Type_Conversion |
| 29499 |
| N_Unchecked_Type_Conversion |
| 29500 |
then |
| 29501 |
return Unqual_Conv (Expression (Expr)); |
| 29502 |
|
| 29503 |
-- Normal case, not a qualified expression |
| 29504 |
|
| 29505 |
else |
| 29506 |
return Expr; |
| 29507 |
end if; |
| 29508 |
end Unqual_Conv; |
| 29509 |
|
| 29510 |
-------------------- |
| 29511 |
-- Validated_View -- |
| 29512 |
-------------------- |
| 29513 |
|
| 29514 |
function Validated_View (Typ : Entity_Id) return Entity_Id is |
| 29515 |
begin |
| 29516 |
-- Scalar types can be always validated. In fast, switiching to the base |
| 29517 |
-- type would drop the range constraints and force validation to use a |
| 29518 |
-- larger type than necessary. |
| 29519 |
|
| 29520 |
if Is_Scalar_Type (Typ) then |
| 29521 |
return Typ; |
| 29522 |
|
| 29523 |
-- Array types can be validated even when they are derived, because |
| 29524 |
-- validation only requires their bounds and component types to be |
| 29525 |
-- accessible. In fact, switching to the parent type would pollute |
| 29526 |
-- expansion of attribute Valid_Scalars with unnecessary conversion |
| 29527 |
-- that might not be eliminated by the frontend. |
| 29528 |
|
| 29529 |
elsif Is_Array_Type (Typ) then |
| 29530 |
return Typ; |
| 29531 |
|
| 29532 |
-- For other types, in particular for record subtypes, we switch to the |
| 29533 |
-- base type. |
| 29534 |
|
| 29535 |
elsif not Is_Base_Type (Typ) then |
| 29536 |
return Validated_View (Base_Type (Typ)); |
| 29537 |
|
| 29538 |
-- Obtain the full view of the input type by stripping away concurrency, |
| 29539 |
-- derivations, and privacy. |
| 29540 |
|
| 29541 |
elsif Is_Concurrent_Type (Typ) then |
| 29542 |
if Present (Corresponding_Record_Type (Typ)) then |
| 29543 |
return Corresponding_Record_Type (Typ); |
| 29544 |
else |
| 29545 |
return Typ; |
| 29546 |
end if; |
| 29547 |
|
| 29548 |
elsif Is_Derived_Type (Typ) then |
| 29549 |
return Validated_View (Etype (Typ)); |
| 29550 |
|
| 29551 |
elsif Is_Private_Type (Typ) then |
| 29552 |
if Present (Underlying_Full_View (Typ)) then |
| 29553 |
return Validated_View (Underlying_Full_View (Typ)); |
| 29554 |
|
| 29555 |
elsif Present (Full_View (Typ)) then |
| 29556 |
return Validated_View (Full_View (Typ)); |
| 29557 |
else |
| 29558 |
return Typ; |
| 29559 |
end if; |
| 29560 |
|
| 29561 |
elsif From_Limited_With (Typ) then |
| 29562 |
if Has_Non_Limited_View (Typ) then |
| 29563 |
return Validated_View (Non_Limited_View (Typ)); |
| 29564 |
else |
| 29565 |
return Typ; |
| 29566 |
end if; |
| 29567 |
|
| 29568 |
else |
| 29569 |
return Typ; |
| 29570 |
end if; |
| 29571 |
end Validated_View; |
| 29572 |
|
| 29573 |
----------------------- |
| 29574 |
-- Visible_Ancestors -- |
| 29575 |
----------------------- |
| 29576 |
|
| 29577 |
function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is |
| 29578 |
List_1 : Elist_Id; |
| 29579 |
List_2 : Elist_Id; |
| 29580 |
Elmt : Elmt_Id; |
| 29581 |
|
| 29582 |
begin |
| 29583 |
pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ)); |
| 29584 |
|
| 29585 |
-- Collect all the parents and progenitors of Typ. If the full-view of |
| 29586 |
-- private parents and progenitors is available then it is used to |
| 29587 |
-- generate the list of visible ancestors; otherwise their partial |
| 29588 |
-- view is added to the resulting list. |
| 29589 |
|
| 29590 |
Collect_Parents |
| 29591 |
(T => Typ, |
| 29592 |
List => List_1, |
| 29593 |
Use_Full_View => True); |
| 29594 |
|
| 29595 |
Collect_Interfaces |
| 29596 |
(T => Typ, |
| 29597 |
Ifaces_List => List_2, |
| 29598 |
Exclude_Parents => True, |
| 29599 |
Use_Full_View => True); |
| 29600 |
|
| 29601 |
-- Join the two lists. Avoid duplications because an interface may |
| 29602 |
-- simultaneously be parent and progenitor of a type. |
| 29603 |
|
| 29604 |
Elmt := First_Elmt (List_2); |
| 29605 |
while Present (Elmt) loop |
| 29606 |
Append_Unique_Elmt (Node (Elmt), List_1); |
| 29607 |
Next_Elmt (Elmt); |
| 29608 |
end loop; |
| 29609 |
|
| 29610 |
return List_1; |
| 29611 |
end Visible_Ancestors; |
| 29612 |
|
| 29613 |
--------------------------- |
| 29614 |
-- Warn_On_Hiding_Entity -- |
| 29615 |
--------------------------- |
| 29616 |
|
| 29617 |
procedure Warn_On_Hiding_Entity |
| 29618 |
(N : Node_Id; |
| 29619 |
Hidden, Visible : Entity_Id; |
| 29620 |
On_Use_Clause : Boolean) |
| 29621 |
is |
| 29622 |
begin |
| 29623 |
-- Don't warn for record components since they always have a well |
| 29624 |
-- defined scope which does not confuse other uses. Note that in |
| 29625 |
-- some cases, Ekind has not been set yet. |
| 29626 |
|
| 29627 |
if Ekind (Hidden) /= E_Component |
| 29628 |
and then Ekind (Hidden) /= E_Discriminant |
| 29629 |
and then Nkind (Parent (Hidden)) /= N_Component_Declaration |
| 29630 |
and then Ekind (Visible) /= E_Component |
| 29631 |
and then Ekind (Visible) /= E_Discriminant |
| 29632 |
and then Nkind (Parent (Visible)) /= N_Component_Declaration |
| 29633 |
|
| 29634 |
-- Don't warn for one character variables. It is too common to use |
| 29635 |
-- such variables as locals and will just cause too many false hits. |
| 29636 |
|
| 29637 |
and then Length_Of_Name (Chars (Hidden)) /= 1 |
| 29638 |
|
| 29639 |
-- Don't warn for non-source entities |
| 29640 |
|
| 29641 |
and then Comes_From_Source (Hidden) |
| 29642 |
and then Comes_From_Source (Visible) |
| 29643 |
|
| 29644 |
-- Don't warn within a generic instantiation |
| 29645 |
|
| 29646 |
and then not In_Instance |
| 29647 |
|
| 29648 |
-- Don't warn unless entity in question is in extended main source |
| 29649 |
|
| 29650 |
and then In_Extended_Main_Source_Unit (Visible) |
| 29651 |
|
| 29652 |
-- Finally, in the case of a declaration, the hidden entity must |
| 29653 |
-- be either immediately visible or use visible (i.e. from a used |
| 29654 |
-- package). In the case of a use clause, the visible entity must |
| 29655 |
-- be immediately visible. |
| 29656 |
|
| 29657 |
and then |
| 29658 |
(if On_Use_Clause then |
| 29659 |
Is_Immediately_Visible (Visible) |
| 29660 |
else |
| 29661 |
(Is_Immediately_Visible (Hidden) |
| 29662 |
or else |
| 29663 |
Is_Potentially_Use_Visible (Hidden))) |
| 29664 |
then |
| 29665 |
if On_Use_Clause then |
| 29666 |
Error_Msg_Sloc := Sloc (Visible); |
| 29667 |
Error_Msg_NE ("visible declaration of&# hides homonym " |
| 29668 |
& "from use clause?h?", N, Hidden); |
| 29669 |
else |
| 29670 |
Error_Msg_Sloc := Sloc (Hidden); |
| 29671 |
Error_Msg_NE ("declaration hides &#?h?", N, Visible); |
| 29672 |
end if; |
| 29673 |
end if; |
| 29674 |
end Warn_On_Hiding_Entity; |
| 29675 |
|
| 29676 |
---------------------- |
| 29677 |
-- Within_Init_Proc -- |
| 29678 |
---------------------- |
| 29679 |
|
| 29680 |
function Within_Init_Proc return Boolean is |
| 29681 |
S : Entity_Id; |
| 29682 |
|
| 29683 |
begin |
| 29684 |
S := Current_Scope; |
| 29685 |
while not Is_Overloadable (S) loop |
| 29686 |
if S = Standard_Standard then |
| 29687 |
return False; |
| 29688 |
else |
| 29689 |
S := Scope (S); |
| 29690 |
end if; |
| 29691 |
end loop; |
| 29692 |
|
| 29693 |
return Is_Init_Proc (S); |
| 29694 |
end Within_Init_Proc; |
| 29695 |
|
| 29696 |
--------------------------- |
| 29697 |
-- Within_Protected_Type -- |
| 29698 |
--------------------------- |
| 29699 |
|
| 29700 |
function Within_Protected_Type (E : Entity_Id) return Boolean is |
| 29701 |
Scop : Entity_Id := Scope (E); |
| 29702 |
|
| 29703 |
begin |
| 29704 |
while Present (Scop) loop |
| 29705 |
if Ekind (Scop) = E_Protected_Type then |
| 29706 |
return True; |
| 29707 |
end if; |
| 29708 |
|
| 29709 |
Scop := Scope (Scop); |
| 29710 |
end loop; |
| 29711 |
|
| 29712 |
return False; |
| 29713 |
end Within_Protected_Type; |
| 29714 |
|
| 29715 |
------------------ |
| 29716 |
-- Within_Scope -- |
| 29717 |
------------------ |
| 29718 |
|
| 29719 |
function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is |
| 29720 |
begin |
| 29721 |
return Scope_Within_Or_Same (Scope (E), S); |
| 29722 |
end Within_Scope; |
| 29723 |
|
| 29724 |
----------------------------------- |
| 29725 |
-- Within_Spec_Static_Expression -- |
| 29726 |
----------------------------------- |
| 29727 |
|
| 29728 |
function Within_Spec_Static_Expression (N : Node_Id) return Boolean is |
| 29729 |
P : Node_Id; |
| 29730 |
|
| 29731 |
begin |
| 29732 |
if not In_Spec_Expression then |
| 29733 |
return False; |
| 29734 |
|
| 29735 |
else |
| 29736 |
P := N; |
| 29737 |
loop |
| 29738 |
if No (P) then |
| 29739 |
return False; |
| 29740 |
|
| 29741 |
-- Prevent the search from going too far |
| 29742 |
|
| 29743 |
elsif Nkind (P) not in N_Subexpr then |
| 29744 |
return False; |
| 29745 |
|
| 29746 |
elsif Is_OK_Static_Expression (P) then |
| 29747 |
return True; |
| 29748 |
|
| 29749 |
-- Return True for static scalar subtypes that are prefixes of an |
| 29750 |
-- attribute (even if not yet marked static) since they will be |
| 29751 |
-- marked as static in Eval_Attribute (as called from Resolve_ |
| 29752 |
-- Attribute). |
| 29753 |
|
| 29754 |
elsif Present (Parent (P)) |
| 29755 |
and then Nkind (Parent (P)) = N_Attribute_Reference |
| 29756 |
and then Is_Entity_Name (P) |
| 29757 |
and then Is_Type (Entity (P)) |
| 29758 |
and then Is_OK_Static_Subtype (Entity (P)) |
| 29759 |
then |
| 29760 |
return True; |
| 29761 |
|
| 29762 |
else |
| 29763 |
P := Parent (P); |
| 29764 |
end if; |
| 29765 |
end loop; |
| 29766 |
end if; |
| 29767 |
end Within_Spec_Static_Expression; |
| 29768 |
|
| 29769 |
---------------- |
| 29770 |
-- Wrong_Type -- |
| 29771 |
---------------- |
| 29772 |
|
| 29773 |
procedure Wrong_Type |
| 29774 |
(Expr : Node_Id; |
| 29775 |
Expected_Type : Entity_Id; |
| 29776 |
Multiple : Boolean := False) |
| 29777 |
is |
| 29778 |
Found_Type : constant Entity_Id := First_Subtype (Etype (Expr)); |
| 29779 |
Expec_Type : constant Entity_Id := First_Subtype (Expected_Type); |
| 29780 |
|
| 29781 |
Err_Msg_Exp_Typ : Entity_Id := Expected_Type; |
| 29782 |
-- Type entity used when printing errors concerning the expected type |
| 29783 |
|
| 29784 |
Matching_Field : Entity_Id; |
| 29785 |
-- Entity to give a more precise suggestion on how to write a one- |
| 29786 |
-- element positional aggregate. |
| 29787 |
|
| 29788 |
function Has_One_Matching_Field return Boolean; |
| 29789 |
-- Determines if Expec_Type is a record type with a single component or |
| 29790 |
-- discriminant whose type matches the found type or is one dimensional |
| 29791 |
-- array whose component type matches the found type. In the case of |
| 29792 |
-- one discriminant, we ignore the variant parts. That's not accurate, |
| 29793 |
-- but good enough for the warning. |
| 29794 |
|
| 29795 |
---------------------------- |
| 29796 |
-- Has_One_Matching_Field -- |
| 29797 |
---------------------------- |
| 29798 |
|
| 29799 |
function Has_One_Matching_Field return Boolean is |
| 29800 |
E : Entity_Id; |
| 29801 |
|
| 29802 |
begin |
| 29803 |
Matching_Field := Empty; |
| 29804 |
|
| 29805 |
if Is_Array_Type (Expec_Type) |
| 29806 |
and then Number_Dimensions (Expec_Type) = 1 |
| 29807 |
and then Covers (Etype (Component_Type (Expec_Type)), Found_Type) |
| 29808 |
then |
| 29809 |
-- Use type name if available. This excludes multidimensional |
| 29810 |
-- arrays and anonymous arrays. |
| 29811 |
|
| 29812 |
if Comes_From_Source (Expec_Type) then |
| 29813 |
Matching_Field := Expec_Type; |
| 29814 |
|
| 29815 |
-- For an assignment, use name of target |
| 29816 |
|
| 29817 |
elsif Nkind (Parent (Expr)) = N_Assignment_Statement |
| 29818 |
and then Is_Entity_Name (Name (Parent (Expr))) |
| 29819 |
then |
| 29820 |
Matching_Field := Entity (Name (Parent (Expr))); |
| 29821 |
end if; |
| 29822 |
|
| 29823 |
return True; |
| 29824 |
|
| 29825 |
elsif not Is_Record_Type (Expec_Type) then |
| 29826 |
return False; |
| 29827 |
|
| 29828 |
else |
| 29829 |
E := First_Entity (Expec_Type); |
| 29830 |
loop |
| 29831 |
if No (E) then |
| 29832 |
return False; |
| 29833 |
|
| 29834 |
elsif Ekind (E) not in E_Discriminant | E_Component |
| 29835 |
or else Chars (E) in Name_uTag | Name_uParent |
| 29836 |
then |
| 29837 |
Next_Entity (E); |
| 29838 |
|
| 29839 |
else |
| 29840 |
exit; |
| 29841 |
end if; |
| 29842 |
end loop; |
| 29843 |
|
| 29844 |
if not Covers (Etype (E), Found_Type) then |
| 29845 |
return False; |
| 29846 |
|
| 29847 |
elsif Present (Next_Entity (E)) |
| 29848 |
and then (Ekind (E) = E_Component |
| 29849 |
or else Ekind (Next_Entity (E)) = E_Discriminant) |
| 29850 |
then |
| 29851 |
return False; |
| 29852 |
|
| 29853 |
else |
| 29854 |
Matching_Field := E; |
| 29855 |
return True; |
| 29856 |
end if; |
| 29857 |
end if; |
| 29858 |
end Has_One_Matching_Field; |
| 29859 |
|
| 29860 |
-- Start of processing for Wrong_Type |
| 29861 |
|
| 29862 |
begin |
| 29863 |
-- Don't output message if either type is Any_Type, or if a message |
| 29864 |
-- has already been posted for this node and we do not want multiple |
| 29865 |
-- error messages. We need to do the latter check explicitly (it is |
| 29866 |
-- ordinarily done in Errout) because we are using '!' to force the |
| 29867 |
-- output of the error messages. |
| 29868 |
|
| 29869 |
if Expec_Type = Any_Type |
| 29870 |
or else Found_Type = Any_Type |
| 29871 |
or else (Error_Posted (Expr) and then not Multiple) |
| 29872 |
then |
| 29873 |
return; |
| 29874 |
|
| 29875 |
-- If one of the types is a Taft-Amendment type and the other it its |
| 29876 |
-- completion, it must be an illegal use of a TAT in the spec, for |
| 29877 |
-- which an error was already emitted. Avoid cascaded errors. |
| 29878 |
|
| 29879 |
elsif Is_Incomplete_Type (Expec_Type) |
| 29880 |
and then Has_Completion_In_Body (Expec_Type) |
| 29881 |
and then Full_View (Expec_Type) = Etype (Expr) |
| 29882 |
then |
| 29883 |
return; |
| 29884 |
|
| 29885 |
elsif Is_Incomplete_Type (Etype (Expr)) |
| 29886 |
and then Has_Completion_In_Body (Etype (Expr)) |
| 29887 |
and then Full_View (Etype (Expr)) = Expec_Type |
| 29888 |
then |
| 29889 |
return; |
| 29890 |
end if; |
| 29891 |
|
| 29892 |
-- Avoid printing internally generated subtypes in error messages and |
| 29893 |
-- instead use the corresponding first subtype in such cases. |
| 29894 |
|
| 29895 |
if not Comes_From_Source (Err_Msg_Exp_Typ) |
| 29896 |
or else not Comes_From_Source (Declaration_Node (Err_Msg_Exp_Typ)) |
| 29897 |
then |
| 29898 |
Err_Msg_Exp_Typ := First_Subtype (Err_Msg_Exp_Typ); |
| 29899 |
end if; |
| 29900 |
|
| 29901 |
-- An interesting special check. If the expression is parenthesized |
| 29902 |
-- and its type corresponds to the type of the sole component of the |
| 29903 |
-- expected record type, or to the component type of the expected one |
| 29904 |
-- dimensional array type, then assume we have a bad aggregate attempt. |
| 29905 |
|
| 29906 |
if Nkind (Expr) in N_Subexpr |
| 29907 |
and then Paren_Count (Expr) /= 0 |
| 29908 |
and then Has_One_Matching_Field |
| 29909 |
then |
| 29910 |
Error_Msg_N ("positional aggregate cannot have one component", Expr); |
| 29911 |
|
| 29912 |
if Present (Matching_Field) then |
| 29913 |
if Is_Array_Type (Expec_Type) then |
| 29914 |
Error_Msg_NE |
| 29915 |
("\write instead `&''First ='> ...`", Expr, Matching_Field); |
| 29916 |
else |
| 29917 |
Error_Msg_NE |
| 29918 |
("\write instead `& ='> ...`", Expr, Matching_Field); |
| 29919 |
end if; |
| 29920 |
end if; |
| 29921 |
|
| 29922 |
-- Another special check, if we are looking for a pool-specific access |
| 29923 |
-- type and we found an E_Access_Attribute_Type, then we have the case |
| 29924 |
-- of an Access attribute being used in a context which needs a pool- |
| 29925 |
-- specific type, which is never allowed. The one extra check we make |
| 29926 |
-- is that the expected designated type covers the Found_Type. |
| 29927 |
|
| 29928 |
elsif Is_Access_Type (Expec_Type) |
| 29929 |
and then Ekind (Found_Type) = E_Access_Attribute_Type |
| 29930 |
and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type |
| 29931 |
and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type |
| 29932 |
and then Covers |
| 29933 |
(Designated_Type (Expec_Type), Designated_Type (Found_Type)) |
| 29934 |
then |
| 29935 |
Error_Msg_N |
| 29936 |
("result must be general access type!", Expr); |
| 29937 |
Error_Msg_NE -- CODEFIX |
| 29938 |
("\add ALL to }!", Expr, Err_Msg_Exp_Typ); |
| 29939 |
|
| 29940 |
-- Another special check, if the expected type is an integer type, |
| 29941 |
-- but the expression is of type System.Address, and the parent is |
| 29942 |
-- an addition or subtraction operation whose left operand is the |
| 29943 |
-- expression in question and whose right operand is of an integral |
| 29944 |
-- type, then this is an attempt at address arithmetic, so give |
| 29945 |
-- appropriate message. |
| 29946 |
|
| 29947 |
elsif Is_Integer_Type (Expec_Type) |
| 29948 |
and then Is_RTE (Found_Type, RE_Address) |
| 29949 |
and then Nkind (Parent (Expr)) in N_Op_Add | N_Op_Subtract |
| 29950 |
and then Expr = Left_Opnd (Parent (Expr)) |
| 29951 |
and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr)))) |
| 29952 |
then |
| 29953 |
Error_Msg_N |
| 29954 |
("address arithmetic not predefined in package System", |
| 29955 |
Parent (Expr)); |
| 29956 |
Error_Msg_N |
| 29957 |
("\possible missing with/use of System.Storage_Elements", |
| 29958 |
Parent (Expr)); |
| 29959 |
return; |
| 29960 |
|
| 29961 |
-- If the expected type is an anonymous access type, as for access |
| 29962 |
-- parameters and discriminants, the error is on the designated types. |
| 29963 |
|
| 29964 |
elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then |
| 29965 |
if Comes_From_Source (Expec_Type) then |
| 29966 |
Error_Msg_NE ("expected}!", Expr, Expec_Type); |
| 29967 |
else |
| 29968 |
Error_Msg_NE |
| 29969 |
("expected an access type with designated}", |
| 29970 |
Expr, Designated_Type (Expec_Type)); |
| 29971 |
end if; |
| 29972 |
|
| 29973 |
if Is_Access_Type (Found_Type) |
| 29974 |
and then not Comes_From_Source (Found_Type) |
| 29975 |
then |
| 29976 |
Error_Msg_NE |
| 29977 |
("\\found an access type with designated}!", |
| 29978 |
Expr, Designated_Type (Found_Type)); |
| 29979 |
else |
| 29980 |
if From_Limited_With (Found_Type) then |
| 29981 |
Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type); |
| 29982 |
Error_Msg_Qual_Level := 99; |
| 29983 |
Error_Msg_NE -- CODEFIX |
| 29984 |
("\\missing `WITH &;", Expr, Scope (Found_Type)); |
| 29985 |
Error_Msg_Qual_Level := 0; |
| 29986 |
else |
| 29987 |
Error_Msg_NE ("found}!", Expr, Found_Type); |
| 29988 |
end if; |
| 29989 |
end if; |
| 29990 |
|
| 29991 |
-- Normal case of one type found, some other type expected |
| 29992 |
|
| 29993 |
else |
| 29994 |
-- If the names of the two types are the same, see if some number |
| 29995 |
-- of levels of qualification will help. Don't try more than three |
| 29996 |
-- levels, and if we get to standard, it's no use (and probably |
| 29997 |
-- represents an error in the compiler) Also do not bother with |
| 29998 |
-- internal scope names. |
| 29999 |
|
| 30000 |
declare |
| 30001 |
Expec_Scope : Entity_Id; |
| 30002 |
Found_Scope : Entity_Id; |
| 30003 |
|
| 30004 |
begin |
| 30005 |
Expec_Scope := Expec_Type; |
| 30006 |
Found_Scope := Found_Type; |
| 30007 |
|
| 30008 |
for Levels in Nat range 0 .. 3 loop |
| 30009 |
if Chars (Expec_Scope) /= Chars (Found_Scope) then |
| 30010 |
Error_Msg_Qual_Level := Levels; |
| 30011 |
exit; |
| 30012 |
end if; |
| 30013 |
|
| 30014 |
Expec_Scope := Scope (Expec_Scope); |
| 30015 |
Found_Scope := Scope (Found_Scope); |
| 30016 |
|
| 30017 |
exit when Expec_Scope = Standard_Standard |
| 30018 |
or else Found_Scope = Standard_Standard |
| 30019 |
or else not Comes_From_Source (Expec_Scope) |
| 30020 |
or else not Comes_From_Source (Found_Scope); |
| 30021 |
end loop; |
| 30022 |
end; |
| 30023 |
|
| 30024 |
if Is_Record_Type (Expec_Type) |
| 30025 |
and then Present (Corresponding_Remote_Type (Expec_Type)) |
| 30026 |
then |
| 30027 |
Error_Msg_NE ("expected}!", Expr, |
| 30028 |
Corresponding_Remote_Type (Expec_Type)); |
| 30029 |
else |
| 30030 |
Error_Msg_NE ("expected}!", Expr, Err_Msg_Exp_Typ); |
| 30031 |
end if; |
| 30032 |
|
| 30033 |
if Is_Entity_Name (Expr) |
| 30034 |
and then Is_Package_Or_Generic_Package (Entity (Expr)) |
| 30035 |
then |
| 30036 |
Error_Msg_N ("\\found package name!", Expr); |
| 30037 |
|
| 30038 |
elsif Is_Entity_Name (Expr) |
| 30039 |
and then Ekind (Entity (Expr)) in E_Procedure | E_Generic_Procedure |
| 30040 |
then |
| 30041 |
if Ekind (Expec_Type) = E_Access_Subprogram_Type then |
| 30042 |
Error_Msg_N |
| 30043 |
("found procedure name, possibly missing Access attribute!", |
| 30044 |
Expr); |
| 30045 |
else |
| 30046 |
Error_Msg_N |
| 30047 |
("\\found procedure name instead of function!", Expr); |
| 30048 |
end if; |
| 30049 |
|
| 30050 |
elsif Nkind (Expr) = N_Function_Call |
| 30051 |
and then Ekind (Expec_Type) = E_Access_Subprogram_Type |
| 30052 |
and then Etype (Designated_Type (Expec_Type)) = Etype (Expr) |
| 30053 |
and then No (Parameter_Associations (Expr)) |
| 30054 |
then |
| 30055 |
Error_Msg_N |
| 30056 |
("found function name, possibly missing Access attribute!", |
| 30057 |
Expr); |
| 30058 |
|
| 30059 |
-- Catch common error: a prefix or infix operator which is not |
| 30060 |
-- directly visible because the type isn't. |
| 30061 |
|
| 30062 |
elsif Nkind (Expr) in N_Op |
| 30063 |
and then Is_Overloaded (Expr) |
| 30064 |
and then not Is_Immediately_Visible (Expec_Type) |
| 30065 |
and then not Is_Potentially_Use_Visible (Expec_Type) |
| 30066 |
and then not In_Use (Expec_Type) |
| 30067 |
and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type) |
| 30068 |
then |
| 30069 |
Error_Msg_N |
| 30070 |
("operator of the type is not directly visible!", Expr); |
| 30071 |
|
| 30072 |
elsif Ekind (Found_Type) = E_Void |
| 30073 |
and then Present (Parent (Found_Type)) |
| 30074 |
and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration |
| 30075 |
then |
| 30076 |
Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type); |
| 30077 |
|
| 30078 |
else |
| 30079 |
Error_Msg_NE ("\\found}!", Expr, Found_Type); |
| 30080 |
end if; |
| 30081 |
|
| 30082 |
-- A special check for cases like M1 and M2 = 0 where M1 and M2 are |
| 30083 |
-- of the same modular type, and (M1 and M2) = 0 was intended. |
| 30084 |
|
| 30085 |
if Expec_Type = Standard_Boolean |
| 30086 |
and then Is_Modular_Integer_Type (Found_Type) |
| 30087 |
and then Nkind (Parent (Expr)) in N_Op_And | N_Op_Or | N_Op_Xor |
| 30088 |
and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare |
| 30089 |
then |
| 30090 |
declare |
| 30091 |
Op : constant Node_Id := Right_Opnd (Parent (Expr)); |
| 30092 |
L : constant Node_Id := Left_Opnd (Op); |
| 30093 |
R : constant Node_Id := Right_Opnd (Op); |
| 30094 |
|
| 30095 |
begin |
| 30096 |
-- The case for the message is when the left operand of the |
| 30097 |
-- comparison is the same modular type, or when it is an |
| 30098 |
-- integer literal (or other universal integer expression), |
| 30099 |
-- which would have been typed as the modular type if the |
| 30100 |
-- parens had been there. |
| 30101 |
|
| 30102 |
if (Etype (L) = Found_Type |
| 30103 |
or else |
| 30104 |
Etype (L) = Universal_Integer) |
| 30105 |
and then Is_Integer_Type (Etype (R)) |
| 30106 |
then |
| 30107 |
Error_Msg_N |
| 30108 |
("\\possible missing parens for modular operation", Expr); |
| 30109 |
end if; |
| 30110 |
end; |
| 30111 |
end if; |
| 30112 |
|
| 30113 |
-- Reset error message qualification indication |
| 30114 |
|
| 30115 |
Error_Msg_Qual_Level := 0; |
| 30116 |
end if; |
| 30117 |
end Wrong_Type; |
| 30118 |
|
| 30119 |
-------------------------------- |
| 30120 |
-- Yields_Synchronized_Object -- |
| 30121 |
-------------------------------- |
| 30122 |
|
| 30123 |
function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is |
| 30124 |
Has_Sync_Comp : Boolean := False; |
| 30125 |
Id : Entity_Id; |
| 30126 |
|
| 30127 |
begin |
| 30128 |
-- An array type yields a synchronized object if its component type |
| 30129 |
-- yields a synchronized object. |
| 30130 |
|
| 30131 |
if Is_Array_Type (Typ) then |
| 30132 |
return Yields_Synchronized_Object (Component_Type (Typ)); |
| 30133 |
|
| 30134 |
-- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object |
| 30135 |
-- yields a synchronized object by default. |
| 30136 |
|
| 30137 |
elsif Is_Descendant_Of_Suspension_Object (Typ) then |
| 30138 |
return True; |
| 30139 |
|
| 30140 |
-- A protected type yields a synchronized object by default |
| 30141 |
|
| 30142 |
elsif Is_Protected_Type (Typ) then |
| 30143 |
return True; |
| 30144 |
|
| 30145 |
-- A record type or type extension yields a synchronized object when its |
| 30146 |
-- discriminants (if any) lack default values and all components are of |
| 30147 |
-- a type that yields a synchronized object. |
| 30148 |
|
| 30149 |
elsif Is_Record_Type (Typ) then |
| 30150 |
|
| 30151 |
-- Inspect all entities defined in the scope of the type, looking for |
| 30152 |
-- components of a type that does not yield a synchronized object or |
| 30153 |
-- for discriminants with default values. |
| 30154 |
|
| 30155 |
Id := First_Entity (Typ); |
| 30156 |
while Present (Id) loop |
| 30157 |
if Comes_From_Source (Id) then |
| 30158 |
if Ekind (Id) = E_Component then |
| 30159 |
if Yields_Synchronized_Object (Etype (Id)) then |
| 30160 |
Has_Sync_Comp := True; |
| 30161 |
|
| 30162 |
-- The component does not yield a synchronized object |
| 30163 |
|
| 30164 |
else |
| 30165 |
return False; |
| 30166 |
end if; |
| 30167 |
|
| 30168 |
elsif Ekind (Id) = E_Discriminant |
| 30169 |
and then Present (Expression (Parent (Id))) |
| 30170 |
then |
| 30171 |
return False; |
| 30172 |
end if; |
| 30173 |
end if; |
| 30174 |
|
| 30175 |
Next_Entity (Id); |
| 30176 |
end loop; |
| 30177 |
|
| 30178 |
-- Ensure that the parent type of a type extension yields a |
| 30179 |
-- synchronized object. |
| 30180 |
|
| 30181 |
if Etype (Typ) /= Typ |
| 30182 |
and then not Is_Private_Type (Etype (Typ)) |
| 30183 |
and then not Yields_Synchronized_Object (Etype (Typ)) |
| 30184 |
then |
| 30185 |
return False; |
| 30186 |
end if; |
| 30187 |
|
| 30188 |
-- If we get here, then all discriminants lack default values and all |
| 30189 |
-- components are of a type that yields a synchronized object. |
| 30190 |
|
| 30191 |
return Has_Sync_Comp; |
| 30192 |
|
| 30193 |
-- A synchronized interface type yields a synchronized object by default |
| 30194 |
|
| 30195 |
elsif Is_Synchronized_Interface (Typ) then |
| 30196 |
return True; |
| 30197 |
|
| 30198 |
-- A task type yields a synchronized object by default |
| 30199 |
|
| 30200 |
elsif Is_Task_Type (Typ) then |
| 30201 |
return True; |
| 30202 |
|
| 30203 |
-- A private type yields a synchronized object if its underlying type |
| 30204 |
-- does. |
| 30205 |
|
| 30206 |
elsif Is_Private_Type (Typ) |
| 30207 |
and then Present (Underlying_Type (Typ)) |
| 30208 |
then |
| 30209 |
return Yields_Synchronized_Object (Underlying_Type (Typ)); |
| 30210 |
|
| 30211 |
-- Otherwise the type does not yield a synchronized object |
| 30212 |
|
| 30213 |
else |
| 30214 |
return False; |
| 30215 |
end if; |
| 30216 |
end Yields_Synchronized_Object; |
| 30217 |
|
| 30218 |
--------------------------- |
| 30219 |
-- Yields_Universal_Type -- |
| 30220 |
--------------------------- |
| 30221 |
|
| 30222 |
function Yields_Universal_Type (N : Node_Id) return Boolean is |
| 30223 |
begin |
| 30224 |
-- Integer and real literals are of a universal type |
| 30225 |
|
| 30226 |
if Nkind (N) in N_Integer_Literal | N_Real_Literal then |
| 30227 |
return True; |
| 30228 |
|
| 30229 |
-- The values of certain attributes are of a universal type |
| 30230 |
|
| 30231 |
elsif Nkind (N) = N_Attribute_Reference then |
| 30232 |
return |
| 30233 |
Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N))); |
| 30234 |
|
| 30235 |
-- ??? There are possibly other cases to consider |
| 30236 |
|
| 30237 |
else |
| 30238 |
return False; |
| 30239 |
end if; |
| 30240 |
end Yields_Universal_Type; |
| 30241 |
|
| 30242 |
package body Interval_Lists is |
| 30243 |
|
| 30244 |
procedure Check_Consistency (Intervals : Discrete_Interval_List); |
| 30245 |
-- Check that list is sorted, lacks null intervals, and has gaps |
| 30246 |
-- between intervals. |
| 30247 |
|
| 30248 |
function Chosen_Interval (Choice : Node_Id) return Discrete_Interval; |
| 30249 |
-- Given an element of a Discrete_Choices list, a |
| 30250 |
-- Static_Discrete_Predicate list, or an Others_Discrete_Choices |
| 30251 |
-- list (but not an N_Others_Choice node) return the corresponding |
| 30252 |
-- interval. If an element that does not represent a single |
| 30253 |
-- contiguous interval due to a static predicate (or which |
| 30254 |
-- represents a single contiguous interval whose bounds depend on |
| 30255 |
-- a static predicate) is encountered, then that is an error on the |
| 30256 |
-- part of whoever built the list in question. |
| 30257 |
|
| 30258 |
function In_Interval |
| 30259 |
(Value : Uint; Interval : Discrete_Interval) return Boolean; |
| 30260 |
-- Does the given value lie within the given interval? |
| 30261 |
|
| 30262 |
procedure Normalize_Interval_List |
| 30263 |
(List : in out Discrete_Interval_List; Last : out Nat); |
| 30264 |
-- Perform sorting and merging as required by Check_Consistency |
| 30265 |
|
| 30266 |
------------------------- |
| 30267 |
-- Aggregate_Intervals -- |
| 30268 |
------------------------- |
| 30269 |
|
| 30270 |
function Aggregate_Intervals (N : Node_Id) return Discrete_Interval_List |
| 30271 |
is |
| 30272 |
pragma Assert (Nkind (N) = N_Aggregate |
| 30273 |
and then Is_Array_Type (Etype (N))); |
| 30274 |
|
| 30275 |
function Unmerged_Intervals_Count return Nat; |
| 30276 |
-- Count the number of intervals given in the aggregate N; the others |
| 30277 |
-- choice (if present) is not taken into account. |
| 30278 |
|
| 30279 |
------------------------------ |
| 30280 |
-- Unmerged_Intervals_Count -- |
| 30281 |
------------------------------ |
| 30282 |
|
| 30283 |
function Unmerged_Intervals_Count return Nat is |
| 30284 |
Count : Nat := 0; |
| 30285 |
Choice : Node_Id; |
| 30286 |
Comp : Node_Id; |
| 30287 |
begin |
| 30288 |
Comp := First (Component_Associations (N)); |
| 30289 |
while Present (Comp) loop |
| 30290 |
Choice := First (Choices (Comp)); |
| 30291 |
|
| 30292 |
while Present (Choice) loop |
| 30293 |
if Nkind (Choice) /= N_Others_Choice then |
| 30294 |
Count := Count + 1; |
| 30295 |
end if; |
| 30296 |
|
| 30297 |
Next (Choice); |
| 30298 |
end loop; |
| 30299 |
|
| 30300 |
Next (Comp); |
| 30301 |
end loop; |
| 30302 |
|
| 30303 |
return Count; |
| 30304 |
end Unmerged_Intervals_Count; |
| 30305 |
|
| 30306 |
-- Local variables |
| 30307 |
|
| 30308 |
Comp : Node_Id; |
| 30309 |
Max_I : constant Nat := Unmerged_Intervals_Count; |
| 30310 |
Intervals : Discrete_Interval_List (1 .. Max_I); |
| 30311 |
Num_I : Nat := 0; |
| 30312 |
|
| 30313 |
-- Start of processing for Aggregate_Intervals |
| 30314 |
|
| 30315 |
begin |
| 30316 |
-- No action needed if there are no intervals |
| 30317 |
|
| 30318 |
if Max_I = 0 then |
| 30319 |
return Intervals; |
| 30320 |
end if; |
| 30321 |
|
| 30322 |
-- Internally store all the unsorted intervals |
| 30323 |
|
| 30324 |
Comp := First (Component_Associations (N)); |
| 30325 |
while Present (Comp) loop |
| 30326 |
declare |
| 30327 |
Choice_Intervals : constant Discrete_Interval_List := |
| 30328 |
Choice_List_Intervals (Choices (Comp)); |
| 30329 |
begin |
| 30330 |
for J in Choice_Intervals'Range loop |
| 30331 |
Num_I := Num_I + 1; |
| 30332 |
Intervals (Num_I) := Choice_Intervals (J); |
| 30333 |
end loop; |
| 30334 |
end; |
| 30335 |
|
| 30336 |
Next (Comp); |
| 30337 |
end loop; |
| 30338 |
|
| 30339 |
-- Normalize the lists sorting and merging the intervals |
| 30340 |
|
| 30341 |
declare |
| 30342 |
Aggr_Intervals : Discrete_Interval_List (1 .. Num_I) := |
| 30343 |
Intervals (1 .. Num_I); |
| 30344 |
begin |
| 30345 |
Normalize_Interval_List (Aggr_Intervals, Num_I); |
| 30346 |
Check_Consistency (Aggr_Intervals (1 .. Num_I)); |
| 30347 |
return Aggr_Intervals (1 .. Num_I); |
| 30348 |
end; |
| 30349 |
end Aggregate_Intervals; |
| 30350 |
|
| 30351 |
------------------------ |
| 30352 |
-- Check_Consistency -- |
| 30353 |
------------------------ |
| 30354 |
|
| 30355 |
procedure Check_Consistency (Intervals : Discrete_Interval_List) is |
| 30356 |
begin |
| 30357 |
if Serious_Errors_Detected > 0 then |
| 30358 |
return; |
| 30359 |
end if; |
| 30360 |
|
| 30361 |
-- low bound is 1 and high bound equals length |
| 30362 |
pragma Assert (Intervals'First = 1 and Intervals'Last >= 0); |
| 30363 |
for Idx in Intervals'Range loop |
| 30364 |
-- each interval is non-null |
| 30365 |
pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High); |
| 30366 |
if Idx /= Intervals'First then |
| 30367 |
-- intervals are sorted with non-empty gaps between them |
| 30368 |
pragma Assert |
| 30369 |
(Intervals (Idx - 1).High < (Intervals (Idx).Low - 1)); |
| 30370 |
null; |
| 30371 |
end if; |
| 30372 |
end loop; |
| 30373 |
end Check_Consistency; |
| 30374 |
|
| 30375 |
--------------------------- |
| 30376 |
-- Choice_List_Intervals -- |
| 30377 |
--------------------------- |
| 30378 |
|
| 30379 |
function Choice_List_Intervals |
| 30380 |
(Discrete_Choices : List_Id) return Discrete_Interval_List |
| 30381 |
is |
| 30382 |
function Unmerged_Choice_Count return Nat; |
| 30383 |
-- The number of intervals before adjacent intervals are merged |
| 30384 |
|
| 30385 |
--------------------------- |
| 30386 |
-- Unmerged_Choice_Count -- |
| 30387 |
--------------------------- |
| 30388 |
|
| 30389 |
function Unmerged_Choice_Count return Nat is |
| 30390 |
Choice : Node_Id := First (Discrete_Choices); |
| 30391 |
Count : Nat := 0; |
| 30392 |
begin |
| 30393 |
while Present (Choice) loop |
| 30394 |
-- Non-contiguous choices involving static predicates |
| 30395 |
-- have already been normalized away. |
| 30396 |
|
| 30397 |
if Nkind (Choice) = N_Others_Choice then |
| 30398 |
Count := |
| 30399 |
Count + List_Length (Others_Discrete_Choices (Choice)); |
| 30400 |
else |
| 30401 |
Count := Count + 1; -- an ordinary expression or range |
| 30402 |
end if; |
| 30403 |
|
| 30404 |
Next (Choice); |
| 30405 |
end loop; |
| 30406 |
return Count; |
| 30407 |
end Unmerged_Choice_Count; |
| 30408 |
|
| 30409 |
-- Local variables |
| 30410 |
|
| 30411 |
Choice : Node_Id := First (Discrete_Choices); |
| 30412 |
Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count); |
| 30413 |
Count : Nat := 0; |
| 30414 |
|
| 30415 |
-- Start of processing for Choice_List_Intervals |
| 30416 |
|
| 30417 |
begin |
| 30418 |
while Present (Choice) loop |
| 30419 |
if Nkind (Choice) = N_Others_Choice then |
| 30420 |
declare |
| 30421 |
Others_Choice : Node_Id := |
| 30422 |
First (Others_Discrete_Choices (Choice)); |
| 30423 |
begin |
| 30424 |
while Present (Others_Choice) loop |
| 30425 |
Count := Count + 1; |
| 30426 |
Result (Count) := Chosen_Interval (Others_Choice); |
| 30427 |
Next (Others_Choice); |
| 30428 |
end loop; |
| 30429 |
end; |
| 30430 |
else |
| 30431 |
Count := Count + 1; |
| 30432 |
Result (Count) := Chosen_Interval (Choice); |
| 30433 |
end if; |
| 30434 |
|
| 30435 |
Next (Choice); |
| 30436 |
end loop; |
| 30437 |
|
| 30438 |
pragma Assert (Count = Result'Last); |
| 30439 |
Normalize_Interval_List (Result, Count); |
| 30440 |
Check_Consistency (Result (1 .. Count)); |
| 30441 |
return Result (1 .. Count); |
| 30442 |
end Choice_List_Intervals; |
| 30443 |
|
| 30444 |
--------------------- |
| 30445 |
-- Chosen_Interval -- |
| 30446 |
--------------------- |
| 30447 |
|
| 30448 |
function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is |
| 30449 |
begin |
| 30450 |
case Nkind (Choice) is |
| 30451 |
when N_Range => |
| 30452 |
return (Low => Expr_Value (Low_Bound (Choice)), |
| 30453 |
High => Expr_Value (High_Bound (Choice))); |
| 30454 |
|
| 30455 |
when N_Subtype_Indication => |
| 30456 |
declare |
| 30457 |
Range_Exp : constant Node_Id := |
| 30458 |
Range_Expression (Constraint (Choice)); |
| 30459 |
begin |
| 30460 |
return (Low => Expr_Value (Low_Bound (Range_Exp)), |
| 30461 |
High => Expr_Value (High_Bound (Range_Exp))); |
| 30462 |
end; |
| 30463 |
|
| 30464 |
when N_Others_Choice => |
| 30465 |
raise Program_Error; |
| 30466 |
|
| 30467 |
when others => |
| 30468 |
if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice)) |
| 30469 |
then |
| 30470 |
return |
| 30471 |
(Low => Expr_Value (Type_Low_Bound (Entity (Choice))), |
| 30472 |
High => Expr_Value (Type_High_Bound (Entity (Choice)))); |
| 30473 |
else |
| 30474 |
-- an expression |
| 30475 |
return (Low | High => Expr_Value (Choice)); |
| 30476 |
end if; |
| 30477 |
end case; |
| 30478 |
end Chosen_Interval; |
| 30479 |
|
| 30480 |
----------------- |
| 30481 |
-- In_Interval -- |
| 30482 |
----------------- |
| 30483 |
|
| 30484 |
function In_Interval |
| 30485 |
(Value : Uint; Interval : Discrete_Interval) return Boolean is |
| 30486 |
begin |
| 30487 |
return Value >= Interval.Low and then Value <= Interval.High; |
| 30488 |
end In_Interval; |
| 30489 |
|
| 30490 |
--------------- |
| 30491 |
-- Is_Subset -- |
| 30492 |
--------------- |
| 30493 |
|
| 30494 |
function Is_Subset |
| 30495 |
(Subset, Of_Set : Discrete_Interval_List) return Boolean |
| 30496 |
is |
| 30497 |
-- Returns True iff for each interval of Subset we can find |
| 30498 |
-- a single interval of Of_Set which contains the Subset interval. |
| 30499 |
begin |
| 30500 |
if Of_Set'Length = 0 then |
| 30501 |
return Subset'Length = 0; |
| 30502 |
end if; |
| 30503 |
|
| 30504 |
declare |
| 30505 |
Set_Index : Pos range Of_Set'Range := Of_Set'First; |
| 30506 |
|
| 30507 |
begin |
| 30508 |
for Ss_Idx in Subset'Range loop |
| 30509 |
while not In_Interval |
| 30510 |
(Value => Subset (Ss_Idx).Low, |
| 30511 |
Interval => Of_Set (Set_Index)) |
| 30512 |
loop |
| 30513 |
if Set_Index = Of_Set'Last then |
| 30514 |
return False; |
| 30515 |
end if; |
| 30516 |
|
| 30517 |
Set_Index := Set_Index + 1; |
| 30518 |
end loop; |
| 30519 |
|
| 30520 |
if not In_Interval |
| 30521 |
(Value => Subset (Ss_Idx).High, |
| 30522 |
Interval => Of_Set (Set_Index)) |
| 30523 |
then |
| 30524 |
return False; |
| 30525 |
end if; |
| 30526 |
end loop; |
| 30527 |
end; |
| 30528 |
|
| 30529 |
return True; |
| 30530 |
end Is_Subset; |
| 30531 |
|
| 30532 |
----------------------------- |
| 30533 |
-- Normalize_Interval_List -- |
| 30534 |
----------------------------- |
| 30535 |
|
| 30536 |
procedure Normalize_Interval_List |
| 30537 |
(List : in out Discrete_Interval_List; Last : out Nat) |
| 30538 |
is |
| 30539 |
Temp_0 : Discrete_Interval := (others => Uint_0); |
| 30540 |
-- Cope with Heap_Sort_G idiosyncrasies. |
| 30541 |
|
| 30542 |
function Is_Null (Idx : Pos) return Boolean; |
| 30543 |
-- True iff List (Idx) defines a null range |
| 30544 |
|
| 30545 |
function Lt_Interval (Idx1, Idx2 : Natural) return Boolean; |
| 30546 |
-- Compare two list elements |
| 30547 |
|
| 30548 |
procedure Merge_Intervals (Null_Interval_Count : out Nat); |
| 30549 |
-- Merge contiguous ranges by replacing one with merged range and |
| 30550 |
-- the other with a null value. Return a count of the null intervals, |
| 30551 |
-- both preexisting and those introduced by merging. |
| 30552 |
|
| 30553 |
procedure Move_Interval (From, To : Natural); |
| 30554 |
-- Copy interval from one location to another |
| 30555 |
|
| 30556 |
function Read_Interval (From : Natural) return Discrete_Interval; |
| 30557 |
-- Normal array indexing unless From = 0 |
| 30558 |
|
| 30559 |
---------------------- |
| 30560 |
-- Interval_Sorting -- |
| 30561 |
---------------------- |
| 30562 |
|
| 30563 |
package Interval_Sorting is |
| 30564 |
new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval); |
| 30565 |
|
| 30566 |
------------- |
| 30567 |
-- Is_Null -- |
| 30568 |
------------- |
| 30569 |
|
| 30570 |
function Is_Null (Idx : Pos) return Boolean is |
| 30571 |
begin |
| 30572 |
return List (Idx).Low > List (Idx).High; |
| 30573 |
end Is_Null; |
| 30574 |
|
| 30575 |
----------------- |
| 30576 |
-- Lt_Interval -- |
| 30577 |
----------------- |
| 30578 |
|
| 30579 |
function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is |
| 30580 |
Elem1 : constant Discrete_Interval := Read_Interval (Idx1); |
| 30581 |
Elem2 : constant Discrete_Interval := Read_Interval (Idx2); |
| 30582 |
Null_1 : constant Boolean := Elem1.Low > Elem1.High; |
| 30583 |
Null_2 : constant Boolean := Elem2.Low > Elem2.High; |
| 30584 |
begin |
| 30585 |
if Null_1 /= Null_2 then |
| 30586 |
-- So that sorting moves null intervals to high end |
| 30587 |
return Null_2; |
| 30588 |
|
| 30589 |
elsif Elem1.Low /= Elem2.Low then |
| 30590 |
return Elem1.Low < Elem2.Low; |
| 30591 |
|
| 30592 |
else |
| 30593 |
return Elem1.High < Elem2.High; |
| 30594 |
end if; |
| 30595 |
end Lt_Interval; |
| 30596 |
|
| 30597 |
--------------------- |
| 30598 |
-- Merge_Intervals -- |
| 30599 |
--------------------- |
| 30600 |
|
| 30601 |
procedure Merge_Intervals (Null_Interval_Count : out Nat) is |
| 30602 |
Not_Null : Pos range List'Range; |
| 30603 |
-- Index of the most recently examined non-null interval |
| 30604 |
|
| 30605 |
Null_Interval : constant Discrete_Interval := |
| 30606 |
(Low => Uint_1, High => Uint_0); -- any null range ok here |
| 30607 |
begin |
| 30608 |
if List'Length = 0 or else Is_Null (List'First) then |
| 30609 |
Null_Interval_Count := List'Length; |
| 30610 |
-- no non-null elements, so no merge candidates |
| 30611 |
return; |
| 30612 |
end if; |
| 30613 |
|
| 30614 |
Null_Interval_Count := 0; |
| 30615 |
Not_Null := List'First; |
| 30616 |
|
| 30617 |
for Idx in List'First + 1 .. List'Last loop |
| 30618 |
if Is_Null (Idx) then |
| 30619 |
|
| 30620 |
-- all remaining elements are null |
| 30621 |
|
| 30622 |
Null_Interval_Count := |
| 30623 |
Null_Interval_Count + List (Idx .. List'Last)'Length; |
| 30624 |
return; |
| 30625 |
|
| 30626 |
elsif List (Idx).Low = List (Not_Null).High + 1 then |
| 30627 |
|
| 30628 |
-- Merge the two intervals into one; discard the other |
| 30629 |
|
| 30630 |
List (Not_Null).High := List (Idx).High; |
| 30631 |
List (Idx) := Null_Interval; |
| 30632 |
Null_Interval_Count := Null_Interval_Count + 1; |
| 30633 |
|
| 30634 |
else |
| 30635 |
if List (Idx).Low <= List (Not_Null).High then |
| 30636 |
raise Intervals_Error; |
| 30637 |
end if; |
| 30638 |
|
| 30639 |
pragma Assert (List (Idx).Low > List (Not_Null).High); |
| 30640 |
Not_Null := Idx; |
| 30641 |
end if; |
| 30642 |
end loop; |
| 30643 |
end Merge_Intervals; |
| 30644 |
|
| 30645 |
------------------- |
| 30646 |
-- Move_Interval -- |
| 30647 |
------------------- |
| 30648 |
|
| 30649 |
procedure Move_Interval (From, To : Natural) is |
| 30650 |
Rhs : constant Discrete_Interval := Read_Interval (From); |
| 30651 |
begin |
| 30652 |
if To = 0 then |
| 30653 |
Temp_0 := Rhs; |
| 30654 |
else |
| 30655 |
List (Pos (To)) := Rhs; |
| 30656 |
end if; |
| 30657 |
end Move_Interval; |
| 30658 |
|
| 30659 |
------------------- |
| 30660 |
-- Read_Interval -- |
| 30661 |
------------------- |
| 30662 |
|
| 30663 |
function Read_Interval (From : Natural) return Discrete_Interval is |
| 30664 |
begin |
| 30665 |
if From = 0 then |
| 30666 |
return Temp_0; |
| 30667 |
else |
| 30668 |
return List (Pos (From)); |
| 30669 |
end if; |
| 30670 |
end Read_Interval; |
| 30671 |
|
| 30672 |
-- Start of processing for Normalize_Interval_Lists |
| 30673 |
|
| 30674 |
begin |
| 30675 |
Interval_Sorting.Sort (Natural (List'Last)); |
| 30676 |
|
| 30677 |
declare |
| 30678 |
Null_Interval_Count : Nat; |
| 30679 |
|
| 30680 |
begin |
| 30681 |
Merge_Intervals (Null_Interval_Count); |
| 30682 |
Last := List'Last - Null_Interval_Count; |
| 30683 |
|
| 30684 |
if Null_Interval_Count /= 0 then |
| 30685 |
-- Move null intervals introduced during merging to high end |
| 30686 |
Interval_Sorting.Sort (Natural (List'Last)); |
| 30687 |
end if; |
| 30688 |
end; |
| 30689 |
end Normalize_Interval_List; |
| 30690 |
|
| 30691 |
-------------------- |
| 30692 |
-- Type_Intervals -- |
| 30693 |
-------------------- |
| 30694 |
|
| 30695 |
function Type_Intervals (Typ : Entity_Id) return Discrete_Interval_List |
| 30696 |
is |
| 30697 |
begin |
| 30698 |
if Has_Static_Predicate (Typ) then |
| 30699 |
declare |
| 30700 |
-- No sorting or merging needed |
| 30701 |
SDP_List : constant List_Id := Static_Discrete_Predicate (Typ); |
| 30702 |
Range_Or_Expr : Node_Id := First (SDP_List); |
| 30703 |
Result : Discrete_Interval_List (1 .. List_Length (SDP_List)); |
| 30704 |
|
| 30705 |
begin |
| 30706 |
for Idx in Result'Range loop |
| 30707 |
Result (Idx) := Chosen_Interval (Range_Or_Expr); |
| 30708 |
Next (Range_Or_Expr); |
| 30709 |
end loop; |
| 30710 |
|
| 30711 |
pragma Assert (No (Range_Or_Expr)); |
| 30712 |
Check_Consistency (Result); |
| 30713 |
return Result; |
| 30714 |
end; |
| 30715 |
else |
| 30716 |
declare |
| 30717 |
Low : constant Uint := Expr_Value (Type_Low_Bound (Typ)); |
| 30718 |
High : constant Uint := Expr_Value (Type_High_Bound (Typ)); |
| 30719 |
begin |
| 30720 |
if Low > High then |
| 30721 |
declare |
| 30722 |
Null_Array : Discrete_Interval_List (1 .. 0); |
| 30723 |
begin |
| 30724 |
return Null_Array; |
| 30725 |
end; |
| 30726 |
else |
| 30727 |
return (1 => (Low => Low, High => High)); |
| 30728 |
end if; |
| 30729 |
end; |
| 30730 |
end if; |
| 30731 |
end Type_Intervals; |
| 30732 |
|
| 30733 |
end Interval_Lists; |
| 30734 |
|
| 30735 |
package body Old_Attr_Util is |
| 30736 |
package body Conditional_Evaluation is |
| 30737 |
type Determining_Expr_Context is |
| 30738 |
(No_Context, If_Expr, Case_Expr, Short_Circuit_Op, Membership_Test); |
| 30739 |
|
| 30740 |
-- Determining_Expr_Context enumeration elements (except for |
| 30741 |
-- No_Context) correspond to the list items in RM 6.1.1 definition |
| 30742 |
-- of "determining expression". |
| 30743 |
|
| 30744 |
type Determining_Expr |
| 30745 |
(Context : Determining_Expr_Context := No_Context) |
| 30746 |
is record |
| 30747 |
Expr : Node_Id := Empty; |
| 30748 |
case Context is |
| 30749 |
when Short_Circuit_Op => |
| 30750 |
Is_And_Then : Boolean; |
| 30751 |
when If_Expr => |
| 30752 |
Is_Then_Part : Boolean; |
| 30753 |
when Case_Expr => |
| 30754 |
Alternatives : Node_Id; |
| 30755 |
when Membership_Test => |
| 30756 |
-- Given a subexpression of <exp4> in a membership test |
| 30757 |
-- <exp1> in <exp2> | <exp3> | <exp4> | <exp5> |
| 30758 |
-- the corresponding determining expression value would |
| 30759 |
-- have First_Non_Preceding = <exp4> (See RM 6.1.1). |
| 30760 |
First_Non_Preceding : Node_Id; |
| 30761 |
when No_Context => |
| 30762 |
null; |
| 30763 |
end case; |
| 30764 |
end record; |
| 30765 |
|
| 30766 |
type Determining_Expression_List is |
| 30767 |
array (Positive range <>) of Determining_Expr; |
| 30768 |
|
| 30769 |
function Determining_Condition (Det : Determining_Expr) |
| 30770 |
return Node_Id; |
| 30771 |
-- Given a determining expression, build a Boolean-valued |
| 30772 |
-- condition that incorporates that expression into condition |
| 30773 |
-- suitable for deciding whether to initialize a 'Old constant. |
| 30774 |
-- Polarity is "True => initialize the constant". |
| 30775 |
|
| 30776 |
function Determining_Expressions |
| 30777 |
(Expr : Node_Id; Expr_Trailer : Node_Id := Empty) |
| 30778 |
return Determining_Expression_List; |
| 30779 |
-- Given a conditionally evaluated expression, return its |
| 30780 |
-- determining expressions. |
| 30781 |
-- See RM 6.1.1 for definition of term "determining expressions". |
| 30782 |
-- Tests should be performed in the order they occur in the |
| 30783 |
-- array, with short circuiting. |
| 30784 |
-- A determining expression need not be of a boolean type (e.g., |
| 30785 |
-- it might be the determining expression of a case expression). |
| 30786 |
-- The Expr_Trailer parameter should be defaulted for nonrecursive |
| 30787 |
-- calls. |
| 30788 |
|
| 30789 |
function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean; |
| 30790 |
-- See RM 6.1.1 for definition of term "conditionally evaluated". |
| 30791 |
|
| 30792 |
function Is_Known_On_Entry (Expr : Node_Id) return Boolean; |
| 30793 |
-- See RM 6.1.1 for definition of term "known on entry". |
| 30794 |
|
| 30795 |
-------------------------------------- |
| 30796 |
-- Conditional_Evaluation_Condition -- |
| 30797 |
-------------------------------------- |
| 30798 |
|
| 30799 |
function Conditional_Evaluation_Condition |
| 30800 |
(Expr : Node_Id) return Node_Id |
| 30801 |
is |
| 30802 |
Determiners : constant Determining_Expression_List := |
| 30803 |
Determining_Expressions (Expr); |
| 30804 |
Loc : constant Source_Ptr := Sloc (Expr); |
| 30805 |
Result : Node_Id := |
| 30806 |
New_Occurrence_Of (Standard_True, Loc); |
| 30807 |
begin |
| 30808 |
pragma Assert (Determiners'Length > 0 or else |
| 30809 |
Is_Anonymous_Access_Type (Etype (Expr))); |
| 30810 |
|
| 30811 |
for I in Determiners'Range loop |
| 30812 |
Result := Make_And_Then |
| 30813 |
(Loc, |
| 30814 |
Left_Opnd => Result, |
| 30815 |
Right_Opnd => |
| 30816 |
Determining_Condition (Determiners (I))); |
| 30817 |
end loop; |
| 30818 |
return Result; |
| 30819 |
end Conditional_Evaluation_Condition; |
| 30820 |
|
| 30821 |
--------------------------- |
| 30822 |
-- Determining_Condition -- |
| 30823 |
--------------------------- |
| 30824 |
|
| 30825 |
function Determining_Condition (Det : Determining_Expr) return Node_Id |
| 30826 |
is |
| 30827 |
Loc : constant Source_Ptr := Sloc (Det.Expr); |
| 30828 |
begin |
| 30829 |
case Det.Context is |
| 30830 |
when Short_Circuit_Op => |
| 30831 |
if Det.Is_And_Then then |
| 30832 |
return New_Copy_Tree (Det.Expr); |
| 30833 |
else |
| 30834 |
return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr)); |
| 30835 |
end if; |
| 30836 |
|
| 30837 |
when If_Expr => |
| 30838 |
if Det.Is_Then_Part then |
| 30839 |
return New_Copy_Tree (Det.Expr); |
| 30840 |
else |
| 30841 |
return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr)); |
| 30842 |
end if; |
| 30843 |
|
| 30844 |
when Case_Expr => |
| 30845 |
declare |
| 30846 |
Alts : List_Id := Discrete_Choices (Det.Alternatives); |
| 30847 |
begin |
| 30848 |
if Nkind (First (Alts)) = N_Others_Choice then |
| 30849 |
Alts := Others_Discrete_Choices (First (Alts)); |
| 30850 |
end if; |
| 30851 |
|
| 30852 |
return Make_In (Loc, |
| 30853 |
Left_Opnd => New_Copy_Tree (Det.Expr), |
| 30854 |
Right_Opnd => Empty, |
| 30855 |
Alternatives => New_Copy_List (Alts)); |
| 30856 |
end; |
| 30857 |
|
| 30858 |
when Membership_Test => |
| 30859 |
declare |
| 30860 |
function Copy_Prefix |
| 30861 |
(List : List_Id; Suffix_Start : Node_Id) |
| 30862 |
return List_Id; |
| 30863 |
-- Given a list and a member of that list, returns |
| 30864 |
-- a copy (similar to Nlists.New_Copy_List) of the |
| 30865 |
-- prefix of the list up to but not including |
| 30866 |
-- Suffix_Start. |
| 30867 |
|
| 30868 |
----------------- |
| 30869 |
-- Copy_Prefix -- |
| 30870 |
----------------- |
| 30871 |
|
| 30872 |
function Copy_Prefix |
| 30873 |
(List : List_Id; Suffix_Start : Node_Id) |
| 30874 |
return List_Id |
| 30875 |
is |
| 30876 |
Result : constant List_Id := New_List; |
| 30877 |
Elem : Node_Id := First (List); |
| 30878 |
begin |
| 30879 |
while Elem /= Suffix_Start loop |
| 30880 |
Append (New_Copy (Elem), Result); |
| 30881 |
Next (Elem); |
| 30882 |
pragma Assert (Present (Elem)); |
| 30883 |
end loop; |
| 30884 |
return Result; |
| 30885 |
end Copy_Prefix; |
| 30886 |
|
| 30887 |
begin |
| 30888 |
return Make_In (Loc, |
| 30889 |
Left_Opnd => New_Copy_Tree (Left_Opnd (Det.Expr)), |
| 30890 |
Right_Opnd => Empty, |
| 30891 |
Alternatives => Copy_Prefix |
| 30892 |
(Alternatives (Det.Expr), |
| 30893 |
Det.First_Non_Preceding)); |
| 30894 |
end; |
| 30895 |
|
| 30896 |
when No_Context => |
| 30897 |
raise Program_Error; |
| 30898 |
end case; |
| 30899 |
end Determining_Condition; |
| 30900 |
|
| 30901 |
----------------------------- |
| 30902 |
-- Determining_Expressions -- |
| 30903 |
----------------------------- |
| 30904 |
|
| 30905 |
function Determining_Expressions |
| 30906 |
(Expr : Node_Id; Expr_Trailer : Node_Id := Empty) |
| 30907 |
return Determining_Expression_List |
| 30908 |
is |
| 30909 |
Par : Node_Id := Expr; |
| 30910 |
Trailer : Node_Id := Expr_Trailer; |
| 30911 |
Next_Element : Determining_Expr; |
| 30912 |
begin |
| 30913 |
-- We want to stop climbing up the tree when we reach the |
| 30914 |
-- postcondition expression. An aspect_specification is |
| 30915 |
-- transformed into a pragma, so reaching a pragma is our |
| 30916 |
-- termination condition. This relies on the fact that |
| 30917 |
-- pragmas are not allowed in declare expressions (or any |
| 30918 |
-- other kind of expression). |
| 30919 |
|
| 30920 |
loop |
| 30921 |
Next_Element.Expr := Empty; |
| 30922 |
|
| 30923 |
case Nkind (Par) is |
| 30924 |
when N_Short_Circuit => |
| 30925 |
if Trailer = Right_Opnd (Par) then |
| 30926 |
Next_Element := |
| 30927 |
(Expr => Left_Opnd (Par), |
| 30928 |
Context => Short_Circuit_Op, |
| 30929 |
Is_And_Then => Nkind (Par) = N_And_Then); |
| 30930 |
end if; |
| 30931 |
|
| 30932 |
when N_If_Expression => |
| 30933 |
-- For an expression like |
| 30934 |
-- (if C1 then ... elsif C2 then ... else Foo'Old) |
| 30935 |
-- the RM says are two determining expressions, |
| 30936 |
-- C1 and C2. Our treatment here (where we only add |
| 30937 |
-- one determining expression to the list) is ok because |
| 30938 |
-- we will see two if-expressions, one within the other. |
| 30939 |
|
| 30940 |
if Trailer /= First (Expressions (Par)) then |
| 30941 |
Next_Element := |
| 30942 |
(Expr => First (Expressions (Par)), |
| 30943 |
Context => If_Expr, |
| 30944 |
Is_Then_Part => |
| 30945 |
Trailer = Next (First (Expressions (Par)))); |
| 30946 |
end if; |
| 30947 |
|
| 30948 |
when N_Case_Expression_Alternative => |
| 30949 |
pragma Assert (Nkind (Parent (Par)) = N_Case_Expression); |
| 30950 |
|
| 30951 |
Next_Element := |
| 30952 |
(Expr => Expression (Parent (Par)), |
| 30953 |
Context => Case_Expr, |
| 30954 |
Alternatives => Par); |
| 30955 |
|
| 30956 |
when N_Membership_Test => |
| 30957 |
if Trailer /= Left_Opnd (Par) |
| 30958 |
and then Is_Non_Empty_List (Alternatives (Par)) |
| 30959 |
and then Trailer /= First (Alternatives (Par)) |
| 30960 |
then |
| 30961 |
pragma Assert (No (Right_Opnd (Par))); |
| 30962 |
pragma Assert |
| 30963 |
(Is_List_Member (Trailer) |
| 30964 |
and then List_Containing (Trailer) |
| 30965 |
= Alternatives (Par)); |
| 30966 |
|
| 30967 |
-- This one is different than the others |
| 30968 |
-- because one element in the array result |
| 30969 |
-- may represent multiple determining |
| 30970 |
-- expressions (i.e. every member of the list |
| 30971 |
-- Alternatives (Par) |
| 30972 |
-- up to but not including Trailer). |
| 30973 |
|
| 30974 |
Next_Element := |
| 30975 |
(Expr => Par, |
| 30976 |
Context => Membership_Test, |
| 30977 |
First_Non_Preceding => Trailer); |
| 30978 |
end if; |
| 30979 |
|
| 30980 |
when N_Pragma => |
| 30981 |
pragma Assert |
| 30982 |
(Get_Pragma_Id (Pragma_Name (Par)) in |
| 30983 |
Pragma_Check |
| 30984 |
| Pragma_Contract_Cases |
| 30985 |
| Pragma_Exceptional_Cases |
| 30986 |
| Pragma_Exit_Cases |
| 30987 |
| Pragma_Post |
| 30988 |
| Pragma_Postcondition |
| 30989 |
| Pragma_Post_Class |
| 30990 |
| Pragma_Refined_Post |
| 30991 |
| Pragma_Test_Case); |
| 30992 |
|
| 30993 |
return (1 .. 0 => <>); -- recursion terminates here |
| 30994 |
|
| 30995 |
when N_Empty => |
| 30996 |
-- This case should be impossible, but if it does |
| 30997 |
-- happen somehow then we don't want an infinite loop. |
| 30998 |
raise Program_Error; |
| 30999 |
|
| 31000 |
when others => |
| 31001 |
null; |
| 31002 |
end case; |
| 31003 |
|
| 31004 |
Trailer := Par; |
| 31005 |
Par := Parent (Par); |
| 31006 |
|
| 31007 |
if Present (Next_Element.Expr) then |
| 31008 |
return Determining_Expressions |
| 31009 |
(Expr => Par, Expr_Trailer => Trailer) |
| 31010 |
& Next_Element; |
| 31011 |
end if; |
| 31012 |
end loop; |
| 31013 |
end Determining_Expressions; |
| 31014 |
|
| 31015 |
----------------------------------------- |
| 31016 |
-- Eligible_For_Conditional_Evaluation -- |
| 31017 |
----------------------------------------- |
| 31018 |
|
| 31019 |
function Eligible_For_Conditional_Evaluation |
| 31020 |
(Expr : Node_Id) return Boolean |
| 31021 |
is |
| 31022 |
begin |
| 31023 |
if Is_Anonymous_Access_Type (Etype (Expr)) then |
| 31024 |
-- The code in exp_attr.adb that also builds declarations |
| 31025 |
-- for 'Old constants doesn't handle the anonymous access |
| 31026 |
-- type case correctly, so we avoid that problem by |
| 31027 |
-- returning True here. |
| 31028 |
return True; |
| 31029 |
|
| 31030 |
elsif Ada_Version < Ada_2022 then |
| 31031 |
return False; |
| 31032 |
|
| 31033 |
elsif Inside_Class_Condition_Preanalysis then |
| 31034 |
-- No need to evaluate it during preanalysis of a class-wide |
| 31035 |
-- pre/postcondition since the expression is not installed yet |
| 31036 |
-- on its definite context. |
| 31037 |
return False; |
| 31038 |
|
| 31039 |
elsif not Is_Conditionally_Evaluated (Expr) then |
| 31040 |
return False; |
| 31041 |
else |
| 31042 |
declare |
| 31043 |
Determiners : constant Determining_Expression_List := |
| 31044 |
Determining_Expressions (Expr); |
| 31045 |
begin |
| 31046 |
pragma Assert (if Serious_Errors_Detected = 0 then |
| 31047 |
Determiners'Length > 0); |
| 31048 |
|
| 31049 |
for Idx in Determiners'Range loop |
| 31050 |
if not Is_Known_On_Entry (Determiners (Idx).Expr) then |
| 31051 |
return False; |
| 31052 |
end if; |
| 31053 |
end loop; |
| 31054 |
end; |
| 31055 |
return True; |
| 31056 |
end if; |
| 31057 |
end Eligible_For_Conditional_Evaluation; |
| 31058 |
|
| 31059 |
-------------------------------- |
| 31060 |
-- Is_Conditionally_Evaluated -- |
| 31061 |
-------------------------------- |
| 31062 |
|
| 31063 |
function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean |
| 31064 |
is |
| 31065 |
-- There are three possibilities - the expression is |
| 31066 |
-- unconditionally evaluated, repeatedly evaluated, or |
| 31067 |
-- conditionally evaluated (see RM 6.1.1). So we implement |
| 31068 |
-- this test by testing for the other two. |
| 31069 |
|
| 31070 |
function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean; |
| 31071 |
-- See RM 6.1.1 for definition of "repeatedly evaluated". |
| 31072 |
|
| 31073 |
----------------------------- |
| 31074 |
-- Is_Repeatedly_Evaluated -- |
| 31075 |
----------------------------- |
| 31076 |
|
| 31077 |
function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean is |
| 31078 |
Par : Node_Id := Expr; |
| 31079 |
Trailer : Node_Id := Empty; |
| 31080 |
|
| 31081 |
-- There are three ways that an expression can be repeatedly |
| 31082 |
-- evaluated. |
| 31083 |
begin |
| 31084 |
-- An aspect_specification is transformed into a pragma, so |
| 31085 |
-- reaching a pragma is our termination condition. We want to |
| 31086 |
-- stop when we reach the postcondition expression. |
| 31087 |
|
| 31088 |
while Nkind (Par) /= N_Pragma loop |
| 31089 |
pragma Assert (Present (Par)); |
| 31090 |
|
| 31091 |
-- test for case 1: |
| 31092 |
-- A subexpression of a predicate of a |
| 31093 |
-- quantified_expression. |
| 31094 |
|
| 31095 |
if Nkind (Par) = N_Quantified_Expression |
| 31096 |
and then Trailer = Condition (Par) |
| 31097 |
then |
| 31098 |
return True; |
| 31099 |
elsif Nkind (Par) = N_Expression_With_Actions |
| 31100 |
and then |
| 31101 |
Nkind (Original_Node (Par)) = N_Quantified_Expression |
| 31102 |
then |
| 31103 |
return True; |
| 31104 |
end if; |
| 31105 |
|
| 31106 |
-- test for cases 2 and 3: |
| 31107 |
-- A subexpression of the expression of an |
| 31108 |
-- array_component_association or of |
| 31109 |
-- a container_element_associatiation. |
| 31110 |
|
| 31111 |
if Nkind (Par) in N_Component_Association |
| 31112 |
| N_Iterated_Component_Association |
| 31113 |
and then Trailer = Expression (Par) |
| 31114 |
then |
| 31115 |
-- determine whether Par is part of an array aggregate |
| 31116 |
-- or a container aggregate |
| 31117 |
declare |
| 31118 |
Rover : Node_Id := Par; |
| 31119 |
begin |
| 31120 |
while Nkind (Rover) not in N_Has_Etype loop |
| 31121 |
pragma Assert (Present (Rover)); |
| 31122 |
Rover := Parent (Rover); |
| 31123 |
end loop; |
| 31124 |
if Present (Etype (Rover)) then |
| 31125 |
if Is_Array_Type (Etype (Rover)) |
| 31126 |
or else Is_Container_Aggregate (Rover) |
| 31127 |
then |
| 31128 |
return True; |
| 31129 |
end if; |
| 31130 |
end if; |
| 31131 |
end; |
| 31132 |
end if; |
| 31133 |
|
| 31134 |
Trailer := Par; |
| 31135 |
Par := Parent (Par); |
| 31136 |
end loop; |
| 31137 |
|
| 31138 |
return False; |
| 31139 |
end Is_Repeatedly_Evaluated; |
| 31140 |
|
| 31141 |
begin |
| 31142 |
if not Is_Potentially_Unevaluated (Expr) then |
| 31143 |
-- the expression is unconditionally evaluated |
| 31144 |
return False; |
| 31145 |
elsif Is_Repeatedly_Evaluated (Expr) then |
| 31146 |
return False; |
| 31147 |
end if; |
| 31148 |
|
| 31149 |
return True; |
| 31150 |
end Is_Conditionally_Evaluated; |
| 31151 |
|
| 31152 |
----------------------- |
| 31153 |
-- Is_Known_On_Entry -- |
| 31154 |
----------------------- |
| 31155 |
|
| 31156 |
function Is_Known_On_Entry (Expr : Node_Id) return Boolean is |
| 31157 |
-- ??? This implementation is incomplete. See RM 6.1.1 |
| 31158 |
-- for details. In particular, this function *should* return |
| 31159 |
-- True for a function call (or a user-defined literal, which |
| 31160 |
-- is equivalent to a function call) if all actual parameters |
| 31161 |
-- (including defaulted params) are known on entry and the |
| 31162 |
-- function has "Globals => null" specified; the current |
| 31163 |
-- implementation will incorrectly return False in this case. |
| 31164 |
|
| 31165 |
function All_Exps_Known_On_Entry |
| 31166 |
(Expr_List : List_Id) return Boolean; |
| 31167 |
-- Given a list of expressions, returns False iff |
| 31168 |
-- Is_Known_On_Entry is False for at least one list element. |
| 31169 |
|
| 31170 |
----------------------------- |
| 31171 |
-- All_Exps_Known_On_Entry -- |
| 31172 |
----------------------------- |
| 31173 |
|
| 31174 |
function All_Exps_Known_On_Entry |
| 31175 |
(Expr_List : List_Id) return Boolean |
| 31176 |
is |
| 31177 |
Expr : Node_Id := First (Expr_List); |
| 31178 |
begin |
| 31179 |
while Present (Expr) loop |
| 31180 |
if not Is_Known_On_Entry (Expr) then |
| 31181 |
return False; |
| 31182 |
end if; |
| 31183 |
Next (Expr); |
| 31184 |
end loop; |
| 31185 |
return True; |
| 31186 |
end All_Exps_Known_On_Entry; |
| 31187 |
|
| 31188 |
begin |
| 31189 |
if Is_Static_Expression (Expr) then |
| 31190 |
return True; |
| 31191 |
end if; |
| 31192 |
|
| 31193 |
if Is_Attribute_Old (Expr) then |
| 31194 |
return True; |
| 31195 |
end if; |
| 31196 |
|
| 31197 |
declare |
| 31198 |
Pref : Node_Id := Expr; |
| 31199 |
begin |
| 31200 |
loop |
| 31201 |
case Nkind (Pref) is |
| 31202 |
when N_Selected_Component => |
| 31203 |
null; |
| 31204 |
|
| 31205 |
when N_Indexed_Component => |
| 31206 |
if not All_Exps_Known_On_Entry (Expressions (Pref)) |
| 31207 |
then |
| 31208 |
return False; |
| 31209 |
end if; |
| 31210 |
|
| 31211 |
when N_Slice => |
| 31212 |
return False; -- just to be clear about this case |
| 31213 |
|
| 31214 |
when others => |
| 31215 |
exit; |
| 31216 |
end case; |
| 31217 |
|
| 31218 |
Pref := Prefix (Pref); |
| 31219 |
end loop; |
| 31220 |
|
| 31221 |
if Is_Entity_Name (Pref) |
| 31222 |
and then Is_Constant_Object (Entity (Pref)) |
| 31223 |
then |
| 31224 |
declare |
| 31225 |
Obj : constant Entity_Id := Entity (Pref); |
| 31226 |
Obj_Typ : constant Entity_Id := Etype (Obj); |
| 31227 |
begin |
| 31228 |
case Ekind (Obj) is |
| 31229 |
when E_In_Parameter => |
| 31230 |
if not Is_Elementary_Type (Obj_Typ) then |
| 31231 |
return False; |
| 31232 |
elsif Is_Aliased (Obj) then |
| 31233 |
return False; |
| 31234 |
end if; |
| 31235 |
|
| 31236 |
when E_Constant => |
| 31237 |
-- return False for a deferred constant |
| 31238 |
if Present (Full_View (Obj)) then |
| 31239 |
return False; |
| 31240 |
end if; |
| 31241 |
|
| 31242 |
-- Handle constants introduced by side-effect |
| 31243 |
-- removal, e.g. by validity checks. |
| 31244 |
|
| 31245 |
if not Comes_From_Source (Obj) then |
| 31246 |
declare |
| 31247 |
D : constant Node_Id := |
| 31248 |
Declaration_Node (Obj); |
| 31249 |
begin |
| 31250 |
if Nkind (D) = N_Object_Renaming_Declaration |
| 31251 |
then |
| 31252 |
return Is_Known_On_Entry (Name (D)); |
| 31253 |
else |
| 31254 |
return Is_Known_On_Entry (Expression (D)); |
| 31255 |
end if; |
| 31256 |
end; |
| 31257 |
end if; |
| 31258 |
|
| 31259 |
-- return False if not "all views are constant". |
| 31260 |
if Is_Immutably_Limited_Type (Obj_Typ) |
| 31261 |
or Needs_Finalization (Obj_Typ) |
| 31262 |
then |
| 31263 |
return False; |
| 31264 |
end if; |
| 31265 |
|
| 31266 |
when others => |
| 31267 |
null; |
| 31268 |
end case; |
| 31269 |
end; |
| 31270 |
|
| 31271 |
return True; |
| 31272 |
end if; |
| 31273 |
|
| 31274 |
-- ??? Cope with a malformed tree. Code to cope with a |
| 31275 |
-- nonstatic use of an enumeration literal should not be |
| 31276 |
-- necessary. |
| 31277 |
if Is_Entity_Name (Pref) |
| 31278 |
and then Ekind (Entity (Pref)) = E_Enumeration_Literal |
| 31279 |
then |
| 31280 |
return True; |
| 31281 |
end if; |
| 31282 |
end; |
| 31283 |
|
| 31284 |
case Nkind (Expr) is |
| 31285 |
when N_Unary_Op => |
| 31286 |
return Is_Known_On_Entry (Right_Opnd (Expr)); |
| 31287 |
|
| 31288 |
when N_Binary_Op => |
| 31289 |
return Is_Known_On_Entry (Left_Opnd (Expr)) |
| 31290 |
and then Is_Known_On_Entry (Right_Opnd (Expr)); |
| 31291 |
|
| 31292 |
when N_Type_Conversion | N_Qualified_Expression => |
| 31293 |
return Is_Known_On_Entry (Expression (Expr)); |
| 31294 |
|
| 31295 |
when N_If_Expression => |
| 31296 |
return All_Exps_Known_On_Entry (Expressions (Expr)); |
| 31297 |
|
| 31298 |
when N_Case_Expression => |
| 31299 |
if not Is_Known_On_Entry (Expression (Expr)) then |
| 31300 |
return False; |
| 31301 |
end if; |
| 31302 |
|
| 31303 |
declare |
| 31304 |
Alt : Node_Id := First (Alternatives (Expr)); |
| 31305 |
begin |
| 31306 |
while Present (Alt) loop |
| 31307 |
if not Is_Known_On_Entry (Expression (Alt)) then |
| 31308 |
return False; |
| 31309 |
end if; |
| 31310 |
Next (Alt); |
| 31311 |
end loop; |
| 31312 |
end; |
| 31313 |
|
| 31314 |
return True; |
| 31315 |
|
| 31316 |
when others => |
| 31317 |
return False; |
| 31318 |
end case; |
| 31319 |
end Is_Known_On_Entry; |
| 31320 |
|
| 31321 |
end Conditional_Evaluation; |
| 31322 |
|
| 31323 |
package body Indirect_Temps is |
| 31324 |
|
| 31325 |
Indirect_Temp_Access_Type_Char : constant Character := 'K'; |
| 31326 |
-- The character passed to Make_Temporary when declaring |
| 31327 |
-- the access type that is used in the implementation of an |
| 31328 |
-- indirect temporary. |
| 31329 |
|
| 31330 |
-------------------------- |
| 31331 |
-- Indirect_Temp_Needed -- |
| 31332 |
-------------------------- |
| 31333 |
|
| 31334 |
function Indirect_Temp_Needed (Typ : Entity_Id) return Boolean is |
| 31335 |
begin |
| 31336 |
-- There should be no correctness issues if the only cases where |
| 31337 |
-- this function returns False are cases where Typ is an |
| 31338 |
-- anonymous access type and we need to generate a saooaaat (a |
| 31339 |
-- stand-alone object of an anonymous access type) in order get |
| 31340 |
-- accessibility right. In other cases where this function |
| 31341 |
-- returns False, there would be no correctness problems with |
| 31342 |
-- returning True instead; however, returning False when we can |
| 31343 |
-- generally results in simpler code. |
| 31344 |
|
| 31345 |
return False |
| 31346 |
|
| 31347 |
-- If Typ is not definite, then we cannot generate |
| 31348 |
-- Temp : Typ; |
| 31349 |
|
| 31350 |
or else not Is_Definite_Subtype (Typ) |
| 31351 |
|
| 31352 |
-- If Typ is tagged, then generating |
| 31353 |
-- Temp : Typ; |
| 31354 |
-- might generate an object with the wrong tag. If we had |
| 31355 |
-- a predicate that indicated whether the nominal tag is |
| 31356 |
-- trustworthy, we could use that predicate here. |
| 31357 |
|
| 31358 |
or else Is_Tagged_Type (Typ) |
| 31359 |
|
| 31360 |
-- If Typ needs finalization, then generating an implicit |
| 31361 |
-- Temp : Typ; |
| 31362 |
-- declaration could have user-visible side effects. |
| 31363 |
|
| 31364 |
or else Needs_Finalization (Typ) |
| 31365 |
|
| 31366 |
-- In the anonymous access type case, we need to |
| 31367 |
-- generate a saooaaat. We don't want the code in |
| 31368 |
-- in exp_attr.adb that deals with the case where this |
| 31369 |
-- function returns False to have to deal with that case |
| 31370 |
-- (just to avoid code duplication). So we cheat a little |
| 31371 |
-- bit and return True here for an anonymous access type. |
| 31372 |
|
| 31373 |
or else Is_Anonymous_Access_Type (Typ); |
| 31374 |
|
| 31375 |
-- ??? Unimplemented - spec description says: |
| 31376 |
-- For an unconstrained-but-definite discriminated subtype, |
| 31377 |
-- returns True if the potential difference in size between an |
| 31378 |
-- unconstrained object and a constrained object is large. |
| 31379 |
-- |
| 31380 |
-- For example, |
| 31381 |
-- type Typ (Len : Natural := 0) is |
| 31382 |
-- record F : String (1 .. Len); end record; |
| 31383 |
-- |
| 31384 |
-- See Large_Max_Size_Mutable function elsewhere in this file, |
| 31385 |
-- currently declared inside of Needs_Secondary_Stack, so it |
| 31386 |
-- would have to be moved if we want it to be callable from here. |
| 31387 |
|
| 31388 |
end Indirect_Temp_Needed; |
| 31389 |
|
| 31390 |
--------------------------- |
| 31391 |
-- Declare_Indirect_Temp -- |
| 31392 |
--------------------------- |
| 31393 |
|
| 31394 |
procedure Declare_Indirect_Temp |
| 31395 |
(Attr_Prefix : Node_Id; Indirect_Temp : out Entity_Id) |
| 31396 |
is |
| 31397 |
Loc : constant Source_Ptr := Sloc (Attr_Prefix); |
| 31398 |
Prefix_Type : constant Entity_Id := Etype (Attr_Prefix); |
| 31399 |
Temp_Id : constant Entity_Id := |
| 31400 |
Make_Temporary (Loc, 'P', Attr_Prefix); |
| 31401 |
|
| 31402 |
procedure Declare_Indirect_Temp_Via_Allocation; |
| 31403 |
-- Handle the usual case. |
| 31404 |
|
| 31405 |
------------------------------------------- |
| 31406 |
-- Declare_Indirect_Temp_Via_Allocation -- |
| 31407 |
------------------------------------------- |
| 31408 |
|
| 31409 |
procedure Declare_Indirect_Temp_Via_Allocation is |
| 31410 |
Access_Type_Id : constant Entity_Id := |
| 31411 |
Make_Temporary |
| 31412 |
(Loc, Indirect_Temp_Access_Type_Char, Attr_Prefix); |
| 31413 |
|
| 31414 |
Temp_Decl : constant Node_Id := |
| 31415 |
Make_Object_Declaration (Loc, |
| 31416 |
Defining_Identifier => Temp_Id, |
| 31417 |
Object_Definition => |
| 31418 |
New_Occurrence_Of (Access_Type_Id, Loc)); |
| 31419 |
|
| 31420 |
Allocate_Class_Wide : constant Boolean := |
| 31421 |
Is_Specific_Tagged_Type (Prefix_Type); |
| 31422 |
-- If True then access type designates the class-wide type in |
| 31423 |
-- order to preserve (at run time) the value of the underlying |
| 31424 |
-- tag. |
| 31425 |
-- ??? We could do better here (in the case where Prefix_Type |
| 31426 |
-- is tagged and specific) if we had a predicate which takes an |
| 31427 |
-- expression and returns True iff the expression is of |
| 31428 |
-- a specific tagged type and the underlying tag (at run time) |
| 31429 |
-- is statically known to match that of the specific type. |
| 31430 |
-- In that case, Allocate_Class_Wide could safely be False. |
| 31431 |
|
| 31432 |
function Designated_Subtype_Mark return Node_Id; |
| 31433 |
-- Usually, a subtype mark indicating the subtype of the |
| 31434 |
-- attribute prefix. If that subtype is a specific tagged |
| 31435 |
-- type, then returns the corresponding class-wide type. |
| 31436 |
-- If the prefix is of an anonymous access type, then returns |
| 31437 |
-- the designated type of that type. |
| 31438 |
|
| 31439 |
----------------------------- |
| 31440 |
-- Designated_Subtype_Mark -- |
| 31441 |
----------------------------- |
| 31442 |
|
| 31443 |
function Designated_Subtype_Mark return Node_Id is |
| 31444 |
Typ : Entity_Id := Prefix_Type; |
| 31445 |
begin |
| 31446 |
if Allocate_Class_Wide then |
| 31447 |
if Is_Private_Type (Typ) |
| 31448 |
and then Present (Full_View (Typ)) |
| 31449 |
then |
| 31450 |
Typ := Full_View (Typ); |
| 31451 |
end if; |
| 31452 |
Typ := Class_Wide_Type (Typ); |
| 31453 |
end if; |
| 31454 |
|
| 31455 |
return New_Occurrence_Of (Typ, Loc); |
| 31456 |
end Designated_Subtype_Mark; |
| 31457 |
|
| 31458 |
Access_Type_Def : constant Node_Id := |
| 31459 |
Make_Access_To_Object_Definition |
| 31460 |
(Loc, Subtype_Indication => Designated_Subtype_Mark); |
| 31461 |
|
| 31462 |
Access_Type_Decl : constant Node_Id := |
| 31463 |
Make_Full_Type_Declaration |
| 31464 |
(Loc, Access_Type_Id, |
| 31465 |
Type_Definition => Access_Type_Def); |
| 31466 |
begin |
| 31467 |
Mutate_Ekind (Temp_Id, E_Variable); |
| 31468 |
Set_Etype (Temp_Id, Access_Type_Id); |
| 31469 |
Mutate_Ekind (Access_Type_Id, E_Access_Type); |
| 31470 |
|
| 31471 |
if Append_Decls_In_Reverse_Order then |
| 31472 |
Append_Item (Temp_Decl, Is_Eval_Stmt => False); |
| 31473 |
Append_Item (Access_Type_Decl, Is_Eval_Stmt => False); |
| 31474 |
else |
| 31475 |
Append_Item (Access_Type_Decl, Is_Eval_Stmt => False); |
| 31476 |
Append_Item (Temp_Decl, Is_Eval_Stmt => False); |
| 31477 |
end if; |
| 31478 |
|
| 31479 |
-- When a type associated with an indirect temporary gets |
| 31480 |
-- created for a 'Old attribute reference we need to mark |
| 31481 |
-- the type as such. This allows, for example, finalization |
| 31482 |
-- collections associated with them to be finalized in the |
| 31483 |
-- correct order after postcondition checks. |
| 31484 |
|
| 31485 |
if Attribute_Name (Parent (Attr_Prefix)) = Name_Old then |
| 31486 |
Set_Stores_Attribute_Old_Prefix (Access_Type_Id); |
| 31487 |
end if; |
| 31488 |
|
| 31489 |
Analyze (Access_Type_Decl); |
| 31490 |
Analyze (Temp_Decl); |
| 31491 |
|
| 31492 |
pragma Assert |
| 31493 |
(Is_Access_Type_For_Indirect_Temp (Access_Type_Id)); |
| 31494 |
|
| 31495 |
declare |
| 31496 |
Expression : Node_Id := Attr_Prefix; |
| 31497 |
Allocator : Node_Id; |
| 31498 |
begin |
| 31499 |
if Allocate_Class_Wide then |
| 31500 |
-- generate T'Class'(T'Class (<prefix>)) |
| 31501 |
Expression := |
| 31502 |
Make_Type_Conversion (Loc, |
| 31503 |
Subtype_Mark => Designated_Subtype_Mark, |
| 31504 |
Expression => Expression); |
| 31505 |
end if; |
| 31506 |
|
| 31507 |
Allocator := |
| 31508 |
Make_Allocator (Loc, |
| 31509 |
Expression => |
| 31510 |
Make_Qualified_Expression |
| 31511 |
(Loc, |
| 31512 |
Subtype_Mark => Designated_Subtype_Mark, |
| 31513 |
Expression => Expression)); |
| 31514 |
|
| 31515 |
-- Allocate saved prefix value on the secondary stack |
| 31516 |
-- in order to avoid introducing a storage leak. This |
| 31517 |
-- allocated object is never explicitly reclaimed. |
| 31518 |
-- |
| 31519 |
-- ??? Emit storage leak warning if RE_SS_Pool |
| 31520 |
-- unavailable? |
| 31521 |
|
| 31522 |
if RTE_Available (RE_SS_Pool) then |
| 31523 |
Set_Storage_Pool (Allocator, RTE (RE_SS_Pool)); |
| 31524 |
Set_Procedure_To_Call |
| 31525 |
(Allocator, RTE (RE_SS_Allocate)); |
| 31526 |
Set_Uses_Sec_Stack (Current_Scope); |
| 31527 |
end if; |
| 31528 |
|
| 31529 |
Append_Item |
| 31530 |
(Make_Assignment_Statement (Loc, |
| 31531 |
Name => New_Occurrence_Of (Temp_Id, Loc), |
| 31532 |
Expression => Allocator), |
| 31533 |
Is_Eval_Stmt => True); |
| 31534 |
end; |
| 31535 |
end Declare_Indirect_Temp_Via_Allocation; |
| 31536 |
|
| 31537 |
begin |
| 31538 |
Indirect_Temp := Temp_Id; |
| 31539 |
|
| 31540 |
if Is_Anonymous_Access_Type (Prefix_Type) then |
| 31541 |
-- In the anonymous access type case, we do not want a level |
| 31542 |
-- indirection (which would result in declaring an |
| 31543 |
-- access-to-access type); that would result in correctness |
| 31544 |
-- problems - the accessibility level of the type of the |
| 31545 |
-- 'Old constant would be wrong (See 6.1.1.). So in that case, |
| 31546 |
-- we do not generate an allocator. Instead we generate |
| 31547 |
-- Temp : access Designated := null; |
| 31548 |
-- which is unconditionally elaborated and then |
| 31549 |
-- Temp := <attribute prefix>; |
| 31550 |
-- which is conditionally executed. |
| 31551 |
|
| 31552 |
declare |
| 31553 |
Temp_Decl : constant Node_Id := |
| 31554 |
Make_Object_Declaration (Loc, |
| 31555 |
Defining_Identifier => Temp_Id, |
| 31556 |
Object_Definition => |
| 31557 |
Make_Access_Definition |
| 31558 |
(Loc, |
| 31559 |
Constant_Present => |
| 31560 |
Is_Access_Constant (Prefix_Type), |
| 31561 |
Subtype_Mark => |
| 31562 |
New_Occurrence_Of |
| 31563 |
(Designated_Type (Prefix_Type), Loc))); |
| 31564 |
begin |
| 31565 |
Append_Item (Temp_Decl, Is_Eval_Stmt => False); |
| 31566 |
Analyze (Temp_Decl); |
| 31567 |
Append_Item |
| 31568 |
(Make_Assignment_Statement (Loc, |
| 31569 |
Name => New_Occurrence_Of (Temp_Id, Loc), |
| 31570 |
Expression => Attr_Prefix), |
| 31571 |
Is_Eval_Stmt => True); |
| 31572 |
end; |
| 31573 |
else |
| 31574 |
-- the usual case |
| 31575 |
Declare_Indirect_Temp_Via_Allocation; |
| 31576 |
end if; |
| 31577 |
end Declare_Indirect_Temp; |
| 31578 |
|
| 31579 |
------------------------- |
| 31580 |
-- Indirect_Temp_Value -- |
| 31581 |
------------------------- |
| 31582 |
|
| 31583 |
function Indirect_Temp_Value |
| 31584 |
(Temp : Entity_Id; |
| 31585 |
Typ : Entity_Id; |
| 31586 |
Loc : Source_Ptr) return Node_Id |
| 31587 |
is |
| 31588 |
Result : Node_Id; |
| 31589 |
begin |
| 31590 |
if Is_Anonymous_Access_Type (Typ) then |
| 31591 |
-- No indirection in this case; just evaluate the temp. |
| 31592 |
return New_Occurrence_Of (Temp, Loc); |
| 31593 |
|
| 31594 |
else |
| 31595 |
Result := Make_Explicit_Dereference (Loc, |
| 31596 |
New_Occurrence_Of (Temp, Loc)); |
| 31597 |
|
| 31598 |
Set_Etype (Result, Designated_Type (Etype (Temp))); |
| 31599 |
|
| 31600 |
if Is_Specific_Tagged_Type (Typ) then |
| 31601 |
-- The designated type of the access type is class-wide, so |
| 31602 |
-- convert to the specific type. |
| 31603 |
|
| 31604 |
Result := |
| 31605 |
Make_Type_Conversion (Loc, |
| 31606 |
Subtype_Mark => New_Occurrence_Of (Typ, Loc), |
| 31607 |
Expression => Result); |
| 31608 |
|
| 31609 |
Set_Etype (Result, Typ); |
| 31610 |
end if; |
| 31611 |
|
| 31612 |
return Result; |
| 31613 |
end if; |
| 31614 |
end Indirect_Temp_Value; |
| 31615 |
|
| 31616 |
-------------------------------------- |
| 31617 |
-- Is_Access_Type_For_Indirect_Temp -- |
| 31618 |
-------------------------------------- |
| 31619 |
|
| 31620 |
function Is_Access_Type_For_Indirect_Temp |
| 31621 |
(T : Entity_Id) return Boolean is |
| 31622 |
begin |
| 31623 |
if Is_Access_Type (T) |
| 31624 |
and then not Comes_From_Source (T) |
| 31625 |
and then Is_Internal_Name (Chars (T)) |
| 31626 |
and then Nkind (Scope (T)) in N_Entity |
| 31627 |
and then Ekind (Scope (T)) |
| 31628 |
in E_Entry | E_Entry_Family | E_Function | E_Procedure |
| 31629 |
and then |
| 31630 |
(Present (Wrapped_Statements (Scope (T))) |
| 31631 |
or else Present (Contract (Scope (T)))) |
| 31632 |
then |
| 31633 |
-- ??? Should define a flag for this. We could incorrectly |
| 31634 |
-- return True if other clients of Make_Temporary happen to |
| 31635 |
-- pass in the same character. |
| 31636 |
declare |
| 31637 |
Name : constant String := Get_Name_String (Chars (T)); |
| 31638 |
begin |
| 31639 |
if Name (Name'First) = Indirect_Temp_Access_Type_Char then |
| 31640 |
return True; |
| 31641 |
end if; |
| 31642 |
end; |
| 31643 |
end if; |
| 31644 |
|
| 31645 |
return False; |
| 31646 |
end Is_Access_Type_For_Indirect_Temp; |
| 31647 |
|
| 31648 |
end Indirect_Temps; |
| 31649 |
end Old_Attr_Util; |
| 31650 |
|
| 31651 |
package body Storage_Model_Support is |
| 31652 |
|
| 31653 |
----------------------------------------- |
| 31654 |
-- Has_Designated_Storage_Model_Aspect -- |
| 31655 |
----------------------------------------- |
| 31656 |
|
| 31657 |
function Has_Designated_Storage_Model_Aspect |
| 31658 |
(Typ : Entity_Id) return Boolean |
| 31659 |
is |
| 31660 |
begin |
| 31661 |
return Has_Aspect (Typ, Aspect_Designated_Storage_Model); |
| 31662 |
end Has_Designated_Storage_Model_Aspect; |
| 31663 |
|
| 31664 |
----------------------------------- |
| 31665 |
-- Has_Storage_Model_Type_Aspect -- |
| 31666 |
----------------------------------- |
| 31667 |
|
| 31668 |
function Has_Storage_Model_Type_Aspect (Typ : Entity_Id) return Boolean |
| 31669 |
is |
| 31670 |
begin |
| 31671 |
return Has_Aspect (Typ, Aspect_Storage_Model_Type); |
| 31672 |
end Has_Storage_Model_Type_Aspect; |
| 31673 |
|
| 31674 |
-------------------------- |
| 31675 |
-- Storage_Model_Object -- |
| 31676 |
-------------------------- |
| 31677 |
|
| 31678 |
function Storage_Model_Object (Typ : Entity_Id) return Entity_Id is |
| 31679 |
begin |
| 31680 |
pragma Assert (Has_Designated_Storage_Model_Aspect (Typ)); |
| 31681 |
|
| 31682 |
return |
| 31683 |
Entity |
| 31684 |
(Find_Value_Of_Aspect (Typ, Aspect_Designated_Storage_Model)); |
| 31685 |
end Storage_Model_Object; |
| 31686 |
|
| 31687 |
------------------------ |
| 31688 |
-- Storage_Model_Type -- |
| 31689 |
------------------------ |
| 31690 |
|
| 31691 |
function Storage_Model_Type (Obj : Entity_Id) return Entity_Id is |
| 31692 |
begin |
| 31693 |
pragma Assert (Has_Storage_Model_Type_Aspect (Etype (Obj))); |
| 31694 |
|
| 31695 |
return Etype (Obj); |
| 31696 |
end Storage_Model_Type; |
| 31697 |
|
| 31698 |
----------------------------------- |
| 31699 |
-- Get_Storage_Model_Type_Entity -- |
| 31700 |
----------------------------------- |
| 31701 |
|
| 31702 |
function Get_Storage_Model_Type_Entity |
| 31703 |
(SM_Obj_Or_Type : Entity_Id; |
| 31704 |
Nam : Name_Id) return Entity_Id |
| 31705 |
is |
| 31706 |
Typ : constant Entity_Id := (if Is_Object (SM_Obj_Or_Type) then |
| 31707 |
Storage_Model_Type (SM_Obj_Or_Type) |
| 31708 |
else |
| 31709 |
SM_Obj_Or_Type); |
| 31710 |
pragma Assert |
| 31711 |
(Is_Type (Typ) |
| 31712 |
and then |
| 31713 |
Nam in Name_Address_Type |
| 31714 |
| Name_Null_Address |
| 31715 |
| Name_Allocate |
| 31716 |
| Name_Deallocate |
| 31717 |
| Name_Copy_From |
| 31718 |
| Name_Copy_To |
| 31719 |
| Name_Storage_Size); |
| 31720 |
|
| 31721 |
Assoc : Node_Id; |
| 31722 |
SMT_Aspect_Value : constant Node_Id := |
| 31723 |
Find_Value_Of_Aspect (Typ, Aspect_Storage_Model_Type); |
| 31724 |
|
| 31725 |
begin |
| 31726 |
-- When the aspect has an aggregate expression, search through it |
| 31727 |
-- to locate a match for the name of the given "subaspect" and return |
| 31728 |
-- the entity of the aggregate association's expression. |
| 31729 |
|
| 31730 |
if Present (SMT_Aspect_Value) then |
| 31731 |
Assoc := First (Component_Associations (SMT_Aspect_Value)); |
| 31732 |
while Present (Assoc) loop |
| 31733 |
if Chars (First (Choices (Assoc))) = Nam then |
| 31734 |
return Entity (Expression (Assoc)); |
| 31735 |
end if; |
| 31736 |
|
| 31737 |
Next (Assoc); |
| 31738 |
end loop; |
| 31739 |
end if; |
| 31740 |
|
| 31741 |
-- The aggregate argument of Storage_Model_Type is optional, and when |
| 31742 |
-- not present the aspect defaults to the native storage model, where |
| 31743 |
-- the address type is System.Address. In that case, we return |
| 31744 |
-- System.Address for Name_Address_Type and System.Null_Address for |
| 31745 |
-- Name_Null_Address, but return Empty for other cases, and leave it |
| 31746 |
-- to the back end to map those to the appropriate native operations. |
| 31747 |
|
| 31748 |
if Nam = Name_Address_Type then |
| 31749 |
return RTE (RE_Address); |
| 31750 |
|
| 31751 |
elsif Nam = Name_Null_Address then |
| 31752 |
return RTE (RE_Null_Address); |
| 31753 |
|
| 31754 |
else |
| 31755 |
return Empty; |
| 31756 |
end if; |
| 31757 |
end Get_Storage_Model_Type_Entity; |
| 31758 |
|
| 31759 |
-------------------------------- |
| 31760 |
-- Storage_Model_Address_Type -- |
| 31761 |
-------------------------------- |
| 31762 |
|
| 31763 |
function Storage_Model_Address_Type |
| 31764 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31765 |
is |
| 31766 |
begin |
| 31767 |
return |
| 31768 |
Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Address_Type); |
| 31769 |
end Storage_Model_Address_Type; |
| 31770 |
|
| 31771 |
-------------------------------- |
| 31772 |
-- Storage_Model_Null_Address -- |
| 31773 |
-------------------------------- |
| 31774 |
|
| 31775 |
function Storage_Model_Null_Address |
| 31776 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31777 |
is |
| 31778 |
begin |
| 31779 |
return |
| 31780 |
Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Null_Address); |
| 31781 |
end Storage_Model_Null_Address; |
| 31782 |
|
| 31783 |
---------------------------- |
| 31784 |
-- Storage_Model_Allocate -- |
| 31785 |
---------------------------- |
| 31786 |
|
| 31787 |
function Storage_Model_Allocate |
| 31788 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31789 |
is |
| 31790 |
begin |
| 31791 |
return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Allocate); |
| 31792 |
end Storage_Model_Allocate; |
| 31793 |
|
| 31794 |
------------------------------ |
| 31795 |
-- Storage_Model_Deallocate -- |
| 31796 |
------------------------------ |
| 31797 |
|
| 31798 |
function Storage_Model_Deallocate |
| 31799 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31800 |
is |
| 31801 |
begin |
| 31802 |
return |
| 31803 |
Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Deallocate); |
| 31804 |
end Storage_Model_Deallocate; |
| 31805 |
|
| 31806 |
----------------------------- |
| 31807 |
-- Storage_Model_Copy_From -- |
| 31808 |
----------------------------- |
| 31809 |
|
| 31810 |
function Storage_Model_Copy_From |
| 31811 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31812 |
is |
| 31813 |
begin |
| 31814 |
return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_From); |
| 31815 |
end Storage_Model_Copy_From; |
| 31816 |
|
| 31817 |
--------------------------- |
| 31818 |
-- Storage_Model_Copy_To -- |
| 31819 |
--------------------------- |
| 31820 |
|
| 31821 |
function Storage_Model_Copy_To |
| 31822 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31823 |
is |
| 31824 |
begin |
| 31825 |
return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_To); |
| 31826 |
end Storage_Model_Copy_To; |
| 31827 |
|
| 31828 |
-------------------------------- |
| 31829 |
-- Storage_Model_Storage_Size -- |
| 31830 |
-------------------------------- |
| 31831 |
|
| 31832 |
function Storage_Model_Storage_Size |
| 31833 |
(SM_Obj_Or_Type : Entity_Id) return Entity_Id |
| 31834 |
is |
| 31835 |
begin |
| 31836 |
return |
| 31837 |
Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Storage_Size); |
| 31838 |
end Storage_Model_Storage_Size; |
| 31839 |
|
| 31840 |
end Storage_Model_Support; |
| 31841 |
|
| 31842 |
end Sem_Util; |