1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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
;
37 with Sem_Eval
; use Sem_Eval
;
38 with Sem_Util
; use Sem_Util
;
39 with Sinfo
; use Sinfo
;
40 with Snames
; use Snames
;
41 with Stand
; use Stand
;
43 package body Sem_Cat
is
45 -----------------------
46 -- Local Subprograms --
47 -----------------------
49 procedure Check_Categorization_Dependencies
50 (Unit_Entity
: Entity_Id
;
51 Depended_Entity
: Entity_Id
;
53 Is_Subunit
: Boolean);
54 -- This procedure checks that the categorization of a lib unit and that
55 -- of the depended unit satisfy dependency restrictions.
56 -- The depended_entity can be the entity in a with_clause item, in which
57 -- case Info_Node denotes that item. The depended_entity can also be the
58 -- parent unit of a child unit, in which case Info_Node is the declaration
59 -- of the child unit. The error message is posted on Info_Node, and is
60 -- specialized if Is_Subunit is true.
62 procedure Check_Non_Static_Default_Expr
65 -- Iterate through the component list of a record definition, check
66 -- that no component is declared with a nonstatic default value.
67 -- If a nonstatic default exists, report an error on Obj_Decl.
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a non-static default value.
72 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
73 -- Return True if the entity or one of its subcomponent is an access
74 -- type which does not have user-defined Read and Write attribute.
76 function In_RCI_Declaration
(N
: Node_Id
) return Boolean;
77 -- Determines if a declaration is within the visible part of a Remote
78 -- Call Interface compilation unit, for semantic checking purposes only,
79 -- (returns false within an instance and within the package body).
81 function In_RT_Declaration
return Boolean;
82 -- Determines if current scope is within a Remote Types compilation unit,
83 -- for semantic checking purposes.
85 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean;
86 -- Returns true if the entity is a non-remote access type
88 function In_Shared_Passive_Unit
return Boolean;
89 -- Determines if current scope is within a Shared Passive compilation unit
91 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
92 -- Iterate through the list of discriminants to check if any of them
93 -- contains non-static default expression, which is a violation in
94 -- a preelaborated library unit.
96 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
97 -- Check validity of declaration if RCI or RT unit. It should not contain
98 -- the declaration of an access-to-object type unless it is a
99 -- general access type that designates a class-wide limited
100 -- private type. There are also constraints about the primitive
101 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
103 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean;
104 -- Return True if E is a limited private type, or if E is a private
105 -- extension of a type whose parent verifies this property (hence the
106 -- recursive keyword).
108 ---------------------------------------
109 -- Check_Categorization_Dependencies --
110 ---------------------------------------
112 procedure Check_Categorization_Dependencies
113 (Unit_Entity
: Entity_Id
;
114 Depended_Entity
: Entity_Id
;
116 Is_Subunit
: Boolean)
118 N
: constant Node_Id
:= Info_Node
;
120 type Categorization
is
121 (Pure
, Shared_Passive
, Remote_Types
,
122 Remote_Call_Interface
, Pre_Elaborated
, Normal
);
124 Unit_Category
: Categorization
;
125 With_Category
: Categorization
;
127 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
128 -- Check categorization flags from entity, and return in the form
129 -- of a corresponding enumeration value.
131 ------------------------
132 -- Get_Categorization --
133 ------------------------
135 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
137 if Is_Preelaborated
(E
) then
138 return Pre_Elaborated
;
139 elsif Is_Pure
(E
) then
141 elsif Is_Shared_Passive
(E
) then
142 return Shared_Passive
;
143 elsif Is_Remote_Types
(E
) then
145 elsif Is_Remote_Call_Interface
(E
) then
146 return Remote_Call_Interface
;
150 end Get_Categorization
;
152 -- Start of processing for Check_Categorization_Dependencies
155 -- Intrinsic subprograms are preelaborated, so do not impose any
156 -- categorization dependencies.
158 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
162 Unit_Category
:= Get_Categorization
(Unit_Entity
);
163 With_Category
:= Get_Categorization
(Depended_Entity
);
165 if With_Category
> Unit_Category
then
167 if (Unit_Category
= Remote_Types
168 or else Unit_Category
= Remote_Call_Interface
)
169 and then In_Package_Body
(Unit_Entity
)
173 elsif Is_Subunit
then
174 Error_Msg_NE
("subunit cannot depend on&"
175 & " (parent has wrong categorization)", N
, Depended_Entity
);
177 Error_Msg_NE
("current unit cannot depend on&"
178 & " (wrong categorization)", N
, Depended_Entity
);
182 end Check_Categorization_Dependencies
;
184 -----------------------------------
185 -- Check_Non_Static_Default_Expr --
186 -----------------------------------
188 procedure Check_Non_Static_Default_Expr
193 Component_Decl
: Node_Id
;
196 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
197 Recdef
:= Record_Extension_Part
(Type_Def
);
207 -- Check that component declarations do not involve:
209 -- a. a non-static default expression, where the object is
210 -- declared to be default initialized.
212 -- b. a dynamic Itype (discriminants and constraints)
214 if Null_Present
(Recdef
) then
217 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
220 while Present
(Component_Decl
)
221 and then Nkind
(Component_Decl
) = N_Component_Declaration
223 if Present
(Expression
(Component_Decl
))
224 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
225 and then not Is_Static_Expression
(Expression
(Component_Decl
))
227 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
229 ("object in preelaborated unit has non-static default#",
232 -- Fix this later ???
234 -- elsif Has_Dynamic_Itype (Component_Decl) then
236 -- ("dynamic type discriminant," &
237 -- " constraint in preelaborated unit",
241 Next
(Component_Decl
);
243 end Check_Non_Static_Default_Expr
;
245 ---------------------------
246 -- In_Preelaborated_Unit --
247 ---------------------------
249 function In_Preelaborated_Unit
return Boolean is
250 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
251 Unit_Kind
: constant Node_Kind
:=
252 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
255 -- There are no constraints on body of remote_call_interface or
256 -- remote_types packages..
258 return (Unit_Entity
/= Standard_Standard
)
259 and then (Is_Preelaborated
(Unit_Entity
)
260 or else Is_Pure
(Unit_Entity
)
261 or else Is_Shared_Passive
(Unit_Entity
)
263 ((Is_Remote_Types
(Unit_Entity
)
264 or else Is_Remote_Call_Interface
(Unit_Entity
))
265 and then Ekind
(Unit_Entity
) = E_Package
266 and then Unit_Kind
/= N_Package_Body
267 and then not In_Package_Body
(Unit_Entity
)
268 and then not In_Instance
));
269 end In_Preelaborated_Unit
;
275 function In_Pure_Unit
return Boolean is
277 return Is_Pure
(Current_Scope
);
280 ------------------------
281 -- In_RCI_Declaration --
282 ------------------------
284 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
285 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
286 Unit_Kind
: constant Node_Kind
:=
287 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
290 -- There are no restrictions on the private part or body
293 return Is_Remote_Call_Interface
(Unit_Entity
)
294 and then (Ekind
(Unit_Entity
) = E_Package
295 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
296 and then Unit_Kind
/= N_Package_Body
297 and then List_Containing
(N
) =
299 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
300 and then not In_Package_Body
(Unit_Entity
)
301 and then not In_Instance
;
302 end In_RCI_Declaration
;
304 -----------------------
305 -- In_RT_Declaration --
306 -----------------------
308 function In_RT_Declaration
return Boolean is
309 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
310 Unit_Kind
: constant Node_Kind
:=
311 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
314 -- There are no restrictions on the body of a Remote Types unit.
316 return Is_Remote_Types
(Unit_Entity
)
317 and then (Ekind
(Unit_Entity
) = E_Package
318 or else Ekind
(Unit_Entity
) = E_Generic_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_RT_Declaration
;
324 ----------------------------
325 -- In_Shared_Passive_Unit --
326 ----------------------------
328 function In_Shared_Passive_Unit
return Boolean is
329 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
332 return Is_Shared_Passive
(Unit_Entity
);
333 end In_Shared_Passive_Unit
;
335 ---------------------------------------
336 -- In_Subprogram_Task_Protected_Unit --
337 ---------------------------------------
339 function In_Subprogram_Task_Protected_Unit
return Boolean is
343 -- The following is to verify that a declaration is inside
344 -- subprogram, generic subprogram, task unit, protected unit.
345 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
347 -- Use scope chain to check successively outer scopes
353 Is_Generic_Subprogram
(E
)
355 Is_Concurrent_Type
(E
)
359 elsif E
= Standard_Standard
then
365 end In_Subprogram_Task_Protected_Unit
;
367 -------------------------------
368 -- Is_Non_Remote_Access_Type --
369 -------------------------------
371 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
373 return Is_Access_Type
(E
)
374 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
375 and then not Is_Remote_Access_To_Subprogram_Type
(E
);
376 end Is_Non_Remote_Access_Type
;
378 ------------------------------------
379 -- Is_Recursively_Limited_Private --
380 ------------------------------------
382 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean is
383 P
: constant Node_Id
:= Parent
(E
);
386 if Nkind
(P
) = N_Private_Type_Declaration
387 and then Is_Limited_Record
(E
)
390 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
391 return Is_Recursively_Limited_Private
(Etype
(E
));
392 elsif Nkind
(P
) = N_Formal_Type_Declaration
393 and then Ekind
(E
) = E_Record_Type_With_Private
394 and then Is_Generic_Type
(E
)
395 and then Is_Limited_Record
(E
)
401 end Is_Recursively_Limited_Private
;
403 ----------------------------------
404 -- Missing_Read_Write_Attribute --
405 ----------------------------------
407 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
408 Component
: Entity_Id
;
409 Component_Type
: Entity_Id
;
411 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
412 -- Return True if entity has Read and Write attributes
414 -------------------------------
415 -- Has_Read_Write_Attributes --
416 -------------------------------
418 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
419 Rep_Item
: Node_Id
:= First_Rep_Item
(E
);
420 Read_Attribute
: Boolean := False;
421 Write_Attribute
: Boolean := False;
424 -- We start from the declaration node and then loop until the end
425 -- of the list until we find those two attribute definition clauses.
427 while Present
(Rep_Item
) loop
428 if Chars
(Rep_Item
) = Name_Read
then
429 Read_Attribute
:= True;
430 elsif Chars
(Rep_Item
) = Name_Write
then
431 Write_Attribute
:= True;
434 if Read_Attribute
and Write_Attribute
then
438 Next_Rep_Item
(Rep_Item
);
442 end Has_Read_Write_Attributes
;
444 -- Start of processing for Missing_Read_Write_Attributes
447 if Has_Read_Write_Attributes
(E
) then
449 elsif Is_Non_Remote_Access_Type
(E
) then
453 if Is_Record_Type
(E
) then
454 Component
:= First_Entity
(E
);
455 while Present
(Component
) loop
456 Component_Type
:= Etype
(Component
);
458 if (Is_Non_Remote_Access_Type
(Component_Type
)
459 or else Is_Record_Type
(Component_Type
))
460 and then Missing_Read_Write_Attributes
(Component_Type
)
465 Next_Entity
(Component
);
470 end Missing_Read_Write_Attributes
;
472 -------------------------------------
473 -- Set_Categorization_From_Pragmas --
474 -------------------------------------
476 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
477 P
: constant Node_Id
:= Parent
(N
);
478 S
: constant Entity_Id
:= Current_Scope
;
480 procedure Set_Parents
(Visibility
: Boolean);
481 -- If this is a child instance, the parents are not immediately
482 -- visible during analysis. Make them momentarily visible so that
483 -- the argument of the pragma can be resolved properly, and reset
486 procedure Set_Parents
(Visibility
: Boolean) is
487 Par
: Entity_Id
:= Scope
(S
);
490 while Present
(Par
) and then Par
/= Standard_Standard
loop
491 Set_Is_Immediately_Visible
(Par
, Visibility
);
497 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
498 -- The purpose is to set categorization flags before analyzing the
499 -- unit itself, so as to diagnose violations of categorization as
500 -- we process each declaration, even though the pragma appears after
503 if Nkind
(P
) /= N_Compilation_Unit
then
508 PN
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
513 and then Is_Generic_Instance
(S
)
518 while Present
(PN
) loop
520 -- Skip implicit types that may have been introduced by
521 -- previous analysis.
523 if Nkind
(PN
) = N_Pragma
then
525 case Get_Pragma_Id
(Chars
(PN
)) is
526 when Pragma_All_Calls_Remote |
527 Pragma_Preelaborate |
529 Pragma_Remote_Call_Interface |
530 Pragma_Remote_Types |
531 Pragma_Shared_Passive
=> Analyze
(PN
);
539 and then Is_Generic_Instance
(S
)
545 end Set_Categorization_From_Pragmas
;
547 -----------------------------------
548 -- Set_Categorization_From_Scope --
549 -----------------------------------
551 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
552 Declaration
: Node_Id
:= Empty
;
553 Specification
: Node_Id
:= Empty
;
557 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
559 if not Is_Remote_Call_Interface
(E
) then
560 if Ekind
(E
) in Subprogram_Kind
then
561 Declaration
:= Unit_Declaration_Node
(E
);
564 or else Nkind
(Declaration
) = N_Subprogram_Body
565 or else Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
567 Specification
:= Corresponding_Spec
(Declaration
);
571 -- A subprogram body or renaming-as-body is a remote call
572 -- interface if it serves as the completion of a subprogram
573 -- declaration that is a remote call interface.
575 if Nkind
(Specification
) in N_Entity
then
576 Set_Is_Remote_Call_Interface
577 (E
, Is_Remote_Call_Interface
(Specification
));
579 -- A subprogram declaration is a remote call interface when it is
580 -- declared within the visible part of, or declared by, a library
581 -- unit declaration that is a remote call interface.
584 Set_Is_Remote_Call_Interface
585 (E
, Is_Remote_Call_Interface
(Scop
)
586 and then not (In_Private_Part
(Scop
)
587 or else In_Package_Body
(Scop
)));
591 Set_Is_Remote_Types
(E
, Is_Remote_Types
(Scop
));
592 end Set_Categorization_From_Scope
;
594 ------------------------------
595 -- Static_Discriminant_Expr --
596 ------------------------------
598 -- We need to accomodate a Why_Not_Static call somehow here ???
600 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
601 Discriminant_Spec
: Node_Id
;
604 Discriminant_Spec
:= First
(L
);
605 while Present
(Discriminant_Spec
) loop
606 if Present
(Expression
(Discriminant_Spec
))
607 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
612 Next
(Discriminant_Spec
);
616 end Static_Discriminant_Expr
;
618 --------------------------------------
619 -- Validate_Access_Type_Declaration --
620 --------------------------------------
622 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
623 Def
: constant Node_Id
:= Type_Definition
(N
);
627 when N_Access_To_Subprogram_Definition
=>
629 -- A pure library_item must not contain the declaration of a
630 -- named access type, except within a subprogram, generic
631 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
633 if Comes_From_Source
(T
)
634 and then In_Pure_Unit
635 and then not In_Subprogram_Task_Protected_Unit
637 Error_Msg_N
("named access type not allowed in pure unit", T
);
640 when N_Access_To_Object_Definition
=>
642 if Comes_From_Source
(T
)
643 and then In_Pure_Unit
644 and then not In_Subprogram_Task_Protected_Unit
647 ("named access type not allowed in pure unit", T
);
650 -- Check for RCI or RT unit type declaration. It should not
651 -- contain the declaration of an access-to-object type unless it
652 -- is a general access type that designates a class-wide limited
653 -- private type. There are also constraints about the primitive
654 -- subprograms of the class-wide type.
656 Validate_Remote_Access_Object_Type_Declaration
(T
);
658 -- Check for shared passive unit type declaration. It should
659 -- not contain the declaration of access to class wide type,
660 -- access to task type and access to protected type with entry.
662 Validate_SP_Access_Object_Type_Decl
(T
);
667 -- Set categorization flag from package on entity as well, to allow
668 -- easy checks later on for required validations of RCI or RT units.
669 -- This is only done for entities that are in the original source.
671 if Comes_From_Source
(T
)
672 and then not (In_Package_Body
(Scope
(T
))
673 or else In_Private_Part
(Scope
(T
)))
675 Set_Is_Remote_Call_Interface
676 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
678 (T
, Is_Remote_Types
(Scope
(T
)));
680 end Validate_Access_Type_Declaration
;
682 ----------------------------
683 -- Validate_Ancestor_Part --
684 ----------------------------
686 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
687 A
: constant Node_Id
:= Ancestor_Part
(N
);
688 T
: constant Entity_Id
:= Entity
(A
);
691 if In_Preelaborated_Unit
692 and then not In_Subprogram_Or_Concurrent_Unit
693 and then (not Inside_A_Generic
694 or else Present
(Enclosing_Generic_Body
(N
)))
696 -- We relax the restriction of 10.2.1(9) within GNAT
697 -- units to allow packages such as Ada.Strings.Unbounded
698 -- to be implemented (i.p., Null_Unbounded_String).
699 -- (There are ACVC tests that check that the restriction
700 -- is enforced, but note that AI-161, once approved,
701 -- will relax the restriction prohibiting default-
702 -- initialized objects of private and controlled
705 if Is_Private_Type
(T
)
706 and then not Is_Internal_File_Name
707 (Unit_File_Name
(Get_Source_Unit
(N
)))
710 ("private ancestor type not allowed in preelaborated unit", A
);
712 elsif Is_Record_Type
(T
) then
713 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
714 Check_Non_Static_Default_Expr
715 (Type_Definition
(Parent
(T
)), A
);
719 end Validate_Ancestor_Part
;
721 ----------------------------------------
722 -- Validate_Categorization_Dependency --
723 ----------------------------------------
725 procedure Validate_Categorization_Dependency
729 K
: constant Node_Kind
:= Nkind
(N
);
730 P
: Node_Id
:= Parent
(N
);
732 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
735 -- Only validate library units and subunits. For subunits, checks
736 -- concerning withed units apply to the parent compilation unit.
743 and then not Is_Compilation_Unit
(U
)
744 and then not Is_Child_Unit
(U
)
751 if Nkind
(P
) /= N_Compilation_Unit
then
755 -- Body of RCI unit does not need validation.
757 if Is_Remote_Call_Interface
(E
)
758 and then (Nkind
(N
) = N_Package_Body
759 or else Nkind
(N
) = N_Subprogram_Body
)
764 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
768 Entity_Of_Withed
: Entity_Id
;
771 Item
:= First
(Context_Items
(P
));
773 while Present
(Item
) loop
774 if Nkind
(Item
) = N_With_Clause
775 and then not (Implicit_With
(Item
)
776 or else Limited_Present
(Item
))
778 Entity_Of_Withed
:= Entity
(Name
(Item
));
779 Check_Categorization_Dependencies
780 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
787 -- Child depends on parent; therefore parent should also
788 -- be categorized and satify the dependency hierarchy.
790 -- Check if N is a child spec.
792 if (K
in N_Generic_Declaration
or else
793 K
in N_Generic_Instantiation
or else
794 K
in N_Generic_Renaming_Declaration
or else
795 K
= N_Package_Declaration
or else
796 K
= N_Package_Renaming_Declaration
or else
797 K
= N_Subprogram_Declaration
or else
798 K
= N_Subprogram_Renaming_Declaration
)
799 and then Present
(Parent_Spec
(N
))
801 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
803 -- Verify that public child of an RCI library unit
804 -- must also be an RCI library unit (RM E.2.3(15)).
806 if Is_Remote_Call_Interface
(Scope
(E
))
807 and then not Private_Present
(P
)
808 and then not Is_Remote_Call_Interface
(E
)
810 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
813 end Validate_Categorization_Dependency
;
815 --------------------------------
816 -- Validate_Controlled_Object --
817 --------------------------------
819 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
821 -- For now, never apply this check for internal GNAT units, since we
822 -- have a number of cases in the library where we are stuck with objects
823 -- of this type, and the RM requires Preelaborate.
825 -- For similar reasons, we only do this check for source entities, since
826 -- we generate entities of this type in some situations.
828 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
829 -- We have to enforce them for RM compatibility, but we have no trouble
830 -- accepting these objects and doing the right thing. Note that there is
831 -- no requirement that Preelaborate not actually generate any code!
833 if In_Preelaborated_Unit
834 and then not Debug_Flag_PP
835 and then Comes_From_Source
(E
)
837 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
838 and then (not Inside_A_Generic
839 or else Present
(Enclosing_Generic_Body
(E
)))
840 and then not Is_Protected_Type
(Etype
(E
))
843 ("library level controlled object not allowed in " &
844 "preelaborated unit", E
);
846 end Validate_Controlled_Object
;
848 --------------------------------------
849 -- Validate_Null_Statement_Sequence --
850 --------------------------------------
852 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
856 if In_Preelaborated_Unit
then
857 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
859 while Present
(Item
) loop
860 if Nkind
(Item
) /= N_Label
861 and then Nkind
(Item
) /= N_Null_Statement
864 ("statements not allowed in preelaborated unit", Item
);
871 end Validate_Null_Statement_Sequence
;
873 ---------------------------------
874 -- Validate_Object_Declaration --
875 ---------------------------------
877 procedure Validate_Object_Declaration
(N
: Node_Id
) is
878 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
879 E
: constant Node_Id
:= Expression
(N
);
880 Odf
: constant Node_Id
:= Object_Definition
(N
);
881 T
: constant Entity_Id
:= Etype
(Id
);
884 -- Verify that any access to subprogram object does not have in its
885 -- subprogram profile access type parameters or limited parameters
886 -- without Read and Write attributes (E.2.3(13)).
888 Validate_RCI_Subprogram_Declaration
(N
);
890 -- Check that if we are in preelaborated elaboration code, then we
891 -- do not have an instance of a default initialized private, task or
892 -- protected object declaration which would violate (RM 10.2.1(9)).
893 -- Note that constants are never default initialized (and the test
894 -- below also filters out deferred constants). A variable is default
895 -- initialized if it does *not* have an initialization expression.
897 -- Filter out cases that are not declaration of a variable from source
899 if Nkind
(N
) /= N_Object_Declaration
900 or else Constant_Present
(N
)
901 or else not Comes_From_Source
(Id
)
906 -- Exclude generic specs from the checks (this will get rechecked
907 -- on instantiations).
910 and then not Present
(Enclosing_Generic_Body
(Id
))
915 -- Required checks for declaration that is in a preelaborated
916 -- package and is not within some subprogram.
918 if In_Preelaborated_Unit
919 and then not In_Subprogram_Or_Concurrent_Unit
921 -- Check for default initialized variable case. Note that in
922 -- accordance with (RM B.1(24)) imported objects are not
923 -- subject to default initialization.
925 if No
(E
) and then not Is_Imported
(Id
) then
927 Ent
: Entity_Id
:= T
;
930 -- An array whose component type is a record with nonstatic
931 -- default expressions is a violation, so we get the array's
934 if Is_Array_Type
(Ent
) then
936 Comp_Type
: Entity_Id
:= Component_Type
(Ent
);
939 while Is_Array_Type
(Comp_Type
) loop
940 Comp_Type
:= Component_Type
(Comp_Type
);
947 -- Object decl. that is of record type and has no default expr.
948 -- should check if there is any non-static default expression
949 -- in component decl. of the record type decl.
951 if Is_Record_Type
(Ent
) then
952 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
953 Check_Non_Static_Default_Expr
954 (Type_Definition
(Parent
(Ent
)), N
);
956 elsif Nkind
(Odf
) = N_Subtype_Indication
957 and then not Is_Array_Type
(T
)
958 and then not Is_Private_Type
(T
)
960 Check_Non_Static_Default_Expr
(Type_Definition
961 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
965 -- We relax the restriction of 10.2.1(9) within GNAT
966 -- units. (There are ACVC tests that check that the
967 -- restriction is enforced, but note that AI-161,
968 -- once approved, will relax the restriction prohibiting
969 -- default-initialized objects of private types, and
970 -- will recommend a pragma for marking private types.)
972 if (Is_Private_Type
(Ent
)
973 or else Depends_On_Private
(Ent
))
974 and then not Is_Internal_File_Name
975 (Unit_File_Name
(Get_Source_Unit
(N
)))
978 ("private object not allowed in preelaborated unit", N
);
981 -- Access to Task or Protected type
983 elsif Is_Entity_Name
(Odf
)
984 and then Present
(Etype
(Odf
))
985 and then Is_Access_Type
(Etype
(Odf
))
987 Ent
:= Designated_Type
(Etype
(Odf
));
989 elsif Is_Entity_Name
(Odf
) then
992 elsif Nkind
(Odf
) = N_Subtype_Indication
then
993 Ent
:= Etype
(Subtype_Mark
(Odf
));
996 Nkind
(Odf
) = N_Constrained_Array_Definition
998 Ent
:= Component_Type
(T
);
1004 if Is_Task_Type
(Ent
)
1005 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1008 ("concurrent object not allowed in preelaborated unit",
1015 -- Non-static discriminant not allowed in preelaborayted unit
1017 if Is_Record_Type
(Etype
(Id
)) then
1019 ET
: constant Entity_Id
:= Etype
(Id
);
1020 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1024 if Has_Discriminants
(ET
)
1025 and then Present
(EE
)
1029 if Nkind
(PEE
) = N_Full_Type_Declaration
1030 and then not Static_Discriminant_Expr
1031 (Discriminant_Specifications
(PEE
))
1034 ("non-static discriminant in preelaborated unit",
1042 -- A pure library_item must not contain the declaration of any
1043 -- variable except within a subprogram, generic subprogram, task
1044 -- unit or protected unit (RM 10.2.1(16)).
1047 and then not In_Subprogram_Task_Protected_Unit
1049 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1051 -- The visible part of an RCI library unit must not contain the
1052 -- declaration of a variable (RM E.1.3(9))
1054 elsif In_RCI_Declaration
(N
) then
1055 Error_Msg_N
("declaration of variable not allowed in rci unit", N
);
1057 -- The visible part of a Shared Passive library unit must not contain
1058 -- the declaration of a variable (RM E.2.2(7))
1060 elsif In_RT_Declaration
then
1062 ("variable declaration not allowed in remote types unit", N
);
1065 end Validate_Object_Declaration
;
1067 -------------------------------
1068 -- Validate_RCI_Declarations --
1069 -------------------------------
1071 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1075 E
:= First_Entity
(P
);
1076 while Present
(E
) loop
1077 if Comes_From_Source
(E
) then
1078 if Is_Limited_Type
(E
) then
1080 ("Limited type not allowed in rci unit", Parent
(E
));
1081 Explain_Limited_Type
(E
, Parent
(E
));
1083 elsif Ekind
(E
) = E_Generic_Function
1084 or else Ekind
(E
) = E_Generic_Package
1085 or else Ekind
(E
) = E_Generic_Procedure
1087 Error_Msg_N
("generic declaration not allowed in rci unit",
1090 elsif (Ekind
(E
) = E_Function
1091 or else Ekind
(E
) = E_Procedure
)
1092 and then Has_Pragma_Inline
(E
)
1095 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1097 -- Inner packages that are renamings need not be checked.
1098 -- Generic RCI packages are subject to the checks, but
1099 -- entities that come from formal packages are not part of the
1100 -- visible declarations of the package and are not checked.
1102 elsif Ekind
(E
) = E_Package
then
1103 if Present
(Renamed_Entity
(E
)) then
1106 elsif Ekind
(P
) /= E_Generic_Package
1107 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1108 Generic_Formal_Declarations
1109 (Unit_Declaration_Node
(P
))
1111 Validate_RCI_Declarations
(E
);
1118 end Validate_RCI_Declarations
;
1120 -----------------------------------------
1121 -- Validate_RCI_Subprogram_Declaration --
1122 -----------------------------------------
1124 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1125 K
: constant Node_Kind
:= Nkind
(N
);
1128 Param_Spec
: Node_Id
;
1129 Param_Type
: Entity_Id
;
1130 Base_Param_Type
: Entity_Id
;
1131 Type_Decl
: Node_Id
;
1132 Error_Node
: Node_Id
:= N
;
1135 -- There are two possible cases in which this procedure is called:
1137 -- 1. called from Analyze_Subprogram_Declaration.
1138 -- 2. called from Validate_Object_Declaration (access to subprogram).
1140 if not In_RCI_Declaration
(N
) then
1144 if K
= N_Subprogram_Declaration
then
1145 Profile
:= Parameter_Specifications
(Specification
(N
));
1147 else pragma Assert
(K
= N_Object_Declaration
);
1148 Id
:= Defining_Identifier
(N
);
1150 if Nkind
(Id
) = N_Defining_Identifier
1151 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1152 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1155 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1161 -- Iterate through the parameter specification list, checking that
1162 -- no access parameter and no limited type parameter in the list.
1165 if Present
(Profile
) then
1166 Param_Spec
:= First
(Profile
);
1168 while Present
(Param_Spec
) loop
1169 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1170 Type_Decl
:= Parent
(Param_Type
);
1172 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1174 if K
= N_Subprogram_Declaration
then
1175 Error_Node
:= Param_Spec
;
1178 -- Report error only if declaration is in source program.
1180 if Comes_From_Source
1181 (Defining_Entity
(Specification
(N
)))
1184 ("subprogram in rci unit cannot have access parameter",
1188 -- For limited private type parameter, we check only the
1189 -- private declaration and ignore full type declaration,
1190 -- unless this is the only declaration for the type, eg.
1191 -- as a limited record.
1193 elsif Is_Limited_Type
(Param_Type
)
1194 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1196 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1197 and then not (Has_Private_Declaration
(Param_Type
))
1198 and then Comes_From_Source
(N
)))
1200 -- A limited parameter is legal only if user-specified
1201 -- Read and Write attributes exist for it.
1202 -- second part of RM E.2.3 (14)
1204 if No
(Full_View
(Param_Type
))
1205 and then Ekind
(Param_Type
) /= E_Record_Type
1207 -- Type does not have completion yet, so if declared in
1208 -- in the current RCI scope it is illegal, and will be
1209 -- flagged subsequently.
1213 Base_Param_Type
:= Base_Type
(Underlying_Type
(Param_Type
));
1215 if No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1217 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1219 if K
= N_Subprogram_Declaration
then
1220 Error_Node
:= Param_Spec
;
1224 ("limited parameter in rci unit "
1225 & "must have read/write attributes ", Error_Node
);
1226 Explain_Limited_Type
(Param_Type
, Error_Node
);
1233 end Validate_RCI_Subprogram_Declaration
;
1235 ----------------------------------------------------
1236 -- Validate_Remote_Access_Object_Type_Declaration --
1237 ----------------------------------------------------
1239 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1240 Direct_Designated_Type
: Entity_Id
;
1241 Desig_Type
: Entity_Id
;
1242 Primitive_Subprograms
: Elist_Id
;
1243 Subprogram
: Elmt_Id
;
1244 Subprogram_Node
: Node_Id
;
1246 Param_Spec
: Node_Id
;
1247 Param_Type
: Entity_Id
;
1250 -- We are called from Analyze_Type_Declaration, and the Nkind
1251 -- of the given node is N_Access_To_Object_Definition.
1253 if not Comes_From_Source
(T
)
1254 or else (not In_RCI_Declaration
(Parent
(T
))
1255 and then not In_RT_Declaration
)
1260 -- An access definition in the private part of a Remote Types package
1261 -- may be legal if it has user-defined Read and Write attributes. This
1262 -- will be checked at the end of the package spec processing.
1264 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1268 -- Check RCI or RT unit type declaration. It may not contain
1269 -- the declaration of an access-to-object type unless it is a
1270 -- general access type that designates a class-wide limited
1271 -- private type. There are also constraints about the primitive
1272 -- subprograms of the class-wide type (RM E.2.3(14)).
1274 if Ekind
(T
) /= E_General_Access_Type
1275 or else Ekind
(Designated_Type
(T
)) /= E_Class_Wide_Type
1277 if In_RCI_Declaration
(Parent
(T
)) then
1279 ("access type in Remote_Call_Interface unit must be " &
1280 "general access", T
);
1282 Error_Msg_N
("access type in Remote_Types unit must be " &
1283 "general access", T
);
1285 Error_Msg_N
("\to class-wide type", T
);
1289 Direct_Designated_Type
:= Designated_Type
(T
);
1290 Desig_Type
:= Etype
(Direct_Designated_Type
);
1292 if not Is_Recursively_Limited_Private
(Desig_Type
) then
1294 ("error in designated type of remote access to class-wide type", T
);
1296 ("\must be tagged limited private or private extension of type", T
);
1300 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1301 Subprogram
:= First_Elmt
(Primitive_Subprograms
);
1303 while Subprogram
/= No_Elmt
loop
1304 Subprogram_Node
:= Node
(Subprogram
);
1306 if not Comes_From_Source
(Subprogram_Node
) then
1307 goto Next_Subprogram
;
1310 Profile
:= Parameter_Specifications
(Parent
(Subprogram_Node
));
1312 -- Profile must exist, otherwise not primitive operation
1314 Param_Spec
:= First
(Profile
);
1316 while Present
(Param_Spec
) loop
1318 -- Now find out if this parameter is a controlling parameter
1320 Param_Type
:= Parameter_Type
(Param_Spec
);
1322 if (Nkind
(Param_Type
) = N_Access_Definition
1323 and then Etype
(Subtype_Mark
(Param_Type
)) = Desig_Type
)
1324 or else (Nkind
(Param_Type
) /= N_Access_Definition
1325 and then Etype
(Param_Type
) = Desig_Type
)
1327 -- It is a controlling parameter, so specific checks below
1333 Nkind
(Param_Type
) = N_Access_Definition
1335 -- From RM E.2.2(14), no access parameter other than
1336 -- controlling ones may be used.
1339 ("non-controlling access parameter", Param_Spec
);
1342 Is_Limited_Type
(Etype
(Defining_Identifier
(Param_Spec
)))
1344 -- Not a controlling parameter, so type must have Read
1345 -- and Write attributes.
1347 if Nkind
(Param_Type
) in N_Has_Etype
1348 and then Nkind
(Parent
(Etype
(Param_Type
))) =
1349 N_Private_Type_Declaration
1351 Param_Type
:= Etype
(Param_Type
);
1353 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1355 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1358 ("limited formal must have Read and Write attributes",
1360 Explain_Limited_Type
1361 (Etype
(Defining_Identifier
(Param_Spec
)), Param_Spec
);
1366 -- Check next parameter in this subprogram
1372 Next_Elmt
(Subprogram
);
1375 -- Now this is an RCI unit access-to-class-wide-limited-private type
1376 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1377 -- optimize later checks by avoiding tree traversal to find out if this
1378 -- entity is inside an RCI unit.
1380 Set_Is_Remote_Call_Interface
(T
);
1382 end Validate_Remote_Access_Object_Type_Declaration
;
1384 -----------------------------------------------
1385 -- Validate_Remote_Access_To_Class_Wide_Type --
1386 -----------------------------------------------
1388 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1389 K
: constant Node_Kind
:= Nkind
(N
);
1390 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1394 -- This subprogram enforces the checks in (RM E.2.2(8)) for
1395 -- certain uses of class-wide limited private types.
1397 -- Storage_Pool and Storage_Size are not defined for such types
1399 -- The expected type of allocator must not not be such a type.
1401 -- The actual parameter of generic instantiation must not
1402 -- be such a type if the formal parameter is of an access type.
1404 -- On entry, there are five cases
1406 -- 1. called from sem_attr Analyze_Attribute where attribute
1407 -- name is either Storage_Pool or Storage_Size.
1409 -- 2. called from exp_ch4 Expand_N_Allocator
1411 -- 3. called from sem_ch12 Analyze_Associations
1413 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1415 -- 5. called from sem_res Resolve_Actuals
1417 if K
= N_Attribute_Reference
then
1418 E
:= Etype
(Prefix
(N
));
1420 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1421 Error_Msg_N
("incorrect attribute of remote operand", N
);
1425 elsif K
= N_Allocator
then
1428 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1429 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1433 elsif K
in N_Has_Entity
then
1436 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1437 Error_Msg_N
("incorrect remote type generic actual", N
);
1441 -- This subprogram also enforces the checks in E.2.2(13).
1442 -- A value of such type must not be dereferenced unless as a
1443 -- controlling operand of a dispatching call.
1445 elsif K
= N_Explicit_Dereference
1446 and then (Comes_From_Source
(N
)
1447 or else (Nkind
(Original_Node
(N
)) = N_Selected_Component
1448 and then Comes_From_Source
(Original_Node
(N
))))
1450 E
:= Etype
(Prefix
(N
));
1452 -- If the class-wide type is not a remote one, the restrictions
1455 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1459 -- If we have a true dereference that comes from source and that
1460 -- is a controlling argument for a dispatching call, accept it.
1462 if K
= N_Explicit_Dereference
1463 and then Is_Actual_Parameter
(N
)
1464 and then Is_Controlling_Actual
(N
)
1469 -- If we are just within a procedure or function call and the
1470 -- dereference has not been analyzed, return because this
1471 -- procedure will be called again from sem_res Resolve_Actuals.
1473 if Is_Actual_Parameter
(N
)
1474 and then not Analyzed
(N
)
1479 -- The following is to let the compiler generated tags check
1480 -- pass through without error message. This is a bit kludgy
1481 -- isn't there some better way of making this exclusion ???
1483 if (PK
= N_Selected_Component
1484 and then Present
(Parent
(Parent
(N
)))
1485 and then Nkind
(Parent
(Parent
(N
))) = N_Op_Ne
)
1486 or else (PK
= N_Unchecked_Type_Conversion
1487 and then Present
(Parent
(Parent
(N
)))
1489 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
)
1494 -- The following code is needed for expansion of RACW Write
1495 -- attribute, since such expressions can appear in the expanded
1498 if not Comes_From_Source
(N
)
1501 or else PK
= N_Attribute_Reference
1503 (PK
= N_Type_Conversion
1504 and then Present
(Parent
(N
))
1505 and then Present
(Parent
(Parent
(N
)))
1507 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
))
1512 Error_Msg_N
("incorrect remote type dereference", N
);
1514 end Validate_Remote_Access_To_Class_Wide_Type
;
1516 ------------------------------------------
1517 -- Validate_Remote_Type_Type_Conversion --
1518 ------------------------------------------
1520 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1521 S
: constant Entity_Id
:= Etype
(N
);
1522 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1525 -- This test is required in the case where a conversion appears
1526 -- inside a normal package, it does not necessarily have to be
1527 -- inside an RCI, Remote_Types unit (RM E.2.2(9,12)).
1529 if Is_Remote_Access_To_Subprogram_Type
(E
)
1530 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1532 Error_Msg_N
("incorrect conversion of remote operand", N
);
1535 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1536 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1538 Error_Msg_N
("incorrect conversion of remote operand", N
);
1542 -- If a local access type is converted into a RACW type, then the
1543 -- current unit has a pointer that may now be exported to another
1546 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1547 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1549 Set_Has_RACW
(Current_Sem_Unit
);
1551 end Validate_Remote_Type_Type_Conversion
;
1553 -------------------------------
1554 -- Validate_RT_RAT_Component --
1555 -------------------------------
1557 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1558 Spec
: constant Node_Id
:= Specification
(N
);
1559 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1561 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1562 In_Visible_Part
: Boolean := True;
1565 if not Is_Remote_Types
(Name_U
) then
1569 Typ
:= First_Entity
(Name_U
);
1570 while Present
(Typ
) loop
1571 if In_Visible_Part
and then Typ
= First_Priv_Ent
then
1572 In_Visible_Part
:= False;
1575 if Comes_From_Source
(Typ
)
1576 and then Is_Type
(Typ
)
1577 and then (In_Visible_Part
or else Has_Private_Declaration
(Typ
))
1579 if Missing_Read_Write_Attributes
(Typ
) then
1580 if Is_Non_Remote_Access_Type
(Typ
) then
1582 ("non-remote access type without user-defined Read " &
1583 "and Write attributes", Typ
);
1586 ("record type containing a component of a " &
1587 "non-remote access", Typ
);
1589 ("\type without Read and Write attributes " &
1590 "('R'M E.2.2(8))", Typ
);
1597 end Validate_RT_RAT_Component
;
1599 -----------------------------------------
1600 -- Validate_SP_Access_Object_Type_Decl --
1601 -----------------------------------------
1603 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
1604 Direct_Designated_Type
: Entity_Id
;
1606 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
1607 -- Return true if the protected type designated by T has
1608 -- entry declarations.
1610 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
1614 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
1615 Ety
:= First_Entity
(E
);
1616 while Present
(Ety
) loop
1617 if Ekind
(Ety
) = E_Entry
then
1626 end Has_Entry_Declarations
;
1628 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1631 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1632 -- Nkind of the given entity is N_Access_To_Object_Definition.
1634 if not Comes_From_Source
(T
)
1635 or else not In_Shared_Passive_Unit
1636 or else In_Subprogram_Task_Protected_Unit
1641 -- Check Shared Passive unit. It should not contain the declaration
1642 -- of an access-to-object type whose designated type is a class-wide
1643 -- type, task type or protected type with entry (RM E.2.1(7)).
1645 Direct_Designated_Type
:= Designated_Type
(T
);
1647 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
1649 ("invalid access-to-class-wide type in shared passive unit", T
);
1652 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
1654 ("invalid access-to-task type in shared passive unit", T
);
1657 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
1658 and then Has_Entry_Declarations
(Direct_Designated_Type
)
1661 ("invalid access-to-protected type in shared passive unit", T
);
1664 end Validate_SP_Access_Object_Type_Decl
;
1666 ---------------------------------
1667 -- Validate_Static_Object_Name --
1668 ---------------------------------
1670 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
1673 function Is_Primary
(N
: Node_Id
) return Boolean;
1674 -- Determine whether node is syntactically a primary in an expression.
1676 function Is_Primary
(N
: Node_Id
) return Boolean is
1677 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1682 when N_Op | N_In | N_Not_In
=>
1686 | N_Component_Association
1687 | N_Index_Or_Discriminant_Constraint
=>
1690 when N_Attribute_Reference
=>
1691 return Attribute_Name
(Parent
(N
)) /= Name_Address
1692 and then Attribute_Name
(Parent
(N
)) /= Name_Access
1693 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
1695 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
1697 when N_Indexed_Component
=>
1698 return (N
/= Prefix
(Parent
(N
))
1699 or else Is_Primary
(Parent
(N
)));
1701 when N_Qualified_Expression | N_Type_Conversion
=>
1702 return Is_Primary
(Parent
(N
));
1704 when N_Assignment_Statement | N_Object_Declaration
=>
1705 return (N
= Expression
(Parent
(N
)));
1707 when N_Selected_Component
=>
1708 return Is_Primary
(Parent
(N
));
1715 -- Start of processing for Validate_Static_Object_Name
1718 if not In_Preelaborated_Unit
1719 or else not Comes_From_Source
(N
)
1720 or else In_Subprogram_Or_Concurrent_Unit
1721 or else Ekind
(Current_Scope
) = E_Block
1725 -- Filter out cases where primary is default in a component
1726 -- declaration, discriminant specification, or actual in a record
1727 -- type initialization call.
1729 -- Initialization call of internal types.
1731 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
1733 if Present
(Parent
(Parent
(N
)))
1734 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
1739 if Nkind
(Name
(Parent
(N
))) = N_Identifier
1740 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
1746 -- Error if the name is a primary in an expression. The parent must not
1747 -- be an operator, or a selected component or an indexed component that
1748 -- is itself a primary. Entities that are actuals do not need to be
1749 -- checked, because the call itself will be diagnosed.
1752 and then (not Inside_A_Generic
1753 or else Present
(Enclosing_Generic_Body
(N
)))
1755 if Ekind
(Entity
(N
)) = E_Variable
then
1756 Flag_Non_Static_Expr
1757 ("non-static object name in preelaborated unit", N
);
1759 -- We take the view that a constant defined in another preelaborated
1760 -- unit is preelaborable, even though it may have a private type and
1761 -- thus appear non-static in a client. This must be the intent of
1762 -- the language, but currently is an RM gap.
1764 elsif Ekind
(Entity
(N
)) = E_Constant
1765 and then not Is_Static_Expression
(N
)
1769 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
1771 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
1772 and then (Is_Preelaborated
(Scope
(E
))
1773 or else Is_Pure
(Scope
(E
))
1774 or else (Present
(Renamed_Object
(E
))
1776 Is_Entity_Name
(Renamed_Object
(E
))
1779 (Scope
(Renamed_Object
(E
)))
1782 (Renamed_Object
(E
))))))
1786 Flag_Non_Static_Expr
1787 ("non-static constant in preelaborated unit", N
);
1791 end Validate_Static_Object_Name
;