* arm.c (FL_WBUF): Define.
[official-gcc.git] / gcc / ada / sem_cat.adb
bloba17521cad9dc85f2eef1988de04ab1d402a52f17
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-2005, 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_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;
52 Info_Node : Node_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
63 (Type_Def : Node_Id;
64 Obj_Decl : Node_Id);
65 -- Iterate through the component list of a record definition, check
66 -- that no component is declared with a nonstatic default value.
67 -- If a nonstatic default exists, report an error on Obj_Decl.
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a non-static default value.
72 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
73 -- Return True if the entity or one of its subcomponent is an access
74 -- type which does not have user-defined Read and Write attribute.
76 function In_RCI_Declaration (N : Node_Id) return Boolean;
77 -- Determines if a declaration is within the visible part of a Remote
78 -- Call Interface compilation unit, for semantic checking purposes only,
79 -- (returns false within an instance and within the package body).
81 function In_RT_Declaration return Boolean;
82 -- Determines if current scope is within a Remote Types compilation unit,
83 -- for semantic checking purposes.
85 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
86 -- Returns true if the entity is a non-remote access type
88 function In_Shared_Passive_Unit return Boolean;
89 -- Determines if current scope is within a Shared Passive compilation unit
91 function Static_Discriminant_Expr (L : List_Id) return Boolean;
92 -- Iterate through the list of discriminants to check if any of them
93 -- contains non-static default expression, which is a violation in
94 -- a preelaborated library unit.
96 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
97 -- Check validity of declaration if RCI or RT unit. It should not contain
98 -- the declaration of an access-to-object type unless it is a
99 -- general access type that designates a class-wide limited
100 -- private type. There are also constraints about the primitive
101 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
103 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean;
104 -- Return True if E is a limited private type, or if E is a private
105 -- extension of a type whose parent verifies this property (hence the
106 -- recursive keyword).
108 ---------------------------------------
109 -- Check_Categorization_Dependencies --
110 ---------------------------------------
112 procedure Check_Categorization_Dependencies
113 (Unit_Entity : Entity_Id;
114 Depended_Entity : Entity_Id;
115 Info_Node : Node_Id;
116 Is_Subunit : Boolean)
118 N : constant Node_Id := Info_Node;
120 type Categorization is
121 (Pure, Shared_Passive, Remote_Types,
122 Remote_Call_Interface, Pre_Elaborated, Normal);
124 Unit_Category : Categorization;
125 With_Category : Categorization;
127 function Get_Categorization (E : Entity_Id) return Categorization;
128 -- Check categorization flags from entity, and return in the form
129 -- of a corresponding enumeration value.
131 ------------------------
132 -- Get_Categorization --
133 ------------------------
135 function Get_Categorization (E : Entity_Id) return Categorization is
136 begin
137 if Is_Preelaborated (E) then
138 return Pre_Elaborated;
139 elsif Is_Pure (E) then
140 return Pure;
141 elsif Is_Shared_Passive (E) then
142 return Shared_Passive;
143 elsif Is_Remote_Types (E) then
144 return Remote_Types;
145 elsif Is_Remote_Call_Interface (E) then
146 return Remote_Call_Interface;
147 else
148 return Normal;
149 end if;
150 end Get_Categorization;
152 -- Start of processing for Check_Categorization_Dependencies
154 begin
155 -- Intrinsic subprograms are preelaborated, so do not impose any
156 -- categorization dependencies.
158 if Is_Intrinsic_Subprogram (Depended_Entity) then
159 return;
160 end if;
162 Unit_Category := Get_Categorization (Unit_Entity);
163 With_Category := Get_Categorization (Depended_Entity);
165 if With_Category > Unit_Category then
167 if (Unit_Category = Remote_Types
168 or else Unit_Category = Remote_Call_Interface)
169 and then In_Package_Body (Unit_Entity)
170 then
171 null;
173 elsif Is_Subunit then
174 Error_Msg_NE ("subunit cannot depend on&"
175 & " (parent has wrong categorization)", N, Depended_Entity);
176 else
177 Error_Msg_NE ("current unit cannot depend on&"
178 & " (wrong categorization)", N, Depended_Entity);
179 end if;
180 end if;
182 end Check_Categorization_Dependencies;
184 -----------------------------------
185 -- Check_Non_Static_Default_Expr --
186 -----------------------------------
188 procedure Check_Non_Static_Default_Expr
189 (Type_Def : Node_Id;
190 Obj_Decl : Node_Id)
192 Recdef : Node_Id;
193 Component_Decl : Node_Id;
195 begin
196 if Nkind (Type_Def) = N_Derived_Type_Definition then
197 Recdef := Record_Extension_Part (Type_Def);
199 if No (Recdef) then
200 return;
201 end if;
203 else
204 Recdef := Type_Def;
205 end if;
207 -- Check that component declarations do not involve:
209 -- a. a non-static default expression, where the object is
210 -- declared to be default initialized.
212 -- b. a dynamic Itype (discriminants and constraints)
214 if Null_Present (Recdef) then
215 return;
216 else
217 Component_Decl := First (Component_Items (Component_List (Recdef)));
218 end if;
220 while Present (Component_Decl)
221 and then Nkind (Component_Decl) = N_Component_Declaration
222 loop
223 if Present (Expression (Component_Decl))
224 and then Nkind (Expression (Component_Decl)) /= N_Null
225 and then not Is_Static_Expression (Expression (Component_Decl))
226 then
227 Error_Msg_Sloc := Sloc (Component_Decl);
228 Error_Msg_F
229 ("object in preelaborated unit has non-static default#",
230 Obj_Decl);
232 -- Fix this later ???
234 -- elsif Has_Dynamic_Itype (Component_Decl) then
235 -- Error_Msg_N
236 -- ("dynamic type discriminant," &
237 -- " constraint in preelaborated unit",
238 -- Component_Decl);
239 end if;
241 Next (Component_Decl);
242 end loop;
243 end Check_Non_Static_Default_Expr;
245 ---------------------------
246 -- In_Preelaborated_Unit --
247 ---------------------------
249 function In_Preelaborated_Unit return Boolean is
250 Unit_Entity : constant Entity_Id := Current_Scope;
251 Unit_Kind : constant Node_Kind :=
252 Nkind (Unit (Cunit (Current_Sem_Unit)));
254 begin
255 -- There are no constraints on body of remote_call_interface or
256 -- remote_types packages..
258 return (Unit_Entity /= Standard_Standard)
259 and then (Is_Preelaborated (Unit_Entity)
260 or else Is_Pure (Unit_Entity)
261 or else Is_Shared_Passive (Unit_Entity)
262 or else
263 ((Is_Remote_Types (Unit_Entity)
264 or else Is_Remote_Call_Interface (Unit_Entity))
265 and then Ekind (Unit_Entity) = E_Package
266 and then Unit_Kind /= N_Package_Body
267 and then not In_Package_Body (Unit_Entity)
268 and then not In_Instance));
269 end In_Preelaborated_Unit;
271 ------------------
272 -- In_Pure_Unit --
273 ------------------
275 function In_Pure_Unit return Boolean is
276 begin
277 return Is_Pure (Current_Scope);
278 end In_Pure_Unit;
280 ------------------------
281 -- In_RCI_Declaration --
282 ------------------------
284 function In_RCI_Declaration (N : Node_Id) return Boolean is
285 Unit_Entity : constant Entity_Id := Current_Scope;
286 Unit_Kind : constant Node_Kind :=
287 Nkind (Unit (Cunit (Current_Sem_Unit)));
289 begin
290 -- There are no restrictions on the private part or body
291 -- of an RCI unit.
293 return Is_Remote_Call_Interface (Unit_Entity)
294 and then (Ekind (Unit_Entity) = E_Package
295 or else Ekind (Unit_Entity) = E_Generic_Package)
296 and then Unit_Kind /= N_Package_Body
297 and then List_Containing (N) =
298 Visible_Declarations
299 (Specification (Unit_Declaration_Node (Unit_Entity)))
300 and then not In_Package_Body (Unit_Entity)
301 and then not In_Instance;
302 end In_RCI_Declaration;
304 -----------------------
305 -- In_RT_Declaration --
306 -----------------------
308 function In_RT_Declaration return Boolean is
309 Unit_Entity : constant Entity_Id := Current_Scope;
310 Unit_Kind : constant Node_Kind :=
311 Nkind (Unit (Cunit (Current_Sem_Unit)));
313 begin
314 -- There are no restrictions on the body of a Remote Types unit.
316 return Is_Remote_Types (Unit_Entity)
317 and then (Ekind (Unit_Entity) = E_Package
318 or else Ekind (Unit_Entity) = E_Generic_Package)
319 and then Unit_Kind /= N_Package_Body
320 and then not In_Package_Body (Unit_Entity)
321 and then not In_Instance;
322 end In_RT_Declaration;
324 ----------------------------
325 -- In_Shared_Passive_Unit --
326 ----------------------------
328 function In_Shared_Passive_Unit return Boolean is
329 Unit_Entity : constant Entity_Id := Current_Scope;
331 begin
332 return Is_Shared_Passive (Unit_Entity);
333 end In_Shared_Passive_Unit;
335 ---------------------------------------
336 -- In_Subprogram_Task_Protected_Unit --
337 ---------------------------------------
339 function In_Subprogram_Task_Protected_Unit return Boolean is
340 E : Entity_Id;
342 begin
343 -- The following is to verify that a declaration is inside
344 -- subprogram, generic subprogram, task unit, protected unit.
345 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
347 -- Use scope chain to check successively outer scopes
349 E := Current_Scope;
350 loop
351 if Is_Subprogram (E)
352 or else
353 Is_Generic_Subprogram (E)
354 or else
355 Is_Concurrent_Type (E)
356 then
357 return True;
359 elsif E = Standard_Standard then
360 return False;
361 end if;
363 E := Scope (E);
364 end loop;
365 end In_Subprogram_Task_Protected_Unit;
367 -------------------------------
368 -- Is_Non_Remote_Access_Type --
369 -------------------------------
371 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
372 begin
373 return Is_Access_Type (E)
374 and then not Is_Remote_Access_To_Class_Wide_Type (E)
375 and then not Is_Remote_Access_To_Subprogram_Type (E);
376 end Is_Non_Remote_Access_Type;
378 ------------------------------------
379 -- Is_Recursively_Limited_Private --
380 ------------------------------------
382 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
383 P : constant Node_Id := Parent (E);
385 begin
386 if Nkind (P) = N_Private_Type_Declaration
387 and then Is_Limited_Record (E)
388 then
389 return True;
390 elsif Nkind (P) = N_Private_Extension_Declaration then
391 return Is_Recursively_Limited_Private (Etype (E));
392 elsif Nkind (P) = N_Formal_Type_Declaration
393 and then Ekind (E) = E_Record_Type_With_Private
394 and then Is_Generic_Type (E)
395 and then Is_Limited_Record (E)
396 then
397 return True;
398 else
399 return False;
400 end if;
401 end Is_Recursively_Limited_Private;
403 ----------------------------------
404 -- Missing_Read_Write_Attribute --
405 ----------------------------------
407 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
408 Component : Entity_Id;
409 Component_Type : Entity_Id;
411 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
412 -- Return True if entity has Read and Write attributes
414 -------------------------------
415 -- Has_Read_Write_Attributes --
416 -------------------------------
418 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
419 Rep_Item : Node_Id := First_Rep_Item (E);
420 Read_Attribute : Boolean := False;
421 Write_Attribute : Boolean := False;
423 begin
424 -- We start from the declaration node and then loop until the end
425 -- of the list until we find those two attribute definition clauses.
427 while Present (Rep_Item) loop
428 if Chars (Rep_Item) = Name_Read then
429 Read_Attribute := True;
430 elsif Chars (Rep_Item) = Name_Write then
431 Write_Attribute := True;
432 end if;
434 if Read_Attribute and Write_Attribute then
435 return True;
436 end if;
438 Next_Rep_Item (Rep_Item);
439 end loop;
441 return False;
442 end Has_Read_Write_Attributes;
444 -- Start of processing for Missing_Read_Write_Attributes
446 begin
447 if Has_Read_Write_Attributes (E) then
448 return False;
449 elsif Is_Non_Remote_Access_Type (E) then
450 return True;
451 end if;
453 if Is_Record_Type (E) then
454 Component := First_Entity (E);
455 while Present (Component) loop
456 Component_Type := Etype (Component);
458 if (Is_Non_Remote_Access_Type (Component_Type)
459 or else Is_Record_Type (Component_Type))
460 and then Missing_Read_Write_Attributes (Component_Type)
461 then
462 return True;
463 end if;
465 Next_Entity (Component);
466 end loop;
467 end if;
469 return False;
470 end Missing_Read_Write_Attributes;
472 -------------------------------------
473 -- Set_Categorization_From_Pragmas --
474 -------------------------------------
476 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
477 P : constant Node_Id := Parent (N);
478 S : constant Entity_Id := Current_Scope;
480 procedure Set_Parents (Visibility : Boolean);
481 -- If this is a child instance, the parents are not immediately
482 -- visible during analysis. Make them momentarily visible so that
483 -- the argument of the pragma can be resolved properly, and reset
484 -- afterwards.
486 procedure Set_Parents (Visibility : Boolean) is
487 Par : Entity_Id := Scope (S);
489 begin
490 while Present (Par) and then Par /= Standard_Standard loop
491 Set_Is_Immediately_Visible (Par, Visibility);
492 Par := Scope (Par);
493 end loop;
494 end Set_Parents;
496 begin
497 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
498 -- The purpose is to set categorization flags before analyzing the
499 -- unit itself, so as to diagnose violations of categorization as
500 -- we process each declaration, even though the pragma appears after
501 -- the unit.
503 if Nkind (P) /= N_Compilation_Unit then
504 return;
505 end if;
507 declare
508 PN : Node_Id := First (Pragmas_After (Aux_Decls_Node (P)));
510 begin
512 if Is_Child_Unit (S)
513 and then Is_Generic_Instance (S)
514 then
515 Set_Parents (True);
516 end if;
518 while Present (PN) loop
520 -- Skip implicit types that may have been introduced by
521 -- previous analysis.
523 if Nkind (PN) = N_Pragma then
525 case Get_Pragma_Id (Chars (PN)) is
526 when Pragma_All_Calls_Remote |
527 Pragma_Preelaborate |
528 Pragma_Pure |
529 Pragma_Remote_Call_Interface |
530 Pragma_Remote_Types |
531 Pragma_Shared_Passive => Analyze (PN);
532 when others => null;
533 end case;
534 end if;
536 Next (PN);
537 end loop;
538 if Is_Child_Unit (S)
539 and then Is_Generic_Instance (S)
540 then
541 Set_Parents (False);
542 end if;
544 end;
545 end Set_Categorization_From_Pragmas;
547 -----------------------------------
548 -- Set_Categorization_From_Scope --
549 -----------------------------------
551 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
552 Declaration : Node_Id := Empty;
553 Specification : Node_Id := Empty;
555 begin
556 Set_Is_Pure (E,
557 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
559 if not Is_Remote_Call_Interface (E) then
560 if Ekind (E) in Subprogram_Kind then
561 Declaration := Unit_Declaration_Node (E);
563 if False
564 or else Nkind (Declaration) = N_Subprogram_Body
565 or else Nkind (Declaration) = N_Subprogram_Renaming_Declaration
566 then
567 Specification := Corresponding_Spec (Declaration);
568 end if;
569 end if;
571 -- A subprogram body or renaming-as-body is a remote call
572 -- interface if it serves as the completion of a subprogram
573 -- declaration that is a remote call interface.
575 if Nkind (Specification) in N_Entity then
576 Set_Is_Remote_Call_Interface
577 (E, Is_Remote_Call_Interface (Specification));
579 -- A subprogram declaration is a remote call interface when it is
580 -- declared within the visible part of, or declared by, a library
581 -- unit declaration that is a remote call interface.
583 else
584 Set_Is_Remote_Call_Interface
585 (E, Is_Remote_Call_Interface (Scop)
586 and then not (In_Private_Part (Scop)
587 or else In_Package_Body (Scop)));
588 end if;
589 end if;
591 Set_Is_Remote_Types (E, Is_Remote_Types (Scop));
592 end Set_Categorization_From_Scope;
594 ------------------------------
595 -- Static_Discriminant_Expr --
596 ------------------------------
598 -- We need to accomodate a Why_Not_Static call somehow here ???
600 function Static_Discriminant_Expr (L : List_Id) return Boolean is
601 Discriminant_Spec : Node_Id;
603 begin
604 Discriminant_Spec := First (L);
605 while Present (Discriminant_Spec) loop
606 if Present (Expression (Discriminant_Spec))
607 and then not Is_Static_Expression (Expression (Discriminant_Spec))
608 then
609 return False;
610 end if;
612 Next (Discriminant_Spec);
613 end loop;
615 return True;
616 end Static_Discriminant_Expr;
618 --------------------------------------
619 -- Validate_Access_Type_Declaration --
620 --------------------------------------
622 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
623 Def : constant Node_Id := Type_Definition (N);
625 begin
626 case Nkind (Def) is
627 when N_Access_To_Subprogram_Definition =>
629 -- A pure library_item must not contain the declaration of a
630 -- named access type, except within a subprogram, generic
631 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
633 if Comes_From_Source (T)
634 and then In_Pure_Unit
635 and then not In_Subprogram_Task_Protected_Unit
636 then
637 Error_Msg_N ("named access type not allowed in pure unit", T);
638 end if;
640 when N_Access_To_Object_Definition =>
642 if Comes_From_Source (T)
643 and then In_Pure_Unit
644 and then not In_Subprogram_Task_Protected_Unit
645 then
646 Error_Msg_N
647 ("named access type not allowed in pure unit", T);
648 end if;
650 -- Check for RCI or RT unit type declaration. It should not
651 -- contain the declaration of an access-to-object type unless it
652 -- is a general access type that designates a class-wide limited
653 -- private type. There are also constraints about the primitive
654 -- subprograms of the class-wide type.
656 Validate_Remote_Access_Object_Type_Declaration (T);
658 -- Check for shared passive unit type declaration. It should
659 -- not contain the declaration of access to class wide type,
660 -- access to task type and access to protected type with entry.
662 Validate_SP_Access_Object_Type_Decl (T);
664 when others => null;
665 end case;
667 -- Set categorization flag from package on entity as well, to allow
668 -- easy checks later on for required validations of RCI or RT units.
669 -- This is only done for entities that are in the original source.
671 if Comes_From_Source (T)
672 and then not (In_Package_Body (Scope (T))
673 or else In_Private_Part (Scope (T)))
674 then
675 Set_Is_Remote_Call_Interface
676 (T, Is_Remote_Call_Interface (Scope (T)));
677 Set_Is_Remote_Types
678 (T, Is_Remote_Types (Scope (T)));
679 end if;
680 end Validate_Access_Type_Declaration;
682 ----------------------------
683 -- Validate_Ancestor_Part --
684 ----------------------------
686 procedure Validate_Ancestor_Part (N : Node_Id) is
687 A : constant Node_Id := Ancestor_Part (N);
688 T : constant Entity_Id := Entity (A);
690 begin
691 if In_Preelaborated_Unit
692 and then not In_Subprogram_Or_Concurrent_Unit
693 and then (not Inside_A_Generic
694 or else Present (Enclosing_Generic_Body (N)))
695 then
696 -- We relax the restriction of 10.2.1(9) within GNAT
697 -- units to allow packages such as Ada.Strings.Unbounded
698 -- to be implemented (i.p., Null_Unbounded_String).
699 -- (There are ACVC tests that check that the restriction
700 -- is enforced, but note that AI-161, once approved,
701 -- will relax the restriction prohibiting default-
702 -- initialized objects of private and controlled
703 -- types.)
705 if Is_Private_Type (T)
706 and then not Is_Internal_File_Name
707 (Unit_File_Name (Get_Source_Unit (N)))
708 then
709 Error_Msg_N
710 ("private ancestor type not allowed in preelaborated unit", A);
712 elsif Is_Record_Type (T) then
713 if Nkind (Parent (T)) = N_Full_Type_Declaration then
714 Check_Non_Static_Default_Expr
715 (Type_Definition (Parent (T)), A);
716 end if;
717 end if;
718 end if;
719 end Validate_Ancestor_Part;
721 ----------------------------------------
722 -- Validate_Categorization_Dependency --
723 ----------------------------------------
725 procedure Validate_Categorization_Dependency
726 (N : Node_Id;
727 E : Entity_Id)
729 K : constant Node_Kind := Nkind (N);
730 P : Node_Id := Parent (N);
731 U : Entity_Id := E;
732 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
734 begin
735 -- Only validate library units and subunits. For subunits, checks
736 -- concerning withed units apply to the parent compilation unit.
738 if Is_Subunit then
739 P := Parent (P);
740 U := Scope (E);
742 while Present (U)
743 and then not Is_Compilation_Unit (U)
744 and then not Is_Child_Unit (U)
745 loop
746 U := Scope (U);
747 end loop;
749 end if;
751 if Nkind (P) /= N_Compilation_Unit then
752 return;
753 end if;
755 -- Body of RCI unit does not need validation.
757 if Is_Remote_Call_Interface (E)
758 and then (Nkind (N) = N_Package_Body
759 or else Nkind (N) = N_Subprogram_Body)
760 then
761 return;
762 end if;
764 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
766 declare
767 Item : Node_Id;
768 Entity_Of_Withed : Entity_Id;
770 begin
771 Item := First (Context_Items (P));
773 while Present (Item) loop
774 if Nkind (Item) = N_With_Clause
775 and then not (Implicit_With (Item)
776 or else Limited_Present (Item))
777 then
778 Entity_Of_Withed := Entity (Name (Item));
779 Check_Categorization_Dependencies
780 (U, Entity_Of_Withed, Item, Is_Subunit);
781 end if;
783 Next (Item);
784 end loop;
785 end;
787 -- Child depends on parent; therefore parent should also
788 -- be categorized and satify the dependency hierarchy.
790 -- Check if N is a child spec.
792 if (K in N_Generic_Declaration or else
793 K in N_Generic_Instantiation or else
794 K in N_Generic_Renaming_Declaration or else
795 K = N_Package_Declaration or else
796 K = N_Package_Renaming_Declaration or else
797 K = N_Subprogram_Declaration or else
798 K = N_Subprogram_Renaming_Declaration)
799 and then Present (Parent_Spec (N))
800 then
801 Check_Categorization_Dependencies (E, Scope (E), N, False);
803 -- Verify that public child of an RCI library unit
804 -- must also be an RCI library unit (RM E.2.3(15)).
806 if Is_Remote_Call_Interface (Scope (E))
807 and then not Private_Present (P)
808 and then not Is_Remote_Call_Interface (E)
809 then
810 Error_Msg_N ("public child of rci unit must also be rci unit", N);
811 end if;
812 end if;
813 end Validate_Categorization_Dependency;
815 --------------------------------
816 -- Validate_Controlled_Object --
817 --------------------------------
819 procedure Validate_Controlled_Object (E : Entity_Id) is
820 begin
821 -- For now, never apply this check for internal GNAT units, since we
822 -- have a number of cases in the library where we are stuck with objects
823 -- of this type, and the RM requires Preelaborate.
825 -- For similar reasons, we only do this check for source entities, since
826 -- we generate entities of this type in some situations.
828 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
829 -- We have to enforce them for RM compatibility, but we have no trouble
830 -- accepting these objects and doing the right thing. Note that there is
831 -- no requirement that Preelaborate not actually generate any code!
833 if In_Preelaborated_Unit
834 and then not Debug_Flag_PP
835 and then Comes_From_Source (E)
836 and then not
837 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
838 and then (not Inside_A_Generic
839 or else Present (Enclosing_Generic_Body (E)))
840 and then not Is_Protected_Type (Etype (E))
841 then
842 Error_Msg_N
843 ("library level controlled object not allowed in " &
844 "preelaborated unit", E);
845 end if;
846 end Validate_Controlled_Object;
848 --------------------------------------
849 -- Validate_Null_Statement_Sequence --
850 --------------------------------------
852 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
853 Item : Node_Id;
855 begin
856 if In_Preelaborated_Unit then
857 Item := First (Statements (Handled_Statement_Sequence (N)));
859 while Present (Item) loop
860 if Nkind (Item) /= N_Label
861 and then Nkind (Item) /= N_Null_Statement
862 then
863 Error_Msg_N
864 ("statements not allowed in preelaborated unit", Item);
865 exit;
866 end if;
868 Next (Item);
869 end loop;
870 end if;
871 end Validate_Null_Statement_Sequence;
873 ---------------------------------
874 -- Validate_Object_Declaration --
875 ---------------------------------
877 procedure Validate_Object_Declaration (N : Node_Id) is
878 Id : constant Entity_Id := Defining_Identifier (N);
879 E : constant Node_Id := Expression (N);
880 Odf : constant Node_Id := Object_Definition (N);
881 T : constant Entity_Id := Etype (Id);
883 begin
884 -- Verify that any access to subprogram object does not have in its
885 -- subprogram profile access type parameters or limited parameters
886 -- without Read and Write attributes (E.2.3(13)).
888 Validate_RCI_Subprogram_Declaration (N);
890 -- Check that if we are in preelaborated elaboration code, then we
891 -- do not have an instance of a default initialized private, task or
892 -- protected object declaration which would violate (RM 10.2.1(9)).
893 -- Note that constants are never default initialized (and the test
894 -- below also filters out deferred constants). A variable is default
895 -- initialized if it does *not* have an initialization expression.
897 -- Filter out cases that are not declaration of a variable from source
899 if Nkind (N) /= N_Object_Declaration
900 or else Constant_Present (N)
901 or else not Comes_From_Source (Id)
902 then
903 return;
904 end if;
906 -- Exclude generic specs from the checks (this will get rechecked
907 -- on instantiations).
909 if Inside_A_Generic
910 and then not Present (Enclosing_Generic_Body (Id))
911 then
912 return;
913 end if;
915 -- Required checks for declaration that is in a preelaborated
916 -- package and is not within some subprogram.
918 if In_Preelaborated_Unit
919 and then not In_Subprogram_Or_Concurrent_Unit
920 then
921 -- Check for default initialized variable case. Note that in
922 -- accordance with (RM B.1(24)) imported objects are not
923 -- subject to default initialization.
925 if No (E) and then not Is_Imported (Id) then
926 declare
927 Ent : Entity_Id := T;
929 begin
930 -- An array whose component type is a record with nonstatic
931 -- default expressions is a violation, so we get the array's
932 -- component type.
934 if Is_Array_Type (Ent) then
935 declare
936 Comp_Type : Entity_Id := Component_Type (Ent);
938 begin
939 while Is_Array_Type (Comp_Type) loop
940 Comp_Type := Component_Type (Comp_Type);
941 end loop;
943 Ent := Comp_Type;
944 end;
945 end if;
947 -- Object decl. that is of record type and has no default expr.
948 -- should check if there is any non-static default expression
949 -- in component decl. of the record type decl.
951 if Is_Record_Type (Ent) then
952 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
953 Check_Non_Static_Default_Expr
954 (Type_Definition (Parent (Ent)), N);
956 elsif Nkind (Odf) = N_Subtype_Indication
957 and then not Is_Array_Type (T)
958 and then not Is_Private_Type (T)
959 then
960 Check_Non_Static_Default_Expr (Type_Definition
961 (Parent (Entity (Subtype_Mark (Odf)))), N);
962 end if;
963 end if;
965 -- We relax the restriction of 10.2.1(9) within GNAT
966 -- units. (There are ACVC tests that check that the
967 -- restriction is enforced, but note that AI-161,
968 -- once approved, will relax the restriction prohibiting
969 -- default-initialized objects of private types, and
970 -- will recommend a pragma for marking private types.)
972 if (Is_Private_Type (Ent)
973 or else Depends_On_Private (Ent))
974 and then not Is_Internal_File_Name
975 (Unit_File_Name (Get_Source_Unit (N)))
976 then
977 Error_Msg_N
978 ("private object not allowed in preelaborated unit", N);
979 return;
981 -- Access to Task or Protected type
983 elsif Is_Entity_Name (Odf)
984 and then Present (Etype (Odf))
985 and then Is_Access_Type (Etype (Odf))
986 then
987 Ent := Designated_Type (Etype (Odf));
989 elsif Is_Entity_Name (Odf) then
990 Ent := Entity (Odf);
992 elsif Nkind (Odf) = N_Subtype_Indication then
993 Ent := Etype (Subtype_Mark (Odf));
995 elsif
996 Nkind (Odf) = N_Constrained_Array_Definition
997 then
998 Ent := Component_Type (T);
1000 -- else
1001 -- return;
1002 end if;
1004 if Is_Task_Type (Ent)
1005 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1006 then
1007 Error_Msg_N
1008 ("concurrent object not allowed in preelaborated unit",
1010 return;
1011 end if;
1012 end;
1013 end if;
1015 -- Non-static discriminant not allowed in preelaborayted unit
1017 if Is_Record_Type (Etype (Id)) then
1018 declare
1019 ET : constant Entity_Id := Etype (Id);
1020 EE : constant Entity_Id := Etype (Etype (Id));
1021 PEE : Node_Id;
1023 begin
1024 if Has_Discriminants (ET)
1025 and then Present (EE)
1026 then
1027 PEE := Parent (EE);
1029 if Nkind (PEE) = N_Full_Type_Declaration
1030 and then not Static_Discriminant_Expr
1031 (Discriminant_Specifications (PEE))
1032 then
1033 Error_Msg_N
1034 ("non-static discriminant in preelaborated unit",
1035 PEE);
1036 end if;
1037 end if;
1038 end;
1039 end if;
1040 end if;
1042 -- A pure library_item must not contain the declaration of any
1043 -- variable except within a subprogram, generic subprogram, task
1044 -- unit or protected unit (RM 10.2.1(16)).
1046 if In_Pure_Unit
1047 and then not In_Subprogram_Task_Protected_Unit
1048 then
1049 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1051 -- The visible part of an RCI library unit must not contain the
1052 -- declaration of a variable (RM E.1.3(9))
1054 elsif In_RCI_Declaration (N) then
1055 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1057 -- The visible part of a Shared Passive library unit must not contain
1058 -- the declaration of a variable (RM E.2.2(7))
1060 elsif In_RT_Declaration then
1061 Error_Msg_N
1062 ("variable declaration not allowed in remote types unit", N);
1063 end if;
1065 end Validate_Object_Declaration;
1067 -------------------------------
1068 -- Validate_RCI_Declarations --
1069 -------------------------------
1071 procedure Validate_RCI_Declarations (P : Entity_Id) is
1072 E : Entity_Id;
1074 begin
1075 E := First_Entity (P);
1076 while Present (E) loop
1077 if Comes_From_Source (E) then
1078 if Is_Limited_Type (E) then
1079 Error_Msg_N
1080 ("Limited type not allowed in rci unit", Parent (E));
1081 Explain_Limited_Type (E, Parent (E));
1083 elsif Ekind (E) = E_Generic_Function
1084 or else Ekind (E) = E_Generic_Package
1085 or else Ekind (E) = E_Generic_Procedure
1086 then
1087 Error_Msg_N ("generic declaration not allowed in rci unit",
1088 Parent (E));
1090 elsif (Ekind (E) = E_Function
1091 or else Ekind (E) = E_Procedure)
1092 and then Has_Pragma_Inline (E)
1093 then
1094 Error_Msg_N
1095 ("inlined subprogram not allowed in rci unit", Parent (E));
1097 -- Inner packages that are renamings need not be checked.
1098 -- Generic RCI packages are subject to the checks, but
1099 -- entities that come from formal packages are not part of the
1100 -- visible declarations of the package and are not checked.
1102 elsif Ekind (E) = E_Package then
1103 if Present (Renamed_Entity (E)) then
1104 null;
1106 elsif Ekind (P) /= E_Generic_Package
1107 or else List_Containing (Unit_Declaration_Node (E)) /=
1108 Generic_Formal_Declarations
1109 (Unit_Declaration_Node (P))
1110 then
1111 Validate_RCI_Declarations (E);
1112 end if;
1113 end if;
1114 end if;
1116 Next_Entity (E);
1117 end loop;
1118 end Validate_RCI_Declarations;
1120 -----------------------------------------
1121 -- Validate_RCI_Subprogram_Declaration --
1122 -----------------------------------------
1124 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1125 K : constant Node_Kind := Nkind (N);
1126 Profile : List_Id;
1127 Id : Node_Id;
1128 Param_Spec : Node_Id;
1129 Param_Type : Entity_Id;
1130 Base_Param_Type : Entity_Id;
1131 Type_Decl : Node_Id;
1132 Error_Node : Node_Id := N;
1134 begin
1135 -- There are two possible cases in which this procedure is called:
1137 -- 1. called from Analyze_Subprogram_Declaration.
1138 -- 2. called from Validate_Object_Declaration (access to subprogram).
1140 if not In_RCI_Declaration (N) then
1141 return;
1142 end if;
1144 if K = N_Subprogram_Declaration then
1145 Profile := Parameter_Specifications (Specification (N));
1147 else pragma Assert (K = N_Object_Declaration);
1148 Id := Defining_Identifier (N);
1150 if Nkind (Id) = N_Defining_Identifier
1151 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1152 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1153 then
1154 Profile :=
1155 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1156 else
1157 return;
1158 end if;
1159 end if;
1161 -- Iterate through the parameter specification list, checking that
1162 -- no access parameter and no limited type parameter in the list.
1163 -- RM E.2.3 (14)
1165 if Present (Profile) then
1166 Param_Spec := First (Profile);
1168 while Present (Param_Spec) loop
1169 Param_Type := Etype (Defining_Identifier (Param_Spec));
1170 Type_Decl := Parent (Param_Type);
1172 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1174 if K = N_Subprogram_Declaration then
1175 Error_Node := Param_Spec;
1176 end if;
1178 -- Report error only if declaration is in source program.
1180 if Comes_From_Source
1181 (Defining_Entity (Specification (N)))
1182 then
1183 Error_Msg_N
1184 ("subprogram in rci unit cannot have access parameter",
1185 Error_Node);
1186 end if;
1188 -- For limited private type parameter, we check only the
1189 -- private declaration and ignore full type declaration,
1190 -- unless this is the only declaration for the type, eg.
1191 -- as a limited record.
1193 elsif Is_Limited_Type (Param_Type)
1194 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1195 or else
1196 (Nkind (Type_Decl) = N_Full_Type_Declaration
1197 and then not (Has_Private_Declaration (Param_Type))
1198 and then Comes_From_Source (N)))
1199 then
1200 -- A limited parameter is legal only if user-specified
1201 -- Read and Write attributes exist for it.
1202 -- second part of RM E.2.3 (14)
1204 if No (Full_View (Param_Type))
1205 and then Ekind (Param_Type) /= E_Record_Type
1206 then
1207 -- Type does not have completion yet, so if declared in
1208 -- in the current RCI scope it is illegal, and will be
1209 -- flagged subsequently.
1210 return;
1211 end if;
1213 Base_Param_Type := Base_Type (Underlying_Type (Param_Type));
1215 if No (TSS (Base_Param_Type, TSS_Stream_Read))
1216 or else
1217 No (TSS (Base_Param_Type, TSS_Stream_Write))
1218 then
1219 if K = N_Subprogram_Declaration then
1220 Error_Node := Param_Spec;
1221 end if;
1223 Error_Msg_N
1224 ("limited parameter in rci unit "
1225 & "must have read/write attributes ", Error_Node);
1226 Explain_Limited_Type (Param_Type, Error_Node);
1227 end if;
1228 end if;
1230 Next (Param_Spec);
1231 end loop;
1232 end if;
1233 end Validate_RCI_Subprogram_Declaration;
1235 ----------------------------------------------------
1236 -- Validate_Remote_Access_Object_Type_Declaration --
1237 ----------------------------------------------------
1239 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1240 Direct_Designated_Type : Entity_Id;
1241 Desig_Type : Entity_Id;
1242 Primitive_Subprograms : Elist_Id;
1243 Subprogram : Elmt_Id;
1244 Subprogram_Node : Node_Id;
1245 Profile : List_Id;
1246 Param_Spec : Node_Id;
1247 Param_Type : Entity_Id;
1249 begin
1250 -- We are called from Analyze_Type_Declaration, and the Nkind
1251 -- of the given node is N_Access_To_Object_Definition.
1253 if not Comes_From_Source (T)
1254 or else (not In_RCI_Declaration (Parent (T))
1255 and then not In_RT_Declaration)
1256 then
1257 return;
1258 end if;
1260 -- An access definition in the private part of a Remote Types package
1261 -- may be legal if it has user-defined Read and Write attributes. This
1262 -- will be checked at the end of the package spec processing.
1264 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1265 return;
1266 end if;
1268 -- Check RCI or RT unit type declaration. It may not contain
1269 -- the declaration of an access-to-object type unless it is a
1270 -- general access type that designates a class-wide limited
1271 -- private type. There are also constraints about the primitive
1272 -- subprograms of the class-wide type (RM E.2.3(14)).
1274 if Ekind (T) /= E_General_Access_Type
1275 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1276 then
1277 if In_RCI_Declaration (Parent (T)) then
1278 Error_Msg_N
1279 ("access type in Remote_Call_Interface unit must be " &
1280 "general access", T);
1281 else
1282 Error_Msg_N ("access type in Remote_Types unit must be " &
1283 "general access", T);
1284 end if;
1285 Error_Msg_N ("\to class-wide type", T);
1286 return;
1287 end if;
1289 Direct_Designated_Type := Designated_Type (T);
1290 Desig_Type := Etype (Direct_Designated_Type);
1292 if not Is_Recursively_Limited_Private (Desig_Type) then
1293 Error_Msg_N
1294 ("error in designated type of remote access to class-wide type", T);
1295 Error_Msg_N
1296 ("\must be tagged limited private or private extension of type", T);
1297 return;
1298 end if;
1300 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1301 Subprogram := First_Elmt (Primitive_Subprograms);
1303 while Subprogram /= No_Elmt loop
1304 Subprogram_Node := Node (Subprogram);
1306 if not Comes_From_Source (Subprogram_Node) then
1307 goto Next_Subprogram;
1308 end if;
1310 Profile := Parameter_Specifications (Parent (Subprogram_Node));
1312 -- Profile must exist, otherwise not primitive operation
1314 Param_Spec := First (Profile);
1316 while Present (Param_Spec) loop
1318 -- Now find out if this parameter is a controlling parameter
1320 Param_Type := Parameter_Type (Param_Spec);
1322 if (Nkind (Param_Type) = N_Access_Definition
1323 and then Etype (Subtype_Mark (Param_Type)) = Desig_Type)
1324 or else (Nkind (Param_Type) /= N_Access_Definition
1325 and then Etype (Param_Type) = Desig_Type)
1326 then
1327 -- It is a controlling parameter, so specific checks below
1328 -- do not apply.
1330 null;
1332 elsif
1333 Nkind (Param_Type) = N_Access_Definition
1334 then
1335 -- From RM E.2.2(14), no access parameter other than
1336 -- controlling ones may be used.
1338 Error_Msg_N
1339 ("non-controlling access parameter", Param_Spec);
1341 elsif
1342 Is_Limited_Type (Etype (Defining_Identifier (Param_Spec)))
1343 then
1344 -- Not a controlling parameter, so type must have Read
1345 -- and Write attributes.
1347 if Nkind (Param_Type) in N_Has_Etype
1348 and then Nkind (Parent (Etype (Param_Type))) =
1349 N_Private_Type_Declaration
1350 then
1351 Param_Type := Etype (Param_Type);
1353 if No (TSS (Param_Type, TSS_Stream_Read))
1354 or else
1355 No (TSS (Param_Type, TSS_Stream_Write))
1356 then
1357 Error_Msg_N
1358 ("limited formal must have Read and Write attributes",
1359 Param_Spec);
1360 Explain_Limited_Type
1361 (Etype (Defining_Identifier (Param_Spec)), Param_Spec);
1362 end if;
1363 end if;
1364 end if;
1366 -- Check next parameter in this subprogram
1368 Next (Param_Spec);
1369 end loop;
1371 <<Next_Subprogram>>
1372 Next_Elmt (Subprogram);
1373 end loop;
1375 -- Now this is an RCI unit access-to-class-wide-limited-private type
1376 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1377 -- optimize later checks by avoiding tree traversal to find out if this
1378 -- entity is inside an RCI unit.
1380 Set_Is_Remote_Call_Interface (T);
1382 end Validate_Remote_Access_Object_Type_Declaration;
1384 -----------------------------------------------
1385 -- Validate_Remote_Access_To_Class_Wide_Type --
1386 -----------------------------------------------
1388 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1389 K : constant Node_Kind := Nkind (N);
1390 PK : constant Node_Kind := Nkind (Parent (N));
1391 E : Entity_Id;
1393 begin
1394 -- This subprogram enforces the checks in (RM E.2.2(8)) for
1395 -- certain uses of class-wide limited private types.
1397 -- Storage_Pool and Storage_Size are not defined for such types
1399 -- The expected type of allocator must not not be such a type.
1401 -- The actual parameter of generic instantiation must not
1402 -- be such a type if the formal parameter is of an access type.
1404 -- On entry, there are five cases
1406 -- 1. called from sem_attr Analyze_Attribute where attribute
1407 -- name is either Storage_Pool or Storage_Size.
1409 -- 2. called from exp_ch4 Expand_N_Allocator
1411 -- 3. called from sem_ch12 Analyze_Associations
1413 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1415 -- 5. called from sem_res Resolve_Actuals
1417 if K = N_Attribute_Reference then
1418 E := Etype (Prefix (N));
1420 if Is_Remote_Access_To_Class_Wide_Type (E) then
1421 Error_Msg_N ("incorrect attribute of remote operand", N);
1422 return;
1423 end if;
1425 elsif K = N_Allocator then
1426 E := Etype (N);
1428 if Is_Remote_Access_To_Class_Wide_Type (E) then
1429 Error_Msg_N ("incorrect expected remote type of allocator", N);
1430 return;
1431 end if;
1433 elsif K in N_Has_Entity then
1434 E := Entity (N);
1436 if Is_Remote_Access_To_Class_Wide_Type (E) then
1437 Error_Msg_N ("incorrect remote type generic actual", N);
1438 return;
1439 end if;
1441 -- This subprogram also enforces the checks in E.2.2(13).
1442 -- A value of such type must not be dereferenced unless as a
1443 -- controlling operand of a dispatching call.
1445 elsif K = N_Explicit_Dereference
1446 and then (Comes_From_Source (N)
1447 or else (Nkind (Original_Node (N)) = N_Selected_Component
1448 and then Comes_From_Source (Original_Node (N))))
1449 then
1450 E := Etype (Prefix (N));
1452 -- If the class-wide type is not a remote one, the restrictions
1453 -- do not apply.
1455 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1456 return;
1457 end if;
1459 -- If we have a true dereference that comes from source and that
1460 -- is a controlling argument for a dispatching call, accept it.
1462 if K = N_Explicit_Dereference
1463 and then Is_Actual_Parameter (N)
1464 and then Is_Controlling_Actual (N)
1465 then
1466 return;
1467 end if;
1469 -- If we are just within a procedure or function call and the
1470 -- dereference has not been analyzed, return because this
1471 -- procedure will be called again from sem_res Resolve_Actuals.
1473 if Is_Actual_Parameter (N)
1474 and then not Analyzed (N)
1475 then
1476 return;
1477 end if;
1479 -- The following is to let the compiler generated tags check
1480 -- pass through without error message. This is a bit kludgy
1481 -- isn't there some better way of making this exclusion ???
1483 if (PK = N_Selected_Component
1484 and then Present (Parent (Parent (N)))
1485 and then Nkind (Parent (Parent (N))) = N_Op_Ne)
1486 or else (PK = N_Unchecked_Type_Conversion
1487 and then Present (Parent (Parent (N)))
1488 and then
1489 Nkind (Parent (Parent (N))) = N_Selected_Component)
1490 then
1491 return;
1492 end if;
1494 -- The following code is needed for expansion of RACW Write
1495 -- attribute, since such expressions can appear in the expanded
1496 -- code.
1498 if not Comes_From_Source (N)
1499 and then
1500 (PK = N_In
1501 or else PK = N_Attribute_Reference
1502 or else
1503 (PK = N_Type_Conversion
1504 and then Present (Parent (N))
1505 and then Present (Parent (Parent (N)))
1506 and then
1507 Nkind (Parent (Parent (N))) = N_Selected_Component))
1508 then
1509 return;
1510 end if;
1512 Error_Msg_N ("incorrect remote type dereference", N);
1513 end if;
1514 end Validate_Remote_Access_To_Class_Wide_Type;
1516 ------------------------------------------
1517 -- Validate_Remote_Type_Type_Conversion --
1518 ------------------------------------------
1520 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1521 S : constant Entity_Id := Etype (N);
1522 E : constant Entity_Id := Etype (Expression (N));
1524 begin
1525 -- This test is required in the case where a conversion appears
1526 -- inside a normal package, it does not necessarily have to be
1527 -- inside an RCI, Remote_Types unit (RM E.2.2(9,12)).
1529 if Is_Remote_Access_To_Subprogram_Type (E)
1530 and then not Is_Remote_Access_To_Subprogram_Type (S)
1531 then
1532 Error_Msg_N
1533 ("incorrect conversion of remote operand to local type", N);
1534 return;
1536 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1537 and then Is_Remote_Access_To_Subprogram_Type (S)
1538 then
1539 Error_Msg_N
1540 ("incorrect conversion of local operand to remote type", N);
1541 return;
1543 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1544 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1545 then
1546 Error_Msg_N
1547 ("incorrect conversion of remote operand to local type", N);
1548 return;
1549 end if;
1551 -- If a local access type is converted into a RACW type, then the
1552 -- current unit has a pointer that may now be exported to another
1553 -- partition.
1555 if Is_Remote_Access_To_Class_Wide_Type (S)
1556 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1557 then
1558 Set_Has_RACW (Current_Sem_Unit);
1559 end if;
1560 end Validate_Remote_Type_Type_Conversion;
1562 -------------------------------
1563 -- Validate_RT_RAT_Component --
1564 -------------------------------
1566 procedure Validate_RT_RAT_Component (N : Node_Id) is
1567 Spec : constant Node_Id := Specification (N);
1568 Name_U : constant Entity_Id := Defining_Entity (Spec);
1569 Typ : Entity_Id;
1570 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1571 In_Visible_Part : Boolean := True;
1573 begin
1574 if not Is_Remote_Types (Name_U) then
1575 return;
1576 end if;
1578 Typ := First_Entity (Name_U);
1579 while Present (Typ) loop
1580 if In_Visible_Part and then Typ = First_Priv_Ent then
1581 In_Visible_Part := False;
1582 end if;
1584 if Comes_From_Source (Typ)
1585 and then Is_Type (Typ)
1586 and then (In_Visible_Part or else Has_Private_Declaration (Typ))
1587 then
1588 if Missing_Read_Write_Attributes (Typ) then
1589 if Is_Non_Remote_Access_Type (Typ) then
1590 Error_Msg_N
1591 ("non-remote access type without user-defined Read " &
1592 "and Write attributes", Typ);
1593 else
1594 Error_Msg_N
1595 ("record type containing a component of a " &
1596 "non-remote access", Typ);
1597 Error_Msg_N
1598 ("\type without Read and Write attributes " &
1599 "('R'M E.2.2(8))", Typ);
1600 end if;
1601 end if;
1602 end if;
1604 Next_Entity (Typ);
1605 end loop;
1606 end Validate_RT_RAT_Component;
1608 -----------------------------------------
1609 -- Validate_SP_Access_Object_Type_Decl --
1610 -----------------------------------------
1612 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1613 Direct_Designated_Type : Entity_Id;
1615 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1616 -- Return true if the protected type designated by T has
1617 -- entry declarations.
1619 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1620 Ety : Entity_Id;
1622 begin
1623 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1624 Ety := First_Entity (E);
1625 while Present (Ety) loop
1626 if Ekind (Ety) = E_Entry then
1627 return True;
1628 end if;
1630 Next_Entity (Ety);
1631 end loop;
1632 end if;
1634 return False;
1635 end Has_Entry_Declarations;
1637 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1639 begin
1640 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1641 -- Nkind of the given entity is N_Access_To_Object_Definition.
1643 if not Comes_From_Source (T)
1644 or else not In_Shared_Passive_Unit
1645 or else In_Subprogram_Task_Protected_Unit
1646 then
1647 return;
1648 end if;
1650 -- Check Shared Passive unit. It should not contain the declaration
1651 -- of an access-to-object type whose designated type is a class-wide
1652 -- type, task type or protected type with entry (RM E.2.1(7)).
1654 Direct_Designated_Type := Designated_Type (T);
1656 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
1657 Error_Msg_N
1658 ("invalid access-to-class-wide type in shared passive unit", T);
1659 return;
1661 elsif Ekind (Direct_Designated_Type) in Task_Kind then
1662 Error_Msg_N
1663 ("invalid access-to-task type in shared passive unit", T);
1664 return;
1666 elsif Ekind (Direct_Designated_Type) in Protected_Kind
1667 and then Has_Entry_Declarations (Direct_Designated_Type)
1668 then
1669 Error_Msg_N
1670 ("invalid access-to-protected type in shared passive unit", T);
1671 return;
1672 end if;
1673 end Validate_SP_Access_Object_Type_Decl;
1675 ---------------------------------
1676 -- Validate_Static_Object_Name --
1677 ---------------------------------
1679 procedure Validate_Static_Object_Name (N : Node_Id) is
1680 E : Entity_Id;
1682 function Is_Primary (N : Node_Id) return Boolean;
1683 -- Determine whether node is syntactically a primary in an expression.
1685 function Is_Primary (N : Node_Id) return Boolean is
1686 K : constant Node_Kind := Nkind (Parent (N));
1688 begin
1689 case K is
1691 when N_Op | N_In | N_Not_In =>
1692 return True;
1694 when N_Aggregate
1695 | N_Component_Association
1696 | N_Index_Or_Discriminant_Constraint =>
1697 return True;
1699 when N_Attribute_Reference =>
1700 return Attribute_Name (Parent (N)) /= Name_Address
1701 and then Attribute_Name (Parent (N)) /= Name_Access
1702 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
1703 and then
1704 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
1706 when N_Indexed_Component =>
1707 return (N /= Prefix (Parent (N))
1708 or else Is_Primary (Parent (N)));
1710 when N_Qualified_Expression | N_Type_Conversion =>
1711 return Is_Primary (Parent (N));
1713 when N_Assignment_Statement | N_Object_Declaration =>
1714 return (N = Expression (Parent (N)));
1716 when N_Selected_Component =>
1717 return Is_Primary (Parent (N));
1719 when others =>
1720 return False;
1721 end case;
1722 end Is_Primary;
1724 -- Start of processing for Validate_Static_Object_Name
1726 begin
1727 if not In_Preelaborated_Unit
1728 or else not Comes_From_Source (N)
1729 or else In_Subprogram_Or_Concurrent_Unit
1730 or else Ekind (Current_Scope) = E_Block
1731 then
1732 return;
1734 -- Filter out cases where primary is default in a component
1735 -- declaration, discriminant specification, or actual in a record
1736 -- type initialization call.
1738 -- Initialization call of internal types.
1740 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
1742 if Present (Parent (Parent (N)))
1743 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
1744 then
1745 return;
1746 end if;
1748 if Nkind (Name (Parent (N))) = N_Identifier
1749 and then not Comes_From_Source (Entity (Name (Parent (N))))
1750 then
1751 return;
1752 end if;
1753 end if;
1755 -- Error if the name is a primary in an expression. The parent must not
1756 -- be an operator, or a selected component or an indexed component that
1757 -- is itself a primary. Entities that are actuals do not need to be
1758 -- checked, because the call itself will be diagnosed.
1760 if Is_Primary (N)
1761 and then (not Inside_A_Generic
1762 or else Present (Enclosing_Generic_Body (N)))
1763 then
1764 if Ekind (Entity (N)) = E_Variable then
1765 Flag_Non_Static_Expr
1766 ("non-static object name in preelaborated unit", N);
1768 -- We take the view that a constant defined in another preelaborated
1769 -- unit is preelaborable, even though it may have a private type and
1770 -- thus appear non-static in a client. This must be the intent of
1771 -- the language, but currently is an RM gap.
1773 elsif Ekind (Entity (N)) = E_Constant
1774 and then not Is_Static_Expression (N)
1775 then
1776 E := Entity (N);
1778 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
1779 and then
1780 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
1781 and then (Is_Preelaborated (Scope (E))
1782 or else Is_Pure (Scope (E))
1783 or else (Present (Renamed_Object (E))
1784 and then
1785 Is_Entity_Name (Renamed_Object (E))
1786 and then
1787 (Is_Preelaborated
1788 (Scope (Renamed_Object (E)))
1789 or else
1790 Is_Pure (Scope
1791 (Renamed_Object (E))))))
1792 then
1793 null;
1794 else
1795 Flag_Non_Static_Expr
1796 ("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;