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
139 (With_Clause : Node_Id;
140 Private_With_OK : Boolean := False);
142 -- If the unit is not a child unit, make unit immediately visible.
143 -- The caller ensures that the unit is not already currently installed.
144 -- The flag Private_With_OK is set true in Install_Private_With_Clauses,
145 -- which is called when compiling the private part of a package, or
146 -- installing the private declarations of a parent unit.
148 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean);
149 -- This procedure establishes the context for the compilation of a child
150 -- unit. If Lib_Unit is a child library spec then the context of the parent
151 -- is installed, and the parent itself made immediately visible, so that
152 -- the child unit is processed in the declarative region of the parent.
153 -- Install_Parents makes a recursive call to itself to ensure that all
154 -- parents are loaded in the nested case. If Lib_Unit is a library body,
155 -- the only effect of Install_Parents is to install the private decls of
156 -- the parents, because the visible parent declarations will have been
157 -- installed as part of the context of the corresponding spec.
159 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
160 -- In the compilation of a child unit, a child of any of the ancestor
161 -- units is directly visible if it is visible, because the parent is in
162 -- an enclosing scope. Iterate over context to find child units of U_Name
163 -- or of some ancestor of it.
165 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean;
166 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
167 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
168 -- a library spec that has a parent. If the call to Is_Child_Spec returns
169 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
170 -- compilation unit for the parent spec.
172 -- Lib_Unit can also be a subprogram body that acts as its own spec. If
173 -- the Parent_Spec is non-empty, this is also a child unit.
175 procedure Remove_With_Type_Clause (Name : Node_Id);
176 -- Remove imported type and its enclosing package from visibility, and
177 -- remove attributes of imported type so they don't interfere with its
178 -- analysis (should it appear otherwise in the context).
180 procedure Remove_Context_Clauses (N : Node_Id);
181 -- Subsidiary of previous one. Remove use_ and with_clauses.
183 procedure Remove_Limited_With_Clause (N : Node_Id);
184 -- Remove from visibility the shadow entities introduced for a package
185 -- mentioned in a limited_with clause. Implements Ada0Y (AI-50217).
187 procedure Remove_Parents (Lib_Unit : Node_Id);
188 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
189 -- contexts established by the corresponding call to Install_Parents are
190 -- removed. Remove_Parents contains a recursive call to itself to ensure
191 -- that all parents are removed in the nested case.
193 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id);
194 -- Reset all visibility flags on unit after compiling it, either as a
195 -- main unit or as a unit in the context.
197 procedure Unchain (E : Entity_Id);
198 -- Remove single entity from visibility list
200 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id);
201 -- Common processing for all stubs (subprograms, tasks, packages, and
202 -- protected cases). N is the stub to be analyzed. Once the subunit
203 -- name is established, load and analyze. Nam is the non-overloadable
204 -- entity for which the proper body provides a completion. Subprogram
205 -- stubs are handled differently because they can be declarations.
207 --------------------------
208 -- Limited_With_Clauses --
209 --------------------------
211 -- Limited_With clauses are the mechanism chosen for Ada05 to support
212 -- mutually recursive types declared in different units. A limited_with
213 -- clause that names package P in the context of unit U makes the types
214 -- declared in the visible part of P available within U, but with the
215 -- restriction that these types can only be used as incomplete types.
216 -- The limited_with clause does not impose a semantic dependence on P,
217 -- and it is possible for two packages to have limited_with_clauses on
218 -- each other without creating an elaboration circularity.
220 -- To support this feature, the analysis of a limited_with clause must
221 -- create an abbreviated view of the package, without performing any
222 -- semantic analysis on it. This "package abstract" contains shadow
223 -- types that are in one-one correspondence with the real types in the
224 -- package, and that have the properties of incomplete types.
226 -- The implementation creates two element lists: one to chain the shadow
227 -- entities, and one to chain the corresponding type entities in the tree
228 -- of the package. Links between corresponding entities in both chains
229 -- allow the compiler to select the proper view of a given type, depending
230 -- on the context. Note that in contrast with the handling of private
231 -- types, the limited view and the non-limited view of a type are treated
232 -- as separate entities, and no entity exchange needs to take place, which
233 -- makes the implementation must simpler than could be feared.
235 ------------------------------
236 -- Analyze_Compilation_Unit --
237 ------------------------------
239 procedure Analyze_Compilation_Unit (N : Node_Id) is
240 Unit_Node : constant Node_Id := Unit (N);
241 Lib_Unit : Node_Id := Library_Unit (N);
243 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
244 Par_Spec_Name : Unit_Name_Type;
245 Unum : Unit_Number_Type;
247 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id);
248 -- Generate cross-reference information for the parents of child units.
249 -- N is a defining_program_unit_name, and P_Id is the immediate parent.
251 --------------------------------
252 -- Generate_Parent_References --
253 --------------------------------
255 procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is
257 P_Name : Entity_Id := P_Id;
260 Pref := Name (Parent (Defining_Entity (N)));
262 if Nkind (Pref) = N_Expanded_Name then
264 -- Done already, if the unit has been compiled indirectly as
265 -- part of the closure of its context because of inlining.
270 while Nkind (Pref) = N_Selected_Component loop
271 Change_Selected_Component_To_Expanded_Name (Pref);
272 Set_Entity (Pref, P_Name);
273 Set_Etype (Pref, Etype (P_Name));
274 Generate_Reference (P_Name, Pref, 'r');
275 Pref := Prefix (Pref);
276 P_Name := Scope (P_Name);
279 -- The guard here on P_Name is to handle the error condition where
280 -- the parent unit is missing because the file was not found.
282 if Present (P_Name) then
283 Set_Entity (Pref, P_Name);
284 Set_Etype (Pref, Etype (P_Name));
285 Generate_Reference (P_Name, Pref, 'r');
286 Style.Check_Identifier (Pref, P_Name);
288 end Generate_Parent_References;
290 -- Start of processing for Analyze_Compilation_Unit
293 Process_Compilation_Unit_Pragmas (N);
295 -- If the unit is a subunit whose parent has not been analyzed (which
296 -- indicates that the main unit is a subunit, either the current one or
297 -- one of its descendents) then the subunit is compiled as part of the
298 -- analysis of the parent, which we proceed to do. Basically this gets
299 -- handled from the top down and we don't want to do anything at this
300 -- level (i.e. this subunit will be handled on the way down from the
301 -- parent), so at this level we immediately return. If the subunit
302 -- ends up not analyzed, it means that the parent did not contain a
303 -- stub for it, or that there errors were dectected in some ancestor.
305 if Nkind (Unit_Node) = N_Subunit
306 and then not Analyzed (Lib_Unit)
308 Semantics (Lib_Unit);
310 if not Analyzed (Proper_Body (Unit_Node)) then
311 if Serious_Errors_Detected > 0 then
312 Error_Msg_N ("subunit not analyzed (errors in parent unit)", N);
314 Error_Msg_N ("missing stub for subunit", N);
321 -- Analyze context (this will call Sem recursively for with'ed units)
325 -- If the unit is a package body, the spec is already loaded and must
326 -- be analyzed first, before we analyze the body.
328 if Nkind (Unit_Node) = N_Package_Body then
330 -- If no Lib_Unit, then there was a serious previous error, so
331 -- just ignore the entire analysis effort
333 if No (Lib_Unit) then
337 Semantics (Lib_Unit);
338 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
340 -- Verify that the library unit is a package declaration.
342 if Nkind (Unit (Lib_Unit)) /= N_Package_Declaration
344 Nkind (Unit (Lib_Unit)) /= N_Generic_Package_Declaration
347 ("no legal package declaration for package body", N);
350 -- Otherwise, the entity in the declaration is visible. Update
351 -- the version to reflect dependence of this body on the spec.
354 Spec_Id := Defining_Entity (Unit (Lib_Unit));
355 Set_Is_Immediately_Visible (Spec_Id, True);
356 Version_Update (N, Lib_Unit);
358 if Nkind (Defining_Unit_Name (Unit_Node))
359 = N_Defining_Program_Unit_Name
361 Generate_Parent_References (Unit_Node, Scope (Spec_Id));
366 -- If the unit is a subprogram body, then we similarly need to analyze
367 -- its spec. However, things are a little simpler in this case, because
368 -- here, this analysis is done only for error checking and consistency
369 -- purposes, so there's nothing else to be done.
371 elsif Nkind (Unit_Node) = N_Subprogram_Body then
372 if Acts_As_Spec (N) then
374 -- If the subprogram body is a child unit, we must create a
375 -- declaration for it, in order to properly load the parent(s).
376 -- After this, the original unit does not acts as a spec, because
377 -- there is an explicit one. If this unit appears in a context
378 -- clause, then an implicit with on the parent will be added when
379 -- installing the context. If this is the main unit, there is no
380 -- Unit_Table entry for the declaration, (It has the unit number
381 -- of the main unit) and code generation is unaffected.
383 Unum := Get_Cunit_Unit_Number (N);
384 Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum));
386 if Par_Spec_Name /= No_Name then
389 (Load_Name => Par_Spec_Name,
394 if Unum /= No_Unit then
396 -- Build subprogram declaration and attach parent unit to it
397 -- This subprogram declaration does not come from source,
398 -- Nevertheless the backend must generate debugging info for
399 -- it, and this must be indicated explicitly.
402 Loc : constant Source_Ptr := Sloc (N);
403 SCS : constant Boolean :=
404 Get_Comes_From_Source_Default;
407 Set_Comes_From_Source_Default (False);
409 Make_Compilation_Unit (Loc,
410 Context_Items => New_Copy_List (Context_Items (N)),
412 Make_Subprogram_Declaration (Sloc (N),
415 (Specification (Unit_Node))),
417 Make_Compilation_Unit_Aux (Loc));
419 Set_Library_Unit (N, Lib_Unit);
420 Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
421 Semantics (Lib_Unit);
422 Set_Acts_As_Spec (N, False);
423 Set_Needs_Debug_Info (Defining_Entity (Unit (Lib_Unit)));
424 Set_Comes_From_Source_Default (SCS);
429 -- Here for subprogram with separate declaration
432 Semantics (Lib_Unit);
433 Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
434 Version_Update (N, Lib_Unit);
437 if Nkind (Defining_Unit_Name (Specification (Unit_Node))) =
438 N_Defining_Program_Unit_Name
440 Generate_Parent_References (
441 Specification (Unit_Node),
442 Scope (Defining_Entity (Unit (Lib_Unit))));
446 -- If it is a child unit, the parent must be elaborated first
447 -- and we update version, since we are dependent on our parent.
449 if Is_Child_Spec (Unit_Node) then
451 -- The analysis of the parent is done with style checks off
454 Save_Style_Check : constant Boolean := Style_Check;
455 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
456 Cunit_Boolean_Restrictions_Save;
459 if not GNAT_Mode then
460 Style_Check := False;
463 Semantics (Parent_Spec (Unit_Node));
464 Version_Update (N, Parent_Spec (Unit_Node));
465 Style_Check := Save_Style_Check;
466 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
470 -- With the analysis done, install the context. Note that we can't
471 -- install the context from the with clauses as we analyze them,
472 -- because each with clause must be analyzed in a clean visibility
473 -- context, so we have to wait and install them all at once.
477 if Is_Child_Spec (Unit_Node) then
479 -- Set the entities of all parents in the program_unit_name.
481 Generate_Parent_References (
482 Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node))));
485 -- All components of the context: with-clauses, library unit, ancestors
486 -- if any, (and their context) are analyzed and installed. Now analyze
487 -- the unit itself, which is either a package, subprogram spec or body.
491 -- The above call might have made Unit_Node an N_Subprogram_Body
492 -- from something else, so propagate any Acts_As_Spec flag.
494 if Nkind (Unit_Node) = N_Subprogram_Body
495 and then Acts_As_Spec (Unit_Node)
497 Set_Acts_As_Spec (N);
500 -- Treat compilation unit pragmas that appear after the library unit
502 if Present (Pragmas_After (Aux_Decls_Node (N))) then
504 Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N)));
507 while Present (Prag_Node) loop
514 -- Generate distribution stubs if requested and no error
517 and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
519 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
520 and then not Fatal_Error (Main_Unit)
522 if Is_RCI_Pkg_Spec_Or_Body (N) then
524 -- Regular RCI package
526 Add_Stub_Constructs (N);
528 elsif (Nkind (Unit_Node) = N_Package_Declaration
529 and then Is_Shared_Passive (Defining_Entity
530 (Specification (Unit_Node))))
531 or else (Nkind (Unit_Node) = N_Package_Body
533 Is_Shared_Passive (Corresponding_Spec (Unit_Node)))
535 -- Shared passive package
537 Add_Stub_Constructs (N);
539 elsif Nkind (Unit_Node) = N_Package_Instantiation
541 Is_Remote_Call_Interface
542 (Defining_Entity (Specification (Instance_Spec (Unit_Node))))
544 -- Instantiation of a RCI generic package
546 Add_Stub_Constructs (N);
551 if Nkind (Unit_Node) = N_Package_Declaration
552 or else Nkind (Unit_Node) in N_Generic_Declaration
553 or else Nkind (Unit_Node) = N_Package_Renaming_Declaration
554 or else Nkind (Unit_Node) = N_Subprogram_Declaration
556 Remove_Unit_From_Visibility (Defining_Entity (Unit_Node));
558 -- If the unit is an instantiation whose body will be elaborated
559 -- for inlining purposes, use the the proper entity of the instance.
561 elsif Nkind (Unit_Node) = N_Package_Instantiation
562 and then not Error_Posted (Unit_Node)
564 Remove_Unit_From_Visibility
565 (Defining_Entity (Instance_Spec (Unit_Node)));
567 elsif Nkind (Unit_Node) = N_Package_Body
568 or else (Nkind (Unit_Node) = N_Subprogram_Body
569 and then not Acts_As_Spec (Unit_Node))
571 -- Bodies that are not the main unit are compiled if they
572 -- are generic or contain generic or inlined units. Their
573 -- analysis brings in the context of the corresponding spec
574 -- (unit declaration) which must be removed as well, to
575 -- return the compilation environment to its proper state.
577 Remove_Context (Lib_Unit);
578 Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False);
581 -- Last step is to deinstall the context we just installed
582 -- as well as the unit just compiled.
586 -- If this is the main unit and we are generating code, we must
587 -- check that all generic units in the context have a body if they
588 -- need it, even if they have not been instantiated. In the absence
589 -- of .ali files for generic units, we must force the load of the body,
590 -- just to produce the proper error if the body is absent. We skip this
591 -- verification if the main unit itself is generic.
593 if Get_Cunit_Unit_Number (N) = Main_Unit
594 and then Operating_Mode = Generate_Code
595 and then Expander_Active
597 -- Check whether the source for the body of the unit must be
598 -- included in a standalone library.
600 Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit));
602 -- Indicate that the main unit is now analyzed, to catch possible
603 -- circularities between it and generic bodies. Remove main unit
604 -- from visibility. This might seem superfluous, but the main unit
605 -- must not be visible in the generic body expansions that follow.
607 Set_Analyzed (N, True);
608 Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False);
613 Un : Unit_Number_Type;
615 Save_Style_Check : constant Boolean := Style_Check;
616 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
617 Cunit_Boolean_Restrictions_Save;
620 Item := First (Context_Items (N));
621 while Present (Item) loop
623 -- Ada0Y (AI-50217): Do not consider limited-withed units
625 if Nkind (Item) = N_With_Clause
626 and then not Implicit_With (Item)
627 and then not Limited_Present (Item)
629 Nam := Entity (Name (Item));
631 if (Is_Generic_Subprogram (Nam)
632 and then not Is_Intrinsic_Subprogram (Nam))
633 or else (Ekind (Nam) = E_Generic_Package
634 and then Unit_Requires_Body (Nam))
636 Style_Check := False;
638 if Present (Renamed_Object (Nam)) then
641 (Load_Name => Get_Body_Name
643 (Unit_Declaration_Node
644 (Renamed_Object (Nam)))),
652 (Load_Name => Get_Body_Name
653 (Get_Unit_Name (Item)),
662 ("body of generic unit& not found", Item, Nam);
665 elsif not Analyzed (Cunit (Un))
666 and then Un /= Main_Unit
667 and then not Fatal_Error (Un)
669 Style_Check := False;
670 Semantics (Cunit (Un));
678 Style_Check := Save_Style_Check;
679 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
683 -- Deal with creating elaboration Boolean if needed. We create an
684 -- elaboration boolean only for units that come from source since
685 -- units manufactured by the compiler never need elab checks.
687 if Comes_From_Source (N)
689 (Nkind (Unit (N)) = N_Package_Declaration or else
690 Nkind (Unit (N)) = N_Generic_Package_Declaration or else
691 Nkind (Unit (N)) = N_Subprogram_Declaration or else
692 Nkind (Unit (N)) = N_Generic_Subprogram_Declaration)
695 Loc : constant Source_Ptr := Sloc (N);
696 Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
699 Spec_Id := Defining_Entity (Unit (N));
700 Generate_Definition (Spec_Id);
702 -- See if an elaboration entity is required for possible
703 -- access before elaboration checking. Note that we must
704 -- allow for this even if -gnatE is not set, since a client
705 -- may be compiled in -gnatE mode and reference the entity.
707 -- Case of units which do not require elaboration checks
710 -- Pure units do not need checks
714 -- Preelaborated units do not need checks
716 or else Is_Preelaborated (Spec_Id)
718 -- No checks needed if pagma Elaborate_Body present
720 or else Has_Pragma_Elaborate_Body (Spec_Id)
722 -- No checks needed if unit does not require a body
724 or else not Unit_Requires_Body (Spec_Id)
726 -- No checks needed for predefined files
728 or else Is_Predefined_File_Name (Unit_File_Name (Unum))
730 -- No checks required if no separate spec
732 or else Acts_As_Spec (N)
734 -- This is a case where we only need the entity for
735 -- checking to prevent multiple elaboration checks.
737 Set_Elaboration_Entity_Required (Spec_Id, False);
739 -- Case of elaboration entity is required for access before
740 -- elaboration checking (so certainly we must build it!)
743 Set_Elaboration_Entity_Required (Spec_Id, True);
746 Build_Elaboration_Entity (N, Spec_Id);
750 -- Finally, freeze the compilation unit entity. This for sure is needed
751 -- because of some warnings that can be output (see Freeze_Subprogram),
752 -- but may in general be required. If freezing actions result, place
753 -- them in the compilation unit actions list, and analyze them.
756 Loc : constant Source_Ptr := Sloc (N);
757 L : constant List_Id :=
758 Freeze_Entity (Cunit_Entity (Current_Sem_Unit), Loc);
761 while Is_Non_Empty_List (L) loop
762 Insert_Library_Level_Action (Remove_Head (L));
768 if Nkind (Unit_Node) = N_Package_Declaration
769 and then Get_Cunit_Unit_Number (N) /= Main_Unit
770 and then Expander_Active
773 Save_Style_Check : constant Boolean := Style_Check;
774 Save_Warning : constant Warning_Mode_Type := Warning_Mode;
775 Options : Style_Check_Options;
778 Save_Style_Check_Options (Options);
779 Reset_Style_Check_Options;
780 Opt.Warning_Mode := Suppress;
781 Check_Body_For_Inlining (N, Defining_Entity (Unit_Node));
783 Reset_Style_Check_Options;
784 Set_Style_Check_Options (Options);
785 Style_Check := Save_Style_Check;
786 Warning_Mode := Save_Warning;
789 end Analyze_Compilation_Unit;
791 ---------------------
792 -- Analyze_Context --
793 ---------------------
795 procedure Analyze_Context (N : Node_Id) is
799 -- Loop through context items. This is done is three passes:
800 -- a) The first pass analyze non-limited with-clauses.
801 -- b) The second pass add implicit limited_with clauses for
802 -- the parents of child units (Ada0Y: AI-50217)
803 -- c) The third pass analyzes limited_with clauses (Ada0Y: AI-50217)
805 Item := First (Context_Items (N));
806 while Present (Item) loop
808 -- For with clause, analyze the with clause, and then update
809 -- the version, since we are dependent on a unit that we with.
811 if Nkind (Item) = N_With_Clause
812 and then not Limited_Present (Item)
815 -- Skip analyzing with clause if no unit, nothing to do (this
816 -- happens for a with that references a non-existant unit)
818 if Present (Library_Unit (Item)) then
822 if not Implicit_With (Item) then
823 Version_Update (N, Library_Unit (Item));
826 -- But skip use clauses at this stage, since we don't want to do
827 -- any installing of potentially use visible entities until we
828 -- we actually install the complete context (in Install_Context).
829 -- Otherwise things can get installed in the wrong context.
830 -- Similarly, pragmas are analyzed in Install_Context, after all
831 -- the implicit with's on parent units are generated.
840 -- Second pass: add implicit limited_with_clauses for parents of
841 -- child units mentioned in limited_with clauses.
843 Item := First (Context_Items (N));
845 while Present (Item) loop
846 if Nkind (Item) = N_With_Clause
847 and then Limited_Present (Item)
848 and then Nkind (Name (Item)) = N_Selected_Component
850 Expand_Limited_With_Clause
851 (Nam => Prefix (Name (Item)), N => Item);
857 -- Third pass: examine all limited_with clauses.
859 Item := First (Context_Items (N));
861 while Present (Item) loop
862 if Nkind (Item) = N_With_Clause
863 and then Limited_Present (Item)
866 if Nkind (Unit (N)) /= N_Package_Declaration then
867 Error_Msg_N ("limited with_clause only allowed in"
868 & " package specification", Item);
871 -- Skip analyzing with clause if no unit, see above.
873 if Present (Library_Unit (Item)) then
877 -- A limited_with does not impose an elaboration order, but
878 -- there is a semantic dependency for recompilation purposes.
880 if not Implicit_With (Item) then
881 Version_Update (N, Library_Unit (Item));
889 -------------------------------
890 -- Analyze_Package_Body_Stub --
891 -------------------------------
893 procedure Analyze_Package_Body_Stub (N : Node_Id) is
894 Id : constant Entity_Id := Defining_Identifier (N);
898 -- The package declaration must be in the current declarative part.
900 Check_Stub_Level (N);
901 Nam := Current_Entity_In_Scope (Id);
903 if No (Nam) or else not Is_Package (Nam) then
904 Error_Msg_N ("missing specification for package stub", N);
906 elsif Has_Completion (Nam)
907 and then Present (Corresponding_Body (Unit_Declaration_Node (Nam)))
909 Error_Msg_N ("duplicate or redundant stub for package", N);
912 -- Indicate that the body of the package exists. If we are doing
913 -- only semantic analysis, the stub stands for the body. If we are
914 -- generating code, the existence of the body will be confirmed
915 -- when we load the proper body.
917 Set_Has_Completion (Nam);
918 Set_Scope (Defining_Entity (N), Current_Scope);
919 Generate_Reference (Nam, Id, 'b');
920 Analyze_Proper_Body (N, Nam);
922 end Analyze_Package_Body_Stub;
924 -------------------------
925 -- Analyze_Proper_Body --
926 -------------------------
928 procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is
929 Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
930 Unum : Unit_Number_Type;
932 procedure Optional_Subunit;
933 -- This procedure is called when the main unit is a stub, or when we
934 -- are not generating code. In such a case, we analyze the subunit if
935 -- present, which is user-friendly and in fact required for ASIS, but
936 -- we don't complain if the subunit is missing.
938 ----------------------
939 -- Optional_Subunit --
940 ----------------------
942 procedure Optional_Subunit is
946 -- Try to load subunit, but ignore any errors that occur during
947 -- the loading of the subunit, by using the special feature in
948 -- Errout to ignore all errors. Note that Fatal_Error will still
949 -- be set, so we will be able to check for this case below.
951 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
954 (Load_Name => Subunit_Name,
958 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
960 -- All done if we successfully loaded the subunit
963 and then (not Fatal_Error (Unum) or else Try_Semantics)
965 Comp_Unit := Cunit (Unum);
967 if Nkind (Unit (Comp_Unit)) /= N_Subunit then
969 ("expected SEPARATE subunit, found child unit",
970 Cunit_Entity (Unum));
972 Set_Corresponding_Stub (Unit (Comp_Unit), N);
973 Analyze_Subunit (Comp_Unit);
974 Set_Library_Unit (N, Comp_Unit);
978 and then Present (Nam)
980 if Is_Protected_Type (Nam) then
981 Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N));
983 Set_Corresponding_Body (
984 Unit_Declaration_Node (Nam), Defining_Identifier (N));
987 end Optional_Subunit;
989 -- Start of processing for Analyze_Proper_Body
992 -- If the subunit is already loaded, it means that the main unit
993 -- is a subunit, and that the current unit is one of its parents
994 -- which was being analyzed to provide the needed context for the
995 -- analysis of the subunit. In this case we analyze the subunit and
996 -- continue with the parent, without looking a subsequent subunits.
998 if Is_Loaded (Subunit_Name) then
1000 -- If the proper body is already linked to the stub node,
1001 -- the stub is in a generic unit and just needs analyzing.
1003 if Present (Library_Unit (N)) then
1004 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1005 Analyze_Subunit (Library_Unit (N));
1007 -- Otherwise we must load the subunit and link to it
1010 -- Load the subunit, this must work, since we originally
1011 -- loaded the subunit earlier on. So this will not really
1012 -- load it, just give access to it.
1016 (Load_Name => Subunit_Name,
1021 -- And analyze the subunit in the parent context (note that we
1022 -- do not call Semantics, since that would remove the parent
1023 -- context). Because of this, we have to manually reset the
1024 -- compiler state to Analyzing since it got destroyed by Load.
1026 if Unum /= No_Unit then
1027 Compiler_State := Analyzing;
1029 -- Check that the proper body is a subunit and not a child
1030 -- unit. If the unit was previously loaded, the error will
1031 -- have been emitted when copying the generic node, so we
1032 -- just return to avoid cascaded errors.
1034 if Nkind (Unit (Cunit (Unum))) /= N_Subunit then
1038 Set_Corresponding_Stub (Unit (Cunit (Unum)), N);
1039 Analyze_Subunit (Cunit (Unum));
1040 Set_Library_Unit (N, Cunit (Unum));
1044 -- If the main unit is a subunit, then we are just performing semantic
1045 -- analysis on that subunit, and any other subunits of any parent unit
1046 -- should be ignored, except that if we are building trees for ASIS
1047 -- usage we want to annotate the stub properly.
1049 elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
1050 and then Subunit_Name /= Unit_Name (Main_Unit)
1056 -- But before we return, set the flag for unloaded subunits. This
1057 -- will suppress junk warnings of variables in the same declarative
1058 -- part (or a higher level one) that are in danger of looking unused
1059 -- when in fact there might be a declaration in the subunit that we
1060 -- do not intend to load.
1062 Unloaded_Subunits := True;
1065 -- If the subunit is not already loaded, and we are generating code,
1066 -- then this is the case where compilation started from the parent,
1067 -- and we are generating code for an entire subunit tree. In that
1068 -- case we definitely need to load the subunit.
1070 -- In order to continue the analysis with the rest of the parent,
1071 -- and other subunits, we load the unit without requiring its
1072 -- presence, and emit a warning if not found, rather than terminating
1073 -- the compilation abruptly, as for other missing file problems.
1075 elsif Original_Operating_Mode = Generate_Code then
1077 -- If the proper body is already linked to the stub node,
1078 -- the stub is in a generic unit and just needs analyzing.
1080 -- We update the version. Although we are not technically
1081 -- semantically dependent on the subunit, given our approach
1082 -- of macro substitution of subunits, it makes sense to
1083 -- include it in the version identification.
1085 if Present (Library_Unit (N)) then
1086 Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
1087 Analyze_Subunit (Library_Unit (N));
1088 Version_Update (Cunit (Main_Unit), Library_Unit (N));
1090 -- Otherwise we must load the subunit and link to it
1095 (Load_Name => Subunit_Name,
1100 if Original_Operating_Mode = Generate_Code
1101 and then Unum = No_Unit
1103 Error_Msg_Name_1 := Subunit_Name;
1105 Get_File_Name (Subunit_Name, Subunit => True);
1107 ("subunit% in file{ not found!?", N);
1108 Subunits_Missing := True;
1111 -- Load_Unit may reset Compiler_State, since it may have been
1112 -- necessary to parse an additional units, so we make sure
1113 -- that we reset it to the Analyzing state.
1115 Compiler_State := Analyzing;
1118 and then (not Fatal_Error (Unum) or else Try_Semantics)
1120 if Debug_Flag_L then
1121 Write_Str ("*** Loaded subunit from stub. Analyze");
1126 Comp_Unit : constant Node_Id := Cunit (Unum);
1129 -- Check for child unit instead of subunit
1131 if Nkind (Unit (Comp_Unit)) /= N_Subunit then
1133 ("expected SEPARATE subunit, found child unit",
1134 Cunit_Entity (Unum));
1136 -- OK, we have a subunit, so go ahead and analyze it,
1137 -- and set Scope of entity in stub, for ASIS use.
1140 Set_Corresponding_Stub (Unit (Comp_Unit), N);
1141 Analyze_Subunit (Comp_Unit);
1142 Set_Library_Unit (N, Comp_Unit);
1144 -- We update the version. Although we are not technically
1145 -- semantically dependent on the subunit, given our
1146 -- approach of macro substitution of subunits, it makes
1147 -- sense to include it in the version identification.
1149 Version_Update (Cunit (Main_Unit), Comp_Unit);
1155 -- The remaining case is when the subunit is not already loaded and
1156 -- we are not generating code. In this case we are just performing
1157 -- semantic analysis on the parent, and we are not interested in
1158 -- the subunit. For subprograms, analyze the stub as a body. For
1159 -- other entities the stub has already been marked as completed.
1165 end Analyze_Proper_Body;
1167 ----------------------------------
1168 -- Analyze_Protected_Body_Stub --
1169 ----------------------------------
1171 procedure Analyze_Protected_Body_Stub (N : Node_Id) is
1172 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
1175 Check_Stub_Level (N);
1177 -- First occurence of name may have been as an incomplete type.
1179 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1180 Nam := Full_View (Nam);
1184 or else not Is_Protected_Type (Etype (Nam))
1186 Error_Msg_N ("missing specification for Protected body", N);
1188 Set_Scope (Defining_Entity (N), Current_Scope);
1189 Set_Has_Completion (Etype (Nam));
1190 Generate_Reference (Nam, Defining_Identifier (N), 'b');
1191 Analyze_Proper_Body (N, Etype (Nam));
1193 end Analyze_Protected_Body_Stub;
1195 ----------------------------------
1196 -- Analyze_Subprogram_Body_Stub --
1197 ----------------------------------
1199 -- A subprogram body stub can appear with or without a previous
1200 -- specification. If there is one, the analysis of the body will
1201 -- find it and verify conformance. The formals appearing in the
1202 -- specification of the stub play no role, except for requiring an
1203 -- additional conformance check. If there is no previous subprogram
1204 -- declaration, the stub acts as a spec, and provides the defining
1205 -- entity for the subprogram.
1207 procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
1211 Check_Stub_Level (N);
1213 -- Verify that the identifier for the stub is unique within this
1214 -- declarative part.
1216 if Nkind (Parent (N)) = N_Block_Statement
1217 or else Nkind (Parent (N)) = N_Package_Body
1218 or else Nkind (Parent (N)) = N_Subprogram_Body
1220 Decl := First (Declarations (Parent (N)));
1222 while Present (Decl)
1225 if Nkind (Decl) = N_Subprogram_Body_Stub
1226 and then (Chars (Defining_Unit_Name (Specification (Decl)))
1227 = Chars (Defining_Unit_Name (Specification (N))))
1229 Error_Msg_N ("identifier for stub is not unique", N);
1236 -- Treat stub as a body, which checks conformance if there is a previous
1237 -- declaration, or else introduces entity and its signature.
1239 Analyze_Subprogram_Body (N);
1240 Analyze_Proper_Body (N, Empty);
1241 end Analyze_Subprogram_Body_Stub;
1243 ---------------------
1244 -- Analyze_Subunit --
1245 ---------------------
1247 -- A subunit is compiled either by itself (for semantic checking)
1248 -- or as part of compiling the parent (for code generation). In
1249 -- either case, by the time we actually process the subunit, the
1250 -- parent has already been installed and analyzed. The node N is
1251 -- a compilation unit, whose context needs to be treated here,
1252 -- because we come directly here from the parent without calling
1253 -- Analyze_Compilation_Unit.
1255 -- The compilation context includes the explicit context of the
1256 -- subunit, and the context of the parent, together with the parent
1257 -- itself. In order to compile the current context, we remove the
1258 -- one inherited from the parent, in order to have a clean visibility
1259 -- table. We restore the parent context before analyzing the proper
1260 -- body itself. On exit, we remove only the explicit context of the
1263 procedure Analyze_Subunit (N : Node_Id) is
1264 Lib_Unit : constant Node_Id := Library_Unit (N);
1265 Par_Unit : constant Entity_Id := Current_Scope;
1267 Lib_Spec : Node_Id := Library_Unit (Lib_Unit);
1268 Num_Scopes : Int := 0;
1269 Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id;
1270 Enclosing_Child : Entity_Id := Empty;
1271 Svg : constant Suppress_Array := Scope_Suppress;
1273 procedure Analyze_Subunit_Context;
1274 -- Capture names in use clauses of the subunit. This must be done
1275 -- before re-installing parent declarations, because items in the
1276 -- context must not be hidden by declarations local to the parent.
1278 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id);
1279 -- Recursive procedure to restore scope of all ancestors of subunit,
1280 -- from outermost in. If parent is not a subunit, the call to install
1281 -- context installs context of spec and (if parent is a child unit)
1282 -- the context of its parents as well. It is confusing that parents
1283 -- should be treated differently in both cases, but the semantics are
1284 -- just not identical.
1286 procedure Re_Install_Use_Clauses;
1287 -- As part of the removal of the parent scope, the use clauses are
1288 -- removed, to be reinstalled when the context of the subunit has
1289 -- been analyzed. Use clauses may also have been affected by the
1290 -- analysis of the context of the subunit, so they have to be applied
1291 -- again, to insure that the compilation environment of the rest of
1292 -- the parent unit is identical.
1294 procedure Remove_Scope;
1295 -- Remove current scope from scope stack, and preserve the list
1296 -- of use clauses in it, to be reinstalled after context is analyzed.
1298 ------------------------------
1299 -- Analyze_Subunit_Context --
1300 ------------------------------
1302 procedure Analyze_Subunit_Context is
1305 Unit_Name : Entity_Id;
1308 Analyze_Context (N);
1309 Item := First (Context_Items (N));
1311 -- make withed units immediately visible. If child unit, make the
1312 -- ultimate parent immediately visible.
1314 while Present (Item) loop
1316 if Nkind (Item) = N_With_Clause then
1317 Unit_Name := Entity (Name (Item));
1319 while Is_Child_Unit (Unit_Name) loop
1320 Set_Is_Visible_Child_Unit (Unit_Name);
1321 Unit_Name := Scope (Unit_Name);
1324 if not Is_Immediately_Visible (Unit_Name) then
1325 Set_Is_Immediately_Visible (Unit_Name);
1326 Set_Context_Installed (Item);
1329 elsif Nkind (Item) = N_Use_Package_Clause then
1330 Nam := First (Names (Item));
1332 while Present (Nam) loop
1337 elsif Nkind (Item) = N_Use_Type_Clause then
1338 Nam := First (Subtype_Marks (Item));
1340 while Present (Nam) loop
1349 Item := First (Context_Items (N));
1351 -- reset visibility of withed units. They will be made visible
1352 -- again when we install the subunit context.
1354 while Present (Item) loop
1356 if Nkind (Item) = N_With_Clause then
1357 Unit_Name := Entity (Name (Item));
1359 while Is_Child_Unit (Unit_Name) loop
1360 Set_Is_Visible_Child_Unit (Unit_Name, False);
1361 Unit_Name := Scope (Unit_Name);
1364 if Context_Installed (Item) then
1365 Set_Is_Immediately_Visible (Unit_Name, False);
1366 Set_Context_Installed (Item, False);
1373 end Analyze_Subunit_Context;
1375 ------------------------
1376 -- Re_Install_Parents --
1377 ------------------------
1379 procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is
1383 if Nkind (Unit (L)) = N_Subunit then
1384 Re_Install_Parents (Library_Unit (L), Scope (Scop));
1387 Install_Context (L);
1389 -- If the subunit occurs within a child unit, we must restore the
1390 -- immediate visibility of any siblings that may occur in context.
1392 if Present (Enclosing_Child) then
1393 Install_Siblings (Enclosing_Child, L);
1398 if Scop /= Par_Unit then
1399 Set_Is_Immediately_Visible (Scop);
1402 E := First_Entity (Current_Scope);
1404 while Present (E) loop
1405 Set_Is_Immediately_Visible (E);
1409 -- A subunit appears within a body, and for a nested subunits
1410 -- all the parents are bodies. Restore full visibility of their
1411 -- private entities.
1413 if Ekind (Scop) = E_Package then
1414 Set_In_Package_Body (Scop);
1415 Install_Private_Declarations (Scop);
1417 end Re_Install_Parents;
1419 ----------------------------
1420 -- Re_Install_Use_Clauses --
1421 ----------------------------
1423 procedure Re_Install_Use_Clauses is
1427 for J in reverse 1 .. Num_Scopes loop
1428 U := Use_Clauses (J);
1429 Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U;
1430 Install_Use_Clauses (U);
1432 end Re_Install_Use_Clauses;
1438 procedure Remove_Scope is
1442 Num_Scopes := Num_Scopes + 1;
1443 Use_Clauses (Num_Scopes) :=
1444 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause;
1445 E := First_Entity (Current_Scope);
1447 while Present (E) loop
1448 Set_Is_Immediately_Visible (E, False);
1452 if Is_Child_Unit (Current_Scope) then
1453 Enclosing_Child := Current_Scope;
1459 -- Start of processing for Analyze_Subunit
1462 if not Is_Empty_List (Context_Items (N)) then
1464 -- Save current use clauses.
1467 Remove_Context (Lib_Unit);
1469 -- Now remove parents and their context, including enclosing
1470 -- subunits and the outer parent body which is not a subunit.
1472 if Present (Lib_Spec) then
1473 Remove_Context (Lib_Spec);
1475 while Nkind (Unit (Lib_Spec)) = N_Subunit loop
1476 Lib_Spec := Library_Unit (Lib_Spec);
1478 Remove_Context (Lib_Spec);
1481 if Nkind (Unit (Lib_Unit)) = N_Subunit then
1485 if Nkind (Unit (Lib_Spec)) = N_Package_Body then
1486 Remove_Context (Library_Unit (Lib_Spec));
1490 Set_Is_Immediately_Visible (Par_Unit, False);
1492 Analyze_Subunit_Context;
1494 Re_Install_Parents (Lib_Unit, Par_Unit);
1495 Set_Is_Immediately_Visible (Par_Unit);
1497 -- If the context includes a child unit of the parent of the
1498 -- subunit, the parent will have been removed from visibility,
1499 -- after compiling that cousin in the context. The visibility
1500 -- of the parent must be restored now. This also applies if the
1501 -- context includes another subunit of the same parent which in
1502 -- turn includes a child unit in its context.
1504 if Ekind (Par_Unit) = E_Package then
1505 if not Is_Immediately_Visible (Par_Unit)
1506 or else (Present (First_Entity (Par_Unit))
1507 and then not Is_Immediately_Visible
1508 (First_Entity (Par_Unit)))
1510 Set_Is_Immediately_Visible (Par_Unit);
1511 Install_Visible_Declarations (Par_Unit);
1512 Install_Private_Declarations (Par_Unit);
1516 Re_Install_Use_Clauses;
1517 Install_Context (N);
1519 -- Restore state of suppress flags for current body.
1521 Scope_Suppress := Svg;
1523 -- If the subunit is within a child unit, then siblings of any
1524 -- parent unit that appear in the context clause of the subunit
1525 -- must also be made immediately visible.
1527 if Present (Enclosing_Child) then
1528 Install_Siblings (Enclosing_Child, N);
1533 Analyze (Proper_Body (Unit (N)));
1535 end Analyze_Subunit;
1537 ----------------------------
1538 -- Analyze_Task_Body_Stub --
1539 ----------------------------
1541 procedure Analyze_Task_Body_Stub (N : Node_Id) is
1542 Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
1543 Loc : constant Source_Ptr := Sloc (N);
1546 Check_Stub_Level (N);
1548 -- First occurence of name may have been as an incomplete type.
1550 if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
1551 Nam := Full_View (Nam);
1555 or else not Is_Task_Type (Etype (Nam))
1557 Error_Msg_N ("missing specification for task body", N);
1559 Set_Scope (Defining_Entity (N), Current_Scope);
1560 Generate_Reference (Nam, Defining_Identifier (N), 'b');
1561 Set_Has_Completion (Etype (Nam));
1562 Analyze_Proper_Body (N, Etype (Nam));
1564 -- Set elaboration flag to indicate that entity is callable.
1565 -- This cannot be done in the expansion of the body itself,
1566 -- because the proper body is not in a declarative part. This
1567 -- is only done if expansion is active, because the context
1568 -- may be generic and the flag not defined yet.
1570 if Expander_Active then
1572 Make_Assignment_Statement (Loc,
1574 Make_Identifier (Loc,
1575 New_External_Name (Chars (Etype (Nam)), 'E')),
1576 Expression => New_Reference_To (Standard_True, Loc)));
1580 end Analyze_Task_Body_Stub;
1582 -------------------------
1583 -- Analyze_With_Clause --
1584 -------------------------
1586 -- Analyze the declaration of a unit in a with clause. At end,
1587 -- label the with clause with the defining entity for the unit.
1589 procedure Analyze_With_Clause (N : Node_Id) is
1591 -- Retrieve the original kind of the unit node, before analysis.
1592 -- If it is a subprogram instantiation, its analysis below will
1593 -- rewrite as the declaration of the wrapper package. If the same
1594 -- instantiation appears indirectly elsewhere in the context, it
1595 -- will have been analyzed already.
1597 Unit_Kind : constant Node_Kind :=
1598 Nkind (Original_Node (Unit (Library_Unit (N))));
1601 Par_Name : Entity_Id;
1606 -- Set True if the unit currently being compiled is an internal unit
1608 Save_Style_Check : constant Boolean := Opt.Style_Check;
1609 Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
1610 Cunit_Boolean_Restrictions_Save;
1613 if Limited_Present (N) then
1614 -- Ada0Y (AI-50217): Build visibility structures but do not
1617 Build_Limited_Views (N);
1621 -- We reset ordinary style checking during the analysis of a with'ed
1622 -- unit, but we do NOT reset GNAT special analysis mode (the latter
1623 -- definitely *does* apply to with'ed units).
1625 if not GNAT_Mode then
1626 Style_Check := False;
1629 -- If the library unit is a predefined unit, and we are in high
1630 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
1631 -- for the analysis of the with'ed unit. This mode does not prevent
1632 -- explicit with'ing of run-time units.
1634 if Configurable_Run_Time_Mode
1636 Is_Predefined_File_Name
1637 (Unit_File_Name (Get_Source_Unit (Unit (Library_Unit (N)))))
1639 Configurable_Run_Time_Mode := False;
1640 Semantics (Library_Unit (N));
1641 Configurable_Run_Time_Mode := True;
1644 Semantics (Library_Unit (N));
1647 U := Unit (Library_Unit (N));
1648 Intunit := Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit));
1650 -- Following checks are skipped for dummy packages (those supplied
1651 -- for with's where no matching file could be found). Such packages
1652 -- are identified by the Sloc value being set to No_Location
1654 if Sloc (U) /= No_Location then
1656 -- Check restrictions, except that we skip the check if this
1657 -- is an internal unit unless we are compiling the internal
1658 -- unit as the main unit. We also skip this for dummy packages.
1660 if not Intunit or else Current_Sem_Unit = Main_Unit then
1661 Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N);
1664 -- Check for inappropriate with of internal implementation unit
1665 -- if we are currently compiling the main unit and the main unit
1666 -- is itself not an internal unit. We do not issue this message
1667 -- for implicit with's generated by the compiler itself.
1669 if Implementation_Unit_Warnings
1670 and then Current_Sem_Unit = Main_Unit
1671 and then Implementation_Unit (Get_Source_Unit (U))
1672 and then not Intunit
1673 and then not Implicit_With (N)
1675 Error_Msg_N ("& is an internal 'G'N'A'T unit?", Name (N));
1677 ("\use of this unit is non-portable and version-dependent?",
1682 -- Semantic analysis of a generic unit is performed on a copy of
1683 -- the original tree. Retrieve the entity on which semantic info
1684 -- actually appears.
1686 if Unit_Kind in N_Generic_Declaration then
1687 E_Name := Defining_Entity (U);
1689 -- Note: in the following test, Unit_Kind is the original Nkind, but
1690 -- in the case of an instantiation, semantic analysis above will
1691 -- have replaced the unit by its instantiated version. If the instance
1692 -- body has been generated, the instance now denotes the body entity.
1693 -- For visibility purposes we need the entity of its spec.
1695 elsif (Unit_Kind = N_Package_Instantiation
1696 or else Nkind (Original_Node (Unit (Library_Unit (N)))) =
1697 N_Package_Instantiation)
1698 and then Nkind (U) = N_Package_Body
1700 E_Name := Corresponding_Spec (U);
1702 elsif Unit_Kind = N_Package_Instantiation
1703 and then Nkind (U) = N_Package_Instantiation
1705 -- If the instance has not been rewritten as a package declaration,
1706 -- then it appeared already in a previous with clause. Retrieve
1707 -- the entity from the previous instance.
1709 E_Name := Defining_Entity (Specification (Instance_Spec (U)));
1711 elsif Unit_Kind = N_Procedure_Instantiation
1712 or else Unit_Kind = N_Function_Instantiation
1714 -- Instantiation node is replaced with a package that contains
1715 -- renaming declarations and instance itself. The subprogram
1716 -- Instance is declared in the visible part of the wrapper package.
1718 E_Name := First_Entity (Defining_Entity (U));
1720 while Present (E_Name) loop
1721 exit when Is_Subprogram (E_Name)
1722 and then Is_Generic_Instance (E_Name);
1723 E_Name := Next_Entity (E_Name);
1726 elsif Unit_Kind = N_Package_Renaming_Declaration
1727 or else Unit_Kind in N_Generic_Renaming_Declaration
1729 E_Name := Defining_Entity (U);
1731 elsif Unit_Kind = N_Subprogram_Body
1732 and then Nkind (Name (N)) = N_Selected_Component
1733 and then not Acts_As_Spec (Library_Unit (N))
1735 -- For a child unit that has no spec, one has been created and
1736 -- analyzed. The entity required is that of the spec.
1738 E_Name := Corresponding_Spec (U);
1741 E_Name := Defining_Entity (U);
1744 if Nkind (Name (N)) = N_Selected_Component then
1746 -- Child unit in a with clause
1748 Change_Selected_Component_To_Expanded_Name (Name (N));
1751 -- Restore style checks and restrictions
1753 Style_Check := Save_Style_Check;
1754 Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
1756 -- Record the reference, but do NOT set the unit as referenced, we
1757 -- want to consider the unit as unreferenced if this is the only
1758 -- reference that occurs.
1760 Set_Entity_With_Style_Check (Name (N), E_Name);
1761 Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False);
1763 if Is_Child_Unit (E_Name) then
1764 Pref := Prefix (Name (N));
1765 Par_Name := Scope (E_Name);
1767 while Nkind (Pref) = N_Selected_Component loop
1768 Change_Selected_Component_To_Expanded_Name (Pref);
1769 Set_Entity_With_Style_Check (Pref, Par_Name);
1771 Generate_Reference (Par_Name, Pref);
1772 Pref := Prefix (Pref);
1774 -- If E_Name is the dummy entity for a nonexistent unit,
1775 -- its scope is set to Standard_Standard, and no attempt
1776 -- should be made to further unwind scopes.
1778 if Par_Name /= Standard_Standard then
1779 Par_Name := Scope (Par_Name);
1783 if Present (Entity (Pref))
1784 and then not Analyzed (Parent (Parent (Entity (Pref))))
1786 -- If the entity is set without its unit being compiled,
1787 -- the original parent is a renaming, and Par_Name is the
1788 -- renamed entity. For visibility purposes, we need the
1789 -- original entity, which must be analyzed now, because
1790 -- Load_Unit retrieves directly the renamed unit, and the
1791 -- renaming declaration itself has not been analyzed.
1793 Analyze (Parent (Parent (Entity (Pref))));
1794 pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name);
1795 Par_Name := Entity (Pref);
1798 Set_Entity_With_Style_Check (Pref, Par_Name);
1799 Generate_Reference (Par_Name, Pref);
1802 -- If the withed unit is System, and a system extension pragma is
1803 -- present, compile the extension now, rather than waiting for
1804 -- a visibility check on a specific entity.
1806 if Chars (E_Name) = Name_System
1807 and then Scope (E_Name) = Standard_Standard
1808 and then Present (System_Extend_Unit)
1809 and then Present_System_Aux (N)
1811 -- If the extension is not present, an error will have been emitted.
1816 -- Ada 0Y (AI-262): Remove from visibility the entity corresponding to
1817 -- private_with units; they will be made visible later (just before the
1818 -- private part is analyzed)
1820 if Private_Present (N) then
1821 Set_Is_Immediately_Visible (E_Name, False);
1823 end Analyze_With_Clause;
1825 ------------------------------
1826 -- Analyze_With_Type_Clause --
1827 ------------------------------
1829 procedure Analyze_With_Type_Clause (N : Node_Id) is
1830 Loc : constant Source_Ptr := Sloc (N);
1831 Nam : constant Node_Id := Name (N);
1835 Unum : Unit_Number_Type;
1838 procedure Decorate_Tagged_Type (T : Entity_Id);
1839 -- Set basic attributes of type, including its class_wide type.
1841 function In_Chain (E : Entity_Id) return Boolean;
1842 -- Check that the imported type is not already in the homonym chain,
1843 -- for example through a with_type clause in a parent unit.
1845 --------------------------
1846 -- Decorate_Tagged_Type --
1847 --------------------------
1849 procedure Decorate_Tagged_Type (T : Entity_Id) is
1853 Set_Ekind (T, E_Record_Type);
1854 Set_Is_Tagged_Type (T);
1856 Set_From_With_Type (T);
1859 if not In_Chain (T) then
1860 Set_Homonym (T, Current_Entity (T));
1861 Set_Current_Entity (T);
1864 -- Build bogus class_wide type, if not previously done.
1866 if No (Class_Wide_Type (T)) then
1867 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
1869 Set_Ekind (CW, E_Class_Wide_Type);
1872 Set_Is_Tagged_Type (CW);
1873 Set_Is_First_Subtype (CW, True);
1874 Init_Size_Align (CW);
1875 Set_Has_Unknown_Discriminants
1877 Set_Class_Wide_Type (CW, CW);
1878 Set_Equivalent_Type (CW, Empty);
1879 Set_From_With_Type (CW);
1881 Set_Class_Wide_Type (T, CW);
1883 end Decorate_Tagged_Type;
1889 function In_Chain (E : Entity_Id) return Boolean is
1890 H : Entity_Id := Current_Entity (E);
1893 while Present (H) loop
1905 -- Start of processing for Analyze_With_Type_Clause
1908 if Nkind (Nam) = N_Selected_Component then
1909 Pack := New_Copy_Tree (Prefix (Nam));
1910 Sel := Selector_Name (Nam);
1913 Error_Msg_N ("illegal name for imported type", Nam);
1918 Make_Package_Declaration (Loc,
1920 (Make_Package_Specification (Loc,
1921 Defining_Unit_Name => Pack,
1922 Visible_Declarations => New_List,
1923 End_Label => Empty)));
1927 (Load_Name => Get_Unit_Name (Decl),
1933 or else Nkind (Unit (Cunit (Unum))) /= N_Package_Declaration
1935 Error_Msg_N ("imported type must be declared in package", Nam);
1938 elsif Unum = Current_Sem_Unit then
1940 -- If type is defined in unit being analyzed, then the clause
1946 P := Cunit_Entity (Unum);
1949 -- Find declaration for imported type, and set its basic attributes
1950 -- if it has not been analyzed (which will be the case if there is
1951 -- circular dependence).
1958 if not Analyzed (Cunit (Unum))
1959 and then not From_With_Type (P)
1961 Set_Ekind (P, E_Package);
1962 Set_Etype (P, Standard_Void_Type);
1963 Set_From_With_Type (P);
1964 Set_Scope (P, Standard_Standard);
1965 Set_Homonym (P, Current_Entity (P));
1966 Set_Current_Entity (P);
1968 elsif Analyzed (Cunit (Unum))
1969 and then Is_Child_Unit (P)
1971 -- If the child unit is already in scope, indicate that it is
1972 -- visible, and remains so after intervening calls to rtsfind.
1974 Set_Is_Visible_Child_Unit (P);
1977 if Nkind (Parent (P)) = N_Defining_Program_Unit_Name then
1979 -- Make parent packages visible.
1982 Parent_Comp : Node_Id;
1983 Parent_Id : Entity_Id;
1988 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
1991 Parent_Id := Defining_Entity (Unit (Parent_Comp));
1992 Set_Scope (Child, Parent_Id);
1994 -- The type may be imported from a child unit, in which
1995 -- case the current compilation appears in the name. Do
1996 -- not change its visibility here because it will conflict
1997 -- with the subsequent normal processing.
1999 if not Analyzed (Unit_Declaration_Node (Parent_Id))
2000 and then Parent_Id /= Cunit_Entity (Current_Sem_Unit)
2002 Set_Ekind (Parent_Id, E_Package);
2003 Set_Etype (Parent_Id, Standard_Void_Type);
2005 -- The same package may appear is several with_type
2008 if not From_With_Type (Parent_Id) then
2009 Set_Homonym (Parent_Id, Current_Entity (Parent_Id));
2010 Set_Current_Entity (Parent_Id);
2011 Set_From_With_Type (Parent_Id);
2015 Set_Is_Immediately_Visible (Parent_Id);
2018 Parent_Comp := Parent_Spec (Unit (Parent_Comp));
2019 exit when No (Parent_Comp);
2022 Set_Scope (Parent_Id, Standard_Standard);
2026 -- Even if analyzed, the package may not be currently visible. It
2027 -- must be while the with_type clause is active.
2029 Set_Is_Immediately_Visible (P);
2032 First (Visible_Declarations (Specification (Unit (Cunit (Unum)))));
2034 while Present (Decl) loop
2036 if Nkind (Decl) = N_Full_Type_Declaration
2037 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2039 Typ := Defining_Identifier (Decl);
2041 if Tagged_Present (N) then
2043 -- The declaration must indicate that this is a tagged
2044 -- type or a type extension.
2046 if (Nkind (Type_Definition (Decl)) = N_Record_Definition
2047 and then Tagged_Present (Type_Definition (Decl)))
2049 (Nkind (Type_Definition (Decl))
2050 = N_Derived_Type_Definition
2052 (Record_Extension_Part (Type_Definition (Decl))))
2056 Error_Msg_N ("imported type is not a tagged type", Nam);
2060 if not Analyzed (Decl) then
2062 -- Unit is not currently visible. Add basic attributes
2063 -- to type and build its class-wide type.
2065 Init_Size_Align (Typ);
2066 Decorate_Tagged_Type (Typ);
2070 if Nkind (Type_Definition (Decl))
2071 /= N_Access_To_Object_Definition
2074 ("imported type is not an access type", Nam);
2076 elsif not Analyzed (Decl) then
2077 Set_Ekind (Typ, E_Access_Type);
2078 Set_Etype (Typ, Typ);
2080 Init_Size (Typ, System_Address_Size);
2081 Init_Alignment (Typ);
2082 Set_Directly_Designated_Type (Typ, Standard_Integer);
2083 Set_From_With_Type (Typ);
2085 if not In_Chain (Typ) then
2086 Set_Homonym (Typ, Current_Entity (Typ));
2087 Set_Current_Entity (Typ);
2092 Set_Entity (Sel, Typ);
2095 elsif ((Nkind (Decl) = N_Private_Type_Declaration
2096 and then Tagged_Present (Decl))
2097 or else (Nkind (Decl) = N_Private_Extension_Declaration))
2098 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2100 Typ := Defining_Identifier (Decl);
2102 if not Tagged_Present (N) then
2103 Error_Msg_N ("type must be declared tagged", N);
2105 elsif not Analyzed (Decl) then
2106 Decorate_Tagged_Type (Typ);
2109 Set_Entity (Sel, Typ);
2110 Set_From_With_Type (Typ);
2114 Decl := Next (Decl);
2117 Error_Msg_NE ("not a visible access or tagged type in&", Nam, P);
2119 end Analyze_With_Type_Clause;
2121 -----------------------------
2122 -- Check_With_Type_Clauses --
2123 -----------------------------
2125 procedure Check_With_Type_Clauses (N : Node_Id) is
2126 Lib_Unit : constant Node_Id := Unit (N);
2128 procedure Check_Parent_Context (U : Node_Id);
2129 -- Examine context items of parent unit to locate with_type clauses.
2131 --------------------------
2132 -- Check_Parent_Context --
2133 --------------------------
2135 procedure Check_Parent_Context (U : Node_Id) is
2139 Item := First (Context_Items (U));
2140 while Present (Item) loop
2141 if Nkind (Item) = N_With_Type_Clause
2142 and then not Error_Posted (Item)
2144 From_With_Type (Scope (Entity (Selector_Name (Name (Item)))))
2146 Error_Msg_Sloc := Sloc (Item);
2147 Error_Msg_N ("Missing With_Clause for With_Type_Clause#", N);
2152 end Check_Parent_Context;
2154 -- Start of processing for Check_With_Type_Clauses
2157 if Extensions_Allowed
2158 and then (Nkind (Lib_Unit) = N_Package_Body
2159 or else Nkind (Lib_Unit) = N_Subprogram_Body)
2161 Check_Parent_Context (Library_Unit (N));
2162 if Is_Child_Spec (Unit (Library_Unit (N))) then
2163 Check_Parent_Context (Parent_Spec (Unit (Library_Unit (N))));
2166 end Check_With_Type_Clauses;
2168 ------------------------------
2169 -- Check_Private_Child_Unit --
2170 ------------------------------
2172 procedure Check_Private_Child_Unit (N : Node_Id) is
2173 Lib_Unit : constant Node_Id := Unit (N);
2175 Curr_Unit : Entity_Id;
2176 Sub_Parent : Node_Id;
2177 Priv_Child : Entity_Id;
2178 Par_Lib : Entity_Id;
2181 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
2182 -- Returns true if and only if the library unit is declared with
2183 -- an explicit designation of private.
2185 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
2186 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
2189 return Private_Present (Comp_Unit);
2190 end Is_Private_Library_Unit;
2192 -- Start of processing for Check_Private_Child_Unit
2195 if Nkind (Lib_Unit) = N_Package_Body
2196 or else Nkind (Lib_Unit) = N_Subprogram_Body
2198 Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
2199 Par_Lib := Curr_Unit;
2201 elsif Nkind (Lib_Unit) = N_Subunit then
2203 -- The parent is itself a body. The parent entity is to be found
2204 -- in the corresponding spec.
2206 Sub_Parent := Library_Unit (N);
2207 Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
2209 -- If the parent itself is a subunit, Curr_Unit is the entity
2210 -- of the enclosing body, retrieve the spec entity which is
2211 -- the proper ancestor we need for the following tests.
2213 if Ekind (Curr_Unit) = E_Package_Body then
2214 Curr_Unit := Spec_Entity (Curr_Unit);
2217 Par_Lib := Curr_Unit;
2220 Curr_Unit := Defining_Entity (Lib_Unit);
2222 Par_Lib := Curr_Unit;
2223 Par_Spec := Parent_Spec (Lib_Unit);
2225 if No (Par_Spec) then
2228 Par_Lib := Defining_Entity (Unit (Par_Spec));
2232 -- Loop through context items
2234 Item := First (Context_Items (N));
2235 while Present (Item) loop
2237 -- Ada 0Y (AI-262): Allow private_with of a private child package in
2240 if Nkind (Item) = N_With_Clause
2241 and then not Implicit_With (Item)
2242 and then not Private_Present (Item)
2243 and then Is_Private_Descendant (Entity (Name (Item)))
2245 Priv_Child := Entity (Name (Item));
2248 Curr_Parent : Entity_Id := Par_Lib;
2249 Child_Parent : Entity_Id := Scope (Priv_Child);
2250 Prv_Ancestor : Entity_Id := Child_Parent;
2251 Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
2254 -- If the child unit is a public child then locate
2255 -- the nearest private ancestor; Child_Parent will
2256 -- then be set to the parent of that ancestor.
2258 if not Is_Private_Library_Unit (Priv_Child) then
2259 while Present (Prv_Ancestor)
2260 and then not Is_Private_Library_Unit (Prv_Ancestor)
2262 Prv_Ancestor := Scope (Prv_Ancestor);
2265 if Present (Prv_Ancestor) then
2266 Child_Parent := Scope (Prv_Ancestor);
2270 while Present (Curr_Parent)
2271 and then Curr_Parent /= Standard_Standard
2272 and then Curr_Parent /= Child_Parent
2275 Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
2276 Curr_Parent := Scope (Curr_Parent);
2279 if not Present (Curr_Parent) then
2280 Curr_Parent := Standard_Standard;
2283 if Curr_Parent /= Child_Parent then
2285 if Ekind (Priv_Child) = E_Generic_Package
2286 and then Chars (Priv_Child) in Text_IO_Package_Name
2287 and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
2290 ("& is a nested package, not a compilation unit",
2291 Name (Item), Priv_Child);
2295 ("unit in with clause is private child unit!", Item);
2297 ("current unit must also have parent&!",
2298 Item, Child_Parent);
2301 elsif not Curr_Private
2302 and then Nkind (Lib_Unit) /= N_Package_Body
2303 and then Nkind (Lib_Unit) /= N_Subprogram_Body
2304 and then Nkind (Lib_Unit) /= N_Subunit
2307 ("current unit must also be private descendant of&",
2308 Item, Child_Parent);
2316 end Check_Private_Child_Unit;
2318 ----------------------
2319 -- Check_Stub_Level --
2320 ----------------------
2322 procedure Check_Stub_Level (N : Node_Id) is
2323 Par : constant Node_Id := Parent (N);
2324 Kind : constant Node_Kind := Nkind (Par);
2327 if (Kind = N_Package_Body
2328 or else Kind = N_Subprogram_Body
2329 or else Kind = N_Task_Body
2330 or else Kind = N_Protected_Body)
2332 and then (Nkind (Parent (Par)) = N_Compilation_Unit
2333 or else Nkind (Parent (Par)) = N_Subunit)
2337 -- In an instance, a missing stub appears at any level. A warning
2338 -- message will have been emitted already for the missing file.
2340 elsif not In_Instance then
2341 Error_Msg_N ("stub cannot appear in an inner scope", N);
2343 elsif Expander_Active then
2344 Error_Msg_N ("missing proper body", N);
2346 end Check_Stub_Level;
2348 ------------------------
2349 -- Expand_With_Clause --
2350 ------------------------
2352 procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id) is
2353 Loc : constant Source_Ptr := Sloc (Nam);
2354 Ent : constant Entity_Id := Entity (Nam);
2358 function Build_Unit_Name (Nam : Node_Id) return Node_Id;
2360 function Build_Unit_Name (Nam : Node_Id) return Node_Id is
2364 if Nkind (Nam) = N_Identifier then
2365 return New_Occurrence_Of (Entity (Nam), Loc);
2369 Make_Expanded_Name (Loc,
2370 Chars => Chars (Entity (Nam)),
2371 Prefix => Build_Unit_Name (Prefix (Nam)),
2372 Selector_Name => New_Occurrence_Of (Entity (Nam), Loc));
2373 Set_Entity (Result, Entity (Nam));
2376 end Build_Unit_Name;
2379 New_Nodes_OK := New_Nodes_OK + 1;
2381 Make_With_Clause (Loc, Name => Build_Unit_Name (Nam));
2383 P := Parent (Unit_Declaration_Node (Ent));
2384 Set_Library_Unit (Withn, P);
2385 Set_Corresponding_Spec (Withn, Ent);
2386 Set_First_Name (Withn, True);
2387 Set_Implicit_With (Withn, True);
2389 Prepend (Withn, Context_Items (N));
2390 Mark_Rewrite_Insertion (Withn);
2391 Install_Withed_Unit (Withn);
2393 if Nkind (Nam) = N_Expanded_Name then
2394 Expand_With_Clause (Prefix (Nam), N);
2397 New_Nodes_OK := New_Nodes_OK - 1;
2398 end Expand_With_Clause;
2400 --------------------------------
2401 -- Expand_Limited_With_Clause --
2402 --------------------------------
2404 procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id) is
2405 Loc : constant Source_Ptr := Sloc (Nam);
2406 Unum : Unit_Number_Type;
2410 New_Nodes_OK := New_Nodes_OK + 1;
2412 if Nkind (Nam) = N_Identifier then
2414 Make_With_Clause (Loc, Name => Nam);
2415 Set_Limited_Present (Withn);
2416 Set_First_Name (Withn);
2417 Set_Implicit_With (Withn);
2419 -- Load the corresponding parent unit
2423 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2428 if not Analyzed (Cunit (Unum)) then
2429 Set_Library_Unit (Withn, Cunit (Unum));
2430 Set_Corresponding_Spec
2431 (Withn, Specification (Unit (Cunit (Unum))));
2433 Prepend (Withn, Context_Items (Parent (N)));
2434 Mark_Rewrite_Insertion (Withn);
2437 else pragma Assert (Nkind (Nam) = N_Selected_Component);
2442 Make_Selected_Component
2444 Prefix => Prefix (Nam),
2445 Selector_Name => Selector_Name (Nam)));
2447 Set_Parent (Withn, Parent (N));
2448 Set_Limited_Present (Withn);
2449 Set_First_Name (Withn);
2450 Set_Implicit_With (Withn);
2454 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2459 if not Analyzed (Cunit (Unum)) then
2460 Set_Library_Unit (Withn, Cunit (Unum));
2461 Set_Corresponding_Spec
2462 (Withn, Specification (Unit (Cunit (Unum))));
2463 Prepend (Withn, Context_Items (Parent (N)));
2464 Mark_Rewrite_Insertion (Withn);
2466 Expand_Limited_With_Clause (Prefix (Nam), N);
2470 New_Nodes_OK := New_Nodes_OK - 1;
2471 end Expand_Limited_With_Clause;
2473 -----------------------
2474 -- Get_Parent_Entity --
2475 -----------------------
2477 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
2479 if Nkind (Unit) = N_Package_Instantiation then
2480 return Defining_Entity (Specification (Instance_Spec (Unit)));
2482 return Defining_Entity (Unit);
2484 end Get_Parent_Entity;
2486 -----------------------------
2487 -- Implicit_With_On_Parent --
2488 -----------------------------
2490 procedure Implicit_With_On_Parent
2491 (Child_Unit : Node_Id;
2494 Loc : constant Source_Ptr := Sloc (N);
2495 P : constant Node_Id := Parent_Spec (Child_Unit);
2496 P_Unit : constant Node_Id := Unit (P);
2497 P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
2500 function Build_Ancestor_Name (P : Node_Id) return Node_Id;
2501 -- Build prefix of child unit name. Recurse if needed.
2503 function Build_Unit_Name return Node_Id;
2504 -- If the unit is a child unit, build qualified name with all
2507 -------------------------
2508 -- Build_Ancestor_Name --
2509 -------------------------
2511 function Build_Ancestor_Name (P : Node_Id) return Node_Id is
2512 P_Ref : constant Node_Id :=
2513 New_Reference_To (Defining_Entity (P), Loc);
2515 if No (Parent_Spec (P)) then
2519 Make_Selected_Component (Loc,
2520 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P))),
2521 Selector_Name => P_Ref);
2523 end Build_Ancestor_Name;
2525 ---------------------
2526 -- Build_Unit_Name --
2527 ---------------------
2529 function Build_Unit_Name return Node_Id is
2532 if No (Parent_Spec (P_Unit)) then
2533 return New_Reference_To (P_Name, Loc);
2536 Make_Expanded_Name (Loc,
2537 Chars => Chars (P_Name),
2538 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
2539 Selector_Name => New_Reference_To (P_Name, Loc));
2540 Set_Entity (Result, P_Name);
2543 end Build_Unit_Name;
2545 -- Start of processing for Implicit_With_On_Parent
2548 New_Nodes_OK := New_Nodes_OK + 1;
2549 Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
2551 Set_Library_Unit (Withn, P);
2552 Set_Corresponding_Spec (Withn, P_Name);
2553 Set_First_Name (Withn, True);
2554 Set_Implicit_With (Withn, True);
2556 -- Node is placed at the beginning of the context items, so that
2557 -- subsequent use clauses on the parent can be validated.
2559 Prepend (Withn, Context_Items (N));
2560 Mark_Rewrite_Insertion (Withn);
2561 Install_Withed_Unit (Withn);
2563 if Is_Child_Spec (P_Unit) then
2564 Implicit_With_On_Parent (P_Unit, N);
2567 New_Nodes_OK := New_Nodes_OK - 1;
2568 end Implicit_With_On_Parent;
2570 ---------------------
2571 -- Install_Context --
2572 ---------------------
2574 procedure Install_Context (N : Node_Id) is
2575 Lib_Unit : constant Node_Id := Unit (N);
2578 Install_Context_Clauses (N);
2580 if Is_Child_Spec (Lib_Unit) then
2581 Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit)));
2584 Install_Limited_Context_Clauses (N);
2586 Check_With_Type_Clauses (N);
2587 end Install_Context;
2589 -----------------------------
2590 -- Install_Context_Clauses --
2591 -----------------------------
2593 procedure Install_Context_Clauses (N : Node_Id) is
2594 Lib_Unit : constant Node_Id := Unit (N);
2596 Uname_Node : Entity_Id;
2597 Check_Private : Boolean := False;
2598 Decl_Node : Node_Id;
2599 Lib_Parent : Entity_Id;
2602 -- Loop through context clauses to find the with/use clauses.
2603 -- This is done twice, first for everything except limited_with
2604 -- clauses, and then for those, if any are present.
2606 Item := First (Context_Items (N));
2607 while Present (Item) loop
2609 -- Case of explicit WITH clause
2611 if Nkind (Item) = N_With_Clause
2612 and then not Implicit_With (Item)
2614 if Limited_Present (Item) then
2616 -- Limited withed units will be installed later.
2620 -- If Name (Item) is not an entity name, something is wrong, and
2621 -- this will be detected in due course, for now ignore the item
2623 elsif not Is_Entity_Name (Name (Item)) then
2626 elsif No (Entity (Name (Item))) then
2627 Set_Entity (Name (Item), Any_Id);
2631 Uname_Node := Entity (Name (Item));
2633 if Is_Private_Descendant (Uname_Node) then
2634 Check_Private := True;
2637 Install_Withed_Unit (Item);
2639 Decl_Node := Unit_Declaration_Node (Uname_Node);
2641 -- If the unit is a subprogram instance, it appears nested
2642 -- within a package that carries the parent information.
2644 if Is_Generic_Instance (Uname_Node)
2645 and then Ekind (Uname_Node) /= E_Package
2647 Decl_Node := Parent (Parent (Decl_Node));
2650 if Is_Child_Spec (Decl_Node) then
2651 if Nkind (Name (Item)) = N_Expanded_Name then
2652 Expand_With_Clause (Prefix (Name (Item)), N);
2654 -- if not an expanded name, the child unit must be a
2655 -- renaming, nothing to do.
2660 elsif Nkind (Decl_Node) = N_Subprogram_Body
2661 and then not Acts_As_Spec (Parent (Decl_Node))
2662 and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
2664 Implicit_With_On_Parent
2665 (Unit (Library_Unit (Parent (Decl_Node))), N);
2668 -- Check license conditions unless this is a dummy unit
2670 if Sloc (Library_Unit (Item)) /= No_Location then
2671 License_Check : declare
2672 Withl : constant License_Type :=
2673 License (Source_Index
2675 (Library_Unit (Item))));
2677 Unitl : constant License_Type :=
2678 License (Source_Index (Current_Sem_Unit));
2680 procedure License_Error;
2681 -- Signal error of bad license
2687 procedure License_Error is
2690 ("?license of with'ed unit & is incompatible",
2694 -- Start of processing for License_Check
2707 if Withl = Restricted then
2711 when Modified_GPL =>
2712 if Withl = Restricted or else Withl = GPL then
2716 when Unrestricted =>
2722 -- Case of USE PACKAGE clause
2724 elsif Nkind (Item) = N_Use_Package_Clause then
2725 Analyze_Use_Package (Item);
2727 -- Case of USE TYPE clause
2729 elsif Nkind (Item) = N_Use_Type_Clause then
2730 Analyze_Use_Type (Item);
2732 -- Case of WITH TYPE clause
2734 -- A With_Type_Clause is processed when installing the context,
2735 -- because it is a visibility mechanism and does not create a
2736 -- semantic dependence on other units, as a With_Clause does.
2738 elsif Nkind (Item) = N_With_Type_Clause then
2739 Analyze_With_Type_Clause (Item);
2743 elsif Nkind (Item) = N_Pragma then
2751 if Is_Child_Spec (Lib_Unit) then
2753 -- The unit also has implicit withs on its own parents
2755 if No (Context_Items (N)) then
2756 Set_Context_Items (N, New_List);
2759 Implicit_With_On_Parent (Lib_Unit, N);
2762 -- If the unit is a body, the context of the specification must also
2765 if Nkind (Lib_Unit) = N_Package_Body
2766 or else (Nkind (Lib_Unit) = N_Subprogram_Body
2767 and then not Acts_As_Spec (N))
2769 Install_Context (Library_Unit (N));
2771 if Is_Child_Spec (Unit (Library_Unit (N))) then
2773 -- If the unit is the body of a public child unit, the private
2774 -- declarations of the parent must be made visible. If the child
2775 -- unit is private, the private declarations have been installed
2776 -- already in the call to Install_Parents for the spec. Installing
2777 -- private declarations must be done for all ancestors of public
2778 -- child units. In addition, sibling units mentioned in the
2779 -- context clause of the body are directly visible.
2782 Lib_Spec : Node_Id := Unit (Library_Unit (N));
2787 while Is_Child_Spec (Lib_Spec) loop
2788 P := Unit (Parent_Spec (Lib_Spec));
2790 if not (Private_Present (Parent (Lib_Spec))) then
2791 P_Name := Defining_Entity (P);
2792 Install_Private_Declarations (P_Name);
2793 Install_Private_With_Clauses (P_Name);
2794 Set_Use (Private_Declarations (Specification (P)));
2802 -- For a package body, children in context are immediately visible
2804 Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
2807 if Nkind (Lib_Unit) = N_Generic_Package_Declaration
2808 or else Nkind (Lib_Unit) = N_Generic_Subprogram_Declaration
2809 or else Nkind (Lib_Unit) = N_Package_Declaration
2810 or else Nkind (Lib_Unit) = N_Subprogram_Declaration
2812 if Is_Child_Spec (Lib_Unit) then
2813 Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
2814 Set_Is_Private_Descendant
2815 (Defining_Entity (Lib_Unit),
2816 Is_Private_Descendant (Lib_Parent)
2817 or else Private_Present (Parent (Lib_Unit)));
2820 Set_Is_Private_Descendant
2821 (Defining_Entity (Lib_Unit),
2822 Private_Present (Parent (Lib_Unit)));
2826 if Check_Private then
2827 Check_Private_Child_Unit (N);
2829 end Install_Context_Clauses;
2831 -------------------------------------
2832 -- Install_Limited_Context_Clauses --
2833 -------------------------------------
2835 procedure Install_Limited_Context_Clauses (N : Node_Id) is
2838 procedure Check_Parent (P : Node_Id; W : Node_Id);
2839 -- Check that the unlimited view of a given compilation_unit is not
2840 -- already visible in the parents (neither immediately through the
2841 -- context clauses, nor indirectly through "use + renamings").
2843 procedure Check_Private_Limited_Withed_Unit (N : Node_Id);
2844 -- Check that if a limited_with clause of a given compilation_unit
2845 -- mentions a private child of some library unit, then the given
2846 -- compilation_unit shall be the declaration of a private descendant
2847 -- of that library unit.
2849 procedure Check_Withed_Unit (W : Node_Id);
2850 -- Check that a limited with_clause does not appear in the same
2851 -- context_clause as a nonlimited with_clause that mentions
2852 -- the same library.
2854 --------------------
2856 --------------------
2858 procedure Check_Parent (P : Node_Id; W : Node_Id) is
2867 pragma Assert (Nkind (W) = N_With_Clause);
2869 -- Step 1: Check if the unlimited view is installed in the parent
2871 Item := First (Context_Items (P));
2872 while Present (Item) loop
2873 if Nkind (Item) = N_With_Clause
2874 and then not Limited_Present (Item)
2875 and then not Implicit_With (Item)
2876 and then Library_Unit (Item) = Library_Unit (W)
2878 Error_Msg_N ("unlimited view visible in ancestor", W);
2885 -- Step 2: Check "use + renamings"
2887 WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
2888 Spec := Specification (Unit (P));
2890 -- We tried to traverse the list of entities corresponding to the
2891 -- defining entity of the package spec. However, first_entity was
2892 -- found to be 'empty'. Don't know why???
2894 -- Def := Defining_Unit_Name (Spec);
2895 -- Ent := First_Entity (Def);
2897 -- As a workaround we traverse the list of visible declarations ???
2899 Item := First (Visible_Declarations (Spec));
2900 while Present (Item) loop
2902 if Nkind (Item) = N_Use_Package_Clause then
2904 -- Traverse the list of packages
2906 Nam := First (Names (Item));
2908 while Present (Nam) loop
2911 pragma Assert (Present (Parent (E)));
2913 if Nkind (Parent (E))
2914 = N_Package_Renaming_Declaration
2915 and then Renamed_Entity (E) = WEnt
2917 Error_Msg_N ("unlimited view visible through "
2918 & "use_clause + renamings", W);
2921 elsif Nkind (Parent (E)) = N_Package_Specification then
2923 -- The use clause may refer to a local package.
2924 -- Check all the enclosing scopes.
2927 while E2 /= Standard_Standard
2928 and then E2 /= WEnt loop
2933 Error_Msg_N ("unlimited view visible through "
2934 & "use_clause ", W);
2947 -- Recursive call to check all the ancestors
2949 if Is_Child_Spec (Unit (P)) then
2950 Check_Parent (P => Parent_Spec (Unit (P)), W => W);
2954 ---------------------------------------
2955 -- Check_Private_Limited_Withed_Unit --
2956 ---------------------------------------
2958 procedure Check_Private_Limited_Withed_Unit (N : Node_Id) is
2961 Found : Boolean := False;
2964 -- If the current compilation unit is not private we don't
2965 -- need to check anything else.
2967 if not Private_Present (Parent (N)) then
2971 -- Compilation unit of the parent of the withed library unit
2973 P := Parent_Spec (Unit (Library_Unit (N)));
2975 -- Traverse all the ancestors of the current compilation
2976 -- unit to check if it is a descendant of named library unit.
2979 while Present (Parent_Spec (Unit (C))) loop
2980 C := Parent_Spec (Unit (C));
2990 Error_Msg_N ("current unit is not a private descendant"
2991 & " of the withed unit ('R'M 10.1.2(8)", N);
2993 end Check_Private_Limited_Withed_Unit;
2995 -----------------------
2996 -- Check_Withed_Unit --
2997 -----------------------
2999 procedure Check_Withed_Unit (W : Node_Id) is
3003 -- A limited with_clause can not appear in the same context_clause
3004 -- as a nonlimited with_clause which mentions the same library.
3006 Item := First (Context_Items (N));
3007 while Present (Item) loop
3008 if Nkind (Item) = N_With_Clause
3009 and then not Limited_Present (Item)
3010 and then not Implicit_With (Item)
3011 and then Library_Unit (Item) = Library_Unit (W)
3013 Error_Msg_N ("limited and unlimited view "
3014 & "not allowed in the same context clauses", W);
3020 end Check_Withed_Unit;
3022 -- Start of processing for Install_Limited_Context_Clauses
3025 Item := First (Context_Items (N));
3026 while Present (Item) loop
3027 if Nkind (Item) = N_With_Clause
3028 and then Limited_Present (Item)
3031 Check_Withed_Unit (Item);
3033 if Private_Present (Library_Unit (Item)) then
3034 Check_Private_Limited_Withed_Unit (Item);
3037 if Is_Child_Spec (Unit (N)) then
3038 Check_Parent (Parent_Spec (Unit (N)), Item);
3041 Install_Limited_Withed_Unit (Item);
3046 end Install_Limited_Context_Clauses;
3048 ---------------------
3049 -- Install_Parents --
3050 ---------------------
3052 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is
3059 P := Unit (Parent_Spec (Lib_Unit));
3060 P_Name := Get_Parent_Entity (P);
3062 if Etype (P_Name) = Any_Type then
3066 if Ekind (P_Name) = E_Generic_Package
3067 and then Nkind (Lib_Unit) /= N_Generic_Subprogram_Declaration
3068 and then Nkind (Lib_Unit) /= N_Generic_Package_Declaration
3069 and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration
3072 ("child of a generic package must be a generic unit", Lib_Unit);
3074 elsif not Is_Package (P_Name) then
3076 ("parent unit must be package or generic package", Lib_Unit);
3077 raise Unrecoverable_Error;
3079 elsif Present (Renamed_Object (P_Name)) then
3080 Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
3081 raise Unrecoverable_Error;
3083 -- Verify that a child of an instance is itself an instance, or
3084 -- the renaming of one. Given that an instance that is a unit is
3085 -- replaced with a package declaration, check against the original
3088 elsif Nkind (Original_Node (P)) = N_Package_Instantiation
3089 and then Nkind (Lib_Unit)
3090 not in N_Renaming_Declaration
3091 and then Nkind (Original_Node (Lib_Unit))
3092 not in N_Generic_Instantiation
3095 ("child of an instance must be an instance or renaming", Lib_Unit);
3098 -- This is the recursive call that ensures all parents are loaded
3100 if Is_Child_Spec (P) then
3102 Is_Private or else Private_Present (Parent (Lib_Unit)));
3105 -- Now we can install the context for this parent
3107 Install_Context_Clauses (Parent_Spec (Lib_Unit));
3108 Install_Siblings (P_Name, Parent (Lib_Unit));
3110 -- The child unit is in the declarative region of the parent. The
3111 -- parent must therefore appear in the scope stack and be visible,
3112 -- as when compiling the corresponding body. If the child unit is
3113 -- private or it is a package body, private declarations must be
3114 -- accessible as well. Use declarations in the parent must also
3115 -- be installed. Finally, other child units of the same parent that
3116 -- are in the context are immediately visible.
3118 -- Find entity for compilation unit, and set its private descendant
3119 -- status as needed.
3121 E_Name := Defining_Entity (Lib_Unit);
3123 Set_Is_Child_Unit (E_Name);
3125 Set_Is_Private_Descendant (E_Name,
3126 Is_Private_Descendant (P_Name)
3127 or else Private_Present (Parent (Lib_Unit)));
3129 P_Spec := Specification (Unit_Declaration_Node (P_Name));
3132 -- Save current visibility of unit
3134 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
3135 Is_Immediately_Visible (P_Name);
3136 Set_Is_Immediately_Visible (P_Name);
3137 Install_Visible_Declarations (P_Name);
3138 Set_Use (Visible_Declarations (P_Spec));
3140 -- If the parent is a generic unit, its formal part may contain
3141 -- formal packages and use clauses for them.
3143 if Ekind (P_Name) = E_Generic_Package then
3144 Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
3148 or else Private_Present (Parent (Lib_Unit))
3150 Install_Private_Declarations (P_Name);
3151 Install_Private_With_Clauses (P_Name);
3152 Set_Use (Private_Declarations (P_Spec));
3154 end Install_Parents;
3156 ----------------------------------
3157 -- Install_Private_With_Clauses --
3158 ----------------------------------
3160 procedure Install_Private_With_Clauses (P : Entity_Id) is
3161 Decl : constant Node_Id := Unit_Declaration_Node (P);
3165 if Debug_Flag_I then
3166 Write_Str ("install private with clauses of ");
3167 Write_Name (Chars (P));
3171 if Nkind (Parent (Decl)) = N_Compilation_Unit then
3172 Clause := First (Context_Items (Parent (Decl)));
3173 while Present (Clause) loop
3174 if Nkind (Clause) = N_With_Clause
3175 and then Private_Present (Clause)
3177 Install_Withed_Unit (Clause, Private_With_OK => True);
3183 end Install_Private_With_Clauses;
3185 ----------------------
3186 -- Install_Siblings --
3187 ----------------------
3189 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
3194 -- Iterate over explicit with clauses, and check whether the
3195 -- scope of each entity is an ancestor of the current unit.
3197 Item := First (Context_Items (N));
3198 while Present (Item) loop
3199 if Nkind (Item) = N_With_Clause
3200 and then not Implicit_With (Item)
3201 and then not Limited_Present (Item)
3203 Id := Entity (Name (Item));
3205 if Is_Child_Unit (Id)
3206 and then Is_Ancestor_Package (Scope (Id), U_Name)
3208 Set_Is_Immediately_Visible (Id);
3210 -- Ada 0Y (AI-262): Make visible the private entities of
3211 -- private-withed siblings
3213 if Private_Present (Item) then
3214 Install_Private_Declarations (Id);
3217 -- Check for the presence of another unit in the context,
3218 -- that may be inadvertently hidden by the child.
3220 Prev := Current_Entity (Id);
3223 and then Is_Immediately_Visible (Prev)
3224 and then not Is_Child_Unit (Prev)
3230 Clause := First (Context_Items (N));
3232 while Present (Clause) loop
3233 if Nkind (Clause) = N_With_Clause
3234 and then Entity (Name (Clause)) = Prev
3237 ("child unit& hides compilation unit " &
3238 "with the same name?",
3248 -- the With_Clause may be on a grand-child, which makes
3249 -- the child immediately visible.
3251 elsif Is_Child_Unit (Scope (Id))
3252 and then Is_Ancestor_Package (Scope (Scope (Id)), U_Name)
3254 Set_Is_Immediately_Visible (Scope (Id));
3260 end Install_Siblings;
3262 -------------------------------
3263 -- Install_Limited_With_Unit --
3264 -------------------------------
3266 procedure Install_Limited_Withed_Unit (N : Node_Id) is
3267 Unum : constant Unit_Number_Type :=
3268 Get_Source_Unit (Library_Unit (N));
3269 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
3272 Lim_Typ : Entity_Id;
3273 Is_Child_Package : Boolean := False;
3275 function In_Chain (E : Entity_Id) return Boolean;
3276 -- Check that the shadow entity is not already in the homonym
3277 -- chain, for example through a limited_with clause in a parent unit.
3283 function In_Chain (E : Entity_Id) return Boolean is
3284 H : Entity_Id := Current_Entity (E);
3287 while Present (H) loop
3298 -- Start of processing for Install_Limited_Withed_Unit
3301 -- In case of limited with_clause on subprograms, generics, instances,
3302 -- or generic renamings, the corresponding error was previously posted
3303 -- and we have nothing to do here.
3305 case Nkind (P_Unit) is
3307 when N_Package_Declaration =>
3310 when N_Subprogram_Declaration |
3311 N_Generic_Package_Declaration |
3312 N_Generic_Subprogram_Declaration |
3313 N_Package_Instantiation |
3314 N_Function_Instantiation |
3315 N_Procedure_Instantiation |
3316 N_Generic_Package_Renaming_Declaration |
3317 N_Generic_Procedure_Renaming_Declaration |
3318 N_Generic_Function_Renaming_Declaration =>
3322 raise Program_Error;
3325 P := Defining_Unit_Name (Specification (P_Unit));
3327 if Nkind (P) = N_Defining_Program_Unit_Name then
3329 -- Retrieve entity of child package
3331 Is_Child_Package := True;
3332 P := Defining_Identifier (P);
3335 -- A common usage of the limited-with is to have a limited-with
3336 -- in the package spec, and a normal with in its package body.
3339 -- limited with X; -- [1]
3343 -- package body A is ...
3345 -- The compilation of A's body installs the entities of its
3346 -- withed packages (the context clauses found at [2]) and
3347 -- then the context clauses of its specification (found at [1]).
3349 -- As a consequence, at point [1] the specification of X has been
3350 -- analyzed and it is immediately visible. According to the semantics
3351 -- of the limited-with context clauses we don't install the limited
3352 -- view because the full view of X supersedes its limited view.
3354 if Analyzed (Cunit (Unum))
3355 and then (Is_Immediately_Visible (P)
3356 or else (Is_Child_Package
3357 and then Is_Visible_Child_Unit (P)))
3362 if Debug_Flag_I then
3363 Write_Str ("install limited view of ");
3364 Write_Name (Chars (P));
3368 if not Analyzed (Cunit (Unum)) then
3369 Set_Ekind (P, E_Package);
3370 Set_Etype (P, Standard_Void_Type);
3371 Set_Scope (P, Standard_Standard);
3373 -- Place entity on visibility structure
3375 if Current_Entity (P) /= P then
3376 Set_Homonym (P, Current_Entity (P));
3377 Set_Current_Entity (P);
3379 if Debug_Flag_I then
3380 Write_Str (" (homonym) chain ");
3381 Write_Name (Chars (P));
3387 if Is_Child_Package then
3388 Set_Is_Child_Unit (P);
3389 Set_Is_Visible_Child_Unit (P);
3392 Parent_Comp : Node_Id;
3393 Parent_Id : Entity_Id;
3396 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
3397 Parent_Id := Defining_Entity (Unit (Parent_Comp));
3399 Set_Scope (P, Parent_Id);
3405 -- If the unit appears in a previous regular with_clause, the
3406 -- regular entities must be unchained before the shadow ones
3407 -- are made accessible.
3412 Ent := First_Entity (P);
3414 while Present (Ent) loop
3422 -- The package must be visible while the with_type clause is active,
3423 -- because references to the type P.T must resolve in the usual way.
3425 Set_Is_Immediately_Visible (P);
3427 -- Install each incomplete view
3429 Lim_Elmt := First_Elmt (Limited_Views (P));
3431 while Present (Lim_Elmt) loop
3432 Lim_Typ := Node (Lim_Elmt);
3434 if not In_Chain (Lim_Typ) then
3435 Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
3436 Set_Current_Entity (Lim_Typ);
3438 if Debug_Flag_I then
3439 Write_Str (" (homonym) chain ");
3440 Write_Name (Chars (Lim_Typ));
3446 Next_Elmt (Lim_Elmt);
3449 -- The context clause has installed a limited-view, mark it
3450 -- accordingly, to uninstall it when the context is removed.
3452 Set_Limited_View_Installed (N);
3453 Set_From_With_Type (P);
3454 end Install_Limited_Withed_Unit;
3456 -------------------------
3457 -- Install_Withed_Unit --
3458 -------------------------
3460 procedure Install_Withed_Unit
3461 (With_Clause : Node_Id;
3462 Private_With_OK : Boolean := False)
3464 Uname : constant Entity_Id := Entity (Name (With_Clause));
3465 P : constant Entity_Id := Scope (Uname);
3468 -- Ada 0Y (AI-262): Do not install the private withed unit if we are
3469 -- compiling a package declaration and the Private_With_OK flag was not
3470 -- set by the caller. These declarations will be installed later (before
3471 -- analyzing the private part of the package).
3473 if Private_Present (With_Clause)
3474 and then Nkind (Cunit (Current_Sem_Unit)) = N_Package_Declaration
3475 and then not (Private_With_OK)
3480 if Debug_Flag_I then
3481 if Private_Present (With_Clause) then
3482 Write_Str ("install private withed unit ");
3484 Write_Str ("install withed unit ");
3487 Write_Name (Chars (Uname));
3491 -- We do not apply the restrictions to an internal unit unless
3492 -- we are compiling the internal unit as a main unit. This check
3493 -- is also skipped for dummy units (for missing packages).
3495 if Sloc (Uname) /= No_Location
3496 and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
3497 or else Current_Sem_Unit = Main_Unit)
3499 Check_Restricted_Unit
3500 (Unit_Name (Get_Source_Unit (Uname)), With_Clause);
3503 if P /= Standard_Standard then
3505 -- If the unit is not analyzed after analysis of the with clause,
3506 -- and it is an instantiation, then it awaits a body and is the main
3507 -- unit. Its appearance in the context of some other unit indicates
3508 -- a circular dependency (DEC suite perversity).
3510 if not Analyzed (Uname)
3511 and then Nkind (Parent (Uname)) = N_Package_Instantiation
3514 ("instantiation depends on itself", Name (With_Clause));
3516 elsif not Is_Visible_Child_Unit (Uname) then
3517 Set_Is_Visible_Child_Unit (Uname);
3519 if Is_Generic_Instance (Uname)
3520 and then Ekind (Uname) in Subprogram_Kind
3522 -- Set flag as well on the visible entity that denotes the
3523 -- instance, which renames the current one.
3525 Set_Is_Visible_Child_Unit
3527 (Defining_Entity (Unit (Library_Unit (With_Clause)))));
3530 -- The parent unit may have been installed already, and
3531 -- may have appeared in a use clause.
3533 if In_Use (Scope (Uname)) then
3534 Set_Is_Potentially_Use_Visible (Uname);
3537 Set_Context_Installed (With_Clause);
3540 elsif not Is_Immediately_Visible (Uname) then
3541 if not Private_Present (With_Clause)
3542 or else Private_With_OK
3544 Set_Is_Immediately_Visible (Uname);
3547 Set_Context_Installed (With_Clause);
3550 -- A with-clause overrides a with-type clause: there are no restric-
3551 -- tions on the use of package entities.
3553 if Ekind (Uname) = E_Package then
3554 Set_From_With_Type (Uname, False);
3556 end Install_Withed_Unit;
3562 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
3563 K : constant Node_Kind := Nkind (Lib_Unit);
3566 return (K in N_Generic_Declaration or else
3567 K in N_Generic_Instantiation or else
3568 K in N_Generic_Renaming_Declaration or else
3569 K = N_Package_Declaration or else
3570 K = N_Package_Renaming_Declaration or else
3571 K = N_Subprogram_Declaration or else
3572 K = N_Subprogram_Renaming_Declaration)
3573 and then Present (Parent_Spec (Lib_Unit));
3576 -----------------------
3577 -- Load_Needed_Body --
3578 -----------------------
3580 -- N is a generic unit named in a with clause, or else it is
3581 -- a unit that contains a generic unit or an inlined function.
3582 -- In order to perform an instantiation, the body of the unit
3583 -- must be present. If the unit itself is generic, we assume
3584 -- that an instantiation follows, and load and analyze the body
3585 -- unconditionally. This forces analysis of the spec as well.
3587 -- If the unit is not generic, but contains a generic unit, it
3588 -- is loaded on demand, at the point of instantiation (see ch12).
3590 procedure Load_Needed_Body (N : Node_Id; OK : out Boolean) is
3591 Body_Name : Unit_Name_Type;
3592 Unum : Unit_Number_Type;
3594 Save_Style_Check : constant Boolean := Opt.Style_Check;
3595 -- The loading and analysis is done with style checks off
3598 if not GNAT_Mode then
3599 Style_Check := False;
3602 Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
3605 (Load_Name => Body_Name,
3611 if Unum = No_Unit then
3615 Compiler_State := Analyzing; -- reset after load
3617 if not Fatal_Error (Unum) or else Try_Semantics then
3618 if Debug_Flag_L then
3619 Write_Str ("*** Loaded generic body");
3623 Semantics (Cunit (Unum));
3629 Style_Check := Save_Style_Check;
3630 end Load_Needed_Body;
3632 -------------------------
3633 -- Build_Limited_Views --
3634 -------------------------
3636 procedure Build_Limited_Views (N : Node_Id) is
3637 Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N));
3638 P : constant Entity_Id := Cunit_Entity (Unum);
3640 Spec : Node_Id; -- To denote a package specification
3641 Lim_Typ : Entity_Id; -- To denote shadow entities.
3642 Comp_Typ : Entity_Id; -- To denote real entities.
3644 procedure Decorate_Incomplete_Type
3647 -- Add attributes of an incomplete type to a shadow entity. The same
3648 -- attributes are placed on the real entity, so that gigi receives
3649 -- a consistent view.
3651 procedure Decorate_Package_Specification (P : Entity_Id);
3652 -- Add attributes of a package entity to the entity in a package
3655 procedure Decorate_Tagged_Type
3659 -- Set basic attributes of tagged type T, including its class_wide type.
3660 -- The parameters Loc, Scope are used to decorate the class_wide type.
3662 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id);
3663 -- Construct list of shadow entities and attach it to entity of
3664 -- package that is mentioned in a limited_with clause.
3666 function New_Internal_Shadow_Entity
3667 (Kind : Entity_Kind;
3668 Sloc_Value : Source_Ptr;
3669 Id_Char : Character) return Entity_Id;
3670 -- This function is similar to New_Internal_Entity, except that the
3671 -- entity is not added to the scope's list of entities.
3673 ------------------------------
3674 -- Decorate_Incomplete_Type --
3675 ------------------------------
3677 procedure Decorate_Incomplete_Type
3682 Set_Ekind (E, E_Incomplete_Type);
3683 Set_Scope (E, Scop);
3685 Set_Is_First_Subtype (E, True);
3686 Set_Stored_Constraint (E, No_Elist);
3687 Set_Full_View (E, Empty);
3688 Init_Size_Align (E);
3689 end Decorate_Incomplete_Type;
3691 --------------------------
3692 -- Decorate_Tagged_Type --
3693 --------------------------
3695 procedure Decorate_Tagged_Type
3703 Decorate_Incomplete_Type (T, Scop);
3704 Set_Is_Tagged_Type (T);
3706 -- Build corresponding class_wide type, if not previously done
3708 if No (Class_Wide_Type (T)) then
3709 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3711 Set_Ekind (CW, E_Class_Wide_Type);
3713 Set_Scope (CW, Scop);
3714 Set_Is_Tagged_Type (CW);
3715 Set_Is_First_Subtype (CW, True);
3716 Init_Size_Align (CW);
3717 Set_Has_Unknown_Discriminants (CW, True);
3718 Set_Class_Wide_Type (CW, CW);
3719 Set_Equivalent_Type (CW, Empty);
3720 Set_From_With_Type (CW, From_With_Type (T));
3722 Set_Class_Wide_Type (T, CW);
3724 end Decorate_Tagged_Type;
3726 ------------------------------------
3727 -- Decorate_Package_Specification --
3728 ------------------------------------
3730 procedure Decorate_Package_Specification (P : Entity_Id) is
3732 -- Place only the most basic attributes
3734 Set_Ekind (P, E_Package);
3735 Set_Etype (P, Standard_Void_Type);
3736 end Decorate_Package_Specification;
3738 -------------------------
3739 -- New_Internal_Entity --
3740 -------------------------
3742 function New_Internal_Shadow_Entity
3743 (Kind : Entity_Kind;
3744 Sloc_Value : Source_Ptr;
3745 Id_Char : Character) return Entity_Id
3747 N : constant Entity_Id :=
3748 Make_Defining_Identifier (Sloc_Value,
3749 Chars => New_Internal_Name (Id_Char));
3752 Set_Ekind (N, Kind);
3753 Set_Is_Internal (N, True);
3755 if Kind in Type_Kind then
3756 Init_Size_Align (N);
3760 end New_Internal_Shadow_Entity;
3766 -- Could use more comments below ???
3768 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id) is
3769 Analyzed_Unit : constant Boolean := Analyzed (Cunit (Unum));
3770 Is_Tagged : Boolean;
3774 Decl := First (Visible_Declarations (Spec));
3776 while Present (Decl) loop
3777 if Nkind (Decl) = N_Full_Type_Declaration then
3779 Nkind (Type_Definition (Decl)) = N_Record_Definition
3780 and then Tagged_Present (Type_Definition (Decl));
3782 Comp_Typ := Defining_Identifier (Decl);
3784 if not Analyzed_Unit then
3786 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3788 Decorate_Incomplete_Type (Comp_Typ, Scope);
3792 -- Create shadow entity for type
3794 Lim_Typ := New_Internal_Shadow_Entity
3795 (Kind => Ekind (Comp_Typ),
3796 Sloc_Value => Sloc (Comp_Typ),
3799 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3800 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3801 Set_From_With_Type (Lim_Typ);
3804 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3806 Decorate_Incomplete_Type (Lim_Typ, Scope);
3809 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3810 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3812 elsif Nkind (Decl) = N_Private_Type_Declaration
3813 and then Tagged_Present (Decl)
3815 Comp_Typ := Defining_Identifier (Decl);
3817 if not Analyzed_Unit then
3818 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3821 Lim_Typ := New_Internal_Shadow_Entity
3822 (Kind => Ekind (Comp_Typ),
3823 Sloc_Value => Sloc (Comp_Typ),
3826 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3827 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3828 Set_From_With_Type (Lim_Typ);
3830 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3832 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3833 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3835 elsif Nkind (Decl) = N_Package_Declaration then
3840 Spec : constant Node_Id := Specification (Decl);
3843 Comp_Typ := Defining_Unit_Name (Spec);
3845 if not Analyzed (Cunit (Unum)) then
3846 Decorate_Package_Specification (Comp_Typ);
3847 Set_Scope (Comp_Typ, Scope);
3850 Lim_Typ := New_Internal_Shadow_Entity
3851 (Kind => Ekind (Comp_Typ),
3852 Sloc_Value => Sloc (Comp_Typ),
3855 Decorate_Package_Specification (Lim_Typ);
3856 Set_Scope (Lim_Typ, Scope);
3858 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3859 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3860 Set_From_With_Type (Lim_Typ);
3862 -- Note: The non_limited_view attribute is not used
3863 -- for local packages.
3865 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3867 Build_Chain (Spec, Scope => Lim_Typ);
3875 -- Start of processing for Build_Limited_Views
3878 pragma Assert (Limited_Present (N));
3880 -- A library_item mentioned in a limited_with_clause shall be
3881 -- a package_declaration, not a subprogram_declaration,
3882 -- generic_declaration, generic_instantiation, or
3883 -- package_renaming_declaration
3885 case Nkind (Unit (Library_Unit (N))) is
3887 when N_Package_Declaration =>
3890 when N_Subprogram_Declaration =>
3891 Error_Msg_N ("subprograms not allowed in "
3892 & "limited with_clauses", N);
3895 when N_Generic_Package_Declaration |
3896 N_Generic_Subprogram_Declaration =>
3897 Error_Msg_N ("generics not allowed in "
3898 & "limited with_clauses", N);
3901 when N_Package_Instantiation |
3902 N_Function_Instantiation |
3903 N_Procedure_Instantiation =>
3904 Error_Msg_N ("generic instantiations not allowed in "
3905 & "limited with_clauses", N);
3908 when N_Generic_Package_Renaming_Declaration |
3909 N_Generic_Procedure_Renaming_Declaration |
3910 N_Generic_Function_Renaming_Declaration =>
3911 Error_Msg_N ("generic renamings not allowed in "
3912 & "limited with_clauses", N);
3916 raise Program_Error;
3919 -- Check if the chain is already built
3921 Spec := Specification (Unit (Library_Unit (N)));
3923 if Limited_View_Installed (Spec) then
3927 Set_Ekind (P, E_Package);
3928 Set_Limited_Views (P, New_Elmt_List);
3929 -- Set_Entity (Name (N), P);
3931 -- Create the auxiliary chain
3933 Build_Chain (Spec, Scope => P);
3934 Set_Limited_View_Installed (Spec);
3935 end Build_Limited_Views;
3937 -------------------------------
3938 -- Check_Body_Needed_For_SAL --
3939 -------------------------------
3941 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
3943 function Entity_Needs_Body (E : Entity_Id) return Boolean;
3944 -- Determine whether use of entity E might require the presence
3945 -- of its body. For a package this requires a recursive traversal
3946 -- of all nested declarations.
3948 ---------------------------
3949 -- Entity_Needed_For_SAL --
3950 ---------------------------
3952 function Entity_Needs_Body (E : Entity_Id) return Boolean is
3956 if Is_Subprogram (E)
3957 and then Has_Pragma_Inline (E)
3961 elsif Ekind (E) = E_Generic_Function
3962 or else Ekind (E) = E_Generic_Procedure
3966 elsif Ekind (E) = E_Generic_Package
3968 Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
3969 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3973 elsif Ekind (E) = E_Package
3975 Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
3976 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3978 Ent := First_Entity (E);
3980 while Present (Ent) loop
3981 if Entity_Needs_Body (Ent) then
3993 end Entity_Needs_Body;
3995 -- Start of processing for Check_Body_Needed_For_SAL
3998 if Ekind (Unit_Name) = E_Generic_Package
4000 Nkind (Unit_Declaration_Node (Unit_Name)) =
4001 N_Generic_Package_Declaration
4003 Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
4005 Set_Body_Needed_For_SAL (Unit_Name);
4007 elsif Ekind (Unit_Name) = E_Generic_Procedure
4008 or else Ekind (Unit_Name) = E_Generic_Function
4010 Set_Body_Needed_For_SAL (Unit_Name);
4012 elsif Is_Subprogram (Unit_Name)
4013 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
4014 N_Subprogram_Declaration
4015 and then Has_Pragma_Inline (Unit_Name)
4017 Set_Body_Needed_For_SAL (Unit_Name);
4019 elsif Ekind (Unit_Name) = E_Subprogram_Body then
4020 Check_Body_Needed_For_SAL
4021 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
4023 elsif Ekind (Unit_Name) = E_Package
4024 and then Entity_Needs_Body (Unit_Name)
4026 Set_Body_Needed_For_SAL (Unit_Name);
4028 elsif Ekind (Unit_Name) = E_Package_Body
4029 and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
4031 Check_Body_Needed_For_SAL
4032 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
4034 end Check_Body_Needed_For_SAL;
4036 --------------------
4037 -- Remove_Context --
4038 --------------------
4040 procedure Remove_Context (N : Node_Id) is
4041 Lib_Unit : constant Node_Id := Unit (N);
4044 -- If this is a child unit, first remove the parent units.
4046 if Is_Child_Spec (Lib_Unit) then
4047 Remove_Parents (Lib_Unit);
4050 Remove_Context_Clauses (N);
4053 ----------------------------
4054 -- Remove_Context_Clauses --
4055 ----------------------------
4057 procedure Remove_Context_Clauses (N : Node_Id) is
4059 Unit_Name : Entity_Id;
4062 -- Ada0Y (AI-50217): We remove the context clauses in two phases:
4063 -- limited-views first and regular-views later (to maintain the
4066 -- First Phase: Remove limited_with context clauses
4068 Item := First (Context_Items (N));
4069 while Present (Item) loop
4071 -- We are interested only in with clauses which got installed
4074 if Nkind (Item) = N_With_Clause
4075 and then Limited_Present (Item)
4076 and then Limited_View_Installed (Item)
4078 Remove_Limited_With_Clause (Item);
4085 -- Second Phase: Loop through context items and undo regular
4086 -- with_clauses and use_clauses.
4088 Item := First (Context_Items (N));
4089 while Present (Item) loop
4091 -- We are interested only in with clauses which got installed
4092 -- on entry, as indicated by their Context_Installed flag set
4094 if Nkind (Item) = N_With_Clause
4095 and then Limited_Present (Item)
4096 and then Limited_View_Installed (Item)
4100 elsif Nkind (Item) = N_With_Clause
4101 and then Context_Installed (Item)
4103 -- Remove items from one with'ed unit
4105 Unit_Name := Entity (Name (Item));
4106 Remove_Unit_From_Visibility (Unit_Name);
4107 Set_Context_Installed (Item, False);
4109 elsif Nkind (Item) = N_Use_Package_Clause then
4110 End_Use_Package (Item);
4112 elsif Nkind (Item) = N_Use_Type_Clause then
4113 End_Use_Type (Item);
4115 elsif Nkind (Item) = N_With_Type_Clause then
4116 Remove_With_Type_Clause (Name (Item));
4121 end Remove_Context_Clauses;
4123 --------------------------------
4124 -- Remove_Limited_With_Clause --
4125 --------------------------------
4127 procedure Remove_Limited_With_Clause (N : Node_Id) is
4128 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
4129 P : Entity_Id := Defining_Unit_Name (Specification (P_Unit));
4131 Lim_Typ : Entity_Id;
4134 if Nkind (P) = N_Defining_Program_Unit_Name then
4136 -- Retrieve entity of Child package
4138 P := Defining_Identifier (P);
4141 if Debug_Flag_I then
4142 Write_Str ("remove limited view of ");
4143 Write_Name (Chars (P));
4144 Write_Str (" from visibility");
4148 -- Remove all shadow entities from visibility
4150 Lim_Elmt := First_Elmt (Limited_Views (P));
4152 while Present (Lim_Elmt) loop
4153 Lim_Typ := Node (Lim_Elmt);
4156 Next_Elmt (Lim_Elmt);
4159 -- Indicate that the limited view of the package is not installed
4161 Set_From_With_Type (P, False);
4162 Set_Limited_View_Installed (N, False);
4164 -- If the exporting package has previously been analyzed, it
4165 -- has appeared in the closure already and should be left alone.
4166 -- Otherwise, remove package itself from visibility.
4168 if not Analyzed (P_Unit) then
4170 Set_First_Entity (P, Empty);
4171 Set_Last_Entity (P, Empty);
4172 Set_Ekind (P, E_Void);
4173 Set_Scope (P, Empty);
4174 Set_Is_Immediately_Visible (P, False);
4178 -- Reinstall visible entities (entities removed from visibility in
4179 -- Install_Limited_Withed to install the shadow entities).
4185 Ent := First_Entity (P);
4186 while Present (Ent) and then Ent /= First_Private_Entity (P) loop
4188 -- Shadow entities have not been added to the list of
4189 -- entities associated to the package spec. Therefore we
4190 -- just have to re-chain all its visible entities.
4192 if not Is_Class_Wide_Type (Ent) then
4194 Set_Homonym (Ent, Current_Entity (Ent));
4195 Set_Current_Entity (Ent);
4197 if Debug_Flag_I then
4198 Write_Str (" (homonym) chain ");
4199 Write_Name (Chars (Ent));
4209 end Remove_Limited_With_Clause;
4211 --------------------
4212 -- Remove_Parents --
4213 --------------------
4215 procedure Remove_Parents (Lib_Unit : Node_Id) is
4219 Vis : constant Boolean :=
4220 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
4223 if Is_Child_Spec (Lib_Unit) then
4224 P := Unit (Parent_Spec (Lib_Unit));
4225 P_Name := Get_Parent_Entity (P);
4227 Remove_Context_Clauses (Parent_Spec (Lib_Unit));
4228 End_Package_Scope (P_Name);
4229 Set_Is_Immediately_Visible (P_Name, Vis);
4231 -- Remove from visibility the siblings as well, which are directly
4232 -- visible while the parent is in scope.
4234 E := First_Entity (P_Name);
4236 while Present (E) loop
4238 if Is_Child_Unit (E) then
4239 Set_Is_Immediately_Visible (E, False);
4245 Set_In_Package_Body (P_Name, False);
4247 -- This is the recursive call to remove the context of any
4248 -- higher level parent. This recursion ensures that all parents
4249 -- are removed in the reverse order of their installation.
4255 -----------------------------
4256 -- Remove_With_Type_Clause --
4257 -----------------------------
4259 procedure Remove_With_Type_Clause (Name : Node_Id) is
4263 procedure Unchain (E : Entity_Id);
4264 -- Remove entity from visibility list.
4266 procedure Unchain (E : Entity_Id) is
4270 Prev := Current_Entity (E);
4272 -- Package entity may appear is several with_type_clauses, and
4273 -- may have been removed already.
4279 Set_Name_Entity_Id (Chars (E), Homonym (E));
4282 while Present (Prev)
4283 and then Homonym (Prev) /= E
4285 Prev := Homonym (Prev);
4288 if Present (Prev) then
4289 Set_Homonym (Prev, Homonym (E));
4294 -- Start of Remove_With_Type_Clause
4297 if Nkind (Name) = N_Selected_Component then
4298 Typ := Entity (Selector_Name (Name));
4300 if No (Typ) then -- error in declaration.
4309 -- If the exporting package has been analyzed, it has appeared in the
4310 -- context already and should be left alone. Otherwise, remove from
4313 if not Analyzed (Unit_Declaration_Node (P)) then
4316 Set_Is_Frozen (Typ, False);
4319 if Ekind (Typ) = E_Record_Type then
4320 Set_From_With_Type (Class_Wide_Type (Typ), False);
4321 Set_From_With_Type (Typ, False);
4324 Set_From_With_Type (P, False);
4326 -- If P is a child unit, remove parents as well.
4331 and then P /= Standard_Standard
4333 Set_From_With_Type (P, False);
4335 if not Analyzed (Unit_Declaration_Node (P)) then
4342 -- The back-end needs to know that an access type is imported, so it
4343 -- does not need elaboration and can appear in a mutually recursive
4344 -- record definition, so the imported flag on an access type is
4347 end Remove_With_Type_Clause;
4349 ---------------------------------
4350 -- Remove_Unit_From_Visibility --
4351 ---------------------------------
4353 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
4354 P : constant Entity_Id := Scope (Unit_Name);
4358 if Debug_Flag_I then
4359 Write_Str ("remove unit ");
4360 Write_Name (Chars (Unit_Name));
4361 Write_Str (" from visibility");
4365 if P /= Standard_Standard then
4366 Set_Is_Visible_Child_Unit (Unit_Name, False);
4369 Set_Is_Potentially_Use_Visible (Unit_Name, False);
4370 Set_Is_Immediately_Visible (Unit_Name, False);
4372 end Remove_Unit_From_Visibility;
4378 procedure Unchain (E : Entity_Id) is
4382 Prev := Current_Entity (E);
4388 Set_Name_Entity_Id (Chars (E), Homonym (E));
4391 while Present (Prev)
4392 and then Homonym (Prev) /= E
4394 Prev := Homonym (Prev);
4397 if Present (Prev) then
4398 Set_Homonym (Prev, Homonym (E));
4402 if Debug_Flag_I then
4403 Write_Str (" (homonym) unchain ");
4404 Write_Name (Chars (E));