1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Elists
; use Elists
;
34 with Fname
; use Fname
;
35 with Fname
.UF
; use Fname
.UF
;
36 with Freeze
; use Freeze
;
37 with Impunit
; use Impunit
;
38 with Inline
; use Inline
;
40 with Lib
.Load
; use Lib
.Load
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Namet
; use Namet
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Output
; use Output
;
47 with Par_SCO
; use Par_SCO
;
48 with Restrict
; use Restrict
;
49 with Rident
; use Rident
;
50 with Rtsfind
; use Rtsfind
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Ch3
; use Sem_Ch3
;
54 with Sem_Ch6
; use Sem_Ch6
;
55 with Sem_Ch7
; use Sem_Ch7
;
56 with Sem_Ch8
; use Sem_Ch8
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Prag
; use Sem_Prag
;
59 with Sem_Util
; use Sem_Util
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Stand
; use Stand
;
62 with Sinfo
; use Sinfo
;
63 with Sinfo
.CN
; use Sinfo
.CN
;
64 with Sinput
; use Sinput
;
65 with Snames
; use Snames
;
66 with Style
; use Style
;
67 with Stylesw
; use Stylesw
;
68 with Tbuild
; use Tbuild
;
69 with Uname
; use Uname
;
71 package body Sem_Ch10
is
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 procedure Analyze_Context
(N
: Node_Id
);
78 -- Analyzes items in the context clause of compilation unit
80 procedure Build_Limited_Views
(N
: Node_Id
);
81 -- Build and decorate the list of shadow entities for a package mentioned
82 -- in a limited_with clause. If the package was not previously analyzed
83 -- then it also performs a basic decoration of the real entities. This is
84 -- required in order to avoid passing non-decorated entities to the
85 -- back-end. Implements Ada 2005 (AI-50217).
87 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
);
88 -- Common processing for all stubs (subprograms, tasks, packages, and
89 -- protected cases). N is the stub to be analyzed. Once the subunit name
90 -- is established, load and analyze. Nam is the non-overloadable entity
91 -- for which the proper body provides a completion. Subprogram stubs are
92 -- handled differently because they can be declarations.
94 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
);
95 -- Check whether the source for the body of a compilation unit must be
96 -- included in a standalone library.
98 procedure Check_No_Elab_Code_All
(N
: Node_Id
);
99 -- Carries out possible tests for violation of No_Elab_Code all for withed
100 -- units in the Context_Items of unit N.
102 procedure Check_Private_Child_Unit
(N
: Node_Id
);
103 -- If a with_clause mentions a private child unit, the compilation unit
104 -- must be a member of the same family, as described in 10.1.2.
106 procedure Check_Stub_Level
(N
: Node_Id
);
107 -- Verify that a stub is declared immediately within a compilation unit,
108 -- and not in an inner frame.
110 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
);
111 -- When a child unit appears in a context clause, the implicit withs on
112 -- parents are made explicit, and with clauses are inserted in the context
113 -- clause before the one for the child. If a parent in the with_clause
114 -- is a renaming, the implicit with_clause is on the renaming whose name
115 -- is mentioned in the with_clause, and not on the package it renames.
116 -- N is the compilation unit whose list of context items receives the
117 -- implicit with_clauses.
119 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
);
120 -- Generate cross-reference information for the parents of child units
121 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
122 -- immediate parent scope.
124 function Has_With_Clause
127 Is_Limited
: Boolean := False) return Boolean;
128 -- Determine whether compilation unit C_Unit contains a [limited] with
129 -- clause for package Pack. Use the flag Is_Limited to designate desired
132 procedure Implicit_With_On_Parent
(Child_Unit
: Node_Id
; N
: Node_Id
);
133 -- If the main unit is a child unit, implicit withs are also added for
134 -- all its ancestors.
136 function In_Chain
(E
: Entity_Id
) return Boolean;
137 -- Check that the shadow entity is not already in the homonym chain, for
138 -- example through a limited_with clause in a parent unit.
140 procedure Install_Context_Clauses
(N
: Node_Id
);
141 -- Subsidiary to Install_Context and Install_Parents. Process all with
142 -- and use clauses for current unit and its library unit if any.
144 procedure Install_Limited_Context_Clauses
(N
: Node_Id
);
145 -- Subsidiary to Install_Context. Process only limited with_clauses for
146 -- current unit. Implements Ada 2005 (AI-50217).
148 procedure Install_Limited_Withed_Unit
(N
: Node_Id
);
149 -- Place shadow entities for a limited_with package in the visibility
150 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
152 procedure Install_Withed_Unit
153 (With_Clause
: Node_Id
;
154 Private_With_OK
: Boolean := False);
155 -- If the unit is not a child unit, make unit immediately visible. The
156 -- caller ensures that the unit is not already currently installed. The
157 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
158 -- is called when compiling the private part of a package, or installing
159 -- the private declarations of a parent unit.
161 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean);
162 -- This procedure establishes the context for the compilation of a child
163 -- unit. If Lib_Unit is a child library spec then the context of the parent
164 -- is installed, and the parent itself made immediately visible, so that
165 -- the child unit is processed in the declarative region of the parent.
166 -- Install_Parents makes a recursive call to itself to ensure that all
167 -- parents are loaded in the nested case. If Lib_Unit is a library body,
168 -- the only effect of Install_Parents is to install the private decls of
169 -- the parents, because the visible parent declarations will have been
170 -- installed as part of the context of the corresponding spec.
172 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
);
173 -- In the compilation of a child unit, a child of any of the ancestor
174 -- units is directly visible if it is visible, because the parent is in
175 -- an enclosing scope. Iterate over context to find child units of U_Name
176 -- or of some ancestor of it.
178 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean;
179 -- When compiling a unit Q descended from some parent unit P, a limited
180 -- with_clause in the context of P that names some other ancestor of Q
181 -- must not be installed because the ancestor is immediately visible.
183 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean;
184 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
185 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
186 -- a library spec that has a parent. If the call to Is_Child_Spec returns
187 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
188 -- compilation unit for the parent spec.
190 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
191 -- Parent_Spec is non-empty, this is also a child unit.
193 procedure Remove_Context_Clauses
(N
: Node_Id
);
194 -- Subsidiary of previous one. Remove use_ and with_clauses
196 procedure Remove_Limited_With_Clause
(N
: Node_Id
);
197 -- Remove from visibility the shadow entities introduced for a package
198 -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217).
200 procedure Remove_Parents
(Lib_Unit
: Node_Id
);
201 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
202 -- contexts established by the corresponding call to Install_Parents are
203 -- removed. Remove_Parents contains a recursive call to itself to ensure
204 -- that all parents are removed in the nested case.
206 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
);
207 -- Reset all visibility flags on unit after compiling it, either as a main
208 -- unit or as a unit in the context.
210 procedure Unchain
(E
: Entity_Id
);
211 -- Remove single entity from visibility list
214 -- A dummy procedure, for debugging use, called just before analyzing the
215 -- main unit (after dealing with any context clauses).
217 --------------------------
218 -- Limited_With_Clauses --
219 --------------------------
221 -- Limited_With clauses are the mechanism chosen for Ada 2005 to support
222 -- mutually recursive types declared in different units. A limited_with
223 -- clause that names package P in the context of unit U makes the types
224 -- declared in the visible part of P available within U, but with the
225 -- restriction that these types can only be used as incomplete types.
226 -- The limited_with clause does not impose a semantic dependence on P,
227 -- and it is possible for two packages to have limited_with_clauses on
228 -- each other without creating an elaboration circularity.
230 -- To support this feature, the analysis of a limited_with clause must
231 -- create an abbreviated view of the package, without performing any
232 -- semantic analysis on it. This "package abstract" contains shadow types
233 -- that are in one-one correspondence with the real types in the package,
234 -- and that have the properties of incomplete types.
236 -- The implementation creates two element lists: one to chain the shadow
237 -- entities, and one to chain the corresponding type entities in the tree
238 -- of the package. Links between corresponding entities in both chains
239 -- allow the compiler to select the proper view of a given type, depending
240 -- on the context. Note that in contrast with the handling of private
241 -- types, the limited view and the non-limited view of a type are treated
242 -- as separate entities, and no entity exchange needs to take place, which
243 -- makes the implementation much simpler than could be feared.
245 ------------------------------
246 -- Analyze_Compilation_Unit --
247 ------------------------------
249 procedure Analyze_Compilation_Unit
(N
: Node_Id
) is
250 procedure Check_Redundant_Withs
251 (Context_Items
: List_Id
;
252 Spec_Context_Items
: List_Id
:= No_List
);
253 -- Determine whether the context list of a compilation unit contains
254 -- redundant with clauses. When checking body clauses against spec
255 -- clauses, set Context_Items to the context list of the body and
256 -- Spec_Context_Items to that of the spec. Parent packages are not
257 -- examined for documentation purposes.
259 ---------------------------
260 -- Check_Redundant_Withs --
261 ---------------------------
263 procedure Check_Redundant_Withs
264 (Context_Items
: List_Id
;
265 Spec_Context_Items
: List_Id
:= No_List
)
269 procedure Process_Body_Clauses
270 (Context_List
: List_Id
;
273 Used_Type_Or_Elab
: out Boolean);
274 -- Examine the context clauses of a package body, trying to match the
275 -- name entity of Clause with any list element. If the match occurs
276 -- on a use package clause set Used to True, for a use type clause or
277 -- pragma Elaborate[_All], set Used_Type_Or_Elab to True.
279 procedure Process_Spec_Clauses
280 (Context_List
: List_Id
;
283 Withed
: out Boolean;
284 Exit_On_Self
: Boolean := False);
285 -- Examine the context clauses of a package spec, trying to match
286 -- the name entity of Clause with any list element. If the match
287 -- occurs on a use package clause, set Used to True, for a with
288 -- package clause other than Clause, set Withed to True. Limited
289 -- with clauses, implicitly generated with clauses and withs
290 -- having pragmas Elaborate or Elaborate_All applied to them are
291 -- skipped. Exit_On_Self is used to control the search loop and
292 -- force an exit whenever Clause sees itself in the search.
294 --------------------------
295 -- Process_Body_Clauses --
296 --------------------------
298 procedure Process_Body_Clauses
299 (Context_List
: List_Id
;
302 Used_Type_Or_Elab
: out Boolean)
304 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
310 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean;
311 -- In an expanded name in a use clause, if the prefix is a renamed
312 -- package, the entity is set to the original package as a result,
313 -- when checking whether the package appears in a previous with
314 -- clause, the renaming has to be taken into account, to prevent
315 -- spurious/incorrect warnings. A common case is use of Text_IO.
321 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean is
323 return Entity
(N
) = P
324 or else (Present
(Renamed_Object
(P
))
325 and then Entity
(N
) = Renamed_Object
(P
));
328 -- Start of processing for Process_Body_Clauses
332 Used_Type_Or_Elab
:= False;
334 Cont_Item
:= First
(Context_List
);
335 while Present
(Cont_Item
) loop
337 -- Package use clause
339 if Nkind
(Cont_Item
) = N_Use_Package_Clause
342 -- Search through use clauses
344 Use_Item
:= First
(Names
(Cont_Item
));
345 while Present
(Use_Item
) and then not Used
loop
347 -- Case of a direct use of the one we are looking for
349 if Entity
(Use_Item
) = Nam_Ent
then
352 -- Handle nested case, as in "with P; use P.Q.R"
359 -- Loop through prefixes looking for match
362 while Nkind
(UE
) = N_Expanded_Name
loop
363 if Same_Unit
(Prefix
(UE
), Nam_Ent
) then
378 elsif Nkind
(Cont_Item
) = N_Use_Type_Clause
379 and then not Used_Type_Or_Elab
381 Subt_Mark
:= First
(Subtype_Marks
(Cont_Item
));
382 while Present
(Subt_Mark
)
383 and then not Used_Type_Or_Elab
385 if Same_Unit
(Prefix
(Subt_Mark
), Nam_Ent
) then
386 Used_Type_Or_Elab
:= True;
392 -- Pragma Elaborate or Elaborate_All
394 elsif Nkind
(Cont_Item
) = N_Pragma
396 Nam_In
(Pragma_Name
(Cont_Item
), Name_Elaborate
,
398 and then not Used_Type_Or_Elab
401 First
(Pragma_Argument_Associations
(Cont_Item
));
402 while Present
(Prag_Unit
) and then not Used_Type_Or_Elab
loop
403 if Entity
(Expression
(Prag_Unit
)) = Nam_Ent
then
404 Used_Type_Or_Elab
:= True;
413 end Process_Body_Clauses
;
415 --------------------------
416 -- Process_Spec_Clauses --
417 --------------------------
419 procedure Process_Spec_Clauses
420 (Context_List
: List_Id
;
423 Withed
: out Boolean;
424 Exit_On_Self
: Boolean := False)
426 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
434 Cont_Item
:= First
(Context_List
);
435 while Present
(Cont_Item
) loop
437 -- Stop the search since the context items after Cont_Item have
438 -- already been examined in a previous iteration of the reverse
439 -- loop in Check_Redundant_Withs.
442 and Cont_Item
= Clause
447 -- Package use clause
449 if Nkind
(Cont_Item
) = N_Use_Package_Clause
452 Use_Item
:= First
(Names
(Cont_Item
));
453 while Present
(Use_Item
) and then not Used
loop
454 if Entity
(Use_Item
) = Nam_Ent
then
461 -- Package with clause. Avoid processing self, implicitly
462 -- generated with clauses or limited with clauses. Note that
463 -- we examine with clauses having pragmas Elaborate or
464 -- Elaborate_All applied to them due to cases such as:
468 -- pragma Elaborate (Pack);
470 -- In this case, the second with clause is redundant since
471 -- the pragma applies only to the first "with Pack;".
473 -- Note that we only consider with_clauses that comes from
474 -- source. In the case of renamings used as prefixes of names
475 -- in with_clauses, we generate a with_clause for the prefix,
476 -- which we do not treat as implicit because it is needed for
477 -- visibility analysis, but is also not redundant.
479 elsif Nkind
(Cont_Item
) = N_With_Clause
480 and then not Implicit_With
(Cont_Item
)
481 and then Comes_From_Source
(Cont_Item
)
482 and then not Limited_Present
(Cont_Item
)
483 and then Cont_Item
/= Clause
484 and then Entity
(Name
(Cont_Item
)) = Nam_Ent
491 end Process_Spec_Clauses
;
493 -- Start of processing for Check_Redundant_Withs
496 Clause
:= Last
(Context_Items
);
497 while Present
(Clause
) loop
499 -- Avoid checking implicitly generated with clauses, limited with
500 -- clauses or withs that have pragma Elaborate or Elaborate_All.
502 if Nkind
(Clause
) = N_With_Clause
503 and then not Implicit_With
(Clause
)
504 and then not Limited_Present
(Clause
)
505 and then not Elaborate_Present
(Clause
)
507 -- With_clauses introduced for renamings of parent clauses
508 -- are not marked implicit because they need to be properly
509 -- installed, but they do not come from source and do not
512 and then Comes_From_Source
(Clause
)
514 -- Package body-to-spec check
516 if Present
(Spec_Context_Items
) then
518 Used_In_Body
: Boolean;
519 Used_In_Spec
: Boolean;
520 Used_Type_Or_Elab
: Boolean;
521 Withed_In_Spec
: Boolean;
525 (Context_List
=> Spec_Context_Items
,
527 Used
=> Used_In_Spec
,
528 Withed
=> Withed_In_Spec
);
531 (Context_List
=> Context_Items
,
533 Used
=> Used_In_Body
,
534 Used_Type_Or_Elab
=> Used_Type_Or_Elab
);
536 -- "Type Elab" refers to the presence of either a use
537 -- type clause, pragmas Elaborate or Elaborate_All.
539 -- +---------------+---------------------------+------+
540 -- | Spec | Body | Warn |
541 -- +--------+------+--------+------+-----------+------+
542 -- | Withed | Used | Withed | Used | Type Elab | |
543 -- | X | | X | | | X |
544 -- | X | | X | X | | |
545 -- | X | | X | | X | |
546 -- | X | | X | X | X | |
547 -- | X | X | X | | | X |
548 -- | X | X | X | | X | |
549 -- | X | X | X | X | | X |
550 -- | X | X | X | X | X | |
551 -- +--------+------+--------+------+-----------+------+
554 and then not Used_Type_Or_Elab
)
556 ((not Used_In_Spec
and then not Used_In_Body
)
557 or else Used_In_Spec
)
559 Error_Msg_N
-- CODEFIX
560 ("redundant with clause in body?r?", Clause
);
563 Used_In_Body
:= False;
564 Used_In_Spec
:= False;
565 Used_Type_Or_Elab
:= False;
566 Withed_In_Spec
:= False;
569 -- Standalone package spec or body check
573 Dont_Care
: Boolean := False;
574 Withed
: Boolean := False;
577 -- The mechanism for examining the context clauses of a
578 -- package spec can be applied to package body clauses.
581 (Context_List
=> Context_Items
,
585 Exit_On_Self
=> True);
588 Error_Msg_N
-- CODEFIX
589 ("redundant with clause?r?", Clause
);
597 end Check_Redundant_Withs
;
601 Main_Cunit
: constant Node_Id
:= Cunit
(Main_Unit
);
602 Unit_Node
: constant Node_Id
:= Unit
(N
);
603 Lib_Unit
: Node_Id
:= Library_Unit
(N
);
604 Par_Spec_Name
: Unit_Name_Type
;
606 Unum
: Unit_Number_Type
;
608 -- Start of processing for Analyze_Compilation_Unit
611 Process_Compilation_Unit_Pragmas
(N
);
613 -- If the unit is a subunit whose parent has not been analyzed (which
614 -- indicates that the main unit is a subunit, either the current one or
615 -- one of its descendants) then the subunit is compiled as part of the
616 -- analysis of the parent, which we proceed to do. Basically this gets
617 -- handled from the top down and we don't want to do anything at this
618 -- level (i.e. this subunit will be handled on the way down from the
619 -- parent), so at this level we immediately return. If the subunit ends
620 -- up not analyzed, it means that the parent did not contain a stub for
621 -- it, or that there errors were detected in some ancestor.
623 if Nkind
(Unit_Node
) = N_Subunit
and then not Analyzed
(Lib_Unit
) then
624 Semantics
(Lib_Unit
);
626 if not Analyzed
(Proper_Body
(Unit_Node
)) then
627 if Serious_Errors_Detected
> 0 then
628 Error_Msg_N
("subunit not analyzed (errors in parent unit)", N
);
630 Error_Msg_N
("missing stub for subunit", N
);
637 -- Analyze context (this will call Sem recursively for with'ed units) To
638 -- detect circularities among with-clauses that are not caught during
639 -- loading, we set the Context_Pending flag on the current unit. If the
640 -- flag is already set there is a potential circularity. We exclude
641 -- predefined units from this check because they are known to be safe.
642 -- We also exclude package bodies that are present because circularities
643 -- between bodies are harmless (and necessary).
645 if Context_Pending
(N
) then
647 Circularity
: Boolean := True;
650 if Is_Predefined_File_Name
651 (Unit_File_Name
(Get_Source_Unit
(Unit
(N
))))
653 Circularity
:= False;
656 for U
in Main_Unit
+ 1 .. Last_Unit
loop
657 if Nkind
(Unit
(Cunit
(U
))) = N_Package_Body
658 and then not Analyzed
(Cunit
(U
))
660 Circularity
:= False;
667 Error_Msg_N
("circular dependency caused by with_clauses", N
);
669 ("\possibly missing limited_with clause"
670 & " in one of the following", N
);
672 for U
in Main_Unit
.. Last_Unit
loop
673 if Context_Pending
(Cunit
(U
)) then
674 Error_Msg_Unit_1
:= Get_Unit_Name
(Unit
(Cunit
(U
)));
675 Error_Msg_N
("\unit$", N
);
679 raise Unrecoverable_Error
;
683 Set_Context_Pending
(N
);
688 Set_Context_Pending
(N
, False);
690 -- If the unit is a package body, the spec is already loaded and must be
691 -- analyzed first, before we analyze the body.
693 if Nkind
(Unit_Node
) = N_Package_Body
then
695 -- If no Lib_Unit, then there was a serious previous error, so just
696 -- ignore the entire analysis effort.
698 if No
(Lib_Unit
) then
699 Check_Error_Detected
;
703 -- Analyze the package spec
705 Semantics
(Lib_Unit
);
707 -- Check for unused with's
709 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
711 -- Verify that the library unit is a package declaration
713 if not Nkind_In
(Unit
(Lib_Unit
), N_Package_Declaration
,
714 N_Generic_Package_Declaration
)
717 ("no legal package declaration for package body", N
);
720 -- Otherwise, the entity in the declaration is visible. Update the
721 -- version to reflect dependence of this body on the spec.
724 Spec_Id
:= Defining_Entity
(Unit
(Lib_Unit
));
725 Set_Is_Immediately_Visible
(Spec_Id
, True);
726 Version_Update
(N
, Lib_Unit
);
728 if Nkind
(Defining_Unit_Name
(Unit_Node
)) =
729 N_Defining_Program_Unit_Name
731 Generate_Parent_References
(Unit_Node
, Scope
(Spec_Id
));
736 -- If the unit is a subprogram body, then we similarly need to analyze
737 -- its spec. However, things are a little simpler in this case, because
738 -- here, this analysis is done mostly for error checking and consistency
739 -- purposes (but not only, e.g. there could be a contract on the spec),
740 -- so there's nothing else to be done.
742 elsif Nkind
(Unit_Node
) = N_Subprogram_Body
then
743 if Acts_As_Spec
(N
) then
745 -- If the subprogram body is a child unit, we must create a
746 -- declaration for it, in order to properly load the parent(s).
747 -- After this, the original unit does not acts as a spec, because
748 -- there is an explicit one. If this unit appears in a context
749 -- clause, then an implicit with on the parent will be added when
750 -- installing the context. If this is the main unit, there is no
751 -- Unit_Table entry for the declaration (it has the unit number
752 -- of the main unit) and code generation is unaffected.
754 Unum
:= Get_Cunit_Unit_Number
(N
);
755 Par_Spec_Name
:= Get_Parent_Spec_Name
(Unit_Name
(Unum
));
757 if Par_Spec_Name
/= No_Unit_Name
then
760 (Load_Name
=> Par_Spec_Name
,
765 if Unum
/= No_Unit
then
767 -- Build subprogram declaration and attach parent unit to it
768 -- This subprogram declaration does not come from source,
769 -- Nevertheless the backend must generate debugging info for
770 -- it, and this must be indicated explicitly. We also mark
771 -- the body entity as a child unit now, to prevent a
772 -- cascaded error if the spec entity cannot be entered
773 -- in its scope. Finally we create a Units table entry for
774 -- the subprogram declaration, to maintain a one-to-one
775 -- correspondence with compilation unit nodes. This is
776 -- critical for the tree traversals performed by CodePeer.
779 Loc
: constant Source_Ptr
:= Sloc
(N
);
780 SCS
: constant Boolean :=
781 Get_Comes_From_Source_Default
;
784 Set_Comes_From_Source_Default
(False);
786 -- Note: We copy the Context_Items from the explicit body
787 -- to the implicit spec, setting the former to Empty_List
788 -- to preserve the treeish nature of the tree, during
789 -- analysis of the spec. Then we put it back the way it
790 -- was -- copy the Context_Items from the spec to the
791 -- body, and set the spec Context_Items to Empty_List.
792 -- It is necessary to preserve the treeish nature,
793 -- because otherwise we will call End_Use_* twice on the
797 Make_Compilation_Unit
(Loc
,
798 Context_Items
=> Context_Items
(N
),
800 Make_Subprogram_Declaration
(Sloc
(N
),
803 (Specification
(Unit_Node
))),
805 Make_Compilation_Unit_Aux
(Loc
));
807 Set_Context_Items
(N
, Empty_List
);
808 Set_Library_Unit
(N
, Lib_Unit
);
809 Set_Parent_Spec
(Unit
(Lib_Unit
), Cunit
(Unum
));
810 Make_Child_Decl_Unit
(N
);
811 Semantics
(Lib_Unit
);
813 -- Now that a separate declaration exists, the body
814 -- of the child unit does not act as spec any longer.
816 Set_Acts_As_Spec
(N
, False);
817 Set_Is_Child_Unit
(Defining_Entity
(Unit_Node
));
818 Set_Debug_Info_Needed
(Defining_Entity
(Unit
(Lib_Unit
)));
819 Set_Comes_From_Source_Default
(SCS
);
821 -- Restore Context_Items to the body
823 Set_Context_Items
(N
, Context_Items
(Lib_Unit
));
824 Set_Context_Items
(Lib_Unit
, Empty_List
);
829 -- Here for subprogram with separate declaration
832 Semantics
(Lib_Unit
);
833 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
834 Version_Update
(N
, Lib_Unit
);
837 -- If this is a child unit, generate references to the parents
839 if Nkind
(Defining_Unit_Name
(Specification
(Unit_Node
))) =
840 N_Defining_Program_Unit_Name
842 Generate_Parent_References
843 (Specification
(Unit_Node
),
844 Scope
(Defining_Entity
(Unit
(Lib_Unit
))));
848 -- If it is a child unit, the parent must be elaborated first and we
849 -- update version, since we are dependent on our parent.
851 if Is_Child_Spec
(Unit_Node
) then
853 -- The analysis of the parent is done with style checks off
856 Save_Style_Check
: constant Boolean := Style_Check
;
859 if not GNAT_Mode
then
860 Style_Check
:= False;
863 Semantics
(Parent_Spec
(Unit_Node
));
864 Version_Update
(N
, Parent_Spec
(Unit_Node
));
866 -- Restore style check settings
868 Style_Check
:= Save_Style_Check
;
872 -- With the analysis done, install the context. Note that we can't
873 -- install the context from the with clauses as we analyze them, because
874 -- each with clause must be analyzed in a clean visibility context, so
875 -- we have to wait and install them all at once.
879 if Is_Child_Spec
(Unit_Node
) then
881 -- Set the entities of all parents in the program_unit_name
883 Generate_Parent_References
884 (Unit_Node
, Get_Parent_Entity
(Unit
(Parent_Spec
(Unit_Node
))));
887 -- All components of the context: with-clauses, library unit, ancestors
888 -- if any, (and their context) are analyzed and installed.
890 -- Call special debug routine sm if this is the main unit
892 if Current_Sem_Unit
= Main_Unit
then
896 -- Now analyze the unit (package, subprogram spec, body) itself
900 if Warn_On_Redundant_Constructs
then
901 Check_Redundant_Withs
(Context_Items
(N
));
903 if Nkind
(Unit_Node
) = N_Package_Body
then
904 Check_Redundant_Withs
905 (Context_Items
=> Context_Items
(N
),
906 Spec_Context_Items
=> Context_Items
(Lib_Unit
));
910 -- The above call might have made Unit_Node an N_Subprogram_Body from
911 -- something else, so propagate any Acts_As_Spec flag.
913 if Nkind
(Unit_Node
) = N_Subprogram_Body
914 and then Acts_As_Spec
(Unit_Node
)
916 Set_Acts_As_Spec
(N
);
919 -- Register predefined units in Rtsfind
922 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Sloc
(N
));
924 if Is_Predefined_File_Name
(Unit_File_Name
(Unum
)) then
925 Set_RTU_Loaded
(Unit_Node
);
929 -- Treat compilation unit pragmas that appear after the library unit
931 if Present
(Pragmas_After
(Aux_Decls_Node
(N
))) then
933 Prag_Node
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(N
)));
935 while Present
(Prag_Node
) loop
942 -- Analyze the contract of a [generic] subprogram that acts as a
943 -- compilation unit after all compilation pragmas have been analyzed.
945 if Nkind_In
(Unit_Node
, N_Generic_Subprogram_Declaration
,
946 N_Subprogram_Declaration
)
948 Analyze_Entry_Or_Subprogram_Contract
(Defining_Entity
(Unit_Node
));
951 -- Generate distribution stubs if requested and no error
954 and then (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
956 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
957 and then Fatal_Error
(Main_Unit
) /= Error_Detected
959 if Is_RCI_Pkg_Spec_Or_Body
(N
) then
961 -- Regular RCI package
963 Add_Stub_Constructs
(N
);
965 elsif (Nkind
(Unit_Node
) = N_Package_Declaration
966 and then Is_Shared_Passive
(Defining_Entity
967 (Specification
(Unit_Node
))))
968 or else (Nkind
(Unit_Node
) = N_Package_Body
970 Is_Shared_Passive
(Corresponding_Spec
(Unit_Node
)))
972 -- Shared passive package
974 Add_Stub_Constructs
(N
);
976 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
978 Is_Remote_Call_Interface
979 (Defining_Entity
(Specification
(Instance_Spec
(Unit_Node
))))
981 -- Instantiation of a RCI generic package
983 Add_Stub_Constructs
(N
);
987 -- Remove unit from visibility, so that environment is clean for the
988 -- next compilation, which is either the main unit or some other unit
991 if Nkind_In
(Unit_Node
, N_Package_Declaration
,
992 N_Package_Renaming_Declaration
,
993 N_Subprogram_Declaration
)
994 or else Nkind
(Unit_Node
) in N_Generic_Declaration
995 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
996 and then Acts_As_Spec
(Unit_Node
))
998 Remove_Unit_From_Visibility
(Defining_Entity
(Unit_Node
));
1000 -- If the unit is an instantiation whose body will be elaborated for
1001 -- inlining purposes, use the proper entity of the instance. The entity
1002 -- may be missing if the instantiation was illegal.
1004 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
1005 and then not Error_Posted
(Unit_Node
)
1006 and then Present
(Instance_Spec
(Unit_Node
))
1008 Remove_Unit_From_Visibility
1009 (Defining_Entity
(Instance_Spec
(Unit_Node
)));
1011 elsif Nkind
(Unit_Node
) = N_Package_Body
1012 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
1013 and then not Acts_As_Spec
(Unit_Node
))
1015 -- Bodies that are not the main unit are compiled if they are generic
1016 -- or contain generic or inlined units. Their analysis brings in the
1017 -- context of the corresponding spec (unit declaration) which must be
1018 -- removed as well, to return the compilation environment to its
1021 Remove_Context
(Lib_Unit
);
1022 Set_Is_Immediately_Visible
(Defining_Entity
(Unit
(Lib_Unit
)), False);
1025 -- Last step is to deinstall the context we just installed as well as
1026 -- the unit just compiled.
1030 -- When generating code for a non-generic main unit, check that withed
1031 -- generic units have a body if they need it, even if the units have not
1032 -- been instantiated. Force the load of the bodies to produce the proper
1033 -- error if the body is absent. The same applies to GNATprove mode, with
1034 -- the added benefit of capturing global references within the generic.
1035 -- This in turn allows for proper inlining of subprogram bodies without
1036 -- a previous declaration.
1038 if Get_Cunit_Unit_Number
(N
) = Main_Unit
1039 and then ((Operating_Mode
= Generate_Code
and then Expander_Active
)
1041 (Operating_Mode
= Check_Semantics
and then GNATprove_Mode
))
1043 -- Check whether the source for the body of the unit must be included
1044 -- in a standalone library.
1046 Check_Body_Needed_For_SAL
(Cunit_Entity
(Main_Unit
));
1048 -- Indicate that the main unit is now analyzed, to catch possible
1049 -- circularities between it and generic bodies. Remove main unit from
1050 -- visibility. This might seem superfluous, but the main unit must
1051 -- not be visible in the generic body expansions that follow.
1053 Set_Analyzed
(N
, True);
1054 Set_Is_Immediately_Visible
(Cunit_Entity
(Main_Unit
), False);
1059 Un
: Unit_Number_Type
;
1061 Save_Style_Check
: constant Boolean := Style_Check
;
1064 Item
:= First
(Context_Items
(N
));
1065 while Present
(Item
) loop
1067 -- Check for explicit with clause
1069 if Nkind
(Item
) = N_With_Clause
1070 and then not Implicit_With
(Item
)
1072 -- Ada 2005 (AI-50217): Ignore limited-withed units
1074 and then not Limited_Present
(Item
)
1076 Nam
:= Entity
(Name
(Item
));
1078 -- Compile the generic subprogram, unless it is intrinsic or
1079 -- imported so no body is required, or generic package body
1080 -- if the package spec requires a body.
1082 if (Is_Generic_Subprogram
(Nam
)
1083 and then not Is_Intrinsic_Subprogram
(Nam
)
1084 and then not Is_Imported
(Nam
))
1085 or else (Ekind
(Nam
) = E_Generic_Package
1086 and then Unit_Requires_Body
(Nam
))
1088 Style_Check
:= False;
1090 if Present
(Renamed_Object
(Nam
)) then
1096 (Unit_Declaration_Node
1097 (Renamed_Object
(Nam
)))),
1106 Get_Body_Name
(Get_Unit_Name
(Item
)),
1113 if Un
= No_Unit
then
1115 ("body of generic unit& not found", Item
, Nam
);
1118 elsif not Analyzed
(Cunit
(Un
))
1119 and then Un
/= Main_Unit
1120 and then Fatal_Error
(Un
) /= Error_Detected
1122 Style_Check
:= False;
1123 Semantics
(Cunit
(Un
));
1131 -- Restore style checks settings
1133 Style_Check
:= Save_Style_Check
;
1137 -- Deal with creating elaboration counter if needed. We create an
1138 -- elaboration counter only for units that come from source since
1139 -- units manufactured by the compiler never need elab checks.
1141 if Comes_From_Source
(N
)
1142 and then Nkind_In
(Unit_Node
, N_Package_Declaration
,
1143 N_Generic_Package_Declaration
,
1144 N_Subprogram_Declaration
,
1145 N_Generic_Subprogram_Declaration
)
1148 Loc
: constant Source_Ptr
:= Sloc
(N
);
1149 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1152 Spec_Id
:= Defining_Entity
(Unit_Node
);
1153 Generate_Definition
(Spec_Id
);
1155 -- See if an elaboration entity is required for possible access
1156 -- before elaboration checking. Note that we must allow for this
1157 -- even if -gnatE is not set, since a client may be compiled in
1158 -- -gnatE mode and reference the entity.
1160 -- These entities are also used by the binder to prevent multiple
1161 -- attempts to execute the elaboration code for the library case
1162 -- where the elaboration routine might otherwise be called more
1165 -- Case of units which do not require elaboration checks
1168 -- Pure units do not need checks
1172 -- Preelaborated units do not need checks
1174 or else Is_Preelaborated
(Spec_Id
)
1176 -- No checks needed if pragma Elaborate_Body present
1178 or else Has_Pragma_Elaborate_Body
(Spec_Id
)
1180 -- No checks needed if unit does not require a body
1182 or else not Unit_Requires_Body
(Spec_Id
)
1184 -- No checks needed for predefined files
1186 or else Is_Predefined_File_Name
(Unit_File_Name
(Unum
))
1188 -- No checks required if no separate spec
1190 or else Acts_As_Spec
(N
)
1192 -- This is a case where we only need the entity for
1193 -- checking to prevent multiple elaboration checks.
1195 Set_Elaboration_Entity_Required
(Spec_Id
, False);
1197 -- Case of elaboration entity is required for access before
1198 -- elaboration checking (so certainly we must build it).
1201 Set_Elaboration_Entity_Required
(Spec_Id
, True);
1204 Build_Elaboration_Entity
(N
, Spec_Id
);
1208 -- Freeze the compilation unit entity. This for sure is needed because
1209 -- of some warnings that can be output (see Freeze_Subprogram), but may
1210 -- in general be required. If freezing actions result, place them in the
1211 -- compilation unit actions list, and analyze them.
1214 L
: constant List_Id
:=
1215 Freeze_Entity
(Cunit_Entity
(Current_Sem_Unit
), N
);
1217 while Is_Non_Empty_List
(L
) loop
1218 Insert_Library_Level_Action
(Remove_Head
(L
));
1224 -- Call Check_Package_Body so that a body containing subprograms with
1225 -- Inline_Always can be made available for front end inlining.
1227 if Nkind
(Unit_Node
) = N_Package_Declaration
1228 and then Get_Cunit_Unit_Number
(N
) /= Main_Unit
1230 -- We don't need to do this if the Expander is not active, since there
1231 -- is no code to inline.
1233 and then Expander_Active
1236 Save_Style_Check
: constant Boolean := Style_Check
;
1237 Save_Warning
: constant Warning_Mode_Type
:= Warning_Mode
;
1238 Options
: Style_Check_Options
;
1241 Save_Style_Check_Options
(Options
);
1242 Reset_Style_Check_Options
;
1243 Opt
.Warning_Mode
:= Suppress
;
1245 Check_Package_Body_For_Inlining
(N
, Defining_Entity
(Unit_Node
));
1247 Reset_Style_Check_Options
;
1248 Set_Style_Check_Options
(Options
);
1249 Style_Check
:= Save_Style_Check
;
1250 Warning_Mode
:= Save_Warning
;
1254 -- If we are generating obsolescent warnings, then here is where we
1255 -- generate them for the with'ed items. The reason for this special
1256 -- processing is that the normal mechanism of generating the warnings
1257 -- for referenced entities does not work for context clause references.
1258 -- That's because when we first analyze the context, it is too early to
1259 -- know if the with'ing unit is itself obsolescent (which suppresses
1263 and then Warn_On_Obsolescent_Feature
1264 and then Nkind
(Unit_Node
) not in N_Generic_Instantiation
1266 -- Push current compilation unit as scope, so that the test for
1267 -- being within an obsolescent unit will work correctly. The check
1268 -- is not performed within an instantiation, because the warning
1269 -- will have been emitted in the corresponding generic unit.
1271 Push_Scope
(Defining_Entity
(Unit_Node
));
1273 -- Loop through context items to deal with with clauses
1281 Item
:= First
(Context_Items
(N
));
1282 while Present
(Item
) loop
1283 if Nkind
(Item
) = N_With_Clause
1285 -- Suppress this check in limited-withed units. Further work
1286 -- needed here if we decide to incorporate this check on
1287 -- limited-withed units.
1289 and then not Limited_Present
(Item
)
1292 Ent
:= Entity
(Nam
);
1294 if Is_Obsolescent
(Ent
) then
1295 Output_Obsolescent_Entity_Warnings
(Nam
, Ent
);
1303 -- Remove temporary install of current unit as scope
1308 -- If No_Elaboration_Code_All was encountered, this is where we do the
1309 -- transitive test of with'ed units to make sure they have the aspect.
1310 -- This is delayed till the end of analyzing the compilation unit to
1311 -- ensure that the pragma/aspect, if present, has been analyzed.
1313 Check_No_Elab_Code_All
(N
);
1314 end Analyze_Compilation_Unit
;
1316 ---------------------
1317 -- Analyze_Context --
1318 ---------------------
1320 procedure Analyze_Context
(N
: Node_Id
) is
1321 Ukind
: constant Node_Kind
:= Nkind
(Unit
(N
));
1325 -- First process all configuration pragmas at the start of the context
1326 -- items. Strictly these are not part of the context clause, but that
1327 -- is where the parser puts them. In any case for sure we must analyze
1328 -- these before analyzing the actual context items, since they can have
1329 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1330 -- be with'ed as a result of changing categorizations in Ada 2005).
1332 Item
:= First
(Context_Items
(N
));
1333 while Present
(Item
)
1334 and then Nkind
(Item
) = N_Pragma
1335 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
1341 -- This is the point at which we capture the configuration settings
1342 -- for the unit. At the moment only the Optimize_Alignment setting
1343 -- needs to be captured. Probably more later ???
1345 if Optimize_Alignment_Local
then
1346 Set_OA_Setting
(Current_Sem_Unit
, 'L');
1348 Set_OA_Setting
(Current_Sem_Unit
, Optimize_Alignment
);
1351 -- Loop through actual context items. This is done in two passes:
1353 -- a) The first pass analyzes non-limited with-clauses and also any
1354 -- configuration pragmas (we need to get the latter analyzed right
1355 -- away, since they can affect processing of subsequent items).
1357 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1359 while Present
(Item
) loop
1361 -- For with clause, analyze the with clause, and then update the
1362 -- version, since we are dependent on a unit that we with.
1364 if Nkind
(Item
) = N_With_Clause
1365 and then not Limited_Present
(Item
)
1367 -- Skip analyzing with clause if no unit, nothing to do (this
1368 -- happens for a with that references a non-existent unit).
1370 if Present
(Library_Unit
(Item
)) then
1372 -- Skip analyzing with clause if this is a with_clause for
1373 -- the main unit, which happens if a subunit has a useless
1374 -- with_clause on its parent.
1376 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
) then
1379 -- Here for the case of a useless with for the main unit
1382 Set_Entity
(Name
(Item
), Cunit_Entity
(Current_Sem_Unit
));
1386 -- Do version update (skipped for implicit with)
1388 if not Implicit_With
(Item
) then
1389 Version_Update
(N
, Library_Unit
(Item
));
1392 -- Skip pragmas. Configuration pragmas at the start were handled in
1393 -- the loop above, and remaining pragmas are not processed until we
1394 -- actually install the context (see Install_Context). We delay the
1395 -- analysis of these pragmas to make sure that we have installed all
1396 -- the implicit with's on parent units.
1398 -- Skip use clauses at this stage, since we don't want to do any
1399 -- installing of potentially use-visible entities until we
1400 -- actually install the complete context (in Install_Context).
1401 -- Otherwise things can get installed in the wrong context.
1410 -- Second pass: examine all limited_with clauses. All other context
1411 -- items are ignored in this pass.
1413 Item
:= First
(Context_Items
(N
));
1414 while Present
(Item
) loop
1415 if Nkind
(Item
) = N_With_Clause
1416 and then Limited_Present
(Item
)
1418 -- No need to check errors on implicitly generated limited-with
1421 if not Implicit_With
(Item
) then
1423 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1424 -- properly rejected, including renaming declarations.
1426 if not Nkind_In
(Ukind
, N_Package_Declaration
,
1427 N_Subprogram_Declaration
)
1428 and then Ukind
not in N_Generic_Declaration
1429 and then Ukind
not in N_Generic_Instantiation
1431 Error_Msg_N
("limited with_clause not allowed here", Item
);
1433 -- Check wrong use of a limited with clause applied to the
1434 -- compilation unit containing the limited-with clause.
1436 -- limited with P.Q;
1437 -- package P.Q is ...
1439 elsif Unit
(Library_Unit
(Item
)) = Unit
(N
) then
1440 Error_Msg_N
("wrong use of limited-with clause", Item
);
1442 -- Check wrong use of limited-with clause applied to some
1443 -- immediate ancestor.
1445 elsif Is_Child_Spec
(Unit
(N
)) then
1447 Lib_U
: constant Entity_Id
:= Unit
(Library_Unit
(Item
));
1451 P
:= Parent_Spec
(Unit
(N
));
1453 if Unit
(P
) = Lib_U
then
1454 Error_Msg_N
("limited with_clause cannot "
1455 & "name ancestor", Item
);
1459 exit when not Is_Child_Spec
(Unit
(P
));
1460 P
:= Parent_Spec
(Unit
(P
));
1465 -- Check if the limited-withed unit is already visible through
1466 -- some context clause of the current compilation unit or some
1467 -- ancestor of the current compilation unit.
1470 Lim_Unit_Name
: constant Node_Id
:= Name
(Item
);
1471 Comp_Unit
: Node_Id
;
1473 Unit_Name
: Node_Id
;
1478 It
:= First
(Context_Items
(Comp_Unit
));
1479 while Present
(It
) loop
1481 and then Nkind
(It
) = N_With_Clause
1482 and then not Limited_Present
(It
)
1484 Nkind_In
(Unit
(Library_Unit
(It
)),
1485 N_Package_Declaration
,
1486 N_Package_Renaming_Declaration
)
1488 if Nkind
(Unit
(Library_Unit
(It
))) =
1489 N_Package_Declaration
1491 Unit_Name
:= Name
(It
);
1493 Unit_Name
:= Name
(Unit
(Library_Unit
(It
)));
1496 -- Check if the named package (or some ancestor)
1497 -- leaves visible the full-view of the unit given
1498 -- in the limited-with clause.
1501 if Designate_Same_Unit
(Lim_Unit_Name
,
1504 Error_Msg_Sloc
:= Sloc
(It
);
1506 ("simultaneous visibility of limited "
1507 & "and unlimited views not allowed",
1510 ("\unlimited view visible through "
1511 & "context clause #",
1515 elsif Nkind
(Unit_Name
) = N_Identifier
then
1519 Unit_Name
:= Prefix
(Unit_Name
);
1526 exit when not Is_Child_Spec
(Unit
(Comp_Unit
));
1528 Comp_Unit
:= Parent_Spec
(Unit
(Comp_Unit
));
1533 -- Skip analyzing with clause if no unit, see above
1535 if Present
(Library_Unit
(Item
)) then
1539 -- A limited_with does not impose an elaboration order, but
1540 -- there is a semantic dependency for recompilation purposes.
1542 if not Implicit_With
(Item
) then
1543 Version_Update
(N
, Library_Unit
(Item
));
1546 -- Pragmas and use clauses and with clauses other than limited
1547 -- with's are ignored in this pass through the context items.
1555 end Analyze_Context
;
1557 -------------------------------
1558 -- Analyze_Package_Body_Stub --
1559 -------------------------------
1561 procedure Analyze_Package_Body_Stub
(N
: Node_Id
) is
1562 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1564 Opts
: Config_Switches_Type
;
1567 -- The package declaration must be in the current declarative part
1569 Check_Stub_Level
(N
);
1570 Nam
:= Current_Entity_In_Scope
(Id
);
1572 if No
(Nam
) or else not Is_Package_Or_Generic_Package
(Nam
) then
1573 Error_Msg_N
("missing specification for package stub", N
);
1575 elsif Has_Completion
(Nam
)
1576 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Nam
)))
1578 Error_Msg_N
("duplicate or redundant stub for package", N
);
1581 -- Retain and restore the configuration options of the enclosing
1582 -- context as the proper body may introduce a set of its own.
1584 Save_Opt_Config_Switches
(Opts
);
1586 -- Indicate that the body of the package exists. If we are doing
1587 -- only semantic analysis, the stub stands for the body. If we are
1588 -- generating code, the existence of the body will be confirmed
1589 -- when we load the proper body.
1591 Set_Has_Completion
(Nam
);
1592 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1593 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1594 Generate_Reference
(Nam
, Id
, 'b');
1595 Analyze_Proper_Body
(N
, Nam
);
1597 Restore_Opt_Config_Switches
(Opts
);
1599 end Analyze_Package_Body_Stub
;
1601 -------------------------
1602 -- Analyze_Proper_Body --
1603 -------------------------
1605 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1606 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1608 procedure Optional_Subunit
;
1609 -- This procedure is called when the main unit is a stub, or when we
1610 -- are not generating code. In such a case, we analyze the subunit if
1611 -- present, which is user-friendly and in fact required for ASIS, but we
1612 -- don't complain if the subunit is missing. In GNATprove_Mode, we issue
1613 -- an error to avoid formal verification of a partial unit.
1615 ----------------------
1616 -- Optional_Subunit --
1617 ----------------------
1619 procedure Optional_Subunit
is
1620 Comp_Unit
: Node_Id
;
1621 Unum
: Unit_Number_Type
;
1624 -- Try to load subunit, but ignore any errors that occur during the
1625 -- loading of the subunit, by using the special feature in Errout to
1626 -- ignore all errors. Note that Fatal_Error will still be set, so we
1627 -- will be able to check for this case below.
1629 if not (ASIS_Mode
or GNATprove_Mode
) then
1630 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1635 (Load_Name
=> Subunit_Name
,
1636 Required
=> GNATprove_Mode
,
1640 if not (ASIS_Mode
or GNATprove_Mode
) then
1641 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1644 -- All done if we successfully loaded the subunit
1647 and then (Fatal_Error
(Unum
) /= Error_Detected
1648 or else Try_Semantics
)
1650 Comp_Unit
:= Cunit
(Unum
);
1652 -- If the file was empty or seriously mangled, the unit itself may
1655 if No
(Unit
(Comp_Unit
)) then
1657 ("subunit does not contain expected proper body", N
);
1659 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1661 ("expected SEPARATE subunit, found child unit",
1662 Cunit_Entity
(Unum
));
1664 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1665 Analyze_Subunit
(Comp_Unit
);
1666 Set_Library_Unit
(N
, Comp_Unit
);
1667 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1670 elsif Unum
= No_Unit
1671 and then Present
(Nam
)
1673 if Is_Protected_Type
(Nam
) then
1674 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1676 Set_Corresponding_Body
(
1677 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1680 end Optional_Subunit
;
1684 Comp_Unit
: Node_Id
;
1685 Unum
: Unit_Number_Type
;
1687 -- Start of processing for Analyze_Proper_Body
1690 -- If the subunit is already loaded, it means that the main unit is a
1691 -- subunit, and that the current unit is one of its parents which was
1692 -- being analyzed to provide the needed context for the analysis of the
1693 -- subunit. In this case we analyze the subunit and continue with the
1694 -- parent, without looking at subsequent subunits.
1696 if Is_Loaded
(Subunit_Name
) then
1698 -- If the proper body is already linked to the stub node, the stub is
1699 -- in a generic unit and just needs analyzing.
1701 if Present
(Library_Unit
(N
)) then
1702 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1704 -- If the subunit has severe errors, the spec of the enclosing
1705 -- body may not be available, in which case do not try analysis.
1707 if Serious_Errors_Detected
> 0
1708 and then No
(Library_Unit
(Library_Unit
(N
)))
1713 -- Collect SCO information for loaded subunit if we are in the
1714 -- extended main unit.
1717 and then In_Extended_Main_Source_Unit
1718 (Cunit_Entity
(Current_Sem_Unit
))
1720 SCO_Record_Raw
(Get_Cunit_Unit_Number
(Library_Unit
(N
)));
1723 Analyze_Subunit
(Library_Unit
(N
));
1725 -- Otherwise we must load the subunit and link to it
1728 -- Load the subunit, this must work, since we originally loaded
1729 -- the subunit earlier on. So this will not really load it, just
1730 -- give access to it.
1734 (Load_Name
=> Subunit_Name
,
1739 -- And analyze the subunit in the parent context (note that we
1740 -- do not call Semantics, since that would remove the parent
1741 -- context). Because of this, we have to manually reset the
1742 -- compiler state to Analyzing since it got destroyed by Load.
1744 if Unum
/= No_Unit
then
1745 Compiler_State
:= Analyzing
;
1747 -- Check that the proper body is a subunit and not a child
1748 -- unit. If the unit was previously loaded, the error will
1749 -- have been emitted when copying the generic node, so we
1750 -- just return to avoid cascaded errors.
1752 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1756 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1757 Analyze_Subunit
(Cunit
(Unum
));
1758 Set_Library_Unit
(N
, Cunit
(Unum
));
1762 -- If the main unit is a subunit, then we are just performing semantic
1763 -- analysis on that subunit, and any other subunits of any parent unit
1764 -- should be ignored, except that if we are building trees for ASIS
1765 -- usage we want to annotate the stub properly. If the main unit is
1766 -- itself a subunit, another subunit is irrelevant unless it is a
1767 -- subunit of the current one, that is to say appears in the current
1770 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1771 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1775 PB
: constant Node_Id
:= Proper_Body
(Unit
(Cunit
(Main_Unit
)));
1777 if Nkind_In
(PB
, N_Package_Body
, N_Subprogram_Body
)
1778 and then List_Containing
(N
) = Declarations
(PB
)
1785 -- But before we return, set the flag for unloaded subunits. This
1786 -- will suppress junk warnings of variables in the same declarative
1787 -- part (or a higher level one) that are in danger of looking unused
1788 -- when in fact there might be a declaration in the subunit that we
1789 -- do not intend to load.
1791 Unloaded_Subunits
:= True;
1794 -- If the subunit is not already loaded, and we are generating code,
1795 -- then this is the case where compilation started from the parent, and
1796 -- we are generating code for an entire subunit tree. In that case we
1797 -- definitely need to load the subunit.
1799 -- In order to continue the analysis with the rest of the parent,
1800 -- and other subunits, we load the unit without requiring its
1801 -- presence, and emit a warning if not found, rather than terminating
1802 -- the compilation abruptly, as for other missing file problems.
1804 elsif Original_Operating_Mode
= Generate_Code
then
1806 -- If the proper body is already linked to the stub node, the stub is
1807 -- in a generic unit and just needs analyzing.
1809 -- We update the version. Although we are not strictly technically
1810 -- semantically dependent on the subunit, given our approach of macro
1811 -- substitution of subunits, it makes sense to include it in the
1812 -- version identification.
1814 if Present
(Library_Unit
(N
)) then
1815 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1816 Analyze_Subunit
(Library_Unit
(N
));
1817 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1819 -- Otherwise we must load the subunit and link to it
1822 -- Make sure that, if the subunit is preprocessed and -gnateG is
1823 -- specified, the preprocessed file will be written.
1825 Lib
.Analysing_Subunit_Of_Main
:= True;
1828 (Load_Name
=> Subunit_Name
,
1832 Lib
.Analysing_Subunit_Of_Main
:= False;
1834 -- Give message if we did not get the unit Emit warning even if
1835 -- missing subunit is not within main unit, to simplify debugging.
1837 pragma Assert
(Original_Operating_Mode
= Generate_Code
);
1838 if Unum
= No_Unit
then
1839 Error_Msg_Unit_1
:= Subunit_Name
;
1841 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1843 ("subunit$$ in file{ not found??!!", N
);
1844 Subunits_Missing
:= True;
1847 -- Load_Unit may reset Compiler_State, since it may have been
1848 -- necessary to parse an additional units, so we make sure that
1849 -- we reset it to the Analyzing state.
1851 Compiler_State
:= Analyzing
;
1853 if Unum
/= No_Unit
then
1854 if Debug_Flag_L
then
1855 Write_Str
("*** Loaded subunit from stub. Analyze");
1859 Comp_Unit
:= Cunit
(Unum
);
1861 -- Check for child unit instead of subunit
1863 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1865 ("expected SEPARATE subunit, found child unit",
1866 Cunit_Entity
(Unum
));
1868 -- OK, we have a subunit
1871 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1872 Set_Library_Unit
(N
, Comp_Unit
);
1874 -- We update the version. Although we are not technically
1875 -- semantically dependent on the subunit, given our approach
1876 -- of macro substitution of subunits, it makes sense to
1877 -- include it in the version identification.
1879 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1881 -- Collect SCO information for loaded subunit if we are in
1882 -- the extended main unit.
1885 and then In_Extended_Main_Source_Unit
1886 (Cunit_Entity
(Current_Sem_Unit
))
1888 SCO_Record_Raw
(Unum
);
1891 -- Analyze the unit if semantics active
1893 if Fatal_Error
(Unum
) /= Error_Detected
1894 or else Try_Semantics
1896 Analyze_Subunit
(Comp_Unit
);
1902 -- The remaining case is when the subunit is not already loaded and we
1903 -- are not generating code. In this case we are just performing semantic
1904 -- analysis on the parent, and we are not interested in the subunit. For
1905 -- subprograms, analyze the stub as a body. For other entities the stub
1906 -- has already been marked as completed.
1911 end Analyze_Proper_Body
;
1913 ----------------------------------
1914 -- Analyze_Protected_Body_Stub --
1915 ----------------------------------
1917 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
1918 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
1921 Check_Stub_Level
(N
);
1923 -- First occurrence of name may have been as an incomplete type
1925 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
1926 Nam
:= Full_View
(Nam
);
1929 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
1930 Error_Msg_N
("missing specification for Protected body", N
);
1933 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1934 Set_Has_Completion
(Etype
(Nam
));
1935 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1936 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
1937 Analyze_Proper_Body
(N
, Etype
(Nam
));
1939 end Analyze_Protected_Body_Stub
;
1941 ----------------------------------
1942 -- Analyze_Subprogram_Body_Stub --
1943 ----------------------------------
1945 -- A subprogram body stub can appear with or without a previous spec. If
1946 -- there is one, then the analysis of the body will find it and verify
1947 -- conformance. The formals appearing in the specification of the stub play
1948 -- no role, except for requiring an additional conformance check. If there
1949 -- is no previous subprogram declaration, the stub acts as a spec, and
1950 -- provides the defining entity for the subprogram.
1952 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
1954 Opts
: Config_Switches_Type
;
1957 Check_Stub_Level
(N
);
1959 -- Verify that the identifier for the stub is unique within this
1960 -- declarative part.
1962 if Nkind_In
(Parent
(N
), N_Block_Statement
,
1966 Decl
:= First
(Declarations
(Parent
(N
)));
1967 while Present
(Decl
) and then Decl
/= N
loop
1968 if Nkind
(Decl
) = N_Subprogram_Body_Stub
1969 and then (Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
1970 Chars
(Defining_Unit_Name
(Specification
(N
))))
1972 Error_Msg_N
("identifier for stub is not unique", N
);
1979 -- Retain and restore the configuration options of the enclosing context
1980 -- as the proper body may introduce a set of its own.
1982 Save_Opt_Config_Switches
(Opts
);
1984 -- Treat stub as a body, which checks conformance if there is a previous
1985 -- declaration, or else introduces entity and its signature.
1987 Analyze_Subprogram_Body
(N
);
1988 Analyze_Proper_Body
(N
, Empty
);
1990 Restore_Opt_Config_Switches
(Opts
);
1991 end Analyze_Subprogram_Body_Stub
;
1993 ---------------------
1994 -- Analyze_Subunit --
1995 ---------------------
1997 -- A subunit is compiled either by itself (for semantic checking) or as
1998 -- part of compiling the parent (for code generation). In either case, by
1999 -- the time we actually process the subunit, the parent has already been
2000 -- installed and analyzed. The node N is a compilation unit, whose context
2001 -- needs to be treated here, because we come directly here from the parent
2002 -- without calling Analyze_Compilation_Unit.
2004 -- The compilation context includes the explicit context of the subunit,
2005 -- and the context of the parent, together with the parent itself. In order
2006 -- to compile the current context, we remove the one inherited from the
2007 -- parent, in order to have a clean visibility table. We restore the parent
2008 -- context before analyzing the proper body itself. On exit, we remove only
2009 -- the explicit context of the subunit.
2011 procedure Analyze_Subunit
(N
: Node_Id
) is
2012 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2013 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2015 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2016 Num_Scopes
: Nat
:= 0;
2017 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2018 Enclosing_Child
: Entity_Id
:= Empty
;
2019 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2021 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2022 Cunit_Boolean_Restrictions_Save
;
2023 -- Save non-partition wide restrictions before processing the subunit.
2024 -- All subunits are analyzed with config restrictions reset and we need
2025 -- to restore these saved values at the end.
2027 procedure Analyze_Subunit_Context
;
2028 -- Capture names in use clauses of the subunit. This must be done before
2029 -- re-installing parent declarations, because items in the context must
2030 -- not be hidden by declarations local to the parent.
2032 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2033 -- Recursive procedure to restore scope of all ancestors of subunit,
2034 -- from outermost in. If parent is not a subunit, the call to install
2035 -- context installs context of spec and (if parent is a child unit) the
2036 -- context of its parents as well. It is confusing that parents should
2037 -- be treated differently in both cases, but the semantics are just not
2040 procedure Re_Install_Use_Clauses
;
2041 -- As part of the removal of the parent scope, the use clauses are
2042 -- removed, to be reinstalled when the context of the subunit has been
2043 -- analyzed. Use clauses may also have been affected by the analysis of
2044 -- the context of the subunit, so they have to be applied again, to
2045 -- insure that the compilation environment of the rest of the parent
2046 -- unit is identical.
2048 procedure Remove_Scope
;
2049 -- Remove current scope from scope stack, and preserve the list of use
2050 -- clauses in it, to be reinstalled after context is analyzed.
2052 -----------------------------
2053 -- Analyze_Subunit_Context --
2054 -----------------------------
2056 procedure Analyze_Subunit_Context
is
2059 Unit_Name
: Entity_Id
;
2062 Analyze_Context
(N
);
2063 Check_No_Elab_Code_All
(N
);
2065 -- Make withed units immediately visible. If child unit, make the
2066 -- ultimate parent immediately visible.
2068 Item
:= First
(Context_Items
(N
));
2069 while Present
(Item
) loop
2070 if Nkind
(Item
) = N_With_Clause
then
2072 -- Protect frontend against previous errors in context clauses
2074 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2075 if Error_Posted
(Item
) then
2079 -- If a subunits has serious syntax errors, the context
2080 -- may not have been loaded. Add a harmless unit name to
2081 -- attempt processing.
2083 if Serious_Errors_Detected
> 0
2084 and then No
(Entity
(Name
(Item
)))
2086 Set_Entity
(Name
(Item
), Standard_Standard
);
2089 Unit_Name
:= Entity
(Name
(Item
));
2091 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2092 exit when Scope
(Unit_Name
) = Standard_Standard
;
2093 Unit_Name
:= Scope
(Unit_Name
);
2095 if No
(Unit_Name
) then
2096 Check_Error_Detected
;
2101 if not Is_Immediately_Visible
(Unit_Name
) then
2102 Set_Is_Immediately_Visible
(Unit_Name
);
2103 Set_Context_Installed
(Item
);
2108 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2109 Nam
:= First
(Names
(Item
));
2110 while Present
(Nam
) loop
2115 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2116 Nam
:= First
(Subtype_Marks
(Item
));
2117 while Present
(Nam
) loop
2126 -- Reset visibility of withed units. They will be made visible again
2127 -- when we install the subunit context.
2129 Item
:= First
(Context_Items
(N
));
2130 while Present
(Item
) loop
2131 if Nkind
(Item
) = N_With_Clause
2133 -- Protect frontend against previous errors in context clauses
2135 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2136 and then not Error_Posted
(Item
)
2138 Unit_Name
:= Entity
(Name
(Item
));
2140 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2141 exit when Scope
(Unit_Name
) = Standard_Standard
;
2142 Unit_Name
:= Scope
(Unit_Name
);
2145 if Context_Installed
(Item
) then
2146 Set_Is_Immediately_Visible
(Unit_Name
, False);
2147 Set_Context_Installed
(Item
, False);
2153 end Analyze_Subunit_Context
;
2155 ------------------------
2156 -- Re_Install_Parents --
2157 ------------------------
2159 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2163 if Nkind
(Unit
(L
)) = N_Subunit
then
2164 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2167 Install_Context
(L
);
2169 -- If the subunit occurs within a child unit, we must restore the
2170 -- immediate visibility of any siblings that may occur in context.
2172 if Present
(Enclosing_Child
) then
2173 Install_Siblings
(Enclosing_Child
, L
);
2178 if Scop
/= Par_Unit
then
2179 Set_Is_Immediately_Visible
(Scop
);
2182 -- Make entities in scope visible again. For child units, restore
2183 -- visibility only if they are actually in context.
2185 E
:= First_Entity
(Current_Scope
);
2186 while Present
(E
) loop
2187 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2188 Set_Is_Immediately_Visible
(E
);
2194 -- A subunit appears within a body, and for a nested subunits all the
2195 -- parents are bodies. Restore full visibility of their private
2198 if Is_Package_Or_Generic_Package
(Scop
) then
2199 Set_In_Package_Body
(Scop
);
2200 Install_Private_Declarations
(Scop
);
2202 end Re_Install_Parents
;
2204 ----------------------------
2205 -- Re_Install_Use_Clauses --
2206 ----------------------------
2208 procedure Re_Install_Use_Clauses
is
2211 for J
in reverse 1 .. Num_Scopes
loop
2212 U
:= Use_Clauses
(J
);
2213 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2214 Install_Use_Clauses
(U
, Force_Installation
=> True);
2216 end Re_Install_Use_Clauses
;
2222 procedure Remove_Scope
is
2226 Num_Scopes
:= Num_Scopes
+ 1;
2227 Use_Clauses
(Num_Scopes
) :=
2228 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2230 E
:= First_Entity
(Current_Scope
);
2231 while Present
(E
) loop
2232 Set_Is_Immediately_Visible
(E
, False);
2236 if Is_Child_Unit
(Current_Scope
) then
2237 Enclosing_Child
:= Current_Scope
;
2243 -- Start of processing for Analyze_Subunit
2246 -- For subunit in main extended unit, we reset the configuration values
2247 -- for the non-partition-wide restrictions. For other units reset them.
2249 if In_Extended_Main_Source_Unit
(N
) then
2250 Restore_Config_Cunit_Boolean_Restrictions
;
2252 Reset_Cunit_Boolean_Restrictions
;
2257 Nam
: Node_Id
:= Name
(Unit
(N
));
2260 if Nkind
(Nam
) = N_Selected_Component
then
2261 Nam
:= Selector_Name
(Nam
);
2264 Check_Identifier
(Nam
, Par_Unit
);
2268 if not Is_Empty_List
(Context_Items
(N
)) then
2270 -- Save current use clauses
2273 Remove_Context
(Lib_Unit
);
2275 -- Now remove parents and their context, including enclosing subunits
2276 -- and the outer parent body which is not a subunit.
2278 if Present
(Lib_Spec
) then
2279 Remove_Context
(Lib_Spec
);
2281 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2282 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2284 Remove_Context
(Lib_Spec
);
2287 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2291 if Nkind
(Unit
(Lib_Spec
)) = N_Package_Body
then
2292 Remove_Context
(Library_Unit
(Lib_Spec
));
2296 Set_Is_Immediately_Visible
(Par_Unit
, False);
2298 Analyze_Subunit_Context
;
2300 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2301 Set_Is_Immediately_Visible
(Par_Unit
);
2303 -- If the context includes a child unit of the parent of the subunit,
2304 -- the parent will have been removed from visibility, after compiling
2305 -- that cousin in the context. The visibility of the parent must be
2306 -- restored now. This also applies if the context includes another
2307 -- subunit of the same parent which in turn includes a child unit in
2310 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2311 if not Is_Immediately_Visible
(Par_Unit
)
2312 or else (Present
(First_Entity
(Par_Unit
))
2314 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2316 Set_Is_Immediately_Visible
(Par_Unit
);
2317 Install_Visible_Declarations
(Par_Unit
);
2318 Install_Private_Declarations
(Par_Unit
);
2322 Re_Install_Use_Clauses
;
2323 Install_Context
(N
);
2325 -- Restore state of suppress flags for current body
2327 Scope_Suppress
:= Svg
;
2329 -- If the subunit is within a child unit, then siblings of any parent
2330 -- unit that appear in the context clause of the subunit must also be
2331 -- made immediately visible.
2333 if Present
(Enclosing_Child
) then
2334 Install_Siblings
(Enclosing_Child
, N
);
2338 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2339 Analyze
(Proper_Body
(Unit
(N
)));
2342 -- The subunit may contain a with_clause on a sibling of some ancestor.
2343 -- Removing the context will remove from visibility those ancestor child
2344 -- units, which must be restored to the visibility they have in the
2347 if Present
(Enclosing_Child
) then
2352 while Present
(C
) and then C
/= Standard_Standard
loop
2353 Set_Is_Immediately_Visible
(C
);
2354 Set_Is_Visible_Lib_Unit
(C
);
2360 -- Deal with restore of restrictions
2362 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2363 end Analyze_Subunit
;
2365 ----------------------------
2366 -- Analyze_Task_Body_Stub --
2367 ----------------------------
2369 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2370 Loc
: constant Source_Ptr
:= Sloc
(N
);
2371 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
2374 Check_Stub_Level
(N
);
2376 -- First occurrence of name may have been as an incomplete type
2378 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2379 Nam
:= Full_View
(Nam
);
2382 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2383 Error_Msg_N
("missing specification for task body", N
);
2386 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
2387 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
2388 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2390 -- Check for duplicate stub, if so give message and terminate
2392 if Has_Completion
(Etype
(Nam
)) then
2393 Error_Msg_N
("duplicate stub for task", N
);
2396 Set_Has_Completion
(Etype
(Nam
));
2399 Analyze_Proper_Body
(N
, Etype
(Nam
));
2401 -- Set elaboration flag to indicate that entity is callable. This
2402 -- cannot be done in the expansion of the body itself, because the
2403 -- proper body is not in a declarative part. This is only done if
2404 -- expansion is active, because the context may be generic and the
2405 -- flag not defined yet.
2407 if Expander_Active
then
2409 Make_Assignment_Statement
(Loc
,
2411 Make_Identifier
(Loc
,
2412 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2413 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2416 end Analyze_Task_Body_Stub
;
2418 -------------------------
2419 -- Analyze_With_Clause --
2420 -------------------------
2422 -- Analyze the declaration of a unit in a with clause. At end, label the
2423 -- with clause with the defining entity for the unit.
2425 procedure Analyze_With_Clause
(N
: Node_Id
) is
2427 -- Retrieve the original kind of the unit node, before analysis. If it
2428 -- is a subprogram instantiation, its analysis below will rewrite the
2429 -- node as the declaration of the wrapper package. If the same
2430 -- instantiation appears indirectly elsewhere in the context, it will
2431 -- have been analyzed already.
2433 Unit_Kind
: constant Node_Kind
:=
2434 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2435 Nam
: constant Node_Id
:= Name
(N
);
2437 Par_Name
: Entity_Id
;
2442 -- Set True if the unit currently being compiled is an internal unit
2444 Restriction_Violation
: Boolean := False;
2445 -- Set True if a with violates a restriction, no point in giving any
2446 -- warnings if we have this definite error.
2448 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2451 U
:= Unit
(Library_Unit
(N
));
2453 -- If this is an internal unit which is a renaming, then this is a
2454 -- violation of No_Obsolescent_Features.
2456 -- Note: this is not quite right if the user defines one of these units
2457 -- himself, but that's a marginal case, and fixing it is hard ???
2459 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2461 F
: constant File_Name_Type
:=
2462 Unit_File_Name
(Get_Source_Unit
(U
));
2464 if Is_Predefined_File_Name
(F
, Renamings_Included
=> True)
2466 Is_Predefined_File_Name
(F
, Renamings_Included
=> False)
2468 Check_Restriction
(No_Obsolescent_Features
, N
);
2469 Restriction_Violation
:= True;
2474 -- Check No_Implementation_Units violation
2476 if Restriction_Check_Required
(No_Implementation_Units
) then
2477 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2480 Check_Restriction
(No_Implementation_Units
, Nam
);
2481 Restriction_Violation
:= True;
2485 -- Several actions are skipped for dummy packages (those supplied for
2486 -- with's where no matching file could be found). Such packages are
2487 -- identified by the Sloc value being set to No_Location.
2489 if Limited_Present
(N
) then
2491 -- Ada 2005 (AI-50217): Build visibility structures but do not
2492 -- analyze the unit.
2494 -- If the designated unit is a predefined unit, which might be used
2495 -- implicitly through the rtsfind machinery, a limited with clause
2496 -- on such a unit is usually pointless, because run-time units are
2497 -- unlikely to appear in mutually dependent units, and because this
2498 -- disables the rtsfind mechanism. We transform such limited with
2499 -- clauses into regular with clauses.
2501 if Sloc
(U
) /= No_Location
then
2502 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2504 -- In ASIS mode the rtsfind mechanism plays no role, and
2505 -- we need to maintain the original tree structure, so
2506 -- this transformation is not performed in this case.
2508 and then not ASIS_Mode
2510 Set_Limited_Present
(N
, False);
2511 Analyze_With_Clause
(N
);
2513 Build_Limited_Views
(N
);
2520 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2521 -- already detected serious errors then we mark the with-clause nodes as
2522 -- analyzed before the corresponding compilation unit is analyzed. This
2523 -- is done here to protect the frontend against never ending recursion
2524 -- caused by circularities in the sources (because the previous errors
2525 -- may break the regular machine of the compiler implemented in
2526 -- Load_Unit to detect circularities).
2528 if Serious_Errors_Detected
> 0 and then Try_Semantics
then
2532 -- If the library unit is a predefined unit, and we are in high
2533 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
2534 -- for the analysis of the with'ed unit. This mode does not prevent
2535 -- explicit with'ing of run-time units.
2537 if Configurable_Run_Time_Mode
2538 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2540 Configurable_Run_Time_Mode
:= False;
2541 Semantics
(Library_Unit
(N
));
2542 Configurable_Run_Time_Mode
:= True;
2545 Semantics
(Library_Unit
(N
));
2548 Intunit
:= Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
));
2550 if Sloc
(U
) /= No_Location
then
2552 -- Check restrictions, except that we skip the check if this is an
2553 -- internal unit unless we are compiling the internal unit as the
2554 -- main unit. We also skip this for dummy packages.
2556 Check_Restriction_No_Dependence
(Nam
, N
);
2558 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2559 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2562 -- Deal with special case of GNAT.Current_Exceptions which interacts
2563 -- with the optimization of local raise statements into gotos.
2565 if Nkind
(Nam
) = N_Selected_Component
2566 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2567 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2568 and then Nam_In
(Chars
(Selector_Name
(Nam
)),
2569 Name_Most_Recent_Exception
,
2570 Name_Exception_Traces
)
2572 Check_Restriction
(No_Exception_Propagation
, N
);
2573 Special_Exception_Package_Used
:= True;
2576 -- Check for inappropriate with of internal implementation unit if we
2577 -- are not compiling an internal unit and also check for withing unit
2578 -- in wrong version of Ada. Do not issue these messages for implicit
2579 -- with's generated by the compiler itself.
2581 if Implementation_Unit_Warnings
2582 and then not Intunit
2583 and then not Implicit_With
(N
)
2584 and then not Restriction_Violation
2587 U_Kind
: constant Kind_Of_Unit
:=
2588 Get_Kind_Of_Unit
(Get_Source_Unit
(U
));
2591 if U_Kind
= Implementation_Unit
then
2592 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2594 -- Add alternative name if available, otherwise issue a
2595 -- general warning message.
2597 if Error_Msg_Strlen
/= 0 then
2598 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2601 ("\use of this unit is non-portable " &
2602 "and version-dependent?i?", Name
(N
));
2605 elsif U_Kind
= Ada_2005_Unit
2606 and then Ada_Version
< Ada_2005
2607 and then Warn_On_Ada_2005_Compatibility
2609 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2611 elsif U_Kind
= Ada_2012_Unit
2612 and then Ada_Version
< Ada_2012
2613 and then Warn_On_Ada_2012_Compatibility
2615 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2621 -- Semantic analysis of a generic unit is performed on a copy of
2622 -- the original tree. Retrieve the entity on which semantic info
2623 -- actually appears.
2625 if Unit_Kind
in N_Generic_Declaration
then
2626 E_Name
:= Defining_Entity
(U
);
2628 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2629 -- the case of an instantiation, semantic analysis above will have
2630 -- replaced the unit by its instantiated version. If the instance body
2631 -- has been generated, the instance now denotes the body entity. For
2632 -- visibility purposes we need the entity of its spec.
2634 elsif (Unit_Kind
= N_Package_Instantiation
2635 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2636 N_Package_Instantiation
)
2637 and then Nkind
(U
) = N_Package_Body
2639 E_Name
:= Corresponding_Spec
(U
);
2641 elsif Unit_Kind
= N_Package_Instantiation
2642 and then Nkind
(U
) = N_Package_Instantiation
2643 and then Present
(Instance_Spec
(U
))
2645 -- If the instance has not been rewritten as a package declaration,
2646 -- then it appeared already in a previous with clause. Retrieve
2647 -- the entity from the previous instance.
2649 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2651 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2653 -- The visible subprogram is created during instantiation, and is
2654 -- an attribute of the wrapper package. We retrieve the wrapper
2655 -- package directly from the instantiation node. If the instance
2656 -- is inlined the unit is still an instantiation. Otherwise it has
2657 -- been rewritten as the declaration of the wrapper itself.
2659 if Nkind
(U
) in N_Subprogram_Instantiation
then
2662 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2664 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2667 elsif Unit_Kind
= N_Package_Renaming_Declaration
2668 or else Unit_Kind
in N_Generic_Renaming_Declaration
2670 E_Name
:= Defining_Entity
(U
);
2672 elsif Unit_Kind
= N_Subprogram_Body
2673 and then Nkind
(Name
(N
)) = N_Selected_Component
2674 and then not Acts_As_Spec
(Library_Unit
(N
))
2676 -- For a child unit that has no spec, one has been created and
2677 -- analyzed. The entity required is that of the spec.
2679 E_Name
:= Corresponding_Spec
(U
);
2682 E_Name
:= Defining_Entity
(U
);
2685 if Nkind
(Name
(N
)) = N_Selected_Component
then
2687 -- Child unit in a with clause
2689 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2691 -- If this is a child unit without a spec, and it has been analyzed
2692 -- already, a declaration has been created for it. The with_clause
2693 -- must reflect the actual body, and not the generated declaration,
2694 -- to prevent spurious binding errors involving an out-of-date spec.
2695 -- Note that this can only happen if the unit includes more than one
2696 -- with_clause for the child unit (e.g. in separate subunits).
2698 if Unit_Kind
= N_Subprogram_Declaration
2699 and then Analyzed
(Library_Unit
(N
))
2700 and then not Comes_From_Source
(Library_Unit
(N
))
2702 Set_Library_Unit
(N
,
2703 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2707 -- Restore style checks
2709 Style_Check
:= Save_Style_Check
;
2711 -- Record the reference, but do NOT set the unit as referenced, we want
2712 -- to consider the unit as unreferenced if this is the only reference
2715 Set_Entity_With_Checks
(Name
(N
), E_Name
);
2716 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
2718 -- Generate references and check No_Dependence restriction for parents
2720 if Is_Child_Unit
(E_Name
) then
2721 Pref
:= Prefix
(Name
(N
));
2722 Par_Name
:= Scope
(E_Name
);
2723 while Nkind
(Pref
) = N_Selected_Component
loop
2724 Change_Selected_Component_To_Expanded_Name
(Pref
);
2726 if Present
(Entity
(Selector_Name
(Pref
)))
2728 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
2729 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
2731 -- The prefix is a child unit that denotes a renaming declaration.
2732 -- Replace the prefix directly with the renamed unit, because the
2733 -- rest of the prefix is irrelevant to the visibility of the real
2736 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
2740 Set_Entity_With_Checks
(Pref
, Par_Name
);
2742 Generate_Reference
(Par_Name
, Pref
);
2743 Check_Restriction_No_Dependence
(Pref
, N
);
2744 Pref
:= Prefix
(Pref
);
2746 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2747 -- is set to Standard_Standard, and no attempt should be made to
2748 -- further unwind scopes.
2750 if Par_Name
/= Standard_Standard
then
2751 Par_Name
:= Scope
(Par_Name
);
2754 -- Abandon processing in case of previous errors
2756 if No
(Par_Name
) then
2757 Check_Error_Detected
;
2762 if Present
(Entity
(Pref
))
2763 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
2765 -- If the entity is set without its unit being compiled, the
2766 -- original parent is a renaming, and Par_Name is the renamed
2767 -- entity. For visibility purposes, we need the original entity,
2768 -- which must be analyzed now because Load_Unit directly retrieves
2769 -- the renamed unit, and the renaming declaration itself has not
2772 Analyze
(Parent
(Parent
(Entity
(Pref
))));
2773 pragma Assert
(Renamed_Object
(Entity
(Pref
)) = Par_Name
);
2774 Par_Name
:= Entity
(Pref
);
2777 -- Guard against missing or misspelled child units
2779 if Present
(Par_Name
) then
2780 Set_Entity_With_Checks
(Pref
, Par_Name
);
2781 Generate_Reference
(Par_Name
, Pref
);
2784 pragma Assert
(Serious_Errors_Detected
/= 0);
2786 -- Mark the node to indicate that a related error has been posted.
2787 -- This defends further compilation passes against improper use of
2788 -- the invalid WITH clause node.
2790 Set_Error_Posted
(N
);
2791 Set_Name
(N
, Error
);
2796 -- If the withed unit is System, and a system extension pragma is
2797 -- present, compile the extension now, rather than waiting for a
2798 -- visibility check on a specific entity.
2800 if Chars
(E_Name
) = Name_System
2801 and then Scope
(E_Name
) = Standard_Standard
2802 and then Present
(System_Extend_Unit
)
2803 and then Present_System_Aux
(N
)
2805 -- If the extension is not present, an error will have been emitted
2810 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2811 -- to private_with units; they will be made visible later (just before
2812 -- the private part is analyzed)
2814 if Private_Present
(N
) then
2815 Set_Is_Immediately_Visible
(E_Name
, False);
2818 -- Propagate Fatal_Error setting from with'ed unit to current unit
2820 case Fatal_Error
(Get_Source_Unit
(Library_Unit
(N
))) is
2822 -- Nothing to do if with'ed unit had no error
2827 -- If with'ed unit had a detected fatal error, propagate it
2829 when Error_Detected
=>
2830 Set_Fatal_Error
(Current_Sem_Unit
, Error_Detected
);
2832 -- If with'ed unit had an ignored error, then propagate it but do not
2833 -- overide an existring setting.
2835 when Error_Ignored
=>
2836 if Fatal_Error
(Current_Sem_Unit
) = None
then
2837 Set_Fatal_Error
(Current_Sem_Unit
, Error_Ignored
);
2840 end Analyze_With_Clause
;
2842 ------------------------------
2843 -- Check_Private_Child_Unit --
2844 ------------------------------
2846 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
2847 Lib_Unit
: constant Node_Id
:= Unit
(N
);
2849 Curr_Unit
: Entity_Id
;
2850 Sub_Parent
: Node_Id
;
2851 Priv_Child
: Entity_Id
;
2852 Par_Lib
: Entity_Id
;
2855 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean;
2856 -- Returns true if and only if the library unit is declared with
2857 -- an explicit designation of private.
2859 -----------------------------
2860 -- Is_Private_Library_Unit --
2861 -----------------------------
2863 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
2864 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
2867 return Private_Present
(Comp_Unit
);
2868 end Is_Private_Library_Unit
;
2870 -- Start of processing for Check_Private_Child_Unit
2873 if Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subprogram_Body
) then
2874 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
2875 Par_Lib
:= Curr_Unit
;
2877 elsif Nkind
(Lib_Unit
) = N_Subunit
then
2879 -- The parent is itself a body. The parent entity is to be found in
2880 -- the corresponding spec.
2882 Sub_Parent
:= Library_Unit
(N
);
2883 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
2885 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2886 -- enclosing body, retrieve the spec entity which is the proper
2887 -- ancestor we need for the following tests.
2889 if Ekind
(Curr_Unit
) = E_Package_Body
then
2890 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
2893 Par_Lib
:= Curr_Unit
;
2896 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
2898 Par_Lib
:= Curr_Unit
;
2899 Par_Spec
:= Parent_Spec
(Lib_Unit
);
2901 if No
(Par_Spec
) then
2904 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
2908 -- Loop through context items
2910 Item
:= First
(Context_Items
(N
));
2911 while Present
(Item
) loop
2913 -- Ada 2005 (AI-262): Allow private_with of a private child package
2914 -- in public siblings
2916 if Nkind
(Item
) = N_With_Clause
2917 and then not Implicit_With
(Item
)
2918 and then not Limited_Present
(Item
)
2919 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
2921 Priv_Child
:= Entity
(Name
(Item
));
2924 Curr_Parent
: Entity_Id
:= Par_Lib
;
2925 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
2926 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
2927 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
2930 -- If the child unit is a public child then locate the nearest
2931 -- private ancestor. Child_Parent will then be set to the
2932 -- parent of that ancestor.
2934 if not Is_Private_Library_Unit
(Priv_Child
) then
2935 while Present
(Prv_Ancestor
)
2936 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
2938 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
2941 if Present
(Prv_Ancestor
) then
2942 Child_Parent
:= Scope
(Prv_Ancestor
);
2946 while Present
(Curr_Parent
)
2947 and then Curr_Parent
/= Standard_Standard
2948 and then Curr_Parent
/= Child_Parent
2951 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
2952 Curr_Parent
:= Scope
(Curr_Parent
);
2955 if No
(Curr_Parent
) then
2956 Curr_Parent
:= Standard_Standard
;
2959 if Curr_Parent
/= Child_Parent
then
2960 if Ekind
(Priv_Child
) = E_Generic_Package
2961 and then Chars
(Priv_Child
) in Text_IO_Package_Name
2962 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
2965 ("& is a nested package, not a compilation unit",
2966 Name
(Item
), Priv_Child
);
2970 ("unit in with clause is private child unit!", Item
);
2972 ("\current unit must also have parent&!",
2973 Item
, Child_Parent
);
2977 or else Private_Present
(Item
)
2978 or else Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subunit
)
2979 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
2980 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
2986 ("current unit must also be private descendant of&",
2987 Item
, Child_Parent
);
2995 end Check_Private_Child_Unit
;
2997 ----------------------
2998 -- Check_Stub_Level --
2999 ----------------------
3001 procedure Check_Stub_Level
(N
: Node_Id
) is
3002 Par
: constant Node_Id
:= Parent
(N
);
3003 Kind
: constant Node_Kind
:= Nkind
(Par
);
3006 if Nkind_In
(Kind
, N_Package_Body
,
3010 and then Nkind_In
(Parent
(Par
), N_Compilation_Unit
, N_Subunit
)
3014 -- In an instance, a missing stub appears at any level. A warning
3015 -- message will have been emitted already for the missing file.
3017 elsif not In_Instance
then
3018 Error_Msg_N
("stub cannot appear in an inner scope", N
);
3020 elsif Expander_Active
then
3021 Error_Msg_N
("missing proper body", N
);
3023 end Check_Stub_Level
;
3025 ------------------------
3026 -- Expand_With_Clause --
3027 ------------------------
3029 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
3030 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3031 Ent
: constant Entity_Id
:= Entity
(Nam
);
3035 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3036 -- Build name to be used in implicit with_clause. In most cases this
3037 -- is the source name, but if renamings are present we must make the
3038 -- original unit visible, not the one it renames. The entity in the
3039 -- with clause is the renamed unit, but the identifier is the one from
3040 -- the source, which allows us to recover the unit renaming.
3042 ---------------------
3043 -- Build_Unit_Name --
3044 ---------------------
3046 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3051 if Nkind
(Nam
) = N_Identifier
then
3052 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3055 Ent
:= Entity
(Nam
);
3057 if Present
(Entity
(Selector_Name
(Nam
)))
3058 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3060 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
))))
3061 = N_Package_Renaming_Declaration
3063 -- The name in the with_clause is of the form A.B.C, and B is
3064 -- given by a renaming declaration. In that case we may not
3065 -- have analyzed the unit for B, but replaced it directly in
3066 -- lib-load with the unit it renames. We have to make A.B
3067 -- visible, so analyze the declaration for B now, in case it
3068 -- has not been done yet.
3070 Ent
:= Entity
(Selector_Name
(Nam
));
3073 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3077 Make_Expanded_Name
(Loc
,
3078 Chars
=> Chars
(Entity
(Nam
)),
3079 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3080 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3081 Set_Entity
(Result
, Ent
);
3084 end Build_Unit_Name
;
3086 -- Start of processing for Expand_With_Clause
3090 Make_With_Clause
(Loc
,
3091 Name
=> Build_Unit_Name
(Nam
));
3093 P
:= Parent
(Unit_Declaration_Node
(Ent
));
3094 Set_Library_Unit
(Withn
, P
);
3095 Set_Corresponding_Spec
(Withn
, Ent
);
3096 Set_First_Name
(Withn
, True);
3097 Set_Implicit_With
(Withn
, True);
3099 -- If the unit is a package or generic package declaration, a private_
3100 -- with_clause on a child unit implies that the implicit with on the
3101 -- parent is also private.
3103 if Nkind_In
(Unit
(N
), N_Package_Declaration
,
3104 N_Generic_Package_Declaration
)
3106 Set_Private_Present
(Withn
, Private_Present
(Item
));
3109 Prepend
(Withn
, Context_Items
(N
));
3110 Mark_Rewrite_Insertion
(Withn
);
3111 Install_Withed_Unit
(Withn
);
3113 -- If we have "with X.Y;", we want to recurse on "X", except in the
3114 -- unusual case where X.Y is a renaming of X. In that case, the scope
3115 -- of X will be null.
3117 if Nkind
(Nam
) = N_Expanded_Name
3118 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3120 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3122 end Expand_With_Clause
;
3124 --------------------------------
3125 -- Generate_Parent_References --
3126 --------------------------------
3128 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3130 P_Name
: Entity_Id
:= P_Id
;
3133 if Nkind
(N
) = N_Subunit
then
3136 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3139 if Nkind
(Pref
) = N_Expanded_Name
then
3141 -- Done already, if the unit has been compiled indirectly as
3142 -- part of the closure of its context because of inlining.
3147 while Nkind
(Pref
) = N_Selected_Component
loop
3148 Change_Selected_Component_To_Expanded_Name
(Pref
);
3149 Set_Entity
(Pref
, P_Name
);
3150 Set_Etype
(Pref
, Etype
(P_Name
));
3151 Generate_Reference
(P_Name
, Pref
, 'r');
3152 Pref
:= Prefix
(Pref
);
3153 P_Name
:= Scope
(P_Name
);
3156 -- The guard here on P_Name is to handle the error condition where
3157 -- the parent unit is missing because the file was not found.
3159 if Present
(P_Name
) then
3160 Set_Entity
(Pref
, P_Name
);
3161 Set_Etype
(Pref
, Etype
(P_Name
));
3162 Generate_Reference
(P_Name
, Pref
, 'r');
3163 Style
.Check_Identifier
(Pref
, P_Name
);
3165 end Generate_Parent_References
;
3167 ---------------------
3168 -- Has_With_Clause --
3169 ---------------------
3171 function Has_With_Clause
3174 Is_Limited
: Boolean := False) return Boolean
3178 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3179 -- Return the entity for the unit named in a [limited] with clause
3185 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3187 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3188 return Entity
(Selector_Name
(Name
(Clause
)));
3190 return Entity
(Name
(Clause
));
3194 -- Start of processing for Has_With_Clause
3197 if Present
(Context_Items
(C_Unit
)) then
3198 Item
:= First
(Context_Items
(C_Unit
));
3199 while Present
(Item
) loop
3200 if Nkind
(Item
) = N_With_Clause
3201 and then Limited_Present
(Item
) = Is_Limited
3202 and then Named_Unit
(Item
) = Pack
3212 end Has_With_Clause
;
3214 -----------------------------
3215 -- Implicit_With_On_Parent --
3216 -----------------------------
3218 procedure Implicit_With_On_Parent
3219 (Child_Unit
: Node_Id
;
3222 Loc
: constant Source_Ptr
:= Sloc
(N
);
3223 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3224 P_Unit
: Node_Id
:= Unit
(P
);
3225 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3228 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3229 -- Build prefix of child unit name. Recurse if needed
3231 function Build_Unit_Name
return Node_Id
;
3232 -- If the unit is a child unit, build qualified name with all ancestors
3234 -------------------------
3235 -- Build_Ancestor_Name --
3236 -------------------------
3238 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3239 P_Ref
: constant Node_Id
:=
3240 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3241 P_Spec
: Node_Id
:= P
;
3244 -- Ancestor may have been rewritten as a package body. Retrieve
3245 -- the original spec to trace earlier ancestors.
3247 if Nkind
(P
) = N_Package_Body
3248 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3250 P_Spec
:= Original_Node
(P
);
3253 if No
(Parent_Spec
(P_Spec
)) then
3257 Make_Selected_Component
(Loc
,
3258 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3259 Selector_Name
=> P_Ref
);
3261 end Build_Ancestor_Name
;
3263 ---------------------
3264 -- Build_Unit_Name --
3265 ---------------------
3267 function Build_Unit_Name
return Node_Id
is
3271 if No
(Parent_Spec
(P_Unit
)) then
3272 return New_Occurrence_Of
(P_Name
, Loc
);
3276 Make_Expanded_Name
(Loc
,
3277 Chars
=> Chars
(P_Name
),
3278 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3279 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3280 Set_Entity
(Result
, P_Name
);
3283 end Build_Unit_Name
;
3285 -- Start of processing for Implicit_With_On_Parent
3288 -- The unit of the current compilation may be a package body that
3289 -- replaces an instance node. In this case we need the original instance
3290 -- node to construct the proper parent name.
3292 if Nkind
(P_Unit
) = N_Package_Body
3293 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3295 P_Unit
:= Original_Node
(P_Unit
);
3298 -- We add the implicit with if the child unit is the current unit being
3299 -- compiled. If the current unit is a body, we do not want to add an
3300 -- implicit_with a second time to the corresponding spec.
3302 if Nkind
(Child_Unit
) = N_Package_Declaration
3303 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3308 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3310 Set_Library_Unit
(Withn
, P
);
3311 Set_Corresponding_Spec
(Withn
, P_Name
);
3312 Set_First_Name
(Withn
, True);
3313 Set_Implicit_With
(Withn
, True);
3315 -- Node is placed at the beginning of the context items, so that
3316 -- subsequent use clauses on the parent can be validated.
3318 Prepend
(Withn
, Context_Items
(N
));
3319 Mark_Rewrite_Insertion
(Withn
);
3320 Install_Withed_Unit
(Withn
);
3322 if Is_Child_Spec
(P_Unit
) then
3323 Implicit_With_On_Parent
(P_Unit
, N
);
3325 end Implicit_With_On_Parent
;
3331 function In_Chain
(E
: Entity_Id
) return Boolean is
3335 H
:= Current_Entity
(E
);
3336 while Present
(H
) loop
3347 ---------------------
3348 -- Install_Context --
3349 ---------------------
3351 procedure Install_Context
(N
: Node_Id
) is
3352 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3355 Install_Context_Clauses
(N
);
3357 if Is_Child_Spec
(Lib_Unit
) then
3358 Install_Parents
(Lib_Unit
, Private_Present
(Parent
(Lib_Unit
)));
3361 Install_Limited_Context_Clauses
(N
);
3362 end Install_Context
;
3364 -----------------------------
3365 -- Install_Context_Clauses --
3366 -----------------------------
3368 procedure Install_Context_Clauses
(N
: Node_Id
) is
3369 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3371 Uname_Node
: Entity_Id
;
3372 Check_Private
: Boolean := False;
3373 Decl_Node
: Node_Id
;
3374 Lib_Parent
: Entity_Id
;
3377 -- First skip configuration pragmas at the start of the context. They
3378 -- are not technically part of the context clause, but that's where the
3379 -- parser puts them. Note they were analyzed in Analyze_Context.
3381 Item
:= First
(Context_Items
(N
));
3382 while Present
(Item
)
3383 and then Nkind
(Item
) = N_Pragma
3384 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
3389 -- Loop through the actual context clause items. We process everything
3390 -- except Limited_With clauses in this routine. Limited_With clauses
3391 -- are separately installed (see Install_Limited_Context_Clauses).
3393 while Present
(Item
) loop
3395 -- Case of explicit WITH clause
3397 if Nkind
(Item
) = N_With_Clause
3398 and then not Implicit_With
(Item
)
3400 if Limited_Present
(Item
) then
3402 -- Limited withed units will be installed later
3406 -- If Name (Item) is not an entity name, something is wrong, and
3407 -- this will be detected in due course, for now ignore the item
3409 elsif not Is_Entity_Name
(Name
(Item
)) then
3412 elsif No
(Entity
(Name
(Item
))) then
3413 Set_Entity
(Name
(Item
), Any_Id
);
3417 Uname_Node
:= Entity
(Name
(Item
));
3419 if Is_Private_Descendant
(Uname_Node
) then
3420 Check_Private
:= True;
3423 Install_Withed_Unit
(Item
);
3425 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3427 -- If the unit is a subprogram instance, it appears nested within
3428 -- a package that carries the parent information.
3430 if Is_Generic_Instance
(Uname_Node
)
3431 and then Ekind
(Uname_Node
) /= E_Package
3433 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3436 if Is_Child_Spec
(Decl_Node
) then
3437 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3438 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3440 -- If not an expanded name, the child unit must be a
3441 -- renaming, nothing to do.
3446 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3447 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3448 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3450 Implicit_With_On_Parent
3451 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3454 -- Check license conditions unless this is a dummy unit
3456 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3457 License_Check
: declare
3458 Withu
: constant Unit_Number_Type
:=
3459 Get_Source_Unit
(Library_Unit
(Item
));
3460 Withl
: constant License_Type
:=
3461 License
(Source_Index
(Withu
));
3462 Unitl
: constant License_Type
:=
3463 License
(Source_Index
(Current_Sem_Unit
));
3465 procedure License_Error
;
3466 -- Signal error of bad license
3472 procedure License_Error
is
3475 ("license of withed unit & may be inconsistent??",
3479 -- Start of processing for License_Check
3482 -- Exclude license check if withed unit is an internal unit.
3483 -- This situation arises e.g. with the GPL version of GNAT.
3485 if Is_Internal_File_Name
(Unit_File_Name
(Withu
)) then
3488 -- Otherwise check various cases
3500 if Withl
= Restricted
then
3504 when Modified_GPL
=>
3505 if Withl
= Restricted
or else Withl
= GPL
then
3509 when Unrestricted
=>
3516 -- Case of USE PACKAGE clause
3518 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3519 Analyze_Use_Package
(Item
);
3521 -- Case of USE TYPE clause
3523 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3524 Analyze_Use_Type
(Item
);
3528 elsif Nkind
(Item
) = N_Pragma
then
3536 if Is_Child_Spec
(Lib_Unit
) then
3538 -- The unit also has implicit with_clauses on its own parents
3540 if No
(Context_Items
(N
)) then
3541 Set_Context_Items
(N
, New_List
);
3544 Implicit_With_On_Parent
(Lib_Unit
, N
);
3547 -- If the unit is a body, the context of the specification must also
3548 -- be installed. That includes private with_clauses in that context.
3550 if Nkind
(Lib_Unit
) = N_Package_Body
3551 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3552 and then not Acts_As_Spec
(N
))
3554 Install_Context
(Library_Unit
(N
));
3556 -- Only install private with-clauses of a spec that comes from
3557 -- source, excluding specs created for a subprogram body that is
3560 if Comes_From_Source
(Library_Unit
(N
)) then
3561 Install_Private_With_Clauses
3562 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3565 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3567 -- If the unit is the body of a public child unit, the private
3568 -- declarations of the parent must be made visible. If the child
3569 -- unit is private, the private declarations have been installed
3570 -- already in the call to Install_Parents for the spec. Installing
3571 -- private declarations must be done for all ancestors of public
3572 -- child units. In addition, sibling units mentioned in the
3573 -- context clause of the body are directly visible.
3581 Lib_Spec
:= Unit
(Library_Unit
(N
));
3582 while Is_Child_Spec
(Lib_Spec
) loop
3583 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3584 P_Name
:= Defining_Entity
(P
);
3586 if not (Private_Present
(Parent
(Lib_Spec
)))
3587 and then not In_Private_Part
(P_Name
)
3589 Install_Private_Declarations
(P_Name
);
3590 Install_Private_With_Clauses
(P_Name
);
3591 Set_Use
(Private_Declarations
(Specification
(P
)));
3599 -- For a package body, children in context are immediately visible
3601 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3604 if Nkind_In
(Lib_Unit
, N_Generic_Package_Declaration
,
3605 N_Generic_Subprogram_Declaration
,
3606 N_Package_Declaration
,
3607 N_Subprogram_Declaration
)
3609 if Is_Child_Spec
(Lib_Unit
) then
3610 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3611 Set_Is_Private_Descendant
3612 (Defining_Entity
(Lib_Unit
),
3613 Is_Private_Descendant
(Lib_Parent
)
3614 or else Private_Present
(Parent
(Lib_Unit
)));
3617 Set_Is_Private_Descendant
3618 (Defining_Entity
(Lib_Unit
),
3619 Private_Present
(Parent
(Lib_Unit
)));
3623 if Check_Private
then
3624 Check_Private_Child_Unit
(N
);
3626 end Install_Context_Clauses
;
3628 -------------------------------------
3629 -- Install_Limited_Context_Clauses --
3630 -------------------------------------
3632 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3635 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3636 -- Check that the unlimited view of a given compilation_unit is not
3637 -- already visible through "use + renamings".
3639 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3640 -- Check that if a limited_with clause of a given compilation_unit
3641 -- mentions a descendant of a private child of some library unit, then
3642 -- the given compilation_unit must be the declaration of a private
3643 -- descendant of that library unit, or a public descendant of such. The
3644 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3645 -- use entities on the limited with_clauses because their units have not
3646 -- been analyzed, so we have to climb the tree of ancestors looking for
3647 -- private keywords.
3649 procedure Expand_Limited_With_Clause
3650 (Comp_Unit
: Node_Id
;
3653 -- If a child unit appears in a limited_with clause, there are implicit
3654 -- limited_with clauses on all parents that are not already visible
3655 -- through a regular with clause. This procedure creates the implicit
3656 -- limited with_clauses for the parents and loads the corresponding
3657 -- units. The shadow entities are created when the inserted clause is
3658 -- analyzed. Implements Ada 2005 (AI-50217).
3660 ---------------------
3661 -- Check_Renamings --
3662 ---------------------
3664 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
3673 pragma Assert
(Nkind
(W
) = N_With_Clause
);
3675 -- Protect the frontend against previous critical errors
3677 case Nkind
(Unit
(Library_Unit
(W
))) is
3678 when N_Subprogram_Declaration |
3679 N_Package_Declaration |
3680 N_Generic_Subprogram_Declaration |
3681 N_Generic_Package_Declaration
=>
3688 -- Check "use + renamings"
3690 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
3691 Spec
:= Specification
(Unit
(P
));
3693 Item
:= First
(Visible_Declarations
(Spec
));
3694 while Present
(Item
) loop
3696 -- Look only at use package clauses
3698 if Nkind
(Item
) = N_Use_Package_Clause
then
3700 -- Traverse the list of packages
3702 Nam
:= First
(Names
(Item
));
3703 while Present
(Nam
) loop
3706 pragma Assert
(Present
(Parent
(E
)));
3708 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
3709 and then Renamed_Entity
(E
) = WEnt
3711 -- The unlimited view is visible through use clause and
3712 -- renamings. There is no need to generate the error
3713 -- message here because Is_Visible_Through_Renamings
3714 -- takes care of generating the precise error message.
3718 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
3720 -- The use clause may refer to a local package.
3721 -- Check all the enclosing scopes.
3724 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
3730 ("unlimited view visible through use clause ", W
);
3742 -- Recursive call to check all the ancestors
3744 if Is_Child_Spec
(Unit
(P
)) then
3745 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
3747 end Check_Renamings
;
3749 ---------------------------------------
3750 -- Check_Private_Limited_Withed_Unit --
3751 ---------------------------------------
3753 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
3754 Curr_Parent
: Node_Id
;
3755 Child_Parent
: Node_Id
;
3756 Curr_Private
: Boolean;
3759 -- Compilation unit of the parent of the withed library unit
3761 Child_Parent
:= Library_Unit
(Item
);
3763 -- If the child unit is a public child, then locate its nearest
3764 -- private ancestor, if any, then Child_Parent will then be set to
3765 -- the parent of that ancestor.
3767 if not Private_Present
(Library_Unit
(Item
)) then
3768 while Present
(Child_Parent
)
3769 and then not Private_Present
(Child_Parent
)
3771 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3774 if No
(Child_Parent
) then
3779 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3781 -- Traverse all the ancestors of the current compilation unit to
3782 -- check if it is a descendant of named library unit.
3784 Curr_Parent
:= Parent
(Item
);
3785 Curr_Private
:= Private_Present
(Curr_Parent
);
3787 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
3788 and then Curr_Parent
/= Child_Parent
3790 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
3791 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
3794 if Curr_Parent
/= Child_Parent
then
3796 ("unit in with clause is private child unit!", Item
);
3798 ("\current unit must also have parent&!",
3799 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3801 elsif Private_Present
(Parent
(Item
))
3802 or else Curr_Private
3803 or else Private_Present
(Item
)
3804 or else Nkind_In
(Unit
(Parent
(Item
)), N_Package_Body
,
3808 -- Current unit is private, of descendant of a private unit
3814 ("current unit must also be private descendant of&",
3815 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3817 end Check_Private_Limited_Withed_Unit
;
3819 --------------------------------
3820 -- Expand_Limited_With_Clause --
3821 --------------------------------
3823 procedure Expand_Limited_With_Clause
3824 (Comp_Unit
: Node_Id
;
3828 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3829 Unum
: Unit_Number_Type
;
3832 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
3833 -- Returns true if the context already includes a with_clause for
3834 -- this unit. If the with_clause is non-limited, the unit is fully
3835 -- visible and an implicit limited_with should not be created. If
3836 -- there is already a limited_with clause for W, a second one is
3837 -- simply redundant.
3839 --------------------------
3840 -- Previous_Withed_Unit --
3841 --------------------------
3843 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
3847 -- A limited with_clause cannot appear in the same context_clause
3848 -- as a nonlimited with_clause which mentions the same library.
3850 Item
:= First
(Context_Items
(Comp_Unit
));
3851 while Present
(Item
) loop
3852 if Nkind
(Item
) = N_With_Clause
3853 and then Library_Unit
(Item
) = Library_Unit
(W
)
3862 end Previous_Withed_Unit
;
3864 -- Start of processing for Expand_Limited_With_Clause
3867 if Nkind
(Nam
) = N_Identifier
then
3869 -- Create node for name of withed unit
3872 Make_With_Clause
(Loc
,
3873 Name
=> New_Copy
(Nam
));
3875 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
3877 Make_With_Clause
(Loc
,
3878 Name
=> Make_Selected_Component
(Loc
,
3879 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
3880 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
3881 Set_Parent
(Withn
, Parent
(N
));
3884 Set_Limited_Present
(Withn
);
3885 Set_First_Name
(Withn
);
3886 Set_Implicit_With
(Withn
);
3890 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
3895 -- Do not generate a limited_with_clause on the current unit. This
3896 -- path is taken when a unit has a limited_with clause on one of its
3899 if Unum
= Current_Sem_Unit
then
3903 Set_Library_Unit
(Withn
, Cunit
(Unum
));
3904 Set_Corresponding_Spec
3905 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
3907 if not Previous_Withed_Unit
(Withn
) then
3908 Prepend
(Withn
, Context_Items
(Parent
(N
)));
3909 Mark_Rewrite_Insertion
(Withn
);
3911 -- Add implicit limited_with_clauses for parents of child units
3912 -- mentioned in limited_with clauses.
3914 if Nkind
(Nam
) = N_Selected_Component
then
3915 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
3920 if not Limited_View_Installed
(Withn
) then
3921 Install_Limited_Withed_Unit
(Withn
);
3924 end Expand_Limited_With_Clause
;
3926 -- Start of processing for Install_Limited_Context_Clauses
3929 Item
:= First
(Context_Items
(N
));
3930 while Present
(Item
) loop
3931 if Nkind
(Item
) = N_With_Clause
3932 and then Limited_Present
(Item
)
3933 and then not Error_Posted
(Item
)
3935 if Nkind
(Name
(Item
)) = N_Selected_Component
then
3936 Expand_Limited_With_Clause
3937 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
3940 Check_Private_Limited_Withed_Unit
(Item
);
3942 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
3943 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
3946 -- A unit may have a limited with on itself if it has a limited
3947 -- with_clause on one of its child units. In that case it is
3948 -- already being compiled and it makes no sense to install its
3951 -- If the item is a limited_private_with_clause, install it if the
3952 -- current unit is a body or if it is a private child. Otherwise
3953 -- the private clause is installed before analyzing the private
3954 -- part of the current unit.
3956 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
3957 and then not Limited_View_Installed
(Item
)
3959 not Is_Ancestor_Unit
3960 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
3962 if not Private_Present
(Item
)
3963 or else Private_Present
(N
)
3964 or else Nkind_In
(Unit
(N
), N_Package_Body
,
3968 Install_Limited_Withed_Unit
(Item
);
3976 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
3977 -- looking for incomplete subtype declarations of incomplete types
3978 -- visible through a limited with clause.
3980 if Ada_Version
>= Ada_2005
3981 and then Analyzed
(N
)
3982 and then Nkind
(Unit
(N
)) = N_Package_Declaration
3987 Non_Lim_View
: Entity_Id
;
3990 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
3991 while Present
(Decl
) loop
3992 if Nkind
(Decl
) = N_Subtype_Declaration
3994 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
3996 From_Limited_With
(Defining_Identifier
(Decl
))
3998 Def_Id
:= Defining_Identifier
(Decl
);
3999 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
4001 if not Is_Incomplete_Type
(Non_Lim_View
) then
4003 -- Convert an incomplete subtype declaration into a
4004 -- corresponding non-limited view subtype declaration.
4005 -- This is usually the case when analyzing a body that
4006 -- has regular with clauses, when the spec has limited
4009 -- If the non-limited view is still incomplete, it is
4010 -- the dummy entry already created, and the declaration
4011 -- cannot be reanalyzed. This is the case when installing
4012 -- a parent unit that has limited with-clauses.
4014 Set_Subtype_Indication
(Decl
,
4015 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
4016 Set_Etype
(Def_Id
, Non_Lim_View
);
4017 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
4018 Set_Analyzed
(Decl
, False);
4020 -- Reanalyze the declaration, suppressing the call to
4021 -- Enter_Name to avoid duplicate names.
4023 Analyze_Subtype_Declaration
4033 end Install_Limited_Context_Clauses
;
4035 ---------------------
4036 -- Install_Parents --
4037 ---------------------
4039 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean) is
4046 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4047 P_Name
:= Get_Parent_Entity
(P
);
4049 if Etype
(P_Name
) = Any_Type
then
4053 if Ekind
(P_Name
) = E_Generic_Package
4054 and then not Nkind_In
(Lib_Unit
, N_Generic_Subprogram_Declaration
,
4055 N_Generic_Package_Declaration
)
4056 and then Nkind
(Lib_Unit
) not in N_Generic_Renaming_Declaration
4059 ("child of a generic package must be a generic unit", Lib_Unit
);
4061 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4063 ("parent unit must be package or generic package", Lib_Unit
);
4064 raise Unrecoverable_Error
;
4066 elsif Present
(Renamed_Object
(P_Name
)) then
4067 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4068 raise Unrecoverable_Error
;
4070 -- Verify that a child of an instance is itself an instance, or the
4071 -- renaming of one. Given that an instance that is a unit is replaced
4072 -- with a package declaration, check against the original node. The
4073 -- parent may be currently being instantiated, in which case it appears
4074 -- as a declaration, but the generic_parent is already established
4075 -- indicating that we deal with an instance.
4077 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4078 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4079 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4081 (Nkind
(Lib_Unit
) = N_Package_Declaration
4082 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4087 ("child of an instance must be an instance or renaming",
4092 -- This is the recursive call that ensures all parents are loaded
4094 if Is_Child_Spec
(P
) then
4096 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)));
4099 -- Now we can install the context for this parent
4101 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4102 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4103 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4105 -- The child unit is in the declarative region of the parent. The parent
4106 -- must therefore appear in the scope stack and be visible, as when
4107 -- compiling the corresponding body. If the child unit is private or it
4108 -- is a package body, private declarations must be accessible as well.
4109 -- Use declarations in the parent must also be installed. Finally, other
4110 -- child units of the same parent that are in the context are
4111 -- immediately visible.
4113 -- Find entity for compilation unit, and set its private descendant
4114 -- status as needed. Indicate that it is a compilation unit, which is
4115 -- redundant in general, but needed if this is a generated child spec
4116 -- for a child body without previous spec.
4118 E_Name
:= Defining_Entity
(Lib_Unit
);
4120 Set_Is_Child_Unit
(E_Name
);
4121 Set_Is_Compilation_Unit
(E_Name
);
4123 Set_Is_Private_Descendant
(E_Name
,
4124 Is_Private_Descendant
(P_Name
)
4125 or else Private_Present
(Parent
(Lib_Unit
)));
4127 P_Spec
:= Package_Specification
(P_Name
);
4128 Push_Scope
(P_Name
);
4130 -- Save current visibility of unit
4132 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4133 Is_Immediately_Visible
(P_Name
);
4134 Set_Is_Immediately_Visible
(P_Name
);
4135 Install_Visible_Declarations
(P_Name
);
4136 Set_Use
(Visible_Declarations
(P_Spec
));
4138 -- If the parent is a generic unit, its formal part may contain formal
4139 -- packages and use clauses for them.
4141 if Ekind
(P_Name
) = E_Generic_Package
then
4142 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4145 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4146 Install_Private_Declarations
(P_Name
);
4147 Install_Private_With_Clauses
(P_Name
);
4148 Set_Use
(Private_Declarations
(P_Spec
));
4150 end Install_Parents
;
4152 ----------------------------------
4153 -- Install_Private_With_Clauses --
4154 ----------------------------------
4156 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4157 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4161 if Debug_Flag_I
then
4162 Write_Str
("install private with clauses of ");
4163 Write_Name
(Chars
(P
));
4167 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4168 Item
:= First
(Context_Items
(Parent
(Decl
)));
4169 while Present
(Item
) loop
4170 if Nkind
(Item
) = N_With_Clause
4171 and then Private_Present
(Item
)
4173 -- If the unit is an ancestor of the current one, it is the
4174 -- case of a private limited with clause on a child unit, and
4175 -- the compilation of one of its descendants, In that case the
4176 -- limited view is errelevant.
4178 if Limited_Present
(Item
) then
4179 if not Limited_View_Installed
(Item
)
4181 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4182 Cunit
(Current_Sem_Unit
))
4184 Install_Limited_Withed_Unit
(Item
);
4187 Install_Withed_Unit
(Item
, Private_With_OK
=> True);
4194 end Install_Private_With_Clauses
;
4196 ----------------------
4197 -- Install_Siblings --
4198 ----------------------
4200 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4206 -- Iterate over explicit with clauses, and check whether the scope of
4207 -- each entity is an ancestor of the current unit, in which case it is
4208 -- immediately visible.
4210 Item
:= First
(Context_Items
(N
));
4211 while Present
(Item
) loop
4213 -- Do not install private_with_clauses declaration, unless unit
4214 -- is itself a private child unit, or is a body. Note that for a
4215 -- subprogram body the private_with_clause does not take effect until
4216 -- after the specification.
4218 if Nkind
(Item
) /= N_With_Clause
4219 or else Implicit_With
(Item
)
4220 or else Limited_Present
(Item
)
4221 or else Error_Posted
(Item
)
4225 elsif not Private_Present
(Item
)
4226 or else Private_Present
(N
)
4227 or else Nkind
(Unit
(N
)) = N_Package_Body
4229 Id
:= Entity
(Name
(Item
));
4231 if Is_Child_Unit
(Id
)
4232 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4234 Set_Is_Immediately_Visible
(Id
);
4236 -- Check for the presence of another unit in the context that
4237 -- may be inadvertently hidden by the child.
4239 Prev
:= Current_Entity
(Id
);
4242 and then Is_Immediately_Visible
(Prev
)
4243 and then not Is_Child_Unit
(Prev
)
4249 Clause
:= First
(Context_Items
(N
));
4250 while Present
(Clause
) loop
4251 if Nkind
(Clause
) = N_With_Clause
4252 and then Entity
(Name
(Clause
)) = Prev
4255 ("child unit& hides compilation unit " &
4256 "with the same name??",
4266 -- The With_Clause may be on a grand-child or one of its further
4267 -- descendants, which makes a child immediately visible. Examine
4268 -- ancestry to determine whether such a child exists. For example,
4269 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4270 -- is immediately visible.
4272 elsif Is_Child_Unit
(Id
) then
4278 while Is_Child_Unit
(Par
) loop
4279 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4280 Set_Is_Immediately_Visible
(Par
);
4289 -- If the item is a private with-clause on a child unit, the parent
4290 -- may have been installed already, but the child unit must remain
4291 -- invisible until installed in a private part or body, unless there
4292 -- is already a regular with_clause for it in the current unit.
4294 elsif Private_Present
(Item
) then
4295 Id
:= Entity
(Name
(Item
));
4297 if Is_Child_Unit
(Id
) then
4301 function In_Context
return Boolean;
4302 -- Scan context of current unit, to check whether there is
4303 -- a with_clause on the same unit as a private with-clause
4304 -- on a parent, in which case child unit is visible. If the
4305 -- unit is a grand-child, the same applies to its parent.
4311 function In_Context
return Boolean is
4314 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4315 while Present
(Clause
) loop
4316 if Nkind
(Clause
) = N_With_Clause
4317 and then Comes_From_Source
(Clause
)
4318 and then Is_Entity_Name
(Name
(Clause
))
4319 and then not Private_Present
(Clause
)
4321 if Entity
(Name
(Clause
)) = Id
4323 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4324 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4337 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4344 end Install_Siblings
;
4346 ---------------------------------
4347 -- Install_Limited_Withed_Unit --
4348 ---------------------------------
4350 procedure Install_Limited_Withed_Unit
(N
: Node_Id
) is
4351 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4354 Is_Child_Package
: Boolean := False;
4355 Lim_Header
: Entity_Id
;
4356 Lim_Typ
: Entity_Id
;
4358 procedure Check_Body_Required
;
4359 -- A unit mentioned in a limited with_clause may not be mentioned in
4360 -- a regular with_clause, but must still be included in the current
4361 -- partition. We need to determine whether the unit needs a body, so
4362 -- that the binder can determine the name of the file to be compiled.
4363 -- Checking whether a unit needs a body can be done without semantic
4364 -- analysis, by examining the nature of the declarations in the package.
4366 function Has_Limited_With_Clause
4367 (C_Unit
: Entity_Id
;
4368 Pack
: Entity_Id
) return Boolean;
4369 -- Determine whether any package in the ancestor chain starting with
4370 -- C_Unit has a limited with clause for package Pack.
4372 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean;
4373 -- Check if some package installed though normal with-clauses has a
4374 -- renaming declaration of package P. AARM 10.1.2(21/2).
4376 -------------------------
4377 -- Check_Body_Required --
4378 -------------------------
4380 procedure Check_Body_Required
is
4381 PA
: constant List_Id
:=
4382 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4384 procedure Check_Declarations
(Spec
: Node_Id
);
4385 -- Recursive procedure that does the work and checks nested packages
4387 ------------------------
4388 -- Check_Declarations --
4389 ------------------------
4391 procedure Check_Declarations
(Spec
: Node_Id
) is
4393 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4395 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4397 procedure Check_Pragma_Import
(P
: Node_Id
);
4398 -- If a pragma import applies to a previous subprogram, the
4399 -- enclosing unit may not need a body. The processing is syntactic
4400 -- and does not require a declaration to be analyzed. The code
4401 -- below also handles pragma Import when applied to a subprogram
4402 -- that renames another. In this case the pragma applies to the
4405 -- Chains of multiple renames are not handled by the code below.
4406 -- It is probably impossible to handle all cases without proper
4407 -- name resolution. In such cases the algorithm is conservative
4408 -- and will indicate that a body is needed???
4410 -------------------------
4411 -- Check_Pragma_Import --
4412 -------------------------
4414 procedure Check_Pragma_Import
(P
: Node_Id
) is
4420 procedure Remove_Homonyms
(E
: Node_Id
);
4421 -- Make one pass over list of subprograms. Called again if
4422 -- subprogram is a renaming. E is known to be an identifier.
4424 ---------------------
4425 -- Remove_Homonyms --
4426 ---------------------
4428 procedure Remove_Homonyms
(E
: Node_Id
) is
4429 R
: Entity_Id
:= Empty
;
4430 -- Name of renamed entity, if any
4433 Subp_Id
:= First_Elmt
(Subp_List
);
4434 while Present
(Subp_Id
) loop
4435 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4436 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4437 /= N_Subprogram_Renaming_Declaration
4440 Next_Elmt
(Subp_Id
);
4441 Remove_Elmt
(Subp_List
, Prev_Id
);
4443 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4447 Next_Elmt
(Subp_Id
);
4452 if Nkind
(R
) = N_Identifier
then
4453 Remove_Homonyms
(R
);
4455 elsif Nkind
(R
) = N_Selected_Component
then
4456 Remove_Homonyms
(Selector_Name
(R
));
4458 -- Renaming of attribute
4464 end Remove_Homonyms
;
4466 -- Start of processing for Check_Pragma_Import
4469 -- Find name of entity in Import pragma. We have not analyzed
4470 -- the construct, so we must guard against syntax errors.
4472 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4475 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4479 Imported
:= Expression
(Arg
);
4482 Remove_Homonyms
(Imported
);
4483 end Check_Pragma_Import
;
4485 -- Start of processing for Check_Declarations
4488 -- Search for Elaborate Body pragma
4490 Decl
:= First
(Visible_Declarations
(Spec
));
4491 while Present
(Decl
)
4492 and then Nkind
(Decl
) = N_Pragma
4494 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4495 Set_Body_Required
(Library_Unit
(N
));
4502 -- Look for declarations that require the presence of a body. We
4503 -- have already skipped pragmas at the start of the list.
4505 while Present
(Decl
) loop
4507 -- Subprogram that comes from source means body may be needed.
4508 -- Save for subsequent examination of import pragmas.
4510 if Comes_From_Source
(Decl
)
4511 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4512 N_Subprogram_Renaming_Declaration
,
4513 N_Generic_Subprogram_Declaration
))
4515 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4517 -- Package declaration of generic package declaration. We need
4518 -- to recursively examine nested declarations.
4520 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4521 N_Generic_Package_Declaration
)
4523 Check_Declarations
(Specification
(Decl
));
4525 elsif Nkind
(Decl
) = N_Pragma
4526 and then Pragma_Name
(Decl
) = Name_Import
4528 Check_Pragma_Import
(Decl
);
4534 -- Same set of tests for private part. In addition to subprograms
4535 -- detect the presence of Taft Amendment types (incomplete types
4536 -- completed in the body).
4538 Decl
:= First
(Private_Declarations
(Spec
));
4539 while Present
(Decl
) loop
4540 if Comes_From_Source
(Decl
)
4541 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4542 N_Subprogram_Renaming_Declaration
,
4543 N_Generic_Subprogram_Declaration
))
4545 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4547 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4548 N_Generic_Package_Declaration
)
4550 Check_Declarations
(Specification
(Decl
));
4552 -- Collect incomplete type declarations for separate pass
4554 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4555 Append_Elmt
(Decl
, Incomplete_Decls
);
4557 elsif Nkind
(Decl
) = N_Pragma
4558 and then Pragma_Name
(Decl
) = Name_Import
4560 Check_Pragma_Import
(Decl
);
4566 -- Now check incomplete declarations to locate Taft amendment
4567 -- types. This can be done by examining the defining identifiers
4568 -- of type declarations without real semantic analysis.
4574 Inc
:= First_Elmt
(Incomplete_Decls
);
4575 while Present
(Inc
) loop
4576 Decl
:= Next
(Node
(Inc
));
4577 while Present
(Decl
) loop
4578 if Nkind
(Decl
) = N_Full_Type_Declaration
4579 and then Chars
(Defining_Identifier
(Decl
)) =
4580 Chars
(Defining_Identifier
(Node
(Inc
)))
4588 -- If no completion, this is a TAT, and a body is needed
4591 Set_Body_Required
(Library_Unit
(N
));
4599 -- Finally, check whether there are subprograms that still require
4600 -- a body, i.e. are not renamings or null.
4602 if not Is_Empty_Elmt_List
(Subp_List
) then
4608 Subp_Id
:= First_Elmt
(Subp_List
);
4609 Spec
:= Parent
(Node
(Subp_Id
));
4611 while Present
(Subp_Id
) loop
4612 if Nkind
(Parent
(Spec
))
4613 = N_Subprogram_Renaming_Declaration
4617 elsif Nkind
(Spec
) = N_Procedure_Specification
4618 and then Null_Present
(Spec
)
4623 Set_Body_Required
(Library_Unit
(N
));
4627 Next_Elmt
(Subp_Id
);
4631 end Check_Declarations
;
4633 -- Start of processing for Check_Body_Required
4636 -- If this is an imported package (Java and CIL usage) no body is
4637 -- needed. Scan list of pragmas that may follow a compilation unit
4638 -- to look for a relevant pragma Import.
4640 if Present
(PA
) then
4646 while Present
(Prag
) loop
4647 if Nkind
(Prag
) = N_Pragma
4648 and then Get_Pragma_Id
(Prag
) = Pragma_Import
4658 Check_Declarations
(Specification
(P_Unit
));
4659 end Check_Body_Required
;
4661 -----------------------------
4662 -- Has_Limited_With_Clause --
4663 -----------------------------
4665 function Has_Limited_With_Clause
4666 (C_Unit
: Entity_Id
;
4667 Pack
: Entity_Id
) return Boolean
4674 while Present
(Par
) loop
4675 if Ekind
(Par
) /= E_Package
then
4679 -- Retrieve the Compilation_Unit node for Par and determine if
4680 -- its context clauses contain a limited with for Pack.
4682 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
4684 if Nkind
(Par_Unit
) = N_Package_Declaration
then
4685 Par_Unit
:= Parent
(Par_Unit
);
4688 if Has_With_Clause
(Par_Unit
, Pack
, True) then
4692 -- If there are more ancestors, climb up the tree, otherwise we
4695 if Is_Child_Unit
(Par
) then
4703 end Has_Limited_With_Clause
;
4705 ----------------------------------
4706 -- Is_Visible_Through_Renamings --
4707 ----------------------------------
4709 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean is
4710 Kind
: constant Node_Kind
:=
4711 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
4717 -- Example of the error detected by this subprogram:
4725 -- package Ren_P renames P;
4731 -- limited with P; -- ERROR
4732 -- package R.C is ...
4734 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
4737 Item
:= First
(Context_Items
(Aux_Unit
));
4738 while Present
(Item
) loop
4739 if Nkind
(Item
) = N_With_Clause
4740 and then not Limited_Present
(Item
)
4741 and then Nkind
(Unit
(Library_Unit
(Item
))) =
4742 N_Package_Declaration
4745 First
(Visible_Declarations
4746 (Specification
(Unit
(Library_Unit
(Item
)))));
4747 while Present
(Decl
) loop
4748 if Nkind
(Decl
) = N_Package_Renaming_Declaration
4749 and then Entity
(Name
(Decl
)) = P
4751 -- Generate the error message only if the current unit
4752 -- is a package declaration; in case of subprogram
4753 -- bodies and package bodies we just return True to
4754 -- indicate that the limited view must not be
4757 if Kind
= N_Package_Declaration
then
4759 ("simultaneous visibility of the limited and " &
4760 "unlimited views not allowed", N
);
4761 Error_Msg_Sloc
:= Sloc
(Item
);
4763 ("\\ unlimited view of & visible through the " &
4764 "context clause #", N
, P
);
4765 Error_Msg_Sloc
:= Sloc
(Decl
);
4766 Error_Msg_NE
("\\ and the renaming #", N
, P
);
4779 -- If it is a body not acting as spec, follow pointer to the
4780 -- corresponding spec, otherwise follow pointer to parent spec.
4782 if Present
(Library_Unit
(Aux_Unit
))
4783 and then Nkind_In
(Unit
(Aux_Unit
),
4784 N_Package_Body
, N_Subprogram_Body
)
4786 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
4788 -- Aux_Unit is a body that acts as a spec. Clause has
4789 -- already been flagged as illegal.
4794 Aux_Unit
:= Library_Unit
(Aux_Unit
);
4798 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
4801 exit when No
(Aux_Unit
);
4805 end Is_Visible_Through_Renamings
;
4807 -- Start of processing for Install_Limited_Withed_Unit
4810 pragma Assert
(not Limited_View_Installed
(N
));
4812 -- In case of limited with_clause on subprograms, generics, instances,
4813 -- or renamings, the corresponding error was previously posted and we
4814 -- have nothing to do here. If the file is missing altogether, it has
4815 -- no source location.
4817 if Nkind
(P_Unit
) /= N_Package_Declaration
4818 or else Sloc
(P_Unit
) = No_Location
4823 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
4825 -- Handle child packages
4827 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
4828 Is_Child_Package
:= True;
4829 P
:= Defining_Identifier
(P
);
4832 -- Do not install the limited-view if the context of the unit is already
4833 -- available through a regular with clause.
4835 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4836 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4841 -- Do not install the limited-view if the full-view is already visible
4842 -- through renaming declarations.
4844 if Is_Visible_Through_Renamings
(P
) then
4848 -- Do not install the limited view if this is the unit being analyzed.
4849 -- This unusual case will happen when a unit has a limited_with clause
4850 -- on one of its children. The compilation of the child forces the load
4851 -- of the parent which tries to install the limited view of the child
4852 -- again. Installing the limited view must also be disabled when
4853 -- compiling the body of the child unit.
4855 if P
= Cunit_Entity
(Current_Sem_Unit
)
4856 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4857 and then P
= Main_Unit_Entity
4858 and then Is_Ancestor_Unit
4859 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
4864 -- This scenario is similar to the one above, the difference is that the
4865 -- compilation of sibling Par.Sib forces the load of parent Par which
4866 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4867 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4868 -- non-limited views of all entities from Lim_Pack.
4870 -- limited with Lim_Pack; -- [1]
4871 -- package Par is ... package Lim_Pack is ...
4873 -- with Lim_Pack; -- [2]
4874 -- package Par.Sib is ... package body Par.Sib is ...
4876 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4877 -- Sem_Unit is the body of Par.Sib.
4879 if Ekind
(P
) = E_Package
4880 and then Ekind
(Main_Unit_Entity
) = E_Package
4881 and then Is_Child_Unit
(Main_Unit_Entity
)
4883 -- The body has a regular with clause
4885 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4886 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4888 -- One of the ancestors has a limited with clause
4890 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
4891 N_Package_Specification
4892 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
4897 -- A common use of the limited-with is to have a limited-with in the
4898 -- package spec, and a normal with in its package body. For example:
4900 -- limited with X; -- [1]
4904 -- package body A is ...
4906 -- The compilation of A's body installs the context clauses found at [2]
4907 -- and then the context clauses of its specification (found at [1]). As
4908 -- a consequence, at [1] the specification of X has been analyzed and it
4909 -- is immediately visible. According to the semantics of limited-with
4910 -- context clauses we don't install the limited view because the full
4911 -- view of X supersedes its limited view.
4913 if Analyzed
(P_Unit
)
4915 (Is_Immediately_Visible
(P
)
4916 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
4919 -- The presence of both the limited and the analyzed nonlimited view
4920 -- may also be an error, such as an illegal context for a limited
4921 -- with_clause. In that case, do not process the context item at all.
4923 if Error_Posted
(N
) then
4927 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
4931 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4932 while Present
(Item
) loop
4933 if Nkind
(Item
) = N_With_Clause
4934 and then Comes_From_Source
(Item
)
4935 and then Entity
(Name
(Item
)) = P
4944 -- If this is a child body, assume that the nonlimited with_clause
4945 -- appears in an ancestor. Could be refined ???
4949 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
4956 -- If in package declaration, nonlimited view brought in from
4957 -- parent unit or some error condition.
4963 if Debug_Flag_I
then
4964 Write_Str
("install limited view of ");
4965 Write_Name
(Chars
(P
));
4969 -- If the unit has not been analyzed and the limited view has not been
4970 -- already installed then we install it.
4972 if not Analyzed
(P_Unit
) then
4973 if not In_Chain
(P
) then
4975 -- Minimum decoration
4977 Set_Ekind
(P
, E_Package
);
4978 Set_Etype
(P
, Standard_Void_Type
);
4979 Set_Scope
(P
, Standard_Standard
);
4980 Set_Is_Visible_Lib_Unit
(P
);
4982 if Is_Child_Package
then
4983 Set_Is_Child_Unit
(P
);
4984 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
4987 -- Place entity on visibility structure
4989 Set_Homonym
(P
, Current_Entity
(P
));
4990 Set_Current_Entity
(P
);
4992 if Debug_Flag_I
then
4993 Write_Str
(" (homonym) chain ");
4994 Write_Name
(Chars
(P
));
4998 -- Install the incomplete view. The first element of the limited
4999 -- view is a header (an E_Package entity) used to reference the
5000 -- first shadow entity in the private part of the package.
5002 Lim_Header
:= Limited_View
(P
);
5003 Lim_Typ
:= First_Entity
(Lim_Header
);
5005 while Present
(Lim_Typ
)
5006 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5008 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
5009 Set_Current_Entity
(Lim_Typ
);
5011 if Debug_Flag_I
then
5012 Write_Str
(" (homonym) chain ");
5013 Write_Name
(Chars
(Lim_Typ
));
5017 Next_Entity
(Lim_Typ
);
5021 -- If the unit appears in a previous regular with_clause, the regular
5022 -- entities of the public part of the withed package must be replaced
5023 -- by the shadow ones.
5025 -- This code must be kept synchronized with the code that replaces the
5026 -- shadow entities by the real entities (see body of Remove_Limited
5027 -- With_Clause); otherwise the contents of the homonym chains are not
5031 -- Hide all the type entities of the public part of the package to
5032 -- avoid its usage. This is needed to cover all the subtype decla-
5033 -- rations because we do not remove them from the homonym chain.
5035 E
:= First_Entity
(P
);
5036 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5038 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5045 -- Replace the real entities by the shadow entities of the limited
5046 -- view. The first element of the limited view is a header that is
5047 -- used to reference the first shadow entity in the private part
5048 -- of the package. Successive elements are the limited views of the
5049 -- type (including regular incomplete types) declared in the package.
5051 Lim_Header
:= Limited_View
(P
);
5053 Lim_Typ
:= First_Entity
(Lim_Header
);
5054 while Present
(Lim_Typ
)
5055 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5057 pragma Assert
(not In_Chain
(Lim_Typ
));
5059 -- Do not unchain nested packages and child units
5061 if Ekind
(Lim_Typ
) /= E_Package
5062 and then not Is_Child_Unit
(Lim_Typ
)
5068 Prev
:= Current_Entity
(Lim_Typ
);
5071 -- Replace E in the homonyms list, so that the limited view
5072 -- becomes available.
5074 -- If the non-limited view is a record with an anonymous
5075 -- self-referential component, the analysis of the record
5076 -- declaration creates an incomplete type with the same name
5077 -- in order to define an internal access type. The visible
5078 -- entity is now the incomplete type, and that is the one to
5079 -- replace in the visibility structure.
5081 if E
= Non_Limited_View
(Lim_Typ
)
5083 (Ekind
(E
) = E_Incomplete_Type
5084 and then Full_View
(E
) = Non_Limited_View
(Lim_Typ
))
5086 Set_Homonym
(Lim_Typ
, Homonym
(Prev
));
5087 Set_Current_Entity
(Lim_Typ
);
5091 E
:= Homonym
(Prev
);
5093 -- E may have been removed when installing a previous
5094 -- limited_with_clause.
5097 exit when E
= Non_Limited_View
(Lim_Typ
);
5098 Prev
:= Homonym
(Prev
);
5102 Set_Homonym
(Lim_Typ
, Homonym
(Homonym
(Prev
)));
5103 Set_Homonym
(Prev
, Lim_Typ
);
5108 if Debug_Flag_I
then
5109 Write_Str
(" (homonym) chain ");
5110 Write_Name
(Chars
(Lim_Typ
));
5115 Next_Entity
(Lim_Typ
);
5119 -- The package must be visible while the limited-with clause is active
5120 -- because references to the type P.T must resolve in the usual way.
5121 -- In addition, we remember that the limited-view has been installed to
5122 -- uninstall it at the point of context removal.
5124 Set_Is_Immediately_Visible
(P
);
5125 Set_Limited_View_Installed
(N
);
5127 -- If unit has not been analyzed in some previous context, check
5128 -- (imperfectly ???) whether it might need a body.
5130 if not Analyzed
(P_Unit
) then
5131 Check_Body_Required
;
5134 -- If the package in the limited_with clause is a child unit, the clause
5135 -- is unanalyzed and appears as a selected component. Recast it as an
5136 -- expanded name so that the entity can be properly set. Use entity of
5137 -- parent, if available, for higher ancestors in the name.
5139 if Nkind
(Name
(N
)) = N_Selected_Component
then
5147 while Nkind
(Nam
) = N_Selected_Component
5148 and then Present
(Ent
)
5150 Change_Selected_Component_To_Expanded_Name
(Nam
);
5152 -- Set entity of parent identifiers if the unit is a child
5153 -- unit. This ensures that the tree is properly formed from
5154 -- semantic point of view (e.g. for ASIS queries). The unit
5155 -- entities are not fully analyzed, so we need to follow unit
5156 -- links in the tree.
5158 Set_Entity
(Nam
, Ent
);
5160 Nam
:= Prefix
(Nam
);
5163 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5165 -- Set entity of last ancestor
5167 if Nkind
(Nam
) = N_Identifier
then
5168 Set_Entity
(Nam
, Ent
);
5174 Set_Entity
(Name
(N
), P
);
5175 Set_From_Limited_With
(P
);
5176 end Install_Limited_Withed_Unit
;
5178 -------------------------
5179 -- Install_Withed_Unit --
5180 -------------------------
5182 procedure Install_Withed_Unit
5183 (With_Clause
: Node_Id
;
5184 Private_With_OK
: Boolean := False)
5186 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5187 P
: constant Entity_Id
:= Scope
(Uname
);
5190 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5191 -- compiling a package declaration and the Private_With_OK flag was not
5192 -- set by the caller. These declarations will be installed later (before
5193 -- analyzing the private part of the package).
5195 if Private_Present
(With_Clause
)
5196 and then Nkind
(Unit
(Parent
(With_Clause
))) = N_Package_Declaration
5197 and then not (Private_With_OK
)
5202 if Debug_Flag_I
then
5203 if Private_Present
(With_Clause
) then
5204 Write_Str
("install private withed unit ");
5206 Write_Str
("install withed unit ");
5209 Write_Name
(Chars
(Uname
));
5213 -- We do not apply the restrictions to an internal unit unless we are
5214 -- compiling the internal unit as a main unit. This check is also
5215 -- skipped for dummy units (for missing packages).
5217 if Sloc
(Uname
) /= No_Location
5218 and then (not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
5219 or else Current_Sem_Unit
= Main_Unit
)
5221 Check_Restricted_Unit
5222 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5225 if P
/= Standard_Standard
then
5227 -- If the unit is not analyzed after analysis of the with clause and
5228 -- it is an instantiation then it awaits a body and is the main unit.
5229 -- Its appearance in the context of some other unit indicates a
5230 -- circular dependency (DEC suite perversity).
5232 if not Analyzed
(Uname
)
5233 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5236 ("instantiation depends on itself", Name
(With_Clause
));
5238 elsif not Is_Visible_Lib_Unit
(Uname
) then
5240 -- Abandon processing in case of previous errors
5242 if No
(Scope
(Uname
)) then
5243 Check_Error_Detected
;
5247 Set_Is_Visible_Lib_Unit
(Uname
);
5249 -- If the unit is a wrapper package for a compilation unit that is
5250 -- a subprogrm instance, indicate that the instance itself is a
5251 -- visible unit. This is necessary if the instance is inlined.
5253 if Is_Wrapper_Package
(Uname
) then
5254 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5257 -- If the child unit appears in the context of its parent, it is
5258 -- immediately visible.
5260 if In_Open_Scopes
(Scope
(Uname
)) then
5261 Set_Is_Immediately_Visible
(Uname
);
5264 if Is_Generic_Instance
(Uname
)
5265 and then Ekind
(Uname
) in Subprogram_Kind
5267 -- Set flag as well on the visible entity that denotes the
5268 -- instance, which renames the current one.
5270 Set_Is_Visible_Lib_Unit
5272 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5275 -- The parent unit may have been installed already, and may have
5276 -- appeared in a use clause.
5278 if In_Use
(Scope
(Uname
)) then
5279 Set_Is_Potentially_Use_Visible
(Uname
);
5282 Set_Context_Installed
(With_Clause
);
5285 elsif not Is_Immediately_Visible
(Uname
) then
5286 Set_Is_Visible_Lib_Unit
(Uname
);
5288 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5289 Set_Is_Immediately_Visible
(Uname
);
5292 Set_Context_Installed
(With_Clause
);
5295 -- A with-clause overrides a with-type clause: there are no restric-
5296 -- tions on the use of package entities.
5298 if Ekind
(Uname
) = E_Package
then
5299 Set_From_Limited_With
(Uname
, False);
5302 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5303 -- unit if there is a visible homograph for it declared in the same
5304 -- declarative region. This pathological case can only arise when an
5305 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5306 -- G1 has a generic child also named G2, and the context includes with_
5307 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5308 -- of I1.G2 visible as well. If the child unit is named Standard, do
5309 -- not apply the check to the Standard package itself.
5311 if Is_Child_Unit
(Uname
)
5312 and then Is_Visible_Lib_Unit
(Uname
)
5313 and then Ada_Version
>= Ada_2005
5316 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5322 U2
:= Homonym
(Uname
);
5323 while Present
(U2
) and then U2
/= Standard_Standard
loop
5325 Decl2
:= Unit_Declaration_Node
(P2
);
5327 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5328 if Is_Generic_Instance
(P
)
5329 and then Nkind
(Decl1
) = N_Package_Declaration
5330 and then Generic_Parent
(Specification
(Decl1
)) = P2
5332 Error_Msg_N
("illegal with_clause", With_Clause
);
5334 ("\child unit has visible homograph" &
5335 " (RM 8.3(26), 10.1.1(19))",
5339 elsif Is_Generic_Instance
(P2
)
5340 and then Nkind
(Decl2
) = N_Package_Declaration
5341 and then Generic_Parent
(Specification
(Decl2
)) = P
5343 -- With_clause for child unit of instance appears before
5344 -- in the context. We want to place the error message on
5345 -- it, not on the generic child unit itself.
5348 Prev_Clause
: Node_Id
;
5351 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5352 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5356 pragma Assert
(Present
(Prev_Clause
));
5357 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5359 ("\child unit has visible homograph" &
5360 " (RM 8.3(26), 10.1.1(19))",
5371 end Install_Withed_Unit
;
5377 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5378 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5381 return (K
in N_Generic_Declaration
or else
5382 K
in N_Generic_Instantiation
or else
5383 K
in N_Generic_Renaming_Declaration
or else
5384 K
= N_Package_Declaration
or else
5385 K
= N_Package_Renaming_Declaration
or else
5386 K
= N_Subprogram_Declaration
or else
5387 K
= N_Subprogram_Renaming_Declaration
)
5388 and then Present
(Parent_Spec
(Lib_Unit
));
5391 ------------------------------------
5392 -- Is_Legal_Shadow_Entity_In_Body --
5393 ------------------------------------
5395 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5396 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5398 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5401 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5402 end Is_Legal_Shadow_Entity_In_Body
;
5404 ----------------------
5405 -- Is_Ancestor_Unit --
5406 ----------------------
5408 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5409 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5412 if Nkind_In
(Unit
(U2
), N_Package_Body
, N_Subprogram_Body
) then
5413 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5414 return Is_Ancestor_Package
(E1
, E2
);
5418 end Is_Ancestor_Unit
;
5420 -----------------------
5421 -- Load_Needed_Body --
5422 -----------------------
5424 -- N is a generic unit named in a with clause, or else it is a unit that
5425 -- contains a generic unit or an inlined function. In order to perform an
5426 -- instantiation, the body of the unit must be present. If the unit itself
5427 -- is generic, we assume that an instantiation follows, and load & analyze
5428 -- the body unconditionally. This forces analysis of the spec as well.
5430 -- If the unit is not generic, but contains a generic unit, it is loaded on
5431 -- demand, at the point of instantiation (see ch12).
5433 procedure Load_Needed_Body
5436 Do_Analyze
: Boolean := True)
5438 Body_Name
: Unit_Name_Type
;
5439 Unum
: Unit_Number_Type
;
5441 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5442 -- The loading and analysis is done with style checks off
5445 if not GNAT_Mode
then
5446 Style_Check
:= False;
5449 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5452 (Load_Name
=> Body_Name
,
5458 if Unum
= No_Unit
then
5462 Compiler_State
:= Analyzing
; -- reset after load
5464 if Fatal_Error
(Unum
) /= Error_Detected
or else Try_Semantics
then
5465 if Debug_Flag_L
then
5466 Write_Str
("*** Loaded generic body");
5471 Semantics
(Cunit
(Unum
));
5478 Style_Check
:= Save_Style_Check
;
5479 end Load_Needed_Body
;
5481 -------------------------
5482 -- Build_Limited_Views --
5483 -------------------------
5485 procedure Build_Limited_Views
(N
: Node_Id
) is
5486 Unum
: constant Unit_Number_Type
:=
5487 Get_Source_Unit
(Library_Unit
(N
));
5488 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5490 Shadow_Pack
: Entity_Id
;
5491 -- The corresponding shadow entity of the withed package. This entity
5492 -- offers incomplete views of packages and types as well as abstract
5493 -- views of states and variables declared within.
5495 Last_Shadow
: Entity_Id
:= Empty
;
5496 -- The last shadow entity created by routine Build_Shadow_Entity
5498 procedure Build_Shadow_Entity
5501 Shadow
: out Entity_Id
;
5502 Is_Tagged
: Boolean := False);
5503 -- Create a shadow entity that hides Ent and offers an abstract or
5504 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5505 -- should be set when Ent is a tagged type. The generated entity is
5506 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5508 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5509 -- Perform minimal decoration of a package or its corresponding shadow
5510 -- entity denoted by Ent. Scop is the proper scope.
5512 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5513 -- Perform full decoration of an abstract state or its corresponding
5514 -- shadow entity denoted by Ent. Scop is the proper scope.
5516 procedure Decorate_Type
5519 Is_Tagged
: Boolean := False;
5520 Materialize
: Boolean := False);
5521 -- Perform minimal decoration of a type or its corresponding shadow
5522 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5523 -- should be set when Ent is a tagged type. Flag Materialize should be
5524 -- set when Ent is a tagged type and its class-wide type needs to appear
5527 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5528 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5531 procedure Process_Declarations_And_States
5535 Create_Abstract_Views
: Boolean);
5536 -- Inspect the states of package Pack and declarative list Decls. Create
5537 -- shadow entities for all nested packages, states, types and variables
5538 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5539 -- be set when the abstract states and variables need to be processed.
5541 -------------------------
5542 -- Build_Shadow_Entity --
5543 -------------------------
5545 procedure Build_Shadow_Entity
5548 Shadow
: out Entity_Id
;
5549 Is_Tagged
: Boolean := False)
5552 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5554 -- The shadow entity must share the same name and parent as the
5557 Set_Chars
(Shadow
, Chars
(Ent
));
5558 Set_Parent
(Shadow
, Parent
(Ent
));
5560 -- The abstract view of a variable is a state, not another variable
5562 if Ekind
(Ent
) = E_Variable
then
5563 Set_Ekind
(Shadow
, E_Abstract_State
);
5565 Set_Ekind
(Shadow
, Ekind
(Ent
));
5568 Set_Is_Internal
(Shadow
);
5569 Set_From_Limited_With
(Shadow
);
5571 -- Add the new shadow entity to the limited view of the package
5573 Last_Shadow
:= Shadow
;
5574 Append_Entity
(Shadow
, Shadow_Pack
);
5576 -- Perform context-specific decoration of the shadow entity
5578 if Ekind
(Ent
) = E_Abstract_State
then
5579 Decorate_State
(Shadow
, Scop
);
5580 Set_Non_Limited_View
(Shadow
, Ent
);
5582 elsif Ekind
(Ent
) = E_Package
then
5583 Decorate_Package
(Shadow
, Scop
);
5585 elsif Is_Type
(Ent
) then
5586 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
5587 Set_Non_Limited_View
(Shadow
, Ent
);
5590 Set_Non_Limited_View
5591 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Ent
));
5594 if Is_Incomplete_Or_Private_Type
(Ent
) then
5595 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
5598 elsif Ekind
(Ent
) = E_Variable
then
5599 Decorate_State
(Shadow
, Scop
);
5600 Set_Non_Limited_View
(Shadow
, Ent
);
5602 end Build_Shadow_Entity
;
5604 ----------------------
5605 -- Decorate_Package --
5606 ----------------------
5608 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5610 Set_Ekind
(Ent
, E_Package
);
5611 Set_Etype
(Ent
, Standard_Void_Type
);
5612 Set_Scope
(Ent
, Scop
);
5613 end Decorate_Package
;
5615 --------------------
5616 -- Decorate_State --
5617 --------------------
5619 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5621 Set_Ekind
(Ent
, E_Abstract_State
);
5622 Set_Etype
(Ent
, Standard_Void_Type
);
5623 Set_Scope
(Ent
, Scop
);
5624 Set_Encapsulating_State
(Ent
, Empty
);
5631 procedure Decorate_Type
5634 Is_Tagged
: Boolean := False;
5635 Materialize
: Boolean := False)
5640 -- An unanalyzed type or a shadow entity of a type is treated as an
5641 -- incomplete type, and carries the corresponding attributes.
5643 Set_Ekind
(Ent
, E_Incomplete_Type
);
5644 Set_Etype
(Ent
, Ent
);
5645 Set_Full_View
(Ent
, Empty
);
5646 Set_Is_First_Subtype
(Ent
);
5647 Set_Scope
(Ent
, Scop
);
5648 Set_Stored_Constraint
(Ent
, No_Elist
);
5649 Init_Size_Align
(Ent
);
5651 if From_Limited_With
(Ent
) then
5652 Set_Private_Dependents
(Ent
, New_Elmt_List
);
5655 -- A tagged type and its corresponding shadow entity share one common
5656 -- class-wide type. The list of primitive operations for the shadow
5660 Set_Is_Tagged_Type
(Ent
);
5661 Set_Direct_Primitive_Operations
(Ent
, New_Elmt_List
);
5665 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
5667 Set_Class_Wide_Type
(Ent
, CW_Typ
);
5669 -- Set parent to be the same as the parent of the tagged type.
5670 -- We need a parent field set, and it is supposed to point to
5671 -- the declaration of the type. The tagged type declaration
5672 -- essentially declares two separate types, the tagged type
5673 -- itself and the corresponding class-wide type, so it is
5674 -- reasonable for the parent fields to point to the declaration
5677 Set_Parent
(CW_Typ
, Parent
(Ent
));
5679 Set_Ekind
(CW_Typ
, E_Class_Wide_Type
);
5680 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
5681 Set_Etype
(CW_Typ
, Ent
);
5682 Set_Equivalent_Type
(CW_Typ
, Empty
);
5683 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
5684 Set_Has_Unknown_Discriminants
(CW_Typ
);
5685 Set_Is_First_Subtype
(CW_Typ
);
5686 Set_Is_Tagged_Type
(CW_Typ
);
5687 Set_Materialize_Entity
(CW_Typ
, Materialize
);
5688 Set_Scope
(CW_Typ
, Scop
);
5689 Init_Size_Align
(CW_Typ
);
5693 -----------------------
5694 -- Decorate_Variable --
5695 -----------------------
5697 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5699 Set_Ekind
(Ent
, E_Variable
);
5700 Set_Etype
(Ent
, Standard_Void_Type
);
5701 Set_Scope
(Ent
, Scop
);
5702 end Decorate_Variable
;
5704 -------------------------------------
5705 -- Process_Declarations_And_States --
5706 -------------------------------------
5708 procedure Process_Declarations_And_States
5712 Create_Abstract_Views
: Boolean)
5714 procedure Find_And_Process_States
;
5715 -- Determine whether package Pack defines abstract state either by
5716 -- using an aspect or a pragma. If this is the case, build shadow
5717 -- entities for all abstract states of Pack.
5719 procedure Process_States
(States
: Elist_Id
);
5720 -- Generate shadow entities for all abstract states in list States
5722 -----------------------------
5723 -- Find_And_Process_States --
5724 -----------------------------
5726 procedure Find_And_Process_States
is
5727 procedure Process_State
(State
: Node_Id
);
5728 -- Generate shadow entities for a single abstract state or
5729 -- multiple states expressed as an aggregate.
5735 procedure Process_State
(State
: Node_Id
) is
5736 Loc
: constant Source_Ptr
:= Sloc
(State
);
5743 -- Multiple abstract states appear as an aggregate
5745 if Nkind
(State
) = N_Aggregate
then
5746 Elmt
:= First
(Expressions
(State
));
5747 while Present
(Elmt
) loop
5748 Process_State
(Elmt
);
5754 -- A null state has no abstract view
5756 elsif Nkind
(State
) = N_Null
then
5759 -- State declaration with various options appears as an
5760 -- extension aggregate.
5762 elsif Nkind
(State
) = N_Extension_Aggregate
then
5763 Decl
:= Ancestor_Part
(State
);
5765 -- Simple state declaration
5767 elsif Nkind
(State
) = N_Identifier
then
5770 -- Possibly an illegal state declaration
5776 -- Abstract states are elaborated when the related pragma is
5777 -- elaborated. Since the withed package is not analyzed yet,
5778 -- the entities of the abstract states are not available. To
5779 -- overcome this complication, create the entities now and
5780 -- store them in their respective declarations. The entities
5781 -- are later used by routine Create_Abstract_State to declare
5782 -- and enter the states into visibility.
5784 if No
(Entity
(Decl
)) then
5785 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
5787 Set_Entity
(Decl
, Id
);
5788 Set_Parent
(Id
, State
);
5789 Decorate_State
(Id
, Scop
);
5791 -- Otherwise the package was previously withed
5794 Id
:= Entity
(Decl
);
5797 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
5802 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
5806 -- Start of processing for Find_And_Process_States
5809 -- Find aspect Abstract_State
5811 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
5812 while Present
(Asp
) loop
5813 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
5814 Process_State
(Expression
(Asp
));
5822 -- Find pragma Abstract_State by inspecting the declarations
5824 Decl
:= First
(Decls
);
5825 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
5826 if Pragma_Name
(Decl
) = Name_Abstract_State
then
5829 (First
(Pragma_Argument_Associations
(Decl
))));
5836 end Find_And_Process_States
;
5838 --------------------
5839 -- Process_States --
5840 --------------------
5842 procedure Process_States
(States
: Elist_Id
) is
5847 Elmt
:= First_Elmt
(States
);
5848 while Present
(Elmt
) loop
5849 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
5857 Is_Tagged
: Boolean;
5863 -- Start of processing for Process_Declarations_And_States
5866 -- Build abstract views for all states defined in the package
5868 if Create_Abstract_Views
then
5870 -- When a package has been analyzed, all states are stored in list
5871 -- Abstract_States. Generate the shadow entities directly.
5874 if Present
(Abstract_States
(Pack
)) then
5875 Process_States
(Abstract_States
(Pack
));
5878 -- The package may declare abstract states by using an aspect or a
5879 -- pragma. Attempt to locate one of these construct and if found,
5880 -- build the shadow entities.
5883 Find_And_Process_States
;
5887 -- Inspect the declarative list, looking for nested packages, types
5888 -- and variable declarations.
5890 Decl
:= First
(Decls
);
5891 while Present
(Decl
) loop
5895 if Nkind
(Decl
) = N_Package_Declaration
then
5896 Def_Id
:= Defining_Entity
(Decl
);
5898 -- Perform minor decoration when the withed package has not
5901 if not Is_Analyzed
then
5902 Decorate_Package
(Def_Id
, Scop
);
5905 -- Create a shadow entity that offers a limited view of all
5906 -- visible types declared within.
5908 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5910 Process_Declarations_And_States
5912 Decls
=> Visible_Declarations
(Specification
(Decl
)),
5914 Create_Abstract_Views
=> Create_Abstract_Views
);
5918 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
5919 N_Incomplete_Type_Declaration
,
5920 N_Private_Extension_Declaration
,
5921 N_Private_Type_Declaration
,
5922 N_Protected_Type_Declaration
,
5923 N_Task_Type_Declaration
)
5925 Def_Id
:= Defining_Entity
(Decl
);
5927 -- Determine whether the type is tagged. Note that packages
5928 -- included via a limited with clause are not always analyzed,
5929 -- hence the tree lookup rather than the use of attribute
5932 if Nkind
(Decl
) = N_Full_Type_Declaration
then
5933 Def
:= Type_Definition
(Decl
);
5936 (Nkind
(Def
) = N_Record_Definition
5937 and then Tagged_Present
(Def
))
5939 (Nkind
(Def
) = N_Derived_Type_Definition
5940 and then Present
(Record_Extension_Part
(Def
)));
5942 elsif Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
5943 N_Private_Type_Declaration
)
5945 Is_Tagged
:= Tagged_Present
(Decl
);
5947 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
5954 -- Perform minor decoration when the withed package has not
5957 if not Is_Analyzed
then
5958 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
5961 -- Create a shadow entity that hides the type and offers an
5962 -- incomplete view of the said type.
5964 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
5968 elsif Create_Abstract_Views
5969 and then Nkind
(Decl
) = N_Object_Declaration
5970 and then not Constant_Present
(Decl
)
5972 Def_Id
:= Defining_Entity
(Decl
);
5974 -- Perform minor decoration when the withed package has not
5977 if not Is_Analyzed
then
5978 Decorate_Variable
(Def_Id
, Scop
);
5981 -- Create a shadow entity that hides the variable and offers an
5982 -- abstract view of the said variable.
5984 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5989 end Process_Declarations_And_States
;
5993 Nam
: constant Node_Id
:= Name
(N
);
5994 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
5996 Last_Public_Shadow
: Entity_Id
:= Empty
;
5997 Private_Shadow
: Entity_Id
;
6000 -- Start of processing for Build_Limited_Views
6003 pragma Assert
(Limited_Present
(N
));
6005 -- A library_item mentioned in a limited_with_clause is a package
6006 -- declaration, not a subprogram declaration, generic declaration,
6007 -- generic instantiation, or package renaming declaration.
6009 case Nkind
(Unit
(Library_Unit
(N
))) is
6010 when N_Package_Declaration
=>
6013 when N_Subprogram_Declaration
=>
6014 Error_Msg_N
("subprograms not allowed in limited with_clauses", N
);
6017 when N_Generic_Package_Declaration |
6018 N_Generic_Subprogram_Declaration
=>
6019 Error_Msg_N
("generics not allowed in limited with_clauses", N
);
6022 when N_Generic_Instantiation
=>
6024 ("generic instantiations not allowed in limited with_clauses",
6028 when N_Generic_Renaming_Declaration
=>
6030 ("generic renamings not allowed in limited with_clauses", N
);
6033 when N_Subprogram_Renaming_Declaration
=>
6035 ("renamed subprograms not allowed in limited with_clauses", N
);
6038 when N_Package_Renaming_Declaration
=>
6040 ("renamed packages not allowed in limited with_clauses", N
);
6044 raise Program_Error
;
6047 -- The withed unit may not be analyzed, but the with calause itself
6048 -- must be minimally decorated. This ensures that the checks on unused
6049 -- with clauses also process limieted withs.
6051 Set_Ekind
(Pack
, E_Package
);
6052 Set_Etype
(Pack
, Standard_Void_Type
);
6054 if Is_Entity_Name
(Nam
) then
6055 Set_Entity
(Nam
, Pack
);
6057 elsif Nkind
(Nam
) = N_Selected_Component
then
6058 Set_Entity
(Selector_Name
(Nam
), Pack
);
6061 -- Check if the chain is already built
6063 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6065 if Limited_View_Installed
(Spec
) then
6069 -- Create the shadow package wich hides the withed unit and provides
6070 -- incomplete view of all types and packages declared within.
6072 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6073 Set_Ekind
(Shadow_Pack
, E_Package
);
6074 Set_Is_Internal
(Shadow_Pack
);
6075 Set_Limited_View
(Pack
, Shadow_Pack
);
6077 -- Inspect the abstract states and visible declarations of the withed
6078 -- unit and create shadow entities that hide existing packages, states,
6079 -- variables and types.
6081 Process_Declarations_And_States
6083 Decls
=> Visible_Declarations
(Spec
),
6085 Create_Abstract_Views
=> True);
6087 Last_Public_Shadow
:= Last_Shadow
;
6089 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6090 -- to accomodate limited private with clauses.
6092 Process_Declarations_And_States
6094 Decls
=> Private_Declarations
(Spec
),
6096 Create_Abstract_Views
=> False);
6098 if Present
(Last_Public_Shadow
) then
6099 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6101 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6104 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6105 Set_Limited_View_Installed
(Spec
);
6106 end Build_Limited_Views
;
6108 ----------------------------
6109 -- Check_No_Elab_Code_All --
6110 ----------------------------
6112 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6114 if Present
(No_Elab_Code_All_Pragma
)
6115 and then In_Extended_Main_Source_Unit
(N
)
6116 and then Present
(Context_Items
(N
))
6119 CL
: constant List_Id
:= Context_Items
(N
);
6124 while Present
(CI
) loop
6125 if Nkind
(CI
) = N_With_Clause
6127 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6129 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6131 ("violation of No_Elaboration_Code_All#", CI
);
6133 ("\unit& does not have No_Elaboration_Code_All",
6134 CI
, Entity
(Name
(CI
)));
6141 end Check_No_Elab_Code_All
;
6143 -------------------------------
6144 -- Check_Body_Needed_For_SAL --
6145 -------------------------------
6147 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6149 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6150 -- Determine whether use of entity E might require the presence of its
6151 -- body. For a package this requires a recursive traversal of all nested
6154 ---------------------------
6155 -- Entity_Needed_For_SAL --
6156 ---------------------------
6158 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6162 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6165 elsif Ekind_In
(E
, E_Generic_Function
, E_Generic_Procedure
) then
6168 elsif Ekind
(E
) = E_Generic_Package
6170 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6171 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6175 elsif Ekind
(E
) = E_Package
6176 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6177 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6179 Ent
:= First_Entity
(E
);
6180 while Present
(Ent
) loop
6181 if Entity_Needs_Body
(Ent
) then
6193 end Entity_Needs_Body
;
6195 -- Start of processing for Check_Body_Needed_For_SAL
6198 if Ekind
(Unit_Name
) = E_Generic_Package
6199 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6200 N_Generic_Package_Declaration
6202 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6204 Set_Body_Needed_For_SAL
(Unit_Name
);
6206 elsif Ekind_In
(Unit_Name
, E_Generic_Procedure
, E_Generic_Function
) then
6207 Set_Body_Needed_For_SAL
(Unit_Name
);
6209 elsif Is_Subprogram
(Unit_Name
)
6210 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6211 N_Subprogram_Declaration
6212 and then Has_Pragma_Inline
(Unit_Name
)
6214 Set_Body_Needed_For_SAL
(Unit_Name
);
6216 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6217 Check_Body_Needed_For_SAL
6218 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6220 elsif Ekind
(Unit_Name
) = E_Package
6221 and then Entity_Needs_Body
(Unit_Name
)
6223 Set_Body_Needed_For_SAL
(Unit_Name
);
6225 elsif Ekind
(Unit_Name
) = E_Package_Body
6226 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6228 Check_Body_Needed_For_SAL
6229 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6231 end Check_Body_Needed_For_SAL
;
6233 --------------------
6234 -- Remove_Context --
6235 --------------------
6237 procedure Remove_Context
(N
: Node_Id
) is
6238 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6241 -- If this is a child unit, first remove the parent units
6243 if Is_Child_Spec
(Lib_Unit
) then
6244 Remove_Parents
(Lib_Unit
);
6247 Remove_Context_Clauses
(N
);
6250 ----------------------------
6251 -- Remove_Context_Clauses --
6252 ----------------------------
6254 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6256 Unit_Name
: Entity_Id
;
6259 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6260 -- limited-views first and regular-views later (to maintain the
6263 -- First Phase: Remove limited_with context clauses
6265 Item
:= First
(Context_Items
(N
));
6266 while Present
(Item
) loop
6268 -- We are interested only in with clauses which got installed
6271 if Nkind
(Item
) = N_With_Clause
6272 and then Limited_Present
(Item
)
6273 and then Limited_View_Installed
(Item
)
6275 Remove_Limited_With_Clause
(Item
);
6281 -- Second Phase: Loop through context items and undo regular
6282 -- with_clauses and use_clauses.
6284 Item
:= First
(Context_Items
(N
));
6285 while Present
(Item
) loop
6287 -- We are interested only in with clauses which got installed on
6288 -- entry, as indicated by their Context_Installed flag set
6290 if Nkind
(Item
) = N_With_Clause
6291 and then Limited_Present
(Item
)
6292 and then Limited_View_Installed
(Item
)
6296 elsif Nkind
(Item
) = N_With_Clause
6297 and then Context_Installed
(Item
)
6299 -- Remove items from one with'ed unit
6301 Unit_Name
:= Entity
(Name
(Item
));
6302 Remove_Unit_From_Visibility
(Unit_Name
);
6303 Set_Context_Installed
(Item
, False);
6305 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6306 End_Use_Package
(Item
);
6308 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6309 End_Use_Type
(Item
);
6314 end Remove_Context_Clauses
;
6316 --------------------------------
6317 -- Remove_Limited_With_Clause --
6318 --------------------------------
6320 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6321 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6324 Lim_Header
: Entity_Id
;
6325 Lim_Typ
: Entity_Id
;
6329 pragma Assert
(Limited_View_Installed
(N
));
6331 -- In case of limited with_clause on subprograms, generics, instances,
6332 -- or renamings, the corresponding error was previously posted and we
6333 -- have nothing to do here.
6335 if Nkind
(P_Unit
) /= N_Package_Declaration
then
6339 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
6341 -- Handle child packages
6343 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
6344 P
:= Defining_Identifier
(P
);
6347 if Debug_Flag_I
then
6348 Write_Str
("remove limited view of ");
6349 Write_Name
(Chars
(P
));
6350 Write_Str
(" from visibility");
6354 -- Prepare the removal of the shadow entities from visibility. The first
6355 -- element of the limited view is a header (an E_Package entity) that is
6356 -- used to reference the first shadow entity in the private part of the
6359 Lim_Header
:= Limited_View
(P
);
6360 Lim_Typ
:= First_Entity
(Lim_Header
);
6362 -- Remove package and shadow entities from visibility if it has not
6365 if not Analyzed
(P_Unit
) then
6367 Set_Is_Immediately_Visible
(P
, False);
6369 while Present
(Lim_Typ
) loop
6371 Next_Entity
(Lim_Typ
);
6374 -- Otherwise this package has already appeared in the closure and its
6375 -- shadow entities must be replaced by its real entities. This code
6376 -- must be kept synchronized with the complementary code in Install
6377 -- Limited_Withed_Unit.
6380 -- Real entities that are type or subtype declarations were hidden
6381 -- from visibility at the point of installation of the limited-view.
6382 -- Now we recover the previous value of the hidden attribute.
6384 E
:= First_Entity
(P
);
6385 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
6387 Set_Is_Hidden
(E
, Was_Hidden
(E
));
6393 while Present
(Lim_Typ
)
6394 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
6396 -- Nested packages and child units were not unchained
6398 if Ekind
(Lim_Typ
) /= E_Package
6399 and then not Is_Child_Unit
(Non_Limited_View
(Lim_Typ
))
6401 -- If the package has incomplete types, the limited view of the
6402 -- incomplete type is in fact never visible (AI05-129) but we
6403 -- have created a shadow entity E1 for it, that points to E2,
6404 -- a non-limited incomplete type. This in turn has a full view
6405 -- E3 that is the full declaration. There is a corresponding
6406 -- shadow entity E4. When reinstalling the non-limited view,
6407 -- E2 must become the current entity and E3 must be ignored.
6409 E
:= Non_Limited_View
(Lim_Typ
);
6411 if Present
(Current_Entity
(E
))
6412 and then Ekind
(Current_Entity
(E
)) = E_Incomplete_Type
6413 and then Full_View
(Current_Entity
(E
)) = E
6416 -- Lim_Typ is the limited view of a full type declaration
6417 -- that has a previous incomplete declaration, i.e. E3 from
6418 -- the previous description. Nothing to insert.
6423 pragma Assert
(not In_Chain
(E
));
6425 Prev
:= Current_Entity
(Lim_Typ
);
6427 if Prev
= Lim_Typ
then
6428 Set_Current_Entity
(E
);
6431 while Present
(Prev
)
6432 and then Homonym
(Prev
) /= Lim_Typ
6434 Prev
:= Homonym
(Prev
);
6437 if Present
(Prev
) then
6438 Set_Homonym
(Prev
, E
);
6442 -- Preserve structure of homonym chain
6444 Set_Homonym
(E
, Homonym
(Lim_Typ
));
6448 Next_Entity
(Lim_Typ
);
6452 -- Indicate that the limited view of the package is not installed
6454 Set_From_Limited_With
(P
, False);
6455 Set_Limited_View_Installed
(N
, False);
6456 end Remove_Limited_With_Clause
;
6458 --------------------
6459 -- Remove_Parents --
6460 --------------------
6462 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
6465 P_Spec
: Node_Id
:= Empty
;
6467 Vis
: constant Boolean :=
6468 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
6471 if Is_Child_Spec
(Lib_Unit
) then
6472 P_Spec
:= Parent_Spec
(Lib_Unit
);
6474 elsif Nkind
(Lib_Unit
) = N_Package_Body
6475 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
6477 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
6480 if Present
(P_Spec
) then
6482 P_Name
:= Get_Parent_Entity
(P
);
6483 Remove_Context_Clauses
(P_Spec
);
6484 End_Package_Scope
(P_Name
);
6485 Set_Is_Immediately_Visible
(P_Name
, Vis
);
6487 -- Remove from visibility the siblings as well, which are directly
6488 -- visible while the parent is in scope.
6490 E
:= First_Entity
(P_Name
);
6491 while Present
(E
) loop
6492 if Is_Child_Unit
(E
) then
6493 Set_Is_Immediately_Visible
(E
, False);
6499 Set_In_Package_Body
(P_Name
, False);
6501 -- This is the recursive call to remove the context of any higher
6502 -- level parent. This recursion ensures that all parents are removed
6503 -- in the reverse order of their installation.
6509 ---------------------------------
6510 -- Remove_Private_With_Clauses --
6511 ---------------------------------
6513 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
6516 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
6517 -- Check whether a given unit appears in a regular with_clause. Used to
6518 -- determine whether a private_with_clause, implicit or explicit, should
6521 ----------------------------
6522 -- In_Regular_With_Clause --
6523 ----------------------------
6525 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean
6530 Item
:= First
(Context_Items
(Comp_Unit
));
6531 while Present
(Item
) loop
6532 if Nkind
(Item
) = N_With_Clause
6534 -- The following guard is needed to ensure that the name has
6535 -- been properly analyzed before we go fetching its entity.
6537 and then Is_Entity_Name
(Name
(Item
))
6538 and then Entity
(Name
(Item
)) = E
6539 and then not Private_Present
(Item
)
6547 end In_Regular_With_Clause
;
6549 -- Start of processing for Remove_Private_With_Clauses
6552 Item
:= First
(Context_Items
(Comp_Unit
));
6553 while Present
(Item
) loop
6554 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
6556 -- If private_with_clause is redundant, remove it from context,
6557 -- as a small optimization to subsequent handling of private_with
6558 -- clauses in other nested packages.
6560 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
6562 Nxt
: constant Node_Id
:= Next
(Item
);
6568 elsif Limited_Present
(Item
) then
6569 if not Limited_View_Installed
(Item
) then
6570 Remove_Limited_With_Clause
(Item
);
6576 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
6577 Set_Context_Installed
(Item
, False);
6585 end Remove_Private_With_Clauses
;
6587 ---------------------------------
6588 -- Remove_Unit_From_Visibility --
6589 ---------------------------------
6591 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
6593 if Debug_Flag_I
then
6594 Write_Str
("remove unit ");
6595 Write_Name
(Chars
(Unit_Name
));
6596 Write_Str
(" from visibility");
6600 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
6601 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
6602 Set_Is_Immediately_Visible
(Unit_Name
, False);
6604 -- If the unit is a wrapper package, the subprogram instance is
6605 -- what must be removed from visibility.
6606 -- Should we use Related_Instance instead???
6608 if Is_Wrapper_Package
(Unit_Name
) then
6609 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
6611 end Remove_Unit_From_Visibility
;
6626 procedure Unchain
(E
: Entity_Id
) is
6630 Prev
:= Current_Entity
(E
);
6636 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6639 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
6640 Prev
:= Homonym
(Prev
);
6643 if Present
(Prev
) then
6644 Set_Homonym
(Prev
, Homonym
(E
));
6648 if Debug_Flag_I
then
6649 Write_Str
(" (homonym) unchain ");
6650 Write_Name
(Chars
(E
));