1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Tss
; use Exp_Tss
;
33 with Fname
; use Fname
;
35 with Nlists
; use Nlists
;
38 with Sem_Eval
; use Sem_Eval
;
39 with Sem_Util
; use Sem_Util
;
40 with Sinfo
; use Sinfo
;
41 with Snames
; use Snames
;
42 with Stand
; use Stand
;
44 package body Sem_Cat
is
46 -----------------------
47 -- Local Subprograms --
48 -----------------------
50 procedure Check_Categorization_Dependencies
51 (Unit_Entity
: Entity_Id
;
52 Depended_Entity
: Entity_Id
;
54 Is_Subunit
: Boolean);
55 -- This procedure checks that the categorization of a lib unit and that
56 -- of the depended unit satisfy dependency restrictions.
57 -- The depended_entity can be the entity in a with_clause item, in which
58 -- case Info_Node denotes that item. The depended_entity can also be the
59 -- parent unit of a child unit, in which case Info_Node is the declaration
60 -- of the child unit. The error message is posted on Info_Node, and is
61 -- specialized if Is_Subunit is true.
63 procedure Check_Non_Static_Default_Expr
66 -- Iterate through the component list of a record definition, check
67 -- that no component is declared with a nonstatic default value.
68 -- If a nonstatic default exists, report an error on Obj_Decl.
70 -- Iterate through the component list of a record definition, check
71 -- that no component is declared with a non-static default value.
73 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
74 -- Return True if the entity or one of its subcomponent is an access
75 -- type which does not have user-defined Read and Write attribute.
77 function In_RCI_Declaration
(N
: Node_Id
) return Boolean;
78 -- Determines if a declaration is within the visible part of a Remote
79 -- Call Interface compilation unit, for semantic checking purposes only,
80 -- (returns false within an instance and within the package body).
82 function In_RT_Declaration
return Boolean;
83 -- Determines if current scope is within a Remote Types compilation unit,
84 -- for semantic checking purposes.
86 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
87 -- Returns true if the entity is a non-remote access type
89 function In_Shared_Passive_Unit
return Boolean;
90 -- Determines if current scope is within a Shared Passive compilation unit
92 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
93 -- Iterate through the list of discriminants to check if any of them
94 -- contains non-static default expression, which is a violation in
95 -- a preelaborated library unit.
97 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
98 -- Check validity of declaration if RCI or RT unit. It should not contain
99 -- the declaration of an access-to-object type unless it is a
100 -- general access type that designates a class-wide limited
101 -- private type. There are also constraints about the primitive
102 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
104 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean;
105 -- Return True if E is a limited private type, or if E is a private
106 -- extension of a type whose parent verifies this property (hence the
107 -- recursive keyword).
109 ---------------------------------------
110 -- Check_Categorization_Dependencies --
111 ---------------------------------------
113 procedure Check_Categorization_Dependencies
114 (Unit_Entity
: Entity_Id
;
115 Depended_Entity
: Entity_Id
;
117 Is_Subunit
: Boolean)
119 N
: constant Node_Id
:= Info_Node
;
121 -- Here we define an enumeration type to represent categorization
122 -- types, ordered so that a unit with a given categorization can
123 -- only WITH units with lower or equal categorization type.
125 type Categorization
is
129 Remote_Call_Interface
,
133 Unit_Category
: Categorization
;
134 With_Category
: Categorization
;
136 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
137 -- Check categorization flags from entity, and return in the form
138 -- of a corresponding enumeration value.
140 ------------------------
141 -- Get_Categorization --
142 ------------------------
144 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
146 if Is_Preelaborated
(E
) then
147 return Preelaborated
;
148 elsif Is_Pure
(E
) then
150 elsif Is_Shared_Passive
(E
) then
151 return Shared_Passive
;
152 elsif Is_Remote_Types
(E
) then
154 elsif Is_Remote_Call_Interface
(E
) then
155 return Remote_Call_Interface
;
159 end Get_Categorization
;
161 -- Start of processing for Check_Categorization_Dependencies
164 -- Intrinsic subprograms are preelaborated, so do not impose any
165 -- categorization dependencies.
167 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
171 Unit_Category
:= Get_Categorization
(Unit_Entity
);
172 With_Category
:= Get_Categorization
(Depended_Entity
);
174 -- These messages are wanings in GNAT mode, to allow it to be
175 -- judiciously turned off. Otherwise it is a real error.
177 Error_Msg_Warn
:= GNAT_Mode
;
179 -- Check for possible error
181 if With_Category
> Unit_Category
then
183 -- Special case: Remote_Types and Remote_Call_Interface are allowed
184 -- to be with'ed in package body.
186 if (Unit_Category
= Remote_Types
187 or else Unit_Category
= Remote_Call_Interface
)
188 and then In_Package_Body
(Unit_Entity
)
192 -- Here we have an error
197 ("<subunit cannot depend on& " &
198 "(parent has wrong categorization)", N
, Depended_Entity
);
202 ("<cannot depend on& " &
203 "(wrong categorization)", N
, Depended_Entity
);
206 -- Add further explanation for common cases
208 case Unit_Category
is
211 ("\<pure unit cannot depend on non-pure unit",
214 when Preelaborated
=>
216 ("\<preelaborated unit cannot depend on " &
217 "non-preelaborated unit",
225 end Check_Categorization_Dependencies
;
227 -----------------------------------
228 -- Check_Non_Static_Default_Expr --
229 -----------------------------------
231 procedure Check_Non_Static_Default_Expr
236 Component_Decl
: Node_Id
;
239 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
240 Recdef
:= Record_Extension_Part
(Type_Def
);
250 -- Check that component declarations do not involve:
252 -- a. a non-static default expression, where the object is
253 -- declared to be default initialized.
255 -- b. a dynamic Itype (discriminants and constraints)
257 if Null_Present
(Recdef
) then
260 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
263 while Present
(Component_Decl
)
264 and then Nkind
(Component_Decl
) = N_Component_Declaration
266 if Present
(Expression
(Component_Decl
))
267 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
268 and then not Is_Static_Expression
(Expression
(Component_Decl
))
270 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
272 ("object in preelaborated unit has non-static default#",
275 -- Fix this later ???
277 -- elsif Has_Dynamic_Itype (Component_Decl) then
279 -- ("dynamic type discriminant," &
280 -- " constraint in preelaborated unit",
284 Next
(Component_Decl
);
286 end Check_Non_Static_Default_Expr
;
288 ---------------------------
289 -- In_Preelaborated_Unit --
290 ---------------------------
292 function In_Preelaborated_Unit
return Boolean is
293 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
294 Unit_Kind
: constant Node_Kind
:=
295 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
298 -- There are no constraints on body of remote_call_interface or
299 -- remote_types packages..
301 return (Unit_Entity
/= Standard_Standard
)
302 and then (Is_Preelaborated
(Unit_Entity
)
303 or else Is_Pure
(Unit_Entity
)
304 or else Is_Shared_Passive
(Unit_Entity
)
306 ((Is_Remote_Types
(Unit_Entity
)
307 or else Is_Remote_Call_Interface
(Unit_Entity
))
308 and then Ekind
(Unit_Entity
) = E_Package
309 and then Unit_Kind
/= N_Package_Body
310 and then not In_Package_Body
(Unit_Entity
)
311 and then not In_Instance
));
312 end In_Preelaborated_Unit
;
318 function In_Pure_Unit
return Boolean is
320 return Is_Pure
(Current_Scope
);
323 ------------------------
324 -- In_RCI_Declaration --
325 ------------------------
327 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
328 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
329 Unit_Kind
: constant Node_Kind
:=
330 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
333 -- There are no restrictions on the private part or body
336 return Is_Remote_Call_Interface
(Unit_Entity
)
337 and then (Ekind
(Unit_Entity
) = E_Package
338 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
339 and then Unit_Kind
/= N_Package_Body
340 and then List_Containing
(N
) =
342 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
343 and then not In_Package_Body
(Unit_Entity
)
344 and then not In_Instance
;
345 end In_RCI_Declaration
;
347 -----------------------
348 -- In_RT_Declaration --
349 -----------------------
351 function In_RT_Declaration
return Boolean is
352 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
353 Unit_Kind
: constant Node_Kind
:=
354 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
357 -- There are no restrictions on the body of a Remote Types unit
359 return Is_Remote_Types
(Unit_Entity
)
360 and then (Ekind
(Unit_Entity
) = E_Package
361 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
362 and then Unit_Kind
/= N_Package_Body
363 and then not In_Package_Body
(Unit_Entity
)
364 and then not In_Instance
;
365 end In_RT_Declaration
;
367 ----------------------------
368 -- In_Shared_Passive_Unit --
369 ----------------------------
371 function In_Shared_Passive_Unit
return Boolean is
372 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
375 return Is_Shared_Passive
(Unit_Entity
);
376 end In_Shared_Passive_Unit
;
378 ---------------------------------------
379 -- In_Subprogram_Task_Protected_Unit --
380 ---------------------------------------
382 function In_Subprogram_Task_Protected_Unit
return Boolean is
386 -- The following is to verify that a declaration is inside
387 -- subprogram, generic subprogram, task unit, protected unit.
388 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
390 -- Use scope chain to check successively outer scopes
396 Is_Generic_Subprogram
(E
)
398 Is_Concurrent_Type
(E
)
402 elsif E
= Standard_Standard
then
408 end In_Subprogram_Task_Protected_Unit
;
410 -------------------------------
411 -- Is_Non_Remote_Access_Type --
412 -------------------------------
414 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
416 return Is_Access_Type
(E
)
417 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
418 and then not Is_Remote_Access_To_Subprogram_Type
(E
);
419 end Is_Non_Remote_Access_Type
;
421 ------------------------------------
422 -- Is_Recursively_Limited_Private --
423 ------------------------------------
425 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean is
426 P
: constant Node_Id
:= Parent
(E
);
429 if Nkind
(P
) = N_Private_Type_Declaration
430 and then Is_Limited_Record
(E
)
433 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
434 return Is_Recursively_Limited_Private
(Etype
(E
));
435 elsif Nkind
(P
) = N_Formal_Type_Declaration
436 and then Ekind
(E
) = E_Record_Type_With_Private
437 and then Is_Generic_Type
(E
)
438 and then Is_Limited_Record
(E
)
444 end Is_Recursively_Limited_Private
;
446 ----------------------------------
447 -- Missing_Read_Write_Attribute --
448 ----------------------------------
450 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
451 Component
: Entity_Id
;
452 Component_Type
: Entity_Id
;
454 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
455 -- Return True if entity has Read and Write attributes
457 -------------------------------
458 -- Has_Read_Write_Attributes --
459 -------------------------------
461 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
462 Rep_Item
: Node_Id
:= First_Rep_Item
(E
);
463 Read_Attribute
: Boolean := False;
464 Write_Attribute
: Boolean := False;
467 -- We start from the declaration node and then loop until the end
468 -- of the list until we find those two attribute definition clauses.
470 while Present
(Rep_Item
) loop
471 if Chars
(Rep_Item
) = Name_Read
then
472 Read_Attribute
:= True;
473 elsif Chars
(Rep_Item
) = Name_Write
then
474 Write_Attribute
:= True;
477 if Read_Attribute
and Write_Attribute
then
481 Next_Rep_Item
(Rep_Item
);
485 end Has_Read_Write_Attributes
;
487 -- Start of processing for Missing_Read_Write_Attributes
490 if Has_Read_Write_Attributes
(E
) then
492 elsif Is_Non_Remote_Access_Type
(E
) then
496 if Is_Record_Type
(E
) then
497 Component
:= First_Entity
(E
);
498 while Present
(Component
) loop
499 Component_Type
:= Etype
(Component
);
501 if (Is_Non_Remote_Access_Type
(Component_Type
)
502 or else Is_Record_Type
(Component_Type
))
503 and then Missing_Read_Write_Attributes
(Component_Type
)
508 Next_Entity
(Component
);
513 end Missing_Read_Write_Attributes
;
515 -------------------------------------
516 -- Set_Categorization_From_Pragmas --
517 -------------------------------------
519 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
520 P
: constant Node_Id
:= Parent
(N
);
521 S
: constant Entity_Id
:= Current_Scope
;
523 procedure Set_Parents
(Visibility
: Boolean);
524 -- If this is a child instance, the parents are not immediately
525 -- visible during analysis. Make them momentarily visible so that
526 -- the argument of the pragma can be resolved properly, and reset
529 procedure Set_Parents
(Visibility
: Boolean) is
530 Par
: Entity_Id
:= Scope
(S
);
533 while Present
(Par
) and then Par
/= Standard_Standard
loop
534 Set_Is_Immediately_Visible
(Par
, Visibility
);
540 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
541 -- The purpose is to set categorization flags before analyzing the
542 -- unit itself, so as to diagnose violations of categorization as
543 -- we process each declaration, even though the pragma appears after
546 if Nkind
(P
) /= N_Compilation_Unit
then
551 PN
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
556 and then Is_Generic_Instance
(S
)
561 while Present
(PN
) loop
563 -- Skip implicit types that may have been introduced by
564 -- previous analysis.
566 if Nkind
(PN
) = N_Pragma
then
568 case Get_Pragma_Id
(Chars
(PN
)) is
569 when Pragma_All_Calls_Remote |
570 Pragma_Preelaborate |
572 Pragma_Remote_Call_Interface |
573 Pragma_Remote_Types |
574 Pragma_Shared_Passive
=> Analyze
(PN
);
582 and then Is_Generic_Instance
(S
)
588 end Set_Categorization_From_Pragmas
;
590 -----------------------------------
591 -- Set_Categorization_From_Scope --
592 -----------------------------------
594 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
595 Declaration
: Node_Id
:= Empty
;
596 Specification
: Node_Id
:= Empty
;
600 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
602 if not Is_Remote_Call_Interface
(E
) then
603 if Ekind
(E
) in Subprogram_Kind
then
604 Declaration
:= Unit_Declaration_Node
(E
);
607 or else Nkind
(Declaration
) = N_Subprogram_Body
608 or else Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
610 Specification
:= Corresponding_Spec
(Declaration
);
614 -- A subprogram body or renaming-as-body is a remote call
615 -- interface if it serves as the completion of a subprogram
616 -- declaration that is a remote call interface.
618 if Nkind
(Specification
) in N_Entity
then
619 Set_Is_Remote_Call_Interface
620 (E
, Is_Remote_Call_Interface
(Specification
));
622 -- A subprogram declaration is a remote call interface when it is
623 -- declared within the visible part of, or declared by, a library
624 -- unit declaration that is a remote call interface.
627 Set_Is_Remote_Call_Interface
628 (E
, Is_Remote_Call_Interface
(Scop
)
629 and then not (In_Private_Part
(Scop
)
630 or else In_Package_Body
(Scop
)));
634 Set_Is_Remote_Types
(E
, Is_Remote_Types
(Scop
));
635 end Set_Categorization_From_Scope
;
637 ------------------------------
638 -- Static_Discriminant_Expr --
639 ------------------------------
641 -- We need to accomodate a Why_Not_Static call somehow here ???
643 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
644 Discriminant_Spec
: Node_Id
;
647 Discriminant_Spec
:= First
(L
);
648 while Present
(Discriminant_Spec
) loop
649 if Present
(Expression
(Discriminant_Spec
))
650 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
655 Next
(Discriminant_Spec
);
659 end Static_Discriminant_Expr
;
661 --------------------------------------
662 -- Validate_Access_Type_Declaration --
663 --------------------------------------
665 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
666 Def
: constant Node_Id
:= Type_Definition
(N
);
671 -- Access to subprogram case
673 when N_Access_To_Subprogram_Definition
=>
675 -- A pure library_item must not contain the declaration of a
676 -- named access type, except within a subprogram, generic
677 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
679 -- This test is skipped in Ada 2005 (see AI-366)
681 if Ada_Version
< Ada_05
682 and then Comes_From_Source
(T
)
683 and then In_Pure_Unit
684 and then not In_Subprogram_Task_Protected_Unit
686 Error_Msg_N
("named access type not allowed in pure unit", T
);
689 -- Access to object case
691 when N_Access_To_Object_Definition
=>
692 if Comes_From_Source
(T
)
693 and then In_Pure_Unit
694 and then not In_Subprogram_Task_Protected_Unit
696 -- We can't give the message yet, since the type is not frozen
697 -- and in Ada 2005 mode, access types are allowed in pure units
698 -- if the type has no storage pool (see AI-366). So we set a
699 -- flag which will be checked at freeze time.
701 Set_Is_Pure_Unit_Access_Type
(T
);
704 -- Check for RCI or RT unit type declaration. It should not
705 -- contain the declaration of an access-to-object type unless it
706 -- is a general access type that designates a class-wide limited
707 -- private type. There are also constraints about the primitive
708 -- subprograms of the class-wide type.
710 Validate_Remote_Access_Object_Type_Declaration
(T
);
712 -- Check for shared passive unit type declaration. It should
713 -- not contain the declaration of access to class wide type,
714 -- access to task type and access to protected type with entry.
716 Validate_SP_Access_Object_Type_Decl
(T
);
722 -- Set categorization flag from package on entity as well, to allow
723 -- easy checks later on for required validations of RCI or RT units.
724 -- This is only done for entities that are in the original source.
726 if Comes_From_Source
(T
)
727 and then not (In_Package_Body
(Scope
(T
))
728 or else In_Private_Part
(Scope
(T
)))
730 Set_Is_Remote_Call_Interface
731 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
733 (T
, Is_Remote_Types
(Scope
(T
)));
735 end Validate_Access_Type_Declaration
;
737 ----------------------------
738 -- Validate_Ancestor_Part --
739 ----------------------------
741 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
742 A
: constant Node_Id
:= Ancestor_Part
(N
);
743 T
: constant Entity_Id
:= Entity
(A
);
746 if In_Preelaborated_Unit
747 and then not In_Subprogram_Or_Concurrent_Unit
748 and then (not Inside_A_Generic
749 or else Present
(Enclosing_Generic_Body
(N
)))
751 -- We relax the restriction of 10.2.1(9) within GNAT
752 -- units to allow packages such as Ada.Strings.Unbounded
753 -- to be implemented (i.p., Null_Unbounded_String).
754 -- (There are ACVC tests that check that the restriction
755 -- is enforced, but note that AI-161, once approved,
756 -- will relax the restriction prohibiting default-
757 -- initialized objects of private and controlled
760 if Is_Private_Type
(T
)
761 and then not Is_Internal_File_Name
762 (Unit_File_Name
(Get_Source_Unit
(N
)))
765 ("private ancestor type not allowed in preelaborated unit", A
);
767 elsif Is_Record_Type
(T
) then
768 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
769 Check_Non_Static_Default_Expr
770 (Type_Definition
(Parent
(T
)), A
);
774 end Validate_Ancestor_Part
;
776 ----------------------------------------
777 -- Validate_Categorization_Dependency --
778 ----------------------------------------
780 procedure Validate_Categorization_Dependency
784 K
: constant Node_Kind
:= Nkind
(N
);
785 P
: Node_Id
:= Parent
(N
);
787 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
790 -- Only validate library units and subunits. For subunits, checks
791 -- concerning withed units apply to the parent compilation unit.
798 and then not Is_Compilation_Unit
(U
)
799 and then not Is_Child_Unit
(U
)
806 if Nkind
(P
) /= N_Compilation_Unit
then
810 -- Body of RCI unit does not need validation
812 if Is_Remote_Call_Interface
(E
)
813 and then (Nkind
(N
) = N_Package_Body
814 or else Nkind
(N
) = N_Subprogram_Body
)
819 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
823 Entity_Of_Withed
: Entity_Id
;
826 Item
:= First
(Context_Items
(P
));
828 while Present
(Item
) loop
829 if Nkind
(Item
) = N_With_Clause
830 and then not (Implicit_With
(Item
)
831 or else Limited_Present
(Item
))
833 Entity_Of_Withed
:= Entity
(Name
(Item
));
834 Check_Categorization_Dependencies
835 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
842 -- Child depends on parent; therefore parent should also be categorized
843 -- and satify the dependency hierarchy.
845 -- Check if N is a child spec
847 if (K
in N_Generic_Declaration
or else
848 K
in N_Generic_Instantiation
or else
849 K
in N_Generic_Renaming_Declaration
or else
850 K
= N_Package_Declaration
or else
851 K
= N_Package_Renaming_Declaration
or else
852 K
= N_Subprogram_Declaration
or else
853 K
= N_Subprogram_Renaming_Declaration
)
854 and then Present
(Parent_Spec
(N
))
856 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
858 -- Verify that public child of an RCI library unit must also be an
859 -- RCI library unit (RM E.2.3(15)).
861 if Is_Remote_Call_Interface
(Scope
(E
))
862 and then not Private_Present
(P
)
863 and then not Is_Remote_Call_Interface
(E
)
865 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
868 end Validate_Categorization_Dependency
;
870 --------------------------------
871 -- Validate_Controlled_Object --
872 --------------------------------
874 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
876 -- For now, never apply this check for internal GNAT units, since we
877 -- have a number of cases in the library where we are stuck with objects
878 -- of this type, and the RM requires Preelaborate.
880 -- For similar reasons, we only do this check for source entities, since
881 -- we generate entities of this type in some situations.
883 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
884 -- We have to enforce them for RM compatibility, but we have no trouble
885 -- accepting these objects and doing the right thing. Note that there is
886 -- no requirement that Preelaborate not actually generate any code!
888 if In_Preelaborated_Unit
889 and then not Debug_Flag_PP
890 and then Comes_From_Source
(E
)
892 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
893 and then (not Inside_A_Generic
894 or else Present
(Enclosing_Generic_Body
(E
)))
895 and then not Is_Protected_Type
(Etype
(E
))
898 ("library level controlled object not allowed in " &
899 "preelaborated unit", E
);
901 end Validate_Controlled_Object
;
903 --------------------------------------
904 -- Validate_Null_Statement_Sequence --
905 --------------------------------------
907 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
911 if In_Preelaborated_Unit
then
912 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
914 while Present
(Item
) loop
915 if Nkind
(Item
) /= N_Label
916 and then Nkind
(Item
) /= N_Null_Statement
918 -- In GNAT mode, this is a warning, allowing the run-time
919 -- to judiciously bypass this error condition.
921 Error_Msg_Warn
:= GNAT_Mode
;
923 ("<statements not allowed in preelaborated unit", Item
);
931 end Validate_Null_Statement_Sequence
;
933 ---------------------------------
934 -- Validate_Object_Declaration --
935 ---------------------------------
937 procedure Validate_Object_Declaration
(N
: Node_Id
) is
938 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
939 E
: constant Node_Id
:= Expression
(N
);
940 Odf
: constant Node_Id
:= Object_Definition
(N
);
941 T
: constant Entity_Id
:= Etype
(Id
);
944 -- Verify that any access to subprogram object does not have in its
945 -- subprogram profile access type parameters or limited parameters
946 -- without Read and Write attributes (E.2.3(13)).
948 Validate_RCI_Subprogram_Declaration
(N
);
950 -- Check that if we are in preelaborated elaboration code, then we
951 -- do not have an instance of a default initialized private, task or
952 -- protected object declaration which would violate (RM 10.2.1(9)).
953 -- Note that constants are never default initialized (and the test
954 -- below also filters out deferred constants). A variable is default
955 -- initialized if it does *not* have an initialization expression.
957 -- Filter out cases that are not declaration of a variable from source
959 if Nkind
(N
) /= N_Object_Declaration
960 or else Constant_Present
(N
)
961 or else not Comes_From_Source
(Id
)
966 -- Exclude generic specs from the checks (this will get rechecked
967 -- on instantiations).
970 and then not Present
(Enclosing_Generic_Body
(Id
))
975 -- Required checks for declaration that is in a preelaborated
976 -- package and is not within some subprogram.
978 if In_Preelaborated_Unit
979 and then not In_Subprogram_Or_Concurrent_Unit
981 -- Check for default initialized variable case. Note that in
982 -- accordance with (RM B.1(24)) imported objects are not
983 -- subject to default initialization.
985 if No
(E
) and then not Is_Imported
(Id
) then
987 Ent
: Entity_Id
:= T
;
990 -- An array whose component type is a record with nonstatic
991 -- default expressions is a violation, so we get the array's
994 if Is_Array_Type
(Ent
) then
996 Comp_Type
: Entity_Id
:= Component_Type
(Ent
);
999 while Is_Array_Type
(Comp_Type
) loop
1000 Comp_Type
:= Component_Type
(Comp_Type
);
1007 -- Object decl. that is of record type and has no default expr.
1008 -- should check if there is any non-static default expression
1009 -- in component decl. of the record type decl.
1011 if Is_Record_Type
(Ent
) then
1012 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1013 Check_Non_Static_Default_Expr
1014 (Type_Definition
(Parent
(Ent
)), N
);
1016 elsif Nkind
(Odf
) = N_Subtype_Indication
1017 and then not Is_Array_Type
(T
)
1018 and then not Is_Private_Type
(T
)
1020 Check_Non_Static_Default_Expr
(Type_Definition
1021 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1025 -- We relax the restriction of 10.2.1(9) within GNAT
1026 -- units. (There are ACVC tests that check that the
1027 -- restriction is enforced, but note that AI-161,
1028 -- once approved, will relax the restriction prohibiting
1029 -- default-initialized objects of private types, and
1030 -- will recommend a pragma for marking private types.)
1032 if (Is_Private_Type
(Ent
)
1033 or else Depends_On_Private
(Ent
))
1034 and then not Is_Internal_File_Name
1035 (Unit_File_Name
(Get_Source_Unit
(N
)))
1038 ("private object not allowed in preelaborated unit", N
);
1041 -- Access to Task or Protected type
1043 elsif Is_Entity_Name
(Odf
)
1044 and then Present
(Etype
(Odf
))
1045 and then Is_Access_Type
(Etype
(Odf
))
1047 Ent
:= Designated_Type
(Etype
(Odf
));
1049 elsif Is_Entity_Name
(Odf
) then
1050 Ent
:= Entity
(Odf
);
1052 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1053 Ent
:= Etype
(Subtype_Mark
(Odf
));
1056 Nkind
(Odf
) = N_Constrained_Array_Definition
1058 Ent
:= Component_Type
(T
);
1064 if Is_Task_Type
(Ent
)
1065 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1068 ("concurrent object not allowed in preelaborated unit",
1075 -- Non-static discriminant not allowed in preelaborayted unit
1077 if Is_Record_Type
(Etype
(Id
)) then
1079 ET
: constant Entity_Id
:= Etype
(Id
);
1080 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1084 if Has_Discriminants
(ET
)
1085 and then Present
(EE
)
1089 if Nkind
(PEE
) = N_Full_Type_Declaration
1090 and then not Static_Discriminant_Expr
1091 (Discriminant_Specifications
(PEE
))
1094 ("non-static discriminant in preelaborated unit",
1102 -- A pure library_item must not contain the declaration of any
1103 -- variable except within a subprogram, generic subprogram, task
1104 -- unit or protected unit (RM 10.2.1(16)).
1107 and then not In_Subprogram_Task_Protected_Unit
1109 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1111 -- The visible part of an RCI library unit must not contain the
1112 -- declaration of a variable (RM E.1.3(9))
1114 elsif In_RCI_Declaration
(N
) then
1115 Error_Msg_N
("declaration of variable not allowed in rci unit", N
);
1117 -- The visible part of a Shared Passive library unit must not contain
1118 -- the declaration of a variable (RM E.2.2(7))
1120 elsif In_RT_Declaration
then
1122 ("variable declaration not allowed in remote types unit", N
);
1125 end Validate_Object_Declaration
;
1127 -------------------------------
1128 -- Validate_RCI_Declarations --
1129 -------------------------------
1131 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1135 E
:= First_Entity
(P
);
1136 while Present
(E
) loop
1137 if Comes_From_Source
(E
) then
1138 if Is_Limited_Type
(E
) then
1140 ("Limited type not allowed in rci unit", Parent
(E
));
1141 Explain_Limited_Type
(E
, Parent
(E
));
1143 elsif Ekind
(E
) = E_Generic_Function
1144 or else Ekind
(E
) = E_Generic_Package
1145 or else Ekind
(E
) = E_Generic_Procedure
1147 Error_Msg_N
("generic declaration not allowed in rci unit",
1150 elsif (Ekind
(E
) = E_Function
1151 or else Ekind
(E
) = E_Procedure
)
1152 and then Has_Pragma_Inline
(E
)
1155 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1157 -- Inner packages that are renamings need not be checked.
1158 -- Generic RCI packages are subject to the checks, but
1159 -- entities that come from formal packages are not part of the
1160 -- visible declarations of the package and are not checked.
1162 elsif Ekind
(E
) = E_Package
then
1163 if Present
(Renamed_Entity
(E
)) then
1166 elsif Ekind
(P
) /= E_Generic_Package
1167 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1168 Generic_Formal_Declarations
1169 (Unit_Declaration_Node
(P
))
1171 Validate_RCI_Declarations
(E
);
1178 end Validate_RCI_Declarations
;
1180 -----------------------------------------
1181 -- Validate_RCI_Subprogram_Declaration --
1182 -----------------------------------------
1184 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1185 K
: constant Node_Kind
:= Nkind
(N
);
1188 Param_Spec
: Node_Id
;
1189 Param_Type
: Entity_Id
;
1190 Base_Param_Type
: Entity_Id
;
1191 Base_Under_Type
: Entity_Id
;
1192 Type_Decl
: Node_Id
;
1193 Error_Node
: Node_Id
:= N
;
1196 -- There are two possible cases in which this procedure is called:
1198 -- 1. called from Analyze_Subprogram_Declaration.
1199 -- 2. called from Validate_Object_Declaration (access to subprogram).
1201 if not In_RCI_Declaration
(N
) then
1205 if K
= N_Subprogram_Declaration
then
1206 Profile
:= Parameter_Specifications
(Specification
(N
));
1208 else pragma Assert
(K
= N_Object_Declaration
);
1209 Id
:= Defining_Identifier
(N
);
1211 if Nkind
(Id
) = N_Defining_Identifier
1212 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1213 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1216 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1222 -- Iterate through the parameter specification list, checking that
1223 -- no access parameter and no limited type parameter in the list.
1226 if Present
(Profile
) then
1227 Param_Spec
:= First
(Profile
);
1229 while Present
(Param_Spec
) loop
1230 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1231 Type_Decl
:= Parent
(Param_Type
);
1233 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1235 if K
= N_Subprogram_Declaration
then
1236 Error_Node
:= Param_Spec
;
1239 -- Report error only if declaration is in source program
1241 if Comes_From_Source
1242 (Defining_Entity
(Specification
(N
)))
1245 ("subprogram in rci unit cannot have access parameter",
1249 -- For limited private type parameter, we check only the
1250 -- private declaration and ignore full type declaration,
1251 -- unless this is the only declaration for the type, eg.
1252 -- as a limited record.
1254 elsif Is_Limited_Type
(Param_Type
)
1255 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1257 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1258 and then not (Has_Private_Declaration
(Param_Type
))
1259 and then Comes_From_Source
(N
)))
1261 -- A limited parameter is legal only if user-specified Read and
1262 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1264 if No
(Full_View
(Param_Type
))
1265 and then Ekind
(Param_Type
) /= E_Record_Type
1267 -- Type does not have completion yet, so if declared in in
1268 -- the current RCI scope it is illegal, and will be flagged
1274 -- In Ada 95 the rules permit using a limited type that has
1275 -- user-specified Read and Write attributes that are specified
1276 -- in the private part of the package, whereas Ada 2005
1277 -- (AI-240) revises this to require the attributes to be
1278 -- "available" (implying that the attribute clauses must be
1279 -- visible to the RCI client). The Ada 95 rules violate the
1280 -- contract model for privacy, but we support both semantics
1281 -- for now for compatibility (note that ACATS test BXE2009
1282 -- checks a case that conforms to the Ada 95 rules but is
1283 -- illegal in Ada 2005).
1285 Base_Param_Type
:= Base_Type
(Param_Type
);
1286 Base_Under_Type
:= Base_Type
(Underlying_Type
1289 if (Ada_Version
< Ada_05
1291 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1293 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1295 (No
(TSS
(Base_Under_Type
, TSS_Stream_Read
))
1297 No
(TSS
(Base_Under_Type
, TSS_Stream_Write
))))
1299 (Ada_Version
>= Ada_05
1301 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1303 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1305 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1307 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Write
))))
1309 if K
= N_Subprogram_Declaration
then
1310 Error_Node
:= Param_Spec
;
1313 if Ada_Version
>= Ada_05
then
1315 ("limited parameter in rci unit "
1316 & "must have visible read/write attributes ",
1320 ("limited parameter in rci unit "
1321 & "must have read/write attributes ",
1324 Explain_Limited_Type
(Param_Type
, Error_Node
);
1331 end Validate_RCI_Subprogram_Declaration
;
1333 ----------------------------------------------------
1334 -- Validate_Remote_Access_Object_Type_Declaration --
1335 ----------------------------------------------------
1337 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1338 Direct_Designated_Type
: Entity_Id
;
1339 Desig_Type
: Entity_Id
;
1340 Primitive_Subprograms
: Elist_Id
;
1341 Subprogram
: Elmt_Id
;
1342 Subprogram_Node
: Node_Id
;
1344 Param_Spec
: Node_Id
;
1345 Param_Type
: Entity_Id
;
1348 -- We are called from Analyze_Type_Declaration, and the Nkind
1349 -- of the given node is N_Access_To_Object_Definition.
1351 if not Comes_From_Source
(T
)
1352 or else (not In_RCI_Declaration
(Parent
(T
))
1353 and then not In_RT_Declaration
)
1358 -- An access definition in the private part of a Remote Types package
1359 -- may be legal if it has user-defined Read and Write attributes. This
1360 -- will be checked at the end of the package spec processing.
1362 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1366 -- Check RCI or RT unit type declaration. It may not contain
1367 -- the declaration of an access-to-object type unless it is a
1368 -- general access type that designates a class-wide limited
1369 -- private type. There are also constraints about the primitive
1370 -- subprograms of the class-wide type (RM E.2.3(14)).
1372 if Ekind
(T
) /= E_General_Access_Type
1373 or else Ekind
(Designated_Type
(T
)) /= E_Class_Wide_Type
1375 if In_RCI_Declaration
(Parent
(T
)) then
1377 ("access type in Remote_Call_Interface unit must be " &
1378 "general access", T
);
1380 Error_Msg_N
("access type in Remote_Types unit must be " &
1381 "general access", T
);
1383 Error_Msg_N
("\to class-wide type", T
);
1387 Direct_Designated_Type
:= Designated_Type
(T
);
1388 Desig_Type
:= Etype
(Direct_Designated_Type
);
1390 if not Is_Recursively_Limited_Private
(Desig_Type
) then
1392 ("error in designated type of remote access to class-wide type", T
);
1394 ("\must be tagged limited private or private extension of type", T
);
1398 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1399 Subprogram
:= First_Elmt
(Primitive_Subprograms
);
1401 while Subprogram
/= No_Elmt
loop
1402 Subprogram_Node
:= Node
(Subprogram
);
1404 if not Comes_From_Source
(Subprogram_Node
) then
1405 goto Next_Subprogram
;
1408 Profile
:= Parameter_Specifications
(Parent
(Subprogram_Node
));
1410 -- Profile must exist, otherwise not primitive operation
1412 Param_Spec
:= First
(Profile
);
1413 while Present
(Param_Spec
) loop
1415 -- Now find out if this parameter is a controlling parameter
1417 Param_Type
:= Parameter_Type
(Param_Spec
);
1419 if (Nkind
(Param_Type
) = N_Access_Definition
1420 and then Etype
(Subtype_Mark
(Param_Type
)) = Desig_Type
)
1421 or else (Nkind
(Param_Type
) /= N_Access_Definition
1422 and then Etype
(Param_Type
) = Desig_Type
)
1424 -- It is a controlling parameter, so specific checks below
1430 Nkind
(Param_Type
) = N_Access_Definition
1432 -- From RM E.2.2(14), no access parameter other than
1433 -- controlling ones may be used.
1436 ("non-controlling access parameter", Param_Spec
);
1439 Is_Limited_Type
(Etype
(Defining_Identifier
(Param_Spec
)))
1441 -- Not a controlling parameter, so type must have Read
1442 -- and Write attributes.
1444 if Nkind
(Param_Type
) in N_Has_Etype
1445 and then Nkind
(Parent
(Etype
(Param_Type
))) =
1446 N_Private_Type_Declaration
1448 Param_Type
:= Etype
(Param_Type
);
1450 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1452 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1455 ("limited formal must have Read and Write attributes",
1457 Explain_Limited_Type
1458 (Etype
(Defining_Identifier
(Param_Spec
)), Param_Spec
);
1463 -- Check next parameter in this subprogram
1469 Next_Elmt
(Subprogram
);
1472 -- Now this is an RCI unit access-to-class-wide-limited-private type
1473 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1474 -- optimize later checks by avoiding tree traversal to find out if this
1475 -- entity is inside an RCI unit.
1477 Set_Is_Remote_Call_Interface
(T
);
1478 end Validate_Remote_Access_Object_Type_Declaration
;
1480 -----------------------------------------------
1481 -- Validate_Remote_Access_To_Class_Wide_Type --
1482 -----------------------------------------------
1484 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1485 K
: constant Node_Kind
:= Nkind
(N
);
1486 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1490 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1491 -- of class-wide limited private types.
1493 -- Storage_Pool and Storage_Size are not defined for such types
1495 -- The expected type of allocator must not not be such a type.
1497 -- The actual parameter of generic instantiation must not be such a
1498 -- type if the formal parameter is of an access type.
1500 -- On entry, there are five cases
1502 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1503 -- either Storage_Pool or Storage_Size.
1505 -- 2. called from exp_ch4 Expand_N_Allocator
1507 -- 3. called from sem_ch12 Analyze_Associations
1509 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1511 -- 5. called from sem_res Resolve_Actuals
1513 if K
= N_Attribute_Reference
then
1514 E
:= Etype
(Prefix
(N
));
1516 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1517 Error_Msg_N
("incorrect attribute of remote operand", N
);
1521 elsif K
= N_Allocator
then
1524 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1525 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1529 elsif K
in N_Has_Entity
then
1532 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1533 Error_Msg_N
("incorrect remote type generic actual", N
);
1537 -- This subprogram also enforces the checks in E.2.2(13). A value of
1538 -- such type must not be dereferenced unless as controlling operand of a
1539 -- dispatching call.
1541 elsif K
= N_Explicit_Dereference
1542 and then (Comes_From_Source
(N
)
1543 or else (Nkind
(Original_Node
(N
)) = N_Selected_Component
1544 and then Comes_From_Source
(Original_Node
(N
))))
1546 E
:= Etype
(Prefix
(N
));
1548 -- If the class-wide type is not a remote one, the restrictions
1551 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1555 -- If we have a true dereference that comes from source and that
1556 -- is a controlling argument for a dispatching call, accept it.
1558 if K
= N_Explicit_Dereference
1559 and then Is_Actual_Parameter
(N
)
1560 and then Is_Controlling_Actual
(N
)
1565 -- If we are just within a procedure or function call and the
1566 -- dereference has not been analyzed, return because this procedure
1567 -- will be called again from sem_res Resolve_Actuals.
1569 if Is_Actual_Parameter
(N
)
1570 and then not Analyzed
(N
)
1575 -- The following is to let the compiler generated tags check pass
1576 -- through without error message. This is a bit kludgy isn't there
1577 -- some better way of making this exclusion ???
1579 if (PK
= N_Selected_Component
1580 and then Present
(Parent
(Parent
(N
)))
1581 and then Nkind
(Parent
(Parent
(N
))) = N_Op_Ne
)
1582 or else (PK
= N_Unchecked_Type_Conversion
1583 and then Present
(Parent
(Parent
(N
)))
1585 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
)
1590 -- The following code is needed for expansion of RACW Write
1591 -- attribute, since such expressions can appear in the expanded
1594 if not Comes_From_Source
(N
)
1597 or else PK
= N_Attribute_Reference
1599 (PK
= N_Type_Conversion
1600 and then Present
(Parent
(N
))
1601 and then Present
(Parent
(Parent
(N
)))
1603 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
))
1608 Error_Msg_N
("incorrect remote type dereference", N
);
1610 end Validate_Remote_Access_To_Class_Wide_Type
;
1612 ------------------------------------------
1613 -- Validate_Remote_Type_Type_Conversion --
1614 ------------------------------------------
1616 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1617 S
: constant Entity_Id
:= Etype
(N
);
1618 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1621 -- This test is required in the case where a conversion appears inside a
1622 -- normal package, it does not necessarily have to be inside an RCI,
1623 -- Remote_Types unit (RM E.2.2(9,12)).
1625 if Is_Remote_Access_To_Subprogram_Type
(E
)
1626 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1629 ("incorrect conversion of remote operand to local type", N
);
1632 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1633 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1636 ("incorrect conversion of local operand to remote type", N
);
1639 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1640 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1643 ("incorrect conversion of remote operand to local type", N
);
1647 -- If a local access type is converted into a RACW type, then the
1648 -- current unit has a pointer that may now be exported to another
1651 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1652 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1654 Set_Has_RACW
(Current_Sem_Unit
);
1656 end Validate_Remote_Type_Type_Conversion
;
1658 -------------------------------
1659 -- Validate_RT_RAT_Component --
1660 -------------------------------
1662 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1663 Spec
: constant Node_Id
:= Specification
(N
);
1664 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1666 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1667 In_Visible_Part
: Boolean := True;
1670 if not Is_Remote_Types
(Name_U
) then
1674 Typ
:= First_Entity
(Name_U
);
1675 while Present
(Typ
) loop
1676 if In_Visible_Part
and then Typ
= First_Priv_Ent
then
1677 In_Visible_Part
:= False;
1680 if Comes_From_Source
(Typ
)
1681 and then Is_Type
(Typ
)
1682 and then (In_Visible_Part
or else Has_Private_Declaration
(Typ
))
1684 if Missing_Read_Write_Attributes
(Typ
) then
1685 if Is_Non_Remote_Access_Type
(Typ
) then
1687 ("non-remote access type without user-defined Read " &
1688 "and Write attributes", Typ
);
1691 ("record type containing a component of a " &
1692 "non-remote access", Typ
);
1694 ("\type without Read and Write attributes " &
1695 "('R'M E.2.2(8))", Typ
);
1702 end Validate_RT_RAT_Component
;
1704 -----------------------------------------
1705 -- Validate_SP_Access_Object_Type_Decl --
1706 -----------------------------------------
1708 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
1709 Direct_Designated_Type
: Entity_Id
;
1711 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
1712 -- Return true if the protected type designated by T has
1713 -- entry declarations.
1715 ----------------------------
1716 -- Has_Entry_Declarations --
1717 ----------------------------
1719 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
1723 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
1724 Ety
:= First_Entity
(E
);
1725 while Present
(Ety
) loop
1726 if Ekind
(Ety
) = E_Entry
then
1735 end Has_Entry_Declarations
;
1737 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1740 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1741 -- Nkind of the given entity is N_Access_To_Object_Definition.
1743 if not Comes_From_Source
(T
)
1744 or else not In_Shared_Passive_Unit
1745 or else In_Subprogram_Task_Protected_Unit
1750 -- Check Shared Passive unit. It should not contain the declaration
1751 -- of an access-to-object type whose designated type is a class-wide
1752 -- type, task type or protected type with entry (RM E.2.1(7)).
1754 Direct_Designated_Type
:= Designated_Type
(T
);
1756 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
1758 ("invalid access-to-class-wide type in shared passive unit", T
);
1761 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
1763 ("invalid access-to-task type in shared passive unit", T
);
1766 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
1767 and then Has_Entry_Declarations
(Direct_Designated_Type
)
1770 ("invalid access-to-protected type in shared passive unit", T
);
1773 end Validate_SP_Access_Object_Type_Decl
;
1775 ---------------------------------
1776 -- Validate_Static_Object_Name --
1777 ---------------------------------
1779 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
1782 function Is_Primary
(N
: Node_Id
) return Boolean;
1783 -- Determine whether node is syntactically a primary in an expression
1789 function Is_Primary
(N
: Node_Id
) return Boolean is
1790 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1794 when N_Op | N_In | N_Not_In
=>
1798 | N_Component_Association
1799 | N_Index_Or_Discriminant_Constraint
=>
1802 when N_Attribute_Reference
=>
1803 return Attribute_Name
(Parent
(N
)) /= Name_Address
1804 and then Attribute_Name
(Parent
(N
)) /= Name_Access
1805 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
1807 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
1809 when N_Indexed_Component
=>
1810 return (N
/= Prefix
(Parent
(N
))
1811 or else Is_Primary
(Parent
(N
)));
1813 when N_Qualified_Expression | N_Type_Conversion
=>
1814 return Is_Primary
(Parent
(N
));
1816 when N_Assignment_Statement | N_Object_Declaration
=>
1817 return (N
= Expression
(Parent
(N
)));
1819 when N_Selected_Component
=>
1820 return Is_Primary
(Parent
(N
));
1827 -- Start of processing for Validate_Static_Object_Name
1830 if not In_Preelaborated_Unit
1831 or else not Comes_From_Source
(N
)
1832 or else In_Subprogram_Or_Concurrent_Unit
1833 or else Ekind
(Current_Scope
) = E_Block
1837 -- Filter out cases where primary is default in a component declaration,
1838 -- discriminant specification, or actual in a record type initialization
1841 -- Initialization call of internal types
1843 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
1845 if Present
(Parent
(Parent
(N
)))
1846 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
1851 if Nkind
(Name
(Parent
(N
))) = N_Identifier
1852 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
1858 -- Error if the name is a primary in an expression. The parent must not
1859 -- be an operator, or a selected component or an indexed component that
1860 -- is itself a primary. Entities that are actuals do not need to be
1861 -- checked, because the call itself will be diagnosed.
1864 and then (not Inside_A_Generic
1865 or else Present
(Enclosing_Generic_Body
(N
)))
1867 if Ekind
(Entity
(N
)) = E_Variable
then
1868 Flag_Non_Static_Expr
1869 ("non-static object name in preelaborated unit", N
);
1871 -- We take the view that a constant defined in another preelaborated
1872 -- unit is preelaborable, even though it may have a private type and
1873 -- thus appear non-static in a client. This must be the intent of
1874 -- the language, but currently is an RM gap ???
1876 elsif Ekind
(Entity
(N
)) = E_Constant
1877 and then not Is_Static_Expression
(N
)
1881 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
1883 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
1884 and then (Is_Preelaborated
(Scope
(E
))
1885 or else Is_Pure
(Scope
(E
))
1886 or else (Present
(Renamed_Object
(E
))
1888 Is_Entity_Name
(Renamed_Object
(E
))
1891 (Scope
(Renamed_Object
(E
)))
1894 (Renamed_Object
(E
))))))
1898 -- This is the error case
1901 -- In GNAT mode, this is just a warning, to allow it to be
1902 -- judiciously turned off. Otherwise it is a real error.
1906 ("?non-static constant in preelaborated unit", N
);
1908 Flag_Non_Static_Expr
1909 ("non-static constant in preelaborated unit", N
);
1915 end Validate_Static_Object_Name
;