1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Aux
; use Sem_Aux
;
39 with Sem_Eval
; use Sem_Eval
;
40 with Sem_Util
; use Sem_Util
;
41 with Sinfo
; use Sinfo
;
42 with Snames
; use Snames
;
43 with Stand
; use Stand
;
45 package body Sem_Cat
is
47 -----------------------
48 -- Local Subprograms --
49 -----------------------
51 procedure Check_Categorization_Dependencies
52 (Unit_Entity
: Entity_Id
;
53 Depended_Entity
: Entity_Id
;
55 Is_Subunit
: Boolean);
56 -- This procedure checks that the categorization of a lib unit and that
57 -- of the depended unit satisfy dependency restrictions.
58 -- The depended_entity can be the entity in a with_clause item, in which
59 -- case Info_Node denotes that item. The depended_entity can also be the
60 -- parent unit of a child unit, in which case Info_Node is the declaration
61 -- of the child unit. The error message is posted on Info_Node, and is
62 -- specialized if Is_Subunit is true.
64 procedure Check_Non_Static_Default_Expr
67 -- Iterate through the component list of a record definition, check
68 -- that no component is declared with a nonstatic default value.
69 -- If a nonstatic default exists, report an error on Obj_Decl.
71 -- Iterate through the component list of a record definition, check
72 -- that no component is declared with a non-static default value.
74 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
75 -- Return True if the entity or one of its subcomponents is of an access
76 -- type that does not have user-defined Read and Write attributes visible
79 function In_RCI_Declaration
(N
: Node_Id
) return Boolean;
80 -- Determines if a declaration is within the visible part of a Remote
81 -- Call Interface compilation unit, for semantic checking purposes only
82 -- (returns false within an instance and within the package body).
84 function In_RT_Declaration
return Boolean;
85 -- Determines if current scope is within the declaration of a Remote Types
86 -- unit, for semantic checking purposes.
88 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
89 -- Returns true if the entity is a type whose full view is a non-remote
90 -- access type, for the purpose of enforcing E.2.2(8) rules.
92 function In_Shared_Passive_Unit
return Boolean;
93 -- Determines if current scope is within a Shared Passive compilation unit
95 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
96 -- Iterate through the list of discriminants to check if any of them
97 -- contains non-static default expression, which is a violation in
98 -- a preelaborated library unit.
100 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
101 -- Check validity of declaration if RCI or RT unit. It should not contain
102 -- the declaration of an access-to-object type unless it is a general
103 -- access type that designates a class-wide limited private type. There are
104 -- also constraints about the primitive subprograms of the class-wide type.
105 -- RM E.2 (9, 13, 14)
107 ---------------------------------------
108 -- Check_Categorization_Dependencies --
109 ---------------------------------------
111 procedure Check_Categorization_Dependencies
112 (Unit_Entity
: Entity_Id
;
113 Depended_Entity
: Entity_Id
;
115 Is_Subunit
: Boolean)
117 N
: constant Node_Id
:= Info_Node
;
120 -- Here we define an enumeration type to represent categorization types,
121 -- ordered so that a unit with a given categorization can only WITH
122 -- units with lower or equal categorization type.
124 type Categorization
is
128 Remote_Call_Interface
,
131 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
132 -- Check categorization flags from entity, and return in the form
133 -- of the lowest value of the Categorization type that applies to E.
135 ------------------------
136 -- Get_Categorization --
137 ------------------------
139 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
141 -- Get the lowest categorization that corresponds to E. Note that
142 -- nothing prevents several (different) categorization pragmas
143 -- to apply to the same library unit, in which case the unit has
144 -- all associated categories, so we need to be careful here to
145 -- check pragmas in proper Categorization order in order to
146 -- return the lowest applicable value.
148 -- Ignore Pure specification if set by pragma Pure_Function
152 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
156 elsif Is_Shared_Passive
(E
) then
157 return Shared_Passive
;
159 elsif Is_Remote_Types
(E
) then
162 elsif Is_Remote_Call_Interface
(E
) then
163 return Remote_Call_Interface
;
168 end Get_Categorization
;
170 Unit_Category
: Categorization
;
171 With_Category
: Categorization
;
173 -- Start of processing for Check_Categorization_Dependencies
176 -- Intrinsic subprograms are preelaborated, so do not impose any
177 -- categorization dependencies.
179 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
183 -- First check 10.2.1 (11/1) rules on preelaborate packages
185 if Is_Preelaborated
(Unit_Entity
)
186 and then not Is_Preelaborated
(Depended_Entity
)
187 and then not Is_Pure
(Depended_Entity
)
194 -- Check categorization rules of RM E.2(5)
196 Unit_Category
:= Get_Categorization
(Unit_Entity
);
197 With_Category
:= Get_Categorization
(Depended_Entity
);
199 if With_Category
> Unit_Category
then
201 -- Special case: Remote_Types and Remote_Call_Interface are allowed
202 -- to WITH anything in the package body, per (RM E.2(5)).
204 if (Unit_Category
= Remote_Types
205 or else Unit_Category
= Remote_Call_Interface
)
206 and then In_Package_Body
(Unit_Entity
)
210 -- Special case: Remote_Types can depend on Preelaborated per
213 elsif Unit_Category
= Remote_Types
214 and then Is_Preelaborated
(Depended_Entity
)
218 -- All other cases, we do have an error
225 -- Here if we have an error
229 -- These messages are warnings in GNAT mode or if the -gnateP switch
230 -- was set. Otherwise these are real errors for real illegalities.
232 -- The reason we suppress these errors in GNAT mode is that the run-
233 -- time has several instances of violations of the categorization
234 -- errors (e.g. Pure units withing Preelaborate units. All these
235 -- violations are harmless in the cases where we intend them, and
236 -- we suppress the warnings with Warnings (Off). In cases where we
237 -- do not intend the violation, warnings are errors in GNAT mode
238 -- anyway, so we will still get an error.
241 Treat_Categorization_Errors_As_Warnings
or GNAT_Mode
;
243 -- Don't give error if main unit is not an internal unit, and the
244 -- unit generating the message is an internal unit. This is the
245 -- situation in which such messages would be ignored in any case,
246 -- so it is convenient not to generate them (since it causes
247 -- annoying interference with debugging).
249 if Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
250 and then not Is_Internal_File_Name
(Unit_File_Name
(Main_Unit
))
256 elsif Is_Subunit
then
258 ("<subunit cannot depend on& " &
259 "(parent has wrong categorization)", N
, Depended_Entity
);
261 -- Normal unit, not subunit
265 ("<cannot depend on& " &
266 "(wrong categorization)", N
, Depended_Entity
);
269 -- Add further explanation for Pure/Preelaborate common cases
271 if Unit_Category
= Pure
then
273 ("\<pure unit cannot depend on non-pure unit",
276 elsif Is_Preelaborated
(Unit_Entity
)
277 and then not Is_Preelaborated
(Depended_Entity
)
278 and then not Is_Pure
(Depended_Entity
)
281 ("\<preelaborated unit cannot depend on "
282 & "non-preelaborated unit",
286 end Check_Categorization_Dependencies
;
288 -----------------------------------
289 -- Check_Non_Static_Default_Expr --
290 -----------------------------------
292 procedure Check_Non_Static_Default_Expr
297 Component_Decl
: Node_Id
;
300 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
301 Recdef
:= Record_Extension_Part
(Type_Def
);
311 -- Check that component declarations do not involve:
313 -- a. a non-static default expression, where the object is
314 -- declared to be default initialized.
316 -- b. a dynamic Itype (discriminants and constraints)
318 if Null_Present
(Recdef
) then
321 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
324 while Present
(Component_Decl
)
325 and then Nkind
(Component_Decl
) = N_Component_Declaration
327 if Present
(Expression
(Component_Decl
))
328 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
329 and then not Is_Static_Expression
(Expression
(Component_Decl
))
331 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
333 ("object in preelaborated unit has non-static default#",
336 -- Fix this later ???
338 -- elsif Has_Dynamic_Itype (Component_Decl) then
340 -- ("dynamic type discriminant," &
341 -- " constraint in preelaborated unit",
345 Next
(Component_Decl
);
347 end Check_Non_Static_Default_Expr
;
349 -------------------------------------
350 -- Has_Stream_Attribute_Definition --
351 -------------------------------------
353 function Has_Stream_Attribute_Definition
356 At_Any_Place
: Boolean := False) return Boolean
359 Full_Type
: Entity_Id
:= Typ
;
362 -- In the case of a type derived from a private view, any specified
363 -- stream attributes will be attached to the derived type's underlying
364 -- type rather the derived type entity itself (which is itself private).
366 if Is_Private_Type
(Typ
)
367 and then Is_Derived_Type
(Typ
)
368 and then Present
(Full_View
(Typ
))
370 Full_Type
:= Underlying_Type
(Typ
);
373 -- We start from the declaration node and then loop until the end of
374 -- the list until we find the requested attribute definition clause.
375 -- In Ada 2005 mode, clauses are ignored if they are not currently
376 -- visible (this is tested using the corresponding Entity, which is
377 -- inserted by the expander at the point where the clause occurs),
378 -- unless At_Any_Place is true.
380 Rep_Item
:= First_Rep_Item
(Full_Type
);
381 while Present
(Rep_Item
) loop
382 if Nkind
(Rep_Item
) = N_Attribute_Definition_Clause
then
383 case Chars
(Rep_Item
) is
385 exit when Nam
= TSS_Stream_Read
;
388 exit when Nam
= TSS_Stream_Write
;
391 exit when Nam
= TSS_Stream_Input
;
394 exit when Nam
= TSS_Stream_Output
;
402 Next_Rep_Item
(Rep_Item
);
405 -- If At_Any_Place is true, return True if the attribute is available
406 -- at any place; if it is false, return True only if the attribute is
407 -- currently visible.
409 return Present
(Rep_Item
)
410 and then (Ada_Version
< Ada_2005
412 or else not Is_Hidden
(Entity
(Rep_Item
)));
413 end Has_Stream_Attribute_Definition
;
415 ---------------------------
416 -- In_Preelaborated_Unit --
417 ---------------------------
419 function In_Preelaborated_Unit
return Boolean is
420 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
421 Unit_Kind
: constant Node_Kind
:=
422 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
425 -- There are no constraints on body of remote_call_interface or
426 -- remote_types packages.
428 return (Unit_Entity
/= Standard_Standard
)
429 and then (Is_Preelaborated
(Unit_Entity
)
430 or else Is_Pure
(Unit_Entity
)
431 or else Is_Shared_Passive
(Unit_Entity
)
433 ((Is_Remote_Types
(Unit_Entity
)
434 or else Is_Remote_Call_Interface
(Unit_Entity
))
435 and then Ekind
(Unit_Entity
) = E_Package
436 and then Unit_Kind
/= N_Package_Body
437 and then not In_Package_Body
(Unit_Entity
)
438 and then not In_Instance
));
439 end In_Preelaborated_Unit
;
445 function In_Pure_Unit
return Boolean is
447 return Is_Pure
(Current_Scope
);
450 ------------------------
451 -- In_RCI_Declaration --
452 ------------------------
454 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
455 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
456 Unit_Kind
: constant Node_Kind
:=
457 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
460 -- There are no restrictions on the private part or body
463 return Is_Remote_Call_Interface
(Unit_Entity
)
464 and then Is_Package_Or_Generic_Package
(Unit_Entity
)
465 and then Unit_Kind
/= N_Package_Body
466 and then List_Containing
(N
) =
468 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
469 and then not In_Package_Body
(Unit_Entity
)
470 and then not In_Instance
;
472 -- What about the case of a nested package in the visible part???
473 -- This case is missed by the List_Containing check above???
474 end In_RCI_Declaration
;
476 -----------------------
477 -- In_RT_Declaration --
478 -----------------------
480 function In_RT_Declaration
return Boolean is
481 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
482 Unit_Kind
: constant Node_Kind
:=
483 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
486 -- There are no restrictions on the body of a Remote Types unit
488 return Is_Remote_Types
(Unit_Entity
)
489 and then Is_Package_Or_Generic_Package
(Unit_Entity
)
490 and then Unit_Kind
/= N_Package_Body
491 and then not In_Package_Body
(Unit_Entity
)
492 and then not In_Instance
;
493 end In_RT_Declaration
;
495 ----------------------------
496 -- In_Shared_Passive_Unit --
497 ----------------------------
499 function In_Shared_Passive_Unit
return Boolean is
500 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
503 return Is_Shared_Passive
(Unit_Entity
);
504 end In_Shared_Passive_Unit
;
506 ---------------------------------------
507 -- In_Subprogram_Task_Protected_Unit --
508 ---------------------------------------
510 function In_Subprogram_Task_Protected_Unit
return Boolean is
514 -- The following is to verify that a declaration is inside
515 -- subprogram, generic subprogram, task unit, protected unit.
516 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
518 -- Use scope chain to check successively outer scopes
524 Is_Generic_Subprogram
(E
)
526 Is_Concurrent_Type
(E
)
530 elsif E
= Standard_Standard
then
536 end In_Subprogram_Task_Protected_Unit
;
538 -------------------------------
539 -- Is_Non_Remote_Access_Type --
540 -------------------------------
542 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
543 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
547 -- This case arises for the case of a generic formal type, in which
548 -- case E.2.2(8) rules will be enforced at instantiation time.
553 return Is_Access_Type
(U_E
)
554 and then not Is_Remote_Access_To_Class_Wide_Type
(U_E
)
555 and then not Is_Remote_Access_To_Subprogram_Type
(U_E
);
556 end Is_Non_Remote_Access_Type
;
558 ----------------------------------
559 -- Missing_Read_Write_Attribute --
560 ----------------------------------
562 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
563 Component
: Entity_Id
;
564 Component_Type
: Entity_Id
;
565 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
567 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
568 -- Return True if entity has attribute definition clauses for Read and
569 -- Write attributes that are visible at some place.
571 -------------------------------
572 -- Has_Read_Write_Attributes --
573 -------------------------------
575 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
578 and then Has_Stream_Attribute_Definition
(E
,
579 TSS_Stream_Read
, At_Any_Place
=> True)
580 and then Has_Stream_Attribute_Definition
(E
,
581 TSS_Stream_Write
, At_Any_Place
=> True);
582 end Has_Read_Write_Attributes
;
584 -- Start of processing for Missing_Read_Write_Attributes
590 elsif Has_Read_Write_Attributes
(E
)
591 or else Has_Read_Write_Attributes
(U_E
)
595 elsif Is_Non_Remote_Access_Type
(U_E
) then
599 if Is_Record_Type
(U_E
) then
600 Component
:= First_Entity
(U_E
);
601 while Present
(Component
) loop
602 if not Is_Tag
(Component
) then
603 Component_Type
:= Etype
(Component
);
605 if Missing_Read_Write_Attributes
(Component_Type
) then
610 Next_Entity
(Component
);
615 end Missing_Read_Write_Attributes
;
617 -------------------------------------
618 -- Set_Categorization_From_Pragmas --
619 -------------------------------------
621 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
622 P
: constant Node_Id
:= Parent
(N
);
623 S
: constant Entity_Id
:= Current_Scope
;
625 procedure Set_Parents
(Visibility
: Boolean);
626 -- If this is a child instance, the parents are not immediately
627 -- visible during analysis. Make them momentarily visible so that
628 -- the argument of the pragma can be resolved properly, and reset
635 procedure Set_Parents
(Visibility
: Boolean) is
639 while Present
(Par
) and then Par
/= Standard_Standard
loop
640 Set_Is_Immediately_Visible
(Par
, Visibility
);
645 -- Start of processing for Set_Categorization_From_Pragmas
648 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
649 -- The purpose is to set categorization flags before analyzing the
650 -- unit itself, so as to diagnose violations of categorization as
651 -- we process each declaration, even though the pragma appears after
654 if Nkind
(P
) /= N_Compilation_Unit
then
663 and then Is_Generic_Instance
(S
)
668 PN
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
669 while Present
(PN
) loop
671 -- Skip implicit types that may have been introduced by
672 -- previous analysis.
674 if Nkind
(PN
) = N_Pragma
then
675 case Get_Pragma_Id
(PN
) is
676 when Pragma_All_Calls_Remote |
677 Pragma_Preelaborate |
679 Pragma_Remote_Call_Interface |
680 Pragma_Remote_Types |
681 Pragma_Shared_Passive
=> Analyze
(PN
);
690 and then Is_Generic_Instance
(S
)
695 end Set_Categorization_From_Pragmas
;
697 -----------------------------------
698 -- Set_Categorization_From_Scope --
699 -----------------------------------
701 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
702 Declaration
: Node_Id
:= Empty
;
703 Specification
: Node_Id
:= Empty
;
707 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
709 if not Is_Remote_Call_Interface
(E
) then
710 if Ekind
(E
) in Subprogram_Kind
then
711 Declaration
:= Unit_Declaration_Node
(E
);
713 if Nkind
(Declaration
) = N_Subprogram_Body
715 Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
717 Specification
:= Corresponding_Spec
(Declaration
);
721 -- A subprogram body or renaming-as-body is a remote call
722 -- interface if it serves as the completion of a subprogram
723 -- declaration that is a remote call interface.
725 if Nkind
(Specification
) in N_Entity
then
726 Set_Is_Remote_Call_Interface
727 (E
, Is_Remote_Call_Interface
(Specification
));
729 -- A subprogram declaration is a remote call interface when it is
730 -- declared within the visible part of, or declared by, a library
731 -- unit declaration that is a remote call interface.
734 Set_Is_Remote_Call_Interface
735 (E
, Is_Remote_Call_Interface
(Scop
)
736 and then not (In_Private_Part
(Scop
)
737 or else In_Package_Body
(Scop
)));
742 (E
, Is_Remote_Types
(Scop
)
743 and then not (In_Private_Part
(Scop
)
744 or else In_Package_Body
(Scop
)));
745 end Set_Categorization_From_Scope
;
747 ------------------------------
748 -- Static_Discriminant_Expr --
749 ------------------------------
751 -- We need to accommodate a Why_Not_Static call somehow here ???
753 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
754 Discriminant_Spec
: Node_Id
;
757 Discriminant_Spec
:= First
(L
);
758 while Present
(Discriminant_Spec
) loop
759 if Present
(Expression
(Discriminant_Spec
))
760 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
765 Next
(Discriminant_Spec
);
769 end Static_Discriminant_Expr
;
771 --------------------------------------
772 -- Validate_Access_Type_Declaration --
773 --------------------------------------
775 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
776 Def
: constant Node_Id
:= Type_Definition
(N
);
781 -- Access to subprogram case
783 when N_Access_To_Subprogram_Definition
=>
785 -- A pure library_item must not contain the declaration of a
786 -- named access type, except within a subprogram, generic
787 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
789 -- This test is skipped in Ada 2005 (see AI-366)
791 if Ada_Version
< Ada_2005
792 and then Comes_From_Source
(T
)
793 and then In_Pure_Unit
794 and then not In_Subprogram_Task_Protected_Unit
796 Error_Msg_N
("named access type not allowed in pure unit", T
);
799 -- Access to object case
801 when N_Access_To_Object_Definition
=>
802 if Comes_From_Source
(T
)
803 and then In_Pure_Unit
804 and then not In_Subprogram_Task_Protected_Unit
806 -- We can't give the message yet, since the type is not frozen
807 -- and in Ada 2005 mode, access types are allowed in pure units
808 -- if the type has no storage pool (see AI-366). So we set a
809 -- flag which will be checked at freeze time.
811 Set_Is_Pure_Unit_Access_Type
(T
);
814 -- Check for RCI or RT unit type declaration: declaration of an
815 -- access-to-object type is illegal unless it is a general access
816 -- type that designates a class-wide limited private type.
817 -- Note that constraints on the primitive subprograms of the
818 -- designated tagged type are not enforced here but in
819 -- Validate_RACW_Primitives, which is done separately because the
820 -- designated type might not be frozen (and therefore its
821 -- primitive operations might not be completely known) at the
822 -- point of the RACW declaration.
824 Validate_Remote_Access_Object_Type_Declaration
(T
);
826 -- Check for shared passive unit type declaration. It should
827 -- not contain the declaration of access to class wide type,
828 -- access to task type and access to protected type with entry.
830 Validate_SP_Access_Object_Type_Decl
(T
);
836 -- Set categorization flag from package on entity as well, to allow
837 -- easy checks later on for required validations of RCI or RT units.
838 -- This is only done for entities that are in the original source.
840 if Comes_From_Source
(T
)
841 and then not (In_Package_Body
(Scope
(T
))
842 or else In_Private_Part
(Scope
(T
)))
844 Set_Is_Remote_Call_Interface
845 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
847 (T
, Is_Remote_Types
(Scope
(T
)));
849 end Validate_Access_Type_Declaration
;
851 ----------------------------
852 -- Validate_Ancestor_Part --
853 ----------------------------
855 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
856 A
: constant Node_Id
:= Ancestor_Part
(N
);
857 T
: constant Entity_Id
:= Entity
(A
);
860 if In_Preelaborated_Unit
861 and then not In_Subprogram_Or_Concurrent_Unit
862 and then (not Inside_A_Generic
863 or else Present
(Enclosing_Generic_Body
(N
)))
865 -- If the type is private, it must have the Ada 2005 pragma
866 -- Has_Preelaborable_Initialization.
867 -- The check is omitted within predefined units. This is probably
868 -- obsolete code to fix the Ada95 weakness in this area ???
870 if Is_Private_Type
(T
)
871 and then not Has_Pragma_Preelab_Init
(T
)
872 and then not Is_Internal_File_Name
873 (Unit_File_Name
(Get_Source_Unit
(N
)))
876 ("private ancestor type not allowed in preelaborated unit", A
);
878 elsif Is_Record_Type
(T
) then
879 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
880 Check_Non_Static_Default_Expr
881 (Type_Definition
(Parent
(T
)), A
);
885 end Validate_Ancestor_Part
;
887 ----------------------------------------
888 -- Validate_Categorization_Dependency --
889 ----------------------------------------
891 procedure Validate_Categorization_Dependency
895 K
: constant Node_Kind
:= Nkind
(N
);
896 P
: Node_Id
:= Parent
(N
);
898 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
901 -- Only validate library units and subunits. For subunits, checks
902 -- concerning withed units apply to the parent compilation unit.
909 and then not Is_Compilation_Unit
(U
)
910 and then not Is_Child_Unit
(U
)
916 if Nkind
(P
) /= N_Compilation_Unit
then
920 -- Body of RCI unit does not need validation
922 if Is_Remote_Call_Interface
(E
)
923 and then (Nkind
(N
) = N_Package_Body
924 or else Nkind
(N
) = N_Subprogram_Body
)
929 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
933 Entity_Of_Withed
: Entity_Id
;
936 Item
:= First
(Context_Items
(P
));
937 while Present
(Item
) loop
938 if Nkind
(Item
) = N_With_Clause
939 and then not (Implicit_With
(Item
)
940 or else Limited_Present
(Item
))
942 Entity_Of_Withed
:= Entity
(Name
(Item
));
943 Check_Categorization_Dependencies
944 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
951 -- Child depends on parent; therefore parent should also be categorized
952 -- and satisfy the dependency hierarchy.
954 -- Check if N is a child spec
956 if (K
in N_Generic_Declaration
or else
957 K
in N_Generic_Instantiation
or else
958 K
in N_Generic_Renaming_Declaration
or else
959 K
= N_Package_Declaration
or else
960 K
= N_Package_Renaming_Declaration
or else
961 K
= N_Subprogram_Declaration
or else
962 K
= N_Subprogram_Renaming_Declaration
)
963 and then Present
(Parent_Spec
(N
))
965 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
967 -- Verify that public child of an RCI library unit must also be an
968 -- RCI library unit (RM E.2.3(15)).
970 if Is_Remote_Call_Interface
(Scope
(E
))
971 and then not Private_Present
(P
)
972 and then not Is_Remote_Call_Interface
(E
)
974 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
977 end Validate_Categorization_Dependency
;
979 --------------------------------
980 -- Validate_Controlled_Object --
981 --------------------------------
983 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
985 -- Don't need this check in Ada 2005 mode, where this is all taken
986 -- care of by the mechanism for Preelaborable Initialization.
988 if Ada_Version
>= Ada_2005
then
992 -- For now, never apply this check for internal GNAT units, since we
993 -- have a number of cases in the library where we are stuck with objects
994 -- of this type, and the RM requires Preelaborate.
996 -- For similar reasons, we only do this check for source entities, since
997 -- we generate entities of this type in some situations.
999 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1000 -- We have to enforce them for RM compatibility, but we have no trouble
1001 -- accepting these objects and doing the right thing. Note that there is
1002 -- no requirement that Preelaborate not actually generate any code!
1004 if In_Preelaborated_Unit
1005 and then not Debug_Flag_PP
1006 and then Comes_From_Source
(E
)
1008 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
1009 and then (not Inside_A_Generic
1010 or else Present
(Enclosing_Generic_Body
(E
)))
1011 and then not Is_Protected_Type
(Etype
(E
))
1014 ("library level controlled object not allowed in " &
1015 "preelaborated unit", E
);
1017 end Validate_Controlled_Object
;
1019 --------------------------------------
1020 -- Validate_Null_Statement_Sequence --
1021 --------------------------------------
1023 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
1027 if In_Preelaborated_Unit
then
1028 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
1029 while Present
(Item
) loop
1030 if Nkind
(Item
) /= N_Label
1031 and then Nkind
(Item
) /= N_Null_Statement
1033 -- In GNAT mode, this is a warning, allowing the run-time
1034 -- to judiciously bypass this error condition.
1036 Error_Msg_Warn
:= GNAT_Mode
;
1038 ("<statements not allowed in preelaborated unit", Item
);
1046 end Validate_Null_Statement_Sequence
;
1048 ---------------------------------
1049 -- Validate_Object_Declaration --
1050 ---------------------------------
1052 procedure Validate_Object_Declaration
(N
: Node_Id
) is
1053 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1054 E
: constant Node_Id
:= Expression
(N
);
1055 Odf
: constant Node_Id
:= Object_Definition
(N
);
1056 T
: constant Entity_Id
:= Etype
(Id
);
1059 -- Verify that any access to subprogram object does not have in its
1060 -- subprogram profile access type parameters or limited parameters
1061 -- without Read and Write attributes (E.2.3(13)).
1063 Validate_RCI_Subprogram_Declaration
(N
);
1065 -- Check that if we are in preelaborated elaboration code, then we
1066 -- do not have an instance of a default initialized private, task or
1067 -- protected object declaration which would violate (RM 10.2.1(9)).
1068 -- Note that constants are never default initialized (and the test
1069 -- below also filters out deferred constants). A variable is default
1070 -- initialized if it does *not* have an initialization expression.
1072 -- Filter out cases that are not declaration of a variable from source
1074 if Nkind
(N
) /= N_Object_Declaration
1075 or else Constant_Present
(N
)
1076 or else not Comes_From_Source
(Id
)
1081 -- Exclude generic specs from the checks (this will get rechecked
1082 -- on instantiations).
1084 if Inside_A_Generic
and then No
(Enclosing_Generic_Body
(Id
)) then
1088 -- Required checks for declaration that is in a preelaborated package
1089 -- and is not within some subprogram.
1091 if In_Preelaborated_Unit
1092 and then not In_Subprogram_Or_Concurrent_Unit
1094 -- Check for default initialized variable case. Note that in
1095 -- accordance with (RM B.1(24)) imported objects are not subject to
1096 -- default initialization.
1097 -- If the initialization does not come from source and is an
1098 -- aggregate, it is a static initialization that replaces an
1099 -- implicit call, and must be treated as such.
1102 and then (Comes_From_Source
(E
) or else Nkind
(E
) /= N_Aggregate
)
1106 elsif Is_Imported
(Id
) then
1111 Ent
: Entity_Id
:= T
;
1114 -- An array whose component type is a record with nonstatic
1115 -- default expressions is a violation, so we get the array's
1118 if Is_Array_Type
(Ent
) then
1120 Comp_Type
: Entity_Id
;
1123 Comp_Type
:= Component_Type
(Ent
);
1124 while Is_Array_Type
(Comp_Type
) loop
1125 Comp_Type
:= Component_Type
(Comp_Type
);
1132 -- Object decl. that is of record type and has no default expr.
1133 -- should check if there is any non-static default expression
1134 -- in component decl. of the record type decl.
1136 if Is_Record_Type
(Ent
) then
1137 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1138 Check_Non_Static_Default_Expr
1139 (Type_Definition
(Parent
(Ent
)), N
);
1141 elsif Nkind
(Odf
) = N_Subtype_Indication
1142 and then not Is_Array_Type
(T
)
1143 and then not Is_Private_Type
(T
)
1145 Check_Non_Static_Default_Expr
(Type_Definition
1146 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1150 -- Check for invalid use of private object. Note that Ada 2005
1151 -- AI-161 modifies the rules for Ada 2005, including the use of
1152 -- the new pragma Preelaborable_Initialization.
1154 if Is_Private_Type
(Ent
)
1155 or else Depends_On_Private
(Ent
)
1157 -- Case where type has preelaborable initialization which
1158 -- means that a pragma Preelaborable_Initialization was
1159 -- given for the private type.
1161 if Has_Preelaborable_Initialization
(Ent
) then
1163 -- But for the predefined units, we will ignore this
1164 -- status unless we are in Ada 2005 mode since we want
1165 -- Ada 95 compatible behavior, in which the entities
1166 -- marked with this pragma in the predefined library are
1167 -- not treated specially.
1169 if Ada_Version
< Ada_2005
then
1171 ("private object not allowed in preelaborated unit",
1173 Error_Msg_N
("\(would be legal in Ada 2005 mode)", N
);
1176 -- Type does not have preelaborable initialization
1179 -- We allow this when compiling in GNAT mode to make life
1180 -- easier for some cases where it would otherwise be hard
1181 -- to be exactly valid Ada.
1183 if not GNAT_Mode
then
1185 ("private object not allowed in preelaborated unit",
1188 -- Add a message if it would help to provide a pragma
1189 -- Preelaborable_Initialization on the type of the
1190 -- object (which would make it legal in Ada 2005).
1192 -- If the type has no full view (generic type, or
1193 -- previous error), the warning does not apply.
1195 if Is_Private_Type
(Ent
)
1196 and then Present
(Full_View
(Ent
))
1198 Has_Preelaborable_Initialization
(Full_View
(Ent
))
1200 Error_Msg_Sloc
:= Sloc
(Ent
);
1202 if Ada_Version
>= Ada_2005
then
1204 ("\would be legal if pragma Preelaborable_" &
1205 "Initialization given for & #", N
, Ent
);
1208 ("\would be legal in Ada 2005 if pragma " &
1209 "Preelaborable_Initialization given for & #",
1216 -- Access to Task or Protected type
1218 elsif Is_Entity_Name
(Odf
)
1219 and then Present
(Etype
(Odf
))
1220 and then Is_Access_Type
(Etype
(Odf
))
1222 Ent
:= Designated_Type
(Etype
(Odf
));
1224 elsif Is_Entity_Name
(Odf
) then
1225 Ent
:= Entity
(Odf
);
1227 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1228 Ent
:= Etype
(Subtype_Mark
(Odf
));
1230 elsif Nkind
(Odf
) = N_Constrained_Array_Definition
then
1231 Ent
:= Component_Type
(T
);
1234 if Is_Task_Type
(Ent
)
1235 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1238 ("concurrent object not allowed in preelaborated unit",
1245 -- Non-static discriminants not allowed in preelaborated unit.
1246 -- Objects of a controlled type with a user-defined Initialize
1247 -- are forbidden as well.
1249 if Is_Record_Type
(Etype
(Id
)) then
1251 ET
: constant Entity_Id
:= Etype
(Id
);
1252 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1256 if Has_Discriminants
(ET
)
1257 and then Present
(EE
)
1261 if Nkind
(PEE
) = N_Full_Type_Declaration
1262 and then not Static_Discriminant_Expr
1263 (Discriminant_Specifications
(PEE
))
1266 ("non-static discriminant in preelaborated unit",
1271 if Has_Overriding_Initialize
(ET
) then
1273 ("controlled type& does not have"
1274 & " preelaborable initialization", N
, ET
);
1281 -- A pure library_item must not contain the declaration of any variable
1282 -- except within a subprogram, generic subprogram, task unit, or
1283 -- protected unit (RM 10.2.1(16)).
1285 if In_Pure_Unit
and then not In_Subprogram_Task_Protected_Unit
then
1286 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1288 -- The visible part of an RCI library unit must not contain the
1289 -- declaration of a variable (RM E.1.3(9))
1291 elsif In_RCI_Declaration
(N
) then
1292 Error_Msg_N
("visible variable not allowed in 'R'C'I unit", N
);
1294 -- The visible part of a Shared Passive library unit must not contain
1295 -- the declaration of a variable (RM E.2.2(7))
1297 elsif In_RT_Declaration
and then not In_Private_Part
(Id
) then
1299 ("visible variable not allowed in remote types unit", N
);
1302 end Validate_Object_Declaration
;
1304 ------------------------------
1305 -- Validate_RACW_Primitives --
1306 ------------------------------
1308 procedure Validate_RACW_Primitives
(T
: Entity_Id
) is
1309 Desig_Type
: Entity_Id
;
1310 Primitive_Subprograms
: Elist_Id
;
1311 Subprogram_Elmt
: Elmt_Id
;
1312 Subprogram
: Entity_Id
;
1313 Param_Spec
: Node_Id
;
1315 Param_Type
: Entity_Id
;
1318 procedure Illegal_RACW
(Msg
: String; N
: Node_Id
);
1319 -- Diagnose that T is illegal because of the given reason, associated
1320 -- with the location of node N.
1322 Illegal_RACW_Message_Issued
: Boolean := False;
1323 -- Set True once Illegal_RACW has been called
1329 procedure Illegal_RACW
(Msg
: String; N
: Node_Id
) is
1331 if not Illegal_RACW_Message_Issued
then
1333 ("illegal remote access to class-wide type&", T
);
1334 Illegal_RACW_Message_Issued
:= True;
1337 Error_Msg_Sloc
:= Sloc
(N
);
1338 Error_Msg_N
("\\" & Msg
& " in primitive#", T
);
1341 -- Start of processing for Validate_RACW_Primitives
1344 Desig_Type
:= Etype
(Designated_Type
(T
));
1346 -- No action needed for concurrent types
1348 if Is_Concurrent_Type
(Desig_Type
) then
1352 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1354 Subprogram_Elmt
:= First_Elmt
(Primitive_Subprograms
);
1355 while Subprogram_Elmt
/= No_Elmt
loop
1356 Subprogram
:= Node
(Subprogram_Elmt
);
1358 if Is_Predefined_Dispatching_Operation
(Subprogram
)
1359 or else Is_Hidden
(Subprogram
)
1361 goto Next_Subprogram
;
1364 -- Check return type
1366 if Ekind
(Subprogram
) = E_Function
then
1367 Rtyp
:= Etype
(Subprogram
);
1369 if Has_Controlling_Result
(Subprogram
) then
1372 elsif Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
1373 Illegal_RACW
("anonymous access result", Rtyp
);
1375 elsif Is_Limited_Type
(Rtyp
) then
1376 if No
(TSS
(Rtyp
, TSS_Stream_Read
))
1378 No
(TSS
(Rtyp
, TSS_Stream_Write
))
1381 ("limited return type must have Read and Write attributes",
1382 Parent
(Subprogram
));
1383 Explain_Limited_Type
(Rtyp
, Parent
(Subprogram
));
1385 -- Check that the return type supports external streaming.
1386 -- Note that the language of the standard (E.2.2(14)) does not
1387 -- explicitly mention that case, but it really does not make
1388 -- sense to return a value containing a local access type.
1390 elsif Missing_Read_Write_Attributes
(Rtyp
)
1391 and then not Error_Posted
(Rtyp
)
1393 Illegal_RACW
("return type containing non-remote access "
1394 & "must have Read and Write attributes",
1395 Parent
(Subprogram
));
1401 Param
:= First_Formal
(Subprogram
);
1402 while Present
(Param
) loop
1404 -- Now find out if this parameter is a controlling parameter
1406 Param_Spec
:= Parent
(Param
);
1407 Param_Type
:= Etype
(Param
);
1409 if Is_Controlling_Formal
(Param
) then
1411 -- It is a controlling parameter, so specific checks below
1416 elsif Ekind_In
(Param_Type
, E_Anonymous_Access_Type
,
1417 E_Anonymous_Access_Subprogram_Type
)
1419 -- From RM E.2.2(14), no anonymous access parameter other than
1420 -- controlling ones may be used (because an anonymous access
1421 -- type never supports external streaming).
1423 Illegal_RACW
("non-controlling access parameter", Param_Spec
);
1425 elsif Is_Limited_Type
(Param_Type
) then
1427 -- Not a controlling parameter, so type must have Read and
1428 -- Write attributes.
1430 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1432 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1435 ("limited formal must have Read and Write attributes",
1437 Explain_Limited_Type
(Param_Type
, Param_Spec
);
1440 elsif Missing_Read_Write_Attributes
(Param_Type
)
1441 and then not Error_Posted
(Param_Type
)
1443 Illegal_RACW
("parameter containing non-remote access "
1444 & "must have Read and Write attributes", Param_Spec
);
1447 -- Check next parameter in this subprogram
1449 Next_Formal
(Param
);
1453 Next_Elmt
(Subprogram_Elmt
);
1455 end Validate_RACW_Primitives
;
1457 -------------------------------
1458 -- Validate_RCI_Declarations --
1459 -------------------------------
1461 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1465 E
:= First_Entity
(P
);
1466 while Present
(E
) loop
1467 if Comes_From_Source
(E
) then
1468 if Is_Limited_Type
(E
) then
1470 ("limited type not allowed in rci unit", Parent
(E
));
1471 Explain_Limited_Type
(E
, Parent
(E
));
1473 elsif Ekind_In
(E
, E_Generic_Function
,
1475 E_Generic_Procedure
)
1477 Error_Msg_N
("generic declaration not allowed in rci unit",
1480 elsif (Ekind
(E
) = E_Function
1481 or else Ekind
(E
) = E_Procedure
)
1482 and then Has_Pragma_Inline
(E
)
1485 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1487 -- Inner packages that are renamings need not be checked. Generic
1488 -- RCI packages are subject to the checks, but entities that come
1489 -- from formal packages are not part of the visible declarations
1490 -- of the package and are not checked.
1492 elsif Ekind
(E
) = E_Package
then
1493 if Present
(Renamed_Entity
(E
)) then
1496 elsif Ekind
(P
) /= E_Generic_Package
1497 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1498 Generic_Formal_Declarations
1499 (Unit_Declaration_Node
(P
))
1501 Validate_RCI_Declarations
(E
);
1508 end Validate_RCI_Declarations
;
1510 -----------------------------------------
1511 -- Validate_RCI_Subprogram_Declaration --
1512 -----------------------------------------
1514 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1515 K
: constant Node_Kind
:= Nkind
(N
);
1518 Param_Spec
: Node_Id
;
1519 Param_Type
: Entity_Id
;
1520 Base_Param_Type
: Entity_Id
;
1521 Base_Under_Type
: Entity_Id
;
1522 Type_Decl
: Node_Id
;
1523 Error_Node
: Node_Id
:= N
;
1526 -- This procedure enforces rules on subprogram and access to subprogram
1527 -- declarations in RCI units. These rules do not apply to expander
1528 -- generated routines, which are not remote subprograms. It is called:
1530 -- 1. from Analyze_Subprogram_Declaration.
1531 -- 2. from Validate_Object_Declaration (access to subprogram).
1533 if not (Comes_From_Source
(N
) and then In_RCI_Declaration
(N
)) then
1537 if K
= N_Subprogram_Declaration
then
1538 Profile
:= Parameter_Specifications
(Specification
(N
));
1540 else pragma Assert
(K
= N_Object_Declaration
);
1542 -- The above assertion is dubious, the visible declarations of an
1543 -- RCI unit never contain an object declaration, this should be an
1544 -- ACCESS-to-object declaration???
1546 Id
:= Defining_Identifier
(N
);
1548 if Nkind
(Id
) = N_Defining_Identifier
1549 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1550 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1553 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1559 -- Iterate through the parameter specification list, checking that
1560 -- no access parameter and no limited type parameter in the list.
1563 if Present
(Profile
) then
1564 Param_Spec
:= First
(Profile
);
1565 while Present
(Param_Spec
) loop
1566 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1567 Type_Decl
:= Parent
(Param_Type
);
1569 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1570 if K
= N_Subprogram_Declaration
then
1571 Error_Node
:= Param_Spec
;
1574 -- Report error only if declaration is in source program
1576 if Comes_From_Source
1577 (Defining_Entity
(Specification
(N
)))
1580 ("subprogram in 'R'C'I unit cannot have access parameter",
1584 -- For a limited private type parameter, we check only the private
1585 -- declaration and ignore full type declaration, unless this is
1586 -- the only declaration for the type, e.g., as a limited record.
1588 elsif Is_Limited_Type
(Param_Type
)
1589 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1591 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1592 and then not (Has_Private_Declaration
(Param_Type
))
1593 and then Comes_From_Source
(N
)))
1595 -- A limited parameter is legal only if user-specified Read and
1596 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1598 if No
(Full_View
(Param_Type
))
1599 and then Ekind
(Param_Type
) /= E_Record_Type
1601 -- Type does not have completion yet, so if declared in
1602 -- the current RCI scope it is illegal, and will be flagged
1608 -- In Ada 95 the rules permit using a limited type that has
1609 -- user-specified Read and Write attributes that are specified
1610 -- in the private part of the package, whereas Ada 2005
1611 -- (AI-240) revises this to require the attributes to be
1612 -- "available" (implying that the attribute clauses must be
1613 -- visible to the RCI client). The Ada 95 rules violate the
1614 -- contract model for privacy, but we support both semantics
1615 -- for now for compatibility (note that ACATS test BXE2009
1616 -- checks a case that conforms to the Ada 95 rules but is
1617 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1618 -- possibilities of visible TSS stream subprograms or explicit
1619 -- stream attribute definitions because the TSS subprograms
1620 -- can be hidden in the private part while the attribute
1621 -- definitions are still be available from the visible part.
1623 Base_Param_Type
:= Base_Type
(Param_Type
);
1624 Base_Under_Type
:= Base_Type
(Underlying_Type
1627 if (Ada_Version
< Ada_2005
1629 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1631 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1633 (No
(TSS
(Base_Under_Type
, TSS_Stream_Read
))
1635 No
(TSS
(Base_Under_Type
, TSS_Stream_Write
))))
1637 (Ada_Version
>= Ada_2005
1639 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1641 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1643 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1645 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1647 (not Has_Stream_Attribute_Definition
1648 (Base_Param_Type
, TSS_Stream_Read
)
1650 not Has_Stream_Attribute_Definition
1651 (Base_Param_Type
, TSS_Stream_Write
)))
1653 if K
= N_Subprogram_Declaration
then
1654 Error_Node
:= Param_Spec
;
1657 if Ada_Version
>= Ada_2005
then
1659 ("limited parameter in 'R'C'I unit "
1660 & "must have visible read/write attributes ",
1664 ("limited parameter in 'R'C'I unit "
1665 & "must have read/write attributes ",
1668 Explain_Limited_Type
(Param_Type
, Error_Node
);
1671 -- In Ada 95, any non-remote access type (or any type with a
1672 -- component of a non-remote access type) that is visible in an
1673 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1674 -- unit, and thus is already guaranteed to support external
1675 -- streaming. However in Ada 2005 we have to account for the case
1676 -- of named access types from declared pure units as well, which
1677 -- may or may not support external streaming, and so we need to
1678 -- perform a specific check for E.2.3(14/2) here.
1680 -- Note that if the declaration of the type itself is illegal, we
1681 -- do not perform this check since it might be a cascaded error.
1684 if K
= N_Subprogram_Declaration
then
1685 Error_Node
:= Param_Spec
;
1688 if Missing_Read_Write_Attributes
(Param_Type
)
1689 and then not Error_Posted
(Param_Type
)
1692 ("parameter containing non-remote access in 'R'C'I "
1693 & "subprogram must have visible "
1694 & "Read and Write attributes", Error_Node
);
1700 -- No check on return type???
1702 end Validate_RCI_Subprogram_Declaration
;
1704 ----------------------------------------------------
1705 -- Validate_Remote_Access_Object_Type_Declaration --
1706 ----------------------------------------------------
1708 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1710 function Is_Valid_Remote_Object_Type
(E
: Entity_Id
) return Boolean;
1711 -- True if tagged type E is a valid candidate as the root type of the
1712 -- designated type for a RACW, i.e. a tagged limited private type, or a
1713 -- limited interface type, or a private extension of such a type.
1715 ---------------------------------
1716 -- Is_Valid_Remote_Object_Type --
1717 ---------------------------------
1719 function Is_Valid_Remote_Object_Type
(E
: Entity_Id
) return Boolean is
1720 P
: constant Node_Id
:= Parent
(E
);
1723 pragma Assert
(Is_Tagged_Type
(E
));
1725 -- Simple case: a limited private type
1727 if Nkind
(P
) = N_Private_Type_Declaration
1728 and then Is_Limited_Record
(E
)
1732 -- A limited interface is not currently a legal ancestor for the
1733 -- designated type of an RACW type, because a type that implements
1734 -- such an interface need not be limited. However, the ARG seems to
1735 -- incline towards allowing an access to classwide limited interface
1736 -- type as a remote access type, as resolved in AI05-060. But note
1737 -- that the expansion circuitry for RACWs that designate classwide
1738 -- interfaces is not complete yet.
1740 elsif Is_Limited_Record
(E
) and then Is_Limited_Interface
(E
) then
1743 -- A generic tagged limited type is a valid candidate. Limitedness
1744 -- will be checked again on the actual at instantiation point.
1746 elsif Nkind
(P
) = N_Formal_Type_Declaration
1747 and then Ekind
(E
) = E_Record_Type_With_Private
1748 and then Is_Generic_Type
(E
)
1749 and then Is_Limited_Record
(E
)
1753 -- A private extension declaration is a valid candidate if its parent
1756 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
1757 return Is_Valid_Remote_Object_Type
(Etype
(E
));
1762 end Is_Valid_Remote_Object_Type
;
1766 Direct_Designated_Type
: Entity_Id
;
1767 Desig_Type
: Entity_Id
;
1769 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1772 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1773 -- the given node is N_Access_To_Object_Definition.
1775 if not Comes_From_Source
(T
)
1776 or else (not In_RCI_Declaration
(Parent
(T
))
1777 and then not In_RT_Declaration
)
1782 -- An access definition in the private part of a Remote Types package
1783 -- may be legal if it has user-defined Read and Write attributes. This
1784 -- will be checked at the end of the package spec processing.
1786 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1790 -- Check RCI or RT unit type declaration. It may not contain the
1791 -- declaration of an access-to-object type unless it is a general access
1792 -- type that designates a class-wide limited private type or subtype.
1793 -- There are also constraints on the primitive subprograms of the
1794 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1796 if Ekind
(T
) /= E_General_Access_Type
1797 or else not Is_Class_Wide_Type
(Designated_Type
(T
))
1799 if In_RCI_Declaration
(Parent
(T
)) then
1801 ("error in access type in Remote_Call_Interface unit", T
);
1804 ("error in access type in Remote_Types unit", T
);
1807 Error_Msg_N
("\must be general access to class-wide type", T
);
1811 Direct_Designated_Type
:= Designated_Type
(T
);
1812 Desig_Type
:= Etype
(Direct_Designated_Type
);
1814 -- Why is the check below not in
1815 -- Validate_Remote_Access_To_Class_Wide_Type???
1817 if not Is_Valid_Remote_Object_Type
(Desig_Type
) then
1819 ("error in designated type of remote access to class-wide type", T
);
1821 ("\must be tagged limited private or private extension", T
);
1824 end Validate_Remote_Access_Object_Type_Declaration
;
1826 -----------------------------------------------
1827 -- Validate_Remote_Access_To_Class_Wide_Type --
1828 -----------------------------------------------
1830 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1831 K
: constant Node_Kind
:= Nkind
(N
);
1832 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1836 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1837 -- of class-wide limited private types.
1839 -- Storage_Pool and Storage_Size are not defined for such types
1841 -- The expected type of allocator must not be such a type.
1843 -- The actual parameter of generic instantiation must not be such a
1844 -- type if the formal parameter is of an access type.
1846 -- On entry, there are five cases
1848 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1849 -- either Storage_Pool or Storage_Size.
1851 -- 2. called from exp_ch4 Expand_N_Allocator
1853 -- 3. called from sem_ch12 Analyze_Associations
1855 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1857 -- 5. called from sem_res Resolve_Actuals
1859 if K
= N_Attribute_Reference
then
1860 E
:= Etype
(Prefix
(N
));
1862 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1863 Error_Msg_N
("incorrect attribute of remote operand", N
);
1867 elsif K
= N_Allocator
then
1870 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1871 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1875 elsif K
in N_Has_Entity
then
1878 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1879 Error_Msg_N
("incorrect remote type generic actual", N
);
1883 -- This subprogram also enforces the checks in E.2.2(13). A value of
1884 -- such type must not be dereferenced unless as controlling operand of
1885 -- a dispatching call. Explicit dereferences not coming from source are
1886 -- exempted from this checking because the expander produces them in
1887 -- some cases (such as for tag checks on dispatching calls with multiple
1888 -- controlling operands). However we do check in the case of an implicit
1889 -- dereference that is expanded to an explicit dereference (hence the
1890 -- test of whether Original_Node (N) comes from source).
1892 elsif K
= N_Explicit_Dereference
1893 and then Comes_From_Source
(Original_Node
(N
))
1895 E
:= Etype
(Prefix
(N
));
1897 -- If the class-wide type is not a remote one, the restrictions
1900 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1904 -- If we have a true dereference that comes from source and that
1905 -- is a controlling argument for a dispatching call, accept it.
1907 if Is_Actual_Parameter
(N
)
1908 and then Is_Controlling_Actual
(N
)
1913 -- If we are just within a procedure or function call and the
1914 -- dereference has not been analyzed, return because this procedure
1915 -- will be called again from sem_res Resolve_Actuals. The same can
1916 -- apply in the case of dereference that is the prefix of a selected
1917 -- component, which can be a call given in prefixed form.
1919 if (Is_Actual_Parameter
(N
)
1920 or else PK
= N_Selected_Component
)
1921 and then not Analyzed
(N
)
1926 -- We must allow expanded code to generate a reference to the tag of
1927 -- the designated object (may be either the actual tag, or the stub
1928 -- tag in the case of a remote object).
1930 if PK
= N_Selected_Component
1931 and then Is_Tag
(Entity
(Selector_Name
(Parent
(N
))))
1937 ("invalid dereference of a remote access-to-class-wide value", N
);
1939 end Validate_Remote_Access_To_Class_Wide_Type
;
1941 ------------------------------------------
1942 -- Validate_Remote_Type_Type_Conversion --
1943 ------------------------------------------
1945 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1946 S
: constant Entity_Id
:= Etype
(N
);
1947 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1950 -- This test is required in the case where a conversion appears inside a
1951 -- normal package, it does not necessarily have to be inside an RCI,
1952 -- Remote_Types unit (RM E.2.2(9,12)).
1954 if Is_Remote_Access_To_Subprogram_Type
(E
)
1955 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1958 ("incorrect conversion of remote operand to local type", N
);
1961 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1962 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1965 ("incorrect conversion of local operand to remote type", N
);
1968 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1969 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1972 ("incorrect conversion of remote operand to local type", N
);
1976 -- If a local access type is converted into a RACW type, then the
1977 -- current unit has a pointer that may now be exported to another
1980 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1981 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1983 Set_Has_RACW
(Current_Sem_Unit
);
1985 end Validate_Remote_Type_Type_Conversion
;
1987 -------------------------------
1988 -- Validate_RT_RAT_Component --
1989 -------------------------------
1991 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1992 Spec
: constant Node_Id
:= Specification
(N
);
1993 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1996 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1999 if not Is_Remote_Types
(Name_U
) then
2003 Typ
:= First_Entity
(Name_U
);
2004 while Present
(Typ
) and then Typ
/= First_Priv_Ent
loop
2005 U_Typ
:= Underlying_Type
(Typ
);
2011 if Comes_From_Source
(Typ
) and then Is_Type
(Typ
) then
2012 if Missing_Read_Write_Attributes
(Typ
) then
2013 if Is_Non_Remote_Access_Type
(Typ
) then
2014 Error_Msg_N
("error in non-remote access type", U_Typ
);
2017 ("error in record type containing a component of a " &
2018 "non-remote access type", U_Typ
);
2021 if Ada_Version
>= Ada_2005
then
2023 ("\must have visible Read and Write attribute " &
2024 "definition clauses (RM E.2.2(8))", U_Typ
);
2027 ("\must have Read and Write attribute " &
2028 "definition clauses (RM E.2.2(8))", U_Typ
);
2035 end Validate_RT_RAT_Component
;
2037 -----------------------------------------
2038 -- Validate_SP_Access_Object_Type_Decl --
2039 -----------------------------------------
2041 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
2042 Direct_Designated_Type
: Entity_Id
;
2044 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
2045 -- Return true if the protected type designated by T has
2046 -- entry declarations.
2048 ----------------------------
2049 -- Has_Entry_Declarations --
2050 ----------------------------
2052 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
2056 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
2057 Ety
:= First_Entity
(E
);
2058 while Present
(Ety
) loop
2059 if Ekind
(Ety
) = E_Entry
then
2068 end Has_Entry_Declarations
;
2070 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2073 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2074 -- Nkind of the given entity is N_Access_To_Object_Definition.
2076 if not Comes_From_Source
(T
)
2077 or else not In_Shared_Passive_Unit
2078 or else In_Subprogram_Task_Protected_Unit
2083 -- Check Shared Passive unit. It should not contain the declaration
2084 -- of an access-to-object type whose designated type is a class-wide
2085 -- type, task type or protected type with entry (RM E.2.1(7)).
2087 Direct_Designated_Type
:= Designated_Type
(T
);
2089 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
2091 ("invalid access-to-class-wide type in shared passive unit", T
);
2094 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
2096 ("invalid access-to-task type in shared passive unit", T
);
2099 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
2100 and then Has_Entry_Declarations
(Direct_Designated_Type
)
2103 ("invalid access-to-protected type in shared passive unit", T
);
2106 end Validate_SP_Access_Object_Type_Decl
;
2108 ---------------------------------
2109 -- Validate_Static_Object_Name --
2110 ---------------------------------
2112 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
2115 function Is_Primary
(N
: Node_Id
) return Boolean;
2116 -- Determine whether node is syntactically a primary in an expression
2117 -- This function should probably be somewhere else ???
2118 -- Also it does not do what it says, e.g if N is a binary operator
2119 -- whose parent is a binary operator, Is_Primary returns True ???
2125 function Is_Primary
(N
: Node_Id
) return Boolean is
2126 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
2130 when N_Op | N_Membership_Test
=>
2134 | N_Component_Association
2135 | N_Index_Or_Discriminant_Constraint
=>
2138 when N_Attribute_Reference
=>
2139 return Attribute_Name
(Parent
(N
)) /= Name_Address
2140 and then Attribute_Name
(Parent
(N
)) /= Name_Access
2141 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
2143 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
2145 when N_Indexed_Component
=>
2146 return (N
/= Prefix
(Parent
(N
))
2147 or else Is_Primary
(Parent
(N
)));
2149 when N_Qualified_Expression | N_Type_Conversion
=>
2150 return Is_Primary
(Parent
(N
));
2152 when N_Assignment_Statement | N_Object_Declaration
=>
2153 return (N
= Expression
(Parent
(N
)));
2155 when N_Selected_Component
=>
2156 return Is_Primary
(Parent
(N
));
2163 -- Start of processing for Validate_Static_Object_Name
2166 if not In_Preelaborated_Unit
2167 or else not Comes_From_Source
(N
)
2168 or else In_Subprogram_Or_Concurrent_Unit
2169 or else Ekind
(Current_Scope
) = E_Block
2173 -- Filter out cases where primary is default in a component declaration,
2174 -- discriminant specification, or actual in a record type initialization
2177 -- Initialization call of internal types
2179 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
2181 if Present
(Parent
(Parent
(N
)))
2182 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
2187 if Nkind
(Name
(Parent
(N
))) = N_Identifier
2188 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
2194 -- Error if the name is a primary in an expression. The parent must not
2195 -- be an operator, or a selected component or an indexed component that
2196 -- is itself a primary. Entities that are actuals do not need to be
2197 -- checked, because the call itself will be diagnosed.
2200 and then (not Inside_A_Generic
2201 or else Present
(Enclosing_Generic_Body
(N
)))
2203 if Ekind
(Entity
(N
)) = E_Variable
2204 or else Ekind
(Entity
(N
)) in Formal_Object_Kind
2206 Flag_Non_Static_Expr
2207 ("non-static object name in preelaborated unit", N
);
2209 -- Give an error for a reference to a nonstatic constant, unless the
2210 -- constant is in another GNAT library unit that is preelaborable.
2212 elsif Ekind
(Entity
(N
)) = E_Constant
2213 and then not Is_Static_Expression
(N
)
2217 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
2219 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
2220 and then (Is_Preelaborated
(Scope
(E
))
2221 or else Is_Pure
(Scope
(E
))
2222 or else (Present
(Renamed_Object
(E
))
2224 Is_Entity_Name
(Renamed_Object
(E
))
2227 (Scope
(Renamed_Object
(E
)))
2230 (Renamed_Object
(E
))))))
2234 -- This is the error case
2237 -- In GNAT mode, this is just a warning, to allow it to be
2238 -- judiciously turned off. Otherwise it is a real error.
2242 ("?non-static constant in preelaborated unit", N
);
2244 Flag_Non_Static_Expr
2245 ("non-static constant in preelaborated unit", N
);
2250 end Validate_Static_Object_Name
;