1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Fname; use Fname;
34 with Nlists; use Nlists;
37 with Sem_Eval; use Sem_Eval;
38 with Sem_Util; use Sem_Util;
39 with Sinfo; use Sinfo;
40 with Snames; use Snames;
41 with Stand; use Stand;
43 package body Sem_Cat is
45 -----------------------
46 -- Local Subprograms --
47 -----------------------
49 procedure Check_Categorization_Dependencies
50 (Unit_Entity : Entity_Id;
51 Depended_Entity : Entity_Id;
53 Is_Subunit : Boolean);
54 -- This procedure checks that the categorization of a lib unit and that
55 -- of the depended unit satisfy dependency restrictions.
56 -- The depended_entity can be the entity in a with_clause item, in which
57 -- case Info_Node denotes that item. The depended_entity can also be the
58 -- parent unit of a child unit, in which case Info_Node is the declaration
59 -- of the child unit. The error message is posted on Info_Node, and is
60 -- specialized if Is_Subunit is true.
62 procedure Check_Non_Static_Default_Expr
65 -- Iterate through the component list of a record definition, check
66 -- that no component is declared with a nonstatic default value.
67 -- If a nonstatic default exists, report an error on Obj_Decl.
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a non-static default value.
72 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
73 -- Return True if the entity or one of its subcomponent is an access
74 -- type which does not have user-defined Read and Write attribute.
75 -- Additionally, in Ada 2005 mode, stream attributes are considered missing
76 -- if the attribute definition clause is not visible.
78 function In_RCI_Declaration (N : Node_Id) return Boolean;
79 -- Determines if a declaration is within the visible part of a Remote
80 -- Call Interface compilation unit, for semantic checking purposes only,
81 -- (returns false within an instance and within the package body).
83 function In_RT_Declaration return Boolean;
84 -- Determines if current scope is within a Remote Types compilation unit,
85 -- for semantic checking purposes.
87 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
88 -- Returns true if the entity is a type whose full view is a non-remote
89 -- access type, for the purpose of enforcing E.2.2(8) rules.
91 function In_Shared_Passive_Unit return Boolean;
92 -- Determines if current scope is within a Shared Passive compilation unit
94 function Static_Discriminant_Expr (L : List_Id) return Boolean;
95 -- Iterate through the list of discriminants to check if any of them
96 -- contains non-static default expression, which is a violation in
97 -- a preelaborated library unit.
99 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
100 -- Check validity of declaration if RCI or RT unit. It should not contain
101 -- the declaration of an access-to-object type unless it is a
102 -- general access type that designates a class-wide limited
103 -- private type. There are also constraints about the primitive
104 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
106 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean;
107 -- Return True if E is a limited private type, or if E is a private
108 -- extension of a type whose parent verifies this property (hence the
109 -- recursive keyword).
111 ---------------------------------------
112 -- Check_Categorization_Dependencies --
113 ---------------------------------------
115 procedure Check_Categorization_Dependencies
116 (Unit_Entity : Entity_Id;
117 Depended_Entity : Entity_Id;
119 Is_Subunit : Boolean)
121 N : constant Node_Id := Info_Node;
123 -- Here we define an enumeration type to represent categorization
124 -- types, ordered so that a unit with a given categorization can
125 -- only WITH units with lower or equal categorization type.
127 type Categorization is
131 Remote_Call_Interface,
135 Unit_Category : Categorization;
136 With_Category : Categorization;
138 function Get_Categorization (E : Entity_Id) return Categorization;
139 -- Check categorization flags from entity, and return in the form
140 -- of a corresponding enumeration value.
142 ------------------------
143 -- Get_Categorization --
144 ------------------------
146 function Get_Categorization (E : Entity_Id) return Categorization is
148 if Is_Preelaborated (E) then
149 return Preelaborated;
151 -- Ignore Pure specification if set by pragma Pure_Function
155 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
159 elsif Is_Shared_Passive (E) then
160 return Shared_Passive;
162 elsif Is_Remote_Types (E) then
165 elsif Is_Remote_Call_Interface (E) then
166 return Remote_Call_Interface;
171 end Get_Categorization;
173 -- Start of processing for Check_Categorization_Dependencies
176 -- Intrinsic subprograms are preelaborated, so do not impose any
177 -- categorization dependencies.
179 if Is_Intrinsic_Subprogram (Depended_Entity) then
183 Unit_Category := Get_Categorization (Unit_Entity);
184 With_Category := Get_Categorization (Depended_Entity);
186 -- These messages are wanings in GNAT mode, to allow it to be
187 -- judiciously turned off. Otherwise it is a real error.
189 Error_Msg_Warn := GNAT_Mode;
191 -- Check for possible error
193 if With_Category > Unit_Category then
195 -- Special case: Remote_Types and Remote_Call_Interface are allowed
196 -- to be with'ed in package body.
198 if (Unit_Category = Remote_Types
199 or else Unit_Category = Remote_Call_Interface)
200 and then In_Package_Body (Unit_Entity)
204 -- Here we have an error
209 ("<subunit cannot depend on& " &
210 "(parent has wrong categorization)", N, Depended_Entity);
214 ("<cannot depend on& " &
215 "(wrong categorization)", N, Depended_Entity);
218 -- Add further explanation for common cases
220 case Unit_Category is
223 ("\<pure unit cannot depend on non-pure unit",
226 when Preelaborated =>
228 ("\<preelaborated unit cannot depend on " &
229 "non-preelaborated unit",
237 end Check_Categorization_Dependencies;
239 -----------------------------------
240 -- Check_Non_Static_Default_Expr --
241 -----------------------------------
243 procedure Check_Non_Static_Default_Expr
248 Component_Decl : Node_Id;
251 if Nkind (Type_Def) = N_Derived_Type_Definition then
252 Recdef := Record_Extension_Part (Type_Def);
262 -- Check that component declarations do not involve:
264 -- a. a non-static default expression, where the object is
265 -- declared to be default initialized.
267 -- b. a dynamic Itype (discriminants and constraints)
269 if Null_Present (Recdef) then
272 Component_Decl := First (Component_Items (Component_List (Recdef)));
275 while Present (Component_Decl)
276 and then Nkind (Component_Decl) = N_Component_Declaration
278 if Present (Expression (Component_Decl))
279 and then Nkind (Expression (Component_Decl)) /= N_Null
280 and then not Is_Static_Expression (Expression (Component_Decl))
282 Error_Msg_Sloc := Sloc (Component_Decl);
284 ("object in preelaborated unit has non-static default#",
287 -- Fix this later ???
289 -- elsif Has_Dynamic_Itype (Component_Decl) then
291 -- ("dynamic type discriminant," &
292 -- " constraint in preelaborated unit",
296 Next (Component_Decl);
298 end Check_Non_Static_Default_Expr;
300 -------------------------------------
301 -- Has_Stream_Attribute_Definition --
302 -------------------------------------
304 function Has_Stream_Attribute_Definition
305 (Typ : Entity_Id; Nam : TSS_Name_Type) return Boolean
309 -- We start from the declaration node and then loop until the end of
310 -- the list until we find the requested attribute definition clause.
311 -- In Ada 2005 mode, clauses are ignored if they are not currently
312 -- visible (this is tested using the corresponding Entity, which is
313 -- inserted by the expander at the point where the clause occurs).
315 Rep_Item := First_Rep_Item (Typ);
316 while Present (Rep_Item) loop
317 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
318 case Chars (Rep_Item) is
320 exit when Nam = TSS_Stream_Read;
323 exit when Nam = TSS_Stream_Write;
326 exit when Nam = TSS_Stream_Input;
329 exit when Nam = TSS_Stream_Output;
337 Next_Rep_Item (Rep_Item);
340 return Present (Rep_Item)
341 and then (Ada_Version < Ada_05
342 or else not Is_Hidden (Entity (Rep_Item)));
343 end Has_Stream_Attribute_Definition;
345 ---------------------------
346 -- In_Preelaborated_Unit --
347 ---------------------------
349 function In_Preelaborated_Unit return Boolean is
350 Unit_Entity : constant Entity_Id := Current_Scope;
351 Unit_Kind : constant Node_Kind :=
352 Nkind (Unit (Cunit (Current_Sem_Unit)));
355 -- There are no constraints on body of remote_call_interface or
356 -- remote_types packages.
358 return (Unit_Entity /= Standard_Standard)
359 and then (Is_Preelaborated (Unit_Entity)
360 or else Is_Pure (Unit_Entity)
361 or else Is_Shared_Passive (Unit_Entity)
363 ((Is_Remote_Types (Unit_Entity)
364 or else Is_Remote_Call_Interface (Unit_Entity))
365 and then Ekind (Unit_Entity) = E_Package
366 and then Unit_Kind /= N_Package_Body
367 and then not In_Package_Body (Unit_Entity)
368 and then not In_Instance));
369 end In_Preelaborated_Unit;
375 function In_Pure_Unit return Boolean is
377 return Is_Pure (Current_Scope);
380 ------------------------
381 -- In_RCI_Declaration --
382 ------------------------
384 function In_RCI_Declaration (N : Node_Id) return Boolean is
385 Unit_Entity : constant Entity_Id := Current_Scope;
386 Unit_Kind : constant Node_Kind :=
387 Nkind (Unit (Cunit (Current_Sem_Unit)));
390 -- There are no restrictions on the private part or body
393 return Is_Remote_Call_Interface (Unit_Entity)
394 and then (Ekind (Unit_Entity) = E_Package
395 or else Ekind (Unit_Entity) = E_Generic_Package)
396 and then Unit_Kind /= N_Package_Body
397 and then List_Containing (N) =
399 (Specification (Unit_Declaration_Node (Unit_Entity)))
400 and then not In_Package_Body (Unit_Entity)
401 and then not In_Instance;
402 end In_RCI_Declaration;
404 -----------------------
405 -- In_RT_Declaration --
406 -----------------------
408 function In_RT_Declaration return Boolean is
409 Unit_Entity : constant Entity_Id := Current_Scope;
410 Unit_Kind : constant Node_Kind :=
411 Nkind (Unit (Cunit (Current_Sem_Unit)));
414 -- There are no restrictions on the body of a Remote Types unit
416 return Is_Remote_Types (Unit_Entity)
417 and then (Ekind (Unit_Entity) = E_Package
418 or else Ekind (Unit_Entity) = E_Generic_Package)
419 and then Unit_Kind /= N_Package_Body
420 and then not In_Package_Body (Unit_Entity)
421 and then not In_Instance;
422 end In_RT_Declaration;
424 ----------------------------
425 -- In_Shared_Passive_Unit --
426 ----------------------------
428 function In_Shared_Passive_Unit return Boolean is
429 Unit_Entity : constant Entity_Id := Current_Scope;
432 return Is_Shared_Passive (Unit_Entity);
433 end In_Shared_Passive_Unit;
435 ---------------------------------------
436 -- In_Subprogram_Task_Protected_Unit --
437 ---------------------------------------
439 function In_Subprogram_Task_Protected_Unit return Boolean is
443 -- The following is to verify that a declaration is inside
444 -- subprogram, generic subprogram, task unit, protected unit.
445 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
447 -- Use scope chain to check successively outer scopes
453 Is_Generic_Subprogram (E)
455 Is_Concurrent_Type (E)
459 elsif E = Standard_Standard then
465 end In_Subprogram_Task_Protected_Unit;
467 -------------------------------
468 -- Is_Non_Remote_Access_Type --
469 -------------------------------
471 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
472 U_E : constant Entity_Id := Underlying_Type (E);
476 -- This case arises for the case of a generic formal type, in which
477 -- case E.2.2(8) rules will be enforced at instantiation time.
482 return Is_Access_Type (U_E)
483 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
484 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
485 end Is_Non_Remote_Access_Type;
487 ------------------------------------
488 -- Is_Recursively_Limited_Private --
489 ------------------------------------
491 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
492 P : constant Node_Id := Parent (E);
495 if Nkind (P) = N_Private_Type_Declaration
496 and then Is_Limited_Record (E)
499 elsif Nkind (P) = N_Private_Extension_Declaration then
500 return Is_Recursively_Limited_Private (Etype (E));
501 elsif Nkind (P) = N_Formal_Type_Declaration
502 and then Ekind (E) = E_Record_Type_With_Private
503 and then Is_Generic_Type (E)
504 and then Is_Limited_Record (E)
510 end Is_Recursively_Limited_Private;
512 ----------------------------------
513 -- Missing_Read_Write_Attribute --
514 ----------------------------------
516 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
517 Component : Entity_Id;
518 Component_Type : Entity_Id;
519 U_E : constant Entity_Id := Underlying_Type (E);
521 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
522 -- Return True if entity has visible attribute definition clauses for
523 -- Read and Write attributes.
525 -------------------------------
526 -- Has_Read_Write_Attributes --
527 -------------------------------
529 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
532 and then Has_Stream_Attribute_Definition (E, TSS_Stream_Read)
533 and then Has_Stream_Attribute_Definition (E, TSS_Stream_Write);
534 end Has_Read_Write_Attributes;
536 -- Start of processing for Missing_Read_Write_Attributes
542 elsif Has_Read_Write_Attributes (E)
543 or else Has_Read_Write_Attributes (U_E)
547 elsif Is_Non_Remote_Access_Type (U_E) then
551 if Is_Record_Type (U_E) then
552 Component := First_Entity (U_E);
553 while Present (Component) loop
554 if not Is_Tag (Component) then
555 Component_Type := Etype (Component);
557 if Missing_Read_Write_Attributes (Component_Type) then
562 Next_Entity (Component);
567 end Missing_Read_Write_Attributes;
569 -------------------------------------
570 -- Set_Categorization_From_Pragmas --
571 -------------------------------------
573 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
574 P : constant Node_Id := Parent (N);
575 S : constant Entity_Id := Current_Scope;
577 procedure Set_Parents (Visibility : Boolean);
578 -- If this is a child instance, the parents are not immediately
579 -- visible during analysis. Make them momentarily visible so that
580 -- the argument of the pragma can be resolved properly, and reset
587 procedure Set_Parents (Visibility : Boolean) is
591 while Present (Par) and then Par /= Standard_Standard loop
592 Set_Is_Immediately_Visible (Par, Visibility);
597 -- Start of processing for Set_Categorization_From_Pragmas
600 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
601 -- The purpose is to set categorization flags before analyzing the
602 -- unit itself, so as to diagnose violations of categorization as
603 -- we process each declaration, even though the pragma appears after
606 if Nkind (P) /= N_Compilation_Unit then
615 and then Is_Generic_Instance (S)
620 PN := First (Pragmas_After (Aux_Decls_Node (P)));
621 while Present (PN) loop
623 -- Skip implicit types that may have been introduced by
624 -- previous analysis.
626 if Nkind (PN) = N_Pragma then
628 case Get_Pragma_Id (Chars (PN)) is
629 when Pragma_All_Calls_Remote |
630 Pragma_Preelaborate |
632 Pragma_Remote_Call_Interface |
633 Pragma_Remote_Types |
634 Pragma_Shared_Passive => Analyze (PN);
643 and then Is_Generic_Instance (S)
648 end Set_Categorization_From_Pragmas;
650 -----------------------------------
651 -- Set_Categorization_From_Scope --
652 -----------------------------------
654 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
655 Declaration : Node_Id := Empty;
656 Specification : Node_Id := Empty;
660 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
662 if not Is_Remote_Call_Interface (E) then
663 if Ekind (E) in Subprogram_Kind then
664 Declaration := Unit_Declaration_Node (E);
667 or else Nkind (Declaration) = N_Subprogram_Body
668 or else Nkind (Declaration) = N_Subprogram_Renaming_Declaration
670 Specification := Corresponding_Spec (Declaration);
674 -- A subprogram body or renaming-as-body is a remote call
675 -- interface if it serves as the completion of a subprogram
676 -- declaration that is a remote call interface.
678 if Nkind (Specification) in N_Entity then
679 Set_Is_Remote_Call_Interface
680 (E, Is_Remote_Call_Interface (Specification));
682 -- A subprogram declaration is a remote call interface when it is
683 -- declared within the visible part of, or declared by, a library
684 -- unit declaration that is a remote call interface.
687 Set_Is_Remote_Call_Interface
688 (E, Is_Remote_Call_Interface (Scop)
689 and then not (In_Private_Part (Scop)
690 or else In_Package_Body (Scop)));
694 Set_Is_Remote_Types (E, Is_Remote_Types (Scop));
695 end Set_Categorization_From_Scope;
697 ------------------------------
698 -- Static_Discriminant_Expr --
699 ------------------------------
701 -- We need to accomodate a Why_Not_Static call somehow here ???
703 function Static_Discriminant_Expr (L : List_Id) return Boolean is
704 Discriminant_Spec : Node_Id;
707 Discriminant_Spec := First (L);
708 while Present (Discriminant_Spec) loop
709 if Present (Expression (Discriminant_Spec))
710 and then not Is_Static_Expression (Expression (Discriminant_Spec))
715 Next (Discriminant_Spec);
719 end Static_Discriminant_Expr;
721 --------------------------------------
722 -- Validate_Access_Type_Declaration --
723 --------------------------------------
725 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
726 Def : constant Node_Id := Type_Definition (N);
731 -- Access to subprogram case
733 when N_Access_To_Subprogram_Definition =>
735 -- A pure library_item must not contain the declaration of a
736 -- named access type, except within a subprogram, generic
737 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
739 -- This test is skipped in Ada 2005 (see AI-366)
741 if Ada_Version < Ada_05
742 and then Comes_From_Source (T)
743 and then In_Pure_Unit
744 and then not In_Subprogram_Task_Protected_Unit
746 Error_Msg_N ("named access type not allowed in pure unit", T);
749 -- Access to object case
751 when N_Access_To_Object_Definition =>
752 if Comes_From_Source (T)
753 and then In_Pure_Unit
754 and then not In_Subprogram_Task_Protected_Unit
756 -- We can't give the message yet, since the type is not frozen
757 -- and in Ada 2005 mode, access types are allowed in pure units
758 -- if the type has no storage pool (see AI-366). So we set a
759 -- flag which will be checked at freeze time.
761 Set_Is_Pure_Unit_Access_Type (T);
764 -- Check for RCI or RT unit type declaration: declaration of an
765 -- access-to-object type is illegal unless it is a general access
766 -- type that designates a class-wide limited private type.
767 -- Note that constraints on the primitive subprograms of the
768 -- designated tagged type are not enforced here but in
769 -- Validate_RACW_Primitives, which is done separately because the
770 -- designated type might not be frozen (and therefore its
771 -- primitive operations might not be completely known) at the
772 -- point of the RACW declaration.
774 Validate_Remote_Access_Object_Type_Declaration (T);
776 -- Check for shared passive unit type declaration. It should
777 -- not contain the declaration of access to class wide type,
778 -- access to task type and access to protected type with entry.
780 Validate_SP_Access_Object_Type_Decl (T);
786 -- Set categorization flag from package on entity as well, to allow
787 -- easy checks later on for required validations of RCI or RT units.
788 -- This is only done for entities that are in the original source.
790 if Comes_From_Source (T)
791 and then not (In_Package_Body (Scope (T))
792 or else In_Private_Part (Scope (T)))
794 Set_Is_Remote_Call_Interface
795 (T, Is_Remote_Call_Interface (Scope (T)));
797 (T, Is_Remote_Types (Scope (T)));
799 end Validate_Access_Type_Declaration;
801 ----------------------------
802 -- Validate_Ancestor_Part --
803 ----------------------------
805 procedure Validate_Ancestor_Part (N : Node_Id) is
806 A : constant Node_Id := Ancestor_Part (N);
807 T : constant Entity_Id := Entity (A);
810 if In_Preelaborated_Unit
811 and then not In_Subprogram_Or_Concurrent_Unit
812 and then (not Inside_A_Generic
813 or else Present (Enclosing_Generic_Body (N)))
815 -- We relax the restriction of 10.2.1(9) within GNAT
816 -- units to allow packages such as Ada.Strings.Unbounded
817 -- to be implemented (i.p., Null_Unbounded_String).
818 -- (There are ACVC tests that check that the restriction
819 -- is enforced, but note that AI-161, once approved,
820 -- will relax the restriction prohibiting default-
821 -- initialized objects of private and controlled
824 if Is_Private_Type (T)
825 and then not Is_Internal_File_Name
826 (Unit_File_Name (Get_Source_Unit (N)))
829 ("private ancestor type not allowed in preelaborated unit", A);
831 elsif Is_Record_Type (T) then
832 if Nkind (Parent (T)) = N_Full_Type_Declaration then
833 Check_Non_Static_Default_Expr
834 (Type_Definition (Parent (T)), A);
838 end Validate_Ancestor_Part;
840 ----------------------------------------
841 -- Validate_Categorization_Dependency --
842 ----------------------------------------
844 procedure Validate_Categorization_Dependency
848 K : constant Node_Kind := Nkind (N);
849 P : Node_Id := Parent (N);
851 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
854 -- Only validate library units and subunits. For subunits, checks
855 -- concerning withed units apply to the parent compilation unit.
862 and then not Is_Compilation_Unit (U)
863 and then not Is_Child_Unit (U)
869 if Nkind (P) /= N_Compilation_Unit then
873 -- Body of RCI unit does not need validation
875 if Is_Remote_Call_Interface (E)
876 and then (Nkind (N) = N_Package_Body
877 or else Nkind (N) = N_Subprogram_Body)
882 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
886 Entity_Of_Withed : Entity_Id;
889 Item := First (Context_Items (P));
890 while Present (Item) loop
891 if Nkind (Item) = N_With_Clause
892 and then not (Implicit_With (Item)
893 or else Limited_Present (Item))
895 Entity_Of_Withed := Entity (Name (Item));
896 Check_Categorization_Dependencies
897 (U, Entity_Of_Withed, Item, Is_Subunit);
904 -- Child depends on parent; therefore parent should also be categorized
905 -- and satify the dependency hierarchy.
907 -- Check if N is a child spec
909 if (K in N_Generic_Declaration or else
910 K in N_Generic_Instantiation or else
911 K in N_Generic_Renaming_Declaration or else
912 K = N_Package_Declaration or else
913 K = N_Package_Renaming_Declaration or else
914 K = N_Subprogram_Declaration or else
915 K = N_Subprogram_Renaming_Declaration)
916 and then Present (Parent_Spec (N))
918 Check_Categorization_Dependencies (E, Scope (E), N, False);
920 -- Verify that public child of an RCI library unit must also be an
921 -- RCI library unit (RM E.2.3(15)).
923 if Is_Remote_Call_Interface (Scope (E))
924 and then not Private_Present (P)
925 and then not Is_Remote_Call_Interface (E)
927 Error_Msg_N ("public child of rci unit must also be rci unit", N);
930 end Validate_Categorization_Dependency;
932 --------------------------------
933 -- Validate_Controlled_Object --
934 --------------------------------
936 procedure Validate_Controlled_Object (E : Entity_Id) is
938 -- Don't need this check in Ada 2005 mode, where this is all taken
939 -- care of by the mechanism for Preelaborable Initialization.
941 if Ada_Version >= Ada_05 then
945 -- For now, never apply this check for internal GNAT units, since we
946 -- have a number of cases in the library where we are stuck with objects
947 -- of this type, and the RM requires Preelaborate.
949 -- For similar reasons, we only do this check for source entities, since
950 -- we generate entities of this type in some situations.
952 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
953 -- We have to enforce them for RM compatibility, but we have no trouble
954 -- accepting these objects and doing the right thing. Note that there is
955 -- no requirement that Preelaborate not actually generate any code!
957 if In_Preelaborated_Unit
958 and then not Debug_Flag_PP
959 and then Comes_From_Source (E)
961 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
962 and then (not Inside_A_Generic
963 or else Present (Enclosing_Generic_Body (E)))
964 and then not Is_Protected_Type (Etype (E))
967 ("library level controlled object not allowed in " &
968 "preelaborated unit", E);
970 end Validate_Controlled_Object;
972 --------------------------------------
973 -- Validate_Null_Statement_Sequence --
974 --------------------------------------
976 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
980 if In_Preelaborated_Unit then
981 Item := First (Statements (Handled_Statement_Sequence (N)));
982 while Present (Item) loop
983 if Nkind (Item) /= N_Label
984 and then Nkind (Item) /= N_Null_Statement
986 -- In GNAT mode, this is a warning, allowing the run-time
987 -- to judiciously bypass this error condition.
989 Error_Msg_Warn := GNAT_Mode;
991 ("<statements not allowed in preelaborated unit", Item);
999 end Validate_Null_Statement_Sequence;
1001 ---------------------------------
1002 -- Validate_Object_Declaration --
1003 ---------------------------------
1005 procedure Validate_Object_Declaration (N : Node_Id) is
1006 Id : constant Entity_Id := Defining_Identifier (N);
1007 E : constant Node_Id := Expression (N);
1008 Odf : constant Node_Id := Object_Definition (N);
1009 T : constant Entity_Id := Etype (Id);
1012 -- Verify that any access to subprogram object does not have in its
1013 -- subprogram profile access type parameters or limited parameters
1014 -- without Read and Write attributes (E.2.3(13)).
1016 Validate_RCI_Subprogram_Declaration (N);
1018 -- Check that if we are in preelaborated elaboration code, then we
1019 -- do not have an instance of a default initialized private, task or
1020 -- protected object declaration which would violate (RM 10.2.1(9)).
1021 -- Note that constants are never default initialized (and the test
1022 -- below also filters out deferred constants). A variable is default
1023 -- initialized if it does *not* have an initialization expression.
1025 -- Filter out cases that are not declaration of a variable from source
1027 if Nkind (N) /= N_Object_Declaration
1028 or else Constant_Present (N)
1029 or else not Comes_From_Source (Id)
1034 -- Exclude generic specs from the checks (this will get rechecked
1035 -- on instantiations).
1038 and then No (Enclosing_Generic_Body (Id))
1043 -- Required checks for declaration that is in a preelaborated
1044 -- package and is not within some subprogram.
1046 if In_Preelaborated_Unit
1047 and then not In_Subprogram_Or_Concurrent_Unit
1049 -- Check for default initialized variable case. Note that in
1050 -- accordance with (RM B.1(24)) imported objects are not
1051 -- subject to default initialization.
1053 if No (E) and then not Is_Imported (Id) then
1055 Ent : Entity_Id := T;
1058 -- An array whose component type is a record with nonstatic
1059 -- default expressions is a violation, so we get the array's
1062 if Is_Array_Type (Ent) then
1064 Comp_Type : Entity_Id;
1067 Comp_Type := Component_Type (Ent);
1068 while Is_Array_Type (Comp_Type) loop
1069 Comp_Type := Component_Type (Comp_Type);
1076 -- Object decl. that is of record type and has no default expr.
1077 -- should check if there is any non-static default expression
1078 -- in component decl. of the record type decl.
1080 if Is_Record_Type (Ent) then
1081 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1082 Check_Non_Static_Default_Expr
1083 (Type_Definition (Parent (Ent)), N);
1085 elsif Nkind (Odf) = N_Subtype_Indication
1086 and then not Is_Array_Type (T)
1087 and then not Is_Private_Type (T)
1089 Check_Non_Static_Default_Expr (Type_Definition
1090 (Parent (Entity (Subtype_Mark (Odf)))), N);
1094 -- Check for invalid use of private object. Note that Ada 2005
1095 -- AI-161 modifies the rules for Ada 2005, including the use of
1096 -- the new pragma Preelaborable_Initialization.
1098 if Is_Private_Type (Ent)
1099 or else Depends_On_Private (Ent)
1101 -- Case where type has preelaborable initialization which
1102 -- means that a pragma Preelaborable_Initialization was
1103 -- given for the private type.
1105 if Has_Preelaborable_Initialization (Ent) then
1107 -- But for the predefined units, we will ignore this
1108 -- status unless we are in Ada 2005 mode since we want
1109 -- Ada 95 compatible behavior, in which the entities
1110 -- marked with this pragma in the predefined library are
1111 -- not treated specially.
1113 if Ada_Version < Ada_05 then
1115 ("private object not allowed in preelaborated unit",
1117 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1120 -- Type does not have preelaborable initialization
1123 -- We allow this when compiling in GNAT mode to make life
1124 -- easier for some cases where it would otherwise be hard
1125 -- to be exactly valid Ada.
1127 if not GNAT_Mode then
1129 ("private object not allowed in preelaborated unit",
1132 -- If we are in Ada 2005 mode, add a message if pragma
1133 -- Preelaborable_Initialization on the type of the
1134 -- object would help.
1136 -- If the type has no full view (generic type, or
1137 -- previous error), the warning does not apply.
1139 if Ada_Version >= Ada_05
1140 and then Is_Private_Type (Ent)
1141 and then Present (Full_View (Ent))
1143 Has_Preelaborable_Initialization (Full_View (Ent))
1145 Error_Msg_Sloc := Sloc (Ent);
1147 ("\would be legal if pragma Preelaborable_" &
1148 "Initialization given for & #", N, Ent);
1153 -- Access to Task or Protected type
1155 elsif Is_Entity_Name (Odf)
1156 and then Present (Etype (Odf))
1157 and then Is_Access_Type (Etype (Odf))
1159 Ent := Designated_Type (Etype (Odf));
1161 elsif Is_Entity_Name (Odf) then
1162 Ent := Entity (Odf);
1164 elsif Nkind (Odf) = N_Subtype_Indication then
1165 Ent := Etype (Subtype_Mark (Odf));
1168 Nkind (Odf) = N_Constrained_Array_Definition
1170 Ent := Component_Type (T);
1176 if Is_Task_Type (Ent)
1177 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1180 ("concurrent object not allowed in preelaborated unit",
1187 -- Non-static discriminant not allowed in preelaborayted unit
1189 if Is_Record_Type (Etype (Id)) then
1191 ET : constant Entity_Id := Etype (Id);
1192 EE : constant Entity_Id := Etype (Etype (Id));
1196 if Has_Discriminants (ET)
1197 and then Present (EE)
1201 if Nkind (PEE) = N_Full_Type_Declaration
1202 and then not Static_Discriminant_Expr
1203 (Discriminant_Specifications (PEE))
1206 ("non-static discriminant in preelaborated unit",
1214 -- A pure library_item must not contain the declaration of any variable
1215 -- except within a subprogram, generic subprogram, task unit, or
1216 -- protected unit (RM 10.2.1(16)).
1219 and then not In_Subprogram_Task_Protected_Unit
1221 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1223 -- The visible part of an RCI library unit must not contain the
1224 -- declaration of a variable (RM E.1.3(9))
1226 elsif In_RCI_Declaration (N) then
1227 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1229 -- The visible part of a Shared Passive library unit must not contain
1230 -- the declaration of a variable (RM E.2.2(7))
1232 elsif In_RT_Declaration then
1234 ("variable declaration not allowed in remote types unit", N);
1237 end Validate_Object_Declaration;
1239 ------------------------------
1240 -- Validate_RACW_Primitives --
1241 ------------------------------
1243 procedure Validate_RACW_Primitives (T : Entity_Id) is
1244 Desig_Type : Entity_Id;
1245 Primitive_Subprograms : Elist_Id;
1246 Subprogram_Elmt : Elmt_Id;
1247 Subprogram : Entity_Id;
1249 Param_Spec : Node_Id;
1251 Param_Type : Entity_Id;
1255 Desig_Type := Etype (Designated_Type (T));
1257 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1259 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1260 while Subprogram_Elmt /= No_Elmt loop
1261 Subprogram := Node (Subprogram_Elmt);
1263 if not Comes_From_Source (Subprogram) then
1264 goto Next_Subprogram;
1267 -- Check return type
1269 if Ekind (Subprogram) = E_Function then
1270 Rtyp := Etype (Subprogram);
1272 if Has_Controlling_Result (Subprogram) then
1275 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1277 ("anonymous access result in remote object primitive", Rtyp);
1279 elsif Is_Limited_Type (Rtyp) then
1280 if No (TSS (Rtyp, TSS_Stream_Read))
1282 No (TSS (Rtyp, TSS_Stream_Write))
1285 ("limited return type must have Read and Write attributes",
1286 Parent (Subprogram));
1287 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1293 Profile := Parameter_Specifications (Parent (Subprogram));
1295 -- Profile must exist, otherwise not primitive operation
1297 Param_Spec := First (Profile);
1298 while Present (Param_Spec) loop
1300 -- Now find out if this parameter is a controlling parameter
1302 Param := Defining_Identifier (Param_Spec);
1303 Param_Type := Etype (Param);
1305 if Is_Controlling_Formal (Param) then
1307 -- It is a controlling parameter, so specific checks below
1312 elsif Ekind (Param_Type) = E_Anonymous_Access_Type then
1314 -- From RM E.2.2(14), no access parameter other than
1315 -- controlling ones may be used.
1318 ("non-controlling access parameter", Param_Spec);
1320 elsif Is_Limited_Type (Param_Type) then
1322 -- Not a controlling parameter, so type must have Read and
1323 -- Write attributes.
1325 if No (TSS (Param_Type, TSS_Stream_Read))
1327 No (TSS (Param_Type, TSS_Stream_Write))
1330 ("limited formal must have Read and Write attributes",
1332 Explain_Limited_Type (Param_Type, Param_Spec);
1336 -- Check next parameter in this subprogram
1342 Next_Elmt (Subprogram_Elmt);
1344 end Validate_RACW_Primitives;
1346 -------------------------------
1347 -- Validate_RCI_Declarations --
1348 -------------------------------
1350 procedure Validate_RCI_Declarations (P : Entity_Id) is
1354 E := First_Entity (P);
1355 while Present (E) loop
1356 if Comes_From_Source (E) then
1357 if Is_Limited_Type (E) then
1359 ("limited type not allowed in rci unit", Parent (E));
1360 Explain_Limited_Type (E, Parent (E));
1362 elsif Ekind (E) = E_Generic_Function
1363 or else Ekind (E) = E_Generic_Package
1364 or else Ekind (E) = E_Generic_Procedure
1366 Error_Msg_N ("generic declaration not allowed in rci unit",
1369 elsif (Ekind (E) = E_Function
1370 or else Ekind (E) = E_Procedure)
1371 and then Has_Pragma_Inline (E)
1374 ("inlined subprogram not allowed in rci unit", Parent (E));
1376 -- Inner packages that are renamings need not be checked. Generic
1377 -- RCI packages are subject to the checks, but entities that come
1378 -- from formal packages are not part of the visible declarations
1379 -- of the package and are not checked.
1381 elsif Ekind (E) = E_Package then
1382 if Present (Renamed_Entity (E)) then
1385 elsif Ekind (P) /= E_Generic_Package
1386 or else List_Containing (Unit_Declaration_Node (E)) /=
1387 Generic_Formal_Declarations
1388 (Unit_Declaration_Node (P))
1390 Validate_RCI_Declarations (E);
1397 end Validate_RCI_Declarations;
1399 -----------------------------------------
1400 -- Validate_RCI_Subprogram_Declaration --
1401 -----------------------------------------
1403 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1404 K : constant Node_Kind := Nkind (N);
1407 Param_Spec : Node_Id;
1408 Param_Type : Entity_Id;
1409 Base_Param_Type : Entity_Id;
1410 Base_Under_Type : Entity_Id;
1411 Type_Decl : Node_Id;
1412 Error_Node : Node_Id := N;
1415 -- There are two possible cases in which this procedure is called:
1417 -- 1. called from Analyze_Subprogram_Declaration.
1418 -- 2. called from Validate_Object_Declaration (access to subprogram).
1420 if not In_RCI_Declaration (N) then
1424 if K = N_Subprogram_Declaration then
1425 Profile := Parameter_Specifications (Specification (N));
1427 else pragma Assert (K = N_Object_Declaration);
1428 Id := Defining_Identifier (N);
1430 if Nkind (Id) = N_Defining_Identifier
1431 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1432 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1435 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1441 -- Iterate through the parameter specification list, checking that
1442 -- no access parameter and no limited type parameter in the list.
1445 if Present (Profile) then
1446 Param_Spec := First (Profile);
1447 while Present (Param_Spec) loop
1448 Param_Type := Etype (Defining_Identifier (Param_Spec));
1449 Type_Decl := Parent (Param_Type);
1451 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1453 if K = N_Subprogram_Declaration then
1454 Error_Node := Param_Spec;
1457 -- Report error only if declaration is in source program
1459 if Comes_From_Source
1460 (Defining_Entity (Specification (N)))
1463 ("subprogram in rci unit cannot have access parameter",
1467 -- For limited private type parameter, we check only the private
1468 -- declaration and ignore full type declaration, unless this is
1469 -- the only declaration for the type, eg. as a limited record.
1471 elsif Is_Limited_Type (Param_Type)
1472 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1474 (Nkind (Type_Decl) = N_Full_Type_Declaration
1475 and then not (Has_Private_Declaration (Param_Type))
1476 and then Comes_From_Source (N)))
1478 -- A limited parameter is legal only if user-specified Read and
1479 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1481 if No (Full_View (Param_Type))
1482 and then Ekind (Param_Type) /= E_Record_Type
1484 -- Type does not have completion yet, so if declared in in
1485 -- the current RCI scope it is illegal, and will be flagged
1491 -- In Ada 95 the rules permit using a limited type that has
1492 -- user-specified Read and Write attributes that are specified
1493 -- in the private part of the package, whereas Ada 2005
1494 -- (AI-240) revises this to require the attributes to be
1495 -- "available" (implying that the attribute clauses must be
1496 -- visible to the RCI client). The Ada 95 rules violate the
1497 -- contract model for privacy, but we support both semantics
1498 -- for now for compatibility (note that ACATS test BXE2009
1499 -- checks a case that conforms to the Ada 95 rules but is
1500 -- illegal in Ada 2005).
1502 Base_Param_Type := Base_Type (Param_Type);
1503 Base_Under_Type := Base_Type (Underlying_Type
1506 if (Ada_Version < Ada_05
1508 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1510 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1512 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1514 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1516 (Ada_Version >= Ada_05
1518 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1520 No (TSS (Base_Param_Type, TSS_Stream_Write))
1522 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1524 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write))))
1526 if K = N_Subprogram_Declaration then
1527 Error_Node := Param_Spec;
1530 if Ada_Version >= Ada_05 then
1532 ("limited parameter in rci unit "
1533 & "must have visible read/write attributes ",
1537 ("limited parameter in rci unit "
1538 & "must have read/write attributes ",
1541 Explain_Limited_Type (Param_Type, Error_Node);
1548 end Validate_RCI_Subprogram_Declaration;
1550 ----------------------------------------------------
1551 -- Validate_Remote_Access_Object_Type_Declaration --
1552 ----------------------------------------------------
1554 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1555 Direct_Designated_Type : Entity_Id;
1556 Desig_Type : Entity_Id;
1559 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1560 -- given node is N_Access_To_Object_Definition.
1562 if not Comes_From_Source (T)
1563 or else (not In_RCI_Declaration (Parent (T))
1564 and then not In_RT_Declaration)
1569 -- An access definition in the private part of a Remote Types package
1570 -- may be legal if it has user-defined Read and Write attributes. This
1571 -- will be checked at the end of the package spec processing.
1573 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1577 -- Check RCI or RT unit type declaration. It may not contain the
1578 -- declaration of an access-to-object type unless it is a general access
1579 -- type that designates a class-wide limited private type. There are
1580 -- also constraints on the primitive subprograms of the class-wide type
1581 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1583 if Ekind (T) /= E_General_Access_Type
1584 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1586 if In_RCI_Declaration (Parent (T)) then
1588 ("error in access type in Remote_Call_Interface unit", T);
1591 ("error in access type in Remote_Types unit", T);
1594 Error_Msg_N ("\must be general access to class-wide type", T);
1598 Direct_Designated_Type := Designated_Type (T);
1599 Desig_Type := Etype (Direct_Designated_Type);
1601 if not Is_Recursively_Limited_Private (Desig_Type) then
1603 ("error in designated type of remote access to class-wide type", T);
1605 ("\must be tagged limited private or private extension of type", T);
1609 -- Now this is an RCI unit access-to-class-wide-limited-private type
1610 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1611 -- optimize later checks by avoiding tree traversal to find out if this
1612 -- entity is inside an RCI unit.
1614 Set_Is_Remote_Call_Interface (T);
1615 end Validate_Remote_Access_Object_Type_Declaration;
1617 -----------------------------------------------
1618 -- Validate_Remote_Access_To_Class_Wide_Type --
1619 -----------------------------------------------
1621 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1622 K : constant Node_Kind := Nkind (N);
1623 PK : constant Node_Kind := Nkind (Parent (N));
1627 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1628 -- of class-wide limited private types.
1630 -- Storage_Pool and Storage_Size are not defined for such types
1632 -- The expected type of allocator must not not be such a type.
1634 -- The actual parameter of generic instantiation must not be such a
1635 -- type if the formal parameter is of an access type.
1637 -- On entry, there are five cases
1639 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1640 -- either Storage_Pool or Storage_Size.
1642 -- 2. called from exp_ch4 Expand_N_Allocator
1644 -- 3. called from sem_ch12 Analyze_Associations
1646 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1648 -- 5. called from sem_res Resolve_Actuals
1650 if K = N_Attribute_Reference then
1651 E := Etype (Prefix (N));
1653 if Is_Remote_Access_To_Class_Wide_Type (E) then
1654 Error_Msg_N ("incorrect attribute of remote operand", N);
1658 elsif K = N_Allocator then
1661 if Is_Remote_Access_To_Class_Wide_Type (E) then
1662 Error_Msg_N ("incorrect expected remote type of allocator", N);
1666 elsif K in N_Has_Entity then
1669 if Is_Remote_Access_To_Class_Wide_Type (E) then
1670 Error_Msg_N ("incorrect remote type generic actual", N);
1674 -- This subprogram also enforces the checks in E.2.2(13). A value of
1675 -- such type must not be dereferenced unless as controlling operand of
1676 -- a dispatching call.
1678 elsif K = N_Explicit_Dereference
1679 and then (Comes_From_Source (N)
1680 or else (Nkind (Original_Node (N)) = N_Selected_Component
1681 and then Comes_From_Source (Original_Node (N))))
1683 E := Etype (Prefix (N));
1685 -- If the class-wide type is not a remote one, the restrictions
1688 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1692 -- If we have a true dereference that comes from source and that
1693 -- is a controlling argument for a dispatching call, accept it.
1695 if Is_Actual_Parameter (N)
1696 and then Is_Controlling_Actual (N)
1701 -- If we are just within a procedure or function call and the
1702 -- dereference has not been analyzed, return because this procedure
1703 -- will be called again from sem_res Resolve_Actuals.
1705 if Is_Actual_Parameter (N)
1706 and then not Analyzed (N)
1711 -- We must allow expanded code to generate a reference to the tag of
1712 -- the designated object (may be either the actual tag, or the stub
1713 -- tag in the case of a remote object).
1715 if PK = N_Selected_Component
1716 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1721 -- The following code is needed for expansion of RACW Write
1722 -- attribute, since such expressions can appear in the expanded
1725 if not Comes_From_Source (N)
1728 or else PK = N_Attribute_Reference
1730 (PK = N_Type_Conversion
1731 and then Present (Parent (N))
1732 and then Present (Parent (Parent (N)))
1734 Nkind (Parent (Parent (N))) = N_Selected_Component))
1739 Error_Msg_N ("incorrect remote type dereference", N);
1741 end Validate_Remote_Access_To_Class_Wide_Type;
1743 ------------------------------------------
1744 -- Validate_Remote_Type_Type_Conversion --
1745 ------------------------------------------
1747 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1748 S : constant Entity_Id := Etype (N);
1749 E : constant Entity_Id := Etype (Expression (N));
1752 -- This test is required in the case where a conversion appears inside a
1753 -- normal package, it does not necessarily have to be inside an RCI,
1754 -- Remote_Types unit (RM E.2.2(9,12)).
1756 if Is_Remote_Access_To_Subprogram_Type (E)
1757 and then not Is_Remote_Access_To_Subprogram_Type (S)
1760 ("incorrect conversion of remote operand to local type", N);
1763 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1764 and then Is_Remote_Access_To_Subprogram_Type (S)
1767 ("incorrect conversion of local operand to remote type", N);
1770 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1771 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1774 ("incorrect conversion of remote operand to local type", N);
1778 -- If a local access type is converted into a RACW type, then the
1779 -- current unit has a pointer that may now be exported to another
1782 if Is_Remote_Access_To_Class_Wide_Type (S)
1783 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1785 Set_Has_RACW (Current_Sem_Unit);
1787 end Validate_Remote_Type_Type_Conversion;
1789 -------------------------------
1790 -- Validate_RT_RAT_Component --
1791 -------------------------------
1793 procedure Validate_RT_RAT_Component (N : Node_Id) is
1794 Spec : constant Node_Id := Specification (N);
1795 Name_U : constant Entity_Id := Defining_Entity (Spec);
1798 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1801 if not Is_Remote_Types (Name_U) then
1805 Typ := First_Entity (Name_U);
1806 while Present (Typ) and then Typ /= First_Priv_Ent loop
1807 U_Typ := Underlying_Type (Typ);
1813 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1814 if Missing_Read_Write_Attributes (Typ) then
1815 if Is_Non_Remote_Access_Type (Typ) then
1816 Error_Msg_N ("error in non-remote access type", U_Typ);
1819 ("error in record type containing a component of a " &
1820 "non-remote access type", U_Typ);
1823 if Ada_Version >= Ada_05 then
1825 ("\must have visible Read and Write attribute " &
1826 "definition clauses ('R'M E.2.2(8))", U_Typ);
1829 ("\must have Read and Write attribute " &
1830 "definition clauses ('R'M E.2.2(8))", U_Typ);
1837 end Validate_RT_RAT_Component;
1839 -----------------------------------------
1840 -- Validate_SP_Access_Object_Type_Decl --
1841 -----------------------------------------
1843 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1844 Direct_Designated_Type : Entity_Id;
1846 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1847 -- Return true if the protected type designated by T has
1848 -- entry declarations.
1850 ----------------------------
1851 -- Has_Entry_Declarations --
1852 ----------------------------
1854 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1858 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1859 Ety := First_Entity (E);
1860 while Present (Ety) loop
1861 if Ekind (Ety) = E_Entry then
1870 end Has_Entry_Declarations;
1872 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1875 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1876 -- Nkind of the given entity is N_Access_To_Object_Definition.
1878 if not Comes_From_Source (T)
1879 or else not In_Shared_Passive_Unit
1880 or else In_Subprogram_Task_Protected_Unit
1885 -- Check Shared Passive unit. It should not contain the declaration
1886 -- of an access-to-object type whose designated type is a class-wide
1887 -- type, task type or protected type with entry (RM E.2.1(7)).
1889 Direct_Designated_Type := Designated_Type (T);
1891 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
1893 ("invalid access-to-class-wide type in shared passive unit", T);
1896 elsif Ekind (Direct_Designated_Type) in Task_Kind then
1898 ("invalid access-to-task type in shared passive unit", T);
1901 elsif Ekind (Direct_Designated_Type) in Protected_Kind
1902 and then Has_Entry_Declarations (Direct_Designated_Type)
1905 ("invalid access-to-protected type in shared passive unit", T);
1908 end Validate_SP_Access_Object_Type_Decl;
1910 ---------------------------------
1911 -- Validate_Static_Object_Name --
1912 ---------------------------------
1914 procedure Validate_Static_Object_Name (N : Node_Id) is
1917 function Is_Primary (N : Node_Id) return Boolean;
1918 -- Determine whether node is syntactically a primary in an expression
1919 -- This function should probably be somewhere else ???
1920 -- Also it does not do what it says, e.g if N is a binary operator
1921 -- whose parent is a binary operator, Is_Primary returns True ???
1927 function Is_Primary (N : Node_Id) return Boolean is
1928 K : constant Node_Kind := Nkind (Parent (N));
1932 when N_Op | N_Membership_Test =>
1936 | N_Component_Association
1937 | N_Index_Or_Discriminant_Constraint =>
1940 when N_Attribute_Reference =>
1941 return Attribute_Name (Parent (N)) /= Name_Address
1942 and then Attribute_Name (Parent (N)) /= Name_Access
1943 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
1945 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
1947 when N_Indexed_Component =>
1948 return (N /= Prefix (Parent (N))
1949 or else Is_Primary (Parent (N)));
1951 when N_Qualified_Expression | N_Type_Conversion =>
1952 return Is_Primary (Parent (N));
1954 when N_Assignment_Statement | N_Object_Declaration =>
1955 return (N = Expression (Parent (N)));
1957 when N_Selected_Component =>
1958 return Is_Primary (Parent (N));
1965 -- Start of processing for Validate_Static_Object_Name
1968 if not In_Preelaborated_Unit
1969 or else not Comes_From_Source (N)
1970 or else In_Subprogram_Or_Concurrent_Unit
1971 or else Ekind (Current_Scope) = E_Block
1975 -- Filter out cases where primary is default in a component declaration,
1976 -- discriminant specification, or actual in a record type initialization
1979 -- Initialization call of internal types
1981 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
1983 if Present (Parent (Parent (N)))
1984 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
1989 if Nkind (Name (Parent (N))) = N_Identifier
1990 and then not Comes_From_Source (Entity (Name (Parent (N))))
1996 -- Error if the name is a primary in an expression. The parent must not
1997 -- be an operator, or a selected component or an indexed component that
1998 -- is itself a primary. Entities that are actuals do not need to be
1999 -- checked, because the call itself will be diagnosed.
2002 and then (not Inside_A_Generic
2003 or else Present (Enclosing_Generic_Body (N)))
2005 if Ekind (Entity (N)) = E_Variable
2006 or else Ekind (Entity (N)) in Formal_Object_Kind
2008 Flag_Non_Static_Expr
2009 ("non-static object name in preelaborated unit", N);
2011 -- We take the view that a constant defined in another preelaborated
2012 -- unit is preelaborable, even though it may have a private type and
2013 -- thus appear non-static in a client. This must be the intent of
2014 -- the language, but currently is an RM gap ???
2016 elsif Ekind (Entity (N)) = E_Constant
2017 and then not Is_Static_Expression (N)
2021 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2023 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2024 and then (Is_Preelaborated (Scope (E))
2025 or else Is_Pure (Scope (E))
2026 or else (Present (Renamed_Object (E))
2028 Is_Entity_Name (Renamed_Object (E))
2031 (Scope (Renamed_Object (E)))
2034 (Renamed_Object (E))))))
2038 -- This is the error case
2041 -- In GNAT mode, this is just a warning, to allow it to be
2042 -- judiciously turned off. Otherwise it is a real error.
2046 ("?non-static constant in preelaborated unit", N);
2048 Flag_Non_Static_Expr
2049 ("non-static constant in preelaborated unit", N);
2054 end Validate_Static_Object_Name;