1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Fname
; use Fname
;
33 with Namet
; use Namet
;
34 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 subcomponents is of an access
74 -- type that does not have user-defined Read and Write attributes visible
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 type whose full view is a non-remote
88 -- access type, for the purpose of enforcing E.2.2(8) rules.
90 function In_Shared_Passive_Unit
return Boolean;
91 -- Determines if current scope is within a Shared Passive compilation unit
93 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean;
94 -- Iterate through the list of discriminants to check if any of them
95 -- contains non-static default expression, which is a violation in
96 -- a preelaborated library unit.
98 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
);
99 -- Check validity of declaration if RCI or RT unit. It should not contain
100 -- the declaration of an access-to-object type unless it is a
101 -- general access type that designates a class-wide limited
102 -- private type. There are also constraints about the primitive
103 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
105 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean;
106 -- Return True if E is a limited private type, or if E is a private
107 -- extension of a type whose parent verifies this property (hence the
108 -- recursive keyword).
110 ---------------------------------------
111 -- Check_Categorization_Dependencies --
112 ---------------------------------------
114 procedure Check_Categorization_Dependencies
115 (Unit_Entity
: Entity_Id
;
116 Depended_Entity
: Entity_Id
;
118 Is_Subunit
: Boolean)
120 N
: constant Node_Id
:= Info_Node
;
122 -- Here we define an enumeration type to represent categorization types,
123 -- ordered so that a unit with a given categorization can only WITH
124 -- units with lower or equal categorization type.
126 -- Note that we take advantage of E.2(14) to define a category
127 -- Preelaborated and treat pragma Preelaborate as a categorization
128 -- pragma that defines that category.
130 type Categorization
is
134 Remote_Call_Interface
,
138 function Get_Categorization
(E
: Entity_Id
) return Categorization
;
139 -- Check categorization flags from entity, and return in the form
140 -- of the lowest value of the Categorization type that applies to E.
142 ------------------------
143 -- Get_Categorization --
144 ------------------------
146 function Get_Categorization
(E
: Entity_Id
) return Categorization
is
148 -- Get the lowest categorization that corresponds to E. Note that
149 -- nothing prevents several (different) categorization pragmas
150 -- to apply to the same library unit, in which case the unit has
151 -- all associated categories, so we need to be careful here to
152 -- check pragmas in proper Categorization order in order to
153 -- return the lowest appplicable value.
155 -- Ignore Pure specification if set by pragma Pure_Function
159 (Has_Pragma_Pure_Function
(E
) and not Has_Pragma_Pure
(E
))
163 elsif Is_Shared_Passive
(E
) then
164 return Shared_Passive
;
166 elsif Is_Remote_Types
(E
) then
169 elsif Is_Remote_Call_Interface
(E
) then
170 return Remote_Call_Interface
;
172 elsif Is_Preelaborated
(E
) then
173 return Preelaborated
;
178 end Get_Categorization
;
180 Unit_Category
: Categorization
;
181 With_Category
: Categorization
;
183 -- Start of processing for Check_Categorization_Dependencies
186 -- Intrinsic subprograms are preelaborated, so do not impose any
187 -- categorization dependencies.
189 if Is_Intrinsic_Subprogram
(Depended_Entity
) then
193 Unit_Category
:= Get_Categorization
(Unit_Entity
);
194 With_Category
:= Get_Categorization
(Depended_Entity
);
196 -- These messages are wanings in GNAT mode, to allow it to be
197 -- judiciously turned off. Otherwise it is a real error.
199 Error_Msg_Warn
:= GNAT_Mode
;
201 -- Check for possible error
203 if With_Category
> Unit_Category
then
205 -- Special case: Remote_Types and Remote_Call_Interface are allowed
206 -- to be with'ed in package body.
208 if (Unit_Category
= Remote_Types
209 or else Unit_Category
= Remote_Call_Interface
)
210 and then In_Package_Body
(Unit_Entity
)
214 -- Here we have an error
219 ("<subunit cannot depend on& " &
220 "(parent has wrong categorization)", N
, Depended_Entity
);
224 ("<cannot depend on& " &
225 "(wrong categorization)", N
, Depended_Entity
);
228 -- Add further explanation for common cases
230 case Unit_Category
is
233 ("\<pure unit cannot depend on non-pure unit",
236 when Preelaborated
=>
238 ("\<preelaborated unit cannot depend on " &
239 "non-preelaborated unit",
247 end Check_Categorization_Dependencies
;
249 -----------------------------------
250 -- Check_Non_Static_Default_Expr --
251 -----------------------------------
253 procedure Check_Non_Static_Default_Expr
258 Component_Decl
: Node_Id
;
261 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
262 Recdef
:= Record_Extension_Part
(Type_Def
);
272 -- Check that component declarations do not involve:
274 -- a. a non-static default expression, where the object is
275 -- declared to be default initialized.
277 -- b. a dynamic Itype (discriminants and constraints)
279 if Null_Present
(Recdef
) then
282 Component_Decl
:= First
(Component_Items
(Component_List
(Recdef
)));
285 while Present
(Component_Decl
)
286 and then Nkind
(Component_Decl
) = N_Component_Declaration
288 if Present
(Expression
(Component_Decl
))
289 and then Nkind
(Expression
(Component_Decl
)) /= N_Null
290 and then not Is_Static_Expression
(Expression
(Component_Decl
))
292 Error_Msg_Sloc
:= Sloc
(Component_Decl
);
294 ("object in preelaborated unit has non-static default#",
297 -- Fix this later ???
299 -- elsif Has_Dynamic_Itype (Component_Decl) then
301 -- ("dynamic type discriminant," &
302 -- " constraint in preelaborated unit",
306 Next
(Component_Decl
);
308 end Check_Non_Static_Default_Expr
;
310 -------------------------------------
311 -- Has_Stream_Attribute_Definition --
312 -------------------------------------
314 function Has_Stream_Attribute_Definition
317 At_Any_Place
: Boolean := False) return Boolean
321 -- We start from the declaration node and then loop until the end of
322 -- the list until we find the requested attribute definition clause.
323 -- In Ada 2005 mode, clauses are ignored if they are not currently
324 -- visible (this is tested using the corresponding Entity, which is
325 -- inserted by the expander at the point where the clause occurs),
326 -- unless At_Any_Place is true.
328 Rep_Item
:= First_Rep_Item
(Typ
);
329 while Present
(Rep_Item
) loop
330 if Nkind
(Rep_Item
) = N_Attribute_Definition_Clause
then
331 case Chars
(Rep_Item
) is
333 exit when Nam
= TSS_Stream_Read
;
336 exit when Nam
= TSS_Stream_Write
;
339 exit when Nam
= TSS_Stream_Input
;
342 exit when Nam
= TSS_Stream_Output
;
350 Next_Rep_Item
(Rep_Item
);
353 -- If At_Any_Place is true, return True if the attribute is available
354 -- at any place; if it is false, return True only if the attribute is
355 -- currently visible.
357 return Present
(Rep_Item
)
358 and then (Ada_Version
< Ada_05
360 or else not Is_Hidden
(Entity
(Rep_Item
)));
361 end Has_Stream_Attribute_Definition
;
363 ---------------------------
364 -- In_Preelaborated_Unit --
365 ---------------------------
367 function In_Preelaborated_Unit
return Boolean is
368 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
369 Unit_Kind
: constant Node_Kind
:=
370 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
373 -- There are no constraints on body of remote_call_interface or
374 -- remote_types packages.
376 return (Unit_Entity
/= Standard_Standard
)
377 and then (Is_Preelaborated
(Unit_Entity
)
378 or else Is_Pure
(Unit_Entity
)
379 or else Is_Shared_Passive
(Unit_Entity
)
381 ((Is_Remote_Types
(Unit_Entity
)
382 or else Is_Remote_Call_Interface
(Unit_Entity
))
383 and then Ekind
(Unit_Entity
) = E_Package
384 and then Unit_Kind
/= N_Package_Body
385 and then not In_Package_Body
(Unit_Entity
)
386 and then not In_Instance
));
387 end In_Preelaborated_Unit
;
393 function In_Pure_Unit
return Boolean is
395 return Is_Pure
(Current_Scope
);
398 ------------------------
399 -- In_RCI_Declaration --
400 ------------------------
402 function In_RCI_Declaration
(N
: Node_Id
) return Boolean is
403 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
404 Unit_Kind
: constant Node_Kind
:=
405 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
408 -- There are no restrictions on the private part or body
411 return Is_Remote_Call_Interface
(Unit_Entity
)
412 and then (Ekind
(Unit_Entity
) = E_Package
413 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
414 and then Unit_Kind
/= N_Package_Body
415 and then List_Containing
(N
) =
417 (Specification
(Unit_Declaration_Node
(Unit_Entity
)))
418 and then not In_Package_Body
(Unit_Entity
)
419 and then not In_Instance
;
420 end In_RCI_Declaration
;
422 -----------------------
423 -- In_RT_Declaration --
424 -----------------------
426 function In_RT_Declaration
return Boolean is
427 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
428 Unit_Kind
: constant Node_Kind
:=
429 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
432 -- There are no restrictions on the body of a Remote Types unit
434 return Is_Remote_Types
(Unit_Entity
)
435 and then (Ekind
(Unit_Entity
) = E_Package
436 or else Ekind
(Unit_Entity
) = E_Generic_Package
)
437 and then Unit_Kind
/= N_Package_Body
438 and then not In_Package_Body
(Unit_Entity
)
439 and then not In_Instance
;
440 end In_RT_Declaration
;
442 ----------------------------
443 -- In_Shared_Passive_Unit --
444 ----------------------------
446 function In_Shared_Passive_Unit
return Boolean is
447 Unit_Entity
: constant Entity_Id
:= Current_Scope
;
450 return Is_Shared_Passive
(Unit_Entity
);
451 end In_Shared_Passive_Unit
;
453 ---------------------------------------
454 -- In_Subprogram_Task_Protected_Unit --
455 ---------------------------------------
457 function In_Subprogram_Task_Protected_Unit
return Boolean is
461 -- The following is to verify that a declaration is inside
462 -- subprogram, generic subprogram, task unit, protected unit.
463 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
465 -- Use scope chain to check successively outer scopes
471 Is_Generic_Subprogram
(E
)
473 Is_Concurrent_Type
(E
)
477 elsif E
= Standard_Standard
then
483 end In_Subprogram_Task_Protected_Unit
;
485 -------------------------------
486 -- Is_Non_Remote_Access_Type --
487 -------------------------------
489 function Is_Non_Remote_Access_Type
(E
: Entity_Id
) return Boolean is
490 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
494 -- This case arises for the case of a generic formal type, in which
495 -- case E.2.2(8) rules will be enforced at instantiation time.
500 return Is_Access_Type
(U_E
)
501 and then not Is_Remote_Access_To_Class_Wide_Type
(U_E
)
502 and then not Is_Remote_Access_To_Subprogram_Type
(U_E
);
503 end Is_Non_Remote_Access_Type
;
505 ------------------------------------
506 -- Is_Recursively_Limited_Private --
507 ------------------------------------
509 function Is_Recursively_Limited_Private
(E
: Entity_Id
) return Boolean is
510 P
: constant Node_Id
:= Parent
(E
);
513 if Nkind
(P
) = N_Private_Type_Declaration
514 and then Is_Limited_Record
(E
)
518 -- A limited interface is not currently a legal ancestor for the
519 -- designated type of an RACW type, because a type that implements
520 -- such an interface need not be limited. However, the ARG seems to
521 -- incline towards allowing an access to classwide limited interface
522 -- type as a remote access type. This may be revised when the ARG
523 -- rules on this question, but it seems safe to allow it for now,
524 -- in order to see whether it is a useful extension for distributed
525 -- programming, in particular for Brad Moore's buffer taxonomy.
527 elsif Is_Limited_Record
(E
)
528 and then Is_Limited_Interface
(E
)
532 elsif Nkind
(P
) = N_Private_Extension_Declaration
then
533 return Is_Recursively_Limited_Private
(Etype
(E
));
535 elsif Nkind
(P
) = N_Formal_Type_Declaration
536 and then Ekind
(E
) = E_Record_Type_With_Private
537 and then Is_Generic_Type
(E
)
538 and then Is_Limited_Record
(E
)
544 end Is_Recursively_Limited_Private
;
546 ----------------------------------
547 -- Missing_Read_Write_Attribute --
548 ----------------------------------
550 function Missing_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
551 Component
: Entity_Id
;
552 Component_Type
: Entity_Id
;
553 U_E
: constant Entity_Id
:= Underlying_Type
(E
);
555 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean;
556 -- Return True if entity has attribute definition clauses for Read and
557 -- Write attributes that are visible at some place.
559 -------------------------------
560 -- Has_Read_Write_Attributes --
561 -------------------------------
563 function Has_Read_Write_Attributes
(E
: Entity_Id
) return Boolean is
566 and then Has_Stream_Attribute_Definition
(E
,
567 TSS_Stream_Read
, At_Any_Place
=> True)
568 and then Has_Stream_Attribute_Definition
(E
,
569 TSS_Stream_Write
, At_Any_Place
=> True);
570 end Has_Read_Write_Attributes
;
572 -- Start of processing for Missing_Read_Write_Attributes
578 elsif Has_Read_Write_Attributes
(E
)
579 or else Has_Read_Write_Attributes
(U_E
)
583 elsif Is_Non_Remote_Access_Type
(U_E
) then
587 if Is_Record_Type
(U_E
) then
588 Component
:= First_Entity
(U_E
);
589 while Present
(Component
) loop
590 if not Is_Tag
(Component
) then
591 Component_Type
:= Etype
(Component
);
593 if Missing_Read_Write_Attributes
(Component_Type
) then
598 Next_Entity
(Component
);
603 end Missing_Read_Write_Attributes
;
605 -------------------------------------
606 -- Set_Categorization_From_Pragmas --
607 -------------------------------------
609 procedure Set_Categorization_From_Pragmas
(N
: Node_Id
) is
610 P
: constant Node_Id
:= Parent
(N
);
611 S
: constant Entity_Id
:= Current_Scope
;
613 procedure Set_Parents
(Visibility
: Boolean);
614 -- If this is a child instance, the parents are not immediately
615 -- visible during analysis. Make them momentarily visible so that
616 -- the argument of the pragma can be resolved properly, and reset
623 procedure Set_Parents
(Visibility
: Boolean) is
627 while Present
(Par
) and then Par
/= Standard_Standard
loop
628 Set_Is_Immediately_Visible
(Par
, Visibility
);
633 -- Start of processing for Set_Categorization_From_Pragmas
636 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
637 -- The purpose is to set categorization flags before analyzing the
638 -- unit itself, so as to diagnose violations of categorization as
639 -- we process each declaration, even though the pragma appears after
642 if Nkind
(P
) /= N_Compilation_Unit
then
651 and then Is_Generic_Instance
(S
)
656 PN
:= First
(Pragmas_After
(Aux_Decls_Node
(P
)));
657 while Present
(PN
) loop
659 -- Skip implicit types that may have been introduced by
660 -- previous analysis.
662 if Nkind
(PN
) = N_Pragma
then
664 case Get_Pragma_Id
(Chars
(PN
)) is
665 when Pragma_All_Calls_Remote |
666 Pragma_Preelaborate |
668 Pragma_Remote_Call_Interface |
669 Pragma_Remote_Types |
670 Pragma_Shared_Passive
=> Analyze
(PN
);
679 and then Is_Generic_Instance
(S
)
684 end Set_Categorization_From_Pragmas
;
686 -----------------------------------
687 -- Set_Categorization_From_Scope --
688 -----------------------------------
690 procedure Set_Categorization_From_Scope
(E
: Entity_Id
; Scop
: Entity_Id
) is
691 Declaration
: Node_Id
:= Empty
;
692 Specification
: Node_Id
:= Empty
;
696 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(E
));
698 if not Is_Remote_Call_Interface
(E
) then
699 if Ekind
(E
) in Subprogram_Kind
then
700 Declaration
:= Unit_Declaration_Node
(E
);
702 if Nkind
(Declaration
) = N_Subprogram_Body
704 Nkind
(Declaration
) = N_Subprogram_Renaming_Declaration
706 Specification
:= Corresponding_Spec
(Declaration
);
710 -- A subprogram body or renaming-as-body is a remote call
711 -- interface if it serves as the completion of a subprogram
712 -- declaration that is a remote call interface.
714 if Nkind
(Specification
) in N_Entity
then
715 Set_Is_Remote_Call_Interface
716 (E
, Is_Remote_Call_Interface
(Specification
));
718 -- A subprogram declaration is a remote call interface when it is
719 -- declared within the visible part of, or declared by, a library
720 -- unit declaration that is a remote call interface.
723 Set_Is_Remote_Call_Interface
724 (E
, Is_Remote_Call_Interface
(Scop
)
725 and then not (In_Private_Part
(Scop
)
726 or else In_Package_Body
(Scop
)));
730 Set_Is_Remote_Types
(E
, Is_Remote_Types
(Scop
));
731 end Set_Categorization_From_Scope
;
733 ------------------------------
734 -- Static_Discriminant_Expr --
735 ------------------------------
737 -- We need to accomodate a Why_Not_Static call somehow here ???
739 function Static_Discriminant_Expr
(L
: List_Id
) return Boolean is
740 Discriminant_Spec
: Node_Id
;
743 Discriminant_Spec
:= First
(L
);
744 while Present
(Discriminant_Spec
) loop
745 if Present
(Expression
(Discriminant_Spec
))
746 and then not Is_Static_Expression
(Expression
(Discriminant_Spec
))
751 Next
(Discriminant_Spec
);
755 end Static_Discriminant_Expr
;
757 --------------------------------------
758 -- Validate_Access_Type_Declaration --
759 --------------------------------------
761 procedure Validate_Access_Type_Declaration
(T
: Entity_Id
; N
: Node_Id
) is
762 Def
: constant Node_Id
:= Type_Definition
(N
);
767 -- Access to subprogram case
769 when N_Access_To_Subprogram_Definition
=>
771 -- A pure library_item must not contain the declaration of a
772 -- named access type, except within a subprogram, generic
773 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
775 -- This test is skipped in Ada 2005 (see AI-366)
777 if Ada_Version
< Ada_05
778 and then Comes_From_Source
(T
)
779 and then In_Pure_Unit
780 and then not In_Subprogram_Task_Protected_Unit
782 Error_Msg_N
("named access type not allowed in pure unit", T
);
785 -- Access to object case
787 when N_Access_To_Object_Definition
=>
788 if Comes_From_Source
(T
)
789 and then In_Pure_Unit
790 and then not In_Subprogram_Task_Protected_Unit
792 -- We can't give the message yet, since the type is not frozen
793 -- and in Ada 2005 mode, access types are allowed in pure units
794 -- if the type has no storage pool (see AI-366). So we set a
795 -- flag which will be checked at freeze time.
797 Set_Is_Pure_Unit_Access_Type
(T
);
800 -- Check for RCI or RT unit type declaration: declaration of an
801 -- access-to-object type is illegal unless it is a general access
802 -- type that designates a class-wide limited private type.
803 -- Note that constraints on the primitive subprograms of the
804 -- designated tagged type are not enforced here but in
805 -- Validate_RACW_Primitives, which is done separately because the
806 -- designated type might not be frozen (and therefore its
807 -- primitive operations might not be completely known) at the
808 -- point of the RACW declaration.
810 Validate_Remote_Access_Object_Type_Declaration
(T
);
812 -- Check for shared passive unit type declaration. It should
813 -- not contain the declaration of access to class wide type,
814 -- access to task type and access to protected type with entry.
816 Validate_SP_Access_Object_Type_Decl
(T
);
822 -- Set categorization flag from package on entity as well, to allow
823 -- easy checks later on for required validations of RCI or RT units.
824 -- This is only done for entities that are in the original source.
826 if Comes_From_Source
(T
)
827 and then not (In_Package_Body
(Scope
(T
))
828 or else In_Private_Part
(Scope
(T
)))
830 Set_Is_Remote_Call_Interface
831 (T
, Is_Remote_Call_Interface
(Scope
(T
)));
833 (T
, Is_Remote_Types
(Scope
(T
)));
835 end Validate_Access_Type_Declaration
;
837 ----------------------------
838 -- Validate_Ancestor_Part --
839 ----------------------------
841 procedure Validate_Ancestor_Part
(N
: Node_Id
) is
842 A
: constant Node_Id
:= Ancestor_Part
(N
);
843 T
: constant Entity_Id
:= Entity
(A
);
846 if In_Preelaborated_Unit
847 and then not In_Subprogram_Or_Concurrent_Unit
848 and then (not Inside_A_Generic
849 or else Present
(Enclosing_Generic_Body
(N
)))
851 -- If the type is private, it must have the Ada 2005 pragma
852 -- Has_Preelaborable_Initialization.
853 -- The check is omitted within predefined units. This is probably
854 -- obsolete code to fix the Ada95 weakness in this area ???
856 if Is_Private_Type
(T
)
857 and then not Has_Pragma_Preelab_Init
(T
)
858 and then not Is_Internal_File_Name
859 (Unit_File_Name
(Get_Source_Unit
(N
)))
862 ("private ancestor type not allowed in preelaborated unit", A
);
864 elsif Is_Record_Type
(T
) then
865 if Nkind
(Parent
(T
)) = N_Full_Type_Declaration
then
866 Check_Non_Static_Default_Expr
867 (Type_Definition
(Parent
(T
)), A
);
871 end Validate_Ancestor_Part
;
873 ----------------------------------------
874 -- Validate_Categorization_Dependency --
875 ----------------------------------------
877 procedure Validate_Categorization_Dependency
881 K
: constant Node_Kind
:= Nkind
(N
);
882 P
: Node_Id
:= Parent
(N
);
884 Is_Subunit
: constant Boolean := Nkind
(P
) = N_Subunit
;
887 -- Only validate library units and subunits. For subunits, checks
888 -- concerning withed units apply to the parent compilation unit.
895 and then not Is_Compilation_Unit
(U
)
896 and then not Is_Child_Unit
(U
)
902 if Nkind
(P
) /= N_Compilation_Unit
then
906 -- Body of RCI unit does not need validation
908 if Is_Remote_Call_Interface
(E
)
909 and then (Nkind
(N
) = N_Package_Body
910 or else Nkind
(N
) = N_Subprogram_Body
)
915 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
919 Entity_Of_Withed
: Entity_Id
;
922 Item
:= First
(Context_Items
(P
));
923 while Present
(Item
) loop
924 if Nkind
(Item
) = N_With_Clause
925 and then not (Implicit_With
(Item
)
926 or else Limited_Present
(Item
))
928 Entity_Of_Withed
:= Entity
(Name
(Item
));
929 Check_Categorization_Dependencies
930 (U
, Entity_Of_Withed
, Item
, Is_Subunit
);
937 -- Child depends on parent; therefore parent should also be categorized
938 -- and satify the dependency hierarchy.
940 -- Check if N is a child spec
942 if (K
in N_Generic_Declaration
or else
943 K
in N_Generic_Instantiation
or else
944 K
in N_Generic_Renaming_Declaration
or else
945 K
= N_Package_Declaration
or else
946 K
= N_Package_Renaming_Declaration
or else
947 K
= N_Subprogram_Declaration
or else
948 K
= N_Subprogram_Renaming_Declaration
)
949 and then Present
(Parent_Spec
(N
))
951 Check_Categorization_Dependencies
(E
, Scope
(E
), N
, False);
953 -- Verify that public child of an RCI library unit must also be an
954 -- RCI library unit (RM E.2.3(15)).
956 if Is_Remote_Call_Interface
(Scope
(E
))
957 and then not Private_Present
(P
)
958 and then not Is_Remote_Call_Interface
(E
)
960 Error_Msg_N
("public child of rci unit must also be rci unit", N
);
963 end Validate_Categorization_Dependency
;
965 --------------------------------
966 -- Validate_Controlled_Object --
967 --------------------------------
969 procedure Validate_Controlled_Object
(E
: Entity_Id
) is
971 -- Don't need this check in Ada 2005 mode, where this is all taken
972 -- care of by the mechanism for Preelaborable Initialization.
974 if Ada_Version
>= Ada_05
then
978 -- For now, never apply this check for internal GNAT units, since we
979 -- have a number of cases in the library where we are stuck with objects
980 -- of this type, and the RM requires Preelaborate.
982 -- For similar reasons, we only do this check for source entities, since
983 -- we generate entities of this type in some situations.
985 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
986 -- We have to enforce them for RM compatibility, but we have no trouble
987 -- accepting these objects and doing the right thing. Note that there is
988 -- no requirement that Preelaborate not actually generate any code!
990 if In_Preelaborated_Unit
991 and then not Debug_Flag_PP
992 and then Comes_From_Source
(E
)
994 Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(E
)))
995 and then (not Inside_A_Generic
996 or else Present
(Enclosing_Generic_Body
(E
)))
997 and then not Is_Protected_Type
(Etype
(E
))
1000 ("library level controlled object not allowed in " &
1001 "preelaborated unit", E
);
1003 end Validate_Controlled_Object
;
1005 --------------------------------------
1006 -- Validate_Null_Statement_Sequence --
1007 --------------------------------------
1009 procedure Validate_Null_Statement_Sequence
(N
: Node_Id
) is
1013 if In_Preelaborated_Unit
then
1014 Item
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
1015 while Present
(Item
) loop
1016 if Nkind
(Item
) /= N_Label
1017 and then Nkind
(Item
) /= N_Null_Statement
1019 -- In GNAT mode, this is a warning, allowing the run-time
1020 -- to judiciously bypass this error condition.
1022 Error_Msg_Warn
:= GNAT_Mode
;
1024 ("<statements not allowed in preelaborated unit", Item
);
1032 end Validate_Null_Statement_Sequence
;
1034 ---------------------------------
1035 -- Validate_Object_Declaration --
1036 ---------------------------------
1038 procedure Validate_Object_Declaration
(N
: Node_Id
) is
1039 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1040 E
: constant Node_Id
:= Expression
(N
);
1041 Odf
: constant Node_Id
:= Object_Definition
(N
);
1042 T
: constant Entity_Id
:= Etype
(Id
);
1045 -- Verify that any access to subprogram object does not have in its
1046 -- subprogram profile access type parameters or limited parameters
1047 -- without Read and Write attributes (E.2.3(13)).
1049 Validate_RCI_Subprogram_Declaration
(N
);
1051 -- Check that if we are in preelaborated elaboration code, then we
1052 -- do not have an instance of a default initialized private, task or
1053 -- protected object declaration which would violate (RM 10.2.1(9)).
1054 -- Note that constants are never default initialized (and the test
1055 -- below also filters out deferred constants). A variable is default
1056 -- initialized if it does *not* have an initialization expression.
1058 -- Filter out cases that are not declaration of a variable from source
1060 if Nkind
(N
) /= N_Object_Declaration
1061 or else Constant_Present
(N
)
1062 or else not Comes_From_Source
(Id
)
1067 -- Exclude generic specs from the checks (this will get rechecked
1068 -- on instantiations).
1071 and then No
(Enclosing_Generic_Body
(Id
))
1076 -- Required checks for declaration that is in a preelaborated
1077 -- package and is not within some subprogram.
1079 if In_Preelaborated_Unit
1080 and then not In_Subprogram_Or_Concurrent_Unit
1082 -- Check for default initialized variable case. Note that in
1083 -- accordance with (RM B.1(24)) imported objects are not
1084 -- subject to default initialization.
1085 -- If the initialization does not come from source and is an
1086 -- aggregate, it is a static initialization that replaces an
1087 -- implicit call, and must be treated as such.
1091 (Comes_From_Source
(E
) or else Nkind
(E
) /= N_Aggregate
)
1095 elsif Is_Imported
(Id
) then
1100 Ent
: Entity_Id
:= T
;
1103 -- An array whose component type is a record with nonstatic
1104 -- default expressions is a violation, so we get the array's
1107 if Is_Array_Type
(Ent
) then
1109 Comp_Type
: Entity_Id
;
1112 Comp_Type
:= Component_Type
(Ent
);
1113 while Is_Array_Type
(Comp_Type
) loop
1114 Comp_Type
:= Component_Type
(Comp_Type
);
1121 -- Object decl. that is of record type and has no default expr.
1122 -- should check if there is any non-static default expression
1123 -- in component decl. of the record type decl.
1125 if Is_Record_Type
(Ent
) then
1126 if Nkind
(Parent
(Ent
)) = N_Full_Type_Declaration
then
1127 Check_Non_Static_Default_Expr
1128 (Type_Definition
(Parent
(Ent
)), N
);
1130 elsif Nkind
(Odf
) = N_Subtype_Indication
1131 and then not Is_Array_Type
(T
)
1132 and then not Is_Private_Type
(T
)
1134 Check_Non_Static_Default_Expr
(Type_Definition
1135 (Parent
(Entity
(Subtype_Mark
(Odf
)))), N
);
1139 -- Check for invalid use of private object. Note that Ada 2005
1140 -- AI-161 modifies the rules for Ada 2005, including the use of
1141 -- the new pragma Preelaborable_Initialization.
1143 if Is_Private_Type
(Ent
)
1144 or else Depends_On_Private
(Ent
)
1146 -- Case where type has preelaborable initialization which
1147 -- means that a pragma Preelaborable_Initialization was
1148 -- given for the private type.
1150 if Has_Preelaborable_Initialization
(Ent
) then
1152 -- But for the predefined units, we will ignore this
1153 -- status unless we are in Ada 2005 mode since we want
1154 -- Ada 95 compatible behavior, in which the entities
1155 -- marked with this pragma in the predefined library are
1156 -- not treated specially.
1158 if Ada_Version
< Ada_05
then
1160 ("private object not allowed in preelaborated unit",
1162 Error_Msg_N
("\(would be legal in Ada 2005 mode)", N
);
1165 -- Type does not have preelaborable initialization
1168 -- We allow this when compiling in GNAT mode to make life
1169 -- easier for some cases where it would otherwise be hard
1170 -- to be exactly valid Ada.
1172 if not GNAT_Mode
then
1174 ("private object not allowed in preelaborated unit",
1177 -- Add a message if it would help to provide a pragma
1178 -- Preelaborable_Initialization on the type of the
1179 -- object (which would make it legal in Ada 2005).
1181 -- If the type has no full view (generic type, or
1182 -- previous error), the warning does not apply.
1184 if Is_Private_Type
(Ent
)
1185 and then Present
(Full_View
(Ent
))
1187 Has_Preelaborable_Initialization
(Full_View
(Ent
))
1189 Error_Msg_Sloc
:= Sloc
(Ent
);
1191 if Ada_Version
>= Ada_05
then
1193 ("\would be legal if pragma Preelaborable_" &
1194 "Initialization given for & #", N
, Ent
);
1197 ("\would be legal in Ada 2005 if pragma " &
1198 "Preelaborable_Initialization given for & #",
1205 -- Access to Task or Protected type
1207 elsif Is_Entity_Name
(Odf
)
1208 and then Present
(Etype
(Odf
))
1209 and then Is_Access_Type
(Etype
(Odf
))
1211 Ent
:= Designated_Type
(Etype
(Odf
));
1213 elsif Is_Entity_Name
(Odf
) then
1214 Ent
:= Entity
(Odf
);
1216 elsif Nkind
(Odf
) = N_Subtype_Indication
then
1217 Ent
:= Etype
(Subtype_Mark
(Odf
));
1220 Nkind
(Odf
) = N_Constrained_Array_Definition
1222 Ent
:= Component_Type
(T
);
1228 if Is_Task_Type
(Ent
)
1229 or else (Is_Protected_Type
(Ent
) and then Has_Entries
(Ent
))
1232 ("concurrent object not allowed in preelaborated unit",
1239 -- Non-static discriminant not allowed in preelaborayted unit
1241 if Is_Record_Type
(Etype
(Id
)) then
1243 ET
: constant Entity_Id
:= Etype
(Id
);
1244 EE
: constant Entity_Id
:= Etype
(Etype
(Id
));
1248 if Has_Discriminants
(ET
)
1249 and then Present
(EE
)
1253 if Nkind
(PEE
) = N_Full_Type_Declaration
1254 and then not Static_Discriminant_Expr
1255 (Discriminant_Specifications
(PEE
))
1258 ("non-static discriminant in preelaborated unit",
1266 -- A pure library_item must not contain the declaration of any variable
1267 -- except within a subprogram, generic subprogram, task unit, or
1268 -- protected unit (RM 10.2.1(16)).
1271 and then not In_Subprogram_Task_Protected_Unit
1273 Error_Msg_N
("declaration of variable not allowed in pure unit", N
);
1275 -- The visible part of an RCI library unit must not contain the
1276 -- declaration of a variable (RM E.1.3(9))
1278 elsif In_RCI_Declaration
(N
) then
1279 Error_Msg_N
("declaration of variable not allowed in rci unit", N
);
1281 -- The visible part of a Shared Passive library unit must not contain
1282 -- the declaration of a variable (RM E.2.2(7))
1284 elsif In_RT_Declaration
then
1286 ("variable declaration not allowed in remote types unit", N
);
1289 end Validate_Object_Declaration
;
1291 ------------------------------
1292 -- Validate_RACW_Primitives --
1293 ------------------------------
1295 procedure Validate_RACW_Primitives
(T
: Entity_Id
) is
1296 Desig_Type
: Entity_Id
;
1297 Primitive_Subprograms
: Elist_Id
;
1298 Subprogram_Elmt
: Elmt_Id
;
1299 Subprogram
: Entity_Id
;
1301 Param_Spec
: Node_Id
;
1303 Param_Type
: Entity_Id
;
1307 Desig_Type
:= Etype
(Designated_Type
(T
));
1309 Primitive_Subprograms
:= Primitive_Operations
(Desig_Type
);
1311 Subprogram_Elmt
:= First_Elmt
(Primitive_Subprograms
);
1312 while Subprogram_Elmt
/= No_Elmt
loop
1313 Subprogram
:= Node
(Subprogram_Elmt
);
1315 if not Comes_From_Source
(Subprogram
) then
1316 goto Next_Subprogram
;
1319 -- Check return type
1321 if Ekind
(Subprogram
) = E_Function
then
1322 Rtyp
:= Etype
(Subprogram
);
1324 if Has_Controlling_Result
(Subprogram
) then
1327 elsif Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
1329 ("anonymous access result in remote object primitive", Rtyp
);
1331 elsif Is_Limited_Type
(Rtyp
) then
1332 if No
(TSS
(Rtyp
, TSS_Stream_Read
))
1334 No
(TSS
(Rtyp
, TSS_Stream_Write
))
1337 ("limited return type must have Read and Write attributes",
1338 Parent
(Subprogram
));
1339 Explain_Limited_Type
(Rtyp
, Parent
(Subprogram
));
1345 Profile
:= Parameter_Specifications
(Parent
(Subprogram
));
1347 -- Profile must exist, otherwise not primitive operation
1349 Param_Spec
:= First
(Profile
);
1350 while Present
(Param_Spec
) loop
1352 -- Now find out if this parameter is a controlling parameter
1354 Param
:= Defining_Identifier
(Param_Spec
);
1355 Param_Type
:= Etype
(Param
);
1357 if Is_Controlling_Formal
(Param
) then
1359 -- It is a controlling parameter, so specific checks below
1364 elsif Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1366 -- From RM E.2.2(14), no access parameter other than
1367 -- controlling ones may be used.
1370 ("non-controlling access parameter", Param_Spec
);
1372 elsif Is_Limited_Type
(Param_Type
) then
1374 -- Not a controlling parameter, so type must have Read and
1375 -- Write attributes.
1377 if No
(TSS
(Param_Type
, TSS_Stream_Read
))
1379 No
(TSS
(Param_Type
, TSS_Stream_Write
))
1382 ("limited formal must have Read and Write attributes",
1384 Explain_Limited_Type
(Param_Type
, Param_Spec
);
1388 -- Check next parameter in this subprogram
1394 Next_Elmt
(Subprogram_Elmt
);
1396 end Validate_RACW_Primitives
;
1398 -------------------------------
1399 -- Validate_RCI_Declarations --
1400 -------------------------------
1402 procedure Validate_RCI_Declarations
(P
: Entity_Id
) is
1406 E
:= First_Entity
(P
);
1407 while Present
(E
) loop
1408 if Comes_From_Source
(E
) then
1409 if Is_Limited_Type
(E
) then
1411 ("limited type not allowed in rci unit", Parent
(E
));
1412 Explain_Limited_Type
(E
, Parent
(E
));
1414 elsif Ekind
(E
) = E_Generic_Function
1415 or else Ekind
(E
) = E_Generic_Package
1416 or else Ekind
(E
) = E_Generic_Procedure
1418 Error_Msg_N
("generic declaration not allowed in rci unit",
1421 elsif (Ekind
(E
) = E_Function
1422 or else Ekind
(E
) = E_Procedure
)
1423 and then Has_Pragma_Inline
(E
)
1426 ("inlined subprogram not allowed in rci unit", Parent
(E
));
1428 -- Inner packages that are renamings need not be checked. Generic
1429 -- RCI packages are subject to the checks, but entities that come
1430 -- from formal packages are not part of the visible declarations
1431 -- of the package and are not checked.
1433 elsif Ekind
(E
) = E_Package
then
1434 if Present
(Renamed_Entity
(E
)) then
1437 elsif Ekind
(P
) /= E_Generic_Package
1438 or else List_Containing
(Unit_Declaration_Node
(E
)) /=
1439 Generic_Formal_Declarations
1440 (Unit_Declaration_Node
(P
))
1442 Validate_RCI_Declarations
(E
);
1449 end Validate_RCI_Declarations
;
1451 -----------------------------------------
1452 -- Validate_RCI_Subprogram_Declaration --
1453 -----------------------------------------
1455 procedure Validate_RCI_Subprogram_Declaration
(N
: Node_Id
) is
1456 K
: constant Node_Kind
:= Nkind
(N
);
1459 Param_Spec
: Node_Id
;
1460 Param_Type
: Entity_Id
;
1461 Base_Param_Type
: Entity_Id
;
1462 Base_Under_Type
: Entity_Id
;
1463 Type_Decl
: Node_Id
;
1464 Error_Node
: Node_Id
:= N
;
1467 -- There are two possible cases in which this procedure is called:
1469 -- 1. called from Analyze_Subprogram_Declaration.
1470 -- 2. called from Validate_Object_Declaration (access to subprogram).
1472 if not In_RCI_Declaration
(N
) then
1476 if K
= N_Subprogram_Declaration
then
1477 Profile
:= Parameter_Specifications
(Specification
(N
));
1479 else pragma Assert
(K
= N_Object_Declaration
);
1480 Id
:= Defining_Identifier
(N
);
1482 if Nkind
(Id
) = N_Defining_Identifier
1483 and then Nkind
(Parent
(Etype
(Id
))) = N_Full_Type_Declaration
1484 and then Ekind
(Etype
(Id
)) = E_Access_Subprogram_Type
1487 Parameter_Specifications
(Type_Definition
(Parent
(Etype
(Id
))));
1493 -- Iterate through the parameter specification list, checking that
1494 -- no access parameter and no limited type parameter in the list.
1497 if Present
(Profile
) then
1498 Param_Spec
:= First
(Profile
);
1499 while Present
(Param_Spec
) loop
1500 Param_Type
:= Etype
(Defining_Identifier
(Param_Spec
));
1501 Type_Decl
:= Parent
(Param_Type
);
1503 if Ekind
(Param_Type
) = E_Anonymous_Access_Type
then
1505 if K
= N_Subprogram_Declaration
then
1506 Error_Node
:= Param_Spec
;
1509 -- Report error only if declaration is in source program
1511 if Comes_From_Source
1512 (Defining_Entity
(Specification
(N
)))
1515 ("subprogram in rci unit cannot have access parameter",
1519 -- For limited private type parameter, we check only the private
1520 -- declaration and ignore full type declaration, unless this is
1521 -- the only declaration for the type, eg. as a limited record.
1523 elsif Is_Limited_Type
(Param_Type
)
1524 and then (Nkind
(Type_Decl
) = N_Private_Type_Declaration
1526 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
1527 and then not (Has_Private_Declaration
(Param_Type
))
1528 and then Comes_From_Source
(N
)))
1530 -- A limited parameter is legal only if user-specified Read and
1531 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1533 if No
(Full_View
(Param_Type
))
1534 and then Ekind
(Param_Type
) /= E_Record_Type
1536 -- Type does not have completion yet, so if declared in in
1537 -- the current RCI scope it is illegal, and will be flagged
1543 -- In Ada 95 the rules permit using a limited type that has
1544 -- user-specified Read and Write attributes that are specified
1545 -- in the private part of the package, whereas Ada 2005
1546 -- (AI-240) revises this to require the attributes to be
1547 -- "available" (implying that the attribute clauses must be
1548 -- visible to the RCI client). The Ada 95 rules violate the
1549 -- contract model for privacy, but we support both semantics
1550 -- for now for compatibility (note that ACATS test BXE2009
1551 -- checks a case that conforms to the Ada 95 rules but is
1552 -- illegal in Ada 2005).
1554 Base_Param_Type
:= Base_Type
(Param_Type
);
1555 Base_Under_Type
:= Base_Type
(Underlying_Type
1558 if (Ada_Version
< Ada_05
1560 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1562 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
)))
1564 (No
(TSS
(Base_Under_Type
, TSS_Stream_Read
))
1566 No
(TSS
(Base_Under_Type
, TSS_Stream_Write
))))
1568 (Ada_Version
>= Ada_05
1570 (No
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1572 No
(TSS
(Base_Param_Type
, TSS_Stream_Write
))
1574 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Read
))
1576 Is_Hidden
(TSS
(Base_Param_Type
, TSS_Stream_Write
))))
1578 if K
= N_Subprogram_Declaration
then
1579 Error_Node
:= Param_Spec
;
1582 if Ada_Version
>= Ada_05
then
1584 ("limited parameter in rci unit "
1585 & "must have visible read/write attributes ",
1589 ("limited parameter in rci unit "
1590 & "must have read/write attributes ",
1593 Explain_Limited_Type
(Param_Type
, Error_Node
);
1600 end Validate_RCI_Subprogram_Declaration
;
1602 ----------------------------------------------------
1603 -- Validate_Remote_Access_Object_Type_Declaration --
1604 ----------------------------------------------------
1606 procedure Validate_Remote_Access_Object_Type_Declaration
(T
: Entity_Id
) is
1607 Direct_Designated_Type
: Entity_Id
;
1608 Desig_Type
: Entity_Id
;
1611 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1612 -- given node is N_Access_To_Object_Definition.
1614 if not Comes_From_Source
(T
)
1615 or else (not In_RCI_Declaration
(Parent
(T
))
1616 and then not In_RT_Declaration
)
1621 -- An access definition in the private part of a Remote Types package
1622 -- may be legal if it has user-defined Read and Write attributes. This
1623 -- will be checked at the end of the package spec processing.
1625 if In_RT_Declaration
and then In_Private_Part
(Scope
(T
)) then
1629 -- Check RCI or RT unit type declaration. It may not contain the
1630 -- declaration of an access-to-object type unless it is a general access
1631 -- type that designates a class-wide limited private type. There are
1632 -- also constraints on the primitive subprograms of the class-wide type
1633 -- (RM E.2.2(14), see Validate_RACW_Primitives).
1635 if Ekind
(T
) /= E_General_Access_Type
1636 or else Ekind
(Designated_Type
(T
)) /= E_Class_Wide_Type
1638 if In_RCI_Declaration
(Parent
(T
)) then
1640 ("error in access type in Remote_Call_Interface unit", T
);
1643 ("error in access type in Remote_Types unit", T
);
1646 Error_Msg_N
("\must be general access to class-wide type", T
);
1650 Direct_Designated_Type
:= Designated_Type
(T
);
1651 Desig_Type
:= Etype
(Direct_Designated_Type
);
1653 if not Is_Recursively_Limited_Private
(Desig_Type
) then
1655 ("error in designated type of remote access to class-wide type", T
);
1657 ("\must be tagged limited private or private extension of type", T
);
1661 -- Now this is an RCI unit access-to-class-wide-limited-private type
1662 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1663 -- optimize later checks by avoiding tree traversal to find out if this
1664 -- entity is inside an RCI unit.
1666 Set_Is_Remote_Call_Interface
(T
);
1667 end Validate_Remote_Access_Object_Type_Declaration
;
1669 -----------------------------------------------
1670 -- Validate_Remote_Access_To_Class_Wide_Type --
1671 -----------------------------------------------
1673 procedure Validate_Remote_Access_To_Class_Wide_Type
(N
: Node_Id
) is
1674 K
: constant Node_Kind
:= Nkind
(N
);
1675 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
1679 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1680 -- of class-wide limited private types.
1682 -- Storage_Pool and Storage_Size are not defined for such types
1684 -- The expected type of allocator must not not be such a type.
1686 -- The actual parameter of generic instantiation must not be such a
1687 -- type if the formal parameter is of an access type.
1689 -- On entry, there are five cases
1691 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1692 -- either Storage_Pool or Storage_Size.
1694 -- 2. called from exp_ch4 Expand_N_Allocator
1696 -- 3. called from sem_ch12 Analyze_Associations
1698 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1700 -- 5. called from sem_res Resolve_Actuals
1702 if K
= N_Attribute_Reference
then
1703 E
:= Etype
(Prefix
(N
));
1705 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1706 Error_Msg_N
("incorrect attribute of remote operand", N
);
1710 elsif K
= N_Allocator
then
1713 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1714 Error_Msg_N
("incorrect expected remote type of allocator", N
);
1718 elsif K
in N_Has_Entity
then
1721 if Is_Remote_Access_To_Class_Wide_Type
(E
) then
1722 Error_Msg_N
("incorrect remote type generic actual", N
);
1726 -- This subprogram also enforces the checks in E.2.2(13). A value of
1727 -- such type must not be dereferenced unless as controlling operand of
1728 -- a dispatching call.
1730 elsif K
= N_Explicit_Dereference
1731 and then (Comes_From_Source
(N
)
1732 or else (Nkind
(Original_Node
(N
)) = N_Selected_Component
1733 and then Comes_From_Source
(Original_Node
(N
))))
1735 E
:= Etype
(Prefix
(N
));
1737 -- If the class-wide type is not a remote one, the restrictions
1740 if not Is_Remote_Access_To_Class_Wide_Type
(E
) then
1744 -- If we have a true dereference that comes from source and that
1745 -- is a controlling argument for a dispatching call, accept it.
1747 if Is_Actual_Parameter
(N
)
1748 and then Is_Controlling_Actual
(N
)
1753 -- If we are just within a procedure or function call and the
1754 -- dereference has not been analyzed, return because this procedure
1755 -- will be called again from sem_res Resolve_Actuals.
1757 if Is_Actual_Parameter
(N
)
1758 and then not Analyzed
(N
)
1763 -- We must allow expanded code to generate a reference to the tag of
1764 -- the designated object (may be either the actual tag, or the stub
1765 -- tag in the case of a remote object).
1767 if PK
= N_Selected_Component
1768 and then Is_Tag
(Entity
(Selector_Name
(Parent
(N
))))
1773 -- The following code is needed for expansion of RACW Write
1774 -- attribute, since such expressions can appear in the expanded
1777 if not Comes_From_Source
(N
)
1780 or else PK
= N_Attribute_Reference
1782 (PK
= N_Type_Conversion
1783 and then Present
(Parent
(N
))
1784 and then Present
(Parent
(Parent
(N
)))
1786 Nkind
(Parent
(Parent
(N
))) = N_Selected_Component
))
1791 Error_Msg_N
("incorrect remote type dereference", N
);
1793 end Validate_Remote_Access_To_Class_Wide_Type
;
1795 ------------------------------------------
1796 -- Validate_Remote_Type_Type_Conversion --
1797 ------------------------------------------
1799 procedure Validate_Remote_Type_Type_Conversion
(N
: Node_Id
) is
1800 S
: constant Entity_Id
:= Etype
(N
);
1801 E
: constant Entity_Id
:= Etype
(Expression
(N
));
1804 -- This test is required in the case where a conversion appears inside a
1805 -- normal package, it does not necessarily have to be inside an RCI,
1806 -- Remote_Types unit (RM E.2.2(9,12)).
1808 if Is_Remote_Access_To_Subprogram_Type
(E
)
1809 and then not Is_Remote_Access_To_Subprogram_Type
(S
)
1812 ("incorrect conversion of remote operand to local type", N
);
1815 elsif not Is_Remote_Access_To_Subprogram_Type
(E
)
1816 and then Is_Remote_Access_To_Subprogram_Type
(S
)
1819 ("incorrect conversion of local operand to remote type", N
);
1822 elsif Is_Remote_Access_To_Class_Wide_Type
(E
)
1823 and then not Is_Remote_Access_To_Class_Wide_Type
(S
)
1826 ("incorrect conversion of remote operand to local type", N
);
1830 -- If a local access type is converted into a RACW type, then the
1831 -- current unit has a pointer that may now be exported to another
1834 if Is_Remote_Access_To_Class_Wide_Type
(S
)
1835 and then not Is_Remote_Access_To_Class_Wide_Type
(E
)
1837 Set_Has_RACW
(Current_Sem_Unit
);
1839 end Validate_Remote_Type_Type_Conversion
;
1841 -------------------------------
1842 -- Validate_RT_RAT_Component --
1843 -------------------------------
1845 procedure Validate_RT_RAT_Component
(N
: Node_Id
) is
1846 Spec
: constant Node_Id
:= Specification
(N
);
1847 Name_U
: constant Entity_Id
:= Defining_Entity
(Spec
);
1850 First_Priv_Ent
: constant Entity_Id
:= First_Private_Entity
(Name_U
);
1853 if not Is_Remote_Types
(Name_U
) then
1857 Typ
:= First_Entity
(Name_U
);
1858 while Present
(Typ
) and then Typ
/= First_Priv_Ent
loop
1859 U_Typ
:= Underlying_Type
(Typ
);
1865 if Comes_From_Source
(Typ
) and then Is_Type
(Typ
) then
1866 if Missing_Read_Write_Attributes
(Typ
) then
1867 if Is_Non_Remote_Access_Type
(Typ
) then
1868 Error_Msg_N
("error in non-remote access type", U_Typ
);
1871 ("error in record type containing a component of a " &
1872 "non-remote access type", U_Typ
);
1875 if Ada_Version
>= Ada_05
then
1877 ("\must have visible Read and Write attribute " &
1878 "definition clauses (RM E.2.2(8))", U_Typ
);
1881 ("\must have Read and Write attribute " &
1882 "definition clauses (RM E.2.2(8))", U_Typ
);
1889 end Validate_RT_RAT_Component
;
1891 -----------------------------------------
1892 -- Validate_SP_Access_Object_Type_Decl --
1893 -----------------------------------------
1895 procedure Validate_SP_Access_Object_Type_Decl
(T
: Entity_Id
) is
1896 Direct_Designated_Type
: Entity_Id
;
1898 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean;
1899 -- Return true if the protected type designated by T has
1900 -- entry declarations.
1902 ----------------------------
1903 -- Has_Entry_Declarations --
1904 ----------------------------
1906 function Has_Entry_Declarations
(E
: Entity_Id
) return Boolean is
1910 if Nkind
(Parent
(E
)) = N_Protected_Type_Declaration
then
1911 Ety
:= First_Entity
(E
);
1912 while Present
(Ety
) loop
1913 if Ekind
(Ety
) = E_Entry
then
1922 end Has_Entry_Declarations
;
1924 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1927 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1928 -- Nkind of the given entity is N_Access_To_Object_Definition.
1930 if not Comes_From_Source
(T
)
1931 or else not In_Shared_Passive_Unit
1932 or else In_Subprogram_Task_Protected_Unit
1937 -- Check Shared Passive unit. It should not contain the declaration
1938 -- of an access-to-object type whose designated type is a class-wide
1939 -- type, task type or protected type with entry (RM E.2.1(7)).
1941 Direct_Designated_Type
:= Designated_Type
(T
);
1943 if Ekind
(Direct_Designated_Type
) = E_Class_Wide_Type
then
1945 ("invalid access-to-class-wide type in shared passive unit", T
);
1948 elsif Ekind
(Direct_Designated_Type
) in Task_Kind
then
1950 ("invalid access-to-task type in shared passive unit", T
);
1953 elsif Ekind
(Direct_Designated_Type
) in Protected_Kind
1954 and then Has_Entry_Declarations
(Direct_Designated_Type
)
1957 ("invalid access-to-protected type in shared passive unit", T
);
1960 end Validate_SP_Access_Object_Type_Decl
;
1962 ---------------------------------
1963 -- Validate_Static_Object_Name --
1964 ---------------------------------
1966 procedure Validate_Static_Object_Name
(N
: Node_Id
) is
1969 function Is_Primary
(N
: Node_Id
) return Boolean;
1970 -- Determine whether node is syntactically a primary in an expression
1971 -- This function should probably be somewhere else ???
1972 -- Also it does not do what it says, e.g if N is a binary operator
1973 -- whose parent is a binary operator, Is_Primary returns True ???
1979 function Is_Primary
(N
: Node_Id
) return Boolean is
1980 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1984 when N_Op | N_Membership_Test
=>
1988 | N_Component_Association
1989 | N_Index_Or_Discriminant_Constraint
=>
1992 when N_Attribute_Reference
=>
1993 return Attribute_Name
(Parent
(N
)) /= Name_Address
1994 and then Attribute_Name
(Parent
(N
)) /= Name_Access
1995 and then Attribute_Name
(Parent
(N
)) /= Name_Unchecked_Access
1997 Attribute_Name
(Parent
(N
)) /= Name_Unrestricted_Access
;
1999 when N_Indexed_Component
=>
2000 return (N
/= Prefix
(Parent
(N
))
2001 or else Is_Primary
(Parent
(N
)));
2003 when N_Qualified_Expression | N_Type_Conversion
=>
2004 return Is_Primary
(Parent
(N
));
2006 when N_Assignment_Statement | N_Object_Declaration
=>
2007 return (N
= Expression
(Parent
(N
)));
2009 when N_Selected_Component
=>
2010 return Is_Primary
(Parent
(N
));
2017 -- Start of processing for Validate_Static_Object_Name
2020 if not In_Preelaborated_Unit
2021 or else not Comes_From_Source
(N
)
2022 or else In_Subprogram_Or_Concurrent_Unit
2023 or else Ekind
(Current_Scope
) = E_Block
2027 -- Filter out cases where primary is default in a component declaration,
2028 -- discriminant specification, or actual in a record type initialization
2031 -- Initialization call of internal types
2033 elsif Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
then
2035 if Present
(Parent
(Parent
(N
)))
2036 and then Nkind
(Parent
(Parent
(N
))) = N_Freeze_Entity
2041 if Nkind
(Name
(Parent
(N
))) = N_Identifier
2042 and then not Comes_From_Source
(Entity
(Name
(Parent
(N
))))
2048 -- Error if the name is a primary in an expression. The parent must not
2049 -- be an operator, or a selected component or an indexed component that
2050 -- is itself a primary. Entities that are actuals do not need to be
2051 -- checked, because the call itself will be diagnosed.
2054 and then (not Inside_A_Generic
2055 or else Present
(Enclosing_Generic_Body
(N
)))
2057 if Ekind
(Entity
(N
)) = E_Variable
2058 or else Ekind
(Entity
(N
)) in Formal_Object_Kind
2060 Flag_Non_Static_Expr
2061 ("non-static object name in preelaborated unit", N
);
2063 -- We take the view that a constant defined in another preelaborated
2064 -- unit is preelaborable, even though it may have a private type and
2065 -- thus appear non-static in a client. This must be the intent of
2066 -- the language, but currently is an RM gap ???
2068 elsif Ekind
(Entity
(N
)) = E_Constant
2069 and then not Is_Static_Expression
(N
)
2073 if Is_Internal_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
2075 Enclosing_Lib_Unit_Node
(N
) /= Enclosing_Lib_Unit_Node
(E
)
2076 and then (Is_Preelaborated
(Scope
(E
))
2077 or else Is_Pure
(Scope
(E
))
2078 or else (Present
(Renamed_Object
(E
))
2080 Is_Entity_Name
(Renamed_Object
(E
))
2083 (Scope
(Renamed_Object
(E
)))
2086 (Renamed_Object
(E
))))))
2090 -- This is the error case
2093 -- In GNAT mode, this is just a warning, to allow it to be
2094 -- judiciously turned off. Otherwise it is a real error.
2098 ("?non-static constant in preelaborated unit", N
);
2100 Flag_Non_Static_Expr
2101 ("non-static constant in preelaborated unit", N
);
2106 end Validate_Static_Object_Name
;