1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Errout
; use Errout
;
31 with Exp_Util
; use Exp_Util
;
32 with Elists
; use Elists
;
33 with Fname
; use Fname
;
34 with Fname
.UF
; use Fname
.UF
;
35 with Freeze
; use Freeze
;
36 with Impunit
; use Impunit
;
37 with Inline
; use Inline
;
39 with Lib
.Load
; use Lib
.Load
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Output
; use Output
;
46 with Par_SCO
; use Par_SCO
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch12
; use Sem_Ch12
;
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 Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
);
88 -- Check whether the source for the body of a compilation unit must be
89 -- included in a standalone library.
91 procedure Check_No_Elab_Code_All
(N
: Node_Id
);
92 -- Carries out possible tests for violation of No_Elab_Code all for withed
93 -- units in the Context_Items of unit N.
95 procedure Check_Private_Child_Unit
(N
: Node_Id
);
96 -- If a with_clause mentions a private child unit, the compilation unit
97 -- must be a member of the same family, as described in 10.1.2.
99 procedure Check_Stub_Level
(N
: Node_Id
);
100 -- Verify that a stub is declared immediately within a compilation unit,
101 -- and not in an inner frame.
103 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
);
104 -- When a child unit appears in a context clause, the implicit withs on
105 -- parents are made explicit, and with clauses are inserted in the context
106 -- clause before the one for the child. If a parent in the with_clause
107 -- is a renaming, the implicit with_clause is on the renaming whose name
108 -- is mentioned in the with_clause, and not on the package it renames.
109 -- N is the compilation unit whose list of context items receives the
110 -- implicit with_clauses.
112 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
);
113 -- Generate cross-reference information for the parents of child units
114 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
115 -- immediate parent scope.
117 function Has_With_Clause
120 Is_Limited
: Boolean := False) return Boolean;
121 -- Determine whether compilation unit C_Unit contains a [limited] with
122 -- clause for package Pack. Use the flag Is_Limited to designate desired
125 procedure Implicit_With_On_Parent
(Child_Unit
: Node_Id
; N
: Node_Id
);
126 -- If the main unit is a child unit, implicit withs are also added for
127 -- all its ancestors.
129 function In_Chain
(E
: Entity_Id
) return Boolean;
130 -- Check that the shadow entity is not already in the homonym chain, for
131 -- example through a limited_with clause in a parent unit.
133 procedure Install_Context_Clauses
(N
: Node_Id
);
134 -- Subsidiary to Install_Context and Install_Parents. Process all with
135 -- and use clauses for current unit and its library unit if any.
137 procedure Install_Limited_Context_Clauses
(N
: Node_Id
);
138 -- Subsidiary to Install_Context. Process only limited with_clauses for
139 -- current unit. Implements Ada 2005 (AI-50217).
141 procedure Install_Limited_Withed_Unit
(N
: Node_Id
);
142 -- Place shadow entities for a limited_with package in the visibility
143 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
145 procedure Install_Withed_Unit
146 (With_Clause
: Node_Id
;
147 Private_With_OK
: Boolean := False);
148 -- If the unit is not a child unit, make unit immediately visible. The
149 -- caller ensures that the unit is not already currently installed. The
150 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
151 -- is called when compiling the private part of a package, or installing
152 -- the private declarations of a parent unit.
154 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean);
155 -- This procedure establishes the context for the compilation of a child
156 -- unit. If Lib_Unit is a child library spec then the context of the parent
157 -- is installed, and the parent itself made immediately visible, so that
158 -- the child unit is processed in the declarative region of the parent.
159 -- Install_Parents makes a recursive call to itself to ensure that all
160 -- parents are loaded in the nested case. If Lib_Unit is a library body,
161 -- the only effect of Install_Parents is to install the private decls of
162 -- the parents, because the visible parent declarations will have been
163 -- installed as part of the context of the corresponding spec.
165 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
);
166 -- In the compilation of a child unit, a child of any of the ancestor
167 -- units is directly visible if it is visible, because the parent is in
168 -- an enclosing scope. Iterate over context to find child units of U_Name
169 -- or of some ancestor of it.
171 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean;
172 -- When compiling a unit Q descended from some parent unit P, a limited
173 -- with_clause in the context of P that names some other ancestor of Q
174 -- must not be installed because the ancestor is immediately visible.
176 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean;
177 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
178 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
179 -- a library spec that has a parent. If the call to Is_Child_Spec returns
180 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
181 -- compilation unit for the parent spec.
183 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
184 -- Parent_Spec is non-empty, this is also a child unit.
186 procedure Remove_Context_Clauses
(N
: Node_Id
);
187 -- Subsidiary of previous one. Remove use_ and with_clauses
189 procedure Remove_Limited_With_Clause
(N
: Node_Id
);
190 -- Remove from visibility the shadow entities introduced for a package
191 -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217).
193 procedure Remove_Parents
(Lib_Unit
: Node_Id
);
194 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
195 -- contexts established by the corresponding call to Install_Parents are
196 -- removed. Remove_Parents contains a recursive call to itself to ensure
197 -- that all parents are removed in the nested case.
199 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
);
200 -- Reset all visibility flags on unit after compiling it, either as a main
201 -- unit or as a unit in the context.
203 procedure Unchain
(E
: Entity_Id
);
204 -- Remove single entity from visibility list
206 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
);
207 -- Common processing for all stubs (subprograms, tasks, packages, and
208 -- protected cases). N is the stub to be analyzed. Once the subunit name
209 -- is established, load and analyze. Nam is the non-overloadable entity
210 -- for which the proper body provides a completion. Subprogram stubs are
211 -- handled differently because they can be declarations.
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
;
272 Used
: in out Boolean;
273 Used_Type_Or_Elab
: in 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
;
282 Used
: in out Boolean;
283 Withed
: in 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
;
301 Used
: in out Boolean;
302 Used_Type_Or_Elab
: in 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
;
422 Used
: in out Boolean;
423 Withed
: in 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 := False;
519 Used_In_Spec
: Boolean := False;
520 Used_Type_Or_Elab
: Boolean := False;
521 Withed_In_Spec
: Boolean := False;
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??", 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??", 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 descendents) 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 -- Checks for redundant USE TYPE clauses have a special
787 -- exception for the synthetic spec we create here. This
788 -- special case relies on the two compilation units
789 -- sharing the same context clause.
791 -- Note: We used to do a shallow copy (New_Copy_List),
792 -- which defeated those checks and also created malformed
793 -- trees (subtype mark shared by two distinct
794 -- N_Use_Type_Clause nodes) which crashed the compiler.
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_Library_Unit
(N
, Lib_Unit
);
808 Set_Parent_Spec
(Unit
(Lib_Unit
), Cunit
(Unum
));
809 Make_Child_Decl_Unit
(N
);
810 Semantics
(Lib_Unit
);
812 -- Now that a separate declaration exists, the body
813 -- of the child unit does not act as spec any longer.
815 Set_Acts_As_Spec
(N
, False);
816 Set_Is_Child_Unit
(Defining_Entity
(Unit_Node
));
817 Set_Debug_Info_Needed
(Defining_Entity
(Unit
(Lib_Unit
)));
818 Set_Comes_From_Source_Default
(SCS
);
823 -- Here for subprogram with separate declaration
826 Semantics
(Lib_Unit
);
827 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
828 Version_Update
(N
, Lib_Unit
);
831 -- If this is a child unit, generate references to the parents
833 if Nkind
(Defining_Unit_Name
(Specification
(Unit_Node
))) =
834 N_Defining_Program_Unit_Name
836 Generate_Parent_References
837 (Specification
(Unit_Node
),
838 Scope
(Defining_Entity
(Unit
(Lib_Unit
))));
842 -- If it is a child unit, the parent must be elaborated first and we
843 -- update version, since we are dependent on our parent.
845 if Is_Child_Spec
(Unit_Node
) then
847 -- The analysis of the parent is done with style checks off
850 Save_Style_Check
: constant Boolean := Style_Check
;
853 if not GNAT_Mode
then
854 Style_Check
:= False;
857 Semantics
(Parent_Spec
(Unit_Node
));
858 Version_Update
(N
, Parent_Spec
(Unit_Node
));
860 -- Restore style check settings
862 Style_Check
:= Save_Style_Check
;
866 -- With the analysis done, install the context. Note that we can't
867 -- install the context from the with clauses as we analyze them, because
868 -- each with clause must be analyzed in a clean visibility context, so
869 -- we have to wait and install them all at once.
873 if Is_Child_Spec
(Unit_Node
) then
875 -- Set the entities of all parents in the program_unit_name
877 Generate_Parent_References
878 (Unit_Node
, Get_Parent_Entity
(Unit
(Parent_Spec
(Unit_Node
))));
881 -- All components of the context: with-clauses, library unit, ancestors
882 -- if any, (and their context) are analyzed and installed.
884 -- Call special debug routine sm if this is the main unit
886 if Current_Sem_Unit
= Main_Unit
then
890 -- Now analyze the unit (package, subprogram spec, body) itself
894 if Warn_On_Redundant_Constructs
then
895 Check_Redundant_Withs
(Context_Items
(N
));
897 if Nkind
(Unit_Node
) = N_Package_Body
then
898 Check_Redundant_Withs
899 (Context_Items
=> Context_Items
(N
),
900 Spec_Context_Items
=> Context_Items
(Lib_Unit
));
904 -- The above call might have made Unit_Node an N_Subprogram_Body from
905 -- something else, so propagate any Acts_As_Spec flag.
907 if Nkind
(Unit_Node
) = N_Subprogram_Body
908 and then Acts_As_Spec
(Unit_Node
)
910 Set_Acts_As_Spec
(N
);
913 -- Register predefined units in Rtsfind
916 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Sloc
(N
));
918 if Is_Predefined_File_Name
(Unit_File_Name
(Unum
)) then
919 Set_RTU_Loaded
(Unit_Node
);
923 -- Treat compilation unit pragmas that appear after the library unit
925 if Present
(Pragmas_After
(Aux_Decls_Node
(N
))) then
927 Prag_Node
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(N
)));
929 while Present
(Prag_Node
) loop
936 -- Analyze the contract of a [generic] subprogram that acts as a
937 -- compilation unit after all compilation pragmas have been analyzed.
939 if Nkind_In
(Unit_Node
, N_Generic_Subprogram_Declaration
,
940 N_Subprogram_Declaration
)
942 Analyze_Subprogram_Contract
(Defining_Entity
(Unit_Node
));
944 -- Capture all global references in a generic subprogram that acts as
945 -- a compilation unit now that the contract has been analyzed.
947 if Is_Generic_Declaration_Or_Body
(Unit_Node
) then
948 Save_Global_References_In_Contract
949 (Templ
=> Original_Node
(Unit_Node
),
950 Gen_Id
=> Defining_Entity
(Unit_Node
));
954 -- Generate distribution stubs if requested and no error
957 and then (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
959 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
960 and then Fatal_Error
(Main_Unit
) /= Error_Detected
962 if Is_RCI_Pkg_Spec_Or_Body
(N
) then
964 -- Regular RCI package
966 Add_Stub_Constructs
(N
);
968 elsif (Nkind
(Unit_Node
) = N_Package_Declaration
969 and then Is_Shared_Passive
(Defining_Entity
970 (Specification
(Unit_Node
))))
971 or else (Nkind
(Unit_Node
) = N_Package_Body
973 Is_Shared_Passive
(Corresponding_Spec
(Unit_Node
)))
975 -- Shared passive package
977 Add_Stub_Constructs
(N
);
979 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
981 Is_Remote_Call_Interface
982 (Defining_Entity
(Specification
(Instance_Spec
(Unit_Node
))))
984 -- Instantiation of a RCI generic package
986 Add_Stub_Constructs
(N
);
990 -- Remove unit from visibility, so that environment is clean for the
991 -- next compilation, which is either the main unit or some other unit
994 if Nkind_In
(Unit_Node
, N_Package_Declaration
,
995 N_Package_Renaming_Declaration
,
996 N_Subprogram_Declaration
)
997 or else Nkind
(Unit_Node
) in N_Generic_Declaration
998 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
999 and then Acts_As_Spec
(Unit_Node
))
1001 Remove_Unit_From_Visibility
(Defining_Entity
(Unit_Node
));
1003 -- If the unit is an instantiation whose body will be elaborated for
1004 -- inlining purposes, use the proper entity of the instance. The entity
1005 -- may be missing if the instantiation was illegal.
1007 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
1008 and then not Error_Posted
(Unit_Node
)
1009 and then Present
(Instance_Spec
(Unit_Node
))
1011 Remove_Unit_From_Visibility
1012 (Defining_Entity
(Instance_Spec
(Unit_Node
)));
1014 elsif Nkind
(Unit_Node
) = N_Package_Body
1015 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
1016 and then not Acts_As_Spec
(Unit_Node
))
1018 -- Bodies that are not the main unit are compiled if they are generic
1019 -- or contain generic or inlined units. Their analysis brings in the
1020 -- context of the corresponding spec (unit declaration) which must be
1021 -- removed as well, to return the compilation environment to its
1024 Remove_Context
(Lib_Unit
);
1025 Set_Is_Immediately_Visible
(Defining_Entity
(Unit
(Lib_Unit
)), False);
1028 -- Last step is to deinstall the context we just installed as well as
1029 -- the unit just compiled.
1033 -- When generating code for a non-generic main unit, check that withed
1034 -- generic units have a body if they need it, even if the units have not
1035 -- been instantiated. Force the load of the bodies to produce the proper
1036 -- error if the body is absent. The same applies to GNATprove mode, with
1037 -- the added benefit of capturing global references within the generic.
1038 -- This in turn allows for proper inlining of subprogram bodies without
1039 -- a previous declaration.
1041 if Get_Cunit_Unit_Number
(N
) = Main_Unit
1042 and then ((Operating_Mode
= Generate_Code
and then Expander_Active
)
1044 (Operating_Mode
= Check_Semantics
and then GNATprove_Mode
))
1046 -- Check whether the source for the body of the unit must be included
1047 -- in a standalone library.
1049 Check_Body_Needed_For_SAL
(Cunit_Entity
(Main_Unit
));
1051 -- Indicate that the main unit is now analyzed, to catch possible
1052 -- circularities between it and generic bodies. Remove main unit from
1053 -- visibility. This might seem superfluous, but the main unit must
1054 -- not be visible in the generic body expansions that follow.
1056 Set_Analyzed
(N
, True);
1057 Set_Is_Immediately_Visible
(Cunit_Entity
(Main_Unit
), False);
1062 Un
: Unit_Number_Type
;
1064 Save_Style_Check
: constant Boolean := Style_Check
;
1067 Item
:= First
(Context_Items
(N
));
1068 while Present
(Item
) loop
1070 -- Check for explicit with clause
1072 if Nkind
(Item
) = N_With_Clause
1073 and then not Implicit_With
(Item
)
1075 -- Ada 2005 (AI-50217): Ignore limited-withed units
1077 and then not Limited_Present
(Item
)
1079 Nam
:= Entity
(Name
(Item
));
1081 -- Compile the generic subprogram, unless it is intrinsic or
1082 -- imported so no body is required, or generic package body
1083 -- if the package spec requires a body.
1085 if (Is_Generic_Subprogram
(Nam
)
1086 and then not Is_Intrinsic_Subprogram
(Nam
)
1087 and then not Is_Imported
(Nam
))
1088 or else (Ekind
(Nam
) = E_Generic_Package
1089 and then Unit_Requires_Body
(Nam
))
1091 Style_Check
:= False;
1093 if Present
(Renamed_Object
(Nam
)) then
1099 (Unit_Declaration_Node
1100 (Renamed_Object
(Nam
)))),
1109 Get_Body_Name
(Get_Unit_Name
(Item
)),
1116 if Un
= No_Unit
then
1118 ("body of generic unit& not found", Item
, Nam
);
1121 elsif not Analyzed
(Cunit
(Un
))
1122 and then Un
/= Main_Unit
1123 and then Fatal_Error
(Un
) /= Error_Detected
1125 Style_Check
:= False;
1126 Semantics
(Cunit
(Un
));
1134 -- Restore style checks settings
1136 Style_Check
:= Save_Style_Check
;
1140 -- Deal with creating elaboration counter if needed. We create an
1141 -- elaboration counter only for units that come from source since
1142 -- units manufactured by the compiler never need elab checks.
1144 if Comes_From_Source
(N
)
1145 and then Nkind_In
(Unit_Node
, N_Package_Declaration
,
1146 N_Generic_Package_Declaration
,
1147 N_Subprogram_Declaration
,
1148 N_Generic_Subprogram_Declaration
)
1151 Loc
: constant Source_Ptr
:= Sloc
(N
);
1152 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1155 Spec_Id
:= Defining_Entity
(Unit_Node
);
1156 Generate_Definition
(Spec_Id
);
1158 -- See if an elaboration entity is required for possible access
1159 -- before elaboration checking. Note that we must allow for this
1160 -- even if -gnatE is not set, since a client may be compiled in
1161 -- -gnatE mode and reference the entity.
1163 -- These entities are also used by the binder to prevent multiple
1164 -- attempts to execute the elaboration code for the library case
1165 -- where the elaboration routine might otherwise be called more
1168 -- Case of units which do not require elaboration checks
1171 -- Pure units do not need checks
1175 -- Preelaborated units do not need checks
1177 or else Is_Preelaborated
(Spec_Id
)
1179 -- No checks needed if pragma Elaborate_Body present
1181 or else Has_Pragma_Elaborate_Body
(Spec_Id
)
1183 -- No checks needed if unit does not require a body
1185 or else not Unit_Requires_Body
(Spec_Id
)
1187 -- No checks needed for predefined files
1189 or else Is_Predefined_File_Name
(Unit_File_Name
(Unum
))
1191 -- No checks required if no separate spec
1193 or else Acts_As_Spec
(N
)
1195 -- This is a case where we only need the entity for
1196 -- checking to prevent multiple elaboration checks.
1198 Set_Elaboration_Entity_Required
(Spec_Id
, False);
1200 -- Case of elaboration entity is required for access before
1201 -- elaboration checking (so certainly we must build it).
1204 Set_Elaboration_Entity_Required
(Spec_Id
, True);
1207 Build_Elaboration_Entity
(N
, Spec_Id
);
1211 -- Freeze the compilation unit entity. This for sure is needed because
1212 -- of some warnings that can be output (see Freeze_Subprogram), but may
1213 -- in general be required. If freezing actions result, place them in the
1214 -- compilation unit actions list, and analyze them.
1217 L
: constant List_Id
:=
1218 Freeze_Entity
(Cunit_Entity
(Current_Sem_Unit
), N
);
1220 while Is_Non_Empty_List
(L
) loop
1221 Insert_Library_Level_Action
(Remove_Head
(L
));
1227 -- Call Check_Package_Body so that a body containing subprograms with
1228 -- Inline_Always can be made available for front end inlining.
1230 if Nkind
(Unit_Node
) = N_Package_Declaration
1231 and then Get_Cunit_Unit_Number
(N
) /= Main_Unit
1233 -- We don't need to do this if the Expander is not active, since there
1234 -- is no code to inline.
1236 and then Expander_Active
1239 Save_Style_Check
: constant Boolean := Style_Check
;
1240 Save_Warning
: constant Warning_Mode_Type
:= Warning_Mode
;
1241 Options
: Style_Check_Options
;
1244 Save_Style_Check_Options
(Options
);
1245 Reset_Style_Check_Options
;
1246 Opt
.Warning_Mode
:= Suppress
;
1248 Check_Package_Body_For_Inlining
(N
, Defining_Entity
(Unit_Node
));
1250 Reset_Style_Check_Options
;
1251 Set_Style_Check_Options
(Options
);
1252 Style_Check
:= Save_Style_Check
;
1253 Warning_Mode
:= Save_Warning
;
1257 -- If we are generating obsolescent warnings, then here is where we
1258 -- generate them for the with'ed items. The reason for this special
1259 -- processing is that the normal mechanism of generating the warnings
1260 -- for referenced entities does not work for context clause references.
1261 -- That's because when we first analyze the context, it is too early to
1262 -- know if the with'ing unit is itself obsolescent (which suppresses
1266 and then Warn_On_Obsolescent_Feature
1267 and then Nkind
(Unit_Node
) not in N_Generic_Instantiation
1269 -- Push current compilation unit as scope, so that the test for
1270 -- being within an obsolescent unit will work correctly. The check
1271 -- is not performed within an instantiation, because the warning
1272 -- will have been emitted in the corresponding generic unit.
1274 Push_Scope
(Defining_Entity
(Unit_Node
));
1276 -- Loop through context items to deal with with clauses
1284 Item
:= First
(Context_Items
(N
));
1285 while Present
(Item
) loop
1286 if Nkind
(Item
) = N_With_Clause
1288 -- Suppress this check in limited-withed units. Further work
1289 -- needed here if we decide to incorporate this check on
1290 -- limited-withed units.
1292 and then not Limited_Present
(Item
)
1295 Ent
:= Entity
(Nam
);
1297 if Is_Obsolescent
(Ent
) then
1298 Output_Obsolescent_Entity_Warnings
(Nam
, Ent
);
1306 -- Remove temporary install of current unit as scope
1311 -- If No_Elaboration_Code_All was encountered, this is where we do the
1312 -- transitive test of with'ed units to make sure they have the aspect.
1313 -- This is delayed till the end of analyzing the compilation unit to
1314 -- ensure that the pragma/aspect, if present, has been analyzed.
1316 Check_No_Elab_Code_All
(N
);
1317 end Analyze_Compilation_Unit
;
1319 ---------------------
1320 -- Analyze_Context --
1321 ---------------------
1323 procedure Analyze_Context
(N
: Node_Id
) is
1324 Ukind
: constant Node_Kind
:= Nkind
(Unit
(N
));
1328 -- First process all configuration pragmas at the start of the context
1329 -- items. Strictly these are not part of the context clause, but that
1330 -- is where the parser puts them. In any case for sure we must analyze
1331 -- these before analyzing the actual context items, since they can have
1332 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1333 -- be with'ed as a result of changing categorizations in Ada 2005).
1335 Item
:= First
(Context_Items
(N
));
1336 while Present
(Item
)
1337 and then Nkind
(Item
) = N_Pragma
1338 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
1344 -- This is the point at which we capture the configuration settings
1345 -- for the unit. At the moment only the Optimize_Alignment setting
1346 -- needs to be captured. Probably more later ???
1348 if Optimize_Alignment_Local
then
1349 Set_OA_Setting
(Current_Sem_Unit
, 'L');
1351 Set_OA_Setting
(Current_Sem_Unit
, Optimize_Alignment
);
1354 -- Loop through actual context items. This is done in two passes:
1356 -- a) The first pass analyzes non-limited with-clauses and also any
1357 -- configuration pragmas (we need to get the latter analyzed right
1358 -- away, since they can affect processing of subsequent items).
1360 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1362 while Present
(Item
) loop
1364 -- For with clause, analyze the with clause, and then update the
1365 -- version, since we are dependent on a unit that we with.
1367 if Nkind
(Item
) = N_With_Clause
1368 and then not Limited_Present
(Item
)
1370 -- Skip analyzing with clause if no unit, nothing to do (this
1371 -- happens for a with that references a non-existent unit).
1373 if Present
(Library_Unit
(Item
)) then
1375 -- Skip analyzing with clause if this is a with_clause for
1376 -- the main unit, which happens if a subunit has a useless
1377 -- with_clause on its parent.
1379 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
) then
1382 -- Here for the case of a useless with for the main unit
1385 Set_Entity
(Name
(Item
), Cunit_Entity
(Current_Sem_Unit
));
1389 -- Do version update (skipped for implicit with)
1391 if not Implicit_With
(Item
) then
1392 Version_Update
(N
, Library_Unit
(Item
));
1395 -- Skip pragmas. Configuration pragmas at the start were handled in
1396 -- the loop above, and remaining pragmas are not processed until we
1397 -- actually install the context (see Install_Context). We delay the
1398 -- analysis of these pragmas to make sure that we have installed all
1399 -- the implicit with's on parent units.
1401 -- Skip use clauses at this stage, since we don't want to do any
1402 -- installing of potentially use-visible entities until we
1403 -- actually install the complete context (in Install_Context).
1404 -- Otherwise things can get installed in the wrong context.
1413 -- Second pass: examine all limited_with clauses. All other context
1414 -- items are ignored in this pass.
1416 Item
:= First
(Context_Items
(N
));
1417 while Present
(Item
) loop
1418 if Nkind
(Item
) = N_With_Clause
1419 and then Limited_Present
(Item
)
1421 -- No need to check errors on implicitly generated limited-with
1424 if not Implicit_With
(Item
) then
1426 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1427 -- properly rejected, including renaming declarations.
1429 if not Nkind_In
(Ukind
, N_Package_Declaration
,
1430 N_Subprogram_Declaration
)
1431 and then Ukind
not in N_Generic_Declaration
1432 and then Ukind
not in N_Generic_Instantiation
1434 Error_Msg_N
("limited with_clause not allowed here", Item
);
1436 -- Check wrong use of a limited with clause applied to the
1437 -- compilation unit containing the limited-with clause.
1439 -- limited with P.Q;
1440 -- package P.Q is ...
1442 elsif Unit
(Library_Unit
(Item
)) = Unit
(N
) then
1443 Error_Msg_N
("wrong use of limited-with clause", Item
);
1445 -- Check wrong use of limited-with clause applied to some
1446 -- immediate ancestor.
1448 elsif Is_Child_Spec
(Unit
(N
)) then
1450 Lib_U
: constant Entity_Id
:= Unit
(Library_Unit
(Item
));
1454 P
:= Parent_Spec
(Unit
(N
));
1456 if Unit
(P
) = Lib_U
then
1457 Error_Msg_N
("limited with_clause cannot "
1458 & "name ancestor", Item
);
1462 exit when not Is_Child_Spec
(Unit
(P
));
1463 P
:= Parent_Spec
(Unit
(P
));
1468 -- Check if the limited-withed unit is already visible through
1469 -- some context clause of the current compilation unit or some
1470 -- ancestor of the current compilation unit.
1473 Lim_Unit_Name
: constant Node_Id
:= Name
(Item
);
1474 Comp_Unit
: Node_Id
;
1476 Unit_Name
: Node_Id
;
1481 It
:= First
(Context_Items
(Comp_Unit
));
1482 while Present
(It
) loop
1484 and then Nkind
(It
) = N_With_Clause
1485 and then not Limited_Present
(It
)
1487 Nkind_In
(Unit
(Library_Unit
(It
)),
1488 N_Package_Declaration
,
1489 N_Package_Renaming_Declaration
)
1491 if Nkind
(Unit
(Library_Unit
(It
))) =
1492 N_Package_Declaration
1494 Unit_Name
:= Name
(It
);
1496 Unit_Name
:= Name
(Unit
(Library_Unit
(It
)));
1499 -- Check if the named package (or some ancestor)
1500 -- leaves visible the full-view of the unit given
1501 -- in the limited-with clause
1504 if Designate_Same_Unit
(Lim_Unit_Name
,
1507 Error_Msg_Sloc
:= Sloc
(It
);
1509 ("simultaneous visibility of limited "
1510 & "and unlimited views not allowed",
1513 ("\unlimited view visible through "
1514 & "context clause #",
1518 elsif Nkind
(Unit_Name
) = N_Identifier
then
1522 Unit_Name
:= Prefix
(Unit_Name
);
1529 exit when not Is_Child_Spec
(Unit
(Comp_Unit
));
1531 Comp_Unit
:= Parent_Spec
(Unit
(Comp_Unit
));
1536 -- Skip analyzing with clause if no unit, see above
1538 if Present
(Library_Unit
(Item
)) then
1542 -- A limited_with does not impose an elaboration order, but
1543 -- there is a semantic dependency for recompilation purposes.
1545 if not Implicit_With
(Item
) then
1546 Version_Update
(N
, Library_Unit
(Item
));
1549 -- Pragmas and use clauses and with clauses other than limited
1550 -- with's are ignored in this pass through the context items.
1558 end Analyze_Context
;
1560 -------------------------------
1561 -- Analyze_Package_Body_Stub --
1562 -------------------------------
1564 procedure Analyze_Package_Body_Stub
(N
: Node_Id
) is
1565 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1567 Opts
: Config_Switches_Type
;
1570 -- The package declaration must be in the current declarative part
1572 Check_Stub_Level
(N
);
1573 Nam
:= Current_Entity_In_Scope
(Id
);
1575 if No
(Nam
) or else not Is_Package_Or_Generic_Package
(Nam
) then
1576 Error_Msg_N
("missing specification for package stub", N
);
1578 elsif Has_Completion
(Nam
)
1579 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Nam
)))
1581 Error_Msg_N
("duplicate or redundant stub for package", N
);
1584 -- Retain and restore the configuration options of the enclosing
1585 -- context as the proper body may introduce a set of its own.
1587 Save_Opt_Config_Switches
(Opts
);
1589 -- Indicate that the body of the package exists. If we are doing
1590 -- only semantic analysis, the stub stands for the body. If we are
1591 -- generating code, the existence of the body will be confirmed
1592 -- when we load the proper body.
1594 Set_Has_Completion
(Nam
);
1595 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1596 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1597 Generate_Reference
(Nam
, Id
, 'b');
1598 Analyze_Proper_Body
(N
, Nam
);
1600 Restore_Opt_Config_Switches
(Opts
);
1602 end Analyze_Package_Body_Stub
;
1604 -------------------------
1605 -- Analyze_Proper_Body --
1606 -------------------------
1608 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1609 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1611 procedure Optional_Subunit
;
1612 -- This procedure is called when the main unit is a stub, or when we
1613 -- are not generating code. In such a case, we analyze the subunit if
1614 -- present, which is user-friendly and in fact required for ASIS, but we
1615 -- don't complain if the subunit is missing. In GNATprove_Mode, we issue
1616 -- an error to avoid formal verification of a partial unit.
1618 ----------------------
1619 -- Optional_Subunit --
1620 ----------------------
1622 procedure Optional_Subunit
is
1623 Comp_Unit
: Node_Id
;
1624 Unum
: Unit_Number_Type
;
1627 -- Try to load subunit, but ignore any errors that occur during the
1628 -- loading of the subunit, by using the special feature in Errout to
1629 -- ignore all errors. Note that Fatal_Error will still be set, so we
1630 -- will be able to check for this case below.
1632 if not (ASIS_Mode
or GNATprove_Mode
) then
1633 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1638 (Load_Name
=> Subunit_Name
,
1639 Required
=> GNATprove_Mode
,
1643 if not (ASIS_Mode
or GNATprove_Mode
) then
1644 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1647 -- All done if we successfully loaded the subunit
1650 and then (Fatal_Error
(Unum
) /= Error_Detected
1651 or else Try_Semantics
)
1653 Comp_Unit
:= Cunit
(Unum
);
1655 -- If the file was empty or seriously mangled, the unit itself may
1658 if No
(Unit
(Comp_Unit
)) then
1660 ("subunit does not contain expected proper body", N
);
1662 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1664 ("expected SEPARATE subunit, found child unit",
1665 Cunit_Entity
(Unum
));
1667 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1668 Analyze_Subunit
(Comp_Unit
);
1669 Set_Library_Unit
(N
, Comp_Unit
);
1670 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1673 elsif Unum
= No_Unit
1674 and then Present
(Nam
)
1676 if Is_Protected_Type
(Nam
) then
1677 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1679 Set_Corresponding_Body
(
1680 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1683 end Optional_Subunit
;
1687 Comp_Unit
: Node_Id
;
1688 Unum
: Unit_Number_Type
;
1690 -- Start of processing for Analyze_Proper_Body
1693 -- If the subunit is already loaded, it means that the main unit is a
1694 -- subunit, and that the current unit is one of its parents which was
1695 -- being analyzed to provide the needed context for the analysis of the
1696 -- subunit. In this case we analyze the subunit and continue with the
1697 -- parent, without looking at subsequent subunits.
1699 if Is_Loaded
(Subunit_Name
) then
1701 -- If the proper body is already linked to the stub node, the stub is
1702 -- in a generic unit and just needs analyzing.
1704 if Present
(Library_Unit
(N
)) then
1705 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1707 -- If the subunit has severe errors, the spec of the enclosing
1708 -- body may not be available, in which case do not try analysis.
1710 if Serious_Errors_Detected
> 0
1711 and then No
(Library_Unit
(Library_Unit
(N
)))
1716 -- Collect SCO information for loaded subunit if we are in the
1717 -- extended main unit.
1720 and then In_Extended_Main_Source_Unit
1721 (Cunit_Entity
(Current_Sem_Unit
))
1723 SCO_Record_Raw
(Get_Cunit_Unit_Number
(Library_Unit
(N
)));
1726 Analyze_Subunit
(Library_Unit
(N
));
1728 -- Otherwise we must load the subunit and link to it
1731 -- Load the subunit, this must work, since we originally loaded
1732 -- the subunit earlier on. So this will not really load it, just
1733 -- give access to it.
1737 (Load_Name
=> Subunit_Name
,
1742 -- And analyze the subunit in the parent context (note that we
1743 -- do not call Semantics, since that would remove the parent
1744 -- context). Because of this, we have to manually reset the
1745 -- compiler state to Analyzing since it got destroyed by Load.
1747 if Unum
/= No_Unit
then
1748 Compiler_State
:= Analyzing
;
1750 -- Check that the proper body is a subunit and not a child
1751 -- unit. If the unit was previously loaded, the error will
1752 -- have been emitted when copying the generic node, so we
1753 -- just return to avoid cascaded errors.
1755 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1759 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1760 Analyze_Subunit
(Cunit
(Unum
));
1761 Set_Library_Unit
(N
, Cunit
(Unum
));
1765 -- If the main unit is a subunit, then we are just performing semantic
1766 -- analysis on that subunit, and any other subunits of any parent unit
1767 -- should be ignored, except that if we are building trees for ASIS
1768 -- usage we want to annotate the stub properly. If the main unit is
1769 -- itself a subunit, another subunit is irrelevant unless it is a
1770 -- subunit of the current one, that is to say appears in the current
1773 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1774 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1778 PB
: constant Node_Id
:= Proper_Body
(Unit
(Cunit
(Main_Unit
)));
1780 if Nkind_In
(PB
, N_Package_Body
, N_Subprogram_Body
)
1781 and then List_Containing
(N
) = Declarations
(PB
)
1788 -- But before we return, set the flag for unloaded subunits. This
1789 -- will suppress junk warnings of variables in the same declarative
1790 -- part (or a higher level one) that are in danger of looking unused
1791 -- when in fact there might be a declaration in the subunit that we
1792 -- do not intend to load.
1794 Unloaded_Subunits
:= True;
1797 -- If the subunit is not already loaded, and we are generating code,
1798 -- then this is the case where compilation started from the parent, and
1799 -- we are generating code for an entire subunit tree. In that case we
1800 -- definitely need to load the subunit.
1802 -- In order to continue the analysis with the rest of the parent,
1803 -- and other subunits, we load the unit without requiring its
1804 -- presence, and emit a warning if not found, rather than terminating
1805 -- the compilation abruptly, as for other missing file problems.
1807 elsif Original_Operating_Mode
= Generate_Code
then
1809 -- If the proper body is already linked to the stub node, the stub is
1810 -- in a generic unit and just needs analyzing.
1812 -- We update the version. Although we are not strictly technically
1813 -- semantically dependent on the subunit, given our approach of macro
1814 -- substitution of subunits, it makes sense to include it in the
1815 -- version identification.
1817 if Present
(Library_Unit
(N
)) then
1818 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1819 Analyze_Subunit
(Library_Unit
(N
));
1820 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1822 -- Otherwise we must load the subunit and link to it
1825 -- Make sure that, if the subunit is preprocessed and -gnateG is
1826 -- specified, the preprocessed file will be written.
1828 Lib
.Analysing_Subunit_Of_Main
:= True;
1831 (Load_Name
=> Subunit_Name
,
1835 Lib
.Analysing_Subunit_Of_Main
:= False;
1837 -- Give message if we did not get the unit Emit warning even if
1838 -- missing subunit is not within main unit, to simplify debugging.
1840 if Original_Operating_Mode
= Generate_Code
1841 and then Unum
= No_Unit
1843 Error_Msg_Unit_1
:= Subunit_Name
;
1845 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1847 ("subunit$$ in file{ not found??!!", N
);
1848 Subunits_Missing
:= True;
1851 -- Load_Unit may reset Compiler_State, since it may have been
1852 -- necessary to parse an additional units, so we make sure that
1853 -- we reset it to the Analyzing state.
1855 Compiler_State
:= Analyzing
;
1857 if Unum
/= No_Unit
then
1858 if Debug_Flag_L
then
1859 Write_Str
("*** Loaded subunit from stub. Analyze");
1863 Comp_Unit
:= Cunit
(Unum
);
1865 -- Check for child unit instead of subunit
1867 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1869 ("expected SEPARATE subunit, found child unit",
1870 Cunit_Entity
(Unum
));
1872 -- OK, we have a subunit
1875 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1876 Set_Library_Unit
(N
, Comp_Unit
);
1878 -- We update the version. Although we are not technically
1879 -- semantically dependent on the subunit, given our approach
1880 -- of macro substitution of subunits, it makes sense to
1881 -- include it in the version identification.
1883 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1885 -- Collect SCO information for loaded subunit if we are in
1886 -- the extended main unit.
1890 In_Extended_Main_Source_Unit
1891 (Cunit_Entity
(Current_Sem_Unit
))
1893 SCO_Record_Raw
(Unum
);
1896 -- Analyze the unit if semantics active
1898 if Fatal_Error
(Unum
) /= Error_Detected
1899 or else Try_Semantics
1901 Analyze_Subunit
(Comp_Unit
);
1907 -- The remaining case is when the subunit is not already loaded and we
1908 -- are not generating code. In this case we are just performing semantic
1909 -- analysis on the parent, and we are not interested in the subunit. For
1910 -- subprograms, analyze the stub as a body. For other entities the stub
1911 -- has already been marked as completed.
1916 end Analyze_Proper_Body
;
1918 ----------------------------------
1919 -- Analyze_Protected_Body_Stub --
1920 ----------------------------------
1922 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
1923 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
1926 Check_Stub_Level
(N
);
1928 -- First occurrence of name may have been as an incomplete type
1930 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
1931 Nam
:= Full_View
(Nam
);
1934 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
1935 Error_Msg_N
("missing specification for Protected body", N
);
1938 -- Currently there are no language-defined aspects that can apply to
1939 -- a protected body stub. Issue an error and remove the aspects to
1940 -- prevent cascaded errors.
1942 if Has_Aspects
(N
) then
1944 ("aspects on protected bodies are not allowed",
1945 First
(Aspect_Specifications
(N
)));
1949 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1950 Set_Has_Completion
(Etype
(Nam
));
1951 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1952 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
1953 Analyze_Proper_Body
(N
, Etype
(Nam
));
1955 end Analyze_Protected_Body_Stub
;
1957 ----------------------------------
1958 -- Analyze_Subprogram_Body_Stub --
1959 ----------------------------------
1961 -- A subprogram body stub can appear with or without a previous spec. If
1962 -- there is one, then the analysis of the body will find it and verify
1963 -- conformance. The formals appearing in the specification of the stub play
1964 -- no role, except for requiring an additional conformance check. If there
1965 -- is no previous subprogram declaration, the stub acts as a spec, and
1966 -- provides the defining entity for the subprogram.
1968 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
1970 Opts
: Config_Switches_Type
;
1973 Check_Stub_Level
(N
);
1975 -- Verify that the identifier for the stub is unique within this
1976 -- declarative part.
1978 if Nkind_In
(Parent
(N
), N_Block_Statement
,
1982 Decl
:= First
(Declarations
(Parent
(N
)));
1983 while Present
(Decl
) and then Decl
/= N
loop
1984 if Nkind
(Decl
) = N_Subprogram_Body_Stub
1985 and then (Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
1986 Chars
(Defining_Unit_Name
(Specification
(N
))))
1988 Error_Msg_N
("identifier for stub is not unique", N
);
1995 -- Retain and restore the configuration options of the enclosing context
1996 -- as the proper body may introduce a set of its own.
1998 Save_Opt_Config_Switches
(Opts
);
2000 -- Treat stub as a body, which checks conformance if there is a previous
2001 -- declaration, or else introduces entity and its signature.
2003 Analyze_Subprogram_Body
(N
);
2004 Analyze_Proper_Body
(N
, Empty
);
2006 Restore_Opt_Config_Switches
(Opts
);
2007 end Analyze_Subprogram_Body_Stub
;
2009 -------------------------------------------
2010 -- Analyze_Subprogram_Body_Stub_Contract --
2011 -------------------------------------------
2013 procedure Analyze_Subprogram_Body_Stub_Contract
(Stub_Id
: Entity_Id
) is
2014 Stub_Decl
: constant Node_Id
:= Parent
(Parent
(Stub_Id
));
2015 Spec_Id
: constant Entity_Id
:= Corresponding_Spec_Of_Stub
(Stub_Decl
);
2018 -- A subprogram body stub may act as its own spec or as the completion
2019 -- of a previous declaration. Depending on the context, the contract of
2020 -- the stub may contain two sets of pragmas.
2022 -- The stub is a completion, the applicable pragmas are:
2026 if Present
(Spec_Id
) then
2027 Analyze_Subprogram_Body_Contract
(Stub_Id
);
2029 -- The stub acts as its own spec, the applicable pragmas are:
2038 Analyze_Subprogram_Contract
(Stub_Id
);
2040 end Analyze_Subprogram_Body_Stub_Contract
;
2042 ---------------------
2043 -- Analyze_Subunit --
2044 ---------------------
2046 -- A subunit is compiled either by itself (for semantic checking) or as
2047 -- part of compiling the parent (for code generation). In either case, by
2048 -- the time we actually process the subunit, the parent has already been
2049 -- installed and analyzed. The node N is a compilation unit, whose context
2050 -- needs to be treated here, because we come directly here from the parent
2051 -- without calling Analyze_Compilation_Unit.
2053 -- The compilation context includes the explicit context of the subunit,
2054 -- and the context of the parent, together with the parent itself. In order
2055 -- to compile the current context, we remove the one inherited from the
2056 -- parent, in order to have a clean visibility table. We restore the parent
2057 -- context before analyzing the proper body itself. On exit, we remove only
2058 -- the explicit context of the subunit.
2060 procedure Analyze_Subunit
(N
: Node_Id
) is
2061 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2062 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2064 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2065 Num_Scopes
: Int
:= 0;
2066 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2067 Enclosing_Child
: Entity_Id
:= Empty
;
2068 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2070 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2071 Cunit_Boolean_Restrictions_Save
;
2072 -- Save non-partition wide restrictions before processing the subunit.
2073 -- All subunits are analyzed with config restrictions reset and we need
2074 -- to restore these saved values at the end.
2076 procedure Analyze_Subunit_Context
;
2077 -- Capture names in use clauses of the subunit. This must be done before
2078 -- re-installing parent declarations, because items in the context must
2079 -- not be hidden by declarations local to the parent.
2081 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2082 -- Recursive procedure to restore scope of all ancestors of subunit,
2083 -- from outermost in. If parent is not a subunit, the call to install
2084 -- context installs context of spec and (if parent is a child unit) the
2085 -- context of its parents as well. It is confusing that parents should
2086 -- be treated differently in both cases, but the semantics are just not
2089 procedure Re_Install_Use_Clauses
;
2090 -- As part of the removal of the parent scope, the use clauses are
2091 -- removed, to be reinstalled when the context of the subunit has been
2092 -- analyzed. Use clauses may also have been affected by the analysis of
2093 -- the context of the subunit, so they have to be applied again, to
2094 -- insure that the compilation environment of the rest of the parent
2095 -- unit is identical.
2097 procedure Remove_Scope
;
2098 -- Remove current scope from scope stack, and preserve the list of use
2099 -- clauses in it, to be reinstalled after context is analyzed.
2101 -----------------------------
2102 -- Analyze_Subunit_Context --
2103 -----------------------------
2105 procedure Analyze_Subunit_Context
is
2108 Unit_Name
: Entity_Id
;
2111 Analyze_Context
(N
);
2112 Check_No_Elab_Code_All
(N
);
2114 -- Make withed units immediately visible. If child unit, make the
2115 -- ultimate parent immediately visible.
2117 Item
:= First
(Context_Items
(N
));
2118 while Present
(Item
) loop
2119 if Nkind
(Item
) = N_With_Clause
then
2121 -- Protect frontend against previous errors in context clauses
2123 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2124 if Error_Posted
(Item
) then
2128 -- If a subunits has serious syntax errors, the context
2129 -- may not have been loaded. Add a harmless unit name to
2130 -- attempt processing.
2132 if Serious_Errors_Detected
> 0
2133 and then No
(Entity
(Name
(Item
)))
2135 Set_Entity
(Name
(Item
), Standard_Standard
);
2138 Unit_Name
:= Entity
(Name
(Item
));
2140 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2141 exit when Scope
(Unit_Name
) = Standard_Standard
;
2142 Unit_Name
:= Scope
(Unit_Name
);
2144 if No
(Unit_Name
) then
2145 Check_Error_Detected
;
2150 if not Is_Immediately_Visible
(Unit_Name
) then
2151 Set_Is_Immediately_Visible
(Unit_Name
);
2152 Set_Context_Installed
(Item
);
2157 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2158 Nam
:= First
(Names
(Item
));
2159 while Present
(Nam
) loop
2164 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2165 Nam
:= First
(Subtype_Marks
(Item
));
2166 while Present
(Nam
) loop
2175 -- Reset visibility of withed units. They will be made visible again
2176 -- when we install the subunit context.
2178 Item
:= First
(Context_Items
(N
));
2179 while Present
(Item
) loop
2180 if Nkind
(Item
) = N_With_Clause
2182 -- Protect frontend against previous errors in context clauses
2184 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2185 and then not Error_Posted
(Item
)
2187 Unit_Name
:= Entity
(Name
(Item
));
2189 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2190 exit when Scope
(Unit_Name
) = Standard_Standard
;
2191 Unit_Name
:= Scope
(Unit_Name
);
2194 if Context_Installed
(Item
) then
2195 Set_Is_Immediately_Visible
(Unit_Name
, False);
2196 Set_Context_Installed
(Item
, False);
2202 end Analyze_Subunit_Context
;
2204 ------------------------
2205 -- Re_Install_Parents --
2206 ------------------------
2208 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2212 if Nkind
(Unit
(L
)) = N_Subunit
then
2213 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2216 Install_Context
(L
);
2218 -- If the subunit occurs within a child unit, we must restore the
2219 -- immediate visibility of any siblings that may occur in context.
2221 if Present
(Enclosing_Child
) then
2222 Install_Siblings
(Enclosing_Child
, L
);
2227 if Scop
/= Par_Unit
then
2228 Set_Is_Immediately_Visible
(Scop
);
2231 -- Make entities in scope visible again. For child units, restore
2232 -- visibility only if they are actually in context.
2234 E
:= First_Entity
(Current_Scope
);
2235 while Present
(E
) loop
2236 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2237 Set_Is_Immediately_Visible
(E
);
2243 -- A subunit appears within a body, and for a nested subunits all the
2244 -- parents are bodies. Restore full visibility of their private
2247 if Is_Package_Or_Generic_Package
(Scop
) then
2248 Set_In_Package_Body
(Scop
);
2249 Install_Private_Declarations
(Scop
);
2251 end Re_Install_Parents
;
2253 ----------------------------
2254 -- Re_Install_Use_Clauses --
2255 ----------------------------
2257 procedure Re_Install_Use_Clauses
is
2260 for J
in reverse 1 .. Num_Scopes
loop
2261 U
:= Use_Clauses
(J
);
2262 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2263 Install_Use_Clauses
(U
, Force_Installation
=> True);
2265 end Re_Install_Use_Clauses
;
2271 procedure Remove_Scope
is
2275 Num_Scopes
:= Num_Scopes
+ 1;
2276 Use_Clauses
(Num_Scopes
) :=
2277 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2279 E
:= First_Entity
(Current_Scope
);
2280 while Present
(E
) loop
2281 Set_Is_Immediately_Visible
(E
, False);
2285 if Is_Child_Unit
(Current_Scope
) then
2286 Enclosing_Child
:= Current_Scope
;
2292 -- Start of processing for Analyze_Subunit
2295 -- For subunit in main extended unit, we reset the configuration values
2296 -- for the non-partition-wide restrictions. For other units reset them.
2298 if In_Extended_Main_Source_Unit
(N
) then
2299 Restore_Config_Cunit_Boolean_Restrictions
;
2301 Reset_Cunit_Boolean_Restrictions
;
2306 Nam
: Node_Id
:= Name
(Unit
(N
));
2309 if Nkind
(Nam
) = N_Selected_Component
then
2310 Nam
:= Selector_Name
(Nam
);
2313 Check_Identifier
(Nam
, Par_Unit
);
2317 if not Is_Empty_List
(Context_Items
(N
)) then
2319 -- Save current use clauses
2322 Remove_Context
(Lib_Unit
);
2324 -- Now remove parents and their context, including enclosing subunits
2325 -- and the outer parent body which is not a subunit.
2327 if Present
(Lib_Spec
) then
2328 Remove_Context
(Lib_Spec
);
2330 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2331 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2333 Remove_Context
(Lib_Spec
);
2336 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2340 if Nkind
(Unit
(Lib_Spec
)) = N_Package_Body
then
2341 Remove_Context
(Library_Unit
(Lib_Spec
));
2345 Set_Is_Immediately_Visible
(Par_Unit
, False);
2347 Analyze_Subunit_Context
;
2349 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2350 Set_Is_Immediately_Visible
(Par_Unit
);
2352 -- If the context includes a child unit of the parent of the subunit,
2353 -- the parent will have been removed from visibility, after compiling
2354 -- that cousin in the context. The visibility of the parent must be
2355 -- restored now. This also applies if the context includes another
2356 -- subunit of the same parent which in turn includes a child unit in
2359 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2360 if not Is_Immediately_Visible
(Par_Unit
)
2361 or else (Present
(First_Entity
(Par_Unit
))
2363 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2365 Set_Is_Immediately_Visible
(Par_Unit
);
2366 Install_Visible_Declarations
(Par_Unit
);
2367 Install_Private_Declarations
(Par_Unit
);
2371 Re_Install_Use_Clauses
;
2372 Install_Context
(N
);
2374 -- Restore state of suppress flags for current body
2376 Scope_Suppress
:= Svg
;
2378 -- If the subunit is within a child unit, then siblings of any parent
2379 -- unit that appear in the context clause of the subunit must also be
2380 -- made immediately visible.
2382 if Present
(Enclosing_Child
) then
2383 Install_Siblings
(Enclosing_Child
, N
);
2387 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2388 Analyze
(Proper_Body
(Unit
(N
)));
2391 -- The subunit may contain a with_clause on a sibling of some ancestor.
2392 -- Removing the context will remove from visibility those ancestor child
2393 -- units, which must be restored to the visibility they have in the
2396 if Present
(Enclosing_Child
) then
2401 while Present
(C
) and then C
/= Standard_Standard
loop
2402 Set_Is_Immediately_Visible
(C
);
2403 Set_Is_Visible_Lib_Unit
(C
);
2409 -- Deal with restore of restrictions
2411 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2412 end Analyze_Subunit
;
2414 ----------------------------
2415 -- Analyze_Task_Body_Stub --
2416 ----------------------------
2418 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2419 Loc
: constant Source_Ptr
:= Sloc
(N
);
2420 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
2423 Check_Stub_Level
(N
);
2425 -- First occurrence of name may have been as an incomplete type
2427 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2428 Nam
:= Full_View
(Nam
);
2431 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2432 Error_Msg_N
("missing specification for task body", N
);
2435 -- Currently there are no language-defined aspects that can apply to
2436 -- a task body stub. Issue an error and remove the aspects to prevent
2439 if Has_Aspects
(N
) then
2441 ("aspects on task bodies are not allowed",
2442 First
(Aspect_Specifications
(N
)));
2446 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
2447 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
2448 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2450 -- Check for duplicate stub, if so give message and terminate
2452 if Has_Completion
(Etype
(Nam
)) then
2453 Error_Msg_N
("duplicate stub for task", N
);
2456 Set_Has_Completion
(Etype
(Nam
));
2459 Analyze_Proper_Body
(N
, Etype
(Nam
));
2461 -- Set elaboration flag to indicate that entity is callable. This
2462 -- cannot be done in the expansion of the body itself, because the
2463 -- proper body is not in a declarative part. This is only done if
2464 -- expansion is active, because the context may be generic and the
2465 -- flag not defined yet.
2467 if Expander_Active
then
2469 Make_Assignment_Statement
(Loc
,
2471 Make_Identifier
(Loc
,
2472 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2473 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2476 end Analyze_Task_Body_Stub
;
2478 -------------------------
2479 -- Analyze_With_Clause --
2480 -------------------------
2482 -- Analyze the declaration of a unit in a with clause. At end, label the
2483 -- with clause with the defining entity for the unit.
2485 procedure Analyze_With_Clause
(N
: Node_Id
) is
2487 -- Retrieve the original kind of the unit node, before analysis. If it
2488 -- is a subprogram instantiation, its analysis below will rewrite the
2489 -- node as the declaration of the wrapper package. If the same
2490 -- instantiation appears indirectly elsewhere in the context, it will
2491 -- have been analyzed already.
2493 Unit_Kind
: constant Node_Kind
:=
2494 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2495 Nam
: constant Node_Id
:= Name
(N
);
2497 Par_Name
: Entity_Id
;
2502 -- Set True if the unit currently being compiled is an internal unit
2504 Restriction_Violation
: Boolean := False;
2505 -- Set True if a with violates a restriction, no point in giving any
2506 -- warnings if we have this definite error.
2508 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2511 U
:= Unit
(Library_Unit
(N
));
2513 -- If this is an internal unit which is a renaming, then this is a
2514 -- violation of No_Obsolescent_Features.
2516 -- Note: this is not quite right if the user defines one of these units
2517 -- himself, but that's a marginal case, and fixing it is hard ???
2519 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2521 F
: constant File_Name_Type
:=
2522 Unit_File_Name
(Get_Source_Unit
(U
));
2524 if Is_Predefined_File_Name
(F
, Renamings_Included
=> True)
2526 Is_Predefined_File_Name
(F
, Renamings_Included
=> False)
2528 Check_Restriction
(No_Obsolescent_Features
, N
);
2529 Restriction_Violation
:= True;
2534 -- Check No_Implementation_Units violation
2536 if Restriction_Check_Required
(No_Implementation_Units
) then
2537 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2540 Check_Restriction
(No_Implementation_Units
, Nam
);
2541 Restriction_Violation
:= True;
2545 -- Several actions are skipped for dummy packages (those supplied for
2546 -- with's where no matching file could be found). Such packages are
2547 -- identified by the Sloc value being set to No_Location.
2549 if Limited_Present
(N
) then
2551 -- Ada 2005 (AI-50217): Build visibility structures but do not
2552 -- analyze the unit.
2554 if Sloc
(U
) /= No_Location
then
2555 Build_Limited_Views
(N
);
2561 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2562 -- already detected serious errors then we mark the with-clause nodes as
2563 -- analyzed before the corresponding compilation unit is analyzed. This
2564 -- is done here to protect the frontend against never ending recursion
2565 -- caused by circularities in the sources (because the previous errors
2566 -- may break the regular machine of the compiler implemented in
2567 -- Load_Unit to detect circularities).
2569 if Serious_Errors_Detected
> 0 and then Try_Semantics
then
2573 -- If the library unit is a predefined unit, and we are in high
2574 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
2575 -- for the analysis of the with'ed unit. This mode does not prevent
2576 -- explicit with'ing of run-time units.
2578 if Configurable_Run_Time_Mode
2579 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2581 Configurable_Run_Time_Mode
:= False;
2582 Semantics
(Library_Unit
(N
));
2583 Configurable_Run_Time_Mode
:= True;
2586 Semantics
(Library_Unit
(N
));
2589 Intunit
:= Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
));
2591 if Sloc
(U
) /= No_Location
then
2593 -- Check restrictions, except that we skip the check if this is an
2594 -- internal unit unless we are compiling the internal unit as the
2595 -- main unit. We also skip this for dummy packages.
2597 Check_Restriction_No_Dependence
(Nam
, N
);
2599 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2600 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2603 -- Deal with special case of GNAT.Current_Exceptions which interacts
2604 -- with the optimization of local raise statements into gotos.
2606 if Nkind
(Nam
) = N_Selected_Component
2607 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2608 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2609 and then Nam_In
(Chars
(Selector_Name
(Nam
)),
2610 Name_Most_Recent_Exception
,
2611 Name_Exception_Traces
)
2613 Check_Restriction
(No_Exception_Propagation
, N
);
2614 Special_Exception_Package_Used
:= True;
2617 -- Check for inappropriate with of internal implementation unit if we
2618 -- are not compiling an internal unit and also check for withing unit
2619 -- in wrong version of Ada. Do not issue these messages for implicit
2620 -- with's generated by the compiler itself.
2622 if Implementation_Unit_Warnings
2623 and then not Intunit
2624 and then not Implicit_With
(N
)
2625 and then not Restriction_Violation
2628 U_Kind
: constant Kind_Of_Unit
:=
2629 Get_Kind_Of_Unit
(Get_Source_Unit
(U
));
2632 if U_Kind
= Implementation_Unit
then
2633 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2635 -- Add alternative name if available, otherwise issue a
2636 -- general warning message.
2638 if Error_Msg_Strlen
/= 0 then
2639 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2642 ("\use of this unit is non-portable " &
2643 "and version-dependent?i?", Name
(N
));
2646 elsif U_Kind
= Ada_2005_Unit
2647 and then Ada_Version
< Ada_2005
2648 and then Warn_On_Ada_2005_Compatibility
2650 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2652 elsif U_Kind
= Ada_2012_Unit
2653 and then Ada_Version
< Ada_2012
2654 and then Warn_On_Ada_2012_Compatibility
2656 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2662 -- Semantic analysis of a generic unit is performed on a copy of
2663 -- the original tree. Retrieve the entity on which semantic info
2664 -- actually appears.
2666 if Unit_Kind
in N_Generic_Declaration
then
2667 E_Name
:= Defining_Entity
(U
);
2669 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2670 -- the case of an instantiation, semantic analysis above will have
2671 -- replaced the unit by its instantiated version. If the instance body
2672 -- has been generated, the instance now denotes the body entity. For
2673 -- visibility purposes we need the entity of its spec.
2675 elsif (Unit_Kind
= N_Package_Instantiation
2676 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2677 N_Package_Instantiation
)
2678 and then Nkind
(U
) = N_Package_Body
2680 E_Name
:= Corresponding_Spec
(U
);
2682 elsif Unit_Kind
= N_Package_Instantiation
2683 and then Nkind
(U
) = N_Package_Instantiation
2684 and then Present
(Instance_Spec
(U
))
2686 -- If the instance has not been rewritten as a package declaration,
2687 -- then it appeared already in a previous with clause. Retrieve
2688 -- the entity from the previous instance.
2690 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2692 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2694 -- The visible subprogram is created during instantiation, and is
2695 -- an attribute of the wrapper package. We retrieve the wrapper
2696 -- package directly from the instantiation node. If the instance
2697 -- is inlined the unit is still an instantiation. Otherwise it has
2698 -- been rewritten as the declaration of the wrapper itself.
2700 if Nkind
(U
) in N_Subprogram_Instantiation
then
2703 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2705 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2708 elsif Unit_Kind
= N_Package_Renaming_Declaration
2709 or else Unit_Kind
in N_Generic_Renaming_Declaration
2711 E_Name
:= Defining_Entity
(U
);
2713 elsif Unit_Kind
= N_Subprogram_Body
2714 and then Nkind
(Name
(N
)) = N_Selected_Component
2715 and then not Acts_As_Spec
(Library_Unit
(N
))
2717 -- For a child unit that has no spec, one has been created and
2718 -- analyzed. The entity required is that of the spec.
2720 E_Name
:= Corresponding_Spec
(U
);
2723 E_Name
:= Defining_Entity
(U
);
2726 if Nkind
(Name
(N
)) = N_Selected_Component
then
2728 -- Child unit in a with clause
2730 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2732 -- If this is a child unit without a spec, and it has been analyzed
2733 -- already, a declaration has been created for it. The with_clause
2734 -- must reflect the actual body, and not the generated declaration,
2735 -- to prevent spurious binding errors involving an out-of-date spec.
2736 -- Note that this can only happen if the unit includes more than one
2737 -- with_clause for the child unit (e.g. in separate subunits).
2739 if Unit_Kind
= N_Subprogram_Declaration
2740 and then Analyzed
(Library_Unit
(N
))
2741 and then not Comes_From_Source
(Library_Unit
(N
))
2743 Set_Library_Unit
(N
,
2744 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2748 -- Restore style checks
2750 Style_Check
:= Save_Style_Check
;
2752 -- Record the reference, but do NOT set the unit as referenced, we want
2753 -- to consider the unit as unreferenced if this is the only reference
2756 Set_Entity_With_Checks
(Name
(N
), E_Name
);
2757 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
2759 -- Generate references and check No_Dependence restriction for parents
2761 if Is_Child_Unit
(E_Name
) then
2762 Pref
:= Prefix
(Name
(N
));
2763 Par_Name
:= Scope
(E_Name
);
2764 while Nkind
(Pref
) = N_Selected_Component
loop
2765 Change_Selected_Component_To_Expanded_Name
(Pref
);
2767 if Present
(Entity
(Selector_Name
(Pref
)))
2769 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
2770 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
2772 -- The prefix is a child unit that denotes a renaming declaration.
2773 -- Replace the prefix directly with the renamed unit, because the
2774 -- rest of the prefix is irrelevant to the visibility of the real
2777 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
2781 Set_Entity_With_Checks
(Pref
, Par_Name
);
2783 Generate_Reference
(Par_Name
, Pref
);
2784 Check_Restriction_No_Dependence
(Pref
, N
);
2785 Pref
:= Prefix
(Pref
);
2787 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2788 -- is set to Standard_Standard, and no attempt should be made to
2789 -- further unwind scopes.
2791 if Par_Name
/= Standard_Standard
then
2792 Par_Name
:= Scope
(Par_Name
);
2795 -- Abandon processing in case of previous errors
2797 if No
(Par_Name
) then
2798 Check_Error_Detected
;
2803 if Present
(Entity
(Pref
))
2804 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
2806 -- If the entity is set without its unit being compiled, the
2807 -- original parent is a renaming, and Par_Name is the renamed
2808 -- entity. For visibility purposes, we need the original entity,
2809 -- which must be analyzed now because Load_Unit directly retrieves
2810 -- the renamed unit, and the renaming declaration itself has not
2813 Analyze
(Parent
(Parent
(Entity
(Pref
))));
2814 pragma Assert
(Renamed_Object
(Entity
(Pref
)) = Par_Name
);
2815 Par_Name
:= Entity
(Pref
);
2818 -- Guard against missing or misspelled child units
2820 if Present
(Par_Name
) then
2821 Set_Entity_With_Checks
(Pref
, Par_Name
);
2822 Generate_Reference
(Par_Name
, Pref
);
2825 pragma Assert
(Serious_Errors_Detected
/= 0);
2827 -- Mark the node to indicate that a related error has been posted.
2828 -- This defends further compilation passes against improper use of
2829 -- the invalid WITH clause node.
2831 Set_Error_Posted
(N
);
2832 Set_Name
(N
, Error
);
2837 -- If the withed unit is System, and a system extension pragma is
2838 -- present, compile the extension now, rather than waiting for a
2839 -- visibility check on a specific entity.
2841 if Chars
(E_Name
) = Name_System
2842 and then Scope
(E_Name
) = Standard_Standard
2843 and then Present
(System_Extend_Unit
)
2844 and then Present_System_Aux
(N
)
2846 -- If the extension is not present, an error will have been emitted
2851 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2852 -- to private_with units; they will be made visible later (just before
2853 -- the private part is analyzed)
2855 if Private_Present
(N
) then
2856 Set_Is_Immediately_Visible
(E_Name
, False);
2859 -- Propagate Fatal_Error setting from with'ed unit to current unit
2861 case Fatal_Error
(Get_Source_Unit
(Library_Unit
(N
))) is
2863 -- Nothing to do if with'ed unit had no error
2868 -- If with'ed unit had a detected fatal error, propagate it
2870 when Error_Detected
=>
2871 Set_Fatal_Error
(Current_Sem_Unit
, Error_Detected
);
2873 -- If with'ed unit had an ignored error, then propagate it but do not
2874 -- overide an existring setting.
2876 when Error_Ignored
=>
2877 if Fatal_Error
(Current_Sem_Unit
) = None
then
2878 Set_Fatal_Error
(Current_Sem_Unit
, Error_Ignored
);
2881 end Analyze_With_Clause
;
2883 ------------------------------
2884 -- Check_Private_Child_Unit --
2885 ------------------------------
2887 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
2888 Lib_Unit
: constant Node_Id
:= Unit
(N
);
2890 Curr_Unit
: Entity_Id
;
2891 Sub_Parent
: Node_Id
;
2892 Priv_Child
: Entity_Id
;
2893 Par_Lib
: Entity_Id
;
2896 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean;
2897 -- Returns true if and only if the library unit is declared with
2898 -- an explicit designation of private.
2900 -----------------------------
2901 -- Is_Private_Library_Unit --
2902 -----------------------------
2904 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
2905 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
2908 return Private_Present
(Comp_Unit
);
2909 end Is_Private_Library_Unit
;
2911 -- Start of processing for Check_Private_Child_Unit
2914 if Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subprogram_Body
) then
2915 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
2916 Par_Lib
:= Curr_Unit
;
2918 elsif Nkind
(Lib_Unit
) = N_Subunit
then
2920 -- The parent is itself a body. The parent entity is to be found in
2921 -- the corresponding spec.
2923 Sub_Parent
:= Library_Unit
(N
);
2924 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
2926 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2927 -- enclosing body, retrieve the spec entity which is the proper
2928 -- ancestor we need for the following tests.
2930 if Ekind
(Curr_Unit
) = E_Package_Body
then
2931 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
2934 Par_Lib
:= Curr_Unit
;
2937 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
2939 Par_Lib
:= Curr_Unit
;
2940 Par_Spec
:= Parent_Spec
(Lib_Unit
);
2942 if No
(Par_Spec
) then
2945 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
2949 -- Loop through context items
2951 Item
:= First
(Context_Items
(N
));
2952 while Present
(Item
) loop
2954 -- Ada 2005 (AI-262): Allow private_with of a private child package
2955 -- in public siblings
2957 if Nkind
(Item
) = N_With_Clause
2958 and then not Implicit_With
(Item
)
2959 and then not Limited_Present
(Item
)
2960 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
2962 Priv_Child
:= Entity
(Name
(Item
));
2965 Curr_Parent
: Entity_Id
:= Par_Lib
;
2966 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
2967 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
2968 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
2971 -- If the child unit is a public child then locate the nearest
2972 -- private ancestor. Child_Parent will then be set to the
2973 -- parent of that ancestor.
2975 if not Is_Private_Library_Unit
(Priv_Child
) then
2976 while Present
(Prv_Ancestor
)
2977 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
2979 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
2982 if Present
(Prv_Ancestor
) then
2983 Child_Parent
:= Scope
(Prv_Ancestor
);
2987 while Present
(Curr_Parent
)
2988 and then Curr_Parent
/= Standard_Standard
2989 and then Curr_Parent
/= Child_Parent
2992 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
2993 Curr_Parent
:= Scope
(Curr_Parent
);
2996 if No
(Curr_Parent
) then
2997 Curr_Parent
:= Standard_Standard
;
3000 if Curr_Parent
/= Child_Parent
then
3001 if Ekind
(Priv_Child
) = E_Generic_Package
3002 and then Chars
(Priv_Child
) in Text_IO_Package_Name
3003 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
3006 ("& is a nested package, not a compilation unit",
3007 Name
(Item
), Priv_Child
);
3011 ("unit in with clause is private child unit!", Item
);
3013 ("\current unit must also have parent&!",
3014 Item
, Child_Parent
);
3018 or else Private_Present
(Item
)
3019 or else Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subunit
)
3020 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3021 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
3027 ("current unit must also be private descendant of&",
3028 Item
, Child_Parent
);
3036 end Check_Private_Child_Unit
;
3038 ----------------------
3039 -- Check_Stub_Level --
3040 ----------------------
3042 procedure Check_Stub_Level
(N
: Node_Id
) is
3043 Par
: constant Node_Id
:= Parent
(N
);
3044 Kind
: constant Node_Kind
:= Nkind
(Par
);
3047 if Nkind_In
(Kind
, N_Package_Body
,
3051 and then Nkind_In
(Parent
(Par
), N_Compilation_Unit
, N_Subunit
)
3055 -- In an instance, a missing stub appears at any level. A warning
3056 -- message will have been emitted already for the missing file.
3058 elsif not In_Instance
then
3059 Error_Msg_N
("stub cannot appear in an inner scope", N
);
3061 elsif Expander_Active
then
3062 Error_Msg_N
("missing proper body", N
);
3064 end Check_Stub_Level
;
3066 ------------------------
3067 -- Expand_With_Clause --
3068 ------------------------
3070 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
3071 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3072 Ent
: constant Entity_Id
:= Entity
(Nam
);
3076 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3077 -- Build name to be used in implicit with_clause. In most cases this
3078 -- is the source name, but if renamings are present we must make the
3079 -- original unit visible, not the one it renames. The entity in the
3080 -- with clause is the renamed unit, but the identifier is the one from
3081 -- the source, which allows us to recover the unit renaming.
3083 ---------------------
3084 -- Build_Unit_Name --
3085 ---------------------
3087 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3092 if Nkind
(Nam
) = N_Identifier
then
3093 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3096 Ent
:= Entity
(Nam
);
3098 if Present
(Entity
(Selector_Name
(Nam
)))
3099 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3101 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
))))
3102 = N_Package_Renaming_Declaration
3104 -- The name in the with_clause is of the form A.B.C, and B is
3105 -- given by a renaming declaration. In that case we may not
3106 -- have analyzed the unit for B, but replaced it directly in
3107 -- lib-load with the unit it renames. We have to make A.B
3108 -- visible, so analyze the declaration for B now, in case it
3109 -- has not been done yet.
3111 Ent
:= Entity
(Selector_Name
(Nam
));
3114 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3118 Make_Expanded_Name
(Loc
,
3119 Chars
=> Chars
(Entity
(Nam
)),
3120 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3121 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3122 Set_Entity
(Result
, Ent
);
3125 end Build_Unit_Name
;
3127 -- Start of processing for Expand_With_Clause
3131 Make_With_Clause
(Loc
,
3132 Name
=> Build_Unit_Name
(Nam
));
3134 P
:= Parent
(Unit_Declaration_Node
(Ent
));
3135 Set_Library_Unit
(Withn
, P
);
3136 Set_Corresponding_Spec
(Withn
, Ent
);
3137 Set_First_Name
(Withn
, True);
3138 Set_Implicit_With
(Withn
, True);
3140 -- If the unit is a package or generic package declaration, a private_
3141 -- with_clause on a child unit implies that the implicit with on the
3142 -- parent is also private.
3144 if Nkind_In
(Unit
(N
), N_Package_Declaration
,
3145 N_Generic_Package_Declaration
)
3147 Set_Private_Present
(Withn
, Private_Present
(Item
));
3150 Prepend
(Withn
, Context_Items
(N
));
3151 Mark_Rewrite_Insertion
(Withn
);
3152 Install_Withed_Unit
(Withn
);
3154 -- If we have "with X.Y;", we want to recurse on "X", except in the
3155 -- unusual case where X.Y is a renaming of X. In that case, the scope
3156 -- of X will be null.
3158 if Nkind
(Nam
) = N_Expanded_Name
3159 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3161 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3163 end Expand_With_Clause
;
3165 --------------------------------
3166 -- Generate_Parent_References --
3167 --------------------------------
3169 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3171 P_Name
: Entity_Id
:= P_Id
;
3174 if Nkind
(N
) = N_Subunit
then
3177 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3180 if Nkind
(Pref
) = N_Expanded_Name
then
3182 -- Done already, if the unit has been compiled indirectly as
3183 -- part of the closure of its context because of inlining.
3188 while Nkind
(Pref
) = N_Selected_Component
loop
3189 Change_Selected_Component_To_Expanded_Name
(Pref
);
3190 Set_Entity
(Pref
, P_Name
);
3191 Set_Etype
(Pref
, Etype
(P_Name
));
3192 Generate_Reference
(P_Name
, Pref
, 'r');
3193 Pref
:= Prefix
(Pref
);
3194 P_Name
:= Scope
(P_Name
);
3197 -- The guard here on P_Name is to handle the error condition where
3198 -- the parent unit is missing because the file was not found.
3200 if Present
(P_Name
) then
3201 Set_Entity
(Pref
, P_Name
);
3202 Set_Etype
(Pref
, Etype
(P_Name
));
3203 Generate_Reference
(P_Name
, Pref
, 'r');
3204 Style
.Check_Identifier
(Pref
, P_Name
);
3206 end Generate_Parent_References
;
3208 ---------------------
3209 -- Has_With_Clause --
3210 ---------------------
3212 function Has_With_Clause
3215 Is_Limited
: Boolean := False) return Boolean
3219 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3220 -- Return the entity for the unit named in a [limited] with clause
3226 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3228 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3229 return Entity
(Selector_Name
(Name
(Clause
)));
3231 return Entity
(Name
(Clause
));
3235 -- Start of processing for Has_With_Clause
3238 if Present
(Context_Items
(C_Unit
)) then
3239 Item
:= First
(Context_Items
(C_Unit
));
3240 while Present
(Item
) loop
3241 if Nkind
(Item
) = N_With_Clause
3242 and then Limited_Present
(Item
) = Is_Limited
3243 and then Named_Unit
(Item
) = Pack
3253 end Has_With_Clause
;
3255 -----------------------------
3256 -- Implicit_With_On_Parent --
3257 -----------------------------
3259 procedure Implicit_With_On_Parent
3260 (Child_Unit
: Node_Id
;
3263 Loc
: constant Source_Ptr
:= Sloc
(N
);
3264 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3265 P_Unit
: Node_Id
:= Unit
(P
);
3266 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3269 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3270 -- Build prefix of child unit name. Recurse if needed
3272 function Build_Unit_Name
return Node_Id
;
3273 -- If the unit is a child unit, build qualified name with all ancestors
3275 -------------------------
3276 -- Build_Ancestor_Name --
3277 -------------------------
3279 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3280 P_Ref
: constant Node_Id
:=
3281 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3282 P_Spec
: Node_Id
:= P
;
3285 -- Ancestor may have been rewritten as a package body. Retrieve
3286 -- the original spec to trace earlier ancestors.
3288 if Nkind
(P
) = N_Package_Body
3289 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3291 P_Spec
:= Original_Node
(P
);
3294 if No
(Parent_Spec
(P_Spec
)) then
3298 Make_Selected_Component
(Loc
,
3299 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3300 Selector_Name
=> P_Ref
);
3302 end Build_Ancestor_Name
;
3304 ---------------------
3305 -- Build_Unit_Name --
3306 ---------------------
3308 function Build_Unit_Name
return Node_Id
is
3312 if No
(Parent_Spec
(P_Unit
)) then
3313 return New_Occurrence_Of
(P_Name
, Loc
);
3317 Make_Expanded_Name
(Loc
,
3318 Chars
=> Chars
(P_Name
),
3319 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3320 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3321 Set_Entity
(Result
, P_Name
);
3324 end Build_Unit_Name
;
3326 -- Start of processing for Implicit_With_On_Parent
3329 -- The unit of the current compilation may be a package body that
3330 -- replaces an instance node. In this case we need the original instance
3331 -- node to construct the proper parent name.
3333 if Nkind
(P_Unit
) = N_Package_Body
3334 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3336 P_Unit
:= Original_Node
(P_Unit
);
3339 -- We add the implicit with if the child unit is the current unit being
3340 -- compiled. If the current unit is a body, we do not want to add an
3341 -- implicit_with a second time to the corresponding spec.
3343 if Nkind
(Child_Unit
) = N_Package_Declaration
3344 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3349 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3351 Set_Library_Unit
(Withn
, P
);
3352 Set_Corresponding_Spec
(Withn
, P_Name
);
3353 Set_First_Name
(Withn
, True);
3354 Set_Implicit_With
(Withn
, True);
3356 -- Node is placed at the beginning of the context items, so that
3357 -- subsequent use clauses on the parent can be validated.
3359 Prepend
(Withn
, Context_Items
(N
));
3360 Mark_Rewrite_Insertion
(Withn
);
3361 Install_Withed_Unit
(Withn
);
3363 if Is_Child_Spec
(P_Unit
) then
3364 Implicit_With_On_Parent
(P_Unit
, N
);
3366 end Implicit_With_On_Parent
;
3372 function In_Chain
(E
: Entity_Id
) return Boolean is
3376 H
:= Current_Entity
(E
);
3377 while Present
(H
) loop
3388 ---------------------
3389 -- Install_Context --
3390 ---------------------
3392 procedure Install_Context
(N
: Node_Id
) is
3393 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3396 Install_Context_Clauses
(N
);
3398 if Is_Child_Spec
(Lib_Unit
) then
3399 Install_Parents
(Lib_Unit
, Private_Present
(Parent
(Lib_Unit
)));
3402 Install_Limited_Context_Clauses
(N
);
3403 end Install_Context
;
3405 -----------------------------
3406 -- Install_Context_Clauses --
3407 -----------------------------
3409 procedure Install_Context_Clauses
(N
: Node_Id
) is
3410 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3412 Uname_Node
: Entity_Id
;
3413 Check_Private
: Boolean := False;
3414 Decl_Node
: Node_Id
;
3415 Lib_Parent
: Entity_Id
;
3418 -- First skip configuration pragmas at the start of the context. They
3419 -- are not technically part of the context clause, but that's where the
3420 -- parser puts them. Note they were analyzed in Analyze_Context.
3422 Item
:= First
(Context_Items
(N
));
3423 while Present
(Item
)
3424 and then Nkind
(Item
) = N_Pragma
3425 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
3430 -- Loop through the actual context clause items. We process everything
3431 -- except Limited_With clauses in this routine. Limited_With clauses
3432 -- are separately installed (see Install_Limited_Context_Clauses).
3434 while Present
(Item
) loop
3436 -- Case of explicit WITH clause
3438 if Nkind
(Item
) = N_With_Clause
3439 and then not Implicit_With
(Item
)
3441 if Limited_Present
(Item
) then
3443 -- Limited withed units will be installed later
3447 -- If Name (Item) is not an entity name, something is wrong, and
3448 -- this will be detected in due course, for now ignore the item
3450 elsif not Is_Entity_Name
(Name
(Item
)) then
3453 elsif No
(Entity
(Name
(Item
))) then
3454 Set_Entity
(Name
(Item
), Any_Id
);
3458 Uname_Node
:= Entity
(Name
(Item
));
3460 if Is_Private_Descendant
(Uname_Node
) then
3461 Check_Private
:= True;
3464 Install_Withed_Unit
(Item
);
3466 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3468 -- If the unit is a subprogram instance, it appears nested within
3469 -- a package that carries the parent information.
3471 if Is_Generic_Instance
(Uname_Node
)
3472 and then Ekind
(Uname_Node
) /= E_Package
3474 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3477 if Is_Child_Spec
(Decl_Node
) then
3478 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3479 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3481 -- If not an expanded name, the child unit must be a
3482 -- renaming, nothing to do.
3487 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3488 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3489 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3491 Implicit_With_On_Parent
3492 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3495 -- Check license conditions unless this is a dummy unit
3497 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3498 License_Check
: declare
3499 Withu
: constant Unit_Number_Type
:=
3500 Get_Source_Unit
(Library_Unit
(Item
));
3501 Withl
: constant License_Type
:=
3502 License
(Source_Index
(Withu
));
3503 Unitl
: constant License_Type
:=
3504 License
(Source_Index
(Current_Sem_Unit
));
3506 procedure License_Error
;
3507 -- Signal error of bad license
3513 procedure License_Error
is
3516 ("license of withed unit & may be inconsistent??",
3520 -- Start of processing for License_Check
3523 -- Exclude license check if withed unit is an internal unit.
3524 -- This situation arises e.g. with the GPL version of GNAT.
3526 if Is_Internal_File_Name
(Unit_File_Name
(Withu
)) then
3529 -- Otherwise check various cases
3541 if Withl
= Restricted
then
3545 when Modified_GPL
=>
3546 if Withl
= Restricted
or else Withl
= GPL
then
3550 when Unrestricted
=>
3557 -- Case of USE PACKAGE clause
3559 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3560 Analyze_Use_Package
(Item
);
3562 -- Case of USE TYPE clause
3564 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3565 Analyze_Use_Type
(Item
);
3569 elsif Nkind
(Item
) = N_Pragma
then
3577 if Is_Child_Spec
(Lib_Unit
) then
3579 -- The unit also has implicit with_clauses on its own parents
3581 if No
(Context_Items
(N
)) then
3582 Set_Context_Items
(N
, New_List
);
3585 Implicit_With_On_Parent
(Lib_Unit
, N
);
3588 -- If the unit is a body, the context of the specification must also
3589 -- be installed. That includes private with_clauses in that context.
3591 if Nkind
(Lib_Unit
) = N_Package_Body
3592 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3593 and then not Acts_As_Spec
(N
))
3595 Install_Context
(Library_Unit
(N
));
3597 -- Only install private with-clauses of a spec that comes from
3598 -- source, excluding specs created for a subprogram body that is
3601 if Comes_From_Source
(Library_Unit
(N
)) then
3602 Install_Private_With_Clauses
3603 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3606 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3608 -- If the unit is the body of a public child unit, the private
3609 -- declarations of the parent must be made visible. If the child
3610 -- unit is private, the private declarations have been installed
3611 -- already in the call to Install_Parents for the spec. Installing
3612 -- private declarations must be done for all ancestors of public
3613 -- child units. In addition, sibling units mentioned in the
3614 -- context clause of the body are directly visible.
3622 Lib_Spec
:= Unit
(Library_Unit
(N
));
3623 while Is_Child_Spec
(Lib_Spec
) loop
3624 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3625 P_Name
:= Defining_Entity
(P
);
3627 if not (Private_Present
(Parent
(Lib_Spec
)))
3628 and then not In_Private_Part
(P_Name
)
3630 Install_Private_Declarations
(P_Name
);
3631 Install_Private_With_Clauses
(P_Name
);
3632 Set_Use
(Private_Declarations
(Specification
(P
)));
3640 -- For a package body, children in context are immediately visible
3642 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3645 if Nkind_In
(Lib_Unit
, N_Generic_Package_Declaration
,
3646 N_Generic_Subprogram_Declaration
,
3647 N_Package_Declaration
,
3648 N_Subprogram_Declaration
)
3650 if Is_Child_Spec
(Lib_Unit
) then
3651 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3652 Set_Is_Private_Descendant
3653 (Defining_Entity
(Lib_Unit
),
3654 Is_Private_Descendant
(Lib_Parent
)
3655 or else Private_Present
(Parent
(Lib_Unit
)));
3658 Set_Is_Private_Descendant
3659 (Defining_Entity
(Lib_Unit
),
3660 Private_Present
(Parent
(Lib_Unit
)));
3664 if Check_Private
then
3665 Check_Private_Child_Unit
(N
);
3667 end Install_Context_Clauses
;
3669 -------------------------------------
3670 -- Install_Limited_Context_Clauses --
3671 -------------------------------------
3673 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3676 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3677 -- Check that the unlimited view of a given compilation_unit is not
3678 -- already visible through "use + renamings".
3680 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3681 -- Check that if a limited_with clause of a given compilation_unit
3682 -- mentions a descendant of a private child of some library unit, then
3683 -- the given compilation_unit must be the declaration of a private
3684 -- descendant of that library unit, or a public descendant of such. The
3685 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3686 -- use entities on the limited with_clauses because their units have not
3687 -- been analyzed, so we have to climb the tree of ancestors looking for
3688 -- private keywords.
3690 procedure Expand_Limited_With_Clause
3691 (Comp_Unit
: Node_Id
;
3694 -- If a child unit appears in a limited_with clause, there are implicit
3695 -- limited_with clauses on all parents that are not already visible
3696 -- through a regular with clause. This procedure creates the implicit
3697 -- limited with_clauses for the parents and loads the corresponding
3698 -- units. The shadow entities are created when the inserted clause is
3699 -- analyzed. Implements Ada 2005 (AI-50217).
3701 ---------------------
3702 -- Check_Renamings --
3703 ---------------------
3705 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
3714 pragma Assert
(Nkind
(W
) = N_With_Clause
);
3716 -- Protect the frontend against previous critical errors
3718 case Nkind
(Unit
(Library_Unit
(W
))) is
3719 when N_Subprogram_Declaration |
3720 N_Package_Declaration |
3721 N_Generic_Subprogram_Declaration |
3722 N_Generic_Package_Declaration
=>
3729 -- Check "use + renamings"
3731 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
3732 Spec
:= Specification
(Unit
(P
));
3734 Item
:= First
(Visible_Declarations
(Spec
));
3735 while Present
(Item
) loop
3737 -- Look only at use package clauses
3739 if Nkind
(Item
) = N_Use_Package_Clause
then
3741 -- Traverse the list of packages
3743 Nam
:= First
(Names
(Item
));
3744 while Present
(Nam
) loop
3747 pragma Assert
(Present
(Parent
(E
)));
3749 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
3750 and then Renamed_Entity
(E
) = WEnt
3752 -- The unlimited view is visible through use clause and
3753 -- renamings. There is no need to generate the error
3754 -- message here because Is_Visible_Through_Renamings
3755 -- takes care of generating the precise error message.
3759 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
3761 -- The use clause may refer to a local package.
3762 -- Check all the enclosing scopes.
3765 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
3771 ("unlimited view visible through use clause ", W
);
3783 -- Recursive call to check all the ancestors
3785 if Is_Child_Spec
(Unit
(P
)) then
3786 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
3788 end Check_Renamings
;
3790 ---------------------------------------
3791 -- Check_Private_Limited_Withed_Unit --
3792 ---------------------------------------
3794 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
3795 Curr_Parent
: Node_Id
;
3796 Child_Parent
: Node_Id
;
3797 Curr_Private
: Boolean;
3800 -- Compilation unit of the parent of the withed library unit
3802 Child_Parent
:= Library_Unit
(Item
);
3804 -- If the child unit is a public child, then locate its nearest
3805 -- private ancestor, if any, then Child_Parent will then be set to
3806 -- the parent of that ancestor.
3808 if not Private_Present
(Library_Unit
(Item
)) then
3809 while Present
(Child_Parent
)
3810 and then not Private_Present
(Child_Parent
)
3812 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3815 if No
(Child_Parent
) then
3820 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3822 -- Traverse all the ancestors of the current compilation unit to
3823 -- check if it is a descendant of named library unit.
3825 Curr_Parent
:= Parent
(Item
);
3826 Curr_Private
:= Private_Present
(Curr_Parent
);
3828 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
3829 and then Curr_Parent
/= Child_Parent
3831 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
3832 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
3835 if Curr_Parent
/= Child_Parent
then
3837 ("unit in with clause is private child unit!", Item
);
3839 ("\current unit must also have parent&!",
3840 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3842 elsif Private_Present
(Parent
(Item
))
3843 or else Curr_Private
3844 or else Private_Present
(Item
)
3845 or else Nkind_In
(Unit
(Parent
(Item
)), N_Package_Body
,
3849 -- Current unit is private, of descendant of a private unit
3855 ("current unit must also be private descendant of&",
3856 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3858 end Check_Private_Limited_Withed_Unit
;
3860 --------------------------------
3861 -- Expand_Limited_With_Clause --
3862 --------------------------------
3864 procedure Expand_Limited_With_Clause
3865 (Comp_Unit
: Node_Id
;
3869 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3870 Unum
: Unit_Number_Type
;
3873 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
3874 -- Returns true if the context already includes a with_clause for
3875 -- this unit. If the with_clause is non-limited, the unit is fully
3876 -- visible and an implicit limited_with should not be created. If
3877 -- there is already a limited_with clause for W, a second one is
3878 -- simply redundant.
3880 --------------------------
3881 -- Previous_Withed_Unit --
3882 --------------------------
3884 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
3888 -- A limited with_clause cannot appear in the same context_clause
3889 -- as a nonlimited with_clause which mentions the same library.
3891 Item
:= First
(Context_Items
(Comp_Unit
));
3892 while Present
(Item
) loop
3893 if Nkind
(Item
) = N_With_Clause
3894 and then Library_Unit
(Item
) = Library_Unit
(W
)
3903 end Previous_Withed_Unit
;
3905 -- Start of processing for Expand_Limited_With_Clause
3908 if Nkind
(Nam
) = N_Identifier
then
3910 -- Create node for name of withed unit
3913 Make_With_Clause
(Loc
,
3914 Name
=> New_Copy
(Nam
));
3916 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
3918 Make_With_Clause
(Loc
,
3919 Name
=> Make_Selected_Component
(Loc
,
3920 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
3921 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
3922 Set_Parent
(Withn
, Parent
(N
));
3925 Set_Limited_Present
(Withn
);
3926 Set_First_Name
(Withn
);
3927 Set_Implicit_With
(Withn
);
3931 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
3936 -- Do not generate a limited_with_clause on the current unit. This
3937 -- path is taken when a unit has a limited_with clause on one of its
3940 if Unum
= Current_Sem_Unit
then
3944 Set_Library_Unit
(Withn
, Cunit
(Unum
));
3945 Set_Corresponding_Spec
3946 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
3948 if not Previous_Withed_Unit
(Withn
) then
3949 Prepend
(Withn
, Context_Items
(Parent
(N
)));
3950 Mark_Rewrite_Insertion
(Withn
);
3952 -- Add implicit limited_with_clauses for parents of child units
3953 -- mentioned in limited_with clauses.
3955 if Nkind
(Nam
) = N_Selected_Component
then
3956 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
3961 if not Limited_View_Installed
(Withn
) then
3962 Install_Limited_Withed_Unit
(Withn
);
3965 end Expand_Limited_With_Clause
;
3967 -- Start of processing for Install_Limited_Context_Clauses
3970 Item
:= First
(Context_Items
(N
));
3971 while Present
(Item
) loop
3972 if Nkind
(Item
) = N_With_Clause
3973 and then Limited_Present
(Item
)
3974 and then not Error_Posted
(Item
)
3976 if Nkind
(Name
(Item
)) = N_Selected_Component
then
3977 Expand_Limited_With_Clause
3978 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
3981 Check_Private_Limited_Withed_Unit
(Item
);
3983 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
3984 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
3987 -- A unit may have a limited with on itself if it has a limited
3988 -- with_clause on one of its child units. In that case it is
3989 -- already being compiled and it makes no sense to install its
3992 -- If the item is a limited_private_with_clause, install it if the
3993 -- current unit is a body or if it is a private child. Otherwise
3994 -- the private clause is installed before analyzing the private
3995 -- part of the current unit.
3997 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
3998 and then not Limited_View_Installed
(Item
)
4000 not Is_Ancestor_Unit
4001 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
4003 if not Private_Present
(Item
)
4004 or else Private_Present
(N
)
4005 or else Nkind_In
(Unit
(N
), N_Package_Body
,
4009 Install_Limited_Withed_Unit
(Item
);
4017 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
4018 -- looking for incomplete subtype declarations of incomplete types
4019 -- visible through a limited with clause.
4021 if Ada_Version
>= Ada_2005
4022 and then Analyzed
(N
)
4023 and then Nkind
(Unit
(N
)) = N_Package_Declaration
4028 Non_Lim_View
: Entity_Id
;
4031 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
4032 while Present
(Decl
) loop
4033 if Nkind
(Decl
) = N_Subtype_Declaration
4035 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
4037 From_Limited_With
(Defining_Identifier
(Decl
))
4039 Def_Id
:= Defining_Identifier
(Decl
);
4040 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
4042 if not Is_Incomplete_Type
(Non_Lim_View
) then
4044 -- Convert an incomplete subtype declaration into a
4045 -- corresponding non-limited view subtype declaration.
4046 -- This is usually the case when analyzing a body that
4047 -- has regular with clauses, when the spec has limited
4050 -- If the non-limited view is still incomplete, it is
4051 -- the dummy entry already created, and the declaration
4052 -- cannot be reanalyzed. This is the case when installing
4053 -- a parent unit that has limited with-clauses.
4055 Set_Subtype_Indication
(Decl
,
4056 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
4057 Set_Etype
(Def_Id
, Non_Lim_View
);
4058 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
4059 Set_Analyzed
(Decl
, False);
4061 -- Reanalyze the declaration, suppressing the call to
4062 -- Enter_Name to avoid duplicate names.
4064 Analyze_Subtype_Declaration
4074 end Install_Limited_Context_Clauses
;
4076 ---------------------
4077 -- Install_Parents --
4078 ---------------------
4080 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean) is
4087 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4088 P_Name
:= Get_Parent_Entity
(P
);
4090 if Etype
(P_Name
) = Any_Type
then
4094 if Ekind
(P_Name
) = E_Generic_Package
4095 and then not Nkind_In
(Lib_Unit
, N_Generic_Subprogram_Declaration
,
4096 N_Generic_Package_Declaration
)
4097 and then Nkind
(Lib_Unit
) not in N_Generic_Renaming_Declaration
4100 ("child of a generic package must be a generic unit", Lib_Unit
);
4102 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4104 ("parent unit must be package or generic package", Lib_Unit
);
4105 raise Unrecoverable_Error
;
4107 elsif Present
(Renamed_Object
(P_Name
)) then
4108 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4109 raise Unrecoverable_Error
;
4111 -- Verify that a child of an instance is itself an instance, or the
4112 -- renaming of one. Given that an instance that is a unit is replaced
4113 -- with a package declaration, check against the original node. The
4114 -- parent may be currently being instantiated, in which case it appears
4115 -- as a declaration, but the generic_parent is already established
4116 -- indicating that we deal with an instance.
4118 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4119 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4120 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4122 (Nkind
(Lib_Unit
) = N_Package_Declaration
4123 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4128 ("child of an instance must be an instance or renaming",
4133 -- This is the recursive call that ensures all parents are loaded
4135 if Is_Child_Spec
(P
) then
4137 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)));
4140 -- Now we can install the context for this parent
4142 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4143 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4144 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4146 -- The child unit is in the declarative region of the parent. The parent
4147 -- must therefore appear in the scope stack and be visible, as when
4148 -- compiling the corresponding body. If the child unit is private or it
4149 -- is a package body, private declarations must be accessible as well.
4150 -- Use declarations in the parent must also be installed. Finally, other
4151 -- child units of the same parent that are in the context are
4152 -- immediately visible.
4154 -- Find entity for compilation unit, and set its private descendant
4155 -- status as needed. Indicate that it is a compilation unit, which is
4156 -- redundant in general, but needed if this is a generated child spec
4157 -- for a child body without previous spec.
4159 E_Name
:= Defining_Entity
(Lib_Unit
);
4161 Set_Is_Child_Unit
(E_Name
);
4162 Set_Is_Compilation_Unit
(E_Name
);
4164 Set_Is_Private_Descendant
(E_Name
,
4165 Is_Private_Descendant
(P_Name
)
4166 or else Private_Present
(Parent
(Lib_Unit
)));
4168 P_Spec
:= Package_Specification
(P_Name
);
4169 Push_Scope
(P_Name
);
4171 -- Save current visibility of unit
4173 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4174 Is_Immediately_Visible
(P_Name
);
4175 Set_Is_Immediately_Visible
(P_Name
);
4176 Install_Visible_Declarations
(P_Name
);
4177 Set_Use
(Visible_Declarations
(P_Spec
));
4179 -- If the parent is a generic unit, its formal part may contain formal
4180 -- packages and use clauses for them.
4182 if Ekind
(P_Name
) = E_Generic_Package
then
4183 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4186 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4187 Install_Private_Declarations
(P_Name
);
4188 Install_Private_With_Clauses
(P_Name
);
4189 Set_Use
(Private_Declarations
(P_Spec
));
4191 end Install_Parents
;
4193 ----------------------------------
4194 -- Install_Private_With_Clauses --
4195 ----------------------------------
4197 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4198 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4202 if Debug_Flag_I
then
4203 Write_Str
("install private with clauses of ");
4204 Write_Name
(Chars
(P
));
4208 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4209 Item
:= First
(Context_Items
(Parent
(Decl
)));
4210 while Present
(Item
) loop
4211 if Nkind
(Item
) = N_With_Clause
4212 and then Private_Present
(Item
)
4214 -- If the unit is an ancestor of the current one, it is the
4215 -- case of a private limited with clause on a child unit, and
4216 -- the compilation of one of its descendants, In that case the
4217 -- limited view is errelevant.
4219 if Limited_Present
(Item
) then
4220 if not Limited_View_Installed
(Item
)
4222 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4223 Cunit
(Current_Sem_Unit
))
4225 Install_Limited_Withed_Unit
(Item
);
4228 Install_Withed_Unit
(Item
, Private_With_OK
=> True);
4235 end Install_Private_With_Clauses
;
4237 ----------------------
4238 -- Install_Siblings --
4239 ----------------------
4241 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4247 -- Iterate over explicit with clauses, and check whether the scope of
4248 -- each entity is an ancestor of the current unit, in which case it is
4249 -- immediately visible.
4251 Item
:= First
(Context_Items
(N
));
4252 while Present
(Item
) loop
4254 -- Do not install private_with_clauses declaration, unless unit
4255 -- is itself a private child unit, or is a body. Note that for a
4256 -- subprogram body the private_with_clause does not take effect until
4257 -- after the specification.
4259 if Nkind
(Item
) /= N_With_Clause
4260 or else Implicit_With
(Item
)
4261 or else Limited_Present
(Item
)
4262 or else Error_Posted
(Item
)
4266 elsif not Private_Present
(Item
)
4267 or else Private_Present
(N
)
4268 or else Nkind
(Unit
(N
)) = N_Package_Body
4270 Id
:= Entity
(Name
(Item
));
4272 if Is_Child_Unit
(Id
)
4273 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4275 Set_Is_Immediately_Visible
(Id
);
4277 -- Check for the presence of another unit in the context that
4278 -- may be inadvertently hidden by the child.
4280 Prev
:= Current_Entity
(Id
);
4283 and then Is_Immediately_Visible
(Prev
)
4284 and then not Is_Child_Unit
(Prev
)
4290 Clause
:= First
(Context_Items
(N
));
4291 while Present
(Clause
) loop
4292 if Nkind
(Clause
) = N_With_Clause
4293 and then Entity
(Name
(Clause
)) = Prev
4296 ("child unit& hides compilation unit " &
4297 "with the same name??",
4307 -- The With_Clause may be on a grand-child or one of its further
4308 -- descendants, which makes a child immediately visible. Examine
4309 -- ancestry to determine whether such a child exists. For example,
4310 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4311 -- is immediately visible.
4313 elsif Is_Child_Unit
(Id
) then
4319 while Is_Child_Unit
(Par
) loop
4320 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4321 Set_Is_Immediately_Visible
(Par
);
4330 -- If the item is a private with-clause on a child unit, the parent
4331 -- may have been installed already, but the child unit must remain
4332 -- invisible until installed in a private part or body, unless there
4333 -- is already a regular with_clause for it in the current unit.
4335 elsif Private_Present
(Item
) then
4336 Id
:= Entity
(Name
(Item
));
4338 if Is_Child_Unit
(Id
) then
4342 function In_Context
return Boolean;
4343 -- Scan context of current unit, to check whether there is
4344 -- a with_clause on the same unit as a private with-clause
4345 -- on a parent, in which case child unit is visible. If the
4346 -- unit is a grand-child, the same applies to its parent.
4352 function In_Context
return Boolean is
4355 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4356 while Present
(Clause
) loop
4357 if Nkind
(Clause
) = N_With_Clause
4358 and then Comes_From_Source
(Clause
)
4359 and then Is_Entity_Name
(Name
(Clause
))
4360 and then not Private_Present
(Clause
)
4362 if Entity
(Name
(Clause
)) = Id
4364 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4365 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4378 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4385 end Install_Siblings
;
4387 ---------------------------------
4388 -- Install_Limited_Withed_Unit --
4389 ---------------------------------
4391 procedure Install_Limited_Withed_Unit
(N
: Node_Id
) is
4392 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4395 Is_Child_Package
: Boolean := False;
4396 Lim_Header
: Entity_Id
;
4397 Lim_Typ
: Entity_Id
;
4399 procedure Check_Body_Required
;
4400 -- A unit mentioned in a limited with_clause may not be mentioned in
4401 -- a regular with_clause, but must still be included in the current
4402 -- partition. We need to determine whether the unit needs a body, so
4403 -- that the binder can determine the name of the file to be compiled.
4404 -- Checking whether a unit needs a body can be done without semantic
4405 -- analysis, by examining the nature of the declarations in the package.
4407 function Has_Limited_With_Clause
4408 (C_Unit
: Entity_Id
;
4409 Pack
: Entity_Id
) return Boolean;
4410 -- Determine whether any package in the ancestor chain starting with
4411 -- C_Unit has a limited with clause for package Pack.
4413 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean;
4414 -- Check if some package installed though normal with-clauses has a
4415 -- renaming declaration of package P. AARM 10.1.2(21/2).
4417 -------------------------
4418 -- Check_Body_Required --
4419 -------------------------
4421 procedure Check_Body_Required
is
4422 PA
: constant List_Id
:=
4423 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4425 procedure Check_Declarations
(Spec
: Node_Id
);
4426 -- Recursive procedure that does the work and checks nested packages
4428 ------------------------
4429 -- Check_Declarations --
4430 ------------------------
4432 procedure Check_Declarations
(Spec
: Node_Id
) is
4434 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4436 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4438 procedure Check_Pragma_Import
(P
: Node_Id
);
4439 -- If a pragma import applies to a previous subprogram, the
4440 -- enclosing unit may not need a body. The processing is syntactic
4441 -- and does not require a declaration to be analyzed. The code
4442 -- below also handles pragma Import when applied to a subprogram
4443 -- that renames another. In this case the pragma applies to the
4446 -- Chains of multiple renames are not handled by the code below.
4447 -- It is probably impossible to handle all cases without proper
4448 -- name resolution. In such cases the algorithm is conservative
4449 -- and will indicate that a body is needed???
4451 -------------------------
4452 -- Check_Pragma_Import --
4453 -------------------------
4455 procedure Check_Pragma_Import
(P
: Node_Id
) is
4461 procedure Remove_Homonyms
(E
: Node_Id
);
4462 -- Make one pass over list of subprograms. Called again if
4463 -- subprogram is a renaming. E is known to be an identifier.
4465 ---------------------
4466 -- Remove_Homonyms --
4467 ---------------------
4469 procedure Remove_Homonyms
(E
: Node_Id
) is
4470 R
: Entity_Id
:= Empty
;
4471 -- Name of renamed entity, if any
4474 Subp_Id
:= First_Elmt
(Subp_List
);
4475 while Present
(Subp_Id
) loop
4476 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4477 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4478 /= N_Subprogram_Renaming_Declaration
4481 Next_Elmt
(Subp_Id
);
4482 Remove_Elmt
(Subp_List
, Prev_Id
);
4484 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4488 Next_Elmt
(Subp_Id
);
4493 if Nkind
(R
) = N_Identifier
then
4494 Remove_Homonyms
(R
);
4496 elsif Nkind
(R
) = N_Selected_Component
then
4497 Remove_Homonyms
(Selector_Name
(R
));
4499 -- Renaming of attribute
4505 end Remove_Homonyms
;
4507 -- Start of processing for Check_Pragma_Import
4510 -- Find name of entity in Import pragma. We have not analyzed
4511 -- the construct, so we must guard against syntax errors.
4513 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4516 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4520 Imported
:= Expression
(Arg
);
4523 Remove_Homonyms
(Imported
);
4524 end Check_Pragma_Import
;
4526 -- Start of processing for Check_Declarations
4529 -- Search for Elaborate Body pragma
4531 Decl
:= First
(Visible_Declarations
(Spec
));
4532 while Present
(Decl
)
4533 and then Nkind
(Decl
) = N_Pragma
4535 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4536 Set_Body_Required
(Library_Unit
(N
));
4543 -- Look for declarations that require the presence of a body. We
4544 -- have already skipped pragmas at the start of the list.
4546 while Present
(Decl
) loop
4548 -- Subprogram that comes from source means body may be needed.
4549 -- Save for subsequent examination of import pragmas.
4551 if Comes_From_Source
(Decl
)
4552 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4553 N_Subprogram_Renaming_Declaration
,
4554 N_Generic_Subprogram_Declaration
))
4556 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4558 -- Package declaration of generic package declaration. We need
4559 -- to recursively examine nested declarations.
4561 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4562 N_Generic_Package_Declaration
)
4564 Check_Declarations
(Specification
(Decl
));
4566 elsif Nkind
(Decl
) = N_Pragma
4567 and then Pragma_Name
(Decl
) = Name_Import
4569 Check_Pragma_Import
(Decl
);
4575 -- Same set of tests for private part. In addition to subprograms
4576 -- detect the presence of Taft Amendment types (incomplete types
4577 -- completed in the body).
4579 Decl
:= First
(Private_Declarations
(Spec
));
4580 while Present
(Decl
) loop
4581 if Comes_From_Source
(Decl
)
4582 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4583 N_Subprogram_Renaming_Declaration
,
4584 N_Generic_Subprogram_Declaration
))
4586 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4588 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4589 N_Generic_Package_Declaration
)
4591 Check_Declarations
(Specification
(Decl
));
4593 -- Collect incomplete type declarations for separate pass
4595 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4596 Append_Elmt
(Decl
, Incomplete_Decls
);
4598 elsif Nkind
(Decl
) = N_Pragma
4599 and then Pragma_Name
(Decl
) = Name_Import
4601 Check_Pragma_Import
(Decl
);
4607 -- Now check incomplete declarations to locate Taft amendment
4608 -- types. This can be done by examining the defining identifiers
4609 -- of type declarations without real semantic analysis.
4615 Inc
:= First_Elmt
(Incomplete_Decls
);
4616 while Present
(Inc
) loop
4617 Decl
:= Next
(Node
(Inc
));
4618 while Present
(Decl
) loop
4619 if Nkind
(Decl
) = N_Full_Type_Declaration
4620 and then Chars
(Defining_Identifier
(Decl
)) =
4621 Chars
(Defining_Identifier
(Node
(Inc
)))
4629 -- If no completion, this is a TAT, and a body is needed
4632 Set_Body_Required
(Library_Unit
(N
));
4640 -- Finally, check whether there are subprograms that still require
4641 -- a body, i.e. are not renamings or null.
4643 if not Is_Empty_Elmt_List
(Subp_List
) then
4649 Subp_Id
:= First_Elmt
(Subp_List
);
4650 Spec
:= Parent
(Node
(Subp_Id
));
4652 while Present
(Subp_Id
) loop
4653 if Nkind
(Parent
(Spec
))
4654 = N_Subprogram_Renaming_Declaration
4658 elsif Nkind
(Spec
) = N_Procedure_Specification
4659 and then Null_Present
(Spec
)
4664 Set_Body_Required
(Library_Unit
(N
));
4668 Next_Elmt
(Subp_Id
);
4672 end Check_Declarations
;
4674 -- Start of processing for Check_Body_Required
4677 -- If this is an imported package (Java and CIL usage) no body is
4678 -- needed. Scan list of pragmas that may follow a compilation unit
4679 -- to look for a relevant pragma Import.
4681 if Present
(PA
) then
4687 while Present
(Prag
) loop
4688 if Nkind
(Prag
) = N_Pragma
4689 and then Get_Pragma_Id
(Prag
) = Pragma_Import
4699 Check_Declarations
(Specification
(P_Unit
));
4700 end Check_Body_Required
;
4702 -----------------------------
4703 -- Has_Limited_With_Clause --
4704 -----------------------------
4706 function Has_Limited_With_Clause
4707 (C_Unit
: Entity_Id
;
4708 Pack
: Entity_Id
) return Boolean
4715 while Present
(Par
) loop
4716 if Ekind
(Par
) /= E_Package
then
4720 -- Retrieve the Compilation_Unit node for Par and determine if
4721 -- its context clauses contain a limited with for Pack.
4723 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
4725 if Nkind
(Par_Unit
) = N_Package_Declaration
then
4726 Par_Unit
:= Parent
(Par_Unit
);
4729 if Has_With_Clause
(Par_Unit
, Pack
, True) then
4733 -- If there are more ancestors, climb up the tree, otherwise we
4736 if Is_Child_Unit
(Par
) then
4744 end Has_Limited_With_Clause
;
4746 ----------------------------------
4747 -- Is_Visible_Through_Renamings --
4748 ----------------------------------
4750 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean is
4751 Kind
: constant Node_Kind
:=
4752 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
4758 -- Example of the error detected by this subprogram:
4766 -- package Ren_P renames P;
4772 -- limited with P; -- ERROR
4773 -- package R.C is ...
4775 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
4778 Item
:= First
(Context_Items
(Aux_Unit
));
4779 while Present
(Item
) loop
4780 if Nkind
(Item
) = N_With_Clause
4781 and then not Limited_Present
(Item
)
4782 and then Nkind
(Unit
(Library_Unit
(Item
))) =
4783 N_Package_Declaration
4786 First
(Visible_Declarations
4787 (Specification
(Unit
(Library_Unit
(Item
)))));
4788 while Present
(Decl
) loop
4789 if Nkind
(Decl
) = N_Package_Renaming_Declaration
4790 and then Entity
(Name
(Decl
)) = P
4792 -- Generate the error message only if the current unit
4793 -- is a package declaration; in case of subprogram
4794 -- bodies and package bodies we just return True to
4795 -- indicate that the limited view must not be
4798 if Kind
= N_Package_Declaration
then
4800 ("simultaneous visibility of the limited and " &
4801 "unlimited views not allowed", N
);
4802 Error_Msg_Sloc
:= Sloc
(Item
);
4804 ("\\ unlimited view of & visible through the " &
4805 "context clause #", N
, P
);
4806 Error_Msg_Sloc
:= Sloc
(Decl
);
4807 Error_Msg_NE
("\\ and the renaming #", N
, P
);
4820 -- If it is a body not acting as spec, follow pointer to the
4821 -- corresponding spec, otherwise follow pointer to parent spec.
4823 if Present
(Library_Unit
(Aux_Unit
))
4824 and then Nkind_In
(Unit
(Aux_Unit
),
4825 N_Package_Body
, N_Subprogram_Body
)
4827 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
4829 -- Aux_Unit is a body that acts as a spec. Clause has
4830 -- already been flagged as illegal.
4835 Aux_Unit
:= Library_Unit
(Aux_Unit
);
4839 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
4842 exit when No
(Aux_Unit
);
4846 end Is_Visible_Through_Renamings
;
4848 -- Start of processing for Install_Limited_Withed_Unit
4851 pragma Assert
(not Limited_View_Installed
(N
));
4853 -- In case of limited with_clause on subprograms, generics, instances,
4854 -- or renamings, the corresponding error was previously posted and we
4855 -- have nothing to do here. If the file is missing altogether, it has
4856 -- no source location.
4858 if Nkind
(P_Unit
) /= N_Package_Declaration
4859 or else Sloc
(P_Unit
) = No_Location
4864 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
4866 -- Handle child packages
4868 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
4869 Is_Child_Package
:= True;
4870 P
:= Defining_Identifier
(P
);
4873 -- Do not install the limited-view if the context of the unit is already
4874 -- available through a regular with clause.
4876 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4877 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4882 -- Do not install the limited-view if the full-view is already visible
4883 -- through renaming declarations.
4885 if Is_Visible_Through_Renamings
(P
) then
4889 -- Do not install the limited view if this is the unit being analyzed.
4890 -- This unusual case will happen when a unit has a limited_with clause
4891 -- on one of its children. The compilation of the child forces the load
4892 -- of the parent which tries to install the limited view of the child
4893 -- again. Installing the limited view must also be disabled when
4894 -- compiling the body of the child unit.
4896 if P
= Cunit_Entity
(Current_Sem_Unit
)
4897 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4898 and then P
= Main_Unit_Entity
4899 and then Is_Ancestor_Unit
4900 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
4905 -- This scenario is similar to the one above, the difference is that the
4906 -- compilation of sibling Par.Sib forces the load of parent Par which
4907 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4908 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4909 -- non-limited views of all entities from Lim_Pack.
4911 -- limited with Lim_Pack; -- [1]
4912 -- package Par is ... package Lim_Pack is ...
4914 -- with Lim_Pack; -- [2]
4915 -- package Par.Sib is ... package body Par.Sib is ...
4917 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4918 -- Sem_Unit is the body of Par.Sib.
4920 if Ekind
(P
) = E_Package
4921 and then Ekind
(Main_Unit_Entity
) = E_Package
4922 and then Is_Child_Unit
(Main_Unit_Entity
)
4924 -- The body has a regular with clause
4926 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4927 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4929 -- One of the ancestors has a limited with clause
4931 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
4932 N_Package_Specification
4933 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
4938 -- A common use of the limited-with is to have a limited-with in the
4939 -- package spec, and a normal with in its package body. For example:
4941 -- limited with X; -- [1]
4945 -- package body A is ...
4947 -- The compilation of A's body installs the context clauses found at [2]
4948 -- and then the context clauses of its specification (found at [1]). As
4949 -- a consequence, at [1] the specification of X has been analyzed and it
4950 -- is immediately visible. According to the semantics of limited-with
4951 -- context clauses we don't install the limited view because the full
4952 -- view of X supersedes its limited view.
4954 if Analyzed
(P_Unit
)
4956 (Is_Immediately_Visible
(P
)
4957 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
4960 -- The presence of both the limited and the analyzed nonlimited view
4961 -- may also be an error, such as an illegal context for a limited
4962 -- with_clause. In that case, do not process the context item at all.
4964 if Error_Posted
(N
) then
4968 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
4972 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4973 while Present
(Item
) loop
4974 if Nkind
(Item
) = N_With_Clause
4975 and then Comes_From_Source
(Item
)
4976 and then Entity
(Name
(Item
)) = P
4985 -- If this is a child body, assume that the nonlimited with_clause
4986 -- appears in an ancestor. Could be refined ???
4990 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
4997 -- If in package declaration, nonlimited view brought in from
4998 -- parent unit or some error condition.
5004 if Debug_Flag_I
then
5005 Write_Str
("install limited view of ");
5006 Write_Name
(Chars
(P
));
5010 -- If the unit has not been analyzed and the limited view has not been
5011 -- already installed then we install it.
5013 if not Analyzed
(P_Unit
) then
5014 if not In_Chain
(P
) then
5016 -- Minimum decoration
5018 Set_Ekind
(P
, E_Package
);
5019 Set_Etype
(P
, Standard_Void_Type
);
5020 Set_Scope
(P
, Standard_Standard
);
5021 Set_Is_Visible_Lib_Unit
(P
);
5023 if Is_Child_Package
then
5024 Set_Is_Child_Unit
(P
);
5025 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
5028 -- Place entity on visibility structure
5030 Set_Homonym
(P
, Current_Entity
(P
));
5031 Set_Current_Entity
(P
);
5033 if Debug_Flag_I
then
5034 Write_Str
(" (homonym) chain ");
5035 Write_Name
(Chars
(P
));
5039 -- Install the incomplete view. The first element of the limited
5040 -- view is a header (an E_Package entity) used to reference the
5041 -- first shadow entity in the private part of the package.
5043 Lim_Header
:= Limited_View
(P
);
5044 Lim_Typ
:= First_Entity
(Lim_Header
);
5046 while Present
(Lim_Typ
)
5047 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5049 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
5050 Set_Current_Entity
(Lim_Typ
);
5052 if Debug_Flag_I
then
5053 Write_Str
(" (homonym) chain ");
5054 Write_Name
(Chars
(Lim_Typ
));
5058 Next_Entity
(Lim_Typ
);
5062 -- If the unit appears in a previous regular with_clause, the regular
5063 -- entities of the public part of the withed package must be replaced
5064 -- by the shadow ones.
5066 -- This code must be kept synchronized with the code that replaces the
5067 -- shadow entities by the real entities (see body of Remove_Limited
5068 -- With_Clause); otherwise the contents of the homonym chains are not
5072 -- Hide all the type entities of the public part of the package to
5073 -- avoid its usage. This is needed to cover all the subtype decla-
5074 -- rations because we do not remove them from the homonym chain.
5076 E
:= First_Entity
(P
);
5077 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5079 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5086 -- Replace the real entities by the shadow entities of the limited
5087 -- view. The first element of the limited view is a header that is
5088 -- used to reference the first shadow entity in the private part
5089 -- of the package. Successive elements are the limited views of the
5090 -- type (including regular incomplete types) declared in the package.
5092 Lim_Header
:= Limited_View
(P
);
5094 Lim_Typ
:= First_Entity
(Lim_Header
);
5095 while Present
(Lim_Typ
)
5096 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5098 pragma Assert
(not In_Chain
(Lim_Typ
));
5100 -- Do not unchain nested packages and child units
5102 if Ekind
(Lim_Typ
) /= E_Package
5103 and then not Is_Child_Unit
(Lim_Typ
)
5109 Prev
:= Current_Entity
(Lim_Typ
);
5112 -- Replace E in the homonyms list, so that the limited view
5113 -- becomes available.
5115 -- If the non-limited view is a record with an anonymous
5116 -- self-referential component, the analysis of the record
5117 -- declaration creates an incomplete type with the same name
5118 -- in order to define an internal access type. The visible
5119 -- entity is now the incomplete type, and that is the one to
5120 -- replace in the visibility structure.
5122 if E
= Non_Limited_View
(Lim_Typ
)
5124 (Ekind
(E
) = E_Incomplete_Type
5125 and then Full_View
(E
) = Non_Limited_View
(Lim_Typ
))
5127 Set_Homonym
(Lim_Typ
, Homonym
(Prev
));
5128 Set_Current_Entity
(Lim_Typ
);
5132 E
:= Homonym
(Prev
);
5134 -- E may have been removed when installing a previous
5135 -- limited_with_clause.
5138 exit when E
= Non_Limited_View
(Lim_Typ
);
5139 Prev
:= Homonym
(Prev
);
5143 Set_Homonym
(Lim_Typ
, Homonym
(Homonym
(Prev
)));
5144 Set_Homonym
(Prev
, Lim_Typ
);
5149 if Debug_Flag_I
then
5150 Write_Str
(" (homonym) chain ");
5151 Write_Name
(Chars
(Lim_Typ
));
5156 Next_Entity
(Lim_Typ
);
5160 -- The package must be visible while the limited-with clause is active
5161 -- because references to the type P.T must resolve in the usual way.
5162 -- In addition, we remember that the limited-view has been installed to
5163 -- uninstall it at the point of context removal.
5165 Set_Is_Immediately_Visible
(P
);
5166 Set_Limited_View_Installed
(N
);
5168 -- If unit has not been analyzed in some previous context, check
5169 -- (imperfectly ???) whether it might need a body.
5171 if not Analyzed
(P_Unit
) then
5172 Check_Body_Required
;
5175 -- If the package in the limited_with clause is a child unit, the clause
5176 -- is unanalyzed and appears as a selected component. Recast it as an
5177 -- expanded name so that the entity can be properly set. Use entity of
5178 -- parent, if available, for higher ancestors in the name.
5180 if Nkind
(Name
(N
)) = N_Selected_Component
then
5188 while Nkind
(Nam
) = N_Selected_Component
5189 and then Present
(Ent
)
5191 Change_Selected_Component_To_Expanded_Name
(Nam
);
5193 -- Set entity of parent identifiers if the unit is a child
5194 -- unit. This ensures that the tree is properly formed from
5195 -- semantic point of view (e.g. for ASIS queries). The unit
5196 -- entities are not fully analyzed, so we need to follow unit
5197 -- links in the tree.
5199 Set_Entity
(Nam
, Ent
);
5201 Nam
:= Prefix
(Nam
);
5204 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5206 -- Set entity of last ancestor
5208 if Nkind
(Nam
) = N_Identifier
then
5209 Set_Entity
(Nam
, Ent
);
5215 Set_Entity
(Name
(N
), P
);
5216 Set_From_Limited_With
(P
);
5217 end Install_Limited_Withed_Unit
;
5219 -------------------------
5220 -- Install_Withed_Unit --
5221 -------------------------
5223 procedure Install_Withed_Unit
5224 (With_Clause
: Node_Id
;
5225 Private_With_OK
: Boolean := False)
5227 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5228 P
: constant Entity_Id
:= Scope
(Uname
);
5231 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5232 -- compiling a package declaration and the Private_With_OK flag was not
5233 -- set by the caller. These declarations will be installed later (before
5234 -- analyzing the private part of the package).
5236 if Private_Present
(With_Clause
)
5237 and then Nkind
(Unit
(Parent
(With_Clause
))) = N_Package_Declaration
5238 and then not (Private_With_OK
)
5243 if Debug_Flag_I
then
5244 if Private_Present
(With_Clause
) then
5245 Write_Str
("install private withed unit ");
5247 Write_Str
("install withed unit ");
5250 Write_Name
(Chars
(Uname
));
5254 -- We do not apply the restrictions to an internal unit unless we are
5255 -- compiling the internal unit as a main unit. This check is also
5256 -- skipped for dummy units (for missing packages).
5258 if Sloc
(Uname
) /= No_Location
5259 and then (not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
5260 or else Current_Sem_Unit
= Main_Unit
)
5262 Check_Restricted_Unit
5263 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5266 if P
/= Standard_Standard
then
5268 -- If the unit is not analyzed after analysis of the with clause and
5269 -- it is an instantiation then it awaits a body and is the main unit.
5270 -- Its appearance in the context of some other unit indicates a
5271 -- circular dependency (DEC suite perversity).
5273 if not Analyzed
(Uname
)
5274 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5277 ("instantiation depends on itself", Name
(With_Clause
));
5279 elsif not Is_Visible_Lib_Unit
(Uname
) then
5281 -- Abandon processing in case of previous errors
5283 if No
(Scope
(Uname
)) then
5284 Check_Error_Detected
;
5288 Set_Is_Visible_Lib_Unit
(Uname
);
5290 -- If the unit is a wrapper package for a compilation unit that is
5291 -- a subprogrm instance, indicate that the instance itself is a
5292 -- visible unit. This is necessary if the instance is inlined.
5294 if Is_Wrapper_Package
(Uname
) then
5295 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5298 -- If the child unit appears in the context of its parent, it is
5299 -- immediately visible.
5301 if In_Open_Scopes
(Scope
(Uname
)) then
5302 Set_Is_Immediately_Visible
(Uname
);
5305 if Is_Generic_Instance
(Uname
)
5306 and then Ekind
(Uname
) in Subprogram_Kind
5308 -- Set flag as well on the visible entity that denotes the
5309 -- instance, which renames the current one.
5311 Set_Is_Visible_Lib_Unit
5313 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5316 -- The parent unit may have been installed already, and may have
5317 -- appeared in a use clause.
5319 if In_Use
(Scope
(Uname
)) then
5320 Set_Is_Potentially_Use_Visible
(Uname
);
5323 Set_Context_Installed
(With_Clause
);
5326 elsif not Is_Immediately_Visible
(Uname
) then
5327 Set_Is_Visible_Lib_Unit
(Uname
);
5329 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5330 Set_Is_Immediately_Visible
(Uname
);
5333 Set_Context_Installed
(With_Clause
);
5336 -- A with-clause overrides a with-type clause: there are no restric-
5337 -- tions on the use of package entities.
5339 if Ekind
(Uname
) = E_Package
then
5340 Set_From_Limited_With
(Uname
, False);
5343 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5344 -- unit if there is a visible homograph for it declared in the same
5345 -- declarative region. This pathological case can only arise when an
5346 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5347 -- G1 has a generic child also named G2, and the context includes with_
5348 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5349 -- of I1.G2 visible as well. If the child unit is named Standard, do
5350 -- not apply the check to the Standard package itself.
5352 if Is_Child_Unit
(Uname
)
5353 and then Is_Visible_Lib_Unit
(Uname
)
5354 and then Ada_Version
>= Ada_2005
5357 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5363 U2
:= Homonym
(Uname
);
5364 while Present
(U2
) and then U2
/= Standard_Standard
loop
5366 Decl2
:= Unit_Declaration_Node
(P2
);
5368 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5369 if Is_Generic_Instance
(P
)
5370 and then Nkind
(Decl1
) = N_Package_Declaration
5371 and then Generic_Parent
(Specification
(Decl1
)) = P2
5373 Error_Msg_N
("illegal with_clause", With_Clause
);
5375 ("\child unit has visible homograph" &
5376 " (RM 8.3(26), 10.1.1(19))",
5380 elsif Is_Generic_Instance
(P2
)
5381 and then Nkind
(Decl2
) = N_Package_Declaration
5382 and then Generic_Parent
(Specification
(Decl2
)) = P
5384 -- With_clause for child unit of instance appears before
5385 -- in the context. We want to place the error message on
5386 -- it, not on the generic child unit itself.
5389 Prev_Clause
: Node_Id
;
5392 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5393 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5397 pragma Assert
(Present
(Prev_Clause
));
5398 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5400 ("\child unit has visible homograph" &
5401 " (RM 8.3(26), 10.1.1(19))",
5412 end Install_Withed_Unit
;
5418 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5419 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5422 return (K
in N_Generic_Declaration
or else
5423 K
in N_Generic_Instantiation
or else
5424 K
in N_Generic_Renaming_Declaration
or else
5425 K
= N_Package_Declaration
or else
5426 K
= N_Package_Renaming_Declaration
or else
5427 K
= N_Subprogram_Declaration
or else
5428 K
= N_Subprogram_Renaming_Declaration
)
5429 and then Present
(Parent_Spec
(Lib_Unit
));
5432 ------------------------------------
5433 -- Is_Legal_Shadow_Entity_In_Body --
5434 ------------------------------------
5436 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5437 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5439 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5442 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5443 end Is_Legal_Shadow_Entity_In_Body
;
5445 ----------------------
5446 -- Is_Ancestor_Unit --
5447 ----------------------
5449 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5450 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5453 if Nkind_In
(Unit
(U2
), N_Package_Body
, N_Subprogram_Body
) then
5454 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5455 return Is_Ancestor_Package
(E1
, E2
);
5459 end Is_Ancestor_Unit
;
5461 -----------------------
5462 -- Load_Needed_Body --
5463 -----------------------
5465 -- N is a generic unit named in a with clause, or else it is a unit that
5466 -- contains a generic unit or an inlined function. In order to perform an
5467 -- instantiation, the body of the unit must be present. If the unit itself
5468 -- is generic, we assume that an instantiation follows, and load & analyze
5469 -- the body unconditionally. This forces analysis of the spec as well.
5471 -- If the unit is not generic, but contains a generic unit, it is loaded on
5472 -- demand, at the point of instantiation (see ch12).
5474 procedure Load_Needed_Body
5477 Do_Analyze
: Boolean := True)
5479 Body_Name
: Unit_Name_Type
;
5480 Unum
: Unit_Number_Type
;
5482 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5483 -- The loading and analysis is done with style checks off
5486 if not GNAT_Mode
then
5487 Style_Check
:= False;
5490 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5493 (Load_Name
=> Body_Name
,
5499 if Unum
= No_Unit
then
5503 Compiler_State
:= Analyzing
; -- reset after load
5505 if Fatal_Error
(Unum
) /= Error_Detected
or else Try_Semantics
then
5506 if Debug_Flag_L
then
5507 Write_Str
("*** Loaded generic body");
5512 Semantics
(Cunit
(Unum
));
5519 Style_Check
:= Save_Style_Check
;
5520 end Load_Needed_Body
;
5522 -------------------------
5523 -- Build_Limited_Views --
5524 -------------------------
5526 procedure Build_Limited_Views
(N
: Node_Id
) is
5527 Unum
: constant Unit_Number_Type
:=
5528 Get_Source_Unit
(Library_Unit
(N
));
5529 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5531 Shadow_Pack
: Entity_Id
;
5532 -- The corresponding shadow entity of the withed package. This entity
5533 -- offers incomplete views of packages and types as well as abstract
5534 -- views of states and variables declared within.
5536 Last_Shadow
: Entity_Id
:= Empty
;
5537 -- The last shadow entity created by routine Build_Shadow_Entity
5539 procedure Build_Shadow_Entity
5542 Shadow
: out Entity_Id
;
5543 Is_Tagged
: Boolean := False);
5544 -- Create a shadow entity that hides Ent and offers an abstract or
5545 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5546 -- should be set when Ent is a tagged type. The generated entity is
5547 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5549 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5550 -- Perform minimal decoration of a package or its corresponding shadow
5551 -- entity denoted by Ent. Scop is the proper scope.
5553 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5554 -- Perform full decoration of an abstract state or its corresponding
5555 -- shadow entity denoted by Ent. Scop is the proper scope.
5557 procedure Decorate_Type
5560 Is_Tagged
: Boolean := False;
5561 Materialize
: Boolean := False);
5562 -- Perform minimal decoration of a type or its corresponding shadow
5563 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5564 -- should be set when Ent is a tagged type. Flag Materialize should be
5565 -- set when Ent is a tagged type and its class-wide type needs to appear
5568 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5569 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5572 procedure Process_Declarations_And_States
5576 Create_Abstract_Views
: Boolean);
5577 -- Inspect the states of package Pack and declarative list Decls. Create
5578 -- shadow entities for all nested packages, states, types and variables
5579 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5580 -- be set when the abstract states and variables need to be processed.
5582 -------------------------
5583 -- Build_Shadow_Entity --
5584 -------------------------
5586 procedure Build_Shadow_Entity
5589 Shadow
: out Entity_Id
;
5590 Is_Tagged
: Boolean := False)
5593 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5595 -- The shadow entity must share the same name and parent as the
5598 Set_Chars
(Shadow
, Chars
(Ent
));
5599 Set_Parent
(Shadow
, Parent
(Ent
));
5601 -- The abstract view of a variable is a state, not another variable
5603 if Ekind
(Ent
) = E_Variable
then
5604 Set_Ekind
(Shadow
, E_Abstract_State
);
5606 Set_Ekind
(Shadow
, Ekind
(Ent
));
5609 Set_Is_Internal
(Shadow
);
5610 Set_From_Limited_With
(Shadow
);
5612 -- Add the new shadow entity to the limited view of the package
5614 Last_Shadow
:= Shadow
;
5615 Append_Entity
(Shadow
, Shadow_Pack
);
5617 -- Perform context-specific decoration of the shadow entity
5619 if Ekind
(Ent
) = E_Abstract_State
then
5620 Decorate_State
(Shadow
, Scop
);
5621 Set_Non_Limited_View
(Shadow
, Ent
);
5623 elsif Ekind
(Ent
) = E_Package
then
5624 Decorate_Package
(Shadow
, Scop
);
5626 elsif Is_Type
(Ent
) then
5627 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
5628 Set_Non_Limited_View
(Shadow
, Ent
);
5631 Set_Non_Limited_View
5632 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Ent
));
5635 if Is_Incomplete_Or_Private_Type
(Ent
) then
5636 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
5639 elsif Ekind
(Ent
) = E_Variable
then
5640 Decorate_State
(Shadow
, Scop
);
5641 Set_Non_Limited_View
(Shadow
, Ent
);
5643 end Build_Shadow_Entity
;
5645 ----------------------
5646 -- Decorate_Package --
5647 ----------------------
5649 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5651 Set_Ekind
(Ent
, E_Package
);
5652 Set_Etype
(Ent
, Standard_Void_Type
);
5653 Set_Scope
(Ent
, Scop
);
5654 end Decorate_Package
;
5656 --------------------
5657 -- Decorate_State --
5658 --------------------
5660 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5662 Set_Ekind
(Ent
, E_Abstract_State
);
5663 Set_Etype
(Ent
, Standard_Void_Type
);
5664 Set_Scope
(Ent
, Scop
);
5665 Set_Encapsulating_State
(Ent
, Empty
);
5666 Set_Refinement_Constituents
(Ent
, New_Elmt_List
);
5667 Set_Part_Of_Constituents
(Ent
, New_Elmt_List
);
5674 procedure Decorate_Type
5677 Is_Tagged
: Boolean := False;
5678 Materialize
: Boolean := False)
5683 -- An unanalyzed type or a shadow entity of a type is treated as an
5686 Set_Ekind
(Ent
, E_Incomplete_Type
);
5687 Set_Etype
(Ent
, Ent
);
5688 Set_Scope
(Ent
, Scop
);
5689 Set_Is_First_Subtype
(Ent
);
5690 Set_Stored_Constraint
(Ent
, No_Elist
);
5691 Set_Full_View
(Ent
, Empty
);
5692 Init_Size_Align
(Ent
);
5694 -- A tagged type and its corresponding shadow entity share one common
5695 -- class-wide type. The list of primitive operations for the shadow
5699 Set_Is_Tagged_Type
(Ent
);
5700 Set_Direct_Primitive_Operations
(Ent
, New_Elmt_List
);
5704 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
5706 Set_Class_Wide_Type
(Ent
, CW_Typ
);
5708 -- Set parent to be the same as the parent of the tagged type.
5709 -- We need a parent field set, and it is supposed to point to
5710 -- the declaration of the type. The tagged type declaration
5711 -- essentially declares two separate types, the tagged type
5712 -- itself and the corresponding class-wide type, so it is
5713 -- reasonable for the parent fields to point to the declaration
5716 Set_Parent
(CW_Typ
, Parent
(Ent
));
5718 Set_Ekind
(CW_Typ
, E_Class_Wide_Type
);
5719 Set_Etype
(CW_Typ
, Ent
);
5720 Set_Scope
(CW_Typ
, Scop
);
5721 Set_Is_Tagged_Type
(CW_Typ
);
5722 Set_Is_First_Subtype
(CW_Typ
);
5723 Init_Size_Align
(CW_Typ
);
5724 Set_Has_Unknown_Discriminants
(CW_Typ
);
5725 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
5726 Set_Equivalent_Type
(CW_Typ
, Empty
);
5727 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
5728 Set_Materialize_Entity
(CW_Typ
, Materialize
);
5732 -----------------------
5733 -- Decorate_Variable --
5734 -----------------------
5736 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5738 Set_Ekind
(Ent
, E_Variable
);
5739 Set_Etype
(Ent
, Standard_Void_Type
);
5740 Set_Scope
(Ent
, Scop
);
5741 end Decorate_Variable
;
5743 -------------------------------------
5744 -- Process_Declarations_And_States --
5745 -------------------------------------
5747 procedure Process_Declarations_And_States
5751 Create_Abstract_Views
: Boolean)
5753 procedure Find_And_Process_States
;
5754 -- Determine whether package Pack defines abstract state either by
5755 -- using an aspect or a pragma. If this is the case, build shadow
5756 -- entities for all abstract states of Pack.
5758 procedure Process_States
(States
: Elist_Id
);
5759 -- Generate shadow entities for all abstract states in list States
5761 -----------------------------
5762 -- Find_And_Process_States --
5763 -----------------------------
5765 procedure Find_And_Process_States
is
5766 procedure Process_State
(State
: Node_Id
);
5767 -- Generate shadow entities for a single abstract state or
5768 -- multiple states expressed as an aggregate.
5774 procedure Process_State
(State
: Node_Id
) is
5775 Loc
: constant Source_Ptr
:= Sloc
(State
);
5782 -- Multiple abstract states appear as an aggregate
5784 if Nkind
(State
) = N_Aggregate
then
5785 Elmt
:= First
(Expressions
(State
));
5786 while Present
(Elmt
) loop
5787 Process_State
(Elmt
);
5793 -- A null state has no abstract view
5795 elsif Nkind
(State
) = N_Null
then
5798 -- State declaration with various options appears as an
5799 -- extension aggregate.
5801 elsif Nkind
(State
) = N_Extension_Aggregate
then
5802 Decl
:= Ancestor_Part
(State
);
5804 -- Simple state declaration
5806 elsif Nkind
(State
) = N_Identifier
then
5809 -- Possibly an illegal state declaration
5815 -- Abstract states are elaborated when the related pragma is
5816 -- elaborated. Since the withed package is not analyzed yet,
5817 -- the entities of the abstract states are not available. To
5818 -- overcome this complication, create the entities now and
5819 -- store them in their respective declarations. The entities
5820 -- are later used by routine Create_Abstract_State to declare
5821 -- and enter the states into visibility.
5823 if No
(Entity
(Decl
)) then
5824 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
5826 Set_Entity
(Decl
, Id
);
5827 Set_Parent
(Id
, State
);
5828 Decorate_State
(Id
, Scop
);
5830 -- Otherwise the package was previously withed
5833 Id
:= Entity
(Decl
);
5836 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
5841 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
5845 -- Start of processing for Find_And_Process_States
5848 -- Find aspect Abstract_State
5850 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
5851 while Present
(Asp
) loop
5852 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
5853 Process_State
(Expression
(Asp
));
5861 -- Find pragma Abstract_State by inspecting the declarations
5863 Decl
:= First
(Decls
);
5864 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
5865 if Pragma_Name
(Decl
) = Name_Abstract_State
then
5868 (First
(Pragma_Argument_Associations
(Decl
))));
5875 end Find_And_Process_States
;
5877 --------------------
5878 -- Process_States --
5879 --------------------
5881 procedure Process_States
(States
: Elist_Id
) is
5886 Elmt
:= First_Elmt
(States
);
5887 while Present
(Elmt
) loop
5888 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
5896 Is_Tagged
: Boolean;
5902 -- Start of processing for Process_Declarations_And_States
5905 -- Build abstract views for all states defined in the package
5907 if Create_Abstract_Views
then
5909 -- When a package has been analyzed, all states are stored in list
5910 -- Abstract_States. Generate the shadow entities directly.
5913 if Present
(Abstract_States
(Pack
)) then
5914 Process_States
(Abstract_States
(Pack
));
5917 -- The package may declare abstract states by using an aspect or a
5918 -- pragma. Attempt to locate one of these construct and if found,
5919 -- build the shadow entities.
5922 Find_And_Process_States
;
5926 -- Inspect the declarative list, looking for nested packages, types
5927 -- and variable declarations.
5929 Decl
:= First
(Decls
);
5930 while Present
(Decl
) loop
5934 if Nkind
(Decl
) = N_Package_Declaration
then
5935 Def_Id
:= Defining_Entity
(Decl
);
5937 -- Perform minor decoration when the withed package has not
5940 if not Is_Analyzed
then
5941 Decorate_Package
(Def_Id
, Scop
);
5944 -- Create a shadow entity that offers a limited view of all
5945 -- visible types declared within.
5947 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5949 Process_Declarations_And_States
5951 Decls
=> Visible_Declarations
(Specification
(Decl
)),
5953 Create_Abstract_Views
=> Create_Abstract_Views
);
5957 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
5958 N_Incomplete_Type_Declaration
,
5959 N_Private_Extension_Declaration
,
5960 N_Private_Type_Declaration
,
5961 N_Protected_Type_Declaration
,
5962 N_Task_Type_Declaration
)
5964 Def_Id
:= Defining_Entity
(Decl
);
5966 -- Determine whether the type is tagged. Note that packages
5967 -- included via a limited with clause are not always analyzed,
5968 -- hence the tree lookup rather than the use of attribute
5971 if Nkind
(Decl
) = N_Full_Type_Declaration
then
5972 Def
:= Type_Definition
(Decl
);
5975 (Nkind
(Def
) = N_Record_Definition
5976 and then Tagged_Present
(Def
))
5978 (Nkind
(Def
) = N_Derived_Type_Definition
5979 and then Present
(Record_Extension_Part
(Def
)));
5981 elsif Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
5982 N_Private_Type_Declaration
)
5984 Is_Tagged
:= Tagged_Present
(Decl
);
5986 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
5993 -- Perform minor decoration when the withed package has not
5996 if not Is_Analyzed
then
5997 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
6000 -- Create a shadow entity that hides the type and offers an
6001 -- incomplete view of the said type.
6003 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
6007 elsif Create_Abstract_Views
6008 and then Nkind
(Decl
) = N_Object_Declaration
6009 and then not Constant_Present
(Decl
)
6011 Def_Id
:= Defining_Entity
(Decl
);
6013 -- Perform minor decoration when the withed package has not
6016 if not Is_Analyzed
then
6017 Decorate_Variable
(Def_Id
, Scop
);
6020 -- Create a shadow entity that hides the variable and offers an
6021 -- abstract view of the said variable.
6023 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
6028 end Process_Declarations_And_States
;
6032 Nam
: constant Node_Id
:= Name
(N
);
6033 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
6035 Last_Public_Shadow
: Entity_Id
:= Empty
;
6036 Private_Shadow
: Entity_Id
;
6039 -- Start of processing for Build_Limited_Views
6042 pragma Assert
(Limited_Present
(N
));
6044 -- A library_item mentioned in a limited_with_clause is a package
6045 -- declaration, not a subprogram declaration, generic declaration,
6046 -- generic instantiation, or package renaming declaration.
6048 case Nkind
(Unit
(Library_Unit
(N
))) is
6049 when N_Package_Declaration
=>
6052 when N_Subprogram_Declaration
=>
6053 Error_Msg_N
("subprograms not allowed in limited with_clauses", N
);
6056 when N_Generic_Package_Declaration |
6057 N_Generic_Subprogram_Declaration
=>
6058 Error_Msg_N
("generics not allowed in limited with_clauses", N
);
6061 when N_Generic_Instantiation
=>
6063 ("generic instantiations not allowed in limited with_clauses",
6067 when N_Generic_Renaming_Declaration
=>
6069 ("generic renamings not allowed in limited with_clauses", N
);
6072 when N_Subprogram_Renaming_Declaration
=>
6074 ("renamed subprograms not allowed in limited with_clauses", N
);
6077 when N_Package_Renaming_Declaration
=>
6079 ("renamed packages not allowed in limited with_clauses", N
);
6083 raise Program_Error
;
6086 -- The withed unit may not be analyzed, but the with calause itself
6087 -- must be minimally decorated. This ensures that the checks on unused
6088 -- with clauses also process limieted withs.
6090 Set_Ekind
(Pack
, E_Package
);
6091 Set_Etype
(Pack
, Standard_Void_Type
);
6093 if Is_Entity_Name
(Nam
) then
6094 Set_Entity
(Nam
, Pack
);
6096 elsif Nkind
(Nam
) = N_Selected_Component
then
6097 Set_Entity
(Selector_Name
(Nam
), Pack
);
6100 -- Check if the chain is already built
6102 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6104 if Limited_View_Installed
(Spec
) then
6108 -- Create the shadow package wich hides the withed unit and provides
6109 -- incomplete view of all types and packages declared within.
6111 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6112 Set_Ekind
(Shadow_Pack
, E_Package
);
6113 Set_Is_Internal
(Shadow_Pack
);
6114 Set_Limited_View
(Pack
, Shadow_Pack
);
6116 -- Inspect the abstract states and visible declarations of the withed
6117 -- unit and create shadow entities that hide existing packages, states,
6118 -- variables and types.
6120 Process_Declarations_And_States
6122 Decls
=> Visible_Declarations
(Spec
),
6124 Create_Abstract_Views
=> True);
6126 Last_Public_Shadow
:= Last_Shadow
;
6128 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6129 -- to accomodate limited private with clauses.
6131 Process_Declarations_And_States
6133 Decls
=> Private_Declarations
(Spec
),
6135 Create_Abstract_Views
=> False);
6137 if Present
(Last_Public_Shadow
) then
6138 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6140 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6143 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6144 Set_Limited_View_Installed
(Spec
);
6145 end Build_Limited_Views
;
6147 ----------------------------
6148 -- Check_No_Elab_Code_All --
6149 ----------------------------
6151 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6153 if Present
(No_Elab_Code_All_Pragma
)
6154 and then In_Extended_Main_Source_Unit
(N
)
6155 and then Present
(Context_Items
(N
))
6158 CL
: constant List_Id
:= Context_Items
(N
);
6163 while Present
(CI
) loop
6164 if Nkind
(CI
) = N_With_Clause
6166 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6168 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6170 ("violation of No_Elaboration_Code_All#", CI
);
6172 ("\unit& does not have No_Elaboration_Code_All",
6173 CI
, Entity
(Name
(CI
)));
6180 end Check_No_Elab_Code_All
;
6182 -------------------------------
6183 -- Check_Body_Needed_For_SAL --
6184 -------------------------------
6186 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6188 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6189 -- Determine whether use of entity E might require the presence of its
6190 -- body. For a package this requires a recursive traversal of all nested
6193 ---------------------------
6194 -- Entity_Needed_For_SAL --
6195 ---------------------------
6197 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6201 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6204 elsif Ekind_In
(E
, E_Generic_Function
, E_Generic_Procedure
) then
6207 elsif Ekind
(E
) = E_Generic_Package
6209 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6210 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6214 elsif Ekind
(E
) = E_Package
6215 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6216 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6218 Ent
:= First_Entity
(E
);
6219 while Present
(Ent
) loop
6220 if Entity_Needs_Body
(Ent
) then
6232 end Entity_Needs_Body
;
6234 -- Start of processing for Check_Body_Needed_For_SAL
6237 if Ekind
(Unit_Name
) = E_Generic_Package
6238 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6239 N_Generic_Package_Declaration
6241 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6243 Set_Body_Needed_For_SAL
(Unit_Name
);
6245 elsif Ekind_In
(Unit_Name
, E_Generic_Procedure
, E_Generic_Function
) then
6246 Set_Body_Needed_For_SAL
(Unit_Name
);
6248 elsif Is_Subprogram
(Unit_Name
)
6249 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6250 N_Subprogram_Declaration
6251 and then Has_Pragma_Inline
(Unit_Name
)
6253 Set_Body_Needed_For_SAL
(Unit_Name
);
6255 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6256 Check_Body_Needed_For_SAL
6257 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6259 elsif Ekind
(Unit_Name
) = E_Package
6260 and then Entity_Needs_Body
(Unit_Name
)
6262 Set_Body_Needed_For_SAL
(Unit_Name
);
6264 elsif Ekind
(Unit_Name
) = E_Package_Body
6265 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6267 Check_Body_Needed_For_SAL
6268 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6270 end Check_Body_Needed_For_SAL
;
6272 --------------------
6273 -- Remove_Context --
6274 --------------------
6276 procedure Remove_Context
(N
: Node_Id
) is
6277 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6280 -- If this is a child unit, first remove the parent units
6282 if Is_Child_Spec
(Lib_Unit
) then
6283 Remove_Parents
(Lib_Unit
);
6286 Remove_Context_Clauses
(N
);
6289 ----------------------------
6290 -- Remove_Context_Clauses --
6291 ----------------------------
6293 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6295 Unit_Name
: Entity_Id
;
6298 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6299 -- limited-views first and regular-views later (to maintain the
6302 -- First Phase: Remove limited_with context clauses
6304 Item
:= First
(Context_Items
(N
));
6305 while Present
(Item
) loop
6307 -- We are interested only in with clauses which got installed
6310 if Nkind
(Item
) = N_With_Clause
6311 and then Limited_Present
(Item
)
6312 and then Limited_View_Installed
(Item
)
6314 Remove_Limited_With_Clause
(Item
);
6320 -- Second Phase: Loop through context items and undo regular
6321 -- with_clauses and use_clauses.
6323 Item
:= First
(Context_Items
(N
));
6324 while Present
(Item
) loop
6326 -- We are interested only in with clauses which got installed on
6327 -- entry, as indicated by their Context_Installed flag set
6329 if Nkind
(Item
) = N_With_Clause
6330 and then Limited_Present
(Item
)
6331 and then Limited_View_Installed
(Item
)
6335 elsif Nkind
(Item
) = N_With_Clause
6336 and then Context_Installed
(Item
)
6338 -- Remove items from one with'ed unit
6340 Unit_Name
:= Entity
(Name
(Item
));
6341 Remove_Unit_From_Visibility
(Unit_Name
);
6342 Set_Context_Installed
(Item
, False);
6344 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6345 End_Use_Package
(Item
);
6347 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6348 End_Use_Type
(Item
);
6353 end Remove_Context_Clauses
;
6355 --------------------------------
6356 -- Remove_Limited_With_Clause --
6357 --------------------------------
6359 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6360 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6363 Lim_Header
: Entity_Id
;
6364 Lim_Typ
: Entity_Id
;
6368 pragma Assert
(Limited_View_Installed
(N
));
6370 -- In case of limited with_clause on subprograms, generics, instances,
6371 -- or renamings, the corresponding error was previously posted and we
6372 -- have nothing to do here.
6374 if Nkind
(P_Unit
) /= N_Package_Declaration
then
6378 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
6380 -- Handle child packages
6382 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
6383 P
:= Defining_Identifier
(P
);
6386 if Debug_Flag_I
then
6387 Write_Str
("remove limited view of ");
6388 Write_Name
(Chars
(P
));
6389 Write_Str
(" from visibility");
6393 -- Prepare the removal of the shadow entities from visibility. The first
6394 -- element of the limited view is a header (an E_Package entity) that is
6395 -- used to reference the first shadow entity in the private part of the
6398 Lim_Header
:= Limited_View
(P
);
6399 Lim_Typ
:= First_Entity
(Lim_Header
);
6401 -- Remove package and shadow entities from visibility if it has not
6404 if not Analyzed
(P_Unit
) then
6406 Set_Is_Immediately_Visible
(P
, False);
6408 while Present
(Lim_Typ
) loop
6410 Next_Entity
(Lim_Typ
);
6413 -- Otherwise this package has already appeared in the closure and its
6414 -- shadow entities must be replaced by its real entities. This code
6415 -- must be kept synchronized with the complementary code in Install
6416 -- Limited_Withed_Unit.
6419 -- Real entities that are type or subtype declarations were hidden
6420 -- from visibility at the point of installation of the limited-view.
6421 -- Now we recover the previous value of the hidden attribute.
6423 E
:= First_Entity
(P
);
6424 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
6426 Set_Is_Hidden
(E
, Was_Hidden
(E
));
6432 while Present
(Lim_Typ
)
6433 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
6435 -- Nested packages and child units were not unchained
6437 if Ekind
(Lim_Typ
) /= E_Package
6438 and then not Is_Child_Unit
(Non_Limited_View
(Lim_Typ
))
6440 -- If the package has incomplete types, the limited view of the
6441 -- incomplete type is in fact never visible (AI05-129) but we
6442 -- have created a shadow entity E1 for it, that points to E2,
6443 -- a non-limited incomplete type. This in turn has a full view
6444 -- E3 that is the full declaration. There is a corresponding
6445 -- shadow entity E4. When reinstalling the non-limited view,
6446 -- E2 must become the current entity and E3 must be ignored.
6448 E
:= Non_Limited_View
(Lim_Typ
);
6450 if Present
(Current_Entity
(E
))
6451 and then Ekind
(Current_Entity
(E
)) = E_Incomplete_Type
6452 and then Full_View
(Current_Entity
(E
)) = E
6455 -- Lim_Typ is the limited view of a full type declaration
6456 -- that has a previous incomplete declaration, i.e. E3 from
6457 -- the previous description. Nothing to insert.
6462 pragma Assert
(not In_Chain
(E
));
6464 Prev
:= Current_Entity
(Lim_Typ
);
6466 if Prev
= Lim_Typ
then
6467 Set_Current_Entity
(E
);
6470 while Present
(Prev
)
6471 and then Homonym
(Prev
) /= Lim_Typ
6473 Prev
:= Homonym
(Prev
);
6476 if Present
(Prev
) then
6477 Set_Homonym
(Prev
, E
);
6481 -- Preserve structure of homonym chain
6483 Set_Homonym
(E
, Homonym
(Lim_Typ
));
6487 Next_Entity
(Lim_Typ
);
6491 -- Indicate that the limited view of the package is not installed
6493 Set_From_Limited_With
(P
, False);
6494 Set_Limited_View_Installed
(N
, False);
6495 end Remove_Limited_With_Clause
;
6497 --------------------
6498 -- Remove_Parents --
6499 --------------------
6501 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
6504 P_Spec
: Node_Id
:= Empty
;
6506 Vis
: constant Boolean :=
6507 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
6510 if Is_Child_Spec
(Lib_Unit
) then
6511 P_Spec
:= Parent_Spec
(Lib_Unit
);
6513 elsif Nkind
(Lib_Unit
) = N_Package_Body
6514 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
6516 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
6519 if Present
(P_Spec
) then
6521 P_Name
:= Get_Parent_Entity
(P
);
6522 Remove_Context_Clauses
(P_Spec
);
6523 End_Package_Scope
(P_Name
);
6524 Set_Is_Immediately_Visible
(P_Name
, Vis
);
6526 -- Remove from visibility the siblings as well, which are directly
6527 -- visible while the parent is in scope.
6529 E
:= First_Entity
(P_Name
);
6530 while Present
(E
) loop
6531 if Is_Child_Unit
(E
) then
6532 Set_Is_Immediately_Visible
(E
, False);
6538 Set_In_Package_Body
(P_Name
, False);
6540 -- This is the recursive call to remove the context of any higher
6541 -- level parent. This recursion ensures that all parents are removed
6542 -- in the reverse order of their installation.
6548 ---------------------------------
6549 -- Remove_Private_With_Clauses --
6550 ---------------------------------
6552 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
6555 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
6556 -- Check whether a given unit appears in a regular with_clause. Used to
6557 -- determine whether a private_with_clause, implicit or explicit, should
6560 ----------------------------
6561 -- In_Regular_With_Clause --
6562 ----------------------------
6564 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean
6569 Item
:= First
(Context_Items
(Comp_Unit
));
6570 while Present
(Item
) loop
6571 if Nkind
(Item
) = N_With_Clause
6573 -- The following guard is needed to ensure that the name has
6574 -- been properly analyzed before we go fetching its entity.
6576 and then Is_Entity_Name
(Name
(Item
))
6577 and then Entity
(Name
(Item
)) = E
6578 and then not Private_Present
(Item
)
6586 end In_Regular_With_Clause
;
6588 -- Start of processing for Remove_Private_With_Clauses
6591 Item
:= First
(Context_Items
(Comp_Unit
));
6592 while Present
(Item
) loop
6593 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
6595 -- If private_with_clause is redundant, remove it from context,
6596 -- as a small optimization to subsequent handling of private_with
6597 -- clauses in other nested packages.
6599 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
6601 Nxt
: constant Node_Id
:= Next
(Item
);
6607 elsif Limited_Present
(Item
) then
6608 if not Limited_View_Installed
(Item
) then
6609 Remove_Limited_With_Clause
(Item
);
6615 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
6616 Set_Context_Installed
(Item
, False);
6624 end Remove_Private_With_Clauses
;
6626 ---------------------------------
6627 -- Remove_Unit_From_Visibility --
6628 ---------------------------------
6630 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
6632 if Debug_Flag_I
then
6633 Write_Str
("remove unit ");
6634 Write_Name
(Chars
(Unit_Name
));
6635 Write_Str
(" from visibility");
6639 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
6640 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
6641 Set_Is_Immediately_Visible
(Unit_Name
, False);
6643 -- If the unit is a wrapper package, the subprogram instance is
6644 -- what must be removed from visibility.
6645 -- Should we use Related_Instance instead???
6647 if Is_Wrapper_Package
(Unit_Name
) then
6648 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
6650 end Remove_Unit_From_Visibility
;
6665 procedure Unchain
(E
: Entity_Id
) is
6669 Prev
:= Current_Entity
(E
);
6675 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6678 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
6679 Prev
:= Homonym
(Prev
);
6682 if Present
(Prev
) then
6683 Set_Homonym
(Prev
, Homonym
(E
));
6687 if Debug_Flag_I
then
6688 Write_Str
(" (homonym) unchain ");
6689 Write_Name
(Chars
(E
));