Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / sem_cat.adb
blob1f4ed1069f62aa749026f48af5fbecf5c8440eb2
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-2010, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Disp; use Exp_Disp;
32 with Fname; use Fname;
33 with Lib; use Lib;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
36 with Opt; use Opt;
37 with Sem; use Sem;
38 with Sem_Aux; use Sem_Aux;
39 with Sem_Eval; use Sem_Eval;
40 with Sem_Util; use Sem_Util;
41 with Sinfo; use Sinfo;
42 with Snames; use Snames;
43 with Stand; use Stand;
45 package body Sem_Cat is
47 -----------------------
48 -- Local Subprograms --
49 -----------------------
51 procedure Check_Categorization_Dependencies
52 (Unit_Entity : Entity_Id;
53 Depended_Entity : Entity_Id;
54 Info_Node : Node_Id;
55 Is_Subunit : Boolean);
56 -- This procedure checks that the categorization of a lib unit and that
57 -- of the depended unit satisfy dependency restrictions.
58 -- The depended_entity can be the entity in a with_clause item, in which
59 -- case Info_Node denotes that item. The depended_entity can also be the
60 -- parent unit of a child unit, in which case Info_Node is the declaration
61 -- of the child unit. The error message is posted on Info_Node, and is
62 -- specialized if Is_Subunit is true.
64 procedure Check_Non_Static_Default_Expr
65 (Type_Def : Node_Id;
66 Obj_Decl : Node_Id);
67 -- Iterate through the component list of a record definition, check
68 -- that no component is declared with a nonstatic default value.
69 -- If a nonstatic default exists, report an error on Obj_Decl.
71 -- Iterate through the component list of a record definition, check
72 -- that no component is declared with a non-static default value.
74 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean;
75 -- Return True if the entity or one of its subcomponents is of an access
76 -- type that does not have user-defined Read and Write attributes visible
77 -- at any place.
79 function In_RCI_Declaration (N : Node_Id) return Boolean;
80 -- Determines if a declaration is within the visible part of a Remote
81 -- Call Interface compilation unit, for semantic checking purposes only
82 -- (returns false within an instance and within the package body).
84 function In_RT_Declaration return Boolean;
85 -- Determines if current scope is within the declaration of a Remote Types
86 -- unit, for semantic checking purposes.
88 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
89 -- Returns true if the entity is a type whose full view is a non-remote
90 -- access type, for the purpose of enforcing E.2.2(8) rules.
92 function In_Shared_Passive_Unit return Boolean;
93 -- Determines if current scope is within a Shared Passive compilation unit
95 function Static_Discriminant_Expr (L : List_Id) return Boolean;
96 -- Iterate through the list of discriminants to check if any of them
97 -- contains non-static default expression, which is a violation in
98 -- a preelaborated library unit.
100 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
101 -- Check validity of declaration if RCI or RT unit. It should not contain
102 -- the declaration of an access-to-object type unless it is a general
103 -- access type that designates a class-wide limited private type. There are
104 -- also constraints about the primitive subprograms of the class-wide type.
105 -- RM E.2 (9, 13, 14)
107 ---------------------------------------
108 -- Check_Categorization_Dependencies --
109 ---------------------------------------
111 procedure Check_Categorization_Dependencies
112 (Unit_Entity : Entity_Id;
113 Depended_Entity : Entity_Id;
114 Info_Node : Node_Id;
115 Is_Subunit : Boolean)
117 N : constant Node_Id := Info_Node;
118 Err : Boolean;
120 -- Here we define an enumeration type to represent categorization types,
121 -- ordered so that a unit with a given categorization can only WITH
122 -- units with lower or equal categorization type.
124 type Categorization is
125 (Pure,
126 Shared_Passive,
127 Remote_Types,
128 Remote_Call_Interface,
129 Normal);
131 function Get_Categorization (E : Entity_Id) return Categorization;
132 -- Check categorization flags from entity, and return in the form
133 -- of the lowest value of the Categorization type that applies to E.
135 ------------------------
136 -- Get_Categorization --
137 ------------------------
139 function Get_Categorization (E : Entity_Id) return Categorization is
140 begin
141 -- Get the lowest categorization that corresponds to E. Note that
142 -- nothing prevents several (different) categorization pragmas
143 -- to apply to the same library unit, in which case the unit has
144 -- all associated categories, so we need to be careful here to
145 -- check pragmas in proper Categorization order in order to
146 -- return the lowest applicable value.
148 -- Ignore Pure specification if set by pragma Pure_Function
150 if Is_Pure (E)
151 and then not
152 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
153 then
154 return Pure;
156 elsif Is_Shared_Passive (E) then
157 return Shared_Passive;
159 elsif Is_Remote_Types (E) then
160 return Remote_Types;
162 elsif Is_Remote_Call_Interface (E) then
163 return Remote_Call_Interface;
165 else
166 return Normal;
167 end if;
168 end Get_Categorization;
170 Unit_Category : Categorization;
171 With_Category : Categorization;
173 -- Start of processing for Check_Categorization_Dependencies
175 begin
176 -- Intrinsic subprograms are preelaborated, so do not impose any
177 -- categorization dependencies.
179 if Is_Intrinsic_Subprogram (Depended_Entity) then
180 return;
181 end if;
183 -- First check 10.2.1 (11/1) rules on preelaborate packages
185 if Is_Preelaborated (Unit_Entity)
186 and then not Is_Preelaborated (Depended_Entity)
187 and then not Is_Pure (Depended_Entity)
188 then
189 Err := True;
190 else
191 Err := False;
192 end if;
194 -- Check categorization rules of RM E.2(5)
196 Unit_Category := Get_Categorization (Unit_Entity);
197 With_Category := Get_Categorization (Depended_Entity);
199 if With_Category > Unit_Category then
201 -- Special case: Remote_Types and Remote_Call_Interface are allowed
202 -- to WITH anything in the package body, per (RM E.2(5)).
204 if (Unit_Category = Remote_Types
205 or else Unit_Category = Remote_Call_Interface)
206 and then In_Package_Body (Unit_Entity)
207 then
208 null;
209 else
210 Err := True;
211 end if;
212 end if;
214 -- Here if we have an error
216 if Err then
218 -- These messages are warnings in GNAT mode, to allow it to be
219 -- judiciously turned off. Otherwise it is a real error.
221 Error_Msg_Warn := GNAT_Mode;
223 -- Don't give error if main unit is not an internal unit, and the
224 -- unit generating the message is an internal unit. This is the
225 -- situation in which such messages would be ignored in any case,
226 -- so it is convenient not to generate them (since it causes
227 -- annoying interference with debugging).
229 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
230 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
231 then
232 return;
234 -- Subunit case
236 elsif Is_Subunit then
237 Error_Msg_NE
238 ("<subunit cannot depend on& " &
239 "(parent has wrong categorization)", N, Depended_Entity);
241 -- Normal unit, not subunit
243 else
244 Error_Msg_NE
245 ("<cannot depend on& " &
246 "(wrong categorization)", N, Depended_Entity);
247 end if;
249 -- Add further explanation for Pure/Preelaborate common cases
251 if Unit_Category = Pure then
252 Error_Msg_NE
253 ("\<pure unit cannot depend on non-pure unit",
254 N, Depended_Entity);
256 elsif Is_Preelaborated (Unit_Entity)
257 and then not Is_Preelaborated (Depended_Entity)
258 and then not Is_Pure (Depended_Entity)
259 then
260 Error_Msg_NE
261 ("\<preelaborated unit cannot depend on "
262 & "non-preelaborated unit",
263 N, Depended_Entity);
264 end if;
265 end if;
266 end Check_Categorization_Dependencies;
268 -----------------------------------
269 -- Check_Non_Static_Default_Expr --
270 -----------------------------------
272 procedure Check_Non_Static_Default_Expr
273 (Type_Def : Node_Id;
274 Obj_Decl : Node_Id)
276 Recdef : Node_Id;
277 Component_Decl : Node_Id;
279 begin
280 if Nkind (Type_Def) = N_Derived_Type_Definition then
281 Recdef := Record_Extension_Part (Type_Def);
283 if No (Recdef) then
284 return;
285 end if;
287 else
288 Recdef := Type_Def;
289 end if;
291 -- Check that component declarations do not involve:
293 -- a. a non-static default expression, where the object is
294 -- declared to be default initialized.
296 -- b. a dynamic Itype (discriminants and constraints)
298 if Null_Present (Recdef) then
299 return;
300 else
301 Component_Decl := First (Component_Items (Component_List (Recdef)));
302 end if;
304 while Present (Component_Decl)
305 and then Nkind (Component_Decl) = N_Component_Declaration
306 loop
307 if Present (Expression (Component_Decl))
308 and then Nkind (Expression (Component_Decl)) /= N_Null
309 and then not Is_Static_Expression (Expression (Component_Decl))
310 then
311 Error_Msg_Sloc := Sloc (Component_Decl);
312 Error_Msg_F
313 ("object in preelaborated unit has non-static default#",
314 Obj_Decl);
316 -- Fix this later ???
318 -- elsif Has_Dynamic_Itype (Component_Decl) then
319 -- Error_Msg_N
320 -- ("dynamic type discriminant," &
321 -- " constraint in preelaborated unit",
322 -- Component_Decl);
323 end if;
325 Next (Component_Decl);
326 end loop;
327 end Check_Non_Static_Default_Expr;
329 -------------------------------------
330 -- Has_Stream_Attribute_Definition --
331 -------------------------------------
333 function Has_Stream_Attribute_Definition
334 (Typ : Entity_Id;
335 Nam : TSS_Name_Type;
336 At_Any_Place : Boolean := False) return Boolean
338 Rep_Item : Node_Id;
339 Full_Type : Entity_Id := Typ;
341 begin
342 -- In the case of a type derived from a private view, any specified
343 -- stream attributes will be attached to the derived type's underlying
344 -- type rather the derived type entity itself (which is itself private).
346 if Is_Private_Type (Typ)
347 and then Is_Derived_Type (Typ)
348 and then Present (Full_View (Typ))
349 then
350 Full_Type := Underlying_Type (Typ);
351 end if;
353 -- We start from the declaration node and then loop until the end of
354 -- the list until we find the requested attribute definition clause.
355 -- In Ada 2005 mode, clauses are ignored if they are not currently
356 -- visible (this is tested using the corresponding Entity, which is
357 -- inserted by the expander at the point where the clause occurs),
358 -- unless At_Any_Place is true.
360 Rep_Item := First_Rep_Item (Full_Type);
361 while Present (Rep_Item) loop
362 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
363 case Chars (Rep_Item) is
364 when Name_Read =>
365 exit when Nam = TSS_Stream_Read;
367 when Name_Write =>
368 exit when Nam = TSS_Stream_Write;
370 when Name_Input =>
371 exit when Nam = TSS_Stream_Input;
373 when Name_Output =>
374 exit when Nam = TSS_Stream_Output;
376 when others =>
377 null;
379 end case;
380 end if;
382 Next_Rep_Item (Rep_Item);
383 end loop;
385 -- If At_Any_Place is true, return True if the attribute is available
386 -- at any place; if it is false, return True only if the attribute is
387 -- currently visible.
389 return Present (Rep_Item)
390 and then (Ada_Version < Ada_05
391 or else At_Any_Place
392 or else not Is_Hidden (Entity (Rep_Item)));
393 end Has_Stream_Attribute_Definition;
395 ---------------------------
396 -- In_Preelaborated_Unit --
397 ---------------------------
399 function In_Preelaborated_Unit return Boolean is
400 Unit_Entity : constant Entity_Id := Current_Scope;
401 Unit_Kind : constant Node_Kind :=
402 Nkind (Unit (Cunit (Current_Sem_Unit)));
404 begin
405 -- There are no constraints on body of remote_call_interface or
406 -- remote_types packages.
408 return (Unit_Entity /= Standard_Standard)
409 and then (Is_Preelaborated (Unit_Entity)
410 or else Is_Pure (Unit_Entity)
411 or else Is_Shared_Passive (Unit_Entity)
412 or else
413 ((Is_Remote_Types (Unit_Entity)
414 or else Is_Remote_Call_Interface (Unit_Entity))
415 and then Ekind (Unit_Entity) = E_Package
416 and then Unit_Kind /= N_Package_Body
417 and then not In_Package_Body (Unit_Entity)
418 and then not In_Instance));
419 end In_Preelaborated_Unit;
421 ------------------
422 -- In_Pure_Unit --
423 ------------------
425 function In_Pure_Unit return Boolean is
426 begin
427 return Is_Pure (Current_Scope);
428 end In_Pure_Unit;
430 ------------------------
431 -- In_RCI_Declaration --
432 ------------------------
434 function In_RCI_Declaration (N : Node_Id) return Boolean is
435 Unit_Entity : constant Entity_Id := Current_Scope;
436 Unit_Kind : constant Node_Kind :=
437 Nkind (Unit (Cunit (Current_Sem_Unit)));
439 begin
440 -- There are no restrictions on the private part or body
441 -- of an RCI unit.
443 return Is_Remote_Call_Interface (Unit_Entity)
444 and then Is_Package_Or_Generic_Package (Unit_Entity)
445 and then Unit_Kind /= N_Package_Body
446 and then List_Containing (N) =
447 Visible_Declarations
448 (Specification (Unit_Declaration_Node (Unit_Entity)))
449 and then not In_Package_Body (Unit_Entity)
450 and then not In_Instance;
452 -- What about the case of a nested package in the visible part???
453 -- This case is missed by the List_Containing check above???
454 end In_RCI_Declaration;
456 -----------------------
457 -- In_RT_Declaration --
458 -----------------------
460 function In_RT_Declaration return Boolean is
461 Unit_Entity : constant Entity_Id := Current_Scope;
462 Unit_Kind : constant Node_Kind :=
463 Nkind (Unit (Cunit (Current_Sem_Unit)));
465 begin
466 -- There are no restrictions on the body of a Remote Types unit
468 return Is_Remote_Types (Unit_Entity)
469 and then Is_Package_Or_Generic_Package (Unit_Entity)
470 and then Unit_Kind /= N_Package_Body
471 and then not In_Package_Body (Unit_Entity)
472 and then not In_Instance;
473 end In_RT_Declaration;
475 ----------------------------
476 -- In_Shared_Passive_Unit --
477 ----------------------------
479 function In_Shared_Passive_Unit return Boolean is
480 Unit_Entity : constant Entity_Id := Current_Scope;
482 begin
483 return Is_Shared_Passive (Unit_Entity);
484 end In_Shared_Passive_Unit;
486 ---------------------------------------
487 -- In_Subprogram_Task_Protected_Unit --
488 ---------------------------------------
490 function In_Subprogram_Task_Protected_Unit return Boolean is
491 E : Entity_Id;
493 begin
494 -- The following is to verify that a declaration is inside
495 -- subprogram, generic subprogram, task unit, protected unit.
496 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
498 -- Use scope chain to check successively outer scopes
500 E := Current_Scope;
501 loop
502 if Is_Subprogram (E)
503 or else
504 Is_Generic_Subprogram (E)
505 or else
506 Is_Concurrent_Type (E)
507 then
508 return True;
510 elsif E = Standard_Standard then
511 return False;
512 end if;
514 E := Scope (E);
515 end loop;
516 end In_Subprogram_Task_Protected_Unit;
518 -------------------------------
519 -- Is_Non_Remote_Access_Type --
520 -------------------------------
522 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
523 U_E : constant Entity_Id := Underlying_Type (E);
524 begin
525 if No (U_E) then
527 -- This case arises for the case of a generic formal type, in which
528 -- case E.2.2(8) rules will be enforced at instantiation time.
530 return False;
531 end if;
533 return Is_Access_Type (U_E)
534 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
535 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
536 end Is_Non_Remote_Access_Type;
538 ----------------------------------
539 -- Missing_Read_Write_Attribute --
540 ----------------------------------
542 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
543 Component : Entity_Id;
544 Component_Type : Entity_Id;
545 U_E : constant Entity_Id := Underlying_Type (E);
547 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
548 -- Return True if entity has attribute definition clauses for Read and
549 -- Write attributes that are visible at some place.
551 -------------------------------
552 -- Has_Read_Write_Attributes --
553 -------------------------------
555 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
556 begin
557 return True
558 and then Has_Stream_Attribute_Definition (E,
559 TSS_Stream_Read, At_Any_Place => True)
560 and then Has_Stream_Attribute_Definition (E,
561 TSS_Stream_Write, At_Any_Place => True);
562 end Has_Read_Write_Attributes;
564 -- Start of processing for Missing_Read_Write_Attributes
566 begin
567 if No (U_E) then
568 return False;
570 elsif Has_Read_Write_Attributes (E)
571 or else Has_Read_Write_Attributes (U_E)
572 then
573 return False;
575 elsif Is_Non_Remote_Access_Type (U_E) then
576 return True;
577 end if;
579 if Is_Record_Type (U_E) then
580 Component := First_Entity (U_E);
581 while Present (Component) loop
582 if not Is_Tag (Component) then
583 Component_Type := Etype (Component);
585 if Missing_Read_Write_Attributes (Component_Type) then
586 return True;
587 end if;
588 end if;
590 Next_Entity (Component);
591 end loop;
592 end if;
594 return False;
595 end Missing_Read_Write_Attributes;
597 -------------------------------------
598 -- Set_Categorization_From_Pragmas --
599 -------------------------------------
601 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
602 P : constant Node_Id := Parent (N);
603 S : constant Entity_Id := Current_Scope;
605 procedure Set_Parents (Visibility : Boolean);
606 -- If this is a child instance, the parents are not immediately
607 -- visible during analysis. Make them momentarily visible so that
608 -- the argument of the pragma can be resolved properly, and reset
609 -- afterwards.
611 -----------------
612 -- Set_Parents --
613 -----------------
615 procedure Set_Parents (Visibility : Boolean) is
616 Par : Entity_Id;
617 begin
618 Par := Scope (S);
619 while Present (Par) and then Par /= Standard_Standard loop
620 Set_Is_Immediately_Visible (Par, Visibility);
621 Par := Scope (Par);
622 end loop;
623 end Set_Parents;
625 -- Start of processing for Set_Categorization_From_Pragmas
627 begin
628 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
629 -- The purpose is to set categorization flags before analyzing the
630 -- unit itself, so as to diagnose violations of categorization as
631 -- we process each declaration, even though the pragma appears after
632 -- the unit.
634 if Nkind (P) /= N_Compilation_Unit then
635 return;
636 end if;
638 declare
639 PN : Node_Id;
641 begin
642 if Is_Child_Unit (S)
643 and then Is_Generic_Instance (S)
644 then
645 Set_Parents (True);
646 end if;
648 PN := First (Pragmas_After (Aux_Decls_Node (P)));
649 while Present (PN) loop
651 -- Skip implicit types that may have been introduced by
652 -- previous analysis.
654 if Nkind (PN) = N_Pragma then
655 case Get_Pragma_Id (PN) is
656 when Pragma_All_Calls_Remote |
657 Pragma_Preelaborate |
658 Pragma_Pure |
659 Pragma_Remote_Call_Interface |
660 Pragma_Remote_Types |
661 Pragma_Shared_Passive => Analyze (PN);
662 when others => null;
663 end case;
664 end if;
666 Next (PN);
667 end loop;
669 if Is_Child_Unit (S)
670 and then Is_Generic_Instance (S)
671 then
672 Set_Parents (False);
673 end if;
674 end;
675 end Set_Categorization_From_Pragmas;
677 -----------------------------------
678 -- Set_Categorization_From_Scope --
679 -----------------------------------
681 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
682 Declaration : Node_Id := Empty;
683 Specification : Node_Id := Empty;
685 begin
686 Set_Is_Pure (E,
687 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
689 if not Is_Remote_Call_Interface (E) then
690 if Ekind (E) in Subprogram_Kind then
691 Declaration := Unit_Declaration_Node (E);
693 if Nkind (Declaration) = N_Subprogram_Body
694 or else
695 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
696 then
697 Specification := Corresponding_Spec (Declaration);
698 end if;
699 end if;
701 -- A subprogram body or renaming-as-body is a remote call
702 -- interface if it serves as the completion of a subprogram
703 -- declaration that is a remote call interface.
705 if Nkind (Specification) in N_Entity then
706 Set_Is_Remote_Call_Interface
707 (E, Is_Remote_Call_Interface (Specification));
709 -- A subprogram declaration is a remote call interface when it is
710 -- declared within the visible part of, or declared by, a library
711 -- unit declaration that is a remote call interface.
713 else
714 Set_Is_Remote_Call_Interface
715 (E, Is_Remote_Call_Interface (Scop)
716 and then not (In_Private_Part (Scop)
717 or else In_Package_Body (Scop)));
718 end if;
719 end if;
721 Set_Is_Remote_Types
722 (E, Is_Remote_Types (Scop)
723 and then not (In_Private_Part (Scop)
724 or else In_Package_Body (Scop)));
725 end Set_Categorization_From_Scope;
727 ------------------------------
728 -- Static_Discriminant_Expr --
729 ------------------------------
731 -- We need to accommodate a Why_Not_Static call somehow here ???
733 function Static_Discriminant_Expr (L : List_Id) return Boolean is
734 Discriminant_Spec : Node_Id;
736 begin
737 Discriminant_Spec := First (L);
738 while Present (Discriminant_Spec) loop
739 if Present (Expression (Discriminant_Spec))
740 and then not Is_Static_Expression (Expression (Discriminant_Spec))
741 then
742 return False;
743 end if;
745 Next (Discriminant_Spec);
746 end loop;
748 return True;
749 end Static_Discriminant_Expr;
751 --------------------------------------
752 -- Validate_Access_Type_Declaration --
753 --------------------------------------
755 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
756 Def : constant Node_Id := Type_Definition (N);
758 begin
759 case Nkind (Def) is
761 -- Access to subprogram case
763 when N_Access_To_Subprogram_Definition =>
765 -- A pure library_item must not contain the declaration of a
766 -- named access type, except within a subprogram, generic
767 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
769 -- This test is skipped in Ada 2005 (see AI-366)
771 if Ada_Version < Ada_05
772 and then Comes_From_Source (T)
773 and then In_Pure_Unit
774 and then not In_Subprogram_Task_Protected_Unit
775 then
776 Error_Msg_N ("named access type not allowed in pure unit", T);
777 end if;
779 -- Access to object case
781 when N_Access_To_Object_Definition =>
782 if Comes_From_Source (T)
783 and then In_Pure_Unit
784 and then not In_Subprogram_Task_Protected_Unit
785 then
786 -- We can't give the message yet, since the type is not frozen
787 -- and in Ada 2005 mode, access types are allowed in pure units
788 -- if the type has no storage pool (see AI-366). So we set a
789 -- flag which will be checked at freeze time.
791 Set_Is_Pure_Unit_Access_Type (T);
792 end if;
794 -- Check for RCI or RT unit type declaration: declaration of an
795 -- access-to-object type is illegal unless it is a general access
796 -- type that designates a class-wide limited private type.
797 -- Note that constraints on the primitive subprograms of the
798 -- designated tagged type are not enforced here but in
799 -- Validate_RACW_Primitives, which is done separately because the
800 -- designated type might not be frozen (and therefore its
801 -- primitive operations might not be completely known) at the
802 -- point of the RACW declaration.
804 Validate_Remote_Access_Object_Type_Declaration (T);
806 -- Check for shared passive unit type declaration. It should
807 -- not contain the declaration of access to class wide type,
808 -- access to task type and access to protected type with entry.
810 Validate_SP_Access_Object_Type_Decl (T);
812 when others =>
813 null;
814 end case;
816 -- Set categorization flag from package on entity as well, to allow
817 -- easy checks later on for required validations of RCI or RT units.
818 -- This is only done for entities that are in the original source.
820 if Comes_From_Source (T)
821 and then not (In_Package_Body (Scope (T))
822 or else In_Private_Part (Scope (T)))
823 then
824 Set_Is_Remote_Call_Interface
825 (T, Is_Remote_Call_Interface (Scope (T)));
826 Set_Is_Remote_Types
827 (T, Is_Remote_Types (Scope (T)));
828 end if;
829 end Validate_Access_Type_Declaration;
831 ----------------------------
832 -- Validate_Ancestor_Part --
833 ----------------------------
835 procedure Validate_Ancestor_Part (N : Node_Id) is
836 A : constant Node_Id := Ancestor_Part (N);
837 T : constant Entity_Id := Entity (A);
839 begin
840 if In_Preelaborated_Unit
841 and then not In_Subprogram_Or_Concurrent_Unit
842 and then (not Inside_A_Generic
843 or else Present (Enclosing_Generic_Body (N)))
844 then
845 -- If the type is private, it must have the Ada 2005 pragma
846 -- Has_Preelaborable_Initialization.
847 -- The check is omitted within predefined units. This is probably
848 -- obsolete code to fix the Ada95 weakness in this area ???
850 if Is_Private_Type (T)
851 and then not Has_Pragma_Preelab_Init (T)
852 and then not Is_Internal_File_Name
853 (Unit_File_Name (Get_Source_Unit (N)))
854 then
855 Error_Msg_N
856 ("private ancestor type not allowed in preelaborated unit", A);
858 elsif Is_Record_Type (T) then
859 if Nkind (Parent (T)) = N_Full_Type_Declaration then
860 Check_Non_Static_Default_Expr
861 (Type_Definition (Parent (T)), A);
862 end if;
863 end if;
864 end if;
865 end Validate_Ancestor_Part;
867 ----------------------------------------
868 -- Validate_Categorization_Dependency --
869 ----------------------------------------
871 procedure Validate_Categorization_Dependency
872 (N : Node_Id;
873 E : Entity_Id)
875 K : constant Node_Kind := Nkind (N);
876 P : Node_Id := Parent (N);
877 U : Entity_Id := E;
878 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
880 begin
881 -- Only validate library units and subunits. For subunits, checks
882 -- concerning withed units apply to the parent compilation unit.
884 if Is_Subunit then
885 P := Parent (P);
886 U := Scope (E);
888 while Present (U)
889 and then not Is_Compilation_Unit (U)
890 and then not Is_Child_Unit (U)
891 loop
892 U := Scope (U);
893 end loop;
894 end if;
896 if Nkind (P) /= N_Compilation_Unit then
897 return;
898 end if;
900 -- Body of RCI unit does not need validation
902 if Is_Remote_Call_Interface (E)
903 and then (Nkind (N) = N_Package_Body
904 or else Nkind (N) = N_Subprogram_Body)
905 then
906 return;
907 end if;
909 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
911 declare
912 Item : Node_Id;
913 Entity_Of_Withed : Entity_Id;
915 begin
916 Item := First (Context_Items (P));
917 while Present (Item) loop
918 if Nkind (Item) = N_With_Clause
919 and then not (Implicit_With (Item)
920 or else Limited_Present (Item))
921 then
922 Entity_Of_Withed := Entity (Name (Item));
923 Check_Categorization_Dependencies
924 (U, Entity_Of_Withed, Item, Is_Subunit);
925 end if;
927 Next (Item);
928 end loop;
929 end;
931 -- Child depends on parent; therefore parent should also be categorized
932 -- and satisfy the dependency hierarchy.
934 -- Check if N is a child spec
936 if (K in N_Generic_Declaration or else
937 K in N_Generic_Instantiation or else
938 K in N_Generic_Renaming_Declaration or else
939 K = N_Package_Declaration or else
940 K = N_Package_Renaming_Declaration or else
941 K = N_Subprogram_Declaration or else
942 K = N_Subprogram_Renaming_Declaration)
943 and then Present (Parent_Spec (N))
944 then
945 Check_Categorization_Dependencies (E, Scope (E), N, False);
947 -- Verify that public child of an RCI library unit must also be an
948 -- RCI library unit (RM E.2.3(15)).
950 if Is_Remote_Call_Interface (Scope (E))
951 and then not Private_Present (P)
952 and then not Is_Remote_Call_Interface (E)
953 then
954 Error_Msg_N ("public child of rci unit must also be rci unit", N);
955 end if;
956 end if;
957 end Validate_Categorization_Dependency;
959 --------------------------------
960 -- Validate_Controlled_Object --
961 --------------------------------
963 procedure Validate_Controlled_Object (E : Entity_Id) is
964 begin
965 -- Don't need this check in Ada 2005 mode, where this is all taken
966 -- care of by the mechanism for Preelaborable Initialization.
968 if Ada_Version >= Ada_05 then
969 return;
970 end if;
972 -- For now, never apply this check for internal GNAT units, since we
973 -- have a number of cases in the library where we are stuck with objects
974 -- of this type, and the RM requires Preelaborate.
976 -- For similar reasons, we only do this check for source entities, since
977 -- we generate entities of this type in some situations.
979 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
980 -- We have to enforce them for RM compatibility, but we have no trouble
981 -- accepting these objects and doing the right thing. Note that there is
982 -- no requirement that Preelaborate not actually generate any code!
984 if In_Preelaborated_Unit
985 and then not Debug_Flag_PP
986 and then Comes_From_Source (E)
987 and then not
988 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
989 and then (not Inside_A_Generic
990 or else Present (Enclosing_Generic_Body (E)))
991 and then not Is_Protected_Type (Etype (E))
992 then
993 Error_Msg_N
994 ("library level controlled object not allowed in " &
995 "preelaborated unit", E);
996 end if;
997 end Validate_Controlled_Object;
999 --------------------------------------
1000 -- Validate_Null_Statement_Sequence --
1001 --------------------------------------
1003 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1004 Item : Node_Id;
1006 begin
1007 if In_Preelaborated_Unit then
1008 Item := First (Statements (Handled_Statement_Sequence (N)));
1009 while Present (Item) loop
1010 if Nkind (Item) /= N_Label
1011 and then Nkind (Item) /= N_Null_Statement
1012 then
1013 -- In GNAT mode, this is a warning, allowing the run-time
1014 -- to judiciously bypass this error condition.
1016 Error_Msg_Warn := GNAT_Mode;
1017 Error_Msg_N
1018 ("<statements not allowed in preelaborated unit", Item);
1020 exit;
1021 end if;
1023 Next (Item);
1024 end loop;
1025 end if;
1026 end Validate_Null_Statement_Sequence;
1028 ---------------------------------
1029 -- Validate_Object_Declaration --
1030 ---------------------------------
1032 procedure Validate_Object_Declaration (N : Node_Id) is
1033 Id : constant Entity_Id := Defining_Identifier (N);
1034 E : constant Node_Id := Expression (N);
1035 Odf : constant Node_Id := Object_Definition (N);
1036 T : constant Entity_Id := Etype (Id);
1038 begin
1039 -- Verify that any access to subprogram object does not have in its
1040 -- subprogram profile access type parameters or limited parameters
1041 -- without Read and Write attributes (E.2.3(13)).
1043 Validate_RCI_Subprogram_Declaration (N);
1045 -- Check that if we are in preelaborated elaboration code, then we
1046 -- do not have an instance of a default initialized private, task or
1047 -- protected object declaration which would violate (RM 10.2.1(9)).
1048 -- Note that constants are never default initialized (and the test
1049 -- below also filters out deferred constants). A variable is default
1050 -- initialized if it does *not* have an initialization expression.
1052 -- Filter out cases that are not declaration of a variable from source
1054 if Nkind (N) /= N_Object_Declaration
1055 or else Constant_Present (N)
1056 or else not Comes_From_Source (Id)
1057 then
1058 return;
1059 end if;
1061 -- Exclude generic specs from the checks (this will get rechecked
1062 -- on instantiations).
1064 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1065 return;
1066 end if;
1068 -- Required checks for declaration that is in a preelaborated package
1069 -- and is not within some subprogram.
1071 if In_Preelaborated_Unit
1072 and then not In_Subprogram_Or_Concurrent_Unit
1073 then
1074 -- Check for default initialized variable case. Note that in
1075 -- accordance with (RM B.1(24)) imported objects are not subject to
1076 -- default initialization.
1077 -- If the initialization does not come from source and is an
1078 -- aggregate, it is a static initialization that replaces an
1079 -- implicit call, and must be treated as such.
1081 if Present (E)
1082 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1083 then
1084 null;
1086 elsif Is_Imported (Id) then
1087 null;
1089 else
1090 declare
1091 Ent : Entity_Id := T;
1093 begin
1094 -- An array whose component type is a record with nonstatic
1095 -- default expressions is a violation, so we get the array's
1096 -- component type.
1098 if Is_Array_Type (Ent) then
1099 declare
1100 Comp_Type : Entity_Id;
1102 begin
1103 Comp_Type := Component_Type (Ent);
1104 while Is_Array_Type (Comp_Type) loop
1105 Comp_Type := Component_Type (Comp_Type);
1106 end loop;
1108 Ent := Comp_Type;
1109 end;
1110 end if;
1112 -- Object decl. that is of record type and has no default expr.
1113 -- should check if there is any non-static default expression
1114 -- in component decl. of the record type decl.
1116 if Is_Record_Type (Ent) then
1117 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1118 Check_Non_Static_Default_Expr
1119 (Type_Definition (Parent (Ent)), N);
1121 elsif Nkind (Odf) = N_Subtype_Indication
1122 and then not Is_Array_Type (T)
1123 and then not Is_Private_Type (T)
1124 then
1125 Check_Non_Static_Default_Expr (Type_Definition
1126 (Parent (Entity (Subtype_Mark (Odf)))), N);
1127 end if;
1128 end if;
1130 -- Check for invalid use of private object. Note that Ada 2005
1131 -- AI-161 modifies the rules for Ada 2005, including the use of
1132 -- the new pragma Preelaborable_Initialization.
1134 if Is_Private_Type (Ent)
1135 or else Depends_On_Private (Ent)
1136 then
1137 -- Case where type has preelaborable initialization which
1138 -- means that a pragma Preelaborable_Initialization was
1139 -- given for the private type.
1141 if Has_Preelaborable_Initialization (Ent) then
1143 -- But for the predefined units, we will ignore this
1144 -- status unless we are in Ada 2005 mode since we want
1145 -- Ada 95 compatible behavior, in which the entities
1146 -- marked with this pragma in the predefined library are
1147 -- not treated specially.
1149 if Ada_Version < Ada_05 then
1150 Error_Msg_N
1151 ("private object not allowed in preelaborated unit",
1153 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1154 end if;
1156 -- Type does not have preelaborable initialization
1158 else
1159 -- We allow this when compiling in GNAT mode to make life
1160 -- easier for some cases where it would otherwise be hard
1161 -- to be exactly valid Ada.
1163 if not GNAT_Mode then
1164 Error_Msg_N
1165 ("private object not allowed in preelaborated unit",
1168 -- Add a message if it would help to provide a pragma
1169 -- Preelaborable_Initialization on the type of the
1170 -- object (which would make it legal in Ada 2005).
1172 -- If the type has no full view (generic type, or
1173 -- previous error), the warning does not apply.
1175 if Is_Private_Type (Ent)
1176 and then Present (Full_View (Ent))
1177 and then
1178 Has_Preelaborable_Initialization (Full_View (Ent))
1179 then
1180 Error_Msg_Sloc := Sloc (Ent);
1182 if Ada_Version >= Ada_05 then
1183 Error_Msg_NE
1184 ("\would be legal if pragma Preelaborable_" &
1185 "Initialization given for & #", N, Ent);
1186 else
1187 Error_Msg_NE
1188 ("\would be legal in Ada 2005 if pragma " &
1189 "Preelaborable_Initialization given for & #",
1190 N, Ent);
1191 end if;
1192 end if;
1193 end if;
1194 end if;
1196 -- Access to Task or Protected type
1198 elsif Is_Entity_Name (Odf)
1199 and then Present (Etype (Odf))
1200 and then Is_Access_Type (Etype (Odf))
1201 then
1202 Ent := Designated_Type (Etype (Odf));
1204 elsif Is_Entity_Name (Odf) then
1205 Ent := Entity (Odf);
1207 elsif Nkind (Odf) = N_Subtype_Indication then
1208 Ent := Etype (Subtype_Mark (Odf));
1210 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1211 Ent := Component_Type (T);
1212 end if;
1214 if Is_Task_Type (Ent)
1215 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1216 then
1217 Error_Msg_N
1218 ("concurrent object not allowed in preelaborated unit",
1220 return;
1221 end if;
1222 end;
1223 end if;
1225 -- Non-static discriminants not allowed in preelaborated unit.
1226 -- Objects of a controlled type with a user-defined Initialize
1227 -- are forbidden as well.
1229 if Is_Record_Type (Etype (Id)) then
1230 declare
1231 ET : constant Entity_Id := Etype (Id);
1232 EE : constant Entity_Id := Etype (Etype (Id));
1233 PEE : Node_Id;
1235 begin
1236 if Has_Discriminants (ET)
1237 and then Present (EE)
1238 then
1239 PEE := Parent (EE);
1241 if Nkind (PEE) = N_Full_Type_Declaration
1242 and then not Static_Discriminant_Expr
1243 (Discriminant_Specifications (PEE))
1244 then
1245 Error_Msg_N
1246 ("non-static discriminant in preelaborated unit",
1247 PEE);
1248 end if;
1249 end if;
1251 if Has_Overriding_Initialize (ET) then
1252 Error_Msg_NE
1253 ("controlled type& does not have"
1254 & " preelaborable initialization", N, ET);
1255 end if;
1256 end;
1258 end if;
1259 end if;
1261 -- A pure library_item must not contain the declaration of any variable
1262 -- except within a subprogram, generic subprogram, task unit, or
1263 -- protected unit (RM 10.2.1(16)).
1265 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1266 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1268 -- The visible part of an RCI library unit must not contain the
1269 -- declaration of a variable (RM E.1.3(9))
1271 elsif In_RCI_Declaration (N) then
1272 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1274 -- The visible part of a Shared Passive library unit must not contain
1275 -- the declaration of a variable (RM E.2.2(7))
1277 elsif In_RT_Declaration and then not In_Private_Part (Id) then
1278 Error_Msg_N
1279 ("visible variable not allowed in remote types unit", N);
1280 end if;
1282 end Validate_Object_Declaration;
1284 ------------------------------
1285 -- Validate_RACW_Primitives --
1286 ------------------------------
1288 procedure Validate_RACW_Primitives (T : Entity_Id) is
1289 Desig_Type : Entity_Id;
1290 Primitive_Subprograms : Elist_Id;
1291 Subprogram_Elmt : Elmt_Id;
1292 Subprogram : Entity_Id;
1293 Param_Spec : Node_Id;
1294 Param : Entity_Id;
1295 Param_Type : Entity_Id;
1296 Rtyp : Node_Id;
1298 procedure Illegal_RACW (Msg : String; N : Node_Id);
1299 -- Diagnose that T is illegal because of the given reason, associated
1300 -- with the location of node N.
1302 Illegal_RACW_Message_Issued : Boolean := False;
1303 -- Set True once Illegal_RACW has been called
1305 ------------------
1306 -- Illegal_RACW --
1307 ------------------
1309 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1310 begin
1311 if not Illegal_RACW_Message_Issued then
1312 Error_Msg_N
1313 ("illegal remote access to class-wide type&", T);
1314 Illegal_RACW_Message_Issued := True;
1315 end if;
1317 Error_Msg_Sloc := Sloc (N);
1318 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1319 end Illegal_RACW;
1321 -- Start of processing for Validate_RACW_Primitives
1323 begin
1324 Desig_Type := Etype (Designated_Type (T));
1326 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1328 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1329 while Subprogram_Elmt /= No_Elmt loop
1330 Subprogram := Node (Subprogram_Elmt);
1332 if Is_Predefined_Dispatching_Operation (Subprogram)
1333 or else Is_Hidden (Subprogram)
1334 then
1335 goto Next_Subprogram;
1336 end if;
1338 -- Check return type
1340 if Ekind (Subprogram) = E_Function then
1341 Rtyp := Etype (Subprogram);
1343 if Has_Controlling_Result (Subprogram) then
1344 null;
1346 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1347 Illegal_RACW ("anonymous access result", Rtyp);
1349 elsif Is_Limited_Type (Rtyp) then
1350 if No (TSS (Rtyp, TSS_Stream_Read))
1351 or else
1352 No (TSS (Rtyp, TSS_Stream_Write))
1353 then
1354 Illegal_RACW
1355 ("limited return type must have Read and Write attributes",
1356 Parent (Subprogram));
1357 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1359 -- Check that the return type supports external streaming.
1360 -- Note that the language of the standard (E.2.2(14)) does not
1361 -- explicitly mention that case, but it really does not make
1362 -- sense to return a value containing a local access type.
1364 elsif Missing_Read_Write_Attributes (Rtyp)
1365 and then not Error_Posted (Rtyp)
1366 then
1367 Illegal_RACW ("return type containing non-remote access "
1368 & "must have Read and Write attributes",
1369 Parent (Subprogram));
1370 end if;
1372 end if;
1373 end if;
1375 Param := First_Formal (Subprogram);
1376 while Present (Param) loop
1378 -- Now find out if this parameter is a controlling parameter
1380 Param_Spec := Parent (Param);
1381 Param_Type := Etype (Param);
1383 if Is_Controlling_Formal (Param) then
1385 -- It is a controlling parameter, so specific checks below
1386 -- do not apply.
1388 null;
1390 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1391 E_Anonymous_Access_Subprogram_Type)
1392 then
1393 -- From RM E.2.2(14), no anonymous access parameter other than
1394 -- controlling ones may be used (because an anonymous access
1395 -- type never supports external streaming).
1397 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1399 elsif Is_Limited_Type (Param_Type) then
1401 -- Not a controlling parameter, so type must have Read and
1402 -- Write attributes.
1404 if No (TSS (Param_Type, TSS_Stream_Read))
1405 or else
1406 No (TSS (Param_Type, TSS_Stream_Write))
1407 then
1408 Illegal_RACW
1409 ("limited formal must have Read and Write attributes",
1410 Param_Spec);
1411 Explain_Limited_Type (Param_Type, Param_Spec);
1412 end if;
1414 elsif Missing_Read_Write_Attributes (Param_Type)
1415 and then not Error_Posted (Param_Type)
1416 then
1417 Illegal_RACW ("parameter containing non-remote access "
1418 & "must have Read and Write attributes", Param_Spec);
1419 end if;
1421 -- Check next parameter in this subprogram
1423 Next_Formal (Param);
1424 end loop;
1426 <<Next_Subprogram>>
1427 Next_Elmt (Subprogram_Elmt);
1428 end loop;
1429 end Validate_RACW_Primitives;
1431 -------------------------------
1432 -- Validate_RCI_Declarations --
1433 -------------------------------
1435 procedure Validate_RCI_Declarations (P : Entity_Id) is
1436 E : Entity_Id;
1438 begin
1439 E := First_Entity (P);
1440 while Present (E) loop
1441 if Comes_From_Source (E) then
1442 if Is_Limited_Type (E) then
1443 Error_Msg_N
1444 ("limited type not allowed in rci unit", Parent (E));
1445 Explain_Limited_Type (E, Parent (E));
1447 elsif Ekind_In (E, E_Generic_Function,
1448 E_Generic_Package,
1449 E_Generic_Procedure)
1450 then
1451 Error_Msg_N ("generic declaration not allowed in rci unit",
1452 Parent (E));
1454 elsif (Ekind (E) = E_Function
1455 or else Ekind (E) = E_Procedure)
1456 and then Has_Pragma_Inline (E)
1457 then
1458 Error_Msg_N
1459 ("inlined subprogram not allowed in rci unit", Parent (E));
1461 -- Inner packages that are renamings need not be checked. Generic
1462 -- RCI packages are subject to the checks, but entities that come
1463 -- from formal packages are not part of the visible declarations
1464 -- of the package and are not checked.
1466 elsif Ekind (E) = E_Package then
1467 if Present (Renamed_Entity (E)) then
1468 null;
1470 elsif Ekind (P) /= E_Generic_Package
1471 or else List_Containing (Unit_Declaration_Node (E)) /=
1472 Generic_Formal_Declarations
1473 (Unit_Declaration_Node (P))
1474 then
1475 Validate_RCI_Declarations (E);
1476 end if;
1477 end if;
1478 end if;
1480 Next_Entity (E);
1481 end loop;
1482 end Validate_RCI_Declarations;
1484 -----------------------------------------
1485 -- Validate_RCI_Subprogram_Declaration --
1486 -----------------------------------------
1488 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1489 K : constant Node_Kind := Nkind (N);
1490 Profile : List_Id;
1491 Id : Node_Id;
1492 Param_Spec : Node_Id;
1493 Param_Type : Entity_Id;
1494 Base_Param_Type : Entity_Id;
1495 Base_Under_Type : Entity_Id;
1496 Type_Decl : Node_Id;
1497 Error_Node : Node_Id := N;
1499 begin
1500 -- This procedure enforces rules on subprogram and access to subprogram
1501 -- declarations in RCI units. These rules do not apply to expander
1502 -- generated routines, which are not remote subprograms. It is called:
1504 -- 1. from Analyze_Subprogram_Declaration.
1505 -- 2. from Validate_Object_Declaration (access to subprogram).
1507 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1508 return;
1509 end if;
1511 if K = N_Subprogram_Declaration then
1512 Profile := Parameter_Specifications (Specification (N));
1514 else pragma Assert (K = N_Object_Declaration);
1516 -- The above assertion is dubious, the visible declarations of an
1517 -- RCI unit never contain an object declaration, this should be an
1518 -- ACCESS-to-object declaration???
1520 Id := Defining_Identifier (N);
1522 if Nkind (Id) = N_Defining_Identifier
1523 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1524 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1525 then
1526 Profile :=
1527 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1528 else
1529 return;
1530 end if;
1531 end if;
1533 -- Iterate through the parameter specification list, checking that
1534 -- no access parameter and no limited type parameter in the list.
1535 -- RM E.2.3(14).
1537 if Present (Profile) then
1538 Param_Spec := First (Profile);
1539 while Present (Param_Spec) loop
1540 Param_Type := Etype (Defining_Identifier (Param_Spec));
1541 Type_Decl := Parent (Param_Type);
1543 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1544 if K = N_Subprogram_Declaration then
1545 Error_Node := Param_Spec;
1546 end if;
1548 -- Report error only if declaration is in source program
1550 if Comes_From_Source
1551 (Defining_Entity (Specification (N)))
1552 then
1553 Error_Msg_N
1554 ("subprogram in 'R'C'I unit cannot have access parameter",
1555 Error_Node);
1556 end if;
1558 -- For a limited private type parameter, we check only the private
1559 -- declaration and ignore full type declaration, unless this is
1560 -- the only declaration for the type, e.g., as a limited record.
1562 elsif Is_Limited_Type (Param_Type)
1563 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1564 or else
1565 (Nkind (Type_Decl) = N_Full_Type_Declaration
1566 and then not (Has_Private_Declaration (Param_Type))
1567 and then Comes_From_Source (N)))
1568 then
1569 -- A limited parameter is legal only if user-specified Read and
1570 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1572 if No (Full_View (Param_Type))
1573 and then Ekind (Param_Type) /= E_Record_Type
1574 then
1575 -- Type does not have completion yet, so if declared in
1576 -- the current RCI scope it is illegal, and will be flagged
1577 -- subsequently.
1579 return;
1580 end if;
1582 -- In Ada 95 the rules permit using a limited type that has
1583 -- user-specified Read and Write attributes that are specified
1584 -- in the private part of the package, whereas Ada 2005
1585 -- (AI-240) revises this to require the attributes to be
1586 -- "available" (implying that the attribute clauses must be
1587 -- visible to the RCI client). The Ada 95 rules violate the
1588 -- contract model for privacy, but we support both semantics
1589 -- for now for compatibility (note that ACATS test BXE2009
1590 -- checks a case that conforms to the Ada 95 rules but is
1591 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1592 -- possibilities of visible TSS stream subprograms or explicit
1593 -- stream attribute definitions because the TSS subprograms
1594 -- can be hidden in the private part while the attribute
1595 -- definitions are still be available from the visible part.
1597 Base_Param_Type := Base_Type (Param_Type);
1598 Base_Under_Type := Base_Type (Underlying_Type
1599 (Base_Param_Type));
1601 if (Ada_Version < Ada_05
1602 and then
1603 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1604 or else
1605 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1606 and then
1607 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1608 or else
1609 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1610 or else
1611 (Ada_Version >= Ada_05
1612 and then
1613 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1614 or else
1615 No (TSS (Base_Param_Type, TSS_Stream_Write))
1616 or else
1617 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1618 or else
1619 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1620 and then
1621 (not Has_Stream_Attribute_Definition
1622 (Base_Param_Type, TSS_Stream_Read)
1623 or else
1624 not Has_Stream_Attribute_Definition
1625 (Base_Param_Type, TSS_Stream_Write)))
1626 then
1627 if K = N_Subprogram_Declaration then
1628 Error_Node := Param_Spec;
1629 end if;
1631 if Ada_Version >= Ada_05 then
1632 Error_Msg_N
1633 ("limited parameter in 'R'C'I unit "
1634 & "must have visible read/write attributes ",
1635 Error_Node);
1636 else
1637 Error_Msg_N
1638 ("limited parameter in 'R'C'I unit "
1639 & "must have read/write attributes ",
1640 Error_Node);
1641 end if;
1642 Explain_Limited_Type (Param_Type, Error_Node);
1643 end if;
1645 -- In Ada 95, any non-remote access type (or any type with a
1646 -- component of a non-remote access type) that is visible in an
1647 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1648 -- unit, and thus is already guaranteed to support external
1649 -- streaming. However in Ada 2005 we have to account for the case
1650 -- of named access types from declared pure units as well, which
1651 -- may or may not support external streaming, and so we need to
1652 -- perform a specific check for E.2.3(14/2) here.
1654 -- Note that if the declaration of the type itself is illegal, we
1655 -- do not perform this check since it might be a cascaded error.
1657 else
1658 if K = N_Subprogram_Declaration then
1659 Error_Node := Param_Spec;
1660 end if;
1662 if Missing_Read_Write_Attributes (Param_Type)
1663 and then not Error_Posted (Param_Type)
1664 then
1665 Error_Msg_N
1666 ("parameter containing non-remote access in 'R'C'I "
1667 & "subprogram must have visible "
1668 & "Read and Write attributes", Error_Node);
1669 end if;
1670 end if;
1671 Next (Param_Spec);
1672 end loop;
1674 -- No check on return type???
1675 end if;
1676 end Validate_RCI_Subprogram_Declaration;
1678 ----------------------------------------------------
1679 -- Validate_Remote_Access_Object_Type_Declaration --
1680 ----------------------------------------------------
1682 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1684 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1685 -- True if tagged type E is a valid candidate as the root type of the
1686 -- designated type for a RACW, i.e. a tagged limited private type, or a
1687 -- limited interface type, or a private extension of such a type.
1689 ---------------------------------
1690 -- Is_Valid_Remote_Object_Type --
1691 ---------------------------------
1693 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1694 P : constant Node_Id := Parent (E);
1696 begin
1697 pragma Assert (Is_Tagged_Type (E));
1699 -- Simple case: a limited private type
1701 if Nkind (P) = N_Private_Type_Declaration
1702 and then Is_Limited_Record (E)
1703 then
1704 return True;
1706 -- A limited interface is not currently a legal ancestor for the
1707 -- designated type of an RACW type, because a type that implements
1708 -- such an interface need not be limited. However, the ARG seems to
1709 -- incline towards allowing an access to classwide limited interface
1710 -- type as a remote access type, as resolved in AI05-060. But note
1711 -- that the expansion circuitry for RACWs that designate classwide
1712 -- interfaces is not complete yet.
1714 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1715 return True;
1717 -- A generic tagged limited type is a valid candidate. Limitedness
1718 -- will be checked again on the actual at instantiation point.
1720 elsif Nkind (P) = N_Formal_Type_Declaration
1721 and then Ekind (E) = E_Record_Type_With_Private
1722 and then Is_Generic_Type (E)
1723 and then Is_Limited_Record (E)
1724 then
1725 return True;
1727 -- A private extension declaration is a valid candidate if its parent
1728 -- type is.
1730 elsif Nkind (P) = N_Private_Extension_Declaration then
1731 return Is_Valid_Remote_Object_Type (Etype (E));
1733 else
1734 return False;
1735 end if;
1736 end Is_Valid_Remote_Object_Type;
1738 -- Local variables
1740 Direct_Designated_Type : Entity_Id;
1741 Desig_Type : Entity_Id;
1743 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1745 begin
1746 -- We are called from Analyze_Type_Declaration, and the Nkind of the
1747 -- given node is N_Access_To_Object_Definition.
1749 if not Comes_From_Source (T)
1750 or else (not In_RCI_Declaration (Parent (T))
1751 and then not In_RT_Declaration)
1752 then
1753 return;
1754 end if;
1756 -- An access definition in the private part of a Remote Types package
1757 -- may be legal if it has user-defined Read and Write attributes. This
1758 -- will be checked at the end of the package spec processing.
1760 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1761 return;
1762 end if;
1764 -- Check RCI or RT unit type declaration. It may not contain the
1765 -- declaration of an access-to-object type unless it is a general access
1766 -- type that designates a class-wide limited private type or subtype.
1767 -- There are also constraints on the primitive subprograms of the
1768 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1770 if Ekind (T) /= E_General_Access_Type
1771 or else not Is_Class_Wide_Type (Designated_Type (T))
1772 then
1773 if In_RCI_Declaration (Parent (T)) then
1774 Error_Msg_N
1775 ("error in access type in Remote_Call_Interface unit", T);
1776 else
1777 Error_Msg_N
1778 ("error in access type in Remote_Types unit", T);
1779 end if;
1781 Error_Msg_N ("\must be general access to class-wide type", T);
1782 return;
1783 end if;
1785 Direct_Designated_Type := Designated_Type (T);
1786 Desig_Type := Etype (Direct_Designated_Type);
1788 -- Why is the check below not in
1789 -- Validate_Remote_Access_To_Class_Wide_Type???
1791 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1792 Error_Msg_N
1793 ("error in designated type of remote access to class-wide type", T);
1794 Error_Msg_N
1795 ("\must be tagged limited private or private extension", T);
1796 return;
1797 end if;
1798 end Validate_Remote_Access_Object_Type_Declaration;
1800 -----------------------------------------------
1801 -- Validate_Remote_Access_To_Class_Wide_Type --
1802 -----------------------------------------------
1804 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1805 K : constant Node_Kind := Nkind (N);
1806 PK : constant Node_Kind := Nkind (Parent (N));
1807 E : Entity_Id;
1809 begin
1810 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1811 -- of class-wide limited private types.
1813 -- Storage_Pool and Storage_Size are not defined for such types
1815 -- The expected type of allocator must not be such a type.
1817 -- The actual parameter of generic instantiation must not be such a
1818 -- type if the formal parameter is of an access type.
1820 -- On entry, there are five cases
1822 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1823 -- either Storage_Pool or Storage_Size.
1825 -- 2. called from exp_ch4 Expand_N_Allocator
1827 -- 3. called from sem_ch12 Analyze_Associations
1829 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1831 -- 5. called from sem_res Resolve_Actuals
1833 if K = N_Attribute_Reference then
1834 E := Etype (Prefix (N));
1836 if Is_Remote_Access_To_Class_Wide_Type (E) then
1837 Error_Msg_N ("incorrect attribute of remote operand", N);
1838 return;
1839 end if;
1841 elsif K = N_Allocator then
1842 E := Etype (N);
1844 if Is_Remote_Access_To_Class_Wide_Type (E) then
1845 Error_Msg_N ("incorrect expected remote type of allocator", N);
1846 return;
1847 end if;
1849 elsif K in N_Has_Entity then
1850 E := Entity (N);
1852 if Is_Remote_Access_To_Class_Wide_Type (E) then
1853 Error_Msg_N ("incorrect remote type generic actual", N);
1854 return;
1855 end if;
1857 -- This subprogram also enforces the checks in E.2.2(13). A value of
1858 -- such type must not be dereferenced unless as controlling operand of
1859 -- a dispatching call. Explicit dereferences not coming from source are
1860 -- exempted from this checking because the expander produces them in
1861 -- some cases (such as for tag checks on dispatching calls with multiple
1862 -- controlling operands). However we do check in the case of an implicit
1863 -- dereference that is expanded to an explicit dereference (hence the
1864 -- test of whether Original_Node (N) comes from source).
1866 elsif K = N_Explicit_Dereference
1867 and then Comes_From_Source (Original_Node (N))
1868 then
1869 E := Etype (Prefix (N));
1871 -- If the class-wide type is not a remote one, the restrictions
1872 -- do not apply.
1874 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1875 return;
1876 end if;
1878 -- If we have a true dereference that comes from source and that
1879 -- is a controlling argument for a dispatching call, accept it.
1881 if Is_Actual_Parameter (N)
1882 and then Is_Controlling_Actual (N)
1883 then
1884 return;
1885 end if;
1887 -- If we are just within a procedure or function call and the
1888 -- dereference has not been analyzed, return because this procedure
1889 -- will be called again from sem_res Resolve_Actuals. The same can
1890 -- apply in the case of dereference that is the prefix of a selected
1891 -- component, which can be a call given in prefixed form.
1893 if (Is_Actual_Parameter (N)
1894 or else PK = N_Selected_Component)
1895 and then not Analyzed (N)
1896 then
1897 return;
1898 end if;
1900 -- We must allow expanded code to generate a reference to the tag of
1901 -- the designated object (may be either the actual tag, or the stub
1902 -- tag in the case of a remote object).
1904 if PK = N_Selected_Component
1905 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1906 then
1907 return;
1908 end if;
1910 Error_Msg_N
1911 ("invalid dereference of a remote access-to-class-wide value", N);
1912 end if;
1913 end Validate_Remote_Access_To_Class_Wide_Type;
1915 ------------------------------------------
1916 -- Validate_Remote_Type_Type_Conversion --
1917 ------------------------------------------
1919 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1920 S : constant Entity_Id := Etype (N);
1921 E : constant Entity_Id := Etype (Expression (N));
1923 begin
1924 -- This test is required in the case where a conversion appears inside a
1925 -- normal package, it does not necessarily have to be inside an RCI,
1926 -- Remote_Types unit (RM E.2.2(9,12)).
1928 if Is_Remote_Access_To_Subprogram_Type (E)
1929 and then not Is_Remote_Access_To_Subprogram_Type (S)
1930 then
1931 Error_Msg_N
1932 ("incorrect conversion of remote operand to local type", N);
1933 return;
1935 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1936 and then Is_Remote_Access_To_Subprogram_Type (S)
1937 then
1938 Error_Msg_N
1939 ("incorrect conversion of local operand to remote type", N);
1940 return;
1942 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1943 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1944 then
1945 Error_Msg_N
1946 ("incorrect conversion of remote operand to local type", N);
1947 return;
1948 end if;
1950 -- If a local access type is converted into a RACW type, then the
1951 -- current unit has a pointer that may now be exported to another
1952 -- partition.
1954 if Is_Remote_Access_To_Class_Wide_Type (S)
1955 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1956 then
1957 Set_Has_RACW (Current_Sem_Unit);
1958 end if;
1959 end Validate_Remote_Type_Type_Conversion;
1961 -------------------------------
1962 -- Validate_RT_RAT_Component --
1963 -------------------------------
1965 procedure Validate_RT_RAT_Component (N : Node_Id) is
1966 Spec : constant Node_Id := Specification (N);
1967 Name_U : constant Entity_Id := Defining_Entity (Spec);
1968 Typ : Entity_Id;
1969 U_Typ : Entity_Id;
1970 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1972 begin
1973 if not Is_Remote_Types (Name_U) then
1974 return;
1975 end if;
1977 Typ := First_Entity (Name_U);
1978 while Present (Typ) and then Typ /= First_Priv_Ent loop
1979 U_Typ := Underlying_Type (Typ);
1981 if No (U_Typ) then
1982 U_Typ := Typ;
1983 end if;
1985 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1986 if Missing_Read_Write_Attributes (Typ) then
1987 if Is_Non_Remote_Access_Type (Typ) then
1988 Error_Msg_N ("error in non-remote access type", U_Typ);
1989 else
1990 Error_Msg_N
1991 ("error in record type containing a component of a " &
1992 "non-remote access type", U_Typ);
1993 end if;
1995 if Ada_Version >= Ada_05 then
1996 Error_Msg_N
1997 ("\must have visible Read and Write attribute " &
1998 "definition clauses (RM E.2.2(8))", U_Typ);
1999 else
2000 Error_Msg_N
2001 ("\must have Read and Write attribute " &
2002 "definition clauses (RM E.2.2(8))", U_Typ);
2003 end if;
2004 end if;
2005 end if;
2007 Next_Entity (Typ);
2008 end loop;
2009 end Validate_RT_RAT_Component;
2011 -----------------------------------------
2012 -- Validate_SP_Access_Object_Type_Decl --
2013 -----------------------------------------
2015 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2016 Direct_Designated_Type : Entity_Id;
2018 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2019 -- Return true if the protected type designated by T has
2020 -- entry declarations.
2022 ----------------------------
2023 -- Has_Entry_Declarations --
2024 ----------------------------
2026 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2027 Ety : Entity_Id;
2029 begin
2030 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2031 Ety := First_Entity (E);
2032 while Present (Ety) loop
2033 if Ekind (Ety) = E_Entry then
2034 return True;
2035 end if;
2037 Next_Entity (Ety);
2038 end loop;
2039 end if;
2041 return False;
2042 end Has_Entry_Declarations;
2044 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2046 begin
2047 -- We are called from Sem_Ch3.Analyze_Type_Declaration, and the
2048 -- Nkind of the given entity is N_Access_To_Object_Definition.
2050 if not Comes_From_Source (T)
2051 or else not In_Shared_Passive_Unit
2052 or else In_Subprogram_Task_Protected_Unit
2053 then
2054 return;
2055 end if;
2057 -- Check Shared Passive unit. It should not contain the declaration
2058 -- of an access-to-object type whose designated type is a class-wide
2059 -- type, task type or protected type with entry (RM E.2.1(7)).
2061 Direct_Designated_Type := Designated_Type (T);
2063 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2064 Error_Msg_N
2065 ("invalid access-to-class-wide type in shared passive unit", T);
2066 return;
2068 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2069 Error_Msg_N
2070 ("invalid access-to-task type in shared passive unit", T);
2071 return;
2073 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2074 and then Has_Entry_Declarations (Direct_Designated_Type)
2075 then
2076 Error_Msg_N
2077 ("invalid access-to-protected type in shared passive unit", T);
2078 return;
2079 end if;
2080 end Validate_SP_Access_Object_Type_Decl;
2082 ---------------------------------
2083 -- Validate_Static_Object_Name --
2084 ---------------------------------
2086 procedure Validate_Static_Object_Name (N : Node_Id) is
2087 E : Entity_Id;
2089 function Is_Primary (N : Node_Id) return Boolean;
2090 -- Determine whether node is syntactically a primary in an expression
2091 -- This function should probably be somewhere else ???
2092 -- Also it does not do what it says, e.g if N is a binary operator
2093 -- whose parent is a binary operator, Is_Primary returns True ???
2095 ----------------
2096 -- Is_Primary --
2097 ----------------
2099 function Is_Primary (N : Node_Id) return Boolean is
2100 K : constant Node_Kind := Nkind (Parent (N));
2102 begin
2103 case K is
2104 when N_Op | N_Membership_Test =>
2105 return True;
2107 when N_Aggregate
2108 | N_Component_Association
2109 | N_Index_Or_Discriminant_Constraint =>
2110 return True;
2112 when N_Attribute_Reference =>
2113 return Attribute_Name (Parent (N)) /= Name_Address
2114 and then Attribute_Name (Parent (N)) /= Name_Access
2115 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2116 and then
2117 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2119 when N_Indexed_Component =>
2120 return (N /= Prefix (Parent (N))
2121 or else Is_Primary (Parent (N)));
2123 when N_Qualified_Expression | N_Type_Conversion =>
2124 return Is_Primary (Parent (N));
2126 when N_Assignment_Statement | N_Object_Declaration =>
2127 return (N = Expression (Parent (N)));
2129 when N_Selected_Component =>
2130 return Is_Primary (Parent (N));
2132 when others =>
2133 return False;
2134 end case;
2135 end Is_Primary;
2137 -- Start of processing for Validate_Static_Object_Name
2139 begin
2140 if not In_Preelaborated_Unit
2141 or else not Comes_From_Source (N)
2142 or else In_Subprogram_Or_Concurrent_Unit
2143 or else Ekind (Current_Scope) = E_Block
2144 then
2145 return;
2147 -- Filter out cases where primary is default in a component declaration,
2148 -- discriminant specification, or actual in a record type initialization
2149 -- call.
2151 -- Initialization call of internal types
2153 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2155 if Present (Parent (Parent (N)))
2156 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2157 then
2158 return;
2159 end if;
2161 if Nkind (Name (Parent (N))) = N_Identifier
2162 and then not Comes_From_Source (Entity (Name (Parent (N))))
2163 then
2164 return;
2165 end if;
2166 end if;
2168 -- Error if the name is a primary in an expression. The parent must not
2169 -- be an operator, or a selected component or an indexed component that
2170 -- is itself a primary. Entities that are actuals do not need to be
2171 -- checked, because the call itself will be diagnosed.
2173 if Is_Primary (N)
2174 and then (not Inside_A_Generic
2175 or else Present (Enclosing_Generic_Body (N)))
2176 then
2177 if Ekind (Entity (N)) = E_Variable
2178 or else Ekind (Entity (N)) in Formal_Object_Kind
2179 then
2180 Flag_Non_Static_Expr
2181 ("non-static object name in preelaborated unit", N);
2183 -- Give an error for a reference to a nonstatic constant, unless the
2184 -- constant is in another GNAT library unit that is preelaborable.
2186 elsif Ekind (Entity (N)) = E_Constant
2187 and then not Is_Static_Expression (N)
2188 then
2189 E := Entity (N);
2191 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2192 and then
2193 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2194 and then (Is_Preelaborated (Scope (E))
2195 or else Is_Pure (Scope (E))
2196 or else (Present (Renamed_Object (E))
2197 and then
2198 Is_Entity_Name (Renamed_Object (E))
2199 and then
2200 (Is_Preelaborated
2201 (Scope (Renamed_Object (E)))
2202 or else
2203 Is_Pure (Scope
2204 (Renamed_Object (E))))))
2205 then
2206 null;
2208 -- This is the error case
2210 else
2211 -- In GNAT mode, this is just a warning, to allow it to be
2212 -- judiciously turned off. Otherwise it is a real error.
2214 if GNAT_Mode then
2215 Error_Msg_N
2216 ("?non-static constant in preelaborated unit", N);
2217 else
2218 Flag_Non_Static_Expr
2219 ("non-static constant in preelaborated unit", N);
2220 end if;
2221 end if;
2222 end if;
2223 end if;
2224 end Validate_Static_Object_Name;
2226 end Sem_Cat;