1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- S E M _ C A T -- 6-- -- 7-- B o d y -- 8-- -- 9-- Copyright (C) 1992-2013, 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 26with Atree; use Atree; 27with Debug; use Debug; 28with Einfo; use Einfo; 29with Elists; use Elists; 30with Errout; use Errout; 31with Exp_Disp; use Exp_Disp; 32with Fname; use Fname; 33with Lib; use Lib; 34with Namet; use Namet; 35with Nlists; use Nlists; 36with Opt; use Opt; 37with Sem; use Sem; 38with Sem_Attr; use Sem_Attr; 39with Sem_Aux; use Sem_Aux; 40with Sem_Dist; use Sem_Dist; 41with Sem_Eval; use Sem_Eval; 42with Sem_Util; use Sem_Util; 43with Sinfo; use Sinfo; 44with Snames; use Snames; 45with Stand; use Stand; 46 47package body Sem_Cat is 48 49 ----------------------- 50 -- Local Subprograms -- 51 ----------------------- 52 53 procedure Check_Categorization_Dependencies 54 (Unit_Entity : Entity_Id; 55 Depended_Entity : Entity_Id; 56 Info_Node : Node_Id; 57 Is_Subunit : Boolean); 58 -- This procedure checks that the categorization of a lib unit and that 59 -- of the depended unit satisfy dependency restrictions. 60 -- The depended_entity can be the entity in a with_clause item, in which 61 -- case Info_Node denotes that item. The depended_entity can also be the 62 -- parent unit of a child unit, in which case Info_Node is the declaration 63 -- of the child unit. The error message is posted on Info_Node, and is 64 -- specialized if Is_Subunit is true. 65 66 procedure Check_Non_Static_Default_Expr 67 (Type_Def : Node_Id; 68 Obj_Decl : Node_Id); 69 -- Iterate through the component list of a record definition, check 70 -- that no component is declared with a nonstatic default value. 71 -- If a nonstatic default exists, report an error on Obj_Decl. 72 73 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean; 74 -- Return True if entity has attribute definition clauses for Read and 75 -- Write attributes that are visible at some place. 76 77 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean; 78 -- Returns true if the entity is a type whose full view is a non-remote 79 -- access type, for the purpose of enforcing E.2.2(8) rules. 80 81 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean; 82 -- Return true if Typ or the type of any of its subcomponents is a non 83 -- remote access type and doesn't have user-defined stream attributes. 84 85 function No_External_Streaming (E : Entity_Id) return Boolean; 86 -- Return True if the entity or one of its subcomponents does not support 87 -- external streaming. 88 89 function In_RCI_Declaration (N : Node_Id) return Boolean; 90 -- Determines if a declaration is within the visible part of a Remote 91 -- Call Interface compilation unit, for semantic checking purposes only 92 -- (returns false within an instance and within the package body). 93 94 function In_RT_Declaration return Boolean; 95 -- Determines if current scope is within the declaration of a Remote Types 96 -- unit, for semantic checking purposes. 97 98 function In_Shared_Passive_Unit return Boolean; 99 -- Determines if current scope is within a Shared Passive compilation unit 100 101 function Static_Discriminant_Expr (L : List_Id) return Boolean; 102 -- Iterate through the list of discriminants to check if any of them 103 -- contains non-static default expression, which is a violation in 104 -- a preelaborated library unit. 105 106 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id); 107 -- Check validity of declaration if RCI or RT unit. It should not contain 108 -- the declaration of an access-to-object type unless it is a general 109 -- access type that designates a class-wide limited private type. There are 110 -- also constraints about the primitive subprograms of the class-wide type. 111 -- RM E.2 (9, 13, 14) 112 113 procedure Validate_RACW_Primitive 114 (Subp : Entity_Id; 115 RACW : Entity_Id); 116 -- Check legality of the declaration of primitive Subp of the designated 117 -- type of the given RACW type. 118 119 --------------------------------------- 120 -- Check_Categorization_Dependencies -- 121 --------------------------------------- 122 123 procedure Check_Categorization_Dependencies 124 (Unit_Entity : Entity_Id; 125 Depended_Entity : Entity_Id; 126 Info_Node : Node_Id; 127 Is_Subunit : Boolean) 128 is 129 N : constant Node_Id := Info_Node; 130 Err : Boolean; 131 132 -- Here we define an enumeration type to represent categorization types, 133 -- ordered so that a unit with a given categorization can only WITH 134 -- units with lower or equal categorization type. 135 136 type Categorization is 137 (Pure, 138 Shared_Passive, 139 Remote_Types, 140 Remote_Call_Interface, 141 Normal); 142 143 function Get_Categorization (E : Entity_Id) return Categorization; 144 -- Check categorization flags from entity, and return in the form 145 -- of the lowest value of the Categorization type that applies to E. 146 147 ------------------------ 148 -- Get_Categorization -- 149 ------------------------ 150 151 function Get_Categorization (E : Entity_Id) return Categorization is 152 begin 153 -- Get the lowest categorization that corresponds to E. Note that 154 -- nothing prevents several (different) categorization pragmas 155 -- to apply to the same library unit, in which case the unit has 156 -- all associated categories, so we need to be careful here to 157 -- check pragmas in proper Categorization order in order to 158 -- return the lowest applicable value. 159 160 -- Ignore Pure specification if set by pragma Pure_Function 161 162 if Is_Pure (E) 163 and then not 164 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E)) 165 then 166 return Pure; 167 168 elsif Is_Shared_Passive (E) then 169 return Shared_Passive; 170 171 elsif Is_Remote_Types (E) then 172 return Remote_Types; 173 174 elsif Is_Remote_Call_Interface (E) then 175 return Remote_Call_Interface; 176 177 else 178 return Normal; 179 end if; 180 end Get_Categorization; 181 182 Unit_Category : Categorization; 183 With_Category : Categorization; 184 185 -- Start of processing for Check_Categorization_Dependencies 186 187 begin 188 -- Intrinsic subprograms are preelaborated, so do not impose any 189 -- categorization dependencies. 190 191 if Is_Intrinsic_Subprogram (Depended_Entity) then 192 return; 193 end if; 194 195 -- First check 10.2.1 (11/1) rules on preelaborate packages 196 197 if Is_Preelaborated (Unit_Entity) 198 and then not Is_Preelaborated (Depended_Entity) 199 and then not Is_Pure (Depended_Entity) 200 then 201 Err := True; 202 else 203 Err := False; 204 end if; 205 206 -- Check categorization rules of RM E.2(5) 207 208 Unit_Category := Get_Categorization (Unit_Entity); 209 With_Category := Get_Categorization (Depended_Entity); 210 211 if With_Category > Unit_Category then 212 213 -- Special case: Remote_Types and Remote_Call_Interface are allowed 214 -- to WITH anything in the package body, per (RM E.2(5)). 215 216 if (Unit_Category = Remote_Types 217 or else Unit_Category = Remote_Call_Interface) 218 and then In_Package_Body (Unit_Entity) 219 then 220 null; 221 222 -- Special case: Remote_Types and Remote_Call_Interface declarations 223 -- can depend on a preelaborated unit via a private with_clause, per 224 -- AI05-0206. 225 226 elsif (Unit_Category = Remote_Types 227 or else 228 Unit_Category = Remote_Call_Interface) 229 and then Nkind (N) = N_With_Clause 230 and then Private_Present (N) 231 and then Is_Preelaborated (Depended_Entity) 232 then 233 null; 234 235 -- All other cases, we do have an error 236 237 else 238 Err := True; 239 end if; 240 end if; 241 242 -- Here if we have an error 243 244 if Err then 245 246 -- These messages are warnings in GNAT mode or if the -gnateP switch 247 -- was set. Otherwise these are real errors for real illegalities. 248 249 -- The reason we suppress these errors in GNAT mode is that the run- 250 -- time has several instances of violations of the categorization 251 -- errors (e.g. Pure units withing Preelaborate units. All these 252 -- violations are harmless in the cases where we intend them, and 253 -- we suppress the warnings with Warnings (Off). In cases where we 254 -- do not intend the violation, warnings are errors in GNAT mode 255 -- anyway, so we will still get an error. 256 257 Error_Msg_Warn := 258 Treat_Categorization_Errors_As_Warnings or GNAT_Mode; 259 260 -- Don't give error if main unit is not an internal unit, and the 261 -- unit generating the message is an internal unit. This is the 262 -- situation in which such messages would be ignored in any case, 263 -- so it is convenient not to generate them (since it causes 264 -- annoying interference with debugging). 265 266 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)) 267 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit)) 268 then 269 return; 270 271 -- Dependence of Remote_Types or Remote_Call_Interface declaration 272 -- on a preelaborated unit with a normal with_clause. 273 274 elsif (Unit_Category = Remote_Types 275 or else 276 Unit_Category = Remote_Call_Interface) 277 and then Is_Preelaborated (Depended_Entity) 278 then 279 Error_Msg_NE 280 ("<must use private with clause for preelaborated unit& ", 281 N, Depended_Entity); 282 283 -- Subunit case 284 285 elsif Is_Subunit then 286 Error_Msg_NE 287 ("<subunit cannot depend on& " & 288 "(parent has wrong categorization)", N, Depended_Entity); 289 290 -- Normal unit, not subunit 291 292 else 293 Error_Msg_NE 294 ("<cannot depend on& " & 295 "(wrong categorization)", N, Depended_Entity); 296 end if; 297 298 -- Add further explanation for Pure/Preelaborate common cases 299 300 if Unit_Category = Pure then 301 Error_Msg_NE 302 ("\<pure unit cannot depend on non-pure unit", 303 N, Depended_Entity); 304 305 elsif Is_Preelaborated (Unit_Entity) 306 and then not Is_Preelaborated (Depended_Entity) 307 and then not Is_Pure (Depended_Entity) 308 then 309 Error_Msg_NE 310 ("\<preelaborated unit cannot depend on " 311 & "non-preelaborated unit", 312 N, Depended_Entity); 313 end if; 314 end if; 315 end Check_Categorization_Dependencies; 316 317 ----------------------------------- 318 -- Check_Non_Static_Default_Expr -- 319 ----------------------------------- 320 321 procedure Check_Non_Static_Default_Expr 322 (Type_Def : Node_Id; 323 Obj_Decl : Node_Id) 324 is 325 Recdef : Node_Id; 326 Component_Decl : Node_Id; 327 328 begin 329 if Nkind (Type_Def) = N_Derived_Type_Definition then 330 Recdef := Record_Extension_Part (Type_Def); 331 332 if No (Recdef) then 333 return; 334 end if; 335 336 else 337 Recdef := Type_Def; 338 end if; 339 340 -- Check that component declarations do not involve: 341 342 -- a. a non-static default expression, where the object is 343 -- declared to be default initialized. 344 345 -- b. a dynamic Itype (discriminants and constraints) 346 347 if Null_Present (Recdef) then 348 return; 349 else 350 Component_Decl := First (Component_Items (Component_List (Recdef))); 351 end if; 352 353 while Present (Component_Decl) 354 and then Nkind (Component_Decl) = N_Component_Declaration 355 loop 356 if Present (Expression (Component_Decl)) 357 and then Nkind (Expression (Component_Decl)) /= N_Null 358 and then not Is_Static_Expression (Expression (Component_Decl)) 359 then 360 Error_Msg_Sloc := Sloc (Component_Decl); 361 Error_Msg_F 362 ("object in preelaborated unit has non-static default#", 363 Obj_Decl); 364 365 -- Fix this later ??? 366 367 -- elsif Has_Dynamic_Itype (Component_Decl) then 368 -- Error_Msg_N 369 -- ("dynamic type discriminant," & 370 -- " constraint in preelaborated unit", 371 -- Component_Decl); 372 end if; 373 374 Next (Component_Decl); 375 end loop; 376 end Check_Non_Static_Default_Expr; 377 378 --------------------------- 379 -- Has_Non_Remote_Access -- 380 --------------------------- 381 382 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean is 383 Component : Entity_Id; 384 Comp_Type : Entity_Id; 385 U_Typ : constant Entity_Id := Underlying_Type (Typ); 386 387 begin 388 if No (U_Typ) then 389 return False; 390 391 elsif Has_Read_Write_Attributes (Typ) 392 or else Has_Read_Write_Attributes (U_Typ) 393 then 394 return False; 395 396 elsif Is_Non_Remote_Access_Type (U_Typ) then 397 return True; 398 end if; 399 400 if Is_Record_Type (U_Typ) then 401 Component := First_Entity (U_Typ); 402 while Present (Component) loop 403 if not Is_Tag (Component) then 404 Comp_Type := Etype (Component); 405 406 if Has_Non_Remote_Access (Comp_Type) then 407 return True; 408 end if; 409 end if; 410 411 Next_Entity (Component); 412 end loop; 413 414 elsif Is_Array_Type (U_Typ) then 415 return Has_Non_Remote_Access (Component_Type (U_Typ)); 416 417 end if; 418 419 return False; 420 end Has_Non_Remote_Access; 421 422 ------------------------------- 423 -- Has_Read_Write_Attributes -- 424 ------------------------------- 425 426 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is 427 begin 428 return True 429 and then Has_Stream_Attribute_Definition 430 (E, TSS_Stream_Read, At_Any_Place => True) 431 and then Has_Stream_Attribute_Definition 432 (E, TSS_Stream_Write, At_Any_Place => True); 433 end Has_Read_Write_Attributes; 434 435 ------------------------------------- 436 -- Has_Stream_Attribute_Definition -- 437 ------------------------------------- 438 439 function Has_Stream_Attribute_Definition 440 (Typ : Entity_Id; 441 Nam : TSS_Name_Type; 442 At_Any_Place : Boolean := False) return Boolean 443 is 444 Rep_Item : Node_Id; 445 Full_Type : Entity_Id := Typ; 446 447 begin 448 -- In the case of a type derived from a private view, any specified 449 -- stream attributes will be attached to the derived type's underlying 450 -- type rather the derived type entity itself (which is itself private). 451 452 if Is_Private_Type (Typ) 453 and then Is_Derived_Type (Typ) 454 and then Present (Full_View (Typ)) 455 then 456 Full_Type := Underlying_Type (Typ); 457 end if; 458 459 -- We start from the declaration node and then loop until the end of 460 -- the list until we find the requested attribute definition clause. 461 -- In Ada 2005 mode, clauses are ignored if they are not currently 462 -- visible (this is tested using the corresponding Entity, which is 463 -- inserted by the expander at the point where the clause occurs), 464 -- unless At_Any_Place is true. 465 466 Rep_Item := First_Rep_Item (Full_Type); 467 while Present (Rep_Item) loop 468 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then 469 case Chars (Rep_Item) is 470 when Name_Read => 471 exit when Nam = TSS_Stream_Read; 472 473 when Name_Write => 474 exit when Nam = TSS_Stream_Write; 475 476 when Name_Input => 477 exit when Nam = TSS_Stream_Input; 478 479 when Name_Output => 480 exit when Nam = TSS_Stream_Output; 481 482 when others => 483 null; 484 485 end case; 486 end if; 487 488 Next_Rep_Item (Rep_Item); 489 end loop; 490 491 -- If At_Any_Place is true, return True if the attribute is available 492 -- at any place; if it is false, return True only if the attribute is 493 -- currently visible. 494 495 return Present (Rep_Item) 496 and then (Ada_Version < Ada_2005 497 or else At_Any_Place 498 or else not Is_Hidden (Entity (Rep_Item))); 499 end Has_Stream_Attribute_Definition; 500 501 --------------------------- 502 -- In_Preelaborated_Unit -- 503 --------------------------- 504 505 function In_Preelaborated_Unit return Boolean is 506 Unit_Entity : Entity_Id := Current_Scope; 507 Unit_Kind : constant Node_Kind := 508 Nkind (Unit (Cunit (Current_Sem_Unit))); 509 510 begin 511 -- If evaluating actuals for a child unit instantiation, then ignore 512 -- the preelaboration status of the parent; use the child instead. 513 514 if Is_Compilation_Unit (Unit_Entity) 515 and then Unit_Kind in N_Generic_Instantiation 516 and then not In_Same_Source_Unit (Unit_Entity, 517 Cunit (Current_Sem_Unit)) 518 then 519 Unit_Entity := Cunit_Entity (Current_Sem_Unit); 520 end if; 521 522 -- There are no constraints on the body of Remote_Call_Interface or 523 -- Remote_Types packages. 524 525 return (Unit_Entity /= Standard_Standard) 526 and then (Is_Preelaborated (Unit_Entity) 527 or else Is_Pure (Unit_Entity) 528 or else Is_Shared_Passive (Unit_Entity) 529 or else 530 ((Is_Remote_Types (Unit_Entity) 531 or else Is_Remote_Call_Interface (Unit_Entity)) 532 and then Ekind (Unit_Entity) = E_Package 533 and then Unit_Kind /= N_Package_Body 534 and then not In_Package_Body (Unit_Entity) 535 and then not In_Instance)); 536 end In_Preelaborated_Unit; 537 538 ------------------ 539 -- In_Pure_Unit -- 540 ------------------ 541 542 function In_Pure_Unit return Boolean is 543 begin 544 return Is_Pure (Current_Scope); 545 end In_Pure_Unit; 546 547 ------------------------ 548 -- In_RCI_Declaration -- 549 ------------------------ 550 551 function In_RCI_Declaration (N : Node_Id) return Boolean is 552 Unit_Entity : constant Entity_Id := Current_Scope; 553 Unit_Kind : constant Node_Kind := 554 Nkind (Unit (Cunit (Current_Sem_Unit))); 555 556 begin 557 -- There are no restrictions on the private part or body 558 -- of an RCI unit. 559 560 return Is_Remote_Call_Interface (Unit_Entity) 561 and then Is_Package_Or_Generic_Package (Unit_Entity) 562 and then Unit_Kind /= N_Package_Body 563 and then List_Containing (N) = 564 Visible_Declarations (Package_Specification (Unit_Entity)) 565 and then not In_Package_Body (Unit_Entity) 566 and then not In_Instance; 567 568 -- What about the case of a nested package in the visible part??? 569 -- This case is missed by the List_Containing check above??? 570 end In_RCI_Declaration; 571 572 ----------------------- 573 -- In_RT_Declaration -- 574 ----------------------- 575 576 function In_RT_Declaration return Boolean is 577 Unit_Entity : constant Entity_Id := Current_Scope; 578 Unit_Kind : constant Node_Kind := 579 Nkind (Unit (Cunit (Current_Sem_Unit))); 580 581 begin 582 -- There are no restrictions on the body of a Remote Types unit 583 584 return Is_Remote_Types (Unit_Entity) 585 and then Is_Package_Or_Generic_Package (Unit_Entity) 586 and then Unit_Kind /= N_Package_Body 587 and then not In_Package_Body (Unit_Entity) 588 and then not In_Instance; 589 end In_RT_Declaration; 590 591 ---------------------------- 592 -- In_Shared_Passive_Unit -- 593 ---------------------------- 594 595 function In_Shared_Passive_Unit return Boolean is 596 Unit_Entity : constant Entity_Id := Current_Scope; 597 598 begin 599 return Is_Shared_Passive (Unit_Entity); 600 end In_Shared_Passive_Unit; 601 602 --------------------------------------- 603 -- In_Subprogram_Task_Protected_Unit -- 604 --------------------------------------- 605 606 function In_Subprogram_Task_Protected_Unit return Boolean is 607 E : Entity_Id; 608 609 begin 610 -- The following is to verify that a declaration is inside 611 -- subprogram, generic subprogram, task unit, protected unit. 612 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16). 613 614 -- Use scope chain to check successively outer scopes 615 616 E := Current_Scope; 617 loop 618 if Is_Subprogram (E) 619 or else 620 Is_Generic_Subprogram (E) 621 or else 622 Is_Concurrent_Type (E) 623 then 624 return True; 625 626 elsif E = Standard_Standard then 627 return False; 628 end if; 629 630 E := Scope (E); 631 end loop; 632 end In_Subprogram_Task_Protected_Unit; 633 634 ------------------------------- 635 -- Is_Non_Remote_Access_Type -- 636 ------------------------------- 637 638 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is 639 U_E : constant Entity_Id := Underlying_Type (E); 640 begin 641 if No (U_E) then 642 643 -- This case arises for the case of a generic formal type, in which 644 -- case E.2.2(8) rules will be enforced at instantiation time. 645 646 return False; 647 end if; 648 649 return Is_Access_Type (U_E) 650 and then not Is_Remote_Access_To_Class_Wide_Type (U_E) 651 and then not Is_Remote_Access_To_Subprogram_Type (U_E); 652 end Is_Non_Remote_Access_Type; 653 654 --------------------------- 655 -- No_External_Streaming -- 656 --------------------------- 657 658 function No_External_Streaming (E : Entity_Id) return Boolean is 659 U_E : constant Entity_Id := Underlying_Type (E); 660 661 begin 662 if No (U_E) then 663 return False; 664 665 elsif Has_Read_Write_Attributes (E) then 666 667 -- Note: availability of stream attributes is tested on E, not U_E. 668 -- There may be stream attributes defined on U_E that are not visible 669 -- at the place where support of external streaming is tested. 670 671 return False; 672 673 elsif Has_Non_Remote_Access (U_E) then 674 return True; 675 end if; 676 677 return Is_Limited_Type (E); 678 end No_External_Streaming; 679 680 ------------------------------------- 681 -- Set_Categorization_From_Pragmas -- 682 ------------------------------------- 683 684 procedure Set_Categorization_From_Pragmas (N : Node_Id) is 685 P : constant Node_Id := Parent (N); 686 S : constant Entity_Id := Current_Scope; 687 688 procedure Set_Parents (Visibility : Boolean); 689 -- If this is a child instance, the parents are not immediately 690 -- visible during analysis. Make them momentarily visible so that 691 -- the argument of the pragma can be resolved properly, and reset 692 -- afterwards. 693 694 ----------------- 695 -- Set_Parents -- 696 ----------------- 697 698 procedure Set_Parents (Visibility : Boolean) is 699 Par : Entity_Id; 700 begin 701 Par := Scope (S); 702 while Present (Par) and then Par /= Standard_Standard loop 703 Set_Is_Immediately_Visible (Par, Visibility); 704 Par := Scope (Par); 705 end loop; 706 end Set_Parents; 707 708 -- Start of processing for Set_Categorization_From_Pragmas 709 710 begin 711 -- Deal with categorization pragmas in Pragmas of Compilation_Unit. 712 -- The purpose is to set categorization flags before analyzing the 713 -- unit itself, so as to diagnose violations of categorization as 714 -- we process each declaration, even though the pragma appears after 715 -- the unit. 716 717 if Nkind (P) /= N_Compilation_Unit then 718 return; 719 end if; 720 721 declare 722 PN : Node_Id; 723 724 begin 725 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then 726 Set_Parents (True); 727 end if; 728 729 PN := First (Pragmas_After (Aux_Decls_Node (P))); 730 while Present (PN) loop 731 732 -- Skip implicit types that may have been introduced by 733 -- previous analysis. 734 735 if Nkind (PN) = N_Pragma then 736 case Get_Pragma_Id (PN) is 737 when Pragma_All_Calls_Remote | 738 Pragma_Preelaborate | 739 Pragma_Pure | 740 Pragma_Remote_Call_Interface | 741 Pragma_Remote_Types | 742 Pragma_Shared_Passive => Analyze (PN); 743 when others => null; 744 end case; 745 end if; 746 747 Next (PN); 748 end loop; 749 750 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then 751 Set_Parents (False); 752 end if; 753 end; 754 end Set_Categorization_From_Pragmas; 755 756 ----------------------------------- 757 -- Set_Categorization_From_Scope -- 758 ----------------------------------- 759 760 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is 761 Declaration : Node_Id := Empty; 762 Specification : Node_Id := Empty; 763 764 begin 765 Set_Is_Pure 766 (E, Is_Pure (Scop) and then Is_Library_Level_Entity (E)); 767 768 if not Is_Remote_Call_Interface (E) then 769 if Ekind (E) in Subprogram_Kind then 770 Declaration := Unit_Declaration_Node (E); 771 772 if Nkind_In (Declaration, N_Subprogram_Body, 773 N_Subprogram_Renaming_Declaration) 774 then 775 Specification := Corresponding_Spec (Declaration); 776 end if; 777 end if; 778 779 -- A subprogram body or renaming-as-body is a remote call interface 780 -- if it serves as the completion of a subprogram declaration that 781 -- is a remote call interface. 782 783 if Nkind (Specification) in N_Entity then 784 Set_Is_Remote_Call_Interface 785 (E, Is_Remote_Call_Interface (Specification)); 786 787 -- A subprogram declaration is a remote call interface when it is 788 -- declared within the visible part of, or declared by, a library 789 -- unit declaration that is a remote call interface. 790 791 else 792 Set_Is_Remote_Call_Interface 793 (E, Is_Remote_Call_Interface (Scop) 794 and then not (In_Private_Part (Scop) 795 or else In_Package_Body (Scop))); 796 end if; 797 end if; 798 799 Set_Is_Remote_Types 800 (E, Is_Remote_Types (Scop) 801 and then not (In_Private_Part (Scop) 802 or else In_Package_Body (Scop))); 803 end Set_Categorization_From_Scope; 804 805 ------------------------------ 806 -- Static_Discriminant_Expr -- 807 ------------------------------ 808 809 -- We need to accommodate a Why_Not_Static call somehow here ??? 810 811 function Static_Discriminant_Expr (L : List_Id) return Boolean is 812 Discriminant_Spec : Node_Id; 813 814 begin 815 Discriminant_Spec := First (L); 816 while Present (Discriminant_Spec) loop 817 if Present (Expression (Discriminant_Spec)) 818 and then not Is_Static_Expression (Expression (Discriminant_Spec)) 819 then 820 return False; 821 end if; 822 823 Next (Discriminant_Spec); 824 end loop; 825 826 return True; 827 end Static_Discriminant_Expr; 828 829 -------------------------------------- 830 -- Validate_Access_Type_Declaration -- 831 -------------------------------------- 832 833 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is 834 Def : constant Node_Id := Type_Definition (N); 835 836 begin 837 case Nkind (Def) is 838 839 -- Access to subprogram case 840 841 when N_Access_To_Subprogram_Definition => 842 843 -- A pure library_item must not contain the declaration of a 844 -- named access type, except within a subprogram, generic 845 -- subprogram, task unit, or protected unit (RM 10.2.1(16)). 846 847 -- This test is skipped in Ada 2005 (see AI-366) 848 849 if Ada_Version < Ada_2005 850 and then Comes_From_Source (T) 851 and then In_Pure_Unit 852 and then not In_Subprogram_Task_Protected_Unit 853 then 854 Error_Msg_N ("named access type not allowed in pure unit", T); 855 end if; 856 857 -- Access to object case 858 859 when N_Access_To_Object_Definition => 860 if Comes_From_Source (T) 861 and then In_Pure_Unit 862 and then not In_Subprogram_Task_Protected_Unit 863 then 864 -- We can't give the message yet, since the type is not frozen 865 -- and in Ada 2005 mode, access types are allowed in pure units 866 -- if the type has no storage pool (see AI-366). So we set a 867 -- flag which will be checked at freeze time. 868 869 Set_Is_Pure_Unit_Access_Type (T); 870 end if; 871 872 -- Check for RCI or RT unit type declaration: declaration of an 873 -- access-to-object type is illegal unless it is a general access 874 -- type that designates a class-wide limited private type. 875 -- Note that constraints on the primitive subprograms of the 876 -- designated tagged type are not enforced here but in 877 -- Validate_RACW_Primitives, which is done separately because the 878 -- designated type might not be frozen (and therefore its 879 -- primitive operations might not be completely known) at the 880 -- point of the RACW declaration. 881 882 Validate_Remote_Access_Object_Type_Declaration (T); 883 884 -- Check for shared passive unit type declaration. It should 885 -- not contain the declaration of access to class wide type, 886 -- access to task type and access to protected type with entry. 887 888 Validate_SP_Access_Object_Type_Decl (T); 889 890 when others => 891 null; 892 end case; 893 894 -- Set categorization flag from package on entity as well, to allow 895 -- easy checks later on for required validations of RCI or RT units. 896 -- This is only done for entities that are in the original source. 897 898 if Comes_From_Source (T) 899 and then not (In_Package_Body (Scope (T)) 900 or else In_Private_Part (Scope (T))) 901 then 902 Set_Is_Remote_Call_Interface 903 (T, Is_Remote_Call_Interface (Scope (T))); 904 Set_Is_Remote_Types 905 (T, Is_Remote_Types (Scope (T))); 906 end if; 907 end Validate_Access_Type_Declaration; 908 909 ---------------------------- 910 -- Validate_Ancestor_Part -- 911 ---------------------------- 912 913 procedure Validate_Ancestor_Part (N : Node_Id) is 914 A : constant Node_Id := Ancestor_Part (N); 915 T : constant Entity_Id := Entity (A); 916 917 begin 918 if In_Preelaborated_Unit 919 and then not In_Subprogram_Or_Concurrent_Unit 920 and then (not Inside_A_Generic 921 or else Present (Enclosing_Generic_Body (N))) 922 then 923 -- If the type is private, it must have the Ada 2005 pragma 924 -- Has_Preelaborable_Initialization. 925 926 -- The check is omitted within predefined units. This is probably 927 -- obsolete code to fix the Ada 95 weakness in this area ??? 928 929 if Is_Private_Type (T) 930 and then not Has_Pragma_Preelab_Init (T) 931 and then not Is_Internal_File_Name 932 (Unit_File_Name (Get_Source_Unit (N))) 933 then 934 Error_Msg_N 935 ("private ancestor type not allowed in preelaborated unit", A); 936 937 elsif Is_Record_Type (T) then 938 if Nkind (Parent (T)) = N_Full_Type_Declaration then 939 Check_Non_Static_Default_Expr 940 (Type_Definition (Parent (T)), A); 941 end if; 942 end if; 943 end if; 944 end Validate_Ancestor_Part; 945 946 ---------------------------------------- 947 -- Validate_Categorization_Dependency -- 948 ---------------------------------------- 949 950 procedure Validate_Categorization_Dependency 951 (N : Node_Id; 952 E : Entity_Id) 953 is 954 K : constant Node_Kind := Nkind (N); 955 P : Node_Id := Parent (N); 956 U : Entity_Id := E; 957 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit; 958 959 begin 960 -- Only validate library units and subunits. For subunits, checks 961 -- concerning withed units apply to the parent compilation unit. 962 963 if Is_Subunit then 964 P := Parent (P); 965 U := Scope (E); 966 967 while Present (U) 968 and then not Is_Compilation_Unit (U) 969 and then not Is_Child_Unit (U) 970 loop 971 U := Scope (U); 972 end loop; 973 end if; 974 975 if Nkind (P) /= N_Compilation_Unit then 976 return; 977 end if; 978 979 -- Body of RCI unit does not need validation 980 981 if Is_Remote_Call_Interface (E) 982 and then Nkind_In (N, N_Package_Body, N_Subprogram_Body) 983 then 984 return; 985 end if; 986 987 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses 988 989 declare 990 Item : Node_Id; 991 Entity_Of_Withed : Entity_Id; 992 993 begin 994 Item := First (Context_Items (P)); 995 while Present (Item) loop 996 if Nkind (Item) = N_With_Clause 997 and then not (Implicit_With (Item) 998 or else Limited_Present (Item) 999 1000 -- Skip if error already posted on the WITH 1001 -- clause (in which case the Name attribute 1002 -- may be invalid). In particular, this fixes 1003 -- the problem of hanging in the presence of a 1004 -- WITH clause on a child that is an illegal 1005 -- generic instantiation. 1006 1007 or else Error_Posted (Item)) 1008 then 1009 Entity_Of_Withed := Entity (Name (Item)); 1010 Check_Categorization_Dependencies 1011 (U, Entity_Of_Withed, Item, Is_Subunit); 1012 end if; 1013 1014 Next (Item); 1015 end loop; 1016 end; 1017 1018 -- Child depends on parent; therefore parent should also be categorized 1019 -- and satisfy the dependency hierarchy. 1020 1021 -- Check if N is a child spec 1022 1023 if (K in N_Generic_Declaration or else 1024 K in N_Generic_Instantiation or else 1025 K in N_Generic_Renaming_Declaration or else 1026 K = N_Package_Declaration or else 1027 K = N_Package_Renaming_Declaration or else 1028 K = N_Subprogram_Declaration or else 1029 K = N_Subprogram_Renaming_Declaration) 1030 and then Present (Parent_Spec (N)) 1031 then 1032 Check_Categorization_Dependencies (E, Scope (E), N, False); 1033 1034 -- Verify that public child of an RCI library unit must also be an 1035 -- RCI library unit (RM E.2.3(15)). 1036 1037 if Is_Remote_Call_Interface (Scope (E)) 1038 and then not Private_Present (P) 1039 and then not Is_Remote_Call_Interface (E) 1040 then 1041 Error_Msg_N ("public child of rci unit must also be rci unit", N); 1042 end if; 1043 end if; 1044 end Validate_Categorization_Dependency; 1045 1046 -------------------------------- 1047 -- Validate_Controlled_Object -- 1048 -------------------------------- 1049 1050 procedure Validate_Controlled_Object (E : Entity_Id) is 1051 begin 1052 -- Don't need this check in Ada 2005 mode, where this is all taken 1053 -- care of by the mechanism for Preelaborable Initialization. 1054 1055 if Ada_Version >= Ada_2005 then 1056 return; 1057 end if; 1058 1059 -- For now, never apply this check for internal GNAT units, since we 1060 -- have a number of cases in the library where we are stuck with objects 1061 -- of this type, and the RM requires Preelaborate. 1062 1063 -- For similar reasons, we only do this check for source entities, since 1064 -- we generate entities of this type in some situations. 1065 1066 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway. 1067 -- We have to enforce them for RM compatibility, but we have no trouble 1068 -- accepting these objects and doing the right thing. Note that there is 1069 -- no requirement that Preelaborate not actually generate any code. 1070 1071 if In_Preelaborated_Unit 1072 and then not Debug_Flag_PP 1073 and then Comes_From_Source (E) 1074 and then not 1075 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E))) 1076 and then (not Inside_A_Generic 1077 or else Present (Enclosing_Generic_Body (E))) 1078 and then not Is_Protected_Type (Etype (E)) 1079 then 1080 Error_Msg_N 1081 ("library level controlled object not allowed in " & 1082 "preelaborated unit", E); 1083 end if; 1084 end Validate_Controlled_Object; 1085 1086 -------------------------------------- 1087 -- Validate_Null_Statement_Sequence -- 1088 -------------------------------------- 1089 1090 procedure Validate_Null_Statement_Sequence (N : Node_Id) is 1091 Item : Node_Id; 1092 1093 begin 1094 if In_Preelaborated_Unit then 1095 Item := First (Statements (Handled_Statement_Sequence (N))); 1096 while Present (Item) loop 1097 if Nkind (Item) /= N_Label 1098 and then Nkind (Item) /= N_Null_Statement 1099 then 1100 -- In GNAT mode, this is a warning, allowing the run-time 1101 -- to judiciously bypass this error condition. 1102 1103 Error_Msg_Warn := GNAT_Mode; 1104 Error_Msg_N 1105 ("<statements not allowed in preelaborated unit", Item); 1106 1107 exit; 1108 end if; 1109 1110 Next (Item); 1111 end loop; 1112 end if; 1113 end Validate_Null_Statement_Sequence; 1114 1115 --------------------------------- 1116 -- Validate_Object_Declaration -- 1117 --------------------------------- 1118 1119 procedure Validate_Object_Declaration (N : Node_Id) is 1120 Id : constant Entity_Id := Defining_Identifier (N); 1121 E : constant Node_Id := Expression (N); 1122 Odf : constant Node_Id := Object_Definition (N); 1123 T : constant Entity_Id := Etype (Id); 1124 1125 begin 1126 -- Verify that any access to subprogram object does not have in its 1127 -- subprogram profile access type parameters or limited parameters 1128 -- without Read and Write attributes (E.2.3(13)). 1129 1130 Validate_RCI_Subprogram_Declaration (N); 1131 1132 -- Check that if we are in preelaborated elaboration code, then we 1133 -- do not have an instance of a default initialized private, task or 1134 -- protected object declaration which would violate (RM 10.2.1(9)). 1135 -- Note that constants are never default initialized (and the test 1136 -- below also filters out deferred constants). A variable is default 1137 -- initialized if it does *not* have an initialization expression. 1138 1139 -- Filter out cases that are not declaration of a variable from source 1140 1141 if Nkind (N) /= N_Object_Declaration 1142 or else Constant_Present (N) 1143 or else not Comes_From_Source (Id) 1144 then 1145 return; 1146 end if; 1147 1148 -- Exclude generic specs from the checks (this will get rechecked 1149 -- on instantiations). 1150 1151 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then 1152 return; 1153 end if; 1154 1155 -- Required checks for declaration that is in a preelaborated package 1156 -- and is not within some subprogram. 1157 1158 if In_Preelaborated_Unit 1159 and then not In_Subprogram_Or_Concurrent_Unit 1160 then 1161 -- Check for default initialized variable case. Note that in 1162 -- accordance with (RM B.1(24)) imported objects are not subject to 1163 -- default initialization. 1164 -- If the initialization does not come from source and is an 1165 -- aggregate, it is a static initialization that replaces an 1166 -- implicit call, and must be treated as such. 1167 1168 if Present (E) 1169 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate) 1170 then 1171 null; 1172 1173 elsif Is_Imported (Id) then 1174 null; 1175 1176 else 1177 declare 1178 Ent : Entity_Id := T; 1179 1180 begin 1181 -- An array whose component type is a record with nonstatic 1182 -- default expressions is a violation, so we get the array's 1183 -- component type. 1184 1185 if Is_Array_Type (Ent) then 1186 declare 1187 Comp_Type : Entity_Id; 1188 1189 begin 1190 Comp_Type := Component_Type (Ent); 1191 while Is_Array_Type (Comp_Type) loop 1192 Comp_Type := Component_Type (Comp_Type); 1193 end loop; 1194 1195 Ent := Comp_Type; 1196 end; 1197 end if; 1198 1199 -- Object decl. that is of record type and has no default expr. 1200 -- should check if there is any non-static default expression 1201 -- in component decl. of the record type decl. 1202 1203 if Is_Record_Type (Ent) then 1204 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then 1205 Check_Non_Static_Default_Expr 1206 (Type_Definition (Parent (Ent)), N); 1207 1208 elsif Nkind (Odf) = N_Subtype_Indication 1209 and then not Is_Array_Type (T) 1210 and then not Is_Private_Type (T) 1211 then 1212 Check_Non_Static_Default_Expr (Type_Definition 1213 (Parent (Entity (Subtype_Mark (Odf)))), N); 1214 end if; 1215 end if; 1216 1217 -- Check for invalid use of private object. Note that Ada 2005 1218 -- AI-161 modifies the rules for Ada 2005, including the use of 1219 -- the new pragma Preelaborable_Initialization. 1220 1221 if Is_Private_Type (Ent) 1222 or else Depends_On_Private (Ent) 1223 then 1224 -- Case where type has preelaborable initialization which 1225 -- means that a pragma Preelaborable_Initialization was 1226 -- given for the private type. 1227 1228 if Relaxed_RM_Semantics then 1229 1230 -- In relaxed mode, do not issue these messages, this 1231 -- is basically similar to the GNAT_Mode test below. 1232 1233 null; 1234 1235 elsif Has_Preelaborable_Initialization (Ent) then 1236 1237 -- But for the predefined units, we will ignore this 1238 -- status unless we are in Ada 2005 mode since we want 1239 -- Ada 95 compatible behavior, in which the entities 1240 -- marked with this pragma in the predefined library are 1241 -- not treated specially. 1242 1243 if Ada_Version < Ada_2005 then 1244 Error_Msg_N 1245 ("private object not allowed in preelaborated unit", 1246 N); 1247 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N); 1248 end if; 1249 1250 -- Type does not have preelaborable initialization 1251 1252 else 1253 -- We allow this when compiling in GNAT mode to make life 1254 -- easier for some cases where it would otherwise be hard 1255 -- to be exactly valid Ada. 1256 1257 if not GNAT_Mode then 1258 Error_Msg_N 1259 ("private object not allowed in preelaborated unit", 1260 N); 1261 1262 -- Add a message if it would help to provide a pragma 1263 -- Preelaborable_Initialization on the type of the 1264 -- object (which would make it legal in Ada 2005). 1265 1266 -- If the type has no full view (generic type, or 1267 -- previous error), the warning does not apply. 1268 1269 if Is_Private_Type (Ent) 1270 and then Present (Full_View (Ent)) 1271 and then 1272 Has_Preelaborable_Initialization (Full_View (Ent)) 1273 then 1274 Error_Msg_Sloc := Sloc (Ent); 1275 1276 if Ada_Version >= Ada_2005 then 1277 Error_Msg_NE 1278 ("\would be legal if pragma Preelaborable_" & 1279 "Initialization given for & #", N, Ent); 1280 else 1281 Error_Msg_NE 1282 ("\would be legal in Ada 2005 if pragma " & 1283 "Preelaborable_Initialization given for & #", 1284 N, Ent); 1285 end if; 1286 end if; 1287 end if; 1288 end if; 1289 1290 -- Access to Task or Protected type 1291 1292 elsif Is_Entity_Name (Odf) 1293 and then Present (Etype (Odf)) 1294 and then Is_Access_Type (Etype (Odf)) 1295 then 1296 Ent := Designated_Type (Etype (Odf)); 1297 1298 elsif Is_Entity_Name (Odf) then 1299 Ent := Entity (Odf); 1300 1301 elsif Nkind (Odf) = N_Subtype_Indication then 1302 Ent := Etype (Subtype_Mark (Odf)); 1303 1304 elsif Nkind (Odf) = N_Constrained_Array_Definition then 1305 Ent := Component_Type (T); 1306 end if; 1307 1308 if Is_Task_Type (Ent) 1309 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent)) 1310 then 1311 Error_Msg_N 1312 ("concurrent object not allowed in preelaborated unit", 1313 N); 1314 return; 1315 end if; 1316 end; 1317 end if; 1318 1319 -- Non-static discriminants not allowed in preelaborated unit. 1320 -- Objects of a controlled type with a user-defined Initialize 1321 -- are forbidden as well. 1322 1323 if Is_Record_Type (Etype (Id)) then 1324 declare 1325 ET : constant Entity_Id := Etype (Id); 1326 EE : constant Entity_Id := Etype (Etype (Id)); 1327 PEE : Node_Id; 1328 1329 begin 1330 if Has_Discriminants (ET) and then Present (EE) then 1331 PEE := Parent (EE); 1332 1333 if Nkind (PEE) = N_Full_Type_Declaration 1334 and then not Static_Discriminant_Expr 1335 (Discriminant_Specifications (PEE)) 1336 then 1337 Error_Msg_N 1338 ("non-static discriminant in preelaborated unit", 1339 PEE); 1340 end if; 1341 end if; 1342 1343 -- For controlled type or type with controlled component, check 1344 -- preelaboration flag, as there may be a non-null Initialize 1345 -- primitive. For language versions earlier than Ada 2005, 1346 -- there is no notion of preelaborable initialization, and 1347 -- Validate_Controlled_Object is used to enforce rules for 1348 -- controlled objects. 1349 1350 if (Is_Controlled (ET) or else Has_Controlled_Component (ET)) 1351 and then Ada_Version >= Ada_2005 1352 and then not Has_Preelaborable_Initialization (ET) 1353 then 1354 Error_Msg_NE 1355 ("controlled type& does not have" 1356 & " preelaborable initialization", N, ET); 1357 end if; 1358 end; 1359 1360 end if; 1361 end if; 1362 1363 -- A pure library_item must not contain the declaration of any variable 1364 -- except within a subprogram, generic subprogram, task unit, or 1365 -- protected unit (RM 10.2.1(16)). 1366 1367 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then 1368 Error_Msg_N ("declaration of variable not allowed in pure unit", N); 1369 1370 -- The visible part of an RCI library unit must not contain the 1371 -- declaration of a variable (RM E.1.3(9)) 1372 1373 elsif In_RCI_Declaration (N) then 1374 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N); 1375 1376 -- The visible part of a Shared Passive library unit must not contain 1377 -- the declaration of a variable (RM E.2.2(7)) 1378 1379 elsif In_RT_Declaration and then not In_Private_Part (Id) then 1380 Error_Msg_N 1381 ("visible variable not allowed in remote types unit", N); 1382 end if; 1383 1384 end Validate_Object_Declaration; 1385 1386 ----------------------------- 1387 -- Validate_RACW_Primitive -- 1388 ----------------------------- 1389 1390 procedure Validate_RACW_Primitive 1391 (Subp : Entity_Id; 1392 RACW : Entity_Id) 1393 is 1394 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id); 1395 -- Diagnose illegality on N. If RACW is present, report the error on it 1396 -- rather than on N. 1397 1398 ------------------------- 1399 -- Illegal_Remote_Subp -- 1400 ------------------------- 1401 1402 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id) is 1403 begin 1404 if Present (RACW) then 1405 if not Error_Posted (RACW) then 1406 Error_Msg_N 1407 ("illegal remote access to class-wide type&", RACW); 1408 end if; 1409 1410 Error_Msg_Sloc := Sloc (N); 1411 Error_Msg_NE ("\\" & Msg & " in primitive& #", RACW, Subp); 1412 1413 else 1414 Error_Msg_NE (Msg & " in remote subprogram&", N, Subp); 1415 end if; 1416 end Illegal_Remote_Subp; 1417 1418 Rtyp : Entity_Id; 1419 Param : Node_Id; 1420 Param_Spec : Node_Id; 1421 Param_Type : Entity_Id; 1422 1423 -- Start of processing for Validate_RACW_Primitive 1424 1425 begin 1426 -- Check return type 1427 1428 if Ekind (Subp) = E_Function then 1429 Rtyp := Etype (Subp); 1430 1431 -- AI05-0101 (Binding Interpretation): The result type of a remote 1432 -- function must either support external streaming or be a 1433 -- controlling access result type. 1434 1435 if Has_Controlling_Result (Subp) then 1436 null; 1437 1438 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then 1439 Illegal_Remote_Subp ("anonymous access result", Rtyp); 1440 1441 elsif Is_Limited_Type (Rtyp) then 1442 if No (TSS (Rtyp, TSS_Stream_Read)) 1443 or else 1444 No (TSS (Rtyp, TSS_Stream_Write)) 1445 then 1446 Illegal_Remote_Subp 1447 ("limited return type must have Read and Write attributes", 1448 Parent (Subp)); 1449 Explain_Limited_Type (Rtyp, Parent (Subp)); 1450 end if; 1451 1452 -- Check that the return type supports external streaming 1453 1454 elsif No_External_Streaming (Rtyp) 1455 and then not Error_Posted (Rtyp) 1456 then 1457 Illegal_Remote_Subp ("return type containing non-remote access " 1458 & "must have Read and Write attributes", 1459 Parent (Subp)); 1460 end if; 1461 end if; 1462 1463 Param := First_Formal (Subp); 1464 while Present (Param) loop 1465 1466 -- Now find out if this parameter is a controlling parameter 1467 1468 Param_Spec := Parent (Param); 1469 Param_Type := Etype (Param); 1470 1471 if Is_Controlling_Formal (Param) then 1472 1473 -- It is a controlling parameter, so specific checks below do not 1474 -- apply. 1475 1476 null; 1477 1478 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type, 1479 E_Anonymous_Access_Subprogram_Type) 1480 then 1481 -- From RM E.2.2(14), no anonymous access parameter other than 1482 -- controlling ones may be used (because an anonymous access 1483 -- type never supports external streaming). 1484 1485 Illegal_Remote_Subp 1486 ("non-controlling access parameter", Param_Spec); 1487 1488 elsif No_External_Streaming (Param_Type) 1489 and then not Error_Posted (Param_Type) 1490 then 1491 Illegal_Remote_Subp ("formal parameter in remote subprogram must " 1492 & "support external streaming", Param_Spec); 1493 end if; 1494 1495 -- Check next parameter in this subprogram 1496 1497 Next_Formal (Param); 1498 end loop; 1499 end Validate_RACW_Primitive; 1500 1501 ------------------------------ 1502 -- Validate_RACW_Primitives -- 1503 ------------------------------ 1504 1505 procedure Validate_RACW_Primitives (T : Entity_Id) is 1506 Desig_Type : Entity_Id; 1507 Primitive_Subprograms : Elist_Id; 1508 Subprogram_Elmt : Elmt_Id; 1509 Subprogram : Entity_Id; 1510 1511 begin 1512 Desig_Type := Etype (Designated_Type (T)); 1513 1514 -- No action needed for concurrent types 1515 1516 if Is_Concurrent_Type (Desig_Type) then 1517 return; 1518 end if; 1519 1520 Primitive_Subprograms := Primitive_Operations (Desig_Type); 1521 1522 Subprogram_Elmt := First_Elmt (Primitive_Subprograms); 1523 while Subprogram_Elmt /= No_Elmt loop 1524 Subprogram := Node (Subprogram_Elmt); 1525 1526 if Is_Predefined_Dispatching_Operation (Subprogram) 1527 or else Is_Hidden (Subprogram) 1528 then 1529 goto Next_Subprogram; 1530 end if; 1531 1532 Validate_RACW_Primitive (Subp => Subprogram, RACW => T); 1533 1534 <<Next_Subprogram>> 1535 Next_Elmt (Subprogram_Elmt); 1536 end loop; 1537 end Validate_RACW_Primitives; 1538 1539 ------------------------------- 1540 -- Validate_RCI_Declarations -- 1541 ------------------------------- 1542 1543 procedure Validate_RCI_Declarations (P : Entity_Id) is 1544 E : Entity_Id; 1545 1546 begin 1547 E := First_Entity (P); 1548 while Present (E) loop 1549 if Comes_From_Source (E) then 1550 if Is_Limited_Type (E) then 1551 Error_Msg_N 1552 ("limited type not allowed in rci unit", Parent (E)); 1553 Explain_Limited_Type (E, Parent (E)); 1554 1555 elsif Ekind_In (E, E_Generic_Function, 1556 E_Generic_Package, 1557 E_Generic_Procedure) 1558 then 1559 Error_Msg_N ("generic declaration not allowed in rci unit", 1560 Parent (E)); 1561 1562 elsif (Ekind (E) = E_Function or else Ekind (E) = E_Procedure) 1563 and then Has_Pragma_Inline (E) 1564 then 1565 Error_Msg_N 1566 ("inlined subprogram not allowed in rci unit", Parent (E)); 1567 1568 -- Inner packages that are renamings need not be checked. Generic 1569 -- RCI packages are subject to the checks, but entities that come 1570 -- from formal packages are not part of the visible declarations 1571 -- of the package and are not checked. 1572 1573 elsif Ekind (E) = E_Package then 1574 if Present (Renamed_Entity (E)) then 1575 null; 1576 1577 elsif Ekind (P) /= E_Generic_Package 1578 or else List_Containing (Unit_Declaration_Node (E)) /= 1579 Generic_Formal_Declarations 1580 (Unit_Declaration_Node (P)) 1581 then 1582 Validate_RCI_Declarations (E); 1583 end if; 1584 end if; 1585 end if; 1586 1587 Next_Entity (E); 1588 end loop; 1589 end Validate_RCI_Declarations; 1590 1591 ----------------------------------------- 1592 -- Validate_RCI_Subprogram_Declaration -- 1593 ----------------------------------------- 1594 1595 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is 1596 K : constant Node_Kind := Nkind (N); 1597 Profile : List_Id; 1598 Id : Node_Id; 1599 Param_Spec : Node_Id; 1600 Param_Type : Entity_Id; 1601 Error_Node : Node_Id := N; 1602 1603 begin 1604 -- This procedure enforces rules on subprogram and access to subprogram 1605 -- declarations in RCI units. These rules do not apply to expander 1606 -- generated routines, which are not remote subprograms. It is called: 1607 1608 -- 1. from Analyze_Subprogram_Declaration. 1609 -- 2. from Validate_Object_Declaration (access to subprogram). 1610 1611 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then 1612 return; 1613 end if; 1614 1615 if K = N_Subprogram_Declaration then 1616 Id := Defining_Unit_Name (Specification (N)); 1617 Profile := Parameter_Specifications (Specification (N)); 1618 1619 else pragma Assert (K = N_Object_Declaration); 1620 1621 -- The above assertion is dubious, the visible declarations of an 1622 -- RCI unit never contain an object declaration, this should be an 1623 -- ACCESS-to-object declaration??? 1624 1625 Id := Defining_Identifier (N); 1626 1627 if Nkind (Id) = N_Defining_Identifier 1628 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration 1629 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type 1630 then 1631 Profile := 1632 Parameter_Specifications (Type_Definition (Parent (Etype (Id)))); 1633 else 1634 return; 1635 end if; 1636 end if; 1637 1638 -- Iterate through the parameter specification list, checking that 1639 -- no access parameter and no limited type parameter in the list. 1640 -- RM E.2.3(14). 1641 1642 if Present (Profile) then 1643 Param_Spec := First (Profile); 1644 while Present (Param_Spec) loop 1645 Param_Type := Etype (Defining_Identifier (Param_Spec)); 1646 1647 if Ekind (Param_Type) = E_Anonymous_Access_Type then 1648 if K = N_Subprogram_Declaration then 1649 Error_Node := Param_Spec; 1650 end if; 1651 1652 -- Report error only if declaration is in source program 1653 1654 if Comes_From_Source 1655 (Defining_Entity (Specification (N))) 1656 then 1657 Error_Msg_N 1658 ("subprogram in 'R'C'I unit cannot have access parameter", 1659 Error_Node); 1660 end if; 1661 1662 -- For a limited private type parameter, we check only the private 1663 -- declaration and ignore full type declaration, unless this is 1664 -- the only declaration for the type, e.g., as a limited record. 1665 1666 elsif No_External_Streaming (Param_Type) then 1667 if K = N_Subprogram_Declaration then 1668 Error_Node := Param_Spec; 1669 end if; 1670 1671 Error_Msg_NE 1672 ("formal of remote subprogram& " 1673 & "must support external streaming", 1674 Error_Node, Id); 1675 if Is_Limited_Type (Param_Type) then 1676 Explain_Limited_Type (Param_Type, Error_Node); 1677 end if; 1678 end if; 1679 1680 Next (Param_Spec); 1681 end loop; 1682 1683 -- No check on return type??? 1684 end if; 1685 end Validate_RCI_Subprogram_Declaration; 1686 1687 ---------------------------------------------------- 1688 -- Validate_Remote_Access_Object_Type_Declaration -- 1689 ---------------------------------------------------- 1690 1691 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is 1692 Direct_Designated_Type : Entity_Id; 1693 Desig_Type : Entity_Id; 1694 1695 begin 1696 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of 1697 -- the given node is N_Access_To_Object_Definition. 1698 1699 if not Comes_From_Source (T) 1700 or else (not In_RCI_Declaration (Parent (T)) 1701 and then not In_RT_Declaration) 1702 then 1703 return; 1704 end if; 1705 1706 -- An access definition in the private part of a Remote Types package 1707 -- may be legal if it has user-defined Read and Write attributes. This 1708 -- will be checked at the end of the package spec processing. 1709 1710 if In_RT_Declaration and then In_Private_Part (Scope (T)) then 1711 return; 1712 end if; 1713 1714 -- Check RCI or RT unit type declaration. It may not contain the 1715 -- declaration of an access-to-object type unless it is a general access 1716 -- type that designates a class-wide limited private type or subtype. 1717 -- There are also constraints on the primitive subprograms of the 1718 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives). 1719 1720 if Ekind (T) /= E_General_Access_Type 1721 or else not Is_Class_Wide_Type (Designated_Type (T)) 1722 then 1723 if In_RCI_Declaration (Parent (T)) then 1724 Error_Msg_N 1725 ("error in access type in Remote_Call_Interface unit", T); 1726 else 1727 Error_Msg_N 1728 ("error in access type in Remote_Types unit", T); 1729 end if; 1730 1731 Error_Msg_N ("\must be general access to class-wide type", T); 1732 return; 1733 end if; 1734 1735 Direct_Designated_Type := Designated_Type (T); 1736 Desig_Type := Etype (Direct_Designated_Type); 1737 1738 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type??? 1739 1740 if not Is_Valid_Remote_Object_Type (Desig_Type) then 1741 Error_Msg_N 1742 ("error in designated type of remote access to class-wide type", T); 1743 Error_Msg_N 1744 ("\must be tagged limited private or private extension", T); 1745 return; 1746 end if; 1747 end Validate_Remote_Access_Object_Type_Declaration; 1748 1749 ----------------------------------------------- 1750 -- Validate_Remote_Access_To_Class_Wide_Type -- 1751 ----------------------------------------------- 1752 1753 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is 1754 K : constant Node_Kind := Nkind (N); 1755 PK : constant Node_Kind := Nkind (Parent (N)); 1756 E : Entity_Id; 1757 1758 begin 1759 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses 1760 -- of class-wide limited private types. 1761 1762 -- Storage_Pool and Storage_Size are not defined for such types 1763 -- 1764 -- The expected type of allocator must not be such a type. 1765 1766 -- The actual parameter of generic instantiation must not be such a 1767 -- type if the formal parameter is of an access type. 1768 1769 -- On entry, there are several cases: 1770 1771 -- 1. called from sem_attr Analyze_Attribute where attribute name is 1772 -- either Storage_Pool or Storage_Size. 1773 1774 -- 2. called from exp_ch4 Expand_N_Allocator 1775 1776 -- 3. called from sem_ch4 Analyze_Explicit_Dereference 1777 1778 -- 4. called from sem_res Resolve_Actuals 1779 1780 if K = N_Attribute_Reference then 1781 E := Etype (Prefix (N)); 1782 1783 if Is_Remote_Access_To_Class_Wide_Type (E) then 1784 Error_Msg_N ("incorrect attribute of remote operand", N); 1785 return; 1786 end if; 1787 1788 elsif K = N_Allocator then 1789 E := Etype (N); 1790 1791 if Is_Remote_Access_To_Class_Wide_Type (E) then 1792 Error_Msg_N ("incorrect expected remote type of allocator", N); 1793 return; 1794 end if; 1795 1796 -- This subprogram also enforces the checks in E.2.2(13). A value of 1797 -- such type must not be dereferenced unless as controlling operand of 1798 -- a dispatching call. Explicit dereferences not coming from source are 1799 -- exempted from this checking because the expander produces them in 1800 -- some cases (such as for tag checks on dispatching calls with multiple 1801 -- controlling operands). However we do check in the case of an implicit 1802 -- dereference that is expanded to an explicit dereference (hence the 1803 -- test of whether Original_Node (N) comes from source). 1804 1805 elsif K = N_Explicit_Dereference 1806 and then Comes_From_Source (Original_Node (N)) 1807 then 1808 E := Etype (Prefix (N)); 1809 1810 -- If the class-wide type is not a remote one, the restrictions 1811 -- do not apply. 1812 1813 if not Is_Remote_Access_To_Class_Wide_Type (E) then 1814 return; 1815 end if; 1816 1817 -- If we have a true dereference that comes from source and that 1818 -- is a controlling argument for a dispatching call, accept it. 1819 1820 if Is_Actual_Parameter (N) and then Is_Controlling_Actual (N) then 1821 return; 1822 end if; 1823 1824 -- If we are just within a procedure or function call and the 1825 -- dereference has not been analyzed, return because this procedure 1826 -- will be called again from sem_res Resolve_Actuals. The same can 1827 -- apply in the case of dereference that is the prefix of a selected 1828 -- component, which can be a call given in prefixed form. 1829 1830 if (Is_Actual_Parameter (N) or else PK = N_Selected_Component) 1831 and then not Analyzed (N) 1832 then 1833 return; 1834 end if; 1835 1836 -- We must allow expanded code to generate a reference to the tag of 1837 -- the designated object (may be either the actual tag, or the stub 1838 -- tag in the case of a remote object). 1839 1840 if PK = N_Selected_Component 1841 and then Is_Tag (Entity (Selector_Name (Parent (N)))) 1842 then 1843 return; 1844 end if; 1845 1846 Error_Msg_N 1847 ("invalid dereference of a remote access-to-class-wide value", N); 1848 end if; 1849 end Validate_Remote_Access_To_Class_Wide_Type; 1850 1851 ------------------------------------------ 1852 -- Validate_Remote_Type_Type_Conversion -- 1853 ------------------------------------------ 1854 1855 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is 1856 S : constant Entity_Id := Etype (N); 1857 E : constant Entity_Id := Etype (Expression (N)); 1858 1859 begin 1860 -- This test is required in the case where a conversion appears inside a 1861 -- normal package, it does not necessarily have to be inside an RCI, 1862 -- Remote_Types unit (RM E.2.2(9,12)). 1863 1864 if Is_Remote_Access_To_Subprogram_Type (E) 1865 and then not Is_Remote_Access_To_Subprogram_Type (S) 1866 then 1867 Error_Msg_N 1868 ("incorrect conversion of remote operand to local type", N); 1869 return; 1870 1871 elsif not Is_Remote_Access_To_Subprogram_Type (E) 1872 and then Is_Remote_Access_To_Subprogram_Type (S) 1873 then 1874 Error_Msg_N 1875 ("incorrect conversion of local operand to remote type", N); 1876 return; 1877 1878 elsif Is_Remote_Access_To_Class_Wide_Type (E) 1879 and then not Is_Remote_Access_To_Class_Wide_Type (S) 1880 then 1881 Error_Msg_N 1882 ("incorrect conversion of remote operand to local type", N); 1883 return; 1884 end if; 1885 1886 -- If a local access type is converted into a RACW type, then the 1887 -- current unit has a pointer that may now be exported to another 1888 -- partition. 1889 1890 if Is_Remote_Access_To_Class_Wide_Type (S) 1891 and then not Is_Remote_Access_To_Class_Wide_Type (E) 1892 then 1893 Set_Has_RACW (Current_Sem_Unit); 1894 end if; 1895 end Validate_Remote_Type_Type_Conversion; 1896 1897 ------------------------------- 1898 -- Validate_RT_RAT_Component -- 1899 ------------------------------- 1900 1901 procedure Validate_RT_RAT_Component (N : Node_Id) is 1902 Spec : constant Node_Id := Specification (N); 1903 Name_U : constant Entity_Id := Defining_Entity (Spec); 1904 Typ : Entity_Id; 1905 U_Typ : Entity_Id; 1906 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U); 1907 1908 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean; 1909 -- True if any stream attribute is available for Typ 1910 1911 --------------------------------- 1912 -- Stream_Attributes_Available -- 1913 --------------------------------- 1914 1915 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean 1916 is 1917 begin 1918 return Stream_Attribute_Available (Typ, TSS_Stream_Read) 1919 or else 1920 Stream_Attribute_Available (Typ, TSS_Stream_Write) 1921 or else 1922 Stream_Attribute_Available (Typ, TSS_Stream_Input) 1923 or else 1924 Stream_Attribute_Available (Typ, TSS_Stream_Output); 1925 end Stream_Attributes_Available; 1926 1927 -- Start of processing for Validate_RT_RAT_Component 1928 1929 begin 1930 if not Is_Remote_Types (Name_U) then 1931 return; 1932 end if; 1933 1934 Typ := First_Entity (Name_U); 1935 while Present (Typ) and then Typ /= First_Priv_Ent loop 1936 U_Typ := Underlying_Type (Typ); 1937 1938 if No (U_Typ) then 1939 U_Typ := Typ; 1940 end if; 1941 1942 if Comes_From_Source (Typ) and then Is_Type (Typ) then 1943 1944 -- Check that the type can be meaningfully transmitted to another 1945 -- partition (E.2.2(8)). 1946 1947 if (Ada_Version < Ada_2005 and then Has_Non_Remote_Access (U_Typ)) 1948 or else (Stream_Attributes_Available (Typ) 1949 and then No_External_Streaming (U_Typ)) 1950 then 1951 if Is_Non_Remote_Access_Type (Typ) then 1952 Error_Msg_N ("error in non-remote access type", U_Typ); 1953 else 1954 Error_Msg_N 1955 ("error in record type containing a component of a " & 1956 "non-remote access type", U_Typ); 1957 end if; 1958 1959 if Ada_Version >= Ada_2005 then 1960 Error_Msg_N 1961 ("\must have visible Read and Write attribute " & 1962 "definition clauses (RM E.2.2(8))", U_Typ); 1963 else 1964 Error_Msg_N 1965 ("\must have Read and Write attribute " & 1966 "definition clauses (RM E.2.2(8))", U_Typ); 1967 end if; 1968 end if; 1969 end if; 1970 1971 Next_Entity (Typ); 1972 end loop; 1973 end Validate_RT_RAT_Component; 1974 1975 ----------------------------------------- 1976 -- Validate_SP_Access_Object_Type_Decl -- 1977 ----------------------------------------- 1978 1979 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is 1980 Direct_Designated_Type : Entity_Id; 1981 1982 function Has_Entry_Declarations (E : Entity_Id) return Boolean; 1983 -- Return true if the protected type designated by T has entry 1984 -- declarations. 1985 1986 ---------------------------- 1987 -- Has_Entry_Declarations -- 1988 ---------------------------- 1989 1990 function Has_Entry_Declarations (E : Entity_Id) return Boolean is 1991 Ety : Entity_Id; 1992 1993 begin 1994 if Nkind (Parent (E)) = N_Protected_Type_Declaration then 1995 Ety := First_Entity (E); 1996 while Present (Ety) loop 1997 if Ekind (Ety) = E_Entry then 1998 return True; 1999 end if; 2000 2001 Next_Entity (Ety); 2002 end loop; 2003 end if; 2004 2005 return False; 2006 end Has_Entry_Declarations; 2007 2008 -- Start of processing for Validate_SP_Access_Object_Type_Decl 2009 2010 begin 2011 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the 2012 -- Nkind of the given entity is N_Access_To_Object_Definition. 2013 2014 if not Comes_From_Source (T) 2015 or else not In_Shared_Passive_Unit 2016 or else In_Subprogram_Task_Protected_Unit 2017 then 2018 return; 2019 end if; 2020 2021 -- Check Shared Passive unit. It should not contain the declaration 2022 -- of an access-to-object type whose designated type is a class-wide 2023 -- type, task type or protected type with entry (RM E.2.1(7)). 2024 2025 Direct_Designated_Type := Designated_Type (T); 2026 2027 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then 2028 Error_Msg_N 2029 ("invalid access-to-class-wide type in shared passive unit", T); 2030 return; 2031 2032 elsif Ekind (Direct_Designated_Type) in Task_Kind then 2033 Error_Msg_N 2034 ("invalid access-to-task type in shared passive unit", T); 2035 return; 2036 2037 elsif Ekind (Direct_Designated_Type) in Protected_Kind 2038 and then Has_Entry_Declarations (Direct_Designated_Type) 2039 then 2040 Error_Msg_N 2041 ("invalid access-to-protected type in shared passive unit", T); 2042 return; 2043 end if; 2044 end Validate_SP_Access_Object_Type_Decl; 2045 2046 --------------------------------- 2047 -- Validate_Static_Object_Name -- 2048 --------------------------------- 2049 2050 procedure Validate_Static_Object_Name (N : Node_Id) is 2051 E : Entity_Id; 2052 2053 function Is_Primary (N : Node_Id) return Boolean; 2054 -- Determine whether node is syntactically a primary in an expression 2055 -- This function should probably be somewhere else ??? 2056 -- 2057 -- Also it does not do what it says, e.g if N is a binary operator 2058 -- whose parent is a binary operator, Is_Primary returns True ??? 2059 2060 ---------------- 2061 -- Is_Primary -- 2062 ---------------- 2063 2064 function Is_Primary (N : Node_Id) return Boolean is 2065 K : constant Node_Kind := Nkind (Parent (N)); 2066 2067 begin 2068 case K is 2069 when N_Op | N_Membership_Test => 2070 return True; 2071 2072 when N_Aggregate 2073 | N_Component_Association 2074 | N_Index_Or_Discriminant_Constraint => 2075 return True; 2076 2077 when N_Attribute_Reference => 2078 return Attribute_Name (Parent (N)) /= Name_Address 2079 and then Attribute_Name (Parent (N)) /= Name_Access 2080 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access 2081 and then 2082 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access; 2083 2084 when N_Indexed_Component => 2085 return (N /= Prefix (Parent (N)) 2086 or else Is_Primary (Parent (N))); 2087 2088 when N_Qualified_Expression | N_Type_Conversion => 2089 return Is_Primary (Parent (N)); 2090 2091 when N_Assignment_Statement | N_Object_Declaration => 2092 return (N = Expression (Parent (N))); 2093 2094 when N_Selected_Component => 2095 return Is_Primary (Parent (N)); 2096 2097 when others => 2098 return False; 2099 end case; 2100 end Is_Primary; 2101 2102 -- Start of processing for Validate_Static_Object_Name 2103 2104 begin 2105 if not In_Preelaborated_Unit 2106 or else not Comes_From_Source (N) 2107 or else In_Subprogram_Or_Concurrent_Unit 2108 or else Ekind (Current_Scope) = E_Block 2109 then 2110 return; 2111 2112 -- Filter out cases where primary is default in a component declaration, 2113 -- discriminant specification, or actual in a record type initialization 2114 -- call. 2115 2116 -- Initialization call of internal types 2117 2118 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then 2119 2120 if Present (Parent (Parent (N))) 2121 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity 2122 then 2123 return; 2124 end if; 2125 2126 if Nkind (Name (Parent (N))) = N_Identifier 2127 and then not Comes_From_Source (Entity (Name (Parent (N)))) 2128 then 2129 return; 2130 end if; 2131 end if; 2132 2133 -- Error if the name is a primary in an expression. The parent must not 2134 -- be an operator, or a selected component or an indexed component that 2135 -- is itself a primary. Entities that are actuals do not need to be 2136 -- checked, because the call itself will be diagnosed. 2137 2138 if Is_Primary (N) 2139 and then (not Inside_A_Generic 2140 or else Present (Enclosing_Generic_Body (N))) 2141 then 2142 if Ekind (Entity (N)) = E_Variable 2143 or else Ekind (Entity (N)) in Formal_Object_Kind 2144 then 2145 Flag_Non_Static_Expr 2146 ("non-static object name in preelaborated unit", N); 2147 2148 -- Give an error for a reference to a nonstatic constant, unless the 2149 -- constant is in another GNAT library unit that is preelaborable. 2150 2151 elsif Ekind (Entity (N)) = E_Constant 2152 and then not Is_Static_Expression (N) 2153 then 2154 E := Entity (N); 2155 2156 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N))) 2157 and then 2158 Enclosing_Comp_Unit_Node (N) /= Enclosing_Comp_Unit_Node (E) 2159 and then (Is_Preelaborated (Scope (E)) 2160 or else Is_Pure (Scope (E)) 2161 or else (Present (Renamed_Object (E)) 2162 and then Is_Entity_Name (Renamed_Object (E)) 2163 and then 2164 (Is_Preelaborated 2165 (Scope (Renamed_Object (E))) 2166 or else 2167 Is_Pure (Scope 2168 (Renamed_Object (E)))))) 2169 then 2170 null; 2171 2172 -- This is the error case 2173 2174 else 2175 -- In GNAT mode or Relaxed RM Semantic mode, this is just a 2176 -- warning, to allow it to be judiciously turned off. 2177 -- Otherwise it is a real error. 2178 2179 if GNAT_Mode or Relaxed_RM_Semantics then 2180 Error_Msg_N 2181 ("??non-static constant in preelaborated unit", N); 2182 else 2183 Flag_Non_Static_Expr 2184 ("non-static constant in preelaborated unit", N); 2185 end if; 2186 end if; 2187 end if; 2188 end if; 2189 end Validate_Static_Object_Name; 2190 2191end Sem_Cat; 2192