1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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_Eval; use Sem_Eval;
39 with Sem_Util; use Sem_Util;
40 with Sinfo; use Sinfo;
41 with Snames; use Snames;
42 with Stand; use Stand;
44 package body Sem_Cat is
46 -----------------------
47 -- Local Subprograms --
48 -----------------------
50 procedure Check_Categorization_Dependencies
51 (Unit_Entity : Entity_Id;
52 Depended_Entity : Entity_Id;
54 Is_Subunit : Boolean);
55 -- This procedure checks that the categorization of a lib unit and that
56 -- of the depended unit satisfy dependency restrictions.
57 -- The depended_entity can be the entity in a with_clause item, in which
58 -- case Info_Node denotes that item. The depended_entity can also be the
59 -- parent unit of a child unit, in which case Info_Node is the declaration
60 -- of the child unit. The error message is posted on Info_Node, and is
61 -- specialized if Is_Subunit is true.
63 procedure Check_Non_Static_Default_Expr
66 -- Iterate through the component list of a record definition, check
67 -- that no component is declared with a nonstatic default value.
68 -- If a nonstatic default exists, report an error on Obj_Decl.
70 -- Iterate through the component list of a record definition, check
71 -- that no component is declared with a non-static default value.
73 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
74 -- Return True if the entity or one of its subcomponents is of an access
75 -- type that does not have user-defined Read and Write attributes 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 general
102 -- access type that designates a class-wide limited private type. There are
103 -- also constraints about the primitive subprograms of the class-wide type.
104 -- RM E.2 (9, 13, 14)
106 ---------------------------------------
107 -- Check_Categorization_Dependencies --
108 ---------------------------------------
110 procedure Check_Categorization_Dependencies
111 (Unit_Entity : Entity_Id;
112 Depended_Entity : Entity_Id;
114 Is_Subunit : Boolean)
116 N : constant Node_Id := Info_Node;
118 -- Here we define an enumeration type to represent categorization types,
119 -- ordered so that a unit with a given categorization can only WITH
120 -- units with lower or equal categorization type.
122 -- Note that we take advantage of E.2(14) to define a category
123 -- Preelaborated and treat pragma Preelaborate as a categorization
124 -- pragma that defines that category.
126 type Categorization is
130 Remote_Call_Interface,
134 function Get_Categorization (E : Entity_Id) return Categorization;
135 -- Check categorization flags from entity, and return in the form
136 -- of the lowest value of the Categorization type that applies to E.
138 ------------------------
139 -- Get_Categorization --
140 ------------------------
142 function Get_Categorization (E : Entity_Id) return Categorization is
144 -- Get the lowest categorization that corresponds to E. Note that
145 -- nothing prevents several (different) categorization pragmas
146 -- to apply to the same library unit, in which case the unit has
147 -- all associated categories, so we need to be careful here to
148 -- check pragmas in proper Categorization order in order to
149 -- return the lowest applicable value.
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;
168 elsif Is_Preelaborated (E) then
169 return Preelaborated;
174 end Get_Categorization;
176 Unit_Category : Categorization;
177 With_Category : Categorization;
179 -- Start of processing for Check_Categorization_Dependencies
182 -- Intrinsic subprograms are preelaborated, so do not impose any
183 -- categorization dependencies.
185 if Is_Intrinsic_Subprogram (Depended_Entity) then
189 Unit_Category := Get_Categorization (Unit_Entity);
190 With_Category := Get_Categorization (Depended_Entity);
192 -- These messages are warnings in GNAT mode, to allow it to be
193 -- judiciously turned off. Otherwise it is a real error.
195 Error_Msg_Warn := GNAT_Mode;
197 -- Check for possible error
199 if With_Category > Unit_Category then
201 -- Special case: Remote_Types and Remote_Call_Interface are allowed
202 -- to be with'ed in package body.
204 if (Unit_Category = Remote_Types
205 or else Unit_Category = Remote_Call_Interface)
206 and then In_Package_Body (Unit_Entity)
210 -- Here we have an error
213 -- Don't give error if main unit is not an internal unit, and the
214 -- unit generating the message is an internal unit. This is the
215 -- situation in which such messages would be ignored in any case,
216 -- so it is convenient not to generate them (since it causes
217 -- annoying interference with debugging).
219 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
220 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
226 elsif Is_Subunit then
228 ("<subunit cannot depend on& " &
229 "(parent has wrong categorization)", N, Depended_Entity);
231 -- Normal unit, not subunit
235 ("<cannot depend on& " &
236 "(wrong categorization)", N, Depended_Entity);
239 -- Add further explanation for common cases
241 case Unit_Category is
244 ("\<pure unit cannot depend on non-pure unit",
247 when Preelaborated =>
249 ("\<preelaborated unit cannot depend on " &
250 "non-preelaborated unit",
258 end Check_Categorization_Dependencies;
260 -----------------------------------
261 -- Check_Non_Static_Default_Expr --
262 -----------------------------------
264 procedure Check_Non_Static_Default_Expr
269 Component_Decl : Node_Id;
272 if Nkind (Type_Def) = N_Derived_Type_Definition then
273 Recdef := Record_Extension_Part (Type_Def);
283 -- Check that component declarations do not involve:
285 -- a. a non-static default expression, where the object is
286 -- declared to be default initialized.
288 -- b. a dynamic Itype (discriminants and constraints)
290 if Null_Present (Recdef) then
293 Component_Decl := First (Component_Items (Component_List (Recdef)));
296 while Present (Component_Decl)
297 and then Nkind (Component_Decl) = N_Component_Declaration
299 if Present (Expression (Component_Decl))
300 and then Nkind (Expression (Component_Decl)) /= N_Null
301 and then not Is_Static_Expression (Expression (Component_Decl))
303 Error_Msg_Sloc := Sloc (Component_Decl);
305 ("object in preelaborated unit has non-static default#",
308 -- Fix this later ???
310 -- elsif Has_Dynamic_Itype (Component_Decl) then
312 -- ("dynamic type discriminant," &
313 -- " constraint in preelaborated unit",
317 Next (Component_Decl);
319 end Check_Non_Static_Default_Expr;
321 -------------------------------------
322 -- Has_Stream_Attribute_Definition --
323 -------------------------------------
325 function Has_Stream_Attribute_Definition
328 At_Any_Place : Boolean := False) return Boolean
331 Full_Type : Entity_Id := Typ;
334 -- In the case of a type derived from a private view, any specified
335 -- stream attributes will be attached to the derived type's underlying
336 -- type rather the derived type entity itself (which is itself private).
338 if Is_Private_Type (Typ)
339 and then Is_Derived_Type (Typ)
340 and then Present (Full_View (Typ))
342 Full_Type := Underlying_Type (Typ);
345 -- We start from the declaration node and then loop until the end of
346 -- the list until we find the requested attribute definition clause.
347 -- In Ada 2005 mode, clauses are ignored if they are not currently
348 -- visible (this is tested using the corresponding Entity, which is
349 -- inserted by the expander at the point where the clause occurs),
350 -- unless At_Any_Place is true.
352 Rep_Item := First_Rep_Item (Full_Type);
353 while Present (Rep_Item) loop
354 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
355 case Chars (Rep_Item) is
357 exit when Nam = TSS_Stream_Read;
360 exit when Nam = TSS_Stream_Write;
363 exit when Nam = TSS_Stream_Input;
366 exit when Nam = TSS_Stream_Output;
374 Next_Rep_Item (Rep_Item);
377 -- If At_Any_Place is true, return True if the attribute is available
378 -- at any place; if it is false, return True only if the attribute is
379 -- currently visible.
381 return Present (Rep_Item)
382 and then (Ada_Version < Ada_05
384 or else not Is_Hidden (Entity (Rep_Item)));
385 end Has_Stream_Attribute_Definition;
387 ---------------------------
388 -- In_Preelaborated_Unit --
389 ---------------------------
391 function In_Preelaborated_Unit return Boolean is
392 Unit_Entity : constant Entity_Id := Current_Scope;
393 Unit_Kind : constant Node_Kind :=
394 Nkind (Unit (Cunit (Current_Sem_Unit)));
397 -- There are no constraints on body of remote_call_interface or
398 -- remote_types packages.
400 return (Unit_Entity /= Standard_Standard)
401 and then (Is_Preelaborated (Unit_Entity)
402 or else Is_Pure (Unit_Entity)
403 or else Is_Shared_Passive (Unit_Entity)
405 ((Is_Remote_Types (Unit_Entity)
406 or else Is_Remote_Call_Interface (Unit_Entity))
407 and then Ekind (Unit_Entity) = E_Package
408 and then Unit_Kind /= N_Package_Body
409 and then not In_Package_Body (Unit_Entity)
410 and then not In_Instance));
411 end In_Preelaborated_Unit;
417 function In_Pure_Unit return Boolean is
419 return Is_Pure (Current_Scope);
422 ------------------------
423 -- In_RCI_Declaration --
424 ------------------------
426 function In_RCI_Declaration (N : Node_Id) return Boolean is
427 Unit_Entity : constant Entity_Id := Current_Scope;
428 Unit_Kind : constant Node_Kind :=
429 Nkind (Unit (Cunit (Current_Sem_Unit)));
432 -- There are no restrictions on the private part or body
435 return Is_Remote_Call_Interface (Unit_Entity)
436 and then Is_Package_Or_Generic_Package (Unit_Entity)
437 and then Unit_Kind /= N_Package_Body
438 and then List_Containing (N) =
440 (Specification (Unit_Declaration_Node (Unit_Entity)))
441 and then not In_Package_Body (Unit_Entity)
442 and then not In_Instance;
444 -- What about the case of a nested package in the visible part???
445 -- This case is missed by the List_Containing check above???
446 end In_RCI_Declaration;
448 -----------------------
449 -- In_RT_Declaration --
450 -----------------------
452 function In_RT_Declaration return Boolean is
453 Unit_Entity : constant Entity_Id := Current_Scope;
454 Unit_Kind : constant Node_Kind :=
455 Nkind (Unit (Cunit (Current_Sem_Unit)));
458 -- There are no restrictions on the body of a Remote Types unit
460 return Is_Remote_Types (Unit_Entity)
461 and then Is_Package_Or_Generic_Package (Unit_Entity)
462 and then Unit_Kind /= N_Package_Body
463 and then not In_Package_Body (Unit_Entity)
464 and then not In_Instance;
465 end In_RT_Declaration;
467 ----------------------------
468 -- In_Shared_Passive_Unit --
469 ----------------------------
471 function In_Shared_Passive_Unit return Boolean is
472 Unit_Entity : constant Entity_Id := Current_Scope;
475 return Is_Shared_Passive (Unit_Entity);
476 end In_Shared_Passive_Unit;
478 ---------------------------------------
479 -- In_Subprogram_Task_Protected_Unit --
480 ---------------------------------------
482 function In_Subprogram_Task_Protected_Unit return Boolean is
486 -- The following is to verify that a declaration is inside
487 -- subprogram, generic subprogram, task unit, protected unit.
488 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
490 -- Use scope chain to check successively outer scopes
496 Is_Generic_Subprogram (E)
498 Is_Concurrent_Type (E)
502 elsif E = Standard_Standard then
508 end In_Subprogram_Task_Protected_Unit;
510 -------------------------------
511 -- Is_Non_Remote_Access_Type --
512 -------------------------------
514 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
515 U_E : constant Entity_Id := Underlying_Type (E);
519 -- This case arises for the case of a generic formal type, in which
520 -- case E.2.2(8) rules will be enforced at instantiation time.
525 return Is_Access_Type (U_E)
526 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
527 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
528 end Is_Non_Remote_Access_Type;
530 ----------------------------------
531 -- Missing_Read_Write_Attribute --
532 ----------------------------------
534 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
535 Component : Entity_Id;
536 Component_Type : Entity_Id;
537 U_E : constant Entity_Id := Underlying_Type (E);
539 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
540 -- Return True if entity has attribute definition clauses for Read and
541 -- Write attributes that are visible at some place.
543 -------------------------------
544 -- Has_Read_Write_Attributes --
545 -------------------------------
547 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
550 and then Has_Stream_Attribute_Definition (E,
551 TSS_Stream_Read, At_Any_Place => True)
552 and then Has_Stream_Attribute_Definition (E,
553 TSS_Stream_Write, At_Any_Place => True);
554 end Has_Read_Write_Attributes;
556 -- Start of processing for Missing_Read_Write_Attributes
562 elsif Has_Read_Write_Attributes (E)
563 or else Has_Read_Write_Attributes (U_E)
567 elsif Is_Non_Remote_Access_Type (U_E) then
571 if Is_Record_Type (U_E) then
572 Component := First_Entity (U_E);
573 while Present (Component) loop
574 if not Is_Tag (Component) then
575 Component_Type := Etype (Component);
577 if Missing_Read_Write_Attributes (Component_Type) then
582 Next_Entity (Component);
587 end Missing_Read_Write_Attributes;
589 -------------------------------------
590 -- Set_Categorization_From_Pragmas --
591 -------------------------------------
593 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
594 P : constant Node_Id := Parent (N);
595 S : constant Entity_Id := Current_Scope;
597 procedure Set_Parents (Visibility : Boolean);
598 -- If this is a child instance, the parents are not immediately
599 -- visible during analysis. Make them momentarily visible so that
600 -- the argument of the pragma can be resolved properly, and reset
607 procedure Set_Parents (Visibility : Boolean) is
611 while Present (Par) and then Par /= Standard_Standard loop
612 Set_Is_Immediately_Visible (Par, Visibility);
617 -- Start of processing for Set_Categorization_From_Pragmas
620 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
621 -- The purpose is to set categorization flags before analyzing the
622 -- unit itself, so as to diagnose violations of categorization as
623 -- we process each declaration, even though the pragma appears after
626 if Nkind (P) /= N_Compilation_Unit then
635 and then Is_Generic_Instance (S)
640 PN := First (Pragmas_After (Aux_Decls_Node (P)));
641 while Present (PN) loop
643 -- Skip implicit types that may have been introduced by
644 -- previous analysis.
646 if Nkind (PN) = N_Pragma then
647 case Get_Pragma_Id (PN) is
648 when Pragma_All_Calls_Remote |
649 Pragma_Preelaborate |
651 Pragma_Remote_Call_Interface |
652 Pragma_Remote_Types |
653 Pragma_Shared_Passive => Analyze (PN);
662 and then Is_Generic_Instance (S)
667 end Set_Categorization_From_Pragmas;
669 -----------------------------------
670 -- Set_Categorization_From_Scope --
671 -----------------------------------
673 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
674 Declaration : Node_Id := Empty;
675 Specification : Node_Id := Empty;
679 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
681 if not Is_Remote_Call_Interface (E) then
682 if Ekind (E) in Subprogram_Kind then
683 Declaration := Unit_Declaration_Node (E);
685 if Nkind (Declaration) = N_Subprogram_Body
687 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
689 Specification := Corresponding_Spec (Declaration);
693 -- A subprogram body or renaming-as-body is a remote call
694 -- interface if it serves as the completion of a subprogram
695 -- declaration that is a remote call interface.
697 if Nkind (Specification) in N_Entity then
698 Set_Is_Remote_Call_Interface
699 (E, Is_Remote_Call_Interface (Specification));
701 -- A subprogram declaration is a remote call interface when it is
702 -- declared within the visible part of, or declared by, a library
703 -- unit declaration that is a remote call interface.
706 Set_Is_Remote_Call_Interface
707 (E, Is_Remote_Call_Interface (Scop)
708 and then not (In_Private_Part (Scop)
709 or else In_Package_Body (Scop)));
714 (E, Is_Remote_Types (Scop)
715 and then not (In_Private_Part (Scop)
716 or else In_Package_Body (Scop)));
717 end Set_Categorization_From_Scope;
719 ------------------------------
720 -- Static_Discriminant_Expr --
721 ------------------------------
723 -- We need to accommodate a Why_Not_Static call somehow here ???
725 function Static_Discriminant_Expr (L : List_Id) return Boolean is
726 Discriminant_Spec : Node_Id;
729 Discriminant_Spec := First (L);
730 while Present (Discriminant_Spec) loop
731 if Present (Expression (Discriminant_Spec))
732 and then not Is_Static_Expression (Expression (Discriminant_Spec))
737 Next (Discriminant_Spec);
741 end Static_Discriminant_Expr;
743 --------------------------------------
744 -- Validate_Access_Type_Declaration --
745 --------------------------------------
747 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
748 Def : constant Node_Id := Type_Definition (N);
753 -- Access to subprogram case
755 when N_Access_To_Subprogram_Definition =>
757 -- A pure library_item must not contain the declaration of a
758 -- named access type, except within a subprogram, generic
759 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
761 -- This test is skipped in Ada 2005 (see AI-366)
763 if Ada_Version < Ada_05
764 and then Comes_From_Source (T)
765 and then In_Pure_Unit
766 and then not In_Subprogram_Task_Protected_Unit
768 Error_Msg_N ("named access type not allowed in pure unit", T);
771 -- Access to object case
773 when N_Access_To_Object_Definition =>
774 if Comes_From_Source (T)
775 and then In_Pure_Unit
776 and then not In_Subprogram_Task_Protected_Unit
778 -- We can't give the message yet, since the type is not frozen
779 -- and in Ada 2005 mode, access types are allowed in pure units
780 -- if the type has no storage pool (see AI-366). So we set a
781 -- flag which will be checked at freeze time.
783 Set_Is_Pure_Unit_Access_Type (T);
786 -- Check for RCI or RT unit type declaration: declaration of an
787 -- access-to-object type is illegal unless it is a general access
788 -- type that designates a class-wide limited private type.
789 -- Note that constraints on the primitive subprograms of the
790 -- designated tagged type are not enforced here but in
791 -- Validate_RACW_Primitives, which is done separately because the
792 -- designated type might not be frozen (and therefore its
793 -- primitive operations might not be completely known) at the
794 -- point of the RACW declaration.
796 Validate_Remote_Access_Object_Type_Declaration (T);
798 -- Check for shared passive unit type declaration. It should
799 -- not contain the declaration of access to class wide type,
800 -- access to task type and access to protected type with entry.
802 Validate_SP_Access_Object_Type_Decl (T);
808 -- Set categorization flag from package on entity as well, to allow
809 -- easy checks later on for required validations of RCI or RT units.
810 -- This is only done for entities that are in the original source.
812 if Comes_From_Source (T)
813 and then not (In_Package_Body (Scope (T))
814 or else In_Private_Part (Scope (T)))
816 Set_Is_Remote_Call_Interface
817 (T, Is_Remote_Call_Interface (Scope (T)));
819 (T, Is_Remote_Types (Scope (T)));
821 end Validate_Access_Type_Declaration;
823 ----------------------------
824 -- Validate_Ancestor_Part --
825 ----------------------------
827 procedure Validate_Ancestor_Part (N : Node_Id) is
828 A : constant Node_Id := Ancestor_Part (N);
829 T : constant Entity_Id := Entity (A);
832 if In_Preelaborated_Unit
833 and then not In_Subprogram_Or_Concurrent_Unit
834 and then (not Inside_A_Generic
835 or else Present (Enclosing_Generic_Body (N)))
837 -- If the type is private, it must have the Ada 2005 pragma
838 -- Has_Preelaborable_Initialization.
839 -- The check is omitted within predefined units. This is probably
840 -- obsolete code to fix the Ada95 weakness in this area ???
842 if Is_Private_Type (T)
843 and then not Has_Pragma_Preelab_Init (T)
844 and then not Is_Internal_File_Name
845 (Unit_File_Name (Get_Source_Unit (N)))
848 ("private ancestor type not allowed in preelaborated unit", A);
850 elsif Is_Record_Type (T) then
851 if Nkind (Parent (T)) = N_Full_Type_Declaration then
852 Check_Non_Static_Default_Expr
853 (Type_Definition (Parent (T)), A);
857 end Validate_Ancestor_Part;
859 ----------------------------------------
860 -- Validate_Categorization_Dependency --
861 ----------------------------------------
863 procedure Validate_Categorization_Dependency
867 K : constant Node_Kind := Nkind (N);
868 P : Node_Id := Parent (N);
870 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
873 -- Only validate library units and subunits. For subunits, checks
874 -- concerning withed units apply to the parent compilation unit.
881 and then not Is_Compilation_Unit (U)
882 and then not Is_Child_Unit (U)
888 if Nkind (P) /= N_Compilation_Unit then
892 -- Body of RCI unit does not need validation
894 if Is_Remote_Call_Interface (E)
895 and then (Nkind (N) = N_Package_Body
896 or else Nkind (N) = N_Subprogram_Body)
901 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
905 Entity_Of_Withed : Entity_Id;
908 Item := First (Context_Items (P));
909 while Present (Item) loop
910 if Nkind (Item) = N_With_Clause
911 and then not (Implicit_With (Item)
912 or else Limited_Present (Item))
914 Entity_Of_Withed := Entity (Name (Item));
915 Check_Categorization_Dependencies
916 (U, Entity_Of_Withed, Item, Is_Subunit);
923 -- Child depends on parent; therefore parent should also be categorized
924 -- and satisfy the dependency hierarchy.
926 -- Check if N is a child spec
928 if (K in N_Generic_Declaration or else
929 K in N_Generic_Instantiation or else
930 K in N_Generic_Renaming_Declaration or else
931 K = N_Package_Declaration or else
932 K = N_Package_Renaming_Declaration or else
933 K = N_Subprogram_Declaration or else
934 K = N_Subprogram_Renaming_Declaration)
935 and then Present (Parent_Spec (N))
937 Check_Categorization_Dependencies (E, Scope (E), N, False);
939 -- Verify that public child of an RCI library unit must also be an
940 -- RCI library unit (RM E.2.3(15)).
942 if Is_Remote_Call_Interface (Scope (E))
943 and then not Private_Present (P)
944 and then not Is_Remote_Call_Interface (E)
946 Error_Msg_N ("public child of rci unit must also be rci unit", N);
949 end Validate_Categorization_Dependency;
951 --------------------------------
952 -- Validate_Controlled_Object --
953 --------------------------------
955 procedure Validate_Controlled_Object (E : Entity_Id) is
957 -- Don't need this check in Ada 2005 mode, where this is all taken
958 -- care of by the mechanism for Preelaborable Initialization.
960 if Ada_Version >= Ada_05 then
964 -- For now, never apply this check for internal GNAT units, since we
965 -- have a number of cases in the library where we are stuck with objects
966 -- of this type, and the RM requires Preelaborate.
968 -- For similar reasons, we only do this check for source entities, since
969 -- we generate entities of this type in some situations.
971 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
972 -- We have to enforce them for RM compatibility, but we have no trouble
973 -- accepting these objects and doing the right thing. Note that there is
974 -- no requirement that Preelaborate not actually generate any code!
976 if In_Preelaborated_Unit
977 and then not Debug_Flag_PP
978 and then Comes_From_Source (E)
980 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
981 and then (not Inside_A_Generic
982 or else Present (Enclosing_Generic_Body (E)))
983 and then not Is_Protected_Type (Etype (E))
986 ("library level controlled object not allowed in " &
987 "preelaborated unit", E);
989 end Validate_Controlled_Object;
991 --------------------------------------
992 -- Validate_Null_Statement_Sequence --
993 --------------------------------------
995 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
999 if In_Preelaborated_Unit then
1000 Item := First (Statements (Handled_Statement_Sequence (N)));
1001 while Present (Item) loop
1002 if Nkind (Item) /= N_Label
1003 and then Nkind (Item) /= N_Null_Statement
1005 -- In GNAT mode, this is a warning, allowing the run-time
1006 -- to judiciously bypass this error condition.
1008 Error_Msg_Warn := GNAT_Mode;
1010 ("<statements not allowed in preelaborated unit", Item);
1018 end Validate_Null_Statement_Sequence;
1020 ---------------------------------
1021 -- Validate_Object_Declaration --
1022 ---------------------------------
1024 procedure Validate_Object_Declaration (N : Node_Id) is
1025 Id : constant Entity_Id := Defining_Identifier (N);
1026 E : constant Node_Id := Expression (N);
1027 Odf : constant Node_Id := Object_Definition (N);
1028 T : constant Entity_Id := Etype (Id);
1031 -- Verify that any access to subprogram object does not have in its
1032 -- subprogram profile access type parameters or limited parameters
1033 -- without Read and Write attributes (E.2.3(13)).
1035 Validate_RCI_Subprogram_Declaration (N);
1037 -- Check that if we are in preelaborated elaboration code, then we
1038 -- do not have an instance of a default initialized private, task or
1039 -- protected object declaration which would violate (RM 10.2.1(9)).
1040 -- Note that constants are never default initialized (and the test
1041 -- below also filters out deferred constants). A variable is default
1042 -- initialized if it does *not* have an initialization expression.
1044 -- Filter out cases that are not declaration of a variable from source
1046 if Nkind (N) /= N_Object_Declaration
1047 or else Constant_Present (N)
1048 or else not Comes_From_Source (Id)
1053 -- Exclude generic specs from the checks (this will get rechecked
1054 -- on instantiations).
1057 and then No (Enclosing_Generic_Body (Id))
1062 -- Required checks for declaration that is in a preelaborated
1063 -- package and is not within some subprogram.
1065 if In_Preelaborated_Unit
1066 and then not In_Subprogram_Or_Concurrent_Unit
1068 -- Check for default initialized variable case. Note that in
1069 -- accordance with (RM B.1(24)) imported objects are not
1070 -- subject to default initialization.
1071 -- If the initialization does not come from source and is an
1072 -- aggregate, it is a static initialization that replaces an
1073 -- implicit call, and must be treated as such.
1077 (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1081 elsif Is_Imported (Id) then
1086 Ent : Entity_Id := T;
1089 -- An array whose component type is a record with nonstatic
1090 -- default expressions is a violation, so we get the array's
1093 if Is_Array_Type (Ent) then
1095 Comp_Type : Entity_Id;
1098 Comp_Type := Component_Type (Ent);
1099 while Is_Array_Type (Comp_Type) loop
1100 Comp_Type := Component_Type (Comp_Type);
1107 -- Object decl. that is of record type and has no default expr.
1108 -- should check if there is any non-static default expression
1109 -- in component decl. of the record type decl.
1111 if Is_Record_Type (Ent) then
1112 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1113 Check_Non_Static_Default_Expr
1114 (Type_Definition (Parent (Ent)), N);
1116 elsif Nkind (Odf) = N_Subtype_Indication
1117 and then not Is_Array_Type (T)
1118 and then not Is_Private_Type (T)
1120 Check_Non_Static_Default_Expr (Type_Definition
1121 (Parent (Entity (Subtype_Mark (Odf)))), N);
1125 -- Check for invalid use of private object. Note that Ada 2005
1126 -- AI-161 modifies the rules for Ada 2005, including the use of
1127 -- the new pragma Preelaborable_Initialization.
1129 if Is_Private_Type (Ent)
1130 or else Depends_On_Private (Ent)
1132 -- Case where type has preelaborable initialization which
1133 -- means that a pragma Preelaborable_Initialization was
1134 -- given for the private type.
1136 if Has_Preelaborable_Initialization (Ent) then
1138 -- But for the predefined units, we will ignore this
1139 -- status unless we are in Ada 2005 mode since we want
1140 -- Ada 95 compatible behavior, in which the entities
1141 -- marked with this pragma in the predefined library are
1142 -- not treated specially.
1144 if Ada_Version < Ada_05 then
1146 ("private object not allowed in preelaborated unit",
1148 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1151 -- Type does not have preelaborable initialization
1154 -- We allow this when compiling in GNAT mode to make life
1155 -- easier for some cases where it would otherwise be hard
1156 -- to be exactly valid Ada.
1158 if not GNAT_Mode then
1160 ("private object not allowed in preelaborated unit",
1163 -- Add a message if it would help to provide a pragma
1164 -- Preelaborable_Initialization on the type of the
1165 -- object (which would make it legal in Ada 2005).
1167 -- If the type has no full view (generic type, or
1168 -- previous error), the warning does not apply.
1170 if Is_Private_Type (Ent)
1171 and then Present (Full_View (Ent))
1173 Has_Preelaborable_Initialization (Full_View (Ent))
1175 Error_Msg_Sloc := Sloc (Ent);
1177 if Ada_Version >= Ada_05 then
1179 ("\would be legal if pragma Preelaborable_" &
1180 "Initialization given for & #", N, Ent);
1183 ("\would be legal in Ada 2005 if pragma " &
1184 "Preelaborable_Initialization given for & #",
1191 -- Access to Task or Protected type
1193 elsif Is_Entity_Name (Odf)
1194 and then Present (Etype (Odf))
1195 and then Is_Access_Type (Etype (Odf))
1197 Ent := Designated_Type (Etype (Odf));
1199 elsif Is_Entity_Name (Odf) then
1200 Ent := Entity (Odf);
1202 elsif Nkind (Odf) = N_Subtype_Indication then
1203 Ent := Etype (Subtype_Mark (Odf));
1206 Nkind (Odf) = N_Constrained_Array_Definition
1208 Ent := Component_Type (T);
1214 if Is_Task_Type (Ent)
1215 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1218 ("concurrent object not allowed in preelaborated unit",
1225 -- Non-static discriminant not allowed in preelaborated unit
1226 -- Controlled object of a type with a user-defined Initialize
1227 -- is forbidden as well.
1229 if Is_Record_Type (Etype (Id)) then
1231 ET : constant Entity_Id := Etype (Id);
1232 EE : constant Entity_Id := Etype (Etype (Id));
1236 if Has_Discriminants (ET)
1237 and then Present (EE)
1241 if Nkind (PEE) = N_Full_Type_Declaration
1242 and then not Static_Discriminant_Expr
1243 (Discriminant_Specifications (PEE))
1246 ("non-static discriminant in preelaborated unit",
1251 if Has_Overriding_Initialize (ET) then
1253 ("controlled type& does not have"
1254 & " preelaborable initialization", N, ET);
1261 -- A pure library_item must not contain the declaration of any variable
1262 -- except within a subprogram, generic subprogram, task unit, or
1263 -- protected unit (RM 10.2.1(16)).
1266 and then not In_Subprogram_Task_Protected_Unit
1268 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1270 -- The visible part of an RCI library unit must not contain the
1271 -- declaration of a variable (RM E.1.3(9))
1273 elsif In_RCI_Declaration (N) then
1274 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1276 -- The visible part of a Shared Passive library unit must not contain
1277 -- the declaration of a variable (RM E.2.2(7))
1279 elsif In_RT_Declaration then
1281 ("variable declaration not allowed in remote types unit", N);
1284 end Validate_Object_Declaration;
1286 ------------------------------
1287 -- Validate_RACW_Primitives --
1288 ------------------------------
1290 procedure Validate_RACW_Primitives (T : Entity_Id) is
1291 Desig_Type : Entity_Id;
1292 Primitive_Subprograms : Elist_Id;
1293 Subprogram_Elmt : Elmt_Id;
1294 Subprogram : Entity_Id;
1295 Param_Spec : Node_Id;
1297 Param_Type : Entity_Id;
1300 procedure Illegal_RACW (Msg : String; N : Node_Id);
1301 -- Diagnose that T is illegal because of the given reason, associated
1302 -- with the location of node N.
1304 Illegal_RACW_Message_Issued : Boolean := False;
1305 -- Set True once Illegal_RACW has been called
1311 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1313 if not Illegal_RACW_Message_Issued then
1315 ("illegal remote access to class-wide type&", T);
1316 Illegal_RACW_Message_Issued := True;
1319 Error_Msg_Sloc := Sloc (N);
1320 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1323 -- Start of processing for Validate_RACW_Primitives
1326 Desig_Type := Etype (Designated_Type (T));
1328 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1330 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1331 while Subprogram_Elmt /= No_Elmt loop
1332 Subprogram := Node (Subprogram_Elmt);
1334 if Is_Predefined_Dispatching_Operation (Subprogram)
1335 or else Is_Hidden (Subprogram)
1337 goto Next_Subprogram;
1340 -- Check return type
1342 if Ekind (Subprogram) = E_Function then
1343 Rtyp := Etype (Subprogram);
1345 if Has_Controlling_Result (Subprogram) then
1348 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1349 Illegal_RACW ("anonymous access result", Rtyp);
1351 elsif Is_Limited_Type (Rtyp) then
1352 if No (TSS (Rtyp, TSS_Stream_Read))
1354 No (TSS (Rtyp, TSS_Stream_Write))
1357 ("limited return type must have Read and Write attributes",
1358 Parent (Subprogram));
1359 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1361 -- Check that the return type supports external streaming.
1362 -- Note that the language of the standard (E.2.2(14)) does not
1363 -- explicitly mention that case, but it really does not make
1364 -- sense to return a value containing a local access type.
1366 elsif Missing_Read_Write_Attributes (Rtyp)
1367 and then not Error_Posted (Rtyp)
1369 Illegal_RACW ("return type containing non-remote access "
1370 & "must have Read and Write attributes",
1371 Parent (Subprogram));
1377 Param := First_Formal (Subprogram);
1378 while Present (Param) loop
1380 -- Now find out if this parameter is a controlling parameter
1382 Param_Spec := Parent (Param);
1383 Param_Type := Etype (Param);
1385 if Is_Controlling_Formal (Param) then
1387 -- It is a controlling parameter, so specific checks below
1392 elsif Ekind (Param_Type) = E_Anonymous_Access_Type
1393 or else Ekind (Param_Type) = E_Anonymous_Access_Subprogram_Type
1395 -- From RM E.2.2(14), no anonymous access parameter other than
1396 -- controlling ones may be used (because an anonymous access
1397 -- type never supports external streaming).
1399 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1401 elsif Is_Limited_Type (Param_Type) then
1403 -- Not a controlling parameter, so type must have Read and
1404 -- Write attributes.
1406 if No (TSS (Param_Type, TSS_Stream_Read))
1408 No (TSS (Param_Type, TSS_Stream_Write))
1411 ("limited formal must have Read and Write attributes",
1413 Explain_Limited_Type (Param_Type, Param_Spec);
1416 elsif Missing_Read_Write_Attributes (Param_Type)
1417 and then not Error_Posted (Param_Type)
1419 Illegal_RACW ("parameter containing non-remote access "
1420 & "must have Read and Write attributes", Param_Spec);
1423 -- Check next parameter in this subprogram
1425 Next_Formal (Param);
1429 Next_Elmt (Subprogram_Elmt);
1431 end Validate_RACW_Primitives;
1433 -------------------------------
1434 -- Validate_RCI_Declarations --
1435 -------------------------------
1437 procedure Validate_RCI_Declarations (P : Entity_Id) is
1441 E := First_Entity (P);
1442 while Present (E) loop
1443 if Comes_From_Source (E) then
1444 if Is_Limited_Type (E) then
1446 ("limited type not allowed in rci unit", Parent (E));
1447 Explain_Limited_Type (E, Parent (E));
1449 elsif Ekind (E) = E_Generic_Function
1450 or else Ekind (E) = E_Generic_Package
1451 or else Ekind (E) = E_Generic_Procedure
1453 Error_Msg_N ("generic declaration not allowed in rci unit",
1456 elsif (Ekind (E) = E_Function
1457 or else Ekind (E) = E_Procedure)
1458 and then Has_Pragma_Inline (E)
1461 ("inlined subprogram not allowed in rci unit", Parent (E));
1463 -- Inner packages that are renamings need not be checked. Generic
1464 -- RCI packages are subject to the checks, but entities that come
1465 -- from formal packages are not part of the visible declarations
1466 -- of the package and are not checked.
1468 elsif Ekind (E) = E_Package then
1469 if Present (Renamed_Entity (E)) then
1472 elsif Ekind (P) /= E_Generic_Package
1473 or else List_Containing (Unit_Declaration_Node (E)) /=
1474 Generic_Formal_Declarations
1475 (Unit_Declaration_Node (P))
1477 Validate_RCI_Declarations (E);
1484 end Validate_RCI_Declarations;
1486 -----------------------------------------
1487 -- Validate_RCI_Subprogram_Declaration --
1488 -----------------------------------------
1490 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1491 K : constant Node_Kind := Nkind (N);
1494 Param_Spec : Node_Id;
1495 Param_Type : Entity_Id;
1496 Base_Param_Type : Entity_Id;
1497 Base_Under_Type : Entity_Id;
1498 Type_Decl : Node_Id;
1499 Error_Node : Node_Id := N;
1502 -- This procedure enforces rules on subprogram and access to subprogram
1503 -- declarations in RCI units. These rules do not apply to expander
1504 -- generated routines, which are not remote subprograms. It is called:
1506 -- 1. from Analyze_Subprogram_Declaration.
1507 -- 2. from Validate_Object_Declaration (access to subprogram).
1509 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1513 if K = N_Subprogram_Declaration then
1514 Profile := Parameter_Specifications (Specification (N));
1516 else pragma Assert (K = N_Object_Declaration);
1518 -- The above assertion is dubious, the visible declarations of an
1519 -- RCI unit never contain an object declaration, this should be an
1520 -- ACCESS-to-object declaration???
1522 Id := Defining_Identifier (N);
1524 if Nkind (Id) = N_Defining_Identifier
1525 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1526 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1529 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1535 -- Iterate through the parameter specification list, checking that
1536 -- no access parameter and no limited type parameter in the list.
1539 if Present (Profile) then
1540 Param_Spec := First (Profile);
1541 while Present (Param_Spec) loop
1542 Param_Type := Etype (Defining_Identifier (Param_Spec));
1543 Type_Decl := Parent (Param_Type);
1545 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1547 if K = N_Subprogram_Declaration then
1548 Error_Node := Param_Spec;
1551 -- Report error only if declaration is in source program
1553 if Comes_From_Source
1554 (Defining_Entity (Specification (N)))
1557 ("subprogram in 'R'C'I unit cannot have access parameter",
1561 -- For a limited private type parameter, we check only the private
1562 -- declaration and ignore full type declaration, unless this is
1563 -- the only declaration for the type, e.g., as a limited record.
1565 elsif Is_Limited_Type (Param_Type)
1566 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1568 (Nkind (Type_Decl) = N_Full_Type_Declaration
1569 and then not (Has_Private_Declaration (Param_Type))
1570 and then Comes_From_Source (N)))
1572 -- A limited parameter is legal only if user-specified Read and
1573 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1575 if No (Full_View (Param_Type))
1576 and then Ekind (Param_Type) /= E_Record_Type
1578 -- Type does not have completion yet, so if declared in
1579 -- the current RCI scope it is illegal, and will be flagged
1585 -- In Ada 95 the rules permit using a limited type that has
1586 -- user-specified Read and Write attributes that are specified
1587 -- in the private part of the package, whereas Ada 2005
1588 -- (AI-240) revises this to require the attributes to be
1589 -- "available" (implying that the attribute clauses must be
1590 -- visible to the RCI client). The Ada 95 rules violate the
1591 -- contract model for privacy, but we support both semantics
1592 -- for now for compatibility (note that ACATS test BXE2009
1593 -- checks a case that conforms to the Ada 95 rules but is
1594 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1595 -- possibilities of visible TSS stream subprograms or explicit
1596 -- stream attribute definitions because the TSS subprograms
1597 -- can be hidden in the private part while the attribute
1598 -- definitions are still be available from the visible part.
1600 Base_Param_Type := Base_Type (Param_Type);
1601 Base_Under_Type := Base_Type (Underlying_Type
1604 if (Ada_Version < Ada_05
1606 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1608 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1610 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1612 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1614 (Ada_Version >= Ada_05
1616 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1618 No (TSS (Base_Param_Type, TSS_Stream_Write))
1620 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1622 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1624 (not Has_Stream_Attribute_Definition
1625 (Base_Param_Type, TSS_Stream_Read)
1627 not Has_Stream_Attribute_Definition
1628 (Base_Param_Type, TSS_Stream_Write)))
1630 if K = N_Subprogram_Declaration then
1631 Error_Node := Param_Spec;
1634 if Ada_Version >= Ada_05 then
1636 ("limited parameter in 'R'C'I unit "
1637 & "must have visible read/write attributes ",
1641 ("limited parameter in 'R'C'I unit "
1642 & "must have read/write attributes ",
1645 Explain_Limited_Type (Param_Type, Error_Node);
1648 -- In Ada 95, any non-remote access type (or any type with a
1649 -- component of a non-remote access type) that is visible in an
1650 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1651 -- unit, and thus is already guaranteed to support external
1652 -- streaming. However in Ada 2005 we have to account for the case
1653 -- of named access types from declared pure units as well, which
1654 -- may or may not support external streaming, and so we need to
1655 -- perform a specific check for E.2.3(14/2) here.
1657 -- Note that if the declaration of the type itself is illegal, we
1658 -- do not perform this check since it might be a cascaded error.
1661 if K = N_Subprogram_Declaration then
1662 Error_Node := Param_Spec;
1665 if Missing_Read_Write_Attributes (Param_Type)
1666 and then not Error_Posted (Param_Type)
1669 ("parameter containing non-remote access in 'R'C'I "
1670 & "subprogram must have visible "
1671 & "Read and Write attributes", Error_Node);
1677 -- No check on return type???
1679 end Validate_RCI_Subprogram_Declaration;
1681 ----------------------------------------------------
1682 -- Validate_Remote_Access_Object_Type_Declaration --
1683 ----------------------------------------------------
1685 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1687 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1688 -- True if tagged type E is a valid candidate as the root type of the
1689 -- designated type for a RACW, i.e. a tagged limited private type, or a
1690 -- limited interface type, or a private extension of such a type.
1692 ---------------------------------
1693 -- Is_Valid_Remote_Object_Type --
1694 ---------------------------------
1696 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1697 P : constant Node_Id := Parent (E);
1700 pragma Assert (Is_Tagged_Type (E));
1702 -- Simple case: a limited private type
1704 if Nkind (P) = N_Private_Type_Declaration
1705 and then Is_Limited_Record (E)
1709 -- A limited interface is not currently a legal ancestor for the
1710 -- designated type of an RACW type, because a type that implements
1711 -- such an interface need not be limited. However, the ARG seems to
1712 -- incline towards allowing an access to classwide limited interface
1713 -- type as a remote access type, as resolved in AI05-060. But note
1714 -- that the expansion circuitry for RACWs that designate classwide
1715 -- interfaces is not complete yet.
1717 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1720 -- A generic tagged limited type is a valid candidate. Limitedness
1721 -- will be checked again on the actual at instantiation point.
1723 elsif Nkind (P) = N_Formal_Type_Declaration
1724 and then Ekind (E) = E_Record_Type_With_Private
1725 and then Is_Generic_Type (E)
1726 and then Is_Limited_Record (E)
1730 -- A private extension declaration is a valid candidate if its parent
1733 elsif Nkind (P) = N_Private_Extension_Declaration then
1734 return Is_Valid_Remote_Object_Type (Etype (E));
1739 end Is_Valid_Remote_Object_Type;
1743 Direct_Designated_Type : Entity_Id;
1744 Desig_Type : Entity_Id;
1746 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1749 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1750 -- given node is N_Access_To_Object_Definition.
1752 if not Comes_From_Source (T)
1753 or else (not In_RCI_Declaration (Parent (T))
1754 and then not In_RT_Declaration)
1759 -- An access definition in the private part of a Remote Types package
1760 -- may be legal if it has user-defined Read and Write attributes. This
1761 -- will be checked at the end of the package spec processing.
1763 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1767 -- Check RCI or RT unit type declaration. It may not contain the
1768 -- declaration of an access-to-object type unless it is a general access
1769 -- type that designates a class-wide limited private type. There are
1770 -- also constraints on the primitive subprograms of the class-wide type
1771 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1773 if Ekind (T) /= E_General_Access_Type
1774 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1776 if In_RCI_Declaration (Parent (T)) then
1778 ("error in access type in Remote_Call_Interface unit", T);
1781 ("error in access type in Remote_Types unit", T);
1784 Error_Msg_N ("\must be general access to class-wide type", T);
1788 Direct_Designated_Type := Designated_Type (T);
1789 Desig_Type := Etype (Direct_Designated_Type);
1791 -- Why is the check below not in
1792 -- Validate_Remote_Access_To_Class_Wide_Type???
1794 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1796 ("error in designated type of remote access to class-wide type", T);
1798 ("\must be tagged limited private or private extension", T);
1801 end Validate_Remote_Access_Object_Type_Declaration;
1803 -----------------------------------------------
1804 -- Validate_Remote_Access_To_Class_Wide_Type --
1805 -----------------------------------------------
1807 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1808 K : constant Node_Kind := Nkind (N);
1809 PK : constant Node_Kind := Nkind (Parent (N));
1813 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1814 -- of class-wide limited private types.
1816 -- Storage_Pool and Storage_Size are not defined for such types
1818 -- The expected type of allocator must not be such a type.
1820 -- The actual parameter of generic instantiation must not be such a
1821 -- type if the formal parameter is of an access type.
1823 -- On entry, there are five cases
1825 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1826 -- either Storage_Pool or Storage_Size.
1828 -- 2. called from exp_ch4 Expand_N_Allocator
1830 -- 3. called from sem_ch12 Analyze_Associations
1832 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1834 -- 5. called from sem_res Resolve_Actuals
1836 if K = N_Attribute_Reference then
1837 E := Etype (Prefix (N));
1839 if Is_Remote_Access_To_Class_Wide_Type (E) then
1840 Error_Msg_N ("incorrect attribute of remote operand", N);
1844 elsif K = N_Allocator then
1847 if Is_Remote_Access_To_Class_Wide_Type (E) then
1848 Error_Msg_N ("incorrect expected remote type of allocator", N);
1852 elsif K in N_Has_Entity then
1855 if Is_Remote_Access_To_Class_Wide_Type (E) then
1856 Error_Msg_N ("incorrect remote type generic actual", N);
1860 -- This subprogram also enforces the checks in E.2.2(13). A value of
1861 -- such type must not be dereferenced unless as controlling operand of
1862 -- a dispatching call. Explicit dereferences not coming from source are
1863 -- exempted from this checking because the expander produces them in
1864 -- some cases (such as for tag checks on dispatching calls with multiple
1865 -- controlling operands). However we do check in the case of an implicit
1866 -- dereference that is expanded to an explicit dereference (hence the
1867 -- test of whether Original_Node (N) comes from source).
1869 elsif K = N_Explicit_Dereference
1870 and then Comes_From_Source (Original_Node (N))
1872 E := Etype (Prefix (N));
1874 -- If the class-wide type is not a remote one, the restrictions
1877 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1881 -- If we have a true dereference that comes from source and that
1882 -- is a controlling argument for a dispatching call, accept it.
1884 if Is_Actual_Parameter (N)
1885 and then Is_Controlling_Actual (N)
1890 -- If we are just within a procedure or function call and the
1891 -- dereference has not been analyzed, return because this procedure
1892 -- will be called again from sem_res Resolve_Actuals. The same can
1893 -- apply in the case of dereference that is the prefix of a selected
1894 -- component, which can be a call given in prefixed form.
1896 if (Is_Actual_Parameter (N)
1897 or else PK = N_Selected_Component)
1898 and then not Analyzed (N)
1903 -- We must allow expanded code to generate a reference to the tag of
1904 -- the designated object (may be either the actual tag, or the stub
1905 -- tag in the case of a remote object).
1907 if PK = N_Selected_Component
1908 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1914 ("invalid dereference of a remote access-to-class-wide value", N);
1916 end Validate_Remote_Access_To_Class_Wide_Type;
1918 ------------------------------------------
1919 -- Validate_Remote_Type_Type_Conversion --
1920 ------------------------------------------
1922 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1923 S : constant Entity_Id := Etype (N);
1924 E : constant Entity_Id := Etype (Expression (N));
1927 -- This test is required in the case where a conversion appears inside a
1928 -- normal package, it does not necessarily have to be inside an RCI,
1929 -- Remote_Types unit (RM E.2.2(9,12)).
1931 if Is_Remote_Access_To_Subprogram_Type (E)
1932 and then not Is_Remote_Access_To_Subprogram_Type (S)
1935 ("incorrect conversion of remote operand to local type", N);
1938 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1939 and then Is_Remote_Access_To_Subprogram_Type (S)
1942 ("incorrect conversion of local operand to remote type", N);
1945 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1946 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1949 ("incorrect conversion of remote operand to local type", N);
1953 -- If a local access type is converted into a RACW type, then the
1954 -- current unit has a pointer that may now be exported to another
1957 if Is_Remote_Access_To_Class_Wide_Type (S)
1958 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1960 Set_Has_RACW (Current_Sem_Unit);
1962 end Validate_Remote_Type_Type_Conversion;
1964 -------------------------------
1965 -- Validate_RT_RAT_Component --
1966 -------------------------------
1968 procedure Validate_RT_RAT_Component (N : Node_Id) is
1969 Spec : constant Node_Id := Specification (N);
1970 Name_U : constant Entity_Id := Defining_Entity (Spec);
1973 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1976 if not Is_Remote_Types (Name_U) then
1980 Typ := First_Entity (Name_U);
1981 while Present (Typ) and then Typ /= First_Priv_Ent loop
1982 U_Typ := Underlying_Type (Typ);
1988 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1989 if Missing_Read_Write_Attributes (Typ) then
1990 if Is_Non_Remote_Access_Type (Typ) then
1991 Error_Msg_N ("error in non-remote access type", U_Typ);
1994 ("error in record type containing a component of a " &
1995 "non-remote access type", U_Typ);
1998 if Ada_Version >= Ada_05 then
2000 ("\must have visible Read and Write attribute " &
2001 "definition clauses (RM E.2.2(8))", U_Typ);
2004 ("\must have Read and Write attribute " &
2005 "definition clauses (RM E.2.2(8))", U_Typ);
2012 end Validate_RT_RAT_Component;
2014 -----------------------------------------
2015 -- Validate_SP_Access_Object_Type_Decl --
2016 -----------------------------------------
2018 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2019 Direct_Designated_Type : Entity_Id;
2021 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2022 -- Return true if the protected type designated by T has
2023 -- entry declarations.
2025 ----------------------------
2026 -- Has_Entry_Declarations --
2027 ----------------------------
2029 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2033 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2034 Ety := First_Entity (E);
2035 while Present (Ety) loop
2036 if Ekind (Ety) = E_Entry then
2045 end Has_Entry_Declarations;
2047 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2050 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
2051 -- Nkind of the given entity is N_Access_To_Object_Definition.
2053 if not Comes_From_Source (T)
2054 or else not In_Shared_Passive_Unit
2055 or else In_Subprogram_Task_Protected_Unit
2060 -- Check Shared Passive unit. It should not contain the declaration
2061 -- of an access-to-object type whose designated type is a class-wide
2062 -- type, task type or protected type with entry (RM E.2.1(7)).
2064 Direct_Designated_Type := Designated_Type (T);
2066 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2068 ("invalid access-to-class-wide type in shared passive unit", T);
2071 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2073 ("invalid access-to-task type in shared passive unit", T);
2076 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2077 and then Has_Entry_Declarations (Direct_Designated_Type)
2080 ("invalid access-to-protected type in shared passive unit", T);
2083 end Validate_SP_Access_Object_Type_Decl;
2085 ---------------------------------
2086 -- Validate_Static_Object_Name --
2087 ---------------------------------
2089 procedure Validate_Static_Object_Name (N : Node_Id) is
2092 function Is_Primary (N : Node_Id) return Boolean;
2093 -- Determine whether node is syntactically a primary in an expression
2094 -- This function should probably be somewhere else ???
2095 -- Also it does not do what it says, e.g if N is a binary operator
2096 -- whose parent is a binary operator, Is_Primary returns True ???
2102 function Is_Primary (N : Node_Id) return Boolean is
2103 K : constant Node_Kind := Nkind (Parent (N));
2107 when N_Op | N_Membership_Test =>
2111 | N_Component_Association
2112 | N_Index_Or_Discriminant_Constraint =>
2115 when N_Attribute_Reference =>
2116 return Attribute_Name (Parent (N)) /= Name_Address
2117 and then Attribute_Name (Parent (N)) /= Name_Access
2118 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2120 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2122 when N_Indexed_Component =>
2123 return (N /= Prefix (Parent (N))
2124 or else Is_Primary (Parent (N)));
2126 when N_Qualified_Expression | N_Type_Conversion =>
2127 return Is_Primary (Parent (N));
2129 when N_Assignment_Statement | N_Object_Declaration =>
2130 return (N = Expression (Parent (N)));
2132 when N_Selected_Component =>
2133 return Is_Primary (Parent (N));
2140 -- Start of processing for Validate_Static_Object_Name
2143 if not In_Preelaborated_Unit
2144 or else not Comes_From_Source (N)
2145 or else In_Subprogram_Or_Concurrent_Unit
2146 or else Ekind (Current_Scope) = E_Block
2150 -- Filter out cases where primary is default in a component declaration,
2151 -- discriminant specification, or actual in a record type initialization
2154 -- Initialization call of internal types
2156 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2158 if Present (Parent (Parent (N)))
2159 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2164 if Nkind (Name (Parent (N))) = N_Identifier
2165 and then not Comes_From_Source (Entity (Name (Parent (N))))
2171 -- Error if the name is a primary in an expression. The parent must not
2172 -- be an operator, or a selected component or an indexed component that
2173 -- is itself a primary. Entities that are actuals do not need to be
2174 -- checked, because the call itself will be diagnosed.
2177 and then (not Inside_A_Generic
2178 or else Present (Enclosing_Generic_Body (N)))
2180 if Ekind (Entity (N)) = E_Variable
2181 or else Ekind (Entity (N)) in Formal_Object_Kind
2183 Flag_Non_Static_Expr
2184 ("non-static object name in preelaborated unit", N);
2186 -- We take the view that a constant defined in another preelaborated
2187 -- unit is preelaborable, even though it may have a private type and
2188 -- thus appear non-static in a client. This must be the intent of
2189 -- the language, but currently is an RM gap ???
2191 elsif Ekind (Entity (N)) = E_Constant
2192 and then not Is_Static_Expression (N)
2196 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2198 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2199 and then (Is_Preelaborated (Scope (E))
2200 or else Is_Pure (Scope (E))
2201 or else (Present (Renamed_Object (E))
2203 Is_Entity_Name (Renamed_Object (E))
2206 (Scope (Renamed_Object (E)))
2209 (Renamed_Object (E))))))
2213 -- This is the error case
2216 -- In GNAT mode, this is just a warning, to allow it to be
2217 -- judiciously turned off. Otherwise it is a real error.
2221 ("?non-static constant in preelaborated unit", N);
2223 Flag_Non_Static_Expr
2224 ("non-static constant in preelaborated unit", N);
2229 end Validate_Static_Object_Name;