1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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_Dist; use Sem_Dist;
41 with Sem_Eval; use Sem_Eval;
42 with Sem_Util; use Sem_Util;
43 with Sinfo; use Sinfo;
44 with Snames; use Snames;
45 with Stand; use Stand;
47 package body Sem_Cat is
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 procedure Check_Categorization_Dependencies
54 (Unit_Entity : Entity_Id;
55 Depended_Entity : Entity_Id;
57 Is_Subunit : Boolean);
58 -- This procedure checks that the categorization of a lib unit and that
59 -- of the depended unit satisfy dependency restrictions.
60 -- The depended_entity can be the entity in a with_clause item, in which
61 -- case Info_Node denotes that item. The depended_entity can also be the
62 -- parent unit of a child unit, in which case Info_Node is the declaration
63 -- of the child unit. The error message is posted on Info_Node, and is
64 -- specialized if Is_Subunit is true.
66 procedure Check_Non_Static_Default_Expr
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a nonstatic default value.
71 -- If a nonstatic default exists, report an error on Obj_Decl.
73 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
74 -- Return True if entity has attribute definition clauses for Read and
75 -- Write attributes that are visible at some place.
77 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
78 -- Returns true if the entity is a type whose full view is a non-remote
79 -- access type, for the purpose of enforcing E.2.2(8) rules.
81 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean;
82 -- Return true if Typ or the type of any of its subcomponents is a non
83 -- remote access type and doesn't have user-defined stream attributes.
85 function No_External_Streaming (E : Entity_Id) return Boolean;
86 -- Return True if the entity or one of its subcomponents does not support
87 -- external streaming.
89 function In_RCI_Declaration return Boolean;
90 function In_RT_Declaration return Boolean;
91 -- Determine if current scope is within the declaration of a Remote Call
92 -- Interface or Remote Types unit, for semantic checking purposes.
94 function In_Package_Declaration return Boolean;
95 -- Shared supporting routine for In_RCI_Declaration and In_RT_Declaration
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 and Remote_Call_Interface declarations
222 -- can depend on a preelaborated unit via a private with_clause, per
225 elsif (Unit_Category = Remote_Types
227 Unit_Category = Remote_Call_Interface)
228 and then Nkind (N) = N_With_Clause
229 and then Private_Present (N)
230 and then Is_Preelaborated (Depended_Entity)
234 -- All other cases, we do have an error
241 -- Here if we have an error
245 -- These messages are warnings in GNAT mode or if the -gnateP switch
246 -- was set. Otherwise these are real errors for real illegalities.
248 -- The reason we suppress these errors in GNAT mode is that the run-
249 -- time has several instances of violations of the categorization
250 -- errors (e.g. Pure units withing Preelaborate units. All these
251 -- violations are harmless in the cases where we intend them, and
252 -- we suppress the warnings with Warnings (Off). In cases where we
253 -- do not intend the violation, warnings are errors in GNAT mode
254 -- anyway, so we will still get an error.
257 Treat_Categorization_Errors_As_Warnings or GNAT_Mode;
259 -- Don't give error if main unit is not an internal unit, and the
260 -- unit generating the message is an internal unit. This is the
261 -- situation in which such messages would be ignored in any case,
262 -- so it is convenient not to generate them (since it causes
263 -- annoying interference with debugging).
265 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
266 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
270 -- Dependence of Remote_Types or Remote_Call_Interface declaration
271 -- on a preelaborated unit with a normal with_clause.
273 elsif (Unit_Category = Remote_Types
275 Unit_Category = Remote_Call_Interface)
276 and then Is_Preelaborated (Depended_Entity)
279 ("<<must use private with clause for preelaborated unit& ",
284 elsif Is_Subunit then
286 ("<subunit cannot depend on& " &
287 "(parent has wrong categorization)", N, Depended_Entity);
289 -- Normal unit, not subunit
293 ("<<cannot depend on& " &
294 "(wrong categorization)", N, Depended_Entity);
297 -- Add further explanation for Pure/Preelaborate common cases
299 if Unit_Category = Pure then
301 ("\<<pure unit cannot depend on non-pure unit",
304 elsif Is_Preelaborated (Unit_Entity)
305 and then not Is_Preelaborated (Depended_Entity)
306 and then not Is_Pure (Depended_Entity)
309 ("\<<preelaborated unit cannot depend on "
310 & "non-preelaborated unit",
314 end Check_Categorization_Dependencies;
316 -----------------------------------
317 -- Check_Non_Static_Default_Expr --
318 -----------------------------------
320 procedure Check_Non_Static_Default_Expr
325 Component_Decl : Node_Id;
328 if Nkind (Type_Def) = N_Derived_Type_Definition then
329 Recdef := Record_Extension_Part (Type_Def);
339 -- Check that component declarations do not involve:
341 -- a. a non-static default expression, where the object is
342 -- declared to be default initialized.
344 -- b. a dynamic Itype (discriminants and constraints)
346 if Null_Present (Recdef) then
349 Component_Decl := First (Component_Items (Component_List (Recdef)));
352 while Present (Component_Decl)
353 and then Nkind (Component_Decl) = N_Component_Declaration
355 if Present (Expression (Component_Decl))
356 and then Nkind (Expression (Component_Decl)) /= N_Null
357 and then not Is_OK_Static_Expression (Expression (Component_Decl))
359 Error_Msg_Sloc := Sloc (Component_Decl);
361 ("object in preelaborated unit has non-static default#",
364 -- Fix this later ???
366 -- elsif Has_Dynamic_Itype (Component_Decl) then
368 -- ("dynamic type discriminant," &
369 -- " constraint in preelaborated unit",
373 Next (Component_Decl);
375 end Check_Non_Static_Default_Expr;
377 ---------------------------
378 -- Has_Non_Remote_Access --
379 ---------------------------
381 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean is
382 Component : Entity_Id;
383 Comp_Type : Entity_Id;
384 U_Typ : constant Entity_Id := Underlying_Type (Typ);
390 elsif Has_Read_Write_Attributes (Typ)
391 or else Has_Read_Write_Attributes (U_Typ)
395 elsif Is_Non_Remote_Access_Type (U_Typ) then
399 if Is_Record_Type (U_Typ) then
400 Component := First_Entity (U_Typ);
401 while Present (Component) loop
402 if not Is_Tag (Component) then
403 Comp_Type := Etype (Component);
405 if Has_Non_Remote_Access (Comp_Type) then
410 Next_Entity (Component);
413 elsif Is_Array_Type (U_Typ) then
414 return Has_Non_Remote_Access (Component_Type (U_Typ));
419 end Has_Non_Remote_Access;
421 -------------------------------
422 -- Has_Read_Write_Attributes --
423 -------------------------------
425 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
428 and then Has_Stream_Attribute_Definition
429 (E, TSS_Stream_Read, At_Any_Place => True)
430 and then Has_Stream_Attribute_Definition
431 (E, TSS_Stream_Write, At_Any_Place => True);
432 end Has_Read_Write_Attributes;
434 -------------------------------------
435 -- Has_Stream_Attribute_Definition --
436 -------------------------------------
438 function Has_Stream_Attribute_Definition
441 At_Any_Place : Boolean := False) return Boolean
446 -- The stream operation may be specified by an attribute definition
447 -- clause in the source, or by an aspect that generates such an
448 -- attribute definition. For an aspect, the generated attribute
449 -- definition may be placed at the freeze point of the full view of
450 -- the type, but the aspect specification makes the operation visible
451 -- to a client wherever the partial view is visible.
454 -- We start from the declaration node and then loop until the end of
455 -- the list until we find the requested attribute definition clause.
456 -- In Ada 2005 mode, clauses are ignored if they are not currently
457 -- visible (this is tested using the corresponding Entity, which is
458 -- inserted by the expander at the point where the clause occurs),
459 -- unless At_Any_Place is true.
461 Rep_Item := First_Rep_Item (Typ);
462 while Present (Rep_Item) loop
463 Real_Rep := Rep_Item;
465 -- If the representation item is an aspect specification, retrieve
466 -- the corresponding pragma or attribute definition.
468 if Nkind (Rep_Item) = N_Aspect_Specification then
469 Real_Rep := Aspect_Rep_Item (Rep_Item);
472 if Nkind (Real_Rep) = N_Attribute_Definition_Clause then
473 case Chars (Real_Rep) is
475 exit when Nam = TSS_Stream_Read;
478 exit when Nam = TSS_Stream_Write;
481 exit when Nam = TSS_Stream_Input;
484 exit when Nam = TSS_Stream_Output;
492 Next_Rep_Item (Rep_Item);
495 -- If not found, and the type is derived from a private view, check
496 -- for a stream attribute inherited from parent. Any specified stream
497 -- attributes will be attached to the derived type's underlying type
498 -- rather the derived type entity itself (which is itself private).
501 and then Is_Private_Type (Typ)
502 and then Is_Derived_Type (Typ)
503 and then Present (Full_View (Typ))
505 return Has_Stream_Attribute_Definition
506 (Underlying_Type (Typ), Nam, At_Any_Place);
508 -- Otherwise, if At_Any_Place is true, return True if the attribute is
509 -- available at any place; if it is false, return True only if the
510 -- attribute is currently visible.
513 return Present (Rep_Item)
514 and then (Ada_Version < Ada_2005
516 or else not Is_Hidden (Entity (Rep_Item)));
518 end Has_Stream_Attribute_Definition;
520 ----------------------------
521 -- In_Package_Declaration --
522 ----------------------------
524 function In_Package_Declaration return Boolean is
525 Unit_Kind : constant Node_Kind :=
526 Nkind (Unit (Cunit (Current_Sem_Unit)));
529 -- There are no restrictions on the body of an RCI or RT unit
531 return Is_Package_Or_Generic_Package (Current_Scope)
532 and then Unit_Kind /= N_Package_Body
533 and then not In_Package_Body (Current_Scope)
534 and then not In_Instance;
535 end In_Package_Declaration;
537 ---------------------------
538 -- In_Preelaborated_Unit --
539 ---------------------------
541 function In_Preelaborated_Unit return Boolean is
542 Unit_Entity : Entity_Id := Current_Scope;
543 Unit_Kind : constant Node_Kind :=
544 Nkind (Unit (Cunit (Current_Sem_Unit)));
547 -- If evaluating actuals for a child unit instantiation, then ignore
548 -- the preelaboration status of the parent; use the child instead.
550 if Is_Compilation_Unit (Unit_Entity)
551 and then Unit_Kind in N_Generic_Instantiation
552 and then not In_Same_Source_Unit (Unit_Entity,
553 Cunit (Current_Sem_Unit))
555 Unit_Entity := Cunit_Entity (Current_Sem_Unit);
558 -- There are no constraints on the body of Remote_Call_Interface or
559 -- Remote_Types packages.
561 return (Unit_Entity /= Standard_Standard)
562 and then (Is_Preelaborated (Unit_Entity)
563 or else Is_Pure (Unit_Entity)
564 or else Is_Shared_Passive (Unit_Entity)
566 ((Is_Remote_Types (Unit_Entity)
567 or else Is_Remote_Call_Interface (Unit_Entity))
568 and then Ekind (Unit_Entity) = E_Package
569 and then Unit_Kind /= N_Package_Body
570 and then not In_Package_Body (Unit_Entity)
571 and then not In_Instance));
572 end In_Preelaborated_Unit;
578 function In_Pure_Unit return Boolean is
580 return Is_Pure (Current_Scope);
583 ------------------------
584 -- In_RCI_Declaration --
585 ------------------------
587 function In_RCI_Declaration return Boolean is
589 return Is_Remote_Call_Interface (Current_Scope)
590 and then In_Package_Declaration;
591 end In_RCI_Declaration;
593 -----------------------
594 -- In_RT_Declaration --
595 -----------------------
597 function In_RT_Declaration return Boolean is
599 return Is_Remote_Types (Current_Scope) and then In_Package_Declaration;
600 end In_RT_Declaration;
602 ----------------------------
603 -- In_Shared_Passive_Unit --
604 ----------------------------
606 function In_Shared_Passive_Unit return Boolean is
607 Unit_Entity : constant Entity_Id := Current_Scope;
610 return Is_Shared_Passive (Unit_Entity);
611 end In_Shared_Passive_Unit;
613 ---------------------------------------
614 -- In_Subprogram_Task_Protected_Unit --
615 ---------------------------------------
617 function In_Subprogram_Task_Protected_Unit return Boolean is
621 -- The following is to verify that a declaration is inside
622 -- subprogram, generic subprogram, task unit, protected unit.
623 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
625 -- Use scope chain to check successively outer scopes
629 if Is_Subprogram_Or_Generic_Subprogram (E)
631 Is_Concurrent_Type (E)
635 elsif E = Standard_Standard then
641 end In_Subprogram_Task_Protected_Unit;
643 -------------------------------
644 -- Is_Non_Remote_Access_Type --
645 -------------------------------
647 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
648 U_E : constant Entity_Id := Underlying_Type (Base_Type (E));
649 -- Use full view of base type to handle subtypes properly.
654 -- This case arises for the case of a generic formal type, in which
655 -- case E.2.2(8) rules will be enforced at instantiation time.
660 return Is_Access_Type (U_E)
661 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
662 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
663 end Is_Non_Remote_Access_Type;
665 ---------------------------
666 -- No_External_Streaming --
667 ---------------------------
669 function No_External_Streaming (E : Entity_Id) return Boolean is
670 U_E : constant Entity_Id := Underlying_Type (E);
676 elsif Has_Read_Write_Attributes (E) then
678 -- Note: availability of stream attributes is tested on E, not U_E.
679 -- There may be stream attributes defined on U_E that are not visible
680 -- at the place where support of external streaming is tested.
684 elsif Has_Non_Remote_Access (U_E) then
688 return Is_Limited_Type (E);
689 end No_External_Streaming;
691 -------------------------------------
692 -- Set_Categorization_From_Pragmas --
693 -------------------------------------
695 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
696 P : constant Node_Id := Parent (N);
697 S : constant Entity_Id := Current_Scope;
699 procedure Set_Parents (Visibility : Boolean);
700 -- If this is a child instance, the parents are not immediately
701 -- visible during analysis. Make them momentarily visible so that
702 -- the argument of the pragma can be resolved properly, and reset
709 procedure Set_Parents (Visibility : Boolean) is
713 while Present (Par) and then Par /= Standard_Standard loop
714 Set_Is_Immediately_Visible (Par, Visibility);
719 -- Start of processing for Set_Categorization_From_Pragmas
722 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
723 -- The purpose is to set categorization flags before analyzing the
724 -- unit itself, so as to diagnose violations of categorization as
725 -- we process each declaration, even though the pragma appears after
728 if Nkind (P) /= N_Compilation_Unit then
736 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then
740 PN := First (Pragmas_After (Aux_Decls_Node (P)));
741 while Present (PN) loop
743 -- Skip implicit types that may have been introduced by
744 -- previous analysis.
746 if Nkind (PN) = N_Pragma then
747 case Get_Pragma_Id (PN) is
748 when Pragma_All_Calls_Remote |
749 Pragma_Preelaborate |
751 Pragma_Remote_Call_Interface |
752 Pragma_Remote_Types |
753 Pragma_Shared_Passive => Analyze (PN);
761 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then
765 end Set_Categorization_From_Pragmas;
767 -----------------------------------
768 -- Set_Categorization_From_Scope --
769 -----------------------------------
771 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
772 Declaration : Node_Id := Empty;
773 Specification : Node_Id := Empty;
777 (E, Is_Pure (Scop) and then Is_Library_Level_Entity (E));
779 if not Is_Remote_Call_Interface (E) then
780 if Ekind (E) in Subprogram_Kind then
781 Declaration := Unit_Declaration_Node (E);
783 if Nkind_In (Declaration, N_Subprogram_Body,
784 N_Subprogram_Renaming_Declaration)
786 Specification := Corresponding_Spec (Declaration);
790 -- A subprogram body or renaming-as-body is a remote call interface
791 -- if it serves as the completion of a subprogram declaration that
792 -- is a remote call interface.
794 if Nkind (Specification) in N_Entity then
795 Set_Is_Remote_Call_Interface
796 (E, Is_Remote_Call_Interface (Specification));
798 -- A subprogram declaration is a remote call interface when it is
799 -- declared within the visible part of, or declared by, a library
800 -- unit declaration that is a remote call interface.
803 Set_Is_Remote_Call_Interface
804 (E, Is_Remote_Call_Interface (Scop)
805 and then not (In_Private_Part (Scop)
806 or else In_Package_Body (Scop)));
811 (E, Is_Remote_Types (Scop)
812 and then not (In_Private_Part (Scop)
813 or else In_Package_Body (Scop)));
814 end Set_Categorization_From_Scope;
816 ------------------------------
817 -- Static_Discriminant_Expr --
818 ------------------------------
820 -- We need to accommodate a Why_Not_Static call somehow here ???
822 function Static_Discriminant_Expr (L : List_Id) return Boolean is
823 Discriminant_Spec : Node_Id;
826 Discriminant_Spec := First (L);
827 while Present (Discriminant_Spec) loop
828 if Present (Expression (Discriminant_Spec))
830 not Is_OK_Static_Expression (Expression (Discriminant_Spec))
835 Next (Discriminant_Spec);
839 end Static_Discriminant_Expr;
841 --------------------------------------
842 -- Validate_Access_Type_Declaration --
843 --------------------------------------
845 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
846 Def : constant Node_Id := Type_Definition (N);
851 -- Access to subprogram case
853 when N_Access_To_Subprogram_Definition =>
855 -- A pure library_item must not contain the declaration of a
856 -- named access type, except within a subprogram, generic
857 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
859 -- This test is skipped in Ada 2005 (see AI-366)
861 if Ada_Version < Ada_2005
862 and then Comes_From_Source (T)
863 and then In_Pure_Unit
864 and then not In_Subprogram_Task_Protected_Unit
866 Error_Msg_N ("named access type not allowed in pure unit", T);
869 -- Access to object case
871 when N_Access_To_Object_Definition =>
872 if Comes_From_Source (T)
873 and then In_Pure_Unit
874 and then not In_Subprogram_Task_Protected_Unit
876 -- We can't give the message yet, since the type is not frozen
877 -- and in Ada 2005 mode, access types are allowed in pure units
878 -- if the type has no storage pool (see AI-366). So we set a
879 -- flag which will be checked at freeze time.
881 Set_Is_Pure_Unit_Access_Type (T);
884 -- Check for RCI or RT unit type declaration: declaration of an
885 -- access-to-object type is illegal unless it is a general access
886 -- type that designates a class-wide limited private type.
887 -- Note that constraints on the primitive subprograms of the
888 -- designated tagged type are not enforced here but in
889 -- Validate_RACW_Primitives, which is done separately because the
890 -- designated type might not be frozen (and therefore its
891 -- primitive operations might not be completely known) at the
892 -- point of the RACW declaration.
894 Validate_Remote_Access_Object_Type_Declaration (T);
896 -- Check for shared passive unit type declaration. It should
897 -- not contain the declaration of access to class wide type,
898 -- access to task type and access to protected type with entry.
900 Validate_SP_Access_Object_Type_Decl (T);
906 -- Set categorization flag from package on entity as well, to allow
907 -- easy checks later on for required validations of RCI or RT units.
908 -- This is only done for entities that are in the original source.
910 if Comes_From_Source (T)
911 and then not (In_Package_Body (Scope (T))
912 or else In_Private_Part (Scope (T)))
914 Set_Is_Remote_Call_Interface
915 (T, Is_Remote_Call_Interface (Scope (T)));
917 (T, Is_Remote_Types (Scope (T)));
919 end Validate_Access_Type_Declaration;
921 ----------------------------
922 -- Validate_Ancestor_Part --
923 ----------------------------
925 procedure Validate_Ancestor_Part (N : Node_Id) is
926 A : constant Node_Id := Ancestor_Part (N);
927 T : constant Entity_Id := Entity (A);
930 if In_Preelaborated_Unit
931 and then not In_Subprogram_Or_Concurrent_Unit
932 and then (not Inside_A_Generic
933 or else Present (Enclosing_Generic_Body (N)))
935 -- If the type is private, it must have the Ada 2005 pragma
936 -- Has_Preelaborable_Initialization.
938 -- The check is omitted within predefined units. This is probably
939 -- obsolete code to fix the Ada 95 weakness in this area ???
941 if Is_Private_Type (T)
942 and then not Has_Pragma_Preelab_Init (T)
943 and then not Is_Internal_File_Name
944 (Unit_File_Name (Get_Source_Unit (N)))
947 ("private ancestor type not allowed in preelaborated unit", A);
949 elsif Is_Record_Type (T) then
950 if Nkind (Parent (T)) = N_Full_Type_Declaration then
951 Check_Non_Static_Default_Expr
952 (Type_Definition (Parent (T)), A);
956 end Validate_Ancestor_Part;
958 ----------------------------------------
959 -- Validate_Categorization_Dependency --
960 ----------------------------------------
962 procedure Validate_Categorization_Dependency
966 K : constant Node_Kind := Nkind (N);
967 P : Node_Id := Parent (N);
969 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
972 -- Only validate library units and subunits. For subunits, checks
973 -- concerning withed units apply to the parent compilation unit.
980 and then not Is_Compilation_Unit (U)
981 and then not Is_Child_Unit (U)
987 if Nkind (P) /= N_Compilation_Unit then
991 -- Body of RCI unit does not need validation
993 if Is_Remote_Call_Interface (E)
994 and then Nkind_In (N, N_Package_Body, N_Subprogram_Body)
999 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
1003 Entity_Of_Withed : Entity_Id;
1006 Item := First (Context_Items (P));
1007 while Present (Item) loop
1008 if Nkind (Item) = N_With_Clause
1009 and then not (Implicit_With (Item)
1010 or else Limited_Present (Item)
1012 -- Skip if error already posted on the WITH
1013 -- clause (in which case the Name attribute
1014 -- may be invalid). In particular, this fixes
1015 -- the problem of hanging in the presence of a
1016 -- WITH clause on a child that is an illegal
1017 -- generic instantiation.
1019 or else Error_Posted (Item))
1021 Entity_Of_Withed := Entity (Name (Item));
1022 Check_Categorization_Dependencies
1023 (U, Entity_Of_Withed, Item, Is_Subunit);
1030 -- Child depends on parent; therefore parent should also be categorized
1031 -- and satisfy the dependency hierarchy.
1033 -- Check if N is a child spec
1035 if (K in N_Generic_Declaration or else
1036 K in N_Generic_Instantiation or else
1037 K in N_Generic_Renaming_Declaration or else
1038 K = N_Package_Declaration or else
1039 K = N_Package_Renaming_Declaration or else
1040 K = N_Subprogram_Declaration or else
1041 K = N_Subprogram_Renaming_Declaration)
1042 and then Present (Parent_Spec (N))
1044 Check_Categorization_Dependencies (E, Scope (E), N, False);
1046 -- Verify that public child of an RCI library unit must also be an
1047 -- RCI library unit (RM E.2.3(15)).
1049 if Is_Remote_Call_Interface (Scope (E))
1050 and then not Private_Present (P)
1051 and then not Is_Remote_Call_Interface (E)
1053 Error_Msg_N ("public child of rci unit must also be rci unit", N);
1056 end Validate_Categorization_Dependency;
1058 --------------------------------
1059 -- Validate_Controlled_Object --
1060 --------------------------------
1062 procedure Validate_Controlled_Object (E : Entity_Id) is
1064 -- Don't need this check in Ada 2005 mode, where this is all taken
1065 -- care of by the mechanism for Preelaborable Initialization.
1067 if Ada_Version >= Ada_2005 then
1071 -- For now, never apply this check for internal GNAT units, since we
1072 -- have a number of cases in the library where we are stuck with objects
1073 -- of this type, and the RM requires Preelaborate.
1075 -- For similar reasons, we only do this check for source entities, since
1076 -- we generate entities of this type in some situations.
1078 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1079 -- We have to enforce them for RM compatibility, but we have no trouble
1080 -- accepting these objects and doing the right thing. Note that there is
1081 -- no requirement that Preelaborate not actually generate any code.
1083 if In_Preelaborated_Unit
1084 and then not Debug_Flag_PP
1085 and then Comes_From_Source (E)
1087 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1088 and then (not Inside_A_Generic
1089 or else Present (Enclosing_Generic_Body (E)))
1090 and then not Is_Protected_Type (Etype (E))
1093 ("library level controlled object not allowed in " &
1094 "preelaborated unit", E);
1096 end Validate_Controlled_Object;
1098 --------------------------------------
1099 -- Validate_Null_Statement_Sequence --
1100 --------------------------------------
1102 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1106 if In_Preelaborated_Unit then
1107 Item := First (Statements (Handled_Statement_Sequence (N)));
1108 while Present (Item) loop
1109 if Nkind (Item) /= N_Label
1110 and then Nkind (Item) /= N_Null_Statement
1112 -- In GNAT mode, this is a warning, allowing the run-time
1113 -- to judiciously bypass this error condition.
1115 Error_Msg_Warn := GNAT_Mode;
1117 ("<<statements not allowed in preelaborated unit", Item);
1125 end Validate_Null_Statement_Sequence;
1127 ---------------------------------
1128 -- Validate_Object_Declaration --
1129 ---------------------------------
1131 procedure Validate_Object_Declaration (N : Node_Id) is
1132 Id : constant Entity_Id := Defining_Identifier (N);
1133 E : constant Node_Id := Expression (N);
1134 Odf : constant Node_Id := Object_Definition (N);
1135 T : constant Entity_Id := Etype (Id);
1138 -- Verify that any access to subprogram object does not have in its
1139 -- subprogram profile access type parameters or limited parameters
1140 -- without Read and Write attributes (E.2.3(13)).
1142 Validate_RCI_Subprogram_Declaration (N);
1144 -- Check that if we are in preelaborated elaboration code, then we
1145 -- do not have an instance of a default initialized private, task or
1146 -- protected object declaration which would violate (RM 10.2.1(9)).
1147 -- Note that constants are never default initialized (and the test
1148 -- below also filters out deferred constants). A variable is default
1149 -- initialized if it does *not* have an initialization expression.
1151 -- Filter out cases that are not declaration of a variable from source
1153 if Nkind (N) /= N_Object_Declaration
1154 or else Constant_Present (N)
1155 or else not Comes_From_Source (Id)
1160 -- Exclude generic specs from the checks (this will get rechecked
1161 -- on instantiations).
1163 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1167 -- Required checks for declaration that is in a preelaborated package
1168 -- and is not within some subprogram.
1170 if In_Preelaborated_Unit
1171 and then not In_Subprogram_Or_Concurrent_Unit
1173 -- Check for default initialized variable case. Note that in
1174 -- accordance with (RM B.1(24)) imported objects are not subject to
1175 -- default initialization.
1176 -- If the initialization does not come from source and is an
1177 -- aggregate, it is a static initialization that replaces an
1178 -- implicit call, and must be treated as such.
1181 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1185 elsif Is_Imported (Id) then
1190 Ent : Entity_Id := T;
1193 -- An array whose component type is a record with nonstatic
1194 -- default expressions is a violation, so we get the array's
1197 if Is_Array_Type (Ent) then
1199 Comp_Type : Entity_Id;
1202 Comp_Type := Component_Type (Ent);
1203 while Is_Array_Type (Comp_Type) loop
1204 Comp_Type := Component_Type (Comp_Type);
1211 -- Object decl. that is of record type and has no default expr.
1212 -- should check if there is any non-static default expression
1213 -- in component decl. of the record type decl.
1215 if Is_Record_Type (Ent) then
1216 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1217 Check_Non_Static_Default_Expr
1218 (Type_Definition (Parent (Ent)), N);
1220 elsif Nkind (Odf) = N_Subtype_Indication
1221 and then not Is_Array_Type (T)
1222 and then not Is_Private_Type (T)
1224 Check_Non_Static_Default_Expr (Type_Definition
1225 (Parent (Entity (Subtype_Mark (Odf)))), N);
1229 -- Check for invalid use of private object. Note that Ada 2005
1230 -- AI-161 modifies the rules for Ada 2005, including the use of
1231 -- the new pragma Preelaborable_Initialization.
1233 if Is_Private_Type (Ent)
1234 or else Depends_On_Private (Ent)
1236 -- Case where type has preelaborable initialization which
1237 -- means that a pragma Preelaborable_Initialization was
1238 -- given for the private type.
1240 if Relaxed_RM_Semantics then
1242 -- In relaxed mode, do not issue these messages, this
1243 -- is basically similar to the GNAT_Mode test below.
1247 elsif Has_Preelaborable_Initialization (Ent) then
1249 -- But for the predefined units, we will ignore this
1250 -- status unless we are in Ada 2005 mode since we want
1251 -- Ada 95 compatible behavior, in which the entities
1252 -- marked with this pragma in the predefined library are
1253 -- not treated specially.
1255 if Ada_Version < Ada_2005 then
1257 ("private object not allowed in preelaborated unit",
1259 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1262 -- Type does not have preelaborable initialization
1265 -- We allow this when compiling in GNAT mode to make life
1266 -- easier for some cases where it would otherwise be hard
1267 -- to be exactly valid Ada.
1269 if not GNAT_Mode then
1271 ("private object not allowed in preelaborated unit",
1274 -- Add a message if it would help to provide a pragma
1275 -- Preelaborable_Initialization on the type of the
1276 -- object (which would make it legal in Ada 2005).
1278 -- If the type has no full view (generic type, or
1279 -- previous error), the warning does not apply.
1281 if Is_Private_Type (Ent)
1282 and then Present (Full_View (Ent))
1284 Has_Preelaborable_Initialization (Full_View (Ent))
1286 Error_Msg_Sloc := Sloc (Ent);
1288 if Ada_Version >= Ada_2005 then
1290 ("\would be legal if pragma Preelaborable_" &
1291 "Initialization given for & #", N, Ent);
1294 ("\would be legal in Ada 2005 if pragma " &
1295 "Preelaborable_Initialization given for & #",
1302 -- Access to Task or Protected type
1304 elsif Is_Entity_Name (Odf)
1305 and then Present (Etype (Odf))
1306 and then Is_Access_Type (Etype (Odf))
1308 Ent := Designated_Type (Etype (Odf));
1310 elsif Is_Entity_Name (Odf) then
1311 Ent := Entity (Odf);
1313 elsif Nkind (Odf) = N_Subtype_Indication then
1314 Ent := Etype (Subtype_Mark (Odf));
1316 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1317 Ent := Component_Type (T);
1320 if Is_Task_Type (Ent)
1321 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1324 ("concurrent object not allowed in preelaborated unit",
1331 -- Non-static discriminants not allowed in preelaborated unit.
1332 -- Objects of a controlled type with a user-defined Initialize
1333 -- are forbidden as well.
1335 if Is_Record_Type (Etype (Id)) then
1337 ET : constant Entity_Id := Etype (Id);
1338 EE : constant Entity_Id := Etype (Etype (Id));
1342 if Has_Discriminants (ET) and then Present (EE) then
1345 if Nkind (PEE) = N_Full_Type_Declaration
1346 and then not Static_Discriminant_Expr
1347 (Discriminant_Specifications (PEE))
1350 ("non-static discriminant in preelaborated unit",
1355 -- For controlled type or type with controlled component, check
1356 -- preelaboration flag, as there may be a non-null Initialize
1357 -- primitive. For language versions earlier than Ada 2005,
1358 -- there is no notion of preelaborable initialization, and
1359 -- Validate_Controlled_Object is used to enforce rules for
1360 -- controlled objects.
1362 if (Is_Controlled (ET) or else Has_Controlled_Component (ET))
1363 and then Ada_Version >= Ada_2005
1364 and then not Has_Preelaborable_Initialization (ET)
1367 ("controlled type& does not have"
1368 & " preelaborable initialization", N, ET);
1375 -- A pure library_item must not contain the declaration of any variable
1376 -- except within a subprogram, generic subprogram, task unit, or
1377 -- protected unit (RM 10.2.1(16)).
1379 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1380 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1382 elsif not In_Private_Part (Id) then
1384 -- The visible part of an RCI library unit must not contain the
1385 -- declaration of a variable (RM E.1.3(9)).
1387 if In_RCI_Declaration then
1388 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1390 -- The visible part of a Shared Passive library unit must not contain
1391 -- the declaration of a variable (RM E.2.2(7)).
1393 elsif In_RT_Declaration then
1395 ("visible variable not allowed in remote types unit", N);
1398 end Validate_Object_Declaration;
1400 -----------------------------
1401 -- Validate_RACW_Primitive --
1402 -----------------------------
1404 procedure Validate_RACW_Primitive
1408 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id);
1409 -- Diagnose illegality on N. If RACW is present, report the error on it
1410 -- rather than on N.
1412 -------------------------
1413 -- Illegal_Remote_Subp --
1414 -------------------------
1416 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id) is
1418 if Present (RACW) then
1419 if not Error_Posted (RACW) then
1421 ("illegal remote access to class-wide type&", RACW);
1424 Error_Msg_Sloc := Sloc (N);
1425 Error_Msg_NE ("\\" & Msg & " in primitive& #", RACW, Subp);
1428 Error_Msg_NE (Msg & " in remote subprogram&", N, Subp);
1430 end Illegal_Remote_Subp;
1434 Param_Spec : Node_Id;
1435 Param_Type : Entity_Id;
1437 -- Start of processing for Validate_RACW_Primitive
1440 -- Check return type
1442 if Ekind (Subp) = E_Function then
1443 Rtyp := Etype (Subp);
1445 -- AI05-0101 (Binding Interpretation): The result type of a remote
1446 -- function must either support external streaming or be a
1447 -- controlling access result type.
1449 if Has_Controlling_Result (Subp) then
1452 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1453 Illegal_Remote_Subp ("anonymous access result", Rtyp);
1455 elsif Is_Limited_Type (Rtyp) then
1456 if No (TSS (Rtyp, TSS_Stream_Read))
1458 No (TSS (Rtyp, TSS_Stream_Write))
1461 ("limited return type must have Read and Write attributes",
1463 Explain_Limited_Type (Rtyp, Parent (Subp));
1466 -- Check that the return type supports external streaming
1468 elsif No_External_Streaming (Rtyp)
1469 and then not Error_Posted (Rtyp)
1471 Illegal_Remote_Subp ("return type containing non-remote access "
1472 & "must have Read and Write attributes",
1477 Param := First_Formal (Subp);
1478 while Present (Param) loop
1480 -- Now find out if this parameter is a controlling parameter
1482 Param_Spec := Parent (Param);
1483 Param_Type := Etype (Param);
1485 if Is_Controlling_Formal (Param) then
1487 -- It is a controlling parameter, so specific checks below do not
1492 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1493 E_Anonymous_Access_Subprogram_Type)
1495 -- From RM E.2.2(14), no anonymous access parameter other than
1496 -- controlling ones may be used (because an anonymous access
1497 -- type never supports external streaming).
1500 ("non-controlling access parameter", Param_Spec);
1502 elsif No_External_Streaming (Param_Type)
1503 and then not Error_Posted (Param_Type)
1505 Illegal_Remote_Subp ("formal parameter in remote subprogram must "
1506 & "support external streaming", Param_Spec);
1509 -- Check next parameter in this subprogram
1511 Next_Formal (Param);
1513 end Validate_RACW_Primitive;
1515 ------------------------------
1516 -- Validate_RACW_Primitives --
1517 ------------------------------
1519 procedure Validate_RACW_Primitives (T : Entity_Id) is
1520 Desig_Type : Entity_Id;
1521 Primitive_Subprograms : Elist_Id;
1522 Subprogram_Elmt : Elmt_Id;
1523 Subprogram : Entity_Id;
1526 Desig_Type := Etype (Designated_Type (T));
1528 -- No action needed for concurrent types
1530 if Is_Concurrent_Type (Desig_Type) then
1534 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1536 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1537 while Subprogram_Elmt /= No_Elmt loop
1538 Subprogram := Node (Subprogram_Elmt);
1540 if Is_Predefined_Dispatching_Operation (Subprogram)
1541 or else Is_Hidden (Subprogram)
1543 goto Next_Subprogram;
1546 Validate_RACW_Primitive (Subp => Subprogram, RACW => T);
1549 Next_Elmt (Subprogram_Elmt);
1551 end Validate_RACW_Primitives;
1553 -------------------------------
1554 -- Validate_RCI_Declarations --
1555 -------------------------------
1557 procedure Validate_RCI_Declarations (P : Entity_Id) is
1561 E := First_Entity (P);
1562 while Present (E) loop
1563 if Comes_From_Source (E) then
1564 if Is_Limited_Type (E) then
1566 ("limited type not allowed in rci unit", Parent (E));
1567 Explain_Limited_Type (E, Parent (E));
1569 elsif Ekind_In (E, E_Generic_Function,
1571 E_Generic_Procedure)
1573 Error_Msg_N ("generic declaration not allowed in rci unit",
1576 elsif (Ekind (E) = E_Function or else Ekind (E) = E_Procedure)
1577 and then Has_Pragma_Inline (E)
1580 ("inlined subprogram not allowed in rci unit", Parent (E));
1582 -- Inner packages that are renamings need not be checked. Generic
1583 -- RCI packages are subject to the checks, but entities that come
1584 -- from formal packages are not part of the visible declarations
1585 -- of the package and are not checked.
1587 elsif Ekind (E) = E_Package then
1588 if Present (Renamed_Entity (E)) then
1591 elsif Ekind (P) /= E_Generic_Package
1592 or else List_Containing (Unit_Declaration_Node (E)) /=
1593 Generic_Formal_Declarations
1594 (Unit_Declaration_Node (P))
1596 Validate_RCI_Declarations (E);
1603 end Validate_RCI_Declarations;
1605 -----------------------------------------
1606 -- Validate_RCI_Subprogram_Declaration --
1607 -----------------------------------------
1609 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1610 K : constant Node_Kind := Nkind (N);
1612 Id : constant Entity_Id := Defining_Entity (N);
1613 Param_Spec : Node_Id;
1614 Param_Type : Entity_Id;
1615 Error_Node : Node_Id := N;
1618 -- This procedure enforces rules on subprogram and access to subprogram
1619 -- declarations in RCI units. These rules do not apply to expander
1620 -- generated routines, which are not remote subprograms. It is called:
1622 -- 1. from Analyze_Subprogram_Declaration.
1623 -- 2. from Validate_Object_Declaration (access to subprogram).
1625 if not (Comes_From_Source (N)
1626 and then In_RCI_Declaration
1627 and then not In_Private_Part (Scope (Id)))
1632 if K = N_Subprogram_Declaration then
1633 Profile := Parameter_Specifications (Specification (N));
1636 pragma Assert (K = N_Object_Declaration);
1638 -- The above assertion is dubious, the visible declarations of an
1639 -- RCI unit never contain an object declaration, this should be an
1640 -- ACCESS-to-object declaration???
1642 if Nkind (Id) = N_Defining_Identifier
1643 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1644 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1647 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1653 -- Iterate through the parameter specification list, checking that
1654 -- no access parameter and no limited type parameter in the list.
1657 if Present (Profile) then
1658 Param_Spec := First (Profile);
1659 while Present (Param_Spec) loop
1660 Param_Type := Etype (Defining_Identifier (Param_Spec));
1662 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1663 if K = N_Subprogram_Declaration then
1664 Error_Node := Param_Spec;
1667 -- Report error only if declaration is in source program
1669 if Comes_From_Source (Id) then
1671 ("subprogram in 'R'C'I unit cannot have access parameter",
1675 -- For a limited private type parameter, we check only the private
1676 -- declaration and ignore full type declaration, unless this is
1677 -- the only declaration for the type, e.g., as a limited record.
1679 elsif No_External_Streaming (Param_Type) then
1680 if K = N_Subprogram_Declaration then
1681 Error_Node := Param_Spec;
1685 ("formal of remote subprogram& "
1686 & "must support external streaming",
1688 if Is_Limited_Type (Param_Type) then
1689 Explain_Limited_Type (Param_Type, Error_Node);
1697 if Ekind (Id) = E_Function
1698 and then Ekind (Etype (Id)) = E_Anonymous_Access_Type
1699 and then Comes_From_Source (Id)
1702 ("function in 'R'C'I unit cannot have access result",
1705 end Validate_RCI_Subprogram_Declaration;
1707 ----------------------------------------------------
1708 -- Validate_Remote_Access_Object_Type_Declaration --
1709 ----------------------------------------------------
1711 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1712 Direct_Designated_Type : Entity_Id;
1713 Desig_Type : Entity_Id;
1716 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1717 -- the given node is N_Access_To_Object_Definition.
1719 if not Comes_From_Source (T)
1720 or else (not In_RCI_Declaration and then not In_RT_Declaration)
1725 -- An access definition in the private part of a package is not a
1726 -- remote access type. Restrictions related to external streaming
1727 -- support for non-remote access types are enforced elsewhere. Note
1728 -- that In_Private_Part is never set on type entities: check flag
1729 -- on enclosing scope.
1731 if In_Private_Part (Scope (T)) then
1735 -- Check RCI or RT unit type declaration. It may not contain the
1736 -- declaration of an access-to-object type unless it is a general access
1737 -- type that designates a class-wide limited private type or subtype.
1738 -- There are also constraints on the primitive subprograms of the
1739 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1741 if Ekind (T) /= E_General_Access_Type
1742 or else not Is_Class_Wide_Type (Designated_Type (T))
1744 if In_RCI_Declaration then
1746 ("error in access type in Remote_Call_Interface unit", T);
1749 ("error in access type in Remote_Types unit", T);
1752 Error_Msg_N ("\must be general access to class-wide type", T);
1756 Direct_Designated_Type := Designated_Type (T);
1757 Desig_Type := Etype (Direct_Designated_Type);
1759 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type???
1761 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1763 ("error in designated type of remote access to class-wide type", T);
1765 ("\must be tagged limited private or private extension", T);
1768 end Validate_Remote_Access_Object_Type_Declaration;
1770 -----------------------------------------------
1771 -- Validate_Remote_Access_To_Class_Wide_Type --
1772 -----------------------------------------------
1774 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1775 K : constant Node_Kind := Nkind (N);
1776 PK : constant Node_Kind := Nkind (Parent (N));
1780 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1781 -- of class-wide limited private types.
1783 -- Storage_Pool and Storage_Size are not defined for such types
1785 -- The expected type of allocator must not be such a type.
1787 -- The actual parameter of generic instantiation must not be such a
1788 -- type if the formal parameter is of an access type.
1790 -- On entry, there are several cases:
1792 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1793 -- either Storage_Pool or Storage_Size.
1795 -- 2. called from exp_ch4 Expand_N_Allocator
1797 -- 3. called from sem_ch4 Analyze_Explicit_Dereference
1799 -- 4. called from sem_res Resolve_Actuals
1801 if K = N_Attribute_Reference then
1802 E := Etype (Prefix (N));
1804 if Is_Remote_Access_To_Class_Wide_Type (E) then
1805 Error_Msg_N ("incorrect attribute of remote operand", N);
1809 elsif K = N_Allocator then
1812 if Is_Remote_Access_To_Class_Wide_Type (E) then
1813 Error_Msg_N ("incorrect expected remote type of allocator", N);
1817 -- This subprogram also enforces the checks in E.2.2(13). A value of
1818 -- such type must not be dereferenced unless as controlling operand of
1819 -- a dispatching call. Explicit dereferences not coming from source are
1820 -- exempted from this checking because the expander produces them in
1821 -- some cases (such as for tag checks on dispatching calls with multiple
1822 -- controlling operands). However we do check in the case of an implicit
1823 -- dereference that is expanded to an explicit dereference (hence the
1824 -- test of whether Original_Node (N) comes from source).
1826 elsif K = N_Explicit_Dereference
1827 and then Comes_From_Source (Original_Node (N))
1829 E := Etype (Prefix (N));
1831 -- If the class-wide type is not a remote one, the restrictions
1834 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1838 -- If we have a true dereference that comes from source and that
1839 -- is a controlling argument for a dispatching call, accept it.
1841 if Is_Actual_Parameter (N) and then Is_Controlling_Actual (N) then
1845 -- If we are just within a procedure or function call and the
1846 -- dereference has not been analyzed, return because this procedure
1847 -- will be called again from sem_res Resolve_Actuals. The same can
1848 -- apply in the case of dereference that is the prefix of a selected
1849 -- component, which can be a call given in prefixed form.
1851 if (Is_Actual_Parameter (N) or else PK = N_Selected_Component)
1852 and then not Analyzed (N)
1857 -- We must allow expanded code to generate a reference to the tag of
1858 -- the designated object (may be either the actual tag, or the stub
1859 -- tag in the case of a remote object).
1861 if PK = N_Selected_Component
1862 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1868 ("invalid dereference of a remote access-to-class-wide value", N);
1870 end Validate_Remote_Access_To_Class_Wide_Type;
1872 ------------------------------------------
1873 -- Validate_Remote_Type_Type_Conversion --
1874 ------------------------------------------
1876 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1877 S : constant Entity_Id := Etype (N);
1878 E : constant Entity_Id := Etype (Expression (N));
1881 -- This test is required in the case where a conversion appears inside a
1882 -- normal package, it does not necessarily have to be inside an RCI,
1883 -- Remote_Types unit (RM E.2.2(9,12)).
1885 if Is_Remote_Access_To_Subprogram_Type (E)
1886 and then not Is_Remote_Access_To_Subprogram_Type (S)
1889 ("incorrect conversion of remote operand to local type", N);
1892 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1893 and then Is_Remote_Access_To_Subprogram_Type (S)
1896 ("incorrect conversion of local operand to remote type", N);
1899 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1900 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1903 ("incorrect conversion of remote operand to local type", N);
1907 -- If a local access type is converted into a RACW type, then the
1908 -- current unit has a pointer that may now be exported to another
1911 if Is_Remote_Access_To_Class_Wide_Type (S)
1912 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1914 Set_Has_RACW (Current_Sem_Unit);
1916 end Validate_Remote_Type_Type_Conversion;
1918 -------------------------------
1919 -- Validate_RT_RAT_Component --
1920 -------------------------------
1922 procedure Validate_RT_RAT_Component (N : Node_Id) is
1923 Spec : constant Node_Id := Specification (N);
1924 Name_U : constant Entity_Id := Defining_Entity (Spec);
1927 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1929 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean;
1930 -- True if any stream attribute is available for Typ
1932 ---------------------------------
1933 -- Stream_Attributes_Available --
1934 ---------------------------------
1936 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean
1939 return Stream_Attribute_Available (Typ, TSS_Stream_Read)
1941 Stream_Attribute_Available (Typ, TSS_Stream_Write)
1943 Stream_Attribute_Available (Typ, TSS_Stream_Input)
1945 Stream_Attribute_Available (Typ, TSS_Stream_Output);
1946 end Stream_Attributes_Available;
1948 -- Start of processing for Validate_RT_RAT_Component
1951 if not Is_Remote_Types (Name_U) then
1955 Typ := First_Entity (Name_U);
1956 while Present (Typ) and then Typ /= First_Priv_Ent loop
1957 U_Typ := Underlying_Type (Base_Type (Typ));
1963 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1965 -- Check that the type can be meaningfully transmitted to another
1966 -- partition (E.2.2(8)).
1968 if (Ada_Version < Ada_2005 and then Has_Non_Remote_Access (U_Typ))
1969 or else (Stream_Attributes_Available (Typ)
1970 and then No_External_Streaming (U_Typ))
1972 if Is_Non_Remote_Access_Type (Typ) then
1973 Error_Msg_N ("error in non-remote access type", U_Typ);
1976 ("error in record type containing a component of a " &
1977 "non-remote access type", U_Typ);
1980 if Ada_Version >= Ada_2005 then
1982 ("\must have visible Read and Write attribute " &
1983 "definition clauses (RM E.2.2(8))", U_Typ);
1986 ("\must have Read and Write attribute " &
1987 "definition clauses (RM E.2.2(8))", U_Typ);
1994 end Validate_RT_RAT_Component;
1996 -----------------------------------------
1997 -- Validate_SP_Access_Object_Type_Decl --
1998 -----------------------------------------
2000 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2001 Direct_Designated_Type : Entity_Id;
2003 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2004 -- Return true if the protected type designated by T has entry
2007 ----------------------------
2008 -- Has_Entry_Declarations --
2009 ----------------------------
2011 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2015 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2016 Ety := First_Entity (E);
2017 while Present (Ety) loop
2018 if Ekind (Ety) = E_Entry then
2027 end Has_Entry_Declarations;
2029 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2032 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2033 -- Nkind of the given entity is N_Access_To_Object_Definition.
2035 if not Comes_From_Source (T)
2036 or else not In_Shared_Passive_Unit
2037 or else In_Subprogram_Task_Protected_Unit
2042 -- Check Shared Passive unit. It should not contain the declaration
2043 -- of an access-to-object type whose designated type is a class-wide
2044 -- type, task type or protected type with entry (RM E.2.1(7)).
2046 Direct_Designated_Type := Designated_Type (T);
2048 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2050 ("invalid access-to-class-wide type in shared passive unit", T);
2053 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2055 ("invalid access-to-task type in shared passive unit", T);
2058 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2059 and then Has_Entry_Declarations (Direct_Designated_Type)
2062 ("invalid access-to-protected type in shared passive unit", T);
2065 end Validate_SP_Access_Object_Type_Decl;
2067 ---------------------------------
2068 -- Validate_Static_Object_Name --
2069 ---------------------------------
2071 procedure Validate_Static_Object_Name (N : Node_Id) is
2075 function Is_Primary (N : Node_Id) return Boolean;
2076 -- Determine whether node is syntactically a primary in an expression
2077 -- This function should probably be somewhere else ???
2079 -- Also it does not do what it says, e.g if N is a binary operator
2080 -- whose parent is a binary operator, Is_Primary returns True ???
2086 function Is_Primary (N : Node_Id) return Boolean is
2087 K : constant Node_Kind := Nkind (Parent (N));
2091 when N_Op | N_Membership_Test =>
2095 | N_Component_Association
2096 | N_Index_Or_Discriminant_Constraint =>
2099 when N_Attribute_Reference =>
2100 return Attribute_Name (Parent (N)) /= Name_Address
2101 and then Attribute_Name (Parent (N)) /= Name_Access
2102 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2104 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2106 when N_Indexed_Component =>
2107 return (N /= Prefix (Parent (N))
2108 or else Is_Primary (Parent (N)));
2110 when N_Qualified_Expression | N_Type_Conversion =>
2111 return Is_Primary (Parent (N));
2113 when N_Assignment_Statement | N_Object_Declaration =>
2114 return (N = Expression (Parent (N)));
2116 when N_Selected_Component =>
2117 return Is_Primary (Parent (N));
2124 -- Start of processing for Validate_Static_Object_Name
2127 if not In_Preelaborated_Unit
2128 or else not Comes_From_Source (N)
2129 or else In_Subprogram_Or_Concurrent_Unit
2130 or else Ekind (Current_Scope) = E_Block
2134 -- Filter out cases where primary is default in a component declaration,
2135 -- discriminant specification, or actual in a record type initialization
2138 -- Initialization call of internal types
2140 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2142 if Present (Parent (Parent (N)))
2143 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2148 if Nkind (Name (Parent (N))) = N_Identifier
2149 and then not Comes_From_Source (Entity (Name (Parent (N))))
2155 -- Error if the name is a primary in an expression. The parent must not
2156 -- be an operator, or a selected component or an indexed component that
2157 -- is itself a primary. Entities that are actuals do not need to be
2158 -- checked, because the call itself will be diagnosed.
2161 and then (not Inside_A_Generic
2162 or else Present (Enclosing_Generic_Body (N)))
2164 if Ekind (Entity (N)) = E_Variable
2165 or else Ekind (Entity (N)) in Formal_Object_Kind
2167 Flag_Non_Static_Expr
2168 ("non-static object name in preelaborated unit", N);
2170 -- Give an error for a reference to a nonstatic constant, unless the
2171 -- constant is in another GNAT library unit that is preelaborable.
2173 elsif Ekind (Entity (N)) = E_Constant
2174 and then not Is_Static_Expression (N)
2177 Val := Constant_Value (E);
2179 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2181 Enclosing_Comp_Unit_Node (N) /= Enclosing_Comp_Unit_Node (E)
2182 and then (Is_Preelaborated (Scope (E))
2183 or else Is_Pure (Scope (E))
2184 or else (Present (Renamed_Object (E))
2185 and then Is_Entity_Name (Renamed_Object (E))
2188 (Scope (Renamed_Object (E)))
2191 (Scope (Renamed_Object (E))))))
2195 -- If the value of the constant is a local variable that renames
2196 -- an aggregate, this is in itself legal. The aggregate may be
2197 -- expanded into a loop, but this does not affect preelaborability
2198 -- in itself. If some aggregate components are non-static, that is
2199 -- to say if they involve non static primaries, they will be
2200 -- flagged when analyzed.
2203 and then Is_Entity_Name (Val)
2204 and then Is_Array_Type (Etype (Val))
2205 and then not Comes_From_Source (Val)
2206 and then Nkind (Original_Node (Val)) = N_Aggregate
2210 -- This is the error case
2213 -- In GNAT mode or Relaxed RM Semantic mode, this is just a
2214 -- warning, to allow it to be judiciously turned off.
2215 -- Otherwise it is a real error.
2217 if GNAT_Mode or Relaxed_RM_Semantics then
2219 ("??non-static constant in preelaborated unit", N);
2221 Flag_Non_Static_Expr
2222 ("non-static constant in preelaborated unit", N);
2227 end Validate_Static_Object_Name;