1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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
;
149 -- Ignore Pure specification if set by pragma Pure_Function
153 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
157 elsif Is_Shared_Passive
(E
) then
158 return Shared_Passive
;
160 elsif Is_Remote_Types
(E
) then
163 elsif Is_Remote_Call_Interface
(E
) then
164 return Remote_Call_Interface
;
169 end Get_Categorization
;
171 -- Start of processing for Check_Categorization_Dependencies
174 -- Intrinsic subprograms are preelaborated, so do not impose any
175 -- categorization dependencies.
177 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
181 Unit_Category
:= Get_Categorization
(Unit_Entity
);
182 With_Category
:= Get_Categorization
(Depended_Entity
);
184 -- These messages are wanings in GNAT mode, to allow it to be
185 -- judiciously turned off. Otherwise it is a real error.
187 Error_Msg_Warn
:= GNAT_Mode
;
189 -- Check for possible error
191 if With_Category
> Unit_Category
then
193 -- Special case: Remote_Types and Remote_Call_Interface are allowed
194 -- to be with'ed in package body.
196 if (Unit_Category
= Remote_Types
197 or else Unit_Category
= Remote_Call_Interface
)
198 and then In_Package_Body
(Unit_Entity
)
202 -- Here we have an error
207 ("<subunit cannot depend on& " &
208 "(parent has wrong categorization)", N
, Depended_Entity
);
212 ("<cannot depend on& " &
213 "(wrong categorization)", N
, Depended_Entity
);
216 -- Add further explanation for common cases
218 case Unit_Category
is
221 ("\<pure unit cannot depend on non-pure unit",
224 when Preelaborated
=>
226 ("\<preelaborated unit cannot depend on " &
227 "non-preelaborated unit",
235 end Check_Categorization_Dependencies
;
237 -----------------------------------
238 -- Check_Non_Static_Default_Expr --
239 -----------------------------------
241 procedure Check_Non_Static_Default_Expr
246 Component_Decl
: Node_Id
;
249 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
250 Recdef
:= Record_Extension_Part
(Type_Def
);
260 -- Check that component declarations do not involve:
262 -- a. a non-static default expression, where the object is
263 -- declared to be default initialized.
265 -- b. a dynamic Itype (discriminants and constraints)
267 if Null_Present
(Recdef
) then
270 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
273 while Present
(Component_Decl
)
274 and then Nkind
(Component_Decl
) = N_Component_Declaration
276 if Present
(Expression
(Component_Decl
))
277 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
278 and then not Is_Static_Expression
(Expression
(Component_Decl
))
280 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
282 ("object in preelaborated unit has non-static default#",
285 -- Fix this later ???
287 -- elsif Has_Dynamic_Itype (Component_Decl) then
289 -- ("dynamic type discriminant," &
290 -- " constraint in preelaborated unit",
294 Next
(Component_Decl
);
296 end Check_Non_Static_Default_Expr
;
298 ---------------------------
299 -- In_Preelaborated_Unit --
300 ---------------------------
302 function In_Preelaborated_Unit
return Boolean is
303 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
304 Unit_Kind
: constant Node_Kind
:=
305 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
308 -- There are no constraints on body of remote_call_interface or
309 -- remote_types packages..
311 return (Unit_Entity
/= Standard_Standard
)
312 and then (Is_Preelaborated
(Unit_Entity
)
313 or else Is_Pure
(Unit_Entity
)
314 or else Is_Shared_Passive
(Unit_Entity
)
316 ((Is_Remote_Types
(Unit_Entity
)
317 or else Is_Remote_Call_Interface
(Unit_Entity
))
318 and then Ekind
(Unit_Entity
) = E_Package
319 and then Unit_Kind
/= N_Package_Body
320 and then not In_Package_Body
(Unit_Entity
)
321 and then not In_Instance
));
322 end In_Preelaborated_Unit
;
328 function In_Pure_Unit
return Boolean is
330 return Is_Pure
(Current_Scope
);
333 ------------------------
334 -- In_RCI_Declaration --
335 ------------------------
337 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
338 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
339 Unit_Kind
: constant Node_Kind
:=
340 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
343 -- There are no restrictions on the private part or body
346 return Is_Remote_Call_Interface
(Unit_Entity
)
347 and then (Ekind
(Unit_Entity
) = E_Package
348 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
349 and then Unit_Kind
/= N_Package_Body
350 and then List_Containing
(N
) =
352 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
353 and then not In_Package_Body
(Unit_Entity
)
354 and then not In_Instance
;
355 end In_RCI_Declaration
;
357 -----------------------
358 -- In_RT_Declaration --
359 -----------------------
361 function In_RT_Declaration
return Boolean is
362 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
363 Unit_Kind
: constant Node_Kind
:=
364 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
367 -- There are no restrictions on the body of a Remote Types unit
369 return Is_Remote_Types
(Unit_Entity
)
370 and then (Ekind
(Unit_Entity
) = E_Package
371 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
372 and then Unit_Kind
/= N_Package_Body
373 and then not In_Package_Body
(Unit_Entity
)
374 and then not In_Instance
;
375 end In_RT_Declaration
;
377 ----------------------------
378 -- In_Shared_Passive_Unit --
379 ----------------------------
381 function In_Shared_Passive_Unit
return Boolean is
382 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
385 return Is_Shared_Passive
(Unit_Entity
);
386 end In_Shared_Passive_Unit
;
388 ---------------------------------------
389 -- In_Subprogram_Task_Protected_Unit --
390 ---------------------------------------
392 function In_Subprogram_Task_Protected_Unit
return Boolean is
396 -- The following is to verify that a declaration is inside
397 -- subprogram, generic subprogram, task unit, protected unit.
398 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
400 -- Use scope chain to check successively outer scopes
406 Is_Generic_Subprogram
(E
)
408 Is_Concurrent_Type
(E
)
412 elsif E
= Standard_Standard
then
418 end In_Subprogram_Task_Protected_Unit
;
420 -------------------------------
421 -- Is_Non_Remote_Access_Type --
422 -------------------------------
424 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
426 return Is_Access_Type
(E
)
427 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
428 and then not Is_Remote_Access_To_Subprogram_Type
(E
);
429 end Is_Non_Remote_Access_Type
;
431 ------------------------------------
432 -- Is_Recursively_Limited_Private --
433 ------------------------------------
435 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean is
436 P
: constant Node_Id
:= Parent
(E
);
439 if Nkind
(P
) = N_Private_Type_Declaration
440 and then Is_Limited_Record
(E
)
443 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
444 return Is_Recursively_Limited_Private
(Etype
(E
));
445 elsif Nkind
(P
) = N_Formal_Type_Declaration
446 and then Ekind
(E
) = E_Record_Type_With_Private
447 and then Is_Generic_Type
(E
)
448 and then Is_Limited_Record
(E
)
454 end Is_Recursively_Limited_Private
;
456 ----------------------------------
457 -- Missing_Read_Write_Attribute --
458 ----------------------------------
460 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
461 Component
: Entity_Id
;
462 Component_Type
: Entity_Id
;
464 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
465 -- Return True if entity has Read and Write attributes
467 -------------------------------
468 -- Has_Read_Write_Attributes --
469 -------------------------------
471 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
472 Rep_Item
: Node_Id
:= First_Rep_Item
(E
);
473 Read_Attribute
: Boolean := False;
474 Write_Attribute
: Boolean := False;
477 -- We start from the declaration node and then loop until the end
478 -- of the list until we find those two attribute definition clauses.
480 while Present
(Rep_Item
) loop
481 if Chars
(Rep_Item
) = Name_Read
then
482 Read_Attribute
:= True;
483 elsif Chars
(Rep_Item
) = Name_Write
then
484 Write_Attribute
:= True;
487 if Read_Attribute
and Write_Attribute
then
491 Next_Rep_Item
(Rep_Item
);
495 end Has_Read_Write_Attributes
;
497 -- Start of processing for Missing_Read_Write_Attributes
500 if Has_Read_Write_Attributes
(E
) then
502 elsif Is_Non_Remote_Access_Type
(E
) then
506 if Is_Record_Type
(E
) then
507 Component
:= First_Entity
(E
);
508 while Present
(Component
) loop
509 Component_Type
:= Etype
(Component
);
511 if (Is_Non_Remote_Access_Type
(Component_Type
)
512 or else Is_Record_Type
(Component_Type
))
513 and then Missing_Read_Write_Attributes
(Component_Type
)
518 Next_Entity
(Component
);
523 end Missing_Read_Write_Attributes
;
525 -------------------------------------
526 -- Set_Categorization_From_Pragmas --
527 -------------------------------------
529 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
530 P
: constant Node_Id
:= Parent
(N
);
531 S
: constant Entity_Id
:= Current_Scope
;
533 procedure Set_Parents
(Visibility
: Boolean);
534 -- If this is a child instance, the parents are not immediately
535 -- visible during analysis. Make them momentarily visible so that
536 -- the argument of the pragma can be resolved properly, and reset
539 procedure Set_Parents
(Visibility
: Boolean) is
540 Par
: Entity_Id
:= Scope
(S
);
543 while Present
(Par
) and then Par
/= Standard_Standard
loop
544 Set_Is_Immediately_Visible
(Par
, Visibility
);
550 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
551 -- The purpose is to set categorization flags before analyzing the
552 -- unit itself, so as to diagnose violations of categorization as
553 -- we process each declaration, even though the pragma appears after
556 if Nkind
(P
) /= N_Compilation_Unit
then
561 PN
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
566 and then Is_Generic_Instance
(S
)
571 while Present
(PN
) loop
573 -- Skip implicit types that may have been introduced by
574 -- previous analysis.
576 if Nkind
(PN
) = N_Pragma
then
578 case Get_Pragma_Id
(Chars
(PN
)) is
579 when Pragma_All_Calls_Remote |
580 Pragma_Preelaborate |
582 Pragma_Remote_Call_Interface |
583 Pragma_Remote_Types |
584 Pragma_Shared_Passive
=> Analyze
(PN
);
592 and then Is_Generic_Instance
(S
)
598 end Set_Categorization_From_Pragmas
;
600 -----------------------------------
601 -- Set_Categorization_From_Scope --
602 -----------------------------------
604 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
605 Declaration
: Node_Id
:= Empty
;
606 Specification
: Node_Id
:= Empty
;
610 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
612 if not Is_Remote_Call_Interface
(E
) then
613 if Ekind
(E
) in Subprogram_Kind
then
614 Declaration
:= Unit_Declaration_Node
(E
);
617 or else Nkind
(Declaration
) = N_Subprogram_Body
618 or else Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
620 Specification
:= Corresponding_Spec
(Declaration
);
624 -- A subprogram body or renaming-as-body is a remote call
625 -- interface if it serves as the completion of a subprogram
626 -- declaration that is a remote call interface.
628 if Nkind
(Specification
) in N_Entity
then
629 Set_Is_Remote_Call_Interface
630 (E
, Is_Remote_Call_Interface
(Specification
));
632 -- A subprogram declaration is a remote call interface when it is
633 -- declared within the visible part of, or declared by, a library
634 -- unit declaration that is a remote call interface.
637 Set_Is_Remote_Call_Interface
638 (E
, Is_Remote_Call_Interface
(Scop
)
639 and then not (In_Private_Part
(Scop
)
640 or else In_Package_Body
(Scop
)));
644 Set_Is_Remote_Types
(E
, Is_Remote_Types
(Scop
));
645 end Set_Categorization_From_Scope
;
647 ------------------------------
648 -- Static_Discriminant_Expr --
649 ------------------------------
651 -- We need to accomodate a Why_Not_Static call somehow here ???
653 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
654 Discriminant_Spec
: Node_Id
;
657 Discriminant_Spec
:= First
(L
);
658 while Present
(Discriminant_Spec
) loop
659 if Present
(Expression
(Discriminant_Spec
))
660 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
665 Next
(Discriminant_Spec
);
669 end Static_Discriminant_Expr
;
671 --------------------------------------
672 -- Validate_Access_Type_Declaration --
673 --------------------------------------
675 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
676 Def
: constant Node_Id
:= Type_Definition
(N
);
681 -- Access to subprogram case
683 when N_Access_To_Subprogram_Definition
=>
685 -- A pure library_item must not contain the declaration of a
686 -- named access type, except within a subprogram, generic
687 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
689 -- This test is skipped in Ada 2005 (see AI-366)
691 if Ada_Version
< Ada_05
692 and then Comes_From_Source
(T
)
693 and then In_Pure_Unit
694 and then not In_Subprogram_Task_Protected_Unit
696 Error_Msg_N
("named access type not allowed in pure unit", T
);
699 -- Access to object case
701 when N_Access_To_Object_Definition
=>
702 if Comes_From_Source
(T
)
703 and then In_Pure_Unit
704 and then not In_Subprogram_Task_Protected_Unit
706 -- We can't give the message yet, since the type is not frozen
707 -- and in Ada 2005 mode, access types are allowed in pure units
708 -- if the type has no storage pool (see AI-366). So we set a
709 -- flag which will be checked at freeze time.
711 Set_Is_Pure_Unit_Access_Type
(T
);
714 -- Check for RCI or RT unit type declaration. It should not
715 -- contain the declaration of an access-to-object type unless it
716 -- is a general access type that designates a class-wide limited
717 -- private type. There are also constraints about the primitive
718 -- subprograms of the class-wide type.
720 Validate_Remote_Access_Object_Type_Declaration
(T
);
722 -- Check for shared passive unit type declaration. It should
723 -- not contain the declaration of access to class wide type,
724 -- access to task type and access to protected type with entry.
726 Validate_SP_Access_Object_Type_Decl
(T
);
732 -- Set categorization flag from package on entity as well, to allow
733 -- easy checks later on for required validations of RCI or RT units.
734 -- This is only done for entities that are in the original source.
736 if Comes_From_Source
(T
)
737 and then not (In_Package_Body
(Scope
(T
))
738 or else In_Private_Part
(Scope
(T
)))
740 Set_Is_Remote_Call_Interface
741 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
743 (T
, Is_Remote_Types
(Scope
(T
)));
745 end Validate_Access_Type_Declaration
;
747 ----------------------------
748 -- Validate_Ancestor_Part --
749 ----------------------------
751 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
752 A
: constant Node_Id
:= Ancestor_Part
(N
);
753 T
: constant Entity_Id
:= Entity
(A
);
756 if In_Preelaborated_Unit
757 and then not In_Subprogram_Or_Concurrent_Unit
758 and then (not Inside_A_Generic
759 or else Present
(Enclosing_Generic_Body
(N
)))
761 -- We relax the restriction of 10.2.1(9) within GNAT
762 -- units to allow packages such as Ada.Strings.Unbounded
763 -- to be implemented (i.p., Null_Unbounded_String).
764 -- (There are ACVC tests that check that the restriction
765 -- is enforced, but note that AI-161, once approved,
766 -- will relax the restriction prohibiting default-
767 -- initialized objects of private and controlled
770 if Is_Private_Type
(T
)
771 and then not Is_Internal_File_Name
772 (Unit_File_Name
(Get_Source_Unit
(N
)))
775 ("private ancestor type not allowed in preelaborated unit", A
);
777 elsif Is_Record_Type
(T
) then
778 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
779 Check_Non_Static_Default_Expr
780 (Type_Definition
(Parent
(T
)), A
);
784 end Validate_Ancestor_Part
;
786 ----------------------------------------
787 -- Validate_Categorization_Dependency --
788 ----------------------------------------
790 procedure Validate_Categorization_Dependency
794 K
: constant Node_Kind
:= Nkind
(N
);
795 P
: Node_Id
:= Parent
(N
);
797 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
800 -- Only validate library units and subunits. For subunits, checks
801 -- concerning withed units apply to the parent compilation unit.
808 and then not Is_Compilation_Unit
(U
)
809 and then not Is_Child_Unit
(U
)
816 if Nkind
(P
) /= N_Compilation_Unit
then
820 -- Body of RCI unit does not need validation
822 if Is_Remote_Call_Interface
(E
)
823 and then (Nkind
(N
) = N_Package_Body
824 or else Nkind
(N
) = N_Subprogram_Body
)
829 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
833 Entity_Of_Withed
: Entity_Id
;
836 Item
:= First
(Context_Items
(P
));
838 while Present
(Item
) loop
839 if Nkind
(Item
) = N_With_Clause
840 and then not (Implicit_With
(Item
)
841 or else Limited_Present
(Item
))
843 Entity_Of_Withed
:= Entity
(Name
(Item
));
844 Check_Categorization_Dependencies
845 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
852 -- Child depends on parent; therefore parent should also be categorized
853 -- and satify the dependency hierarchy.
855 -- Check if N is a child spec
857 if (K
in N_Generic_Declaration
or else
858 K
in N_Generic_Instantiation
or else
859 K
in N_Generic_Renaming_Declaration
or else
860 K
= N_Package_Declaration
or else
861 K
= N_Package_Renaming_Declaration
or else
862 K
= N_Subprogram_Declaration
or else
863 K
= N_Subprogram_Renaming_Declaration
)
864 and then Present
(Parent_Spec
(N
))
866 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
868 -- Verify that public child of an RCI library unit must also be an
869 -- RCI library unit (RM E.2.3(15)).
871 if Is_Remote_Call_Interface
(Scope
(E
))
872 and then not Private_Present
(P
)
873 and then not Is_Remote_Call_Interface
(E
)
875 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
878 end Validate_Categorization_Dependency
;
880 --------------------------------
881 -- Validate_Controlled_Object --
882 --------------------------------
884 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
886 -- For now, never apply this check for internal GNAT units, since we
887 -- have a number of cases in the library where we are stuck with objects
888 -- of this type, and the RM requires Preelaborate.
890 -- For similar reasons, we only do this check for source entities, since
891 -- we generate entities of this type in some situations.
893 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
894 -- We have to enforce them for RM compatibility, but we have no trouble
895 -- accepting these objects and doing the right thing. Note that there is
896 -- no requirement that Preelaborate not actually generate any code!
898 if In_Preelaborated_Unit
899 and then not Debug_Flag_PP
900 and then Comes_From_Source
(E
)
902 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
903 and then (not Inside_A_Generic
904 or else Present
(Enclosing_Generic_Body
(E
)))
905 and then not Is_Protected_Type
(Etype
(E
))
908 ("library level controlled object not allowed in " &
909 "preelaborated unit", E
);
911 end Validate_Controlled_Object
;
913 --------------------------------------
914 -- Validate_Null_Statement_Sequence --
915 --------------------------------------
917 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
921 if In_Preelaborated_Unit
then
922 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
924 while Present
(Item
) loop
925 if Nkind
(Item
) /= N_Label
926 and then Nkind
(Item
) /= N_Null_Statement
928 -- In GNAT mode, this is a warning, allowing the run-time
929 -- to judiciously bypass this error condition.
931 Error_Msg_Warn
:= GNAT_Mode
;
933 ("<statements not allowed in preelaborated unit", Item
);
941 end Validate_Null_Statement_Sequence
;
943 ---------------------------------
944 -- Validate_Object_Declaration --
945 ---------------------------------
947 procedure Validate_Object_Declaration
(N
: Node_Id
) is
948 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
949 E
: constant Node_Id
:= Expression
(N
);
950 Odf
: constant Node_Id
:= Object_Definition
(N
);
951 T
: constant Entity_Id
:= Etype
(Id
);
954 -- Verify that any access to subprogram object does not have in its
955 -- subprogram profile access type parameters or limited parameters
956 -- without Read and Write attributes (E.2.3(13)).
958 Validate_RCI_Subprogram_Declaration
(N
);
960 -- Check that if we are in preelaborated elaboration code, then we
961 -- do not have an instance of a default initialized private, task or
962 -- protected object declaration which would violate (RM 10.2.1(9)).
963 -- Note that constants are never default initialized (and the test
964 -- below also filters out deferred constants). A variable is default
965 -- initialized if it does *not* have an initialization expression.
967 -- Filter out cases that are not declaration of a variable from source
969 if Nkind
(N
) /= N_Object_Declaration
970 or else Constant_Present
(N
)
971 or else not Comes_From_Source
(Id
)
976 -- Exclude generic specs from the checks (this will get rechecked
977 -- on instantiations).
980 and then No
(Enclosing_Generic_Body
(Id
))
985 -- Required checks for declaration that is in a preelaborated
986 -- package and is not within some subprogram.
988 if In_Preelaborated_Unit
989 and then not In_Subprogram_Or_Concurrent_Unit
991 -- Check for default initialized variable case. Note that in
992 -- accordance with (RM B.1(24)) imported objects are not
993 -- subject to default initialization.
995 if No
(E
) and then not Is_Imported
(Id
) then
997 Ent
: Entity_Id
:= T
;
1000 -- An array whose component type is a record with nonstatic
1001 -- default expressions is a violation, so we get the array's
1004 if Is_Array_Type
(Ent
) then
1006 Comp_Type
: Entity_Id
:= Component_Type
(Ent
);
1009 while Is_Array_Type
(Comp_Type
) loop
1010 Comp_Type
:= Component_Type
(Comp_Type
);
1017 -- Object decl. that is of record type and has no default expr.
1018 -- should check if there is any non-static default expression
1019 -- in component decl. of the record type decl.
1021 if Is_Record_Type
(Ent
) then
1022 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1023 Check_Non_Static_Default_Expr
1024 (Type_Definition
(Parent
(Ent
)), N
);
1026 elsif Nkind
(Odf
) = N_Subtype_Indication
1027 and then not Is_Array_Type
(T
)
1028 and then not Is_Private_Type
(T
)
1030 Check_Non_Static_Default_Expr
(Type_Definition
1031 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1035 -- We relax the restriction of 10.2.1(9) within GNAT
1036 -- units. (There are ACVC tests that check that the
1037 -- restriction is enforced, but note that AI-161,
1038 -- once approved, will relax the restriction prohibiting
1039 -- default-initialized objects of private types, and
1040 -- will recommend a pragma for marking private types.)
1042 if (Is_Private_Type
(Ent
)
1043 or else Depends_On_Private
(Ent
))
1044 and then not Is_Internal_File_Name
1045 (Unit_File_Name
(Get_Source_Unit
(N
)))
1048 ("private object not allowed in preelaborated unit", N
);
1051 -- Access to Task or Protected type
1053 elsif Is_Entity_Name
(Odf
)
1054 and then Present
(Etype
(Odf
))
1055 and then Is_Access_Type
(Etype
(Odf
))
1057 Ent
:= Designated_Type
(Etype
(Odf
));
1059 elsif Is_Entity_Name
(Odf
) then
1060 Ent
:= Entity
(Odf
);
1062 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1063 Ent
:= Etype
(Subtype_Mark
(Odf
));
1066 Nkind
(Odf
) = N_Constrained_Array_Definition
1068 Ent
:= Component_Type
(T
);
1074 if Is_Task_Type
(Ent
)
1075 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1078 ("concurrent object not allowed in preelaborated unit",
1085 -- Non-static discriminant not allowed in preelaborayted unit
1087 if Is_Record_Type
(Etype
(Id
)) then
1089 ET
: constant Entity_Id
:= Etype
(Id
);
1090 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1094 if Has_Discriminants
(ET
)
1095 and then Present
(EE
)
1099 if Nkind
(PEE
) = N_Full_Type_Declaration
1100 and then not Static_Discriminant_Expr
1101 (Discriminant_Specifications
(PEE
))
1104 ("non-static discriminant in preelaborated unit",
1112 -- A pure library_item must not contain the declaration of any
1113 -- variable except within a subprogram, generic subprogram, task
1114 -- unit or protected unit (RM 10.2.1(16)).
1117 and then not In_Subprogram_Task_Protected_Unit
1119 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1121 -- The visible part of an RCI library unit must not contain the
1122 -- declaration of a variable (RM E.1.3(9))
1124 elsif In_RCI_Declaration
(N
) then
1125 Error_Msg_N
("declaration of variable not allowed in rci unit", N
);
1127 -- The visible part of a Shared Passive library unit must not contain
1128 -- the declaration of a variable (RM E.2.2(7))
1130 elsif In_RT_Declaration
then
1132 ("variable declaration not allowed in remote types unit", N
);
1135 end Validate_Object_Declaration
;
1137 -------------------------------
1138 -- Validate_RCI_Declarations --
1139 -------------------------------
1141 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1145 E
:= First_Entity
(P
);
1146 while Present
(E
) loop
1147 if Comes_From_Source
(E
) then
1148 if Is_Limited_Type
(E
) then
1150 ("Limited type not allowed in rci unit", Parent
(E
));
1151 Explain_Limited_Type
(E
, Parent
(E
));
1153 elsif Ekind
(E
) = E_Generic_Function
1154 or else Ekind
(E
) = E_Generic_Package
1155 or else Ekind
(E
) = E_Generic_Procedure
1157 Error_Msg_N
("generic declaration not allowed in rci unit",
1160 elsif (Ekind
(E
) = E_Function
1161 or else Ekind
(E
) = E_Procedure
)
1162 and then Has_Pragma_Inline
(E
)
1165 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1167 -- Inner packages that are renamings need not be checked.
1168 -- Generic RCI packages are subject to the checks, but
1169 -- entities that come from formal packages are not part of the
1170 -- visible declarations of the package and are not checked.
1172 elsif Ekind
(E
) = E_Package
then
1173 if Present
(Renamed_Entity
(E
)) then
1176 elsif Ekind
(P
) /= E_Generic_Package
1177 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1178 Generic_Formal_Declarations
1179 (Unit_Declaration_Node
(P
))
1181 Validate_RCI_Declarations
(E
);
1188 end Validate_RCI_Declarations
;
1190 -----------------------------------------
1191 -- Validate_RCI_Subprogram_Declaration --
1192 -----------------------------------------
1194 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1195 K
: constant Node_Kind
:= Nkind
(N
);
1198 Param_Spec
: Node_Id
;
1199 Param_Type
: Entity_Id
;
1200 Base_Param_Type
: Entity_Id
;
1201 Base_Under_Type
: Entity_Id
;
1202 Type_Decl
: Node_Id
;
1203 Error_Node
: Node_Id
:= N
;
1206 -- There are two possible cases in which this procedure is called:
1208 -- 1. called from Analyze_Subprogram_Declaration.
1209 -- 2. called from Validate_Object_Declaration (access to subprogram).
1211 if not In_RCI_Declaration
(N
) then
1215 if K
= N_Subprogram_Declaration
then
1216 Profile
:= Parameter_Specifications
(Specification
(N
));
1218 else pragma Assert
(K
= N_Object_Declaration
);
1219 Id
:= Defining_Identifier
(N
);
1221 if Nkind
(Id
) = N_Defining_Identifier
1222 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1223 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1226 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1232 -- Iterate through the parameter specification list, checking that
1233 -- no access parameter and no limited type parameter in the list.
1236 if Present
(Profile
) then
1237 Param_Spec
:= First
(Profile
);
1239 while Present
(Param_Spec
) loop
1240 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1241 Type_Decl
:= Parent
(Param_Type
);
1243 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1245 if K
= N_Subprogram_Declaration
then
1246 Error_Node
:= Param_Spec
;
1249 -- Report error only if declaration is in source program
1251 if Comes_From_Source
1252 (Defining_Entity
(Specification
(N
)))
1255 ("subprogram in rci unit cannot have access parameter",
1259 -- For limited private type parameter, we check only the
1260 -- private declaration and ignore full type declaration,
1261 -- unless this is the only declaration for the type, eg.
1262 -- as a limited record.
1264 elsif Is_Limited_Type
(Param_Type
)
1265 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1267 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1268 and then not (Has_Private_Declaration
(Param_Type
))
1269 and then Comes_From_Source
(N
)))
1271 -- A limited parameter is legal only if user-specified Read and
1272 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1274 if No
(Full_View
(Param_Type
))
1275 and then Ekind
(Param_Type
) /= E_Record_Type
1277 -- Type does not have completion yet, so if declared in in
1278 -- the current RCI scope it is illegal, and will be flagged
1284 -- In Ada 95 the rules permit using a limited type that has
1285 -- user-specified Read and Write attributes that are specified
1286 -- in the private part of the package, whereas Ada 2005
1287 -- (AI-240) revises this to require the attributes to be
1288 -- "available" (implying that the attribute clauses must be
1289 -- visible to the RCI client). The Ada 95 rules violate the
1290 -- contract model for privacy, but we support both semantics
1291 -- for now for compatibility (note that ACATS test BXE2009
1292 -- checks a case that conforms to the Ada 95 rules but is
1293 -- illegal in Ada 2005).
1295 Base_Param_Type
:= Base_Type
(Param_Type
);
1296 Base_Under_Type
:= Base_Type
(Underlying_Type
1299 if (Ada_Version
< Ada_05
1301 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1303 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1305 (No
(TSS
(Base_Under_Type
, TSS_Stream_Read
))
1307 No
(TSS
(Base_Under_Type
, TSS_Stream_Write
))))
1309 (Ada_Version
>= Ada_05
1311 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1313 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1315 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1317 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Write
))))
1319 if K
= N_Subprogram_Declaration
then
1320 Error_Node
:= Param_Spec
;
1323 if Ada_Version
>= Ada_05
then
1325 ("limited parameter in rci unit "
1326 & "must have visible read/write attributes ",
1330 ("limited parameter in rci unit "
1331 & "must have read/write attributes ",
1334 Explain_Limited_Type
(Param_Type
, Error_Node
);
1341 end Validate_RCI_Subprogram_Declaration
;
1343 ----------------------------------------------------
1344 -- Validate_Remote_Access_Object_Type_Declaration --
1345 ----------------------------------------------------
1347 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1348 Direct_Designated_Type
: Entity_Id
;
1349 Desig_Type
: Entity_Id
;
1350 Primitive_Subprograms
: Elist_Id
;
1351 Subprogram
: Elmt_Id
;
1352 Subprogram_Node
: Node_Id
;
1354 Param_Spec
: Node_Id
;
1355 Param_Type
: Entity_Id
;
1358 -- We are called from Analyze_Type_Declaration, and the Nkind
1359 -- of the given node is N_Access_To_Object_Definition.
1361 if not Comes_From_Source
(T
)
1362 or else (not In_RCI_Declaration
(Parent
(T
))
1363 and then not In_RT_Declaration
)
1368 -- An access definition in the private part of a Remote Types package
1369 -- may be legal if it has user-defined Read and Write attributes. This
1370 -- will be checked at the end of the package spec processing.
1372 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1376 -- Check RCI or RT unit type declaration. It may not contain
1377 -- the declaration of an access-to-object type unless it is a
1378 -- general access type that designates a class-wide limited
1379 -- private type. There are also constraints about the primitive
1380 -- subprograms of the class-wide type (RM E.2.3(14)).
1382 if Ekind
(T
) /= E_General_Access_Type
1383 or else Ekind
(Designated_Type
(T
)) /= E_Class_Wide_Type
1385 if In_RCI_Declaration
(Parent
(T
)) then
1387 ("access type in Remote_Call_Interface unit must be " &
1388 "general access", T
);
1390 Error_Msg_N
("access type in Remote_Types unit must be " &
1391 "general access", T
);
1393 Error_Msg_N
("\to class-wide type", T
);
1397 Direct_Designated_Type
:= Designated_Type
(T
);
1398 Desig_Type
:= Etype
(Direct_Designated_Type
);
1400 if not Is_Recursively_Limited_Private
(Desig_Type
) then
1402 ("error in designated type of remote access to class-wide type", T
);
1404 ("\must be tagged limited private or private extension of type", T
);
1408 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1409 Subprogram
:= First_Elmt
(Primitive_Subprograms
);
1411 while Subprogram
/= No_Elmt
loop
1412 Subprogram_Node
:= Node
(Subprogram
);
1414 if not Comes_From_Source
(Subprogram_Node
) then
1415 goto Next_Subprogram
;
1418 Profile
:= Parameter_Specifications
(Parent
(Subprogram_Node
));
1420 -- Profile must exist, otherwise not primitive operation
1422 Param_Spec
:= First
(Profile
);
1423 while Present
(Param_Spec
) loop
1425 -- Now find out if this parameter is a controlling parameter
1427 Param_Type
:= Parameter_Type
(Param_Spec
);
1429 if (Nkind
(Param_Type
) = N_Access_Definition
1430 and then Etype
(Subtype_Mark
(Param_Type
)) = Desig_Type
)
1431 or else (Nkind
(Param_Type
) /= N_Access_Definition
1432 and then Etype
(Param_Type
) = Desig_Type
)
1434 -- It is a controlling parameter, so specific checks below
1440 Nkind
(Param_Type
) = N_Access_Definition
1442 -- From RM E.2.2(14), no access parameter other than
1443 -- controlling ones may be used.
1446 ("non-controlling access parameter", Param_Spec
);
1449 Is_Limited_Type
(Etype
(Defining_Identifier
(Param_Spec
)))
1451 -- Not a controlling parameter, so type must have Read
1452 -- and Write attributes.
1454 if Nkind
(Param_Type
) in N_Has_Etype
1455 and then Nkind
(Parent
(Etype
(Param_Type
))) =
1456 N_Private_Type_Declaration
1458 Param_Type
:= Etype
(Param_Type
);
1460 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1462 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1465 ("limited formal must have Read and Write attributes",
1467 Explain_Limited_Type
1468 (Etype
(Defining_Identifier
(Param_Spec
)), Param_Spec
);
1473 -- Check next parameter in this subprogram
1479 Next_Elmt
(Subprogram
);
1482 -- Now this is an RCI unit access-to-class-wide-limited-private type
1483 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1484 -- optimize later checks by avoiding tree traversal to find out if this
1485 -- entity is inside an RCI unit.
1487 Set_Is_Remote_Call_Interface
(T
);
1488 end Validate_Remote_Access_Object_Type_Declaration
;
1490 -----------------------------------------------
1491 -- Validate_Remote_Access_To_Class_Wide_Type --
1492 -----------------------------------------------
1494 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1495 K
: constant Node_Kind
:= Nkind
(N
);
1496 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1500 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1501 -- of class-wide limited private types.
1503 -- Storage_Pool and Storage_Size are not defined for such types
1505 -- The expected type of allocator must not not be such a type.
1507 -- The actual parameter of generic instantiation must not be such a
1508 -- type if the formal parameter is of an access type.
1510 -- On entry, there are five cases
1512 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1513 -- either Storage_Pool or Storage_Size.
1515 -- 2. called from exp_ch4 Expand_N_Allocator
1517 -- 3. called from sem_ch12 Analyze_Associations
1519 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1521 -- 5. called from sem_res Resolve_Actuals
1523 if K
= N_Attribute_Reference
then
1524 E
:= Etype
(Prefix
(N
));
1526 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1527 Error_Msg_N
("incorrect attribute of remote operand", N
);
1531 elsif K
= N_Allocator
then
1534 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1535 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1539 elsif K
in N_Has_Entity
then
1542 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1543 Error_Msg_N
("incorrect remote type generic actual", N
);
1547 -- This subprogram also enforces the checks in E.2.2(13). A value of
1548 -- such type must not be dereferenced unless as controlling operand of a
1549 -- dispatching call.
1551 elsif K
= N_Explicit_Dereference
1552 and then (Comes_From_Source
(N
)
1553 or else (Nkind
(Original_Node
(N
)) = N_Selected_Component
1554 and then Comes_From_Source
(Original_Node
(N
))))
1556 E
:= Etype
(Prefix
(N
));
1558 -- If the class-wide type is not a remote one, the restrictions
1561 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1565 -- If we have a true dereference that comes from source and that
1566 -- is a controlling argument for a dispatching call, accept it.
1568 if K
= N_Explicit_Dereference
1569 and then Is_Actual_Parameter
(N
)
1570 and then Is_Controlling_Actual
(N
)
1575 -- If we are just within a procedure or function call and the
1576 -- dereference has not been analyzed, return because this procedure
1577 -- will be called again from sem_res Resolve_Actuals.
1579 if Is_Actual_Parameter
(N
)
1580 and then not Analyzed
(N
)
1585 -- The following is to let the compiler generated tags check pass
1586 -- through without error message. This is a bit kludgy isn't there
1587 -- some better way of making this exclusion ???
1589 if (PK
= N_Selected_Component
1590 and then Present
(Parent
(Parent
(N
)))
1591 and then Nkind
(Parent
(Parent
(N
))) = N_Op_Ne
)
1592 or else (PK
= N_Unchecked_Type_Conversion
1593 and then Present
(Parent
(Parent
(N
)))
1595 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
)
1600 -- The following code is needed for expansion of RACW Write
1601 -- attribute, since such expressions can appear in the expanded
1604 if not Comes_From_Source
(N
)
1607 or else PK
= N_Attribute_Reference
1609 (PK
= N_Type_Conversion
1610 and then Present
(Parent
(N
))
1611 and then Present
(Parent
(Parent
(N
)))
1613 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
))
1618 Error_Msg_N
("incorrect remote type dereference", N
);
1620 end Validate_Remote_Access_To_Class_Wide_Type
;
1622 ------------------------------------------
1623 -- Validate_Remote_Type_Type_Conversion --
1624 ------------------------------------------
1626 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1627 S
: constant Entity_Id
:= Etype
(N
);
1628 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1631 -- This test is required in the case where a conversion appears inside a
1632 -- normal package, it does not necessarily have to be inside an RCI,
1633 -- Remote_Types unit (RM E.2.2(9,12)).
1635 if Is_Remote_Access_To_Subprogram_Type
(E
)
1636 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1639 ("incorrect conversion of remote operand to local type", N
);
1642 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1643 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1646 ("incorrect conversion of local operand to remote type", N
);
1649 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1650 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1653 ("incorrect conversion of remote operand to local type", N
);
1657 -- If a local access type is converted into a RACW type, then the
1658 -- current unit has a pointer that may now be exported to another
1661 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1662 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1664 Set_Has_RACW
(Current_Sem_Unit
);
1666 end Validate_Remote_Type_Type_Conversion
;
1668 -------------------------------
1669 -- Validate_RT_RAT_Component --
1670 -------------------------------
1672 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1673 Spec
: constant Node_Id
:= Specification
(N
);
1674 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1676 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1677 In_Visible_Part
: Boolean := True;
1680 if not Is_Remote_Types
(Name_U
) then
1684 Typ
:= First_Entity
(Name_U
);
1685 while Present
(Typ
) loop
1686 if In_Visible_Part
and then Typ
= First_Priv_Ent
then
1687 In_Visible_Part
:= False;
1690 if Comes_From_Source
(Typ
)
1691 and then Is_Type
(Typ
)
1692 and then (In_Visible_Part
or else Has_Private_Declaration
(Typ
))
1694 if Missing_Read_Write_Attributes
(Typ
) then
1695 if Is_Non_Remote_Access_Type
(Typ
) then
1697 ("non-remote access type without user-defined Read " &
1698 "and Write attributes", Typ
);
1701 ("record type containing a component of a " &
1702 "non-remote access", Typ
);
1704 ("\type without Read and Write attributes " &
1705 "('R'M E.2.2(8))", Typ
);
1712 end Validate_RT_RAT_Component
;
1714 -----------------------------------------
1715 -- Validate_SP_Access_Object_Type_Decl --
1716 -----------------------------------------
1718 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
1719 Direct_Designated_Type
: Entity_Id
;
1721 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
1722 -- Return true if the protected type designated by T has
1723 -- entry declarations.
1725 ----------------------------
1726 -- Has_Entry_Declarations --
1727 ----------------------------
1729 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
1733 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
1734 Ety
:= First_Entity
(E
);
1735 while Present
(Ety
) loop
1736 if Ekind
(Ety
) = E_Entry
then
1745 end Has_Entry_Declarations
;
1747 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1750 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1751 -- Nkind of the given entity is N_Access_To_Object_Definition.
1753 if not Comes_From_Source
(T
)
1754 or else not In_Shared_Passive_Unit
1755 or else In_Subprogram_Task_Protected_Unit
1760 -- Check Shared Passive unit. It should not contain the declaration
1761 -- of an access-to-object type whose designated type is a class-wide
1762 -- type, task type or protected type with entry (RM E.2.1(7)).
1764 Direct_Designated_Type
:= Designated_Type
(T
);
1766 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
1768 ("invalid access-to-class-wide type in shared passive unit", T
);
1771 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
1773 ("invalid access-to-task type in shared passive unit", T
);
1776 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
1777 and then Has_Entry_Declarations
(Direct_Designated_Type
)
1780 ("invalid access-to-protected type in shared passive unit", T
);
1783 end Validate_SP_Access_Object_Type_Decl
;
1785 ---------------------------------
1786 -- Validate_Static_Object_Name --
1787 ---------------------------------
1789 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
1792 function Is_Primary
(N
: Node_Id
) return Boolean;
1793 -- Determine whether node is syntactically a primary in an expression
1799 function Is_Primary
(N
: Node_Id
) return Boolean is
1800 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1804 when N_Op | N_In | N_Not_In
=>
1808 | N_Component_Association
1809 | N_Index_Or_Discriminant_Constraint
=>
1812 when N_Attribute_Reference
=>
1813 return Attribute_Name
(Parent
(N
)) /= Name_Address
1814 and then Attribute_Name
(Parent
(N
)) /= Name_Access
1815 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
1817 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
1819 when N_Indexed_Component
=>
1820 return (N
/= Prefix
(Parent
(N
))
1821 or else Is_Primary
(Parent
(N
)));
1823 when N_Qualified_Expression | N_Type_Conversion
=>
1824 return Is_Primary
(Parent
(N
));
1826 when N_Assignment_Statement | N_Object_Declaration
=>
1827 return (N
= Expression
(Parent
(N
)));
1829 when N_Selected_Component
=>
1830 return Is_Primary
(Parent
(N
));
1837 -- Start of processing for Validate_Static_Object_Name
1840 if not In_Preelaborated_Unit
1841 or else not Comes_From_Source
(N
)
1842 or else In_Subprogram_Or_Concurrent_Unit
1843 or else Ekind
(Current_Scope
) = E_Block
1847 -- Filter out cases where primary is default in a component declaration,
1848 -- discriminant specification, or actual in a record type initialization
1851 -- Initialization call of internal types
1853 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
1855 if Present
(Parent
(Parent
(N
)))
1856 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
1861 if Nkind
(Name
(Parent
(N
))) = N_Identifier
1862 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
1868 -- Error if the name is a primary in an expression. The parent must not
1869 -- be an operator, or a selected component or an indexed component that
1870 -- is itself a primary. Entities that are actuals do not need to be
1871 -- checked, because the call itself will be diagnosed.
1874 and then (not Inside_A_Generic
1875 or else Present
(Enclosing_Generic_Body
(N
)))
1877 if Ekind
(Entity
(N
)) = E_Variable
then
1878 Flag_Non_Static_Expr
1879 ("non-static object name in preelaborated unit", N
);
1881 -- We take the view that a constant defined in another preelaborated
1882 -- unit is preelaborable, even though it may have a private type and
1883 -- thus appear non-static in a client. This must be the intent of
1884 -- the language, but currently is an RM gap ???
1886 elsif Ekind
(Entity
(N
)) = E_Constant
1887 and then not Is_Static_Expression
(N
)
1891 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
1893 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
1894 and then (Is_Preelaborated
(Scope
(E
))
1895 or else Is_Pure
(Scope
(E
))
1896 or else (Present
(Renamed_Object
(E
))
1898 Is_Entity_Name
(Renamed_Object
(E
))
1901 (Scope
(Renamed_Object
(E
)))
1904 (Renamed_Object
(E
))))))
1908 -- This is the error case
1911 -- In GNAT mode, this is just a warning, to allow it to be
1912 -- judiciously turned off. Otherwise it is a real error.
1916 ("?non-static constant in preelaborated unit", N
);
1918 Flag_Non_Static_Expr
1919 ("non-static constant in preelaborated unit", N
);
1925 end Validate_Static_Object_Name
;