1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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_Attr
; use Sem_Attr
;
39 with Sem_Aux
; use Sem_Aux
;
40 with Sem_Dist
; use Sem_Dist
;
41 with Sem_Eval
; use Sem_Eval
;
42 with Sem_Util
; use Sem_Util
;
43 with Sinfo
; use Sinfo
;
44 with Snames
; use Snames
;
45 with Stand
; use Stand
;
47 package body Sem_Cat
is
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 procedure Check_Categorization_Dependencies
54 (Unit_Entity
: Entity_Id
;
55 Depended_Entity
: Entity_Id
;
57 Is_Subunit
: Boolean);
58 -- This procedure checks that the categorization of a lib unit and that
59 -- of the depended unit satisfy dependency restrictions.
60 -- The depended_entity can be the entity in a with_clause item, in which
61 -- case Info_Node denotes that item. The depended_entity can also be the
62 -- parent unit of a child unit, in which case Info_Node is the declaration
63 -- of the child unit. The error message is posted on Info_Node, and is
64 -- specialized if Is_Subunit is true.
66 procedure Check_Non_Static_Default_Expr
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a nonstatic default value.
71 -- If a nonstatic default exists, report an error on Obj_Decl.
73 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
74 -- Return True if entity has attribute definition clauses for Read and
75 -- Write attributes that are visible at some place.
77 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
78 -- Returns true if the entity is a type whose full view is a non-remote
79 -- access type, for the purpose of enforcing E.2.2(8) rules.
81 function Has_Non_Remote_Access
(Typ
: Entity_Id
) return Boolean;
82 -- Return true if Typ or the type of any of its subcomponents is a non
83 -- remote access type and doesn't have user-defined stream attributes.
85 function No_External_Streaming
(E
: Entity_Id
) return Boolean;
86 -- Return True if the entity or one of its subcomponents does not support
87 -- external streaming.
89 function In_RCI_Declaration
(N
: Node_Id
) return Boolean;
90 -- Determines if a declaration is within the visible part of a Remote
91 -- Call Interface compilation unit, for semantic checking purposes only
92 -- (returns false within an instance and within the package body).
94 function In_RT_Declaration
return Boolean;
95 -- Determines if current scope is within the declaration of a Remote Types
96 -- unit, for semantic checking purposes.
98 function In_Shared_Passive_Unit
return Boolean;
99 -- Determines if current scope is within a Shared Passive compilation unit
101 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
102 -- Iterate through the list of discriminants to check if any of them
103 -- contains non-static default expression, which is a violation in
104 -- a preelaborated library unit.
106 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
107 -- Check validity of declaration if RCI or RT unit. It should not contain
108 -- the declaration of an access-to-object type unless it is a general
109 -- access type that designates a class-wide limited private type. There are
110 -- also constraints about the primitive subprograms of the class-wide type.
111 -- RM E.2 (9, 13, 14)
113 procedure Validate_RACW_Primitive
116 -- Check legality of the declaration of primitive Subp of the designated
117 -- type of the given RACW type.
119 ---------------------------------------
120 -- Check_Categorization_Dependencies --
121 ---------------------------------------
123 procedure Check_Categorization_Dependencies
124 (Unit_Entity
: Entity_Id
;
125 Depended_Entity
: Entity_Id
;
127 Is_Subunit
: Boolean)
129 N
: constant Node_Id
:= Info_Node
;
132 -- Here we define an enumeration type to represent categorization types,
133 -- ordered so that a unit with a given categorization can only WITH
134 -- units with lower or equal categorization type.
136 type Categorization
is
140 Remote_Call_Interface
,
143 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
144 -- Check categorization flags from entity, and return in the form
145 -- of the lowest value of the Categorization type that applies to E.
147 ------------------------
148 -- Get_Categorization --
149 ------------------------
151 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
153 -- Get the lowest categorization that corresponds to E. Note that
154 -- nothing prevents several (different) categorization pragmas
155 -- to apply to the same library unit, in which case the unit has
156 -- all associated categories, so we need to be careful here to
157 -- check pragmas in proper Categorization order in order to
158 -- return the lowest applicable value.
160 -- Ignore Pure specification if set by pragma Pure_Function
164 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
168 elsif Is_Shared_Passive
(E
) then
169 return Shared_Passive
;
171 elsif Is_Remote_Types
(E
) then
174 elsif Is_Remote_Call_Interface
(E
) then
175 return Remote_Call_Interface
;
180 end Get_Categorization
;
182 Unit_Category
: Categorization
;
183 With_Category
: Categorization
;
185 -- Start of processing for Check_Categorization_Dependencies
188 -- Intrinsic subprograms are preelaborated, so do not impose any
189 -- categorization dependencies.
191 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
195 -- First check 10.2.1 (11/1) rules on preelaborate packages
197 if Is_Preelaborated
(Unit_Entity
)
198 and then not Is_Preelaborated
(Depended_Entity
)
199 and then not Is_Pure
(Depended_Entity
)
206 -- Check categorization rules of RM E.2(5)
208 Unit_Category
:= Get_Categorization
(Unit_Entity
);
209 With_Category
:= Get_Categorization
(Depended_Entity
);
211 if With_Category
> Unit_Category
then
213 -- Special case: Remote_Types and Remote_Call_Interface are allowed
214 -- to WITH anything in the package body, per (RM E.2(5)).
216 if (Unit_Category
= Remote_Types
217 or else Unit_Category
= Remote_Call_Interface
)
218 and then In_Package_Body
(Unit_Entity
)
222 -- Special case: Remote_Types and Remote_Call_Interface declarations
223 -- can depend on a preelaborated unit via a private with_clause, per
226 elsif (Unit_Category
= Remote_Types
228 Unit_Category
= Remote_Call_Interface
)
229 and then Nkind
(N
) = N_With_Clause
230 and then Private_Present
(N
)
231 and then Is_Preelaborated
(Depended_Entity
)
235 -- All other cases, we do have an error
242 -- Here if we have an error
246 -- These messages are warnings in GNAT mode or if the -gnateP switch
247 -- was set. Otherwise these are real errors for real illegalities.
249 -- The reason we suppress these errors in GNAT mode is that the run-
250 -- time has several instances of violations of the categorization
251 -- errors (e.g. Pure units withing Preelaborate units. All these
252 -- violations are harmless in the cases where we intend them, and
253 -- we suppress the warnings with Warnings (Off). In cases where we
254 -- do not intend the violation, warnings are errors in GNAT mode
255 -- anyway, so we will still get an error.
258 Treat_Categorization_Errors_As_Warnings
or GNAT_Mode
;
260 -- Don't give error if main unit is not an internal unit, and the
261 -- unit generating the message is an internal unit. This is the
262 -- situation in which such messages would be ignored in any case,
263 -- so it is convenient not to generate them (since it causes
264 -- annoying interference with debugging).
266 if Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
267 and then not Is_Internal_File_Name
(Unit_File_Name
(Main_Unit
))
271 -- Dependence of Remote_Types or Remote_Call_Interface declaration
272 -- on a preelaborated unit with a normal with_clause.
274 elsif (Unit_Category
= Remote_Types
276 Unit_Category
= Remote_Call_Interface
)
277 and then Is_Preelaborated
(Depended_Entity
)
280 ("<<must use private with clause for preelaborated unit& ",
285 elsif Is_Subunit
then
287 ("<subunit cannot depend on& " &
288 "(parent has wrong categorization)", N
, Depended_Entity
);
290 -- Normal unit, not subunit
294 ("<<cannot depend on& " &
295 "(wrong categorization)", N
, Depended_Entity
);
298 -- Add further explanation for Pure/Preelaborate common cases
300 if Unit_Category
= Pure
then
302 ("\<<pure unit cannot depend on non-pure unit",
305 elsif Is_Preelaborated
(Unit_Entity
)
306 and then not Is_Preelaborated
(Depended_Entity
)
307 and then not Is_Pure
(Depended_Entity
)
310 ("\<<preelaborated unit cannot depend on "
311 & "non-preelaborated unit",
315 end Check_Categorization_Dependencies
;
317 -----------------------------------
318 -- Check_Non_Static_Default_Expr --
319 -----------------------------------
321 procedure Check_Non_Static_Default_Expr
326 Component_Decl
: Node_Id
;
329 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
330 Recdef
:= Record_Extension_Part
(Type_Def
);
340 -- Check that component declarations do not involve:
342 -- a. a non-static default expression, where the object is
343 -- declared to be default initialized.
345 -- b. a dynamic Itype (discriminants and constraints)
347 if Null_Present
(Recdef
) then
350 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
353 while Present
(Component_Decl
)
354 and then Nkind
(Component_Decl
) = N_Component_Declaration
356 if Present
(Expression
(Component_Decl
))
357 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
358 and then not Is_OK_Static_Expression
(Expression
(Component_Decl
))
360 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
362 ("object in preelaborated unit has non-static default#",
365 -- Fix this later ???
367 -- elsif Has_Dynamic_Itype (Component_Decl) then
369 -- ("dynamic type discriminant," &
370 -- " constraint in preelaborated unit",
374 Next
(Component_Decl
);
376 end Check_Non_Static_Default_Expr
;
378 ---------------------------
379 -- Has_Non_Remote_Access --
380 ---------------------------
382 function Has_Non_Remote_Access
(Typ
: Entity_Id
) return Boolean is
383 Component
: Entity_Id
;
384 Comp_Type
: Entity_Id
;
385 U_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
391 elsif Has_Read_Write_Attributes
(Typ
)
392 or else Has_Read_Write_Attributes
(U_Typ
)
396 elsif Is_Non_Remote_Access_Type
(U_Typ
) then
400 if Is_Record_Type
(U_Typ
) then
401 Component
:= First_Entity
(U_Typ
);
402 while Present
(Component
) loop
403 if not Is_Tag
(Component
) then
404 Comp_Type
:= Etype
(Component
);
406 if Has_Non_Remote_Access
(Comp_Type
) then
411 Next_Entity
(Component
);
414 elsif Is_Array_Type
(U_Typ
) then
415 return Has_Non_Remote_Access
(Component_Type
(U_Typ
));
420 end Has_Non_Remote_Access
;
422 -------------------------------
423 -- Has_Read_Write_Attributes --
424 -------------------------------
426 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
429 and then Has_Stream_Attribute_Definition
430 (E
, TSS_Stream_Read
, At_Any_Place
=> True)
431 and then Has_Stream_Attribute_Definition
432 (E
, TSS_Stream_Write
, At_Any_Place
=> True);
433 end Has_Read_Write_Attributes
;
435 -------------------------------------
436 -- Has_Stream_Attribute_Definition --
437 -------------------------------------
439 function Has_Stream_Attribute_Definition
442 At_Any_Place
: Boolean := False) return Boolean
445 Full_Type
: Entity_Id
:= Typ
;
448 -- In the case of a type derived from a private view, any specified
449 -- stream attributes will be attached to the derived type's underlying
450 -- type rather the derived type entity itself (which is itself private).
452 if Is_Private_Type
(Typ
)
453 and then Is_Derived_Type
(Typ
)
454 and then Present
(Full_View
(Typ
))
456 Full_Type
:= Underlying_Type
(Typ
);
459 -- We start from the declaration node and then loop until the end of
460 -- the list until we find the requested attribute definition clause.
461 -- In Ada 2005 mode, clauses are ignored if they are not currently
462 -- visible (this is tested using the corresponding Entity, which is
463 -- inserted by the expander at the point where the clause occurs),
464 -- unless At_Any_Place is true.
466 Rep_Item
:= First_Rep_Item
(Full_Type
);
467 while Present
(Rep_Item
) loop
468 if Nkind
(Rep_Item
) = N_Attribute_Definition_Clause
then
469 case Chars
(Rep_Item
) is
471 exit when Nam
= TSS_Stream_Read
;
474 exit when Nam
= TSS_Stream_Write
;
477 exit when Nam
= TSS_Stream_Input
;
480 exit when Nam
= TSS_Stream_Output
;
488 Next_Rep_Item
(Rep_Item
);
491 -- If At_Any_Place is true, return True if the attribute is available
492 -- at any place; if it is false, return True only if the attribute is
493 -- currently visible.
495 return Present
(Rep_Item
)
496 and then (Ada_Version
< Ada_2005
498 or else not Is_Hidden
(Entity
(Rep_Item
)));
499 end Has_Stream_Attribute_Definition
;
501 ---------------------------
502 -- In_Preelaborated_Unit --
503 ---------------------------
505 function In_Preelaborated_Unit
return Boolean is
506 Unit_Entity
: Entity_Id
:= Current_Scope
;
507 Unit_Kind
: constant Node_Kind
:=
508 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
511 -- If evaluating actuals for a child unit instantiation, then ignore
512 -- the preelaboration status of the parent; use the child instead.
514 if Is_Compilation_Unit
(Unit_Entity
)
515 and then Unit_Kind
in N_Generic_Instantiation
516 and then not In_Same_Source_Unit
(Unit_Entity
,
517 Cunit
(Current_Sem_Unit
))
519 Unit_Entity
:= Cunit_Entity
(Current_Sem_Unit
);
522 -- There are no constraints on the body of Remote_Call_Interface or
523 -- Remote_Types packages.
525 return (Unit_Entity
/= Standard_Standard
)
526 and then (Is_Preelaborated
(Unit_Entity
)
527 or else Is_Pure
(Unit_Entity
)
528 or else Is_Shared_Passive
(Unit_Entity
)
530 ((Is_Remote_Types
(Unit_Entity
)
531 or else Is_Remote_Call_Interface
(Unit_Entity
))
532 and then Ekind
(Unit_Entity
) = E_Package
533 and then Unit_Kind
/= N_Package_Body
534 and then not In_Package_Body
(Unit_Entity
)
535 and then not In_Instance
));
536 end In_Preelaborated_Unit
;
542 function In_Pure_Unit
return Boolean is
544 return Is_Pure
(Current_Scope
);
547 ------------------------
548 -- In_RCI_Declaration --
549 ------------------------
551 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
552 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
553 Unit_Kind
: constant Node_Kind
:=
554 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
557 -- There are no restrictions on the private part or body
560 return Is_Remote_Call_Interface
(Unit_Entity
)
561 and then Is_Package_Or_Generic_Package
(Unit_Entity
)
562 and then Unit_Kind
/= N_Package_Body
563 and then List_Containing
(N
) =
564 Visible_Declarations
(Package_Specification
(Unit_Entity
))
565 and then not In_Package_Body
(Unit_Entity
)
566 and then not In_Instance
;
568 -- What about the case of a nested package in the visible part???
569 -- This case is missed by the List_Containing check above???
570 end In_RCI_Declaration
;
572 -----------------------
573 -- In_RT_Declaration --
574 -----------------------
576 function In_RT_Declaration
return Boolean is
577 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
578 Unit_Kind
: constant Node_Kind
:=
579 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
582 -- There are no restrictions on the body of a Remote Types unit
584 return Is_Remote_Types
(Unit_Entity
)
585 and then Is_Package_Or_Generic_Package
(Unit_Entity
)
586 and then Unit_Kind
/= N_Package_Body
587 and then not In_Package_Body
(Unit_Entity
)
588 and then not In_Instance
;
589 end In_RT_Declaration
;
591 ----------------------------
592 -- In_Shared_Passive_Unit --
593 ----------------------------
595 function In_Shared_Passive_Unit
return Boolean is
596 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
599 return Is_Shared_Passive
(Unit_Entity
);
600 end In_Shared_Passive_Unit
;
602 ---------------------------------------
603 -- In_Subprogram_Task_Protected_Unit --
604 ---------------------------------------
606 function In_Subprogram_Task_Protected_Unit
return Boolean is
610 -- The following is to verify that a declaration is inside
611 -- subprogram, generic subprogram, task unit, protected unit.
612 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
614 -- Use scope chain to check successively outer scopes
618 if Is_Subprogram_Or_Generic_Subprogram
(E
)
620 Is_Concurrent_Type
(E
)
624 elsif E
= Standard_Standard
then
630 end In_Subprogram_Task_Protected_Unit
;
632 -------------------------------
633 -- Is_Non_Remote_Access_Type --
634 -------------------------------
636 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
637 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
641 -- This case arises for the case of a generic formal type, in which
642 -- case E.2.2(8) rules will be enforced at instantiation time.
647 return Is_Access_Type
(U_E
)
648 and then not Is_Remote_Access_To_Class_Wide_Type
(U_E
)
649 and then not Is_Remote_Access_To_Subprogram_Type
(U_E
);
650 end Is_Non_Remote_Access_Type
;
652 ---------------------------
653 -- No_External_Streaming --
654 ---------------------------
656 function No_External_Streaming
(E
: Entity_Id
) return Boolean is
657 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
663 elsif Has_Read_Write_Attributes
(E
) then
665 -- Note: availability of stream attributes is tested on E, not U_E.
666 -- There may be stream attributes defined on U_E that are not visible
667 -- at the place where support of external streaming is tested.
671 elsif Has_Non_Remote_Access
(U_E
) then
675 return Is_Limited_Type
(E
);
676 end No_External_Streaming
;
678 -------------------------------------
679 -- Set_Categorization_From_Pragmas --
680 -------------------------------------
682 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
683 P
: constant Node_Id
:= Parent
(N
);
684 S
: constant Entity_Id
:= Current_Scope
;
686 procedure Set_Parents
(Visibility
: Boolean);
687 -- If this is a child instance, the parents are not immediately
688 -- visible during analysis. Make them momentarily visible so that
689 -- the argument of the pragma can be resolved properly, and reset
696 procedure Set_Parents
(Visibility
: Boolean) is
700 while Present
(Par
) and then Par
/= Standard_Standard
loop
701 Set_Is_Immediately_Visible
(Par
, Visibility
);
706 -- Start of processing for Set_Categorization_From_Pragmas
709 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
710 -- The purpose is to set categorization flags before analyzing the
711 -- unit itself, so as to diagnose violations of categorization as
712 -- we process each declaration, even though the pragma appears after
715 if Nkind
(P
) /= N_Compilation_Unit
then
723 if Is_Child_Unit
(S
) and then Is_Generic_Instance
(S
) then
727 PN
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
728 while Present
(PN
) loop
730 -- Skip implicit types that may have been introduced by
731 -- previous analysis.
733 if Nkind
(PN
) = N_Pragma
then
734 case Get_Pragma_Id
(PN
) is
735 when Pragma_All_Calls_Remote |
736 Pragma_Preelaborate |
738 Pragma_Remote_Call_Interface |
739 Pragma_Remote_Types |
740 Pragma_Shared_Passive
=> Analyze
(PN
);
748 if Is_Child_Unit
(S
) and then Is_Generic_Instance
(S
) then
752 end Set_Categorization_From_Pragmas
;
754 -----------------------------------
755 -- Set_Categorization_From_Scope --
756 -----------------------------------
758 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
759 Declaration
: Node_Id
:= Empty
;
760 Specification
: Node_Id
:= Empty
;
764 (E
, Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
766 if not Is_Remote_Call_Interface
(E
) then
767 if Ekind
(E
) in Subprogram_Kind
then
768 Declaration
:= Unit_Declaration_Node
(E
);
770 if Nkind_In
(Declaration
, N_Subprogram_Body
,
771 N_Subprogram_Renaming_Declaration
)
773 Specification
:= Corresponding_Spec
(Declaration
);
777 -- A subprogram body or renaming-as-body is a remote call interface
778 -- if it serves as the completion of a subprogram declaration that
779 -- is a remote call interface.
781 if Nkind
(Specification
) in N_Entity
then
782 Set_Is_Remote_Call_Interface
783 (E
, Is_Remote_Call_Interface
(Specification
));
785 -- A subprogram declaration is a remote call interface when it is
786 -- declared within the visible part of, or declared by, a library
787 -- unit declaration that is a remote call interface.
790 Set_Is_Remote_Call_Interface
791 (E
, Is_Remote_Call_Interface
(Scop
)
792 and then not (In_Private_Part
(Scop
)
793 or else In_Package_Body
(Scop
)));
798 (E
, Is_Remote_Types
(Scop
)
799 and then not (In_Private_Part
(Scop
)
800 or else In_Package_Body
(Scop
)));
801 end Set_Categorization_From_Scope
;
803 ------------------------------
804 -- Static_Discriminant_Expr --
805 ------------------------------
807 -- We need to accommodate a Why_Not_Static call somehow here ???
809 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
810 Discriminant_Spec
: Node_Id
;
813 Discriminant_Spec
:= First
(L
);
814 while Present
(Discriminant_Spec
) loop
815 if Present
(Expression
(Discriminant_Spec
))
817 not Is_OK_Static_Expression
(Expression
(Discriminant_Spec
))
822 Next
(Discriminant_Spec
);
826 end Static_Discriminant_Expr
;
828 --------------------------------------
829 -- Validate_Access_Type_Declaration --
830 --------------------------------------
832 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
833 Def
: constant Node_Id
:= Type_Definition
(N
);
838 -- Access to subprogram case
840 when N_Access_To_Subprogram_Definition
=>
842 -- A pure library_item must not contain the declaration of a
843 -- named access type, except within a subprogram, generic
844 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
846 -- This test is skipped in Ada 2005 (see AI-366)
848 if Ada_Version
< Ada_2005
849 and then Comes_From_Source
(T
)
850 and then In_Pure_Unit
851 and then not In_Subprogram_Task_Protected_Unit
853 Error_Msg_N
("named access type not allowed in pure unit", T
);
856 -- Access to object case
858 when N_Access_To_Object_Definition
=>
859 if Comes_From_Source
(T
)
860 and then In_Pure_Unit
861 and then not In_Subprogram_Task_Protected_Unit
863 -- We can't give the message yet, since the type is not frozen
864 -- and in Ada 2005 mode, access types are allowed in pure units
865 -- if the type has no storage pool (see AI-366). So we set a
866 -- flag which will be checked at freeze time.
868 Set_Is_Pure_Unit_Access_Type
(T
);
871 -- Check for RCI or RT unit type declaration: declaration of an
872 -- access-to-object type is illegal unless it is a general access
873 -- type that designates a class-wide limited private type.
874 -- Note that constraints on the primitive subprograms of the
875 -- designated tagged type are not enforced here but in
876 -- Validate_RACW_Primitives, which is done separately because the
877 -- designated type might not be frozen (and therefore its
878 -- primitive operations might not be completely known) at the
879 -- point of the RACW declaration.
881 Validate_Remote_Access_Object_Type_Declaration
(T
);
883 -- Check for shared passive unit type declaration. It should
884 -- not contain the declaration of access to class wide type,
885 -- access to task type and access to protected type with entry.
887 Validate_SP_Access_Object_Type_Decl
(T
);
893 -- Set categorization flag from package on entity as well, to allow
894 -- easy checks later on for required validations of RCI or RT units.
895 -- This is only done for entities that are in the original source.
897 if Comes_From_Source
(T
)
898 and then not (In_Package_Body
(Scope
(T
))
899 or else In_Private_Part
(Scope
(T
)))
901 Set_Is_Remote_Call_Interface
902 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
904 (T
, Is_Remote_Types
(Scope
(T
)));
906 end Validate_Access_Type_Declaration
;
908 ----------------------------
909 -- Validate_Ancestor_Part --
910 ----------------------------
912 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
913 A
: constant Node_Id
:= Ancestor_Part
(N
);
914 T
: constant Entity_Id
:= Entity
(A
);
917 if In_Preelaborated_Unit
918 and then not In_Subprogram_Or_Concurrent_Unit
919 and then (not Inside_A_Generic
920 or else Present
(Enclosing_Generic_Body
(N
)))
922 -- If the type is private, it must have the Ada 2005 pragma
923 -- Has_Preelaborable_Initialization.
925 -- The check is omitted within predefined units. This is probably
926 -- obsolete code to fix the Ada 95 weakness in this area ???
928 if Is_Private_Type
(T
)
929 and then not Has_Pragma_Preelab_Init
(T
)
930 and then not Is_Internal_File_Name
931 (Unit_File_Name
(Get_Source_Unit
(N
)))
934 ("private ancestor type not allowed in preelaborated unit", A
);
936 elsif Is_Record_Type
(T
) then
937 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
938 Check_Non_Static_Default_Expr
939 (Type_Definition
(Parent
(T
)), A
);
943 end Validate_Ancestor_Part
;
945 ----------------------------------------
946 -- Validate_Categorization_Dependency --
947 ----------------------------------------
949 procedure Validate_Categorization_Dependency
953 K
: constant Node_Kind
:= Nkind
(N
);
954 P
: Node_Id
:= Parent
(N
);
956 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
959 -- Only validate library units and subunits. For subunits, checks
960 -- concerning withed units apply to the parent compilation unit.
967 and then not Is_Compilation_Unit
(U
)
968 and then not Is_Child_Unit
(U
)
974 if Nkind
(P
) /= N_Compilation_Unit
then
978 -- Body of RCI unit does not need validation
980 if Is_Remote_Call_Interface
(E
)
981 and then Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
)
986 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
990 Entity_Of_Withed
: Entity_Id
;
993 Item
:= First
(Context_Items
(P
));
994 while Present
(Item
) loop
995 if Nkind
(Item
) = N_With_Clause
996 and then not (Implicit_With
(Item
)
997 or else Limited_Present
(Item
)
999 -- Skip if error already posted on the WITH
1000 -- clause (in which case the Name attribute
1001 -- may be invalid). In particular, this fixes
1002 -- the problem of hanging in the presence of a
1003 -- WITH clause on a child that is an illegal
1004 -- generic instantiation.
1006 or else Error_Posted
(Item
))
1008 Entity_Of_Withed
:= Entity
(Name
(Item
));
1009 Check_Categorization_Dependencies
1010 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
1017 -- Child depends on parent; therefore parent should also be categorized
1018 -- and satisfy the dependency hierarchy.
1020 -- Check if N is a child spec
1022 if (K
in N_Generic_Declaration
or else
1023 K
in N_Generic_Instantiation
or else
1024 K
in N_Generic_Renaming_Declaration
or else
1025 K
= N_Package_Declaration
or else
1026 K
= N_Package_Renaming_Declaration
or else
1027 K
= N_Subprogram_Declaration
or else
1028 K
= N_Subprogram_Renaming_Declaration
)
1029 and then Present
(Parent_Spec
(N
))
1031 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
1033 -- Verify that public child of an RCI library unit must also be an
1034 -- RCI library unit (RM E.2.3(15)).
1036 if Is_Remote_Call_Interface
(Scope
(E
))
1037 and then not Private_Present
(P
)
1038 and then not Is_Remote_Call_Interface
(E
)
1040 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
1043 end Validate_Categorization_Dependency
;
1045 --------------------------------
1046 -- Validate_Controlled_Object --
1047 --------------------------------
1049 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
1051 -- Don't need this check in Ada 2005 mode, where this is all taken
1052 -- care of by the mechanism for Preelaborable Initialization.
1054 if Ada_Version
>= Ada_2005
then
1058 -- For now, never apply this check for internal GNAT units, since we
1059 -- have a number of cases in the library where we are stuck with objects
1060 -- of this type, and the RM requires Preelaborate.
1062 -- For similar reasons, we only do this check for source entities, since
1063 -- we generate entities of this type in some situations.
1065 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1066 -- We have to enforce them for RM compatibility, but we have no trouble
1067 -- accepting these objects and doing the right thing. Note that there is
1068 -- no requirement that Preelaborate not actually generate any code.
1070 if In_Preelaborated_Unit
1071 and then not Debug_Flag_PP
1072 and then Comes_From_Source
(E
)
1074 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
1075 and then (not Inside_A_Generic
1076 or else Present
(Enclosing_Generic_Body
(E
)))
1077 and then not Is_Protected_Type
(Etype
(E
))
1080 ("library level controlled object not allowed in " &
1081 "preelaborated unit", E
);
1083 end Validate_Controlled_Object
;
1085 --------------------------------------
1086 -- Validate_Null_Statement_Sequence --
1087 --------------------------------------
1089 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
1093 if In_Preelaborated_Unit
then
1094 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
1095 while Present
(Item
) loop
1096 if Nkind
(Item
) /= N_Label
1097 and then Nkind
(Item
) /= N_Null_Statement
1099 -- In GNAT mode, this is a warning, allowing the run-time
1100 -- to judiciously bypass this error condition.
1102 Error_Msg_Warn
:= GNAT_Mode
;
1104 ("<<statements not allowed in preelaborated unit", Item
);
1112 end Validate_Null_Statement_Sequence
;
1114 ---------------------------------
1115 -- Validate_Object_Declaration --
1116 ---------------------------------
1118 procedure Validate_Object_Declaration
(N
: Node_Id
) is
1119 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1120 E
: constant Node_Id
:= Expression
(N
);
1121 Odf
: constant Node_Id
:= Object_Definition
(N
);
1122 T
: constant Entity_Id
:= Etype
(Id
);
1125 -- Verify that any access to subprogram object does not have in its
1126 -- subprogram profile access type parameters or limited parameters
1127 -- without Read and Write attributes (E.2.3(13)).
1129 Validate_RCI_Subprogram_Declaration
(N
);
1131 -- Check that if we are in preelaborated elaboration code, then we
1132 -- do not have an instance of a default initialized private, task or
1133 -- protected object declaration which would violate (RM 10.2.1(9)).
1134 -- Note that constants are never default initialized (and the test
1135 -- below also filters out deferred constants). A variable is default
1136 -- initialized if it does *not* have an initialization expression.
1138 -- Filter out cases that are not declaration of a variable from source
1140 if Nkind
(N
) /= N_Object_Declaration
1141 or else Constant_Present
(N
)
1142 or else not Comes_From_Source
(Id
)
1147 -- Exclude generic specs from the checks (this will get rechecked
1148 -- on instantiations).
1150 if Inside_A_Generic
and then No
(Enclosing_Generic_Body
(Id
)) then
1154 -- Required checks for declaration that is in a preelaborated package
1155 -- and is not within some subprogram.
1157 if In_Preelaborated_Unit
1158 and then not In_Subprogram_Or_Concurrent_Unit
1160 -- Check for default initialized variable case. Note that in
1161 -- accordance with (RM B.1(24)) imported objects are not subject to
1162 -- default initialization.
1163 -- If the initialization does not come from source and is an
1164 -- aggregate, it is a static initialization that replaces an
1165 -- implicit call, and must be treated as such.
1168 and then (Comes_From_Source
(E
) or else Nkind
(E
) /= N_Aggregate
)
1172 elsif Is_Imported
(Id
) then
1177 Ent
: Entity_Id
:= T
;
1180 -- An array whose component type is a record with nonstatic
1181 -- default expressions is a violation, so we get the array's
1184 if Is_Array_Type
(Ent
) then
1186 Comp_Type
: Entity_Id
;
1189 Comp_Type
:= Component_Type
(Ent
);
1190 while Is_Array_Type
(Comp_Type
) loop
1191 Comp_Type
:= Component_Type
(Comp_Type
);
1198 -- Object decl. that is of record type and has no default expr.
1199 -- should check if there is any non-static default expression
1200 -- in component decl. of the record type decl.
1202 if Is_Record_Type
(Ent
) then
1203 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1204 Check_Non_Static_Default_Expr
1205 (Type_Definition
(Parent
(Ent
)), N
);
1207 elsif Nkind
(Odf
) = N_Subtype_Indication
1208 and then not Is_Array_Type
(T
)
1209 and then not Is_Private_Type
(T
)
1211 Check_Non_Static_Default_Expr
(Type_Definition
1212 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1216 -- Check for invalid use of private object. Note that Ada 2005
1217 -- AI-161 modifies the rules for Ada 2005, including the use of
1218 -- the new pragma Preelaborable_Initialization.
1220 if Is_Private_Type
(Ent
)
1221 or else Depends_On_Private
(Ent
)
1223 -- Case where type has preelaborable initialization which
1224 -- means that a pragma Preelaborable_Initialization was
1225 -- given for the private type.
1227 if Relaxed_RM_Semantics
then
1229 -- In relaxed mode, do not issue these messages, this
1230 -- is basically similar to the GNAT_Mode test below.
1234 elsif Has_Preelaborable_Initialization
(Ent
) then
1236 -- But for the predefined units, we will ignore this
1237 -- status unless we are in Ada 2005 mode since we want
1238 -- Ada 95 compatible behavior, in which the entities
1239 -- marked with this pragma in the predefined library are
1240 -- not treated specially.
1242 if Ada_Version
< Ada_2005
then
1244 ("private object not allowed in preelaborated unit",
1246 Error_Msg_N
("\(would be legal in Ada 2005 mode)", N
);
1249 -- Type does not have preelaborable initialization
1252 -- We allow this when compiling in GNAT mode to make life
1253 -- easier for some cases where it would otherwise be hard
1254 -- to be exactly valid Ada.
1256 if not GNAT_Mode
then
1258 ("private object not allowed in preelaborated unit",
1261 -- Add a message if it would help to provide a pragma
1262 -- Preelaborable_Initialization on the type of the
1263 -- object (which would make it legal in Ada 2005).
1265 -- If the type has no full view (generic type, or
1266 -- previous error), the warning does not apply.
1268 if Is_Private_Type
(Ent
)
1269 and then Present
(Full_View
(Ent
))
1271 Has_Preelaborable_Initialization
(Full_View
(Ent
))
1273 Error_Msg_Sloc
:= Sloc
(Ent
);
1275 if Ada_Version
>= Ada_2005
then
1277 ("\would be legal if pragma Preelaborable_" &
1278 "Initialization given for & #", N
, Ent
);
1281 ("\would be legal in Ada 2005 if pragma " &
1282 "Preelaborable_Initialization given for & #",
1289 -- Access to Task or Protected type
1291 elsif Is_Entity_Name
(Odf
)
1292 and then Present
(Etype
(Odf
))
1293 and then Is_Access_Type
(Etype
(Odf
))
1295 Ent
:= Designated_Type
(Etype
(Odf
));
1297 elsif Is_Entity_Name
(Odf
) then
1298 Ent
:= Entity
(Odf
);
1300 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1301 Ent
:= Etype
(Subtype_Mark
(Odf
));
1303 elsif Nkind
(Odf
) = N_Constrained_Array_Definition
then
1304 Ent
:= Component_Type
(T
);
1307 if Is_Task_Type
(Ent
)
1308 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1311 ("concurrent object not allowed in preelaborated unit",
1318 -- Non-static discriminants not allowed in preelaborated unit.
1319 -- Objects of a controlled type with a user-defined Initialize
1320 -- are forbidden as well.
1322 if Is_Record_Type
(Etype
(Id
)) then
1324 ET
: constant Entity_Id
:= Etype
(Id
);
1325 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1329 if Has_Discriminants
(ET
) and then Present
(EE
) then
1332 if Nkind
(PEE
) = N_Full_Type_Declaration
1333 and then not Static_Discriminant_Expr
1334 (Discriminant_Specifications
(PEE
))
1337 ("non-static discriminant in preelaborated unit",
1342 -- For controlled type or type with controlled component, check
1343 -- preelaboration flag, as there may be a non-null Initialize
1344 -- primitive. For language versions earlier than Ada 2005,
1345 -- there is no notion of preelaborable initialization, and
1346 -- Validate_Controlled_Object is used to enforce rules for
1347 -- controlled objects.
1349 if (Is_Controlled
(ET
) or else Has_Controlled_Component
(ET
))
1350 and then Ada_Version
>= Ada_2005
1351 and then not Has_Preelaborable_Initialization
(ET
)
1354 ("controlled type& does not have"
1355 & " preelaborable initialization", N
, ET
);
1362 -- A pure library_item must not contain the declaration of any variable
1363 -- except within a subprogram, generic subprogram, task unit, or
1364 -- protected unit (RM 10.2.1(16)).
1366 if In_Pure_Unit
and then not In_Subprogram_Task_Protected_Unit
then
1367 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1369 -- The visible part of an RCI library unit must not contain the
1370 -- declaration of a variable (RM E.1.3(9))
1372 elsif In_RCI_Declaration
(N
) then
1373 Error_Msg_N
("visible variable not allowed in 'R'C'I unit", N
);
1375 -- The visible part of a Shared Passive library unit must not contain
1376 -- the declaration of a variable (RM E.2.2(7))
1378 elsif In_RT_Declaration
and then not In_Private_Part
(Id
) then
1380 ("visible variable not allowed in remote types unit", N
);
1383 end Validate_Object_Declaration
;
1385 -----------------------------
1386 -- Validate_RACW_Primitive --
1387 -----------------------------
1389 procedure Validate_RACW_Primitive
1393 procedure Illegal_Remote_Subp
(Msg
: String; N
: Node_Id
);
1394 -- Diagnose illegality on N. If RACW is present, report the error on it
1395 -- rather than on N.
1397 -------------------------
1398 -- Illegal_Remote_Subp --
1399 -------------------------
1401 procedure Illegal_Remote_Subp
(Msg
: String; N
: Node_Id
) is
1403 if Present
(RACW
) then
1404 if not Error_Posted
(RACW
) then
1406 ("illegal remote access to class-wide type&", RACW
);
1409 Error_Msg_Sloc
:= Sloc
(N
);
1410 Error_Msg_NE
("\\" & Msg
& " in primitive& #", RACW
, Subp
);
1413 Error_Msg_NE
(Msg
& " in remote subprogram&", N
, Subp
);
1415 end Illegal_Remote_Subp
;
1419 Param_Spec
: Node_Id
;
1420 Param_Type
: Entity_Id
;
1422 -- Start of processing for Validate_RACW_Primitive
1425 -- Check return type
1427 if Ekind
(Subp
) = E_Function
then
1428 Rtyp
:= Etype
(Subp
);
1430 -- AI05-0101 (Binding Interpretation): The result type of a remote
1431 -- function must either support external streaming or be a
1432 -- controlling access result type.
1434 if Has_Controlling_Result
(Subp
) then
1437 elsif Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
1438 Illegal_Remote_Subp
("anonymous access result", Rtyp
);
1440 elsif Is_Limited_Type
(Rtyp
) then
1441 if No
(TSS
(Rtyp
, TSS_Stream_Read
))
1443 No
(TSS
(Rtyp
, TSS_Stream_Write
))
1446 ("limited return type must have Read and Write attributes",
1448 Explain_Limited_Type
(Rtyp
, Parent
(Subp
));
1451 -- Check that the return type supports external streaming
1453 elsif No_External_Streaming
(Rtyp
)
1454 and then not Error_Posted
(Rtyp
)
1456 Illegal_Remote_Subp
("return type containing non-remote access "
1457 & "must have Read and Write attributes",
1462 Param
:= First_Formal
(Subp
);
1463 while Present
(Param
) loop
1465 -- Now find out if this parameter is a controlling parameter
1467 Param_Spec
:= Parent
(Param
);
1468 Param_Type
:= Etype
(Param
);
1470 if Is_Controlling_Formal
(Param
) then
1472 -- It is a controlling parameter, so specific checks below do not
1477 elsif Ekind_In
(Param_Type
, E_Anonymous_Access_Type
,
1478 E_Anonymous_Access_Subprogram_Type
)
1480 -- From RM E.2.2(14), no anonymous access parameter other than
1481 -- controlling ones may be used (because an anonymous access
1482 -- type never supports external streaming).
1485 ("non-controlling access parameter", Param_Spec
);
1487 elsif No_External_Streaming
(Param_Type
)
1488 and then not Error_Posted
(Param_Type
)
1490 Illegal_Remote_Subp
("formal parameter in remote subprogram must "
1491 & "support external streaming", Param_Spec
);
1494 -- Check next parameter in this subprogram
1496 Next_Formal
(Param
);
1498 end Validate_RACW_Primitive
;
1500 ------------------------------
1501 -- Validate_RACW_Primitives --
1502 ------------------------------
1504 procedure Validate_RACW_Primitives
(T
: Entity_Id
) is
1505 Desig_Type
: Entity_Id
;
1506 Primitive_Subprograms
: Elist_Id
;
1507 Subprogram_Elmt
: Elmt_Id
;
1508 Subprogram
: Entity_Id
;
1511 Desig_Type
:= Etype
(Designated_Type
(T
));
1513 -- No action needed for concurrent types
1515 if Is_Concurrent_Type
(Desig_Type
) then
1519 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1521 Subprogram_Elmt
:= First_Elmt
(Primitive_Subprograms
);
1522 while Subprogram_Elmt
/= No_Elmt
loop
1523 Subprogram
:= Node
(Subprogram_Elmt
);
1525 if Is_Predefined_Dispatching_Operation
(Subprogram
)
1526 or else Is_Hidden
(Subprogram
)
1528 goto Next_Subprogram
;
1531 Validate_RACW_Primitive
(Subp
=> Subprogram
, RACW
=> T
);
1534 Next_Elmt
(Subprogram_Elmt
);
1536 end Validate_RACW_Primitives
;
1538 -------------------------------
1539 -- Validate_RCI_Declarations --
1540 -------------------------------
1542 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1546 E
:= First_Entity
(P
);
1547 while Present
(E
) loop
1548 if Comes_From_Source
(E
) then
1549 if Is_Limited_Type
(E
) then
1551 ("limited type not allowed in rci unit", Parent
(E
));
1552 Explain_Limited_Type
(E
, Parent
(E
));
1554 elsif Ekind_In
(E
, E_Generic_Function
,
1556 E_Generic_Procedure
)
1558 Error_Msg_N
("generic declaration not allowed in rci unit",
1561 elsif (Ekind
(E
) = E_Function
or else Ekind
(E
) = E_Procedure
)
1562 and then Has_Pragma_Inline
(E
)
1565 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1567 -- Inner packages that are renamings need not be checked. Generic
1568 -- RCI packages are subject to the checks, but entities that come
1569 -- from formal packages are not part of the visible declarations
1570 -- of the package and are not checked.
1572 elsif Ekind
(E
) = E_Package
then
1573 if Present
(Renamed_Entity
(E
)) then
1576 elsif Ekind
(P
) /= E_Generic_Package
1577 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1578 Generic_Formal_Declarations
1579 (Unit_Declaration_Node
(P
))
1581 Validate_RCI_Declarations
(E
);
1588 end Validate_RCI_Declarations
;
1590 -----------------------------------------
1591 -- Validate_RCI_Subprogram_Declaration --
1592 -----------------------------------------
1594 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1595 K
: constant Node_Kind
:= Nkind
(N
);
1598 Param_Spec
: Node_Id
;
1599 Param_Type
: Entity_Id
;
1600 Error_Node
: Node_Id
:= N
;
1603 -- This procedure enforces rules on subprogram and access to subprogram
1604 -- declarations in RCI units. These rules do not apply to expander
1605 -- generated routines, which are not remote subprograms. It is called:
1607 -- 1. from Analyze_Subprogram_Declaration.
1608 -- 2. from Validate_Object_Declaration (access to subprogram).
1610 if not (Comes_From_Source
(N
) and then In_RCI_Declaration
(N
)) then
1614 if K
= N_Subprogram_Declaration
then
1615 Id
:= Defining_Unit_Name
(Specification
(N
));
1616 Profile
:= Parameter_Specifications
(Specification
(N
));
1618 else pragma Assert
(K
= N_Object_Declaration
);
1620 -- The above assertion is dubious, the visible declarations of an
1621 -- RCI unit never contain an object declaration, this should be an
1622 -- ACCESS-to-object declaration???
1624 Id
:= Defining_Identifier
(N
);
1626 if Nkind
(Id
) = N_Defining_Identifier
1627 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1628 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1631 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1637 -- Iterate through the parameter specification list, checking that
1638 -- no access parameter and no limited type parameter in the list.
1641 if Present
(Profile
) then
1642 Param_Spec
:= First
(Profile
);
1643 while Present
(Param_Spec
) loop
1644 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1646 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1647 if K
= N_Subprogram_Declaration
then
1648 Error_Node
:= Param_Spec
;
1651 -- Report error only if declaration is in source program
1653 if Comes_From_Source
1654 (Defining_Entity
(Specification
(N
)))
1657 ("subprogram in 'R'C'I unit cannot have access parameter",
1661 -- For a limited private type parameter, we check only the private
1662 -- declaration and ignore full type declaration, unless this is
1663 -- the only declaration for the type, e.g., as a limited record.
1665 elsif No_External_Streaming
(Param_Type
) then
1666 if K
= N_Subprogram_Declaration
then
1667 Error_Node
:= Param_Spec
;
1671 ("formal of remote subprogram& "
1672 & "must support external streaming",
1674 if Is_Limited_Type
(Param_Type
) then
1675 Explain_Limited_Type
(Param_Type
, Error_Node
);
1682 -- No check on return type???
1684 end Validate_RCI_Subprogram_Declaration
;
1686 ----------------------------------------------------
1687 -- Validate_Remote_Access_Object_Type_Declaration --
1688 ----------------------------------------------------
1690 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1691 Direct_Designated_Type
: Entity_Id
;
1692 Desig_Type
: Entity_Id
;
1695 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1696 -- the given node is N_Access_To_Object_Definition.
1698 if not Comes_From_Source
(T
)
1699 or else (not In_RCI_Declaration
(Parent
(T
))
1700 and then not In_RT_Declaration
)
1705 -- An access definition in the private part of a Remote Types package
1706 -- may be legal if it has user-defined Read and Write attributes. This
1707 -- will be checked at the end of the package spec processing.
1709 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1713 -- Check RCI or RT unit type declaration. It may not contain the
1714 -- declaration of an access-to-object type unless it is a general access
1715 -- type that designates a class-wide limited private type or subtype.
1716 -- There are also constraints on the primitive subprograms of the
1717 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1719 if Ekind
(T
) /= E_General_Access_Type
1720 or else not Is_Class_Wide_Type
(Designated_Type
(T
))
1722 if In_RCI_Declaration
(Parent
(T
)) then
1724 ("error in access type in Remote_Call_Interface unit", T
);
1727 ("error in access type in Remote_Types unit", T
);
1730 Error_Msg_N
("\must be general access to class-wide type", T
);
1734 Direct_Designated_Type
:= Designated_Type
(T
);
1735 Desig_Type
:= Etype
(Direct_Designated_Type
);
1737 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type???
1739 if not Is_Valid_Remote_Object_Type
(Desig_Type
) then
1741 ("error in designated type of remote access to class-wide type", T
);
1743 ("\must be tagged limited private or private extension", T
);
1746 end Validate_Remote_Access_Object_Type_Declaration
;
1748 -----------------------------------------------
1749 -- Validate_Remote_Access_To_Class_Wide_Type --
1750 -----------------------------------------------
1752 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1753 K
: constant Node_Kind
:= Nkind
(N
);
1754 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1758 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1759 -- of class-wide limited private types.
1761 -- Storage_Pool and Storage_Size are not defined for such types
1763 -- The expected type of allocator must not be such a type.
1765 -- The actual parameter of generic instantiation must not be such a
1766 -- type if the formal parameter is of an access type.
1768 -- On entry, there are several cases:
1770 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1771 -- either Storage_Pool or Storage_Size.
1773 -- 2. called from exp_ch4 Expand_N_Allocator
1775 -- 3. called from sem_ch4 Analyze_Explicit_Dereference
1777 -- 4. called from sem_res Resolve_Actuals
1779 if K
= N_Attribute_Reference
then
1780 E
:= Etype
(Prefix
(N
));
1782 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1783 Error_Msg_N
("incorrect attribute of remote operand", N
);
1787 elsif K
= N_Allocator
then
1790 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1791 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1795 -- This subprogram also enforces the checks in E.2.2(13). A value of
1796 -- such type must not be dereferenced unless as controlling operand of
1797 -- a dispatching call. Explicit dereferences not coming from source are
1798 -- exempted from this checking because the expander produces them in
1799 -- some cases (such as for tag checks on dispatching calls with multiple
1800 -- controlling operands). However we do check in the case of an implicit
1801 -- dereference that is expanded to an explicit dereference (hence the
1802 -- test of whether Original_Node (N) comes from source).
1804 elsif K
= N_Explicit_Dereference
1805 and then Comes_From_Source
(Original_Node
(N
))
1807 E
:= Etype
(Prefix
(N
));
1809 -- If the class-wide type is not a remote one, the restrictions
1812 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1816 -- If we have a true dereference that comes from source and that
1817 -- is a controlling argument for a dispatching call, accept it.
1819 if Is_Actual_Parameter
(N
) and then Is_Controlling_Actual
(N
) then
1823 -- If we are just within a procedure or function call and the
1824 -- dereference has not been analyzed, return because this procedure
1825 -- will be called again from sem_res Resolve_Actuals. The same can
1826 -- apply in the case of dereference that is the prefix of a selected
1827 -- component, which can be a call given in prefixed form.
1829 if (Is_Actual_Parameter
(N
) or else PK
= N_Selected_Component
)
1830 and then not Analyzed
(N
)
1835 -- We must allow expanded code to generate a reference to the tag of
1836 -- the designated object (may be either the actual tag, or the stub
1837 -- tag in the case of a remote object).
1839 if PK
= N_Selected_Component
1840 and then Is_Tag
(Entity
(Selector_Name
(Parent
(N
))))
1846 ("invalid dereference of a remote access-to-class-wide value", N
);
1848 end Validate_Remote_Access_To_Class_Wide_Type
;
1850 ------------------------------------------
1851 -- Validate_Remote_Type_Type_Conversion --
1852 ------------------------------------------
1854 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1855 S
: constant Entity_Id
:= Etype
(N
);
1856 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1859 -- This test is required in the case where a conversion appears inside a
1860 -- normal package, it does not necessarily have to be inside an RCI,
1861 -- Remote_Types unit (RM E.2.2(9,12)).
1863 if Is_Remote_Access_To_Subprogram_Type
(E
)
1864 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1867 ("incorrect conversion of remote operand to local type", N
);
1870 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1871 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1874 ("incorrect conversion of local operand to remote type", N
);
1877 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1878 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1881 ("incorrect conversion of remote operand to local type", N
);
1885 -- If a local access type is converted into a RACW type, then the
1886 -- current unit has a pointer that may now be exported to another
1889 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1890 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1892 Set_Has_RACW
(Current_Sem_Unit
);
1894 end Validate_Remote_Type_Type_Conversion
;
1896 -------------------------------
1897 -- Validate_RT_RAT_Component --
1898 -------------------------------
1900 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1901 Spec
: constant Node_Id
:= Specification
(N
);
1902 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1905 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1907 function Stream_Attributes_Available
(Typ
: Entity_Id
) return Boolean;
1908 -- True if any stream attribute is available for Typ
1910 ---------------------------------
1911 -- Stream_Attributes_Available --
1912 ---------------------------------
1914 function Stream_Attributes_Available
(Typ
: Entity_Id
) return Boolean
1917 return Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
1919 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
1921 Stream_Attribute_Available
(Typ
, TSS_Stream_Input
)
1923 Stream_Attribute_Available
(Typ
, TSS_Stream_Output
);
1924 end Stream_Attributes_Available
;
1926 -- Start of processing for Validate_RT_RAT_Component
1929 if not Is_Remote_Types
(Name_U
) then
1933 Typ
:= First_Entity
(Name_U
);
1934 while Present
(Typ
) and then Typ
/= First_Priv_Ent
loop
1935 U_Typ
:= Underlying_Type
(Typ
);
1941 if Comes_From_Source
(Typ
) and then Is_Type
(Typ
) then
1943 -- Check that the type can be meaningfully transmitted to another
1944 -- partition (E.2.2(8)).
1946 if (Ada_Version
< Ada_2005
and then Has_Non_Remote_Access
(U_Typ
))
1947 or else (Stream_Attributes_Available
(Typ
)
1948 and then No_External_Streaming
(U_Typ
))
1950 if Is_Non_Remote_Access_Type
(Typ
) then
1951 Error_Msg_N
("error in non-remote access type", U_Typ
);
1954 ("error in record type containing a component of a " &
1955 "non-remote access type", U_Typ
);
1958 if Ada_Version
>= Ada_2005
then
1960 ("\must have visible Read and Write attribute " &
1961 "definition clauses (RM E.2.2(8))", U_Typ
);
1964 ("\must have Read and Write attribute " &
1965 "definition clauses (RM E.2.2(8))", U_Typ
);
1972 end Validate_RT_RAT_Component
;
1974 -----------------------------------------
1975 -- Validate_SP_Access_Object_Type_Decl --
1976 -----------------------------------------
1978 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
1979 Direct_Designated_Type
: Entity_Id
;
1981 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
1982 -- Return true if the protected type designated by T has entry
1985 ----------------------------
1986 -- Has_Entry_Declarations --
1987 ----------------------------
1989 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
1993 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
1994 Ety
:= First_Entity
(E
);
1995 while Present
(Ety
) loop
1996 if Ekind
(Ety
) = E_Entry
then
2005 end Has_Entry_Declarations
;
2007 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2010 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2011 -- Nkind of the given entity is N_Access_To_Object_Definition.
2013 if not Comes_From_Source
(T
)
2014 or else not In_Shared_Passive_Unit
2015 or else In_Subprogram_Task_Protected_Unit
2020 -- Check Shared Passive unit. It should not contain the declaration
2021 -- of an access-to-object type whose designated type is a class-wide
2022 -- type, task type or protected type with entry (RM E.2.1(7)).
2024 Direct_Designated_Type
:= Designated_Type
(T
);
2026 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
2028 ("invalid access-to-class-wide type in shared passive unit", T
);
2031 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
2033 ("invalid access-to-task type in shared passive unit", T
);
2036 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
2037 and then Has_Entry_Declarations
(Direct_Designated_Type
)
2040 ("invalid access-to-protected type in shared passive unit", T
);
2043 end Validate_SP_Access_Object_Type_Decl
;
2045 ---------------------------------
2046 -- Validate_Static_Object_Name --
2047 ---------------------------------
2049 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
2053 function Is_Primary
(N
: Node_Id
) return Boolean;
2054 -- Determine whether node is syntactically a primary in an expression
2055 -- This function should probably be somewhere else ???
2057 -- Also it does not do what it says, e.g if N is a binary operator
2058 -- whose parent is a binary operator, Is_Primary returns True ???
2064 function Is_Primary
(N
: Node_Id
) return Boolean is
2065 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
2069 when N_Op | N_Membership_Test
=>
2073 | N_Component_Association
2074 | N_Index_Or_Discriminant_Constraint
=>
2077 when N_Attribute_Reference
=>
2078 return Attribute_Name
(Parent
(N
)) /= Name_Address
2079 and then Attribute_Name
(Parent
(N
)) /= Name_Access
2080 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
2082 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
2084 when N_Indexed_Component
=>
2085 return (N
/= Prefix
(Parent
(N
))
2086 or else Is_Primary
(Parent
(N
)));
2088 when N_Qualified_Expression | N_Type_Conversion
=>
2089 return Is_Primary
(Parent
(N
));
2091 when N_Assignment_Statement | N_Object_Declaration
=>
2092 return (N
= Expression
(Parent
(N
)));
2094 when N_Selected_Component
=>
2095 return Is_Primary
(Parent
(N
));
2102 -- Start of processing for Validate_Static_Object_Name
2105 if not In_Preelaborated_Unit
2106 or else not Comes_From_Source
(N
)
2107 or else In_Subprogram_Or_Concurrent_Unit
2108 or else Ekind
(Current_Scope
) = E_Block
2112 -- Filter out cases where primary is default in a component declaration,
2113 -- discriminant specification, or actual in a record type initialization
2116 -- Initialization call of internal types
2118 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
2120 if Present
(Parent
(Parent
(N
)))
2121 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
2126 if Nkind
(Name
(Parent
(N
))) = N_Identifier
2127 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
2133 -- Error if the name is a primary in an expression. The parent must not
2134 -- be an operator, or a selected component or an indexed component that
2135 -- is itself a primary. Entities that are actuals do not need to be
2136 -- checked, because the call itself will be diagnosed.
2139 and then (not Inside_A_Generic
2140 or else Present
(Enclosing_Generic_Body
(N
)))
2142 if Ekind
(Entity
(N
)) = E_Variable
2143 or else Ekind
(Entity
(N
)) in Formal_Object_Kind
2145 Flag_Non_Static_Expr
2146 ("non-static object name in preelaborated unit", N
);
2148 -- Give an error for a reference to a nonstatic constant, unless the
2149 -- constant is in another GNAT library unit that is preelaborable.
2151 elsif Ekind
(Entity
(N
)) = E_Constant
2152 and then not Is_Static_Expression
(N
)
2155 Val
:= Constant_Value
(E
);
2157 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
2159 Enclosing_Comp_Unit_Node
(N
) /= Enclosing_Comp_Unit_Node
(E
)
2160 and then (Is_Preelaborated
(Scope
(E
))
2161 or else Is_Pure
(Scope
(E
))
2162 or else (Present
(Renamed_Object
(E
))
2163 and then Is_Entity_Name
(Renamed_Object
(E
))
2166 (Scope
(Renamed_Object
(E
)))
2169 (Scope
(Renamed_Object
(E
))))))
2173 -- If the value of the constant is a local variable that renames
2174 -- an aggregate, this is in itself legal. The aggregate may be
2175 -- expanded into a loop, but this does not affect preelaborability
2176 -- in itself. If some aggregate components are non-static, that is
2177 -- to say if they involve non static primaries, they will be
2178 -- flagged when analyzed.
2181 and then Is_Entity_Name
(Val
)
2182 and then Is_Array_Type
(Etype
(Val
))
2183 and then not Comes_From_Source
(Val
)
2184 and then Nkind
(Original_Node
(Val
)) = N_Aggregate
2188 -- This is the error case
2191 -- In GNAT mode or Relaxed RM Semantic mode, this is just a
2192 -- warning, to allow it to be judiciously turned off.
2193 -- Otherwise it is a real error.
2195 if GNAT_Mode
or Relaxed_RM_Semantics
then
2197 ("??non-static constant in preelaborated unit", N
);
2199 Flag_Non_Static_Expr
2200 ("non-static constant in preelaborated unit", N
);
2205 end Validate_Static_Object_Name
;