* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / sem_cat.adb
blobdb7594cf3b8cc96b91873892a03b81c1bd668496
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Opt; use Opt;
37 with Sem; use Sem;
38 with Sem_Eval; use Sem_Eval;
39 with Sem_Util; use Sem_Util;
40 with Sinfo; use Sinfo;
41 with Snames; use Snames;
42 with Stand; use Stand;
44 package body Sem_Cat is
46 -----------------------
47 -- Local Subprograms --
48 -----------------------
50 procedure Check_Categorization_Dependencies
51 (Unit_Entity : Entity_Id;
52 Depended_Entity : Entity_Id;
53 Info_Node : Node_Id;
54 Is_Subunit : Boolean);
55 -- This procedure checks that the categorization of a lib unit and that
56 -- of the depended unit satisfy dependency restrictions.
57 -- The depended_entity can be the entity in a with_clause item, in which
58 -- case Info_Node denotes that item. The depended_entity can also be the
59 -- parent unit of a child unit, in which case Info_Node is the declaration
60 -- of the child unit. The error message is posted on Info_Node, and is
61 -- specialized if Is_Subunit is true.
63 procedure Check_Non_Static_Default_Expr
64 (Type_Def : Node_Id;
65 Obj_Decl : Node_Id);
66 -- Iterate through the component list of a record definition, check
67 -- that no component is declared with a nonstatic default value.
68 -- If a nonstatic default exists, report an error on Obj_Decl.
70 -- Iterate through the component list of a record definition, check
71 -- that no component is declared with a non-static default value.
73 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
74 -- Return True if the entity or one of its subcomponent is an access
75 -- type which does not have user-defined Read and Write attribute.
77 function In_RCI_Declaration (N : Node_Id) return Boolean;
78 -- Determines if a declaration is within the visible part of a Remote
79 -- Call Interface compilation unit, for semantic checking purposes only,
80 -- (returns false within an instance and within the package body).
82 function In_RT_Declaration return Boolean;
83 -- Determines if current scope is within a Remote Types compilation unit,
84 -- for semantic checking purposes.
86 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
87 -- Returns true if the entity is a non-remote access type
89 function In_Shared_Passive_Unit return Boolean;
90 -- Determines if current scope is within a Shared Passive compilation unit
92 function Static_Discriminant_Expr (L : List_Id) return Boolean;
93 -- Iterate through the list of discriminants to check if any of them
94 -- contains non-static default expression, which is a violation in
95 -- a preelaborated library unit.
97 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
98 -- Check validity of declaration if RCI or RT unit. It should not contain
99 -- the declaration of an access-to-object type unless it is a
100 -- general access type that designates a class-wide limited
101 -- private type. There are also constraints about the primitive
102 -- subprograms of the class-wide type. RM E.2 (9, 13, 14)
104 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean;
105 -- Return True if E is a limited private type, or if E is a private
106 -- extension of a type whose parent verifies this property (hence the
107 -- recursive keyword).
109 ---------------------------------------
110 -- Check_Categorization_Dependencies --
111 ---------------------------------------
113 procedure Check_Categorization_Dependencies
114 (Unit_Entity : Entity_Id;
115 Depended_Entity : Entity_Id;
116 Info_Node : Node_Id;
117 Is_Subunit : Boolean)
119 N : constant Node_Id := Info_Node;
121 -- Here we define an enumeration type to represent categorization
122 -- types, ordered so that a unit with a given categorization can
123 -- only WITH units with lower or equal categorization type.
125 type Categorization is
126 (Pure,
127 Shared_Passive,
128 Remote_Types,
129 Remote_Call_Interface,
130 Preelaborated,
131 Normal);
133 Unit_Category : Categorization;
134 With_Category : Categorization;
136 function Get_Categorization (E : Entity_Id) return Categorization;
137 -- Check categorization flags from entity, and return in the form
138 -- of a corresponding enumeration value.
140 ------------------------
141 -- Get_Categorization --
142 ------------------------
144 function Get_Categorization (E : Entity_Id) return Categorization is
145 begin
146 if Is_Preelaborated (E) then
147 return Preelaborated;
148 elsif Is_Pure (E) then
149 return Pure;
150 elsif Is_Shared_Passive (E) then
151 return Shared_Passive;
152 elsif Is_Remote_Types (E) then
153 return Remote_Types;
154 elsif Is_Remote_Call_Interface (E) then
155 return Remote_Call_Interface;
156 else
157 return Normal;
158 end if;
159 end Get_Categorization;
161 -- Start of processing for Check_Categorization_Dependencies
163 begin
164 -- Intrinsic subprograms are preelaborated, so do not impose any
165 -- categorization dependencies.
167 if Is_Intrinsic_Subprogram (Depended_Entity) then
168 return;
169 end if;
171 Unit_Category := Get_Categorization (Unit_Entity);
172 With_Category := Get_Categorization (Depended_Entity);
174 -- These messages are wanings in GNAT mode, to allow it to be
175 -- judiciously turned off. Otherwise it is a real error.
177 Error_Msg_Warn := GNAT_Mode;
179 -- Check for possible error
181 if With_Category > Unit_Category then
183 -- Special case: Remote_Types and Remote_Call_Interface are allowed
184 -- to be with'ed in package body.
186 if (Unit_Category = Remote_Types
187 or else Unit_Category = Remote_Call_Interface)
188 and then In_Package_Body (Unit_Entity)
189 then
190 null;
192 -- Here we have an error
194 else
195 if Is_Subunit then
196 Error_Msg_NE
197 ("<subunit cannot depend on& " &
198 "(parent has wrong categorization)", N, Depended_Entity);
200 else
201 Error_Msg_NE
202 ("<cannot depend on& " &
203 "(wrong categorization)", N, Depended_Entity);
204 end if;
206 -- Add further explanation for common cases
208 case Unit_Category is
209 when Pure =>
210 Error_Msg_NE
211 ("\<pure unit cannot depend on non-pure unit",
212 N, Depended_Entity);
214 when Preelaborated =>
215 Error_Msg_NE
216 ("\<preelaborated unit cannot depend on " &
217 "non-preelaborated unit",
218 N, Depended_Entity);
220 when others =>
221 null;
222 end case;
223 end if;
224 end if;
225 end Check_Categorization_Dependencies;
227 -----------------------------------
228 -- Check_Non_Static_Default_Expr --
229 -----------------------------------
231 procedure Check_Non_Static_Default_Expr
232 (Type_Def : Node_Id;
233 Obj_Decl : Node_Id)
235 Recdef : Node_Id;
236 Component_Decl : Node_Id;
238 begin
239 if Nkind (Type_Def) = N_Derived_Type_Definition then
240 Recdef := Record_Extension_Part (Type_Def);
242 if No (Recdef) then
243 return;
244 end if;
246 else
247 Recdef := Type_Def;
248 end if;
250 -- Check that component declarations do not involve:
252 -- a. a non-static default expression, where the object is
253 -- declared to be default initialized.
255 -- b. a dynamic Itype (discriminants and constraints)
257 if Null_Present (Recdef) then
258 return;
259 else
260 Component_Decl := First (Component_Items (Component_List (Recdef)));
261 end if;
263 while Present (Component_Decl)
264 and then Nkind (Component_Decl) = N_Component_Declaration
265 loop
266 if Present (Expression (Component_Decl))
267 and then Nkind (Expression (Component_Decl)) /= N_Null
268 and then not Is_Static_Expression (Expression (Component_Decl))
269 then
270 Error_Msg_Sloc := Sloc (Component_Decl);
271 Error_Msg_F
272 ("object in preelaborated unit has non-static default#",
273 Obj_Decl);
275 -- Fix this later ???
277 -- elsif Has_Dynamic_Itype (Component_Decl) then
278 -- Error_Msg_N
279 -- ("dynamic type discriminant," &
280 -- " constraint in preelaborated unit",
281 -- Component_Decl);
282 end if;
284 Next (Component_Decl);
285 end loop;
286 end Check_Non_Static_Default_Expr;
288 ---------------------------
289 -- In_Preelaborated_Unit --
290 ---------------------------
292 function In_Preelaborated_Unit return Boolean is
293 Unit_Entity : constant Entity_Id := Current_Scope;
294 Unit_Kind : constant Node_Kind :=
295 Nkind (Unit (Cunit (Current_Sem_Unit)));
297 begin
298 -- There are no constraints on body of remote_call_interface or
299 -- remote_types packages..
301 return (Unit_Entity /= Standard_Standard)
302 and then (Is_Preelaborated (Unit_Entity)
303 or else Is_Pure (Unit_Entity)
304 or else Is_Shared_Passive (Unit_Entity)
305 or else
306 ((Is_Remote_Types (Unit_Entity)
307 or else Is_Remote_Call_Interface (Unit_Entity))
308 and then Ekind (Unit_Entity) = E_Package
309 and then Unit_Kind /= N_Package_Body
310 and then not In_Package_Body (Unit_Entity)
311 and then not In_Instance));
312 end In_Preelaborated_Unit;
314 ------------------
315 -- In_Pure_Unit --
316 ------------------
318 function In_Pure_Unit return Boolean is
319 begin
320 return Is_Pure (Current_Scope);
321 end In_Pure_Unit;
323 ------------------------
324 -- In_RCI_Declaration --
325 ------------------------
327 function In_RCI_Declaration (N : Node_Id) return Boolean is
328 Unit_Entity : constant Entity_Id := Current_Scope;
329 Unit_Kind : constant Node_Kind :=
330 Nkind (Unit (Cunit (Current_Sem_Unit)));
332 begin
333 -- There are no restrictions on the private part or body
334 -- of an RCI unit.
336 return Is_Remote_Call_Interface (Unit_Entity)
337 and then (Ekind (Unit_Entity) = E_Package
338 or else Ekind (Unit_Entity) = E_Generic_Package)
339 and then Unit_Kind /= N_Package_Body
340 and then List_Containing (N) =
341 Visible_Declarations
342 (Specification (Unit_Declaration_Node (Unit_Entity)))
343 and then not In_Package_Body (Unit_Entity)
344 and then not In_Instance;
345 end In_RCI_Declaration;
347 -----------------------
348 -- In_RT_Declaration --
349 -----------------------
351 function In_RT_Declaration return Boolean is
352 Unit_Entity : constant Entity_Id := Current_Scope;
353 Unit_Kind : constant Node_Kind :=
354 Nkind (Unit (Cunit (Current_Sem_Unit)));
356 begin
357 -- There are no restrictions on the body of a Remote Types unit
359 return Is_Remote_Types (Unit_Entity)
360 and then (Ekind (Unit_Entity) = E_Package
361 or else Ekind (Unit_Entity) = E_Generic_Package)
362 and then Unit_Kind /= N_Package_Body
363 and then not In_Package_Body (Unit_Entity)
364 and then not In_Instance;
365 end In_RT_Declaration;
367 ----------------------------
368 -- In_Shared_Passive_Unit --
369 ----------------------------
371 function In_Shared_Passive_Unit return Boolean is
372 Unit_Entity : constant Entity_Id := Current_Scope;
374 begin
375 return Is_Shared_Passive (Unit_Entity);
376 end In_Shared_Passive_Unit;
378 ---------------------------------------
379 -- In_Subprogram_Task_Protected_Unit --
380 ---------------------------------------
382 function In_Subprogram_Task_Protected_Unit return Boolean is
383 E : Entity_Id;
385 begin
386 -- The following is to verify that a declaration is inside
387 -- subprogram, generic subprogram, task unit, protected unit.
388 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
390 -- Use scope chain to check successively outer scopes
392 E := Current_Scope;
393 loop
394 if Is_Subprogram (E)
395 or else
396 Is_Generic_Subprogram (E)
397 or else
398 Is_Concurrent_Type (E)
399 then
400 return True;
402 elsif E = Standard_Standard then
403 return False;
404 end if;
406 E := Scope (E);
407 end loop;
408 end In_Subprogram_Task_Protected_Unit;
410 -------------------------------
411 -- Is_Non_Remote_Access_Type --
412 -------------------------------
414 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
415 begin
416 return Is_Access_Type (E)
417 and then not Is_Remote_Access_To_Class_Wide_Type (E)
418 and then not Is_Remote_Access_To_Subprogram_Type (E);
419 end Is_Non_Remote_Access_Type;
421 ------------------------------------
422 -- Is_Recursively_Limited_Private --
423 ------------------------------------
425 function Is_Recursively_Limited_Private (E : Entity_Id) return Boolean is
426 P : constant Node_Id := Parent (E);
428 begin
429 if Nkind (P) = N_Private_Type_Declaration
430 and then Is_Limited_Record (E)
431 then
432 return True;
433 elsif Nkind (P) = N_Private_Extension_Declaration then
434 return Is_Recursively_Limited_Private (Etype (E));
435 elsif Nkind (P) = N_Formal_Type_Declaration
436 and then Ekind (E) = E_Record_Type_With_Private
437 and then Is_Generic_Type (E)
438 and then Is_Limited_Record (E)
439 then
440 return True;
441 else
442 return False;
443 end if;
444 end Is_Recursively_Limited_Private;
446 ----------------------------------
447 -- Missing_Read_Write_Attribute --
448 ----------------------------------
450 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
451 Component : Entity_Id;
452 Component_Type : Entity_Id;
454 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
455 -- Return True if entity has Read and Write attributes
457 -------------------------------
458 -- Has_Read_Write_Attributes --
459 -------------------------------
461 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
462 Rep_Item : Node_Id := First_Rep_Item (E);
463 Read_Attribute : Boolean := False;
464 Write_Attribute : Boolean := False;
466 begin
467 -- We start from the declaration node and then loop until the end
468 -- of the list until we find those two attribute definition clauses.
470 while Present (Rep_Item) loop
471 if Chars (Rep_Item) = Name_Read then
472 Read_Attribute := True;
473 elsif Chars (Rep_Item) = Name_Write then
474 Write_Attribute := True;
475 end if;
477 if Read_Attribute and Write_Attribute then
478 return True;
479 end if;
481 Next_Rep_Item (Rep_Item);
482 end loop;
484 return False;
485 end Has_Read_Write_Attributes;
487 -- Start of processing for Missing_Read_Write_Attributes
489 begin
490 if Has_Read_Write_Attributes (E) then
491 return False;
492 elsif Is_Non_Remote_Access_Type (E) then
493 return True;
494 end if;
496 if Is_Record_Type (E) then
497 Component := First_Entity (E);
498 while Present (Component) loop
499 Component_Type := Etype (Component);
501 if (Is_Non_Remote_Access_Type (Component_Type)
502 or else Is_Record_Type (Component_Type))
503 and then Missing_Read_Write_Attributes (Component_Type)
504 then
505 return True;
506 end if;
508 Next_Entity (Component);
509 end loop;
510 end if;
512 return False;
513 end Missing_Read_Write_Attributes;
515 -------------------------------------
516 -- Set_Categorization_From_Pragmas --
517 -------------------------------------
519 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
520 P : constant Node_Id := Parent (N);
521 S : constant Entity_Id := Current_Scope;
523 procedure Set_Parents (Visibility : Boolean);
524 -- If this is a child instance, the parents are not immediately
525 -- visible during analysis. Make them momentarily visible so that
526 -- the argument of the pragma can be resolved properly, and reset
527 -- afterwards.
529 procedure Set_Parents (Visibility : Boolean) is
530 Par : Entity_Id := Scope (S);
532 begin
533 while Present (Par) and then Par /= Standard_Standard loop
534 Set_Is_Immediately_Visible (Par, Visibility);
535 Par := Scope (Par);
536 end loop;
537 end Set_Parents;
539 begin
540 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
541 -- The purpose is to set categorization flags before analyzing the
542 -- unit itself, so as to diagnose violations of categorization as
543 -- we process each declaration, even though the pragma appears after
544 -- the unit.
546 if Nkind (P) /= N_Compilation_Unit then
547 return;
548 end if;
550 declare
551 PN : Node_Id := First (Pragmas_After (Aux_Decls_Node (P)));
553 begin
555 if Is_Child_Unit (S)
556 and then Is_Generic_Instance (S)
557 then
558 Set_Parents (True);
559 end if;
561 while Present (PN) loop
563 -- Skip implicit types that may have been introduced by
564 -- previous analysis.
566 if Nkind (PN) = N_Pragma then
568 case Get_Pragma_Id (Chars (PN)) is
569 when Pragma_All_Calls_Remote |
570 Pragma_Preelaborate |
571 Pragma_Pure |
572 Pragma_Remote_Call_Interface |
573 Pragma_Remote_Types |
574 Pragma_Shared_Passive => Analyze (PN);
575 when others => null;
576 end case;
577 end if;
579 Next (PN);
580 end loop;
581 if Is_Child_Unit (S)
582 and then Is_Generic_Instance (S)
583 then
584 Set_Parents (False);
585 end if;
587 end;
588 end Set_Categorization_From_Pragmas;
590 -----------------------------------
591 -- Set_Categorization_From_Scope --
592 -----------------------------------
594 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
595 Declaration : Node_Id := Empty;
596 Specification : Node_Id := Empty;
598 begin
599 Set_Is_Pure (E,
600 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
602 if not Is_Remote_Call_Interface (E) then
603 if Ekind (E) in Subprogram_Kind then
604 Declaration := Unit_Declaration_Node (E);
606 if False
607 or else Nkind (Declaration) = N_Subprogram_Body
608 or else Nkind (Declaration) = N_Subprogram_Renaming_Declaration
609 then
610 Specification := Corresponding_Spec (Declaration);
611 end if;
612 end if;
614 -- A subprogram body or renaming-as-body is a remote call
615 -- interface if it serves as the completion of a subprogram
616 -- declaration that is a remote call interface.
618 if Nkind (Specification) in N_Entity then
619 Set_Is_Remote_Call_Interface
620 (E, Is_Remote_Call_Interface (Specification));
622 -- A subprogram declaration is a remote call interface when it is
623 -- declared within the visible part of, or declared by, a library
624 -- unit declaration that is a remote call interface.
626 else
627 Set_Is_Remote_Call_Interface
628 (E, Is_Remote_Call_Interface (Scop)
629 and then not (In_Private_Part (Scop)
630 or else In_Package_Body (Scop)));
631 end if;
632 end if;
634 Set_Is_Remote_Types (E, Is_Remote_Types (Scop));
635 end Set_Categorization_From_Scope;
637 ------------------------------
638 -- Static_Discriminant_Expr --
639 ------------------------------
641 -- We need to accomodate a Why_Not_Static call somehow here ???
643 function Static_Discriminant_Expr (L : List_Id) return Boolean is
644 Discriminant_Spec : Node_Id;
646 begin
647 Discriminant_Spec := First (L);
648 while Present (Discriminant_Spec) loop
649 if Present (Expression (Discriminant_Spec))
650 and then not Is_Static_Expression (Expression (Discriminant_Spec))
651 then
652 return False;
653 end if;
655 Next (Discriminant_Spec);
656 end loop;
658 return True;
659 end Static_Discriminant_Expr;
661 --------------------------------------
662 -- Validate_Access_Type_Declaration --
663 --------------------------------------
665 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
666 Def : constant Node_Id := Type_Definition (N);
668 begin
669 case Nkind (Def) is
671 -- Access to subprogram case
673 when N_Access_To_Subprogram_Definition =>
675 -- A pure library_item must not contain the declaration of a
676 -- named access type, except within a subprogram, generic
677 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
679 -- This test is skipped in Ada 2005 (see AI-366)
681 if Ada_Version < Ada_05
682 and then Comes_From_Source (T)
683 and then In_Pure_Unit
684 and then not In_Subprogram_Task_Protected_Unit
685 then
686 Error_Msg_N ("named access type not allowed in pure unit", T);
687 end if;
689 -- Access to object case
691 when N_Access_To_Object_Definition =>
692 if Comes_From_Source (T)
693 and then In_Pure_Unit
694 and then not In_Subprogram_Task_Protected_Unit
695 then
696 -- We can't give the message yet, since the type is not frozen
697 -- and in Ada 2005 mode, access types are allowed in pure units
698 -- if the type has no storage pool (see AI-366). So we set a
699 -- flag which will be checked at freeze time.
701 Set_Is_Pure_Unit_Access_Type (T);
702 end if;
704 -- Check for RCI or RT unit type declaration. It should not
705 -- contain the declaration of an access-to-object type unless it
706 -- is a general access type that designates a class-wide limited
707 -- private type. There are also constraints about the primitive
708 -- subprograms of the class-wide type.
710 Validate_Remote_Access_Object_Type_Declaration (T);
712 -- Check for shared passive unit type declaration. It should
713 -- not contain the declaration of access to class wide type,
714 -- access to task type and access to protected type with entry.
716 Validate_SP_Access_Object_Type_Decl (T);
718 when others =>
719 null;
720 end case;
722 -- Set categorization flag from package on entity as well, to allow
723 -- easy checks later on for required validations of RCI or RT units.
724 -- This is only done for entities that are in the original source.
726 if Comes_From_Source (T)
727 and then not (In_Package_Body (Scope (T))
728 or else In_Private_Part (Scope (T)))
729 then
730 Set_Is_Remote_Call_Interface
731 (T, Is_Remote_Call_Interface (Scope (T)));
732 Set_Is_Remote_Types
733 (T, Is_Remote_Types (Scope (T)));
734 end if;
735 end Validate_Access_Type_Declaration;
737 ----------------------------
738 -- Validate_Ancestor_Part --
739 ----------------------------
741 procedure Validate_Ancestor_Part (N : Node_Id) is
742 A : constant Node_Id := Ancestor_Part (N);
743 T : constant Entity_Id := Entity (A);
745 begin
746 if In_Preelaborated_Unit
747 and then not In_Subprogram_Or_Concurrent_Unit
748 and then (not Inside_A_Generic
749 or else Present (Enclosing_Generic_Body (N)))
750 then
751 -- We relax the restriction of 10.2.1(9) within GNAT
752 -- units to allow packages such as Ada.Strings.Unbounded
753 -- to be implemented (i.p., Null_Unbounded_String).
754 -- (There are ACVC tests that check that the restriction
755 -- is enforced, but note that AI-161, once approved,
756 -- will relax the restriction prohibiting default-
757 -- initialized objects of private and controlled
758 -- types.)
760 if Is_Private_Type (T)
761 and then not Is_Internal_File_Name
762 (Unit_File_Name (Get_Source_Unit (N)))
763 then
764 Error_Msg_N
765 ("private ancestor type not allowed in preelaborated unit", A);
767 elsif Is_Record_Type (T) then
768 if Nkind (Parent (T)) = N_Full_Type_Declaration then
769 Check_Non_Static_Default_Expr
770 (Type_Definition (Parent (T)), A);
771 end if;
772 end if;
773 end if;
774 end Validate_Ancestor_Part;
776 ----------------------------------------
777 -- Validate_Categorization_Dependency --
778 ----------------------------------------
780 procedure Validate_Categorization_Dependency
781 (N : Node_Id;
782 E : Entity_Id)
784 K : constant Node_Kind := Nkind (N);
785 P : Node_Id := Parent (N);
786 U : Entity_Id := E;
787 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
789 begin
790 -- Only validate library units and subunits. For subunits, checks
791 -- concerning withed units apply to the parent compilation unit.
793 if Is_Subunit then
794 P := Parent (P);
795 U := Scope (E);
797 while Present (U)
798 and then not Is_Compilation_Unit (U)
799 and then not Is_Child_Unit (U)
800 loop
801 U := Scope (U);
802 end loop;
804 end if;
806 if Nkind (P) /= N_Compilation_Unit then
807 return;
808 end if;
810 -- Body of RCI unit does not need validation
812 if Is_Remote_Call_Interface (E)
813 and then (Nkind (N) = N_Package_Body
814 or else Nkind (N) = N_Subprogram_Body)
815 then
816 return;
817 end if;
819 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
821 declare
822 Item : Node_Id;
823 Entity_Of_Withed : Entity_Id;
825 begin
826 Item := First (Context_Items (P));
828 while Present (Item) loop
829 if Nkind (Item) = N_With_Clause
830 and then not (Implicit_With (Item)
831 or else Limited_Present (Item))
832 then
833 Entity_Of_Withed := Entity (Name (Item));
834 Check_Categorization_Dependencies
835 (U, Entity_Of_Withed, Item, Is_Subunit);
836 end if;
838 Next (Item);
839 end loop;
840 end;
842 -- Child depends on parent; therefore parent should also be categorized
843 -- and satify the dependency hierarchy.
845 -- Check if N is a child spec
847 if (K in N_Generic_Declaration or else
848 K in N_Generic_Instantiation or else
849 K in N_Generic_Renaming_Declaration or else
850 K = N_Package_Declaration or else
851 K = N_Package_Renaming_Declaration or else
852 K = N_Subprogram_Declaration or else
853 K = N_Subprogram_Renaming_Declaration)
854 and then Present (Parent_Spec (N))
855 then
856 Check_Categorization_Dependencies (E, Scope (E), N, False);
858 -- Verify that public child of an RCI library unit must also be an
859 -- RCI library unit (RM E.2.3(15)).
861 if Is_Remote_Call_Interface (Scope (E))
862 and then not Private_Present (P)
863 and then not Is_Remote_Call_Interface (E)
864 then
865 Error_Msg_N ("public child of rci unit must also be rci unit", N);
866 end if;
867 end if;
868 end Validate_Categorization_Dependency;
870 --------------------------------
871 -- Validate_Controlled_Object --
872 --------------------------------
874 procedure Validate_Controlled_Object (E : Entity_Id) is
875 begin
876 -- For now, never apply this check for internal GNAT units, since we
877 -- have a number of cases in the library where we are stuck with objects
878 -- of this type, and the RM requires Preelaborate.
880 -- For similar reasons, we only do this check for source entities, since
881 -- we generate entities of this type in some situations.
883 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
884 -- We have to enforce them for RM compatibility, but we have no trouble
885 -- accepting these objects and doing the right thing. Note that there is
886 -- no requirement that Preelaborate not actually generate any code!
888 if In_Preelaborated_Unit
889 and then not Debug_Flag_PP
890 and then Comes_From_Source (E)
891 and then not
892 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
893 and then (not Inside_A_Generic
894 or else Present (Enclosing_Generic_Body (E)))
895 and then not Is_Protected_Type (Etype (E))
896 then
897 Error_Msg_N
898 ("library level controlled object not allowed in " &
899 "preelaborated unit", E);
900 end if;
901 end Validate_Controlled_Object;
903 --------------------------------------
904 -- Validate_Null_Statement_Sequence --
905 --------------------------------------
907 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
908 Item : Node_Id;
910 begin
911 if In_Preelaborated_Unit then
912 Item := First (Statements (Handled_Statement_Sequence (N)));
914 while Present (Item) loop
915 if Nkind (Item) /= N_Label
916 and then Nkind (Item) /= N_Null_Statement
917 then
918 -- In GNAT mode, this is a warning, allowing the run-time
919 -- to judiciously bypass this error condition.
921 Error_Msg_Warn := GNAT_Mode;
922 Error_Msg_N
923 ("<statements not allowed in preelaborated unit", Item);
925 exit;
926 end if;
928 Next (Item);
929 end loop;
930 end if;
931 end Validate_Null_Statement_Sequence;
933 ---------------------------------
934 -- Validate_Object_Declaration --
935 ---------------------------------
937 procedure Validate_Object_Declaration (N : Node_Id) is
938 Id : constant Entity_Id := Defining_Identifier (N);
939 E : constant Node_Id := Expression (N);
940 Odf : constant Node_Id := Object_Definition (N);
941 T : constant Entity_Id := Etype (Id);
943 begin
944 -- Verify that any access to subprogram object does not have in its
945 -- subprogram profile access type parameters or limited parameters
946 -- without Read and Write attributes (E.2.3(13)).
948 Validate_RCI_Subprogram_Declaration (N);
950 -- Check that if we are in preelaborated elaboration code, then we
951 -- do not have an instance of a default initialized private, task or
952 -- protected object declaration which would violate (RM 10.2.1(9)).
953 -- Note that constants are never default initialized (and the test
954 -- below also filters out deferred constants). A variable is default
955 -- initialized if it does *not* have an initialization expression.
957 -- Filter out cases that are not declaration of a variable from source
959 if Nkind (N) /= N_Object_Declaration
960 or else Constant_Present (N)
961 or else not Comes_From_Source (Id)
962 then
963 return;
964 end if;
966 -- Exclude generic specs from the checks (this will get rechecked
967 -- on instantiations).
969 if Inside_A_Generic
970 and then not Present (Enclosing_Generic_Body (Id))
971 then
972 return;
973 end if;
975 -- Required checks for declaration that is in a preelaborated
976 -- package and is not within some subprogram.
978 if In_Preelaborated_Unit
979 and then not In_Subprogram_Or_Concurrent_Unit
980 then
981 -- Check for default initialized variable case. Note that in
982 -- accordance with (RM B.1(24)) imported objects are not
983 -- subject to default initialization.
985 if No (E) and then not Is_Imported (Id) then
986 declare
987 Ent : Entity_Id := T;
989 begin
990 -- An array whose component type is a record with nonstatic
991 -- default expressions is a violation, so we get the array's
992 -- component type.
994 if Is_Array_Type (Ent) then
995 declare
996 Comp_Type : Entity_Id := Component_Type (Ent);
998 begin
999 while Is_Array_Type (Comp_Type) loop
1000 Comp_Type := Component_Type (Comp_Type);
1001 end loop;
1003 Ent := Comp_Type;
1004 end;
1005 end if;
1007 -- Object decl. that is of record type and has no default expr.
1008 -- should check if there is any non-static default expression
1009 -- in component decl. of the record type decl.
1011 if Is_Record_Type (Ent) then
1012 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1013 Check_Non_Static_Default_Expr
1014 (Type_Definition (Parent (Ent)), N);
1016 elsif Nkind (Odf) = N_Subtype_Indication
1017 and then not Is_Array_Type (T)
1018 and then not Is_Private_Type (T)
1019 then
1020 Check_Non_Static_Default_Expr (Type_Definition
1021 (Parent (Entity (Subtype_Mark (Odf)))), N);
1022 end if;
1023 end if;
1025 -- We relax the restriction of 10.2.1(9) within GNAT
1026 -- units. (There are ACVC tests that check that the
1027 -- restriction is enforced, but note that AI-161,
1028 -- once approved, will relax the restriction prohibiting
1029 -- default-initialized objects of private types, and
1030 -- will recommend a pragma for marking private types.)
1032 if (Is_Private_Type (Ent)
1033 or else Depends_On_Private (Ent))
1034 and then not Is_Internal_File_Name
1035 (Unit_File_Name (Get_Source_Unit (N)))
1036 then
1037 Error_Msg_N
1038 ("private object not allowed in preelaborated unit", N);
1039 return;
1041 -- Access to Task or Protected type
1043 elsif Is_Entity_Name (Odf)
1044 and then Present (Etype (Odf))
1045 and then Is_Access_Type (Etype (Odf))
1046 then
1047 Ent := Designated_Type (Etype (Odf));
1049 elsif Is_Entity_Name (Odf) then
1050 Ent := Entity (Odf);
1052 elsif Nkind (Odf) = N_Subtype_Indication then
1053 Ent := Etype (Subtype_Mark (Odf));
1055 elsif
1056 Nkind (Odf) = N_Constrained_Array_Definition
1057 then
1058 Ent := Component_Type (T);
1060 -- else
1061 -- return;
1062 end if;
1064 if Is_Task_Type (Ent)
1065 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1066 then
1067 Error_Msg_N
1068 ("concurrent object not allowed in preelaborated unit",
1070 return;
1071 end if;
1072 end;
1073 end if;
1075 -- Non-static discriminant not allowed in preelaborayted unit
1077 if Is_Record_Type (Etype (Id)) then
1078 declare
1079 ET : constant Entity_Id := Etype (Id);
1080 EE : constant Entity_Id := Etype (Etype (Id));
1081 PEE : Node_Id;
1083 begin
1084 if Has_Discriminants (ET)
1085 and then Present (EE)
1086 then
1087 PEE := Parent (EE);
1089 if Nkind (PEE) = N_Full_Type_Declaration
1090 and then not Static_Discriminant_Expr
1091 (Discriminant_Specifications (PEE))
1092 then
1093 Error_Msg_N
1094 ("non-static discriminant in preelaborated unit",
1095 PEE);
1096 end if;
1097 end if;
1098 end;
1099 end if;
1100 end if;
1102 -- A pure library_item must not contain the declaration of any
1103 -- variable except within a subprogram, generic subprogram, task
1104 -- unit or protected unit (RM 10.2.1(16)).
1106 if In_Pure_Unit
1107 and then not In_Subprogram_Task_Protected_Unit
1108 then
1109 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1111 -- The visible part of an RCI library unit must not contain the
1112 -- declaration of a variable (RM E.1.3(9))
1114 elsif In_RCI_Declaration (N) then
1115 Error_Msg_N ("declaration of variable not allowed in rci unit", N);
1117 -- The visible part of a Shared Passive library unit must not contain
1118 -- the declaration of a variable (RM E.2.2(7))
1120 elsif In_RT_Declaration then
1121 Error_Msg_N
1122 ("variable declaration not allowed in remote types unit", N);
1123 end if;
1125 end Validate_Object_Declaration;
1127 -------------------------------
1128 -- Validate_RCI_Declarations --
1129 -------------------------------
1131 procedure Validate_RCI_Declarations (P : Entity_Id) is
1132 E : Entity_Id;
1134 begin
1135 E := First_Entity (P);
1136 while Present (E) loop
1137 if Comes_From_Source (E) then
1138 if Is_Limited_Type (E) then
1139 Error_Msg_N
1140 ("Limited type not allowed in rci unit", Parent (E));
1141 Explain_Limited_Type (E, Parent (E));
1143 elsif Ekind (E) = E_Generic_Function
1144 or else Ekind (E) = E_Generic_Package
1145 or else Ekind (E) = E_Generic_Procedure
1146 then
1147 Error_Msg_N ("generic declaration not allowed in rci unit",
1148 Parent (E));
1150 elsif (Ekind (E) = E_Function
1151 or else Ekind (E) = E_Procedure)
1152 and then Has_Pragma_Inline (E)
1153 then
1154 Error_Msg_N
1155 ("inlined subprogram not allowed in rci unit", Parent (E));
1157 -- Inner packages that are renamings need not be checked.
1158 -- Generic RCI packages are subject to the checks, but
1159 -- entities that come from formal packages are not part of the
1160 -- visible declarations of the package and are not checked.
1162 elsif Ekind (E) = E_Package then
1163 if Present (Renamed_Entity (E)) then
1164 null;
1166 elsif Ekind (P) /= E_Generic_Package
1167 or else List_Containing (Unit_Declaration_Node (E)) /=
1168 Generic_Formal_Declarations
1169 (Unit_Declaration_Node (P))
1170 then
1171 Validate_RCI_Declarations (E);
1172 end if;
1173 end if;
1174 end if;
1176 Next_Entity (E);
1177 end loop;
1178 end Validate_RCI_Declarations;
1180 -----------------------------------------
1181 -- Validate_RCI_Subprogram_Declaration --
1182 -----------------------------------------
1184 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1185 K : constant Node_Kind := Nkind (N);
1186 Profile : List_Id;
1187 Id : Node_Id;
1188 Param_Spec : Node_Id;
1189 Param_Type : Entity_Id;
1190 Base_Param_Type : Entity_Id;
1191 Type_Decl : Node_Id;
1192 Error_Node : Node_Id := N;
1194 begin
1195 -- There are two possible cases in which this procedure is called:
1197 -- 1. called from Analyze_Subprogram_Declaration.
1198 -- 2. called from Validate_Object_Declaration (access to subprogram).
1200 if not In_RCI_Declaration (N) then
1201 return;
1202 end if;
1204 if K = N_Subprogram_Declaration then
1205 Profile := Parameter_Specifications (Specification (N));
1207 else pragma Assert (K = N_Object_Declaration);
1208 Id := Defining_Identifier (N);
1210 if Nkind (Id) = N_Defining_Identifier
1211 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1212 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1213 then
1214 Profile :=
1215 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1216 else
1217 return;
1218 end if;
1219 end if;
1221 -- Iterate through the parameter specification list, checking that
1222 -- no access parameter and no limited type parameter in the list.
1223 -- RM E.2.3 (14)
1225 if Present (Profile) then
1226 Param_Spec := First (Profile);
1228 while Present (Param_Spec) loop
1229 Param_Type := Etype (Defining_Identifier (Param_Spec));
1230 Type_Decl := Parent (Param_Type);
1232 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1234 if K = N_Subprogram_Declaration then
1235 Error_Node := Param_Spec;
1236 end if;
1238 -- Report error only if declaration is in source program
1240 if Comes_From_Source
1241 (Defining_Entity (Specification (N)))
1242 then
1243 Error_Msg_N
1244 ("subprogram in rci unit cannot have access parameter",
1245 Error_Node);
1246 end if;
1248 -- For limited private type parameter, we check only the
1249 -- private declaration and ignore full type declaration,
1250 -- unless this is the only declaration for the type, eg.
1251 -- as a limited record.
1253 elsif Is_Limited_Type (Param_Type)
1254 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1255 or else
1256 (Nkind (Type_Decl) = N_Full_Type_Declaration
1257 and then not (Has_Private_Declaration (Param_Type))
1258 and then Comes_From_Source (N)))
1259 then
1260 -- A limited parameter is legal only if user-specified
1261 -- Read and Write attributes exist for it.
1262 -- second part of RM E.2.3 (14)
1264 if No (Full_View (Param_Type))
1265 and then Ekind (Param_Type) /= E_Record_Type
1266 then
1267 -- Type does not have completion yet, so if declared in
1268 -- in the current RCI scope it is illegal, and will be
1269 -- flagged subsequently.
1270 return;
1271 end if;
1273 Base_Param_Type := Base_Type (Underlying_Type (Param_Type));
1275 if No (TSS (Base_Param_Type, TSS_Stream_Read))
1276 or else
1277 No (TSS (Base_Param_Type, TSS_Stream_Write))
1278 then
1279 if K = N_Subprogram_Declaration then
1280 Error_Node := Param_Spec;
1281 end if;
1283 Error_Msg_N
1284 ("limited parameter in rci unit "
1285 & "must have read/write attributes ", Error_Node);
1286 Explain_Limited_Type (Param_Type, Error_Node);
1287 end if;
1288 end if;
1290 Next (Param_Spec);
1291 end loop;
1292 end if;
1293 end Validate_RCI_Subprogram_Declaration;
1295 ----------------------------------------------------
1296 -- Validate_Remote_Access_Object_Type_Declaration --
1297 ----------------------------------------------------
1299 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1300 Direct_Designated_Type : Entity_Id;
1301 Desig_Type : Entity_Id;
1302 Primitive_Subprograms : Elist_Id;
1303 Subprogram : Elmt_Id;
1304 Subprogram_Node : Node_Id;
1305 Profile : List_Id;
1306 Param_Spec : Node_Id;
1307 Param_Type : Entity_Id;
1309 begin
1310 -- We are called from Analyze_Type_Declaration, and the Nkind
1311 -- of the given node is N_Access_To_Object_Definition.
1313 if not Comes_From_Source (T)
1314 or else (not In_RCI_Declaration (Parent (T))
1315 and then not In_RT_Declaration)
1316 then
1317 return;
1318 end if;
1320 -- An access definition in the private part of a Remote Types package
1321 -- may be legal if it has user-defined Read and Write attributes. This
1322 -- will be checked at the end of the package spec processing.
1324 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1325 return;
1326 end if;
1328 -- Check RCI or RT unit type declaration. It may not contain
1329 -- the declaration of an access-to-object type unless it is a
1330 -- general access type that designates a class-wide limited
1331 -- private type. There are also constraints about the primitive
1332 -- subprograms of the class-wide type (RM E.2.3(14)).
1334 if Ekind (T) /= E_General_Access_Type
1335 or else Ekind (Designated_Type (T)) /= E_Class_Wide_Type
1336 then
1337 if In_RCI_Declaration (Parent (T)) then
1338 Error_Msg_N
1339 ("access type in Remote_Call_Interface unit must be " &
1340 "general access", T);
1341 else
1342 Error_Msg_N ("access type in Remote_Types unit must be " &
1343 "general access", T);
1344 end if;
1345 Error_Msg_N ("\to class-wide type", T);
1346 return;
1347 end if;
1349 Direct_Designated_Type := Designated_Type (T);
1350 Desig_Type := Etype (Direct_Designated_Type);
1352 if not Is_Recursively_Limited_Private (Desig_Type) then
1353 Error_Msg_N
1354 ("error in designated type of remote access to class-wide type", T);
1355 Error_Msg_N
1356 ("\must be tagged limited private or private extension of type", T);
1357 return;
1358 end if;
1360 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1361 Subprogram := First_Elmt (Primitive_Subprograms);
1363 while Subprogram /= No_Elmt loop
1364 Subprogram_Node := Node (Subprogram);
1366 if not Comes_From_Source (Subprogram_Node) then
1367 goto Next_Subprogram;
1368 end if;
1370 Profile := Parameter_Specifications (Parent (Subprogram_Node));
1372 -- Profile must exist, otherwise not primitive operation
1374 Param_Spec := First (Profile);
1375 while Present (Param_Spec) loop
1377 -- Now find out if this parameter is a controlling parameter
1379 Param_Type := Parameter_Type (Param_Spec);
1381 if (Nkind (Param_Type) = N_Access_Definition
1382 and then Etype (Subtype_Mark (Param_Type)) = Desig_Type)
1383 or else (Nkind (Param_Type) /= N_Access_Definition
1384 and then Etype (Param_Type) = Desig_Type)
1385 then
1386 -- It is a controlling parameter, so specific checks below
1387 -- do not apply.
1389 null;
1391 elsif
1392 Nkind (Param_Type) = N_Access_Definition
1393 then
1394 -- From RM E.2.2(14), no access parameter other than
1395 -- controlling ones may be used.
1397 Error_Msg_N
1398 ("non-controlling access parameter", Param_Spec);
1400 elsif
1401 Is_Limited_Type (Etype (Defining_Identifier (Param_Spec)))
1402 then
1403 -- Not a controlling parameter, so type must have Read
1404 -- and Write attributes.
1406 if Nkind (Param_Type) in N_Has_Etype
1407 and then Nkind (Parent (Etype (Param_Type))) =
1408 N_Private_Type_Declaration
1409 then
1410 Param_Type := Etype (Param_Type);
1412 if No (TSS (Param_Type, TSS_Stream_Read))
1413 or else
1414 No (TSS (Param_Type, TSS_Stream_Write))
1415 then
1416 Error_Msg_N
1417 ("limited formal must have Read and Write attributes",
1418 Param_Spec);
1419 Explain_Limited_Type
1420 (Etype (Defining_Identifier (Param_Spec)), Param_Spec);
1421 end if;
1422 end if;
1423 end if;
1425 -- Check next parameter in this subprogram
1427 Next (Param_Spec);
1428 end loop;
1430 <<Next_Subprogram>>
1431 Next_Elmt (Subprogram);
1432 end loop;
1434 -- Now this is an RCI unit access-to-class-wide-limited-private type
1435 -- declaration. Set the type entity to be Is_Remote_Call_Interface to
1436 -- optimize later checks by avoiding tree traversal to find out if this
1437 -- entity is inside an RCI unit.
1439 Set_Is_Remote_Call_Interface (T);
1440 end Validate_Remote_Access_Object_Type_Declaration;
1442 -----------------------------------------------
1443 -- Validate_Remote_Access_To_Class_Wide_Type --
1444 -----------------------------------------------
1446 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1447 K : constant Node_Kind := Nkind (N);
1448 PK : constant Node_Kind := Nkind (Parent (N));
1449 E : Entity_Id;
1451 begin
1452 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1453 -- of class-wide limited private types.
1455 -- Storage_Pool and Storage_Size are not defined for such types
1457 -- The expected type of allocator must not not be such a type.
1459 -- The actual parameter of generic instantiation must not be such a
1460 -- type if the formal parameter is of an access type.
1462 -- On entry, there are five cases
1464 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1465 -- either Storage_Pool or Storage_Size.
1467 -- 2. called from exp_ch4 Expand_N_Allocator
1469 -- 3. called from sem_ch12 Analyze_Associations
1471 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1473 -- 5. called from sem_res Resolve_Actuals
1475 if K = N_Attribute_Reference then
1476 E := Etype (Prefix (N));
1478 if Is_Remote_Access_To_Class_Wide_Type (E) then
1479 Error_Msg_N ("incorrect attribute of remote operand", N);
1480 return;
1481 end if;
1483 elsif K = N_Allocator then
1484 E := Etype (N);
1486 if Is_Remote_Access_To_Class_Wide_Type (E) then
1487 Error_Msg_N ("incorrect expected remote type of allocator", N);
1488 return;
1489 end if;
1491 elsif K in N_Has_Entity then
1492 E := Entity (N);
1494 if Is_Remote_Access_To_Class_Wide_Type (E) then
1495 Error_Msg_N ("incorrect remote type generic actual", N);
1496 return;
1497 end if;
1499 -- This subprogram also enforces the checks in E.2.2(13). A value of
1500 -- such type must not be dereferenced unless as controlling operand of a
1501 -- dispatching call.
1503 elsif K = N_Explicit_Dereference
1504 and then (Comes_From_Source (N)
1505 or else (Nkind (Original_Node (N)) = N_Selected_Component
1506 and then Comes_From_Source (Original_Node (N))))
1507 then
1508 E := Etype (Prefix (N));
1510 -- If the class-wide type is not a remote one, the restrictions
1511 -- do not apply.
1513 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1514 return;
1515 end if;
1517 -- If we have a true dereference that comes from source and that
1518 -- is a controlling argument for a dispatching call, accept it.
1520 if K = N_Explicit_Dereference
1521 and then Is_Actual_Parameter (N)
1522 and then Is_Controlling_Actual (N)
1523 then
1524 return;
1525 end if;
1527 -- If we are just within a procedure or function call and the
1528 -- dereference has not been analyzed, return because this procedure
1529 -- will be called again from sem_res Resolve_Actuals.
1531 if Is_Actual_Parameter (N)
1532 and then not Analyzed (N)
1533 then
1534 return;
1535 end if;
1537 -- The following is to let the compiler generated tags check pass
1538 -- through without error message. This is a bit kludgy isn't there
1539 -- some better way of making this exclusion ???
1541 if (PK = N_Selected_Component
1542 and then Present (Parent (Parent (N)))
1543 and then Nkind (Parent (Parent (N))) = N_Op_Ne)
1544 or else (PK = N_Unchecked_Type_Conversion
1545 and then Present (Parent (Parent (N)))
1546 and then
1547 Nkind (Parent (Parent (N))) = N_Selected_Component)
1548 then
1549 return;
1550 end if;
1552 -- The following code is needed for expansion of RACW Write
1553 -- attribute, since such expressions can appear in the expanded
1554 -- code.
1556 if not Comes_From_Source (N)
1557 and then
1558 (PK = N_In
1559 or else PK = N_Attribute_Reference
1560 or else
1561 (PK = N_Type_Conversion
1562 and then Present (Parent (N))
1563 and then Present (Parent (Parent (N)))
1564 and then
1565 Nkind (Parent (Parent (N))) = N_Selected_Component))
1566 then
1567 return;
1568 end if;
1570 Error_Msg_N ("incorrect remote type dereference", N);
1571 end if;
1572 end Validate_Remote_Access_To_Class_Wide_Type;
1574 ------------------------------------------
1575 -- Validate_Remote_Type_Type_Conversion --
1576 ------------------------------------------
1578 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1579 S : constant Entity_Id := Etype (N);
1580 E : constant Entity_Id := Etype (Expression (N));
1582 begin
1583 -- This test is required in the case where a conversion appears inside a
1584 -- normal package, it does not necessarily have to be inside an RCI,
1585 -- Remote_Types unit (RM E.2.2(9,12)).
1587 if Is_Remote_Access_To_Subprogram_Type (E)
1588 and then not Is_Remote_Access_To_Subprogram_Type (S)
1589 then
1590 Error_Msg_N
1591 ("incorrect conversion of remote operand to local type", N);
1592 return;
1594 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1595 and then Is_Remote_Access_To_Subprogram_Type (S)
1596 then
1597 Error_Msg_N
1598 ("incorrect conversion of local operand to remote type", N);
1599 return;
1601 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1602 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1603 then
1604 Error_Msg_N
1605 ("incorrect conversion of remote operand to local type", N);
1606 return;
1607 end if;
1609 -- If a local access type is converted into a RACW type, then the
1610 -- current unit has a pointer that may now be exported to another
1611 -- partition.
1613 if Is_Remote_Access_To_Class_Wide_Type (S)
1614 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1615 then
1616 Set_Has_RACW (Current_Sem_Unit);
1617 end if;
1618 end Validate_Remote_Type_Type_Conversion;
1620 -------------------------------
1621 -- Validate_RT_RAT_Component --
1622 -------------------------------
1624 procedure Validate_RT_RAT_Component (N : Node_Id) is
1625 Spec : constant Node_Id := Specification (N);
1626 Name_U : constant Entity_Id := Defining_Entity (Spec);
1627 Typ : Entity_Id;
1628 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1629 In_Visible_Part : Boolean := True;
1631 begin
1632 if not Is_Remote_Types (Name_U) then
1633 return;
1634 end if;
1636 Typ := First_Entity (Name_U);
1637 while Present (Typ) loop
1638 if In_Visible_Part and then Typ = First_Priv_Ent then
1639 In_Visible_Part := False;
1640 end if;
1642 if Comes_From_Source (Typ)
1643 and then Is_Type (Typ)
1644 and then (In_Visible_Part or else Has_Private_Declaration (Typ))
1645 then
1646 if Missing_Read_Write_Attributes (Typ) then
1647 if Is_Non_Remote_Access_Type (Typ) then
1648 Error_Msg_N
1649 ("non-remote access type without user-defined Read " &
1650 "and Write attributes", Typ);
1651 else
1652 Error_Msg_N
1653 ("record type containing a component of a " &
1654 "non-remote access", Typ);
1655 Error_Msg_N
1656 ("\type without Read and Write attributes " &
1657 "('R'M E.2.2(8))", Typ);
1658 end if;
1659 end if;
1660 end if;
1662 Next_Entity (Typ);
1663 end loop;
1664 end Validate_RT_RAT_Component;
1666 -----------------------------------------
1667 -- Validate_SP_Access_Object_Type_Decl --
1668 -----------------------------------------
1670 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
1671 Direct_Designated_Type : Entity_Id;
1673 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
1674 -- Return true if the protected type designated by T has
1675 -- entry declarations.
1677 ----------------------------
1678 -- Has_Entry_Declarations --
1679 ----------------------------
1681 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
1682 Ety : Entity_Id;
1684 begin
1685 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
1686 Ety := First_Entity (E);
1687 while Present (Ety) loop
1688 if Ekind (Ety) = E_Entry then
1689 return True;
1690 end if;
1692 Next_Entity (Ety);
1693 end loop;
1694 end if;
1696 return False;
1697 end Has_Entry_Declarations;
1699 -- Start of processing for Validate_SP_Access_Object_Type_Decl
1701 begin
1702 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
1703 -- Nkind of the given entity is N_Access_To_Object_Definition.
1705 if not Comes_From_Source (T)
1706 or else not In_Shared_Passive_Unit
1707 or else In_Subprogram_Task_Protected_Unit
1708 then
1709 return;
1710 end if;
1712 -- Check Shared Passive unit. It should not contain the declaration
1713 -- of an access-to-object type whose designated type is a class-wide
1714 -- type, task type or protected type with entry (RM E.2.1(7)).
1716 Direct_Designated_Type := Designated_Type (T);
1718 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
1719 Error_Msg_N
1720 ("invalid access-to-class-wide type in shared passive unit", T);
1721 return;
1723 elsif Ekind (Direct_Designated_Type) in Task_Kind then
1724 Error_Msg_N
1725 ("invalid access-to-task type in shared passive unit", T);
1726 return;
1728 elsif Ekind (Direct_Designated_Type) in Protected_Kind
1729 and then Has_Entry_Declarations (Direct_Designated_Type)
1730 then
1731 Error_Msg_N
1732 ("invalid access-to-protected type in shared passive unit", T);
1733 return;
1734 end if;
1735 end Validate_SP_Access_Object_Type_Decl;
1737 ---------------------------------
1738 -- Validate_Static_Object_Name --
1739 ---------------------------------
1741 procedure Validate_Static_Object_Name (N : Node_Id) is
1742 E : Entity_Id;
1744 function Is_Primary (N : Node_Id) return Boolean;
1745 -- Determine whether node is syntactically a primary in an expression
1747 ----------------
1748 -- Is_Primary --
1749 ----------------
1751 function Is_Primary (N : Node_Id) return Boolean is
1752 K : constant Node_Kind := Nkind (Parent (N));
1754 begin
1755 case K is
1756 when N_Op | N_In | N_Not_In =>
1757 return True;
1759 when N_Aggregate
1760 | N_Component_Association
1761 | N_Index_Or_Discriminant_Constraint =>
1762 return True;
1764 when N_Attribute_Reference =>
1765 return Attribute_Name (Parent (N)) /= Name_Address
1766 and then Attribute_Name (Parent (N)) /= Name_Access
1767 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
1768 and then
1769 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
1771 when N_Indexed_Component =>
1772 return (N /= Prefix (Parent (N))
1773 or else Is_Primary (Parent (N)));
1775 when N_Qualified_Expression | N_Type_Conversion =>
1776 return Is_Primary (Parent (N));
1778 when N_Assignment_Statement | N_Object_Declaration =>
1779 return (N = Expression (Parent (N)));
1781 when N_Selected_Component =>
1782 return Is_Primary (Parent (N));
1784 when others =>
1785 return False;
1786 end case;
1787 end Is_Primary;
1789 -- Start of processing for Validate_Static_Object_Name
1791 begin
1792 if not In_Preelaborated_Unit
1793 or else not Comes_From_Source (N)
1794 or else In_Subprogram_Or_Concurrent_Unit
1795 or else Ekind (Current_Scope) = E_Block
1796 then
1797 return;
1799 -- Filter out cases where primary is default in a component declaration,
1800 -- discriminant specification, or actual in a record type initialization
1801 -- call.
1803 -- Initialization call of internal types
1805 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
1807 if Present (Parent (Parent (N)))
1808 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
1809 then
1810 return;
1811 end if;
1813 if Nkind (Name (Parent (N))) = N_Identifier
1814 and then not Comes_From_Source (Entity (Name (Parent (N))))
1815 then
1816 return;
1817 end if;
1818 end if;
1820 -- Error if the name is a primary in an expression. The parent must not
1821 -- be an operator, or a selected component or an indexed component that
1822 -- is itself a primary. Entities that are actuals do not need to be
1823 -- checked, because the call itself will be diagnosed.
1825 if Is_Primary (N)
1826 and then (not Inside_A_Generic
1827 or else Present (Enclosing_Generic_Body (N)))
1828 then
1829 if Ekind (Entity (N)) = E_Variable then
1830 Flag_Non_Static_Expr
1831 ("non-static object name in preelaborated unit", N);
1833 -- We take the view that a constant defined in another preelaborated
1834 -- unit is preelaborable, even though it may have a private type and
1835 -- thus appear non-static in a client. This must be the intent of
1836 -- the language, but currently is an RM gap ???
1838 elsif Ekind (Entity (N)) = E_Constant
1839 and then not Is_Static_Expression (N)
1840 then
1841 E := Entity (N);
1843 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
1844 and then
1845 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
1846 and then (Is_Preelaborated (Scope (E))
1847 or else Is_Pure (Scope (E))
1848 or else (Present (Renamed_Object (E))
1849 and then
1850 Is_Entity_Name (Renamed_Object (E))
1851 and then
1852 (Is_Preelaborated
1853 (Scope (Renamed_Object (E)))
1854 or else
1855 Is_Pure (Scope
1856 (Renamed_Object (E))))))
1857 then
1858 null;
1860 -- This is the error case
1862 else
1863 -- In GNAT mode, this is just a warning, to allow it to be
1864 -- judiciously turned off. Otherwise it is a real error.
1866 if GNAT_Mode then
1867 Error_Msg_N
1868 ("?non-static constant in preelaborated unit", N);
1869 else
1870 Flag_Non_Static_Expr
1871 ("non-static constant in preelaborated unit", N);
1872 end if;
1874 end if;
1875 end if;
1876 end if;
1877 end Validate_Static_Object_Name;
1879 end Sem_Cat;