configure.ac: GCC_NO_EXECUTABLES was supposed to be commented in the patch from 3...
[official-gcc.git] / gcc / ada / sem_cat.adb
blob3360f6e5db7eea2fc0bb39c14c6d10de2e2424e3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C A T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
10 -- --
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. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
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;
34 with Lib; use Lib;
35 with Nlists; use Nlists;
36 with Sem; use Sem;
37 with Sem_Util; use Sem_Util;
38 with Sinfo; use Sinfo;
39 with Snames; use Snames;
40 with Stand; use Stand;
42 package body Sem_Cat is
44 -----------------------
45 -- Local Subprograms --
46 -----------------------
48 procedure Check_Categorization_Dependencies
49 (Unit_Entity : Entity_Id;
50 Depended_Entity : Entity_Id;
51 Info_Node : Node_Id;
52 Is_Subunit : Boolean);
53 -- This procedure checks that the categorization of a lib unit and that
54 -- of the depended unit satisfy dependency restrictions.
55 -- The depended_entity can be the entity in a with_clause item, in which
56 -- case Info_Node denotes that item. The depended_entity can also be the
57 -- parent unit of a child unit, in which case Info_Node is the declaration
58 -- of the child unit. The error message is posted on Info_Node, and is
59 -- specialized if Is_Subunit is true.
61 procedure Check_Non_Static_Default_Expr
62 (Type_Def : Node_Id;
63 Obj_Decl : Node_Id);
64 -- Iterate through the component list of a record definition, check
65 -- that no component is declared with a nonstatic default value.
66 -- If a nonstatic default exists, report an error on Obj_Decl.
68 -- Iterate through the component list of a record definition, check
69 -- that no component is declared with a non-static default value.
71 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
72 -- Return True if the entity or one of its subcomponent is an access
73 -- type which does not have user-defined Read and Write attribute.
75 function In_RCI_Declaration (N : Node_Id) return Boolean;
76 -- Determines if a declaration is within the visible part of a Remote
77 -- Call Interface compilation unit, for semantic checking purposes only,
78 -- (returns false within an instance and within the package body).
80 function In_RT_Declaration return Boolean;
81 -- Determines if current scope is within a Remote Types compilation unit,
82 -- for semantic checking purposes.
84 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
85 -- Returns true if the entity is a non-remote access type
87 function In_Shared_Passive_Unit return Boolean;
88 -- Determines if current scope is within a Shared Passive compilation unit
90 function Static_Discriminant_Expr (L : List_Id) return Boolean;
91 -- Iterate through the list of discriminants to check if any of them
92 -- contains non-static default expression, which is a violation in
93 -- a preelaborated library unit.
95 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
96 -- Check validity of declaration if RCI unit. It should not contain
97 -- the declaration of an access-to-object type unless it is a
98 -- general access type that designates a class-wide limited
99 -- private type. There are also constraints about the primitive
100 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
102 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean;
103 -- Return True if E is a limited private type, or if E is a private
104 -- extension of a type whose parent verifies this property (hence the
105 -- recursive keyword).
107 ---------------------------------------
108 -- Check_Categorization_Dependencies --
109 ---------------------------------------
111 procedure Check_Categorization_Dependencies
112 (Unit_Entity : Entity_Id;
113 Depended_Entity : Entity_Id;
114 Info_Node : Node_Id;
115 Is_Subunit : Boolean)
117 N : Node_Id := Info_Node;
119 type Categorization is
120 (Pure, Shared_Passive, Remote_Types,
121 Remote_Call_Interface, Pre_Elaborated, Normal);
123 Unit_Category : Categorization;
124 With_Category : Categorization;
126 function Get_Categorization (E : Entity_Id) return Categorization;
127 -- Check categorization flags from entity, and return in the form
128 -- of a corresponding enumeration value.
130 function Get_Categorization (E : Entity_Id) return Categorization is
131 begin
132 if Is_Preelaborated (E) then
133 return Pre_Elaborated;
134 elsif Is_Pure (E) then
135 return Pure;
136 elsif Is_Shared_Passive (E) then
137 return Shared_Passive;
138 elsif Is_Remote_Types (E) then
139 return Remote_Types;
140 elsif Is_Remote_Call_Interface (E) then
141 return Remote_Call_Interface;
142 else
143 return Normal;
144 end if;
145 end Get_Categorization;
147 -- Start of processing for Check_Categorization_Dependencies
149 begin
150 -- Intrinsic subprograms are preelaborated, so do not impose any
151 -- categorization dependencies.
153 if Is_Intrinsic_Subprogram (Depended_Entity) then
154 return;
155 end if;
157 Unit_Category := Get_Categorization (Unit_Entity);
158 With_Category := Get_Categorization (Depended_Entity);
160 if With_Category > Unit_Category then
162 if (Unit_Category = Remote_Types
163 or else Unit_Category = Remote_Call_Interface)
164 and then In_Package_Body (Unit_Entity)
165 then
166 null;
168 elsif Is_Subunit then
169 Error_Msg_NE ("subunit cannot depend on&"
170 & " (parent has wrong categorization)", N, Depended_Entity);
171 else
172 Error_Msg_NE ("current unit cannot depend on&"
173 & " (wrong categorization)", N, Depended_Entity);
174 end if;
175 end if;
177 end Check_Categorization_Dependencies;
179 -----------------------------------
180 -- Check_Non_Static_Default_Expr --
181 -----------------------------------
183 procedure Check_Non_Static_Default_Expr
184 (Type_Def : Node_Id;
185 Obj_Decl : Node_Id)
187 Recdef : Node_Id;
188 Component_Decl : Node_Id;
190 begin
191 if Nkind (Type_Def) = N_Derived_Type_Definition then
192 Recdef := Record_Extension_Part (Type_Def);
194 if No (Recdef) then
195 return;
196 end if;
198 else
199 Recdef := Type_Def;
200 end if;
202 -- Check that component declarations do not involve:
204 -- a. a non-static default expression, where the object is
205 -- declared to be default initialized.
207 -- b. a dynamic Itype (discriminants and constraints)
209 if Null_Present (Recdef) then
210 return;
211 else
212 Component_Decl := First (Component_Items (Component_List (Recdef)));
213 end if;
215 while Present (Component_Decl)
216 and then Nkind (Component_Decl) = N_Component_Declaration
217 loop
218 if Present (Expression (Component_Decl))
219 and then Nkind (Expression (Component_Decl)) /= N_Null
220 and then not Is_Static_Expression (Expression (Component_Decl))
221 then
222 Error_Msg_Sloc := Sloc (Component_Decl);
223 Error_Msg_N
224 ("object in preelaborated unit has nonstatic default#",
225 Obj_Decl);
227 -- Fix this later ???
229 -- elsif Has_Dynamic_Itype (Component_Decl) then
230 -- Error_Msg_N
231 -- ("dynamic type discriminant," &
232 -- " constraint in preelaborated unit",
233 -- Component_Decl);
234 end if;
236 Next (Component_Decl);
237 end loop;
238 end Check_Non_Static_Default_Expr;
240 ---------------------------
241 -- In_Preelaborated_Unit --
242 ---------------------------
244 function In_Preelaborated_Unit return Boolean is
245 Unit_Entity : constant Entity_Id := Current_Scope;
246 Unit_Kind : constant Node_Kind :=
247 Nkind (Unit (Cunit (Current_Sem_Unit)));
249 begin
250 -- There are no constraints on body of remote_call_interface or
251 -- remote_types packages..
253 return (Unit_Entity /= Standard_Standard)
254 and then (Is_Preelaborated (Unit_Entity)
255 or else Is_Pure (Unit_Entity)
256 or else Is_Shared_Passive (Unit_Entity)
257 or else
258 ((Is_Remote_Types (Unit_Entity)
259 or else Is_Remote_Call_Interface (Unit_Entity))
260 and then Ekind (Unit_Entity) = E_Package
261 and then Unit_Kind /= N_Package_Body
262 and then not In_Package_Body (Unit_Entity)
263 and then not In_Instance));
264 end In_Preelaborated_Unit;
266 ------------------
267 -- In_Pure_Unit --
268 ------------------
270 function In_Pure_Unit return Boolean is
271 begin
272 return Is_Pure (Current_Scope);
273 end In_Pure_Unit;
275 ------------------------
276 -- In_RCI_Declaration --
277 ------------------------
279 function In_RCI_Declaration (N : Node_Id) return Boolean is
280 Unit_Entity : constant Entity_Id := Current_Scope;
281 Unit_Kind : constant Node_Kind :=
282 Nkind (Unit (Cunit (Current_Sem_Unit)));
284 begin
285 -- There are no restrictions on the private part or body
286 -- of an RCI unit.
288 return Is_Remote_Call_Interface (Unit_Entity)
289 and then (Ekind (Unit_Entity) = E_Package
290 or else Ekind (Unit_Entity) = E_Generic_Package)
291 and then Unit_Kind /= N_Package_Body
292 and then List_Containing (N) =
293 Visible_Declarations
294 (Specification (Unit_Declaration_Node (Unit_Entity)))
295 and then not In_Package_Body (Unit_Entity)
296 and then not In_Instance;
297 end In_RCI_Declaration;
299 -----------------------
300 -- In_RT_Declaration --
301 -----------------------
303 function In_RT_Declaration return Boolean is
304 Unit_Entity : constant Entity_Id := Current_Scope;
305 Unit_Kind : constant Node_Kind :=
306 Nkind (Unit (Cunit (Current_Sem_Unit)));
308 begin
309 -- There are no restrictions on the body of a Remote Types unit.
311 return Is_Remote_Types (Unit_Entity)
312 and then (Ekind (Unit_Entity) = E_Package
313 or else Ekind (Unit_Entity) = E_Generic_Package)
314 and then Unit_Kind /= N_Package_Body
315 and then not In_Package_Body (Unit_Entity)
316 and then not In_Instance;
317 end In_RT_Declaration;
319 ----------------------------
320 -- In_Shared_Passive_Unit --
321 ----------------------------
323 function In_Shared_Passive_Unit return Boolean is
324 Unit_Entity : constant Entity_Id := Current_Scope;
326 begin
327 return Is_Shared_Passive (Unit_Entity);
328 end In_Shared_Passive_Unit;
330 ---------------------------------------
331 -- In_Subprogram_Task_Protected_Unit --
332 ---------------------------------------
334 function In_Subprogram_Task_Protected_Unit return Boolean is
335 E : Entity_Id;
336 K : Entity_Kind;
338 begin
339 -- The following is to verify that a declaration is inside
340 -- subprogram, generic subprogram, task unit, protected unit.
341 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
343 -- Use scope chain to check successively outer scopes
345 E := Current_Scope;
346 loop
347 K := Ekind (E);
349 if K = E_Procedure
350 or else K = E_Function
351 or else K = E_Generic_Procedure
352 or else K = E_Generic_Function
353 or else K = E_Task_Type
354 or else K = E_Task_Subtype
355 or else K = E_Protected_Type
356 or else K = E_Protected_Subtype
357 then
358 return True;
360 elsif E = Standard_Standard then
361 return False;
362 end if;
364 E := Scope (E);
365 end loop;
367 end In_Subprogram_Task_Protected_Unit;
369 -------------------------------
370 -- Is_Non_Remote_Access_Type --
371 -------------------------------
373 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
374 begin
375 return Is_Access_Type (E)
376 and then not Is_Remote_Access_To_Class_Wide_Type (E)
377 and then not Is_Remote_Access_To_Subprogram_Type (E);
378 end Is_Non_Remote_Access_Type;
380 ------------------------------------
381 -- Is_Recursively_Limited_Private --
382 ------------------------------------
384 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
385 P : constant Node_Id := Parent (E);
387 begin
388 if Nkind (P) = N_Private_Type_Declaration
389 and then Is_Limited_Record (E)
390 then
391 return True;
392 elsif Nkind (P) = N_Private_Extension_Declaration then
393 return Is_Recursively_Limited_Private (Etype (E));
394 elsif Nkind (P) = N_Formal_Type_Declaration
395 and then Ekind (E) = E_Record_Type_With_Private
396 and then Is_Generic_Type (E)
397 and then Is_Limited_Record (E)
398 then
399 return True;
400 else
401 return False;
402 end if;
403 end Is_Recursively_Limited_Private;
405 ----------------------------------
406 -- Missing_Read_Write_Attribute --
407 ----------------------------------
409 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
410 Component : Entity_Id;
411 Component_Type : Entity_Id;
413 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
414 -- Return True if entity has Read and Write attributes
416 -------------------------------
417 -- Has_Read_Write_Attributes --
418 -------------------------------
420 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
421 Rep_Item : Node_Id := First_Rep_Item (E);
422 Read_Attribute : Boolean := False;
423 Write_Attribute : Boolean := False;
425 begin
426 -- We start from the declaration node and then loop until the end
427 -- of the list until we find those two attribute definition clauses.
429 while Present (Rep_Item) loop
430 if Chars (Rep_Item) = Name_Read then
431 Read_Attribute := True;
432 elsif Chars (Rep_Item) = Name_Write then
433 Write_Attribute := True;
434 end if;
436 if Read_Attribute and Write_Attribute then
437 return True;
438 end if;
440 Next_Rep_Item (Rep_Item);
441 end loop;
443 return False;
444 end Has_Read_Write_Attributes;
446 -- Start of processing for Missing_Read_Write_Attributes
448 begin
449 if Has_Read_Write_Attributes (E) then
450 return False;
451 elsif Is_Non_Remote_Access_Type (E) then
452 return True;
453 end if;
455 if Is_Record_Type (E) then
456 Component := First_Entity (E);
457 while Present (Component) loop
458 Component_Type := Etype (Component);
460 if (Is_Non_Remote_Access_Type (Component_Type)
461 or else Is_Record_Type (Component_Type))
462 and then Missing_Read_Write_Attributes (Component_Type)
463 then
464 return True;
465 end if;
467 Next_Entity (Component);
468 end loop;
469 end if;
471 return False;
472 end Missing_Read_Write_Attributes;
474 -------------------------------------
475 -- Set_Categorization_From_Pragmas --
476 -------------------------------------
478 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
479 P : constant Node_Id := Parent (N);
480 S : constant Entity_Id := Current_Scope;
482 procedure Set_Parents (Visibility : Boolean);
483 -- If this is a child instance, the parents are not immediately
484 -- visible during analysis. Make them momentarily visible so that
485 -- the argument of the pragma can be resolved properly, and reset
486 -- afterwards.
488 procedure Set_Parents (Visibility : Boolean) is
489 Par : Entity_Id := Scope (S);
491 begin
492 while Present (Par) and then Par /= Standard_Standard loop
493 Set_Is_Immediately_Visible (Par, Visibility);
494 Par := Scope (Par);
495 end loop;
496 end Set_Parents;
498 begin
499 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
500 -- The purpose is to set categorization flags before analyzing the
501 -- unit itself, so as to diagnose violations of categorization as
502 -- we process each declaration, even though the pragma appears after
503 -- the unit.
505 if Nkind (P) /= N_Compilation_Unit then
506 return;
507 end if;
509 declare
510 PN : Node_Id := First (Pragmas_After (Aux_Decls_Node (P)));
512 begin
514 if Is_Child_Unit (S)
515 and then Is_Generic_Instance (S)
516 then
517 Set_Parents (True);
518 end if;
520 while Present (PN) loop
522 -- Skip implicit types that may have been introduced by
523 -- previous analysis.
525 if Nkind (PN) = N_Pragma then
527 case Get_Pragma_Id (Chars (PN)) is
528 when Pragma_All_Calls_Remote |
529 Pragma_Preelaborate |
530 Pragma_Pure |
531 Pragma_Remote_Call_Interface |
532 Pragma_Remote_Types |
533 Pragma_Shared_Passive => Analyze (PN);
534 when others => null;
535 end case;
536 end if;
538 Next (PN);
539 end loop;
540 if Is_Child_Unit (S)
541 and then Is_Generic_Instance (S)
542 then
543 Set_Parents (False);
544 end if;
546 end;
547 end Set_Categorization_From_Pragmas;
549 ------------------------------
550 -- Static_Discriminant_Expr --
551 ------------------------------
553 function Static_Discriminant_Expr (L : List_Id) return Boolean is
554 Discriminant_Spec : Node_Id;
556 begin
557 Discriminant_Spec := First (L);
558 while Present (Discriminant_Spec) loop
559 if Present (Expression (Discriminant_Spec))
560 and then not Is_Static_Expression (Expression (Discriminant_Spec))
561 then
562 return False;
563 end if;
565 Next (Discriminant_Spec);
566 end loop;
568 return True;
569 end Static_Discriminant_Expr;
571 --------------------------------------
572 -- Validate_Access_Type_Declaration --
573 --------------------------------------
575 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
576 Def : constant Node_Id := Type_Definition (N);
578 begin
579 case Nkind (Def) is
580 when N_Access_To_Subprogram_Definition =>
582 -- A pure library_item must not contain the declaration of a
583 -- named access type, except within a subprogram, generic
584 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
586 if Comes_From_Source (T)
587 and then In_Pure_Unit
588 and then not In_Subprogram_Task_Protected_Unit
589 then
590 Error_Msg_N ("named access type not allowed in pure unit", T);
591 end if;
593 when N_Access_To_Object_Definition =>
595 if Comes_From_Source (T)
596 and then In_Pure_Unit
597 and then not In_Subprogram_Task_Protected_Unit
598 then
599 Error_Msg_N
600 ("named access type not allowed in pure unit", T);
601 end if;
603 -- Check for RCI unit type declaration. It should not contain
604 -- the declaration of an access-to-object type unless it is a
605 -- general access type that designates a class-wide limited
606 -- private type. There are also constraints about the primitive
607 -- subprograms of the class-wide type.
609 Validate_Remote_Access_Object_Type_Declaration (T);
611 -- Check for shared passive unit type declaration. It should
612 -- not contain the declaration of access to class wide type,
613 -- access to task type and access to protected type with entry.
615 Validate_SP_Access_Object_Type_Decl (T);
617 when others => null;
618 end case;
620 -- Set Categorization flag of package on entity as well, to allow
621 -- easy checks later on for required validations of RCI units. This
622 -- is only done for entities that are in the original source.
624 if Comes_From_Source (T) then
625 if Is_Remote_Call_Interface (Scope (T))
626 and then not In_Package_Body (Scope (T))
627 then
628 Set_Is_Remote_Call_Interface (T);
629 end if;
631 if Is_Remote_Types (Scope (T))
632 and then not In_Package_Body (Scope (T))
633 then
634 Set_Is_Remote_Types (T);
635 end if;
636 end if;
637 end Validate_Access_Type_Declaration;
639 ----------------------------
640 -- Validate_Ancestor_Part --
641 ----------------------------
643 procedure Validate_Ancestor_Part (N : Node_Id) is
644 A : constant Node_Id := Ancestor_Part (N);
645 T : Entity_Id := Entity (A);
647 begin
648 if In_Preelaborated_Unit
649 and then not In_Subprogram_Or_Concurrent_Unit
650 and then (not Inside_A_Generic
651 or else Present (Enclosing_Generic_Body (N)))
652 then
653 -- We relax the restriction of 10.2.1(9) within GNAT
654 -- units to allow packages such as Ada.Strings.Unbounded
655 -- to be implemented (i.p., Null_Unbounded_String).
656 -- (There are ACVC tests that check that the restriction
657 -- is enforced, but note that AI-161, once approved,
658 -- will relax the restriction prohibiting default-
659 -- initialized objects of private and controlled
660 -- types.)
662 if Is_Private_Type (T)
663 and then not Is_Internal_File_Name
664 (Unit_File_Name (Get_Source_Unit (N)))
665 then
666 Error_Msg_N
667 ("private ancestor type not allowed in preelaborated unit", A);
669 elsif Is_Record_Type (T) then
670 if Nkind (Parent (T)) = N_Full_Type_Declaration then
671 Check_Non_Static_Default_Expr
672 (Type_Definition (Parent (T)), A);
673 end if;
674 end if;
675 end if;
676 end Validate_Ancestor_Part;
678 ----------------------------------------
679 -- Validate_Categorization_Dependency --
680 ----------------------------------------
682 procedure Validate_Categorization_Dependency
683 (N : Node_Id;
684 E : Entity_Id)
686 K : constant Node_Kind := Nkind (N);
687 P : Node_Id := Parent (N);
688 U : Entity_Id := E;
689 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
691 begin
692 -- Only validate library units and subunits. For subunits, checks
693 -- concerning withed units apply to the parent compilation unit.
695 if Is_Subunit then
696 P := Parent (P);
697 U := Scope (E);
699 while Present (U)
700 and then not Is_Compilation_Unit (U)
701 and then not Is_Child_Unit (U)
702 loop
703 U := Scope (U);
704 end loop;
706 end if;
708 if Nkind (P) /= N_Compilation_Unit then
709 return;
710 end if;
712 -- Body of RCI unit does not need validation.
714 if Is_Remote_Call_Interface (E)
715 and then (Nkind (N) = N_Package_Body
716 or else Nkind (N) = N_Subprogram_Body)
717 then
718 return;
719 end if;
721 -- Process with clauses
723 declare
724 Item : Node_Id;
725 Entity_Of_Withed : Entity_Id;
727 begin
728 Item := First (Context_Items (P));
730 while Present (Item) loop
731 if Nkind (Item) = N_With_Clause
732 and then not Implicit_With (Item)
733 then
734 Entity_Of_Withed := Entity (Name (Item));
735 Check_Categorization_Dependencies
736 (U, Entity_Of_Withed, Item, Is_Subunit);
737 end if;
739 Next (Item);
740 end loop;
741 end;
743 -- Child depends on parent; therefore parent should also
744 -- be categorized and satify the dependency hierarchy.
746 -- Check if N is a child spec.
748 if (K in N_Generic_Declaration or else
749 K in N_Generic_Instantiation or else
750 K in N_Generic_Renaming_Declaration or else
751 K = N_Package_Declaration or else
752 K = N_Package_Renaming_Declaration or else
753 K = N_Subprogram_Declaration or else
754 K = N_Subprogram_Renaming_Declaration)
755 and then Present (Parent_Spec (N))
756 then
757 declare
758 Parent_Lib_U : constant Node_Id := Parent_Spec (N);
759 Parent_Kind : constant Node_Kind :=
760 Nkind (Unit (Parent_Lib_U));
761 Parent_Entity : Entity_Id;
763 begin
764 if Parent_Kind = N_Package_Instantiation
765 or else Parent_Kind = N_Procedure_Instantiation
766 or else Parent_Kind = N_Function_Instantiation
767 or else Parent_Kind = N_Package_Renaming_Declaration
768 or else Parent_Kind in N_Generic_Renaming_Declaration
769 then
770 Parent_Entity := Defining_Entity (Unit (Parent_Lib_U));
772 else
773 Parent_Entity :=
774 Defining_Entity (Specification (Unit (Parent_Lib_U)));
775 end if;
777 Check_Categorization_Dependencies (E, Parent_Entity, N, False);
779 -- Verify that public child of an RCI library unit
780 -- must also be an RCI library unit (RM E.2.3(15)).
782 if Is_Remote_Call_Interface (Parent_Entity)
783 and then not Private_Present (P)
784 and then not Is_Remote_Call_Interface (E)
785 then
786 Error_Msg_N
787 ("public child of rci unit must also be rci unit", N);
788 return;
789 end if;
790 end;
791 end if;
793 end Validate_Categorization_Dependency;
795 --------------------------------
796 -- Validate_Controlled_Object --
797 --------------------------------
799 procedure Validate_Controlled_Object (E : Entity_Id) is
800 begin
801 -- For now, never apply this check for internal GNAT units, since we
802 -- have a number of cases in the library where we are stuck with objects
803 -- of this type, and the RM requires Preelaborate.
805 -- For similar reasons, we only do this check for source entities, since
806 -- we generate entities of this type in some situations.
808 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
809 -- We have to enforce them for RM compatibility, but we have no trouble
810 -- accepting these objects and doing the right thing. Note that there is
811 -- no requirement that Preelaborate not actually generate any code!
813 if In_Preelaborated_Unit
814 and then not Debug_Flag_PP
815 and then Comes_From_Source (E)
816 and then not
817 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
818 and then (not Inside_A_Generic
819 or else Present (Enclosing_Generic_Body (E)))
820 and then not Is_Protected_Type (Etype (E))
821 then
822 Error_Msg_N
823 ("library level controlled object not allowed in " &
824 "preelaborated unit", E);
825 end if;
826 end Validate_Controlled_Object;
828 --------------------------------------
829 -- Validate_Null_Statement_Sequence --
830 --------------------------------------
832 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
833 Item : Node_Id;
835 begin
836 if In_Preelaborated_Unit then
837 Item := First (Statements (Handled_Statement_Sequence (N)));
839 while Present (Item) loop
840 if Nkind (Item) /= N_Label
841 and then Nkind (Item) /= N_Null_Statement
842 then
843 Error_Msg_N
844 ("statements not allowed in preelaborated unit", Item);
845 exit;
846 end if;
848 Next (Item);
849 end loop;
850 end if;
851 end Validate_Null_Statement_Sequence;
853 ---------------------------------
854 -- Validate_Object_Declaration --
855 ---------------------------------
857 procedure Validate_Object_Declaration (N : Node_Id) is
858 Id : constant Entity_Id := Defining_Identifier (N);
859 E : constant Node_Id := Expression (N);
860 Odf : constant Node_Id := Object_Definition (N);
861 T : constant Entity_Id := Etype (Id);
863 begin
864 -- Verify that any access to subprogram object does not have in its
865 -- subprogram profile access type parameters or limited parameters
866 -- without Read and Write attributes (E.2.3(13)).
868 Validate_RCI_Subprogram_Declaration (N);
870 -- Check that if we are in preelaborated elaboration code, then we
871 -- do not have an instance of a default initialized private, task or
872 -- protected object declaration which would violate (RM 10.2.1(9)).
873 -- Note that constants are never default initialized (and the test
874 -- below also filters out deferred constants). A variable is default
875 -- initialized if it does *not* have an initialization expression.
877 -- Filter out cases that are not declaration of a variable from source
879 if Nkind (N) /= N_Object_Declaration
880 or else Constant_Present (N)
881 or else not Comes_From_Source (Id)
882 then
883 return;
884 end if;
886 -- Exclude generic specs from the checks (this will get rechecked
887 -- on instantiations).
889 if Inside_A_Generic
890 and then not Present (Enclosing_Generic_Body (Id))
891 then
892 return;
893 end if;
895 -- Required checks for declaration that is in a preelaborated
896 -- package and is not within some subprogram.
898 if In_Preelaborated_Unit
899 and then not In_Subprogram_Or_Concurrent_Unit
900 then
901 -- Check for default initialized variable case. Note that in
902 -- accordance with (RM B.1(24)) imported objects are not
903 -- subject to default initialization.
905 if No (E) and then not Is_Imported (Id) then
906 declare
907 Ent : Entity_Id := T;
909 begin
910 -- An array whose component type is a record with nonstatic
911 -- default expressions is a violation, so we get the array's
912 -- component type.
914 if Is_Array_Type (Ent) then
915 declare
916 Comp_Type : Entity_Id := Component_Type (Ent);
918 begin
919 while Is_Array_Type (Comp_Type) loop
920 Comp_Type := Component_Type (Comp_Type);
921 end loop;
923 Ent := Comp_Type;
924 end;
925 end if;
927 -- Object decl. that is of record type and has no default expr.
928 -- should check if there is any non-static default expression
929 -- in component decl. of the record type decl.
931 if Is_Record_Type (Ent) then
932 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
933 Check_Non_Static_Default_Expr
934 (Type_Definition (Parent (Ent)), N);
936 elsif Nkind (Odf) = N_Subtype_Indication
937 and then not Is_Array_Type (T)
938 and then not Is_Private_Type (T)
939 then
940 Check_Non_Static_Default_Expr (Type_Definition
941 (Parent (Entity (Subtype_Mark (Odf)))), N);
942 end if;
943 end if;
945 -- We relax the restriction of 10.2.1(9) within GNAT
946 -- units. (There are ACVC tests that check that the
947 -- restriction is enforced, but note that AI-161,
948 -- once approved, will relax the restriction prohibiting
949 -- default-initialized objects of private types, and
950 -- will recommend a pragma for marking private types.)
952 if (Is_Private_Type (Ent)
953 or else Depends_On_Private (Ent))
954 and then not Is_Internal_File_Name
955 (Unit_File_Name (Get_Source_Unit (N)))
956 then
957 Error_Msg_N
958 ("private object not allowed in preelaborated unit", N);
959 return;
961 -- Access to Task or Protected type
963 elsif Is_Entity_Name (Odf)
964 and then Present (Etype (Odf))
965 and then Is_Access_Type (Etype (Odf))
966 then
967 Ent := Designated_Type (Etype (Odf));
969 elsif Is_Entity_Name (Odf) then
970 Ent := Entity (Odf);
972 elsif Nkind (Odf) = N_Subtype_Indication then
973 Ent := Etype (Subtype_Mark (Odf));
975 elsif
976 Nkind (Odf) = N_Constrained_Array_Definition
977 then
978 Ent := Component_Type (T);
980 -- else
981 -- return;
982 end if;
984 if Is_Task_Type (Ent)
985 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
986 then
987 Error_Msg_N
988 ("concurrent object not allowed in preelaborated unit",
990 return;
991 end if;
992 end;
993 end if;
995 -- Non-static discriminant not allowed in preelaborayted unit
997 if Is_Record_Type (Etype (Id)) then
998 declare
999 ET : constant Entity_Id := Etype (Id);
1000 EE : constant Entity_Id := Etype (Etype (Id));
1001 PEE : Node_Id;
1003 begin
1004 if Has_Discriminants (ET)
1005 and then Present (EE)
1006 then
1007 PEE := Parent (EE);
1009 if Nkind (PEE) = N_Full_Type_Declaration
1010 and then not Static_Discriminant_Expr
1011 (Discriminant_Specifications (PEE))
1012 then
1013 Error_Msg_N
1014 ("non-static discriminant in preelaborated unit",
1015 PEE);
1016 end if;
1017 end if;
1018 end;
1019 end if;
1020 end if;
1022 -- A pure library_item must not contain the declaration of any
1023 -- variable except within a subprogram, generic subprogram, task
1024 -- unit or protected unit (RM 10.2.1(16)).
1026 if In_Pure_Unit
1027 and then not In_Subprogram_Task_Protected_Unit
1028 then
1029 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1031 -- The visible part of an RCI library unit must not contain the
1032 -- declaration of a variable (RM E.1.3(9))
1034 elsif In_RCI_Declaration (N) then
1035 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1037 -- The visible part of a Shared Passive library unit must not contain
1038 -- the declaration of a variable (RM E.2.2(7))
1040 elsif In_RT_Declaration then
1041 Error_Msg_N
1042 ("variable declaration not allowed in remote types unit", N);
1043 end if;
1045 end Validate_Object_Declaration;
1047 --------------------------------
1048 -- Validate_RCI_Declarations --
1049 --------------------------------
1051 procedure Validate_RCI_Declarations (P : Entity_Id) is
1052 E : Entity_Id;
1054 begin
1055 E := First_Entity (P);
1057 while Present (E) loop
1058 if Comes_From_Source (E) then
1060 if Is_Limited_Type (E) then
1061 Error_Msg_N
1062 ("Limited type not allowed in rci unit", Parent (E));
1064 elsif Ekind (E) = E_Generic_Function
1065 or else Ekind (E) = E_Generic_Package
1066 or else Ekind (E) = E_Generic_Procedure
1067 then
1068 Error_Msg_N ("generic declaration not allowed in rci unit",
1069 Parent (E));
1071 elsif (Ekind (E) = E_Function
1072 or else Ekind (E) = E_Procedure)
1073 and then Has_Pragma_Inline (E)
1074 then
1075 Error_Msg_N
1076 ("inlined subprogram not allowed in rci unit", Parent (E));
1078 -- Inner packages that are renamings need not be checked.
1079 -- Generic RCI packages are subject to the checks, but
1080 -- entities that come from formal packages are not part of the
1081 -- visible declarations of the package and are not checked.
1083 elsif Ekind (E) = E_Package then
1084 if Present (Renamed_Entity (E)) then
1085 null;
1087 elsif Ekind (P) /= E_Generic_Package
1088 or else List_Containing (Unit_Declaration_Node (E)) /=
1089 Generic_Formal_Declarations
1090 (Unit_Declaration_Node (P))
1091 then
1092 Validate_RCI_Declarations (E);
1093 end if;
1094 end if;
1095 end if;
1097 Next_Entity (E);
1098 end loop;
1099 end Validate_RCI_Declarations;
1101 -----------------------------------------
1102 -- Validate_RCI_Subprogram_Declaration --
1103 -----------------------------------------
1105 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1106 K : Node_Kind := Nkind (N);
1107 Profile : List_Id;
1108 Id : Node_Id;
1109 Param_Spec : Node_Id;
1110 Param_Type : Entity_Id;
1111 Base_Param_Type : Entity_Id;
1112 Type_Decl : Node_Id;
1113 Error_Node : Node_Id := N;
1115 begin
1116 -- There are two possible cases in which this procedure is called:
1118 -- 1. called from Analyze_Subprogram_Declaration.
1119 -- 2. called from Validate_Object_Declaration (access to subprogram).
1121 if not In_RCI_Declaration (N) then
1122 return;
1123 end if;
1125 if K = N_Subprogram_Declaration then
1126 Profile := Parameter_Specifications (Specification (N));
1128 else pragma Assert (K = N_Object_Declaration);
1129 Id := Defining_Identifier (N);
1131 if Nkind (Id) = N_Defining_Identifier
1132 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1133 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1134 then
1135 Profile :=
1136 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1137 else
1138 return;
1139 end if;
1140 end if;
1142 -- Iterate through the parameter specification list, checking that
1143 -- no access parameter and no limited type parameter in the list.
1144 -- RM E.2.3 (14)
1146 if Present (Profile) then
1147 Param_Spec := First (Profile);
1149 while Present (Param_Spec) loop
1150 Param_Type := Etype (Defining_Identifier (Param_Spec));
1151 Type_Decl := Parent (Param_Type);
1153 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1155 if K = N_Subprogram_Declaration then
1156 Error_Node := Param_Spec;
1157 end if;
1159 -- Report error only if declaration is in source program.
1161 if Comes_From_Source
1162 (Defining_Entity (Specification (N)))
1163 then
1164 Error_Msg_N
1165 ("subprogram in rci unit cannot have access parameter",
1166 Error_Node);
1167 end if;
1169 -- For limited private type parameter, we check only the
1170 -- private declaration and ignore full type declaration,
1171 -- unless this is the only declaration for the type, eg.
1172 -- as a limited record.
1174 elsif Is_Limited_Type (Param_Type)
1175 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1176 or else
1177 (Nkind (Type_Decl) = N_Full_Type_Declaration
1178 and then not (Has_Private_Declaration (Param_Type))
1179 and then Comes_From_Source (N)))
1180 then
1182 -- A limited parameter is legal only if user-specified
1183 -- Read and Write attributes exist for it.
1184 -- second part of RM E.2.3 (14)
1186 if No (Full_View (Param_Type))
1187 and then Ekind (Param_Type) /= E_Record_Type
1188 then
1189 -- type does not have completion yet, so if declared in
1190 -- in the current RCI scope it is illegal, and will be
1191 -- flagged subsequently.
1192 return;
1193 end if;
1195 Base_Param_Type := Base_Type (Underlying_Type (Param_Type));
1197 if No (TSS (Base_Param_Type, Name_uRead))
1198 or else No (TSS (Base_Param_Type, Name_uWrite))
1199 then
1201 if K = N_Subprogram_Declaration then
1202 Error_Node := Param_Spec;
1203 end if;
1205 Error_Msg_N
1206 ("limited parameter in rci unit "
1207 & "must have read/write attributes ", Error_Node);
1208 end if;
1209 end if;
1211 Next (Param_Spec);
1212 end loop;
1213 end if;
1214 end Validate_RCI_Subprogram_Declaration;
1216 ----------------------------------------------------
1217 -- Validate_Remote_Access_Object_Type_Declaration --
1218 ----------------------------------------------------
1220 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1221 Direct_Designated_Type : Entity_Id;
1222 Desig_Type : Entity_Id;
1223 Primitive_Subprograms : Elist_Id;
1224 Subprogram : Elmt_Id;
1225 Subprogram_Node : Node_Id;
1226 Profile : List_Id;
1227 Param_Spec : Node_Id;
1228 Param_Type : Entity_Id;
1229 Limited_Type_Decl : Node_Id;
1231 begin
1232 -- We are called from Analyze_Type_Declaration, and the Nkind
1233 -- of the given node is N_Access_To_Object_Definition.
1235 if not Comes_From_Source (T)
1236 or else (not In_RCI_Declaration (Parent (T))
1237 and then not In_RT_Declaration)
1238 then
1239 return;
1240 end if;
1242 -- An access definition in the private part of a Remote Types package
1243 -- may be legal if it has user-defined Read and Write attributes. This
1244 -- will be checked at the end of the package spec processing.
1246 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1247 return;
1248 end if;
1250 -- Check RCI unit type declaration. It should not contain the
1251 -- declaration of an access-to-object type unless it is a
1252 -- general access type that designates a class-wide limited
1253 -- private type. There are also constraints about the primitive
1254 -- subprograms of the class-wide type (RM E.2.3(14)).
1256 if Ekind (T) /= E_General_Access_Type
1257 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1258 then
1259 if In_RCI_Declaration (Parent (T)) then
1260 Error_Msg_N
1261 ("access type in Remote_Call_Interface unit must be " &
1262 "general access", T);
1263 else
1264 Error_Msg_N ("access type in Remote_Types unit must be " &
1265 "general access", T);
1266 end if;
1267 Error_Msg_N ("\to class-wide type", T);
1268 return;
1269 end if;
1271 Direct_Designated_Type := Designated_Type (T);
1273 Desig_Type := Etype (Direct_Designated_Type);
1275 if not Is_Recursively_Limited_Private (Desig_Type) then
1276 Error_Msg_N
1277 ("error in designated type of remote access to class-wide type", T);
1278 Error_Msg_N
1279 ("\must be tagged limited private or private extension of type", T);
1280 return;
1281 end if;
1283 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1284 Subprogram := First_Elmt (Primitive_Subprograms);
1286 while Subprogram /= No_Elmt loop
1287 Subprogram_Node := Node (Subprogram);
1289 if not Comes_From_Source (Subprogram_Node) then
1290 goto Next_Subprogram;
1291 end if;
1293 Profile := Parameter_Specifications (Parent (Subprogram_Node));
1295 -- Profile must exist, otherwise not primitive operation
1297 Param_Spec := First (Profile);
1299 while Present (Param_Spec) loop
1301 -- Now find out if this parameter is a controlling parameter
1303 Param_Type := Parameter_Type (Param_Spec);
1305 if (Nkind (Param_Type) = N_Access_Definition
1306 and then Etype (Subtype_Mark (Param_Type)) = Desig_Type)
1307 or else (Nkind (Param_Type) /= N_Access_Definition
1308 and then Etype (Param_Type) = Desig_Type)
1309 then
1310 -- It is a controlling parameter, so specific checks below
1311 -- do not apply.
1313 null;
1315 elsif
1316 Nkind (Param_Type) = N_Access_Definition
1317 then
1318 -- From RM E.2.2(14), no access parameter other than
1319 -- controlling ones may be used.
1321 Error_Msg_N
1322 ("non-controlling access parameter", Param_Spec);
1324 elsif
1325 Is_Limited_Type (Etype (Defining_Identifier (Param_Spec)))
1326 then
1327 -- Not a controlling parameter, so type must have Read
1328 -- and Write attributes.
1329 -- ??? I suspect this to be dead code because any violation
1330 -- should be caught before in sem_attr.adb (with the message
1331 -- "limited type ... used in ... has no stream attr."). ST
1333 if Nkind (Param_Type) in N_Has_Etype
1334 and then Nkind (Parent (Etype (Param_Type))) =
1335 N_Private_Type_Declaration
1336 then
1337 Param_Type := Etype (Param_Type);
1338 Limited_Type_Decl := Parent (Param_Type);
1340 if No (TSS (Param_Type, Name_uRead))
1341 or else No (TSS (Param_Type, Name_uWrite))
1342 then
1343 Error_Msg_N
1344 ("limited formal must have Read and Write attributes",
1345 Param_Spec);
1346 end if;
1347 end if;
1348 end if;
1350 -- Check next parameter in this subprogram
1352 Next (Param_Spec);
1353 end loop;
1355 <<Next_Subprogram>>
1356 Next_Elmt (Subprogram);
1357 end loop;
1359 -- Now this is an RCI unit access-to-class-wide-limited-private type
1360 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1361 -- optimize later checks by avoiding tree traversal to find out if this
1362 -- entity is inside an RCI unit.
1364 Set_Is_Remote_Call_Interface (T);
1366 end Validate_Remote_Access_Object_Type_Declaration;
1368 -----------------------------------------------
1369 -- Validate_Remote_Access_To_Class_Wide_Type --
1370 -----------------------------------------------
1372 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1373 K : constant Node_Kind := Nkind (N);
1374 PK : constant Node_Kind := Nkind (Parent (N));
1375 E : Entity_Id;
1377 begin
1378 -- This subprogram enforces the checks in (RM E.2.2(8)) for
1379 -- certain uses of class-wide limited private types.
1381 -- Storage_Pool and Storage_Size are not defined for such types
1383 -- The expected type of allocator must not not be such a type.
1385 -- The actual parameter of generic instantiation must not
1386 -- be such a type if the formal parameter is of an access type.
1388 -- On entry, there are five cases
1390 -- 1. called from sem_attr Analyze_Attribute where attribute
1391 -- name is either Storage_Pool or Storage_Size.
1393 -- 2. called from exp_ch4 Expand_N_Allocator
1395 -- 3. called from sem_ch12 Analyze_Associations
1397 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1399 -- 5. called from sem_res Resolve_Actuals
1401 if K = N_Attribute_Reference then
1402 E := Etype (Prefix (N));
1404 if Is_Remote_Access_To_Class_Wide_Type (E) then
1405 Error_Msg_N ("incorrect attribute of remote operand", N);
1406 return;
1407 end if;
1409 elsif K = N_Allocator then
1410 E := Etype (N);
1412 if Is_Remote_Access_To_Class_Wide_Type (E) then
1413 Error_Msg_N ("incorrect expected remote type of allocator", N);
1414 return;
1415 end if;
1417 elsif K in N_Has_Entity then
1418 E := Entity (N);
1420 if Is_Remote_Access_To_Class_Wide_Type (E) then
1421 Error_Msg_N ("incorrect remote type generic actual", N);
1422 return;
1423 end if;
1425 -- This subprogram also enforces the checks in E.2.2(13).
1426 -- A value of such type must not be dereferenced unless as a
1427 -- controlling operand of a dispatching call.
1429 elsif K = N_Explicit_Dereference
1430 and then (Comes_From_Source (N)
1431 or else (Nkind (Original_Node (N)) = N_Selected_Component
1432 and then Comes_From_Source (Original_Node (N))))
1433 then
1434 E := Etype (Prefix (N));
1436 -- If the class-wide type is not a remote one, the restrictions
1437 -- do not apply.
1439 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1440 return;
1441 end if;
1443 -- If we have a true dereference that comes from source and that
1444 -- is a controlling argument for a dispatching call, accept it.
1446 if K = N_Explicit_Dereference
1447 and then Is_Actual_Parameter (N)
1448 and then Is_Controlling_Actual (N)
1449 then
1450 return;
1451 end if;
1453 -- If we are just within a procedure or function call and the
1454 -- dereference has not been analyzed, return because this
1455 -- procedure will be called again from sem_res Resolve_Actuals.
1457 if Is_Actual_Parameter (N)
1458 and then not Analyzed (N)
1459 then
1460 return;
1461 end if;
1463 -- The following is to let the compiler generated tags check
1464 -- pass through without error message. This is a bit kludgy
1465 -- isn't there some better way of making this exclusion ???
1467 if (PK = N_Selected_Component
1468 and then Present (Parent (Parent (N)))
1469 and then Nkind (Parent (Parent (N))) = N_Op_Ne)
1470 or else (PK = N_Unchecked_Type_Conversion
1471 and then Present (Parent (Parent (N)))
1472 and then
1473 Nkind (Parent (Parent (N))) = N_Selected_Component)
1474 then
1475 return;
1476 end if;
1478 -- The following code is needed for expansion of RACW Write
1479 -- attribute, since such expressions can appear in the expanded
1480 -- code.
1482 if not Comes_From_Source (N)
1483 and then
1484 (PK = N_In
1485 or else PK = N_Attribute_Reference
1486 or else
1487 (PK = N_Type_Conversion
1488 and then Present (Parent (N))
1489 and then Present (Parent (Parent (N)))
1490 and then
1491 Nkind (Parent (Parent (N))) = N_Selected_Component))
1492 then
1493 return;
1494 end if;
1496 Error_Msg_N ("incorrect remote type dereference", N);
1497 end if;
1498 end Validate_Remote_Access_To_Class_Wide_Type;
1500 -----------------------------------------------
1501 -- Validate_Remote_Access_To_Subprogram_Type --
1502 -----------------------------------------------
1504 procedure Validate_Remote_Access_To_Subprogram_Type (N : Node_Id) is
1505 Type_Def : constant Node_Id := Type_Definition (N);
1506 Current_Parameter : Node_Id;
1508 begin
1509 if Present (Parameter_Specifications (Type_Def)) then
1510 Current_Parameter := First (Parameter_Specifications (Type_Def));
1511 while Present (Current_Parameter) loop
1512 if Nkind (Parameter_Type (Current_Parameter)) =
1513 N_Access_Definition
1514 then
1515 Error_Msg_N
1516 ("remote access to subprogram type declaration contains",
1517 Current_Parameter);
1518 Error_Msg_N
1519 ("\parameter of an anonymous access type", Current_Parameter);
1520 end if;
1522 Current_Parameter := Next (Current_Parameter);
1523 end loop;
1524 end if;
1525 end Validate_Remote_Access_To_Subprogram_Type;
1527 ------------------------------------------
1528 -- Validate_Remote_Type_Type_Conversion --
1529 ------------------------------------------
1531 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1532 S : constant Entity_Id := Etype (N);
1533 E : constant Entity_Id := Etype (Expression (N));
1535 begin
1536 -- This test is required in the case where a conversion appears
1537 -- inside a normal package, it does not necessarily have to be
1538 -- inside an RCI, Remote_Types unit (RM E.2.2(9,12)).
1540 if Is_Remote_Access_To_Subprogram_Type (E)
1541 and then not Is_Remote_Access_To_Subprogram_Type (S)
1542 then
1543 Error_Msg_N ("incorrect conversion of remote operand", N);
1544 return;
1546 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1547 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1548 then
1549 Error_Msg_N ("incorrect conversion of remote operand", N);
1550 return;
1551 end if;
1553 -- If a local access type is converted into a RACW type, then the
1554 -- current unit has a pointer that may now be exported to another
1555 -- partition.
1557 if Is_Remote_Access_To_Class_Wide_Type (S)
1558 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1559 then
1560 Set_Has_RACW (Current_Sem_Unit);
1561 end if;
1562 end Validate_Remote_Type_Type_Conversion;
1564 -------------------------------
1565 -- Validate_RT_RAT_Component --
1566 -------------------------------
1568 procedure Validate_RT_RAT_Component (N : Node_Id) is
1569 Spec : constant Node_Id := Specification (N);
1570 Name_U : constant Entity_Id := Defining_Entity (Spec);
1571 Typ : Entity_Id;
1572 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1573 In_Visible_Part : Boolean := True;
1575 begin
1576 if not Is_Remote_Types (Name_U) then
1577 return;
1578 end if;
1580 Typ := First_Entity (Name_U);
1581 while Present (Typ) loop
1582 if In_Visible_Part and then Typ = First_Priv_Ent then
1583 In_Visible_Part := False;
1584 end if;
1586 if Comes_From_Source (Typ)
1587 and then Is_Type (Typ)
1588 and then (In_Visible_Part or else Has_Private_Declaration (Typ))
1589 then
1590 if Missing_Read_Write_Attributes (Typ) then
1591 if Is_Non_Remote_Access_Type (Typ) then
1592 Error_Msg_N
1593 ("non-remote access type without user-defined Read " &
1594 "and Write attributes", Typ);
1595 else
1596 Error_Msg_N
1597 ("record type containing a component of a " &
1598 "non-remote access", Typ);
1599 Error_Msg_N
1600 ("\type without Read and Write attributes " &
1601 "('R'M E.2.2(8))", Typ);
1602 end if;
1603 end if;
1604 end if;
1606 Next_Entity (Typ);
1607 end loop;
1608 end Validate_RT_RAT_Component;
1610 -----------------------------------------
1611 -- Validate_SP_Access_Object_Type_Decl --
1612 -----------------------------------------
1614 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1615 Direct_Designated_Type : Entity_Id;
1617 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1618 -- Return true if the protected type designated by T has
1619 -- entry declarations.
1621 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1622 Ety : Entity_Id;
1624 begin
1625 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1626 Ety := First_Entity (E);
1627 while Present (Ety) loop
1628 if Ekind (Ety) = E_Entry then
1629 return True;
1630 end if;
1632 Next_Entity (Ety);
1633 end loop;
1634 end if;
1636 return False;
1637 end Has_Entry_Declarations;
1639 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1641 begin
1642 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1643 -- Nkind of the given entity is N_Access_To_Object_Definition.
1645 if not Comes_From_Source (T)
1646 or else not In_Shared_Passive_Unit
1647 or else In_Subprogram_Task_Protected_Unit
1648 then
1649 return;
1650 end if;
1652 -- Check Shared Passive unit. It should not contain the declaration
1653 -- of an access-to-object type whose designated type is a class-wide
1654 -- type, task type or protected type with entry (RM E.2.1(7)).
1656 Direct_Designated_Type := Designated_Type (T);
1658 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
1659 Error_Msg_N
1660 ("invalid access-to-class-wide type in shared passive unit", T);
1661 return;
1663 elsif Ekind (Direct_Designated_Type) in Task_Kind then
1664 Error_Msg_N
1665 ("invalid access-to-task type in shared passive unit", T);
1666 return;
1668 elsif Ekind (Direct_Designated_Type) in Protected_Kind
1669 and then Has_Entry_Declarations (Direct_Designated_Type)
1670 then
1671 Error_Msg_N
1672 ("invalid access-to-protected type in shared passive unit", T);
1673 return;
1674 end if;
1675 end Validate_SP_Access_Object_Type_Decl;
1677 ---------------------------------
1678 -- Validate_Static_Object_Name --
1679 ---------------------------------
1681 procedure Validate_Static_Object_Name (N : Node_Id) is
1682 E : Entity_Id;
1684 function Is_Primary (N : Node_Id) return Boolean;
1685 -- Determine whether node is syntactically a primary in an expression.
1687 function Is_Primary (N : Node_Id) return Boolean is
1688 K : constant Node_Kind := Nkind (Parent (N));
1690 begin
1691 case K is
1693 when N_Op | N_In | N_Not_In =>
1694 return True;
1696 when N_Aggregate
1697 | N_Component_Association
1698 | N_Index_Or_Discriminant_Constraint =>
1699 return True;
1701 when N_Attribute_Reference =>
1702 return Attribute_Name (Parent (N)) /= Name_Address
1703 and then Attribute_Name (Parent (N)) /= Name_Access
1704 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
1705 and then
1706 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
1708 when N_Indexed_Component =>
1709 return (N /= Prefix (Parent (N))
1710 or else Is_Primary (Parent (N)));
1712 when N_Qualified_Expression | N_Type_Conversion =>
1713 return Is_Primary (Parent (N));
1715 when N_Assignment_Statement | N_Object_Declaration =>
1716 return (N = Expression (Parent (N)));
1718 when N_Selected_Component =>
1719 return Is_Primary (Parent (N));
1721 when others =>
1722 return False;
1723 end case;
1724 end Is_Primary;
1726 -- Start of processing for Validate_Static_Object_Name
1728 begin
1729 if not In_Preelaborated_Unit
1730 or else not Comes_From_Source (N)
1731 or else In_Subprogram_Or_Concurrent_Unit
1732 or else Ekind (Current_Scope) = E_Block
1733 then
1734 return;
1736 -- Filter out cases where primary is default in a component
1737 -- declaration, discriminant specification, or actual in a record
1738 -- type initialization call.
1740 -- Initialization call of internal types.
1742 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
1744 if Present (Parent (Parent (N)))
1745 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
1746 then
1747 return;
1748 end if;
1750 if Nkind (Name (Parent (N))) = N_Identifier
1751 and then not Comes_From_Source (Entity (Name (Parent (N))))
1752 then
1753 return;
1754 end if;
1755 end if;
1757 -- Error if the name is a primary in an expression. The parent must not
1758 -- be an operator, or a selected component or an indexed component that
1759 -- is itself a primary. Entities that are actuals do not need to be
1760 -- checked, because the call itself will be diagnosed.
1762 if Is_Primary (N)
1763 and then (not Inside_A_Generic
1764 or else Present (Enclosing_Generic_Body (N)))
1765 then
1766 if Ekind (Entity (N)) = E_Variable then
1767 Error_Msg_N ("non-static object name in preelaborated unit", N);
1769 -- We take the view that a constant defined in another preelaborated
1770 -- unit is preelaborable, even though it may have a private type and
1771 -- thus appear non-static in a client. This must be the intent of
1772 -- the language, but currently is an RM gap.
1774 elsif Ekind (Entity (N)) = E_Constant
1775 and then not Is_Static_Expression (N)
1776 then
1777 E := Entity (N);
1779 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
1780 and then
1781 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
1782 and then (Is_Preelaborated (Scope (E))
1783 or else Is_Pure (Scope (E))
1784 or else (Present (Renamed_Object (E))
1785 and then
1786 Is_Entity_Name (Renamed_Object (E))
1787 and then
1788 (Is_Preelaborated
1789 (Scope (Renamed_Object (E)))
1790 or else
1791 Is_Pure (Scope
1792 (Renamed_Object (E))))))
1793 then
1794 null;
1795 else
1796 Error_Msg_N ("non-static constant in preelaborated unit", N);
1797 end if;
1798 end if;
1799 end if;
1800 end Validate_Static_Object_Name;
1802 end Sem_Cat;