1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Disp
; use Exp_Disp
;
32 with Fname
; use Fname
;
34 with Namet
; use Namet
;
35 with Nlists
; use Nlists
;
38 with Sem_Eval
; use Sem_Eval
;
39 with Sem_Util
; use Sem_Util
;
40 with Sinfo
; use Sinfo
;
41 with Snames
; use Snames
;
42 with Stand
; use Stand
;
44 package body Sem_Cat
is
46 -----------------------
47 -- Local Subprograms --
48 -----------------------
50 procedure Check_Categorization_Dependencies
51 (Unit_Entity
: Entity_Id
;
52 Depended_Entity
: Entity_Id
;
54 Is_Subunit
: Boolean);
55 -- This procedure checks that the categorization of a lib unit and that
56 -- of the depended unit satisfy dependency restrictions.
57 -- The depended_entity can be the entity in a with_clause item, in which
58 -- case Info_Node denotes that item. The depended_entity can also be the
59 -- parent unit of a child unit, in which case Info_Node is the declaration
60 -- of the child unit. The error message is posted on Info_Node, and is
61 -- specialized if Is_Subunit is true.
63 procedure Check_Non_Static_Default_Expr
66 -- Iterate through the component list of a record definition, check
67 -- that no component is declared with a nonstatic default value.
68 -- If a nonstatic default exists, report an error on Obj_Decl.
70 -- Iterate through the component list of a record definition, check
71 -- that no component is declared with a non-static default value.
73 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
74 -- Return True if the entity or one of its subcomponents is of an access
75 -- type that does not have user-defined Read and Write attributes visible
78 function In_RCI_Declaration
(N
: Node_Id
) return Boolean;
79 -- Determines if a declaration is within the visible part of a Remote
80 -- Call Interface compilation unit, for semantic checking purposes only,
81 -- (returns false within an instance and within the package body).
83 function In_RT_Declaration
return Boolean;
84 -- Determines if current scope is within a Remote Types compilation unit,
85 -- for semantic checking purposes.
87 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
88 -- Returns true if the entity is a type whose full view is a non-remote
89 -- access type, for the purpose of enforcing E.2.2(8) rules.
91 function In_Shared_Passive_Unit
return Boolean;
92 -- Determines if current scope is within a Shared Passive compilation unit
94 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
95 -- Iterate through the list of discriminants to check if any of them
96 -- contains non-static default expression, which is a violation in
97 -- a preelaborated library unit.
99 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
100 -- Check validity of declaration if RCI or RT unit. It should not contain
101 -- the declaration of an access-to-object type unless it is a general
102 -- access type that designates a class-wide limited private type. There are
103 -- also constraints about the primitive subprograms of the class-wide type.
104 -- RM E.2 (9, 13, 14)
106 ---------------------------------------
107 -- Check_Categorization_Dependencies --
108 ---------------------------------------
110 procedure Check_Categorization_Dependencies
111 (Unit_Entity
: Entity_Id
;
112 Depended_Entity
: Entity_Id
;
114 Is_Subunit
: Boolean)
116 N
: constant Node_Id
:= Info_Node
;
118 -- Here we define an enumeration type to represent categorization types,
119 -- ordered so that a unit with a given categorization can only WITH
120 -- units with lower or equal categorization type.
122 -- Note that we take advantage of E.2(14) to define a category
123 -- Preelaborated and treat pragma Preelaborate as a categorization
124 -- pragma that defines that category.
126 type Categorization
is
130 Remote_Call_Interface
,
134 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
135 -- Check categorization flags from entity, and return in the form
136 -- of the lowest value of the Categorization type that applies to E.
138 ------------------------
139 -- Get_Categorization --
140 ------------------------
142 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
144 -- Get the lowest categorization that corresponds to E. Note that
145 -- nothing prevents several (different) categorization pragmas
146 -- to apply to the same library unit, in which case the unit has
147 -- all associated categories, so we need to be careful here to
148 -- check pragmas in proper Categorization order in order to
149 -- return the lowest applicable value.
151 -- Ignore Pure specification if set by pragma Pure_Function
155 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
159 elsif Is_Shared_Passive
(E
) then
160 return Shared_Passive
;
162 elsif Is_Remote_Types
(E
) then
165 elsif Is_Remote_Call_Interface
(E
) then
166 return Remote_Call_Interface
;
168 elsif Is_Preelaborated
(E
) then
169 return Preelaborated
;
174 end Get_Categorization
;
176 Unit_Category
: Categorization
;
177 With_Category
: Categorization
;
179 -- Start of processing for Check_Categorization_Dependencies
182 -- Intrinsic subprograms are preelaborated, so do not impose any
183 -- categorization dependencies.
185 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
189 Unit_Category
:= Get_Categorization
(Unit_Entity
);
190 With_Category
:= Get_Categorization
(Depended_Entity
);
192 -- These messages are warnings in GNAT mode, to allow it to be
193 -- judiciously turned off. Otherwise it is a real error.
195 Error_Msg_Warn
:= GNAT_Mode
;
197 -- Check for possible error
199 if With_Category
> Unit_Category
then
201 -- Special case: Remote_Types and Remote_Call_Interface are allowed
202 -- to be with'ed in package body.
204 if (Unit_Category
= Remote_Types
205 or else Unit_Category
= Remote_Call_Interface
)
206 and then In_Package_Body
(Unit_Entity
)
210 -- Here we have an error
213 -- Don't give error if main unit is not an internal unit, and the
214 -- unit generating the message is an internal unit. This is the
215 -- situation in which such messages would be ignored in any case,
216 -- so it is convenient not to generate them (since it causes
217 -- annoying interference with debugging).
219 if Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
220 and then not Is_Internal_File_Name
(Unit_File_Name
(Main_Unit
))
226 elsif Is_Subunit
then
228 ("<subunit cannot depend on& " &
229 "(parent has wrong categorization)", N
, Depended_Entity
);
231 -- Normal unit, not subunit
235 ("<cannot depend on& " &
236 "(wrong categorization)", N
, Depended_Entity
);
239 -- Add further explanation for common cases
241 case Unit_Category
is
244 ("\<pure unit cannot depend on non-pure unit",
247 when Preelaborated
=>
249 ("\<preelaborated unit cannot depend on " &
250 "non-preelaborated unit",
258 end Check_Categorization_Dependencies
;
260 -----------------------------------
261 -- Check_Non_Static_Default_Expr --
262 -----------------------------------
264 procedure Check_Non_Static_Default_Expr
269 Component_Decl
: Node_Id
;
272 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
273 Recdef
:= Record_Extension_Part
(Type_Def
);
283 -- Check that component declarations do not involve:
285 -- a. a non-static default expression, where the object is
286 -- declared to be default initialized.
288 -- b. a dynamic Itype (discriminants and constraints)
290 if Null_Present
(Recdef
) then
293 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
296 while Present
(Component_Decl
)
297 and then Nkind
(Component_Decl
) = N_Component_Declaration
299 if Present
(Expression
(Component_Decl
))
300 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
301 and then not Is_Static_Expression
(Expression
(Component_Decl
))
303 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
305 ("object in preelaborated unit has non-static default#",
308 -- Fix this later ???
310 -- elsif Has_Dynamic_Itype (Component_Decl) then
312 -- ("dynamic type discriminant," &
313 -- " constraint in preelaborated unit",
317 Next
(Component_Decl
);
319 end Check_Non_Static_Default_Expr
;
321 -------------------------------------
322 -- Has_Stream_Attribute_Definition --
323 -------------------------------------
325 function Has_Stream_Attribute_Definition
328 At_Any_Place
: Boolean := False) return Boolean
331 Full_Type
: Entity_Id
:= Typ
;
334 -- In the case of a type derived from a private view, any specified
335 -- stream attributes will be attached to the derived type's underlying
336 -- type rather the derived type entity itself (which is itself private).
338 if Is_Private_Type
(Typ
)
339 and then Is_Derived_Type
(Typ
)
340 and then Present
(Full_View
(Typ
))
342 Full_Type
:= Underlying_Type
(Typ
);
345 -- We start from the declaration node and then loop until the end of
346 -- the list until we find the requested attribute definition clause.
347 -- In Ada 2005 mode, clauses are ignored if they are not currently
348 -- visible (this is tested using the corresponding Entity, which is
349 -- inserted by the expander at the point where the clause occurs),
350 -- unless At_Any_Place is true.
352 Rep_Item
:= First_Rep_Item
(Full_Type
);
353 while Present
(Rep_Item
) loop
354 if Nkind
(Rep_Item
) = N_Attribute_Definition_Clause
then
355 case Chars
(Rep_Item
) is
357 exit when Nam
= TSS_Stream_Read
;
360 exit when Nam
= TSS_Stream_Write
;
363 exit when Nam
= TSS_Stream_Input
;
366 exit when Nam
= TSS_Stream_Output
;
374 Next_Rep_Item
(Rep_Item
);
377 -- If At_Any_Place is true, return True if the attribute is available
378 -- at any place; if it is false, return True only if the attribute is
379 -- currently visible.
381 return Present
(Rep_Item
)
382 and then (Ada_Version
< Ada_05
384 or else not Is_Hidden
(Entity
(Rep_Item
)));
385 end Has_Stream_Attribute_Definition
;
387 ---------------------------
388 -- In_Preelaborated_Unit --
389 ---------------------------
391 function In_Preelaborated_Unit
return Boolean is
392 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
393 Unit_Kind
: constant Node_Kind
:=
394 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
397 -- There are no constraints on body of remote_call_interface or
398 -- remote_types packages.
400 return (Unit_Entity
/= Standard_Standard
)
401 and then (Is_Preelaborated
(Unit_Entity
)
402 or else Is_Pure
(Unit_Entity
)
403 or else Is_Shared_Passive
(Unit_Entity
)
405 ((Is_Remote_Types
(Unit_Entity
)
406 or else Is_Remote_Call_Interface
(Unit_Entity
))
407 and then Ekind
(Unit_Entity
) = E_Package
408 and then Unit_Kind
/= N_Package_Body
409 and then not In_Package_Body
(Unit_Entity
)
410 and then not In_Instance
));
411 end In_Preelaborated_Unit
;
417 function In_Pure_Unit
return Boolean is
419 return Is_Pure
(Current_Scope
);
422 ------------------------
423 -- In_RCI_Declaration --
424 ------------------------
426 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
427 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
428 Unit_Kind
: constant Node_Kind
:=
429 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
432 -- There are no restrictions on the private part or body
435 return Is_Remote_Call_Interface
(Unit_Entity
)
436 and then (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 List_Containing
(N
) =
441 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
442 and then not In_Package_Body
(Unit_Entity
)
443 and then not In_Instance
;
445 -- What about the case of a nested package in the visible part???
446 -- This case is missed by the List_Containing check above???
447 end In_RCI_Declaration
;
449 -----------------------
450 -- In_RT_Declaration --
451 -----------------------
453 function In_RT_Declaration
return Boolean is
454 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
455 Unit_Kind
: constant Node_Kind
:=
456 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
459 -- There are no restrictions on the body of a Remote Types unit
461 return Is_Remote_Types
(Unit_Entity
)
462 and then (Ekind
(Unit_Entity
) = E_Package
463 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
464 and then Unit_Kind
/= N_Package_Body
465 and then not In_Package_Body
(Unit_Entity
)
466 and then not In_Instance
;
467 end In_RT_Declaration
;
469 ----------------------------
470 -- In_Shared_Passive_Unit --
471 ----------------------------
473 function In_Shared_Passive_Unit
return Boolean is
474 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
477 return Is_Shared_Passive
(Unit_Entity
);
478 end In_Shared_Passive_Unit
;
480 ---------------------------------------
481 -- In_Subprogram_Task_Protected_Unit --
482 ---------------------------------------
484 function In_Subprogram_Task_Protected_Unit
return Boolean is
488 -- The following is to verify that a declaration is inside
489 -- subprogram, generic subprogram, task unit, protected unit.
490 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
492 -- Use scope chain to check successively outer scopes
498 Is_Generic_Subprogram
(E
)
500 Is_Concurrent_Type
(E
)
504 elsif E
= Standard_Standard
then
510 end In_Subprogram_Task_Protected_Unit
;
512 -------------------------------
513 -- Is_Non_Remote_Access_Type --
514 -------------------------------
516 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
517 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
521 -- This case arises for the case of a generic formal type, in which
522 -- case E.2.2(8) rules will be enforced at instantiation time.
527 return Is_Access_Type
(U_E
)
528 and then not Is_Remote_Access_To_Class_Wide_Type
(U_E
)
529 and then not Is_Remote_Access_To_Subprogram_Type
(U_E
);
530 end Is_Non_Remote_Access_Type
;
532 ----------------------------------
533 -- Missing_Read_Write_Attribute --
534 ----------------------------------
536 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
537 Component
: Entity_Id
;
538 Component_Type
: Entity_Id
;
539 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
541 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
542 -- Return True if entity has attribute definition clauses for Read and
543 -- Write attributes that are visible at some place.
545 -------------------------------
546 -- Has_Read_Write_Attributes --
547 -------------------------------
549 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
552 and then Has_Stream_Attribute_Definition
(E
,
553 TSS_Stream_Read
, At_Any_Place
=> True)
554 and then Has_Stream_Attribute_Definition
(E
,
555 TSS_Stream_Write
, At_Any_Place
=> True);
556 end Has_Read_Write_Attributes
;
558 -- Start of processing for Missing_Read_Write_Attributes
564 elsif Has_Read_Write_Attributes
(E
)
565 or else Has_Read_Write_Attributes
(U_E
)
569 elsif Is_Non_Remote_Access_Type
(U_E
) then
573 if Is_Record_Type
(U_E
) then
574 Component
:= First_Entity
(U_E
);
575 while Present
(Component
) loop
576 if not Is_Tag
(Component
) then
577 Component_Type
:= Etype
(Component
);
579 if Missing_Read_Write_Attributes
(Component_Type
) then
584 Next_Entity
(Component
);
589 end Missing_Read_Write_Attributes
;
591 -------------------------------------
592 -- Set_Categorization_From_Pragmas --
593 -------------------------------------
595 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
596 P
: constant Node_Id
:= Parent
(N
);
597 S
: constant Entity_Id
:= Current_Scope
;
599 procedure Set_Parents
(Visibility
: Boolean);
600 -- If this is a child instance, the parents are not immediately
601 -- visible during analysis. Make them momentarily visible so that
602 -- the argument of the pragma can be resolved properly, and reset
609 procedure Set_Parents
(Visibility
: Boolean) is
613 while Present
(Par
) and then Par
/= Standard_Standard
loop
614 Set_Is_Immediately_Visible
(Par
, Visibility
);
619 -- Start of processing for Set_Categorization_From_Pragmas
622 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
623 -- The purpose is to set categorization flags before analyzing the
624 -- unit itself, so as to diagnose violations of categorization as
625 -- we process each declaration, even though the pragma appears after
628 if Nkind
(P
) /= N_Compilation_Unit
then
637 and then Is_Generic_Instance
(S
)
642 PN
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
643 while Present
(PN
) loop
645 -- Skip implicit types that may have been introduced by
646 -- previous analysis.
648 if Nkind
(PN
) = N_Pragma
then
649 case Get_Pragma_Id
(PN
) is
650 when Pragma_All_Calls_Remote |
651 Pragma_Preelaborate |
653 Pragma_Remote_Call_Interface |
654 Pragma_Remote_Types |
655 Pragma_Shared_Passive
=> Analyze
(PN
);
664 and then Is_Generic_Instance
(S
)
669 end Set_Categorization_From_Pragmas
;
671 -----------------------------------
672 -- Set_Categorization_From_Scope --
673 -----------------------------------
675 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
676 Declaration
: Node_Id
:= Empty
;
677 Specification
: Node_Id
:= Empty
;
681 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
683 if not Is_Remote_Call_Interface
(E
) then
684 if Ekind
(E
) in Subprogram_Kind
then
685 Declaration
:= Unit_Declaration_Node
(E
);
687 if Nkind
(Declaration
) = N_Subprogram_Body
689 Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
691 Specification
:= Corresponding_Spec
(Declaration
);
695 -- A subprogram body or renaming-as-body is a remote call
696 -- interface if it serves as the completion of a subprogram
697 -- declaration that is a remote call interface.
699 if Nkind
(Specification
) in N_Entity
then
700 Set_Is_Remote_Call_Interface
701 (E
, Is_Remote_Call_Interface
(Specification
));
703 -- A subprogram declaration is a remote call interface when it is
704 -- declared within the visible part of, or declared by, a library
705 -- unit declaration that is a remote call interface.
708 Set_Is_Remote_Call_Interface
709 (E
, Is_Remote_Call_Interface
(Scop
)
710 and then not (In_Private_Part
(Scop
)
711 or else In_Package_Body
(Scop
)));
716 (E
, Is_Remote_Types
(Scop
)
717 and then not (In_Private_Part
(Scop
)
718 or else In_Package_Body
(Scop
)));
719 end Set_Categorization_From_Scope
;
721 ------------------------------
722 -- Static_Discriminant_Expr --
723 ------------------------------
725 -- We need to accommodate a Why_Not_Static call somehow here ???
727 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
728 Discriminant_Spec
: Node_Id
;
731 Discriminant_Spec
:= First
(L
);
732 while Present
(Discriminant_Spec
) loop
733 if Present
(Expression
(Discriminant_Spec
))
734 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
739 Next
(Discriminant_Spec
);
743 end Static_Discriminant_Expr
;
745 --------------------------------------
746 -- Validate_Access_Type_Declaration --
747 --------------------------------------
749 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
750 Def
: constant Node_Id
:= Type_Definition
(N
);
755 -- Access to subprogram case
757 when N_Access_To_Subprogram_Definition
=>
759 -- A pure library_item must not contain the declaration of a
760 -- named access type, except within a subprogram, generic
761 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
763 -- This test is skipped in Ada 2005 (see AI-366)
765 if Ada_Version
< Ada_05
766 and then Comes_From_Source
(T
)
767 and then In_Pure_Unit
768 and then not In_Subprogram_Task_Protected_Unit
770 Error_Msg_N
("named access type not allowed in pure unit", T
);
773 -- Access to object case
775 when N_Access_To_Object_Definition
=>
776 if Comes_From_Source
(T
)
777 and then In_Pure_Unit
778 and then not In_Subprogram_Task_Protected_Unit
780 -- We can't give the message yet, since the type is not frozen
781 -- and in Ada 2005 mode, access types are allowed in pure units
782 -- if the type has no storage pool (see AI-366). So we set a
783 -- flag which will be checked at freeze time.
785 Set_Is_Pure_Unit_Access_Type
(T
);
788 -- Check for RCI or RT unit type declaration: declaration of an
789 -- access-to-object type is illegal unless it is a general access
790 -- type that designates a class-wide limited private type.
791 -- Note that constraints on the primitive subprograms of the
792 -- designated tagged type are not enforced here but in
793 -- Validate_RACW_Primitives, which is done separately because the
794 -- designated type might not be frozen (and therefore its
795 -- primitive operations might not be completely known) at the
796 -- point of the RACW declaration.
798 Validate_Remote_Access_Object_Type_Declaration
(T
);
800 -- Check for shared passive unit type declaration. It should
801 -- not contain the declaration of access to class wide type,
802 -- access to task type and access to protected type with entry.
804 Validate_SP_Access_Object_Type_Decl
(T
);
810 -- Set categorization flag from package on entity as well, to allow
811 -- easy checks later on for required validations of RCI or RT units.
812 -- This is only done for entities that are in the original source.
814 if Comes_From_Source
(T
)
815 and then not (In_Package_Body
(Scope
(T
))
816 or else In_Private_Part
(Scope
(T
)))
818 Set_Is_Remote_Call_Interface
819 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
821 (T
, Is_Remote_Types
(Scope
(T
)));
823 end Validate_Access_Type_Declaration
;
825 ----------------------------
826 -- Validate_Ancestor_Part --
827 ----------------------------
829 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
830 A
: constant Node_Id
:= Ancestor_Part
(N
);
831 T
: constant Entity_Id
:= Entity
(A
);
834 if In_Preelaborated_Unit
835 and then not In_Subprogram_Or_Concurrent_Unit
836 and then (not Inside_A_Generic
837 or else Present
(Enclosing_Generic_Body
(N
)))
839 -- If the type is private, it must have the Ada 2005 pragma
840 -- Has_Preelaborable_Initialization.
841 -- The check is omitted within predefined units. This is probably
842 -- obsolete code to fix the Ada95 weakness in this area ???
844 if Is_Private_Type
(T
)
845 and then not Has_Pragma_Preelab_Init
(T
)
846 and then not Is_Internal_File_Name
847 (Unit_File_Name
(Get_Source_Unit
(N
)))
850 ("private ancestor type not allowed in preelaborated unit", A
);
852 elsif Is_Record_Type
(T
) then
853 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
854 Check_Non_Static_Default_Expr
855 (Type_Definition
(Parent
(T
)), A
);
859 end Validate_Ancestor_Part
;
861 ----------------------------------------
862 -- Validate_Categorization_Dependency --
863 ----------------------------------------
865 procedure Validate_Categorization_Dependency
869 K
: constant Node_Kind
:= Nkind
(N
);
870 P
: Node_Id
:= Parent
(N
);
872 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
875 -- Only validate library units and subunits. For subunits, checks
876 -- concerning withed units apply to the parent compilation unit.
883 and then not Is_Compilation_Unit
(U
)
884 and then not Is_Child_Unit
(U
)
890 if Nkind
(P
) /= N_Compilation_Unit
then
894 -- Body of RCI unit does not need validation
896 if Is_Remote_Call_Interface
(E
)
897 and then (Nkind
(N
) = N_Package_Body
898 or else Nkind
(N
) = N_Subprogram_Body
)
903 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
907 Entity_Of_Withed
: Entity_Id
;
910 Item
:= First
(Context_Items
(P
));
911 while Present
(Item
) loop
912 if Nkind
(Item
) = N_With_Clause
913 and then not (Implicit_With
(Item
)
914 or else Limited_Present
(Item
))
916 Entity_Of_Withed
:= Entity
(Name
(Item
));
917 Check_Categorization_Dependencies
918 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
925 -- Child depends on parent; therefore parent should also be categorized
926 -- and satisfy the dependency hierarchy.
928 -- Check if N is a child spec
930 if (K
in N_Generic_Declaration
or else
931 K
in N_Generic_Instantiation
or else
932 K
in N_Generic_Renaming_Declaration
or else
933 K
= N_Package_Declaration
or else
934 K
= N_Package_Renaming_Declaration
or else
935 K
= N_Subprogram_Declaration
or else
936 K
= N_Subprogram_Renaming_Declaration
)
937 and then Present
(Parent_Spec
(N
))
939 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
941 -- Verify that public child of an RCI library unit must also be an
942 -- RCI library unit (RM E.2.3(15)).
944 if Is_Remote_Call_Interface
(Scope
(E
))
945 and then not Private_Present
(P
)
946 and then not Is_Remote_Call_Interface
(E
)
948 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
951 end Validate_Categorization_Dependency
;
953 --------------------------------
954 -- Validate_Controlled_Object --
955 --------------------------------
957 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
959 -- Don't need this check in Ada 2005 mode, where this is all taken
960 -- care of by the mechanism for Preelaborable Initialization.
962 if Ada_Version
>= Ada_05
then
966 -- For now, never apply this check for internal GNAT units, since we
967 -- have a number of cases in the library where we are stuck with objects
968 -- of this type, and the RM requires Preelaborate.
970 -- For similar reasons, we only do this check for source entities, since
971 -- we generate entities of this type in some situations.
973 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
974 -- We have to enforce them for RM compatibility, but we have no trouble
975 -- accepting these objects and doing the right thing. Note that there is
976 -- no requirement that Preelaborate not actually generate any code!
978 if In_Preelaborated_Unit
979 and then not Debug_Flag_PP
980 and then Comes_From_Source
(E
)
982 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
983 and then (not Inside_A_Generic
984 or else Present
(Enclosing_Generic_Body
(E
)))
985 and then not Is_Protected_Type
(Etype
(E
))
988 ("library level controlled object not allowed in " &
989 "preelaborated unit", E
);
991 end Validate_Controlled_Object
;
993 --------------------------------------
994 -- Validate_Null_Statement_Sequence --
995 --------------------------------------
997 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
1001 if In_Preelaborated_Unit
then
1002 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
1003 while Present
(Item
) loop
1004 if Nkind
(Item
) /= N_Label
1005 and then Nkind
(Item
) /= N_Null_Statement
1007 -- In GNAT mode, this is a warning, allowing the run-time
1008 -- to judiciously bypass this error condition.
1010 Error_Msg_Warn
:= GNAT_Mode
;
1012 ("<statements not allowed in preelaborated unit", Item
);
1020 end Validate_Null_Statement_Sequence
;
1022 ---------------------------------
1023 -- Validate_Object_Declaration --
1024 ---------------------------------
1026 procedure Validate_Object_Declaration
(N
: Node_Id
) is
1027 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1028 E
: constant Node_Id
:= Expression
(N
);
1029 Odf
: constant Node_Id
:= Object_Definition
(N
);
1030 T
: constant Entity_Id
:= Etype
(Id
);
1033 -- Verify that any access to subprogram object does not have in its
1034 -- subprogram profile access type parameters or limited parameters
1035 -- without Read and Write attributes (E.2.3(13)).
1037 Validate_RCI_Subprogram_Declaration
(N
);
1039 -- Check that if we are in preelaborated elaboration code, then we
1040 -- do not have an instance of a default initialized private, task or
1041 -- protected object declaration which would violate (RM 10.2.1(9)).
1042 -- Note that constants are never default initialized (and the test
1043 -- below also filters out deferred constants). A variable is default
1044 -- initialized if it does *not* have an initialization expression.
1046 -- Filter out cases that are not declaration of a variable from source
1048 if Nkind
(N
) /= N_Object_Declaration
1049 or else Constant_Present
(N
)
1050 or else not Comes_From_Source
(Id
)
1055 -- Exclude generic specs from the checks (this will get rechecked
1056 -- on instantiations).
1059 and then No
(Enclosing_Generic_Body
(Id
))
1064 -- Required checks for declaration that is in a preelaborated
1065 -- package and is not within some subprogram.
1067 if In_Preelaborated_Unit
1068 and then not In_Subprogram_Or_Concurrent_Unit
1070 -- Check for default initialized variable case. Note that in
1071 -- accordance with (RM B.1(24)) imported objects are not
1072 -- subject to default initialization.
1073 -- If the initialization does not come from source and is an
1074 -- aggregate, it is a static initialization that replaces an
1075 -- implicit call, and must be treated as such.
1079 (Comes_From_Source
(E
) or else Nkind
(E
) /= N_Aggregate
)
1083 elsif Is_Imported
(Id
) then
1088 Ent
: Entity_Id
:= T
;
1091 -- An array whose component type is a record with nonstatic
1092 -- default expressions is a violation, so we get the array's
1095 if Is_Array_Type
(Ent
) then
1097 Comp_Type
: Entity_Id
;
1100 Comp_Type
:= Component_Type
(Ent
);
1101 while Is_Array_Type
(Comp_Type
) loop
1102 Comp_Type
:= Component_Type
(Comp_Type
);
1109 -- Object decl. that is of record type and has no default expr.
1110 -- should check if there is any non-static default expression
1111 -- in component decl. of the record type decl.
1113 if Is_Record_Type
(Ent
) then
1114 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1115 Check_Non_Static_Default_Expr
1116 (Type_Definition
(Parent
(Ent
)), N
);
1118 elsif Nkind
(Odf
) = N_Subtype_Indication
1119 and then not Is_Array_Type
(T
)
1120 and then not Is_Private_Type
(T
)
1122 Check_Non_Static_Default_Expr
(Type_Definition
1123 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1127 -- Check for invalid use of private object. Note that Ada 2005
1128 -- AI-161 modifies the rules for Ada 2005, including the use of
1129 -- the new pragma Preelaborable_Initialization.
1131 if Is_Private_Type
(Ent
)
1132 or else Depends_On_Private
(Ent
)
1134 -- Case where type has preelaborable initialization which
1135 -- means that a pragma Preelaborable_Initialization was
1136 -- given for the private type.
1138 if Has_Preelaborable_Initialization
(Ent
) then
1140 -- But for the predefined units, we will ignore this
1141 -- status unless we are in Ada 2005 mode since we want
1142 -- Ada 95 compatible behavior, in which the entities
1143 -- marked with this pragma in the predefined library are
1144 -- not treated specially.
1146 if Ada_Version
< Ada_05
then
1148 ("private object not allowed in preelaborated unit",
1150 Error_Msg_N
("\(would be legal in Ada 2005 mode)", N
);
1153 -- Type does not have preelaborable initialization
1156 -- We allow this when compiling in GNAT mode to make life
1157 -- easier for some cases where it would otherwise be hard
1158 -- to be exactly valid Ada.
1160 if not GNAT_Mode
then
1162 ("private object not allowed in preelaborated unit",
1165 -- Add a message if it would help to provide a pragma
1166 -- Preelaborable_Initialization on the type of the
1167 -- object (which would make it legal in Ada 2005).
1169 -- If the type has no full view (generic type, or
1170 -- previous error), the warning does not apply.
1172 if Is_Private_Type
(Ent
)
1173 and then Present
(Full_View
(Ent
))
1175 Has_Preelaborable_Initialization
(Full_View
(Ent
))
1177 Error_Msg_Sloc
:= Sloc
(Ent
);
1179 if Ada_Version
>= Ada_05
then
1181 ("\would be legal if pragma Preelaborable_" &
1182 "Initialization given for & #", N
, Ent
);
1185 ("\would be legal in Ada 2005 if pragma " &
1186 "Preelaborable_Initialization given for & #",
1193 -- Access to Task or Protected type
1195 elsif Is_Entity_Name
(Odf
)
1196 and then Present
(Etype
(Odf
))
1197 and then Is_Access_Type
(Etype
(Odf
))
1199 Ent
:= Designated_Type
(Etype
(Odf
));
1201 elsif Is_Entity_Name
(Odf
) then
1202 Ent
:= Entity
(Odf
);
1204 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1205 Ent
:= Etype
(Subtype_Mark
(Odf
));
1208 Nkind
(Odf
) = N_Constrained_Array_Definition
1210 Ent
:= Component_Type
(T
);
1216 if Is_Task_Type
(Ent
)
1217 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1220 ("concurrent object not allowed in preelaborated unit",
1227 -- Non-static discriminant not allowed in preelaborated unit
1228 -- Controlled object of a type with a user-defined Initialize
1229 -- is forbidden as well.
1231 if Is_Record_Type
(Etype
(Id
)) then
1233 ET
: constant Entity_Id
:= Etype
(Id
);
1234 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1238 if Has_Discriminants
(ET
)
1239 and then Present
(EE
)
1243 if Nkind
(PEE
) = N_Full_Type_Declaration
1244 and then not Static_Discriminant_Expr
1245 (Discriminant_Specifications
(PEE
))
1248 ("non-static discriminant in preelaborated unit",
1253 if Has_Overriding_Initialize
(ET
) then
1255 ("controlled type& does not have"
1256 & " preelaborable initialization", N
, ET
);
1263 -- A pure library_item must not contain the declaration of any variable
1264 -- except within a subprogram, generic subprogram, task unit, or
1265 -- protected unit (RM 10.2.1(16)).
1268 and then not In_Subprogram_Task_Protected_Unit
1270 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1272 -- The visible part of an RCI library unit must not contain the
1273 -- declaration of a variable (RM E.1.3(9))
1275 elsif In_RCI_Declaration
(N
) then
1276 Error_Msg_N
("declaration of variable not allowed in rci unit", N
);
1278 -- The visible part of a Shared Passive library unit must not contain
1279 -- the declaration of a variable (RM E.2.2(7))
1281 elsif In_RT_Declaration
then
1283 ("variable declaration not allowed in remote types unit", N
);
1286 end Validate_Object_Declaration
;
1288 ------------------------------
1289 -- Validate_RACW_Primitives --
1290 ------------------------------
1292 procedure Validate_RACW_Primitives
(T
: Entity_Id
) is
1293 Desig_Type
: Entity_Id
;
1294 Primitive_Subprograms
: Elist_Id
;
1295 Subprogram_Elmt
: Elmt_Id
;
1296 Subprogram
: Entity_Id
;
1297 Param_Spec
: Node_Id
;
1299 Param_Type
: Entity_Id
;
1302 procedure Illegal_RACW
(Msg
: String; N
: Node_Id
);
1303 -- Diagnose that T is illegal because of the given reason, associated
1304 -- with the location of node N.
1306 Illegal_RACW_Message_Issued
: Boolean := False;
1307 -- Set True once Illegal_RACW has been called
1313 procedure Illegal_RACW
(Msg
: String; N
: Node_Id
) is
1315 if not Illegal_RACW_Message_Issued
then
1317 ("illegal remote access to class-wide type&", T
);
1318 Illegal_RACW_Message_Issued
:= True;
1321 Error_Msg_Sloc
:= Sloc
(N
);
1322 Error_Msg_N
("\\" & Msg
& " in primitive#", T
);
1325 -- Start of processing for Validate_RACW_Primitives
1328 Desig_Type
:= Etype
(Designated_Type
(T
));
1330 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1332 Subprogram_Elmt
:= First_Elmt
(Primitive_Subprograms
);
1333 while Subprogram_Elmt
/= No_Elmt
loop
1334 Subprogram
:= Node
(Subprogram_Elmt
);
1336 if Is_Predefined_Dispatching_Operation
(Subprogram
)
1337 or else Is_Hidden
(Subprogram
)
1339 goto Next_Subprogram
;
1342 -- Check return type
1344 if Ekind
(Subprogram
) = E_Function
then
1345 Rtyp
:= Etype
(Subprogram
);
1347 if Has_Controlling_Result
(Subprogram
) then
1350 elsif Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
1351 Illegal_RACW
("anonymous access result", Rtyp
);
1353 elsif Is_Limited_Type
(Rtyp
) then
1354 if No
(TSS
(Rtyp
, TSS_Stream_Read
))
1356 No
(TSS
(Rtyp
, TSS_Stream_Write
))
1359 ("limited return type must have Read and Write attributes",
1360 Parent
(Subprogram
));
1361 Explain_Limited_Type
(Rtyp
, Parent
(Subprogram
));
1363 -- Check that the return type supports external streaming.
1364 -- Note that the language of the standard (E.2.2(14)) does not
1365 -- explicitly mention that case, but it really does not make
1366 -- sense to return a value containing a local access type.
1368 elsif Missing_Read_Write_Attributes
(Rtyp
)
1369 and then not Error_Posted
(Rtyp
)
1371 Illegal_RACW
("return type containing non-remote access "
1372 & "must have Read and Write attributes",
1373 Parent
(Subprogram
));
1379 Param
:= First_Formal
(Subprogram
);
1380 while Present
(Param
) loop
1382 -- Now find out if this parameter is a controlling parameter
1384 Param_Spec
:= Parent
(Param
);
1385 Param_Type
:= Etype
(Param
);
1387 if Is_Controlling_Formal
(Param
) then
1389 -- It is a controlling parameter, so specific checks below
1394 elsif Ekind
(Param_Type
) = E_Anonymous_Access_Type
1395 or else Ekind
(Param_Type
) = E_Anonymous_Access_Subprogram_Type
1397 -- From RM E.2.2(14), no anonymous access parameter other than
1398 -- controlling ones may be used (because an anonymous access
1399 -- type never supports external streaming).
1401 Illegal_RACW
("non-controlling access parameter", Param_Spec
);
1403 elsif Is_Limited_Type
(Param_Type
) then
1405 -- Not a controlling parameter, so type must have Read and
1406 -- Write attributes.
1408 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1410 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1413 ("limited formal must have Read and Write attributes",
1415 Explain_Limited_Type
(Param_Type
, Param_Spec
);
1418 elsif Missing_Read_Write_Attributes
(Param_Type
)
1419 and then not Error_Posted
(Param_Type
)
1421 Illegal_RACW
("parameter containing non-remote access "
1422 & "must have Read and Write attributes", Param_Spec
);
1425 -- Check next parameter in this subprogram
1427 Next_Formal
(Param
);
1431 Next_Elmt
(Subprogram_Elmt
);
1433 end Validate_RACW_Primitives
;
1435 -------------------------------
1436 -- Validate_RCI_Declarations --
1437 -------------------------------
1439 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1443 E
:= First_Entity
(P
);
1444 while Present
(E
) loop
1445 if Comes_From_Source
(E
) then
1446 if Is_Limited_Type
(E
) then
1448 ("limited type not allowed in rci unit", Parent
(E
));
1449 Explain_Limited_Type
(E
, Parent
(E
));
1451 elsif Ekind
(E
) = E_Generic_Function
1452 or else Ekind
(E
) = E_Generic_Package
1453 or else Ekind
(E
) = E_Generic_Procedure
1455 Error_Msg_N
("generic declaration not allowed in rci unit",
1458 elsif (Ekind
(E
) = E_Function
1459 or else Ekind
(E
) = E_Procedure
)
1460 and then Has_Pragma_Inline
(E
)
1463 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1465 -- Inner packages that are renamings need not be checked. Generic
1466 -- RCI packages are subject to the checks, but entities that come
1467 -- from formal packages are not part of the visible declarations
1468 -- of the package and are not checked.
1470 elsif Ekind
(E
) = E_Package
then
1471 if Present
(Renamed_Entity
(E
)) then
1474 elsif Ekind
(P
) /= E_Generic_Package
1475 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1476 Generic_Formal_Declarations
1477 (Unit_Declaration_Node
(P
))
1479 Validate_RCI_Declarations
(E
);
1486 end Validate_RCI_Declarations
;
1488 -----------------------------------------
1489 -- Validate_RCI_Subprogram_Declaration --
1490 -----------------------------------------
1492 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1493 K
: constant Node_Kind
:= Nkind
(N
);
1496 Param_Spec
: Node_Id
;
1497 Param_Type
: Entity_Id
;
1498 Base_Param_Type
: Entity_Id
;
1499 Base_Under_Type
: Entity_Id
;
1500 Type_Decl
: Node_Id
;
1501 Error_Node
: Node_Id
:= N
;
1504 -- This procedure enforces rules on subprogram and access to subprogram
1505 -- declarations in RCI units. These rules do not apply to expander
1506 -- generated routines, which are not remote subprograms. It is called:
1508 -- 1. from Analyze_Subprogram_Declaration.
1509 -- 2. from Validate_Object_Declaration (access to subprogram).
1511 if not (Comes_From_Source
(N
) and then In_RCI_Declaration
(N
)) then
1515 if K
= N_Subprogram_Declaration
then
1516 Profile
:= Parameter_Specifications
(Specification
(N
));
1518 else pragma Assert
(K
= N_Object_Declaration
);
1520 -- The above assertion is dubious, the visible declarations of an
1521 -- RCI unit never contain an object declaration, this should be an
1522 -- ACCESS-to-object declaration???
1524 Id
:= Defining_Identifier
(N
);
1526 if Nkind
(Id
) = N_Defining_Identifier
1527 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1528 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1531 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1537 -- Iterate through the parameter specification list, checking that
1538 -- no access parameter and no limited type parameter in the list.
1541 if Present
(Profile
) then
1542 Param_Spec
:= First
(Profile
);
1543 while Present
(Param_Spec
) loop
1544 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1545 Type_Decl
:= Parent
(Param_Type
);
1547 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1549 if K
= N_Subprogram_Declaration
then
1550 Error_Node
:= Param_Spec
;
1553 -- Report error only if declaration is in source program
1555 if Comes_From_Source
1556 (Defining_Entity
(Specification
(N
)))
1559 ("subprogram in 'R'C'I unit cannot have access parameter",
1563 -- For a limited private type parameter, we check only the private
1564 -- declaration and ignore full type declaration, unless this is
1565 -- the only declaration for the type, e.g., as a limited record.
1567 elsif Is_Limited_Type
(Param_Type
)
1568 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1570 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1571 and then not (Has_Private_Declaration
(Param_Type
))
1572 and then Comes_From_Source
(N
)))
1574 -- A limited parameter is legal only if user-specified Read and
1575 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1577 if No
(Full_View
(Param_Type
))
1578 and then Ekind
(Param_Type
) /= E_Record_Type
1580 -- Type does not have completion yet, so if declared in
1581 -- the current RCI scope it is illegal, and will be flagged
1587 -- In Ada 95 the rules permit using a limited type that has
1588 -- user-specified Read and Write attributes that are specified
1589 -- in the private part of the package, whereas Ada 2005
1590 -- (AI-240) revises this to require the attributes to be
1591 -- "available" (implying that the attribute clauses must be
1592 -- visible to the RCI client). The Ada 95 rules violate the
1593 -- contract model for privacy, but we support both semantics
1594 -- for now for compatibility (note that ACATS test BXE2009
1595 -- checks a case that conforms to the Ada 95 rules but is
1596 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1597 -- possibilities of visible TSS stream subprograms or explicit
1598 -- stream attribute definitions because the TSS subprograms
1599 -- can be hidden in the private part while the attribute
1600 -- definitions are still be available from the visible part.
1602 Base_Param_Type
:= Base_Type
(Param_Type
);
1603 Base_Under_Type
:= Base_Type
(Underlying_Type
1606 if (Ada_Version
< Ada_05
1608 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1610 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1612 (No
(TSS
(Base_Under_Type
, TSS_Stream_Read
))
1614 No
(TSS
(Base_Under_Type
, TSS_Stream_Write
))))
1616 (Ada_Version
>= Ada_05
1618 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1620 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1622 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1624 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1626 (not Has_Stream_Attribute_Definition
1627 (Base_Param_Type
, TSS_Stream_Read
)
1629 not Has_Stream_Attribute_Definition
1630 (Base_Param_Type
, TSS_Stream_Write
)))
1632 if K
= N_Subprogram_Declaration
then
1633 Error_Node
:= Param_Spec
;
1636 if Ada_Version
>= Ada_05
then
1638 ("limited parameter in 'R'C'I unit "
1639 & "must have visible read/write attributes ",
1643 ("limited parameter in 'R'C'I unit "
1644 & "must have read/write attributes ",
1647 Explain_Limited_Type
(Param_Type
, Error_Node
);
1650 -- In Ada 95, any non-remote access type (or any type with a
1651 -- component of a non-remote access type) that is visible in an
1652 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1653 -- unit, and thus is already guaranteed to support external
1654 -- streaming. However in Ada 2005 we have to account for the case
1655 -- of named access types from declared pure units as well, which
1656 -- may or may not support external streaming, and so we need to
1657 -- perform a specific check for E.2.3(14/2) here.
1659 -- Note that if the declaration of the type itself is illegal, we
1660 -- do not perform this check since it might be a cascaded error.
1663 if K
= N_Subprogram_Declaration
then
1664 Error_Node
:= Param_Spec
;
1667 if Missing_Read_Write_Attributes
(Param_Type
)
1668 and then not Error_Posted
(Param_Type
)
1671 ("parameter containing non-remote access in 'R'C'I "
1672 & "subprogram must have visible "
1673 & "Read and Write attributes", Error_Node
);
1679 -- No check on return type???
1681 end Validate_RCI_Subprogram_Declaration
;
1683 ----------------------------------------------------
1684 -- Validate_Remote_Access_Object_Type_Declaration --
1685 ----------------------------------------------------
1687 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1689 function Is_Valid_Remote_Object_Type
(E
: Entity_Id
) return Boolean;
1690 -- True if tagged type E is a valid candidate as the root type of the
1691 -- designated type for a RACW, i.e. a tagged limited private type, or a
1692 -- limited interface type, or a private extension of such a type.
1694 ---------------------------------
1695 -- Is_Valid_Remote_Object_Type --
1696 ---------------------------------
1698 function Is_Valid_Remote_Object_Type
(E
: Entity_Id
) return Boolean is
1699 P
: constant Node_Id
:= Parent
(E
);
1702 pragma Assert
(Is_Tagged_Type
(E
));
1704 -- Simple case: a limited private type
1706 if Nkind
(P
) = N_Private_Type_Declaration
1707 and then Is_Limited_Record
(E
)
1711 -- A limited interface is not currently a legal ancestor for the
1712 -- designated type of an RACW type, because a type that implements
1713 -- such an interface need not be limited. However, the ARG seems to
1714 -- incline towards allowing an access to classwide limited interface
1715 -- type as a remote access type, as resolved in AI05-060. But note
1716 -- that the expansion circuitry for RACWs that designate classwide
1717 -- interfaces is not complete yet.
1719 elsif Is_Limited_Record
(E
) and then Is_Limited_Interface
(E
) then
1722 -- A generic tagged limited type is a valid candidate. Limitedness
1723 -- will be checked again on the actual at instantiation point.
1725 elsif Nkind
(P
) = N_Formal_Type_Declaration
1726 and then Ekind
(E
) = E_Record_Type_With_Private
1727 and then Is_Generic_Type
(E
)
1728 and then Is_Limited_Record
(E
)
1732 -- A private extension declaration is a valid candidate if its parent
1735 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
1736 return Is_Valid_Remote_Object_Type
(Etype
(E
));
1741 end Is_Valid_Remote_Object_Type
;
1745 Direct_Designated_Type
: Entity_Id
;
1746 Desig_Type
: Entity_Id
;
1748 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1751 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1752 -- given node is N_Access_To_Object_Definition.
1754 if not Comes_From_Source
(T
)
1755 or else (not In_RCI_Declaration
(Parent
(T
))
1756 and then not In_RT_Declaration
)
1761 -- An access definition in the private part of a Remote Types package
1762 -- may be legal if it has user-defined Read and Write attributes. This
1763 -- will be checked at the end of the package spec processing.
1765 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1769 -- Check RCI or RT unit type declaration. It may not contain the
1770 -- declaration of an access-to-object type unless it is a general access
1771 -- type that designates a class-wide limited private type. There are
1772 -- also constraints on the primitive subprograms of the class-wide type
1773 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1775 if Ekind
(T
) /= E_General_Access_Type
1776 or else Ekind
(Designated_Type
(T
)) /= E_Class_Wide_Type
1778 if In_RCI_Declaration
(Parent
(T
)) then
1780 ("error in access type in Remote_Call_Interface unit", T
);
1783 ("error in access type in Remote_Types unit", T
);
1786 Error_Msg_N
("\must be general access to class-wide type", T
);
1790 Direct_Designated_Type
:= Designated_Type
(T
);
1791 Desig_Type
:= Etype
(Direct_Designated_Type
);
1793 -- Why is the check below not in
1794 -- Validate_Remote_Access_To_Class_Wide_Type???
1796 if not Is_Valid_Remote_Object_Type
(Desig_Type
) then
1798 ("error in designated type of remote access to class-wide type", T
);
1800 ("\must be tagged limited private or private extension", T
);
1803 end Validate_Remote_Access_Object_Type_Declaration
;
1805 -----------------------------------------------
1806 -- Validate_Remote_Access_To_Class_Wide_Type --
1807 -----------------------------------------------
1809 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1810 K
: constant Node_Kind
:= Nkind
(N
);
1811 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1815 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1816 -- of class-wide limited private types.
1818 -- Storage_Pool and Storage_Size are not defined for such types
1820 -- The expected type of allocator must not be such a type.
1822 -- The actual parameter of generic instantiation must not be such a
1823 -- type if the formal parameter is of an access type.
1825 -- On entry, there are five cases
1827 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1828 -- either Storage_Pool or Storage_Size.
1830 -- 2. called from exp_ch4 Expand_N_Allocator
1832 -- 3. called from sem_ch12 Analyze_Associations
1834 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1836 -- 5. called from sem_res Resolve_Actuals
1838 if K
= N_Attribute_Reference
then
1839 E
:= Etype
(Prefix
(N
));
1841 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1842 Error_Msg_N
("incorrect attribute of remote operand", N
);
1846 elsif K
= N_Allocator
then
1849 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1850 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1854 elsif K
in N_Has_Entity
then
1857 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1858 Error_Msg_N
("incorrect remote type generic actual", N
);
1862 -- This subprogram also enforces the checks in E.2.2(13). A value of
1863 -- such type must not be dereferenced unless as controlling operand of
1864 -- a dispatching call. Explicit dereferences not coming from source are
1865 -- exempted from this checking because the expander produces them in
1866 -- some cases (such as for tag checks on dispatching calls with multiple
1867 -- controlling operands). However we do check in the case of an implicit
1868 -- dereference that is expanded to an explicit dereference (hence the
1869 -- test of whether Original_Node (N) comes from source).
1871 elsif K
= N_Explicit_Dereference
1872 and then Comes_From_Source
(Original_Node
(N
))
1874 E
:= Etype
(Prefix
(N
));
1876 -- If the class-wide type is not a remote one, the restrictions
1879 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1883 -- If we have a true dereference that comes from source and that
1884 -- is a controlling argument for a dispatching call, accept it.
1886 if Is_Actual_Parameter
(N
)
1887 and then Is_Controlling_Actual
(N
)
1892 -- If we are just within a procedure or function call and the
1893 -- dereference has not been analyzed, return because this procedure
1894 -- will be called again from sem_res Resolve_Actuals. The same can
1895 -- apply in the case of dereference that is the prefix of a selected
1896 -- component, which can be a call given in prefixed form.
1898 if (Is_Actual_Parameter
(N
)
1899 or else PK
= N_Selected_Component
)
1900 and then not Analyzed
(N
)
1905 -- We must allow expanded code to generate a reference to the tag of
1906 -- the designated object (may be either the actual tag, or the stub
1907 -- tag in the case of a remote object).
1909 if PK
= N_Selected_Component
1910 and then Is_Tag
(Entity
(Selector_Name
(Parent
(N
))))
1916 ("invalid dereference of a remote access-to-class-wide value", N
);
1918 end Validate_Remote_Access_To_Class_Wide_Type
;
1920 ------------------------------------------
1921 -- Validate_Remote_Type_Type_Conversion --
1922 ------------------------------------------
1924 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1925 S
: constant Entity_Id
:= Etype
(N
);
1926 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1929 -- This test is required in the case where a conversion appears inside a
1930 -- normal package, it does not necessarily have to be inside an RCI,
1931 -- Remote_Types unit (RM E.2.2(9,12)).
1933 if Is_Remote_Access_To_Subprogram_Type
(E
)
1934 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1937 ("incorrect conversion of remote operand to local type", N
);
1940 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1941 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1944 ("incorrect conversion of local operand to remote type", N
);
1947 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1948 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1951 ("incorrect conversion of remote operand to local type", N
);
1955 -- If a local access type is converted into a RACW type, then the
1956 -- current unit has a pointer that may now be exported to another
1959 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1960 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1962 Set_Has_RACW
(Current_Sem_Unit
);
1964 end Validate_Remote_Type_Type_Conversion
;
1966 -------------------------------
1967 -- Validate_RT_RAT_Component --
1968 -------------------------------
1970 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1971 Spec
: constant Node_Id
:= Specification
(N
);
1972 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1975 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1978 if not Is_Remote_Types
(Name_U
) then
1982 Typ
:= First_Entity
(Name_U
);
1983 while Present
(Typ
) and then Typ
/= First_Priv_Ent
loop
1984 U_Typ
:= Underlying_Type
(Typ
);
1990 if Comes_From_Source
(Typ
) and then Is_Type
(Typ
) then
1991 if Missing_Read_Write_Attributes
(Typ
) then
1992 if Is_Non_Remote_Access_Type
(Typ
) then
1993 Error_Msg_N
("error in non-remote access type", U_Typ
);
1996 ("error in record type containing a component of a " &
1997 "non-remote access type", U_Typ
);
2000 if Ada_Version
>= Ada_05
then
2002 ("\must have visible Read and Write attribute " &
2003 "definition clauses (RM E.2.2(8))", U_Typ
);
2006 ("\must have Read and Write attribute " &
2007 "definition clauses (RM E.2.2(8))", U_Typ
);
2014 end Validate_RT_RAT_Component
;
2016 -----------------------------------------
2017 -- Validate_SP_Access_Object_Type_Decl --
2018 -----------------------------------------
2020 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
2021 Direct_Designated_Type
: Entity_Id
;
2023 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
2024 -- Return true if the protected type designated by T has
2025 -- entry declarations.
2027 ----------------------------
2028 -- Has_Entry_Declarations --
2029 ----------------------------
2031 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
2035 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
2036 Ety
:= First_Entity
(E
);
2037 while Present
(Ety
) loop
2038 if Ekind
(Ety
) = E_Entry
then
2047 end Has_Entry_Declarations
;
2049 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2052 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
2053 -- Nkind of the given entity is N_Access_To_Object_Definition.
2055 if not Comes_From_Source
(T
)
2056 or else not In_Shared_Passive_Unit
2057 or else In_Subprogram_Task_Protected_Unit
2062 -- Check Shared Passive unit. It should not contain the declaration
2063 -- of an access-to-object type whose designated type is a class-wide
2064 -- type, task type or protected type with entry (RM E.2.1(7)).
2066 Direct_Designated_Type
:= Designated_Type
(T
);
2068 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
2070 ("invalid access-to-class-wide type in shared passive unit", T
);
2073 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
2075 ("invalid access-to-task type in shared passive unit", T
);
2078 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
2079 and then Has_Entry_Declarations
(Direct_Designated_Type
)
2082 ("invalid access-to-protected type in shared passive unit", T
);
2085 end Validate_SP_Access_Object_Type_Decl
;
2087 ---------------------------------
2088 -- Validate_Static_Object_Name --
2089 ---------------------------------
2091 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
2094 function Is_Primary
(N
: Node_Id
) return Boolean;
2095 -- Determine whether node is syntactically a primary in an expression
2096 -- This function should probably be somewhere else ???
2097 -- Also it does not do what it says, e.g if N is a binary operator
2098 -- whose parent is a binary operator, Is_Primary returns True ???
2104 function Is_Primary
(N
: Node_Id
) return Boolean is
2105 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
2109 when N_Op | N_Membership_Test
=>
2113 | N_Component_Association
2114 | N_Index_Or_Discriminant_Constraint
=>
2117 when N_Attribute_Reference
=>
2118 return Attribute_Name
(Parent
(N
)) /= Name_Address
2119 and then Attribute_Name
(Parent
(N
)) /= Name_Access
2120 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
2122 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
2124 when N_Indexed_Component
=>
2125 return (N
/= Prefix
(Parent
(N
))
2126 or else Is_Primary
(Parent
(N
)));
2128 when N_Qualified_Expression | N_Type_Conversion
=>
2129 return Is_Primary
(Parent
(N
));
2131 when N_Assignment_Statement | N_Object_Declaration
=>
2132 return (N
= Expression
(Parent
(N
)));
2134 when N_Selected_Component
=>
2135 return Is_Primary
(Parent
(N
));
2142 -- Start of processing for Validate_Static_Object_Name
2145 if not In_Preelaborated_Unit
2146 or else not Comes_From_Source
(N
)
2147 or else In_Subprogram_Or_Concurrent_Unit
2148 or else Ekind
(Current_Scope
) = E_Block
2152 -- Filter out cases where primary is default in a component declaration,
2153 -- discriminant specification, or actual in a record type initialization
2156 -- Initialization call of internal types
2158 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
2160 if Present
(Parent
(Parent
(N
)))
2161 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
2166 if Nkind
(Name
(Parent
(N
))) = N_Identifier
2167 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
2173 -- Error if the name is a primary in an expression. The parent must not
2174 -- be an operator, or a selected component or an indexed component that
2175 -- is itself a primary. Entities that are actuals do not need to be
2176 -- checked, because the call itself will be diagnosed.
2179 and then (not Inside_A_Generic
2180 or else Present
(Enclosing_Generic_Body
(N
)))
2182 if Ekind
(Entity
(N
)) = E_Variable
2183 or else Ekind
(Entity
(N
)) in Formal_Object_Kind
2185 Flag_Non_Static_Expr
2186 ("non-static object name in preelaborated unit", N
);
2188 -- We take the view that a constant defined in another preelaborated
2189 -- unit is preelaborable, even though it may have a private type and
2190 -- thus appear non-static in a client. This must be the intent of
2191 -- the language, but currently is an RM gap ???
2193 elsif Ekind
(Entity
(N
)) = E_Constant
2194 and then not Is_Static_Expression
(N
)
2198 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
2200 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
2201 and then (Is_Preelaborated
(Scope
(E
))
2202 or else Is_Pure
(Scope
(E
))
2203 or else (Present
(Renamed_Object
(E
))
2205 Is_Entity_Name
(Renamed_Object
(E
))
2208 (Scope
(Renamed_Object
(E
)))
2211 (Renamed_Object
(E
))))))
2215 -- This is the error case
2218 -- In GNAT mode, this is just a warning, to allow it to be
2219 -- judiciously turned off. Otherwise it is a real error.
2223 ("?non-static constant in preelaborated unit", N
);
2225 Flag_Non_Static_Expr
2226 ("non-static constant in preelaborated unit", N
);
2231 end Validate_Static_Object_Name
;