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_Util; use Exp_Util;
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
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 types,
124 -- ordered so that a unit with a given categorization can only WITH
125 -- units with lower or equal categorization type.
127 -- Note that we take advantage of E.2(14) to define a category
128 -- Preelaborated and treat pragma Preelaborate as a categorization
129 -- pragma that defines that category.
131 type Categorization is
135 Remote_Call_Interface,
139 function Get_Categorization (E : Entity_Id) return Categorization;
140 -- Check categorization flags from entity, and return in the form
141 -- of the lowest value of the Categorization type that applies to E.
143 ------------------------
144 -- Get_Categorization --
145 ------------------------
147 function Get_Categorization (E : Entity_Id) return Categorization is
149 -- Get the lowest categorization that corresponds to E. Note that
150 -- nothing prevents several (different) categorization pragmas
151 -- to apply to the same library unit, in which case the unit has
152 -- all associated categories, so we need to be careful here to
153 -- check pragmas in proper Categorization order in order to
154 -- return the lowest appplicable value.
156 -- Ignore Pure specification if set by pragma Pure_Function
160 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
164 elsif Is_Shared_Passive (E) then
165 return Shared_Passive;
167 elsif Is_Remote_Types (E) then
170 elsif Is_Remote_Call_Interface (E) then
171 return Remote_Call_Interface;
173 elsif Is_Preelaborated (E) then
174 return Preelaborated;
179 end Get_Categorization;
181 Unit_Category : Categorization;
182 With_Category : Categorization;
184 -- Start of processing for Check_Categorization_Dependencies
187 -- Intrinsic subprograms are preelaborated, so do not impose any
188 -- categorization dependencies.
190 if Is_Intrinsic_Subprogram (Depended_Entity) then
194 Unit_Category := Get_Categorization (Unit_Entity);
195 With_Category := Get_Categorization (Depended_Entity);
197 -- These messages are wanings in GNAT mode, to allow it to be
198 -- judiciously turned off. Otherwise it is a real error.
200 Error_Msg_Warn := GNAT_Mode;
202 -- Check for possible error
204 if With_Category > Unit_Category then
206 -- Special case: Remote_Types and Remote_Call_Interface are allowed
207 -- to be with'ed in package body.
209 if (Unit_Category = Remote_Types
210 or else Unit_Category = Remote_Call_Interface)
211 and then In_Package_Body (Unit_Entity)
215 -- Here we have an error
218 -- Don't give error if main unit is not an internal unit, and the
219 -- unit generating the message is an internal unit. This is the
220 -- situation in which such messages would be ignored in any case,
221 -- so it is convenient not to generate them (since it causes
222 -- annoying interference with debugging).
224 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
225 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
231 elsif Is_Subunit then
233 ("<subunit cannot depend on& " &
234 "(parent has wrong categorization)", N, Depended_Entity);
236 -- Normal unit, not subunit
240 ("<cannot depend on& " &
241 "(wrong categorization)", N, Depended_Entity);
244 -- Add further explanation for common cases
246 case Unit_Category is
249 ("\<pure unit cannot depend on non-pure unit",
252 when Preelaborated =>
254 ("\<preelaborated unit cannot depend on " &
255 "non-preelaborated unit",
263 end Check_Categorization_Dependencies;
265 -----------------------------------
266 -- Check_Non_Static_Default_Expr --
267 -----------------------------------
269 procedure Check_Non_Static_Default_Expr
274 Component_Decl : Node_Id;
277 if Nkind (Type_Def) = N_Derived_Type_Definition then
278 Recdef := Record_Extension_Part (Type_Def);
288 -- Check that component declarations do not involve:
290 -- a. a non-static default expression, where the object is
291 -- declared to be default initialized.
293 -- b. a dynamic Itype (discriminants and constraints)
295 if Null_Present (Recdef) then
298 Component_Decl := First (Component_Items (Component_List (Recdef)));
301 while Present (Component_Decl)
302 and then Nkind (Component_Decl) = N_Component_Declaration
304 if Present (Expression (Component_Decl))
305 and then Nkind (Expression (Component_Decl)) /= N_Null
306 and then not Is_Static_Expression (Expression (Component_Decl))
308 Error_Msg_Sloc := Sloc (Component_Decl);
310 ("object in preelaborated unit has non-static default#",
313 -- Fix this later ???
315 -- elsif Has_Dynamic_Itype (Component_Decl) then
317 -- ("dynamic type discriminant," &
318 -- " constraint in preelaborated unit",
322 Next (Component_Decl);
324 end Check_Non_Static_Default_Expr;
326 -------------------------------------
327 -- Has_Stream_Attribute_Definition --
328 -------------------------------------
330 function Has_Stream_Attribute_Definition
333 At_Any_Place : Boolean := False) return Boolean
336 Full_Type : Entity_Id := Typ;
339 -- In the case of a type derived from a private view, any specified
340 -- stream attributes will be attached to the derived type's underlying
341 -- type rather the derived type entity itself (which is itself private).
343 if Is_Private_Type (Typ)
344 and then Is_Derived_Type (Typ)
345 and then Present (Full_View (Typ))
347 Full_Type := Underlying_Type (Typ);
350 -- We start from the declaration node and then loop until the end of
351 -- the list until we find the requested attribute definition clause.
352 -- In Ada 2005 mode, clauses are ignored if they are not currently
353 -- visible (this is tested using the corresponding Entity, which is
354 -- inserted by the expander at the point where the clause occurs),
355 -- unless At_Any_Place is true.
357 Rep_Item := First_Rep_Item (Full_Type);
358 while Present (Rep_Item) loop
359 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
360 case Chars (Rep_Item) is
362 exit when Nam = TSS_Stream_Read;
365 exit when Nam = TSS_Stream_Write;
368 exit when Nam = TSS_Stream_Input;
371 exit when Nam = TSS_Stream_Output;
379 Next_Rep_Item (Rep_Item);
382 -- If At_Any_Place is true, return True if the attribute is available
383 -- at any place; if it is false, return True only if the attribute is
384 -- currently visible.
386 return Present (Rep_Item)
387 and then (Ada_Version < Ada_05
389 or else not Is_Hidden (Entity (Rep_Item)));
390 end Has_Stream_Attribute_Definition;
392 ---------------------------
393 -- In_Preelaborated_Unit --
394 ---------------------------
396 function In_Preelaborated_Unit return Boolean is
397 Unit_Entity : constant Entity_Id := Current_Scope;
398 Unit_Kind : constant Node_Kind :=
399 Nkind (Unit (Cunit (Current_Sem_Unit)));
402 -- There are no constraints on body of remote_call_interface or
403 -- remote_types packages.
405 return (Unit_Entity /= Standard_Standard)
406 and then (Is_Preelaborated (Unit_Entity)
407 or else Is_Pure (Unit_Entity)
408 or else Is_Shared_Passive (Unit_Entity)
410 ((Is_Remote_Types (Unit_Entity)
411 or else Is_Remote_Call_Interface (Unit_Entity))
412 and then Ekind (Unit_Entity) = E_Package
413 and then Unit_Kind /= N_Package_Body
414 and then not In_Package_Body (Unit_Entity)
415 and then not In_Instance));
416 end In_Preelaborated_Unit;
422 function In_Pure_Unit return Boolean is
424 return Is_Pure (Current_Scope);
427 ------------------------
428 -- In_RCI_Declaration --
429 ------------------------
431 function In_RCI_Declaration (N : Node_Id) return Boolean is
432 Unit_Entity : constant Entity_Id := Current_Scope;
433 Unit_Kind : constant Node_Kind :=
434 Nkind (Unit (Cunit (Current_Sem_Unit)));
437 -- There are no restrictions on the private part or body
440 return Is_Remote_Call_Interface (Unit_Entity)
441 and then (Ekind (Unit_Entity) = E_Package
442 or else Ekind (Unit_Entity) = E_Generic_Package)
443 and then Unit_Kind /= N_Package_Body
444 and then List_Containing (N) =
446 (Specification (Unit_Declaration_Node (Unit_Entity)))
447 and then not In_Package_Body (Unit_Entity)
448 and then not In_Instance;
449 end In_RCI_Declaration;
451 -----------------------
452 -- In_RT_Declaration --
453 -----------------------
455 function In_RT_Declaration return Boolean is
456 Unit_Entity : constant Entity_Id := Current_Scope;
457 Unit_Kind : constant Node_Kind :=
458 Nkind (Unit (Cunit (Current_Sem_Unit)));
461 -- There are no restrictions on the body of a Remote Types unit
463 return Is_Remote_Types (Unit_Entity)
464 and then (Ekind (Unit_Entity) = E_Package
465 or else Ekind (Unit_Entity) = E_Generic_Package)
466 and then Unit_Kind /= N_Package_Body
467 and then not In_Package_Body (Unit_Entity)
468 and then not In_Instance;
469 end In_RT_Declaration;
471 ----------------------------
472 -- In_Shared_Passive_Unit --
473 ----------------------------
475 function In_Shared_Passive_Unit return Boolean is
476 Unit_Entity : constant Entity_Id := Current_Scope;
479 return Is_Shared_Passive (Unit_Entity);
480 end In_Shared_Passive_Unit;
482 ---------------------------------------
483 -- In_Subprogram_Task_Protected_Unit --
484 ---------------------------------------
486 function In_Subprogram_Task_Protected_Unit return Boolean is
490 -- The following is to verify that a declaration is inside
491 -- subprogram, generic subprogram, task unit, protected unit.
492 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
494 -- Use scope chain to check successively outer scopes
500 Is_Generic_Subprogram (E)
502 Is_Concurrent_Type (E)
506 elsif E = Standard_Standard then
512 end In_Subprogram_Task_Protected_Unit;
514 -------------------------------
515 -- Is_Non_Remote_Access_Type --
516 -------------------------------
518 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
519 U_E : constant Entity_Id := Underlying_Type (E);
523 -- This case arises for the case of a generic formal type, in which
524 -- case E.2.2(8) rules will be enforced at instantiation time.
529 return Is_Access_Type (U_E)
530 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
531 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
532 end Is_Non_Remote_Access_Type;
534 ------------------------------------
535 -- Is_Recursively_Limited_Private --
536 ------------------------------------
538 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
539 P : constant Node_Id := Parent (E);
542 if Nkind (P) = N_Private_Type_Declaration
543 and then Is_Limited_Record (E)
547 -- A limited interface is not currently a legal ancestor for the
548 -- designated type of an RACW type, because a type that implements
549 -- such an interface need not be limited. However, the ARG seems to
550 -- incline towards allowing an access to classwide limited interface
551 -- type as a remote access type. This may be revised when the ARG
552 -- rules on this question, but it seems safe to allow it for now,
553 -- in order to see whether it is a useful extension for distributed
554 -- programming, in particular for Brad Moore's buffer taxonomy.
556 elsif Is_Limited_Record (E)
557 and then Is_Limited_Interface (E)
561 elsif Nkind (P) = N_Private_Extension_Declaration then
562 return Is_Recursively_Limited_Private (Etype (E));
564 elsif Nkind (P) = N_Formal_Type_Declaration
565 and then Ekind (E) = E_Record_Type_With_Private
566 and then Is_Generic_Type (E)
567 and then Is_Limited_Record (E)
573 end Is_Recursively_Limited_Private;
575 ----------------------------------
576 -- Missing_Read_Write_Attribute --
577 ----------------------------------
579 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
580 Component : Entity_Id;
581 Component_Type : Entity_Id;
582 U_E : constant Entity_Id := Underlying_Type (E);
584 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
585 -- Return True if entity has attribute definition clauses for Read and
586 -- Write attributes that are visible at some place.
588 -------------------------------
589 -- Has_Read_Write_Attributes --
590 -------------------------------
592 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
595 and then Has_Stream_Attribute_Definition (E,
596 TSS_Stream_Read, At_Any_Place => True)
597 and then Has_Stream_Attribute_Definition (E,
598 TSS_Stream_Write, At_Any_Place => True);
599 end Has_Read_Write_Attributes;
601 -- Start of processing for Missing_Read_Write_Attributes
607 elsif Has_Read_Write_Attributes (E)
608 or else Has_Read_Write_Attributes (U_E)
612 elsif Is_Non_Remote_Access_Type (U_E) then
616 if Is_Record_Type (U_E) then
617 Component := First_Entity (U_E);
618 while Present (Component) loop
619 if not Is_Tag (Component) then
620 Component_Type := Etype (Component);
622 if Missing_Read_Write_Attributes (Component_Type) then
627 Next_Entity (Component);
632 end Missing_Read_Write_Attributes;
634 -------------------------------------
635 -- Set_Categorization_From_Pragmas --
636 -------------------------------------
638 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
639 P : constant Node_Id := Parent (N);
640 S : constant Entity_Id := Current_Scope;
642 procedure Set_Parents (Visibility : Boolean);
643 -- If this is a child instance, the parents are not immediately
644 -- visible during analysis. Make them momentarily visible so that
645 -- the argument of the pragma can be resolved properly, and reset
652 procedure Set_Parents (Visibility : Boolean) is
656 while Present (Par) and then Par /= Standard_Standard loop
657 Set_Is_Immediately_Visible (Par, Visibility);
662 -- Start of processing for Set_Categorization_From_Pragmas
665 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
666 -- The purpose is to set categorization flags before analyzing the
667 -- unit itself, so as to diagnose violations of categorization as
668 -- we process each declaration, even though the pragma appears after
671 if Nkind (P) /= N_Compilation_Unit then
680 and then Is_Generic_Instance (S)
685 PN := First (Pragmas_After (Aux_Decls_Node (P)));
686 while Present (PN) loop
688 -- Skip implicit types that may have been introduced by
689 -- previous analysis.
691 if Nkind (PN) = N_Pragma then
692 case Get_Pragma_Id (PN) is
693 when Pragma_All_Calls_Remote |
694 Pragma_Preelaborate |
696 Pragma_Remote_Call_Interface |
697 Pragma_Remote_Types |
698 Pragma_Shared_Passive => Analyze (PN);
707 and then Is_Generic_Instance (S)
712 end Set_Categorization_From_Pragmas;
714 -----------------------------------
715 -- Set_Categorization_From_Scope --
716 -----------------------------------
718 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
719 Declaration : Node_Id := Empty;
720 Specification : Node_Id := Empty;
724 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
726 if not Is_Remote_Call_Interface (E) then
727 if Ekind (E) in Subprogram_Kind then
728 Declaration := Unit_Declaration_Node (E);
730 if Nkind (Declaration) = N_Subprogram_Body
732 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
734 Specification := Corresponding_Spec (Declaration);
738 -- A subprogram body or renaming-as-body is a remote call
739 -- interface if it serves as the completion of a subprogram
740 -- declaration that is a remote call interface.
742 if Nkind (Specification) in N_Entity then
743 Set_Is_Remote_Call_Interface
744 (E, Is_Remote_Call_Interface (Specification));
746 -- A subprogram declaration is a remote call interface when it is
747 -- declared within the visible part of, or declared by, a library
748 -- unit declaration that is a remote call interface.
751 Set_Is_Remote_Call_Interface
752 (E, Is_Remote_Call_Interface (Scop)
753 and then not (In_Private_Part (Scop)
754 or else In_Package_Body (Scop)));
758 Set_Is_Remote_Types (E, Is_Remote_Types (Scop));
759 end Set_Categorization_From_Scope;
761 ------------------------------
762 -- Static_Discriminant_Expr --
763 ------------------------------
765 -- We need to accomodate a Why_Not_Static call somehow here ???
767 function Static_Discriminant_Expr (L : List_Id) return Boolean is
768 Discriminant_Spec : Node_Id;
771 Discriminant_Spec := First (L);
772 while Present (Discriminant_Spec) loop
773 if Present (Expression (Discriminant_Spec))
774 and then not Is_Static_Expression (Expression (Discriminant_Spec))
779 Next (Discriminant_Spec);
783 end Static_Discriminant_Expr;
785 --------------------------------------
786 -- Validate_Access_Type_Declaration --
787 --------------------------------------
789 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
790 Def : constant Node_Id := Type_Definition (N);
795 -- Access to subprogram case
797 when N_Access_To_Subprogram_Definition =>
799 -- A pure library_item must not contain the declaration of a
800 -- named access type, except within a subprogram, generic
801 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
803 -- This test is skipped in Ada 2005 (see AI-366)
805 if Ada_Version < Ada_05
806 and then Comes_From_Source (T)
807 and then In_Pure_Unit
808 and then not In_Subprogram_Task_Protected_Unit
810 Error_Msg_N ("named access type not allowed in pure unit", T);
813 -- Access to object case
815 when N_Access_To_Object_Definition =>
816 if Comes_From_Source (T)
817 and then In_Pure_Unit
818 and then not In_Subprogram_Task_Protected_Unit
820 -- We can't give the message yet, since the type is not frozen
821 -- and in Ada 2005 mode, access types are allowed in pure units
822 -- if the type has no storage pool (see AI-366). So we set a
823 -- flag which will be checked at freeze time.
825 Set_Is_Pure_Unit_Access_Type (T);
828 -- Check for RCI or RT unit type declaration: declaration of an
829 -- access-to-object type is illegal unless it is a general access
830 -- type that designates a class-wide limited private type.
831 -- Note that constraints on the primitive subprograms of the
832 -- designated tagged type are not enforced here but in
833 -- Validate_RACW_Primitives, which is done separately because the
834 -- designated type might not be frozen (and therefore its
835 -- primitive operations might not be completely known) at the
836 -- point of the RACW declaration.
838 Validate_Remote_Access_Object_Type_Declaration (T);
840 -- Check for shared passive unit type declaration. It should
841 -- not contain the declaration of access to class wide type,
842 -- access to task type and access to protected type with entry.
844 Validate_SP_Access_Object_Type_Decl (T);
850 -- Set categorization flag from package on entity as well, to allow
851 -- easy checks later on for required validations of RCI or RT units.
852 -- This is only done for entities that are in the original source.
854 if Comes_From_Source (T)
855 and then not (In_Package_Body (Scope (T))
856 or else In_Private_Part (Scope (T)))
858 Set_Is_Remote_Call_Interface
859 (T, Is_Remote_Call_Interface (Scope (T)));
861 (T, Is_Remote_Types (Scope (T)));
863 end Validate_Access_Type_Declaration;
865 ----------------------------
866 -- Validate_Ancestor_Part --
867 ----------------------------
869 procedure Validate_Ancestor_Part (N : Node_Id) is
870 A : constant Node_Id := Ancestor_Part (N);
871 T : constant Entity_Id := Entity (A);
874 if In_Preelaborated_Unit
875 and then not In_Subprogram_Or_Concurrent_Unit
876 and then (not Inside_A_Generic
877 or else Present (Enclosing_Generic_Body (N)))
879 -- If the type is private, it must have the Ada 2005 pragma
880 -- Has_Preelaborable_Initialization.
881 -- The check is omitted within predefined units. This is probably
882 -- obsolete code to fix the Ada95 weakness in this area ???
884 if Is_Private_Type (T)
885 and then not Has_Pragma_Preelab_Init (T)
886 and then not Is_Internal_File_Name
887 (Unit_File_Name (Get_Source_Unit (N)))
890 ("private ancestor type not allowed in preelaborated unit", A);
892 elsif Is_Record_Type (T) then
893 if Nkind (Parent (T)) = N_Full_Type_Declaration then
894 Check_Non_Static_Default_Expr
895 (Type_Definition (Parent (T)), A);
899 end Validate_Ancestor_Part;
901 ----------------------------------------
902 -- Validate_Categorization_Dependency --
903 ----------------------------------------
905 procedure Validate_Categorization_Dependency
909 K : constant Node_Kind := Nkind (N);
910 P : Node_Id := Parent (N);
912 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
915 -- Only validate library units and subunits. For subunits, checks
916 -- concerning withed units apply to the parent compilation unit.
923 and then not Is_Compilation_Unit (U)
924 and then not Is_Child_Unit (U)
930 if Nkind (P) /= N_Compilation_Unit then
934 -- Body of RCI unit does not need validation
936 if Is_Remote_Call_Interface (E)
937 and then (Nkind (N) = N_Package_Body
938 or else Nkind (N) = N_Subprogram_Body)
943 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
947 Entity_Of_Withed : Entity_Id;
950 Item := First (Context_Items (P));
951 while Present (Item) loop
952 if Nkind (Item) = N_With_Clause
953 and then not (Implicit_With (Item)
954 or else Limited_Present (Item))
956 Entity_Of_Withed := Entity (Name (Item));
957 Check_Categorization_Dependencies
958 (U, Entity_Of_Withed, Item, Is_Subunit);
965 -- Child depends on parent; therefore parent should also be categorized
966 -- and satify the dependency hierarchy.
968 -- Check if N is a child spec
970 if (K in N_Generic_Declaration or else
971 K in N_Generic_Instantiation or else
972 K in N_Generic_Renaming_Declaration or else
973 K = N_Package_Declaration or else
974 K = N_Package_Renaming_Declaration or else
975 K = N_Subprogram_Declaration or else
976 K = N_Subprogram_Renaming_Declaration)
977 and then Present (Parent_Spec (N))
979 Check_Categorization_Dependencies (E, Scope (E), N, False);
981 -- Verify that public child of an RCI library unit must also be an
982 -- RCI library unit (RM E.2.3(15)).
984 if Is_Remote_Call_Interface (Scope (E))
985 and then not Private_Present (P)
986 and then not Is_Remote_Call_Interface (E)
988 Error_Msg_N ("public child of rci unit must also be rci unit", N);
991 end Validate_Categorization_Dependency;
993 --------------------------------
994 -- Validate_Controlled_Object --
995 --------------------------------
997 procedure Validate_Controlled_Object (E : Entity_Id) is
999 -- Don't need this check in Ada 2005 mode, where this is all taken
1000 -- care of by the mechanism for Preelaborable Initialization.
1002 if Ada_Version >= Ada_05 then
1006 -- For now, never apply this check for internal GNAT units, since we
1007 -- have a number of cases in the library where we are stuck with objects
1008 -- of this type, and the RM requires Preelaborate.
1010 -- For similar reasons, we only do this check for source entities, since
1011 -- we generate entities of this type in some situations.
1013 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1014 -- We have to enforce them for RM compatibility, but we have no trouble
1015 -- accepting these objects and doing the right thing. Note that there is
1016 -- no requirement that Preelaborate not actually generate any code!
1018 if In_Preelaborated_Unit
1019 and then not Debug_Flag_PP
1020 and then Comes_From_Source (E)
1022 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1023 and then (not Inside_A_Generic
1024 or else Present (Enclosing_Generic_Body (E)))
1025 and then not Is_Protected_Type (Etype (E))
1028 ("library level controlled object not allowed in " &
1029 "preelaborated unit", E);
1031 end Validate_Controlled_Object;
1033 --------------------------------------
1034 -- Validate_Null_Statement_Sequence --
1035 --------------------------------------
1037 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1041 if In_Preelaborated_Unit then
1042 Item := First (Statements (Handled_Statement_Sequence (N)));
1043 while Present (Item) loop
1044 if Nkind (Item) /= N_Label
1045 and then Nkind (Item) /= N_Null_Statement
1047 -- In GNAT mode, this is a warning, allowing the run-time
1048 -- to judiciously bypass this error condition.
1050 Error_Msg_Warn := GNAT_Mode;
1052 ("<statements not allowed in preelaborated unit", Item);
1060 end Validate_Null_Statement_Sequence;
1062 ---------------------------------
1063 -- Validate_Object_Declaration --
1064 ---------------------------------
1066 procedure Validate_Object_Declaration (N : Node_Id) is
1067 Id : constant Entity_Id := Defining_Identifier (N);
1068 E : constant Node_Id := Expression (N);
1069 Odf : constant Node_Id := Object_Definition (N);
1070 T : constant Entity_Id := Etype (Id);
1073 -- Verify that any access to subprogram object does not have in its
1074 -- subprogram profile access type parameters or limited parameters
1075 -- without Read and Write attributes (E.2.3(13)).
1077 Validate_RCI_Subprogram_Declaration (N);
1079 -- Check that if we are in preelaborated elaboration code, then we
1080 -- do not have an instance of a default initialized private, task or
1081 -- protected object declaration which would violate (RM 10.2.1(9)).
1082 -- Note that constants are never default initialized (and the test
1083 -- below also filters out deferred constants). A variable is default
1084 -- initialized if it does *not* have an initialization expression.
1086 -- Filter out cases that are not declaration of a variable from source
1088 if Nkind (N) /= N_Object_Declaration
1089 or else Constant_Present (N)
1090 or else not Comes_From_Source (Id)
1095 -- Exclude generic specs from the checks (this will get rechecked
1096 -- on instantiations).
1099 and then No (Enclosing_Generic_Body (Id))
1104 -- Required checks for declaration that is in a preelaborated
1105 -- package and is not within some subprogram.
1107 if In_Preelaborated_Unit
1108 and then not In_Subprogram_Or_Concurrent_Unit
1110 -- Check for default initialized variable case. Note that in
1111 -- accordance with (RM B.1(24)) imported objects are not
1112 -- subject to default initialization.
1113 -- If the initialization does not come from source and is an
1114 -- aggregate, it is a static initialization that replaces an
1115 -- implicit call, and must be treated as such.
1119 (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1123 elsif Is_Imported (Id) then
1128 Ent : Entity_Id := T;
1131 -- An array whose component type is a record with nonstatic
1132 -- default expressions is a violation, so we get the array's
1135 if Is_Array_Type (Ent) then
1137 Comp_Type : Entity_Id;
1140 Comp_Type := Component_Type (Ent);
1141 while Is_Array_Type (Comp_Type) loop
1142 Comp_Type := Component_Type (Comp_Type);
1149 -- Object decl. that is of record type and has no default expr.
1150 -- should check if there is any non-static default expression
1151 -- in component decl. of the record type decl.
1153 if Is_Record_Type (Ent) then
1154 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1155 Check_Non_Static_Default_Expr
1156 (Type_Definition (Parent (Ent)), N);
1158 elsif Nkind (Odf) = N_Subtype_Indication
1159 and then not Is_Array_Type (T)
1160 and then not Is_Private_Type (T)
1162 Check_Non_Static_Default_Expr (Type_Definition
1163 (Parent (Entity (Subtype_Mark (Odf)))), N);
1167 -- Check for invalid use of private object. Note that Ada 2005
1168 -- AI-161 modifies the rules for Ada 2005, including the use of
1169 -- the new pragma Preelaborable_Initialization.
1171 if Is_Private_Type (Ent)
1172 or else Depends_On_Private (Ent)
1174 -- Case where type has preelaborable initialization which
1175 -- means that a pragma Preelaborable_Initialization was
1176 -- given for the private type.
1178 if Has_Preelaborable_Initialization (Ent) then
1180 -- But for the predefined units, we will ignore this
1181 -- status unless we are in Ada 2005 mode since we want
1182 -- Ada 95 compatible behavior, in which the entities
1183 -- marked with this pragma in the predefined library are
1184 -- not treated specially.
1186 if Ada_Version < Ada_05 then
1188 ("private object not allowed in preelaborated unit",
1190 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1193 -- Type does not have preelaborable initialization
1196 -- We allow this when compiling in GNAT mode to make life
1197 -- easier for some cases where it would otherwise be hard
1198 -- to be exactly valid Ada.
1200 if not GNAT_Mode then
1202 ("private object not allowed in preelaborated unit",
1205 -- Add a message if it would help to provide a pragma
1206 -- Preelaborable_Initialization on the type of the
1207 -- object (which would make it legal in Ada 2005).
1209 -- If the type has no full view (generic type, or
1210 -- previous error), the warning does not apply.
1212 if Is_Private_Type (Ent)
1213 and then Present (Full_View (Ent))
1215 Has_Preelaborable_Initialization (Full_View (Ent))
1217 Error_Msg_Sloc := Sloc (Ent);
1219 if Ada_Version >= Ada_05 then
1221 ("\would be legal if pragma Preelaborable_" &
1222 "Initialization given for & #", N, Ent);
1225 ("\would be legal in Ada 2005 if pragma " &
1226 "Preelaborable_Initialization given for & #",
1233 -- Access to Task or Protected type
1235 elsif Is_Entity_Name (Odf)
1236 and then Present (Etype (Odf))
1237 and then Is_Access_Type (Etype (Odf))
1239 Ent := Designated_Type (Etype (Odf));
1241 elsif Is_Entity_Name (Odf) then
1242 Ent := Entity (Odf);
1244 elsif Nkind (Odf) = N_Subtype_Indication then
1245 Ent := Etype (Subtype_Mark (Odf));
1248 Nkind (Odf) = N_Constrained_Array_Definition
1250 Ent := Component_Type (T);
1256 if Is_Task_Type (Ent)
1257 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1260 ("concurrent object not allowed in preelaborated unit",
1267 -- Non-static discriminant not allowed in preelaborated unit
1268 -- Controlled object of a type with a user-defined Initialize
1269 -- is forbidden as well.
1271 if Is_Record_Type (Etype (Id)) then
1273 ET : constant Entity_Id := Etype (Id);
1274 EE : constant Entity_Id := Etype (Etype (Id));
1278 if Has_Discriminants (ET)
1279 and then Present (EE)
1283 if Nkind (PEE) = N_Full_Type_Declaration
1284 and then not Static_Discriminant_Expr
1285 (Discriminant_Specifications (PEE))
1288 ("non-static discriminant in preelaborated unit",
1293 if Has_Overriding_Initialize (ET) then
1295 ("controlled type& does not have"
1296 & " preelaborable initialization", N, ET);
1303 -- A pure library_item must not contain the declaration of any variable
1304 -- except within a subprogram, generic subprogram, task unit, or
1305 -- protected unit (RM 10.2.1(16)).
1308 and then not In_Subprogram_Task_Protected_Unit
1310 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1312 -- The visible part of an RCI library unit must not contain the
1313 -- declaration of a variable (RM E.1.3(9))
1315 elsif In_RCI_Declaration (N) then
1316 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1318 -- The visible part of a Shared Passive library unit must not contain
1319 -- the declaration of a variable (RM E.2.2(7))
1321 elsif In_RT_Declaration then
1323 ("variable declaration not allowed in remote types unit", N);
1326 end Validate_Object_Declaration;
1328 ------------------------------
1329 -- Validate_RACW_Primitives --
1330 ------------------------------
1332 procedure Validate_RACW_Primitives (T : Entity_Id) is
1333 Desig_Type : Entity_Id;
1334 Primitive_Subprograms : Elist_Id;
1335 Subprogram_Elmt : Elmt_Id;
1336 Subprogram : Entity_Id;
1337 Param_Spec : Node_Id;
1339 Param_Type : Entity_Id;
1342 procedure Illegal_RACW (Msg : String; N : Node_Id);
1343 -- Diagnose that T is illegal because of the given reason, associated
1344 -- with the location of node N.
1346 Illegal_RACW_Message_Issued : Boolean := False;
1347 -- Set True once Illegal_RACW has been called
1353 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1355 if not Illegal_RACW_Message_Issued then
1357 ("illegal remote access to class-wide type&", T);
1358 Illegal_RACW_Message_Issued := True;
1361 Error_Msg_Sloc := Sloc (N);
1362 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1365 -- Start of processing for Validate_RACW_Primitives
1368 Desig_Type := Etype (Designated_Type (T));
1370 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1372 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1373 while Subprogram_Elmt /= No_Elmt loop
1374 Subprogram := Node (Subprogram_Elmt);
1376 if Is_Predefined_Dispatching_Operation (Subprogram)
1377 or else Is_Hidden (Subprogram)
1379 goto Next_Subprogram;
1382 -- Check return type
1384 if Ekind (Subprogram) = E_Function then
1385 Rtyp := Etype (Subprogram);
1387 if Has_Controlling_Result (Subprogram) then
1390 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1391 Illegal_RACW ("anonymous access result", Rtyp);
1393 elsif Is_Limited_Type (Rtyp) then
1394 if No (TSS (Rtyp, TSS_Stream_Read))
1396 No (TSS (Rtyp, TSS_Stream_Write))
1399 ("limited return type must have Read and Write attributes",
1400 Parent (Subprogram));
1401 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1407 Param := First_Formal (Subprogram);
1408 while Present (Param) loop
1410 -- Now find out if this parameter is a controlling parameter
1412 Param_Spec := Parent (Param);
1413 Param_Type := Etype (Param);
1415 if Is_Controlling_Formal (Param) then
1417 -- It is a controlling parameter, so specific checks below
1422 elsif Ekind (Param_Type) = E_Anonymous_Access_Type
1423 or else Ekind (Param_Type) = E_Anonymous_Access_Subprogram_Type
1425 -- From RM E.2.2(14), no access parameter other than
1426 -- controlling ones may be used.
1428 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1430 elsif Is_Limited_Type (Param_Type) then
1432 -- Not a controlling parameter, so type must have Read and
1433 -- Write attributes.
1435 if No (TSS (Param_Type, TSS_Stream_Read))
1437 No (TSS (Param_Type, TSS_Stream_Write))
1440 ("limited formal must have Read and Write attributes",
1442 Explain_Limited_Type (Param_Type, Param_Spec);
1446 -- Check next parameter in this subprogram
1448 Next_Formal (Param);
1452 Next_Elmt (Subprogram_Elmt);
1454 end Validate_RACW_Primitives;
1456 -------------------------------
1457 -- Validate_RCI_Declarations --
1458 -------------------------------
1460 procedure Validate_RCI_Declarations (P : Entity_Id) is
1464 E := First_Entity (P);
1465 while Present (E) loop
1466 if Comes_From_Source (E) then
1467 if Is_Limited_Type (E) then
1469 ("limited type not allowed in rci unit", Parent (E));
1470 Explain_Limited_Type (E, Parent (E));
1472 elsif Ekind (E) = E_Generic_Function
1473 or else Ekind (E) = E_Generic_Package
1474 or else Ekind (E) = E_Generic_Procedure
1476 Error_Msg_N ("generic declaration not allowed in rci unit",
1479 elsif (Ekind (E) = E_Function
1480 or else Ekind (E) = E_Procedure)
1481 and then Has_Pragma_Inline (E)
1484 ("inlined subprogram not allowed in rci unit", Parent (E));
1486 -- Inner packages that are renamings need not be checked. Generic
1487 -- RCI packages are subject to the checks, but entities that come
1488 -- from formal packages are not part of the visible declarations
1489 -- of the package and are not checked.
1491 elsif Ekind (E) = E_Package then
1492 if Present (Renamed_Entity (E)) then
1495 elsif Ekind (P) /= E_Generic_Package
1496 or else List_Containing (Unit_Declaration_Node (E)) /=
1497 Generic_Formal_Declarations
1498 (Unit_Declaration_Node (P))
1500 Validate_RCI_Declarations (E);
1507 end Validate_RCI_Declarations;
1509 -----------------------------------------
1510 -- Validate_RCI_Subprogram_Declaration --
1511 -----------------------------------------
1513 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1514 K : constant Node_Kind := Nkind (N);
1517 Param_Spec : Node_Id;
1518 Param_Type : Entity_Id;
1519 Base_Param_Type : Entity_Id;
1520 Base_Under_Type : Entity_Id;
1521 Type_Decl : Node_Id;
1522 Error_Node : Node_Id := N;
1525 -- There are two possible cases in which this procedure is called:
1527 -- 1. called from Analyze_Subprogram_Declaration.
1528 -- 2. called from Validate_Object_Declaration (access to subprogram).
1530 if not In_RCI_Declaration (N) then
1534 if K = N_Subprogram_Declaration then
1535 Profile := Parameter_Specifications (Specification (N));
1537 else pragma Assert (K = N_Object_Declaration);
1538 Id := Defining_Identifier (N);
1540 if Nkind (Id) = N_Defining_Identifier
1541 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1542 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1545 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1551 -- Iterate through the parameter specification list, checking that
1552 -- no access parameter and no limited type parameter in the list.
1555 if Present (Profile) then
1556 Param_Spec := First (Profile);
1557 while Present (Param_Spec) loop
1558 Param_Type := Etype (Defining_Identifier (Param_Spec));
1559 Type_Decl := Parent (Param_Type);
1561 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1563 if K = N_Subprogram_Declaration then
1564 Error_Node := Param_Spec;
1567 -- Report error only if declaration is in source program
1569 if Comes_From_Source
1570 (Defining_Entity (Specification (N)))
1573 ("subprogram in rci unit cannot have access parameter",
1577 -- For a limited private type parameter, we check only the private
1578 -- declaration and ignore full type declaration, unless this is
1579 -- the only declaration for the type, e.g., as a limited record.
1581 elsif Is_Limited_Type (Param_Type)
1582 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1584 (Nkind (Type_Decl) = N_Full_Type_Declaration
1585 and then not (Has_Private_Declaration (Param_Type))
1586 and then Comes_From_Source (N)))
1588 -- A limited parameter is legal only if user-specified Read and
1589 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1591 if No (Full_View (Param_Type))
1592 and then Ekind (Param_Type) /= E_Record_Type
1594 -- Type does not have completion yet, so if declared in
1595 -- the current RCI scope it is illegal, and will be flagged
1601 -- In Ada 95 the rules permit using a limited type that has
1602 -- user-specified Read and Write attributes that are specified
1603 -- in the private part of the package, whereas Ada 2005
1604 -- (AI-240) revises this to require the attributes to be
1605 -- "available" (implying that the attribute clauses must be
1606 -- visible to the RCI client). The Ada 95 rules violate the
1607 -- contract model for privacy, but we support both semantics
1608 -- for now for compatibility (note that ACATS test BXE2009
1609 -- checks a case that conforms to the Ada 95 rules but is
1610 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1611 -- possibilities of visible TSS stream subprograms or explicit
1612 -- stream attribute definitions because the TSS subprograms
1613 -- can be hidden in the private part while the attribute
1614 -- definitions are still be available from the visible part.
1616 Base_Param_Type := Base_Type (Param_Type);
1617 Base_Under_Type := Base_Type (Underlying_Type
1620 if (Ada_Version < Ada_05
1622 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1624 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1626 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1628 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1630 (Ada_Version >= Ada_05
1632 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1634 No (TSS (Base_Param_Type, TSS_Stream_Write))
1636 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1638 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1640 (not Has_Stream_Attribute_Definition
1641 (Base_Param_Type, TSS_Stream_Read)
1643 not Has_Stream_Attribute_Definition
1644 (Base_Param_Type, TSS_Stream_Write)))
1646 if K = N_Subprogram_Declaration then
1647 Error_Node := Param_Spec;
1650 if Ada_Version >= Ada_05 then
1652 ("limited parameter in rci unit "
1653 & "must have visible read/write attributes ",
1657 ("limited parameter in rci unit "
1658 & "must have read/write attributes ",
1661 Explain_Limited_Type (Param_Type, Error_Node);
1668 end Validate_RCI_Subprogram_Declaration;
1670 ----------------------------------------------------
1671 -- Validate_Remote_Access_Object_Type_Declaration --
1672 ----------------------------------------------------
1674 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1675 Direct_Designated_Type : Entity_Id;
1676 Desig_Type : Entity_Id;
1679 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1680 -- given node is N_Access_To_Object_Definition.
1682 if not Comes_From_Source (T)
1683 or else (not In_RCI_Declaration (Parent (T))
1684 and then not In_RT_Declaration)
1689 -- An access definition in the private part of a Remote Types package
1690 -- may be legal if it has user-defined Read and Write attributes. This
1691 -- will be checked at the end of the package spec processing.
1693 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1697 -- Check RCI or RT unit type declaration. It may not contain the
1698 -- declaration of an access-to-object type unless it is a general access
1699 -- type that designates a class-wide limited private type. There are
1700 -- also constraints on the primitive subprograms of the class-wide type
1701 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1703 if Ekind (T) /= E_General_Access_Type
1704 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1706 if In_RCI_Declaration (Parent (T)) then
1708 ("error in access type in Remote_Call_Interface unit", T);
1711 ("error in access type in Remote_Types unit", T);
1714 Error_Msg_N ("\must be general access to class-wide type", T);
1718 Direct_Designated_Type := Designated_Type (T);
1719 Desig_Type := Etype (Direct_Designated_Type);
1721 if not Is_Recursively_Limited_Private (Desig_Type) then
1723 ("error in designated type of remote access to class-wide type", T);
1725 ("\must be tagged limited private or private extension", T);
1729 -- Now this is an RCI unit access-to-class-wide-limited-private type
1730 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1731 -- optimize later checks by avoiding tree traversal to find out if this
1732 -- entity is inside an RCI unit.
1734 Set_Is_Remote_Call_Interface (T);
1735 end Validate_Remote_Access_Object_Type_Declaration;
1737 -----------------------------------------------
1738 -- Validate_Remote_Access_To_Class_Wide_Type --
1739 -----------------------------------------------
1741 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1742 K : constant Node_Kind := Nkind (N);
1743 PK : constant Node_Kind := Nkind (Parent (N));
1747 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1748 -- of class-wide limited private types.
1750 -- Storage_Pool and Storage_Size are not defined for such types
1752 -- The expected type of allocator must not not be such a type.
1754 -- The actual parameter of generic instantiation must not be such a
1755 -- type if the formal parameter is of an access type.
1757 -- On entry, there are five cases
1759 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1760 -- either Storage_Pool or Storage_Size.
1762 -- 2. called from exp_ch4 Expand_N_Allocator
1764 -- 3. called from sem_ch12 Analyze_Associations
1766 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1768 -- 5. called from sem_res Resolve_Actuals
1770 if K = N_Attribute_Reference then
1771 E := Etype (Prefix (N));
1773 if Is_Remote_Access_To_Class_Wide_Type (E) then
1774 Error_Msg_N ("incorrect attribute of remote operand", N);
1778 elsif K = N_Allocator then
1781 if Is_Remote_Access_To_Class_Wide_Type (E) then
1782 Error_Msg_N ("incorrect expected remote type of allocator", N);
1786 elsif K in N_Has_Entity then
1789 if Is_Remote_Access_To_Class_Wide_Type (E) then
1790 Error_Msg_N ("incorrect remote type generic actual", N);
1794 -- This subprogram also enforces the checks in E.2.2(13). A value of
1795 -- such type must not be dereferenced unless as controlling operand of
1796 -- a dispatching call. Explicit dereferences not coming from source are
1797 -- exempted from this checking because the expander produces them in
1798 -- some cases (such as for tag checks on dispatching calls with multiple
1799 -- controlling operands). However we do check in the case of an implicit
1800 -- dereference that is expanded to an explicit dereference (hence the
1801 -- test of whether Original_Node (N) comes from source).
1803 elsif K = N_Explicit_Dereference
1804 and then Comes_From_Source (Original_Node (N))
1806 E := Etype (Prefix (N));
1808 -- If the class-wide type is not a remote one, the restrictions
1811 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1815 -- If we have a true dereference that comes from source and that
1816 -- is a controlling argument for a dispatching call, accept it.
1818 if Is_Actual_Parameter (N)
1819 and then Is_Controlling_Actual (N)
1824 -- If we are just within a procedure or function call and the
1825 -- dereference has not been analyzed, return because this procedure
1826 -- will be called again from sem_res Resolve_Actuals. The same can
1827 -- apply in the case of dereference that is the prefix of a selected
1828 -- component, which can be a call given in prefixed form.
1830 if (Is_Actual_Parameter (N)
1831 or else PK = N_Selected_Component)
1832 and then not Analyzed (N)
1837 -- We must allow expanded code to generate a reference to the tag of
1838 -- the designated object (may be either the actual tag, or the stub
1839 -- tag in the case of a remote object).
1841 if PK = N_Selected_Component
1842 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1848 ("invalid dereference of a remote access-to-class-wide value", N);
1850 end Validate_Remote_Access_To_Class_Wide_Type;
1852 ------------------------------------------
1853 -- Validate_Remote_Type_Type_Conversion --
1854 ------------------------------------------
1856 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1857 S : constant Entity_Id := Etype (N);
1858 E : constant Entity_Id := Etype (Expression (N));
1861 -- This test is required in the case where a conversion appears inside a
1862 -- normal package, it does not necessarily have to be inside an RCI,
1863 -- Remote_Types unit (RM E.2.2(9,12)).
1865 if Is_Remote_Access_To_Subprogram_Type (E)
1866 and then not Is_Remote_Access_To_Subprogram_Type (S)
1869 ("incorrect conversion of remote operand to local type", N);
1872 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1873 and then Is_Remote_Access_To_Subprogram_Type (S)
1876 ("incorrect conversion of local operand to remote type", N);
1879 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1880 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1883 ("incorrect conversion of remote operand to local type", N);
1887 -- If a local access type is converted into a RACW type, then the
1888 -- current unit has a pointer that may now be exported to another
1891 if Is_Remote_Access_To_Class_Wide_Type (S)
1892 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1894 Set_Has_RACW (Current_Sem_Unit);
1896 end Validate_Remote_Type_Type_Conversion;
1898 -------------------------------
1899 -- Validate_RT_RAT_Component --
1900 -------------------------------
1902 procedure Validate_RT_RAT_Component (N : Node_Id) is
1903 Spec : constant Node_Id := Specification (N);
1904 Name_U : constant Entity_Id := Defining_Entity (Spec);
1907 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1910 if not Is_Remote_Types (Name_U) then
1914 Typ := First_Entity (Name_U);
1915 while Present (Typ) and then Typ /= First_Priv_Ent loop
1916 U_Typ := Underlying_Type (Typ);
1922 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1923 if Missing_Read_Write_Attributes (Typ) then
1924 if Is_Non_Remote_Access_Type (Typ) then
1925 Error_Msg_N ("error in non-remote access type", U_Typ);
1928 ("error in record type containing a component of a " &
1929 "non-remote access type", U_Typ);
1932 if Ada_Version >= Ada_05 then
1934 ("\must have visible Read and Write attribute " &
1935 "definition clauses (RM E.2.2(8))", U_Typ);
1938 ("\must have Read and Write attribute " &
1939 "definition clauses (RM E.2.2(8))", U_Typ);
1946 end Validate_RT_RAT_Component;
1948 -----------------------------------------
1949 -- Validate_SP_Access_Object_Type_Decl --
1950 -----------------------------------------
1952 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1953 Direct_Designated_Type : Entity_Id;
1955 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1956 -- Return true if the protected type designated by T has
1957 -- entry declarations.
1959 ----------------------------
1960 -- Has_Entry_Declarations --
1961 ----------------------------
1963 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1967 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1968 Ety := First_Entity (E);
1969 while Present (Ety) loop
1970 if Ekind (Ety) = E_Entry then
1979 end Has_Entry_Declarations;
1981 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1984 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1985 -- Nkind of the given entity is N_Access_To_Object_Definition.
1987 if not Comes_From_Source (T)
1988 or else not In_Shared_Passive_Unit
1989 or else In_Subprogram_Task_Protected_Unit
1994 -- Check Shared Passive unit. It should not contain the declaration
1995 -- of an access-to-object type whose designated type is a class-wide
1996 -- type, task type or protected type with entry (RM E.2.1(7)).
1998 Direct_Designated_Type := Designated_Type (T);
2000 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2002 ("invalid access-to-class-wide type in shared passive unit", T);
2005 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2007 ("invalid access-to-task type in shared passive unit", T);
2010 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2011 and then Has_Entry_Declarations (Direct_Designated_Type)
2014 ("invalid access-to-protected type in shared passive unit", T);
2017 end Validate_SP_Access_Object_Type_Decl;
2019 ---------------------------------
2020 -- Validate_Static_Object_Name --
2021 ---------------------------------
2023 procedure Validate_Static_Object_Name (N : Node_Id) is
2026 function Is_Primary (N : Node_Id) return Boolean;
2027 -- Determine whether node is syntactically a primary in an expression
2028 -- This function should probably be somewhere else ???
2029 -- Also it does not do what it says, e.g if N is a binary operator
2030 -- whose parent is a binary operator, Is_Primary returns True ???
2036 function Is_Primary (N : Node_Id) return Boolean is
2037 K : constant Node_Kind := Nkind (Parent (N));
2041 when N_Op | N_Membership_Test =>
2045 | N_Component_Association
2046 | N_Index_Or_Discriminant_Constraint =>
2049 when N_Attribute_Reference =>
2050 return Attribute_Name (Parent (N)) /= Name_Address
2051 and then Attribute_Name (Parent (N)) /= Name_Access
2052 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2054 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2056 when N_Indexed_Component =>
2057 return (N /= Prefix (Parent (N))
2058 or else Is_Primary (Parent (N)));
2060 when N_Qualified_Expression | N_Type_Conversion =>
2061 return Is_Primary (Parent (N));
2063 when N_Assignment_Statement | N_Object_Declaration =>
2064 return (N = Expression (Parent (N)));
2066 when N_Selected_Component =>
2067 return Is_Primary (Parent (N));
2074 -- Start of processing for Validate_Static_Object_Name
2077 if not In_Preelaborated_Unit
2078 or else not Comes_From_Source (N)
2079 or else In_Subprogram_Or_Concurrent_Unit
2080 or else Ekind (Current_Scope) = E_Block
2084 -- Filter out cases where primary is default in a component declaration,
2085 -- discriminant specification, or actual in a record type initialization
2088 -- Initialization call of internal types
2090 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2092 if Present (Parent (Parent (N)))
2093 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2098 if Nkind (Name (Parent (N))) = N_Identifier
2099 and then not Comes_From_Source (Entity (Name (Parent (N))))
2105 -- Error if the name is a primary in an expression. The parent must not
2106 -- be an operator, or a selected component or an indexed component that
2107 -- is itself a primary. Entities that are actuals do not need to be
2108 -- checked, because the call itself will be diagnosed.
2111 and then (not Inside_A_Generic
2112 or else Present (Enclosing_Generic_Body (N)))
2114 if Ekind (Entity (N)) = E_Variable
2115 or else Ekind (Entity (N)) in Formal_Object_Kind
2117 Flag_Non_Static_Expr
2118 ("non-static object name in preelaborated unit", N);
2120 -- We take the view that a constant defined in another preelaborated
2121 -- unit is preelaborable, even though it may have a private type and
2122 -- thus appear non-static in a client. This must be the intent of
2123 -- the language, but currently is an RM gap ???
2125 elsif Ekind (Entity (N)) = E_Constant
2126 and then not Is_Static_Expression (N)
2130 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2132 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2133 and then (Is_Preelaborated (Scope (E))
2134 or else Is_Pure (Scope (E))
2135 or else (Present (Renamed_Object (E))
2137 Is_Entity_Name (Renamed_Object (E))
2140 (Scope (Renamed_Object (E)))
2143 (Renamed_Object (E))))))
2147 -- This is the error case
2150 -- In GNAT mode, this is just a warning, to allow it to be
2151 -- judiciously turned off. Otherwise it is a real error.
2155 ("?non-static constant in preelaborated unit", N);
2157 Flag_Non_Static_Expr
2158 ("non-static constant in preelaborated unit", N);
2163 end Validate_Static_Object_Name;