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_Mapped
(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_Ekind
(Defining_Entity
(N
), E_Package_Body
);
1594 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1595 Generate_Reference
(Nam
, Id
, 'b');
1596 Analyze_Proper_Body
(N
, Nam
);
1598 Restore_Opt_Config_Switches
(Opts
);
1600 end Analyze_Package_Body_Stub
;
1602 -------------------------
1603 -- Analyze_Proper_Body --
1604 -------------------------
1606 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1607 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1609 procedure Optional_Subunit
;
1610 -- This procedure is called when the main unit is a stub, or when we
1611 -- are not generating code. In such a case, we analyze the subunit if
1612 -- present, which is user-friendly and in fact required for ASIS, but we
1613 -- don't complain if the subunit is missing. In GNATprove_Mode, we issue
1614 -- an error to avoid formal verification of a partial unit.
1616 ----------------------
1617 -- Optional_Subunit --
1618 ----------------------
1620 procedure Optional_Subunit
is
1621 Comp_Unit
: Node_Id
;
1622 Unum
: Unit_Number_Type
;
1625 -- Try to load subunit, but ignore any errors that occur during the
1626 -- loading of the subunit, by using the special feature in Errout to
1627 -- ignore all errors. Note that Fatal_Error will still be set, so we
1628 -- will be able to check for this case below.
1630 if not (ASIS_Mode
or GNATprove_Mode
) then
1631 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1636 (Load_Name
=> Subunit_Name
,
1637 Required
=> GNATprove_Mode
,
1641 if not (ASIS_Mode
or GNATprove_Mode
) then
1642 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1645 -- All done if we successfully loaded the subunit
1648 and then (Fatal_Error
(Unum
) /= Error_Detected
1649 or else Try_Semantics
)
1651 Comp_Unit
:= Cunit
(Unum
);
1653 -- If the file was empty or seriously mangled, the unit itself may
1656 if No
(Unit
(Comp_Unit
)) then
1658 ("subunit does not contain expected proper body", N
);
1660 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1662 ("expected SEPARATE subunit, found child unit",
1663 Cunit_Entity
(Unum
));
1665 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1666 Analyze_Subunit
(Comp_Unit
);
1667 Set_Library_Unit
(N
, Comp_Unit
);
1668 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1671 elsif Unum
= No_Unit
1672 and then Present
(Nam
)
1674 if Is_Protected_Type
(Nam
) then
1675 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1677 Set_Corresponding_Body
(
1678 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1681 end Optional_Subunit
;
1685 Comp_Unit
: Node_Id
;
1686 Unum
: Unit_Number_Type
;
1688 -- Start of processing for Analyze_Proper_Body
1691 -- If the subunit is already loaded, it means that the main unit is a
1692 -- subunit, and that the current unit is one of its parents which was
1693 -- being analyzed to provide the needed context for the analysis of the
1694 -- subunit. In this case we analyze the subunit and continue with the
1695 -- parent, without looking at subsequent subunits.
1697 if Is_Loaded
(Subunit_Name
) then
1699 -- If the proper body is already linked to the stub node, the stub is
1700 -- in a generic unit and just needs analyzing.
1702 if Present
(Library_Unit
(N
)) then
1703 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1705 -- If the subunit has severe errors, the spec of the enclosing
1706 -- body may not be available, in which case do not try analysis.
1708 if Serious_Errors_Detected
> 0
1709 and then No
(Library_Unit
(Library_Unit
(N
)))
1714 -- Collect SCO information for loaded subunit if we are in the
1715 -- extended main unit.
1718 and then In_Extended_Main_Source_Unit
1719 (Cunit_Entity
(Current_Sem_Unit
))
1721 SCO_Record_Raw
(Get_Cunit_Unit_Number
(Library_Unit
(N
)));
1724 Analyze_Subunit
(Library_Unit
(N
));
1726 -- Otherwise we must load the subunit and link to it
1729 -- Load the subunit, this must work, since we originally loaded
1730 -- the subunit earlier on. So this will not really load it, just
1731 -- give access to it.
1735 (Load_Name
=> Subunit_Name
,
1740 -- And analyze the subunit in the parent context (note that we
1741 -- do not call Semantics, since that would remove the parent
1742 -- context). Because of this, we have to manually reset the
1743 -- compiler state to Analyzing since it got destroyed by Load.
1745 if Unum
/= No_Unit
then
1746 Compiler_State
:= Analyzing
;
1748 -- Check that the proper body is a subunit and not a child
1749 -- unit. If the unit was previously loaded, the error will
1750 -- have been emitted when copying the generic node, so we
1751 -- just return to avoid cascaded errors.
1753 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1757 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1758 Analyze_Subunit
(Cunit
(Unum
));
1759 Set_Library_Unit
(N
, Cunit
(Unum
));
1763 -- If the main unit is a subunit, then we are just performing semantic
1764 -- analysis on that subunit, and any other subunits of any parent unit
1765 -- should be ignored, except that if we are building trees for ASIS
1766 -- usage we want to annotate the stub properly. If the main unit is
1767 -- itself a subunit, another subunit is irrelevant unless it is a
1768 -- subunit of the current one, that is to say appears in the current
1771 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1772 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1776 PB
: constant Node_Id
:= Proper_Body
(Unit
(Cunit
(Main_Unit
)));
1778 if Nkind_In
(PB
, N_Package_Body
, N_Subprogram_Body
)
1779 and then List_Containing
(N
) = Declarations
(PB
)
1786 -- But before we return, set the flag for unloaded subunits. This
1787 -- will suppress junk warnings of variables in the same declarative
1788 -- part (or a higher level one) that are in danger of looking unused
1789 -- when in fact there might be a declaration in the subunit that we
1790 -- do not intend to load.
1792 Unloaded_Subunits
:= True;
1795 -- If the subunit is not already loaded, and we are generating code,
1796 -- then this is the case where compilation started from the parent, and
1797 -- we are generating code for an entire subunit tree. In that case we
1798 -- definitely need to load the subunit.
1800 -- In order to continue the analysis with the rest of the parent,
1801 -- and other subunits, we load the unit without requiring its
1802 -- presence, and emit a warning if not found, rather than terminating
1803 -- the compilation abruptly, as for other missing file problems.
1805 elsif Original_Operating_Mode
= Generate_Code
then
1807 -- If the proper body is already linked to the stub node, the stub is
1808 -- in a generic unit and just needs analyzing.
1810 -- We update the version. Although we are not strictly technically
1811 -- semantically dependent on the subunit, given our approach of macro
1812 -- substitution of subunits, it makes sense to include it in the
1813 -- version identification.
1815 if Present
(Library_Unit
(N
)) then
1816 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1817 Analyze_Subunit
(Library_Unit
(N
));
1818 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1820 -- Otherwise we must load the subunit and link to it
1823 -- Make sure that, if the subunit is preprocessed and -gnateG is
1824 -- specified, the preprocessed file will be written.
1826 Lib
.Analysing_Subunit_Of_Main
:= True;
1829 (Load_Name
=> Subunit_Name
,
1833 Lib
.Analysing_Subunit_Of_Main
:= False;
1835 -- Give message if we did not get the unit Emit warning even if
1836 -- missing subunit is not within main unit, to simplify debugging.
1838 pragma Assert
(Original_Operating_Mode
= Generate_Code
);
1839 if Unum
= No_Unit
then
1840 Error_Msg_Unit_1
:= Subunit_Name
;
1842 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1844 ("subunit$$ in file{ not found??!!", N
);
1845 Subunits_Missing
:= True;
1848 -- Load_Unit may reset Compiler_State, since it may have been
1849 -- necessary to parse an additional units, so we make sure that
1850 -- we reset it to the Analyzing state.
1852 Compiler_State
:= Analyzing
;
1854 if Unum
/= No_Unit
then
1855 if Debug_Flag_L
then
1856 Write_Str
("*** Loaded subunit from stub. Analyze");
1860 Comp_Unit
:= Cunit
(Unum
);
1862 -- Check for child unit instead of subunit
1864 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1866 ("expected SEPARATE subunit, found child unit",
1867 Cunit_Entity
(Unum
));
1869 -- OK, we have a subunit
1872 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1873 Set_Library_Unit
(N
, Comp_Unit
);
1875 -- We update the version. Although we are not technically
1876 -- semantically dependent on the subunit, given our approach
1877 -- of macro substitution of subunits, it makes sense to
1878 -- include it in the version identification.
1880 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1882 -- Collect SCO information for loaded subunit if we are in
1883 -- the extended main unit.
1886 and then In_Extended_Main_Source_Unit
1887 (Cunit_Entity
(Current_Sem_Unit
))
1889 SCO_Record_Raw
(Unum
);
1892 -- Analyze the unit if semantics active
1894 if Fatal_Error
(Unum
) /= Error_Detected
1895 or else Try_Semantics
1897 Analyze_Subunit
(Comp_Unit
);
1903 -- The remaining case is when the subunit is not already loaded and we
1904 -- are not generating code. In this case we are just performing semantic
1905 -- analysis on the parent, and we are not interested in the subunit. For
1906 -- subprograms, analyze the stub as a body. For other entities the stub
1907 -- has already been marked as completed.
1912 end Analyze_Proper_Body
;
1914 ----------------------------------
1915 -- Analyze_Protected_Body_Stub --
1916 ----------------------------------
1918 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
1919 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
1922 Check_Stub_Level
(N
);
1924 -- First occurrence of name may have been as an incomplete type
1926 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
1927 Nam
:= Full_View
(Nam
);
1930 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
1931 Error_Msg_N
("missing specification for Protected body", N
);
1934 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1935 Set_Ekind
(Defining_Entity
(N
), E_Protected_Body
);
1936 Set_Has_Completion
(Etype
(Nam
));
1937 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1938 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
1939 Analyze_Proper_Body
(N
, Etype
(Nam
));
1941 end Analyze_Protected_Body_Stub
;
1943 ----------------------------------
1944 -- Analyze_Subprogram_Body_Stub --
1945 ----------------------------------
1947 -- A subprogram body stub can appear with or without a previous spec. If
1948 -- there is one, then the analysis of the body will find it and verify
1949 -- conformance. The formals appearing in the specification of the stub play
1950 -- no role, except for requiring an additional conformance check. If there
1951 -- is no previous subprogram declaration, the stub acts as a spec, and
1952 -- provides the defining entity for the subprogram.
1954 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
1956 Opts
: Config_Switches_Type
;
1959 Check_Stub_Level
(N
);
1961 -- Verify that the identifier for the stub is unique within this
1962 -- declarative part.
1964 if Nkind_In
(Parent
(N
), N_Block_Statement
,
1968 Decl
:= First
(Declarations
(Parent
(N
)));
1969 while Present
(Decl
) and then Decl
/= N
loop
1970 if Nkind
(Decl
) = N_Subprogram_Body_Stub
1971 and then (Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
1972 Chars
(Defining_Unit_Name
(Specification
(N
))))
1974 Error_Msg_N
("identifier for stub is not unique", N
);
1981 -- Retain and restore the configuration options of the enclosing context
1982 -- as the proper body may introduce a set of its own.
1984 Save_Opt_Config_Switches
(Opts
);
1986 -- Treat stub as a body, which checks conformance if there is a previous
1987 -- declaration, or else introduces entity and its signature.
1989 Analyze_Subprogram_Body
(N
);
1990 Analyze_Proper_Body
(N
, Empty
);
1992 Restore_Opt_Config_Switches
(Opts
);
1993 end Analyze_Subprogram_Body_Stub
;
1995 ---------------------
1996 -- Analyze_Subunit --
1997 ---------------------
1999 -- A subunit is compiled either by itself (for semantic checking) or as
2000 -- part of compiling the parent (for code generation). In either case, by
2001 -- the time we actually process the subunit, the parent has already been
2002 -- installed and analyzed. The node N is a compilation unit, whose context
2003 -- needs to be treated here, because we come directly here from the parent
2004 -- without calling Analyze_Compilation_Unit.
2006 -- The compilation context includes the explicit context of the subunit,
2007 -- and the context of the parent, together with the parent itself. In order
2008 -- to compile the current context, we remove the one inherited from the
2009 -- parent, in order to have a clean visibility table. We restore the parent
2010 -- context before analyzing the proper body itself. On exit, we remove only
2011 -- the explicit context of the subunit.
2013 procedure Analyze_Subunit
(N
: Node_Id
) is
2014 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2015 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2017 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2018 Num_Scopes
: Nat
:= 0;
2019 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2020 Enclosing_Child
: Entity_Id
:= Empty
;
2021 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2023 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2024 Cunit_Boolean_Restrictions_Save
;
2025 -- Save non-partition wide restrictions before processing the subunit.
2026 -- All subunits are analyzed with config restrictions reset and we need
2027 -- to restore these saved values at the end.
2029 procedure Analyze_Subunit_Context
;
2030 -- Capture names in use clauses of the subunit. This must be done before
2031 -- re-installing parent declarations, because items in the context must
2032 -- not be hidden by declarations local to the parent.
2034 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2035 -- Recursive procedure to restore scope of all ancestors of subunit,
2036 -- from outermost in. If parent is not a subunit, the call to install
2037 -- context installs context of spec and (if parent is a child unit) the
2038 -- context of its parents as well. It is confusing that parents should
2039 -- be treated differently in both cases, but the semantics are just not
2042 procedure Re_Install_Use_Clauses
;
2043 -- As part of the removal of the parent scope, the use clauses are
2044 -- removed, to be reinstalled when the context of the subunit has been
2045 -- analyzed. Use clauses may also have been affected by the analysis of
2046 -- the context of the subunit, so they have to be applied again, to
2047 -- insure that the compilation environment of the rest of the parent
2048 -- unit is identical.
2050 procedure Remove_Scope
;
2051 -- Remove current scope from scope stack, and preserve the list of use
2052 -- clauses in it, to be reinstalled after context is analyzed.
2054 -----------------------------
2055 -- Analyze_Subunit_Context --
2056 -----------------------------
2058 procedure Analyze_Subunit_Context
is
2061 Unit_Name
: Entity_Id
;
2064 Analyze_Context
(N
);
2065 Check_No_Elab_Code_All
(N
);
2067 -- Make withed units immediately visible. If child unit, make the
2068 -- ultimate parent immediately visible.
2070 Item
:= First
(Context_Items
(N
));
2071 while Present
(Item
) loop
2072 if Nkind
(Item
) = N_With_Clause
then
2074 -- Protect frontend against previous errors in context clauses
2076 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2077 if Error_Posted
(Item
) then
2081 -- If a subunits has serious syntax errors, the context
2082 -- may not have been loaded. Add a harmless unit name to
2083 -- attempt processing.
2085 if Serious_Errors_Detected
> 0
2086 and then No
(Entity
(Name
(Item
)))
2088 Set_Entity
(Name
(Item
), Standard_Standard
);
2091 Unit_Name
:= Entity
(Name
(Item
));
2093 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2094 exit when Scope
(Unit_Name
) = Standard_Standard
;
2095 Unit_Name
:= Scope
(Unit_Name
);
2097 if No
(Unit_Name
) then
2098 Check_Error_Detected
;
2103 if not Is_Immediately_Visible
(Unit_Name
) then
2104 Set_Is_Immediately_Visible
(Unit_Name
);
2105 Set_Context_Installed
(Item
);
2110 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2111 Nam
:= First
(Names
(Item
));
2112 while Present
(Nam
) loop
2117 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2118 Nam
:= First
(Subtype_Marks
(Item
));
2119 while Present
(Nam
) loop
2128 -- Reset visibility of withed units. They will be made visible again
2129 -- when we install the subunit context.
2131 Item
:= First
(Context_Items
(N
));
2132 while Present
(Item
) loop
2133 if Nkind
(Item
) = N_With_Clause
2135 -- Protect frontend against previous errors in context clauses
2137 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2138 and then not Error_Posted
(Item
)
2140 Unit_Name
:= Entity
(Name
(Item
));
2142 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2143 exit when Scope
(Unit_Name
) = Standard_Standard
;
2144 Unit_Name
:= Scope
(Unit_Name
);
2147 if Context_Installed
(Item
) then
2148 Set_Is_Immediately_Visible
(Unit_Name
, False);
2149 Set_Context_Installed
(Item
, False);
2155 end Analyze_Subunit_Context
;
2157 ------------------------
2158 -- Re_Install_Parents --
2159 ------------------------
2161 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2165 if Nkind
(Unit
(L
)) = N_Subunit
then
2166 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2169 Install_Context
(L
);
2171 -- If the subunit occurs within a child unit, we must restore the
2172 -- immediate visibility of any siblings that may occur in context.
2174 if Present
(Enclosing_Child
) then
2175 Install_Siblings
(Enclosing_Child
, L
);
2180 if Scop
/= Par_Unit
then
2181 Set_Is_Immediately_Visible
(Scop
);
2184 -- Make entities in scope visible again. For child units, restore
2185 -- visibility only if they are actually in context.
2187 E
:= First_Entity
(Current_Scope
);
2188 while Present
(E
) loop
2189 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2190 Set_Is_Immediately_Visible
(E
);
2196 -- A subunit appears within a body, and for a nested subunits all the
2197 -- parents are bodies. Restore full visibility of their private
2200 if Is_Package_Or_Generic_Package
(Scop
) then
2201 Set_In_Package_Body
(Scop
);
2202 Install_Private_Declarations
(Scop
);
2204 end Re_Install_Parents
;
2206 ----------------------------
2207 -- Re_Install_Use_Clauses --
2208 ----------------------------
2210 procedure Re_Install_Use_Clauses
is
2213 for J
in reverse 1 .. Num_Scopes
loop
2214 U
:= Use_Clauses
(J
);
2215 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2216 Install_Use_Clauses
(U
, Force_Installation
=> True);
2218 end Re_Install_Use_Clauses
;
2224 procedure Remove_Scope
is
2228 Num_Scopes
:= Num_Scopes
+ 1;
2229 Use_Clauses
(Num_Scopes
) :=
2230 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2232 E
:= First_Entity
(Current_Scope
);
2233 while Present
(E
) loop
2234 Set_Is_Immediately_Visible
(E
, False);
2238 if Is_Child_Unit
(Current_Scope
) then
2239 Enclosing_Child
:= Current_Scope
;
2245 -- Start of processing for Analyze_Subunit
2248 -- For subunit in main extended unit, we reset the configuration values
2249 -- for the non-partition-wide restrictions. For other units reset them.
2251 if In_Extended_Main_Source_Unit
(N
) then
2252 Restore_Config_Cunit_Boolean_Restrictions
;
2254 Reset_Cunit_Boolean_Restrictions
;
2259 Nam
: Node_Id
:= Name
(Unit
(N
));
2262 if Nkind
(Nam
) = N_Selected_Component
then
2263 Nam
:= Selector_Name
(Nam
);
2266 Check_Identifier
(Nam
, Par_Unit
);
2270 if not Is_Empty_List
(Context_Items
(N
)) then
2272 -- Save current use clauses
2275 Remove_Context
(Lib_Unit
);
2277 -- Now remove parents and their context, including enclosing subunits
2278 -- and the outer parent body which is not a subunit.
2280 if Present
(Lib_Spec
) then
2281 Remove_Context
(Lib_Spec
);
2283 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2284 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2286 Remove_Context
(Lib_Spec
);
2289 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2293 if Nkind
(Unit
(Lib_Spec
)) = N_Package_Body
then
2294 Remove_Context
(Library_Unit
(Lib_Spec
));
2298 Set_Is_Immediately_Visible
(Par_Unit
, False);
2300 Analyze_Subunit_Context
;
2302 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2303 Set_Is_Immediately_Visible
(Par_Unit
);
2305 -- If the context includes a child unit of the parent of the subunit,
2306 -- the parent will have been removed from visibility, after compiling
2307 -- that cousin in the context. The visibility of the parent must be
2308 -- restored now. This also applies if the context includes another
2309 -- subunit of the same parent which in turn includes a child unit in
2312 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2313 if not Is_Immediately_Visible
(Par_Unit
)
2314 or else (Present
(First_Entity
(Par_Unit
))
2316 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2318 Set_Is_Immediately_Visible
(Par_Unit
);
2319 Install_Visible_Declarations
(Par_Unit
);
2320 Install_Private_Declarations
(Par_Unit
);
2324 Re_Install_Use_Clauses
;
2325 Install_Context
(N
);
2327 -- Restore state of suppress flags for current body
2329 Scope_Suppress
:= Svg
;
2331 -- If the subunit is within a child unit, then siblings of any parent
2332 -- unit that appear in the context clause of the subunit must also be
2333 -- made immediately visible.
2335 if Present
(Enclosing_Child
) then
2336 Install_Siblings
(Enclosing_Child
, N
);
2340 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2341 Analyze
(Proper_Body
(Unit
(N
)));
2344 -- The subunit may contain a with_clause on a sibling of some ancestor.
2345 -- Removing the context will remove from visibility those ancestor child
2346 -- units, which must be restored to the visibility they have in the
2349 if Present
(Enclosing_Child
) then
2354 while Present
(C
) and then C
/= Standard_Standard
loop
2355 Set_Is_Immediately_Visible
(C
);
2356 Set_Is_Visible_Lib_Unit
(C
);
2362 -- Deal with restore of restrictions
2364 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2365 end Analyze_Subunit
;
2367 ----------------------------
2368 -- Analyze_Task_Body_Stub --
2369 ----------------------------
2371 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2372 Loc
: constant Source_Ptr
:= Sloc
(N
);
2373 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
2376 Check_Stub_Level
(N
);
2378 -- First occurrence of name may have been as an incomplete type
2380 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2381 Nam
:= Full_View
(Nam
);
2384 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2385 Error_Msg_N
("missing specification for task body", N
);
2388 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
2389 Set_Ekind
(Defining_Entity
(N
), E_Task_Body
);
2390 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
2391 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2393 -- Check for duplicate stub, if so give message and terminate
2395 if Has_Completion
(Etype
(Nam
)) then
2396 Error_Msg_N
("duplicate stub for task", N
);
2399 Set_Has_Completion
(Etype
(Nam
));
2402 Analyze_Proper_Body
(N
, Etype
(Nam
));
2404 -- Set elaboration flag to indicate that entity is callable. This
2405 -- cannot be done in the expansion of the body itself, because the
2406 -- proper body is not in a declarative part. This is only done if
2407 -- expansion is active, because the context may be generic and the
2408 -- flag not defined yet.
2410 if Expander_Active
then
2412 Make_Assignment_Statement
(Loc
,
2414 Make_Identifier
(Loc
,
2415 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2416 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2419 end Analyze_Task_Body_Stub
;
2421 -------------------------
2422 -- Analyze_With_Clause --
2423 -------------------------
2425 -- Analyze the declaration of a unit in a with clause. At end, label the
2426 -- with clause with the defining entity for the unit.
2428 procedure Analyze_With_Clause
(N
: Node_Id
) is
2430 -- Retrieve the original kind of the unit node, before analysis. If it
2431 -- is a subprogram instantiation, its analysis below will rewrite the
2432 -- node as the declaration of the wrapper package. If the same
2433 -- instantiation appears indirectly elsewhere in the context, it will
2434 -- have been analyzed already.
2436 Unit_Kind
: constant Node_Kind
:=
2437 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2438 Nam
: constant Node_Id
:= Name
(N
);
2440 Par_Name
: Entity_Id
;
2445 -- Set True if the unit currently being compiled is an internal unit
2447 Restriction_Violation
: Boolean := False;
2448 -- Set True if a with violates a restriction, no point in giving any
2449 -- warnings if we have this definite error.
2451 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2454 U
:= Unit
(Library_Unit
(N
));
2456 -- If this is an internal unit which is a renaming, then this is a
2457 -- violation of No_Obsolescent_Features.
2459 -- Note: this is not quite right if the user defines one of these units
2460 -- himself, but that's a marginal case, and fixing it is hard ???
2462 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2464 F
: constant File_Name_Type
:=
2465 Unit_File_Name
(Get_Source_Unit
(U
));
2467 if Is_Predefined_File_Name
(F
, Renamings_Included
=> True)
2469 Is_Predefined_File_Name
(F
, Renamings_Included
=> False)
2471 Check_Restriction
(No_Obsolescent_Features
, N
);
2472 Restriction_Violation
:= True;
2477 -- Check No_Implementation_Units violation
2479 if Restriction_Check_Required
(No_Implementation_Units
) then
2480 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2483 Check_Restriction
(No_Implementation_Units
, Nam
);
2484 Restriction_Violation
:= True;
2488 -- Several actions are skipped for dummy packages (those supplied for
2489 -- with's where no matching file could be found). Such packages are
2490 -- identified by the Sloc value being set to No_Location.
2492 if Limited_Present
(N
) then
2494 -- Ada 2005 (AI-50217): Build visibility structures but do not
2495 -- analyze the unit.
2497 -- If the designated unit is a predefined unit, which might be used
2498 -- implicitly through the rtsfind machinery, a limited with clause
2499 -- on such a unit is usually pointless, because run-time units are
2500 -- unlikely to appear in mutually dependent units, and because this
2501 -- disables the rtsfind mechanism. We transform such limited with
2502 -- clauses into regular with clauses.
2504 if Sloc
(U
) /= No_Location
then
2505 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2507 -- In ASIS mode the rtsfind mechanism plays no role, and
2508 -- we need to maintain the original tree structure, so
2509 -- this transformation is not performed in this case.
2511 and then not ASIS_Mode
2513 Set_Limited_Present
(N
, False);
2514 Analyze_With_Clause
(N
);
2516 Build_Limited_Views
(N
);
2523 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2524 -- already detected serious errors then we mark the with-clause nodes as
2525 -- analyzed before the corresponding compilation unit is analyzed. This
2526 -- is done here to protect the frontend against never ending recursion
2527 -- caused by circularities in the sources (because the previous errors
2528 -- may break the regular machine of the compiler implemented in
2529 -- Load_Unit to detect circularities).
2531 if Serious_Errors_Detected
> 0 and then Try_Semantics
then
2535 -- If the library unit is a predefined unit, and we are in high
2536 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
2537 -- for the analysis of the with'ed unit. This mode does not prevent
2538 -- explicit with'ing of run-time units.
2540 if Configurable_Run_Time_Mode
2541 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2543 Configurable_Run_Time_Mode
:= False;
2544 Semantics
(Library_Unit
(N
));
2545 Configurable_Run_Time_Mode
:= True;
2548 Semantics
(Library_Unit
(N
));
2551 Intunit
:= Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
));
2553 if Sloc
(U
) /= No_Location
then
2555 -- Check restrictions, except that we skip the check if this is an
2556 -- internal unit unless we are compiling the internal unit as the
2557 -- main unit. We also skip this for dummy packages.
2559 Check_Restriction_No_Dependence
(Nam
, N
);
2561 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2562 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2565 -- Deal with special case of GNAT.Current_Exceptions which interacts
2566 -- with the optimization of local raise statements into gotos.
2568 if Nkind
(Nam
) = N_Selected_Component
2569 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2570 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2571 and then Nam_In
(Chars
(Selector_Name
(Nam
)),
2572 Name_Most_Recent_Exception
,
2573 Name_Exception_Traces
)
2575 Check_Restriction
(No_Exception_Propagation
, N
);
2576 Special_Exception_Package_Used
:= True;
2579 -- Check for inappropriate with of internal implementation unit if we
2580 -- are not compiling an internal unit and also check for withing unit
2581 -- in wrong version of Ada. Do not issue these messages for implicit
2582 -- with's generated by the compiler itself.
2584 if Implementation_Unit_Warnings
2585 and then not Intunit
2586 and then not Implicit_With
(N
)
2587 and then not Restriction_Violation
2590 U_Kind
: constant Kind_Of_Unit
:=
2591 Get_Kind_Of_Unit
(Get_Source_Unit
(U
));
2594 if U_Kind
= Implementation_Unit
then
2595 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2597 -- Add alternative name if available, otherwise issue a
2598 -- general warning message.
2600 if Error_Msg_Strlen
/= 0 then
2601 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2604 ("\use of this unit is non-portable " &
2605 "and version-dependent?i?", Name
(N
));
2608 elsif U_Kind
= Ada_2005_Unit
2609 and then Ada_Version
< Ada_2005
2610 and then Warn_On_Ada_2005_Compatibility
2612 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2614 elsif U_Kind
= Ada_2012_Unit
2615 and then Ada_Version
< Ada_2012
2616 and then Warn_On_Ada_2012_Compatibility
2618 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2624 -- Semantic analysis of a generic unit is performed on a copy of
2625 -- the original tree. Retrieve the entity on which semantic info
2626 -- actually appears.
2628 if Unit_Kind
in N_Generic_Declaration
then
2629 E_Name
:= Defining_Entity
(U
);
2631 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2632 -- the case of an instantiation, semantic analysis above will have
2633 -- replaced the unit by its instantiated version. If the instance body
2634 -- has been generated, the instance now denotes the body entity. For
2635 -- visibility purposes we need the entity of its spec.
2637 elsif (Unit_Kind
= N_Package_Instantiation
2638 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2639 N_Package_Instantiation
)
2640 and then Nkind
(U
) = N_Package_Body
2642 E_Name
:= Corresponding_Spec
(U
);
2644 elsif Unit_Kind
= N_Package_Instantiation
2645 and then Nkind
(U
) = N_Package_Instantiation
2646 and then Present
(Instance_Spec
(U
))
2648 -- If the instance has not been rewritten as a package declaration,
2649 -- then it appeared already in a previous with clause. Retrieve
2650 -- the entity from the previous instance.
2652 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2654 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2656 -- The visible subprogram is created during instantiation, and is
2657 -- an attribute of the wrapper package. We retrieve the wrapper
2658 -- package directly from the instantiation node. If the instance
2659 -- is inlined the unit is still an instantiation. Otherwise it has
2660 -- been rewritten as the declaration of the wrapper itself.
2662 if Nkind
(U
) in N_Subprogram_Instantiation
then
2665 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2667 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2670 elsif Unit_Kind
= N_Package_Renaming_Declaration
2671 or else Unit_Kind
in N_Generic_Renaming_Declaration
2673 E_Name
:= Defining_Entity
(U
);
2675 elsif Unit_Kind
= N_Subprogram_Body
2676 and then Nkind
(Name
(N
)) = N_Selected_Component
2677 and then not Acts_As_Spec
(Library_Unit
(N
))
2679 -- For a child unit that has no spec, one has been created and
2680 -- analyzed. The entity required is that of the spec.
2682 E_Name
:= Corresponding_Spec
(U
);
2685 E_Name
:= Defining_Entity
(U
);
2688 if Nkind
(Name
(N
)) = N_Selected_Component
then
2690 -- Child unit in a with clause
2692 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2694 -- If this is a child unit without a spec, and it has been analyzed
2695 -- already, a declaration has been created for it. The with_clause
2696 -- must reflect the actual body, and not the generated declaration,
2697 -- to prevent spurious binding errors involving an out-of-date spec.
2698 -- Note that this can only happen if the unit includes more than one
2699 -- with_clause for the child unit (e.g. in separate subunits).
2701 if Unit_Kind
= N_Subprogram_Declaration
2702 and then Analyzed
(Library_Unit
(N
))
2703 and then not Comes_From_Source
(Library_Unit
(N
))
2705 Set_Library_Unit
(N
,
2706 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2710 -- Restore style checks
2712 Style_Check
:= Save_Style_Check
;
2714 -- Record the reference, but do NOT set the unit as referenced, we want
2715 -- to consider the unit as unreferenced if this is the only reference
2718 Set_Entity_With_Checks
(Name
(N
), E_Name
);
2719 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
2721 -- Generate references and check No_Dependence restriction for parents
2723 if Is_Child_Unit
(E_Name
) then
2724 Pref
:= Prefix
(Name
(N
));
2725 Par_Name
:= Scope
(E_Name
);
2726 while Nkind
(Pref
) = N_Selected_Component
loop
2727 Change_Selected_Component_To_Expanded_Name
(Pref
);
2729 if Present
(Entity
(Selector_Name
(Pref
)))
2731 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
2732 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
2734 -- The prefix is a child unit that denotes a renaming declaration.
2735 -- Replace the prefix directly with the renamed unit, because the
2736 -- rest of the prefix is irrelevant to the visibility of the real
2739 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
2743 Set_Entity_With_Checks
(Pref
, Par_Name
);
2745 Generate_Reference
(Par_Name
, Pref
);
2746 Check_Restriction_No_Dependence
(Pref
, N
);
2747 Pref
:= Prefix
(Pref
);
2749 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2750 -- is set to Standard_Standard, and no attempt should be made to
2751 -- further unwind scopes.
2753 if Par_Name
/= Standard_Standard
then
2754 Par_Name
:= Scope
(Par_Name
);
2757 -- Abandon processing in case of previous errors
2759 if No
(Par_Name
) then
2760 Check_Error_Detected
;
2765 if Present
(Entity
(Pref
))
2766 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
2768 -- If the entity is set without its unit being compiled, the
2769 -- original parent is a renaming, and Par_Name is the renamed
2770 -- entity. For visibility purposes, we need the original entity,
2771 -- which must be analyzed now because Load_Unit directly retrieves
2772 -- the renamed unit, and the renaming declaration itself has not
2775 Analyze
(Parent
(Parent
(Entity
(Pref
))));
2776 pragma Assert
(Renamed_Object
(Entity
(Pref
)) = Par_Name
);
2777 Par_Name
:= Entity
(Pref
);
2780 -- Guard against missing or misspelled child units
2782 if Present
(Par_Name
) then
2783 Set_Entity_With_Checks
(Pref
, Par_Name
);
2784 Generate_Reference
(Par_Name
, Pref
);
2787 pragma Assert
(Serious_Errors_Detected
/= 0);
2789 -- Mark the node to indicate that a related error has been posted.
2790 -- This defends further compilation passes against improper use of
2791 -- the invalid WITH clause node.
2793 Set_Error_Posted
(N
);
2794 Set_Name
(N
, Error
);
2799 -- If the withed unit is System, and a system extension pragma is
2800 -- present, compile the extension now, rather than waiting for a
2801 -- visibility check on a specific entity.
2803 if Chars
(E_Name
) = Name_System
2804 and then Scope
(E_Name
) = Standard_Standard
2805 and then Present
(System_Extend_Unit
)
2806 and then Present_System_Aux
(N
)
2808 -- If the extension is not present, an error will have been emitted
2813 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2814 -- to private_with units; they will be made visible later (just before
2815 -- the private part is analyzed)
2817 if Private_Present
(N
) then
2818 Set_Is_Immediately_Visible
(E_Name
, False);
2821 -- Propagate Fatal_Error setting from with'ed unit to current unit
2823 case Fatal_Error
(Get_Source_Unit
(Library_Unit
(N
))) is
2825 -- Nothing to do if with'ed unit had no error
2830 -- If with'ed unit had a detected fatal error, propagate it
2832 when Error_Detected
=>
2833 Set_Fatal_Error
(Current_Sem_Unit
, Error_Detected
);
2835 -- If with'ed unit had an ignored error, then propagate it but do not
2836 -- overide an existring setting.
2838 when Error_Ignored
=>
2839 if Fatal_Error
(Current_Sem_Unit
) = None
then
2840 Set_Fatal_Error
(Current_Sem_Unit
, Error_Ignored
);
2843 end Analyze_With_Clause
;
2845 ------------------------------
2846 -- Check_Private_Child_Unit --
2847 ------------------------------
2849 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
2850 Lib_Unit
: constant Node_Id
:= Unit
(N
);
2852 Curr_Unit
: Entity_Id
;
2853 Sub_Parent
: Node_Id
;
2854 Priv_Child
: Entity_Id
;
2855 Par_Lib
: Entity_Id
;
2858 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean;
2859 -- Returns true if and only if the library unit is declared with
2860 -- an explicit designation of private.
2862 -----------------------------
2863 -- Is_Private_Library_Unit --
2864 -----------------------------
2866 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
2867 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
2870 return Private_Present
(Comp_Unit
);
2871 end Is_Private_Library_Unit
;
2873 -- Start of processing for Check_Private_Child_Unit
2876 if Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subprogram_Body
) then
2877 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
2878 Par_Lib
:= Curr_Unit
;
2880 elsif Nkind
(Lib_Unit
) = N_Subunit
then
2882 -- The parent is itself a body. The parent entity is to be found in
2883 -- the corresponding spec.
2885 Sub_Parent
:= Library_Unit
(N
);
2886 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
2888 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2889 -- enclosing body, retrieve the spec entity which is the proper
2890 -- ancestor we need for the following tests.
2892 if Ekind
(Curr_Unit
) = E_Package_Body
then
2893 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
2896 Par_Lib
:= Curr_Unit
;
2899 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
2901 Par_Lib
:= Curr_Unit
;
2902 Par_Spec
:= Parent_Spec
(Lib_Unit
);
2904 if No
(Par_Spec
) then
2907 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
2911 -- Loop through context items
2913 Item
:= First
(Context_Items
(N
));
2914 while Present
(Item
) loop
2916 -- Ada 2005 (AI-262): Allow private_with of a private child package
2917 -- in public siblings
2919 if Nkind
(Item
) = N_With_Clause
2920 and then not Implicit_With
(Item
)
2921 and then not Limited_Present
(Item
)
2922 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
2924 Priv_Child
:= Entity
(Name
(Item
));
2927 Curr_Parent
: Entity_Id
:= Par_Lib
;
2928 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
2929 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
2930 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
2933 -- If the child unit is a public child then locate the nearest
2934 -- private ancestor. Child_Parent will then be set to the
2935 -- parent of that ancestor.
2937 if not Is_Private_Library_Unit
(Priv_Child
) then
2938 while Present
(Prv_Ancestor
)
2939 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
2941 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
2944 if Present
(Prv_Ancestor
) then
2945 Child_Parent
:= Scope
(Prv_Ancestor
);
2949 while Present
(Curr_Parent
)
2950 and then Curr_Parent
/= Standard_Standard
2951 and then Curr_Parent
/= Child_Parent
2954 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
2955 Curr_Parent
:= Scope
(Curr_Parent
);
2958 if No
(Curr_Parent
) then
2959 Curr_Parent
:= Standard_Standard
;
2962 if Curr_Parent
/= Child_Parent
then
2963 if Ekind
(Priv_Child
) = E_Generic_Package
2964 and then Chars
(Priv_Child
) in Text_IO_Package_Name
2965 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
2968 ("& is a nested package, not a compilation unit",
2969 Name
(Item
), Priv_Child
);
2973 ("unit in with clause is private child unit!", Item
);
2975 ("\current unit must also have parent&!",
2976 Item
, Child_Parent
);
2980 or else Private_Present
(Item
)
2981 or else Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subunit
)
2982 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
2983 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
2989 ("current unit must also be private descendant of&",
2990 Item
, Child_Parent
);
2998 end Check_Private_Child_Unit
;
3000 ----------------------
3001 -- Check_Stub_Level --
3002 ----------------------
3004 procedure Check_Stub_Level
(N
: Node_Id
) is
3005 Par
: constant Node_Id
:= Parent
(N
);
3006 Kind
: constant Node_Kind
:= Nkind
(Par
);
3009 if Nkind_In
(Kind
, N_Package_Body
,
3013 and then Nkind_In
(Parent
(Par
), N_Compilation_Unit
, N_Subunit
)
3017 -- In an instance, a missing stub appears at any level. A warning
3018 -- message will have been emitted already for the missing file.
3020 elsif not In_Instance
then
3021 Error_Msg_N
("stub cannot appear in an inner scope", N
);
3023 elsif Expander_Active
then
3024 Error_Msg_N
("missing proper body", N
);
3026 end Check_Stub_Level
;
3028 ------------------------
3029 -- Expand_With_Clause --
3030 ------------------------
3032 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
3033 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3034 Ent
: constant Entity_Id
:= Entity
(Nam
);
3038 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3039 -- Build name to be used in implicit with_clause. In most cases this
3040 -- is the source name, but if renamings are present we must make the
3041 -- original unit visible, not the one it renames. The entity in the
3042 -- with clause is the renamed unit, but the identifier is the one from
3043 -- the source, which allows us to recover the unit renaming.
3045 ---------------------
3046 -- Build_Unit_Name --
3047 ---------------------
3049 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3054 if Nkind
(Nam
) = N_Identifier
then
3055 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3058 Ent
:= Entity
(Nam
);
3060 if Present
(Entity
(Selector_Name
(Nam
)))
3061 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3063 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
))))
3064 = N_Package_Renaming_Declaration
3066 -- The name in the with_clause is of the form A.B.C, and B is
3067 -- given by a renaming declaration. In that case we may not
3068 -- have analyzed the unit for B, but replaced it directly in
3069 -- lib-load with the unit it renames. We have to make A.B
3070 -- visible, so analyze the declaration for B now, in case it
3071 -- has not been done yet.
3073 Ent
:= Entity
(Selector_Name
(Nam
));
3076 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3080 Make_Expanded_Name
(Loc
,
3081 Chars
=> Chars
(Entity
(Nam
)),
3082 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3083 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3084 Set_Entity
(Result
, Ent
);
3087 end Build_Unit_Name
;
3089 -- Start of processing for Expand_With_Clause
3093 Make_With_Clause
(Loc
,
3094 Name
=> Build_Unit_Name
(Nam
));
3096 P
:= Parent
(Unit_Declaration_Node
(Ent
));
3097 Set_Library_Unit
(Withn
, P
);
3098 Set_Corresponding_Spec
(Withn
, Ent
);
3099 Set_First_Name
(Withn
, True);
3100 Set_Implicit_With
(Withn
, True);
3102 -- If the unit is a package or generic package declaration, a private_
3103 -- with_clause on a child unit implies that the implicit with on the
3104 -- parent is also private.
3106 if Nkind_In
(Unit
(N
), N_Package_Declaration
,
3107 N_Generic_Package_Declaration
)
3109 Set_Private_Present
(Withn
, Private_Present
(Item
));
3112 Prepend
(Withn
, Context_Items
(N
));
3113 Mark_Rewrite_Insertion
(Withn
);
3114 Install_Withed_Unit
(Withn
);
3116 -- If we have "with X.Y;", we want to recurse on "X", except in the
3117 -- unusual case where X.Y is a renaming of X. In that case, the scope
3118 -- of X will be null.
3120 if Nkind
(Nam
) = N_Expanded_Name
3121 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3123 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3125 end Expand_With_Clause
;
3127 --------------------------------
3128 -- Generate_Parent_References --
3129 --------------------------------
3131 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3133 P_Name
: Entity_Id
:= P_Id
;
3136 if Nkind
(N
) = N_Subunit
then
3139 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3142 if Nkind
(Pref
) = N_Expanded_Name
then
3144 -- Done already, if the unit has been compiled indirectly as
3145 -- part of the closure of its context because of inlining.
3150 while Nkind
(Pref
) = N_Selected_Component
loop
3151 Change_Selected_Component_To_Expanded_Name
(Pref
);
3152 Set_Entity
(Pref
, P_Name
);
3153 Set_Etype
(Pref
, Etype
(P_Name
));
3154 Generate_Reference
(P_Name
, Pref
, 'r');
3155 Pref
:= Prefix
(Pref
);
3156 P_Name
:= Scope
(P_Name
);
3159 -- The guard here on P_Name is to handle the error condition where
3160 -- the parent unit is missing because the file was not found.
3162 if Present
(P_Name
) then
3163 Set_Entity
(Pref
, P_Name
);
3164 Set_Etype
(Pref
, Etype
(P_Name
));
3165 Generate_Reference
(P_Name
, Pref
, 'r');
3166 Style
.Check_Identifier
(Pref
, P_Name
);
3168 end Generate_Parent_References
;
3170 ---------------------
3171 -- Has_With_Clause --
3172 ---------------------
3174 function Has_With_Clause
3177 Is_Limited
: Boolean := False) return Boolean
3181 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3182 -- Return the entity for the unit named in a [limited] with clause
3188 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3190 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3191 return Entity
(Selector_Name
(Name
(Clause
)));
3193 return Entity
(Name
(Clause
));
3197 -- Start of processing for Has_With_Clause
3200 if Present
(Context_Items
(C_Unit
)) then
3201 Item
:= First
(Context_Items
(C_Unit
));
3202 while Present
(Item
) loop
3203 if Nkind
(Item
) = N_With_Clause
3204 and then Limited_Present
(Item
) = Is_Limited
3205 and then Named_Unit
(Item
) = Pack
3215 end Has_With_Clause
;
3217 -----------------------------
3218 -- Implicit_With_On_Parent --
3219 -----------------------------
3221 procedure Implicit_With_On_Parent
3222 (Child_Unit
: Node_Id
;
3225 Loc
: constant Source_Ptr
:= Sloc
(N
);
3226 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3227 P_Unit
: Node_Id
:= Unit
(P
);
3228 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3231 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3232 -- Build prefix of child unit name. Recurse if needed
3234 function Build_Unit_Name
return Node_Id
;
3235 -- If the unit is a child unit, build qualified name with all ancestors
3237 -------------------------
3238 -- Build_Ancestor_Name --
3239 -------------------------
3241 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3242 P_Ref
: constant Node_Id
:=
3243 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3244 P_Spec
: Node_Id
:= P
;
3247 -- Ancestor may have been rewritten as a package body. Retrieve
3248 -- the original spec to trace earlier ancestors.
3250 if Nkind
(P
) = N_Package_Body
3251 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3253 P_Spec
:= Original_Node
(P
);
3256 if No
(Parent_Spec
(P_Spec
)) then
3260 Make_Selected_Component
(Loc
,
3261 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3262 Selector_Name
=> P_Ref
);
3264 end Build_Ancestor_Name
;
3266 ---------------------
3267 -- Build_Unit_Name --
3268 ---------------------
3270 function Build_Unit_Name
return Node_Id
is
3274 if No
(Parent_Spec
(P_Unit
)) then
3275 return New_Occurrence_Of
(P_Name
, Loc
);
3279 Make_Expanded_Name
(Loc
,
3280 Chars
=> Chars
(P_Name
),
3281 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3282 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3283 Set_Entity
(Result
, P_Name
);
3286 end Build_Unit_Name
;
3288 -- Start of processing for Implicit_With_On_Parent
3291 -- The unit of the current compilation may be a package body that
3292 -- replaces an instance node. In this case we need the original instance
3293 -- node to construct the proper parent name.
3295 if Nkind
(P_Unit
) = N_Package_Body
3296 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3298 P_Unit
:= Original_Node
(P_Unit
);
3301 -- We add the implicit with if the child unit is the current unit being
3302 -- compiled. If the current unit is a body, we do not want to add an
3303 -- implicit_with a second time to the corresponding spec.
3305 if Nkind
(Child_Unit
) = N_Package_Declaration
3306 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3311 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3313 Set_Library_Unit
(Withn
, P
);
3314 Set_Corresponding_Spec
(Withn
, P_Name
);
3315 Set_First_Name
(Withn
, True);
3316 Set_Implicit_With
(Withn
, True);
3318 -- Node is placed at the beginning of the context items, so that
3319 -- subsequent use clauses on the parent can be validated.
3321 Prepend
(Withn
, Context_Items
(N
));
3322 Mark_Rewrite_Insertion
(Withn
);
3323 Install_Withed_Unit
(Withn
);
3325 if Is_Child_Spec
(P_Unit
) then
3326 Implicit_With_On_Parent
(P_Unit
, N
);
3328 end Implicit_With_On_Parent
;
3334 function In_Chain
(E
: Entity_Id
) return Boolean is
3338 H
:= Current_Entity
(E
);
3339 while Present
(H
) loop
3350 ---------------------
3351 -- Install_Context --
3352 ---------------------
3354 procedure Install_Context
(N
: Node_Id
) is
3355 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3358 Install_Context_Clauses
(N
);
3360 if Is_Child_Spec
(Lib_Unit
) then
3361 Install_Parents
(Lib_Unit
, Private_Present
(Parent
(Lib_Unit
)));
3364 Install_Limited_Context_Clauses
(N
);
3365 end Install_Context
;
3367 -----------------------------
3368 -- Install_Context_Clauses --
3369 -----------------------------
3371 procedure Install_Context_Clauses
(N
: Node_Id
) is
3372 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3374 Uname_Node
: Entity_Id
;
3375 Check_Private
: Boolean := False;
3376 Decl_Node
: Node_Id
;
3377 Lib_Parent
: Entity_Id
;
3380 -- First skip configuration pragmas at the start of the context. They
3381 -- are not technically part of the context clause, but that's where the
3382 -- parser puts them. Note they were analyzed in Analyze_Context.
3384 Item
:= First
(Context_Items
(N
));
3385 while Present
(Item
)
3386 and then Nkind
(Item
) = N_Pragma
3387 and then Pragma_Name_Mapped
(Item
) in Configuration_Pragma_Names
3392 -- Loop through the actual context clause items. We process everything
3393 -- except Limited_With clauses in this routine. Limited_With clauses
3394 -- are separately installed (see Install_Limited_Context_Clauses).
3396 while Present
(Item
) loop
3398 -- Case of explicit WITH clause
3400 if Nkind
(Item
) = N_With_Clause
3401 and then not Implicit_With
(Item
)
3403 if Limited_Present
(Item
) then
3405 -- Limited withed units will be installed later
3409 -- If Name (Item) is not an entity name, something is wrong, and
3410 -- this will be detected in due course, for now ignore the item
3412 elsif not Is_Entity_Name
(Name
(Item
)) then
3415 elsif No
(Entity
(Name
(Item
))) then
3416 Set_Entity
(Name
(Item
), Any_Id
);
3420 Uname_Node
:= Entity
(Name
(Item
));
3422 if Is_Private_Descendant
(Uname_Node
) then
3423 Check_Private
:= True;
3426 Install_Withed_Unit
(Item
);
3428 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3430 -- If the unit is a subprogram instance, it appears nested within
3431 -- a package that carries the parent information.
3433 if Is_Generic_Instance
(Uname_Node
)
3434 and then Ekind
(Uname_Node
) /= E_Package
3436 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3439 if Is_Child_Spec
(Decl_Node
) then
3440 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3441 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3443 -- If not an expanded name, the child unit must be a
3444 -- renaming, nothing to do.
3449 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3450 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3451 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3453 Implicit_With_On_Parent
3454 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3457 -- Check license conditions unless this is a dummy unit
3459 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3460 License_Check
: declare
3461 Withu
: constant Unit_Number_Type
:=
3462 Get_Source_Unit
(Library_Unit
(Item
));
3463 Withl
: constant License_Type
:=
3464 License
(Source_Index
(Withu
));
3465 Unitl
: constant License_Type
:=
3466 License
(Source_Index
(Current_Sem_Unit
));
3468 procedure License_Error
;
3469 -- Signal error of bad license
3475 procedure License_Error
is
3478 ("license of withed unit & may be inconsistent??",
3482 -- Start of processing for License_Check
3485 -- Exclude license check if withed unit is an internal unit.
3486 -- This situation arises e.g. with the GPL version of GNAT.
3488 if Is_Internal_File_Name
(Unit_File_Name
(Withu
)) then
3491 -- Otherwise check various cases
3503 if Withl
= Restricted
then
3507 when Modified_GPL
=>
3508 if Withl
= Restricted
or else Withl
= GPL
then
3512 when Unrestricted
=>
3519 -- Case of USE PACKAGE clause
3521 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3522 Analyze_Use_Package
(Item
);
3524 -- Case of USE TYPE clause
3526 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3527 Analyze_Use_Type
(Item
);
3531 elsif Nkind
(Item
) = N_Pragma
then
3539 if Is_Child_Spec
(Lib_Unit
) then
3541 -- The unit also has implicit with_clauses on its own parents
3543 if No
(Context_Items
(N
)) then
3544 Set_Context_Items
(N
, New_List
);
3547 Implicit_With_On_Parent
(Lib_Unit
, N
);
3550 -- If the unit is a body, the context of the specification must also
3551 -- be installed. That includes private with_clauses in that context.
3553 if Nkind
(Lib_Unit
) = N_Package_Body
3554 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3555 and then not Acts_As_Spec
(N
))
3557 Install_Context
(Library_Unit
(N
));
3559 -- Only install private with-clauses of a spec that comes from
3560 -- source, excluding specs created for a subprogram body that is
3563 if Comes_From_Source
(Library_Unit
(N
)) then
3564 Install_Private_With_Clauses
3565 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3568 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3570 -- If the unit is the body of a public child unit, the private
3571 -- declarations of the parent must be made visible. If the child
3572 -- unit is private, the private declarations have been installed
3573 -- already in the call to Install_Parents for the spec. Installing
3574 -- private declarations must be done for all ancestors of public
3575 -- child units. In addition, sibling units mentioned in the
3576 -- context clause of the body are directly visible.
3584 Lib_Spec
:= Unit
(Library_Unit
(N
));
3585 while Is_Child_Spec
(Lib_Spec
) loop
3586 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3587 P_Name
:= Defining_Entity
(P
);
3589 if not (Private_Present
(Parent
(Lib_Spec
)))
3590 and then not In_Private_Part
(P_Name
)
3592 Install_Private_Declarations
(P_Name
);
3593 Install_Private_With_Clauses
(P_Name
);
3594 Set_Use
(Private_Declarations
(Specification
(P
)));
3602 -- For a package body, children in context are immediately visible
3604 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3607 if Nkind_In
(Lib_Unit
, N_Generic_Package_Declaration
,
3608 N_Generic_Subprogram_Declaration
,
3609 N_Package_Declaration
,
3610 N_Subprogram_Declaration
)
3612 if Is_Child_Spec
(Lib_Unit
) then
3613 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3614 Set_Is_Private_Descendant
3615 (Defining_Entity
(Lib_Unit
),
3616 Is_Private_Descendant
(Lib_Parent
)
3617 or else Private_Present
(Parent
(Lib_Unit
)));
3620 Set_Is_Private_Descendant
3621 (Defining_Entity
(Lib_Unit
),
3622 Private_Present
(Parent
(Lib_Unit
)));
3626 if Check_Private
then
3627 Check_Private_Child_Unit
(N
);
3629 end Install_Context_Clauses
;
3631 -------------------------------------
3632 -- Install_Limited_Context_Clauses --
3633 -------------------------------------
3635 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3638 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3639 -- Check that the unlimited view of a given compilation_unit is not
3640 -- already visible through "use + renamings".
3642 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3643 -- Check that if a limited_with clause of a given compilation_unit
3644 -- mentions a descendant of a private child of some library unit, then
3645 -- the given compilation_unit must be the declaration of a private
3646 -- descendant of that library unit, or a public descendant of such. The
3647 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3648 -- use entities on the limited with_clauses because their units have not
3649 -- been analyzed, so we have to climb the tree of ancestors looking for
3650 -- private keywords.
3652 procedure Expand_Limited_With_Clause
3653 (Comp_Unit
: Node_Id
;
3656 -- If a child unit appears in a limited_with clause, there are implicit
3657 -- limited_with clauses on all parents that are not already visible
3658 -- through a regular with clause. This procedure creates the implicit
3659 -- limited with_clauses for the parents and loads the corresponding
3660 -- units. The shadow entities are created when the inserted clause is
3661 -- analyzed. Implements Ada 2005 (AI-50217).
3663 ---------------------
3664 -- Check_Renamings --
3665 ---------------------
3667 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
3676 pragma Assert
(Nkind
(W
) = N_With_Clause
);
3678 -- Protect the frontend against previous critical errors
3680 case Nkind
(Unit
(Library_Unit
(W
))) is
3681 when N_Subprogram_Declaration |
3682 N_Package_Declaration |
3683 N_Generic_Subprogram_Declaration |
3684 N_Generic_Package_Declaration
=>
3691 -- Check "use + renamings"
3693 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
3694 Spec
:= Specification
(Unit
(P
));
3696 Item
:= First
(Visible_Declarations
(Spec
));
3697 while Present
(Item
) loop
3699 -- Look only at use package clauses
3701 if Nkind
(Item
) = N_Use_Package_Clause
then
3703 -- Traverse the list of packages
3705 Nam
:= First
(Names
(Item
));
3706 while Present
(Nam
) loop
3709 pragma Assert
(Present
(Parent
(E
)));
3711 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
3712 and then Renamed_Entity
(E
) = WEnt
3714 -- The unlimited view is visible through use clause and
3715 -- renamings. There is no need to generate the error
3716 -- message here because Is_Visible_Through_Renamings
3717 -- takes care of generating the precise error message.
3721 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
3723 -- The use clause may refer to a local package.
3724 -- Check all the enclosing scopes.
3727 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
3733 ("unlimited view visible through use clause ", W
);
3745 -- Recursive call to check all the ancestors
3747 if Is_Child_Spec
(Unit
(P
)) then
3748 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
3750 end Check_Renamings
;
3752 ---------------------------------------
3753 -- Check_Private_Limited_Withed_Unit --
3754 ---------------------------------------
3756 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
3757 Curr_Parent
: Node_Id
;
3758 Child_Parent
: Node_Id
;
3759 Curr_Private
: Boolean;
3762 -- Compilation unit of the parent of the withed library unit
3764 Child_Parent
:= Library_Unit
(Item
);
3766 -- If the child unit is a public child, then locate its nearest
3767 -- private ancestor, if any, then Child_Parent will then be set to
3768 -- the parent of that ancestor.
3770 if not Private_Present
(Library_Unit
(Item
)) then
3771 while Present
(Child_Parent
)
3772 and then not Private_Present
(Child_Parent
)
3774 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3777 if No
(Child_Parent
) then
3782 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3784 -- Traverse all the ancestors of the current compilation unit to
3785 -- check if it is a descendant of named library unit.
3787 Curr_Parent
:= Parent
(Item
);
3788 Curr_Private
:= Private_Present
(Curr_Parent
);
3790 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
3791 and then Curr_Parent
/= Child_Parent
3793 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
3794 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
3797 if Curr_Parent
/= Child_Parent
then
3799 ("unit in with clause is private child unit!", Item
);
3801 ("\current unit must also have parent&!",
3802 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3804 elsif Private_Present
(Parent
(Item
))
3805 or else Curr_Private
3806 or else Private_Present
(Item
)
3807 or else Nkind_In
(Unit
(Parent
(Item
)), N_Package_Body
,
3811 -- Current unit is private, of descendant of a private unit
3817 ("current unit must also be private descendant of&",
3818 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3820 end Check_Private_Limited_Withed_Unit
;
3822 --------------------------------
3823 -- Expand_Limited_With_Clause --
3824 --------------------------------
3826 procedure Expand_Limited_With_Clause
3827 (Comp_Unit
: Node_Id
;
3831 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3832 Unum
: Unit_Number_Type
;
3835 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
3836 -- Returns true if the context already includes a with_clause for
3837 -- this unit. If the with_clause is non-limited, the unit is fully
3838 -- visible and an implicit limited_with should not be created. If
3839 -- there is already a limited_with clause for W, a second one is
3840 -- simply redundant.
3842 --------------------------
3843 -- Previous_Withed_Unit --
3844 --------------------------
3846 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
3850 -- A limited with_clause cannot appear in the same context_clause
3851 -- as a nonlimited with_clause which mentions the same library.
3853 Item
:= First
(Context_Items
(Comp_Unit
));
3854 while Present
(Item
) loop
3855 if Nkind
(Item
) = N_With_Clause
3856 and then Library_Unit
(Item
) = Library_Unit
(W
)
3865 end Previous_Withed_Unit
;
3867 -- Start of processing for Expand_Limited_With_Clause
3870 if Nkind
(Nam
) = N_Identifier
then
3872 -- Create node for name of withed unit
3875 Make_With_Clause
(Loc
,
3876 Name
=> New_Copy
(Nam
));
3878 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
3880 Make_With_Clause
(Loc
,
3881 Name
=> Make_Selected_Component
(Loc
,
3882 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
3883 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
3884 Set_Parent
(Withn
, Parent
(N
));
3887 Set_Limited_Present
(Withn
);
3888 Set_First_Name
(Withn
);
3889 Set_Implicit_With
(Withn
);
3893 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
3898 -- Do not generate a limited_with_clause on the current unit. This
3899 -- path is taken when a unit has a limited_with clause on one of its
3902 if Unum
= Current_Sem_Unit
then
3906 Set_Library_Unit
(Withn
, Cunit
(Unum
));
3907 Set_Corresponding_Spec
3908 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
3910 if not Previous_Withed_Unit
(Withn
) then
3911 Prepend
(Withn
, Context_Items
(Parent
(N
)));
3912 Mark_Rewrite_Insertion
(Withn
);
3914 -- Add implicit limited_with_clauses for parents of child units
3915 -- mentioned in limited_with clauses.
3917 if Nkind
(Nam
) = N_Selected_Component
then
3918 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
3923 if not Limited_View_Installed
(Withn
) then
3924 Install_Limited_Withed_Unit
(Withn
);
3927 end Expand_Limited_With_Clause
;
3929 -- Start of processing for Install_Limited_Context_Clauses
3932 Item
:= First
(Context_Items
(N
));
3933 while Present
(Item
) loop
3934 if Nkind
(Item
) = N_With_Clause
3935 and then Limited_Present
(Item
)
3936 and then not Error_Posted
(Item
)
3938 if Nkind
(Name
(Item
)) = N_Selected_Component
then
3939 Expand_Limited_With_Clause
3940 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
3943 Check_Private_Limited_Withed_Unit
(Item
);
3945 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
3946 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
3949 -- A unit may have a limited with on itself if it has a limited
3950 -- with_clause on one of its child units. In that case it is
3951 -- already being compiled and it makes no sense to install its
3954 -- If the item is a limited_private_with_clause, install it if the
3955 -- current unit is a body or if it is a private child. Otherwise
3956 -- the private clause is installed before analyzing the private
3957 -- part of the current unit.
3959 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
3960 and then not Limited_View_Installed
(Item
)
3962 not Is_Ancestor_Unit
3963 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
3965 if not Private_Present
(Item
)
3966 or else Private_Present
(N
)
3967 or else Nkind_In
(Unit
(N
), N_Package_Body
,
3971 Install_Limited_Withed_Unit
(Item
);
3979 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
3980 -- looking for incomplete subtype declarations of incomplete types
3981 -- visible through a limited with clause.
3983 if Ada_Version
>= Ada_2005
3984 and then Analyzed
(N
)
3985 and then Nkind
(Unit
(N
)) = N_Package_Declaration
3990 Non_Lim_View
: Entity_Id
;
3993 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
3994 while Present
(Decl
) loop
3995 if Nkind
(Decl
) = N_Subtype_Declaration
3997 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
3999 From_Limited_With
(Defining_Identifier
(Decl
))
4001 Def_Id
:= Defining_Identifier
(Decl
);
4002 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
4004 if not Is_Incomplete_Type
(Non_Lim_View
) then
4006 -- Convert an incomplete subtype declaration into a
4007 -- corresponding non-limited view subtype declaration.
4008 -- This is usually the case when analyzing a body that
4009 -- has regular with clauses, when the spec has limited
4012 -- If the non-limited view is still incomplete, it is
4013 -- the dummy entry already created, and the declaration
4014 -- cannot be reanalyzed. This is the case when installing
4015 -- a parent unit that has limited with-clauses.
4017 Set_Subtype_Indication
(Decl
,
4018 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
4019 Set_Etype
(Def_Id
, Non_Lim_View
);
4020 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
4021 Set_Analyzed
(Decl
, False);
4023 -- Reanalyze the declaration, suppressing the call to
4024 -- Enter_Name to avoid duplicate names.
4026 Analyze_Subtype_Declaration
4036 end Install_Limited_Context_Clauses
;
4038 ---------------------
4039 -- Install_Parents --
4040 ---------------------
4042 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean) is
4049 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4050 P_Name
:= Get_Parent_Entity
(P
);
4052 if Etype
(P_Name
) = Any_Type
then
4056 if Ekind
(P_Name
) = E_Generic_Package
4057 and then not Nkind_In
(Lib_Unit
, N_Generic_Subprogram_Declaration
,
4058 N_Generic_Package_Declaration
)
4059 and then Nkind
(Lib_Unit
) not in N_Generic_Renaming_Declaration
4062 ("child of a generic package must be a generic unit", Lib_Unit
);
4064 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4066 ("parent unit must be package or generic package", Lib_Unit
);
4067 raise Unrecoverable_Error
;
4069 elsif Present
(Renamed_Object
(P_Name
)) then
4070 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4071 raise Unrecoverable_Error
;
4073 -- Verify that a child of an instance is itself an instance, or the
4074 -- renaming of one. Given that an instance that is a unit is replaced
4075 -- with a package declaration, check against the original node. The
4076 -- parent may be currently being instantiated, in which case it appears
4077 -- as a declaration, but the generic_parent is already established
4078 -- indicating that we deal with an instance.
4080 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4081 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4082 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4084 (Nkind
(Lib_Unit
) = N_Package_Declaration
4085 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4090 ("child of an instance must be an instance or renaming",
4095 -- This is the recursive call that ensures all parents are loaded
4097 if Is_Child_Spec
(P
) then
4099 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)));
4102 -- Now we can install the context for this parent
4104 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4105 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4106 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4108 -- The child unit is in the declarative region of the parent. The parent
4109 -- must therefore appear in the scope stack and be visible, as when
4110 -- compiling the corresponding body. If the child unit is private or it
4111 -- is a package body, private declarations must be accessible as well.
4112 -- Use declarations in the parent must also be installed. Finally, other
4113 -- child units of the same parent that are in the context are
4114 -- immediately visible.
4116 -- Find entity for compilation unit, and set its private descendant
4117 -- status as needed. Indicate that it is a compilation unit, which is
4118 -- redundant in general, but needed if this is a generated child spec
4119 -- for a child body without previous spec.
4121 E_Name
:= Defining_Entity
(Lib_Unit
);
4123 Set_Is_Child_Unit
(E_Name
);
4124 Set_Is_Compilation_Unit
(E_Name
);
4126 Set_Is_Private_Descendant
(E_Name
,
4127 Is_Private_Descendant
(P_Name
)
4128 or else Private_Present
(Parent
(Lib_Unit
)));
4130 P_Spec
:= Package_Specification
(P_Name
);
4131 Push_Scope
(P_Name
);
4133 -- Save current visibility of unit
4135 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4136 Is_Immediately_Visible
(P_Name
);
4137 Set_Is_Immediately_Visible
(P_Name
);
4138 Install_Visible_Declarations
(P_Name
);
4139 Set_Use
(Visible_Declarations
(P_Spec
));
4141 -- If the parent is a generic unit, its formal part may contain formal
4142 -- packages and use clauses for them.
4144 if Ekind
(P_Name
) = E_Generic_Package
then
4145 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4148 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4149 Install_Private_Declarations
(P_Name
);
4150 Install_Private_With_Clauses
(P_Name
);
4151 Set_Use
(Private_Declarations
(P_Spec
));
4153 end Install_Parents
;
4155 ----------------------------------
4156 -- Install_Private_With_Clauses --
4157 ----------------------------------
4159 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4160 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4164 if Debug_Flag_I
then
4165 Write_Str
("install private with clauses of ");
4166 Write_Name
(Chars
(P
));
4170 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4171 Item
:= First
(Context_Items
(Parent
(Decl
)));
4172 while Present
(Item
) loop
4173 if Nkind
(Item
) = N_With_Clause
4174 and then Private_Present
(Item
)
4176 -- If the unit is an ancestor of the current one, it is the
4177 -- case of a private limited with clause on a child unit, and
4178 -- the compilation of one of its descendants, In that case the
4179 -- limited view is errelevant.
4181 if Limited_Present
(Item
) then
4182 if not Limited_View_Installed
(Item
)
4184 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4185 Cunit
(Current_Sem_Unit
))
4187 Install_Limited_Withed_Unit
(Item
);
4190 Install_Withed_Unit
(Item
, Private_With_OK
=> True);
4197 end Install_Private_With_Clauses
;
4199 ----------------------
4200 -- Install_Siblings --
4201 ----------------------
4203 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4209 -- Iterate over explicit with clauses, and check whether the scope of
4210 -- each entity is an ancestor of the current unit, in which case it is
4211 -- immediately visible.
4213 Item
:= First
(Context_Items
(N
));
4214 while Present
(Item
) loop
4216 -- Do not install private_with_clauses declaration, unless unit
4217 -- is itself a private child unit, or is a body. Note that for a
4218 -- subprogram body the private_with_clause does not take effect until
4219 -- after the specification.
4221 if Nkind
(Item
) /= N_With_Clause
4222 or else Implicit_With
(Item
)
4223 or else Limited_Present
(Item
)
4224 or else Error_Posted
(Item
)
4228 elsif not Private_Present
(Item
)
4229 or else Private_Present
(N
)
4230 or else Nkind
(Unit
(N
)) = N_Package_Body
4232 Id
:= Entity
(Name
(Item
));
4234 if Is_Child_Unit
(Id
)
4235 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4237 Set_Is_Immediately_Visible
(Id
);
4239 -- Check for the presence of another unit in the context that
4240 -- may be inadvertently hidden by the child.
4242 Prev
:= Current_Entity
(Id
);
4245 and then Is_Immediately_Visible
(Prev
)
4246 and then not Is_Child_Unit
(Prev
)
4252 Clause
:= First
(Context_Items
(N
));
4253 while Present
(Clause
) loop
4254 if Nkind
(Clause
) = N_With_Clause
4255 and then Entity
(Name
(Clause
)) = Prev
4258 ("child unit& hides compilation unit " &
4259 "with the same name??",
4269 -- The With_Clause may be on a grand-child or one of its further
4270 -- descendants, which makes a child immediately visible. Examine
4271 -- ancestry to determine whether such a child exists. For example,
4272 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4273 -- is immediately visible.
4275 elsif Is_Child_Unit
(Id
) then
4281 while Is_Child_Unit
(Par
) loop
4282 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4283 Set_Is_Immediately_Visible
(Par
);
4292 -- If the item is a private with-clause on a child unit, the parent
4293 -- may have been installed already, but the child unit must remain
4294 -- invisible until installed in a private part or body, unless there
4295 -- is already a regular with_clause for it in the current unit.
4297 elsif Private_Present
(Item
) then
4298 Id
:= Entity
(Name
(Item
));
4300 if Is_Child_Unit
(Id
) then
4304 function In_Context
return Boolean;
4305 -- Scan context of current unit, to check whether there is
4306 -- a with_clause on the same unit as a private with-clause
4307 -- on a parent, in which case child unit is visible. If the
4308 -- unit is a grand-child, the same applies to its parent.
4314 function In_Context
return Boolean is
4317 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4318 while Present
(Clause
) loop
4319 if Nkind
(Clause
) = N_With_Clause
4320 and then Comes_From_Source
(Clause
)
4321 and then Is_Entity_Name
(Name
(Clause
))
4322 and then not Private_Present
(Clause
)
4324 if Entity
(Name
(Clause
)) = Id
4326 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4327 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4340 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4347 end Install_Siblings
;
4349 ---------------------------------
4350 -- Install_Limited_Withed_Unit --
4351 ---------------------------------
4353 procedure Install_Limited_Withed_Unit
(N
: Node_Id
) is
4354 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4357 Is_Child_Package
: Boolean := False;
4358 Lim_Header
: Entity_Id
;
4359 Lim_Typ
: Entity_Id
;
4361 procedure Check_Body_Required
;
4362 -- A unit mentioned in a limited with_clause may not be mentioned in
4363 -- a regular with_clause, but must still be included in the current
4364 -- partition. We need to determine whether the unit needs a body, so
4365 -- that the binder can determine the name of the file to be compiled.
4366 -- Checking whether a unit needs a body can be done without semantic
4367 -- analysis, by examining the nature of the declarations in the package.
4369 function Has_Limited_With_Clause
4370 (C_Unit
: Entity_Id
;
4371 Pack
: Entity_Id
) return Boolean;
4372 -- Determine whether any package in the ancestor chain starting with
4373 -- C_Unit has a limited with clause for package Pack.
4375 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean;
4376 -- Check if some package installed though normal with-clauses has a
4377 -- renaming declaration of package P. AARM 10.1.2(21/2).
4379 -------------------------
4380 -- Check_Body_Required --
4381 -------------------------
4383 procedure Check_Body_Required
is
4384 PA
: constant List_Id
:=
4385 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4387 procedure Check_Declarations
(Spec
: Node_Id
);
4388 -- Recursive procedure that does the work and checks nested packages
4390 ------------------------
4391 -- Check_Declarations --
4392 ------------------------
4394 procedure Check_Declarations
(Spec
: Node_Id
) is
4396 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4398 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4400 procedure Check_Pragma_Import
(P
: Node_Id
);
4401 -- If a pragma import applies to a previous subprogram, the
4402 -- enclosing unit may not need a body. The processing is syntactic
4403 -- and does not require a declaration to be analyzed. The code
4404 -- below also handles pragma Import when applied to a subprogram
4405 -- that renames another. In this case the pragma applies to the
4408 -- Chains of multiple renames are not handled by the code below.
4409 -- It is probably impossible to handle all cases without proper
4410 -- name resolution. In such cases the algorithm is conservative
4411 -- and will indicate that a body is needed???
4413 -------------------------
4414 -- Check_Pragma_Import --
4415 -------------------------
4417 procedure Check_Pragma_Import
(P
: Node_Id
) is
4423 procedure Remove_Homonyms
(E
: Node_Id
);
4424 -- Make one pass over list of subprograms. Called again if
4425 -- subprogram is a renaming. E is known to be an identifier.
4427 ---------------------
4428 -- Remove_Homonyms --
4429 ---------------------
4431 procedure Remove_Homonyms
(E
: Node_Id
) is
4432 R
: Entity_Id
:= Empty
;
4433 -- Name of renamed entity, if any
4436 Subp_Id
:= First_Elmt
(Subp_List
);
4437 while Present
(Subp_Id
) loop
4438 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4439 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4440 /= N_Subprogram_Renaming_Declaration
4443 Next_Elmt
(Subp_Id
);
4444 Remove_Elmt
(Subp_List
, Prev_Id
);
4446 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4450 Next_Elmt
(Subp_Id
);
4455 if Nkind
(R
) = N_Identifier
then
4456 Remove_Homonyms
(R
);
4458 elsif Nkind
(R
) = N_Selected_Component
then
4459 Remove_Homonyms
(Selector_Name
(R
));
4461 -- Renaming of attribute
4467 end Remove_Homonyms
;
4469 -- Start of processing for Check_Pragma_Import
4472 -- Find name of entity in Import pragma. We have not analyzed
4473 -- the construct, so we must guard against syntax errors.
4475 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4478 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4482 Imported
:= Expression
(Arg
);
4485 Remove_Homonyms
(Imported
);
4486 end Check_Pragma_Import
;
4488 -- Start of processing for Check_Declarations
4491 -- Search for Elaborate Body pragma
4493 Decl
:= First
(Visible_Declarations
(Spec
));
4494 while Present
(Decl
)
4495 and then Nkind
(Decl
) = N_Pragma
4497 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4498 Set_Body_Required
(Library_Unit
(N
));
4505 -- Look for declarations that require the presence of a body. We
4506 -- have already skipped pragmas at the start of the list.
4508 while Present
(Decl
) loop
4510 -- Subprogram that comes from source means body may be needed.
4511 -- Save for subsequent examination of import pragmas.
4513 if Comes_From_Source
(Decl
)
4514 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4515 N_Subprogram_Renaming_Declaration
,
4516 N_Generic_Subprogram_Declaration
))
4518 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4520 -- Package declaration of generic package declaration. We need
4521 -- to recursively examine nested declarations.
4523 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4524 N_Generic_Package_Declaration
)
4526 Check_Declarations
(Specification
(Decl
));
4528 elsif Nkind
(Decl
) = N_Pragma
4529 and then Pragma_Name_Mapped
(Decl
) = Name_Import
4531 Check_Pragma_Import
(Decl
);
4537 -- Same set of tests for private part. In addition to subprograms
4538 -- detect the presence of Taft Amendment types (incomplete types
4539 -- completed in the body).
4541 Decl
:= First
(Private_Declarations
(Spec
));
4542 while Present
(Decl
) loop
4543 if Comes_From_Source
(Decl
)
4544 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4545 N_Subprogram_Renaming_Declaration
,
4546 N_Generic_Subprogram_Declaration
))
4548 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4550 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4551 N_Generic_Package_Declaration
)
4553 Check_Declarations
(Specification
(Decl
));
4555 -- Collect incomplete type declarations for separate pass
4557 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4558 Append_Elmt
(Decl
, Incomplete_Decls
);
4560 elsif Nkind
(Decl
) = N_Pragma
4561 and then Pragma_Name_Mapped
(Decl
) = Name_Import
4563 Check_Pragma_Import
(Decl
);
4569 -- Now check incomplete declarations to locate Taft amendment
4570 -- types. This can be done by examining the defining identifiers
4571 -- of type declarations without real semantic analysis.
4577 Inc
:= First_Elmt
(Incomplete_Decls
);
4578 while Present
(Inc
) loop
4579 Decl
:= Next
(Node
(Inc
));
4580 while Present
(Decl
) loop
4581 if Nkind
(Decl
) = N_Full_Type_Declaration
4582 and then Chars
(Defining_Identifier
(Decl
)) =
4583 Chars
(Defining_Identifier
(Node
(Inc
)))
4591 -- If no completion, this is a TAT, and a body is needed
4594 Set_Body_Required
(Library_Unit
(N
));
4602 -- Finally, check whether there are subprograms that still require
4603 -- a body, i.e. are not renamings or null.
4605 if not Is_Empty_Elmt_List
(Subp_List
) then
4611 Subp_Id
:= First_Elmt
(Subp_List
);
4612 Spec
:= Parent
(Node
(Subp_Id
));
4614 while Present
(Subp_Id
) loop
4615 if Nkind
(Parent
(Spec
))
4616 = N_Subprogram_Renaming_Declaration
4620 elsif Nkind
(Spec
) = N_Procedure_Specification
4621 and then Null_Present
(Spec
)
4626 Set_Body_Required
(Library_Unit
(N
));
4630 Next_Elmt
(Subp_Id
);
4634 end Check_Declarations
;
4636 -- Start of processing for Check_Body_Required
4639 -- If this is an imported package (Java and CIL usage) no body is
4640 -- needed. Scan list of pragmas that may follow a compilation unit
4641 -- to look for a relevant pragma Import.
4643 if Present
(PA
) then
4649 while Present
(Prag
) loop
4650 if Nkind
(Prag
) = N_Pragma
4651 and then Get_Pragma_Id
(Prag
) = Pragma_Import
4661 Check_Declarations
(Specification
(P_Unit
));
4662 end Check_Body_Required
;
4664 -----------------------------
4665 -- Has_Limited_With_Clause --
4666 -----------------------------
4668 function Has_Limited_With_Clause
4669 (C_Unit
: Entity_Id
;
4670 Pack
: Entity_Id
) return Boolean
4677 while Present
(Par
) loop
4678 if Ekind
(Par
) /= E_Package
then
4682 -- Retrieve the Compilation_Unit node for Par and determine if
4683 -- its context clauses contain a limited with for Pack.
4685 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
4687 if Nkind
(Par_Unit
) = N_Package_Declaration
then
4688 Par_Unit
:= Parent
(Par_Unit
);
4691 if Has_With_Clause
(Par_Unit
, Pack
, True) then
4695 -- If there are more ancestors, climb up the tree, otherwise we
4698 if Is_Child_Unit
(Par
) then
4706 end Has_Limited_With_Clause
;
4708 ----------------------------------
4709 -- Is_Visible_Through_Renamings --
4710 ----------------------------------
4712 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean is
4713 Kind
: constant Node_Kind
:=
4714 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
4720 -- Example of the error detected by this subprogram:
4728 -- package Ren_P renames P;
4734 -- limited with P; -- ERROR
4735 -- package R.C is ...
4737 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
4740 Item
:= First
(Context_Items
(Aux_Unit
));
4741 while Present
(Item
) loop
4742 if Nkind
(Item
) = N_With_Clause
4743 and then not Limited_Present
(Item
)
4744 and then Nkind
(Unit
(Library_Unit
(Item
))) =
4745 N_Package_Declaration
4748 First
(Visible_Declarations
4749 (Specification
(Unit
(Library_Unit
(Item
)))));
4750 while Present
(Decl
) loop
4751 if Nkind
(Decl
) = N_Package_Renaming_Declaration
4752 and then Entity
(Name
(Decl
)) = P
4754 -- Generate the error message only if the current unit
4755 -- is a package declaration; in case of subprogram
4756 -- bodies and package bodies we just return True to
4757 -- indicate that the limited view must not be
4760 if Kind
= N_Package_Declaration
then
4762 ("simultaneous visibility of the limited and " &
4763 "unlimited views not allowed", N
);
4764 Error_Msg_Sloc
:= Sloc
(Item
);
4766 ("\\ unlimited view of & visible through the " &
4767 "context clause #", N
, P
);
4768 Error_Msg_Sloc
:= Sloc
(Decl
);
4769 Error_Msg_NE
("\\ and the renaming #", N
, P
);
4782 -- If it is a body not acting as spec, follow pointer to the
4783 -- corresponding spec, otherwise follow pointer to parent spec.
4785 if Present
(Library_Unit
(Aux_Unit
))
4786 and then Nkind_In
(Unit
(Aux_Unit
),
4787 N_Package_Body
, N_Subprogram_Body
)
4789 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
4791 -- Aux_Unit is a body that acts as a spec. Clause has
4792 -- already been flagged as illegal.
4797 Aux_Unit
:= Library_Unit
(Aux_Unit
);
4801 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
4804 exit when No
(Aux_Unit
);
4808 end Is_Visible_Through_Renamings
;
4810 -- Start of processing for Install_Limited_Withed_Unit
4813 pragma Assert
(not Limited_View_Installed
(N
));
4815 -- In case of limited with_clause on subprograms, generics, instances,
4816 -- or renamings, the corresponding error was previously posted and we
4817 -- have nothing to do here. If the file is missing altogether, it has
4818 -- no source location.
4820 if Nkind
(P_Unit
) /= N_Package_Declaration
4821 or else Sloc
(P_Unit
) = No_Location
4826 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
4828 -- Handle child packages
4830 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
4831 Is_Child_Package
:= True;
4832 P
:= Defining_Identifier
(P
);
4835 -- Do not install the limited-view if the context of the unit is already
4836 -- available through a regular with clause.
4838 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4839 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4844 -- Do not install the limited-view if the full-view is already visible
4845 -- through renaming declarations.
4847 if Is_Visible_Through_Renamings
(P
) then
4851 -- Do not install the limited view if this is the unit being analyzed.
4852 -- This unusual case will happen when a unit has a limited_with clause
4853 -- on one of its children. The compilation of the child forces the load
4854 -- of the parent which tries to install the limited view of the child
4855 -- again. Installing the limited view must also be disabled when
4856 -- compiling the body of the child unit.
4858 if P
= Cunit_Entity
(Current_Sem_Unit
)
4859 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4860 and then P
= Main_Unit_Entity
4861 and then Is_Ancestor_Unit
4862 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
4867 -- This scenario is similar to the one above, the difference is that the
4868 -- compilation of sibling Par.Sib forces the load of parent Par which
4869 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4870 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4871 -- non-limited views of all entities from Lim_Pack.
4873 -- limited with Lim_Pack; -- [1]
4874 -- package Par is ... package Lim_Pack is ...
4876 -- with Lim_Pack; -- [2]
4877 -- package Par.Sib is ... package body Par.Sib is ...
4879 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4880 -- Sem_Unit is the body of Par.Sib.
4882 if Ekind
(P
) = E_Package
4883 and then Ekind
(Main_Unit_Entity
) = E_Package
4884 and then Is_Child_Unit
(Main_Unit_Entity
)
4886 -- The body has a regular with clause
4888 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4889 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4891 -- One of the ancestors has a limited with clause
4893 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
4894 N_Package_Specification
4895 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
4900 -- A common use of the limited-with is to have a limited-with in the
4901 -- package spec, and a normal with in its package body. For example:
4903 -- limited with X; -- [1]
4907 -- package body A is ...
4909 -- The compilation of A's body installs the context clauses found at [2]
4910 -- and then the context clauses of its specification (found at [1]). As
4911 -- a consequence, at [1] the specification of X has been analyzed and it
4912 -- is immediately visible. According to the semantics of limited-with
4913 -- context clauses we don't install the limited view because the full
4914 -- view of X supersedes its limited view.
4916 if Analyzed
(P_Unit
)
4918 (Is_Immediately_Visible
(P
)
4919 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
4922 -- The presence of both the limited and the analyzed nonlimited view
4923 -- may also be an error, such as an illegal context for a limited
4924 -- with_clause. In that case, do not process the context item at all.
4926 if Error_Posted
(N
) then
4930 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
4934 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4935 while Present
(Item
) loop
4936 if Nkind
(Item
) = N_With_Clause
4937 and then Comes_From_Source
(Item
)
4938 and then Entity
(Name
(Item
)) = P
4947 -- If this is a child body, assume that the nonlimited with_clause
4948 -- appears in an ancestor. Could be refined ???
4952 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
4959 -- If in package declaration, nonlimited view brought in from
4960 -- parent unit or some error condition.
4966 if Debug_Flag_I
then
4967 Write_Str
("install limited view of ");
4968 Write_Name
(Chars
(P
));
4972 -- If the unit has not been analyzed and the limited view has not been
4973 -- already installed then we install it.
4975 if not Analyzed
(P_Unit
) then
4976 if not In_Chain
(P
) then
4978 -- Minimum decoration
4980 Set_Ekind
(P
, E_Package
);
4981 Set_Etype
(P
, Standard_Void_Type
);
4982 Set_Scope
(P
, Standard_Standard
);
4983 Set_Is_Visible_Lib_Unit
(P
);
4985 if Is_Child_Package
then
4986 Set_Is_Child_Unit
(P
);
4987 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
4990 -- Place entity on visibility structure
4992 Set_Homonym
(P
, Current_Entity
(P
));
4993 Set_Current_Entity
(P
);
4995 if Debug_Flag_I
then
4996 Write_Str
(" (homonym) chain ");
4997 Write_Name
(Chars
(P
));
5001 -- Install the incomplete view. The first element of the limited
5002 -- view is a header (an E_Package entity) used to reference the
5003 -- first shadow entity in the private part of the package.
5005 Lim_Header
:= Limited_View
(P
);
5006 Lim_Typ
:= First_Entity
(Lim_Header
);
5008 while Present
(Lim_Typ
)
5009 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5011 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
5012 Set_Current_Entity
(Lim_Typ
);
5014 if Debug_Flag_I
then
5015 Write_Str
(" (homonym) chain ");
5016 Write_Name
(Chars
(Lim_Typ
));
5020 Next_Entity
(Lim_Typ
);
5024 -- If the unit appears in a previous regular with_clause, the regular
5025 -- entities of the public part of the withed package must be replaced
5026 -- by the shadow ones.
5028 -- This code must be kept synchronized with the code that replaces the
5029 -- shadow entities by the real entities (see body of Remove_Limited
5030 -- With_Clause); otherwise the contents of the homonym chains are not
5034 -- Hide all the type entities of the public part of the package to
5035 -- avoid its usage. This is needed to cover all the subtype decla-
5036 -- rations because we do not remove them from the homonym chain.
5038 E
:= First_Entity
(P
);
5039 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5041 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5048 -- Replace the real entities by the shadow entities of the limited
5049 -- view. The first element of the limited view is a header that is
5050 -- used to reference the first shadow entity in the private part
5051 -- of the package. Successive elements are the limited views of the
5052 -- type (including regular incomplete types) declared in the package.
5054 Lim_Header
:= Limited_View
(P
);
5056 Lim_Typ
:= First_Entity
(Lim_Header
);
5057 while Present
(Lim_Typ
)
5058 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5060 pragma Assert
(not In_Chain
(Lim_Typ
));
5062 -- Do not unchain nested packages and child units
5064 if Ekind
(Lim_Typ
) /= E_Package
5065 and then not Is_Child_Unit
(Lim_Typ
)
5071 Prev
:= Current_Entity
(Lim_Typ
);
5074 -- Replace E in the homonyms list, so that the limited view
5075 -- becomes available.
5077 -- If the non-limited view is a record with an anonymous
5078 -- self-referential component, the analysis of the record
5079 -- declaration creates an incomplete type with the same name
5080 -- in order to define an internal access type. The visible
5081 -- entity is now the incomplete type, and that is the one to
5082 -- replace in the visibility structure.
5084 if E
= Non_Limited_View
(Lim_Typ
)
5086 (Ekind
(E
) = E_Incomplete_Type
5087 and then Full_View
(E
) = Non_Limited_View
(Lim_Typ
))
5089 Set_Homonym
(Lim_Typ
, Homonym
(Prev
));
5090 Set_Current_Entity
(Lim_Typ
);
5094 E
:= Homonym
(Prev
);
5096 -- E may have been removed when installing a previous
5097 -- limited_with_clause.
5100 exit when E
= Non_Limited_View
(Lim_Typ
);
5101 Prev
:= Homonym
(Prev
);
5105 Set_Homonym
(Lim_Typ
, Homonym
(Homonym
(Prev
)));
5106 Set_Homonym
(Prev
, Lim_Typ
);
5111 if Debug_Flag_I
then
5112 Write_Str
(" (homonym) chain ");
5113 Write_Name
(Chars
(Lim_Typ
));
5118 Next_Entity
(Lim_Typ
);
5122 -- The package must be visible while the limited-with clause is active
5123 -- because references to the type P.T must resolve in the usual way.
5124 -- In addition, we remember that the limited-view has been installed to
5125 -- uninstall it at the point of context removal.
5127 Set_Is_Immediately_Visible
(P
);
5128 Set_Limited_View_Installed
(N
);
5130 -- If unit has not been analyzed in some previous context, check
5131 -- (imperfectly ???) whether it might need a body.
5133 if not Analyzed
(P_Unit
) then
5134 Check_Body_Required
;
5137 -- If the package in the limited_with clause is a child unit, the clause
5138 -- is unanalyzed and appears as a selected component. Recast it as an
5139 -- expanded name so that the entity can be properly set. Use entity of
5140 -- parent, if available, for higher ancestors in the name.
5142 if Nkind
(Name
(N
)) = N_Selected_Component
then
5150 while Nkind
(Nam
) = N_Selected_Component
5151 and then Present
(Ent
)
5153 Change_Selected_Component_To_Expanded_Name
(Nam
);
5155 -- Set entity of parent identifiers if the unit is a child
5156 -- unit. This ensures that the tree is properly formed from
5157 -- semantic point of view (e.g. for ASIS queries). The unit
5158 -- entities are not fully analyzed, so we need to follow unit
5159 -- links in the tree.
5161 Set_Entity
(Nam
, Ent
);
5163 Nam
:= Prefix
(Nam
);
5166 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5168 -- Set entity of last ancestor
5170 if Nkind
(Nam
) = N_Identifier
then
5171 Set_Entity
(Nam
, Ent
);
5177 Set_Entity
(Name
(N
), P
);
5178 Set_From_Limited_With
(P
);
5179 end Install_Limited_Withed_Unit
;
5181 -------------------------
5182 -- Install_Withed_Unit --
5183 -------------------------
5185 procedure Install_Withed_Unit
5186 (With_Clause
: Node_Id
;
5187 Private_With_OK
: Boolean := False)
5189 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5190 P
: constant Entity_Id
:= Scope
(Uname
);
5193 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5194 -- compiling a package declaration and the Private_With_OK flag was not
5195 -- set by the caller. These declarations will be installed later (before
5196 -- analyzing the private part of the package).
5198 if Private_Present
(With_Clause
)
5199 and then Nkind
(Unit
(Parent
(With_Clause
))) = N_Package_Declaration
5200 and then not (Private_With_OK
)
5205 if Debug_Flag_I
then
5206 if Private_Present
(With_Clause
) then
5207 Write_Str
("install private withed unit ");
5209 Write_Str
("install withed unit ");
5212 Write_Name
(Chars
(Uname
));
5216 -- We do not apply the restrictions to an internal unit unless we are
5217 -- compiling the internal unit as a main unit. This check is also
5218 -- skipped for dummy units (for missing packages).
5220 if Sloc
(Uname
) /= No_Location
5221 and then (not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
5222 or else Current_Sem_Unit
= Main_Unit
)
5224 Check_Restricted_Unit
5225 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5228 if P
/= Standard_Standard
then
5230 -- If the unit is not analyzed after analysis of the with clause and
5231 -- it is an instantiation then it awaits a body and is the main unit.
5232 -- Its appearance in the context of some other unit indicates a
5233 -- circular dependency (DEC suite perversity).
5235 if not Analyzed
(Uname
)
5236 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5239 ("instantiation depends on itself", Name
(With_Clause
));
5241 elsif not Is_Visible_Lib_Unit
(Uname
) then
5243 -- Abandon processing in case of previous errors
5245 if No
(Scope
(Uname
)) then
5246 Check_Error_Detected
;
5250 Set_Is_Visible_Lib_Unit
(Uname
);
5252 -- If the unit is a wrapper package for a compilation unit that is
5253 -- a subprogrm instance, indicate that the instance itself is a
5254 -- visible unit. This is necessary if the instance is inlined.
5256 if Is_Wrapper_Package
(Uname
) then
5257 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5260 -- If the child unit appears in the context of its parent, it is
5261 -- immediately visible.
5263 if In_Open_Scopes
(Scope
(Uname
)) then
5264 Set_Is_Immediately_Visible
(Uname
);
5267 if Is_Generic_Instance
(Uname
)
5268 and then Ekind
(Uname
) in Subprogram_Kind
5270 -- Set flag as well on the visible entity that denotes the
5271 -- instance, which renames the current one.
5273 Set_Is_Visible_Lib_Unit
5275 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5278 -- The parent unit may have been installed already, and may have
5279 -- appeared in a use clause.
5281 if In_Use
(Scope
(Uname
)) then
5282 Set_Is_Potentially_Use_Visible
(Uname
);
5285 Set_Context_Installed
(With_Clause
);
5288 elsif not Is_Immediately_Visible
(Uname
) then
5289 Set_Is_Visible_Lib_Unit
(Uname
);
5291 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5292 Set_Is_Immediately_Visible
(Uname
);
5295 Set_Context_Installed
(With_Clause
);
5298 -- A with-clause overrides a with-type clause: there are no restric-
5299 -- tions on the use of package entities.
5301 if Ekind
(Uname
) = E_Package
then
5302 Set_From_Limited_With
(Uname
, False);
5305 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5306 -- unit if there is a visible homograph for it declared in the same
5307 -- declarative region. This pathological case can only arise when an
5308 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5309 -- G1 has a generic child also named G2, and the context includes with_
5310 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5311 -- of I1.G2 visible as well. If the child unit is named Standard, do
5312 -- not apply the check to the Standard package itself.
5314 if Is_Child_Unit
(Uname
)
5315 and then Is_Visible_Lib_Unit
(Uname
)
5316 and then Ada_Version
>= Ada_2005
5319 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5325 U2
:= Homonym
(Uname
);
5326 while Present
(U2
) and then U2
/= Standard_Standard
loop
5328 Decl2
:= Unit_Declaration_Node
(P2
);
5330 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5331 if Is_Generic_Instance
(P
)
5332 and then Nkind
(Decl1
) = N_Package_Declaration
5333 and then Generic_Parent
(Specification
(Decl1
)) = P2
5335 Error_Msg_N
("illegal with_clause", With_Clause
);
5337 ("\child unit has visible homograph" &
5338 " (RM 8.3(26), 10.1.1(19))",
5342 elsif Is_Generic_Instance
(P2
)
5343 and then Nkind
(Decl2
) = N_Package_Declaration
5344 and then Generic_Parent
(Specification
(Decl2
)) = P
5346 -- With_clause for child unit of instance appears before
5347 -- in the context. We want to place the error message on
5348 -- it, not on the generic child unit itself.
5351 Prev_Clause
: Node_Id
;
5354 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5355 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5359 pragma Assert
(Present
(Prev_Clause
));
5360 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5362 ("\child unit has visible homograph" &
5363 " (RM 8.3(26), 10.1.1(19))",
5374 end Install_Withed_Unit
;
5380 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5381 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5384 return (K
in N_Generic_Declaration
or else
5385 K
in N_Generic_Instantiation
or else
5386 K
in N_Generic_Renaming_Declaration
or else
5387 K
= N_Package_Declaration
or else
5388 K
= N_Package_Renaming_Declaration
or else
5389 K
= N_Subprogram_Declaration
or else
5390 K
= N_Subprogram_Renaming_Declaration
)
5391 and then Present
(Parent_Spec
(Lib_Unit
));
5394 ------------------------------------
5395 -- Is_Legal_Shadow_Entity_In_Body --
5396 ------------------------------------
5398 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5399 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5401 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5404 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5405 end Is_Legal_Shadow_Entity_In_Body
;
5407 ----------------------
5408 -- Is_Ancestor_Unit --
5409 ----------------------
5411 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5412 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5415 if Nkind_In
(Unit
(U2
), N_Package_Body
, N_Subprogram_Body
) then
5416 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5417 return Is_Ancestor_Package
(E1
, E2
);
5421 end Is_Ancestor_Unit
;
5423 -----------------------
5424 -- Load_Needed_Body --
5425 -----------------------
5427 -- N is a generic unit named in a with clause, or else it is a unit that
5428 -- contains a generic unit or an inlined function. In order to perform an
5429 -- instantiation, the body of the unit must be present. If the unit itself
5430 -- is generic, we assume that an instantiation follows, and load & analyze
5431 -- the body unconditionally. This forces analysis of the spec as well.
5433 -- If the unit is not generic, but contains a generic unit, it is loaded on
5434 -- demand, at the point of instantiation (see ch12).
5436 procedure Load_Needed_Body
5439 Do_Analyze
: Boolean := True)
5441 Body_Name
: Unit_Name_Type
;
5442 Unum
: Unit_Number_Type
;
5444 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5445 -- The loading and analysis is done with style checks off
5448 if not GNAT_Mode
then
5449 Style_Check
:= False;
5452 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5455 (Load_Name
=> Body_Name
,
5461 if Unum
= No_Unit
then
5465 Compiler_State
:= Analyzing
; -- reset after load
5467 if Fatal_Error
(Unum
) /= Error_Detected
or else Try_Semantics
then
5468 if Debug_Flag_L
then
5469 Write_Str
("*** Loaded generic body");
5474 Semantics
(Cunit
(Unum
));
5481 Style_Check
:= Save_Style_Check
;
5482 end Load_Needed_Body
;
5484 -------------------------
5485 -- Build_Limited_Views --
5486 -------------------------
5488 procedure Build_Limited_Views
(N
: Node_Id
) is
5489 Unum
: constant Unit_Number_Type
:=
5490 Get_Source_Unit
(Library_Unit
(N
));
5491 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5493 Shadow_Pack
: Entity_Id
;
5494 -- The corresponding shadow entity of the withed package. This entity
5495 -- offers incomplete views of packages and types as well as abstract
5496 -- views of states and variables declared within.
5498 Last_Shadow
: Entity_Id
:= Empty
;
5499 -- The last shadow entity created by routine Build_Shadow_Entity
5501 procedure Build_Shadow_Entity
5504 Shadow
: out Entity_Id
;
5505 Is_Tagged
: Boolean := False);
5506 -- Create a shadow entity that hides Ent and offers an abstract or
5507 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5508 -- should be set when Ent is a tagged type. The generated entity is
5509 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5511 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5512 -- Perform minimal decoration of a package or its corresponding shadow
5513 -- entity denoted by Ent. Scop is the proper scope.
5515 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5516 -- Perform full decoration of an abstract state or its corresponding
5517 -- shadow entity denoted by Ent. Scop is the proper scope.
5519 procedure Decorate_Type
5522 Is_Tagged
: Boolean := False;
5523 Materialize
: Boolean := False);
5524 -- Perform minimal decoration of a type or its corresponding shadow
5525 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5526 -- should be set when Ent is a tagged type. Flag Materialize should be
5527 -- set when Ent is a tagged type and its class-wide type needs to appear
5530 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5531 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5534 procedure Process_Declarations_And_States
5538 Create_Abstract_Views
: Boolean);
5539 -- Inspect the states of package Pack and declarative list Decls. Create
5540 -- shadow entities for all nested packages, states, types and variables
5541 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5542 -- be set when the abstract states and variables need to be processed.
5544 -------------------------
5545 -- Build_Shadow_Entity --
5546 -------------------------
5548 procedure Build_Shadow_Entity
5551 Shadow
: out Entity_Id
;
5552 Is_Tagged
: Boolean := False)
5555 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5557 -- The shadow entity must share the same name and parent as the
5560 Set_Chars
(Shadow
, Chars
(Ent
));
5561 Set_Parent
(Shadow
, Parent
(Ent
));
5563 -- The abstract view of a variable is a state, not another variable
5565 if Ekind
(Ent
) = E_Variable
then
5566 Set_Ekind
(Shadow
, E_Abstract_State
);
5568 Set_Ekind
(Shadow
, Ekind
(Ent
));
5571 Set_Is_Internal
(Shadow
);
5572 Set_From_Limited_With
(Shadow
);
5574 -- Add the new shadow entity to the limited view of the package
5576 Last_Shadow
:= Shadow
;
5577 Append_Entity
(Shadow
, Shadow_Pack
);
5579 -- Perform context-specific decoration of the shadow entity
5581 if Ekind
(Ent
) = E_Abstract_State
then
5582 Decorate_State
(Shadow
, Scop
);
5583 Set_Non_Limited_View
(Shadow
, Ent
);
5585 elsif Ekind
(Ent
) = E_Package
then
5586 Decorate_Package
(Shadow
, Scop
);
5588 elsif Is_Type
(Ent
) then
5589 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
5590 Set_Non_Limited_View
(Shadow
, Ent
);
5593 Set_Non_Limited_View
5594 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Ent
));
5597 if Is_Incomplete_Or_Private_Type
(Ent
) then
5598 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
5601 elsif Ekind
(Ent
) = E_Variable
then
5602 Decorate_State
(Shadow
, Scop
);
5603 Set_Non_Limited_View
(Shadow
, Ent
);
5605 end Build_Shadow_Entity
;
5607 ----------------------
5608 -- Decorate_Package --
5609 ----------------------
5611 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5613 Set_Ekind
(Ent
, E_Package
);
5614 Set_Etype
(Ent
, Standard_Void_Type
);
5615 Set_Scope
(Ent
, Scop
);
5616 end Decorate_Package
;
5618 --------------------
5619 -- Decorate_State --
5620 --------------------
5622 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5624 Set_Ekind
(Ent
, E_Abstract_State
);
5625 Set_Etype
(Ent
, Standard_Void_Type
);
5626 Set_Scope
(Ent
, Scop
);
5627 Set_Encapsulating_State
(Ent
, Empty
);
5634 procedure Decorate_Type
5637 Is_Tagged
: Boolean := False;
5638 Materialize
: Boolean := False)
5643 -- An unanalyzed type or a shadow entity of a type is treated as an
5644 -- incomplete type, and carries the corresponding attributes.
5646 Set_Ekind
(Ent
, E_Incomplete_Type
);
5647 Set_Etype
(Ent
, Ent
);
5648 Set_Full_View
(Ent
, Empty
);
5649 Set_Is_First_Subtype
(Ent
);
5650 Set_Scope
(Ent
, Scop
);
5651 Set_Stored_Constraint
(Ent
, No_Elist
);
5652 Init_Size_Align
(Ent
);
5654 if From_Limited_With
(Ent
) then
5655 Set_Private_Dependents
(Ent
, New_Elmt_List
);
5658 -- A tagged type and its corresponding shadow entity share one common
5659 -- class-wide type. The list of primitive operations for the shadow
5663 Set_Is_Tagged_Type
(Ent
);
5664 Set_Direct_Primitive_Operations
(Ent
, New_Elmt_List
);
5668 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
5670 Set_Class_Wide_Type
(Ent
, CW_Typ
);
5672 -- Set parent to be the same as the parent of the tagged type.
5673 -- We need a parent field set, and it is supposed to point to
5674 -- the declaration of the type. The tagged type declaration
5675 -- essentially declares two separate types, the tagged type
5676 -- itself and the corresponding class-wide type, so it is
5677 -- reasonable for the parent fields to point to the declaration
5680 Set_Parent
(CW_Typ
, Parent
(Ent
));
5682 Set_Ekind
(CW_Typ
, E_Class_Wide_Type
);
5683 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
5684 Set_Etype
(CW_Typ
, Ent
);
5685 Set_Equivalent_Type
(CW_Typ
, Empty
);
5686 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
5687 Set_Has_Unknown_Discriminants
(CW_Typ
);
5688 Set_Is_First_Subtype
(CW_Typ
);
5689 Set_Is_Tagged_Type
(CW_Typ
);
5690 Set_Materialize_Entity
(CW_Typ
, Materialize
);
5691 Set_Scope
(CW_Typ
, Scop
);
5692 Init_Size_Align
(CW_Typ
);
5696 -----------------------
5697 -- Decorate_Variable --
5698 -----------------------
5700 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5702 Set_Ekind
(Ent
, E_Variable
);
5703 Set_Etype
(Ent
, Standard_Void_Type
);
5704 Set_Scope
(Ent
, Scop
);
5705 end Decorate_Variable
;
5707 -------------------------------------
5708 -- Process_Declarations_And_States --
5709 -------------------------------------
5711 procedure Process_Declarations_And_States
5715 Create_Abstract_Views
: Boolean)
5717 procedure Find_And_Process_States
;
5718 -- Determine whether package Pack defines abstract state either by
5719 -- using an aspect or a pragma. If this is the case, build shadow
5720 -- entities for all abstract states of Pack.
5722 procedure Process_States
(States
: Elist_Id
);
5723 -- Generate shadow entities for all abstract states in list States
5725 -----------------------------
5726 -- Find_And_Process_States --
5727 -----------------------------
5729 procedure Find_And_Process_States
is
5730 procedure Process_State
(State
: Node_Id
);
5731 -- Generate shadow entities for a single abstract state or
5732 -- multiple states expressed as an aggregate.
5738 procedure Process_State
(State
: Node_Id
) is
5739 Loc
: constant Source_Ptr
:= Sloc
(State
);
5746 -- Multiple abstract states appear as an aggregate
5748 if Nkind
(State
) = N_Aggregate
then
5749 Elmt
:= First
(Expressions
(State
));
5750 while Present
(Elmt
) loop
5751 Process_State
(Elmt
);
5757 -- A null state has no abstract view
5759 elsif Nkind
(State
) = N_Null
then
5762 -- State declaration with various options appears as an
5763 -- extension aggregate.
5765 elsif Nkind
(State
) = N_Extension_Aggregate
then
5766 Decl
:= Ancestor_Part
(State
);
5768 -- Simple state declaration
5770 elsif Nkind
(State
) = N_Identifier
then
5773 -- Possibly an illegal state declaration
5779 -- Abstract states are elaborated when the related pragma is
5780 -- elaborated. Since the withed package is not analyzed yet,
5781 -- the entities of the abstract states are not available. To
5782 -- overcome this complication, create the entities now and
5783 -- store them in their respective declarations. The entities
5784 -- are later used by routine Create_Abstract_State to declare
5785 -- and enter the states into visibility.
5787 if No
(Entity
(Decl
)) then
5788 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
5790 Set_Entity
(Decl
, Id
);
5791 Set_Parent
(Id
, State
);
5792 Decorate_State
(Id
, Scop
);
5794 -- Otherwise the package was previously withed
5797 Id
:= Entity
(Decl
);
5800 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
5805 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
5809 -- Start of processing for Find_And_Process_States
5812 -- Find aspect Abstract_State
5814 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
5815 while Present
(Asp
) loop
5816 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
5817 Process_State
(Expression
(Asp
));
5825 -- Find pragma Abstract_State by inspecting the declarations
5827 Decl
:= First
(Decls
);
5828 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
5829 if Pragma_Name_Mapped
(Decl
) = Name_Abstract_State
then
5832 (First
(Pragma_Argument_Associations
(Decl
))));
5839 end Find_And_Process_States
;
5841 --------------------
5842 -- Process_States --
5843 --------------------
5845 procedure Process_States
(States
: Elist_Id
) is
5850 Elmt
:= First_Elmt
(States
);
5851 while Present
(Elmt
) loop
5852 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
5860 Is_Tagged
: Boolean;
5866 -- Start of processing for Process_Declarations_And_States
5869 -- Build abstract views for all states defined in the package
5871 if Create_Abstract_Views
then
5873 -- When a package has been analyzed, all states are stored in list
5874 -- Abstract_States. Generate the shadow entities directly.
5877 if Present
(Abstract_States
(Pack
)) then
5878 Process_States
(Abstract_States
(Pack
));
5881 -- The package may declare abstract states by using an aspect or a
5882 -- pragma. Attempt to locate one of these construct and if found,
5883 -- build the shadow entities.
5886 Find_And_Process_States
;
5890 -- Inspect the declarative list, looking for nested packages, types
5891 -- and variable declarations.
5893 Decl
:= First
(Decls
);
5894 while Present
(Decl
) loop
5898 if Nkind
(Decl
) = N_Package_Declaration
then
5899 Def_Id
:= Defining_Entity
(Decl
);
5901 -- Perform minor decoration when the withed package has not
5904 if not Is_Analyzed
then
5905 Decorate_Package
(Def_Id
, Scop
);
5908 -- Create a shadow entity that offers a limited view of all
5909 -- visible types declared within.
5911 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5913 Process_Declarations_And_States
5915 Decls
=> Visible_Declarations
(Specification
(Decl
)),
5917 Create_Abstract_Views
=> Create_Abstract_Views
);
5921 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
5922 N_Incomplete_Type_Declaration
,
5923 N_Private_Extension_Declaration
,
5924 N_Private_Type_Declaration
,
5925 N_Protected_Type_Declaration
,
5926 N_Task_Type_Declaration
)
5928 Def_Id
:= Defining_Entity
(Decl
);
5930 -- Determine whether the type is tagged. Note that packages
5931 -- included via a limited with clause are not always analyzed,
5932 -- hence the tree lookup rather than the use of attribute
5935 if Nkind
(Decl
) = N_Full_Type_Declaration
then
5936 Def
:= Type_Definition
(Decl
);
5939 (Nkind
(Def
) = N_Record_Definition
5940 and then Tagged_Present
(Def
))
5942 (Nkind
(Def
) = N_Derived_Type_Definition
5943 and then Present
(Record_Extension_Part
(Def
)));
5945 elsif Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
5946 N_Private_Type_Declaration
)
5948 Is_Tagged
:= Tagged_Present
(Decl
);
5950 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
5957 -- Perform minor decoration when the withed package has not
5960 if not Is_Analyzed
then
5961 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
5964 -- Create a shadow entity that hides the type and offers an
5965 -- incomplete view of the said type.
5967 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
5971 elsif Create_Abstract_Views
5972 and then Nkind
(Decl
) = N_Object_Declaration
5973 and then not Constant_Present
(Decl
)
5975 Def_Id
:= Defining_Entity
(Decl
);
5977 -- Perform minor decoration when the withed package has not
5980 if not Is_Analyzed
then
5981 Decorate_Variable
(Def_Id
, Scop
);
5984 -- Create a shadow entity that hides the variable and offers an
5985 -- abstract view of the said variable.
5987 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5992 end Process_Declarations_And_States
;
5996 Nam
: constant Node_Id
:= Name
(N
);
5997 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
5999 Last_Public_Shadow
: Entity_Id
:= Empty
;
6000 Private_Shadow
: Entity_Id
;
6003 -- Start of processing for Build_Limited_Views
6006 pragma Assert
(Limited_Present
(N
));
6008 -- A library_item mentioned in a limited_with_clause is a package
6009 -- declaration, not a subprogram declaration, generic declaration,
6010 -- generic instantiation, or package renaming declaration.
6012 case Nkind
(Unit
(Library_Unit
(N
))) is
6013 when N_Package_Declaration
=>
6016 when N_Subprogram_Declaration
=>
6017 Error_Msg_N
("subprograms not allowed in limited with_clauses", N
);
6020 when N_Generic_Package_Declaration |
6021 N_Generic_Subprogram_Declaration
=>
6022 Error_Msg_N
("generics not allowed in limited with_clauses", N
);
6025 when N_Generic_Instantiation
=>
6027 ("generic instantiations not allowed in limited with_clauses",
6031 when N_Generic_Renaming_Declaration
=>
6033 ("generic renamings not allowed in limited with_clauses", N
);
6036 when N_Subprogram_Renaming_Declaration
=>
6038 ("renamed subprograms not allowed in limited with_clauses", N
);
6041 when N_Package_Renaming_Declaration
=>
6043 ("renamed packages not allowed in limited with_clauses", N
);
6047 raise Program_Error
;
6050 -- The withed unit may not be analyzed, but the with calause itself
6051 -- must be minimally decorated. This ensures that the checks on unused
6052 -- with clauses also process limieted withs.
6054 Set_Ekind
(Pack
, E_Package
);
6055 Set_Etype
(Pack
, Standard_Void_Type
);
6057 if Is_Entity_Name
(Nam
) then
6058 Set_Entity
(Nam
, Pack
);
6060 elsif Nkind
(Nam
) = N_Selected_Component
then
6061 Set_Entity
(Selector_Name
(Nam
), Pack
);
6064 -- Check if the chain is already built
6066 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6068 if Limited_View_Installed
(Spec
) then
6072 -- Create the shadow package wich hides the withed unit and provides
6073 -- incomplete view of all types and packages declared within.
6075 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6076 Set_Ekind
(Shadow_Pack
, E_Package
);
6077 Set_Is_Internal
(Shadow_Pack
);
6078 Set_Limited_View
(Pack
, Shadow_Pack
);
6080 -- Inspect the abstract states and visible declarations of the withed
6081 -- unit and create shadow entities that hide existing packages, states,
6082 -- variables and types.
6084 Process_Declarations_And_States
6086 Decls
=> Visible_Declarations
(Spec
),
6088 Create_Abstract_Views
=> True);
6090 Last_Public_Shadow
:= Last_Shadow
;
6092 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6093 -- to accomodate limited private with clauses.
6095 Process_Declarations_And_States
6097 Decls
=> Private_Declarations
(Spec
),
6099 Create_Abstract_Views
=> False);
6101 if Present
(Last_Public_Shadow
) then
6102 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6104 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6107 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6108 Set_Limited_View_Installed
(Spec
);
6109 end Build_Limited_Views
;
6111 ----------------------------
6112 -- Check_No_Elab_Code_All --
6113 ----------------------------
6115 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6117 if Present
(No_Elab_Code_All_Pragma
)
6118 and then In_Extended_Main_Source_Unit
(N
)
6119 and then Present
(Context_Items
(N
))
6122 CL
: constant List_Id
:= Context_Items
(N
);
6127 while Present
(CI
) loop
6128 if Nkind
(CI
) = N_With_Clause
6130 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6132 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6134 ("violation of No_Elaboration_Code_All#", CI
);
6136 ("\unit& does not have No_Elaboration_Code_All",
6137 CI
, Entity
(Name
(CI
)));
6144 end Check_No_Elab_Code_All
;
6146 -------------------------------
6147 -- Check_Body_Needed_For_SAL --
6148 -------------------------------
6150 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6151 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6152 -- Determine whether use of entity E might require the presence of its
6153 -- body. For a package this requires a recursive traversal of all nested
6156 -----------------------
6157 -- Entity_Needs_Body --
6158 -----------------------
6160 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6164 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6167 elsif Ekind_In
(E
, E_Generic_Function
, E_Generic_Procedure
) then
6169 -- A generic subprogram always requires the presence of its
6170 -- body because an instantiation needs both templates. The only
6171 -- exceptions is a generic subprogram renaming. In this case the
6172 -- body is needed only when the template is declared outside the
6173 -- compilation unit being checked.
6175 if Present
(Renamed_Entity
(E
)) then
6176 return not Within_Scope
(E
, Unit_Name
);
6181 elsif Ekind
(E
) = E_Generic_Package
6183 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6184 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6188 elsif Ekind
(E
) = E_Package
6189 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6190 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6192 Ent
:= First_Entity
(E
);
6193 while Present
(Ent
) loop
6194 if Entity_Needs_Body
(Ent
) then
6206 end Entity_Needs_Body
;
6208 -- Start of processing for Check_Body_Needed_For_SAL
6211 if Ekind
(Unit_Name
) = E_Generic_Package
6212 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6213 N_Generic_Package_Declaration
6215 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6217 Set_Body_Needed_For_SAL
(Unit_Name
);
6219 elsif Ekind_In
(Unit_Name
, E_Generic_Procedure
, E_Generic_Function
) then
6220 Set_Body_Needed_For_SAL
(Unit_Name
);
6222 elsif Is_Subprogram
(Unit_Name
)
6223 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6224 N_Subprogram_Declaration
6225 and then Has_Pragma_Inline
(Unit_Name
)
6227 Set_Body_Needed_For_SAL
(Unit_Name
);
6229 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6230 Check_Body_Needed_For_SAL
6231 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6233 elsif Ekind
(Unit_Name
) = E_Package
6234 and then Entity_Needs_Body
(Unit_Name
)
6236 Set_Body_Needed_For_SAL
(Unit_Name
);
6238 elsif Ekind
(Unit_Name
) = E_Package_Body
6239 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6241 Check_Body_Needed_For_SAL
6242 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6244 end Check_Body_Needed_For_SAL
;
6246 --------------------
6247 -- Remove_Context --
6248 --------------------
6250 procedure Remove_Context
(N
: Node_Id
) is
6251 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6254 -- If this is a child unit, first remove the parent units
6256 if Is_Child_Spec
(Lib_Unit
) then
6257 Remove_Parents
(Lib_Unit
);
6260 Remove_Context_Clauses
(N
);
6263 ----------------------------
6264 -- Remove_Context_Clauses --
6265 ----------------------------
6267 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6269 Unit_Name
: Entity_Id
;
6272 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6273 -- limited-views first and regular-views later (to maintain the
6276 -- First Phase: Remove limited_with context clauses
6278 Item
:= First
(Context_Items
(N
));
6279 while Present
(Item
) loop
6281 -- We are interested only in with clauses which got installed
6284 if Nkind
(Item
) = N_With_Clause
6285 and then Limited_Present
(Item
)
6286 and then Limited_View_Installed
(Item
)
6288 Remove_Limited_With_Clause
(Item
);
6294 -- Second Phase: Loop through context items and undo regular
6295 -- with_clauses and use_clauses.
6297 Item
:= First
(Context_Items
(N
));
6298 while Present
(Item
) loop
6300 -- We are interested only in with clauses which got installed on
6301 -- entry, as indicated by their Context_Installed flag set
6303 if Nkind
(Item
) = N_With_Clause
6304 and then Limited_Present
(Item
)
6305 and then Limited_View_Installed
(Item
)
6309 elsif Nkind
(Item
) = N_With_Clause
6310 and then Context_Installed
(Item
)
6312 -- Remove items from one with'ed unit
6314 Unit_Name
:= Entity
(Name
(Item
));
6315 Remove_Unit_From_Visibility
(Unit_Name
);
6316 Set_Context_Installed
(Item
, False);
6318 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6319 End_Use_Package
(Item
);
6321 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6322 End_Use_Type
(Item
);
6327 end Remove_Context_Clauses
;
6329 --------------------------------
6330 -- Remove_Limited_With_Clause --
6331 --------------------------------
6333 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6334 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6337 Lim_Header
: Entity_Id
;
6338 Lim_Typ
: Entity_Id
;
6342 pragma Assert
(Limited_View_Installed
(N
));
6344 -- In case of limited with_clause on subprograms, generics, instances,
6345 -- or renamings, the corresponding error was previously posted and we
6346 -- have nothing to do here.
6348 if Nkind
(P_Unit
) /= N_Package_Declaration
then
6352 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
6354 -- Handle child packages
6356 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
6357 P
:= Defining_Identifier
(P
);
6360 if Debug_Flag_I
then
6361 Write_Str
("remove limited view of ");
6362 Write_Name
(Chars
(P
));
6363 Write_Str
(" from visibility");
6367 -- Prepare the removal of the shadow entities from visibility. The first
6368 -- element of the limited view is a header (an E_Package entity) that is
6369 -- used to reference the first shadow entity in the private part of the
6372 Lim_Header
:= Limited_View
(P
);
6373 Lim_Typ
:= First_Entity
(Lim_Header
);
6375 -- Remove package and shadow entities from visibility if it has not
6378 if not Analyzed
(P_Unit
) then
6380 Set_Is_Immediately_Visible
(P
, False);
6382 while Present
(Lim_Typ
) loop
6384 Next_Entity
(Lim_Typ
);
6387 -- Otherwise this package has already appeared in the closure and its
6388 -- shadow entities must be replaced by its real entities. This code
6389 -- must be kept synchronized with the complementary code in Install
6390 -- Limited_Withed_Unit.
6393 -- If the limited_with_clause is in some other unit in the context
6394 -- then it is not visible in the main unit.
6396 if not In_Extended_Main_Source_Unit
(N
) then
6397 Set_Is_Immediately_Visible
(P
, False);
6400 -- Real entities that are type or subtype declarations were hidden
6401 -- from visibility at the point of installation of the limited-view.
6402 -- Now we recover the previous value of the hidden attribute.
6404 E
:= First_Entity
(P
);
6405 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
6407 Set_Is_Hidden
(E
, Was_Hidden
(E
));
6413 while Present
(Lim_Typ
)
6414 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
6416 -- Nested packages and child units were not unchained
6418 if Ekind
(Lim_Typ
) /= E_Package
6419 and then not Is_Child_Unit
(Non_Limited_View
(Lim_Typ
))
6421 -- If the package has incomplete types, the limited view of the
6422 -- incomplete type is in fact never visible (AI05-129) but we
6423 -- have created a shadow entity E1 for it, that points to E2,
6424 -- a non-limited incomplete type. This in turn has a full view
6425 -- E3 that is the full declaration. There is a corresponding
6426 -- shadow entity E4. When reinstalling the non-limited view,
6427 -- E2 must become the current entity and E3 must be ignored.
6429 E
:= Non_Limited_View
(Lim_Typ
);
6431 if Present
(Current_Entity
(E
))
6432 and then Ekind
(Current_Entity
(E
)) = E_Incomplete_Type
6433 and then Full_View
(Current_Entity
(E
)) = E
6436 -- Lim_Typ is the limited view of a full type declaration
6437 -- that has a previous incomplete declaration, i.e. E3 from
6438 -- the previous description. Nothing to insert.
6443 pragma Assert
(not In_Chain
(E
));
6445 Prev
:= Current_Entity
(Lim_Typ
);
6447 if Prev
= Lim_Typ
then
6448 Set_Current_Entity
(E
);
6451 while Present
(Prev
)
6452 and then Homonym
(Prev
) /= Lim_Typ
6454 Prev
:= Homonym
(Prev
);
6457 if Present
(Prev
) then
6458 Set_Homonym
(Prev
, E
);
6462 -- Preserve structure of homonym chain
6464 Set_Homonym
(E
, Homonym
(Lim_Typ
));
6468 Next_Entity
(Lim_Typ
);
6472 -- Indicate that the limited view of the package is not installed
6474 Set_From_Limited_With
(P
, False);
6475 Set_Limited_View_Installed
(N
, False);
6476 end Remove_Limited_With_Clause
;
6478 --------------------
6479 -- Remove_Parents --
6480 --------------------
6482 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
6485 P_Spec
: Node_Id
:= Empty
;
6487 Vis
: constant Boolean :=
6488 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
6491 if Is_Child_Spec
(Lib_Unit
) then
6492 P_Spec
:= Parent_Spec
(Lib_Unit
);
6494 elsif Nkind
(Lib_Unit
) = N_Package_Body
6495 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
6497 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
6500 if Present
(P_Spec
) then
6502 P_Name
:= Get_Parent_Entity
(P
);
6503 Remove_Context_Clauses
(P_Spec
);
6504 End_Package_Scope
(P_Name
);
6505 Set_Is_Immediately_Visible
(P_Name
, Vis
);
6507 -- Remove from visibility the siblings as well, which are directly
6508 -- visible while the parent is in scope.
6510 E
:= First_Entity
(P_Name
);
6511 while Present
(E
) loop
6512 if Is_Child_Unit
(E
) then
6513 Set_Is_Immediately_Visible
(E
, False);
6519 Set_In_Package_Body
(P_Name
, False);
6521 -- This is the recursive call to remove the context of any higher
6522 -- level parent. This recursion ensures that all parents are removed
6523 -- in the reverse order of their installation.
6529 ---------------------------------
6530 -- Remove_Private_With_Clauses --
6531 ---------------------------------
6533 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
6536 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
6537 -- Check whether a given unit appears in a regular with_clause. Used to
6538 -- determine whether a private_with_clause, implicit or explicit, should
6541 ----------------------------
6542 -- In_Regular_With_Clause --
6543 ----------------------------
6545 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean
6550 Item
:= First
(Context_Items
(Comp_Unit
));
6551 while Present
(Item
) loop
6552 if Nkind
(Item
) = N_With_Clause
6554 -- The following guard is needed to ensure that the name has
6555 -- been properly analyzed before we go fetching its entity.
6557 and then Is_Entity_Name
(Name
(Item
))
6558 and then Entity
(Name
(Item
)) = E
6559 and then not Private_Present
(Item
)
6567 end In_Regular_With_Clause
;
6569 -- Start of processing for Remove_Private_With_Clauses
6572 Item
:= First
(Context_Items
(Comp_Unit
));
6573 while Present
(Item
) loop
6574 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
6576 -- If private_with_clause is redundant, remove it from context,
6577 -- as a small optimization to subsequent handling of private_with
6578 -- clauses in other nested packages.
6580 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
6582 Nxt
: constant Node_Id
:= Next
(Item
);
6588 elsif Limited_Present
(Item
) then
6589 if not Limited_View_Installed
(Item
) then
6590 Remove_Limited_With_Clause
(Item
);
6596 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
6597 Set_Context_Installed
(Item
, False);
6605 end Remove_Private_With_Clauses
;
6607 ---------------------------------
6608 -- Remove_Unit_From_Visibility --
6609 ---------------------------------
6611 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
6613 if Debug_Flag_I
then
6614 Write_Str
("remove unit ");
6615 Write_Name
(Chars
(Unit_Name
));
6616 Write_Str
(" from visibility");
6620 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
6621 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
6622 Set_Is_Immediately_Visible
(Unit_Name
, False);
6624 -- If the unit is a wrapper package, the subprogram instance is
6625 -- what must be removed from visibility.
6626 -- Should we use Related_Instance instead???
6628 if Is_Wrapper_Package
(Unit_Name
) then
6629 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
6631 end Remove_Unit_From_Visibility
;
6646 procedure Unchain
(E
: Entity_Id
) is
6650 Prev
:= Current_Entity
(E
);
6656 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6659 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
6660 Prev
:= Homonym
(Prev
);
6663 if Present
(Prev
) then
6664 Set_Homonym
(Prev
, Homonym
(E
));
6668 if Debug_Flag_I
then
6669 Write_Str
(" (homonym) unchain ");
6670 Write_Name
(Chars
(E
));