1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Contracts
; use Contracts
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Einfo
.Entities
; use Einfo
.Entities
;
32 with Einfo
.Utils
; use Einfo
.Utils
;
33 with Errout
; use Errout
;
34 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Util
; use Exp_Util
;
37 with Elists
; use Elists
;
38 with Fname
; use Fname
;
39 with Fname
.UF
; use Fname
.UF
;
40 with Freeze
; use Freeze
;
41 with Impunit
; use Impunit
;
42 with Inline
; use Inline
;
44 with Lib
.Load
; use Lib
.Load
;
45 with Lib
.Xref
; use Lib
.Xref
;
46 with Namet
; use Namet
;
47 with Nlists
; use Nlists
;
48 with Nmake
; use Nmake
;
50 with Output
; use Output
;
51 with Par_SCO
; use Par_SCO
;
52 with Restrict
; use Restrict
;
53 with Rident
; use Rident
;
54 with Rtsfind
; use Rtsfind
;
56 with Sem_Aux
; use Sem_Aux
;
57 with Sem_Ch3
; use Sem_Ch3
;
58 with Sem_Ch6
; use Sem_Ch6
;
59 with Sem_Ch7
; use Sem_Ch7
;
60 with Sem_Ch8
; use Sem_Ch8
;
61 with Sem_Ch13
; use Sem_Ch13
;
62 with Sem_Dist
; use Sem_Dist
;
63 with Sem_Prag
; use Sem_Prag
;
64 with Sem_Util
; use Sem_Util
;
65 with Sem_Warn
; use Sem_Warn
;
66 with Stand
; use Stand
;
67 with Sinfo
; use Sinfo
;
68 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
69 with Sinfo
.Utils
; use Sinfo
.Utils
;
70 with Sinfo
.CN
; use Sinfo
.CN
;
71 with Sinput
; use Sinput
;
72 with Snames
; use Snames
;
73 with Style
; use Style
;
74 with Stylesw
; use Stylesw
;
75 with Tbuild
; use Tbuild
;
76 with Uname
; use Uname
;
77 with Warnsw
; use Warnsw
;
79 package body Sem_Ch10
is
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 procedure Analyze_Context
(N
: Node_Id
);
86 -- Analyzes items in the context clause of compilation unit
88 procedure Analyze_Required_Limited_With_Units
(N
: Node_Id
);
89 -- Subsidiary of Analyze_Compilation_Unit. Perform full analysis of the
90 -- limited-with units of N when it is a package declaration that does not
91 -- require a package body, and the profile of some subprogram defined in N
92 -- depends on shadow incomplete type entities visible through limited-with
93 -- context clauses. This analysis is required to provide the backend with
94 -- the non-limited view of these shadow entities.
96 procedure Build_Limited_Views
(N
: Node_Id
);
97 -- Build and decorate the list of shadow entities for a package mentioned
98 -- in a limited_with clause. If the package was not previously analyzed
99 -- then it also performs a basic decoration of the real entities. This is
100 -- required in order to avoid passing non-decorated entities to the
101 -- back-end. Implements Ada 2005 (AI-50217).
103 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
);
104 -- Common processing for all stubs (subprograms, tasks, packages, and
105 -- protected cases). N is the stub to be analyzed. Once the subunit name
106 -- is established, load and analyze. Nam is the non-overloadable entity
107 -- for which the proper body provides a completion. Subprogram stubs are
108 -- handled differently because they can be declarations.
110 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
);
111 -- Check whether the source for the body of a compilation unit must be
112 -- included in a standalone library.
114 procedure Check_No_Elab_Code_All
(N
: Node_Id
);
115 -- Carries out possible tests for violation of No_Elab_Code all for withed
116 -- units in the Context_Items of unit N.
118 procedure Check_Private_Child_Unit
(N
: Node_Id
);
119 -- If a with_clause mentions a private child unit, the compilation unit
120 -- must be a member of the same family, as described in 10.1.2.
122 procedure Check_Stub_Level
(N
: Node_Id
);
123 -- Verify that a stub is declared immediately within a compilation unit,
124 -- and not in an inner frame.
126 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
);
127 -- When a child unit appears in a context clause, the implicit withs on
128 -- parents are made explicit, and with clauses are inserted in the context
129 -- clause before the one for the child. If a parent in the with_clause
130 -- is a renaming, the implicit with_clause is on the renaming whose name
131 -- is mentioned in the with_clause, and not on the package it renames.
132 -- N is the compilation unit whose list of context items receives the
133 -- implicit with_clauses.
135 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
);
136 -- Generate cross-reference information for the parents of child units
137 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
138 -- immediate parent scope.
140 function Has_With_Clause
143 Is_Limited
: Boolean := False) return Boolean;
144 -- Determine whether compilation unit C_Unit contains a [limited] with
145 -- clause for package Pack. Use the flag Is_Limited to designate desired
148 procedure Implicit_With_On_Parent
(Child_Unit
: Node_Id
; N
: Node_Id
);
149 -- If the main unit is a child unit, implicit withs are also added for
150 -- all its ancestors.
152 function In_Chain
(E
: Entity_Id
) return Boolean;
153 -- Check that the shadow entity is not already in the homonym chain, for
154 -- example through a limited_with clause in a parent unit.
156 procedure Install_Context_Clauses
(N
: Node_Id
; Chain
: Boolean := True);
157 -- Subsidiary to Install_Context and Install_Parents. Process all with
158 -- and use clauses for current unit and its library unit if any. The flag
159 -- Chain is used to control the "chaining" or linking together of use-type
160 -- and use-package clauses to avoid circularities with reinstalling
163 procedure Install_Limited_Context_Clauses
(N
: Node_Id
);
164 -- Subsidiary to Install_Context. Process only limited with_clauses for
165 -- current unit. Implements Ada 2005 (AI-50217).
167 procedure Install_Limited_With_Clause
(N
: Node_Id
);
168 -- Place shadow entities for a limited_with package in the visibility
169 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
171 procedure Install_Parents
173 Is_Private
: Boolean;
174 Chain
: Boolean := True);
175 -- This procedure establishes the context for the compilation of a child
176 -- unit. If Lib_Unit is a child library spec then the context of the parent
177 -- is installed, and the parent itself made immediately visible, so that
178 -- the child unit is processed in the declarative region of the parent.
179 -- Install_Parents makes a recursive call to itself to ensure that all
180 -- parents are loaded in the nested case. If Lib_Unit is a library body,
181 -- the only effect of Install_Parents is to install the private decls of
182 -- the parents, because the visible parent declarations will have been
183 -- installed as part of the context of the corresponding spec. The flag
184 -- Chain is used to control the "chaining" or linking of use-type and
185 -- use-package clauses to avoid circularities when installing context.
187 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
);
188 -- In the compilation of a child unit, a child of any of the ancestor
189 -- units is directly visible if it is visible, because the parent is in
190 -- an enclosing scope. Iterate over context to find child units of U_Name
191 -- or of some ancestor of it.
193 procedure Install_With_Clause
194 (With_Clause
: Node_Id
;
195 Private_With_OK
: Boolean := False);
196 -- If the unit is not a child unit, make unit immediately visible. The
197 -- caller ensures that the unit is not already currently installed. The
198 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
199 -- is called when compiling the private part of a package, or installing
200 -- the private declarations of a parent unit.
202 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean;
203 -- When compiling a unit Q descended from some parent unit P, a limited
204 -- with_clause in the context of P that names some other ancestor of Q
205 -- must not be installed because the ancestor is immediately visible.
207 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean;
208 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
209 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
210 -- a library spec that has a parent. If the call to Is_Child_Spec returns
211 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
212 -- compilation unit for the parent spec.
214 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
215 -- Parent_Spec is non-empty, this is also a child unit.
217 procedure Remove_Context_Clauses
(N
: Node_Id
);
218 -- Subsidiary of previous one. Remove use_ and with_clauses
220 procedure Remove_Limited_With_Clause
(N
: Node_Id
);
221 -- Remove the shadow entities from visibility introduced for a package
222 -- mentioned in limited with clause N. Implements Ada 2005 (AI-50217).
224 procedure Remove_Limited_With_Unit
225 (Pack_Decl
: Node_Id
;
226 Lim_Clause
: Node_Id
:= Empty
);
227 -- Remove the shadow entities from visibility introduced for a package
228 -- denoted by declaration Pack_Decl. Lim_Clause is the related limited
229 -- with clause, if any. Implements Ada 2005 (AI-50217).
231 procedure Remove_Parents
(Lib_Unit
: Node_Id
);
232 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
233 -- contexts established by the corresponding call to Install_Parents are
234 -- removed. Remove_Parents contains a recursive call to itself to ensure
235 -- that all parents are removed in the nested case.
237 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
);
238 -- Reset all visibility flags on unit after compiling it, either as a main
239 -- unit or as a unit in the context.
241 procedure Replace
(Old_E
, New_E
: Entity_Id
);
242 -- Replace Old_E by New_E on visibility list
244 procedure Unchain
(E
: Entity_Id
);
245 -- Remove single entity from visibility list
248 -- A dummy procedure, for debugging use, called just before analyzing the
249 -- main unit (after dealing with any context clauses).
251 --------------------------
252 -- Limited_With_Clauses --
253 --------------------------
255 -- Limited_With clauses are the mechanism chosen for Ada 2005 to support
256 -- mutually recursive types declared in different units. A limited_with
257 -- clause that names package P in the context of unit U makes the types
258 -- declared in the visible part of P available within U, but with the
259 -- restriction that these types can only be used as incomplete types.
260 -- The limited_with clause does not impose a semantic dependence on P,
261 -- and it is possible for two packages to have limited_with_clauses on
262 -- each other without creating an elaboration circularity.
264 -- To support this feature, the analysis of a limited_with clause must
265 -- create an abbreviated view of the package, without performing any
266 -- semantic analysis on it. This "package abstract" contains shadow types
267 -- that are in one-one correspondence with the real types in the package,
268 -- and that have the properties of incomplete types.
270 -- The implementation creates two element lists: one to chain the shadow
271 -- entities, and one to chain the corresponding type entities in the tree
272 -- of the package. Links between corresponding entities in both chains
273 -- allow the compiler to select the proper view of a given type, depending
274 -- on the context. Note that in contrast with the handling of private
275 -- types, the limited view and the nonlimited view of a type are treated
276 -- as separate entities, and no entity exchange needs to take place, which
277 -- makes the implementation much simpler than could be feared.
279 ------------------------------
280 -- Analyze_Compilation_Unit --
281 ------------------------------
283 procedure Analyze_Compilation_Unit
(N
: Node_Id
) is
284 Unit_Node
: constant Node_Id
:= Unit
(N
);
286 procedure Check_Redundant_Withs
287 (Context_Items
: List_Id
;
288 Spec_Context_Items
: List_Id
:= No_List
);
289 -- Determine whether the context list of a compilation unit contains
290 -- redundant with clauses. When checking body clauses against spec
291 -- clauses, set Context_Items to the context list of the body and
292 -- Spec_Context_Items to that of the spec. Parent packages are not
293 -- examined for documentation purposes.
295 ---------------------------
296 -- Check_Redundant_Withs --
297 ---------------------------
299 procedure Check_Redundant_Withs
300 (Context_Items
: List_Id
;
301 Spec_Context_Items
: List_Id
:= No_List
)
305 procedure Process_Body_Clauses
306 (Context_List
: List_Id
;
309 Used_Type_Or_Elab
: out Boolean);
310 -- Examine the context clauses of a package body, trying to match the
311 -- name entity of Clause with any list element. If the match occurs
312 -- on a use package clause set Used to True, for a use type clause or
313 -- pragma Elaborate[_All], set Used_Type_Or_Elab to True.
315 procedure Process_Spec_Clauses
316 (Context_List
: List_Id
;
319 Withed
: out Boolean;
320 Exit_On_Self
: Boolean := False);
321 -- Examine the context clauses of a package spec, trying to match
322 -- the name entity of Clause with any list element. If the match
323 -- occurs on a use package clause, set Used to True, for a with
324 -- package clause other than Clause, set Withed to True. Limited
325 -- with clauses, implicitly generated with clauses and withs
326 -- having pragmas Elaborate or Elaborate_All applied to them are
327 -- skipped. Exit_On_Self is used to control the search loop and
328 -- force an exit whenever Clause sees itself in the search.
330 --------------------------
331 -- Process_Body_Clauses --
332 --------------------------
334 procedure Process_Body_Clauses
335 (Context_List
: List_Id
;
338 Used_Type_Or_Elab
: out Boolean)
340 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
345 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean;
346 -- In an expanded name in a use clause, if the prefix is a renamed
347 -- package, the entity is set to the original package as a result,
348 -- when checking whether the package appears in a previous with
349 -- clause, the renaming has to be taken into account, to prevent
350 -- spurious/incorrect warnings. A common case is use of Text_IO.
356 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean is
358 return Entity
(N
) = P
359 or else (Present
(Renamed_Entity
(P
))
360 and then Entity
(N
) = Renamed_Entity
(P
));
363 -- Start of processing for Process_Body_Clauses
367 Used_Type_Or_Elab
:= False;
369 Cont_Item
:= First
(Context_List
);
370 while Present
(Cont_Item
) loop
372 -- Package use clause
374 if Nkind
(Cont_Item
) = N_Use_Package_Clause
377 -- Search through use clauses
379 Use_Item
:= Name
(Cont_Item
);
381 -- Case of a direct use of the one we are looking for
383 if Entity
(Use_Item
) = Nam_Ent
then
386 -- Handle nested case, as in "with P; use P.Q.R"
393 -- Loop through prefixes looking for match
396 while Nkind
(UE
) = N_Expanded_Name
loop
397 if Same_Unit
(Prefix
(UE
), Nam_Ent
) then
409 elsif Nkind
(Cont_Item
) = N_Use_Type_Clause
410 and then not Used_Type_Or_Elab
416 -- Loop through prefixes looking for a match
418 UE
:= Prefix
(Subtype_Mark
(Cont_Item
));
420 if not Used_Type_Or_Elab
421 and then Same_Unit
(UE
, Nam_Ent
)
423 Used_Type_Or_Elab
:= True;
426 exit when Nkind
(UE
) /= N_Expanded_Name
;
431 -- Pragma Elaborate or Elaborate_All
433 elsif Nkind
(Cont_Item
) = N_Pragma
435 Pragma_Name_Unmapped
(Cont_Item
)
436 in Name_Elaborate | Name_Elaborate_All
437 and then not Used_Type_Or_Elab
440 First
(Pragma_Argument_Associations
(Cont_Item
));
441 while Present
(Prag_Unit
) and then not Used_Type_Or_Elab
loop
442 if Entity
(Expression
(Prag_Unit
)) = Nam_Ent
then
443 Used_Type_Or_Elab
:= True;
452 end Process_Body_Clauses
;
454 --------------------------
455 -- Process_Spec_Clauses --
456 --------------------------
458 procedure Process_Spec_Clauses
459 (Context_List
: List_Id
;
462 Withed
: out Boolean;
463 Exit_On_Self
: Boolean := False)
465 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
472 Cont_Item
:= First
(Context_List
);
473 while Present
(Cont_Item
) loop
475 -- Stop the search since the context items after Cont_Item have
476 -- already been examined in a previous iteration of the reverse
477 -- loop in Check_Redundant_Withs.
480 and Cont_Item
= Clause
485 -- Package use clause
487 if Nkind
(Cont_Item
) = N_Use_Package_Clause
490 if Entity
(Name
(Cont_Item
)) = Nam_Ent
then
494 -- Package with clause. Avoid processing self, implicitly
495 -- generated with clauses or limited with clauses. Note that
496 -- we examine with clauses having pragmas Elaborate or
497 -- Elaborate_All applied to them due to cases such as:
501 -- pragma Elaborate (Pack);
503 -- In this case, the second with clause is redundant since
504 -- the pragma applies only to the first "with Pack;".
506 -- Note that we only consider with_clauses that comes from
507 -- source. In the case of renamings used as prefixes of names
508 -- in with_clauses, we generate a with_clause for the prefix,
509 -- which we do not treat as implicit because it is needed for
510 -- visibility analysis, but is also not redundant.
512 elsif Nkind
(Cont_Item
) = N_With_Clause
513 and then Comes_From_Source
(Cont_Item
)
514 and then not Implicit_With
(Cont_Item
)
515 and then not Limited_Present
(Cont_Item
)
516 and then Cont_Item
/= Clause
517 and then Entity
(Name
(Cont_Item
)) = Nam_Ent
524 end Process_Spec_Clauses
;
526 -- Start of processing for Check_Redundant_Withs
529 Clause
:= Last
(Context_Items
);
530 while Present
(Clause
) loop
532 -- Avoid checking implicitly generated with clauses, limited with
533 -- clauses or withs that have pragma Elaborate or Elaborate_All.
535 if Nkind
(Clause
) = N_With_Clause
536 and then not Implicit_With
(Clause
)
537 and then not Limited_Present
(Clause
)
538 and then not Elaborate_Present
(Clause
)
540 -- With_clauses introduced for renamings of parent clauses
541 -- are not marked implicit because they need to be properly
542 -- installed, but they do not come from source and do not
545 and then Comes_From_Source
(Clause
)
547 -- Package body-to-spec check
549 if Present
(Spec_Context_Items
) then
551 Used_In_Body
: Boolean;
552 Used_In_Spec
: Boolean;
553 Used_Type_Or_Elab
: Boolean;
554 Withed_In_Spec
: Boolean;
558 (Context_List
=> Spec_Context_Items
,
560 Used
=> Used_In_Spec
,
561 Withed
=> Withed_In_Spec
);
564 (Context_List
=> Context_Items
,
566 Used
=> Used_In_Body
,
567 Used_Type_Or_Elab
=> Used_Type_Or_Elab
);
569 -- "Type Elab" refers to the presence of either a use
570 -- type clause, pragmas Elaborate or Elaborate_All.
572 -- +---------------+---------------------------+------+
573 -- | Spec | Body | Warn |
574 -- +--------+------+--------+------+-----------+------+
575 -- | Withed | Used | Withed | Used | Type Elab | |
576 -- | X | | X | | | X |
577 -- | X | | X | X | | |
578 -- | X | | X | | X | |
579 -- | X | | X | X | X | |
580 -- | X | X | X | | | X |
581 -- | X | X | X | | X | |
582 -- | X | X | X | X | | X |
583 -- | X | X | X | X | X | |
584 -- +--------+------+--------+------+-----------+------+
587 and then not Used_Type_Or_Elab
)
589 ((not Used_In_Spec
and then not Used_In_Body
)
590 or else Used_In_Spec
)
592 Error_Msg_N
-- CODEFIX
593 ("redundant with clause in body?r?", Clause
);
597 -- Standalone package spec or body check
600 if Is_Ancestor_Package
(Entity
(Name
(Clause
)),
601 Defining_Entity
(Unit_Node
))
604 ("unnecessary with of ancestor?r?", Clause
);
608 Dummy
: Boolean := False;
609 Withed
: Boolean := False;
612 -- The mechanism for examining the context clauses of a
613 -- package spec can be applied to package body clauses.
616 (Context_List
=> Context_Items
,
620 Exit_On_Self
=> True);
623 Error_Msg_N
-- CODEFIX
624 ("redundant with clause?r?", Clause
);
632 end Check_Redundant_Withs
;
636 Main_Cunit
: constant Node_Id
:= Cunit
(Main_Unit
);
637 Lib_Unit
: Node_Id
:= Library_Unit
(N
);
638 Par_Spec_Name
: Unit_Name_Type
;
640 Unum
: Unit_Number_Type
;
641 Options
: Style_Check_Options
;
643 -- Start of processing for Analyze_Compilation_Unit
646 Exp_Put_Image
.Preload_Root_Buffer_Type
(N
);
648 Process_Compilation_Unit_Pragmas
(N
);
650 -- If the unit is a subunit whose parent has not been analyzed (which
651 -- indicates that the main unit is a subunit, either the current one or
652 -- one of its descendants) then the subunit is compiled as part of the
653 -- analysis of the parent, which we proceed to do. Basically this gets
654 -- handled from the top down and we don't want to do anything at this
655 -- level (i.e. this subunit will be handled on the way down from the
656 -- parent), so at this level we immediately return. If the subunit ends
657 -- up not analyzed, it means that the parent did not contain a stub for
658 -- it, or that there errors were detected in some ancestor.
660 if Nkind
(Unit_Node
) = N_Subunit
and then not Analyzed
(Lib_Unit
) then
661 Semantics
(Lib_Unit
);
663 if not Analyzed
(Proper_Body
(Unit_Node
)) then
664 if Serious_Errors_Detected
> 0 then
665 Error_Msg_N
("subunit not analyzed (errors in parent unit)", N
);
667 Error_Msg_N
("missing stub for subunit", N
);
674 -- Analyze context (this will call Sem recursively for with'ed units) To
675 -- detect circularities among with-clauses that are not caught during
676 -- loading, we set the Context_Pending flag on the current unit. If the
677 -- flag is already set there is a potential circularity. We exclude
678 -- predefined units from this check because they are known to be safe.
679 -- We also exclude package bodies that are present because circularities
680 -- between bodies are harmless (and necessary).
682 if Context_Pending
(N
) then
684 Circularity
: Boolean := True;
687 if In_Predefined_Unit
(N
) then
688 Circularity
:= False;
691 for U
in Main_Unit
+ 1 .. Last_Unit
loop
692 if Nkind
(Unit
(Cunit
(U
))) = N_Package_Body
693 and then not Analyzed
(Cunit
(U
))
695 Circularity
:= False;
702 Error_Msg_N
("circular dependency caused by with_clauses", N
);
704 ("\possibly missing limited_with clause"
705 & " in one of the following", N
);
707 for U
in Main_Unit
.. Last_Unit
loop
708 if Context_Pending
(Cunit
(U
)) then
709 Error_Msg_Unit_1
:= Get_Unit_Name
(Unit
(Cunit
(U
)));
710 Error_Msg_N
("\unit$", N
);
714 raise Unrecoverable_Error
;
718 Set_Context_Pending
(N
);
721 -- Store the style check options before analyzing context pragmas that
722 -- might change them for this compilation unit.
724 Save_Style_Check_Options
(Options
);
728 Set_Context_Pending
(N
, False);
730 -- If the unit is a package body, the spec is already loaded and must be
731 -- analyzed first, before we analyze the body.
733 if Nkind
(Unit_Node
) = N_Package_Body
then
735 -- If no Lib_Unit, then there was a serious previous error, so just
736 -- ignore the entire analysis effort.
738 if No
(Lib_Unit
) then
739 Check_Error_Detected
;
743 -- Analyze the package spec
745 Semantics
(Lib_Unit
);
747 -- Check for unused with's
749 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
751 -- Verify that the library unit is a package declaration
753 if Nkind
(Unit
(Lib_Unit
)) not in
754 N_Package_Declaration | N_Generic_Package_Declaration
757 ("no legal package declaration for package body", N
);
760 -- Otherwise, the entity in the declaration is visible. Update the
761 -- version to reflect dependence of this body on the spec.
764 Spec_Id
:= Defining_Entity
(Unit
(Lib_Unit
));
765 Set_Is_Immediately_Visible
(Spec_Id
, True);
766 Version_Update
(N
, Lib_Unit
);
768 if Nkind
(Defining_Unit_Name
(Unit_Node
)) =
769 N_Defining_Program_Unit_Name
771 Generate_Parent_References
(Unit_Node
, Scope
(Spec_Id
));
776 -- If the unit is a subprogram body, then we similarly need to analyze
777 -- its spec. However, things are a little simpler in this case, because
778 -- here, this analysis is done mostly for error checking and consistency
779 -- purposes (but not only, e.g. there could be a contract on the spec),
780 -- so there's nothing else to be done.
782 elsif Nkind
(Unit_Node
) = N_Subprogram_Body
then
783 if Acts_As_Spec
(N
) then
785 -- If the subprogram body is a child unit, we must create a
786 -- declaration for it, in order to properly load the parent(s).
787 -- After this, the original unit does not acts as a spec, because
788 -- there is an explicit one. If this unit appears in a context
789 -- clause, then an implicit with on the parent will be added when
790 -- installing the context. If this is the main unit, there is no
791 -- Unit_Table entry for the declaration (it has the unit number
792 -- of the main unit) and code generation is unaffected.
794 Unum
:= Get_Cunit_Unit_Number
(N
);
795 Par_Spec_Name
:= Get_Parent_Spec_Name
(Unit_Name
(Unum
));
797 if Present
(Par_Spec_Name
) then
800 (Load_Name
=> Par_Spec_Name
,
805 if Unum
/= No_Unit
then
807 -- Build subprogram declaration and attach parent unit to it
808 -- This subprogram declaration does not come from source,
809 -- Nevertheless the backend must generate debugging info for
810 -- it, and this must be indicated explicitly. We also mark
811 -- the body entity as a child unit now, to prevent a
812 -- cascaded error if the spec entity cannot be entered
813 -- in its scope. Finally we create a Units table entry for
814 -- the subprogram declaration, to maintain a one-to-one
815 -- correspondence with compilation unit nodes. This is
816 -- critical for the tree traversals performed by CodePeer.
819 Loc
: constant Source_Ptr
:= Sloc
(N
);
820 SCS
: constant Boolean :=
821 Get_Comes_From_Source_Default
;
824 Set_Comes_From_Source_Default
(False);
826 -- Note: We copy the Context_Items from the explicit body
827 -- to the implicit spec, setting the former to Empty_List
828 -- to preserve the treeish nature of the tree, during
829 -- analysis of the spec. Then we put it back the way it
830 -- was -- copy the Context_Items from the spec to the
831 -- body, and set the spec Context_Items to Empty_List.
832 -- It is necessary to preserve the treeish nature,
833 -- because otherwise we will call End_Use_* twice on the
837 Make_Compilation_Unit
(Loc
,
838 Context_Items
=> Context_Items
(N
),
840 Make_Subprogram_Declaration
(Sloc
(N
),
843 (Specification
(Unit_Node
))),
845 Make_Compilation_Unit_Aux
(Loc
));
847 Set_Context_Items
(N
, Empty_List
);
848 Set_Library_Unit
(N
, Lib_Unit
);
849 Set_Parent_Spec
(Unit
(Lib_Unit
), Cunit
(Unum
));
850 Make_Child_Decl_Unit
(N
);
851 Semantics
(Lib_Unit
);
853 -- Now that a separate declaration exists, the body
854 -- of the child unit does not act as spec any longer.
856 Set_Acts_As_Spec
(N
, False);
857 Move_Aspects
(From
=> Unit_Node
, To
=> Unit
(Lib_Unit
));
858 Set_Is_Child_Unit
(Defining_Entity
(Unit_Node
));
859 Set_Debug_Info_Needed
(Defining_Entity
(Unit
(Lib_Unit
)));
860 Set_Comes_From_Source_Default
(SCS
);
862 -- Restore Context_Items to the body
864 Set_Context_Items
(N
, Context_Items
(Lib_Unit
));
865 Set_Context_Items
(Lib_Unit
, Empty_List
);
870 -- Here for subprogram with separate declaration
873 Semantics
(Lib_Unit
);
874 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
875 Version_Update
(N
, Lib_Unit
);
878 -- If this is a child unit, generate references to the parents
880 if Nkind
(Defining_Unit_Name
(Specification
(Unit_Node
))) =
881 N_Defining_Program_Unit_Name
883 Generate_Parent_References
884 (Specification
(Unit_Node
),
885 Scope
(Defining_Entity
(Unit
(Lib_Unit
))));
889 -- If it is a child unit, the parent must be elaborated first and we
890 -- update version, since we are dependent on our parent.
892 if Is_Child_Spec
(Unit_Node
) then
894 -- The analysis of the parent is done with style checks off
897 Save_Style_Check
: constant Boolean := Style_Check
;
900 if not GNAT_Mode
then
901 Style_Check
:= False;
904 Semantics
(Parent_Spec
(Unit_Node
));
905 Version_Update
(N
, Parent_Spec
(Unit_Node
));
907 -- Restore style check settings
909 Style_Check
:= Save_Style_Check
;
913 -- With the analysis done, install the context. Note that we can't
914 -- install the context from the with clauses as we analyze them, because
915 -- each with clause must be analyzed in a clean visibility context, so
916 -- we have to wait and install them all at once.
920 if Is_Child_Spec
(Unit_Node
) then
922 -- Set the entities of all parents in the program_unit_name
924 Generate_Parent_References
925 (Unit_Node
, Get_Parent_Entity
(Unit
(Parent_Spec
(Unit_Node
))));
928 -- All components of the context: with-clauses, library unit, ancestors
929 -- if any, (and their context) are analyzed and installed.
931 -- Call special debug routine sm if this is the main unit
933 if Current_Sem_Unit
= Main_Unit
then
937 -- Now analyze the unit (package, subprogram spec, body) itself
941 if Warn_On_Redundant_Constructs
then
942 Check_Redundant_Withs
(Context_Items
(N
));
944 if Nkind
(Unit_Node
) = N_Package_Body
then
945 Check_Redundant_Withs
946 (Context_Items
=> Context_Items
(N
),
947 Spec_Context_Items
=> Context_Items
(Lib_Unit
));
951 -- The above call might have made Unit_Node an N_Subprogram_Body from
952 -- something else, so propagate any Acts_As_Spec flag.
954 if Nkind
(Unit_Node
) = N_Subprogram_Body
955 and then Acts_As_Spec
(Unit_Node
)
957 Set_Acts_As_Spec
(N
);
960 -- Register predefined units in Rtsfind
962 if In_Predefined_Unit
(N
) then
963 Set_RTU_Loaded
(Unit_Node
);
966 -- Treat compilation unit pragmas that appear after the library unit
969 Prag_Node
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(N
)));
971 while Present
(Prag_Node
) loop
977 -- Analyze the contract of a [generic] subprogram that acts as a
978 -- compilation unit after all compilation pragmas have been analyzed.
980 if Nkind
(Unit_Node
) in
981 N_Generic_Subprogram_Declaration | N_Subprogram_Declaration
983 Analyze_Entry_Or_Subprogram_Contract
(Defining_Entity
(Unit_Node
));
986 -- Generate distribution stubs if requested and no error
989 and then (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
991 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
992 and then Fatal_Error
(Main_Unit
) /= Error_Detected
994 if Is_RCI_Pkg_Spec_Or_Body
(N
) then
996 -- Regular RCI package
998 Add_Stub_Constructs
(N
);
1000 elsif (Nkind
(Unit_Node
) = N_Package_Declaration
1001 and then Is_Shared_Passive
(Defining_Entity
1002 (Specification
(Unit_Node
))))
1003 or else (Nkind
(Unit_Node
) = N_Package_Body
1005 Is_Shared_Passive
(Corresponding_Spec
(Unit_Node
)))
1007 -- Shared passive package
1009 Add_Stub_Constructs
(N
);
1011 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
1013 Is_Remote_Call_Interface
1014 (Defining_Entity
(Specification
(Instance_Spec
(Unit_Node
))))
1016 -- Instantiation of a RCI generic package
1018 Add_Stub_Constructs
(N
);
1022 -- Build dispatch tables of library-level tagged types only now because
1023 -- the generation of distribution stubs above may create some of them.
1025 if Expander_Active
and then Tagged_Type_Expansion
then
1026 case Nkind
(Unit_Node
) is
1027 when N_Package_Declaration | N_Package_Body
=>
1028 Build_Static_Dispatch_Tables
(Unit_Node
);
1030 when N_Package_Instantiation
=>
1031 Build_Static_Dispatch_Tables
(Instance_Spec
(Unit_Node
));
1038 -- Remove unit from visibility, so that environment is clean for the
1039 -- next compilation, which is either the main unit or some other unit
1042 if Nkind
(Unit_Node
) in N_Package_Declaration
1043 | N_Package_Renaming_Declaration
1044 | N_Subprogram_Declaration
1045 | N_Generic_Declaration
1046 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
1047 and then Acts_As_Spec
(Unit_Node
))
1049 Remove_Unit_From_Visibility
(Defining_Entity
(Unit_Node
));
1051 -- If the unit is an instantiation whose body will be elaborated for
1052 -- inlining purposes, use the proper entity of the instance. The entity
1053 -- may be missing if the instantiation was illegal.
1055 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
1056 and then not Error_Posted
(Unit_Node
)
1057 and then Present
(Instance_Spec
(Unit_Node
))
1059 Remove_Unit_From_Visibility
1060 (Defining_Entity
(Instance_Spec
(Unit_Node
)));
1062 elsif Nkind
(Unit_Node
) = N_Package_Body
1063 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
1064 and then not Acts_As_Spec
(Unit_Node
))
1066 -- Bodies that are not the main unit are compiled if they are generic
1067 -- or contain generic or inlined units. Their analysis brings in the
1068 -- context of the corresponding spec (unit declaration) which must be
1069 -- removed as well, to return the compilation environment to its
1072 Remove_Context
(Lib_Unit
);
1073 Set_Is_Immediately_Visible
(Defining_Entity
(Unit
(Lib_Unit
)), False);
1076 -- Last step is to deinstall the context we just installed as well as
1077 -- the unit just compiled.
1081 -- When generating code for a non-generic main unit, check that withed
1082 -- generic units have a body if they need it, even if the units have not
1083 -- been instantiated. Force the load of the bodies to produce the proper
1084 -- error if the body is absent. The same applies to GNATprove mode, with
1085 -- the added benefit of capturing global references within the generic.
1086 -- This in turn allows for proper inlining of subprogram bodies without
1087 -- a previous declaration.
1089 if Get_Cunit_Unit_Number
(N
) = Main_Unit
1090 and then ((Operating_Mode
= Generate_Code
and then Expander_Active
)
1092 (Operating_Mode
= Check_Semantics
and then GNATprove_Mode
))
1094 -- Check whether the source for the body of the unit must be included
1095 -- in a standalone library.
1097 Check_Body_Needed_For_SAL
(Cunit_Entity
(Main_Unit
));
1099 -- Indicate that the main unit is now analyzed, to catch possible
1100 -- circularities between it and generic bodies. Remove main unit from
1101 -- visibility. This might seem superfluous, but the main unit must
1102 -- not be visible in the generic body expansions that follow.
1104 Set_Analyzed
(N
, True);
1105 Set_Is_Immediately_Visible
(Cunit_Entity
(Main_Unit
), False);
1110 Un
: Unit_Number_Type
;
1112 Save_Style_Check
: constant Boolean := Style_Check
;
1115 Item
:= First
(Context_Items
(N
));
1116 while Present
(Item
) loop
1118 -- Check for explicit with clause
1120 if Nkind
(Item
) = N_With_Clause
1121 and then not Implicit_With
(Item
)
1123 -- Ada 2005 (AI-50217): Ignore limited-withed units
1125 and then not Limited_Present
(Item
)
1127 Nam
:= Entity
(Name
(Item
));
1129 -- Compile the generic subprogram, unless it is intrinsic or
1130 -- imported so no body is required, or generic package body
1131 -- if the package spec requires a body.
1133 if (Is_Generic_Subprogram
(Nam
)
1134 and then not Is_Intrinsic_Subprogram
(Nam
)
1135 and then not Is_Imported
(Nam
))
1136 or else (Ekind
(Nam
) = E_Generic_Package
1137 and then Unit_Requires_Body
(Nam
))
1139 Style_Check
:= False;
1141 if Present
(Renamed_Entity
(Nam
)) then
1147 (Unit_Declaration_Node
1148 (Renamed_Entity
(Nam
)))),
1157 Get_Body_Name
(Get_Unit_Name
(Item
)),
1164 if Un
= No_Unit
then
1166 ("body of generic unit& not found", Item
, Nam
);
1169 elsif not Analyzed
(Cunit
(Un
))
1170 and then Un
/= Main_Unit
1171 and then Fatal_Error
(Un
) /= Error_Detected
1173 Style_Check
:= False;
1174 Semantics
(Cunit
(Un
));
1182 -- Restore style checks settings
1184 Style_Check
:= Save_Style_Check
;
1187 -- In GNATprove mode, force the loading of an Interrupt_Priority when
1188 -- processing compilation units with potentially "main" subprograms.
1189 -- This is required for the ceiling priority protocol checks, which
1190 -- are triggered by these subprograms.
1193 and then Nkind
(Unit_Node
) in N_Function_Instantiation
1194 | N_Procedure_Instantiation
1201 case Nkind
(Unit_Node
) is
1202 when N_Subprogram_Body
=>
1203 Spec
:= Specification
(Unit_Node
);
1205 when N_Subprogram_Instantiation
=>
1207 Subprogram_Specification
(Entity
(Name
(Unit_Node
)));
1210 raise Program_Error
;
1213 pragma Assert
(Nkind
(Spec
) in N_Subprogram_Specification
);
1215 -- Main subprogram must have no parameters, and if it is a
1216 -- function, it must return an integer.
1218 if No
(Parameter_Specifications
(Spec
))
1219 and then (Nkind
(Spec
) = N_Procedure_Specification
1221 Is_Integer_Type
(Etype
(Result_Definition
(Spec
))))
1223 SPARK_Implicit_Load
(RE_Interrupt_Priority
);
1229 -- Deal with creating elaboration counter if needed. We create an
1230 -- elaboration counter only for units that come from source since
1231 -- units manufactured by the compiler never need elab checks.
1233 if Comes_From_Source
(N
)
1234 and then Nkind
(Unit_Node
) in N_Package_Declaration
1235 | N_Generic_Package_Declaration
1236 | N_Subprogram_Declaration
1237 | N_Generic_Subprogram_Declaration
1240 Loc
: constant Source_Ptr
:= Sloc
(N
);
1241 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1244 Spec_Id
:= Defining_Entity
(Unit_Node
);
1245 Generate_Definition
(Spec_Id
);
1247 -- See if an elaboration entity is required for possible access
1248 -- before elaboration checking. Note that we must allow for this
1249 -- even if -gnatE is not set, since a client may be compiled in
1250 -- -gnatE mode and reference the entity.
1252 -- These entities are also used by the binder to prevent multiple
1253 -- attempts to execute the elaboration code for the library case
1254 -- where the elaboration routine might otherwise be called more
1257 -- They are also needed to ensure explicit visibility from the
1258 -- binder generated code of all the units involved in a partition
1259 -- when control-flow preservation is requested.
1261 if not Opt
.Suppress_Control_Flow_Optimizations
1263 ( -- Pure units do not need checks
1267 -- Preelaborated units do not need checks
1269 or else Is_Preelaborated
(Spec_Id
)
1271 -- No checks needed if pragma Elaborate_Body present
1273 or else Has_Pragma_Elaborate_Body
(Spec_Id
)
1275 -- No checks needed if unit does not require a body
1277 or else not Unit_Requires_Body
(Spec_Id
)
1279 -- No checks needed for predefined files
1281 or else Is_Predefined_Unit
(Unum
)
1283 -- No checks required if no separate spec
1285 or else Acts_As_Spec
(N
)
1288 -- This is a case where we only need the entity for checking to
1289 -- prevent multiple elaboration checks.
1291 Set_Elaboration_Entity_Required
(Spec_Id
, False);
1293 -- Otherwise the unit requires an elaboration entity because it
1297 Set_Elaboration_Entity_Required
(Spec_Id
);
1300 Build_Elaboration_Entity
(N
, Spec_Id
);
1304 -- Freeze the compilation unit entity. This for sure is needed because
1305 -- of some warnings that can be output (see Freeze_Subprogram), but may
1306 -- in general be required. If freezing actions result, place them in the
1307 -- compilation unit actions list, and analyze them.
1310 L
: constant List_Id
:=
1311 Freeze_Entity
(Cunit_Entity
(Current_Sem_Unit
), N
);
1313 while Is_Non_Empty_List
(L
) loop
1314 Insert_Library_Level_Action
(Remove_Head
(L
));
1320 -- Call Check_Package_Body so that a body containing subprograms with
1321 -- Inline_Always can be made available for front end inlining.
1323 if Nkind
(Unit_Node
) = N_Package_Declaration
1324 and then Get_Cunit_Unit_Number
(N
) /= Main_Unit
1326 -- We don't need to do this if the Expander is not active, since there
1327 -- is no code to inline.
1329 and then Expander_Active
1332 Save_Style_Check
: constant Boolean := Style_Check
;
1333 Save_Warning
: constant Warning_Mode_Type
:= Warning_Mode
;
1334 Options
: Style_Check_Options
;
1337 Save_Style_Check_Options
(Options
);
1338 Reset_Style_Check_Options
;
1339 Opt
.Warning_Mode
:= Suppress
;
1341 Check_Package_Body_For_Inlining
(N
, Defining_Entity
(Unit_Node
));
1343 Reset_Style_Check_Options
;
1344 Set_Style_Check_Options
(Options
);
1345 Style_Check
:= Save_Style_Check
;
1346 Warning_Mode
:= Save_Warning
;
1350 -- If we are generating obsolescent warnings, then here is where we
1351 -- generate them for the with'ed items. The reason for this special
1352 -- processing is that the normal mechanism of generating the warnings
1353 -- for referenced entities does not work for context clause references.
1354 -- That's because when we first analyze the context, it is too early to
1355 -- know if the with'ing unit is itself obsolescent (which suppresses
1359 and then Warn_On_Obsolescent_Feature
1360 and then Nkind
(Unit_Node
) not in N_Generic_Instantiation
1362 -- Push current compilation unit as scope, so that the test for
1363 -- being within an obsolescent unit will work correctly. The check
1364 -- is not performed within an instantiation, because the warning
1365 -- will have been emitted in the corresponding generic unit.
1367 Push_Scope
(Defining_Entity
(Unit_Node
));
1369 -- Loop through context items to deal with with clauses
1377 Item
:= First
(Context_Items
(N
));
1378 while Present
(Item
) loop
1379 if Nkind
(Item
) = N_With_Clause
1381 -- Suppress this check in limited-withed units. Further work
1382 -- needed here if we decide to incorporate this check on
1383 -- limited-withed units.
1385 and then not Limited_Present
(Item
)
1388 Ent
:= Entity
(Nam
);
1390 if Is_Obsolescent
(Ent
) then
1391 Output_Obsolescent_Entity_Warnings
(Nam
, Ent
);
1399 -- Remove temporary install of current unit as scope
1404 -- Finally restore all the original style check options
1406 Set_Style_Check_Options
(Options
);
1408 -- If No_Elaboration_Code_All was encountered, this is where we do the
1409 -- transitive test of with'ed units to make sure they have the aspect.
1410 -- This is delayed till the end of analyzing the compilation unit to
1411 -- ensure that the pragma/aspect, if present, has been analyzed.
1413 Check_No_Elab_Code_All
(N
);
1415 -- If this is a main compilation containing a package declaration that
1416 -- requires no package body, and the profile of some subprogram depends
1417 -- on shadow incomplete entities then perform full analysis of its
1418 -- limited-with units.
1420 Analyze_Required_Limited_With_Units
(N
);
1421 end Analyze_Compilation_Unit
;
1423 ---------------------
1424 -- Analyze_Context --
1425 ---------------------
1427 procedure Analyze_Context
(N
: Node_Id
) is
1428 Ukind
: constant Node_Kind
:= Nkind
(Unit
(N
));
1432 -- First process all configuration pragmas at the start of the context
1433 -- items. Strictly these are not part of the context clause, but that
1434 -- is where the parser puts them. In any case for sure we must analyze
1435 -- these before analyzing the actual context items, since they can have
1436 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1437 -- be with'ed as a result of changing categorizations in Ada 2005).
1439 Item
:= First
(Context_Items
(N
));
1440 while Present
(Item
)
1441 and then Nkind
(Item
) = N_Pragma
1442 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
1448 -- This is the point at which we capture the configuration settings
1449 -- for the unit. At the moment only the Optimize_Alignment setting
1450 -- needs to be captured. Probably more later ???
1452 if Optimize_Alignment_Local
then
1453 Set_OA_Setting
(Current_Sem_Unit
, 'L');
1455 Set_OA_Setting
(Current_Sem_Unit
, Optimize_Alignment
);
1458 -- Loop through actual context items. This is done in two passes:
1460 -- a) The first pass analyzes nonlimited with clauses and also any
1461 -- configuration pragmas (we need to get the latter analyzed right
1462 -- away, since they can affect processing of subsequent items).
1464 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1466 while Present
(Item
) loop
1468 -- For with clause, analyze the with clause, and then update the
1469 -- version, since we are dependent on a unit that we with.
1471 if Nkind
(Item
) = N_With_Clause
1472 and then not Limited_Present
(Item
)
1474 -- Skip analyzing with clause if no unit, nothing to do (this
1475 -- happens for a with that references a non-existent unit).
1477 if Present
(Library_Unit
(Item
)) then
1479 -- Skip analyzing with clause if this is a with_clause for
1480 -- the main unit, which happens if a subunit has a useless
1481 -- with_clause on its parent.
1483 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
) then
1486 -- Here for the case of a useless with for the main unit
1489 Set_Entity
(Name
(Item
), Cunit_Entity
(Current_Sem_Unit
));
1493 -- Do version update (skipped for implicit with)
1495 if not Implicit_With
(Item
) then
1496 Version_Update
(N
, Library_Unit
(Item
));
1499 -- Skip pragmas. Configuration pragmas at the start were handled in
1500 -- the loop above, and remaining pragmas are not processed until we
1501 -- actually install the context (see Install_Context). We delay the
1502 -- analysis of these pragmas to make sure that we have installed all
1503 -- the implicit with's on parent units.
1505 -- Skip use clauses at this stage, since we don't want to do any
1506 -- installing of potentially use-visible entities until we
1507 -- actually install the complete context (in Install_Context).
1508 -- Otherwise things can get installed in the wrong context.
1517 -- Second pass: examine all limited_with clauses. All other context
1518 -- items are ignored in this pass.
1520 Item
:= First
(Context_Items
(N
));
1521 while Present
(Item
) loop
1522 if Nkind
(Item
) = N_With_Clause
1523 and then Limited_Present
(Item
)
1525 -- No need to check errors on implicitly generated limited-with
1528 if not Implicit_With
(Item
) then
1530 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1531 -- properly rejected, including renaming declarations.
1533 if Ukind
not in N_Package_Declaration
1534 | N_Subprogram_Declaration
1535 | N_Generic_Declaration
1536 | N_Generic_Instantiation
1538 Error_Msg_N
("limited with_clause not allowed here", Item
);
1540 -- Check wrong use of a limited with clause applied to the
1541 -- compilation unit containing the limited-with clause.
1543 -- limited with P.Q;
1544 -- package P.Q is ...
1546 elsif Unit
(Library_Unit
(Item
)) = Unit
(N
) then
1547 Error_Msg_N
("wrong use of limited-with clause", Item
);
1549 -- Check wrong use of limited-with clause applied to some
1550 -- immediate ancestor.
1552 elsif Is_Child_Spec
(Unit
(N
)) then
1554 Lib_U
: constant Entity_Id
:= Unit
(Library_Unit
(Item
));
1558 P
:= Parent_Spec
(Unit
(N
));
1560 if Unit
(P
) = Lib_U
then
1562 ("limited with_clause cannot name ancestor",
1567 exit when not Is_Child_Spec
(Unit
(P
));
1568 P
:= Parent_Spec
(Unit
(P
));
1573 -- Check if the limited-withed unit is already visible through
1574 -- some context clause of the current compilation unit or some
1575 -- ancestor of the current compilation unit.
1578 Lim_Unit_Name
: constant Node_Id
:= Name
(Item
);
1579 Comp_Unit
: Node_Id
;
1581 Unit_Name
: Node_Id
;
1586 It
:= First
(Context_Items
(Comp_Unit
));
1587 while Present
(It
) loop
1589 and then Nkind
(It
) = N_With_Clause
1590 and then not Limited_Present
(It
)
1591 and then Nkind
(Unit
(Library_Unit
(It
))) in
1592 N_Package_Declaration |
1593 N_Package_Renaming_Declaration
1595 if Nkind
(Unit
(Library_Unit
(It
))) =
1596 N_Package_Declaration
1598 Unit_Name
:= Name
(It
);
1600 Unit_Name
:= Name
(Unit
(Library_Unit
(It
)));
1603 -- Check if the named package (or some ancestor)
1604 -- leaves visible the full-view of the unit given
1605 -- in the limited-with clause.
1608 if Designate_Same_Unit
(Lim_Unit_Name
,
1611 Error_Msg_Sloc
:= Sloc
(It
);
1613 ("simultaneous visibility of limited and "
1614 & "unlimited views not allowed", Item
);
1616 ("\unlimited view visible through context "
1617 & "clause #", Item
);
1620 elsif Nkind
(Unit_Name
) = N_Identifier
then
1624 Unit_Name
:= Prefix
(Unit_Name
);
1631 exit when not Is_Child_Spec
(Unit
(Comp_Unit
));
1633 Comp_Unit
:= Parent_Spec
(Unit
(Comp_Unit
));
1638 -- Skip analyzing with clause if no unit, see above
1640 if Present
(Library_Unit
(Item
)) then
1644 -- A limited_with does not impose an elaboration order, but there
1645 -- is a semantic dependency for recompilation purposes.
1647 if not Implicit_With
(Item
) then
1648 Version_Update
(N
, Library_Unit
(Item
));
1651 -- Pragmas and use clauses and with clauses other than limited with's
1652 -- are ignored in this pass through the context items.
1660 end Analyze_Context
;
1662 -------------------------------
1663 -- Analyze_Package_Body_Stub --
1664 -------------------------------
1666 procedure Analyze_Package_Body_Stub
(N
: Node_Id
) is
1667 Id
: constant Entity_Id
:= Defining_Entity
(N
);
1669 Opts
: Config_Switches_Type
;
1672 -- The package declaration must be in the current declarative part
1674 Check_Stub_Level
(N
);
1675 Nam
:= Current_Entity_In_Scope
(Id
);
1677 if No
(Nam
) or else not Is_Package_Or_Generic_Package
(Nam
) then
1678 Error_Msg_N
("missing specification for package stub", N
);
1680 elsif Has_Completion
(Nam
)
1681 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Nam
)))
1683 Error_Msg_N
("duplicate or redundant stub for package", N
);
1686 -- Retain and restore the configuration options of the enclosing
1687 -- context as the proper body may introduce a set of its own.
1689 Opts
:= Save_Config_Switches
;
1691 -- Indicate that the body of the package exists. If we are doing
1692 -- only semantic analysis, the stub stands for the body. If we are
1693 -- generating code, the existence of the body will be confirmed
1694 -- when we load the proper body.
1696 Set_Scope
(Id
, Current_Scope
);
1697 Mutate_Ekind
(Id
, E_Package_Body
);
1698 Set_Etype
(Id
, Standard_Void_Type
);
1700 Analyze_Aspect_Specifications
(N
, Id
);
1702 Set_Has_Completion
(Nam
);
1703 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1704 Generate_Reference
(Nam
, Id
, 'b');
1705 Analyze_Proper_Body
(N
, Nam
);
1707 Restore_Config_Switches
(Opts
);
1709 end Analyze_Package_Body_Stub
;
1711 -------------------------
1712 -- Analyze_Proper_Body --
1713 -------------------------
1715 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1716 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1718 procedure Optional_Subunit
;
1719 -- This procedure is called when the main unit is a stub, or when we
1720 -- are not generating code. In such a case, we analyze the subunit if
1721 -- present, which is user-friendly, but we don't complain if the subunit
1722 -- is missing. In GNATprove_Mode, we issue an error to avoid formal
1723 -- verification of a partial unit.
1725 ----------------------
1726 -- Optional_Subunit --
1727 ----------------------
1729 procedure Optional_Subunit
is
1730 Comp_Unit
: Node_Id
;
1731 Unum
: Unit_Number_Type
;
1734 -- Try to load subunit, but ignore any errors that occur during the
1735 -- loading of the subunit, by using the special feature in Errout to
1736 -- ignore all errors. Note that Fatal_Error will still be set, so we
1737 -- will be able to check for this case below.
1739 if not GNATprove_Mode
then
1740 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1745 (Load_Name
=> Subunit_Name
,
1746 Required
=> GNATprove_Mode
,
1750 if not GNATprove_Mode
then
1751 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1754 -- All done if we successfully loaded the subunit
1757 and then (Fatal_Error
(Unum
) /= Error_Detected
1758 or else Try_Semantics
)
1760 Comp_Unit
:= Cunit
(Unum
);
1762 -- If the file was empty or seriously mangled, the unit itself may
1765 if No
(Unit
(Comp_Unit
)) then
1767 ("subunit does not contain expected proper body", N
);
1769 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1771 ("expected SEPARATE subunit, found child unit",
1772 Cunit_Entity
(Unum
));
1774 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1775 Analyze_Subunit
(Comp_Unit
);
1776 Set_Library_Unit
(N
, Comp_Unit
);
1777 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1780 elsif Unum
= No_Unit
1781 and then Present
(Nam
)
1783 if Is_Protected_Type
(Nam
) then
1784 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1786 Set_Corresponding_Body
(
1787 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1790 end Optional_Subunit
;
1794 Comp_Unit
: Node_Id
;
1795 Unum
: Unit_Number_Type
;
1797 -- Start of processing for Analyze_Proper_Body
1800 -- If the subunit is already loaded, it means that the main unit is a
1801 -- subunit, and that the current unit is one of its parents which was
1802 -- being analyzed to provide the needed context for the analysis of the
1803 -- subunit. In this case we analyze the subunit and continue with the
1804 -- parent, without looking at subsequent subunits.
1806 if Is_Loaded
(Subunit_Name
) then
1808 -- If the proper body is already linked to the stub node, the stub is
1809 -- in a generic unit and just needs analyzing.
1811 if Present
(Library_Unit
(N
)) then
1812 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1814 -- If the subunit has severe errors, the spec of the enclosing
1815 -- body may not be available, in which case do not try analysis.
1817 if Serious_Errors_Detected
> 0
1818 and then No
(Library_Unit
(Library_Unit
(N
)))
1823 -- Collect SCO information for loaded subunit if we are in the
1824 -- extended main unit.
1827 and then In_Extended_Main_Source_Unit
1828 (Cunit_Entity
(Current_Sem_Unit
))
1830 SCO_Record_Raw
(Get_Cunit_Unit_Number
(Library_Unit
(N
)));
1833 Analyze_Subunit
(Library_Unit
(N
));
1835 -- Otherwise we must load the subunit and link to it
1838 -- Load the subunit, this must work, since we originally loaded
1839 -- the subunit earlier on. So this will not really load it, just
1840 -- give access to it.
1844 (Load_Name
=> Subunit_Name
,
1849 -- And analyze the subunit in the parent context (note that we
1850 -- do not call Semantics, since that would remove the parent
1851 -- context). Because of this, we have to manually reset the
1852 -- compiler state to Analyzing since it got destroyed by Load.
1854 if Unum
/= No_Unit
then
1855 Compiler_State
:= Analyzing
;
1857 -- Check that the proper body is a subunit and not a child
1858 -- unit. If the unit was previously loaded, the error will
1859 -- have been emitted when copying the generic node, so we
1860 -- just return to avoid cascaded errors.
1862 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1866 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1867 Analyze_Subunit
(Cunit
(Unum
));
1868 Set_Library_Unit
(N
, Cunit
(Unum
));
1872 -- If the main unit is a subunit, then we are just performing semantic
1873 -- analysis on that subunit, and any other subunits of any parent unit
1874 -- should be ignored. If the main unit is itself a subunit, another
1875 -- subunit is irrelevant unless it is a subunit of the current one, that
1876 -- is to say appears in the current source tree.
1878 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1879 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1881 -- But before we return, set the flag for unloaded subunits. This
1882 -- will suppress junk warnings of variables in the same declarative
1883 -- part (or a higher level one) that are in danger of looking unused
1884 -- when in fact there might be a declaration in the subunit that we
1885 -- do not intend to load.
1887 Unloaded_Subunits
:= True;
1890 -- If the subunit is not already loaded, and we are generating code,
1891 -- then this is the case where compilation started from the parent, and
1892 -- we are generating code for an entire subunit tree. In that case we
1893 -- definitely need to load the subunit.
1895 -- In order to continue the analysis with the rest of the parent,
1896 -- and other subunits, we load the unit without requiring its
1897 -- presence, and emit a warning if not found, rather than terminating
1898 -- the compilation abruptly, as for other missing file problems.
1900 elsif Original_Operating_Mode
= Generate_Code
then
1902 -- If the proper body is already linked to the stub node, the stub is
1903 -- in a generic unit and just needs analyzing.
1905 -- We update the version. Although we are not strictly technically
1906 -- semantically dependent on the subunit, given our approach of macro
1907 -- substitution of subunits, it makes sense to include it in the
1908 -- version identification.
1910 if Present
(Library_Unit
(N
)) then
1911 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1912 Analyze_Subunit
(Library_Unit
(N
));
1913 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1915 -- Otherwise we must load the subunit and link to it
1918 -- Make sure that, if the subunit is preprocessed and -gnateG is
1919 -- specified, the preprocessed file will be written.
1921 Lib
.Analysing_Subunit_Of_Main
:= True;
1924 (Load_Name
=> Subunit_Name
,
1928 Lib
.Analysing_Subunit_Of_Main
:= False;
1930 -- Give message if we did not get the unit Emit warning even if
1931 -- missing subunit is not within main unit, to simplify debugging.
1933 pragma Assert
(Original_Operating_Mode
= Generate_Code
);
1934 if Unum
= No_Unit
then
1935 Error_Msg_Unit_1
:= Subunit_Name
;
1937 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1939 ("subunit$$ in file{ not found??!!", N
);
1940 Subunits_Missing
:= True;
1943 -- Load_Unit may reset Compiler_State, since it may have been
1944 -- necessary to parse an additional units, so we make sure that
1945 -- we reset it to the Analyzing state.
1947 Compiler_State
:= Analyzing
;
1949 if Unum
/= No_Unit
then
1950 if Debug_Flag_L
then
1951 Write_Str
("*** Loaded subunit from stub. Analyze");
1955 Comp_Unit
:= Cunit
(Unum
);
1957 -- Check for child unit instead of subunit
1959 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1961 ("expected SEPARATE subunit, found child unit",
1962 Cunit_Entity
(Unum
));
1964 -- OK, we have a subunit
1967 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1968 Set_Library_Unit
(N
, Comp_Unit
);
1970 -- We update the version. Although we are not technically
1971 -- semantically dependent on the subunit, given our approach
1972 -- of macro substitution of subunits, it makes sense to
1973 -- include it in the version identification.
1975 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1977 -- Collect SCO information for loaded subunit if we are in
1978 -- the extended main unit.
1981 and then In_Extended_Main_Source_Unit
1982 (Cunit_Entity
(Current_Sem_Unit
))
1984 SCO_Record_Raw
(Unum
);
1987 -- Analyze the unit if semantics active
1989 if Fatal_Error
(Unum
) /= Error_Detected
1990 or else Try_Semantics
1992 Analyze_Subunit
(Comp_Unit
);
1998 -- The remaining case is when the subunit is not already loaded and we
1999 -- are not generating code. In this case we are just performing semantic
2000 -- analysis on the parent, and we are not interested in the subunit. For
2001 -- subprograms, analyze the stub as a body. For other entities the stub
2002 -- has already been marked as completed.
2007 end Analyze_Proper_Body
;
2009 ----------------------------------
2010 -- Analyze_Protected_Body_Stub --
2011 ----------------------------------
2013 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
2014 Id
: constant Entity_Id
:= Defining_Entity
(N
);
2015 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Id
);
2016 Opts
: Config_Switches_Type
;
2019 Check_Stub_Level
(N
);
2021 -- First occurrence of name may have been as an incomplete type
2023 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2024 Nam
:= Full_View
(Nam
);
2027 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
2028 Error_Msg_N
("missing specification for Protected body", N
);
2031 -- Retain and restore the configuration options of the enclosing
2032 -- context as the proper body may introduce a set of its own.
2034 Opts
:= Save_Config_Switches
;
2036 Set_Scope
(Id
, Current_Scope
);
2037 Mutate_Ekind
(Id
, E_Protected_Body
);
2038 Set_Etype
(Id
, Standard_Void_Type
);
2040 Analyze_Aspect_Specifications
(N
, Id
);
2042 Set_Has_Completion
(Etype
(Nam
));
2043 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2044 Generate_Reference
(Nam
, Id
, 'b');
2045 Analyze_Proper_Body
(N
, Etype
(Nam
));
2047 Restore_Config_Switches
(Opts
);
2049 end Analyze_Protected_Body_Stub
;
2051 -----------------------------------------
2052 -- Analyze_Required_Limited_With_Units --
2053 -----------------------------------------
2055 procedure Analyze_Required_Limited_With_Units
(N
: Node_Id
) is
2056 Unit_Node
: constant Node_Id
:= Unit
(N
);
2057 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Unit_Node
);
2059 function Depends_On_Limited_Views
(Pkg_Id
: Entity_Id
) return Boolean;
2060 -- Determines whether the given package has some subprogram with a
2061 -- profile that depends on shadow incomplete type entities of a
2062 -- limited-with unit.
2064 function Has_Limited_With_Clauses
return Boolean;
2065 -- Determines whether the compilation unit N has limited-with context
2068 ------------------------------
2069 -- Has_Limited_With_Clauses --
2070 ------------------------------
2072 function Has_Limited_With_Clauses
return Boolean is
2073 Item
: Node_Id
:= First
(Context_Items
(N
));
2076 while Present
(Item
) loop
2077 if Nkind
(Item
) = N_With_Clause
2078 and then Limited_Present
(Item
)
2079 and then not Implicit_With
(Item
)
2088 end Has_Limited_With_Clauses
;
2090 ------------------------------
2091 -- Depends_On_Limited_Views --
2092 ------------------------------
2094 function Depends_On_Limited_Views
(Pkg_Id
: Entity_Id
) return Boolean is
2096 function Has_Limited_View_Types
(Subp
: Entity_Id
) return Boolean;
2097 -- Determines whether the type of some formal of Subp, or its return
2098 -- type, is a shadow incomplete entity of a limited-with unit.
2100 ----------------------------
2101 -- Has_Limited_View_Types --
2102 ----------------------------
2104 function Has_Limited_View_Types
(Subp
: Entity_Id
) return Boolean is
2105 Formal
: Entity_Id
:= First_Formal
(Subp
);
2108 while Present
(Formal
) loop
2109 if From_Limited_With
(Etype
(Formal
))
2110 and then Has_Non_Limited_View
(Etype
(Formal
))
2111 and then Ekind
(Non_Limited_View
(Etype
(Formal
)))
2117 Formal
:= Next_Formal
(Formal
);
2120 if Ekind
(Subp
) = E_Function
2121 and then From_Limited_With
(Etype
(Subp
))
2122 and then Has_Non_Limited_View
(Etype
(Subp
))
2123 and then Ekind
(Non_Limited_View
(Etype
(Subp
)))
2130 end Has_Limited_View_Types
;
2134 E
: Entity_Id
:= First_Entity
(Pkg_Id
);
2137 while Present
(E
) loop
2138 if Is_Subprogram
(E
)
2139 and then Has_Limited_View_Types
(E
)
2143 -- Recursion on nested packages skipping package renamings
2145 elsif Ekind
(E
) = E_Package
2146 and then No
(Renamed_Entity
(E
))
2147 and then Depends_On_Limited_Views
(E
)
2156 end Depends_On_Limited_Views
;
2162 -- Start of processing for Analyze_Required_Limited_With_Units
2165 -- Cases where no action is required
2167 if not Expander_Active
2168 or else Nkind
(Unit_Node
) /= N_Package_Declaration
2169 or else Main_Unit_Entity
/= Spec_Id
2170 or else Is_Generic_Unit
(Spec_Id
)
2171 or else Unit_Requires_Body
(Spec_Id
)
2172 or else not Has_Limited_With_Clauses
2173 or else not Depends_On_Limited_Views
(Spec_Id
)
2178 -- Perform full analyis of limited-with units to provide the backend
2179 -- with the full-view of shadow entities.
2181 Item
:= First
(Context_Items
(N
));
2182 while Present
(Item
) loop
2183 if Nkind
(Item
) = N_With_Clause
2184 and then Limited_Present
(Item
)
2185 and then not Implicit_With
(Item
)
2187 Semantics
(Library_Unit
(Item
));
2192 end Analyze_Required_Limited_With_Units
;
2194 ----------------------------------
2195 -- Analyze_Subprogram_Body_Stub --
2196 ----------------------------------
2198 -- A subprogram body stub can appear with or without a previous spec. If
2199 -- there is one, then the analysis of the body will find it and verify
2200 -- conformance. The formals appearing in the specification of the stub play
2201 -- no role, except for requiring an additional conformance check. If there
2202 -- is no previous subprogram declaration, the stub acts as a spec, and
2203 -- provides the defining entity for the subprogram.
2205 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
2207 Opts
: Config_Switches_Type
;
2210 Check_Stub_Level
(N
);
2212 -- Verify that the identifier for the stub is unique within this
2213 -- declarative part.
2215 if Nkind
(Parent
(N
)) in
2216 N_Block_Statement | N_Package_Body | N_Subprogram_Body
2218 Decl
:= First
(Declarations
(Parent
(N
)));
2219 while Present
(Decl
) and then Decl
/= N
loop
2220 if Nkind
(Decl
) = N_Subprogram_Body_Stub
2221 and then Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
2222 Chars
(Defining_Unit_Name
(Specification
(N
)))
2224 Error_Msg_N
("identifier for stub is not unique", N
);
2231 -- Retain and restore the configuration options of the enclosing context
2232 -- as the proper body may introduce a set of its own.
2234 Opts
:= Save_Config_Switches
;
2236 -- Treat stub as a body, which checks conformance if there is a previous
2237 -- declaration, or else introduces entity and its signature.
2239 Analyze_Subprogram_Body
(N
);
2240 Analyze_Proper_Body
(N
, Empty
);
2242 Restore_Config_Switches
(Opts
);
2243 end Analyze_Subprogram_Body_Stub
;
2245 ---------------------
2246 -- Analyze_Subunit --
2247 ---------------------
2249 -- A subunit is compiled either by itself (for semantic checking) or as
2250 -- part of compiling the parent (for code generation). In either case, by
2251 -- the time we actually process the subunit, the parent has already been
2252 -- installed and analyzed. The node N is a compilation unit, whose context
2253 -- needs to be treated here, because we come directly here from the parent
2254 -- without calling Analyze_Compilation_Unit.
2256 -- The compilation context includes the explicit context of the subunit,
2257 -- and the context of the parent, together with the parent itself. In order
2258 -- to compile the current context, we remove the one inherited from the
2259 -- parent, in order to have a clean visibility table. We restore the parent
2260 -- context before analyzing the proper body itself. On exit, we remove only
2261 -- the explicit context of the subunit.
2263 -- WARNING: This routine manages SPARK regions. Return statements must be
2264 -- replaced by gotos which jump to the end of the routine and restore the
2267 procedure Analyze_Subunit
(N
: Node_Id
) is
2268 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2269 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2271 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2272 Num_Scopes
: Nat
:= 0;
2273 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2274 Enclosing_Child
: Entity_Id
:= Empty
;
2275 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2277 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2278 Cunit_Boolean_Restrictions_Save
;
2279 -- Save non-partition wide restrictions before processing the subunit.
2280 -- All subunits are analyzed with config restrictions reset and we need
2281 -- to restore these saved values at the end.
2283 procedure Analyze_Subunit_Context
;
2284 -- Capture names in use clauses of the subunit. This must be done before
2285 -- re-installing parent declarations, because items in the context must
2286 -- not be hidden by declarations local to the parent.
2288 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2289 -- Recursive procedure to restore scope of all ancestors of subunit,
2290 -- from outermost in. If parent is not a subunit, the call to install
2291 -- context installs context of spec and (if parent is a child unit) the
2292 -- context of its parents as well. It is confusing that parents should
2293 -- be treated differently in both cases, but the semantics are just not
2296 procedure Re_Install_Use_Clauses
;
2297 -- As part of the removal of the parent scope, the use clauses are
2298 -- removed, to be reinstalled when the context of the subunit has been
2299 -- analyzed. Use clauses may also have been affected by the analysis of
2300 -- the context of the subunit, so they have to be applied again, to
2301 -- insure that the compilation environment of the rest of the parent
2302 -- unit is identical.
2304 procedure Remove_Scope
;
2305 -- Remove current scope from scope stack, and preserve the list of use
2306 -- clauses in it, to be reinstalled after context is analyzed.
2308 -----------------------------
2309 -- Analyze_Subunit_Context --
2310 -----------------------------
2312 procedure Analyze_Subunit_Context
is
2314 Unit_Name
: Entity_Id
;
2317 Analyze_Context
(N
);
2318 Check_No_Elab_Code_All
(N
);
2320 -- Make withed units immediately visible. If child unit, make the
2321 -- ultimate parent immediately visible.
2323 Item
:= First
(Context_Items
(N
));
2324 while Present
(Item
) loop
2325 if Nkind
(Item
) = N_With_Clause
then
2327 -- Protect frontend against previous errors in context clauses
2329 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2330 if Error_Posted
(Item
) then
2334 -- If a subunits has serious syntax errors, the context
2335 -- may not have been loaded. Add a harmless unit name to
2336 -- attempt processing.
2338 if Serious_Errors_Detected
> 0
2339 and then No
(Entity
(Name
(Item
)))
2341 Set_Entity
(Name
(Item
), Standard_Standard
);
2344 Unit_Name
:= Entity
(Name
(Item
));
2346 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2347 exit when Scope
(Unit_Name
) = Standard_Standard
;
2348 Unit_Name
:= Scope
(Unit_Name
);
2350 if No
(Unit_Name
) then
2351 Check_Error_Detected
;
2356 if not Is_Immediately_Visible
(Unit_Name
) then
2357 Set_Is_Immediately_Visible
(Unit_Name
);
2358 Set_Context_Installed
(Item
);
2363 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2364 Analyze
(Name
(Item
));
2366 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2367 Analyze
(Subtype_Mark
(Item
));
2373 -- Reset visibility of withed units. They will be made visible again
2374 -- when we install the subunit context.
2376 Item
:= First
(Context_Items
(N
));
2377 while Present
(Item
) loop
2378 if Nkind
(Item
) = N_With_Clause
2380 -- Protect frontend against previous errors in context clauses
2382 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2383 and then not Error_Posted
(Item
)
2385 Unit_Name
:= Entity
(Name
(Item
));
2387 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2388 exit when Scope
(Unit_Name
) = Standard_Standard
;
2389 Unit_Name
:= Scope
(Unit_Name
);
2392 if Context_Installed
(Item
) then
2393 Set_Is_Immediately_Visible
(Unit_Name
, False);
2394 Set_Context_Installed
(Item
, False);
2400 end Analyze_Subunit_Context
;
2402 ------------------------
2403 -- Re_Install_Parents --
2404 ------------------------
2406 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2410 if Nkind
(Unit
(L
)) = N_Subunit
then
2411 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2414 Install_Context
(L
, False);
2416 -- If the subunit occurs within a child unit, we must restore the
2417 -- immediate visibility of any siblings that may occur in context.
2418 -- In addition, we must reset the previous visibility of the
2419 -- parent unit which is now on the scope stack. This is because
2420 -- the Previous_Visibility was previously set when removing the
2421 -- context. This is necessary to prevent the parent entity from
2422 -- remaining visible after the subunit is compiled. This only
2423 -- has an effect if a homonym exists in a body to be processed
2424 -- later if inlining is enabled.
2426 if Present
(Enclosing_Child
) then
2427 Install_Siblings
(Enclosing_Child
, L
);
2428 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
2434 if Scop
/= Par_Unit
then
2435 Set_Is_Immediately_Visible
(Scop
);
2438 -- Make entities in scope visible again. For child units, restore
2439 -- visibility only if they are actually in context.
2441 E
:= First_Entity
(Current_Scope
);
2442 while Present
(E
) loop
2443 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2444 Set_Is_Immediately_Visible
(E
);
2450 -- A subunit appears within a body, and for a nested subunits all the
2451 -- parents are bodies. Restore full visibility of their private
2454 if Is_Package_Or_Generic_Package
(Scop
) then
2455 Set_In_Package_Body
(Scop
);
2456 Install_Private_Declarations
(Scop
);
2458 end Re_Install_Parents
;
2460 ----------------------------
2461 -- Re_Install_Use_Clauses --
2462 ----------------------------
2464 procedure Re_Install_Use_Clauses
is
2467 for J
in reverse 1 .. Num_Scopes
loop
2468 U
:= Use_Clauses
(J
);
2469 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2470 Install_Use_Clauses
(U
);
2472 end Re_Install_Use_Clauses
;
2478 procedure Remove_Scope
is
2482 Num_Scopes
:= Num_Scopes
+ 1;
2483 Use_Clauses
(Num_Scopes
) :=
2484 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2486 E
:= First_Entity
(Current_Scope
);
2487 while Present
(E
) loop
2488 Set_Is_Immediately_Visible
(E
, False);
2492 if Is_Child_Unit
(Current_Scope
) then
2493 Enclosing_Child
:= Current_Scope
;
2499 Saved_SM
: SPARK_Mode_Type
:= SPARK_Mode
;
2500 Saved_SMP
: Node_Id
:= SPARK_Mode_Pragma
;
2501 -- Save the SPARK mode-related data to restore on exit. Removing
2502 -- enclosing scopes and contexts to provide a clean environment for the
2503 -- context of the subunit will eliminate any previously set SPARK_Mode.
2505 -- Start of processing for Analyze_Subunit
2508 -- For subunit in main extended unit, we reset the configuration values
2509 -- for the non-partition-wide restrictions. For other units reset them.
2511 if In_Extended_Main_Source_Unit
(N
) then
2512 Restore_Config_Cunit_Boolean_Restrictions
;
2514 Reset_Cunit_Boolean_Restrictions
;
2519 Nam
: Node_Id
:= Name
(Unit
(N
));
2522 if Nkind
(Nam
) = N_Selected_Component
then
2523 Nam
:= Selector_Name
(Nam
);
2526 Check_Identifier
(Nam
, Par_Unit
);
2530 if not Is_Empty_List
(Context_Items
(N
)) then
2532 -- Save current use clauses
2535 Remove_Context
(Lib_Unit
);
2537 -- Now remove parents and their context, including enclosing subunits
2538 -- and the outer parent body which is not a subunit.
2540 if Present
(Lib_Spec
) then
2541 Remove_Context
(Lib_Spec
);
2543 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2544 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2546 Remove_Context
(Lib_Spec
);
2549 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2553 if Nkind
(Unit
(Lib_Spec
)) in N_Package_Body | N_Subprogram_Body
2555 Remove_Context
(Library_Unit
(Lib_Spec
));
2559 Set_Is_Immediately_Visible
(Par_Unit
, False);
2561 Analyze_Subunit_Context
;
2563 -- Take into account the effect of any SPARK_Mode configuration
2564 -- pragma, which takes precedence over a different value of
2565 -- SPARK_Mode inherited from the context of the stub.
2567 if SPARK_Mode
/= None
then
2568 Saved_SM
:= SPARK_Mode
;
2569 Saved_SMP
:= SPARK_Mode_Pragma
;
2572 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2573 Set_Is_Immediately_Visible
(Par_Unit
);
2575 -- If the context includes a child unit of the parent of the subunit,
2576 -- the parent will have been removed from visibility, after compiling
2577 -- that cousin in the context. The visibility of the parent must be
2578 -- restored now. This also applies if the context includes another
2579 -- subunit of the same parent which in turn includes a child unit in
2582 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2583 if not Is_Immediately_Visible
(Par_Unit
)
2584 or else (Present
(First_Entity
(Par_Unit
))
2586 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2588 Set_Is_Immediately_Visible
(Par_Unit
);
2589 Install_Visible_Declarations
(Par_Unit
);
2590 Install_Private_Declarations
(Par_Unit
);
2594 Re_Install_Use_Clauses
;
2595 Install_Context
(N
, Chain
=> False);
2597 -- Restore state of suppress flags for current body
2599 Scope_Suppress
:= Svg
;
2601 -- If the subunit is within a child unit, then siblings of any parent
2602 -- unit that appear in the context clause of the subunit must also be
2603 -- made immediately visible.
2605 if Present
(Enclosing_Child
) then
2606 Install_Siblings
(Enclosing_Child
, N
);
2610 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2612 -- Reinstall the SPARK_Mode which was in effect prior to any scope and
2613 -- context manipulations, taking into account a possible SPARK_Mode
2614 -- configuration pragma if present.
2616 Install_SPARK_Mode
(Saved_SM
, Saved_SMP
);
2618 -- If the subunit is part of a compilation unit which is subject to
2619 -- pragma Elaboration_Checks, set the model specified by the pragma
2620 -- because it applies to all parts of the unit.
2622 Install_Elaboration_Model
(Par_Unit
);
2624 -- The syntax rules require a proper body for a subprogram subunit
2626 if Nkind
(Proper_Body
(Sinfo
.Nodes
.Unit
(N
))) = N_Subprogram_Declaration
2628 if Null_Present
(Specification
(Proper_Body
(Sinfo
.Nodes
.Unit
(N
))))
2631 ("null procedure not allowed as subunit",
2632 Proper_Body
(Unit
(N
)));
2635 ("subprogram declaration not allowed as subunit",
2636 Defining_Unit_Name
(Specification
(Proper_Body
(Unit
(N
)))));
2640 Analyze
(Proper_Body
(Unit
(N
)));
2643 -- The subunit may contain a with_clause on a sibling of some ancestor.
2644 -- Removing the context will remove from visibility those ancestor child
2645 -- units, which must be restored to the visibility they have in the
2648 if Present
(Enclosing_Child
) then
2653 while Present
(C
) and then C
/= Standard_Standard
loop
2654 Set_Is_Immediately_Visible
(C
);
2655 Set_Is_Visible_Lib_Unit
(C
);
2661 -- Deal with restore of restrictions
2663 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2664 end Analyze_Subunit
;
2666 ----------------------------
2667 -- Analyze_Task_Body_Stub --
2668 ----------------------------
2670 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2671 Id
: constant Entity_Id
:= Defining_Entity
(N
);
2672 Loc
: constant Source_Ptr
:= Sloc
(N
);
2673 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Id
);
2676 Check_Stub_Level
(N
);
2678 -- First occurrence of name may have been as an incomplete type
2680 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2681 Nam
:= Full_View
(Nam
);
2684 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2685 Error_Msg_N
("missing specification for task body", N
);
2688 Set_Scope
(Id
, Current_Scope
);
2689 Mutate_Ekind
(Id
, E_Task_Body
);
2690 Set_Etype
(Id
, Standard_Void_Type
);
2692 Analyze_Aspect_Specifications
(N
, Id
);
2694 Generate_Reference
(Nam
, Id
, 'b');
2695 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2697 -- Check for duplicate stub, if so give message and terminate
2699 if Has_Completion
(Etype
(Nam
)) then
2700 Error_Msg_N
("duplicate stub for task", N
);
2703 Set_Has_Completion
(Etype
(Nam
));
2706 Analyze_Proper_Body
(N
, Etype
(Nam
));
2708 -- Set elaboration flag to indicate that entity is callable. This
2709 -- cannot be done in the expansion of the body itself, because the
2710 -- proper body is not in a declarative part. This is only done if
2711 -- expansion is active, because the context may be generic and the
2712 -- flag not defined yet.
2714 if Expander_Active
then
2716 Make_Assignment_Statement
(Loc
,
2718 Make_Identifier
(Loc
,
2719 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2720 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2723 end Analyze_Task_Body_Stub
;
2725 -------------------------
2726 -- Analyze_With_Clause --
2727 -------------------------
2729 -- Analyze the declaration of a unit in a with clause. At end, label the
2730 -- with clause with the defining entity for the unit.
2732 procedure Analyze_With_Clause
(N
: Node_Id
) is
2734 -- Retrieve the original kind of the unit node, before analysis. If it
2735 -- is a subprogram instantiation, its analysis below will rewrite the
2736 -- node as the declaration of the wrapper package. If the same
2737 -- instantiation appears indirectly elsewhere in the context, it will
2738 -- have been analyzed already.
2740 Unit_Kind
: constant Node_Kind
:=
2741 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2742 Nam
: constant Node_Id
:= Name
(N
);
2744 Par_Name
: Entity_Id
;
2749 -- Set True if the unit currently being compiled is an internal unit
2751 Restriction_Violation
: Boolean := False;
2752 -- Set True if a with violates a restriction, no point in giving any
2753 -- warnings if we have this definite error.
2755 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2758 U
:= Unit
(Library_Unit
(N
));
2760 -- If this is an internal unit which is a renaming, then this is a
2761 -- violation of No_Obsolescent_Features.
2763 -- Note: this is not quite right if the user defines one of these units
2764 -- himself, but that's a marginal case, and fixing it is hard ???
2766 if Ada_Version
>= Ada_95
2767 and then In_Predefined_Renaming
(U
)
2769 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2770 Check_Restriction
(No_Obsolescent_Features
, N
);
2771 Restriction_Violation
:= True;
2774 if Warn_On_Obsolescent_Feature
then
2776 ("renamed predefined unit is an obsolescent feature "
2777 & "(RM J.1)?j?", N
);
2781 -- Check No_Implementation_Units violation
2783 if Restriction_Check_Required
(No_Implementation_Units
) then
2784 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2787 Check_Restriction
(No_Implementation_Units
, Nam
);
2788 Restriction_Violation
:= True;
2792 -- Several actions are skipped for dummy packages (those supplied for
2793 -- with's where no matching file could be found). Such packages are
2794 -- identified by the Sloc value being set to No_Location.
2796 if Limited_Present
(N
) then
2798 -- Ada 2005 (AI-50217): Build visibility structures but do not
2799 -- analyze the unit.
2801 -- If the designated unit is a predefined unit, which might be used
2802 -- implicitly through the rtsfind machinery, a limited with clause
2803 -- on such a unit is usually pointless, because run-time units are
2804 -- unlikely to appear in mutually dependent units, and because this
2805 -- disables the rtsfind mechanism. We transform such limited with
2806 -- clauses into regular with clauses.
2808 if Sloc
(U
) /= No_Location
then
2809 if In_Predefined_Unit
(U
) then
2810 Set_Limited_Present
(N
, False);
2811 Analyze_With_Clause
(N
);
2813 Build_Limited_Views
(N
);
2820 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2821 -- already detected serious errors then we mark the with-clause nodes as
2822 -- analyzed before the corresponding compilation unit is analyzed. This
2823 -- is done here to protect the frontend against never ending recursion
2824 -- caused by circularities in the sources (because the previous errors
2825 -- may break the regular machine of the compiler implemented in
2826 -- Load_Unit to detect circularities).
2828 if Serious_Errors_Detected
> 0 and then Try_Semantics
then
2832 Semantics
(Library_Unit
(N
));
2834 Intunit
:= Is_Internal_Unit
(Current_Sem_Unit
);
2836 if Sloc
(U
) /= No_Location
then
2838 -- Check restrictions, except that we skip the check if this is an
2839 -- internal unit unless we are compiling the internal unit as the
2840 -- main unit. We also skip this for dummy packages.
2842 Check_Restriction_No_Dependence
(Nam
, N
);
2844 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2845 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2848 -- Deal with special case of GNAT.Current_Exceptions which interacts
2849 -- with the optimization of local raise statements into gotos.
2851 if Nkind
(Nam
) = N_Selected_Component
2852 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2853 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2854 and then Chars
(Selector_Name
(Nam
))
2855 in Name_Most_Recent_Exception | Name_Exception_Traces
2857 Check_Restriction
(No_Exception_Propagation
, N
);
2858 Special_Exception_Package_Used
:= True;
2861 -- Check for inappropriate with of internal implementation unit if we
2862 -- are not compiling an internal unit and also check for withing unit
2863 -- in wrong version of Ada. Do not issue these messages for implicit
2864 -- with's generated by the compiler itself.
2866 if Implementation_Unit_Warnings
2867 and then not Intunit
2868 and then not Implicit_With
(N
)
2869 and then not Restriction_Violation
2871 case Get_Kind_Of_Unit
(Get_Source_Unit
(U
)) is
2872 when Implementation_Unit
=>
2873 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2875 -- Add alternative name if available, otherwise issue a
2876 -- general warning message.
2878 if Error_Msg_Strlen
/= 0 then
2879 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2882 ("\use of this unit is non-portable and "
2883 & "version-dependent?i?", Name
(N
));
2886 when Not_Predefined_Unit | Ada_95_Unit
=>
2887 null; -- no checks needed
2889 when Ada_2005_Unit
=>
2890 if Ada_Version
< Ada_2005
2891 and then Warn_On_Ada_2005_Compatibility
2893 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2896 when Ada_2012_Unit
=>
2897 if Ada_Version
< Ada_2012
2898 and then Warn_On_Ada_2012_Compatibility
2900 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2903 when Ada_2022_Unit
=>
2904 if Ada_Version
< Ada_2022
2905 and then Warn_On_Ada_2022_Compatibility
2907 Error_Msg_N
("& is an Ada 2022 unit?i?", Name
(N
));
2913 -- Semantic analysis of a generic unit is performed on a copy of
2914 -- the original tree. Retrieve the entity on which semantic info
2915 -- actually appears.
2917 if Unit_Kind
in N_Generic_Declaration
then
2918 E_Name
:= Defining_Entity
(U
);
2920 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2921 -- the case of an instantiation, semantic analysis above will have
2922 -- replaced the unit by its instantiated version. If the instance body
2923 -- has been generated, the instance now denotes the body entity. For
2924 -- visibility purposes we need the entity of its spec.
2926 elsif (Unit_Kind
= N_Package_Instantiation
2927 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2928 N_Package_Instantiation
)
2929 and then Nkind
(U
) = N_Package_Body
2931 E_Name
:= Corresponding_Spec
(U
);
2933 elsif Unit_Kind
= N_Package_Instantiation
2934 and then Nkind
(U
) = N_Package_Instantiation
2935 and then Present
(Instance_Spec
(U
))
2937 -- If the instance has not been rewritten as a package declaration,
2938 -- then it appeared already in a previous with clause. Retrieve
2939 -- the entity from the previous instance.
2941 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2943 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2945 -- The visible subprogram is created during instantiation, and is
2946 -- an attribute of the wrapper package. We retrieve the wrapper
2947 -- package directly from the instantiation node. If the instance
2948 -- is inlined the unit is still an instantiation. Otherwise it has
2949 -- been rewritten as the declaration of the wrapper itself.
2951 if Nkind
(U
) in N_Subprogram_Instantiation
then
2954 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2956 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2959 elsif Unit_Kind
= N_Package_Renaming_Declaration
2960 or else Unit_Kind
in N_Generic_Renaming_Declaration
2962 E_Name
:= Defining_Entity
(U
);
2964 elsif Unit_Kind
= N_Subprogram_Body
2965 and then Nkind
(Name
(N
)) = N_Selected_Component
2966 and then not Acts_As_Spec
(Library_Unit
(N
))
2968 -- For a child unit that has no spec, one has been created and
2969 -- analyzed. The entity required is that of the spec.
2971 E_Name
:= Corresponding_Spec
(U
);
2974 E_Name
:= Defining_Entity
(U
);
2977 if Nkind
(Name
(N
)) = N_Selected_Component
then
2979 -- Child unit in a with clause
2981 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2983 -- If this is a child unit without a spec, and it has been analyzed
2984 -- already, a declaration has been created for it. The with_clause
2985 -- must reflect the actual body, and not the generated declaration,
2986 -- to prevent spurious binding errors involving an out-of-date spec.
2987 -- Note that this can only happen if the unit includes more than one
2988 -- with_clause for the child unit (e.g. in separate subunits).
2990 if Unit_Kind
= N_Subprogram_Declaration
2991 and then Analyzed
(Library_Unit
(N
))
2992 and then not Comes_From_Source
(Library_Unit
(N
))
2994 Set_Library_Unit
(N
,
2995 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2999 -- Restore style checks
3001 Style_Check
:= Save_Style_Check
;
3003 -- Record the reference, but do NOT set the unit as referenced, we want
3004 -- to consider the unit as unreferenced if this is the only reference
3007 Set_Entity_With_Checks
(Name
(N
), E_Name
);
3008 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
3010 -- Generate references and check No_Dependence restriction for parents
3012 if Is_Child_Unit
(E_Name
) then
3013 Pref
:= Prefix
(Name
(N
));
3014 Par_Name
:= Scope
(E_Name
);
3015 while Nkind
(Pref
) = N_Selected_Component
loop
3016 Change_Selected_Component_To_Expanded_Name
(Pref
);
3018 if Present
(Entity
(Selector_Name
(Pref
)))
3020 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
3021 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
3023 -- The prefix is a child unit that denotes a renaming declaration.
3024 -- Replace the prefix directly with the renamed unit, because the
3025 -- rest of the prefix is irrelevant to the visibility of the real
3028 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
3032 Set_Entity_With_Checks
(Pref
, Par_Name
);
3034 Generate_Reference
(Par_Name
, Pref
);
3035 Check_Restriction_No_Dependence
(Pref
, N
);
3036 Pref
:= Prefix
(Pref
);
3038 -- If E_Name is the dummy entity for a nonexistent unit, its scope
3039 -- is set to Standard_Standard, and no attempt should be made to
3040 -- further unwind scopes.
3042 if Par_Name
/= Standard_Standard
then
3043 Par_Name
:= Scope
(Par_Name
);
3046 -- Abandon processing in case of previous errors
3048 if No
(Par_Name
) then
3049 Check_Error_Detected
;
3054 if Present
(Entity
(Pref
))
3055 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
3057 -- If the entity is set without its unit being compiled, the
3058 -- original parent is a renaming, and Par_Name is the renamed
3059 -- entity. For visibility purposes, we need the original entity,
3060 -- which must be analyzed now because Load_Unit directly retrieves
3061 -- the renamed unit, and the renaming declaration itself has not
3064 Analyze
(Parent
(Parent
(Entity
(Pref
))));
3065 pragma Assert
(Renamed_Entity
(Entity
(Pref
)) = Par_Name
);
3066 Par_Name
:= Entity
(Pref
);
3069 -- Guard against missing or misspelled child units
3071 if Present
(Par_Name
) then
3072 Set_Entity_With_Checks
(Pref
, Par_Name
);
3073 Generate_Reference
(Par_Name
, Pref
);
3076 pragma Assert
(Serious_Errors_Detected
/= 0);
3078 -- Mark the node to indicate that a related error has been posted.
3079 -- This defends further compilation passes against improper use of
3080 -- the invalid WITH clause node.
3082 Set_Error_Posted
(N
);
3083 Set_Name
(N
, Error
);
3088 -- If the withed unit is System, and a system extension pragma is
3089 -- present, compile the extension now, rather than waiting for a
3090 -- visibility check on a specific entity.
3092 if Chars
(E_Name
) = Name_System
3093 and then Scope
(E_Name
) = Standard_Standard
3094 and then Present
(System_Extend_Unit
)
3095 and then Present_System_Aux
(N
)
3097 -- If the extension is not present, an error will have been emitted
3102 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
3103 -- to private_with units; they will be made visible later (just before
3104 -- the private part is analyzed)
3106 if Private_Present
(N
) then
3107 Set_Is_Immediately_Visible
(E_Name
, False);
3110 -- Propagate Fatal_Error setting from with'ed unit to current unit
3112 case Fatal_Error
(Get_Source_Unit
(Library_Unit
(N
))) is
3114 -- Nothing to do if with'ed unit had no error
3119 -- If with'ed unit had a detected fatal error, propagate it
3121 when Error_Detected
=>
3122 Set_Fatal_Error
(Current_Sem_Unit
, Error_Detected
);
3124 -- If with'ed unit had an ignored error, then propagate it but do not
3125 -- overide an existring setting.
3127 when Error_Ignored
=>
3128 if Fatal_Error
(Current_Sem_Unit
) = None
then
3129 Set_Fatal_Error
(Current_Sem_Unit
, Error_Ignored
);
3132 end Analyze_With_Clause
;
3134 ------------------------------
3135 -- Check_Private_Child_Unit --
3136 ------------------------------
3138 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
3139 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3141 Curr_Unit
: Entity_Id
;
3142 Sub_Parent
: Node_Id
;
3143 Priv_Child
: Entity_Id
;
3144 Par_Lib
: Entity_Id
;
3148 if Nkind
(Lib_Unit
) in N_Package_Body | N_Subprogram_Body
then
3149 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
3150 Par_Lib
:= Curr_Unit
;
3152 elsif Nkind
(Lib_Unit
) = N_Subunit
then
3154 -- The parent is itself a body. The parent entity is to be found in
3155 -- the corresponding spec.
3157 Sub_Parent
:= Library_Unit
(N
);
3158 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
3160 -- If the parent itself is a subunit, Curr_Unit is the entity of the
3161 -- enclosing body, retrieve the spec entity which is the proper
3162 -- ancestor we need for the following tests.
3164 if Ekind
(Curr_Unit
) = E_Package_Body
then
3165 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
3168 Par_Lib
:= Curr_Unit
;
3171 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
3173 Par_Lib
:= Curr_Unit
;
3174 Par_Spec
:= Parent_Spec
(Lib_Unit
);
3176 if No
(Par_Spec
) then
3179 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
3183 -- Loop through context items
3185 Item
:= First
(Context_Items
(N
));
3186 while Present
(Item
) loop
3188 -- Ada 2005 (AI-262): Allow private_with of a private child package
3189 -- in public siblings
3191 if Nkind
(Item
) = N_With_Clause
3192 and then not Implicit_With
(Item
)
3193 and then not Limited_Present
(Item
)
3194 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
3196 Priv_Child
:= Entity
(Name
(Item
));
3199 Curr_Parent
: Entity_Id
:= Par_Lib
;
3200 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
3201 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
3202 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
3205 -- If the child unit is a public child then locate the nearest
3206 -- private ancestor. Child_Parent will then be set to the
3207 -- parent of that ancestor.
3209 if not Is_Private_Library_Unit
(Priv_Child
) then
3210 while Present
(Prv_Ancestor
)
3211 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
3213 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
3216 if Present
(Prv_Ancestor
) then
3217 Child_Parent
:= Scope
(Prv_Ancestor
);
3221 while Present
(Curr_Parent
)
3222 and then Curr_Parent
/= Standard_Standard
3223 and then Curr_Parent
/= Child_Parent
3226 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
3227 Curr_Parent
:= Scope
(Curr_Parent
);
3230 if No
(Curr_Parent
) then
3231 Curr_Parent
:= Standard_Standard
;
3234 if Curr_Parent
/= Child_Parent
then
3235 if Ekind
(Priv_Child
) = E_Generic_Package
3236 and then Chars
(Priv_Child
) in Text_IO_Package_Name
3237 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
3238 and then Scope
(Scope
(Scope
(Priv_Child
))) =
3242 ("& is a nested package, not a compilation unit",
3243 Name
(Item
), Priv_Child
);
3247 ("unit in with clause is private child unit!", Item
);
3249 ("\current unit must also have parent&!",
3250 Item
, Child_Parent
);
3254 or else Private_Present
(Item
)
3255 or else Nkind
(Lib_Unit
) in N_Package_Body | N_Subunit
3256 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3257 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
3263 ("current unit must also be private descendant of&",
3264 Item
, Child_Parent
);
3271 end Check_Private_Child_Unit
;
3273 ----------------------
3274 -- Check_Stub_Level --
3275 ----------------------
3277 procedure Check_Stub_Level
(N
: Node_Id
) is
3278 Par
: constant Node_Id
:= Parent
(N
);
3279 Kind
: constant Node_Kind
:= Nkind
(Par
);
3283 N_Package_Body | N_Subprogram_Body | N_Task_Body | N_Protected_Body
3284 and then Nkind
(Parent
(Par
)) in N_Compilation_Unit | N_Subunit
3288 -- In an instance, a missing stub appears at any level. A warning
3289 -- message will have been emitted already for the missing file.
3291 elsif not In_Instance
then
3292 Error_Msg_N
("stub cannot appear in an inner scope", N
);
3294 elsif Expander_Active
then
3295 Error_Msg_N
("missing proper body", N
);
3297 end Check_Stub_Level
;
3303 procedure Decorate_Type
3306 Is_Tagged
: Boolean := False;
3307 Materialize
: Boolean := False)
3312 -- An unanalyzed type or a shadow entity of a type is treated as an
3313 -- incomplete type, and carries the corresponding attributes.
3315 Mutate_Ekind
(Ent
, E_Incomplete_Type
);
3316 Set_Is_Not_Self_Hidden
(Ent
);
3317 Set_Etype
(Ent
, Ent
);
3318 Set_Full_View
(Ent
, Empty
);
3319 Set_Is_First_Subtype
(Ent
);
3320 Set_Scope
(Ent
, Scop
);
3321 Set_Stored_Constraint
(Ent
, No_Elist
);
3322 Reinit_Size_Align
(Ent
);
3324 if From_Limited_With
(Ent
) then
3325 Set_Private_Dependents
(Ent
, New_Elmt_List
);
3328 -- A tagged type and its corresponding shadow entity share one common
3329 -- class-wide type. The list of primitive operations for the shadow
3333 Set_Is_Tagged_Type
(Ent
);
3334 Set_Direct_Primitive_Operations
(Ent
, New_Elmt_List
);
3338 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
3340 Set_Class_Wide_Type
(Ent
, CW_Typ
);
3342 -- Set parent to be the same as the parent of the tagged type.
3343 -- We need a parent field set, and it is supposed to point to
3344 -- the declaration of the type. The tagged type declaration
3345 -- essentially declares two separate types, the tagged type
3346 -- itself and the corresponding class-wide type, so it is
3347 -- reasonable for the parent fields to point to the declaration
3350 Set_Parent
(CW_Typ
, Parent
(Ent
));
3352 Mutate_Ekind
(CW_Typ
, E_Class_Wide_Type
);
3353 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
3354 Set_Etype
(CW_Typ
, Ent
);
3355 Set_Equivalent_Type
(CW_Typ
, Empty
);
3356 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
3357 Set_Has_Unknown_Discriminants
(CW_Typ
);
3358 Set_Is_First_Subtype
(CW_Typ
);
3359 Set_Is_Tagged_Type
(CW_Typ
);
3360 Set_Materialize_Entity
(CW_Typ
, Materialize
);
3361 Set_Scope
(CW_Typ
, Scop
);
3362 Reinit_Size_Align
(CW_Typ
);
3366 ------------------------
3367 -- Expand_With_Clause --
3368 ------------------------
3370 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
3371 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3373 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3374 -- Build name to be used in implicit with_clause. In most cases this
3375 -- is the source name, but if renamings are present we must make the
3376 -- original unit visible, not the one it renames. The entity in the
3377 -- with clause is the renamed unit, but the identifier is the one from
3378 -- the source, which allows us to recover the unit renaming.
3380 ---------------------
3381 -- Build_Unit_Name --
3382 ---------------------
3384 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3389 if Nkind
(Nam
) = N_Identifier
then
3390 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3393 Ent
:= Entity
(Nam
);
3395 if Present
(Entity
(Selector_Name
(Nam
)))
3396 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3398 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))) =
3399 N_Package_Renaming_Declaration
3401 -- The name in the with_clause is of the form A.B.C, and B is
3402 -- given by a renaming declaration. In that case we may not
3403 -- have analyzed the unit for B, but replaced it directly in
3404 -- lib-load with the unit it renames. We have to make A.B
3405 -- visible, so analyze the declaration for B now, in case it
3406 -- has not been done yet.
3408 Ent
:= Entity
(Selector_Name
(Nam
));
3411 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3415 Make_Expanded_Name
(Loc
,
3416 Chars
=> Chars
(Entity
(Nam
)),
3417 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3418 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3419 Set_Entity
(Result
, Ent
);
3423 end Build_Unit_Name
;
3427 Ent
: constant Entity_Id
:= Entity
(Nam
);
3430 -- Start of processing for Expand_With_Clause
3434 Make_With_Clause
(Loc
,
3435 Name
=> Build_Unit_Name
(Nam
));
3437 Set_Corresponding_Spec
(Withn
, Ent
);
3438 Set_First_Name
(Withn
);
3439 Set_Implicit_With
(Withn
);
3440 Set_Library_Unit
(Withn
, Parent
(Unit_Declaration_Node
(Ent
)));
3441 Set_Parent_With
(Withn
);
3443 -- If the unit is a [generic] package or subprogram declaration
3444 -- (including a subprogram body acting as spec), a private_with_clause
3445 -- on a child unit implies that the implicit with on the parent is also
3448 if Nkind
(Unit
(N
)) in N_Generic_Package_Declaration
3449 | N_Package_Declaration
3450 | N_Generic_Subprogram_Declaration
3451 | N_Subprogram_Declaration
3454 Set_Private_Present
(Withn
, Private_Present
(Item
));
3457 Prepend
(Withn
, Context_Items
(N
));
3458 Mark_Rewrite_Insertion
(Withn
);
3460 Install_With_Clause
(Withn
);
3462 -- If we have "with X.Y;", we want to recurse on "X", except in the
3463 -- unusual case where X.Y is a renaming of X. In that case, the scope
3464 -- of X will be null.
3466 if Nkind
(Nam
) = N_Expanded_Name
3467 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3469 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3471 end Expand_With_Clause
;
3473 --------------------------------
3474 -- Generate_Parent_References --
3475 --------------------------------
3477 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3479 P_Name
: Entity_Id
:= P_Id
;
3482 if Nkind
(N
) = N_Subunit
then
3485 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3488 if Nkind
(Pref
) = N_Expanded_Name
then
3490 -- Done already, if the unit has been compiled indirectly as
3491 -- part of the closure of its context because of inlining.
3496 while Nkind
(Pref
) = N_Selected_Component
loop
3497 Change_Selected_Component_To_Expanded_Name
(Pref
);
3498 Set_Entity
(Pref
, P_Name
);
3499 Set_Etype
(Pref
, Etype
(P_Name
));
3500 Generate_Reference
(P_Name
, Pref
, 'r');
3501 Pref
:= Prefix
(Pref
);
3502 P_Name
:= Scope
(P_Name
);
3505 -- The guard here on P_Name is to handle the error condition where
3506 -- the parent unit is missing because the file was not found.
3508 if Present
(P_Name
) then
3509 Set_Entity
(Pref
, P_Name
);
3510 Set_Etype
(Pref
, Etype
(P_Name
));
3511 Generate_Reference
(P_Name
, Pref
, 'r');
3512 Style
.Check_Identifier
(Pref
, P_Name
);
3514 end Generate_Parent_References
;
3516 ---------------------
3517 -- Has_With_Clause --
3518 ---------------------
3520 function Has_With_Clause
3523 Is_Limited
: Boolean := False) return Boolean
3527 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3528 -- Return the entity for the unit named in a [limited] with clause
3534 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3536 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3537 return Entity
(Selector_Name
(Name
(Clause
)));
3539 return Entity
(Name
(Clause
));
3543 -- Start of processing for Has_With_Clause
3546 Item
:= First
(Context_Items
(C_Unit
));
3547 while Present
(Item
) loop
3548 if Nkind
(Item
) = N_With_Clause
3549 and then Limited_Present
(Item
) = Is_Limited
3550 and then Named_Unit
(Item
) = Pack
3559 end Has_With_Clause
;
3561 -----------------------------
3562 -- Implicit_With_On_Parent --
3563 -----------------------------
3565 procedure Implicit_With_On_Parent
3566 (Child_Unit
: Node_Id
;
3569 Loc
: constant Source_Ptr
:= Sloc
(N
);
3570 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3571 P_Unit
: Node_Id
:= Unit
(P
);
3572 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3575 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3576 -- Build prefix of child unit name. Recurse if needed
3578 function Build_Unit_Name
return Node_Id
;
3579 -- If the unit is a child unit, build qualified name with all ancestors
3581 -------------------------
3582 -- Build_Ancestor_Name --
3583 -------------------------
3585 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3586 P_Ref
: constant Node_Id
:=
3587 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3588 P_Spec
: Node_Id
:= P
;
3591 -- Ancestor may have been rewritten as a package body. Retrieve the
3592 -- original spec to trace earlier ancestors.
3594 if Nkind
(P
) = N_Package_Body
3595 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3597 P_Spec
:= Original_Node
(P
);
3600 if No
(Parent_Spec
(P_Spec
)) then
3604 Make_Selected_Component
(Loc
,
3606 Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3607 Selector_Name
=> P_Ref
);
3609 end Build_Ancestor_Name
;
3611 ---------------------
3612 -- Build_Unit_Name --
3613 ---------------------
3615 function Build_Unit_Name
return Node_Id
is
3619 if No
(Parent_Spec
(P_Unit
)) then
3620 return New_Occurrence_Of
(P_Name
, Loc
);
3624 Make_Expanded_Name
(Loc
,
3625 Chars
=> Chars
(P_Name
),
3627 Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3628 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3629 Set_Entity
(Result
, P_Name
);
3633 end Build_Unit_Name
;
3635 -- Start of processing for Implicit_With_On_Parent
3638 -- The unit of the current compilation may be a package body that
3639 -- replaces an instance node. In this case we need the original instance
3640 -- node to construct the proper parent name.
3642 if Nkind
(P_Unit
) = N_Package_Body
3643 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3645 P_Unit
:= Original_Node
(P_Unit
);
3648 -- We add the implicit with if the child unit is the current unit being
3649 -- compiled. If the current unit is a body, we do not want to add an
3650 -- implicit_with a second time to the corresponding spec.
3652 if Nkind
(Child_Unit
) = N_Package_Declaration
3653 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3658 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3660 Set_Corresponding_Spec
(Withn
, P_Name
);
3661 Set_First_Name
(Withn
);
3662 Set_Implicit_With
(Withn
);
3663 Set_Library_Unit
(Withn
, P
);
3664 Set_Parent_With
(Withn
);
3666 -- Node is placed at the beginning of the context items, so that
3667 -- subsequent use clauses on the parent can be validated.
3669 Prepend
(Withn
, Context_Items
(N
));
3670 Mark_Rewrite_Insertion
(Withn
);
3672 Install_With_Clause
(Withn
);
3674 if Is_Child_Spec
(P_Unit
) then
3675 Implicit_With_On_Parent
(P_Unit
, N
);
3677 end Implicit_With_On_Parent
;
3683 function In_Chain
(E
: Entity_Id
) return Boolean is
3687 H
:= Current_Entity
(E
);
3688 while Present
(H
) loop
3699 ---------------------
3700 -- Install_Context --
3701 ---------------------
3703 procedure Install_Context
(N
: Node_Id
; Chain
: Boolean := True) is
3704 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3707 Install_Context_Clauses
(N
, Chain
);
3709 if Is_Child_Spec
(Lib_Unit
) then
3711 (Lib_Unit
=> Lib_Unit
,
3712 Is_Private
=> Private_Present
(Parent
(Lib_Unit
)),
3716 Install_Limited_Context_Clauses
(N
);
3717 end Install_Context
;
3719 -----------------------------
3720 -- Install_Context_Clauses --
3721 -----------------------------
3723 procedure Install_Context_Clauses
(N
: Node_Id
; Chain
: Boolean := True) is
3724 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3726 Uname_Node
: Entity_Id
;
3727 Check_Private
: Boolean := False;
3728 Decl_Node
: Node_Id
;
3729 Lib_Parent
: Entity_Id
;
3732 -- First skip configuration pragmas at the start of the context. They
3733 -- are not technically part of the context clause, but that's where the
3734 -- parser puts them. Note they were analyzed in Analyze_Context.
3736 Item
:= First
(Context_Items
(N
));
3737 while Present
(Item
)
3738 and then Nkind
(Item
) = N_Pragma
3739 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
3744 -- Loop through the actual context clause items. We process everything
3745 -- except Limited_With clauses in this routine. Limited_With clauses
3746 -- are separately installed (see Install_Limited_Context_Clauses).
3748 while Present
(Item
) loop
3750 -- Case of explicit WITH clause
3752 if Nkind
(Item
) = N_With_Clause
3753 and then not Implicit_With
(Item
)
3755 if Limited_Present
(Item
) then
3757 -- Limited withed units will be installed later
3761 -- If Name (Item) is not an entity name, something is wrong, and
3762 -- this will be detected in due course, for now ignore the item
3764 elsif not Is_Entity_Name
(Name
(Item
)) then
3767 elsif No
(Entity
(Name
(Item
))) then
3768 Set_Entity
(Name
(Item
), Any_Id
);
3772 Uname_Node
:= Entity
(Name
(Item
));
3774 if Is_Private_Descendant
(Uname_Node
) then
3775 Check_Private
:= True;
3778 Install_With_Clause
(Item
);
3780 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3782 -- If the unit is a subprogram instance, it appears nested within
3783 -- a package that carries the parent information.
3785 if Is_Generic_Instance
(Uname_Node
)
3786 and then Ekind
(Uname_Node
) /= E_Package
3788 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3791 if Is_Child_Spec
(Decl_Node
) then
3792 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3793 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3795 -- If not an expanded name, the child unit must be a
3796 -- renaming, nothing to do.
3801 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3802 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3803 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3805 Implicit_With_On_Parent
3806 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3809 -- Check license conditions unless this is a dummy unit
3811 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3812 License_Check
: declare
3813 Withu
: constant Unit_Number_Type
:=
3814 Get_Source_Unit
(Library_Unit
(Item
));
3815 Withl
: constant License_Type
:=
3816 License
(Source_Index
(Withu
));
3817 Unitl
: constant License_Type
:=
3818 License
(Source_Index
(Current_Sem_Unit
));
3820 procedure License_Error
;
3821 -- Signal error of bad license
3827 procedure License_Error
is
3830 ("license of withed unit & may be inconsistent??",
3834 -- Start of processing for License_Check
3837 -- Exclude license check if withed unit is an internal unit.
3838 -- This situation arises e.g. with the GPL version of GNAT.
3840 if Is_Internal_Unit
(Withu
) then
3843 -- Otherwise check various cases
3855 if Withl
= Restricted
then
3859 when Modified_GPL
=>
3860 if Withl
= Restricted
or else Withl
= GPL
then
3864 when Unrestricted
=>
3871 -- Case of USE PACKAGE clause
3873 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3874 Analyze_Use_Package
(Item
, Chain
);
3876 -- Case of USE TYPE clause
3878 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3879 Analyze_Use_Type
(Item
, Chain
);
3883 elsif Nkind
(Item
) = N_Pragma
then
3891 if Is_Child_Spec
(Lib_Unit
) then
3893 -- The unit also has implicit with_clauses on its own parents
3895 if No
(Context_Items
(N
)) then
3896 Set_Context_Items
(N
, New_List
);
3899 Implicit_With_On_Parent
(Lib_Unit
, N
);
3902 -- If the unit is a body, the context of the specification must also
3903 -- be installed. That includes private with_clauses in that context.
3905 if Nkind
(Lib_Unit
) = N_Package_Body
3906 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3907 and then not Acts_As_Spec
(N
))
3909 Install_Context
(Library_Unit
(N
), Chain
);
3911 -- Only install private with-clauses of a spec that comes from
3912 -- source, excluding specs created for a subprogram body that is
3915 if Comes_From_Source
(Library_Unit
(N
)) then
3916 Install_Private_With_Clauses
3917 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3920 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3922 -- If the unit is the body of a public child unit, the private
3923 -- declarations of the parent must be made visible. If the child
3924 -- unit is private, the private declarations have been installed
3925 -- already in the call to Install_Parents for the spec. Installing
3926 -- private declarations must be done for all ancestors of public
3927 -- child units. In addition, sibling units mentioned in the
3928 -- context clause of the body are directly visible.
3936 Lib_Spec
:= Unit
(Library_Unit
(N
));
3937 while Is_Child_Spec
(Lib_Spec
) loop
3938 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3939 P_Name
:= Defining_Entity
(P
);
3941 if not (Private_Present
(Parent
(Lib_Spec
)))
3942 and then not In_Private_Part
(P_Name
)
3944 Install_Private_Declarations
(P_Name
);
3945 Install_Private_With_Clauses
(P_Name
);
3946 Set_Use
(Private_Declarations
(Specification
(P
)));
3954 -- For a package body, children in context are immediately visible
3956 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3959 if Nkind
(Lib_Unit
) in N_Generic_Package_Declaration
3960 | N_Generic_Subprogram_Declaration
3961 | N_Package_Declaration
3962 | N_Subprogram_Declaration
3964 if Is_Child_Spec
(Lib_Unit
) then
3965 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3966 Set_Is_Private_Descendant
3967 (Defining_Entity
(Lib_Unit
),
3968 Is_Private_Descendant
(Lib_Parent
)
3969 or else Private_Present
(Parent
(Lib_Unit
)));
3972 Set_Is_Private_Descendant
3973 (Defining_Entity
(Lib_Unit
),
3974 Private_Present
(Parent
(Lib_Unit
)));
3978 if Check_Private
then
3979 Check_Private_Child_Unit
(N
);
3981 end Install_Context_Clauses
;
3983 -------------------------------------
3984 -- Install_Limited_Context_Clauses --
3985 -------------------------------------
3987 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3990 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3991 -- Check that the unlimited view of a given compilation_unit is not
3992 -- already visible through "use + renamings".
3994 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3995 -- Check that if a limited_with clause of a given compilation_unit
3996 -- mentions a descendant of a private child of some library unit, then
3997 -- the given compilation_unit must be the declaration of a private
3998 -- descendant of that library unit, or a public descendant of such. The
3999 -- code is analogous to that of Check_Private_Child_Unit but we cannot
4000 -- use entities on the limited with_clauses because their units have not
4001 -- been analyzed, so we have to climb the tree of ancestors looking for
4002 -- private keywords.
4004 procedure Expand_Limited_With_Clause
4005 (Comp_Unit
: Node_Id
;
4008 -- If a child unit appears in a limited_with clause, there are implicit
4009 -- limited_with clauses on all parents that are not already visible
4010 -- through a regular with clause. This procedure creates the implicit
4011 -- limited with_clauses for the parents and loads the corresponding
4012 -- units. The shadow entities are created when the inserted clause is
4013 -- analyzed. Implements Ada 2005 (AI-50217).
4015 ---------------------
4016 -- Check_Renamings --
4017 ---------------------
4019 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
4027 pragma Assert
(Nkind
(W
) = N_With_Clause
);
4029 -- Protect the frontend against previous critical errors
4031 case Nkind
(Unit
(Library_Unit
(W
))) is
4032 when N_Generic_Package_Declaration
4033 | N_Generic_Subprogram_Declaration
4034 | N_Package_Declaration
4035 | N_Subprogram_Declaration
4043 -- Check "use + renamings"
4045 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
4046 Spec
:= Specification
(Unit
(P
));
4048 Item
:= First
(Visible_Declarations
(Spec
));
4049 while Present
(Item
) loop
4051 -- Look only at use package clauses
4053 if Nkind
(Item
) = N_Use_Package_Clause
then
4055 E
:= Entity
(Name
(Item
));
4057 pragma Assert
(Present
(Parent
(E
)));
4059 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
4060 and then Renamed_Entity
(E
) = WEnt
4062 -- The unlimited view is visible through use clause and
4063 -- renamings. There is no need to generate the error
4064 -- message here because Is_Visible_Through_Renamings
4065 -- takes care of generating the precise error message.
4069 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
4071 -- The use clause may refer to a local package.
4072 -- Check all the enclosing scopes.
4075 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
4081 ("unlimited view visible through use clause", W
);
4090 -- Recursive call to check all the ancestors
4092 if Is_Child_Spec
(Unit
(P
)) then
4093 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
4095 end Check_Renamings
;
4097 ---------------------------------------
4098 -- Check_Private_Limited_Withed_Unit --
4099 ---------------------------------------
4101 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
4102 Curr_Parent
: Node_Id
;
4103 Child_Parent
: Node_Id
;
4104 Curr_Private
: Boolean;
4107 -- Compilation unit of the parent of the withed library unit
4109 Child_Parent
:= Library_Unit
(Item
);
4111 -- If the child unit is a public child, then locate its nearest
4112 -- private ancestor, if any, then Child_Parent will then be set to
4113 -- the parent of that ancestor.
4115 if not Private_Present
(Library_Unit
(Item
)) then
4116 while Present
(Child_Parent
)
4117 and then not Private_Present
(Child_Parent
)
4119 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
4122 if No
(Child_Parent
) then
4127 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
4129 -- Traverse all the ancestors of the current compilation unit to
4130 -- check if it is a descendant of named library unit.
4132 Curr_Parent
:= Parent
(Item
);
4133 Curr_Private
:= Private_Present
(Curr_Parent
);
4135 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
4136 and then Curr_Parent
/= Child_Parent
4138 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
4139 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
4142 if Curr_Parent
/= Child_Parent
then
4144 ("unit in with clause is private child unit!", Item
);
4146 ("\current unit must also have parent&!",
4147 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
4149 elsif Private_Present
(Parent
(Item
))
4150 or else Curr_Private
4151 or else Private_Present
(Item
)
4152 or else Nkind
(Unit
(Parent
(Item
))) in
4153 N_Package_Body | N_Subprogram_Body | N_Subunit
4155 -- Current unit is private, of descendant of a private unit
4161 ("current unit must also be private descendant of&",
4162 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
4164 end Check_Private_Limited_Withed_Unit
;
4166 --------------------------------
4167 -- Expand_Limited_With_Clause --
4168 --------------------------------
4170 procedure Expand_Limited_With_Clause
4171 (Comp_Unit
: Node_Id
;
4175 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
4176 Unum
: Unit_Number_Type
;
4179 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
4180 -- Returns true if the context already includes a with_clause for
4181 -- this unit. If the with_clause is nonlimited, the unit is fully
4182 -- visible and an implicit limited_with should not be created. If
4183 -- there is already a limited_with clause for W, a second one is
4184 -- simply redundant.
4186 --------------------------
4187 -- Previous_Withed_Unit --
4188 --------------------------
4190 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
4194 -- A limited with_clause cannot appear in the same context_clause
4195 -- as a nonlimited with_clause which mentions the same library.
4197 Item
:= First
(Context_Items
(Comp_Unit
));
4198 while Present
(Item
) loop
4199 if Nkind
(Item
) = N_With_Clause
4200 and then Library_Unit
(Item
) = Library_Unit
(W
)
4209 end Previous_Withed_Unit
;
4211 -- Start of processing for Expand_Limited_With_Clause
4214 if Nkind
(Nam
) = N_Identifier
then
4216 -- Create node for name of withed unit
4219 Make_With_Clause
(Loc
,
4220 Name
=> New_Copy
(Nam
));
4222 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
4224 Make_With_Clause
(Loc
,
4225 Name
=> Make_Selected_Component
(Loc
,
4226 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
4227 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
4228 Set_Parent
(Withn
, Parent
(N
));
4231 Set_First_Name
(Withn
);
4232 Set_Implicit_With
(Withn
);
4233 Set_Limited_Present
(Withn
);
4237 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
4242 -- Do not generate a limited_with_clause on the current unit. This
4243 -- path is taken when a unit has a limited_with clause on one of its
4246 if Unum
= Current_Sem_Unit
then
4250 Set_Library_Unit
(Withn
, Cunit
(Unum
));
4251 Set_Corresponding_Spec
4252 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
4254 if not Previous_Withed_Unit
(Withn
) then
4255 Prepend
(Withn
, Context_Items
(Parent
(N
)));
4256 Mark_Rewrite_Insertion
(Withn
);
4258 -- Add implicit limited_with_clauses for parents of child units
4259 -- mentioned in limited_with clauses.
4261 if Nkind
(Nam
) = N_Selected_Component
then
4262 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
4267 if not Limited_View_Installed
(Withn
) then
4268 Install_Limited_With_Clause
(Withn
);
4271 end Expand_Limited_With_Clause
;
4273 -- Start of processing for Install_Limited_Context_Clauses
4276 Item
:= First
(Context_Items
(N
));
4277 while Present
(Item
) loop
4278 if Nkind
(Item
) = N_With_Clause
4279 and then Limited_Present
(Item
)
4280 and then not Error_Posted
(Item
)
4282 if Nkind
(Name
(Item
)) = N_Selected_Component
then
4283 Expand_Limited_With_Clause
4284 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
4287 Check_Private_Limited_Withed_Unit
(Item
);
4289 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
4290 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
4293 -- A unit may have a limited with on itself if it has a limited
4294 -- with_clause on one of its child units. In that case it is
4295 -- already being compiled and it makes no sense to install its
4298 -- If the item is a limited_private_with_clause, install it if the
4299 -- current unit is a body or if it is a private child. Otherwise
4300 -- the private clause is installed before analyzing the private
4301 -- part of the current unit.
4303 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
4304 and then not Limited_View_Installed
(Item
)
4306 not Is_Ancestor_Unit
4307 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
4309 if not Private_Present
(Item
)
4310 or else Private_Present
(N
)
4311 or else Nkind
(Unit
(N
)) in
4312 N_Package_Body | N_Subprogram_Body | N_Subunit
4314 Install_Limited_With_Clause
(Item
);
4322 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
4323 -- looking for incomplete subtype declarations of incomplete types
4324 -- visible through a limited with clause.
4326 if Ada_Version
>= Ada_2005
4327 and then Analyzed
(N
)
4328 and then Nkind
(Unit
(N
)) = N_Package_Declaration
4333 Non_Lim_View
: Entity_Id
;
4336 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
4337 while Present
(Decl
) loop
4338 if Nkind
(Decl
) = N_Subtype_Declaration
4340 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
4342 From_Limited_With
(Defining_Identifier
(Decl
))
4344 Def_Id
:= Defining_Identifier
(Decl
);
4345 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
4347 if not Is_Incomplete_Type
(Non_Lim_View
) then
4349 -- Convert an incomplete subtype declaration into a
4350 -- corresponding nonlimited view subtype declaration.
4351 -- This is usually the case when analyzing a body that
4352 -- has regular with clauses, when the spec has limited
4355 -- If the nonlimited view is still incomplete, it is
4356 -- the dummy entry already created, and the declaration
4357 -- cannot be reanalyzed. This is the case when installing
4358 -- a parent unit that has limited with-clauses.
4360 Set_Subtype_Indication
(Decl
,
4361 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
4362 Set_Etype
(Def_Id
, Non_Lim_View
);
4363 Reinit_Field_To_Zero
(Def_Id
, F_Non_Limited_View
,
4364 Old_Ekind
=> (E_Incomplete_Subtype
=> True,
4366 Reinit_Field_To_Zero
(Def_Id
, F_Private_Dependents
);
4368 (Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
4369 Set_Analyzed
(Decl
, False);
4371 -- Reanalyze the declaration, suppressing the call to
4372 -- Enter_Name to avoid duplicate names.
4374 Analyze_Subtype_Declaration
4384 end Install_Limited_Context_Clauses
;
4386 ---------------------
4387 -- Install_Parents --
4388 ---------------------
4390 procedure Install_Parents
4391 (Lib_Unit
: Node_Id
;
4392 Is_Private
: Boolean;
4393 Chain
: Boolean := True)
4401 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4402 P_Name
:= Get_Parent_Entity
(P
);
4404 if Etype
(P_Name
) = Any_Type
then
4408 if Ekind
(P_Name
) = E_Generic_Package
4409 and then Nkind
(Lib_Unit
) not in N_Generic_Declaration
4410 | N_Generic_Renaming_Declaration
4413 ("child of a generic package must be a generic unit", Lib_Unit
);
4415 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4417 ("parent unit must be package or generic package", Lib_Unit
);
4418 raise Unrecoverable_Error
;
4420 elsif Present
(Renamed_Entity
(P_Name
)) then
4421 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4422 raise Unrecoverable_Error
;
4424 -- Verify that a child of an instance is itself an instance, or the
4425 -- renaming of one. Given that an instance that is a unit is replaced
4426 -- with a package declaration, check against the original node. The
4427 -- parent may be currently being instantiated, in which case it appears
4428 -- as a declaration, but the generic_parent is already established
4429 -- indicating that we deal with an instance.
4431 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4432 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4433 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4435 (Nkind
(Lib_Unit
) = N_Package_Declaration
4436 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4441 ("child of an instance must be an instance or renaming",
4446 -- This is the recursive call that ensures all parents are loaded
4448 if Is_Child_Spec
(P
) then
4452 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)),
4456 -- Now we can install the context for this parent
4458 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
), Chain
);
4459 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4460 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4462 -- The child unit is in the declarative region of the parent. The parent
4463 -- must therefore appear in the scope stack and be visible, as when
4464 -- compiling the corresponding body. If the child unit is private or it
4465 -- is a package body, private declarations must be accessible as well.
4466 -- Use declarations in the parent must also be installed. Finally, other
4467 -- child units of the same parent that are in the context are
4468 -- immediately visible.
4470 -- Find entity for compilation unit, and set its private descendant
4471 -- status as needed. Indicate that it is a compilation unit, which is
4472 -- redundant in general, but needed if this is a generated child spec
4473 -- for a child body without previous spec.
4475 E_Name
:= Defining_Entity
(Lib_Unit
);
4477 Set_Is_Child_Unit
(E_Name
);
4478 Set_Is_Compilation_Unit
(E_Name
);
4480 Set_Is_Private_Descendant
(E_Name
,
4481 Is_Private_Descendant
(P_Name
)
4482 or else Private_Present
(Parent
(Lib_Unit
)));
4484 P_Spec
:= Package_Specification
(P_Name
);
4485 Push_Scope
(P_Name
);
4487 -- Save current visibility of unit
4489 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4490 Is_Immediately_Visible
(P_Name
);
4491 Set_Is_Immediately_Visible
(P_Name
);
4492 Install_Visible_Declarations
(P_Name
);
4493 Set_Use
(Visible_Declarations
(P_Spec
));
4495 -- If the parent is a generic unit, its formal part may contain formal
4496 -- packages and use clauses for them.
4498 if Ekind
(P_Name
) = E_Generic_Package
then
4499 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4502 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4503 Install_Private_Declarations
(P_Name
);
4504 Install_Private_With_Clauses
(P_Name
);
4505 Set_Use
(Private_Declarations
(P_Spec
));
4507 end Install_Parents
;
4509 ----------------------------------
4510 -- Install_Private_With_Clauses --
4511 ----------------------------------
4513 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4514 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4518 if Debug_Flag_I
then
4519 Write_Str
("install private with clauses of ");
4520 Write_Name
(Chars
(P
));
4524 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4525 Item
:= First
(Context_Items
(Parent
(Decl
)));
4526 while Present
(Item
) loop
4527 if Nkind
(Item
) = N_With_Clause
4528 and then Private_Present
(Item
)
4530 -- If the unit is an ancestor of the current one, it is the
4531 -- case of a private limited with clause on a child unit, and
4532 -- the compilation of one of its descendants, In that case the
4533 -- limited view is errelevant.
4535 if Limited_Present
(Item
) then
4536 if not Limited_View_Installed
(Item
)
4538 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4539 Cunit
(Current_Sem_Unit
))
4541 Install_Limited_With_Clause
(Item
);
4544 Install_With_Clause
(Item
, Private_With_OK
=> True);
4551 end Install_Private_With_Clauses
;
4553 ----------------------
4554 -- Install_Siblings --
4555 ----------------------
4557 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4563 -- Iterate over explicit with clauses, and check whether the scope of
4564 -- each entity is an ancestor of the current unit, in which case it is
4565 -- immediately visible.
4567 Item
:= First
(Context_Items
(N
));
4568 while Present
(Item
) loop
4570 -- Do not install private_with_clauses declaration, unless unit
4571 -- is itself a private child unit, or is a body. Note that for a
4572 -- subprogram body the private_with_clause does not take effect
4573 -- until after the specification.
4575 if Nkind
(Item
) /= N_With_Clause
4576 or else Implicit_With
(Item
)
4577 or else Limited_Present
(Item
)
4578 or else Error_Posted
(Item
)
4580 -- Skip processing malformed trees
4582 or else (Try_Semantics
4583 and then Nkind
(Name
(Item
)) not in N_Has_Entity
)
4587 elsif not Private_Present
(Item
)
4588 or else Private_Present
(N
)
4589 or else Nkind
(Unit
(N
)) = N_Package_Body
4591 Id
:= Entity
(Name
(Item
));
4593 if Is_Child_Unit
(Id
)
4594 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4596 Set_Is_Immediately_Visible
(Id
);
4598 -- Check for the presence of another unit in the context that
4599 -- may be inadvertently hidden by the child.
4601 Prev
:= Current_Entity
(Id
);
4604 and then Is_Immediately_Visible
(Prev
)
4605 and then not Is_Child_Unit
(Prev
)
4611 Clause
:= First
(Context_Items
(N
));
4612 while Present
(Clause
) loop
4613 if Nkind
(Clause
) = N_With_Clause
4614 and then Entity
(Name
(Clause
)) = Prev
4617 ("child unit& hides compilation unit " &
4618 "with the same name??",
4628 -- The With_Clause may be on a grandchild or one of its further
4629 -- descendants, which makes a child immediately visible. Examine
4630 -- ancestry to determine whether such a child exists. For example,
4631 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4632 -- is immediately visible.
4634 elsif Is_Child_Unit
(Id
) then
4640 while Is_Child_Unit
(Par
) loop
4641 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4642 Set_Is_Immediately_Visible
(Par
);
4651 -- If the item is a private with-clause on a child unit, the parent
4652 -- may have been installed already, but the child unit must remain
4653 -- invisible until installed in a private part or body, unless there
4654 -- is already a regular with_clause for it in the current unit.
4656 elsif Private_Present
(Item
) then
4657 Id
:= Entity
(Name
(Item
));
4659 if Is_Child_Unit
(Id
) then
4663 function In_Context
return Boolean;
4664 -- Scan context of current unit, to check whether there is
4665 -- a with_clause on the same unit as a private with-clause
4666 -- on a parent, in which case child unit is visible. If the
4667 -- unit is a grandchild, the same applies to its parent.
4673 function In_Context
return Boolean is
4676 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4677 while Present
(Clause
) loop
4678 if Nkind
(Clause
) = N_With_Clause
4679 and then Comes_From_Source
(Clause
)
4680 and then Is_Entity_Name
(Name
(Clause
))
4681 and then not Private_Present
(Clause
)
4683 if Entity
(Name
(Clause
)) = Id
4685 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4686 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4699 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4706 end Install_Siblings
;
4708 ---------------------------------
4709 -- Install_Limited_With_Clause --
4710 ---------------------------------
4712 procedure Install_Limited_With_Clause
(N
: Node_Id
) is
4713 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4716 Is_Child_Package
: Boolean := False;
4717 Lim_Header
: Entity_Id
;
4718 Lim_Typ
: Entity_Id
;
4720 procedure Check_Body_Required
;
4721 -- A unit mentioned in a limited with_clause may not be mentioned in
4722 -- a regular with_clause, but must still be included in the current
4723 -- partition. We need to determine whether the unit needs a body, so
4724 -- that the binder can determine the name of the file to be compiled.
4725 -- Checking whether a unit needs a body can be done without semantic
4726 -- analysis, by examining the nature of the declarations in the package.
4728 function Has_Limited_With_Clause
4729 (C_Unit
: Entity_Id
;
4730 Pack
: Entity_Id
) return Boolean;
4731 -- Determine whether any package in the ancestor chain starting with
4732 -- C_Unit has a limited with clause for package Pack.
4734 -------------------------
4735 -- Check_Body_Required --
4736 -------------------------
4738 procedure Check_Body_Required
is
4739 PA
: constant List_Id
:=
4740 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4742 procedure Check_Declarations
(Spec
: Node_Id
);
4743 -- Recursive procedure that does the work and checks nested packages
4745 ------------------------
4746 -- Check_Declarations --
4747 ------------------------
4749 procedure Check_Declarations
(Spec
: Node_Id
) is
4751 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4753 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4755 procedure Check_Pragma_Import
(P
: Node_Id
);
4756 -- If a pragma import applies to a previous subprogram, the
4757 -- enclosing unit may not need a body. The processing is syntactic
4758 -- and does not require a declaration to be analyzed. The code
4759 -- below also handles pragma Import when applied to a subprogram
4760 -- that renames another. In this case the pragma applies to the
4763 -- Chains of multiple renames are not handled by the code below.
4764 -- It is probably impossible to handle all cases without proper
4765 -- name resolution. In such cases the algorithm is conservative
4766 -- and will indicate that a body is needed???
4768 -------------------------
4769 -- Check_Pragma_Import --
4770 -------------------------
4772 procedure Check_Pragma_Import
(P
: Node_Id
) is
4778 procedure Remove_Homonyms
(E
: Node_Id
);
4779 -- Make one pass over list of subprograms. Called again if
4780 -- subprogram is a renaming. E is known to be an identifier.
4782 ---------------------
4783 -- Remove_Homonyms --
4784 ---------------------
4786 procedure Remove_Homonyms
(E
: Node_Id
) is
4787 R
: Entity_Id
:= Empty
;
4788 -- Name of renamed entity, if any
4791 Subp_Id
:= First_Elmt
(Subp_List
);
4792 while Present
(Subp_Id
) loop
4793 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4794 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4795 /= N_Subprogram_Renaming_Declaration
4798 Next_Elmt
(Subp_Id
);
4799 Remove_Elmt
(Subp_List
, Prev_Id
);
4801 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4805 Next_Elmt
(Subp_Id
);
4810 if Nkind
(R
) = N_Identifier
then
4811 Remove_Homonyms
(R
);
4813 elsif Nkind
(R
) = N_Selected_Component
then
4814 Remove_Homonyms
(Selector_Name
(R
));
4816 -- Renaming of attribute
4822 end Remove_Homonyms
;
4824 -- Start of processing for Check_Pragma_Import
4827 -- Find name of entity in Import pragma. We have not analyzed
4828 -- the construct, so we must guard against syntax errors.
4830 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4833 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4837 Imported
:= Expression
(Arg
);
4840 Remove_Homonyms
(Imported
);
4841 end Check_Pragma_Import
;
4843 -- Start of processing for Check_Declarations
4846 -- Search for Elaborate Body pragma
4848 Decl
:= First
(Visible_Declarations
(Spec
));
4849 while Present
(Decl
)
4850 and then Nkind
(Decl
) = N_Pragma
4852 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4853 Set_Body_Required
(Library_Unit
(N
));
4860 -- Look for declarations that require the presence of a body. We
4861 -- have already skipped pragmas at the start of the list.
4863 while Present
(Decl
) loop
4865 -- Subprogram that comes from source means body may be needed.
4866 -- Save for subsequent examination of import pragmas.
4868 if Comes_From_Source
(Decl
)
4869 and then Nkind
(Decl
) in N_Subprogram_Declaration
4870 | N_Subprogram_Renaming_Declaration
4871 | N_Generic_Subprogram_Declaration
4873 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4875 -- Package declaration of generic package declaration. We need
4876 -- to recursively examine nested declarations.
4878 elsif Nkind
(Decl
) in N_Package_Declaration
4879 | N_Generic_Package_Declaration
4881 Check_Declarations
(Specification
(Decl
));
4883 elsif Nkind
(Decl
) = N_Pragma
4884 and then Pragma_Name
(Decl
) = Name_Import
4886 Check_Pragma_Import
(Decl
);
4892 -- Same set of tests for private part. In addition to subprograms
4893 -- detect the presence of Taft Amendment types (incomplete types
4894 -- completed in the body).
4896 Decl
:= First
(Private_Declarations
(Spec
));
4897 while Present
(Decl
) loop
4898 if Comes_From_Source
(Decl
)
4899 and then Nkind
(Decl
) in N_Subprogram_Declaration
4900 | N_Subprogram_Renaming_Declaration
4901 | N_Generic_Subprogram_Declaration
4903 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4905 elsif Nkind
(Decl
) in N_Package_Declaration
4906 | N_Generic_Package_Declaration
4908 Check_Declarations
(Specification
(Decl
));
4910 -- Collect incomplete type declarations for separate pass
4912 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4913 Append_Elmt
(Decl
, Incomplete_Decls
);
4915 elsif Nkind
(Decl
) = N_Pragma
4916 and then Pragma_Name
(Decl
) = Name_Import
4918 Check_Pragma_Import
(Decl
);
4924 -- Now check incomplete declarations to locate Taft amendment
4925 -- types. This can be done by examining the defining identifiers
4926 -- of type declarations without real semantic analysis.
4932 Inc
:= First_Elmt
(Incomplete_Decls
);
4933 while Present
(Inc
) loop
4934 Decl
:= Next
(Node
(Inc
));
4935 while Present
(Decl
) loop
4936 if Nkind
(Decl
) = N_Full_Type_Declaration
4937 and then Chars
(Defining_Identifier
(Decl
)) =
4938 Chars
(Defining_Identifier
(Node
(Inc
)))
4946 -- If no completion, this is a TAT, and a body is needed
4949 Set_Body_Required
(Library_Unit
(N
));
4957 -- Finally, check whether there are subprograms that still require
4958 -- a body, i.e. are not renamings or null.
4960 if not Is_Empty_Elmt_List
(Subp_List
) then
4966 Subp_Id
:= First_Elmt
(Subp_List
);
4967 Spec
:= Parent
(Node
(Subp_Id
));
4969 while Present
(Subp_Id
) loop
4970 if Nkind
(Parent
(Spec
))
4971 = N_Subprogram_Renaming_Declaration
4975 elsif Nkind
(Spec
) = N_Procedure_Specification
4976 and then Null_Present
(Spec
)
4981 Set_Body_Required
(Library_Unit
(N
));
4985 Next_Elmt
(Subp_Id
);
4989 end Check_Declarations
;
4991 -- Start of processing for Check_Body_Required
4994 -- If this is an imported package (Java and CIL usage) no body is
4995 -- needed. Scan list of pragmas that may follow a compilation unit
4996 -- to look for a relevant pragma Import.
4998 if Present
(PA
) then
5004 while Present
(Prag
) loop
5005 if Nkind
(Prag
) = N_Pragma
5006 and then Get_Pragma_Id
(Prag
) = Pragma_Import
5016 Check_Declarations
(Specification
(P_Unit
));
5017 end Check_Body_Required
;
5019 -----------------------------
5020 -- Has_Limited_With_Clause --
5021 -----------------------------
5023 function Has_Limited_With_Clause
5024 (C_Unit
: Entity_Id
;
5025 Pack
: Entity_Id
) return Boolean
5032 while Present
(Par
) loop
5033 if Ekind
(Par
) /= E_Package
then
5037 -- Retrieve the Compilation_Unit node for Par and determine if
5038 -- its context clauses contain a limited with for Pack.
5040 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
5042 if Nkind
(Par_Unit
) = N_Package_Declaration
then
5043 Par_Unit
:= Parent
(Par_Unit
);
5046 if Has_With_Clause
(Par_Unit
, Pack
, True) then
5050 -- If there are more ancestors, climb up the tree, otherwise we
5053 if Is_Child_Unit
(Par
) then
5061 end Has_Limited_With_Clause
;
5063 -- Start of processing for Install_Limited_With_Clause
5066 pragma Assert
(not Limited_View_Installed
(N
));
5068 -- In case of limited with_clause on subprograms, generics, instances,
5069 -- or renamings, the corresponding error was previously posted and we
5070 -- have nothing to do here. If the file is missing altogether, it has
5071 -- no source location.
5073 if Nkind
(P_Unit
) /= N_Package_Declaration
5074 or else Sloc
(P_Unit
) = No_Location
5079 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
5081 -- Handle child packages
5083 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
5084 Is_Child_Package
:= True;
5085 P
:= Defining_Identifier
(P
);
5088 -- Do not install the limited-view if the context of the unit is already
5089 -- available through a regular with clause.
5091 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
5092 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
5097 -- Do not install the limited-view if the full-view is already visible
5098 -- through renaming declarations.
5100 if Is_Visible_Through_Renamings
(P
, N
) then
5104 -- Do not install the limited view if this is the unit being analyzed.
5105 -- This unusual case will happen when a unit has a limited_with clause
5106 -- on one of its children. The compilation of the child forces the load
5107 -- of the parent which tries to install the limited view of the child
5108 -- again. Installing the limited view must also be disabled when
5109 -- compiling the body of the child unit.
5111 if P
= Cunit_Entity
(Current_Sem_Unit
)
5112 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
5113 and then P
= Main_Unit_Entity
5114 and then Is_Ancestor_Unit
5115 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
5120 -- This scenario is similar to the one above, the difference is that the
5121 -- compilation of sibling Par.Sib forces the load of parent Par which
5122 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
5123 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
5124 -- nonlimited views of all entities from Lim_Pack.
5126 -- limited with Lim_Pack; -- [1]
5127 -- package Par is ... package Lim_Pack is ...
5129 -- with Lim_Pack; -- [2]
5130 -- package Par.Sib is ... package body Par.Sib is ...
5132 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
5133 -- Sem_Unit is the body of Par.Sib.
5135 if Ekind
(P
) = E_Package
5136 and then Ekind
(Main_Unit_Entity
) = E_Package
5137 and then Is_Child_Unit
(Main_Unit_Entity
)
5139 -- The body has a regular with clause
5141 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
5142 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
5144 -- One of the ancestors has a limited with clause
5146 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
5147 N_Package_Specification
5148 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
5153 -- A common use of the limited-with is to have a limited-with in the
5154 -- package spec, and a normal with in its package body. For example:
5156 -- limited with X; -- [1]
5160 -- package body A is ...
5162 -- The compilation of A's body installs the context clauses found at [2]
5163 -- and then the context clauses of its specification (found at [1]). As
5164 -- a consequence, at [1] the specification of X has been analyzed and it
5165 -- is immediately visible. According to the semantics of limited-with
5166 -- context clauses we don't install the limited view because the full
5167 -- view of X supersedes its limited view.
5169 if Analyzed
(P_Unit
)
5171 (Is_Immediately_Visible
(P
)
5172 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
5175 -- The presence of both the limited and the analyzed nonlimited view
5176 -- may also be an error, such as an illegal context for a limited
5177 -- with_clause. In that case, do not process the context item at all.
5179 if Error_Posted
(N
) then
5183 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
5187 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
5188 while Present
(Item
) loop
5189 if Nkind
(Item
) = N_With_Clause
5190 and then Comes_From_Source
(Item
)
5191 and then Entity
(Name
(Item
)) = P
5200 -- If this is a child body, assume that the nonlimited with_clause
5201 -- appears in an ancestor. Could be refined ???
5205 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
5212 -- If in package declaration, nonlimited view brought in from
5213 -- parent unit or some error condition.
5219 if Debug_Flag_I
then
5220 Write_Str
("install limited view of ");
5221 Write_Name
(Chars
(P
));
5225 -- If the unit has not been analyzed and the limited view has not been
5226 -- already installed then we install it.
5228 if not Analyzed
(P_Unit
) then
5229 if not In_Chain
(P
) then
5231 -- Minimum decoration
5233 Mutate_Ekind
(P
, E_Package
);
5234 Set_Etype
(P
, Standard_Void_Type
);
5235 Set_Scope
(P
, Standard_Standard
);
5236 Set_Is_Visible_Lib_Unit
(P
);
5238 if Is_Child_Package
then
5239 Set_Is_Child_Unit
(P
);
5240 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
5243 -- Place entity on visibility structure
5245 Set_Homonym
(P
, Current_Entity
(P
));
5246 Set_Current_Entity
(P
);
5248 if Debug_Flag_I
then
5249 Write_Str
(" (homonym) chain ");
5250 Write_Name
(Chars
(P
));
5254 -- Install the incomplete view. The first element of the limited
5255 -- view is a header (an E_Package entity) used to reference the
5256 -- first shadow entity in the private part of the package.
5258 Lim_Header
:= Limited_View
(P
);
5259 Lim_Typ
:= First_Entity
(Lim_Header
);
5261 while Present
(Lim_Typ
)
5262 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5264 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
5265 Set_Current_Entity
(Lim_Typ
);
5267 if Debug_Flag_I
then
5268 Write_Str
(" (homonym) chain ");
5269 Write_Name
(Chars
(Lim_Typ
));
5273 Next_Entity
(Lim_Typ
);
5277 -- If the unit appears in a previous regular with_clause, the regular
5278 -- entities of the public part of the withed package must be replaced
5279 -- by the shadow ones.
5281 -- This code must be kept synchronized with the code that replaces the
5282 -- shadow entities by the real entities in Remove_Limited_With_Unit,
5283 -- otherwise the contents of the homonym chains are not consistent.
5286 -- Hide all the type entities of the public part of the package to
5287 -- avoid its usage. This is needed to cover all the subtype decla-
5288 -- rations because we do not remove them from the homonym chain.
5290 E
:= First_Entity
(P
);
5291 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5293 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5300 -- Replace the real entities by the shadow entities of the limited
5301 -- view. The first element of the limited view is a header that is
5302 -- used to reference the first shadow entity in the private part
5303 -- of the package. Successive elements are the limited views of the
5304 -- type (including regular incomplete types) declared in the package.
5306 Lim_Header
:= Limited_View
(P
);
5308 Lim_Typ
:= First_Entity
(Lim_Header
);
5309 while Present
(Lim_Typ
)
5310 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5312 pragma Assert
(not In_Chain
(Lim_Typ
));
5314 -- Do not unchain nested packages and child units
5316 if Ekind
(Lim_Typ
) /= E_Package
5317 and then not Is_Child_Unit
(Lim_Typ
)
5320 Typ
: constant Entity_Id
:= Non_Limited_View
(Lim_Typ
);
5325 -- Replace Typ by Lim_Typ in the homonyms list, so that the
5326 -- limited view becomes available.
5328 -- If the nonlimited view is a record with an anonymous
5329 -- self-referential component, the analysis of the record
5330 -- declaration creates an incomplete type with the same name
5331 -- in order to define an internal access type. The visible
5332 -- entity is now the incomplete type, and that is the one to
5333 -- replace in the visibility structure.
5335 -- Similarly, if the source already contains the incomplete
5336 -- type declaration, the limited view of the incomplete type
5337 -- is in fact never visible (AI05-129) but we have created a
5338 -- shadow entity E1 for it that points to E2, the incomplete
5339 -- type at stake. This in turn has full view E3 that is the
5340 -- full declaration, with a corresponding shadow entity E4.
5341 -- When reinstalling the limited view, the visible entity E2
5342 -- is first replaced with E1, but E4 must eventually become
5343 -- the visible entity as per the AI and thus displace E1, as
5344 -- it is replacing E3 in the homonyms list.
5346 -- regular views limited views
5348 -- * E2 (incomplete) <-- E1 (shadow)
5353 -- E3 (full) <-- E4 (shadow) *
5355 -- [*] denotes the visible entity (Current_Entity)
5357 Prev
:= Current_Entity
(Lim_Typ
);
5359 while Present
(Prev
) loop
5360 -- This is a regular replacement
5363 or else (Ekind
(Prev
) = E_Incomplete_Type
5364 and then Full_View
(Prev
) = Typ
)
5366 Replace
(Prev
, Lim_Typ
);
5368 if Debug_Flag_I
then
5369 Write_Str
(" (homonym) replace ");
5370 Write_Name
(Chars
(Typ
));
5376 -- This is where E1 is replaced with E4
5378 elsif Ekind
(Prev
) = E_Incomplete_Type
5379 and then From_Limited_With
(Prev
)
5381 Ekind
(Non_Limited_View
(Prev
)) = E_Incomplete_Type
5382 and then Full_View
(Non_Limited_View
(Prev
)) = Typ
5384 Replace
(Prev
, Lim_Typ
);
5386 if Debug_Flag_I
then
5387 Write_Str
(" (homonym) E1 -> E4 ");
5388 Write_Name
(Chars
(Typ
));
5395 Prev
:= Homonym
(Prev
);
5400 Next_Entity
(Lim_Typ
);
5404 -- The package must be visible while the limited-with clause is active
5405 -- because references to the type P.T must resolve in the usual way.
5406 -- In addition, we remember that the limited-view has been installed to
5407 -- uninstall it at the point of context removal.
5409 Set_Is_Immediately_Visible
(P
);
5410 Set_Limited_View_Installed
(N
);
5412 -- If unit has not been analyzed in some previous context, check
5413 -- (imperfectly ???) whether it might need a body.
5415 if not Analyzed
(P_Unit
) then
5416 Check_Body_Required
;
5419 -- If the package in the limited_with clause is a child unit, the clause
5420 -- is unanalyzed and appears as a selected component. Recast it as an
5421 -- expanded name so that the entity can be properly set. Use entity of
5422 -- parent, if available, for higher ancestors in the name.
5424 if Nkind
(Name
(N
)) = N_Selected_Component
then
5432 while Nkind
(Nam
) = N_Selected_Component
5433 and then Present
(Ent
)
5435 Change_Selected_Component_To_Expanded_Name
(Nam
);
5437 -- Set entity of parent identifiers if the unit is a child
5438 -- unit. This ensures that the tree is properly formed from
5439 -- semantic point of view. The unit entities are not fully
5440 -- analyzed, so we need to follow unit links in the tree.
5442 Set_Entity
(Nam
, Ent
);
5444 Nam
:= Prefix
(Nam
);
5447 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5449 -- Set entity of last ancestor
5451 if Nkind
(Nam
) = N_Identifier
then
5452 Set_Entity
(Nam
, Ent
);
5458 Set_Entity
(Name
(N
), P
);
5459 Set_From_Limited_With
(P
);
5460 end Install_Limited_With_Clause
;
5462 -------------------------
5463 -- Install_With_Clause --
5464 -------------------------
5466 procedure Install_With_Clause
5467 (With_Clause
: Node_Id
;
5468 Private_With_OK
: Boolean := False)
5470 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5471 P
: constant Entity_Id
:= Scope
(Uname
);
5474 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5475 -- compiling a package declaration and the Private_With_OK flag was not
5476 -- set by the caller. These declarations will be installed later (before
5477 -- analyzing the private part of the package).
5479 if Private_Present
(With_Clause
)
5480 and then Nkind
(Unit
(Parent
(With_Clause
)))
5481 in N_Package_Declaration | N_Generic_Package_Declaration
5482 and then not Private_With_OK
5487 if Debug_Flag_I
then
5488 if Private_Present
(With_Clause
) then
5489 Write_Str
("install private withed unit ");
5490 elsif Parent_With
(With_Clause
) then
5491 Write_Str
("install parent withed unit ");
5492 elsif Implicit_With
(With_Clause
) then
5493 Write_Str
("install implicit withed unit ");
5495 Write_Str
("install withed unit ");
5498 Write_Name
(Chars
(Uname
));
5502 -- We do not apply the restrictions to an internal unit unless we are
5503 -- compiling the internal unit as a main unit. This check is also
5504 -- skipped for dummy units (for missing packages).
5506 if Sloc
(Uname
) /= No_Location
5507 and then (not Is_Internal_Unit
(Current_Sem_Unit
)
5508 or else Current_Sem_Unit
= Main_Unit
)
5510 Check_Restricted_Unit
5511 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5514 if P
/= Standard_Standard
then
5516 -- If the unit is not analyzed after analysis of the with clause and
5517 -- it is an instantiation then it awaits a body and is the main unit.
5518 -- Its appearance in the context of some other unit indicates a
5519 -- circular dependency (DEC suite perversity).
5521 if not Analyzed
(Uname
)
5522 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5525 ("instantiation depends on itself", Name
(With_Clause
));
5527 elsif not Analyzed
(Uname
)
5528 and then Is_Internal_Unit
(Current_Sem_Unit
)
5529 and then not Is_Visible_Lib_Unit
(Uname
)
5530 and then No
(Scope
(Uname
))
5532 if Is_Predefined_Unit
(Current_Sem_Unit
) then
5534 ("predefined unit depends on itself", Name
(With_Clause
));
5537 ("GNAT-defined unit depends on itself", Name
(With_Clause
));
5541 elsif not Is_Visible_Lib_Unit
(Uname
) then
5543 -- Abandon processing in case of previous errors
5545 if No
(Scope
(Uname
)) then
5546 Check_Error_Detected
;
5550 Set_Is_Visible_Lib_Unit
(Uname
);
5552 -- If the unit is a wrapper package for a compilation unit that is
5553 -- a subprogram instance, indicate that the instance itself is a
5554 -- visible unit. This is necessary if the instance is inlined.
5556 if Is_Wrapper_Package
(Uname
) then
5557 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5560 -- If the child unit appears in the context of its parent, it is
5561 -- immediately visible.
5563 if In_Open_Scopes
(Scope
(Uname
)) then
5564 Set_Is_Immediately_Visible
(Uname
);
5567 if Is_Generic_Instance
(Uname
)
5568 and then Is_Subprogram
(Uname
)
5570 -- Set flag as well on the visible entity that denotes the
5571 -- instance, which renames the current one.
5573 Set_Is_Visible_Lib_Unit
5575 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5578 -- The parent unit may have been installed already, and may have
5579 -- appeared in a use clause.
5581 if In_Use
(Scope
(Uname
)) then
5582 Set_Is_Potentially_Use_Visible
(Uname
);
5585 Set_Context_Installed
(With_Clause
);
5588 elsif not Is_Immediately_Visible
(Uname
) then
5589 Set_Is_Visible_Lib_Unit
(Uname
);
5591 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5592 Set_Is_Immediately_Visible
(Uname
);
5595 Set_Context_Installed
(With_Clause
);
5598 -- A [private] with clause overrides a limited with clause. Restore the
5599 -- proper view of the package by performing the following actions:
5601 -- * Remove all shadow entities which hide their corresponding
5602 -- entities from direct visibility by updating the entity and
5605 -- * Enter the corresponding entities back in direct visibility
5607 -- Note that the original limited with clause which installed its view
5608 -- is still marked as "active". This effect is undone when the clause
5609 -- itself is removed, see Remove_Limited_With_Clause.
5611 if Ekind
(Uname
) = E_Package
and then From_Limited_With
(Uname
) then
5612 Remove_Limited_With_Unit
(Unit_Declaration_Node
(Uname
));
5615 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5616 -- unit if there is a visible homograph for it declared in the same
5617 -- declarative region. This pathological case can only arise when an
5618 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5619 -- G1 has a generic child also named G2, and the context includes with_
5620 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5621 -- of I1.G2 visible as well. If the child unit is named Standard, do
5622 -- not apply the check to the Standard package itself.
5624 if Is_Child_Unit
(Uname
)
5625 and then Is_Visible_Lib_Unit
(Uname
)
5626 and then Ada_Version
>= Ada_2005
5629 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5635 U2
:= Homonym
(Uname
);
5636 while Present
(U2
) and then U2
/= Standard_Standard
loop
5638 Decl2
:= Unit_Declaration_Node
(P2
);
5640 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5641 if Is_Generic_Instance
(P
)
5642 and then Nkind
(Decl1
) = N_Package_Declaration
5643 and then Generic_Parent
(Specification
(Decl1
)) = P2
5645 Error_Msg_N
("illegal with_clause", With_Clause
);
5647 ("\child unit has visible homograph" &
5648 " (RM 8.3(26), 10.1.1(19))",
5652 elsif Is_Generic_Instance
(P2
)
5653 and then Nkind
(Decl2
) = N_Package_Declaration
5654 and then Generic_Parent
(Specification
(Decl2
)) = P
5656 -- With_clause for child unit of instance appears before
5657 -- in the context. We want to place the error message on
5658 -- it, not on the generic child unit itself.
5661 Prev_Clause
: Node_Id
;
5664 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5665 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5669 pragma Assert
(Present
(Prev_Clause
));
5670 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5672 ("\child unit has visible homograph" &
5673 " (RM 8.3(26), 10.1.1(19))",
5684 end Install_With_Clause
;
5690 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5691 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5694 return (K
in N_Generic_Declaration
or else
5695 K
in N_Generic_Instantiation
or else
5696 K
in N_Generic_Renaming_Declaration
or else
5697 K
= N_Package_Declaration
or else
5698 K
= N_Package_Renaming_Declaration
or else
5699 K
= N_Subprogram_Declaration
or else
5700 K
= N_Subprogram_Renaming_Declaration
)
5701 and then Present
(Parent_Spec
(Lib_Unit
));
5704 ------------------------------------
5705 -- Is_Legal_Shadow_Entity_In_Body --
5706 ------------------------------------
5708 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5709 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5711 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5714 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5715 end Is_Legal_Shadow_Entity_In_Body
;
5717 ----------------------
5718 -- Is_Ancestor_Unit --
5719 ----------------------
5721 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5722 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5725 if Nkind
(Unit
(U2
)) in N_Package_Body | N_Subprogram_Body
then
5726 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5727 return Is_Ancestor_Package
(E1
, E2
);
5731 end Is_Ancestor_Unit
;
5733 ----------------------------------
5734 -- Is_Visible_Through_Renamings --
5735 ----------------------------------
5737 function Is_Visible_Through_Renamings
5739 Error_Node
: Node_Id
:= Empty
) return Boolean
5741 function Is_Limited_Withed_Unit
5742 (Lib_Unit
: Node_Id
;
5743 Pkg_Ent
: Entity_Id
) return Boolean;
5744 -- Return True if Pkg_Ent is a limited-withed package of the given
5747 ----------------------------
5748 -- Is_Limited_Withed_Unit --
5749 ----------------------------
5751 function Is_Limited_Withed_Unit
5752 (Lib_Unit
: Node_Id
;
5753 Pkg_Ent
: Entity_Id
) return Boolean
5755 Item
: Node_Id
:= First
(Context_Items
(Lib_Unit
));
5758 while Present
(Item
) loop
5759 if Nkind
(Item
) = N_With_Clause
5760 and then Limited_Present
(Item
)
5761 and then Entity
(Name
(Item
)) = Pkg_Ent
5770 end Is_Limited_Withed_Unit
;
5774 Kind
: constant Node_Kind
:= Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
5780 -- Example of the error detected by this subprogram:
5788 -- package Ren_P renames P;
5794 -- limited with P; -- ERROR
5795 -- package R.C is ...
5797 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
5800 Item
:= First
(Context_Items
(Aux_Unit
));
5801 while Present
(Item
) loop
5802 if Nkind
(Item
) = N_With_Clause
5803 and then not Limited_Present
(Item
)
5804 and then Nkind
(Unit
(Library_Unit
(Item
))) =
5805 N_Package_Declaration
5808 First
(Visible_Declarations
5809 (Specification
(Unit
(Library_Unit
(Item
)))));
5810 while Present
(Decl
) loop
5811 if Nkind
(Decl
) = N_Package_Renaming_Declaration
5812 and then Entity
(Name
(Decl
)) = P
5813 and then not Is_Limited_Withed_Unit
5814 (Lib_Unit
=> Library_Unit
(Item
),
5815 Pkg_Ent
=> Entity
(Name
(Decl
)))
5817 -- Generate the error message only if the current unit
5818 -- is a package declaration; in case of subprogram
5819 -- bodies and package bodies we just return True to
5820 -- indicate that the limited view must not be
5823 if Kind
= N_Package_Declaration
5824 and then Present
(Error_Node
)
5827 ("simultaneous visibility of the limited and " &
5828 "unlimited views not allowed", Error_Node
);
5829 Error_Msg_Sloc
:= Sloc
(Item
);
5831 ("\\ unlimited view of & visible through the " &
5832 "context clause #", Error_Node
, P
);
5833 Error_Msg_Sloc
:= Sloc
(Decl
);
5834 Error_Msg_NE
("\\ and the renaming #", Error_Node
, P
);
5847 -- If it is a body not acting as spec, follow pointer to the
5848 -- corresponding spec, otherwise follow pointer to parent spec.
5850 if Present
(Library_Unit
(Aux_Unit
))
5851 and then Nkind
(Unit
(Aux_Unit
)) in
5852 N_Package_Body | N_Subprogram_Body
5854 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
5856 -- Aux_Unit is a body that acts as a spec. Clause has
5857 -- already been flagged as illegal.
5862 Aux_Unit
:= Library_Unit
(Aux_Unit
);
5866 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
5869 exit when No
(Aux_Unit
);
5873 end Is_Visible_Through_Renamings
;
5875 -----------------------
5876 -- Load_Needed_Body --
5877 -----------------------
5879 -- N is a generic unit named in a with clause, or else it is a unit that
5880 -- contains a generic unit or an inlined function. In order to perform an
5881 -- instantiation, the body of the unit must be present. If the unit itself
5882 -- is generic, we assume that an instantiation follows, and load & analyze
5883 -- the body unconditionally. This forces analysis of the spec as well.
5885 -- If the unit is not generic, but contains a generic unit, it is loaded on
5886 -- demand, at the point of instantiation (see ch12).
5888 procedure Load_Needed_Body
5892 Body_Name
: Unit_Name_Type
;
5893 Unum
: Unit_Number_Type
;
5895 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5896 -- The loading and analysis is done with style checks off
5899 if not GNAT_Mode
then
5900 Style_Check
:= False;
5903 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5906 (Load_Name
=> Body_Name
,
5912 if Unum
= No_Unit
then
5916 Compiler_State
:= Analyzing
; -- reset after load
5918 if Fatal_Error
(Unum
) /= Error_Detected
or else Try_Semantics
then
5919 if Debug_Flag_L
then
5920 Write_Str
("*** Loaded generic body");
5924 -- We always perform analyses
5925 Semantics
(Cunit
(Unum
));
5931 Style_Check
:= Save_Style_Check
;
5932 end Load_Needed_Body
;
5934 -------------------------
5935 -- Build_Limited_Views --
5936 -------------------------
5938 procedure Build_Limited_Views
(N
: Node_Id
) is
5939 Unum
: constant Unit_Number_Type
:=
5940 Get_Source_Unit
(Library_Unit
(N
));
5941 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5943 Shadow_Pack
: Entity_Id
;
5944 -- The corresponding shadow entity of the withed package. This entity
5945 -- offers incomplete views of packages and types as well as abstract
5946 -- views of states and variables declared within.
5948 Last_Shadow
: Entity_Id
:= Empty
;
5949 -- The last shadow entity created by routine Build_Shadow_Entity
5951 procedure Build_Shadow_Entity
5954 Shadow
: out Entity_Id
;
5955 Is_Tagged
: Boolean := False);
5956 -- Create a shadow entity that hides Ent and offers an abstract or
5957 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5958 -- should be set when Ent is a tagged type. The generated entity is
5959 -- added to Shadow_Pack. The routine updates the value of Last_Shadow.
5961 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5962 -- Perform minimal decoration of a package or its corresponding shadow
5963 -- entity denoted by Ent. Scop is the proper scope.
5965 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5966 -- Perform full decoration of an abstract state or its corresponding
5967 -- shadow entity denoted by Ent. Scop is the proper scope.
5969 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5970 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5973 procedure Process_Declarations_And_States
5977 Create_Abstract_Views
: Boolean);
5978 -- Inspect the states of package Pack and declarative list Decls. Create
5979 -- shadow entities for all nested packages, states, types and variables
5980 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5981 -- be set when the abstract states and variables need to be processed.
5983 -------------------------
5984 -- Build_Shadow_Entity --
5985 -------------------------
5987 procedure Build_Shadow_Entity
5990 Shadow
: out Entity_Id
;
5991 Is_Tagged
: Boolean := False)
5994 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5996 -- The shadow entity must share the same name and parent as the
5999 Set_Chars
(Shadow
, Chars
(Ent
));
6000 Set_Parent
(Shadow
, Parent
(Ent
));
6002 -- The abstract view of a variable is a state, not another variable
6004 if Ekind
(Ent
) = E_Variable
then
6005 Mutate_Ekind
(Shadow
, E_Abstract_State
);
6007 Mutate_Ekind
(Shadow
, Ekind
(Ent
));
6010 Set_Is_Not_Self_Hidden
(Shadow
);
6011 Set_Is_Internal
(Shadow
);
6012 Set_From_Limited_With
(Shadow
);
6014 -- Add the new shadow entity to the limited view of the package
6016 Last_Shadow
:= Shadow
;
6017 Append_Entity
(Shadow
, Shadow_Pack
);
6019 -- Perform context-specific decoration of the shadow entity
6021 if Ekind
(Ent
) = E_Abstract_State
then
6022 Decorate_State
(Shadow
, Scop
);
6023 Set_Non_Limited_View
(Shadow
, Ent
);
6025 elsif Ekind
(Ent
) = E_Package
then
6026 Decorate_Package
(Shadow
, Scop
);
6028 elsif Is_Type
(Ent
) then
6029 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
6031 -- If Ent is a private type and we are analyzing the body of its
6032 -- scope, its private and full views are swapped and, therefore,
6033 -- we need to undo this swapping in order to build the same shadow
6034 -- entity as we would have in other contexts.
6036 if Is_Private_Type
(Ent
)
6037 and then Present
(Full_View
(Ent
))
6038 and then In_Package_Body
(Scop
)
6040 Set_Non_Limited_View
(Shadow
, Full_View
(Ent
));
6042 Set_Non_Limited_View
(Shadow
, Ent
);
6046 Set_Non_Limited_View
6047 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Ent
));
6050 if Is_Incomplete_Or_Private_Type
(Ent
) then
6051 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
6054 elsif Ekind
(Ent
) = E_Variable
then
6055 Decorate_State
(Shadow
, Scop
);
6056 Set_Non_Limited_View
(Shadow
, Ent
);
6058 end Build_Shadow_Entity
;
6060 ----------------------
6061 -- Decorate_Package --
6062 ----------------------
6064 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
6066 Mutate_Ekind
(Ent
, E_Package
);
6067 Set_Etype
(Ent
, Standard_Void_Type
);
6068 Set_Scope
(Ent
, Scop
);
6069 end Decorate_Package
;
6071 --------------------
6072 -- Decorate_State --
6073 --------------------
6075 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
6077 Mutate_Ekind
(Ent
, E_Abstract_State
);
6078 Set_Is_Not_Self_Hidden
(Ent
);
6079 Set_Etype
(Ent
, Standard_Void_Type
);
6080 Set_Scope
(Ent
, Scop
);
6081 Set_Encapsulating_State
(Ent
, Empty
);
6084 -----------------------
6085 -- Decorate_Variable --
6086 -----------------------
6088 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
6090 Mutate_Ekind
(Ent
, E_Variable
);
6091 Set_Etype
(Ent
, Standard_Void_Type
);
6092 Set_Scope
(Ent
, Scop
);
6093 end Decorate_Variable
;
6095 -------------------------------------
6096 -- Process_Declarations_And_States --
6097 -------------------------------------
6099 procedure Process_Declarations_And_States
6103 Create_Abstract_Views
: Boolean)
6105 procedure Find_And_Process_States
;
6106 -- Determine whether package Pack defines abstract state either by
6107 -- using an aspect or a pragma. If this is the case, build shadow
6108 -- entities for all abstract states of Pack.
6110 procedure Process_States
(States
: Elist_Id
);
6111 -- Generate shadow entities for all abstract states in list States
6113 -----------------------------
6114 -- Find_And_Process_States --
6115 -----------------------------
6117 procedure Find_And_Process_States
is
6118 procedure Process_State
(State
: Node_Id
);
6119 -- Generate shadow entities for a single abstract state or
6120 -- multiple states expressed as an aggregate.
6126 procedure Process_State
(State
: Node_Id
) is
6127 Loc
: constant Source_Ptr
:= Sloc
(State
);
6134 -- Multiple abstract states appear as an aggregate
6136 if Nkind
(State
) = N_Aggregate
then
6137 Elmt
:= First
(Expressions
(State
));
6138 while Present
(Elmt
) loop
6139 Process_State
(Elmt
);
6145 -- A null state has no abstract view
6147 elsif Nkind
(State
) = N_Null
then
6150 -- State declaration with various options appears as an
6151 -- extension aggregate.
6153 elsif Nkind
(State
) = N_Extension_Aggregate
then
6154 Decl
:= Ancestor_Part
(State
);
6156 -- Simple state declaration
6158 elsif Nkind
(State
) = N_Identifier
then
6161 -- Possibly an illegal state declaration
6167 -- Abstract states are elaborated when the related pragma is
6168 -- elaborated. Since the withed package is not analyzed yet,
6169 -- the entities of the abstract states are not available. To
6170 -- overcome this complication, create the entities now and
6171 -- store them in their respective declarations. The entities
6172 -- are later used by routine Create_Abstract_State to declare
6173 -- and enter the states into visibility.
6175 if No
(Entity
(Decl
)) then
6176 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
6178 Set_Entity
(Decl
, Id
);
6179 Set_Parent
(Id
, State
);
6180 Decorate_State
(Id
, Scop
);
6182 -- Otherwise the package was previously withed
6185 Id
:= Entity
(Decl
);
6188 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
6193 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
6197 -- Start of processing for Find_And_Process_States
6200 -- Find aspect Abstract_State
6202 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
6203 while Present
(Asp
) loop
6204 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
6205 Process_State
(Expression
(Asp
));
6213 -- Find pragma Abstract_State by inspecting the declarations
6215 Decl
:= First
(Decls
);
6216 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
6217 if Pragma_Name
(Decl
) = Name_Abstract_State
then
6220 (First
(Pragma_Argument_Associations
(Decl
))));
6227 end Find_And_Process_States
;
6229 --------------------
6230 -- Process_States --
6231 --------------------
6233 procedure Process_States
(States
: Elist_Id
) is
6238 Elmt
:= First_Elmt
(States
);
6239 while Present
(Elmt
) loop
6240 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
6248 Is_Tagged
: Boolean;
6254 -- Start of processing for Process_Declarations_And_States
6257 -- Build abstract views for all states defined in the package
6259 if Create_Abstract_Views
then
6261 -- When a package has been analyzed, all states are stored in list
6262 -- Abstract_States. Generate the shadow entities directly.
6265 if Present
(Abstract_States
(Pack
)) then
6266 Process_States
(Abstract_States
(Pack
));
6269 -- The package may declare abstract states by using an aspect or a
6270 -- pragma. Attempt to locate one of these construct and if found,
6271 -- build the shadow entities.
6274 Find_And_Process_States
;
6278 -- Inspect the declarative list, looking for nested packages, types
6279 -- and variable declarations.
6281 Decl
:= First
(Decls
);
6282 while Present
(Decl
) loop
6286 if Nkind
(Decl
) = N_Package_Declaration
then
6287 Def_Id
:= Defining_Entity
(Decl
);
6289 -- Perform minor decoration when the withed package has not
6292 if not Is_Analyzed
then
6293 Decorate_Package
(Def_Id
, Scop
);
6296 -- Create a shadow entity that offers a limited view of all
6297 -- visible types declared within.
6299 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
6301 Process_Declarations_And_States
6304 Visible_Declarations
(Specification
(Decl
)),
6306 Create_Abstract_Views
=> Create_Abstract_Views
);
6310 elsif Nkind
(Decl
) in N_Full_Type_Declaration
6311 | N_Incomplete_Type_Declaration
6312 | N_Private_Extension_Declaration
6313 | N_Private_Type_Declaration
6314 | N_Protected_Type_Declaration
6315 | N_Task_Type_Declaration
6317 Def_Id
:= Defining_Entity
(Decl
);
6319 -- Determine whether the type is tagged. Note that packages
6320 -- included via a limited with clause are not always analyzed,
6321 -- hence the tree lookup rather than the use of attribute
6324 if Nkind
(Decl
) = N_Full_Type_Declaration
then
6325 Def
:= Type_Definition
(Decl
);
6328 (Nkind
(Def
) = N_Record_Definition
6329 and then Tagged_Present
(Def
))
6331 (Nkind
(Def
) = N_Derived_Type_Definition
6332 and then Present
(Record_Extension_Part
(Def
)));
6334 elsif Nkind
(Decl
) in N_Incomplete_Type_Declaration
6335 | N_Private_Type_Declaration
6337 Is_Tagged
:= Tagged_Present
(Decl
);
6339 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
6346 -- Perform minor decoration when the withed package has not
6349 if not Is_Analyzed
then
6350 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
6353 -- Create a shadow entity that hides the type and offers an
6354 -- incomplete view of the said type.
6356 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
6360 elsif Create_Abstract_Views
6361 and then Nkind
(Decl
) = N_Object_Declaration
6362 and then not Constant_Present
(Decl
)
6364 Def_Id
:= Defining_Entity
(Decl
);
6366 -- Perform minor decoration when the withed package has not
6369 if not Is_Analyzed
then
6370 Decorate_Variable
(Def_Id
, Scop
);
6373 -- Create a shadow entity that hides the variable and offers an
6374 -- abstract view of the said variable.
6376 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
6381 end Process_Declarations_And_States
;
6385 Nam
: constant Node_Id
:= Name
(N
);
6386 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
6388 Last_Public_Shadow
: Entity_Id
:= Empty
;
6389 Private_Shadow
: Entity_Id
;
6392 -- Start of processing for Build_Limited_Views
6395 pragma Assert
(Limited_Present
(N
));
6397 -- A library_item mentioned in a limited_with_clause is a package
6398 -- declaration, not a subprogram declaration, generic declaration,
6399 -- generic instantiation, or package renaming declaration.
6401 case Nkind
(Unit
(Library_Unit
(N
))) is
6402 when N_Package_Declaration
=>
6405 when N_Subprogram_Declaration
=>
6407 ("subprogram not allowed in `LIMITED WITH` clause", N
);
6410 when N_Generic_Declaration
=>
6411 Error_Msg_N
("generic not allowed in `LIMITED WITH` clause", N
);
6414 when N_Generic_Instantiation
=>
6416 ("generic instantiation not allowed in `LIMITED WITH` clause",
6420 when N_Generic_Renaming_Declaration
=>
6422 ("generic renaming not allowed in `LIMITED WITH` clause", N
);
6425 when N_Subprogram_Renaming_Declaration
=>
6427 ("renamed subprogram not allowed in `LIMITED WITH` clause", N
);
6430 when N_Package_Renaming_Declaration
=>
6432 ("renamed package not allowed in `LIMITED WITH` clause", N
);
6436 raise Program_Error
;
6439 -- The withed unit may not be analyzed, but the with clause itself
6440 -- must be minimally decorated. This ensures that the checks on unused
6441 -- with clauses also process limieted withs.
6443 Mutate_Ekind
(Pack
, E_Package
);
6444 Set_Is_Not_Self_Hidden
(Pack
);
6445 Set_Etype
(Pack
, Standard_Void_Type
);
6447 if Is_Entity_Name
(Nam
) then
6448 Set_Entity
(Nam
, Pack
);
6450 elsif Nkind
(Nam
) = N_Selected_Component
then
6451 Set_Entity
(Selector_Name
(Nam
), Pack
);
6454 -- Check if the chain is already built
6456 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6458 if Limited_View_Installed
(Spec
) then
6462 -- Create the shadow package wich hides the withed unit and provides
6463 -- incomplete view of all types and packages declared within.
6465 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6466 Mutate_Ekind
(Shadow_Pack
, E_Package
);
6467 Set_Is_Internal
(Shadow_Pack
);
6468 Set_Limited_View
(Pack
, Shadow_Pack
);
6470 -- Inspect the abstract states and visible declarations of the withed
6471 -- unit and create shadow entities that hide existing packages, states,
6472 -- variables and types.
6474 Process_Declarations_And_States
6476 Decls
=> Visible_Declarations
(Spec
),
6478 Create_Abstract_Views
=> True);
6480 Last_Public_Shadow
:= Last_Shadow
;
6482 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6483 -- to accommodate limited private with clauses.
6485 Process_Declarations_And_States
6487 Decls
=> Private_Declarations
(Spec
),
6489 Create_Abstract_Views
=> False);
6491 if Present
(Last_Public_Shadow
) then
6492 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6494 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6497 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6498 Set_Limited_View_Installed
(Spec
);
6499 end Build_Limited_Views
;
6501 ----------------------------
6502 -- Check_No_Elab_Code_All --
6503 ----------------------------
6505 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6507 if Present
(No_Elab_Code_All_Pragma
)
6508 and then In_Extended_Main_Source_Unit
(N
)
6509 and then Present
(Context_Items
(N
))
6512 CL
: constant List_Id
:= Context_Items
(N
);
6517 while Present
(CI
) loop
6518 if Nkind
(CI
) = N_With_Clause
6520 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6522 -- In GNATprove mode, some runtime units are implicitly
6523 -- loaded to make their entities available for analysis. In
6524 -- this case, ignore violations of No_Elaboration_Code_All
6525 -- for this special analysis mode.
6528 (GNATprove_Mode
and then Implicit_With
(CI
))
6530 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6532 ("violation of No_Elaboration_Code_All#", CI
);
6534 ("\unit& does not have No_Elaboration_Code_All",
6535 CI
, Entity
(Name
(CI
)));
6542 end Check_No_Elab_Code_All
;
6544 -------------------------------
6545 -- Check_Body_Needed_For_SAL --
6546 -------------------------------
6548 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6549 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6550 -- Determine whether use of entity E might require the presence of its
6551 -- body. For a package this requires a recursive traversal of all nested
6554 -----------------------
6555 -- Entity_Needs_Body --
6556 -----------------------
6558 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6562 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6565 elsif Is_Generic_Subprogram
(E
) then
6567 -- A generic subprogram always requires the presence of its
6568 -- body because an instantiation needs both templates. The only
6569 -- exceptions is a generic subprogram renaming. In this case the
6570 -- body is needed only when the template is declared outside the
6571 -- compilation unit being checked.
6573 if Present
(Renamed_Entity
(E
)) then
6574 return not Within_Scope
(E
, Unit_Name
);
6579 elsif Ekind
(E
) = E_Generic_Package
6581 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6582 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6586 elsif Ekind
(E
) = E_Package
6587 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6588 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6590 Ent
:= First_Entity
(E
);
6591 while Present
(Ent
) loop
6592 if Entity_Needs_Body
(Ent
) then
6604 end Entity_Needs_Body
;
6606 -- Start of processing for Check_Body_Needed_For_SAL
6609 if Ekind
(Unit_Name
) = E_Generic_Package
6610 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6611 N_Generic_Package_Declaration
6613 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6615 Set_Body_Needed_For_SAL
(Unit_Name
);
6617 elsif Ekind
(Unit_Name
) in E_Generic_Procedure | E_Generic_Function
then
6618 Set_Body_Needed_For_SAL
(Unit_Name
);
6620 elsif Is_Subprogram
(Unit_Name
)
6621 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6622 N_Subprogram_Declaration
6623 and then Has_Pragma_Inline
(Unit_Name
)
6625 Set_Body_Needed_For_SAL
(Unit_Name
);
6627 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6628 Check_Body_Needed_For_SAL
6629 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6631 elsif Ekind
(Unit_Name
) = E_Package
6632 and then Entity_Needs_Body
(Unit_Name
)
6634 Set_Body_Needed_For_SAL
(Unit_Name
);
6636 elsif Ekind
(Unit_Name
) = E_Package_Body
6637 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6639 Check_Body_Needed_For_SAL
6640 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6642 end Check_Body_Needed_For_SAL
;
6644 --------------------
6645 -- Remove_Context --
6646 --------------------
6648 procedure Remove_Context
(N
: Node_Id
) is
6649 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6652 -- If this is a child unit, first remove the parent units
6654 if Is_Child_Spec
(Lib_Unit
) then
6655 Remove_Parents
(Lib_Unit
);
6658 Remove_Context_Clauses
(N
);
6661 ----------------------------
6662 -- Remove_Context_Clauses --
6663 ----------------------------
6665 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6667 Unit_Name
: Entity_Id
;
6670 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6671 -- limited-views first and regular-views later (to maintain the stack
6674 -- First Phase: Remove limited_with context clauses
6676 Item
:= First
(Context_Items
(N
));
6677 while Present
(Item
) loop
6679 -- We are interested only in with clauses that got installed on entry
6681 if Nkind
(Item
) = N_With_Clause
6682 and then Limited_Present
(Item
)
6684 if Limited_View_Installed
(Item
) then
6685 Remove_Limited_With_Clause
(Item
);
6687 -- An unusual case: If the library unit of the Main_Unit has a
6688 -- limited with_clause on some unit P and the context somewhere
6689 -- includes a with_clause on P, P has been analyzed. The entity
6690 -- for P is still visible, which in general is harmless because
6691 -- this is the end of the compilation, but it can affect pending
6692 -- instantiations that may have been generated elsewhere, so it
6693 -- it is necessary to remove U from visibility so that inlining
6694 -- and the analysis of instance bodies can proceed cleanly.
6696 elsif Current_Sem_Unit
= Main_Unit
6697 and then Serious_Errors_Detected
= 0
6698 and then not Implicit_With
(Item
)
6700 Set_Is_Immediately_Visible
6701 (Defining_Entity
(Unit
(Library_Unit
(Item
))), False);
6708 -- Second Phase: Loop through context items and undo regular
6709 -- with_clauses and use_clauses.
6711 Item
:= First
(Context_Items
(N
));
6712 while Present
(Item
) loop
6714 -- We are interested only in with clauses which got installed on
6715 -- entry, as indicated by their Context_Installed flag set
6717 if Nkind
(Item
) = N_With_Clause
6718 and then Limited_Present
(Item
)
6719 and then Limited_View_Installed
(Item
)
6723 elsif Nkind
(Item
) = N_With_Clause
6724 and then Context_Installed
(Item
)
6726 -- Remove items from one with'ed unit
6728 Unit_Name
:= Entity
(Name
(Item
));
6729 Remove_Unit_From_Visibility
(Unit_Name
);
6730 Set_Context_Installed
(Item
, False);
6732 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6733 End_Use_Package
(Item
);
6735 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6736 End_Use_Type
(Item
);
6741 end Remove_Context_Clauses
;
6743 --------------------------------
6744 -- Remove_Limited_With_Clause --
6745 --------------------------------
6747 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6748 Pack_Decl
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6751 pragma Assert
(Limited_View_Installed
(N
));
6753 -- Limited with clauses that designate units other than packages are
6754 -- illegal and are never installed.
6756 if Nkind
(Pack_Decl
) = N_Package_Declaration
then
6757 Remove_Limited_With_Unit
(Pack_Decl
, N
);
6760 -- Indicate that the limited views of the clause have been removed
6762 Set_Limited_View_Installed
(N
, False);
6763 end Remove_Limited_With_Clause
;
6765 ------------------------------
6766 -- Remove_Limited_With_Unit --
6767 ------------------------------
6769 procedure Remove_Limited_With_Unit
6770 (Pack_Decl
: Node_Id
;
6771 Lim_Clause
: Node_Id
:= Empty
)
6773 procedure Remove_Shadow_Entities_From_Visibility
(Pack_Id
: Entity_Id
);
6774 -- Remove the shadow entities of package Pack_Id from direct visibility
6776 procedure Remove_Shadow_Entities_With_Restore
(Pack_Id
: Entity_Id
);
6777 -- Remove the shadow entities of package Pack_Id from direct visibility,
6778 -- restore the corresponding entities they hide into direct visibility,
6779 -- and update the entity and homonym chains.
6781 --------------------------------------------
6782 -- Remove_Shadow_Entities_From_Visibility --
6783 --------------------------------------------
6785 procedure Remove_Shadow_Entities_From_Visibility
(Pack_Id
: Entity_Id
) is
6786 Lim_Header
: constant Entity_Id
:= Limited_View
(Pack_Id
);
6787 Upto
: constant Entity_Id
:= First_Private_Entity
(Lim_Header
);
6792 -- Remove the package from direct visibility
6795 Set_Is_Immediately_Visible
(Pack_Id
, False);
6797 -- Remove all shadow entities from direct visibility
6799 Shadow
:= First_Entity
(Lim_Header
);
6800 while Present
(Shadow
) and then Shadow
/= Upto
loop
6802 Next_Entity
(Shadow
);
6804 end Remove_Shadow_Entities_From_Visibility
;
6806 -----------------------------------------
6807 -- Remove_Shadow_Entities_With_Restore --
6808 -----------------------------------------
6810 -- This code must be kept synchronized with the code that replaces the
6811 -- real entities by the shadow entities in Install_Limited_With_Clause,
6812 -- otherwise the contents of the homonym chains are not consistent.
6814 procedure Remove_Shadow_Entities_With_Restore
(Pack_Id
: Entity_Id
) is
6815 procedure Restore_Chain_For_Shadow
(Shadow
: Entity_Id
);
6816 -- Remove shadow entity Shadow by updating the entity and homonym
6819 procedure Restore_Chains
6822 -- Remove a sequence of shadow entities starting from From and ending
6823 -- prior to Upto by updating the entity and homonym chains.
6825 procedure Restore_Type_Visibility
6828 -- Restore a sequence of types starting from From and ending prior to
6829 -- Upto back in direct visibility.
6831 ------------------------------
6832 -- Restore_Chain_For_Shadow --
6833 ------------------------------
6835 procedure Restore_Chain_For_Shadow
(Shadow
: Entity_Id
) is
6836 Typ
: constant Entity_Id
:= Non_Limited_View
(Shadow
);
6837 pragma Assert
(not In_Chain
(Typ
));
6842 -- If the package has incomplete types, the limited view of the
6843 -- incomplete type is in fact never visible (AI05-129) but we
6844 -- have created a shadow entity E1 for it, that points to E2,
6845 -- the incomplete type at stake. This in turn has a full view
6846 -- E3 that is the full declaration, with a corresponding
6847 -- shadow entity E4. When reinstalling the nonlimited view,
6848 -- the visible entity E4 is replaced directly with E2 in the
6849 -- the homonyms list and E3 is simply ignored.
6851 -- regular views limited views
6853 -- * E2 (incomplete) <-- E1 (shadow)
6858 -- E3 (full) <-- E4 (shadow) *
6860 -- [*] denotes the visible entity (Current_Entity)
6862 Prev
:= Current_Entity
(Shadow
);
6864 while Present
(Prev
) loop
6865 -- This is a regular replacement
6867 if Prev
= Shadow
then
6868 Replace
(Prev
, Typ
);
6870 if Debug_Flag_I
then
6871 Write_Str
(" (homonym) replace ");
6872 Write_Name
(Chars
(Typ
));
6878 -- This is where E4 is replaced with E2
6880 elsif Ekind
(Prev
) = E_Incomplete_Type
6881 and then From_Limited_With
(Prev
)
6882 and then Ekind
(Typ
) = E_Incomplete_Type
6883 and then Full_View
(Typ
) = Non_Limited_View
(Prev
)
6885 Replace
(Prev
, Typ
);
6887 if Debug_Flag_I
then
6888 Write_Str
(" (homonym) E4 -> E2 ");
6889 Write_Name
(Chars
(Typ
));
6896 Prev
:= Homonym
(Prev
);
6898 end Restore_Chain_For_Shadow
;
6900 --------------------
6901 -- Restore_Chains --
6902 --------------------
6904 procedure Restore_Chains
6912 while Present
(Shadow
) and then Shadow
/= Upto
loop
6914 -- Do not unchain nested packages and child units
6916 if Ekind
(Shadow
) = E_Package
then
6919 elsif Is_Child_Unit
(Non_Limited_View
(Shadow
)) then
6923 Restore_Chain_For_Shadow
(Shadow
);
6926 Next_Entity
(Shadow
);
6930 -----------------------------
6931 -- Restore_Type_Visibility --
6932 -----------------------------
6934 procedure Restore_Type_Visibility
6942 while Present
(Typ
) and then Typ
/= Upto
loop
6943 if Is_Type
(Typ
) then
6944 Set_Is_Hidden
(Typ
, Was_Hidden
(Typ
));
6949 end Restore_Type_Visibility
;
6953 Lim_Header
: constant Entity_Id
:= Limited_View
(Pack_Id
);
6955 -- Start of processing Remove_Shadow_Entities_With_Restore
6958 -- The limited view of a package is being uninstalled by removing
6959 -- the effects of a limited with clause. If the clause appears in a
6960 -- unit which is not part of the main unit closure, then the related
6961 -- package must not be visible.
6963 if Present
(Lim_Clause
)
6964 and then not In_Extended_Main_Source_Unit
(Lim_Clause
)
6966 Set_Is_Immediately_Visible
(Pack_Id
, False);
6968 -- Otherwise a limited view is being overridden by a nonlimited view.
6969 -- Leave the visibility of the package as is because the unit must be
6970 -- visible when the nonlimited view is installed.
6976 -- Remove the shadow entities from visibility by updating the entity
6977 -- and homonym chains.
6980 (From
=> First_Entity
(Lim_Header
),
6981 Upto
=> First_Private_Entity
(Lim_Header
));
6983 -- Reinstate the types that were hidden by the shadow entities back
6984 -- into direct visibility.
6986 Restore_Type_Visibility
6987 (From
=> First_Entity
(Pack_Id
),
6988 Upto
=> First_Private_Entity
(Pack_Id
));
6989 end Remove_Shadow_Entities_With_Restore
;
6993 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
6995 -- Start of processing for Remove_Limited_With_Unit
6998 -- Nothing to do when the limited view of the package is not installed
7000 if not From_Limited_With
(Pack_Id
) then
7004 if Debug_Flag_I
then
7005 Write_Str
("remove limited view of ");
7006 Write_Name
(Chars
(Pack_Id
));
7007 Write_Str
(" from visibility");
7011 -- The package already appears in the compilation closure. As a result,
7012 -- its shadow entities must be replaced by the real entities they hide
7013 -- and the previously hidden entities must be entered back into direct
7016 if Analyzed
(Pack_Decl
) then
7017 Remove_Shadow_Entities_With_Restore
(Pack_Id
);
7019 -- Otherwise the package is not analyzed and its shadow entities must be
7020 -- removed from direct visibility.
7023 Remove_Shadow_Entities_From_Visibility
(Pack_Id
);
7026 -- Indicate that the limited view of the package is not installed
7028 Set_From_Limited_With
(Pack_Id
, False);
7029 end Remove_Limited_With_Unit
;
7031 --------------------
7032 -- Remove_Parents --
7033 --------------------
7035 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
7038 P_Spec
: Node_Id
:= Empty
;
7040 Vis
: constant Boolean :=
7041 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
7044 if Is_Child_Spec
(Lib_Unit
) then
7045 P_Spec
:= Parent_Spec
(Lib_Unit
);
7047 elsif Nkind
(Lib_Unit
) = N_Package_Body
7048 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
7050 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
7053 if Present
(P_Spec
) then
7055 P_Name
:= Get_Parent_Entity
(P
);
7056 Remove_Context_Clauses
(P_Spec
);
7057 End_Package_Scope
(P_Name
);
7058 Set_Is_Immediately_Visible
(P_Name
, Vis
);
7060 -- Remove from visibility the siblings as well, which are directly
7061 -- visible while the parent is in scope.
7063 E
:= First_Entity
(P_Name
);
7064 while Present
(E
) loop
7065 if Is_Child_Unit
(E
) then
7066 Set_Is_Immediately_Visible
(E
, False);
7072 Set_In_Package_Body
(P_Name
, False);
7074 -- This is the recursive call to remove the context of any higher
7075 -- level parent. This recursion ensures that all parents are removed
7076 -- in the reverse order of their installation.
7082 ---------------------------------
7083 -- Remove_Private_With_Clauses --
7084 ---------------------------------
7086 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
7089 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
7090 -- Check whether a given unit appears in a regular with_clause. Used to
7091 -- determine whether a private_with_clause, implicit or explicit, should
7094 ----------------------------
7095 -- In_Regular_With_Clause --
7096 ----------------------------
7098 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean is
7102 Item
:= First
(Context_Items
(Comp_Unit
));
7104 while Present
(Item
) loop
7105 if Nkind
(Item
) = N_With_Clause
7107 -- The following guard is needed to ensure that the name has
7108 -- been properly analyzed before we go fetching its entity.
7110 and then Is_Entity_Name
(Name
(Item
))
7111 and then Entity
(Name
(Item
)) = E
7112 and then not Private_Present
(Item
)
7121 end In_Regular_With_Clause
;
7123 -- Start of processing for Remove_Private_With_Clauses
7126 Item
:= First
(Context_Items
(Comp_Unit
));
7127 while Present
(Item
) loop
7128 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
7130 -- If private_with_clause is redundant, remove it from context,
7131 -- as a small optimization to subsequent handling of private_with
7132 -- clauses in other nested packages. We replace the clause with
7133 -- a null statement, which is otherwise ignored by the rest of
7136 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
7138 Nxt
: constant Node_Id
:= Next
(Item
);
7140 Rewrite
(Item
, Make_Null_Statement
(Sloc
(Item
)));
7145 elsif Limited_Present
(Item
) then
7146 if not Limited_View_Installed
(Item
) then
7147 Remove_Limited_With_Clause
(Item
);
7153 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
7154 Set_Context_Installed
(Item
, False);
7162 end Remove_Private_With_Clauses
;
7164 ---------------------------------
7165 -- Remove_Unit_From_Visibility --
7166 ---------------------------------
7168 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
7170 if Debug_Flag_I
then
7171 Write_Str
("remove unit ");
7172 Write_Name
(Chars
(Unit_Name
));
7173 Write_Str
(" from visibility");
7177 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
7178 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
7179 Set_Is_Immediately_Visible
(Unit_Name
, False);
7181 -- If the unit is a wrapper package, the subprogram instance is
7182 -- what must be removed from visibility.
7183 -- Should we use Related_Instance instead???
7185 if Is_Wrapper_Package
(Unit_Name
) then
7186 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
7188 end Remove_Unit_From_Visibility
;
7203 procedure Replace
(Old_E
, New_E
: Entity_Id
) is
7207 Prev
:= Current_Entity
(Old_E
);
7212 elsif Prev
= Old_E
then
7213 Set_Current_Entity
(New_E
);
7214 Set_Homonym
(New_E
, Homonym
(Old_E
));
7217 while Present
(Prev
) and then Homonym
(Prev
) /= Old_E
loop
7218 Prev
:= Homonym
(Prev
);
7221 if Present
(Prev
) then
7222 Set_Homonym
(Prev
, New_E
);
7223 Set_Homonym
(New_E
, Homonym
(Old_E
));
7232 procedure Unchain
(E
: Entity_Id
) is
7236 Prev
:= Current_Entity
(E
);
7242 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
7245 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
7246 Prev
:= Homonym
(Prev
);
7249 if Present
(Prev
) then
7250 Set_Homonym
(Prev
, Homonym
(E
));
7254 if Debug_Flag_I
then
7255 Write_Str
(" (homonym) unchain ");
7256 Write_Name
(Chars
(E
));