1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Errout; use Errout;
30 with Exp_Util; use Exp_Util;
31 with Elists; use Elists;
32 with Fname; use Fname;
33 with Fname.UF; use Fname.UF;
34 with Freeze; use Freeze;
35 with Impunit; use Impunit;
36 with Inline; use Inline;
38 with Lib.Load; use Lib.Load;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Output; use Output;
45 with Par_SCO; use Par_SCO;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch7; use Sem_Ch7;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Dist; use Sem_Dist;
55 with Sem_Prag; use Sem_Prag;
56 with Sem_Util; use Sem_Util;
57 with Sem_Warn; use Sem_Warn;
58 with Stand; use Stand;
59 with Sinfo; use Sinfo;
60 with Sinfo.CN; use Sinfo.CN;
61 with Sinput; use Sinput;
62 with Snames; use Snames;
63 with Style; use Style;
64 with Stylesw; use Stylesw;
65 with Tbuild; use Tbuild;
66 with Uname; use Uname;
68 package body Sem_Ch10 is
70 -----------------------
71 -- Local Subprograms --
72 -----------------------
74 procedure Analyze_Context (N : Node_Id);
75 -- Analyzes items in the context clause of compilation unit
77 procedure Build_Limited_Views (N : Node_Id);
78 -- Build and decorate the list of shadow entities for a package mentioned
79 -- in a limited_with clause. If the package was not previously analyzed
80 -- then it also performs a basic decoration of the real entities. This is
81 -- required to do not pass non-decorated entities to the back-end.
82 -- Implements Ada 2005 (AI-50217).
84 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id);
85 -- Check whether the source for the body of a compilation unit must be
86 -- included in a standalone library.
88 procedure Check_Private_Child_Unit (N : Node_Id);
89 -- If a with_clause mentions a private child unit, the compilation
90 -- unit must be a member of the same family, as described in 10.1.2.
92 procedure Check_Stub_Level (N : Node_Id);
93 -- Verify that a stub is declared immediately within a compilation unit,
94 -- and not in an inner frame.
96 procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id);
97 -- When a child unit appears in a context clause, the implicit withs on
98 -- parents are made explicit, and with clauses are inserted in the context
99 -- clause before the one for the child. If a parent in the with_clause
100 -- is a renaming, the implicit with_clause is on the renaming whose name
101 -- is mentioned in the with_clause, and not on the package it renames.
102 -- N is the compilation unit whose list of context items receives the
103 -- implicit with_clauses.
105 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id;
106 -- Get defining entity of parent unit of a child unit. In most cases this
107 -- is the defining entity of the unit, but for a child instance whose
108 -- parent needs a body for inlining, the instantiation node of the parent
109 -- has not yet been rewritten as a package declaration, and the entity has
110 -- to be retrieved from the Instance_Spec of the unit.
112 function Has_With_Clause
115 Is_Limited : Boolean := False) return Boolean;
116 -- Determine whether compilation unit C_Unit contains a [limited] with
117 -- clause for package Pack. Use the flag Is_Limited to designate desired
120 procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id);
121 -- If the main unit is a child unit, implicit withs are also added for
122 -- all its ancestors.
124 function In_Chain (E : Entity_Id) return Boolean;
125 -- Check that the shadow entity is not already in the homonym chain, for
126 -- example through a limited_with clause in a parent unit.
128 procedure Install_Context_Clauses (N : Node_Id);
129 -- Subsidiary to Install_Context and Install_Parents. Process only with_
130 -- and use_clauses for current unit and its library unit if any.
132 procedure Install_Limited_Context_Clauses (N : Node_Id);
133 -- Subsidiary to Install_Context. Process only limited with_clauses for
134 -- current unit. Implements Ada 2005 (AI-50217).
136 procedure Install_Limited_Withed_Unit (N : Node_Id);
137 -- Place shadow entities for a limited_with package in the visibility
138 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
140 procedure Install_Withed_Unit
141 (With_Clause : Node_Id;
142 Private_With_OK : Boolean := False);
143 -- If the unit is not a child unit, make unit immediately visible. The
144 -- caller ensures that the unit is not already currently installed. The
145 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
146 -- is called when compiling the private part of a package, or installing
147 -- the private declarations of a parent unit.
149 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean);
150 -- This procedure establishes the context for the compilation of a child
151 -- unit. If Lib_Unit is a child library spec then the context of the parent
152 -- is installed, and the parent itself made immediately visible, so that
153 -- the child unit is processed in the declarative region of the parent.
154 -- Install_Parents makes a recursive call to itself to ensure that all
155 -- parents are loaded in the nested case. If Lib_Unit is a library body,
156 -- the only effect of Install_Parents is to install the private decls of
157 -- the parents, because the visible parent declarations will have been
158 -- installed as part of the context of the corresponding spec.
160 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
161 -- In the compilation of a child unit, a child of any of the ancestor
162 -- units is directly visible if it is visible, because the parent is in
163 -- an enclosing scope. Iterate over context to find child units of U_Name
164 -- or of some ancestor of it.
166 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean;
167 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
168 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
169 -- a library spec that has a parent. If the call to Is_Child_Spec returns
170 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
171 -- compilation unit for the parent spec.
173 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
174 -- Parent_Spec is non-empty, this is also a child unit.
176 procedure Remove_Context_Clauses (N : Node_Id);
177 -- Subsidiary of previous one. Remove use_ and with_clauses
179 procedure Remove_Limited_With_Clause (N : Node_Id);
180 -- Remove from visibility the shadow entities introduced for a package
181 -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217).
183 procedure Remove_Parents (Lib_Unit : Node_Id);
184 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
185 -- contexts established by the corresponding call to Install_Parents are
186 -- removed. Remove_Parents contains a recursive call to itself to ensure
187 -- that all parents are removed in the nested case.
189 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id);
190 -- Reset all visibility flags on unit after compiling it, either as a
191 -- main unit or as a unit in the context.
193 procedure Unchain (E : Entity_Id);
194 -- Remove single entity from visibility list
196 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id);
197 -- Common processing for all stubs (subprograms, tasks, packages, and
198 -- protected cases). N is the stub to be analyzed. Once the subunit
199 -- name is established, load and analyze. Nam is the non-overloadable
200 -- entity for which the proper body provides a completion. Subprogram
201 -- stubs are handled differently because they can be declarations.
204 -- A dummy procedure, for debugging use, called just before analyzing the
205 -- main unit (after dealing with any context clauses).
207 --------------------------
208 -- Limited_With_Clauses --
209 --------------------------
211 -- Limited_With clauses are the mechanism chosen for Ada05 to support
212 -- mutually recursive types declared in different units. A limited_with
213 -- clause that names package P in the context of unit U makes the types
214 -- declared in the visible part of P available within U, but with the
215 -- restriction that these types can only be used as incomplete types.
216 -- The limited_with clause does not impose a semantic dependence on P,
217 -- and it is possible for two packages to have limited_with_clauses on
218 -- each other without creating an elaboration circularity.
220 -- To support this feature, the analysis of a limited_with clause must
221 -- create an abbreviated view of the package, without performing any
222 -- semantic analysis on it. This "package abstract" contains shadow
223 -- types that are in one-one correspondence with the real types in the
224 -- package, and that have the properties of incomplete types.
226 -- The implementation creates two element lists: one to chain the shadow
227 -- entities, and one to chain the corresponding type entities in the tree
228 -- of the package. Links between corresponding entities in both chains
229 -- allow the compiler to select the proper view of a given type, depending
230 -- on the context. Note that in contrast with the handling of private
231 -- types, the limited view and the non-limited view of a type are treated
232 -- as separate entities, and no entity exchange needs to take place, which
233 -- makes the implementation must simpler than could be feared.
235 ------------------------------
236 -- Analyze_Compilation_Unit --
237 ------------------------------
239 procedure Analyze_Compilation_Unit (N : Node_Id) is
240 Unit_Node : constant Node_Id := Unit (N);
241 Lib_Unit : Node_Id := Library_Unit (N);
243 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
244 Par_Spec_Name : Unit_Name_Type;
245 Unum : Unit_Number_Type;
247 procedure Check_Redundant_Withs
248 (Context_Items : List_Id;
249 Spec_Context_Items : List_Id := No_List);
250 -- Determine whether the context list of a compilation unit contains
251 -- redundant with clauses. When checking body clauses against spec
252 -- clauses, set Context_Items to the context list of the body and
253 -- Spec_Context_Items to that of the spec. Parent packages are not
254 -- examined for documentation purposes.
256 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id);
257 -- Generate cross-reference information for the parents of child units.
258 -- N is a defining_program_unit_name, and P_Id is the immediate parent.
260 ---------------------------
261 -- Check_Redundant_Withs --
262 ---------------------------
264 procedure Check_Redundant_Withs
265 (Context_Items : List_Id;
266 Spec_Context_Items : List_Id := No_List)
270 procedure Process_Body_Clauses
271 (Context_List : List_Id;
273 Used : in out Boolean;
274 Used_Type_Or_Elab : in out Boolean);
275 -- Examine the context clauses of a package body, trying to match
276 -- the name entity of Clause with any list element. If the match
277 -- occurs on a use package clause, set Used to True, for a use
278 -- type clause, pragma Elaborate or pragma Elaborate_All, set
279 -- Used_Type_Or_Elab to True.
281 procedure Process_Spec_Clauses
282 (Context_List : List_Id;
284 Used : in out Boolean;
285 Withed : in out Boolean;
286 Exit_On_Self : Boolean := False);
287 -- Examine the context clauses of a package spec, trying to match
288 -- the name entity of Clause with any list element. If the match
289 -- occurs on a use package clause, set Used to True, for a with
290 -- package clause other than Clause, set Withed to True. Limited
291 -- with clauses, implicitly generated with clauses and withs
292 -- having pragmas Elaborate or Elaborate_All applied to them are
293 -- skipped. Exit_On_Self is used to control the search loop and
294 -- force an exit whenever Clause sees itself in the search.
296 --------------------------
297 -- Process_Body_Clauses --
298 --------------------------
300 procedure Process_Body_Clauses
301 (Context_List : List_Id;
303 Used : in out Boolean;
304 Used_Type_Or_Elab : in out Boolean)
306 Nam_Ent : constant Entity_Id := Entity (Name (Clause));
312 function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean;
313 -- In an expanded name in a use clause, if the prefix is a
314 -- renamed package, the entity is set to the original package
315 -- as a result, when checking whether the package appears in a
316 -- previous with_clause, the renaming has to be taken into
317 -- account, to prevent spurious or incorrect warnings. The
318 -- common case is the use of Text_IO.
324 function Same_Unit (N : Node_Id; P : Entity_Id) return Boolean is
326 return Entity (N) = P
328 (Present (Renamed_Object (P))
329 and then Entity (N) = Renamed_Object (P));
332 -- Start of processing for Process_Body_Clauses
336 Used_Type_Or_Elab := False;
338 Cont_Item := First (Context_List);
339 while Present (Cont_Item) loop
341 -- Package use clause
343 if Nkind (Cont_Item) = N_Use_Package_Clause
346 -- Search through use clauses
348 Use_Item := First (Names (Cont_Item));
349 while Present (Use_Item) and then not Used loop
351 -- Case of a direct use of the one we are looking for
353 if Entity (Use_Item) = Nam_Ent then
356 -- Handle nested case, as in "with P; use P.Q.R"
363 -- Loop through prefixes looking for match
366 while Nkind (UE) = N_Expanded_Name loop
367 if Same_Unit (Prefix (UE), Nam_Ent) then
382 elsif Nkind (Cont_Item) = N_Use_Type_Clause
383 and then not Used_Type_Or_Elab
385 Subt_Mark := First (Subtype_Marks (Cont_Item));
386 while Present (Subt_Mark)
387 and then not Used_Type_Or_Elab
389 if Same_Unit (Prefix (Subt_Mark), Nam_Ent) then
390 Used_Type_Or_Elab := True;
396 -- Pragma Elaborate or Elaborate_All
398 elsif Nkind (Cont_Item) = N_Pragma
400 (Pragma_Name (Cont_Item) = Name_Elaborate
402 Pragma_Name (Cont_Item) = Name_Elaborate_All)
403 and then not Used_Type_Or_Elab
406 First (Pragma_Argument_Associations (Cont_Item));
407 while Present (Prag_Unit)
408 and then not Used_Type_Or_Elab
410 if Entity (Expression (Prag_Unit)) = Nam_Ent then
411 Used_Type_Or_Elab := True;
420 end Process_Body_Clauses;
422 --------------------------
423 -- Process_Spec_Clauses --
424 --------------------------
426 procedure Process_Spec_Clauses
427 (Context_List : List_Id;
429 Used : in out Boolean;
430 Withed : in out Boolean;
431 Exit_On_Self : Boolean := False)
433 Nam_Ent : constant Entity_Id := Entity (Name (Clause));
441 Cont_Item := First (Context_List);
442 while Present (Cont_Item) loop
444 -- Stop the search since the context items after Cont_Item
445 -- have already been examined in a previous iteration of
446 -- the reverse loop in Check_Redundant_Withs.
449 and Cont_Item = Clause
454 -- Package use clause
456 if Nkind (Cont_Item) = N_Use_Package_Clause
459 Use_Item := First (Names (Cont_Item));
460 while Present (Use_Item) and then not Used loop
461 if Entity (Use_Item) = Nam_Ent then
468 -- Package with clause. Avoid processing self, implicitly
469 -- generated with clauses or limited with clauses. Note
470 -- that we examine with clauses having pragmas Elaborate
471 -- or Elaborate_All applied to them due to cases such as:
475 -- pragma Elaborate (Pack);
477 -- In this case, the second with clause is redundant since
478 -- the pragma applies only to the first "with Pack;".
480 elsif Nkind (Cont_Item) = N_With_Clause
481 and then not Implicit_With (Cont_Item)
482 and then not Limited_Present (Cont_Item)
483 and then Cont_Item /= Clause
484 and then Entity (Name (Cont_Item)) = Nam_Ent
491 end Process_Spec_Clauses;
493 -- Start of processing for Check_Redundant_Withs
496 Clause := Last (Context_Items);
497 while Present (Clause) loop
499 -- Avoid checking implicitly generated with clauses, limited
500 -- with clauses or withs that have pragma Elaborate or
501 -- Elaborate_All applied.
503 if Nkind (Clause) = N_With_Clause
504 and then not Implicit_With (Clause)
505 and then not Limited_Present (Clause)
506 and then not Elaborate_Present (Clause)
508 -- Package body-to-spec check
510 if Present (Spec_Context_Items) then
512 Used_In_Body : Boolean := False;
513 Used_In_Spec : Boolean := False;
514 Used_Type_Or_Elab : Boolean := False;
515 Withed_In_Spec : Boolean := False;
519 (Context_List => Spec_Context_Items,
521 Used => Used_In_Spec,
522 Withed => Withed_In_Spec);
525 (Context_List => Context_Items,
527 Used => Used_In_Body,
528 Used_Type_Or_Elab => Used_Type_Or_Elab);
530 -- "Type Elab" refers to the presence of either a use
531 -- type clause, pragmas Elaborate or Elaborate_All.
533 -- +---------------+---------------------------+------+
534 -- | Spec | Body | Warn |
535 -- +--------+------+--------+------+-----------+------+
536 -- | Withed | Used | Withed | Used | Type Elab | |
537 -- | X | | X | | | X |
538 -- | X | | X | X | | |
539 -- | X | | X | | X | |
540 -- | X | | X | X | X | |
541 -- | X | X | X | | | X |
542 -- | X | X | X | | X | |
543 -- | X | X | X | X | | X |
544 -- | X | X | X | X | X | |
545 -- +--------+------+--------+------+-----------+------+
548 and then not Used_Type_Or_Elab)
551 and then not Used_In_Body)
555 Error_Msg_N ("?redundant with clause in body", Clause);
558 Used_In_Body := False;
559 Used_In_Spec := False;
560 Used_Type_Or_Elab := False;
561 Withed_In_Spec := False;
564 -- Standalone package spec or body check
568 Dont_Care : Boolean := False;
569 Withed : Boolean := False;
572 -- The mechanism for examining the context clauses of a
573 -- package spec can be applied to package body clauses.
576 (Context_List => Context_Items,
580 Exit_On_Self => True);
583 Error_Msg_N ("?redundant with clause", Clause);
591 end Check_Redundant_Withs;
593 --------------------------------
594 -- Generate_Parent_References --
595 --------------------------------
597 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is
599 P_Name : Entity_Id := P_Id;
602 Pref := Name (Parent (Defining_Entity (N)));
604 if Nkind (Pref) = N_Expanded_Name then
606 -- Done already, if the unit has been compiled indirectly as
607 -- part of the closure of its context because of inlining.
612 while Nkind (Pref) = N_Selected_Component loop
613 Change_Selected_Component_To_Expanded_Name (Pref);
614 Set_Entity (Pref, P_Name);
615 Set_Etype (Pref, Etype (P_Name));
616 Generate_Reference (P_Name, Pref, 'r');
617 Pref := Prefix (Pref);
618 P_Name := Scope (P_Name);
621 -- The guard here on P_Name is to handle the error condition where
622 -- the parent unit is missing because the file was not found.
624 if Present (P_Name) then
625 Set_Entity (Pref, P_Name);
626 Set_Etype (Pref, Etype (P_Name));
627 Generate_Reference (P_Name, Pref, 'r');
628 Style.Check_Identifier (Pref, P_Name);
630 end Generate_Parent_References;
632 -- Start of processing for Analyze_Compilation_Unit
635 Process_Compilation_Unit_Pragmas (N);
637 -- If the unit is a subunit whose parent has not been analyzed (which
638 -- indicates that the main unit is a subunit, either the current one or
639 -- one of its descendents) then the subunit is compiled as part of the
640 -- analysis of the parent, which we proceed to do. Basically this gets
641 -- handled from the top down and we don't want to do anything at this
642 -- level (i.e. this subunit will be handled on the way down from the
643 -- parent), so at this level we immediately return. If the subunit
644 -- ends up not analyzed, it means that the parent did not contain a
645 -- stub for it, or that there errors were detected in some ancestor.
647 if Nkind (Unit_Node) = N_Subunit
648 and then not Analyzed (Lib_Unit)
650 Semantics (Lib_Unit);
652 if not Analyzed (Proper_Body (Unit_Node)) then
653 if Serious_Errors_Detected > 0 then
654 Error_Msg_N ("subunit not analyzed (errors in parent unit)", N);
656 Error_Msg_N ("missing stub for subunit", N);
663 -- Analyze context (this will call Sem recursively for with'ed units)
664 -- To detect circularities among with-clauses that are not caught during
665 -- loading, we set the Context_Pending flag on the current unit. If the
666 -- flag is already set there is a potential circularity.
667 -- We exclude predefined units from this check because they are known
668 -- to be safe. We also exclude package bodies that are present because
669 -- circularities between bodies are harmless (and necessary).
671 if Context_Pending (N) then
673 Circularity : Boolean := True;
676 if Is_Predefined_File_Name
677 (Unit_File_Name (Get_Source_Unit (Unit (N))))
679 Circularity := False;
682 for U in Main_Unit + 1 .. Last_Unit loop
683 if Nkind (Unit (Cunit (U))) = N_Package_Body
684 and then not Analyzed (Cunit (U))
686 Circularity := False;
694 ("circular dependency caused by with_clauses", N);
696 ("\possibly missing limited_with clause"
697 & " in one of the following", N);
699 for U in Main_Unit .. Last_Unit loop
700 if Context_Pending (Cunit (U)) then
701 Error_Msg_Unit_1 := Get_Unit_Name (Unit (Cunit (U)));
702 Error_Msg_N ("\unit$", N);
706 raise Unrecoverable_Error;
710 Set_Context_Pending (N);
715 Set_Context_Pending (N, False);
717 -- If the unit is a package body, the spec is already loaded and must be
718 -- analyzed first, before we analyze the body.
720 if Nkind (Unit_Node) = N_Package_Body then
722 -- If no Lib_Unit, then there was a serious previous error, so just
723 -- ignore the entire analysis effort
725 if No (Lib_Unit) then
729 Semantics (Lib_Unit);
730 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
732 -- Verify that the library unit is a package declaration
734 if not Nkind_In (Unit (Lib_Unit), N_Package_Declaration,
735 N_Generic_Package_Declaration)
738 ("no legal package declaration for package body", N);
741 -- Otherwise, the entity in the declaration is visible. Update the
742 -- version to reflect dependence of this body on the spec.
745 Spec_Id := Defining_Entity (Unit (Lib_Unit));
746 Set_Is_Immediately_Visible (Spec_Id, True);
747 Version_Update (N, Lib_Unit);
749 if Nkind (Defining_Unit_Name (Unit_Node)) =
750 N_Defining_Program_Unit_Name
752 Generate_Parent_References (Unit_Node, Scope (Spec_Id));
757 -- If the unit is a subprogram body, then we similarly need to analyze
758 -- its spec. However, things are a little simpler in this case, because
759 -- here, this analysis is done only for error checking and consistency
760 -- purposes, so there's nothing else to be done.
762 elsif Nkind (Unit_Node) = N_Subprogram_Body then
763 if Acts_As_Spec (N) then
765 -- If the subprogram body is a child unit, we must create a
766 -- declaration for it, in order to properly load the parent(s).
767 -- After this, the original unit does not acts as a spec, because
768 -- there is an explicit one. If this unit appears in a context
769 -- clause, then an implicit with on the parent will be added when
770 -- installing the context. If this is the main unit, there is no
771 -- Unit_Table entry for the declaration (it has the unit number
772 -- of the main unit) and code generation is unaffected.
774 Unum := Get_Cunit_Unit_Number (N);
775 Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum));
777 if Par_Spec_Name /= No_Unit_Name then
780 (Load_Name => Par_Spec_Name,
785 if Unum /= No_Unit then
787 -- Build subprogram declaration and attach parent unit to it
788 -- This subprogram declaration does not come from source,
789 -- Nevertheless the backend must generate debugging info for
790 -- it, and this must be indicated explicitly. We also mark
791 -- the body entity as a child unit now, to prevent a
792 -- cascaded error if the spec entity cannot be entered
793 -- in its scope. Finally we create a Units table entry for
794 -- the subprogram declaration, to maintain a one-to-one
795 -- correspondence with compilation unit nodes. This is
796 -- critical for the tree traversals performed by CodePeer.
799 Loc : constant Source_Ptr := Sloc (N);
800 SCS : constant Boolean :=
801 Get_Comes_From_Source_Default;
804 Set_Comes_From_Source_Default (False);
806 Make_Compilation_Unit (Loc,
807 Context_Items => New_Copy_List (Context_Items (N)),
809 Make_Subprogram_Declaration (Sloc (N),
812 (Specification (Unit_Node))),
814 Make_Compilation_Unit_Aux (Loc));
816 Set_Library_Unit (N, Lib_Unit);
817 Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
818 Make_Child_Decl_Unit (N);
819 Semantics (Lib_Unit);
821 -- Now that a separate declaration exists, the body
822 -- of the child unit does not act as spec any longer.
824 Set_Acts_As_Spec (N, False);
825 Set_Is_Child_Unit (Defining_Entity (Unit_Node));
826 Set_Debug_Info_Needed (Defining_Entity (Unit (Lib_Unit)));
827 Set_Comes_From_Source_Default (SCS);
832 -- Here for subprogram with separate declaration
835 Semantics (Lib_Unit);
836 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
837 Version_Update (N, Lib_Unit);
840 -- If this is a child unit, generate references to the parents
842 if Nkind (Defining_Unit_Name (Specification (Unit_Node))) =
843 N_Defining_Program_Unit_Name
845 Generate_Parent_References (
846 Specification (Unit_Node),
847 Scope (Defining_Entity (Unit (Lib_Unit))));
851 -- If it is a child unit, the parent must be elaborated first and we
852 -- update version, since we are dependent on our parent.
854 if Is_Child_Spec (Unit_Node) then
856 -- The analysis of the parent is done with style checks off
859 Save_Style_Check : constant Boolean := Style_Check;
860 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
861 Cunit_Boolean_Restrictions_Save;
864 if not GNAT_Mode then
865 Style_Check := False;
868 Semantics (Parent_Spec (Unit_Node));
869 Version_Update (N, Parent_Spec (Unit_Node));
870 Style_Check := Save_Style_Check;
871 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
875 -- With the analysis done, install the context. Note that we can't
876 -- install the context from the with clauses as we analyze them, because
877 -- each with clause must be analyzed in a clean visibility context, so
878 -- we have to wait and install them all at once.
882 if Is_Child_Spec (Unit_Node) then
884 -- Set the entities of all parents in the program_unit_name
886 Generate_Parent_References (
887 Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node))));
890 -- All components of the context: with-clauses, library unit, ancestors
891 -- if any, (and their context) are analyzed and installed.
893 -- Call special debug routine sm if this is the main unit
895 if Current_Sem_Unit = Main_Unit then
899 -- Now analyze the unit (package, subprogram spec, body) itself
903 if Warn_On_Redundant_Constructs then
904 Check_Redundant_Withs (Context_Items (N));
906 if Nkind (Unit_Node) = N_Package_Body then
907 Check_Redundant_Withs
908 (Context_Items => Context_Items (N),
909 Spec_Context_Items => Context_Items (Lib_Unit));
913 -- The above call might have made Unit_Node an N_Subprogram_Body from
914 -- something else, so propagate any Acts_As_Spec flag.
916 if Nkind (Unit_Node) = N_Subprogram_Body
917 and then Acts_As_Spec (Unit_Node)
919 Set_Acts_As_Spec (N);
922 -- Register predefined units in Rtsfind
925 Unum : constant Unit_Number_Type := Get_Source_Unit (Sloc (N));
927 if Is_Predefined_File_Name (Unit_File_Name (Unum)) then
928 Set_RTU_Loaded (Unit_Node);
932 -- Treat compilation unit pragmas that appear after the library unit
934 if Present (Pragmas_After (Aux_Decls_Node (N))) then
936 Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N)));
938 while Present (Prag_Node) loop
945 -- Generate distribution stubs if requested and no error
948 and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
950 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
951 and then not Fatal_Error (Main_Unit)
953 if Is_RCI_Pkg_Spec_Or_Body (N) then
955 -- Regular RCI package
957 Add_Stub_Constructs (N);
959 elsif (Nkind (Unit_Node) = N_Package_Declaration
960 and then Is_Shared_Passive (Defining_Entity
961 (Specification (Unit_Node))))
962 or else (Nkind (Unit_Node) = N_Package_Body
964 Is_Shared_Passive (Corresponding_Spec (Unit_Node)))
966 -- Shared passive package
968 Add_Stub_Constructs (N);
970 elsif Nkind (Unit_Node) = N_Package_Instantiation
972 Is_Remote_Call_Interface
973 (Defining_Entity (Specification (Instance_Spec (Unit_Node))))
975 -- Instantiation of a RCI generic package
977 Add_Stub_Constructs (N);
981 -- Remove unit from visibility, so that environment is clean for
982 -- the next compilation, which is either the main unit or some
983 -- other unit in the context.
985 if Nkind_In (Unit_Node, N_Package_Declaration,
986 N_Package_Renaming_Declaration,
987 N_Subprogram_Declaration)
988 or else Nkind (Unit_Node) in N_Generic_Declaration
990 (Nkind (Unit_Node) = N_Subprogram_Body
991 and then Acts_As_Spec (Unit_Node))
993 Remove_Unit_From_Visibility (Defining_Entity (Unit_Node));
995 -- If the unit is an instantiation whose body will be elaborated for
996 -- inlining purposes, use the proper entity of the instance. The
997 -- entity may be missing if the instantiation was illegal.
999 elsif Nkind (Unit_Node) = N_Package_Instantiation
1000 and then not Error_Posted (Unit_Node)
1001 and then Present (Instance_Spec (Unit_Node))
1003 Remove_Unit_From_Visibility
1004 (Defining_Entity (Instance_Spec (Unit_Node)));
1006 elsif Nkind (Unit_Node) = N_Package_Body
1007 or else (Nkind (Unit_Node) = N_Subprogram_Body
1008 and then not Acts_As_Spec (Unit_Node))
1010 -- Bodies that are not the main unit are compiled if they are generic
1011 -- or contain generic or inlined units. Their analysis brings in the
1012 -- context of the corresponding spec (unit declaration) which must be
1013 -- removed as well, to return the compilation environment to its
1016 Remove_Context (Lib_Unit);
1017 Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False);
1020 -- Last step is to deinstall the context we just installed as well as
1021 -- the unit just compiled.
1025 -- If this is the main unit and we are generating code, we must check
1026 -- that all generic units in the context have a body if they need it,
1027 -- even if they have not been instantiated. In the absence of .ali files
1028 -- for generic units, we must force the load of the body, just to
1029 -- produce the proper error if the body is absent. We skip this
1030 -- verification if the main unit itself is generic.
1032 if Get_Cunit_Unit_Number (N) = Main_Unit
1033 and then Operating_Mode = Generate_Code
1034 and then Expander_Active
1036 -- Check whether the source for the body of the unit must be included
1037 -- in a standalone library.
1039 Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit));
1041 -- Indicate that the main unit is now analyzed, to catch possible
1042 -- circularities between it and generic bodies. Remove main unit from
1043 -- visibility. This might seem superfluous, but the main unit must
1044 -- not be visible in the generic body expansions that follow.
1046 Set_Analyzed (N, True);
1047 Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False);
1052 Un : Unit_Number_Type;
1054 Save_Style_Check : constant Boolean := Style_Check;
1055 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
1056 Cunit_Boolean_Restrictions_Save;
1059 Item := First (Context_Items (N));
1060 while Present (Item) loop
1062 -- Check for explicit with clause
1064 if Nkind (Item) = N_With_Clause
1065 and then not Implicit_With (Item)
1067 -- Ada 2005 (AI-50217): Ignore limited-withed units
1069 and then not Limited_Present (Item)
1071 Nam := Entity (Name (Item));
1073 -- Compile generic subprogram, unless it is intrinsic or
1074 -- imported so no body is required, or generic package body
1075 -- if the package spec requires a body.
1077 if (Is_Generic_Subprogram (Nam)
1078 and then not Is_Intrinsic_Subprogram (Nam)
1079 and then not Is_Imported (Nam))
1080 or else (Ekind (Nam) = E_Generic_Package
1081 and then Unit_Requires_Body (Nam))
1083 Style_Check := False;
1085 if Present (Renamed_Object (Nam)) then
1088 (Load_Name => Get_Body_Name
1090 (Unit_Declaration_Node
1091 (Renamed_Object (Nam)))),
1099 (Load_Name => Get_Body_Name
1100 (Get_Unit_Name (Item)),
1107 if Un = No_Unit then
1109 ("body of generic unit& not found", Item, Nam);
1112 elsif not Analyzed (Cunit (Un))
1113 and then Un /= Main_Unit
1114 and then not Fatal_Error (Un)
1116 Style_Check := False;
1117 Semantics (Cunit (Un));
1125 Style_Check := Save_Style_Check;
1126 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
1130 -- Deal with creating elaboration Boolean if needed. We create an
1131 -- elaboration boolean only for units that come from source since
1132 -- units manufactured by the compiler never need elab checks.
1134 if Comes_From_Source (N)
1135 and then Nkind_In (Unit_Node, N_Package_Declaration,
1136 N_Generic_Package_Declaration,
1137 N_Subprogram_Declaration,
1138 N_Generic_Subprogram_Declaration)
1141 Loc : constant Source_Ptr := Sloc (N);
1142 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
1145 Spec_Id := Defining_Entity (Unit_Node);
1146 Generate_Definition (Spec_Id);
1148 -- See if an elaboration entity is required for possible access
1149 -- before elaboration checking. Note that we must allow for this
1150 -- even if -gnatE is not set, since a client may be compiled in
1151 -- -gnatE mode and reference the entity.
1153 -- These entities are also used by the binder to prevent multiple
1154 -- attempts to execute the elaboration code for the library case
1155 -- where the elaboration routine might otherwise be called more
1158 -- Case of units which do not require elaboration checks
1161 -- Pure units do not need checks
1165 -- Preelaborated units do not need checks
1167 or else Is_Preelaborated (Spec_Id)
1169 -- No checks needed if pragma Elaborate_Body present
1171 or else Has_Pragma_Elaborate_Body (Spec_Id)
1173 -- No checks needed if unit does not require a body
1175 or else not Unit_Requires_Body (Spec_Id)
1177 -- No checks needed for predefined files
1179 or else Is_Predefined_File_Name (Unit_File_Name (Unum))
1181 -- No checks required if no separate spec
1183 or else Acts_As_Spec (N)
1185 -- This is a case where we only need the entity for
1186 -- checking to prevent multiple elaboration checks.
1188 Set_Elaboration_Entity_Required (Spec_Id, False);
1190 -- Case of elaboration entity is required for access before
1191 -- elaboration checking (so certainly we must build it!)
1194 Set_Elaboration_Entity_Required (Spec_Id, True);
1197 Build_Elaboration_Entity (N, Spec_Id);
1201 -- Freeze the compilation unit entity. This for sure is needed because
1202 -- of some warnings that can be output (see Freeze_Subprogram), but may
1203 -- in general be required. If freezing actions result, place them in the
1204 -- compilation unit actions list, and analyze them.
1207 Loc : constant Source_Ptr := Sloc (N);
1208 L : constant List_Id :=
1209 Freeze_Entity (Cunit_Entity (Current_Sem_Unit), Loc);
1211 while Is_Non_Empty_List (L) loop
1212 Insert_Library_Level_Action (Remove_Head (L));
1218 if Nkind (Unit_Node) = N_Package_Declaration
1219 and then Get_Cunit_Unit_Number (N) /= Main_Unit
1220 and then Expander_Active
1223 Save_Style_Check : constant Boolean := Style_Check;
1224 Save_Warning : constant Warning_Mode_Type := Warning_Mode;
1225 Options : Style_Check_Options;
1228 Save_Style_Check_Options (Options);
1229 Reset_Style_Check_Options;
1230 Opt.Warning_Mode := Suppress;
1231 Check_Body_For_Inlining (N, Defining_Entity (Unit_Node));
1233 Reset_Style_Check_Options;
1234 Set_Style_Check_Options (Options);
1235 Style_Check := Save_Style_Check;
1236 Warning_Mode := Save_Warning;
1240 -- If we are generating obsolescent warnings, then here is where we
1241 -- generate them for the with'ed items. The reason for this special
1242 -- processing is that the normal mechanism of generating the warnings
1243 -- for referenced entities does not work for context clause references.
1244 -- That's because when we first analyze the context, it is too early to
1245 -- know if the with'ing unit is itself obsolescent (which suppresses
1248 if not GNAT_Mode and then Warn_On_Obsolescent_Feature then
1250 -- Push current compilation unit as scope, so that the test for
1251 -- being within an obsolescent unit will work correctly.
1253 Push_Scope (Defining_Entity (Unit_Node));
1255 -- Loop through context items to deal with with clauses
1263 Item := First (Context_Items (N));
1264 while Present (Item) loop
1265 if Nkind (Item) = N_With_Clause
1267 -- Suppress this check in limited-withed units. Further work
1268 -- needed here if we decide to incorporate this check on
1269 -- limited-withed units.
1271 and then not Limited_Present (Item)
1274 Ent := Entity (Nam);
1276 if Is_Obsolescent (Ent) then
1277 Output_Obsolescent_Entity_Warnings (Nam, Ent);
1285 -- Remove temporary install of current unit as scope
1289 end Analyze_Compilation_Unit;
1291 ---------------------
1292 -- Analyze_Context --
1293 ---------------------
1295 procedure Analyze_Context (N : Node_Id) is
1296 Ukind : constant Node_Kind := Nkind (Unit (N));
1300 -- First process all configuration pragmas at the start of the context
1301 -- items. Strictly these are not part of the context clause, but that
1302 -- is where the parser puts them. In any case for sure we must analyze
1303 -- these before analyzing the actual context items, since they can have
1304 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1305 -- be with'ed as a result of changing categorizations in Ada 2005).
1307 Item := First (Context_Items (N));
1308 while Present (Item)
1309 and then Nkind (Item) = N_Pragma
1310 and then Pragma_Name (Item) in Configuration_Pragma_Names
1316 -- This is the point at which we capture the configuration settings
1317 -- for the unit. At the moment only the Optimize_Alignment setting
1318 -- needs to be captured. Probably more later ???
1320 if Optimize_Alignment_Local then
1321 Set_OA_Setting (Current_Sem_Unit, 'L');
1323 Set_OA_Setting (Current_Sem_Unit, Optimize_Alignment);
1326 -- Loop through actual context items. This is done in two passes:
1328 -- a) The first pass analyzes non-limited with-clauses and also any
1329 -- configuration pragmas (we need to get the latter analyzed right
1330 -- away, since they can affect processing of subsequent items.
1332 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1334 while Present (Item) loop
1336 -- For with clause, analyze the with clause, and then update the
1337 -- version, since we are dependent on a unit that we with.
1339 if Nkind (Item) = N_With_Clause
1340 and then not Limited_Present (Item)
1342 -- Skip analyzing with clause if no unit, nothing to do (this
1343 -- happens for a with that references a non-existent unit). Skip
1344 -- as well if this is a with_clause for the main unit, which
1345 -- happens if a subunit has a useless with_clause on its parent.
1347 if Present (Library_Unit (Item)) then
1348 if Library_Unit (Item) /= Cunit (Current_Sem_Unit) then
1352 Set_Entity (Name (Item), Cunit_Entity (Current_Sem_Unit));
1356 if not Implicit_With (Item) then
1357 Version_Update (N, Library_Unit (Item));
1360 -- Skip pragmas. Configuration pragmas at the start were handled in
1361 -- the loop above, and remaining pragmas are not processed until we
1362 -- actually install the context (see Install_Context). We delay the
1363 -- analysis of these pragmas to make sure that we have installed all
1364 -- the implicit with's on parent units.
1366 -- Skip use clauses at this stage, since we don't want to do any
1367 -- installing of potentially use-visible entities until we
1368 -- actually install the complete context (in Install_Context).
1369 -- Otherwise things can get installed in the wrong context.
1378 -- Second pass: examine all limited_with clauses. All other context
1379 -- items are ignored in this pass.
1381 Item := First (Context_Items (N));
1382 while Present (Item) loop
1383 if Nkind (Item) = N_With_Clause
1384 and then Limited_Present (Item)
1386 -- No need to check errors on implicitly generated limited-with
1389 if not Implicit_With (Item) then
1391 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1392 -- properly rejected, including renaming declarations.
1394 if not Nkind_In (Ukind, N_Package_Declaration,
1395 N_Subprogram_Declaration)
1396 and then Ukind not in N_Generic_Declaration
1397 and then Ukind not in N_Generic_Instantiation
1399 Error_Msg_N ("limited with_clause not allowed here", Item);
1401 -- Check wrong use of a limited with clause applied to the
1402 -- compilation unit containing the limited-with clause.
1404 -- limited with P.Q;
1405 -- package P.Q is ...
1407 elsif Unit (Library_Unit (Item)) = Unit (N) then
1408 Error_Msg_N ("wrong use of limited-with clause", Item);
1410 -- Check wrong use of limited-with clause applied to some
1411 -- immediate ancestor.
1413 elsif Is_Child_Spec (Unit (N)) then
1415 Lib_U : constant Entity_Id := Unit (Library_Unit (Item));
1419 P := Parent_Spec (Unit (N));
1421 if Unit (P) = Lib_U then
1422 Error_Msg_N ("limited with_clause of immediate "
1423 & "ancestor not allowed", Item);
1427 exit when not Is_Child_Spec (Unit (P));
1428 P := Parent_Spec (Unit (P));
1433 -- Check if the limited-withed unit is already visible through
1434 -- some context clause of the current compilation unit or some
1435 -- ancestor of the current compilation unit.
1438 Lim_Unit_Name : constant Node_Id := Name (Item);
1439 Comp_Unit : Node_Id;
1441 Unit_Name : Node_Id;
1446 It := First (Context_Items (Comp_Unit));
1447 while Present (It) loop
1449 and then Nkind (It) = N_With_Clause
1450 and then not Limited_Present (It)
1452 Nkind_In (Unit (Library_Unit (It)),
1453 N_Package_Declaration,
1454 N_Package_Renaming_Declaration)
1456 if Nkind (Unit (Library_Unit (It))) =
1457 N_Package_Declaration
1459 Unit_Name := Name (It);
1461 Unit_Name := Name (Unit (Library_Unit (It)));
1464 -- Check if the named package (or some ancestor)
1465 -- leaves visible the full-view of the unit given
1466 -- in the limited-with clause
1469 if Designate_Same_Unit (Lim_Unit_Name,
1472 Error_Msg_Sloc := Sloc (It);
1474 ("simultaneous visibility of limited "
1475 & "and unlimited views not allowed",
1478 ("\unlimited view visible through "
1479 & "context clause #",
1483 elsif Nkind (Unit_Name) = N_Identifier then
1487 Unit_Name := Prefix (Unit_Name);
1494 exit when not Is_Child_Spec (Unit (Comp_Unit));
1496 Comp_Unit := Parent_Spec (Unit (Comp_Unit));
1501 -- Skip analyzing with clause if no unit, see above
1503 if Present (Library_Unit (Item)) then
1507 -- A limited_with does not impose an elaboration order, but
1508 -- there is a semantic dependency for recompilation purposes.
1510 if not Implicit_With (Item) then
1511 Version_Update (N, Library_Unit (Item));
1514 -- Pragmas and use clauses and with clauses other than limited
1515 -- with's are ignored in this pass through the context items.
1523 end Analyze_Context;
1525 -------------------------------
1526 -- Analyze_Package_Body_Stub --
1527 -------------------------------
1529 procedure Analyze_Package_Body_Stub (N : Node_Id) is
1530 Id : constant Entity_Id := Defining_Identifier (N);
1534 -- The package declaration must be in the current declarative part
1536 Check_Stub_Level (N);
1537 Nam := Current_Entity_In_Scope (Id);
1539 if No (Nam) or else not Is_Package_Or_Generic_Package (Nam) then
1540 Error_Msg_N ("missing specification for package stub", N);
1542 elsif Has_Completion (Nam)
1543 and then Present (Corresponding_Body (Unit_Declaration_Node (Nam)))
1545 Error_Msg_N ("duplicate or redundant stub for package", N);
1548 -- Indicate that the body of the package exists. If we are doing
1549 -- only semantic analysis, the stub stands for the body. If we are
1550 -- generating code, the existence of the body will be confirmed
1551 -- when we load the proper body.
1553 Set_Has_Completion (Nam);
1554 Set_Scope (Defining_Entity (N), Current_Scope);
1555 Generate_Reference (Nam, Id, 'b');
1556 Analyze_Proper_Body (N, Nam);
1558 end Analyze_Package_Body_Stub;
1560 -------------------------
1561 -- Analyze_Proper_Body --
1562 -------------------------
1564 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is
1565 Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
1566 Unum : Unit_Number_Type;
1568 procedure Optional_Subunit;
1569 -- This procedure is called when the main unit is a stub, or when we
1570 -- are not generating code. In such a case, we analyze the subunit if
1571 -- present, which is user-friendly and in fact required for ASIS, but
1572 -- we don't complain if the subunit is missing.
1574 ----------------------
1575 -- Optional_Subunit --
1576 ----------------------
1578 procedure Optional_Subunit is
1579 Comp_Unit : Node_Id;
1582 -- Try to load subunit, but ignore any errors that occur during
1583 -- the loading of the subunit, by using the special feature in
1584 -- Errout to ignore all errors. Note that Fatal_Error will still
1585 -- be set, so we will be able to check for this case below.
1587 if not ASIS_Mode then
1588 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
1593 (Load_Name => Subunit_Name,
1598 if not ASIS_Mode then
1599 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
1602 -- All done if we successfully loaded the subunit
1605 and then (not Fatal_Error (Unum) or else Try_Semantics)
1607 Comp_Unit := Cunit (Unum);
1609 -- If the file was empty or seriously mangled, the unit itself may
1612 if No (Unit (Comp_Unit)) then
1614 ("subunit does not contain expected proper body", N);
1616 elsif Nkind (Unit (Comp_Unit)) /= N_Subunit then
1618 ("expected SEPARATE subunit, found child unit",
1619 Cunit_Entity (Unum));
1621 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1622 Analyze_Subunit (Comp_Unit);
1623 Set_Library_Unit (N, Comp_Unit);
1626 elsif Unum = No_Unit
1627 and then Present (Nam)
1629 if Is_Protected_Type (Nam) then
1630 Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N));
1632 Set_Corresponding_Body (
1633 Unit_Declaration_Node (Nam), Defining_Identifier (N));
1636 end Optional_Subunit;
1638 -- Start of processing for Analyze_Proper_Body
1641 -- If the subunit is already loaded, it means that the main unit is a
1642 -- subunit, and that the current unit is one of its parents which was
1643 -- being analyzed to provide the needed context for the analysis of the
1644 -- subunit. In this case we analyze the subunit and continue with the
1645 -- parent, without looking a subsequent subunits.
1647 if Is_Loaded (Subunit_Name) then
1649 -- If the proper body is already linked to the stub node, the stub is
1650 -- in a generic unit and just needs analyzing.
1652 if Present (Library_Unit (N)) then
1653 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1654 Analyze_Subunit (Library_Unit (N));
1656 -- Otherwise we must load the subunit and link to it
1659 -- Load the subunit, this must work, since we originally loaded
1660 -- the subunit earlier on. So this will not really load it, just
1661 -- give access to it.
1665 (Load_Name => Subunit_Name,
1670 -- And analyze the subunit in the parent context (note that we
1671 -- do not call Semantics, since that would remove the parent
1672 -- context). Because of this, we have to manually reset the
1673 -- compiler state to Analyzing since it got destroyed by Load.
1675 if Unum /= No_Unit then
1676 Compiler_State := Analyzing;
1678 -- Check that the proper body is a subunit and not a child
1679 -- unit. If the unit was previously loaded, the error will
1680 -- have been emitted when copying the generic node, so we
1681 -- just return to avoid cascaded errors.
1683 if Nkind (Unit (Cunit (Unum))) /= N_Subunit then
1687 Set_Corresponding_Stub (Unit (Cunit (Unum)), N);
1688 Analyze_Subunit (Cunit (Unum));
1689 Set_Library_Unit (N, Cunit (Unum));
1693 -- If the main unit is a subunit, then we are just performing semantic
1694 -- analysis on that subunit, and any other subunits of any parent unit
1695 -- should be ignored, except that if we are building trees for ASIS
1696 -- usage we want to annotate the stub properly.
1698 elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
1699 and then Subunit_Name /= Unit_Name (Main_Unit)
1705 -- But before we return, set the flag for unloaded subunits. This
1706 -- will suppress junk warnings of variables in the same declarative
1707 -- part (or a higher level one) that are in danger of looking unused
1708 -- when in fact there might be a declaration in the subunit that we
1709 -- do not intend to load.
1711 Unloaded_Subunits := True;
1714 -- If the subunit is not already loaded, and we are generating code,
1715 -- then this is the case where compilation started from the parent,
1716 -- and we are generating code for an entire subunit tree. In that
1717 -- case we definitely need to load the subunit.
1719 -- In order to continue the analysis with the rest of the parent,
1720 -- and other subunits, we load the unit without requiring its
1721 -- presence, and emit a warning if not found, rather than terminating
1722 -- the compilation abruptly, as for other missing file problems.
1724 elsif Original_Operating_Mode = Generate_Code then
1726 -- If the proper body is already linked to the stub node,
1727 -- the stub is in a generic unit and just needs analyzing.
1729 -- We update the version. Although we are not technically
1730 -- semantically dependent on the subunit, given our approach
1731 -- of macro substitution of subunits, it makes sense to
1732 -- include it in the version identification.
1734 if Present (Library_Unit (N)) then
1735 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1736 Analyze_Subunit (Library_Unit (N));
1737 Version_Update (Cunit (Main_Unit), Library_Unit (N));
1739 -- Otherwise we must load the subunit and link to it
1744 (Load_Name => Subunit_Name,
1749 -- Give message if we did not get the unit
1750 -- Emit warning even if missing subunit is not
1751 -- within main unit, to simplify debugging.
1753 if Original_Operating_Mode = Generate_Code
1754 and then Unum = No_Unit
1756 Error_Msg_Unit_1 := Subunit_Name;
1758 Get_File_Name (Subunit_Name, Subunit => True);
1760 ("subunit$$ in file{ not found?!!", N);
1761 Subunits_Missing := True;
1764 -- Load_Unit may reset Compiler_State, since it may have been
1765 -- necessary to parse an additional units, so we make sure
1766 -- that we reset it to the Analyzing state.
1768 Compiler_State := Analyzing;
1770 if Unum /= No_Unit then
1771 if Debug_Flag_L then
1772 Write_Str ("*** Loaded subunit from stub. Analyze");
1777 Comp_Unit : constant Node_Id := Cunit (Unum);
1780 -- Check for child unit instead of subunit
1782 if Nkind (Unit (Comp_Unit)) /= N_Subunit then
1784 ("expected SEPARATE subunit, found child unit",
1785 Cunit_Entity (Unum));
1787 -- OK, we have a subunit
1790 -- Set corresponding stub (even if errors)
1792 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1794 -- Collect SCO information for loaded subunit if we are
1795 -- in the main unit).
1799 In_Extended_Main_Source_Unit
1800 (Cunit_Entity (Current_Sem_Unit))
1805 -- Analyze the unit if semantics active
1807 if not Fatal_Error (Unum) or else Try_Semantics then
1808 Analyze_Subunit (Comp_Unit);
1811 -- Set the library unit pointer in any case
1813 Set_Library_Unit (N, Comp_Unit);
1815 -- We update the version. Although we are not technically
1816 -- semantically dependent on the subunit, given our
1817 -- approach of macro substitution of subunits, it makes
1818 -- sense to include it in the version identification.
1820 Version_Update (Cunit (Main_Unit), Comp_Unit);
1826 -- The remaining case is when the subunit is not already loaded and
1827 -- we are not generating code. In this case we are just performing
1828 -- semantic analysis on the parent, and we are not interested in
1829 -- the subunit. For subprograms, analyze the stub as a body. For
1830 -- other entities the stub has already been marked as completed.
1835 end Analyze_Proper_Body;
1837 ----------------------------------
1838 -- Analyze_Protected_Body_Stub --
1839 ----------------------------------
1841 procedure Analyze_Protected_Body_Stub (N : Node_Id) is
1842 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
1845 Check_Stub_Level (N);
1847 -- First occurrence of name may have been as an incomplete type
1849 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1850 Nam := Full_View (Nam);
1854 or else not Is_Protected_Type (Etype (Nam))
1856 Error_Msg_N ("missing specification for Protected body", N);
1858 Set_Scope (Defining_Entity (N), Current_Scope);
1859 Set_Has_Completion (Etype (Nam));
1860 Generate_Reference (Nam, Defining_Identifier (N), 'b');
1861 Analyze_Proper_Body (N, Etype (Nam));
1863 end Analyze_Protected_Body_Stub;
1865 ----------------------------------
1866 -- Analyze_Subprogram_Body_Stub --
1867 ----------------------------------
1869 -- A subprogram body stub can appear with or without a previous spec. If
1870 -- there is one, then the analysis of the body will find it and verify
1871 -- conformance. The formals appearing in the specification of the stub play
1872 -- no role, except for requiring an additional conformance check. If there
1873 -- is no previous subprogram declaration, the stub acts as a spec, and
1874 -- provides the defining entity for the subprogram.
1876 procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
1880 Check_Stub_Level (N);
1882 -- Verify that the identifier for the stub is unique within this
1883 -- declarative part.
1885 if Nkind_In (Parent (N), N_Block_Statement,
1889 Decl := First (Declarations (Parent (N)));
1890 while Present (Decl)
1893 if Nkind (Decl) = N_Subprogram_Body_Stub
1894 and then (Chars (Defining_Unit_Name (Specification (Decl))) =
1895 Chars (Defining_Unit_Name (Specification (N))))
1897 Error_Msg_N ("identifier for stub is not unique", N);
1904 -- Treat stub as a body, which checks conformance if there is a previous
1905 -- declaration, or else introduces entity and its signature.
1907 Analyze_Subprogram_Body (N);
1908 Analyze_Proper_Body (N, Empty);
1909 end Analyze_Subprogram_Body_Stub;
1911 ---------------------
1912 -- Analyze_Subunit --
1913 ---------------------
1915 -- A subunit is compiled either by itself (for semantic checking) or as
1916 -- part of compiling the parent (for code generation). In either case, by
1917 -- the time we actually process the subunit, the parent has already been
1918 -- installed and analyzed. The node N is a compilation unit, whose context
1919 -- needs to be treated here, because we come directly here from the parent
1920 -- without calling Analyze_Compilation_Unit.
1922 -- The compilation context includes the explicit context of the subunit,
1923 -- and the context of the parent, together with the parent itself. In order
1924 -- to compile the current context, we remove the one inherited from the
1925 -- parent, in order to have a clean visibility table. We restore the parent
1926 -- context before analyzing the proper body itself. On exit, we remove only
1927 -- the explicit context of the subunit.
1929 procedure Analyze_Subunit (N : Node_Id) is
1930 Lib_Unit : constant Node_Id := Library_Unit (N);
1931 Par_Unit : constant Entity_Id := Current_Scope;
1933 Lib_Spec : Node_Id := Library_Unit (Lib_Unit);
1934 Num_Scopes : Int := 0;
1935 Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id;
1936 Enclosing_Child : Entity_Id := Empty;
1937 Svg : constant Suppress_Array := Scope_Suppress;
1939 procedure Analyze_Subunit_Context;
1940 -- Capture names in use clauses of the subunit. This must be done before
1941 -- re-installing parent declarations, because items in the context must
1942 -- not be hidden by declarations local to the parent.
1944 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id);
1945 -- Recursive procedure to restore scope of all ancestors of subunit,
1946 -- from outermost in. If parent is not a subunit, the call to install
1947 -- context installs context of spec and (if parent is a child unit) the
1948 -- context of its parents as well. It is confusing that parents should
1949 -- be treated differently in both cases, but the semantics are just not
1952 procedure Re_Install_Use_Clauses;
1953 -- As part of the removal of the parent scope, the use clauses are
1954 -- removed, to be reinstalled when the context of the subunit has been
1955 -- analyzed. Use clauses may also have been affected by the analysis of
1956 -- the context of the subunit, so they have to be applied again, to
1957 -- insure that the compilation environment of the rest of the parent
1958 -- unit is identical.
1960 procedure Remove_Scope;
1961 -- Remove current scope from scope stack, and preserve the list of use
1962 -- clauses in it, to be reinstalled after context is analyzed.
1964 -----------------------------
1965 -- Analyze_Subunit_Context --
1966 -----------------------------
1968 procedure Analyze_Subunit_Context is
1971 Unit_Name : Entity_Id;
1974 Analyze_Context (N);
1976 -- Make withed units immediately visible. If child unit, make the
1977 -- ultimate parent immediately visible.
1979 Item := First (Context_Items (N));
1980 while Present (Item) loop
1981 if Nkind (Item) = N_With_Clause then
1983 -- Protect frontend against previous errors in context clauses
1985 if Nkind (Name (Item)) /= N_Selected_Component then
1986 if Error_Posted (Item) then
1990 Unit_Name := Entity (Name (Item));
1991 while Is_Child_Unit (Unit_Name) loop
1992 Set_Is_Visible_Child_Unit (Unit_Name);
1993 Unit_Name := Scope (Unit_Name);
1996 if not Is_Immediately_Visible (Unit_Name) then
1997 Set_Is_Immediately_Visible (Unit_Name);
1998 Set_Context_Installed (Item);
2003 elsif Nkind (Item) = N_Use_Package_Clause then
2004 Nam := First (Names (Item));
2005 while Present (Nam) loop
2010 elsif Nkind (Item) = N_Use_Type_Clause then
2011 Nam := First (Subtype_Marks (Item));
2012 while Present (Nam) loop
2021 -- Reset visibility of withed units. They will be made visible again
2022 -- when we install the subunit context.
2024 Item := First (Context_Items (N));
2025 while Present (Item) loop
2026 if Nkind (Item) = N_With_Clause
2028 -- Protect frontend against previous errors in context clauses
2030 and then Nkind (Name (Item)) /= N_Selected_Component
2031 and then not Error_Posted (Item)
2033 Unit_Name := Entity (Name (Item));
2034 while Is_Child_Unit (Unit_Name) loop
2035 Set_Is_Visible_Child_Unit (Unit_Name, False);
2036 Unit_Name := Scope (Unit_Name);
2039 if Context_Installed (Item) then
2040 Set_Is_Immediately_Visible (Unit_Name, False);
2041 Set_Context_Installed (Item, False);
2047 end Analyze_Subunit_Context;
2049 ------------------------
2050 -- Re_Install_Parents --
2051 ------------------------
2053 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is
2057 if Nkind (Unit (L)) = N_Subunit then
2058 Re_Install_Parents (Library_Unit (L), Scope (Scop));
2061 Install_Context (L);
2063 -- If the subunit occurs within a child unit, we must restore the
2064 -- immediate visibility of any siblings that may occur in context.
2066 if Present (Enclosing_Child) then
2067 Install_Siblings (Enclosing_Child, L);
2072 if Scop /= Par_Unit then
2073 Set_Is_Immediately_Visible (Scop);
2076 -- Make entities in scope visible again. For child units, restore
2077 -- visibility only if they are actually in context.
2079 E := First_Entity (Current_Scope);
2080 while Present (E) loop
2081 if not Is_Child_Unit (E)
2082 or else Is_Visible_Child_Unit (E)
2084 Set_Is_Immediately_Visible (E);
2090 -- A subunit appears within a body, and for a nested subunits all the
2091 -- parents are bodies. Restore full visibility of their private
2094 if Is_Package_Or_Generic_Package (Scop) then
2095 Set_In_Package_Body (Scop);
2096 Install_Private_Declarations (Scop);
2098 end Re_Install_Parents;
2100 ----------------------------
2101 -- Re_Install_Use_Clauses --
2102 ----------------------------
2104 procedure Re_Install_Use_Clauses is
2107 for J in reverse 1 .. Num_Scopes loop
2108 U := Use_Clauses (J);
2109 Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U;
2110 Install_Use_Clauses (U, Force_Installation => True);
2112 end Re_Install_Use_Clauses;
2118 procedure Remove_Scope is
2122 Num_Scopes := Num_Scopes + 1;
2123 Use_Clauses (Num_Scopes) :=
2124 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause;
2126 E := First_Entity (Current_Scope);
2127 while Present (E) loop
2128 Set_Is_Immediately_Visible (E, False);
2132 if Is_Child_Unit (Current_Scope) then
2133 Enclosing_Child := Current_Scope;
2139 -- Start of processing for Analyze_Subunit
2142 if not Is_Empty_List (Context_Items (N)) then
2144 -- Save current use clauses
2147 Remove_Context (Lib_Unit);
2149 -- Now remove parents and their context, including enclosing subunits
2150 -- and the outer parent body which is not a subunit.
2152 if Present (Lib_Spec) then
2153 Remove_Context (Lib_Spec);
2155 while Nkind (Unit (Lib_Spec)) = N_Subunit loop
2156 Lib_Spec := Library_Unit (Lib_Spec);
2158 Remove_Context (Lib_Spec);
2161 if Nkind (Unit (Lib_Unit)) = N_Subunit then
2165 if Nkind (Unit (Lib_Spec)) = N_Package_Body then
2166 Remove_Context (Library_Unit (Lib_Spec));
2170 Set_Is_Immediately_Visible (Par_Unit, False);
2172 Analyze_Subunit_Context;
2174 Re_Install_Parents (Lib_Unit, Par_Unit);
2175 Set_Is_Immediately_Visible (Par_Unit);
2177 -- If the context includes a child unit of the parent of the subunit,
2178 -- the parent will have been removed from visibility, after compiling
2179 -- that cousin in the context. The visibility of the parent must be
2180 -- restored now. This also applies if the context includes another
2181 -- subunit of the same parent which in turn includes a child unit in
2184 if Is_Package_Or_Generic_Package (Par_Unit) then
2185 if not Is_Immediately_Visible (Par_Unit)
2186 or else (Present (First_Entity (Par_Unit))
2187 and then not Is_Immediately_Visible
2188 (First_Entity (Par_Unit)))
2190 Set_Is_Immediately_Visible (Par_Unit);
2191 Install_Visible_Declarations (Par_Unit);
2192 Install_Private_Declarations (Par_Unit);
2196 Re_Install_Use_Clauses;
2197 Install_Context (N);
2199 -- Restore state of suppress flags for current body
2201 Scope_Suppress := Svg;
2203 -- If the subunit is within a child unit, then siblings of any parent
2204 -- unit that appear in the context clause of the subunit must also be
2205 -- made immediately visible.
2207 if Present (Enclosing_Child) then
2208 Install_Siblings (Enclosing_Child, N);
2213 Analyze (Proper_Body (Unit (N)));
2216 -- The subunit may contain a with_clause on a sibling of some ancestor.
2217 -- Removing the context will remove from visibility those ancestor child
2218 -- units, which must be restored to the visibility they have in the
2221 if Present (Enclosing_Child) then
2227 and then Is_Child_Unit (C)
2229 Set_Is_Immediately_Visible (C);
2230 Set_Is_Visible_Child_Unit (C);
2235 end Analyze_Subunit;
2237 ----------------------------
2238 -- Analyze_Task_Body_Stub --
2239 ----------------------------
2241 procedure Analyze_Task_Body_Stub (N : Node_Id) is
2242 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
2243 Loc : constant Source_Ptr := Sloc (N);
2246 Check_Stub_Level (N);
2248 -- First occurrence of name may have been as an incomplete type
2250 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
2251 Nam := Full_View (Nam);
2254 if No (Nam) or else not Is_Task_Type (Etype (Nam)) then
2255 Error_Msg_N ("missing specification for task body", N);
2257 Set_Scope (Defining_Entity (N), Current_Scope);
2258 Generate_Reference (Nam, Defining_Identifier (N), 'b');
2259 Set_Has_Completion (Etype (Nam));
2260 Analyze_Proper_Body (N, Etype (Nam));
2262 -- Set elaboration flag to indicate that entity is callable. This
2263 -- cannot be done in the expansion of the body itself, because the
2264 -- proper body is not in a declarative part. This is only done if
2265 -- expansion is active, because the context may be generic and the
2266 -- flag not defined yet.
2268 if Expander_Active then
2270 Make_Assignment_Statement (Loc,
2272 Make_Identifier (Loc,
2273 New_External_Name (Chars (Etype (Nam)), 'E')),
2274 Expression => New_Reference_To (Standard_True, Loc)));
2277 end Analyze_Task_Body_Stub;
2279 -------------------------
2280 -- Analyze_With_Clause --
2281 -------------------------
2283 -- Analyze the declaration of a unit in a with clause. At end, label the
2284 -- with clause with the defining entity for the unit.
2286 procedure Analyze_With_Clause (N : Node_Id) is
2288 -- Retrieve the original kind of the unit node, before analysis. If it
2289 -- is a subprogram instantiation, its analysis below will rewrite the
2290 -- node as the declaration of the wrapper package. If the same
2291 -- instantiation appears indirectly elsewhere in the context, it will
2292 -- have been analyzed already.
2294 Unit_Kind : constant Node_Kind :=
2295 Nkind (Original_Node (Unit (Library_Unit (N))));
2296 Nam : constant Node_Id := Name (N);
2298 Par_Name : Entity_Id;
2303 -- Set True if the unit currently being compiled is an internal unit
2305 Save_Style_Check : constant Boolean := Opt.Style_Check;
2306 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
2307 Cunit_Boolean_Restrictions_Save;
2310 U := Unit (Library_Unit (N));
2312 -- Several actions are skipped for dummy packages (those supplied for
2313 -- with's where no matching file could be found). Such packages are
2314 -- identified by the Sloc value being set to No_Location.
2316 if Limited_Present (N) then
2318 -- Ada 2005 (AI-50217): Build visibility structures but do not
2319 -- analyze the unit.
2321 if Sloc (U) /= No_Location then
2322 Build_Limited_Views (N);
2328 -- We reset ordinary style checking during the analysis of a with'ed
2329 -- unit, but we do NOT reset GNAT special analysis mode (the latter
2330 -- definitely *does* apply to with'ed units).
2332 if not GNAT_Mode then
2333 Style_Check := False;
2336 -- If the library unit is a predefined unit, and we are in high
2337 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
2338 -- for the analysis of the with'ed unit. This mode does not prevent
2339 -- explicit with'ing of run-time units.
2341 if Configurable_Run_Time_Mode
2343 Is_Predefined_File_Name
2344 (Unit_File_Name (Get_Source_Unit (Unit (Library_Unit (N)))))
2346 Configurable_Run_Time_Mode := False;
2347 Semantics (Library_Unit (N));
2348 Configurable_Run_Time_Mode := True;
2351 Semantics (Library_Unit (N));
2354 Intunit := Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit));
2356 if Sloc (U) /= No_Location then
2358 -- Check restrictions, except that we skip the check if this is an
2359 -- internal unit unless we are compiling the internal unit as the
2360 -- main unit. We also skip this for dummy packages.
2362 Check_Restriction_No_Dependence (Nam, N);
2364 if not Intunit or else Current_Sem_Unit = Main_Unit then
2365 Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N);
2368 -- Deal with special case of GNAT.Current_Exceptions which interacts
2369 -- with the optimization of local raise statements into gotos.
2371 if Nkind (Nam) = N_Selected_Component
2372 and then Nkind (Prefix (Nam)) = N_Identifier
2373 and then Chars (Prefix (Nam)) = Name_Gnat
2374 and then (Chars (Selector_Name (Nam)) = Name_Most_Recent_Exception
2376 Chars (Selector_Name (Nam)) = Name_Exception_Traces)
2378 Check_Restriction (No_Exception_Propagation, N);
2379 Special_Exception_Package_Used := True;
2382 -- Check for inappropriate with of internal implementation unit if we
2383 -- are not compiling an internal unit. We do not issue this message
2384 -- for implicit with's generated by the compiler itself.
2386 if Implementation_Unit_Warnings
2387 and then not Intunit
2388 and then not Implicit_With (N)
2391 U_Kind : constant Kind_Of_Unit :=
2392 Get_Kind_Of_Unit (Get_Source_Unit (U));
2395 if U_Kind = Implementation_Unit then
2396 Error_Msg_F ("& is an internal 'G'N'A'T unit?", Name (N));
2398 -- Add alternative name if available, otherwise issue a
2399 -- general warning message.
2401 if Error_Msg_Strlen /= 0 then
2402 Error_Msg_F ("\use ""~"" instead", Name (N));
2405 ("\use of this unit is non-portable " &
2406 "and version-dependent?", Name (N));
2409 elsif U_Kind = Ada_05_Unit
2410 and then Ada_Version < Ada_05
2411 and then Warn_On_Ada_2005_Compatibility
2413 Error_Msg_N ("& is an Ada 2005 unit?", Name (N));
2419 -- Semantic analysis of a generic unit is performed on a copy of
2420 -- the original tree. Retrieve the entity on which semantic info
2421 -- actually appears.
2423 if Unit_Kind in N_Generic_Declaration then
2424 E_Name := Defining_Entity (U);
2426 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2427 -- the case of an instantiation, semantic analysis above will have
2428 -- replaced the unit by its instantiated version. If the instance body
2429 -- has been generated, the instance now denotes the body entity. For
2430 -- visibility purposes we need the entity of its spec.
2432 elsif (Unit_Kind = N_Package_Instantiation
2433 or else Nkind (Original_Node (Unit (Library_Unit (N)))) =
2434 N_Package_Instantiation)
2435 and then Nkind (U) = N_Package_Body
2437 E_Name := Corresponding_Spec (U);
2439 elsif Unit_Kind = N_Package_Instantiation
2440 and then Nkind (U) = N_Package_Instantiation
2442 -- If the instance has not been rewritten as a package declaration,
2443 -- then it appeared already in a previous with clause. Retrieve
2444 -- the entity from the previous instance.
2446 E_Name := Defining_Entity (Specification (Instance_Spec (U)));
2448 elsif Unit_Kind in N_Subprogram_Instantiation then
2450 -- The visible subprogram is created during instantiation, and is
2451 -- an attribute of the wrapper package. We retrieve the wrapper
2452 -- package directly from the instantiation node. If the instance
2453 -- is inlined the unit is still an instantiation. Otherwise it has
2454 -- been rewritten as the declaration of the wrapper itself.
2456 if Nkind (U) in N_Subprogram_Instantiation then
2459 (Defining_Entity (Specification (Instance_Spec (U))));
2461 E_Name := Related_Instance (Defining_Entity (U));
2464 elsif Unit_Kind = N_Package_Renaming_Declaration
2465 or else Unit_Kind in N_Generic_Renaming_Declaration
2467 E_Name := Defining_Entity (U);
2469 elsif Unit_Kind = N_Subprogram_Body
2470 and then Nkind (Name (N)) = N_Selected_Component
2471 and then not Acts_As_Spec (Library_Unit (N))
2473 -- For a child unit that has no spec, one has been created and
2474 -- analyzed. The entity required is that of the spec.
2476 E_Name := Corresponding_Spec (U);
2479 E_Name := Defining_Entity (U);
2482 if Nkind (Name (N)) = N_Selected_Component then
2484 -- Child unit in a with clause
2486 Change_Selected_Component_To_Expanded_Name (Name (N));
2489 -- Restore style checks and restrictions
2491 Style_Check := Save_Style_Check;
2492 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
2494 -- Record the reference, but do NOT set the unit as referenced, we want
2495 -- to consider the unit as unreferenced if this is the only reference
2498 Set_Entity_With_Style_Check (Name (N), E_Name);
2499 Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False);
2501 -- Generate references and check No_Dependence restriction for parents
2503 if Is_Child_Unit (E_Name) then
2504 Pref := Prefix (Name (N));
2505 Par_Name := Scope (E_Name);
2506 while Nkind (Pref) = N_Selected_Component loop
2507 Change_Selected_Component_To_Expanded_Name (Pref);
2508 Set_Entity_With_Style_Check (Pref, Par_Name);
2510 Generate_Reference (Par_Name, Pref);
2511 Check_Restriction_No_Dependence (Pref, N);
2512 Pref := Prefix (Pref);
2514 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2515 -- is set to Standard_Standard, and no attempt should be made to
2516 -- further unwind scopes.
2518 if Par_Name /= Standard_Standard then
2519 Par_Name := Scope (Par_Name);
2523 if Present (Entity (Pref))
2524 and then not Analyzed (Parent (Parent (Entity (Pref))))
2526 -- If the entity is set without its unit being compiled, the
2527 -- original parent is a renaming, and Par_Name is the renamed
2528 -- entity. For visibility purposes, we need the original entity,
2529 -- which must be analyzed now because Load_Unit directly retrieves
2530 -- the renamed unit, and the renaming declaration itself has not
2533 Analyze (Parent (Parent (Entity (Pref))));
2534 pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name);
2535 Par_Name := Entity (Pref);
2538 Set_Entity_With_Style_Check (Pref, Par_Name);
2539 Generate_Reference (Par_Name, Pref);
2542 -- If the withed unit is System, and a system extension pragma is
2543 -- present, compile the extension now, rather than waiting for a
2544 -- visibility check on a specific entity.
2546 if Chars (E_Name) = Name_System
2547 and then Scope (E_Name) = Standard_Standard
2548 and then Present (System_Extend_Unit)
2549 and then Present_System_Aux (N)
2551 -- If the extension is not present, an error will have been emitted
2556 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2557 -- to private_with units; they will be made visible later (just before
2558 -- the private part is analyzed)
2560 if Private_Present (N) then
2561 Set_Is_Immediately_Visible (E_Name, False);
2563 end Analyze_With_Clause;
2565 ------------------------------
2566 -- Check_Private_Child_Unit --
2567 ------------------------------
2569 procedure Check_Private_Child_Unit (N : Node_Id) is
2570 Lib_Unit : constant Node_Id := Unit (N);
2572 Curr_Unit : Entity_Id;
2573 Sub_Parent : Node_Id;
2574 Priv_Child : Entity_Id;
2575 Par_Lib : Entity_Id;
2578 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
2579 -- Returns true if and only if the library unit is declared with
2580 -- an explicit designation of private.
2582 -----------------------------
2583 -- Is_Private_Library_Unit --
2584 -----------------------------
2586 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
2587 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
2590 return Private_Present (Comp_Unit);
2591 end Is_Private_Library_Unit;
2593 -- Start of processing for Check_Private_Child_Unit
2596 if Nkind_In (Lib_Unit, N_Package_Body, N_Subprogram_Body) then
2597 Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
2598 Par_Lib := Curr_Unit;
2600 elsif Nkind (Lib_Unit) = N_Subunit then
2602 -- The parent is itself a body. The parent entity is to be found in
2603 -- the corresponding spec.
2605 Sub_Parent := Library_Unit (N);
2606 Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
2608 -- If the parent itself is a subunit, Curr_Unit is the entity
2609 -- of the enclosing body, retrieve the spec entity which is
2610 -- the proper ancestor we need for the following tests.
2612 if Ekind (Curr_Unit) = E_Package_Body then
2613 Curr_Unit := Spec_Entity (Curr_Unit);
2616 Par_Lib := Curr_Unit;
2619 Curr_Unit := Defining_Entity (Lib_Unit);
2621 Par_Lib := Curr_Unit;
2622 Par_Spec := Parent_Spec (Lib_Unit);
2624 if No (Par_Spec) then
2627 Par_Lib := Defining_Entity (Unit (Par_Spec));
2631 -- Loop through context items
2633 Item := First (Context_Items (N));
2634 while Present (Item) loop
2636 -- Ada 2005 (AI-262): Allow private_with of a private child package
2637 -- in public siblings
2639 if Nkind (Item) = N_With_Clause
2640 and then not Implicit_With (Item)
2641 and then not Limited_Present (Item)
2642 and then Is_Private_Descendant (Entity (Name (Item)))
2644 Priv_Child := Entity (Name (Item));
2647 Curr_Parent : Entity_Id := Par_Lib;
2648 Child_Parent : Entity_Id := Scope (Priv_Child);
2649 Prv_Ancestor : Entity_Id := Child_Parent;
2650 Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
2653 -- If the child unit is a public child then locate the nearest
2654 -- private ancestor. Child_Parent will then be set to the
2655 -- parent of that ancestor.
2657 if not Is_Private_Library_Unit (Priv_Child) then
2658 while Present (Prv_Ancestor)
2659 and then not Is_Private_Library_Unit (Prv_Ancestor)
2661 Prv_Ancestor := Scope (Prv_Ancestor);
2664 if Present (Prv_Ancestor) then
2665 Child_Parent := Scope (Prv_Ancestor);
2669 while Present (Curr_Parent)
2670 and then Curr_Parent /= Standard_Standard
2671 and then Curr_Parent /= Child_Parent
2674 Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
2675 Curr_Parent := Scope (Curr_Parent);
2678 if No (Curr_Parent) then
2679 Curr_Parent := Standard_Standard;
2682 if Curr_Parent /= Child_Parent then
2683 if Ekind (Priv_Child) = E_Generic_Package
2684 and then Chars (Priv_Child) in Text_IO_Package_Name
2685 and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
2688 ("& is a nested package, not a compilation unit",
2689 Name (Item), Priv_Child);
2693 ("unit in with clause is private child unit!", Item);
2695 ("\current unit must also have parent&!",
2696 Item, Child_Parent);
2700 or else Private_Present (Item)
2701 or else Nkind_In (Lib_Unit, N_Package_Body, N_Subunit)
2702 or else (Nkind (Lib_Unit) = N_Subprogram_Body
2703 and then not Acts_As_Spec (Parent (Lib_Unit)))
2709 ("current unit must also be private descendant of&",
2710 Item, Child_Parent);
2718 end Check_Private_Child_Unit;
2720 ----------------------
2721 -- Check_Stub_Level --
2722 ----------------------
2724 procedure Check_Stub_Level (N : Node_Id) is
2725 Par : constant Node_Id := Parent (N);
2726 Kind : constant Node_Kind := Nkind (Par);
2729 if Nkind_In (Kind, N_Package_Body,
2733 and then Nkind_In (Parent (Par), N_Compilation_Unit, N_Subunit)
2737 -- In an instance, a missing stub appears at any level. A warning
2738 -- message will have been emitted already for the missing file.
2740 elsif not In_Instance then
2741 Error_Msg_N ("stub cannot appear in an inner scope", N);
2743 elsif Expander_Active then
2744 Error_Msg_N ("missing proper body", N);
2746 end Check_Stub_Level;
2748 ------------------------
2749 -- Expand_With_Clause --
2750 ------------------------
2752 procedure Expand_With_Clause (Item : Node_Id; Nam : Node_Id; N : Node_Id) is
2753 Loc : constant Source_Ptr := Sloc (Nam);
2754 Ent : constant Entity_Id := Entity (Nam);
2758 function Build_Unit_Name (Nam : Node_Id) return Node_Id;
2759 -- Build name to be used in implicit with_clause. In most cases this
2760 -- is the source name, but if renamings are present we must make the
2761 -- original unit visible, not the one it renames. The entity in the
2762 -- with clause is the renamed unit, but the identifier is the one from
2763 -- the source, which allows us to recover the unit renaming.
2765 ---------------------
2766 -- Build_Unit_Name --
2767 ---------------------
2769 function Build_Unit_Name (Nam : Node_Id) return Node_Id is
2771 Renaming : Entity_Id;
2775 if Nkind (Nam) = N_Identifier then
2777 -- If the parent unit P in the name of the with_clause for P.Q
2778 -- is a renaming of package R, then the entity of the parent is
2779 -- set to R, but the identifier retains Chars (P) to be consistent
2780 -- with the source (see details in lib-load). However, the
2781 -- implicit_with_clause for the parent must make the entity for
2782 -- P visible, because P.Q may be used as a prefix within the
2783 -- current unit. The entity for P is the current_entity with that
2784 -- name, because the package renaming declaration for it has just
2785 -- been analyzed. Note that this case can only happen if P.Q has
2786 -- already appeared in a previous with_clause in a related unit,
2787 -- such as the library body of the current unit.
2789 if Chars (Nam) /= Chars (Entity (Nam)) then
2790 Renaming := Current_Entity (Nam);
2791 pragma Assert (Renamed_Entity (Renaming) = Entity (Nam));
2792 return New_Occurrence_Of (Renaming, Loc);
2795 return New_Occurrence_Of (Entity (Nam), Loc);
2799 Ent := Entity (Nam);
2801 if Present (Entity (Selector_Name (Nam)))
2802 and then Chars (Entity (Selector_Name (Nam))) /= Chars (Ent)
2804 Nkind (Unit_Declaration_Node (Entity (Selector_Name (Nam))))
2805 = N_Package_Renaming_Declaration
2807 -- The name in the with_clause is of the form A.B.C, and B
2808 -- is given by a renaming declaration. In that case we may
2809 -- not have analyzed the unit for B, but replaced it directly
2810 -- in lib-load with the unit it renames. We have to make A.B
2811 -- visible, so analyze the declaration for B now, in case it
2812 -- has not been done yet.
2814 Ent := Entity (Selector_Name (Nam));
2817 (Unit_Declaration_Node (Entity (Selector_Name (Nam)))));
2821 Make_Expanded_Name (Loc,
2822 Chars => Chars (Entity (Nam)),
2823 Prefix => Build_Unit_Name (Prefix (Nam)),
2824 Selector_Name => New_Occurrence_Of (Ent, Loc));
2825 Set_Entity (Result, Ent);
2828 end Build_Unit_Name;
2830 -- Start of processing for Expand_With_Clause
2833 New_Nodes_OK := New_Nodes_OK + 1;
2835 Make_With_Clause (Loc,
2836 Name => Build_Unit_Name (Nam));
2838 P := Parent (Unit_Declaration_Node (Ent));
2839 Set_Library_Unit (Withn, P);
2840 Set_Corresponding_Spec (Withn, Ent);
2841 Set_First_Name (Withn, True);
2842 Set_Implicit_With (Withn, True);
2844 -- If the unit is a package declaration, a private_with_clause on a
2845 -- child unit implies the implicit with on the parent is also private.
2847 if Nkind (Unit (N)) = N_Package_Declaration then
2848 Set_Private_Present (Withn, Private_Present (Item));
2851 Prepend (Withn, Context_Items (N));
2852 Mark_Rewrite_Insertion (Withn);
2853 Install_Withed_Unit (Withn);
2855 if Nkind (Nam) = N_Expanded_Name then
2856 Expand_With_Clause (Item, Prefix (Nam), N);
2859 New_Nodes_OK := New_Nodes_OK - 1;
2860 end Expand_With_Clause;
2862 -----------------------
2863 -- Get_Parent_Entity --
2864 -----------------------
2866 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
2868 if Nkind (Unit) = N_Package_Body
2869 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
2871 return Defining_Entity
2872 (Specification (Instance_Spec (Original_Node (Unit))));
2873 elsif Nkind (Unit) = N_Package_Instantiation then
2874 return Defining_Entity (Specification (Instance_Spec (Unit)));
2876 return Defining_Entity (Unit);
2878 end Get_Parent_Entity;
2880 ---------------------
2881 -- Has_With_Clause --
2882 ---------------------
2884 function Has_With_Clause
2887 Is_Limited : Boolean := False) return Boolean
2891 function Named_Unit (Clause : Node_Id) return Entity_Id;
2892 -- Return the entity for the unit named in a [limited] with clause
2898 function Named_Unit (Clause : Node_Id) return Entity_Id is
2900 if Nkind (Name (Clause)) = N_Selected_Component then
2901 return Entity (Selector_Name (Name (Clause)));
2903 return Entity (Name (Clause));
2907 -- Start of processing for Has_With_Clause
2910 if Present (Context_Items (C_Unit)) then
2911 Item := First (Context_Items (C_Unit));
2912 while Present (Item) loop
2913 if Nkind (Item) = N_With_Clause
2914 and then Limited_Present (Item) = Is_Limited
2915 and then Named_Unit (Item) = Pack
2925 end Has_With_Clause;
2927 -----------------------------
2928 -- Implicit_With_On_Parent --
2929 -----------------------------
2931 procedure Implicit_With_On_Parent
2932 (Child_Unit : Node_Id;
2935 Loc : constant Source_Ptr := Sloc (N);
2936 P : constant Node_Id := Parent_Spec (Child_Unit);
2937 P_Unit : Node_Id := Unit (P);
2938 P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
2941 function Build_Ancestor_Name (P : Node_Id) return Node_Id;
2942 -- Build prefix of child unit name. Recurse if needed
2944 function Build_Unit_Name return Node_Id;
2945 -- If the unit is a child unit, build qualified name with all ancestors
2947 -------------------------
2948 -- Build_Ancestor_Name --
2949 -------------------------
2951 function Build_Ancestor_Name (P : Node_Id) return Node_Id is
2952 P_Ref : constant Node_Id :=
2953 New_Reference_To (Defining_Entity (P), Loc);
2954 P_Spec : Node_Id := P;
2957 -- Ancestor may have been rewritten as a package body. Retrieve
2958 -- the original spec to trace earlier ancestors.
2960 if Nkind (P) = N_Package_Body
2961 and then Nkind (Original_Node (P)) = N_Package_Instantiation
2963 P_Spec := Original_Node (P);
2966 if No (Parent_Spec (P_Spec)) then
2970 Make_Selected_Component (Loc,
2971 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Spec))),
2972 Selector_Name => P_Ref);
2974 end Build_Ancestor_Name;
2976 ---------------------
2977 -- Build_Unit_Name --
2978 ---------------------
2980 function Build_Unit_Name return Node_Id is
2984 if No (Parent_Spec (P_Unit)) then
2985 return New_Reference_To (P_Name, Loc);
2989 Make_Expanded_Name (Loc,
2990 Chars => Chars (P_Name),
2991 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
2992 Selector_Name => New_Reference_To (P_Name, Loc));
2993 Set_Entity (Result, P_Name);
2996 end Build_Unit_Name;
2998 -- Start of processing for Implicit_With_On_Parent
3001 -- The unit of the current compilation may be a package body that
3002 -- replaces an instance node. In this case we need the original instance
3003 -- node to construct the proper parent name.
3005 if Nkind (P_Unit) = N_Package_Body
3006 and then Nkind (Original_Node (P_Unit)) = N_Package_Instantiation
3008 P_Unit := Original_Node (P_Unit);
3011 -- We add the implicit with if the child unit is the current unit being
3012 -- compiled. If the current unit is a body, we do not want to add an
3013 -- implicit_with a second time to the corresponding spec.
3015 if Nkind (Child_Unit) = N_Package_Declaration
3016 and then Child_Unit /= Unit (Cunit (Current_Sem_Unit))
3021 New_Nodes_OK := New_Nodes_OK + 1;
3022 Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
3024 Set_Library_Unit (Withn, P);
3025 Set_Corresponding_Spec (Withn, P_Name);
3026 Set_First_Name (Withn, True);
3027 Set_Implicit_With (Withn, True);
3029 -- Node is placed at the beginning of the context items, so that
3030 -- subsequent use clauses on the parent can be validated.
3032 Prepend (Withn, Context_Items (N));
3033 Mark_Rewrite_Insertion (Withn);
3034 Install_Withed_Unit (Withn);
3036 if Is_Child_Spec (P_Unit) then
3037 Implicit_With_On_Parent (P_Unit, N);
3040 New_Nodes_OK := New_Nodes_OK - 1;
3041 end Implicit_With_On_Parent;
3047 function In_Chain (E : Entity_Id) return Boolean is
3051 H := Current_Entity (E);
3052 while Present (H) loop
3063 ---------------------
3064 -- Install_Context --
3065 ---------------------
3067 procedure Install_Context (N : Node_Id) is
3068 Lib_Unit : constant Node_Id := Unit (N);
3071 Install_Context_Clauses (N);
3073 if Is_Child_Spec (Lib_Unit) then
3074 Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit)));
3077 Install_Limited_Context_Clauses (N);
3078 end Install_Context;
3080 -----------------------------
3081 -- Install_Context_Clauses --
3082 -----------------------------
3084 procedure Install_Context_Clauses (N : Node_Id) is
3085 Lib_Unit : constant Node_Id := Unit (N);
3087 Uname_Node : Entity_Id;
3088 Check_Private : Boolean := False;
3089 Decl_Node : Node_Id;
3090 Lib_Parent : Entity_Id;
3093 -- First skip configuration pragmas at the start of the context. They
3094 -- are not technically part of the context clause, but that's where the
3095 -- parser puts them. Note they were analyzed in Analyze_Context.
3097 Item := First (Context_Items (N));
3098 while Present (Item)
3099 and then Nkind (Item) = N_Pragma
3100 and then Pragma_Name (Item) in Configuration_Pragma_Names
3105 -- Loop through the actual context clause items. We process everything
3106 -- except Limited_With clauses in this routine. Limited_With clauses
3107 -- are separately installed (see Install_Limited_Context_Clauses).
3109 while Present (Item) loop
3111 -- Case of explicit WITH clause
3113 if Nkind (Item) = N_With_Clause
3114 and then not Implicit_With (Item)
3116 if Limited_Present (Item) then
3118 -- Limited withed units will be installed later
3122 -- If Name (Item) is not an entity name, something is wrong, and
3123 -- this will be detected in due course, for now ignore the item
3125 elsif not Is_Entity_Name (Name (Item)) then
3128 elsif No (Entity (Name (Item))) then
3129 Set_Entity (Name (Item), Any_Id);
3133 Uname_Node := Entity (Name (Item));
3135 if Is_Private_Descendant (Uname_Node) then
3136 Check_Private := True;
3139 Install_Withed_Unit (Item);
3141 Decl_Node := Unit_Declaration_Node (Uname_Node);
3143 -- If the unit is a subprogram instance, it appears nested within
3144 -- a package that carries the parent information.
3146 if Is_Generic_Instance (Uname_Node)
3147 and then Ekind (Uname_Node) /= E_Package
3149 Decl_Node := Parent (Parent (Decl_Node));
3152 if Is_Child_Spec (Decl_Node) then
3153 if Nkind (Name (Item)) = N_Expanded_Name then
3154 Expand_With_Clause (Item, Prefix (Name (Item)), N);
3156 -- If not an expanded name, the child unit must be a
3157 -- renaming, nothing to do.
3162 elsif Nkind (Decl_Node) = N_Subprogram_Body
3163 and then not Acts_As_Spec (Parent (Decl_Node))
3164 and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
3166 Implicit_With_On_Parent
3167 (Unit (Library_Unit (Parent (Decl_Node))), N);
3170 -- Check license conditions unless this is a dummy unit
3172 if Sloc (Library_Unit (Item)) /= No_Location then
3173 License_Check : declare
3174 Withu : constant Unit_Number_Type :=
3175 Get_Source_Unit (Library_Unit (Item));
3176 Withl : constant License_Type :=
3177 License (Source_Index (Withu));
3178 Unitl : constant License_Type :=
3179 License (Source_Index (Current_Sem_Unit));
3181 procedure License_Error;
3182 -- Signal error of bad license
3188 procedure License_Error is
3191 ("?license of with'ed unit & may be inconsistent",
3195 -- Start of processing for License_Check
3198 -- Exclude license check if withed unit is an internal unit.
3199 -- This situation arises e.g. with the GPL version of GNAT.
3201 if Is_Internal_File_Name (Unit_File_Name (Withu)) then
3204 -- Otherwise check various cases
3216 if Withl = Restricted then
3220 when Modified_GPL =>
3221 if Withl = Restricted or else Withl = GPL then
3225 when Unrestricted =>
3232 -- Case of USE PACKAGE clause
3234 elsif Nkind (Item) = N_Use_Package_Clause then
3235 Analyze_Use_Package (Item);
3237 -- Case of USE TYPE clause
3239 elsif Nkind (Item) = N_Use_Type_Clause then
3240 Analyze_Use_Type (Item);
3244 elsif Nkind (Item) = N_Pragma then
3252 if Is_Child_Spec (Lib_Unit) then
3254 -- The unit also has implicit with_clauses on its own parents
3256 if No (Context_Items (N)) then
3257 Set_Context_Items (N, New_List);
3260 Implicit_With_On_Parent (Lib_Unit, N);
3263 -- If the unit is a body, the context of the specification must also
3264 -- be installed. That includes private with_clauses in that context.
3266 if Nkind (Lib_Unit) = N_Package_Body
3267 or else (Nkind (Lib_Unit) = N_Subprogram_Body
3268 and then not Acts_As_Spec (N))
3270 Install_Context (Library_Unit (N));
3272 -- Only install private with-clauses of a spec that comes from
3273 -- source, excluding specs created for a subprogram body that is
3276 if Comes_From_Source (Library_Unit (N)) then
3277 Install_Private_With_Clauses
3278 (Defining_Entity (Unit (Library_Unit (N))));
3281 if Is_Child_Spec (Unit (Library_Unit (N))) then
3283 -- If the unit is the body of a public child unit, the private
3284 -- declarations of the parent must be made visible. If the child
3285 -- unit is private, the private declarations have been installed
3286 -- already in the call to Install_Parents for the spec. Installing
3287 -- private declarations must be done for all ancestors of public
3288 -- child units. In addition, sibling units mentioned in the
3289 -- context clause of the body are directly visible.
3297 Lib_Spec := Unit (Library_Unit (N));
3298 while Is_Child_Spec (Lib_Spec) loop
3299 P := Unit (Parent_Spec (Lib_Spec));
3300 P_Name := Defining_Entity (P);
3302 if not (Private_Present (Parent (Lib_Spec)))
3303 and then not In_Private_Part (P_Name)
3305 Install_Private_Declarations (P_Name);
3306 Install_Private_With_Clauses (P_Name);
3307 Set_Use (Private_Declarations (Specification (P)));
3315 -- For a package body, children in context are immediately visible
3317 Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
3320 if Nkind_In (Lib_Unit, N_Generic_Package_Declaration,
3321 N_Generic_Subprogram_Declaration,
3322 N_Package_Declaration,
3323 N_Subprogram_Declaration)
3325 if Is_Child_Spec (Lib_Unit) then
3326 Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
3327 Set_Is_Private_Descendant
3328 (Defining_Entity (Lib_Unit),
3329 Is_Private_Descendant (Lib_Parent)
3330 or else Private_Present (Parent (Lib_Unit)));
3333 Set_Is_Private_Descendant
3334 (Defining_Entity (Lib_Unit),
3335 Private_Present (Parent (Lib_Unit)));
3339 if Check_Private then
3340 Check_Private_Child_Unit (N);
3342 end Install_Context_Clauses;
3344 -------------------------------------
3345 -- Install_Limited_Context_Clauses --
3346 -------------------------------------
3348 procedure Install_Limited_Context_Clauses (N : Node_Id) is
3351 procedure Check_Renamings (P : Node_Id; W : Node_Id);
3352 -- Check that the unlimited view of a given compilation_unit is not
3353 -- already visible through "use + renamings".
3355 procedure Check_Private_Limited_Withed_Unit (Item : Node_Id);
3356 -- Check that if a limited_with clause of a given compilation_unit
3357 -- mentions a descendant of a private child of some library unit, then
3358 -- the given compilation_unit shall be the declaration of a private
3359 -- descendant of that library unit, or a public descendant of such. The
3360 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3361 -- use entities on the limited with_clauses because their units have not
3362 -- been analyzed, so we have to climb the tree of ancestors looking for
3363 -- private keywords.
3365 procedure Expand_Limited_With_Clause
3366 (Comp_Unit : Node_Id;
3369 -- If a child unit appears in a limited_with clause, there are implicit
3370 -- limited_with clauses on all parents that are not already visible
3371 -- through a regular with clause. This procedure creates the implicit
3372 -- limited with_clauses for the parents and loads the corresponding
3373 -- units. The shadow entities are created when the inserted clause is
3374 -- analyzed. Implements Ada 2005 (AI-50217).
3376 function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean;
3377 -- When compiling a unit Q descended from some parent unit P, a limited
3378 -- with_clause in the context of P that names some other ancestor of Q
3379 -- must not be installed because the ancestor is immediately visible.
3381 ---------------------
3382 -- Check_Renamings --
3383 ---------------------
3385 procedure Check_Renamings (P : Node_Id; W : Node_Id) is
3394 pragma Assert (Nkind (W) = N_With_Clause);
3396 -- Protect the frontend against previous critical errors
3398 case Nkind (Unit (Library_Unit (W))) is
3399 when N_Subprogram_Declaration |
3400 N_Package_Declaration |
3401 N_Generic_Subprogram_Declaration |
3402 N_Generic_Package_Declaration =>
3409 -- Check "use + renamings"
3411 WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
3412 Spec := Specification (Unit (P));
3414 Item := First (Visible_Declarations (Spec));
3415 while Present (Item) loop
3417 -- Look only at use package clauses
3419 if Nkind (Item) = N_Use_Package_Clause then
3421 -- Traverse the list of packages
3423 Nam := First (Names (Item));
3424 while Present (Nam) loop
3427 pragma Assert (Present (Parent (E)));
3429 if Nkind (Parent (E)) = N_Package_Renaming_Declaration
3430 and then Renamed_Entity (E) = WEnt
3432 -- The unlimited view is visible through use clause and
3433 -- renamings. There is no need to generate the error
3434 -- message here because Is_Visible_Through_Renamings
3435 -- takes care of generating the precise error message.
3439 elsif Nkind (Parent (E)) = N_Package_Specification then
3441 -- The use clause may refer to a local package.
3442 -- Check all the enclosing scopes.
3445 while E2 /= Standard_Standard
3453 ("unlimited view visible through use clause ", W);
3465 -- Recursive call to check all the ancestors
3467 if Is_Child_Spec (Unit (P)) then
3468 Check_Renamings (P => Parent_Spec (Unit (P)), W => W);
3470 end Check_Renamings;
3472 ---------------------------------------
3473 -- Check_Private_Limited_Withed_Unit --
3474 ---------------------------------------
3476 procedure Check_Private_Limited_Withed_Unit (Item : Node_Id) is
3477 Curr_Parent : Node_Id;
3478 Child_Parent : Node_Id;
3479 Curr_Private : Boolean;
3482 -- Compilation unit of the parent of the withed library unit
3484 Child_Parent := Library_Unit (Item);
3486 -- If the child unit is a public child, then locate its nearest
3487 -- private ancestor, if any, then Child_Parent will then be set to
3488 -- the parent of that ancestor.
3490 if not Private_Present (Library_Unit (Item)) then
3491 while Present (Child_Parent)
3492 and then not Private_Present (Child_Parent)
3494 Child_Parent := Parent_Spec (Unit (Child_Parent));
3497 if No (Child_Parent) then
3502 Child_Parent := Parent_Spec (Unit (Child_Parent));
3504 -- Traverse all the ancestors of the current compilation unit to
3505 -- check if it is a descendant of named library unit.
3507 Curr_Parent := Parent (Item);
3508 Curr_Private := Private_Present (Curr_Parent);
3510 while Present (Parent_Spec (Unit (Curr_Parent)))
3511 and then Curr_Parent /= Child_Parent
3513 Curr_Parent := Parent_Spec (Unit (Curr_Parent));
3514 Curr_Private := Curr_Private or else Private_Present (Curr_Parent);
3517 if Curr_Parent /= Child_Parent then
3519 ("unit in with clause is private child unit!", Item);
3521 ("\current unit must also have parent&!",
3522 Item, Defining_Unit_Name (Specification (Unit (Child_Parent))));
3524 elsif Private_Present (Parent (Item))
3525 or else Curr_Private
3526 or else Private_Present (Item)
3527 or else Nkind_In (Unit (Parent (Item)), N_Package_Body,
3531 -- Current unit is private, of descendant of a private unit
3537 ("current unit must also be private descendant of&",
3538 Item, Defining_Unit_Name (Specification (Unit (Child_Parent))));
3540 end Check_Private_Limited_Withed_Unit;
3542 --------------------------------
3543 -- Expand_Limited_With_Clause --
3544 --------------------------------
3546 procedure Expand_Limited_With_Clause
3547 (Comp_Unit : Node_Id;
3551 Loc : constant Source_Ptr := Sloc (Nam);
3552 Unum : Unit_Number_Type;
3555 function Previous_Withed_Unit (W : Node_Id) return Boolean;
3556 -- Returns true if the context already includes a with_clause for
3557 -- this unit. If the with_clause is non-limited, the unit is fully
3558 -- visible and an implicit limited_with should not be created. If
3559 -- there is already a limited_with clause for W, a second one is
3560 -- simply redundant.
3562 --------------------------
3563 -- Previous_Withed_Unit --
3564 --------------------------
3566 function Previous_Withed_Unit (W : Node_Id) return Boolean is
3570 -- A limited with_clause cannot appear in the same context_clause
3571 -- as a nonlimited with_clause which mentions the same library.
3573 Item := First (Context_Items (Comp_Unit));
3574 while Present (Item) loop
3575 if Nkind (Item) = N_With_Clause
3576 and then Library_Unit (Item) = Library_Unit (W)
3585 end Previous_Withed_Unit;
3587 -- Start of processing for Expand_Limited_With_Clause
3590 New_Nodes_OK := New_Nodes_OK + 1;
3592 if Nkind (Nam) = N_Identifier then
3594 -- Create node for name of withed unit
3597 Make_With_Clause (Loc,
3598 Name => New_Copy (Nam));
3600 else pragma Assert (Nkind (Nam) = N_Selected_Component);
3602 Make_With_Clause (Loc,
3603 Name => Make_Selected_Component (Loc,
3604 Prefix => New_Copy_Tree (Prefix (Nam)),
3605 Selector_Name => New_Copy (Selector_Name (Nam))));
3606 Set_Parent (Withn, Parent (N));
3609 Set_Limited_Present (Withn);
3610 Set_First_Name (Withn);
3611 Set_Implicit_With (Withn);
3615 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
3620 -- Do not generate a limited_with_clause on the current unit.
3621 -- This path is taken when a unit has a limited_with clause on
3622 -- one of its child units.
3624 if Unum = Current_Sem_Unit then
3628 Set_Library_Unit (Withn, Cunit (Unum));
3629 Set_Corresponding_Spec
3630 (Withn, Specification (Unit (Cunit (Unum))));
3632 if not Previous_Withed_Unit (Withn) then
3633 Prepend (Withn, Context_Items (Parent (N)));
3634 Mark_Rewrite_Insertion (Withn);
3636 -- Add implicit limited_with_clauses for parents of child units
3637 -- mentioned in limited_with clauses.
3639 if Nkind (Nam) = N_Selected_Component then
3640 Expand_Limited_With_Clause (Comp_Unit, Prefix (Nam), N);
3645 if not Limited_View_Installed (Withn) then
3646 Install_Limited_Withed_Unit (Withn);
3650 New_Nodes_OK := New_Nodes_OK - 1;
3651 end Expand_Limited_With_Clause;
3653 ----------------------
3654 -- Is_Ancestor_Unit --
3655 ----------------------
3657 function Is_Ancestor_Unit (U1 : Node_Id; U2 : Node_Id) return Boolean is
3658 E1 : constant Entity_Id := Defining_Entity (Unit (U1));
3661 if Nkind_In (Unit (U2), N_Package_Body, N_Subprogram_Body) then
3662 E2 := Defining_Entity (Unit (Library_Unit (U2)));
3663 return Is_Ancestor_Package (E1, E2);
3667 end Is_Ancestor_Unit;
3669 -- Start of processing for Install_Limited_Context_Clauses
3672 Item := First (Context_Items (N));
3673 while Present (Item) loop
3674 if Nkind (Item) = N_With_Clause
3675 and then Limited_Present (Item)
3677 if Nkind (Name (Item)) = N_Selected_Component then
3678 Expand_Limited_With_Clause
3679 (Comp_Unit => N, Nam => Prefix (Name (Item)), N => Item);
3682 Check_Private_Limited_Withed_Unit (Item);
3684 if not Implicit_With (Item)
3685 and then Is_Child_Spec (Unit (N))
3687 Check_Renamings (Parent_Spec (Unit (N)), Item);
3690 -- A unit may have a limited with on itself if it has a limited
3691 -- with_clause on one of its child units. In that case it is
3692 -- already being compiled and it makes no sense to install its
3695 -- If the item is a limited_private_with_clause, install it if the
3696 -- current unit is a body or if it is a private child. Otherwise
3697 -- the private clause is installed before analyzing the private
3698 -- part of the current unit.
3700 if Library_Unit (Item) /= Cunit (Current_Sem_Unit)
3701 and then not Limited_View_Installed (Item)
3703 not Is_Ancestor_Unit
3704 (Library_Unit (Item), Cunit (Current_Sem_Unit))
3706 if not Private_Present (Item)
3707 or else Private_Present (N)
3708 or else Nkind_In (Unit (N), N_Package_Body,
3712 Install_Limited_Withed_Unit (Item);
3720 -- Ada 2005 (AI-412): Examine the visible declarations of a package
3721 -- spec, looking for incomplete subtype declarations of incomplete types
3722 -- visible through a limited with clause.
3724 if Ada_Version >= Ada_05
3725 and then Analyzed (N)
3726 and then Nkind (Unit (N)) = N_Package_Declaration
3731 Non_Lim_View : Entity_Id;
3734 Decl := First (Visible_Declarations (Specification (Unit (N))));
3735 while Present (Decl) loop
3736 if Nkind (Decl) = N_Subtype_Declaration
3738 Ekind (Defining_Identifier (Decl)) = E_Incomplete_Subtype
3740 From_With_Type (Defining_Identifier (Decl))
3742 Def_Id := Defining_Identifier (Decl);
3743 Non_Lim_View := Non_Limited_View (Def_Id);
3745 if not Is_Incomplete_Type (Non_Lim_View) then
3747 -- Convert an incomplete subtype declaration into a
3748 -- corresponding non-limited view subtype declaration.
3749 -- This is usually the case when analyzing a body that
3750 -- has regular with-clauses, when the spec has limited
3753 -- If the non-limited view is still incomplete, it is
3754 -- the dummy entry already created, and the declaration
3755 -- cannot be reanalyzed. This is the case when installing
3756 -- a parent unit that has limited with-clauses.
3758 Set_Subtype_Indication (Decl,
3759 New_Reference_To (Non_Lim_View, Sloc (Def_Id)));
3760 Set_Etype (Def_Id, Non_Lim_View);
3761 Set_Ekind (Def_Id, Subtype_Kind (Ekind (Non_Lim_View)));
3762 Set_Analyzed (Decl, False);
3764 -- Reanalyze the declaration, suppressing the call to
3765 -- Enter_Name to avoid duplicate names.
3767 Analyze_Subtype_Declaration
3777 end Install_Limited_Context_Clauses;
3779 ---------------------
3780 -- Install_Parents --
3781 ---------------------
3783 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is
3790 P := Unit (Parent_Spec (Lib_Unit));
3791 P_Name := Get_Parent_Entity (P);
3793 if Etype (P_Name) = Any_Type then
3797 if Ekind (P_Name) = E_Generic_Package
3798 and then not Nkind_In (Lib_Unit, N_Generic_Subprogram_Declaration,
3799 N_Generic_Package_Declaration)
3800 and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration
3803 ("child of a generic package must be a generic unit", Lib_Unit);
3805 elsif not Is_Package_Or_Generic_Package (P_Name) then
3807 ("parent unit must be package or generic package", Lib_Unit);
3808 raise Unrecoverable_Error;
3810 elsif Present (Renamed_Object (P_Name)) then
3811 Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
3812 raise Unrecoverable_Error;
3814 -- Verify that a child of an instance is itself an instance, or the
3815 -- renaming of one. Given that an instance that is a unit is replaced
3816 -- with a package declaration, check against the original node. The
3817 -- parent may be currently being instantiated, in which case it appears
3818 -- as a declaration, but the generic_parent is already established
3819 -- indicating that we deal with an instance.
3821 elsif Nkind (Original_Node (P)) = N_Package_Instantiation then
3822 if Nkind (Lib_Unit) in N_Renaming_Declaration
3823 or else Nkind (Original_Node (Lib_Unit)) in N_Generic_Instantiation
3825 (Nkind (Lib_Unit) = N_Package_Declaration
3826 and then Present (Generic_Parent (Specification (Lib_Unit))))
3831 ("child of an instance must be an instance or renaming",
3836 -- This is the recursive call that ensures all parents are loaded
3838 if Is_Child_Spec (P) then
3840 Is_Private or else Private_Present (Parent (Lib_Unit)));
3843 -- Now we can install the context for this parent
3845 Install_Context_Clauses (Parent_Spec (Lib_Unit));
3846 Install_Limited_Context_Clauses (Parent_Spec (Lib_Unit));
3847 Install_Siblings (P_Name, Parent (Lib_Unit));
3849 -- The child unit is in the declarative region of the parent. The parent
3850 -- must therefore appear in the scope stack and be visible, as when
3851 -- compiling the corresponding body. If the child unit is private or it
3852 -- is a package body, private declarations must be accessible as well.
3853 -- Use declarations in the parent must also be installed. Finally, other
3854 -- child units of the same parent that are in the context are
3855 -- immediately visible.
3857 -- Find entity for compilation unit, and set its private descendant
3858 -- status as needed. Indicate that it is a compilation unit, which is
3859 -- redundant in general, but needed if this is a generated child spec
3860 -- for a child body without previous spec.
3862 E_Name := Defining_Entity (Lib_Unit);
3864 Set_Is_Child_Unit (E_Name);
3865 Set_Is_Compilation_Unit (E_Name);
3867 Set_Is_Private_Descendant (E_Name,
3868 Is_Private_Descendant (P_Name)
3869 or else Private_Present (Parent (Lib_Unit)));
3871 P_Spec := Specification (Unit_Declaration_Node (P_Name));
3872 Push_Scope (P_Name);
3874 -- Save current visibility of unit
3876 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
3877 Is_Immediately_Visible (P_Name);
3878 Set_Is_Immediately_Visible (P_Name);
3879 Install_Visible_Declarations (P_Name);
3880 Set_Use (Visible_Declarations (P_Spec));
3882 -- If the parent is a generic unit, its formal part may contain formal
3883 -- packages and use clauses for them.
3885 if Ekind (P_Name) = E_Generic_Package then
3886 Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
3890 or else Private_Present (Parent (Lib_Unit))
3892 Install_Private_Declarations (P_Name);
3893 Install_Private_With_Clauses (P_Name);
3894 Set_Use (Private_Declarations (P_Spec));
3896 end Install_Parents;
3898 ----------------------------------
3899 -- Install_Private_With_Clauses --
3900 ----------------------------------
3902 procedure Install_Private_With_Clauses (P : Entity_Id) is
3903 Decl : constant Node_Id := Unit_Declaration_Node (P);
3907 if Debug_Flag_I then
3908 Write_Str ("install private with clauses of ");
3909 Write_Name (Chars (P));
3913 if Nkind (Parent (Decl)) = N_Compilation_Unit then
3914 Item := First (Context_Items (Parent (Decl)));
3915 while Present (Item) loop
3916 if Nkind (Item) = N_With_Clause
3917 and then Private_Present (Item)
3919 if Limited_Present (Item) then
3920 if not Limited_View_Installed (Item) then
3921 Install_Limited_Withed_Unit (Item);
3924 Install_Withed_Unit (Item, Private_With_OK => True);
3931 end Install_Private_With_Clauses;
3933 ----------------------
3934 -- Install_Siblings --
3935 ----------------------
3937 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
3943 -- Iterate over explicit with clauses, and check whether the scope of
3944 -- each entity is an ancestor of the current unit, in which case it is
3945 -- immediately visible.
3947 Item := First (Context_Items (N));
3948 while Present (Item) loop
3950 -- Do not install private_with_clauses declaration, unless unit
3951 -- is itself a private child unit, or is a body. Note that for a
3952 -- subprogram body the private_with_clause does not take effect until
3953 -- after the specification.
3955 if Nkind (Item) /= N_With_Clause
3956 or else Implicit_With (Item)
3957 or else Limited_Present (Item)
3961 elsif not Private_Present (Item)
3962 or else Private_Present (N)
3963 or else Nkind (Unit (N)) = N_Package_Body
3965 Id := Entity (Name (Item));
3967 if Is_Child_Unit (Id)
3968 and then Is_Ancestor_Package (Scope (Id), U_Name)
3970 Set_Is_Immediately_Visible (Id);
3972 -- Check for the presence of another unit in the context that
3973 -- may be inadvertently hidden by the child.
3975 Prev := Current_Entity (Id);
3978 and then Is_Immediately_Visible (Prev)
3979 and then not Is_Child_Unit (Prev)
3985 Clause := First (Context_Items (N));
3986 while Present (Clause) loop
3987 if Nkind (Clause) = N_With_Clause
3988 and then Entity (Name (Clause)) = Prev
3991 ("child unit& hides compilation unit " &
3992 "with the same name?",
4002 -- The With_Clause may be on a grand-child or one of its further
4003 -- descendants, which makes a child immediately visible. Examine
4004 -- ancestry to determine whether such a child exists. For example,
4005 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4006 -- is immediately visible.
4008 elsif Is_Child_Unit (Id) then
4014 while Is_Child_Unit (Par) loop
4015 if Is_Ancestor_Package (Scope (Par), U_Name) then
4016 Set_Is_Immediately_Visible (Par);
4025 -- If the item is a private with-clause on a child unit, the parent
4026 -- may have been installed already, but the child unit must remain
4027 -- invisible until installed in a private part or body, unless there
4028 -- is already a regular with_clause for it in the current unit.
4030 elsif Private_Present (Item) then
4031 Id := Entity (Name (Item));
4033 if Is_Child_Unit (Id) then
4037 function In_Context return Boolean;
4038 -- Scan context of current unit, to check whether there is
4039 -- a with_clause on the same unit as a private with-clause
4040 -- on a parent, in which case child unit is visible. If the
4041 -- unit is a grand-child, the same applies to its parent.
4047 function In_Context return Boolean is
4050 First (Context_Items (Cunit (Current_Sem_Unit)));
4051 while Present (Clause) loop
4052 if Nkind (Clause) = N_With_Clause
4053 and then Comes_From_Source (Clause)
4054 and then Is_Entity_Name (Name (Clause))
4055 and then not Private_Present (Clause)
4057 if Entity (Name (Clause)) = Id
4059 (Nkind (Name (Clause)) = N_Expanded_Name
4060 and then Entity (Prefix (Name (Clause))) = Id)
4073 Set_Is_Visible_Child_Unit (Id, In_Context);
4080 end Install_Siblings;
4082 ---------------------------------
4083 -- Install_Limited_Withed_Unit --
4084 ---------------------------------
4086 procedure Install_Limited_Withed_Unit (N : Node_Id) is
4087 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
4090 Is_Child_Package : Boolean := False;
4091 Lim_Header : Entity_Id;
4092 Lim_Typ : Entity_Id;
4094 procedure Check_Body_Required;
4095 -- A unit mentioned in a limited with_clause may not be mentioned in
4096 -- a regular with_clause, but must still be included in the current
4097 -- partition. We need to determine whether the unit needs a body, so
4098 -- that the binder can determine the name of the file to be compiled.
4099 -- Checking whether a unit needs a body can be done without semantic
4100 -- analysis, by examining the nature of the declarations in the package.
4102 function Has_Limited_With_Clause
4103 (C_Unit : Entity_Id;
4104 Pack : Entity_Id) return Boolean;
4105 -- Determine whether any package in the ancestor chain starting with
4106 -- C_Unit has a limited with clause for package Pack.
4108 function Is_Visible_Through_Renamings (P : Entity_Id) return Boolean;
4109 -- Check if some package installed though normal with-clauses has a
4110 -- renaming declaration of package P. AARM 10.1.2(21/2).
4112 -------------------------
4113 -- Check_Body_Required --
4114 -------------------------
4116 procedure Check_Body_Required is
4117 PA : constant List_Id :=
4118 Pragmas_After (Aux_Decls_Node (Parent (P_Unit)));
4120 procedure Check_Declarations (Spec : Node_Id);
4121 -- Recursive procedure that does the work and checks nested packages
4123 ------------------------
4124 -- Check_Declarations --
4125 ------------------------
4127 procedure Check_Declarations (Spec : Node_Id) is
4129 Incomplete_Decls : constant Elist_Id := New_Elmt_List;
4131 Subp_List : constant Elist_Id := New_Elmt_List;
4133 procedure Check_Pragma_Import (P : Node_Id);
4134 -- If a pragma import applies to a previous subprogram, the
4135 -- enclosing unit may not need a body. The processing is syntactic
4136 -- and does not require a declaration to be analyzed. The code
4137 -- below also handles pragma Import when applied to a subprogram
4138 -- that renames another. In this case the pragma applies to the
4141 -- Chains of multiple renames are not handled by the code below.
4142 -- It is probably impossible to handle all cases without proper
4143 -- name resolution. In such cases the algorithm is conservative
4144 -- and will indicate that a body is needed???
4146 -------------------------
4147 -- Check_Pragma_Import --
4148 -------------------------
4150 procedure Check_Pragma_Import (P : Node_Id) is
4156 procedure Remove_Homonyms (E : Node_Id);
4157 -- Make one pass over list of subprograms. Called again if
4158 -- subprogram is a renaming. E is known to be an identifier.
4160 ---------------------
4161 -- Remove_Homonyms --
4162 ---------------------
4164 procedure Remove_Homonyms (E : Node_Id) is
4165 R : Entity_Id := Empty;
4166 -- Name of renamed entity, if any
4169 Subp_Id := First_Elmt (Subp_List);
4170 while Present (Subp_Id) loop
4171 if Chars (Node (Subp_Id)) = Chars (E) then
4172 if Nkind (Parent (Parent (Node (Subp_Id))))
4173 /= N_Subprogram_Renaming_Declaration
4176 Next_Elmt (Subp_Id);
4177 Remove_Elmt (Subp_List, Prev_Id);
4179 R := Name (Parent (Parent (Node (Subp_Id))));
4183 Next_Elmt (Subp_Id);
4188 if Nkind (R) = N_Identifier then
4189 Remove_Homonyms (R);
4191 elsif Nkind (R) = N_Selected_Component then
4192 Remove_Homonyms (Selector_Name (R));
4194 -- Renaming of attribute
4200 end Remove_Homonyms;
4202 -- Start of processing for Check_Pragma_Import
4205 -- Find name of entity in Import pragma. We have not analyzed
4206 -- the construct, so we must guard against syntax errors.
4208 Arg := Next (First (Pragma_Argument_Associations (P)));
4211 or else Nkind (Expression (Arg)) /= N_Identifier
4215 Imported := Expression (Arg);
4218 Remove_Homonyms (Imported);
4219 end Check_Pragma_Import;
4221 -- Start of processing for Check_Declarations
4224 -- Search for Elaborate Body pragma
4226 Decl := First (Visible_Declarations (Spec));
4227 while Present (Decl)
4228 and then Nkind (Decl) = N_Pragma
4230 if Get_Pragma_Id (Decl) = Pragma_Elaborate_Body then
4231 Set_Body_Required (Library_Unit (N));
4238 -- Look for declarations that require the presence of a body. We
4239 -- have already skipped pragmas at the start of the list.
4241 while Present (Decl) loop
4243 -- Subprogram that comes from source means body may be needed.
4244 -- Save for subsequent examination of import pragmas.
4246 if Comes_From_Source (Decl)
4247 and then (Nkind_In (Decl, N_Subprogram_Declaration,
4248 N_Subprogram_Renaming_Declaration,
4249 N_Generic_Subprogram_Declaration))
4251 Append_Elmt (Defining_Entity (Decl), Subp_List);
4253 -- Package declaration of generic package declaration. We need
4254 -- to recursively examine nested declarations.
4256 elsif Nkind_In (Decl, N_Package_Declaration,
4257 N_Generic_Package_Declaration)
4259 Check_Declarations (Specification (Decl));
4261 elsif Nkind (Decl) = N_Pragma
4262 and then Pragma_Name (Decl) = Name_Import
4264 Check_Pragma_Import (Decl);
4270 -- Same set of tests for private part. In addition to subprograms
4271 -- detect the presence of Taft Amendment types (incomplete types
4272 -- completed in the body).
4274 Decl := First (Private_Declarations (Spec));
4275 while Present (Decl) loop
4276 if Comes_From_Source (Decl)
4277 and then (Nkind_In (Decl, N_Subprogram_Declaration,
4278 N_Subprogram_Renaming_Declaration,
4279 N_Generic_Subprogram_Declaration))
4281 Append_Elmt (Defining_Entity (Decl), Subp_List);
4283 elsif Nkind_In (Decl, N_Package_Declaration,
4284 N_Generic_Package_Declaration)
4286 Check_Declarations (Specification (Decl));
4288 -- Collect incomplete type declarations for separate pass
4290 elsif Nkind (Decl) = N_Incomplete_Type_Declaration then
4291 Append_Elmt (Decl, Incomplete_Decls);
4293 elsif Nkind (Decl) = N_Pragma
4294 and then Pragma_Name (Decl) = Name_Import
4296 Check_Pragma_Import (Decl);
4302 -- Now check incomplete declarations to locate Taft amendment
4303 -- types. This can be done by examining the defining identifiers
4304 -- of type declarations without real semantic analysis.
4310 Inc := First_Elmt (Incomplete_Decls);
4311 while Present (Inc) loop
4312 Decl := Next (Node (Inc));
4313 while Present (Decl) loop
4314 if Nkind (Decl) = N_Full_Type_Declaration
4315 and then Chars (Defining_Identifier (Decl)) =
4316 Chars (Defining_Identifier (Node (Inc)))
4324 -- If no completion, this is a TAT, and a body is needed
4327 Set_Body_Required (Library_Unit (N));
4335 -- Finally, check whether there are subprograms that still
4336 -- require a body, i.e. are not renamings or null.
4338 if not Is_Empty_Elmt_List (Subp_List) then
4344 Subp_Id := First_Elmt (Subp_List);
4345 Spec := Parent (Node (Subp_Id));
4347 while Present (Subp_Id) loop
4348 if Nkind (Parent (Spec))
4349 = N_Subprogram_Renaming_Declaration
4353 elsif Nkind (Spec) = N_Procedure_Specification
4354 and then Null_Present (Spec)
4359 Set_Body_Required (Library_Unit (N));
4363 Next_Elmt (Subp_Id);
4367 end Check_Declarations;
4369 -- Start of processing for Check_Body_Required
4372 -- If this is an imported package (Java and CIL usage) no body is
4373 -- needed. Scan list of pragmas that may follow a compilation unit
4374 -- to look for a relevant pragma Import.
4376 if Present (PA) then
4382 while Present (Prag) loop
4383 if Nkind (Prag) = N_Pragma
4384 and then Get_Pragma_Id (Prag) = Pragma_Import
4394 Check_Declarations (Specification (P_Unit));
4395 end Check_Body_Required;
4397 -----------------------------
4398 -- Has_Limited_With_Clause --
4399 -----------------------------
4401 function Has_Limited_With_Clause
4402 (C_Unit : Entity_Id;
4403 Pack : Entity_Id) return Boolean
4410 while Present (Par) loop
4411 if Ekind (Par) /= E_Package then
4415 -- Retrieve the Compilation_Unit node for Par and determine if
4416 -- its context clauses contain a limited with for Pack.
4418 Par_Unit := Parent (Parent (Parent (Par)));
4420 if Nkind (Par_Unit) = N_Package_Declaration then
4421 Par_Unit := Parent (Par_Unit);
4424 if Has_With_Clause (Par_Unit, Pack, True) then
4428 -- If there are more ancestors, climb up the tree, otherwise
4431 if Is_Child_Unit (Par) then
4439 end Has_Limited_With_Clause;
4441 ----------------------------------
4442 -- Is_Visible_Through_Renamings --
4443 ----------------------------------
4445 function Is_Visible_Through_Renamings (P : Entity_Id) return Boolean is
4446 Kind : constant Node_Kind :=
4447 Nkind (Unit (Cunit (Current_Sem_Unit)));
4453 -- Example of the error detected by this subprogram:
4461 -- package Ren_P renames P;
4467 -- limited with P; -- ERROR
4468 -- package R.C is ...
4470 Aux_Unit := Cunit (Current_Sem_Unit);
4473 Item := First (Context_Items (Aux_Unit));
4474 while Present (Item) loop
4475 if Nkind (Item) = N_With_Clause
4476 and then not Limited_Present (Item)
4477 and then Nkind (Unit (Library_Unit (Item))) =
4478 N_Package_Declaration
4481 First (Visible_Declarations
4482 (Specification (Unit (Library_Unit (Item)))));
4483 while Present (Decl) loop
4484 if Nkind (Decl) = N_Package_Renaming_Declaration
4485 and then Entity (Name (Decl)) = P
4487 -- Generate the error message only if the current unit
4488 -- is a package declaration; in case of subprogram
4489 -- bodies and package bodies we just return True to
4490 -- indicate that the limited view must not be
4493 if Kind = N_Package_Declaration then
4495 ("simultaneous visibility of the limited and " &
4496 "unlimited views not allowed", N);
4497 Error_Msg_Sloc := Sloc (Item);
4499 ("\\ unlimited view of & visible through the " &
4500 "context clause #", N, P);
4501 Error_Msg_Sloc := Sloc (Decl);
4502 Error_Msg_NE ("\\ and the renaming #", N, P);
4515 -- If it is a body not acting as spec, follow pointer to the
4516 -- corresponding spec, otherwise follow pointer to parent spec.
4518 if Present (Library_Unit (Aux_Unit))
4519 and then Nkind_In (Unit (Aux_Unit),
4520 N_Package_Body, N_Subprogram_Body)
4522 if Aux_Unit = Library_Unit (Aux_Unit) then
4524 -- Aux_Unit is a body that acts as a spec. Clause has
4525 -- already been flagged as illegal.
4530 Aux_Unit := Library_Unit (Aux_Unit);
4534 Aux_Unit := Parent_Spec (Unit (Aux_Unit));
4537 exit when No (Aux_Unit);
4541 end Is_Visible_Through_Renamings;
4543 -- Start of processing for Install_Limited_Withed_Unit
4546 pragma Assert (not Limited_View_Installed (N));
4548 -- In case of limited with_clause on subprograms, generics, instances,
4549 -- or renamings, the corresponding error was previously posted and we
4550 -- have nothing to do here. If the file is missing altogether, it has
4551 -- no source location.
4553 if Nkind (P_Unit) /= N_Package_Declaration
4554 or else Sloc (P_Unit) = No_Location
4559 P := Defining_Unit_Name (Specification (P_Unit));
4561 -- Handle child packages
4563 if Nkind (P) = N_Defining_Program_Unit_Name then
4564 Is_Child_Package := True;
4565 P := Defining_Identifier (P);
4568 -- Do not install the limited-view if the context of the unit is already
4569 -- available through a regular with clause.
4571 if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4572 and then Has_With_Clause (Cunit (Current_Sem_Unit), P)
4577 -- Do not install the limited-view if the full-view is already visible
4578 -- through renaming declarations.
4580 if Is_Visible_Through_Renamings (P) then
4584 -- Do not install the limited view if this is the unit being analyzed.
4585 -- This unusual case will happen when a unit has a limited_with clause
4586 -- on one of its children. The compilation of the child forces the
4587 -- load of the parent which tries to install the limited view of the
4588 -- child again. Installing the limited view must also be disabled
4589 -- when compiling the body of the child unit.
4591 if P = Cunit_Entity (Current_Sem_Unit)
4593 (Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4594 and then P = Main_Unit_Entity)
4599 -- This scenario is similar to the one above, the difference is that
4600 -- the compilation of sibling Par.Sib forces the load of parent Par
4601 -- which tries to install the limited view of Lim_Pack [1]. However
4602 -- Par.Sib has a with clause for Lim_Pack [2] in its body, and thus
4603 -- needs the non-limited views of all entities from Lim_Pack.
4605 -- limited with Lim_Pack; -- [1]
4606 -- package Par is ... package Lim_Pack is ...
4608 -- with Lim_Pack; -- [2]
4609 -- package Par.Sib is ... package body Par.Sib is ...
4611 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4612 -- Sem_Unit is the body of Par.Sib.
4614 if Ekind (P) = E_Package
4615 and then Ekind (Main_Unit_Entity) = E_Package
4616 and then Is_Child_Unit (Main_Unit_Entity)
4618 -- The body has a regular with clause
4620 and then Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body
4621 and then Has_With_Clause (Cunit (Current_Sem_Unit), P)
4623 -- One of the ancestors has a limited with clause
4625 and then Nkind (Parent (Parent (Main_Unit_Entity))) =
4626 N_Package_Specification
4627 and then Has_Limited_With_Clause (Scope (Main_Unit_Entity), P)
4632 -- A common use of the limited-with is to have a limited-with
4633 -- in the package spec, and a normal with in its package body.
4636 -- limited with X; -- [1]
4640 -- package body A is ...
4642 -- The compilation of A's body installs the context clauses found at [2]
4643 -- and then the context clauses of its specification (found at [1]). As
4644 -- a consequence, at [1] the specification of X has been analyzed and it
4645 -- is immediately visible. According to the semantics of limited-with
4646 -- context clauses we don't install the limited view because the full
4647 -- view of X supersedes its limited view.
4649 if Analyzed (P_Unit)
4651 (Is_Immediately_Visible (P)
4652 or else (Is_Child_Package and then Is_Visible_Child_Unit (P)))
4657 if Debug_Flag_I then
4658 Write_Str ("install limited view of ");
4659 Write_Name (Chars (P));
4663 -- If the unit has not been analyzed and the limited view has not been
4664 -- already installed then we install it.
4666 if not Analyzed (P_Unit) then
4667 if not In_Chain (P) then
4669 -- Minimum decoration
4671 Set_Ekind (P, E_Package);
4672 Set_Etype (P, Standard_Void_Type);
4673 Set_Scope (P, Standard_Standard);
4675 if Is_Child_Package then
4676 Set_Is_Child_Unit (P);
4677 Set_Is_Visible_Child_Unit (P);
4678 Set_Scope (P, Defining_Entity (Unit (Parent_Spec (P_Unit))));
4681 -- Place entity on visibility structure
4683 Set_Homonym (P, Current_Entity (P));
4684 Set_Current_Entity (P);
4686 if Debug_Flag_I then
4687 Write_Str (" (homonym) chain ");
4688 Write_Name (Chars (P));
4692 -- Install the incomplete view. The first element of the limited
4693 -- view is a header (an E_Package entity) used to reference the
4694 -- first shadow entity in the private part of the package.
4696 Lim_Header := Limited_View (P);
4697 Lim_Typ := First_Entity (Lim_Header);
4699 while Present (Lim_Typ)
4700 and then Lim_Typ /= First_Private_Entity (Lim_Header)
4702 Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
4703 Set_Current_Entity (Lim_Typ);
4705 if Debug_Flag_I then
4706 Write_Str (" (homonym) chain ");
4707 Write_Name (Chars (Lim_Typ));
4711 Next_Entity (Lim_Typ);
4715 -- If the unit appears in a previous regular with_clause, the regular
4716 -- entities of the public part of the withed package must be replaced
4717 -- by the shadow ones.
4719 -- This code must be kept synchronized with the code that replaces the
4720 -- shadow entities by the real entities (see body of Remove_Limited
4721 -- With_Clause); otherwise the contents of the homonym chains are not
4725 -- Hide all the type entities of the public part of the package to
4726 -- avoid its usage. This is needed to cover all the subtype decla-
4727 -- rations because we do not remove them from the homonym chain.
4729 E := First_Entity (P);
4730 while Present (E) and then E /= First_Private_Entity (P) loop
4732 Set_Was_Hidden (E, Is_Hidden (E));
4739 -- Replace the real entities by the shadow entities of the limited
4740 -- view. The first element of the limited view is a header that is
4741 -- used to reference the first shadow entity in the private part
4742 -- of the package. Successive elements are the limited views of the
4743 -- type (including regular incomplete types) declared in the package.
4745 Lim_Header := Limited_View (P);
4747 Lim_Typ := First_Entity (Lim_Header);
4748 while Present (Lim_Typ)
4749 and then Lim_Typ /= First_Private_Entity (Lim_Header)
4751 pragma Assert (not In_Chain (Lim_Typ));
4753 -- Do not unchain nested packages and child units
4755 if Ekind (Lim_Typ) /= E_Package
4756 and then not Is_Child_Unit (Lim_Typ)
4762 Prev := Current_Entity (Lim_Typ);
4765 -- Replace E in the homonyms list, so that the limited
4766 -- view becomes available.
4768 if E = Non_Limited_View (Lim_Typ) then
4769 Set_Homonym (Lim_Typ, Homonym (Prev));
4770 Set_Current_Entity (Lim_Typ);
4774 E := Homonym (Prev);
4776 -- E may have been removed when installing a
4777 -- previous limited_with_clause.
4781 exit when E = Non_Limited_View (Lim_Typ);
4783 Prev := Homonym (Prev);
4787 Set_Homonym (Lim_Typ, Homonym (Homonym (Prev)));
4788 Set_Homonym (Prev, Lim_Typ);
4793 if Debug_Flag_I then
4794 Write_Str (" (homonym) chain ");
4795 Write_Name (Chars (Lim_Typ));
4800 Next_Entity (Lim_Typ);
4804 -- The package must be visible while the limited-with clause is active
4805 -- because references to the type P.T must resolve in the usual way.
4806 -- In addition, we remember that the limited-view has been installed to
4807 -- uninstall it at the point of context removal.
4809 Set_Is_Immediately_Visible (P);
4810 Set_Limited_View_Installed (N);
4812 -- If unit has not been analyzed in some previous context, check
4813 -- (imperfectly ???) whether it might need a body.
4815 if not Analyzed (P_Unit) then
4816 Check_Body_Required;
4819 -- If the package in the limited_with clause is a child unit, the
4820 -- clause is unanalyzed and appears as a selected component. Recast
4821 -- it as an expanded name so that the entity can be properly set. Use
4822 -- entity of parent, if available, for higher ancestors in the name.
4824 if Nkind (Name (N)) = N_Selected_Component then
4832 while Nkind (Nam) = N_Selected_Component
4833 and then Present (Ent)
4835 Change_Selected_Component_To_Expanded_Name (Nam);
4837 -- Set entity of parent identifiers if the unit is a child
4838 -- unit. This ensures that the tree is properly formed from
4839 -- semantic point of view (e.g. for ASIS queries).
4841 Set_Entity (Nam, Ent);
4843 Nam := Prefix (Nam);
4846 -- Set entity of last ancestor
4848 if Nkind (Nam) = N_Identifier then
4849 Set_Entity (Nam, Ent);
4855 Set_Entity (Name (N), P);
4856 Set_From_With_Type (P);
4857 end Install_Limited_Withed_Unit;
4859 -------------------------
4860 -- Install_Withed_Unit --
4861 -------------------------
4863 procedure Install_Withed_Unit
4864 (With_Clause : Node_Id;
4865 Private_With_OK : Boolean := False)
4867 Uname : constant Entity_Id := Entity (Name (With_Clause));
4868 P : constant Entity_Id := Scope (Uname);
4871 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
4872 -- compiling a package declaration and the Private_With_OK flag was not
4873 -- set by the caller. These declarations will be installed later (before
4874 -- analyzing the private part of the package).
4876 if Private_Present (With_Clause)
4877 and then Nkind (Unit (Parent (With_Clause))) = N_Package_Declaration
4878 and then not (Private_With_OK)
4883 if Debug_Flag_I then
4884 if Private_Present (With_Clause) then
4885 Write_Str ("install private withed unit ");
4887 Write_Str ("install withed unit ");
4890 Write_Name (Chars (Uname));
4894 -- We do not apply the restrictions to an internal unit unless we are
4895 -- compiling the internal unit as a main unit. This check is also
4896 -- skipped for dummy units (for missing packages).
4898 if Sloc (Uname) /= No_Location
4899 and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
4900 or else Current_Sem_Unit = Main_Unit)
4902 Check_Restricted_Unit
4903 (Unit_Name (Get_Source_Unit (Uname)), With_Clause);
4906 if P /= Standard_Standard then
4908 -- If the unit is not analyzed after analysis of the with clause and
4909 -- it is an instantiation then it awaits a body and is the main unit.
4910 -- Its appearance in the context of some other unit indicates a
4911 -- circular dependency (DEC suite perversity).
4913 if not Analyzed (Uname)
4914 and then Nkind (Parent (Uname)) = N_Package_Instantiation
4917 ("instantiation depends on itself", Name (With_Clause));
4919 elsif not Is_Visible_Child_Unit (Uname) then
4920 Set_Is_Visible_Child_Unit (Uname);
4922 -- If the child unit appears in the context of its parent, it is
4923 -- immediately visible.
4925 if In_Open_Scopes (Scope (Uname)) then
4926 Set_Is_Immediately_Visible (Uname);
4929 if Is_Generic_Instance (Uname)
4930 and then Ekind (Uname) in Subprogram_Kind
4932 -- Set flag as well on the visible entity that denotes the
4933 -- instance, which renames the current one.
4935 Set_Is_Visible_Child_Unit
4937 (Defining_Entity (Unit (Library_Unit (With_Clause)))));
4940 -- The parent unit may have been installed already, and may have
4941 -- appeared in a use clause.
4943 if In_Use (Scope (Uname)) then
4944 Set_Is_Potentially_Use_Visible (Uname);
4947 Set_Context_Installed (With_Clause);
4950 elsif not Is_Immediately_Visible (Uname) then
4951 if not Private_Present (With_Clause)
4952 or else Private_With_OK
4954 Set_Is_Immediately_Visible (Uname);
4957 Set_Context_Installed (With_Clause);
4960 -- A with-clause overrides a with-type clause: there are no restric-
4961 -- tions on the use of package entities.
4963 if Ekind (Uname) = E_Package then
4964 Set_From_With_Type (Uname, False);
4967 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
4968 -- unit if there is a visible homograph for it declared in the same
4969 -- declarative region. This pathological case can only arise when an
4970 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
4971 -- G1 has a generic child also named G2, and the context includes with_
4972 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
4973 -- of I1.G2 visible as well. If the child unit is named Standard, do
4974 -- not apply the check to the Standard package itself.
4976 if Is_Child_Unit (Uname)
4977 and then Is_Visible_Child_Unit (Uname)
4978 and then Ada_Version >= Ada_05
4981 Decl1 : constant Node_Id := Unit_Declaration_Node (P);
4987 U2 := Homonym (Uname);
4989 and then U2 /= Standard_Standard
4992 Decl2 := Unit_Declaration_Node (P2);
4994 if Is_Child_Unit (U2)
4995 and then Is_Visible_Child_Unit (U2)
4997 if Is_Generic_Instance (P)
4998 and then Nkind (Decl1) = N_Package_Declaration
4999 and then Generic_Parent (Specification (Decl1)) = P2
5001 Error_Msg_N ("illegal with_clause", With_Clause);
5003 ("\child unit has visible homograph" &
5004 " (RM 8.3(26), 10.1.1(19))",
5008 elsif Is_Generic_Instance (P2)
5009 and then Nkind (Decl2) = N_Package_Declaration
5010 and then Generic_Parent (Specification (Decl2)) = P
5012 -- With_clause for child unit of instance appears before
5013 -- in the context. We want to place the error message on
5014 -- it, not on the generic child unit itself.
5017 Prev_Clause : Node_Id;
5020 Prev_Clause := First (List_Containing (With_Clause));
5021 while Entity (Name (Prev_Clause)) /= U2 loop
5025 pragma Assert (Present (Prev_Clause));
5026 Error_Msg_N ("illegal with_clause", Prev_Clause);
5028 ("\child unit has visible homograph" &
5029 " (RM 8.3(26), 10.1.1(19))",
5040 end Install_Withed_Unit;
5046 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
5047 K : constant Node_Kind := Nkind (Lib_Unit);
5050 return (K in N_Generic_Declaration or else
5051 K in N_Generic_Instantiation or else
5052 K in N_Generic_Renaming_Declaration or else
5053 K = N_Package_Declaration or else
5054 K = N_Package_Renaming_Declaration or else
5055 K = N_Subprogram_Declaration or else
5056 K = N_Subprogram_Renaming_Declaration)
5057 and then Present (Parent_Spec (Lib_Unit));
5060 ------------------------------------
5061 -- Is_Legal_Shadow_Entity_In_Body --
5062 ------------------------------------
5064 function Is_Legal_Shadow_Entity_In_Body (T : Entity_Id) return Boolean is
5065 C_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
5067 return Nkind (Unit (C_Unit)) = N_Package_Body
5070 (C_Unit, Cunit_Entity (Get_Source_Unit (Non_Limited_View (T))));
5071 end Is_Legal_Shadow_Entity_In_Body;
5073 -----------------------
5074 -- Load_Needed_Body --
5075 -----------------------
5077 -- N is a generic unit named in a with clause, or else it is a unit that
5078 -- contains a generic unit or an inlined function. In order to perform an
5079 -- instantiation, the body of the unit must be present. If the unit itself
5080 -- is generic, we assume that an instantiation follows, and load & analyze
5081 -- the body unconditionally. This forces analysis of the spec as well.
5083 -- If the unit is not generic, but contains a generic unit, it is loaded on
5084 -- demand, at the point of instantiation (see ch12).
5086 procedure Load_Needed_Body (N : Node_Id; OK : out Boolean) is
5087 Body_Name : Unit_Name_Type;
5088 Unum : Unit_Number_Type;
5090 Save_Style_Check : constant Boolean := Opt.Style_Check;
5091 -- The loading and analysis is done with style checks off
5094 if not GNAT_Mode then
5095 Style_Check := False;
5098 Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
5101 (Load_Name => Body_Name,
5107 if Unum = No_Unit then
5111 Compiler_State := Analyzing; -- reset after load
5113 if not Fatal_Error (Unum) or else Try_Semantics then
5114 if Debug_Flag_L then
5115 Write_Str ("*** Loaded generic body");
5119 Semantics (Cunit (Unum));
5125 Style_Check := Save_Style_Check;
5126 end Load_Needed_Body;
5128 -------------------------
5129 -- Build_Limited_Views --
5130 -------------------------
5132 procedure Build_Limited_Views (N : Node_Id) is
5133 Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N));
5134 P : constant Entity_Id := Cunit_Entity (Unum);
5136 Spec : Node_Id; -- To denote a package specification
5137 Lim_Typ : Entity_Id; -- To denote shadow entities
5138 Comp_Typ : Entity_Id; -- To denote real entities
5140 Lim_Header : Entity_Id; -- Package entity
5141 Last_Lim_E : Entity_Id := Empty; -- Last limited entity built
5142 Last_Pub_Lim_E : Entity_Id; -- To set the first private entity
5144 procedure Decorate_Incomplete_Type (E : Entity_Id; Scop : Entity_Id);
5145 -- Add attributes of an incomplete type to a shadow entity. The same
5146 -- attributes are placed on the real entity, so that gigi receives
5147 -- a consistent view.
5149 procedure Decorate_Package_Specification (P : Entity_Id);
5150 -- Add attributes of a package entity to the entity in a package
5153 procedure Decorate_Tagged_Type
5157 -- Set basic attributes of tagged type T, including its class_wide type.
5158 -- The parameters Loc, Scope are used to decorate the class_wide type.
5160 procedure Build_Chain (Scope : Entity_Id; First_Decl : Node_Id);
5161 -- Construct list of shadow entities and attach it to entity of
5162 -- package that is mentioned in a limited_with clause.
5164 function New_Internal_Shadow_Entity
5165 (Kind : Entity_Kind;
5166 Sloc_Value : Source_Ptr;
5167 Id_Char : Character) return Entity_Id;
5168 -- Build a new internal entity and append it to the list of shadow
5169 -- entities available through the limited-header
5175 procedure Build_Chain (Scope : Entity_Id; First_Decl : Node_Id) is
5176 Analyzed_Unit : constant Boolean := Analyzed (Cunit (Unum));
5177 Is_Tagged : Boolean;
5182 while Present (Decl) loop
5184 -- For each library_package_declaration in the environment, there
5185 -- is an implicit declaration of a *limited view* of that library
5186 -- package. The limited view of a package contains:
5188 -- * For each nested package_declaration, a declaration of the
5189 -- limited view of that package, with the same defining-
5190 -- program-unit name.
5192 -- * For each type_declaration in the visible part, an incomplete
5193 -- type-declaration with the same defining_identifier, whose
5194 -- completion is the type_declaration. If the type_declaration
5195 -- is tagged, then the incomplete_type_declaration is tagged
5198 -- The partial view is tagged if the declaration has the
5199 -- explicit keyword, or else if it is a type extension, both
5200 -- of which can be ascertained syntactically.
5202 if Nkind (Decl) = N_Full_Type_Declaration then
5204 (Nkind (Type_Definition (Decl)) = N_Record_Definition
5205 and then Tagged_Present (Type_Definition (Decl)))
5207 (Nkind (Type_Definition (Decl)) = N_Derived_Type_Definition
5210 (Record_Extension_Part (Type_Definition (Decl))));
5212 Comp_Typ := Defining_Identifier (Decl);
5214 if not Analyzed_Unit then
5216 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
5218 Decorate_Incomplete_Type (Comp_Typ, Scope);
5222 -- Create shadow entity for type
5225 New_Internal_Shadow_Entity
5226 (Kind => Ekind (Comp_Typ),
5227 Sloc_Value => Sloc (Comp_Typ),
5230 Set_Chars (Lim_Typ, Chars (Comp_Typ));
5231 Set_Parent (Lim_Typ, Parent (Comp_Typ));
5232 Set_From_With_Type (Lim_Typ);
5235 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
5237 Decorate_Incomplete_Type (Lim_Typ, Scope);
5240 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
5242 elsif Nkind_In (Decl, N_Private_Type_Declaration,
5243 N_Incomplete_Type_Declaration,
5244 N_Task_Type_Declaration,
5245 N_Protected_Type_Declaration)
5247 Comp_Typ := Defining_Identifier (Decl);
5250 Nkind_In (Decl, N_Private_Type_Declaration,
5251 N_Incomplete_Type_Declaration)
5252 and then Tagged_Present (Decl);
5254 if not Analyzed_Unit then
5256 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
5258 Decorate_Incomplete_Type (Comp_Typ, Scope);
5263 New_Internal_Shadow_Entity
5264 (Kind => Ekind (Comp_Typ),
5265 Sloc_Value => Sloc (Comp_Typ),
5268 Set_Chars (Lim_Typ, Chars (Comp_Typ));
5269 Set_Parent (Lim_Typ, Parent (Comp_Typ));
5270 Set_From_With_Type (Lim_Typ);
5273 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
5275 Decorate_Incomplete_Type (Lim_Typ, Scope);
5278 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
5280 elsif Nkind (Decl) = N_Private_Extension_Declaration then
5281 Comp_Typ := Defining_Identifier (Decl);
5283 if not Analyzed_Unit then
5284 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
5287 -- Create shadow entity for type
5290 New_Internal_Shadow_Entity
5291 (Kind => Ekind (Comp_Typ),
5292 Sloc_Value => Sloc (Comp_Typ),
5295 Set_Chars (Lim_Typ, Chars (Comp_Typ));
5296 Set_Parent (Lim_Typ, Parent (Comp_Typ));
5297 Set_From_With_Type (Lim_Typ);
5299 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
5300 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
5302 elsif Nkind (Decl) = N_Package_Declaration then
5307 Spec : constant Node_Id := Specification (Decl);
5310 Comp_Typ := Defining_Unit_Name (Spec);
5312 if not Analyzed (Cunit (Unum)) then
5313 Decorate_Package_Specification (Comp_Typ);
5314 Set_Scope (Comp_Typ, Scope);
5318 New_Internal_Shadow_Entity
5319 (Kind => Ekind (Comp_Typ),
5320 Sloc_Value => Sloc (Comp_Typ),
5323 Decorate_Package_Specification (Lim_Typ);
5324 Set_Scope (Lim_Typ, Scope);
5326 Set_Chars (Lim_Typ, Chars (Comp_Typ));
5327 Set_Parent (Lim_Typ, Parent (Comp_Typ));
5328 Set_From_With_Type (Lim_Typ);
5330 -- Note: The non_limited_view attribute is not used
5331 -- for local packages.
5335 First_Decl => First (Visible_Declarations (Spec)));
5343 ------------------------------
5344 -- Decorate_Incomplete_Type --
5345 ------------------------------
5347 procedure Decorate_Incomplete_Type (E : Entity_Id; Scop : Entity_Id) is
5349 Set_Ekind (E, E_Incomplete_Type);
5350 Set_Scope (E, Scop);
5352 Set_Is_First_Subtype (E, True);
5353 Set_Stored_Constraint (E, No_Elist);
5354 Set_Full_View (E, Empty);
5355 Init_Size_Align (E);
5356 end Decorate_Incomplete_Type;
5358 --------------------------
5359 -- Decorate_Tagged_Type --
5360 --------------------------
5362 procedure Decorate_Tagged_Type
5370 Decorate_Incomplete_Type (T, Scop);
5371 Set_Is_Tagged_Type (T);
5373 -- Build corresponding class_wide type, if not previously done
5375 -- Note: The class-wide entity is shared by the limited-view
5376 -- and the full-view.
5378 if No (Class_Wide_Type (T)) then
5379 CW := Make_Temporary (Loc, 'S');
5381 -- Set parent to be the same as the parent of the tagged type.
5382 -- We need a parent field set, and it is supposed to point to
5383 -- the declaration of the type. The tagged type declaration
5384 -- essentially declares two separate types, the tagged type
5385 -- itself and the corresponding class-wide type, so it is
5386 -- reasonable for the parent fields to point to the declaration
5389 Set_Parent (CW, Parent (T));
5391 -- Set remaining fields of classwide type
5393 Set_Ekind (CW, E_Class_Wide_Type);
5395 Set_Scope (CW, Scop);
5396 Set_Is_Tagged_Type (CW);
5397 Set_Is_First_Subtype (CW, True);
5398 Init_Size_Align (CW);
5399 Set_Has_Unknown_Discriminants (CW, True);
5400 Set_Class_Wide_Type (CW, CW);
5401 Set_Equivalent_Type (CW, Empty);
5402 Set_From_With_Type (CW, From_With_Type (T));
5404 -- Link type to its class-wide type
5406 Set_Class_Wide_Type (T, CW);
5408 end Decorate_Tagged_Type;
5410 ------------------------------------
5411 -- Decorate_Package_Specification --
5412 ------------------------------------
5414 procedure Decorate_Package_Specification (P : Entity_Id) is
5416 -- Place only the most basic attributes
5418 Set_Ekind (P, E_Package);
5419 Set_Etype (P, Standard_Void_Type);
5420 end Decorate_Package_Specification;
5422 --------------------------------
5423 -- New_Internal_Shadow_Entity --
5424 --------------------------------
5426 function New_Internal_Shadow_Entity
5427 (Kind : Entity_Kind;
5428 Sloc_Value : Source_Ptr;
5429 Id_Char : Character) return Entity_Id
5431 E : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
5434 Set_Ekind (E, Kind);
5435 Set_Is_Internal (E, True);
5437 if Kind in Type_Kind then
5438 Init_Size_Align (E);
5441 Append_Entity (E, Lim_Header);
5444 end New_Internal_Shadow_Entity;
5446 -- Start of processing for Build_Limited_Views
5449 pragma Assert (Limited_Present (N));
5451 -- A library_item mentioned in a limited_with_clause is a package
5452 -- declaration, not a subprogram declaration, generic declaration,
5453 -- generic instantiation, or package renaming declaration.
5455 case Nkind (Unit (Library_Unit (N))) is
5456 when N_Package_Declaration =>
5459 when N_Subprogram_Declaration =>
5460 Error_Msg_N ("subprograms not allowed in "
5461 & "limited with_clauses", N);
5464 when N_Generic_Package_Declaration |
5465 N_Generic_Subprogram_Declaration =>
5466 Error_Msg_N ("generics not allowed in "
5467 & "limited with_clauses", N);
5470 when N_Generic_Instantiation =>
5471 Error_Msg_N ("generic instantiations not allowed in "
5472 & "limited with_clauses", N);
5475 when N_Generic_Renaming_Declaration =>
5476 Error_Msg_N ("generic renamings not allowed in "
5477 & "limited with_clauses", N);
5480 when N_Subprogram_Renaming_Declaration =>
5481 Error_Msg_N ("renamed subprograms not allowed in "
5482 & "limited with_clauses", N);
5485 when N_Package_Renaming_Declaration =>
5486 Error_Msg_N ("renamed packages not allowed in "
5487 & "limited with_clauses", N);
5491 raise Program_Error;
5494 -- Check if the chain is already built
5496 Spec := Specification (Unit (Library_Unit (N)));
5498 if Limited_View_Installed (Spec) then
5502 Set_Ekind (P, E_Package);
5504 -- Build the header of the limited_view
5506 Lim_Header := Make_Temporary (Sloc (N), 'Z');
5507 Set_Ekind (Lim_Header, E_Package);
5508 Set_Is_Internal (Lim_Header);
5509 Set_Limited_View (P, Lim_Header);
5511 -- Create the auxiliary chain. All the shadow entities are appended to
5512 -- the list of entities of the limited-view header
5516 First_Decl => First (Visible_Declarations (Spec)));
5518 -- Save the last built shadow entity. It is needed later to set the
5519 -- reference to the first shadow entity in the private part
5521 Last_Pub_Lim_E := Last_Lim_E;
5523 -- Ada 2005 (AI-262): Add the limited view of the private declarations
5524 -- Required to give support to limited-private-with clauses
5526 Build_Chain (Scope => P,
5527 First_Decl => First (Private_Declarations (Spec)));
5529 if Last_Pub_Lim_E /= Empty then
5530 Set_First_Private_Entity
5531 (Lim_Header, Next_Entity (Last_Pub_Lim_E));
5533 Set_First_Private_Entity
5534 (Lim_Header, First_Entity (P));
5537 Set_Limited_View_Installed (Spec);
5538 end Build_Limited_Views;
5540 -------------------------------
5541 -- Check_Body_Needed_For_SAL --
5542 -------------------------------
5544 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
5546 function Entity_Needs_Body (E : Entity_Id) return Boolean;
5547 -- Determine whether use of entity E might require the presence of its
5548 -- body. For a package this requires a recursive traversal of all nested
5551 ---------------------------
5552 -- Entity_Needed_For_SAL --
5553 ---------------------------
5555 function Entity_Needs_Body (E : Entity_Id) return Boolean is
5559 if Is_Subprogram (E)
5560 and then Has_Pragma_Inline (E)
5564 elsif Ekind_In (E, E_Generic_Function, E_Generic_Procedure) then
5567 elsif Ekind (E) = E_Generic_Package
5569 Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
5570 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
5574 elsif Ekind (E) = E_Package
5575 and then Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
5576 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
5578 Ent := First_Entity (E);
5579 while Present (Ent) loop
5580 if Entity_Needs_Body (Ent) then
5592 end Entity_Needs_Body;
5594 -- Start of processing for Check_Body_Needed_For_SAL
5597 if Ekind (Unit_Name) = E_Generic_Package
5598 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
5599 N_Generic_Package_Declaration
5601 Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
5603 Set_Body_Needed_For_SAL (Unit_Name);
5605 elsif Ekind_In (Unit_Name, E_Generic_Procedure, E_Generic_Function) then
5606 Set_Body_Needed_For_SAL (Unit_Name);
5608 elsif Is_Subprogram (Unit_Name)
5609 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
5610 N_Subprogram_Declaration
5611 and then Has_Pragma_Inline (Unit_Name)
5613 Set_Body_Needed_For_SAL (Unit_Name);
5615 elsif Ekind (Unit_Name) = E_Subprogram_Body then
5616 Check_Body_Needed_For_SAL
5617 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
5619 elsif Ekind (Unit_Name) = E_Package
5620 and then Entity_Needs_Body (Unit_Name)
5622 Set_Body_Needed_For_SAL (Unit_Name);
5624 elsif Ekind (Unit_Name) = E_Package_Body
5625 and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
5627 Check_Body_Needed_For_SAL
5628 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
5630 end Check_Body_Needed_For_SAL;
5632 --------------------
5633 -- Remove_Context --
5634 --------------------
5636 procedure Remove_Context (N : Node_Id) is
5637 Lib_Unit : constant Node_Id := Unit (N);
5640 -- If this is a child unit, first remove the parent units
5642 if Is_Child_Spec (Lib_Unit) then
5643 Remove_Parents (Lib_Unit);
5646 Remove_Context_Clauses (N);
5649 ----------------------------
5650 -- Remove_Context_Clauses --
5651 ----------------------------
5653 procedure Remove_Context_Clauses (N : Node_Id) is
5655 Unit_Name : Entity_Id;
5658 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
5659 -- limited-views first and regular-views later (to maintain the
5662 -- First Phase: Remove limited_with context clauses
5664 Item := First (Context_Items (N));
5665 while Present (Item) loop
5667 -- We are interested only in with clauses which got installed
5670 if Nkind (Item) = N_With_Clause
5671 and then Limited_Present (Item)
5672 and then Limited_View_Installed (Item)
5674 Remove_Limited_With_Clause (Item);
5680 -- Second Phase: Loop through context items and undo regular
5681 -- with_clauses and use_clauses.
5683 Item := First (Context_Items (N));
5684 while Present (Item) loop
5686 -- We are interested only in with clauses which got installed on
5687 -- entry, as indicated by their Context_Installed flag set
5689 if Nkind (Item) = N_With_Clause
5690 and then Limited_Present (Item)
5691 and then Limited_View_Installed (Item)
5695 elsif Nkind (Item) = N_With_Clause
5696 and then Context_Installed (Item)
5698 -- Remove items from one with'ed unit
5700 Unit_Name := Entity (Name (Item));
5701 Remove_Unit_From_Visibility (Unit_Name);
5702 Set_Context_Installed (Item, False);
5704 elsif Nkind (Item) = N_Use_Package_Clause then
5705 End_Use_Package (Item);
5707 elsif Nkind (Item) = N_Use_Type_Clause then
5708 End_Use_Type (Item);
5713 end Remove_Context_Clauses;
5715 --------------------------------
5716 -- Remove_Limited_With_Clause --
5717 --------------------------------
5719 procedure Remove_Limited_With_Clause (N : Node_Id) is
5720 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
5723 Lim_Header : Entity_Id;
5724 Lim_Typ : Entity_Id;
5728 pragma Assert (Limited_View_Installed (N));
5730 -- In case of limited with_clause on subprograms, generics, instances,
5731 -- or renamings, the corresponding error was previously posted and we
5732 -- have nothing to do here.
5734 if Nkind (P_Unit) /= N_Package_Declaration then
5738 P := Defining_Unit_Name (Specification (P_Unit));
5740 -- Handle child packages
5742 if Nkind (P) = N_Defining_Program_Unit_Name then
5743 P := Defining_Identifier (P);
5746 if Debug_Flag_I then
5747 Write_Str ("remove limited view of ");
5748 Write_Name (Chars (P));
5749 Write_Str (" from visibility");
5753 -- Prepare the removal of the shadow entities from visibility. The
5754 -- first element of the limited view is a header (an E_Package
5755 -- entity) that is used to reference the first shadow entity in the
5756 -- private part of the package
5758 Lim_Header := Limited_View (P);
5759 Lim_Typ := First_Entity (Lim_Header);
5761 -- Remove package and shadow entities from visibility if it has not
5764 if not Analyzed (P_Unit) then
5766 Set_Is_Immediately_Visible (P, False);
5768 while Present (Lim_Typ) loop
5770 Next_Entity (Lim_Typ);
5773 -- Otherwise this package has already appeared in the closure and its
5774 -- shadow entities must be replaced by its real entities. This code
5775 -- must be kept synchronized with the complementary code in Install
5776 -- Limited_Withed_Unit.
5779 -- Real entities that are type or subtype declarations were hidden
5780 -- from visibility at the point of installation of the limited-view.
5781 -- Now we recover the previous value of the hidden attribute.
5783 E := First_Entity (P);
5784 while Present (E) and then E /= First_Private_Entity (P) loop
5786 Set_Is_Hidden (E, Was_Hidden (E));
5792 while Present (Lim_Typ)
5793 and then Lim_Typ /= First_Private_Entity (Lim_Header)
5795 -- Nested packages and child units were not unchained
5797 if Ekind (Lim_Typ) /= E_Package
5798 and then not Is_Child_Unit (Non_Limited_View (Lim_Typ))
5800 -- If the package has incomplete types, the limited view of the
5801 -- incomplete type is in fact never visible (AI05-129) but we
5802 -- have created a shadow entity E1 for it, that points to E2,
5803 -- a non-limited incomplete type. This in turn has a full view
5804 -- E3 that is the full declaration. There is a corresponding
5805 -- shadow entity E4. When reinstalling the non-limited view,
5806 -- E2 must become the current entity and E3 must be ignored.
5808 E := Non_Limited_View (Lim_Typ);
5810 if Present (Current_Entity (E))
5811 and then Ekind (Current_Entity (E)) = E_Incomplete_Type
5812 and then Full_View (Current_Entity (E)) = E
5815 -- Lim_Typ is the limited view of a full type declaration
5816 -- that has a previous incomplete declaration, i.e. E3 from
5817 -- the previous description. Nothing to insert.
5822 pragma Assert (not In_Chain (E));
5824 Prev := Current_Entity (Lim_Typ);
5826 if Prev = Lim_Typ then
5827 Set_Current_Entity (E);
5830 while Present (Prev)
5831 and then Homonym (Prev) /= Lim_Typ
5833 Prev := Homonym (Prev);
5836 if Present (Prev) then
5837 Set_Homonym (Prev, E);
5841 -- Preserve structure of homonym chain
5843 Set_Homonym (E, Homonym (Lim_Typ));
5847 Next_Entity (Lim_Typ);
5851 -- Indicate that the limited view of the package is not installed
5853 Set_From_With_Type (P, False);
5854 Set_Limited_View_Installed (N, False);
5855 end Remove_Limited_With_Clause;
5857 --------------------
5858 -- Remove_Parents --
5859 --------------------
5861 procedure Remove_Parents (Lib_Unit : Node_Id) is
5864 P_Spec : Node_Id := Empty;
5866 Vis : constant Boolean :=
5867 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
5870 if Is_Child_Spec (Lib_Unit) then
5871 P_Spec := Parent_Spec (Lib_Unit);
5873 elsif Nkind (Lib_Unit) = N_Package_Body
5874 and then Nkind (Original_Node (Lib_Unit)) = N_Package_Instantiation
5876 P_Spec := Parent_Spec (Original_Node (Lib_Unit));
5879 if Present (P_Spec) then
5881 P_Name := Get_Parent_Entity (P);
5882 Remove_Context_Clauses (P_Spec);
5883 End_Package_Scope (P_Name);
5884 Set_Is_Immediately_Visible (P_Name, Vis);
5886 -- Remove from visibility the siblings as well, which are directly
5887 -- visible while the parent is in scope.
5889 E := First_Entity (P_Name);
5890 while Present (E) loop
5891 if Is_Child_Unit (E) then
5892 Set_Is_Immediately_Visible (E, False);
5898 Set_In_Package_Body (P_Name, False);
5900 -- This is the recursive call to remove the context of any higher
5901 -- level parent. This recursion ensures that all parents are removed
5902 -- in the reverse order of their installation.
5908 ---------------------------------
5909 -- Remove_Private_With_Clauses --
5910 ---------------------------------
5912 procedure Remove_Private_With_Clauses (Comp_Unit : Node_Id) is
5915 function In_Regular_With_Clause (E : Entity_Id) return Boolean;
5916 -- Check whether a given unit appears in a regular with_clause. Used to
5917 -- determine whether a private_with_clause, implicit or explicit, should
5920 ----------------------------
5921 -- In_Regular_With_Clause --
5922 ----------------------------
5924 function In_Regular_With_Clause (E : Entity_Id) return Boolean
5929 Item := First (Context_Items (Comp_Unit));
5930 while Present (Item) loop
5931 if Nkind (Item) = N_With_Clause
5932 and then Entity (Name (Item)) = E
5933 and then not Private_Present (Item)
5941 end In_Regular_With_Clause;
5943 -- Start of processing for Remove_Private_With_Clauses
5946 Item := First (Context_Items (Comp_Unit));
5947 while Present (Item) loop
5948 if Nkind (Item) = N_With_Clause
5949 and then Private_Present (Item)
5951 -- If private_with_clause is redundant, remove it from
5952 -- context, as a small optimization to subsequent handling
5953 -- of private_with clauses in other nested packages..
5955 if In_Regular_With_Clause (Entity (Name (Item))) then
5957 Nxt : constant Node_Id := Next (Item);
5963 elsif Limited_Present (Item) then
5964 if not Limited_View_Installed (Item) then
5965 Remove_Limited_With_Clause (Item);
5971 Remove_Unit_From_Visibility (Entity (Name (Item)));
5972 Set_Context_Installed (Item, False);
5980 end Remove_Private_With_Clauses;
5982 ---------------------------------
5983 -- Remove_Unit_From_Visibility --
5984 ---------------------------------
5986 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
5987 P : constant Entity_Id := Scope (Unit_Name);
5990 if Debug_Flag_I then
5991 Write_Str ("remove unit ");
5992 Write_Name (Chars (Unit_Name));
5993 Write_Str (" from visibility");
5997 if P /= Standard_Standard then
5998 Set_Is_Visible_Child_Unit (Unit_Name, False);
6001 Set_Is_Potentially_Use_Visible (Unit_Name, False);
6002 Set_Is_Immediately_Visible (Unit_Name, False);
6003 end Remove_Unit_From_Visibility;
6018 procedure Unchain (E : Entity_Id) is
6022 Prev := Current_Entity (E);
6028 Set_Name_Entity_Id (Chars (E), Homonym (E));
6031 while Present (Prev)
6032 and then Homonym (Prev) /= E
6034 Prev := Homonym (Prev);
6037 if Present (Prev) then
6038 Set_Homonym (Prev, Homonym (E));
6042 if Debug_Flag_I then
6043 Write_Str (" (homonym) unchain ");
6044 Write_Name (Chars (E));