1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Einfo
.Entities
; use Einfo
.Entities
;
30 with Einfo
.Utils
; use Einfo
.Utils
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
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 Sinfo
.Nodes
; use Sinfo
.Nodes
;
45 with Sinfo
.Utils
; use Sinfo
.Utils
;
46 with Snames
; use Snames
;
47 with Stand
; use Stand
;
49 package body Sem_Cat
is
51 -----------------------
52 -- Local Subprograms --
53 -----------------------
55 procedure Check_Categorization_Dependencies
56 (Unit_Entity
: Entity_Id
;
57 Depended_Entity
: Entity_Id
;
59 Is_Subunit
: Boolean);
60 -- This procedure checks that the categorization of a lib unit and that
61 -- of the depended unit satisfy dependency restrictions.
62 -- The depended_entity can be the entity in a with_clause item, in which
63 -- case Info_Node denotes that item. The depended_entity can also be the
64 -- parent unit of a child unit, in which case Info_Node is the declaration
65 -- of the child unit. The error message is posted on Info_Node, and is
66 -- specialized if Is_Subunit is true.
68 procedure Check_Non_Static_Default_Expr
71 -- Iterate through the component list of a record definition, check
72 -- that no component is declared with a nonstatic default value.
73 -- If a nonstatic default exists, report an error on Obj_Decl.
75 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
76 -- Return True if entity has attribute definition clauses for Read and
77 -- Write attributes that are visible at some place.
79 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
80 -- Returns true if the entity is a type whose full view is a non-remote
81 -- access type, for the purpose of enforcing E.2.2(8) rules.
83 function Has_Non_Remote_Access
(Typ
: Entity_Id
) return Boolean;
84 -- Return true if Typ or the type of any of its subcomponents is a non
85 -- remote access type and doesn't have user-defined stream attributes.
87 function No_External_Streaming
(E
: Entity_Id
) return Boolean;
88 -- Return True if the entity or one of its subcomponents does not support
89 -- external streaming.
91 function In_RCI_Declaration
return Boolean;
92 function In_RT_Declaration
return Boolean;
93 -- Determine if current scope is within the declaration of a Remote Call
94 -- Interface or Remote Types unit, for semantic checking purposes.
96 function In_Package_Declaration
return Boolean;
97 -- Shared supporting routine for In_RCI_Declaration and In_RT_Declaration
99 function In_Shared_Passive_Unit
return Boolean;
100 -- Determines if current scope is within a Shared Passive compilation unit
102 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
103 -- Iterate through the list of discriminants to check if any of them
104 -- contains non-static default expression, which is a violation in
105 -- a preelaborated library unit.
107 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
108 -- Check validity of declaration if RCI or RT unit. It should not contain
109 -- the declaration of an access-to-object type unless it is a general
110 -- access type that designates a class-wide limited private type. There are
111 -- also constraints about the primitive subprograms of the class-wide type.
112 -- RM E.2 (9, 13, 14)
114 procedure Validate_RACW_Primitive
117 -- Check legality of the declaration of primitive Subp of the designated
118 -- type of the given RACW type.
120 ---------------------------------------
121 -- Check_Categorization_Dependencies --
122 ---------------------------------------
124 procedure Check_Categorization_Dependencies
125 (Unit_Entity
: Entity_Id
;
126 Depended_Entity
: Entity_Id
;
128 Is_Subunit
: Boolean)
130 N
: constant Node_Id
:= Info_Node
;
133 -- Here we define an enumeration type to represent categorization types,
134 -- ordered so that a unit with a given categorization can only WITH
135 -- units with lower or equal categorization type.
137 type Categorization
is
141 Remote_Call_Interface
,
144 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
145 -- Check categorization flags from entity, and return in the form
146 -- of the lowest value of the Categorization type that applies to E.
148 ------------------------
149 -- Get_Categorization --
150 ------------------------
152 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
154 -- Get the lowest categorization that corresponds to E. Note that
155 -- nothing prevents several (different) categorization pragmas
156 -- to apply to the same library unit, in which case the unit has
157 -- all associated categories, so we need to be careful here to
158 -- check pragmas in proper Categorization order in order to
159 -- return the lowest applicable value.
161 -- Ignore Pure specification if set by pragma Pure_Function
165 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
169 elsif Is_Shared_Passive
(E
) then
170 return Shared_Passive
;
172 elsif Is_Remote_Types
(E
) then
175 elsif Is_Remote_Call_Interface
(E
) then
176 return Remote_Call_Interface
;
181 end Get_Categorization
;
183 Unit_Category
: Categorization
;
184 With_Category
: Categorization
;
186 -- Start of processing for Check_Categorization_Dependencies
189 -- Intrinsic subprograms are preelaborated, so do not impose any
190 -- categorization dependencies. Also, ignore categorization
191 -- dependencies when compilation switch -gnatdu is used.
193 if Is_Intrinsic_Subprogram
(Depended_Entity
) or else Debug_Flag_U
then
197 -- First check 10.2.1 (11/1) rules on preelaborate packages
199 if Is_Preelaborated
(Unit_Entity
)
200 and then not Is_Preelaborated
(Depended_Entity
)
201 and then not Is_Pure
(Depended_Entity
)
208 -- Check categorization rules of RM E.2(5)
210 Unit_Category
:= Get_Categorization
(Unit_Entity
);
211 With_Category
:= Get_Categorization
(Depended_Entity
);
213 if With_Category
> Unit_Category
then
215 -- Special case: Remote_Types and Remote_Call_Interface are allowed
216 -- to WITH anything in the package body, per (RM E.2(5)).
218 if (Unit_Category
= Remote_Types
219 or else Unit_Category
= Remote_Call_Interface
)
220 and then In_Package_Body
(Unit_Entity
)
224 -- Special case: Remote_Types and Remote_Call_Interface declarations
225 -- can depend on a preelaborated unit via a private with_clause, per
228 elsif (Unit_Category
= Remote_Types
230 Unit_Category
= Remote_Call_Interface
)
231 and then Nkind
(N
) = N_With_Clause
232 and then Private_Present
(N
)
233 and then Is_Preelaborated
(Depended_Entity
)
237 -- All other cases, we do have an error
244 -- Here if we have an error
248 -- These messages are warnings in GNAT mode or if the -gnateP switch
249 -- was set. Otherwise these are real errors for real illegalities.
251 -- The reason we suppress these errors in GNAT mode is that the run-
252 -- time has several instances of violations of the categorization
253 -- errors (e.g. Pure units withing Preelaborate units. All these
254 -- violations are harmless in the cases where we intend them, and
255 -- we suppress the warnings with Warnings (Off). In cases where we
256 -- do not intend the violation, warnings are errors in GNAT mode
257 -- anyway, so we will still get an error.
260 Treat_Categorization_Errors_As_Warnings
or GNAT_Mode
;
262 -- Don't give error if main unit is not an internal unit, and the
263 -- unit generating the message is an internal unit. This is the
264 -- situation in which such messages would be ignored in any case,
265 -- so it is convenient not to generate them (since it causes
266 -- annoying interference with debugging).
268 if Is_Internal_Unit
(Current_Sem_Unit
)
269 and then not Is_Internal_Unit
(Main_Unit
)
273 -- Dependence of Remote_Types or Remote_Call_Interface declaration
274 -- on a preelaborated unit with a normal with_clause.
276 elsif (Unit_Category
= Remote_Types
278 Unit_Category
= Remote_Call_Interface
)
279 and then Is_Preelaborated
(Depended_Entity
)
282 ("<<must use private with clause for preelaborated unit&",
287 elsif Is_Subunit
then
289 ("<subunit cannot depend on& " &
290 "(parent has wrong categorization)", N
, Depended_Entity
);
292 -- Normal unit, not subunit
296 ("<<cannot depend on& " &
297 "(wrong categorization)", N
, Depended_Entity
);
300 -- Add further explanation for Pure/Preelaborate common cases
302 if Unit_Category
= Pure
then
304 ("\<<pure unit cannot depend on non-pure unit", N
);
306 elsif Is_Preelaborated
(Unit_Entity
)
307 and then not Is_Preelaborated
(Depended_Entity
)
308 and then not Is_Pure
(Depended_Entity
)
311 ("\<<preelaborated unit cannot depend on "
312 & "non-preelaborated unit", N
);
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
351 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
353 while Present
(Component_Decl
) loop
354 if Nkind
(Component_Decl
) = N_Component_Declaration
355 and then Present
(Expression
(Component_Decl
))
356 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
357 and then not Is_OK_Static_Expression
(Expression
(Component_Decl
))
359 -- If we're in a predefined unit, we can put whatever we like in a
360 -- preelaborated package, and in fact in some cases it's necessary
361 -- to bend the rules. Ada.Containers.Bounded_Hashed_Maps contains
362 -- some code that would not be considered preelaborable in user
363 -- code, for example.
365 and then not In_Predefined_Unit
(Component_Decl
)
367 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
369 ("object in preelaborated unit has non-static default#",
372 -- Fix this later ???
374 -- elsif Has_Dynamic_Itype (Component_Decl) then
376 -- ("dynamic type discriminant," &
377 -- " constraint in preelaborated unit",
381 Next
(Component_Decl
);
383 end Check_Non_Static_Default_Expr
;
385 ---------------------------
386 -- Has_Non_Remote_Access --
387 ---------------------------
389 function Has_Non_Remote_Access
(Typ
: Entity_Id
) return Boolean is
390 Component
: Entity_Id
;
391 Comp_Type
: Entity_Id
;
392 U_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
398 elsif Has_Read_Write_Attributes
(Typ
)
399 or else Has_Read_Write_Attributes
(U_Typ
)
403 elsif Is_Non_Remote_Access_Type
(U_Typ
) then
407 if Is_Record_Type
(U_Typ
) then
408 Component
:= First_Entity
(U_Typ
);
409 while Present
(Component
) loop
410 if not Is_Tag
(Component
) then
411 Comp_Type
:= Etype
(Component
);
413 if Has_Non_Remote_Access
(Comp_Type
) then
418 Next_Entity
(Component
);
421 elsif Is_Array_Type
(U_Typ
) then
422 return Has_Non_Remote_Access
(Component_Type
(U_Typ
));
427 end Has_Non_Remote_Access
;
429 -------------------------------
430 -- Has_Read_Write_Attributes --
431 -------------------------------
433 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
437 and then Has_Stream_Attribute_Definition
438 (E
, TSS_Stream_Read
, Real_Rep
, At_Any_Place
=> True)
439 and then Has_Stream_Attribute_Definition
440 (E
, TSS_Stream_Write
, Real_Rep
, At_Any_Place
=> True);
441 end Has_Read_Write_Attributes
;
443 -------------------------------------
444 -- Has_Stream_Attribute_Definition --
445 -------------------------------------
447 function Has_Stream_Attribute_Definition
450 Real_Rep
: out Node_Id
;
451 At_Any_Place
: Boolean := False) return Boolean
456 -- We start from the declaration node and then loop until the end of
457 -- the list until we find the requested attribute definition clause.
458 -- In Ada 2005 mode, clauses are ignored if they are not currently
459 -- visible (this is tested using the corresponding Entity, which is
460 -- inserted by the expander at the point where the clause occurs),
461 -- unless At_Any_Place is true.
465 Rep_Item
:= First_Rep_Item
(Typ
);
466 while Present
(Rep_Item
) loop
467 Real_Rep
:= Rep_Item
;
469 -- If the representation item is an aspect specification, retrieve
470 -- the corresponding pragma or attribute definition.
472 if Nkind
(Rep_Item
) = N_Aspect_Specification
then
473 Real_Rep
:= Aspect_Rep_Item
(Rep_Item
);
476 if Nkind
(Real_Rep
) = N_Attribute_Definition_Clause
then
477 case Chars
(Real_Rep
) is
479 exit when Nam
= TSS_Stream_Read
;
482 exit when Nam
= TSS_Stream_Write
;
485 exit when Nam
= TSS_Stream_Input
;
488 exit when Nam
= TSS_Stream_Output
;
495 Next_Rep_Item
(Rep_Item
);
498 -- If not found, and the type is derived from a private view, check
499 -- for a stream attribute inherited from parent. Any specified stream
500 -- attributes will be attached to the derived type's underlying type
501 -- rather the derived type entity itself (which is itself private).
504 and then Is_Private_Type
(Typ
)
505 and then Is_Derived_Type
(Typ
)
506 and then Present
(Full_View
(Typ
))
508 return Has_Stream_Attribute_Definition
509 (Underlying_Type
(Typ
), Nam
, Real_Rep
, At_Any_Place
);
511 -- Otherwise, if At_Any_Place is true, return True if the attribute is
512 -- available at any place; if it is false, return True only if the
513 -- attribute is currently visible.
516 return Present
(Rep_Item
)
517 and then (Ada_Version
< Ada_2005
519 or else not Is_Hidden
(Entity
(Rep_Item
)));
521 end Has_Stream_Attribute_Definition
;
523 ----------------------------
524 -- In_Package_Declaration --
525 ----------------------------
527 function In_Package_Declaration
return Boolean is
528 Unit_Kind
: constant Node_Kind
:=
529 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
532 -- There are no restrictions on the body of an RCI or RT unit
534 return Is_Package_Or_Generic_Package
(Current_Scope
)
535 and then Unit_Kind
/= N_Package_Body
536 and then not In_Package_Body
(Current_Scope
)
537 and then not In_Instance
;
538 end In_Package_Declaration
;
540 ---------------------------
541 -- In_Preelaborated_Unit --
542 ---------------------------
544 function In_Preelaborated_Unit
return Boolean is
545 Unit_Entity
: Entity_Id
:= Current_Scope
;
546 Unit_Kind
: constant Node_Kind
:=
547 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
550 -- If evaluating actuals for a child unit instantiation, then ignore
551 -- the preelaboration status of the parent; use the child instead.
553 if Is_Compilation_Unit
(Unit_Entity
)
554 and then Unit_Kind
in N_Generic_Instantiation
555 and then not In_Same_Source_Unit
(Unit_Entity
,
556 Cunit
(Current_Sem_Unit
))
558 Unit_Entity
:= Cunit_Entity
(Current_Sem_Unit
);
561 -- There are no constraints on the body of Remote_Call_Interface or
562 -- Remote_Types packages.
564 return Unit_Entity
/= Standard_Standard
565 and then (Is_Preelaborated
(Unit_Entity
)
566 or else Is_Pure
(Unit_Entity
)
567 or else Is_Shared_Passive
(Unit_Entity
)
569 ((Is_Remote_Types
(Unit_Entity
)
570 or else Is_Remote_Call_Interface
(Unit_Entity
))
571 and then Ekind
(Unit_Entity
) = E_Package
572 and then Unit_Kind
/= N_Package_Body
573 and then not In_Package_Body
(Unit_Entity
)
574 and then not In_Instance
));
575 end In_Preelaborated_Unit
;
581 function In_Pure_Unit
return Boolean is
583 return Is_Pure
(Current_Scope
);
586 ------------------------
587 -- In_RCI_Declaration --
588 ------------------------
590 function In_RCI_Declaration
return Boolean is
592 return Is_Remote_Call_Interface
(Current_Scope
)
593 and then In_Package_Declaration
;
594 end In_RCI_Declaration
;
596 -----------------------
597 -- In_RT_Declaration --
598 -----------------------
600 function In_RT_Declaration
return Boolean is
602 return Is_Remote_Types
(Current_Scope
) and then In_Package_Declaration
;
603 end In_RT_Declaration
;
605 ----------------------------
606 -- In_Shared_Passive_Unit --
607 ----------------------------
609 function In_Shared_Passive_Unit
return Boolean is
610 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
613 return Is_Shared_Passive
(Unit_Entity
);
614 end In_Shared_Passive_Unit
;
616 ---------------------------------------
617 -- In_Subprogram_Task_Protected_Unit --
618 ---------------------------------------
620 function In_Subprogram_Task_Protected_Unit
return Boolean is
624 -- The following is to verify that a declaration is inside
625 -- subprogram, generic subprogram, task unit, protected unit.
626 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
628 -- Use scope chain to check successively outer scopes
632 if Is_Subprogram_Or_Generic_Subprogram
(E
)
634 Is_Concurrent_Type
(E
)
638 elsif E
= Standard_Standard
then
644 end In_Subprogram_Task_Protected_Unit
;
646 -------------------------------
647 -- Is_Non_Remote_Access_Type --
648 -------------------------------
650 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
651 U_E
: constant Entity_Id
:= Underlying_Type
(Base_Type
(E
));
652 -- Use full view of base type to handle subtypes properly.
657 -- This case arises for the case of a generic formal type, in which
658 -- case E.2.2(8) rules will be enforced at instantiation time.
663 return Is_Access_Type
(U_E
)
664 and then not Is_Remote_Access_To_Class_Wide_Type
(U_E
)
665 and then not Is_Remote_Access_To_Subprogram_Type
(U_E
);
666 end Is_Non_Remote_Access_Type
;
668 ---------------------------
669 -- No_External_Streaming --
670 ---------------------------
672 function No_External_Streaming
(E
: Entity_Id
) return Boolean is
673 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
679 elsif Has_Read_Write_Attributes
(E
) then
681 -- Note: availability of stream attributes is tested on E, not U_E.
682 -- There may be stream attributes defined on U_E that are not visible
683 -- at the place where support of external streaming is tested.
687 elsif Has_Non_Remote_Access
(U_E
) then
691 return Is_Limited_Type
(E
);
692 end No_External_Streaming
;
694 -------------------------------------
695 -- Set_Categorization_From_Pragmas --
696 -------------------------------------
698 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
699 P
: constant Node_Id
:= Parent
(N
);
701 procedure Make_Parents_Visible_And_Process_Pragmas
(Par
: Entity_Id
);
702 -- Parents might not be immediately visible during analysis. Make
703 -- them momentarily visible so that the argument of the pragma can
704 -- be resolved properly, process pragmas and restore the previous
707 procedure Process_Categorization_Pragmas
;
708 -- Process categorization pragmas, if any
710 ------------------------------------
711 -- Process_Categorization_Pragmas --
712 ------------------------------------
714 procedure Process_Categorization_Pragmas
is
718 PN
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
719 while Present
(PN
) loop
721 -- Skip implicit types that may have been introduced by
722 -- previous analysis.
724 if Nkind
(PN
) = N_Pragma
then
725 case Get_Pragma_Id
(PN
) is
726 when Pragma_All_Calls_Remote
727 | Pragma_Preelaborate
729 | Pragma_Remote_Call_Interface
730 | Pragma_Remote_Types
731 | Pragma_Shared_Passive
742 end Process_Categorization_Pragmas
;
744 ----------------------------------------------
745 -- Make_Parents_Visible_And_Process_Pragmas --
746 ----------------------------------------------
748 procedure Make_Parents_Visible_And_Process_Pragmas
(Par
: Entity_Id
) is
750 -- When we reached the Standard scope, then just process pragmas
752 if Par
= Standard_Standard
then
753 Process_Categorization_Pragmas
;
755 -- Otherwise make the current scope momentarily visible, recurse
756 -- into its enclosing scope, and restore the visibility. This is
757 -- required for child units that are instances of generic parents.
761 Save_Is_Immediately_Visible
: constant Boolean :=
762 Is_Immediately_Visible
(Par
);
764 Set_Is_Immediately_Visible
(Par
);
765 Make_Parents_Visible_And_Process_Pragmas
(Scope
(Par
));
766 Set_Is_Immediately_Visible
(Par
, Save_Is_Immediately_Visible
);
769 end Make_Parents_Visible_And_Process_Pragmas
;
771 -- Start of processing for Set_Categorization_From_Pragmas
774 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
775 -- The purpose is to set categorization flags before analyzing the
776 -- unit itself, so as to diagnose violations of categorization as
777 -- we process each declaration, even though the pragma appears after
780 if Nkind
(P
) /= N_Compilation_Unit
then
784 Make_Parents_Visible_And_Process_Pragmas
(Scope
(Current_Scope
));
785 end Set_Categorization_From_Pragmas
;
787 -----------------------------------
788 -- Set_Categorization_From_Scope --
789 -----------------------------------
791 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
792 Declaration
: Node_Id
:= Empty
;
793 Specification
: Node_Id
:= Empty
;
796 -- Do not modify the purity of an internally generated entity if it has
797 -- been explicitly marked as pure for optimization purposes.
799 if not Has_Pragma_Pure_Function
(E
) then
801 (E
, Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
804 if not Is_Remote_Call_Interface
(E
) then
805 if Is_Subprogram
(E
) then
806 Declaration
:= Unit_Declaration_Node
(E
);
808 if Nkind
(Declaration
) in
809 N_Subprogram_Body | N_Subprogram_Renaming_Declaration
811 Specification
:= Corresponding_Spec
(Declaration
);
815 -- A subprogram body or renaming-as-body is a remote call interface
816 -- if it serves as the completion of a subprogram declaration that
817 -- is a remote call interface.
819 if Nkind
(Specification
) in N_Entity
then
820 Set_Is_Remote_Call_Interface
821 (E
, Is_Remote_Call_Interface
(Specification
));
823 -- A subprogram declaration is a remote call interface when it is
824 -- declared within the visible part of, or declared by, a library
825 -- unit declaration that is a remote call interface.
828 Set_Is_Remote_Call_Interface
829 (E
, Is_Remote_Call_Interface
(Scop
)
830 and then not (In_Private_Part
(Scop
)
831 or else In_Package_Body
(Scop
)));
836 (E
, Is_Remote_Types
(Scop
)
837 and then not (In_Private_Part
(Scop
)
838 or else In_Package_Body
(Scop
)));
839 end Set_Categorization_From_Scope
;
841 ------------------------------
842 -- Static_Discriminant_Expr --
843 ------------------------------
845 -- We need to accommodate a Why_Not_Static call somehow here ???
847 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
848 Discriminant_Spec
: Node_Id
;
851 Discriminant_Spec
:= First
(L
);
852 while Present
(Discriminant_Spec
) loop
853 if Present
(Expression
(Discriminant_Spec
))
855 not Is_OK_Static_Expression
(Expression
(Discriminant_Spec
))
860 Next
(Discriminant_Spec
);
864 end Static_Discriminant_Expr
;
866 --------------------------------------
867 -- Validate_Access_Type_Declaration --
868 --------------------------------------
870 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
871 Def
: constant Node_Id
:= Type_Definition
(N
);
876 -- Access to subprogram case
878 when N_Access_To_Subprogram_Definition
=>
880 -- A pure library_item must not contain the declaration of a
881 -- named access type, except within a subprogram, generic
882 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
884 -- This test is skipped in Ada 2005 (see AI-366)
886 if Ada_Version
< Ada_2005
887 and then Comes_From_Source
(T
)
888 and then In_Pure_Unit
889 and then not In_Subprogram_Task_Protected_Unit
891 Error_Msg_N
("named access type not allowed in pure unit", T
);
894 -- Access to object case
896 when N_Access_To_Object_Definition
=>
897 if Comes_From_Source
(T
)
898 and then In_Pure_Unit
899 and then not In_Subprogram_Task_Protected_Unit
901 -- We can't give the message yet, since the type is not frozen
902 -- and in Ada 2005 mode, access types are allowed in pure units
903 -- if the type has no storage pool (see AI-366). So we set a
904 -- flag which will be checked at freeze time.
906 Set_Is_Pure_Unit_Access_Type
(T
);
909 -- Check for RCI or RT unit type declaration: declaration of an
910 -- access-to-object type is illegal unless it is a general access
911 -- type that designates a class-wide limited private type.
912 -- Note that constraints on the primitive subprograms of the
913 -- designated tagged type are not enforced here but in
914 -- Validate_RACW_Primitives, which is done separately because the
915 -- designated type might not be frozen (and therefore its
916 -- primitive operations might not be completely known) at the
917 -- point of the RACW declaration.
919 Validate_Remote_Access_Object_Type_Declaration
(T
);
921 -- Check for shared passive unit type declaration. It should
922 -- not contain the declaration of access to class wide type,
923 -- access to task type and access to protected type with entry.
925 Validate_SP_Access_Object_Type_Decl
(T
);
931 -- Set categorization flag from package on entity as well, to allow
932 -- easy checks later on for required validations of RCI or RT units.
933 -- This is only done for entities that are in the original source.
935 if Comes_From_Source
(T
)
936 and then not (In_Package_Body
(Scope
(T
))
937 or else In_Private_Part
(Scope
(T
)))
939 Set_Is_Remote_Call_Interface
940 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
942 (T
, Is_Remote_Types
(Scope
(T
)));
944 end Validate_Access_Type_Declaration
;
946 ----------------------------
947 -- Validate_Ancestor_Part --
948 ----------------------------
950 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
951 A
: constant Node_Id
:= Ancestor_Part
(N
);
952 T
: constant Entity_Id
:= Entity
(A
);
955 if In_Preelaborated_Unit
956 and then not In_Subprogram_Or_Concurrent_Unit
957 and then (not Inside_A_Generic
958 or else Present
(Enclosing_Generic_Body
(N
)))
960 -- If the type is private, it must have the Ada 2005 pragma
961 -- Has_Preelaborable_Initialization.
963 -- The check is omitted within predefined units. This is probably
964 -- obsolete code to fix the Ada 95 weakness in this area ???
966 if Is_Private_Type
(T
)
967 and then not Has_Pragma_Preelab_Init
(T
)
968 and then not In_Internal_Unit
(N
)
971 ("private ancestor type not allowed in preelaborated unit", A
);
973 elsif Is_Record_Type
(T
) then
974 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
975 Check_Non_Static_Default_Expr
976 (Type_Definition
(Parent
(T
)), A
);
980 end Validate_Ancestor_Part
;
982 ----------------------------------------
983 -- Validate_Categorization_Dependency --
984 ----------------------------------------
986 procedure Validate_Categorization_Dependency
990 K
: constant Node_Kind
:= Nkind
(N
);
991 P
: Node_Id
:= Parent
(N
);
993 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
996 -- Only validate library units and subunits. For subunits, checks
997 -- concerning withed units apply to the parent compilation unit.
1004 and then not Is_Compilation_Unit
(U
)
1005 and then not Is_Child_Unit
(U
)
1011 if Nkind
(P
) /= N_Compilation_Unit
then
1015 -- Body of RCI unit does not need validation
1017 if Is_Remote_Call_Interface
(E
)
1018 and then Nkind
(N
) in N_Package_Body | N_Subprogram_Body
1023 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
1027 Entity_Of_Withed
: Entity_Id
;
1030 Item
:= First
(Context_Items
(P
));
1031 while Present
(Item
) loop
1032 if Nkind
(Item
) = N_With_Clause
1034 not (Implicit_With
(Item
)
1035 or else Limited_Present
(Item
)
1037 -- Skip if error already posted on the WITH clause (in
1038 -- which case the Name attribute may be invalid). In
1039 -- particular, this fixes the problem of hanging in the
1040 -- presence of a WITH clause on a child that is an
1041 -- illegal generic instantiation.
1043 or else Error_Posted
(Item
))
1047 -- Skip processing malformed trees
1049 and then Nkind
(Name
(Item
)) not in N_Has_Entity
)
1051 Entity_Of_Withed
:= Entity
(Name
(Item
));
1052 Check_Categorization_Dependencies
1053 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
1060 -- Child depends on parent; therefore parent should also be categorized
1061 -- and satisfy the dependency hierarchy.
1063 -- Check if N is a child spec
1065 if (K
in N_Generic_Declaration
or else
1066 K
in N_Generic_Instantiation
or else
1067 K
in N_Generic_Renaming_Declaration
or else
1068 K
= N_Package_Declaration
or else
1069 K
= N_Package_Renaming_Declaration
or else
1070 K
= N_Subprogram_Declaration
or else
1071 K
= N_Subprogram_Renaming_Declaration
)
1072 and then Present
(Parent_Spec
(N
))
1074 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
1076 -- Verify that public child of an RCI library unit must also be an
1077 -- RCI library unit (RM E.2.3(15)).
1079 if Is_Remote_Call_Interface
(Scope
(E
))
1080 and then not Private_Present
(P
)
1081 and then not Is_Remote_Call_Interface
(E
)
1084 ("public child of 'R'C'I unit must also be 'R'C'I unit", N
);
1087 end Validate_Categorization_Dependency
;
1089 --------------------------------
1090 -- Validate_Controlled_Object --
1091 --------------------------------
1093 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
1095 -- Don't need this check in Ada 2005 mode, where this is all taken
1096 -- care of by the mechanism for Preelaborable Initialization.
1098 if Ada_Version
>= Ada_2005
then
1102 -- For now, never apply this check for internal GNAT units, since we
1103 -- have a number of cases in the library where we are stuck with objects
1104 -- of this type, and the RM requires Preelaborate.
1106 -- For similar reasons, we only do this check for source entities, since
1107 -- we generate entities of this type in some situations.
1109 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1110 -- We have to enforce them for RM compatibility, but we have no trouble
1111 -- accepting these objects and doing the right thing. Note that there is
1112 -- no requirement that Preelaborate not actually generate any code.
1114 if In_Preelaborated_Unit
1115 and then not Debug_Flag_PP
1116 and then Comes_From_Source
(E
)
1117 and then not In_Internal_Unit
(E
)
1118 and then (not Inside_A_Generic
1119 or else Present
(Enclosing_Generic_Body
(E
)))
1120 and then not Is_Protected_Type
(Etype
(E
))
1123 ("library level controlled object not allowed in " &
1124 "preelaborated unit", E
);
1126 end Validate_Controlled_Object
;
1128 --------------------------------------
1129 -- Validate_Null_Statement_Sequence --
1130 --------------------------------------
1132 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
1136 if In_Preelaborated_Unit
then
1137 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
1138 while Present
(Item
) loop
1139 if Nkind
(Item
) /= N_Label
1140 and then Nkind
(Item
) /= N_Null_Statement
1142 -- In GNAT mode, this is a warning, allowing the run-time
1143 -- to judiciously bypass this error condition.
1145 Error_Msg_Warn
:= GNAT_Mode
;
1147 ("<<statements not allowed in preelaborated unit", Item
);
1155 end Validate_Null_Statement_Sequence
;
1157 ---------------------------------
1158 -- Validate_Object_Declaration --
1159 ---------------------------------
1161 procedure Validate_Object_Declaration
(N
: Node_Id
) is
1162 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1163 E
: constant Node_Id
:= Expression
(N
);
1164 Odf
: constant Node_Id
:= Object_Definition
(N
);
1165 T
: constant Entity_Id
:= Etype
(Id
);
1168 -- Verify that any access to subprogram object does not have in its
1169 -- subprogram profile access type parameters or limited parameters
1170 -- without Read and Write attributes (E.2.3(13)).
1172 Validate_RCI_Subprogram_Declaration
(N
);
1174 -- Check that if we are in preelaborated elaboration code, then we
1175 -- do not have an instance of a default initialized private, task or
1176 -- protected object declaration which would violate (RM 10.2.1(9)).
1177 -- Note that constants are never default initialized (and the test
1178 -- below also filters out deferred constants). A variable is default
1179 -- initialized if it does *not* have an initialization expression.
1181 -- Filter out cases that are not declaration of a variable from source
1183 if Nkind
(N
) /= N_Object_Declaration
1184 or else Constant_Present
(N
)
1185 or else not Comes_From_Source
(Id
)
1190 -- Exclude generic specs from the checks (this will get rechecked
1191 -- on instantiations).
1193 if Inside_A_Generic
and then No
(Enclosing_Generic_Body
(Id
)) then
1197 -- Required checks for declaration that is in a preelaborated package
1198 -- and is not within some subprogram.
1200 if In_Preelaborated_Unit
1201 and then not In_Subprogram_Or_Concurrent_Unit
1203 -- Check for default initialized variable case. Note that in
1204 -- accordance with (RM B.1(24)) imported objects are not subject to
1205 -- default initialization.
1206 -- If the initialization does not come from source and is an
1207 -- aggregate, it is a static initialization that replaces an
1208 -- implicit call, and must be treated as such.
1211 and then (Comes_From_Source
(E
) or else Nkind
(E
) /= N_Aggregate
)
1215 elsif Is_Imported
(Id
) then
1220 Ent
: Entity_Id
:= T
;
1223 -- An array whose component type is a record with nonstatic
1224 -- default expressions is a violation, so we get the array's
1227 if Is_Array_Type
(Ent
) then
1229 Comp_Type
: Entity_Id
;
1232 Comp_Type
:= Component_Type
(Ent
);
1233 while Is_Array_Type
(Comp_Type
) loop
1234 Comp_Type
:= Component_Type
(Comp_Type
);
1241 -- Object decl. that is of record type and has no default expr.
1242 -- should check if there is any non-static default expression
1243 -- in component decl. of the record type decl.
1245 if Is_Record_Type
(Ent
) then
1246 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1247 Check_Non_Static_Default_Expr
1248 (Type_Definition
(Parent
(Ent
)), N
);
1250 elsif Nkind
(Odf
) = N_Subtype_Indication
1251 and then not Is_Array_Type
(T
)
1252 and then not Is_Private_Type
(T
)
1254 Check_Non_Static_Default_Expr
(Type_Definition
1255 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1259 -- Check for invalid use of private object. Note that Ada 2005
1260 -- AI-161 modifies the rules for Ada 2005, including the use of
1261 -- the new pragma Preelaborable_Initialization.
1263 if Is_Private_Type
(Ent
)
1264 or else Depends_On_Private
(Ent
)
1266 -- Case where type has preelaborable initialization which
1267 -- means that a pragma Preelaborable_Initialization was
1268 -- given for the private type.
1270 if Relaxed_RM_Semantics
then
1272 -- In relaxed mode, do not issue these messages, this
1273 -- is basically similar to the GNAT_Mode test below.
1277 elsif Has_Preelaborable_Initialization
(Ent
) then
1279 -- But for the predefined units, we will ignore this
1280 -- status unless we are in Ada 2005 mode since we want
1281 -- Ada 95 compatible behavior, in which the entities
1282 -- marked with this pragma in the predefined library are
1283 -- not treated specially.
1285 if Ada_Version
< Ada_2005
then
1287 ("private object not allowed in preelaborated unit",
1289 Error_Msg_N
("\(would be legal in Ada 2005 mode)", N
);
1292 -- Type does not have preelaborable initialization
1295 -- We allow this when compiling in GNAT mode to make life
1296 -- easier for some cases where it would otherwise be hard
1297 -- to be exactly valid Ada.
1299 if not GNAT_Mode
then
1301 ("private object not allowed in preelaborated unit",
1304 -- Add a message if it would help to provide a pragma
1305 -- Preelaborable_Initialization on the type of the
1306 -- object (which would make it legal in Ada 2005).
1308 -- If the type has no full view (generic type, or
1309 -- previous error), the warning does not apply.
1311 if Is_Private_Type
(Ent
)
1312 and then Present
(Full_View
(Ent
))
1314 Has_Preelaborable_Initialization
(Full_View
(Ent
))
1316 Error_Msg_Sloc
:= Sloc
(Ent
);
1318 if Ada_Version
>= Ada_2005
then
1320 ("\would be legal if pragma Preelaborable_" &
1321 "Initialization given for & #", N
, Ent
);
1324 ("\would be legal in Ada 2005 if pragma " &
1325 "Preelaborable_Initialization given for & #",
1332 -- Access to Task or Protected type
1334 elsif Is_Entity_Name
(Odf
)
1335 and then Present
(Etype
(Odf
))
1336 and then Is_Access_Type
(Etype
(Odf
))
1338 Ent
:= Designated_Type
(Etype
(Odf
));
1340 elsif Is_Entity_Name
(Odf
) then
1341 Ent
:= Entity
(Odf
);
1343 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1344 Ent
:= Etype
(Subtype_Mark
(Odf
));
1346 elsif Nkind
(Odf
) = N_Constrained_Array_Definition
then
1347 Ent
:= Component_Type
(T
);
1350 if Is_Task_Type
(Ent
)
1351 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1354 ("concurrent object not allowed in preelaborated unit",
1361 -- Non-static discriminants not allowed in preelaborated unit.
1362 -- Objects of a controlled type with a user-defined Initialize
1363 -- are forbidden as well.
1365 if Is_Record_Type
(Etype
(Id
)) then
1367 ET
: constant Entity_Id
:= Etype
(Id
);
1368 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1372 if Has_Discriminants
(ET
) and then Present
(EE
) then
1375 if Nkind
(PEE
) = N_Full_Type_Declaration
1376 and then not Static_Discriminant_Expr
1377 (Discriminant_Specifications
(PEE
))
1380 ("non-static discriminant in preelaborated unit",
1385 -- For controlled type or type with controlled component, check
1386 -- preelaboration flag, as there may be a non-null Initialize
1387 -- primitive. For language versions earlier than Ada 2005,
1388 -- there is no notion of preelaborable initialization, and
1389 -- Validate_Controlled_Object is used to enforce rules for
1390 -- controlled objects.
1392 if (Is_Controlled
(ET
) or else Has_Controlled_Component
(ET
))
1393 and then Ada_Version
>= Ada_2005
1394 and then not Has_Preelaborable_Initialization
(ET
)
1397 ("controlled type& does not have"
1398 & " preelaborable initialization", N
, ET
);
1405 -- A pure library_item must not contain the declaration of any variable
1406 -- except within a subprogram, generic subprogram, task unit, or
1407 -- protected unit (RM 10.2.1(16)).
1409 if In_Pure_Unit
and then not In_Subprogram_Task_Protected_Unit
then
1410 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1412 elsif not In_Private_Part
(Id
) then
1414 -- The visible part of an RCI library unit must not contain the
1415 -- declaration of a variable (RM E.1.3(9)).
1417 if In_RCI_Declaration
then
1418 Error_Msg_N
("visible variable not allowed in 'R'C'I unit", N
);
1420 -- The visible part of a Shared Passive library unit must not contain
1421 -- the declaration of a variable (RM E.2.2(7)).
1423 elsif In_RT_Declaration
then
1425 ("visible variable not allowed in remote types unit", N
);
1428 end Validate_Object_Declaration
;
1430 -----------------------------
1431 -- Validate_RACW_Primitive --
1432 -----------------------------
1434 procedure Validate_RACW_Primitive
1438 procedure Illegal_Remote_Subp
(Msg
: String; N
: Node_Id
);
1439 -- Diagnose illegality on N. If RACW is present, report the error on it
1440 -- rather than on N.
1442 -------------------------
1443 -- Illegal_Remote_Subp --
1444 -------------------------
1446 procedure Illegal_Remote_Subp
(Msg
: String; N
: Node_Id
) is
1448 if Present
(RACW
) then
1449 if not Error_Posted
(RACW
) then
1451 ("illegal remote access to class-wide type&", RACW
);
1454 Error_Msg_Sloc
:= Sloc
(N
);
1455 Error_Msg_NE
("\\" & Msg
& " in primitive& #", RACW
, Subp
);
1458 Error_Msg_NE
(Msg
& " in remote subprogram&", N
, Subp
);
1460 end Illegal_Remote_Subp
;
1464 Param_Spec
: Node_Id
;
1465 Param_Type
: Entity_Id
;
1467 -- Start of processing for Validate_RACW_Primitive
1470 -- Check return type
1472 if Ekind
(Subp
) = E_Function
then
1473 Rtyp
:= Etype
(Subp
);
1475 -- AI05-0101 (Binding Interpretation): The result type of a remote
1476 -- function must either support external streaming or be a
1477 -- controlling access result type.
1479 if Has_Controlling_Result
(Subp
) then
1482 elsif Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
1483 Illegal_Remote_Subp
("anonymous access result", Rtyp
);
1485 elsif Is_Limited_Type
(Rtyp
) then
1486 if No
(TSS
(Rtyp
, TSS_Stream_Read
))
1488 No
(TSS
(Rtyp
, TSS_Stream_Write
))
1491 ("limited return type must have Read and Write attributes",
1493 Explain_Limited_Type
(Rtyp
, Parent
(Subp
));
1496 -- Check that the return type supports external streaming
1498 elsif No_External_Streaming
(Rtyp
)
1499 and then not Error_Posted
(Rtyp
)
1501 Illegal_Remote_Subp
("return type containing non-remote access "
1502 & "must have Read and Write attributes",
1507 Param
:= First_Formal
(Subp
);
1508 while Present
(Param
) loop
1510 -- Now find out if this parameter is a controlling parameter
1512 Param_Spec
:= Parent
(Param
);
1513 Param_Type
:= Etype
(Param
);
1515 if Is_Controlling_Formal
(Param
) then
1517 -- It is a controlling parameter, so specific checks below do not
1522 elsif Ekind
(Param_Type
) in E_Anonymous_Access_Type
1523 | E_Anonymous_Access_Subprogram_Type
1525 -- From RM E.2.2(14), no anonymous access parameter other than
1526 -- controlling ones may be used (because an anonymous access
1527 -- type never supports external streaming).
1530 ("non-controlling access parameter", Param_Spec
);
1532 elsif No_External_Streaming
(Param_Type
)
1533 and then not Error_Posted
(Param_Type
)
1535 Illegal_Remote_Subp
("formal parameter in remote subprogram must "
1536 & "support external streaming", Param_Spec
);
1539 -- Check next parameter in this subprogram
1541 Next_Formal
(Param
);
1543 end Validate_RACW_Primitive
;
1545 ------------------------------
1546 -- Validate_RACW_Primitives --
1547 ------------------------------
1549 procedure Validate_RACW_Primitives
(T
: Entity_Id
) is
1550 Desig_Type
: Entity_Id
;
1551 Primitive_Subprograms
: Elist_Id
;
1552 Subprogram_Elmt
: Elmt_Id
;
1553 Subprogram
: Entity_Id
;
1556 Desig_Type
:= Etype
(Designated_Type
(T
));
1558 -- No action needed for concurrent types
1560 if Is_Concurrent_Type
(Desig_Type
) then
1564 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1566 Subprogram_Elmt
:= First_Elmt
(Primitive_Subprograms
);
1567 while Subprogram_Elmt
/= No_Elmt
loop
1568 Subprogram
:= Node
(Subprogram_Elmt
);
1570 if Is_Predefined_Dispatching_Operation
(Subprogram
)
1571 or else Is_Hidden
(Subprogram
)
1573 goto Next_Subprogram
;
1576 Validate_RACW_Primitive
(Subp
=> Subprogram
, RACW
=> T
);
1579 Next_Elmt
(Subprogram_Elmt
);
1581 end Validate_RACW_Primitives
;
1583 -------------------------------
1584 -- Validate_RCI_Declarations --
1585 -------------------------------
1587 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1591 E
:= First_Entity
(P
);
1592 while Present
(E
) loop
1593 if Comes_From_Source
(E
) then
1594 if Is_Limited_Type
(E
) then
1596 ("limited type not allowed in 'R'C'I unit", Parent
(E
));
1597 Explain_Limited_Type
(E
, Parent
(E
));
1599 elsif Ekind
(E
) in E_Generic_Function
1601 | E_Generic_Procedure
1603 Error_Msg_N
("generic declaration not allowed in 'R'C'I unit",
1606 elsif (Ekind
(E
) = E_Function
or else Ekind
(E
) = E_Procedure
)
1607 and then Has_Pragma_Inline
(E
)
1610 ("inlined subprogram not allowed in 'R'C'I unit", Parent
(E
));
1612 -- Inner packages that are renamings need not be checked. Generic
1613 -- RCI packages are subject to the checks, but entities that come
1614 -- from formal packages are not part of the visible declarations
1615 -- of the package and are not checked.
1617 elsif Ekind
(E
) = E_Package
then
1618 if Present
(Renamed_Entity
(E
)) then
1621 elsif Ekind
(P
) /= E_Generic_Package
1622 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1623 Generic_Formal_Declarations
1624 (Unit_Declaration_Node
(P
))
1626 Validate_RCI_Declarations
(E
);
1633 end Validate_RCI_Declarations
;
1635 -----------------------------------------
1636 -- Validate_RCI_Subprogram_Declaration --
1637 -----------------------------------------
1639 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1640 K
: constant Node_Kind
:= Nkind
(N
);
1642 Id
: constant Entity_Id
:= Defining_Entity
(N
);
1643 Param_Spec
: Node_Id
;
1644 Param_Type
: Entity_Id
;
1645 Error_Node
: Node_Id
:= N
;
1648 -- This procedure enforces rules on subprogram and access to subprogram
1649 -- declarations in RCI units. These rules do not apply to expander
1650 -- generated routines, which are not remote subprograms. It is called:
1652 -- 1. from Analyze_Subprogram_Declaration.
1653 -- 2. from Validate_Object_Declaration (access to subprogram).
1655 if not (Comes_From_Source
(N
)
1656 and then In_RCI_Declaration
1657 and then not In_Private_Part
(Scope
(Id
)))
1662 if K
= N_Subprogram_Declaration
then
1663 Profile
:= Parameter_Specifications
(Specification
(N
));
1666 pragma Assert
(K
= N_Object_Declaration
);
1668 -- The above assertion is dubious, the visible declarations of an
1669 -- RCI unit never contain an object declaration, this should be an
1670 -- ACCESS-to-object declaration???
1672 if Nkind
(Id
) = N_Defining_Identifier
1673 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1674 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1677 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1683 -- Iterate through the parameter specification list, checking that
1684 -- no access parameter and no limited type parameter in the list.
1687 if Present
(Profile
) then
1688 Param_Spec
:= First
(Profile
);
1689 while Present
(Param_Spec
) loop
1690 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1692 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1693 if K
= N_Subprogram_Declaration
then
1694 Error_Node
:= Param_Spec
;
1697 -- Report error only if declaration is in source program
1699 if Comes_From_Source
(Id
) then
1701 ("subprogram in 'R'C'I unit cannot have access parameter",
1705 -- For a limited private type parameter, we check only the private
1706 -- declaration and ignore full type declaration, unless this is
1707 -- the only declaration for the type, e.g., as a limited record.
1709 elsif No_External_Streaming
(Param_Type
) then
1710 if K
= N_Subprogram_Declaration
then
1711 Error_Node
:= Param_Spec
;
1715 ("formal of remote subprogram& "
1716 & "must support external streaming",
1718 if Is_Limited_Type
(Param_Type
) then
1719 Explain_Limited_Type
(Param_Type
, Error_Node
);
1727 if Ekind
(Id
) = E_Function
1728 and then Ekind
(Etype
(Id
)) = E_Anonymous_Access_Type
1729 and then Comes_From_Source
(Id
)
1732 ("function in 'R'C'I unit cannot have access result",
1735 end Validate_RCI_Subprogram_Declaration
;
1737 ----------------------------------------------------
1738 -- Validate_Remote_Access_Object_Type_Declaration --
1739 ----------------------------------------------------
1741 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1742 Direct_Designated_Type
: Entity_Id
;
1743 Desig_Type
: Entity_Id
;
1746 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1747 -- the given node is N_Access_To_Object_Definition.
1749 if not Comes_From_Source
(T
)
1750 or else (not In_RCI_Declaration
and then not In_RT_Declaration
)
1755 -- An access definition in the private part of a package is not a
1756 -- remote access type. Restrictions related to external streaming
1757 -- support for non-remote access types are enforced elsewhere. Note
1758 -- that In_Private_Part is never set on type entities: check flag
1759 -- on enclosing scope.
1761 if In_Private_Part
(Scope
(T
)) then
1765 -- Check RCI or RT unit type declaration. It may not contain the
1766 -- declaration of an access-to-object type unless it is a general access
1767 -- type that designates a class-wide limited private type or subtype.
1768 -- There are also constraints on the primitive subprograms of the
1769 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1771 if Ekind
(T
) /= E_General_Access_Type
1772 or else not Is_Class_Wide_Type
(Designated_Type
(T
))
1774 if In_RCI_Declaration
then
1776 ("error in access type in Remote_Call_Interface unit", T
);
1779 ("error in access type in Remote_Types unit", T
);
1782 Error_Msg_N
("\must be general access to class-wide type", T
);
1786 Direct_Designated_Type
:= Designated_Type
(T
);
1787 Desig_Type
:= Etype
(Direct_Designated_Type
);
1789 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type???
1791 if not Is_Valid_Remote_Object_Type
(Desig_Type
) then
1793 ("error in designated type of remote access to class-wide type", T
);
1795 ("\must be tagged limited private or private extension", T
);
1798 end Validate_Remote_Access_Object_Type_Declaration
;
1800 -----------------------------------------------
1801 -- Validate_Remote_Access_To_Class_Wide_Type --
1802 -----------------------------------------------
1804 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1805 K
: constant Node_Kind
:= Nkind
(N
);
1806 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1810 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1811 -- of class-wide limited private types.
1813 -- Storage_Pool and Storage_Size are not defined for such types
1815 -- The expected type of allocator must not be such a type.
1817 -- The actual parameter of generic instantiation must not be such a
1818 -- type if the formal parameter is of an access type.
1820 -- On entry, there are several cases:
1822 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1823 -- either Storage_Pool or Storage_Size.
1825 -- 2. called from exp_ch4 Expand_N_Allocator
1827 -- 3. called from sem_ch4 Analyze_Explicit_Dereference
1829 -- 4. called from sem_res Resolve_Actuals
1831 if K
= N_Attribute_Definition_Clause
then
1832 E
:= Etype
(Entity
(N
));
1834 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1835 Error_Msg_Name_1
:= Chars
(N
);
1837 ("cannot specify% aspect for a remote operand", N
);
1841 elsif K
= N_Attribute_Reference
then
1842 E
:= Etype
(Prefix
(N
));
1844 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1845 Error_Msg_N
("incorrect attribute of remote operand", N
);
1849 elsif K
= N_Allocator
then
1852 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1853 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1857 -- This subprogram also enforces the checks in E.2.2(13). A value of
1858 -- such type must not be dereferenced unless as controlling operand of
1859 -- a dispatching call. Explicit dereferences not coming from source are
1860 -- exempted from this checking because the expander produces them in
1861 -- some cases (such as for tag checks on dispatching calls with multiple
1862 -- controlling operands). However we do check in the case of an implicit
1863 -- dereference that is expanded to an explicit dereference (hence the
1864 -- test of whether Original_Node (N) comes from source).
1866 elsif K
= N_Explicit_Dereference
1867 and then Comes_From_Source
(Original_Node
(N
))
1869 E
:= Etype
(Prefix
(N
));
1871 -- If the class-wide type is not a remote one, the restrictions
1874 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1878 -- If we have a true dereference that comes from source and that
1879 -- is a controlling argument for a dispatching call, accept it.
1881 if Is_Actual_Parameter
(N
) and then Is_Controlling_Actual
(N
) then
1885 -- If we are just within a procedure or function call and the
1886 -- dereference has not been analyzed, return because this procedure
1887 -- will be called again from sem_res Resolve_Actuals. The same can
1888 -- apply in the case of dereference that is the prefix of a selected
1889 -- component, which can be a call given in prefixed form.
1891 if (Is_Actual_Parameter
(N
) or else PK
= N_Selected_Component
)
1892 and then not Analyzed
(N
)
1897 -- We must allow expanded code to generate a reference to the tag of
1898 -- the designated object (may be either the actual tag, or the stub
1899 -- tag in the case of a remote object).
1901 if PK
= N_Selected_Component
1902 and then Is_Tag
(Entity
(Selector_Name
(Parent
(N
))))
1908 ("invalid dereference of a remote access-to-class-wide value", N
);
1910 end Validate_Remote_Access_To_Class_Wide_Type
;
1912 ------------------------------------------
1913 -- Validate_Remote_Type_Type_Conversion --
1914 ------------------------------------------
1916 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1917 S
: constant Entity_Id
:= Etype
(N
);
1918 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1921 -- This test is required in the case where a conversion appears inside a
1922 -- normal package, it does not necessarily have to be inside an RCI,
1923 -- Remote_Types unit (RM E.2.2(9,12)).
1925 if Is_Remote_Access_To_Subprogram_Type
(E
)
1926 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1929 ("incorrect conversion of remote operand to local type", N
);
1932 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1933 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1936 ("incorrect conversion of local operand to remote type", N
);
1939 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1940 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1943 ("incorrect conversion of remote operand to local type", N
);
1947 -- If a local access type is converted into a RACW type, then the
1948 -- current unit has a pointer that may now be exported to another
1951 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1952 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1954 Set_Has_RACW
(Current_Sem_Unit
);
1956 end Validate_Remote_Type_Type_Conversion
;
1958 -------------------------------
1959 -- Validate_RT_RAT_Component --
1960 -------------------------------
1962 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1963 Spec
: constant Node_Id
:= Specification
(N
);
1964 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1967 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1969 function Stream_Attributes_Available
(Typ
: Entity_Id
) return Boolean;
1970 -- True if any stream attribute is available for Typ
1972 ---------------------------------
1973 -- Stream_Attributes_Available --
1974 ---------------------------------
1976 function Stream_Attributes_Available
(Typ
: Entity_Id
) return Boolean
1979 return Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
1981 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
1983 Stream_Attribute_Available
(Typ
, TSS_Stream_Input
)
1985 Stream_Attribute_Available
(Typ
, TSS_Stream_Output
);
1986 end Stream_Attributes_Available
;
1988 -- Start of processing for Validate_RT_RAT_Component
1991 if not Is_Remote_Types
(Name_U
) then
1995 Typ
:= First_Entity
(Name_U
);
1996 while Present
(Typ
) and then Typ
/= First_Priv_Ent
loop
1997 U_Typ
:= Underlying_Type
(Base_Type
(Typ
));
2003 if Comes_From_Source
(Typ
) and then Is_Type
(Typ
)
2004 and then Ekind
(Typ
) /= E_Incomplete_Type
2006 -- Check that the type can be meaningfully transmitted to another
2007 -- partition (E.2.2(8)).
2009 if (Ada_Version
< Ada_2005
and then Has_Non_Remote_Access
(U_Typ
))
2010 or else (Stream_Attributes_Available
(Typ
)
2011 and then No_External_Streaming
(U_Typ
))
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 entry
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
2116 function Is_Primary
(N
: Node_Id
) return Boolean;
2117 -- Determine whether node is syntactically a primary in an expression
2118 -- This function should probably be somewhere else ???
2120 -- Also it does not do what it says, e.g if N is a binary operator
2121 -- whose parent is a binary operator, Is_Primary returns True ???
2127 function Is_Primary
(N
: Node_Id
) return Boolean is
2128 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
2133 | N_Component_Association
2134 | N_Index_Or_Discriminant_Constraint
2141 when N_Attribute_Reference
=>
2143 Attr
: constant Name_Id
:= Attribute_Name
(Parent
(N
));
2146 return Attr
/= Name_Address
2147 and then Attr
/= Name_Access
2148 and then Attr
/= Name_Unchecked_Access
2149 and then Attr
/= Name_Unrestricted_Access
;
2152 when N_Indexed_Component
=>
2153 return N
/= Prefix
(Parent
(N
)) or else Is_Primary
(Parent
(N
));
2155 when N_Qualified_Expression
2158 return Is_Primary
(Parent
(N
));
2160 when N_Assignment_Statement
2161 | N_Object_Declaration
2163 return N
= Expression
(Parent
(N
));
2165 when N_Selected_Component
=>
2166 return Is_Primary
(Parent
(N
));
2173 -- Start of processing for Validate_Static_Object_Name
2176 if not In_Preelaborated_Unit
2177 or else not Comes_From_Source
(N
)
2178 or else In_Subprogram_Or_Concurrent_Unit
2179 or else Ekind
(Current_Scope
) = E_Block
2183 -- Filter out cases where primary is default in a component declaration,
2184 -- discriminant specification, or actual in a record type initialization
2187 -- Initialization call of internal types
2189 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
2191 if Present
(Parent
(Parent
(N
)))
2192 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
2197 if Nkind
(Name
(Parent
(N
))) = N_Identifier
2198 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
2204 -- Error if the name is a primary in an expression. The parent must not
2205 -- be an operator, or a selected component or an indexed component that
2206 -- is itself a primary. Entities that are actuals do not need to be
2207 -- checked, because the call itself will be diagnosed. Entities in a
2208 -- generic unit or within a preanalyzed expression are not checked:
2209 -- only their use in executable code matters.
2212 and then (not Inside_A_Generic
2213 or else Present
(Enclosing_Generic_Body
(N
)))
2214 and then not In_Spec_Expression
2216 if Ekind
(Entity
(N
)) = E_Variable
2217 or else Ekind
(Entity
(N
)) in Formal_Object_Kind
2219 Flag_Non_Static_Expr
2220 ("non-static object name in preelaborated unit", N
);
2222 -- Give an error for a reference to a nonstatic constant, unless the
2223 -- constant is in another GNAT library unit that is preelaborable.
2225 elsif Ekind
(Entity
(N
)) = E_Constant
2226 and then not Is_Static_Expression
(N
)
2229 Val
:= Constant_Value
(E
);
2231 if In_Internal_Unit
(N
)
2233 Enclosing_Comp_Unit_Node
(N
) /= Enclosing_Comp_Unit_Node
(E
)
2234 and then (Is_Preelaborated
(Scope
(E
))
2235 or else Is_Pure
(Scope
(E
))
2236 or else (Present
(Renamed_Object
(E
))
2237 and then Is_Entity_Name
(Renamed_Object
(E
))
2240 (Scope
(Renamed_Object
(E
)))
2243 (Scope
(Renamed_Object
(E
))))))
2247 -- If the value of the constant is a local variable that renames
2248 -- an aggregate, this is in itself legal. The aggregate may be
2249 -- expanded into a loop, but this does not affect preelaborability
2250 -- in itself. If some aggregate components are non-static, that is
2251 -- to say if they involve non static primaries, they will be
2252 -- flagged when analyzed.
2255 and then Is_Entity_Name
(Val
)
2256 and then Is_Array_Type
(Etype
(Val
))
2257 and then not Comes_From_Source
(Val
)
2258 and then Nkind
(Original_Node
(Val
)) = N_Aggregate
2262 -- This is the error case
2265 -- In GNAT mode or Relaxed RM Semantic mode, this is just a
2266 -- warning, to allow it to be judiciously turned off.
2267 -- Otherwise it is a real error.
2269 if GNAT_Mode
or Relaxed_RM_Semantics
then
2271 ("??non-static constant in preelaborated unit", N
);
2273 Flag_Non_Static_Expr
2274 ("non-static constant in preelaborated unit", N
);
2279 end Validate_Static_Object_Name
;