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.
1815 end Analyze_With_Clause;
1817 ------------------------------
1818 -- Analyze_With_Type_Clause --
1819 ------------------------------
1821 procedure Analyze_With_Type_Clause (N : Node_Id) is
1822 Loc : constant Source_Ptr := Sloc (N);
1823 Nam : constant Node_Id := Name (N);
1827 Unum : Unit_Number_Type;
1830 procedure Decorate_Tagged_Type (T : Entity_Id);
1831 -- Set basic attributes of type, including its class_wide type.
1833 function In_Chain (E : Entity_Id) return Boolean;
1834 -- Check that the imported type is not already in the homonym chain,
1835 -- for example through a with_type clause in a parent unit.
1837 --------------------------
1838 -- Decorate_Tagged_Type --
1839 --------------------------
1841 procedure Decorate_Tagged_Type (T : Entity_Id) is
1845 Set_Ekind (T, E_Record_Type);
1846 Set_Is_Tagged_Type (T);
1848 Set_From_With_Type (T);
1851 if not In_Chain (T) then
1852 Set_Homonym (T, Current_Entity (T));
1853 Set_Current_Entity (T);
1856 -- Build bogus class_wide type, if not previously done.
1858 if No (Class_Wide_Type (T)) then
1859 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
1861 Set_Ekind (CW, E_Class_Wide_Type);
1864 Set_Is_Tagged_Type (CW);
1865 Set_Is_First_Subtype (CW, True);
1866 Init_Size_Align (CW);
1867 Set_Has_Unknown_Discriminants
1869 Set_Class_Wide_Type (CW, CW);
1870 Set_Equivalent_Type (CW, Empty);
1871 Set_From_With_Type (CW);
1873 Set_Class_Wide_Type (T, CW);
1875 end Decorate_Tagged_Type;
1881 function In_Chain (E : Entity_Id) return Boolean is
1882 H : Entity_Id := Current_Entity (E);
1885 while Present (H) loop
1897 -- Start of processing for Analyze_With_Type_Clause
1900 if Nkind (Nam) = N_Selected_Component then
1901 Pack := New_Copy_Tree (Prefix (Nam));
1902 Sel := Selector_Name (Nam);
1905 Error_Msg_N ("illegal name for imported type", Nam);
1910 Make_Package_Declaration (Loc,
1912 (Make_Package_Specification (Loc,
1913 Defining_Unit_Name => Pack,
1914 Visible_Declarations => New_List,
1915 End_Label => Empty)));
1919 (Load_Name => Get_Unit_Name (Decl),
1925 or else Nkind (Unit (Cunit (Unum))) /= N_Package_Declaration
1927 Error_Msg_N ("imported type must be declared in package", Nam);
1930 elsif Unum = Current_Sem_Unit then
1932 -- If type is defined in unit being analyzed, then the clause
1938 P := Cunit_Entity (Unum);
1941 -- Find declaration for imported type, and set its basic attributes
1942 -- if it has not been analyzed (which will be the case if there is
1943 -- circular dependence).
1950 if not Analyzed (Cunit (Unum))
1951 and then not From_With_Type (P)
1953 Set_Ekind (P, E_Package);
1954 Set_Etype (P, Standard_Void_Type);
1955 Set_From_With_Type (P);
1956 Set_Scope (P, Standard_Standard);
1957 Set_Homonym (P, Current_Entity (P));
1958 Set_Current_Entity (P);
1960 elsif Analyzed (Cunit (Unum))
1961 and then Is_Child_Unit (P)
1963 -- If the child unit is already in scope, indicate that it is
1964 -- visible, and remains so after intervening calls to rtsfind.
1966 Set_Is_Visible_Child_Unit (P);
1969 if Nkind (Parent (P)) = N_Defining_Program_Unit_Name then
1971 -- Make parent packages visible.
1974 Parent_Comp : Node_Id;
1975 Parent_Id : Entity_Id;
1980 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
1983 Parent_Id := Defining_Entity (Unit (Parent_Comp));
1984 Set_Scope (Child, Parent_Id);
1986 -- The type may be imported from a child unit, in which
1987 -- case the current compilation appears in the name. Do
1988 -- not change its visibility here because it will conflict
1989 -- with the subsequent normal processing.
1991 if not Analyzed (Unit_Declaration_Node (Parent_Id))
1992 and then Parent_Id /= Cunit_Entity (Current_Sem_Unit)
1994 Set_Ekind (Parent_Id, E_Package);
1995 Set_Etype (Parent_Id, Standard_Void_Type);
1997 -- The same package may appear is several with_type
2000 if not From_With_Type (Parent_Id) then
2001 Set_Homonym (Parent_Id, Current_Entity (Parent_Id));
2002 Set_Current_Entity (Parent_Id);
2003 Set_From_With_Type (Parent_Id);
2007 Set_Is_Immediately_Visible (Parent_Id);
2010 Parent_Comp := Parent_Spec (Unit (Parent_Comp));
2011 exit when No (Parent_Comp);
2014 Set_Scope (Parent_Id, Standard_Standard);
2018 -- Even if analyzed, the package may not be currently visible. It
2019 -- must be while the with_type clause is active.
2021 Set_Is_Immediately_Visible (P);
2024 First (Visible_Declarations (Specification (Unit (Cunit (Unum)))));
2026 while Present (Decl) loop
2028 if Nkind (Decl) = N_Full_Type_Declaration
2029 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2031 Typ := Defining_Identifier (Decl);
2033 if Tagged_Present (N) then
2035 -- The declaration must indicate that this is a tagged
2036 -- type or a type extension.
2038 if (Nkind (Type_Definition (Decl)) = N_Record_Definition
2039 and then Tagged_Present (Type_Definition (Decl)))
2041 (Nkind (Type_Definition (Decl))
2042 = N_Derived_Type_Definition
2044 (Record_Extension_Part (Type_Definition (Decl))))
2048 Error_Msg_N ("imported type is not a tagged type", Nam);
2052 if not Analyzed (Decl) then
2054 -- Unit is not currently visible. Add basic attributes
2055 -- to type and build its class-wide type.
2057 Init_Size_Align (Typ);
2058 Decorate_Tagged_Type (Typ);
2062 if Nkind (Type_Definition (Decl))
2063 /= N_Access_To_Object_Definition
2066 ("imported type is not an access type", Nam);
2068 elsif not Analyzed (Decl) then
2069 Set_Ekind (Typ, E_Access_Type);
2070 Set_Etype (Typ, Typ);
2072 Init_Size (Typ, System_Address_Size);
2073 Init_Alignment (Typ);
2074 Set_Directly_Designated_Type (Typ, Standard_Integer);
2075 Set_From_With_Type (Typ);
2077 if not In_Chain (Typ) then
2078 Set_Homonym (Typ, Current_Entity (Typ));
2079 Set_Current_Entity (Typ);
2084 Set_Entity (Sel, Typ);
2087 elsif ((Nkind (Decl) = N_Private_Type_Declaration
2088 and then Tagged_Present (Decl))
2089 or else (Nkind (Decl) = N_Private_Extension_Declaration))
2090 and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
2092 Typ := Defining_Identifier (Decl);
2094 if not Tagged_Present (N) then
2095 Error_Msg_N ("type must be declared tagged", N);
2097 elsif not Analyzed (Decl) then
2098 Decorate_Tagged_Type (Typ);
2101 Set_Entity (Sel, Typ);
2102 Set_From_With_Type (Typ);
2106 Decl := Next (Decl);
2109 Error_Msg_NE ("not a visible access or tagged type in&", Nam, P);
2111 end Analyze_With_Type_Clause;
2113 -----------------------------
2114 -- Check_With_Type_Clauses --
2115 -----------------------------
2117 procedure Check_With_Type_Clauses (N : Node_Id) is
2118 Lib_Unit : constant Node_Id := Unit (N);
2120 procedure Check_Parent_Context (U : Node_Id);
2121 -- Examine context items of parent unit to locate with_type clauses.
2123 --------------------------
2124 -- Check_Parent_Context --
2125 --------------------------
2127 procedure Check_Parent_Context (U : Node_Id) is
2131 Item := First (Context_Items (U));
2132 while Present (Item) loop
2133 if Nkind (Item) = N_With_Type_Clause
2134 and then not Error_Posted (Item)
2136 From_With_Type (Scope (Entity (Selector_Name (Name (Item)))))
2138 Error_Msg_Sloc := Sloc (Item);
2139 Error_Msg_N ("Missing With_Clause for With_Type_Clause#", N);
2144 end Check_Parent_Context;
2146 -- Start of processing for Check_With_Type_Clauses
2149 if Extensions_Allowed
2150 and then (Nkind (Lib_Unit) = N_Package_Body
2151 or else Nkind (Lib_Unit) = N_Subprogram_Body)
2153 Check_Parent_Context (Library_Unit (N));
2154 if Is_Child_Spec (Unit (Library_Unit (N))) then
2155 Check_Parent_Context (Parent_Spec (Unit (Library_Unit (N))));
2158 end Check_With_Type_Clauses;
2160 ------------------------------
2161 -- Check_Private_Child_Unit --
2162 ------------------------------
2164 procedure Check_Private_Child_Unit (N : Node_Id) is
2165 Lib_Unit : constant Node_Id := Unit (N);
2167 Curr_Unit : Entity_Id;
2168 Sub_Parent : Node_Id;
2169 Priv_Child : Entity_Id;
2170 Par_Lib : Entity_Id;
2173 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
2174 -- Returns true if and only if the library unit is declared with
2175 -- an explicit designation of private.
2177 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
2178 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
2181 return Private_Present (Comp_Unit);
2182 end Is_Private_Library_Unit;
2184 -- Start of processing for Check_Private_Child_Unit
2187 if Nkind (Lib_Unit) = N_Package_Body
2188 or else Nkind (Lib_Unit) = N_Subprogram_Body
2190 Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
2191 Par_Lib := Curr_Unit;
2193 elsif Nkind (Lib_Unit) = N_Subunit then
2195 -- The parent is itself a body. The parent entity is to be found
2196 -- in the corresponding spec.
2198 Sub_Parent := Library_Unit (N);
2199 Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
2201 -- If the parent itself is a subunit, Curr_Unit is the entity
2202 -- of the enclosing body, retrieve the spec entity which is
2203 -- the proper ancestor we need for the following tests.
2205 if Ekind (Curr_Unit) = E_Package_Body then
2206 Curr_Unit := Spec_Entity (Curr_Unit);
2209 Par_Lib := Curr_Unit;
2212 Curr_Unit := Defining_Entity (Lib_Unit);
2214 Par_Lib := Curr_Unit;
2215 Par_Spec := Parent_Spec (Lib_Unit);
2217 if No (Par_Spec) then
2220 Par_Lib := Defining_Entity (Unit (Par_Spec));
2224 -- Loop through context items
2226 Item := First (Context_Items (N));
2227 while Present (Item) loop
2229 if Nkind (Item) = N_With_Clause
2230 and then not Implicit_With (Item)
2231 and then Is_Private_Descendant (Entity (Name (Item)))
2233 Priv_Child := Entity (Name (Item));
2236 Curr_Parent : Entity_Id := Par_Lib;
2237 Child_Parent : Entity_Id := Scope (Priv_Child);
2238 Prv_Ancestor : Entity_Id := Child_Parent;
2239 Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
2242 -- If the child unit is a public child then locate
2243 -- the nearest private ancestor; Child_Parent will
2244 -- then be set to the parent of that ancestor.
2246 if not Is_Private_Library_Unit (Priv_Child) then
2247 while Present (Prv_Ancestor)
2248 and then not Is_Private_Library_Unit (Prv_Ancestor)
2250 Prv_Ancestor := Scope (Prv_Ancestor);
2253 if Present (Prv_Ancestor) then
2254 Child_Parent := Scope (Prv_Ancestor);
2258 while Present (Curr_Parent)
2259 and then Curr_Parent /= Standard_Standard
2260 and then Curr_Parent /= Child_Parent
2263 Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
2264 Curr_Parent := Scope (Curr_Parent);
2267 if not Present (Curr_Parent) then
2268 Curr_Parent := Standard_Standard;
2271 if Curr_Parent /= Child_Parent then
2273 if Ekind (Priv_Child) = E_Generic_Package
2274 and then Chars (Priv_Child) in Text_IO_Package_Name
2275 and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
2278 ("& is a nested package, not a compilation unit",
2279 Name (Item), Priv_Child);
2283 ("unit in with clause is private child unit!", Item);
2285 ("current unit must also have parent&!",
2286 Item, Child_Parent);
2289 elsif not Curr_Private
2290 and then Nkind (Lib_Unit) /= N_Package_Body
2291 and then Nkind (Lib_Unit) /= N_Subprogram_Body
2292 and then Nkind (Lib_Unit) /= N_Subunit
2295 ("current unit must also be private descendant of&",
2296 Item, Child_Parent);
2304 end Check_Private_Child_Unit;
2306 ----------------------
2307 -- Check_Stub_Level --
2308 ----------------------
2310 procedure Check_Stub_Level (N : Node_Id) is
2311 Par : constant Node_Id := Parent (N);
2312 Kind : constant Node_Kind := Nkind (Par);
2315 if (Kind = N_Package_Body
2316 or else Kind = N_Subprogram_Body
2317 or else Kind = N_Task_Body
2318 or else Kind = N_Protected_Body)
2320 and then (Nkind (Parent (Par)) = N_Compilation_Unit
2321 or else Nkind (Parent (Par)) = N_Subunit)
2325 -- In an instance, a missing stub appears at any level. A warning
2326 -- message will have been emitted already for the missing file.
2328 elsif not In_Instance then
2329 Error_Msg_N ("stub cannot appear in an inner scope", N);
2331 elsif Expander_Active then
2332 Error_Msg_N ("missing proper body", N);
2334 end Check_Stub_Level;
2336 ------------------------
2337 -- Expand_With_Clause --
2338 ------------------------
2340 procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id) is
2341 Loc : constant Source_Ptr := Sloc (Nam);
2342 Ent : constant Entity_Id := Entity (Nam);
2346 function Build_Unit_Name (Nam : Node_Id) return Node_Id;
2348 function Build_Unit_Name (Nam : Node_Id) return Node_Id is
2352 if Nkind (Nam) = N_Identifier then
2353 return New_Occurrence_Of (Entity (Nam), Loc);
2357 Make_Expanded_Name (Loc,
2358 Chars => Chars (Entity (Nam)),
2359 Prefix => Build_Unit_Name (Prefix (Nam)),
2360 Selector_Name => New_Occurrence_Of (Entity (Nam), Loc));
2361 Set_Entity (Result, Entity (Nam));
2364 end Build_Unit_Name;
2367 New_Nodes_OK := New_Nodes_OK + 1;
2369 Make_With_Clause (Loc, Name => Build_Unit_Name (Nam));
2371 P := Parent (Unit_Declaration_Node (Ent));
2372 Set_Library_Unit (Withn, P);
2373 Set_Corresponding_Spec (Withn, Ent);
2374 Set_First_Name (Withn, True);
2375 Set_Implicit_With (Withn, True);
2377 Prepend (Withn, Context_Items (N));
2378 Mark_Rewrite_Insertion (Withn);
2379 Install_Withed_Unit (Withn);
2381 if Nkind (Nam) = N_Expanded_Name then
2382 Expand_With_Clause (Prefix (Nam), N);
2385 New_Nodes_OK := New_Nodes_OK - 1;
2386 end Expand_With_Clause;
2388 --------------------------------
2389 -- Expand_Limited_With_Clause --
2390 --------------------------------
2392 procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id) is
2393 Loc : constant Source_Ptr := Sloc (Nam);
2394 Unum : Unit_Number_Type;
2398 New_Nodes_OK := New_Nodes_OK + 1;
2400 if Nkind (Nam) = N_Identifier then
2402 Make_With_Clause (Loc, Name => Nam);
2403 Set_Limited_Present (Withn);
2404 Set_First_Name (Withn);
2405 Set_Implicit_With (Withn);
2407 -- Load the corresponding parent unit
2411 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2416 if not Analyzed (Cunit (Unum)) then
2417 Set_Library_Unit (Withn, Cunit (Unum));
2418 Set_Corresponding_Spec
2419 (Withn, Specification (Unit (Cunit (Unum))));
2421 Prepend (Withn, Context_Items (Parent (N)));
2422 Mark_Rewrite_Insertion (Withn);
2425 elsif Nkind (Nam) = N_Selected_Component then
2430 Make_Selected_Component
2432 Prefix => Prefix (Nam),
2433 Selector_Name => Selector_Name (Nam)));
2435 Set_Parent (Withn, Parent (N));
2436 Set_Limited_Present (Withn);
2437 Set_First_Name (Withn);
2438 Set_Implicit_With (Withn);
2442 (Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
2447 if not Analyzed (Cunit (Unum)) then
2448 Set_Library_Unit (Withn, Cunit (Unum));
2449 Set_Corresponding_Spec
2450 (Withn, Specification (Unit (Cunit (Unum))));
2451 Prepend (Withn, Context_Items (Parent (N)));
2452 Mark_Rewrite_Insertion (Withn);
2454 Expand_Limited_With_Clause (Prefix (Nam), N);
2459 pragma Assert (False);
2462 New_Nodes_OK := New_Nodes_OK - 1;
2463 end Expand_Limited_With_Clause;
2465 -----------------------
2466 -- Get_Parent_Entity --
2467 -----------------------
2469 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
2471 if Nkind (Unit) = N_Package_Instantiation then
2472 return Defining_Entity (Specification (Instance_Spec (Unit)));
2474 return Defining_Entity (Unit);
2476 end Get_Parent_Entity;
2478 -----------------------------
2479 -- Implicit_With_On_Parent --
2480 -----------------------------
2482 procedure Implicit_With_On_Parent
2483 (Child_Unit : Node_Id;
2486 Loc : constant Source_Ptr := Sloc (N);
2487 P : constant Node_Id := Parent_Spec (Child_Unit);
2488 P_Unit : constant Node_Id := Unit (P);
2489 P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
2492 function Build_Ancestor_Name (P : Node_Id) return Node_Id;
2493 -- Build prefix of child unit name. Recurse if needed.
2495 function Build_Unit_Name return Node_Id;
2496 -- If the unit is a child unit, build qualified name with all
2499 -------------------------
2500 -- Build_Ancestor_Name --
2501 -------------------------
2503 function Build_Ancestor_Name (P : Node_Id) return Node_Id is
2504 P_Ref : constant Node_Id :=
2505 New_Reference_To (Defining_Entity (P), Loc);
2507 if No (Parent_Spec (P)) then
2511 Make_Selected_Component (Loc,
2512 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P))),
2513 Selector_Name => P_Ref);
2515 end Build_Ancestor_Name;
2517 ---------------------
2518 -- Build_Unit_Name --
2519 ---------------------
2521 function Build_Unit_Name return Node_Id is
2524 if No (Parent_Spec (P_Unit)) then
2525 return New_Reference_To (P_Name, Loc);
2528 Make_Expanded_Name (Loc,
2529 Chars => Chars (P_Name),
2530 Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
2531 Selector_Name => New_Reference_To (P_Name, Loc));
2532 Set_Entity (Result, P_Name);
2535 end Build_Unit_Name;
2537 -- Start of processing for Implicit_With_On_Parent
2540 New_Nodes_OK := New_Nodes_OK + 1;
2541 Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
2543 Set_Library_Unit (Withn, P);
2544 Set_Corresponding_Spec (Withn, P_Name);
2545 Set_First_Name (Withn, True);
2546 Set_Implicit_With (Withn, True);
2548 -- Node is placed at the beginning of the context items, so that
2549 -- subsequent use clauses on the parent can be validated.
2551 Prepend (Withn, Context_Items (N));
2552 Mark_Rewrite_Insertion (Withn);
2553 Install_Withed_Unit (Withn);
2555 if Is_Child_Spec (P_Unit) then
2556 Implicit_With_On_Parent (P_Unit, N);
2559 New_Nodes_OK := New_Nodes_OK - 1;
2560 end Implicit_With_On_Parent;
2562 ---------------------
2563 -- Install_Context --
2564 ---------------------
2566 procedure Install_Context (N : Node_Id) is
2567 Lib_Unit : constant Node_Id := Unit (N);
2570 Install_Context_Clauses (N);
2572 if Is_Child_Spec (Lib_Unit) then
2573 Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit)));
2576 Install_Limited_Context_Clauses (N);
2578 Check_With_Type_Clauses (N);
2579 end Install_Context;
2581 -----------------------------
2582 -- Install_Context_Clauses --
2583 -----------------------------
2585 procedure Install_Context_Clauses (N : Node_Id) is
2586 Lib_Unit : constant Node_Id := Unit (N);
2588 Uname_Node : Entity_Id;
2589 Check_Private : Boolean := False;
2590 Decl_Node : Node_Id;
2591 Lib_Parent : Entity_Id;
2594 -- Loop through context clauses to find the with/use clauses.
2595 -- This is done twice, first for everything except limited_with
2596 -- clauses, and then for those, if any are present.
2598 Item := First (Context_Items (N));
2599 while Present (Item) loop
2601 -- Case of explicit WITH clause
2603 if Nkind (Item) = N_With_Clause
2604 and then not Implicit_With (Item)
2606 if Limited_Present (Item) then
2608 -- Limited withed units will be installed later.
2612 -- If Name (Item) is not an entity name, something is wrong, and
2613 -- this will be detected in due course, for now ignore the item
2615 elsif not Is_Entity_Name (Name (Item)) then
2618 elsif No (Entity (Name (Item))) then
2619 Set_Entity (Name (Item), Any_Id);
2623 Uname_Node := Entity (Name (Item));
2625 if Is_Private_Descendant (Uname_Node) then
2626 Check_Private := True;
2629 Install_Withed_Unit (Item);
2631 Decl_Node := Unit_Declaration_Node (Uname_Node);
2633 -- If the unit is a subprogram instance, it appears nested
2634 -- within a package that carries the parent information.
2636 if Is_Generic_Instance (Uname_Node)
2637 and then Ekind (Uname_Node) /= E_Package
2639 Decl_Node := Parent (Parent (Decl_Node));
2642 if Is_Child_Spec (Decl_Node) then
2643 if Nkind (Name (Item)) = N_Expanded_Name then
2644 Expand_With_Clause (Prefix (Name (Item)), N);
2646 -- if not an expanded name, the child unit must be a
2647 -- renaming, nothing to do.
2652 elsif Nkind (Decl_Node) = N_Subprogram_Body
2653 and then not Acts_As_Spec (Parent (Decl_Node))
2654 and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
2656 Implicit_With_On_Parent
2657 (Unit (Library_Unit (Parent (Decl_Node))), N);
2660 -- Check license conditions unless this is a dummy unit
2662 if Sloc (Library_Unit (Item)) /= No_Location then
2663 License_Check : declare
2664 Withl : constant License_Type :=
2665 License (Source_Index
2667 (Library_Unit (Item))));
2669 Unitl : constant License_Type :=
2670 License (Source_Index (Current_Sem_Unit));
2672 procedure License_Error;
2673 -- Signal error of bad license
2679 procedure License_Error is
2682 ("?license of with'ed unit & is incompatible",
2686 -- Start of processing for License_Check
2699 if Withl = Restricted then
2703 when Modified_GPL =>
2704 if Withl = Restricted or else Withl = GPL then
2708 when Unrestricted =>
2714 -- Case of USE PACKAGE clause
2716 elsif Nkind (Item) = N_Use_Package_Clause then
2717 Analyze_Use_Package (Item);
2719 -- Case of USE TYPE clause
2721 elsif Nkind (Item) = N_Use_Type_Clause then
2722 Analyze_Use_Type (Item);
2724 -- Case of WITH TYPE clause
2726 -- A With_Type_Clause is processed when installing the context,
2727 -- because it is a visibility mechanism and does not create a
2728 -- semantic dependence on other units, as a With_Clause does.
2730 elsif Nkind (Item) = N_With_Type_Clause then
2731 Analyze_With_Type_Clause (Item);
2735 elsif Nkind (Item) = N_Pragma then
2743 if Is_Child_Spec (Lib_Unit) then
2745 -- The unit also has implicit withs on its own parents
2747 if No (Context_Items (N)) then
2748 Set_Context_Items (N, New_List);
2751 Implicit_With_On_Parent (Lib_Unit, N);
2754 -- If the unit is a body, the context of the specification must also
2757 if Nkind (Lib_Unit) = N_Package_Body
2758 or else (Nkind (Lib_Unit) = N_Subprogram_Body
2759 and then not Acts_As_Spec (N))
2761 Install_Context (Library_Unit (N));
2763 if Is_Child_Spec (Unit (Library_Unit (N))) then
2765 -- If the unit is the body of a public child unit, the private
2766 -- declarations of the parent must be made visible. If the child
2767 -- unit is private, the private declarations have been installed
2768 -- already in the call to Install_Parents for the spec. Installing
2769 -- private declarations must be done for all ancestors of public
2770 -- child units. In addition, sibling units mentioned in the
2771 -- context clause of the body are directly visible.
2774 Lib_Spec : Node_Id := Unit (Library_Unit (N));
2779 while Is_Child_Spec (Lib_Spec) loop
2780 P := Unit (Parent_Spec (Lib_Spec));
2782 if not (Private_Present (Parent (Lib_Spec))) then
2783 P_Name := Defining_Entity (P);
2784 Install_Private_Declarations (P_Name);
2785 Install_Private_With_Clauses (P_Name);
2786 Set_Use (Private_Declarations (Specification (P)));
2794 -- For a package body, children in context are immediately visible
2796 Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
2799 if Nkind (Lib_Unit) = N_Generic_Package_Declaration
2800 or else Nkind (Lib_Unit) = N_Generic_Subprogram_Declaration
2801 or else Nkind (Lib_Unit) = N_Package_Declaration
2802 or else Nkind (Lib_Unit) = N_Subprogram_Declaration
2804 if Is_Child_Spec (Lib_Unit) then
2805 Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
2806 Set_Is_Private_Descendant
2807 (Defining_Entity (Lib_Unit),
2808 Is_Private_Descendant (Lib_Parent)
2809 or else Private_Present (Parent (Lib_Unit)));
2812 Set_Is_Private_Descendant
2813 (Defining_Entity (Lib_Unit),
2814 Private_Present (Parent (Lib_Unit)));
2818 if Check_Private then
2819 Check_Private_Child_Unit (N);
2821 end Install_Context_Clauses;
2823 -------------------------------------
2824 -- Install_Limited_Context_Clauses --
2825 -------------------------------------
2827 procedure Install_Limited_Context_Clauses (N : Node_Id) is
2830 procedure Check_Parent (P : Node_Id; W : Node_Id);
2831 -- Check that the unlimited view of a given compilation_unit is not
2832 -- already visible in the parents (neither immediately through the
2833 -- context clauses, nor indirectly through "use + renamings").
2835 procedure Check_Private_Limited_Withed_Unit (N : Node_Id);
2836 -- Check that if a limited_with clause of a given compilation_unit
2837 -- mentions a private child of some library unit, then the given
2838 -- compilation_unit shall be the declaration of a private descendant
2839 -- of that library unit.
2841 procedure Check_Withed_Unit (W : Node_Id);
2842 -- Check that a limited with_clause does not appear in the same
2843 -- context_clause as a nonlimited with_clause that mentions
2844 -- the same library.
2846 --------------------
2848 --------------------
2850 procedure Check_Parent (P : Node_Id; W : Node_Id) is
2859 pragma Assert (Nkind (W) = N_With_Clause);
2861 -- Step 1: Check if the unlimited view is installed in the parent
2863 Item := First (Context_Items (P));
2864 while Present (Item) loop
2865 if Nkind (Item) = N_With_Clause
2866 and then not Limited_Present (Item)
2867 and then not Implicit_With (Item)
2868 and then Library_Unit (Item) = Library_Unit (W)
2870 Error_Msg_N ("unlimited view visible in ancestor", W);
2877 -- Step 2: Check "use + renamings"
2879 WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
2880 Spec := Specification (Unit (P));
2882 -- We tried to traverse the list of entities corresponding to the
2883 -- defining entity of the package spec. However, first_entity was
2884 -- found to be 'empty'. Don't know why???
2886 -- Def := Defining_Unit_Name (Spec);
2887 -- Ent := First_Entity (Def);
2889 -- As a workaround we traverse the list of visible declarations ???
2891 Item := First (Visible_Declarations (Spec));
2892 while Present (Item) loop
2894 if Nkind (Item) = N_Use_Package_Clause then
2896 -- Traverse the list of packages
2898 Nam := First (Names (Item));
2900 while Present (Nam) loop
2903 pragma Assert (Present (Parent (E)));
2905 if Nkind (Parent (E))
2906 = N_Package_Renaming_Declaration
2907 and then Renamed_Entity (E) = WEnt
2909 Error_Msg_N ("unlimited view visible through "
2910 & "use_clause + renamings", W);
2913 elsif Nkind (Parent (E)) = N_Package_Specification then
2915 -- The use clause may refer to a local package.
2916 -- Check all the enclosing scopes.
2919 while E2 /= Standard_Standard
2920 and then E2 /= WEnt loop
2925 Error_Msg_N ("unlimited view visible through "
2926 & "use_clause ", W);
2939 -- Recursive call to check all the ancestors
2941 if Is_Child_Spec (Unit (P)) then
2942 Check_Parent (P => Parent_Spec (Unit (P)), W => W);
2946 ---------------------------------------
2947 -- Check_Private_Limited_Withed_Unit --
2948 ---------------------------------------
2950 procedure Check_Private_Limited_Withed_Unit (N : Node_Id) is
2953 Found : Boolean := False;
2956 -- If the current compilation unit is not private we don't
2957 -- need to check anything else.
2959 if not Private_Present (Parent (N)) then
2963 -- Compilation unit of the parent of the withed library unit
2965 P := Parent_Spec (Unit (Library_Unit (N)));
2967 -- Traverse all the ancestors of the current compilation
2968 -- unit to check if it is a descendant of named library unit.
2971 while Present (Parent_Spec (Unit (C))) loop
2972 C := Parent_Spec (Unit (C));
2982 Error_Msg_N ("current unit is not a private descendant"
2983 & " of the withed unit ('R'M 10.1.2(8)", N);
2985 end Check_Private_Limited_Withed_Unit;
2987 -----------------------
2988 -- Check_Withed_Unit --
2989 -----------------------
2991 procedure Check_Withed_Unit (W : Node_Id) is
2995 -- A limited with_clause can not appear in the same context_clause
2996 -- as a nonlimited with_clause which mentions the same library.
2998 Item := First (Context_Items (N));
2999 while Present (Item) loop
3000 if Nkind (Item) = N_With_Clause
3001 and then not Limited_Present (Item)
3002 and then not Implicit_With (Item)
3003 and then Library_Unit (Item) = Library_Unit (W)
3005 Error_Msg_N ("limited and unlimited view "
3006 & "not allowed in the same context clauses", W);
3012 end Check_Withed_Unit;
3014 -- Start of processing for Install_Limited_Context_Clauses
3017 Item := First (Context_Items (N));
3018 while Present (Item) loop
3019 if Nkind (Item) = N_With_Clause
3020 and then Limited_Present (Item)
3023 Check_Withed_Unit (Item);
3025 if Private_Present (Library_Unit (Item)) then
3026 Check_Private_Limited_Withed_Unit (Item);
3029 if Is_Child_Spec (Unit (N)) then
3030 Check_Parent (Parent_Spec (Unit (N)), Item);
3033 Install_Limited_Withed_Unit (Item);
3038 end Install_Limited_Context_Clauses;
3040 ---------------------
3041 -- Install_Parents --
3042 ---------------------
3044 procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is
3051 P := Unit (Parent_Spec (Lib_Unit));
3052 P_Name := Get_Parent_Entity (P);
3054 if Etype (P_Name) = Any_Type then
3058 if Ekind (P_Name) = E_Generic_Package
3059 and then Nkind (Lib_Unit) /= N_Generic_Subprogram_Declaration
3060 and then Nkind (Lib_Unit) /= N_Generic_Package_Declaration
3061 and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration
3064 ("child of a generic package must be a generic unit", Lib_Unit);
3066 elsif not Is_Package (P_Name) then
3068 ("parent unit must be package or generic package", Lib_Unit);
3069 raise Unrecoverable_Error;
3071 elsif Present (Renamed_Object (P_Name)) then
3072 Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
3073 raise Unrecoverable_Error;
3075 -- Verify that a child of an instance is itself an instance, or
3076 -- the renaming of one. Given that an instance that is a unit is
3077 -- replaced with a package declaration, check against the original
3080 elsif Nkind (Original_Node (P)) = N_Package_Instantiation
3081 and then Nkind (Lib_Unit)
3082 not in N_Renaming_Declaration
3083 and then Nkind (Original_Node (Lib_Unit))
3084 not in N_Generic_Instantiation
3087 ("child of an instance must be an instance or renaming", Lib_Unit);
3090 -- This is the recursive call that ensures all parents are loaded
3092 if Is_Child_Spec (P) then
3094 Is_Private or else Private_Present (Parent (Lib_Unit)));
3097 -- Now we can install the context for this parent
3099 Install_Context_Clauses (Parent_Spec (Lib_Unit));
3100 Install_Siblings (P_Name, Parent (Lib_Unit));
3102 -- The child unit is in the declarative region of the parent. The
3103 -- parent must therefore appear in the scope stack and be visible,
3104 -- as when compiling the corresponding body. If the child unit is
3105 -- private or it is a package body, private declarations must be
3106 -- accessible as well. Use declarations in the parent must also
3107 -- be installed. Finally, other child units of the same parent that
3108 -- are in the context are immediately visible.
3110 -- Find entity for compilation unit, and set its private descendant
3111 -- status as needed.
3113 E_Name := Defining_Entity (Lib_Unit);
3115 Set_Is_Child_Unit (E_Name);
3117 Set_Is_Private_Descendant (E_Name,
3118 Is_Private_Descendant (P_Name)
3119 or else Private_Present (Parent (Lib_Unit)));
3121 P_Spec := Specification (Unit_Declaration_Node (P_Name));
3124 -- Save current visibility of unit
3126 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
3127 Is_Immediately_Visible (P_Name);
3128 Set_Is_Immediately_Visible (P_Name);
3129 Install_Visible_Declarations (P_Name);
3130 Set_Use (Visible_Declarations (P_Spec));
3132 -- If the parent is a generic unit, its formal part may contain
3133 -- formal packages and use clauses for them.
3135 if Ekind (P_Name) = E_Generic_Package then
3136 Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
3140 or else Private_Present (Parent (Lib_Unit))
3142 Install_Private_Declarations (P_Name);
3143 Install_Private_With_Clauses (P_Name);
3144 Set_Use (Private_Declarations (P_Spec));
3146 end Install_Parents;
3148 ----------------------------------
3149 -- Install_Private_With_Clauses --
3150 ----------------------------------
3152 procedure Install_Private_With_Clauses (P : Entity_Id) is
3153 Decl : constant Node_Id := Unit_Declaration_Node (P);
3157 if Nkind (Parent (Decl)) = N_Compilation_Unit then
3158 Clause := First (Context_Items (Parent (Decl)));
3159 while Present (Clause) loop
3160 if Nkind (Clause) = N_With_Clause
3161 and then Private_Present (Clause)
3163 Install_Withed_Unit (Clause, Private_With_OK => True);
3169 end Install_Private_With_Clauses;
3171 ----------------------
3172 -- Install_Siblings --
3173 ----------------------
3175 procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
3180 function Is_Ancestor (E : Entity_Id) return Boolean;
3181 -- Determine whether the scope of a child unit is an ancestor of
3182 -- the current unit.
3183 -- Shouldn't this be somewhere more general ???
3189 function Is_Ancestor (E : Entity_Id) return Boolean is
3195 and then Par /= Standard_Standard
3207 -- Start of processing for Install_Siblings
3210 -- Iterate over explicit with clauses, and check whether the
3211 -- scope of each entity is an ancestor of the current unit.
3213 Item := First (Context_Items (N));
3214 while Present (Item) loop
3215 if Nkind (Item) = N_With_Clause
3216 and then not Implicit_With (Item)
3217 and then not Limited_Present (Item)
3219 Id := Entity (Name (Item));
3221 if Is_Child_Unit (Id)
3222 and then Is_Ancestor (Scope (Id))
3224 Set_Is_Immediately_Visible (Id);
3225 Prev := Current_Entity (Id);
3227 -- Check for the presence of another unit in the context,
3228 -- that may be inadvertently hidden by the child.
3231 and then Is_Immediately_Visible (Prev)
3232 and then not Is_Child_Unit (Prev)
3238 Clause := First (Context_Items (N));
3240 while Present (Clause) loop
3241 if Nkind (Clause) = N_With_Clause
3242 and then Entity (Name (Clause)) = Prev
3245 ("child unit& hides compilation unit " &
3246 "with the same name?",
3256 -- the With_Clause may be on a grand-child, which makes
3257 -- the child immediately visible.
3259 elsif Is_Child_Unit (Scope (Id))
3260 and then Is_Ancestor (Scope (Scope (Id)))
3262 Set_Is_Immediately_Visible (Scope (Id));
3268 end Install_Siblings;
3270 -------------------------------
3271 -- Install_Limited_With_Unit --
3272 -------------------------------
3274 procedure Install_Limited_Withed_Unit (N : Node_Id) is
3275 Unum : constant Unit_Number_Type :=
3276 Get_Source_Unit (Library_Unit (N));
3277 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
3280 Lim_Typ : Entity_Id;
3281 Is_Child_Package : Boolean := False;
3283 function In_Chain (E : Entity_Id) return Boolean;
3284 -- Check that the shadow entity is not already in the homonym
3285 -- chain, for example through a limited_with clause in a parent unit.
3291 function In_Chain (E : Entity_Id) return Boolean is
3292 H : Entity_Id := Current_Entity (E);
3295 while Present (H) loop
3306 -- Start of processing for Install_Limited_Withed_Unit
3309 -- In case of limited with_clause on subprograms, generics, instances,
3310 -- or generic renamings, the corresponding error was previously posted
3311 -- and we have nothing to do here.
3313 case Nkind (P_Unit) is
3315 when N_Package_Declaration =>
3318 when N_Subprogram_Declaration |
3319 N_Generic_Package_Declaration |
3320 N_Generic_Subprogram_Declaration |
3321 N_Package_Instantiation |
3322 N_Function_Instantiation |
3323 N_Procedure_Instantiation |
3324 N_Generic_Package_Renaming_Declaration |
3325 N_Generic_Procedure_Renaming_Declaration |
3326 N_Generic_Function_Renaming_Declaration =>
3330 pragma Assert (False);
3334 P := Defining_Unit_Name (Specification (P_Unit));
3336 if Nkind (P) = N_Defining_Program_Unit_Name then
3338 -- Retrieve entity of child package
3340 Is_Child_Package := True;
3341 P := Defining_Identifier (P);
3344 -- A common usage of the limited-with is to have a limited-with
3345 -- in the package spec, and a normal with in its package body.
3348 -- limited with X; -- [1]
3352 -- package body A is ...
3354 -- The compilation of A's body installs the entities of its
3355 -- withed packages (the context clauses found at [2]) and
3356 -- then the context clauses of its specification (found at [1]).
3358 -- As a consequence, at point [1] the specification of X has been
3359 -- analyzed and it is immediately visible. According to the semantics
3360 -- of the limited-with context clauses we don't install the limited
3361 -- view because the full view of X supersedes its limited view.
3363 if Analyzed (Cunit (Unum))
3364 and then Is_Immediately_Visible (P)
3369 if Debug_Flag_I then
3370 Write_Str ("install limited view of ");
3371 Write_Name (Chars (P));
3375 if not Analyzed (Cunit (Unum)) then
3376 Set_Ekind (P, E_Package);
3377 Set_Etype (P, Standard_Void_Type);
3378 Set_Scope (P, Standard_Standard);
3380 -- Place entity on visibility structure
3382 if Current_Entity (P) /= P then
3383 Set_Homonym (P, Current_Entity (P));
3384 Set_Current_Entity (P);
3386 if Debug_Flag_I then
3387 Write_Str (" (homonym) chain ");
3388 Write_Name (Chars (P));
3394 if Is_Child_Package then
3395 Set_Is_Child_Unit (P);
3396 Set_Is_Visible_Child_Unit (P);
3399 Parent_Comp : Node_Id;
3400 Parent_Id : Entity_Id;
3403 Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
3404 Parent_Id := Defining_Entity (Unit (Parent_Comp));
3406 Set_Scope (P, Parent_Id);
3412 -- If the unit appears in a previous regular with_clause, the
3413 -- regular entities must be unchained before the shadow ones
3414 -- are made accessible.
3419 Ent := First_Entity (P);
3421 while Present (Ent) loop
3429 -- The package must be visible while the with_type clause is active,
3430 -- because references to the type P.T must resolve in the usual way.
3432 Set_Is_Immediately_Visible (P);
3434 -- Install each incomplete view
3436 Lim_Elmt := First_Elmt (Limited_Views (P));
3438 while Present (Lim_Elmt) loop
3439 Lim_Typ := Node (Lim_Elmt);
3441 if not In_Chain (Lim_Typ) then
3442 Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
3443 Set_Current_Entity (Lim_Typ);
3445 if Debug_Flag_I then
3446 Write_Str (" (homonym) chain ");
3447 Write_Name (Chars (Lim_Typ));
3453 Next_Elmt (Lim_Elmt);
3456 -- The context clause has installed a limited-view, mark it
3457 -- accordingly, to uninstall it when the context is removed.
3459 Set_Limited_View_Installed (N);
3460 Set_From_With_Type (P);
3461 end Install_Limited_Withed_Unit;
3463 -------------------------
3464 -- Install_Withed_Unit --
3465 -------------------------
3467 procedure Install_Withed_Unit
3468 (With_Clause : Node_Id;
3469 Private_With_OK : Boolean := False)
3471 Uname : constant Entity_Id := Entity (Name (With_Clause));
3472 P : constant Entity_Id := Scope (Uname);
3476 if Debug_Flag_I then
3477 Write_Str ("install withed unit ");
3478 Write_Name (Chars (Uname));
3482 -- We do not apply the restrictions to an internal unit unless
3483 -- we are compiling the internal unit as a main unit. This check
3484 -- is also skipped for dummy units (for missing packages).
3486 if Sloc (Uname) /= No_Location
3487 and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
3488 or else Current_Sem_Unit = Main_Unit)
3490 Check_Restricted_Unit
3491 (Unit_Name (Get_Source_Unit (Uname)), With_Clause);
3494 if P /= Standard_Standard then
3495 if Private_Present (With_Clause)
3496 and then not (Private_With_OK)
3500 -- If the unit is not analyzed after analysis of the with clause,
3501 -- and it is an instantiation, then it awaits a body and is the main
3502 -- unit. Its appearance in the context of some other unit indicates
3503 -- a circular dependency (DEC suite perversity).
3505 elsif not Analyzed (Uname)
3506 and then Nkind (Parent (Uname)) = N_Package_Instantiation
3509 ("instantiation depends on itself", Name (With_Clause));
3511 elsif not Is_Visible_Child_Unit (Uname) then
3512 Set_Is_Visible_Child_Unit (Uname);
3514 if Is_Generic_Instance (Uname)
3515 and then Ekind (Uname) in Subprogram_Kind
3517 -- Set flag as well on the visible entity that denotes the
3518 -- instance, which renames the current one.
3520 Set_Is_Visible_Child_Unit
3522 (Defining_Entity (Unit (Library_Unit (With_Clause)))));
3526 -- The parent unit may have been installed already, and
3527 -- may have appeared in a use clause.
3529 if In_Use (Scope (Uname)) then
3530 Set_Is_Potentially_Use_Visible (Uname);
3533 Set_Context_Installed (With_Clause);
3536 elsif not Is_Immediately_Visible (Uname) then
3537 if not Private_Present (With_Clause)
3538 or else Private_With_OK
3540 Set_Is_Immediately_Visible (Uname);
3543 Set_Context_Installed (With_Clause);
3546 -- A with-clause overrides a with-type clause: there are no restric-
3547 -- tions on the use of package entities.
3549 if Ekind (Uname) = E_Package then
3550 Set_From_With_Type (Uname, False);
3552 end Install_Withed_Unit;
3558 function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
3559 K : constant Node_Kind := Nkind (Lib_Unit);
3562 return (K in N_Generic_Declaration or else
3563 K in N_Generic_Instantiation or else
3564 K in N_Generic_Renaming_Declaration or else
3565 K = N_Package_Declaration or else
3566 K = N_Package_Renaming_Declaration or else
3567 K = N_Subprogram_Declaration or else
3568 K = N_Subprogram_Renaming_Declaration)
3569 and then Present (Parent_Spec (Lib_Unit));
3572 -----------------------
3573 -- Load_Needed_Body --
3574 -----------------------
3576 -- N is a generic unit named in a with clause, or else it is
3577 -- a unit that contains a generic unit or an inlined function.
3578 -- In order to perform an instantiation, the body of the unit
3579 -- must be present. If the unit itself is generic, we assume
3580 -- that an instantiation follows, and load and analyze the body
3581 -- unconditionally. This forces analysis of the spec as well.
3583 -- If the unit is not generic, but contains a generic unit, it
3584 -- is loaded on demand, at the point of instantiation (see ch12).
3586 procedure Load_Needed_Body (N : Node_Id; OK : out Boolean) is
3587 Body_Name : Unit_Name_Type;
3588 Unum : Unit_Number_Type;
3590 Save_Style_Check : constant Boolean := Opt.Style_Check;
3591 -- The loading and analysis is done with style checks off
3594 if not GNAT_Mode then
3595 Style_Check := False;
3598 Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
3601 (Load_Name => Body_Name,
3607 if Unum = No_Unit then
3611 Compiler_State := Analyzing; -- reset after load
3613 if not Fatal_Error (Unum) or else Try_Semantics then
3614 if Debug_Flag_L then
3615 Write_Str ("*** Loaded generic body");
3619 Semantics (Cunit (Unum));
3625 Style_Check := Save_Style_Check;
3626 end Load_Needed_Body;
3628 -------------------------
3629 -- Build_Limited_Views --
3630 -------------------------
3632 procedure Build_Limited_Views (N : Node_Id) is
3633 Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N));
3634 P : constant Entity_Id := Cunit_Entity (Unum);
3636 Spec : Node_Id; -- To denote a package specification
3637 Lim_Typ : Entity_Id; -- To denote shadow entities.
3638 Comp_Typ : Entity_Id; -- To denote real entities.
3640 procedure Decorate_Incomplete_Type
3643 -- Add attributes of an incomplete type to a shadow entity. The same
3644 -- attributes are placed on the real entity, so that gigi receives
3645 -- a consistent view.
3647 procedure Decorate_Package_Specification (P : Entity_Id);
3648 -- Add attributes of a package entity to the entity in a package
3651 procedure Decorate_Tagged_Type
3655 -- Set basic attributes of tagged type T, including its class_wide type.
3656 -- The parameters Loc, Scope are used to decorate the class_wide type.
3658 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id);
3659 -- Construct list of shadow entities and attach it to entity of
3660 -- package that is mentioned in a limited_with clause.
3662 function New_Internal_Shadow_Entity
3663 (Kind : Entity_Kind;
3664 Sloc_Value : Source_Ptr;
3665 Id_Char : Character) return Entity_Id;
3666 -- This function is similar to New_Internal_Entity, except that the
3667 -- entity is not added to the scope's list of entities.
3669 ------------------------------
3670 -- Decorate_Incomplete_Type --
3671 ------------------------------
3673 procedure Decorate_Incomplete_Type
3678 Set_Ekind (E, E_Incomplete_Type);
3679 Set_Scope (E, Scop);
3681 Set_Is_First_Subtype (E, True);
3682 Set_Stored_Constraint (E, No_Elist);
3683 Set_Full_View (E, Empty);
3684 Init_Size_Align (E);
3685 end Decorate_Incomplete_Type;
3687 --------------------------
3688 -- Decorate_Tagged_Type --
3689 --------------------------
3691 procedure Decorate_Tagged_Type
3699 Decorate_Incomplete_Type (T, Scop);
3700 Set_Is_Tagged_Type (T);
3702 -- Build corresponding class_wide type, if not previously done
3704 if No (Class_Wide_Type (T)) then
3705 CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
3707 Set_Ekind (CW, E_Class_Wide_Type);
3709 Set_Scope (CW, Scop);
3710 Set_Is_Tagged_Type (CW);
3711 Set_Is_First_Subtype (CW, True);
3712 Init_Size_Align (CW);
3713 Set_Has_Unknown_Discriminants (CW, True);
3714 Set_Class_Wide_Type (CW, CW);
3715 Set_Equivalent_Type (CW, Empty);
3716 Set_From_With_Type (CW, From_With_Type (T));
3718 Set_Class_Wide_Type (T, CW);
3720 end Decorate_Tagged_Type;
3722 ------------------------------------
3723 -- Decorate_Package_Specification --
3724 ------------------------------------
3726 procedure Decorate_Package_Specification (P : Entity_Id) is
3728 -- Place only the most basic attributes
3730 Set_Ekind (P, E_Package);
3731 Set_Etype (P, Standard_Void_Type);
3732 end Decorate_Package_Specification;
3734 -------------------------
3735 -- New_Internal_Entity --
3736 -------------------------
3738 function New_Internal_Shadow_Entity
3739 (Kind : Entity_Kind;
3740 Sloc_Value : Source_Ptr;
3741 Id_Char : Character) return Entity_Id
3743 N : constant Entity_Id :=
3744 Make_Defining_Identifier (Sloc_Value,
3745 Chars => New_Internal_Name (Id_Char));
3748 Set_Ekind (N, Kind);
3749 Set_Is_Internal (N, True);
3751 if Kind in Type_Kind then
3752 Init_Size_Align (N);
3756 end New_Internal_Shadow_Entity;
3762 -- Could use more comments below ???
3764 procedure Build_Chain (Spec : Node_Id; Scope : Entity_Id) is
3765 Analyzed_Unit : constant Boolean := Analyzed (Cunit (Unum));
3766 Is_Tagged : Boolean;
3770 Decl := First (Visible_Declarations (Spec));
3772 while Present (Decl) loop
3773 if Nkind (Decl) = N_Full_Type_Declaration then
3775 Nkind (Type_Definition (Decl)) = N_Record_Definition
3776 and then Tagged_Present (Type_Definition (Decl));
3778 Comp_Typ := Defining_Identifier (Decl);
3780 if not Analyzed_Unit then
3782 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3784 Decorate_Incomplete_Type (Comp_Typ, Scope);
3788 -- Create shadow entity for type
3790 Lim_Typ := New_Internal_Shadow_Entity
3791 (Kind => Ekind (Comp_Typ),
3792 Sloc_Value => Sloc (Comp_Typ),
3795 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3796 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3797 Set_From_With_Type (Lim_Typ);
3800 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3802 Decorate_Incomplete_Type (Lim_Typ, Scope);
3805 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3806 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3808 elsif Nkind (Decl) = N_Private_Type_Declaration
3809 and then Tagged_Present (Decl)
3811 Comp_Typ := Defining_Identifier (Decl);
3813 if not Analyzed_Unit then
3814 Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
3817 Lim_Typ := New_Internal_Shadow_Entity
3818 (Kind => Ekind (Comp_Typ),
3819 Sloc_Value => Sloc (Comp_Typ),
3822 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3823 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3824 Set_From_With_Type (Lim_Typ);
3826 Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
3828 Set_Non_Limited_View (Lim_Typ, Comp_Typ);
3829 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3831 elsif Nkind (Decl) = N_Package_Declaration then
3836 Spec : constant Node_Id := Specification (Decl);
3839 Comp_Typ := Defining_Unit_Name (Spec);
3841 if not Analyzed (Cunit (Unum)) then
3842 Decorate_Package_Specification (Comp_Typ);
3843 Set_Scope (Comp_Typ, Scope);
3846 Lim_Typ := New_Internal_Shadow_Entity
3847 (Kind => Ekind (Comp_Typ),
3848 Sloc_Value => Sloc (Comp_Typ),
3851 Decorate_Package_Specification (Lim_Typ);
3852 Set_Scope (Lim_Typ, Scope);
3854 Set_Chars (Lim_Typ, Chars (Comp_Typ));
3855 Set_Parent (Lim_Typ, Parent (Comp_Typ));
3856 Set_From_With_Type (Lim_Typ);
3858 -- Note: The non_limited_view attribute is not used
3859 -- for local packages.
3861 Append_Elmt (Lim_Typ, To => Limited_Views (P));
3863 Build_Chain (Spec, Scope => Lim_Typ);
3871 -- Start of processing for Build_Limited_Views
3874 pragma Assert (Limited_Present (N));
3876 -- A library_item mentioned in a limited_with_clause shall be
3877 -- a package_declaration, not a subprogram_declaration,
3878 -- generic_declaration, generic_instantiation, or
3879 -- package_renaming_declaration
3881 case Nkind (Unit (Library_Unit (N))) is
3883 when N_Package_Declaration =>
3886 when N_Subprogram_Declaration =>
3887 Error_Msg_N ("subprograms not allowed in "
3888 & "limited with_clauses", N);
3891 when N_Generic_Package_Declaration |
3892 N_Generic_Subprogram_Declaration =>
3893 Error_Msg_N ("generics not allowed in "
3894 & "limited with_clauses", N);
3897 when N_Package_Instantiation |
3898 N_Function_Instantiation |
3899 N_Procedure_Instantiation =>
3900 Error_Msg_N ("generic instantiations not allowed in "
3901 & "limited with_clauses", N);
3904 when N_Generic_Package_Renaming_Declaration |
3905 N_Generic_Procedure_Renaming_Declaration |
3906 N_Generic_Function_Renaming_Declaration =>
3907 Error_Msg_N ("generic renamings not allowed in "
3908 & "limited with_clauses", N);
3912 pragma Assert (False);
3916 -- Check if the chain is already built
3918 Spec := Specification (Unit (Library_Unit (N)));
3920 if Limited_View_Installed (Spec) then
3924 Set_Ekind (P, E_Package);
3925 Set_Limited_Views (P, New_Elmt_List);
3926 -- Set_Entity (Name (N), P);
3928 -- Create the auxiliary chain
3930 Build_Chain (Spec, Scope => P);
3931 Set_Limited_View_Installed (Spec);
3932 end Build_Limited_Views;
3934 -------------------------------
3935 -- Check_Body_Needed_For_SAL --
3936 -------------------------------
3938 procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
3940 function Entity_Needs_Body (E : Entity_Id) return Boolean;
3941 -- Determine whether use of entity E might require the presence
3942 -- of its body. For a package this requires a recursive traversal
3943 -- of all nested declarations.
3945 ---------------------------
3946 -- Entity_Needed_For_SAL --
3947 ---------------------------
3949 function Entity_Needs_Body (E : Entity_Id) return Boolean is
3953 if Is_Subprogram (E)
3954 and then Has_Pragma_Inline (E)
3958 elsif Ekind (E) = E_Generic_Function
3959 or else Ekind (E) = E_Generic_Procedure
3963 elsif Ekind (E) = E_Generic_Package
3965 Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
3966 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3970 elsif Ekind (E) = E_Package
3972 Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
3973 and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
3975 Ent := First_Entity (E);
3977 while Present (Ent) loop
3978 if Entity_Needs_Body (Ent) then
3990 end Entity_Needs_Body;
3992 -- Start of processing for Check_Body_Needed_For_SAL
3995 if Ekind (Unit_Name) = E_Generic_Package
3997 Nkind (Unit_Declaration_Node (Unit_Name)) =
3998 N_Generic_Package_Declaration
4000 Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
4002 Set_Body_Needed_For_SAL (Unit_Name);
4004 elsif Ekind (Unit_Name) = E_Generic_Procedure
4005 or else Ekind (Unit_Name) = E_Generic_Function
4007 Set_Body_Needed_For_SAL (Unit_Name);
4009 elsif Is_Subprogram (Unit_Name)
4010 and then Nkind (Unit_Declaration_Node (Unit_Name)) =
4011 N_Subprogram_Declaration
4012 and then Has_Pragma_Inline (Unit_Name)
4014 Set_Body_Needed_For_SAL (Unit_Name);
4016 elsif Ekind (Unit_Name) = E_Subprogram_Body then
4017 Check_Body_Needed_For_SAL
4018 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
4020 elsif Ekind (Unit_Name) = E_Package
4021 and then Entity_Needs_Body (Unit_Name)
4023 Set_Body_Needed_For_SAL (Unit_Name);
4025 elsif Ekind (Unit_Name) = E_Package_Body
4026 and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
4028 Check_Body_Needed_For_SAL
4029 (Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
4031 end Check_Body_Needed_For_SAL;
4033 --------------------
4034 -- Remove_Context --
4035 --------------------
4037 procedure Remove_Context (N : Node_Id) is
4038 Lib_Unit : constant Node_Id := Unit (N);
4041 -- If this is a child unit, first remove the parent units.
4043 if Is_Child_Spec (Lib_Unit) then
4044 Remove_Parents (Lib_Unit);
4047 Remove_Context_Clauses (N);
4050 ----------------------------
4051 -- Remove_Context_Clauses --
4052 ----------------------------
4054 procedure Remove_Context_Clauses (N : Node_Id) is
4056 Unit_Name : Entity_Id;
4059 -- Ada0Y (AI-50217): We remove the context clauses in two phases:
4060 -- limited-views first and regular-views later (to maintain the
4063 -- First Phase: Remove limited_with context clauses
4065 Item := First (Context_Items (N));
4066 while Present (Item) loop
4068 -- We are interested only in with clauses which got installed
4071 if Nkind (Item) = N_With_Clause
4072 and then Limited_Present (Item)
4073 and then Limited_View_Installed (Item)
4075 Remove_Limited_With_Clause (Item);
4082 -- Second Phase: Loop through context items and undo regular
4083 -- with_clauses and use_clauses.
4085 Item := First (Context_Items (N));
4086 while Present (Item) loop
4088 -- We are interested only in with clauses which got installed
4089 -- on entry, as indicated by their Context_Installed flag set
4091 if Nkind (Item) = N_With_Clause
4092 and then Limited_Present (Item)
4093 and then Limited_View_Installed (Item)
4097 elsif Nkind (Item) = N_With_Clause
4098 and then Context_Installed (Item)
4100 -- Remove items from one with'ed unit
4102 Unit_Name := Entity (Name (Item));
4103 Remove_Unit_From_Visibility (Unit_Name);
4104 Set_Context_Installed (Item, False);
4106 elsif Nkind (Item) = N_Use_Package_Clause then
4107 End_Use_Package (Item);
4109 elsif Nkind (Item) = N_Use_Type_Clause then
4110 End_Use_Type (Item);
4112 elsif Nkind (Item) = N_With_Type_Clause then
4113 Remove_With_Type_Clause (Name (Item));
4118 end Remove_Context_Clauses;
4120 --------------------------------
4121 -- Remove_Limited_With_Clause --
4122 --------------------------------
4124 procedure Remove_Limited_With_Clause (N : Node_Id) is
4125 P_Unit : constant Entity_Id := Unit (Library_Unit (N));
4126 P : Entity_Id := Defining_Unit_Name (Specification (P_Unit));
4128 Lim_Typ : Entity_Id;
4131 if Nkind (P) = N_Defining_Program_Unit_Name then
4133 -- Retrieve entity of Child package
4135 P := Defining_Identifier (P);
4138 if Debug_Flag_I then
4139 Write_Str ("remove limited view of ");
4140 Write_Name (Chars (P));
4141 Write_Str (" from visibility");
4145 -- Remove all shadow entities from visibility
4147 Lim_Elmt := First_Elmt (Limited_Views (P));
4149 while Present (Lim_Elmt) loop
4150 Lim_Typ := Node (Lim_Elmt);
4153 Next_Elmt (Lim_Elmt);
4156 -- Indicate that the limited view of the package is not installed
4158 Set_From_With_Type (P, False);
4159 Set_Limited_View_Installed (N, False);
4161 -- If the exporting package has previously been analyzed, it
4162 -- has appeared in the closure already and should be left alone.
4163 -- Otherwise, remove package itself from visibility.
4165 if not Analyzed (P_Unit) then
4167 Set_First_Entity (P, Empty);
4168 Set_Last_Entity (P, Empty);
4169 Set_Ekind (P, E_Void);
4170 Set_Scope (P, Empty);
4171 Set_Is_Immediately_Visible (P, False);
4175 -- Reinstall visible entities (entities removed from visibility in
4176 -- Install_Limited_Withed to install the shadow entities).
4182 Ent := First_Entity (P);
4183 while Present (Ent) and then Ent /= First_Private_Entity (P) loop
4185 -- Shadow entities have not been added to the list of
4186 -- entities associated to the package spec. Therefore we
4187 -- just have to re-chain all its visible entities.
4189 if not Is_Class_Wide_Type (Ent) then
4191 Set_Homonym (Ent, Current_Entity (Ent));
4192 Set_Current_Entity (Ent);
4194 if Debug_Flag_I then
4195 Write_Str (" (homonym) chain ");
4196 Write_Name (Chars (Ent));
4206 end Remove_Limited_With_Clause;
4208 --------------------
4209 -- Remove_Parents --
4210 --------------------
4212 procedure Remove_Parents (Lib_Unit : Node_Id) is
4216 Vis : constant Boolean :=
4217 Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
4220 if Is_Child_Spec (Lib_Unit) then
4221 P := Unit (Parent_Spec (Lib_Unit));
4222 P_Name := Get_Parent_Entity (P);
4224 Remove_Context_Clauses (Parent_Spec (Lib_Unit));
4225 End_Package_Scope (P_Name);
4226 Set_Is_Immediately_Visible (P_Name, Vis);
4228 -- Remove from visibility the siblings as well, which are directly
4229 -- visible while the parent is in scope.
4231 E := First_Entity (P_Name);
4233 while Present (E) loop
4235 if Is_Child_Unit (E) then
4236 Set_Is_Immediately_Visible (E, False);
4242 Set_In_Package_Body (P_Name, False);
4244 -- This is the recursive call to remove the context of any
4245 -- higher level parent. This recursion ensures that all parents
4246 -- are removed in the reverse order of their installation.
4252 -----------------------------
4253 -- Remove_With_Type_Clause --
4254 -----------------------------
4256 procedure Remove_With_Type_Clause (Name : Node_Id) is
4260 procedure Unchain (E : Entity_Id);
4261 -- Remove entity from visibility list.
4263 procedure Unchain (E : Entity_Id) is
4267 Prev := Current_Entity (E);
4269 -- Package entity may appear is several with_type_clauses, and
4270 -- may have been removed already.
4276 Set_Name_Entity_Id (Chars (E), Homonym (E));
4279 while Present (Prev)
4280 and then Homonym (Prev) /= E
4282 Prev := Homonym (Prev);
4285 if Present (Prev) then
4286 Set_Homonym (Prev, Homonym (E));
4291 -- Start of Remove_With_Type_Clause
4294 if Nkind (Name) = N_Selected_Component then
4295 Typ := Entity (Selector_Name (Name));
4297 if No (Typ) then -- error in declaration.
4306 -- If the exporting package has been analyzed, it has appeared in the
4307 -- context already and should be left alone. Otherwise, remove from
4310 if not Analyzed (Unit_Declaration_Node (P)) then
4313 Set_Is_Frozen (Typ, False);
4316 if Ekind (Typ) = E_Record_Type then
4317 Set_From_With_Type (Class_Wide_Type (Typ), False);
4318 Set_From_With_Type (Typ, False);
4321 Set_From_With_Type (P, False);
4323 -- If P is a child unit, remove parents as well.
4328 and then P /= Standard_Standard
4330 Set_From_With_Type (P, False);
4332 if not Analyzed (Unit_Declaration_Node (P)) then
4339 -- The back-end needs to know that an access type is imported, so it
4340 -- does not need elaboration and can appear in a mutually recursive
4341 -- record definition, so the imported flag on an access type is
4344 end Remove_With_Type_Clause;
4346 ---------------------------------
4347 -- Remove_Unit_From_Visibility --
4348 ---------------------------------
4350 procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
4351 P : constant Entity_Id := Scope (Unit_Name);
4355 if Debug_Flag_I then
4356 Write_Str ("remove unit ");
4357 Write_Name (Chars (Unit_Name));
4358 Write_Str (" from visibility");
4362 if P /= Standard_Standard then
4363 Set_Is_Visible_Child_Unit (Unit_Name, False);
4366 Set_Is_Potentially_Use_Visible (Unit_Name, False);
4367 Set_Is_Immediately_Visible (Unit_Name, False);
4369 end Remove_Unit_From_Visibility;
4375 procedure Unchain (E : Entity_Id) is
4379 Prev := Current_Entity (E);
4385 Set_Name_Entity_Id (Chars (E), Homonym (E));
4388 while Present (Prev)
4389 and then Homonym (Prev) /= E
4391 Prev := Homonym (Prev);
4394 if Present (Prev) then
4395 Set_Homonym (Prev, Homonym (E));
4399 if Debug_Flag_I then
4400 Write_Str (" (homonym) unchain ");
4401 Write_Name (Chars (E));