1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Elists; use Elists;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Fname.UF; use Fname.UF;
35 with Freeze; use Freeze;
36 with Impunit; use Impunit;
37 with Inline; use Inline;
39 with Lib.Load; use Lib.Load;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Output; use Output;
46 with Restrict; use Restrict;
48 with Sem_Ch6; use Sem_Ch6;
49 with Sem_Ch7; use Sem_Ch7;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Dist; use Sem_Dist;
52 with Sem_Prag; use Sem_Prag;
53 with Sem_Util; use Sem_Util;
54 with Sem_Warn; use Sem_Warn;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Sinfo.CN; use Sinfo.CN;
58 with Sinput; use Sinput;
59 with Snames; use Snames;
60 with Style; use Style;
61 with Stylesw; use Stylesw;
62 with Tbuild; use Tbuild;
63 with Ttypes; use Ttypes;
64 with Uname; use Uname;
66 package body Sem_Ch10 is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Analyze_Context (N : Node_Id);
73 -- Analyzes items in the context clause of compilation unit
75 procedure Build_Limited_Views (N : Node_Id);
76 -- Build and decorate the list of shadow entities for a package mentioned
77 -- in a limited_with clause. If the package was not previously analyzed
78 -- then it also performs a basic decoration of the real entities; this
79 -- is required to do not pass non-decorated entities to the back-end.
80 -- Implements Ada0Y (AI-50217).
82 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id);
83 -- Check whether the source for the body of a compilation unit must
84 -- be included in a standalone library.
86 procedure Check_With_Type_Clauses (N : Node_Id);
87 -- If N is a body, verify that any with_type clauses on the spec, or
88 -- on the spec of any parent, have a matching with_clause.
90 procedure Check_Private_Child_Unit (N : Node_Id);
91 -- If a with_clause mentions a private child unit, the compilation
92 -- unit must be a member of the same family, as described in 10.1.2 (8).
94 procedure Check_Stub_Level (N : Node_Id);
95 -- Verify that a stub is declared immediately within a compilation unit,
96 -- and not in an inner frame.
98 procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id);
99 -- If a child unit appears in a limited_with clause, there are implicit
100 -- limited_with clauses on all parents that are not already visible
101 -- through a regular with clause. This procedure creates the implicit
102 -- limited with_clauses for the parents and loads the corresponding units.
103 -- The shadow entities are created when the inserted clause is analyzed.
104 -- Implements Ada0Y (AI-50217).
106 procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id);
107 -- When a child unit appears in a context clause, the implicit withs on
108 -- parents are made explicit, and with clauses are inserted in the context
109 -- clause before the one for the child. If a parent in the with_clause
110 -- is a renaming, the implicit with_clause is on the renaming whose name
111 -- is mentioned in the with_clause, and not on the package it renames.
112 -- N is the compilation unit whose list of context items receives the
113 -- implicit with_clauses.
115 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id;
116 -- Get defining entity of parent unit of a child unit. In most cases this
117 -- is the defining entity of the unit, but for a child instance whose
118 -- parent needs a body for inlining, the instantiation node of the parent
119 -- has not yet been rewritten as a package declaration, and the entity has
120 -- to be retrieved from the Instance_Spec of the unit.
122 procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id);
123 -- If the main unit is a child unit, implicit withs are also added for
124 -- all its ancestors.
126 procedure Install_Context_Clauses (N : Node_Id);
127 -- Subsidiary to previous one. Process only with_ and use_clauses for
128 -- current unit and its library unit if any.
130 procedure Install_Limited_Context_Clauses (N : Node_Id);
131 -- Subsidiary to Install_Context. Process only limited with_clauses
132 -- for current unit. Implements Ada0Y (AI-50217).
134 procedure Install_Limited_Withed_Unit (N : Node_Id);
135 -- Place shadow entities for a limited_with package in the visibility
136 -- structures for the current compilation. Implements Ada0Y (AI-50217).
138 procedure Install_Withed_Unit (With_Clause : Node_Id);
139 -- If the unit is not a child unit, make unit immediately visible.
140 -- The caller ensures that the unit is not already currently installed.
142 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean);
143 -- This procedure establishes the context for the compilation of a child
144 -- unit. If Lib_Unit is a child library spec then the context of the parent
145 -- is installed, and the parent itself made immediately visible, so that
146 -- the child unit is processed in the declarative region of the parent.
147 -- Install_Parents makes a recursive call to itself to ensure that all
148 -- parents are loaded in the nested case. If Lib_Unit is a library body,
149 -- the only effect of Install_Parents is to install the private decls of
150 -- the parents, because the visible parent declarations will have been
151 -- installed as part of the context of the corresponding spec.
153 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
154 -- In the compilation of a child unit, a child of any of the ancestor
155 -- units is directly visible if it is visible, because the parent is in
156 -- an enclosing scope. Iterate over context to find child units of U_Name
157 -- or of some ancestor of it.
159 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean;
160 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
161 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
162 -- a library spec that has a parent. If the call to Is_Child_Spec returns
163 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
164 -- compilation unit for the parent spec.
166 -- Lib_Unit can also be a subprogram body that acts as its own spec. If
167 -- the Parent_Spec is non-empty, this is also a child unit.
169 procedure Remove_With_Type_Clause (Name : Node_Id);
170 -- Remove imported type and its enclosing package from visibility, and
171 -- remove attributes of imported type so they don't interfere with its
172 -- analysis (should it appear otherwise in the context).
174 procedure Remove_Context_Clauses (N : Node_Id);
175 -- Subsidiary of previous one. Remove use_ and with_clauses.
177 procedure Remove_Limited_With_Clause (N : Node_Id);
178 -- Remove from visibility the shadow entities introduced for a package
179 -- mentioned in a limited_with clause. Implements Ada0Y (AI-50217).
181 procedure Remove_Parents (Lib_Unit : Node_Id);
182 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
183 -- contexts established by the corresponding call to Install_Parents are
184 -- removed. Remove_Parents contains a recursive call to itself to ensure
185 -- that all parents are removed in the nested case.
187 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id);
188 -- Reset all visibility flags on unit after compiling it, either as a
189 -- main unit or as a unit in the context.
191 procedure Unchain (E : Entity_Id);
192 -- Remove single entity from visibility list
194 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id);
195 -- Common processing for all stubs (subprograms, tasks, packages, and
196 -- protected cases). N is the stub to be analyzed. Once the subunit
197 -- name is established, load and analyze. Nam is the non-overloadable
198 -- entity for which the proper body provides a completion. Subprogram
199 -- stubs are handled differently because they can be declarations.
201 --------------------------
202 -- Limited_With_Clauses --
203 --------------------------
205 -- Limited_With clauses are the mechanism chosen for Ada05 to support
206 -- mutually recursive types declared in different units. A limited_with
207 -- clause that names package P in the context of unit U makes the types
208 -- declared in the visible part of P available within U, but with the
209 -- restriction that these types can only be used as incomplete types.
210 -- The limited_with clause does not impose a semantic dependence on P,
211 -- and it is possible for two packages to have limited_with_clauses on
212 -- each other without creating an elaboration circularity.
214 -- To support this feature, the analysis of a limited_with clause must
215 -- create an abbreviated view of the package, without performing any
216 -- semantic analysis on it. This "package abstract" contains shadow
217 -- types that are in one-one correspondence with the real types in the
218 -- package, and that have the properties of incomplete types.
220 -- The implementation creates two element lists: one to chain the shadow
221 -- entities, and one to chain the corresponding type entities in the tree
222 -- of the package. Links between corresponding entities in both chains
223 -- allow the compiler to select the proper view of a given type, depending
224 -- on the context. Note that in contrast with the handling of private
225 -- types, the limited view and the non-limited view of a type are treated
226 -- as separate entities, and no entity exchange needs to take place, which
227 -- makes the implementation must simpler than could be feared.
229 ------------------------------
230 -- Analyze_Compilation_Unit --
231 ------------------------------
233 procedure Analyze_Compilation_Unit (N : Node_Id) is
234 Unit_Node : constant Node_Id := Unit (N);
235 Lib_Unit : Node_Id := Library_Unit (N);
237 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
238 Par_Spec_Name : Unit_Name_Type;
239 Unum : Unit_Number_Type;
241 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id);
242 -- Generate cross-reference information for the parents of child units.
243 -- N is a defining_program_unit_name, and P_Id is the immediate parent.
245 --------------------------------
246 -- Generate_Parent_References --
247 --------------------------------
249 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is
251 P_Name : Entity_Id := P_Id;
254 Pref := Name (Parent (Defining_Entity (N)));
256 if Nkind (Pref) = N_Expanded_Name then
258 -- Done already, if the unit has been compiled indirectly as
259 -- part of the closure of its context because of inlining.
264 while Nkind (Pref) = N_Selected_Component loop
265 Change_Selected_Component_To_Expanded_Name (Pref);
266 Set_Entity (Pref, P_Name);
267 Set_Etype (Pref, Etype (P_Name));
268 Generate_Reference (P_Name, Pref, 'r');
269 Pref := Prefix (Pref);
270 P_Name := Scope (P_Name);
273 -- The guard here on P_Name is to handle the error condition where
274 -- the parent unit is missing because the file was not found.
276 if Present (P_Name) then
277 Set_Entity (Pref, P_Name);
278 Set_Etype (Pref, Etype (P_Name));
279 Generate_Reference (P_Name, Pref, 'r');
280 Style.Check_Identifier (Pref, P_Name);
282 end Generate_Parent_References;
284 -- Start of processing for Analyze_Compilation_Unit
287 Process_Compilation_Unit_Pragmas (N);
289 -- If the unit is a subunit whose parent has not been analyzed (which
290 -- indicates that the main unit is a subunit, either the current one or
291 -- one of its descendents) then the subunit is compiled as part of the
292 -- analysis of the parent, which we proceed to do. Basically this gets
293 -- handled from the top down and we don't want to do anything at this
294 -- level (i.e. this subunit will be handled on the way down from the
295 -- parent), so at this level we immediately return. If the subunit
296 -- ends up not analyzed, it means that the parent did not contain a
297 -- stub for it, or that there errors were dectected in some ancestor.
299 if Nkind (Unit_Node) = N_Subunit
300 and then not Analyzed (Lib_Unit)
302 Semantics (Lib_Unit);
304 if not Analyzed (Proper_Body (Unit_Node)) then
305 if Serious_Errors_Detected > 0 then
306 Error_Msg_N ("subunit not analyzed (errors in parent unit)", N);
308 Error_Msg_N ("missing stub for subunit", N);
315 -- Analyze context (this will call Sem recursively for with'ed units)
319 -- If the unit is a package body, the spec is already loaded and must
320 -- be analyzed first, before we analyze the body.
322 if Nkind (Unit_Node) = N_Package_Body then
324 -- If no Lib_Unit, then there was a serious previous error, so
325 -- just ignore the entire analysis effort
327 if No (Lib_Unit) then
331 Semantics (Lib_Unit);
332 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
334 -- Verify that the library unit is a package declaration.
336 if Nkind (Unit (Lib_Unit)) /= N_Package_Declaration
338 Nkind (Unit (Lib_Unit)) /= N_Generic_Package_Declaration
341 ("no legal package declaration for package body", N);
344 -- Otherwise, the entity in the declaration is visible. Update
345 -- the version to reflect dependence of this body on the spec.
348 Spec_Id := Defining_Entity (Unit (Lib_Unit));
349 Set_Is_Immediately_Visible (Spec_Id, True);
350 Version_Update (N, Lib_Unit);
352 if Nkind (Defining_Unit_Name (Unit_Node))
353 = N_Defining_Program_Unit_Name
355 Generate_Parent_References (Unit_Node, Scope (Spec_Id));
360 -- If the unit is a subprogram body, then we similarly need to analyze
361 -- its spec. However, things are a little simpler in this case, because
362 -- here, this analysis is done only for error checking and consistency
363 -- purposes, so there's nothing else to be done.
365 elsif Nkind (Unit_Node) = N_Subprogram_Body then
366 if Acts_As_Spec (N) then
368 -- If the subprogram body is a child unit, we must create a
369 -- declaration for it, in order to properly load the parent(s).
370 -- After this, the original unit does not acts as a spec, because
371 -- there is an explicit one. If this unit appears in a context
372 -- clause, then an implicit with on the parent will be added when
373 -- installing the context. If this is the main unit, there is no
374 -- Unit_Table entry for the declaration, (It has the unit number
375 -- of the main unit) and code generation is unaffected.
377 Unum := Get_Cunit_Unit_Number (N);
378 Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum));
380 if Par_Spec_Name /= No_Name then
383 (Load_Name => Par_Spec_Name,
388 if Unum /= No_Unit then
390 -- Build subprogram declaration and attach parent unit to it
391 -- This subprogram declaration does not come from source!
394 Loc : constant Source_Ptr := Sloc (N);
395 SCS : constant Boolean :=
396 Get_Comes_From_Source_Default;
399 Set_Comes_From_Source_Default (False);
401 Make_Compilation_Unit (Loc,
402 Context_Items => New_Copy_List (Context_Items (N)),
404 Make_Subprogram_Declaration (Sloc (N),
407 (Specification (Unit_Node))),
409 Make_Compilation_Unit_Aux (Loc));
411 Set_Library_Unit (N, Lib_Unit);
412 Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
413 Semantics (Lib_Unit);
414 Set_Acts_As_Spec (N, False);
415 Set_Comes_From_Source_Default (SCS);
420 -- Here for subprogram with separate declaration
423 Semantics (Lib_Unit);
424 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
425 Version_Update (N, Lib_Unit);
428 if Nkind (Defining_Unit_Name (Specification (Unit_Node))) =
429 N_Defining_Program_Unit_Name
431 Generate_Parent_References (
432 Specification (Unit_Node),
433 Scope (Defining_Entity (Unit (Lib_Unit))));
437 -- If it is a child unit, the parent must be elaborated first
438 -- and we update version, since we are dependent on our parent.
440 if Is_Child_Spec (Unit_Node) then
442 -- The analysis of the parent is done with style checks off
445 Save_Style_Check : constant Boolean := Style_Check;
446 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
447 Cunit_Boolean_Restrictions_Save;
450 if not GNAT_Mode then
451 Style_Check := False;
454 Semantics (Parent_Spec (Unit_Node));
455 Version_Update (N, Parent_Spec (Unit_Node));
456 Style_Check := Save_Style_Check;
457 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
461 -- With the analysis done, install the context. Note that we can't
462 -- install the context from the with clauses as we analyze them,
463 -- because each with clause must be analyzed in a clean visibility
464 -- context, so we have to wait and install them all at once.
468 if Is_Child_Spec (Unit_Node) then
470 -- Set the entities of all parents in the program_unit_name.
472 Generate_Parent_References (
473 Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node))));
476 -- All components of the context: with-clauses, library unit, ancestors
477 -- if any, (and their context) are analyzed and installed. Now analyze
478 -- the unit itself, which is either a package, subprogram spec or body.
482 -- The above call might have made Unit_Node an N_Subprogram_Body
483 -- from something else, so propagate any Acts_As_Spec flag.
485 if Nkind (Unit_Node) = N_Subprogram_Body
486 and then Acts_As_Spec (Unit_Node)
488 Set_Acts_As_Spec (N);
491 -- Treat compilation unit pragmas that appear after the library unit
493 if Present (Pragmas_After (Aux_Decls_Node (N))) then
495 Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N)));
498 while Present (Prag_Node) loop
505 -- Generate distribution stub files if requested and no error
508 and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
510 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
511 and then not Fatal_Error (Main_Unit)
513 if Is_RCI_Pkg_Spec_Or_Body (N) then
515 -- Regular RCI package
517 Add_Stub_Constructs (N);
519 elsif (Nkind (Unit_Node) = N_Package_Declaration
520 and then Is_Shared_Passive (Defining_Entity
521 (Specification (Unit_Node))))
522 or else (Nkind (Unit_Node) = N_Package_Body
524 Is_Shared_Passive (Corresponding_Spec (Unit_Node)))
526 -- Shared passive package
528 Add_Stub_Constructs (N);
530 elsif Nkind (Unit_Node) = N_Package_Instantiation
532 Is_Remote_Call_Interface
533 (Defining_Entity (Specification (Instance_Spec (Unit_Node))))
535 -- Instantiation of a RCI generic package
537 Add_Stub_Constructs (N);
540 -- Reanalyze the unit with the new constructs
545 if Nkind (Unit_Node) = N_Package_Declaration
546 or else Nkind (Unit_Node) in N_Generic_Declaration
547 or else Nkind (Unit_Node) = N_Package_Renaming_Declaration
548 or else Nkind (Unit_Node) = N_Subprogram_Declaration
550 Remove_Unit_From_Visibility (Defining_Entity (Unit_Node));
552 -- If the unit is an instantiation whose body will be elaborated
553 -- for inlining purposes, use the the proper entity of the instance.
555 elsif Nkind (Unit_Node) = N_Package_Instantiation
556 and then not Error_Posted (Unit_Node)
558 Remove_Unit_From_Visibility
559 (Defining_Entity (Instance_Spec (Unit_Node)));
561 elsif Nkind (Unit_Node) = N_Package_Body
562 or else (Nkind (Unit_Node) = N_Subprogram_Body
563 and then not Acts_As_Spec (Unit_Node))
565 -- Bodies that are not the main unit are compiled if they
566 -- are generic or contain generic or inlined units. Their
567 -- analysis brings in the context of the corresponding spec
568 -- (unit declaration) which must be removed as well, to
569 -- return the compilation environment to its proper state.
571 Remove_Context (Lib_Unit);
572 Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False);
575 -- Last step is to deinstall the context we just installed
576 -- as well as the unit just compiled.
580 -- If this is the main unit and we are generating code, we must
581 -- check that all generic units in the context have a body if they
582 -- need it, even if they have not been instantiated. In the absence
583 -- of .ali files for generic units, we must force the load of the body,
584 -- just to produce the proper error if the body is absent. We skip this
585 -- verification if the main unit itself is generic.
587 if Get_Cunit_Unit_Number (N) = Main_Unit
588 and then Operating_Mode = Generate_Code
589 and then Expander_Active
591 -- Check whether the source for the body of the unit must be
592 -- included in a standalone library.
594 Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit));
596 -- Indicate that the main unit is now analyzed, to catch possible
597 -- circularities between it and generic bodies. Remove main unit
598 -- from visibility. This might seem superfluous, but the main unit
599 -- must not be visible in the generic body expansions that follow.
601 Set_Analyzed (N, True);
602 Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False);
607 Un : Unit_Number_Type;
609 Save_Style_Check : constant Boolean := Style_Check;
610 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
611 Cunit_Boolean_Restrictions_Save;
614 Item := First (Context_Items (N));
615 while Present (Item) loop
617 -- Ada0Y (AI-50217): Do not consider limited-withed units
619 if Nkind (Item) = N_With_Clause
620 and then not Implicit_With (Item)
621 and then not Limited_Present (Item)
623 Nam := Entity (Name (Item));
625 if (Is_Generic_Subprogram (Nam)
626 and then not Is_Intrinsic_Subprogram (Nam))
627 or else (Ekind (Nam) = E_Generic_Package
628 and then Unit_Requires_Body (Nam))
630 Style_Check := False;
632 if Present (Renamed_Object (Nam)) then
635 (Load_Name => Get_Body_Name
637 (Unit_Declaration_Node
638 (Renamed_Object (Nam)))),
646 (Load_Name => Get_Body_Name
647 (Get_Unit_Name (Item)),
656 ("body of generic unit& not found", Item, Nam);
659 elsif not Analyzed (Cunit (Un))
660 and then Un /= Main_Unit
661 and then not Fatal_Error (Un)
663 Style_Check := False;
664 Semantics (Cunit (Un));
672 Style_Check := Save_Style_Check;
673 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
677 -- Deal with creating elaboration Boolean if needed. We create an
678 -- elaboration boolean only for units that come from source since
679 -- units manufactured by the compiler never need elab checks.
681 if Comes_From_Source (N)
683 (Nkind (Unit (N)) = N_Package_Declaration or else
684 Nkind (Unit (N)) = N_Generic_Package_Declaration or else
685 Nkind (Unit (N)) = N_Subprogram_Declaration or else
686 Nkind (Unit (N)) = N_Generic_Subprogram_Declaration)
689 Loc : constant Source_Ptr := Sloc (N);
690 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
693 Spec_Id := Defining_Entity (Unit (N));
694 Generate_Definition (Spec_Id);
696 -- See if an elaboration entity is required for possible
697 -- access before elaboration checking. Note that we must
698 -- allow for this even if -gnatE is not set, since a client
699 -- may be compiled in -gnatE mode and reference the entity.
701 -- Case of units which do not require elaboration checks
704 -- Pure units do not need checks
708 -- Preelaborated units do not need checks
710 or else Is_Preelaborated (Spec_Id)
712 -- No checks needed if pagma Elaborate_Body present
714 or else Has_Pragma_Elaborate_Body (Spec_Id)
716 -- No checks needed if unit does not require a body
718 or else not Unit_Requires_Body (Spec_Id)
720 -- No checks needed for predefined files
722 or else Is_Predefined_File_Name (Unit_File_Name (Unum))
724 -- No checks required if no separate spec
726 or else Acts_As_Spec (N)
728 -- This is a case where we only need the entity for
729 -- checking to prevent multiple elaboration checks.
731 Set_Elaboration_Entity_Required (Spec_Id, False);
733 -- Case of elaboration entity is required for access before
734 -- elaboration checking (so certainly we must build it!)
737 Set_Elaboration_Entity_Required (Spec_Id, True);
740 Build_Elaboration_Entity (N, Spec_Id);
744 -- Finally, freeze the compilation unit entity. This for sure is needed
745 -- because of some warnings that can be output (see Freeze_Subprogram),
746 -- but may in general be required. If freezing actions result, place
747 -- them in the compilation unit actions list, and analyze them.
750 Loc : constant Source_Ptr := Sloc (N);
751 L : constant List_Id :=
752 Freeze_Entity (Cunit_Entity (Current_Sem_Unit), Loc);
755 while Is_Non_Empty_List (L) loop
756 Insert_Library_Level_Action (Remove_Head (L));
762 if Nkind (Unit_Node) = N_Package_Declaration
763 and then Get_Cunit_Unit_Number (N) /= Main_Unit
764 and then Expander_Active
767 Save_Style_Check : constant Boolean := Style_Check;
768 Save_Warning : constant Warning_Mode_Type := Warning_Mode;
769 Options : Style_Check_Options;
772 Save_Style_Check_Options (Options);
773 Reset_Style_Check_Options;
774 Opt.Warning_Mode := Suppress;
775 Check_Body_For_Inlining (N, Defining_Entity (Unit_Node));
777 Reset_Style_Check_Options;
778 Set_Style_Check_Options (Options);
779 Style_Check := Save_Style_Check;
780 Warning_Mode := Save_Warning;
783 end Analyze_Compilation_Unit;
785 ---------------------
786 -- Analyze_Context --
787 ---------------------
789 procedure Analyze_Context (N : Node_Id) is
793 -- Loop through context items. This is done is three passes:
794 -- a) The first pass analyze non-limited with-clauses.
795 -- b) The second pass add implicit limited_with clauses for
796 -- the parents of child units (Ada0Y: AI-50217)
797 -- c) The third pass analyzes limited_with clauses (Ada0Y: AI-50217)
799 Item := First (Context_Items (N));
800 while Present (Item) loop
802 -- For with clause, analyze the with clause, and then update
803 -- the version, since we are dependent on a unit that we with.
805 if Nkind (Item) = N_With_Clause
806 and then not Limited_Present (Item)
809 -- Skip analyzing with clause if no unit, nothing to do (this
810 -- happens for a with that references a non-existant unit)
812 if Present (Library_Unit (Item)) then
816 if not Implicit_With (Item) then
817 Version_Update (N, Library_Unit (Item));
820 -- But skip use clauses at this stage, since we don't want to do
821 -- any installing of potentially use visible entities until we
822 -- we actually install the complete context (in Install_Context).
823 -- Otherwise things can get installed in the wrong context.
824 -- Similarly, pragmas are analyzed in Install_Context, after all
825 -- the implicit with's on parent units are generated.
834 -- Second pass: add implicit limited_with_clauses for parents of
835 -- child units mentioned in limited_with clauses.
837 Item := First (Context_Items (N));
839 while Present (Item) loop
840 if Nkind (Item) = N_With_Clause
841 and then Limited_Present (Item)
842 and then Nkind (Name (Item)) = N_Selected_Component
844 Expand_Limited_With_Clause
845 (Nam => Prefix (Name (Item)), N => Item);
851 -- Third pass: examine all limited_with clauses.
853 Item := First (Context_Items (N));
855 while Present (Item) loop
856 if Nkind (Item) = N_With_Clause
857 and then Limited_Present (Item)
860 if Nkind (Unit (N)) /= N_Package_Declaration then
861 Error_Msg_N ("limited with_clause only allowed in"
862 & " package specification", Item);
865 -- Skip analyzing with clause if no unit, see above.
867 if Present (Library_Unit (Item)) then
871 -- A limited_with does not impose an elaboration order, but
872 -- there is a semantic dependency for recompilation purposes.
874 if not Implicit_With (Item) then
875 Version_Update (N, Library_Unit (Item));
883 -------------------------------
884 -- Analyze_Package_Body_Stub --
885 -------------------------------
887 procedure Analyze_Package_Body_Stub (N : Node_Id) is
888 Id : constant Entity_Id := Defining_Identifier (N);
892 -- The package declaration must be in the current declarative part.
894 Check_Stub_Level (N);
895 Nam := Current_Entity_In_Scope (Id);
897 if No (Nam) or else not Is_Package (Nam) then
898 Error_Msg_N ("missing specification for package stub", N);
900 elsif Has_Completion (Nam)
901 and then Present (Corresponding_Body (Unit_Declaration_Node (Nam)))
903 Error_Msg_N ("duplicate or redundant stub for package", N);
906 -- Indicate that the body of the package exists. If we are doing
907 -- only semantic analysis, the stub stands for the body. If we are
908 -- generating code, the existence of the body will be confirmed
909 -- when we load the proper body.
911 Set_Has_Completion (Nam);
912 Set_Scope (Defining_Entity (N), Current_Scope);
913 Generate_Reference (Nam, Id, 'b');
914 Analyze_Proper_Body (N, Nam);
916 end Analyze_Package_Body_Stub;
918 -------------------------
919 -- Analyze_Proper_Body --
920 -------------------------
922 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is
923 Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
924 Unum : Unit_Number_Type;
926 procedure Optional_Subunit;
927 -- This procedure is called when the main unit is a stub, or when we
928 -- are not generating code. In such a case, we analyze the subunit if
929 -- present, which is user-friendly and in fact required for ASIS, but
930 -- we don't complain if the subunit is missing.
932 ----------------------
933 -- Optional_Subunit --
934 ----------------------
936 procedure Optional_Subunit is
940 -- Try to load subunit, but ignore any errors that occur during
941 -- the loading of the subunit, by using the special feature in
942 -- Errout to ignore all errors. Note that Fatal_Error will still
943 -- be set, so we will be able to check for this case below.
945 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
948 (Load_Name => Subunit_Name,
952 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
954 -- All done if we successfully loaded the subunit
957 and then (not Fatal_Error (Unum) or else Try_Semantics)
959 Comp_Unit := Cunit (Unum);
961 Set_Corresponding_Stub (Unit (Comp_Unit), N);
962 Analyze_Subunit (Comp_Unit);
963 Set_Library_Unit (N, Comp_Unit);
966 and then Present (Nam)
968 if Is_Protected_Type (Nam) then
969 Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N));
971 Set_Corresponding_Body (
972 Unit_Declaration_Node (Nam), Defining_Identifier (N));
975 end Optional_Subunit;
977 -- Start of processing for Analyze_Proper_Body
980 -- If the subunit is already loaded, it means that the main unit
981 -- is a subunit, and that the current unit is one of its parents
982 -- which was being analyzed to provide the needed context for the
983 -- analysis of the subunit. In this case we analyze the subunit and
984 -- continue with the parent, without looking a subsequent subunits.
986 if Is_Loaded (Subunit_Name) then
988 -- If the proper body is already linked to the stub node,
989 -- the stub is in a generic unit and just needs analyzing.
991 if Present (Library_Unit (N)) then
992 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
993 Analyze_Subunit (Library_Unit (N));
995 -- Otherwise we must load the subunit and link to it
998 -- Load the subunit, this must work, since we originally
999 -- loaded the subunit earlier on. So this will not really
1000 -- load it, just give access to it.
1004 (Load_Name => Subunit_Name,
1009 -- And analyze the subunit in the parent context (note that we
1010 -- do not call Semantics, since that would remove the parent
1011 -- context). Because of this, we have to manually reset the
1012 -- compiler state to Analyzing since it got destroyed by Load.
1014 if Unum /= No_Unit then
1015 Compiler_State := Analyzing;
1017 -- Check that the proper body is a subunit and not a child
1018 -- unit. If the unit was previously loaded, the error will
1019 -- have been emitted when copying the generic node, so we
1020 -- just return to avoid cascaded errors.
1022 if Nkind (Unit (Cunit (Unum))) /= N_Subunit then
1026 Set_Corresponding_Stub (Unit (Cunit (Unum)), N);
1027 Analyze_Subunit (Cunit (Unum));
1028 Set_Library_Unit (N, Cunit (Unum));
1032 -- If the main unit is a subunit, then we are just performing semantic
1033 -- analysis on that subunit, and any other subunits of any parent unit
1034 -- should be ignored, except that if we are building trees for ASIS
1035 -- usage we want to annotate the stub properly.
1037 elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
1038 and then Subunit_Name /= Unit_Name (Main_Unit)
1044 -- But before we return, set the flag for unloaded subunits. This
1045 -- will suppress junk warnings of variables in the same declarative
1046 -- part (or a higher level one) that are in danger of looking unused
1047 -- when in fact there might be a declaration in the subunit that we
1048 -- do not intend to load.
1050 Unloaded_Subunits := True;
1053 -- If the subunit is not already loaded, and we are generating code,
1054 -- then this is the case where compilation started from the parent,
1055 -- and we are generating code for an entire subunit tree. In that
1056 -- case we definitely need to load the subunit.
1058 -- In order to continue the analysis with the rest of the parent,
1059 -- and other subunits, we load the unit without requiring its
1060 -- presence, and emit a warning if not found, rather than terminating
1061 -- the compilation abruptly, as for other missing file problems.
1063 elsif Original_Operating_Mode = Generate_Code then
1065 -- If the proper body is already linked to the stub node,
1066 -- the stub is in a generic unit and just needs analyzing.
1068 -- We update the version. Although we are not technically
1069 -- semantically dependent on the subunit, given our approach
1070 -- of macro substitution of subunits, it makes sense to
1071 -- include it in the version identification.
1073 if Present (Library_Unit (N)) then
1074 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1075 Analyze_Subunit (Library_Unit (N));
1076 Version_Update (Cunit (Main_Unit), Library_Unit (N));
1078 -- Otherwise we must load the subunit and link to it
1083 (Load_Name => Subunit_Name,
1088 if Original_Operating_Mode = Generate_Code
1089 and then Unum = No_Unit
1091 Error_Msg_Name_1 := Subunit_Name;
1093 Get_File_Name (Subunit_Name, Subunit => True);
1095 ("subunit% in file{ not found!?", N);
1096 Subunits_Missing := True;
1099 -- Load_Unit may reset Compiler_State, since it may have been
1100 -- necessary to parse an additional units, so we make sure
1101 -- that we reset it to the Analyzing state.
1103 Compiler_State := Analyzing;
1106 and then (not Fatal_Error (Unum) or else Try_Semantics)
1108 if Debug_Flag_L then
1109 Write_Str ("*** Loaded subunit from stub. Analyze");
1114 Comp_Unit : constant Node_Id := Cunit (Unum);
1117 -- Check for child unit instead of subunit
1119 if Nkind (Unit (Comp_Unit)) /= N_Subunit then
1121 ("expected SEPARATE subunit, found child unit",
1122 Cunit_Entity (Unum));
1124 -- OK, we have a subunit, so go ahead and analyze it,
1125 -- and set Scope of entity in stub, for ASIS use.
1128 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1129 Analyze_Subunit (Comp_Unit);
1130 Set_Library_Unit (N, Comp_Unit);
1132 -- We update the version. Although we are not technically
1133 -- semantically dependent on the subunit, given our
1134 -- approach of macro substitution of subunits, it makes
1135 -- sense to include it in the version identification.
1137 Version_Update (Cunit (Main_Unit), Comp_Unit);
1143 -- The remaining case is when the subunit is not already loaded and
1144 -- we are not generating code. In this case we are just performing
1145 -- semantic analysis on the parent, and we are not interested in
1146 -- the subunit. For subprograms, analyze the stub as a body. For
1147 -- other entities the stub has already been marked as completed.
1153 end Analyze_Proper_Body;
1155 ----------------------------------
1156 -- Analyze_Protected_Body_Stub --
1157 ----------------------------------
1159 procedure Analyze_Protected_Body_Stub (N : Node_Id) is
1160 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
1163 Check_Stub_Level (N);
1165 -- First occurence of name may have been as an incomplete type.
1167 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1168 Nam := Full_View (Nam);
1172 or else not Is_Protected_Type (Etype (Nam))
1174 Error_Msg_N ("missing specification for Protected body", N);
1176 Set_Scope (Defining_Entity (N), Current_Scope);
1177 Set_Has_Completion (Etype (Nam));
1178 Generate_Reference (Nam, Defining_Identifier (N), 'b');
1179 Analyze_Proper_Body (N, Etype (Nam));
1181 end Analyze_Protected_Body_Stub;
1183 ----------------------------------
1184 -- Analyze_Subprogram_Body_Stub --
1185 ----------------------------------
1187 -- A subprogram body stub can appear with or without a previous
1188 -- specification. If there is one, the analysis of the body will
1189 -- find it and verify conformance. The formals appearing in the
1190 -- specification of the stub play no role, except for requiring an
1191 -- additional conformance check. If there is no previous subprogram
1192 -- declaration, the stub acts as a spec, and provides the defining
1193 -- entity for the subprogram.
1195 procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
1199 Check_Stub_Level (N);
1201 -- Verify that the identifier for the stub is unique within this
1202 -- declarative part.
1204 if Nkind (Parent (N)) = N_Block_Statement
1205 or else Nkind (Parent (N)) = N_Package_Body
1206 or else Nkind (Parent (N)) = N_Subprogram_Body
1208 Decl := First (Declarations (Parent (N)));
1210 while Present (Decl)
1213 if Nkind (Decl) = N_Subprogram_Body_Stub
1214 and then (Chars (Defining_Unit_Name (Specification (Decl)))
1215 = Chars (Defining_Unit_Name (Specification (N))))
1217 Error_Msg_N ("identifier for stub is not unique", N);
1224 -- Treat stub as a body, which checks conformance if there is a previous
1225 -- declaration, or else introduces entity and its signature.
1227 Analyze_Subprogram_Body (N);
1228 Analyze_Proper_Body (N, Empty);
1229 end Analyze_Subprogram_Body_Stub;
1231 ---------------------
1232 -- Analyze_Subunit --
1233 ---------------------
1235 -- A subunit is compiled either by itself (for semantic checking)
1236 -- or as part of compiling the parent (for code generation). In
1237 -- either case, by the time we actually process the subunit, the
1238 -- parent has already been installed and analyzed. The node N is
1239 -- a compilation unit, whose context needs to be treated here,
1240 -- because we come directly here from the parent without calling
1241 -- Analyze_Compilation_Unit.
1243 -- The compilation context includes the explicit context of the
1244 -- subunit, and the context of the parent, together with the parent
1245 -- itself. In order to compile the current context, we remove the
1246 -- one inherited from the parent, in order to have a clean visibility
1247 -- table. We restore the parent context before analyzing the proper
1248 -- body itself. On exit, we remove only the explicit context of the
1251 procedure Analyze_Subunit (N : Node_Id) is
1252 Lib_Unit : constant Node_Id := Library_Unit (N);
1253 Par_Unit : constant Entity_Id := Current_Scope;
1255 Lib_Spec : Node_Id := Library_Unit (Lib_Unit);
1256 Num_Scopes : Int := 0;
1257 Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id;
1258 Enclosing_Child : Entity_Id := Empty;
1259 Svg : constant Suppress_Array := Scope_Suppress;
1261 procedure Analyze_Subunit_Context;
1262 -- Capture names in use clauses of the subunit. This must be done
1263 -- before re-installing parent declarations, because items in the
1264 -- context must not be hidden by declarations local to the parent.
1266 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id);
1267 -- Recursive procedure to restore scope of all ancestors of subunit,
1268 -- from outermost in. If parent is not a subunit, the call to install
1269 -- context installs context of spec and (if parent is a child unit)
1270 -- the context of its parents as well. It is confusing that parents
1271 -- should be treated differently in both cases, but the semantics are
1272 -- just not identical.
1274 procedure Re_Install_Use_Clauses;
1275 -- As part of the removal of the parent scope, the use clauses are
1276 -- removed, to be reinstalled when the context of the subunit has
1277 -- been analyzed. Use clauses may also have been affected by the
1278 -- analysis of the context of the subunit, so they have to be applied
1279 -- again, to insure that the compilation environment of the rest of
1280 -- the parent unit is identical.
1282 procedure Remove_Scope;
1283 -- Remove current scope from scope stack, and preserve the list
1284 -- of use clauses in it, to be reinstalled after context is analyzed.
1286 ------------------------------
1287 -- Analyze_Subunit_Context --
1288 ------------------------------
1290 procedure Analyze_Subunit_Context is
1293 Unit_Name : Entity_Id;
1296 Analyze_Context (N);
1297 Item := First (Context_Items (N));
1299 -- make withed units immediately visible. If child unit, make the
1300 -- ultimate parent immediately visible.
1302 while Present (Item) loop
1304 if Nkind (Item) = N_With_Clause then
1305 Unit_Name := Entity (Name (Item));
1307 while Is_Child_Unit (Unit_Name) loop
1308 Set_Is_Visible_Child_Unit (Unit_Name);
1309 Unit_Name := Scope (Unit_Name);
1312 if not Is_Immediately_Visible (Unit_Name) then
1313 Set_Is_Immediately_Visible (Unit_Name);
1314 Set_Context_Installed (Item);
1317 elsif Nkind (Item) = N_Use_Package_Clause then
1318 Nam := First (Names (Item));
1320 while Present (Nam) loop
1325 elsif Nkind (Item) = N_Use_Type_Clause then
1326 Nam := First (Subtype_Marks (Item));
1328 while Present (Nam) loop
1337 Item := First (Context_Items (N));
1339 -- reset visibility of withed units. They will be made visible
1340 -- again when we install the subunit context.
1342 while Present (Item) loop
1344 if Nkind (Item) = N_With_Clause then
1345 Unit_Name := Entity (Name (Item));
1347 while Is_Child_Unit (Unit_Name) loop
1348 Set_Is_Visible_Child_Unit (Unit_Name, False);
1349 Unit_Name := Scope (Unit_Name);
1352 if Context_Installed (Item) then
1353 Set_Is_Immediately_Visible (Unit_Name, False);
1354 Set_Context_Installed (Item, False);
1361 end Analyze_Subunit_Context;
1363 ------------------------
1364 -- Re_Install_Parents --
1365 ------------------------
1367 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is
1371 if Nkind (Unit (L)) = N_Subunit then
1372 Re_Install_Parents (Library_Unit (L), Scope (Scop));
1375 Install_Context (L);
1377 -- If the subunit occurs within a child unit, we must restore the
1378 -- immediate visibility of any siblings that may occur in context.
1380 if Present (Enclosing_Child) then
1381 Install_Siblings (Enclosing_Child, L);
1386 if Scop /= Par_Unit then
1387 Set_Is_Immediately_Visible (Scop);
1390 E := First_Entity (Current_Scope);
1392 while Present (E) loop
1393 Set_Is_Immediately_Visible (E);
1397 -- A subunit appears within a body, and for a nested subunits
1398 -- all the parents are bodies. Restore full visibility of their
1399 -- private entities.
1401 if Ekind (Scop) = E_Package then
1402 Set_In_Package_Body (Scop);
1403 Install_Private_Declarations (Scop);
1405 end Re_Install_Parents;
1407 ----------------------------
1408 -- Re_Install_Use_Clauses --
1409 ----------------------------
1411 procedure Re_Install_Use_Clauses is
1415 for J in reverse 1 .. Num_Scopes loop
1416 U := Use_Clauses (J);
1417 Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U;
1418 Install_Use_Clauses (U);
1420 end Re_Install_Use_Clauses;
1426 procedure Remove_Scope is
1430 Num_Scopes := Num_Scopes + 1;
1431 Use_Clauses (Num_Scopes) :=
1432 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause;
1433 E := First_Entity (Current_Scope);
1435 while Present (E) loop
1436 Set_Is_Immediately_Visible (E, False);
1440 if Is_Child_Unit (Current_Scope) then
1441 Enclosing_Child := Current_Scope;
1447 -- Start of processing for Analyze_Subunit
1450 if not Is_Empty_List (Context_Items (N)) then
1452 -- Save current use clauses.
1455 Remove_Context (Lib_Unit);
1457 -- Now remove parents and their context, including enclosing
1458 -- subunits and the outer parent body which is not a subunit.
1460 if Present (Lib_Spec) then
1461 Remove_Context (Lib_Spec);
1463 while Nkind (Unit (Lib_Spec)) = N_Subunit loop
1464 Lib_Spec := Library_Unit (Lib_Spec);
1466 Remove_Context (Lib_Spec);
1469 if Nkind (Unit (Lib_Unit)) = N_Subunit then
1473 if Nkind (Unit (Lib_Spec)) = N_Package_Body then
1474 Remove_Context (Library_Unit (Lib_Spec));
1478 Analyze_Subunit_Context;
1479 Re_Install_Parents (Lib_Unit, Par_Unit);
1481 -- If the context includes a child unit of the parent of the
1482 -- subunit, the parent will have been removed from visibility,
1483 -- after compiling that cousin in the context. The visibility
1484 -- of the parent must be restored now. This also applies if the
1485 -- context includes another subunit of the same parent which in
1486 -- turn includes a child unit in its context.
1488 if Ekind (Par_Unit) = E_Package then
1489 if not Is_Immediately_Visible (Par_Unit)
1490 or else (Present (First_Entity (Par_Unit))
1491 and then not Is_Immediately_Visible
1492 (First_Entity (Par_Unit)))
1494 Set_Is_Immediately_Visible (Par_Unit);
1495 Install_Visible_Declarations (Par_Unit);
1496 Install_Private_Declarations (Par_Unit);
1500 Re_Install_Use_Clauses;
1501 Install_Context (N);
1503 -- Restore state of suppress flags for current body.
1505 Scope_Suppress := Svg;
1507 -- If the subunit is within a child unit, then siblings of any
1508 -- parent unit that appear in the context clause of the subunit
1509 -- must also be made immediately visible.
1511 if Present (Enclosing_Child) then
1512 Install_Siblings (Enclosing_Child, N);
1517 Analyze (Proper_Body (Unit (N)));
1519 end Analyze_Subunit;
1521 ----------------------------
1522 -- Analyze_Task_Body_Stub --
1523 ----------------------------
1525 procedure Analyze_Task_Body_Stub (N : Node_Id) is
1526 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
1527 Loc : constant Source_Ptr := Sloc (N);
1530 Check_Stub_Level (N);
1532 -- First occurence of name may have been as an incomplete type.
1534 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1535 Nam := Full_View (Nam);
1539 or else not Is_Task_Type (Etype (Nam))
1541 Error_Msg_N ("missing specification for task body", N);
1543 Set_Scope (Defining_Entity (N), Current_Scope);
1544 Generate_Reference (Nam, Defining_Identifier (N), 'b');
1545 Set_Has_Completion (Etype (Nam));
1546 Analyze_Proper_Body (N, Etype (Nam));
1548 -- Set elaboration flag to indicate that entity is callable.
1549 -- This cannot be done in the expansion of the body itself,
1550 -- because the proper body is not in a declarative part. This
1551 -- is only done if expansion is active, because the context
1552 -- may be generic and the flag not defined yet.
1554 if Expander_Active then
1556 Make_Assignment_Statement (Loc,
1558 Make_Identifier (Loc,
1559 New_External_Name (Chars (Etype (Nam)), 'E')),
1560 Expression => New_Reference_To (Standard_True, Loc)));
1564 end Analyze_Task_Body_Stub;
1566 -------------------------
1567 -- Analyze_With_Clause --
1568 -------------------------
1570 -- Analyze the declaration of a unit in a with clause. At end,
1571 -- label the with clause with the defining entity for the unit.
1573 procedure Analyze_With_Clause (N : Node_Id) is
1575 -- Retrieve the original kind of the unit node, before analysis.
1576 -- If it is a subprogram instantiation, its analysis below will
1577 -- rewrite as the declaration of the wrapper package. If the same
1578 -- instantiation appears indirectly elsewhere in the context, it
1579 -- will have been analyzed already.
1581 Unit_Kind : constant Node_Kind :=
1582 Nkind (Original_Node (Unit (Library_Unit (N))));
1585 Par_Name : Entity_Id;
1590 -- Set True if the unit currently being compiled is an internal unit
1592 Save_Style_Check : constant Boolean := Opt.Style_Check;
1593 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
1594 Cunit_Boolean_Restrictions_Save;
1597 if Limited_Present (N) then
1598 -- Ada0Y (AI-50217): Build visibility structures but do not
1601 Build_Limited_Views (N);
1605 -- We reset ordinary style checking during the analysis of a with'ed
1606 -- unit, but we do NOT reset GNAT special analysis mode (the latter
1607 -- definitely *does* apply to with'ed units).
1609 if not GNAT_Mode then
1610 Style_Check := False;
1613 -- If the library unit is a predefined unit, and we are in high
1614 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
1615 -- for the analysis of the with'ed unit. This mode does not prevent
1616 -- explicit with'ing of run-time units.
1618 if Configurable_Run_Time_Mode
1620 Is_Predefined_File_Name
1621 (Unit_File_Name (Get_Source_Unit (Unit (Library_Unit (N)))))
1623 Configurable_Run_Time_Mode := False;
1624 Semantics (Library_Unit (N));
1625 Configurable_Run_Time_Mode := True;
1628 Semantics (Library_Unit (N));
1631 U := Unit (Library_Unit (N));
1632 Intunit := Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit));
1634 -- Following checks are skipped for dummy packages (those supplied
1635 -- for with's where no matching file could be found). Such packages
1636 -- are identified by the Sloc value being set to No_Location
1638 if Sloc (U) /= No_Location then
1640 -- Check restrictions, except that we skip the check if this
1641 -- is an internal unit unless we are compiling the internal
1642 -- unit as the main unit. We also skip this for dummy packages.
1644 if not Intunit or else Current_Sem_Unit = Main_Unit then
1645 Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N);
1648 -- Check for inappropriate with of internal implementation unit
1649 -- if we are currently compiling the main unit and the main unit
1650 -- is itself not an internal unit. We do not issue this message
1651 -- for implicit with's generated by the compiler itself.
1653 if Implementation_Unit_Warnings
1654 and then Current_Sem_Unit = Main_Unit
1655 and then Implementation_Unit (Get_Source_Unit (U))
1656 and then not Intunit
1657 and then not Implicit_With (N)
1659 Error_Msg_N ("& is an internal 'G'N'A'T unit?", Name (N));
1661 ("\use of this unit is non-portable and version-dependent?",
1666 -- Semantic analysis of a generic unit is performed on a copy of
1667 -- the original tree. Retrieve the entity on which semantic info
1668 -- actually appears.
1670 if Unit_Kind in N_Generic_Declaration then
1671 E_Name := Defining_Entity (U);
1673 -- Note: in the following test, Unit_Kind is the original Nkind, but
1674 -- in the case of an instantiation, semantic analysis above will
1675 -- have replaced the unit by its instantiated version. If the instance
1676 -- body has been generated, the instance now denotes the body entity.
1677 -- For visibility purposes we need the entity of its spec.
1679 elsif (Unit_Kind = N_Package_Instantiation
1680 or else Nkind (Original_Node (Unit (Library_Unit (N)))) =
1681 N_Package_Instantiation)
1682 and then Nkind (U) = N_Package_Body
1684 E_Name := Corresponding_Spec (U);
1686 elsif Unit_Kind = N_Package_Instantiation
1687 and then Nkind (U) = N_Package_Instantiation
1689 -- If the instance has not been rewritten as a package declaration,
1690 -- then it appeared already in a previous with clause. Retrieve
1691 -- the entity from the previous instance.
1693 E_Name := Defining_Entity (Specification (Instance_Spec (U)));
1695 elsif Unit_Kind = N_Procedure_Instantiation
1696 or else Unit_Kind = N_Function_Instantiation
1698 -- Instantiation node is replaced with a package that contains
1699 -- renaming declarations and instance itself. The subprogram
1700 -- Instance is declared in the visible part of the wrapper package.
1702 E_Name := First_Entity (Defining_Entity (U));
1704 while Present (E_Name) loop
1705 exit when Is_Subprogram (E_Name)
1706 and then Is_Generic_Instance (E_Name);
1707 E_Name := Next_Entity (E_Name);
1710 elsif Unit_Kind = N_Package_Renaming_Declaration
1711 or else Unit_Kind in N_Generic_Renaming_Declaration
1713 E_Name := Defining_Entity (U);
1715 elsif Unit_Kind = N_Subprogram_Body
1716 and then Nkind (Name (N)) = N_Selected_Component
1717 and then not Acts_As_Spec (Library_Unit (N))
1719 -- For a child unit that has no spec, one has been created and
1720 -- analyzed. The entity required is that of the spec.
1722 E_Name := Corresponding_Spec (U);
1725 E_Name := Defining_Entity (U);
1728 if Nkind (Name (N)) = N_Selected_Component then
1730 -- Child unit in a with clause
1732 Change_Selected_Component_To_Expanded_Name (Name (N));
1735 -- Restore style checks and restrictions
1737 Style_Check := Save_Style_Check;
1738 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
1740 -- Record the reference, but do NOT set the unit as referenced, we
1741 -- want to consider the unit as unreferenced if this is the only
1742 -- reference that occurs.
1744 Set_Entity_With_Style_Check (Name (N), E_Name);
1745 Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False);
1747 if Is_Child_Unit (E_Name) then
1748 Pref := Prefix (Name (N));
1749 Par_Name := Scope (E_Name);
1751 while Nkind (Pref) = N_Selected_Component loop
1752 Change_Selected_Component_To_Expanded_Name (Pref);
1753 Set_Entity_With_Style_Check (Pref, Par_Name);
1755 Generate_Reference (Par_Name, Pref);
1756 Pref := Prefix (Pref);
1758 -- If E_Name is the dummy entity for a nonexistent unit,
1759 -- its scope is set to Standard_Standard, and no attempt
1760 -- should be made to further unwind scopes.
1762 if Par_Name /= Standard_Standard then
1763 Par_Name := Scope (Par_Name);
1767 if Present (Entity (Pref))
1768 and then not Analyzed (Parent (Parent (Entity (Pref))))
1770 -- If the entity is set without its unit being compiled,
1771 -- the original parent is a renaming, and Par_Name is the
1772 -- renamed entity. For visibility purposes, we need the
1773 -- original entity, which must be analyzed now, because
1774 -- Load_Unit retrieves directly the renamed unit, and the
1775 -- renaming declaration itself has not been analyzed.
1777 Analyze (Parent (Parent (Entity (Pref))));
1778 pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name);
1779 Par_Name := Entity (Pref);
1782 Set_Entity_With_Style_Check (Pref, Par_Name);
1783 Generate_Reference (Par_Name, Pref);
1786 -- If the withed unit is System, and a system extension pragma is
1787 -- present, compile the extension now, rather than waiting for
1788 -- a visibility check on a specific entity.
1790 if Chars (E_Name) = Name_System
1791 and then Scope (E_Name) = Standard_Standard
1792 and then Present (System_Extend_Unit)
1793 and then Present_System_Aux (N)
1795 -- If the extension is not present, an error will have been emitted.
1799 end Analyze_With_Clause;
1801 ------------------------------
1802 -- Analyze_With_Type_Clause --
1803 ------------------------------
1805 procedure Analyze_With_Type_Clause (N : Node_Id) is
1806 Loc : constant Source_Ptr := Sloc (N);
1807 Nam : constant Node_Id := Name (N);
1811 Unum : Unit_Number_Type;
1814 procedure Decorate_Tagged_Type (T : Entity_Id);
1815 -- Set basic attributes of type, including its class_wide type.
1817 function In_Chain (E : Entity_Id) return Boolean;
1818 -- Check that the imported type is not already in the homonym chain,
1819 -- for example through a with_type clause in a parent unit.
1821 --------------------------
1822 -- Decorate_Tagged_Type --
1823 --------------------------
1825 procedure Decorate_Tagged_Type (T : Entity_Id) is
1829 Set_Ekind (T, E_Record_Type);
1830 Set_Is_Tagged_Type (T);
1832 Set_From_With_Type (T);
1835 if not In_Chain (T) then
1836 Set_Homonym (T, Current_Entity (T));
1837 Set_Current_Entity (T);
1840 -- Build bogus class_wide type, if not previously done.
1842 if No (Class_Wide_Type (T)) then
1843 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
1845 Set_Ekind (CW, E_Class_Wide_Type);
1848 Set_Is_Tagged_Type (CW);
1849 Set_Is_First_Subtype (CW, True);
1850 Init_Size_Align (CW);
1851 Set_Has_Unknown_Discriminants
1853 Set_Class_Wide_Type (CW, CW);
1854 Set_Equivalent_Type (CW, Empty);
1855 Set_From_With_Type (CW);
1857 Set_Class_Wide_Type (T, CW);
1859 end Decorate_Tagged_Type;
1865 function In_Chain (E : Entity_Id) return Boolean is
1866 H : Entity_Id := Current_Entity (E);
1869 while Present (H) loop
1881 -- Start of processing for Analyze_With_Type_Clause
1884 if Nkind (Nam) = N_Selected_Component then
1885 Pack := New_Copy_Tree (Prefix (Nam));
1886 Sel := Selector_Name (Nam);
1889 Error_Msg_N ("illegal name for imported type", Nam);
1894 Make_Package_Declaration (Loc,
1896 (Make_Package_Specification (Loc,
1897 Defining_Unit_Name => Pack,
1898 Visible_Declarations => New_List,
1899 End_Label => Empty)));
1903 (Load_Name => Get_Unit_Name (Decl),
1909 or else Nkind (Unit (Cunit (Unum))) /= N_Package_Declaration
1911 Error_Msg_N ("imported type must be declared in package", Nam);
1914 elsif Unum = Current_Sem_Unit then
1916 -- If type is defined in unit being analyzed, then the clause
1922 P := Cunit_Entity (Unum);
1925 -- Find declaration for imported type, and set its basic attributes
1926 -- if it has not been analyzed (which will be the case if there is
1927 -- circular dependence).
1934 if not Analyzed (Cunit (Unum))
1935 and then not From_With_Type (P)
1937 Set_Ekind (P, E_Package);
1938 Set_Etype (P, Standard_Void_Type);
1939 Set_From_With_Type (P);
1940 Set_Scope (P, Standard_Standard);
1941 Set_Homonym (P, Current_Entity (P));
1942 Set_Current_Entity (P);
1944 elsif Analyzed (Cunit (Unum))
1945 and then Is_Child_Unit (P)
1947 -- If the child unit is already in scope, indicate that it is
1948 -- visible, and remains so after intervening calls to rtsfind.
1950 Set_Is_Visible_Child_Unit (P);
1953 if Nkind (Parent (P)) = N_Defining_Program_Unit_Name then
1955 -- Make parent packages visible.
1958 Parent_Comp : Node_Id;
1959 Parent_Id : Entity_Id;
1964 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
1967 Parent_Id := Defining_Entity (Unit (Parent_Comp));
1968 Set_Scope (Child, Parent_Id);
1970 -- The type may be imported from a child unit, in which
1971 -- case the current compilation appears in the name. Do
1972 -- not change its visibility here because it will conflict
1973 -- with the subsequent normal processing.
1975 if not Analyzed (Unit_Declaration_Node (Parent_Id))
1976 and then Parent_Id /= Cunit_Entity (Current_Sem_Unit)
1978 Set_Ekind (Parent_Id, E_Package);
1979 Set_Etype (Parent_Id, Standard_Void_Type);
1981 -- The same package may appear is several with_type
1984 if not From_With_Type (Parent_Id) then
1985 Set_Homonym (Parent_Id, Current_Entity (Parent_Id));
1986 Set_Current_Entity (Parent_Id);
1987 Set_From_With_Type (Parent_Id);
1991 Set_Is_Immediately_Visible (Parent_Id);
1994 Parent_Comp := Parent_Spec (Unit (Parent_Comp));
1995 exit when No (Parent_Comp);
1998 Set_Scope (Parent_Id, Standard_Standard);
2002 -- Even if analyzed, the package may not be currently visible. It
2003 -- must be while the with_type clause is active.
2005 Set_Is_Immediately_Visible (P);
2008 First (Visible_Declarations (Specification (Unit (Cunit (Unum)))));
2010 while Present (Decl) loop
2012 if Nkind (Decl) = N_Full_Type_Declaration
2013 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2015 Typ := Defining_Identifier (Decl);
2017 if Tagged_Present (N) then
2019 -- The declaration must indicate that this is a tagged
2020 -- type or a type extension.
2022 if (Nkind (Type_Definition (Decl)) = N_Record_Definition
2023 and then Tagged_Present (Type_Definition (Decl)))
2025 (Nkind (Type_Definition (Decl))
2026 = N_Derived_Type_Definition
2028 (Record_Extension_Part (Type_Definition (Decl))))
2032 Error_Msg_N ("imported type is not a tagged type", Nam);
2036 if not Analyzed (Decl) then
2038 -- Unit is not currently visible. Add basic attributes
2039 -- to type and build its class-wide type.
2041 Init_Size_Align (Typ);
2042 Decorate_Tagged_Type (Typ);
2046 if Nkind (Type_Definition (Decl))
2047 /= N_Access_To_Object_Definition
2050 ("imported type is not an access type", Nam);
2052 elsif not Analyzed (Decl) then
2053 Set_Ekind (Typ, E_Access_Type);
2054 Set_Etype (Typ, Typ);
2056 Init_Size (Typ, System_Address_Size);
2057 Init_Alignment (Typ);
2058 Set_Directly_Designated_Type (Typ, Standard_Integer);
2059 Set_From_With_Type (Typ);
2061 if not In_Chain (Typ) then
2062 Set_Homonym (Typ, Current_Entity (Typ));
2063 Set_Current_Entity (Typ);
2068 Set_Entity (Sel, Typ);
2071 elsif ((Nkind (Decl) = N_Private_Type_Declaration
2072 and then Tagged_Present (Decl))
2073 or else (Nkind (Decl) = N_Private_Extension_Declaration))
2074 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2076 Typ := Defining_Identifier (Decl);
2078 if not Tagged_Present (N) then
2079 Error_Msg_N ("type must be declared tagged", N);
2081 elsif not Analyzed (Decl) then
2082 Decorate_Tagged_Type (Typ);
2085 Set_Entity (Sel, Typ);
2086 Set_From_With_Type (Typ);
2090 Decl := Next (Decl);
2093 Error_Msg_NE ("not a visible access or tagged type in&", Nam, P);
2095 end Analyze_With_Type_Clause;
2097 -----------------------------
2098 -- Check_With_Type_Clauses --
2099 -----------------------------
2101 procedure Check_With_Type_Clauses (N : Node_Id) is
2102 Lib_Unit : constant Node_Id := Unit (N);
2104 procedure Check_Parent_Context (U : Node_Id);
2105 -- Examine context items of parent unit to locate with_type clauses.
2107 --------------------------
2108 -- Check_Parent_Context --
2109 --------------------------
2111 procedure Check_Parent_Context (U : Node_Id) is
2115 Item := First (Context_Items (U));
2116 while Present (Item) loop
2117 if Nkind (Item) = N_With_Type_Clause
2118 and then not Error_Posted (Item)
2120 From_With_Type (Scope (Entity (Selector_Name (Name (Item)))))
2122 Error_Msg_Sloc := Sloc (Item);
2123 Error_Msg_N ("Missing With_Clause for With_Type_Clause#", N);
2128 end Check_Parent_Context;
2130 -- Start of processing for Check_With_Type_Clauses
2133 if Extensions_Allowed
2134 and then (Nkind (Lib_Unit) = N_Package_Body
2135 or else Nkind (Lib_Unit) = N_Subprogram_Body)
2137 Check_Parent_Context (Library_Unit (N));
2138 if Is_Child_Spec (Unit (Library_Unit (N))) then
2139 Check_Parent_Context (Parent_Spec (Unit (Library_Unit (N))));
2142 end Check_With_Type_Clauses;
2144 ------------------------------
2145 -- Check_Private_Child_Unit --
2146 ------------------------------
2148 procedure Check_Private_Child_Unit (N : Node_Id) is
2149 Lib_Unit : constant Node_Id := Unit (N);
2151 Curr_Unit : Entity_Id;
2152 Sub_Parent : Node_Id;
2153 Priv_Child : Entity_Id;
2154 Par_Lib : Entity_Id;
2157 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
2158 -- Returns true if and only if the library unit is declared with
2159 -- an explicit designation of private.
2161 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
2162 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
2165 return Private_Present (Comp_Unit);
2166 end Is_Private_Library_Unit;
2168 -- Start of processing for Check_Private_Child_Unit
2171 if Nkind (Lib_Unit) = N_Package_Body
2172 or else Nkind (Lib_Unit) = N_Subprogram_Body
2174 Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
2175 Par_Lib := Curr_Unit;
2177 elsif Nkind (Lib_Unit) = N_Subunit then
2179 -- The parent is itself a body. The parent entity is to be found
2180 -- in the corresponding spec.
2182 Sub_Parent := Library_Unit (N);
2183 Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
2185 -- If the parent itself is a subunit, Curr_Unit is the entity
2186 -- of the enclosing body, retrieve the spec entity which is
2187 -- the proper ancestor we need for the following tests.
2189 if Ekind (Curr_Unit) = E_Package_Body then
2190 Curr_Unit := Spec_Entity (Curr_Unit);
2193 Par_Lib := Curr_Unit;
2196 Curr_Unit := Defining_Entity (Lib_Unit);
2198 Par_Lib := Curr_Unit;
2199 Par_Spec := Parent_Spec (Lib_Unit);
2201 if No (Par_Spec) then
2204 Par_Lib := Defining_Entity (Unit (Par_Spec));
2208 -- Loop through context items
2210 Item := First (Context_Items (N));
2211 while Present (Item) loop
2213 if Nkind (Item) = N_With_Clause
2214 and then not Implicit_With (Item)
2215 and then Is_Private_Descendant (Entity (Name (Item)))
2217 Priv_Child := Entity (Name (Item));
2220 Curr_Parent : Entity_Id := Par_Lib;
2221 Child_Parent : Entity_Id := Scope (Priv_Child);
2222 Prv_Ancestor : Entity_Id := Child_Parent;
2223 Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
2226 -- If the child unit is a public child then locate
2227 -- the nearest private ancestor; Child_Parent will
2228 -- then be set to the parent of that ancestor.
2230 if not Is_Private_Library_Unit (Priv_Child) then
2231 while Present (Prv_Ancestor)
2232 and then not Is_Private_Library_Unit (Prv_Ancestor)
2234 Prv_Ancestor := Scope (Prv_Ancestor);
2237 if Present (Prv_Ancestor) then
2238 Child_Parent := Scope (Prv_Ancestor);
2242 while Present (Curr_Parent)
2243 and then Curr_Parent /= Standard_Standard
2244 and then Curr_Parent /= Child_Parent
2247 Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
2248 Curr_Parent := Scope (Curr_Parent);
2251 if not Present (Curr_Parent) then
2252 Curr_Parent := Standard_Standard;
2255 if Curr_Parent /= Child_Parent then
2257 if Ekind (Priv_Child) = E_Generic_Package
2258 and then Chars (Priv_Child) in Text_IO_Package_Name
2259 and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
2262 ("& is a nested package, not a compilation unit",
2263 Name (Item), Priv_Child);
2267 ("unit in with clause is private child unit!", Item);
2269 ("current unit must also have parent&!",
2270 Item, Child_Parent);
2273 elsif not Curr_Private
2274 and then Nkind (Lib_Unit) /= N_Package_Body
2275 and then Nkind (Lib_Unit) /= N_Subprogram_Body
2276 and then Nkind (Lib_Unit) /= N_Subunit
2279 ("current unit must also be private descendant of&",
2280 Item, Child_Parent);
2288 end Check_Private_Child_Unit;
2290 ----------------------
2291 -- Check_Stub_Level --
2292 ----------------------
2294 procedure Check_Stub_Level (N : Node_Id) is
2295 Par : constant Node_Id := Parent (N);
2296 Kind : constant Node_Kind := Nkind (Par);
2299 if (Kind = N_Package_Body
2300 or else Kind = N_Subprogram_Body
2301 or else Kind = N_Task_Body
2302 or else Kind = N_Protected_Body)
2304 and then (Nkind (Parent (Par)) = N_Compilation_Unit
2305 or else Nkind (Parent (Par)) = N_Subunit)
2309 -- In an instance, a missing stub appears at any level. A warning
2310 -- message will have been emitted already for the missing file.
2312 elsif not In_Instance then
2313 Error_Msg_N ("stub cannot appear in an inner scope", N);
2315 elsif Expander_Active then
2316 Error_Msg_N ("missing proper body", N);
2318 end Check_Stub_Level;
2320 ------------------------
2321 -- Expand_With_Clause --
2322 ------------------------
2324 procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id) is
2325 Loc : constant Source_Ptr := Sloc (Nam);
2326 Ent : constant Entity_Id := Entity (Nam);
2330 function Build_Unit_Name (Nam : Node_Id) return Node_Id;
2332 function Build_Unit_Name (Nam : Node_Id) return Node_Id is
2336 if Nkind (Nam) = N_Identifier then
2337 return New_Occurrence_Of (Entity (Nam), Loc);
2341 Make_Expanded_Name (Loc,
2342 Chars => Chars (Entity (Nam)),
2343 Prefix => Build_Unit_Name (Prefix (Nam)),
2344 Selector_Name => New_Occurrence_Of (Entity (Nam), Loc));
2345 Set_Entity (Result, Entity (Nam));
2348 end Build_Unit_Name;
2351 New_Nodes_OK := New_Nodes_OK + 1;
2353 Make_With_Clause (Loc, Name => Build_Unit_Name (Nam));
2355 P := Parent (Unit_Declaration_Node (Ent));
2356 Set_Library_Unit (Withn, P);
2357 Set_Corresponding_Spec (Withn, Ent);
2358 Set_First_Name (Withn, True);
2359 Set_Implicit_With (Withn, True);
2361 Prepend (Withn, Context_Items (N));
2362 Mark_Rewrite_Insertion (Withn);
2363 Install_Withed_Unit (Withn);
2365 if Nkind (Nam) = N_Expanded_Name then
2366 Expand_With_Clause (Prefix (Nam), N);
2369 New_Nodes_OK := New_Nodes_OK - 1;
2370 end Expand_With_Clause;
2372 --------------------------------
2373 -- Expand_Limited_With_Clause --
2374 --------------------------------
2376 procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id) is
2377 Loc : constant Source_Ptr := Sloc (Nam);
2378 Unum : Unit_Number_Type;
2382 New_Nodes_OK := New_Nodes_OK + 1;
2384 if Nkind (Nam) = N_Identifier then
2386 Make_With_Clause (Loc, Name => Nam);
2387 Set_Limited_Present (Withn);
2388 Set_First_Name (Withn);
2389 Set_Implicit_With (Withn);
2391 -- Load the corresponding parent unit
2395 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2400 if not Analyzed (Cunit (Unum)) then
2401 Set_Library_Unit (Withn, Cunit (Unum));
2402 Set_Corresponding_Spec
2403 (Withn, Specification (Unit (Cunit (Unum))));
2405 Prepend (Withn, Context_Items (Parent (N)));
2406 Mark_Rewrite_Insertion (Withn);
2409 elsif Nkind (Nam) = N_Selected_Component then
2414 Make_Selected_Component
2416 Prefix => Prefix (Nam),
2417 Selector_Name => Selector_Name (Nam)));
2419 Set_Parent (Withn, Parent (N));
2420 Set_Limited_Present (Withn);
2421 Set_First_Name (Withn);
2422 Set_Implicit_With (Withn);
2426 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2431 if not Analyzed (Cunit (Unum)) then
2432 Set_Library_Unit (Withn, Cunit (Unum));
2433 Set_Corresponding_Spec
2434 (Withn, Specification (Unit (Cunit (Unum))));
2435 Prepend (Withn, Context_Items (Parent (N)));
2436 Mark_Rewrite_Insertion (Withn);
2438 Expand_Limited_With_Clause (Prefix (Nam), N);
2443 pragma Assert (False);
2446 New_Nodes_OK := New_Nodes_OK - 1;
2447 end Expand_Limited_With_Clause;
2449 -----------------------
2450 -- Get_Parent_Entity --
2451 -----------------------
2453 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
2455 if Nkind (Unit) = N_Package_Instantiation then
2456 return Defining_Entity (Specification (Instance_Spec (Unit)));
2458 return Defining_Entity (Unit);
2460 end Get_Parent_Entity;
2462 -----------------------------
2463 -- Implicit_With_On_Parent --
2464 -----------------------------
2466 procedure Implicit_With_On_Parent
2467 (Child_Unit : Node_Id;
2470 Loc : constant Source_Ptr := Sloc (N);
2471 P : constant Node_Id := Parent_Spec (Child_Unit);
2472 P_Unit : constant Node_Id := Unit (P);
2473 P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
2476 function Build_Ancestor_Name (P : Node_Id) return Node_Id;
2477 -- Build prefix of child unit name. Recurse if needed.
2479 function Build_Unit_Name return Node_Id;
2480 -- If the unit is a child unit, build qualified name with all
2483 -------------------------
2484 -- Build_Ancestor_Name --
2485 -------------------------
2487 function Build_Ancestor_Name (P : Node_Id) return Node_Id is
2488 P_Ref : constant Node_Id :=
2489 New_Reference_To (Defining_Entity (P), Loc);
2492 if No (Parent_Spec (P)) then
2496 Make_Selected_Component (Loc,
2497 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P))),
2498 Selector_Name => P_Ref);
2500 end Build_Ancestor_Name;
2502 ---------------------
2503 -- Build_Unit_Name --
2504 ---------------------
2506 function Build_Unit_Name return Node_Id is
2510 if No (Parent_Spec (P_Unit)) then
2511 return New_Reference_To (P_Name, Loc);
2514 Make_Expanded_Name (Loc,
2515 Chars => Chars (P_Name),
2516 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
2517 Selector_Name => New_Reference_To (P_Name, Loc));
2518 Set_Entity (Result, P_Name);
2521 end Build_Unit_Name;
2523 -- Start of processing for Implicit_With_On_Parent
2526 New_Nodes_OK := New_Nodes_OK + 1;
2527 Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
2529 Set_Library_Unit (Withn, P);
2530 Set_Corresponding_Spec (Withn, P_Name);
2531 Set_First_Name (Withn, True);
2532 Set_Implicit_With (Withn, True);
2534 -- Node is placed at the beginning of the context items, so that
2535 -- subsequent use clauses on the parent can be validated.
2537 Prepend (Withn, Context_Items (N));
2538 Mark_Rewrite_Insertion (Withn);
2539 Install_Withed_Unit (Withn);
2541 if Is_Child_Spec (P_Unit) then
2542 Implicit_With_On_Parent (P_Unit, N);
2544 New_Nodes_OK := New_Nodes_OK - 1;
2545 end Implicit_With_On_Parent;
2547 ---------------------
2548 -- Install_Context --
2549 ---------------------
2551 procedure Install_Context (N : Node_Id) is
2552 Lib_Unit : constant Node_Id := Unit (N);
2555 Install_Context_Clauses (N);
2557 if Is_Child_Spec (Lib_Unit) then
2558 Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit)));
2561 Install_Limited_Context_Clauses (N);
2563 Check_With_Type_Clauses (N);
2564 end Install_Context;
2566 -----------------------------
2567 -- Install_Context_Clauses --
2568 -----------------------------
2570 procedure Install_Context_Clauses (N : Node_Id) is
2571 Lib_Unit : constant Node_Id := Unit (N);
2573 Uname_Node : Entity_Id;
2574 Check_Private : Boolean := False;
2575 Decl_Node : Node_Id;
2576 Lib_Parent : Entity_Id;
2579 -- Loop through context clauses to find the with/use clauses.
2580 -- This is done twice, first for everything except limited_with
2581 -- clauses, and then for those, if any are present.
2583 Item := First (Context_Items (N));
2584 while Present (Item) loop
2586 -- Case of explicit WITH clause
2588 if Nkind (Item) = N_With_Clause
2589 and then not Implicit_With (Item)
2591 if Limited_Present (Item) then
2593 -- Limited withed units will be installed later.
2597 -- If Name (Item) is not an entity name, something is wrong, and
2598 -- this will be detected in due course, for now ignore the item
2600 elsif not Is_Entity_Name (Name (Item)) then
2603 elsif No (Entity (Name (Item))) then
2604 Set_Entity (Name (Item), Any_Id);
2608 Uname_Node := Entity (Name (Item));
2610 if Is_Private_Descendant (Uname_Node) then
2611 Check_Private := True;
2614 Install_Withed_Unit (Item);
2616 Decl_Node := Unit_Declaration_Node (Uname_Node);
2618 -- If the unit is a subprogram instance, it appears nested
2619 -- within a package that carries the parent information.
2621 if Is_Generic_Instance (Uname_Node)
2622 and then Ekind (Uname_Node) /= E_Package
2624 Decl_Node := Parent (Parent (Decl_Node));
2627 if Is_Child_Spec (Decl_Node) then
2628 if Nkind (Name (Item)) = N_Expanded_Name then
2629 Expand_With_Clause (Prefix (Name (Item)), N);
2631 -- if not an expanded name, the child unit must be a
2632 -- renaming, nothing to do.
2637 elsif Nkind (Decl_Node) = N_Subprogram_Body
2638 and then not Acts_As_Spec (Parent (Decl_Node))
2639 and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
2641 Implicit_With_On_Parent
2642 (Unit (Library_Unit (Parent (Decl_Node))), N);
2645 -- Check license conditions unless this is a dummy unit
2647 if Sloc (Library_Unit (Item)) /= No_Location then
2648 License_Check : declare
2649 Withl : constant License_Type :=
2650 License (Source_Index
2652 (Library_Unit (Item))));
2654 Unitl : constant License_Type :=
2655 License (Source_Index (Current_Sem_Unit));
2657 procedure License_Error;
2658 -- Signal error of bad license
2664 procedure License_Error is
2667 ("?license of with'ed unit & is incompatible",
2671 -- Start of processing for License_Check
2684 if Withl = Restricted then
2688 when Modified_GPL =>
2689 if Withl = Restricted or else Withl = GPL then
2693 when Unrestricted =>
2699 -- Case of USE PACKAGE clause
2701 elsif Nkind (Item) = N_Use_Package_Clause then
2702 Analyze_Use_Package (Item);
2704 -- Case of USE TYPE clause
2706 elsif Nkind (Item) = N_Use_Type_Clause then
2707 Analyze_Use_Type (Item);
2709 -- Case of WITH TYPE clause
2711 -- A With_Type_Clause is processed when installing the context,
2712 -- because it is a visibility mechanism and does not create a
2713 -- semantic dependence on other units, as a With_Clause does.
2715 elsif Nkind (Item) = N_With_Type_Clause then
2716 Analyze_With_Type_Clause (Item);
2720 elsif Nkind (Item) = N_Pragma then
2728 if Is_Child_Spec (Lib_Unit) then
2730 -- The unit also has implicit withs on its own parents
2732 if No (Context_Items (N)) then
2733 Set_Context_Items (N, New_List);
2736 Implicit_With_On_Parent (Lib_Unit, N);
2739 -- If the unit is a body, the context of the specification must also
2742 if Nkind (Lib_Unit) = N_Package_Body
2743 or else (Nkind (Lib_Unit) = N_Subprogram_Body
2744 and then not Acts_As_Spec (N))
2746 Install_Context (Library_Unit (N));
2748 if Is_Child_Spec (Unit (Library_Unit (N))) then
2750 -- If the unit is the body of a public child unit, the private
2751 -- declarations of the parent must be made visible. If the child
2752 -- unit is private, the private declarations have been installed
2753 -- already in the call to Install_Parents for the spec. Installing
2754 -- private declarations must be done for all ancestors of public
2755 -- child units. In addition, sibling units mentioned in the
2756 -- context clause of the body are directly visible.
2759 Lib_Spec : Node_Id := Unit (Library_Unit (N));
2764 while Is_Child_Spec (Lib_Spec) loop
2765 P := Unit (Parent_Spec (Lib_Spec));
2767 if not (Private_Present (Parent (Lib_Spec))) then
2768 P_Name := Defining_Entity (P);
2769 Install_Private_Declarations (P_Name);
2770 Set_Use (Private_Declarations (Specification (P)));
2778 -- For a package body, children in context are immediately visible
2780 Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
2783 if Nkind (Lib_Unit) = N_Generic_Package_Declaration
2784 or else Nkind (Lib_Unit) = N_Generic_Subprogram_Declaration
2785 or else Nkind (Lib_Unit) = N_Package_Declaration
2786 or else Nkind (Lib_Unit) = N_Subprogram_Declaration
2788 if Is_Child_Spec (Lib_Unit) then
2789 Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
2790 Set_Is_Private_Descendant
2791 (Defining_Entity (Lib_Unit),
2792 Is_Private_Descendant (Lib_Parent)
2793 or else Private_Present (Parent (Lib_Unit)));
2796 Set_Is_Private_Descendant
2797 (Defining_Entity (Lib_Unit),
2798 Private_Present (Parent (Lib_Unit)));
2802 if Check_Private then
2803 Check_Private_Child_Unit (N);
2805 end Install_Context_Clauses;
2807 -------------------------------------
2808 -- Install_Limited_Context_Clauses --
2809 -------------------------------------
2811 procedure Install_Limited_Context_Clauses (N : Node_Id) is
2814 procedure Check_Parent (P : Node_Id; W : Node_Id);
2815 -- Check that the unlimited view of a given compilation_unit is not
2816 -- already visible in the parents (neither immediately through the
2817 -- context clauses, nor indirectly through "use + renamings").
2819 procedure Check_Private_Limited_Withed_Unit (N : Node_Id);
2820 -- Check that if a limited_with clause of a given compilation_unit
2821 -- mentions a private child of some library unit, then the given
2822 -- compilation_unit shall be the declaration of a private descendant
2823 -- of that library unit.
2825 procedure Check_Withed_Unit (W : Node_Id);
2826 -- Check that a limited with_clause does not appear in the same
2827 -- context_clause as a nonlimited with_clause that mentions
2828 -- the same library.
2830 --------------------
2832 --------------------
2834 procedure Check_Parent (P : Node_Id; W : Node_Id) is
2843 pragma Assert (Nkind (W) = N_With_Clause);
2845 -- Step 1: Check if the unlimited view is installed in the parent
2847 Item := First (Context_Items (P));
2848 while Present (Item) loop
2849 if Nkind (Item) = N_With_Clause
2850 and then not Limited_Present (Item)
2851 and then not Implicit_With (Item)
2852 and then Library_Unit (Item) = Library_Unit (W)
2854 Error_Msg_N ("unlimited view visible in ancestor", W);
2861 -- Step 2: Check "use + renamings"
2863 WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
2864 Spec := Specification (Unit (P));
2866 -- We tried to traverse the list of entities corresponding to the
2867 -- defining entity of the package spec. However, first_entity was
2868 -- found to be 'empty'. Don't know why???
2870 -- Def := Defining_Unit_Name (Spec);
2871 -- Ent := First_Entity (Def);
2873 -- As a workaround we traverse the list of visible declarations ???
2875 Item := First (Visible_Declarations (Spec));
2876 while Present (Item) loop
2878 if Nkind (Item) = N_Use_Package_Clause then
2880 -- Traverse the list of packages
2882 Nam := First (Names (Item));
2884 while Present (Nam) loop
2887 pragma Assert (Present (Parent (E)));
2889 if Nkind (Parent (E))
2890 = N_Package_Renaming_Declaration
2891 and then Renamed_Entity (E) = WEnt
2893 Error_Msg_N ("unlimited view visible through "
2894 & "use_clause + renamings", W);
2897 elsif Nkind (Parent (E)) = N_Package_Specification then
2899 -- The use clause may refer to a local package.
2900 -- Check all the enclosing scopes.
2903 while E2 /= Standard_Standard
2904 and then E2 /= WEnt loop
2909 Error_Msg_N ("unlimited view visible through "
2910 & "use_clause ", W);
2923 -- Recursive call to check all the ancestors
2925 if Is_Child_Spec (Unit (P)) then
2926 Check_Parent (P => Parent_Spec (Unit (P)), W => W);
2930 ---------------------------------------
2931 -- Check_Private_Limited_Withed_Unit --
2932 ---------------------------------------
2934 procedure Check_Private_Limited_Withed_Unit (N : Node_Id) is
2937 Found : Boolean := False;
2940 -- If the current compilation unit is not private we don't
2941 -- need to check anything else.
2943 if not Private_Present (Parent (N)) then
2947 -- Compilation unit of the parent of the withed library unit
2949 P := Parent_Spec (Unit (Library_Unit (N)));
2951 -- Traverse all the ancestors of the current compilation
2952 -- unit to check if it is a descendant of named library unit.
2955 while Present (Parent_Spec (Unit (C))) loop
2956 C := Parent_Spec (Unit (C));
2966 Error_Msg_N ("current unit is not a private descendant"
2967 & " of the withed unit ('R'M 10.1.2(8)", N);
2969 end Check_Private_Limited_Withed_Unit;
2971 -----------------------
2972 -- Check_Withed_Unit --
2973 -----------------------
2975 procedure Check_Withed_Unit (W : Node_Id) is
2979 -- A limited with_clause can not appear in the same context_clause
2980 -- as a nonlimited with_clause which mentions the same library.
2982 Item := First (Context_Items (N));
2983 while Present (Item) loop
2984 if Nkind (Item) = N_With_Clause
2985 and then not Limited_Present (Item)
2986 and then not Implicit_With (Item)
2987 and then Library_Unit (Item) = Library_Unit (W)
2989 Error_Msg_N ("limited and unlimited view "
2990 & "not allowed in the same context clauses", W);
2996 end Check_Withed_Unit;
2998 -- Start of processing for Install_Limited_Context_Clauses
3001 Item := First (Context_Items (N));
3002 while Present (Item) loop
3003 if Nkind (Item) = N_With_Clause
3004 and then Limited_Present (Item)
3007 Check_Withed_Unit (Item);
3009 if Private_Present (Library_Unit (Item)) then
3010 Check_Private_Limited_Withed_Unit (Item);
3013 if Is_Child_Spec (Unit (N)) then
3014 Check_Parent (Parent_Spec (Unit (N)), Item);
3017 Install_Limited_Withed_Unit (Item);
3022 end Install_Limited_Context_Clauses;
3024 ---------------------
3025 -- Install_Parents --
3026 ---------------------
3028 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is
3035 P := Unit (Parent_Spec (Lib_Unit));
3036 P_Name := Get_Parent_Entity (P);
3038 if Etype (P_Name) = Any_Type then
3042 if Ekind (P_Name) = E_Generic_Package
3043 and then Nkind (Lib_Unit) /= N_Generic_Subprogram_Declaration
3044 and then Nkind (Lib_Unit) /= N_Generic_Package_Declaration
3045 and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration
3048 ("child of a generic package must be a generic unit", Lib_Unit);
3050 elsif not Is_Package (P_Name) then
3052 ("parent unit must be package or generic package", Lib_Unit);
3053 raise Unrecoverable_Error;
3055 elsif Present (Renamed_Object (P_Name)) then
3056 Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
3057 raise Unrecoverable_Error;
3059 -- Verify that a child of an instance is itself an instance, or
3060 -- the renaming of one. Given that an instance that is a unit is
3061 -- replaced with a package declaration, check against the original
3064 elsif Nkind (Original_Node (P)) = N_Package_Instantiation
3065 and then Nkind (Lib_Unit)
3066 not in N_Renaming_Declaration
3067 and then Nkind (Original_Node (Lib_Unit))
3068 not in N_Generic_Instantiation
3071 ("child of an instance must be an instance or renaming", Lib_Unit);
3074 -- This is the recursive call that ensures all parents are loaded
3076 if Is_Child_Spec (P) then
3078 Is_Private or else Private_Present (Parent (Lib_Unit)));
3081 -- Now we can install the context for this parent
3083 Install_Context_Clauses (Parent_Spec (Lib_Unit));
3084 Install_Siblings (P_Name, Parent (Lib_Unit));
3086 -- The child unit is in the declarative region of the parent. The
3087 -- parent must therefore appear in the scope stack and be visible,
3088 -- as when compiling the corresponding body. If the child unit is
3089 -- private or it is a package body, private declarations must be
3090 -- accessible as well. Use declarations in the parent must also
3091 -- be installed. Finally, other child units of the same parent that
3092 -- are in the context are immediately visible.
3094 -- Find entity for compilation unit, and set its private descendant
3095 -- status as needed.
3097 E_Name := Defining_Entity (Lib_Unit);
3099 Set_Is_Child_Unit (E_Name);
3101 Set_Is_Private_Descendant (E_Name,
3102 Is_Private_Descendant (P_Name)
3103 or else Private_Present (Parent (Lib_Unit)));
3105 P_Spec := Specification (Unit_Declaration_Node (P_Name));
3108 -- Save current visibility of unit
3110 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
3111 Is_Immediately_Visible (P_Name);
3112 Set_Is_Immediately_Visible (P_Name);
3113 Install_Visible_Declarations (P_Name);
3114 Set_Use (Visible_Declarations (P_Spec));
3116 -- If the parent is a generic unit, its formal part may contain
3117 -- formal packages and use clauses for them.
3119 if Ekind (P_Name) = E_Generic_Package then
3120 Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
3124 or else Private_Present (Parent (Lib_Unit))
3126 Install_Private_Declarations (P_Name);
3127 Set_Use (Private_Declarations (P_Spec));
3129 end Install_Parents;
3131 ----------------------
3132 -- Install_Siblings --
3133 ----------------------
3135 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
3140 function Is_Ancestor (E : Entity_Id) return Boolean;
3141 -- Determine whether the scope of a child unit is an ancestor of
3142 -- the current unit.
3143 -- Shouldn't this be somewhere more general ???
3149 function Is_Ancestor (E : Entity_Id) return Boolean is
3156 and then Par /= Standard_Standard
3169 -- Start of processing for Install_Siblings
3172 -- Iterate over explicit with clauses, and check whether the
3173 -- scope of each entity is an ancestor of the current unit.
3175 Item := First (Context_Items (N));
3177 while Present (Item) loop
3179 if Nkind (Item) = N_With_Clause
3180 and then not Implicit_With (Item)
3181 and then not Limited_Present (Item)
3183 Id := Entity (Name (Item));
3185 if Is_Child_Unit (Id)
3186 and then Is_Ancestor (Scope (Id))
3188 Set_Is_Immediately_Visible (Id);
3189 Prev := Current_Entity (Id);
3191 -- Check for the presence of another unit in the context,
3192 -- that may be inadvertently hidden by the child.
3195 and then Is_Immediately_Visible (Prev)
3196 and then not Is_Child_Unit (Prev)
3202 Clause := First (Context_Items (N));
3204 while Present (Clause) loop
3205 if Nkind (Clause) = N_With_Clause
3206 and then Entity (Name (Clause)) = Prev
3209 ("child unit& hides compilation unit " &
3210 "with the same name?",
3220 -- the With_Clause may be on a grand-child, which makes
3221 -- the child immediately visible.
3223 elsif Is_Child_Unit (Scope (Id))
3224 and then Is_Ancestor (Scope (Scope (Id)))
3226 Set_Is_Immediately_Visible (Scope (Id));
3233 end Install_Siblings;
3235 -------------------------------
3236 -- Install_Limited_With_Unit --
3237 -------------------------------
3239 procedure Install_Limited_Withed_Unit (N : Node_Id) is
3240 Unum : constant Unit_Number_Type :=
3241 Get_Source_Unit (Library_Unit (N));
3242 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
3245 Lim_Typ : Entity_Id;
3246 Is_Child_Package : Boolean := False;
3248 function In_Chain (E : Entity_Id) return Boolean;
3249 -- Check that the shadow entity is not already in the homonym
3250 -- chain, for example through a limited_with clause in a parent unit.
3252 function In_Chain (E : Entity_Id) return Boolean is
3253 H : Entity_Id := Current_Entity (E);
3256 while Present (H) loop
3267 -- Start of processing for Install_Limited_Withed_Unit
3270 -- In case of limited with_clause on subprograms, generics, instances,
3271 -- or generic renamings, the corresponding error was previously posted
3272 -- and we have nothing to do here.
3274 case Nkind (P_Unit) is
3276 when N_Package_Declaration =>
3279 when N_Subprogram_Declaration |
3280 N_Generic_Package_Declaration |
3281 N_Generic_Subprogram_Declaration |
3282 N_Package_Instantiation |
3283 N_Function_Instantiation |
3284 N_Procedure_Instantiation |
3285 N_Generic_Package_Renaming_Declaration |
3286 N_Generic_Procedure_Renaming_Declaration |
3287 N_Generic_Function_Renaming_Declaration =>
3291 pragma Assert (False);
3295 P := Defining_Unit_Name (Specification (P_Unit));
3297 if Nkind (P) = N_Defining_Program_Unit_Name then
3299 -- Retrieve entity of child package
3301 Is_Child_Package := True;
3302 P := Defining_Identifier (P);
3305 -- A common usage of the limited-with is to have a limited-with
3306 -- in the package spec, and a normal with in its package body.
3309 -- limited with X; -- [1]
3313 -- package body A is ...
3315 -- The compilation of A's body installs the entities of its
3316 -- withed packages (the context clauses found at [2]) and
3317 -- then the context clauses of its specification (found at [1]).
3319 -- As a consequence, at point [1] the specification of X has been
3320 -- analyzed and it is immediately visible. According to the semantics
3321 -- of the limited-with context clauses we don't install the limited
3322 -- view because the full view of X supersedes its limited view.
3324 if Analyzed (Cunit (Unum))
3325 and then Is_Immediately_Visible (P)
3330 if Debug_Flag_I then
3331 Write_Str ("install limited view of ");
3332 Write_Name (Chars (P));
3336 if not Analyzed (Cunit (Unum)) then
3337 Set_Ekind (P, E_Package);
3338 Set_Etype (P, Standard_Void_Type);
3339 Set_Scope (P, Standard_Standard);
3341 -- Place entity on visibility structure
3343 if Current_Entity (P) /= P then
3344 Set_Homonym (P, Current_Entity (P));
3345 Set_Current_Entity (P);
3347 if Debug_Flag_I then
3348 Write_Str (" (homonym) chain ");
3349 Write_Name (Chars (P));
3355 if Is_Child_Package then
3356 Set_Is_Child_Unit (P);
3357 Set_Is_Visible_Child_Unit (P);
3360 Parent_Comp : Node_Id;
3361 Parent_Id : Entity_Id;
3364 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
3365 Parent_Id := Defining_Entity (Unit (Parent_Comp));
3367 Set_Scope (P, Parent_Id);
3373 -- If the unit appears in a previous regular with_clause, the
3374 -- regular entities must be unchained before the shadow ones
3375 -- are made accessible.
3380 Ent := First_Entity (P);
3382 while Present (Ent) loop
3390 -- The package must be visible while the with_type clause is active,
3391 -- because references to the type P.T must resolve in the usual way.
3393 Set_Is_Immediately_Visible (P);
3395 -- Install each incomplete view
3397 Lim_Elmt := First_Elmt (Limited_Views (P));
3399 while Present (Lim_Elmt) loop
3400 Lim_Typ := Node (Lim_Elmt);
3402 if not In_Chain (Lim_Typ) then
3403 Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
3404 Set_Current_Entity (Lim_Typ);
3406 if Debug_Flag_I then
3407 Write_Str (" (homonym) chain ");
3408 Write_Name (Chars (Lim_Typ));
3414 Next_Elmt (Lim_Elmt);
3417 -- The context clause has installed a limited-view, mark it
3418 -- accordingly, to uninstall it when the context is removed.
3420 Set_Limited_View_Installed (N);
3421 Set_From_With_Type (P);
3422 end Install_Limited_Withed_Unit;
3424 -------------------------
3425 -- Install_Withed_Unit --
3426 -------------------------
3428 procedure Install_Withed_Unit (With_Clause : Node_Id) is
3429 Uname : constant Entity_Id := Entity (Name (With_Clause));
3430 P : constant Entity_Id := Scope (Uname);
3434 if Debug_Flag_I then
3435 Write_Str ("install withed unit ");
3436 Write_Name (Chars (Uname));
3440 -- We do not apply the restrictions to an internal unit unless
3441 -- we are compiling the internal unit as a main unit. This check
3442 -- is also skipped for dummy units (for missing packages).
3444 if Sloc (Uname) /= No_Location
3445 and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
3446 or else Current_Sem_Unit = Main_Unit)
3448 Check_Restricted_Unit
3449 (Unit_Name (Get_Source_Unit (Uname)), With_Clause);
3452 if P /= Standard_Standard then
3454 -- If the unit is not analyzed after analysis of the with clause,
3455 -- and it is an instantiation, then it awaits a body and is the main
3456 -- unit. Its appearance in the context of some other unit indicates
3457 -- a circular dependency (DEC suite perversity).
3459 if not Analyzed (Uname)
3460 and then Nkind (Parent (Uname)) = N_Package_Instantiation
3463 ("instantiation depends on itself", Name (With_Clause));
3465 elsif not Is_Visible_Child_Unit (Uname) then
3466 Set_Is_Visible_Child_Unit (Uname);
3468 if Is_Generic_Instance (Uname)
3469 and then Ekind (Uname) in Subprogram_Kind
3471 -- Set flag as well on the visible entity that denotes the
3472 -- instance, which renames the current one.
3474 Set_Is_Visible_Child_Unit
3476 (Defining_Entity (Unit (Library_Unit (With_Clause)))));
3480 -- The parent unit may have been installed already, and
3481 -- may have appeared in a use clause.
3483 if In_Use (Scope (Uname)) then
3484 Set_Is_Potentially_Use_Visible (Uname);
3487 Set_Context_Installed (With_Clause);
3490 elsif not Is_Immediately_Visible (Uname) then
3491 Set_Is_Immediately_Visible (Uname);
3492 Set_Context_Installed (With_Clause);
3495 -- A with-clause overrides a with-type clause: there are no restric-
3496 -- tions on the use of package entities.
3498 if Ekind (Uname) = E_Package then
3499 Set_From_With_Type (Uname, False);
3501 end Install_Withed_Unit;
3507 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
3508 K : constant Node_Kind := Nkind (Lib_Unit);
3511 return (K in N_Generic_Declaration or else
3512 K in N_Generic_Instantiation or else
3513 K in N_Generic_Renaming_Declaration or else
3514 K = N_Package_Declaration or else
3515 K = N_Package_Renaming_Declaration or else
3516 K = N_Subprogram_Declaration or else
3517 K = N_Subprogram_Renaming_Declaration)
3518 and then Present (Parent_Spec (Lib_Unit));
3521 -----------------------
3522 -- Load_Needed_Body --
3523 -----------------------
3525 -- N is a generic unit named in a with clause, or else it is
3526 -- a unit that contains a generic unit or an inlined function.
3527 -- In order to perform an instantiation, the body of the unit
3528 -- must be present. If the unit itself is generic, we assume
3529 -- that an instantiation follows, and load and analyze the body
3530 -- unconditionally. This forces analysis of the spec as well.
3532 -- If the unit is not generic, but contains a generic unit, it
3533 -- is loaded on demand, at the point of instantiation (see ch12).
3535 procedure Load_Needed_Body (N : Node_Id; OK : out Boolean) is
3536 Body_Name : Unit_Name_Type;
3537 Unum : Unit_Number_Type;
3539 Save_Style_Check : constant Boolean := Opt.Style_Check;
3540 -- The loading and analysis is done with style checks off
3543 if not GNAT_Mode then
3544 Style_Check := False;
3547 Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
3550 (Load_Name => Body_Name,
3556 if Unum = No_Unit then
3560 Compiler_State := Analyzing; -- reset after load
3562 if not Fatal_Error (Unum) or else Try_Semantics then
3563 if Debug_Flag_L then
3564 Write_Str ("*** Loaded generic body");
3568 Semantics (Cunit (Unum));
3574 Style_Check := Save_Style_Check;
3575 end Load_Needed_Body;
3577 -------------------------
3578 -- Build_Limited_Views --
3579 -------------------------
3581 procedure Build_Limited_Views (N : Node_Id) is
3582 Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N));
3583 P : constant Entity_Id := Cunit_Entity (Unum);
3585 Spec : Node_Id; -- To denote a package specification
3586 Lim_Typ : Entity_Id; -- To denote shadow entities.
3587 Comp_Typ : Entity_Id; -- To denote real entities.
3589 procedure Decorate_Incomplete_Type
3592 -- Add attributes of an incomplete type to a shadow entity. The same
3593 -- attributes are placed on the real entity, so that gigi receives
3594 -- a consistent view.
3596 procedure Decorate_Package_Specification (P : Entity_Id);
3597 -- Add attributes of a package entity to the entity in a package
3600 procedure Decorate_Tagged_Type
3604 -- Set basic attributes of tagged type T, including its class_wide type.
3605 -- The parameters Loc, Scope are used to decorate the class_wide type.
3607 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id);
3608 -- Construct list of shadow entities and attach it to entity of
3609 -- package that is mentioned in a limited_with clause.
3611 function New_Internal_Shadow_Entity
3612 (Kind : Entity_Kind;
3613 Sloc_Value : Source_Ptr;
3614 Id_Char : Character) return Entity_Id;
3615 -- This function is similar to New_Internal_Entity, except that the
3616 -- entity is not added to the scope's list of entities.
3618 ------------------------------
3619 -- Decorate_Incomplete_Type --
3620 ------------------------------
3622 procedure Decorate_Incomplete_Type
3627 Set_Ekind (E, E_Incomplete_Type);
3628 Set_Scope (E, Scop);
3630 Set_Is_First_Subtype (E, True);
3631 Set_Stored_Constraint (E, No_Elist);
3632 Set_Full_View (E, Empty);
3633 Init_Size_Align (E);
3634 end Decorate_Incomplete_Type;
3636 --------------------------
3637 -- Decorate_Tagged_Type --
3638 --------------------------
3640 procedure Decorate_Tagged_Type
3648 Decorate_Incomplete_Type (T, Scop);
3649 Set_Is_Tagged_Type (T);
3651 -- Build corresponding class_wide type, if not previously done
3653 if No (Class_Wide_Type (T)) then
3654 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3656 Set_Ekind (CW, E_Class_Wide_Type);
3658 Set_Scope (CW, Scop);
3659 Set_Is_Tagged_Type (CW);
3660 Set_Is_First_Subtype (CW, True);
3661 Init_Size_Align (CW);
3662 Set_Has_Unknown_Discriminants (CW, True);
3663 Set_Class_Wide_Type (CW, CW);
3664 Set_Equivalent_Type (CW, Empty);
3665 Set_From_With_Type (CW, From_With_Type (T));
3667 Set_Class_Wide_Type (T, CW);
3669 end Decorate_Tagged_Type;
3671 ------------------------------------
3672 -- Decorate_Package_Specification --
3673 ------------------------------------
3675 procedure Decorate_Package_Specification (P : Entity_Id) is
3677 -- Place only the most basic attributes
3679 Set_Ekind (P, E_Package);
3680 Set_Etype (P, Standard_Void_Type);
3681 end Decorate_Package_Specification;
3683 -------------------------
3684 -- New_Internal_Entity --
3685 -------------------------
3687 function New_Internal_Shadow_Entity
3688 (Kind : Entity_Kind;
3689 Sloc_Value : Source_Ptr;
3690 Id_Char : Character) return Entity_Id
3692 N : constant Entity_Id :=
3693 Make_Defining_Identifier (Sloc_Value,
3694 Chars => New_Internal_Name (Id_Char));
3697 Set_Ekind (N, Kind);
3698 Set_Is_Internal (N, True);
3700 if Kind in Type_Kind then
3701 Init_Size_Align (N);
3705 end New_Internal_Shadow_Entity;
3711 -- Could use more comments below ???
3713 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id) is
3714 Analyzed_Unit : constant Boolean := Analyzed (Cunit (Unum));
3715 Is_Tagged : Boolean;
3719 Decl := First (Visible_Declarations (Spec));
3721 while Present (Decl) loop
3722 if Nkind (Decl) = N_Full_Type_Declaration then
3724 Nkind (Type_Definition (Decl)) = N_Record_Definition
3725 and then Tagged_Present (Type_Definition (Decl));
3727 Comp_Typ := Defining_Identifier (Decl);
3729 if not Analyzed_Unit then
3731 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3733 Decorate_Incomplete_Type (Comp_Typ, Scope);
3737 -- Create shadow entity for type
3739 Lim_Typ := New_Internal_Shadow_Entity
3740 (Kind => Ekind (Comp_Typ),
3741 Sloc_Value => Sloc (Comp_Typ),
3744 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3745 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3746 Set_From_With_Type (Lim_Typ);
3749 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3751 Decorate_Incomplete_Type (Lim_Typ, Scope);
3754 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3755 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3757 elsif Nkind (Decl) = N_Private_Type_Declaration
3758 and then Tagged_Present (Decl)
3760 Comp_Typ := Defining_Identifier (Decl);
3762 if not Analyzed_Unit then
3763 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3766 Lim_Typ := New_Internal_Shadow_Entity
3767 (Kind => Ekind (Comp_Typ),
3768 Sloc_Value => Sloc (Comp_Typ),
3771 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3772 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3773 Set_From_With_Type (Lim_Typ);
3775 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3777 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3778 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3780 elsif Nkind (Decl) = N_Package_Declaration then
3785 Spec : constant Node_Id := Specification (Decl);
3788 Comp_Typ := Defining_Unit_Name (Spec);
3790 if not Analyzed (Cunit (Unum)) then
3791 Decorate_Package_Specification (Comp_Typ);
3792 Set_Scope (Comp_Typ, Scope);
3795 Lim_Typ := New_Internal_Shadow_Entity
3796 (Kind => Ekind (Comp_Typ),
3797 Sloc_Value => Sloc (Comp_Typ),
3800 Decorate_Package_Specification (Lim_Typ);
3801 Set_Scope (Lim_Typ, Scope);
3803 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3804 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3805 Set_From_With_Type (Lim_Typ);
3807 -- Note: The non_limited_view attribute is not used
3808 -- for local packages.
3810 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3812 Build_Chain (Spec, Scope => Lim_Typ);
3820 -- Start of processing for Build_Limited_Views
3823 pragma Assert (Limited_Present (N));
3825 -- A library_item mentioned in a limited_with_clause shall be
3826 -- a package_declaration, not a subprogram_declaration,
3827 -- generic_declaration, generic_instantiation, or
3828 -- package_renaming_declaration
3830 case Nkind (Unit (Library_Unit (N))) is
3832 when N_Package_Declaration =>
3835 when N_Subprogram_Declaration =>
3836 Error_Msg_N ("subprograms not allowed in "
3837 & "limited with_clauses", N);
3840 when N_Generic_Package_Declaration |
3841 N_Generic_Subprogram_Declaration =>
3842 Error_Msg_N ("generics not allowed in "
3843 & "limited with_clauses", N);
3846 when N_Package_Instantiation |
3847 N_Function_Instantiation |
3848 N_Procedure_Instantiation =>
3849 Error_Msg_N ("generic instantiations not allowed in "
3850 & "limited with_clauses", N);
3853 when N_Generic_Package_Renaming_Declaration |
3854 N_Generic_Procedure_Renaming_Declaration |
3855 N_Generic_Function_Renaming_Declaration =>
3856 Error_Msg_N ("generic renamings not allowed in "
3857 & "limited with_clauses", N);
3861 pragma Assert (False);
3865 -- Check if the chain is already built
3867 Spec := Specification (Unit (Library_Unit (N)));
3869 if Limited_View_Installed (Spec) then
3873 Set_Ekind (P, E_Package);
3874 Set_Limited_Views (P, New_Elmt_List);
3875 -- Set_Entity (Name (N), P);
3877 -- Create the auxiliary chain
3879 Build_Chain (Spec, Scope => P);
3880 Set_Limited_View_Installed (Spec);
3881 end Build_Limited_Views;
3883 -------------------------------
3884 -- Check_Body_Needed_For_SAL --
3885 -------------------------------
3887 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
3889 function Entity_Needs_Body (E : Entity_Id) return Boolean;
3890 -- Determine whether use of entity E might require the presence
3891 -- of its body. For a package this requires a recursive traversal
3892 -- of all nested declarations.
3894 ---------------------------
3895 -- Entity_Needed_For_SAL --
3896 ---------------------------
3898 function Entity_Needs_Body (E : Entity_Id) return Boolean is
3902 if Is_Subprogram (E)
3903 and then Has_Pragma_Inline (E)
3907 elsif Ekind (E) = E_Generic_Function
3908 or else Ekind (E) = E_Generic_Procedure
3912 elsif Ekind (E) = E_Generic_Package
3914 Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
3915 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3919 elsif Ekind (E) = E_Package
3921 Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
3922 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3924 Ent := First_Entity (E);
3926 while Present (Ent) loop
3927 if Entity_Needs_Body (Ent) then
3939 end Entity_Needs_Body;
3941 -- Start of processing for Check_Body_Needed_For_SAL
3944 if Ekind (Unit_Name) = E_Generic_Package
3946 Nkind (Unit_Declaration_Node (Unit_Name)) =
3947 N_Generic_Package_Declaration
3949 Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
3951 Set_Body_Needed_For_SAL (Unit_Name);
3953 elsif Ekind (Unit_Name) = E_Generic_Procedure
3954 or else Ekind (Unit_Name) = E_Generic_Function
3956 Set_Body_Needed_For_SAL (Unit_Name);
3958 elsif Is_Subprogram (Unit_Name)
3959 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
3960 N_Subprogram_Declaration
3961 and then Has_Pragma_Inline (Unit_Name)
3963 Set_Body_Needed_For_SAL (Unit_Name);
3965 elsif Ekind (Unit_Name) = E_Subprogram_Body then
3966 Check_Body_Needed_For_SAL
3967 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
3969 elsif Ekind (Unit_Name) = E_Package
3970 and then Entity_Needs_Body (Unit_Name)
3972 Set_Body_Needed_For_SAL (Unit_Name);
3974 elsif Ekind (Unit_Name) = E_Package_Body
3975 and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
3977 Check_Body_Needed_For_SAL
3978 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
3980 end Check_Body_Needed_For_SAL;
3982 --------------------
3983 -- Remove_Context --
3984 --------------------
3986 procedure Remove_Context (N : Node_Id) is
3987 Lib_Unit : constant Node_Id := Unit (N);
3990 -- If this is a child unit, first remove the parent units.
3992 if Is_Child_Spec (Lib_Unit) then
3993 Remove_Parents (Lib_Unit);
3996 Remove_Context_Clauses (N);
3999 ----------------------------
4000 -- Remove_Context_Clauses --
4001 ----------------------------
4003 procedure Remove_Context_Clauses (N : Node_Id) is
4005 Unit_Name : Entity_Id;
4008 -- Ada0Y (AI-50217): We remove the context clauses in two phases:
4009 -- limited-views first and regular-views later (to maintain the
4012 -- First Phase: Remove limited_with context clauses
4014 Item := First (Context_Items (N));
4015 while Present (Item) loop
4017 -- We are interested only in with clauses which got installed
4020 if Nkind (Item) = N_With_Clause
4021 and then Limited_Present (Item)
4022 and then Limited_View_Installed (Item)
4024 Remove_Limited_With_Clause (Item);
4031 -- Second Phase: Loop through context items and undo regular
4032 -- with_clauses and use_clauses.
4034 Item := First (Context_Items (N));
4035 while Present (Item) loop
4037 -- We are interested only in with clauses which got installed
4038 -- on entry, as indicated by their Context_Installed flag set
4040 if Nkind (Item) = N_With_Clause
4041 and then Limited_Present (Item)
4042 and then Limited_View_Installed (Item)
4046 elsif Nkind (Item) = N_With_Clause
4047 and then Context_Installed (Item)
4049 -- Remove items from one with'ed unit
4051 Unit_Name := Entity (Name (Item));
4052 Remove_Unit_From_Visibility (Unit_Name);
4053 Set_Context_Installed (Item, False);
4055 elsif Nkind (Item) = N_Use_Package_Clause then
4056 End_Use_Package (Item);
4058 elsif Nkind (Item) = N_Use_Type_Clause then
4059 End_Use_Type (Item);
4061 elsif Nkind (Item) = N_With_Type_Clause then
4062 Remove_With_Type_Clause (Name (Item));
4067 end Remove_Context_Clauses;
4069 --------------------------------
4070 -- Remove_Limited_With_Clause --
4071 --------------------------------
4073 procedure Remove_Limited_With_Clause (N : Node_Id) is
4074 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
4075 P : Entity_Id := Defining_Unit_Name (Specification (P_Unit));
4077 Lim_Typ : Entity_Id;
4080 if Nkind (P) = N_Defining_Program_Unit_Name then
4082 -- Retrieve entity of Child package
4084 P := Defining_Identifier (P);
4087 if Debug_Flag_I then
4088 Write_Str ("remove limited view of ");
4089 Write_Name (Chars (P));
4090 Write_Str (" from visibility");
4094 -- Remove all shadow entities from visibility
4096 Lim_Elmt := First_Elmt (Limited_Views (P));
4098 while Present (Lim_Elmt) loop
4099 Lim_Typ := Node (Lim_Elmt);
4102 Next_Elmt (Lim_Elmt);
4105 -- Indicate that the limited view of the package is not installed
4107 Set_From_With_Type (P, False);
4108 Set_Limited_View_Installed (N, False);
4110 -- If the exporting package has previously been analyzed, it
4111 -- has appeared in the closure already and should be left alone.
4112 -- Otherwise, remove package itself from visibility.
4114 if not Analyzed (P_Unit) then
4116 Set_First_Entity (P, Empty);
4117 Set_Last_Entity (P, Empty);
4118 Set_Ekind (P, E_Void);
4119 Set_Scope (P, Empty);
4120 Set_Is_Immediately_Visible (P, False);
4124 -- Reinstall visible entities (entities removed from visibility in
4125 -- Install_Limited_Withed to install the shadow entities).
4131 Ent := First_Entity (P);
4132 while Present (Ent) and then Ent /= First_Private_Entity (P) loop
4134 -- Shadow entities have not been added to the list of
4135 -- entities associated to the package spec. Therefore we
4136 -- just have to re-chain all its visible entities.
4138 if not Is_Class_Wide_Type (Ent) then
4140 Set_Homonym (Ent, Current_Entity (Ent));
4141 Set_Current_Entity (Ent);
4143 if Debug_Flag_I then
4144 Write_Str (" (homonym) chain ");
4145 Write_Name (Chars (Ent));
4155 end Remove_Limited_With_Clause;
4157 --------------------
4158 -- Remove_Parents --
4159 --------------------
4161 procedure Remove_Parents (Lib_Unit : Node_Id) is
4165 Vis : constant Boolean :=
4166 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
4169 if Is_Child_Spec (Lib_Unit) then
4170 P := Unit (Parent_Spec (Lib_Unit));
4171 P_Name := Get_Parent_Entity (P);
4173 Remove_Context_Clauses (Parent_Spec (Lib_Unit));
4174 End_Package_Scope (P_Name);
4175 Set_Is_Immediately_Visible (P_Name, Vis);
4177 -- Remove from visibility the siblings as well, which are directly
4178 -- visible while the parent is in scope.
4180 E := First_Entity (P_Name);
4182 while Present (E) loop
4184 if Is_Child_Unit (E) then
4185 Set_Is_Immediately_Visible (E, False);
4191 Set_In_Package_Body (P_Name, False);
4193 -- This is the recursive call to remove the context of any
4194 -- higher level parent. This recursion ensures that all parents
4195 -- are removed in the reverse order of their installation.
4201 -----------------------------
4202 -- Remove_With_Type_Clause --
4203 -----------------------------
4205 procedure Remove_With_Type_Clause (Name : Node_Id) is
4209 procedure Unchain (E : Entity_Id);
4210 -- Remove entity from visibility list.
4212 procedure Unchain (E : Entity_Id) is
4216 Prev := Current_Entity (E);
4218 -- Package entity may appear is several with_type_clauses, and
4219 -- may have been removed already.
4225 Set_Name_Entity_Id (Chars (E), Homonym (E));
4228 while Present (Prev)
4229 and then Homonym (Prev) /= E
4231 Prev := Homonym (Prev);
4234 if Present (Prev) then
4235 Set_Homonym (Prev, Homonym (E));
4240 -- Start of Remove_With_Type_Clause
4243 if Nkind (Name) = N_Selected_Component then
4244 Typ := Entity (Selector_Name (Name));
4246 if No (Typ) then -- error in declaration.
4255 -- If the exporting package has been analyzed, it has appeared in the
4256 -- context already and should be left alone. Otherwise, remove from
4259 if not Analyzed (Unit_Declaration_Node (P)) then
4262 Set_Is_Frozen (Typ, False);
4265 if Ekind (Typ) = E_Record_Type then
4266 Set_From_With_Type (Class_Wide_Type (Typ), False);
4267 Set_From_With_Type (Typ, False);
4270 Set_From_With_Type (P, False);
4272 -- If P is a child unit, remove parents as well.
4277 and then P /= Standard_Standard
4279 Set_From_With_Type (P, False);
4281 if not Analyzed (Unit_Declaration_Node (P)) then
4288 -- The back-end needs to know that an access type is imported, so it
4289 -- does not need elaboration and can appear in a mutually recursive
4290 -- record definition, so the imported flag on an access type is
4293 end Remove_With_Type_Clause;
4295 ---------------------------------
4296 -- Remove_Unit_From_Visibility --
4297 ---------------------------------
4299 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
4300 P : constant Entity_Id := Scope (Unit_Name);
4304 if Debug_Flag_I then
4305 Write_Str ("remove unit ");
4306 Write_Name (Chars (Unit_Name));
4307 Write_Str (" from visibility");
4311 if P /= Standard_Standard then
4312 Set_Is_Visible_Child_Unit (Unit_Name, False);
4315 Set_Is_Potentially_Use_Visible (Unit_Name, False);
4316 Set_Is_Immediately_Visible (Unit_Name, False);
4318 end Remove_Unit_From_Visibility;
4324 procedure Unchain (E : Entity_Id) is
4328 Prev := Current_Entity (E);
4334 Set_Name_Entity_Id (Chars (E), Homonym (E));
4337 while Present (Prev)
4338 and then Homonym (Prev) /= E
4340 Prev := Homonym (Prev);
4343 if Present (Prev) then
4344 Set_Homonym (Prev, Homonym (E));
4348 if Debug_Flag_I then
4349 Write_Str (" (homonym) unchain ");
4350 Write_Name (Chars (E));