1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Fname; use Fname;
34 with 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
220 ("<subunit cannot depend on& " &
221 "(parent has wrong categorization)", N, Depended_Entity);
225 ("<cannot depend on& " &
226 "(wrong categorization)", N, Depended_Entity);
229 -- Add further explanation for common cases
231 case Unit_Category is
234 ("\<pure unit cannot depend on non-pure unit",
237 when Preelaborated =>
239 ("\<preelaborated unit cannot depend on " &
240 "non-preelaborated unit",
248 end Check_Categorization_Dependencies;
250 -----------------------------------
251 -- Check_Non_Static_Default_Expr --
252 -----------------------------------
254 procedure Check_Non_Static_Default_Expr
259 Component_Decl : Node_Id;
262 if Nkind (Type_Def) = N_Derived_Type_Definition then
263 Recdef := Record_Extension_Part (Type_Def);
273 -- Check that component declarations do not involve:
275 -- a. a non-static default expression, where the object is
276 -- declared to be default initialized.
278 -- b. a dynamic Itype (discriminants and constraints)
280 if Null_Present (Recdef) then
283 Component_Decl := First (Component_Items (Component_List (Recdef)));
286 while Present (Component_Decl)
287 and then Nkind (Component_Decl) = N_Component_Declaration
289 if Present (Expression (Component_Decl))
290 and then Nkind (Expression (Component_Decl)) /= N_Null
291 and then not Is_Static_Expression (Expression (Component_Decl))
293 Error_Msg_Sloc := Sloc (Component_Decl);
295 ("object in preelaborated unit has non-static default#",
298 -- Fix this later ???
300 -- elsif Has_Dynamic_Itype (Component_Decl) then
302 -- ("dynamic type discriminant," &
303 -- " constraint in preelaborated unit",
307 Next (Component_Decl);
309 end Check_Non_Static_Default_Expr;
311 -------------------------------------
312 -- Has_Stream_Attribute_Definition --
313 -------------------------------------
315 function Has_Stream_Attribute_Definition
318 At_Any_Place : Boolean := False) return Boolean
322 -- We start from the declaration node and then loop until the end of
323 -- the list until we find the requested attribute definition clause.
324 -- In Ada 2005 mode, clauses are ignored if they are not currently
325 -- visible (this is tested using the corresponding Entity, which is
326 -- inserted by the expander at the point where the clause occurs),
327 -- unless At_Any_Place is true.
329 Rep_Item := First_Rep_Item (Typ);
330 while Present (Rep_Item) loop
331 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
332 case Chars (Rep_Item) is
334 exit when Nam = TSS_Stream_Read;
337 exit when Nam = TSS_Stream_Write;
340 exit when Nam = TSS_Stream_Input;
343 exit when Nam = TSS_Stream_Output;
351 Next_Rep_Item (Rep_Item);
354 -- If At_Any_Place is true, return True if the attribute is available
355 -- at any place; if it is false, return True only if the attribute is
356 -- currently visible.
358 return Present (Rep_Item)
359 and then (Ada_Version < Ada_05
361 or else not Is_Hidden (Entity (Rep_Item)));
362 end Has_Stream_Attribute_Definition;
364 ---------------------------
365 -- In_Preelaborated_Unit --
366 ---------------------------
368 function In_Preelaborated_Unit return Boolean is
369 Unit_Entity : constant Entity_Id := Current_Scope;
370 Unit_Kind : constant Node_Kind :=
371 Nkind (Unit (Cunit (Current_Sem_Unit)));
374 -- There are no constraints on body of remote_call_interface or
375 -- remote_types packages.
377 return (Unit_Entity /= Standard_Standard)
378 and then (Is_Preelaborated (Unit_Entity)
379 or else Is_Pure (Unit_Entity)
380 or else Is_Shared_Passive (Unit_Entity)
382 ((Is_Remote_Types (Unit_Entity)
383 or else Is_Remote_Call_Interface (Unit_Entity))
384 and then Ekind (Unit_Entity) = E_Package
385 and then Unit_Kind /= N_Package_Body
386 and then not In_Package_Body (Unit_Entity)
387 and then not In_Instance));
388 end In_Preelaborated_Unit;
394 function In_Pure_Unit return Boolean is
396 return Is_Pure (Current_Scope);
399 ------------------------
400 -- In_RCI_Declaration --
401 ------------------------
403 function In_RCI_Declaration (N : Node_Id) return Boolean is
404 Unit_Entity : constant Entity_Id := Current_Scope;
405 Unit_Kind : constant Node_Kind :=
406 Nkind (Unit (Cunit (Current_Sem_Unit)));
409 -- There are no restrictions on the private part or body
412 return Is_Remote_Call_Interface (Unit_Entity)
413 and then (Ekind (Unit_Entity) = E_Package
414 or else Ekind (Unit_Entity) = E_Generic_Package)
415 and then Unit_Kind /= N_Package_Body
416 and then List_Containing (N) =
418 (Specification (Unit_Declaration_Node (Unit_Entity)))
419 and then not In_Package_Body (Unit_Entity)
420 and then not In_Instance;
421 end In_RCI_Declaration;
423 -----------------------
424 -- In_RT_Declaration --
425 -----------------------
427 function In_RT_Declaration return Boolean is
428 Unit_Entity : constant Entity_Id := Current_Scope;
429 Unit_Kind : constant Node_Kind :=
430 Nkind (Unit (Cunit (Current_Sem_Unit)));
433 -- There are no restrictions on the body of a Remote Types unit
435 return Is_Remote_Types (Unit_Entity)
436 and then (Ekind (Unit_Entity) = E_Package
437 or else Ekind (Unit_Entity) = E_Generic_Package)
438 and then Unit_Kind /= N_Package_Body
439 and then not In_Package_Body (Unit_Entity)
440 and then not In_Instance;
441 end In_RT_Declaration;
443 ----------------------------
444 -- In_Shared_Passive_Unit --
445 ----------------------------
447 function In_Shared_Passive_Unit return Boolean is
448 Unit_Entity : constant Entity_Id := Current_Scope;
451 return Is_Shared_Passive (Unit_Entity);
452 end In_Shared_Passive_Unit;
454 ---------------------------------------
455 -- In_Subprogram_Task_Protected_Unit --
456 ---------------------------------------
458 function In_Subprogram_Task_Protected_Unit return Boolean is
462 -- The following is to verify that a declaration is inside
463 -- subprogram, generic subprogram, task unit, protected unit.
464 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
466 -- Use scope chain to check successively outer scopes
472 Is_Generic_Subprogram (E)
474 Is_Concurrent_Type (E)
478 elsif E = Standard_Standard then
484 end In_Subprogram_Task_Protected_Unit;
486 -------------------------------
487 -- Is_Non_Remote_Access_Type --
488 -------------------------------
490 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
491 U_E : constant Entity_Id := Underlying_Type (E);
495 -- This case arises for the case of a generic formal type, in which
496 -- case E.2.2(8) rules will be enforced at instantiation time.
501 return Is_Access_Type (U_E)
502 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
503 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
504 end Is_Non_Remote_Access_Type;
506 ------------------------------------
507 -- Is_Recursively_Limited_Private --
508 ------------------------------------
510 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
511 P : constant Node_Id := Parent (E);
514 if Nkind (P) = N_Private_Type_Declaration
515 and then Is_Limited_Record (E)
519 -- A limited interface is not currently a legal ancestor for the
520 -- designated type of an RACW type, because a type that implements
521 -- such an interface need not be limited. However, the ARG seems to
522 -- incline towards allowing an access to classwide limited interface
523 -- type as a remote access type. This may be revised when the ARG
524 -- rules on this question, but it seems safe to allow it for now,
525 -- in order to see whether it is a useful extension for distributed
526 -- programming, in particular for Brad Moore's buffer taxonomy.
528 elsif Is_Limited_Record (E)
529 and then Is_Limited_Interface (E)
533 elsif Nkind (P) = N_Private_Extension_Declaration then
534 return Is_Recursively_Limited_Private (Etype (E));
536 elsif Nkind (P) = N_Formal_Type_Declaration
537 and then Ekind (E) = E_Record_Type_With_Private
538 and then Is_Generic_Type (E)
539 and then Is_Limited_Record (E)
545 end Is_Recursively_Limited_Private;
547 ----------------------------------
548 -- Missing_Read_Write_Attribute --
549 ----------------------------------
551 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
552 Component : Entity_Id;
553 Component_Type : Entity_Id;
554 U_E : constant Entity_Id := Underlying_Type (E);
556 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
557 -- Return True if entity has attribute definition clauses for Read and
558 -- Write attributes that are visible at some place.
560 -------------------------------
561 -- Has_Read_Write_Attributes --
562 -------------------------------
564 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
567 and then Has_Stream_Attribute_Definition (E,
568 TSS_Stream_Read, At_Any_Place => True)
569 and then Has_Stream_Attribute_Definition (E,
570 TSS_Stream_Write, At_Any_Place => True);
571 end Has_Read_Write_Attributes;
573 -- Start of processing for Missing_Read_Write_Attributes
579 elsif Has_Read_Write_Attributes (E)
580 or else Has_Read_Write_Attributes (U_E)
584 elsif Is_Non_Remote_Access_Type (U_E) then
588 if Is_Record_Type (U_E) then
589 Component := First_Entity (U_E);
590 while Present (Component) loop
591 if not Is_Tag (Component) then
592 Component_Type := Etype (Component);
594 if Missing_Read_Write_Attributes (Component_Type) then
599 Next_Entity (Component);
604 end Missing_Read_Write_Attributes;
606 -------------------------------------
607 -- Set_Categorization_From_Pragmas --
608 -------------------------------------
610 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
611 P : constant Node_Id := Parent (N);
612 S : constant Entity_Id := Current_Scope;
614 procedure Set_Parents (Visibility : Boolean);
615 -- If this is a child instance, the parents are not immediately
616 -- visible during analysis. Make them momentarily visible so that
617 -- the argument of the pragma can be resolved properly, and reset
624 procedure Set_Parents (Visibility : Boolean) is
628 while Present (Par) and then Par /= Standard_Standard loop
629 Set_Is_Immediately_Visible (Par, Visibility);
634 -- Start of processing for Set_Categorization_From_Pragmas
637 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
638 -- The purpose is to set categorization flags before analyzing the
639 -- unit itself, so as to diagnose violations of categorization as
640 -- we process each declaration, even though the pragma appears after
643 if Nkind (P) /= N_Compilation_Unit then
652 and then Is_Generic_Instance (S)
657 PN := First (Pragmas_After (Aux_Decls_Node (P)));
658 while Present (PN) loop
660 -- Skip implicit types that may have been introduced by
661 -- previous analysis.
663 if Nkind (PN) = N_Pragma then
665 case Get_Pragma_Id (Chars (PN)) is
666 when Pragma_All_Calls_Remote |
667 Pragma_Preelaborate |
669 Pragma_Remote_Call_Interface |
670 Pragma_Remote_Types |
671 Pragma_Shared_Passive => Analyze (PN);
680 and then Is_Generic_Instance (S)
685 end Set_Categorization_From_Pragmas;
687 -----------------------------------
688 -- Set_Categorization_From_Scope --
689 -----------------------------------
691 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
692 Declaration : Node_Id := Empty;
693 Specification : Node_Id := Empty;
697 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
699 if not Is_Remote_Call_Interface (E) then
700 if Ekind (E) in Subprogram_Kind then
701 Declaration := Unit_Declaration_Node (E);
703 if Nkind (Declaration) = N_Subprogram_Body
705 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
707 Specification := Corresponding_Spec (Declaration);
711 -- A subprogram body or renaming-as-body is a remote call
712 -- interface if it serves as the completion of a subprogram
713 -- declaration that is a remote call interface.
715 if Nkind (Specification) in N_Entity then
716 Set_Is_Remote_Call_Interface
717 (E, Is_Remote_Call_Interface (Specification));
719 -- A subprogram declaration is a remote call interface when it is
720 -- declared within the visible part of, or declared by, a library
721 -- unit declaration that is a remote call interface.
724 Set_Is_Remote_Call_Interface
725 (E, Is_Remote_Call_Interface (Scop)
726 and then not (In_Private_Part (Scop)
727 or else In_Package_Body (Scop)));
731 Set_Is_Remote_Types (E, Is_Remote_Types (Scop));
732 end Set_Categorization_From_Scope;
734 ------------------------------
735 -- Static_Discriminant_Expr --
736 ------------------------------
738 -- We need to accomodate a Why_Not_Static call somehow here ???
740 function Static_Discriminant_Expr (L : List_Id) return Boolean is
741 Discriminant_Spec : Node_Id;
744 Discriminant_Spec := First (L);
745 while Present (Discriminant_Spec) loop
746 if Present (Expression (Discriminant_Spec))
747 and then not Is_Static_Expression (Expression (Discriminant_Spec))
752 Next (Discriminant_Spec);
756 end Static_Discriminant_Expr;
758 --------------------------------------
759 -- Validate_Access_Type_Declaration --
760 --------------------------------------
762 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
763 Def : constant Node_Id := Type_Definition (N);
768 -- Access to subprogram case
770 when N_Access_To_Subprogram_Definition =>
772 -- A pure library_item must not contain the declaration of a
773 -- named access type, except within a subprogram, generic
774 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
776 -- This test is skipped in Ada 2005 (see AI-366)
778 if Ada_Version < Ada_05
779 and then Comes_From_Source (T)
780 and then In_Pure_Unit
781 and then not In_Subprogram_Task_Protected_Unit
783 Error_Msg_N ("named access type not allowed in pure unit", T);
786 -- Access to object case
788 when N_Access_To_Object_Definition =>
789 if Comes_From_Source (T)
790 and then In_Pure_Unit
791 and then not In_Subprogram_Task_Protected_Unit
793 -- We can't give the message yet, since the type is not frozen
794 -- and in Ada 2005 mode, access types are allowed in pure units
795 -- if the type has no storage pool (see AI-366). So we set a
796 -- flag which will be checked at freeze time.
798 Set_Is_Pure_Unit_Access_Type (T);
801 -- Check for RCI or RT unit type declaration: declaration of an
802 -- access-to-object type is illegal unless it is a general access
803 -- type that designates a class-wide limited private type.
804 -- Note that constraints on the primitive subprograms of the
805 -- designated tagged type are not enforced here but in
806 -- Validate_RACW_Primitives, which is done separately because the
807 -- designated type might not be frozen (and therefore its
808 -- primitive operations might not be completely known) at the
809 -- point of the RACW declaration.
811 Validate_Remote_Access_Object_Type_Declaration (T);
813 -- Check for shared passive unit type declaration. It should
814 -- not contain the declaration of access to class wide type,
815 -- access to task type and access to protected type with entry.
817 Validate_SP_Access_Object_Type_Decl (T);
823 -- Set categorization flag from package on entity as well, to allow
824 -- easy checks later on for required validations of RCI or RT units.
825 -- This is only done for entities that are in the original source.
827 if Comes_From_Source (T)
828 and then not (In_Package_Body (Scope (T))
829 or else In_Private_Part (Scope (T)))
831 Set_Is_Remote_Call_Interface
832 (T, Is_Remote_Call_Interface (Scope (T)));
834 (T, Is_Remote_Types (Scope (T)));
836 end Validate_Access_Type_Declaration;
838 ----------------------------
839 -- Validate_Ancestor_Part --
840 ----------------------------
842 procedure Validate_Ancestor_Part (N : Node_Id) is
843 A : constant Node_Id := Ancestor_Part (N);
844 T : constant Entity_Id := Entity (A);
847 if In_Preelaborated_Unit
848 and then not In_Subprogram_Or_Concurrent_Unit
849 and then (not Inside_A_Generic
850 or else Present (Enclosing_Generic_Body (N)))
852 -- If the type is private, it must have the Ada 2005 pragma
853 -- Has_Preelaborable_Initialization.
854 -- The check is omitted within predefined units. This is probably
855 -- obsolete code to fix the Ada95 weakness in this area ???
857 if Is_Private_Type (T)
858 and then not Has_Pragma_Preelab_Init (T)
859 and then not Is_Internal_File_Name
860 (Unit_File_Name (Get_Source_Unit (N)))
863 ("private ancestor type not allowed in preelaborated unit", A);
865 elsif Is_Record_Type (T) then
866 if Nkind (Parent (T)) = N_Full_Type_Declaration then
867 Check_Non_Static_Default_Expr
868 (Type_Definition (Parent (T)), A);
872 end Validate_Ancestor_Part;
874 ----------------------------------------
875 -- Validate_Categorization_Dependency --
876 ----------------------------------------
878 procedure Validate_Categorization_Dependency
882 K : constant Node_Kind := Nkind (N);
883 P : Node_Id := Parent (N);
885 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
888 -- Only validate library units and subunits. For subunits, checks
889 -- concerning withed units apply to the parent compilation unit.
896 and then not Is_Compilation_Unit (U)
897 and then not Is_Child_Unit (U)
903 if Nkind (P) /= N_Compilation_Unit then
907 -- Body of RCI unit does not need validation
909 if Is_Remote_Call_Interface (E)
910 and then (Nkind (N) = N_Package_Body
911 or else Nkind (N) = N_Subprogram_Body)
916 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
920 Entity_Of_Withed : Entity_Id;
923 Item := First (Context_Items (P));
924 while Present (Item) loop
925 if Nkind (Item) = N_With_Clause
926 and then not (Implicit_With (Item)
927 or else Limited_Present (Item))
929 Entity_Of_Withed := Entity (Name (Item));
930 Check_Categorization_Dependencies
931 (U, Entity_Of_Withed, Item, Is_Subunit);
938 -- Child depends on parent; therefore parent should also be categorized
939 -- and satify the dependency hierarchy.
941 -- Check if N is a child spec
943 if (K in N_Generic_Declaration or else
944 K in N_Generic_Instantiation or else
945 K in N_Generic_Renaming_Declaration or else
946 K = N_Package_Declaration or else
947 K = N_Package_Renaming_Declaration or else
948 K = N_Subprogram_Declaration or else
949 K = N_Subprogram_Renaming_Declaration)
950 and then Present (Parent_Spec (N))
952 Check_Categorization_Dependencies (E, Scope (E), N, False);
954 -- Verify that public child of an RCI library unit must also be an
955 -- RCI library unit (RM E.2.3(15)).
957 if Is_Remote_Call_Interface (Scope (E))
958 and then not Private_Present (P)
959 and then not Is_Remote_Call_Interface (E)
961 Error_Msg_N ("public child of rci unit must also be rci unit", N);
964 end Validate_Categorization_Dependency;
966 --------------------------------
967 -- Validate_Controlled_Object --
968 --------------------------------
970 procedure Validate_Controlled_Object (E : Entity_Id) is
972 -- Don't need this check in Ada 2005 mode, where this is all taken
973 -- care of by the mechanism for Preelaborable Initialization.
975 if Ada_Version >= Ada_05 then
979 -- For now, never apply this check for internal GNAT units, since we
980 -- have a number of cases in the library where we are stuck with objects
981 -- of this type, and the RM requires Preelaborate.
983 -- For similar reasons, we only do this check for source entities, since
984 -- we generate entities of this type in some situations.
986 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
987 -- We have to enforce them for RM compatibility, but we have no trouble
988 -- accepting these objects and doing the right thing. Note that there is
989 -- no requirement that Preelaborate not actually generate any code!
991 if In_Preelaborated_Unit
992 and then not Debug_Flag_PP
993 and then Comes_From_Source (E)
995 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
996 and then (not Inside_A_Generic
997 or else Present (Enclosing_Generic_Body (E)))
998 and then not Is_Protected_Type (Etype (E))
1001 ("library level controlled object not allowed in " &
1002 "preelaborated unit", E);
1004 end Validate_Controlled_Object;
1006 --------------------------------------
1007 -- Validate_Null_Statement_Sequence --
1008 --------------------------------------
1010 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1014 if In_Preelaborated_Unit then
1015 Item := First (Statements (Handled_Statement_Sequence (N)));
1016 while Present (Item) loop
1017 if Nkind (Item) /= N_Label
1018 and then Nkind (Item) /= N_Null_Statement
1020 -- In GNAT mode, this is a warning, allowing the run-time
1021 -- to judiciously bypass this error condition.
1023 Error_Msg_Warn := GNAT_Mode;
1025 ("<statements not allowed in preelaborated unit", Item);
1033 end Validate_Null_Statement_Sequence;
1035 ---------------------------------
1036 -- Validate_Object_Declaration --
1037 ---------------------------------
1039 procedure Validate_Object_Declaration (N : Node_Id) is
1040 Id : constant Entity_Id := Defining_Identifier (N);
1041 E : constant Node_Id := Expression (N);
1042 Odf : constant Node_Id := Object_Definition (N);
1043 T : constant Entity_Id := Etype (Id);
1046 -- Verify that any access to subprogram object does not have in its
1047 -- subprogram profile access type parameters or limited parameters
1048 -- without Read and Write attributes (E.2.3(13)).
1050 Validate_RCI_Subprogram_Declaration (N);
1052 -- Check that if we are in preelaborated elaboration code, then we
1053 -- do not have an instance of a default initialized private, task or
1054 -- protected object declaration which would violate (RM 10.2.1(9)).
1055 -- Note that constants are never default initialized (and the test
1056 -- below also filters out deferred constants). A variable is default
1057 -- initialized if it does *not* have an initialization expression.
1059 -- Filter out cases that are not declaration of a variable from source
1061 if Nkind (N) /= N_Object_Declaration
1062 or else Constant_Present (N)
1063 or else not Comes_From_Source (Id)
1068 -- Exclude generic specs from the checks (this will get rechecked
1069 -- on instantiations).
1072 and then No (Enclosing_Generic_Body (Id))
1077 -- Required checks for declaration that is in a preelaborated
1078 -- package and is not within some subprogram.
1080 if In_Preelaborated_Unit
1081 and then not In_Subprogram_Or_Concurrent_Unit
1083 -- Check for default initialized variable case. Note that in
1084 -- accordance with (RM B.1(24)) imported objects are not
1085 -- subject to default initialization.
1086 -- If the initialization does not come from source and is an
1087 -- aggregate, it is a static initialization that replaces an
1088 -- implicit call, and must be treated as such.
1092 (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1096 elsif Is_Imported (Id) then
1101 Ent : Entity_Id := T;
1104 -- An array whose component type is a record with nonstatic
1105 -- default expressions is a violation, so we get the array's
1108 if Is_Array_Type (Ent) then
1110 Comp_Type : Entity_Id;
1113 Comp_Type := Component_Type (Ent);
1114 while Is_Array_Type (Comp_Type) loop
1115 Comp_Type := Component_Type (Comp_Type);
1122 -- Object decl. that is of record type and has no default expr.
1123 -- should check if there is any non-static default expression
1124 -- in component decl. of the record type decl.
1126 if Is_Record_Type (Ent) then
1127 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1128 Check_Non_Static_Default_Expr
1129 (Type_Definition (Parent (Ent)), N);
1131 elsif Nkind (Odf) = N_Subtype_Indication
1132 and then not Is_Array_Type (T)
1133 and then not Is_Private_Type (T)
1135 Check_Non_Static_Default_Expr (Type_Definition
1136 (Parent (Entity (Subtype_Mark (Odf)))), N);
1140 -- Check for invalid use of private object. Note that Ada 2005
1141 -- AI-161 modifies the rules for Ada 2005, including the use of
1142 -- the new pragma Preelaborable_Initialization.
1144 if Is_Private_Type (Ent)
1145 or else Depends_On_Private (Ent)
1147 -- Case where type has preelaborable initialization which
1148 -- means that a pragma Preelaborable_Initialization was
1149 -- given for the private type.
1151 if Has_Preelaborable_Initialization (Ent) then
1153 -- But for the predefined units, we will ignore this
1154 -- status unless we are in Ada 2005 mode since we want
1155 -- Ada 95 compatible behavior, in which the entities
1156 -- marked with this pragma in the predefined library are
1157 -- not treated specially.
1159 if Ada_Version < Ada_05 then
1161 ("private object not allowed in preelaborated unit",
1163 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1166 -- Type does not have preelaborable initialization
1169 -- We allow this when compiling in GNAT mode to make life
1170 -- easier for some cases where it would otherwise be hard
1171 -- to be exactly valid Ada.
1173 if not GNAT_Mode then
1175 ("private object not allowed in preelaborated unit",
1178 -- Add a message if it would help to provide a pragma
1179 -- Preelaborable_Initialization on the type of the
1180 -- object (which would make it legal in Ada 2005).
1182 -- If the type has no full view (generic type, or
1183 -- previous error), the warning does not apply.
1185 if Is_Private_Type (Ent)
1186 and then Present (Full_View (Ent))
1188 Has_Preelaborable_Initialization (Full_View (Ent))
1190 Error_Msg_Sloc := Sloc (Ent);
1192 if Ada_Version >= Ada_05 then
1194 ("\would be legal if pragma Preelaborable_" &
1195 "Initialization given for & #", N, Ent);
1198 ("\would be legal in Ada 2005 if pragma " &
1199 "Preelaborable_Initialization given for & #",
1206 -- Access to Task or Protected type
1208 elsif Is_Entity_Name (Odf)
1209 and then Present (Etype (Odf))
1210 and then Is_Access_Type (Etype (Odf))
1212 Ent := Designated_Type (Etype (Odf));
1214 elsif Is_Entity_Name (Odf) then
1215 Ent := Entity (Odf);
1217 elsif Nkind (Odf) = N_Subtype_Indication then
1218 Ent := Etype (Subtype_Mark (Odf));
1221 Nkind (Odf) = N_Constrained_Array_Definition
1223 Ent := Component_Type (T);
1229 if Is_Task_Type (Ent)
1230 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1233 ("concurrent object not allowed in preelaborated unit",
1240 -- Non-static discriminant not allowed in preelaborayted unit
1242 if Is_Record_Type (Etype (Id)) then
1244 ET : constant Entity_Id := Etype (Id);
1245 EE : constant Entity_Id := Etype (Etype (Id));
1249 if Has_Discriminants (ET)
1250 and then Present (EE)
1254 if Nkind (PEE) = N_Full_Type_Declaration
1255 and then not Static_Discriminant_Expr
1256 (Discriminant_Specifications (PEE))
1259 ("non-static discriminant in preelaborated unit",
1267 -- A pure library_item must not contain the declaration of any variable
1268 -- except within a subprogram, generic subprogram, task unit, or
1269 -- protected unit (RM 10.2.1(16)).
1272 and then not In_Subprogram_Task_Protected_Unit
1274 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1276 -- The visible part of an RCI library unit must not contain the
1277 -- declaration of a variable (RM E.1.3(9))
1279 elsif In_RCI_Declaration (N) then
1280 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1282 -- The visible part of a Shared Passive library unit must not contain
1283 -- the declaration of a variable (RM E.2.2(7))
1285 elsif In_RT_Declaration then
1287 ("variable declaration not allowed in remote types unit", N);
1290 end Validate_Object_Declaration;
1292 ------------------------------
1293 -- Validate_RACW_Primitives --
1294 ------------------------------
1296 procedure Validate_RACW_Primitives (T : Entity_Id) is
1297 Desig_Type : Entity_Id;
1298 Primitive_Subprograms : Elist_Id;
1299 Subprogram_Elmt : Elmt_Id;
1300 Subprogram : Entity_Id;
1302 Param_Spec : Node_Id;
1304 Param_Type : Entity_Id;
1308 Desig_Type := Etype (Designated_Type (T));
1310 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1312 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1313 while Subprogram_Elmt /= No_Elmt loop
1314 Subprogram := Node (Subprogram_Elmt);
1316 if not Comes_From_Source (Subprogram) then
1317 goto Next_Subprogram;
1320 -- Check return type
1322 if Ekind (Subprogram) = E_Function then
1323 Rtyp := Etype (Subprogram);
1325 if Has_Controlling_Result (Subprogram) then
1328 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1330 ("anonymous access result in remote object primitive", Rtyp);
1332 elsif Is_Limited_Type (Rtyp) then
1333 if No (TSS (Rtyp, TSS_Stream_Read))
1335 No (TSS (Rtyp, TSS_Stream_Write))
1338 ("limited return type must have Read and Write attributes",
1339 Parent (Subprogram));
1340 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1346 Profile := Parameter_Specifications (Parent (Subprogram));
1348 -- Profile must exist, otherwise not primitive operation
1350 Param_Spec := First (Profile);
1351 while Present (Param_Spec) loop
1353 -- Now find out if this parameter is a controlling parameter
1355 Param := Defining_Identifier (Param_Spec);
1356 Param_Type := Etype (Param);
1358 if Is_Controlling_Formal (Param) then
1360 -- It is a controlling parameter, so specific checks below
1365 elsif Ekind (Param_Type) = E_Anonymous_Access_Type then
1367 -- From RM E.2.2(14), no access parameter other than
1368 -- controlling ones may be used.
1371 ("non-controlling access parameter", Param_Spec);
1373 elsif Is_Limited_Type (Param_Type) then
1375 -- Not a controlling parameter, so type must have Read and
1376 -- Write attributes.
1378 if No (TSS (Param_Type, TSS_Stream_Read))
1380 No (TSS (Param_Type, TSS_Stream_Write))
1383 ("limited formal must have Read and Write attributes",
1385 Explain_Limited_Type (Param_Type, Param_Spec);
1389 -- Check next parameter in this subprogram
1395 Next_Elmt (Subprogram_Elmt);
1397 end Validate_RACW_Primitives;
1399 -------------------------------
1400 -- Validate_RCI_Declarations --
1401 -------------------------------
1403 procedure Validate_RCI_Declarations (P : Entity_Id) is
1407 E := First_Entity (P);
1408 while Present (E) loop
1409 if Comes_From_Source (E) then
1410 if Is_Limited_Type (E) then
1412 ("limited type not allowed in rci unit", Parent (E));
1413 Explain_Limited_Type (E, Parent (E));
1415 elsif Ekind (E) = E_Generic_Function
1416 or else Ekind (E) = E_Generic_Package
1417 or else Ekind (E) = E_Generic_Procedure
1419 Error_Msg_N ("generic declaration not allowed in rci unit",
1422 elsif (Ekind (E) = E_Function
1423 or else Ekind (E) = E_Procedure)
1424 and then Has_Pragma_Inline (E)
1427 ("inlined subprogram not allowed in rci unit", Parent (E));
1429 -- Inner packages that are renamings need not be checked. Generic
1430 -- RCI packages are subject to the checks, but entities that come
1431 -- from formal packages are not part of the visible declarations
1432 -- of the package and are not checked.
1434 elsif Ekind (E) = E_Package then
1435 if Present (Renamed_Entity (E)) then
1438 elsif Ekind (P) /= E_Generic_Package
1439 or else List_Containing (Unit_Declaration_Node (E)) /=
1440 Generic_Formal_Declarations
1441 (Unit_Declaration_Node (P))
1443 Validate_RCI_Declarations (E);
1450 end Validate_RCI_Declarations;
1452 -----------------------------------------
1453 -- Validate_RCI_Subprogram_Declaration --
1454 -----------------------------------------
1456 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1457 K : constant Node_Kind := Nkind (N);
1460 Param_Spec : Node_Id;
1461 Param_Type : Entity_Id;
1462 Base_Param_Type : Entity_Id;
1463 Base_Under_Type : Entity_Id;
1464 Type_Decl : Node_Id;
1465 Error_Node : Node_Id := N;
1468 -- There are two possible cases in which this procedure is called:
1470 -- 1. called from Analyze_Subprogram_Declaration.
1471 -- 2. called from Validate_Object_Declaration (access to subprogram).
1473 if not In_RCI_Declaration (N) then
1477 if K = N_Subprogram_Declaration then
1478 Profile := Parameter_Specifications (Specification (N));
1480 else pragma Assert (K = N_Object_Declaration);
1481 Id := Defining_Identifier (N);
1483 if Nkind (Id) = N_Defining_Identifier
1484 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1485 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1488 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1494 -- Iterate through the parameter specification list, checking that
1495 -- no access parameter and no limited type parameter in the list.
1498 if Present (Profile) then
1499 Param_Spec := First (Profile);
1500 while Present (Param_Spec) loop
1501 Param_Type := Etype (Defining_Identifier (Param_Spec));
1502 Type_Decl := Parent (Param_Type);
1504 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1506 if K = N_Subprogram_Declaration then
1507 Error_Node := Param_Spec;
1510 -- Report error only if declaration is in source program
1512 if Comes_From_Source
1513 (Defining_Entity (Specification (N)))
1516 ("subprogram in rci unit cannot have access parameter",
1520 -- For limited private type parameter, we check only the private
1521 -- declaration and ignore full type declaration, unless this is
1522 -- the only declaration for the type, eg. as a limited record.
1524 elsif Is_Limited_Type (Param_Type)
1525 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1527 (Nkind (Type_Decl) = N_Full_Type_Declaration
1528 and then not (Has_Private_Declaration (Param_Type))
1529 and then Comes_From_Source (N)))
1531 -- A limited parameter is legal only if user-specified Read and
1532 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1534 if No (Full_View (Param_Type))
1535 and then Ekind (Param_Type) /= E_Record_Type
1537 -- Type does not have completion yet, so if declared in in
1538 -- the current RCI scope it is illegal, and will be flagged
1544 -- In Ada 95 the rules permit using a limited type that has
1545 -- user-specified Read and Write attributes that are specified
1546 -- in the private part of the package, whereas Ada 2005
1547 -- (AI-240) revises this to require the attributes to be
1548 -- "available" (implying that the attribute clauses must be
1549 -- visible to the RCI client). The Ada 95 rules violate the
1550 -- contract model for privacy, but we support both semantics
1551 -- for now for compatibility (note that ACATS test BXE2009
1552 -- checks a case that conforms to the Ada 95 rules but is
1553 -- illegal in Ada 2005).
1555 Base_Param_Type := Base_Type (Param_Type);
1556 Base_Under_Type := Base_Type (Underlying_Type
1559 if (Ada_Version < Ada_05
1561 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1563 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1565 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1567 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1569 (Ada_Version >= Ada_05
1571 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1573 No (TSS (Base_Param_Type, TSS_Stream_Write))
1575 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1577 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write))))
1579 if K = N_Subprogram_Declaration then
1580 Error_Node := Param_Spec;
1583 if Ada_Version >= Ada_05 then
1585 ("limited parameter in rci unit "
1586 & "must have visible read/write attributes ",
1590 ("limited parameter in rci unit "
1591 & "must have read/write attributes ",
1594 Explain_Limited_Type (Param_Type, Error_Node);
1601 end Validate_RCI_Subprogram_Declaration;
1603 ----------------------------------------------------
1604 -- Validate_Remote_Access_Object_Type_Declaration --
1605 ----------------------------------------------------
1607 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1608 Direct_Designated_Type : Entity_Id;
1609 Desig_Type : Entity_Id;
1612 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1613 -- given node is N_Access_To_Object_Definition.
1615 if not Comes_From_Source (T)
1616 or else (not In_RCI_Declaration (Parent (T))
1617 and then not In_RT_Declaration)
1622 -- An access definition in the private part of a Remote Types package
1623 -- may be legal if it has user-defined Read and Write attributes. This
1624 -- will be checked at the end of the package spec processing.
1626 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1630 -- Check RCI or RT unit type declaration. It may not contain the
1631 -- declaration of an access-to-object type unless it is a general access
1632 -- type that designates a class-wide limited private type. There are
1633 -- also constraints on the primitive subprograms of the class-wide type
1634 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1636 if Ekind (T) /= E_General_Access_Type
1637 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1639 if In_RCI_Declaration (Parent (T)) then
1641 ("error in access type in Remote_Call_Interface unit", T);
1644 ("error in access type in Remote_Types unit", T);
1647 Error_Msg_N ("\must be general access to class-wide type", T);
1651 Direct_Designated_Type := Designated_Type (T);
1652 Desig_Type := Etype (Direct_Designated_Type);
1654 if not Is_Recursively_Limited_Private (Desig_Type) then
1656 ("error in designated type of remote access to class-wide type", T);
1658 ("\must be tagged limited private or private extension of type", T);
1662 -- Now this is an RCI unit access-to-class-wide-limited-private type
1663 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1664 -- optimize later checks by avoiding tree traversal to find out if this
1665 -- entity is inside an RCI unit.
1667 Set_Is_Remote_Call_Interface (T);
1668 end Validate_Remote_Access_Object_Type_Declaration;
1670 -----------------------------------------------
1671 -- Validate_Remote_Access_To_Class_Wide_Type --
1672 -----------------------------------------------
1674 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1675 K : constant Node_Kind := Nkind (N);
1676 PK : constant Node_Kind := Nkind (Parent (N));
1680 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1681 -- of class-wide limited private types.
1683 -- Storage_Pool and Storage_Size are not defined for such types
1685 -- The expected type of allocator must not not be such a type.
1687 -- The actual parameter of generic instantiation must not be such a
1688 -- type if the formal parameter is of an access type.
1690 -- On entry, there are five cases
1692 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1693 -- either Storage_Pool or Storage_Size.
1695 -- 2. called from exp_ch4 Expand_N_Allocator
1697 -- 3. called from sem_ch12 Analyze_Associations
1699 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1701 -- 5. called from sem_res Resolve_Actuals
1703 if K = N_Attribute_Reference then
1704 E := Etype (Prefix (N));
1706 if Is_Remote_Access_To_Class_Wide_Type (E) then
1707 Error_Msg_N ("incorrect attribute of remote operand", N);
1711 elsif K = N_Allocator then
1714 if Is_Remote_Access_To_Class_Wide_Type (E) then
1715 Error_Msg_N ("incorrect expected remote type of allocator", N);
1719 elsif K in N_Has_Entity then
1722 if Is_Remote_Access_To_Class_Wide_Type (E) then
1723 Error_Msg_N ("incorrect remote type generic actual", N);
1727 -- This subprogram also enforces the checks in E.2.2(13). A value of
1728 -- such type must not be dereferenced unless as controlling operand of
1729 -- a dispatching call.
1731 elsif K = N_Explicit_Dereference
1732 and then (Comes_From_Source (N)
1733 or else (Nkind (Original_Node (N)) = N_Selected_Component
1734 and then Comes_From_Source (Original_Node (N))))
1736 E := Etype (Prefix (N));
1738 -- If the class-wide type is not a remote one, the restrictions
1741 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1745 -- If we have a true dereference that comes from source and that
1746 -- is a controlling argument for a dispatching call, accept it.
1748 if Is_Actual_Parameter (N)
1749 and then Is_Controlling_Actual (N)
1754 -- If we are just within a procedure or function call and the
1755 -- dereference has not been analyzed, return because this procedure
1756 -- will be called again from sem_res Resolve_Actuals.
1758 if Is_Actual_Parameter (N)
1759 and then not Analyzed (N)
1764 -- We must allow expanded code to generate a reference to the tag of
1765 -- the designated object (may be either the actual tag, or the stub
1766 -- tag in the case of a remote object).
1768 if PK = N_Selected_Component
1769 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1774 -- The following code is needed for expansion of RACW Write
1775 -- attribute, since such expressions can appear in the expanded
1778 if not Comes_From_Source (N)
1781 or else PK = N_Attribute_Reference
1783 (PK = N_Type_Conversion
1784 and then Present (Parent (N))
1785 and then Present (Parent (Parent (N)))
1787 Nkind (Parent (Parent (N))) = N_Selected_Component))
1792 Error_Msg_N ("incorrect remote type dereference", N);
1794 end Validate_Remote_Access_To_Class_Wide_Type;
1796 ------------------------------------------
1797 -- Validate_Remote_Type_Type_Conversion --
1798 ------------------------------------------
1800 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1801 S : constant Entity_Id := Etype (N);
1802 E : constant Entity_Id := Etype (Expression (N));
1805 -- This test is required in the case where a conversion appears inside a
1806 -- normal package, it does not necessarily have to be inside an RCI,
1807 -- Remote_Types unit (RM E.2.2(9,12)).
1809 if Is_Remote_Access_To_Subprogram_Type (E)
1810 and then not Is_Remote_Access_To_Subprogram_Type (S)
1813 ("incorrect conversion of remote operand to local type", N);
1816 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1817 and then Is_Remote_Access_To_Subprogram_Type (S)
1820 ("incorrect conversion of local operand to remote type", N);
1823 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1824 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1827 ("incorrect conversion of remote operand to local type", N);
1831 -- If a local access type is converted into a RACW type, then the
1832 -- current unit has a pointer that may now be exported to another
1835 if Is_Remote_Access_To_Class_Wide_Type (S)
1836 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1838 Set_Has_RACW (Current_Sem_Unit);
1840 end Validate_Remote_Type_Type_Conversion;
1842 -------------------------------
1843 -- Validate_RT_RAT_Component --
1844 -------------------------------
1846 procedure Validate_RT_RAT_Component (N : Node_Id) is
1847 Spec : constant Node_Id := Specification (N);
1848 Name_U : constant Entity_Id := Defining_Entity (Spec);
1851 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1854 if not Is_Remote_Types (Name_U) then
1858 Typ := First_Entity (Name_U);
1859 while Present (Typ) and then Typ /= First_Priv_Ent loop
1860 U_Typ := Underlying_Type (Typ);
1866 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1867 if Missing_Read_Write_Attributes (Typ) then
1868 if Is_Non_Remote_Access_Type (Typ) then
1869 Error_Msg_N ("error in non-remote access type", U_Typ);
1872 ("error in record type containing a component of a " &
1873 "non-remote access type", U_Typ);
1876 if Ada_Version >= Ada_05 then
1878 ("\must have visible Read and Write attribute " &
1879 "definition clauses (RM E.2.2(8))", U_Typ);
1882 ("\must have Read and Write attribute " &
1883 "definition clauses (RM E.2.2(8))", U_Typ);
1890 end Validate_RT_RAT_Component;
1892 -----------------------------------------
1893 -- Validate_SP_Access_Object_Type_Decl --
1894 -----------------------------------------
1896 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1897 Direct_Designated_Type : Entity_Id;
1899 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1900 -- Return true if the protected type designated by T has
1901 -- entry declarations.
1903 ----------------------------
1904 -- Has_Entry_Declarations --
1905 ----------------------------
1907 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1911 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1912 Ety := First_Entity (E);
1913 while Present (Ety) loop
1914 if Ekind (Ety) = E_Entry then
1923 end Has_Entry_Declarations;
1925 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1928 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1929 -- Nkind of the given entity is N_Access_To_Object_Definition.
1931 if not Comes_From_Source (T)
1932 or else not In_Shared_Passive_Unit
1933 or else In_Subprogram_Task_Protected_Unit
1938 -- Check Shared Passive unit. It should not contain the declaration
1939 -- of an access-to-object type whose designated type is a class-wide
1940 -- type, task type or protected type with entry (RM E.2.1(7)).
1942 Direct_Designated_Type := Designated_Type (T);
1944 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
1946 ("invalid access-to-class-wide type in shared passive unit", T);
1949 elsif Ekind (Direct_Designated_Type) in Task_Kind then
1951 ("invalid access-to-task type in shared passive unit", T);
1954 elsif Ekind (Direct_Designated_Type) in Protected_Kind
1955 and then Has_Entry_Declarations (Direct_Designated_Type)
1958 ("invalid access-to-protected type in shared passive unit", T);
1961 end Validate_SP_Access_Object_Type_Decl;
1963 ---------------------------------
1964 -- Validate_Static_Object_Name --
1965 ---------------------------------
1967 procedure Validate_Static_Object_Name (N : Node_Id) is
1970 function Is_Primary (N : Node_Id) return Boolean;
1971 -- Determine whether node is syntactically a primary in an expression
1972 -- This function should probably be somewhere else ???
1973 -- Also it does not do what it says, e.g if N is a binary operator
1974 -- whose parent is a binary operator, Is_Primary returns True ???
1980 function Is_Primary (N : Node_Id) return Boolean is
1981 K : constant Node_Kind := Nkind (Parent (N));
1985 when N_Op | N_Membership_Test =>
1989 | N_Component_Association
1990 | N_Index_Or_Discriminant_Constraint =>
1993 when N_Attribute_Reference =>
1994 return Attribute_Name (Parent (N)) /= Name_Address
1995 and then Attribute_Name (Parent (N)) /= Name_Access
1996 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
1998 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2000 when N_Indexed_Component =>
2001 return (N /= Prefix (Parent (N))
2002 or else Is_Primary (Parent (N)));
2004 when N_Qualified_Expression | N_Type_Conversion =>
2005 return Is_Primary (Parent (N));
2007 when N_Assignment_Statement | N_Object_Declaration =>
2008 return (N = Expression (Parent (N)));
2010 when N_Selected_Component =>
2011 return Is_Primary (Parent (N));
2018 -- Start of processing for Validate_Static_Object_Name
2021 if not In_Preelaborated_Unit
2022 or else not Comes_From_Source (N)
2023 or else In_Subprogram_Or_Concurrent_Unit
2024 or else Ekind (Current_Scope) = E_Block
2028 -- Filter out cases where primary is default in a component declaration,
2029 -- discriminant specification, or actual in a record type initialization
2032 -- Initialization call of internal types
2034 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2036 if Present (Parent (Parent (N)))
2037 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2042 if Nkind (Name (Parent (N))) = N_Identifier
2043 and then not Comes_From_Source (Entity (Name (Parent (N))))
2049 -- Error if the name is a primary in an expression. The parent must not
2050 -- be an operator, or a selected component or an indexed component that
2051 -- is itself a primary. Entities that are actuals do not need to be
2052 -- checked, because the call itself will be diagnosed.
2055 and then (not Inside_A_Generic
2056 or else Present (Enclosing_Generic_Body (N)))
2058 if Ekind (Entity (N)) = E_Variable
2059 or else Ekind (Entity (N)) in Formal_Object_Kind
2061 Flag_Non_Static_Expr
2062 ("non-static object name in preelaborated unit", N);
2064 -- We take the view that a constant defined in another preelaborated
2065 -- unit is preelaborable, even though it may have a private type and
2066 -- thus appear non-static in a client. This must be the intent of
2067 -- the language, but currently is an RM gap ???
2069 elsif Ekind (Entity (N)) = E_Constant
2070 and then not Is_Static_Expression (N)
2074 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2076 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2077 and then (Is_Preelaborated (Scope (E))
2078 or else Is_Pure (Scope (E))
2079 or else (Present (Renamed_Object (E))
2081 Is_Entity_Name (Renamed_Object (E))
2084 (Scope (Renamed_Object (E)))
2087 (Renamed_Object (E))))))
2091 -- This is the error case
2094 -- In GNAT mode, this is just a warning, to allow it to be
2095 -- judiciously turned off. Otherwise it is a real error.
2099 ("?non-static constant in preelaborated unit", N);
2101 Flag_Non_Static_Expr
2102 ("non-static constant in preelaborated unit", N);
2107 end Validate_Static_Object_Name;