PR libstdc++/80251
[official-gcc.git] / gcc / ada / sem_cat.adb
blob878cab0119e089a5cb31bf66679653b86982d403
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-2016, 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_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 Snames; use Snames;
45 with Stand; use Stand;
47 package body Sem_Cat is
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 procedure Check_Categorization_Dependencies
54 (Unit_Entity : Entity_Id;
55 Depended_Entity : Entity_Id;
56 Info_Node : Node_Id;
57 Is_Subunit : Boolean);
58 -- This procedure checks that the categorization of a lib unit and that
59 -- of the depended unit satisfy dependency restrictions.
60 -- The depended_entity can be the entity in a with_clause item, in which
61 -- case Info_Node denotes that item. The depended_entity can also be the
62 -- parent unit of a child unit, in which case Info_Node is the declaration
63 -- of the child unit. The error message is posted on Info_Node, and is
64 -- specialized if Is_Subunit is true.
66 procedure Check_Non_Static_Default_Expr
67 (Type_Def : Node_Id;
68 Obj_Decl : Node_Id);
69 -- Iterate through the component list of a record definition, check
70 -- that no component is declared with a nonstatic default value.
71 -- If a nonstatic default exists, report an error on Obj_Decl.
73 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean;
74 -- Return True if entity has attribute definition clauses for Read and
75 -- Write attributes that are visible at some place.
77 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean;
78 -- Returns true if the entity is a type whose full view is a non-remote
79 -- access type, for the purpose of enforcing E.2.2(8) rules.
81 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean;
82 -- Return true if Typ or the type of any of its subcomponents is a non
83 -- remote access type and doesn't have user-defined stream attributes.
85 function No_External_Streaming (E : Entity_Id) return Boolean;
86 -- Return True if the entity or one of its subcomponents does not support
87 -- external streaming.
89 function In_RCI_Declaration return Boolean;
90 function In_RT_Declaration return Boolean;
91 -- Determine if current scope is within the declaration of a Remote Call
92 -- Interface or Remote Types unit, for semantic checking purposes.
94 function In_Package_Declaration return Boolean;
95 -- Shared supporting routine for In_RCI_Declaration and In_RT_Declaration
97 function In_Shared_Passive_Unit return Boolean;
98 -- Determines if current scope is within a Shared Passive compilation unit
100 function Static_Discriminant_Expr (L : List_Id) return Boolean;
101 -- Iterate through the list of discriminants to check if any of them
102 -- contains non-static default expression, which is a violation in
103 -- a preelaborated library unit.
105 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id);
106 -- Check validity of declaration if RCI or RT unit. It should not contain
107 -- the declaration of an access-to-object type unless it is a general
108 -- access type that designates a class-wide limited private type. There are
109 -- also constraints about the primitive subprograms of the class-wide type.
110 -- RM E.2 (9, 13, 14)
112 procedure Validate_RACW_Primitive
113 (Subp : Entity_Id;
114 RACW : Entity_Id);
115 -- Check legality of the declaration of primitive Subp of the designated
116 -- type of the given RACW type.
118 ---------------------------------------
119 -- Check_Categorization_Dependencies --
120 ---------------------------------------
122 procedure Check_Categorization_Dependencies
123 (Unit_Entity : Entity_Id;
124 Depended_Entity : Entity_Id;
125 Info_Node : Node_Id;
126 Is_Subunit : Boolean)
128 N : constant Node_Id := Info_Node;
129 Err : Boolean;
131 -- Here we define an enumeration type to represent categorization types,
132 -- ordered so that a unit with a given categorization can only WITH
133 -- units with lower or equal categorization type.
135 type Categorization is
136 (Pure,
137 Shared_Passive,
138 Remote_Types,
139 Remote_Call_Interface,
140 Normal);
142 function Get_Categorization (E : Entity_Id) return Categorization;
143 -- Check categorization flags from entity, and return in the form
144 -- of the lowest value of the Categorization type that applies to E.
146 ------------------------
147 -- Get_Categorization --
148 ------------------------
150 function Get_Categorization (E : Entity_Id) return Categorization is
151 begin
152 -- Get the lowest categorization that corresponds to E. Note that
153 -- nothing prevents several (different) categorization pragmas
154 -- to apply to the same library unit, in which case the unit has
155 -- all associated categories, so we need to be careful here to
156 -- check pragmas in proper Categorization order in order to
157 -- return the lowest applicable value.
159 -- Ignore Pure specification if set by pragma Pure_Function
161 if Is_Pure (E)
162 and then not
163 (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
164 then
165 return Pure;
167 elsif Is_Shared_Passive (E) then
168 return Shared_Passive;
170 elsif Is_Remote_Types (E) then
171 return Remote_Types;
173 elsif Is_Remote_Call_Interface (E) then
174 return Remote_Call_Interface;
176 else
177 return Normal;
178 end if;
179 end Get_Categorization;
181 Unit_Category : Categorization;
182 With_Category : Categorization;
184 -- Start of processing for Check_Categorization_Dependencies
186 begin
187 -- Intrinsic subprograms are preelaborated, so do not impose any
188 -- categorization dependencies. Also, ignore categorization
189 -- dependencies when compilation switch -gnatdu is used.
191 if Is_Intrinsic_Subprogram (Depended_Entity) or else Debug_Flag_U then
192 return;
193 end if;
195 -- First check 10.2.1 (11/1) rules on preelaborate packages
197 if Is_Preelaborated (Unit_Entity)
198 and then not Is_Preelaborated (Depended_Entity)
199 and then not Is_Pure (Depended_Entity)
200 then
201 Err := True;
202 else
203 Err := False;
204 end if;
206 -- Check categorization rules of RM E.2(5)
208 Unit_Category := Get_Categorization (Unit_Entity);
209 With_Category := Get_Categorization (Depended_Entity);
211 if With_Category > Unit_Category then
213 -- Special case: Remote_Types and Remote_Call_Interface are allowed
214 -- to WITH anything in the package body, per (RM E.2(5)).
216 if (Unit_Category = Remote_Types
217 or else Unit_Category = Remote_Call_Interface)
218 and then In_Package_Body (Unit_Entity)
219 then
220 null;
222 -- Special case: Remote_Types and Remote_Call_Interface declarations
223 -- can depend on a preelaborated unit via a private with_clause, per
224 -- AI05-0206.
226 elsif (Unit_Category = Remote_Types
227 or else
228 Unit_Category = Remote_Call_Interface)
229 and then Nkind (N) = N_With_Clause
230 and then Private_Present (N)
231 and then Is_Preelaborated (Depended_Entity)
232 then
233 null;
235 -- All other cases, we do have an error
237 else
238 Err := True;
239 end if;
240 end if;
242 -- Here if we have an error
244 if Err then
246 -- These messages are warnings in GNAT mode or if the -gnateP switch
247 -- was set. Otherwise these are real errors for real illegalities.
249 -- The reason we suppress these errors in GNAT mode is that the run-
250 -- time has several instances of violations of the categorization
251 -- errors (e.g. Pure units withing Preelaborate units. All these
252 -- violations are harmless in the cases where we intend them, and
253 -- we suppress the warnings with Warnings (Off). In cases where we
254 -- do not intend the violation, warnings are errors in GNAT mode
255 -- anyway, so we will still get an error.
257 Error_Msg_Warn :=
258 Treat_Categorization_Errors_As_Warnings or GNAT_Mode;
260 -- Don't give error if main unit is not an internal unit, and the
261 -- unit generating the message is an internal unit. This is the
262 -- situation in which such messages would be ignored in any case,
263 -- so it is convenient not to generate them (since it causes
264 -- annoying interference with debugging).
266 if Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
267 and then not Is_Internal_File_Name (Unit_File_Name (Main_Unit))
268 then
269 return;
271 -- Dependence of Remote_Types or Remote_Call_Interface declaration
272 -- on a preelaborated unit with a normal with_clause.
274 elsif (Unit_Category = Remote_Types
275 or else
276 Unit_Category = Remote_Call_Interface)
277 and then Is_Preelaborated (Depended_Entity)
278 then
279 Error_Msg_NE
280 ("<<must use private with clause for preelaborated unit& ",
281 N, Depended_Entity);
283 -- Subunit case
285 elsif Is_Subunit then
286 Error_Msg_NE
287 ("<subunit cannot depend on& " &
288 "(parent has wrong categorization)", N, Depended_Entity);
290 -- Normal unit, not subunit
292 else
293 Error_Msg_NE
294 ("<<cannot depend on& " &
295 "(wrong categorization)", N, Depended_Entity);
296 end if;
298 -- Add further explanation for Pure/Preelaborate common cases
300 if Unit_Category = Pure then
301 Error_Msg_NE
302 ("\<<pure unit cannot depend on non-pure unit",
303 N, Depended_Entity);
305 elsif Is_Preelaborated (Unit_Entity)
306 and then not Is_Preelaborated (Depended_Entity)
307 and then not Is_Pure (Depended_Entity)
308 then
309 Error_Msg_NE
310 ("\<<preelaborated unit cannot depend on "
311 & "non-preelaborated unit",
312 N, Depended_Entity);
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))
359 then
360 Error_Msg_Sloc := Sloc (Component_Decl);
361 Error_Msg_F
362 ("object in preelaborated unit has non-static default#",
363 Obj_Decl);
365 -- Fix this later ???
367 -- elsif Has_Dynamic_Itype (Component_Decl) then
368 -- Error_Msg_N
369 -- ("dynamic type discriminant," &
370 -- " constraint in preelaborated unit",
371 -- Component_Decl);
372 end if;
374 Next (Component_Decl);
375 end loop;
376 end Check_Non_Static_Default_Expr;
378 ---------------------------
379 -- Has_Non_Remote_Access --
380 ---------------------------
382 function Has_Non_Remote_Access (Typ : Entity_Id) return Boolean is
383 Component : Entity_Id;
384 Comp_Type : Entity_Id;
385 U_Typ : constant Entity_Id := Underlying_Type (Typ);
387 begin
388 if No (U_Typ) then
389 return False;
391 elsif Has_Read_Write_Attributes (Typ)
392 or else Has_Read_Write_Attributes (U_Typ)
393 then
394 return False;
396 elsif Is_Non_Remote_Access_Type (U_Typ) then
397 return True;
398 end if;
400 if Is_Record_Type (U_Typ) then
401 Component := First_Entity (U_Typ);
402 while Present (Component) loop
403 if not Is_Tag (Component) then
404 Comp_Type := Etype (Component);
406 if Has_Non_Remote_Access (Comp_Type) then
407 return True;
408 end if;
409 end if;
411 Next_Entity (Component);
412 end loop;
414 elsif Is_Array_Type (U_Typ) then
415 return Has_Non_Remote_Access (Component_Type (U_Typ));
417 end if;
419 return False;
420 end Has_Non_Remote_Access;
422 -------------------------------
423 -- Has_Read_Write_Attributes --
424 -------------------------------
426 function Has_Read_Write_Attributes (E : Entity_Id) return Boolean is
427 begin
428 return True
429 and then Has_Stream_Attribute_Definition
430 (E, TSS_Stream_Read, At_Any_Place => True)
431 and then Has_Stream_Attribute_Definition
432 (E, TSS_Stream_Write, At_Any_Place => True);
433 end Has_Read_Write_Attributes;
435 -------------------------------------
436 -- Has_Stream_Attribute_Definition --
437 -------------------------------------
439 function Has_Stream_Attribute_Definition
440 (Typ : Entity_Id;
441 Nam : TSS_Name_Type;
442 At_Any_Place : Boolean := False) return Boolean
444 Rep_Item : Node_Id;
446 Real_Rep : Node_Id;
447 -- The stream operation may be specified by an attribute definition
448 -- clause in the source, or by an aspect that generates such an
449 -- attribute definition. For an aspect, the generated attribute
450 -- definition may be placed at the freeze point of the full view of
451 -- the type, but the aspect specification makes the operation visible
452 -- to a client wherever the partial view is visible.
454 begin
455 -- We start from the declaration node and then loop until the end of
456 -- the list until we find the requested attribute definition clause.
457 -- In Ada 2005 mode, clauses are ignored if they are not currently
458 -- visible (this is tested using the corresponding Entity, which is
459 -- inserted by the expander at the point where the clause occurs),
460 -- unless At_Any_Place is true.
462 Rep_Item := First_Rep_Item (Typ);
463 while Present (Rep_Item) loop
464 Real_Rep := Rep_Item;
466 -- If the representation item is an aspect specification, retrieve
467 -- the corresponding pragma or attribute definition.
469 if Nkind (Rep_Item) = N_Aspect_Specification then
470 Real_Rep := Aspect_Rep_Item (Rep_Item);
471 end if;
473 if Nkind (Real_Rep) = N_Attribute_Definition_Clause then
474 case Chars (Real_Rep) is
475 when Name_Read =>
476 exit when Nam = TSS_Stream_Read;
478 when Name_Write =>
479 exit when Nam = TSS_Stream_Write;
481 when Name_Input =>
482 exit when Nam = TSS_Stream_Input;
484 when Name_Output =>
485 exit when Nam = TSS_Stream_Output;
487 when others =>
488 null;
489 end case;
490 end if;
492 Next_Rep_Item (Rep_Item);
493 end loop;
495 -- If not found, and the type is derived from a private view, check
496 -- for a stream attribute inherited from parent. Any specified stream
497 -- attributes will be attached to the derived type's underlying type
498 -- rather the derived type entity itself (which is itself private).
500 if No (Rep_Item)
501 and then Is_Private_Type (Typ)
502 and then Is_Derived_Type (Typ)
503 and then Present (Full_View (Typ))
504 then
505 return Has_Stream_Attribute_Definition
506 (Underlying_Type (Typ), Nam, At_Any_Place);
508 -- Otherwise, if At_Any_Place is true, return True if the attribute is
509 -- available at any place; if it is false, return True only if the
510 -- attribute is currently visible.
512 else
513 return Present (Rep_Item)
514 and then (Ada_Version < Ada_2005
515 or else At_Any_Place
516 or else not Is_Hidden (Entity (Rep_Item)));
517 end if;
518 end Has_Stream_Attribute_Definition;
520 ----------------------------
521 -- In_Package_Declaration --
522 ----------------------------
524 function In_Package_Declaration return Boolean is
525 Unit_Kind : constant Node_Kind :=
526 Nkind (Unit (Cunit (Current_Sem_Unit)));
528 begin
529 -- There are no restrictions on the body of an RCI or RT unit
531 return Is_Package_Or_Generic_Package (Current_Scope)
532 and then Unit_Kind /= N_Package_Body
533 and then not In_Package_Body (Current_Scope)
534 and then not In_Instance;
535 end In_Package_Declaration;
537 ---------------------------
538 -- In_Preelaborated_Unit --
539 ---------------------------
541 function In_Preelaborated_Unit return Boolean is
542 Unit_Entity : Entity_Id := Current_Scope;
543 Unit_Kind : constant Node_Kind :=
544 Nkind (Unit (Cunit (Current_Sem_Unit)));
546 begin
547 -- If evaluating actuals for a child unit instantiation, then ignore
548 -- the preelaboration status of the parent; use the child instead.
550 if Is_Compilation_Unit (Unit_Entity)
551 and then Unit_Kind in N_Generic_Instantiation
552 and then not In_Same_Source_Unit (Unit_Entity,
553 Cunit (Current_Sem_Unit))
554 then
555 Unit_Entity := Cunit_Entity (Current_Sem_Unit);
556 end if;
558 -- There are no constraints on the body of Remote_Call_Interface or
559 -- Remote_Types packages.
561 return (Unit_Entity /= Standard_Standard)
562 and then (Is_Preelaborated (Unit_Entity)
563 or else Is_Pure (Unit_Entity)
564 or else Is_Shared_Passive (Unit_Entity)
565 or else
566 ((Is_Remote_Types (Unit_Entity)
567 or else Is_Remote_Call_Interface (Unit_Entity))
568 and then Ekind (Unit_Entity) = E_Package
569 and then Unit_Kind /= N_Package_Body
570 and then not In_Package_Body (Unit_Entity)
571 and then not In_Instance));
572 end In_Preelaborated_Unit;
574 ------------------
575 -- In_Pure_Unit --
576 ------------------
578 function In_Pure_Unit return Boolean is
579 begin
580 return Is_Pure (Current_Scope);
581 end In_Pure_Unit;
583 ------------------------
584 -- In_RCI_Declaration --
585 ------------------------
587 function In_RCI_Declaration return Boolean is
588 begin
589 return Is_Remote_Call_Interface (Current_Scope)
590 and then In_Package_Declaration;
591 end In_RCI_Declaration;
593 -----------------------
594 -- In_RT_Declaration --
595 -----------------------
597 function In_RT_Declaration return Boolean is
598 begin
599 return Is_Remote_Types (Current_Scope) and then In_Package_Declaration;
600 end In_RT_Declaration;
602 ----------------------------
603 -- In_Shared_Passive_Unit --
604 ----------------------------
606 function In_Shared_Passive_Unit return Boolean is
607 Unit_Entity : constant Entity_Id := Current_Scope;
609 begin
610 return Is_Shared_Passive (Unit_Entity);
611 end In_Shared_Passive_Unit;
613 ---------------------------------------
614 -- In_Subprogram_Task_Protected_Unit --
615 ---------------------------------------
617 function In_Subprogram_Task_Protected_Unit return Boolean is
618 E : Entity_Id;
620 begin
621 -- The following is to verify that a declaration is inside
622 -- subprogram, generic subprogram, task unit, protected unit.
623 -- Used to validate if a lib. unit is Pure. RM 10.2.1(16).
625 -- Use scope chain to check successively outer scopes
627 E := Current_Scope;
628 loop
629 if Is_Subprogram_Or_Generic_Subprogram (E)
630 or else
631 Is_Concurrent_Type (E)
632 then
633 return True;
635 elsif E = Standard_Standard then
636 return False;
637 end if;
639 E := Scope (E);
640 end loop;
641 end In_Subprogram_Task_Protected_Unit;
643 -------------------------------
644 -- Is_Non_Remote_Access_Type --
645 -------------------------------
647 function Is_Non_Remote_Access_Type (E : Entity_Id) return Boolean is
648 U_E : constant Entity_Id := Underlying_Type (Base_Type (E));
649 -- Use full view of base type to handle subtypes properly.
651 begin
652 if No (U_E) then
654 -- This case arises for the case of a generic formal type, in which
655 -- case E.2.2(8) rules will be enforced at instantiation time.
657 return False;
658 end if;
660 return Is_Access_Type (U_E)
661 and then not Is_Remote_Access_To_Class_Wide_Type (U_E)
662 and then not Is_Remote_Access_To_Subprogram_Type (U_E);
663 end Is_Non_Remote_Access_Type;
665 ---------------------------
666 -- No_External_Streaming --
667 ---------------------------
669 function No_External_Streaming (E : Entity_Id) return Boolean is
670 U_E : constant Entity_Id := Underlying_Type (E);
672 begin
673 if No (U_E) then
674 return False;
676 elsif Has_Read_Write_Attributes (E) then
678 -- Note: availability of stream attributes is tested on E, not U_E.
679 -- There may be stream attributes defined on U_E that are not visible
680 -- at the place where support of external streaming is tested.
682 return False;
684 elsif Has_Non_Remote_Access (U_E) then
685 return True;
686 end if;
688 return Is_Limited_Type (E);
689 end No_External_Streaming;
691 -------------------------------------
692 -- Set_Categorization_From_Pragmas --
693 -------------------------------------
695 procedure Set_Categorization_From_Pragmas (N : Node_Id) is
696 P : constant Node_Id := Parent (N);
697 S : constant Entity_Id := Current_Scope;
699 procedure Set_Parents (Visibility : Boolean);
700 -- If this is a child instance, the parents are not immediately
701 -- visible during analysis. Make them momentarily visible so that
702 -- the argument of the pragma can be resolved properly, and reset
703 -- afterwards.
705 -----------------
706 -- Set_Parents --
707 -----------------
709 procedure Set_Parents (Visibility : Boolean) is
710 Par : Entity_Id;
711 begin
712 Par := Scope (S);
713 while Present (Par) and then Par /= Standard_Standard loop
714 Set_Is_Immediately_Visible (Par, Visibility);
715 Par := Scope (Par);
716 end loop;
717 end Set_Parents;
719 -- Start of processing for Set_Categorization_From_Pragmas
721 begin
722 -- Deal with categorization pragmas in Pragmas of Compilation_Unit.
723 -- The purpose is to set categorization flags before analyzing the
724 -- unit itself, so as to diagnose violations of categorization as
725 -- we process each declaration, even though the pragma appears after
726 -- the unit.
728 if Nkind (P) /= N_Compilation_Unit then
729 return;
730 end if;
732 declare
733 PN : Node_Id;
735 begin
736 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then
737 Set_Parents (True);
738 end if;
740 PN := First (Pragmas_After (Aux_Decls_Node (P)));
741 while Present (PN) loop
743 -- Skip implicit types that may have been introduced by
744 -- previous analysis.
746 if Nkind (PN) = N_Pragma then
747 case Get_Pragma_Id (PN) is
748 when Pragma_All_Calls_Remote
749 | Pragma_Preelaborate
750 | Pragma_Pure
751 | Pragma_Remote_Call_Interface
752 | Pragma_Remote_Types
753 | Pragma_Shared_Passive
755 Analyze (PN);
757 when others =>
758 null;
759 end case;
760 end if;
762 Next (PN);
763 end loop;
765 if Is_Child_Unit (S) and then Is_Generic_Instance (S) then
766 Set_Parents (False);
767 end if;
768 end;
769 end Set_Categorization_From_Pragmas;
771 -----------------------------------
772 -- Set_Categorization_From_Scope --
773 -----------------------------------
775 procedure Set_Categorization_From_Scope (E : Entity_Id; Scop : Entity_Id) is
776 Declaration : Node_Id := Empty;
777 Specification : Node_Id := Empty;
779 begin
780 -- Do not modify the purity of an internally generated entity if it has
781 -- been explicitly marked as pure for optimization purposes.
783 if not Has_Pragma_Pure_Function (E) then
784 Set_Is_Pure
785 (E, Is_Pure (Scop) and then Is_Library_Level_Entity (E));
786 end if;
788 if not Is_Remote_Call_Interface (E) then
789 if Ekind (E) in Subprogram_Kind then
790 Declaration := Unit_Declaration_Node (E);
792 if Nkind_In (Declaration, N_Subprogram_Body,
793 N_Subprogram_Renaming_Declaration)
794 then
795 Specification := Corresponding_Spec (Declaration);
796 end if;
797 end if;
799 -- A subprogram body or renaming-as-body is a remote call interface
800 -- if it serves as the completion of a subprogram declaration that
801 -- is a remote call interface.
803 if Nkind (Specification) in N_Entity then
804 Set_Is_Remote_Call_Interface
805 (E, Is_Remote_Call_Interface (Specification));
807 -- A subprogram declaration is a remote call interface when it is
808 -- declared within the visible part of, or declared by, a library
809 -- unit declaration that is a remote call interface.
811 else
812 Set_Is_Remote_Call_Interface
813 (E, Is_Remote_Call_Interface (Scop)
814 and then not (In_Private_Part (Scop)
815 or else In_Package_Body (Scop)));
816 end if;
817 end if;
819 Set_Is_Remote_Types
820 (E, Is_Remote_Types (Scop)
821 and then not (In_Private_Part (Scop)
822 or else In_Package_Body (Scop)));
823 end Set_Categorization_From_Scope;
825 ------------------------------
826 -- Static_Discriminant_Expr --
827 ------------------------------
829 -- We need to accommodate a Why_Not_Static call somehow here ???
831 function Static_Discriminant_Expr (L : List_Id) return Boolean is
832 Discriminant_Spec : Node_Id;
834 begin
835 Discriminant_Spec := First (L);
836 while Present (Discriminant_Spec) loop
837 if Present (Expression (Discriminant_Spec))
838 and then
839 not Is_OK_Static_Expression (Expression (Discriminant_Spec))
840 then
841 return False;
842 end if;
844 Next (Discriminant_Spec);
845 end loop;
847 return True;
848 end Static_Discriminant_Expr;
850 --------------------------------------
851 -- Validate_Access_Type_Declaration --
852 --------------------------------------
854 procedure Validate_Access_Type_Declaration (T : Entity_Id; N : Node_Id) is
855 Def : constant Node_Id := Type_Definition (N);
857 begin
858 case Nkind (Def) is
860 -- Access to subprogram case
862 when N_Access_To_Subprogram_Definition =>
864 -- A pure library_item must not contain the declaration of a
865 -- named access type, except within a subprogram, generic
866 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
868 -- This test is skipped in Ada 2005 (see AI-366)
870 if Ada_Version < Ada_2005
871 and then Comes_From_Source (T)
872 and then In_Pure_Unit
873 and then not In_Subprogram_Task_Protected_Unit
874 then
875 Error_Msg_N ("named access type not allowed in pure unit", T);
876 end if;
878 -- Access to object case
880 when N_Access_To_Object_Definition =>
881 if Comes_From_Source (T)
882 and then In_Pure_Unit
883 and then not In_Subprogram_Task_Protected_Unit
884 then
885 -- We can't give the message yet, since the type is not frozen
886 -- and in Ada 2005 mode, access types are allowed in pure units
887 -- if the type has no storage pool (see AI-366). So we set a
888 -- flag which will be checked at freeze time.
890 Set_Is_Pure_Unit_Access_Type (T);
891 end if;
893 -- Check for RCI or RT unit type declaration: declaration of an
894 -- access-to-object type is illegal unless it is a general access
895 -- type that designates a class-wide limited private type.
896 -- Note that constraints on the primitive subprograms of the
897 -- designated tagged type are not enforced here but in
898 -- Validate_RACW_Primitives, which is done separately because the
899 -- designated type might not be frozen (and therefore its
900 -- primitive operations might not be completely known) at the
901 -- point of the RACW declaration.
903 Validate_Remote_Access_Object_Type_Declaration (T);
905 -- Check for shared passive unit type declaration. It should
906 -- not contain the declaration of access to class wide type,
907 -- access to task type and access to protected type with entry.
909 Validate_SP_Access_Object_Type_Decl (T);
911 when others =>
912 null;
913 end case;
915 -- Set categorization flag from package on entity as well, to allow
916 -- easy checks later on for required validations of RCI or RT units.
917 -- This is only done for entities that are in the original source.
919 if Comes_From_Source (T)
920 and then not (In_Package_Body (Scope (T))
921 or else In_Private_Part (Scope (T)))
922 then
923 Set_Is_Remote_Call_Interface
924 (T, Is_Remote_Call_Interface (Scope (T)));
925 Set_Is_Remote_Types
926 (T, Is_Remote_Types (Scope (T)));
927 end if;
928 end Validate_Access_Type_Declaration;
930 ----------------------------
931 -- Validate_Ancestor_Part --
932 ----------------------------
934 procedure Validate_Ancestor_Part (N : Node_Id) is
935 A : constant Node_Id := Ancestor_Part (N);
936 T : constant Entity_Id := Entity (A);
938 begin
939 if In_Preelaborated_Unit
940 and then not In_Subprogram_Or_Concurrent_Unit
941 and then (not Inside_A_Generic
942 or else Present (Enclosing_Generic_Body (N)))
943 then
944 -- If the type is private, it must have the Ada 2005 pragma
945 -- Has_Preelaborable_Initialization.
947 -- The check is omitted within predefined units. This is probably
948 -- obsolete code to fix the Ada 95 weakness in this area ???
950 if Is_Private_Type (T)
951 and then not Has_Pragma_Preelab_Init (T)
952 and then not Is_Internal_File_Name
953 (Unit_File_Name (Get_Source_Unit (N)))
954 then
955 Error_Msg_N
956 ("private ancestor type not allowed in preelaborated unit", A);
958 elsif Is_Record_Type (T) then
959 if Nkind (Parent (T)) = N_Full_Type_Declaration then
960 Check_Non_Static_Default_Expr
961 (Type_Definition (Parent (T)), A);
962 end if;
963 end if;
964 end if;
965 end Validate_Ancestor_Part;
967 ----------------------------------------
968 -- Validate_Categorization_Dependency --
969 ----------------------------------------
971 procedure Validate_Categorization_Dependency
972 (N : Node_Id;
973 E : Entity_Id)
975 K : constant Node_Kind := Nkind (N);
976 P : Node_Id := Parent (N);
977 U : Entity_Id := E;
978 Is_Subunit : constant Boolean := Nkind (P) = N_Subunit;
980 begin
981 -- Only validate library units and subunits. For subunits, checks
982 -- concerning withed units apply to the parent compilation unit.
984 if Is_Subunit then
985 P := Parent (P);
986 U := Scope (E);
988 while Present (U)
989 and then not Is_Compilation_Unit (U)
990 and then not Is_Child_Unit (U)
991 loop
992 U := Scope (U);
993 end loop;
994 end if;
996 if Nkind (P) /= N_Compilation_Unit then
997 return;
998 end if;
1000 -- Body of RCI unit does not need validation
1002 if Is_Remote_Call_Interface (E)
1003 and then Nkind_In (N, N_Package_Body, N_Subprogram_Body)
1004 then
1005 return;
1006 end if;
1008 -- Ada 2005 (AI-50217): Process explicit non-limited with_clauses
1010 declare
1011 Item : Node_Id;
1012 Entity_Of_Withed : Entity_Id;
1014 begin
1015 Item := First (Context_Items (P));
1016 while Present (Item) loop
1017 if Nkind (Item) = N_With_Clause
1018 and then
1019 not (Implicit_With (Item)
1020 or else Limited_Present (Item)
1022 -- Skip if error already posted on the WITH clause (in
1023 -- which case the Name attribute may be invalid). In
1024 -- particular, this fixes the problem of hanging in the
1025 -- presence of a WITH clause on a child that is an
1026 -- illegal generic instantiation.
1028 or else Error_Posted (Item))
1029 and then
1030 not (Try_Semantics
1032 -- Skip processing malformed trees
1034 and then Nkind (Name (Item)) not in N_Has_Entity)
1035 then
1036 Entity_Of_Withed := Entity (Name (Item));
1037 Check_Categorization_Dependencies
1038 (U, Entity_Of_Withed, Item, Is_Subunit);
1039 end if;
1041 Next (Item);
1042 end loop;
1043 end;
1045 -- Child depends on parent; therefore parent should also be categorized
1046 -- and satisfy the dependency hierarchy.
1048 -- Check if N is a child spec
1050 if (K in N_Generic_Declaration or else
1051 K in N_Generic_Instantiation or else
1052 K in N_Generic_Renaming_Declaration or else
1053 K = N_Package_Declaration or else
1054 K = N_Package_Renaming_Declaration or else
1055 K = N_Subprogram_Declaration or else
1056 K = N_Subprogram_Renaming_Declaration)
1057 and then Present (Parent_Spec (N))
1058 then
1059 Check_Categorization_Dependencies (E, Scope (E), N, False);
1061 -- Verify that public child of an RCI library unit must also be an
1062 -- RCI library unit (RM E.2.3(15)).
1064 if Is_Remote_Call_Interface (Scope (E))
1065 and then not Private_Present (P)
1066 and then not Is_Remote_Call_Interface (E)
1067 then
1068 Error_Msg_N ("public child of rci unit must also be rci unit", N);
1069 end if;
1070 end if;
1071 end Validate_Categorization_Dependency;
1073 --------------------------------
1074 -- Validate_Controlled_Object --
1075 --------------------------------
1077 procedure Validate_Controlled_Object (E : Entity_Id) is
1078 begin
1079 -- Don't need this check in Ada 2005 mode, where this is all taken
1080 -- care of by the mechanism for Preelaborable Initialization.
1082 if Ada_Version >= Ada_2005 then
1083 return;
1084 end if;
1086 -- For now, never apply this check for internal GNAT units, since we
1087 -- have a number of cases in the library where we are stuck with objects
1088 -- of this type, and the RM requires Preelaborate.
1090 -- For similar reasons, we only do this check for source entities, since
1091 -- we generate entities of this type in some situations.
1093 -- Note that the 10.2.1(9) restrictions are not relevant to us anyway.
1094 -- We have to enforce them for RM compatibility, but we have no trouble
1095 -- accepting these objects and doing the right thing. Note that there is
1096 -- no requirement that Preelaborate not actually generate any code.
1098 if In_Preelaborated_Unit
1099 and then not Debug_Flag_PP
1100 and then Comes_From_Source (E)
1101 and then not
1102 Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (E)))
1103 and then (not Inside_A_Generic
1104 or else Present (Enclosing_Generic_Body (E)))
1105 and then not Is_Protected_Type (Etype (E))
1106 then
1107 Error_Msg_N
1108 ("library level controlled object not allowed in " &
1109 "preelaborated unit", E);
1110 end if;
1111 end Validate_Controlled_Object;
1113 --------------------------------------
1114 -- Validate_Null_Statement_Sequence --
1115 --------------------------------------
1117 procedure Validate_Null_Statement_Sequence (N : Node_Id) is
1118 Item : Node_Id;
1120 begin
1121 if In_Preelaborated_Unit then
1122 Item := First (Statements (Handled_Statement_Sequence (N)));
1123 while Present (Item) loop
1124 if Nkind (Item) /= N_Label
1125 and then Nkind (Item) /= N_Null_Statement
1126 then
1127 -- In GNAT mode, this is a warning, allowing the run-time
1128 -- to judiciously bypass this error condition.
1130 Error_Msg_Warn := GNAT_Mode;
1131 Error_Msg_N
1132 ("<<statements not allowed in preelaborated unit", Item);
1134 exit;
1135 end if;
1137 Next (Item);
1138 end loop;
1139 end if;
1140 end Validate_Null_Statement_Sequence;
1142 ---------------------------------
1143 -- Validate_Object_Declaration --
1144 ---------------------------------
1146 procedure Validate_Object_Declaration (N : Node_Id) is
1147 Id : constant Entity_Id := Defining_Identifier (N);
1148 E : constant Node_Id := Expression (N);
1149 Odf : constant Node_Id := Object_Definition (N);
1150 T : constant Entity_Id := Etype (Id);
1152 begin
1153 -- Verify that any access to subprogram object does not have in its
1154 -- subprogram profile access type parameters or limited parameters
1155 -- without Read and Write attributes (E.2.3(13)).
1157 Validate_RCI_Subprogram_Declaration (N);
1159 -- Check that if we are in preelaborated elaboration code, then we
1160 -- do not have an instance of a default initialized private, task or
1161 -- protected object declaration which would violate (RM 10.2.1(9)).
1162 -- Note that constants are never default initialized (and the test
1163 -- below also filters out deferred constants). A variable is default
1164 -- initialized if it does *not* have an initialization expression.
1166 -- Filter out cases that are not declaration of a variable from source
1168 if Nkind (N) /= N_Object_Declaration
1169 or else Constant_Present (N)
1170 or else not Comes_From_Source (Id)
1171 then
1172 return;
1173 end if;
1175 -- Exclude generic specs from the checks (this will get rechecked
1176 -- on instantiations).
1178 if Inside_A_Generic and then No (Enclosing_Generic_Body (Id)) then
1179 return;
1180 end if;
1182 -- Required checks for declaration that is in a preelaborated package
1183 -- and is not within some subprogram.
1185 if In_Preelaborated_Unit
1186 and then not In_Subprogram_Or_Concurrent_Unit
1187 then
1188 -- Check for default initialized variable case. Note that in
1189 -- accordance with (RM B.1(24)) imported objects are not subject to
1190 -- default initialization.
1191 -- If the initialization does not come from source and is an
1192 -- aggregate, it is a static initialization that replaces an
1193 -- implicit call, and must be treated as such.
1195 if Present (E)
1196 and then (Comes_From_Source (E) or else Nkind (E) /= N_Aggregate)
1197 then
1198 null;
1200 elsif Is_Imported (Id) then
1201 null;
1203 else
1204 declare
1205 Ent : Entity_Id := T;
1207 begin
1208 -- An array whose component type is a record with nonstatic
1209 -- default expressions is a violation, so we get the array's
1210 -- component type.
1212 if Is_Array_Type (Ent) then
1213 declare
1214 Comp_Type : Entity_Id;
1216 begin
1217 Comp_Type := Component_Type (Ent);
1218 while Is_Array_Type (Comp_Type) loop
1219 Comp_Type := Component_Type (Comp_Type);
1220 end loop;
1222 Ent := Comp_Type;
1223 end;
1224 end if;
1226 -- Object decl. that is of record type and has no default expr.
1227 -- should check if there is any non-static default expression
1228 -- in component decl. of the record type decl.
1230 if Is_Record_Type (Ent) then
1231 if Nkind (Parent (Ent)) = N_Full_Type_Declaration then
1232 Check_Non_Static_Default_Expr
1233 (Type_Definition (Parent (Ent)), N);
1235 elsif Nkind (Odf) = N_Subtype_Indication
1236 and then not Is_Array_Type (T)
1237 and then not Is_Private_Type (T)
1238 then
1239 Check_Non_Static_Default_Expr (Type_Definition
1240 (Parent (Entity (Subtype_Mark (Odf)))), N);
1241 end if;
1242 end if;
1244 -- Check for invalid use of private object. Note that Ada 2005
1245 -- AI-161 modifies the rules for Ada 2005, including the use of
1246 -- the new pragma Preelaborable_Initialization.
1248 if Is_Private_Type (Ent)
1249 or else Depends_On_Private (Ent)
1250 then
1251 -- Case where type has preelaborable initialization which
1252 -- means that a pragma Preelaborable_Initialization was
1253 -- given for the private type.
1255 if Relaxed_RM_Semantics then
1257 -- In relaxed mode, do not issue these messages, this
1258 -- is basically similar to the GNAT_Mode test below.
1260 null;
1262 elsif Has_Preelaborable_Initialization (Ent) then
1264 -- But for the predefined units, we will ignore this
1265 -- status unless we are in Ada 2005 mode since we want
1266 -- Ada 95 compatible behavior, in which the entities
1267 -- marked with this pragma in the predefined library are
1268 -- not treated specially.
1270 if Ada_Version < Ada_2005 then
1271 Error_Msg_N
1272 ("private object not allowed in preelaborated unit",
1274 Error_Msg_N ("\(would be legal in Ada 2005 mode)", N);
1275 end if;
1277 -- Type does not have preelaborable initialization
1279 else
1280 -- We allow this when compiling in GNAT mode to make life
1281 -- easier for some cases where it would otherwise be hard
1282 -- to be exactly valid Ada.
1284 if not GNAT_Mode then
1285 Error_Msg_N
1286 ("private object not allowed in preelaborated unit",
1289 -- Add a message if it would help to provide a pragma
1290 -- Preelaborable_Initialization on the type of the
1291 -- object (which would make it legal in Ada 2005).
1293 -- If the type has no full view (generic type, or
1294 -- previous error), the warning does not apply.
1296 if Is_Private_Type (Ent)
1297 and then Present (Full_View (Ent))
1298 and then
1299 Has_Preelaborable_Initialization (Full_View (Ent))
1300 then
1301 Error_Msg_Sloc := Sloc (Ent);
1303 if Ada_Version >= Ada_2005 then
1304 Error_Msg_NE
1305 ("\would be legal if pragma Preelaborable_" &
1306 "Initialization given for & #", N, Ent);
1307 else
1308 Error_Msg_NE
1309 ("\would be legal in Ada 2005 if pragma " &
1310 "Preelaborable_Initialization given for & #",
1311 N, Ent);
1312 end if;
1313 end if;
1314 end if;
1315 end if;
1317 -- Access to Task or Protected type
1319 elsif Is_Entity_Name (Odf)
1320 and then Present (Etype (Odf))
1321 and then Is_Access_Type (Etype (Odf))
1322 then
1323 Ent := Designated_Type (Etype (Odf));
1325 elsif Is_Entity_Name (Odf) then
1326 Ent := Entity (Odf);
1328 elsif Nkind (Odf) = N_Subtype_Indication then
1329 Ent := Etype (Subtype_Mark (Odf));
1331 elsif Nkind (Odf) = N_Constrained_Array_Definition then
1332 Ent := Component_Type (T);
1333 end if;
1335 if Is_Task_Type (Ent)
1336 or else (Is_Protected_Type (Ent) and then Has_Entries (Ent))
1337 then
1338 Error_Msg_N
1339 ("concurrent object not allowed in preelaborated unit",
1341 return;
1342 end if;
1343 end;
1344 end if;
1346 -- Non-static discriminants not allowed in preelaborated unit.
1347 -- Objects of a controlled type with a user-defined Initialize
1348 -- are forbidden as well.
1350 if Is_Record_Type (Etype (Id)) then
1351 declare
1352 ET : constant Entity_Id := Etype (Id);
1353 EE : constant Entity_Id := Etype (Etype (Id));
1354 PEE : Node_Id;
1356 begin
1357 if Has_Discriminants (ET) and then Present (EE) then
1358 PEE := Parent (EE);
1360 if Nkind (PEE) = N_Full_Type_Declaration
1361 and then not Static_Discriminant_Expr
1362 (Discriminant_Specifications (PEE))
1363 then
1364 Error_Msg_N
1365 ("non-static discriminant in preelaborated unit",
1366 PEE);
1367 end if;
1368 end if;
1370 -- For controlled type or type with controlled component, check
1371 -- preelaboration flag, as there may be a non-null Initialize
1372 -- primitive. For language versions earlier than Ada 2005,
1373 -- there is no notion of preelaborable initialization, and
1374 -- Validate_Controlled_Object is used to enforce rules for
1375 -- controlled objects.
1377 if (Is_Controlled (ET) or else Has_Controlled_Component (ET))
1378 and then Ada_Version >= Ada_2005
1379 and then not Has_Preelaborable_Initialization (ET)
1380 then
1381 Error_Msg_NE
1382 ("controlled type& does not have"
1383 & " preelaborable initialization", N, ET);
1384 end if;
1385 end;
1387 end if;
1388 end if;
1390 -- A pure library_item must not contain the declaration of any variable
1391 -- except within a subprogram, generic subprogram, task unit, or
1392 -- protected unit (RM 10.2.1(16)).
1394 if In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit then
1395 Error_Msg_N ("declaration of variable not allowed in pure unit", N);
1397 elsif not In_Private_Part (Id) then
1399 -- The visible part of an RCI library unit must not contain the
1400 -- declaration of a variable (RM E.1.3(9)).
1402 if In_RCI_Declaration then
1403 Error_Msg_N ("visible variable not allowed in 'R'C'I unit", N);
1405 -- The visible part of a Shared Passive library unit must not contain
1406 -- the declaration of a variable (RM E.2.2(7)).
1408 elsif In_RT_Declaration then
1409 Error_Msg_N
1410 ("visible variable not allowed in remote types unit", N);
1411 end if;
1412 end if;
1413 end Validate_Object_Declaration;
1415 -----------------------------
1416 -- Validate_RACW_Primitive --
1417 -----------------------------
1419 procedure Validate_RACW_Primitive
1420 (Subp : Entity_Id;
1421 RACW : Entity_Id)
1423 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id);
1424 -- Diagnose illegality on N. If RACW is present, report the error on it
1425 -- rather than on N.
1427 -------------------------
1428 -- Illegal_Remote_Subp --
1429 -------------------------
1431 procedure Illegal_Remote_Subp (Msg : String; N : Node_Id) is
1432 begin
1433 if Present (RACW) then
1434 if not Error_Posted (RACW) then
1435 Error_Msg_N
1436 ("illegal remote access to class-wide type&", RACW);
1437 end if;
1439 Error_Msg_Sloc := Sloc (N);
1440 Error_Msg_NE ("\\" & Msg & " in primitive& #", RACW, Subp);
1442 else
1443 Error_Msg_NE (Msg & " in remote subprogram&", N, Subp);
1444 end if;
1445 end Illegal_Remote_Subp;
1447 Rtyp : Entity_Id;
1448 Param : Node_Id;
1449 Param_Spec : Node_Id;
1450 Param_Type : Entity_Id;
1452 -- Start of processing for Validate_RACW_Primitive
1454 begin
1455 -- Check return type
1457 if Ekind (Subp) = E_Function then
1458 Rtyp := Etype (Subp);
1460 -- AI05-0101 (Binding Interpretation): The result type of a remote
1461 -- function must either support external streaming or be a
1462 -- controlling access result type.
1464 if Has_Controlling_Result (Subp) then
1465 null;
1467 elsif Ekind (Rtyp) = E_Anonymous_Access_Type then
1468 Illegal_Remote_Subp ("anonymous access result", Rtyp);
1470 elsif Is_Limited_Type (Rtyp) then
1471 if No (TSS (Rtyp, TSS_Stream_Read))
1472 or else
1473 No (TSS (Rtyp, TSS_Stream_Write))
1474 then
1475 Illegal_Remote_Subp
1476 ("limited return type must have Read and Write attributes",
1477 Parent (Subp));
1478 Explain_Limited_Type (Rtyp, Parent (Subp));
1479 end if;
1481 -- Check that the return type supports external streaming
1483 elsif No_External_Streaming (Rtyp)
1484 and then not Error_Posted (Rtyp)
1485 then
1486 Illegal_Remote_Subp ("return type containing non-remote access "
1487 & "must have Read and Write attributes",
1488 Parent (Subp));
1489 end if;
1490 end if;
1492 Param := First_Formal (Subp);
1493 while Present (Param) loop
1495 -- Now find out if this parameter is a controlling parameter
1497 Param_Spec := Parent (Param);
1498 Param_Type := Etype (Param);
1500 if Is_Controlling_Formal (Param) then
1502 -- It is a controlling parameter, so specific checks below do not
1503 -- apply.
1505 null;
1507 elsif Ekind_In (Param_Type, E_Anonymous_Access_Type,
1508 E_Anonymous_Access_Subprogram_Type)
1509 then
1510 -- From RM E.2.2(14), no anonymous access parameter other than
1511 -- controlling ones may be used (because an anonymous access
1512 -- type never supports external streaming).
1514 Illegal_Remote_Subp
1515 ("non-controlling access parameter", Param_Spec);
1517 elsif No_External_Streaming (Param_Type)
1518 and then not Error_Posted (Param_Type)
1519 then
1520 Illegal_Remote_Subp ("formal parameter in remote subprogram must "
1521 & "support external streaming", Param_Spec);
1522 end if;
1524 -- Check next parameter in this subprogram
1526 Next_Formal (Param);
1527 end loop;
1528 end Validate_RACW_Primitive;
1530 ------------------------------
1531 -- Validate_RACW_Primitives --
1532 ------------------------------
1534 procedure Validate_RACW_Primitives (T : Entity_Id) is
1535 Desig_Type : Entity_Id;
1536 Primitive_Subprograms : Elist_Id;
1537 Subprogram_Elmt : Elmt_Id;
1538 Subprogram : Entity_Id;
1540 begin
1541 Desig_Type := Etype (Designated_Type (T));
1543 -- No action needed for concurrent types
1545 if Is_Concurrent_Type (Desig_Type) then
1546 return;
1547 end if;
1549 Primitive_Subprograms := Primitive_Operations (Desig_Type);
1551 Subprogram_Elmt := First_Elmt (Primitive_Subprograms);
1552 while Subprogram_Elmt /= No_Elmt loop
1553 Subprogram := Node (Subprogram_Elmt);
1555 if Is_Predefined_Dispatching_Operation (Subprogram)
1556 or else Is_Hidden (Subprogram)
1557 then
1558 goto Next_Subprogram;
1559 end if;
1561 Validate_RACW_Primitive (Subp => Subprogram, RACW => T);
1563 <<Next_Subprogram>>
1564 Next_Elmt (Subprogram_Elmt);
1565 end loop;
1566 end Validate_RACW_Primitives;
1568 -------------------------------
1569 -- Validate_RCI_Declarations --
1570 -------------------------------
1572 procedure Validate_RCI_Declarations (P : Entity_Id) is
1573 E : Entity_Id;
1575 begin
1576 E := First_Entity (P);
1577 while Present (E) loop
1578 if Comes_From_Source (E) then
1579 if Is_Limited_Type (E) then
1580 Error_Msg_N
1581 ("limited type not allowed in rci unit", Parent (E));
1582 Explain_Limited_Type (E, Parent (E));
1584 elsif Ekind_In (E, E_Generic_Function,
1585 E_Generic_Package,
1586 E_Generic_Procedure)
1587 then
1588 Error_Msg_N ("generic declaration not allowed in rci unit",
1589 Parent (E));
1591 elsif (Ekind (E) = E_Function or else Ekind (E) = E_Procedure)
1592 and then Has_Pragma_Inline (E)
1593 then
1594 Error_Msg_N
1595 ("inlined subprogram not allowed in rci unit", Parent (E));
1597 -- Inner packages that are renamings need not be checked. Generic
1598 -- RCI packages are subject to the checks, but entities that come
1599 -- from formal packages are not part of the visible declarations
1600 -- of the package and are not checked.
1602 elsif Ekind (E) = E_Package then
1603 if Present (Renamed_Entity (E)) then
1604 null;
1606 elsif Ekind (P) /= E_Generic_Package
1607 or else List_Containing (Unit_Declaration_Node (E)) /=
1608 Generic_Formal_Declarations
1609 (Unit_Declaration_Node (P))
1610 then
1611 Validate_RCI_Declarations (E);
1612 end if;
1613 end if;
1614 end if;
1616 Next_Entity (E);
1617 end loop;
1618 end Validate_RCI_Declarations;
1620 -----------------------------------------
1621 -- Validate_RCI_Subprogram_Declaration --
1622 -----------------------------------------
1624 procedure Validate_RCI_Subprogram_Declaration (N : Node_Id) is
1625 K : constant Node_Kind := Nkind (N);
1626 Profile : List_Id;
1627 Id : constant Entity_Id := Defining_Entity (N);
1628 Param_Spec : Node_Id;
1629 Param_Type : Entity_Id;
1630 Error_Node : Node_Id := N;
1632 begin
1633 -- This procedure enforces rules on subprogram and access to subprogram
1634 -- declarations in RCI units. These rules do not apply to expander
1635 -- generated routines, which are not remote subprograms. It is called:
1637 -- 1. from Analyze_Subprogram_Declaration.
1638 -- 2. from Validate_Object_Declaration (access to subprogram).
1640 if not (Comes_From_Source (N)
1641 and then In_RCI_Declaration
1642 and then not In_Private_Part (Scope (Id)))
1643 then
1644 return;
1645 end if;
1647 if K = N_Subprogram_Declaration then
1648 Profile := Parameter_Specifications (Specification (N));
1650 else
1651 pragma Assert (K = N_Object_Declaration);
1653 -- The above assertion is dubious, the visible declarations of an
1654 -- RCI unit never contain an object declaration, this should be an
1655 -- ACCESS-to-object declaration???
1657 if Nkind (Id) = N_Defining_Identifier
1658 and then Nkind (Parent (Etype (Id))) = N_Full_Type_Declaration
1659 and then Ekind (Etype (Id)) = E_Access_Subprogram_Type
1660 then
1661 Profile :=
1662 Parameter_Specifications (Type_Definition (Parent (Etype (Id))));
1663 else
1664 return;
1665 end if;
1666 end if;
1668 -- Iterate through the parameter specification list, checking that
1669 -- no access parameter and no limited type parameter in the list.
1670 -- RM E.2.3(14).
1672 if Present (Profile) then
1673 Param_Spec := First (Profile);
1674 while Present (Param_Spec) loop
1675 Param_Type := Etype (Defining_Identifier (Param_Spec));
1677 if Ekind (Param_Type) = E_Anonymous_Access_Type then
1678 if K = N_Subprogram_Declaration then
1679 Error_Node := Param_Spec;
1680 end if;
1682 -- Report error only if declaration is in source program
1684 if Comes_From_Source (Id) then
1685 Error_Msg_N
1686 ("subprogram in 'R'C'I unit cannot have access parameter",
1687 Error_Node);
1688 end if;
1690 -- For a limited private type parameter, we check only the private
1691 -- declaration and ignore full type declaration, unless this is
1692 -- the only declaration for the type, e.g., as a limited record.
1694 elsif No_External_Streaming (Param_Type) then
1695 if K = N_Subprogram_Declaration then
1696 Error_Node := Param_Spec;
1697 end if;
1699 Error_Msg_NE
1700 ("formal of remote subprogram& "
1701 & "must support external streaming",
1702 Error_Node, Id);
1703 if Is_Limited_Type (Param_Type) then
1704 Explain_Limited_Type (Param_Type, Error_Node);
1705 end if;
1706 end if;
1708 Next (Param_Spec);
1709 end loop;
1710 end if;
1712 if Ekind (Id) = E_Function
1713 and then Ekind (Etype (Id)) = E_Anonymous_Access_Type
1714 and then Comes_From_Source (Id)
1715 then
1716 Error_Msg_N
1717 ("function in 'R'C'I unit cannot have access result",
1718 Error_Node);
1719 end if;
1720 end Validate_RCI_Subprogram_Declaration;
1722 ----------------------------------------------------
1723 -- Validate_Remote_Access_Object_Type_Declaration --
1724 ----------------------------------------------------
1726 procedure Validate_Remote_Access_Object_Type_Declaration (T : Entity_Id) is
1727 Direct_Designated_Type : Entity_Id;
1728 Desig_Type : Entity_Id;
1730 begin
1731 -- We are called from Analyze_Full_Type_Declaration, and the Nkind of
1732 -- the given node is N_Access_To_Object_Definition.
1734 if not Comes_From_Source (T)
1735 or else (not In_RCI_Declaration and then not In_RT_Declaration)
1736 then
1737 return;
1738 end if;
1740 -- An access definition in the private part of a package is not a
1741 -- remote access type. Restrictions related to external streaming
1742 -- support for non-remote access types are enforced elsewhere. Note
1743 -- that In_Private_Part is never set on type entities: check flag
1744 -- on enclosing scope.
1746 if In_Private_Part (Scope (T)) then
1747 return;
1748 end if;
1750 -- Check RCI or RT unit type declaration. It may not contain the
1751 -- declaration of an access-to-object type unless it is a general access
1752 -- type that designates a class-wide limited private type or subtype.
1753 -- There are also constraints on the primitive subprograms of the
1754 -- class-wide type (RM E.2.2(14), see Validate_RACW_Primitives).
1756 if Ekind (T) /= E_General_Access_Type
1757 or else not Is_Class_Wide_Type (Designated_Type (T))
1758 then
1759 if In_RCI_Declaration then
1760 Error_Msg_N
1761 ("error in access type in Remote_Call_Interface unit", T);
1762 else
1763 Error_Msg_N
1764 ("error in access type in Remote_Types unit", T);
1765 end if;
1767 Error_Msg_N ("\must be general access to class-wide type", T);
1768 return;
1769 end if;
1771 Direct_Designated_Type := Designated_Type (T);
1772 Desig_Type := Etype (Direct_Designated_Type);
1774 -- Why is this check not in Validate_Remote_Access_To_Class_Wide_Type???
1776 if not Is_Valid_Remote_Object_Type (Desig_Type) then
1777 Error_Msg_N
1778 ("error in designated type of remote access to class-wide type", T);
1779 Error_Msg_N
1780 ("\must be tagged limited private or private extension", T);
1781 return;
1782 end if;
1783 end Validate_Remote_Access_Object_Type_Declaration;
1785 -----------------------------------------------
1786 -- Validate_Remote_Access_To_Class_Wide_Type --
1787 -----------------------------------------------
1789 procedure Validate_Remote_Access_To_Class_Wide_Type (N : Node_Id) is
1790 K : constant Node_Kind := Nkind (N);
1791 PK : constant Node_Kind := Nkind (Parent (N));
1792 E : Entity_Id;
1794 begin
1795 -- This subprogram enforces the checks in (RM E.2.2(8)) for certain uses
1796 -- of class-wide limited private types.
1798 -- Storage_Pool and Storage_Size are not defined for such types
1800 -- The expected type of allocator must not be such a type.
1802 -- The actual parameter of generic instantiation must not be such a
1803 -- type if the formal parameter is of an access type.
1805 -- On entry, there are several cases:
1807 -- 1. called from sem_attr Analyze_Attribute where attribute name is
1808 -- either Storage_Pool or Storage_Size.
1810 -- 2. called from exp_ch4 Expand_N_Allocator
1812 -- 3. called from sem_ch4 Analyze_Explicit_Dereference
1814 -- 4. called from sem_res Resolve_Actuals
1816 if K = N_Attribute_Reference then
1817 E := Etype (Prefix (N));
1819 if Is_Remote_Access_To_Class_Wide_Type (E) then
1820 Error_Msg_N ("incorrect attribute of remote operand", N);
1821 return;
1822 end if;
1824 elsif K = N_Allocator then
1825 E := Etype (N);
1827 if Is_Remote_Access_To_Class_Wide_Type (E) then
1828 Error_Msg_N ("incorrect expected remote type of allocator", N);
1829 return;
1830 end if;
1832 -- This subprogram also enforces the checks in E.2.2(13). A value of
1833 -- such type must not be dereferenced unless as controlling operand of
1834 -- a dispatching call. Explicit dereferences not coming from source are
1835 -- exempted from this checking because the expander produces them in
1836 -- some cases (such as for tag checks on dispatching calls with multiple
1837 -- controlling operands). However we do check in the case of an implicit
1838 -- dereference that is expanded to an explicit dereference (hence the
1839 -- test of whether Original_Node (N) comes from source).
1841 elsif K = N_Explicit_Dereference
1842 and then Comes_From_Source (Original_Node (N))
1843 then
1844 E := Etype (Prefix (N));
1846 -- If the class-wide type is not a remote one, the restrictions
1847 -- do not apply.
1849 if not Is_Remote_Access_To_Class_Wide_Type (E) then
1850 return;
1851 end if;
1853 -- If we have a true dereference that comes from source and that
1854 -- is a controlling argument for a dispatching call, accept it.
1856 if Is_Actual_Parameter (N) and then Is_Controlling_Actual (N) then
1857 return;
1858 end if;
1860 -- If we are just within a procedure or function call and the
1861 -- dereference has not been analyzed, return because this procedure
1862 -- will be called again from sem_res Resolve_Actuals. The same can
1863 -- apply in the case of dereference that is the prefix of a selected
1864 -- component, which can be a call given in prefixed form.
1866 if (Is_Actual_Parameter (N) or else PK = N_Selected_Component)
1867 and then not Analyzed (N)
1868 then
1869 return;
1870 end if;
1872 -- We must allow expanded code to generate a reference to the tag of
1873 -- the designated object (may be either the actual tag, or the stub
1874 -- tag in the case of a remote object).
1876 if PK = N_Selected_Component
1877 and then Is_Tag (Entity (Selector_Name (Parent (N))))
1878 then
1879 return;
1880 end if;
1882 Error_Msg_N
1883 ("invalid dereference of a remote access-to-class-wide value", N);
1884 end if;
1885 end Validate_Remote_Access_To_Class_Wide_Type;
1887 ------------------------------------------
1888 -- Validate_Remote_Type_Type_Conversion --
1889 ------------------------------------------
1891 procedure Validate_Remote_Type_Type_Conversion (N : Node_Id) is
1892 S : constant Entity_Id := Etype (N);
1893 E : constant Entity_Id := Etype (Expression (N));
1895 begin
1896 -- This test is required in the case where a conversion appears inside a
1897 -- normal package, it does not necessarily have to be inside an RCI,
1898 -- Remote_Types unit (RM E.2.2(9,12)).
1900 if Is_Remote_Access_To_Subprogram_Type (E)
1901 and then not Is_Remote_Access_To_Subprogram_Type (S)
1902 then
1903 Error_Msg_N
1904 ("incorrect conversion of remote operand to local type", N);
1905 return;
1907 elsif not Is_Remote_Access_To_Subprogram_Type (E)
1908 and then Is_Remote_Access_To_Subprogram_Type (S)
1909 then
1910 Error_Msg_N
1911 ("incorrect conversion of local operand to remote type", N);
1912 return;
1914 elsif Is_Remote_Access_To_Class_Wide_Type (E)
1915 and then not Is_Remote_Access_To_Class_Wide_Type (S)
1916 then
1917 Error_Msg_N
1918 ("incorrect conversion of remote operand to local type", N);
1919 return;
1920 end if;
1922 -- If a local access type is converted into a RACW type, then the
1923 -- current unit has a pointer that may now be exported to another
1924 -- partition.
1926 if Is_Remote_Access_To_Class_Wide_Type (S)
1927 and then not Is_Remote_Access_To_Class_Wide_Type (E)
1928 then
1929 Set_Has_RACW (Current_Sem_Unit);
1930 end if;
1931 end Validate_Remote_Type_Type_Conversion;
1933 -------------------------------
1934 -- Validate_RT_RAT_Component --
1935 -------------------------------
1937 procedure Validate_RT_RAT_Component (N : Node_Id) is
1938 Spec : constant Node_Id := Specification (N);
1939 Name_U : constant Entity_Id := Defining_Entity (Spec);
1940 Typ : Entity_Id;
1941 U_Typ : Entity_Id;
1942 First_Priv_Ent : constant Entity_Id := First_Private_Entity (Name_U);
1944 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean;
1945 -- True if any stream attribute is available for Typ
1947 ---------------------------------
1948 -- Stream_Attributes_Available --
1949 ---------------------------------
1951 function Stream_Attributes_Available (Typ : Entity_Id) return Boolean
1953 begin
1954 return Stream_Attribute_Available (Typ, TSS_Stream_Read)
1955 or else
1956 Stream_Attribute_Available (Typ, TSS_Stream_Write)
1957 or else
1958 Stream_Attribute_Available (Typ, TSS_Stream_Input)
1959 or else
1960 Stream_Attribute_Available (Typ, TSS_Stream_Output);
1961 end Stream_Attributes_Available;
1963 -- Start of processing for Validate_RT_RAT_Component
1965 begin
1966 if not Is_Remote_Types (Name_U) then
1967 return;
1968 end if;
1970 Typ := First_Entity (Name_U);
1971 while Present (Typ) and then Typ /= First_Priv_Ent loop
1972 U_Typ := Underlying_Type (Base_Type (Typ));
1974 if No (U_Typ) then
1975 U_Typ := Typ;
1976 end if;
1978 if Comes_From_Source (Typ) and then Is_Type (Typ) then
1980 -- Check that the type can be meaningfully transmitted to another
1981 -- partition (E.2.2(8)).
1983 if (Ada_Version < Ada_2005 and then Has_Non_Remote_Access (U_Typ))
1984 or else (Stream_Attributes_Available (Typ)
1985 and then No_External_Streaming (U_Typ))
1986 then
1987 if Is_Non_Remote_Access_Type (Typ) then
1988 Error_Msg_N ("error in non-remote access type", U_Typ);
1989 else
1990 Error_Msg_N
1991 ("error in record type containing a component of a " &
1992 "non-remote access type", U_Typ);
1993 end if;
1995 if Ada_Version >= Ada_2005 then
1996 Error_Msg_N
1997 ("\must have visible Read and Write attribute " &
1998 "definition clauses (RM E.2.2(8))", U_Typ);
1999 else
2000 Error_Msg_N
2001 ("\must have Read and Write attribute " &
2002 "definition clauses (RM E.2.2(8))", U_Typ);
2003 end if;
2004 end if;
2005 end if;
2007 Next_Entity (Typ);
2008 end loop;
2009 end Validate_RT_RAT_Component;
2011 -----------------------------------------
2012 -- Validate_SP_Access_Object_Type_Decl --
2013 -----------------------------------------
2015 procedure Validate_SP_Access_Object_Type_Decl (T : Entity_Id) is
2016 Direct_Designated_Type : Entity_Id;
2018 function Has_Entry_Declarations (E : Entity_Id) return Boolean;
2019 -- Return true if the protected type designated by T has entry
2020 -- declarations.
2022 ----------------------------
2023 -- Has_Entry_Declarations --
2024 ----------------------------
2026 function Has_Entry_Declarations (E : Entity_Id) return Boolean is
2027 Ety : Entity_Id;
2029 begin
2030 if Nkind (Parent (E)) = N_Protected_Type_Declaration then
2031 Ety := First_Entity (E);
2032 while Present (Ety) loop
2033 if Ekind (Ety) = E_Entry then
2034 return True;
2035 end if;
2037 Next_Entity (Ety);
2038 end loop;
2039 end if;
2041 return False;
2042 end Has_Entry_Declarations;
2044 -- Start of processing for Validate_SP_Access_Object_Type_Decl
2046 begin
2047 -- We are called from Sem_Ch3.Analyze_Full_Type_Declaration, and the
2048 -- Nkind of the given entity is N_Access_To_Object_Definition.
2050 if not Comes_From_Source (T)
2051 or else not In_Shared_Passive_Unit
2052 or else In_Subprogram_Task_Protected_Unit
2053 then
2054 return;
2055 end if;
2057 -- Check Shared Passive unit. It should not contain the declaration
2058 -- of an access-to-object type whose designated type is a class-wide
2059 -- type, task type or protected type with entry (RM E.2.1(7)).
2061 Direct_Designated_Type := Designated_Type (T);
2063 if Ekind (Direct_Designated_Type) = E_Class_Wide_Type then
2064 Error_Msg_N
2065 ("invalid access-to-class-wide type in shared passive unit", T);
2066 return;
2068 elsif Ekind (Direct_Designated_Type) in Task_Kind then
2069 Error_Msg_N
2070 ("invalid access-to-task type in shared passive unit", T);
2071 return;
2073 elsif Ekind (Direct_Designated_Type) in Protected_Kind
2074 and then Has_Entry_Declarations (Direct_Designated_Type)
2075 then
2076 Error_Msg_N
2077 ("invalid access-to-protected type in shared passive unit", T);
2078 return;
2079 end if;
2080 end Validate_SP_Access_Object_Type_Decl;
2082 ---------------------------------
2083 -- Validate_Static_Object_Name --
2084 ---------------------------------
2086 procedure Validate_Static_Object_Name (N : Node_Id) is
2087 E : Entity_Id;
2088 Val : Node_Id;
2090 function Is_Primary (N : Node_Id) return Boolean;
2091 -- Determine whether node is syntactically a primary in an expression
2092 -- This function should probably be somewhere else ???
2094 -- Also it does not do what it says, e.g if N is a binary operator
2095 -- whose parent is a binary operator, Is_Primary returns True ???
2097 ----------------
2098 -- Is_Primary --
2099 ----------------
2101 function Is_Primary (N : Node_Id) return Boolean is
2102 K : constant Node_Kind := Nkind (Parent (N));
2104 begin
2105 case K is
2106 when N_Aggregate
2107 | N_Component_Association
2108 | N_Index_Or_Discriminant_Constraint
2109 | N_Membership_Test
2110 | N_Op
2112 return True;
2114 when N_Attribute_Reference =>
2115 declare
2116 Attr : constant Name_Id := Attribute_Name (Parent (N));
2118 begin
2119 return Attr /= Name_Address
2120 and then Attr /= Name_Access
2121 and then Attr /= Name_Unchecked_Access
2122 and then Attr /= Name_Unrestricted_Access;
2123 end;
2125 when N_Indexed_Component =>
2126 return N /= Prefix (Parent (N)) or else Is_Primary (Parent (N));
2128 when N_Qualified_Expression
2129 | N_Type_Conversion
2131 return Is_Primary (Parent (N));
2133 when N_Assignment_Statement
2134 | N_Object_Declaration
2136 return N = Expression (Parent (N));
2138 when N_Selected_Component =>
2139 return Is_Primary (Parent (N));
2141 when others =>
2142 return False;
2143 end case;
2144 end Is_Primary;
2146 -- Start of processing for Validate_Static_Object_Name
2148 begin
2149 if not In_Preelaborated_Unit
2150 or else not Comes_From_Source (N)
2151 or else In_Subprogram_Or_Concurrent_Unit
2152 or else Ekind (Current_Scope) = E_Block
2153 then
2154 return;
2156 -- Filter out cases where primary is default in a component declaration,
2157 -- discriminant specification, or actual in a record type initialization
2158 -- call.
2160 -- Initialization call of internal types
2162 elsif Nkind (Parent (N)) = N_Procedure_Call_Statement then
2164 if Present (Parent (Parent (N)))
2165 and then Nkind (Parent (Parent (N))) = N_Freeze_Entity
2166 then
2167 return;
2168 end if;
2170 if Nkind (Name (Parent (N))) = N_Identifier
2171 and then not Comes_From_Source (Entity (Name (Parent (N))))
2172 then
2173 return;
2174 end if;
2175 end if;
2177 -- Error if the name is a primary in an expression. The parent must not
2178 -- be an operator, or a selected component or an indexed component that
2179 -- is itself a primary. Entities that are actuals do not need to be
2180 -- checked, because the call itself will be diagnosed. Entities in a
2181 -- generic unit or within a preanalyzed expression are not checked:
2182 -- only their use in executable code matters.
2184 if Is_Primary (N)
2185 and then (not Inside_A_Generic
2186 or else Present (Enclosing_Generic_Body (N)))
2187 and then not In_Spec_Expression
2188 then
2189 if Ekind (Entity (N)) = E_Variable
2190 or else Ekind (Entity (N)) in Formal_Object_Kind
2191 then
2192 Flag_Non_Static_Expr
2193 ("non-static object name in preelaborated unit", N);
2195 -- Give an error for a reference to a nonstatic constant, unless the
2196 -- constant is in another GNAT library unit that is preelaborable.
2198 elsif Ekind (Entity (N)) = E_Constant
2199 and then not Is_Static_Expression (N)
2200 then
2201 E := Entity (N);
2202 Val := Constant_Value (E);
2204 if Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)))
2205 and then
2206 Enclosing_Comp_Unit_Node (N) /= Enclosing_Comp_Unit_Node (E)
2207 and then (Is_Preelaborated (Scope (E))
2208 or else Is_Pure (Scope (E))
2209 or else (Present (Renamed_Object (E))
2210 and then Is_Entity_Name (Renamed_Object (E))
2211 and then
2212 (Is_Preelaborated
2213 (Scope (Renamed_Object (E)))
2214 or else
2215 Is_Pure
2216 (Scope (Renamed_Object (E))))))
2217 then
2218 null;
2220 -- If the value of the constant is a local variable that renames
2221 -- an aggregate, this is in itself legal. The aggregate may be
2222 -- expanded into a loop, but this does not affect preelaborability
2223 -- in itself. If some aggregate components are non-static, that is
2224 -- to say if they involve non static primaries, they will be
2225 -- flagged when analyzed.
2227 elsif Present (Val)
2228 and then Is_Entity_Name (Val)
2229 and then Is_Array_Type (Etype (Val))
2230 and then not Comes_From_Source (Val)
2231 and then Nkind (Original_Node (Val)) = N_Aggregate
2232 then
2233 null;
2235 -- This is the error case
2237 else
2238 -- In GNAT mode or Relaxed RM Semantic mode, this is just a
2239 -- warning, to allow it to be judiciously turned off.
2240 -- Otherwise it is a real error.
2242 if GNAT_Mode or Relaxed_RM_Semantics then
2243 Error_Msg_N
2244 ("??non-static constant in preelaborated unit", N);
2245 else
2246 Flag_Non_Static_Expr
2247 ("non-static constant in preelaborated unit", N);
2248 end if;
2249 end if;
2250 end if;
2251 end if;
2252 end Validate_Static_Object_Name;
2254 end Sem_Cat;