Daily bump.
[official-gcc.git] / gcc / ada / sem_cat.adb
blob6270b7c7aa55bff911ea8fb3746e7a51129fe51e
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-2021, 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 Einfo.Entities; use Einfo.Entities;
30 with Einfo.Utils; use Einfo.Utils;
31 with Elists; use Elists;
32 with Errout; use Errout;
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_Attr; use Sem_Attr;
39 with Sem_Aux; use Sem_Aux;
40 with Sem_Dist; use Sem_Dist;
41 with Sem_Eval; use Sem_Eval;
42 with Sem_Util; use Sem_Util;
43 with Sinfo; use Sinfo;
44 with Sinfo.Nodes; use Sinfo.Nodes;
45 with Sinfo.Utils; use Sinfo.Utils;
46 with Snames; use Snames;
47 with Stand; use Stand;
49 package body Sem_Cat is
51 -----------------------
52 -- Local Subprograms --
53 -----------------------
55 procedure Check_Categorization_Dependencies
56 (Unit_Entity : Entity_Id;
57 Depended_Entity : Entity_Id;
58 Info_Node : Node_Id;
59 Is_Subunit : Boolean);
60 -- This procedure checks that the categorization of a lib unit and that
61 -- of the depended unit satisfy dependency restrictions.
62 -- The depended_entity can be the entity in a with_clause item, in which
63 -- case Info_Node denotes that item. The depended_entity can also be the
64 -- parent unit of a child unit, in which case Info_Node is the declaration
65 -- of the child unit. The error message is posted on Info_Node, and is
66 -- specialized if Is_Subunit is true.
68 procedure Check_Non_Static_Default_Expr
69 (Type_Def : Node_Id;
70 Obj_Decl : Node_Id);
71 -- Iterate through the component list of a record definition, check
72 -- that no component is declared with a nonstatic default value.
73 -- If a nonstatic default exists, report an error on Obj_Decl.
75 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
76 -- Return True if entity has attribute definition clauses for Read and
77 -- Write attributes that are visible at some place.
79 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
80 -- Returns true if the entity is a type whose full view is a non-remote
81 -- access type, for the purpose of enforcing E.2.2(8) rules.
83 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean;
84 -- Return true if Typ or the type of any of its subcomponents is a non
85 -- remote access type and doesn't have user-defined stream attributes.
87 function No_External_Streaming (E : Entity_Id) return Boolean;
88 -- Return True if the entity or one of its subcomponents does not support
89 -- external streaming.
91 function In_RCI_Declaration return Boolean;
92 function In_RT_Declaration return Boolean;
93 -- Determine if current scope is within the declaration of a Remote Call
94 -- Interface or Remote Types unit, for semantic checking purposes.
96 function In_Package_Declaration return Boolean;
97 -- Shared supporting routine for In_RCI_Declaration and In_RT_Declaration
99 function In_Shared_Passive_Unit return Boolean;
100 -- Determines if current scope is within a Shared Passive compilation unit
102 function Static_Discriminant_Expr (L : List_Id) return Boolean;
103 -- Iterate through the list of discriminants to check if any of them
104 -- contains non-static default expression, which is a violation in
105 -- a preelaborated library unit.
107 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
108 -- Check validity of declaration if RCI or RT unit. It should not contain
109 -- the declaration of an access-to-object type unless it is a general
110 -- access type that designates a class-wide limited private type. There are
111 -- also constraints about the primitive subprograms of the class-wide type.
112 -- RM E.2 (9, 13, 14)
114 procedure Validate_RACW_Primitive
115 (Subp : Entity_Id;
116 RACW : Entity_Id);
117 -- Check legality of the declaration of primitive Subp of the designated
118 -- type of the given RACW type.
120 ---------------------------------------
121 -- Check_Categorization_Dependencies --
122 ---------------------------------------
124 procedure Check_Categorization_Dependencies
125 (Unit_Entity : Entity_Id;
126 Depended_Entity : Entity_Id;
127 Info_Node : Node_Id;
128 Is_Subunit : Boolean)
130 N : constant Node_Id := Info_Node;
131 Err : Boolean;
133 -- Here we define an enumeration type to represent categorization types,
134 -- ordered so that a unit with a given categorization can only WITH
135 -- units with lower or equal categorization type.
137 type Categorization is
138 (Pure,
139 Shared_Passive,
140 Remote_Types,
141 Remote_Call_Interface,
142 Normal);
144 function Get_Categorization (E : Entity_Id) return Categorization;
145 -- Check categorization flags from entity, and return in the form
146 -- of the lowest value of the Categorization type that applies to E.
148 ------------------------
149 -- Get_Categorization --
150 ------------------------
152 function Get_Categorization (E : Entity_Id) return Categorization is
153 begin
154 -- Get the lowest categorization that corresponds to E. Note that
155 -- nothing prevents several (different) categorization pragmas
156 -- to apply to the same library unit, in which case the unit has
157 -- all associated categories, so we need to be careful here to
158 -- check pragmas in proper Categorization order in order to
159 -- return the lowest applicable value.
161 -- Ignore Pure specification if set by pragma Pure_Function
163 if Is_Pure (E)
164 and then not
165 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
166 then
167 return Pure;
169 elsif Is_Shared_Passive (E) then
170 return Shared_Passive;
172 elsif Is_Remote_Types (E) then
173 return Remote_Types;
175 elsif Is_Remote_Call_Interface (E) then
176 return Remote_Call_Interface;
178 else
179 return Normal;
180 end if;
181 end Get_Categorization;
183 Unit_Category : Categorization;
184 With_Category : Categorization;
186 -- Start of processing for Check_Categorization_Dependencies
188 begin
189 -- Intrinsic subprograms are preelaborated, so do not impose any
190 -- categorization dependencies. Also, ignore categorization
191 -- dependencies when compilation switch -gnatdu is used.
193 if Is_Intrinsic_Subprogram (Depended_Entity) or else Debug_Flag_U then
194 return;
195 end if;
197 -- First check 10.2.1 (11/1) rules on preelaborate packages
199 if Is_Preelaborated (Unit_Entity)
200 and then not Is_Preelaborated (Depended_Entity)
201 and then not Is_Pure (Depended_Entity)
202 then
203 Err := True;
204 else
205 Err := False;
206 end if;
208 -- Check categorization rules of RM E.2(5)
210 Unit_Category := Get_Categorization (Unit_Entity);
211 With_Category := Get_Categorization (Depended_Entity);
213 if With_Category > Unit_Category then
215 -- Special case: Remote_Types and Remote_Call_Interface are allowed
216 -- to WITH anything in the package body, per (RM E.2(5)).
218 if (Unit_Category = Remote_Types
219 or else Unit_Category = Remote_Call_Interface)
220 and then In_Package_Body (Unit_Entity)
221 then
222 null;
224 -- Special case: Remote_Types and Remote_Call_Interface declarations
225 -- can depend on a preelaborated unit via a private with_clause, per
226 -- AI05-0206.
228 elsif (Unit_Category = Remote_Types
229 or else
230 Unit_Category = Remote_Call_Interface)
231 and then Nkind (N) = N_With_Clause
232 and then Private_Present (N)
233 and then Is_Preelaborated (Depended_Entity)
234 then
235 null;
237 -- All other cases, we do have an error
239 else
240 Err := True;
241 end if;
242 end if;
244 -- Here if we have an error
246 if Err then
248 -- These messages are warnings in GNAT mode or if the -gnateP switch
249 -- was set. Otherwise these are real errors for real illegalities.
251 -- The reason we suppress these errors in GNAT mode is that the run-
252 -- time has several instances of violations of the categorization
253 -- errors (e.g. Pure units withing Preelaborate units. All these
254 -- violations are harmless in the cases where we intend them, and
255 -- we suppress the warnings with Warnings (Off). In cases where we
256 -- do not intend the violation, warnings are errors in GNAT mode
257 -- anyway, so we will still get an error.
259 Error_Msg_Warn :=
260 Treat_Categorization_Errors_As_Warnings or GNAT_Mode;
262 -- Don't give error if main unit is not an internal unit, and the
263 -- unit generating the message is an internal unit. This is the
264 -- situation in which such messages would be ignored in any case,
265 -- so it is convenient not to generate them (since it causes
266 -- annoying interference with debugging).
268 if Is_Internal_Unit (Current_Sem_Unit)
269 and then not Is_Internal_Unit (Main_Unit)
270 then
271 return;
273 -- Dependence of Remote_Types or Remote_Call_Interface declaration
274 -- on a preelaborated unit with a normal with_clause.
276 elsif (Unit_Category = Remote_Types
277 or else
278 Unit_Category = Remote_Call_Interface)
279 and then Is_Preelaborated (Depended_Entity)
280 then
281 Error_Msg_NE
282 ("<<must use private with clause for preelaborated unit&",
283 N, Depended_Entity);
285 -- Subunit case
287 elsif Is_Subunit then
288 Error_Msg_NE
289 ("<subunit cannot depend on& " &
290 "(parent has wrong categorization)", N, Depended_Entity);
292 -- Normal unit, not subunit
294 else
295 Error_Msg_NE
296 ("<<cannot depend on& " &
297 "(wrong categorization)", N, Depended_Entity);
298 end if;
300 -- Add further explanation for Pure/Preelaborate common cases
302 if Unit_Category = Pure then
303 Error_Msg_N
304 ("\<<pure unit cannot depend on non-pure unit", N);
306 elsif Is_Preelaborated (Unit_Entity)
307 and then not Is_Preelaborated (Depended_Entity)
308 and then not Is_Pure (Depended_Entity)
309 then
310 Error_Msg_N
311 ("\<<preelaborated unit cannot depend on "
312 & "non-preelaborated unit", N);
313 end if;
314 end if;
315 end Check_Categorization_Dependencies;
317 -----------------------------------
318 -- Check_Non_Static_Default_Expr --
319 -----------------------------------
321 procedure Check_Non_Static_Default_Expr
322 (Type_Def : Node_Id;
323 Obj_Decl : Node_Id)
325 Recdef : Node_Id;
326 Component_Decl : Node_Id;
328 begin
329 if Nkind (Type_Def) = N_Derived_Type_Definition then
330 Recdef := Record_Extension_Part (Type_Def);
332 if No (Recdef) then
333 return;
334 end if;
336 else
337 Recdef := Type_Def;
338 end if;
340 -- Check that component declarations do not involve:
342 -- a. a non-static default expression, where the object is
343 -- declared to be default initialized.
345 -- b. a dynamic Itype (discriminants and constraints)
347 if Null_Present (Recdef) then
348 return;
349 else
350 Component_Decl := First (Component_Items (Component_List (Recdef)));
351 end if;
353 while Present (Component_Decl)
354 and then Nkind (Component_Decl) = N_Component_Declaration
355 loop
356 if Present (Expression (Component_Decl))
357 and then Nkind (Expression (Component_Decl)) /= N_Null
358 and then not Is_OK_Static_Expression (Expression (Component_Decl))
360 -- If we're in a predefined unit, we can put whatever we like in a
361 -- preelaborated package, and in fact in some cases it's necessary
362 -- to bend the rules. Ada.Containers.Bounded_Hashed_Maps contains
363 -- some code that would not be considered preelaborable in user
364 -- code, for example.
366 and then not In_Predefined_Unit (Component_Decl)
367 then
368 Error_Msg_Sloc := Sloc (Component_Decl);
369 Error_Msg_F
370 ("object in preelaborated unit has non-static default#",
371 Obj_Decl);
373 -- Fix this later ???
375 -- elsif Has_Dynamic_Itype (Component_Decl) then
376 -- Error_Msg_N
377 -- ("dynamic type discriminant," &
378 -- " constraint in preelaborated unit",
379 -- Component_Decl);
380 end if;
382 Next (Component_Decl);
383 end loop;
384 end Check_Non_Static_Default_Expr;
386 ---------------------------
387 -- Has_Non_Remote_Access --
388 ---------------------------
390 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean is
391 Component : Entity_Id;
392 Comp_Type : Entity_Id;
393 U_Typ : constant Entity_Id := Underlying_Type (Typ);
395 begin
396 if No (U_Typ) then
397 return False;
399 elsif Has_Read_Write_Attributes (Typ)
400 or else Has_Read_Write_Attributes (U_Typ)
401 then
402 return False;
404 elsif Is_Non_Remote_Access_Type (U_Typ) then
405 return True;
406 end if;
408 if Is_Record_Type (U_Typ) then
409 Component := First_Entity (U_Typ);
410 while Present (Component) loop
411 if not Is_Tag (Component) then
412 Comp_Type := Etype (Component);
414 if Has_Non_Remote_Access (Comp_Type) then
415 return True;
416 end if;
417 end if;
419 Next_Entity (Component);
420 end loop;
422 elsif Is_Array_Type (U_Typ) then
423 return Has_Non_Remote_Access (Component_Type (U_Typ));
425 end if;
427 return False;
428 end Has_Non_Remote_Access;
430 -------------------------------
431 -- Has_Read_Write_Attributes --
432 -------------------------------
434 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
435 begin
436 return True
437 and then Has_Stream_Attribute_Definition
438 (E, TSS_Stream_Read, At_Any_Place => True)
439 and then Has_Stream_Attribute_Definition
440 (E, TSS_Stream_Write, At_Any_Place => True);
441 end Has_Read_Write_Attributes;
443 -------------------------------------
444 -- Has_Stream_Attribute_Definition --
445 -------------------------------------
447 function Has_Stream_Attribute_Definition
448 (Typ : Entity_Id;
449 Nam : TSS_Name_Type;
450 At_Any_Place : Boolean := False) return Boolean
452 Rep_Item : Node_Id;
454 Real_Rep : Node_Id;
455 -- The stream operation may be specified by an attribute definition
456 -- clause in the source, or by an aspect that generates such an
457 -- attribute definition. For an aspect, the generated attribute
458 -- definition may be placed at the freeze point of the full view of
459 -- the type, but the aspect specification makes the operation visible
460 -- to a client wherever the partial view is visible.
462 begin
463 -- We start from the declaration node and then loop until the end of
464 -- the list until we find the requested attribute definition clause.
465 -- In Ada 2005 mode, clauses are ignored if they are not currently
466 -- visible (this is tested using the corresponding Entity, which is
467 -- inserted by the expander at the point where the clause occurs),
468 -- unless At_Any_Place is true.
470 Rep_Item := First_Rep_Item (Typ);
471 while Present (Rep_Item) loop
472 Real_Rep := Rep_Item;
474 -- If the representation item is an aspect specification, retrieve
475 -- the corresponding pragma or attribute definition.
477 if Nkind (Rep_Item) = N_Aspect_Specification then
478 Real_Rep := Aspect_Rep_Item (Rep_Item);
479 end if;
481 if Nkind (Real_Rep) = N_Attribute_Definition_Clause then
482 case Chars (Real_Rep) is
483 when Name_Read =>
484 exit when Nam = TSS_Stream_Read;
486 when Name_Write =>
487 exit when Nam = TSS_Stream_Write;
489 when Name_Input =>
490 exit when Nam = TSS_Stream_Input;
492 when Name_Output =>
493 exit when Nam = TSS_Stream_Output;
495 when others =>
496 null;
497 end case;
498 end if;
500 Next_Rep_Item (Rep_Item);
501 end loop;
503 -- If not found, and the type is derived from a private view, check
504 -- for a stream attribute inherited from parent. Any specified stream
505 -- attributes will be attached to the derived type's underlying type
506 -- rather the derived type entity itself (which is itself private).
508 if No (Rep_Item)
509 and then Is_Private_Type (Typ)
510 and then Is_Derived_Type (Typ)
511 and then Present (Full_View (Typ))
512 then
513 return Has_Stream_Attribute_Definition
514 (Underlying_Type (Typ), Nam, At_Any_Place);
516 -- Otherwise, if At_Any_Place is true, return True if the attribute is
517 -- available at any place; if it is false, return True only if the
518 -- attribute is currently visible.
520 else
521 return Present (Rep_Item)
522 and then (Ada_Version < Ada_2005
523 or else At_Any_Place
524 or else not Is_Hidden (Entity (Rep_Item)));
525 end if;
526 end Has_Stream_Attribute_Definition;
528 ----------------------------
529 -- In_Package_Declaration --
530 ----------------------------
532 function In_Package_Declaration return Boolean is
533 Unit_Kind : constant Node_Kind :=
534 Nkind (Unit (Cunit (Current_Sem_Unit)));
536 begin
537 -- There are no restrictions on the body of an RCI or RT unit
539 return Is_Package_Or_Generic_Package (Current_Scope)
540 and then Unit_Kind /= N_Package_Body
541 and then not In_Package_Body (Current_Scope)
542 and then not In_Instance;
543 end In_Package_Declaration;
545 ---------------------------
546 -- In_Preelaborated_Unit --
547 ---------------------------
549 function In_Preelaborated_Unit return Boolean is
550 Unit_Entity : Entity_Id := Current_Scope;
551 Unit_Kind : constant Node_Kind :=
552 Nkind (Unit (Cunit (Current_Sem_Unit)));
554 begin
555 -- If evaluating actuals for a child unit instantiation, then ignore
556 -- the preelaboration status of the parent; use the child instead.
558 if Is_Compilation_Unit (Unit_Entity)
559 and then Unit_Kind in N_Generic_Instantiation
560 and then not In_Same_Source_Unit (Unit_Entity,
561 Cunit (Current_Sem_Unit))
562 then
563 Unit_Entity := Cunit_Entity (Current_Sem_Unit);
564 end if;
566 -- There are no constraints on the body of Remote_Call_Interface or
567 -- Remote_Types packages.
569 return (Unit_Entity /= Standard_Standard)
570 and then (Is_Preelaborated (Unit_Entity)
571 or else Is_Pure (Unit_Entity)
572 or else Is_Shared_Passive (Unit_Entity)
573 or else
574 ((Is_Remote_Types (Unit_Entity)
575 or else Is_Remote_Call_Interface (Unit_Entity))
576 and then Ekind (Unit_Entity) = E_Package
577 and then Unit_Kind /= N_Package_Body
578 and then not In_Package_Body (Unit_Entity)
579 and then not In_Instance));
580 end In_Preelaborated_Unit;
582 ------------------
583 -- In_Pure_Unit --
584 ------------------
586 function In_Pure_Unit return Boolean is
587 begin
588 return Is_Pure (Current_Scope);
589 end In_Pure_Unit;
591 ------------------------
592 -- In_RCI_Declaration --
593 ------------------------
595 function In_RCI_Declaration return Boolean is
596 begin
597 return Is_Remote_Call_Interface (Current_Scope)
598 and then In_Package_Declaration;
599 end In_RCI_Declaration;
601 -----------------------
602 -- In_RT_Declaration --
603 -----------------------
605 function In_RT_Declaration return Boolean is
606 begin
607 return Is_Remote_Types (Current_Scope) and then In_Package_Declaration;
608 end In_RT_Declaration;
610 ----------------------------
611 -- In_Shared_Passive_Unit --
612 ----------------------------
614 function In_Shared_Passive_Unit return Boolean is
615 Unit_Entity : constant Entity_Id := Current_Scope;
617 begin
618 return Is_Shared_Passive (Unit_Entity);
619 end In_Shared_Passive_Unit;
621 ---------------------------------------
622 -- In_Subprogram_Task_Protected_Unit --
623 ---------------------------------------
625 function In_Subprogram_Task_Protected_Unit return Boolean is
626 E : Entity_Id;
628 begin
629 -- The following is to verify that a declaration is inside
630 -- subprogram, generic subprogram, task unit, protected unit.
631 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
633 -- Use scope chain to check successively outer scopes
635 E := Current_Scope;
636 loop
637 if Is_Subprogram_Or_Generic_Subprogram (E)
638 or else
639 Is_Concurrent_Type (E)
640 then
641 return True;
643 elsif E = Standard_Standard then
644 return False;
645 end if;
647 E := Scope (E);
648 end loop;
649 end In_Subprogram_Task_Protected_Unit;
651 -------------------------------
652 -- Is_Non_Remote_Access_Type --
653 -------------------------------
655 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
656 U_E : constant Entity_Id := Underlying_Type (Base_Type (E));
657 -- Use full view of base type to handle subtypes properly.
659 begin
660 if No (U_E) then
662 -- This case arises for the case of a generic formal type, in which
663 -- case E.2.2(8) rules will be enforced at instantiation time.
665 return False;
666 end if;
668 return Is_Access_Type (U_E)
669 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
670 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
671 end Is_Non_Remote_Access_Type;
673 ---------------------------
674 -- No_External_Streaming --
675 ---------------------------
677 function No_External_Streaming (E : Entity_Id) return Boolean is
678 U_E : constant Entity_Id := Underlying_Type (E);
680 begin
681 if No (U_E) then
682 return False;
684 elsif Has_Read_Write_Attributes (E) then
686 -- Note: availability of stream attributes is tested on E, not U_E.
687 -- There may be stream attributes defined on U_E that are not visible
688 -- at the place where support of external streaming is tested.
690 return False;
692 elsif Has_Non_Remote_Access (U_E) then
693 return True;
694 end if;
696 return Is_Limited_Type (E);
697 end No_External_Streaming;
699 -------------------------------------
700 -- Set_Categorization_From_Pragmas --
701 -------------------------------------
703 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
704 P : constant Node_Id := Parent (N);
706 procedure Make_Parents_Visible_And_Process_Pragmas (Par : Entity_Id);
707 -- Parents might not be immediately visible during analysis. Make
708 -- them momentarily visible so that the argument of the pragma can
709 -- be resolved properly, process pragmas and restore the previous
710 -- visibility.
712 procedure Process_Categorization_Pragmas;
713 -- Process categorization pragmas, if any
715 ------------------------------------
716 -- Process_Categorization_Pragmas --
717 ------------------------------------
719 procedure Process_Categorization_Pragmas is
720 PN : Node_Id;
722 begin
723 PN := First (Pragmas_After (Aux_Decls_Node (P)));
724 while Present (PN) loop
726 -- Skip implicit types that may have been introduced by
727 -- previous analysis.
729 if Nkind (PN) = N_Pragma then
730 case Get_Pragma_Id (PN) is
731 when Pragma_All_Calls_Remote
732 | Pragma_Preelaborate
733 | Pragma_Pure
734 | Pragma_Remote_Call_Interface
735 | Pragma_Remote_Types
736 | Pragma_Shared_Passive
738 Analyze (PN);
740 when others =>
741 null;
742 end case;
743 end if;
745 Next (PN);
746 end loop;
747 end Process_Categorization_Pragmas;
749 ----------------------------------------------
750 -- Make_Parents_Visible_And_Process_Pragmas --
751 ----------------------------------------------
753 procedure Make_Parents_Visible_And_Process_Pragmas (Par : Entity_Id) is
754 begin
755 -- When we reached the Standard scope, then just process pragmas
757 if Par = Standard_Standard then
758 Process_Categorization_Pragmas;
760 -- Otherwise make the current scope momentarily visible, recurse
761 -- into its enclosing scope, and restore the visibility. This is
762 -- required for child units that are instances of generic parents.
764 else
765 declare
766 Save_Is_Immediately_Visible : constant Boolean :=
767 Is_Immediately_Visible (Par);
768 begin
769 Set_Is_Immediately_Visible (Par);
770 Make_Parents_Visible_And_Process_Pragmas (Scope (Par));
771 Set_Is_Immediately_Visible (Par, Save_Is_Immediately_Visible);
772 end;
773 end if;
774 end Make_Parents_Visible_And_Process_Pragmas;
776 -- Start of processing for Set_Categorization_From_Pragmas
778 begin
779 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
780 -- The purpose is to set categorization flags before analyzing the
781 -- unit itself, so as to diagnose violations of categorization as
782 -- we process each declaration, even though the pragma appears after
783 -- the unit.
785 if Nkind (P) /= N_Compilation_Unit then
786 return;
787 end if;
789 Make_Parents_Visible_And_Process_Pragmas (Scope (Current_Scope));
790 end Set_Categorization_From_Pragmas;
792 -----------------------------------
793 -- Set_Categorization_From_Scope --
794 -----------------------------------
796 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
797 Declaration : Node_Id := Empty;
798 Specification : Node_Id := Empty;
800 begin
801 -- Do not modify the purity of an internally generated entity if it has
802 -- been explicitly marked as pure for optimization purposes.
804 if not Has_Pragma_Pure_Function (E) then
805 Set_Is_Pure
806 (E, Is_Pure (Scop) and then Is_Library_Level_Entity (E));
807 end if;
809 if not Is_Remote_Call_Interface (E) then
810 if Is_Subprogram (E) then
811 Declaration := Unit_Declaration_Node (E);
813 if Nkind (Declaration) in
814 N_Subprogram_Body | N_Subprogram_Renaming_Declaration
815 then
816 Specification := Corresponding_Spec (Declaration);
817 end if;
818 end if;
820 -- A subprogram body or renaming-as-body is a remote call interface
821 -- if it serves as the completion of a subprogram declaration that
822 -- is a remote call interface.
824 if Nkind (Specification) in N_Entity then
825 Set_Is_Remote_Call_Interface
826 (E, Is_Remote_Call_Interface (Specification));
828 -- A subprogram declaration is a remote call interface when it is
829 -- declared within the visible part of, or declared by, a library
830 -- unit declaration that is a remote call interface.
832 else
833 Set_Is_Remote_Call_Interface
834 (E, Is_Remote_Call_Interface (Scop)
835 and then not (In_Private_Part (Scop)
836 or else In_Package_Body (Scop)));
837 end if;
838 end if;
840 Set_Is_Remote_Types
841 (E, Is_Remote_Types (Scop)
842 and then not (In_Private_Part (Scop)
843 or else In_Package_Body (Scop)));
844 end Set_Categorization_From_Scope;
846 ------------------------------
847 -- Static_Discriminant_Expr --
848 ------------------------------
850 -- We need to accommodate a Why_Not_Static call somehow here ???
852 function Static_Discriminant_Expr (L : List_Id) return Boolean is
853 Discriminant_Spec : Node_Id;
855 begin
856 Discriminant_Spec := First (L);
857 while Present (Discriminant_Spec) loop
858 if Present (Expression (Discriminant_Spec))
859 and then
860 not Is_OK_Static_Expression (Expression (Discriminant_Spec))
861 then
862 return False;
863 end if;
865 Next (Discriminant_Spec);
866 end loop;
868 return True;
869 end Static_Discriminant_Expr;
871 --------------------------------------
872 -- Validate_Access_Type_Declaration --
873 --------------------------------------
875 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
876 Def : constant Node_Id := Type_Definition (N);
878 begin
879 case Nkind (Def) is
881 -- Access to subprogram case
883 when N_Access_To_Subprogram_Definition =>
885 -- A pure library_item must not contain the declaration of a
886 -- named access type, except within a subprogram, generic
887 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
889 -- This test is skipped in Ada 2005 (see AI-366)
891 if Ada_Version < Ada_2005
892 and then Comes_From_Source (T)
893 and then In_Pure_Unit
894 and then not In_Subprogram_Task_Protected_Unit
895 then
896 Error_Msg_N ("named access type not allowed in pure unit", T);
897 end if;
899 -- Access to object case
901 when N_Access_To_Object_Definition =>
902 if Comes_From_Source (T)
903 and then In_Pure_Unit
904 and then not In_Subprogram_Task_Protected_Unit
905 then
906 -- We can't give the message yet, since the type is not frozen
907 -- and in Ada 2005 mode, access types are allowed in pure units
908 -- if the type has no storage pool (see AI-366). So we set a
909 -- flag which will be checked at freeze time.
911 Set_Is_Pure_Unit_Access_Type (T);
912 end if;
914 -- Check for RCI or RT unit type declaration: declaration of an
915 -- access-to-object type is illegal unless it is a general access
916 -- type that designates a class-wide limited private type.
917 -- Note that constraints on the primitive subprograms of the
918 -- designated tagged type are not enforced here but in
919 -- Validate_RACW_Primitives, which is done separately because the
920 -- designated type might not be frozen (and therefore its
921 -- primitive operations might not be completely known) at the
922 -- point of the RACW declaration.
924 Validate_Remote_Access_Object_Type_Declaration (T);
926 -- Check for shared passive unit type declaration. It should
927 -- not contain the declaration of access to class wide type,
928 -- access to task type and access to protected type with entry.
930 Validate_SP_Access_Object_Type_Decl (T);
932 when others =>
933 null;
934 end case;
936 -- Set categorization flag from package on entity as well, to allow
937 -- easy checks later on for required validations of RCI or RT units.
938 -- This is only done for entities that are in the original source.
940 if Comes_From_Source (T)
941 and then not (In_Package_Body (Scope (T))
942 or else In_Private_Part (Scope (T)))
943 then
944 Set_Is_Remote_Call_Interface
945 (T, Is_Remote_Call_Interface (Scope (T)));
946 Set_Is_Remote_Types
947 (T, Is_Remote_Types (Scope (T)));
948 end if;
949 end Validate_Access_Type_Declaration;
951 ----------------------------
952 -- Validate_Ancestor_Part --
953 ----------------------------
955 procedure Validate_Ancestor_Part (N : Node_Id) is
956 A : constant Node_Id := Ancestor_Part (N);
957 T : constant Entity_Id := Entity (A);
959 begin
960 if In_Preelaborated_Unit
961 and then not In_Subprogram_Or_Concurrent_Unit
962 and then (not Inside_A_Generic
963 or else Present (Enclosing_Generic_Body (N)))
964 then
965 -- If the type is private, it must have the Ada 2005 pragma
966 -- Has_Preelaborable_Initialization.
968 -- The check is omitted within predefined units. This is probably
969 -- obsolete code to fix the Ada 95 weakness in this area ???
971 if Is_Private_Type (T)
972 and then not Has_Pragma_Preelab_Init (T)
973 and then not In_Internal_Unit (N)
974 then
975 Error_Msg_N
976 ("private ancestor type not allowed in preelaborated unit", A);
978 elsif Is_Record_Type (T) then
979 if Nkind (Parent (T)) = N_Full_Type_Declaration then
980 Check_Non_Static_Default_Expr
981 (Type_Definition (Parent (T)), A);
982 end if;
983 end if;
984 end if;
985 end Validate_Ancestor_Part;
987 ----------------------------------------
988 -- Validate_Categorization_Dependency --
989 ----------------------------------------
991 procedure Validate_Categorization_Dependency
992 (N : Node_Id;
993 E : Entity_Id)
995 K : constant Node_Kind := Nkind (N);
996 P : Node_Id := Parent (N);
997 U : Entity_Id := E;
998 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
1000 begin
1001 -- Only validate library units and subunits. For subunits, checks
1002 -- concerning withed units apply to the parent compilation unit.
1004 if Is_Subunit then
1005 P := Parent (P);
1006 U := Scope (E);
1008 while Present (U)
1009 and then not Is_Compilation_Unit (U)
1010 and then not Is_Child_Unit (U)
1011 loop
1012 U := Scope (U);
1013 end loop;
1014 end if;
1016 if Nkind (P) /= N_Compilation_Unit then
1017 return;
1018 end if;
1020 -- Body of RCI unit does not need validation
1022 if Is_Remote_Call_Interface (E)
1023 and then Nkind (N) in N_Package_Body | N_Subprogram_Body
1024 then
1025 return;
1026 end if;
1028 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
1030 declare
1031 Item : Node_Id;
1032 Entity_Of_Withed : Entity_Id;
1034 begin
1035 Item := First (Context_Items (P));
1036 while Present (Item) loop
1037 if Nkind (Item) = N_With_Clause
1038 and then
1039 not (Implicit_With (Item)
1040 or else Limited_Present (Item)
1042 -- Skip if error already posted on the WITH clause (in
1043 -- which case the Name attribute may be invalid). In
1044 -- particular, this fixes the problem of hanging in the
1045 -- presence of a WITH clause on a child that is an
1046 -- illegal generic instantiation.
1048 or else Error_Posted (Item))
1049 and then
1050 not (Try_Semantics
1052 -- Skip processing malformed trees
1054 and then Nkind (Name (Item)) not in N_Has_Entity)
1055 then
1056 Entity_Of_Withed := Entity (Name (Item));
1057 Check_Categorization_Dependencies
1058 (U, Entity_Of_Withed, Item, Is_Subunit);
1059 end if;
1061 Next (Item);
1062 end loop;
1063 end;
1065 -- Child depends on parent; therefore parent should also be categorized
1066 -- and satisfy the dependency hierarchy.
1068 -- Check if N is a child spec
1070 if (K in N_Generic_Declaration or else
1071 K in N_Generic_Instantiation or else
1072 K in N_Generic_Renaming_Declaration or else
1073 K = N_Package_Declaration or else
1074 K = N_Package_Renaming_Declaration or else
1075 K = N_Subprogram_Declaration or else
1076 K = N_Subprogram_Renaming_Declaration)
1077 and then Present (Parent_Spec (N))
1078 then
1079 Check_Categorization_Dependencies (E, Scope (E), N, False);
1081 -- Verify that public child of an RCI library unit must also be an
1082 -- RCI library unit (RM E.2.3(15)).
1084 if Is_Remote_Call_Interface (Scope (E))
1085 and then not Private_Present (P)
1086 and then not Is_Remote_Call_Interface (E)
1087 then
1088 Error_Msg_N
1089 ("public child of 'R'C'I unit must also be 'R'C'I unit", N);
1090 end if;
1091 end if;
1092 end Validate_Categorization_Dependency;
1094 --------------------------------
1095 -- Validate_Controlled_Object --
1096 --------------------------------
1098 procedure Validate_Controlled_Object (E : Entity_Id) is
1099 begin
1100 -- Don't need this check in Ada 2005 mode, where this is all taken
1101 -- care of by the mechanism for Preelaborable Initialization.
1103 if Ada_Version >= Ada_2005 then
1104 return;
1105 end if;
1107 -- For now, never apply this check for internal GNAT units, since we
1108 -- have a number of cases in the library where we are stuck with objects
1109 -- of this type, and the RM requires Preelaborate.
1111 -- For similar reasons, we only do this check for source entities, since
1112 -- we generate entities of this type in some situations.
1114 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1115 -- We have to enforce them for RM compatibility, but we have no trouble
1116 -- accepting these objects and doing the right thing. Note that there is
1117 -- no requirement that Preelaborate not actually generate any code.
1119 if In_Preelaborated_Unit
1120 and then not Debug_Flag_PP
1121 and then Comes_From_Source (E)
1122 and then not In_Internal_Unit (E)
1123 and then (not Inside_A_Generic
1124 or else Present (Enclosing_Generic_Body (E)))
1125 and then not Is_Protected_Type (Etype (E))
1126 then
1127 Error_Msg_N
1128 ("library level controlled object not allowed in " &
1129 "preelaborated unit", E);
1130 end if;
1131 end Validate_Controlled_Object;
1133 --------------------------------------
1134 -- Validate_Null_Statement_Sequence --
1135 --------------------------------------
1137 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1138 Item : Node_Id;
1140 begin
1141 if In_Preelaborated_Unit then
1142 Item := First (Statements (Handled_Statement_Sequence (N)));
1143 while Present (Item) loop
1144 if Nkind (Item) /= N_Label
1145 and then Nkind (Item) /= N_Null_Statement
1146 then
1147 -- In GNAT mode, this is a warning, allowing the run-time
1148 -- to judiciously bypass this error condition.
1150 Error_Msg_Warn := GNAT_Mode;
1151 Error_Msg_N
1152 ("<<statements not allowed in preelaborated unit", Item);
1154 exit;
1155 end if;
1157 Next (Item);
1158 end loop;
1159 end if;
1160 end Validate_Null_Statement_Sequence;
1162 ---------------------------------
1163 -- Validate_Object_Declaration --
1164 ---------------------------------
1166 procedure Validate_Object_Declaration (N : Node_Id) is
1167 Id : constant Entity_Id := Defining_Identifier (N);
1168 E : constant Node_Id := Expression (N);
1169 Odf : constant Node_Id := Object_Definition (N);
1170 T : constant Entity_Id := Etype (Id);
1172 begin
1173 -- Verify that any access to subprogram object does not have in its
1174 -- subprogram profile access type parameters or limited parameters
1175 -- without Read and Write attributes (E.2.3(13)).
1177 Validate_RCI_Subprogram_Declaration (N);
1179 -- Check that if we are in preelaborated elaboration code, then we
1180 -- do not have an instance of a default initialized private, task or
1181 -- protected object declaration which would violate (RM 10.2.1(9)).
1182 -- Note that constants are never default initialized (and the test
1183 -- below also filters out deferred constants). A variable is default
1184 -- initialized if it does *not* have an initialization expression.
1186 -- Filter out cases that are not declaration of a variable from source
1188 if Nkind (N) /= N_Object_Declaration
1189 or else Constant_Present (N)
1190 or else not Comes_From_Source (Id)
1191 then
1192 return;
1193 end if;
1195 -- Exclude generic specs from the checks (this will get rechecked
1196 -- on instantiations).
1198 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1199 return;
1200 end if;
1202 -- Required checks for declaration that is in a preelaborated package
1203 -- and is not within some subprogram.
1205 if In_Preelaborated_Unit
1206 and then not In_Subprogram_Or_Concurrent_Unit
1207 then
1208 -- Check for default initialized variable case. Note that in
1209 -- accordance with (RM B.1(24)) imported objects are not subject to
1210 -- default initialization.
1211 -- If the initialization does not come from source and is an
1212 -- aggregate, it is a static initialization that replaces an
1213 -- implicit call, and must be treated as such.
1215 if Present (E)
1216 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1217 then
1218 null;
1220 elsif Is_Imported (Id) then
1221 null;
1223 else
1224 declare
1225 Ent : Entity_Id := T;
1227 begin
1228 -- An array whose component type is a record with nonstatic
1229 -- default expressions is a violation, so we get the array's
1230 -- component type.
1232 if Is_Array_Type (Ent) then
1233 declare
1234 Comp_Type : Entity_Id;
1236 begin
1237 Comp_Type := Component_Type (Ent);
1238 while Is_Array_Type (Comp_Type) loop
1239 Comp_Type := Component_Type (Comp_Type);
1240 end loop;
1242 Ent := Comp_Type;
1243 end;
1244 end if;
1246 -- Object decl. that is of record type and has no default expr.
1247 -- should check if there is any non-static default expression
1248 -- in component decl. of the record type decl.
1250 if Is_Record_Type (Ent) then
1251 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1252 Check_Non_Static_Default_Expr
1253 (Type_Definition (Parent (Ent)), N);
1255 elsif Nkind (Odf) = N_Subtype_Indication
1256 and then not Is_Array_Type (T)
1257 and then not Is_Private_Type (T)
1258 then
1259 Check_Non_Static_Default_Expr (Type_Definition
1260 (Parent (Entity (Subtype_Mark (Odf)))), N);
1261 end if;
1262 end if;
1264 -- Check for invalid use of private object. Note that Ada 2005
1265 -- AI-161 modifies the rules for Ada 2005, including the use of
1266 -- the new pragma Preelaborable_Initialization.
1268 if Is_Private_Type (Ent)
1269 or else Depends_On_Private (Ent)
1270 then
1271 -- Case where type has preelaborable initialization which
1272 -- means that a pragma Preelaborable_Initialization was
1273 -- given for the private type.
1275 if Relaxed_RM_Semantics then
1277 -- In relaxed mode, do not issue these messages, this
1278 -- is basically similar to the GNAT_Mode test below.
1280 null;
1282 elsif Has_Preelaborable_Initialization (Ent) then
1284 -- But for the predefined units, we will ignore this
1285 -- status unless we are in Ada 2005 mode since we want
1286 -- Ada 95 compatible behavior, in which the entities
1287 -- marked with this pragma in the predefined library are
1288 -- not treated specially.
1290 if Ada_Version < Ada_2005 then
1291 Error_Msg_N
1292 ("private object not allowed in preelaborated unit",
1294 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1295 end if;
1297 -- Type does not have preelaborable initialization
1299 else
1300 -- We allow this when compiling in GNAT mode to make life
1301 -- easier for some cases where it would otherwise be hard
1302 -- to be exactly valid Ada.
1304 if not GNAT_Mode then
1305 Error_Msg_N
1306 ("private object not allowed in preelaborated unit",
1309 -- Add a message if it would help to provide a pragma
1310 -- Preelaborable_Initialization on the type of the
1311 -- object (which would make it legal in Ada 2005).
1313 -- If the type has no full view (generic type, or
1314 -- previous error), the warning does not apply.
1316 if Is_Private_Type (Ent)
1317 and then Present (Full_View (Ent))
1318 and then
1319 Has_Preelaborable_Initialization (Full_View (Ent))
1320 then
1321 Error_Msg_Sloc := Sloc (Ent);
1323 if Ada_Version >= Ada_2005 then
1324 Error_Msg_NE
1325 ("\would be legal if pragma Preelaborable_" &
1326 "Initialization given for & #", N, Ent);
1327 else
1328 Error_Msg_NE
1329 ("\would be legal in Ada 2005 if pragma " &
1330 "Preelaborable_Initialization given for & #",
1331 N, Ent);
1332 end if;
1333 end if;
1334 end if;
1335 end if;
1337 -- Access to Task or Protected type
1339 elsif Is_Entity_Name (Odf)
1340 and then Present (Etype (Odf))
1341 and then Is_Access_Type (Etype (Odf))
1342 then
1343 Ent := Designated_Type (Etype (Odf));
1345 elsif Is_Entity_Name (Odf) then
1346 Ent := Entity (Odf);
1348 elsif Nkind (Odf) = N_Subtype_Indication then
1349 Ent := Etype (Subtype_Mark (Odf));
1351 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1352 Ent := Component_Type (T);
1353 end if;
1355 if Is_Task_Type (Ent)
1356 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1357 then
1358 Error_Msg_N
1359 ("concurrent object not allowed in preelaborated unit",
1361 return;
1362 end if;
1363 end;
1364 end if;
1366 -- Non-static discriminants not allowed in preelaborated unit.
1367 -- Objects of a controlled type with a user-defined Initialize
1368 -- are forbidden as well.
1370 if Is_Record_Type (Etype (Id)) then
1371 declare
1372 ET : constant Entity_Id := Etype (Id);
1373 EE : constant Entity_Id := Etype (Etype (Id));
1374 PEE : Node_Id;
1376 begin
1377 if Has_Discriminants (ET) and then Present (EE) then
1378 PEE := Parent (EE);
1380 if Nkind (PEE) = N_Full_Type_Declaration
1381 and then not Static_Discriminant_Expr
1382 (Discriminant_Specifications (PEE))
1383 then
1384 Error_Msg_N
1385 ("non-static discriminant in preelaborated unit",
1386 PEE);
1387 end if;
1388 end if;
1390 -- For controlled type or type with controlled component, check
1391 -- preelaboration flag, as there may be a non-null Initialize
1392 -- primitive. For language versions earlier than Ada 2005,
1393 -- there is no notion of preelaborable initialization, and
1394 -- Validate_Controlled_Object is used to enforce rules for
1395 -- controlled objects.
1397 if (Is_Controlled (ET) or else Has_Controlled_Component (ET))
1398 and then Ada_Version >= Ada_2005
1399 and then not Has_Preelaborable_Initialization (ET)
1400 then
1401 Error_Msg_NE
1402 ("controlled type& does not have"
1403 & " preelaborable initialization", N, ET);
1404 end if;
1405 end;
1407 end if;
1408 end if;
1410 -- A pure library_item must not contain the declaration of any variable
1411 -- except within a subprogram, generic subprogram, task unit, or
1412 -- protected unit (RM 10.2.1(16)).
1414 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1415 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1417 elsif not In_Private_Part (Id) then
1419 -- The visible part of an RCI library unit must not contain the
1420 -- declaration of a variable (RM E.1.3(9)).
1422 if In_RCI_Declaration then
1423 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1425 -- The visible part of a Shared Passive library unit must not contain
1426 -- the declaration of a variable (RM E.2.2(7)).
1428 elsif In_RT_Declaration then
1429 Error_Msg_N
1430 ("visible variable not allowed in remote types unit", N);
1431 end if;
1432 end if;
1433 end Validate_Object_Declaration;
1435 -----------------------------
1436 -- Validate_RACW_Primitive --
1437 -----------------------------
1439 procedure Validate_RACW_Primitive
1440 (Subp : Entity_Id;
1441 RACW : Entity_Id)
1443 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id);
1444 -- Diagnose illegality on N. If RACW is present, report the error on it
1445 -- rather than on N.
1447 -------------------------
1448 -- Illegal_Remote_Subp --
1449 -------------------------
1451 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id) is
1452 begin
1453 if Present (RACW) then
1454 if not Error_Posted (RACW) then
1455 Error_Msg_N
1456 ("illegal remote access to class-wide type&", RACW);
1457 end if;
1459 Error_Msg_Sloc := Sloc (N);
1460 Error_Msg_NE ("\\" & Msg & " in primitive& #", RACW, Subp);
1462 else
1463 Error_Msg_NE (Msg & " in remote subprogram&", N, Subp);
1464 end if;
1465 end Illegal_Remote_Subp;
1467 Rtyp : Entity_Id;
1468 Param : Node_Id;
1469 Param_Spec : Node_Id;
1470 Param_Type : Entity_Id;
1472 -- Start of processing for Validate_RACW_Primitive
1474 begin
1475 -- Check return type
1477 if Ekind (Subp) = E_Function then
1478 Rtyp := Etype (Subp);
1480 -- AI05-0101 (Binding Interpretation): The result type of a remote
1481 -- function must either support external streaming or be a
1482 -- controlling access result type.
1484 if Has_Controlling_Result (Subp) then
1485 null;
1487 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1488 Illegal_Remote_Subp ("anonymous access result", Rtyp);
1490 elsif Is_Limited_Type (Rtyp) then
1491 if No (TSS (Rtyp, TSS_Stream_Read))
1492 or else
1493 No (TSS (Rtyp, TSS_Stream_Write))
1494 then
1495 Illegal_Remote_Subp
1496 ("limited return type must have Read and Write attributes",
1497 Parent (Subp));
1498 Explain_Limited_Type (Rtyp, Parent (Subp));
1499 end if;
1501 -- Check that the return type supports external streaming
1503 elsif No_External_Streaming (Rtyp)
1504 and then not Error_Posted (Rtyp)
1505 then
1506 Illegal_Remote_Subp ("return type containing non-remote access "
1507 & "must have Read and Write attributes",
1508 Parent (Subp));
1509 end if;
1510 end if;
1512 Param := First_Formal (Subp);
1513 while Present (Param) loop
1515 -- Now find out if this parameter is a controlling parameter
1517 Param_Spec := Parent (Param);
1518 Param_Type := Etype (Param);
1520 if Is_Controlling_Formal (Param) then
1522 -- It is a controlling parameter, so specific checks below do not
1523 -- apply.
1525 null;
1527 elsif Ekind (Param_Type) in E_Anonymous_Access_Type
1528 | E_Anonymous_Access_Subprogram_Type
1529 then
1530 -- From RM E.2.2(14), no anonymous access parameter other than
1531 -- controlling ones may be used (because an anonymous access
1532 -- type never supports external streaming).
1534 Illegal_Remote_Subp
1535 ("non-controlling access parameter", Param_Spec);
1537 elsif No_External_Streaming (Param_Type)
1538 and then not Error_Posted (Param_Type)
1539 then
1540 Illegal_Remote_Subp ("formal parameter in remote subprogram must "
1541 & "support external streaming", Param_Spec);
1542 end if;
1544 -- Check next parameter in this subprogram
1546 Next_Formal (Param);
1547 end loop;
1548 end Validate_RACW_Primitive;
1550 ------------------------------
1551 -- Validate_RACW_Primitives --
1552 ------------------------------
1554 procedure Validate_RACW_Primitives (T : Entity_Id) is
1555 Desig_Type : Entity_Id;
1556 Primitive_Subprograms : Elist_Id;
1557 Subprogram_Elmt : Elmt_Id;
1558 Subprogram : Entity_Id;
1560 begin
1561 Desig_Type := Etype (Designated_Type (T));
1563 -- No action needed for concurrent types
1565 if Is_Concurrent_Type (Desig_Type) then
1566 return;
1567 end if;
1569 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1571 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1572 while Subprogram_Elmt /= No_Elmt loop
1573 Subprogram := Node (Subprogram_Elmt);
1575 if Is_Predefined_Dispatching_Operation (Subprogram)
1576 or else Is_Hidden (Subprogram)
1577 then
1578 goto Next_Subprogram;
1579 end if;
1581 Validate_RACW_Primitive (Subp => Subprogram, RACW => T);
1583 <<Next_Subprogram>>
1584 Next_Elmt (Subprogram_Elmt);
1585 end loop;
1586 end Validate_RACW_Primitives;
1588 -------------------------------
1589 -- Validate_RCI_Declarations --
1590 -------------------------------
1592 procedure Validate_RCI_Declarations (P : Entity_Id) is
1593 E : Entity_Id;
1595 begin
1596 E := First_Entity (P);
1597 while Present (E) loop
1598 if Comes_From_Source (E) then
1599 if Is_Limited_Type (E) then
1600 Error_Msg_N
1601 ("limited type not allowed in 'R'C'I unit", Parent (E));
1602 Explain_Limited_Type (E, Parent (E));
1604 elsif Ekind (E) in E_Generic_Function
1605 | E_Generic_Package
1606 | E_Generic_Procedure
1607 then
1608 Error_Msg_N ("generic declaration not allowed in 'R'C'I unit",
1609 Parent (E));
1611 elsif (Ekind (E) = E_Function or else Ekind (E) = E_Procedure)
1612 and then Has_Pragma_Inline (E)
1613 then
1614 Error_Msg_N
1615 ("inlined subprogram not allowed in 'R'C'I unit", Parent (E));
1617 -- Inner packages that are renamings need not be checked. Generic
1618 -- RCI packages are subject to the checks, but entities that come
1619 -- from formal packages are not part of the visible declarations
1620 -- of the package and are not checked.
1622 elsif Ekind (E) = E_Package then
1623 if Present (Renamed_Entity (E)) then
1624 null;
1626 elsif Ekind (P) /= E_Generic_Package
1627 or else List_Containing (Unit_Declaration_Node (E)) /=
1628 Generic_Formal_Declarations
1629 (Unit_Declaration_Node (P))
1630 then
1631 Validate_RCI_Declarations (E);
1632 end if;
1633 end if;
1634 end if;
1636 Next_Entity (E);
1637 end loop;
1638 end Validate_RCI_Declarations;
1640 -----------------------------------------
1641 -- Validate_RCI_Subprogram_Declaration --
1642 -----------------------------------------
1644 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1645 K : constant Node_Kind := Nkind (N);
1646 Profile : List_Id;
1647 Id : constant Entity_Id := Defining_Entity (N);
1648 Param_Spec : Node_Id;
1649 Param_Type : Entity_Id;
1650 Error_Node : Node_Id := N;
1652 begin
1653 -- This procedure enforces rules on subprogram and access to subprogram
1654 -- declarations in RCI units. These rules do not apply to expander
1655 -- generated routines, which are not remote subprograms. It is called:
1657 -- 1. from Analyze_Subprogram_Declaration.
1658 -- 2. from Validate_Object_Declaration (access to subprogram).
1660 if not (Comes_From_Source (N)
1661 and then In_RCI_Declaration
1662 and then not In_Private_Part (Scope (Id)))
1663 then
1664 return;
1665 end if;
1667 if K = N_Subprogram_Declaration then
1668 Profile := Parameter_Specifications (Specification (N));
1670 else
1671 pragma Assert (K = N_Object_Declaration);
1673 -- The above assertion is dubious, the visible declarations of an
1674 -- RCI unit never contain an object declaration, this should be an
1675 -- ACCESS-to-object declaration???
1677 if Nkind (Id) = N_Defining_Identifier
1678 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1679 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1680 then
1681 Profile :=
1682 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1683 else
1684 return;
1685 end if;
1686 end if;
1688 -- Iterate through the parameter specification list, checking that
1689 -- no access parameter and no limited type parameter in the list.
1690 -- RM E.2.3(14).
1692 if Present (Profile) then
1693 Param_Spec := First (Profile);
1694 while Present (Param_Spec) loop
1695 Param_Type := Etype (Defining_Identifier (Param_Spec));
1697 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1698 if K = N_Subprogram_Declaration then
1699 Error_Node := Param_Spec;
1700 end if;
1702 -- Report error only if declaration is in source program
1704 if Comes_From_Source (Id) then
1705 Error_Msg_N
1706 ("subprogram in 'R'C'I unit cannot have access parameter",
1707 Error_Node);
1708 end if;
1710 -- For a limited private type parameter, we check only the private
1711 -- declaration and ignore full type declaration, unless this is
1712 -- the only declaration for the type, e.g., as a limited record.
1714 elsif No_External_Streaming (Param_Type) then
1715 if K = N_Subprogram_Declaration then
1716 Error_Node := Param_Spec;
1717 end if;
1719 Error_Msg_NE
1720 ("formal of remote subprogram& "
1721 & "must support external streaming",
1722 Error_Node, Id);
1723 if Is_Limited_Type (Param_Type) then
1724 Explain_Limited_Type (Param_Type, Error_Node);
1725 end if;
1726 end if;
1728 Next (Param_Spec);
1729 end loop;
1730 end if;
1732 if Ekind (Id) = E_Function
1733 and then Ekind (Etype (Id)) = E_Anonymous_Access_Type
1734 and then Comes_From_Source (Id)
1735 then
1736 Error_Msg_N
1737 ("function in 'R'C'I unit cannot have access result",
1738 Error_Node);
1739 end if;
1740 end Validate_RCI_Subprogram_Declaration;
1742 ----------------------------------------------------
1743 -- Validate_Remote_Access_Object_Type_Declaration --
1744 ----------------------------------------------------
1746 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1747 Direct_Designated_Type : Entity_Id;
1748 Desig_Type : Entity_Id;
1750 begin
1751 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1752 -- the given node is N_Access_To_Object_Definition.
1754 if not Comes_From_Source (T)
1755 or else (not In_RCI_Declaration and then not In_RT_Declaration)
1756 then
1757 return;
1758 end if;
1760 -- An access definition in the private part of a package is not a
1761 -- remote access type. Restrictions related to external streaming
1762 -- support for non-remote access types are enforced elsewhere. Note
1763 -- that In_Private_Part is never set on type entities: check flag
1764 -- on enclosing scope.
1766 if In_Private_Part (Scope (T)) then
1767 return;
1768 end if;
1770 -- Check RCI or RT unit type declaration. It may not contain the
1771 -- declaration of an access-to-object type unless it is a general access
1772 -- type that designates a class-wide limited private type or subtype.
1773 -- There are also constraints on the primitive subprograms of the
1774 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1776 if Ekind (T) /= E_General_Access_Type
1777 or else not Is_Class_Wide_Type (Designated_Type (T))
1778 then
1779 if In_RCI_Declaration then
1780 Error_Msg_N
1781 ("error in access type in Remote_Call_Interface unit", T);
1782 else
1783 Error_Msg_N
1784 ("error in access type in Remote_Types unit", T);
1785 end if;
1787 Error_Msg_N ("\must be general access to class-wide type", T);
1788 return;
1789 end if;
1791 Direct_Designated_Type := Designated_Type (T);
1792 Desig_Type := Etype (Direct_Designated_Type);
1794 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type???
1796 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1797 Error_Msg_N
1798 ("error in designated type of remote access to class-wide type", T);
1799 Error_Msg_N
1800 ("\must be tagged limited private or private extension", T);
1801 return;
1802 end if;
1803 end Validate_Remote_Access_Object_Type_Declaration;
1805 -----------------------------------------------
1806 -- Validate_Remote_Access_To_Class_Wide_Type --
1807 -----------------------------------------------
1809 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1810 K : constant Node_Kind := Nkind (N);
1811 PK : constant Node_Kind := Nkind (Parent (N));
1812 E : Entity_Id;
1814 begin
1815 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1816 -- of class-wide limited private types.
1818 -- Storage_Pool and Storage_Size are not defined for such types
1820 -- The expected type of allocator must not be such a type.
1822 -- The actual parameter of generic instantiation must not be such a
1823 -- type if the formal parameter is of an access type.
1825 -- On entry, there are several cases:
1827 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1828 -- either Storage_Pool or Storage_Size.
1830 -- 2. called from exp_ch4 Expand_N_Allocator
1832 -- 3. called from sem_ch4 Analyze_Explicit_Dereference
1834 -- 4. called from sem_res Resolve_Actuals
1836 if K = N_Attribute_Definition_Clause then
1837 E := Etype (Entity (N));
1839 if Is_Remote_Access_To_Class_Wide_Type (E) then
1840 Error_Msg_Name_1 := Chars (N);
1841 Error_Msg_N
1842 ("cannot specify% aspect for a remote operand", N);
1843 return;
1844 end if;
1846 elsif K = N_Attribute_Reference then
1847 E := Etype (Prefix (N));
1849 if Is_Remote_Access_To_Class_Wide_Type (E) then
1850 Error_Msg_N ("incorrect attribute of remote operand", N);
1851 return;
1852 end if;
1854 elsif K = N_Allocator then
1855 E := Etype (N);
1857 if Is_Remote_Access_To_Class_Wide_Type (E) then
1858 Error_Msg_N ("incorrect expected remote type of allocator", N);
1859 return;
1860 end if;
1862 -- This subprogram also enforces the checks in E.2.2(13). A value of
1863 -- such type must not be dereferenced unless as controlling operand of
1864 -- a dispatching call. Explicit dereferences not coming from source are
1865 -- exempted from this checking because the expander produces them in
1866 -- some cases (such as for tag checks on dispatching calls with multiple
1867 -- controlling operands). However we do check in the case of an implicit
1868 -- dereference that is expanded to an explicit dereference (hence the
1869 -- test of whether Original_Node (N) comes from source).
1871 elsif K = N_Explicit_Dereference
1872 and then Comes_From_Source (Original_Node (N))
1873 then
1874 E := Etype (Prefix (N));
1876 -- If the class-wide type is not a remote one, the restrictions
1877 -- do not apply.
1879 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1880 return;
1881 end if;
1883 -- If we have a true dereference that comes from source and that
1884 -- is a controlling argument for a dispatching call, accept it.
1886 if Is_Actual_Parameter (N) and then Is_Controlling_Actual (N) then
1887 return;
1888 end if;
1890 -- If we are just within a procedure or function call and the
1891 -- dereference has not been analyzed, return because this procedure
1892 -- will be called again from sem_res Resolve_Actuals. The same can
1893 -- apply in the case of dereference that is the prefix of a selected
1894 -- component, which can be a call given in prefixed form.
1896 if (Is_Actual_Parameter (N) or else PK = N_Selected_Component)
1897 and then not Analyzed (N)
1898 then
1899 return;
1900 end if;
1902 -- We must allow expanded code to generate a reference to the tag of
1903 -- the designated object (may be either the actual tag, or the stub
1904 -- tag in the case of a remote object).
1906 if PK = N_Selected_Component
1907 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1908 then
1909 return;
1910 end if;
1912 Error_Msg_N
1913 ("invalid dereference of a remote access-to-class-wide value", N);
1914 end if;
1915 end Validate_Remote_Access_To_Class_Wide_Type;
1917 ------------------------------------------
1918 -- Validate_Remote_Type_Type_Conversion --
1919 ------------------------------------------
1921 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1922 S : constant Entity_Id := Etype (N);
1923 E : constant Entity_Id := Etype (Expression (N));
1925 begin
1926 -- This test is required in the case where a conversion appears inside a
1927 -- normal package, it does not necessarily have to be inside an RCI,
1928 -- Remote_Types unit (RM E.2.2(9,12)).
1930 if Is_Remote_Access_To_Subprogram_Type (E)
1931 and then not Is_Remote_Access_To_Subprogram_Type (S)
1932 then
1933 Error_Msg_N
1934 ("incorrect conversion of remote operand to local type", N);
1935 return;
1937 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1938 and then Is_Remote_Access_To_Subprogram_Type (S)
1939 then
1940 Error_Msg_N
1941 ("incorrect conversion of local operand to remote type", N);
1942 return;
1944 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1945 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1946 then
1947 Error_Msg_N
1948 ("incorrect conversion of remote operand to local type", N);
1949 return;
1950 end if;
1952 -- If a local access type is converted into a RACW type, then the
1953 -- current unit has a pointer that may now be exported to another
1954 -- partition.
1956 if Is_Remote_Access_To_Class_Wide_Type (S)
1957 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1958 then
1959 Set_Has_RACW (Current_Sem_Unit);
1960 end if;
1961 end Validate_Remote_Type_Type_Conversion;
1963 -------------------------------
1964 -- Validate_RT_RAT_Component --
1965 -------------------------------
1967 procedure Validate_RT_RAT_Component (N : Node_Id) is
1968 Spec : constant Node_Id := Specification (N);
1969 Name_U : constant Entity_Id := Defining_Entity (Spec);
1970 Typ : Entity_Id;
1971 U_Typ : Entity_Id;
1972 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1974 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean;
1975 -- True if any stream attribute is available for Typ
1977 ---------------------------------
1978 -- Stream_Attributes_Available --
1979 ---------------------------------
1981 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean
1983 begin
1984 return Stream_Attribute_Available (Typ, TSS_Stream_Read)
1985 or else
1986 Stream_Attribute_Available (Typ, TSS_Stream_Write)
1987 or else
1988 Stream_Attribute_Available (Typ, TSS_Stream_Input)
1989 or else
1990 Stream_Attribute_Available (Typ, TSS_Stream_Output);
1991 end Stream_Attributes_Available;
1993 -- Start of processing for Validate_RT_RAT_Component
1995 begin
1996 if not Is_Remote_Types (Name_U) then
1997 return;
1998 end if;
2000 Typ := First_Entity (Name_U);
2001 while Present (Typ) and then Typ /= First_Priv_Ent loop
2002 U_Typ := Underlying_Type (Base_Type (Typ));
2004 if No (U_Typ) then
2005 U_Typ := Typ;
2006 end if;
2008 if Comes_From_Source (Typ) and then Is_Type (Typ)
2009 and then Ekind (Typ) /= E_Incomplete_Type
2010 then
2011 -- Check that the type can be meaningfully transmitted to another
2012 -- partition (E.2.2(8)).
2014 if (Ada_Version < Ada_2005 and then Has_Non_Remote_Access (U_Typ))
2015 or else (Stream_Attributes_Available (Typ)
2016 and then No_External_Streaming (U_Typ))
2017 then
2018 if Is_Non_Remote_Access_Type (Typ) then
2019 Error_Msg_N ("error in non-remote access type", U_Typ);
2020 else
2021 Error_Msg_N
2022 ("error in record type containing a component of a " &
2023 "non-remote access type", U_Typ);
2024 end if;
2026 if Ada_Version >= Ada_2005 then
2027 Error_Msg_N
2028 ("\must have visible Read and Write attribute " &
2029 "definition clauses (RM E.2.2(8))", U_Typ);
2030 else
2031 Error_Msg_N
2032 ("\must have Read and Write attribute " &
2033 "definition clauses (RM E.2.2(8))", U_Typ);
2034 end if;
2035 end if;
2036 end if;
2038 Next_Entity (Typ);
2039 end loop;
2040 end Validate_RT_RAT_Component;
2042 -----------------------------------------
2043 -- Validate_SP_Access_Object_Type_Decl --
2044 -----------------------------------------
2046 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2047 Direct_Designated_Type : Entity_Id;
2049 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2050 -- Return true if the protected type designated by T has entry
2051 -- declarations.
2053 ----------------------------
2054 -- Has_Entry_Declarations --
2055 ----------------------------
2057 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2058 Ety : Entity_Id;
2060 begin
2061 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2062 Ety := First_Entity (E);
2063 while Present (Ety) loop
2064 if Ekind (Ety) = E_Entry then
2065 return True;
2066 end if;
2068 Next_Entity (Ety);
2069 end loop;
2070 end if;
2072 return False;
2073 end Has_Entry_Declarations;
2075 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2077 begin
2078 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2079 -- Nkind of the given entity is N_Access_To_Object_Definition.
2081 if not Comes_From_Source (T)
2082 or else not In_Shared_Passive_Unit
2083 or else In_Subprogram_Task_Protected_Unit
2084 then
2085 return;
2086 end if;
2088 -- Check Shared Passive unit. It should not contain the declaration
2089 -- of an access-to-object type whose designated type is a class-wide
2090 -- type, task type or protected type with entry (RM E.2.1(7)).
2092 Direct_Designated_Type := Designated_Type (T);
2094 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2095 Error_Msg_N
2096 ("invalid access-to-class-wide type in shared passive unit", T);
2097 return;
2099 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2100 Error_Msg_N
2101 ("invalid access-to-task type in shared passive unit", T);
2102 return;
2104 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2105 and then Has_Entry_Declarations (Direct_Designated_Type)
2106 then
2107 Error_Msg_N
2108 ("invalid access-to-protected type in shared passive unit", T);
2109 return;
2110 end if;
2111 end Validate_SP_Access_Object_Type_Decl;
2113 ---------------------------------
2114 -- Validate_Static_Object_Name --
2115 ---------------------------------
2117 procedure Validate_Static_Object_Name (N : Node_Id) is
2118 E : Entity_Id;
2119 Val : Node_Id;
2121 function Is_Primary (N : Node_Id) return Boolean;
2122 -- Determine whether node is syntactically a primary in an expression
2123 -- This function should probably be somewhere else ???
2125 -- Also it does not do what it says, e.g if N is a binary operator
2126 -- whose parent is a binary operator, Is_Primary returns True ???
2128 ----------------
2129 -- Is_Primary --
2130 ----------------
2132 function Is_Primary (N : Node_Id) return Boolean is
2133 K : constant Node_Kind := Nkind (Parent (N));
2135 begin
2136 case K is
2137 when N_Aggregate
2138 | N_Component_Association
2139 | N_Index_Or_Discriminant_Constraint
2140 | N_Membership_Test
2141 | N_Op
2142 | N_Range
2144 return True;
2146 when N_Attribute_Reference =>
2147 declare
2148 Attr : constant Name_Id := Attribute_Name (Parent (N));
2150 begin
2151 return Attr /= Name_Address
2152 and then Attr /= Name_Access
2153 and then Attr /= Name_Unchecked_Access
2154 and then Attr /= Name_Unrestricted_Access;
2155 end;
2157 when N_Indexed_Component =>
2158 return N /= Prefix (Parent (N)) or else Is_Primary (Parent (N));
2160 when N_Qualified_Expression
2161 | N_Type_Conversion
2163 return Is_Primary (Parent (N));
2165 when N_Assignment_Statement
2166 | N_Object_Declaration
2168 return N = Expression (Parent (N));
2170 when N_Selected_Component =>
2171 return Is_Primary (Parent (N));
2173 when others =>
2174 return False;
2175 end case;
2176 end Is_Primary;
2178 -- Start of processing for Validate_Static_Object_Name
2180 begin
2181 if not In_Preelaborated_Unit
2182 or else not Comes_From_Source (N)
2183 or else In_Subprogram_Or_Concurrent_Unit
2184 or else Ekind (Current_Scope) = E_Block
2185 then
2186 return;
2188 -- Filter out cases where primary is default in a component declaration,
2189 -- discriminant specification, or actual in a record type initialization
2190 -- call.
2192 -- Initialization call of internal types
2194 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2196 if Present (Parent (Parent (N)))
2197 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2198 then
2199 return;
2200 end if;
2202 if Nkind (Name (Parent (N))) = N_Identifier
2203 and then not Comes_From_Source (Entity (Name (Parent (N))))
2204 then
2205 return;
2206 end if;
2207 end if;
2209 -- Error if the name is a primary in an expression. The parent must not
2210 -- be an operator, or a selected component or an indexed component that
2211 -- is itself a primary. Entities that are actuals do not need to be
2212 -- checked, because the call itself will be diagnosed. Entities in a
2213 -- generic unit or within a preanalyzed expression are not checked:
2214 -- only their use in executable code matters.
2216 if Is_Primary (N)
2217 and then (not Inside_A_Generic
2218 or else Present (Enclosing_Generic_Body (N)))
2219 and then not In_Spec_Expression
2220 then
2221 if Ekind (Entity (N)) = E_Variable
2222 or else Ekind (Entity (N)) in Formal_Object_Kind
2223 then
2224 Flag_Non_Static_Expr
2225 ("non-static object name in preelaborated unit", N);
2227 -- Give an error for a reference to a nonstatic constant, unless the
2228 -- constant is in another GNAT library unit that is preelaborable.
2230 elsif Ekind (Entity (N)) = E_Constant
2231 and then not Is_Static_Expression (N)
2232 then
2233 E := Entity (N);
2234 Val := Constant_Value (E);
2236 if In_Internal_Unit (N)
2237 and then
2238 Enclosing_Comp_Unit_Node (N) /= Enclosing_Comp_Unit_Node (E)
2239 and then (Is_Preelaborated (Scope (E))
2240 or else Is_Pure (Scope (E))
2241 or else (Present (Renamed_Object (E))
2242 and then Is_Entity_Name (Renamed_Object (E))
2243 and then
2244 (Is_Preelaborated
2245 (Scope (Renamed_Object (E)))
2246 or else
2247 Is_Pure
2248 (Scope (Renamed_Object (E))))))
2249 then
2250 null;
2252 -- If the value of the constant is a local variable that renames
2253 -- an aggregate, this is in itself legal. The aggregate may be
2254 -- expanded into a loop, but this does not affect preelaborability
2255 -- in itself. If some aggregate components are non-static, that is
2256 -- to say if they involve non static primaries, they will be
2257 -- flagged when analyzed.
2259 elsif Present (Val)
2260 and then Is_Entity_Name (Val)
2261 and then Is_Array_Type (Etype (Val))
2262 and then not Comes_From_Source (Val)
2263 and then Nkind (Original_Node (Val)) = N_Aggregate
2264 then
2265 null;
2267 -- This is the error case
2269 else
2270 -- In GNAT mode or Relaxed RM Semantic mode, this is just a
2271 -- warning, to allow it to be judiciously turned off.
2272 -- Otherwise it is a real error.
2274 if GNAT_Mode or Relaxed_RM_Semantics then
2275 Error_Msg_N
2276 ("??non-static constant in preelaborated unit", N);
2277 else
2278 Flag_Non_Static_Expr
2279 ("non-static constant in preelaborated unit", N);
2280 end if;
2281 end if;
2282 end if;
2283 end if;
2284 end Validate_Static_Object_Name;
2286 end Sem_Cat;