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