]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_ch7.adb
[Ada] Remove processing of SPARK_05 restriction
[gcc.git] / gcc / ada / sem_ch7.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 7 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2020, 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 ------------------------------------------------------------------------------
25
26 -- This package contains the routines to process package specifications and
27 -- bodies. The most important semantic aspects of package processing are the
28 -- handling of private and full declarations, and the construction of dispatch
29 -- tables for tagged types.
30
31 with Aspects; use Aspects;
32 with Atree; use Atree;
33 with Contracts; use Contracts;
34 with Debug; use Debug;
35 with Einfo; use Einfo;
36 with Elists; use Elists;
37 with Errout; use Errout;
38 with Exp_Disp; use Exp_Disp;
39 with Exp_Dist; use Exp_Dist;
40 with Exp_Dbug; use Exp_Dbug;
41 with Freeze; use Freeze;
42 with Ghost; use Ghost;
43 with Lib; use Lib;
44 with Lib.Xref; use Lib.Xref;
45 with Namet; use Namet;
46 with Nmake; use Nmake;
47 with Nlists; use Nlists;
48 with Opt; use Opt;
49 with Output; use Output;
50 with Rtsfind; use Rtsfind;
51 with Sem; use Sem;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch10; use Sem_Ch10;
58 with Sem_Ch12; use Sem_Ch12;
59 with Sem_Ch13; use Sem_Ch13;
60 with Sem_Disp; use Sem_Disp;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Prag; use Sem_Prag;
63 with Sem_Util; use Sem_Util;
64 with Sem_Warn; use Sem_Warn;
65 with Snames; use Snames;
66 with Stand; use Stand;
67 with Sinfo; use Sinfo;
68 with Sinput; use Sinput;
69 with Style;
70 with Uintp; use Uintp;
71
72 with GNAT.HTable;
73
74 package body Sem_Ch7 is
75
76 -----------------------------------
77 -- Handling private declarations --
78 -----------------------------------
79
80 -- The principle that each entity has a single defining occurrence clashes
81 -- with the presence of two separate definitions for private types: the
82 -- first is the private type declaration, and the second is the full type
83 -- declaration. It is important that all references to the type point to
84 -- the same defining occurrence, namely the first one. To enforce the two
85 -- separate views of the entity, the corresponding information is swapped
86 -- between the two declarations. Outside of the package, the defining
87 -- occurrence only contains the private declaration information, while in
88 -- the private part and the body of the package the defining occurrence
89 -- contains the full declaration. To simplify the swap, the defining
90 -- occurrence that currently holds the private declaration points to the
91 -- full declaration. During semantic processing the defining occurrence
92 -- also points to a list of private dependents, that is to say access types
93 -- or composite types whose designated types or component types are
94 -- subtypes or derived types of the private type in question. After the
95 -- full declaration has been seen, the private dependents are updated to
96 -- indicate that they have full definitions.
97
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
101
102 procedure Analyze_Package_Body_Helper (N : Node_Id);
103 -- Does all the real work of Analyze_Package_Body
104
105 procedure Check_Anonymous_Access_Types
106 (Spec_Id : Entity_Id;
107 P_Body : Node_Id);
108 -- If the spec of a package has a limited_with_clause, it may declare
109 -- anonymous access types whose designated type is a limited view, such an
110 -- anonymous access return type for a function. This access type cannot be
111 -- elaborated in the spec itself, but it may need an itype reference if it
112 -- is used within a nested scope. In that case the itype reference is
113 -- created at the beginning of the corresponding package body and inserted
114 -- before other body declarations.
115
116 procedure Declare_Inherited_Private_Subprograms (Id : Entity_Id);
117 -- Called upon entering the private part of a public child package and the
118 -- body of a nested package, to potentially declare certain inherited
119 -- subprograms that were inherited by types in the visible part, but whose
120 -- declaration was deferred because the parent operation was private and
121 -- not visible at that point. These subprograms are located by traversing
122 -- the visible part declarations looking for non-private type extensions
123 -- and then examining each of the primitive operations of such types to
124 -- find those that were inherited but declared with a special internal
125 -- name. Each such operation is now declared as an operation with a normal
126 -- name (using the name of the parent operation) and replaces the previous
127 -- implicit operation in the primitive operations list of the type. If the
128 -- inherited private operation has been overridden, then it's replaced by
129 -- the overriding operation.
130
131 procedure Install_Package_Entity (Id : Entity_Id);
132 -- Supporting procedure for Install_{Visible,Private}_Declarations. Places
133 -- one entity on its visibility chain, and recurses on the visible part if
134 -- the entity is an inner package.
135
136 function Is_Private_Base_Type (E : Entity_Id) return Boolean;
137 -- True for a private type that is not a subtype
138
139 function Is_Visible_Dependent (Dep : Entity_Id) return Boolean;
140 -- If the private dependent is a private type whose full view is derived
141 -- from the parent type, its full properties are revealed only if we are in
142 -- the immediate scope of the private dependent. Should this predicate be
143 -- tightened further???
144
145 function Requires_Completion_In_Body
146 (Id : Entity_Id;
147 Pack_Id : Entity_Id;
148 Do_Abstract_States : Boolean := False) return Boolean;
149 -- Subsidiary to routines Unit_Requires_Body and Unit_Requires_Body_Info.
150 -- Determine whether entity Id declared in package spec Pack_Id requires
151 -- completion in a package body. Flag Do_Abstract_Stats should be set when
152 -- abstract states are to be considered in the completion test.
153
154 procedure Unit_Requires_Body_Info (Pack_Id : Entity_Id);
155 -- Outputs info messages showing why package Pack_Id requires a body. The
156 -- caller has checked that the switch requesting this information is set,
157 -- and that the package does indeed require a body.
158
159 --------------------------
160 -- Analyze_Package_Body --
161 --------------------------
162
163 procedure Analyze_Package_Body (N : Node_Id) is
164 Loc : constant Source_Ptr := Sloc (N);
165
166 begin
167 if Debug_Flag_C then
168 Write_Str ("==> package body ");
169 Write_Name (Chars (Defining_Entity (N)));
170 Write_Str (" from ");
171 Write_Location (Loc);
172 Write_Eol;
173 Indent;
174 end if;
175
176 -- The real work is split out into the helper, so it can do "return;"
177 -- without skipping the debug output.
178
179 Analyze_Package_Body_Helper (N);
180
181 if Debug_Flag_C then
182 Outdent;
183 Write_Str ("<== package body ");
184 Write_Name (Chars (Defining_Entity (N)));
185 Write_Str (" from ");
186 Write_Location (Loc);
187 Write_Eol;
188 end if;
189 end Analyze_Package_Body;
190
191 ------------------------------------------------------
192 -- Analyze_Package_Body_Helper Data and Subprograms --
193 ------------------------------------------------------
194
195 Entity_Table_Size : constant := 4093;
196 -- Number of headers in hash table
197
198 subtype Entity_Header_Num is Integer range 0 .. Entity_Table_Size - 1;
199 -- Range of headers in hash table
200
201 function Node_Hash (Id : Entity_Id) return Entity_Header_Num;
202 -- Simple hash function for Entity_Ids
203
204 package Subprogram_Table is new GNAT.Htable.Simple_HTable
205 (Header_Num => Entity_Header_Num,
206 Element => Boolean,
207 No_Element => False,
208 Key => Entity_Id,
209 Hash => Node_Hash,
210 Equal => "=");
211 -- Hash table to record which subprograms are referenced. It is declared
212 -- at library level to avoid elaborating it for every call to Analyze.
213
214 package Traversed_Table is new GNAT.Htable.Simple_HTable
215 (Header_Num => Entity_Header_Num,
216 Element => Boolean,
217 No_Element => False,
218 Key => Node_Id,
219 Hash => Node_Hash,
220 Equal => "=");
221 -- Hash table to record which nodes we have traversed, so we can avoid
222 -- traversing the same nodes repeatedly.
223
224 -----------------
225 -- Node_Hash --
226 -----------------
227
228 function Node_Hash (Id : Entity_Id) return Entity_Header_Num is
229 begin
230 return Entity_Header_Num (Id mod Entity_Table_Size);
231 end Node_Hash;
232
233 ---------------------------------
234 -- Analyze_Package_Body_Helper --
235 ---------------------------------
236
237 -- WARNING: This routine manages Ghost regions. Return statements must be
238 -- replaced by gotos which jump to the end of the routine and restore the
239 -- Ghost mode.
240
241 procedure Analyze_Package_Body_Helper (N : Node_Id) is
242 procedure Hide_Public_Entities (Decls : List_Id);
243 -- Attempt to hide all public entities found in declarative list Decls
244 -- by resetting their Is_Public flag to False depending on whether the
245 -- entities are not referenced by inlined or generic bodies. This kind
246 -- of processing is a conservative approximation and will still leave
247 -- entities externally visible if the package is not simple enough.
248
249 procedure Install_Composite_Operations (P : Entity_Id);
250 -- Composite types declared in the current scope may depend on types
251 -- that were private at the point of declaration, and whose full view
252 -- is now in scope. Indicate that the corresponding operations on the
253 -- composite type are available.
254
255 --------------------------
256 -- Hide_Public_Entities --
257 --------------------------
258
259 procedure Hide_Public_Entities (Decls : List_Id) is
260 function Has_Referencer
261 (Decls : List_Id;
262 In_Nested_Instance : Boolean;
263 Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean;
264 -- A "referencer" is a construct which may reference a previous
265 -- declaration. Examine all declarations in list Decls in reverse
266 -- and determine whether one such referencer exists. All entities
267 -- in the range Last (Decls) .. Referencer are hidden from external
268 -- visibility.
269
270 function Scan_Subprogram_Ref (N : Node_Id) return Traverse_Result;
271 -- Determine whether a node denotes a reference to a subprogram
272
273 procedure Traverse_And_Scan_Subprogram_Refs is
274 new Traverse_Proc (Scan_Subprogram_Ref);
275 -- Subsidiary to routine Has_Referencer. Determine whether a node
276 -- contains references to a subprogram and record them.
277 -- WARNING: this is a very expensive routine as it performs a full
278 -- tree traversal.
279
280 procedure Scan_Subprogram_Refs (Node : Node_Id);
281 -- If we haven't already traversed Node, then mark it and traverse
282 -- it.
283
284 --------------------
285 -- Has_Referencer --
286 --------------------
287
288 function Has_Referencer
289 (Decls : List_Id;
290 In_Nested_Instance : Boolean;
291 Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean
292 is
293 Decl : Node_Id;
294 Decl_Id : Entity_Id;
295 Spec : Node_Id;
296
297 Has_Referencer_Of_Non_Subprograms : Boolean :=
298 Has_Outer_Referencer_Of_Non_Subprograms;
299 -- Set if an inlined subprogram body was detected as a referencer.
300 -- In this case, we do not return True immediately but keep hiding
301 -- subprograms from external visibility.
302
303 begin
304 if No (Decls) then
305 return False;
306 end if;
307
308 -- Examine all declarations in reverse order, hiding all entities
309 -- from external visibility until a referencer has been found. The
310 -- algorithm recurses into nested packages.
311
312 Decl := Last (Decls);
313 while Present (Decl) loop
314
315 -- A stub is always considered a referencer
316
317 if Nkind (Decl) in N_Body_Stub then
318 return True;
319
320 -- Package declaration
321
322 elsif Nkind (Decl) = N_Package_Declaration then
323 Spec := Specification (Decl);
324 Decl_Id := Defining_Entity (Spec);
325
326 -- Inspect the declarations of a non-generic package to try
327 -- and hide more entities from external visibility.
328
329 if not Is_Generic_Unit (Decl_Id) then
330 if Has_Referencer (Private_Declarations (Spec),
331 In_Nested_Instance
332 or else
333 Is_Generic_Instance (Decl_Id),
334 Has_Referencer_Of_Non_Subprograms)
335 or else
336 Has_Referencer (Visible_Declarations (Spec),
337 In_Nested_Instance
338 or else
339 Is_Generic_Instance (Decl_Id),
340 Has_Referencer_Of_Non_Subprograms)
341 then
342 return True;
343 end if;
344 end if;
345
346 -- Package body
347
348 elsif Nkind (Decl) = N_Package_Body
349 and then Present (Corresponding_Spec (Decl))
350 then
351 Decl_Id := Corresponding_Spec (Decl);
352
353 -- A generic package body is a referencer. It would seem
354 -- that we only have to consider generics that can be
355 -- exported, i.e. where the corresponding spec is the
356 -- spec of the current package, but because of nested
357 -- instantiations, a fully private generic body may export
358 -- other private body entities. Furthermore, regardless of
359 -- whether there was a previous inlined subprogram, (an
360 -- instantiation of) the generic package may reference any
361 -- entity declared before it.
362
363 if Is_Generic_Unit (Decl_Id) then
364 return True;
365
366 -- Inspect the declarations of a non-generic package body to
367 -- try and hide more entities from external visibility.
368
369 elsif Has_Referencer (Declarations (Decl),
370 In_Nested_Instance
371 or else
372 Is_Generic_Instance (Decl_Id),
373 Has_Referencer_Of_Non_Subprograms)
374 then
375 return True;
376 end if;
377
378 -- Subprogram body
379
380 elsif Nkind (Decl) = N_Subprogram_Body then
381 if Present (Corresponding_Spec (Decl)) then
382 Decl_Id := Corresponding_Spec (Decl);
383
384 -- A generic subprogram body acts as a referencer
385
386 if Is_Generic_Unit (Decl_Id) then
387 return True;
388 end if;
389
390 -- An inlined subprogram body acts as a referencer
391 -- unless we generate C code since inlining is then
392 -- handled by the C compiler.
393
394 -- Note that we test Has_Pragma_Inline here in addition
395 -- to Is_Inlined. We are doing this for a client, since
396 -- we are computing which entities should be public, and
397 -- it is the client who will decide if actual inlining
398 -- should occur, so we need to catch all cases where the
399 -- subprogram may be inlined by the client.
400
401 if not Generate_C_Code
402 and then (Is_Inlined (Decl_Id)
403 or else Has_Pragma_Inline (Decl_Id))
404 then
405 Has_Referencer_Of_Non_Subprograms := True;
406
407 -- Inspect the statements of the subprogram body
408 -- to determine whether the body references other
409 -- subprograms.
410
411 Scan_Subprogram_Refs (Decl);
412 end if;
413
414 -- Otherwise this is a stand alone subprogram body
415
416 else
417 Decl_Id := Defining_Entity (Decl);
418
419 -- An inlined subprogram body acts as a referencer
420 -- unless we generate C code since inlining is then
421 -- handled by the C compiler.
422
423 if not Generate_C_Code
424 and then (Is_Inlined (Decl_Id)
425 or else Has_Pragma_Inline (Decl_Id))
426 then
427 Has_Referencer_Of_Non_Subprograms := True;
428
429 -- Inspect the statements of the subprogram body
430 -- to determine whether the body references other
431 -- subprograms.
432
433 Scan_Subprogram_Refs (Decl);
434
435 -- Otherwise we can reset Is_Public right away
436
437 elsif not Subprogram_Table.Get (Decl_Id) then
438 Set_Is_Public (Decl_Id, False);
439 end if;
440 end if;
441
442 -- Freeze node
443
444 elsif Nkind (Decl) = N_Freeze_Entity then
445 declare
446 Discard : Boolean;
447 pragma Unreferenced (Discard);
448 begin
449 -- Inspect the actions to find references to subprograms.
450 -- We assume that the actions do not contain other kinds
451 -- of references and, therefore, we do not stop the scan
452 -- or set Has_Referencer_Of_Non_Subprograms here. Doing
453 -- it would pessimize common cases for which the actions
454 -- contain the declaration of an init procedure, since
455 -- such a procedure is automatically marked inline.
456
457 Discard :=
458 Has_Referencer (Actions (Decl),
459 In_Nested_Instance,
460 Has_Referencer_Of_Non_Subprograms);
461 end;
462
463 -- Exceptions, objects and renamings do not need to be public
464 -- if they are not followed by a construct which can reference
465 -- and export them. Likewise for subprograms but we work harder
466 -- for them to see whether they are referenced on an individual
467 -- basis by looking into the table of referenced subprograms.
468 -- But we cannot say anything for entities declared in nested
469 -- instances because instantiations are not done yet so the
470 -- bodies are not visible and could contain references to them.
471 elsif Nkind_In (Decl, N_Exception_Declaration,
472 N_Object_Declaration,
473 N_Object_Renaming_Declaration,
474 N_Subprogram_Declaration,
475 N_Subprogram_Renaming_Declaration)
476 then
477 Decl_Id := Defining_Entity (Decl);
478
479 if not In_Nested_Instance
480 and then not Is_Imported (Decl_Id)
481 and then not Is_Exported (Decl_Id)
482 and then No (Interface_Name (Decl_Id))
483 and then
484 ((Nkind (Decl) /= N_Subprogram_Declaration
485 and then not Has_Referencer_Of_Non_Subprograms)
486 or else (Nkind (Decl) = N_Subprogram_Declaration
487 and then not Subprogram_Table.Get (Decl_Id)))
488 then
489 Set_Is_Public (Decl_Id, False);
490 end if;
491
492 -- For a subprogram renaming, if the entity is referenced,
493 -- then so is the renamed subprogram. But there is an issue
494 -- with generic bodies because instantiations are not done
495 -- yet and, therefore, cannot be scanned for referencers.
496 -- That's why we use an approximation and test that we have
497 -- at least one subprogram referenced by an inlined body
498 -- instead of precisely the entity of this renaming.
499
500 if Nkind (Decl) = N_Subprogram_Renaming_Declaration
501 and then Subprogram_Table.Get_First
502 and then Is_Entity_Name (Name (Decl))
503 and then Present (Entity (Name (Decl)))
504 and then Is_Subprogram (Entity (Name (Decl)))
505 then
506 Subprogram_Table.Set (Entity (Name (Decl)), True);
507 end if;
508 end if;
509
510 Prev (Decl);
511 end loop;
512
513 return Has_Referencer_Of_Non_Subprograms;
514 end Has_Referencer;
515
516 -------------------------
517 -- Scan_Subprogram_Ref --
518 -------------------------
519
520 function Scan_Subprogram_Ref (N : Node_Id) return Traverse_Result is
521 begin
522 -- Detect a reference of the form
523 -- Subp_Call
524
525 if Nkind (N) in N_Subprogram_Call
526 and then Is_Entity_Name (Name (N))
527 and then Present (Entity (Name (N)))
528 and then Is_Subprogram (Entity (Name (N)))
529 then
530 Subprogram_Table.Set (Entity (Name (N)), True);
531
532 -- Detect a reference of the form
533 -- Subp'Some_Attribute
534
535 elsif Nkind (N) = N_Attribute_Reference
536 and then Is_Entity_Name (Prefix (N))
537 and then Present (Entity (Prefix (N)))
538 and then Is_Subprogram (Entity (Prefix (N)))
539 then
540 Subprogram_Table.Set (Entity (Prefix (N)), True);
541
542 -- Constants can be substituted by their value in gigi, which may
543 -- contain a reference, so scan the value recursively.
544
545 elsif Is_Entity_Name (N)
546 and then Present (Entity (N))
547 and then Ekind (Entity (N)) = E_Constant
548 then
549 declare
550 Val : constant Node_Id := Constant_Value (Entity (N));
551 begin
552 if Present (Val)
553 and then not Compile_Time_Known_Value (Val)
554 then
555 Scan_Subprogram_Refs (Val);
556 end if;
557 end;
558 end if;
559
560 return OK;
561 end Scan_Subprogram_Ref;
562
563 --------------------------
564 -- Scan_Subprogram_Refs --
565 --------------------------
566
567 procedure Scan_Subprogram_Refs (Node : Node_Id) is
568 begin
569 if not Traversed_Table.Get (Node) then
570 Traversed_Table.Set (Node, True);
571 Traverse_And_Scan_Subprogram_Refs (Node);
572 end if;
573 end Scan_Subprogram_Refs;
574
575 -- Local variables
576
577 Discard : Boolean;
578 pragma Unreferenced (Discard);
579
580 -- Start of processing for Hide_Public_Entities
581
582 begin
583 -- The algorithm examines the top level declarations of a package
584 -- body in reverse looking for a construct that may export entities
585 -- declared prior to it. If such a scenario is encountered, then all
586 -- entities in the range Last (Decls) .. construct are hidden from
587 -- external visibility. Consider:
588
589 -- package Pack is
590 -- generic
591 -- package Gen is
592 -- end Gen;
593 -- end Pack;
594
595 -- package body Pack is
596 -- External_Obj : ...; -- (1)
597
598 -- package body Gen is -- (2)
599 -- ... External_Obj ... -- (3)
600 -- end Gen;
601
602 -- Local_Obj : ...; -- (4)
603 -- end Pack;
604
605 -- In this example Local_Obj (4) must not be externally visible as
606 -- it cannot be exported by anything in Pack. The body of generic
607 -- package Gen (2) on the other hand acts as a "referencer" and may
608 -- export anything declared before it. Since the compiler does not
609 -- perform flow analysis, it is not possible to determine precisely
610 -- which entities will be exported when Gen is instantiated. In the
611 -- example above External_Obj (1) is exported at (3), but this may
612 -- not always be the case. The algorithm takes a conservative stance
613 -- and leaves entity External_Obj public.
614
615 -- This very conservative algorithm is supplemented by a more precise
616 -- processing for inlined bodies. For them, we traverse the syntactic
617 -- tree and record which subprograms are actually referenced from it.
618 -- This makes it possible to compute a much smaller set of externally
619 -- visible subprograms in the absence of generic bodies, which can
620 -- have a significant impact on the inlining decisions made in the
621 -- back end and the removal of out-of-line bodies from the object
622 -- code. We do it only for inlined bodies because they are supposed
623 -- to be reasonably small and tree traversal is very expensive.
624
625 -- Note that even this special processing is not optimal for inlined
626 -- bodies, because we treat all inlined subprograms alike. An optimal
627 -- algorithm would require computing the transitive closure of the
628 -- inlined subprograms that can really be referenced from other units
629 -- in the source code.
630
631 -- We could extend this processing for inlined bodies and record all
632 -- entities, not just subprograms, referenced from them, which would
633 -- make it possible to compute a much smaller set of all externally
634 -- visible entities in the absence of generic bodies. But this would
635 -- mean implementing a more thorough tree traversal of the bodies,
636 -- i.e. not just syntactic, and the gain would very likely be worth
637 -- neither the hassle nor the slowdown of the compiler.
638
639 -- Finally, an important thing to be aware of is that, at this point,
640 -- instantiations are not done yet so we cannot directly see inlined
641 -- bodies coming from them. That's not catastrophic because only the
642 -- actual parameters of the instantiations matter here, and they are
643 -- present in the declarations list of the instantiated packages.
644
645 Traversed_Table.Reset;
646 Subprogram_Table.Reset;
647 Discard := Has_Referencer (Decls, False, False);
648 end Hide_Public_Entities;
649
650 ----------------------------------
651 -- Install_Composite_Operations --
652 ----------------------------------
653
654 procedure Install_Composite_Operations (P : Entity_Id) is
655 Id : Entity_Id;
656
657 begin
658 Id := First_Entity (P);
659 while Present (Id) loop
660 if Is_Type (Id)
661 and then (Is_Limited_Composite (Id)
662 or else Is_Private_Composite (Id))
663 and then No (Private_Component (Id))
664 then
665 Set_Is_Limited_Composite (Id, False);
666 Set_Is_Private_Composite (Id, False);
667 end if;
668
669 Next_Entity (Id);
670 end loop;
671 end Install_Composite_Operations;
672
673 -- Local variables
674
675 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
676 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
677 Saved_EA : constant Boolean := Expander_Active;
678 Saved_ISMP : constant Boolean :=
679 Ignore_SPARK_Mode_Pragmas_In_Instance;
680 -- Save the Ghost and SPARK mode-related data to restore on exit
681
682 Body_Id : Entity_Id;
683 HSS : Node_Id;
684 Last_Spec_Entity : Entity_Id;
685 New_N : Node_Id;
686 Pack_Decl : Node_Id;
687 Spec_Id : Entity_Id;
688
689 -- Start of processing for Analyze_Package_Body_Helper
690
691 begin
692 -- Find corresponding package specification, and establish the current
693 -- scope. The visible defining entity for the package is the defining
694 -- occurrence in the spec. On exit from the package body, all body
695 -- declarations are attached to the defining entity for the body, but
696 -- the later is never used for name resolution. In this fashion there
697 -- is only one visible entity that denotes the package.
698
699 -- Set Body_Id. Note that this will be reset to point to the generic
700 -- copy later on in the generic case.
701
702 Body_Id := Defining_Entity (N);
703
704 -- Body is body of package instantiation. Corresponding spec has already
705 -- been set.
706
707 if Present (Corresponding_Spec (N)) then
708 Spec_Id := Corresponding_Spec (N);
709 Pack_Decl := Unit_Declaration_Node (Spec_Id);
710
711 else
712 Spec_Id := Current_Entity_In_Scope (Defining_Entity (N));
713
714 if Present (Spec_Id)
715 and then Is_Package_Or_Generic_Package (Spec_Id)
716 then
717 Pack_Decl := Unit_Declaration_Node (Spec_Id);
718
719 if Nkind (Pack_Decl) = N_Package_Renaming_Declaration then
720 Error_Msg_N ("cannot supply body for package renaming", N);
721 return;
722
723 elsif Present (Corresponding_Body (Pack_Decl)) then
724 Error_Msg_N ("redefinition of package body", N);
725 return;
726 end if;
727
728 else
729 Error_Msg_N ("missing specification for package body", N);
730 return;
731 end if;
732
733 if Is_Package_Or_Generic_Package (Spec_Id)
734 and then (Scope (Spec_Id) = Standard_Standard
735 or else Is_Child_Unit (Spec_Id))
736 and then not Unit_Requires_Body (Spec_Id)
737 then
738 if Ada_Version = Ada_83 then
739 Error_Msg_N
740 ("optional package body (not allowed in Ada 95)??", N);
741 else
742 Error_Msg_N ("spec of this package does not allow a body", N);
743 end if;
744 end if;
745 end if;
746
747 -- A [generic] package body freezes the contract of the nearest
748 -- enclosing package body and all other contracts encountered in
749 -- the same declarative part up to and excluding the package body:
750
751 -- package body Nearest_Enclosing_Package
752 -- with Refined_State => (State => Constit)
753 -- is
754 -- Constit : ...;
755
756 -- package body Freezes_Enclosing_Package_Body
757 -- with Refined_State => (State_2 => Constit_2)
758 -- is
759 -- Constit_2 : ...;
760
761 -- procedure Proc
762 -- with Refined_Depends => (Input => (Constit, Constit_2)) ...
763
764 -- This ensures that any annotations referenced by the contract of a
765 -- [generic] subprogram body declared within the current package body
766 -- are available. This form of freezing is decoupled from the usual
767 -- Freeze_xxx mechanism because it must also work in the context of
768 -- generics where normal freezing is disabled.
769
770 -- Only bodies coming from source should cause this type of freezing.
771 -- Instantiated generic bodies are excluded because their processing is
772 -- performed in a separate compilation pass which lacks enough semantic
773 -- information with respect to contract analysis. It is safe to suppress
774 -- the freezing of contracts in this case because this action already
775 -- took place at the end of the enclosing declarative part.
776
777 if Comes_From_Source (N)
778 and then not Is_Generic_Instance (Spec_Id)
779 then
780 Freeze_Previous_Contracts (N);
781 end if;
782
783 -- A package body is Ghost when the corresponding spec is Ghost. Set
784 -- the mode now to ensure that any nodes generated during analysis and
785 -- expansion are properly flagged as ignored Ghost.
786
787 Mark_And_Set_Ghost_Body (N, Spec_Id);
788
789 -- Deactivate expansion inside the body of ignored Ghost entities,
790 -- as this code will ultimately be ignored. This avoids requiring the
791 -- presence of run-time units which are not needed. Only do this for
792 -- user entities, as internally generated entities might still need
793 -- to be expanded (e.g. those generated for types).
794
795 if Present (Ignored_Ghost_Region)
796 and then Comes_From_Source (Body_Id)
797 then
798 Expander_Active := False;
799 end if;
800
801 -- If the body completes the initial declaration of a compilation unit
802 -- which is subject to pragma Elaboration_Checks, set the model of the
803 -- pragma because it applies to all parts of the unit.
804
805 Install_Elaboration_Model (Spec_Id);
806
807 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
808 Style.Check_Identifier (Body_Id, Spec_Id);
809
810 if Is_Child_Unit (Spec_Id) then
811 if Nkind (Parent (N)) /= N_Compilation_Unit then
812 Error_Msg_NE
813 ("body of child unit& cannot be an inner package", N, Spec_Id);
814 end if;
815
816 Set_Is_Child_Unit (Body_Id);
817 end if;
818
819 -- Generic package case
820
821 if Ekind (Spec_Id) = E_Generic_Package then
822
823 -- Disable expansion and perform semantic analysis on copy. The
824 -- unannotated body will be used in all instantiations.
825
826 Body_Id := Defining_Entity (N);
827 Set_Ekind (Body_Id, E_Package_Body);
828 Set_Scope (Body_Id, Scope (Spec_Id));
829 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
830 Set_Body_Entity (Spec_Id, Body_Id);
831 Set_Spec_Entity (Body_Id, Spec_Id);
832
833 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
834 Rewrite (N, New_N);
835
836 -- Once the contents of the generic copy and the template are
837 -- swapped, do the same for their respective aspect specifications.
838
839 Exchange_Aspects (N, New_N);
840
841 -- Collect all contract-related source pragmas found within the
842 -- template and attach them to the contract of the package body.
843 -- This contract is used in the capture of global references within
844 -- annotations.
845
846 Create_Generic_Contract (N);
847
848 -- Update Body_Id to point to the copied node for the remainder of
849 -- the processing.
850
851 Body_Id := Defining_Entity (N);
852 Start_Generic;
853 end if;
854
855 -- The Body_Id is that of the copied node in the generic case, the
856 -- current node otherwise. Note that N was rewritten above, so we must
857 -- be sure to get the latest Body_Id value.
858
859 Set_Ekind (Body_Id, E_Package_Body);
860 Set_Body_Entity (Spec_Id, Body_Id);
861 Set_Spec_Entity (Body_Id, Spec_Id);
862
863 -- Defining name for the package body is not a visible entity: Only the
864 -- defining name for the declaration is visible.
865
866 Set_Etype (Body_Id, Standard_Void_Type);
867 Set_Scope (Body_Id, Scope (Spec_Id));
868 Set_Corresponding_Spec (N, Spec_Id);
869 Set_Corresponding_Body (Pack_Decl, Body_Id);
870
871 -- The body entity is not used for semantics or code generation, but
872 -- it is attached to the entity list of the enclosing scope to simplify
873 -- the listing of back-annotations for the types it main contain.
874
875 if Scope (Spec_Id) /= Standard_Standard then
876 Append_Entity (Body_Id, Scope (Spec_Id));
877 end if;
878
879 -- Indicate that we are currently compiling the body of the package
880
881 Set_In_Package_Body (Spec_Id);
882 Set_Has_Completion (Spec_Id);
883 Last_Spec_Entity := Last_Entity (Spec_Id);
884
885 if Has_Aspects (N) then
886 Analyze_Aspect_Specifications (N, Body_Id);
887 end if;
888
889 Push_Scope (Spec_Id);
890
891 -- Set SPARK_Mode only for non-generic package
892
893 if Ekind (Spec_Id) = E_Package then
894 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
895 Set_SPARK_Aux_Pragma (Body_Id, SPARK_Mode_Pragma);
896 Set_SPARK_Pragma_Inherited (Body_Id);
897 Set_SPARK_Aux_Pragma_Inherited (Body_Id);
898
899 -- A package body may be instantiated or inlined at a later pass.
900 -- Restore the state of Ignore_SPARK_Mode_Pragmas_In_Instance when
901 -- it applied to the package spec.
902
903 if Ignore_SPARK_Mode_Pragmas (Spec_Id) then
904 Ignore_SPARK_Mode_Pragmas_In_Instance := True;
905 end if;
906 end if;
907
908 Set_Categorization_From_Pragmas (N);
909
910 Install_Visible_Declarations (Spec_Id);
911 Install_Private_Declarations (Spec_Id);
912 Install_Private_With_Clauses (Spec_Id);
913 Install_Composite_Operations (Spec_Id);
914
915 Check_Anonymous_Access_Types (Spec_Id, N);
916
917 if Ekind (Spec_Id) = E_Generic_Package then
918 Set_Use (Generic_Formal_Declarations (Pack_Decl));
919 end if;
920
921 Set_Use (Visible_Declarations (Specification (Pack_Decl)));
922 Set_Use (Private_Declarations (Specification (Pack_Decl)));
923
924 -- This is a nested package, so it may be necessary to declare certain
925 -- inherited subprograms that are not yet visible because the parent
926 -- type's subprograms are now visible.
927 -- Note that for child units these operations were generated when
928 -- analyzing the package specification.
929
930 if Ekind (Scope (Spec_Id)) = E_Package
931 and then Scope (Spec_Id) /= Standard_Standard
932 and then not Is_Child_Unit (Spec_Id)
933 then
934 Declare_Inherited_Private_Subprograms (Spec_Id);
935 end if;
936
937 if Present (Declarations (N)) then
938 Analyze_Declarations (Declarations (N));
939 Inspect_Deferred_Constant_Completion (Declarations (N));
940 end if;
941
942 -- Verify that the SPARK_Mode of the body agrees with that of its spec
943
944 if Present (SPARK_Pragma (Body_Id)) then
945 if Present (SPARK_Aux_Pragma (Spec_Id)) then
946 if Get_SPARK_Mode_From_Annotation (SPARK_Aux_Pragma (Spec_Id)) =
947 Off
948 and then
949 Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Body_Id)) = On
950 then
951 Error_Msg_Sloc := Sloc (SPARK_Pragma (Body_Id));
952 Error_Msg_N ("incorrect application of SPARK_Mode#", N);
953 Error_Msg_Sloc := Sloc (SPARK_Aux_Pragma (Spec_Id));
954 Error_Msg_NE
955 ("\value Off was set for SPARK_Mode on & #", N, Spec_Id);
956 end if;
957
958 -- SPARK_Mode Off could complete no SPARK_Mode in a generic, either
959 -- as specified in source code, or because SPARK_Mode On is ignored
960 -- in an instance where the context is SPARK_Mode Off/Auto.
961
962 elsif Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Body_Id)) = Off
963 and then (Is_Generic_Unit (Spec_Id) or else In_Instance)
964 then
965 null;
966
967 else
968 Error_Msg_Sloc := Sloc (SPARK_Pragma (Body_Id));
969 Error_Msg_N ("incorrect application of SPARK_Mode#", N);
970 Error_Msg_Sloc := Sloc (Spec_Id);
971 Error_Msg_NE
972 ("\no value was set for SPARK_Mode on & #", N, Spec_Id);
973 end if;
974 end if;
975
976 -- Analyze_Declarations has caused freezing of all types. Now generate
977 -- bodies for RACW primitives and stream attributes, if any.
978
979 if Ekind (Spec_Id) = E_Package and then Has_RACW (Spec_Id) then
980
981 -- Attach subprogram bodies to support RACWs declared in spec
982
983 Append_RACW_Bodies (Declarations (N), Spec_Id);
984 Analyze_List (Declarations (N));
985 end if;
986
987 HSS := Handled_Statement_Sequence (N);
988
989 if Present (HSS) then
990 Process_End_Label (HSS, 't', Spec_Id);
991 Analyze (HSS);
992
993 -- Check that elaboration code in a preelaborable package body is
994 -- empty other than null statements and labels (RM 10.2.1(6)).
995
996 Validate_Null_Statement_Sequence (N);
997 end if;
998
999 Validate_Categorization_Dependency (N, Spec_Id);
1000 Check_Completion (Body_Id);
1001
1002 -- Generate start of body reference. Note that we do this fairly late,
1003 -- because the call will use In_Extended_Main_Source_Unit as a check,
1004 -- and we want to make sure that Corresponding_Stub links are set
1005
1006 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
1007
1008 -- For a generic package, collect global references and mark them on
1009 -- the original body so that they are not resolved again at the point
1010 -- of instantiation.
1011
1012 if Ekind (Spec_Id) /= E_Package then
1013 Save_Global_References (Original_Node (N));
1014 End_Generic;
1015 end if;
1016
1017 -- The entities of the package body have so far been chained onto the
1018 -- declaration chain for the spec. That's been fine while we were in the
1019 -- body, since we wanted them to be visible, but now that we are leaving
1020 -- the package body, they are no longer visible, so we remove them from
1021 -- the entity chain of the package spec entity, and copy them to the
1022 -- entity chain of the package body entity, where they will never again
1023 -- be visible.
1024
1025 if Present (Last_Spec_Entity) then
1026 Set_First_Entity (Body_Id, Next_Entity (Last_Spec_Entity));
1027 Set_Next_Entity (Last_Spec_Entity, Empty);
1028 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
1029 Set_Last_Entity (Spec_Id, Last_Spec_Entity);
1030
1031 else
1032 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
1033 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
1034 Set_First_Entity (Spec_Id, Empty);
1035 Set_Last_Entity (Spec_Id, Empty);
1036 end if;
1037
1038 Update_Use_Clause_Chain;
1039 End_Package_Scope (Spec_Id);
1040
1041 -- All entities declared in body are not visible
1042
1043 declare
1044 E : Entity_Id;
1045
1046 begin
1047 E := First_Entity (Body_Id);
1048 while Present (E) loop
1049 Set_Is_Immediately_Visible (E, False);
1050 Set_Is_Potentially_Use_Visible (E, False);
1051 Set_Is_Hidden (E);
1052
1053 -- Child units may appear on the entity list (e.g. if they appear
1054 -- in the context of a subunit) but they are not body entities.
1055
1056 if not Is_Child_Unit (E) then
1057 Set_Is_Package_Body_Entity (E);
1058 end if;
1059
1060 Next_Entity (E);
1061 end loop;
1062 end;
1063
1064 Check_References (Body_Id);
1065
1066 -- For a generic unit, check that the formal parameters are referenced,
1067 -- and that local variables are used, as for regular packages.
1068
1069 if Ekind (Spec_Id) = E_Generic_Package then
1070 Check_References (Spec_Id);
1071 end if;
1072
1073 -- At this point all entities of the package body are externally visible
1074 -- to the linker as their Is_Public flag is set to True. This proactive
1075 -- approach is necessary because an inlined or a generic body for which
1076 -- code is generated in other units may need to see these entities. Cut
1077 -- down the number of global symbols that do not need public visibility
1078 -- as this has two beneficial effects:
1079 -- (1) It makes the compilation process more efficient.
1080 -- (2) It gives the code generator more leeway to optimize within each
1081 -- unit, especially subprograms.
1082
1083 -- This is done only for top-level library packages or child units as
1084 -- the algorithm does a top-down traversal of the package body.
1085
1086 if (Scope (Spec_Id) = Standard_Standard or else Is_Child_Unit (Spec_Id))
1087 and then not Is_Generic_Unit (Spec_Id)
1088 then
1089 Hide_Public_Entities (Declarations (N));
1090 end if;
1091
1092 -- If expander is not active, then here is where we turn off the
1093 -- In_Package_Body flag, otherwise it is turned off at the end of the
1094 -- corresponding expansion routine. If this is an instance body, we need
1095 -- to qualify names of local entities, because the body may have been
1096 -- compiled as a preliminary to another instantiation.
1097
1098 if not Expander_Active then
1099 Set_In_Package_Body (Spec_Id, False);
1100
1101 if Is_Generic_Instance (Spec_Id)
1102 and then Operating_Mode = Generate_Code
1103 then
1104 Qualify_Entity_Names (N);
1105 end if;
1106 end if;
1107
1108 if Present (Ignored_Ghost_Region) then
1109 Expander_Active := Saved_EA;
1110 end if;
1111
1112 Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
1113 Restore_Ghost_Region (Saved_GM, Saved_IGR);
1114 end Analyze_Package_Body_Helper;
1115
1116 ---------------------------------
1117 -- Analyze_Package_Declaration --
1118 ---------------------------------
1119
1120 procedure Analyze_Package_Declaration (N : Node_Id) is
1121 Id : constant Node_Id := Defining_Entity (N);
1122
1123 Is_Comp_Unit : constant Boolean :=
1124 Nkind (Parent (N)) = N_Compilation_Unit;
1125
1126 Body_Required : Boolean;
1127 -- True when this package declaration requires a corresponding body
1128
1129 begin
1130 if Debug_Flag_C then
1131 Write_Str ("==> package spec ");
1132 Write_Name (Chars (Id));
1133 Write_Str (" from ");
1134 Write_Location (Sloc (N));
1135 Write_Eol;
1136 Indent;
1137 end if;
1138
1139 Generate_Definition (Id);
1140 Enter_Name (Id);
1141 Set_Ekind (Id, E_Package);
1142 Set_Etype (Id, Standard_Void_Type);
1143
1144 -- Set SPARK_Mode from context
1145
1146 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1147 Set_SPARK_Aux_Pragma (Id, SPARK_Mode_Pragma);
1148 Set_SPARK_Pragma_Inherited (Id);
1149 Set_SPARK_Aux_Pragma_Inherited (Id);
1150
1151 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in case
1152 -- the body of this package is instantiated or inlined later and out of
1153 -- context. The body uses this attribute to restore the value of the
1154 -- global flag.
1155
1156 if Ignore_SPARK_Mode_Pragmas_In_Instance then
1157 Set_Ignore_SPARK_Mode_Pragmas (Id);
1158 end if;
1159
1160 -- Analyze aspect specifications immediately, since we need to recognize
1161 -- things like Pure early enough to diagnose violations during analysis.
1162
1163 if Has_Aspects (N) then
1164 Analyze_Aspect_Specifications (N, Id);
1165 end if;
1166
1167 -- Ada 2005 (AI-217): Check if the package has been illegally named in
1168 -- a limited-with clause of its own context. In this case the error has
1169 -- been previously notified by Analyze_Context.
1170
1171 -- limited with Pkg; -- ERROR
1172 -- package Pkg is ...
1173
1174 if From_Limited_With (Id) then
1175 return;
1176 end if;
1177
1178 Push_Scope (Id);
1179
1180 Set_Is_Pure (Id, Is_Pure (Enclosing_Lib_Unit_Entity));
1181 Set_Categorization_From_Pragmas (N);
1182
1183 Analyze (Specification (N));
1184 Validate_Categorization_Dependency (N, Id);
1185
1186 -- Determine whether the package requires a body. Abstract states are
1187 -- intentionally ignored because they do require refinement which can
1188 -- only come in a body, but at the same time they do not force the need
1189 -- for a body on their own (SPARK RM 7.1.4(4) and 7.2.2(3)).
1190
1191 Body_Required := Unit_Requires_Body (Id);
1192
1193 if not Body_Required then
1194
1195 -- If the package spec does not require an explicit body, then there
1196 -- are not entities requiring completion in the language sense. Call
1197 -- Check_Completion now to ensure that nested package declarations
1198 -- that require an implicit body get one. (In the case where a body
1199 -- is required, Check_Completion is called at the end of the body's
1200 -- declarative part.)
1201
1202 Check_Completion;
1203
1204 -- If the package spec does not require an explicit body, then all
1205 -- abstract states declared in nested packages cannot possibly get
1206 -- a proper refinement (SPARK RM 7.2.2(3)). This check is performed
1207 -- only when the compilation unit is the main unit to allow for
1208 -- modular SPARK analysis where packages do not necessarily have
1209 -- bodies.
1210
1211 if Is_Comp_Unit then
1212 Check_State_Refinements
1213 (Context => N,
1214 Is_Main_Unit => Parent (N) = Cunit (Main_Unit));
1215 end if;
1216 end if;
1217
1218 -- Set Body_Required indication on the compilation unit node
1219
1220 if Is_Comp_Unit then
1221 Set_Body_Required (Parent (N), Body_Required);
1222
1223 if Legacy_Elaboration_Checks and not Body_Required then
1224 Set_Suppress_Elaboration_Warnings (Id);
1225 end if;
1226 end if;
1227
1228 End_Package_Scope (Id);
1229
1230 -- For the declaration of a library unit that is a remote types package,
1231 -- check legality rules regarding availability of stream attributes for
1232 -- types that contain non-remote access values. This subprogram performs
1233 -- visibility tests that rely on the fact that we have exited the scope
1234 -- of Id.
1235
1236 if Is_Comp_Unit then
1237 Validate_RT_RAT_Component (N);
1238 end if;
1239
1240 if Debug_Flag_C then
1241 Outdent;
1242 Write_Str ("<== package spec ");
1243 Write_Name (Chars (Id));
1244 Write_Str (" from ");
1245 Write_Location (Sloc (N));
1246 Write_Eol;
1247 end if;
1248 end Analyze_Package_Declaration;
1249
1250 -----------------------------------
1251 -- Analyze_Package_Specification --
1252 -----------------------------------
1253
1254 -- Note that this code is shared for the analysis of generic package specs
1255 -- (see Sem_Ch12.Analyze_Generic_Package_Declaration for details).
1256
1257 procedure Analyze_Package_Specification (N : Node_Id) is
1258 Id : constant Entity_Id := Defining_Entity (N);
1259 Orig_Decl : constant Node_Id := Original_Node (Parent (N));
1260 Vis_Decls : constant List_Id := Visible_Declarations (N);
1261 Priv_Decls : constant List_Id := Private_Declarations (N);
1262 E : Entity_Id;
1263 L : Entity_Id;
1264 Public_Child : Boolean;
1265
1266 Private_With_Clauses_Installed : Boolean := False;
1267 -- In Ada 2005, private with_clauses are visible in the private part
1268 -- of a nested package, even if it appears in the public part of the
1269 -- enclosing package. This requires a separate step to install these
1270 -- private_with_clauses, and remove them at the end of the nested
1271 -- package.
1272
1273 procedure Clear_Constants (Id : Entity_Id; FE : Entity_Id);
1274 -- Clears constant indications (Never_Set_In_Source, Constant_Value, and
1275 -- Is_True_Constant) on all variables that are entities of Id, and on
1276 -- the chain whose first element is FE. A recursive call is made for all
1277 -- packages and generic packages.
1278
1279 procedure Generate_Parent_References;
1280 -- For a child unit, generate references to parent units, for
1281 -- GNAT Studio navigation purposes.
1282
1283 function Is_Public_Child (Child, Unit : Entity_Id) return Boolean;
1284 -- Child and Unit are entities of compilation units. True if Child
1285 -- is a public child of Parent as defined in 10.1.1
1286
1287 procedure Inspect_Unchecked_Union_Completion (Decls : List_Id);
1288 -- Reject completion of an incomplete or private type declarations
1289 -- having a known discriminant part by an unchecked union.
1290
1291 procedure Install_Parent_Private_Declarations (Inst_Id : Entity_Id);
1292 -- Given the package entity of a generic package instantiation or
1293 -- formal package whose corresponding generic is a child unit, installs
1294 -- the private declarations of each of the child unit's parents.
1295 -- This has to be done at the point of entering the instance package's
1296 -- private part rather than being done in Sem_Ch12.Install_Parent
1297 -- (which is where the parents' visible declarations are installed).
1298
1299 ---------------------
1300 -- Clear_Constants --
1301 ---------------------
1302
1303 procedure Clear_Constants (Id : Entity_Id; FE : Entity_Id) is
1304 E : Entity_Id;
1305
1306 begin
1307 -- Ignore package renamings, not interesting and they can cause self
1308 -- referential loops in the code below.
1309
1310 if Nkind (Parent (Id)) = N_Package_Renaming_Declaration then
1311 return;
1312 end if;
1313
1314 -- Note: in the loop below, the check for Next_Entity pointing back
1315 -- to the package entity may seem odd, but it is needed, because a
1316 -- package can contain a renaming declaration to itself, and such
1317 -- renamings are generated automatically within package instances.
1318
1319 E := FE;
1320 while Present (E) and then E /= Id loop
1321 if Is_Assignable (E) then
1322 Set_Never_Set_In_Source (E, False);
1323 Set_Is_True_Constant (E, False);
1324 Set_Current_Value (E, Empty);
1325 Set_Is_Known_Null (E, False);
1326 Set_Last_Assignment (E, Empty);
1327
1328 if not Can_Never_Be_Null (E) then
1329 Set_Is_Known_Non_Null (E, False);
1330 end if;
1331
1332 elsif Is_Package_Or_Generic_Package (E) then
1333 Clear_Constants (E, First_Entity (E));
1334 Clear_Constants (E, First_Private_Entity (E));
1335 end if;
1336
1337 Next_Entity (E);
1338 end loop;
1339 end Clear_Constants;
1340
1341 --------------------------------
1342 -- Generate_Parent_References --
1343 --------------------------------
1344
1345 procedure Generate_Parent_References is
1346 Decl : constant Node_Id := Parent (N);
1347
1348 begin
1349 if Id = Cunit_Entity (Main_Unit)
1350 or else Parent (Decl) = Library_Unit (Cunit (Main_Unit))
1351 then
1352 Generate_Reference (Id, Scope (Id), 'k', False);
1353
1354 elsif not Nkind_In (Unit (Cunit (Main_Unit)), N_Subprogram_Body,
1355 N_Subunit)
1356 then
1357 -- If current unit is an ancestor of main unit, generate a
1358 -- reference to its own parent.
1359
1360 declare
1361 U : Node_Id;
1362 Main_Spec : Node_Id := Unit (Cunit (Main_Unit));
1363
1364 begin
1365 if Nkind (Main_Spec) = N_Package_Body then
1366 Main_Spec := Unit (Library_Unit (Cunit (Main_Unit)));
1367 end if;
1368
1369 U := Parent_Spec (Main_Spec);
1370 while Present (U) loop
1371 if U = Parent (Decl) then
1372 Generate_Reference (Id, Scope (Id), 'k', False);
1373 exit;
1374
1375 elsif Nkind (Unit (U)) = N_Package_Body then
1376 exit;
1377
1378 else
1379 U := Parent_Spec (Unit (U));
1380 end if;
1381 end loop;
1382 end;
1383 end if;
1384 end Generate_Parent_References;
1385
1386 ---------------------
1387 -- Is_Public_Child --
1388 ---------------------
1389
1390 function Is_Public_Child (Child, Unit : Entity_Id) return Boolean is
1391 begin
1392 if not Is_Private_Descendant (Child) then
1393 return True;
1394 else
1395 if Child = Unit then
1396 return not Private_Present (
1397 Parent (Unit_Declaration_Node (Child)));
1398 else
1399 return Is_Public_Child (Scope (Child), Unit);
1400 end if;
1401 end if;
1402 end Is_Public_Child;
1403
1404 ----------------------------------------
1405 -- Inspect_Unchecked_Union_Completion --
1406 ----------------------------------------
1407
1408 procedure Inspect_Unchecked_Union_Completion (Decls : List_Id) is
1409 Decl : Node_Id;
1410
1411 begin
1412 Decl := First (Decls);
1413 while Present (Decl) loop
1414
1415 -- We are looking at an incomplete or private type declaration
1416 -- with a known_discriminant_part whose full view is an
1417 -- Unchecked_Union. The seemingly useless check with Is_Type
1418 -- prevents cascaded errors when routines defined only for type
1419 -- entities are called with non-type entities.
1420
1421 if Nkind_In (Decl, N_Incomplete_Type_Declaration,
1422 N_Private_Type_Declaration)
1423 and then Is_Type (Defining_Identifier (Decl))
1424 and then Has_Discriminants (Defining_Identifier (Decl))
1425 and then Present (Full_View (Defining_Identifier (Decl)))
1426 and then
1427 Is_Unchecked_Union (Full_View (Defining_Identifier (Decl)))
1428 then
1429 Error_Msg_N
1430 ("completion of discriminated partial view "
1431 & "cannot be an unchecked union",
1432 Full_View (Defining_Identifier (Decl)));
1433 end if;
1434
1435 Next (Decl);
1436 end loop;
1437 end Inspect_Unchecked_Union_Completion;
1438
1439 -----------------------------------------
1440 -- Install_Parent_Private_Declarations --
1441 -----------------------------------------
1442
1443 procedure Install_Parent_Private_Declarations (Inst_Id : Entity_Id) is
1444 Inst_Par : Entity_Id;
1445 Gen_Par : Entity_Id;
1446 Inst_Node : Node_Id;
1447
1448 begin
1449 Inst_Par := Inst_Id;
1450
1451 Gen_Par :=
1452 Generic_Parent (Specification (Unit_Declaration_Node (Inst_Par)));
1453 while Present (Gen_Par) and then Is_Child_Unit (Gen_Par) loop
1454 Inst_Node := Get_Unit_Instantiation_Node (Inst_Par);
1455
1456 if Nkind_In (Inst_Node, N_Package_Instantiation,
1457 N_Formal_Package_Declaration)
1458 and then Nkind (Name (Inst_Node)) = N_Expanded_Name
1459 then
1460 Inst_Par := Entity (Prefix (Name (Inst_Node)));
1461
1462 if Present (Renamed_Entity (Inst_Par)) then
1463 Inst_Par := Renamed_Entity (Inst_Par);
1464 end if;
1465
1466 -- The instance may appear in a sibling generic unit, in
1467 -- which case the prefix must include the common (generic)
1468 -- ancestor, which is treated as a current instance.
1469
1470 if Inside_A_Generic
1471 and then Ekind (Inst_Par) = E_Generic_Package
1472 then
1473 Gen_Par := Inst_Par;
1474 pragma Assert (In_Open_Scopes (Gen_Par));
1475
1476 else
1477 Gen_Par :=
1478 Generic_Parent
1479 (Specification (Unit_Declaration_Node (Inst_Par)));
1480 end if;
1481
1482 -- Install the private declarations and private use clauses
1483 -- of a parent instance of the child instance, unless the
1484 -- parent instance private declarations have already been
1485 -- installed earlier in Analyze_Package_Specification, which
1486 -- happens when a generic child is instantiated, and the
1487 -- instance is a child of the parent instance.
1488
1489 -- Installing the use clauses of the parent instance twice
1490 -- is both unnecessary and wrong, because it would cause the
1491 -- clauses to be chained to themselves in the use clauses
1492 -- list of the scope stack entry. That in turn would cause
1493 -- an endless loop from End_Use_Clauses upon scope exit.
1494
1495 -- The parent is now fully visible. It may be a hidden open
1496 -- scope if we are currently compiling some child instance
1497 -- declared within it, but while the current instance is being
1498 -- compiled the parent is immediately visible. In particular
1499 -- its entities must remain visible if a stack save/restore
1500 -- takes place through a call to Rtsfind.
1501
1502 if Present (Gen_Par) then
1503 if not In_Private_Part (Inst_Par) then
1504 Install_Private_Declarations (Inst_Par);
1505 Set_Use (Private_Declarations
1506 (Specification
1507 (Unit_Declaration_Node (Inst_Par))));
1508 Set_Is_Hidden_Open_Scope (Inst_Par, False);
1509 end if;
1510
1511 -- If we've reached the end of the generic instance parents,
1512 -- then finish off by looping through the nongeneric parents
1513 -- and installing their private declarations.
1514
1515 -- If one of the non-generic parents is itself on the scope
1516 -- stack, do not install its private declarations: they are
1517 -- installed in due time when the private part of that parent
1518 -- is analyzed.
1519
1520 else
1521 while Present (Inst_Par)
1522 and then Inst_Par /= Standard_Standard
1523 and then (not In_Open_Scopes (Inst_Par)
1524 or else not In_Private_Part (Inst_Par))
1525 loop
1526 if Nkind (Inst_Node) = N_Formal_Package_Declaration
1527 or else
1528 not Is_Ancestor_Package
1529 (Inst_Par, Cunit_Entity (Current_Sem_Unit))
1530 then
1531 Install_Private_Declarations (Inst_Par);
1532 Set_Use
1533 (Private_Declarations
1534 (Specification
1535 (Unit_Declaration_Node (Inst_Par))));
1536 Inst_Par := Scope (Inst_Par);
1537 else
1538 exit;
1539 end if;
1540 end loop;
1541
1542 exit;
1543 end if;
1544
1545 else
1546 exit;
1547 end if;
1548 end loop;
1549 end Install_Parent_Private_Declarations;
1550
1551 -- Start of processing for Analyze_Package_Specification
1552
1553 begin
1554 if Present (Vis_Decls) then
1555 Analyze_Declarations (Vis_Decls);
1556 end if;
1557
1558 -- Inspect the entities defined in the package and ensure that all
1559 -- incomplete types have received full declarations. Build default
1560 -- initial condition and invariant procedures for all qualifying types.
1561
1562 E := First_Entity (Id);
1563 while Present (E) loop
1564
1565 -- Check on incomplete types
1566
1567 -- AI05-0213: A formal incomplete type has no completion, and neither
1568 -- does the corresponding subtype in an instance.
1569
1570 if Is_Incomplete_Type (E)
1571 and then No (Full_View (E))
1572 and then not Is_Generic_Type (E)
1573 and then not From_Limited_With (E)
1574 and then not Is_Generic_Actual_Type (E)
1575 then
1576 Error_Msg_N ("no declaration in visible part for incomplete}", E);
1577 end if;
1578
1579 Next_Entity (E);
1580 end loop;
1581
1582 if Is_Remote_Call_Interface (Id)
1583 and then Nkind (Parent (Parent (N))) = N_Compilation_Unit
1584 then
1585 Validate_RCI_Declarations (Id);
1586 end if;
1587
1588 -- Save global references in the visible declarations, before installing
1589 -- private declarations of parent unit if there is one, because the
1590 -- privacy status of types defined in the parent will change. This is
1591 -- only relevant for generic child units, but is done in all cases for
1592 -- uniformity.
1593
1594 if Ekind (Id) = E_Generic_Package
1595 and then Nkind (Orig_Decl) = N_Generic_Package_Declaration
1596 then
1597 declare
1598 Orig_Spec : constant Node_Id := Specification (Orig_Decl);
1599 Save_Priv : constant List_Id := Private_Declarations (Orig_Spec);
1600
1601 begin
1602 -- Insert the freezing nodes after the visible declarations to
1603 -- ensure that we analyze its aspects; needed to ensure that
1604 -- global entities referenced in the aspects are properly handled.
1605
1606 if Ada_Version >= Ada_2012
1607 and then Is_Non_Empty_List (Vis_Decls)
1608 and then Is_Empty_List (Priv_Decls)
1609 then
1610 Insert_List_After_And_Analyze
1611 (Last (Vis_Decls), Freeze_Entity (Id, Last (Vis_Decls)));
1612 end if;
1613
1614 Set_Private_Declarations (Orig_Spec, Empty_List);
1615 Save_Global_References (Orig_Decl);
1616 Set_Private_Declarations (Orig_Spec, Save_Priv);
1617 end;
1618 end if;
1619
1620 -- If package is a public child unit, then make the private declarations
1621 -- of the parent visible.
1622
1623 Public_Child := False;
1624
1625 declare
1626 Par : Entity_Id;
1627 Pack_Decl : Node_Id;
1628 Par_Spec : Node_Id;
1629
1630 begin
1631 Par := Id;
1632 Par_Spec := Parent_Spec (Parent (N));
1633
1634 -- If the package is formal package of an enclosing generic, it is
1635 -- transformed into a local generic declaration, and compiled to make
1636 -- its spec available. We need to retrieve the original generic to
1637 -- determine whether it is a child unit, and install its parents.
1638
1639 if No (Par_Spec)
1640 and then
1641 Nkind (Original_Node (Parent (N))) = N_Formal_Package_Declaration
1642 then
1643 Par := Entity (Name (Original_Node (Parent (N))));
1644 Par_Spec := Parent_Spec (Unit_Declaration_Node (Par));
1645 end if;
1646
1647 if Present (Par_Spec) then
1648 Generate_Parent_References;
1649
1650 while Scope (Par) /= Standard_Standard
1651 and then Is_Public_Child (Id, Par)
1652 and then In_Open_Scopes (Par)
1653 loop
1654 Public_Child := True;
1655 Par := Scope (Par);
1656 Install_Private_Declarations (Par);
1657 Install_Private_With_Clauses (Par);
1658 Pack_Decl := Unit_Declaration_Node (Par);
1659 Set_Use (Private_Declarations (Specification (Pack_Decl)));
1660 end loop;
1661 end if;
1662 end;
1663
1664 if Is_Compilation_Unit (Id) then
1665 Install_Private_With_Clauses (Id);
1666 else
1667 -- The current compilation unit may include private with_clauses,
1668 -- which are visible in the private part of the current nested
1669 -- package, and have to be installed now. This is not done for
1670 -- nested instantiations, where the private with_clauses of the
1671 -- enclosing unit have no effect once the instantiation info is
1672 -- established and we start analyzing the package declaration.
1673
1674 declare
1675 Comp_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
1676 begin
1677 if Is_Package_Or_Generic_Package (Comp_Unit)
1678 and then not In_Private_Part (Comp_Unit)
1679 and then not In_Instance
1680 then
1681 Install_Private_With_Clauses (Comp_Unit);
1682 Private_With_Clauses_Installed := True;
1683 end if;
1684 end;
1685 end if;
1686
1687 -- If this is a package associated with a generic instance or formal
1688 -- package, then the private declarations of each of the generic's
1689 -- parents must be installed at this point.
1690
1691 if Is_Generic_Instance (Id) then
1692 Install_Parent_Private_Declarations (Id);
1693 end if;
1694
1695 -- Analyze private part if present. The flag In_Private_Part is reset
1696 -- in End_Package_Scope.
1697
1698 L := Last_Entity (Id);
1699
1700 if Present (Priv_Decls) then
1701 Set_In_Private_Part (Id);
1702
1703 -- Upon entering a public child's private part, it may be necessary
1704 -- to declare subprograms that were derived in the package's visible
1705 -- part but not yet made visible.
1706
1707 if Public_Child then
1708 Declare_Inherited_Private_Subprograms (Id);
1709 end if;
1710
1711 Analyze_Declarations (Priv_Decls);
1712
1713 -- Check the private declarations for incomplete deferred constants
1714
1715 Inspect_Deferred_Constant_Completion (Priv_Decls);
1716
1717 -- The first private entity is the immediate follower of the last
1718 -- visible entity, if there was one.
1719
1720 if Present (L) then
1721 Set_First_Private_Entity (Id, Next_Entity (L));
1722 else
1723 Set_First_Private_Entity (Id, First_Entity (Id));
1724 end if;
1725
1726 -- There may be inherited private subprograms that need to be declared,
1727 -- even in the absence of an explicit private part. If there are any
1728 -- public declarations in the package and the package is a public child
1729 -- unit, then an implicit private part is assumed.
1730
1731 elsif Present (L) and then Public_Child then
1732 Set_In_Private_Part (Id);
1733 Declare_Inherited_Private_Subprograms (Id);
1734 Set_First_Private_Entity (Id, Next_Entity (L));
1735 end if;
1736
1737 E := First_Entity (Id);
1738 while Present (E) loop
1739
1740 -- Check rule of 3.6(11), which in general requires waiting till all
1741 -- full types have been seen.
1742
1743 if Ekind (E) = E_Record_Type or else Ekind (E) = E_Array_Type then
1744 Check_Aliased_Component_Types (E);
1745 end if;
1746
1747 -- Check preelaborable initialization for full type completing a
1748 -- private type for which pragma Preelaborable_Initialization given.
1749
1750 if Is_Type (E)
1751 and then Must_Have_Preelab_Init (E)
1752 and then not Has_Preelaborable_Initialization (E)
1753 then
1754 Error_Msg_N
1755 ("full view of & does not have preelaborable initialization", E);
1756 end if;
1757
1758 Next_Entity (E);
1759 end loop;
1760
1761 -- Ada 2005 (AI-216): The completion of an incomplete or private type
1762 -- declaration having a known_discriminant_part shall not be an
1763 -- unchecked union type.
1764
1765 if Present (Vis_Decls) then
1766 Inspect_Unchecked_Union_Completion (Vis_Decls);
1767 end if;
1768
1769 if Present (Priv_Decls) then
1770 Inspect_Unchecked_Union_Completion (Priv_Decls);
1771 end if;
1772
1773 if Ekind (Id) = E_Generic_Package
1774 and then Nkind (Orig_Decl) = N_Generic_Package_Declaration
1775 and then Present (Priv_Decls)
1776 then
1777 -- Save global references in private declarations, ignoring the
1778 -- visible declarations that were processed earlier.
1779
1780 declare
1781 Orig_Spec : constant Node_Id := Specification (Orig_Decl);
1782 Save_Vis : constant List_Id := Visible_Declarations (Orig_Spec);
1783 Save_Form : constant List_Id :=
1784 Generic_Formal_Declarations (Orig_Decl);
1785
1786 begin
1787 -- Insert the freezing nodes after the private declarations to
1788 -- ensure that we analyze its aspects; needed to ensure that
1789 -- global entities referenced in the aspects are properly handled.
1790
1791 if Ada_Version >= Ada_2012
1792 and then Is_Non_Empty_List (Priv_Decls)
1793 then
1794 Insert_List_After_And_Analyze
1795 (Last (Priv_Decls), Freeze_Entity (Id, Last (Priv_Decls)));
1796 end if;
1797
1798 Set_Visible_Declarations (Orig_Spec, Empty_List);
1799 Set_Generic_Formal_Declarations (Orig_Decl, Empty_List);
1800 Save_Global_References (Orig_Decl);
1801 Set_Generic_Formal_Declarations (Orig_Decl, Save_Form);
1802 Set_Visible_Declarations (Orig_Spec, Save_Vis);
1803 end;
1804 end if;
1805
1806 Process_End_Label (N, 'e', Id);
1807
1808 -- Remove private_with_clauses of enclosing compilation unit, if they
1809 -- were installed.
1810
1811 if Private_With_Clauses_Installed then
1812 Remove_Private_With_Clauses (Cunit (Current_Sem_Unit));
1813 end if;
1814
1815 -- For the case of a library level package, we must go through all the
1816 -- entities clearing the indications that the value may be constant and
1817 -- not modified. Why? Because any client of this package may modify
1818 -- these values freely from anywhere. This also applies to any nested
1819 -- packages or generic packages.
1820
1821 -- For now we unconditionally clear constants for packages that are
1822 -- instances of generic packages. The reason is that we do not have the
1823 -- body yet, and we otherwise think things are unreferenced when they
1824 -- are not. This should be fixed sometime (the effect is not terrible,
1825 -- we just lose some warnings, and also some cases of value propagation)
1826 -- ???
1827
1828 if Is_Library_Level_Entity (Id)
1829 or else Is_Generic_Instance (Id)
1830 then
1831 Clear_Constants (Id, First_Entity (Id));
1832 Clear_Constants (Id, First_Private_Entity (Id));
1833 end if;
1834
1835 -- Output relevant information as to why the package requires a body.
1836 -- Do not consider generated packages as this exposes internal symbols
1837 -- and leads to confusing messages.
1838
1839 if List_Body_Required_Info
1840 and then In_Extended_Main_Source_Unit (Id)
1841 and then Unit_Requires_Body (Id)
1842 and then Comes_From_Source (Id)
1843 then
1844 Unit_Requires_Body_Info (Id);
1845 end if;
1846
1847 -- Nested package specs that do not require bodies are not checked for
1848 -- ineffective use clauses due to the possibility of subunits. This is
1849 -- because at this stage it is impossible to tell whether there will be
1850 -- a separate body.
1851
1852 if not Unit_Requires_Body (Id)
1853 and then Is_Compilation_Unit (Id)
1854 and then not Is_Private_Descendant (Id)
1855 then
1856 Update_Use_Clause_Chain;
1857 end if;
1858 end Analyze_Package_Specification;
1859
1860 --------------------------------------
1861 -- Analyze_Private_Type_Declaration --
1862 --------------------------------------
1863
1864 procedure Analyze_Private_Type_Declaration (N : Node_Id) is
1865 Id : constant Entity_Id := Defining_Identifier (N);
1866 PF : constant Boolean := Is_Pure (Enclosing_Lib_Unit_Entity);
1867
1868 begin
1869 Generate_Definition (Id);
1870 Set_Is_Pure (Id, PF);
1871 Init_Size_Align (Id);
1872
1873 if not Is_Package_Or_Generic_Package (Current_Scope)
1874 or else In_Private_Part (Current_Scope)
1875 then
1876 Error_Msg_N ("invalid context for private declaration", N);
1877 end if;
1878
1879 New_Private_Type (N, Id, N);
1880 Set_Depends_On_Private (Id);
1881
1882 -- Set the SPARK mode from the current context
1883
1884 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1885 Set_SPARK_Pragma_Inherited (Id);
1886
1887 if Has_Aspects (N) then
1888 Analyze_Aspect_Specifications (N, Id);
1889 end if;
1890 end Analyze_Private_Type_Declaration;
1891
1892 ----------------------------------
1893 -- Check_Anonymous_Access_Types --
1894 ----------------------------------
1895
1896 procedure Check_Anonymous_Access_Types
1897 (Spec_Id : Entity_Id;
1898 P_Body : Node_Id)
1899 is
1900 E : Entity_Id;
1901 IR : Node_Id;
1902
1903 begin
1904 -- Itype references are only needed by gigi, to force elaboration of
1905 -- itypes. In the absence of code generation, they are not needed.
1906
1907 if not Expander_Active then
1908 return;
1909 end if;
1910
1911 E := First_Entity (Spec_Id);
1912 while Present (E) loop
1913 if Ekind (E) = E_Anonymous_Access_Type
1914 and then From_Limited_With (E)
1915 then
1916 IR := Make_Itype_Reference (Sloc (P_Body));
1917 Set_Itype (IR, E);
1918
1919 if No (Declarations (P_Body)) then
1920 Set_Declarations (P_Body, New_List (IR));
1921 else
1922 Prepend (IR, Declarations (P_Body));
1923 end if;
1924 end if;
1925
1926 Next_Entity (E);
1927 end loop;
1928 end Check_Anonymous_Access_Types;
1929
1930 -------------------------------------------
1931 -- Declare_Inherited_Private_Subprograms --
1932 -------------------------------------------
1933
1934 procedure Declare_Inherited_Private_Subprograms (Id : Entity_Id) is
1935
1936 function Is_Primitive_Of (T : Entity_Id; S : Entity_Id) return Boolean;
1937 -- Check whether an inherited subprogram S is an operation of an
1938 -- untagged derived type T.
1939
1940 ---------------------
1941 -- Is_Primitive_Of --
1942 ---------------------
1943
1944 function Is_Primitive_Of (T : Entity_Id; S : Entity_Id) return Boolean is
1945 Formal : Entity_Id;
1946
1947 begin
1948 -- If the full view is a scalar type, the type is the anonymous base
1949 -- type, but the operation mentions the first subtype, so check the
1950 -- signature against the base type.
1951
1952 if Base_Type (Etype (S)) = Base_Type (T) then
1953 return True;
1954
1955 else
1956 Formal := First_Formal (S);
1957 while Present (Formal) loop
1958 if Base_Type (Etype (Formal)) = Base_Type (T) then
1959 return True;
1960 end if;
1961
1962 Next_Formal (Formal);
1963 end loop;
1964
1965 return False;
1966 end if;
1967 end Is_Primitive_Of;
1968
1969 -- Local variables
1970
1971 E : Entity_Id;
1972 Op_List : Elist_Id;
1973 Op_Elmt : Elmt_Id;
1974 Op_Elmt_2 : Elmt_Id;
1975 Prim_Op : Entity_Id;
1976 New_Op : Entity_Id := Empty;
1977 Parent_Subp : Entity_Id;
1978 Tag : Entity_Id;
1979
1980 -- Start of processing for Declare_Inherited_Private_Subprograms
1981
1982 begin
1983 E := First_Entity (Id);
1984 while Present (E) loop
1985
1986 -- If the entity is a nonprivate type extension whose parent type
1987 -- is declared in an open scope, then the type may have inherited
1988 -- operations that now need to be made visible. Ditto if the entity
1989 -- is a formal derived type in a child unit.
1990
1991 if ((Is_Derived_Type (E) and then not Is_Private_Type (E))
1992 or else
1993 (Nkind (Parent (E)) = N_Private_Extension_Declaration
1994 and then Is_Generic_Type (E)))
1995 and then In_Open_Scopes (Scope (Etype (E)))
1996 and then Is_Base_Type (E)
1997 then
1998 if Is_Tagged_Type (E) then
1999 Op_List := Primitive_Operations (E);
2000 New_Op := Empty;
2001 Tag := First_Tag_Component (E);
2002
2003 Op_Elmt := First_Elmt (Op_List);
2004 while Present (Op_Elmt) loop
2005 Prim_Op := Node (Op_Elmt);
2006
2007 -- Search primitives that are implicit operations with an
2008 -- internal name whose parent operation has a normal name.
2009
2010 if Present (Alias (Prim_Op))
2011 and then Find_Dispatching_Type (Alias (Prim_Op)) /= E
2012 and then not Comes_From_Source (Prim_Op)
2013 and then Is_Internal_Name (Chars (Prim_Op))
2014 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
2015 then
2016 Parent_Subp := Alias (Prim_Op);
2017
2018 -- Case 1: Check if the type has also an explicit
2019 -- overriding for this primitive.
2020
2021 Op_Elmt_2 := Next_Elmt (Op_Elmt);
2022 while Present (Op_Elmt_2) loop
2023
2024 -- Skip entities with attribute Interface_Alias since
2025 -- they are not overriding primitives (these entities
2026 -- link an interface primitive with their covering
2027 -- primitive)
2028
2029 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
2030 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
2031 and then No (Interface_Alias (Node (Op_Elmt_2)))
2032 then
2033 -- The private inherited operation has been
2034 -- overridden by an explicit subprogram:
2035 -- replace the former by the latter.
2036
2037 New_Op := Node (Op_Elmt_2);
2038 Replace_Elmt (Op_Elmt, New_Op);
2039 Remove_Elmt (Op_List, Op_Elmt_2);
2040 Set_Overridden_Operation (New_Op, Parent_Subp);
2041
2042 -- We don't need to inherit its dispatching slot.
2043 -- Set_All_DT_Position has previously ensured that
2044 -- the same slot was assigned to the two primitives
2045
2046 if Present (Tag)
2047 and then Present (DTC_Entity (New_Op))
2048 and then Present (DTC_Entity (Prim_Op))
2049 then
2050 pragma Assert
2051 (DT_Position (New_Op) = DT_Position (Prim_Op));
2052 null;
2053 end if;
2054
2055 goto Next_Primitive;
2056 end if;
2057
2058 Next_Elmt (Op_Elmt_2);
2059 end loop;
2060
2061 -- Case 2: We have not found any explicit overriding and
2062 -- hence we need to declare the operation (i.e., make it
2063 -- visible).
2064
2065 Derive_Subprogram (New_Op, Alias (Prim_Op), E, Etype (E));
2066
2067 -- Inherit the dispatching slot if E is already frozen
2068
2069 if Is_Frozen (E)
2070 and then Present (DTC_Entity (Alias (Prim_Op)))
2071 then
2072 Set_DTC_Entity_Value (E, New_Op);
2073 Set_DT_Position_Value (New_Op,
2074 DT_Position (Alias (Prim_Op)));
2075 end if;
2076
2077 pragma Assert
2078 (Is_Dispatching_Operation (New_Op)
2079 and then Node (Last_Elmt (Op_List)) = New_Op);
2080
2081 -- Substitute the new operation for the old one in the
2082 -- type's primitive operations list. Since the new
2083 -- operation was also just added to the end of list,
2084 -- the last element must be removed.
2085
2086 -- (Question: is there a simpler way of declaring the
2087 -- operation, say by just replacing the name of the
2088 -- earlier operation, reentering it in the in the symbol
2089 -- table (how?), and marking it as private???)
2090
2091 Replace_Elmt (Op_Elmt, New_Op);
2092 Remove_Last_Elmt (Op_List);
2093 end if;
2094
2095 <<Next_Primitive>>
2096 Next_Elmt (Op_Elmt);
2097 end loop;
2098
2099 -- Generate listing showing the contents of the dispatch table
2100
2101 if Debug_Flag_ZZ then
2102 Write_DT (E);
2103 end if;
2104
2105 else
2106 -- For untagged type, scan forward to locate inherited hidden
2107 -- operations.
2108
2109 Prim_Op := Next_Entity (E);
2110 while Present (Prim_Op) loop
2111 if Is_Subprogram (Prim_Op)
2112 and then Present (Alias (Prim_Op))
2113 and then not Comes_From_Source (Prim_Op)
2114 and then Is_Internal_Name (Chars (Prim_Op))
2115 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
2116 and then Is_Primitive_Of (E, Prim_Op)
2117 then
2118 Derive_Subprogram (New_Op, Alias (Prim_Op), E, Etype (E));
2119 end if;
2120
2121 Next_Entity (Prim_Op);
2122
2123 -- Derived operations appear immediately after the type
2124 -- declaration (or the following subtype indication for
2125 -- a derived scalar type). Further declarations cannot
2126 -- include inherited operations of the type.
2127
2128 if Present (Prim_Op) then
2129 exit when Ekind (Prim_Op) not in Overloadable_Kind;
2130 end if;
2131 end loop;
2132 end if;
2133 end if;
2134
2135 Next_Entity (E);
2136 end loop;
2137 end Declare_Inherited_Private_Subprograms;
2138
2139 -----------------------
2140 -- End_Package_Scope --
2141 -----------------------
2142
2143 procedure End_Package_Scope (P : Entity_Id) is
2144 begin
2145 Uninstall_Declarations (P);
2146 Pop_Scope;
2147 end End_Package_Scope;
2148
2149 ---------------------------
2150 -- Exchange_Declarations --
2151 ---------------------------
2152
2153 procedure Exchange_Declarations (Id : Entity_Id) is
2154 Full_Id : constant Entity_Id := Full_View (Id);
2155 H1 : constant Entity_Id := Homonym (Id);
2156 Next1 : constant Entity_Id := Next_Entity (Id);
2157 H2 : Entity_Id;
2158 Next2 : Entity_Id;
2159
2160 begin
2161 -- If missing full declaration for type, nothing to exchange
2162
2163 if No (Full_Id) then
2164 return;
2165 end if;
2166
2167 -- Otherwise complete the exchange, and preserve semantic links
2168
2169 Next2 := Next_Entity (Full_Id);
2170 H2 := Homonym (Full_Id);
2171
2172 -- Reset full declaration pointer to reflect the switched entities and
2173 -- readjust the next entity chains.
2174
2175 Exchange_Entities (Id, Full_Id);
2176
2177 Link_Entities (Id, Next1);
2178 Set_Homonym (Id, H1);
2179
2180 Set_Full_View (Full_Id, Id);
2181 Link_Entities (Full_Id, Next2);
2182 Set_Homonym (Full_Id, H2);
2183 end Exchange_Declarations;
2184
2185 ----------------------------
2186 -- Install_Package_Entity --
2187 ----------------------------
2188
2189 procedure Install_Package_Entity (Id : Entity_Id) is
2190 begin
2191 if not Is_Internal (Id) then
2192 if Debug_Flag_E then
2193 Write_Str ("Install: ");
2194 Write_Name (Chars (Id));
2195 Write_Eol;
2196 end if;
2197
2198 if Is_Child_Unit (Id) then
2199 null;
2200
2201 -- Do not enter implicitly inherited non-overridden subprograms of
2202 -- a tagged type back into visibility if they have non-conformant
2203 -- homographs (Ada RM 8.3 12.3/2).
2204
2205 elsif Is_Hidden_Non_Overridden_Subpgm (Id) then
2206 null;
2207
2208 else
2209 Set_Is_Immediately_Visible (Id);
2210 end if;
2211 end if;
2212 end Install_Package_Entity;
2213
2214 ----------------------------------
2215 -- Install_Private_Declarations --
2216 ----------------------------------
2217
2218 procedure Install_Private_Declarations (P : Entity_Id) is
2219 Id : Entity_Id;
2220 Full : Entity_Id;
2221 Priv_Deps : Elist_Id;
2222
2223 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id);
2224 -- When the full view of a private type is made available, we do the
2225 -- same for its private dependents under proper visibility conditions.
2226 -- When compiling a child unit this needs to be done recursively.
2227
2228 -----------------------------
2229 -- Swap_Private_Dependents --
2230 -----------------------------
2231
2232 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id) is
2233 Cunit : Entity_Id;
2234 Deps : Elist_Id;
2235 Priv : Entity_Id;
2236 Priv_Elmt : Elmt_Id;
2237 Is_Priv : Boolean;
2238
2239 begin
2240 Priv_Elmt := First_Elmt (Priv_Deps);
2241 while Present (Priv_Elmt) loop
2242 Priv := Node (Priv_Elmt);
2243
2244 -- Before the exchange, verify that the presence of the Full_View
2245 -- field. This field will be empty if the entity has already been
2246 -- installed due to a previous call.
2247
2248 if Present (Full_View (Priv)) and then Is_Visible_Dependent (Priv)
2249 then
2250 if Is_Private_Type (Priv) then
2251 Cunit := Cunit_Entity (Current_Sem_Unit);
2252 Deps := Private_Dependents (Priv);
2253 Is_Priv := True;
2254 else
2255 Is_Priv := False;
2256 end if;
2257
2258 -- For each subtype that is swapped, we also swap the reference
2259 -- to it in Private_Dependents, to allow access to it when we
2260 -- swap them out in End_Package_Scope.
2261
2262 Replace_Elmt (Priv_Elmt, Full_View (Priv));
2263
2264 -- Ensure that both views of the dependent private subtype are
2265 -- immediately visible if within some open scope. Check full
2266 -- view before exchanging views.
2267
2268 if In_Open_Scopes (Scope (Full_View (Priv))) then
2269 Set_Is_Immediately_Visible (Priv);
2270 end if;
2271
2272 Exchange_Declarations (Priv);
2273 Set_Is_Immediately_Visible
2274 (Priv, In_Open_Scopes (Scope (Priv)));
2275
2276 Set_Is_Potentially_Use_Visible
2277 (Priv, Is_Potentially_Use_Visible (Node (Priv_Elmt)));
2278
2279 -- Recurse for child units, except in generic child units,
2280 -- which unfortunately handle private_dependents separately.
2281 -- Note that the current unit may not have been analyzed,
2282 -- for example a package body, so we cannot rely solely on
2283 -- the Is_Child_Unit flag, but that's only an optimization.
2284
2285 if Is_Priv
2286 and then (No (Etype (Cunit)) or else Is_Child_Unit (Cunit))
2287 and then not Is_Empty_Elmt_List (Deps)
2288 and then not Inside_A_Generic
2289 then
2290 Swap_Private_Dependents (Deps);
2291 end if;
2292 end if;
2293
2294 Next_Elmt (Priv_Elmt);
2295 end loop;
2296 end Swap_Private_Dependents;
2297
2298 -- Start of processing for Install_Private_Declarations
2299
2300 begin
2301 -- First exchange declarations for private types, so that the full
2302 -- declaration is visible. For each private type, we check its
2303 -- Private_Dependents list and also exchange any subtypes of or derived
2304 -- types from it. Finally, if this is a Taft amendment type, the
2305 -- incomplete declaration is irrelevant, and we want to link the
2306 -- eventual full declaration with the original private one so we
2307 -- also skip the exchange.
2308
2309 Id := First_Entity (P);
2310 while Present (Id) and then Id /= First_Private_Entity (P) loop
2311 if Is_Private_Base_Type (Id)
2312 and then Present (Full_View (Id))
2313 and then Comes_From_Source (Full_View (Id))
2314 and then Scope (Full_View (Id)) = Scope (Id)
2315 and then Ekind (Full_View (Id)) /= E_Incomplete_Type
2316 then
2317 -- If there is a use-type clause on the private type, set the full
2318 -- view accordingly.
2319
2320 Set_In_Use (Full_View (Id), In_Use (Id));
2321 Full := Full_View (Id);
2322
2323 if Is_Private_Base_Type (Full)
2324 and then Has_Private_Declaration (Full)
2325 and then Nkind (Parent (Full)) = N_Full_Type_Declaration
2326 and then In_Open_Scopes (Scope (Etype (Full)))
2327 and then In_Package_Body (Current_Scope)
2328 and then not Is_Private_Type (Etype (Full))
2329 then
2330 -- This is the completion of a private type by a derivation
2331 -- from another private type which is not private anymore. This
2332 -- can only happen in a package nested within a child package,
2333 -- when the parent type is defined in the parent unit. At this
2334 -- point the current type is not private either, and we have
2335 -- to install the underlying full view, which is now visible.
2336 -- Save the current full view as well, so that all views can be
2337 -- restored on exit. It may seem that after compiling the child
2338 -- body there are not environments to restore, but the back-end
2339 -- expects those links to be valid, and freeze nodes depend on
2340 -- them.
2341
2342 if No (Full_View (Full))
2343 and then Present (Underlying_Full_View (Full))
2344 then
2345 Set_Full_View (Id, Underlying_Full_View (Full));
2346 Set_Underlying_Full_View (Id, Full);
2347 Set_Is_Underlying_Full_View (Full);
2348
2349 Set_Underlying_Full_View (Full, Empty);
2350 Set_Is_Frozen (Full_View (Id));
2351 end if;
2352 end if;
2353
2354 Priv_Deps := Private_Dependents (Id);
2355 Exchange_Declarations (Id);
2356 Set_Is_Immediately_Visible (Id);
2357 Swap_Private_Dependents (Priv_Deps);
2358 end if;
2359
2360 Next_Entity (Id);
2361 end loop;
2362
2363 -- Next make other declarations in the private part visible as well
2364
2365 Id := First_Private_Entity (P);
2366 while Present (Id) loop
2367 Install_Package_Entity (Id);
2368 Set_Is_Hidden (Id, False);
2369 Next_Entity (Id);
2370 end loop;
2371
2372 -- An abstract state is partially refined when it has at least one
2373 -- Part_Of constituent. Since these constituents are being installed
2374 -- into visibility, update the partial refinement status of any state
2375 -- defined in the associated package, subject to at least one Part_Of
2376 -- constituent.
2377
2378 if Is_Package_Or_Generic_Package (P) then
2379 declare
2380 States : constant Elist_Id := Abstract_States (P);
2381 State_Elmt : Elmt_Id;
2382 State_Id : Entity_Id;
2383
2384 begin
2385 if Present (States) then
2386 State_Elmt := First_Elmt (States);
2387 while Present (State_Elmt) loop
2388 State_Id := Node (State_Elmt);
2389
2390 if Present (Part_Of_Constituents (State_Id)) then
2391 Set_Has_Partial_Visible_Refinement (State_Id);
2392 end if;
2393
2394 Next_Elmt (State_Elmt);
2395 end loop;
2396 end if;
2397 end;
2398 end if;
2399
2400 -- Indicate that the private part is currently visible, so it can be
2401 -- properly reset on exit.
2402
2403 Set_In_Private_Part (P);
2404 end Install_Private_Declarations;
2405
2406 ----------------------------------
2407 -- Install_Visible_Declarations --
2408 ----------------------------------
2409
2410 procedure Install_Visible_Declarations (P : Entity_Id) is
2411 Id : Entity_Id;
2412 Last_Entity : Entity_Id;
2413
2414 begin
2415 pragma Assert
2416 (Is_Package_Or_Generic_Package (P) or else Is_Record_Type (P));
2417
2418 if Is_Package_Or_Generic_Package (P) then
2419 Last_Entity := First_Private_Entity (P);
2420 else
2421 Last_Entity := Empty;
2422 end if;
2423
2424 Id := First_Entity (P);
2425 while Present (Id) and then Id /= Last_Entity loop
2426 Install_Package_Entity (Id);
2427 Next_Entity (Id);
2428 end loop;
2429 end Install_Visible_Declarations;
2430
2431 --------------------------
2432 -- Is_Private_Base_Type --
2433 --------------------------
2434
2435 function Is_Private_Base_Type (E : Entity_Id) return Boolean is
2436 begin
2437 return Ekind (E) = E_Private_Type
2438 or else Ekind (E) = E_Limited_Private_Type
2439 or else Ekind (E) = E_Record_Type_With_Private;
2440 end Is_Private_Base_Type;
2441
2442 --------------------------
2443 -- Is_Visible_Dependent --
2444 --------------------------
2445
2446 function Is_Visible_Dependent (Dep : Entity_Id) return Boolean
2447 is
2448 S : constant Entity_Id := Scope (Dep);
2449
2450 begin
2451 -- Renamings created for actual types have the visibility of the actual
2452
2453 if Ekind (S) = E_Package
2454 and then Is_Generic_Instance (S)
2455 and then (Is_Generic_Actual_Type (Dep)
2456 or else Is_Generic_Actual_Type (Full_View (Dep)))
2457 then
2458 return True;
2459
2460 elsif not (Is_Derived_Type (Dep))
2461 and then Is_Derived_Type (Full_View (Dep))
2462 then
2463 -- When instantiating a package body, the scope stack is empty, so
2464 -- check instead whether the dependent type is defined in the same
2465 -- scope as the instance itself.
2466
2467 return In_Open_Scopes (S)
2468 or else (Is_Generic_Instance (Current_Scope)
2469 and then Scope (Dep) = Scope (Current_Scope));
2470 else
2471 return True;
2472 end if;
2473 end Is_Visible_Dependent;
2474
2475 ----------------------------
2476 -- May_Need_Implicit_Body --
2477 ----------------------------
2478
2479 procedure May_Need_Implicit_Body (E : Entity_Id) is
2480 P : constant Node_Id := Unit_Declaration_Node (E);
2481 S : constant Node_Id := Parent (P);
2482 B : Node_Id;
2483 Decls : List_Id;
2484
2485 begin
2486 if not Has_Completion (E)
2487 and then Nkind (P) = N_Package_Declaration
2488 and then (Present (Activation_Chain_Entity (P)) or else Has_RACW (E))
2489 then
2490 B :=
2491 Make_Package_Body (Sloc (E),
2492 Defining_Unit_Name => Make_Defining_Identifier (Sloc (E),
2493 Chars => Chars (E)),
2494 Declarations => New_List);
2495
2496 if Nkind (S) = N_Package_Specification then
2497 if Present (Private_Declarations (S)) then
2498 Decls := Private_Declarations (S);
2499 else
2500 Decls := Visible_Declarations (S);
2501 end if;
2502 else
2503 Decls := Declarations (S);
2504 end if;
2505
2506 Append (B, Decls);
2507 Analyze (B);
2508 end if;
2509 end May_Need_Implicit_Body;
2510
2511 ----------------------
2512 -- New_Private_Type --
2513 ----------------------
2514
2515 procedure New_Private_Type (N : Node_Id; Id : Entity_Id; Def : Node_Id) is
2516 begin
2517 -- For other than Ada 2012, enter the name in the current scope
2518
2519 if Ada_Version < Ada_2012 then
2520 Enter_Name (Id);
2521
2522 -- Ada 2012 (AI05-0162): Enter the name in the current scope. Note that
2523 -- there may be an incomplete previous view.
2524
2525 else
2526 declare
2527 Prev : Entity_Id;
2528 begin
2529 Prev := Find_Type_Name (N);
2530 pragma Assert (Prev = Id
2531 or else (Ekind (Prev) = E_Incomplete_Type
2532 and then Present (Full_View (Prev))
2533 and then Full_View (Prev) = Id));
2534 end;
2535 end if;
2536
2537 if Limited_Present (Def) then
2538 Set_Ekind (Id, E_Limited_Private_Type);
2539 else
2540 Set_Ekind (Id, E_Private_Type);
2541 end if;
2542
2543 Set_Etype (Id, Id);
2544 Set_Has_Delayed_Freeze (Id);
2545 Set_Is_First_Subtype (Id);
2546 Init_Size_Align (Id);
2547
2548 Set_Is_Constrained (Id,
2549 No (Discriminant_Specifications (N))
2550 and then not Unknown_Discriminants_Present (N));
2551
2552 -- Set tagged flag before processing discriminants, to catch illegal
2553 -- usage.
2554
2555 Set_Is_Tagged_Type (Id, Tagged_Present (Def));
2556
2557 Set_Discriminant_Constraint (Id, No_Elist);
2558 Set_Stored_Constraint (Id, No_Elist);
2559
2560 if Present (Discriminant_Specifications (N)) then
2561 Push_Scope (Id);
2562 Process_Discriminants (N);
2563 End_Scope;
2564
2565 elsif Unknown_Discriminants_Present (N) then
2566 Set_Has_Unknown_Discriminants (Id);
2567 end if;
2568
2569 Set_Private_Dependents (Id, New_Elmt_List);
2570
2571 if Tagged_Present (Def) then
2572 Set_Ekind (Id, E_Record_Type_With_Private);
2573 Set_Direct_Primitive_Operations (Id, New_Elmt_List);
2574 Set_Is_Abstract_Type (Id, Abstract_Present (Def));
2575 Set_Is_Limited_Record (Id, Limited_Present (Def));
2576 Set_Has_Delayed_Freeze (Id, True);
2577
2578 -- Recognize Ada.Real_Time.Timing_Events.Timing_Events here
2579
2580 if Is_RTE (Id, RE_Timing_Event) then
2581 Set_Has_Timing_Event (Id);
2582 end if;
2583
2584 -- Create a class-wide type with the same attributes
2585
2586 Make_Class_Wide_Type (Id);
2587
2588 elsif Abstract_Present (Def) then
2589 Error_Msg_N ("only a tagged type can be abstract", N);
2590 end if;
2591 end New_Private_Type;
2592
2593 ---------------------------------
2594 -- Requires_Completion_In_Body --
2595 ---------------------------------
2596
2597 function Requires_Completion_In_Body
2598 (Id : Entity_Id;
2599 Pack_Id : Entity_Id;
2600 Do_Abstract_States : Boolean := False) return Boolean
2601 is
2602 begin
2603 -- Always ignore child units. Child units get added to the entity list
2604 -- of a parent unit, but are not original entities of the parent, and
2605 -- so do not affect whether the parent needs a body.
2606
2607 if Is_Child_Unit (Id) then
2608 return False;
2609
2610 -- Ignore formal packages and their renamings
2611
2612 elsif Ekind (Id) = E_Package
2613 and then Nkind (Original_Node (Unit_Declaration_Node (Id))) =
2614 N_Formal_Package_Declaration
2615 then
2616 return False;
2617
2618 -- Otherwise test to see if entity requires a completion. Note that
2619 -- subprogram entities whose declaration does not come from source are
2620 -- ignored here on the basis that we assume the expander will provide an
2621 -- implicit completion at some point.
2622
2623 elsif (Is_Overloadable (Id)
2624 and then not Ekind_In (Id, E_Enumeration_Literal, E_Operator)
2625 and then not Is_Abstract_Subprogram (Id)
2626 and then not Has_Completion (Id)
2627 and then Comes_From_Source (Parent (Id)))
2628
2629 or else
2630 (Ekind (Id) = E_Package
2631 and then Id /= Pack_Id
2632 and then not Has_Completion (Id)
2633 and then Unit_Requires_Body (Id, Do_Abstract_States))
2634
2635 or else
2636 (Ekind (Id) = E_Incomplete_Type
2637 and then No (Full_View (Id))
2638 and then not Is_Generic_Type (Id))
2639
2640 or else
2641 (Ekind_In (Id, E_Task_Type, E_Protected_Type)
2642 and then not Has_Completion (Id))
2643
2644 or else
2645 (Ekind (Id) = E_Generic_Package
2646 and then Id /= Pack_Id
2647 and then not Has_Completion (Id)
2648 and then Unit_Requires_Body (Id, Do_Abstract_States))
2649
2650 or else
2651 (Is_Generic_Subprogram (Id)
2652 and then not Has_Completion (Id))
2653 then
2654 return True;
2655
2656 -- Otherwise the entity does not require completion in a package body
2657
2658 else
2659 return False;
2660 end if;
2661 end Requires_Completion_In_Body;
2662
2663 ----------------------------
2664 -- Uninstall_Declarations --
2665 ----------------------------
2666
2667 procedure Uninstall_Declarations (P : Entity_Id) is
2668 Decl : constant Node_Id := Unit_Declaration_Node (P);
2669 Id : Entity_Id;
2670 Full : Entity_Id;
2671
2672 procedure Preserve_Full_Attributes (Priv : Entity_Id; Full : Entity_Id);
2673 -- Copy to the private declaration the attributes of the full view that
2674 -- need to be available for the partial view also.
2675
2676 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id);
2677 -- When the full view of a private type is made unavailable, we do the
2678 -- same for its private dependents under proper visibility conditions.
2679 -- When compiling a child unit this needs to be done recursively.
2680
2681 function Type_In_Use (T : Entity_Id) return Boolean;
2682 -- Check whether type or base type appear in an active use_type clause
2683
2684 ------------------------------
2685 -- Preserve_Full_Attributes --
2686 ------------------------------
2687
2688 procedure Preserve_Full_Attributes
2689 (Priv : Entity_Id;
2690 Full : Entity_Id)
2691 is
2692 Full_Base : constant Entity_Id := Base_Type (Full);
2693 Priv_Is_Base_Type : constant Boolean := Is_Base_Type (Priv);
2694
2695 begin
2696 Set_Size_Info (Priv, Full);
2697 Set_RM_Size (Priv, RM_Size (Full));
2698 Set_Size_Known_At_Compile_Time
2699 (Priv, Size_Known_At_Compile_Time (Full));
2700 Set_Is_Volatile (Priv, Is_Volatile (Full));
2701 Set_Treat_As_Volatile (Priv, Treat_As_Volatile (Full));
2702 Set_Is_Ada_2005_Only (Priv, Is_Ada_2005_Only (Full));
2703 Set_Is_Ada_2012_Only (Priv, Is_Ada_2012_Only (Full));
2704 Set_Has_Pragma_Unmodified (Priv, Has_Pragma_Unmodified (Full));
2705 Set_Has_Pragma_Unreferenced (Priv, Has_Pragma_Unreferenced (Full));
2706 Set_Has_Pragma_Unreferenced_Objects
2707 (Priv, Has_Pragma_Unreferenced_Objects
2708 (Full));
2709 if Is_Unchecked_Union (Full) then
2710 Set_Is_Unchecked_Union (Base_Type (Priv));
2711 end if;
2712 -- Why is atomic not copied here ???
2713
2714 if Referenced (Full) then
2715 Set_Referenced (Priv);
2716 end if;
2717
2718 if Priv_Is_Base_Type then
2719 Set_Is_Controlled_Active
2720 (Priv, Is_Controlled_Active (Full_Base));
2721 Set_Finalize_Storage_Only
2722 (Priv, Finalize_Storage_Only (Full_Base));
2723 Set_Has_Controlled_Component
2724 (Priv, Has_Controlled_Component (Full_Base));
2725
2726 Propagate_Concurrent_Flags (Priv, Base_Type (Full));
2727 end if;
2728
2729 -- As explained in Freeze_Entity, private types are required to point
2730 -- to the same freeze node as their corresponding full view, if any.
2731 -- But we ought not to overwrite a node already inserted in the tree.
2732
2733 pragma Assert
2734 (Serious_Errors_Detected /= 0
2735 or else No (Freeze_Node (Priv))
2736 or else No (Parent (Freeze_Node (Priv)))
2737 or else Freeze_Node (Priv) = Freeze_Node (Full));
2738
2739 Set_Freeze_Node (Priv, Freeze_Node (Full));
2740
2741 -- Propagate Default_Initial_Condition-related attributes from the
2742 -- base type of the full view to the full view and vice versa. This
2743 -- may seem strange, but is necessary depending on which type
2744 -- triggered the generation of the DIC procedure body. As a result,
2745 -- both the full view and its base type carry the same DIC-related
2746 -- information.
2747
2748 Propagate_DIC_Attributes (Full, From_Typ => Full_Base);
2749 Propagate_DIC_Attributes (Full_Base, From_Typ => Full);
2750
2751 -- Propagate Default_Initial_Condition-related attributes from the
2752 -- full view to the private view.
2753
2754 Propagate_DIC_Attributes (Priv, From_Typ => Full);
2755
2756 -- Propagate invariant-related attributes from the base type of the
2757 -- full view to the full view and vice versa. This may seem strange,
2758 -- but is necessary depending on which type triggered the generation
2759 -- of the invariant procedure body. As a result, both the full view
2760 -- and its base type carry the same invariant-related information.
2761
2762 Propagate_Invariant_Attributes (Full, From_Typ => Full_Base);
2763 Propagate_Invariant_Attributes (Full_Base, From_Typ => Full);
2764
2765 -- Propagate invariant-related attributes from the full view to the
2766 -- private view.
2767
2768 Propagate_Invariant_Attributes (Priv, From_Typ => Full);
2769
2770 if Is_Tagged_Type (Priv)
2771 and then Is_Tagged_Type (Full)
2772 and then not Error_Posted (Full)
2773 then
2774 if Is_Tagged_Type (Priv) then
2775
2776 -- If the type is tagged, the tag itself must be available on
2777 -- the partial view, for expansion purposes.
2778
2779 Set_First_Entity (Priv, First_Entity (Full));
2780
2781 -- If there are discriminants in the partial view, these remain
2782 -- visible. Otherwise only the tag itself is visible, and there
2783 -- are no nameable components in the partial view.
2784
2785 if No (Last_Entity (Priv)) then
2786 Set_Last_Entity (Priv, First_Entity (Priv));
2787 end if;
2788 end if;
2789
2790 Set_Has_Discriminants (Priv, Has_Discriminants (Full));
2791
2792 if Has_Discriminants (Full) then
2793 Set_Discriminant_Constraint (Priv,
2794 Discriminant_Constraint (Full));
2795 end if;
2796 end if;
2797 end Preserve_Full_Attributes;
2798
2799 -----------------------------
2800 -- Swap_Private_Dependents --
2801 -----------------------------
2802
2803 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id) is
2804 Cunit : Entity_Id;
2805 Deps : Elist_Id;
2806 Priv : Entity_Id;
2807 Priv_Elmt : Elmt_Id;
2808 Is_Priv : Boolean;
2809
2810 begin
2811 Priv_Elmt := First_Elmt (Priv_Deps);
2812 while Present (Priv_Elmt) loop
2813 Priv := Node (Priv_Elmt);
2814
2815 -- Before we do the swap, we verify the presence of the Full_View
2816 -- field, which may be empty due to a swap by a previous call to
2817 -- End_Package_Scope (e.g. from the freezing mechanism).
2818
2819 if Present (Full_View (Priv)) then
2820 if Is_Private_Type (Priv) then
2821 Cunit := Cunit_Entity (Current_Sem_Unit);
2822 Deps := Private_Dependents (Priv);
2823 Is_Priv := True;
2824 else
2825 Is_Priv := False;
2826 end if;
2827
2828 if Scope (Priv) = P
2829 or else not In_Open_Scopes (Scope (Priv))
2830 then
2831 Set_Is_Immediately_Visible (Priv, False);
2832 end if;
2833
2834 if Is_Visible_Dependent (Priv) then
2835 Preserve_Full_Attributes (Priv, Full_View (Priv));
2836 Replace_Elmt (Priv_Elmt, Full_View (Priv));
2837 Exchange_Declarations (Priv);
2838
2839 -- Recurse for child units, except in generic child units,
2840 -- which unfortunately handle private_dependents separately.
2841 -- Note that the current unit may not have been analyzed,
2842 -- for example a package body, so we cannot rely solely on
2843 -- the Is_Child_Unit flag, but that's only an optimization.
2844
2845 if Is_Priv
2846 and then (No (Etype (Cunit)) or else Is_Child_Unit (Cunit))
2847 and then not Is_Empty_Elmt_List (Deps)
2848 and then not Inside_A_Generic
2849 then
2850 Swap_Private_Dependents (Deps);
2851 end if;
2852 end if;
2853 end if;
2854
2855 Next_Elmt (Priv_Elmt);
2856 end loop;
2857 end Swap_Private_Dependents;
2858
2859 -----------------
2860 -- Type_In_Use --
2861 -----------------
2862
2863 function Type_In_Use (T : Entity_Id) return Boolean is
2864 begin
2865 return Scope (Base_Type (T)) = P
2866 and then (In_Use (T) or else In_Use (Base_Type (T)));
2867 end Type_In_Use;
2868
2869 -- Start of processing for Uninstall_Declarations
2870
2871 begin
2872 Id := First_Entity (P);
2873 while Present (Id) and then Id /= First_Private_Entity (P) loop
2874 if Debug_Flag_E then
2875 Write_Str ("unlinking visible entity ");
2876 Write_Int (Int (Id));
2877 Write_Eol;
2878 end if;
2879
2880 -- On exit from the package scope, we must preserve the visibility
2881 -- established by use clauses in the current scope. Two cases:
2882
2883 -- a) If the entity is an operator, it may be a primitive operator of
2884 -- a type for which there is a visible use-type clause.
2885
2886 -- b) For other entities, their use-visibility is determined by a
2887 -- visible use clause for the package itself or a use-all-type clause
2888 -- applied directly to the entity's type. For a generic instance,
2889 -- the instantiation of the formals appears in the visible part,
2890 -- but the formals are private and remain so.
2891
2892 if Ekind (Id) = E_Function
2893 and then Is_Operator_Symbol_Name (Chars (Id))
2894 and then not Is_Hidden (Id)
2895 and then not Error_Posted (Id)
2896 then
2897 Set_Is_Potentially_Use_Visible (Id,
2898 In_Use (P)
2899 or else Type_In_Use (Etype (Id))
2900 or else Type_In_Use (Etype (First_Formal (Id)))
2901 or else (Present (Next_Formal (First_Formal (Id)))
2902 and then
2903 Type_In_Use
2904 (Etype (Next_Formal (First_Formal (Id))))));
2905 else
2906 if In_Use (P) and then not Is_Hidden (Id) then
2907
2908 -- A child unit of a use-visible package remains use-visible
2909 -- only if it is itself a visible child unit. Otherwise it
2910 -- would remain visible in other contexts where P is use-
2911 -- visible, because once compiled it stays in the entity list
2912 -- of its parent unit.
2913
2914 if Is_Child_Unit (Id) then
2915 Set_Is_Potentially_Use_Visible
2916 (Id, Is_Visible_Lib_Unit (Id));
2917 else
2918 Set_Is_Potentially_Use_Visible (Id);
2919 end if;
2920
2921 -- We need to avoid incorrectly marking enumeration literals as
2922 -- non-visible when a visible use-all-type clause is in effect.
2923
2924 elsif Type_In_Use (Etype (Id))
2925 and then Nkind (Current_Use_Clause (Etype (Id))) =
2926 N_Use_Type_Clause
2927 and then All_Present (Current_Use_Clause (Etype (Id)))
2928 then
2929 null;
2930
2931 else
2932 Set_Is_Potentially_Use_Visible (Id, False);
2933 end if;
2934 end if;
2935
2936 -- Local entities are not immediately visible outside of the package
2937
2938 Set_Is_Immediately_Visible (Id, False);
2939
2940 -- If this is a private type with a full view (for example a local
2941 -- subtype of a private type declared elsewhere), ensure that the
2942 -- full view is also removed from visibility: it may be exposed when
2943 -- swapping views in an instantiation. Similarly, ensure that the
2944 -- use-visibility is properly set on both views.
2945
2946 if Is_Type (Id) and then Present (Full_View (Id)) then
2947 Set_Is_Immediately_Visible (Full_View (Id), False);
2948 Set_Is_Potentially_Use_Visible (Full_View (Id),
2949 Is_Potentially_Use_Visible (Id));
2950 end if;
2951
2952 if Is_Tagged_Type (Id) and then Ekind (Id) = E_Record_Type then
2953 Check_Abstract_Overriding (Id);
2954 Check_Conventions (Id);
2955 end if;
2956
2957 if Ekind_In (Id, E_Private_Type, E_Limited_Private_Type)
2958 and then No (Full_View (Id))
2959 and then not Is_Generic_Type (Id)
2960 and then not Is_Derived_Type (Id)
2961 then
2962 Error_Msg_N ("missing full declaration for private type&", Id);
2963
2964 elsif Ekind (Id) = E_Record_Type_With_Private
2965 and then not Is_Generic_Type (Id)
2966 and then No (Full_View (Id))
2967 then
2968 if Nkind (Parent (Id)) = N_Private_Type_Declaration then
2969 Error_Msg_N ("missing full declaration for private type&", Id);
2970 else
2971 Error_Msg_N
2972 ("missing full declaration for private extension", Id);
2973 end if;
2974
2975 -- Case of constant, check for deferred constant declaration with
2976 -- no full view. Likely just a matter of a missing expression, or
2977 -- accidental use of the keyword constant.
2978
2979 elsif Ekind (Id) = E_Constant
2980
2981 -- OK if constant value present
2982
2983 and then No (Constant_Value (Id))
2984
2985 -- OK if full view present
2986
2987 and then No (Full_View (Id))
2988
2989 -- OK if imported, since that provides the completion
2990
2991 and then not Is_Imported (Id)
2992
2993 -- OK if object declaration replaced by renaming declaration as
2994 -- a result of OK_To_Rename processing (e.g. for concatenation)
2995
2996 and then Nkind (Parent (Id)) /= N_Object_Renaming_Declaration
2997
2998 -- OK if object declaration with the No_Initialization flag set
2999
3000 and then not (Nkind (Parent (Id)) = N_Object_Declaration
3001 and then No_Initialization (Parent (Id)))
3002 then
3003 -- If no private declaration is present, we assume the user did
3004 -- not intend a deferred constant declaration and the problem
3005 -- is simply that the initializing expression is missing.
3006
3007 if not Has_Private_Declaration (Etype (Id)) then
3008
3009 -- We assume that the user did not intend a deferred constant
3010 -- declaration, and the expression is just missing.
3011
3012 Error_Msg_N
3013 ("constant declaration requires initialization expression",
3014 Parent (Id));
3015
3016 if Is_Limited_Type (Etype (Id)) then
3017 Error_Msg_N
3018 ("\if variable intended, remove CONSTANT from declaration",
3019 Parent (Id));
3020 end if;
3021
3022 -- Otherwise if a private declaration is present, then we are
3023 -- missing the full declaration for the deferred constant.
3024
3025 else
3026 Error_Msg_N
3027 ("missing full declaration for deferred constant (RM 7.4)",
3028 Id);
3029
3030 if Is_Limited_Type (Etype (Id)) then
3031 Error_Msg_N
3032 ("\if variable intended, remove CONSTANT from declaration",
3033 Parent (Id));
3034 end if;
3035 end if;
3036 end if;
3037
3038 Next_Entity (Id);
3039 end loop;
3040
3041 -- If the specification was installed as the parent of a public child
3042 -- unit, the private declarations were not installed, and there is
3043 -- nothing to do.
3044
3045 if not In_Private_Part (P) then
3046 return;
3047 else
3048 Set_In_Private_Part (P, False);
3049 end if;
3050
3051 -- Make private entities invisible and exchange full and private
3052 -- declarations for private types. Id is now the first private entity
3053 -- in the package.
3054
3055 while Present (Id) loop
3056 if Debug_Flag_E then
3057 Write_Str ("unlinking private entity ");
3058 Write_Int (Int (Id));
3059 Write_Eol;
3060 end if;
3061
3062 if Is_Tagged_Type (Id) and then Ekind (Id) = E_Record_Type then
3063 Check_Abstract_Overriding (Id);
3064 Check_Conventions (Id);
3065 end if;
3066
3067 Set_Is_Immediately_Visible (Id, False);
3068
3069 if Is_Private_Base_Type (Id) and then Present (Full_View (Id)) then
3070 Full := Full_View (Id);
3071
3072 -- If the partial view is not declared in the visible part of the
3073 -- package (as is the case when it is a type derived from some
3074 -- other private type in the private part of the current package),
3075 -- no exchange takes place.
3076
3077 if No (Parent (Id))
3078 or else List_Containing (Parent (Id)) /=
3079 Visible_Declarations (Specification (Decl))
3080 then
3081 goto Next_Id;
3082 end if;
3083
3084 -- The entry in the private part points to the full declaration,
3085 -- which is currently visible. Exchange them so only the private
3086 -- type declaration remains accessible, and link private and full
3087 -- declaration in the opposite direction. Before the actual
3088 -- exchange, we copy back attributes of the full view that must
3089 -- be available to the partial view too.
3090
3091 Preserve_Full_Attributes (Id, Full);
3092
3093 Set_Is_Potentially_Use_Visible (Id, In_Use (P));
3094
3095 -- The following test may be redundant, as this is already
3096 -- diagnosed in sem_ch3. ???
3097
3098 if not Is_Definite_Subtype (Full)
3099 and then Is_Definite_Subtype (Id)
3100 then
3101 Error_Msg_Sloc := Sloc (Parent (Id));
3102 Error_Msg_NE
3103 ("full view of& not compatible with declaration#", Full, Id);
3104 end if;
3105
3106 -- Swap out the subtypes and derived types of Id that
3107 -- were compiled in this scope, or installed previously
3108 -- by Install_Private_Declarations.
3109
3110 Swap_Private_Dependents (Private_Dependents (Id));
3111
3112 -- Now restore the type itself to its private view
3113
3114 Exchange_Declarations (Id);
3115
3116 -- If we have installed an underlying full view for a type derived
3117 -- from a private type in a child unit, restore the proper views
3118 -- of private and full view. See corresponding code in
3119 -- Install_Private_Declarations.
3120
3121 -- After the exchange, Full denotes the private type in the
3122 -- visible part of the package.
3123
3124 if Is_Private_Base_Type (Full)
3125 and then Present (Full_View (Full))
3126 and then Present (Underlying_Full_View (Full))
3127 and then In_Package_Body (Current_Scope)
3128 then
3129 Set_Full_View (Full, Underlying_Full_View (Full));
3130 Set_Underlying_Full_View (Full, Empty);
3131 end if;
3132
3133 elsif Ekind (Id) = E_Incomplete_Type
3134 and then Comes_From_Source (Id)
3135 and then No (Full_View (Id))
3136 then
3137 -- Mark Taft amendment types. Verify that there are no primitive
3138 -- operations declared for the type (3.10.1(9)).
3139
3140 Set_Has_Completion_In_Body (Id);
3141
3142 declare
3143 Elmt : Elmt_Id;
3144 Subp : Entity_Id;
3145
3146 begin
3147 Elmt := First_Elmt (Private_Dependents (Id));
3148 while Present (Elmt) loop
3149 Subp := Node (Elmt);
3150
3151 -- Is_Primitive is tested because there can be cases where
3152 -- nonprimitive subprograms (in nested packages) are added
3153 -- to the Private_Dependents list.
3154
3155 if Is_Overloadable (Subp) and then Is_Primitive (Subp) then
3156 Error_Msg_NE
3157 ("type& must be completed in the private part",
3158 Parent (Subp), Id);
3159
3160 -- The result type of an access-to-function type cannot be a
3161 -- Taft-amendment type, unless the version is Ada 2012 or
3162 -- later (see AI05-151).
3163
3164 elsif Ada_Version < Ada_2012
3165 and then Ekind (Subp) = E_Subprogram_Type
3166 then
3167 if Etype (Subp) = Id
3168 or else
3169 (Is_Class_Wide_Type (Etype (Subp))
3170 and then Etype (Etype (Subp)) = Id)
3171 then
3172 Error_Msg_NE
3173 ("type& must be completed in the private part",
3174 Associated_Node_For_Itype (Subp), Id);
3175 end if;
3176 end if;
3177
3178 Next_Elmt (Elmt);
3179 end loop;
3180 end;
3181
3182 elsif not Is_Child_Unit (Id)
3183 and then (not Is_Private_Type (Id) or else No (Full_View (Id)))
3184 then
3185 Set_Is_Hidden (Id);
3186 Set_Is_Potentially_Use_Visible (Id, False);
3187 end if;
3188
3189 <<Next_Id>>
3190 Next_Entity (Id);
3191 end loop;
3192 end Uninstall_Declarations;
3193
3194 ------------------------
3195 -- Unit_Requires_Body --
3196 ------------------------
3197
3198 function Unit_Requires_Body
3199 (Pack_Id : Entity_Id;
3200 Do_Abstract_States : Boolean := False) return Boolean
3201 is
3202 E : Entity_Id;
3203
3204 Requires_Body : Boolean := False;
3205 -- Flag set when the unit has at least one construct that requires
3206 -- completion in a body.
3207
3208 begin
3209 -- Imported entity never requires body. Right now, only subprograms can
3210 -- be imported, but perhaps in the future we will allow import of
3211 -- packages.
3212
3213 if Is_Imported (Pack_Id) then
3214 return False;
3215
3216 -- Body required if library package with pragma Elaborate_Body
3217
3218 elsif Has_Pragma_Elaborate_Body (Pack_Id) then
3219 return True;
3220
3221 -- Body required if subprogram
3222
3223 elsif Is_Subprogram_Or_Generic_Subprogram (Pack_Id) then
3224 return True;
3225
3226 -- Treat a block as requiring a body
3227
3228 elsif Ekind (Pack_Id) = E_Block then
3229 return True;
3230
3231 elsif Ekind (Pack_Id) = E_Package
3232 and then Nkind (Parent (Pack_Id)) = N_Package_Specification
3233 and then Present (Generic_Parent (Parent (Pack_Id)))
3234 then
3235 declare
3236 G_P : constant Entity_Id := Generic_Parent (Parent (Pack_Id));
3237 begin
3238 if Has_Pragma_Elaborate_Body (G_P) then
3239 return True;
3240 end if;
3241 end;
3242 end if;
3243
3244 -- Traverse the entity chain of the package and look for constructs that
3245 -- require a completion in a body.
3246
3247 E := First_Entity (Pack_Id);
3248 while Present (E) loop
3249
3250 -- Skip abstract states because their completion depends on several
3251 -- criteria (see below).
3252
3253 if Ekind (E) = E_Abstract_State then
3254 null;
3255
3256 elsif Requires_Completion_In_Body
3257 (E, Pack_Id, Do_Abstract_States)
3258 then
3259 Requires_Body := True;
3260 exit;
3261 end if;
3262
3263 Next_Entity (E);
3264 end loop;
3265
3266 -- A [generic] package that defines at least one non-null abstract state
3267 -- requires a completion only when at least one other construct requires
3268 -- a completion in a body (SPARK RM 7.1.4(4) and (5)). This check is not
3269 -- performed if the caller requests this behavior.
3270
3271 if Do_Abstract_States
3272 and then Is_Package_Or_Generic_Package (Pack_Id)
3273 and then Has_Non_Null_Abstract_State (Pack_Id)
3274 and then Requires_Body
3275 then
3276 return True;
3277 end if;
3278
3279 return Requires_Body;
3280 end Unit_Requires_Body;
3281
3282 -----------------------------
3283 -- Unit_Requires_Body_Info --
3284 -----------------------------
3285
3286 procedure Unit_Requires_Body_Info (Pack_Id : Entity_Id) is
3287 E : Entity_Id;
3288
3289 begin
3290 -- An imported entity never requires body. Right now, only subprograms
3291 -- can be imported, but perhaps in the future we will allow import of
3292 -- packages.
3293
3294 if Is_Imported (Pack_Id) then
3295 return;
3296
3297 -- Body required if library package with pragma Elaborate_Body
3298
3299 elsif Has_Pragma_Elaborate_Body (Pack_Id) then
3300 Error_Msg_N ("info: & requires body (Elaborate_Body)?Y?", Pack_Id);
3301
3302 -- Body required if subprogram
3303
3304 elsif Is_Subprogram_Or_Generic_Subprogram (Pack_Id) then
3305 Error_Msg_N ("info: & requires body (subprogram case)?Y?", Pack_Id);
3306
3307 -- Body required if generic parent has Elaborate_Body
3308
3309 elsif Ekind (Pack_Id) = E_Package
3310 and then Nkind (Parent (Pack_Id)) = N_Package_Specification
3311 and then Present (Generic_Parent (Parent (Pack_Id)))
3312 then
3313 declare
3314 G_P : constant Entity_Id := Generic_Parent (Parent (Pack_Id));
3315 begin
3316 if Has_Pragma_Elaborate_Body (G_P) then
3317 Error_Msg_N
3318 ("info: & requires body (generic parent Elaborate_Body)?Y?",
3319 Pack_Id);
3320 end if;
3321 end;
3322
3323 -- A [generic] package that introduces at least one non-null abstract
3324 -- state requires completion. However, there is a separate rule that
3325 -- requires that such a package have a reason other than this for a
3326 -- body being required (if necessary a pragma Elaborate_Body must be
3327 -- provided). If Ignore_Abstract_State is True, we don't do this check
3328 -- (so we can use Unit_Requires_Body to check for some other reason).
3329
3330 elsif Is_Package_Or_Generic_Package (Pack_Id)
3331 and then Present (Abstract_States (Pack_Id))
3332 and then not Is_Null_State
3333 (Node (First_Elmt (Abstract_States (Pack_Id))))
3334 then
3335 Error_Msg_N
3336 ("info: & requires body (non-null abstract state aspect)?Y?",
3337 Pack_Id);
3338 end if;
3339
3340 -- Otherwise search entity chain for entity requiring completion
3341
3342 E := First_Entity (Pack_Id);
3343 while Present (E) loop
3344 if Requires_Completion_In_Body (E, Pack_Id) then
3345 Error_Msg_Node_2 := E;
3346 Error_Msg_NE
3347 ("info: & requires body (& requires completion)?Y?", E, Pack_Id);
3348 end if;
3349
3350 Next_Entity (E);
3351 end loop;
3352 end Unit_Requires_Body_Info;
3353
3354 end Sem_Ch7;
This page took 0.179406 seconds and 6 git commands to generate.