1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 the declaration of a Remote Types
86 -- unit, 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)
210 -- Special case: Remote_Types can depend on Preelaborated per
213 elsif Unit_Category = Remote_Types
214 and then Is_Preelaborated (Depended_Entity)
218 -- All other cases, we do have an error
225 -- Here if we have an error
229 -- These messages are warnings in GNAT mode, to allow it to be
230 -- judiciously turned off. Otherwise it is a real error.
232 Error_Msg_Warn := GNAT_Mode;
234 -- Don't give error if main unit is not an internal unit, and the
235 -- unit generating the message is an internal unit. This is the
236 -- situation in which such messages would be ignored in any case,
237 -- so it is convenient not to generate them (since it causes
238 -- annoying interference with debugging).
240 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
241 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
247 elsif Is_Subunit then
249 ("<subunit cannot depend on& " &
250 "(parent has wrong categorization)", N, Depended_Entity);
252 -- Normal unit, not subunit
256 ("<cannot depend on& " &
257 "(wrong categorization)", N, Depended_Entity);
260 -- Add further explanation for Pure/Preelaborate common cases
262 if Unit_Category = Pure then
264 ("\<pure unit cannot depend on non-pure unit",
267 elsif Is_Preelaborated (Unit_Entity)
268 and then not Is_Preelaborated (Depended_Entity)
269 and then not Is_Pure (Depended_Entity)
272 ("\<preelaborated unit cannot depend on "
273 & "non-preelaborated unit",
277 end Check_Categorization_Dependencies;
279 -----------------------------------
280 -- Check_Non_Static_Default_Expr --
281 -----------------------------------
283 procedure Check_Non_Static_Default_Expr
288 Component_Decl : Node_Id;
291 if Nkind (Type_Def) = N_Derived_Type_Definition then
292 Recdef := Record_Extension_Part (Type_Def);
302 -- Check that component declarations do not involve:
304 -- a. a non-static default expression, where the object is
305 -- declared to be default initialized.
307 -- b. a dynamic Itype (discriminants and constraints)
309 if Null_Present (Recdef) then
312 Component_Decl := First (Component_Items (Component_List (Recdef)));
315 while Present (Component_Decl)
316 and then Nkind (Component_Decl) = N_Component_Declaration
318 if Present (Expression (Component_Decl))
319 and then Nkind (Expression (Component_Decl)) /= N_Null
320 and then not Is_Static_Expression (Expression (Component_Decl))
322 Error_Msg_Sloc := Sloc (Component_Decl);
324 ("object in preelaborated unit has non-static default#",
327 -- Fix this later ???
329 -- elsif Has_Dynamic_Itype (Component_Decl) then
331 -- ("dynamic type discriminant," &
332 -- " constraint in preelaborated unit",
336 Next (Component_Decl);
338 end Check_Non_Static_Default_Expr;
340 -------------------------------------
341 -- Has_Stream_Attribute_Definition --
342 -------------------------------------
344 function Has_Stream_Attribute_Definition
347 At_Any_Place : Boolean := False) return Boolean
350 Full_Type : Entity_Id := Typ;
353 -- In the case of a type derived from a private view, any specified
354 -- stream attributes will be attached to the derived type's underlying
355 -- type rather the derived type entity itself (which is itself private).
357 if Is_Private_Type (Typ)
358 and then Is_Derived_Type (Typ)
359 and then Present (Full_View (Typ))
361 Full_Type := Underlying_Type (Typ);
364 -- We start from the declaration node and then loop until the end of
365 -- the list until we find the requested attribute definition clause.
366 -- In Ada 2005 mode, clauses are ignored if they are not currently
367 -- visible (this is tested using the corresponding Entity, which is
368 -- inserted by the expander at the point where the clause occurs),
369 -- unless At_Any_Place is true.
371 Rep_Item := First_Rep_Item (Full_Type);
372 while Present (Rep_Item) loop
373 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
374 case Chars (Rep_Item) is
376 exit when Nam = TSS_Stream_Read;
379 exit when Nam = TSS_Stream_Write;
382 exit when Nam = TSS_Stream_Input;
385 exit when Nam = TSS_Stream_Output;
393 Next_Rep_Item (Rep_Item);
396 -- If At_Any_Place is true, return True if the attribute is available
397 -- at any place; if it is false, return True only if the attribute is
398 -- currently visible.
400 return Present (Rep_Item)
401 and then (Ada_Version < Ada_2005
403 or else not Is_Hidden (Entity (Rep_Item)));
404 end Has_Stream_Attribute_Definition;
406 ---------------------------
407 -- In_Preelaborated_Unit --
408 ---------------------------
410 function In_Preelaborated_Unit return Boolean is
411 Unit_Entity : constant Entity_Id := Current_Scope;
412 Unit_Kind : constant Node_Kind :=
413 Nkind (Unit (Cunit (Current_Sem_Unit)));
416 -- There are no constraints on body of remote_call_interface or
417 -- remote_types packages.
419 return (Unit_Entity /= Standard_Standard)
420 and then (Is_Preelaborated (Unit_Entity)
421 or else Is_Pure (Unit_Entity)
422 or else Is_Shared_Passive (Unit_Entity)
424 ((Is_Remote_Types (Unit_Entity)
425 or else Is_Remote_Call_Interface (Unit_Entity))
426 and then Ekind (Unit_Entity) = E_Package
427 and then Unit_Kind /= N_Package_Body
428 and then not In_Package_Body (Unit_Entity)
429 and then not In_Instance));
430 end In_Preelaborated_Unit;
436 function In_Pure_Unit return Boolean is
438 return Is_Pure (Current_Scope);
441 ------------------------
442 -- In_RCI_Declaration --
443 ------------------------
445 function In_RCI_Declaration (N : Node_Id) return Boolean is
446 Unit_Entity : constant Entity_Id := Current_Scope;
447 Unit_Kind : constant Node_Kind :=
448 Nkind (Unit (Cunit (Current_Sem_Unit)));
451 -- There are no restrictions on the private part or body
454 return Is_Remote_Call_Interface (Unit_Entity)
455 and then Is_Package_Or_Generic_Package (Unit_Entity)
456 and then Unit_Kind /= N_Package_Body
457 and then List_Containing (N) =
459 (Specification (Unit_Declaration_Node (Unit_Entity)))
460 and then not In_Package_Body (Unit_Entity)
461 and then not In_Instance;
463 -- What about the case of a nested package in the visible part???
464 -- This case is missed by the List_Containing check above???
465 end In_RCI_Declaration;
467 -----------------------
468 -- In_RT_Declaration --
469 -----------------------
471 function In_RT_Declaration return Boolean is
472 Unit_Entity : constant Entity_Id := Current_Scope;
473 Unit_Kind : constant Node_Kind :=
474 Nkind (Unit (Cunit (Current_Sem_Unit)));
477 -- There are no restrictions on the body of a Remote Types unit
479 return Is_Remote_Types (Unit_Entity)
480 and then Is_Package_Or_Generic_Package (Unit_Entity)
481 and then Unit_Kind /= N_Package_Body
482 and then not In_Package_Body (Unit_Entity)
483 and then not In_Instance;
484 end In_RT_Declaration;
486 ----------------------------
487 -- In_Shared_Passive_Unit --
488 ----------------------------
490 function In_Shared_Passive_Unit return Boolean is
491 Unit_Entity : constant Entity_Id := Current_Scope;
494 return Is_Shared_Passive (Unit_Entity);
495 end In_Shared_Passive_Unit;
497 ---------------------------------------
498 -- In_Subprogram_Task_Protected_Unit --
499 ---------------------------------------
501 function In_Subprogram_Task_Protected_Unit return Boolean is
505 -- The following is to verify that a declaration is inside
506 -- subprogram, generic subprogram, task unit, protected unit.
507 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
509 -- Use scope chain to check successively outer scopes
515 Is_Generic_Subprogram (E)
517 Is_Concurrent_Type (E)
521 elsif E = Standard_Standard then
527 end In_Subprogram_Task_Protected_Unit;
529 -------------------------------
530 -- Is_Non_Remote_Access_Type --
531 -------------------------------
533 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
534 U_E : constant Entity_Id := Underlying_Type (E);
538 -- This case arises for the case of a generic formal type, in which
539 -- case E.2.2(8) rules will be enforced at instantiation time.
544 return Is_Access_Type (U_E)
545 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
546 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
547 end Is_Non_Remote_Access_Type;
549 ----------------------------------
550 -- Missing_Read_Write_Attribute --
551 ----------------------------------
553 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
554 Component : Entity_Id;
555 Component_Type : Entity_Id;
556 U_E : constant Entity_Id := Underlying_Type (E);
558 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
559 -- Return True if entity has attribute definition clauses for Read and
560 -- Write attributes that are visible at some place.
562 -------------------------------
563 -- Has_Read_Write_Attributes --
564 -------------------------------
566 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
569 and then Has_Stream_Attribute_Definition (E,
570 TSS_Stream_Read, At_Any_Place => True)
571 and then Has_Stream_Attribute_Definition (E,
572 TSS_Stream_Write, At_Any_Place => True);
573 end Has_Read_Write_Attributes;
575 -- Start of processing for Missing_Read_Write_Attributes
581 elsif Has_Read_Write_Attributes (E)
582 or else Has_Read_Write_Attributes (U_E)
586 elsif Is_Non_Remote_Access_Type (U_E) then
590 if Is_Record_Type (U_E) then
591 Component := First_Entity (U_E);
592 while Present (Component) loop
593 if not Is_Tag (Component) then
594 Component_Type := Etype (Component);
596 if Missing_Read_Write_Attributes (Component_Type) then
601 Next_Entity (Component);
606 end Missing_Read_Write_Attributes;
608 -------------------------------------
609 -- Set_Categorization_From_Pragmas --
610 -------------------------------------
612 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
613 P : constant Node_Id := Parent (N);
614 S : constant Entity_Id := Current_Scope;
616 procedure Set_Parents (Visibility : Boolean);
617 -- If this is a child instance, the parents are not immediately
618 -- visible during analysis. Make them momentarily visible so that
619 -- the argument of the pragma can be resolved properly, and reset
626 procedure Set_Parents (Visibility : Boolean) is
630 while Present (Par) and then Par /= Standard_Standard loop
631 Set_Is_Immediately_Visible (Par, Visibility);
636 -- Start of processing for Set_Categorization_From_Pragmas
639 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
640 -- The purpose is to set categorization flags before analyzing the
641 -- unit itself, so as to diagnose violations of categorization as
642 -- we process each declaration, even though the pragma appears after
645 if Nkind (P) /= N_Compilation_Unit then
654 and then Is_Generic_Instance (S)
659 PN := First (Pragmas_After (Aux_Decls_Node (P)));
660 while Present (PN) loop
662 -- Skip implicit types that may have been introduced by
663 -- previous analysis.
665 if Nkind (PN) = N_Pragma then
666 case Get_Pragma_Id (PN) is
667 when Pragma_All_Calls_Remote |
668 Pragma_Preelaborate |
670 Pragma_Remote_Call_Interface |
671 Pragma_Remote_Types |
672 Pragma_Shared_Passive => Analyze (PN);
681 and then Is_Generic_Instance (S)
686 end Set_Categorization_From_Pragmas;
688 -----------------------------------
689 -- Set_Categorization_From_Scope --
690 -----------------------------------
692 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
693 Declaration : Node_Id := Empty;
694 Specification : Node_Id := Empty;
698 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
700 if not Is_Remote_Call_Interface (E) then
701 if Ekind (E) in Subprogram_Kind then
702 Declaration := Unit_Declaration_Node (E);
704 if Nkind (Declaration) = N_Subprogram_Body
706 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
708 Specification := Corresponding_Spec (Declaration);
712 -- A subprogram body or renaming-as-body is a remote call
713 -- interface if it serves as the completion of a subprogram
714 -- declaration that is a remote call interface.
716 if Nkind (Specification) in N_Entity then
717 Set_Is_Remote_Call_Interface
718 (E, Is_Remote_Call_Interface (Specification));
720 -- A subprogram declaration is a remote call interface when it is
721 -- declared within the visible part of, or declared by, a library
722 -- unit declaration that is a remote call interface.
725 Set_Is_Remote_Call_Interface
726 (E, Is_Remote_Call_Interface (Scop)
727 and then not (In_Private_Part (Scop)
728 or else In_Package_Body (Scop)));
733 (E, Is_Remote_Types (Scop)
734 and then not (In_Private_Part (Scop)
735 or else In_Package_Body (Scop)));
736 end Set_Categorization_From_Scope;
738 ------------------------------
739 -- Static_Discriminant_Expr --
740 ------------------------------
742 -- We need to accommodate a Why_Not_Static call somehow here ???
744 function Static_Discriminant_Expr (L : List_Id) return Boolean is
745 Discriminant_Spec : Node_Id;
748 Discriminant_Spec := First (L);
749 while Present (Discriminant_Spec) loop
750 if Present (Expression (Discriminant_Spec))
751 and then not Is_Static_Expression (Expression (Discriminant_Spec))
756 Next (Discriminant_Spec);
760 end Static_Discriminant_Expr;
762 --------------------------------------
763 -- Validate_Access_Type_Declaration --
764 --------------------------------------
766 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
767 Def : constant Node_Id := Type_Definition (N);
772 -- Access to subprogram case
774 when N_Access_To_Subprogram_Definition =>
776 -- A pure library_item must not contain the declaration of a
777 -- named access type, except within a subprogram, generic
778 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
780 -- This test is skipped in Ada 2005 (see AI-366)
782 if Ada_Version < Ada_2005
783 and then Comes_From_Source (T)
784 and then In_Pure_Unit
785 and then not In_Subprogram_Task_Protected_Unit
787 Error_Msg_N ("named access type not allowed in pure unit", T);
790 -- Access to object case
792 when N_Access_To_Object_Definition =>
793 if Comes_From_Source (T)
794 and then In_Pure_Unit
795 and then not In_Subprogram_Task_Protected_Unit
797 -- We can't give the message yet, since the type is not frozen
798 -- and in Ada 2005 mode, access types are allowed in pure units
799 -- if the type has no storage pool (see AI-366). So we set a
800 -- flag which will be checked at freeze time.
802 Set_Is_Pure_Unit_Access_Type (T);
805 -- Check for RCI or RT unit type declaration: declaration of an
806 -- access-to-object type is illegal unless it is a general access
807 -- type that designates a class-wide limited private type.
808 -- Note that constraints on the primitive subprograms of the
809 -- designated tagged type are not enforced here but in
810 -- Validate_RACW_Primitives, which is done separately because the
811 -- designated type might not be frozen (and therefore its
812 -- primitive operations might not be completely known) at the
813 -- point of the RACW declaration.
815 Validate_Remote_Access_Object_Type_Declaration (T);
817 -- Check for shared passive unit type declaration. It should
818 -- not contain the declaration of access to class wide type,
819 -- access to task type and access to protected type with entry.
821 Validate_SP_Access_Object_Type_Decl (T);
827 -- Set categorization flag from package on entity as well, to allow
828 -- easy checks later on for required validations of RCI or RT units.
829 -- This is only done for entities that are in the original source.
831 if Comes_From_Source (T)
832 and then not (In_Package_Body (Scope (T))
833 or else In_Private_Part (Scope (T)))
835 Set_Is_Remote_Call_Interface
836 (T, Is_Remote_Call_Interface (Scope (T)));
838 (T, Is_Remote_Types (Scope (T)));
840 end Validate_Access_Type_Declaration;
842 ----------------------------
843 -- Validate_Ancestor_Part --
844 ----------------------------
846 procedure Validate_Ancestor_Part (N : Node_Id) is
847 A : constant Node_Id := Ancestor_Part (N);
848 T : constant Entity_Id := Entity (A);
851 if In_Preelaborated_Unit
852 and then not In_Subprogram_Or_Concurrent_Unit
853 and then (not Inside_A_Generic
854 or else Present (Enclosing_Generic_Body (N)))
856 -- If the type is private, it must have the Ada 2005 pragma
857 -- Has_Preelaborable_Initialization.
858 -- The check is omitted within predefined units. This is probably
859 -- obsolete code to fix the Ada95 weakness in this area ???
861 if Is_Private_Type (T)
862 and then not Has_Pragma_Preelab_Init (T)
863 and then not Is_Internal_File_Name
864 (Unit_File_Name (Get_Source_Unit (N)))
867 ("private ancestor type not allowed in preelaborated unit", A);
869 elsif Is_Record_Type (T) then
870 if Nkind (Parent (T)) = N_Full_Type_Declaration then
871 Check_Non_Static_Default_Expr
872 (Type_Definition (Parent (T)), A);
876 end Validate_Ancestor_Part;
878 ----------------------------------------
879 -- Validate_Categorization_Dependency --
880 ----------------------------------------
882 procedure Validate_Categorization_Dependency
886 K : constant Node_Kind := Nkind (N);
887 P : Node_Id := Parent (N);
889 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
892 -- Only validate library units and subunits. For subunits, checks
893 -- concerning withed units apply to the parent compilation unit.
900 and then not Is_Compilation_Unit (U)
901 and then not Is_Child_Unit (U)
907 if Nkind (P) /= N_Compilation_Unit then
911 -- Body of RCI unit does not need validation
913 if Is_Remote_Call_Interface (E)
914 and then (Nkind (N) = N_Package_Body
915 or else Nkind (N) = N_Subprogram_Body)
920 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
924 Entity_Of_Withed : Entity_Id;
927 Item := First (Context_Items (P));
928 while Present (Item) loop
929 if Nkind (Item) = N_With_Clause
930 and then not (Implicit_With (Item)
931 or else Limited_Present (Item))
933 Entity_Of_Withed := Entity (Name (Item));
934 Check_Categorization_Dependencies
935 (U, Entity_Of_Withed, Item, Is_Subunit);
942 -- Child depends on parent; therefore parent should also be categorized
943 -- and satisfy the dependency hierarchy.
945 -- Check if N is a child spec
947 if (K in N_Generic_Declaration or else
948 K in N_Generic_Instantiation or else
949 K in N_Generic_Renaming_Declaration or else
950 K = N_Package_Declaration or else
951 K = N_Package_Renaming_Declaration or else
952 K = N_Subprogram_Declaration or else
953 K = N_Subprogram_Renaming_Declaration)
954 and then Present (Parent_Spec (N))
956 Check_Categorization_Dependencies (E, Scope (E), N, False);
958 -- Verify that public child of an RCI library unit must also be an
959 -- RCI library unit (RM E.2.3(15)).
961 if Is_Remote_Call_Interface (Scope (E))
962 and then not Private_Present (P)
963 and then not Is_Remote_Call_Interface (E)
965 Error_Msg_N ("public child of rci unit must also be rci unit", N);
968 end Validate_Categorization_Dependency;
970 --------------------------------
971 -- Validate_Controlled_Object --
972 --------------------------------
974 procedure Validate_Controlled_Object (E : Entity_Id) is
976 -- Don't need this check in Ada 2005 mode, where this is all taken
977 -- care of by the mechanism for Preelaborable Initialization.
979 if Ada_Version >= Ada_2005 then
983 -- For now, never apply this check for internal GNAT units, since we
984 -- have a number of cases in the library where we are stuck with objects
985 -- of this type, and the RM requires Preelaborate.
987 -- For similar reasons, we only do this check for source entities, since
988 -- we generate entities of this type in some situations.
990 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
991 -- We have to enforce them for RM compatibility, but we have no trouble
992 -- accepting these objects and doing the right thing. Note that there is
993 -- no requirement that Preelaborate not actually generate any code!
995 if In_Preelaborated_Unit
996 and then not Debug_Flag_PP
997 and then Comes_From_Source (E)
999 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1000 and then (not Inside_A_Generic
1001 or else Present (Enclosing_Generic_Body (E)))
1002 and then not Is_Protected_Type (Etype (E))
1005 ("library level controlled object not allowed in " &
1006 "preelaborated unit", E);
1008 end Validate_Controlled_Object;
1010 --------------------------------------
1011 -- Validate_Null_Statement_Sequence --
1012 --------------------------------------
1014 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1018 if In_Preelaborated_Unit then
1019 Item := First (Statements (Handled_Statement_Sequence (N)));
1020 while Present (Item) loop
1021 if Nkind (Item) /= N_Label
1022 and then Nkind (Item) /= N_Null_Statement
1024 -- In GNAT mode, this is a warning, allowing the run-time
1025 -- to judiciously bypass this error condition.
1027 Error_Msg_Warn := GNAT_Mode;
1029 ("<statements not allowed in preelaborated unit", Item);
1037 end Validate_Null_Statement_Sequence;
1039 ---------------------------------
1040 -- Validate_Object_Declaration --
1041 ---------------------------------
1043 procedure Validate_Object_Declaration (N : Node_Id) is
1044 Id : constant Entity_Id := Defining_Identifier (N);
1045 E : constant Node_Id := Expression (N);
1046 Odf : constant Node_Id := Object_Definition (N);
1047 T : constant Entity_Id := Etype (Id);
1050 -- Verify that any access to subprogram object does not have in its
1051 -- subprogram profile access type parameters or limited parameters
1052 -- without Read and Write attributes (E.2.3(13)).
1054 Validate_RCI_Subprogram_Declaration (N);
1056 -- Check that if we are in preelaborated elaboration code, then we
1057 -- do not have an instance of a default initialized private, task or
1058 -- protected object declaration which would violate (RM 10.2.1(9)).
1059 -- Note that constants are never default initialized (and the test
1060 -- below also filters out deferred constants). A variable is default
1061 -- initialized if it does *not* have an initialization expression.
1063 -- Filter out cases that are not declaration of a variable from source
1065 if Nkind (N) /= N_Object_Declaration
1066 or else Constant_Present (N)
1067 or else not Comes_From_Source (Id)
1072 -- Exclude generic specs from the checks (this will get rechecked
1073 -- on instantiations).
1075 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1079 -- Required checks for declaration that is in a preelaborated package
1080 -- and is not within some subprogram.
1082 if In_Preelaborated_Unit
1083 and then not In_Subprogram_Or_Concurrent_Unit
1085 -- Check for default initialized variable case. Note that in
1086 -- accordance with (RM B.1(24)) imported objects are not subject to
1087 -- default initialization.
1088 -- If the initialization does not come from source and is an
1089 -- aggregate, it is a static initialization that replaces an
1090 -- implicit call, and must be treated as such.
1093 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1097 elsif Is_Imported (Id) then
1102 Ent : Entity_Id := T;
1105 -- An array whose component type is a record with nonstatic
1106 -- default expressions is a violation, so we get the array's
1109 if Is_Array_Type (Ent) then
1111 Comp_Type : Entity_Id;
1114 Comp_Type := Component_Type (Ent);
1115 while Is_Array_Type (Comp_Type) loop
1116 Comp_Type := Component_Type (Comp_Type);
1123 -- Object decl. that is of record type and has no default expr.
1124 -- should check if there is any non-static default expression
1125 -- in component decl. of the record type decl.
1127 if Is_Record_Type (Ent) then
1128 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1129 Check_Non_Static_Default_Expr
1130 (Type_Definition (Parent (Ent)), N);
1132 elsif Nkind (Odf) = N_Subtype_Indication
1133 and then not Is_Array_Type (T)
1134 and then not Is_Private_Type (T)
1136 Check_Non_Static_Default_Expr (Type_Definition
1137 (Parent (Entity (Subtype_Mark (Odf)))), N);
1141 -- Check for invalid use of private object. Note that Ada 2005
1142 -- AI-161 modifies the rules for Ada 2005, including the use of
1143 -- the new pragma Preelaborable_Initialization.
1145 if Is_Private_Type (Ent)
1146 or else Depends_On_Private (Ent)
1148 -- Case where type has preelaborable initialization which
1149 -- means that a pragma Preelaborable_Initialization was
1150 -- given for the private type.
1152 if Has_Preelaborable_Initialization (Ent) then
1154 -- But for the predefined units, we will ignore this
1155 -- status unless we are in Ada 2005 mode since we want
1156 -- Ada 95 compatible behavior, in which the entities
1157 -- marked with this pragma in the predefined library are
1158 -- not treated specially.
1160 if Ada_Version < Ada_2005 then
1162 ("private object not allowed in preelaborated unit",
1164 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1167 -- Type does not have preelaborable initialization
1170 -- We allow this when compiling in GNAT mode to make life
1171 -- easier for some cases where it would otherwise be hard
1172 -- to be exactly valid Ada.
1174 if not GNAT_Mode then
1176 ("private object not allowed in preelaborated unit",
1179 -- Add a message if it would help to provide a pragma
1180 -- Preelaborable_Initialization on the type of the
1181 -- object (which would make it legal in Ada 2005).
1183 -- If the type has no full view (generic type, or
1184 -- previous error), the warning does not apply.
1186 if Is_Private_Type (Ent)
1187 and then Present (Full_View (Ent))
1189 Has_Preelaborable_Initialization (Full_View (Ent))
1191 Error_Msg_Sloc := Sloc (Ent);
1193 if Ada_Version >= Ada_2005 then
1195 ("\would be legal if pragma Preelaborable_" &
1196 "Initialization given for & #", N, Ent);
1199 ("\would be legal in Ada 2005 if pragma " &
1200 "Preelaborable_Initialization given for & #",
1207 -- Access to Task or Protected type
1209 elsif Is_Entity_Name (Odf)
1210 and then Present (Etype (Odf))
1211 and then Is_Access_Type (Etype (Odf))
1213 Ent := Designated_Type (Etype (Odf));
1215 elsif Is_Entity_Name (Odf) then
1216 Ent := Entity (Odf);
1218 elsif Nkind (Odf) = N_Subtype_Indication then
1219 Ent := Etype (Subtype_Mark (Odf));
1221 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1222 Ent := Component_Type (T);
1225 if Is_Task_Type (Ent)
1226 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1229 ("concurrent object not allowed in preelaborated unit",
1236 -- Non-static discriminants not allowed in preelaborated unit.
1237 -- Objects of a controlled type with a user-defined Initialize
1238 -- are forbidden as well.
1240 if Is_Record_Type (Etype (Id)) then
1242 ET : constant Entity_Id := Etype (Id);
1243 EE : constant Entity_Id := Etype (Etype (Id));
1247 if Has_Discriminants (ET)
1248 and then Present (EE)
1252 if Nkind (PEE) = N_Full_Type_Declaration
1253 and then not Static_Discriminant_Expr
1254 (Discriminant_Specifications (PEE))
1257 ("non-static discriminant in preelaborated unit",
1262 if Has_Overriding_Initialize (ET) then
1264 ("controlled type& does not have"
1265 & " preelaborable initialization", N, ET);
1272 -- A pure library_item must not contain the declaration of any variable
1273 -- except within a subprogram, generic subprogram, task unit, or
1274 -- protected unit (RM 10.2.1(16)).
1276 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1277 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1279 -- The visible part of an RCI library unit must not contain the
1280 -- declaration of a variable (RM E.1.3(9))
1282 elsif In_RCI_Declaration (N) then
1283 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1285 -- The visible part of a Shared Passive library unit must not contain
1286 -- the declaration of a variable (RM E.2.2(7))
1288 elsif In_RT_Declaration and then not In_Private_Part (Id) then
1290 ("visible variable not allowed in remote types unit", N);
1293 end Validate_Object_Declaration;
1295 ------------------------------
1296 -- Validate_RACW_Primitives --
1297 ------------------------------
1299 procedure Validate_RACW_Primitives (T : Entity_Id) is
1300 Desig_Type : Entity_Id;
1301 Primitive_Subprograms : Elist_Id;
1302 Subprogram_Elmt : Elmt_Id;
1303 Subprogram : Entity_Id;
1304 Param_Spec : Node_Id;
1306 Param_Type : Entity_Id;
1309 procedure Illegal_RACW (Msg : String; N : Node_Id);
1310 -- Diagnose that T is illegal because of the given reason, associated
1311 -- with the location of node N.
1313 Illegal_RACW_Message_Issued : Boolean := False;
1314 -- Set True once Illegal_RACW has been called
1320 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1322 if not Illegal_RACW_Message_Issued then
1324 ("illegal remote access to class-wide type&", T);
1325 Illegal_RACW_Message_Issued := True;
1328 Error_Msg_Sloc := Sloc (N);
1329 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1332 -- Start of processing for Validate_RACW_Primitives
1335 Desig_Type := Etype (Designated_Type (T));
1337 -- No action needed for concurrent types
1339 if Is_Concurrent_Type (Desig_Type) then
1343 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1345 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1346 while Subprogram_Elmt /= No_Elmt loop
1347 Subprogram := Node (Subprogram_Elmt);
1349 if Is_Predefined_Dispatching_Operation (Subprogram)
1350 or else Is_Hidden (Subprogram)
1352 goto Next_Subprogram;
1355 -- Check return type
1357 if Ekind (Subprogram) = E_Function then
1358 Rtyp := Etype (Subprogram);
1360 if Has_Controlling_Result (Subprogram) then
1363 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1364 Illegal_RACW ("anonymous access result", Rtyp);
1366 elsif Is_Limited_Type (Rtyp) then
1367 if No (TSS (Rtyp, TSS_Stream_Read))
1369 No (TSS (Rtyp, TSS_Stream_Write))
1372 ("limited return type must have Read and Write attributes",
1373 Parent (Subprogram));
1374 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1376 -- Check that the return type supports external streaming.
1377 -- Note that the language of the standard (E.2.2(14)) does not
1378 -- explicitly mention that case, but it really does not make
1379 -- sense to return a value containing a local access type.
1381 elsif Missing_Read_Write_Attributes (Rtyp)
1382 and then not Error_Posted (Rtyp)
1384 Illegal_RACW ("return type containing non-remote access "
1385 & "must have Read and Write attributes",
1386 Parent (Subprogram));
1392 Param := First_Formal (Subprogram);
1393 while Present (Param) loop
1395 -- Now find out if this parameter is a controlling parameter
1397 Param_Spec := Parent (Param);
1398 Param_Type := Etype (Param);
1400 if Is_Controlling_Formal (Param) then
1402 -- It is a controlling parameter, so specific checks below
1407 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1408 E_Anonymous_Access_Subprogram_Type)
1410 -- From RM E.2.2(14), no anonymous access parameter other than
1411 -- controlling ones may be used (because an anonymous access
1412 -- type never supports external streaming).
1414 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1416 elsif Is_Limited_Type (Param_Type) then
1418 -- Not a controlling parameter, so type must have Read and
1419 -- Write attributes.
1421 if No (TSS (Param_Type, TSS_Stream_Read))
1423 No (TSS (Param_Type, TSS_Stream_Write))
1426 ("limited formal must have Read and Write attributes",
1428 Explain_Limited_Type (Param_Type, Param_Spec);
1431 elsif Missing_Read_Write_Attributes (Param_Type)
1432 and then not Error_Posted (Param_Type)
1434 Illegal_RACW ("parameter containing non-remote access "
1435 & "must have Read and Write attributes", Param_Spec);
1438 -- Check next parameter in this subprogram
1440 Next_Formal (Param);
1444 Next_Elmt (Subprogram_Elmt);
1446 end Validate_RACW_Primitives;
1448 -------------------------------
1449 -- Validate_RCI_Declarations --
1450 -------------------------------
1452 procedure Validate_RCI_Declarations (P : Entity_Id) is
1456 E := First_Entity (P);
1457 while Present (E) loop
1458 if Comes_From_Source (E) then
1459 if Is_Limited_Type (E) then
1461 ("limited type not allowed in rci unit", Parent (E));
1462 Explain_Limited_Type (E, Parent (E));
1464 elsif Ekind_In (E, E_Generic_Function,
1466 E_Generic_Procedure)
1468 Error_Msg_N ("generic declaration not allowed in rci unit",
1471 elsif (Ekind (E) = E_Function
1472 or else Ekind (E) = E_Procedure)
1473 and then Has_Pragma_Inline (E)
1476 ("inlined subprogram not allowed in rci unit", Parent (E));
1478 -- Inner packages that are renamings need not be checked. Generic
1479 -- RCI packages are subject to the checks, but entities that come
1480 -- from formal packages are not part of the visible declarations
1481 -- of the package and are not checked.
1483 elsif Ekind (E) = E_Package then
1484 if Present (Renamed_Entity (E)) then
1487 elsif Ekind (P) /= E_Generic_Package
1488 or else List_Containing (Unit_Declaration_Node (E)) /=
1489 Generic_Formal_Declarations
1490 (Unit_Declaration_Node (P))
1492 Validate_RCI_Declarations (E);
1499 end Validate_RCI_Declarations;
1501 -----------------------------------------
1502 -- Validate_RCI_Subprogram_Declaration --
1503 -----------------------------------------
1505 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1506 K : constant Node_Kind := Nkind (N);
1509 Param_Spec : Node_Id;
1510 Param_Type : Entity_Id;
1511 Base_Param_Type : Entity_Id;
1512 Base_Under_Type : Entity_Id;
1513 Type_Decl : Node_Id;
1514 Error_Node : Node_Id := N;
1517 -- This procedure enforces rules on subprogram and access to subprogram
1518 -- declarations in RCI units. These rules do not apply to expander
1519 -- generated routines, which are not remote subprograms. It is called:
1521 -- 1. from Analyze_Subprogram_Declaration.
1522 -- 2. from Validate_Object_Declaration (access to subprogram).
1524 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1528 if K = N_Subprogram_Declaration then
1529 Profile := Parameter_Specifications (Specification (N));
1531 else pragma Assert (K = N_Object_Declaration);
1533 -- The above assertion is dubious, the visible declarations of an
1534 -- RCI unit never contain an object declaration, this should be an
1535 -- ACCESS-to-object declaration???
1537 Id := Defining_Identifier (N);
1539 if Nkind (Id) = N_Defining_Identifier
1540 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1541 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1544 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1550 -- Iterate through the parameter specification list, checking that
1551 -- no access parameter and no limited type parameter in the list.
1554 if Present (Profile) then
1555 Param_Spec := First (Profile);
1556 while Present (Param_Spec) loop
1557 Param_Type := Etype (Defining_Identifier (Param_Spec));
1558 Type_Decl := Parent (Param_Type);
1560 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1561 if K = N_Subprogram_Declaration then
1562 Error_Node := Param_Spec;
1565 -- Report error only if declaration is in source program
1567 if Comes_From_Source
1568 (Defining_Entity (Specification (N)))
1571 ("subprogram in 'R'C'I unit cannot have access parameter",
1575 -- For a limited private type parameter, we check only the private
1576 -- declaration and ignore full type declaration, unless this is
1577 -- the only declaration for the type, e.g., as a limited record.
1579 elsif Is_Limited_Type (Param_Type)
1580 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1582 (Nkind (Type_Decl) = N_Full_Type_Declaration
1583 and then not (Has_Private_Declaration (Param_Type))
1584 and then Comes_From_Source (N)))
1586 -- A limited parameter is legal only if user-specified Read and
1587 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1589 if No (Full_View (Param_Type))
1590 and then Ekind (Param_Type) /= E_Record_Type
1592 -- Type does not have completion yet, so if declared in
1593 -- the current RCI scope it is illegal, and will be flagged
1599 -- In Ada 95 the rules permit using a limited type that has
1600 -- user-specified Read and Write attributes that are specified
1601 -- in the private part of the package, whereas Ada 2005
1602 -- (AI-240) revises this to require the attributes to be
1603 -- "available" (implying that the attribute clauses must be
1604 -- visible to the RCI client). The Ada 95 rules violate the
1605 -- contract model for privacy, but we support both semantics
1606 -- for now for compatibility (note that ACATS test BXE2009
1607 -- checks a case that conforms to the Ada 95 rules but is
1608 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1609 -- possibilities of visible TSS stream subprograms or explicit
1610 -- stream attribute definitions because the TSS subprograms
1611 -- can be hidden in the private part while the attribute
1612 -- definitions are still be available from the visible part.
1614 Base_Param_Type := Base_Type (Param_Type);
1615 Base_Under_Type := Base_Type (Underlying_Type
1618 if (Ada_Version < Ada_2005
1620 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1622 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1624 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1626 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1628 (Ada_Version >= Ada_2005
1630 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1632 No (TSS (Base_Param_Type, TSS_Stream_Write))
1634 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1636 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1638 (not Has_Stream_Attribute_Definition
1639 (Base_Param_Type, TSS_Stream_Read)
1641 not Has_Stream_Attribute_Definition
1642 (Base_Param_Type, TSS_Stream_Write)))
1644 if K = N_Subprogram_Declaration then
1645 Error_Node := Param_Spec;
1648 if Ada_Version >= Ada_2005 then
1650 ("limited parameter in 'R'C'I unit "
1651 & "must have visible read/write attributes ",
1655 ("limited parameter in 'R'C'I unit "
1656 & "must have read/write attributes ",
1659 Explain_Limited_Type (Param_Type, Error_Node);
1662 -- In Ada 95, any non-remote access type (or any type with a
1663 -- component of a non-remote access type) that is visible in an
1664 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1665 -- unit, and thus is already guaranteed to support external
1666 -- streaming. However in Ada 2005 we have to account for the case
1667 -- of named access types from declared pure units as well, which
1668 -- may or may not support external streaming, and so we need to
1669 -- perform a specific check for E.2.3(14/2) here.
1671 -- Note that if the declaration of the type itself is illegal, we
1672 -- do not perform this check since it might be a cascaded error.
1675 if K = N_Subprogram_Declaration then
1676 Error_Node := Param_Spec;
1679 if Missing_Read_Write_Attributes (Param_Type)
1680 and then not Error_Posted (Param_Type)
1683 ("parameter containing non-remote access in 'R'C'I "
1684 & "subprogram must have visible "
1685 & "Read and Write attributes", Error_Node);
1691 -- No check on return type???
1693 end Validate_RCI_Subprogram_Declaration;
1695 ----------------------------------------------------
1696 -- Validate_Remote_Access_Object_Type_Declaration --
1697 ----------------------------------------------------
1699 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1701 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1702 -- True if tagged type E is a valid candidate as the root type of the
1703 -- designated type for a RACW, i.e. a tagged limited private type, or a
1704 -- limited interface type, or a private extension of such a type.
1706 ---------------------------------
1707 -- Is_Valid_Remote_Object_Type --
1708 ---------------------------------
1710 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1711 P : constant Node_Id := Parent (E);
1714 pragma Assert (Is_Tagged_Type (E));
1716 -- Simple case: a limited private type
1718 if Nkind (P) = N_Private_Type_Declaration
1719 and then Is_Limited_Record (E)
1723 -- A limited interface is not currently a legal ancestor for the
1724 -- designated type of an RACW type, because a type that implements
1725 -- such an interface need not be limited. However, the ARG seems to
1726 -- incline towards allowing an access to classwide limited interface
1727 -- type as a remote access type, as resolved in AI05-060. But note
1728 -- that the expansion circuitry for RACWs that designate classwide
1729 -- interfaces is not complete yet.
1731 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1734 -- A generic tagged limited type is a valid candidate. Limitedness
1735 -- will be checked again on the actual at instantiation point.
1737 elsif Nkind (P) = N_Formal_Type_Declaration
1738 and then Ekind (E) = E_Record_Type_With_Private
1739 and then Is_Generic_Type (E)
1740 and then Is_Limited_Record (E)
1744 -- A private extension declaration is a valid candidate if its parent
1747 elsif Nkind (P) = N_Private_Extension_Declaration then
1748 return Is_Valid_Remote_Object_Type (Etype (E));
1753 end Is_Valid_Remote_Object_Type;
1757 Direct_Designated_Type : Entity_Id;
1758 Desig_Type : Entity_Id;
1760 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1763 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1764 -- the given node is N_Access_To_Object_Definition.
1766 if not Comes_From_Source (T)
1767 or else (not In_RCI_Declaration (Parent (T))
1768 and then not In_RT_Declaration)
1773 -- An access definition in the private part of a Remote Types package
1774 -- may be legal if it has user-defined Read and Write attributes. This
1775 -- will be checked at the end of the package spec processing.
1777 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1781 -- Check RCI or RT unit type declaration. It may not contain the
1782 -- declaration of an access-to-object type unless it is a general access
1783 -- type that designates a class-wide limited private type or subtype.
1784 -- There are also constraints on the primitive subprograms of the
1785 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1787 if Ekind (T) /= E_General_Access_Type
1788 or else not Is_Class_Wide_Type (Designated_Type (T))
1790 if In_RCI_Declaration (Parent (T)) then
1792 ("error in access type in Remote_Call_Interface unit", T);
1795 ("error in access type in Remote_Types unit", T);
1798 Error_Msg_N ("\must be general access to class-wide type", T);
1802 Direct_Designated_Type := Designated_Type (T);
1803 Desig_Type := Etype (Direct_Designated_Type);
1805 -- Why is the check below not in
1806 -- Validate_Remote_Access_To_Class_Wide_Type???
1808 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1810 ("error in designated type of remote access to class-wide type", T);
1812 ("\must be tagged limited private or private extension", T);
1815 end Validate_Remote_Access_Object_Type_Declaration;
1817 -----------------------------------------------
1818 -- Validate_Remote_Access_To_Class_Wide_Type --
1819 -----------------------------------------------
1821 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1822 K : constant Node_Kind := Nkind (N);
1823 PK : constant Node_Kind := Nkind (Parent (N));
1827 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1828 -- of class-wide limited private types.
1830 -- Storage_Pool and Storage_Size are not defined for such types
1832 -- The expected type of allocator must not be such a type.
1834 -- The actual parameter of generic instantiation must not be such a
1835 -- type if the formal parameter is of an access type.
1837 -- On entry, there are five cases
1839 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1840 -- either Storage_Pool or Storage_Size.
1842 -- 2. called from exp_ch4 Expand_N_Allocator
1844 -- 3. called from sem_ch12 Analyze_Associations
1846 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1848 -- 5. called from sem_res Resolve_Actuals
1850 if K = N_Attribute_Reference then
1851 E := Etype (Prefix (N));
1853 if Is_Remote_Access_To_Class_Wide_Type (E) then
1854 Error_Msg_N ("incorrect attribute of remote operand", N);
1858 elsif K = N_Allocator then
1861 if Is_Remote_Access_To_Class_Wide_Type (E) then
1862 Error_Msg_N ("incorrect expected remote type of allocator", N);
1866 elsif K in N_Has_Entity then
1869 if Is_Remote_Access_To_Class_Wide_Type (E) then
1870 Error_Msg_N ("incorrect remote type generic actual", N);
1874 -- This subprogram also enforces the checks in E.2.2(13). A value of
1875 -- such type must not be dereferenced unless as controlling operand of
1876 -- a dispatching call. Explicit dereferences not coming from source are
1877 -- exempted from this checking because the expander produces them in
1878 -- some cases (such as for tag checks on dispatching calls with multiple
1879 -- controlling operands). However we do check in the case of an implicit
1880 -- dereference that is expanded to an explicit dereference (hence the
1881 -- test of whether Original_Node (N) comes from source).
1883 elsif K = N_Explicit_Dereference
1884 and then Comes_From_Source (Original_Node (N))
1886 E := Etype (Prefix (N));
1888 -- If the class-wide type is not a remote one, the restrictions
1891 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1895 -- If we have a true dereference that comes from source and that
1896 -- is a controlling argument for a dispatching call, accept it.
1898 if Is_Actual_Parameter (N)
1899 and then Is_Controlling_Actual (N)
1904 -- If we are just within a procedure or function call and the
1905 -- dereference has not been analyzed, return because this procedure
1906 -- will be called again from sem_res Resolve_Actuals. The same can
1907 -- apply in the case of dereference that is the prefix of a selected
1908 -- component, which can be a call given in prefixed form.
1910 if (Is_Actual_Parameter (N)
1911 or else PK = N_Selected_Component)
1912 and then not Analyzed (N)
1917 -- We must allow expanded code to generate a reference to the tag of
1918 -- the designated object (may be either the actual tag, or the stub
1919 -- tag in the case of a remote object).
1921 if PK = N_Selected_Component
1922 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1928 ("invalid dereference of a remote access-to-class-wide value", N);
1930 end Validate_Remote_Access_To_Class_Wide_Type;
1932 ------------------------------------------
1933 -- Validate_Remote_Type_Type_Conversion --
1934 ------------------------------------------
1936 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1937 S : constant Entity_Id := Etype (N);
1938 E : constant Entity_Id := Etype (Expression (N));
1941 -- This test is required in the case where a conversion appears inside a
1942 -- normal package, it does not necessarily have to be inside an RCI,
1943 -- Remote_Types unit (RM E.2.2(9,12)).
1945 if Is_Remote_Access_To_Subprogram_Type (E)
1946 and then not Is_Remote_Access_To_Subprogram_Type (S)
1949 ("incorrect conversion of remote operand to local type", N);
1952 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1953 and then Is_Remote_Access_To_Subprogram_Type (S)
1956 ("incorrect conversion of local operand to remote type", N);
1959 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1960 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1963 ("incorrect conversion of remote operand to local type", N);
1967 -- If a local access type is converted into a RACW type, then the
1968 -- current unit has a pointer that may now be exported to another
1971 if Is_Remote_Access_To_Class_Wide_Type (S)
1972 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1974 Set_Has_RACW (Current_Sem_Unit);
1976 end Validate_Remote_Type_Type_Conversion;
1978 -------------------------------
1979 -- Validate_RT_RAT_Component --
1980 -------------------------------
1982 procedure Validate_RT_RAT_Component (N : Node_Id) is
1983 Spec : constant Node_Id := Specification (N);
1984 Name_U : constant Entity_Id := Defining_Entity (Spec);
1987 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1990 if not Is_Remote_Types (Name_U) then
1994 Typ := First_Entity (Name_U);
1995 while Present (Typ) and then Typ /= First_Priv_Ent loop
1996 U_Typ := Underlying_Type (Typ);
2002 if Comes_From_Source (Typ) and then Is_Type (Typ) then
2003 if Missing_Read_Write_Attributes (Typ) then
2004 if Is_Non_Remote_Access_Type (Typ) then
2005 Error_Msg_N ("error in non-remote access type", U_Typ);
2008 ("error in record type containing a component of a " &
2009 "non-remote access type", U_Typ);
2012 if Ada_Version >= Ada_2005 then
2014 ("\must have visible Read and Write attribute " &
2015 "definition clauses (RM E.2.2(8))", U_Typ);
2018 ("\must have Read and Write attribute " &
2019 "definition clauses (RM E.2.2(8))", U_Typ);
2026 end Validate_RT_RAT_Component;
2028 -----------------------------------------
2029 -- Validate_SP_Access_Object_Type_Decl --
2030 -----------------------------------------
2032 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2033 Direct_Designated_Type : Entity_Id;
2035 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2036 -- Return true if the protected type designated by T has
2037 -- entry declarations.
2039 ----------------------------
2040 -- Has_Entry_Declarations --
2041 ----------------------------
2043 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2047 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2048 Ety := First_Entity (E);
2049 while Present (Ety) loop
2050 if Ekind (Ety) = E_Entry then
2059 end Has_Entry_Declarations;
2061 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2064 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2065 -- Nkind of the given entity is N_Access_To_Object_Definition.
2067 if not Comes_From_Source (T)
2068 or else not In_Shared_Passive_Unit
2069 or else In_Subprogram_Task_Protected_Unit
2074 -- Check Shared Passive unit. It should not contain the declaration
2075 -- of an access-to-object type whose designated type is a class-wide
2076 -- type, task type or protected type with entry (RM E.2.1(7)).
2078 Direct_Designated_Type := Designated_Type (T);
2080 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2082 ("invalid access-to-class-wide type in shared passive unit", T);
2085 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2087 ("invalid access-to-task type in shared passive unit", T);
2090 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2091 and then Has_Entry_Declarations (Direct_Designated_Type)
2094 ("invalid access-to-protected type in shared passive unit", T);
2097 end Validate_SP_Access_Object_Type_Decl;
2099 ---------------------------------
2100 -- Validate_Static_Object_Name --
2101 ---------------------------------
2103 procedure Validate_Static_Object_Name (N : Node_Id) is
2106 function Is_Primary (N : Node_Id) return Boolean;
2107 -- Determine whether node is syntactically a primary in an expression
2108 -- This function should probably be somewhere else ???
2109 -- Also it does not do what it says, e.g if N is a binary operator
2110 -- whose parent is a binary operator, Is_Primary returns True ???
2116 function Is_Primary (N : Node_Id) return Boolean is
2117 K : constant Node_Kind := Nkind (Parent (N));
2121 when N_Op | N_Membership_Test =>
2125 | N_Component_Association
2126 | N_Index_Or_Discriminant_Constraint =>
2129 when N_Attribute_Reference =>
2130 return Attribute_Name (Parent (N)) /= Name_Address
2131 and then Attribute_Name (Parent (N)) /= Name_Access
2132 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2134 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2136 when N_Indexed_Component =>
2137 return (N /= Prefix (Parent (N))
2138 or else Is_Primary (Parent (N)));
2140 when N_Qualified_Expression | N_Type_Conversion =>
2141 return Is_Primary (Parent (N));
2143 when N_Assignment_Statement | N_Object_Declaration =>
2144 return (N = Expression (Parent (N)));
2146 when N_Selected_Component =>
2147 return Is_Primary (Parent (N));
2154 -- Start of processing for Validate_Static_Object_Name
2157 if not In_Preelaborated_Unit
2158 or else not Comes_From_Source (N)
2159 or else In_Subprogram_Or_Concurrent_Unit
2160 or else Ekind (Current_Scope) = E_Block
2164 -- Filter out cases where primary is default in a component declaration,
2165 -- discriminant specification, or actual in a record type initialization
2168 -- Initialization call of internal types
2170 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2172 if Present (Parent (Parent (N)))
2173 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2178 if Nkind (Name (Parent (N))) = N_Identifier
2179 and then not Comes_From_Source (Entity (Name (Parent (N))))
2185 -- Error if the name is a primary in an expression. The parent must not
2186 -- be an operator, or a selected component or an indexed component that
2187 -- is itself a primary. Entities that are actuals do not need to be
2188 -- checked, because the call itself will be diagnosed.
2191 and then (not Inside_A_Generic
2192 or else Present (Enclosing_Generic_Body (N)))
2194 if Ekind (Entity (N)) = E_Variable
2195 or else Ekind (Entity (N)) in Formal_Object_Kind
2197 Flag_Non_Static_Expr
2198 ("non-static object name in preelaborated unit", N);
2200 -- Give an error for a reference to a nonstatic constant, unless the
2201 -- constant is in another GNAT library unit that is preelaborable.
2203 elsif Ekind (Entity (N)) = E_Constant
2204 and then not Is_Static_Expression (N)
2208 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2210 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2211 and then (Is_Preelaborated (Scope (E))
2212 or else Is_Pure (Scope (E))
2213 or else (Present (Renamed_Object (E))
2215 Is_Entity_Name (Renamed_Object (E))
2218 (Scope (Renamed_Object (E)))
2221 (Renamed_Object (E))))))
2225 -- This is the error case
2228 -- In GNAT mode, this is just a warning, to allow it to be
2229 -- judiciously turned off. Otherwise it is a real error.
2233 ("?non-static constant in preelaborated unit", N);
2235 Flag_Non_Static_Expr
2236 ("non-static constant in preelaborated unit", N);
2241 end Validate_Static_Object_Name;