| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ A U X -- |
| 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 Atree; use Atree; |
| 27 |
with Einfo; use Einfo; |
| 28 |
with Einfo.Entities; use Einfo.Entities; |
| 29 |
with Einfo.Utils; use Einfo.Utils; |
| 30 |
with Nlists; use Nlists; |
| 31 |
with Sinfo; use Sinfo; |
| 32 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 33 |
with Sinfo.Utils; use Sinfo.Utils; |
| 34 |
with Snames; use Snames; |
| 35 |
with Stand; use Stand; |
| 36 |
with Uintp; use Uintp; |
| 37 |
|
| 38 |
package body Sem_Aux is |
| 39 |
|
| 40 |
---------------------- |
| 41 |
-- Ancestor_Subtype -- |
| 42 |
---------------------- |
| 43 |
|
| 44 |
function Ancestor_Subtype (Typ : Entity_Id) return Entity_Id is |
| 45 |
begin |
| 46 |
-- If this is first subtype, or is a base type, then there is no |
| 47 |
-- ancestor subtype, so we return Empty to indicate this fact. |
| 48 |
|
| 49 |
if Is_First_Subtype (Typ) or else Is_Base_Type (Typ) then |
| 50 |
return Empty; |
| 51 |
end if; |
| 52 |
|
| 53 |
declare |
| 54 |
D : constant Node_Id := Declaration_Node (Typ); |
| 55 |
|
| 56 |
begin |
| 57 |
-- If we have a subtype declaration, get the ancestor subtype |
| 58 |
|
| 59 |
if Nkind (D) = N_Subtype_Declaration then |
| 60 |
if Nkind (Subtype_Indication (D)) = N_Subtype_Indication then |
| 61 |
return Entity (Subtype_Mark (Subtype_Indication (D))); |
| 62 |
else |
| 63 |
return Entity (Subtype_Indication (D)); |
| 64 |
end if; |
| 65 |
|
| 66 |
-- If not, then no subtype indication is available |
| 67 |
|
| 68 |
else |
| 69 |
return Empty; |
| 70 |
end if; |
| 71 |
end; |
| 72 |
end Ancestor_Subtype; |
| 73 |
|
| 74 |
-------------------- |
| 75 |
-- Available_View -- |
| 76 |
-------------------- |
| 77 |
|
| 78 |
function Available_View (Ent : Entity_Id) return Entity_Id is |
| 79 |
begin |
| 80 |
-- Obtain the non-limited view (if available) |
| 81 |
|
| 82 |
if Has_Non_Limited_View (Ent) then |
| 83 |
return Get_Full_View (Non_Limited_View (Ent)); |
| 84 |
|
| 85 |
-- In all other cases, return entity unchanged |
| 86 |
|
| 87 |
else |
| 88 |
return Ent; |
| 89 |
end if; |
| 90 |
end Available_View; |
| 91 |
|
| 92 |
-------------------- |
| 93 |
-- Constant_Value -- |
| 94 |
-------------------- |
| 95 |
|
| 96 |
function Constant_Value (Ent : Entity_Id) return Node_Id is |
| 97 |
D : constant Node_Id := Declaration_Node (Ent); |
| 98 |
Full_D : Node_Id; |
| 99 |
|
| 100 |
begin |
| 101 |
-- If we have no declaration node, then return no constant value. Not |
| 102 |
-- clear how this can happen, but it does sometimes and this is the |
| 103 |
-- safest approach. |
| 104 |
|
| 105 |
if No (D) then |
| 106 |
return Empty; |
| 107 |
|
| 108 |
-- Normal case where a declaration node is present |
| 109 |
|
| 110 |
elsif Nkind (D) = N_Object_Renaming_Declaration then |
| 111 |
return Renamed_Object (Ent); |
| 112 |
|
| 113 |
-- If this is a component declaration whose entity is a constant, it is |
| 114 |
-- a prival within a protected function (and so has no constant value). |
| 115 |
|
| 116 |
elsif Nkind (D) = N_Component_Declaration then |
| 117 |
return Empty; |
| 118 |
|
| 119 |
-- If there is an expression, return it |
| 120 |
|
| 121 |
elsif Present (Expression (D)) then |
| 122 |
return Expression (D); |
| 123 |
|
| 124 |
-- For a constant, see if we have a full view |
| 125 |
|
| 126 |
elsif Ekind (Ent) = E_Constant |
| 127 |
and then Present (Full_View (Ent)) |
| 128 |
then |
| 129 |
Full_D := Parent (Full_View (Ent)); |
| 130 |
|
| 131 |
-- The full view may have been rewritten as an object renaming |
| 132 |
|
| 133 |
if Nkind (Full_D) = N_Object_Renaming_Declaration then |
| 134 |
return Name (Full_D); |
| 135 |
else |
| 136 |
return Expression (Full_D); |
| 137 |
end if; |
| 138 |
|
| 139 |
-- Otherwise we have no expression to return |
| 140 |
|
| 141 |
else |
| 142 |
return Empty; |
| 143 |
end if; |
| 144 |
end Constant_Value; |
| 145 |
|
| 146 |
--------------------------------- |
| 147 |
-- Corresponding_Unsigned_Type -- |
| 148 |
--------------------------------- |
| 149 |
|
| 150 |
function Corresponding_Unsigned_Type (Typ : Entity_Id) return Entity_Id is |
| 151 |
pragma Assert (Is_Signed_Integer_Type (Typ)); |
| 152 |
Siz : constant Uint := Esize (Base_Type (Typ)); |
| 153 |
begin |
| 154 |
if Siz = Esize (Standard_Short_Short_Integer) then |
| 155 |
return Standard_Short_Short_Unsigned; |
| 156 |
elsif Siz = Esize (Standard_Short_Integer) then |
| 157 |
return Standard_Short_Unsigned; |
| 158 |
elsif Siz = Esize (Standard_Unsigned) then |
| 159 |
return Standard_Unsigned; |
| 160 |
elsif Siz = Esize (Standard_Long_Integer) then |
| 161 |
return Standard_Long_Unsigned; |
| 162 |
elsif Siz = Esize (Standard_Long_Long_Integer) then |
| 163 |
return Standard_Long_Long_Unsigned; |
| 164 |
elsif Siz = Esize (Standard_Long_Long_Long_Integer) then |
| 165 |
return Standard_Long_Long_Long_Unsigned; |
| 166 |
else |
| 167 |
raise Program_Error; |
| 168 |
end if; |
| 169 |
end Corresponding_Unsigned_Type; |
| 170 |
|
| 171 |
----------------------------- |
| 172 |
-- Enclosing_Dynamic_Scope -- |
| 173 |
----------------------------- |
| 174 |
|
| 175 |
function Enclosing_Dynamic_Scope (Ent : Entity_Id) return Entity_Id is |
| 176 |
S : Entity_Id; |
| 177 |
|
| 178 |
begin |
| 179 |
-- The following test is an error defense against some syntax errors |
| 180 |
-- that can leave scopes very messed up. |
| 181 |
|
| 182 |
if Ent = Standard_Standard then |
| 183 |
return Ent; |
| 184 |
end if; |
| 185 |
|
| 186 |
-- Normal case, search enclosing scopes |
| 187 |
|
| 188 |
-- Note: the test for Present (S) should not be required, it defends |
| 189 |
-- against an ill-formed tree. |
| 190 |
|
| 191 |
S := Scope (Ent); |
| 192 |
loop |
| 193 |
-- If we somehow got an empty value for Scope, the tree must be |
| 194 |
-- malformed. Rather than blow up we return Standard in this case. |
| 195 |
|
| 196 |
if No (S) then |
| 197 |
return Standard_Standard; |
| 198 |
|
| 199 |
-- Quit if we get to standard or a dynamic scope. We must also |
| 200 |
-- handle enclosing scopes that have a full view; required to |
| 201 |
-- locate enclosing scopes that are synchronized private types |
| 202 |
-- whose full view is a task type. |
| 203 |
|
| 204 |
elsif S = Standard_Standard |
| 205 |
or else Is_Dynamic_Scope (S) |
| 206 |
or else (Is_Private_Type (S) |
| 207 |
and then Present (Full_View (S)) |
| 208 |
and then Is_Dynamic_Scope (Full_View (S))) |
| 209 |
then |
| 210 |
return S; |
| 211 |
|
| 212 |
-- Otherwise keep climbing |
| 213 |
|
| 214 |
else |
| 215 |
S := Scope (S); |
| 216 |
end if; |
| 217 |
end loop; |
| 218 |
end Enclosing_Dynamic_Scope; |
| 219 |
|
| 220 |
------------------------ |
| 221 |
-- First_Discriminant -- |
| 222 |
------------------------ |
| 223 |
|
| 224 |
function First_Discriminant (Typ : Entity_Id) return Entity_Id is |
| 225 |
Ent : Entity_Id; |
| 226 |
|
| 227 |
begin |
| 228 |
pragma Assert |
| 229 |
(Has_Discriminants (Typ) or else Has_Unknown_Discriminants (Typ)); |
| 230 |
|
| 231 |
Ent := First_Entity (Typ); |
| 232 |
|
| 233 |
-- The discriminants are not necessarily contiguous, because access |
| 234 |
-- discriminants will generate itypes. They are not the first entities |
| 235 |
-- either because the tag must be ahead of them. |
| 236 |
|
| 237 |
if Chars (Ent) = Name_uTag then |
| 238 |
Next_Entity (Ent); |
| 239 |
end if; |
| 240 |
|
| 241 |
-- Skip all hidden stored discriminants if any |
| 242 |
|
| 243 |
while Present (Ent) loop |
| 244 |
exit when Ekind (Ent) = E_Discriminant |
| 245 |
and then not Is_Completely_Hidden (Ent); |
| 246 |
|
| 247 |
Next_Entity (Ent); |
| 248 |
end loop; |
| 249 |
|
| 250 |
-- Call may be on a private type with unknown discriminants, in which |
| 251 |
-- case Ent is Empty, and as per the spec, we return Empty in this case. |
| 252 |
|
| 253 |
-- Historical note: The assertion in previous versions that Ent is a |
| 254 |
-- discriminant was overly cautious and prevented convenient application |
| 255 |
-- of this function in the gnatprove context. |
| 256 |
|
| 257 |
return Ent; |
| 258 |
end First_Discriminant; |
| 259 |
|
| 260 |
------------------------------- |
| 261 |
-- First_Stored_Discriminant -- |
| 262 |
------------------------------- |
| 263 |
|
| 264 |
function First_Stored_Discriminant (Typ : Entity_Id) return Entity_Id is |
| 265 |
Ent : Entity_Id; |
| 266 |
|
| 267 |
function Has_Completely_Hidden_Discriminant |
| 268 |
(Typ : Entity_Id) return Boolean; |
| 269 |
-- Scans the Discriminants to see whether any are Completely_Hidden |
| 270 |
-- (the mechanism for describing non-specified stored discriminants) |
| 271 |
-- Note that the entity list for the type may contain anonymous access |
| 272 |
-- types created by expressions that constrain access discriminants. |
| 273 |
|
| 274 |
---------------------------------------- |
| 275 |
-- Has_Completely_Hidden_Discriminant -- |
| 276 |
---------------------------------------- |
| 277 |
|
| 278 |
function Has_Completely_Hidden_Discriminant |
| 279 |
(Typ : Entity_Id) return Boolean |
| 280 |
is |
| 281 |
Ent : Entity_Id; |
| 282 |
|
| 283 |
begin |
| 284 |
pragma Assert (Ekind (Typ) = E_Discriminant); |
| 285 |
|
| 286 |
Ent := Typ; |
| 287 |
while Present (Ent) loop |
| 288 |
|
| 289 |
-- Skip anonymous types that may be created by expressions |
| 290 |
-- used as discriminant constraints on inherited discriminants. |
| 291 |
|
| 292 |
if Is_Itype (Ent) then |
| 293 |
null; |
| 294 |
|
| 295 |
elsif Ekind (Ent) = E_Discriminant |
| 296 |
and then Is_Completely_Hidden (Ent) |
| 297 |
then |
| 298 |
return True; |
| 299 |
end if; |
| 300 |
|
| 301 |
Next_Entity (Ent); |
| 302 |
end loop; |
| 303 |
|
| 304 |
return False; |
| 305 |
end Has_Completely_Hidden_Discriminant; |
| 306 |
|
| 307 |
-- Start of processing for First_Stored_Discriminant |
| 308 |
|
| 309 |
begin |
| 310 |
pragma Assert |
| 311 |
(Has_Discriminants (Typ) |
| 312 |
or else Has_Unknown_Discriminants (Typ)); |
| 313 |
|
| 314 |
Ent := First_Entity (Typ); |
| 315 |
|
| 316 |
if Chars (Ent) = Name_uTag then |
| 317 |
Next_Entity (Ent); |
| 318 |
end if; |
| 319 |
|
| 320 |
if Has_Completely_Hidden_Discriminant (Ent) then |
| 321 |
while Present (Ent) loop |
| 322 |
exit when Ekind (Ent) = E_Discriminant |
| 323 |
and then Is_Completely_Hidden (Ent); |
| 324 |
Next_Entity (Ent); |
| 325 |
end loop; |
| 326 |
end if; |
| 327 |
|
| 328 |
pragma Assert (Ekind (Ent) = E_Discriminant); |
| 329 |
|
| 330 |
return Ent; |
| 331 |
end First_Stored_Discriminant; |
| 332 |
|
| 333 |
------------------- |
| 334 |
-- First_Subtype -- |
| 335 |
------------------- |
| 336 |
|
| 337 |
function First_Subtype (Typ : Entity_Id) return Entity_Id is |
| 338 |
B : constant Entity_Id := Base_Type (Typ); |
| 339 |
F : Node_Id := Freeze_Node (B); |
| 340 |
Ent : Entity_Id; |
| 341 |
|
| 342 |
begin |
| 343 |
-- The freeze node of a ghost type might have been rewritten in a null |
| 344 |
-- statement by the time gigi calls First_Subtype on the corresponding |
| 345 |
-- type. |
| 346 |
|
| 347 |
if Nkind (F) = N_Null_Statement then |
| 348 |
F := Original_Node (F); |
| 349 |
end if; |
| 350 |
|
| 351 |
-- If the base type has no freeze node, it is a type in Standard, and |
| 352 |
-- always acts as its own first subtype, except where it is one of the |
| 353 |
-- predefined integer types. If the type is formal, it is also a first |
| 354 |
-- subtype, and its base type has no freeze node. On the other hand, a |
| 355 |
-- subtype of a generic formal is not its own first subtype. Its base |
| 356 |
-- type, if anonymous, is attached to the formal type declaration from |
| 357 |
-- which the first subtype is obtained. |
| 358 |
|
| 359 |
if No (F) then |
| 360 |
if B = Base_Type (Standard_Integer) then |
| 361 |
return Standard_Integer; |
| 362 |
|
| 363 |
elsif B = Base_Type (Standard_Long_Integer) then |
| 364 |
return Standard_Long_Integer; |
| 365 |
|
| 366 |
elsif B = Base_Type (Standard_Short_Short_Integer) then |
| 367 |
return Standard_Short_Short_Integer; |
| 368 |
|
| 369 |
elsif B = Base_Type (Standard_Short_Integer) then |
| 370 |
return Standard_Short_Integer; |
| 371 |
|
| 372 |
elsif B = Base_Type (Standard_Long_Long_Integer) then |
| 373 |
return Standard_Long_Long_Integer; |
| 374 |
|
| 375 |
elsif B = Base_Type (Standard_Long_Long_Long_Integer) then |
| 376 |
return Standard_Long_Long_Long_Integer; |
| 377 |
|
| 378 |
elsif Is_Generic_Type (Typ) then |
| 379 |
if Present (Parent (B)) then |
| 380 |
return Defining_Identifier (Parent (B)); |
| 381 |
else |
| 382 |
return Defining_Identifier (Associated_Node_For_Itype (B)); |
| 383 |
end if; |
| 384 |
|
| 385 |
else |
| 386 |
return B; |
| 387 |
end if; |
| 388 |
|
| 389 |
-- Otherwise we check the freeze node, if it has a First_Subtype_Link |
| 390 |
-- then we use that link, otherwise (happens with some Itypes), we use |
| 391 |
-- the base type itself. |
| 392 |
|
| 393 |
else |
| 394 |
Ent := First_Subtype_Link (F); |
| 395 |
|
| 396 |
if Present (Ent) then |
| 397 |
return Ent; |
| 398 |
else |
| 399 |
return B; |
| 400 |
end if; |
| 401 |
end if; |
| 402 |
end First_Subtype; |
| 403 |
|
| 404 |
------------------------- |
| 405 |
-- First_Tag_Component -- |
| 406 |
------------------------- |
| 407 |
|
| 408 |
function First_Tag_Component (Typ : Entity_Id) return Entity_Id is |
| 409 |
Comp : Entity_Id; |
| 410 |
Ctyp : Entity_Id; |
| 411 |
|
| 412 |
begin |
| 413 |
pragma Assert (Is_Tagged_Type (Typ) |
| 414 |
or else Is_Class_Wide_Equivalent_Type (Typ)); |
| 415 |
|
| 416 |
Ctyp := Typ; |
| 417 |
|
| 418 |
if Is_Class_Wide_Type (Ctyp) then |
| 419 |
Ctyp := Root_Type (Ctyp); |
| 420 |
end if; |
| 421 |
|
| 422 |
if Is_Private_Type (Ctyp) then |
| 423 |
Ctyp := Underlying_Type (Ctyp); |
| 424 |
|
| 425 |
-- If the underlying type is missing then the source program has |
| 426 |
-- errors and there is nothing else to do (the full-type declaration |
| 427 |
-- associated with the private type declaration is missing). |
| 428 |
|
| 429 |
if No (Ctyp) then |
| 430 |
return Empty; |
| 431 |
end if; |
| 432 |
end if; |
| 433 |
|
| 434 |
Comp := First_Entity (Ctyp); |
| 435 |
while Present (Comp) loop |
| 436 |
if Is_Tag (Comp) then |
| 437 |
return Comp; |
| 438 |
end if; |
| 439 |
|
| 440 |
Next_Entity (Comp); |
| 441 |
end loop; |
| 442 |
|
| 443 |
-- No tag component found |
| 444 |
|
| 445 |
return Empty; |
| 446 |
end First_Tag_Component; |
| 447 |
|
| 448 |
----------------------- |
| 449 |
-- Get_Called_Entity -- |
| 450 |
----------------------- |
| 451 |
|
| 452 |
function Get_Called_Entity (Call : Node_Id) return Entity_Id is |
| 453 |
Nam : constant Node_Id := Name (Call); |
| 454 |
Id : Entity_Id; |
| 455 |
|
| 456 |
begin |
| 457 |
if Nkind (Nam) = N_Explicit_Dereference then |
| 458 |
Id := Etype (Nam); |
| 459 |
pragma Assert (Ekind (Id) = E_Subprogram_Type); |
| 460 |
|
| 461 |
elsif Nkind (Nam) = N_Selected_Component then |
| 462 |
Id := Entity (Selector_Name (Nam)); |
| 463 |
|
| 464 |
elsif Nkind (Nam) = N_Indexed_Component then |
| 465 |
Id := Entity (Selector_Name (Prefix (Nam))); |
| 466 |
|
| 467 |
else |
| 468 |
Id := Entity (Nam); |
| 469 |
end if; |
| 470 |
|
| 471 |
return Id; |
| 472 |
end Get_Called_Entity; |
| 473 |
|
| 474 |
------------------ |
| 475 |
-- Get_Rep_Item -- |
| 476 |
------------------ |
| 477 |
|
| 478 |
function Get_Rep_Item |
| 479 |
(E : Entity_Id; |
| 480 |
Nam : Name_Id; |
| 481 |
Check_Parents : Boolean := True) return Node_Id |
| 482 |
is |
| 483 |
N : Node_Id; |
| 484 |
|
| 485 |
begin |
| 486 |
N := First_Rep_Item (E); |
| 487 |
while Present (N) loop |
| 488 |
|
| 489 |
-- Only one of Priority / Interrupt_Priority can be specified, so |
| 490 |
-- return whichever one is present to catch illegal duplication. |
| 491 |
|
| 492 |
if Nkind (N) = N_Pragma |
| 493 |
and then |
| 494 |
(Pragma_Name_Unmapped (N) = Nam |
| 495 |
or else (Nam = Name_Priority |
| 496 |
and then Pragma_Name (N) = |
| 497 |
Name_Interrupt_Priority) |
| 498 |
or else (Nam = Name_Interrupt_Priority |
| 499 |
and then Pragma_Name (N) = Name_Priority)) |
| 500 |
then |
| 501 |
if Check_Parents then |
| 502 |
return N; |
| 503 |
|
| 504 |
-- If Check_Parents is False, return N if the pragma doesn't |
| 505 |
-- appear in the Rep_Item chain of the parent. |
| 506 |
|
| 507 |
else |
| 508 |
declare |
| 509 |
Par : constant Entity_Id := Nearest_Ancestor (E); |
| 510 |
-- This node represents the parent type of type E (if any) |
| 511 |
|
| 512 |
begin |
| 513 |
if No (Par) then |
| 514 |
return N; |
| 515 |
|
| 516 |
elsif not Present_In_Rep_Item (Par, N) then |
| 517 |
return N; |
| 518 |
end if; |
| 519 |
end; |
| 520 |
end if; |
| 521 |
|
| 522 |
elsif Nkind (N) = N_Attribute_Definition_Clause |
| 523 |
and then |
| 524 |
(Chars (N) = Nam |
| 525 |
or else (Nam = Name_Priority |
| 526 |
and then Chars (N) = Name_Interrupt_Priority)) |
| 527 |
then |
| 528 |
if Check_Parents or else Entity (N) = E then |
| 529 |
return N; |
| 530 |
end if; |
| 531 |
|
| 532 |
elsif Nkind (N) = N_Aspect_Specification |
| 533 |
and then |
| 534 |
(Chars (Identifier (N)) = Nam |
| 535 |
or else |
| 536 |
(Nam = Name_Priority |
| 537 |
and then Chars (Identifier (N)) = Name_Interrupt_Priority)) |
| 538 |
then |
| 539 |
if Check_Parents then |
| 540 |
return N; |
| 541 |
|
| 542 |
elsif Entity (N) = E then |
| 543 |
return N; |
| 544 |
end if; |
| 545 |
|
| 546 |
-- A Ghost-related aspect, if disabled, may have been replaced by a |
| 547 |
-- null statement. |
| 548 |
|
| 549 |
elsif Nkind (N) = N_Null_Statement then |
| 550 |
N := Original_Node (N); |
| 551 |
end if; |
| 552 |
|
| 553 |
Next_Rep_Item (N); |
| 554 |
end loop; |
| 555 |
|
| 556 |
return Empty; |
| 557 |
end Get_Rep_Item; |
| 558 |
|
| 559 |
function Get_Rep_Item |
| 560 |
(E : Entity_Id; |
| 561 |
Nam1 : Name_Id; |
| 562 |
Nam2 : Name_Id; |
| 563 |
Check_Parents : Boolean := True) return Node_Id |
| 564 |
is |
| 565 |
Nam1_Item : constant Node_Id := Get_Rep_Item (E, Nam1, Check_Parents); |
| 566 |
Nam2_Item : constant Node_Id := Get_Rep_Item (E, Nam2, Check_Parents); |
| 567 |
|
| 568 |
N : Node_Id; |
| 569 |
|
| 570 |
begin |
| 571 |
-- Check both Nam1_Item and Nam2_Item are present |
| 572 |
|
| 573 |
if No (Nam1_Item) then |
| 574 |
return Nam2_Item; |
| 575 |
elsif No (Nam2_Item) then |
| 576 |
return Nam1_Item; |
| 577 |
end if; |
| 578 |
|
| 579 |
-- Return the first node encountered in the list |
| 580 |
|
| 581 |
N := First_Rep_Item (E); |
| 582 |
while Present (N) loop |
| 583 |
if N = Nam1_Item or else N = Nam2_Item then |
| 584 |
return N; |
| 585 |
end if; |
| 586 |
|
| 587 |
Next_Rep_Item (N); |
| 588 |
end loop; |
| 589 |
|
| 590 |
return Empty; |
| 591 |
end Get_Rep_Item; |
| 592 |
|
| 593 |
-------------------- |
| 594 |
-- Get_Rep_Pragma -- |
| 595 |
-------------------- |
| 596 |
|
| 597 |
function Get_Rep_Pragma |
| 598 |
(E : Entity_Id; |
| 599 |
Nam : Name_Id; |
| 600 |
Check_Parents : Boolean := True) return Node_Id |
| 601 |
is |
| 602 |
N : constant Node_Id := Get_Rep_Item (E, Nam, Check_Parents); |
| 603 |
|
| 604 |
begin |
| 605 |
if Present (N) and then Nkind (N) = N_Pragma then |
| 606 |
return N; |
| 607 |
end if; |
| 608 |
|
| 609 |
return Empty; |
| 610 |
end Get_Rep_Pragma; |
| 611 |
|
| 612 |
function Get_Rep_Pragma |
| 613 |
(E : Entity_Id; |
| 614 |
Nam1 : Name_Id; |
| 615 |
Nam2 : Name_Id; |
| 616 |
Check_Parents : Boolean := True) return Node_Id |
| 617 |
is |
| 618 |
Nam1_Item : constant Node_Id := Get_Rep_Pragma (E, Nam1, Check_Parents); |
| 619 |
Nam2_Item : constant Node_Id := Get_Rep_Pragma (E, Nam2, Check_Parents); |
| 620 |
|
| 621 |
N : Node_Id; |
| 622 |
|
| 623 |
begin |
| 624 |
-- Check both Nam1_Item and Nam2_Item are present |
| 625 |
|
| 626 |
if No (Nam1_Item) then |
| 627 |
return Nam2_Item; |
| 628 |
elsif No (Nam2_Item) then |
| 629 |
return Nam1_Item; |
| 630 |
end if; |
| 631 |
|
| 632 |
-- Return the first node encountered in the list |
| 633 |
|
| 634 |
N := First_Rep_Item (E); |
| 635 |
while Present (N) loop |
| 636 |
if N = Nam1_Item or else N = Nam2_Item then |
| 637 |
return N; |
| 638 |
end if; |
| 639 |
|
| 640 |
Next_Rep_Item (N); |
| 641 |
end loop; |
| 642 |
|
| 643 |
return Empty; |
| 644 |
end Get_Rep_Pragma; |
| 645 |
|
| 646 |
--------------------------------- |
| 647 |
-- Has_External_Tag_Rep_Clause -- |
| 648 |
--------------------------------- |
| 649 |
|
| 650 |
function Has_External_Tag_Rep_Clause (T : Entity_Id) return Boolean is |
| 651 |
begin |
| 652 |
pragma Assert (Is_Tagged_Type (T)); |
| 653 |
return Has_Rep_Item (T, Name_External_Tag, Check_Parents => False); |
| 654 |
end Has_External_Tag_Rep_Clause; |
| 655 |
|
| 656 |
------------------ |
| 657 |
-- Has_Rep_Item -- |
| 658 |
------------------ |
| 659 |
|
| 660 |
function Has_Rep_Item |
| 661 |
(E : Entity_Id; |
| 662 |
Nam : Name_Id; |
| 663 |
Check_Parents : Boolean := True) return Boolean |
| 664 |
is |
| 665 |
begin |
| 666 |
return Present (Get_Rep_Item (E, Nam, Check_Parents)); |
| 667 |
end Has_Rep_Item; |
| 668 |
|
| 669 |
function Has_Rep_Item |
| 670 |
(E : Entity_Id; |
| 671 |
Nam1 : Name_Id; |
| 672 |
Nam2 : Name_Id; |
| 673 |
Check_Parents : Boolean := True) return Boolean |
| 674 |
is |
| 675 |
begin |
| 676 |
return Present (Get_Rep_Item (E, Nam1, Nam2, Check_Parents)); |
| 677 |
end Has_Rep_Item; |
| 678 |
|
| 679 |
-------------------- |
| 680 |
-- Has_Rep_Pragma -- |
| 681 |
-------------------- |
| 682 |
|
| 683 |
function Has_Rep_Pragma |
| 684 |
(E : Entity_Id; |
| 685 |
Nam : Name_Id; |
| 686 |
Check_Parents : Boolean := True) return Boolean |
| 687 |
is |
| 688 |
begin |
| 689 |
return Present (Get_Rep_Pragma (E, Nam, Check_Parents)); |
| 690 |
end Has_Rep_Pragma; |
| 691 |
|
| 692 |
function Has_Rep_Pragma |
| 693 |
(E : Entity_Id; |
| 694 |
Nam1 : Name_Id; |
| 695 |
Nam2 : Name_Id; |
| 696 |
Check_Parents : Boolean := True) return Boolean |
| 697 |
is |
| 698 |
begin |
| 699 |
return Present (Get_Rep_Pragma (E, Nam1, Nam2, Check_Parents)); |
| 700 |
end Has_Rep_Pragma; |
| 701 |
|
| 702 |
---------------------- |
| 703 |
-- Has_Variant_Part -- |
| 704 |
---------------------- |
| 705 |
|
| 706 |
function Has_Variant_Part (Typ : Entity_Id) return Boolean is |
| 707 |
FSTyp : Entity_Id; |
| 708 |
Decl : Node_Id; |
| 709 |
TDef : Node_Id; |
| 710 |
CList : Node_Id; |
| 711 |
|
| 712 |
begin |
| 713 |
FSTyp := First_Subtype (Typ); |
| 714 |
|
| 715 |
if not Has_Discriminants (FSTyp) then |
| 716 |
return False; |
| 717 |
end if; |
| 718 |
|
| 719 |
-- Proceed with cautious checks here, return False if tree is not |
| 720 |
-- as expected (may be caused by prior errors). |
| 721 |
|
| 722 |
Decl := Declaration_Node (FSTyp); |
| 723 |
|
| 724 |
if Nkind (Decl) /= N_Full_Type_Declaration then |
| 725 |
return False; |
| 726 |
end if; |
| 727 |
|
| 728 |
TDef := Type_Definition (Decl); |
| 729 |
|
| 730 |
if Nkind (TDef) /= N_Record_Definition then |
| 731 |
return False; |
| 732 |
end if; |
| 733 |
|
| 734 |
CList := Component_List (TDef); |
| 735 |
|
| 736 |
if Nkind (CList) /= N_Component_List then |
| 737 |
return False; |
| 738 |
else |
| 739 |
return Present (Variant_Part (CList)); |
| 740 |
end if; |
| 741 |
end Has_Variant_Part; |
| 742 |
|
| 743 |
--------------------- |
| 744 |
-- In_Generic_Body -- |
| 745 |
--------------------- |
| 746 |
|
| 747 |
function In_Generic_Body (Id : Entity_Id) return Boolean is |
| 748 |
S : Entity_Id; |
| 749 |
|
| 750 |
begin |
| 751 |
-- Climb scopes looking for generic body |
| 752 |
|
| 753 |
S := Id; |
| 754 |
while Present (S) and then S /= Standard_Standard loop |
| 755 |
|
| 756 |
-- Generic package body |
| 757 |
|
| 758 |
if Ekind (S) = E_Generic_Package |
| 759 |
and then In_Package_Body (S) |
| 760 |
then |
| 761 |
return True; |
| 762 |
|
| 763 |
-- Generic subprogram body |
| 764 |
|
| 765 |
elsif Is_Subprogram (S) |
| 766 |
and then Nkind (Unit_Declaration_Node (S)) = |
| 767 |
N_Generic_Subprogram_Declaration |
| 768 |
then |
| 769 |
return True; |
| 770 |
end if; |
| 771 |
|
| 772 |
S := Scope (S); |
| 773 |
end loop; |
| 774 |
|
| 775 |
-- False if top of scope stack without finding a generic body |
| 776 |
|
| 777 |
return False; |
| 778 |
end In_Generic_Body; |
| 779 |
|
| 780 |
------------------------------- |
| 781 |
-- Initialization_Suppressed -- |
| 782 |
------------------------------- |
| 783 |
|
| 784 |
function Initialization_Suppressed (Typ : Entity_Id) return Boolean is |
| 785 |
begin |
| 786 |
return Suppress_Initialization (Typ) |
| 787 |
or else Suppress_Initialization (Base_Type (Typ)); |
| 788 |
end Initialization_Suppressed; |
| 789 |
|
| 790 |
---------------- |
| 791 |
-- Initialize -- |
| 792 |
---------------- |
| 793 |
|
| 794 |
procedure Initialize is |
| 795 |
begin |
| 796 |
Obsolescent_Warnings.Init; |
| 797 |
end Initialize; |
| 798 |
|
| 799 |
------------- |
| 800 |
-- Is_Body -- |
| 801 |
------------- |
| 802 |
|
| 803 |
function Is_Body (N : Node_Id) return Boolean is |
| 804 |
begin |
| 805 |
return Nkind (N) in |
| 806 |
N_Body_Stub | N_Entry_Body | N_Package_Body | N_Protected_Body | |
| 807 |
N_Subprogram_Body | N_Task_Body; |
| 808 |
end Is_Body; |
| 809 |
|
| 810 |
--------------------- |
| 811 |
-- Is_By_Copy_Type -- |
| 812 |
--------------------- |
| 813 |
|
| 814 |
function Is_By_Copy_Type (Ent : Entity_Id) return Boolean is |
| 815 |
begin |
| 816 |
-- If Id is a private type whose full declaration has not been seen, |
| 817 |
-- we assume for now that it is not a By_Copy type. Clearly this |
| 818 |
-- attribute should not be used before the type is frozen, but it is |
| 819 |
-- needed to build the associated record of a protected type. Another |
| 820 |
-- place where some lookahead for a full view is needed ??? |
| 821 |
|
| 822 |
return |
| 823 |
Is_Elementary_Type (Ent) |
| 824 |
or else (Is_Private_Type (Ent) |
| 825 |
and then Present (Underlying_Type (Ent)) |
| 826 |
and then Is_Elementary_Type (Underlying_Type (Ent))); |
| 827 |
end Is_By_Copy_Type; |
| 828 |
|
| 829 |
-------------------------- |
| 830 |
-- Is_By_Reference_Type -- |
| 831 |
-------------------------- |
| 832 |
|
| 833 |
function Is_By_Reference_Type (Ent : Entity_Id) return Boolean is |
| 834 |
Btype : constant Entity_Id := Base_Type (Ent); |
| 835 |
|
| 836 |
begin |
| 837 |
if Is_Private_Type (Btype) then |
| 838 |
declare |
| 839 |
Utyp : constant Entity_Id := Underlying_Type (Btype); |
| 840 |
begin |
| 841 |
if No (Utyp) then |
| 842 |
return False; |
| 843 |
else |
| 844 |
return Is_By_Reference_Type (Utyp); |
| 845 |
end if; |
| 846 |
end; |
| 847 |
|
| 848 |
elsif Is_Incomplete_Type (Btype) then |
| 849 |
declare |
| 850 |
Ftyp : constant Entity_Id := Full_View (Btype); |
| 851 |
begin |
| 852 |
-- Return true for a tagged incomplete type built as a shadow |
| 853 |
-- entity in Build_Limited_Views. It can appear in the profile |
| 854 |
-- of a thunk and the back end needs to know how it is passed. |
| 855 |
|
| 856 |
if No (Ftyp) then |
| 857 |
return Is_Tagged_Type (Btype); |
| 858 |
else |
| 859 |
return Is_By_Reference_Type (Ftyp); |
| 860 |
end if; |
| 861 |
end; |
| 862 |
|
| 863 |
elsif Is_Concurrent_Type (Btype) then |
| 864 |
return True; |
| 865 |
|
| 866 |
elsif Is_Record_Type (Btype) then |
| 867 |
if Is_Controlled (Btype) |
| 868 |
or else Is_Limited_Record (Btype) |
| 869 |
or else Is_Tagged_Type (Btype) |
| 870 |
or else Is_Volatile (Btype) |
| 871 |
then |
| 872 |
return True; |
| 873 |
|
| 874 |
else |
| 875 |
declare |
| 876 |
C : Entity_Id; |
| 877 |
|
| 878 |
begin |
| 879 |
C := First_Component (Btype); |
| 880 |
while Present (C) loop |
| 881 |
|
| 882 |
-- For each component, test if its type is a by reference |
| 883 |
-- type and if its type is volatile. Also test the component |
| 884 |
-- itself for being volatile. This happens for example when |
| 885 |
-- a Volatile aspect is added to a component. |
| 886 |
|
| 887 |
if Is_By_Reference_Type (Etype (C)) |
| 888 |
or else Is_Volatile (Etype (C)) |
| 889 |
or else Is_Volatile (C) |
| 890 |
then |
| 891 |
return True; |
| 892 |
end if; |
| 893 |
|
| 894 |
Next_Component (C); |
| 895 |
end loop; |
| 896 |
end; |
| 897 |
|
| 898 |
return False; |
| 899 |
end if; |
| 900 |
|
| 901 |
elsif Is_Array_Type (Btype) then |
| 902 |
return |
| 903 |
Is_Volatile (Btype) |
| 904 |
or else Is_By_Reference_Type (Component_Type (Btype)) |
| 905 |
or else Is_Volatile (Component_Type (Btype)) |
| 906 |
or else Has_Volatile_Components (Btype); |
| 907 |
|
| 908 |
else |
| 909 |
return False; |
| 910 |
end if; |
| 911 |
end Is_By_Reference_Type; |
| 912 |
|
| 913 |
------------------------- |
| 914 |
-- Is_Definite_Subtype -- |
| 915 |
------------------------- |
| 916 |
|
| 917 |
function Is_Definite_Subtype (T : Entity_Id) return Boolean is |
| 918 |
pragma Assert (Is_Type (T)); |
| 919 |
K : constant Entity_Kind := Ekind (T); |
| 920 |
|
| 921 |
begin |
| 922 |
if Is_Constrained (T) then |
| 923 |
return True; |
| 924 |
|
| 925 |
elsif K in Array_Kind |
| 926 |
or else K in Class_Wide_Kind |
| 927 |
or else Has_Unknown_Discriminants (T) |
| 928 |
then |
| 929 |
return False; |
| 930 |
|
| 931 |
-- Known discriminants: definite if there are default values. Note that |
| 932 |
-- if any discriminant has a default, they all do. |
| 933 |
|
| 934 |
elsif Has_Discriminants (T) then |
| 935 |
return Present (Discriminant_Default_Value (First_Discriminant (T))); |
| 936 |
|
| 937 |
else |
| 938 |
return True; |
| 939 |
end if; |
| 940 |
end Is_Definite_Subtype; |
| 941 |
|
| 942 |
--------------------- |
| 943 |
-- Is_Derived_Type -- |
| 944 |
--------------------- |
| 945 |
|
| 946 |
function Is_Derived_Type (Ent : Entity_Id) return B is |
| 947 |
Par : Node_Id; |
| 948 |
|
| 949 |
begin |
| 950 |
if Is_Type (Ent) |
| 951 |
and then Base_Type (Ent) /= Root_Type (Ent) |
| 952 |
and then not Is_Class_Wide_Type (Ent) |
| 953 |
|
| 954 |
-- An access_to_subprogram whose result type is a limited view can |
| 955 |
-- appear in a return statement, without the full view of the result |
| 956 |
-- type being available. Do not interpret this as a derived type. |
| 957 |
|
| 958 |
and then Ekind (Ent) /= E_Subprogram_Type |
| 959 |
then |
| 960 |
if not Is_Numeric_Type (Root_Type (Ent)) then |
| 961 |
return True; |
| 962 |
|
| 963 |
else |
| 964 |
Par := Parent (First_Subtype (Ent)); |
| 965 |
|
| 966 |
return Present (Par) |
| 967 |
and then Nkind (Par) = N_Full_Type_Declaration |
| 968 |
and then Nkind (Type_Definition (Par)) = |
| 969 |
N_Derived_Type_Definition; |
| 970 |
end if; |
| 971 |
|
| 972 |
else |
| 973 |
return False; |
| 974 |
end if; |
| 975 |
end Is_Derived_Type; |
| 976 |
|
| 977 |
----------------------- |
| 978 |
-- Is_Generic_Formal -- |
| 979 |
----------------------- |
| 980 |
|
| 981 |
function Is_Generic_Formal (E : Entity_Id) return Boolean is |
| 982 |
Kind : Node_Kind; |
| 983 |
|
| 984 |
begin |
| 985 |
if No (E) then |
| 986 |
return False; |
| 987 |
else |
| 988 |
-- Formal derived types are rewritten as private extensions, so |
| 989 |
-- examine original node. |
| 990 |
|
| 991 |
Kind := Nkind (Original_Node (Parent (E))); |
| 992 |
|
| 993 |
return |
| 994 |
Kind in N_Formal_Object_Declaration | N_Formal_Type_Declaration |
| 995 |
or else Is_Formal_Subprogram (E) |
| 996 |
or else |
| 997 |
(Ekind (E) = E_Package |
| 998 |
and then Nkind (Original_Node (Unit_Declaration_Node (E))) = |
| 999 |
N_Formal_Package_Declaration); |
| 1000 |
end if; |
| 1001 |
end Is_Generic_Formal; |
| 1002 |
|
| 1003 |
--------------------- |
| 1004 |
-- Is_Limited_Type -- |
| 1005 |
--------------------- |
| 1006 |
|
| 1007 |
function Is_Limited_Type (Ent : Entity_Id) return Boolean is |
| 1008 |
Btype : Entity_Id; |
| 1009 |
Rtype : Entity_Id; |
| 1010 |
|
| 1011 |
begin |
| 1012 |
if not Is_Type (Ent) then |
| 1013 |
return False; |
| 1014 |
end if; |
| 1015 |
|
| 1016 |
Btype := Base_Type (Ent); |
| 1017 |
Rtype := Root_Type (Btype); |
| 1018 |
|
| 1019 |
if Ekind (Btype) = E_Limited_Private_Type |
| 1020 |
or else Is_Limited_Composite (Btype) |
| 1021 |
then |
| 1022 |
return True; |
| 1023 |
|
| 1024 |
elsif Is_Concurrent_Type (Btype) then |
| 1025 |
return True; |
| 1026 |
|
| 1027 |
-- The Is_Limited_Record flag normally indicates that the type is |
| 1028 |
-- limited. The exception is that a type does not inherit limitedness |
| 1029 |
-- from its interface ancestor. So the type may be derived from a |
| 1030 |
-- limited interface, but is not limited. |
| 1031 |
|
| 1032 |
elsif Is_Limited_Record (Ent) |
| 1033 |
and then not Is_Interface (Ent) |
| 1034 |
then |
| 1035 |
return True; |
| 1036 |
|
| 1037 |
-- Otherwise we will look around to see if there is some other reason |
| 1038 |
-- for it to be limited, except that if an error was posted on the |
| 1039 |
-- entity, then just assume it is non-limited, because it can cause |
| 1040 |
-- trouble to recurse into a murky entity resulting from other errors. |
| 1041 |
|
| 1042 |
elsif Error_Posted (Ent) then |
| 1043 |
return False; |
| 1044 |
|
| 1045 |
elsif Is_Record_Type (Btype) then |
| 1046 |
|
| 1047 |
if Is_Limited_Interface (Ent) then |
| 1048 |
return True; |
| 1049 |
|
| 1050 |
-- AI-419: limitedness is not inherited from a limited interface |
| 1051 |
|
| 1052 |
elsif Is_Limited_Record (Rtype) then |
| 1053 |
return not Is_Interface (Rtype) |
| 1054 |
or else Is_Protected_Interface (Rtype) |
| 1055 |
or else Is_Synchronized_Interface (Rtype) |
| 1056 |
or else Is_Task_Interface (Rtype); |
| 1057 |
|
| 1058 |
elsif Is_Class_Wide_Type (Btype) then |
| 1059 |
return Is_Limited_Type (Rtype); |
| 1060 |
|
| 1061 |
else |
| 1062 |
declare |
| 1063 |
C : Entity_Id := First_Component (Btype); |
| 1064 |
begin |
| 1065 |
while Present (C) loop |
| 1066 |
if Is_Limited_Type (Etype (C)) then |
| 1067 |
return True; |
| 1068 |
end if; |
| 1069 |
|
| 1070 |
Next_Component (C); |
| 1071 |
end loop; |
| 1072 |
end; |
| 1073 |
|
| 1074 |
return False; |
| 1075 |
end if; |
| 1076 |
|
| 1077 |
elsif Is_Array_Type (Btype) then |
| 1078 |
return Is_Limited_Type (Component_Type (Btype)); |
| 1079 |
|
| 1080 |
else |
| 1081 |
return False; |
| 1082 |
end if; |
| 1083 |
end Is_Limited_Type; |
| 1084 |
|
| 1085 |
------------------------------- |
| 1086 |
-- Is_Immutably_Limited_Type -- |
| 1087 |
------------------------------- |
| 1088 |
|
| 1089 |
function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean is |
| 1090 |
Btype : constant Entity_Id := Available_View (Base_Type (Ent)); |
| 1091 |
|
| 1092 |
begin |
| 1093 |
if Is_Limited_Record (Btype) then |
| 1094 |
return True; |
| 1095 |
|
| 1096 |
elsif Ekind (Btype) = E_Limited_Private_Type |
| 1097 |
and then Nkind (Parent (Btype)) = N_Formal_Type_Declaration |
| 1098 |
then |
| 1099 |
return not In_Package_Body (Scope ((Btype))); |
| 1100 |
|
| 1101 |
elsif Is_Private_Type (Btype) then |
| 1102 |
|
| 1103 |
-- If Ent occurs in the completion of a private type, then |
| 1104 |
-- look for the word "limited" in the full view. |
| 1105 |
|
| 1106 |
if Nkind (Parent (Ent)) = N_Full_Type_Declaration |
| 1107 |
and then Nkind (Type_Definition (Parent (Ent))) in |
| 1108 |
N_Record_Definition | N_Derived_Type_Definition |
| 1109 |
and then Limited_Present (Type_Definition (Parent (Ent))) |
| 1110 |
then |
| 1111 |
return True; |
| 1112 |
end if; |
| 1113 |
|
| 1114 |
-- AI05-0063: A type derived from a limited private formal type is |
| 1115 |
-- not immutably limited in a generic body. |
| 1116 |
|
| 1117 |
if Is_Derived_Type (Btype) |
| 1118 |
and then Is_Generic_Type (Etype (Btype)) |
| 1119 |
then |
| 1120 |
if not Is_Limited_Type (Etype (Btype)) then |
| 1121 |
return False; |
| 1122 |
|
| 1123 |
-- A descendant of a limited formal type is not immutably limited |
| 1124 |
-- in the generic body, or in the body of a generic child. |
| 1125 |
|
| 1126 |
elsif Ekind (Scope (Etype (Btype))) = E_Generic_Package then |
| 1127 |
return not In_Package_Body (Scope (Btype)); |
| 1128 |
|
| 1129 |
else |
| 1130 |
return False; |
| 1131 |
end if; |
| 1132 |
|
| 1133 |
else |
| 1134 |
return False; |
| 1135 |
end if; |
| 1136 |
|
| 1137 |
elsif Is_Concurrent_Type (Btype) then |
| 1138 |
return True; |
| 1139 |
|
| 1140 |
else |
| 1141 |
return False; |
| 1142 |
end if; |
| 1143 |
end Is_Immutably_Limited_Type; |
| 1144 |
|
| 1145 |
-------------------------------- |
| 1146 |
-- Is_Inherently_Limited_Type -- |
| 1147 |
-------------------------------- |
| 1148 |
|
| 1149 |
function Is_Inherently_Limited_Type (Ent : Entity_Id) return Boolean is |
| 1150 |
Btype : constant Entity_Id := Available_View (Base_Type (Ent)); |
| 1151 |
|
| 1152 |
begin |
| 1153 |
if Is_Limited_Record (Btype) then |
| 1154 |
return True; |
| 1155 |
|
| 1156 |
elsif Ekind (Btype) = E_Limited_Private_Type |
| 1157 |
and then Nkind (Parent (Btype)) = N_Formal_Type_Declaration |
| 1158 |
then |
| 1159 |
return not In_Package_Body (Scope ((Btype))); |
| 1160 |
|
| 1161 |
elsif Is_Private_Type (Btype) then |
| 1162 |
|
| 1163 |
-- AI05-0063: A type derived from a limited private formal type is |
| 1164 |
-- not immutably limited in a generic body. |
| 1165 |
|
| 1166 |
if Is_Derived_Type (Btype) |
| 1167 |
and then Is_Generic_Type (Etype (Btype)) |
| 1168 |
then |
| 1169 |
if not Is_Limited_Type (Etype (Btype)) then |
| 1170 |
return False; |
| 1171 |
|
| 1172 |
-- A descendant of a limited formal type is not immutably limited |
| 1173 |
-- in the generic body, or in the body of a generic child. |
| 1174 |
|
| 1175 |
elsif Ekind (Scope (Etype (Btype))) = E_Generic_Package then |
| 1176 |
return not In_Package_Body (Scope (Btype)); |
| 1177 |
|
| 1178 |
else |
| 1179 |
return False; |
| 1180 |
end if; |
| 1181 |
|
| 1182 |
else |
| 1183 |
declare |
| 1184 |
Utyp : constant Entity_Id := Underlying_Type (Btype); |
| 1185 |
begin |
| 1186 |
if No (Utyp) then |
| 1187 |
return False; |
| 1188 |
else |
| 1189 |
return Is_Inherently_Limited_Type (Utyp); |
| 1190 |
end if; |
| 1191 |
end; |
| 1192 |
end if; |
| 1193 |
|
| 1194 |
elsif Is_Concurrent_Type (Btype) then |
| 1195 |
return True; |
| 1196 |
|
| 1197 |
elsif Is_Record_Type (Btype) then |
| 1198 |
|
| 1199 |
-- Note that we return True for all limited interfaces, even though |
| 1200 |
-- (unsynchronized) limited interfaces can have descendants that are |
| 1201 |
-- nonlimited, because this is a predicate on the type itself, and |
| 1202 |
-- things like functions with limited interface results need to be |
| 1203 |
-- handled as build in place even though they might return objects |
| 1204 |
-- of a type that is not inherently limited. |
| 1205 |
|
| 1206 |
if Is_Class_Wide_Type (Btype) then |
| 1207 |
return Is_Inherently_Limited_Type (Root_Type (Btype)); |
| 1208 |
|
| 1209 |
else |
| 1210 |
declare |
| 1211 |
C : Entity_Id; |
| 1212 |
|
| 1213 |
begin |
| 1214 |
C := First_Component (Btype); |
| 1215 |
while Present (C) loop |
| 1216 |
|
| 1217 |
-- Don't consider components with interface types (which can |
| 1218 |
-- only occur in the case of a _parent component anyway). |
| 1219 |
-- They don't have any components, plus it would cause this |
| 1220 |
-- function to return true for nonlimited types derived from |
| 1221 |
-- limited interfaces. |
| 1222 |
|
| 1223 |
if not Is_Interface (Etype (C)) |
| 1224 |
and then Is_Inherently_Limited_Type (Etype (C)) |
| 1225 |
then |
| 1226 |
return True; |
| 1227 |
end if; |
| 1228 |
|
| 1229 |
Next_Component (C); |
| 1230 |
end loop; |
| 1231 |
end; |
| 1232 |
|
| 1233 |
return False; |
| 1234 |
end if; |
| 1235 |
|
| 1236 |
elsif Is_Array_Type (Btype) then |
| 1237 |
return Is_Inherently_Limited_Type (Component_Type (Btype)); |
| 1238 |
|
| 1239 |
else |
| 1240 |
return False; |
| 1241 |
end if; |
| 1242 |
end Is_Inherently_Limited_Type; |
| 1243 |
|
| 1244 |
---------------------- |
| 1245 |
-- Nearest_Ancestor -- |
| 1246 |
---------------------- |
| 1247 |
|
| 1248 |
function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id is |
| 1249 |
D : constant Node_Id := Original_Node (Declaration_Node (Typ)); |
| 1250 |
-- We use the original node of the declaration, because derived |
| 1251 |
-- types from record subtypes are rewritten as record declarations, |
| 1252 |
-- and it is the original declaration that carries the ancestor. |
| 1253 |
|
| 1254 |
begin |
| 1255 |
-- If we have a subtype declaration, get the ancestor subtype |
| 1256 |
|
| 1257 |
if Nkind (D) = N_Subtype_Declaration then |
| 1258 |
if Nkind (Subtype_Indication (D)) = N_Subtype_Indication then |
| 1259 |
return Entity (Subtype_Mark (Subtype_Indication (D))); |
| 1260 |
else |
| 1261 |
return Entity (Subtype_Indication (D)); |
| 1262 |
end if; |
| 1263 |
|
| 1264 |
-- If derived type declaration, find who we are derived from |
| 1265 |
|
| 1266 |
elsif Nkind (D) = N_Full_Type_Declaration |
| 1267 |
and then Nkind (Type_Definition (D)) = N_Derived_Type_Definition |
| 1268 |
then |
| 1269 |
declare |
| 1270 |
DTD : constant Entity_Id := Type_Definition (D); |
| 1271 |
SI : constant Entity_Id := Subtype_Indication (DTD); |
| 1272 |
begin |
| 1273 |
if Is_Entity_Name (SI) then |
| 1274 |
return Entity (SI); |
| 1275 |
else |
| 1276 |
return Entity (Subtype_Mark (SI)); |
| 1277 |
end if; |
| 1278 |
end; |
| 1279 |
|
| 1280 |
-- If this is a concurrent declaration with a nonempty interface list, |
| 1281 |
-- get the first progenitor. Account for case of a record type created |
| 1282 |
-- for a concurrent type (which is the only case that seems to occur |
| 1283 |
-- in practice). |
| 1284 |
|
| 1285 |
elsif Nkind (D) = N_Full_Type_Declaration |
| 1286 |
and then (Is_Concurrent_Type (Defining_Identifier (D)) |
| 1287 |
or else Is_Concurrent_Record_Type (Defining_Identifier (D))) |
| 1288 |
and then Is_Non_Empty_List (Interface_List (Type_Definition (D))) |
| 1289 |
then |
| 1290 |
return Entity (First (Interface_List (Type_Definition (D)))); |
| 1291 |
|
| 1292 |
-- If derived type and private type, get the full view to find who we |
| 1293 |
-- are derived from. |
| 1294 |
|
| 1295 |
elsif Is_Derived_Type (Typ) |
| 1296 |
and then Is_Private_Type (Typ) |
| 1297 |
and then Present (Full_View (Typ)) |
| 1298 |
then |
| 1299 |
return Nearest_Ancestor (Full_View (Typ)); |
| 1300 |
|
| 1301 |
-- Otherwise, nothing useful to return, return Empty |
| 1302 |
|
| 1303 |
else |
| 1304 |
return Empty; |
| 1305 |
end if; |
| 1306 |
end Nearest_Ancestor; |
| 1307 |
|
| 1308 |
--------------------------- |
| 1309 |
-- Nearest_Dynamic_Scope -- |
| 1310 |
--------------------------- |
| 1311 |
|
| 1312 |
function Nearest_Dynamic_Scope (Ent : Entity_Id) return Entity_Id is |
| 1313 |
begin |
| 1314 |
if Is_Dynamic_Scope (Ent) then |
| 1315 |
return Ent; |
| 1316 |
else |
| 1317 |
return Enclosing_Dynamic_Scope (Ent); |
| 1318 |
end if; |
| 1319 |
end Nearest_Dynamic_Scope; |
| 1320 |
|
| 1321 |
------------------------ |
| 1322 |
-- Next_Tag_Component -- |
| 1323 |
------------------------ |
| 1324 |
|
| 1325 |
function Next_Tag_Component (Tag : Entity_Id) return Entity_Id is |
| 1326 |
Comp : Entity_Id; |
| 1327 |
|
| 1328 |
begin |
| 1329 |
pragma Assert (Is_Tag (Tag)); |
| 1330 |
|
| 1331 |
-- Loop to look for next tag component |
| 1332 |
|
| 1333 |
Comp := Next_Entity (Tag); |
| 1334 |
while Present (Comp) loop |
| 1335 |
if Is_Tag (Comp) then |
| 1336 |
pragma Assert (Chars (Comp) /= Name_uTag); |
| 1337 |
return Comp; |
| 1338 |
end if; |
| 1339 |
|
| 1340 |
Next_Entity (Comp); |
| 1341 |
end loop; |
| 1342 |
|
| 1343 |
-- No tag component found |
| 1344 |
|
| 1345 |
return Empty; |
| 1346 |
end Next_Tag_Component; |
| 1347 |
|
| 1348 |
-------------------------- |
| 1349 |
-- Number_Discriminants -- |
| 1350 |
-------------------------- |
| 1351 |
|
| 1352 |
function Number_Discriminants (Typ : Entity_Id) return Pos is |
| 1353 |
N : Nat := 0; |
| 1354 |
Discr : Entity_Id := First_Discriminant (Typ); |
| 1355 |
|
| 1356 |
begin |
| 1357 |
while Present (Discr) loop |
| 1358 |
N := N + 1; |
| 1359 |
Next_Discriminant (Discr); |
| 1360 |
end loop; |
| 1361 |
|
| 1362 |
return N; |
| 1363 |
end Number_Discriminants; |
| 1364 |
|
| 1365 |
---------------------------------------------- |
| 1366 |
-- Object_Type_Has_Constrained_Partial_View -- |
| 1367 |
---------------------------------------------- |
| 1368 |
|
| 1369 |
function Object_Type_Has_Constrained_Partial_View |
| 1370 |
(Typ : Entity_Id; |
| 1371 |
Scop : Entity_Id) return Boolean |
| 1372 |
is |
| 1373 |
begin |
| 1374 |
return Has_Constrained_Partial_View (Typ) |
| 1375 |
or else (In_Generic_Body (Scop) |
| 1376 |
and then Is_Generic_Type (Base_Type (Typ)) |
| 1377 |
and then (Is_Private_Type (Base_Type (Typ)) |
| 1378 |
or else Is_Derived_Type (Base_Type (Typ))) |
| 1379 |
and then not Is_Tagged_Type (Typ) |
| 1380 |
and then not (Is_Array_Type (Typ) |
| 1381 |
and then not Is_Constrained (Typ)) |
| 1382 |
and then Has_Discriminants (Typ)); |
| 1383 |
end Object_Type_Has_Constrained_Partial_View; |
| 1384 |
|
| 1385 |
------------------ |
| 1386 |
-- Package_Body -- |
| 1387 |
------------------ |
| 1388 |
|
| 1389 |
function Package_Body (E : Entity_Id) return Node_Id is |
| 1390 |
Body_Decl : Node_Id; |
| 1391 |
Body_Id : constant Opt_E_Package_Body_Id := |
| 1392 |
Corresponding_Body (Package_Spec (E)); |
| 1393 |
|
| 1394 |
begin |
| 1395 |
if Present (Body_Id) then |
| 1396 |
Body_Decl := Parent (Body_Id); |
| 1397 |
|
| 1398 |
if Nkind (Body_Decl) = N_Defining_Program_Unit_Name then |
| 1399 |
Body_Decl := Parent (Body_Decl); |
| 1400 |
end if; |
| 1401 |
|
| 1402 |
pragma Assert (Nkind (Body_Decl) = N_Package_Body); |
| 1403 |
|
| 1404 |
return Body_Decl; |
| 1405 |
else |
| 1406 |
return Empty; |
| 1407 |
end if; |
| 1408 |
end Package_Body; |
| 1409 |
|
| 1410 |
------------------ |
| 1411 |
-- Package_Spec -- |
| 1412 |
------------------ |
| 1413 |
|
| 1414 |
function Package_Spec (E : Entity_Id) return Node_Id is |
| 1415 |
begin |
| 1416 |
return Parent (Package_Specification (E)); |
| 1417 |
end Package_Spec; |
| 1418 |
|
| 1419 |
--------------------------- |
| 1420 |
-- Package_Specification -- |
| 1421 |
--------------------------- |
| 1422 |
|
| 1423 |
function Package_Specification (E : Entity_Id) return Node_Id is |
| 1424 |
N : Node_Id; |
| 1425 |
|
| 1426 |
begin |
| 1427 |
pragma Assert (Is_Package_Or_Generic_Package (E)); |
| 1428 |
|
| 1429 |
N := Parent (E); |
| 1430 |
|
| 1431 |
if Nkind (N) = N_Defining_Program_Unit_Name then |
| 1432 |
N := Parent (N); |
| 1433 |
end if; |
| 1434 |
|
| 1435 |
pragma Assert (Nkind (N) = N_Package_Specification); |
| 1436 |
|
| 1437 |
return N; |
| 1438 |
end Package_Specification; |
| 1439 |
|
| 1440 |
--------------------- |
| 1441 |
-- Subprogram_Body -- |
| 1442 |
--------------------- |
| 1443 |
|
| 1444 |
function Subprogram_Body (E : Entity_Id) return Node_Id is |
| 1445 |
Body_E : constant Entity_Id := Subprogram_Body_Entity (E); |
| 1446 |
|
| 1447 |
begin |
| 1448 |
if No (Body_E) then |
| 1449 |
return Empty; |
| 1450 |
else |
| 1451 |
return Parent (Subprogram_Specification (Body_E)); |
| 1452 |
end if; |
| 1453 |
end Subprogram_Body; |
| 1454 |
|
| 1455 |
---------------------------- |
| 1456 |
-- Subprogram_Body_Entity -- |
| 1457 |
---------------------------- |
| 1458 |
|
| 1459 |
function Subprogram_Body_Entity (E : Entity_Id) return Entity_Id is |
| 1460 |
N : constant Node_Id := Parent (Subprogram_Specification (E)); |
| 1461 |
-- Declaration for E |
| 1462 |
|
| 1463 |
begin |
| 1464 |
-- If this declaration is not a subprogram body, then it must be a |
| 1465 |
-- subprogram declaration or body stub, from which we can retrieve the |
| 1466 |
-- entity for the corresponding subprogram body if any, or an abstract |
| 1467 |
-- subprogram declaration, for which we return Empty. |
| 1468 |
|
| 1469 |
case Nkind (N) is |
| 1470 |
when N_Subprogram_Body => |
| 1471 |
return E; |
| 1472 |
|
| 1473 |
when N_Subprogram_Body_Stub |
| 1474 |
| N_Subprogram_Declaration |
| 1475 |
=> |
| 1476 |
return Corresponding_Body (N); |
| 1477 |
|
| 1478 |
when others => |
| 1479 |
return Empty; |
| 1480 |
end case; |
| 1481 |
end Subprogram_Body_Entity; |
| 1482 |
|
| 1483 |
--------------------- |
| 1484 |
-- Subprogram_Spec -- |
| 1485 |
--------------------- |
| 1486 |
|
| 1487 |
function Subprogram_Spec (E : Entity_Id) return Node_Id is |
| 1488 |
N : constant Node_Id := Parent (Subprogram_Specification (E)); |
| 1489 |
-- Declaration for E |
| 1490 |
|
| 1491 |
begin |
| 1492 |
-- This declaration is either subprogram declaration or a subprogram |
| 1493 |
-- body, in which case return Empty. |
| 1494 |
|
| 1495 |
if Nkind (N) = N_Subprogram_Declaration then |
| 1496 |
return N; |
| 1497 |
else |
| 1498 |
return Empty; |
| 1499 |
end if; |
| 1500 |
end Subprogram_Spec; |
| 1501 |
|
| 1502 |
------------------------------ |
| 1503 |
-- Subprogram_Specification -- |
| 1504 |
------------------------------ |
| 1505 |
|
| 1506 |
function Subprogram_Specification (E : Entity_Id) return Node_Id is |
| 1507 |
N : Node_Id; |
| 1508 |
|
| 1509 |
begin |
| 1510 |
N := Parent (E); |
| 1511 |
|
| 1512 |
if Nkind (N) = N_Defining_Program_Unit_Name then |
| 1513 |
N := Parent (N); |
| 1514 |
end if; |
| 1515 |
|
| 1516 |
-- If the Parent pointer of E is not a subprogram specification node |
| 1517 |
-- (going through an intermediate N_Defining_Program_Unit_Name node |
| 1518 |
-- for subprogram units), then E is an inherited operation. Its parent |
| 1519 |
-- points to the type derivation that produces the inheritance: that's |
| 1520 |
-- the node that generates the subprogram specification. Its alias |
| 1521 |
-- is the parent subprogram, and that one points to a subprogram |
| 1522 |
-- declaration, or to another type declaration if this is a hierarchy |
| 1523 |
-- of derivations. |
| 1524 |
|
| 1525 |
if Nkind (N) not in N_Subprogram_Specification then |
| 1526 |
pragma Assert (Present (Alias (E))); |
| 1527 |
N := Subprogram_Specification (Alias (E)); |
| 1528 |
end if; |
| 1529 |
|
| 1530 |
return N; |
| 1531 |
end Subprogram_Specification; |
| 1532 |
|
| 1533 |
-------------------- |
| 1534 |
-- Ultimate_Alias -- |
| 1535 |
-------------------- |
| 1536 |
|
| 1537 |
function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is |
| 1538 |
E : Entity_Id := Prim; |
| 1539 |
|
| 1540 |
begin |
| 1541 |
while Present (Alias (E)) loop |
| 1542 |
pragma Assert (Alias (E) /= E); |
| 1543 |
E := Alias (E); |
| 1544 |
end loop; |
| 1545 |
|
| 1546 |
return E; |
| 1547 |
end Ultimate_Alias; |
| 1548 |
|
| 1549 |
-------------------------- |
| 1550 |
-- Unit_Declaration_Node -- |
| 1551 |
-------------------------- |
| 1552 |
|
| 1553 |
function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id is |
| 1554 |
N : Node_Id := Parent (Unit_Id); |
| 1555 |
|
| 1556 |
begin |
| 1557 |
-- Predefined operators do not have a full function declaration |
| 1558 |
|
| 1559 |
if Ekind (Unit_Id) = E_Operator then |
| 1560 |
return N; |
| 1561 |
end if; |
| 1562 |
|
| 1563 |
-- Isn't there some better way to express the following ??? |
| 1564 |
|
| 1565 |
while Nkind (N) /= N_Abstract_Subprogram_Declaration |
| 1566 |
and then Nkind (N) /= N_Entry_Body |
| 1567 |
and then Nkind (N) /= N_Entry_Declaration |
| 1568 |
and then Nkind (N) /= N_Formal_Package_Declaration |
| 1569 |
and then Nkind (N) /= N_Function_Instantiation |
| 1570 |
and then Nkind (N) /= N_Generic_Package_Declaration |
| 1571 |
and then Nkind (N) /= N_Generic_Subprogram_Declaration |
| 1572 |
and then Nkind (N) /= N_Package_Declaration |
| 1573 |
and then Nkind (N) /= N_Package_Body |
| 1574 |
and then Nkind (N) /= N_Package_Instantiation |
| 1575 |
and then Nkind (N) /= N_Package_Renaming_Declaration |
| 1576 |
and then Nkind (N) /= N_Procedure_Instantiation |
| 1577 |
and then Nkind (N) /= N_Protected_Body |
| 1578 |
and then Nkind (N) /= N_Protected_Type_Declaration |
| 1579 |
and then Nkind (N) /= N_Subprogram_Declaration |
| 1580 |
and then Nkind (N) /= N_Subprogram_Body |
| 1581 |
and then Nkind (N) /= N_Subprogram_Body_Stub |
| 1582 |
and then Nkind (N) /= N_Subprogram_Renaming_Declaration |
| 1583 |
and then Nkind (N) /= N_Task_Body |
| 1584 |
and then Nkind (N) /= N_Task_Type_Declaration |
| 1585 |
and then Nkind (N) not in N_Formal_Subprogram_Declaration |
| 1586 |
and then Nkind (N) not in N_Generic_Renaming_Declaration |
| 1587 |
loop |
| 1588 |
N := Parent (N); |
| 1589 |
|
| 1590 |
-- We don't use Assert here, because that causes an infinite loop |
| 1591 |
-- when assertions are turned off. Better to crash. |
| 1592 |
|
| 1593 |
if No (N) then |
| 1594 |
raise Program_Error; |
| 1595 |
end if; |
| 1596 |
end loop; |
| 1597 |
|
| 1598 |
return N; |
| 1599 |
end Unit_Declaration_Node; |
| 1600 |
|
| 1601 |
end Sem_Aux; |