]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_ch10.adb
[Ada] Variable-sized node types -- cleanup
[gcc.git] / gcc / ada / sem_ch10.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 1 0 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Contracts; use Contracts;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Errout; use Errout;
34 with Exp_Put_Image;
35 with Exp_Util; use Exp_Util;
36 with Elists; use Elists;
37 with Fname; use Fname;
38 with Fname.UF; use Fname.UF;
39 with Freeze; use Freeze;
40 with Impunit; use Impunit;
41 with Inline; use Inline;
42 with Lib; use Lib;
43 with Lib.Load; use Lib.Load;
44 with Lib.Xref; use Lib.Xref;
45 with Namet; use Namet;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
48 with Opt; use Opt;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
54 with Sem; use Sem;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch7; use Sem_Ch7;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Prag; use Sem_Prag;
63 with Sem_Util; use Sem_Util;
64 with Sem_Warn; use Sem_Warn;
65 with Stand; use Stand;
66 with Sinfo; use Sinfo;
67 with Sinfo.Nodes; use Sinfo.Nodes;
68 with Sinfo.Utils; use Sinfo.Utils;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Style; use Style;
73 with Stylesw; use Stylesw;
74 with Tbuild; use Tbuild;
75 with Uname; use Uname;
76
77 package body Sem_Ch10 is
78
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
82
83 procedure Analyze_Context (N : Node_Id);
84 -- Analyzes items in the context clause of compilation unit
85
86 procedure Build_Limited_Views (N : Node_Id);
87 -- Build and decorate the list of shadow entities for a package mentioned
88 -- in a limited_with clause. If the package was not previously analyzed
89 -- then it also performs a basic decoration of the real entities. This is
90 -- required in order to avoid passing non-decorated entities to the
91 -- back-end. Implements Ada 2005 (AI-50217).
92
93 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id);
94 -- Common processing for all stubs (subprograms, tasks, packages, and
95 -- protected cases). N is the stub to be analyzed. Once the subunit name
96 -- is established, load and analyze. Nam is the non-overloadable entity
97 -- for which the proper body provides a completion. Subprogram stubs are
98 -- handled differently because they can be declarations.
99
100 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id);
101 -- Check whether the source for the body of a compilation unit must be
102 -- included in a standalone library.
103
104 procedure Check_No_Elab_Code_All (N : Node_Id);
105 -- Carries out possible tests for violation of No_Elab_Code all for withed
106 -- units in the Context_Items of unit N.
107
108 procedure Check_Private_Child_Unit (N : Node_Id);
109 -- If a with_clause mentions a private child unit, the compilation unit
110 -- must be a member of the same family, as described in 10.1.2.
111
112 procedure Check_Stub_Level (N : Node_Id);
113 -- Verify that a stub is declared immediately within a compilation unit,
114 -- and not in an inner frame.
115
116 procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id);
117 -- When a child unit appears in a context clause, the implicit withs on
118 -- parents are made explicit, and with clauses are inserted in the context
119 -- clause before the one for the child. If a parent in the with_clause
120 -- is a renaming, the implicit with_clause is on the renaming whose name
121 -- is mentioned in the with_clause, and not on the package it renames.
122 -- N is the compilation unit whose list of context items receives the
123 -- implicit with_clauses.
124
125 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id);
126 -- Generate cross-reference information for the parents of child units
127 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
128 -- immediate parent scope.
129
130 function Has_With_Clause
131 (C_Unit : Node_Id;
132 Pack : Entity_Id;
133 Is_Limited : Boolean := False) return Boolean;
134 -- Determine whether compilation unit C_Unit contains a [limited] with
135 -- clause for package Pack. Use the flag Is_Limited to designate desired
136 -- clause kind.
137
138 procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id);
139 -- If the main unit is a child unit, implicit withs are also added for
140 -- all its ancestors.
141
142 function In_Chain (E : Entity_Id) return Boolean;
143 -- Check that the shadow entity is not already in the homonym chain, for
144 -- example through a limited_with clause in a parent unit.
145
146 procedure Install_Context_Clauses (N : Node_Id; Chain : Boolean := True);
147 -- Subsidiary to Install_Context and Install_Parents. Process all with
148 -- and use clauses for current unit and its library unit if any. The flag
149 -- Chain is used to control the "chaining" or linking together of use-type
150 -- and use-package clauses to avoid circularities with reinstalling
151 -- clauses.
152
153 procedure Install_Limited_Context_Clauses (N : Node_Id);
154 -- Subsidiary to Install_Context. Process only limited with_clauses for
155 -- current unit. Implements Ada 2005 (AI-50217).
156
157 procedure Install_Limited_With_Clause (N : Node_Id);
158 -- Place shadow entities for a limited_with package in the visibility
159 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
160
161 procedure Install_Parents
162 (Lib_Unit : Node_Id;
163 Is_Private : Boolean;
164 Chain : Boolean := True);
165 -- This procedure establishes the context for the compilation of a child
166 -- unit. If Lib_Unit is a child library spec then the context of the parent
167 -- is installed, and the parent itself made immediately visible, so that
168 -- the child unit is processed in the declarative region of the parent.
169 -- Install_Parents makes a recursive call to itself to ensure that all
170 -- parents are loaded in the nested case. If Lib_Unit is a library body,
171 -- the only effect of Install_Parents is to install the private decls of
172 -- the parents, because the visible parent declarations will have been
173 -- installed as part of the context of the corresponding spec. The flag
174 -- Chain is used to control the "chaining" or linking of use-type and
175 -- use-package clauses to avoid circularities when installing context.
176
177 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
178 -- In the compilation of a child unit, a child of any of the ancestor
179 -- units is directly visible if it is visible, because the parent is in
180 -- an enclosing scope. Iterate over context to find child units of U_Name
181 -- or of some ancestor of it.
182
183 procedure Install_With_Clause
184 (With_Clause : Node_Id;
185 Private_With_OK : Boolean := False);
186 -- If the unit is not a child unit, make unit immediately visible. The
187 -- caller ensures that the unit is not already currently installed. The
188 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
189 -- is called when compiling the private part of a package, or installing
190 -- the private declarations of a parent unit.
191
192 function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean;
193 -- When compiling a unit Q descended from some parent unit P, a limited
194 -- with_clause in the context of P that names some other ancestor of Q
195 -- must not be installed because the ancestor is immediately visible.
196
197 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean;
198 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
199 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
200 -- a library spec that has a parent. If the call to Is_Child_Spec returns
201 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
202 -- compilation unit for the parent spec.
203 --
204 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
205 -- Parent_Spec is non-empty, this is also a child unit.
206
207 procedure Remove_Context_Clauses (N : Node_Id);
208 -- Subsidiary of previous one. Remove use_ and with_clauses
209
210 procedure Remove_Limited_With_Clause (N : Node_Id);
211 -- Remove the shadow entities from visibility introduced for a package
212 -- mentioned in limited with clause N. Implements Ada 2005 (AI-50217).
213
214 procedure Remove_Limited_With_Unit
215 (Pack_Decl : Node_Id;
216 Lim_Clause : Node_Id := Empty);
217 -- Remove the shadow entities from visibility introduced for a package
218 -- denoted by declaration Pack_Decl. Lim_Clause is the related limited
219 -- with clause, if any. Implements Ada 2005 (AI-50217).
220
221 procedure Remove_Parents (Lib_Unit : Node_Id);
222 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
223 -- contexts established by the corresponding call to Install_Parents are
224 -- removed. Remove_Parents contains a recursive call to itself to ensure
225 -- that all parents are removed in the nested case.
226
227 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id);
228 -- Reset all visibility flags on unit after compiling it, either as a main
229 -- unit or as a unit in the context.
230
231 procedure Unchain (E : Entity_Id);
232 -- Remove single entity from visibility list
233
234 procedure sm;
235 -- A dummy procedure, for debugging use, called just before analyzing the
236 -- main unit (after dealing with any context clauses).
237
238 --------------------------
239 -- Limited_With_Clauses --
240 --------------------------
241
242 -- Limited_With clauses are the mechanism chosen for Ada 2005 to support
243 -- mutually recursive types declared in different units. A limited_with
244 -- clause that names package P in the context of unit U makes the types
245 -- declared in the visible part of P available within U, but with the
246 -- restriction that these types can only be used as incomplete types.
247 -- The limited_with clause does not impose a semantic dependence on P,
248 -- and it is possible for two packages to have limited_with_clauses on
249 -- each other without creating an elaboration circularity.
250
251 -- To support this feature, the analysis of a limited_with clause must
252 -- create an abbreviated view of the package, without performing any
253 -- semantic analysis on it. This "package abstract" contains shadow types
254 -- that are in one-one correspondence with the real types in the package,
255 -- and that have the properties of incomplete types.
256
257 -- The implementation creates two element lists: one to chain the shadow
258 -- entities, and one to chain the corresponding type entities in the tree
259 -- of the package. Links between corresponding entities in both chains
260 -- allow the compiler to select the proper view of a given type, depending
261 -- on the context. Note that in contrast with the handling of private
262 -- types, the limited view and the nonlimited view of a type are treated
263 -- as separate entities, and no entity exchange needs to take place, which
264 -- makes the implementation much simpler than could be feared.
265
266 ------------------------------
267 -- Analyze_Compilation_Unit --
268 ------------------------------
269
270 procedure Analyze_Compilation_Unit (N : Node_Id) is
271 procedure Check_Redundant_Withs
272 (Context_Items : List_Id;
273 Spec_Context_Items : List_Id := No_List);
274 -- Determine whether the context list of a compilation unit contains
275 -- redundant with clauses. When checking body clauses against spec
276 -- clauses, set Context_Items to the context list of the body and
277 -- Spec_Context_Items to that of the spec. Parent packages are not
278 -- examined for documentation purposes.
279
280 ---------------------------
281 -- Check_Redundant_Withs --
282 ---------------------------
283
284 procedure Check_Redundant_Withs
285 (Context_Items : List_Id;
286 Spec_Context_Items : List_Id := No_List)
287 is
288 Clause : Node_Id;
289
290 procedure Process_Body_Clauses
291 (Context_List : List_Id;
292 Clause : Node_Id;
293 Used : out Boolean;
294 Used_Type_Or_Elab : out Boolean);
295 -- Examine the context clauses of a package body, trying to match the
296 -- name entity of Clause with any list element. If the match occurs
297 -- on a use package clause set Used to True, for a use type clause or
298 -- pragma Elaborate[_All], set Used_Type_Or_Elab to True.
299
300 procedure Process_Spec_Clauses
301 (Context_List : List_Id;
302 Clause : Node_Id;
303 Used : out Boolean;
304 Withed : out Boolean;
305 Exit_On_Self : Boolean := False);
306 -- Examine the context clauses of a package spec, trying to match
307 -- the name entity of Clause with any list element. If the match
308 -- occurs on a use package clause, set Used to True, for a with
309 -- package clause other than Clause, set Withed to True. Limited
310 -- with clauses, implicitly generated with clauses and withs
311 -- having pragmas Elaborate or Elaborate_All applied to them are
312 -- skipped. Exit_On_Self is used to control the search loop and
313 -- force an exit whenever Clause sees itself in the search.
314
315 --------------------------
316 -- Process_Body_Clauses --
317 --------------------------
318
319 procedure Process_Body_Clauses
320 (Context_List : List_Id;
321 Clause : Node_Id;
322 Used : out Boolean;
323 Used_Type_Or_Elab : out Boolean)
324 is
325 Nam_Ent : constant Entity_Id := Entity (Name (Clause));
326 Cont_Item : Node_Id;
327 Prag_Unit : Node_Id;
328 Use_Item : Node_Id;
329
330 function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean;
331 -- In an expanded name in a use clause, if the prefix is a renamed
332 -- package, the entity is set to the original package as a result,
333 -- when checking whether the package appears in a previous with
334 -- clause, the renaming has to be taken into account, to prevent
335 -- spurious/incorrect warnings. A common case is use of Text_IO.
336
337 ---------------
338 -- Same_Unit --
339 ---------------
340
341 function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean is
342 begin
343 return Entity (N) = P
344 or else (Present (Renamed_Object (P))
345 and then Entity (N) = Renamed_Object (P));
346 end Same_Unit;
347
348 -- Start of processing for Process_Body_Clauses
349
350 begin
351 Used := False;
352 Used_Type_Or_Elab := False;
353
354 Cont_Item := First (Context_List);
355 while Present (Cont_Item) loop
356
357 -- Package use clause
358
359 if Nkind (Cont_Item) = N_Use_Package_Clause
360 and then not Used
361 then
362 -- Search through use clauses
363
364 Use_Item := Name (Cont_Item);
365
366 -- Case of a direct use of the one we are looking for
367
368 if Entity (Use_Item) = Nam_Ent then
369 Used := True;
370
371 -- Handle nested case, as in "with P; use P.Q.R"
372
373 else
374 declare
375 UE : Node_Id;
376
377 begin
378 -- Loop through prefixes looking for match
379
380 UE := Use_Item;
381 while Nkind (UE) = N_Expanded_Name loop
382 if Same_Unit (Prefix (UE), Nam_Ent) then
383 Used := True;
384 exit;
385 end if;
386
387 UE := Prefix (UE);
388 end loop;
389 end;
390 end if;
391
392 -- USE TYPE clause
393
394 elsif Nkind (Cont_Item) = N_Use_Type_Clause
395 and then not Used_Type_Or_Elab
396 then
397 declare
398 UE : Node_Id;
399
400 begin
401 -- Loop through prefixes looking for a match
402
403 UE := Prefix (Subtype_Mark (Cont_Item));
404 loop
405 if not Used_Type_Or_Elab
406 and then Same_Unit (UE, Nam_Ent)
407 then
408 Used_Type_Or_Elab := True;
409 end if;
410
411 exit when Nkind (UE) /= N_Expanded_Name;
412 UE := Prefix (UE);
413 end loop;
414 end;
415
416 -- Pragma Elaborate or Elaborate_All
417
418 elsif Nkind (Cont_Item) = N_Pragma
419 and then
420 Pragma_Name_Unmapped (Cont_Item)
421 in Name_Elaborate | Name_Elaborate_All
422 and then not Used_Type_Or_Elab
423 then
424 Prag_Unit :=
425 First (Pragma_Argument_Associations (Cont_Item));
426 while Present (Prag_Unit) and then not Used_Type_Or_Elab loop
427 if Entity (Expression (Prag_Unit)) = Nam_Ent then
428 Used_Type_Or_Elab := True;
429 end if;
430
431 Next (Prag_Unit);
432 end loop;
433 end if;
434
435 Next (Cont_Item);
436 end loop;
437 end Process_Body_Clauses;
438
439 --------------------------
440 -- Process_Spec_Clauses --
441 --------------------------
442
443 procedure Process_Spec_Clauses
444 (Context_List : List_Id;
445 Clause : Node_Id;
446 Used : out Boolean;
447 Withed : out Boolean;
448 Exit_On_Self : Boolean := False)
449 is
450 Nam_Ent : constant Entity_Id := Entity (Name (Clause));
451 Cont_Item : Node_Id;
452
453 begin
454 Used := False;
455 Withed := False;
456
457 Cont_Item := First (Context_List);
458 while Present (Cont_Item) loop
459
460 -- Stop the search since the context items after Cont_Item have
461 -- already been examined in a previous iteration of the reverse
462 -- loop in Check_Redundant_Withs.
463
464 if Exit_On_Self
465 and Cont_Item = Clause
466 then
467 exit;
468 end if;
469
470 -- Package use clause
471
472 if Nkind (Cont_Item) = N_Use_Package_Clause
473 and then not Used
474 then
475 if Entity (Name (Cont_Item)) = Nam_Ent then
476 Used := True;
477 end if;
478
479 -- Package with clause. Avoid processing self, implicitly
480 -- generated with clauses or limited with clauses. Note that
481 -- we examine with clauses having pragmas Elaborate or
482 -- Elaborate_All applied to them due to cases such as:
483
484 -- with Pack;
485 -- with Pack;
486 -- pragma Elaborate (Pack);
487
488 -- In this case, the second with clause is redundant since
489 -- the pragma applies only to the first "with Pack;".
490
491 -- Note that we only consider with_clauses that comes from
492 -- source. In the case of renamings used as prefixes of names
493 -- in with_clauses, we generate a with_clause for the prefix,
494 -- which we do not treat as implicit because it is needed for
495 -- visibility analysis, but is also not redundant.
496
497 elsif Nkind (Cont_Item) = N_With_Clause
498 and then Comes_From_Source (Cont_Item)
499 and then not Implicit_With (Cont_Item)
500 and then not Limited_Present (Cont_Item)
501 and then Cont_Item /= Clause
502 and then Entity (Name (Cont_Item)) = Nam_Ent
503 then
504 Withed := True;
505 end if;
506
507 Next (Cont_Item);
508 end loop;
509 end Process_Spec_Clauses;
510
511 -- Start of processing for Check_Redundant_Withs
512
513 begin
514 Clause := Last (Context_Items);
515 while Present (Clause) loop
516
517 -- Avoid checking implicitly generated with clauses, limited with
518 -- clauses or withs that have pragma Elaborate or Elaborate_All.
519
520 if Nkind (Clause) = N_With_Clause
521 and then not Implicit_With (Clause)
522 and then not Limited_Present (Clause)
523 and then not Elaborate_Present (Clause)
524
525 -- With_clauses introduced for renamings of parent clauses
526 -- are not marked implicit because they need to be properly
527 -- installed, but they do not come from source and do not
528 -- require warnings.
529
530 and then Comes_From_Source (Clause)
531 then
532 -- Package body-to-spec check
533
534 if Present (Spec_Context_Items) then
535 declare
536 Used_In_Body : Boolean;
537 Used_In_Spec : Boolean;
538 Used_Type_Or_Elab : Boolean;
539 Withed_In_Spec : Boolean;
540
541 begin
542 Process_Spec_Clauses
543 (Context_List => Spec_Context_Items,
544 Clause => Clause,
545 Used => Used_In_Spec,
546 Withed => Withed_In_Spec);
547
548 Process_Body_Clauses
549 (Context_List => Context_Items,
550 Clause => Clause,
551 Used => Used_In_Body,
552 Used_Type_Or_Elab => Used_Type_Or_Elab);
553
554 -- "Type Elab" refers to the presence of either a use
555 -- type clause, pragmas Elaborate or Elaborate_All.
556
557 -- +---------------+---------------------------+------+
558 -- | Spec | Body | Warn |
559 -- +--------+------+--------+------+-----------+------+
560 -- | Withed | Used | Withed | Used | Type Elab | |
561 -- | X | | X | | | X |
562 -- | X | | X | X | | |
563 -- | X | | X | | X | |
564 -- | X | | X | X | X | |
565 -- | X | X | X | | | X |
566 -- | X | X | X | | X | |
567 -- | X | X | X | X | | X |
568 -- | X | X | X | X | X | |
569 -- +--------+------+--------+------+-----------+------+
570
571 if (Withed_In_Spec
572 and then not Used_Type_Or_Elab)
573 and then
574 ((not Used_In_Spec and then not Used_In_Body)
575 or else Used_In_Spec)
576 then
577 Error_Msg_N -- CODEFIX
578 ("redundant with clause in body?r?", Clause);
579 end if;
580
581 Used_In_Body := False;
582 Used_In_Spec := False;
583 Used_Type_Or_Elab := False;
584 Withed_In_Spec := False;
585 end;
586
587 -- Standalone package spec or body check
588
589 else
590 declare
591 Dummy : Boolean := False;
592 Withed : Boolean := False;
593
594 begin
595 -- The mechanism for examining the context clauses of a
596 -- package spec can be applied to package body clauses.
597
598 Process_Spec_Clauses
599 (Context_List => Context_Items,
600 Clause => Clause,
601 Used => Dummy,
602 Withed => Withed,
603 Exit_On_Self => True);
604
605 if Withed then
606 Error_Msg_N -- CODEFIX
607 ("redundant with clause?r?", Clause);
608 end if;
609 end;
610 end if;
611 end if;
612
613 Prev (Clause);
614 end loop;
615 end Check_Redundant_Withs;
616
617 -- Local variables
618
619 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
620 Unit_Node : constant Node_Id := Unit (N);
621 Lib_Unit : Node_Id := Library_Unit (N);
622 Par_Spec_Name : Unit_Name_Type;
623 Spec_Id : Entity_Id;
624 Unum : Unit_Number_Type;
625
626 -- Start of processing for Analyze_Compilation_Unit
627
628 begin
629 Exp_Put_Image.Preload_Sink (N);
630
631 Process_Compilation_Unit_Pragmas (N);
632
633 -- If the unit is a subunit whose parent has not been analyzed (which
634 -- indicates that the main unit is a subunit, either the current one or
635 -- one of its descendants) then the subunit is compiled as part of the
636 -- analysis of the parent, which we proceed to do. Basically this gets
637 -- handled from the top down and we don't want to do anything at this
638 -- level (i.e. this subunit will be handled on the way down from the
639 -- parent), so at this level we immediately return. If the subunit ends
640 -- up not analyzed, it means that the parent did not contain a stub for
641 -- it, or that there errors were detected in some ancestor.
642
643 if Nkind (Unit_Node) = N_Subunit and then not Analyzed (Lib_Unit) then
644 Semantics (Lib_Unit);
645
646 if not Analyzed (Proper_Body (Unit_Node)) then
647 if Serious_Errors_Detected > 0 then
648 Error_Msg_N ("subunit not analyzed (errors in parent unit)", N);
649 else
650 Error_Msg_N ("missing stub for subunit", N);
651 end if;
652 end if;
653
654 return;
655 end if;
656
657 -- Analyze context (this will call Sem recursively for with'ed units) To
658 -- detect circularities among with-clauses that are not caught during
659 -- loading, we set the Context_Pending flag on the current unit. If the
660 -- flag is already set there is a potential circularity. We exclude
661 -- predefined units from this check because they are known to be safe.
662 -- We also exclude package bodies that are present because circularities
663 -- between bodies are harmless (and necessary).
664
665 if Context_Pending (N) then
666 declare
667 Circularity : Boolean := True;
668
669 begin
670 if In_Predefined_Unit (N) then
671 Circularity := False;
672
673 else
674 for U in Main_Unit + 1 .. Last_Unit loop
675 if Nkind (Unit (Cunit (U))) = N_Package_Body
676 and then not Analyzed (Cunit (U))
677 then
678 Circularity := False;
679 exit;
680 end if;
681 end loop;
682 end if;
683
684 if Circularity then
685 Error_Msg_N ("circular dependency caused by with_clauses", N);
686 Error_Msg_N
687 ("\possibly missing limited_with clause"
688 & " in one of the following", N);
689
690 for U in Main_Unit .. Last_Unit loop
691 if Context_Pending (Cunit (U)) then
692 Error_Msg_Unit_1 := Get_Unit_Name (Unit (Cunit (U)));
693 Error_Msg_N ("\unit$", N);
694 end if;
695 end loop;
696
697 raise Unrecoverable_Error;
698 end if;
699 end;
700 else
701 Set_Context_Pending (N);
702 end if;
703
704 Analyze_Context (N);
705
706 Set_Context_Pending (N, False);
707
708 -- If the unit is a package body, the spec is already loaded and must be
709 -- analyzed first, before we analyze the body.
710
711 if Nkind (Unit_Node) = N_Package_Body then
712
713 -- If no Lib_Unit, then there was a serious previous error, so just
714 -- ignore the entire analysis effort.
715
716 if No (Lib_Unit) then
717 Check_Error_Detected;
718 return;
719
720 else
721 -- Analyze the package spec
722
723 Semantics (Lib_Unit);
724
725 -- Check for unused with's
726
727 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
728
729 -- Verify that the library unit is a package declaration
730
731 if Nkind (Unit (Lib_Unit)) not in
732 N_Package_Declaration | N_Generic_Package_Declaration
733 then
734 Error_Msg_N
735 ("no legal package declaration for package body", N);
736 return;
737
738 -- Otherwise, the entity in the declaration is visible. Update the
739 -- version to reflect dependence of this body on the spec.
740
741 else
742 Spec_Id := Defining_Entity (Unit (Lib_Unit));
743 Set_Is_Immediately_Visible (Spec_Id, True);
744 Version_Update (N, Lib_Unit);
745
746 if Nkind (Defining_Unit_Name (Unit_Node)) =
747 N_Defining_Program_Unit_Name
748 then
749 Generate_Parent_References (Unit_Node, Scope (Spec_Id));
750 end if;
751 end if;
752 end if;
753
754 -- If the unit is a subprogram body, then we similarly need to analyze
755 -- its spec. However, things are a little simpler in this case, because
756 -- here, this analysis is done mostly for error checking and consistency
757 -- purposes (but not only, e.g. there could be a contract on the spec),
758 -- so there's nothing else to be done.
759
760 elsif Nkind (Unit_Node) = N_Subprogram_Body then
761 if Acts_As_Spec (N) then
762
763 -- If the subprogram body is a child unit, we must create a
764 -- declaration for it, in order to properly load the parent(s).
765 -- After this, the original unit does not acts as a spec, because
766 -- there is an explicit one. If this unit appears in a context
767 -- clause, then an implicit with on the parent will be added when
768 -- installing the context. If this is the main unit, there is no
769 -- Unit_Table entry for the declaration (it has the unit number
770 -- of the main unit) and code generation is unaffected.
771
772 Unum := Get_Cunit_Unit_Number (N);
773 Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum));
774
775 if Present (Par_Spec_Name) then
776 Unum :=
777 Load_Unit
778 (Load_Name => Par_Spec_Name,
779 Required => True,
780 Subunit => False,
781 Error_Node => N);
782
783 if Unum /= No_Unit then
784
785 -- Build subprogram declaration and attach parent unit to it
786 -- This subprogram declaration does not come from source,
787 -- Nevertheless the backend must generate debugging info for
788 -- it, and this must be indicated explicitly. We also mark
789 -- the body entity as a child unit now, to prevent a
790 -- cascaded error if the spec entity cannot be entered
791 -- in its scope. Finally we create a Units table entry for
792 -- the subprogram declaration, to maintain a one-to-one
793 -- correspondence with compilation unit nodes. This is
794 -- critical for the tree traversals performed by CodePeer.
795
796 declare
797 Loc : constant Source_Ptr := Sloc (N);
798 SCS : constant Boolean :=
799 Get_Comes_From_Source_Default;
800
801 begin
802 Set_Comes_From_Source_Default (False);
803
804 -- Note: We copy the Context_Items from the explicit body
805 -- to the implicit spec, setting the former to Empty_List
806 -- to preserve the treeish nature of the tree, during
807 -- analysis of the spec. Then we put it back the way it
808 -- was -- copy the Context_Items from the spec to the
809 -- body, and set the spec Context_Items to Empty_List.
810 -- It is necessary to preserve the treeish nature,
811 -- because otherwise we will call End_Use_* twice on the
812 -- same thing.
813
814 Lib_Unit :=
815 Make_Compilation_Unit (Loc,
816 Context_Items => Context_Items (N),
817 Unit =>
818 Make_Subprogram_Declaration (Sloc (N),
819 Specification =>
820 Copy_Separate_Tree
821 (Specification (Unit_Node))),
822 Aux_Decls_Node =>
823 Make_Compilation_Unit_Aux (Loc));
824
825 Set_Context_Items (N, Empty_List);
826 Set_Library_Unit (N, Lib_Unit);
827 Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
828 Make_Child_Decl_Unit (N);
829 Semantics (Lib_Unit);
830
831 -- Now that a separate declaration exists, the body
832 -- of the child unit does not act as spec any longer.
833
834 Set_Acts_As_Spec (N, False);
835 Move_Aspects (From => Unit_Node, To => Unit (Lib_Unit));
836 Set_Is_Child_Unit (Defining_Entity (Unit_Node));
837 Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit)));
838 Set_Comes_From_Source_Default (SCS);
839
840 -- Restore Context_Items to the body
841
842 Set_Context_Items (N, Context_Items (Lib_Unit));
843 Set_Context_Items (Lib_Unit, Empty_List);
844 end;
845 end if;
846 end if;
847
848 -- Here for subprogram with separate declaration
849
850 else
851 Semantics (Lib_Unit);
852 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
853 Version_Update (N, Lib_Unit);
854 end if;
855
856 -- If this is a child unit, generate references to the parents
857
858 if Nkind (Defining_Unit_Name (Specification (Unit_Node))) =
859 N_Defining_Program_Unit_Name
860 then
861 Generate_Parent_References
862 (Specification (Unit_Node),
863 Scope (Defining_Entity (Unit (Lib_Unit))));
864 end if;
865 end if;
866
867 -- If it is a child unit, the parent must be elaborated first and we
868 -- update version, since we are dependent on our parent.
869
870 if Is_Child_Spec (Unit_Node) then
871
872 -- The analysis of the parent is done with style checks off
873
874 declare
875 Save_Style_Check : constant Boolean := Style_Check;
876
877 begin
878 if not GNAT_Mode then
879 Style_Check := False;
880 end if;
881
882 Semantics (Parent_Spec (Unit_Node));
883 Version_Update (N, Parent_Spec (Unit_Node));
884
885 -- Restore style check settings
886
887 Style_Check := Save_Style_Check;
888 end;
889 end if;
890
891 -- With the analysis done, install the context. Note that we can't
892 -- install the context from the with clauses as we analyze them, because
893 -- each with clause must be analyzed in a clean visibility context, so
894 -- we have to wait and install them all at once.
895
896 Install_Context (N);
897
898 if Is_Child_Spec (Unit_Node) then
899
900 -- Set the entities of all parents in the program_unit_name
901
902 Generate_Parent_References
903 (Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node))));
904 end if;
905
906 -- All components of the context: with-clauses, library unit, ancestors
907 -- if any, (and their context) are analyzed and installed.
908
909 -- Call special debug routine sm if this is the main unit
910
911 if Current_Sem_Unit = Main_Unit then
912 sm;
913 end if;
914
915 -- Now analyze the unit (package, subprogram spec, body) itself
916
917 Analyze (Unit_Node);
918
919 if Warn_On_Redundant_Constructs then
920 Check_Redundant_Withs (Context_Items (N));
921
922 if Nkind (Unit_Node) = N_Package_Body then
923 Check_Redundant_Withs
924 (Context_Items => Context_Items (N),
925 Spec_Context_Items => Context_Items (Lib_Unit));
926 end if;
927 end if;
928
929 -- The above call might have made Unit_Node an N_Subprogram_Body from
930 -- something else, so propagate any Acts_As_Spec flag.
931
932 if Nkind (Unit_Node) = N_Subprogram_Body
933 and then Acts_As_Spec (Unit_Node)
934 then
935 Set_Acts_As_Spec (N);
936 end if;
937
938 -- Register predefined units in Rtsfind
939
940 if In_Predefined_Unit (N) then
941 Set_RTU_Loaded (Unit_Node);
942 end if;
943
944 -- Treat compilation unit pragmas that appear after the library unit
945
946 if Present (Pragmas_After (Aux_Decls_Node (N))) then
947 declare
948 Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N)));
949 begin
950 while Present (Prag_Node) loop
951 Analyze (Prag_Node);
952 Next (Prag_Node);
953 end loop;
954 end;
955 end if;
956
957 -- Analyze the contract of a [generic] subprogram that acts as a
958 -- compilation unit after all compilation pragmas have been analyzed.
959
960 if Nkind (Unit_Node) in
961 N_Generic_Subprogram_Declaration | N_Subprogram_Declaration
962 then
963 Analyze_Entry_Or_Subprogram_Contract (Defining_Entity (Unit_Node));
964 end if;
965
966 -- Generate distribution stubs if requested and no error
967
968 if N = Main_Cunit
969 and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
970 or else
971 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
972 and then Fatal_Error (Main_Unit) /= Error_Detected
973 then
974 if Is_RCI_Pkg_Spec_Or_Body (N) then
975
976 -- Regular RCI package
977
978 Add_Stub_Constructs (N);
979
980 elsif (Nkind (Unit_Node) = N_Package_Declaration
981 and then Is_Shared_Passive (Defining_Entity
982 (Specification (Unit_Node))))
983 or else (Nkind (Unit_Node) = N_Package_Body
984 and then
985 Is_Shared_Passive (Corresponding_Spec (Unit_Node)))
986 then
987 -- Shared passive package
988
989 Add_Stub_Constructs (N);
990
991 elsif Nkind (Unit_Node) = N_Package_Instantiation
992 and then
993 Is_Remote_Call_Interface
994 (Defining_Entity (Specification (Instance_Spec (Unit_Node))))
995 then
996 -- Instantiation of a RCI generic package
997
998 Add_Stub_Constructs (N);
999 end if;
1000 end if;
1001
1002 -- Remove unit from visibility, so that environment is clean for the
1003 -- next compilation, which is either the main unit or some other unit
1004 -- in the context.
1005
1006 if Nkind (Unit_Node) in N_Package_Declaration
1007 | N_Package_Renaming_Declaration
1008 | N_Subprogram_Declaration
1009 | N_Generic_Declaration
1010 or else (Nkind (Unit_Node) = N_Subprogram_Body
1011 and then Acts_As_Spec (Unit_Node))
1012 then
1013 Remove_Unit_From_Visibility (Defining_Entity (Unit_Node));
1014
1015 -- If the unit is an instantiation whose body will be elaborated for
1016 -- inlining purposes, use the proper entity of the instance. The entity
1017 -- may be missing if the instantiation was illegal.
1018
1019 elsif Nkind (Unit_Node) = N_Package_Instantiation
1020 and then not Error_Posted (Unit_Node)
1021 and then Present (Instance_Spec (Unit_Node))
1022 then
1023 Remove_Unit_From_Visibility
1024 (Defining_Entity (Instance_Spec (Unit_Node)));
1025
1026 elsif Nkind (Unit_Node) = N_Package_Body
1027 or else (Nkind (Unit_Node) = N_Subprogram_Body
1028 and then not Acts_As_Spec (Unit_Node))
1029 then
1030 -- Bodies that are not the main unit are compiled if they are generic
1031 -- or contain generic or inlined units. Their analysis brings in the
1032 -- context of the corresponding spec (unit declaration) which must be
1033 -- removed as well, to return the compilation environment to its
1034 -- proper state.
1035
1036 Remove_Context (Lib_Unit);
1037 Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False);
1038 end if;
1039
1040 -- Last step is to deinstall the context we just installed as well as
1041 -- the unit just compiled.
1042
1043 Remove_Context (N);
1044
1045 -- When generating code for a non-generic main unit, check that withed
1046 -- generic units have a body if they need it, even if the units have not
1047 -- been instantiated. Force the load of the bodies to produce the proper
1048 -- error if the body is absent. The same applies to GNATprove mode, with
1049 -- the added benefit of capturing global references within the generic.
1050 -- This in turn allows for proper inlining of subprogram bodies without
1051 -- a previous declaration.
1052
1053 if Get_Cunit_Unit_Number (N) = Main_Unit
1054 and then ((Operating_Mode = Generate_Code and then Expander_Active)
1055 or else
1056 (Operating_Mode = Check_Semantics and then GNATprove_Mode))
1057 then
1058 -- Check whether the source for the body of the unit must be included
1059 -- in a standalone library.
1060
1061 Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit));
1062
1063 -- Indicate that the main unit is now analyzed, to catch possible
1064 -- circularities between it and generic bodies. Remove main unit from
1065 -- visibility. This might seem superfluous, but the main unit must
1066 -- not be visible in the generic body expansions that follow.
1067
1068 Set_Analyzed (N, True);
1069 Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False);
1070
1071 declare
1072 Item : Node_Id;
1073 Nam : Entity_Id;
1074 Un : Unit_Number_Type;
1075
1076 Save_Style_Check : constant Boolean := Style_Check;
1077
1078 begin
1079 Item := First (Context_Items (N));
1080 while Present (Item) loop
1081
1082 -- Check for explicit with clause
1083
1084 if Nkind (Item) = N_With_Clause
1085 and then not Implicit_With (Item)
1086
1087 -- Ada 2005 (AI-50217): Ignore limited-withed units
1088
1089 and then not Limited_Present (Item)
1090 then
1091 Nam := Entity (Name (Item));
1092
1093 -- Compile the generic subprogram, unless it is intrinsic or
1094 -- imported so no body is required, or generic package body
1095 -- if the package spec requires a body.
1096
1097 if (Is_Generic_Subprogram (Nam)
1098 and then not Is_Intrinsic_Subprogram (Nam)
1099 and then not Is_Imported (Nam))
1100 or else (Ekind (Nam) = E_Generic_Package
1101 and then Unit_Requires_Body (Nam))
1102 then
1103 Style_Check := False;
1104
1105 if Present (Renamed_Object (Nam)) then
1106 Un :=
1107 Load_Unit
1108 (Load_Name =>
1109 Get_Body_Name
1110 (Get_Unit_Name
1111 (Unit_Declaration_Node
1112 (Renamed_Object (Nam)))),
1113 Required => False,
1114 Subunit => False,
1115 Error_Node => N,
1116 Renamings => True);
1117 else
1118 Un :=
1119 Load_Unit
1120 (Load_Name =>
1121 Get_Body_Name (Get_Unit_Name (Item)),
1122 Required => False,
1123 Subunit => False,
1124 Error_Node => N,
1125 Renamings => True);
1126 end if;
1127
1128 if Un = No_Unit then
1129 Error_Msg_NE
1130 ("body of generic unit& not found", Item, Nam);
1131 exit;
1132
1133 elsif not Analyzed (Cunit (Un))
1134 and then Un /= Main_Unit
1135 and then Fatal_Error (Un) /= Error_Detected
1136 then
1137 Style_Check := False;
1138 Semantics (Cunit (Un));
1139 end if;
1140 end if;
1141 end if;
1142
1143 Next (Item);
1144 end loop;
1145
1146 -- Restore style checks settings
1147
1148 Style_Check := Save_Style_Check;
1149 end;
1150
1151 -- In GNATprove mode, force the loading of an Interrupt_Priority when
1152 -- processing compilation units with potentially "main" subprograms.
1153 -- This is required for the ceiling priority protocol checks, which
1154 -- are triggered by these subprograms.
1155
1156 if GNATprove_Mode
1157 and then Nkind (Unit_Node) in N_Function_Instantiation
1158 | N_Procedure_Instantiation
1159 | N_Subprogram_Body
1160 then
1161 declare
1162 Spec : Node_Id;
1163
1164 begin
1165 case Nkind (Unit_Node) is
1166 when N_Subprogram_Body =>
1167 Spec := Specification (Unit_Node);
1168
1169 when N_Subprogram_Instantiation =>
1170 Spec :=
1171 Subprogram_Specification (Entity (Name (Unit_Node)));
1172
1173 when others =>
1174 raise Program_Error;
1175 end case;
1176
1177 pragma Assert (Nkind (Spec) in N_Subprogram_Specification);
1178
1179 -- Main subprogram must have no parameters, and if it is a
1180 -- function, it must return an integer.
1181
1182 if No (Parameter_Specifications (Spec))
1183 and then (Nkind (Spec) = N_Procedure_Specification
1184 or else
1185 Is_Integer_Type (Etype (Result_Definition (Spec))))
1186 then
1187 SPARK_Implicit_Load (RE_Interrupt_Priority);
1188 end if;
1189 end;
1190 end if;
1191 end if;
1192
1193 -- Deal with creating elaboration counter if needed. We create an
1194 -- elaboration counter only for units that come from source since
1195 -- units manufactured by the compiler never need elab checks.
1196
1197 if Comes_From_Source (N)
1198 and then Nkind (Unit_Node) in N_Package_Declaration
1199 | N_Generic_Package_Declaration
1200 | N_Subprogram_Declaration
1201 | N_Generic_Subprogram_Declaration
1202 then
1203 declare
1204 Loc : constant Source_Ptr := Sloc (N);
1205 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1206
1207 begin
1208 Spec_Id := Defining_Entity (Unit_Node);
1209 Generate_Definition (Spec_Id);
1210
1211 -- See if an elaboration entity is required for possible access
1212 -- before elaboration checking. Note that we must allow for this
1213 -- even if -gnatE is not set, since a client may be compiled in
1214 -- -gnatE mode and reference the entity.
1215
1216 -- These entities are also used by the binder to prevent multiple
1217 -- attempts to execute the elaboration code for the library case
1218 -- where the elaboration routine might otherwise be called more
1219 -- than once.
1220
1221 -- They are also needed to ensure explicit visibility from the
1222 -- binder generated code of all the units involved in a partition
1223 -- when control-flow preservation is requested.
1224
1225 if not Opt.Suppress_Control_Flow_Optimizations
1226 and then
1227 ( -- Pure units do not need checks
1228
1229 Is_Pure (Spec_Id)
1230
1231 -- Preelaborated units do not need checks
1232
1233 or else Is_Preelaborated (Spec_Id)
1234
1235 -- No checks needed if pragma Elaborate_Body present
1236
1237 or else Has_Pragma_Elaborate_Body (Spec_Id)
1238
1239 -- No checks needed if unit does not require a body
1240
1241 or else not Unit_Requires_Body (Spec_Id)
1242
1243 -- No checks needed for predefined files
1244
1245 or else Is_Predefined_Unit (Unum)
1246
1247 -- No checks required if no separate spec
1248
1249 or else Acts_As_Spec (N)
1250 )
1251 then
1252 -- This is a case where we only need the entity for checking to
1253 -- prevent multiple elaboration checks.
1254
1255 Set_Elaboration_Entity_Required (Spec_Id, False);
1256
1257 -- Otherwise the unit requires an elaboration entity because it
1258 -- carries a body.
1259
1260 else
1261 Set_Elaboration_Entity_Required (Spec_Id);
1262 end if;
1263
1264 Build_Elaboration_Entity (N, Spec_Id);
1265 end;
1266 end if;
1267
1268 -- Freeze the compilation unit entity. This for sure is needed because
1269 -- of some warnings that can be output (see Freeze_Subprogram), but may
1270 -- in general be required. If freezing actions result, place them in the
1271 -- compilation unit actions list, and analyze them.
1272
1273 declare
1274 L : constant List_Id :=
1275 Freeze_Entity (Cunit_Entity (Current_Sem_Unit), N);
1276 begin
1277 while Is_Non_Empty_List (L) loop
1278 Insert_Library_Level_Action (Remove_Head (L));
1279 end loop;
1280 end;
1281
1282 Set_Analyzed (N);
1283
1284 -- Call Check_Package_Body so that a body containing subprograms with
1285 -- Inline_Always can be made available for front end inlining.
1286
1287 if Nkind (Unit_Node) = N_Package_Declaration
1288 and then Get_Cunit_Unit_Number (N) /= Main_Unit
1289
1290 -- We don't need to do this if the Expander is not active, since there
1291 -- is no code to inline.
1292
1293 and then Expander_Active
1294 then
1295 declare
1296 Save_Style_Check : constant Boolean := Style_Check;
1297 Save_Warning : constant Warning_Mode_Type := Warning_Mode;
1298 Options : Style_Check_Options;
1299
1300 begin
1301 Save_Style_Check_Options (Options);
1302 Reset_Style_Check_Options;
1303 Opt.Warning_Mode := Suppress;
1304
1305 Check_Package_Body_For_Inlining (N, Defining_Entity (Unit_Node));
1306
1307 Reset_Style_Check_Options;
1308 Set_Style_Check_Options (Options);
1309 Style_Check := Save_Style_Check;
1310 Warning_Mode := Save_Warning;
1311 end;
1312 end if;
1313
1314 -- If we are generating obsolescent warnings, then here is where we
1315 -- generate them for the with'ed items. The reason for this special
1316 -- processing is that the normal mechanism of generating the warnings
1317 -- for referenced entities does not work for context clause references.
1318 -- That's because when we first analyze the context, it is too early to
1319 -- know if the with'ing unit is itself obsolescent (which suppresses
1320 -- the warnings).
1321
1322 if not GNAT_Mode
1323 and then Warn_On_Obsolescent_Feature
1324 and then Nkind (Unit_Node) not in N_Generic_Instantiation
1325 then
1326 -- Push current compilation unit as scope, so that the test for
1327 -- being within an obsolescent unit will work correctly. The check
1328 -- is not performed within an instantiation, because the warning
1329 -- will have been emitted in the corresponding generic unit.
1330
1331 Push_Scope (Defining_Entity (Unit_Node));
1332
1333 -- Loop through context items to deal with with clauses
1334
1335 declare
1336 Item : Node_Id;
1337 Nam : Node_Id;
1338 Ent : Entity_Id;
1339
1340 begin
1341 Item := First (Context_Items (N));
1342 while Present (Item) loop
1343 if Nkind (Item) = N_With_Clause
1344
1345 -- Suppress this check in limited-withed units. Further work
1346 -- needed here if we decide to incorporate this check on
1347 -- limited-withed units.
1348
1349 and then not Limited_Present (Item)
1350 then
1351 Nam := Name (Item);
1352 Ent := Entity (Nam);
1353
1354 if Is_Obsolescent (Ent) then
1355 Output_Obsolescent_Entity_Warnings (Nam, Ent);
1356 end if;
1357 end if;
1358
1359 Next (Item);
1360 end loop;
1361 end;
1362
1363 -- Remove temporary install of current unit as scope
1364
1365 Pop_Scope;
1366 end if;
1367
1368 -- If No_Elaboration_Code_All was encountered, this is where we do the
1369 -- transitive test of with'ed units to make sure they have the aspect.
1370 -- This is delayed till the end of analyzing the compilation unit to
1371 -- ensure that the pragma/aspect, if present, has been analyzed.
1372
1373 Check_No_Elab_Code_All (N);
1374 end Analyze_Compilation_Unit;
1375
1376 ---------------------
1377 -- Analyze_Context --
1378 ---------------------
1379
1380 procedure Analyze_Context (N : Node_Id) is
1381 Ukind : constant Node_Kind := Nkind (Unit (N));
1382 Item : Node_Id;
1383
1384 begin
1385 -- First process all configuration pragmas at the start of the context
1386 -- items. Strictly these are not part of the context clause, but that
1387 -- is where the parser puts them. In any case for sure we must analyze
1388 -- these before analyzing the actual context items, since they can have
1389 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1390 -- be with'ed as a result of changing categorizations in Ada 2005).
1391
1392 Item := First (Context_Items (N));
1393 while Present (Item)
1394 and then Nkind (Item) = N_Pragma
1395 and then Pragma_Name (Item) in Configuration_Pragma_Names
1396 loop
1397 Analyze (Item);
1398 Next (Item);
1399 end loop;
1400
1401 -- This is the point at which we capture the configuration settings
1402 -- for the unit. At the moment only the Optimize_Alignment setting
1403 -- needs to be captured. Probably more later ???
1404
1405 if Optimize_Alignment_Local then
1406 Set_OA_Setting (Current_Sem_Unit, 'L');
1407 else
1408 Set_OA_Setting (Current_Sem_Unit, Optimize_Alignment);
1409 end if;
1410
1411 -- Loop through actual context items. This is done in two passes:
1412
1413 -- a) The first pass analyzes nonlimited with clauses and also any
1414 -- configuration pragmas (we need to get the latter analyzed right
1415 -- away, since they can affect processing of subsequent items).
1416
1417 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1418
1419 while Present (Item) loop
1420
1421 -- For with clause, analyze the with clause, and then update the
1422 -- version, since we are dependent on a unit that we with.
1423
1424 if Nkind (Item) = N_With_Clause
1425 and then not Limited_Present (Item)
1426 then
1427 -- Skip analyzing with clause if no unit, nothing to do (this
1428 -- happens for a with that references a non-existent unit).
1429
1430 if Present (Library_Unit (Item)) then
1431
1432 -- Skip analyzing with clause if this is a with_clause for
1433 -- the main unit, which happens if a subunit has a useless
1434 -- with_clause on its parent.
1435
1436 if Library_Unit (Item) /= Cunit (Current_Sem_Unit) then
1437 Analyze (Item);
1438
1439 -- Here for the case of a useless with for the main unit
1440
1441 else
1442 Set_Entity (Name (Item), Cunit_Entity (Current_Sem_Unit));
1443 end if;
1444 end if;
1445
1446 -- Do version update (skipped for implicit with)
1447
1448 if not Implicit_With (Item) then
1449 Version_Update (N, Library_Unit (Item));
1450 end if;
1451
1452 -- Skip pragmas. Configuration pragmas at the start were handled in
1453 -- the loop above, and remaining pragmas are not processed until we
1454 -- actually install the context (see Install_Context). We delay the
1455 -- analysis of these pragmas to make sure that we have installed all
1456 -- the implicit with's on parent units.
1457
1458 -- Skip use clauses at this stage, since we don't want to do any
1459 -- installing of potentially use-visible entities until we
1460 -- actually install the complete context (in Install_Context).
1461 -- Otherwise things can get installed in the wrong context.
1462
1463 else
1464 null;
1465 end if;
1466
1467 Next (Item);
1468 end loop;
1469
1470 -- Second pass: examine all limited_with clauses. All other context
1471 -- items are ignored in this pass.
1472
1473 Item := First (Context_Items (N));
1474 while Present (Item) loop
1475 if Nkind (Item) = N_With_Clause
1476 and then Limited_Present (Item)
1477 then
1478 -- No need to check errors on implicitly generated limited-with
1479 -- clauses.
1480
1481 if not Implicit_With (Item) then
1482
1483 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1484 -- properly rejected, including renaming declarations.
1485
1486 if Ukind not in N_Package_Declaration
1487 | N_Subprogram_Declaration
1488 | N_Generic_Declaration
1489 | N_Generic_Instantiation
1490 then
1491 Error_Msg_N ("limited with_clause not allowed here", Item);
1492
1493 -- Check wrong use of a limited with clause applied to the
1494 -- compilation unit containing the limited-with clause.
1495
1496 -- limited with P.Q;
1497 -- package P.Q is ...
1498
1499 elsif Unit (Library_Unit (Item)) = Unit (N) then
1500 Error_Msg_N ("wrong use of limited-with clause", Item);
1501
1502 -- Check wrong use of limited-with clause applied to some
1503 -- immediate ancestor.
1504
1505 elsif Is_Child_Spec (Unit (N)) then
1506 declare
1507 Lib_U : constant Entity_Id := Unit (Library_Unit (Item));
1508 P : Node_Id;
1509
1510 begin
1511 P := Parent_Spec (Unit (N));
1512 loop
1513 if Unit (P) = Lib_U then
1514 Error_Msg_N
1515 ("limited with_clause cannot name ancestor",
1516 Item);
1517 exit;
1518 end if;
1519
1520 exit when not Is_Child_Spec (Unit (P));
1521 P := Parent_Spec (Unit (P));
1522 end loop;
1523 end;
1524 end if;
1525
1526 -- Check if the limited-withed unit is already visible through
1527 -- some context clause of the current compilation unit or some
1528 -- ancestor of the current compilation unit.
1529
1530 declare
1531 Lim_Unit_Name : constant Node_Id := Name (Item);
1532 Comp_Unit : Node_Id;
1533 It : Node_Id;
1534 Unit_Name : Node_Id;
1535
1536 begin
1537 Comp_Unit := N;
1538 loop
1539 It := First (Context_Items (Comp_Unit));
1540 while Present (It) loop
1541 if Item /= It
1542 and then Nkind (It) = N_With_Clause
1543 and then not Limited_Present (It)
1544 and then Nkind (Unit (Library_Unit (It))) in
1545 N_Package_Declaration |
1546 N_Package_Renaming_Declaration
1547 then
1548 if Nkind (Unit (Library_Unit (It))) =
1549 N_Package_Declaration
1550 then
1551 Unit_Name := Name (It);
1552 else
1553 Unit_Name := Name (Unit (Library_Unit (It)));
1554 end if;
1555
1556 -- Check if the named package (or some ancestor)
1557 -- leaves visible the full-view of the unit given
1558 -- in the limited-with clause.
1559
1560 loop
1561 if Designate_Same_Unit (Lim_Unit_Name,
1562 Unit_Name)
1563 then
1564 Error_Msg_Sloc := Sloc (It);
1565 Error_Msg_N
1566 ("simultaneous visibility of limited and "
1567 & "unlimited views not allowed", Item);
1568 Error_Msg_N
1569 ("\unlimited view visible through context "
1570 & "clause #", Item);
1571 exit;
1572
1573 elsif Nkind (Unit_Name) = N_Identifier then
1574 exit;
1575 end if;
1576
1577 Unit_Name := Prefix (Unit_Name);
1578 end loop;
1579 end if;
1580
1581 Next (It);
1582 end loop;
1583
1584 exit when not Is_Child_Spec (Unit (Comp_Unit));
1585
1586 Comp_Unit := Parent_Spec (Unit (Comp_Unit));
1587 end loop;
1588 end;
1589 end if;
1590
1591 -- Skip analyzing with clause if no unit, see above
1592
1593 if Present (Library_Unit (Item)) then
1594 Analyze (Item);
1595 end if;
1596
1597 -- A limited_with does not impose an elaboration order, but there
1598 -- is a semantic dependency for recompilation purposes.
1599
1600 if not Implicit_With (Item) then
1601 Version_Update (N, Library_Unit (Item));
1602 end if;
1603
1604 -- Pragmas and use clauses and with clauses other than limited with's
1605 -- are ignored in this pass through the context items.
1606
1607 else
1608 null;
1609 end if;
1610
1611 Next (Item);
1612 end loop;
1613 end Analyze_Context;
1614
1615 -------------------------------
1616 -- Analyze_Package_Body_Stub --
1617 -------------------------------
1618
1619 procedure Analyze_Package_Body_Stub (N : Node_Id) is
1620 Id : constant Entity_Id := Defining_Entity (N);
1621 Nam : Entity_Id;
1622 Opts : Config_Switches_Type;
1623
1624 begin
1625 -- The package declaration must be in the current declarative part
1626
1627 Check_Stub_Level (N);
1628 Nam := Current_Entity_In_Scope (Id);
1629
1630 if No (Nam) or else not Is_Package_Or_Generic_Package (Nam) then
1631 Error_Msg_N ("missing specification for package stub", N);
1632
1633 elsif Has_Completion (Nam)
1634 and then Present (Corresponding_Body (Unit_Declaration_Node (Nam)))
1635 then
1636 Error_Msg_N ("duplicate or redundant stub for package", N);
1637
1638 else
1639 -- Retain and restore the configuration options of the enclosing
1640 -- context as the proper body may introduce a set of its own.
1641
1642 Opts := Save_Config_Switches;
1643
1644 -- Indicate that the body of the package exists. If we are doing
1645 -- only semantic analysis, the stub stands for the body. If we are
1646 -- generating code, the existence of the body will be confirmed
1647 -- when we load the proper body.
1648
1649 Set_Scope (Id, Current_Scope);
1650 Mutate_Ekind (Id, E_Package_Body);
1651 Set_Etype (Id, Standard_Void_Type);
1652
1653 if Has_Aspects (N) then
1654 Analyze_Aspect_Specifications (N, Id);
1655 end if;
1656
1657 Set_Has_Completion (Nam);
1658 Set_Corresponding_Spec_Of_Stub (N, Nam);
1659 Generate_Reference (Nam, Id, 'b');
1660 Analyze_Proper_Body (N, Nam);
1661
1662 Restore_Config_Switches (Opts);
1663 end if;
1664 end Analyze_Package_Body_Stub;
1665
1666 -------------------------
1667 -- Analyze_Proper_Body --
1668 -------------------------
1669
1670 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is
1671 Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
1672
1673 procedure Optional_Subunit;
1674 -- This procedure is called when the main unit is a stub, or when we
1675 -- are not generating code. In such a case, we analyze the subunit if
1676 -- present, which is user-friendly, but we don't complain if the subunit
1677 -- is missing. In GNATprove_Mode, we issue an error to avoid formal
1678 -- verification of a partial unit.
1679
1680 ----------------------
1681 -- Optional_Subunit --
1682 ----------------------
1683
1684 procedure Optional_Subunit is
1685 Comp_Unit : Node_Id;
1686 Unum : Unit_Number_Type;
1687
1688 begin
1689 -- Try to load subunit, but ignore any errors that occur during the
1690 -- loading of the subunit, by using the special feature in Errout to
1691 -- ignore all errors. Note that Fatal_Error will still be set, so we
1692 -- will be able to check for this case below.
1693
1694 if not GNATprove_Mode then
1695 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
1696 end if;
1697
1698 Unum :=
1699 Load_Unit
1700 (Load_Name => Subunit_Name,
1701 Required => GNATprove_Mode,
1702 Subunit => True,
1703 Error_Node => N);
1704
1705 if not GNATprove_Mode then
1706 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
1707 end if;
1708
1709 -- All done if we successfully loaded the subunit
1710
1711 if Unum /= No_Unit
1712 and then (Fatal_Error (Unum) /= Error_Detected
1713 or else Try_Semantics)
1714 then
1715 Comp_Unit := Cunit (Unum);
1716
1717 -- If the file was empty or seriously mangled, the unit itself may
1718 -- be missing.
1719
1720 if No (Unit (Comp_Unit)) then
1721 Error_Msg_N
1722 ("subunit does not contain expected proper body", N);
1723
1724 elsif Nkind (Unit (Comp_Unit)) /= N_Subunit then
1725 Error_Msg_N
1726 ("expected SEPARATE subunit, found child unit",
1727 Cunit_Entity (Unum));
1728 else
1729 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1730 Analyze_Subunit (Comp_Unit);
1731 Set_Library_Unit (N, Comp_Unit);
1732 Set_Corresponding_Body (N, Defining_Entity (Unit (Comp_Unit)));
1733 end if;
1734
1735 elsif Unum = No_Unit
1736 and then Present (Nam)
1737 then
1738 if Is_Protected_Type (Nam) then
1739 Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N));
1740 else
1741 Set_Corresponding_Body (
1742 Unit_Declaration_Node (Nam), Defining_Identifier (N));
1743 end if;
1744 end if;
1745 end Optional_Subunit;
1746
1747 -- Local variables
1748
1749 Comp_Unit : Node_Id;
1750 Unum : Unit_Number_Type;
1751
1752 -- Start of processing for Analyze_Proper_Body
1753
1754 begin
1755 -- If the subunit is already loaded, it means that the main unit is a
1756 -- subunit, and that the current unit is one of its parents which was
1757 -- being analyzed to provide the needed context for the analysis of the
1758 -- subunit. In this case we analyze the subunit and continue with the
1759 -- parent, without looking at subsequent subunits.
1760
1761 if Is_Loaded (Subunit_Name) then
1762
1763 -- If the proper body is already linked to the stub node, the stub is
1764 -- in a generic unit and just needs analyzing.
1765
1766 if Present (Library_Unit (N)) then
1767 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1768
1769 -- If the subunit has severe errors, the spec of the enclosing
1770 -- body may not be available, in which case do not try analysis.
1771
1772 if Serious_Errors_Detected > 0
1773 and then No (Library_Unit (Library_Unit (N)))
1774 then
1775 return;
1776 end if;
1777
1778 -- Collect SCO information for loaded subunit if we are in the
1779 -- extended main unit.
1780
1781 if Generate_SCO
1782 and then In_Extended_Main_Source_Unit
1783 (Cunit_Entity (Current_Sem_Unit))
1784 then
1785 SCO_Record_Raw (Get_Cunit_Unit_Number (Library_Unit (N)));
1786 end if;
1787
1788 Analyze_Subunit (Library_Unit (N));
1789
1790 -- Otherwise we must load the subunit and link to it
1791
1792 else
1793 -- Load the subunit, this must work, since we originally loaded
1794 -- the subunit earlier on. So this will not really load it, just
1795 -- give access to it.
1796
1797 Unum :=
1798 Load_Unit
1799 (Load_Name => Subunit_Name,
1800 Required => True,
1801 Subunit => False,
1802 Error_Node => N);
1803
1804 -- And analyze the subunit in the parent context (note that we
1805 -- do not call Semantics, since that would remove the parent
1806 -- context). Because of this, we have to manually reset the
1807 -- compiler state to Analyzing since it got destroyed by Load.
1808
1809 if Unum /= No_Unit then
1810 Compiler_State := Analyzing;
1811
1812 -- Check that the proper body is a subunit and not a child
1813 -- unit. If the unit was previously loaded, the error will
1814 -- have been emitted when copying the generic node, so we
1815 -- just return to avoid cascaded errors.
1816
1817 if Nkind (Unit (Cunit (Unum))) /= N_Subunit then
1818 return;
1819 end if;
1820
1821 Set_Corresponding_Stub (Unit (Cunit (Unum)), N);
1822 Analyze_Subunit (Cunit (Unum));
1823 Set_Library_Unit (N, Cunit (Unum));
1824 end if;
1825 end if;
1826
1827 -- If the main unit is a subunit, then we are just performing semantic
1828 -- analysis on that subunit, and any other subunits of any parent unit
1829 -- should be ignored. If the main unit is itself a subunit, another
1830 -- subunit is irrelevant unless it is a subunit of the current one, that
1831 -- is to say appears in the current source tree.
1832
1833 elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
1834 and then Subunit_Name /= Unit_Name (Main_Unit)
1835 then
1836 -- But before we return, set the flag for unloaded subunits. This
1837 -- will suppress junk warnings of variables in the same declarative
1838 -- part (or a higher level one) that are in danger of looking unused
1839 -- when in fact there might be a declaration in the subunit that we
1840 -- do not intend to load.
1841
1842 Unloaded_Subunits := True;
1843 return;
1844
1845 -- If the subunit is not already loaded, and we are generating code,
1846 -- then this is the case where compilation started from the parent, and
1847 -- we are generating code for an entire subunit tree. In that case we
1848 -- definitely need to load the subunit.
1849
1850 -- In order to continue the analysis with the rest of the parent,
1851 -- and other subunits, we load the unit without requiring its
1852 -- presence, and emit a warning if not found, rather than terminating
1853 -- the compilation abruptly, as for other missing file problems.
1854
1855 elsif Original_Operating_Mode = Generate_Code then
1856
1857 -- If the proper body is already linked to the stub node, the stub is
1858 -- in a generic unit and just needs analyzing.
1859
1860 -- We update the version. Although we are not strictly technically
1861 -- semantically dependent on the subunit, given our approach of macro
1862 -- substitution of subunits, it makes sense to include it in the
1863 -- version identification.
1864
1865 if Present (Library_Unit (N)) then
1866 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1867 Analyze_Subunit (Library_Unit (N));
1868 Version_Update (Cunit (Main_Unit), Library_Unit (N));
1869
1870 -- Otherwise we must load the subunit and link to it
1871
1872 else
1873 -- Make sure that, if the subunit is preprocessed and -gnateG is
1874 -- specified, the preprocessed file will be written.
1875
1876 Lib.Analysing_Subunit_Of_Main := True;
1877 Unum :=
1878 Load_Unit
1879 (Load_Name => Subunit_Name,
1880 Required => False,
1881 Subunit => True,
1882 Error_Node => N);
1883 Lib.Analysing_Subunit_Of_Main := False;
1884
1885 -- Give message if we did not get the unit Emit warning even if
1886 -- missing subunit is not within main unit, to simplify debugging.
1887
1888 pragma Assert (Original_Operating_Mode = Generate_Code);
1889 if Unum = No_Unit then
1890 Error_Msg_Unit_1 := Subunit_Name;
1891 Error_Msg_File_1 :=
1892 Get_File_Name (Subunit_Name, Subunit => True);
1893 Error_Msg_N
1894 ("subunit$$ in file{ not found??!!", N);
1895 Subunits_Missing := True;
1896 end if;
1897
1898 -- Load_Unit may reset Compiler_State, since it may have been
1899 -- necessary to parse an additional units, so we make sure that
1900 -- we reset it to the Analyzing state.
1901
1902 Compiler_State := Analyzing;
1903
1904 if Unum /= No_Unit then
1905 if Debug_Flag_L then
1906 Write_Str ("*** Loaded subunit from stub. Analyze");
1907 Write_Eol;
1908 end if;
1909
1910 Comp_Unit := Cunit (Unum);
1911
1912 -- Check for child unit instead of subunit
1913
1914 if Nkind (Unit (Comp_Unit)) /= N_Subunit then
1915 Error_Msg_N
1916 ("expected SEPARATE subunit, found child unit",
1917 Cunit_Entity (Unum));
1918
1919 -- OK, we have a subunit
1920
1921 else
1922 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1923 Set_Library_Unit (N, Comp_Unit);
1924
1925 -- We update the version. Although we are not technically
1926 -- semantically dependent on the subunit, given our approach
1927 -- of macro substitution of subunits, it makes sense to
1928 -- include it in the version identification.
1929
1930 Version_Update (Cunit (Main_Unit), Comp_Unit);
1931
1932 -- Collect SCO information for loaded subunit if we are in
1933 -- the extended main unit.
1934
1935 if Generate_SCO
1936 and then In_Extended_Main_Source_Unit
1937 (Cunit_Entity (Current_Sem_Unit))
1938 then
1939 SCO_Record_Raw (Unum);
1940 end if;
1941
1942 -- Analyze the unit if semantics active
1943
1944 if Fatal_Error (Unum) /= Error_Detected
1945 or else Try_Semantics
1946 then
1947 Analyze_Subunit (Comp_Unit);
1948 end if;
1949 end if;
1950 end if;
1951 end if;
1952
1953 -- The remaining case is when the subunit is not already loaded and we
1954 -- are not generating code. In this case we are just performing semantic
1955 -- analysis on the parent, and we are not interested in the subunit. For
1956 -- subprograms, analyze the stub as a body. For other entities the stub
1957 -- has already been marked as completed.
1958
1959 else
1960 Optional_Subunit;
1961 end if;
1962 end Analyze_Proper_Body;
1963
1964 ----------------------------------
1965 -- Analyze_Protected_Body_Stub --
1966 ----------------------------------
1967
1968 procedure Analyze_Protected_Body_Stub (N : Node_Id) is
1969 Id : constant Entity_Id := Defining_Entity (N);
1970 Nam : Entity_Id := Current_Entity_In_Scope (Id);
1971 Opts : Config_Switches_Type;
1972
1973 begin
1974 Check_Stub_Level (N);
1975
1976 -- First occurrence of name may have been as an incomplete type
1977
1978 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1979 Nam := Full_View (Nam);
1980 end if;
1981
1982 if No (Nam) or else not Is_Protected_Type (Etype (Nam)) then
1983 Error_Msg_N ("missing specification for Protected body", N);
1984
1985 else
1986 -- Retain and restore the configuration options of the enclosing
1987 -- context as the proper body may introduce a set of its own.
1988
1989 Opts := Save_Config_Switches;
1990
1991 Set_Scope (Id, Current_Scope);
1992 Mutate_Ekind (Id, E_Protected_Body);
1993 Set_Etype (Id, Standard_Void_Type);
1994
1995 if Has_Aspects (N) then
1996 Analyze_Aspect_Specifications (N, Id);
1997 end if;
1998
1999 Set_Has_Completion (Etype (Nam));
2000 Set_Corresponding_Spec_Of_Stub (N, Nam);
2001 Generate_Reference (Nam, Id, 'b');
2002 Analyze_Proper_Body (N, Etype (Nam));
2003
2004 Restore_Config_Switches (Opts);
2005 end if;
2006 end Analyze_Protected_Body_Stub;
2007
2008 ----------------------------------
2009 -- Analyze_Subprogram_Body_Stub --
2010 ----------------------------------
2011
2012 -- A subprogram body stub can appear with or without a previous spec. If
2013 -- there is one, then the analysis of the body will find it and verify
2014 -- conformance. The formals appearing in the specification of the stub play
2015 -- no role, except for requiring an additional conformance check. If there
2016 -- is no previous subprogram declaration, the stub acts as a spec, and
2017 -- provides the defining entity for the subprogram.
2018
2019 procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
2020 Decl : Node_Id;
2021 Opts : Config_Switches_Type;
2022
2023 begin
2024 Check_Stub_Level (N);
2025
2026 -- Verify that the identifier for the stub is unique within this
2027 -- declarative part.
2028
2029 if Nkind (Parent (N)) in
2030 N_Block_Statement | N_Package_Body | N_Subprogram_Body
2031 then
2032 Decl := First (Declarations (Parent (N)));
2033 while Present (Decl) and then Decl /= N loop
2034 if Nkind (Decl) = N_Subprogram_Body_Stub
2035 and then (Chars (Defining_Unit_Name (Specification (Decl))) =
2036 Chars (Defining_Unit_Name (Specification (N))))
2037 then
2038 Error_Msg_N ("identifier for stub is not unique", N);
2039 end if;
2040
2041 Next (Decl);
2042 end loop;
2043 end if;
2044
2045 -- Retain and restore the configuration options of the enclosing context
2046 -- as the proper body may introduce a set of its own.
2047
2048 Opts := Save_Config_Switches;
2049
2050 -- Treat stub as a body, which checks conformance if there is a previous
2051 -- declaration, or else introduces entity and its signature.
2052
2053 Analyze_Subprogram_Body (N);
2054 Analyze_Proper_Body (N, Empty);
2055
2056 Restore_Config_Switches (Opts);
2057 end Analyze_Subprogram_Body_Stub;
2058
2059 ---------------------
2060 -- Analyze_Subunit --
2061 ---------------------
2062
2063 -- A subunit is compiled either by itself (for semantic checking) or as
2064 -- part of compiling the parent (for code generation). In either case, by
2065 -- the time we actually process the subunit, the parent has already been
2066 -- installed and analyzed. The node N is a compilation unit, whose context
2067 -- needs to be treated here, because we come directly here from the parent
2068 -- without calling Analyze_Compilation_Unit.
2069
2070 -- The compilation context includes the explicit context of the subunit,
2071 -- and the context of the parent, together with the parent itself. In order
2072 -- to compile the current context, we remove the one inherited from the
2073 -- parent, in order to have a clean visibility table. We restore the parent
2074 -- context before analyzing the proper body itself. On exit, we remove only
2075 -- the explicit context of the subunit.
2076
2077 -- WARNING: This routine manages SPARK regions. Return statements must be
2078 -- replaced by gotos which jump to the end of the routine and restore the
2079 -- SPARK mode.
2080
2081 procedure Analyze_Subunit (N : Node_Id) is
2082 Lib_Unit : constant Node_Id := Library_Unit (N);
2083 Par_Unit : constant Entity_Id := Current_Scope;
2084
2085 Lib_Spec : Node_Id := Library_Unit (Lib_Unit);
2086 Num_Scopes : Nat := 0;
2087 Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id;
2088 Enclosing_Child : Entity_Id := Empty;
2089 Svg : constant Suppress_Record := Scope_Suppress;
2090
2091 Save_Cunit_Restrictions : constant Save_Cunit_Boolean_Restrictions :=
2092 Cunit_Boolean_Restrictions_Save;
2093 -- Save non-partition wide restrictions before processing the subunit.
2094 -- All subunits are analyzed with config restrictions reset and we need
2095 -- to restore these saved values at the end.
2096
2097 procedure Analyze_Subunit_Context;
2098 -- Capture names in use clauses of the subunit. This must be done before
2099 -- re-installing parent declarations, because items in the context must
2100 -- not be hidden by declarations local to the parent.
2101
2102 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id);
2103 -- Recursive procedure to restore scope of all ancestors of subunit,
2104 -- from outermost in. If parent is not a subunit, the call to install
2105 -- context installs context of spec and (if parent is a child unit) the
2106 -- context of its parents as well. It is confusing that parents should
2107 -- be treated differently in both cases, but the semantics are just not
2108 -- identical.
2109
2110 procedure Re_Install_Use_Clauses;
2111 -- As part of the removal of the parent scope, the use clauses are
2112 -- removed, to be reinstalled when the context of the subunit has been
2113 -- analyzed. Use clauses may also have been affected by the analysis of
2114 -- the context of the subunit, so they have to be applied again, to
2115 -- insure that the compilation environment of the rest of the parent
2116 -- unit is identical.
2117
2118 procedure Remove_Scope;
2119 -- Remove current scope from scope stack, and preserve the list of use
2120 -- clauses in it, to be reinstalled after context is analyzed.
2121
2122 -----------------------------
2123 -- Analyze_Subunit_Context --
2124 -----------------------------
2125
2126 procedure Analyze_Subunit_Context is
2127 Item : Node_Id;
2128 Unit_Name : Entity_Id;
2129
2130 begin
2131 Analyze_Context (N);
2132 Check_No_Elab_Code_All (N);
2133
2134 -- Make withed units immediately visible. If child unit, make the
2135 -- ultimate parent immediately visible.
2136
2137 Item := First (Context_Items (N));
2138 while Present (Item) loop
2139 if Nkind (Item) = N_With_Clause then
2140
2141 -- Protect frontend against previous errors in context clauses
2142
2143 if Nkind (Name (Item)) /= N_Selected_Component then
2144 if Error_Posted (Item) then
2145 null;
2146
2147 else
2148 -- If a subunits has serious syntax errors, the context
2149 -- may not have been loaded. Add a harmless unit name to
2150 -- attempt processing.
2151
2152 if Serious_Errors_Detected > 0
2153 and then No (Entity (Name (Item)))
2154 then
2155 Set_Entity (Name (Item), Standard_Standard);
2156 end if;
2157
2158 Unit_Name := Entity (Name (Item));
2159 loop
2160 Set_Is_Visible_Lib_Unit (Unit_Name);
2161 exit when Scope (Unit_Name) = Standard_Standard;
2162 Unit_Name := Scope (Unit_Name);
2163
2164 if No (Unit_Name) then
2165 Check_Error_Detected;
2166 return;
2167 end if;
2168 end loop;
2169
2170 if not Is_Immediately_Visible (Unit_Name) then
2171 Set_Is_Immediately_Visible (Unit_Name);
2172 Set_Context_Installed (Item);
2173 end if;
2174 end if;
2175 end if;
2176
2177 elsif Nkind (Item) = N_Use_Package_Clause then
2178 Analyze (Name (Item));
2179
2180 elsif Nkind (Item) = N_Use_Type_Clause then
2181 Analyze (Subtype_Mark (Item));
2182 end if;
2183
2184 Next (Item);
2185 end loop;
2186
2187 -- Reset visibility of withed units. They will be made visible again
2188 -- when we install the subunit context.
2189
2190 Item := First (Context_Items (N));
2191 while Present (Item) loop
2192 if Nkind (Item) = N_With_Clause
2193
2194 -- Protect frontend against previous errors in context clauses
2195
2196 and then Nkind (Name (Item)) /= N_Selected_Component
2197 and then not Error_Posted (Item)
2198 then
2199 Unit_Name := Entity (Name (Item));
2200 loop
2201 Set_Is_Visible_Lib_Unit (Unit_Name, False);
2202 exit when Scope (Unit_Name) = Standard_Standard;
2203 Unit_Name := Scope (Unit_Name);
2204 end loop;
2205
2206 if Context_Installed (Item) then
2207 Set_Is_Immediately_Visible (Unit_Name, False);
2208 Set_Context_Installed (Item, False);
2209 end if;
2210 end if;
2211
2212 Next (Item);
2213 end loop;
2214 end Analyze_Subunit_Context;
2215
2216 ------------------------
2217 -- Re_Install_Parents --
2218 ------------------------
2219
2220 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is
2221 E : Entity_Id;
2222
2223 begin
2224 if Nkind (Unit (L)) = N_Subunit then
2225 Re_Install_Parents (Library_Unit (L), Scope (Scop));
2226 end if;
2227
2228 Install_Context (L, False);
2229
2230 -- If the subunit occurs within a child unit, we must restore the
2231 -- immediate visibility of any siblings that may occur in context.
2232 -- In addition, we must reset the previous visibility of the
2233 -- parent unit which is now on the scope stack. This is because
2234 -- the Previous_Visibility was previously set when removing the
2235 -- context. This is necessary to prevent the parent entity from
2236 -- remaining visible after the subunit is compiled. This only
2237 -- has an effect if a homonym exists in a body to be processed
2238 -- later if inlining is enabled.
2239
2240 if Present (Enclosing_Child) then
2241 Install_Siblings (Enclosing_Child, L);
2242 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
2243 False;
2244 end if;
2245
2246 Push_Scope (Scop);
2247
2248 if Scop /= Par_Unit then
2249 Set_Is_Immediately_Visible (Scop);
2250 end if;
2251
2252 -- Make entities in scope visible again. For child units, restore
2253 -- visibility only if they are actually in context.
2254
2255 E := First_Entity (Current_Scope);
2256 while Present (E) loop
2257 if not Is_Child_Unit (E) or else Is_Visible_Lib_Unit (E) then
2258 Set_Is_Immediately_Visible (E);
2259 end if;
2260
2261 Next_Entity (E);
2262 end loop;
2263
2264 -- A subunit appears within a body, and for a nested subunits all the
2265 -- parents are bodies. Restore full visibility of their private
2266 -- entities.
2267
2268 if Is_Package_Or_Generic_Package (Scop) then
2269 Set_In_Package_Body (Scop);
2270 Install_Private_Declarations (Scop);
2271 end if;
2272 end Re_Install_Parents;
2273
2274 ----------------------------
2275 -- Re_Install_Use_Clauses --
2276 ----------------------------
2277
2278 procedure Re_Install_Use_Clauses is
2279 U : Node_Id;
2280 begin
2281 for J in reverse 1 .. Num_Scopes loop
2282 U := Use_Clauses (J);
2283 Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U;
2284 Install_Use_Clauses (U);
2285 end loop;
2286 end Re_Install_Use_Clauses;
2287
2288 ------------------
2289 -- Remove_Scope --
2290 ------------------
2291
2292 procedure Remove_Scope is
2293 E : Entity_Id;
2294
2295 begin
2296 Num_Scopes := Num_Scopes + 1;
2297 Use_Clauses (Num_Scopes) :=
2298 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause;
2299
2300 E := First_Entity (Current_Scope);
2301 while Present (E) loop
2302 Set_Is_Immediately_Visible (E, False);
2303 Next_Entity (E);
2304 end loop;
2305
2306 if Is_Child_Unit (Current_Scope) then
2307 Enclosing_Child := Current_Scope;
2308 end if;
2309
2310 Pop_Scope;
2311 end Remove_Scope;
2312
2313 Saved_SM : SPARK_Mode_Type := SPARK_Mode;
2314 Saved_SMP : Node_Id := SPARK_Mode_Pragma;
2315 -- Save the SPARK mode-related data to restore on exit. Removing
2316 -- enclosing scopes and contexts to provide a clean environment for the
2317 -- context of the subunit will eliminate any previously set SPARK_Mode.
2318
2319 -- Start of processing for Analyze_Subunit
2320
2321 begin
2322 -- For subunit in main extended unit, we reset the configuration values
2323 -- for the non-partition-wide restrictions. For other units reset them.
2324
2325 if In_Extended_Main_Source_Unit (N) then
2326 Restore_Config_Cunit_Boolean_Restrictions;
2327 else
2328 Reset_Cunit_Boolean_Restrictions;
2329 end if;
2330
2331 if Style_Check then
2332 declare
2333 Nam : Node_Id := Name (Unit (N));
2334
2335 begin
2336 if Nkind (Nam) = N_Selected_Component then
2337 Nam := Selector_Name (Nam);
2338 end if;
2339
2340 Check_Identifier (Nam, Par_Unit);
2341 end;
2342 end if;
2343
2344 if not Is_Empty_List (Context_Items (N)) then
2345
2346 -- Save current use clauses
2347
2348 Remove_Scope;
2349 Remove_Context (Lib_Unit);
2350
2351 -- Now remove parents and their context, including enclosing subunits
2352 -- and the outer parent body which is not a subunit.
2353
2354 if Present (Lib_Spec) then
2355 Remove_Context (Lib_Spec);
2356
2357 while Nkind (Unit (Lib_Spec)) = N_Subunit loop
2358 Lib_Spec := Library_Unit (Lib_Spec);
2359 Remove_Scope;
2360 Remove_Context (Lib_Spec);
2361 end loop;
2362
2363 if Nkind (Unit (Lib_Unit)) = N_Subunit then
2364 Remove_Scope;
2365 end if;
2366
2367 if Nkind (Unit (Lib_Spec)) in N_Package_Body | N_Subprogram_Body
2368 then
2369 Remove_Context (Library_Unit (Lib_Spec));
2370 end if;
2371 end if;
2372
2373 Set_Is_Immediately_Visible (Par_Unit, False);
2374
2375 Analyze_Subunit_Context;
2376
2377 -- Take into account the effect of any SPARK_Mode configuration
2378 -- pragma, which takes precedence over a different value of
2379 -- SPARK_Mode inherited from the context of the stub.
2380
2381 if SPARK_Mode /= None then
2382 Saved_SM := SPARK_Mode;
2383 Saved_SMP := SPARK_Mode_Pragma;
2384 end if;
2385
2386 Re_Install_Parents (Lib_Unit, Par_Unit);
2387 Set_Is_Immediately_Visible (Par_Unit);
2388
2389 -- If the context includes a child unit of the parent of the subunit,
2390 -- the parent will have been removed from visibility, after compiling
2391 -- that cousin in the context. The visibility of the parent must be
2392 -- restored now. This also applies if the context includes another
2393 -- subunit of the same parent which in turn includes a child unit in
2394 -- its context.
2395
2396 if Is_Package_Or_Generic_Package (Par_Unit) then
2397 if not Is_Immediately_Visible (Par_Unit)
2398 or else (Present (First_Entity (Par_Unit))
2399 and then not
2400 Is_Immediately_Visible (First_Entity (Par_Unit)))
2401 then
2402 Set_Is_Immediately_Visible (Par_Unit);
2403 Install_Visible_Declarations (Par_Unit);
2404 Install_Private_Declarations (Par_Unit);
2405 end if;
2406 end if;
2407
2408 Re_Install_Use_Clauses;
2409 Install_Context (N, Chain => False);
2410
2411 -- Restore state of suppress flags for current body
2412
2413 Scope_Suppress := Svg;
2414
2415 -- If the subunit is within a child unit, then siblings of any parent
2416 -- unit that appear in the context clause of the subunit must also be
2417 -- made immediately visible.
2418
2419 if Present (Enclosing_Child) then
2420 Install_Siblings (Enclosing_Child, N);
2421 end if;
2422 end if;
2423
2424 Generate_Parent_References (Unit (N), Par_Unit);
2425
2426 -- Reinstall the SPARK_Mode which was in effect prior to any scope and
2427 -- context manipulations, taking into account a possible SPARK_Mode
2428 -- configuration pragma if present.
2429
2430 Install_SPARK_Mode (Saved_SM, Saved_SMP);
2431
2432 -- If the subunit is part of a compilation unit which is subject to
2433 -- pragma Elaboration_Checks, set the model specified by the pragma
2434 -- because it applies to all parts of the unit.
2435
2436 Install_Elaboration_Model (Par_Unit);
2437
2438 -- The syntax rules require a proper body for a subprogram subunit
2439
2440 if Nkind (Proper_Body (Sinfo.Nodes.Unit (N))) = N_Subprogram_Declaration
2441 then
2442 if Null_Present (Specification (Proper_Body (Sinfo.Nodes.Unit (N))))
2443 then
2444 Error_Msg_N
2445 ("null procedure not allowed as subunit",
2446 Proper_Body (Unit (N)));
2447 else
2448 Error_Msg_N
2449 ("subprogram declaration not allowed as subunit",
2450 Defining_Unit_Name (Specification (Proper_Body (Unit (N)))));
2451 end if;
2452 end if;
2453
2454 Analyze (Proper_Body (Unit (N)));
2455 Remove_Context (N);
2456
2457 -- The subunit may contain a with_clause on a sibling of some ancestor.
2458 -- Removing the context will remove from visibility those ancestor child
2459 -- units, which must be restored to the visibility they have in the
2460 -- enclosing body.
2461
2462 if Present (Enclosing_Child) then
2463 declare
2464 C : Entity_Id;
2465 begin
2466 C := Current_Scope;
2467 while Present (C) and then C /= Standard_Standard loop
2468 Set_Is_Immediately_Visible (C);
2469 Set_Is_Visible_Lib_Unit (C);
2470 C := Scope (C);
2471 end loop;
2472 end;
2473 end if;
2474
2475 -- Deal with restore of restrictions
2476
2477 Cunit_Boolean_Restrictions_Restore (Save_Cunit_Restrictions);
2478 end Analyze_Subunit;
2479
2480 ----------------------------
2481 -- Analyze_Task_Body_Stub --
2482 ----------------------------
2483
2484 procedure Analyze_Task_Body_Stub (N : Node_Id) is
2485 Id : constant Entity_Id := Defining_Entity (N);
2486 Loc : constant Source_Ptr := Sloc (N);
2487 Nam : Entity_Id := Current_Entity_In_Scope (Id);
2488
2489 begin
2490 Check_Stub_Level (N);
2491
2492 -- First occurrence of name may have been as an incomplete type
2493
2494 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
2495 Nam := Full_View (Nam);
2496 end if;
2497
2498 if No (Nam) or else not Is_Task_Type (Etype (Nam)) then
2499 Error_Msg_N ("missing specification for task body", N);
2500
2501 else
2502 Set_Scope (Id, Current_Scope);
2503 Mutate_Ekind (Id, E_Task_Body);
2504 Set_Etype (Id, Standard_Void_Type);
2505
2506 if Has_Aspects (N) then
2507 Analyze_Aspect_Specifications (N, Id);
2508 end if;
2509
2510 Generate_Reference (Nam, Id, 'b');
2511 Set_Corresponding_Spec_Of_Stub (N, Nam);
2512
2513 -- Check for duplicate stub, if so give message and terminate
2514
2515 if Has_Completion (Etype (Nam)) then
2516 Error_Msg_N ("duplicate stub for task", N);
2517 return;
2518 else
2519 Set_Has_Completion (Etype (Nam));
2520 end if;
2521
2522 Analyze_Proper_Body (N, Etype (Nam));
2523
2524 -- Set elaboration flag to indicate that entity is callable. This
2525 -- cannot be done in the expansion of the body itself, because the
2526 -- proper body is not in a declarative part. This is only done if
2527 -- expansion is active, because the context may be generic and the
2528 -- flag not defined yet.
2529
2530 if Expander_Active then
2531 Insert_After (N,
2532 Make_Assignment_Statement (Loc,
2533 Name =>
2534 Make_Identifier (Loc,
2535 Chars => New_External_Name (Chars (Etype (Nam)), 'E')),
2536 Expression => New_Occurrence_Of (Standard_True, Loc)));
2537 end if;
2538 end if;
2539 end Analyze_Task_Body_Stub;
2540
2541 -------------------------
2542 -- Analyze_With_Clause --
2543 -------------------------
2544
2545 -- Analyze the declaration of a unit in a with clause. At end, label the
2546 -- with clause with the defining entity for the unit.
2547
2548 procedure Analyze_With_Clause (N : Node_Id) is
2549
2550 -- Retrieve the original kind of the unit node, before analysis. If it
2551 -- is a subprogram instantiation, its analysis below will rewrite the
2552 -- node as the declaration of the wrapper package. If the same
2553 -- instantiation appears indirectly elsewhere in the context, it will
2554 -- have been analyzed already.
2555
2556 Unit_Kind : constant Node_Kind :=
2557 Nkind (Original_Node (Unit (Library_Unit (N))));
2558 Nam : constant Node_Id := Name (N);
2559 E_Name : Entity_Id;
2560 Par_Name : Entity_Id;
2561 Pref : Node_Id;
2562 U : Node_Id;
2563
2564 Intunit : Boolean;
2565 -- Set True if the unit currently being compiled is an internal unit
2566
2567 Restriction_Violation : Boolean := False;
2568 -- Set True if a with violates a restriction, no point in giving any
2569 -- warnings if we have this definite error.
2570
2571 Save_Style_Check : constant Boolean := Opt.Style_Check;
2572
2573 begin
2574 U := Unit (Library_Unit (N));
2575
2576 -- If this is an internal unit which is a renaming, then this is a
2577 -- violation of No_Obsolescent_Features.
2578
2579 -- Note: this is not quite right if the user defines one of these units
2580 -- himself, but that's a marginal case, and fixing it is hard ???
2581
2582 if Restriction_Check_Required (No_Obsolescent_Features) then
2583 if In_Predefined_Renaming (U) then
2584 Check_Restriction (No_Obsolescent_Features, N);
2585 Restriction_Violation := True;
2586 end if;
2587 end if;
2588
2589 -- Check No_Implementation_Units violation
2590
2591 if Restriction_Check_Required (No_Implementation_Units) then
2592 if Not_Impl_Defined_Unit (Get_Source_Unit (U)) then
2593 null;
2594 else
2595 Check_Restriction (No_Implementation_Units, Nam);
2596 Restriction_Violation := True;
2597 end if;
2598 end if;
2599
2600 -- Several actions are skipped for dummy packages (those supplied for
2601 -- with's where no matching file could be found). Such packages are
2602 -- identified by the Sloc value being set to No_Location.
2603
2604 if Limited_Present (N) then
2605
2606 -- Ada 2005 (AI-50217): Build visibility structures but do not
2607 -- analyze the unit.
2608
2609 -- If the designated unit is a predefined unit, which might be used
2610 -- implicitly through the rtsfind machinery, a limited with clause
2611 -- on such a unit is usually pointless, because run-time units are
2612 -- unlikely to appear in mutually dependent units, and because this
2613 -- disables the rtsfind mechanism. We transform such limited with
2614 -- clauses into regular with clauses.
2615
2616 if Sloc (U) /= No_Location then
2617 if In_Predefined_Unit (U) then
2618 Set_Limited_Present (N, False);
2619 Analyze_With_Clause (N);
2620 else
2621 Build_Limited_Views (N);
2622 end if;
2623 end if;
2624
2625 return;
2626 end if;
2627
2628 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2629 -- already detected serious errors then we mark the with-clause nodes as
2630 -- analyzed before the corresponding compilation unit is analyzed. This
2631 -- is done here to protect the frontend against never ending recursion
2632 -- caused by circularities in the sources (because the previous errors
2633 -- may break the regular machine of the compiler implemented in
2634 -- Load_Unit to detect circularities).
2635
2636 if Serious_Errors_Detected > 0 and then Try_Semantics then
2637 Set_Analyzed (N);
2638 end if;
2639
2640 Semantics (Library_Unit (N));
2641
2642 Intunit := Is_Internal_Unit (Current_Sem_Unit);
2643
2644 if Sloc (U) /= No_Location then
2645
2646 -- Check restrictions, except that we skip the check if this is an
2647 -- internal unit unless we are compiling the internal unit as the
2648 -- main unit. We also skip this for dummy packages.
2649
2650 Check_Restriction_No_Dependence (Nam, N);
2651
2652 if not Intunit or else Current_Sem_Unit = Main_Unit then
2653 Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N);
2654 end if;
2655
2656 -- Deal with special case of GNAT.Current_Exceptions which interacts
2657 -- with the optimization of local raise statements into gotos.
2658
2659 if Nkind (Nam) = N_Selected_Component
2660 and then Nkind (Prefix (Nam)) = N_Identifier
2661 and then Chars (Prefix (Nam)) = Name_Gnat
2662 and then Chars (Selector_Name (Nam))
2663 in Name_Most_Recent_Exception | Name_Exception_Traces
2664 then
2665 Check_Restriction (No_Exception_Propagation, N);
2666 Special_Exception_Package_Used := True;
2667 end if;
2668
2669 -- Check for inappropriate with of internal implementation unit if we
2670 -- are not compiling an internal unit and also check for withing unit
2671 -- in wrong version of Ada. Do not issue these messages for implicit
2672 -- with's generated by the compiler itself.
2673
2674 if Implementation_Unit_Warnings
2675 and then not Intunit
2676 and then not Implicit_With (N)
2677 and then not Restriction_Violation
2678 then
2679 case Get_Kind_Of_Unit (Get_Source_Unit (U)) is
2680 when Implementation_Unit =>
2681 Error_Msg_F ("& is an internal 'G'N'A'T unit?i?", Name (N));
2682
2683 -- Add alternative name if available, otherwise issue a
2684 -- general warning message.
2685
2686 if Error_Msg_Strlen /= 0 then
2687 Error_Msg_F ("\use ""~"" instead?i?", Name (N));
2688 else
2689 Error_Msg_F
2690 ("\use of this unit is non-portable and "
2691 & "version-dependent?i?", Name (N));
2692 end if;
2693
2694 when Not_Predefined_Unit | Ada_95_Unit =>
2695 null; -- no checks needed
2696
2697 when Ada_2005_Unit =>
2698 if Ada_Version < Ada_2005
2699 and then Warn_On_Ada_2005_Compatibility
2700 then
2701 Error_Msg_N ("& is an Ada 2005 unit?i?", Name (N));
2702 end if;
2703
2704 when Ada_2012_Unit =>
2705 if Ada_Version < Ada_2012
2706 and then Warn_On_Ada_2012_Compatibility
2707 then
2708 Error_Msg_N ("& is an Ada 2012 unit?i?", Name (N));
2709 end if;
2710
2711 when Ada_202X_Unit =>
2712 if Ada_Version < Ada_2020
2713 and then Warn_On_Ada_202X_Compatibility
2714 then
2715 Error_Msg_N ("& is an Ada 202x unit?i?", Name (N));
2716 end if;
2717 end case;
2718 end if;
2719 end if;
2720
2721 -- Semantic analysis of a generic unit is performed on a copy of
2722 -- the original tree. Retrieve the entity on which semantic info
2723 -- actually appears.
2724
2725 if Unit_Kind in N_Generic_Declaration then
2726 E_Name := Defining_Entity (U);
2727
2728 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2729 -- the case of an instantiation, semantic analysis above will have
2730 -- replaced the unit by its instantiated version. If the instance body
2731 -- has been generated, the instance now denotes the body entity. For
2732 -- visibility purposes we need the entity of its spec.
2733
2734 elsif (Unit_Kind = N_Package_Instantiation
2735 or else Nkind (Original_Node (Unit (Library_Unit (N)))) =
2736 N_Package_Instantiation)
2737 and then Nkind (U) = N_Package_Body
2738 then
2739 E_Name := Corresponding_Spec (U);
2740
2741 elsif Unit_Kind = N_Package_Instantiation
2742 and then Nkind (U) = N_Package_Instantiation
2743 and then Present (Instance_Spec (U))
2744 then
2745 -- If the instance has not been rewritten as a package declaration,
2746 -- then it appeared already in a previous with clause. Retrieve
2747 -- the entity from the previous instance.
2748
2749 E_Name := Defining_Entity (Specification (Instance_Spec (U)));
2750
2751 elsif Unit_Kind in N_Subprogram_Instantiation then
2752
2753 -- The visible subprogram is created during instantiation, and is
2754 -- an attribute of the wrapper package. We retrieve the wrapper
2755 -- package directly from the instantiation node. If the instance
2756 -- is inlined the unit is still an instantiation. Otherwise it has
2757 -- been rewritten as the declaration of the wrapper itself.
2758
2759 if Nkind (U) in N_Subprogram_Instantiation then
2760 E_Name :=
2761 Related_Instance
2762 (Defining_Entity (Specification (Instance_Spec (U))));
2763 else
2764 E_Name := Related_Instance (Defining_Entity (U));
2765 end if;
2766
2767 elsif Unit_Kind = N_Package_Renaming_Declaration
2768 or else Unit_Kind in N_Generic_Renaming_Declaration
2769 then
2770 E_Name := Defining_Entity (U);
2771
2772 elsif Unit_Kind = N_Subprogram_Body
2773 and then Nkind (Name (N)) = N_Selected_Component
2774 and then not Acts_As_Spec (Library_Unit (N))
2775 then
2776 -- For a child unit that has no spec, one has been created and
2777 -- analyzed. The entity required is that of the spec.
2778
2779 E_Name := Corresponding_Spec (U);
2780
2781 else
2782 E_Name := Defining_Entity (U);
2783 end if;
2784
2785 if Nkind (Name (N)) = N_Selected_Component then
2786
2787 -- Child unit in a with clause
2788
2789 Change_Selected_Component_To_Expanded_Name (Name (N));
2790
2791 -- If this is a child unit without a spec, and it has been analyzed
2792 -- already, a declaration has been created for it. The with_clause
2793 -- must reflect the actual body, and not the generated declaration,
2794 -- to prevent spurious binding errors involving an out-of-date spec.
2795 -- Note that this can only happen if the unit includes more than one
2796 -- with_clause for the child unit (e.g. in separate subunits).
2797
2798 if Unit_Kind = N_Subprogram_Declaration
2799 and then Analyzed (Library_Unit (N))
2800 and then not Comes_From_Source (Library_Unit (N))
2801 then
2802 Set_Library_Unit (N,
2803 Cunit (Get_Source_Unit (Corresponding_Body (U))));
2804 end if;
2805 end if;
2806
2807 -- Restore style checks
2808
2809 Style_Check := Save_Style_Check;
2810
2811 -- Record the reference, but do NOT set the unit as referenced, we want
2812 -- to consider the unit as unreferenced if this is the only reference
2813 -- that occurs.
2814
2815 Set_Entity_With_Checks (Name (N), E_Name);
2816 Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False);
2817
2818 -- Generate references and check No_Dependence restriction for parents
2819
2820 if Is_Child_Unit (E_Name) then
2821 Pref := Prefix (Name (N));
2822 Par_Name := Scope (E_Name);
2823 while Nkind (Pref) = N_Selected_Component loop
2824 Change_Selected_Component_To_Expanded_Name (Pref);
2825
2826 if Present (Entity (Selector_Name (Pref)))
2827 and then
2828 Present (Renamed_Entity (Entity (Selector_Name (Pref))))
2829 and then Entity (Selector_Name (Pref)) /= Par_Name
2830 then
2831 -- The prefix is a child unit that denotes a renaming declaration.
2832 -- Replace the prefix directly with the renamed unit, because the
2833 -- rest of the prefix is irrelevant to the visibility of the real
2834 -- unit.
2835
2836 Rewrite (Pref, New_Occurrence_Of (Par_Name, Sloc (Pref)));
2837 exit;
2838 end if;
2839
2840 Set_Entity_With_Checks (Pref, Par_Name);
2841
2842 Generate_Reference (Par_Name, Pref);
2843 Check_Restriction_No_Dependence (Pref, N);
2844 Pref := Prefix (Pref);
2845
2846 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2847 -- is set to Standard_Standard, and no attempt should be made to
2848 -- further unwind scopes.
2849
2850 if Par_Name /= Standard_Standard then
2851 Par_Name := Scope (Par_Name);
2852 end if;
2853
2854 -- Abandon processing in case of previous errors
2855
2856 if No (Par_Name) then
2857 Check_Error_Detected;
2858 return;
2859 end if;
2860 end loop;
2861
2862 if Present (Entity (Pref))
2863 and then not Analyzed (Parent (Parent (Entity (Pref))))
2864 then
2865 -- If the entity is set without its unit being compiled, the
2866 -- original parent is a renaming, and Par_Name is the renamed
2867 -- entity. For visibility purposes, we need the original entity,
2868 -- which must be analyzed now because Load_Unit directly retrieves
2869 -- the renamed unit, and the renaming declaration itself has not
2870 -- been analyzed.
2871
2872 Analyze (Parent (Parent (Entity (Pref))));
2873 pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name);
2874 Par_Name := Entity (Pref);
2875 end if;
2876
2877 -- Guard against missing or misspelled child units
2878
2879 if Present (Par_Name) then
2880 Set_Entity_With_Checks (Pref, Par_Name);
2881 Generate_Reference (Par_Name, Pref);
2882
2883 else
2884 pragma Assert (Serious_Errors_Detected /= 0);
2885
2886 -- Mark the node to indicate that a related error has been posted.
2887 -- This defends further compilation passes against improper use of
2888 -- the invalid WITH clause node.
2889
2890 Set_Error_Posted (N);
2891 Set_Name (N, Error);
2892 return;
2893 end if;
2894 end if;
2895
2896 -- If the withed unit is System, and a system extension pragma is
2897 -- present, compile the extension now, rather than waiting for a
2898 -- visibility check on a specific entity.
2899
2900 if Chars (E_Name) = Name_System
2901 and then Scope (E_Name) = Standard_Standard
2902 and then Present (System_Extend_Unit)
2903 and then Present_System_Aux (N)
2904 then
2905 -- If the extension is not present, an error will have been emitted
2906
2907 null;
2908 end if;
2909
2910 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2911 -- to private_with units; they will be made visible later (just before
2912 -- the private part is analyzed)
2913
2914 if Private_Present (N) then
2915 Set_Is_Immediately_Visible (E_Name, False);
2916 end if;
2917
2918 -- Propagate Fatal_Error setting from with'ed unit to current unit
2919
2920 case Fatal_Error (Get_Source_Unit (Library_Unit (N))) is
2921
2922 -- Nothing to do if with'ed unit had no error
2923
2924 when None =>
2925 null;
2926
2927 -- If with'ed unit had a detected fatal error, propagate it
2928
2929 when Error_Detected =>
2930 Set_Fatal_Error (Current_Sem_Unit, Error_Detected);
2931
2932 -- If with'ed unit had an ignored error, then propagate it but do not
2933 -- overide an existring setting.
2934
2935 when Error_Ignored =>
2936 if Fatal_Error (Current_Sem_Unit) = None then
2937 Set_Fatal_Error (Current_Sem_Unit, Error_Ignored);
2938 end if;
2939 end case;
2940 end Analyze_With_Clause;
2941
2942 ------------------------------
2943 -- Check_Private_Child_Unit --
2944 ------------------------------
2945
2946 procedure Check_Private_Child_Unit (N : Node_Id) is
2947 Lib_Unit : constant Node_Id := Unit (N);
2948 Item : Node_Id;
2949 Curr_Unit : Entity_Id;
2950 Sub_Parent : Node_Id;
2951 Priv_Child : Entity_Id;
2952 Par_Lib : Entity_Id;
2953 Par_Spec : Node_Id;
2954
2955 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
2956 -- Returns true if and only if the library unit is declared with
2957 -- an explicit designation of private.
2958
2959 -----------------------------
2960 -- Is_Private_Library_Unit --
2961 -----------------------------
2962
2963 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
2964 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
2965
2966 begin
2967 return Private_Present (Comp_Unit);
2968 end Is_Private_Library_Unit;
2969
2970 -- Start of processing for Check_Private_Child_Unit
2971
2972 begin
2973 if Nkind (Lib_Unit) in N_Package_Body | N_Subprogram_Body then
2974 Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
2975 Par_Lib := Curr_Unit;
2976
2977 elsif Nkind (Lib_Unit) = N_Subunit then
2978
2979 -- The parent is itself a body. The parent entity is to be found in
2980 -- the corresponding spec.
2981
2982 Sub_Parent := Library_Unit (N);
2983 Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
2984
2985 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2986 -- enclosing body, retrieve the spec entity which is the proper
2987 -- ancestor we need for the following tests.
2988
2989 if Ekind (Curr_Unit) = E_Package_Body then
2990 Curr_Unit := Spec_Entity (Curr_Unit);
2991 end if;
2992
2993 Par_Lib := Curr_Unit;
2994
2995 else
2996 Curr_Unit := Defining_Entity (Lib_Unit);
2997
2998 Par_Lib := Curr_Unit;
2999 Par_Spec := Parent_Spec (Lib_Unit);
3000
3001 if No (Par_Spec) then
3002 Par_Lib := Empty;
3003 else
3004 Par_Lib := Defining_Entity (Unit (Par_Spec));
3005 end if;
3006 end if;
3007
3008 -- Loop through context items
3009
3010 Item := First (Context_Items (N));
3011 while Present (Item) loop
3012
3013 -- Ada 2005 (AI-262): Allow private_with of a private child package
3014 -- in public siblings
3015
3016 if Nkind (Item) = N_With_Clause
3017 and then not Implicit_With (Item)
3018 and then not Limited_Present (Item)
3019 and then Is_Private_Descendant (Entity (Name (Item)))
3020 then
3021 Priv_Child := Entity (Name (Item));
3022
3023 declare
3024 Curr_Parent : Entity_Id := Par_Lib;
3025 Child_Parent : Entity_Id := Scope (Priv_Child);
3026 Prv_Ancestor : Entity_Id := Child_Parent;
3027 Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
3028
3029 begin
3030 -- If the child unit is a public child then locate the nearest
3031 -- private ancestor. Child_Parent will then be set to the
3032 -- parent of that ancestor.
3033
3034 if not Is_Private_Library_Unit (Priv_Child) then
3035 while Present (Prv_Ancestor)
3036 and then not Is_Private_Library_Unit (Prv_Ancestor)
3037 loop
3038 Prv_Ancestor := Scope (Prv_Ancestor);
3039 end loop;
3040
3041 if Present (Prv_Ancestor) then
3042 Child_Parent := Scope (Prv_Ancestor);
3043 end if;
3044 end if;
3045
3046 while Present (Curr_Parent)
3047 and then Curr_Parent /= Standard_Standard
3048 and then Curr_Parent /= Child_Parent
3049 loop
3050 Curr_Private :=
3051 Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
3052 Curr_Parent := Scope (Curr_Parent);
3053 end loop;
3054
3055 if No (Curr_Parent) then
3056 Curr_Parent := Standard_Standard;
3057 end if;
3058
3059 if Curr_Parent /= Child_Parent then
3060 if Ekind (Priv_Child) = E_Generic_Package
3061 and then Chars (Priv_Child) in Text_IO_Package_Name
3062 and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
3063 and then Scope (Scope (Scope (Priv_Child))) =
3064 Standard_Standard
3065 then
3066 Error_Msg_NE
3067 ("& is a nested package, not a compilation unit",
3068 Name (Item), Priv_Child);
3069
3070 else
3071 Error_Msg_N
3072 ("unit in with clause is private child unit!", Item);
3073 Error_Msg_NE
3074 ("\current unit must also have parent&!",
3075 Item, Child_Parent);
3076 end if;
3077
3078 elsif Curr_Private
3079 or else Private_Present (Item)
3080 or else Nkind (Lib_Unit) in N_Package_Body | N_Subunit
3081 or else (Nkind (Lib_Unit) = N_Subprogram_Body
3082 and then not Acts_As_Spec (Parent (Lib_Unit)))
3083 then
3084 null;
3085
3086 else
3087 Error_Msg_NE
3088 ("current unit must also be private descendant of&",
3089 Item, Child_Parent);
3090 end if;
3091 end;
3092 end if;
3093
3094 Next (Item);
3095 end loop;
3096 end Check_Private_Child_Unit;
3097
3098 ----------------------
3099 -- Check_Stub_Level --
3100 ----------------------
3101
3102 procedure Check_Stub_Level (N : Node_Id) is
3103 Par : constant Node_Id := Parent (N);
3104 Kind : constant Node_Kind := Nkind (Par);
3105
3106 begin
3107 if Kind in
3108 N_Package_Body | N_Subprogram_Body | N_Task_Body | N_Protected_Body
3109 and then Nkind (Parent (Par)) in N_Compilation_Unit | N_Subunit
3110 then
3111 null;
3112
3113 -- In an instance, a missing stub appears at any level. A warning
3114 -- message will have been emitted already for the missing file.
3115
3116 elsif not In_Instance then
3117 Error_Msg_N ("stub cannot appear in an inner scope", N);
3118
3119 elsif Expander_Active then
3120 Error_Msg_N ("missing proper body", N);
3121 end if;
3122 end Check_Stub_Level;
3123
3124 ------------------------
3125 -- Expand_With_Clause --
3126 ------------------------
3127
3128 procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id) is
3129 Loc : constant Source_Ptr := Sloc (Nam);
3130
3131 function Build_Unit_Name (Nam : Node_Id) return Node_Id;
3132 -- Build name to be used in implicit with_clause. In most cases this
3133 -- is the source name, but if renamings are present we must make the
3134 -- original unit visible, not the one it renames. The entity in the
3135 -- with clause is the renamed unit, but the identifier is the one from
3136 -- the source, which allows us to recover the unit renaming.
3137
3138 ---------------------
3139 -- Build_Unit_Name --
3140 ---------------------
3141
3142 function Build_Unit_Name (Nam : Node_Id) return Node_Id is
3143 Ent : Entity_Id;
3144 Result : Node_Id;
3145
3146 begin
3147 if Nkind (Nam) = N_Identifier then
3148 return New_Occurrence_Of (Entity (Nam), Loc);
3149
3150 else
3151 Ent := Entity (Nam);
3152
3153 if Present (Entity (Selector_Name (Nam)))
3154 and then Chars (Entity (Selector_Name (Nam))) /= Chars (Ent)
3155 and then
3156 Nkind (Unit_Declaration_Node (Entity (Selector_Name (Nam)))) =
3157 N_Package_Renaming_Declaration
3158 then
3159 -- The name in the with_clause is of the form A.B.C, and B is
3160 -- given by a renaming declaration. In that case we may not
3161 -- have analyzed the unit for B, but replaced it directly in
3162 -- lib-load with the unit it renames. We have to make A.B
3163 -- visible, so analyze the declaration for B now, in case it
3164 -- has not been done yet.
3165
3166 Ent := Entity (Selector_Name (Nam));
3167 Analyze
3168 (Parent
3169 (Unit_Declaration_Node (Entity (Selector_Name (Nam)))));
3170 end if;
3171
3172 Result :=
3173 Make_Expanded_Name (Loc,
3174 Chars => Chars (Entity (Nam)),
3175 Prefix => Build_Unit_Name (Prefix (Nam)),
3176 Selector_Name => New_Occurrence_Of (Ent, Loc));
3177 Set_Entity (Result, Ent);
3178
3179 return Result;
3180 end if;
3181 end Build_Unit_Name;
3182
3183 -- Local variables
3184
3185 Ent : constant Entity_Id := Entity (Nam);
3186 Withn : Node_Id;
3187
3188 -- Start of processing for Expand_With_Clause
3189
3190 begin
3191 Withn :=
3192 Make_With_Clause (Loc,
3193 Name => Build_Unit_Name (Nam));
3194
3195 Set_Corresponding_Spec (Withn, Ent);
3196 Set_First_Name (Withn);
3197 Set_Implicit_With (Withn);
3198 Set_Library_Unit (Withn, Parent (Unit_Declaration_Node (Ent)));
3199 Set_Parent_With (Withn);
3200
3201 -- If the unit is a [generic] package or subprogram declaration
3202 -- (including a subprogram body acting as spec), a private_with_clause
3203 -- on a child unit implies that the implicit with on the parent is also
3204 -- private.
3205
3206 if Nkind (Unit (N)) in N_Generic_Package_Declaration
3207 | N_Package_Declaration
3208 | N_Generic_Subprogram_Declaration
3209 | N_Subprogram_Declaration
3210 | N_Subprogram_Body
3211 then
3212 Set_Private_Present (Withn, Private_Present (Item));
3213 end if;
3214
3215 Prepend (Withn, Context_Items (N));
3216 Mark_Rewrite_Insertion (Withn);
3217
3218 Install_With_Clause (Withn);
3219
3220 -- If we have "with X.Y;", we want to recurse on "X", except in the
3221 -- unusual case where X.Y is a renaming of X. In that case, the scope
3222 -- of X will be null.
3223
3224 if Nkind (Nam) = N_Expanded_Name
3225 and then Present (Scope (Entity (Prefix (Nam))))
3226 then
3227 Expand_With_Clause (Item, Prefix (Nam), N);
3228 end if;
3229 end Expand_With_Clause;
3230
3231 --------------------------------
3232 -- Generate_Parent_References --
3233 --------------------------------
3234
3235 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is
3236 Pref : Node_Id;
3237 P_Name : Entity_Id := P_Id;
3238
3239 begin
3240 if Nkind (N) = N_Subunit then
3241 Pref := Name (N);
3242 else
3243 Pref := Name (Parent (Defining_Entity (N)));
3244 end if;
3245
3246 if Nkind (Pref) = N_Expanded_Name then
3247
3248 -- Done already, if the unit has been compiled indirectly as
3249 -- part of the closure of its context because of inlining.
3250
3251 return;
3252 end if;
3253
3254 while Nkind (Pref) = N_Selected_Component loop
3255 Change_Selected_Component_To_Expanded_Name (Pref);
3256 Set_Entity (Pref, P_Name);
3257 Set_Etype (Pref, Etype (P_Name));
3258 Generate_Reference (P_Name, Pref, 'r');
3259 Pref := Prefix (Pref);
3260 P_Name := Scope (P_Name);
3261 end loop;
3262
3263 -- The guard here on P_Name is to handle the error condition where
3264 -- the parent unit is missing because the file was not found.
3265
3266 if Present (P_Name) then
3267 Set_Entity (Pref, P_Name);
3268 Set_Etype (Pref, Etype (P_Name));
3269 Generate_Reference (P_Name, Pref, 'r');
3270 Style.Check_Identifier (Pref, P_Name);
3271 end if;
3272 end Generate_Parent_References;
3273
3274 ---------------------
3275 -- Has_With_Clause --
3276 ---------------------
3277
3278 function Has_With_Clause
3279 (C_Unit : Node_Id;
3280 Pack : Entity_Id;
3281 Is_Limited : Boolean := False) return Boolean
3282 is
3283 Item : Node_Id;
3284
3285 function Named_Unit (Clause : Node_Id) return Entity_Id;
3286 -- Return the entity for the unit named in a [limited] with clause
3287
3288 ----------------
3289 -- Named_Unit --
3290 ----------------
3291
3292 function Named_Unit (Clause : Node_Id) return Entity_Id is
3293 begin
3294 if Nkind (Name (Clause)) = N_Selected_Component then
3295 return Entity (Selector_Name (Name (Clause)));
3296 else
3297 return Entity (Name (Clause));
3298 end if;
3299 end Named_Unit;
3300
3301 -- Start of processing for Has_With_Clause
3302
3303 begin
3304 if Present (Context_Items (C_Unit)) then
3305 Item := First (Context_Items (C_Unit));
3306 while Present (Item) loop
3307 if Nkind (Item) = N_With_Clause
3308 and then Limited_Present (Item) = Is_Limited
3309 and then Named_Unit (Item) = Pack
3310 then
3311 return True;
3312 end if;
3313
3314 Next (Item);
3315 end loop;
3316 end if;
3317
3318 return False;
3319 end Has_With_Clause;
3320
3321 -----------------------------
3322 -- Implicit_With_On_Parent --
3323 -----------------------------
3324
3325 procedure Implicit_With_On_Parent
3326 (Child_Unit : Node_Id;
3327 N : Node_Id)
3328 is
3329 Loc : constant Source_Ptr := Sloc (N);
3330 P : constant Node_Id := Parent_Spec (Child_Unit);
3331 P_Unit : Node_Id := Unit (P);
3332 P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
3333 Withn : Node_Id;
3334
3335 function Build_Ancestor_Name (P : Node_Id) return Node_Id;
3336 -- Build prefix of child unit name. Recurse if needed
3337
3338 function Build_Unit_Name return Node_Id;
3339 -- If the unit is a child unit, build qualified name with all ancestors
3340
3341 -------------------------
3342 -- Build_Ancestor_Name --
3343 -------------------------
3344
3345 function Build_Ancestor_Name (P : Node_Id) return Node_Id is
3346 P_Ref : constant Node_Id :=
3347 New_Occurrence_Of (Defining_Entity (P), Loc);
3348 P_Spec : Node_Id := P;
3349
3350 begin
3351 -- Ancestor may have been rewritten as a package body. Retrieve the
3352 -- original spec to trace earlier ancestors.
3353
3354 if Nkind (P) = N_Package_Body
3355 and then Nkind (Original_Node (P)) = N_Package_Instantiation
3356 then
3357 P_Spec := Original_Node (P);
3358 end if;
3359
3360 if No (Parent_Spec (P_Spec)) then
3361 return P_Ref;
3362 else
3363 return
3364 Make_Selected_Component (Loc,
3365 Prefix =>
3366 Build_Ancestor_Name (Unit (Parent_Spec (P_Spec))),
3367 Selector_Name => P_Ref);
3368 end if;
3369 end Build_Ancestor_Name;
3370
3371 ---------------------
3372 -- Build_Unit_Name --
3373 ---------------------
3374
3375 function Build_Unit_Name return Node_Id is
3376 Result : Node_Id;
3377
3378 begin
3379 if No (Parent_Spec (P_Unit)) then
3380 return New_Occurrence_Of (P_Name, Loc);
3381
3382 else
3383 Result :=
3384 Make_Expanded_Name (Loc,
3385 Chars => Chars (P_Name),
3386 Prefix =>
3387 Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
3388 Selector_Name => New_Occurrence_Of (P_Name, Loc));
3389 Set_Entity (Result, P_Name);
3390
3391 return Result;
3392 end if;
3393 end Build_Unit_Name;
3394
3395 -- Start of processing for Implicit_With_On_Parent
3396
3397 begin
3398 -- The unit of the current compilation may be a package body that
3399 -- replaces an instance node. In this case we need the original instance
3400 -- node to construct the proper parent name.
3401
3402 if Nkind (P_Unit) = N_Package_Body
3403 and then Nkind (Original_Node (P_Unit)) = N_Package_Instantiation
3404 then
3405 P_Unit := Original_Node (P_Unit);
3406 end if;
3407
3408 -- We add the implicit with if the child unit is the current unit being
3409 -- compiled. If the current unit is a body, we do not want to add an
3410 -- implicit_with a second time to the corresponding spec.
3411
3412 if Nkind (Child_Unit) = N_Package_Declaration
3413 and then Child_Unit /= Unit (Cunit (Current_Sem_Unit))
3414 then
3415 return;
3416 end if;
3417
3418 Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
3419
3420 Set_Corresponding_Spec (Withn, P_Name);
3421 Set_First_Name (Withn);
3422 Set_Implicit_With (Withn);
3423 Set_Library_Unit (Withn, P);
3424 Set_Parent_With (Withn);
3425
3426 -- Node is placed at the beginning of the context items, so that
3427 -- subsequent use clauses on the parent can be validated.
3428
3429 Prepend (Withn, Context_Items (N));
3430 Mark_Rewrite_Insertion (Withn);
3431
3432 Install_With_Clause (Withn);
3433
3434 if Is_Child_Spec (P_Unit) then
3435 Implicit_With_On_Parent (P_Unit, N);
3436 end if;
3437 end Implicit_With_On_Parent;
3438
3439 --------------
3440 -- In_Chain --
3441 --------------
3442
3443 function In_Chain (E : Entity_Id) return Boolean is
3444 H : Entity_Id;
3445
3446 begin
3447 H := Current_Entity (E);
3448 while Present (H) loop
3449 if H = E then
3450 return True;
3451 else
3452 H := Homonym (H);
3453 end if;
3454 end loop;
3455
3456 return False;
3457 end In_Chain;
3458
3459 ---------------------
3460 -- Install_Context --
3461 ---------------------
3462
3463 procedure Install_Context (N : Node_Id; Chain : Boolean := True) is
3464 Lib_Unit : constant Node_Id := Unit (N);
3465
3466 begin
3467 Install_Context_Clauses (N, Chain);
3468
3469 if Is_Child_Spec (Lib_Unit) then
3470 Install_Parents
3471 (Lib_Unit => Lib_Unit,
3472 Is_Private => Private_Present (Parent (Lib_Unit)),
3473 Chain => Chain);
3474 end if;
3475
3476 Install_Limited_Context_Clauses (N);
3477 end Install_Context;
3478
3479 -----------------------------
3480 -- Install_Context_Clauses --
3481 -----------------------------
3482
3483 procedure Install_Context_Clauses (N : Node_Id; Chain : Boolean := True) is
3484 Lib_Unit : constant Node_Id := Unit (N);
3485 Item : Node_Id;
3486 Uname_Node : Entity_Id;
3487 Check_Private : Boolean := False;
3488 Decl_Node : Node_Id;
3489 Lib_Parent : Entity_Id;
3490
3491 begin
3492 -- First skip configuration pragmas at the start of the context. They
3493 -- are not technically part of the context clause, but that's where the
3494 -- parser puts them. Note they were analyzed in Analyze_Context.
3495
3496 Item := First (Context_Items (N));
3497 while Present (Item)
3498 and then Nkind (Item) = N_Pragma
3499 and then Pragma_Name (Item) in Configuration_Pragma_Names
3500 loop
3501 Next (Item);
3502 end loop;
3503
3504 -- Loop through the actual context clause items. We process everything
3505 -- except Limited_With clauses in this routine. Limited_With clauses
3506 -- are separately installed (see Install_Limited_Context_Clauses).
3507
3508 while Present (Item) loop
3509
3510 -- Case of explicit WITH clause
3511
3512 if Nkind (Item) = N_With_Clause
3513 and then not Implicit_With (Item)
3514 then
3515 if Limited_Present (Item) then
3516
3517 -- Limited withed units will be installed later
3518
3519 goto Continue;
3520
3521 -- If Name (Item) is not an entity name, something is wrong, and
3522 -- this will be detected in due course, for now ignore the item
3523
3524 elsif not Is_Entity_Name (Name (Item)) then
3525 goto Continue;
3526
3527 elsif No (Entity (Name (Item))) then
3528 Set_Entity (Name (Item), Any_Id);
3529 goto Continue;
3530 end if;
3531
3532 Uname_Node := Entity (Name (Item));
3533
3534 if Is_Private_Descendant (Uname_Node) then
3535 Check_Private := True;
3536 end if;
3537
3538 Install_With_Clause (Item);
3539
3540 Decl_Node := Unit_Declaration_Node (Uname_Node);
3541
3542 -- If the unit is a subprogram instance, it appears nested within
3543 -- a package that carries the parent information.
3544
3545 if Is_Generic_Instance (Uname_Node)
3546 and then Ekind (Uname_Node) /= E_Package
3547 then
3548 Decl_Node := Parent (Parent (Decl_Node));
3549 end if;
3550
3551 if Is_Child_Spec (Decl_Node) then
3552 if Nkind (Name (Item)) = N_Expanded_Name then
3553 Expand_With_Clause (Item, Prefix (Name (Item)), N);
3554 else
3555 -- If not an expanded name, the child unit must be a
3556 -- renaming, nothing to do.
3557
3558 null;
3559 end if;
3560
3561 elsif Nkind (Decl_Node) = N_Subprogram_Body
3562 and then not Acts_As_Spec (Parent (Decl_Node))
3563 and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
3564 then
3565 Implicit_With_On_Parent
3566 (Unit (Library_Unit (Parent (Decl_Node))), N);
3567 end if;
3568
3569 -- Check license conditions unless this is a dummy unit
3570
3571 if Sloc (Library_Unit (Item)) /= No_Location then
3572 License_Check : declare
3573 Withu : constant Unit_Number_Type :=
3574 Get_Source_Unit (Library_Unit (Item));
3575 Withl : constant License_Type :=
3576 License (Source_Index (Withu));
3577 Unitl : constant License_Type :=
3578 License (Source_Index (Current_Sem_Unit));
3579
3580 procedure License_Error;
3581 -- Signal error of bad license
3582
3583 -------------------
3584 -- License_Error --
3585 -------------------
3586
3587 procedure License_Error is
3588 begin
3589 Error_Msg_N
3590 ("license of withed unit & may be inconsistent??",
3591 Name (Item));
3592 end License_Error;
3593
3594 -- Start of processing for License_Check
3595
3596 begin
3597 -- Exclude license check if withed unit is an internal unit.
3598 -- This situation arises e.g. with the GPL version of GNAT.
3599
3600 if Is_Internal_Unit (Withu) then
3601 null;
3602
3603 -- Otherwise check various cases
3604 else
3605 case Unitl is
3606 when Unknown =>
3607 null;
3608
3609 when Restricted =>
3610 if Withl = GPL then
3611 License_Error;
3612 end if;
3613
3614 when GPL =>
3615 if Withl = Restricted then
3616 License_Error;
3617 end if;
3618
3619 when Modified_GPL =>
3620 if Withl = Restricted or else Withl = GPL then
3621 License_Error;
3622 end if;
3623
3624 when Unrestricted =>
3625 null;
3626 end case;
3627 end if;
3628 end License_Check;
3629 end if;
3630
3631 -- Case of USE PACKAGE clause
3632
3633 elsif Nkind (Item) = N_Use_Package_Clause then
3634 Analyze_Use_Package (Item, Chain);
3635
3636 -- Case of USE TYPE clause
3637
3638 elsif Nkind (Item) = N_Use_Type_Clause then
3639 Analyze_Use_Type (Item, Chain);
3640
3641 -- case of PRAGMA
3642
3643 elsif Nkind (Item) = N_Pragma then
3644 Analyze (Item);
3645 end if;
3646
3647 <<Continue>>
3648 Next (Item);
3649 end loop;
3650
3651 if Is_Child_Spec (Lib_Unit) then
3652
3653 -- The unit also has implicit with_clauses on its own parents
3654
3655 if No (Context_Items (N)) then
3656 Set_Context_Items (N, New_List);
3657 end if;
3658
3659 Implicit_With_On_Parent (Lib_Unit, N);
3660 end if;
3661
3662 -- If the unit is a body, the context of the specification must also
3663 -- be installed. That includes private with_clauses in that context.
3664
3665 if Nkind (Lib_Unit) = N_Package_Body
3666 or else (Nkind (Lib_Unit) = N_Subprogram_Body
3667 and then not Acts_As_Spec (N))
3668 then
3669 Install_Context (Library_Unit (N), Chain);
3670
3671 -- Only install private with-clauses of a spec that comes from
3672 -- source, excluding specs created for a subprogram body that is
3673 -- a child unit.
3674
3675 if Comes_From_Source (Library_Unit (N)) then
3676 Install_Private_With_Clauses
3677 (Defining_Entity (Unit (Library_Unit (N))));
3678 end if;
3679
3680 if Is_Child_Spec (Unit (Library_Unit (N))) then
3681
3682 -- If the unit is the body of a public child unit, the private
3683 -- declarations of the parent must be made visible. If the child
3684 -- unit is private, the private declarations have been installed
3685 -- already in the call to Install_Parents for the spec. Installing
3686 -- private declarations must be done for all ancestors of public
3687 -- child units. In addition, sibling units mentioned in the
3688 -- context clause of the body are directly visible.
3689
3690 declare
3691 Lib_Spec : Node_Id;
3692 P : Node_Id;
3693 P_Name : Entity_Id;
3694
3695 begin
3696 Lib_Spec := Unit (Library_Unit (N));
3697 while Is_Child_Spec (Lib_Spec) loop
3698 P := Unit (Parent_Spec (Lib_Spec));
3699 P_Name := Defining_Entity (P);
3700
3701 if not (Private_Present (Parent (Lib_Spec)))
3702 and then not In_Private_Part (P_Name)
3703 then
3704 Install_Private_Declarations (P_Name);
3705 Install_Private_With_Clauses (P_Name);
3706 Set_Use (Private_Declarations (Specification (P)));
3707 end if;
3708
3709 Lib_Spec := P;
3710 end loop;
3711 end;
3712 end if;
3713
3714 -- For a package body, children in context are immediately visible
3715
3716 Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
3717 end if;
3718
3719 if Nkind (Lib_Unit) in N_Generic_Package_Declaration
3720 | N_Generic_Subprogram_Declaration
3721 | N_Package_Declaration
3722 | N_Subprogram_Declaration
3723 then
3724 if Is_Child_Spec (Lib_Unit) then
3725 Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
3726 Set_Is_Private_Descendant
3727 (Defining_Entity (Lib_Unit),
3728 Is_Private_Descendant (Lib_Parent)
3729 or else Private_Present (Parent (Lib_Unit)));
3730
3731 else
3732 Set_Is_Private_Descendant
3733 (Defining_Entity (Lib_Unit),
3734 Private_Present (Parent (Lib_Unit)));
3735 end if;
3736 end if;
3737
3738 if Check_Private then
3739 Check_Private_Child_Unit (N);
3740 end if;
3741 end Install_Context_Clauses;
3742
3743 -------------------------------------
3744 -- Install_Limited_Context_Clauses --
3745 -------------------------------------
3746
3747 procedure Install_Limited_Context_Clauses (N : Node_Id) is
3748 Item : Node_Id;
3749
3750 procedure Check_Renamings (P : Node_Id; W : Node_Id);
3751 -- Check that the unlimited view of a given compilation_unit is not
3752 -- already visible through "use + renamings".
3753
3754 procedure Check_Private_Limited_Withed_Unit (Item : Node_Id);
3755 -- Check that if a limited_with clause of a given compilation_unit
3756 -- mentions a descendant of a private child of some library unit, then
3757 -- the given compilation_unit must be the declaration of a private
3758 -- descendant of that library unit, or a public descendant of such. The
3759 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3760 -- use entities on the limited with_clauses because their units have not
3761 -- been analyzed, so we have to climb the tree of ancestors looking for
3762 -- private keywords.
3763
3764 procedure Expand_Limited_With_Clause
3765 (Comp_Unit : Node_Id;
3766 Nam : Node_Id;
3767 N : Node_Id);
3768 -- If a child unit appears in a limited_with clause, there are implicit
3769 -- limited_with clauses on all parents that are not already visible
3770 -- through a regular with clause. This procedure creates the implicit
3771 -- limited with_clauses for the parents and loads the corresponding
3772 -- units. The shadow entities are created when the inserted clause is
3773 -- analyzed. Implements Ada 2005 (AI-50217).
3774
3775 ---------------------
3776 -- Check_Renamings --
3777 ---------------------
3778
3779 procedure Check_Renamings (P : Node_Id; W : Node_Id) is
3780 Item : Node_Id;
3781 Spec : Node_Id;
3782 WEnt : Entity_Id;
3783 E : Entity_Id;
3784 E2 : Entity_Id;
3785
3786 begin
3787 pragma Assert (Nkind (W) = N_With_Clause);
3788
3789 -- Protect the frontend against previous critical errors
3790
3791 case Nkind (Unit (Library_Unit (W))) is
3792 when N_Generic_Package_Declaration
3793 | N_Generic_Subprogram_Declaration
3794 | N_Package_Declaration
3795 | N_Subprogram_Declaration
3796 =>
3797 null;
3798
3799 when others =>
3800 return;
3801 end case;
3802
3803 -- Check "use + renamings"
3804
3805 WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
3806 Spec := Specification (Unit (P));
3807
3808 Item := First (Visible_Declarations (Spec));
3809 while Present (Item) loop
3810
3811 -- Look only at use package clauses
3812
3813 if Nkind (Item) = N_Use_Package_Clause then
3814
3815 E := Entity (Name (Item));
3816
3817 pragma Assert (Present (Parent (E)));
3818
3819 if Nkind (Parent (E)) = N_Package_Renaming_Declaration
3820 and then Renamed_Entity (E) = WEnt
3821 then
3822 -- The unlimited view is visible through use clause and
3823 -- renamings. There is no need to generate the error
3824 -- message here because Is_Visible_Through_Renamings
3825 -- takes care of generating the precise error message.
3826
3827 return;
3828
3829 elsif Nkind (Parent (E)) = N_Package_Specification then
3830
3831 -- The use clause may refer to a local package.
3832 -- Check all the enclosing scopes.
3833
3834 E2 := E;
3835 while E2 /= Standard_Standard and then E2 /= WEnt loop
3836 E2 := Scope (E2);
3837 end loop;
3838
3839 if E2 = WEnt then
3840 Error_Msg_N
3841 ("unlimited view visible through use clause", W);
3842 return;
3843 end if;
3844 end if;
3845 end if;
3846
3847 Next (Item);
3848 end loop;
3849
3850 -- Recursive call to check all the ancestors
3851
3852 if Is_Child_Spec (Unit (P)) then
3853 Check_Renamings (P => Parent_Spec (Unit (P)), W => W);
3854 end if;
3855 end Check_Renamings;
3856
3857 ---------------------------------------
3858 -- Check_Private_Limited_Withed_Unit --
3859 ---------------------------------------
3860
3861 procedure Check_Private_Limited_Withed_Unit (Item : Node_Id) is
3862 Curr_Parent : Node_Id;
3863 Child_Parent : Node_Id;
3864 Curr_Private : Boolean;
3865
3866 begin
3867 -- Compilation unit of the parent of the withed library unit
3868
3869 Child_Parent := Library_Unit (Item);
3870
3871 -- If the child unit is a public child, then locate its nearest
3872 -- private ancestor, if any, then Child_Parent will then be set to
3873 -- the parent of that ancestor.
3874
3875 if not Private_Present (Library_Unit (Item)) then
3876 while Present (Child_Parent)
3877 and then not Private_Present (Child_Parent)
3878 loop
3879 Child_Parent := Parent_Spec (Unit (Child_Parent));
3880 end loop;
3881
3882 if No (Child_Parent) then
3883 return;
3884 end if;
3885 end if;
3886
3887 Child_Parent := Parent_Spec (Unit (Child_Parent));
3888
3889 -- Traverse all the ancestors of the current compilation unit to
3890 -- check if it is a descendant of named library unit.
3891
3892 Curr_Parent := Parent (Item);
3893 Curr_Private := Private_Present (Curr_Parent);
3894
3895 while Present (Parent_Spec (Unit (Curr_Parent)))
3896 and then Curr_Parent /= Child_Parent
3897 loop
3898 Curr_Parent := Parent_Spec (Unit (Curr_Parent));
3899 Curr_Private := Curr_Private or else Private_Present (Curr_Parent);
3900 end loop;
3901
3902 if Curr_Parent /= Child_Parent then
3903 Error_Msg_N
3904 ("unit in with clause is private child unit!", Item);
3905 Error_Msg_NE
3906 ("\current unit must also have parent&!",
3907 Item, Defining_Unit_Name (Specification (Unit (Child_Parent))));
3908
3909 elsif Private_Present (Parent (Item))
3910 or else Curr_Private
3911 or else Private_Present (Item)
3912 or else Nkind (Unit (Parent (Item))) in
3913 N_Package_Body | N_Subprogram_Body | N_Subunit
3914 then
3915 -- Current unit is private, of descendant of a private unit
3916
3917 null;
3918
3919 else
3920 Error_Msg_NE
3921 ("current unit must also be private descendant of&",
3922 Item, Defining_Unit_Name (Specification (Unit (Child_Parent))));
3923 end if;
3924 end Check_Private_Limited_Withed_Unit;
3925
3926 --------------------------------
3927 -- Expand_Limited_With_Clause --
3928 --------------------------------
3929
3930 procedure Expand_Limited_With_Clause
3931 (Comp_Unit : Node_Id;
3932 Nam : Node_Id;
3933 N : Node_Id)
3934 is
3935 Loc : constant Source_Ptr := Sloc (Nam);
3936 Unum : Unit_Number_Type;
3937 Withn : Node_Id;
3938
3939 function Previous_Withed_Unit (W : Node_Id) return Boolean;
3940 -- Returns true if the context already includes a with_clause for
3941 -- this unit. If the with_clause is nonlimited, the unit is fully
3942 -- visible and an implicit limited_with should not be created. If
3943 -- there is already a limited_with clause for W, a second one is
3944 -- simply redundant.
3945
3946 --------------------------
3947 -- Previous_Withed_Unit --
3948 --------------------------
3949
3950 function Previous_Withed_Unit (W : Node_Id) return Boolean is
3951 Item : Node_Id;
3952
3953 begin
3954 -- A limited with_clause cannot appear in the same context_clause
3955 -- as a nonlimited with_clause which mentions the same library.
3956
3957 Item := First (Context_Items (Comp_Unit));
3958 while Present (Item) loop
3959 if Nkind (Item) = N_With_Clause
3960 and then Library_Unit (Item) = Library_Unit (W)
3961 then
3962 return True;
3963 end if;
3964
3965 Next (Item);
3966 end loop;
3967
3968 return False;
3969 end Previous_Withed_Unit;
3970
3971 -- Start of processing for Expand_Limited_With_Clause
3972
3973 begin
3974 if Nkind (Nam) = N_Identifier then
3975
3976 -- Create node for name of withed unit
3977
3978 Withn :=
3979 Make_With_Clause (Loc,
3980 Name => New_Copy (Nam));
3981
3982 else pragma Assert (Nkind (Nam) = N_Selected_Component);
3983 Withn :=
3984 Make_With_Clause (Loc,
3985 Name => Make_Selected_Component (Loc,
3986 Prefix => New_Copy_Tree (Prefix (Nam)),
3987 Selector_Name => New_Copy (Selector_Name (Nam))));
3988 Set_Parent (Withn, Parent (N));
3989 end if;
3990
3991 Set_First_Name (Withn);
3992 Set_Implicit_With (Withn);
3993 Set_Limited_Present (Withn);
3994
3995 Unum :=
3996 Load_Unit
3997 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
3998 Required => True,
3999 Subunit => False,
4000 Error_Node => Nam);
4001
4002 -- Do not generate a limited_with_clause on the current unit. This
4003 -- path is taken when a unit has a limited_with clause on one of its
4004 -- child units.
4005
4006 if Unum = Current_Sem_Unit then
4007 return;
4008 end if;
4009
4010 Set_Library_Unit (Withn, Cunit (Unum));
4011 Set_Corresponding_Spec
4012 (Withn, Specification (Unit (Cunit (Unum))));
4013
4014 if not Previous_Withed_Unit (Withn) then
4015 Prepend (Withn, Context_Items (Parent (N)));
4016 Mark_Rewrite_Insertion (Withn);
4017
4018 -- Add implicit limited_with_clauses for parents of child units
4019 -- mentioned in limited_with clauses.
4020
4021 if Nkind (Nam) = N_Selected_Component then
4022 Expand_Limited_With_Clause (Comp_Unit, Prefix (Nam), N);
4023 end if;
4024
4025 Analyze (Withn);
4026
4027 if not Limited_View_Installed (Withn) then
4028 Install_Limited_With_Clause (Withn);
4029 end if;
4030 end if;
4031 end Expand_Limited_With_Clause;
4032
4033 -- Start of processing for Install_Limited_Context_Clauses
4034
4035 begin
4036 Item := First (Context_Items (N));
4037 while Present (Item) loop
4038 if Nkind (Item) = N_With_Clause
4039 and then Limited_Present (Item)
4040 and then not Error_Posted (Item)
4041 then
4042 if Nkind (Name (Item)) = N_Selected_Component then
4043 Expand_Limited_With_Clause
4044 (Comp_Unit => N, Nam => Prefix (Name (Item)), N => Item);
4045 end if;
4046
4047 Check_Private_Limited_Withed_Unit (Item);
4048
4049 if not Implicit_With (Item) and then Is_Child_Spec (Unit (N)) then
4050 Check_Renamings (Parent_Spec (Unit (N)), Item);
4051 end if;
4052
4053 -- A unit may have a limited with on itself if it has a limited
4054 -- with_clause on one of its child units. In that case it is
4055 -- already being compiled and it makes no sense to install its
4056 -- limited view.
4057
4058 -- If the item is a limited_private_with_clause, install it if the
4059 -- current unit is a body or if it is a private child. Otherwise
4060 -- the private clause is installed before analyzing the private
4061 -- part of the current unit.
4062
4063 if Library_Unit (Item) /= Cunit (Current_Sem_Unit)
4064 and then not Limited_View_Installed (Item)
4065 and then
4066 not Is_Ancestor_Unit
4067 (Library_Unit (Item), Cunit (Current_Sem_Unit))
4068 then
4069 if not Private_Present (Item)
4070 or else Private_Present (N)
4071 or else Nkind (Unit (N)) in
4072 N_Package_Body | N_Subprogram_Body | N_Subunit
4073 then
4074 Install_Limited_With_Clause (Item);
4075 end if;
4076 end if;
4077 end if;
4078
4079 Next (Item);
4080 end loop;
4081
4082 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
4083 -- looking for incomplete subtype declarations of incomplete types
4084 -- visible through a limited with clause.
4085
4086 if Ada_Version >= Ada_2005
4087 and then Analyzed (N)
4088 and then Nkind (Unit (N)) = N_Package_Declaration
4089 then
4090 declare
4091 Decl : Node_Id;
4092 Def_Id : Entity_Id;
4093 Non_Lim_View : Entity_Id;
4094
4095 begin
4096 Decl := First (Visible_Declarations (Specification (Unit (N))));
4097 while Present (Decl) loop
4098 if Nkind (Decl) = N_Subtype_Declaration
4099 and then
4100 Ekind (Defining_Identifier (Decl)) = E_Incomplete_Subtype
4101 and then
4102 From_Limited_With (Defining_Identifier (Decl))
4103 then
4104 Def_Id := Defining_Identifier (Decl);
4105 Non_Lim_View := Non_Limited_View (Def_Id);
4106
4107 if not Is_Incomplete_Type (Non_Lim_View) then
4108
4109 -- Convert an incomplete subtype declaration into a
4110 -- corresponding nonlimited view subtype declaration.
4111 -- This is usually the case when analyzing a body that
4112 -- has regular with clauses, when the spec has limited
4113 -- ones.
4114
4115 -- If the nonlimited view is still incomplete, it is
4116 -- the dummy entry already created, and the declaration
4117 -- cannot be reanalyzed. This is the case when installing
4118 -- a parent unit that has limited with-clauses.
4119
4120 Set_Subtype_Indication (Decl,
4121 New_Occurrence_Of (Non_Lim_View, Sloc (Def_Id)));
4122 Set_Etype (Def_Id, Non_Lim_View);
4123 Mutate_Ekind
4124 (Def_Id, Subtype_Kind (Ekind (Non_Lim_View)));
4125 Set_Analyzed (Decl, False);
4126
4127 -- Reanalyze the declaration, suppressing the call to
4128 -- Enter_Name to avoid duplicate names.
4129
4130 Analyze_Subtype_Declaration
4131 (N => Decl,
4132 Skip => True);
4133 end if;
4134 end if;
4135
4136 Next (Decl);
4137 end loop;
4138 end;
4139 end if;
4140 end Install_Limited_Context_Clauses;
4141
4142 ---------------------
4143 -- Install_Parents --
4144 ---------------------
4145
4146 procedure Install_Parents
4147 (Lib_Unit : Node_Id;
4148 Is_Private : Boolean;
4149 Chain : Boolean := True)
4150 is
4151 P : Node_Id;
4152 E_Name : Entity_Id;
4153 P_Name : Entity_Id;
4154 P_Spec : Node_Id;
4155
4156 begin
4157 P := Unit (Parent_Spec (Lib_Unit));
4158 P_Name := Get_Parent_Entity (P);
4159
4160 if Etype (P_Name) = Any_Type then
4161 return;
4162 end if;
4163
4164 if Ekind (P_Name) = E_Generic_Package
4165 and then Nkind (Lib_Unit) not in N_Generic_Subprogram_Declaration
4166 | N_Generic_Package_Declaration
4167 | N_Generic_Renaming_Declaration
4168 then
4169 Error_Msg_N
4170 ("child of a generic package must be a generic unit", Lib_Unit);
4171
4172 elsif not Is_Package_Or_Generic_Package (P_Name) then
4173 Error_Msg_N
4174 ("parent unit must be package or generic package", Lib_Unit);
4175 raise Unrecoverable_Error;
4176
4177 elsif Present (Renamed_Object (P_Name)) then
4178 Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
4179 raise Unrecoverable_Error;
4180
4181 -- Verify that a child of an instance is itself an instance, or the
4182 -- renaming of one. Given that an instance that is a unit is replaced
4183 -- with a package declaration, check against the original node. The
4184 -- parent may be currently being instantiated, in which case it appears
4185 -- as a declaration, but the generic_parent is already established
4186 -- indicating that we deal with an instance.
4187
4188 elsif Nkind (Original_Node (P)) = N_Package_Instantiation then
4189 if Nkind (Lib_Unit) in N_Renaming_Declaration
4190 or else Nkind (Original_Node (Lib_Unit)) in N_Generic_Instantiation
4191 or else
4192 (Nkind (Lib_Unit) = N_Package_Declaration
4193 and then Present (Generic_Parent (Specification (Lib_Unit))))
4194 then
4195 null;
4196 else
4197 Error_Msg_N
4198 ("child of an instance must be an instance or renaming",
4199 Lib_Unit);
4200 end if;
4201 end if;
4202
4203 -- This is the recursive call that ensures all parents are loaded
4204
4205 if Is_Child_Spec (P) then
4206 Install_Parents
4207 (Lib_Unit => P,
4208 Is_Private =>
4209 Is_Private or else Private_Present (Parent (Lib_Unit)),
4210 Chain => Chain);
4211 end if;
4212
4213 -- Now we can install the context for this parent
4214
4215 Install_Context_Clauses (Parent_Spec (Lib_Unit), Chain);
4216 Install_Limited_Context_Clauses (Parent_Spec (Lib_Unit));
4217 Install_Siblings (P_Name, Parent (Lib_Unit));
4218
4219 -- The child unit is in the declarative region of the parent. The parent
4220 -- must therefore appear in the scope stack and be visible, as when
4221 -- compiling the corresponding body. If the child unit is private or it
4222 -- is a package body, private declarations must be accessible as well.
4223 -- Use declarations in the parent must also be installed. Finally, other
4224 -- child units of the same parent that are in the context are
4225 -- immediately visible.
4226
4227 -- Find entity for compilation unit, and set its private descendant
4228 -- status as needed. Indicate that it is a compilation unit, which is
4229 -- redundant in general, but needed if this is a generated child spec
4230 -- for a child body without previous spec.
4231
4232 E_Name := Defining_Entity (Lib_Unit);
4233
4234 Set_Is_Child_Unit (E_Name);
4235 Set_Is_Compilation_Unit (E_Name);
4236
4237 Set_Is_Private_Descendant (E_Name,
4238 Is_Private_Descendant (P_Name)
4239 or else Private_Present (Parent (Lib_Unit)));
4240
4241 P_Spec := Package_Specification (P_Name);
4242 Push_Scope (P_Name);
4243
4244 -- Save current visibility of unit
4245
4246 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
4247 Is_Immediately_Visible (P_Name);
4248 Set_Is_Immediately_Visible (P_Name);
4249 Install_Visible_Declarations (P_Name);
4250 Set_Use (Visible_Declarations (P_Spec));
4251
4252 -- If the parent is a generic unit, its formal part may contain formal
4253 -- packages and use clauses for them.
4254
4255 if Ekind (P_Name) = E_Generic_Package then
4256 Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
4257 end if;
4258
4259 if Is_Private or else Private_Present (Parent (Lib_Unit)) then
4260 Install_Private_Declarations (P_Name);
4261 Install_Private_With_Clauses (P_Name);
4262 Set_Use (Private_Declarations (P_Spec));
4263 end if;
4264 end Install_Parents;
4265
4266 ----------------------------------
4267 -- Install_Private_With_Clauses --
4268 ----------------------------------
4269
4270 procedure Install_Private_With_Clauses (P : Entity_Id) is
4271 Decl : constant Node_Id := Unit_Declaration_Node (P);
4272 Item : Node_Id;
4273
4274 begin
4275 if Debug_Flag_I then
4276 Write_Str ("install private with clauses of ");
4277 Write_Name (Chars (P));
4278 Write_Eol;
4279 end if;
4280
4281 if Nkind (Parent (Decl)) = N_Compilation_Unit then
4282 Item := First (Context_Items (Parent (Decl)));
4283 while Present (Item) loop
4284 if Nkind (Item) = N_With_Clause
4285 and then Private_Present (Item)
4286 then
4287 -- If the unit is an ancestor of the current one, it is the
4288 -- case of a private limited with clause on a child unit, and
4289 -- the compilation of one of its descendants, In that case the
4290 -- limited view is errelevant.
4291
4292 if Limited_Present (Item) then
4293 if not Limited_View_Installed (Item)
4294 and then
4295 not Is_Ancestor_Unit (Library_Unit (Item),
4296 Cunit (Current_Sem_Unit))
4297 then
4298 Install_Limited_With_Clause (Item);
4299 end if;
4300 else
4301 Install_With_Clause (Item, Private_With_OK => True);
4302 end if;
4303 end if;
4304
4305 Next (Item);
4306 end loop;
4307 end if;
4308 end Install_Private_With_Clauses;
4309
4310 ----------------------
4311 -- Install_Siblings --
4312 ----------------------
4313
4314 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
4315 Item : Node_Id;
4316 Id : Entity_Id;
4317 Prev : Entity_Id;
4318
4319 begin
4320 -- Iterate over explicit with clauses, and check whether the scope of
4321 -- each entity is an ancestor of the current unit, in which case it is
4322 -- immediately visible.
4323
4324 Item := First (Context_Items (N));
4325 while Present (Item) loop
4326
4327 -- Do not install private_with_clauses declaration, unless unit
4328 -- is itself a private child unit, or is a body. Note that for a
4329 -- subprogram body the private_with_clause does not take effect
4330 -- until after the specification.
4331
4332 if Nkind (Item) /= N_With_Clause
4333 or else Implicit_With (Item)
4334 or else Limited_Present (Item)
4335 or else Error_Posted (Item)
4336
4337 -- Skip processing malformed trees
4338
4339 or else (Try_Semantics
4340 and then Nkind (Name (Item)) not in N_Has_Entity)
4341 then
4342 null;
4343
4344 elsif not Private_Present (Item)
4345 or else Private_Present (N)
4346 or else Nkind (Unit (N)) = N_Package_Body
4347 then
4348 Id := Entity (Name (Item));
4349
4350 if Is_Child_Unit (Id)
4351 and then Is_Ancestor_Package (Scope (Id), U_Name)
4352 then
4353 Set_Is_Immediately_Visible (Id);
4354
4355 -- Check for the presence of another unit in the context that
4356 -- may be inadvertently hidden by the child.
4357
4358 Prev := Current_Entity (Id);
4359
4360 if Present (Prev)
4361 and then Is_Immediately_Visible (Prev)
4362 and then not Is_Child_Unit (Prev)
4363 then
4364 declare
4365 Clause : Node_Id;
4366
4367 begin
4368 Clause := First (Context_Items (N));
4369 while Present (Clause) loop
4370 if Nkind (Clause) = N_With_Clause
4371 and then Entity (Name (Clause)) = Prev
4372 then
4373 Error_Msg_NE
4374 ("child unit& hides compilation unit " &
4375 "with the same name??",
4376 Name (Item), Id);
4377 exit;
4378 end if;
4379
4380 Next (Clause);
4381 end loop;
4382 end;
4383 end if;
4384
4385 -- The With_Clause may be on a grandchild or one of its further
4386 -- descendants, which makes a child immediately visible. Examine
4387 -- ancestry to determine whether such a child exists. For example,
4388 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4389 -- is immediately visible.
4390
4391 elsif Is_Child_Unit (Id) then
4392 declare
4393 Par : Entity_Id;
4394
4395 begin
4396 Par := Scope (Id);
4397 while Is_Child_Unit (Par) loop
4398 if Is_Ancestor_Package (Scope (Par), U_Name) then
4399 Set_Is_Immediately_Visible (Par);
4400 exit;
4401 end if;
4402
4403 Par := Scope (Par);
4404 end loop;
4405 end;
4406 end if;
4407
4408 -- If the item is a private with-clause on a child unit, the parent
4409 -- may have been installed already, but the child unit must remain
4410 -- invisible until installed in a private part or body, unless there
4411 -- is already a regular with_clause for it in the current unit.
4412
4413 elsif Private_Present (Item) then
4414 Id := Entity (Name (Item));
4415
4416 if Is_Child_Unit (Id) then
4417 declare
4418 Clause : Node_Id;
4419
4420 function In_Context return Boolean;
4421 -- Scan context of current unit, to check whether there is
4422 -- a with_clause on the same unit as a private with-clause
4423 -- on a parent, in which case child unit is visible. If the
4424 -- unit is a grandchild, the same applies to its parent.
4425
4426 ----------------
4427 -- In_Context --
4428 ----------------
4429
4430 function In_Context return Boolean is
4431 begin
4432 Clause :=
4433 First (Context_Items (Cunit (Current_Sem_Unit)));
4434 while Present (Clause) loop
4435 if Nkind (Clause) = N_With_Clause
4436 and then Comes_From_Source (Clause)
4437 and then Is_Entity_Name (Name (Clause))
4438 and then not Private_Present (Clause)
4439 then
4440 if Entity (Name (Clause)) = Id
4441 or else
4442 (Nkind (Name (Clause)) = N_Expanded_Name
4443 and then Entity (Prefix (Name (Clause))) = Id)
4444 then
4445 return True;
4446 end if;
4447 end if;
4448
4449 Next (Clause);
4450 end loop;
4451
4452 return False;
4453 end In_Context;
4454
4455 begin
4456 Set_Is_Visible_Lib_Unit (Id, In_Context);
4457 end;
4458 end if;
4459 end if;
4460
4461 Next (Item);
4462 end loop;
4463 end Install_Siblings;
4464
4465 ---------------------------------
4466 -- Install_Limited_With_Clause --
4467 ---------------------------------
4468
4469 procedure Install_Limited_With_Clause (N : Node_Id) is
4470 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
4471 E : Entity_Id;
4472 P : Entity_Id;
4473 Is_Child_Package : Boolean := False;
4474 Lim_Header : Entity_Id;
4475 Lim_Typ : Entity_Id;
4476
4477 procedure Check_Body_Required;
4478 -- A unit mentioned in a limited with_clause may not be mentioned in
4479 -- a regular with_clause, but must still be included in the current
4480 -- partition. We need to determine whether the unit needs a body, so
4481 -- that the binder can determine the name of the file to be compiled.
4482 -- Checking whether a unit needs a body can be done without semantic
4483 -- analysis, by examining the nature of the declarations in the package.
4484
4485 function Has_Limited_With_Clause
4486 (C_Unit : Entity_Id;
4487 Pack : Entity_Id) return Boolean;
4488 -- Determine whether any package in the ancestor chain starting with
4489 -- C_Unit has a limited with clause for package Pack.
4490
4491 -------------------------
4492 -- Check_Body_Required --
4493 -------------------------
4494
4495 procedure Check_Body_Required is
4496 PA : constant List_Id :=
4497 Pragmas_After (Aux_Decls_Node (Parent (P_Unit)));
4498
4499 procedure Check_Declarations (Spec : Node_Id);
4500 -- Recursive procedure that does the work and checks nested packages
4501
4502 ------------------------
4503 -- Check_Declarations --
4504 ------------------------
4505
4506 procedure Check_Declarations (Spec : Node_Id) is
4507 Decl : Node_Id;
4508 Incomplete_Decls : constant Elist_Id := New_Elmt_List;
4509
4510 Subp_List : constant Elist_Id := New_Elmt_List;
4511
4512 procedure Check_Pragma_Import (P : Node_Id);
4513 -- If a pragma import applies to a previous subprogram, the
4514 -- enclosing unit may not need a body. The processing is syntactic
4515 -- and does not require a declaration to be analyzed. The code
4516 -- below also handles pragma Import when applied to a subprogram
4517 -- that renames another. In this case the pragma applies to the
4518 -- renamed entity.
4519 --
4520 -- Chains of multiple renames are not handled by the code below.
4521 -- It is probably impossible to handle all cases without proper
4522 -- name resolution. In such cases the algorithm is conservative
4523 -- and will indicate that a body is needed???
4524
4525 -------------------------
4526 -- Check_Pragma_Import --
4527 -------------------------
4528
4529 procedure Check_Pragma_Import (P : Node_Id) is
4530 Arg : Node_Id;
4531 Prev_Id : Elmt_Id;
4532 Subp_Id : Elmt_Id;
4533 Imported : Node_Id;
4534
4535 procedure Remove_Homonyms (E : Node_Id);
4536 -- Make one pass over list of subprograms. Called again if
4537 -- subprogram is a renaming. E is known to be an identifier.
4538
4539 ---------------------
4540 -- Remove_Homonyms --
4541 ---------------------
4542
4543 procedure Remove_Homonyms (E : Node_Id) is
4544 R : Entity_Id := Empty;
4545 -- Name of renamed entity, if any
4546
4547 begin
4548 Subp_Id := First_Elmt (Subp_List);
4549 while Present (Subp_Id) loop
4550 if Chars (Node (Subp_Id)) = Chars (E) then
4551 if Nkind (Parent (Parent (Node (Subp_Id))))
4552 /= N_Subprogram_Renaming_Declaration
4553 then
4554 Prev_Id := Subp_Id;
4555 Next_Elmt (Subp_Id);
4556 Remove_Elmt (Subp_List, Prev_Id);
4557 else
4558 R := Name (Parent (Parent (Node (Subp_Id))));
4559 exit;
4560 end if;
4561 else
4562 Next_Elmt (Subp_Id);
4563 end if;
4564 end loop;
4565
4566 if Present (R) then
4567 if Nkind (R) = N_Identifier then
4568 Remove_Homonyms (R);
4569
4570 elsif Nkind (R) = N_Selected_Component then
4571 Remove_Homonyms (Selector_Name (R));
4572
4573 -- Renaming of attribute
4574
4575 else
4576 null;
4577 end if;
4578 end if;
4579 end Remove_Homonyms;
4580
4581 -- Start of processing for Check_Pragma_Import
4582
4583 begin
4584 -- Find name of entity in Import pragma. We have not analyzed
4585 -- the construct, so we must guard against syntax errors.
4586
4587 Arg := Next (First (Pragma_Argument_Associations (P)));
4588
4589 if No (Arg)
4590 or else Nkind (Expression (Arg)) /= N_Identifier
4591 then
4592 return;
4593 else
4594 Imported := Expression (Arg);
4595 end if;
4596
4597 Remove_Homonyms (Imported);
4598 end Check_Pragma_Import;
4599
4600 -- Start of processing for Check_Declarations
4601
4602 begin
4603 -- Search for Elaborate Body pragma
4604
4605 Decl := First (Visible_Declarations (Spec));
4606 while Present (Decl)
4607 and then Nkind (Decl) = N_Pragma
4608 loop
4609 if Get_Pragma_Id (Decl) = Pragma_Elaborate_Body then
4610 Set_Body_Required (Library_Unit (N));
4611 return;
4612 end if;
4613
4614 Next (Decl);
4615 end loop;
4616
4617 -- Look for declarations that require the presence of a body. We
4618 -- have already skipped pragmas at the start of the list.
4619
4620 while Present (Decl) loop
4621
4622 -- Subprogram that comes from source means body may be needed.
4623 -- Save for subsequent examination of import pragmas.
4624
4625 if Comes_From_Source (Decl)
4626 and then (Nkind (Decl) in N_Subprogram_Declaration
4627 | N_Subprogram_Renaming_Declaration
4628 | N_Generic_Subprogram_Declaration)
4629 then
4630 Append_Elmt (Defining_Entity (Decl), Subp_List);
4631
4632 -- Package declaration of generic package declaration. We need
4633 -- to recursively examine nested declarations.
4634
4635 elsif Nkind (Decl) in N_Package_Declaration
4636 | N_Generic_Package_Declaration
4637 then
4638 Check_Declarations (Specification (Decl));
4639
4640 elsif Nkind (Decl) = N_Pragma
4641 and then Pragma_Name (Decl) = Name_Import
4642 then
4643 Check_Pragma_Import (Decl);
4644 end if;
4645
4646 Next (Decl);
4647 end loop;
4648
4649 -- Same set of tests for private part. In addition to subprograms
4650 -- detect the presence of Taft Amendment types (incomplete types
4651 -- completed in the body).
4652
4653 Decl := First (Private_Declarations (Spec));
4654 while Present (Decl) loop
4655 if Comes_From_Source (Decl)
4656 and then Nkind (Decl) in N_Subprogram_Declaration
4657 | N_Subprogram_Renaming_Declaration
4658 | N_Generic_Subprogram_Declaration
4659 then
4660 Append_Elmt (Defining_Entity (Decl), Subp_List);
4661
4662 elsif Nkind (Decl) in N_Package_Declaration
4663 | N_Generic_Package_Declaration
4664 then
4665 Check_Declarations (Specification (Decl));
4666
4667 -- Collect incomplete type declarations for separate pass
4668
4669 elsif Nkind (Decl) = N_Incomplete_Type_Declaration then
4670 Append_Elmt (Decl, Incomplete_Decls);
4671
4672 elsif Nkind (Decl) = N_Pragma
4673 and then Pragma_Name (Decl) = Name_Import
4674 then
4675 Check_Pragma_Import (Decl);
4676 end if;
4677
4678 Next (Decl);
4679 end loop;
4680
4681 -- Now check incomplete declarations to locate Taft amendment
4682 -- types. This can be done by examining the defining identifiers
4683 -- of type declarations without real semantic analysis.
4684
4685 declare
4686 Inc : Elmt_Id;
4687
4688 begin
4689 Inc := First_Elmt (Incomplete_Decls);
4690 while Present (Inc) loop
4691 Decl := Next (Node (Inc));
4692 while Present (Decl) loop
4693 if Nkind (Decl) = N_Full_Type_Declaration
4694 and then Chars (Defining_Identifier (Decl)) =
4695 Chars (Defining_Identifier (Node (Inc)))
4696 then
4697 exit;
4698 end if;
4699
4700 Next (Decl);
4701 end loop;
4702
4703 -- If no completion, this is a TAT, and a body is needed
4704
4705 if No (Decl) then
4706 Set_Body_Required (Library_Unit (N));
4707 return;
4708 end if;
4709
4710 Next_Elmt (Inc);
4711 end loop;
4712 end;
4713
4714 -- Finally, check whether there are subprograms that still require
4715 -- a body, i.e. are not renamings or null.
4716
4717 if not Is_Empty_Elmt_List (Subp_List) then
4718 declare
4719 Subp_Id : Elmt_Id;
4720 Spec : Node_Id;
4721
4722 begin
4723 Subp_Id := First_Elmt (Subp_List);
4724 Spec := Parent (Node (Subp_Id));
4725
4726 while Present (Subp_Id) loop
4727 if Nkind (Parent (Spec))
4728 = N_Subprogram_Renaming_Declaration
4729 then
4730 null;
4731
4732 elsif Nkind (Spec) = N_Procedure_Specification
4733 and then Null_Present (Spec)
4734 then
4735 null;
4736
4737 else
4738 Set_Body_Required (Library_Unit (N));
4739 return;
4740 end if;
4741
4742 Next_Elmt (Subp_Id);
4743 end loop;
4744 end;
4745 end if;
4746 end Check_Declarations;
4747
4748 -- Start of processing for Check_Body_Required
4749
4750 begin
4751 -- If this is an imported package (Java and CIL usage) no body is
4752 -- needed. Scan list of pragmas that may follow a compilation unit
4753 -- to look for a relevant pragma Import.
4754
4755 if Present (PA) then
4756 declare
4757 Prag : Node_Id;
4758
4759 begin
4760 Prag := First (PA);
4761 while Present (Prag) loop
4762 if Nkind (Prag) = N_Pragma
4763 and then Get_Pragma_Id (Prag) = Pragma_Import
4764 then
4765 return;
4766 end if;
4767
4768 Next (Prag);
4769 end loop;
4770 end;
4771 end if;
4772
4773 Check_Declarations (Specification (P_Unit));
4774 end Check_Body_Required;
4775
4776 -----------------------------
4777 -- Has_Limited_With_Clause --
4778 -----------------------------
4779
4780 function Has_Limited_With_Clause
4781 (C_Unit : Entity_Id;
4782 Pack : Entity_Id) return Boolean
4783 is
4784 Par : Entity_Id;
4785 Par_Unit : Node_Id;
4786
4787 begin
4788 Par := C_Unit;
4789 while Present (Par) loop
4790 if Ekind (Par) /= E_Package then
4791 exit;
4792 end if;
4793
4794 -- Retrieve the Compilation_Unit node for Par and determine if
4795 -- its context clauses contain a limited with for Pack.
4796
4797 Par_Unit := Parent (Parent (Parent (Par)));
4798
4799 if Nkind (Par_Unit) = N_Package_Declaration then
4800 Par_Unit := Parent (Par_Unit);
4801 end if;
4802
4803 if Has_With_Clause (Par_Unit, Pack, True) then
4804 return True;
4805 end if;
4806
4807 -- If there are more ancestors, climb up the tree, otherwise we
4808 -- are done.
4809
4810 if Is_Child_Unit (Par) then
4811 Par := Scope (Par);
4812 else
4813 exit;
4814 end if;
4815 end loop;
4816
4817 return False;
4818 end Has_Limited_With_Clause;
4819
4820 -- Start of processing for Install_Limited_With_Clause
4821
4822 begin
4823 pragma Assert (not Limited_View_Installed (N));
4824
4825 -- In case of limited with_clause on subprograms, generics, instances,
4826 -- or renamings, the corresponding error was previously posted and we
4827 -- have nothing to do here. If the file is missing altogether, it has
4828 -- no source location.
4829
4830 if Nkind (P_Unit) /= N_Package_Declaration
4831 or else Sloc (P_Unit) = No_Location
4832 then
4833 return;
4834 end if;
4835
4836 P := Defining_Unit_Name (Specification (P_Unit));
4837
4838 -- Handle child packages
4839
4840 if Nkind (P) = N_Defining_Program_Unit_Name then
4841 Is_Child_Package := True;
4842 P := Defining_Identifier (P);
4843 end if;
4844
4845 -- Do not install the limited-view if the context of the unit is already
4846 -- available through a regular with clause.
4847
4848 if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4849 and then Has_With_Clause (Cunit (Current_Sem_Unit), P)
4850 then
4851 return;
4852 end if;
4853
4854 -- Do not install the limited-view if the full-view is already visible
4855 -- through renaming declarations.
4856
4857 if Is_Visible_Through_Renamings (P, N) then
4858 return;
4859 end if;
4860
4861 -- Do not install the limited view if this is the unit being analyzed.
4862 -- This unusual case will happen when a unit has a limited_with clause
4863 -- on one of its children. The compilation of the child forces the load
4864 -- of the parent which tries to install the limited view of the child
4865 -- again. Installing the limited view must also be disabled when
4866 -- compiling the body of the child unit.
4867
4868 if P = Cunit_Entity (Current_Sem_Unit)
4869 or else (Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4870 and then P = Main_Unit_Entity
4871 and then Is_Ancestor_Unit
4872 (Cunit (Main_Unit), Cunit (Current_Sem_Unit)))
4873 then
4874 return;
4875 end if;
4876
4877 -- This scenario is similar to the one above, the difference is that the
4878 -- compilation of sibling Par.Sib forces the load of parent Par which
4879 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4880 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4881 -- nonlimited views of all entities from Lim_Pack.
4882
4883 -- limited with Lim_Pack; -- [1]
4884 -- package Par is ... package Lim_Pack is ...
4885
4886 -- with Lim_Pack; -- [2]
4887 -- package Par.Sib is ... package body Par.Sib is ...
4888
4889 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4890 -- Sem_Unit is the body of Par.Sib.
4891
4892 if Ekind (P) = E_Package
4893 and then Ekind (Main_Unit_Entity) = E_Package
4894 and then Is_Child_Unit (Main_Unit_Entity)
4895
4896 -- The body has a regular with clause
4897
4898 and then Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4899 and then Has_With_Clause (Cunit (Current_Sem_Unit), P)
4900
4901 -- One of the ancestors has a limited with clause
4902
4903 and then Nkind (Parent (Parent (Main_Unit_Entity))) =
4904 N_Package_Specification
4905 and then Has_Limited_With_Clause (Scope (Main_Unit_Entity), P)
4906 then
4907 return;
4908 end if;
4909
4910 -- A common use of the limited-with is to have a limited-with in the
4911 -- package spec, and a normal with in its package body. For example:
4912
4913 -- limited with X; -- [1]
4914 -- package A is ...
4915
4916 -- with X; -- [2]
4917 -- package body A is ...
4918
4919 -- The compilation of A's body installs the context clauses found at [2]
4920 -- and then the context clauses of its specification (found at [1]). As
4921 -- a consequence, at [1] the specification of X has been analyzed and it
4922 -- is immediately visible. According to the semantics of limited-with
4923 -- context clauses we don't install the limited view because the full
4924 -- view of X supersedes its limited view.
4925
4926 if Analyzed (P_Unit)
4927 and then
4928 (Is_Immediately_Visible (P)
4929 or else (Is_Child_Package and then Is_Visible_Lib_Unit (P)))
4930 then
4931
4932 -- The presence of both the limited and the analyzed nonlimited view
4933 -- may also be an error, such as an illegal context for a limited
4934 -- with_clause. In that case, do not process the context item at all.
4935
4936 if Error_Posted (N) then
4937 return;
4938 end if;
4939
4940 if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
4941 declare
4942 Item : Node_Id;
4943 begin
4944 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
4945 while Present (Item) loop
4946 if Nkind (Item) = N_With_Clause
4947 and then Comes_From_Source (Item)
4948 and then Entity (Name (Item)) = P
4949 then
4950 return;
4951 end if;
4952
4953 Next (Item);
4954 end loop;
4955 end;
4956
4957 -- If this is a child body, assume that the nonlimited with_clause
4958 -- appears in an ancestor. Could be refined ???
4959
4960 if Is_Child_Unit
4961 (Defining_Entity
4962 (Unit (Library_Unit (Cunit (Current_Sem_Unit)))))
4963 then
4964 return;
4965 end if;
4966
4967 else
4968
4969 -- If in package declaration, nonlimited view brought in from
4970 -- parent unit or some error condition.
4971
4972 return;
4973 end if;
4974 end if;
4975
4976 if Debug_Flag_I then
4977 Write_Str ("install limited view of ");
4978 Write_Name (Chars (P));
4979 Write_Eol;
4980 end if;
4981
4982 -- If the unit has not been analyzed and the limited view has not been
4983 -- already installed then we install it.
4984
4985 if not Analyzed (P_Unit) then
4986 if not In_Chain (P) then
4987
4988 -- Minimum decoration
4989
4990 Mutate_Ekind (P, E_Package);
4991 Set_Etype (P, Standard_Void_Type);
4992 Set_Scope (P, Standard_Standard);
4993 Set_Is_Visible_Lib_Unit (P);
4994
4995 if Is_Child_Package then
4996 Set_Is_Child_Unit (P);
4997 Set_Scope (P, Defining_Entity (Unit (Parent_Spec (P_Unit))));
4998 end if;
4999
5000 -- Place entity on visibility structure
5001
5002 Set_Homonym (P, Current_Entity (P));
5003 Set_Current_Entity (P);
5004
5005 if Debug_Flag_I then
5006 Write_Str (" (homonym) chain ");
5007 Write_Name (Chars (P));
5008 Write_Eol;
5009 end if;
5010
5011 -- Install the incomplete view. The first element of the limited
5012 -- view is a header (an E_Package entity) used to reference the
5013 -- first shadow entity in the private part of the package.
5014
5015 Lim_Header := Limited_View (P);
5016 Lim_Typ := First_Entity (Lim_Header);
5017
5018 while Present (Lim_Typ)
5019 and then Lim_Typ /= First_Private_Entity (Lim_Header)
5020 loop
5021 Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
5022 Set_Current_Entity (Lim_Typ);
5023
5024 if Debug_Flag_I then
5025 Write_Str (" (homonym) chain ");
5026 Write_Name (Chars (Lim_Typ));
5027 Write_Eol;
5028 end if;
5029
5030 Next_Entity (Lim_Typ);
5031 end loop;
5032 end if;
5033
5034 -- If the unit appears in a previous regular with_clause, the regular
5035 -- entities of the public part of the withed package must be replaced
5036 -- by the shadow ones.
5037
5038 -- This code must be kept synchronized with the code that replaces the
5039 -- shadow entities by the real entities (see body of Remove_Limited
5040 -- With_Clause); otherwise the contents of the homonym chains are not
5041 -- consistent.
5042
5043 else
5044 -- Hide all the type entities of the public part of the package to
5045 -- avoid its usage. This is needed to cover all the subtype decla-
5046 -- rations because we do not remove them from the homonym chain.
5047
5048 E := First_Entity (P);
5049 while Present (E) and then E /= First_Private_Entity (P) loop
5050 if Is_Type (E) then
5051 Set_Was_Hidden (E, Is_Hidden (E));
5052 Set_Is_Hidden (E);
5053 end if;
5054
5055 Next_Entity (E);
5056 end loop;
5057
5058 -- Replace the real entities by the shadow entities of the limited
5059 -- view. The first element of the limited view is a header that is
5060 -- used to reference the first shadow entity in the private part
5061 -- of the package. Successive elements are the limited views of the
5062 -- type (including regular incomplete types) declared in the package.
5063
5064 Lim_Header := Limited_View (P);
5065
5066 Lim_Typ := First_Entity (Lim_Header);
5067 while Present (Lim_Typ)
5068 and then Lim_Typ /= First_Private_Entity (Lim_Header)
5069 loop
5070 pragma Assert (not In_Chain (Lim_Typ));
5071
5072 -- Do not unchain nested packages and child units
5073
5074 if Ekind (Lim_Typ) /= E_Package
5075 and then not Is_Child_Unit (Lim_Typ)
5076 then
5077 declare
5078 Prev : Entity_Id;
5079
5080 begin
5081 Prev := Current_Entity (Lim_Typ);
5082 E := Prev;
5083
5084 -- Replace E in the homonyms list, so that the limited view
5085 -- becomes available.
5086
5087 -- If the nonlimited view is a record with an anonymous
5088 -- self-referential component, the analysis of the record
5089 -- declaration creates an incomplete type with the same name
5090 -- in order to define an internal access type. The visible
5091 -- entity is now the incomplete type, and that is the one to
5092 -- replace in the visibility structure.
5093
5094 if E = Non_Limited_View (Lim_Typ)
5095 or else
5096 (Ekind (E) = E_Incomplete_Type
5097 and then Full_View (E) = Non_Limited_View (Lim_Typ))
5098 then
5099 Set_Homonym (Lim_Typ, Homonym (Prev));
5100 Set_Current_Entity (Lim_Typ);
5101
5102 else
5103 loop
5104 E := Homonym (Prev);
5105
5106 -- E may have been removed when installing a previous
5107 -- limited_with_clause.
5108
5109 exit when No (E);
5110 exit when E = Non_Limited_View (Lim_Typ);
5111 Prev := Homonym (Prev);
5112 end loop;
5113
5114 if Present (E) then
5115 Set_Homonym (Lim_Typ, Homonym (Homonym (Prev)));
5116 Set_Homonym (Prev, Lim_Typ);
5117 end if;
5118 end if;
5119 end;
5120
5121 if Debug_Flag_I then
5122 Write_Str (" (homonym) chain ");
5123 Write_Name (Chars (Lim_Typ));
5124 Write_Eol;
5125 end if;
5126 end if;
5127
5128 Next_Entity (Lim_Typ);
5129 end loop;
5130 end if;
5131
5132 -- The package must be visible while the limited-with clause is active
5133 -- because references to the type P.T must resolve in the usual way.
5134 -- In addition, we remember that the limited-view has been installed to
5135 -- uninstall it at the point of context removal.
5136
5137 Set_Is_Immediately_Visible (P);
5138 Set_Limited_View_Installed (N);
5139
5140 -- If unit has not been analyzed in some previous context, check
5141 -- (imperfectly ???) whether it might need a body.
5142
5143 if not Analyzed (P_Unit) then
5144 Check_Body_Required;
5145 end if;
5146
5147 -- If the package in the limited_with clause is a child unit, the clause
5148 -- is unanalyzed and appears as a selected component. Recast it as an
5149 -- expanded name so that the entity can be properly set. Use entity of
5150 -- parent, if available, for higher ancestors in the name.
5151
5152 if Nkind (Name (N)) = N_Selected_Component then
5153 declare
5154 Nam : Node_Id;
5155 Ent : Entity_Id;
5156
5157 begin
5158 Nam := Name (N);
5159 Ent := P;
5160 while Nkind (Nam) = N_Selected_Component
5161 and then Present (Ent)
5162 loop
5163 Change_Selected_Component_To_Expanded_Name (Nam);
5164
5165 -- Set entity of parent identifiers if the unit is a child
5166 -- unit. This ensures that the tree is properly formed from
5167 -- semantic point of view. The unit entities are not fully
5168 -- analyzed, so we need to follow unit links in the tree.
5169
5170 Set_Entity (Nam, Ent);
5171
5172 Nam := Prefix (Nam);
5173 Ent :=
5174 Defining_Entity
5175 (Unit (Parent_Spec (Unit_Declaration_Node (Ent))));
5176
5177 -- Set entity of last ancestor
5178
5179 if Nkind (Nam) = N_Identifier then
5180 Set_Entity (Nam, Ent);
5181 end if;
5182 end loop;
5183 end;
5184 end if;
5185
5186 Set_Entity (Name (N), P);
5187 Set_From_Limited_With (P);
5188 end Install_Limited_With_Clause;
5189
5190 -------------------------
5191 -- Install_With_Clause --
5192 -------------------------
5193
5194 procedure Install_With_Clause
5195 (With_Clause : Node_Id;
5196 Private_With_OK : Boolean := False)
5197 is
5198 Uname : constant Entity_Id := Entity (Name (With_Clause));
5199 P : constant Entity_Id := Scope (Uname);
5200
5201 begin
5202 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5203 -- compiling a package declaration and the Private_With_OK flag was not
5204 -- set by the caller. These declarations will be installed later (before
5205 -- analyzing the private part of the package).
5206
5207 if Private_Present (With_Clause)
5208 and then Nkind (Unit (Parent (With_Clause)))
5209 in N_Package_Declaration | N_Generic_Package_Declaration
5210 and then not Private_With_OK
5211 then
5212 return;
5213 end if;
5214
5215 if Debug_Flag_I then
5216 if Private_Present (With_Clause) then
5217 Write_Str ("install private withed unit ");
5218 else
5219 Write_Str ("install withed unit ");
5220 end if;
5221
5222 Write_Name (Chars (Uname));
5223 Write_Eol;
5224 end if;
5225
5226 -- We do not apply the restrictions to an internal unit unless we are
5227 -- compiling the internal unit as a main unit. This check is also
5228 -- skipped for dummy units (for missing packages).
5229
5230 if Sloc (Uname) /= No_Location
5231 and then (not Is_Internal_Unit (Current_Sem_Unit)
5232 or else Current_Sem_Unit = Main_Unit)
5233 then
5234 Check_Restricted_Unit
5235 (Unit_Name (Get_Source_Unit (Uname)), With_Clause);
5236 end if;
5237
5238 if P /= Standard_Standard then
5239
5240 -- If the unit is not analyzed after analysis of the with clause and
5241 -- it is an instantiation then it awaits a body and is the main unit.
5242 -- Its appearance in the context of some other unit indicates a
5243 -- circular dependency (DEC suite perversity).
5244
5245 if not Analyzed (Uname)
5246 and then Nkind (Parent (Uname)) = N_Package_Instantiation
5247 then
5248 Error_Msg_N
5249 ("instantiation depends on itself", Name (With_Clause));
5250
5251 elsif not Analyzed (Uname)
5252 and then Is_Internal_Unit (Current_Sem_Unit)
5253 and then not Is_Visible_Lib_Unit (Uname)
5254 and then No (Scope (Uname))
5255 then
5256 if Is_Predefined_Unit (Current_Sem_Unit) then
5257 Error_Msg_N
5258 ("predefined unit depends on itself", Name (With_Clause));
5259 else
5260 Error_Msg_N
5261 ("GNAT-defined unit depends on itself", Name (With_Clause));
5262 end if;
5263 return;
5264
5265 elsif not Is_Visible_Lib_Unit (Uname) then
5266
5267 -- Abandon processing in case of previous errors
5268
5269 if No (Scope (Uname)) then
5270 Check_Error_Detected;
5271 return;
5272 end if;
5273
5274 Set_Is_Visible_Lib_Unit (Uname);
5275
5276 -- If the unit is a wrapper package for a compilation unit that is
5277 -- a subprogram instance, indicate that the instance itself is a
5278 -- visible unit. This is necessary if the instance is inlined.
5279
5280 if Is_Wrapper_Package (Uname) then
5281 Set_Is_Visible_Lib_Unit (Related_Instance (Uname));
5282 end if;
5283
5284 -- If the child unit appears in the context of its parent, it is
5285 -- immediately visible.
5286
5287 if In_Open_Scopes (Scope (Uname)) then
5288 Set_Is_Immediately_Visible (Uname);
5289 end if;
5290
5291 if Is_Generic_Instance (Uname)
5292 and then Ekind (Uname) in Subprogram_Kind
5293 then
5294 -- Set flag as well on the visible entity that denotes the
5295 -- instance, which renames the current one.
5296
5297 Set_Is_Visible_Lib_Unit
5298 (Related_Instance
5299 (Defining_Entity (Unit (Library_Unit (With_Clause)))));
5300 end if;
5301
5302 -- The parent unit may have been installed already, and may have
5303 -- appeared in a use clause.
5304
5305 if In_Use (Scope (Uname)) then
5306 Set_Is_Potentially_Use_Visible (Uname);
5307 end if;
5308
5309 Set_Context_Installed (With_Clause);
5310 end if;
5311
5312 elsif not Is_Immediately_Visible (Uname) then
5313 Set_Is_Visible_Lib_Unit (Uname);
5314
5315 if not Private_Present (With_Clause) or else Private_With_OK then
5316 Set_Is_Immediately_Visible (Uname);
5317 end if;
5318
5319 Set_Context_Installed (With_Clause);
5320 end if;
5321
5322 -- A [private] with clause overrides a limited with clause. Restore the
5323 -- proper view of the package by performing the following actions:
5324 --
5325 -- * Remove all shadow entities which hide their corresponding
5326 -- entities from direct visibility by updating the entity and
5327 -- homonym chains.
5328 --
5329 -- * Enter the corresponding entities back in direct visibility
5330 --
5331 -- Note that the original limited with clause which installed its view
5332 -- is still marked as "active". This effect is undone when the clause
5333 -- itself is removed, see Remove_Limited_With_Clause.
5334
5335 if Ekind (Uname) = E_Package and then From_Limited_With (Uname) then
5336 Remove_Limited_With_Unit (Unit_Declaration_Node (Uname));
5337 end if;
5338
5339 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5340 -- unit if there is a visible homograph for it declared in the same
5341 -- declarative region. This pathological case can only arise when an
5342 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5343 -- G1 has a generic child also named G2, and the context includes with_
5344 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5345 -- of I1.G2 visible as well. If the child unit is named Standard, do
5346 -- not apply the check to the Standard package itself.
5347
5348 if Is_Child_Unit (Uname)
5349 and then Is_Visible_Lib_Unit (Uname)
5350 and then Ada_Version >= Ada_2005
5351 then
5352 declare
5353 Decl1 : constant Node_Id := Unit_Declaration_Node (P);
5354 Decl2 : Node_Id;
5355 P2 : Entity_Id;
5356 U2 : Entity_Id;
5357
5358 begin
5359 U2 := Homonym (Uname);
5360 while Present (U2) and then U2 /= Standard_Standard loop
5361 P2 := Scope (U2);
5362 Decl2 := Unit_Declaration_Node (P2);
5363
5364 if Is_Child_Unit (U2) and then Is_Visible_Lib_Unit (U2) then
5365 if Is_Generic_Instance (P)
5366 and then Nkind (Decl1) = N_Package_Declaration
5367 and then Generic_Parent (Specification (Decl1)) = P2
5368 then
5369 Error_Msg_N ("illegal with_clause", With_Clause);
5370 Error_Msg_N
5371 ("\child unit has visible homograph" &
5372 " (RM 8.3(26), 10.1.1(19))",
5373 With_Clause);
5374 exit;
5375
5376 elsif Is_Generic_Instance (P2)
5377 and then Nkind (Decl2) = N_Package_Declaration
5378 and then Generic_Parent (Specification (Decl2)) = P
5379 then
5380 -- With_clause for child unit of instance appears before
5381 -- in the context. We want to place the error message on
5382 -- it, not on the generic child unit itself.
5383
5384 declare
5385 Prev_Clause : Node_Id;
5386
5387 begin
5388 Prev_Clause := First (List_Containing (With_Clause));
5389 while Entity (Name (Prev_Clause)) /= U2 loop
5390 Next (Prev_Clause);
5391 end loop;
5392
5393 pragma Assert (Present (Prev_Clause));
5394 Error_Msg_N ("illegal with_clause", Prev_Clause);
5395 Error_Msg_N
5396 ("\child unit has visible homograph" &
5397 " (RM 8.3(26), 10.1.1(19))",
5398 Prev_Clause);
5399 exit;
5400 end;
5401 end if;
5402 end if;
5403
5404 U2 := Homonym (U2);
5405 end loop;
5406 end;
5407 end if;
5408 end Install_With_Clause;
5409
5410 -------------------
5411 -- Is_Child_Spec --
5412 -------------------
5413
5414 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
5415 K : constant Node_Kind := Nkind (Lib_Unit);
5416
5417 begin
5418 return (K in N_Generic_Declaration or else
5419 K in N_Generic_Instantiation or else
5420 K in N_Generic_Renaming_Declaration or else
5421 K = N_Package_Declaration or else
5422 K = N_Package_Renaming_Declaration or else
5423 K = N_Subprogram_Declaration or else
5424 K = N_Subprogram_Renaming_Declaration)
5425 and then Present (Parent_Spec (Lib_Unit));
5426 end Is_Child_Spec;
5427
5428 ------------------------------------
5429 -- Is_Legal_Shadow_Entity_In_Body --
5430 ------------------------------------
5431
5432 function Is_Legal_Shadow_Entity_In_Body (T : Entity_Id) return Boolean is
5433 C_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
5434 begin
5435 return Nkind (Unit (C_Unit)) = N_Package_Body
5436 and then
5437 Has_With_Clause
5438 (C_Unit, Cunit_Entity (Get_Source_Unit (Non_Limited_View (T))));
5439 end Is_Legal_Shadow_Entity_In_Body;
5440
5441 ----------------------
5442 -- Is_Ancestor_Unit --
5443 ----------------------
5444
5445 function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean is
5446 E1 : constant Entity_Id := Defining_Entity (Unit (U1));
5447 E2 : Entity_Id;
5448 begin
5449 if Nkind (Unit (U2)) in N_Package_Body | N_Subprogram_Body then
5450 E2 := Defining_Entity (Unit (Library_Unit (U2)));
5451 return Is_Ancestor_Package (E1, E2);
5452 else
5453 return False;
5454 end if;
5455 end Is_Ancestor_Unit;
5456
5457 ----------------------------------
5458 -- Is_Visible_Through_Renamings --
5459 ----------------------------------
5460
5461 function Is_Visible_Through_Renamings
5462 (P : Entity_Id;
5463 Error_Node : Node_Id := Empty) return Boolean
5464 is
5465 function Is_Limited_Withed_Unit
5466 (Lib_Unit : Node_Id;
5467 Pkg_Ent : Entity_Id) return Boolean;
5468 -- Return True if Pkg_Ent is a limited-withed package of the given
5469 -- library unit.
5470
5471 ----------------------------
5472 -- Is_Limited_Withed_Unit --
5473 ----------------------------
5474
5475 function Is_Limited_Withed_Unit
5476 (Lib_Unit : Node_Id;
5477 Pkg_Ent : Entity_Id) return Boolean
5478 is
5479 Item : Node_Id := First (Context_Items (Lib_Unit));
5480
5481 begin
5482 while Present (Item) loop
5483 if Nkind (Item) = N_With_Clause
5484 and then Limited_Present (Item)
5485 and then Entity (Name (Item)) = Pkg_Ent
5486 then
5487 return True;
5488 end if;
5489
5490 Next (Item);
5491 end loop;
5492
5493 return False;
5494 end Is_Limited_Withed_Unit;
5495
5496 -- Local variables
5497
5498 Kind : constant Node_Kind := Nkind (Unit (Cunit (Current_Sem_Unit)));
5499 Aux_Unit : Node_Id;
5500 Item : Node_Id;
5501 Decl : Entity_Id;
5502
5503 begin
5504 -- Example of the error detected by this subprogram:
5505
5506 -- package P is
5507 -- type T is ...
5508 -- end P;
5509
5510 -- with P;
5511 -- package Q is
5512 -- package Ren_P renames P;
5513 -- end Q;
5514
5515 -- with Q;
5516 -- package R is ...
5517
5518 -- limited with P; -- ERROR
5519 -- package R.C is ...
5520
5521 Aux_Unit := Cunit (Current_Sem_Unit);
5522
5523 loop
5524 Item := First (Context_Items (Aux_Unit));
5525 while Present (Item) loop
5526 if Nkind (Item) = N_With_Clause
5527 and then not Limited_Present (Item)
5528 and then Nkind (Unit (Library_Unit (Item))) =
5529 N_Package_Declaration
5530 then
5531 Decl :=
5532 First (Visible_Declarations
5533 (Specification (Unit (Library_Unit (Item)))));
5534 while Present (Decl) loop
5535 if Nkind (Decl) = N_Package_Renaming_Declaration
5536 and then Entity (Name (Decl)) = P
5537 and then not Is_Limited_Withed_Unit
5538 (Lib_Unit => Library_Unit (Item),
5539 Pkg_Ent => Entity (Name (Decl)))
5540 then
5541 -- Generate the error message only if the current unit
5542 -- is a package declaration; in case of subprogram
5543 -- bodies and package bodies we just return True to
5544 -- indicate that the limited view must not be
5545 -- installed.
5546
5547 if Kind = N_Package_Declaration
5548 and then Present (Error_Node)
5549 then
5550 Error_Msg_N
5551 ("simultaneous visibility of the limited and " &
5552 "unlimited views not allowed", Error_Node);
5553 Error_Msg_Sloc := Sloc (Item);
5554 Error_Msg_NE
5555 ("\\ unlimited view of & visible through the " &
5556 "context clause #", Error_Node, P);
5557 Error_Msg_Sloc := Sloc (Decl);
5558 Error_Msg_NE ("\\ and the renaming #", Error_Node, P);
5559 end if;
5560
5561 return True;
5562 end if;
5563
5564 Next (Decl);
5565 end loop;
5566 end if;
5567
5568 Next (Item);
5569 end loop;
5570
5571 -- If it is a body not acting as spec, follow pointer to the
5572 -- corresponding spec, otherwise follow pointer to parent spec.
5573
5574 if Present (Library_Unit (Aux_Unit))
5575 and then Nkind (Unit (Aux_Unit)) in
5576 N_Package_Body | N_Subprogram_Body
5577 then
5578 if Aux_Unit = Library_Unit (Aux_Unit) then
5579
5580 -- Aux_Unit is a body that acts as a spec. Clause has
5581 -- already been flagged as illegal.
5582
5583 return False;
5584
5585 else
5586 Aux_Unit := Library_Unit (Aux_Unit);
5587 end if;
5588
5589 else
5590 Aux_Unit := Parent_Spec (Unit (Aux_Unit));
5591 end if;
5592
5593 exit when No (Aux_Unit);
5594 end loop;
5595
5596 return False;
5597 end Is_Visible_Through_Renamings;
5598
5599 -----------------------
5600 -- Load_Needed_Body --
5601 -----------------------
5602
5603 -- N is a generic unit named in a with clause, or else it is a unit that
5604 -- contains a generic unit or an inlined function. In order to perform an
5605 -- instantiation, the body of the unit must be present. If the unit itself
5606 -- is generic, we assume that an instantiation follows, and load & analyze
5607 -- the body unconditionally. This forces analysis of the spec as well.
5608
5609 -- If the unit is not generic, but contains a generic unit, it is loaded on
5610 -- demand, at the point of instantiation (see ch12).
5611
5612 procedure Load_Needed_Body
5613 (N : Node_Id;
5614 OK : out Boolean;
5615 Do_Analyze : Boolean := True)
5616 is
5617 Body_Name : Unit_Name_Type;
5618 Unum : Unit_Number_Type;
5619
5620 Save_Style_Check : constant Boolean := Opt.Style_Check;
5621 -- The loading and analysis is done with style checks off
5622
5623 begin
5624 if not GNAT_Mode then
5625 Style_Check := False;
5626 end if;
5627
5628 Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
5629 Unum :=
5630 Load_Unit
5631 (Load_Name => Body_Name,
5632 Required => False,
5633 Subunit => False,
5634 Error_Node => N,
5635 Renamings => True);
5636
5637 if Unum = No_Unit then
5638 OK := False;
5639
5640 else
5641 Compiler_State := Analyzing; -- reset after load
5642
5643 if Fatal_Error (Unum) /= Error_Detected or else Try_Semantics then
5644 if Debug_Flag_L then
5645 Write_Str ("*** Loaded generic body");
5646 Write_Eol;
5647 end if;
5648
5649 if Do_Analyze then
5650 Semantics (Cunit (Unum));
5651 end if;
5652 end if;
5653
5654 OK := True;
5655 end if;
5656
5657 Style_Check := Save_Style_Check;
5658 end Load_Needed_Body;
5659
5660 -------------------------
5661 -- Build_Limited_Views --
5662 -------------------------
5663
5664 procedure Build_Limited_Views (N : Node_Id) is
5665 Unum : constant Unit_Number_Type :=
5666 Get_Source_Unit (Library_Unit (N));
5667 Is_Analyzed : constant Boolean := Analyzed (Cunit (Unum));
5668
5669 Shadow_Pack : Entity_Id;
5670 -- The corresponding shadow entity of the withed package. This entity
5671 -- offers incomplete views of packages and types as well as abstract
5672 -- views of states and variables declared within.
5673
5674 Last_Shadow : Entity_Id := Empty;
5675 -- The last shadow entity created by routine Build_Shadow_Entity
5676
5677 procedure Build_Shadow_Entity
5678 (Ent : Entity_Id;
5679 Scop : Entity_Id;
5680 Shadow : out Entity_Id;
5681 Is_Tagged : Boolean := False);
5682 -- Create a shadow entity that hides Ent and offers an abstract or
5683 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5684 -- should be set when Ent is a tagged type. The generated entity is
5685 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5686
5687 procedure Decorate_Package (Ent : Entity_Id; Scop : Entity_Id);
5688 -- Perform minimal decoration of a package or its corresponding shadow
5689 -- entity denoted by Ent. Scop is the proper scope.
5690
5691 procedure Decorate_State (Ent : Entity_Id; Scop : Entity_Id);
5692 -- Perform full decoration of an abstract state or its corresponding
5693 -- shadow entity denoted by Ent. Scop is the proper scope.
5694
5695 procedure Decorate_Type
5696 (Ent : Entity_Id;
5697 Scop : Entity_Id;
5698 Is_Tagged : Boolean := False;
5699 Materialize : Boolean := False);
5700 -- Perform minimal decoration of a type or its corresponding shadow
5701 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5702 -- should be set when Ent is a tagged type. Flag Materialize should be
5703 -- set when Ent is a tagged type and its class-wide type needs to appear
5704 -- in the tree.
5705
5706 procedure Decorate_Variable (Ent : Entity_Id; Scop : Entity_Id);
5707 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5708 -- proper scope.
5709
5710 procedure Process_Declarations_And_States
5711 (Pack : Entity_Id;
5712 Decls : List_Id;
5713 Scop : Entity_Id;
5714 Create_Abstract_Views : Boolean);
5715 -- Inspect the states of package Pack and declarative list Decls. Create
5716 -- shadow entities for all nested packages, states, types and variables
5717 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5718 -- be set when the abstract states and variables need to be processed.
5719
5720 -------------------------
5721 -- Build_Shadow_Entity --
5722 -------------------------
5723
5724 procedure Build_Shadow_Entity
5725 (Ent : Entity_Id;
5726 Scop : Entity_Id;
5727 Shadow : out Entity_Id;
5728 Is_Tagged : Boolean := False)
5729 is
5730 begin
5731 Shadow := Make_Temporary (Sloc (Ent), 'Z');
5732
5733 -- The shadow entity must share the same name and parent as the
5734 -- entity it hides.
5735
5736 Set_Chars (Shadow, Chars (Ent));
5737 Set_Parent (Shadow, Parent (Ent));
5738
5739 -- The abstract view of a variable is a state, not another variable
5740
5741 if Ekind (Ent) = E_Variable then
5742 Mutate_Ekind (Shadow, E_Abstract_State);
5743 else
5744 Mutate_Ekind (Shadow, Ekind (Ent));
5745 end if;
5746
5747 Set_Is_Internal (Shadow);
5748 Set_From_Limited_With (Shadow);
5749
5750 -- Add the new shadow entity to the limited view of the package
5751
5752 Last_Shadow := Shadow;
5753 Append_Entity (Shadow, Shadow_Pack);
5754
5755 -- Perform context-specific decoration of the shadow entity
5756
5757 if Ekind (Ent) = E_Abstract_State then
5758 Decorate_State (Shadow, Scop);
5759 Set_Non_Limited_View (Shadow, Ent);
5760
5761 elsif Ekind (Ent) = E_Package then
5762 Decorate_Package (Shadow, Scop);
5763
5764 elsif Is_Type (Ent) then
5765 Decorate_Type (Shadow, Scop, Is_Tagged);
5766 Set_Non_Limited_View (Shadow, Ent);
5767
5768 if Is_Tagged then
5769 Set_Non_Limited_View
5770 (Class_Wide_Type (Shadow), Class_Wide_Type (Ent));
5771 end if;
5772
5773 if Is_Incomplete_Or_Private_Type (Ent) then
5774 Set_Private_Dependents (Shadow, New_Elmt_List);
5775 end if;
5776
5777 elsif Ekind (Ent) = E_Variable then
5778 Decorate_State (Shadow, Scop);
5779 Set_Non_Limited_View (Shadow, Ent);
5780 end if;
5781 end Build_Shadow_Entity;
5782
5783 ----------------------
5784 -- Decorate_Package --
5785 ----------------------
5786
5787 procedure Decorate_Package (Ent : Entity_Id; Scop : Entity_Id) is
5788 begin
5789 Mutate_Ekind (Ent, E_Package);
5790 Set_Etype (Ent, Standard_Void_Type);
5791 Set_Scope (Ent, Scop);
5792 end Decorate_Package;
5793
5794 --------------------
5795 -- Decorate_State --
5796 --------------------
5797
5798 procedure Decorate_State (Ent : Entity_Id; Scop : Entity_Id) is
5799 begin
5800 Mutate_Ekind (Ent, E_Abstract_State);
5801 Set_Etype (Ent, Standard_Void_Type);
5802 Set_Scope (Ent, Scop);
5803 Set_Encapsulating_State (Ent, Empty);
5804 end Decorate_State;
5805
5806 -------------------
5807 -- Decorate_Type --
5808 -------------------
5809
5810 procedure Decorate_Type
5811 (Ent : Entity_Id;
5812 Scop : Entity_Id;
5813 Is_Tagged : Boolean := False;
5814 Materialize : Boolean := False)
5815 is
5816 CW_Typ : Entity_Id;
5817
5818 begin
5819 -- An unanalyzed type or a shadow entity of a type is treated as an
5820 -- incomplete type, and carries the corresponding attributes.
5821
5822 Mutate_Ekind (Ent, E_Incomplete_Type);
5823 Set_Etype (Ent, Ent);
5824 Set_Full_View (Ent, Empty);
5825 Set_Is_First_Subtype (Ent);
5826 Set_Scope (Ent, Scop);
5827 Set_Stored_Constraint (Ent, No_Elist);
5828 Init_Size_Align (Ent);
5829
5830 if From_Limited_With (Ent) then
5831 Set_Private_Dependents (Ent, New_Elmt_List);
5832 end if;
5833
5834 -- A tagged type and its corresponding shadow entity share one common
5835 -- class-wide type. The list of primitive operations for the shadow
5836 -- entity is empty.
5837
5838 if Is_Tagged then
5839 Set_Is_Tagged_Type (Ent);
5840 Set_Direct_Primitive_Operations (Ent, New_Elmt_List);
5841
5842 CW_Typ :=
5843 New_External_Entity
5844 (E_Void, Scope (Ent), Sloc (Ent), Ent, 'C', 0, 'T');
5845
5846 Set_Class_Wide_Type (Ent, CW_Typ);
5847
5848 -- Set parent to be the same as the parent of the tagged type.
5849 -- We need a parent field set, and it is supposed to point to
5850 -- the declaration of the type. The tagged type declaration
5851 -- essentially declares two separate types, the tagged type
5852 -- itself and the corresponding class-wide type, so it is
5853 -- reasonable for the parent fields to point to the declaration
5854 -- in both cases.
5855
5856 Set_Parent (CW_Typ, Parent (Ent));
5857
5858 Mutate_Ekind (CW_Typ, E_Class_Wide_Type);
5859 Set_Class_Wide_Type (CW_Typ, CW_Typ);
5860 Set_Etype (CW_Typ, Ent);
5861 Set_Equivalent_Type (CW_Typ, Empty);
5862 Set_From_Limited_With (CW_Typ, From_Limited_With (Ent));
5863 Set_Has_Unknown_Discriminants (CW_Typ);
5864 Set_Is_First_Subtype (CW_Typ);
5865 Set_Is_Tagged_Type (CW_Typ);
5866 Set_Materialize_Entity (CW_Typ, Materialize);
5867 Set_Scope (CW_Typ, Scop);
5868 Init_Size_Align (CW_Typ);
5869 end if;
5870 end Decorate_Type;
5871
5872 -----------------------
5873 -- Decorate_Variable --
5874 -----------------------
5875
5876 procedure Decorate_Variable (Ent : Entity_Id; Scop : Entity_Id) is
5877 begin
5878 Mutate_Ekind (Ent, E_Variable);
5879 Set_Etype (Ent, Standard_Void_Type);
5880 Set_Scope (Ent, Scop);
5881 end Decorate_Variable;
5882
5883 -------------------------------------
5884 -- Process_Declarations_And_States --
5885 -------------------------------------
5886
5887 procedure Process_Declarations_And_States
5888 (Pack : Entity_Id;
5889 Decls : List_Id;
5890 Scop : Entity_Id;
5891 Create_Abstract_Views : Boolean)
5892 is
5893 procedure Find_And_Process_States;
5894 -- Determine whether package Pack defines abstract state either by
5895 -- using an aspect or a pragma. If this is the case, build shadow
5896 -- entities for all abstract states of Pack.
5897
5898 procedure Process_States (States : Elist_Id);
5899 -- Generate shadow entities for all abstract states in list States
5900
5901 -----------------------------
5902 -- Find_And_Process_States --
5903 -----------------------------
5904
5905 procedure Find_And_Process_States is
5906 procedure Process_State (State : Node_Id);
5907 -- Generate shadow entities for a single abstract state or
5908 -- multiple states expressed as an aggregate.
5909
5910 -------------------
5911 -- Process_State --
5912 -------------------
5913
5914 procedure Process_State (State : Node_Id) is
5915 Loc : constant Source_Ptr := Sloc (State);
5916 Decl : Node_Id;
5917 Dummy : Entity_Id;
5918 Elmt : Node_Id;
5919 Id : Entity_Id;
5920
5921 begin
5922 -- Multiple abstract states appear as an aggregate
5923
5924 if Nkind (State) = N_Aggregate then
5925 Elmt := First (Expressions (State));
5926 while Present (Elmt) loop
5927 Process_State (Elmt);
5928 Next (Elmt);
5929 end loop;
5930
5931 return;
5932
5933 -- A null state has no abstract view
5934
5935 elsif Nkind (State) = N_Null then
5936 return;
5937
5938 -- State declaration with various options appears as an
5939 -- extension aggregate.
5940
5941 elsif Nkind (State) = N_Extension_Aggregate then
5942 Decl := Ancestor_Part (State);
5943
5944 -- Simple state declaration
5945
5946 elsif Nkind (State) = N_Identifier then
5947 Decl := State;
5948
5949 -- Possibly an illegal state declaration
5950
5951 else
5952 return;
5953 end if;
5954
5955 -- Abstract states are elaborated when the related pragma is
5956 -- elaborated. Since the withed package is not analyzed yet,
5957 -- the entities of the abstract states are not available. To
5958 -- overcome this complication, create the entities now and
5959 -- store them in their respective declarations. The entities
5960 -- are later used by routine Create_Abstract_State to declare
5961 -- and enter the states into visibility.
5962
5963 if No (Entity (Decl)) then
5964 Id := Make_Defining_Identifier (Loc, Chars (Decl));
5965
5966 Set_Entity (Decl, Id);
5967 Set_Parent (Id, State);
5968 Decorate_State (Id, Scop);
5969
5970 -- Otherwise the package was previously withed
5971
5972 else
5973 Id := Entity (Decl);
5974 end if;
5975
5976 Build_Shadow_Entity (Id, Scop, Dummy);
5977 end Process_State;
5978
5979 -- Local variables
5980
5981 Pack_Decl : constant Node_Id := Unit_Declaration_Node (Pack);
5982 Asp : Node_Id;
5983 Decl : Node_Id;
5984
5985 -- Start of processing for Find_And_Process_States
5986
5987 begin
5988 -- Find aspect Abstract_State
5989
5990 Asp := First (Aspect_Specifications (Pack_Decl));
5991 while Present (Asp) loop
5992 if Chars (Identifier (Asp)) = Name_Abstract_State then
5993 Process_State (Expression (Asp));
5994
5995 return;
5996 end if;
5997
5998 Next (Asp);
5999 end loop;
6000
6001 -- Find pragma Abstract_State by inspecting the declarations
6002
6003 Decl := First (Decls);
6004 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
6005 if Pragma_Name (Decl) = Name_Abstract_State then
6006 Process_State
6007 (Get_Pragma_Arg
6008 (First (Pragma_Argument_Associations (Decl))));
6009
6010 return;
6011 end if;
6012
6013 Next (Decl);
6014 end loop;
6015 end Find_And_Process_States;
6016
6017 --------------------
6018 -- Process_States --
6019 --------------------
6020
6021 procedure Process_States (States : Elist_Id) is
6022 Dummy : Entity_Id;
6023 Elmt : Elmt_Id;
6024
6025 begin
6026 Elmt := First_Elmt (States);
6027 while Present (Elmt) loop
6028 Build_Shadow_Entity (Node (Elmt), Scop, Dummy);
6029
6030 Next_Elmt (Elmt);
6031 end loop;
6032 end Process_States;
6033
6034 -- Local variables
6035
6036 Is_Tagged : Boolean;
6037 Decl : Node_Id;
6038 Def : Node_Id;
6039 Def_Id : Entity_Id;
6040 Shadow : Entity_Id;
6041
6042 -- Start of processing for Process_Declarations_And_States
6043
6044 begin
6045 -- Build abstract views for all states defined in the package
6046
6047 if Create_Abstract_Views then
6048
6049 -- When a package has been analyzed, all states are stored in list
6050 -- Abstract_States. Generate the shadow entities directly.
6051
6052 if Is_Analyzed then
6053 if Present (Abstract_States (Pack)) then
6054 Process_States (Abstract_States (Pack));
6055 end if;
6056
6057 -- The package may declare abstract states by using an aspect or a
6058 -- pragma. Attempt to locate one of these construct and if found,
6059 -- build the shadow entities.
6060
6061 else
6062 Find_And_Process_States;
6063 end if;
6064 end if;
6065
6066 -- Inspect the declarative list, looking for nested packages, types
6067 -- and variable declarations.
6068
6069 Decl := First (Decls);
6070 while Present (Decl) loop
6071
6072 -- Packages
6073
6074 if Nkind (Decl) = N_Package_Declaration then
6075 Def_Id := Defining_Entity (Decl);
6076
6077 -- Perform minor decoration when the withed package has not
6078 -- been analyzed.
6079
6080 if not Is_Analyzed then
6081 Decorate_Package (Def_Id, Scop);
6082 end if;
6083
6084 -- Create a shadow entity that offers a limited view of all
6085 -- visible types declared within.
6086
6087 Build_Shadow_Entity (Def_Id, Scop, Shadow);
6088
6089 Process_Declarations_And_States
6090 (Pack => Def_Id,
6091 Decls =>
6092 Visible_Declarations (Specification (Decl)),
6093 Scop => Shadow,
6094 Create_Abstract_Views => Create_Abstract_Views);
6095
6096 -- Types
6097
6098 elsif Nkind (Decl) in N_Full_Type_Declaration
6099 | N_Incomplete_Type_Declaration
6100 | N_Private_Extension_Declaration
6101 | N_Private_Type_Declaration
6102 | N_Protected_Type_Declaration
6103 | N_Task_Type_Declaration
6104 then
6105 Def_Id := Defining_Entity (Decl);
6106
6107 -- Determine whether the type is tagged. Note that packages
6108 -- included via a limited with clause are not always analyzed,
6109 -- hence the tree lookup rather than the use of attribute
6110 -- Is_Tagged_Type.
6111
6112 if Nkind (Decl) = N_Full_Type_Declaration then
6113 Def := Type_Definition (Decl);
6114
6115 Is_Tagged :=
6116 (Nkind (Def) = N_Record_Definition
6117 and then Tagged_Present (Def))
6118 or else
6119 (Nkind (Def) = N_Derived_Type_Definition
6120 and then Present (Record_Extension_Part (Def)));
6121
6122 elsif Nkind (Decl) in N_Incomplete_Type_Declaration
6123 | N_Private_Type_Declaration
6124 then
6125 Is_Tagged := Tagged_Present (Decl);
6126
6127 elsif Nkind (Decl) = N_Private_Extension_Declaration then
6128 Is_Tagged := True;
6129
6130 else
6131 Is_Tagged := False;
6132 end if;
6133
6134 -- Perform minor decoration when the withed package has not
6135 -- been analyzed.
6136
6137 if not Is_Analyzed then
6138 Decorate_Type (Def_Id, Scop, Is_Tagged, True);
6139 end if;
6140
6141 -- Create a shadow entity that hides the type and offers an
6142 -- incomplete view of the said type.
6143
6144 Build_Shadow_Entity (Def_Id, Scop, Shadow, Is_Tagged);
6145
6146 -- Variables
6147
6148 elsif Create_Abstract_Views
6149 and then Nkind (Decl) = N_Object_Declaration
6150 and then not Constant_Present (Decl)
6151 then
6152 Def_Id := Defining_Entity (Decl);
6153
6154 -- Perform minor decoration when the withed package has not
6155 -- been analyzed.
6156
6157 if not Is_Analyzed then
6158 Decorate_Variable (Def_Id, Scop);
6159 end if;
6160
6161 -- Create a shadow entity that hides the variable and offers an
6162 -- abstract view of the said variable.
6163
6164 Build_Shadow_Entity (Def_Id, Scop, Shadow);
6165 end if;
6166
6167 Next (Decl);
6168 end loop;
6169 end Process_Declarations_And_States;
6170
6171 -- Local variables
6172
6173 Nam : constant Node_Id := Name (N);
6174 Pack : constant Entity_Id := Cunit_Entity (Unum);
6175
6176 Last_Public_Shadow : Entity_Id := Empty;
6177 Private_Shadow : Entity_Id;
6178 Spec : Node_Id;
6179
6180 -- Start of processing for Build_Limited_Views
6181
6182 begin
6183 pragma Assert (Limited_Present (N));
6184
6185 -- A library_item mentioned in a limited_with_clause is a package
6186 -- declaration, not a subprogram declaration, generic declaration,
6187 -- generic instantiation, or package renaming declaration.
6188
6189 case Nkind (Unit (Library_Unit (N))) is
6190 when N_Package_Declaration =>
6191 null;
6192
6193 when N_Subprogram_Declaration =>
6194 Error_Msg_N
6195 ("subprogram not allowed in `LIMITED WITH` clause", N);
6196 return;
6197
6198 when N_Generic_Package_Declaration
6199 | N_Generic_Subprogram_Declaration
6200 =>
6201 Error_Msg_N ("generic not allowed in `LIMITED WITH` clause", N);
6202 return;
6203
6204 when N_Generic_Instantiation =>
6205 Error_Msg_N
6206 ("generic instantiation not allowed in `LIMITED WITH` clause",
6207 N);
6208 return;
6209
6210 when N_Generic_Renaming_Declaration =>
6211 Error_Msg_N
6212 ("generic renaming not allowed in `LIMITED WITH` clause", N);
6213 return;
6214
6215 when N_Subprogram_Renaming_Declaration =>
6216 Error_Msg_N
6217 ("renamed subprogram not allowed in `LIMITED WITH` clause", N);
6218 return;
6219
6220 when N_Package_Renaming_Declaration =>
6221 Error_Msg_N
6222 ("renamed package not allowed in `LIMITED WITH` clause", N);
6223 return;
6224
6225 when others =>
6226 raise Program_Error;
6227 end case;
6228
6229 -- The withed unit may not be analyzed, but the with calause itself
6230 -- must be minimally decorated. This ensures that the checks on unused
6231 -- with clauses also process limieted withs.
6232
6233 Mutate_Ekind (Pack, E_Package);
6234 Set_Etype (Pack, Standard_Void_Type);
6235
6236 if Is_Entity_Name (Nam) then
6237 Set_Entity (Nam, Pack);
6238
6239 elsif Nkind (Nam) = N_Selected_Component then
6240 Set_Entity (Selector_Name (Nam), Pack);
6241 end if;
6242
6243 -- Check if the chain is already built
6244
6245 Spec := Specification (Unit (Library_Unit (N)));
6246
6247 if Limited_View_Installed (Spec) then
6248 return;
6249 end if;
6250
6251 -- Create the shadow package wich hides the withed unit and provides
6252 -- incomplete view of all types and packages declared within.
6253
6254 Shadow_Pack := Make_Temporary (Sloc (N), 'Z');
6255 Mutate_Ekind (Shadow_Pack, E_Package);
6256 Set_Is_Internal (Shadow_Pack);
6257 Set_Limited_View (Pack, Shadow_Pack);
6258
6259 -- Inspect the abstract states and visible declarations of the withed
6260 -- unit and create shadow entities that hide existing packages, states,
6261 -- variables and types.
6262
6263 Process_Declarations_And_States
6264 (Pack => Pack,
6265 Decls => Visible_Declarations (Spec),
6266 Scop => Pack,
6267 Create_Abstract_Views => True);
6268
6269 Last_Public_Shadow := Last_Shadow;
6270
6271 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6272 -- to accommodate limited private with clauses.
6273
6274 Process_Declarations_And_States
6275 (Pack => Pack,
6276 Decls => Private_Declarations (Spec),
6277 Scop => Pack,
6278 Create_Abstract_Views => False);
6279
6280 if Present (Last_Public_Shadow) then
6281 Private_Shadow := Next_Entity (Last_Public_Shadow);
6282 else
6283 Private_Shadow := First_Entity (Shadow_Pack);
6284 end if;
6285
6286 Set_First_Private_Entity (Shadow_Pack, Private_Shadow);
6287 Set_Limited_View_Installed (Spec);
6288 end Build_Limited_Views;
6289
6290 ----------------------------
6291 -- Check_No_Elab_Code_All --
6292 ----------------------------
6293
6294 procedure Check_No_Elab_Code_All (N : Node_Id) is
6295 begin
6296 if Present (No_Elab_Code_All_Pragma)
6297 and then In_Extended_Main_Source_Unit (N)
6298 and then Present (Context_Items (N))
6299 then
6300 declare
6301 CL : constant List_Id := Context_Items (N);
6302 CI : Node_Id;
6303
6304 begin
6305 CI := First (CL);
6306 while Present (CI) loop
6307 if Nkind (CI) = N_With_Clause
6308 and then not
6309 No_Elab_Code_All (Get_Source_Unit (Library_Unit (CI)))
6310
6311 -- In GNATprove mode, some runtime units are implicitly
6312 -- loaded to make their entities available for analysis. In
6313 -- this case, ignore violations of No_Elaboration_Code_All
6314 -- for this special analysis mode.
6315
6316 and then not
6317 (GNATprove_Mode and then Implicit_With (CI))
6318 then
6319 Error_Msg_Sloc := Sloc (No_Elab_Code_All_Pragma);
6320 Error_Msg_N
6321 ("violation of No_Elaboration_Code_All#", CI);
6322 Error_Msg_NE
6323 ("\unit& does not have No_Elaboration_Code_All",
6324 CI, Entity (Name (CI)));
6325 end if;
6326
6327 Next (CI);
6328 end loop;
6329 end;
6330 end if;
6331 end Check_No_Elab_Code_All;
6332
6333 -------------------------------
6334 -- Check_Body_Needed_For_SAL --
6335 -------------------------------
6336
6337 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
6338 function Entity_Needs_Body (E : Entity_Id) return Boolean;
6339 -- Determine whether use of entity E might require the presence of its
6340 -- body. For a package this requires a recursive traversal of all nested
6341 -- declarations.
6342
6343 -----------------------
6344 -- Entity_Needs_Body --
6345 -----------------------
6346
6347 function Entity_Needs_Body (E : Entity_Id) return Boolean is
6348 Ent : Entity_Id;
6349
6350 begin
6351 if Is_Subprogram (E) and then Has_Pragma_Inline (E) then
6352 return True;
6353
6354 elsif Is_Generic_Subprogram (E) then
6355
6356 -- A generic subprogram always requires the presence of its
6357 -- body because an instantiation needs both templates. The only
6358 -- exceptions is a generic subprogram renaming. In this case the
6359 -- body is needed only when the template is declared outside the
6360 -- compilation unit being checked.
6361
6362 if Present (Renamed_Entity (E)) then
6363 return not Within_Scope (E, Unit_Name);
6364 else
6365 return True;
6366 end if;
6367
6368 elsif Ekind (E) = E_Generic_Package
6369 and then
6370 Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
6371 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
6372 then
6373 return True;
6374
6375 elsif Ekind (E) = E_Package
6376 and then Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
6377 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
6378 then
6379 Ent := First_Entity (E);
6380 while Present (Ent) loop
6381 if Entity_Needs_Body (Ent) then
6382 return True;
6383 end if;
6384
6385 Next_Entity (Ent);
6386 end loop;
6387
6388 return False;
6389
6390 else
6391 return False;
6392 end if;
6393 end Entity_Needs_Body;
6394
6395 -- Start of processing for Check_Body_Needed_For_SAL
6396
6397 begin
6398 if Ekind (Unit_Name) = E_Generic_Package
6399 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
6400 N_Generic_Package_Declaration
6401 and then
6402 Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
6403 then
6404 Set_Body_Needed_For_SAL (Unit_Name);
6405
6406 elsif Ekind (Unit_Name) in E_Generic_Procedure | E_Generic_Function then
6407 Set_Body_Needed_For_SAL (Unit_Name);
6408
6409 elsif Is_Subprogram (Unit_Name)
6410 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
6411 N_Subprogram_Declaration
6412 and then Has_Pragma_Inline (Unit_Name)
6413 then
6414 Set_Body_Needed_For_SAL (Unit_Name);
6415
6416 elsif Ekind (Unit_Name) = E_Subprogram_Body then
6417 Check_Body_Needed_For_SAL
6418 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
6419
6420 elsif Ekind (Unit_Name) = E_Package
6421 and then Entity_Needs_Body (Unit_Name)
6422 then
6423 Set_Body_Needed_For_SAL (Unit_Name);
6424
6425 elsif Ekind (Unit_Name) = E_Package_Body
6426 and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
6427 then
6428 Check_Body_Needed_For_SAL
6429 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
6430 end if;
6431 end Check_Body_Needed_For_SAL;
6432
6433 --------------------
6434 -- Remove_Context --
6435 --------------------
6436
6437 procedure Remove_Context (N : Node_Id) is
6438 Lib_Unit : constant Node_Id := Unit (N);
6439
6440 begin
6441 -- If this is a child unit, first remove the parent units
6442
6443 if Is_Child_Spec (Lib_Unit) then
6444 Remove_Parents (Lib_Unit);
6445 end if;
6446
6447 Remove_Context_Clauses (N);
6448 end Remove_Context;
6449
6450 ----------------------------
6451 -- Remove_Context_Clauses --
6452 ----------------------------
6453
6454 procedure Remove_Context_Clauses (N : Node_Id) is
6455 Item : Node_Id;
6456 Unit_Name : Entity_Id;
6457
6458 begin
6459 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6460 -- limited-views first and regular-views later (to maintain the stack
6461 -- model).
6462
6463 -- First Phase: Remove limited_with context clauses
6464
6465 Item := First (Context_Items (N));
6466 while Present (Item) loop
6467
6468 -- We are interested only in with clauses that got installed on entry
6469
6470 if Nkind (Item) = N_With_Clause
6471 and then Limited_Present (Item)
6472 then
6473 if Limited_View_Installed (Item) then
6474 Remove_Limited_With_Clause (Item);
6475
6476 -- An unusual case: If the library unit of the Main_Unit has a
6477 -- limited with_clause on some unit P and the context somewhere
6478 -- includes a with_clause on P, P has been analyzed. The entity
6479 -- for P is still visible, which in general is harmless because
6480 -- this is the end of the compilation, but it can affect pending
6481 -- instantiations that may have been generated elsewhere, so it
6482 -- it is necessary to remove U from visibility so that inlining
6483 -- and the analysis of instance bodies can proceed cleanly.
6484
6485 elsif Current_Sem_Unit = Main_Unit
6486 and then Serious_Errors_Detected = 0
6487 and then not Implicit_With (Item)
6488 then
6489 Set_Is_Immediately_Visible
6490 (Defining_Entity (Unit (Library_Unit (Item))), False);
6491 end if;
6492 end if;
6493
6494 Next (Item);
6495 end loop;
6496
6497 -- Second Phase: Loop through context items and undo regular
6498 -- with_clauses and use_clauses.
6499
6500 Item := First (Context_Items (N));
6501 while Present (Item) loop
6502
6503 -- We are interested only in with clauses which got installed on
6504 -- entry, as indicated by their Context_Installed flag set
6505
6506 if Nkind (Item) = N_With_Clause
6507 and then Limited_Present (Item)
6508 and then Limited_View_Installed (Item)
6509 then
6510 null;
6511
6512 elsif Nkind (Item) = N_With_Clause
6513 and then Context_Installed (Item)
6514 then
6515 -- Remove items from one with'ed unit
6516
6517 Unit_Name := Entity (Name (Item));
6518 Remove_Unit_From_Visibility (Unit_Name);
6519 Set_Context_Installed (Item, False);
6520
6521 elsif Nkind (Item) = N_Use_Package_Clause then
6522 End_Use_Package (Item);
6523
6524 elsif Nkind (Item) = N_Use_Type_Clause then
6525 End_Use_Type (Item);
6526 end if;
6527
6528 Next (Item);
6529 end loop;
6530 end Remove_Context_Clauses;
6531
6532 --------------------------------
6533 -- Remove_Limited_With_Clause --
6534 --------------------------------
6535
6536 procedure Remove_Limited_With_Clause (N : Node_Id) is
6537 Pack_Decl : constant Entity_Id := Unit (Library_Unit (N));
6538
6539 begin
6540 pragma Assert (Limited_View_Installed (N));
6541
6542 -- Limited with clauses that designate units other than packages are
6543 -- illegal and are never installed.
6544
6545 if Nkind (Pack_Decl) = N_Package_Declaration then
6546 Remove_Limited_With_Unit (Pack_Decl, N);
6547 end if;
6548
6549 -- Indicate that the limited views of the clause have been removed
6550
6551 Set_Limited_View_Installed (N, False);
6552 end Remove_Limited_With_Clause;
6553
6554 ------------------------------
6555 -- Remove_Limited_With_Unit --
6556 ------------------------------
6557
6558 procedure Remove_Limited_With_Unit
6559 (Pack_Decl : Node_Id;
6560 Lim_Clause : Node_Id := Empty)
6561 is
6562 procedure Remove_Shadow_Entities_From_Visibility (Pack_Id : Entity_Id);
6563 -- Remove the shadow entities of package Pack_Id from direct visibility
6564
6565 procedure Remove_Shadow_Entities_With_Restore (Pack_Id : Entity_Id);
6566 -- Remove the shadow entities of package Pack_Id from direct visibility,
6567 -- restore the corresponding entities they hide into direct visibility,
6568 -- and update the entity and homonym chains.
6569
6570 --------------------------------------------
6571 -- Remove_Shadow_Entities_From_Visibility --
6572 --------------------------------------------
6573
6574 procedure Remove_Shadow_Entities_From_Visibility (Pack_Id : Entity_Id) is
6575 Lim_Header : constant Entity_Id := Limited_View (Pack_Id);
6576 Upto : constant Entity_Id := First_Private_Entity (Lim_Header);
6577
6578 Shadow : Entity_Id;
6579
6580 begin
6581 -- Remove the package from direct visibility
6582
6583 Unchain (Pack_Id);
6584 Set_Is_Immediately_Visible (Pack_Id, False);
6585
6586 -- Remove all shadow entities from direct visibility
6587
6588 Shadow := First_Entity (Lim_Header);
6589 while Present (Shadow) and then Shadow /= Upto loop
6590 Unchain (Shadow);
6591 Next_Entity (Shadow);
6592 end loop;
6593 end Remove_Shadow_Entities_From_Visibility;
6594
6595 -----------------------------------------
6596 -- Remove_Shadow_Entities_With_Restore --
6597 -----------------------------------------
6598
6599 procedure Remove_Shadow_Entities_With_Restore (Pack_Id : Entity_Id) is
6600 procedure Restore_Chain_For_Shadow (Shadow : Entity_Id);
6601 -- Remove shadow entity Shadow by updating the entity and homonym
6602 -- chains.
6603
6604 procedure Restore_Chains
6605 (From : Entity_Id;
6606 Upto : Entity_Id);
6607 -- Remove a sequence of shadow entities starting from From and ending
6608 -- prior to Upto by updating the entity and homonym chains.
6609
6610 procedure Restore_Type_Visibility
6611 (From : Entity_Id;
6612 Upto : Entity_Id);
6613 -- Restore a sequence of types starting from From and ending prior to
6614 -- Upto back in direct visibility.
6615
6616 ------------------------------
6617 -- Restore_Chain_For_Shadow --
6618 ------------------------------
6619
6620 procedure Restore_Chain_For_Shadow (Shadow : Entity_Id) is
6621 Prev : Entity_Id;
6622 Typ : Entity_Id;
6623
6624 begin
6625 -- If the package has incomplete types, the limited view of the
6626 -- incomplete type is in fact never visible (AI05-129) but we
6627 -- have created a shadow entity E1 for it, that points to E2,
6628 -- a nonlimited incomplete type. This in turn has a full view
6629 -- E3 that is the full declaration. There is a corresponding
6630 -- shadow entity E4. When reinstalling the nonlimited view,
6631 -- E2 must become the current entity and E3 must be ignored.
6632
6633 Typ := Non_Limited_View (Shadow);
6634
6635 -- Shadow is the limited view of a full type declaration that has
6636 -- a previous incomplete declaration, i.e. E3 from the previous
6637 -- description. Nothing to insert.
6638
6639 if Present (Current_Entity (Typ))
6640 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
6641 and then Full_View (Current_Entity (Typ)) = Typ
6642 then
6643 return;
6644 end if;
6645
6646 pragma Assert (not In_Chain (Typ));
6647
6648 Prev := Current_Entity (Shadow);
6649
6650 if Prev = Shadow then
6651 Set_Current_Entity (Typ);
6652
6653 else
6654 while Present (Prev) and then Homonym (Prev) /= Shadow loop
6655 Prev := Homonym (Prev);
6656 end loop;
6657
6658 if Present (Prev) then
6659 Set_Homonym (Prev, Typ);
6660 end if;
6661 end if;
6662
6663 Set_Homonym (Typ, Homonym (Shadow));
6664 end Restore_Chain_For_Shadow;
6665
6666 --------------------
6667 -- Restore_Chains --
6668 --------------------
6669
6670 procedure Restore_Chains
6671 (From : Entity_Id;
6672 Upto : Entity_Id)
6673 is
6674 Shadow : Entity_Id;
6675
6676 begin
6677 Shadow := From;
6678 while Present (Shadow) and then Shadow /= Upto loop
6679
6680 -- Do not unchain nested packages and child units
6681
6682 if Ekind (Shadow) = E_Package then
6683 null;
6684
6685 elsif Is_Child_Unit (Non_Limited_View (Shadow)) then
6686 null;
6687
6688 else
6689 Restore_Chain_For_Shadow (Shadow);
6690 end if;
6691
6692 Next_Entity (Shadow);
6693 end loop;
6694 end Restore_Chains;
6695
6696 -----------------------------
6697 -- Restore_Type_Visibility --
6698 -----------------------------
6699
6700 procedure Restore_Type_Visibility
6701 (From : Entity_Id;
6702 Upto : Entity_Id)
6703 is
6704 Typ : Entity_Id;
6705
6706 begin
6707 Typ := From;
6708 while Present (Typ) and then Typ /= Upto loop
6709 if Is_Type (Typ) then
6710 Set_Is_Hidden (Typ, Was_Hidden (Typ));
6711 end if;
6712
6713 Next_Entity (Typ);
6714 end loop;
6715 end Restore_Type_Visibility;
6716
6717 -- Local variables
6718
6719 Lim_Header : constant Entity_Id := Limited_View (Pack_Id);
6720
6721 -- Start of processing Remove_Shadow_Entities_With_Restore
6722
6723 begin
6724 -- The limited view of a package is being uninstalled by removing
6725 -- the effects of a limited with clause. If the clause appears in a
6726 -- unit which is not part of the main unit closure, then the related
6727 -- package must not be visible.
6728
6729 if Present (Lim_Clause)
6730 and then not In_Extended_Main_Source_Unit (Lim_Clause)
6731 then
6732 Set_Is_Immediately_Visible (Pack_Id, False);
6733
6734 -- Otherwise a limited view is being overridden by a nonlimited view.
6735 -- Leave the visibility of the package as is because the unit must be
6736 -- visible when the nonlimited view is installed.
6737
6738 else
6739 null;
6740 end if;
6741
6742 -- Remove the shadow entities from visibility by updating the entity
6743 -- and homonym chains.
6744
6745 Restore_Chains
6746 (From => First_Entity (Lim_Header),
6747 Upto => First_Private_Entity (Lim_Header));
6748
6749 -- Reinstate the types that were hidden by the shadow entities back
6750 -- into direct visibility.
6751
6752 Restore_Type_Visibility
6753 (From => First_Entity (Pack_Id),
6754 Upto => First_Private_Entity (Pack_Id));
6755 end Remove_Shadow_Entities_With_Restore;
6756
6757 -- Local variables
6758
6759 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
6760
6761 -- Start of processing for Remove_Limited_With_Unit
6762
6763 begin
6764 -- Nothing to do when the limited view of the package is not installed
6765
6766 if not From_Limited_With (Pack_Id) then
6767 return;
6768 end if;
6769
6770 if Debug_Flag_I then
6771 Write_Str ("remove limited view of ");
6772 Write_Name (Chars (Pack_Id));
6773 Write_Str (" from visibility");
6774 Write_Eol;
6775 end if;
6776
6777 -- The package already appears in the compilation closure. As a result,
6778 -- its shadow entities must be replaced by the real entities they hide
6779 -- and the previously hidden entities must be entered back into direct
6780 -- visibility.
6781
6782 -- WARNING: This code must be kept synchronized with that of routine
6783 -- Install_Limited_Withed_Clause.
6784
6785 if Analyzed (Pack_Decl) then
6786 Remove_Shadow_Entities_With_Restore (Pack_Id);
6787
6788 -- Otherwise the package is not analyzed and its shadow entities must be
6789 -- removed from direct visibility.
6790
6791 else
6792 Remove_Shadow_Entities_From_Visibility (Pack_Id);
6793 end if;
6794
6795 -- Indicate that the limited view of the package is not installed
6796
6797 Set_From_Limited_With (Pack_Id, False);
6798 end Remove_Limited_With_Unit;
6799
6800 --------------------
6801 -- Remove_Parents --
6802 --------------------
6803
6804 procedure Remove_Parents (Lib_Unit : Node_Id) is
6805 P : Node_Id;
6806 P_Name : Entity_Id;
6807 P_Spec : Node_Id := Empty;
6808 E : Entity_Id;
6809 Vis : constant Boolean :=
6810 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
6811
6812 begin
6813 if Is_Child_Spec (Lib_Unit) then
6814 P_Spec := Parent_Spec (Lib_Unit);
6815
6816 elsif Nkind (Lib_Unit) = N_Package_Body
6817 and then Nkind (Original_Node (Lib_Unit)) = N_Package_Instantiation
6818 then
6819 P_Spec := Parent_Spec (Original_Node (Lib_Unit));
6820 end if;
6821
6822 if Present (P_Spec) then
6823 P := Unit (P_Spec);
6824 P_Name := Get_Parent_Entity (P);
6825 Remove_Context_Clauses (P_Spec);
6826 End_Package_Scope (P_Name);
6827 Set_Is_Immediately_Visible (P_Name, Vis);
6828
6829 -- Remove from visibility the siblings as well, which are directly
6830 -- visible while the parent is in scope.
6831
6832 E := First_Entity (P_Name);
6833 while Present (E) loop
6834 if Is_Child_Unit (E) then
6835 Set_Is_Immediately_Visible (E, False);
6836 end if;
6837
6838 Next_Entity (E);
6839 end loop;
6840
6841 Set_In_Package_Body (P_Name, False);
6842
6843 -- This is the recursive call to remove the context of any higher
6844 -- level parent. This recursion ensures that all parents are removed
6845 -- in the reverse order of their installation.
6846
6847 Remove_Parents (P);
6848 end if;
6849 end Remove_Parents;
6850
6851 ---------------------------------
6852 -- Remove_Private_With_Clauses --
6853 ---------------------------------
6854
6855 procedure Remove_Private_With_Clauses (Comp_Unit : Node_Id) is
6856 Item : Node_Id;
6857
6858 function In_Regular_With_Clause (E : Entity_Id) return Boolean;
6859 -- Check whether a given unit appears in a regular with_clause. Used to
6860 -- determine whether a private_with_clause, implicit or explicit, should
6861 -- be ignored.
6862
6863 ----------------------------
6864 -- In_Regular_With_Clause --
6865 ----------------------------
6866
6867 function In_Regular_With_Clause (E : Entity_Id) return Boolean is
6868 Item : Node_Id;
6869
6870 begin
6871 Item := First (Context_Items (Comp_Unit));
6872
6873 while Present (Item) loop
6874 if Nkind (Item) = N_With_Clause
6875
6876 -- The following guard is needed to ensure that the name has
6877 -- been properly analyzed before we go fetching its entity.
6878
6879 and then Is_Entity_Name (Name (Item))
6880 and then Entity (Name (Item)) = E
6881 and then not Private_Present (Item)
6882 then
6883 return True;
6884 end if;
6885
6886 Next (Item);
6887 end loop;
6888
6889 return False;
6890 end In_Regular_With_Clause;
6891
6892 -- Start of processing for Remove_Private_With_Clauses
6893
6894 begin
6895 Item := First (Context_Items (Comp_Unit));
6896 while Present (Item) loop
6897 if Nkind (Item) = N_With_Clause and then Private_Present (Item) then
6898
6899 -- If private_with_clause is redundant, remove it from context,
6900 -- as a small optimization to subsequent handling of private_with
6901 -- clauses in other nested packages. We replace the clause with
6902 -- a null statement, which is otherwise ignored by the rest of
6903 -- the compiler.
6904
6905 if In_Regular_With_Clause (Entity (Name (Item))) then
6906 declare
6907 Nxt : constant Node_Id := Next (Item);
6908 begin
6909 Rewrite (Item, Make_Null_Statement (Sloc (Item)));
6910 Analyze (Item);
6911 Item := Nxt;
6912 end;
6913
6914 elsif Limited_Present (Item) then
6915 if not Limited_View_Installed (Item) then
6916 Remove_Limited_With_Clause (Item);
6917 end if;
6918
6919 Next (Item);
6920
6921 else
6922 Remove_Unit_From_Visibility (Entity (Name (Item)));
6923 Set_Context_Installed (Item, False);
6924 Next (Item);
6925 end if;
6926
6927 else
6928 Next (Item);
6929 end if;
6930 end loop;
6931 end Remove_Private_With_Clauses;
6932
6933 ---------------------------------
6934 -- Remove_Unit_From_Visibility --
6935 ---------------------------------
6936
6937 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
6938 begin
6939 if Debug_Flag_I then
6940 Write_Str ("remove unit ");
6941 Write_Name (Chars (Unit_Name));
6942 Write_Str (" from visibility");
6943 Write_Eol;
6944 end if;
6945
6946 Set_Is_Visible_Lib_Unit (Unit_Name, False);
6947 Set_Is_Potentially_Use_Visible (Unit_Name, False);
6948 Set_Is_Immediately_Visible (Unit_Name, False);
6949
6950 -- If the unit is a wrapper package, the subprogram instance is
6951 -- what must be removed from visibility.
6952 -- Should we use Related_Instance instead???
6953
6954 if Is_Wrapper_Package (Unit_Name) then
6955 Set_Is_Immediately_Visible (Current_Entity (Unit_Name), False);
6956 end if;
6957 end Remove_Unit_From_Visibility;
6958
6959 --------
6960 -- sm --
6961 --------
6962
6963 procedure sm is
6964 begin
6965 null;
6966 end sm;
6967
6968 -------------
6969 -- Unchain --
6970 -------------
6971
6972 procedure Unchain (E : Entity_Id) is
6973 Prev : Entity_Id;
6974
6975 begin
6976 Prev := Current_Entity (E);
6977
6978 if No (Prev) then
6979 return;
6980
6981 elsif Prev = E then
6982 Set_Name_Entity_Id (Chars (E), Homonym (E));
6983
6984 else
6985 while Present (Prev) and then Homonym (Prev) /= E loop
6986 Prev := Homonym (Prev);
6987 end loop;
6988
6989 if Present (Prev) then
6990 Set_Homonym (Prev, Homonym (E));
6991 end if;
6992 end if;
6993
6994 if Debug_Flag_I then
6995 Write_Str (" (homonym) unchain ");
6996 Write_Name (Chars (E));
6997 Write_Eol;
6998 end if;
6999 end Unchain;
7000
7001 end Sem_Ch10;
This page took 0.323024 seconds and 6 git commands to generate.