1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Disp; use Exp_Disp;
32 with Fname; use Fname;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
38 with Sem_Aux; use Sem_Aux;
39 with Sem_Eval; use Sem_Eval;
40 with Sem_Util; use Sem_Util;
41 with Sinfo; use Sinfo;
42 with Snames; use Snames;
43 with Stand; use Stand;
45 package body Sem_Cat is
47 -----------------------
48 -- Local Subprograms --
49 -----------------------
51 procedure Check_Categorization_Dependencies
52 (Unit_Entity : Entity_Id;
53 Depended_Entity : Entity_Id;
55 Is_Subunit : Boolean);
56 -- This procedure checks that the categorization of a lib unit and that
57 -- of the depended unit satisfy dependency restrictions.
58 -- The depended_entity can be the entity in a with_clause item, in which
59 -- case Info_Node denotes that item. The depended_entity can also be the
60 -- parent unit of a child unit, in which case Info_Node is the declaration
61 -- of the child unit. The error message is posted on Info_Node, and is
62 -- specialized if Is_Subunit is true.
64 procedure Check_Non_Static_Default_Expr
67 -- Iterate through the component list of a record definition, check
68 -- that no component is declared with a nonstatic default value.
69 -- If a nonstatic default exists, report an error on Obj_Decl.
71 -- Iterate through the component list of a record definition, check
72 -- that no component is declared with a non-static default value.
74 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
75 -- Return True if the entity or one of its subcomponents is of an access
76 -- type that does not have user-defined Read and Write attributes visible
79 function In_RCI_Declaration (N : Node_Id) return Boolean;
80 -- Determines if a declaration is within the visible part of a Remote
81 -- Call Interface compilation unit, for semantic checking purposes only,
82 -- (returns false within an instance and within the package body).
84 function In_RT_Declaration return Boolean;
85 -- Determines if current scope is within a Remote Types compilation unit,
86 -- for semantic checking purposes.
88 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
89 -- Returns true if the entity is a type whose full view is a non-remote
90 -- access type, for the purpose of enforcing E.2.2(8) rules.
92 function In_Shared_Passive_Unit return Boolean;
93 -- Determines if current scope is within a Shared Passive compilation unit
95 function Static_Discriminant_Expr (L : List_Id) return Boolean;
96 -- Iterate through the list of discriminants to check if any of them
97 -- contains non-static default expression, which is a violation in
98 -- a preelaborated library unit.
100 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
101 -- Check validity of declaration if RCI or RT unit. It should not contain
102 -- the declaration of an access-to-object type unless it is a general
103 -- access type that designates a class-wide limited private type. There are
104 -- also constraints about the primitive subprograms of the class-wide type.
105 -- RM E.2 (9, 13, 14)
107 ---------------------------------------
108 -- Check_Categorization_Dependencies --
109 ---------------------------------------
111 procedure Check_Categorization_Dependencies
112 (Unit_Entity : Entity_Id;
113 Depended_Entity : Entity_Id;
115 Is_Subunit : Boolean)
117 N : constant Node_Id := Info_Node;
120 -- Here we define an enumeration type to represent categorization types,
121 -- ordered so that a unit with a given categorization can only WITH
122 -- units with lower or equal categorization type.
124 type Categorization is
128 Remote_Call_Interface,
131 function Get_Categorization (E : Entity_Id) return Categorization;
132 -- Check categorization flags from entity, and return in the form
133 -- of the lowest value of the Categorization type that applies to E.
135 ------------------------
136 -- Get_Categorization --
137 ------------------------
139 function Get_Categorization (E : Entity_Id) return Categorization is
141 -- Get the lowest categorization that corresponds to E. Note that
142 -- nothing prevents several (different) categorization pragmas
143 -- to apply to the same library unit, in which case the unit has
144 -- all associated categories, so we need to be careful here to
145 -- check pragmas in proper Categorization order in order to
146 -- return the lowest applicable value.
148 -- Ignore Pure specification if set by pragma Pure_Function
152 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
156 elsif Is_Shared_Passive (E) then
157 return Shared_Passive;
159 elsif Is_Remote_Types (E) then
162 elsif Is_Remote_Call_Interface (E) then
163 return Remote_Call_Interface;
168 end Get_Categorization;
170 Unit_Category : Categorization;
171 With_Category : Categorization;
173 -- Start of processing for Check_Categorization_Dependencies
176 -- Intrinsic subprograms are preelaborated, so do not impose any
177 -- categorization dependencies.
179 if Is_Intrinsic_Subprogram (Depended_Entity) then
183 -- First check 10.2.1 (11/1) rules on preelaborate packages
185 if Is_Preelaborated (Unit_Entity)
186 and then not Is_Preelaborated (Depended_Entity)
187 and then not Is_Pure (Depended_Entity)
194 -- Check categorization rules of RM E.2(5)
196 Unit_Category := Get_Categorization (Unit_Entity);
197 With_Category := Get_Categorization (Depended_Entity);
199 if With_Category > Unit_Category then
201 -- Special case: Remote_Types and Remote_Call_Interface are allowed
202 -- to WITH anything in the package body, per (RM E.2(5)).
204 if (Unit_Category = Remote_Types
205 or else Unit_Category = Remote_Call_Interface)
206 and then In_Package_Body (Unit_Entity)
214 -- Here if we have an error
218 -- These messages are warnings in GNAT mode, to allow it to be
219 -- judiciously turned off. Otherwise it is a real error.
221 Error_Msg_Warn := GNAT_Mode;
223 -- Don't give error if main unit is not an internal unit, and the
224 -- unit generating the message is an internal unit. This is the
225 -- situation in which such messages would be ignored in any case,
226 -- so it is convenient not to generate them (since it causes
227 -- annoying interference with debugging).
229 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
230 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
236 elsif Is_Subunit then
238 ("<subunit cannot depend on& " &
239 "(parent has wrong categorization)", N, Depended_Entity);
241 -- Normal unit, not subunit
245 ("<cannot depend on& " &
246 "(wrong categorization)", N, Depended_Entity);
249 -- Add further explanation for Pure/Preelaborate common cases
251 if Unit_Category = Pure then
253 ("\<pure unit cannot depend on non-pure unit",
256 elsif Is_Preelaborated (Unit_Entity)
257 and then not Is_Preelaborated (Depended_Entity)
258 and then not Is_Pure (Depended_Entity)
261 ("\<preelaborated unit cannot depend on "
262 & "non-preelaborated unit",
266 end Check_Categorization_Dependencies;
268 -----------------------------------
269 -- Check_Non_Static_Default_Expr --
270 -----------------------------------
272 procedure Check_Non_Static_Default_Expr
277 Component_Decl : Node_Id;
280 if Nkind (Type_Def) = N_Derived_Type_Definition then
281 Recdef := Record_Extension_Part (Type_Def);
291 -- Check that component declarations do not involve:
293 -- a. a non-static default expression, where the object is
294 -- declared to be default initialized.
296 -- b. a dynamic Itype (discriminants and constraints)
298 if Null_Present (Recdef) then
301 Component_Decl := First (Component_Items (Component_List (Recdef)));
304 while Present (Component_Decl)
305 and then Nkind (Component_Decl) = N_Component_Declaration
307 if Present (Expression (Component_Decl))
308 and then Nkind (Expression (Component_Decl)) /= N_Null
309 and then not Is_Static_Expression (Expression (Component_Decl))
311 Error_Msg_Sloc := Sloc (Component_Decl);
313 ("object in preelaborated unit has non-static default#",
316 -- Fix this later ???
318 -- elsif Has_Dynamic_Itype (Component_Decl) then
320 -- ("dynamic type discriminant," &
321 -- " constraint in preelaborated unit",
325 Next (Component_Decl);
327 end Check_Non_Static_Default_Expr;
329 -------------------------------------
330 -- Has_Stream_Attribute_Definition --
331 -------------------------------------
333 function Has_Stream_Attribute_Definition
336 At_Any_Place : Boolean := False) return Boolean
339 Full_Type : Entity_Id := Typ;
342 -- In the case of a type derived from a private view, any specified
343 -- stream attributes will be attached to the derived type's underlying
344 -- type rather the derived type entity itself (which is itself private).
346 if Is_Private_Type (Typ)
347 and then Is_Derived_Type (Typ)
348 and then Present (Full_View (Typ))
350 Full_Type := Underlying_Type (Typ);
353 -- We start from the declaration node and then loop until the end of
354 -- the list until we find the requested attribute definition clause.
355 -- In Ada 2005 mode, clauses are ignored if they are not currently
356 -- visible (this is tested using the corresponding Entity, which is
357 -- inserted by the expander at the point where the clause occurs),
358 -- unless At_Any_Place is true.
360 Rep_Item := First_Rep_Item (Full_Type);
361 while Present (Rep_Item) loop
362 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
363 case Chars (Rep_Item) is
365 exit when Nam = TSS_Stream_Read;
368 exit when Nam = TSS_Stream_Write;
371 exit when Nam = TSS_Stream_Input;
374 exit when Nam = TSS_Stream_Output;
382 Next_Rep_Item (Rep_Item);
385 -- If At_Any_Place is true, return True if the attribute is available
386 -- at any place; if it is false, return True only if the attribute is
387 -- currently visible.
389 return Present (Rep_Item)
390 and then (Ada_Version < Ada_05
392 or else not Is_Hidden (Entity (Rep_Item)));
393 end Has_Stream_Attribute_Definition;
395 ---------------------------
396 -- In_Preelaborated_Unit --
397 ---------------------------
399 function In_Preelaborated_Unit return Boolean is
400 Unit_Entity : constant Entity_Id := Current_Scope;
401 Unit_Kind : constant Node_Kind :=
402 Nkind (Unit (Cunit (Current_Sem_Unit)));
405 -- There are no constraints on body of remote_call_interface or
406 -- remote_types packages.
408 return (Unit_Entity /= Standard_Standard)
409 and then (Is_Preelaborated (Unit_Entity)
410 or else Is_Pure (Unit_Entity)
411 or else Is_Shared_Passive (Unit_Entity)
413 ((Is_Remote_Types (Unit_Entity)
414 or else Is_Remote_Call_Interface (Unit_Entity))
415 and then Ekind (Unit_Entity) = E_Package
416 and then Unit_Kind /= N_Package_Body
417 and then not In_Package_Body (Unit_Entity)
418 and then not In_Instance));
419 end In_Preelaborated_Unit;
425 function In_Pure_Unit return Boolean is
427 return Is_Pure (Current_Scope);
430 ------------------------
431 -- In_RCI_Declaration --
432 ------------------------
434 function In_RCI_Declaration (N : Node_Id) return Boolean is
435 Unit_Entity : constant Entity_Id := Current_Scope;
436 Unit_Kind : constant Node_Kind :=
437 Nkind (Unit (Cunit (Current_Sem_Unit)));
440 -- There are no restrictions on the private part or body
443 return Is_Remote_Call_Interface (Unit_Entity)
444 and then Is_Package_Or_Generic_Package (Unit_Entity)
445 and then Unit_Kind /= N_Package_Body
446 and then List_Containing (N) =
448 (Specification (Unit_Declaration_Node (Unit_Entity)))
449 and then not In_Package_Body (Unit_Entity)
450 and then not In_Instance;
452 -- What about the case of a nested package in the visible part???
453 -- This case is missed by the List_Containing check above???
454 end In_RCI_Declaration;
456 -----------------------
457 -- In_RT_Declaration --
458 -----------------------
460 function In_RT_Declaration return Boolean is
461 Unit_Entity : constant Entity_Id := Current_Scope;
462 Unit_Kind : constant Node_Kind :=
463 Nkind (Unit (Cunit (Current_Sem_Unit)));
466 -- There are no restrictions on the body of a Remote Types unit
468 return Is_Remote_Types (Unit_Entity)
469 and then Is_Package_Or_Generic_Package (Unit_Entity)
470 and then Unit_Kind /= N_Package_Body
471 and then not In_Package_Body (Unit_Entity)
472 and then not In_Instance;
473 end In_RT_Declaration;
475 ----------------------------
476 -- In_Shared_Passive_Unit --
477 ----------------------------
479 function In_Shared_Passive_Unit return Boolean is
480 Unit_Entity : constant Entity_Id := Current_Scope;
483 return Is_Shared_Passive (Unit_Entity);
484 end In_Shared_Passive_Unit;
486 ---------------------------------------
487 -- In_Subprogram_Task_Protected_Unit --
488 ---------------------------------------
490 function In_Subprogram_Task_Protected_Unit return Boolean is
494 -- The following is to verify that a declaration is inside
495 -- subprogram, generic subprogram, task unit, protected unit.
496 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
498 -- Use scope chain to check successively outer scopes
504 Is_Generic_Subprogram (E)
506 Is_Concurrent_Type (E)
510 elsif E = Standard_Standard then
516 end In_Subprogram_Task_Protected_Unit;
518 -------------------------------
519 -- Is_Non_Remote_Access_Type --
520 -------------------------------
522 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
523 U_E : constant Entity_Id := Underlying_Type (E);
527 -- This case arises for the case of a generic formal type, in which
528 -- case E.2.2(8) rules will be enforced at instantiation time.
533 return Is_Access_Type (U_E)
534 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
535 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
536 end Is_Non_Remote_Access_Type;
538 ----------------------------------
539 -- Missing_Read_Write_Attribute --
540 ----------------------------------
542 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
543 Component : Entity_Id;
544 Component_Type : Entity_Id;
545 U_E : constant Entity_Id := Underlying_Type (E);
547 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
548 -- Return True if entity has attribute definition clauses for Read and
549 -- Write attributes that are visible at some place.
551 -------------------------------
552 -- Has_Read_Write_Attributes --
553 -------------------------------
555 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
558 and then Has_Stream_Attribute_Definition (E,
559 TSS_Stream_Read, At_Any_Place => True)
560 and then Has_Stream_Attribute_Definition (E,
561 TSS_Stream_Write, At_Any_Place => True);
562 end Has_Read_Write_Attributes;
564 -- Start of processing for Missing_Read_Write_Attributes
570 elsif Has_Read_Write_Attributes (E)
571 or else Has_Read_Write_Attributes (U_E)
575 elsif Is_Non_Remote_Access_Type (U_E) then
579 if Is_Record_Type (U_E) then
580 Component := First_Entity (U_E);
581 while Present (Component) loop
582 if not Is_Tag (Component) then
583 Component_Type := Etype (Component);
585 if Missing_Read_Write_Attributes (Component_Type) then
590 Next_Entity (Component);
595 end Missing_Read_Write_Attributes;
597 -------------------------------------
598 -- Set_Categorization_From_Pragmas --
599 -------------------------------------
601 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
602 P : constant Node_Id := Parent (N);
603 S : constant Entity_Id := Current_Scope;
605 procedure Set_Parents (Visibility : Boolean);
606 -- If this is a child instance, the parents are not immediately
607 -- visible during analysis. Make them momentarily visible so that
608 -- the argument of the pragma can be resolved properly, and reset
615 procedure Set_Parents (Visibility : Boolean) is
619 while Present (Par) and then Par /= Standard_Standard loop
620 Set_Is_Immediately_Visible (Par, Visibility);
625 -- Start of processing for Set_Categorization_From_Pragmas
628 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
629 -- The purpose is to set categorization flags before analyzing the
630 -- unit itself, so as to diagnose violations of categorization as
631 -- we process each declaration, even though the pragma appears after
634 if Nkind (P) /= N_Compilation_Unit then
643 and then Is_Generic_Instance (S)
648 PN := First (Pragmas_After (Aux_Decls_Node (P)));
649 while Present (PN) loop
651 -- Skip implicit types that may have been introduced by
652 -- previous analysis.
654 if Nkind (PN) = N_Pragma then
655 case Get_Pragma_Id (PN) is
656 when Pragma_All_Calls_Remote |
657 Pragma_Preelaborate |
659 Pragma_Remote_Call_Interface |
660 Pragma_Remote_Types |
661 Pragma_Shared_Passive => Analyze (PN);
670 and then Is_Generic_Instance (S)
675 end Set_Categorization_From_Pragmas;
677 -----------------------------------
678 -- Set_Categorization_From_Scope --
679 -----------------------------------
681 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
682 Declaration : Node_Id := Empty;
683 Specification : Node_Id := Empty;
687 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
689 if not Is_Remote_Call_Interface (E) then
690 if Ekind (E) in Subprogram_Kind then
691 Declaration := Unit_Declaration_Node (E);
693 if Nkind (Declaration) = N_Subprogram_Body
695 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
697 Specification := Corresponding_Spec (Declaration);
701 -- A subprogram body or renaming-as-body is a remote call
702 -- interface if it serves as the completion of a subprogram
703 -- declaration that is a remote call interface.
705 if Nkind (Specification) in N_Entity then
706 Set_Is_Remote_Call_Interface
707 (E, Is_Remote_Call_Interface (Specification));
709 -- A subprogram declaration is a remote call interface when it is
710 -- declared within the visible part of, or declared by, a library
711 -- unit declaration that is a remote call interface.
714 Set_Is_Remote_Call_Interface
715 (E, Is_Remote_Call_Interface (Scop)
716 and then not (In_Private_Part (Scop)
717 or else In_Package_Body (Scop)));
722 (E, Is_Remote_Types (Scop)
723 and then not (In_Private_Part (Scop)
724 or else In_Package_Body (Scop)));
725 end Set_Categorization_From_Scope;
727 ------------------------------
728 -- Static_Discriminant_Expr --
729 ------------------------------
731 -- We need to accommodate a Why_Not_Static call somehow here ???
733 function Static_Discriminant_Expr (L : List_Id) return Boolean is
734 Discriminant_Spec : Node_Id;
737 Discriminant_Spec := First (L);
738 while Present (Discriminant_Spec) loop
739 if Present (Expression (Discriminant_Spec))
740 and then not Is_Static_Expression (Expression (Discriminant_Spec))
745 Next (Discriminant_Spec);
749 end Static_Discriminant_Expr;
751 --------------------------------------
752 -- Validate_Access_Type_Declaration --
753 --------------------------------------
755 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
756 Def : constant Node_Id := Type_Definition (N);
761 -- Access to subprogram case
763 when N_Access_To_Subprogram_Definition =>
765 -- A pure library_item must not contain the declaration of a
766 -- named access type, except within a subprogram, generic
767 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
769 -- This test is skipped in Ada 2005 (see AI-366)
771 if Ada_Version < Ada_05
772 and then Comes_From_Source (T)
773 and then In_Pure_Unit
774 and then not In_Subprogram_Task_Protected_Unit
776 Error_Msg_N ("named access type not allowed in pure unit", T);
779 -- Access to object case
781 when N_Access_To_Object_Definition =>
782 if Comes_From_Source (T)
783 and then In_Pure_Unit
784 and then not In_Subprogram_Task_Protected_Unit
786 -- We can't give the message yet, since the type is not frozen
787 -- and in Ada 2005 mode, access types are allowed in pure units
788 -- if the type has no storage pool (see AI-366). So we set a
789 -- flag which will be checked at freeze time.
791 Set_Is_Pure_Unit_Access_Type (T);
794 -- Check for RCI or RT unit type declaration: declaration of an
795 -- access-to-object type is illegal unless it is a general access
796 -- type that designates a class-wide limited private type.
797 -- Note that constraints on the primitive subprograms of the
798 -- designated tagged type are not enforced here but in
799 -- Validate_RACW_Primitives, which is done separately because the
800 -- designated type might not be frozen (and therefore its
801 -- primitive operations might not be completely known) at the
802 -- point of the RACW declaration.
804 Validate_Remote_Access_Object_Type_Declaration (T);
806 -- Check for shared passive unit type declaration. It should
807 -- not contain the declaration of access to class wide type,
808 -- access to task type and access to protected type with entry.
810 Validate_SP_Access_Object_Type_Decl (T);
816 -- Set categorization flag from package on entity as well, to allow
817 -- easy checks later on for required validations of RCI or RT units.
818 -- This is only done for entities that are in the original source.
820 if Comes_From_Source (T)
821 and then not (In_Package_Body (Scope (T))
822 or else In_Private_Part (Scope (T)))
824 Set_Is_Remote_Call_Interface
825 (T, Is_Remote_Call_Interface (Scope (T)));
827 (T, Is_Remote_Types (Scope (T)));
829 end Validate_Access_Type_Declaration;
831 ----------------------------
832 -- Validate_Ancestor_Part --
833 ----------------------------
835 procedure Validate_Ancestor_Part (N : Node_Id) is
836 A : constant Node_Id := Ancestor_Part (N);
837 T : constant Entity_Id := Entity (A);
840 if In_Preelaborated_Unit
841 and then not In_Subprogram_Or_Concurrent_Unit
842 and then (not Inside_A_Generic
843 or else Present (Enclosing_Generic_Body (N)))
845 -- If the type is private, it must have the Ada 2005 pragma
846 -- Has_Preelaborable_Initialization.
847 -- The check is omitted within predefined units. This is probably
848 -- obsolete code to fix the Ada95 weakness in this area ???
850 if Is_Private_Type (T)
851 and then not Has_Pragma_Preelab_Init (T)
852 and then not Is_Internal_File_Name
853 (Unit_File_Name (Get_Source_Unit (N)))
856 ("private ancestor type not allowed in preelaborated unit", A);
858 elsif Is_Record_Type (T) then
859 if Nkind (Parent (T)) = N_Full_Type_Declaration then
860 Check_Non_Static_Default_Expr
861 (Type_Definition (Parent (T)), A);
865 end Validate_Ancestor_Part;
867 ----------------------------------------
868 -- Validate_Categorization_Dependency --
869 ----------------------------------------
871 procedure Validate_Categorization_Dependency
875 K : constant Node_Kind := Nkind (N);
876 P : Node_Id := Parent (N);
878 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
881 -- Only validate library units and subunits. For subunits, checks
882 -- concerning withed units apply to the parent compilation unit.
889 and then not Is_Compilation_Unit (U)
890 and then not Is_Child_Unit (U)
896 if Nkind (P) /= N_Compilation_Unit then
900 -- Body of RCI unit does not need validation
902 if Is_Remote_Call_Interface (E)
903 and then (Nkind (N) = N_Package_Body
904 or else Nkind (N) = N_Subprogram_Body)
909 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
913 Entity_Of_Withed : Entity_Id;
916 Item := First (Context_Items (P));
917 while Present (Item) loop
918 if Nkind (Item) = N_With_Clause
919 and then not (Implicit_With (Item)
920 or else Limited_Present (Item))
922 Entity_Of_Withed := Entity (Name (Item));
923 Check_Categorization_Dependencies
924 (U, Entity_Of_Withed, Item, Is_Subunit);
931 -- Child depends on parent; therefore parent should also be categorized
932 -- and satisfy the dependency hierarchy.
934 -- Check if N is a child spec
936 if (K in N_Generic_Declaration or else
937 K in N_Generic_Instantiation or else
938 K in N_Generic_Renaming_Declaration or else
939 K = N_Package_Declaration or else
940 K = N_Package_Renaming_Declaration or else
941 K = N_Subprogram_Declaration or else
942 K = N_Subprogram_Renaming_Declaration)
943 and then Present (Parent_Spec (N))
945 Check_Categorization_Dependencies (E, Scope (E), N, False);
947 -- Verify that public child of an RCI library unit must also be an
948 -- RCI library unit (RM E.2.3(15)).
950 if Is_Remote_Call_Interface (Scope (E))
951 and then not Private_Present (P)
952 and then not Is_Remote_Call_Interface (E)
954 Error_Msg_N ("public child of rci unit must also be rci unit", N);
957 end Validate_Categorization_Dependency;
959 --------------------------------
960 -- Validate_Controlled_Object --
961 --------------------------------
963 procedure Validate_Controlled_Object (E : Entity_Id) is
965 -- Don't need this check in Ada 2005 mode, where this is all taken
966 -- care of by the mechanism for Preelaborable Initialization.
968 if Ada_Version >= Ada_05 then
972 -- For now, never apply this check for internal GNAT units, since we
973 -- have a number of cases in the library where we are stuck with objects
974 -- of this type, and the RM requires Preelaborate.
976 -- For similar reasons, we only do this check for source entities, since
977 -- we generate entities of this type in some situations.
979 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
980 -- We have to enforce them for RM compatibility, but we have no trouble
981 -- accepting these objects and doing the right thing. Note that there is
982 -- no requirement that Preelaborate not actually generate any code!
984 if In_Preelaborated_Unit
985 and then not Debug_Flag_PP
986 and then Comes_From_Source (E)
988 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
989 and then (not Inside_A_Generic
990 or else Present (Enclosing_Generic_Body (E)))
991 and then not Is_Protected_Type (Etype (E))
994 ("library level controlled object not allowed in " &
995 "preelaborated unit", E);
997 end Validate_Controlled_Object;
999 --------------------------------------
1000 -- Validate_Null_Statement_Sequence --
1001 --------------------------------------
1003 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1007 if In_Preelaborated_Unit then
1008 Item := First (Statements (Handled_Statement_Sequence (N)));
1009 while Present (Item) loop
1010 if Nkind (Item) /= N_Label
1011 and then Nkind (Item) /= N_Null_Statement
1013 -- In GNAT mode, this is a warning, allowing the run-time
1014 -- to judiciously bypass this error condition.
1016 Error_Msg_Warn := GNAT_Mode;
1018 ("<statements not allowed in preelaborated unit", Item);
1026 end Validate_Null_Statement_Sequence;
1028 ---------------------------------
1029 -- Validate_Object_Declaration --
1030 ---------------------------------
1032 procedure Validate_Object_Declaration (N : Node_Id) is
1033 Id : constant Entity_Id := Defining_Identifier (N);
1034 E : constant Node_Id := Expression (N);
1035 Odf : constant Node_Id := Object_Definition (N);
1036 T : constant Entity_Id := Etype (Id);
1039 -- Verify that any access to subprogram object does not have in its
1040 -- subprogram profile access type parameters or limited parameters
1041 -- without Read and Write attributes (E.2.3(13)).
1043 Validate_RCI_Subprogram_Declaration (N);
1045 -- Check that if we are in preelaborated elaboration code, then we
1046 -- do not have an instance of a default initialized private, task or
1047 -- protected object declaration which would violate (RM 10.2.1(9)).
1048 -- Note that constants are never default initialized (and the test
1049 -- below also filters out deferred constants). A variable is default
1050 -- initialized if it does *not* have an initialization expression.
1052 -- Filter out cases that are not declaration of a variable from source
1054 if Nkind (N) /= N_Object_Declaration
1055 or else Constant_Present (N)
1056 or else not Comes_From_Source (Id)
1061 -- Exclude generic specs from the checks (this will get rechecked
1062 -- on instantiations).
1065 and then No (Enclosing_Generic_Body (Id))
1070 -- Required checks for declaration that is in a preelaborated
1071 -- package and is not within some subprogram.
1073 if In_Preelaborated_Unit
1074 and then not In_Subprogram_Or_Concurrent_Unit
1076 -- Check for default initialized variable case. Note that in
1077 -- accordance with (RM B.1(24)) imported objects are not
1078 -- subject to default initialization.
1079 -- If the initialization does not come from source and is an
1080 -- aggregate, it is a static initialization that replaces an
1081 -- implicit call, and must be treated as such.
1085 (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1089 elsif Is_Imported (Id) then
1094 Ent : Entity_Id := T;
1097 -- An array whose component type is a record with nonstatic
1098 -- default expressions is a violation, so we get the array's
1101 if Is_Array_Type (Ent) then
1103 Comp_Type : Entity_Id;
1106 Comp_Type := Component_Type (Ent);
1107 while Is_Array_Type (Comp_Type) loop
1108 Comp_Type := Component_Type (Comp_Type);
1115 -- Object decl. that is of record type and has no default expr.
1116 -- should check if there is any non-static default expression
1117 -- in component decl. of the record type decl.
1119 if Is_Record_Type (Ent) then
1120 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1121 Check_Non_Static_Default_Expr
1122 (Type_Definition (Parent (Ent)), N);
1124 elsif Nkind (Odf) = N_Subtype_Indication
1125 and then not Is_Array_Type (T)
1126 and then not Is_Private_Type (T)
1128 Check_Non_Static_Default_Expr (Type_Definition
1129 (Parent (Entity (Subtype_Mark (Odf)))), N);
1133 -- Check for invalid use of private object. Note that Ada 2005
1134 -- AI-161 modifies the rules for Ada 2005, including the use of
1135 -- the new pragma Preelaborable_Initialization.
1137 if Is_Private_Type (Ent)
1138 or else Depends_On_Private (Ent)
1140 -- Case where type has preelaborable initialization which
1141 -- means that a pragma Preelaborable_Initialization was
1142 -- given for the private type.
1144 if Has_Preelaborable_Initialization (Ent) then
1146 -- But for the predefined units, we will ignore this
1147 -- status unless we are in Ada 2005 mode since we want
1148 -- Ada 95 compatible behavior, in which the entities
1149 -- marked with this pragma in the predefined library are
1150 -- not treated specially.
1152 if Ada_Version < Ada_05 then
1154 ("private object not allowed in preelaborated unit",
1156 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1159 -- Type does not have preelaborable initialization
1162 -- We allow this when compiling in GNAT mode to make life
1163 -- easier for some cases where it would otherwise be hard
1164 -- to be exactly valid Ada.
1166 if not GNAT_Mode then
1168 ("private object not allowed in preelaborated unit",
1171 -- Add a message if it would help to provide a pragma
1172 -- Preelaborable_Initialization on the type of the
1173 -- object (which would make it legal in Ada 2005).
1175 -- If the type has no full view (generic type, or
1176 -- previous error), the warning does not apply.
1178 if Is_Private_Type (Ent)
1179 and then Present (Full_View (Ent))
1181 Has_Preelaborable_Initialization (Full_View (Ent))
1183 Error_Msg_Sloc := Sloc (Ent);
1185 if Ada_Version >= Ada_05 then
1187 ("\would be legal if pragma Preelaborable_" &
1188 "Initialization given for & #", N, Ent);
1191 ("\would be legal in Ada 2005 if pragma " &
1192 "Preelaborable_Initialization given for & #",
1199 -- Access to Task or Protected type
1201 elsif Is_Entity_Name (Odf)
1202 and then Present (Etype (Odf))
1203 and then Is_Access_Type (Etype (Odf))
1205 Ent := Designated_Type (Etype (Odf));
1207 elsif Is_Entity_Name (Odf) then
1208 Ent := Entity (Odf);
1210 elsif Nkind (Odf) = N_Subtype_Indication then
1211 Ent := Etype (Subtype_Mark (Odf));
1214 Nkind (Odf) = N_Constrained_Array_Definition
1216 Ent := Component_Type (T);
1222 if Is_Task_Type (Ent)
1223 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1226 ("concurrent object not allowed in preelaborated unit",
1233 -- Non-static discriminant not allowed in preelaborated unit
1234 -- Controlled object of a type with a user-defined Initialize
1235 -- is forbidden as well.
1237 if Is_Record_Type (Etype (Id)) then
1239 ET : constant Entity_Id := Etype (Id);
1240 EE : constant Entity_Id := Etype (Etype (Id));
1244 if Has_Discriminants (ET)
1245 and then Present (EE)
1249 if Nkind (PEE) = N_Full_Type_Declaration
1250 and then not Static_Discriminant_Expr
1251 (Discriminant_Specifications (PEE))
1254 ("non-static discriminant in preelaborated unit",
1259 if Has_Overriding_Initialize (ET) then
1261 ("controlled type& does not have"
1262 & " preelaborable initialization", N, ET);
1269 -- A pure library_item must not contain the declaration of any variable
1270 -- except within a subprogram, generic subprogram, task unit, or
1271 -- protected unit (RM 10.2.1(16)).
1274 and then not In_Subprogram_Task_Protected_Unit
1276 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1278 -- The visible part of an RCI library unit must not contain the
1279 -- declaration of a variable (RM E.1.3(9))
1281 elsif In_RCI_Declaration (N) then
1282 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1284 -- The visible part of a Shared Passive library unit must not contain
1285 -- the declaration of a variable (RM E.2.2(7))
1287 elsif In_RT_Declaration then
1289 ("variable declaration not allowed in remote types unit", N);
1292 end Validate_Object_Declaration;
1294 ------------------------------
1295 -- Validate_RACW_Primitives --
1296 ------------------------------
1298 procedure Validate_RACW_Primitives (T : Entity_Id) is
1299 Desig_Type : Entity_Id;
1300 Primitive_Subprograms : Elist_Id;
1301 Subprogram_Elmt : Elmt_Id;
1302 Subprogram : Entity_Id;
1303 Param_Spec : Node_Id;
1305 Param_Type : Entity_Id;
1308 procedure Illegal_RACW (Msg : String; N : Node_Id);
1309 -- Diagnose that T is illegal because of the given reason, associated
1310 -- with the location of node N.
1312 Illegal_RACW_Message_Issued : Boolean := False;
1313 -- Set True once Illegal_RACW has been called
1319 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1321 if not Illegal_RACW_Message_Issued then
1323 ("illegal remote access to class-wide type&", T);
1324 Illegal_RACW_Message_Issued := True;
1327 Error_Msg_Sloc := Sloc (N);
1328 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1331 -- Start of processing for Validate_RACW_Primitives
1334 Desig_Type := Etype (Designated_Type (T));
1336 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1338 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1339 while Subprogram_Elmt /= No_Elmt loop
1340 Subprogram := Node (Subprogram_Elmt);
1342 if Is_Predefined_Dispatching_Operation (Subprogram)
1343 or else Is_Hidden (Subprogram)
1345 goto Next_Subprogram;
1348 -- Check return type
1350 if Ekind (Subprogram) = E_Function then
1351 Rtyp := Etype (Subprogram);
1353 if Has_Controlling_Result (Subprogram) then
1356 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1357 Illegal_RACW ("anonymous access result", Rtyp);
1359 elsif Is_Limited_Type (Rtyp) then
1360 if No (TSS (Rtyp, TSS_Stream_Read))
1362 No (TSS (Rtyp, TSS_Stream_Write))
1365 ("limited return type must have Read and Write attributes",
1366 Parent (Subprogram));
1367 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1369 -- Check that the return type supports external streaming.
1370 -- Note that the language of the standard (E.2.2(14)) does not
1371 -- explicitly mention that case, but it really does not make
1372 -- sense to return a value containing a local access type.
1374 elsif Missing_Read_Write_Attributes (Rtyp)
1375 and then not Error_Posted (Rtyp)
1377 Illegal_RACW ("return type containing non-remote access "
1378 & "must have Read and Write attributes",
1379 Parent (Subprogram));
1385 Param := First_Formal (Subprogram);
1386 while Present (Param) loop
1388 -- Now find out if this parameter is a controlling parameter
1390 Param_Spec := Parent (Param);
1391 Param_Type := Etype (Param);
1393 if Is_Controlling_Formal (Param) then
1395 -- It is a controlling parameter, so specific checks below
1400 elsif Ekind (Param_Type) = E_Anonymous_Access_Type
1401 or else Ekind (Param_Type) = E_Anonymous_Access_Subprogram_Type
1403 -- From RM E.2.2(14), no anonymous access parameter other than
1404 -- controlling ones may be used (because an anonymous access
1405 -- type never supports external streaming).
1407 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1409 elsif Is_Limited_Type (Param_Type) then
1411 -- Not a controlling parameter, so type must have Read and
1412 -- Write attributes.
1414 if No (TSS (Param_Type, TSS_Stream_Read))
1416 No (TSS (Param_Type, TSS_Stream_Write))
1419 ("limited formal must have Read and Write attributes",
1421 Explain_Limited_Type (Param_Type, Param_Spec);
1424 elsif Missing_Read_Write_Attributes (Param_Type)
1425 and then not Error_Posted (Param_Type)
1427 Illegal_RACW ("parameter containing non-remote access "
1428 & "must have Read and Write attributes", Param_Spec);
1431 -- Check next parameter in this subprogram
1433 Next_Formal (Param);
1437 Next_Elmt (Subprogram_Elmt);
1439 end Validate_RACW_Primitives;
1441 -------------------------------
1442 -- Validate_RCI_Declarations --
1443 -------------------------------
1445 procedure Validate_RCI_Declarations (P : Entity_Id) is
1449 E := First_Entity (P);
1450 while Present (E) loop
1451 if Comes_From_Source (E) then
1452 if Is_Limited_Type (E) then
1454 ("limited type not allowed in rci unit", Parent (E));
1455 Explain_Limited_Type (E, Parent (E));
1457 elsif Ekind (E) = E_Generic_Function
1458 or else Ekind (E) = E_Generic_Package
1459 or else Ekind (E) = E_Generic_Procedure
1461 Error_Msg_N ("generic declaration not allowed in rci unit",
1464 elsif (Ekind (E) = E_Function
1465 or else Ekind (E) = E_Procedure)
1466 and then Has_Pragma_Inline (E)
1469 ("inlined subprogram not allowed in rci unit", Parent (E));
1471 -- Inner packages that are renamings need not be checked. Generic
1472 -- RCI packages are subject to the checks, but entities that come
1473 -- from formal packages are not part of the visible declarations
1474 -- of the package and are not checked.
1476 elsif Ekind (E) = E_Package then
1477 if Present (Renamed_Entity (E)) then
1480 elsif Ekind (P) /= E_Generic_Package
1481 or else List_Containing (Unit_Declaration_Node (E)) /=
1482 Generic_Formal_Declarations
1483 (Unit_Declaration_Node (P))
1485 Validate_RCI_Declarations (E);
1492 end Validate_RCI_Declarations;
1494 -----------------------------------------
1495 -- Validate_RCI_Subprogram_Declaration --
1496 -----------------------------------------
1498 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1499 K : constant Node_Kind := Nkind (N);
1502 Param_Spec : Node_Id;
1503 Param_Type : Entity_Id;
1504 Base_Param_Type : Entity_Id;
1505 Base_Under_Type : Entity_Id;
1506 Type_Decl : Node_Id;
1507 Error_Node : Node_Id := N;
1510 -- This procedure enforces rules on subprogram and access to subprogram
1511 -- declarations in RCI units. These rules do not apply to expander
1512 -- generated routines, which are not remote subprograms. It is called:
1514 -- 1. from Analyze_Subprogram_Declaration.
1515 -- 2. from Validate_Object_Declaration (access to subprogram).
1517 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1521 if K = N_Subprogram_Declaration then
1522 Profile := Parameter_Specifications (Specification (N));
1524 else pragma Assert (K = N_Object_Declaration);
1526 -- The above assertion is dubious, the visible declarations of an
1527 -- RCI unit never contain an object declaration, this should be an
1528 -- ACCESS-to-object declaration???
1530 Id := Defining_Identifier (N);
1532 if Nkind (Id) = N_Defining_Identifier
1533 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1534 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1537 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1543 -- Iterate through the parameter specification list, checking that
1544 -- no access parameter and no limited type parameter in the list.
1547 if Present (Profile) then
1548 Param_Spec := First (Profile);
1549 while Present (Param_Spec) loop
1550 Param_Type := Etype (Defining_Identifier (Param_Spec));
1551 Type_Decl := Parent (Param_Type);
1553 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1555 if K = N_Subprogram_Declaration then
1556 Error_Node := Param_Spec;
1559 -- Report error only if declaration is in source program
1561 if Comes_From_Source
1562 (Defining_Entity (Specification (N)))
1565 ("subprogram in 'R'C'I unit cannot have access parameter",
1569 -- For a limited private type parameter, we check only the private
1570 -- declaration and ignore full type declaration, unless this is
1571 -- the only declaration for the type, e.g., as a limited record.
1573 elsif Is_Limited_Type (Param_Type)
1574 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1576 (Nkind (Type_Decl) = N_Full_Type_Declaration
1577 and then not (Has_Private_Declaration (Param_Type))
1578 and then Comes_From_Source (N)))
1580 -- A limited parameter is legal only if user-specified Read and
1581 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1583 if No (Full_View (Param_Type))
1584 and then Ekind (Param_Type) /= E_Record_Type
1586 -- Type does not have completion yet, so if declared in
1587 -- the current RCI scope it is illegal, and will be flagged
1593 -- In Ada 95 the rules permit using a limited type that has
1594 -- user-specified Read and Write attributes that are specified
1595 -- in the private part of the package, whereas Ada 2005
1596 -- (AI-240) revises this to require the attributes to be
1597 -- "available" (implying that the attribute clauses must be
1598 -- visible to the RCI client). The Ada 95 rules violate the
1599 -- contract model for privacy, but we support both semantics
1600 -- for now for compatibility (note that ACATS test BXE2009
1601 -- checks a case that conforms to the Ada 95 rules but is
1602 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1603 -- possibilities of visible TSS stream subprograms or explicit
1604 -- stream attribute definitions because the TSS subprograms
1605 -- can be hidden in the private part while the attribute
1606 -- definitions are still be available from the visible part.
1608 Base_Param_Type := Base_Type (Param_Type);
1609 Base_Under_Type := Base_Type (Underlying_Type
1612 if (Ada_Version < Ada_05
1614 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1616 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1618 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1620 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1622 (Ada_Version >= Ada_05
1624 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1626 No (TSS (Base_Param_Type, TSS_Stream_Write))
1628 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1630 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1632 (not Has_Stream_Attribute_Definition
1633 (Base_Param_Type, TSS_Stream_Read)
1635 not Has_Stream_Attribute_Definition
1636 (Base_Param_Type, TSS_Stream_Write)))
1638 if K = N_Subprogram_Declaration then
1639 Error_Node := Param_Spec;
1642 if Ada_Version >= Ada_05 then
1644 ("limited parameter in 'R'C'I unit "
1645 & "must have visible read/write attributes ",
1649 ("limited parameter in 'R'C'I unit "
1650 & "must have read/write attributes ",
1653 Explain_Limited_Type (Param_Type, Error_Node);
1656 -- In Ada 95, any non-remote access type (or any type with a
1657 -- component of a non-remote access type) that is visible in an
1658 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1659 -- unit, and thus is already guaranteed to support external
1660 -- streaming. However in Ada 2005 we have to account for the case
1661 -- of named access types from declared pure units as well, which
1662 -- may or may not support external streaming, and so we need to
1663 -- perform a specific check for E.2.3(14/2) here.
1665 -- Note that if the declaration of the type itself is illegal, we
1666 -- do not perform this check since it might be a cascaded error.
1669 if K = N_Subprogram_Declaration then
1670 Error_Node := Param_Spec;
1673 if Missing_Read_Write_Attributes (Param_Type)
1674 and then not Error_Posted (Param_Type)
1677 ("parameter containing non-remote access in 'R'C'I "
1678 & "subprogram must have visible "
1679 & "Read and Write attributes", Error_Node);
1685 -- No check on return type???
1687 end Validate_RCI_Subprogram_Declaration;
1689 ----------------------------------------------------
1690 -- Validate_Remote_Access_Object_Type_Declaration --
1691 ----------------------------------------------------
1693 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1695 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1696 -- True if tagged type E is a valid candidate as the root type of the
1697 -- designated type for a RACW, i.e. a tagged limited private type, or a
1698 -- limited interface type, or a private extension of such a type.
1700 ---------------------------------
1701 -- Is_Valid_Remote_Object_Type --
1702 ---------------------------------
1704 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1705 P : constant Node_Id := Parent (E);
1708 pragma Assert (Is_Tagged_Type (E));
1710 -- Simple case: a limited private type
1712 if Nkind (P) = N_Private_Type_Declaration
1713 and then Is_Limited_Record (E)
1717 -- A limited interface is not currently a legal ancestor for the
1718 -- designated type of an RACW type, because a type that implements
1719 -- such an interface need not be limited. However, the ARG seems to
1720 -- incline towards allowing an access to classwide limited interface
1721 -- type as a remote access type, as resolved in AI05-060. But note
1722 -- that the expansion circuitry for RACWs that designate classwide
1723 -- interfaces is not complete yet.
1725 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1728 -- A generic tagged limited type is a valid candidate. Limitedness
1729 -- will be checked again on the actual at instantiation point.
1731 elsif Nkind (P) = N_Formal_Type_Declaration
1732 and then Ekind (E) = E_Record_Type_With_Private
1733 and then Is_Generic_Type (E)
1734 and then Is_Limited_Record (E)
1738 -- A private extension declaration is a valid candidate if its parent
1741 elsif Nkind (P) = N_Private_Extension_Declaration then
1742 return Is_Valid_Remote_Object_Type (Etype (E));
1747 end Is_Valid_Remote_Object_Type;
1751 Direct_Designated_Type : Entity_Id;
1752 Desig_Type : Entity_Id;
1754 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1757 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1758 -- given node is N_Access_To_Object_Definition.
1760 if not Comes_From_Source (T)
1761 or else (not In_RCI_Declaration (Parent (T))
1762 and then not In_RT_Declaration)
1767 -- An access definition in the private part of a Remote Types package
1768 -- may be legal if it has user-defined Read and Write attributes. This
1769 -- will be checked at the end of the package spec processing.
1771 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1775 -- Check RCI or RT unit type declaration. It may not contain the
1776 -- declaration of an access-to-object type unless it is a general access
1777 -- type that designates a class-wide limited private type or subtype.
1778 -- There are also constraints on the primitive subprograms of the
1779 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1781 if Ekind (T) /= E_General_Access_Type
1782 or else not Is_Class_Wide_Type (Designated_Type (T))
1784 if In_RCI_Declaration (Parent (T)) then
1786 ("error in access type in Remote_Call_Interface unit", T);
1789 ("error in access type in Remote_Types unit", T);
1792 Error_Msg_N ("\must be general access to class-wide type", T);
1796 Direct_Designated_Type := Designated_Type (T);
1797 Desig_Type := Etype (Direct_Designated_Type);
1799 -- Why is the check below not in
1800 -- Validate_Remote_Access_To_Class_Wide_Type???
1802 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1804 ("error in designated type of remote access to class-wide type", T);
1806 ("\must be tagged limited private or private extension", T);
1809 end Validate_Remote_Access_Object_Type_Declaration;
1811 -----------------------------------------------
1812 -- Validate_Remote_Access_To_Class_Wide_Type --
1813 -----------------------------------------------
1815 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1816 K : constant Node_Kind := Nkind (N);
1817 PK : constant Node_Kind := Nkind (Parent (N));
1821 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1822 -- of class-wide limited private types.
1824 -- Storage_Pool and Storage_Size are not defined for such types
1826 -- The expected type of allocator must not be such a type.
1828 -- The actual parameter of generic instantiation must not be such a
1829 -- type if the formal parameter is of an access type.
1831 -- On entry, there are five cases
1833 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1834 -- either Storage_Pool or Storage_Size.
1836 -- 2. called from exp_ch4 Expand_N_Allocator
1838 -- 3. called from sem_ch12 Analyze_Associations
1840 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1842 -- 5. called from sem_res Resolve_Actuals
1844 if K = N_Attribute_Reference then
1845 E := Etype (Prefix (N));
1847 if Is_Remote_Access_To_Class_Wide_Type (E) then
1848 Error_Msg_N ("incorrect attribute of remote operand", N);
1852 elsif K = N_Allocator then
1855 if Is_Remote_Access_To_Class_Wide_Type (E) then
1856 Error_Msg_N ("incorrect expected remote type of allocator", N);
1860 elsif K in N_Has_Entity then
1863 if Is_Remote_Access_To_Class_Wide_Type (E) then
1864 Error_Msg_N ("incorrect remote type generic actual", N);
1868 -- This subprogram also enforces the checks in E.2.2(13). A value of
1869 -- such type must not be dereferenced unless as controlling operand of
1870 -- a dispatching call. Explicit dereferences not coming from source are
1871 -- exempted from this checking because the expander produces them in
1872 -- some cases (such as for tag checks on dispatching calls with multiple
1873 -- controlling operands). However we do check in the case of an implicit
1874 -- dereference that is expanded to an explicit dereference (hence the
1875 -- test of whether Original_Node (N) comes from source).
1877 elsif K = N_Explicit_Dereference
1878 and then Comes_From_Source (Original_Node (N))
1880 E := Etype (Prefix (N));
1882 -- If the class-wide type is not a remote one, the restrictions
1885 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1889 -- If we have a true dereference that comes from source and that
1890 -- is a controlling argument for a dispatching call, accept it.
1892 if Is_Actual_Parameter (N)
1893 and then Is_Controlling_Actual (N)
1898 -- If we are just within a procedure or function call and the
1899 -- dereference has not been analyzed, return because this procedure
1900 -- will be called again from sem_res Resolve_Actuals. The same can
1901 -- apply in the case of dereference that is the prefix of a selected
1902 -- component, which can be a call given in prefixed form.
1904 if (Is_Actual_Parameter (N)
1905 or else PK = N_Selected_Component)
1906 and then not Analyzed (N)
1911 -- We must allow expanded code to generate a reference to the tag of
1912 -- the designated object (may be either the actual tag, or the stub
1913 -- tag in the case of a remote object).
1915 if PK = N_Selected_Component
1916 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1922 ("invalid dereference of a remote access-to-class-wide value", N);
1924 end Validate_Remote_Access_To_Class_Wide_Type;
1926 ------------------------------------------
1927 -- Validate_Remote_Type_Type_Conversion --
1928 ------------------------------------------
1930 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1931 S : constant Entity_Id := Etype (N);
1932 E : constant Entity_Id := Etype (Expression (N));
1935 -- This test is required in the case where a conversion appears inside a
1936 -- normal package, it does not necessarily have to be inside an RCI,
1937 -- Remote_Types unit (RM E.2.2(9,12)).
1939 if Is_Remote_Access_To_Subprogram_Type (E)
1940 and then not Is_Remote_Access_To_Subprogram_Type (S)
1943 ("incorrect conversion of remote operand to local type", N);
1946 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1947 and then Is_Remote_Access_To_Subprogram_Type (S)
1950 ("incorrect conversion of local operand to remote type", N);
1953 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1954 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1957 ("incorrect conversion of remote operand to local type", N);
1961 -- If a local access type is converted into a RACW type, then the
1962 -- current unit has a pointer that may now be exported to another
1965 if Is_Remote_Access_To_Class_Wide_Type (S)
1966 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1968 Set_Has_RACW (Current_Sem_Unit);
1970 end Validate_Remote_Type_Type_Conversion;
1972 -------------------------------
1973 -- Validate_RT_RAT_Component --
1974 -------------------------------
1976 procedure Validate_RT_RAT_Component (N : Node_Id) is
1977 Spec : constant Node_Id := Specification (N);
1978 Name_U : constant Entity_Id := Defining_Entity (Spec);
1981 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1984 if not Is_Remote_Types (Name_U) then
1988 Typ := First_Entity (Name_U);
1989 while Present (Typ) and then Typ /= First_Priv_Ent loop
1990 U_Typ := Underlying_Type (Typ);
1996 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1997 if Missing_Read_Write_Attributes (Typ) then
1998 if Is_Non_Remote_Access_Type (Typ) then
1999 Error_Msg_N ("error in non-remote access type", U_Typ);
2002 ("error in record type containing a component of a " &
2003 "non-remote access type", U_Typ);
2006 if Ada_Version >= Ada_05 then
2008 ("\must have visible Read and Write attribute " &
2009 "definition clauses (RM E.2.2(8))", U_Typ);
2012 ("\must have Read and Write attribute " &
2013 "definition clauses (RM E.2.2(8))", U_Typ);
2020 end Validate_RT_RAT_Component;
2022 -----------------------------------------
2023 -- Validate_SP_Access_Object_Type_Decl --
2024 -----------------------------------------
2026 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2027 Direct_Designated_Type : Entity_Id;
2029 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2030 -- Return true if the protected type designated by T has
2031 -- entry declarations.
2033 ----------------------------
2034 -- Has_Entry_Declarations --
2035 ----------------------------
2037 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2041 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2042 Ety := First_Entity (E);
2043 while Present (Ety) loop
2044 if Ekind (Ety) = E_Entry then
2053 end Has_Entry_Declarations;
2055 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2058 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
2059 -- Nkind of the given entity is N_Access_To_Object_Definition.
2061 if not Comes_From_Source (T)
2062 or else not In_Shared_Passive_Unit
2063 or else In_Subprogram_Task_Protected_Unit
2068 -- Check Shared Passive unit. It should not contain the declaration
2069 -- of an access-to-object type whose designated type is a class-wide
2070 -- type, task type or protected type with entry (RM E.2.1(7)).
2072 Direct_Designated_Type := Designated_Type (T);
2074 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2076 ("invalid access-to-class-wide type in shared passive unit", T);
2079 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2081 ("invalid access-to-task type in shared passive unit", T);
2084 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2085 and then Has_Entry_Declarations (Direct_Designated_Type)
2088 ("invalid access-to-protected type in shared passive unit", T);
2091 end Validate_SP_Access_Object_Type_Decl;
2093 ---------------------------------
2094 -- Validate_Static_Object_Name --
2095 ---------------------------------
2097 procedure Validate_Static_Object_Name (N : Node_Id) is
2100 function Is_Primary (N : Node_Id) return Boolean;
2101 -- Determine whether node is syntactically a primary in an expression
2102 -- This function should probably be somewhere else ???
2103 -- Also it does not do what it says, e.g if N is a binary operator
2104 -- whose parent is a binary operator, Is_Primary returns True ???
2110 function Is_Primary (N : Node_Id) return Boolean is
2111 K : constant Node_Kind := Nkind (Parent (N));
2115 when N_Op | N_Membership_Test =>
2119 | N_Component_Association
2120 | N_Index_Or_Discriminant_Constraint =>
2123 when N_Attribute_Reference =>
2124 return Attribute_Name (Parent (N)) /= Name_Address
2125 and then Attribute_Name (Parent (N)) /= Name_Access
2126 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2128 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2130 when N_Indexed_Component =>
2131 return (N /= Prefix (Parent (N))
2132 or else Is_Primary (Parent (N)));
2134 when N_Qualified_Expression | N_Type_Conversion =>
2135 return Is_Primary (Parent (N));
2137 when N_Assignment_Statement | N_Object_Declaration =>
2138 return (N = Expression (Parent (N)));
2140 when N_Selected_Component =>
2141 return Is_Primary (Parent (N));
2148 -- Start of processing for Validate_Static_Object_Name
2151 if not In_Preelaborated_Unit
2152 or else not Comes_From_Source (N)
2153 or else In_Subprogram_Or_Concurrent_Unit
2154 or else Ekind (Current_Scope) = E_Block
2158 -- Filter out cases where primary is default in a component declaration,
2159 -- discriminant specification, or actual in a record type initialization
2162 -- Initialization call of internal types
2164 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2166 if Present (Parent (Parent (N)))
2167 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2172 if Nkind (Name (Parent (N))) = N_Identifier
2173 and then not Comes_From_Source (Entity (Name (Parent (N))))
2179 -- Error if the name is a primary in an expression. The parent must not
2180 -- be an operator, or a selected component or an indexed component that
2181 -- is itself a primary. Entities that are actuals do not need to be
2182 -- checked, because the call itself will be diagnosed.
2185 and then (not Inside_A_Generic
2186 or else Present (Enclosing_Generic_Body (N)))
2188 if Ekind (Entity (N)) = E_Variable
2189 or else Ekind (Entity (N)) in Formal_Object_Kind
2191 Flag_Non_Static_Expr
2192 ("non-static object name in preelaborated unit", N);
2194 -- Give an error for a reference to a nonstatic constant, unless the
2195 -- constant is in another GNAT library unit that is preelaborable.
2197 elsif Ekind (Entity (N)) = E_Constant
2198 and then not Is_Static_Expression (N)
2202 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2204 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2205 and then (Is_Preelaborated (Scope (E))
2206 or else Is_Pure (Scope (E))
2207 or else (Present (Renamed_Object (E))
2209 Is_Entity_Name (Renamed_Object (E))
2212 (Scope (Renamed_Object (E)))
2215 (Renamed_Object (E))))))
2219 -- This is the error case
2222 -- In GNAT mode, this is just a warning, to allow it to be
2223 -- judiciously turned off. Otherwise it is a real error.
2227 ("?non-static constant in preelaborated unit", N);
2229 Flag_Non_Static_Expr
2230 ("non-static constant in preelaborated unit", N);
2235 end Validate_Static_Object_Name;