2011-05-31 Gabriel Charette <gchare@google.com>
[official-gcc.git] / gcc / ada / sem_cat.adb
blob9311beb99db86eae8aceedb51a14eb32fbc0d998
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;
210 -- Special case: Remote_Types can depend on Preelaborated per
211 -- Ada 2005 AI 0206.
213 elsif Unit_Category = Remote_Types
214 and then Is_Preelaborated (Depended_Entity)
215 then
216 null;
218 -- All other cases, we do have an error
220 else
221 Err := True;
222 end if;
223 end if;
225 -- Here if we have an error
227 if Err then
229 -- These messages are warnings in GNAT mode or if the -gnateP switch
230 -- was set. Otherwise these are real errors for real illegalities.
232 -- The reason we suppress these errors in GNAT mode is that the run-
233 -- time has several instances of violations of the categorization
234 -- errors (e.g. Pure units withing Preelaborate units. All these
235 -- violations are harmless in the cases where we intend them, and
236 -- we suppress the warnings with Warnings (Off). In cases where we
237 -- do not intend the violation, warnings are errors in GNAT mode
238 -- anyway, so we will still get an error.
240 Error_Msg_Warn :=
241 Treat_Categorization_Errors_As_Warnings or GNAT_Mode;
243 -- Don't give error if main unit is not an internal unit, and the
244 -- unit generating the message is an internal unit. This is the
245 -- situation in which such messages would be ignored in any case,
246 -- so it is convenient not to generate them (since it causes
247 -- annoying interference with debugging).
249 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
250 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
251 then
252 return;
254 -- Subunit case
256 elsif Is_Subunit then
257 Error_Msg_NE
258 ("<subunit cannot depend on& " &
259 "(parent has wrong categorization)", N, Depended_Entity);
261 -- Normal unit, not subunit
263 else
264 Error_Msg_NE
265 ("<cannot depend on& " &
266 "(wrong categorization)", N, Depended_Entity);
267 end if;
269 -- Add further explanation for Pure/Preelaborate common cases
271 if Unit_Category = Pure then
272 Error_Msg_NE
273 ("\<pure unit cannot depend on non-pure unit",
274 N, Depended_Entity);
276 elsif Is_Preelaborated (Unit_Entity)
277 and then not Is_Preelaborated (Depended_Entity)
278 and then not Is_Pure (Depended_Entity)
279 then
280 Error_Msg_NE
281 ("\<preelaborated unit cannot depend on "
282 & "non-preelaborated unit",
283 N, Depended_Entity);
284 end if;
285 end if;
286 end Check_Categorization_Dependencies;
288 -----------------------------------
289 -- Check_Non_Static_Default_Expr --
290 -----------------------------------
292 procedure Check_Non_Static_Default_Expr
293 (Type_Def : Node_Id;
294 Obj_Decl : Node_Id)
296 Recdef : Node_Id;
297 Component_Decl : Node_Id;
299 begin
300 if Nkind (Type_Def) = N_Derived_Type_Definition then
301 Recdef := Record_Extension_Part (Type_Def);
303 if No (Recdef) then
304 return;
305 end if;
307 else
308 Recdef := Type_Def;
309 end if;
311 -- Check that component declarations do not involve:
313 -- a. a non-static default expression, where the object is
314 -- declared to be default initialized.
316 -- b. a dynamic Itype (discriminants and constraints)
318 if Null_Present (Recdef) then
319 return;
320 else
321 Component_Decl := First (Component_Items (Component_List (Recdef)));
322 end if;
324 while Present (Component_Decl)
325 and then Nkind (Component_Decl) = N_Component_Declaration
326 loop
327 if Present (Expression (Component_Decl))
328 and then Nkind (Expression (Component_Decl)) /= N_Null
329 and then not Is_Static_Expression (Expression (Component_Decl))
330 then
331 Error_Msg_Sloc := Sloc (Component_Decl);
332 Error_Msg_F
333 ("object in preelaborated unit has non-static default#",
334 Obj_Decl);
336 -- Fix this later ???
338 -- elsif Has_Dynamic_Itype (Component_Decl) then
339 -- Error_Msg_N
340 -- ("dynamic type discriminant," &
341 -- " constraint in preelaborated unit",
342 -- Component_Decl);
343 end if;
345 Next (Component_Decl);
346 end loop;
347 end Check_Non_Static_Default_Expr;
349 -------------------------------------
350 -- Has_Stream_Attribute_Definition --
351 -------------------------------------
353 function Has_Stream_Attribute_Definition
354 (Typ : Entity_Id;
355 Nam : TSS_Name_Type;
356 At_Any_Place : Boolean := False) return Boolean
358 Rep_Item : Node_Id;
359 Full_Type : Entity_Id := Typ;
361 begin
362 -- In the case of a type derived from a private view, any specified
363 -- stream attributes will be attached to the derived type's underlying
364 -- type rather the derived type entity itself (which is itself private).
366 if Is_Private_Type (Typ)
367 and then Is_Derived_Type (Typ)
368 and then Present (Full_View (Typ))
369 then
370 Full_Type := Underlying_Type (Typ);
371 end if;
373 -- We start from the declaration node and then loop until the end of
374 -- the list until we find the requested attribute definition clause.
375 -- In Ada 2005 mode, clauses are ignored if they are not currently
376 -- visible (this is tested using the corresponding Entity, which is
377 -- inserted by the expander at the point where the clause occurs),
378 -- unless At_Any_Place is true.
380 Rep_Item := First_Rep_Item (Full_Type);
381 while Present (Rep_Item) loop
382 if Nkind (Rep_Item) = N_Attribute_Definition_Clause then
383 case Chars (Rep_Item) is
384 when Name_Read =>
385 exit when Nam = TSS_Stream_Read;
387 when Name_Write =>
388 exit when Nam = TSS_Stream_Write;
390 when Name_Input =>
391 exit when Nam = TSS_Stream_Input;
393 when Name_Output =>
394 exit when Nam = TSS_Stream_Output;
396 when others =>
397 null;
399 end case;
400 end if;
402 Next_Rep_Item (Rep_Item);
403 end loop;
405 -- If At_Any_Place is true, return True if the attribute is available
406 -- at any place; if it is false, return True only if the attribute is
407 -- currently visible.
409 return Present (Rep_Item)
410 and then (Ada_Version < Ada_2005
411 or else At_Any_Place
412 or else not Is_Hidden (Entity (Rep_Item)));
413 end Has_Stream_Attribute_Definition;
415 ---------------------------
416 -- In_Preelaborated_Unit --
417 ---------------------------
419 function In_Preelaborated_Unit return Boolean is
420 Unit_Entity : constant Entity_Id := Current_Scope;
421 Unit_Kind : constant Node_Kind :=
422 Nkind (Unit (Cunit (Current_Sem_Unit)));
424 begin
425 -- There are no constraints on body of remote_call_interface or
426 -- remote_types packages.
428 return (Unit_Entity /= Standard_Standard)
429 and then (Is_Preelaborated (Unit_Entity)
430 or else Is_Pure (Unit_Entity)
431 or else Is_Shared_Passive (Unit_Entity)
432 or else
433 ((Is_Remote_Types (Unit_Entity)
434 or else Is_Remote_Call_Interface (Unit_Entity))
435 and then Ekind (Unit_Entity) = E_Package
436 and then Unit_Kind /= N_Package_Body
437 and then not In_Package_Body (Unit_Entity)
438 and then not In_Instance));
439 end In_Preelaborated_Unit;
441 ------------------
442 -- In_Pure_Unit --
443 ------------------
445 function In_Pure_Unit return Boolean is
446 begin
447 return Is_Pure (Current_Scope);
448 end In_Pure_Unit;
450 ------------------------
451 -- In_RCI_Declaration --
452 ------------------------
454 function In_RCI_Declaration (N : Node_Id) return Boolean is
455 Unit_Entity : constant Entity_Id := Current_Scope;
456 Unit_Kind : constant Node_Kind :=
457 Nkind (Unit (Cunit (Current_Sem_Unit)));
459 begin
460 -- There are no restrictions on the private part or body
461 -- of an RCI unit.
463 return Is_Remote_Call_Interface (Unit_Entity)
464 and then Is_Package_Or_Generic_Package (Unit_Entity)
465 and then Unit_Kind /= N_Package_Body
466 and then List_Containing (N) =
467 Visible_Declarations
468 (Specification (Unit_Declaration_Node (Unit_Entity)))
469 and then not In_Package_Body (Unit_Entity)
470 and then not In_Instance;
472 -- What about the case of a nested package in the visible part???
473 -- This case is missed by the List_Containing check above???
474 end In_RCI_Declaration;
476 -----------------------
477 -- In_RT_Declaration --
478 -----------------------
480 function In_RT_Declaration return Boolean is
481 Unit_Entity : constant Entity_Id := Current_Scope;
482 Unit_Kind : constant Node_Kind :=
483 Nkind (Unit (Cunit (Current_Sem_Unit)));
485 begin
486 -- There are no restrictions on the body of a Remote Types unit
488 return Is_Remote_Types (Unit_Entity)
489 and then Is_Package_Or_Generic_Package (Unit_Entity)
490 and then Unit_Kind /= N_Package_Body
491 and then not In_Package_Body (Unit_Entity)
492 and then not In_Instance;
493 end In_RT_Declaration;
495 ----------------------------
496 -- In_Shared_Passive_Unit --
497 ----------------------------
499 function In_Shared_Passive_Unit return Boolean is
500 Unit_Entity : constant Entity_Id := Current_Scope;
502 begin
503 return Is_Shared_Passive (Unit_Entity);
504 end In_Shared_Passive_Unit;
506 ---------------------------------------
507 -- In_Subprogram_Task_Protected_Unit --
508 ---------------------------------------
510 function In_Subprogram_Task_Protected_Unit return Boolean is
511 E : Entity_Id;
513 begin
514 -- The following is to verify that a declaration is inside
515 -- subprogram, generic subprogram, task unit, protected unit.
516 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
518 -- Use scope chain to check successively outer scopes
520 E := Current_Scope;
521 loop
522 if Is_Subprogram (E)
523 or else
524 Is_Generic_Subprogram (E)
525 or else
526 Is_Concurrent_Type (E)
527 then
528 return True;
530 elsif E = Standard_Standard then
531 return False;
532 end if;
534 E := Scope (E);
535 end loop;
536 end In_Subprogram_Task_Protected_Unit;
538 -------------------------------
539 -- Is_Non_Remote_Access_Type --
540 -------------------------------
542 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
543 U_E : constant Entity_Id := Underlying_Type (E);
544 begin
545 if No (U_E) then
547 -- This case arises for the case of a generic formal type, in which
548 -- case E.2.2(8) rules will be enforced at instantiation time.
550 return False;
551 end if;
553 return Is_Access_Type (U_E)
554 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
555 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
556 end Is_Non_Remote_Access_Type;
558 ----------------------------------
559 -- Missing_Read_Write_Attribute --
560 ----------------------------------
562 function Missing_Read_Write_Attributes (E : Entity_Id) return Boolean is
563 Component : Entity_Id;
564 Component_Type : Entity_Id;
565 U_E : constant Entity_Id := Underlying_Type (E);
567 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
568 -- Return True if entity has attribute definition clauses for Read and
569 -- Write attributes that are visible at some place.
571 -------------------------------
572 -- Has_Read_Write_Attributes --
573 -------------------------------
575 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
576 begin
577 return True
578 and then Has_Stream_Attribute_Definition (E,
579 TSS_Stream_Read, At_Any_Place => True)
580 and then Has_Stream_Attribute_Definition (E,
581 TSS_Stream_Write, At_Any_Place => True);
582 end Has_Read_Write_Attributes;
584 -- Start of processing for Missing_Read_Write_Attributes
586 begin
587 if No (U_E) then
588 return False;
590 elsif Has_Read_Write_Attributes (E)
591 or else Has_Read_Write_Attributes (U_E)
592 then
593 return False;
595 elsif Is_Non_Remote_Access_Type (U_E) then
596 return True;
597 end if;
599 if Is_Record_Type (U_E) then
600 Component := First_Entity (U_E);
601 while Present (Component) loop
602 if not Is_Tag (Component) then
603 Component_Type := Etype (Component);
605 if Missing_Read_Write_Attributes (Component_Type) then
606 return True;
607 end if;
608 end if;
610 Next_Entity (Component);
611 end loop;
612 end if;
614 return False;
615 end Missing_Read_Write_Attributes;
617 -------------------------------------
618 -- Set_Categorization_From_Pragmas --
619 -------------------------------------
621 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
622 P : constant Node_Id := Parent (N);
623 S : constant Entity_Id := Current_Scope;
625 procedure Set_Parents (Visibility : Boolean);
626 -- If this is a child instance, the parents are not immediately
627 -- visible during analysis. Make them momentarily visible so that
628 -- the argument of the pragma can be resolved properly, and reset
629 -- afterwards.
631 -----------------
632 -- Set_Parents --
633 -----------------
635 procedure Set_Parents (Visibility : Boolean) is
636 Par : Entity_Id;
637 begin
638 Par := Scope (S);
639 while Present (Par) and then Par /= Standard_Standard loop
640 Set_Is_Immediately_Visible (Par, Visibility);
641 Par := Scope (Par);
642 end loop;
643 end Set_Parents;
645 -- Start of processing for Set_Categorization_From_Pragmas
647 begin
648 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
649 -- The purpose is to set categorization flags before analyzing the
650 -- unit itself, so as to diagnose violations of categorization as
651 -- we process each declaration, even though the pragma appears after
652 -- the unit.
654 if Nkind (P) /= N_Compilation_Unit then
655 return;
656 end if;
658 declare
659 PN : Node_Id;
661 begin
662 if Is_Child_Unit (S)
663 and then Is_Generic_Instance (S)
664 then
665 Set_Parents (True);
666 end if;
668 PN := First (Pragmas_After (Aux_Decls_Node (P)));
669 while Present (PN) loop
671 -- Skip implicit types that may have been introduced by
672 -- previous analysis.
674 if Nkind (PN) = N_Pragma then
675 case Get_Pragma_Id (PN) is
676 when Pragma_All_Calls_Remote |
677 Pragma_Preelaborate |
678 Pragma_Pure |
679 Pragma_Remote_Call_Interface |
680 Pragma_Remote_Types |
681 Pragma_Shared_Passive => Analyze (PN);
682 when others => null;
683 end case;
684 end if;
686 Next (PN);
687 end loop;
689 if Is_Child_Unit (S)
690 and then Is_Generic_Instance (S)
691 then
692 Set_Parents (False);
693 end if;
694 end;
695 end Set_Categorization_From_Pragmas;
697 -----------------------------------
698 -- Set_Categorization_From_Scope --
699 -----------------------------------
701 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
702 Declaration : Node_Id := Empty;
703 Specification : Node_Id := Empty;
705 begin
706 Set_Is_Pure (E,
707 Is_Pure (Scop) and then Is_Library_Level_Entity (E));
709 if not Is_Remote_Call_Interface (E) then
710 if Ekind (E) in Subprogram_Kind then
711 Declaration := Unit_Declaration_Node (E);
713 if Nkind (Declaration) = N_Subprogram_Body
714 or else
715 Nkind (Declaration) = N_Subprogram_Renaming_Declaration
716 then
717 Specification := Corresponding_Spec (Declaration);
718 end if;
719 end if;
721 -- A subprogram body or renaming-as-body is a remote call
722 -- interface if it serves as the completion of a subprogram
723 -- declaration that is a remote call interface.
725 if Nkind (Specification) in N_Entity then
726 Set_Is_Remote_Call_Interface
727 (E, Is_Remote_Call_Interface (Specification));
729 -- A subprogram declaration is a remote call interface when it is
730 -- declared within the visible part of, or declared by, a library
731 -- unit declaration that is a remote call interface.
733 else
734 Set_Is_Remote_Call_Interface
735 (E, Is_Remote_Call_Interface (Scop)
736 and then not (In_Private_Part (Scop)
737 or else In_Package_Body (Scop)));
738 end if;
739 end if;
741 Set_Is_Remote_Types
742 (E, Is_Remote_Types (Scop)
743 and then not (In_Private_Part (Scop)
744 or else In_Package_Body (Scop)));
745 end Set_Categorization_From_Scope;
747 ------------------------------
748 -- Static_Discriminant_Expr --
749 ------------------------------
751 -- We need to accommodate a Why_Not_Static call somehow here ???
753 function Static_Discriminant_Expr (L : List_Id) return Boolean is
754 Discriminant_Spec : Node_Id;
756 begin
757 Discriminant_Spec := First (L);
758 while Present (Discriminant_Spec) loop
759 if Present (Expression (Discriminant_Spec))
760 and then not Is_Static_Expression (Expression (Discriminant_Spec))
761 then
762 return False;
763 end if;
765 Next (Discriminant_Spec);
766 end loop;
768 return True;
769 end Static_Discriminant_Expr;
771 --------------------------------------
772 -- Validate_Access_Type_Declaration --
773 --------------------------------------
775 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
776 Def : constant Node_Id := Type_Definition (N);
778 begin
779 case Nkind (Def) is
781 -- Access to subprogram case
783 when N_Access_To_Subprogram_Definition =>
785 -- A pure library_item must not contain the declaration of a
786 -- named access type, except within a subprogram, generic
787 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
789 -- This test is skipped in Ada 2005 (see AI-366)
791 if Ada_Version < Ada_2005
792 and then Comes_From_Source (T)
793 and then In_Pure_Unit
794 and then not In_Subprogram_Task_Protected_Unit
795 then
796 Error_Msg_N ("named access type not allowed in pure unit", T);
797 end if;
799 -- Access to object case
801 when N_Access_To_Object_Definition =>
802 if Comes_From_Source (T)
803 and then In_Pure_Unit
804 and then not In_Subprogram_Task_Protected_Unit
805 then
806 -- We can't give the message yet, since the type is not frozen
807 -- and in Ada 2005 mode, access types are allowed in pure units
808 -- if the type has no storage pool (see AI-366). So we set a
809 -- flag which will be checked at freeze time.
811 Set_Is_Pure_Unit_Access_Type (T);
812 end if;
814 -- Check for RCI or RT unit type declaration: declaration of an
815 -- access-to-object type is illegal unless it is a general access
816 -- type that designates a class-wide limited private type.
817 -- Note that constraints on the primitive subprograms of the
818 -- designated tagged type are not enforced here but in
819 -- Validate_RACW_Primitives, which is done separately because the
820 -- designated type might not be frozen (and therefore its
821 -- primitive operations might not be completely known) at the
822 -- point of the RACW declaration.
824 Validate_Remote_Access_Object_Type_Declaration (T);
826 -- Check for shared passive unit type declaration. It should
827 -- not contain the declaration of access to class wide type,
828 -- access to task type and access to protected type with entry.
830 Validate_SP_Access_Object_Type_Decl (T);
832 when others =>
833 null;
834 end case;
836 -- Set categorization flag from package on entity as well, to allow
837 -- easy checks later on for required validations of RCI or RT units.
838 -- This is only done for entities that are in the original source.
840 if Comes_From_Source (T)
841 and then not (In_Package_Body (Scope (T))
842 or else In_Private_Part (Scope (T)))
843 then
844 Set_Is_Remote_Call_Interface
845 (T, Is_Remote_Call_Interface (Scope (T)));
846 Set_Is_Remote_Types
847 (T, Is_Remote_Types (Scope (T)));
848 end if;
849 end Validate_Access_Type_Declaration;
851 ----------------------------
852 -- Validate_Ancestor_Part --
853 ----------------------------
855 procedure Validate_Ancestor_Part (N : Node_Id) is
856 A : constant Node_Id := Ancestor_Part (N);
857 T : constant Entity_Id := Entity (A);
859 begin
860 if In_Preelaborated_Unit
861 and then not In_Subprogram_Or_Concurrent_Unit
862 and then (not Inside_A_Generic
863 or else Present (Enclosing_Generic_Body (N)))
864 then
865 -- If the type is private, it must have the Ada 2005 pragma
866 -- Has_Preelaborable_Initialization.
867 -- The check is omitted within predefined units. This is probably
868 -- obsolete code to fix the Ada95 weakness in this area ???
870 if Is_Private_Type (T)
871 and then not Has_Pragma_Preelab_Init (T)
872 and then not Is_Internal_File_Name
873 (Unit_File_Name (Get_Source_Unit (N)))
874 then
875 Error_Msg_N
876 ("private ancestor type not allowed in preelaborated unit", A);
878 elsif Is_Record_Type (T) then
879 if Nkind (Parent (T)) = N_Full_Type_Declaration then
880 Check_Non_Static_Default_Expr
881 (Type_Definition (Parent (T)), A);
882 end if;
883 end if;
884 end if;
885 end Validate_Ancestor_Part;
887 ----------------------------------------
888 -- Validate_Categorization_Dependency --
889 ----------------------------------------
891 procedure Validate_Categorization_Dependency
892 (N : Node_Id;
893 E : Entity_Id)
895 K : constant Node_Kind := Nkind (N);
896 P : Node_Id := Parent (N);
897 U : Entity_Id := E;
898 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
900 begin
901 -- Only validate library units and subunits. For subunits, checks
902 -- concerning withed units apply to the parent compilation unit.
904 if Is_Subunit then
905 P := Parent (P);
906 U := Scope (E);
908 while Present (U)
909 and then not Is_Compilation_Unit (U)
910 and then not Is_Child_Unit (U)
911 loop
912 U := Scope (U);
913 end loop;
914 end if;
916 if Nkind (P) /= N_Compilation_Unit then
917 return;
918 end if;
920 -- Body of RCI unit does not need validation
922 if Is_Remote_Call_Interface (E)
923 and then (Nkind (N) = N_Package_Body
924 or else Nkind (N) = N_Subprogram_Body)
925 then
926 return;
927 end if;
929 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
931 declare
932 Item : Node_Id;
933 Entity_Of_Withed : Entity_Id;
935 begin
936 Item := First (Context_Items (P));
937 while Present (Item) loop
938 if Nkind (Item) = N_With_Clause
939 and then not (Implicit_With (Item)
940 or else Limited_Present (Item))
941 then
942 Entity_Of_Withed := Entity (Name (Item));
943 Check_Categorization_Dependencies
944 (U, Entity_Of_Withed, Item, Is_Subunit);
945 end if;
947 Next (Item);
948 end loop;
949 end;
951 -- Child depends on parent; therefore parent should also be categorized
952 -- and satisfy the dependency hierarchy.
954 -- Check if N is a child spec
956 if (K in N_Generic_Declaration or else
957 K in N_Generic_Instantiation or else
958 K in N_Generic_Renaming_Declaration or else
959 K = N_Package_Declaration or else
960 K = N_Package_Renaming_Declaration or else
961 K = N_Subprogram_Declaration or else
962 K = N_Subprogram_Renaming_Declaration)
963 and then Present (Parent_Spec (N))
964 then
965 Check_Categorization_Dependencies (E, Scope (E), N, False);
967 -- Verify that public child of an RCI library unit must also be an
968 -- RCI library unit (RM E.2.3(15)).
970 if Is_Remote_Call_Interface (Scope (E))
971 and then not Private_Present (P)
972 and then not Is_Remote_Call_Interface (E)
973 then
974 Error_Msg_N ("public child of rci unit must also be rci unit", N);
975 end if;
976 end if;
977 end Validate_Categorization_Dependency;
979 --------------------------------
980 -- Validate_Controlled_Object --
981 --------------------------------
983 procedure Validate_Controlled_Object (E : Entity_Id) is
984 begin
985 -- Don't need this check in Ada 2005 mode, where this is all taken
986 -- care of by the mechanism for Preelaborable Initialization.
988 if Ada_Version >= Ada_2005 then
989 return;
990 end if;
992 -- For now, never apply this check for internal GNAT units, since we
993 -- have a number of cases in the library where we are stuck with objects
994 -- of this type, and the RM requires Preelaborate.
996 -- For similar reasons, we only do this check for source entities, since
997 -- we generate entities of this type in some situations.
999 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1000 -- We have to enforce them for RM compatibility, but we have no trouble
1001 -- accepting these objects and doing the right thing. Note that there is
1002 -- no requirement that Preelaborate not actually generate any code!
1004 if In_Preelaborated_Unit
1005 and then not Debug_Flag_PP
1006 and then Comes_From_Source (E)
1007 and then not
1008 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1009 and then (not Inside_A_Generic
1010 or else Present (Enclosing_Generic_Body (E)))
1011 and then not Is_Protected_Type (Etype (E))
1012 then
1013 Error_Msg_N
1014 ("library level controlled object not allowed in " &
1015 "preelaborated unit", E);
1016 end if;
1017 end Validate_Controlled_Object;
1019 --------------------------------------
1020 -- Validate_Null_Statement_Sequence --
1021 --------------------------------------
1023 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1024 Item : Node_Id;
1026 begin
1027 if In_Preelaborated_Unit then
1028 Item := First (Statements (Handled_Statement_Sequence (N)));
1029 while Present (Item) loop
1030 if Nkind (Item) /= N_Label
1031 and then Nkind (Item) /= N_Null_Statement
1032 then
1033 -- In GNAT mode, this is a warning, allowing the run-time
1034 -- to judiciously bypass this error condition.
1036 Error_Msg_Warn := GNAT_Mode;
1037 Error_Msg_N
1038 ("<statements not allowed in preelaborated unit", Item);
1040 exit;
1041 end if;
1043 Next (Item);
1044 end loop;
1045 end if;
1046 end Validate_Null_Statement_Sequence;
1048 ---------------------------------
1049 -- Validate_Object_Declaration --
1050 ---------------------------------
1052 procedure Validate_Object_Declaration (N : Node_Id) is
1053 Id : constant Entity_Id := Defining_Identifier (N);
1054 E : constant Node_Id := Expression (N);
1055 Odf : constant Node_Id := Object_Definition (N);
1056 T : constant Entity_Id := Etype (Id);
1058 begin
1059 -- Verify that any access to subprogram object does not have in its
1060 -- subprogram profile access type parameters or limited parameters
1061 -- without Read and Write attributes (E.2.3(13)).
1063 Validate_RCI_Subprogram_Declaration (N);
1065 -- Check that if we are in preelaborated elaboration code, then we
1066 -- do not have an instance of a default initialized private, task or
1067 -- protected object declaration which would violate (RM 10.2.1(9)).
1068 -- Note that constants are never default initialized (and the test
1069 -- below also filters out deferred constants). A variable is default
1070 -- initialized if it does *not* have an initialization expression.
1072 -- Filter out cases that are not declaration of a variable from source
1074 if Nkind (N) /= N_Object_Declaration
1075 or else Constant_Present (N)
1076 or else not Comes_From_Source (Id)
1077 then
1078 return;
1079 end if;
1081 -- Exclude generic specs from the checks (this will get rechecked
1082 -- on instantiations).
1084 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1085 return;
1086 end if;
1088 -- Required checks for declaration that is in a preelaborated package
1089 -- and is not within some subprogram.
1091 if In_Preelaborated_Unit
1092 and then not In_Subprogram_Or_Concurrent_Unit
1093 then
1094 -- Check for default initialized variable case. Note that in
1095 -- accordance with (RM B.1(24)) imported objects are not subject to
1096 -- default initialization.
1097 -- If the initialization does not come from source and is an
1098 -- aggregate, it is a static initialization that replaces an
1099 -- implicit call, and must be treated as such.
1101 if Present (E)
1102 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1103 then
1104 null;
1106 elsif Is_Imported (Id) then
1107 null;
1109 else
1110 declare
1111 Ent : Entity_Id := T;
1113 begin
1114 -- An array whose component type is a record with nonstatic
1115 -- default expressions is a violation, so we get the array's
1116 -- component type.
1118 if Is_Array_Type (Ent) then
1119 declare
1120 Comp_Type : Entity_Id;
1122 begin
1123 Comp_Type := Component_Type (Ent);
1124 while Is_Array_Type (Comp_Type) loop
1125 Comp_Type := Component_Type (Comp_Type);
1126 end loop;
1128 Ent := Comp_Type;
1129 end;
1130 end if;
1132 -- Object decl. that is of record type and has no default expr.
1133 -- should check if there is any non-static default expression
1134 -- in component decl. of the record type decl.
1136 if Is_Record_Type (Ent) then
1137 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1138 Check_Non_Static_Default_Expr
1139 (Type_Definition (Parent (Ent)), N);
1141 elsif Nkind (Odf) = N_Subtype_Indication
1142 and then not Is_Array_Type (T)
1143 and then not Is_Private_Type (T)
1144 then
1145 Check_Non_Static_Default_Expr (Type_Definition
1146 (Parent (Entity (Subtype_Mark (Odf)))), N);
1147 end if;
1148 end if;
1150 -- Check for invalid use of private object. Note that Ada 2005
1151 -- AI-161 modifies the rules for Ada 2005, including the use of
1152 -- the new pragma Preelaborable_Initialization.
1154 if Is_Private_Type (Ent)
1155 or else Depends_On_Private (Ent)
1156 then
1157 -- Case where type has preelaborable initialization which
1158 -- means that a pragma Preelaborable_Initialization was
1159 -- given for the private type.
1161 if Has_Preelaborable_Initialization (Ent) then
1163 -- But for the predefined units, we will ignore this
1164 -- status unless we are in Ada 2005 mode since we want
1165 -- Ada 95 compatible behavior, in which the entities
1166 -- marked with this pragma in the predefined library are
1167 -- not treated specially.
1169 if Ada_Version < Ada_2005 then
1170 Error_Msg_N
1171 ("private object not allowed in preelaborated unit",
1173 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1174 end if;
1176 -- Type does not have preelaborable initialization
1178 else
1179 -- We allow this when compiling in GNAT mode to make life
1180 -- easier for some cases where it would otherwise be hard
1181 -- to be exactly valid Ada.
1183 if not GNAT_Mode then
1184 Error_Msg_N
1185 ("private object not allowed in preelaborated unit",
1188 -- Add a message if it would help to provide a pragma
1189 -- Preelaborable_Initialization on the type of the
1190 -- object (which would make it legal in Ada 2005).
1192 -- If the type has no full view (generic type, or
1193 -- previous error), the warning does not apply.
1195 if Is_Private_Type (Ent)
1196 and then Present (Full_View (Ent))
1197 and then
1198 Has_Preelaborable_Initialization (Full_View (Ent))
1199 then
1200 Error_Msg_Sloc := Sloc (Ent);
1202 if Ada_Version >= Ada_2005 then
1203 Error_Msg_NE
1204 ("\would be legal if pragma Preelaborable_" &
1205 "Initialization given for & #", N, Ent);
1206 else
1207 Error_Msg_NE
1208 ("\would be legal in Ada 2005 if pragma " &
1209 "Preelaborable_Initialization given for & #",
1210 N, Ent);
1211 end if;
1212 end if;
1213 end if;
1214 end if;
1216 -- Access to Task or Protected type
1218 elsif Is_Entity_Name (Odf)
1219 and then Present (Etype (Odf))
1220 and then Is_Access_Type (Etype (Odf))
1221 then
1222 Ent := Designated_Type (Etype (Odf));
1224 elsif Is_Entity_Name (Odf) then
1225 Ent := Entity (Odf);
1227 elsif Nkind (Odf) = N_Subtype_Indication then
1228 Ent := Etype (Subtype_Mark (Odf));
1230 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1231 Ent := Component_Type (T);
1232 end if;
1234 if Is_Task_Type (Ent)
1235 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1236 then
1237 Error_Msg_N
1238 ("concurrent object not allowed in preelaborated unit",
1240 return;
1241 end if;
1242 end;
1243 end if;
1245 -- Non-static discriminants not allowed in preelaborated unit.
1246 -- Objects of a controlled type with a user-defined Initialize
1247 -- are forbidden as well.
1249 if Is_Record_Type (Etype (Id)) then
1250 declare
1251 ET : constant Entity_Id := Etype (Id);
1252 EE : constant Entity_Id := Etype (Etype (Id));
1253 PEE : Node_Id;
1255 begin
1256 if Has_Discriminants (ET)
1257 and then Present (EE)
1258 then
1259 PEE := Parent (EE);
1261 if Nkind (PEE) = N_Full_Type_Declaration
1262 and then not Static_Discriminant_Expr
1263 (Discriminant_Specifications (PEE))
1264 then
1265 Error_Msg_N
1266 ("non-static discriminant in preelaborated unit",
1267 PEE);
1268 end if;
1269 end if;
1271 if Has_Overriding_Initialize (ET) then
1272 Error_Msg_NE
1273 ("controlled type& does not have"
1274 & " preelaborable initialization", N, ET);
1275 end if;
1276 end;
1278 end if;
1279 end if;
1281 -- A pure library_item must not contain the declaration of any variable
1282 -- except within a subprogram, generic subprogram, task unit, or
1283 -- protected unit (RM 10.2.1(16)).
1285 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1286 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1288 -- The visible part of an RCI library unit must not contain the
1289 -- declaration of a variable (RM E.1.3(9))
1291 elsif In_RCI_Declaration (N) then
1292 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1294 -- The visible part of a Shared Passive library unit must not contain
1295 -- the declaration of a variable (RM E.2.2(7))
1297 elsif In_RT_Declaration and then not In_Private_Part (Id) then
1298 Error_Msg_N
1299 ("visible variable not allowed in remote types unit", N);
1300 end if;
1302 end Validate_Object_Declaration;
1304 ------------------------------
1305 -- Validate_RACW_Primitives --
1306 ------------------------------
1308 procedure Validate_RACW_Primitives (T : Entity_Id) is
1309 Desig_Type : Entity_Id;
1310 Primitive_Subprograms : Elist_Id;
1311 Subprogram_Elmt : Elmt_Id;
1312 Subprogram : Entity_Id;
1313 Param_Spec : Node_Id;
1314 Param : Entity_Id;
1315 Param_Type : Entity_Id;
1316 Rtyp : Node_Id;
1318 procedure Illegal_RACW (Msg : String; N : Node_Id);
1319 -- Diagnose that T is illegal because of the given reason, associated
1320 -- with the location of node N.
1322 Illegal_RACW_Message_Issued : Boolean := False;
1323 -- Set True once Illegal_RACW has been called
1325 ------------------
1326 -- Illegal_RACW --
1327 ------------------
1329 procedure Illegal_RACW (Msg : String; N : Node_Id) is
1330 begin
1331 if not Illegal_RACW_Message_Issued then
1332 Error_Msg_N
1333 ("illegal remote access to class-wide type&", T);
1334 Illegal_RACW_Message_Issued := True;
1335 end if;
1337 Error_Msg_Sloc := Sloc (N);
1338 Error_Msg_N ("\\" & Msg & " in primitive#", T);
1339 end Illegal_RACW;
1341 -- Start of processing for Validate_RACW_Primitives
1343 begin
1344 Desig_Type := Etype (Designated_Type (T));
1346 -- No action needed for concurrent types
1348 if Is_Concurrent_Type (Desig_Type) then
1349 return;
1350 end if;
1352 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1354 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1355 while Subprogram_Elmt /= No_Elmt loop
1356 Subprogram := Node (Subprogram_Elmt);
1358 if Is_Predefined_Dispatching_Operation (Subprogram)
1359 or else Is_Hidden (Subprogram)
1360 then
1361 goto Next_Subprogram;
1362 end if;
1364 -- Check return type
1366 if Ekind (Subprogram) = E_Function then
1367 Rtyp := Etype (Subprogram);
1369 if Has_Controlling_Result (Subprogram) then
1370 null;
1372 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1373 Illegal_RACW ("anonymous access result", Rtyp);
1375 elsif Is_Limited_Type (Rtyp) then
1376 if No (TSS (Rtyp, TSS_Stream_Read))
1377 or else
1378 No (TSS (Rtyp, TSS_Stream_Write))
1379 then
1380 Illegal_RACW
1381 ("limited return type must have Read and Write attributes",
1382 Parent (Subprogram));
1383 Explain_Limited_Type (Rtyp, Parent (Subprogram));
1385 -- Check that the return type supports external streaming.
1386 -- Note that the language of the standard (E.2.2(14)) does not
1387 -- explicitly mention that case, but it really does not make
1388 -- sense to return a value containing a local access type.
1390 elsif Missing_Read_Write_Attributes (Rtyp)
1391 and then not Error_Posted (Rtyp)
1392 then
1393 Illegal_RACW ("return type containing non-remote access "
1394 & "must have Read and Write attributes",
1395 Parent (Subprogram));
1396 end if;
1398 end if;
1399 end if;
1401 Param := First_Formal (Subprogram);
1402 while Present (Param) loop
1404 -- Now find out if this parameter is a controlling parameter
1406 Param_Spec := Parent (Param);
1407 Param_Type := Etype (Param);
1409 if Is_Controlling_Formal (Param) then
1411 -- It is a controlling parameter, so specific checks below
1412 -- do not apply.
1414 null;
1416 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1417 E_Anonymous_Access_Subprogram_Type)
1418 then
1419 -- From RM E.2.2(14), no anonymous access parameter other than
1420 -- controlling ones may be used (because an anonymous access
1421 -- type never supports external streaming).
1423 Illegal_RACW ("non-controlling access parameter", Param_Spec);
1425 elsif Is_Limited_Type (Param_Type) then
1427 -- Not a controlling parameter, so type must have Read and
1428 -- Write attributes.
1430 if No (TSS (Param_Type, TSS_Stream_Read))
1431 or else
1432 No (TSS (Param_Type, TSS_Stream_Write))
1433 then
1434 Illegal_RACW
1435 ("limited formal must have Read and Write attributes",
1436 Param_Spec);
1437 Explain_Limited_Type (Param_Type, Param_Spec);
1438 end if;
1440 elsif Missing_Read_Write_Attributes (Param_Type)
1441 and then not Error_Posted (Param_Type)
1442 then
1443 Illegal_RACW ("parameter containing non-remote access "
1444 & "must have Read and Write attributes", Param_Spec);
1445 end if;
1447 -- Check next parameter in this subprogram
1449 Next_Formal (Param);
1450 end loop;
1452 <<Next_Subprogram>>
1453 Next_Elmt (Subprogram_Elmt);
1454 end loop;
1455 end Validate_RACW_Primitives;
1457 -------------------------------
1458 -- Validate_RCI_Declarations --
1459 -------------------------------
1461 procedure Validate_RCI_Declarations (P : Entity_Id) is
1462 E : Entity_Id;
1464 begin
1465 E := First_Entity (P);
1466 while Present (E) loop
1467 if Comes_From_Source (E) then
1468 if Is_Limited_Type (E) then
1469 Error_Msg_N
1470 ("limited type not allowed in rci unit", Parent (E));
1471 Explain_Limited_Type (E, Parent (E));
1473 elsif Ekind_In (E, E_Generic_Function,
1474 E_Generic_Package,
1475 E_Generic_Procedure)
1476 then
1477 Error_Msg_N ("generic declaration not allowed in rci unit",
1478 Parent (E));
1480 elsif (Ekind (E) = E_Function
1481 or else Ekind (E) = E_Procedure)
1482 and then Has_Pragma_Inline (E)
1483 then
1484 Error_Msg_N
1485 ("inlined subprogram not allowed in rci unit", Parent (E));
1487 -- Inner packages that are renamings need not be checked. Generic
1488 -- RCI packages are subject to the checks, but entities that come
1489 -- from formal packages are not part of the visible declarations
1490 -- of the package and are not checked.
1492 elsif Ekind (E) = E_Package then
1493 if Present (Renamed_Entity (E)) then
1494 null;
1496 elsif Ekind (P) /= E_Generic_Package
1497 or else List_Containing (Unit_Declaration_Node (E)) /=
1498 Generic_Formal_Declarations
1499 (Unit_Declaration_Node (P))
1500 then
1501 Validate_RCI_Declarations (E);
1502 end if;
1503 end if;
1504 end if;
1506 Next_Entity (E);
1507 end loop;
1508 end Validate_RCI_Declarations;
1510 -----------------------------------------
1511 -- Validate_RCI_Subprogram_Declaration --
1512 -----------------------------------------
1514 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1515 K : constant Node_Kind := Nkind (N);
1516 Profile : List_Id;
1517 Id : Node_Id;
1518 Param_Spec : Node_Id;
1519 Param_Type : Entity_Id;
1520 Base_Param_Type : Entity_Id;
1521 Base_Under_Type : Entity_Id;
1522 Type_Decl : Node_Id;
1523 Error_Node : Node_Id := N;
1525 begin
1526 -- This procedure enforces rules on subprogram and access to subprogram
1527 -- declarations in RCI units. These rules do not apply to expander
1528 -- generated routines, which are not remote subprograms. It is called:
1530 -- 1. from Analyze_Subprogram_Declaration.
1531 -- 2. from Validate_Object_Declaration (access to subprogram).
1533 if not (Comes_From_Source (N) and then In_RCI_Declaration (N)) then
1534 return;
1535 end if;
1537 if K = N_Subprogram_Declaration then
1538 Profile := Parameter_Specifications (Specification (N));
1540 else pragma Assert (K = N_Object_Declaration);
1542 -- The above assertion is dubious, the visible declarations of an
1543 -- RCI unit never contain an object declaration, this should be an
1544 -- ACCESS-to-object declaration???
1546 Id := Defining_Identifier (N);
1548 if Nkind (Id) = N_Defining_Identifier
1549 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1550 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1551 then
1552 Profile :=
1553 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1554 else
1555 return;
1556 end if;
1557 end if;
1559 -- Iterate through the parameter specification list, checking that
1560 -- no access parameter and no limited type parameter in the list.
1561 -- RM E.2.3(14).
1563 if Present (Profile) then
1564 Param_Spec := First (Profile);
1565 while Present (Param_Spec) loop
1566 Param_Type := Etype (Defining_Identifier (Param_Spec));
1567 Type_Decl := Parent (Param_Type);
1569 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1570 if K = N_Subprogram_Declaration then
1571 Error_Node := Param_Spec;
1572 end if;
1574 -- Report error only if declaration is in source program
1576 if Comes_From_Source
1577 (Defining_Entity (Specification (N)))
1578 then
1579 Error_Msg_N
1580 ("subprogram in 'R'C'I unit cannot have access parameter",
1581 Error_Node);
1582 end if;
1584 -- For a limited private type parameter, we check only the private
1585 -- declaration and ignore full type declaration, unless this is
1586 -- the only declaration for the type, e.g., as a limited record.
1588 elsif Is_Limited_Type (Param_Type)
1589 and then (Nkind (Type_Decl) = N_Private_Type_Declaration
1590 or else
1591 (Nkind (Type_Decl) = N_Full_Type_Declaration
1592 and then not (Has_Private_Declaration (Param_Type))
1593 and then Comes_From_Source (N)))
1594 then
1595 -- A limited parameter is legal only if user-specified Read and
1596 -- Write attributes exist for it. Second part of RM E.2.3 (14).
1598 if No (Full_View (Param_Type))
1599 and then Ekind (Param_Type) /= E_Record_Type
1600 then
1601 -- Type does not have completion yet, so if declared in
1602 -- the current RCI scope it is illegal, and will be flagged
1603 -- subsequently.
1605 return;
1606 end if;
1608 -- In Ada 95 the rules permit using a limited type that has
1609 -- user-specified Read and Write attributes that are specified
1610 -- in the private part of the package, whereas Ada 2005
1611 -- (AI-240) revises this to require the attributes to be
1612 -- "available" (implying that the attribute clauses must be
1613 -- visible to the RCI client). The Ada 95 rules violate the
1614 -- contract model for privacy, but we support both semantics
1615 -- for now for compatibility (note that ACATS test BXE2009
1616 -- checks a case that conforms to the Ada 95 rules but is
1617 -- illegal in Ada 2005). In the Ada 2005 case we check for the
1618 -- possibilities of visible TSS stream subprograms or explicit
1619 -- stream attribute definitions because the TSS subprograms
1620 -- can be hidden in the private part while the attribute
1621 -- definitions are still be available from the visible part.
1623 Base_Param_Type := Base_Type (Param_Type);
1624 Base_Under_Type := Base_Type (Underlying_Type
1625 (Base_Param_Type));
1627 if (Ada_Version < Ada_2005
1628 and then
1629 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1630 or else
1631 No (TSS (Base_Param_Type, TSS_Stream_Write)))
1632 and then
1633 (No (TSS (Base_Under_Type, TSS_Stream_Read))
1634 or else
1635 No (TSS (Base_Under_Type, TSS_Stream_Write))))
1636 or else
1637 (Ada_Version >= Ada_2005
1638 and then
1639 (No (TSS (Base_Param_Type, TSS_Stream_Read))
1640 or else
1641 No (TSS (Base_Param_Type, TSS_Stream_Write))
1642 or else
1643 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Read))
1644 or else
1645 Is_Hidden (TSS (Base_Param_Type, TSS_Stream_Write)))
1646 and then
1647 (not Has_Stream_Attribute_Definition
1648 (Base_Param_Type, TSS_Stream_Read)
1649 or else
1650 not Has_Stream_Attribute_Definition
1651 (Base_Param_Type, TSS_Stream_Write)))
1652 then
1653 if K = N_Subprogram_Declaration then
1654 Error_Node := Param_Spec;
1655 end if;
1657 if Ada_Version >= Ada_2005 then
1658 Error_Msg_N
1659 ("limited parameter in 'R'C'I unit "
1660 & "must have visible read/write attributes ",
1661 Error_Node);
1662 else
1663 Error_Msg_N
1664 ("limited parameter in 'R'C'I unit "
1665 & "must have read/write attributes ",
1666 Error_Node);
1667 end if;
1668 Explain_Limited_Type (Param_Type, Error_Node);
1669 end if;
1671 -- In Ada 95, any non-remote access type (or any type with a
1672 -- component of a non-remote access type) that is visible in an
1673 -- RCI unit comes from a Remote_Types or Remote_Call_Interface
1674 -- unit, and thus is already guaranteed to support external
1675 -- streaming. However in Ada 2005 we have to account for the case
1676 -- of named access types from declared pure units as well, which
1677 -- may or may not support external streaming, and so we need to
1678 -- perform a specific check for E.2.3(14/2) here.
1680 -- Note that if the declaration of the type itself is illegal, we
1681 -- do not perform this check since it might be a cascaded error.
1683 else
1684 if K = N_Subprogram_Declaration then
1685 Error_Node := Param_Spec;
1686 end if;
1688 if Missing_Read_Write_Attributes (Param_Type)
1689 and then not Error_Posted (Param_Type)
1690 then
1691 Error_Msg_N
1692 ("parameter containing non-remote access in 'R'C'I "
1693 & "subprogram must have visible "
1694 & "Read and Write attributes", Error_Node);
1695 end if;
1696 end if;
1697 Next (Param_Spec);
1698 end loop;
1700 -- No check on return type???
1701 end if;
1702 end Validate_RCI_Subprogram_Declaration;
1704 ----------------------------------------------------
1705 -- Validate_Remote_Access_Object_Type_Declaration --
1706 ----------------------------------------------------
1708 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1710 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean;
1711 -- True if tagged type E is a valid candidate as the root type of the
1712 -- designated type for a RACW, i.e. a tagged limited private type, or a
1713 -- limited interface type, or a private extension of such a type.
1715 ---------------------------------
1716 -- Is_Valid_Remote_Object_Type --
1717 ---------------------------------
1719 function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is
1720 P : constant Node_Id := Parent (E);
1722 begin
1723 pragma Assert (Is_Tagged_Type (E));
1725 -- Simple case: a limited private type
1727 if Nkind (P) = N_Private_Type_Declaration
1728 and then Is_Limited_Record (E)
1729 then
1730 return True;
1732 -- A limited interface is not currently a legal ancestor for the
1733 -- designated type of an RACW type, because a type that implements
1734 -- such an interface need not be limited. However, the ARG seems to
1735 -- incline towards allowing an access to classwide limited interface
1736 -- type as a remote access type, as resolved in AI05-060. But note
1737 -- that the expansion circuitry for RACWs that designate classwide
1738 -- interfaces is not complete yet.
1740 elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then
1741 return True;
1743 -- A generic tagged limited type is a valid candidate. Limitedness
1744 -- will be checked again on the actual at instantiation point.
1746 elsif Nkind (P) = N_Formal_Type_Declaration
1747 and then Ekind (E) = E_Record_Type_With_Private
1748 and then Is_Generic_Type (E)
1749 and then Is_Limited_Record (E)
1750 then
1751 return True;
1753 -- A private extension declaration is a valid candidate if its parent
1754 -- type is.
1756 elsif Nkind (P) = N_Private_Extension_Declaration then
1757 return Is_Valid_Remote_Object_Type (Etype (E));
1759 else
1760 return False;
1761 end if;
1762 end Is_Valid_Remote_Object_Type;
1764 -- Local variables
1766 Direct_Designated_Type : Entity_Id;
1767 Desig_Type : Entity_Id;
1769 -- Start of processing for Validate_Remote_Access_Object_Type_Declaration
1771 begin
1772 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1773 -- the given node is N_Access_To_Object_Definition.
1775 if not Comes_From_Source (T)
1776 or else (not In_RCI_Declaration (Parent (T))
1777 and then not In_RT_Declaration)
1778 then
1779 return;
1780 end if;
1782 -- An access definition in the private part of a Remote Types package
1783 -- may be legal if it has user-defined Read and Write attributes. This
1784 -- will be checked at the end of the package spec processing.
1786 if In_RT_Declaration and then In_Private_Part (Scope (T)) then
1787 return;
1788 end if;
1790 -- Check RCI or RT unit type declaration. It may not contain the
1791 -- declaration of an access-to-object type unless it is a general access
1792 -- type that designates a class-wide limited private type or subtype.
1793 -- There are also constraints on the primitive subprograms of the
1794 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1796 if Ekind (T) /= E_General_Access_Type
1797 or else not Is_Class_Wide_Type (Designated_Type (T))
1798 then
1799 if In_RCI_Declaration (Parent (T)) then
1800 Error_Msg_N
1801 ("error in access type in Remote_Call_Interface unit", T);
1802 else
1803 Error_Msg_N
1804 ("error in access type in Remote_Types unit", T);
1805 end if;
1807 Error_Msg_N ("\must be general access to class-wide type", T);
1808 return;
1809 end if;
1811 Direct_Designated_Type := Designated_Type (T);
1812 Desig_Type := Etype (Direct_Designated_Type);
1814 -- Why is the check below not in
1815 -- Validate_Remote_Access_To_Class_Wide_Type???
1817 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1818 Error_Msg_N
1819 ("error in designated type of remote access to class-wide type", T);
1820 Error_Msg_N
1821 ("\must be tagged limited private or private extension", T);
1822 return;
1823 end if;
1824 end Validate_Remote_Access_Object_Type_Declaration;
1826 -----------------------------------------------
1827 -- Validate_Remote_Access_To_Class_Wide_Type --
1828 -----------------------------------------------
1830 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1831 K : constant Node_Kind := Nkind (N);
1832 PK : constant Node_Kind := Nkind (Parent (N));
1833 E : Entity_Id;
1835 begin
1836 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1837 -- of class-wide limited private types.
1839 -- Storage_Pool and Storage_Size are not defined for such types
1841 -- The expected type of allocator must not be such a type.
1843 -- The actual parameter of generic instantiation must not be such a
1844 -- type if the formal parameter is of an access type.
1846 -- On entry, there are five cases
1848 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1849 -- either Storage_Pool or Storage_Size.
1851 -- 2. called from exp_ch4 Expand_N_Allocator
1853 -- 3. called from sem_ch12 Analyze_Associations
1855 -- 4. called from sem_ch4 Analyze_Explicit_Dereference
1857 -- 5. called from sem_res Resolve_Actuals
1859 if K = N_Attribute_Reference then
1860 E := Etype (Prefix (N));
1862 if Is_Remote_Access_To_Class_Wide_Type (E) then
1863 Error_Msg_N ("incorrect attribute of remote operand", N);
1864 return;
1865 end if;
1867 elsif K = N_Allocator then
1868 E := Etype (N);
1870 if Is_Remote_Access_To_Class_Wide_Type (E) then
1871 Error_Msg_N ("incorrect expected remote type of allocator", N);
1872 return;
1873 end if;
1875 elsif K in N_Has_Entity then
1876 E := Entity (N);
1878 if Is_Remote_Access_To_Class_Wide_Type (E) then
1879 Error_Msg_N ("incorrect remote type generic actual", N);
1880 return;
1881 end if;
1883 -- This subprogram also enforces the checks in E.2.2(13). A value of
1884 -- such type must not be dereferenced unless as controlling operand of
1885 -- a dispatching call. Explicit dereferences not coming from source are
1886 -- exempted from this checking because the expander produces them in
1887 -- some cases (such as for tag checks on dispatching calls with multiple
1888 -- controlling operands). However we do check in the case of an implicit
1889 -- dereference that is expanded to an explicit dereference (hence the
1890 -- test of whether Original_Node (N) comes from source).
1892 elsif K = N_Explicit_Dereference
1893 and then Comes_From_Source (Original_Node (N))
1894 then
1895 E := Etype (Prefix (N));
1897 -- If the class-wide type is not a remote one, the restrictions
1898 -- do not apply.
1900 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1901 return;
1902 end if;
1904 -- If we have a true dereference that comes from source and that
1905 -- is a controlling argument for a dispatching call, accept it.
1907 if Is_Actual_Parameter (N)
1908 and then Is_Controlling_Actual (N)
1909 then
1910 return;
1911 end if;
1913 -- If we are just within a procedure or function call and the
1914 -- dereference has not been analyzed, return because this procedure
1915 -- will be called again from sem_res Resolve_Actuals. The same can
1916 -- apply in the case of dereference that is the prefix of a selected
1917 -- component, which can be a call given in prefixed form.
1919 if (Is_Actual_Parameter (N)
1920 or else PK = N_Selected_Component)
1921 and then not Analyzed (N)
1922 then
1923 return;
1924 end if;
1926 -- We must allow expanded code to generate a reference to the tag of
1927 -- the designated object (may be either the actual tag, or the stub
1928 -- tag in the case of a remote object).
1930 if PK = N_Selected_Component
1931 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1932 then
1933 return;
1934 end if;
1936 Error_Msg_N
1937 ("invalid dereference of a remote access-to-class-wide value", N);
1938 end if;
1939 end Validate_Remote_Access_To_Class_Wide_Type;
1941 ------------------------------------------
1942 -- Validate_Remote_Type_Type_Conversion --
1943 ------------------------------------------
1945 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1946 S : constant Entity_Id := Etype (N);
1947 E : constant Entity_Id := Etype (Expression (N));
1949 begin
1950 -- This test is required in the case where a conversion appears inside a
1951 -- normal package, it does not necessarily have to be inside an RCI,
1952 -- Remote_Types unit (RM E.2.2(9,12)).
1954 if Is_Remote_Access_To_Subprogram_Type (E)
1955 and then not Is_Remote_Access_To_Subprogram_Type (S)
1956 then
1957 Error_Msg_N
1958 ("incorrect conversion of remote operand to local type", N);
1959 return;
1961 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1962 and then Is_Remote_Access_To_Subprogram_Type (S)
1963 then
1964 Error_Msg_N
1965 ("incorrect conversion of local operand to remote type", N);
1966 return;
1968 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1969 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1970 then
1971 Error_Msg_N
1972 ("incorrect conversion of remote operand to local type", N);
1973 return;
1974 end if;
1976 -- If a local access type is converted into a RACW type, then the
1977 -- current unit has a pointer that may now be exported to another
1978 -- partition.
1980 if Is_Remote_Access_To_Class_Wide_Type (S)
1981 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1982 then
1983 Set_Has_RACW (Current_Sem_Unit);
1984 end if;
1985 end Validate_Remote_Type_Type_Conversion;
1987 -------------------------------
1988 -- Validate_RT_RAT_Component --
1989 -------------------------------
1991 procedure Validate_RT_RAT_Component (N : Node_Id) is
1992 Spec : constant Node_Id := Specification (N);
1993 Name_U : constant Entity_Id := Defining_Entity (Spec);
1994 Typ : Entity_Id;
1995 U_Typ : Entity_Id;
1996 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1998 begin
1999 if not Is_Remote_Types (Name_U) then
2000 return;
2001 end if;
2003 Typ := First_Entity (Name_U);
2004 while Present (Typ) and then Typ /= First_Priv_Ent loop
2005 U_Typ := Underlying_Type (Typ);
2007 if No (U_Typ) then
2008 U_Typ := Typ;
2009 end if;
2011 if Comes_From_Source (Typ) and then Is_Type (Typ) then
2012 if Missing_Read_Write_Attributes (Typ) then
2013 if Is_Non_Remote_Access_Type (Typ) then
2014 Error_Msg_N ("error in non-remote access type", U_Typ);
2015 else
2016 Error_Msg_N
2017 ("error in record type containing a component of a " &
2018 "non-remote access type", U_Typ);
2019 end if;
2021 if Ada_Version >= Ada_2005 then
2022 Error_Msg_N
2023 ("\must have visible Read and Write attribute " &
2024 "definition clauses (RM E.2.2(8))", U_Typ);
2025 else
2026 Error_Msg_N
2027 ("\must have Read and Write attribute " &
2028 "definition clauses (RM E.2.2(8))", U_Typ);
2029 end if;
2030 end if;
2031 end if;
2033 Next_Entity (Typ);
2034 end loop;
2035 end Validate_RT_RAT_Component;
2037 -----------------------------------------
2038 -- Validate_SP_Access_Object_Type_Decl --
2039 -----------------------------------------
2041 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2042 Direct_Designated_Type : Entity_Id;
2044 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2045 -- Return true if the protected type designated by T has
2046 -- entry declarations.
2048 ----------------------------
2049 -- Has_Entry_Declarations --
2050 ----------------------------
2052 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2053 Ety : Entity_Id;
2055 begin
2056 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2057 Ety := First_Entity (E);
2058 while Present (Ety) loop
2059 if Ekind (Ety) = E_Entry then
2060 return True;
2061 end if;
2063 Next_Entity (Ety);
2064 end loop;
2065 end if;
2067 return False;
2068 end Has_Entry_Declarations;
2070 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2072 begin
2073 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2074 -- Nkind of the given entity is N_Access_To_Object_Definition.
2076 if not Comes_From_Source (T)
2077 or else not In_Shared_Passive_Unit
2078 or else In_Subprogram_Task_Protected_Unit
2079 then
2080 return;
2081 end if;
2083 -- Check Shared Passive unit. It should not contain the declaration
2084 -- of an access-to-object type whose designated type is a class-wide
2085 -- type, task type or protected type with entry (RM E.2.1(7)).
2087 Direct_Designated_Type := Designated_Type (T);
2089 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2090 Error_Msg_N
2091 ("invalid access-to-class-wide type in shared passive unit", T);
2092 return;
2094 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2095 Error_Msg_N
2096 ("invalid access-to-task type in shared passive unit", T);
2097 return;
2099 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2100 and then Has_Entry_Declarations (Direct_Designated_Type)
2101 then
2102 Error_Msg_N
2103 ("invalid access-to-protected type in shared passive unit", T);
2104 return;
2105 end if;
2106 end Validate_SP_Access_Object_Type_Decl;
2108 ---------------------------------
2109 -- Validate_Static_Object_Name --
2110 ---------------------------------
2112 procedure Validate_Static_Object_Name (N : Node_Id) is
2113 E : Entity_Id;
2115 function Is_Primary (N : Node_Id) return Boolean;
2116 -- Determine whether node is syntactically a primary in an expression
2117 -- This function should probably be somewhere else ???
2118 -- Also it does not do what it says, e.g if N is a binary operator
2119 -- whose parent is a binary operator, Is_Primary returns True ???
2121 ----------------
2122 -- Is_Primary --
2123 ----------------
2125 function Is_Primary (N : Node_Id) return Boolean is
2126 K : constant Node_Kind := Nkind (Parent (N));
2128 begin
2129 case K is
2130 when N_Op | N_Membership_Test =>
2131 return True;
2133 when N_Aggregate
2134 | N_Component_Association
2135 | N_Index_Or_Discriminant_Constraint =>
2136 return True;
2138 when N_Attribute_Reference =>
2139 return Attribute_Name (Parent (N)) /= Name_Address
2140 and then Attribute_Name (Parent (N)) /= Name_Access
2141 and then Attribute_Name (Parent (N)) /= Name_Unchecked_Access
2142 and then
2143 Attribute_Name (Parent (N)) /= Name_Unrestricted_Access;
2145 when N_Indexed_Component =>
2146 return (N /= Prefix (Parent (N))
2147 or else Is_Primary (Parent (N)));
2149 when N_Qualified_Expression | N_Type_Conversion =>
2150 return Is_Primary (Parent (N));
2152 when N_Assignment_Statement | N_Object_Declaration =>
2153 return (N = Expression (Parent (N)));
2155 when N_Selected_Component =>
2156 return Is_Primary (Parent (N));
2158 when others =>
2159 return False;
2160 end case;
2161 end Is_Primary;
2163 -- Start of processing for Validate_Static_Object_Name
2165 begin
2166 if not In_Preelaborated_Unit
2167 or else not Comes_From_Source (N)
2168 or else In_Subprogram_Or_Concurrent_Unit
2169 or else Ekind (Current_Scope) = E_Block
2170 then
2171 return;
2173 -- Filter out cases where primary is default in a component declaration,
2174 -- discriminant specification, or actual in a record type initialization
2175 -- call.
2177 -- Initialization call of internal types
2179 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2181 if Present (Parent (Parent (N)))
2182 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2183 then
2184 return;
2185 end if;
2187 if Nkind (Name (Parent (N))) = N_Identifier
2188 and then not Comes_From_Source (Entity (Name (Parent (N))))
2189 then
2190 return;
2191 end if;
2192 end if;
2194 -- Error if the name is a primary in an expression. The parent must not
2195 -- be an operator, or a selected component or an indexed component that
2196 -- is itself a primary. Entities that are actuals do not need to be
2197 -- checked, because the call itself will be diagnosed.
2199 if Is_Primary (N)
2200 and then (not Inside_A_Generic
2201 or else Present (Enclosing_Generic_Body (N)))
2202 then
2203 if Ekind (Entity (N)) = E_Variable
2204 or else Ekind (Entity (N)) in Formal_Object_Kind
2205 then
2206 Flag_Non_Static_Expr
2207 ("non-static object name in preelaborated unit", N);
2209 -- Give an error for a reference to a nonstatic constant, unless the
2210 -- constant is in another GNAT library unit that is preelaborable.
2212 elsif Ekind (Entity (N)) = E_Constant
2213 and then not Is_Static_Expression (N)
2214 then
2215 E := Entity (N);
2217 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2218 and then
2219 Enclosing_Lib_Unit_Node (N) /= Enclosing_Lib_Unit_Node (E)
2220 and then (Is_Preelaborated (Scope (E))
2221 or else Is_Pure (Scope (E))
2222 or else (Present (Renamed_Object (E))
2223 and then
2224 Is_Entity_Name (Renamed_Object (E))
2225 and then
2226 (Is_Preelaborated
2227 (Scope (Renamed_Object (E)))
2228 or else
2229 Is_Pure (Scope
2230 (Renamed_Object (E))))))
2231 then
2232 null;
2234 -- This is the error case
2236 else
2237 -- In GNAT mode, this is just a warning, to allow it to be
2238 -- judiciously turned off. Otherwise it is a real error.
2240 if GNAT_Mode then
2241 Error_Msg_N
2242 ("?non-static constant in preelaborated unit", N);
2243 else
2244 Flag_Non_Static_Expr
2245 ("non-static constant in preelaborated unit", N);
2246 end if;
2247 end if;
2248 end if;
2249 end if;
2250 end Validate_Static_Object_Name;
2252 end Sem_Cat;