1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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_Attr; use Sem_Attr;
39 with Sem_Aux; use Sem_Aux;
40 with Sem_Eval; use Sem_Eval;
41 with Sem_Util; use Sem_Util;
42 with Sinfo; use Sinfo;
43 with Snames; use Snames;
44 with Stand; use Stand;
46 package body Sem_Cat is
48 -----------------------
49 -- Local Subprograms --
50 -----------------------
52 procedure Check_Categorization_Dependencies
53 (Unit_Entity : Entity_Id;
54 Depended_Entity : Entity_Id;
56 Is_Subunit : Boolean);
57 -- This procedure checks that the categorization of a lib unit and that
58 -- of the depended unit satisfy dependency restrictions.
59 -- The depended_entity can be the entity in a with_clause item, in which
60 -- case Info_Node denotes that item. The depended_entity can also be the
61 -- parent unit of a child unit, in which case Info_Node is the declaration
62 -- of the child unit. The error message is posted on Info_Node, and is
63 -- specialized if Is_Subunit is true.
65 procedure Check_Non_Static_Default_Expr
68 -- Iterate through the component list of a record definition, check
69 -- that no component is declared with a nonstatic default value.
70 -- If a nonstatic default exists, report an error on Obj_Decl.
72 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
73 -- Return True if entity has attribute definition clauses for Read and
74 -- Write attributes that are visible at some place.
76 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
77 -- Returns true if the entity is a type whose full view is a non-remote
78 -- access type, for the purpose of enforcing E.2.2(8) rules.
80 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean;
81 -- Return true if Typ or the type of any of its subcomponents is a non
82 -- remote access type and doesn't have user-defined stream attributes.
84 function No_External_Streaming (E : Entity_Id) return Boolean;
85 -- Return True if the entity or one of its subcomponents does not support
86 -- external streaming.
88 function In_RCI_Declaration (N : Node_Id) return Boolean;
89 -- Determines if a declaration is within the visible part of a Remote
90 -- Call Interface compilation unit, for semantic checking purposes only
91 -- (returns false within an instance and within the package body).
93 function In_RT_Declaration return Boolean;
94 -- Determines if current scope is within the declaration of a Remote Types
95 -- unit, for semantic checking purposes.
97 function In_Shared_Passive_Unit return Boolean;
98 -- Determines if current scope is within a Shared Passive compilation unit
100 function Static_Discriminant_Expr (L : List_Id) return Boolean;
101 -- Iterate through the list of discriminants to check if any of them
102 -- contains non-static default expression, which is a violation in
103 -- a preelaborated library unit.
105 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
106 -- Check validity of declaration if RCI or RT unit. It should not contain
107 -- the declaration of an access-to-object type unless it is a general
108 -- access type that designates a class-wide limited private type. There are
109 -- also constraints about the primitive subprograms of the class-wide type.
110 -- RM E.2 (9, 13, 14)
112 procedure Validate_RACW_Primitive
115 -- Check legality of the declaration of primitive Subp of the designated
116 -- type of the given RACW type.
118 ---------------------------------------
119 -- Check_Categorization_Dependencies --
120 ---------------------------------------
122 procedure Check_Categorization_Dependencies
123 (Unit_Entity : Entity_Id;
124 Depended_Entity : Entity_Id;
126 Is_Subunit : Boolean)
128 N : constant Node_Id := Info_Node;
131 -- Here we define an enumeration type to represent categorization types,
132 -- ordered so that a unit with a given categorization can only WITH
133 -- units with lower or equal categorization type.
135 type Categorization is
139 Remote_Call_Interface,
142 function Get_Categorization (E : Entity_Id) return Categorization;
143 -- Check categorization flags from entity, and return in the form
144 -- of the lowest value of the Categorization type that applies to E.
146 ------------------------
147 -- Get_Categorization --
148 ------------------------
150 function Get_Categorization (E : Entity_Id) return Categorization is
152 -- Get the lowest categorization that corresponds to E. Note that
153 -- nothing prevents several (different) categorization pragmas
154 -- to apply to the same library unit, in which case the unit has
155 -- all associated categories, so we need to be careful here to
156 -- check pragmas in proper Categorization order in order to
157 -- return the lowest applicable value.
159 -- Ignore Pure specification if set by pragma Pure_Function
163 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
167 elsif Is_Shared_Passive (E) then
168 return Shared_Passive;
170 elsif Is_Remote_Types (E) then
173 elsif Is_Remote_Call_Interface (E) then
174 return Remote_Call_Interface;
179 end Get_Categorization;
181 Unit_Category : Categorization;
182 With_Category : Categorization;
184 -- Start of processing for Check_Categorization_Dependencies
187 -- Intrinsic subprograms are preelaborated, so do not impose any
188 -- categorization dependencies.
190 if Is_Intrinsic_Subprogram (Depended_Entity) then
194 -- First check 10.2.1 (11/1) rules on preelaborate packages
196 if Is_Preelaborated (Unit_Entity)
197 and then not Is_Preelaborated (Depended_Entity)
198 and then not Is_Pure (Depended_Entity)
205 -- Check categorization rules of RM E.2(5)
207 Unit_Category := Get_Categorization (Unit_Entity);
208 With_Category := Get_Categorization (Depended_Entity);
210 if With_Category > Unit_Category then
212 -- Special case: Remote_Types and Remote_Call_Interface are allowed
213 -- to WITH anything in the package body, per (RM E.2(5)).
215 if (Unit_Category = Remote_Types
216 or else Unit_Category = Remote_Call_Interface)
217 and then In_Package_Body (Unit_Entity)
221 -- Special case: Remote_Types can depend on Preelaborated per
224 elsif Unit_Category = Remote_Types
225 and then Is_Preelaborated (Depended_Entity)
229 -- All other cases, we do have an error
236 -- Here if we have an error
240 -- These messages are warnings in GNAT mode or if the -gnateP switch
241 -- was set. Otherwise these are real errors for real illegalities.
243 -- The reason we suppress these errors in GNAT mode is that the run-
244 -- time has several instances of violations of the categorization
245 -- errors (e.g. Pure units withing Preelaborate units. All these
246 -- violations are harmless in the cases where we intend them, and
247 -- we suppress the warnings with Warnings (Off). In cases where we
248 -- do not intend the violation, warnings are errors in GNAT mode
249 -- anyway, so we will still get an error.
252 Treat_Categorization_Errors_As_Warnings or GNAT_Mode;
254 -- Don't give error if main unit is not an internal unit, and the
255 -- unit generating the message is an internal unit. This is the
256 -- situation in which such messages would be ignored in any case,
257 -- so it is convenient not to generate them (since it causes
258 -- annoying interference with debugging).
260 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
261 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
267 elsif Is_Subunit then
269 ("<subunit cannot depend on& " &
270 "(parent has wrong categorization)", N, Depended_Entity);
272 -- Normal unit, not subunit
276 ("<cannot depend on& " &
277 "(wrong categorization)", N, Depended_Entity);
280 -- Add further explanation for Pure/Preelaborate common cases
282 if Unit_Category = Pure then
284 ("\<pure unit cannot depend on non-pure unit",
287 elsif Is_Preelaborated (Unit_Entity)
288 and then not Is_Preelaborated (Depended_Entity)
289 and then not Is_Pure (Depended_Entity)
292 ("\<preelaborated unit cannot depend on "
293 & "non-preelaborated unit",
297 end Check_Categorization_Dependencies;
299 -----------------------------------
300 -- Check_Non_Static_Default_Expr --
301 -----------------------------------
303 procedure Check_Non_Static_Default_Expr
308 Component_Decl : Node_Id;
311 if Nkind (Type_Def) = N_Derived_Type_Definition then
312 Recdef := Record_Extension_Part (Type_Def);
322 -- Check that component declarations do not involve:
324 -- a. a non-static default expression, where the object is
325 -- declared to be default initialized.
327 -- b. a dynamic Itype (discriminants and constraints)
329 if Null_Present (Recdef) then
332 Component_Decl := First (Component_Items (Component_List (Recdef)));
335 while Present (Component_Decl)
336 and then Nkind (Component_Decl) = N_Component_Declaration
338 if Present (Expression (Component_Decl))
339 and then Nkind (Expression (Component_Decl)) /= N_Null
340 and then not Is_Static_Expression (Expression (Component_Decl))
342 Error_Msg_Sloc := Sloc (Component_Decl);
344 ("object in preelaborated unit has non-static default#",
347 -- Fix this later ???
349 -- elsif Has_Dynamic_Itype (Component_Decl) then
351 -- ("dynamic type discriminant," &
352 -- " constraint in preelaborated unit",
356 Next (Component_Decl);
358 end Check_Non_Static_Default_Expr;
360 ---------------------------
361 -- Has_Non_Remote_Access --
362 ---------------------------
364 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean is
365 Component : Entity_Id;
366 Comp_Type : Entity_Id;
367 U_Typ : constant Entity_Id := Underlying_Type (Typ);
373 elsif Has_Read_Write_Attributes (Typ)
374 or else Has_Read_Write_Attributes (U_Typ)
378 elsif Is_Non_Remote_Access_Type (U_Typ) then
382 if Is_Record_Type (U_Typ) then
383 Component := First_Entity (U_Typ);
384 while Present (Component) loop
385 if not Is_Tag (Component) then
386 Comp_Type := Etype (Component);
388 if Has_Non_Remote_Access (Comp_Type) then
393 Next_Entity (Component);
396 elsif Is_Array_Type (U_Typ) then
397 return Has_Non_Remote_Access (Component_Type (U_Typ));
402 end Has_Non_Remote_Access;
404 -------------------------------
405 -- Has_Read_Write_Attributes --
406 -------------------------------
408 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
411 and then Has_Stream_Attribute_Definition (E,
412 TSS_Stream_Read, At_Any_Place => True)
413 and then Has_Stream_Attribute_Definition (E,
414 TSS_Stream_Write, At_Any_Place => True);
415 end Has_Read_Write_Attributes;
417 -------------------------------------
418 -- Has_Stream_Attribute_Definition --
419 -------------------------------------
421 function Has_Stream_Attribute_Definition
424 At_Any_Place : Boolean := False) return Boolean
427 Full_Type : Entity_Id := Typ;
430 -- In the case of a type derived from a private view, any specified
431 -- stream attributes will be attached to the derived type's underlying
432 -- type rather the derived type entity itself (which is itself private).
434 if Is_Private_Type (Typ)
435 and then Is_Derived_Type (Typ)
436 and then Present (Full_View (Typ))
438 Full_Type := Underlying_Type (Typ);
441 -- We start from the declaration node and then loop until the end of
442 -- the list until we find the requested attribute definition clause.
443 -- In Ada 2005 mode, clauses are ignored if they are not currently
444 -- visible (this is tested using the corresponding Entity, which is
445 -- inserted by the expander at the point where the clause occurs),
446 -- unless At_Any_Place is true.
448 Rep_Item := First_Rep_Item (Full_Type);
449 while Present (Rep_Item) loop
450 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
451 case Chars (Rep_Item) is
453 exit when Nam = TSS_Stream_Read;
456 exit when Nam = TSS_Stream_Write;
459 exit when Nam = TSS_Stream_Input;
462 exit when Nam = TSS_Stream_Output;
470 Next_Rep_Item (Rep_Item);
473 -- If At_Any_Place is true, return True if the attribute is available
474 -- at any place; if it is false, return True only if the attribute is
475 -- currently visible.
477 return Present (Rep_Item)
478 and then (Ada_Version < Ada_2005
480 or else not Is_Hidden (Entity (Rep_Item)));
481 end Has_Stream_Attribute_Definition;
483 ---------------------------
484 -- In_Preelaborated_Unit --
485 ---------------------------
487 function In_Preelaborated_Unit return Boolean is
488 Unit_Entity : constant Entity_Id := Current_Scope;
489 Unit_Kind : constant Node_Kind :=
490 Nkind (Unit (Cunit (Current_Sem_Unit)));
493 -- There are no constraints on body of remote_call_interface or
494 -- remote_types packages.
496 return (Unit_Entity /= Standard_Standard)
497 and then (Is_Preelaborated (Unit_Entity)
498 or else Is_Pure (Unit_Entity)
499 or else Is_Shared_Passive (Unit_Entity)
501 ((Is_Remote_Types (Unit_Entity)
502 or else Is_Remote_Call_Interface (Unit_Entity))
503 and then Ekind (Unit_Entity) = E_Package
504 and then Unit_Kind /= N_Package_Body
505 and then not In_Package_Body (Unit_Entity)
506 and then not In_Instance));
507 end In_Preelaborated_Unit;
513 function In_Pure_Unit return Boolean is
515 return Is_Pure (Current_Scope);
518 ------------------------
519 -- In_RCI_Declaration --
520 ------------------------
522 function In_RCI_Declaration (N : Node_Id) return Boolean is
523 Unit_Entity : constant Entity_Id := Current_Scope;
524 Unit_Kind : constant Node_Kind :=
525 Nkind (Unit (Cunit (Current_Sem_Unit)));
528 -- There are no restrictions on the private part or body
531 return Is_Remote_Call_Interface (Unit_Entity)
532 and then Is_Package_Or_Generic_Package (Unit_Entity)
533 and then Unit_Kind /= N_Package_Body
534 and then List_Containing (N) =
536 (Specification (Unit_Declaration_Node (Unit_Entity)))
537 and then not In_Package_Body (Unit_Entity)
538 and then not In_Instance;
540 -- What about the case of a nested package in the visible part???
541 -- This case is missed by the List_Containing check above???
542 end In_RCI_Declaration;
544 -----------------------
545 -- In_RT_Declaration --
546 -----------------------
548 function In_RT_Declaration return Boolean is
549 Unit_Entity : constant Entity_Id := Current_Scope;
550 Unit_Kind : constant Node_Kind :=
551 Nkind (Unit (Cunit (Current_Sem_Unit)));
554 -- There are no restrictions on the body of a Remote Types unit
556 return Is_Remote_Types (Unit_Entity)
557 and then Is_Package_Or_Generic_Package (Unit_Entity)
558 and then Unit_Kind /= N_Package_Body
559 and then not In_Package_Body (Unit_Entity)
560 and then not In_Instance;
561 end In_RT_Declaration;
563 ----------------------------
564 -- In_Shared_Passive_Unit --
565 ----------------------------
567 function In_Shared_Passive_Unit return Boolean is
568 Unit_Entity : constant Entity_Id := Current_Scope;
571 return Is_Shared_Passive (Unit_Entity);
572 end In_Shared_Passive_Unit;
574 ---------------------------------------
575 -- In_Subprogram_Task_Protected_Unit --
576 ---------------------------------------
578 function In_Subprogram_Task_Protected_Unit return Boolean is
582 -- The following is to verify that a declaration is inside
583 -- subprogram, generic subprogram, task unit, protected unit.
584 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
586 -- Use scope chain to check successively outer scopes
592 Is_Generic_Subprogram (E)
594 Is_Concurrent_Type (E)
598 elsif E = Standard_Standard then
604 end In_Subprogram_Task_Protected_Unit;
606 -------------------------------
607 -- Is_Non_Remote_Access_Type --
608 -------------------------------
610 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
611 U_E : constant Entity_Id := Underlying_Type (E);
615 -- This case arises for the case of a generic formal type, in which
616 -- case E.2.2(8) rules will be enforced at instantiation time.
621 return Is_Access_Type (U_E)
622 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
623 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
624 end Is_Non_Remote_Access_Type;
626 ---------------------------
627 -- No_External_Streaming --
628 ---------------------------
630 function No_External_Streaming (E : Entity_Id) return Boolean is
631 U_E : constant Entity_Id := Underlying_Type (E);
637 elsif Has_Read_Write_Attributes (E) then
639 -- Note: availability of stream attributes is tested on E, not U_E.
640 -- There may be stream attributes defined on U_E that are not visible
641 -- at the place where support of external streaming is tested.
645 elsif Has_Non_Remote_Access (U_E) then
649 return Is_Limited_Type (E);
650 end No_External_Streaming;
652 -------------------------------------
653 -- Set_Categorization_From_Pragmas --
654 -------------------------------------
656 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
657 P : constant Node_Id := Parent (N);
658 S : constant Entity_Id := Current_Scope;
660 procedure Set_Parents (Visibility : Boolean);
661 -- If this is a child instance, the parents are not immediately
662 -- visible during analysis. Make them momentarily visible so that
663 -- the argument of the pragma can be resolved properly, and reset
670 procedure Set_Parents (Visibility : Boolean) is
674 while Present (Par) and then Par /= Standard_Standard loop
675 Set_Is_Immediately_Visible (Par, Visibility);
680 -- Start of processing for Set_Categorization_From_Pragmas
683 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
684 -- The purpose is to set categorization flags before analyzing the
685 -- unit itself, so as to diagnose violations of categorization as
686 -- we process each declaration, even though the pragma appears after
689 if Nkind (P) /= N_Compilation_Unit then
698 and then Is_Generic_Instance (S)
703 PN := First (Pragmas_After (Aux_Decls_Node (P)));
704 while Present (PN) loop
706 -- Skip implicit types that may have been introduced by
707 -- previous analysis.
709 if Nkind (PN) = N_Pragma then
710 case Get_Pragma_Id (PN) is
711 when Pragma_All_Calls_Remote |
712 Pragma_Preelaborate |
714 Pragma_Remote_Call_Interface |
715 Pragma_Remote_Types |
716 Pragma_Shared_Passive => Analyze (PN);
725 and then Is_Generic_Instance (S)
730 end Set_Categorization_From_Pragmas;
732 -----------------------------------
733 -- Set_Categorization_From_Scope --
734 -----------------------------------
736 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
737 Declaration : Node_Id := Empty;
738 Specification : Node_Id := Empty;
742 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
744 if not Is_Remote_Call_Interface (E) then
745 if Ekind (E) in Subprogram_Kind then
746 Declaration := Unit_Declaration_Node (E);
748 if Nkind (Declaration) = N_Subprogram_Body
750 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
752 Specification := Corresponding_Spec (Declaration);
756 -- A subprogram body or renaming-as-body is a remote call
757 -- interface if it serves as the completion of a subprogram
758 -- declaration that is a remote call interface.
760 if Nkind (Specification) in N_Entity then
761 Set_Is_Remote_Call_Interface
762 (E, Is_Remote_Call_Interface (Specification));
764 -- A subprogram declaration is a remote call interface when it is
765 -- declared within the visible part of, or declared by, a library
766 -- unit declaration that is a remote call interface.
769 Set_Is_Remote_Call_Interface
770 (E, Is_Remote_Call_Interface (Scop)
771 and then not (In_Private_Part (Scop)
772 or else In_Package_Body (Scop)));
777 (E, Is_Remote_Types (Scop)
778 and then not (In_Private_Part (Scop)
779 or else In_Package_Body (Scop)));
780 end Set_Categorization_From_Scope;
782 ------------------------------
783 -- Static_Discriminant_Expr --
784 ------------------------------
786 -- We need to accommodate a Why_Not_Static call somehow here ???
788 function Static_Discriminant_Expr (L : List_Id) return Boolean is
789 Discriminant_Spec : Node_Id;
792 Discriminant_Spec := First (L);
793 while Present (Discriminant_Spec) loop
794 if Present (Expression (Discriminant_Spec))
795 and then not Is_Static_Expression (Expression (Discriminant_Spec))
800 Next (Discriminant_Spec);
804 end Static_Discriminant_Expr;
806 --------------------------------------
807 -- Validate_Access_Type_Declaration --
808 --------------------------------------
810 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
811 Def : constant Node_Id := Type_Definition (N);
816 -- Access to subprogram case
818 when N_Access_To_Subprogram_Definition =>
820 -- A pure library_item must not contain the declaration of a
821 -- named access type, except within a subprogram, generic
822 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
824 -- This test is skipped in Ada 2005 (see AI-366)
826 if Ada_Version < Ada_2005
827 and then Comes_From_Source (T)
828 and then In_Pure_Unit
829 and then not In_Subprogram_Task_Protected_Unit
831 Error_Msg_N ("named access type not allowed in pure unit", T);
834 -- Access to object case
836 when N_Access_To_Object_Definition =>
837 if Comes_From_Source (T)
838 and then In_Pure_Unit
839 and then not In_Subprogram_Task_Protected_Unit
841 -- We can't give the message yet, since the type is not frozen
842 -- and in Ada 2005 mode, access types are allowed in pure units
843 -- if the type has no storage pool (see AI-366). So we set a
844 -- flag which will be checked at freeze time.
846 Set_Is_Pure_Unit_Access_Type (T);
849 -- Check for RCI or RT unit type declaration: declaration of an
850 -- access-to-object type is illegal unless it is a general access
851 -- type that designates a class-wide limited private type.
852 -- Note that constraints on the primitive subprograms of the
853 -- designated tagged type are not enforced here but in
854 -- Validate_RACW_Primitives, which is done separately because the
855 -- designated type might not be frozen (and therefore its
856 -- primitive operations might not be completely known) at the
857 -- point of the RACW declaration.
859 Validate_Remote_Access_Object_Type_Declaration (T);
861 -- Check for shared passive unit type declaration. It should
862 -- not contain the declaration of access to class wide type,
863 -- access to task type and access to protected type with entry.
865 Validate_SP_Access_Object_Type_Decl (T);
871 -- Set categorization flag from package on entity as well, to allow
872 -- easy checks later on for required validations of RCI or RT units.
873 -- This is only done for entities that are in the original source.
875 if Comes_From_Source (T)
876 and then not (In_Package_Body (Scope (T))
877 or else In_Private_Part (Scope (T)))
879 Set_Is_Remote_Call_Interface
880 (T, Is_Remote_Call_Interface (Scope (T)));
882 (T, Is_Remote_Types (Scope (T)));
884 end Validate_Access_Type_Declaration;
886 ----------------------------
887 -- Validate_Ancestor_Part --
888 ----------------------------
890 procedure Validate_Ancestor_Part (N : Node_Id) is
891 A : constant Node_Id := Ancestor_Part (N);
892 T : constant Entity_Id := Entity (A);
895 if In_Preelaborated_Unit
896 and then not In_Subprogram_Or_Concurrent_Unit
897 and then (not Inside_A_Generic
898 or else Present (Enclosing_Generic_Body (N)))
900 -- If the type is private, it must have the Ada 2005 pragma
901 -- Has_Preelaborable_Initialization.
902 -- The check is omitted within predefined units. This is probably
903 -- obsolete code to fix the Ada95 weakness in this area ???
905 if Is_Private_Type (T)
906 and then not Has_Pragma_Preelab_Init (T)
907 and then not Is_Internal_File_Name
908 (Unit_File_Name (Get_Source_Unit (N)))
911 ("private ancestor type not allowed in preelaborated unit", A);
913 elsif Is_Record_Type (T) then
914 if Nkind (Parent (T)) = N_Full_Type_Declaration then
915 Check_Non_Static_Default_Expr
916 (Type_Definition (Parent (T)), A);
920 end Validate_Ancestor_Part;
922 ----------------------------------------
923 -- Validate_Categorization_Dependency --
924 ----------------------------------------
926 procedure Validate_Categorization_Dependency
930 K : constant Node_Kind := Nkind (N);
931 P : Node_Id := Parent (N);
933 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
936 -- Only validate library units and subunits. For subunits, checks
937 -- concerning withed units apply to the parent compilation unit.
944 and then not Is_Compilation_Unit (U)
945 and then not Is_Child_Unit (U)
951 if Nkind (P) /= N_Compilation_Unit then
955 -- Body of RCI unit does not need validation
957 if Is_Remote_Call_Interface (E)
958 and then (Nkind (N) = N_Package_Body
959 or else Nkind (N) = N_Subprogram_Body)
964 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
968 Entity_Of_Withed : Entity_Id;
971 Item := First (Context_Items (P));
972 while Present (Item) loop
973 if Nkind (Item) = N_With_Clause
974 and then not (Implicit_With (Item)
975 or else Limited_Present (Item))
977 Entity_Of_Withed := Entity (Name (Item));
978 Check_Categorization_Dependencies
979 (U, Entity_Of_Withed, Item, Is_Subunit);
986 -- Child depends on parent; therefore parent should also be categorized
987 -- and satisfy the dependency hierarchy.
989 -- Check if N is a child spec
991 if (K in N_Generic_Declaration or else
992 K in N_Generic_Instantiation or else
993 K in N_Generic_Renaming_Declaration or else
994 K = N_Package_Declaration or else
995 K = N_Package_Renaming_Declaration or else
996 K = N_Subprogram_Declaration or else
997 K = N_Subprogram_Renaming_Declaration)
998 and then Present (Parent_Spec (N))
1000 Check_Categorization_Dependencies (E, Scope (E), N, False);
1002 -- Verify that public child of an RCI library unit must also be an
1003 -- RCI library unit (RM E.2.3(15)).
1005 if Is_Remote_Call_Interface (Scope (E))
1006 and then not Private_Present (P)
1007 and then not Is_Remote_Call_Interface (E)
1009 Error_Msg_N ("public child of rci unit must also be rci unit", N);
1012 end Validate_Categorization_Dependency;
1014 --------------------------------
1015 -- Validate_Controlled_Object --
1016 --------------------------------
1018 procedure Validate_Controlled_Object (E : Entity_Id) is
1020 -- Don't need this check in Ada 2005 mode, where this is all taken
1021 -- care of by the mechanism for Preelaborable Initialization.
1023 if Ada_Version >= Ada_2005 then
1027 -- For now, never apply this check for internal GNAT units, since we
1028 -- have a number of cases in the library where we are stuck with objects
1029 -- of this type, and the RM requires Preelaborate.
1031 -- For similar reasons, we only do this check for source entities, since
1032 -- we generate entities of this type in some situations.
1034 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1035 -- We have to enforce them for RM compatibility, but we have no trouble
1036 -- accepting these objects and doing the right thing. Note that there is
1037 -- no requirement that Preelaborate not actually generate any code!
1039 if In_Preelaborated_Unit
1040 and then not Debug_Flag_PP
1041 and then Comes_From_Source (E)
1043 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1044 and then (not Inside_A_Generic
1045 or else Present (Enclosing_Generic_Body (E)))
1046 and then not Is_Protected_Type (Etype (E))
1049 ("library level controlled object not allowed in " &
1050 "preelaborated unit", E);
1052 end Validate_Controlled_Object;
1054 --------------------------------------
1055 -- Validate_Null_Statement_Sequence --
1056 --------------------------------------
1058 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1062 if In_Preelaborated_Unit then
1063 Item := First (Statements (Handled_Statement_Sequence (N)));
1064 while Present (Item) loop
1065 if Nkind (Item) /= N_Label
1066 and then Nkind (Item) /= N_Null_Statement
1068 -- In GNAT mode, this is a warning, allowing the run-time
1069 -- to judiciously bypass this error condition.
1071 Error_Msg_Warn := GNAT_Mode;
1073 ("<statements not allowed in preelaborated unit", Item);
1081 end Validate_Null_Statement_Sequence;
1083 ---------------------------------
1084 -- Validate_Object_Declaration --
1085 ---------------------------------
1087 procedure Validate_Object_Declaration (N : Node_Id) is
1088 Id : constant Entity_Id := Defining_Identifier (N);
1089 E : constant Node_Id := Expression (N);
1090 Odf : constant Node_Id := Object_Definition (N);
1091 T : constant Entity_Id := Etype (Id);
1094 -- Verify that any access to subprogram object does not have in its
1095 -- subprogram profile access type parameters or limited parameters
1096 -- without Read and Write attributes (E.2.3(13)).
1098 Validate_RCI_Subprogram_Declaration (N);
1100 -- Check that if we are in preelaborated elaboration code, then we
1101 -- do not have an instance of a default initialized private, task or
1102 -- protected object declaration which would violate (RM 10.2.1(9)).
1103 -- Note that constants are never default initialized (and the test
1104 -- below also filters out deferred constants). A variable is default
1105 -- initialized if it does *not* have an initialization expression.
1107 -- Filter out cases that are not declaration of a variable from source
1109 if Nkind (N) /= N_Object_Declaration
1110 or else Constant_Present (N)
1111 or else not Comes_From_Source (Id)
1116 -- Exclude generic specs from the checks (this will get rechecked
1117 -- on instantiations).
1119 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1123 -- Required checks for declaration that is in a preelaborated package
1124 -- and is not within some subprogram.
1126 if In_Preelaborated_Unit
1127 and then not In_Subprogram_Or_Concurrent_Unit
1129 -- Check for default initialized variable case. Note that in
1130 -- accordance with (RM B.1(24)) imported objects are not subject to
1131 -- default initialization.
1132 -- If the initialization does not come from source and is an
1133 -- aggregate, it is a static initialization that replaces an
1134 -- implicit call, and must be treated as such.
1137 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1141 elsif Is_Imported (Id) then
1146 Ent : Entity_Id := T;
1149 -- An array whose component type is a record with nonstatic
1150 -- default expressions is a violation, so we get the array's
1153 if Is_Array_Type (Ent) then
1155 Comp_Type : Entity_Id;
1158 Comp_Type := Component_Type (Ent);
1159 while Is_Array_Type (Comp_Type) loop
1160 Comp_Type := Component_Type (Comp_Type);
1167 -- Object decl. that is of record type and has no default expr.
1168 -- should check if there is any non-static default expression
1169 -- in component decl. of the record type decl.
1171 if Is_Record_Type (Ent) then
1172 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1173 Check_Non_Static_Default_Expr
1174 (Type_Definition (Parent (Ent)), N);
1176 elsif Nkind (Odf) = N_Subtype_Indication
1177 and then not Is_Array_Type (T)
1178 and then not Is_Private_Type (T)
1180 Check_Non_Static_Default_Expr (Type_Definition
1181 (Parent (Entity (Subtype_Mark (Odf)))), N);
1185 -- Check for invalid use of private object. Note that Ada 2005
1186 -- AI-161 modifies the rules for Ada 2005, including the use of
1187 -- the new pragma Preelaborable_Initialization.
1189 if Is_Private_Type (Ent)
1190 or else Depends_On_Private (Ent)
1192 -- Case where type has preelaborable initialization which
1193 -- means that a pragma Preelaborable_Initialization was
1194 -- given for the private type.
1196 if Has_Preelaborable_Initialization (Ent) then
1198 -- But for the predefined units, we will ignore this
1199 -- status unless we are in Ada 2005 mode since we want
1200 -- Ada 95 compatible behavior, in which the entities
1201 -- marked with this pragma in the predefined library are
1202 -- not treated specially.
1204 if Ada_Version < Ada_2005 then
1206 ("private object not allowed in preelaborated unit",
1208 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1211 -- Type does not have preelaborable initialization
1214 -- We allow this when compiling in GNAT mode to make life
1215 -- easier for some cases where it would otherwise be hard
1216 -- to be exactly valid Ada.
1218 if not GNAT_Mode then
1220 ("private object not allowed in preelaborated unit",
1223 -- Add a message if it would help to provide a pragma
1224 -- Preelaborable_Initialization on the type of the
1225 -- object (which would make it legal in Ada 2005).
1227 -- If the type has no full view (generic type, or
1228 -- previous error), the warning does not apply.
1230 if Is_Private_Type (Ent)
1231 and then Present (Full_View (Ent))
1233 Has_Preelaborable_Initialization (Full_View (Ent))
1235 Error_Msg_Sloc := Sloc (Ent);
1237 if Ada_Version >= Ada_2005 then
1239 ("\would be legal if pragma Preelaborable_" &
1240 "Initialization given for & #", N, Ent);
1243 ("\would be legal in Ada 2005 if pragma " &
1244 "Preelaborable_Initialization given for & #",
1251 -- Access to Task or Protected type
1253 elsif Is_Entity_Name (Odf)
1254 and then Present (Etype (Odf))
1255 and then Is_Access_Type (Etype (Odf))
1257 Ent := Designated_Type (Etype (Odf));
1259 elsif Is_Entity_Name (Odf) then
1260 Ent := Entity (Odf);
1262 elsif Nkind (Odf) = N_Subtype_Indication then
1263 Ent := Etype (Subtype_Mark (Odf));
1265 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1266 Ent := Component_Type (T);
1269 if Is_Task_Type (Ent)
1270 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1273 ("concurrent object not allowed in preelaborated unit",
1280 -- Non-static discriminants not allowed in preelaborated unit.
1281 -- Objects of a controlled type with a user-defined Initialize
1282 -- are forbidden as well.
1284 if Is_Record_Type (Etype (Id)) then
1286 ET : constant Entity_Id := Etype (Id);
1287 EE : constant Entity_Id := Etype (Etype (Id));
1291 if Has_Discriminants (ET)
1292 and then Present (EE)
1296 if Nkind (PEE) = N_Full_Type_Declaration
1297 and then not Static_Discriminant_Expr
1298 (Discriminant_Specifications (PEE))
1301 ("non-static discriminant in preelaborated unit",
1306 -- For controlled type or type with controlled component, check
1307 -- preelaboration flag, as there may be a non-null Initialize
1308 -- primitive. For language versions earlier than Ada 2005,
1309 -- there is no notion of preelaborable initialization, and
1310 -- Validate_Controlled_Object is used to enforce rules for
1311 -- controlled objects.
1313 if (Is_Controlled (ET) or else Has_Controlled_Component (ET))
1314 and then Ada_Version >= Ada_2005
1315 and then not Has_Preelaborable_Initialization (ET)
1318 ("controlled type& does not have"
1319 & " preelaborable initialization", N, ET);
1326 -- A pure library_item must not contain the declaration of any variable
1327 -- except within a subprogram, generic subprogram, task unit, or
1328 -- protected unit (RM 10.2.1(16)).
1330 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1331 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1333 -- The visible part of an RCI library unit must not contain the
1334 -- declaration of a variable (RM E.1.3(9))
1336 elsif In_RCI_Declaration (N) then
1337 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1339 -- The visible part of a Shared Passive library unit must not contain
1340 -- the declaration of a variable (RM E.2.2(7))
1342 elsif In_RT_Declaration and then not In_Private_Part (Id) then
1344 ("visible variable not allowed in remote types unit", N);
1347 end Validate_Object_Declaration;
1349 -----------------------------
1350 -- Validate_RACW_Primitive --
1351 -----------------------------
1353 procedure Validate_RACW_Primitive
1357 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id);
1358 -- Diagnose illegality on N. If RACW is present, report the error on it
1359 -- rather than on N.
1361 -------------------------
1362 -- Illegal_Remote_Subp --
1363 -------------------------
1365 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id) is
1367 if Present (RACW) then
1368 if not Error_Posted (RACW) then
1370 ("illegal remote access to class-wide type&", RACW);
1373 Error_Msg_Sloc := Sloc (N);
1374 Error_Msg_NE ("\\" & Msg & " in primitive& #", RACW, Subp);
1377 Error_Msg_NE (Msg & " in remote subprogram&", N, Subp);
1379 end Illegal_Remote_Subp;
1383 Param_Spec : Node_Id;
1384 Param_Type : Entity_Id;
1386 -- Start of processing for Validate_RACW_Primitive
1389 -- Check return type
1391 if Ekind (Subp) = E_Function then
1392 Rtyp := Etype (Subp);
1394 -- AI05-0101 (Binding Interpretation): The result type of a remote
1395 -- function must either support external streaming or be a
1396 -- controlling access result type.
1398 if Has_Controlling_Result (Subp) then
1401 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1402 Illegal_Remote_Subp ("anonymous access result", Rtyp);
1404 elsif Is_Limited_Type (Rtyp) then
1405 if No (TSS (Rtyp, TSS_Stream_Read))
1407 No (TSS (Rtyp, TSS_Stream_Write))
1410 ("limited return type must have Read and Write attributes",
1412 Explain_Limited_Type (Rtyp, Parent (Subp));
1415 -- Check that the return type supports external streaming
1417 elsif No_External_Streaming (Rtyp)
1418 and then not Error_Posted (Rtyp)
1420 Illegal_Remote_Subp ("return type containing non-remote access "
1421 & "must have Read and Write attributes",
1426 Param := First_Formal (Subp);
1427 while Present (Param) loop
1429 -- Now find out if this parameter is a controlling parameter
1431 Param_Spec := Parent (Param);
1432 Param_Type := Etype (Param);
1434 if Is_Controlling_Formal (Param) then
1436 -- It is a controlling parameter, so specific checks below do not
1441 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1442 E_Anonymous_Access_Subprogram_Type)
1444 -- From RM E.2.2(14), no anonymous access parameter other than
1445 -- controlling ones may be used (because an anonymous access
1446 -- type never supports external streaming).
1449 ("non-controlling access parameter", Param_Spec);
1451 elsif No_External_Streaming (Param_Type)
1452 and then not Error_Posted (Param_Type)
1454 Illegal_Remote_Subp ("formal parameter in remote subprogram must "
1455 & "support external streaming", Param_Spec);
1458 -- Check next parameter in this subprogram
1460 Next_Formal (Param);
1462 end Validate_RACW_Primitive;
1464 ------------------------------
1465 -- Validate_RACW_Primitives --
1466 ------------------------------
1468 procedure Validate_RACW_Primitives (T : Entity_Id) is
1469 Desig_Type : Entity_Id;
1470 Primitive_Subprograms : Elist_Id;
1471 Subprogram_Elmt : Elmt_Id;
1472 Subprogram : Entity_Id;
1475 Desig_Type := Etype (Designated_Type (T));
1477 -- No action needed for concurrent types
1479 if Is_Concurrent_Type (Desig_Type) then
1483 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1485 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1486 while Subprogram_Elmt /= No_Elmt loop
1487 Subprogram := Node (Subprogram_Elmt);
1489 if Is_Predefined_Dispatching_Operation (Subprogram)
1490 or else Is_Hidden (Subprogram)
1492 goto Next_Subprogram;
1495 Validate_RACW_Primitive (Subp => Subprogram, RACW => T);
1498 Next_Elmt (Subprogram_Elmt);
1500 end Validate_RACW_Primitives;
1502 -------------------------------
1503 -- Validate_RCI_Declarations --
1504 -------------------------------
1506 procedure Validate_RCI_Declarations (P : Entity_Id) is
1510 E := First_Entity (P);
1511 while Present (E) loop
1512 if Comes_From_Source (E) then
1513 if Is_Limited_Type (E) then
1515 ("limited type not allowed in rci unit", Parent (E));
1516 Explain_Limited_Type (E, Parent (E));
1518 elsif Ekind_In (E, E_Generic_Function,
1520 E_Generic_Procedure)
1522 Error_Msg_N ("generic declaration not allowed in rci unit",
1525 elsif (Ekind (E) = E_Function or else Ekind (E) = E_Procedure)
1526 and then Has_Pragma_Inline (E)
1529 ("inlined subprogram not allowed in rci unit", Parent (E));
1531 -- Inner packages that are renamings need not be checked. Generic
1532 -- RCI packages are subject to the checks, but entities that come
1533 -- from formal packages are not part of the visible declarations
1534 -- of the package and are not checked.
1536 elsif Ekind (E) = E_Package then
1537 if Present (Renamed_Entity (E)) then
1540 elsif Ekind (P) /= E_Generic_Package
1541 or else List_Containing (Unit_Declaration_Node (E)) /=
1542 Generic_Formal_Declarations
1543 (Unit_Declaration_Node (P))
1545 Validate_RCI_Declarations (E);
1552 end Validate_RCI_Declarations;
1554 -----------------------------------------
1555 -- Validate_RCI_Subprogram_Declaration --
1556 -----------------------------------------
1558 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1559 K : constant Node_Kind := Nkind (N);
1562 Param_Spec : Node_Id;
1563 Param_Type : Entity_Id;
1564 Error_Node : Node_Id := N;
1567 -- This procedure enforces rules on subprogram and access to subprogram
1568 -- declarations in RCI units. These rules do not apply to expander
1569 -- generated routines, which are not remote subprograms. It is called:
1571 -- 1. from Analyze_Subprogram_Declaration.
1572 -- 2. from Validate_Object_Declaration (access to subprogram).
1574 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1578 if K = N_Subprogram_Declaration then
1579 Id := Defining_Unit_Name (Specification (N));
1580 Profile := Parameter_Specifications (Specification (N));
1582 else pragma Assert (K = N_Object_Declaration);
1584 -- The above assertion is dubious, the visible declarations of an
1585 -- RCI unit never contain an object declaration, this should be an
1586 -- ACCESS-to-object declaration???
1588 Id := Defining_Identifier (N);
1590 if Nkind (Id) = N_Defining_Identifier
1591 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1592 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1595 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1601 -- Iterate through the parameter specification list, checking that
1602 -- no access parameter and no limited type parameter in the list.
1605 if Present (Profile) then
1606 Param_Spec := First (Profile);
1607 while Present (Param_Spec) loop
1608 Param_Type := Etype (Defining_Identifier (Param_Spec));
1610 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1611 if K = N_Subprogram_Declaration then
1612 Error_Node := Param_Spec;
1615 -- Report error only if declaration is in source program
1617 if Comes_From_Source
1618 (Defining_Entity (Specification (N)))
1621 ("subprogram in 'R'C'I unit cannot have access parameter",
1625 -- For a limited private type parameter, we check only the private
1626 -- declaration and ignore full type declaration, unless this is
1627 -- the only declaration for the type, e.g., as a limited record.
1629 elsif No_External_Streaming (Param_Type) then
1630 if K = N_Subprogram_Declaration then
1631 Error_Node := Param_Spec;
1635 ("formal of remote subprogram& "
1636 & "must support external streaming",
1638 if Is_Limited_Type (Param_Type) then
1639 Explain_Limited_Type (Param_Type, Error_Node);
1646 -- No check on return type???
1648 end Validate_RCI_Subprogram_Declaration;
1650 ----------------------------------------------------
1651 -- Validate_Remote_Access_Object_Type_Declaration --
1652 ----------------------------------------------------
1654 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1656 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1657 -- True if tagged type E is a valid candidate as the root type of the
1658 -- designated type for a RACW, i.e. a tagged limited private type, or a
1659 -- limited interface type, or a private extension of such a type.
1661 ---------------------------------
1662 -- Is_Valid_Remote_Object_Type --
1663 ---------------------------------
1665 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1666 P : constant Node_Id := Parent (E);
1669 pragma Assert (Is_Tagged_Type (E));
1671 -- Simple case: a limited private type
1673 if Nkind (P) = N_Private_Type_Declaration
1674 and then Is_Limited_Record (E)
1678 -- AI05-0060 (Binding Interpretation): A limited interface is a legal
1679 -- ancestor for the designated type of an RACW type.
1681 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1684 -- A generic tagged limited type is a valid candidate. Limitedness
1685 -- will be checked again on the actual at instantiation point.
1687 elsif Nkind (P) = N_Formal_Type_Declaration
1688 and then Ekind (E) = E_Record_Type_With_Private
1689 and then Is_Generic_Type (E)
1690 and then Is_Limited_Record (E)
1694 -- A private extension declaration is a valid candidate if its parent
1697 elsif Nkind (P) = N_Private_Extension_Declaration then
1698 return Is_Valid_Remote_Object_Type (Etype (E));
1703 end Is_Valid_Remote_Object_Type;
1707 Direct_Designated_Type : Entity_Id;
1708 Desig_Type : Entity_Id;
1710 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1713 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1714 -- the given node is N_Access_To_Object_Definition.
1716 if not Comes_From_Source (T)
1717 or else (not In_RCI_Declaration (Parent (T))
1718 and then not In_RT_Declaration)
1723 -- An access definition in the private part of a Remote Types package
1724 -- may be legal if it has user-defined Read and Write attributes. This
1725 -- will be checked at the end of the package spec processing.
1727 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1731 -- Check RCI or RT unit type declaration. It may not contain the
1732 -- declaration of an access-to-object type unless it is a general access
1733 -- type that designates a class-wide limited private type or subtype.
1734 -- There are also constraints on the primitive subprograms of the
1735 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1737 if Ekind (T) /= E_General_Access_Type
1738 or else not Is_Class_Wide_Type (Designated_Type (T))
1740 if In_RCI_Declaration (Parent (T)) then
1742 ("error in access type in Remote_Call_Interface unit", T);
1745 ("error in access type in Remote_Types unit", T);
1748 Error_Msg_N ("\must be general access to class-wide type", T);
1752 Direct_Designated_Type := Designated_Type (T);
1753 Desig_Type := Etype (Direct_Designated_Type);
1755 -- Why is the check below not in
1756 -- Validate_Remote_Access_To_Class_Wide_Type???
1758 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1760 ("error in designated type of remote access to class-wide type", T);
1762 ("\must be tagged limited private or private extension", T);
1765 end Validate_Remote_Access_Object_Type_Declaration;
1767 -----------------------------------------------
1768 -- Validate_Remote_Access_To_Class_Wide_Type --
1769 -----------------------------------------------
1771 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1772 K : constant Node_Kind := Nkind (N);
1773 PK : constant Node_Kind := Nkind (Parent (N));
1777 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1778 -- of class-wide limited private types.
1780 -- Storage_Pool and Storage_Size are not defined for such types
1782 -- The expected type of allocator must not be such a type.
1784 -- The actual parameter of generic instantiation must not be such a
1785 -- type if the formal parameter is of an access type.
1787 -- On entry, there are five cases
1789 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1790 -- either Storage_Pool or Storage_Size.
1792 -- 2. called from exp_ch4 Expand_N_Allocator
1794 -- 3. called from sem_ch12 Analyze_Associations
1796 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1798 -- 5. called from sem_res Resolve_Actuals
1800 if K = N_Attribute_Reference then
1801 E := Etype (Prefix (N));
1803 if Is_Remote_Access_To_Class_Wide_Type (E) then
1804 Error_Msg_N ("incorrect attribute of remote operand", N);
1808 elsif K = N_Allocator then
1811 if Is_Remote_Access_To_Class_Wide_Type (E) then
1812 Error_Msg_N ("incorrect expected remote type of allocator", N);
1816 elsif K in N_Has_Entity then
1819 if Is_Remote_Access_To_Class_Wide_Type (E) then
1820 Error_Msg_N ("incorrect remote type generic actual", N);
1824 -- This subprogram also enforces the checks in E.2.2(13). A value of
1825 -- such type must not be dereferenced unless as controlling operand of
1826 -- a dispatching call. Explicit dereferences not coming from source are
1827 -- exempted from this checking because the expander produces them in
1828 -- some cases (such as for tag checks on dispatching calls with multiple
1829 -- controlling operands). However we do check in the case of an implicit
1830 -- dereference that is expanded to an explicit dereference (hence the
1831 -- test of whether Original_Node (N) comes from source).
1833 elsif K = N_Explicit_Dereference
1834 and then Comes_From_Source (Original_Node (N))
1836 E := Etype (Prefix (N));
1838 -- If the class-wide type is not a remote one, the restrictions
1841 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1845 -- If we have a true dereference that comes from source and that
1846 -- is a controlling argument for a dispatching call, accept it.
1848 if Is_Actual_Parameter (N)
1849 and then Is_Controlling_Actual (N)
1854 -- If we are just within a procedure or function call and the
1855 -- dereference has not been analyzed, return because this procedure
1856 -- will be called again from sem_res Resolve_Actuals. The same can
1857 -- apply in the case of dereference that is the prefix of a selected
1858 -- component, which can be a call given in prefixed form.
1860 if (Is_Actual_Parameter (N)
1861 or else PK = N_Selected_Component)
1862 and then not Analyzed (N)
1867 -- We must allow expanded code to generate a reference to the tag of
1868 -- the designated object (may be either the actual tag, or the stub
1869 -- tag in the case of a remote object).
1871 if PK = N_Selected_Component
1872 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1878 ("invalid dereference of a remote access-to-class-wide value", N);
1880 end Validate_Remote_Access_To_Class_Wide_Type;
1882 ------------------------------------------
1883 -- Validate_Remote_Type_Type_Conversion --
1884 ------------------------------------------
1886 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1887 S : constant Entity_Id := Etype (N);
1888 E : constant Entity_Id := Etype (Expression (N));
1891 -- This test is required in the case where a conversion appears inside a
1892 -- normal package, it does not necessarily have to be inside an RCI,
1893 -- Remote_Types unit (RM E.2.2(9,12)).
1895 if Is_Remote_Access_To_Subprogram_Type (E)
1896 and then not Is_Remote_Access_To_Subprogram_Type (S)
1899 ("incorrect conversion of remote operand to local type", N);
1902 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1903 and then Is_Remote_Access_To_Subprogram_Type (S)
1906 ("incorrect conversion of local operand to remote type", N);
1909 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1910 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1913 ("incorrect conversion of remote operand to local type", N);
1917 -- If a local access type is converted into a RACW type, then the
1918 -- current unit has a pointer that may now be exported to another
1921 if Is_Remote_Access_To_Class_Wide_Type (S)
1922 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1924 Set_Has_RACW (Current_Sem_Unit);
1926 end Validate_Remote_Type_Type_Conversion;
1928 -------------------------------
1929 -- Validate_RT_RAT_Component --
1930 -------------------------------
1932 procedure Validate_RT_RAT_Component (N : Node_Id) is
1933 Spec : constant Node_Id := Specification (N);
1934 Name_U : constant Entity_Id := Defining_Entity (Spec);
1937 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1939 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean;
1940 -- True if any stream attribute is available for Typ
1942 ---------------------------------
1943 -- Stream_Attributes_Available --
1944 ---------------------------------
1946 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean
1949 return Stream_Attribute_Available (Typ, TSS_Stream_Read)
1951 Stream_Attribute_Available (Typ, TSS_Stream_Write)
1953 Stream_Attribute_Available (Typ, TSS_Stream_Input)
1955 Stream_Attribute_Available (Typ, TSS_Stream_Output);
1956 end Stream_Attributes_Available;
1958 -- Start of processing for Validate_RT_RAT_Component
1961 if not Is_Remote_Types (Name_U) then
1965 Typ := First_Entity (Name_U);
1966 while Present (Typ) and then Typ /= First_Priv_Ent loop
1967 U_Typ := Underlying_Type (Typ);
1973 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1975 -- Check that the type can be meaningfully transmitted to another
1976 -- partition (E.2.2(8)).
1978 if (Ada_Version < Ada_2005 and then Has_Non_Remote_Access (U_Typ))
1980 (Stream_Attributes_Available (Typ)
1981 and then No_External_Streaming (U_Typ))
1983 if Is_Non_Remote_Access_Type (Typ) then
1984 Error_Msg_N ("error in non-remote access type", U_Typ);
1987 ("error in record type containing a component of a " &
1988 "non-remote access type", U_Typ);
1991 if Ada_Version >= Ada_2005 then
1993 ("\must have visible Read and Write attribute " &
1994 "definition clauses (RM E.2.2(8))", U_Typ);
1997 ("\must have Read and Write attribute " &
1998 "definition clauses (RM E.2.2(8))", U_Typ);
2005 end Validate_RT_RAT_Component;
2007 -----------------------------------------
2008 -- Validate_SP_Access_Object_Type_Decl --
2009 -----------------------------------------
2011 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2012 Direct_Designated_Type : Entity_Id;
2014 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2015 -- Return true if the protected type designated by T has
2016 -- entry declarations.
2018 ----------------------------
2019 -- Has_Entry_Declarations --
2020 ----------------------------
2022 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2026 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2027 Ety := First_Entity (E);
2028 while Present (Ety) loop
2029 if Ekind (Ety) = E_Entry then
2038 end Has_Entry_Declarations;
2040 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2043 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2044 -- Nkind of the given entity is N_Access_To_Object_Definition.
2046 if not Comes_From_Source (T)
2047 or else not In_Shared_Passive_Unit
2048 or else In_Subprogram_Task_Protected_Unit
2053 -- Check Shared Passive unit. It should not contain the declaration
2054 -- of an access-to-object type whose designated type is a class-wide
2055 -- type, task type or protected type with entry (RM E.2.1(7)).
2057 Direct_Designated_Type := Designated_Type (T);
2059 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2061 ("invalid access-to-class-wide type in shared passive unit", T);
2064 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2066 ("invalid access-to-task type in shared passive unit", T);
2069 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2070 and then Has_Entry_Declarations (Direct_Designated_Type)
2073 ("invalid access-to-protected type in shared passive unit", T);
2076 end Validate_SP_Access_Object_Type_Decl;
2078 ---------------------------------
2079 -- Validate_Static_Object_Name --
2080 ---------------------------------
2082 procedure Validate_Static_Object_Name (N : Node_Id) is
2085 function Is_Primary (N : Node_Id) return Boolean;
2086 -- Determine whether node is syntactically a primary in an expression
2087 -- This function should probably be somewhere else ???
2088 -- Also it does not do what it says, e.g if N is a binary operator
2089 -- whose parent is a binary operator, Is_Primary returns True ???
2095 function Is_Primary (N : Node_Id) return Boolean is
2096 K : constant Node_Kind := Nkind (Parent (N));
2100 when N_Op | N_Membership_Test =>
2104 | N_Component_Association
2105 | N_Index_Or_Discriminant_Constraint =>
2108 when N_Attribute_Reference =>
2109 return Attribute_Name (Parent (N)) /= Name_Address
2110 and then Attribute_Name (Parent (N)) /= Name_Access
2111 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2113 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2115 when N_Indexed_Component =>
2116 return (N /= Prefix (Parent (N))
2117 or else Is_Primary (Parent (N)));
2119 when N_Qualified_Expression | N_Type_Conversion =>
2120 return Is_Primary (Parent (N));
2122 when N_Assignment_Statement | N_Object_Declaration =>
2123 return (N = Expression (Parent (N)));
2125 when N_Selected_Component =>
2126 return Is_Primary (Parent (N));
2133 -- Start of processing for Validate_Static_Object_Name
2136 if not In_Preelaborated_Unit
2137 or else not Comes_From_Source (N)
2138 or else In_Subprogram_Or_Concurrent_Unit
2139 or else Ekind (Current_Scope) = E_Block
2143 -- Filter out cases where primary is default in a component declaration,
2144 -- discriminant specification, or actual in a record type initialization
2147 -- Initialization call of internal types
2149 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2151 if Present (Parent (Parent (N)))
2152 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2157 if Nkind (Name (Parent (N))) = N_Identifier
2158 and then not Comes_From_Source (Entity (Name (Parent (N))))
2164 -- Error if the name is a primary in an expression. The parent must not
2165 -- be an operator, or a selected component or an indexed component that
2166 -- is itself a primary. Entities that are actuals do not need to be
2167 -- checked, because the call itself will be diagnosed.
2170 and then (not Inside_A_Generic
2171 or else Present (Enclosing_Generic_Body (N)))
2173 if Ekind (Entity (N)) = E_Variable
2174 or else Ekind (Entity (N)) in Formal_Object_Kind
2176 Flag_Non_Static_Expr
2177 ("non-static object name in preelaborated unit", N);
2179 -- Give an error for a reference to a nonstatic constant, unless the
2180 -- constant is in another GNAT library unit that is preelaborable.
2182 elsif Ekind (Entity (N)) = E_Constant
2183 and then not Is_Static_Expression (N)
2187 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2189 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2190 and then (Is_Preelaborated (Scope (E))
2191 or else Is_Pure (Scope (E))
2192 or else (Present (Renamed_Object (E))
2194 Is_Entity_Name (Renamed_Object (E))
2197 (Scope (Renamed_Object (E)))
2200 (Renamed_Object (E))))))
2204 -- This is the error case
2207 -- In GNAT mode, this is just a warning, to allow it to be
2208 -- judiciously turned off. Otherwise it is a real error.
2212 ("?non-static constant in preelaborated unit", N);
2214 Flag_Non_Static_Expr
2215 ("non-static constant in preelaborated unit", N);
2220 end Validate_Static_Object_Name;